Dylan Smith : richedit: Use ME_Cursor instead of offsets for ME_GetCharFormat.

Alexandre Julliard julliard at winehq.org
Wed Aug 12 11:10:41 CDT 2009


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

Author: Dylan Smith <dylan.ah.smith at gmail.com>
Date:   Wed Aug 12 09:06:09 2009 -0400

richedit: Use ME_Cursor instead of offsets for ME_GetCharFormat.

Prevent extra conversions from character offset to ME_Cursor.

---

 dlls/riched20/editor.c |   10 ++++++++--
 dlls/riched20/editor.h |    3 ++-
 dlls/riched20/run.c    |   33 +++++++++++++++++----------------
 3 files changed, 27 insertions(+), 19 deletions(-)

diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index fcfd3c4..6eab00c 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -4846,9 +4846,12 @@ static BOOL ME_UpdateLinkAttribute(ME_TextEditor *editor, int sel_min, int sel_m
 
     if (beforeURL[0] < beforeURL[1])
     {
+      ME_Cursor from, to;
+      ME_CursorFromCharOfs(editor, beforeURL[0], &from);
+      ME_CursorFromCharOfs(editor, beforeURL[1], &to);
       /* CFE_LINK effect should be consistently unset */
       link.cbSize = sizeof(link);
-      ME_GetCharFormat(editor, beforeURL[0], beforeURL[1], &link);
+      ME_GetCharFormat(editor, &from, &to, &link);
       if (!(link.dwMask & CFM_LINK) || (link.dwEffects & CFE_LINK))
       {
         /* CFE_LINK must be unset from this range */
@@ -4862,9 +4865,12 @@ static BOOL ME_UpdateLinkAttribute(ME_TextEditor *editor, int sel_min, int sel_m
     }
     if (inURL[0] < inURL[1])
     {
+      ME_Cursor from, to;
+      ME_CursorFromCharOfs(editor, inURL[0], &from);
+      ME_CursorFromCharOfs(editor, inURL[1], &to);
       /* CFE_LINK effect should be consistently set */
       link.cbSize = sizeof(link);
-      ME_GetCharFormat(editor, inURL[0], inURL[1], &link);
+      ME_GetCharFormat(editor, &from, &to, &link);
       if (!(link.dwMask & CFM_LINK) || !(link.dwEffects & CFE_LINK))
       {
         /* CFE_LINK must be set on this range */
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index 2d2e248..88bb4db 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -149,7 +149,8 @@ int ME_CharOfsFromRunOfs(ME_TextEditor *editor, const ME_DisplayItem *pPara, con
 void ME_SkipAndPropagateCharOffset(ME_DisplayItem *p, int shift);
 void ME_SetCharFormat(ME_TextEditor *editor, int nFrom, int nLen, CHARFORMAT2W *pFmt);
 void ME_SetSelectionCharFormat(ME_TextEditor *editor, CHARFORMAT2W *pFmt);
-void ME_GetCharFormat(ME_TextEditor *editor, int nFrom, int nLen, CHARFORMAT2W *pFmt);
+void ME_GetCharFormat(ME_TextEditor *editor, const ME_Cursor *from,
+                      const ME_Cursor *to, CHARFORMAT2W *pFmt);
 void ME_GetSelectionCharFormat(ME_TextEditor *editor, CHARFORMAT2W *pFmt);
 void ME_GetDefaultCharFormat(ME_TextEditor *editor, CHARFORMAT2W *pFmt);
 void ME_SetDefaultCharFormat(ME_TextEditor *editor, CHARFORMAT2W *mod);
diff --git a/dlls/riched20/run.c b/dlls/riched20/run.c
index dce419b..18b19f4 100644
--- a/dlls/riched20/run.c
+++ b/dlls/riched20/run.c
@@ -842,20 +842,20 @@ void ME_GetDefaultCharFormat(ME_TextEditor *editor, CHARFORMAT2W *pFmt)
 
 /******************************************************************************
  * ME_GetSelectionCharFormat
- * 
+ *
  * If selection exists, it returns all style elements that are set consistently
- * in the whole selection. If not, it just returns the current style.  
- */     
+ * in the whole selection. If not, it just returns the current style.
+ */
 void ME_GetSelectionCharFormat(ME_TextEditor *editor, CHARFORMAT2W *pFmt)
 {
-  int nFrom, nTo;
-  ME_GetSelectionOfs(editor, &nFrom, &nTo);
-  if (nFrom == nTo && editor->pBuffer->pCharStyle)
+  ME_Cursor *from, *to;
+  if (!ME_IsSelection(editor) && editor->pBuffer->pCharStyle)
   {
     ME_CopyCharFormat(pFmt, &editor->pBuffer->pCharStyle->fmt);
     return;
   }
-  ME_GetCharFormat(editor, nFrom, nTo, pFmt);
+  ME_GetSelection(editor, &from, &to);
+  ME_GetCharFormat(editor, from, to, pFmt);
 }
 
 /******************************************************************************
@@ -864,16 +864,17 @@ void ME_GetSelectionCharFormat(ME_TextEditor *editor, CHARFORMAT2W *pFmt)
  * Returns the style consisting of those attributes which are consistently set
  * in the whole character range.
  */
-void ME_GetCharFormat(ME_TextEditor *editor, int nFrom, int nTo, CHARFORMAT2W *pFmt)
+void ME_GetCharFormat(ME_TextEditor *editor, const ME_Cursor *from,
+                      const ME_Cursor *to, CHARFORMAT2W *pFmt)
 {
   ME_DisplayItem *run, *run_end;
-  int nOffset, nOffset2;
   CHARFORMAT2W tmp;
 
-  ME_RunOfsFromCharOfs(editor, nFrom, NULL, &run, &nOffset);
-  if (nFrom == nTo) /* special case - if selection is empty, take previous char's formatting */
+  run = from->pRun;
+  /* special case - if selection is empty, take previous char's formatting */
+  if (from->pRun == to->pRun && from->nOffset == to->nOffset)
   {
-    if (!nOffset)
+    if (!from->nOffset)
     {
       ME_DisplayItem *tmp_run = ME_FindItemBack(run, diRunOrParagraph);
       if (tmp_run->type == diRun) {
@@ -884,10 +885,10 @@ void ME_GetCharFormat(ME_TextEditor *editor, int nFrom, int nTo, CHARFORMAT2W *p
     ME_GetRunCharFormat(editor, run, pFmt);
     return;
   }
-  
-  if (nTo>nFrom) /* selection consists of chars from nFrom up to nTo-1 */
-    nTo--;
-  ME_RunOfsFromCharOfs(editor, nTo, NULL, &run_end, &nOffset2);
+
+  run_end = to->pRun;
+  if (!to->nOffset)
+    run_end = ME_FindItemBack(run_end, diRun);
 
   ME_GetRunCharFormat(editor, run, pFmt);
 




More information about the wine-cvs mailing list