- 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 ( IsWindowActive(window) && 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 ;
- }
- }
-
- return result ;
-
-
-}
-static pascal OSStatus WindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
+ wxMacCarbonEvent cEvent( event ) ;
+
+ Point screenMouseLocation = cEvent.GetParameter<Point>(kEventParamMouseLocation) ;
+ Point windowMouseLocation = screenMouseLocation ;
+
+ WindowRef window = NULL;
+ short windowPart = ::FindWindow(screenMouseLocation, &window);
+
+ wxWindow* currentMouseWindow = NULL ;
+ ControlRef control = NULL ;
+
+#if NEW_CAPTURE_HANDLING
+ if ( wxApp::s_captureWindow )
+ {
+ window = (WindowRef) wxApp::s_captureWindow->MacGetTopLevelWindowRef() ;
+ windowPart = inContent ;
+ }
+#endif
+
+ if ( window )
+ {
+ QDGlobalToLocalPoint( UMAGetWindowPort(window ) , &windowMouseLocation ) ;
+
+ if ( wxApp::s_captureWindow
+#if !NEW_CAPTURE_HANDLING
+ && wxApp::s_captureWindow->MacGetTopLevelWindowRef() == (WXWindow) window && windowPart == inContent
+#endif
+ )
+ {
+ currentMouseWindow = wxApp::s_captureWindow ;
+ }
+ else if ( (IsWindowActive(window) && windowPart == inContent) )
+ {
+ ControlPartCode part ;
+ control = wxMacFindControlUnderMouse( toplevelWindow , windowMouseLocation , window , &part ) ;
+ // if there is no control below the mouse position, send the event to the toplevel window itself
+ if ( control == 0 )
+ {
+ currentMouseWindow = (wxWindow*) data ;
+ }
+ else
+ {
+ currentMouseWindow = wxFindControlFromMacControl( control ) ;
+ if ( currentMouseWindow == NULL && cEvent.GetKind() == kEventMouseMoved )
+ {
+#if wxUSE_TOOLBAR
+ // for wxToolBar to function we have to send certaint events to it
+ // instead of its children (wxToolBarTools)
+ ControlRef parent ;
+ GetSuperControl(control, &parent );
+ wxWindow *wxParent = wxFindControlFromMacControl( parent ) ;
+ if ( wxParent && wxParent->IsKindOf( CLASSINFO( wxToolBar ) ) )
+ currentMouseWindow = wxParent ;
+#endif
+ }
+ }
+
+ // disabled windows must not get any input messages
+ if ( currentMouseWindow && !currentMouseWindow->MacIsReallyEnabled() )
+ currentMouseWindow = NULL;
+ }
+ }
+
+ wxMouseEvent wxevent(wxEVT_LEFT_DOWN);
+ SetupMouseEvent( wxevent , cEvent ) ;
+
+ // handle all enter / leave events
+
+ if ( currentMouseWindow != g_MacLastWindow )
+ {
+ if ( g_MacLastWindow )
+ {
+ wxMouseEvent eventleave(wxevent);
+ eventleave.SetEventType( wxEVT_LEAVE_WINDOW );
+ g_MacLastWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y );
+ eventleave.SetEventObject( g_MacLastWindow ) ;
+ wxevent.SetId( g_MacLastWindow->GetId() ) ;
+
+#if wxUSE_TOOLTIPS
+ wxToolTip::RelayEvent( g_MacLastWindow , eventleave);
+#endif
+
+ g_MacLastWindow->GetEventHandler()->ProcessEvent(eventleave);
+ }
+
+ if ( currentMouseWindow )
+ {
+ wxMouseEvent evententer(wxevent);
+ evententer.SetEventType( wxEVT_ENTER_WINDOW );
+ currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y );
+ evententer.SetEventObject( currentMouseWindow ) ;
+ wxevent.SetId( currentMouseWindow->GetId() ) ;
+
+#if wxUSE_TOOLTIPS
+ wxToolTip::RelayEvent( currentMouseWindow , evententer );
+#endif
+
+ currentMouseWindow->GetEventHandler()->ProcessEvent(evententer);
+ }
+
+ g_MacLastWindow = currentMouseWindow ;
+ }
+
+ if ( windowPart == inMenuBar )
+ {
+ // special case menu bar, as we are having a low-level runloop we must do it ourselves
+ if ( cEvent.GetKind() == kEventMouseDown )
+ {
+ ::MenuSelect( screenMouseLocation ) ;
+ result = noErr ;
+ }
+ }
+ else if ( currentMouseWindow )
+ {
+ wxWindow *currentMouseWindowParent = currentMouseWindow->GetParent();
+
+ currentMouseWindow->ScreenToClient( &wxevent.m_x , &wxevent.m_y ) ;
+
+ wxevent.SetEventObject( currentMouseWindow ) ;
+ wxevent.SetId( currentMouseWindow->GetId() ) ;
+
+ // make tooltips current
+
+#if wxUSE_TOOLTIPS
+ if ( wxevent.GetEventType() == wxEVT_MOTION )
+ wxToolTip::RelayEvent( currentMouseWindow , wxevent );
+#endif
+
+ if ( currentMouseWindow->GetEventHandler()->ProcessEvent(wxevent) )
+ {
+ if ((currentMouseWindowParent != NULL) &&
+ (currentMouseWindowParent->GetChildren().Find(currentMouseWindow) == NULL))
+ currentMouseWindow = NULL;
+
+ result = noErr;
+ }
+ else
+ {
+ // if the user code did _not_ handle the event, then perform the
+ // default processing
+ if ( wxevent.GetEventType() == wxEVT_LEFT_DOWN )
+ {
+ // ... that is set focus to this window
+ if (currentMouseWindow->AcceptsFocus() && wxWindow::FindFocus()!=currentMouseWindow)
+ currentMouseWindow->SetFocus();
+ }
+
+ ControlPartCode dummyPart ;
+ // if built-in find control is finding the wrong control (ie static box instead of overlaid
+ // button, we cannot let the standard handler do its job, but must handle manually
+
+ if ( ( cEvent.GetKind() == kEventMouseDown )
+#ifdef __WXMAC_OSX__
+ &&
+ (FindControlUnderMouse(windowMouseLocation , window , &dummyPart) !=
+ wxMacFindControlUnderMouse( toplevelWindow , windowMouseLocation , window , &dummyPart ) )
+#endif
+ )
+ {
+ if ( currentMouseWindow->MacIsReallyEnabled() )
+ {
+ EventModifiers modifiers = cEvent.GetParameter<EventModifiers>(kEventParamKeyModifiers, typeUInt32) ;
+ Point clickLocation = windowMouseLocation ;
+
+ currentMouseWindow->MacRootWindowToWindow( &clickLocation.h , &clickLocation.v ) ;
+
+ HandleControlClick( (ControlRef) currentMouseWindow->GetHandle() , clickLocation ,
+ modifiers , (ControlActionUPP ) -1 ) ;
+
+ if ((currentMouseWindowParent != NULL) &&
+ (currentMouseWindowParent->GetChildren().Find(currentMouseWindow) == NULL))
+ {
+ currentMouseWindow = NULL;
+ }
+ }
+
+ result = noErr ;
+ }
+ }
+
+ if ( cEvent.GetKind() == kEventMouseUp && wxApp::s_captureWindow )
+ {
+ wxApp::s_captureWindow = NULL ;
+ // update cursor ?
+ }
+
+ // update cursor
+
+ wxWindow* cursorTarget = currentMouseWindow ;
+ wxPoint cursorPoint( wxevent.m_x , wxevent.m_y ) ;
+
+ while ( cursorTarget && !cursorTarget->MacSetupCursor( cursorPoint ) )
+ {
+ cursorTarget = cursorTarget->GetParent() ;
+ if ( cursorTarget )
+ cursorPoint += cursorTarget->GetPosition();
+ }
+
+ }
+ else // currentMouseWindow == NULL
+ {
+ // don't mess with controls we don't know about
+ // for some reason returning eventNotHandledErr does not lead to the correct behaviour
+ // so we try sending them the correct control directly
+ if ( cEvent.GetKind() == kEventMouseDown && toplevelWindow && control )
+ {
+ EventModifiers modifiers = cEvent.GetParameter<EventModifiers>(kEventParamKeyModifiers, typeUInt32) ;
+ Point clickLocation = windowMouseLocation ;
+#if TARGET_API_MAC_OSX
+ HIPoint hiPoint ;
+ hiPoint.x = clickLocation.h ;
+ hiPoint.y = clickLocation.v ;
+ HIViewConvertPoint( &hiPoint , (ControlRef) toplevelWindow->GetHandle() , control ) ;
+ clickLocation.h = (int)hiPoint.x ;
+ clickLocation.v = (int)hiPoint.y ;
+#endif // TARGET_API_MAC_OSX
+
+ HandleControlClick( control , clickLocation , modifiers , (ControlActionUPP ) -1 ) ;
+ result = noErr ;
+ }
+ }
+
+ return result ;
+}
+
+static pascal OSStatus wxMacTopLevelWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data )