diff options
author | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2009-11-23 17:56:03 +0100 |
---|---|---|
committer | Jason McDonald <jason.mcdonald@nokia.com> | 2009-11-25 11:50:50 +1000 |
commit | 49360b3237363db2a8d6c6eeafb0aaa83d3efdc0 (patch) | |
tree | 8c6cdbae6abd1e82e2b28c5a0c35c642f722bab7 /src | |
parent | 4e5173e37ac2ea60d53ac59b7a6838c8e286d67e (diff) | |
download | qt4-tools-49360b3237363db2a8d6c6eeafb0aaa83d3efdc0.tar.gz |
Fixes implicit grabbing in Qt/Cocoa
When delivering mouse events in Qt/Cocoa set the implicit mouse grabber and
deliver the event to it and do not try to propagate the event to the parent
view.
Reviewed-by: Prasanth
(cherry picked from commit aae81f370f6afede95064bc75eb7ee6ac13b1c30)
(cherry picked from commit 106121a74bca32a6411b9ca968ee415f8bdfbff1)
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/kernel/qcocoaview_mac.mm | 51 | ||||
-rw-r--r-- | src/gui/kernel/qt_cocoa_helpers_mac.mm | 8 |
2 files changed, 29 insertions, 30 deletions
diff --git a/src/gui/kernel/qcocoaview_mac.mm b/src/gui/kernel/qcocoaview_mac.mm index d02cf94eb8..4229d4efc7 100644 --- a/src/gui/kernel/qcocoaview_mac.mm +++ b/src/gui/kernel/qcocoaview_mac.mm @@ -79,6 +79,7 @@ extern bool qt_sendSpontaneousEvent(QObject *, QEvent *); // qapplication.cpp extern OSViewRef qt_mac_nativeview_for(const QWidget *w); // qwidget_mac.mm extern const QStringList& qEnabledDraggedTypes(); // qmime_mac.cpp extern QPointer<QWidget> qt_mouseover; //qapplication_mac.mm +extern QPointer<QWidget> qt_button_down; //qapplication_mac.cpp Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum) { @@ -691,6 +692,9 @@ extern "C" { - (void)mouseDown:(NSEvent *)theEvent { + if (!qt_button_down) + qt_button_down = qwidget; + qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseButtonPress, Qt::LeftButton); // Don't call super here. This prevents us from getting the mouseUp event, // which we need to send even if the mouseDown event was not accepted. @@ -700,75 +704,62 @@ extern "C" { - (void)mouseUp:(NSEvent *)theEvent { - bool mouseOK = qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseButtonRelease, Qt::LeftButton); + qt_button_down = 0; - if (!mouseOK) - [super mouseUp:theEvent]; + qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseButtonRelease, Qt::LeftButton); } - (void)rightMouseDown:(NSEvent *)theEvent { - bool mouseOK = qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseButtonPress, Qt::RightButton); + if (!qt_button_down) + qt_button_down = qwidget; - if (!mouseOK) - [super rightMouseDown:theEvent]; + qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseButtonPress, Qt::RightButton); } - (void)rightMouseUp:(NSEvent *)theEvent { - bool mouseOK = qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseButtonRelease, Qt::RightButton); + qt_button_down = 0; - if (!mouseOK) - [super rightMouseUp:theEvent]; + qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseButtonRelease, Qt::RightButton); } - (void)otherMouseDown:(NSEvent *)theEvent { - Qt::MouseButton mouseButton = cocoaButton2QtButton([theEvent buttonNumber]); - bool mouseOK = qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseButtonPress, mouseButton); + if (!qt_button_down) + qt_button_down = qwidget; - if (!mouseOK) - [super otherMouseDown:theEvent]; + Qt::MouseButton mouseButton = cocoaButton2QtButton([theEvent buttonNumber]); + qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseButtonPress, mouseButton); } - (void)otherMouseUp:(NSEvent *)theEvent { - Qt::MouseButton mouseButton = cocoaButton2QtButton([theEvent buttonNumber]); - bool mouseOK = qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseButtonRelease, mouseButton); - - if (!mouseOK) - [super otherMouseUp:theEvent]; + qt_button_down = 0; + Qt::MouseButton mouseButton = cocoaButton2QtButton([theEvent buttonNumber]); + qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseButtonRelease, mouseButton); } - (void)mouseDragged:(NSEvent *)theEvent { qMacDnDParams()->view = self; qMacDnDParams()->theEvent = theEvent; - bool mouseOK = qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseMove, Qt::NoButton); - - if (!mouseOK) - [super mouseDragged:theEvent]; + qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseMove, Qt::NoButton); } - (void)rightMouseDragged:(NSEvent *)theEvent { qMacDnDParams()->view = self; qMacDnDParams()->theEvent = theEvent; - bool mouseOK = qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseMove, Qt::NoButton); - - if (!mouseOK) - [super rightMouseDragged:theEvent]; + qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseMove, Qt::NoButton); } - (void)otherMouseDragged:(NSEvent *)theEvent { qMacDnDParams()->view = self; qMacDnDParams()->theEvent = theEvent; - bool mouseOK = qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseMove, Qt::NoButton); - - if (!mouseOK) - [super otherMouseDragged:theEvent]; + qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseMove, Qt::NoButton); } - (void)scrollWheel:(NSEvent *)theEvent diff --git a/src/gui/kernel/qt_cocoa_helpers_mac.mm b/src/gui/kernel/qt_cocoa_helpers_mac.mm index d17225c8d5..563f0b81cd 100644 --- a/src/gui/kernel/qt_cocoa_helpers_mac.mm +++ b/src/gui/kernel/qt_cocoa_helpers_mac.mm @@ -899,6 +899,14 @@ bool qt_mac_handleMouseEvent(void * /* NSView * */view, void * /* NSEvent * */ev widgetToGetMouse = [static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(tmpView) qt_qwidget]; } + } else { + extern QPointer<QWidget> qt_button_down; //qapplication_mac.cpp + if (!mac_mouse_grabber && qt_button_down) { + // if there is no explicit grabber, and the mouse was grabbed + // implicitely (i.e. a mousebutton was pressed) + widgetToGetMouse = qt_button_down; + tmpView = qt_mac_nativeview_for(widgetToGetMouse); + } } NSPoint localPoint = [tmpView convertPoint:windowPoint fromView:nil]; |