[PATCH 1/3] riched20: Use codepage in ME_ToUnicode.

Jactry Zeng jactry92 at gmail.com
Mon Sep 2 22:55:08 CDT 2013


-------------- next part --------------
From 98f726c309f6e7d56aab74402f5a8e91b92bdb83 Mon Sep 17 00:00:00 2001
From: Jactry Zeng <jactry92 at gmail.com>
Date: Mon, 2 Sep 2013 15:17:11 +0800
Subject: riched20: Use codepage in ME_ToUnicode.
To: wine-patches <wine-patches at winehq.org>
Reply-To: wine-devel <wine-devel at winehq.org>

---
 dlls/riched20/editor.c |   25 +++++++++++++++----------
 dlls/riched20/editor.h |    4 ++--
 dlls/riched20/string.c |   19 +++++++++++--------
 3 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index f54458e..0f27271 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -3314,11 +3314,9 @@ 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;
+      wszText = lParam ? ME_ToUnicode(pStruct->codepage, (void *)lParam, &len) : NULL;
       ME_InsertTextFromCursor(editor, 0, wszText, len, style);
-      ME_EndToUnicode(bUnicode, wszText);
+      ME_EndToUnicode(pStruct->codepage, wszText);
     }
 
     if (bSelection) {
@@ -3505,8 +3503,12 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
   {
     int from, to, nStartCursor;
     ME_Style *style;
-    LPWSTR wszText = lParam ? ME_ToUnicode(unicode, (void *)lParam) : NULL;
-    size_t len = wszText ? lstrlenW(wszText) : 0;
+    LPWSTR wszText;
+    size_t len = 0;
+
+    if(unicode) wszText = lParam ? ME_ToUnicode(1200, (void *)lParam, &len) : NULL;
+    else wszText = lParam ? ME_ToUnicode(CP_ACP, (void *)lParam, &len) : NULL;
+
     TRACE("EM_REPLACESEL - %s\n", debugstr_w(wszText));
 
     nStartCursor = ME_GetSelectionOfs(editor, &from, &to);
@@ -3521,7 +3523,7 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
      */
     if (len>0 && wszText[len-1] == '\n')
       ME_ClearTempStyle(editor);
-    ME_EndToUnicode(unicode, wszText);
+    unicode ? ME_EndToUnicode(1200, wszText) : ME_EndToUnicode(CP_ACP, wszText);
     ME_CommitUndo(editor);
     ME_UpdateSelectionLinkAttribute(editor);
     if (!wParam)
@@ -3576,9 +3578,12 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
       }
       else
       {
-        LPWSTR wszText = ME_ToUnicode(unicode, (void *)lParam);
+        LPWSTR wszText;
+        size_t textLen;
+        unicode ? (wszText = ME_ToUnicode(1200, (void *)lParam, &textLen)) :
+            (wszText = ME_ToUnicode(CP_ACP, (void *)lParam, &textLen));
         TRACE("WM_SETTEXT - %s\n", debugstr_w(wszText)); /* debugstr_w() */
-        if (lstrlenW(wszText) > 0)
+        if (textLen > 0)
         {
           int len = -1;
 
@@ -3593,7 +3598,7 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
           }
           ME_InsertTextFromCursor(editor, 0, wszText, len, editor->pBuffer->pDefaultStyle);
         }
-        ME_EndToUnicode(unicode, wszText);
+        unicode ? ME_EndToUnicode(1200, wszText) : ME_EndToUnicode(CP_ACP, wszText);
       }
     }
     else
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index 8c78447..de450c6 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -109,8 +109,8 @@ void ME_StrDeleteV(ME_String *s, int nVChar, int nChars) DECLSPEC_HIDDEN;
 BOOL ME_InsertString(ME_String *s, int ofs, const WCHAR *insert, int len) DECLSPEC_HIDDEN;
 
 /* smart helpers for A<->W conversions, they reserve/free memory and call MultiByte<->WideChar functions */
-LPWSTR ME_ToUnicode(BOOL unicode, LPVOID psz) DECLSPEC_HIDDEN;
-void ME_EndToUnicode(BOOL unicode, LPVOID psz) DECLSPEC_HIDDEN;
+LPWSTR ME_ToUnicode(LONG codepage, LPVOID psz, size_t *len) DECLSPEC_HIDDEN;
+void ME_EndToUnicode(LONG codepage, LPVOID psz) DECLSPEC_HIDDEN;
 
 static inline int ME_IsWSpace(WCHAR ch)
 {
diff --git a/dlls/riched20/string.c b/dlls/riched20/string.c
index 6d7d222..67f4dae 100644
--- a/dlls/riched20/string.c
+++ b/dlls/riched20/string.c
@@ -172,23 +172,26 @@ ME_CallWordBreakProc(ME_TextEditor *editor, WCHAR *str, INT len, INT start, INT
   }
 }
 
-LPWSTR ME_ToUnicode(BOOL unicode, LPVOID psz)
+LPWSTR ME_ToUnicode(LONG codepage, LPVOID psz, size_t *len)
 {
   assert(psz != NULL);
 
-  if (unicode)
+  if(codepage == 1200)
+  {
+    if(len) *len = lstrlenW(psz);
     return psz;
-  else {
-    WCHAR *tmp;
-    int nChars = MultiByteToWideChar(CP_ACP, 0, psz, -1, NULL, 0);
+  } else {
+    WCHAR *tmp = NULL;
+    int nChars = MultiByteToWideChar(codepage, 0, psz, -1, NULL, 0);
+    if(len) *len = nChars - 1;
     if((tmp = ALLOC_N_OBJ(WCHAR, nChars)) != NULL)
-      MultiByteToWideChar(CP_ACP, 0, psz, -1, tmp, nChars);
+      MultiByteToWideChar(codepage, 0, psz, -1, tmp, nChars);
     return tmp;
   }
 }
 
-void ME_EndToUnicode(BOOL unicode, LPVOID psz)
+void ME_EndToUnicode(LONG codepage, LPVOID psz)
 {
-  if (!unicode)
+  if(codepage != 1200)
     FREE_OBJ(psz);
 }
-- 
1.7.10.4


More information about the wine-patches mailing list