The initial dialog focus should be established by the default handler

for SetFocus(), not in the dialog creation code.
This commit is contained in:
Zach Gorman 2004-09-10 22:29:02 +00:00 committed by Alexandre Julliard
parent 5c8ceb497e
commit 9358f3e9a1
3 changed files with 15 additions and 30 deletions

View File

@ -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.

View File

@ -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. */
}

View File

@ -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))
{