From e0c43ff624e05083fa0983391edec3af1ebe111c Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 15 Mar 2016 10:46:01 +0100 Subject: [PATCH] WIP: Purely experimental: Implement QWidget::create(winId) by QWindow::fromWinId(). Pass the win id to QWidgetPrivate::create_sys() and use QWindow::fromWinId() there. Change QTLWExtra::window to be a QWindow. TODO: Is that worth following up or should QWidget::createWindowContainer() be used always? Task-number: QTBUG-33079 Task-number: QTBUG-51853 Change-Id: I3ed0cf212d27f68134219b26733bd73d44345fa9 --- src/widgets/kernel/qwidget.cpp | 14 +++++++++----- src/widgets/kernel/qwidget_p.h | 5 ++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 7bd4920..888286e 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -1406,7 +1406,7 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO // topData() ensures the extra is created but does not ensure 'window' is non-null // in case the extra was already valid. if (!win) { - createTLSysExtra(); + createTLSysExtra(window); win = topData()->window; } @@ -1419,7 +1419,8 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO win->setProperty("_q_showWithoutActivating", QVariant(true)); if (q->testAttribute(Qt::WA_MacAlwaysShowToolWindow)) win->setProperty("_q_macAlwaysShowToolWindow", QVariant::fromValue(QVariant(true))); - win->setFlags(data.window_flags); + if (win->type() != Qt::ForeignWindow) // ### fixme: Set flags or preserve Qt::ForeignWindow ? + win->setFlags(data.window_flags); fixPosIncludesFrame(); if (q->testAttribute(Qt::WA_Moved) || !QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowManagement)) @@ -1499,11 +1500,14 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO static const char activeXNativeParentHandleProperty[] = "_q_embedded_native_parent_handle"; #endif -void QWidgetPrivate::createTLSysExtra() +void QWidgetPrivate::createTLSysExtra(WId id) { Q_Q(QWidget); if (!extra->topextra->window && (q->testAttribute(Qt::WA_NativeWindow) || q->isWindow())) { - extra->topextra->window = new QWidgetWindow(q); + if (id) + extra->topextra->window = QWindow::fromWinId(id); + else + extra->topextra->window = new QWidgetWindow(q); if (extra->minw || extra->minh) extra->topextra->window->setMinimumSize(QSize(extra->minw, extra->minh)); if (extra->maxw != QWIDGETSIZE_MAX || extra->maxh != QWIDGETSIZE_MAX) @@ -1877,7 +1881,7 @@ void QWidgetPrivate::deleteTLSysExtra() //delete the qglcontext before we delete the qplatformopenglcontext. //One unfortunate thing about this is that we potentially create a glContext just to //delete it straight afterwards. - if (extra->topextra->window) { + if (extra->topextra->window && extra->topextra->window->type() != Qt::ForeignWindow) { extra->topextra->window->destroy(); } setWinId(0); diff --git a/src/widgets/kernel/qwidget_p.h b/src/widgets/kernel/qwidget_p.h index 7eb8d04..a7e372e 100644 --- a/src/widgets/kernel/qwidget_p.h +++ b/src/widgets/kernel/qwidget_p.h @@ -68,7 +68,6 @@ QT_BEGIN_NAMESPACE // Extra QWidget data // - to minimize memory usage for members that are seldom used. // - top-level widgets have extra extra data to reduce cost further -class QWidgetWindow; class QPaintEngine; class QPixmap; class QWidgetBackingStore; @@ -154,7 +153,7 @@ struct QTLWExtra { QWidgetBackingStoreTracker backingStoreTracker; QBackingStore *backingStore; QPainter *sharedPainter; - QWidgetWindow *window; + QWindow *window; QOpenGLContext *shareContext; // Implicit pointers (shared_null). @@ -341,7 +340,7 @@ public: void deleteExtra(); void createSysExtra(); void deleteSysExtra(); - void createTLSysExtra(); + void createTLSysExtra(WId id = 0); void deleteTLSysExtra(); void updateSystemBackground(); void propagatePaletteChange(); -- 2.5.0.windows.1