riched20: fixes and additional conformance tests for EM_EXSETSEL

Matt Finnicum mattfinn at gmail.com
Sun Dec 3 20:53:45 CST 2006


Hey,
I'm sorry for not noticing this bug earlier - I have a bad habit of
only browsing bugs listed under wine-richedit. I actually sent in a
patch that fixes this bug before, but it wasn't accepted because I
hadn't marked a test that it causes to fail as todo_wine. Does the
attached patch solve your problem?

The attached patch moves all the logic to ME_SetSelection, so it'll
apply to EM_SETSEL as well as EM_EXSETSEL (they both are supposed to
follow the same special cases), and this way it will contribute to my
further separating functionality from the message handlers into ME_
local functions which is needed to properly implement windowless
controls.

This patch does result in a wrong return if the user sent a
SetSelection beyond the end of the document (windows allows you to
select an imaginary character at the end), but I don't think that's a
problem for anything, and I'll have it working in a couple weeks (I'm
working on improving the selection code in general, a part of which
will allow you to actually select that extra character in our
richedit). I suppose i could just put a small hack in for the
meantime, if anyone cares.

I haven't tried them together yet, but your new tests do look
significantly more comprehensive - well done.

--Matt

On 12/3/06, Lei Zhang <thestig at google.com> wrote:
> Hi,
>
> Changelog:
> * Check the input to EM_EXSETSEL
> * Fixes bug 6814
> * Added more comprehensive conformance tests for EM_EXSETSEL
>
>  editor.c       |   52 +++++++++++++++++++++---
>  tests/editor.c |  103 +++++++++++++++++++++++++++++++------------------
>  2 files changed, 112 insertions(+), 43 deletions(-)
>
>
>
>
>
>
>
-------------- next part --------------
From fda32ff4aa4e9b5f6ace07d0f7ad8115cdde2360 Mon Sep 17 00:00:00 2001
From: Matt Finnicum <MattFinn at gmail.com>
Date: Sun, 3 Dec 2006 20:47:27 -0600
Subject: [PATCH] riched20: move some selection code from message handler to ME_SetSelection

---
 dlls/riched20/caret.c        |   51 ++++++++++++++++++++++++++---------------
 dlls/riched20/editor.c       |   32 ++-----------------------
 dlls/riched20/tests/editor.c |    6 ++++-
 3 files changed, 40 insertions(+), 49 deletions(-)

diff --git a/dlls/riched20/caret.c b/dlls/riched20/caret.c
index ce3abb7..4709cfc 100644
--- a/dlls/riched20/caret.c
+++ b/dlls/riched20/caret.c
@@ -80,39 +80,52 @@ int ME_GetTextLengthEx(ME_TextEditor *ed
 
 void ME_SetSelection(ME_TextEditor *editor, int from, int to)
 {
-  if (from == 0 && to == -1)
+  int tmp;
+  ME_InvalidateSelection(editor);
+  
+  to = max(-1, to);
+  to = min(ME_GetTextLength(editor) +1, to);
+  
+  from = max(-1, from);
+  from = min(ME_GetTextLength(editor) +1, from);
+  
+  if (from == -1 && to == -1)
   {
+    /* deselect and move caret to end of control */
+    editor->pCursors[1].pRun = editor->pCursors[0].pRun = ME_FindItemBack(editor->pBuffer->pLast, diRun); 
+    editor->pCursors[1].nOffset = editor->pCursors[0].nOffset = 0; 
+    ME_ClearTempStyle(editor);
+  }
+  else if (from == 0 && to == -1)
+  {
+    /* Select all of the text */
     editor->pCursors[1].pRun = ME_FindItemFwd(editor->pBuffer->pFirst, diRun); 
     editor->pCursors[1].nOffset = 0; 
     editor->pCursors[0].pRun = ME_FindItemBack(editor->pBuffer->pLast, diRun); 
     editor->pCursors[0].nOffset = 0; 
-    ME_InvalidateSelection(editor);
-    ME_ClearTempStyle(editor);
-    return;
-  }
-  if (from == -1 && to == -1)	/*-1,-1 means put the selection at the end of the text */
-  {
-    editor->pCursors[1].pRun = editor->pCursors[0].pRun = ME_FindItemBack(editor->pBuffer->pLast, diRun);
-    editor->pCursors[1].nOffset = editor->pCursors[0].nOffset = 0;
-    ME_InvalidateSelection(editor);
     ME_ClearTempStyle(editor);
-    return;
   }
-  if (from == -1)
+  else if (from == -1)
   {
+    /* deselect and move caret to end of current selection */
     editor->pCursors[1] = editor->pCursors[0]; 
     ME_Repaint(editor);
     ME_ClearTempStyle(editor);
-    return;
   }
-  if (from>to)
+  else
   {
-    int tmp = from;
-    from = to;
-    to = tmp;
+    if (from>to)
+    {
+      tmp = from;
+      from = to;
+      to = tmp;
+    }
+    ME_RunOfsFromCharOfs(editor, from, &editor->pCursors[1].pRun, &editor->pCursors[1].nOffset);
+    ME_RunOfsFromCharOfs(editor, to, &editor->pCursors[0].pRun, &editor->pCursors[0].nOffset);
   }
-  ME_RunOfsFromCharOfs(editor, from, &editor->pCursors[1].pRun, &editor->pCursors[1].nOffset);
-  ME_RunOfsFromCharOfs(editor, to, &editor->pCursors[0].pRun, &editor->pCursors[0].nOffset);  
+  
+  ME_InvalidateSelection(editor);
+  ME_SendSelChange(editor);  
 }
 
 
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index a8fadc1..4d9a869 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -1588,10 +1588,7 @@ LRESULT WINAPI RichEditANSIWndProc(HWND
   }
   case EM_SETSEL:
   {
-    ME_InvalidateSelection(editor);
     ME_SetSelection(editor, wParam, lParam);
-    ME_InvalidateSelection(editor);
-    ME_SendSelChange(editor);
     return 0;
   }
   case EM_SETSCROLLPOS:
@@ -1617,33 +1614,10 @@ LRESULT WINAPI RichEditANSIWndProc(HWND
   {
     int start, end;
     CHARRANGE range = *(CHARRANGE *)lParam;
-
-    TRACE("EM_EXSETSEL (%d,%d)\n", range.cpMin, range.cpMax);
-
-    /* if cpMin < 0, then selection is deselected and caret moved to end of
-     * the current selection  */
-    if (range.cpMin < 0)
-    {
-        ME_GetSelection(editor, &start, &end);
-        range.cpMin = end;
-        range.cpMax = end;
-    }  
-    else if (range.cpMax > ME_GetTextLength(editor) +1)
-    {
-      range.cpMax = ME_GetTextLength(editor) + 1;
-    }
-
-    ME_InvalidateSelection(editor);
     ME_SetSelection(editor, range.cpMin, range.cpMax);
-    ME_InvalidateSelection(editor);
-    ME_SendSelChange(editor);
-    
-    return range.cpMax;
-  }
-  case EM_SHOWSCROLLBAR:
-  {
-    ShowScrollBar(editor->hWnd, wParam, lParam);
-    return 0;
+      
+    ME_GetSelection(editor, &start, &end);
+    return end;
   }
   case EM_SETTEXTEX:
   {
diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c
index da6390f..466916c 100644
--- a/dlls/riched20/tests/editor.c
+++ b/dlls/riched20/tests/editor.c
@@ -1330,7 +1330,11 @@ static void test_EM_EXSETSEL(void)
     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);
+    todo_wine
+    {
+      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 */
-- 
1.4.4.1



More information about the wine-devel mailing list