Commit 9358f3e9 authored by Zach Gorman's avatar Zach Gorman Committed by Alexandre Julliard

The initial dialog focus should be established by the default handler

for SetFocus(), not in the dialog creation code.
parent 5c8ceb49
......@@ -769,11 +769,11 @@ static void InitialFocusTest (void)
"Expected NULL focus, got %s (%p).\n",
GetHwndString(g_hwndInitialFocusT1), g_hwndInitialFocusT1);
todo_wine ok ((g_hwndInitialFocusT2 == g_hwndButton2),
"Error after first SetFocus() when WM_INITDIALOG returned FALSE: "
"Expected the second button (%p), got %s (%p).\n",
g_hwndButton2, GetHwndString(g_hwndInitialFocusT2),
g_hwndInitialFocusT2);
ok ((g_hwndInitialFocusT2 == g_hwndButton2),
"Error after first SetFocus() when WM_INITDIALOG returned FALSE: "
"Expected the second button (%p), got %s (%p).\n",
g_hwndButton2, GetHwndString(g_hwndInitialFocusT2),
g_hwndInitialFocusT2);
/* Test 2:
* This is the same as above, except WM_INITDIALOG is made to return TRUE.
......
......@@ -96,13 +96,16 @@ static void DEFDLG_RestoreFocus( HWND hwnd )
if (IsIconic( hwnd )) return;
if (!(infoPtr = DIALOG_get_info( hwnd, FALSE ))) return;
if (!IsWindow( infoPtr->hwndFocus )) return;
/* Don't set the focus back to controls if EndDialog is already called.*/
if (!(infoPtr->flags & DF_END))
{
DEFDLG_SetFocus( hwnd, infoPtr->hwndFocus );
return;
if (infoPtr->flags & DF_END) return;
if (!IsWindow(infoPtr->hwndFocus) || infoPtr->hwndFocus == hwnd) {
/* If no saved focus control exists, set focus to the first visible,
non-disabled, WS_TABSTOP control in the dialog */
infoPtr->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE );
if (!IsWindow( infoPtr->hwndFocus )) return;
}
DEFDLG_SetFocus( hwnd, infoPtr->hwndFocus );
/* This used to set infoPtr->hwndFocus to NULL for no apparent reason,
sometimes losing focus when receiving WM_SETFOCUS messages. */
}
......
......@@ -657,33 +657,15 @@ static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCVOID dlgTemplate,
if (DIALOG_CreateControls32( hwnd, dlgTemplate, &template, hInst, unicode ))
{
HWND hwndPreInitFocus;
/* Send initialisation messages and set focus */
dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE );
hwndPreInitFocus = GetFocus();
if (SendMessageA( hwnd, WM_INITDIALOG, (WPARAM)dlgInfo->hwndFocus, param ))
if (SendMessageA( hwnd, WM_INITDIALOG, (WPARAM)dlgInfo->hwndFocus, param ))
{
/* check where the focus is again,
* some controls status might have changed in WM_INITDIALOG */
/* By returning TRUE, app has requested a default focus assignment */
dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE);
if( dlgInfo->hwndFocus )
SetFocus( dlgInfo->hwndFocus );
}
else
{
/* If the dlgproc has returned FALSE (indicating handling of keyboard focus)
but the focus has not changed, set the focus where we expect it. */
if ((GetFocus() == hwndPreInitFocus) &&
(GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE))
{
dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE);
if( dlgInfo->hwndFocus )
SetFocus( dlgInfo->hwndFocus );
}
}
if (template.style & WS_VISIBLE && !(GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE))
{
......
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