From c6fa0222e2c140eebd0322e550780afef1bc26f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Sat, 24 Sep 2016 18:58:34 +0200 Subject: Remove QCocoaWindowPointer in favor of QCocoaWindow inheriting QObject As already done by the iOS, Mir, and Haiku platform plugins. Change-Id: I449f396dbf234e27206625b178c7d20e3f5b956f Reviewed-by: Gabriel de Dietrich Reviewed-by: Timur Pocheptsov --- src/plugins/platforms/cocoa/qcocoawindow.h | 39 ++++------------------------- src/plugins/platforms/cocoa/qcocoawindow.mm | 34 +++++++++++-------------- 2 files changed, 19 insertions(+), 54 deletions(-) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qcocoawindow.h b/src/plugins/platforms/cocoa/qcocoawindow.h index b016004b23..7b3fec9534 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.h +++ b/src/plugins/platforms/cocoa/qcocoawindow.h @@ -54,32 +54,6 @@ QT_FORWARD_DECLARE_CLASS(QCocoaWindow) -QT_BEGIN_NAMESPACE - -class QCocoaWindowPointer -{ -public: - void assign(QCocoaWindow *w); - void clear(); - - QCocoaWindow *data() const - { return watcher.isNull() ? Q_NULLPTR : window; } - bool isNull() const - { return watcher.isNull(); } - operator QCocoaWindow*() const - { return data(); } - QCocoaWindow *operator->() const - { return data(); } - QCocoaWindow &operator*() const - { return *data(); } - -private: - QPointer watcher; - QCocoaWindow *window; -}; - -QT_END_NAMESPACE - @class QT_MANGLE_NAMESPACE(QNSWindowHelper); @protocol QNSWindowProtocol @@ -96,13 +70,13 @@ typedef NSWindow QCocoaNSWindow; @interface QT_MANGLE_NAMESPACE(QNSWindowHelper) : NSObject { QCocoaNSWindow *_window; - QCocoaWindowPointer _platformWindow; + QPointer _platformWindow; BOOL _grabbingMouse; BOOL _releaseOnMouseUp; } @property (nonatomic, readonly) QCocoaNSWindow *window; -@property (nonatomic, readonly) QCocoaWindowPointer platformWindow; +@property (nonatomic, readonly) QCocoaWindow *platformWindow; @property (nonatomic) BOOL grabbingMouse; @property (nonatomic) BOOL releaseOnMouseUp; @@ -169,8 +143,9 @@ QT_BEGIN_NAMESPACE class QCocoaMenuBar; -class QCocoaWindow : public QPlatformWindow +class QCocoaWindow : public QObject, public QPlatformWindow { + Q_OBJECT public: QCocoaWindow(QWindow *tlw); ~QCocoaWindow(); @@ -288,7 +263,7 @@ public: // for QNSView NSView *m_contentView; QNSView *m_qtView; QCocoaNSWindow *m_nsWindow; - QCocoaWindowPointer m_forwardWindow; + QPointer m_forwardWindow; // TODO merge to one variable if possible bool m_contentViewIsEmbedded; // true if the m_contentView is actually embedded in a "foreign" NSView hiearchy @@ -350,10 +325,6 @@ public: // for QNSView }; QHash m_contentBorderAreas; // identifer -> uppper/lower QHash m_enabledContentBorderAreas; // identifer -> enabled state (true/false) - - // This object is tracked by QCocoaWindowPointer, - // preventing the use of dangling pointers. - QObject sentinel; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index b2fd0580bc..5cbaf74924 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -90,16 +90,20 @@ static void qt_closePopups() @implementation QNSWindowHelper @synthesize window = _window; -@synthesize platformWindow = _platformWindow; @synthesize grabbingMouse = _grabbingMouse; @synthesize releaseOnMouseUp = _releaseOnMouseUp; +- (QCocoaWindow *)platformWindow +{ + return _platformWindow.data(); +} + - (id)initWithNSWindow:(QCocoaNSWindow *)window platformWindow:(QCocoaWindow *)platformWindow { self = [super init]; if (self) { _window = window; - _platformWindow.assign(platformWindow); + _platformWindow = platformWindow; _window.delegate = [[QNSWindowDelegate alloc] initWithQCocoaWindow:_platformWindow]; @@ -170,7 +174,7 @@ static void qt_closePopups() - (void)detachFromPlatformWindow { - self.platformWindow.clear(); + _platformWindow.clear(); [self.window.delegate release]; self.window.delegate = nil; } @@ -191,7 +195,7 @@ static void qt_closePopups() - (void)dealloc { _window = nil; - self.platformWindow.clear(); + _platformWindow.clear(); [super dealloc]; } @@ -343,18 +347,6 @@ static void qt_closePopups() @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) @@ -419,7 +411,7 @@ QCocoaWindow::QCocoaWindow(QWindow *tlw) [m_contentView setWantsLayer:enable]; } setGeometry(tlw->geometry()); - recreateWindow(parent()); + recreateWindow(QPlatformWindow::parent()); tlw->setGeometry(geometry()); if (tlw->isTopLevel()) setWindowIcon(tlw->icon()); @@ -662,7 +654,7 @@ void QCocoaWindow::setVisible(bool visible) if (visible) { // We need to recreate if the modality has changed as the style mask will need updating if (m_windowModality != window()->modality() || isNativeWindowTypeInconsistent()) - recreateWindow(parent()); + recreateWindow(QPlatformWindow::parent()); // Register popup windows. The Cocoa platform plugin will forward mouse events // to them and close them when needed. @@ -1205,7 +1197,7 @@ void QCocoaWindow::setContentView(NSView *contentView) [contentView retain]; m_contentView = contentView; m_qtView = 0; // The new content view is not a QNSView. - recreateWindow(parent()); // Adds the content view to parent NSView + recreateWindow(QPlatformWindow::parent()); // Adds the content view to parent NSView } QNSView *QCocoaWindow::qtView() const @@ -1360,7 +1352,7 @@ void QCocoaWindow::recreateWindow(const QPlatformWindow *parentWindow) if (oldParentCocoaWindow) { if (!m_isNSWindowChild || oldParentCocoaWindow != m_parentCocoaWindow) oldParentCocoaWindow->removeChildWindow(this); - m_forwardWindow.assign(oldParentCocoaWindow); + m_forwardWindow = oldParentCocoaWindow; } setNSWindow(m_nsWindow); @@ -1960,3 +1952,5 @@ void QCocoaWindow::setFrameStrutEventsEnabled(bool enabled) { m_frameStrutEventsEnabled = enabled; } + +#include "moc_qcocoawindow.cpp" -- cgit v1.2.3