Lei Zhang : user32: Add edit control check to see if its in a dialog on WM_CHAR/VK_RETURN.

Alexandre Julliard julliard at winehq.org
Wed Apr 9 14:31:34 CDT 2008


Module: wine
Branch: master
Commit: f704d5c69991d59c70859c172e903318e68536c7
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=f704d5c69991d59c70859c172e903318e68536c7

Author: Lei Zhang <thestig at google.com>
Date:   Wed Apr  9 11:33:03 2008 -0700

user32: Add edit control check to see if its in a dialog on WM_CHAR/VK_RETURN.

---

 dlls/user32/edit.c       |   38 ++++++++++++++++++++++++++++++++++----
 dlls/user32/tests/edit.c |   12 +++++-------
 2 files changed, 39 insertions(+), 11 deletions(-)

diff --git a/dlls/user32/edit.c b/dlls/user32/edit.c
index 2159ab7..a074c17 100644
--- a/dlls/user32/edit.c
+++ b/dlls/user32/edit.c
@@ -863,7 +863,7 @@ static LRESULT WINAPI EditWndProc_common( HWND hwnd, UINT msg,
                 }
                 else
                 {
-                  if (charW == VK_TAB || charW == VK_RETURN)
+                  if (charW == VK_TAB)
                       break;
                 }
 		result = EDIT_WM_Char(es, charW);
@@ -3989,6 +3989,32 @@ static BOOL EDIT_EM_Undo(EDITSTATE *es)
 }
 
 
+/* Helper function for WM_CHAR
+ *
+ * According to an MSDN blog article titled "Just because you're a control
+ * doesn't mean that you're necessarily inside a dialog box," multiline edit
+ * controls without ES_WANTRETURN would attempt to detect whether it is inside
+ * a dialog box or not.
+ */
+static BOOL EDIT_IsInsideDialog(EDITSTATE *es)
+{
+    WND *pParent;
+    BOOL r = FALSE;
+
+    if (es->hwndParent)
+    {
+        pParent = WIN_GetPtr(es->hwndParent);
+        if (pParent && pParent != WND_OTHER_PROCESS && pParent != WND_DESKTOP)
+        {
+            if (pParent->flags & WIN_ISDIALOG)
+                r = TRUE;
+            WIN_ReleasePtr(pParent);
+        }
+    }
+    return r;
+}
+
+
 /*********************************************************************
  *
  *	WM_CHAR
@@ -4002,9 +4028,13 @@ static LRESULT EDIT_WM_Char(EDITSTATE *es, WCHAR c)
 
 	switch (c) {
 	case '\r':
-	    /* If the edit doesn't want the return and it's not a multiline edit, do nothing */
-	    if(!(es->style & ES_MULTILINE) && !(es->style & ES_WANTRETURN))
-		break;
+            /* If it's not a multiline edit box, it would be ignored below.
+             * For multiline edit without ES_WANTRETURN, we have to make a
+             * special case.
+             */
+            if ((es->style & ES_MULTILINE) && !(es->style & ES_WANTRETURN))
+                if (EDIT_IsInsideDialog(es))
+                    break;
 	case '\n':
 		if (es->style & ES_MULTILINE) {
 			if (es->style & ES_READONLY) {
diff --git a/dlls/user32/tests/edit.c b/dlls/user32/tests/edit.c
index 058d9fe..82c4ee0 100644
--- a/dlls/user32/tests/edit.c
+++ b/dlls/user32/tests/edit.c
@@ -1652,15 +1652,13 @@ static void test_enter(void)
     ok(TRUE == r, "Expected: %d, got: %d\n", TRUE, r);
 
     r = SendMessage(hwEdit, WM_CHAR, VK_RETURN, 0);
-    todo_wine ok(1 == r, "Expected: %d, got: %d\n", 1, r);
+    ok(1 == r, "Expected: %d, got: %d\n", 1, r);
 
     /* get text */
     buffer[0] = 0;
     r = SendMessage(hwEdit, WM_GETTEXT, 16, (LPARAM) buffer);
-    todo_wine {
     ok(2 == r, "Expected: %d, got len %d\n", 2, r);
     ok(0 == strcmp(buffer, "\r\n"), "expected \"\\r\\n\", got \"%s\"\n", buffer);
-    }
 
     DestroyWindow (hwEdit);
 
@@ -1674,7 +1672,7 @@ static void test_enter(void)
     ok(TRUE == r, "Expected: %d, got: %d\n", TRUE, r);
 
     r = SendMessage(hwEdit, WM_CHAR, VK_RETURN, 0);
-    todo_wine ok(1 == r, "Expected: %d, got: %d\n", 1, r);
+    ok(1 == r, "Expected: %d, got: %d\n", 1, r);
 
     /* get text */
     buffer[0] = 0;
@@ -1694,7 +1692,7 @@ static void test_enter(void)
     ok(TRUE == r, "Expected: %d, got: %d\n", TRUE, r);
 
     r = SendMessage(hwEdit, WM_CHAR, VK_RETURN, 0);
-    todo_wine ok(1 == r, "Expected: %d, got: %d\n", 1, r);
+    ok(1 == r, "Expected: %d, got: %d\n", 1, r);
 
     /* get text */
     buffer[0] = 0;
@@ -1844,7 +1842,7 @@ static void test_wantreturn_edit_dialog(void)
     r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_wantreturn_dialog_proc, 3);
     ok(444 == r, "Expected %d, got %d\n", 444, r);
     r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_wantreturn_dialog_proc, 4);
-    todo_wine ok(444 == r, "Expected %d, got %d\n", 444, r);
+    ok(444 == r, "Expected %d, got %d\n", 444, r);
     r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_wantreturn_dialog_proc, 5);
     ok(444 == r, "Expected %d, got %d\n", 444, r);
 
@@ -1852,7 +1850,7 @@ static void test_wantreturn_edit_dialog(void)
     r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_wantreturn_dialog_proc, 6);
     todo_wine ok(444 == r, "Expected %d, got %d\n", 444, r);
     r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_wantreturn_dialog_proc, 7);
-    todo_wine ok(444 == r, "Expected %d, got %d\n", 444, r);
+    ok(444 == r, "Expected %d, got %d\n", 444, r);
     r = DialogBoxParam(hinst, "EDIT_WANTRETURN_DIALOG", NULL, (DLGPROC)edit_wantreturn_dialog_proc, 8);
     ok(444 == r, "Expected %d, got %d\n", 444, r);
 }




More information about the wine-cvs mailing list