Commit 9687ceaf authored by Alexandre Julliard's avatar Alexandre Julliard

user32: Don't allow activating a WS_CHILD top-level window through SetFocus.

parent 63e6dbc1
......@@ -266,7 +266,11 @@ HWND WINAPI SetFocus( HWND hwnd )
LONG style = GetWindowLongW( hwndTop, GWL_STYLE );
if (style & (WS_MINIMIZE | WS_DISABLED)) return 0;
parent = GetAncestor( hwndTop, GA_PARENT );
if (!parent || parent == GetDesktopWindow()) break;
if (!parent || parent == GetDesktopWindow())
{
if ((style & (WS_POPUP|WS_CHILD)) == WS_CHILD) return 0;
break;
}
if (parent == get_hwnd_message_parent()) return 0;
hwndTop = parent;
}
......
......@@ -2513,7 +2513,7 @@ static LRESULT WINAPI set_focus_on_activate_proc(HWND hwnd, UINT msg, WPARAM wp,
static void test_SetFocus(HWND hwnd)
{
HWND child, child2;
HWND child, child2, ret;
WNDPROC old_wnd_proc;
/* check if we can set focus to non-visible windows */
......@@ -2588,9 +2588,32 @@ todo_wine
ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
todo_wine
ok( GetFocus() == child, "Focus should be on child %p, not %p\n", child, GetFocus() );
SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)old_wnd_proc);
SetFocus( hwnd );
SetParent( child, GetDesktopWindow());
SetParent( child2, child );
ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
ret = SetFocus( child2 );
ok( ret == 0, "SetFocus %p should fail\n", child2);
ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
ret = SetFocus( child );
ok( ret == 0, "SetFocus %p should fail\n", child);
ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
SetWindowLongW( child, GWL_STYLE, WS_POPUP|WS_CHILD );
SetFocus( child2 );
ok( GetActiveWindow() == child, "child window %p should be active\n", child);
ok( GetFocus() == child2, "Focus should be on child2 %p\n", child2 );
SetFocus( hwnd );
ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
SetFocus( child );
ok( GetActiveWindow() == child, "child window %p should be active\n", child);
ok( GetFocus() == child, "Focus should be on child %p\n", child );
DestroyWindow( child2 );
DestroyWindow( child );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment