[PATCH v2 2/5] riched20: Use combined flags for toggling CRLF and EOP.

Jactry Zeng jzeng at codeweavers.com
Tue May 25 02:06:00 CDT 2021


Signed-off-by: Jactry Zeng <jzeng at codeweavers.com>
---
 dlls/riched20/clipboard.c |  2 +-
 dlls/riched20/editor.c    | 22 ++++++++++------------
 dlls/riched20/editor.h    |  2 +-
 dlls/riched20/editstr.h   |  6 ++++++
 dlls/riched20/richole.c   |  6 +++---
 dlls/riched20/txtsrv.c    |  2 +-
 6 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/dlls/riched20/clipboard.c b/dlls/riched20/clipboard.c
index 10a814214be..69041fb7580 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, MEGT_USECRLF);
     GlobalUnlock(ret);
     return ret;
 }
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index d4aadc325f9..87f4c7a4e32 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, MEGT_DEFAULT);
           if (lastchar[0] == '\r' && (lastchar[1] == '\n' || lastchar[1] == '\0')) {
             ME_InternalDeleteText(editor, &linebreakCursor, linebreakSize, FALSE);
           }
@@ -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) ? MEGT_USECRLF : MEGT_DEFAULT);
     }
     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) ? MEGT_USECRLF : MEGT_DEFAULT);
       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, MEGT_DEFAULT );
 }
 
 int set_selection( ME_TextEditor *editor, int to, int from )
@@ -4239,23 +4239,21 @@ LRESULT editor_handle_message( ME_TextEditor *editor, UINT msg, WPARAM wParam,
  * buflen: length of buffer in characters excluding the NULL terminator.
  * start: start of editor text to copy into buffer.
  * srcChars: Number of characters to use from the editor text.
- * bCRLF: if true, replaces all end of lines with \r\n pairs.
  *
  * returns the number of characters written excluding the NULL terminator.
  *
  * The written text is always NULL terminated.
  */
 int ME_GetTextW(ME_TextEditor *editor, WCHAR *buffer, int buflen,
-                const ME_Cursor *start, int srcChars, BOOL bCRLF,
-                BOOL bEOP)
+                const ME_Cursor *start, int srcChars, DWORD flags)
 {
   ME_Run *run, *next_run;
   const WCHAR *pStart = buffer;
   const WCHAR *str;
   int nLen;
 
-  /* bCRLF flag is only honored in 2.0 and up. 1.0 must always return text verbatim */
-  if (editor->bEmulateVersion10) bCRLF = FALSE;
+  /* CR to CRLF is only supported in 2.0 and up. 1.0 must always return text verbatim. */
+  if (editor->bEmulateVersion10) flags &= ~MEGT_USECRLF;
 
   run = start->run;
   next_run = run_next_all_paras( run );
@@ -4265,7 +4263,7 @@ int ME_GetTextW(ME_TextEditor *editor, WCHAR *buffer, int buflen,
 
   while (srcChars && buflen && next_run)
   {
-    if (bCRLF && run->nFlags & MERF_ENDPARA && ~run->nFlags & MERF_ENDCELL)
+    if (flags & MEGT_USECRLF && run->nFlags & MERF_ENDPARA && ~run->nFlags & MERF_ENDCELL)
     {
       if (buflen == 1) break;
       /* FIXME: native fails to reduce srcChars here for WM_GETTEXT or
@@ -4295,7 +4293,7 @@ int ME_GetTextW(ME_TextEditor *editor, WCHAR *buffer, int buflen,
     str = get_text( run, 0 );
   }
   /* append '\r' to the last paragraph. */
-  if (run == para_end_run( para_prev( editor_end_para( editor ) ) ) && bEOP)
+  if (flags & MEGT_USEEOP && run == para_end_run( para_prev( editor_end_para( editor ) ) ))
   {
     *buffer = '\r';
     buffer ++;
@@ -4454,7 +4452,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, MEGT_DEFAULT);
   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..ee1b2e2b2e1 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, DWORD flags) 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/editstr.h b/dlls/riched20/editstr.h
index 22cfd74722c..7ede0f6a207 100644
--- a/dlls/riched20/editstr.h
+++ b/dlls/riched20/editstr.h
@@ -98,6 +98,12 @@ typedef enum {
 
 #define SELECTIONBAR_WIDTH 8
 
+/* Flags used in ME_GetTextW() */
+#define MEGT_DEFAULT         0x00000000
+#define MEGT_USECRLF         0x00000001 /* Translate each CR into a CR/LF. */
+#define MEGT_USEEOP          0x00000002 /* Append EOP. */
+#define MEGT_NOOLEOBJ        0x00000004 /* Replace OLE object mark with a space. */
+
 /******************************** run flags *************************/
 #define MERF_STYLEFLAGS 0x0FFF
 /* run contains non-text content, which has its own rules for wrapping, sizing etc */
diff --git a/dlls/riched20/richole.c b/dlls/riched20/richole.c
index 72840a4cafa..ccd97668338 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, bEOP ? MEGT_USEEOP : MEGT_DEFAULT);
     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, !para_next( para_next( cursor->para ) ) ? MEGT_USEEOP : MEGT_DEFAULT);
     *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, bEOP ? MEGT_USEEOP : MEGT_DEFAULT);
     TRACE("%s\n", wine_dbgstr_w(*pbstr));
 
     return S_OK;
diff --git a/dlls/riched20/txtsrv.c b/dlls/riched20/txtsrv.c
index 73b8d3ea7e9..c82d14f8f26 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, MEGT_DEFAULT );
         *text = bstr;
     }
     else *text = NULL;
-- 
2.30.2




More information about the wine-devel mailing list