diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.h b/src/plugins/platforms/cocoa/qcocoanativeinterface.h index c344ebc42c..2e5e65f577 100644 --- a/src/plugins/platforms/cocoa/qcocoanativeinterface.h +++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.h @@ -115,6 +115,9 @@ private: // Embedding NSViews as child QWindows static void setWindowContentView(QPlatformWindow *window, void *nsViewContentView); + // Set a QWindow as a "guest" (subwindow) of a non-QWindow + static void setEmbeddedInForeignView(QPlatformWindow *window, bool embedded); + // Register if a window should deliver touch events. Enabling // touch events has implications for delivery of other events, // for example by causing scrolling event lag. diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm index 64e2b619c1..873fa3eed9 100644 --- a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm +++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm @@ -120,6 +120,8 @@ QPlatformNativeInterface::NativeResourceForIntegrationFunction QCocoaNativeInter return NativeResourceForIntegrationFunction(QCocoaNativeInterface::setWindowContentView); if (resource.toLower() == "registertouchwindow") return NativeResourceForIntegrationFunction(QCocoaNativeInterface::registerTouchWindow); + if (resource.toLower() == "setembeddedinforeignview") + return NativeResourceForIntegrationFunction(QCocoaNativeInterface::setEmbeddedInForeignView); return 0; } @@ -229,6 +231,12 @@ void QCocoaNativeInterface::setWindowContentView(QPlatformWindow *window, void * cocoaPlatformWindow->setContentView(reinterpret_cast(contentView)); } +void QCocoaNativeInterface::setEmbeddedInForeignView(QPlatformWindow *window, bool embedded) +{ + QCocoaWindow *cocoaPlatformWindow = static_cast(window); + cocoaPlatformWindow->setEmbeddedInForeignView(embedded); +} + void QCocoaNativeInterface::registerTouchWindow(QWindow *window, bool enable) { if (!window) diff --git a/src/plugins/platforms/cocoa/qcocoawindow.h b/src/plugins/platforms/cocoa/qcocoawindow.h index ff7f99f96a..b2657b7725 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.h +++ b/src/plugins/platforms/cocoa/qcocoawindow.h @@ -127,6 +127,8 @@ public: NSView *contentView() const; void setContentView(NSView *contentView); + void setEmbeddedInForeignView(bool subwindow); + void windowWillMove(); void windowDidMove(); void windowDidResize(); @@ -175,7 +177,10 @@ public: // for QNSView NSView *m_contentView; QNSView *m_qtView; NSWindow *m_nsWindow; - bool m_contentViewIsEmbedded; // true if the m_contentView is embedded in a "foregin" NSView hiearchy + + // TODO merge to one variable if possible + bool m_contentViewIsEmbedded; // true if the m_contentView is actually embedded in a "foreign" NSView hiearchy + bool m_contentViewIsToBeEmbedded; // true if the m_contentView is intended to be embedded in a "foreign" NSView hiearchy QNSWindowDelegate *m_nsWindowDelegate; Qt::WindowFlags m_windowFlags; diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 5cfcec8e54..14b9b66c92 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -194,6 +194,7 @@ QCocoaWindow::QCocoaWindow(QWindow *tlw) : QPlatformWindow(tlw) , m_nsWindow(0) , m_contentViewIsEmbedded(false) + , m_contentViewIsToBeEmbedded(false) , m_nsWindowDelegate(0) , m_synchedWindowState(Qt::WindowActive) , m_windowModality(Qt::NonModal) @@ -654,6 +655,12 @@ void QCocoaWindow::setContentView(NSView *contentView) recreateWindow(parent()); // Adds the content view to parent NSView } +void QCocoaWindow::setEmbeddedInForeignView(bool embedded) +{ + m_contentViewIsToBeEmbedded = embedded; + recreateWindow(0); // destroy what was already created +} + void QCocoaWindow::windowWillMove() { // Close any open popups on window move @@ -715,8 +722,8 @@ void QCocoaWindow::recreateWindow(const QPlatformWindow *parentWindow) m_nsWindowDelegate = 0; } - if (window()->type() == Qt::SubWindow) { - // Subwindows don't have a NSWindow. + if (m_contentViewIsToBeEmbedded) { + // An embedded window doesn't have its own NSWindow. } else if (!parentWindow) { // Create a new NSWindow if this is a top-level window. m_nsWindow = createNSWindow(); diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index d1dd939600..a53d6c4e44 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -172,7 +172,7 @@ static QTouchDevice *touchDevice = 0; - (void)viewDidMoveToSuperview { - if (!(m_window->type() & Qt::SubWindow)) + if (!(m_platformWindow->m_contentViewIsToBeEmbedded)) return; if ([self superview]) { @@ -208,7 +208,7 @@ static QTouchDevice *touchDevice = 0; NSRect rect = [self frame]; NSRect windowRect = [[self window] frame]; geometry = QRect(windowRect.origin.x, qt_mac_flipYCoordinate(windowRect.origin.y + rect.size.height), rect.size.width, rect.size.height); - } else if (m_window->type() & Qt::SubWindow) { + } else if (m_platformWindow->m_contentViewIsToBeEmbedded) { // embedded child window, use the frame rect ### merge with case below geometry = qt_mac_toQRect([self bounds]); } else { @@ -229,9 +229,9 @@ static QTouchDevice *touchDevice = 0; m_platformWindow->QPlatformWindow::setGeometry(geometry); // Don't send the geometry change if the QWindow is designated to be - // embedded in a foregin view hiearchy but has not actually been + // embedded in a foreign view hiearchy but has not actually been // embedded yet - it's too early. - if ((m_window->type() & Qt::SubWindow) && !m_platformWindow->m_contentViewIsEmbedded) + if (m_platformWindow->m_contentViewIsToBeEmbedded && !m_platformWindow->m_contentViewIsEmbedded) return; // Send a geometry change event to Qt, if it's ready to handle events