From 289a51942531b5f25760bb029e936a5674ca853f Mon Sep 17 00:00:00 2001
From: Jiajin Cui <cuijiajin@uniontech.com>
Date: Wed, 1 Jul 2020 18:45:39 +0800
Subject: [PATCH v6 3/4] user32: Make that subwindows shouldn't change z-order
 when calling SetWindowPos with TOPMOST/NOTOPMOST.

Signed-off-by: Jiajin Cui <cuijiajin@uniontech.com>
---
 dlls/user32/tests/msg.c |  4 ++--
 dlls/user32/tests/win.c | 23 +++++++----------------
 dlls/user32/winpos.c    |  4 ++++
 3 files changed, 13 insertions(+), 18 deletions(-)

diff --git a/dlls/user32/tests/msg.c b/dlls/user32/tests/msg.c
index 3a4382eb26..92b14ef52c 100644
--- a/dlls/user32/tests/msg.c
+++ b/dlls/user32/tests/msg.c
@@ -5809,7 +5809,7 @@ static void test_setwindowpos(void)
     flush_sequence();
 
     res = SetWindowPos(hwnd_A, HWND_TOPMOST, 5, 5, 10, 10, SWP_NOACTIVATE | SWP_SHOWWINDOW );
-    ok_sequence(WmChildTOPMOSTZOrder, "Z-Order", TRUE);
+    ok_sequence(WmChildTOPMOSTZOrder, "Z-Order", FALSE);
     ok(res == TRUE, "SetWindowPos expected TRUE, got %ld\n", res);
 
     res = SetWindowPos(hwnd_A, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE);
@@ -5817,7 +5817,7 @@ static void test_setwindowpos(void)
     ok(res == TRUE, "SetWindowPos expected TRUE, got %ld\n", res);
 
     res = SetWindowPos(hwnd_A, HWND_NOTOPMOST, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE);
-    ok_sequence(WmChildTOPMOSTZOrder, "Z-Order", TRUE);
+    ok_sequence(WmChildTOPMOSTZOrder, "Z-Order", FALSE);
     ok(res == TRUE, "SetWindowPos expected TRUE, got %ld\n", res);
 
     DestroyWindow(hwnd_A);
diff --git a/dlls/user32/tests/win.c b/dlls/user32/tests/win.c
index 654e5700fe..18ef4f0f74 100644
--- a/dlls/user32/tests/win.c
+++ b/dlls/user32/tests/win.c
@@ -2594,7 +2594,7 @@ static void test_SetWindowPos(HWND hwnd, HWND hwnd2)
     ret = SetWindowPos(hwnd_child, HWND_NOTOPMOST, 1, 2, 3, 4, 0);
     ok(ret, "Got %d.\n", ret);
     GetWindowRect(hwnd_child, &rc2);
-    todo_wine ok(EqualRect(&rc1, &rc2), "%s != %s.\n", wine_dbgstr_rect(&rc1), wine_dbgstr_rect(&rc2));
+    ok(EqualRect(&rc1, &rc2), "%s != %s.\n", wine_dbgstr_rect(&rc1), wine_dbgstr_rect(&rc2));
     check_active_state(hwnd2, hwnd2, hwnd2);
     SetWindowPos(hwnd_child, HWND_NOTOPMOST, 0, 0, rc1.right - rc1.left, rc1.bottom - rc1.top, 0);
 
@@ -2602,7 +2602,7 @@ static void test_SetWindowPos(HWND hwnd, HWND hwnd2)
     ret = SetWindowPos(hwnd_child, HWND_TOPMOST, 1, 2, 3, 4, 0);
     ok(ret, "Got %d.\n", ret);
     GetWindowRect(hwnd_child, &rc2);
