summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dedietrich@digia.com>2014-02-26 20:05:00 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-04 11:29:30 +0100
commit28c9c2ea50e54236d5975f263ee1d28d831223aa (patch)
tree9858fc926b880486ed58c4e7d217bf682cb82bd1 /src/plugins
parent018d1ca5f3209949cb7e8e1306250ec030fee929 (diff)
Cocoa: Keep child NSWindow alive while it grabs the mouse
Otherwise, Cocoa loses sight on which window to send the dragging mouse event. If the window is kept alive (but hidden) Cocoa will send the events to it, and we can forward them to the actual QWindow. This is the expected use-case: 1. Start dragging a QWindow and change its flags. 2. This triggers a call to QCocoaWindow::recreateWindow(), which will get rid of the old NSWindow and create a new one (the QNSView is moved to the new NSWindow). 3. When we stop dragging, the NSWindow is finally destroyed. QNSView Pointer References Remarks: In QNSView, m_window points to the QWindow which remains unchanged until deleted. Similarly m_platformWindow remains valid until deleted, in which case we delete the QNSView, the NSWindow and its helper (see QCocoaWindow destructor). This fixes undocking QToolBars when they are a child NSWindow. Task-number: QTBUG-33082 Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com> Change-Id: I6fc53292cd96586cfdf401481c5442d759f1fae5 Reviewed-by: Liang Qi <liang.qi@digia.com>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.h4
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.mm22
2 files changed, 24 insertions, 2 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.h b/src/plugins/platforms/cocoa/qcocoawindow.h
index 0f08cd18fb..67cac41383 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.h
+++ b/src/plugins/platforms/cocoa/qcocoawindow.h
@@ -69,10 +69,14 @@ typedef NSWindow<QNSWindowProtocol> QCocoaNSWindow;
{
QCocoaNSWindow *_window;
QCocoaWindow *_platformWindow;
+ BOOL _grabbingMouse;
+ BOOL _releaseOnMouseUp;
}
@property (nonatomic, readonly) QCocoaNSWindow *window;
@property (nonatomic, readonly) QCocoaWindow *platformWindow;
+@property (nonatomic) BOOL grabbingMouse;
+@property (nonatomic) BOOL releaseOnMouseUp;
- (id)initWithNSWindow:(QCocoaNSWindow *)window platformWindow:(QCocoaWindow *)platformWindow;
- (void)handleWindowEvent:(NSEvent *)theEvent;
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
index 65e2a15cec..f1f88a13dd 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.mm
+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
@@ -103,6 +103,8 @@ static bool isMouseEvent(NSEvent *ev)
@synthesize window = _window;
@synthesize platformWindow = _platformWindow;
+@synthesize grabbingMouse = _grabbingMouse;
+@synthesize releaseOnMouseUp = _releaseOnMouseUp;
- (id)initWithNSWindow:(QCocoaNSWindow *)window platformWindow:(QCocoaWindow *)platformWindow
{
@@ -142,6 +144,17 @@ static bool isMouseEvent(NSEvent *ev)
}
}
+ if (theEvent.type == NSLeftMouseDown) {
+ self.grabbingMouse = YES;
+ } else if (theEvent.type == NSLeftMouseUp) {
+ self.grabbingMouse = NO;
+ if (self.releaseOnMouseUp) {
+ [self detachFromPlatformWindow];
+ [self.window release];
+ return;
+ }
+ }
+
[self.window superSendEvent:theEvent];
if (!self.window.delegate)
@@ -234,9 +247,14 @@ static bool isMouseEvent(NSEvent *ev)
- (void)closeAndRelease
{
- [self.helper detachFromPlatformWindow];
[self close];
- [self release];
+
+ if (self.helper.grabbingMouse) {
+ self.helper.releaseOnMouseUp = YES;
+ } else {
+ [self.helper detachFromPlatformWindow];
+ [self release];
+ }
}
- (void)dealloc