Alexandre Julliard : user32: Don' t allow activating a WS_CHILD top-level window through SetFocus.
Alexandre Julliard
julliard at winehq.org
Wed Nov 23 13:40:03 CST 2011
Module: wine
Branch: master
Commit: 9687ceaf1df1f61159b03966d2d3f796b80b7406
URL: http://source.winehq.org/git/wine.git/?a=commit;h=9687ceaf1df1f61159b03966d2d3f796b80b7406
Author: Alexandre Julliard <julliard at winehq.org>
Date: Tue Nov 22 21:39:37 2011 +0100
user32: Don't allow activating a WS_CHILD top-level window through SetFocus.
---
dlls/user32/focus.c | 6 +++++-
dlls/user32/tests/win.c | 27 +++++++++++++++++++++++++--
2 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/dlls/user32/focus.c b/dlls/user32/focus.c
index 70a2a8a..81169db 100644
--- a/dlls/user32/focus.c
+++ b/dlls/user32/focus.c
@@ -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;
}
diff --git a/dlls/user32/tests/win.c b/dlls/user32/tests/win.c
index 804d452..a090389 100644
--- a/dlls/user32/tests/win.c
+++ b/dlls/user32/tests/win.c
@@ -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 );
}
More information about the wine-cvs
mailing list