Lei Zhang : riched20: Move EM_EXSETSEL fix into ME_SetSelection.

Alexandre Julliard julliard at wine.codeweavers.com
Tue Dec 5 04:51:09 CST 2006


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

Author: Lei Zhang <thestig at google.com>
Date:   Mon Dec  4 11:54:24 2006 -0800

riched20: Move EM_EXSETSEL fix into ME_SetSelection.

---

 dlls/riched20/caret.c  |   80 ++++++++++++++++++++++++++++++++++++------------
 dlls/riched20/editor.c |   59 ++---------------------------------
 dlls/riched20/editor.h |    2 +-
 3 files changed, 64 insertions(+), 77 deletions(-)

diff --git a/dlls/riched20/caret.c b/dlls/riched20/caret.c
index ce3abb7..a58d9f0 100644
--- a/dlls/riched20/caret.c
+++ b/dlls/riched20/caret.c
@@ -78,41 +78,81 @@ int ME_GetTextLengthEx(ME_TextEditor *ed
 }
 
 
-void ME_SetSelection(ME_TextEditor *editor, int from, int to)
+int ME_SetSelection(ME_TextEditor *editor, int from, int to)
 {
+  int selectionEnd = 0;
+  const int len = ME_GetTextLength(editor);
+
+  /* all negative values are effectively the same */
+  if (from < 0)
+    from = -1;
+  if (to < 0)
+    to = -1;
+
+  /* select all */
   if (from == 0 && to == -1)
   {
-    editor->pCursors[1].pRun = ME_FindItemFwd(editor->pBuffer->pFirst, diRun); 
+    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; 
+    editor->pCursors[0].nOffset = 0;
     ME_InvalidateSelection(editor);
     ME_ClearTempStyle(editor);
-    return;
+    return len + 1;
   }
-  if (from == -1 && to == -1)	/*-1,-1 means put the selection at the end of the text */
+
+  /* if both values are equal and also out of bound, that means to */
+  /* put the selection at the end of the text */
+  if ((from == to) && (to < 0 || to > len))
   {
-    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;
+    selectionEnd = 1;
   }
-  if (from == -1)
+  else
   {
-    editor->pCursors[1] = editor->pCursors[0]; 
-    ME_Repaint(editor);
-    ME_ClearTempStyle(editor);
-    return;
+    /* if from is negative and to is positive then selection is */
+    /* deselected and caret moved to end of the current selection */
+    if (from < 0)
+    {
+      int start, end;
+      ME_GetSelection(editor, &start, &end);
+      editor->pCursors[1] = editor->pCursors[0];
+      ME_Repaint(editor);
+      ME_ClearTempStyle(editor);
+      return end;
+    }
+
+    /* adjust to if it's a negative value */
+    if (to < 0)
+      to = len + 1;
+
+    /* flip from and to if they are reversed */
+    if (from>to)
+    {
+      int tmp = from;
+      from = to;
+      to = tmp;
+    }
+
+    /* after fiddling with the values, we find from > len && to > len */
+    if (from > len)
+      selectionEnd = 1;
+    /* special case with to too big */
+    else if (to > len)
+      to = len + 1;
   }
-  if (from>to)
+
+  if (selectionEnd)
   {
-    int tmp = from;
-    from = to;
-    to = tmp;
+    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 len;
   }
+
   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, to, &editor->pCursors[0].pRun, &editor->pCursors[0].nOffset);
+  return to;
 }
 
 
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index 254bbb7..738a6fc 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -1615,70 +1615,17 @@ LRESULT WINAPI RichEditANSIWndProc(HWND
   }
   case EM_EXSETSEL:
   {
-    int start, end;
-    int swap;
+    int end;
     CHARRANGE range = *(CHARRANGE *)lParam;
 
     TRACE("EM_EXSETSEL (%d,%d)\n", range.cpMin, range.cpMax);
 
-    /* all negative values are effectively the same */
-    if (range.cpMin < 0)
-      range.cpMin = -1;
-    if (range.cpMax < 0)
-      range.cpMax = -1;
-
-    if (range.cpMin != range.cpMax)
-    {
-      /* if cpMin is negative and cpMax is positive 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
-      {
-        /* adjust cpMax if it's a negative value */
-        if (range.cpMax < 0)
-          range.cpMax = ME_GetTextLength(editor) + 1;
-
-        /* flip cpMin and cpMax if they are reversed */
-        if (range.cpMin > range.cpMax)
-        {
-          swap = range.cpMin;
-          range.cpMin = range.cpMax;
-          range.cpMax = swap;
-        }
-
-        /* special case with cpMin too big */
-        if (range.cpMin > ME_GetTextLength(editor))
-        {
-          range.cpMin = ME_GetTextLength(editor);
-          range.cpMax = ME_GetTextLength(editor);
-        }
-        /* special case with cpMax too big */
-        else if (range.cpMax > ME_GetTextLength(editor))
-          range.cpMax = ME_GetTextLength(editor) + 1;
-      }
-    }
-    else
-    {
-      /* special case with cpMin == cpMax */
-      /* make sure both values are within bounds */
-      if (range.cpMax < 0 || range.cpMax > ME_GetTextLength(editor))
-      {
-        range.cpMin = ME_GetTextLength(editor);
-        range.cpMax = range.cpMin;
-      }
-    }
-
     ME_InvalidateSelection(editor);
-    ME_SetSelection(editor, range.cpMin, range.cpMax);
+    end = ME_SetSelection(editor, range.cpMin, range.cpMax);
     ME_InvalidateSelection(editor);
     ME_SendSelChange(editor);
 
-    return range.cpMax;
+    return end;
   }
   case EM_SHOWSCROLLBAR:
   {
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index 87742c5..ec56e3f 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -178,7 +178,7 @@ void ME_GetDefaultCharFormat(ME_TextEdit
 void ME_SetDefaultCharFormat(ME_TextEditor *editor, CHARFORMAT2W *mod);
 
 /* caret.c */
-void ME_SetSelection(ME_TextEditor *editor, int from, int to);
+int ME_SetSelection(ME_TextEditor *editor, int from, int to);
 void ME_SelectWord(ME_TextEditor *editor);
 void ME_HideCaret(ME_TextEditor *ed);
 void ME_ShowCaret(ME_TextEditor *ed);




More information about the wine-cvs mailing list