diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2017-01-30 14:57:29 +0100 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2017-02-22 07:58:07 +0000 |
commit | c585802e946d97e7d177ea334a162dc7bc286b84 (patch) | |
tree | 27fd7832b2c5956845b4593686be3d616aa20b2e /src/widgets/widgets | |
parent | 5426e689f9d7d5e5e6e1a877578f17c96d248fdd (diff) |
QWindow: Remove "_q_foreignWinId" dynamic property
The platform plugins reading this out of the QWindow was a layering
violation, and propagates the notion that a window can shape shift
into representing a new native handle, while none of the platform
plugins support this.
A foreign QWindow is created via the factory function fromWinId(),
at which point we can pass the WId all the way to the platform
plugin as function arguments, where the platform will create a
corresponding platform-window.
The platform window can then answer the question of whether or
not it's representing a foreign window, which determines a few
behavioral changes here and there, as well as supplying the
native window handle back for QWindow::winId();
[ChangeLog][QtGui][QWindow] The "_q_foreignWinId" dynamic property
is no longer set nor read.
[ChangeLog][QtGui][QPA] The function createForeignWindow() has been
added to QPlatormIntegration and is now responsible for creating
foreign windows. The function isForeignWindow() in QPlatformWindow
has been added, and platforms should implement this to return true
for windows created by createForeignWindow().
Task-number: QTBUG-58383
Change-Id: If84142f95172f62b9377eb5d2a4d792cad36010b
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@qt.io>
Diffstat (limited to 'src/widgets/widgets')
-rw-r--r-- | src/widgets/widgets/qmaccocoaviewcontainer_mac.mm | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/src/widgets/widgets/qmaccocoaviewcontainer_mac.mm b/src/widgets/widgets/qmaccocoaviewcontainer_mac.mm index 8e565ecfe0..610df2125b 100644 --- a/src/widgets/widgets/qmaccocoaviewcontainer_mac.mm +++ b/src/widgets/widgets/qmaccocoaviewcontainer_mac.mm @@ -44,6 +44,7 @@ #include <QtGui/QWindow> #include <qpa/qplatformnativeinterface.h> #include <private/qwidget_p.h> +#include <private/qwindow_p.h> /*! \class QMacCocoaViewContainer @@ -117,7 +118,9 @@ QMacCocoaViewContainerPrivate::~QMacCocoaViewContainerPrivate() QMacCocoaViewContainer::QMacCocoaViewContainer(NSView *view, QWidget *parent) : QWidget(*new QMacCocoaViewContainerPrivate, parent, 0) { + // Ensures that we have a QWindow, even if we're not a top level widget setAttribute(Qt::WA_NativeWindow); + setCocoaView(view); } @@ -149,23 +152,19 @@ void QMacCocoaViewContainer::setCocoaView(NSView *view) [view retain]; d->nsview = view; - QWindow *window = windowHandle(); + // Get rid of QWindow completely, and re-create a new vanilla one, which + // we will then re-configure to be a foreign window. + destroy(); + create(); - // 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. + // Can't use QWindow::fromWinId() here due to QWidget controlling its + // QWindow, and can't use QWidget::createWindowContainer() due to the + // QMacCocoaViewContainer class being public API instead of a factory + // function. + QWindow *window = windowHandle(); window->destroy(); - window->setVisible(isVisible()); - window->setGeometry(geometry()); - window->create(); + qt_window_private(window)->create(false, WId(view)); + Q_ASSERT(window->handle()); [oldView release]; } |