From 04da02743918d217fc8b760f679d7970a5965a2f Mon Sep 17 00:00:00 2001 From: Andre de la Rocha Date: Mon, 20 Nov 2017 17:04:00 +0100 Subject: [PATCH] Windows QPA: Detect a SetParent into a native window and set isEmbedded Detecting that a Qt window has been reparented into a native window and setting isEmbedded automatically. While there is no specific message for the change in the parent window, a WM_WINDOWPOSCHANGING message indicating a change in the Z order is sent. We can recognize an embedding condition by detecting that our QWindow does not have another QWindow as a parent, but the HWND associated with it has another HWND as a parent, which is not the desktop window. This change should cover the use case where a Qt-based plugin must return a HWND to a host application, where the host application will then reparent the HWND as it sees fit, outside of Qt control. Task-number: QTBUG-64116 Change-Id: Iec417c0dd55ad68eff1ea75bb6f5b5495489c31e Reviewed-by: Friedemann Kleint --- src/plugins/platforms/windows/qwindowswindow.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index 24eab2c662e..8702ce7bab7 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -2070,9 +2070,17 @@ void QWindowsWindow::propagateSizeHints() bool QWindowsWindow::handleGeometryChangingMessage(MSG *message, const QWindow *qWindow, const QMargins &margins) { + WINDOWPOS *windowPos = reinterpret_cast(message->lParam); + if ((windowPos->flags & SWP_NOZORDER) == 0) { + if (QWindowsWindow *platformWindow = QWindowsWindow::windowsWindowOf(qWindow)) { + QWindow *parentWindow = qWindow->parent(); + HWND parentHWND = GetAncestor(windowPos->hwnd, GA_PARENT); + HWND desktopHWND = GetDesktopWindow(); + platformWindow->m_data.embedded = !parentWindow && parentHWND && (parentHWND != desktopHWND); + } + } if (!qWindow->isTopLevel()) // Implement hasHeightForWidth(). return false; - WINDOWPOS *windowPos = reinterpret_cast(message->lParam); if ((windowPos->flags & (SWP_NOCOPYBITS | SWP_NOSIZE))) return false; const QRect suggestedFrameGeometry(windowPos->x, windowPos->y,