[PATCH 1/3] riched20: Use codepage in ME_ToUnicode. (try 5)

Jactry Zeng jactry92 at gmail.com
Fri Sep 13 04:27:21 CDT 2013


Re-based to latest git.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.winehq.org/pipermail/wine-patches/attachments/20130913/637e1cdd/attachment.html>
-------------- next part --------------
From 1759724c745a92d16405b1e9a6ae7acbb27be35b Mon Sep 17 00:00:00 2001
From: Jactry Zeng <jactry92 at gmail.com>
Date: Fri, 13 Sep 2013 12:17:34 +0800
Subject: [PATCH 1/3] 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 |   23 ++++++++++++-----------
 dlls/riched20/editor.h |    5 +++--
 dlls/riched20/string.c |   12 ++++++------
 3 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index 9af8a23..0e97ece 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -1918,7 +1918,7 @@ static int ME_GetTextEx(ME_TextEditor *editor, GETTEXTEX *ex, LPARAM pText)
       ME_SetCursorToStart(editor, &start);
       nChars = INT_MAX;
     }
-    if (ex->codepage == 1200)
+    if (ex->codepage == CP_UNICODE)
     {
       return ME_GetTextW(editor, (LPWSTR)pText, ex->cb / sizeof(WCHAR) - 1,
                          &start, nChars, ex->flags & GT_USECRLF);
@@ -3287,7 +3287,7 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
      * we know it isn't unicode. */
     bRtf = (lParam && (!strncmp((char *)lParam, "{\\rtf", 5) ||
                          !strncmp((char *)lParam, "{\\urtf", 6)));
-    bUnicode = !bRtf && pStruct->codepage == 1200;
+    bUnicode = !bRtf && pStruct->codepage == CP_UNICODE;
 
     TRACE("EM_SETTEXTEX - %s, flags %d, cp %d\n",
           bUnicode ? debugstr_w((LPCWSTR)lParam) : debugstr_a((LPCSTR)lParam),
@@ -3313,10 +3313,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 = ME_ToUnicode(bUnicode, (void *)lParam, &len);
+      wszText = ME_ToUnicode(pStruct->codepage, (void *)lParam, &len);
       ME_InsertTextFromCursor(editor, 0, wszText, len, style);
-      ME_EndToUnicode(bUnicode, wszText);
+      ME_EndToUnicode(pStruct->codepage, wszText);
     }
 
     if (bSelection) {
@@ -3504,7 +3503,8 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
     int from, to, nStartCursor;
     ME_Style *style;
     int len = 0;
-    LPWSTR wszText = ME_ToUnicode(unicode, (void *)lParam, &len);
+    LONG codepage = unicode ? CP_UNICODE : CP_ACP;
+    LPWSTR wszText = ME_ToUnicode(codepage, (void *)lParam, &len);
     TRACE("EM_REPLACESEL - %s\n", debugstr_w(wszText));
 
     nStartCursor = ME_GetSelectionOfs(editor, &from, &to);
@@ -3519,7 +3519,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);
+    ME_EndToUnicode(codepage, wszText);
     ME_CommitUndo(editor);
     ME_UpdateSelectionLinkAttribute(editor);
     if (!wParam)
@@ -3575,7 +3575,8 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
       else
       {
         int textLen;
-        LPWSTR wszText = ME_ToUnicode(unicode, (void *)lParam, &textLen);
+        LONG codepage = unicode ? CP_UNICODE : CP_ACP;
+        LPWSTR wszText = ME_ToUnicode(codepage, (void *)lParam, &textLen);
         TRACE("WM_SETTEXT - %s\n", debugstr_w(wszText)); /* debugstr_w() */
         if (textLen > 0)
         {
@@ -3592,7 +3593,7 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
           }
           ME_InsertTextFromCursor(editor, 0, wszText, len, editor->pBuffer->pDefaultStyle);
         }
-        ME_EndToUnicode(unicode, wszText);
+        ME_EndToUnicode(codepage, wszText);
       }
     }
     else
@@ -3640,7 +3641,7 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
 
     /* CR/LF conversion required in 2.0 mode, verbatim in 1.0 mode */
     how.flags = GTL_CLOSE | (editor->bEmulateVersion10 ? 0 : GTL_USECRLF) | GTL_NUMCHARS;
-    how.codepage = unicode ? 1200 : CP_ACP;
+    how.codepage = unicode ? CP_UNICODE : CP_ACP;
     return ME_GetTextLengthEx(editor, &how);
   }
   case EM_GETTEXTLENGTHEX:
@@ -3650,7 +3651,7 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
     GETTEXTEX ex;
     ex.cb = wParam * (unicode ? sizeof(WCHAR) : sizeof(CHAR));
     ex.flags = GT_USECRLF;
-    ex.codepage = unicode ? 1200 : CP_ACP;
+    ex.codepage = unicode ? CP_UNICODE : CP_ACP;
     ex.lpDefaultChar = NULL;
     ex.lpUsedDefChar = NULL;
     return ME_GetTextEx(editor, &ex, lParam);
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index 5893051..69760c8 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -108,9 +108,10 @@ int ME_CallWordBreakProc(ME_TextEditor *editor, WCHAR *str, INT len, INT start,
 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;
 
+#define CP_UNICODE 1200
 /* smart helpers for A<->W conversions, they reserve/free memory and call MultiByte<->WideChar functions */
-LPWSTR ME_ToUnicode(BOOL unicode, LPVOID psz, INT *len) DECLSPEC_HIDDEN;
-void ME_EndToUnicode(BOOL unicode, LPVOID psz) DECLSPEC_HIDDEN;
+LPWSTR ME_ToUnicode(LONG codepage, LPVOID psz, INT *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 f4cd320..12e4ad7 100644
--- a/dlls/riched20/string.c
+++ b/dlls/riched20/string.c
@@ -172,30 +172,30 @@ ME_CallWordBreakProc(ME_TextEditor *editor, WCHAR *str, INT len, INT start, INT
   }
 }
 
-LPWSTR ME_ToUnicode(BOOL unicode, LPVOID psz, INT *len)
+LPWSTR ME_ToUnicode(LONG codepage, LPVOID psz, INT *len)
 {
   *len = 0;
   if (!psz) return NULL;
 
-  if (unicode)
+  if (codepage == CP_UNICODE)
   {
     *len = lstrlenW(psz);
     return psz;
   }
   else {
     WCHAR *tmp;
-    int nChars = MultiByteToWideChar(CP_ACP, 0, psz, -1, NULL, 0);
+    int nChars = MultiByteToWideChar(codepage, 0, psz, -1, NULL, 0);
 
     if(!nChars) return NULL;
 
     if((tmp = ALLOC_N_OBJ(WCHAR, nChars)) != NULL)
-      *len = MultiByteToWideChar(CP_ACP, 0, psz, -1, tmp, nChars) - 1;
+      *len = MultiByteToWideChar(codepage, 0, psz, -1, tmp, nChars) - 1;
     return tmp;
   }
 }
 
-void ME_EndToUnicode(BOOL unicode, LPVOID psz)
+void ME_EndToUnicode(LONG codepage, LPVOID psz)
 {
-  if (!unicode)
+  if (codepage != CP_UNICODE)
     FREE_OBJ(psz);
 }
-- 
1.7.10.4


More information about the wine-patches mailing list