+ // 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 ) ;
+
+#if wxUSE_TOOLTIPS
+ wxToolTip::RelayEvent( g_MacLastWindow , eventleave);
+#endif // wxUSE_TOOLTIPS
+ 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 ) ;
+#if wxUSE_TOOLTIPS
+ wxToolTip::RelayEvent( currentMouseWindow , evententer);
+#endif // wxUSE_TOOLTIPS
+ 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 ;
+ }
+ } // if ( windowPart == inMenuBar )
+ else if ( currentMouseWindow )
+ {
+ wxWindow *currentMouseWindowParent = currentMouseWindow->GetParent();
+
+ currentMouseWindow->ScreenToClient( &wxevent.m_x , &wxevent.m_y ) ;
+
+ wxevent.SetEventObject( currentMouseWindow ) ;
+
+ // make tooltips current
+
+ #if wxUSE_TOOLTIPS
+ if ( wxevent.GetEventType() == wxEVT_MOTION
+ || wxevent.GetEventType() == wxEVT_ENTER_WINDOW
+ || wxevent.GetEventType() == wxEVT_LEAVE_WINDOW )
+ wxToolTip::RelayEvent( currentMouseWindow , wxevent);
+ #endif // wxUSE_TOOLTIPS
+ 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 ) &&
+ (FindControlUnderMouse(windowMouseLocation , window , &dummyPart) !=
+ wxMacFindControlUnderMouse( windowMouseLocation , window , &dummyPart ) ) )
+ {
+ if ( currentMouseWindow->MacIsReallyEnabled() )
+ {
+ EventModifiers modifiers = cEvent.GetParameter<EventModifiers>(kEventParamKeyModifiers, typeUInt32) ;
+ Point clickLocation = windowMouseLocation ;
+ #if TARGET_API_MAC_OSX
+ currentMouseWindow->MacRootWindowToWindow( &clickLocation.h , &clickLocation.v ) ;
+ #endif
+ HandleControlClick( (ControlRef) currentMouseWindow->GetHandle() , clickLocation ,
+ modifiers , (ControlActionUPP ) -1 ) ;
+
+ if ((currentMouseWindowParent != NULL) &&
+ (currentMouseWindowParent->GetChildren().Find(currentMouseWindow) == NULL))
+ currentMouseWindow = NULL;
+ }
+ result = noErr ;
+ }
+ }
+ if ( cEvent.GetKind() == kEventMouseUp && wxTheApp->s_captureWindow )
+ {
+ wxTheApp->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 if ( currentMouseWindow )
+ else
+ {
+ // 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
+ wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ;
+ 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
+ HandleControlClick( control , clickLocation ,
+ modifiers , (ControlActionUPP ) -1 ) ;
+ result = noErr ;
+ }
+ }
+ return result ;