Huw Davies : riched20: Pass a cursor ptr to the insert style retrieval function.

Alexandre Julliard julliard at winehq.org
Wed Oct 21 15:15:14 CDT 2020


Module: wine
Branch: master
Commit: 75433bc39be8d71dbd8ed45e9578a40f965ef6c0
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=75433bc39be8d71dbd8ed45e9578a40f965ef6c0

Author: Huw Davies <huw at codeweavers.com>
Date:   Wed Oct 21 10:05:54 2020 +0100

riched20: Pass a cursor ptr to the insert style retrieval function.

Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/riched20/caret.c   |  6 +++---
 dlls/riched20/editor.c  |  6 +++---
 dlls/riched20/editor.h  |  2 +-
 dlls/riched20/richole.c |  2 +-
 dlls/riched20/run.c     |  2 +-
 dlls/riched20/style.c   | 44 ++++++++++++++------------------------------
 dlls/riched20/table.c   |  2 +-
 7 files changed, 24 insertions(+), 40 deletions(-)

diff --git a/dlls/riched20/caret.c b/dlls/riched20/caret.c
index 97cee3d9b3a..5d49d11bd3b 100644
--- a/dlls/riched20/caret.c
+++ b/dlls/riched20/caret.c
@@ -473,11 +473,11 @@ static struct re_object* create_re_object(const REOBJECT *reo)
 
 void ME_InsertOLEFromCursor(ME_TextEditor *editor, const REOBJECT* reo, int nCursor)
 {
-  ME_Style *style = ME_GetInsertStyle( editor, nCursor );
   ME_Run *run, *prev;
   const WCHAR space = ' ';
   struct re_object *reobj_prev = NULL;
   ME_Cursor *cursor = editor->pCursors + nCursor;
+  ME_Style *style = style_get_insert_style( editor, cursor );
 
   /* FIXME no no no */
   if (ME_IsSelection(editor))
@@ -508,9 +508,9 @@ void ME_InsertOLEFromCursor(ME_TextEditor *editor, const REOBJECT* reo, int nCur
 
 void ME_InsertEndRowFromCursor(ME_TextEditor *editor, int nCursor)
 {
-  ME_Style *style = ME_GetInsertStyle( editor, nCursor );
   const WCHAR space = ' ';
   ME_Cursor *cursor = editor->pCursors + nCursor;
+  ME_Style *style = style_get_insert_style( editor, cursor );
 
   /* FIXME no no no */
   if (ME_IsSelection(editor))
@@ -1510,7 +1510,7 @@ void ME_DeleteSelection(ME_TextEditor *editor)
 
 ME_Style *ME_GetSelectionInsertStyle(ME_TextEditor *editor)
 {
-  return ME_GetInsertStyle(editor, 0);
+    return style_get_insert_style( editor, editor->pCursors );
 }
 
 void ME_SendSelChange(ME_TextEditor *editor)
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index c91d47302cf..dfb066d5976 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -2596,7 +2596,7 @@ static BOOL handle_enter(ME_TextEditor *editor)
                 }
             }
 
-            style = ME_GetInsertStyle(editor, 0);
+            style = style_get_insert_style( editor, editor->pCursors );
 
             /* Normally the new eop style is the insert style, however in a list it is copied from the existing
             eop style (this prevents the list label style changing when the new eop is inserted).
@@ -2838,7 +2838,7 @@ static LRESULT ME_Char(ME_TextEditor *editor, WPARAM charCode,
     /* WM_CHAR is restricted to nTextLimit */
     if(editor->nTextLimit > ME_GetTextLength(editor) - (to-from))
     {
-      ME_Style *style = ME_GetInsertStyle(editor, 0);
+      ME_Style *style = style_get_insert_style( editor, editor->pCursors );
       ME_ContinueCoalescingTransaction(editor);
       ME_InsertTextFromCursor(editor, 0, &wstr, 1, style);
       ME_ReleaseStyle(style);
@@ -4818,7 +4818,7 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
   {
     HIMC hIMC;
 
-    ME_Style *style = ME_GetInsertStyle(editor, 0);
+    ME_Style *style = style_get_insert_style( editor, editor->pCursors );
     hIMC = ITextHost_TxImmGetContext(editor->texthost);
     ME_DeleteSelection(editor);
     ME_SaveTempStyle(editor, style);
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index 1f74a2eb8b4..a43a6c2c1ed 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -47,11 +47,11 @@ static inline const char *debugstr_run( const ME_Run *run )
 }
 
 /* style.c */
+ME_Style *style_get_insert_style( ME_TextEditor *editor, ME_Cursor *cursor ) DECLSPEC_HIDDEN;
 ME_Style *ME_MakeStyle(CHARFORMAT2W *style) DECLSPEC_HIDDEN;
 void ME_AddRefStyle(ME_Style *item) DECLSPEC_HIDDEN;
 void ME_DestroyStyle(ME_Style *item) DECLSPEC_HIDDEN;
 void ME_ReleaseStyle(ME_Style *item) DECLSPEC_HIDDEN;
-ME_Style *ME_GetInsertStyle(ME_TextEditor *editor, int nCursor) DECLSPEC_HIDDEN;
 ME_Style *ME_ApplyStyle(ME_TextEditor *ed, ME_Style *sSrc, CHARFORMAT2W *style) DECLSPEC_HIDDEN;
 void select_style(ME_Context *c, ME_Style *s) DECLSPEC_HIDDEN;
 void ME_InitCharFormat2W(CHARFORMAT2W *pFmt) DECLSPEC_HIDDEN;
diff --git a/dlls/riched20/richole.c b/dlls/riched20/richole.c
index 21e92e95cd1..2f2e5e09d1f 100644
--- a/dlls/riched20/richole.c
+++ b/dlls/riched20/richole.c
@@ -1697,7 +1697,7 @@ static HRESULT WINAPI ITextRange_fnSetText(ITextRange *me, BSTR str)
     len = lstrlenW(str);
     cursor = editor->pCursors[0];
     cursor_from_char_ofs( editor, This->start, &editor->pCursors[0] );
-    style = ME_GetInsertStyle(editor, 0);
+    style = style_get_insert_style( editor, editor->pCursors );
     ME_InsertTextFromCursor(editor, 0, str, len, style);
     ME_ReleaseStyle(style);
     editor->pCursors[0] = cursor;
diff --git a/dlls/riched20/run.c b/dlls/riched20/run.c
index 22a5db8610b..b1436ad5060 100644
--- a/dlls/riched20/run.c
+++ b/dlls/riched20/run.c
@@ -716,7 +716,7 @@ void ME_SetSelectionCharFormat(ME_TextEditor *editor, CHARFORMAT2W *pFmt)
   {
     ME_Style *s;
     if (!editor->pBuffer->pCharStyle)
-      editor->pBuffer->pCharStyle = ME_GetInsertStyle(editor, 0);
+      editor->pBuffer->pCharStyle = style_get_insert_style( editor, editor->pCursors );
     s = ME_ApplyStyle(editor, editor->pBuffer->pCharStyle, pFmt);
     ME_ReleaseStyle(editor->pBuffer->pCharStyle);
     editor->pBuffer->pCharStyle = s;
diff --git a/dlls/riched20/style.c b/dlls/riched20/style.c
index 8b9c2126b1b..fbbe29dce14 100644
--- a/dlls/riched20/style.c
+++ b/dlls/riched20/style.c
@@ -473,42 +473,26 @@ void ME_ReleaseStyle(ME_Style *s)
     ME_DestroyStyle(s);
 }
 
-ME_Style *ME_GetInsertStyle(ME_TextEditor *editor, int nCursor)
+ME_Style *style_get_insert_style( ME_TextEditor *editor, ME_Cursor *cursor )
 {
-  if (ME_IsSelection(editor))
-  {
+    ME_Style *style;
     ME_Cursor *from, *to;
+    ME_Run *prev;
 
-    ME_GetSelection(editor, &from, &to);
-    ME_AddRefStyle(from->pRun->member.run.style);
-    return from->pRun->member.run.style;
-  }
-  if (editor->pBuffer->pCharStyle) {
-    ME_AddRefStyle(editor->pBuffer->pCharStyle);
-    return editor->pBuffer->pCharStyle;
-  }
-  else
-  {
-    ME_Cursor *pCursor = &editor->pCursors[nCursor];
-    ME_DisplayItem *pRunItem = pCursor->pRun;
-    ME_DisplayItem *pPrevItem = NULL;
-    if (pCursor->nOffset) {
-      ME_Run *pRun = &pRunItem->member.run;
-      ME_AddRefStyle(pRun->style);
-      return pRun->style;
-    }
-    pPrevItem = ME_FindItemBack(pRunItem, diRunOrParagraph);
-    if (pPrevItem->type == diRun)
+    if (ME_IsSelection( editor ))
     {
-      ME_AddRefStyle(pPrevItem->member.run.style);
-      return pPrevItem->member.run.style;
+        ME_GetSelection( editor, &from, &to );
+        style = from->pRun->member.run.style;
     }
+    else if (editor->pBuffer->pCharStyle)
+        style = editor->pBuffer->pCharStyle;
+    else if (!cursor->nOffset && (prev = run_prev( &cursor->pRun->member.run )))
+        style = prev->style;
     else
-    {
-      ME_AddRefStyle(pRunItem->member.run.style);
-      return pRunItem->member.run.style;
-    }
-  }
+        style = cursor->pRun->member.run.style;
+
+    ME_AddRefStyle( style );
+    return style;
 }
 
 void ME_SaveTempStyle(ME_TextEditor *editor, ME_Style *style)
diff --git a/dlls/riched20/table.c b/dlls/riched20/table.c
index 876244c9706..08c8fcb7ebf 100644
--- a/dlls/riched20/table.c
+++ b/dlls/riched20/table.c
@@ -63,7 +63,7 @@ static ME_DisplayItem* ME_InsertEndParaFromCursor(ME_TextEditor *editor,
                                                   const WCHAR *eol_str, int eol_len,
                                                   int paraFlags)
 {
-  ME_Style *pStyle = ME_GetInsertStyle(editor, nCursor);
+  ME_Style *pStyle = style_get_insert_style( editor, editor->pCursors + nCursor );
   ME_Paragraph *para;
   ME_Cursor* cursor = &editor->pCursors[nCursor];
 




More information about the wine-cvs mailing list