+ // 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() >= 1030 )
+ 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 )
+{
+
+ OSStatus result = eventNotHandledErr ;
+
+ wxMacCarbonEvent cEvent( event ) ;
+
+ Point screenMouseLocation = cEvent.GetParameter<Point>(kEventParamMouseLocation) ;
+ Point windowMouseLocation = screenMouseLocation ;
+
+ WindowRef window ;
+ short windowPart = ::FindWindow(screenMouseLocation, &window);
+
+ wxWindow* currentMouseWindow = NULL ;
+ if ( window )
+ {
+ // calculate window relative coordinates
+ GrafPtr port;
+ ::GetPort( &port ) ;
+ ::SetPort( UMAGetWindowPort(window ) ) ;
+ ::GlobalToLocal( &windowMouseLocation ) ;
+ ::SetPort( port ) ;
+
+ if ( wxTheApp->s_captureWindow && wxTheApp->s_captureWindow->MacGetTopLevelWindowRef() == (WXWindow) window && windowPart == inContent )
+ {
+ currentMouseWindow = wxTheApp->s_captureWindow ;
+ }
+ else if ( (IsWindowActive(window) && windowPart == inContent) )
+ {
+ ControlPartCode part ;
+ ControlRef control = wxMacFindControlUnderMouse( windowMouseLocation , window , &part ) ;
+ if ( control == 0 )
+ currentMouseWindow = (wxWindow*) data ;
+ else
+ currentMouseWindow = wxFindControlFromMacControl( control ) ;
+ }
+ }
+
+ wxMouseEvent wxevent(wxEVT_LEFT_DOWN);
+ SetupMouseEvent( wxevent , cEvent ) ;
+
+ // handle all enter / leave events