Dylan Smith : richedit: Use ME_Cursor as parameter to ME_SplitRunSimple.

Alexandre Julliard julliard at winehq.org
Fri Jul 30 10:24:12 CDT 2010


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

Author: Dylan Smith <dylan.ah.smith at gmail.com>
Date:   Thu Jul 29 14:07:40 2010 -0400

richedit: Use ME_Cursor as parameter to ME_SplitRunSimple.

The paragraph needed to be included in the parameters to avoid needing
traverse the linked list of display items to find the paragraph.

---

 dlls/riched20/caret.c  |    6 +--
 dlls/riched20/editor.h |    2 +-
 dlls/riched20/run.c    |   81 ++++++++++++++++++++---------------------------
 dlls/riched20/table.c  |    6 +--
 dlls/riched20/undo.c   |    2 +-
 5 files changed, 41 insertions(+), 56 deletions(-)

diff --git a/dlls/riched20/caret.c b/dlls/riched20/caret.c
index 5750db9..536b89a 100644
--- a/dlls/riched20/caret.c
+++ b/dlls/riched20/caret.c
@@ -579,10 +579,8 @@ void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor,
         }
 
         p = &editor->pCursors[nCursor];
-        if (p->nOffset) {
-          ME_SplitRunSimple(editor, p->pRun, p->nOffset);
-          p = &editor->pCursors[nCursor];
-        }
+        if (p->nOffset)
+          ME_SplitRunSimple(editor, p);
         tmp_style = ME_GetInsertStyle(editor, nCursor);
         /* ME_SplitParagraph increases style refcount */
         tp = ME_SplitParagraph(editor, p->pRun, p->pRun->member.run.style, eol_str, 0);
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index 10a1f2c..f85ec2e 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -137,7 +137,7 @@ int ME_PointFromChar(ME_TextEditor *editor, ME_Run *pRun, int nOffset);
 int ME_CanJoinRuns(const ME_Run *run1, const ME_Run *run2);
 void ME_JoinRuns(ME_TextEditor *editor, ME_DisplayItem *p);
 ME_DisplayItem *ME_SplitRun(ME_WrapContext *wc, ME_DisplayItem *item, int nChar);
-ME_DisplayItem *ME_SplitRunSimple(ME_TextEditor *editor, ME_DisplayItem *item, int nChar);
+ME_DisplayItem *ME_SplitRunSimple(ME_TextEditor *editor, ME_Cursor *cursor);
 void ME_UpdateRunFlags(ME_TextEditor *editor, ME_Run *run);
 void ME_CalcRunExtent(ME_Context *c, const ME_Paragraph *para, int startx, ME_Run *run);
 SIZE ME_GetRunSize(ME_Context *c, const ME_Paragraph *para, ME_Run *run, int nLen, int startx);
