static OSStatus playerEvtHandler(EventHandlerCallRef nextHdlr, EventRef thisEvt, void *pvUserData) { ControlRef cRef; ControlID cID; OSStatus iErr; UInt32 iSize, iPos; HIPoint pMouse; Rect rDims; int iPct; if ( (kEventClassWindow == GetEventClass(thisEvt)) && (kEventWindowClose == GetEventKind(thisEvt)) ) { HideWindow(g_refPlayerWin); g_bVisible = false; return noErr; } else if ( (kEventClassControl == GetEventClass(thisEvt)) && (kEventControlClick == GetEventKind(thisEvt)) ) { if (noErr != (iErr = GetEventParameter(thisEvt, kEventParamWindowMouseLocation, typeHIPoint, NULL, sizeof(Point), NULL, &pMouse))) { fprintf(stderr, "playerEvtHandler() - GetEventParameter(HitTest) failed, returning %lu!\n", (unsigned long) iErr); } cID.signature = FOUR_CHAR_CODE('fpos'); cID.id = 7; if (noErr == (iErr = GetControlByID(g_refPlayerWin, &cID, &cRef))) { GetControlBounds(cRef, &rDims); iSize = rDims.right - rDims.left; iPos = (UInt32) pMouse.x - rDims.left; iPct = (int) (100.0 * ((double) iPos) / ((double) iSize)); } else { fprintf(stderr, "playerEvtHandler() - GetControlByID() failed, returning %lu!\n", (unsigned long) iErr); } attemptSeekTo(iPct); return CallNextEventHandler(nextHdlr, thisEvt); } else { return CallNextEventHandler(nextHdlr, thisEvt); } }
// ----------------------------------------------------------------------------- // HITestViewInitialize // ----------------------------------------------------------------------------- // The view is constructed. Do anything necessary to initialize it. // OSStatus HITestViewInitialize( EventHandlerCallRef inCallRef, EventRef inEvent, HITestViewData* inData ) { OSStatus err; // Let any parent classes have a chance at initialization err = CallNextEventHandler( inCallRef, inEvent ); require_noerr( err, TroubleInSuperClass ); // Extract the bounds from the initialization event err = GetEventParameter( inEvent, 'redx', typeFloat, NULL, sizeof( float ), NULL, &inData->red ); require_noerr( err, ParameterMissing ); err = GetEventParameter( inEvent, 'gren', typeFloat, NULL, sizeof( float ), NULL, &inData->green ); require_noerr( err, ParameterMissing ); err = GetEventParameter( inEvent, 'blue', typeFloat, NULL, sizeof( float ), NULL, &inData->blue ); require_noerr( err, ParameterMissing ); ParameterMissing: TroubleInSuperClass: return err; }
//------------------------------------------------------------------------ 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); }
//------------------------------------------------------------------------ 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 EventHandler( EventHandlerCallRef nextHandler, /* I - Next handler to call */ EventRef event, /* I - Event reference */ void *userData) /* I - User data (not used) */ { UInt32 kind; /* Kind of event */ Rect rect; /* New window size */ EventMouseButton button; /* Mouse button */ Point point; /* Mouse position */ kind = GetEventKind(event); switch (kind) { case kEventWindowBoundsChanged: GetEventParameter(event, kEventParamCurrentBounds, typeQDRectangle, NULL, sizeof(Rect), NULL, &rect); if (aglContext) aglUpdateContext(aglContext); altEngine.resize(rect.right - rect.left, rect.bottom - rect.top); break; case kEventWindowShown: WindowVisible = 1; break; case kEventWindowHidden: WindowVisible = 0; break; case kEventMouseDown: GetEventParameter(event, kEventParamMouseButton, typeMouseButton, NULL, sizeof(EventMouseButton), NULL, &button); GetEventParameter(event, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &point); //MouseFunc(button, 0, point.h, point.v); break; case kEventMouseUp: GetEventParameter(event, kEventParamMouseButton, typeMouseButton, NULL, sizeof(EventMouseButton), NULL, &button); GetEventParameter(event, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &point); //MouseFunc(button, 1, point.h, point.v); break; case kEventMouseDragged: GetEventParameter(event, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &point); //MotionFunc(point.h, point.v); break; case kEventWindowClose: altEngine.destroy(); ExitToShell(); break; default: return CallNextEventHandler(nextHandler, event); } return noErr; }
pascal OSStatus pxWindowNative::doWindowClosed(EventHandlerCallRef nextHandler, EventRef theEvent, void* userData) { pxWindowNative* w = (pxWindowNative*)userData; w->onClose(); 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; }
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); }
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)); }
/* OvalsDrawEventHandler : Handles the draw events for the "Ovals" window. Parameter DescriptionsinHandler : A reference to the current handler call chain. This is passed to your handler so that you can call CallNextEventHandler if you need to. inEvent : The event that triggered this call. inUserData : The application-specific data you passed in to InstallEventHandler. */ OSStatus OvalsDrawEventHandler (EventHandlerCallRef inHandler, EventRef inEvent, void* inUserData) { OSStatus status = eventNotHandledErr; CGContextRef context; CGRect r; //CallNextEventHandler in order to make sure the default handling of the inEvent // (drawing the white background) happens status = CallNextEventHandler( inHandler, inEvent ); require_noerr(status, CantCallNextEventHandler); // Get the CGContextRef status = GetEventParameter (inEvent, kEventParamCGContextRef, typeCGContextRef, NULL, sizeof (CGContextRef), NULL, &context); require_noerr(status, CantGetEventParameter); // Draw the outer oval in the left portion of the window r.size.height = 210; r.origin.x = 20; r.origin.y = 20; r.size.width = 210; frameOval(context, r); // Draw the inner oval in the left portion of the window r.size.height = 145; r.origin.x = 75; r.origin.y = 55; r.size.width = 100; frameOval(context, r); /* Set the fill color to green. */ CGContextSetRGBFillColor(context, 0, 1, 0, 1); // Draw and fill the outter oval in the right portion of the window r.size.height = 210; r.origin.x = 270; r.origin.y = 20; r.size.width = 210; paintOval(context, r); /* Set the fill color to yellow. */ CGContextSetRGBFillColor(context, 1, 1, 0, 1); // Draw and fill the inner oval in the right portion of the window r.size.height = 145; r.origin.x = 325; r.origin.y = 55; r.size.width = 100; paintOval(context, r); CantCallNextEventHandler: CantGetEventParameter: return status; }
//------------------------------------------------------------------------ pascal OSStatus DoWindowClose (EventHandlerCallRef nextHandler, EventRef theEvent, void* userData) { userData; QuitApplicationEventLoop (); return CallNextEventHandler (nextHandler, theEvent); }
pascal OSStatus quit_event_handler(EventHandlerCallRef call_ref, EventRef event, void *ignore) { OSStatus err; err = CallNextEventHandler(call_ref, event); if(err == noErr) { g_quit_seen = 1; } return err; }
pascal OSStatus pxWindowNative::doWindowDrawContent (EventHandlerCallRef nextHandler, EventRef theEvent, void* userData) { pxWindowNative* w = (pxWindowNative*)userData; //SetPort(GetWindowPort(w->mWindowRef)); //w->onDraw(GetPortPixMap(GetWindowPort(w->mWindowRef))); w->onDraw(GetWindowPort(w->mWindowRef)); return CallNextEventHandler (nextHandler, theEvent); }
static OSStatus infoEvtHandler(EventHandlerCallRef nextHdlr, EventRef thisEvt, void *pvUserData) { if ( (kEventClassWindow != GetEventClass(thisEvt)) || (kEventWindowClose != GetEventKind(thisEvt)) ) { return CallNextEventHandler(nextHdlr, thisEvt); } HideWindow(g_refInfoWin); g_bVisible = false; return noErr; }
OSStatus QuartzWindow::handle_event(EventHandlerCallRef handler_call_chain, EventRef e) { put_event(e); // Hack: if this is a user-level window (not SPY) and if it is window-close, // must leave it for Self, otherwise let standard handler do it if ( myContext == NULL && GetEventClass && GetEventClass(e) == kEventClassWindow && GetEventKind(e) == kEventWindowClose ) return noErr; return CallNextEventHandler(handler_call_chain, e); // In future, could return either eventNotHandledErr or noErr }
// -------------------------------------------------------------------------------------- static pascal OSStatus listBoxControlEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *prefsDialog) { OSStatus result = eventNotHandledErr; UInt32 eventClass, eventKind; DialogRef dialog; WindowRef dialogWindow; eventClass = GetEventClass(event); eventKind = GetEventKind(event); switch (eventClass) { case kEventClassTextInput: switch (eventKind) { case kEventTextInputUnicodeForKeyEvent: /* The strategy here is to first let the default handler handle the event (i.e. change the selected cell in the category list box control), then react to that change by showing the correct category panel. However the key pressed could potentially cause the default or cancel button to get hit. In this case, our window handler will be called which will dispose of the dialog. If this is the case, we need to not postprocess the event. We will test for this by getting the dialog's window, retaining it, calling the default handler, then getting the window's retain count. If the retain count is back to 1, then we know the dialog is already disposed. */ dialog = (DialogRef)prefsDialog; dialogWindow = GetDialogWindow(dialog); RetainWindow(dialogWindow); // hold onto the dialog's window result = CallNextEventHandler(nextHandler, event); if (result == noErr) // we don't need to postprocess if nothing happened { ItemCount retainCount; retainCount = GetWindowRetainCount(dialogWindow); if (retainCount > 1) // if we're the last one holding the window handleDialogItemHit(dialog, iIconList); // then there's no } // need to postprocess anything because it's about to go away ReleaseWindow(dialogWindow); break; } break; } return result; }
pascal OSStatus pxWindowNative::doMouseMove(EventHandlerCallRef nextHandler, EventRef theEvent, void* userData) { pxWindowNative* w = (pxWindowNative*)userData; Point loc; GetEventParameter (theEvent, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &loc); SetPort(GetWindowPort(w->mWindowRef)); GlobalToLocal (&loc); w->onMouseMove(loc.h, loc.v); return CallNextEventHandler (nextHandler, theEvent); }
//------------------------------------------------------------------------ pascal OSStatus DoWindowDrawContent (EventHandlerCallRef nextHandler, EventRef theEvent, void* userData) { platform_support * app = reinterpret_cast<platform_support*>(userData); if(app) { if(app->m_specific->m_redraw_flag) { app->on_draw(); app->m_specific->m_redraw_flag = false; } app->m_specific->display_pmap(app->m_specific->m_window, &app->rbuf_window()); } return CallNextEventHandler (nextHandler, theEvent); }
pascal OSStatus pxWindowNative::doWindowResizeComplete(EventHandlerCallRef nextHandler, EventRef theEvent, void* userData) { pxWindowNative* w = (pxWindowNative*)userData; Rect rect; GetEventParameter(theEvent, kEventParamCurrentBounds, typeQDRectangle, NULL, sizeof(Rect), NULL, &rect); w->onSize(rect.right-rect.left, rect.bottom-rect.top); Rect r; GetWindowBounds(w->mWindowRef,kWindowContentRgn ,&r); r.right -= r.left; r.bottom -= r.top; r.left = r.top = 0; InvalWindowRect(w->mWindowRef,&r); return CallNextEventHandler (nextHandler, theEvent); }
static OSStatus EventHandler(EventHandlerCallRef next_handler, EventRef event, void* p) { switch (GetEventClass(event)) { case kEventClassWindow: { switch (GetEventKind(event)) { case kEventWindowClose: Shell::RequestExit(); break; } } break; } // InputMacOSX::ProcessCarbonEvent(event); return CallNextEventHandler(next_handler, event); }
pascal OSStatus COSXScreen::userSwitchCallback(EventHandlerCallRef nextHandler, EventRef theEvent, void* inUserData) { COSXScreen* screen = (COSXScreen*)inUserData; UInt32 kind = GetEventKind(theEvent); if (kind == kEventSystemUserSessionDeactivated) { LOG((CLOG_DEBUG "user session deactivated")); EVENTQUEUE->addEvent(CEvent(IScreen::getSuspendEvent(), screen->getEventTarget())); } else if (kind == kEventSystemUserSessionActivated) { LOG((CLOG_DEBUG "user session activated")); EVENTQUEUE->addEvent(CEvent(IScreen::getResumeEvent(), screen->getEventTarget())); } return (CallNextEventHandler(nextHandler, theEvent)); }
//default keyboard event handler static OSStatus KeyEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData) { OSStatus result = noErr; UInt32 class = GetEventClass (event); UInt32 kind = GetEventKind (event); result = CallNextEventHandler(nextHandler, event); if(class == kEventClassKeyboard) { char macCharCodes; UInt32 macKeyCode; UInt32 macKeyModifiers; GetEventParameter(event, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(macCharCodes), NULL, &macCharCodes); GetEventParameter(event, kEventParamKeyCode, typeUInt32, NULL, sizeof(macKeyCode), NULL, &macKeyCode); GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(macKeyModifiers), NULL, &macKeyModifiers); if(macKeyModifiers != 256) { if (kind == kEventRawKeyRepeat || kind == kEventRawKeyDown) { int key = convert_key(macKeyCode, macCharCodes); if(key != -1) mplayer_put_key(key); } } else if(macKeyModifiers == 256) { switch(macCharCodes) { case '[': SetWindowAlpha(theWindow, winAlpha-=0.05); break; case ']': SetWindowAlpha(theWindow, winAlpha+=0.05); break; } } else result = eventNotHandledErr; } return result; }
pascal OSStatus COSXScreen::userSwitchCallback(EventHandlerCallRef nextHandler, EventRef theEvent, void* inUserData) { COSXScreen* screen = (COSXScreen*)inUserData; UInt32 kind = GetEventKind(theEvent); IEventQueue* events = screen->getEvents(); if (kind == kEventSystemUserSessionDeactivated) { LOG((CLOG_DEBUG "user session deactivated")); events->addEvent(CEvent(events->forIScreen().suspend(), screen->getEventTarget())); } else if (kind == kEventSystemUserSessionActivated) { LOG((CLOG_DEBUG "user session activated")); events->addEvent(CEvent(events->forIScreen().resume(), screen->getEventTarget())); } return (CallNextEventHandler(nextHandler, theEvent)); }
/* Handle the messages necessary for creating the custom StarMenuFame class. */ OSStatus HandleStarFrameObjectEvents( EventHandlerCallRef inCallRef, EventRef inEvent, StarFrameData* frameData) { OSStatus err = eventNotHandledErr; switch ( GetEventKind( inEvent ) ) { case kEventHIObjectConstruct: frameData = (StarFrameData *) calloc(1, sizeof(StarFrameData)); frameData->menu = NULL; GetEventParameter(inEvent, kEventParamHIObjectInstance, typeHIObjectRef, NULL, sizeof( frameData->hiSelf ), NULL, &frameData->hiSelf ); // This important step actually associates our frameData with the view being initialized SetEventParameter(inEvent, kEventParamHIObjectInstance, typeVoidPtr, sizeof( frameData ), &frameData ); err = noErr; break; case kEventHIObjectInitialize: err = CallNextEventHandler( inCallRef, inEvent ); if ( err == noErr ) { GetEventParameter(inEvent, kEventParamMenuRef, typeMenuRef, NULL, sizeof(frameData->menu), NULL, &frameData->menu); GetEventParameter(inEvent, kEventParamMenuType, typeThemeMenuType, NULL, sizeof( frameData->menuType ), NULL, &frameData->menuType ); } err = noErr; break; case kEventHIObjectDestruct: free( (void*) frameData ); err = noErr; break; default: break; } return err; }
pascal OSStatus pxWindowNative::doKeyModifierChanged (EventHandlerCallRef nextHandler, EventRef theEvent, void* userData) { UInt32 modifier; GetEventParameter (theEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifier); pxWindowNative* w = (pxWindowNative*)userData; if (!(w->mLastModifierState & shiftKey) && (modifier & shiftKey)) w->onKeyDown(PX_KEY_SHIFT, 0); else if ((w->mLastModifierState & shiftKey) && !(modifier & shiftKey)) w->onKeyUp(PX_KEY_SHIFT, 0); if (!(w->mLastModifierState & optionKey) && (modifier & optionKey)) w->onKeyDown(PX_KEY_ALT, 0); else if ((w->mLastModifierState & optionKey) && !(modifier & optionKey)) w->onKeyUp(PX_KEY_ALT, 0); if (!(w->mLastModifierState & controlKey) && (modifier & controlKey)) w->onKeyDown(PX_KEY_CONTROL, 0); else if ((w->mLastModifierState & controlKey) && !(modifier & controlKey)) w->onKeyUp(PX_KEY_CONTROL, 0); if (!(w->mLastModifierState & alphaLock) && (modifier & alphaLock)) w->onKeyDown(PX_KEY_CAPSLOCK, 0); else if ((w->mLastModifierState & alphaLock) && !(modifier & alphaLock)) w->onKeyUp(PX_KEY_CAPSLOCK, 0); w->mLastModifierState = modifier; return CallNextEventHandler (nextHandler, theEvent); }
//------------------------------------------------------------------------ pascal OSStatus DoKeyUp (EventHandlerCallRef nextHandler, EventRef theEvent, void* userData) { char key_code; UInt32 modifier; GetEventParameter (theEvent, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(char), NULL, &key_code); GetEventParameter (theEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifier); platform_support * app = reinterpret_cast<platform_support*>(userData); app->m_specific->m_last_translated_key = 0; switch(modifier) { case controlKey: app->m_specific->m_input_flags &= ~kbd_ctrl; break; case shiftKey: app->m_specific->m_input_flags &= ~kbd_shift; break; } return CallNextEventHandler (nextHandler, theEvent); }
//------------------------------------------------------------------------ pascal OSStatus DoKeyDown (EventHandlerCallRef nextHandler, EventRef theEvent, void* userData) { char key_code; UInt32 modifier; GetEventParameter (theEvent, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(char), NULL, &key_code); GetEventParameter (theEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifier); platform_support * app = reinterpret_cast<platform_support*>(userData); app->m_specific->m_last_translated_key = 0; switch(modifier) { case controlKey: app->m_specific->m_input_flags |= kbd_ctrl; break; case shiftKey: app->m_specific->m_input_flags |= kbd_shift; break; default: app->m_specific->translate(key_code); break; } if(app->m_specific->m_last_translated_key) { bool left = false; bool up = false; bool right = false; bool down = false; switch(app->m_specific->m_last_translated_key) { case key_left: left = true; break; case key_up: up = true; break; case key_right: right = true; break; case key_down: down = true; break; //On a Mac, screenshots are handled by the system. case key_f2: app->copy_window_to_img(agg::platform_support::max_images - 1); app->save_img(agg::platform_support::max_images - 1, "screenshot"); break; } if(app->m_ctrls.on_arrow_keys(left, right, down, up)) { app->on_ctrl_change(); app->force_redraw(); } else { app->on_key(app->m_specific->m_cur_x, app->m_specific->m_cur_y, app->m_specific->m_last_translated_key, app->m_specific->m_input_flags); } } return CallNextEventHandler (nextHandler, theEvent); }
OSStatus CL_DisplayWindow_OpenGL::on_window_event(EventHandlerCallRef call_ref, EventRef event_ref, void *user_data) { CL_DisplayWindow_OpenGL *self = (CL_DisplayWindow_OpenGL *) user_data; OSStatus result = CallNextEventHandler(call_ref, event_ref); UInt32 event_class = GetEventClass(event_ref); UInt32 event_kind = GetEventKind(event_ref); if (event_class == kEventClassKeyboard) { Point mouse_pos; UInt32 key_modifiers = 0; UInt32 click_count = 0; UInt32 key_code = 0; // Todo: // KeyboardLayoutRef layout; // KLGetCurrentKeyboardLayout(&layout); // KLGetKeyboardLayoutProperty(layout, kKLuchrData, &data); // call UCKeyTranslate to get unicode string for keys being pressed. GetMouse(&mouse_pos); GetEventParameter(event_ref, kEventParamKeyModifiers, typeUInt32, 0, sizeof(UInt32), 0, &key_modifiers); GetEventParameter(event_ref, kEventParamKeyCode, typeUInt32, 0, sizeof(UInt32), 0, &key_code); GetEventParameter(event_ref, kEventParamClickCount, typeUInt32, 0, sizeof(UInt32), 0, &click_count); if (!self->fullscreen) { Rect wbounds; GetWindowBounds(self->window_ref, kWindowContentRgn, &wbounds); mouse_pos.h -= wbounds.left; mouse_pos.v -= wbounds.top; } static unsigned long state = 0; static Ptr keymap = nil; Ptr new_keymap; // Get the current keyboard map resource new_keymap = (Ptr)GetScriptManagerVariable(smKCHRCache); if (new_keymap != keymap) { keymap = new_keymap; state = 0; } CL_InputEvent event; event.str = KeyTranslate(keymap, key_code|key_modifiers, &state) & 0xffff; event.device = self->keyboard; event.mouse_pos = CL_Point(mouse_pos.h, mouse_pos.v); event.repeat_count = click_count; self->mouse_pos = event.mouse_pos; // if kEventParamMouseLocation is not valid here, reverse this. switch (event_kind) { case kEventRawKeyModifiersChanged: { std::set<int> current_keys = modifiercode_to_clkeys(key_modifiers); for (std::set<int>::iterator i=current_keys.begin(); i!=current_keys.end(); i++) { if (!self->prev_modifier_keys.count(*i)) { event.id = *i; event.type = CL_InputEvent::pressed; self->keyboard.sig_key_down().call(event); } } for (std::set<int>::iterator i=self->prev_modifier_keys.begin(); i!=self->prev_modifier_keys.end(); i++) { if (!current_keys.count(*i)) { event.id = *i; event.type = CL_InputEvent::released; self->keyboard.sig_key_up().call(event); } } self->prev_modifier_keys = current_keys; return noErr; } case kEventRawKeyDown: // first tests for cmd-q(12) or cmd-w(13) to close the window if needed if ((key_modifiers & cmdKey) && (key_code==12 || key_code==13)) { EventRef close_event; CreateEvent(NULL, kEventClassWindow, kEventWindowClose, 0, kEventAttributeNone, &close_event); EventTargetRef target = GetWindowEventTarget(self->window_ref); SendEventToEventTarget(close_event, target); return noErr; } else { event.id = keycode_to_clkey(key_code); event.type = CL_InputEvent::pressed; self->keyboard.sig_key_down().call(event); return noErr; } case kEventRawKeyRepeat: event.id = keycode_to_clkey(key_code); event.type = CL_InputEvent::pressed; self->keyboard.sig_key_down().call(event); return noErr; case kEventRawKeyUp: event.id = keycode_to_clkey(key_code); event.type = CL_InputEvent::released; self->keyboard.sig_key_up().call(event); return noErr; } } else if (event_class == kEventClassMouse) { Point mouse_pos; EventMouseButton mouse_button; UInt32 key_modifiers = 0; GetEventParameter(event_ref, kEventParamMouseLocation, typeQDPoint, 0, sizeof(Point), 0, &mouse_pos); GetEventParameter(event_ref, kEventParamMouseButton, typeMouseButton, 0, sizeof(EventMouseButton), 0, &mouse_button); GetEventParameter(event_ref, kEventParamKeyModifiers, typeUInt32, 0, sizeof(UInt32), 0, &key_modifiers); if (!self->fullscreen) { Rect wbounds; GetWindowBounds(self->window_ref, kWindowContentRgn, &wbounds); mouse_pos.h -= wbounds.left; mouse_pos.v -= wbounds.top; } CL_InputEvent event; event.id = mouse_button-1; event.device = self->mouse; event.mouse_pos = CL_Point(mouse_pos.h, mouse_pos.v); // Simulate second mouse button. if ((key_modifiers & controlKey) && (event.id == CL_MOUSE_LEFT)) event.id = CL_MOUSE_RIGHT; self->mouse_pos = event.mouse_pos; switch (event_kind) { case kEventMouseDown: self->mouse_states[event.id] = true; event.type = CL_InputEvent::pressed; self->mouse.sig_key_down().call(event); return noErr; case kEventMouseUp: self->mouse_states[event.id] = false; event.type = CL_InputEvent::released; self->mouse.sig_key_up().call(event); return noErr; case kEventMouseMoved: case kEventMouseDragged: self->mouse.sig_pointer_move().call(event); return noErr; case kEventMouseWheelMoved: //Note, this is not properly handling large quick wheel movements, but the implementation on other //platforms don't seem to either so I will do it their way for consistancy - mrfun EventMouseWheelAxis axis; GetEventParameter(event_ref, kEventParamMouseWheelAxis, typeMouseWheelAxis, NULL, sizeof(axis), NULL, &axis); if (axis == kEventMouseWheelAxisY) { long wheel_delta = 0; GetEventParameter(event_ref, kEventParamMouseWheelDelta, typeLongInteger, 0, sizeof(long), 0, &wheel_delta); //Ok, let me explain this bIgnoreThisOne thing. We are being passed two identical wheel events for every wheel movement - //This behavior is also in the apple example app GLCarbonAGLWindow and I can't figure out a way to get it to send only one //event or a difference in the events. (like a press and release tag differentiating them) //So the hack solution is to simply ignore every other mouse wheel event. This way, programs behave the same on every //platform instead of wheel zooming being twice as fast on macs. //If anybody has a better solution or finds a problem here please feel free to dig in. -mrfun static bool bIgnoreThisOne = true; bIgnoreThisOne = !bIgnoreThisOne; if (bIgnoreThisOne) if (wheel_delta) { if (wheel_delta > 0) { event.id = CL_MOUSE_WHEEL_UP; } else { event.id = CL_MOUSE_WHEEL_DOWN; } //sending both the down and up event, like the linux version event.type = CL_InputEvent::pressed; self->mouse.sig_key_down().call(event); event.type = CL_InputEvent::released; self->mouse.sig_key_up().call(event); } else { //handle the X axis someday? } } return noErr; } } else if (event_class == kEventClassWindow) { switch (event_kind) { case kEventWindowCollapsing: break; case kEventWindowDrawContent: { if (!self->fullscreen) { Rect rectPort; GetWindowPortBounds(self->window_ref, &rectPort); self->sig_paint( CL_Rect( rectPort.left, rectPort.top, rectPort.right, rectPort.bottom)); } } break; case kEventWindowShown: // called on initial show (not on un-minimize) break; case kEventWindowClose: self->sig_window_close(); return noErr; case kEventWindowActivated: case kEventWindowFocusAcquired: self->focus = true; self->sig_got_focus(); return noErr; case kEventWindowDeactivated: case kEventWindowFocusRelinquish: self->focus = false; self->sig_lost_focus(); return noErr; case kEventWindowBoundsChanged: { if (!self->fullscreen) { Rect rectPort; GetWindowPortBounds (self->window_ref, &rectPort); self->set_size(rectPort.right-rectPort.left, rectPort.bottom-rectPort.top); } } return noErr; case kEventWindowZoomed: // when maximized, but kEventWindowBoundsChanged is also called break; } } return result; }
static pascal OSStatus windowEventHandler(EventHandlerCallRef nextHandler, EventRef theEvent, void *inUserData) { CvWindow* window = NULL; UInt32 eventKind, eventClass; OSErr err = noErr; int event = 0; UInt32 count = 0; HIPoint point = {0,0}; EventMouseButton eventMouseButton = 0;//FD UInt32 modifiers;//FD WindowRef theWindow = (WindowRef)inUserData; if (theWindow == NULL) return eventNotHandledErr; window = icvWindowByHandle(theWindow); if ( window == NULL) return eventNotHandledErr; eventKind = GetEventKind(theEvent); eventClass = GetEventClass(theEvent); switch (eventClass) { case kEventClassMouse : { switch (eventKind){ case kEventMouseUp : case kEventMouseDown : case kEventMouseMoved : { err = CallNextEventHandler(nextHandler, theEvent); if (err != eventNotHandledErr) return err; err = GetEventParameter(theEvent, kEventParamMouseButton, typeMouseButton, NULL, sizeof(eventMouseButton), NULL, &eventMouseButton); err = GetEventParameter(theEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(modifiers), NULL, &modifiers); err = GetEventParameter(theEvent,kEventParamClickCount,typeUInt32,NULL,sizeof(UInt32),NULL,&count); if (err == noErr){ if (count >1) event += 6; } else { event = CV_EVENT_MOUSEMOVE; } if (eventKind == kEventMouseUp) event +=4; if (eventKind == kEventMouseDown) event +=1; err = GetEventParameter(theEvent, kEventParamWindowMouseLocation, typeHIPoint, NULL, sizeof(point), NULL, &point); if (eventKind != kEventMouseMoved){ switch(eventMouseButton){ case kEventMouseButtonPrimary: if (modifiers & controlKey) /* ctrl-click for right button */ event += 1; break; case kEventMouseButtonSecondary: event += 1; break; case kEventMouseButtonTertiary: event += 2; break; } } int c = icvCountTrackbarInWindow(window); if (window->on_mouse != NULL){ int lx,ly; Rect structure, content; GetWindowBounds(theWindow, kWindowStructureRgn, &structure); GetWindowBounds(theWindow, kWindowContentRgn, &content); lx = point.x - content.left + structure.left; ly = point.y - window->trackbarheight - content.top + structure.top; /* minus la taille des trackbars */ if (window->flags & CV_WINDOW_AUTOSIZE) {//FD //printf("was %d,%d\n", lx, ly); /* scale the mouse coordinates */ lx = lx * window->imageWidth / (content.right - content.left); ly = ly * window->imageHeight / (content.bottom - content.top - window->trackbarheight); //printf("now %d,%d\n", lx, ly); } //fprintf(stdout,"final OpenCV event is %d\n",event); //fprintf(stdout,"event @ %d %d which is localy %d %d offset of %d\n",point.h, point.v ,lx,ly,yOffset); if (lx>0 && ly >0){ /* a remettre dans les coordonnŽes locale */ window->on_mouse(event,lx,ly,0,NULL); } } } default : return eventNotHandledErr; } } case kEventClassWindow : {//FD switch (eventKind){ case kEventWindowBoundsChanged : { /* resize the trackbars */ CvTrackbar *t; Rect bounds; GetWindowBounds(window->window,kWindowContentRgn,&bounds); for ( t = window->toolbar.first; t != 0; t = t->next ) SizeControl(t->trackbar,bounds.right - bounds.left - INTERWIDGETSPACE*3 - LABELWIDTH , WIDGETHEIGHT); } /* redraw the image */ icvDrawImage(window); break; default : return eventNotHandledErr; } } default: return eventNotHandledErr; } return eventNotHandledErr; }
static OSStatus menu_event_handler_func (EventHandlerCallRef event_handler_call_ref, EventRef event_ref, void *data) { UInt32 event_class = GetEventClass (event_ref); UInt32 event_kind = GetEventKind (event_ref); MenuRef menu_ref; switch (event_class) { case kEventClassCommand: /* This is called when activating (is that the right GTK+ term?) * a menu item. */ if (event_kind == kEventCommandProcess) { HICommand command; OSStatus err; /*g_printerr ("Menu: kEventClassCommand/kEventCommandProcess\n");*/ err = GetEventParameter (event_ref, kEventParamDirectObject, typeHICommand, 0, sizeof (command), 0, &command); if (err == noErr) { GtkWidget *widget = NULL; /* Get any GtkWidget associated with the item. */ err = GetMenuItemProperty (command.menu.menuRef, command.menu.menuItemIndex, IGE_QUARTZ_MENU_CREATOR, IGE_QUARTZ_ITEM_WIDGET, sizeof (widget), 0, &widget); if (err == noErr && GTK_IS_WIDGET (widget)) { gtk_menu_item_activate (GTK_MENU_ITEM (widget)); return noErr; } } } break; case kEventClassMenu: GetEventParameter (event_ref, kEventParamDirectObject, typeMenuRef, NULL, sizeof (menu_ref), NULL, &menu_ref); switch (event_kind) { case kEventMenuTargetItem: /* This is called when an item is selected (what is the * GTK+ term? prelight?) */ /*g_printerr ("kEventClassMenu/kEventMenuTargetItem\n");*/ break; case kEventMenuOpening: /* Is it possible to dynamically build the menu here? We * can at least set visibility/sensitivity. */ /*g_printerr ("kEventClassMenu/kEventMenuOpening\n");*/ break; case kEventMenuClosed: /*g_printerr ("kEventClassMenu/kEventMenuClosed\n");*/ break; default: break; } break; default: break; } return CallNextEventHandler (event_handler_call_ref, event_ref); }