From e7fc72f7968f1a3e370f0886bf4068a1c472f8db Mon Sep 17 00:00:00 2001 From: Sebastian Gasiorek Date: Fri, 2 Dec 2005 22:50:23 +0000 Subject: [PATCH] imported newer version of DIALOG_DoDialogBox and DEFDLG_RestoreFocus from Wine svn path=/trunk/; revision=19834 --- reactos/lib/user32/windows/dialog.c | 30 +++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/reactos/lib/user32/windows/dialog.c b/reactos/lib/user32/windows/dialog.c index 05234f98596..b1a46cc92d7 100644 --- a/reactos/lib/user32/windows/dialog.c +++ b/reactos/lib/user32/windows/dialog.c @@ -502,23 +502,30 @@ INT DIALOG_DoDialogBox( HWND hwnd, HWND owner ) MSG msg; INT retval; HWND ownerMsg = GetAncestor( owner, GA_ROOT ); + BOOL bFirstEmpty; + if (!(dlgInfo = GETDLGINFO(hwnd))) return -1; + bFirstEmpty = TRUE; if (!(dlgInfo->flags & DF_END)) /* was EndDialog called in WM_INITDIALOG ? */ { - ShowWindow( hwnd, SW_SHOW ); for (;;) { - if (!(GetWindowLongW( hwnd, GWL_STYLE ) & DS_NOIDLEMSG)) + if (!PeekMessageW( &msg, 0, 0, 0, PM_REMOVE )) { - if (!PeekMessageW( &msg, 0, 0, 0, PM_REMOVE )) + if (bFirstEmpty) { + /* ShowWindow the first time the queue goes empty */ + ShowWindow( hwnd, SW_SHOWNORMAL ); + bFirstEmpty = FALSE; + } + if (!(GetWindowLongW( hwnd, GWL_STYLE ) & DS_NOIDLEMSG)) + { /* No message present -> send ENTERIDLE and wait */ SendMessageW( ownerMsg, WM_ENTERIDLE, MSGF_DIALOGBOX, (LPARAM)hwnd ); - if (!GetMessageW( &msg, 0, 0, 0 )) break; } + if (!GetMessageW( &msg, 0, 0, 0 )) break; } - else if (!GetMessageW( &msg, 0, 0, 0 )) break; if (!IsWindow( hwnd )) return -1; if (!(dlgInfo->flags & DF_END) && !IsDialogMessageW( hwnd, &msg)) @@ -889,13 +896,16 @@ static void DEFDLG_RestoreFocus( HWND hwnd ) if (IsIconic( hwnd )) return; if (!(infoPtr = GETDLGINFO(hwnd))) 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. */ }