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, ...@@ -695,6 +695,7 @@ static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCVOID dlgTemplate,
if (dlgProc) if (dlgProc)
{ {
HWND focus = GetNextDlgTabItem( hwnd, 0, FALSE ); HWND focus = GetNextDlgTabItem( hwnd, 0, FALSE );
if (!focus) focus = GetNextDlgGroupItem( hwnd, 0, FALSE );
if (SendMessageW( hwnd, WM_INITDIALOG, (WPARAM)focus, param ) && IsWindow( hwnd ) && if (SendMessageW( hwnd, WM_INITDIALOG, (WPARAM)focus, param ) && IsWindow( hwnd ) &&
((~template.style & DS_CONTROL) || (template.style & WS_VISIBLE))) ((~template.style & DS_CONTROL) || (template.style & WS_VISIBLE)))
{ {
...@@ -702,6 +703,7 @@ static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCVOID dlgTemplate, ...@@ -702,6 +703,7 @@ static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCVOID dlgTemplate,
* WM_INITDIALOG may have changed the tab order, so find the first * WM_INITDIALOG may have changed the tab order, so find the first
* tabstop control again. */ * tabstop control again. */
dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE ); dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE );
if (!dlgInfo->hwndFocus) dlgInfo->hwndFocus = GetNextDlgGroupItem( hwnd, 0, FALSE );
if( dlgInfo->hwndFocus ) if( dlgInfo->hwndFocus )
SetFocus( dlgInfo->hwndFocus ); SetFocus( dlgInfo->hwndFocus );
} }
......
...@@ -832,8 +832,7 @@ static void test_initial_focus(void) ...@@ -832,8 +832,7 @@ static void test_initial_focus(void)
{ {
/* Test 1: /* Test 1:
* This test intentionally returns FALSE in response to WM_INITDIALOG * This test intentionally returns FALSE in response to WM_INITDIALOG
* without setting focus to a control. This is not allowed according to * without setting focus to a control. This is what MFC's CFormView does.
* MSDN, but it is exactly what MFC's CFormView does.
* *
* Since the WM_INITDIALOG handler returns FALSE without setting the focus, * Since the WM_INITDIALOG handler returns FALSE without setting the focus,
* the focus should initially be NULL. Later, when we manually set focus to * the focus should initially be NULL. Later, when we manually set focus to
...@@ -915,6 +914,31 @@ static void test_initial_focus(void) ...@@ -915,6 +914,31 @@ static void test_initial_focus(void)
DestroyWindow(hDlg); 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) static void test_GetDlgItemText(void)
......
...@@ -99,6 +99,14 @@ FONT 8, "MS Shell Dlg" ...@@ -99,6 +99,14 @@ FONT 8, "MS Shell Dlg"
EDITTEXT 200,4,4,50,14 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 IDD_DIALOG DIALOG 0, 0, 186, 95
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog" 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