From 91eced0ce5279b59715330466742925d89e8d0f5 Mon Sep 17 00:00:00 2001 From: Piotr Caban Date: Mon, 22 Dec 2014 16:36:48 +0100 Subject: [PATCH] user32: Only store dialog focus when window is hidden or inactive. --- dlls/user32/defdlg.c | 4 +--- dlls/user32/tests/dialog.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/dlls/user32/defdlg.c b/dlls/user32/defdlg.c index e4b55f38904..00a73c6b927 100644 --- a/dlls/user32/defdlg.c +++ b/dlls/user32/defdlg.c @@ -105,9 +105,7 @@ static void DEFDLG_RestoreFocus( HWND hwnd, BOOL justActivate ) SetFocus( infoPtr->hwndFocus ); else DEFDLG_SetFocus( infoPtr->hwndFocus ); - - /* This used to set infoPtr->hwndFocus to NULL for no apparent reason, - sometimes losing focus when receiving WM_SETFOCUS messages. */ + infoPtr->hwndFocus = NULL; } diff --git a/dlls/user32/tests/dialog.c b/dlls/user32/tests/dialog.c index ef72cfe9eaf..63e76f78b34 100644 --- a/dlls/user32/tests/dialog.c +++ b/dlls/user32/tests/dialog.c @@ -1357,6 +1357,24 @@ static void test_SaveRestoreFocus(void) foundId = GetWindowLongPtrA(GetFocus(), GWLP_ID); ok (foundId == 1001, "Second edit box should have gained focus after dialog reactivation. Expected: %d, Found: %ld\n", 1001, foundId); + /* set focus to the dialog */ + SetFocus(hDlg); + + foundId = GetWindowLongPtrA(GetFocus(), GWLP_ID); + ok (foundId == 1000, "First edit box should have gained focus on dialog focus. Expected: %d, Found: %ld\n", 1000, foundId); + + /* select second tabbable item */ + SetFocus(GetNextDlgTabItem(hDlg, GetNextDlgTabItem(hDlg, NULL, FALSE), FALSE)); + + foundId = GetWindowLongPtrA(GetFocus(), GWLP_ID); + ok (foundId == 1001, "Second edit box should have gained focus. Expected: %d, Found: %ld\n", 1001, foundId); + + /* send WM_ACTIVATE message to already active dialog */ + SendMessageA(hDlg, WM_ACTIVATE, MAKEWPARAM(WA_ACTIVE, 0), 0); + + foundId = GetWindowLongPtrA(GetFocus(), GWLP_ID); + ok (foundId == 1001, "Second edit box should have gained focus. Expected: %d, Found: %ld\n", 1001, foundId); + /* disable the 2nd box */ EnableWindow(GetFocus(), FALSE);