Module: wine Branch: master Commit: 73ee2a8b4f7d13701c756721b2b9b92b4ddabd0d URL: http://source.winehq.org/git/wine.git/?a=commit;h=73ee2a8b4f7d13701c756721b2...
Author: Piotr Caban piotr@codeweavers.com Date: Tue Feb 16 14:49:10 2016 +0100
user32: Select text control content while setting dialog focus.
Signed-off-by: Piotr Caban piotr@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/user32/dialog.c | 4 ++++ dlls/user32/tests/dialog.c | 31 ++++++++++++++++++++++++++++++- dlls/user32/tests/resource.rc | 8 ++++++++ 3 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/dlls/user32/dialog.c b/dlls/user32/dialog.c index 8340850..e841152 100644 --- a/dlls/user32/dialog.c +++ b/dlls/user32/dialog.c @@ -707,7 +707,11 @@ static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCVOID dlgTemplate, focus = GetNextDlgTabItem( hwnd, 0, FALSE ); if (!focus) focus = GetNextDlgGroupItem( hwnd, 0, FALSE ); if (focus) + { + if (SendMessageW( focus, WM_GETDLGCODE, 0, 0 ) & DLGC_HASSETSEL) + SendMessageW( focus, EM_SETSEL, 0, MAXLONG ); SetFocus( focus ); + } } }
diff --git a/dlls/user32/tests/dialog.c b/dlls/user32/tests/dialog.c index eede834..a6cd1be 100644 --- a/dlls/user32/tests/dialog.c +++ b/dlls/user32/tests/dialog.c @@ -786,7 +786,8 @@ static INT_PTR CALLBACK focusDlgWinProc (HWND hDlg, UINT uiMsg, WPARAM wParam, switch (uiMsg) { case WM_INITDIALOG: - return TRUE; + SetWindowTextA(GetDlgItem(hDlg, 200), "new caption"); + return TRUE;
case WM_COMMAND: if (LOWORD(wParam) == 200) @@ -958,6 +959,34 @@ static void test_focus(void)
DestroyWindow(hDlg); } + + /* Test 5: + * Select textbox's text on creation */ + { + HWND hDlg; + HRSRC hResource; + HANDLE hTemplate; + DLGTEMPLATE* pTemplate; + HWND edit; + DWORD selectionStart = 0xdead, selectionEnd = 0xbeef; + + hResource = FindResourceA(g_hinst,"FOCUS_TEST_DIALOG_3", (LPCSTR)RT_DIALOG); + hTemplate = LoadResource(g_hinst, hResource); + pTemplate = LockResource(hTemplate); + + hDlg = CreateDialogIndirectParamA(g_hinst, pTemplate, NULL, focusDlgWinProc, 0); + ok(hDlg != 0, "Failed to create test dialog.\n"); + edit = GetDlgItem(hDlg, 200); + + ok(GetFocus() == edit, "Focus not set to edit, focus=%p, dialog=%p, edit=%p\n", + GetFocus(), hDlg, edit); + SendMessageA(edit, EM_GETSEL, (WPARAM)&selectionStart, (LPARAM)&selectionEnd); + ok(selectionStart == 0 && selectionEnd == 11, + "Text selection after WM_SETFOCUS is [%i, %i) expected [0, 11)\n", + selectionStart, selectionEnd); + + DestroyWindow(hDlg); + } }
static void test_GetDlgItemText(void) diff --git a/dlls/user32/tests/resource.rc b/dlls/user32/tests/resource.rc index be47038..fdef5a9 100644 --- a/dlls/user32/tests/resource.rc +++ b/dlls/user32/tests/resource.rc @@ -107,6 +107,14 @@ FONT 8, "MS Shell Dlg" LTEXT "Hello world", 200,4,4,50,14 }
+FOCUS_TEST_DIALOG_3 DIALOG 0, 0, 60, 30 +STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "Test dialog" +FONT 8, "MS Shell Dlg" +{ + EDITTEXT 200,4,4,50,14 +} + IDD_DIALOG DIALOG 0, 0, 186, 95 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Dialog"