- wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ;
- Point point ;
- UInt32 modifiers = 0;
- EventMouseButton button = 0 ;
- UInt32 click = 0 ;
-
- GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL,
- sizeof( Point ), NULL, &point );
- GetEventParameter( event, kEventParamKeyModifiers, typeUInt32, NULL,
- sizeof( UInt32 ), NULL, &modifiers );
- GetEventParameter( event, kEventParamMouseButton, typeMouseButton, NULL,
- sizeof( EventMouseButton ), NULL, &button );
- GetEventParameter( event, kEventParamClickCount, typeUInt32, NULL,
- sizeof( UInt32 ), NULL, &click );
-
- if ( button == 0 || GetEventKind( event ) == kEventMouseUp )
- modifiers += btnState ;
-
- WindowRef window ;
- short windowPart = ::FindWindow(point, &window);
- if ( windowPart == inContent )
- {
- switch ( GetEventKind( event ) )
- {
- case kEventMouseDown :
- toplevelWindow->MacFireMouseEvent( mouseDown , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ;
- result = noErr ;
- break ;
- case kEventMouseUp :
- toplevelWindow->MacFireMouseEvent( mouseUp , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ;
- result = noErr ;
- break ;
- case kEventMouseMoved :
- toplevelWindow->MacFireMouseEvent( nullEvent , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ;
- result = noErr ;
- break ;
- case kEventMouseDragged :
- toplevelWindow->MacFireMouseEvent( nullEvent , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ;
- result = noErr ;
- break ;
- default :
- break ;
- }
+ wxWindow* focus = wxWindow::FindFocus() ;
+ char charCode ;
+ UInt32 keyCode ;
+ UInt32 modifiers ;
+ Point point ;
+ UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ;
+
+ GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode );
+ GetEventParameter( event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode );
+ GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers);
+ GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL,
+ sizeof( Point ), NULL, &point );
+
+ UInt32 message = (keyCode << 8) + charCode;
+ switch( GetEventKind( event ) )
+ {
+ case kEventRawKeyRepeat :
+ case kEventRawKeyDown :
+ {
+ WXEVENTREF formerEvent = wxTheApp->MacGetCurrentEvent() ;
+ WXEVENTHANDLERCALLREF formerHandler = wxTheApp->MacGetCurrentEventHandlerCallRef() ;
+ wxTheApp->MacSetCurrentEvent( event , handler ) ;
+ if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent(
+ focus , message , modifiers , when , point.h , point.v ) )
+ {
+ result = noErr ;
+ }
+ wxTheApp->MacSetCurrentEvent( formerEvent , formerHandler ) ;
+ }
+ break ;
+ case kEventRawKeyUp :
+ if ( (focus != NULL) && wxTheApp->MacSendKeyUpEvent(
+ focus , message , modifiers , when , point.h , point.v ) )
+ {
+ result = noErr ;
+ }
+ break ;
+ case kEventRawKeyModifiersChanged :
+ {
+ wxKeyEvent event(wxEVT_KEY_DOWN);
+
+ event.m_shiftDown = modifiers & shiftKey;
+ event.m_controlDown = modifiers & controlKey;
+ event.m_altDown = modifiers & optionKey;
+ event.m_metaDown = modifiers & cmdKey;
+
+ event.m_x = point.h;
+ event.m_y = point.v;
+ event.m_timeStamp = when;
+ wxWindow* focus = wxWindow::FindFocus() ;
+ event.SetEventObject(focus);
+
+ if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & controlKey )
+ {
+ event.m_keyCode = WXK_CONTROL ;
+ event.SetEventType( ( modifiers & controlKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
+ focus->GetEventHandler()->ProcessEvent( event ) ;
+ }
+ if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & shiftKey )
+ {
+ event.m_keyCode = WXK_SHIFT ;
+ event.SetEventType( ( modifiers & shiftKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
+ focus->GetEventHandler()->ProcessEvent( event ) ;
+ }
+ if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & optionKey )
+ {
+ event.m_keyCode = WXK_ALT ;
+ event.SetEventType( ( modifiers & optionKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
+ focus->GetEventHandler()->ProcessEvent( event ) ;
+ }
+ if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & cmdKey )
+ {
+ event.m_keyCode = WXK_COMMAND ;
+ event.SetEventType( ( modifiers & cmdKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
+ focus->GetEventHandler()->ProcessEvent( event ) ;
+ }
+ wxTheApp->s_lastModifiers = modifiers ;
+ }
+ break ;
+ }
+
+ return result ;
+}
+
+pascal OSStatus MouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
+{
+ OSStatus result = eventNotHandledErr ;
+
+ wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ;
+ Point point ;
+ UInt32 modifiers = 0;
+ EventMouseButton button = 0 ;
+ UInt32 click = 0 ;
+
+ GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL,
+ sizeof( Point ), NULL, &point );
+ GetEventParameter( event, kEventParamKeyModifiers, typeUInt32, NULL,
+ sizeof( UInt32 ), NULL, &modifiers );
+ GetEventParameter( event, kEventParamMouseButton, typeMouseButton, NULL,
+ sizeof( EventMouseButton ), NULL, &button );
+ GetEventParameter( event, kEventParamClickCount, typeUInt32, NULL,
+ sizeof( UInt32 ), NULL, &click );
+
+ if ( button == 0 || GetEventKind( event ) == kEventMouseUp )
+ modifiers += btnState ;
+
+ // temporary hack to support true two button mouse
+ if ( button == kEventMouseButtonSecondary )
+ {
+ modifiers |= controlKey ;