riched20: Add utf-8 support for EM_SETTEXTEX.

Jactry Zeng jactry92 at gmail.com
Sun Aug 18 21:47:01 CDT 2013


-------------- next part --------------
From 2fb8b7f1d815a1ead188dd71a1c7b0a30e4f8a69 Mon Sep 17 00:00:00 2001
From: Jactry Zeng <jactry92 at gmail.com>
Date: Mon, 19 Aug 2013 10:17:36 +0800
Subject: [PATCH 2/2] riched20: Add utf-8 support for EM_SETTEXTEX.
To: wine-patches <wine-patches at winehq.org>
Reply-To: wine-devel <wine-devel at winehq.org>

---
 dlls/riched20/editor.c |   22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index f54458e..e6e6e13 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -3279,8 +3279,9 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
     size_t len = 0;
     int from, to;
     ME_Style *style;
-    BOOL bRtf, bUnicode, bSelection;
+    BOOL bRtf, bUnicode, bSelection, bUTF8;
     int oldModify = editor->nModifyStep;
+    static const char utf8_bom[] = {0xef, 0xbb, 0xbf};
 
     if (!pStruct) return 0;
 
@@ -3289,6 +3290,7 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
     bRtf = (lParam && (!strncmp((char *)lParam, "{\\rtf", 5) ||
                          !strncmp((char *)lParam, "{\\urtf", 6)));
     bUnicode = !bRtf && pStruct->codepage == 1200;
+    bUTF8 = (lParam && (!strncmp((char *)lParam, utf8_bom, 3)));
 
     TRACE("EM_SETTEXTEX - %s, flags %d, cp %d\n",
           bUnicode ? debugstr_w((LPCWSTR)lParam) : debugstr_a((LPCSTR)lParam),
@@ -3314,11 +3316,19 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
         len = lParam ? strlen((char *)lParam) : 0;
       }
     } else {
-      /* FIXME: make use of pStruct->codepage in the to unicode translation */
-      wszText = lParam ? ME_ToUnicode(bUnicode, (void *)lParam) : NULL;
-      len = wszText ? lstrlenW(wszText) : 0;
-      ME_InsertTextFromCursor(editor, 0, wszText, len, style);
-      ME_EndToUnicode(bUnicode, wszText);
+      if (bUTF8) {
+        wszText = lParam ? ME_ToUnicode(bUnicode, (void *)(lParam)) : NULL;
+        len = wszText ?  MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)lParam, -1, 0, 0): 0;
+        MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)(lParam), -1, wszText, len);
+        ME_InsertTextFromCursor(editor, 0, wszText, len-1, style);
+        ME_EndToUnicode(bUnicode, wszText);
+      } else {
+        /* FIXME: make use of pStruct->codepage in the to unicode translation */
+        wszText = lParam ? ME_ToUnicode(bUnicode, (void *)lParam) : NULL;
+        len = wszText ? lstrlenW(wszText) : 0;
+        ME_InsertTextFromCursor(editor, 0, wszText, len, style);
+        ME_EndToUnicode(bUnicode, wszText);
+      }
     }
 
     if (bSelection) {
-- 
1.7.10.4


More information about the wine-patches mailing list