summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qcocoawindow.mm
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dedietrich@theqtcompany.com>2016-04-19 13:45:12 -0700
committerGabriel de Dietrich <gabriel.dedietrich@qt.io>2016-05-06 21:25:28 +0000
commit6eb27afcdfb6df2e620f1ec66196600f0f9ed022 (patch)
treeecdc57075a112277cb5a677ef90979c3e27427f3 /src/plugins/platforms/cocoa/qcocoawindow.mm
parente6c0373421a3239a828969d5c49e5418b1122dd0 (diff)
Cocoa: Add QCocoaWindowPointer
This patch extends 5b54c352edbc597ec5283bc9cfdd77906350161f by abstracting the watcher pattern. The class is specialized for QCocoaWindow since it's aware of the QObject sentinel there. We update the usage in QNSWindowHelper and extend it to the forward window (this one is used for mouse coordinate conversion when docking windows). Change-Id: I628415527593daec835bbad1b6e83d13fe7b6703 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@theqtcompany.com>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoawindow.mm')
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.mm31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
index 12e85c5205..dd67946a27 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.mm
+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
@@ -85,7 +85,7 @@ static bool isMouseEvent(NSEvent *ev)
self = [super init];
if (self) {
_window = window;
- _platformWindow = platformWindow;
+ _platformWindow.assign(platformWindow);
_window.delegate = [[QNSWindowDelegate alloc] initWithQCocoaWindow:_platformWindow];
@@ -94,7 +94,6 @@ static bool isMouseEvent(NSEvent *ev)
// make sure that m_nsWindow stays valid until the
// QCocoaWindow is deleted by Qt.
[_window setReleasedWhenClosed:NO];
- _watcher = &_platformWindow->sentinel;
}
return self;
@@ -103,19 +102,19 @@ static bool isMouseEvent(NSEvent *ev)
- (void)handleWindowEvent:(NSEvent *)theEvent
{
QCocoaWindow *pw = self.platformWindow;
- if (_watcher && pw && pw->m_forwardWindow) {
+ if (pw && pw->m_forwardWindow) {
if (theEvent.type == NSLeftMouseUp || theEvent.type == NSLeftMouseDragged) {
QNSView *forwardView = pw->m_qtView;
if (theEvent.type == NSLeftMouseUp) {
[forwardView mouseUp:theEvent];
- pw->m_forwardWindow = 0;
+ pw->m_forwardWindow.clear();
} else {
[forwardView mouseDragged:theEvent];
}
}
if (!pw->m_isNSWindowChild && theEvent.type == NSLeftMouseDown) {
- pw->m_forwardWindow = 0;
+ pw->m_forwardWindow.clear();
}
}
@@ -142,7 +141,7 @@ static bool isMouseEvent(NSEvent *ev)
if (!self.window.delegate)
return; // Already detached, pending NSAppKitDefined event
- if (_watcher && pw && pw->frameStrutEventsEnabled() && isMouseEvent(theEvent)) {
+ if (pw && pw->frameStrutEventsEnabled() && isMouseEvent(theEvent)) {
NSPoint loc = [theEvent locationInWindow];
NSRect windowFrame = [self.window convertRectFromScreen:[self.window frame]];
NSRect contentFrame = [[self.window contentView] frame];
@@ -157,8 +156,7 @@ static bool isMouseEvent(NSEvent *ev)
- (void)detachFromPlatformWindow
{
- _platformWindow = 0;
- _watcher.clear();
+ self.platformWindow.clear();
[self.window.delegate release];
self.window.delegate = nil;
}
@@ -179,7 +177,7 @@ static bool isMouseEvent(NSEvent *ev)
- (void)dealloc
{
_window = nil;
- _platformWindow = 0;
+ self.platformWindow.clear();
[super dealloc];
}
@@ -331,6 +329,18 @@ static bool isMouseEvent(NSEvent *ev)
@end
+void QCocoaWindowPointer::assign(QCocoaWindow *w)
+{
+ window = w;
+ watcher = &w->sentinel;
+}
+
+void QCocoaWindowPointer::clear()
+{
+ window = Q_NULLPTR;
+ watcher.clear();
+}
+
const int QCocoaWindow::NoAlertRequest = -1;
QCocoaWindow::QCocoaWindow(QWindow *tlw)
@@ -338,7 +348,6 @@ QCocoaWindow::QCocoaWindow(QWindow *tlw)
, m_contentView(nil)
, m_qtView(nil)
, m_nsWindow(0)
- , m_forwardWindow(0)
, m_contentViewIsEmbedded(false)
, m_contentViewIsToBeEmbedded(false)
, m_parentCocoaWindow(0)
@@ -1320,7 +1329,7 @@ void QCocoaWindow::recreateWindow(const QPlatformWindow *parentWindow)
if (oldParentCocoaWindow) {
if (!m_isNSWindowChild || oldParentCocoaWindow != m_parentCocoaWindow)
oldParentCocoaWindow->removeChildWindow(this);
- m_forwardWindow = oldParentCocoaWindow;
+ m_forwardWindow.assign(oldParentCocoaWindow);
}
setNSWindow(m_nsWindow);