summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qcocoawindow.h
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dedietrich@digia.com>2014-02-25 20:33:39 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-04 11:29:30 +0100
commit018d1ca5f3209949cb7e8e1306250ec030fee929 (patch)
tree4bdd42f21ecc24cc4b27d4da53889e2ec44f4160 /src/plugins/platforms/cocoa/qcocoawindow.h
parentce909a138ab486c1ec5cf4b13232ef8d73ab5816 (diff)
Cocoa: Use helper class for event handling in native windows
QNSWindow and QNSPanel duplicate some code when it comes to event handling, which can be refactored. Also, it's currently not possible to keep an NSWindow derived instance temporarily alive as QCocoaWindow is not designed to keep track of more than one NSWindow. Finally, we can reduce the size of (and eventually remove) the QCocoaWindowCategory which polutes the NSWindow namespace. We move QNSWindow and QNSPanel specific API into QNSWindowProtocol, and define QCocoaNSWindow as NSWindow extended by that protocol. This gives us a type we can refer to any of the native windows QCocoaWindow instanciates. We introduce QNSWindowHelper which gathers the common code between QNSWindow and QNSPanel. This is a one-to-one mapping that keeps a weak (non-retaining) reference to the NSWindow and a weak reference to the QCocoaWindow. It has the same life span as its associated NSWindow. Task-number: QTBUG-33082 Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com> Change-Id: I38d001bf13f64a1ba4f1439291c5103c3f755183 Reviewed-by: Liang Qi <liang.qi@digia.com>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoawindow.h')
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.h50
1 files changed, 39 insertions, 11 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.h b/src/plugins/platforms/cocoa/qcocoawindow.h
index 748280af6a..0f08cd18fb 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.h
+++ b/src/plugins/platforms/cocoa/qcocoawindow.h
@@ -52,27 +52,57 @@
QT_FORWARD_DECLARE_CLASS(QCocoaWindow)
-@interface QNSWindow : NSWindow
+@class QNSWindowHelper;
+
+@protocol QNSWindowProtocol
+
+@property (nonatomic, readonly) QNSWindowHelper *helper;
+
+- (void)superSendEvent:(NSEvent *)theEvent;
+- (void)closeAndRelease;
+
+@end
+
+typedef NSWindow<QNSWindowProtocol> QCocoaNSWindow;
+
+@interface QNSWindowHelper : NSObject
{
- @public QCocoaWindow *m_cocoaPlatformWindow;
+ QCocoaNSWindow *_window;
+ QCocoaWindow *_platformWindow;
}
+
+@property (nonatomic, readonly) QCocoaNSWindow *window;
+@property (nonatomic, readonly) QCocoaWindow *platformWindow;
+
+- (id)initWithNSWindow:(QCocoaNSWindow *)window platformWindow:(QCocoaWindow *)platformWindow;
+- (void)handleWindowEvent:(NSEvent *)theEvent;
+
+@end
+
+@interface QNSWindow : NSWindow<QNSWindowProtocol>
+{
+ QNSWindowHelper *_helper;
+}
+
+@property (nonatomic, readonly) QNSWindowHelper *helper;
+
- (id)initWithContentRect:(NSRect)contentRect
styleMask:(NSUInteger)windowStyle
qPlatformWindow:(QCocoaWindow *)qpw;
-- (void)clearPlatformWindow;
@end
-@interface QNSPanel : NSPanel
+@interface QNSPanel : NSPanel<QNSWindowProtocol>
{
- @public QCocoaWindow *m_cocoaPlatformWindow;
+ QNSWindowHelper *_helper;
}
+@property (nonatomic, readonly) QNSWindowHelper *helper;
+
- (id)initWithContentRect:(NSRect)contentRect
styleMask:(NSUInteger)windowStyle
qPlatformWindow:(QCocoaWindow *)qpw;
-- (void)clearPlatformWindow;
@end
@class QNSWindowDelegate;
@@ -183,9 +213,8 @@ public:
QWindow *childWindowAt(QPoint windowPoint);
protected:
void recreateWindow(const QPlatformWindow *parentWindow);
- NSWindow *createNSWindow();
- void setNSWindow(NSWindow *window);
- void clearNSWindow(NSWindow *window);
+ QCocoaNSWindow *createNSWindow();
+ void setNSWindow(QCocoaNSWindow *window);
bool shouldUseNSPanel();
@@ -202,7 +231,7 @@ public: // for QNSView
NSView *m_contentView;
QNSView *m_qtView;
- NSWindow *m_nsWindow;
+ QCocoaNSWindow *m_nsWindow;
QCocoaWindow *m_forwardWindow;
// TODO merge to one variable if possible
@@ -213,7 +242,6 @@ public: // for QNSView
bool m_isNSWindowChild; // this window is a non-top level QWindow with a NSWindow.
QList<QCocoaWindow *> m_childWindows;
- QNSWindowDelegate *m_nsWindowDelegate;
Qt::WindowFlags m_windowFlags;
Qt::WindowState m_synchedWindowState;
Qt::WindowModality m_windowModality;