From 6be2aea1b33f2d66f91ac6aa59072432ce55c673 Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Mon, 12 Oct 2009 12:47:54 +0000 Subject: [PATCH] - Change DIALOG_CreateIndirect location in source to make DEFDLG_SaveFocus available for use. - DIALOG_CreateIndirect: The current window with focus could have been set in the dialog's procedure, so save the current focused window after sending WM_INITDIALOG and before any other message are sent that modify focus. - Fixes setting focus on Open and Close dialogs to the FileName edit control in OpenOffice. svn path=/trunk/; revision=43396 --- reactos/dll/win32/user32/windows/dialog.c | 111 +++++++++++----------- 1 file changed, 56 insertions(+), 55 deletions(-) diff --git a/reactos/dll/win32/user32/windows/dialog.c b/reactos/dll/win32/user32/windows/dialog.c index 109c936b3da..7011fc27ec1 100644 --- a/reactos/dll/win32/user32/windows/dialog.c +++ b/reactos/dll/win32/user32/windows/dialog.c @@ -682,7 +682,59 @@ static LPCSTR DIALOG_ParseTemplate32( LPCSTR template, DLG_TEMPLATE * result ) return (LPCSTR)((((UINT_PTR)p) + 3) & ~3); } - /*********************************************************************** +/*********************************************************************** + * DEFDLG_SetFocus + * + * Set the focus to a control of the dialog, selecting the text if + * the control is an edit dialog. + */ +static void DEFDLG_SetFocus( HWND hwndDlg, HWND hwndCtrl ) +{ + if (SendMessageW( hwndCtrl, WM_GETDLGCODE, 0, 0 ) & DLGC_HASSETSEL) + SendMessageW( hwndCtrl, EM_SETSEL, 0, -1 ); + SetFocus( hwndCtrl ); +} + + +/*********************************************************************** + * DEFDLG_SaveFocus + */ +static void DEFDLG_SaveFocus( HWND hwnd ) +{ + DIALOGINFO *infoPtr; + HWND hwndFocus = GetFocus(); + + if (!hwndFocus || !IsChild( hwnd, hwndFocus )) return; + if (!(infoPtr = GETDLGINFO(hwnd))) return; + infoPtr->hwndFocus = hwndFocus; + /* Remove default button */ +} + + +/*********************************************************************** + * DEFDLG_RestoreFocus + */ +static void DEFDLG_RestoreFocus( HWND hwnd ) +{ + DIALOGINFO *infoPtr; + + if (IsIconic( hwnd )) return; + if (!(infoPtr = GETDLGINFO(hwnd))) return; + /* Don't set the focus back to controls if EndDialog is already called.*/ + 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. */ +} + +/*********************************************************************** * DIALOG_CreateIndirect * Creates a dialog box window * @@ -923,6 +975,9 @@ static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCVOID dlgTemplate, if( dlgInfo->hwndFocus ) SetFocus( dlgInfo->hwndFocus ); } +//// ReactOS + DEFDLG_SaveFocus( hwnd ); +//// } //// ReactOS Rev 30613 & 30644 if (!(GetWindowLongPtrW( hwnd, GWL_STYLE ) & WS_CHILD)) @@ -939,60 +994,6 @@ static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCVOID dlgTemplate, return 0; } - -/*********************************************************************** - * DEFDLG_SetFocus - * - * Set the focus to a control of the dialog, selecting the text if - * the control is an edit dialog. - */ -static void DEFDLG_SetFocus( HWND hwndDlg, HWND hwndCtrl ) -{ - if (SendMessageW( hwndCtrl, WM_GETDLGCODE, 0, 0 ) & DLGC_HASSETSEL) - SendMessageW( hwndCtrl, EM_SETSEL, 0, -1 ); - SetFocus( hwndCtrl ); -} - - -/*********************************************************************** - * DEFDLG_SaveFocus - */ -static void DEFDLG_SaveFocus( HWND hwnd ) -{ - DIALOGINFO *infoPtr; - HWND hwndFocus = GetFocus(); - - if (!hwndFocus || !IsChild( hwnd, hwndFocus )) return; - if (!(infoPtr = GETDLGINFO(hwnd))) return; - infoPtr->hwndFocus = hwndFocus; - /* Remove default button */ -} - - -/*********************************************************************** - * DEFDLG_RestoreFocus - */ -static void DEFDLG_RestoreFocus( HWND hwnd ) -{ - DIALOGINFO *infoPtr; - - if (IsIconic( hwnd )) return; - if (!(infoPtr = GETDLGINFO(hwnd))) return; - /* Don't set the focus back to controls if EndDialog is already called.*/ - 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. */ -} - - /*********************************************************************** * DEFDLG_FindDefButton *