From 2ccd34fd20b72a1cd4125d67dd206d4f968a1b5d Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Wed, 8 Aug 2012 13:48:29 +0300 Subject: [PATCH] Use native handles for parent change check in QWindowsWindow. QWindow::setParent() sets the parent to zero instead of the desired parent, if platform window has not yet been created for the parent. This caused QWindowsWindow::setParent() to skip setting the parent later, when correct window was specified, as the QWindow parent-child relationship hadn't changed. Fixed by changing the the check to use native handles instead. Task-number: QTBUG-26791 Change-Id: I292a1ddf746583a7268f2d07c20166995c0dd7d6 Reviewed-by: Joerg Bornemann --- .../platforms/windows/qwindowswindow.cpp | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index 6e0d9b5924..edb3e8c7a1 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -888,31 +888,35 @@ void QWindowsWindow::setParent(const QPlatformWindow *newParent) if (QWindowsContext::verboseWindows) qDebug() << __FUNCTION__ << window() << newParent; - if (newParent != parent() && m_data.hwnd) + if (m_data.hwnd) setParent_sys(newParent); } void QWindowsWindow::setParent_sys(const QPlatformWindow *parent) const { - HWND parentHWND = 0; + // Use GetAncestor instead of GetParent, as GetParent can return owner window for toplevels + HWND oldParentHWND = GetAncestor(m_data.hwnd, GA_PARENT); + HWND newParentHWND = 0; if (parent) { const QWindowsWindow *parentW = static_cast(parent); - parentHWND = parentW->handle(); + newParentHWND = parentW->handle(); } - const bool wasTopLevel = window()->isTopLevel(); - const bool isTopLevel = parentHWND == 0; + if (newParentHWND != oldParentHWND) { + const bool wasTopLevel = window()->isTopLevel(); + const bool isTopLevel = newParentHWND == 0; - setFlag(WithinSetParent); - SetParent(m_data.hwnd, parentHWND); - clearFlag(WithinSetParent); + setFlag(WithinSetParent); + SetParent(m_data.hwnd, newParentHWND); + clearFlag(WithinSetParent); - // WS_CHILD/WS_POPUP must be manually set/cleared in addition - // to dialog frames, etc (see SetParent() ) if the top level state changes. - if (wasTopLevel != isTopLevel) { - const unsigned flags = isTopLevel ? unsigned(0) : unsigned(WindowCreationData::ForceChild); - setWindowFlags_sys(window()->windowFlags(), flags); + // WS_CHILD/WS_POPUP must be manually set/cleared in addition + // to dialog frames, etc (see SetParent() ) if the top level state changes. + if (wasTopLevel != isTopLevel) { + const unsigned flags = isTopLevel ? unsigned(0) : unsigned(WindowCreationData::ForceChild); + setWindowFlags_sys(window()->windowFlags(), flags); + } } }