diff --git a/dlls/riched20/run.c b/dlls/riched20/run.c
index cd282ec..09cad59 100644
--- a/dlls/riched20/run.c
+++ b/dlls/riched20/run.c
@@ -251,9 +251,9 @@ void ME_JoinRuns(ME_TextEditor *editor, ME_DisplayItem *p)
 ME_DisplayItem *ME_SplitRun(ME_WrapContext *wc, ME_DisplayItem *item, int nVChar)
 {
   ME_TextEditor *editor = wc->context->editor;
-  ME_DisplayItem *item2 = NULL;
   ME_Run *run, *run2;
-  ME_Paragraph *para = &ME_GetParagraph(item)->member.para;
+  ME_Paragraph *para = &wc->pPara->member.para;
+  ME_Cursor cursor = {wc->pPara, item, nVChar};
 
   assert(item->member.run.nCharOfs != -1);
   if(TRACE_ON(richedit))
@@ -268,9 +268,9 @@ ME_DisplayItem *ME_SplitRun(ME_WrapContext *wc, ME_DisplayItem *item, int nVChar
   TRACE("Before split: %s(%d, %d)\n", debugstr_w(run->strText->szData),
         run->pt.x, run->pt.y);
 
-  item2 = ME_SplitRunSimple(editor, item, nVChar);
+  ME_SplitRunSimple(editor, &cursor);
 
-  run2 = &item2->member.run;
+  run2 = &cursor.pRun->member.run;
 
   ME_CalcRunExtent(wc->context, para, wc->nRow ? wc->nLeftMargin : wc->nFirstMargin, run);
   ME_CalcRunExtent(wc->context, para, wc->nRow ? wc->nLeftMargin : wc->nFirstMargin, run2);
@@ -288,46 +288,45 @@ ME_DisplayItem *ME_SplitRun(ME_WrapContext *wc, ME_DisplayItem *item, int nVChar
       debugstr_w(run2->strText->szData), run2->pt.x, run2->pt.y);
   }
 
-  return item2;
+  return cursor.pRun;
 }
 
 /******************************************************************************
  * ME_SplitRunSimple
- * 
+ *
  * Does the most basic job of splitting a run into two - it does not
- * update the positions and extents.    
- */    
-ME_DisplayItem *ME_SplitRunSimple(ME_TextEditor *editor, ME_DisplayItem *item, int nVChar)
+ * update the positions and extents.
+ */
+ME_DisplayItem *ME_SplitRunSimple(ME_TextEditor *editor, ME_Cursor *cursor)
 {
-  ME_Run *run = &item->member.run;
-  ME_DisplayItem *item2;
-  ME_Run *run2;
+  ME_DisplayItem *run = cursor->pRun;
+  ME_DisplayItem *new_run;
   int i;
-  assert(nVChar > 0 && nVChar < run->strText->nLen);
-  assert(item->type == diRun);
-  assert(!(item->member.run.nFlags & MERF_NONTEXT));
-  assert(item->member.run.nCharOfs != -1);
+  int nOffset = cursor->nOffset;
 
-  item2 = ME_MakeRun(run->style,
-      ME_VSplitString(run->strText, nVChar), run->nFlags&MERF_SPLITMASK);
+  assert(!(run->member.run.nFlags & MERF_NONTEXT));
 
-  item2->member.run.nCharOfs = item->member.run.nCharOfs + nVChar;
+  new_run = ME_MakeRun(run->member.run.style,
+                       ME_VSplitString(run->member.run.strText, nOffset),
+                       run->member.run.nFlags & MERF_SPLITMASK);
 
-  run2 = &item2->member.run;
-  ME_InsertBefore(item->next, item2);
+  new_run->member.run.nCharOfs = run->member.run.nCharOfs + nOffset;
+  cursor->pRun = new_run;
+  cursor->nOffset = 0;
 
-  ME_UpdateRunFlags(editor, run);
-  ME_UpdateRunFlags(editor, run2);
-  for (i=0; i<editor->nCursors; i++) {
-    if (editor->pCursors[i].pRun == item &&
-        editor->pCursors[i].nOffset >= nVChar) {
-      assert(item2->type == diRun);
-      editor->pCursors[i].pRun = item2;
-      editor->pCursors[i].nOffset -= nVChar;
+  ME_InsertBefore(run->next, new_run);
+
+  ME_UpdateRunFlags(editor, &run->member.run);
+  ME_UpdateRunFlags(editor, &new_run->member.run);
+  for (i = 0; i < editor->nCursors; i++) {
+    if (editor->pCursors[i].pRun == run &&
+        editor->pCursors[i].nOffset >= nOffset) {
+      editor->pCursors[i].pRun = new_run;
+      editor->pCursors[i].nOffset -= nOffset;
     }
   }
-  ME_GetParagraph(item)->member.para.nFlags |= MEPF_REWRAP;
-  return item2;
+  cursor->pPara->member.para.nFlags |= MEPF_REWRAP;
+  return run;
 }
 
 /******************************************************************************
@@ -361,12 +360,8 @@ ME_InsertRunAtCursor(ME_TextEditor *editor, ME_Cursor *cursor, ME_Style *style,
   ME_DisplayItem *pDI;
   ME_UndoItem *pUI;
 
-  if (cursor->nOffset) {
-  	/* We're inserting at the middle of the existing run, which means that
-		 * that run must be split. It isn't always necessary, but */
-    cursor->pRun = ME_SplitRunSimple(editor, cursor->pRun, cursor->nOffset);
-    cursor->nOffset = 0;
-  }
+  if (cursor->nOffset)
+    ME_SplitRunSimple(editor, cursor);
 
   pUI = ME_AddUndoItem(editor, diUndoDeleteRun, NULL);
   if (pUI) {
@@ -756,10 +751,8 @@ void ME_SetCharFormat(ME_TextEditor *editor, ME_Cursor *start, ME_Cursor *end, C
   {
     /* SplitRunSimple may or may not update the cursors, depending on whether they
      * are selection cursors, but we need to make sure they are valid. */
-    ME_DisplayItem *split_run = start->pRun;
     int split_offset = start->nOffset;
-    start->pRun = ME_SplitRunSimple(editor, split_run, split_offset);
-    start->nOffset = 0;
+    ME_DisplayItem *split_run = ME_SplitRunSimple(editor, start);
     if (end && end->pRun == split_run)
     {
       end->pRun = start->pRun;
@@ -768,12 +761,8 @@ void ME_SetCharFormat(ME_TextEditor *editor, ME_Cursor *start, ME_Cursor *end, C
   }
 
   if (end && end->nOffset)
-  {
-    end_run = end->pRun = ME_SplitRunSimple(editor, end->pRun, end->nOffset);
-    end->nOffset = 0;
-  } else if (end) {
-    end_run = end->pRun;
-  }
+    ME_SplitRunSimple(editor, end);
+  end_run = end ? end->pRun : NULL;
 
   run = start->pRun;
   para = start->pPara;
diff --git a/dlls/riched20/table.c b/dlls/riched20/table.c
index cbfa2b3..f184ff0 100644
--- a/dlls/riched20/table.c
+++ b/dlls/riched20/table.c
@@ -64,10 +64,8 @@ static ME_DisplayItem* ME_InsertEndParaFromCursor(ME_TextEditor *editor,
   ME_Style *pStyle = ME_GetInsertStyle(editor, nCursor);
   ME_DisplayItem *tp;
   ME_Cursor* cursor = &editor->pCursors[nCursor];
-  if (cursor->nOffset) {
-    ME_SplitRunSimple(editor, cursor->pRun, cursor->nOffset);
-    cursor = &editor->pCursors[nCursor];
-  }
+  if (cursor->nOffset)
+    ME_SplitRunSimple(editor, cursor);
 
   tp = ME_SplitParagraph(editor, cursor->pRun, pStyle, eol_str, paraFlags);
   ME_ReleaseStyle(pStyle);
diff --git a/dlls/riched20/undo.c b/dlls/riched20/undo.c
index be7f0e1..9f43f0a 100644
--- a/dlls/riched20/undo.c
+++ b/dlls/riched20/undo.c
@@ -336,7 +336,7 @@ static void ME_PlayUndoItem(ME_TextEditor *editor, ME_DisplayItem *pItem)
     int paraFlags = pItem->member.para.nFlags & (MEPF_ROWSTART|MEPF_CELL|MEPF_ROWEND);
     ME_CursorFromCharOfs(editor, pUItem->nStart, &tmp);
     if (tmp.nOffset)
-      tmp.pRun = ME_SplitRunSimple(editor, tmp.pRun, tmp.nOffset);
+      ME_SplitRunSimple(editor, &tmp);
     assert(pUItem->eol_str);
     this_para = tmp.pPara;
     bFixRowStart = this_para->member.para.nFlags & MEPF_ROWSTART;




More information about the wine-cvs mailing list