diff options
author | Morten Sorvig <morten.sorvig@nokia.com> | 2011-12-06 12:59:21 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-12-14 23:26:15 +0100 |
commit | f950a0f0c0b9259bb424f0c81fd6516fe8e4e103 (patch) | |
tree | e7e1006cbf66bd29192cd6f94656e54fe6405678 /src/plugins/platforms/cocoa/qnsview.mm | |
parent | f295ef1a4b76eb6421fc3dcd7ab307d471c3e895 (diff) |
Make QCocoaWindow independent of NSWindow.
QCocoaWindow now gets resize events from QNSViev
and does not require a NSWindow. QWindow instances
can now be inserted in NSView hierarchies. This is
useful for Qt-as-a-plugin use cases and is needed to
implement QMacNativeWidget for Qt 5.
Change-Id: Ia95ea9c22a15a3e62d1e6543466cff07390c70a2
Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
Diffstat (limited to 'src/plugins/platforms/cocoa/qnsview.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qnsview.mm | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index 82b4e54deb..1a1e02d2fd 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -44,6 +44,7 @@ #include <Carbon/Carbon.h> #include "qnsview.h" +#include "qcocoawindow.h" #include "qcocoahelpers.h" #include "qmultitouch_mac_p.h" @@ -81,12 +82,14 @@ static QTouchDevice *touchDevice = 0; return self; } -- (id)initWithQWindow:(QWindow *)window { +- (id)initWithQWindow:(QWindow *)window platformWindow:(QCocoaWindow *) platformWindow +{ self = [self init]; if (!self) return 0; m_window = window; + m_platformWindow = platformWindow; m_accessibleRoot = 0; #ifdef QT_COCOA_ENABLE_ACCESSIBILITY_INSPECTOR @@ -106,9 +109,31 @@ static QTouchDevice *touchDevice = 0; m_accessibleRoot = window->accessibleRoot(); #endif + [self setPostsFrameChangedNotifications : YES]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(frameDidChangeNotification:) + name:NSViewFrameDidChangeNotification + object:self]; + return self; } +- (void) frameDidChangeNotification: (NSNotification *) notification +{ + NSRect rect = [self frame]; + NSRect windowRect = [[self window] frame]; + QRect geo(windowRect.origin.x, qt_mac_flipYCoordinate(windowRect.origin.y + rect.size.height), rect.size.width, rect.size.height); + + // Call setGeometry on QPlatformWindow. (not on QCocoaWindow, + // doing that will initiate a geometry change it and possibly create + // an infinite loop when this notification is triggered again.) + m_platformWindow->QPlatformWindow::setGeometry(geo); + + // Send a geometry change event to Qt, if it's ready to handle events + if (!m_platformWindow->m_inConstructor) + QWindowSystemInterface::handleSynchronousGeometryChange(m_window, geo); +} + - (void) setImage:(QImage *)image { CGImageRelease(m_cgImage); |