-    todo_wine ok(EqualRect(&rc1, &rc2), "%s != %s.\n", wine_dbgstr_rect(&rc1), wine_dbgstr_rect(&rc2));
+    ok(EqualRect(&rc1, &rc2), "%s != %s.\n", wine_dbgstr_rect(&rc1), wine_dbgstr_rect(&rc2));
     check_active_state(hwnd2, hwnd2, hwnd2);
     SetWindowPos(hwnd_child, HWND_TOPMOST, 0, 0, rc1.right - rc1.left, rc1.bottom - rc1.top, 0);
 
@@ -3046,23 +3046,17 @@ todo_wine check_z_order(hwnd_A, hwnd_C, 0, 0, TRUE);
     SetWindowPos(hwnd_A, HWND_TOPMOST, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE);
     check_z_order(hwnd_C, hwnd_B, hwnd_A, 0, FALSE);
     check_z_order(hwnd_B, 0, hwnd_C, 0, FALSE);
-    check_z_order(hwnd_A, hwnd_C, 0, 0, TRUE);
+todo_wine check_z_order(hwnd_A, hwnd_C, 0, 0, TRUE);
 
     SetWindowPos(hwnd_B, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE);
-todo_wine
-{
     check_z_order(hwnd_C, 0, hwnd_A, 0, FALSE);
     check_z_order(hwnd_B, hwnd_A, 0, 0, FALSE);
-    check_z_order(hwnd_A, hwnd_C, hwnd_B, 0, TRUE);
-}
+todo_wine check_z_order(hwnd_A, hwnd_C, hwnd_B, 0, TRUE);
 
     SetWindowPos(hwnd_A, HWND_NOTOPMOST, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE);
-todo_wine
-{
     check_z_order(hwnd_C, 0, hwnd_A, 0, FALSE);
     check_z_order(hwnd_B, hwnd_A, 0, 0, FALSE);
-    check_z_order(hwnd_A, hwnd_C, hwnd_B, 0, TRUE);
-}
+todo_wine check_z_order(hwnd_A, hwnd_C, hwnd_B, 0, TRUE);
 
     SetWindowPos(hwnd_A, HWND_BOTTOM, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE);
     check_z_order(hwnd_C, hwnd_A, hwnd_B, 0, FALSE);
@@ -3070,15 +3064,12 @@ todo_wine
 todo_wine check_z_order(hwnd_A, 0, hwnd_C, 0, TRUE);
 
     SetWindowPos(hwnd_C, HWND_TOPMOST, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE);
-todo_wine
-{
     check_z_order(hwnd_C, hwnd_A, hwnd_B, 0, FALSE);
     check_z_order(hwnd_B, hwnd_C, 0, 0, FALSE);
-    check_z_order(hwnd_A, 0, hwnd_C, 0, TRUE);
-}
+todo_wine check_z_order(hwnd_A, 0, hwnd_C, 0, TRUE);
 
     SetWindowPos(hwnd_C, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE);
-todo_wine check_z_order(hwnd_C, hwnd_B, 0, 0, FALSE);
+    check_z_order(hwnd_C, hwnd_B, 0, 0, FALSE);
     check_z_order(hwnd_B, hwnd_A, hwnd_C, 0, FALSE);
 todo_wine check_z_order(hwnd_A, 0, hwnd_B, 0, TRUE);
 
diff --git a/dlls/user32/winpos.c b/dlls/user32/winpos.c
index b92a20df18..7d5398ce8d 100644
--- a/dlls/user32/winpos.c
+++ b/dlls/user32/winpos.c
@@ -2258,6 +2258,10 @@ BOOL USER_SetWindowPos( WINDOWPOS * winpos, int parent_x, int parent_y )
             if (!insertafter_parent) return FALSE;
             if (insertafter_parent != parent) return TRUE;
         }
+
+        if ((GetWindowLongW( winpos->hwnd, GWL_STYLE ) & WS_CHILD) &&
+            (winpos->hwndInsertAfter == HWND_TOPMOST || winpos->hwndInsertAfter == HWND_NOTOPMOST))
+            return TRUE;
     }
 
     /* Make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
-- 
2.20.1

