[PATCH 1/5] riched20: Handle EM_GETLINE's unicode conversion in the host.

Huw Davies huw at codeweavers.com
Mon Mar 15 05:03:17 CDT 2021


Signed-off-by: Huw Davies <huw at codeweavers.com>
---
 dlls/riched20/editor.c  | 24 +++++-------------------
 dlls/riched20/txthost.c | 31 +++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 19 deletions(-)

diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index eb1ec78d962..c27a691de4f 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -4030,11 +4030,9 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
     const unsigned int nMaxChars = *(WORD *) lParam;
     unsigned int nCharsLeft = nMaxChars;
     char *dest = (char *) lParam;
-    BOOL wroteNull = FALSE;
     ME_Cursor start, end;
 
-    TRACE("EM_GETLINE: row=%d, nMaxChars=%d (%s)\n", (int) wParam, nMaxChars,
-          unicode ? "Unicode" : "Ansi");
+    TRACE( "EM_GETLINE: row=%d, nMaxChars=%d\n", (int)wParam, nMaxChars );
 
     row = row_from_row_number( editor, wParam );
     if (row == NULL) return 0;
@@ -4052,30 +4050,18 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
       str = get_text( run, ofs );
       nCopy = min( nCharsLeft, len );
 
-      if (unicode)
-        memcpy(dest, str, nCopy * sizeof(WCHAR));
-      else
-        nCopy = WideCharToMultiByte(CP_ACP, 0, str, nCopy, dest,
-                                    nCharsLeft, NULL, NULL);
-      dest += nCopy * (unicode ? sizeof(WCHAR) : 1);
+      memcpy(dest, str, nCopy * sizeof(WCHAR));
+      dest += nCopy * sizeof(WCHAR);
       nCharsLeft -= nCopy;
       if (run == end.run) break;
       run = row_next_run( row, run );
     }
 
     /* append line termination, space allowing */
-    if (nCharsLeft > 0)
-    {
-      if (unicode)
-        *((WCHAR *)dest) = '\0';
-      else
-        *dest = '\0';
-      nCharsLeft--;
-      wroteNull = TRUE;
-    }
+    if (nCharsLeft > 0) *((WCHAR *)dest) = '\0';
 
     TRACE("EM_GETLINE: got %u characters\n", nMaxChars - nCharsLeft);
-    return nMaxChars - nCharsLeft - (wroteNull ? 1 : 0);
+    return nMaxChars - nCharsLeft;
   }
   case EM_GETLINECOUNT:
   {
diff --git a/dlls/riched20/txthost.c b/dlls/riched20/txthost.c
index d249137d829..a10b77e8ebb 100644
--- a/dlls/riched20/txthost.c
+++ b/dlls/riched20/txthost.c
@@ -753,6 +753,32 @@ static BOOL create_windowed_editor( HWND hwnd, CREATESTRUCTW *create, BOOL emula
     return TRUE;
 }
 
+static HRESULT get_lineA( ITextServices *text_srv, WPARAM wparam, LPARAM lparam, LRESULT *res )
+{
+    LRESULT len = USHRT_MAX;
+    WORD sizeA;
+    HRESULT hr;
+    WCHAR *buf;
+
+    *res = 0;
+    sizeA = *(WORD *)lparam;
+    *(WORD *)lparam = 0;
+    if (!sizeA) return S_OK;
+    buf = heap_alloc( len * sizeof(WCHAR) );
+    if (!buf) return E_OUTOFMEMORY;
+    *(WORD *)buf = len;
+    hr = ITextServices_TxSendMessage( text_srv, EM_GETLINE, wparam, (LPARAM)buf, &len );
+    if (hr == S_OK && len)
+    {
+        len = WideCharToMultiByte( CP_ACP, 0, buf, len, (char *)lparam, sizeA, NULL, NULL );
+        if (!len && GetLastError() == ERROR_INSUFFICIENT_BUFFER) len = sizeA;
+        if (len < sizeA) ((char *)lparam)[len] = '\0';
+        *res = len;
+    }
+    heap_free( buf );
+    return hr;
+}
+
 static HRESULT get_text_rangeA( struct host *host, TEXTRANGEA *rangeA, LRESULT *res )
 {
     TEXTRANGEW range;
@@ -871,6 +897,11 @@ static LRESULT RichEditWndProc_common( HWND hwnd, UINT msg, WPARAM wparam,
         }
         break;
     }
+    case EM_GETLINE:
+        if (unicode) hr = ITextServices_TxSendMessage( host->text_srv, msg, wparam, lparam, &res );
+        else hr = get_lineA( host->text_srv, wparam, lparam, &res );
+        break;
+
     case WM_GETTEXT:
     {
         GETTEXTEX params;
-- 
2.23.0




More information about the wine-devel mailing list