From 31b36a3299068263b9ea48b909311629bd0702fb Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Fri, 4 Apr 2008 00:08:54 -0700 Subject: [PATCH] user32: on VK_RETURN, send WM_COMMAND to ancestor, not parent. --- dlls/user32/edit.c | 20 +++++++------- dlls/user32/tests/edit.c | 53 +++++++++++++++++++++++++++++++++++++++++ dlls/user32/tests/resource.rc | 17 +++++++++++++ 3 files changed, 80 insertions(+), 10 deletions(-) diff --git a/dlls/user32/edit.c b/dlls/user32/edit.c index e6d2530..5b72709 100644 --- a/dlls/user32/edit.c +++ b/dlls/user32/edit.c @@ -4597,16 +4597,16 @@ static LRESULT EDIT_WM_KeyDown(EDITSTATE *es, INT key) /* If the edit doesn't want the return send a message to the default object */ if(!(es->style & ES_WANTRETURN)) { - HWND hwndParent = GetParent(es->hwndSelf); - DWORD dw = SendMessageW( hwndParent, DM_GETDEFID, 0, 0 ); - if (HIWORD(dw) == DC_HASDEFID) - { - SendMessageW( hwndParent, WM_COMMAND, - MAKEWPARAM( LOWORD(dw), BN_CLICKED ), - (LPARAM)GetDlgItem( hwndParent, LOWORD(dw) ) ); - } - else - SendMessageW( hwndParent, WM_COMMAND, IDOK, (LPARAM)GetDlgItem( hwndParent, IDOK ) ); + HWND hwndAncestor = GetAncestor(es->hwndSelf, GA_ROOT); + DWORD dw = SendMessageW( hwndAncestor, DM_GETDEFID, 0, 0 ); + if (HIWORD(dw) == DC_HASDEFID) + { + SendMessageW( hwndAncestor, WM_COMMAND, + MAKEWPARAM( LOWORD(dw), BN_CLICKED ), + (LPARAM)GetDlgItem( hwndAncestor, LOWORD(dw) ) ); + } + else + SendMessageW( hwndAncestor, WM_COMMAND, IDOK, (LPARAM)GetDlgItem( hwndAncestor, IDOK ) ); } break; } diff --git a/dlls/user32/tests/edit.c b/dlls/user32/tests/edit.c index 0e9487d..3a97375 100644 --- a/dlls/user32/tests/edit.c +++ b/dlls/user32/tests/edit.c @@ -289,6 +289,50 @@ static HWND hwndET2; static const char szEditTest2Class[] = "EditTest2Class"; static const char szEditTest3Class[] = "EditTest3Class"; static const char szEditTextPositionClass[] = "EditTextPositionWindowClass"; +static int num_child_commands = 0; + +static INT_PTR CALLBACK edit_child_dialog_proc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam) +{ + if (msg == WM_COMMAND) + num_child_commands++; + return FALSE; +} + +static INT_PTR CALLBACK edit_parent_dialog_proc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam) +{ + static HWND hchild; + static int num_parent_commands = 0; + switch (msg) + { + case WM_INITDIALOG: + { + /* This is what NSIS does */ + hchild = CreateDialogParam(hinst, "EDIT_CHILD_DIALOG", hdlg, edit_child_dialog_proc, 0); + SetFocus(GetDlgItem(hchild, 1000)); + PostMessage(GetDlgItem(hchild, 1000), WM_KEYDOWN, VK_RETURN, 0x1c0001); + PostMessage(hdlg, WM_USER, 0xdeadbeef, 0); + break; + } + + case WM_COMMAND: + num_parent_commands++; + /* Check and make sure we got the right number of WM_COMMANDs */ + if ((wparam == IDOK) && (num_parent_commands == 1) && (num_child_commands == 2)) + EndDialog(hdlg, 11); + else + EndDialog(hdlg, 22); + break; + + case WM_USER: + EndDialog(hdlg, 33); + break; + + default: + break; + } + + return FALSE; +} static HWND create_editcontrol (DWORD style, DWORD exstyle) { @@ -1455,6 +1499,14 @@ static void test_multi_edit_dialog(void) ok(11 == r, "Expected %d, got %d\n", 11, r); } +static void test_child_edit_dialog(void) +{ + int r; + + r = DialogBox(hinst, "EDIT_PARENT_DIALOG", NULL, (DLGPROC)edit_parent_dialog_proc); + ok(11 == r, "Expected %d, got %d\n", 11, r); +} + static BOOL RegisterWindowClasses (void) { WNDCLASSA test2; @@ -1525,6 +1577,7 @@ START_TEST(edit) test_undo(); test_edit_dialog(); test_multi_edit_dialog(); + test_child_edit_dialog(); UnregisterWindowClasses(); } diff --git a/dlls/user32/tests/resource.rc b/dlls/user32/tests/resource.rc index 80abf08..4691bee 100644 --- a/dlls/user32/tests/resource.rc +++ b/dlls/user32/tests/resource.rc @@ -98,6 +98,23 @@ BEGIN PUSHBUTTON "Cancel",IDCANCEL,129,24,50,14 END +EDIT_PARENT_DIALOG DIALOG DISCARDABLE 0, 0, 200, 100 +STYLE DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "EDIT_PARENT" +FONT 8, "MS Shell Dlg" +{ + DEFPUSHBUTTON "OK",IDOK,129,7,50,14 + PUSHBUTTON "Cancel",IDCANCEL,129,24,50,14 + CONTROL "",1001,"Static",WS_GROUP,7,6,60,14 +} + +EDIT_CHILD_DIALOG DIALOG DISCARDABLE 0, 0, 80, 30 +STYLE DS_CONTROL | WS_CHILD +FONT 8, "MS Shell Dlg" +{ + EDITTEXT 1000, 5, 5, 60, 14, ES_AUTOHSCROLL +} + MULTI_EDIT_DIALOG DIALOG DISCARDABLE 0, 0, 160, 75 STYLE WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | DS_CENTER CAPTION "Multiple Edit Test" -- 1.5.2.2