summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2016-10-05 20:56:38 +0200
committerTor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>2016-10-05 19:37:17 +0000
commit89842b97d74d1824240d3cc35950c92aa011a8ac (patch)
tree2abff407aa26e6cbc07c0ec75b0eed0ebe8cf479 /src/widgets
parent087b11e881032bbd7bc1cbc06c45480c22ecb714 (diff)
Implement QMacCocoaViewContainer in terms of foreign window
This leaves a clearer separation between the foreign-window and non-foreign window use-cases, where a single QCococaWindow can only be in one mode, which is determined in the constructor and doesn't change after that. There are no source or binary compatibility guarantees for the QPA classes, meaning the helper function in QPlatformNativeInterface can be removed. Change-Id: I3232aedca1d98c49a8f54e16750832187f9dc69a Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/widgets/qmaccocoaviewcontainer_mac.mm45
1 files changed, 18 insertions, 27 deletions
diff --git a/src/widgets/widgets/qmaccocoaviewcontainer_mac.mm b/src/widgets/widgets/qmaccocoaviewcontainer_mac.mm
index 725cc637d6..b4f2b8959e 100644
--- a/src/widgets/widgets/qmaccocoaviewcontainer_mac.mm
+++ b/src/widgets/widgets/qmaccocoaviewcontainer_mac.mm
@@ -92,21 +92,6 @@
QT_BEGIN_NAMESPACE
-namespace {
-// TODO use QtMacExtras copy of this function when available.
-inline QPlatformNativeInterface::NativeResourceForIntegrationFunction resolvePlatformFunction(const QByteArray &functionName)
-{
- QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface();
- QPlatformNativeInterface::NativeResourceForIntegrationFunction function =
- nativeInterface->nativeResourceFunctionForIntegration(functionName);
- if (Q_UNLIKELY(!function))
- qWarning("Qt could not resolve function %s from "
- "QGuiApplication::platformNativeInterface()->nativeResourceFunctionForIntegration()",
- functionName.constData());
- return function;
-}
-} //namespsace
-
class QMacCocoaViewContainerPrivate : public QWidgetPrivate
{
Q_DECLARE_PUBLIC(QMacCocoaViewContainer)
@@ -137,12 +122,8 @@ QMacCocoaViewContainerPrivate::~QMacCocoaViewContainerPrivate()
QMacCocoaViewContainer::QMacCocoaViewContainer(NSView *view, QWidget *parent)
: QWidget(*new QMacCocoaViewContainerPrivate, parent, 0)
{
-
- if (view)
- setCocoaView(view);
-
- // QMacCocoaViewContainer requires a native window handle.
setAttribute(Qt::WA_NativeWindow);
+ setCocoaView(view);
}
/*!
@@ -173,13 +154,23 @@ void QMacCocoaViewContainer::setCocoaView(NSView *view)
[view retain];
d->nsview = view;
- // Create window and platformwindow
- winId();
- QPlatformWindow *platformWindow = this->windowHandle()->handle();
-
- // Set the new view as the content view for the window.
- typedef void (*SetWindowContentViewFunction)(QPlatformWindow *window, NSView *nsview);
- reinterpret_cast<SetWindowContentViewFunction>(resolvePlatformFunction("setwindowcontentview"))(platformWindow, view);
+ QWindow *window = windowHandle();
+
+ // Note that we only set the flag on the QWindow, and not the QWidget.
+ // These two are not in sync, so from a QWidget standpoint the widget
+ // is not a Window, and hence will be shown when the parent widget is
+ // shown, like all QWidget children.
+ window->setFlags(Qt::ForeignWindow);
+ window->setProperty("_q_foreignWinId", view ? WId(view) : QVariant());
+
+ // Destroying the platform window implies hiding the window, and we
+ // also lose the geometry information that the platform window kept,
+ // and fall back to the stale QWindow geometry, so we update the two
+ // based on the widget visibility and geometry, which is up to date.
+ window->destroy();
+ window->setVisible(isVisible());
+ window->setGeometry(geometry());
+ window->create();
[oldView release];
}