diff options
author | Morten Johan Sørvig <morten.sorvig@digia.com> | 2013-01-08 13:45:37 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-02-23 08:03:03 +0100 |
commit | d9b04f8575745f699e39256c3c428e5c08d3bb70 (patch) | |
tree | 492b970e2714283691e092160d73be617e75b982 /src | |
parent | d7dfab8cacff688b2f048097dc1a50eee81885f1 (diff) | |
download | qtbase-d9b04f8575745f699e39256c3c428e5c08d3bb70.tar.gz qtbase-d9b04f8575745f699e39256c3c428e5c08d3bb70.tar.bz2 qtbase-d9b04f8575745f699e39256c3c428e5c08d3bb70.zip |
QCococaWindow: Add NSView hosting support.
Add and export QCCoocaView::setContentView(NSView *),
making it possible to host a foreign NSView in a QWindow.
Change QCoocaWindow::m_contentView to be a generic
NSView, instead of a QNSView. Add a separate m_qtView
for code paths that expect a QNSView.
Change-Id: I47935b69705c70ea7efbb03d6d4bf489947c3487
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoabackingstore.mm | 2 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoanativeinterface.h | 3 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoanativeinterface.mm | 7 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoawindow.h | 4 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoawindow.mm | 22 |
5 files changed, 32 insertions, 6 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoabackingstore.mm b/src/plugins/platforms/cocoa/qcocoabackingstore.mm index 7f022da4c3..d3d8369c9b 100644 --- a/src/plugins/platforms/cocoa/qcocoabackingstore.mm +++ b/src/plugins/platforms/cocoa/qcocoabackingstore.mm @@ -91,7 +91,7 @@ void QCocoaBackingStore::flush(QWindow *win, const QRegion ®ion, const QPoint CGImageRelease(m_cgImage); m_cgImage = 0; if (QCocoaWindow *cocoaWindow = static_cast<QCocoaWindow *>(win->handle())) - [cocoaWindow->m_contentView flushBackingStore:this region:region offset:offset]; + [cocoaWindow->m_qtView flushBackingStore:this region:region offset:offset]; } void QCocoaBackingStore::resize(const QSize &size, const QRegion &) diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.h b/src/plugins/platforms/cocoa/qcocoanativeinterface.h index 9506f86238..2f79b49534 100644 --- a/src/plugins/platforms/cocoa/qcocoanativeinterface.h +++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.h @@ -102,6 +102,9 @@ private: // QImage <-> CGImage conversion functions static CGImageRef qImageToCGImage(const QImage &image); static QImage cgImageToQImage(CGImageRef image); + + // Embedding NSViews as child QWindows + static void setWindowContentView(QPlatformWindow *window, void *nsViewContentView); }; #endif // QCOCOANATIVEINTERFACE_H diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm index bd3a909137..9990537c1f 100644 --- a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm +++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm @@ -113,6 +113,8 @@ QPlatformNativeInterface::NativeResourceForIntegrationFunction QCocoaNativeInter return NativeResourceForIntegrationFunction(QCocoaNativeInterface::qImageToCGImage); if (resource.toLower() == "cgimagetoqimage") return NativeResourceForIntegrationFunction(QCocoaNativeInterface::cgImageToQImage); + if (resource.toLower() == "setwindowcontentview") + return NativeResourceForIntegrationFunction(QCocoaNativeInterface::setWindowContentView); return 0; } @@ -198,5 +200,10 @@ QImage QCocoaNativeInterface::cgImageToQImage(CGImageRef image) return qt_mac_toQImage(image); } +void QCocoaNativeInterface::setWindowContentView(QPlatformWindow *window, void *contentView) +{ + QCocoaWindow *cocoaPlatformWindow = static_cast<QCocoaWindow *>(window); + cocoaPlatformWindow->setContentView(reinterpret_cast<NSView *>(contentView)); +} QT_END_NAMESPACE diff --git a/src/plugins/platforms/cocoa/qcocoawindow.h b/src/plugins/platforms/cocoa/qcocoawindow.h index 931319190c..2422788f7a 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.h +++ b/src/plugins/platforms/cocoa/qcocoawindow.h @@ -119,6 +119,7 @@ public: void setParent(const QPlatformWindow *window); NSView *contentView() const; + void setContentView(NSView *contentView); void windowWillMove(); void windowDidMove(); @@ -160,7 +161,8 @@ public: // for QNSView friend class QCocoaBackingStore; friend class QCocoaNativeInterface; - QNSView *m_contentView; + NSView *m_contentView; + QNSView *m_qtView; NSWindow *m_nsWindow; bool m_contentViewIsEmbedded; // true if the m_contentView is embedded in a "foregin" NSView hiearchy diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index f7348e7dda..489c229187 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -201,7 +201,8 @@ QCocoaWindow::QCocoaWindow(QWindow *tlw) #endif QCocoaAutoReleasePool pool; - m_contentView = [[QNSView alloc] initWithQWindow:tlw platformWindow:this]; + m_qtView = [[QNSView alloc] initWithQWindow:tlw platformWindow:this]; + m_contentView = m_qtView; setGeometry(tlw->geometry()); recreateWindow(parent()); @@ -534,7 +535,7 @@ void QCocoaWindow::setMask(const QRegion ®ion) [m_nsWindow setBackgroundColor:[NSColor clearColor]]; } - [m_contentView setMaskRegion:®ion]; + [m_qtView setMaskRegion:®ion]; } bool QCocoaWindow::setKeyboardGrabEnabled(bool grab) @@ -578,6 +579,19 @@ NSView *QCocoaWindow::contentView() const return m_contentView; } +void QCocoaWindow::setContentView(NSView *contentView) +{ + // Remove and release the previous content view + [m_contentView removeFromSuperview]; + [m_contentView release]; + + // Insert and retain the new content view + [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 +} + void QCocoaWindow::windowWillMove() { // Close any open popups on window move @@ -590,7 +604,7 @@ void QCocoaWindow::windowWillMove() void QCocoaWindow::windowDidMove() { - [m_contentView updateGeometry]; + [m_qtView updateGeometry]; } void QCocoaWindow::windowDidResize() @@ -598,7 +612,7 @@ void QCocoaWindow::windowDidResize() if (!m_nsWindow) return; - [m_contentView updateGeometry]; + [m_qtView updateGeometry]; } void QCocoaWindow::windowWillClose() |