riched20: add EM_EXSETSEL conformance tests and fixes bug 4462 (revised)

Brian Chang brianch at seas.ucla.edu
Fri Mar 17 02:58:59 CST 2006


This is the first revision to the patch that addresses issues in following threads:
http://www.winehq.org/pipermail/wine-devel/2006-March/045625.html
http://www.winehq.org/pipermail/wine-devel/2006-March/045628.html

changelog:
Fix addresses bug 4462 found at: http://bugs.winehq.org/show_bug.cgi?id=4462
Also adds conformance tests for EM_EXSETSEL that reproduces bug behavior

Tested with FileZilla with patch and seems to work fine


 editor.c       |   29 +++++++++++++++++++++++++----
 tests/editor.c |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 77 insertions(+), 4 deletions(-)

Index: dlls/riched20/editor.c
===================================================================
RCS file: /home/wine/wine/dlls/riched20/editor.c,v
retrieving revision 1.103
diff -a -u -r1.103 editor.c
--- dlls/riched20/editor.c	2 Mar 2006 17:12:37 -0000	1.103
+++ dlls/riched20/editor.c	17 Mar 2006 08:42:59 -0000
@@ -1460,13 +1460,34 @@
   }
   case EM_EXSETSEL:
   {
-    CHARRANGE *pRange = (CHARRANGE *)lParam;
-    TRACE("EM_EXSETSEL (%ld,%ld)\n", pRange->cpMin, pRange->cpMax);
+    int start, end, textlen;
+    CHARRANGE range = *(CHARRANGE *)lParam;
+
+    TRACE("EM_EXSETSEL (%ld,%ld)\n", range.cpMin, range.cpMax);
+
+    /* get the current selection and text length */
+    ME_GetSelection(editor, &start, &end);
+    textlen = ME_GetTextLength(editor);
+
+    /* if cpMin < 0, then selection is deselected and caret moved to end of
+     * the current selection
+     */
+    if (range.cpMin < 0)
+    {
+        range.cpMin = end;
+        range.cpMax = end;
+    }  
+    else if (range.cpMax > textlen +1)
+    {
+        range.cpMax = textlen + 1;
+    }
+
     ME_InvalidateSelection(editor);
-    ME_SetSelection(editor, pRange->cpMin, pRange->cpMax);
+    ME_SetSelection(editor, range.cpMin, range.cpMax);
     ME_InvalidateSelection(editor);
     ME_SendSelChange(editor);
-    return 0;
+    
+    return range.cpMax;
   }
   case EM_SETTEXTEX:
   {
Index: dlls/riched20/tests/editor.c
===================================================================
RCS file: /home/wine/wine/dlls/riched20/tests/editor.c,v
retrieving revision 1.11
diff -a -u -r1.11 editor.c
--- dlls/riched20/tests/editor.c	2 Mar 2006 17:12:37 -0000	1.11
+++ dlls/riched20/tests/editor.c	17 Mar 2006 08:42:59 -0000
@@ -744,6 +744,57 @@
   DestroyWindow(hwndRichEdit);
 }
 
+static void test_EM_EXSETSEL()
+{
+    HWND hwndRichEdit = new_richedit(NULL);
+    long result;
+    CHARRANGE cr;
+    int start,end;
+
+    /* sending some text to the window */
+    SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) "testing selection");
+    /*                                                 01234567890123456*/
+    /*                                                          10      */
+
+    /* EM_EXSETSEL returns (cr.cpMax < strlen+1 ? cr.cpMax:strlen+1 if cpMin is positive */
+    cr.cpMin = 0;
+    cr.cpMax = 100;
+    result = SendMessage(hwndRichEdit, EM_EXSETSEL, 0, (LPARAM) &cr);
+    ok(result == 18, "EM_EXSETSEL: expected: 18 actual: %ld\n", result);
+    SendMessage(hwndRichEdit, EM_GETSEL, (WPARAM) &start, (LPARAM) &end);
+
+    /* FIXME: EM_GETSEL needs to return proper ending value */
+    todo_wine
+    {
+        ok(start == 0 && end == 18, "EM_EXSETSEL: expected (0,18) actual:(%d,%d)\n", start,end);
+    }
+
+    cr.cpMin = 5;
+    cr.cpMax = 10;
+    result = SendMessage(hwndRichEdit, EM_EXSETSEL, 0, (LPARAM) &cr);
+    ok(result == 10, "EM_EXSETSEL: expected: 10 actual: %ld\n", result);
+    SendMessage(hwndRichEdit, EM_GETSEL, (WPARAM) &start, (LPARAM) &end);
+    ok(start == 5 && end == 10, "EM_EXSETSEL: expected (5,10) actual:(%d,%d)\n", start,end);
+
+    cr.cpMin = 15;
+    cr.cpMax = 17;
+    result = SendMessage(hwndRichEdit, EM_EXSETSEL, 0, (LPARAM) &cr);
+    ok(result == 17, "EM_EXSETSEL: expected: 17 actual: %ld\n", result);
+    SendMessage(hwndRichEdit, EM_GETSEL, (WPARAM) &start, (LPARAM) &end);
+    ok(start == 15 && end == 17, "EM_EXSETSEL: expected (15,17) actual:(%d,%d)\n", start,end);
+
+    /* bug 4462 - the following values get used in FileZilla */
+    /* when min < 0, selection is deselected and caret is moved to end of last selection */
+    cr.cpMin = -3;
+    cr.cpMax = 0;
+    result = SendMessage(hwndRichEdit, EM_EXSETSEL, 0, (LPARAM) &cr);
+    ok(result == 17, "EM_EXSETSEL: expected: 17 actual: %ld\n", result);
+    SendMessage(hwndRichEdit, EM_GETSEL, (WPARAM) &start, (LPARAM) &end);
+    ok(start == 17 && end == 17, "EM_EXSETSEL: expected (17,17) actual:(%d,%d)\n", start,end);
+
+    DestroyWindow(hwndRichEdit);
+}
+
 START_TEST( editor )
 {
   MSG msg;
@@ -761,6 +812,7 @@
   test_EM_SETOPTIONS();
   test_WM_GETTEXT();
   test_EM_AUTOURLDETECT();
+  test_EM_EXSETSEL();
 
   /* Set the environment variable WINETEST_RICHED20 to keep windows
    * responsive and open for 30 seconds. This is useful for debugging.



More information about the wine-patches mailing list