pascal OSStatus CustomEventHandler(EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData) { DWORD id=0; GetEventParameter(inEvent,'evid',0,NULL,sizeof(id),NULL,&id); switch (id) { case 'open': SetStaticText(31,"connecting..."); SetStaticText(30,""); SetStaticText(32,""); break; case 'end ': SetStaticText(31,"not playing"); SetStaticText(30,""); SetStaticText(32,""); break; case 'stat': { char *status; GetEventParameter(inEvent,'data',0,NULL,sizeof(status),NULL,&status); SetStaticText(32,status); // display connection status free(status); } break; case 'meta': DoMeta(); break; } return noErr; }
//------------------------------------------------------------------------ pascal OSStatus DoMouseUp (EventHandlerCallRef nextHandler, EventRef theEvent, void* userData) { Point wheresMyMouse; UInt32 modifier; GetEventParameter (theEvent, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &wheresMyMouse); GlobalToLocal (&wheresMyMouse); GetEventParameter (theEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifier); platform_support * app = reinterpret_cast<platform_support*>(userData); app->m_specific->m_cur_x = wheresMyMouse.h; if(app->flip_y()) { app->m_specific->m_cur_y = app->rbuf_window().height() - wheresMyMouse.v; } else { app->m_specific->m_cur_y = wheresMyMouse.v; } app->m_specific->m_input_flags = mouse_left | get_key_flags(modifier); if(app->m_ctrls.on_mouse_button_up(app->m_specific->m_cur_x, app->m_specific->m_cur_y)) { app->on_ctrl_change(); app->force_redraw(); } app->on_mouse_button_up(app->m_specific->m_cur_x, app->m_specific->m_cur_y, app->m_specific->m_input_flags); return CallNextEventHandler (nextHandler, theEvent); }
static pascal OSStatus NPServerDialogEventHandler (EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData) { OSStatus err, result = eventNotHandledErr; WindowRef tWindowRef = (WindowRef) inUserData; switch (GetEventClass(inEvent)) { case kEventClassCommand: switch (GetEventKind(inEvent)) { HICommand tHICommand; case kEventCommandUpdateStatus: err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &tHICommand); if (err == noErr && tHICommand.commandID == 'clos') { UpdateMenuCommandStatus(false); result = noErr; } break; case kEventCommandProcess: err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &tHICommand); if (err == noErr) { switch (tHICommand.commandID) { case 'OKAY': HIViewRef ctl, root; HIViewID cid; root = HIViewGetRoot(tWindowRef); cid.id = 0; cid.signature = 'OKAY'; HIViewFindByID(root, cid, &ctl); DeactivateControl(ctl); cid.signature = 'CNSL'; HIViewFindByID(root, cid, &ctl); DeactivateControl(ctl); npserver.dialogprocess = kNPSDialogProcess; result = noErr; break; case 'CNSL': npserver.dialogprocess = kNPSDialogCancel; result = noErr; break; } } break; } break; } return (result); }
pascal OSStatus pxWindowNative::doMouseUp(EventHandlerCallRef nextHandler, EventRef theEvent, void* userData) { pxWindowNative* w = (pxWindowNative*)userData; Point loc; UInt16 button; UInt32 modifier; GetEventParameter (theEvent, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &loc); SetPort(GetWindowPort(w->mWindowRef)); GlobalToLocal(&loc); GetEventParameter(theEvent, kEventParamMouseButton, typeMouseButton, NULL, sizeof(button), NULL, &button); GetEventParameter(theEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifier); unsigned long flags = 0; if (button == kEventMouseButtonPrimary) flags |= PX_LEFTBUTTON; else if (button == kEventMouseButtonSecondary) flags |= PX_RIGHTBUTTON; else if (button == kEventMouseButtonTertiary) flags |= PX_MIDDLEBUTTON; if (modifier & shiftKey) flags |= PX_MOD_SHIFT; if (modifier & optionKey) flags |= PX_MOD_ALT; if (modifier & controlKey) flags |= PX_MOD_CONTROL; w->onMouseUp(loc.h, loc.v, flags); return CallNextEventHandler (nextHandler, theEvent); }
static OSStatus handleKeyInput (EventHandlerCallRef myHandler, EventRef event, Boolean keyDown, OSXWindowData* oW) { WindowBase *wB = oW->WindowBaseOwner; WindowRef window = NULL; window = wB->GetWindowHandle(); OSStatus result = eventNotHandledErr; result = CallNextEventHandler(myHandler, event); if (eventNotHandledErr == result) { UInt32 keyCode; char keyChar; GetEventParameter (event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode); GetEventParameter (event, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(char), NULL, &keyChar); // handle keyboard input here int prophecyKeyCode = remapChar(keyChar); int prophecyKeyCodeExtended = prophecyKeyCode; if(prophecyKeyCode == 0) prophecyKeyCodeExtended = prophecyKeyCode = remapKeyCodes(keyCode); else prophecyKeyCodeExtended = remapKeyCodes(keyCode); if( prophecyKeyCodeExtended != prophecyKeyCode && prophecyKeyCodeExtended != 0 ) prophecyKeyCode = prophecyKeyCodeExtended; wB->DispatchEventKeyboard(prophecyKeyCode,keyChar,keyDown); } return result; }
static OSStatus handle_unicode(EventRef event) { UInt32 actual_size, i; UniChar *text; UniCharCount num_chars; OSStatus result = noErr; // hack to keep sequences like Cmd+f from writing to buffer if(! cmdPressed) { result = GetEventParameter (event, kEventParamTextInputSendText, typeUnicodeText, NULL, 0, &actual_size, NULL); if(result == noErr) { text = (UniChar*) NewPtr(actual_size); result = GetEventParameter (event, kEventParamTextInputSendText, typeUnicodeText, NULL, actual_size, NULL, text); if(result == noErr) { num_chars = actual_size / sizeof(UniChar); for(i=0; i < num_chars; i++) { int key = convert_unichar(text[i]); gkbdputc(gkbdq, key); } } } } return result; }
void wxControl::OnKeyDown( wxKeyEvent &event ) { if ( (ControlHandle) m_macControl == NULL ) return ; #if TARGET_CARBON char charCode ; UInt32 keyCode ; UInt32 modifiers ; GetEventParameter( (EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode ); GetEventParameter( (EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode ); GetEventParameter((EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); ::HandleControlKey( (ControlHandle) m_macControl , keyCode , charCode , modifiers ) ; #else EventRecord *ev = (EventRecord*) wxTheApp->MacGetCurrentEvent() ; short keycode ; short keychar ; keychar = short(ev->message & charCodeMask); keycode = short(ev->message & keyCodeMask) >> 8 ; ::HandleControlKey( (ControlHandle) m_macControl , keycode , keychar , ev->modifiers ) ; #endif }
//------------------------------------------------------------------------ pascal OSStatus pxWindowNative::doKeyUp (EventHandlerCallRef nextHandler, EventRef theEvent, void* userData) { char key_code; char char_code; UInt32 modifier; GetEventParameter (theEvent, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(char), NULL, &key_code); GetEventParameter (theEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifier); UInt32 kc; GetEventParameter (theEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &kc); // printf("VK UP: %lx\n", kc); pxWindowNative* w = (pxWindowNative*)userData; if (kc == 0x24) kc = 0x4c; unsigned long flags = 0; if (modifier & shiftKey) flags |= PX_MOD_SHIFT; if (modifier & optionKey) flags |= PX_MOD_ALT; if (modifier & controlKey) flags |= PX_MOD_CONTROL; w->onKeyUp(kc, flags); return CallNextEventHandler (nextHandler, theEvent); }
static OSStatus handleWindowEvent(EventHandlerCallRef nextHandler, EventRef event, void *userData) { OSStatus err; // Get the window WindowRef window; err = GetEventParameter(event, kEventParamDirectObject, typeWindowRef, 0, sizeof(window), 0, &window); if (err != noErr) return err; // Handle the different kinds of events ::UInt32 eventKind = GetEventKind(event); switch (eventKind) { // Quit the application when the user closes the window case kEventWindowClose: QuitApplicationEventLoop(); return noErr; // Draw the contents of the window case kEventWindowDrawContent: redraw(); return noErr; case kEventWindowBoundsChanged: { // Update the GL context aglUpdateContext(win->getContext()); // Find out if we have a move or a resize situation ::UInt32 attributes; GetEventParameter(event, kEventParamAttributes, typeUInt32, 0, sizeof(attributes), 0, &attributes); if ((attributes & kWindowBoundsChangeSizeChanged) != 0) { // Get the new bounds of the window Rect bounds; GetEventParameter(event, kEventParamCurrentBounds, typeQDRectangle, 0, sizeof(Rect), 0, &bounds); // Resize the OpenSG Window GLsizei width = bounds.right - bounds.left; GLsizei height = bounds.bottom - bounds.top; win->resize(width, height); // Redraw the whole window Rect portRect; GetWindowPortBounds(window, &portRect); InvalWindowRect(window, &portRect); } return noErr; } default: return eventNotHandledErr; } }
int TkMacOSXProcessCommandEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr) { HICommand command; int menuContext; OSStatus status; switch (eventPtr->eKind) { case kEventCommandProcess: case kEventCommandUpdateStatus: break; default: return 0; break; } status = GetEventParameter(eventPtr->eventRef, kEventParamDirectObject, typeHICommand, NULL, sizeof(command), NULL, &command); if (status == noErr && (command.attributes & kHICommandFromMenu)) { if (eventPtr->eKind == kEventCommandProcess) { status = GetEventParameter(eventPtr->eventRef, kEventParamMenuContext, typeUInt32, NULL, sizeof(menuContext), NULL, &menuContext); if (status == noErr && (menuContext & kMenuContextMenuBar) && (menuContext & kMenuContextMenuBarTracking)) { TkMacOSXHandleMenuSelect(GetMenuID(command.menu.menuRef), command.menu.menuItemIndex, GetCurrentEventKeyModifiers() & optionKey); return 1; } } else { Tcl_CmdInfo dummy; if (command.commandID == kHICommandPreferences && eventPtr->interp) { if (Tcl_GetCommandInfo(eventPtr->interp, "::tk::mac::ShowPreferences", &dummy)) { if (!IsMenuItemEnabled(command.menu.menuRef, command.menu.menuItemIndex)) { EnableMenuItem(command.menu.menuRef, command.menu.menuItemIndex); } } else { if (IsMenuItemEnabled(command.menu.menuRef, command.menu.menuItemIndex)) { DisableMenuItem(command.menu.menuRef, command.menu.menuItemIndex); } } return 1; } } } return 0; }
OSStatus dialogHandler(EventHandlerCallRef handler, EventRef event, void *userdata) { OSStatus result = eventNotHandledErr; OSStatus err; UInt32 evtClass = GetEventClass(event); UInt32 evtKind = GetEventKind(event); if((evtClass == kEventClassCommand) && (evtKind == kEventCommandProcess)) { HICommand cmd; err = GetEventParameter(event, kEventParamDirectObject, typeHICommand, NULL, sizeof(cmd), NULL, &cmd); if(err == noErr) { switch(cmd.commandID) { case kHICommandCancel: gCancelled = true; // QuitAppModalLoopForWindow(gWindow); result = noErr; break; } } } else if((evtClass == kEventClassCustom) && (evtKind == kEventCustomProgress)) { // Request to update the progress dialog long cur = 0; long max = 0; CFStringRef text = NULL; (void) GetEventParameter(event, kEventParamCustomCurValue, typeLongInteger, NULL, sizeof(cur), NULL, &cur); (void) GetEventParameter(event, kEventParamCustomMaxValue, typeLongInteger, NULL, sizeof(max), NULL, &max); (void) GetEventParameter(event, kEventParamCustomText, typeCFStringRef, NULL, sizeof(text), NULL, &text); err = setProgress(cur, max); if(err == noErr) { if(text != NULL) { setProgressText(text); } } result = noErr; } else if((evtClass == kEventClassCustom) && (evtKind == kEventCustomDone)) { // We're done. Exit the modal loop. QuitAppModalLoopForWindow(gWindow); result = noErr; } return(result); }
static OSStatus handleKeyEvent(EventHandlerCallRef nextHandler, EventRef event, void *userData) { OSStatus err; // Try to determine the size of the text input ::UInt32 actualSize; err = GetEventParameter(event, kEventParamTextInputSendText, typeUnicodeText, 0, 0, &actualSize, 0); if (err != noErr) return err; // The input can actually consist of more than one character. // We are only interested in single character input if (actualSize == sizeof(UniChar)) { // Get the character unicode UniChar c; err = GetEventParameter(event, kEventParamTextInputSendText, typeUnicodeText, 0, sizeof(UniChar), 0, &c); if (err != noErr) return err; // Handle different keyboard commands CGLSetCurrentContext(win->getContext()); switch (c) { case kEscapeCharCode: QuitApplicationEventLoop(); break; case 'a': glDisable( GL_LIGHTING ); redraw(); break; case 's': glEnable( GL_LIGHTING ); redraw(); break; case 'z': glPolygonMode( GL_FRONT_AND_BACK, GL_POINT); redraw(); break; case 'x': glPolygonMode( GL_FRONT_AND_BACK, GL_LINE); redraw(); break; case 'c': glPolygonMode( GL_FRONT_AND_BACK, GL_FILL); redraw(); break; } } return noErr; }
static pascal OSStatus TextInputEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) { OSStatus result = eventNotHandledErr ; wxWindow* focus = wxWindow::FindFocus() ; char charCode ; UInt32 keyCode ; UInt32 modifiers ; Point point ; EventRef rawEvent ; GetEventParameter( event , kEventParamTextInputSendKeyboardEvent ,typeEventRef,NULL,sizeof(rawEvent),NULL,&rawEvent ) ; GetEventParameter( rawEvent, kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode ); GetEventParameter( rawEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode ); GetEventParameter( rawEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); GetEventParameter( rawEvent, kEventParamMouseLocation, typeQDPoint, NULL, sizeof( Point ), NULL, &point ); switch ( GetEventKind( event ) ) { case kEventTextInputUnicodeForKeyEvent : // this is only called when no default handler has jumped in, eg a wxControl on a floater window does not // get its own kEventTextInputUnicodeForKeyEvent, so we route back the wxControl* control = wxDynamicCast( focus , wxControl ) ; if ( control ) { ControlHandle macControl = (ControlHandle) control->GetMacControl() ; if ( macControl ) { ::HandleControlKey( macControl , keyCode , charCode , modifiers ) ; result = noErr ; } } /* // this may lead to double events sent to a window in case all handlers have skipped the key down event UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ; UInt32 message = (keyCode << 8) + charCode; if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent( focus , message , modifiers , when , point.h , point.v ) ) { result = noErr ; } */ break ; } return result ; }
static OSStatus AppEventHandler(EventHandlerCallRef inCaller, EventRef inEvent, void* inRefcon) { OSStatus result = eventNotHandledErr; switch ( GetEventClass( inEvent ) ) { case kEventClassCommand: { HICommandExtended cmd; verify_noerr( GetEventParameter( inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof( cmd ), NULL, &cmd ) ); switch ( GetEventKind( inEvent ) ) { case kEventCommandProcess: CContextOSX* pContext = (CContextOSX*)inRefcon; pContext->OnMenuEventHandler(cmd.source.menu.menuItemIndex, (tint32)cmd.source.menu.menuRef); } break; } case kCoreEventClass: { HICommandExtended cmd; verify_noerr( GetEventParameter( inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof( cmd ), NULL, &cmd ) ); switch ( GetEventKind( inEvent ) ) { case kAEOpenDocuments:{ tuint32 ui = 0; ui++; break; } case kAEOpenApplication:{ tuint32 ui = 0; ui++; break; } } } default: break; } return result; }
OSStatus CSMNativeWindow::handleKeyEvent(EventHandlerCallRef nextHandler, EventRef event ) { OSStatus err; // Try to determine the size of the text input ::UInt32 actualSize; err = GetEventParameter(event, kEventParamTextInputSendText, typeUnicodeText, 0, 0, &actualSize, 0); if (err != noErr) return err; // The input can actually consist of more than one character. // We are only interested in single character input if (actualSize == sizeof(UniChar)) { // Get the character unicode UniChar c; err = GetEventParameter(event, kEventParamTextInputSendText, typeUnicodeText, 0, sizeof(UniChar), 0, &c); if (err != noErr) return err; switch (c) { case kEscapeCharCode: //QuitApplicationEventLoop(); _bRun = false; break; default: ComplexSceneManager::the()->key( 0, 0, CSMKeyData::ButtonDown, c); break; } } return noErr; }
void wxControl::OnKeyDown( wxKeyEvent &event ) { if ( m_peer == NULL || !m_peer->Ok() ) return ; char charCode ; UInt32 keyCode ; UInt32 modifiers ; GetEventParameter( (EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode ); GetEventParameter( (EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode ); GetEventParameter((EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); m_peer->HandleKey( keyCode , charCode , modifiers ) ; }
// ----------------------------------------------------------------------------- // HITestViewSetData // ----------------------------------------------------------------------------- // OSStatus HITestViewSetData( EventRef inEvent, HITestViewData* inData ) { #pragma unused( inData ) OSStatus err; ControlPartCode part; OSType tag; Ptr ptr; Size size; // Extract the part -- we don't use it here, but it might be important // in a non-trivial view err = GetEventParameter( inEvent, kEventParamControlPart, typeControlPartCode, NULL, sizeof( ControlPartCode ), NULL, &part ); require_noerr( err, ParameterMissing ); // Extract the rest of the info needs for data handling err = GetEventParameter( inEvent, kEventParamControlDataTag, typeEnumeration, NULL, sizeof( OSType ), NULL, &tag ); require_noerr( err, ParameterMissing ); err = GetEventParameter( inEvent, kEventParamControlDataBuffer, typePtr, NULL, sizeof( Ptr ), NULL, &ptr ); require_noerr( err, ParameterMissing ); err = GetEventParameter( inEvent, kEventParamControlDataBufferSize, typeLongInteger, NULL, sizeof( Size ), NULL, &size ); require_noerr( err, ParameterMissing ); switch ( tag ) { /* case kControlHITest_YourTagHere_Tag: if ( size == sizeof( HITest_YourTypeHere ) ) inData->HITest_YourDataMemberHere = *( (HITest_YourTypeHere*) ptr ); else err = errDataSizeMismatch; break; */ default: err = errDataNotSupported; break; } ParameterMissing: return err; }
static pascal OSStatus RomInfoEventHandler (EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData) { OSStatus err, result = eventNotHandledErr; WindowRef tWindowRef = (WindowRef) inUserData; switch (GetEventClass(inEvent)) { case kEventClassWindow: switch (GetEventKind(inEvent)) { case kEventWindowClose: QuitAppModalLoopForWindow(tWindowRef); result = noErr; } break; case kEventClassCommand: switch (GetEventKind(inEvent)) { HICommand tHICommand; case kEventCommandUpdateStatus: err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &tHICommand); if (err == noErr && tHICommand.commandID == 'clos') { UpdateMenuCommandStatus(true); result = noErr; } break; case kEventCommandProcess: err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &tHICommand); if (err == noErr) { switch (tHICommand.commandID) { case 'Clip': RomInfoCopyToClipboard(); result = noErr; } } } } return (result); }
// ----------------------------------------------------------------------------- // HITestViewHitTest // ----------------------------------------------------------------------------- // Check to see if a point hits the view // OSStatus HITestViewHitTest( EventRef inEvent, HITestViewData* inData ) { OSStatus err; HIRect bounds; HIPoint where; ControlPartCode part; // Extract the mouse location err = GetEventParameter( inEvent, kEventParamMouseLocation, typeHIPoint, NULL, sizeof( HIPoint ), NULL, &where ); require_noerr( err, ParameterMissing ); // Is the mouse in the view? err = HIViewGetBounds( inData->view, &bounds ); if ( CGRectContainsPoint( bounds, where ) ) part = 1; else part = kControlNoPart; // Send back the value of the hit part err = SetEventParameter( inEvent, kEventParamControlPart, typeControlPartCode, sizeof( ControlPartCode ), &part ); ParameterMissing: return err; }
bool COSXScreen::onHotKey(EventRef event) const { // get the hotkey id EventHotKeyID hkid; GetEventParameter(event, kEventParamDirectObject, typeEventHotKeyID, NULL, sizeof(EventHotKeyID), NULL, &hkid); UInt32 id = hkid.id; // determine event type CEvent::Type type; UInt32 eventKind = GetEventKind(event); if (eventKind == kEventHotKeyPressed) { type = m_events->forIPrimaryScreen().hotKeyDown(); } else if (eventKind == kEventHotKeyReleased) { type = m_events->forIPrimaryScreen().hotKeyUp(); } else { return false; } m_events->addEvent(CEvent(type, getEventTarget(), CHotKeyInfo::alloc(id))); return true; }
// ----------------------------------------------------------------------------- // HITestViewConstruct // ----------------------------------------------------------------------------- // Do any instatiation-time preparation for the view. // OSStatus HITestViewConstruct( EventRef inEvent ) { OSStatus err; HITestViewData* data; // don't CallNextEventHandler! data = (HITestViewData*) malloc( sizeof( HITestViewData ) ); require_action( data != NULL, CantMalloc, err = memFullErr ); err = GetEventParameter( inEvent, kEventParamHIObjectInstance, typeHIObjectRef, NULL, sizeof( HIObjectRef ), NULL, (HIObjectRef*) &data->view ); require_noerr( err, ParameterMissing ); // Set the userData that will be used with all subsequent eventHandler calls err = SetEventParameter( inEvent, kEventParamHIObjectInstance, typeVoidPtr, sizeof( HITestViewData* ), &data ); ParameterMissing: if ( err != noErr ) free( data ); CantMalloc: return err; }
/***************************************************** * * Handle_CommandUpdateStatus(inHandlerCallRef, inEvent, inUserData) * * Purpose: called to update status of the commands, enabling or disabling the menu items * * Inputs: inHandlerCallRef - reference to the current handler call chain * inEvent - the event * inUserData - app-specified data you passed in the call to InstallEventHandler * * Returns: OSStatus - noErr indicates the event was handled * eventNotHandledErr indicates the event was not handled and the Toolbox should take over */ static pascal OSStatus Handle_CommandUpdateStatus(EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *inUserData) { OSStatus status = eventNotHandledErr; HICommand aCommand; GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &aCommand); WindowRef aWindowRef = GetFrontWindowOfClass(kDocumentWindowClass, true); if (aWindowRef == NULL) { switch (aCommand.commandID) { case kHICommandClose: DisableMenuItem(aCommand.menu.menuRef, aCommand.menu.menuItemIndex); break; } } else { switch (aCommand.commandID) { case kHICommandClose: EnableMenuItem(aCommand.menu.menuRef, aCommand.menu.menuItemIndex); break; } } return status; } // Handle_CommandUpdateStatus
pascal OSStatus COSXScreenSaver::launchTerminationCallback( EventHandlerCallRef nextHandler, EventRef theEvent, void* userData) { OSStatus result; ProcessSerialNumber psn; EventParamType actualType; UInt32 actualSize; result = GetEventParameter(theEvent, kEventParamProcessID, typeProcessSerialNumber, &actualType, sizeof(psn), &actualSize, &psn); if ((result == noErr) && (actualSize > 0) && (actualType == typeProcessSerialNumber)) { COSXScreenSaver* screenSaver = (COSXScreenSaver*)userData; UInt32 eventKind = GetEventKind(theEvent); if (eventKind == kEventAppLaunched) { screenSaver->processLaunched(psn); } else if (eventKind == kEventAppTerminated) { screenSaver->processTerminated(psn); } } return (CallNextEventHandler(nextHandler, theEvent)); }
// -------------------------------------------------------------------------------------- static pascal OSStatus dialogEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *prefsDialog) { #pragma unused (nextHandler) OSStatus result = eventNotHandledErr; UInt32 eventClass, eventKind; ControlRef controlHit; ControlID controlID; eventClass = GetEventClass(event); eventKind = GetEventKind(event); switch (eventClass) { case kEventClassControl: switch (eventKind) { case kEventControlHit: GetEventParameter(event, kEventParamDirectObject, typeControlRef, NULL, sizeof(ControlRef), NULL, &controlHit); GetControlID(controlHit, &controlID); handleDialogItemHit((DialogRef)prefsDialog, (DialogItemIndex)controlID.id); result = noErr; break; } break; } return result; }
// -------------------------------------------------------------------------------------- static pascal OSStatus appEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *junk) { #pragma unused (nextHandler, junk) OSStatus result = eventNotHandledErr; UInt32 eventClass, eventKind; HICommand command; eventClass = GetEventClass(event); eventKind = GetEventKind(event); switch (eventClass) { case kEventClassCommand: switch (eventKind) { case kEventCommandProcess: GetEventParameter(event, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &command); result = handleCommand(command); break; } break; } return result; }
static pascal OSStatus group_setting_event_proc(EventHandlerCallRef handler,EventRef event,void *data) { HICommand cmd; switch (GetEventKind(event)) { case kEventProcessCommand: GetEventParameter(event,kEventParamDirectObject,typeHICommand,NULL,sizeof(HICommand),NULL,&cmd); switch (cmd.commandID) { case kHICommandCancel: dialog_group_settings_cancel=TRUE; QuitAppModalLoopForWindow(dialog_group_settings_wind); return(noErr); case kHICommandOK: QuitAppModalLoopForWindow(dialog_group_settings_wind); return(noErr); } return(eventNotHandledErr); } return(eventNotHandledErr); }
static pascal OSStatus IndicatorEventHandler(EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *userData) { #pragma unused (inHandlerCallRef) OSStatus err, result = eventNotHandledErr; HIViewRef view = (HIViewRef) userData; switch (GetEventClass(inEvent)) { case kEventClassControl: switch (GetEventKind(inEvent)) { case kEventControlDraw: CGContextRef ctx; err = GetEventParameter(inEvent, kEventParamCGContextRef, typeCGContextRef, nil, sizeof(CGContextRef), nil, &ctx); if (err == noErr) { HIRect bounds; HIViewGetBounds(view, &bounds); CGContextTranslateCTM(ctx, 0, bounds.size.height); CGContextScaleCTM(ctx, 1.0, -1.0); MusicBoxDrawIndicator(view, ctx); result = noErr; } } } return result; }
static uint16 get_short_event_parm(EventRef evt, EventParamName n, EventParamType t) { uint16 r = NULL; OSStatus e = GetEventParameter(evt, n, t, NULL, sizeof(r), NULL, &r); uint32 nb = EndianU32_NtoB(n); if (e) lprintf("scalar event parm failed: %4.4s, %d\n", (char*)&n, e); return r; }
static pascal OSStatus PickMonitorHandler( EventHandlerCallRef inHandler, EventRef inEvent, void* inUserData ) { #pragma unused( inHandler ) HICommand cmd; OSStatus result = eventNotHandledErr; WindowRef theWindow = (WindowRef)inUserData; // The direct object for a 'process commmand' event is the HICommand. // Extract it here and switch off the command ID. GetEventParameter( inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof( cmd ), NULL, &cmd ); switch ( cmd.commandID ) { case kHICommandOK: QuitAppModalLoopForWindow( theWindow ); result = noErr; break; case kHICommandCancel: // Setting sSelectedDevice to zero will signal that the user cancelled. sSelectedDevice = 0; QuitAppModalLoopForWindow( theWindow ); result = noErr; break; } return result; }
static pascal OSStatus MacOSXDialogCommandProcess(EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void* inUserData) { HICommand aCommand; OSStatus status = eventNotHandledErr; GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &aCommand); switch (aCommand.commandID) { case kHICommandOK: // we got a valid click on the OK button so let's quit our local run loop QuitAppModalLoopForWindow((WindowRef) inUserData); break; case 'CBED': { // we still enable or disable the custom spot view depending on whether the box is checked or not HIViewRef checkBox = ((HICommandExtended *)&aCommand)->source.control; SInt32 enable = GetControl32BitValue(checkBox); HIViewID hidcsv = {0, 13}; HIViewRef customSpotView; HIViewFindByID(HIViewGetRoot(GetControlOwner(checkBox)), hidcsv, &customSpotView); if (enable) ActivateControl(customSpotView); else DeactivateControl(customSpotView); HIViewSetNeedsDisplay(customSpotView, true); } break; } return status; }