Commit 59c398b8 authored by Alex Henrie's avatar Alex Henrie Committed by Alexandre Julliard

user32: If a dialog has no tab-accessible controls, set focus to first control (with tests).

parent 7f476a23
......@@ -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 );
}
......
......@@ -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)
......
......@@ -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"
......
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