+ UInt32 modifiers = cEvent.GetParameter<UInt32>(kEventParamKeyModifiers, typeUInt32) ;
+ Point screenMouseLocation = cEvent.GetParameter<Point>(kEventParamMouseLocation) ;
+
+ // this parameter are not given for all events
+ EventMouseButton button = 0 ;
+ UInt32 clickCount = 0 ;
+ cEvent.GetParameter<EventMouseButton>(kEventParamMouseButton, typeMouseButton , &button) ;
+ cEvent.GetParameter<UInt32>(kEventParamClickCount, typeUInt32 , &clickCount ) ;
+
+ wxevent.m_x = screenMouseLocation.h;
+ wxevent.m_y = screenMouseLocation.v;
+ wxevent.m_shiftDown = modifiers & shiftKey;
+ wxevent.m_controlDown = modifiers & controlKey;
+ wxevent.m_altDown = modifiers & optionKey;
+ wxevent.m_metaDown = modifiers & cmdKey;
+ wxevent.SetTimestamp( cEvent.GetTicks() ) ;
+ // a control click is interpreted as a right click
+ if ( button == kEventMouseButtonPrimary && (modifiers & controlKey) )
+ {
+ button = kEventMouseButtonSecondary ;
+ }
+
+ // determinate the correct down state, wx does not want a 'down' for a mouseUp event, while mac delivers
+ // this button
+ if ( button != 0 && cEvent.GetKind() != kEventMouseUp )
+ {
+ switch( button )
+ {
+ case kEventMouseButtonPrimary :
+ wxevent.m_leftDown = true ;
+ break ;
+ case kEventMouseButtonSecondary :
+ wxevent.m_rightDown = true ;
+ break ;
+ case kEventMouseButtonTertiary :
+ wxevent.m_middleDown = true ;
+ break ;
+ }
+ }
+ // determinate the correct click button
+ if ( button == kEventMouseButtonSecondary )
+ {
+ if (cEvent.GetKind() == kEventMouseDown )
+ wxevent.SetEventType( clickCount > 1 ? wxEVT_RIGHT_DCLICK : wxEVT_RIGHT_DOWN ) ;
+ else if ( cEvent.GetKind() == kEventMouseUp )
+ wxevent.SetEventType(wxEVT_RIGHT_UP ) ;
+ }
+ else if ( button == kEventMouseButtonTertiary )
+ {
+ if (cEvent.GetKind() == kEventMouseDown )
+ wxevent.SetEventType(clickCount > 1 ? wxEVT_MIDDLE_DCLICK : wxEVT_MIDDLE_DOWN ) ;
+ else if ( cEvent.GetKind() == kEventMouseUp )
+ wxevent.SetEventType(wxEVT_MIDDLE_UP ) ;
+ }
+ else
+ {
+ if (cEvent.GetKind() == kEventMouseDown )
+ wxevent.SetEventType(clickCount > 1 ? wxEVT_LEFT_DCLICK : wxEVT_LEFT_DOWN ) ;
+ else if ( cEvent.GetKind() == kEventMouseUp )
+ wxevent.SetEventType(wxEVT_LEFT_UP ) ;
+ else if ( cEvent.GetKind() == kEventMouseWheelMoved )
+ {
+ wxevent.SetEventType(wxEVT_MOUSEWHEEL ) ;
+
+ // EventMouseWheelAxis axis = cEvent.GetParameter<EventMouseWheelAxis>(kEventParamMouseWheelAxis, typeMouseWheelAxis) ;
+ SInt32 delta = cEvent.GetParameter<SInt32>(kEventParamMouseWheelDelta, typeLongInteger) ;
+
+ wxevent.m_wheelRotation = delta;
+ wxevent.m_wheelDelta = 1;
+ wxevent.m_linesPerAction = 1;
+ }
+ else
+ wxevent.SetEventType(wxEVT_MOTION ) ;
+ }
+}
+
+ControlRef wxMacFindSubControl( Point location , ControlRef superControl , ControlPartCode *outPart )
+{
+ if ( superControl )
+ {
+ UInt16 childrenCount = 0 ;
+ OSStatus err = CountSubControls( superControl , &childrenCount ) ;
+ if ( err == errControlIsNotEmbedder )
+ return NULL ;
+ wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ) ;
+
+ for ( UInt16 i = childrenCount ; i >=1 ; --i )
+ {
+ ControlHandle sibling ;
+ err = GetIndexedSubControl( superControl , i , & sibling ) ;
+ if ( err == errControlIsNotEmbedder )
+ return NULL ;
+
+ wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ) ;
+ if ( IsControlVisible( sibling ) )
+ {
+ Rect r ;
+ GetControlBounds( sibling , &r ) ;
+ if ( MacPtInRect( location , &r ) )
+ {
+ ControlHandle child = wxMacFindSubControl( location , sibling , outPart ) ;
+ if ( child )
+ return child ;
+ else
+ {
+ *outPart = TestControl( sibling , location ) ;
+ return sibling ;
+ }
+ }
+ }
+ }
+ }
+ return NULL ;
+}
+
+ControlRef wxMacFindControlUnderMouse( Point location , WindowRef window , ControlPartCode *outPart )
+{
+#if TARGET_API_MAC_OSX
+ if ( UMAGetSystemVersion() >= 0x1030 )
+ return FindControlUnderMouse( location , window , outPart ) ;
+#endif
+ ControlRef rootControl = NULL ;
+ verify_noerr( GetRootControl( window , &rootControl ) ) ;
+ return wxMacFindSubControl( location , rootControl , outPart ) ;
+
+}
+pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
+{
+