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>
This commit is contained in:
parent
d7dfab8cac
commit
d9b04f8575
@ -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 &)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user