Nikolay Sivov : riched20: Implement SetText() for selection range.

Alexandre Julliard julliard at wine.codeweavers.com
Wed May 27 09:30:58 CDT 2015


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

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Wed May 27 01:17:41 2015 +0300

riched20: Implement SetText() for selection range.

---

 dlls/riched20/editor.c  | 45 ++++++++++++++++++++++++++-------------------
 dlls/riched20/editor.h  |  1 +
 dlls/riched20/richole.c | 18 +++++++++++++++---
 3 files changed, 42 insertions(+), 22 deletions(-)

diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index 3ed06ef..8d878a4 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -3134,6 +3134,30 @@ static void ME_LinkNotify(ME_TextEditor *editor, UINT msg, WPARAM wParam, LPARAM
   }
 }
 
+void ME_ReplaceSel(ME_TextEditor *editor, BOOL can_undo, const WCHAR *str, int len)
+{
+  int from, to, nStartCursor;
+  ME_Style *style;
+
+  nStartCursor = ME_GetSelectionOfs(editor, &from, &to);
+  style = ME_GetSelectionInsertStyle(editor);
+  ME_InternalDeleteText(editor, &editor->pCursors[nStartCursor], to-from, FALSE);
+  ME_InsertTextFromCursor(editor, 0, str, len, style);
+  ME_ReleaseStyle(style);
+  /* drop temporary style if line end */
+  /*
+   * FIXME question: does abc\n mean: put abc,
+   * clear temp style, put \n? (would require a change)
+   */
+  if (len>0 && str[len-1] == '\n')
+    ME_ClearTempStyle(editor);
+  ME_CommitUndo(editor);
+  ME_UpdateSelectionLinkAttribute(editor);
+  if (!can_undo)
+    ME_EmptyUndoStack(editor);
+  ME_UpdateRepaint(editor, FALSE);
+}
+
 #define UNSUPPORTED_MSG(e) \
   case e:                  \
     FIXME(#e ": stub\n");  \
@@ -3609,31 +3633,14 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
   }
   case EM_REPLACESEL:
   {
-    int from, to, nStartCursor;
-    ME_Style *style;
     int len = 0;
     LONG codepage = unicode ? CP_UNICODE : CP_ACP;
     LPWSTR wszText = ME_ToUnicode(codepage, (void *)lParam, &len);
+
     TRACE("EM_REPLACESEL - %s\n", debugstr_w(wszText));
 
-    nStartCursor = ME_GetSelectionOfs(editor, &from, &to);
-    style = ME_GetSelectionInsertStyle(editor);
-    ME_InternalDeleteText(editor, &editor->pCursors[nStartCursor], to-from, FALSE);
-    ME_InsertTextFromCursor(editor, 0, wszText, len, style);
-    ME_ReleaseStyle(style);
-    /* drop temporary style if line end */
-    /*
-     * FIXME question: does abc\n mean: put abc,
-     * clear temp style, put \n? (would require a change)
-     */
-    if (len>0 && wszText[len-1] == '\n')
-      ME_ClearTempStyle(editor);
+    ME_ReplaceSel(editor, !!wParam, wszText, len);
     ME_EndToUnicode(codepage, wszText);
-    ME_CommitUndo(editor);
-    ME_UpdateSelectionLinkAttribute(editor);
-    if (!wParam)
-      ME_EmptyUndoStack(editor);
-    ME_UpdateRepaint(editor, FALSE);
     return len;
   }
   case EM_SCROLLCARET:
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index b3691c8..3e42ed8 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -262,6 +262,7 @@ void ME_RTFTblAttrHook(struct _RTF_Info *info) DECLSPEC_HIDDEN;
 void ME_RTFSpecialCharHook(struct _RTF_Info *info) DECLSPEC_HIDDEN;
 void ME_StreamInFill(ME_InStream *stream) DECLSPEC_HIDDEN;
 extern BOOL me_debug DECLSPEC_HIDDEN;
+void ME_ReplaceSel(ME_TextEditor *editor, BOOL can_undo, const WCHAR *str, int len) DECLSPEC_HIDDEN;
 
 /* table.c */
 BOOL ME_IsInTable(ME_DisplayItem *pItem) DECLSPEC_HIDDEN;
diff --git a/dlls/riched20/richole.c b/dlls/riched20/richole.c
index 06ff9aa..14c4c8e 100644
--- a/dlls/riched20/richole.c
+++ b/dlls/riched20/richole.c
@@ -3860,14 +3860,26 @@ static HRESULT WINAPI ITextSelection_fnGetText(ITextSelection *me, BSTR *pbstr)
     return S_OK;
 }
 
-static HRESULT WINAPI ITextSelection_fnSetText(ITextSelection *me, BSTR bstr)
+static HRESULT WINAPI ITextSelection_fnSetText(ITextSelection *me, BSTR str)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    ME_TextEditor *editor;
+    int len, to, from;
+
+    TRACE("(%p)->(%s)\n", This, debugstr_w(str));
+
     if (!This->reOle)
         return CO_E_RELEASED;
 
-    FIXME("not implemented\n");
-    return E_NOTIMPL;
+    editor = This->reOle->editor;
+    len = strlenW(str);
+    ME_GetSelectionOfs(editor, &from, &to);
+    ME_ReplaceSel(editor, FALSE, str, len);
+
+    if (len < to - from)
+        textranges_update_ranges(This->reOle, from, len, RANGE_UPDATE_DELETE);
+
+    return S_OK;
 }
 
 static HRESULT WINAPI ITextSelection_fnGetChar(ITextSelection *me, LONG *pch)




More information about the wine-cvs mailing list