- 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 ;
- }
- WindowRef window ;
- short windowPart = ::FindWindow(point, &window);
-
- // either we really are active or we are capturing mouse events
-
- if ( (IsWindowActive(window) && windowPart == inContent) ||
- (wxTheApp->s_captureWindow && wxTheApp->s_captureWindow->MacGetTopLevelWindow() == toplevelWindow) )
+ UInt32 clickCount = 0 ;
+ UInt32 mouseChord = 0;
+
+ cEvent.GetParameter<EventMouseButton>( kEventParamMouseButton, typeMouseButton , &button ) ;
+ cEvent.GetParameter<UInt32>( kEventParamClickCount, typeUInt32 , &clickCount ) ;
+ // the chord is the state of the buttons pressed currently
+ cEvent.GetParameter<UInt32>( kEventParamMouseChord, typeUInt32 , &mouseChord ) ;
+
+ 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.m_clickCount = clickCount;
+ wxevent.SetTimestamp( cEvent.GetTicks() ) ;
+
+ // a control click is interpreted as a right click
+ bool thisButtonIsFakeRight = false ;
+ if ( button == kEventMouseButtonPrimary && (modifiers & controlKey) )
+ {
+ button = kEventMouseButtonSecondary ;
+ thisButtonIsFakeRight = true ;
+ }
+
+ // otherwise we report double clicks by connecting a left click with a ctrl-left click
+ if ( clickCount > 1 && button != g_lastButton )
+ clickCount = 1 ;
+
+ // we must make sure that our synthetic 'right' button corresponds in
+ // mouse down, moved and mouse up, and does not deliver a right down and left up
+
+ if ( cEvent.GetKind() == kEventMouseDown )
+ {
+ g_lastButton = button ;
+ g_lastButtonWasFakeRight = thisButtonIsFakeRight ;
+ }
+
+ if ( button == 0 )
+ {
+ g_lastButton = 0 ;
+ g_lastButtonWasFakeRight = false ;
+ }
+ else if ( g_lastButton == kEventMouseButtonSecondary && g_lastButtonWasFakeRight )
+ button = g_lastButton ;
+
+ // Adjust the chord mask to remove the primary button and add the
+ // secondary button. It is possible that the secondary button is
+ // already pressed, e.g. on a mouse connected to a laptop, but this
+ // possibility is ignored here:
+ if( thisButtonIsFakeRight && ( mouseChord & 1U ) )
+ mouseChord = ((mouseChord & ~1U) | 2U);
+
+ if(mouseChord & 1U)
+ wxevent.m_leftDown = true ;
+ if(mouseChord & 2U)
+ wxevent.m_rightDown = true ;
+ if(mouseChord & 4U)
+ wxevent.m_middleDown = true ;
+
+ // translate into wx types
+ switch ( cEvent.GetKind() )
+ {
+ case kEventMouseDown :
+ switch ( button )
+ {
+ case kEventMouseButtonPrimary :
+ wxevent.SetEventType( clickCount > 1 ? wxEVT_LEFT_DCLICK : wxEVT_LEFT_DOWN ) ;
+ break ;
+
+ case kEventMouseButtonSecondary :
+ wxevent.SetEventType( clickCount > 1 ? wxEVT_RIGHT_DCLICK : wxEVT_RIGHT_DOWN ) ;
+ break ;
+
+ case kEventMouseButtonTertiary :
+ wxevent.SetEventType( clickCount > 1 ? wxEVT_MIDDLE_DCLICK : wxEVT_MIDDLE_DOWN ) ;
+ break ;
+
+ default:
+ break ;
+ }
+ break ;
+
+ case kEventMouseUp :
+ switch ( button )
+ {
+ case kEventMouseButtonPrimary :
+ wxevent.SetEventType( wxEVT_LEFT_UP ) ;
+ break ;
+
+ case kEventMouseButtonSecondary :
+ wxevent.SetEventType( wxEVT_RIGHT_UP ) ;
+ break ;
+
+ case kEventMouseButtonTertiary :
+ wxevent.SetEventType( wxEVT_MIDDLE_UP ) ;
+ break ;
+
+ default:
+ break ;
+ }
+ break ;
+
+ case kEventMouseWheelMoved :
+ {
+ wxevent.SetEventType( wxEVT_MOUSEWHEEL ) ;
+
+ EventMouseWheelAxis axis = cEvent.GetParameter<EventMouseWheelAxis>(kEventParamMouseWheelAxis, typeMouseWheelAxis) ;
+ SInt32 delta = cEvent.GetParameter<SInt32>(kEventParamMouseWheelDelta, typeSInt32) ;
+
+ wxevent.m_wheelRotation = delta;
+ wxevent.m_wheelDelta = 1;
+ wxevent.m_linesPerAction = 1;
+ if ( axis == kEventMouseWheelAxisX )
+ wxevent.m_wheelAxis = 1;
+ }
+ break ;
+
+ case kEventMouseEntered :
+ case kEventMouseExited :
+ case kEventMouseDragged :
+ case kEventMouseMoved :
+ wxevent.SetEventType( wxEVT_MOTION ) ;
+ break;
+ default :
+ break ;
+ }
+}
+
+#define NEW_CAPTURE_HANDLING 1
+
+pascal OSStatus
+wxMacTopLevelMouseEventHandler(EventHandlerCallRef WXUNUSED(handler),
+ EventRef event,
+ void *data)
+{
+ wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ;
+
+ OSStatus result = eventNotHandledErr ;
+
+ 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 )