Alex Henrie : user32: If a dialog has no tab-accessible controls, set focus to first control (with tests).
Alexandre Julliard
julliard at winehq.org
Mon Dec 5 14:55:03 CST 2011
Module: wine
Branch: master
Commit: 59c398b8ed46e0852386ad913c0f0a658a196523
URL: http://source.winehq.org/git/wine.git/?a=commit;h=59c398b8ed46e0852386ad913c0f0a658a196523
Author: Alex Henrie <alexhenrie24 at gmail.com>
Date: Fri Dec 2 00:37:01 2011 -0700
user32: If a dialog has no tab-accessible controls, set focus to first control (with tests).
---
dlls/user32/dialog.c | 2 ++
dlls/user32/tests/dialog.c | 28 ++++++++++++++++++++++++++--
dlls/user32/tests/resource.rc | 8 ++++++++
3 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/dlls/user32/dialog.c b/dlls/user32/dialog.c
index b9e739a..c6b2455 100644
--- a/dlls/user32/dialog.c
+++ b/dlls/user32/dialog.c
@@ -695,6 +695,7 @@ static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCVOID dlgTemplate,
if (dlgProc)
{
HWND focus = GetNextDlgTabItem( hwnd, 0, FALSE );
+ if (!focus) focus = GetNextDlgGroupItem( hwnd, 0, FALSE );
if (SendMessageW( hwnd, WM_INITDIALOG, (WPARAM)focus, param ) && IsWindow( hwnd ) &&
((~template.style & DS_CONTROL) || (template.style & WS_VISIBLE)))
{
@@ -702,6 +703,7 @@ static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCVOID dlgTemplate,
* WM_INITDIALOG may have changed the tab order, so find the first
* tabstop control again. */
dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE );
+ if (!dlgInfo->hwndFocus) dlgInfo->hwndFocus = GetNextDlgGroupItem( hwnd, 0, FALSE );
if( dlgInfo->hwndFocus )
SetFocus( dlgInfo->hwndFocus );
}
diff --git a/dlls/user32/tests/dialog.c b/dlls/user32/tests/dialog.c
index fa14b36..404aeee 100644
--- a/dlls/user32/tests/dialog.c
+++ b/dlls/user32/tests/dialog.c
@@ -832,8 +832,7 @@ static void test_initial_focus(void)
{
/* Test 1:
* This test intentionally returns FALSE in response to WM_INITDIALOG
- * without setting focus to a control. This is not allowed according to
- * MSDN, but it is exactly what MFC's CFormView does.
+ * without setting focus to a control. This is what MFC's CFormView does.
*
* Since the WM_INITDIALOG handler returns FALSE without setting the focus,
* the focus should initially be NULL. Later, when we manually set focus to
@@ -915,6 +914,31 @@ static void test_initial_focus(void)
DestroyWindow(hDlg);
}
+
+ /* Test 4:
+ * If the dialog has no tab-accessible controls, set focus to first control */
+ {
+ HWND hDlg;
+ HRSRC hResource;
+ HANDLE hTemplate;
+ DLGTEMPLATE* pTemplate;
+ HWND hLabel;
+
+ hResource = FindResourceA(g_hinst,"FOCUS_TEST_DIALOG_2", RT_DIALOG);
+ hTemplate = LoadResource(g_hinst, hResource);
+ pTemplate = LockResource(hTemplate);
+
+ hDlg = CreateDialogIndirectParamA(g_hinst, pTemplate, NULL, focusDlgWinProc, 0);
+ g_hwndInitialFocusT1 = GetFocus();
+ hLabel = GetDlgItem(hDlg, 200);
+ ok (hDlg != 0, "Failed to create test dialog.\n");
+
+ ok ((g_hwndInitialFocusT1 == hLabel),
+ "Focus should have been set to the first control, expected (%p) got (%p).\n",
+ hLabel, g_hwndInitialFocusT1);
+
+ DestroyWindow(hDlg);
+ }
}
static void test_GetDlgItemText(void)
diff --git a/dlls/user32/tests/resource.rc b/dlls/user32/tests/resource.rc
index cce1478..be47038 100644
--- a/dlls/user32/tests/resource.rc
+++ b/dlls/user32/tests/resource.rc
@@ -99,6 +99,14 @@ FONT 8, "MS Shell Dlg"
EDITTEXT 200,4,4,50,14
}
+FOCUS_TEST_DIALOG_2 DIALOG 0, 0, 60, 30
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Test dialog"
+FONT 8, "MS Shell Dlg"
+{
+ LTEXT "Hello world", 200,4,4,50,14
+}
+
IDD_DIALOG DIALOG 0, 0, 186, 95
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog"
More information about the wine-cvs
mailing list