Fix setParent_sys() to use native methods when checking for toplevel
authorMiikka Heikkinen <miikka.heikkinen@digia.com>
Thu, 16 Aug 2012 10:03:32 +0000 (13:03 +0300)
committerQt by Nokia <qt-info@nokia.com>
Fri, 17 Aug 2012 10:21:34 +0000 (12:21 +0200)
QWindowsWindow::setParent_sys() was checking if window was toplevel
using non-native method, which caused wrong result in some cases
involving native windows. Changed the toplevel check to utilize
native method instead.

Task-number: QTBUG-26826
Change-Id: I72ca17c53c1ed7611f141cee17b2edaaa80c6c17
Reviewed-by: Joerg Bornemann <joerg.bornemann@nokia.com>
src/plugins/platforms/windows/qwindowswindow.cpp

index 773d3f7..8f37616 100644 (file)
@@ -903,8 +903,15 @@ void QWindowsWindow::setParent_sys(const QPlatformWindow *parent) const
 
     }
 
+    // NULL handle means desktop window, which also has its proper handle -> disambiguate
+    HWND desktopHwnd = GetDesktopWindow();
+    if (oldParentHWND == desktopHwnd)
+        oldParentHWND = 0;
+    if (newParentHWND == desktopHwnd)
+        newParentHWND = 0;
+
     if (newParentHWND != oldParentHWND) {
-        const bool wasTopLevel = window()->isTopLevel();
+        const bool wasTopLevel = oldParentHWND == 0;
         const bool isTopLevel = newParentHWND == 0;
 
         setFlag(WithinSetParent);