[PATCH 7/7] riched20: Allow to return text with OLE object mark.

Jactry Zeng jzeng at codeweavers.com
Thu May 20 02:56:15 CDT 2021


Signed-off-by: Jactry Zeng <jzeng at codeweavers.com>
---
 dlls/riched20/clipboard.c     |  2 +-
 dlls/riched20/editor.c        | 23 ++++++++++++++---------
 dlls/riched20/editor.h        |  2 +-
 dlls/riched20/richole.c       |  6 +++---
 dlls/riched20/tests/richole.c | 20 ++++++++++----------
 dlls/riched20/tests/txtsrv.c  |  2 +-
 dlls/riched20/txtsrv.c        |  2 +-
 7 files changed, 31 insertions(+), 26 deletions(-)

diff --git a/dlls/riched20/clipboard.c b/dlls/riched20/clipboard.c
index 10a814214be..c7abdeba6a3 100644
--- a/dlls/riched20/clipboard.c
+++ b/dlls/riched20/clipboard.c
@@ -354,7 +354,7 @@ static HGLOBAL get_unicode_text(ME_TextEditor *editor, const ME_Cursor *start, i
 
     ret = GlobalAlloc(GMEM_MOVEABLE, sizeof(WCHAR) * (nChars + pars + 1));
     data = GlobalLock(ret);
-    ME_GetTextW(editor, data, nChars + pars, start, nChars, TRUE, FALSE);
+    ME_GetTextW(editor, data, nChars + pars, start, nChars, TRUE, FALSE, FALSE);
     GlobalUnlock(ret);
     return ret;
 }
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index d4aadc325f9..c267832fa58 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -1750,7 +1750,7 @@ static LRESULT ME_StreamIn(ME_TextEditor *editor, DWORD format, EDITSTREAM *stre
           set_selection_cursors(editor, newto, newto);
 
           ME_MoveCursorChars(editor, &linebreakCursor, -linebreakSize, FALSE);
-          ME_GetTextW(editor, lastchar, 2, &linebreakCursor, linebreakSize, FALSE, FALSE);
+          ME_GetTextW(editor, lastchar, 2, &linebreakCursor, linebreakSize, FALSE, FALSE, FALSE);
           if (lastchar[0] == '\r' && (lastchar[1] == '\n' || lastchar[1] == '\0')) {
             ME_InternalDeleteText(editor, &linebreakCursor, linebreakSize, FALSE);
           }
@@ -2076,7 +2076,7 @@ ME_FindText(ME_TextEditor *editor, DWORD flags, const CHARRANGE *chrg, const WCH
   return -1;
 }
 
-static int ME_GetTextEx(ME_TextEditor *editor, GETTEXTEX *ex, LPARAM pText)
+static int ME_GetTextEx(ME_TextEditor *editor, GETTEXTEX *ex, LPARAM pText, BOOL object)
 {
     int nChars;
     ME_Cursor start;
@@ -2101,7 +2101,7 @@ static int ME_GetTextEx(ME_TextEditor *editor, GETTEXTEX *ex, LPARAM pText)
     if (ex->codepage == CP_UNICODE)
     {
       return ME_GetTextW(editor, (LPWSTR)pText, ex->cb / sizeof(WCHAR) - 1,
-                         &start, nChars, ex->flags & GT_USECRLF, FALSE);
+                         &start, nChars, ex->flags & GT_USECRLF, FALSE, object);
     }
     else
     {
@@ -2118,7 +2118,7 @@ static int ME_GetTextEx(ME_TextEditor *editor, GETTEXTEX *ex, LPARAM pText)
       buflen = min(crlfmul * nChars, ex->cb - 1);
       buffer = heap_alloc((buflen + 1) * sizeof(WCHAR));
 
-      nChars = ME_GetTextW(editor, buffer, buflen, &start, nChars, ex->flags & GT_USECRLF, FALSE);
+      nChars = ME_GetTextW(editor, buffer, buflen, &start, nChars, ex->flags & GT_USECRLF, FALSE, object);
       rc = WideCharToMultiByte(ex->codepage, 0, buffer, nChars + 1,
                                (LPSTR)pText, ex->cb, ex->lpDefaultChar, ex->lpUsedDefChar);
       if (rc) rc--; /* do not count 0 terminator */
@@ -2132,7 +2132,7 @@ static int get_text_range( ME_TextEditor *editor, WCHAR *buffer,
                            const ME_Cursor *start, int len )
 {
     if (!buffer) return 0;
-    return ME_GetTextW( editor, buffer, INT_MAX, start, len, FALSE, FALSE );
+    return ME_GetTextW( editor, buffer, INT_MAX, start, len, FALSE, FALSE, FALSE );
 }
 
 int set_selection( ME_TextEditor *editor, int to, int from )
@@ -3662,10 +3662,10 @@ LRESULT editor_handle_message( ME_TextEditor *editor, UINT msg, WPARAM wParam,
     ex.codepage = CP_UNICODE;
     ex.lpDefaultChar = NULL;
     ex.lpUsedDefChar = NULL;
-    return ME_GetTextEx(editor, &ex, lParam);
+    return ME_GetTextEx(editor, &ex, lParam, FALSE);
   }
   case EM_GETTEXTEX:
-    return ME_GetTextEx(editor, (GETTEXTEX*)wParam, lParam);
+    return ME_GetTextEx(editor, (GETTEXTEX*)wParam, lParam, TRUE);
   case EM_GETSELTEXT:
   {
     int nFrom, nTo, nStartCur = ME_GetSelectionOfs(editor, &nFrom, &nTo);
@@ -4247,7 +4247,7 @@ LRESULT editor_handle_message( ME_TextEditor *editor, UINT msg, WPARAM wParam,
  */
 int ME_GetTextW(ME_TextEditor *editor, WCHAR *buffer, int buflen,
                 const ME_Cursor *start, int srcChars, BOOL bCRLF,
-                BOOL bEOP)
+                BOOL bEOP, BOOL object)
 {
   ME_Run *run, *next_run;
   const WCHAR *pStart = buffer;
@@ -4275,6 +4275,11 @@ int ME_GetTextW(ME_TextEditor *editor, WCHAR *buffer, int buflen,
       nLen = 2;
       str = L"\r\n";
     }
+    else if (object && run->nFlags & MERF_GRAPHICS)
+    {
+      srcChars--;
+      str = L"\xfffc";
+    }
     else
     {
       nLen = min(nLen, srcChars);
@@ -4454,7 +4459,7 @@ static BOOL ME_IsCandidateAnURL(ME_TextEditor *editor, const ME_Cursor *start, i
   WCHAR bufferW[MAX_PREFIX_LEN + 1];
   unsigned int i;
 
-  ME_GetTextW(editor, bufferW, MAX_PREFIX_LEN, start, nChars, FALSE, FALSE);
+  ME_GetTextW(editor, bufferW, MAX_PREFIX_LEN, start, nChars, FALSE, FALSE, FALSE);
   for (i = 0; i < ARRAY_SIZE(prefixes); i++)
   {
     if (nChars < prefixes[i].length) continue;
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index 141e9034a6a..3f956a3d27b 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -277,7 +277,7 @@ void ME_DestroyEditor(ME_TextEditor *editor) DECLSPEC_HIDDEN;
 LRESULT editor_handle_message( ME_TextEditor *editor, UINT msg, WPARAM wParam,
                                LPARAM lParam, HRESULT* phresult ) DECLSPEC_HIDDEN;
 int ME_GetTextW(ME_TextEditor *editor, WCHAR *buffer, int buflen,
-                const ME_Cursor *start, int srcChars, BOOL bCRLF, BOOL bEOP) DECLSPEC_HIDDEN;
+                const ME_Cursor *start, int srcChars, BOOL bCRLF, BOOL bEOP, BOOL object) DECLSPEC_HIDDEN;
 void ME_RTFCharAttrHook(struct _RTF_Info *info) DECLSPEC_HIDDEN;
 void ME_RTFParAttrHook(struct _RTF_Info *info) DECLSPEC_HIDDEN;
 void ME_RTFTblAttrHook(struct _RTF_Info *info) DECLSPEC_HIDDEN;
diff --git a/dlls/riched20/richole.c b/dlls/riched20/richole.c
index 72840a4cafa..7049526f577 100644
--- a/dlls/riched20/richole.c
+++ b/dlls/riched20/richole.c
@@ -1563,7 +1563,7 @@ static HRESULT WINAPI ITextRange_fnGetText(ITextRange *me, BSTR *str)
         return E_OUTOFMEMORY;
 
     bEOP = (!para_next( para_next( end.para )) && This->end > ME_GetTextLength(editor));
-    ME_GetTextW(editor, *str, length, &start, length, FALSE, bEOP);
+    ME_GetTextW(editor, *str, length, &start, length, FALSE, bEOP, TRUE);
     return S_OK;
 }
 
@@ -1617,7 +1617,7 @@ static HRESULT range_GetChar(ME_TextEditor *editor, ME_Cursor *cursor, LONG *pch
 {
     WCHAR wch[2];
 
-    ME_GetTextW(editor, wch, 1, cursor, 1, FALSE, !para_next( para_next( cursor->para ) ));
+    ME_GetTextW(editor, wch, 1, cursor, 1, FALSE, !para_next( para_next( cursor->para ) ), TRUE);
     *pch = wch[0];
 
     return S_OK;
@@ -4651,7 +4651,7 @@ static HRESULT WINAPI ITextSelection_fnGetText(ITextSelection *me, BSTR *pbstr)
         return E_OUTOFMEMORY;
 
     bEOP = (!para_next( para_next( end->para ) ) && endOfs > ME_GetTextLength(This->services->editor));
-    ME_GetTextW(This->services->editor, *pbstr, nChars, start, nChars, FALSE, bEOP);
+    ME_GetTextW(This->services->editor, *pbstr, nChars, start, nChars, FALSE, bEOP, TRUE);
     TRACE("%s\n", wine_dbgstr_w(*pbstr));
 
     return S_OK;
diff --git a/dlls/riched20/tests/richole.c b/dlls/riched20/tests/richole.c
index a50a4aff26b..702190c8259 100644
--- a/dlls/riched20/tests/richole.c
+++ b/dlls/riched20/tests/richole.c
@@ -3395,13 +3395,13 @@ static void test_InsertObject(void)
   gettextex.lpUsedDefChar = NULL;
   result = SendMessageW(hwnd, EM_GETTEXTEX, (WPARAM)&gettextex, (LPARAM)buffer);
   ok(result == lstrlenW(expected_string), "Got wrong length: %d.\n", result);
-  todo_wine ok(!lstrcmpW(buffer, expected_string), "Got wrong content: %s.\n", debugstr_w(buffer));
+  ok(!lstrcmpW(buffer, expected_string), "Got wrong content: %s.\n", debugstr_w(buffer));
 
   gettextex.flags = GT_RAWTEXT;
   memset(buffer, 0, sizeof(buffer));
   result = SendMessageW(hwnd, EM_GETTEXTEX, (WPARAM)&gettextex, (LPARAM)buffer);
   ok(result == lstrlenW(expected_string), "Got wrong length: %d.\n", result);
-  todo_wine ok(!lstrcmpW(buffer, expected_string), "Got wrong content: %s.\n", debugstr_w(buffer));
+  ok(!lstrcmpW(buffer, expected_string), "Got wrong content: %s.\n", debugstr_w(buffer));
 
   expected_stringA = "abc d efg";
   memset(bufferA, 0, sizeof(bufferA));
@@ -3424,26 +3424,26 @@ static void test_InsertObject(void)
   hr = ITextRange_GetText(range, &bstr);
   ok(hr == S_OK, "Got hr %#x.\n", hr);
   ok(lstrlenW(bstr) == lstrlenW(expected_string), "Got wrong length: %d.\n", lstrlenW(bstr));
-  todo_wine ok(!lstrcmpW(bstr, expected_string), "Got text: %s.\n", wine_dbgstr_w(bstr));
+  ok(!lstrcmpW(bstr, expected_string), "Got text: %s.\n", wine_dbgstr_w(bstr));
   SysFreeString(bstr);
   hr = ITextRange_SetRange(range, 3, 4);
   ok(hr == S_OK, "Got hr %#x.\n", hr);
   hr = ITextRange_GetChar(range, &result);
   ok(hr == S_OK, "Got hr %#x.\n", hr);
-  todo_wine ok(result == 0xfffc, "Got char: %c\n", result);
+  ok(result == 0xfffc, "Got char: %c\n", result);
   ITextRange_Release(range);
 
   SendMessageW(hwnd, EM_SETSEL, 0, -1);
   hr = ITextSelection_GetText(selection, &bstr);
   ok(hr == S_OK, "Got hr %#x.\n", hr);
   ok(lstrlenW(bstr) == lstrlenW(expected_string), "Got wrong length: %d.\n", lstrlenW(bstr));
-  todo_wine ok(!lstrcmpW(bstr, expected_string), "Got text: %s.\n", wine_dbgstr_w(bstr));
+  ok(!lstrcmpW(bstr, expected_string), "Got text: %s.\n", wine_dbgstr_w(bstr));
   SysFreeString(bstr);
   SendMessageW(hwnd, EM_SETSEL, 3, 4);
   result = 0;
   hr = ITextSelection_GetChar(selection, &result);
   ok(hr == S_OK, "Got hr %#x.\n", hr);
-  todo_wine ok(result == 0xfffc, "Got char: %c\n", result);
+  ok(result == 0xfffc, "Got char: %c\n", result);
 
   SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)"");
   result = SendMessageW(hwnd, EM_SETTEXTMODE, (WPARAM)TM_PLAINTEXT, 0);
@@ -3476,13 +3476,13 @@ static void test_InsertObject(void)
   gettextex.lpUsedDefChar = NULL;
   result = SendMessageW(hwnd, EM_GETTEXTEX, (WPARAM)&gettextex, (LPARAM)buffer);
   ok(result == lstrlenW(expected_string), "Got wrong length: %d.\n", result);
-  todo_wine ok(!lstrcmpW(buffer, expected_string), "Got wrong content: %s.\n", debugstr_w(buffer));
+  ok(!lstrcmpW(buffer, expected_string), "Got wrong content: %s.\n", debugstr_w(buffer));
 
   gettextex.flags = GT_RAWTEXT;
   memset(buffer, 0, sizeof(buffer));
   result = SendMessageW(hwnd, EM_GETTEXTEX, (WPARAM)&gettextex, (LPARAM)buffer);
   ok(result == lstrlenW(expected_string), "Got wrong length: %d.\n", result);
-  todo_wine ok(!lstrcmpW(buffer, expected_string), "Got wrong content: %s.\n", debugstr_w(buffer));
+  ok(!lstrcmpW(buffer, expected_string), "Got wrong content: %s.\n", debugstr_w(buffer));
 
   expected_stringA = "abc d efg";
   memset(bufferA, 0, sizeof(bufferA));
@@ -3511,7 +3511,7 @@ static void test_InsertObject(void)
   ok(hr == S_OK, "Got hr %#x.\n", hr);
   hr = ITextRange_GetChar(range, &result);
   ok(hr == S_OK, "Got hr %#x.\n", hr);
-  todo_wine ok(result == 0xfffc, "Got char: %c\n", result);
+  ok(result == 0xfffc, "Got char: %c\n", result);
   ITextRange_Release(range);
 
   SendMessageW(hwnd, EM_SETSEL, 0, -1);
@@ -3524,7 +3524,7 @@ static void test_InsertObject(void)
   result = 0;
   hr = ITextSelection_GetChar(selection, &result);
   ok(hr == S_OK, "Got hr %#x.\n", hr);
-  todo_wine ok(result == 0xfffc, "Got char: %c\n", result);
+  ok(result == 0xfffc, "Got char: %c\n", result);
 
   release_interfaces(&hwnd, &reole, &doc, &selection);
 }
diff --git a/dlls/riched20/tests/txtsrv.c b/dlls/riched20/tests/txtsrv.c
index 08db02517f5..8f9ccf35717 100644
--- a/dlls/riched20/tests/txtsrv.c
+++ b/dlls/riched20/tests/txtsrv.c
@@ -698,7 +698,7 @@ static void test_TxGetText(void)
     hres = ITextServices_TxGetText(txtserv, &rettext);
     ok(hres == S_OK, "Got hres: %#x.\n", hres);
     ok(lstrlenW(rettext) == lstrlenW(expected_string), "Got wrong length: %d.\n", lstrlenW(rettext));
-    todo_wine ok(!lstrcmpW(rettext, expected_string), "Got wrong content: %s.\n", debugstr_w(rettext));
+    ok(!lstrcmpW(rettext, expected_string), "Got wrong content: %s.\n", debugstr_w(rettext));
     SysFreeString(rettext);
     IOleClientSite_Release(clientsite);
     IRichEditOle_Release(reole);
diff --git a/dlls/riched20/txtsrv.c b/dlls/riched20/txtsrv.c
index 73b8d3ea7e9..9ea8b64b4ac 100644
--- a/dlls/riched20/txtsrv.c
+++ b/dlls/riched20/txtsrv.c
@@ -312,7 +312,7 @@ DECLSPEC_HIDDEN HRESULT __thiscall fnTextSrv_TxGetText( ITextServices *iface, BS
         if (bstr == NULL) return E_OUTOFMEMORY;
 
         cursor_from_char_ofs( services->editor, 0, &start );
-        ME_GetTextW( services->editor, bstr, length, &start, INT_MAX, FALSE, FALSE );
+        ME_GetTextW( services->editor, bstr, length, &start, INT_MAX, FALSE, FALSE, TRUE );
         *text = bstr;
     }
     else *text = NULL;
-- 
2.30.2




More information about the wine-devel mailing list