[PATCH 1/4] riched20: Add the length return parameter. (try 4)

Jactry Zeng jactry92 at gmail.com
Fri Sep 6 05:17:25 CDT 2013


-------------- next part --------------
From 7663e5321b88b5581d235cb5ece836860389bbfa Mon Sep 17 00:00:00 2001
From: Jactry Zeng <jactry92 at gmail.com>
Date: Fri, 6 Sep 2013 10:46:10 +0800
Subject: [PATCH 1/4] riched20: Add the length return parameter.
To: wine-patches <wine-patches at winehq.org>
Reply-To: wine-devel <wine-devel at winehq.org>

---
 dlls/riched20/editor.c |   14 +++++++-------
 dlls/riched20/editor.h |    2 +-
 dlls/riched20/string.c |   13 ++++++++++++-
 3 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index f54458e..e4d0434 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -3276,7 +3276,7 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
   {
     LPWSTR wszText;
     SETTEXTEX *pStruct = (SETTEXTEX *)wParam;
-    size_t len = 0;
+    int len = 0;
     int from, to;
     ME_Style *style;
     BOOL bRtf, bUnicode, bSelection;
@@ -3315,8 +3315,7 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
       }
     } 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(bUnicode, (void *)lParam, &len) : NULL;
       ME_InsertTextFromCursor(editor, 0, wszText, len, style);
       ME_EndToUnicode(bUnicode, wszText);
     }
@@ -3505,8 +3504,8 @@ 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;
+    int len = 0;
+    LPWSTR wszText = lParam ? ME_ToUnicode(unicode, (void *)lParam, &len) : NULL;
     TRACE("EM_REPLACESEL - %s\n", debugstr_w(wszText));
 
     nStartCursor = ME_GetSelectionOfs(editor, &from, &to);
@@ -3576,9 +3575,10 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
       }
       else
       {
-        LPWSTR wszText = ME_ToUnicode(unicode, (void *)lParam);
+        int textLen;
+        LPWSTR wszText = ME_ToUnicode(unicode, (void *)lParam, &textLen);
         TRACE("WM_SETTEXT - %s\n", debugstr_w(wszText)); /* debugstr_w() */
-        if (lstrlenW(wszText) > 0)
+        if (textLen > 0)
         {
           int len = -1;
 
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index 8c78447..5893051 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -109,7 +109,7 @@ 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;
+LPWSTR ME_ToUnicode(BOOL unicode, LPVOID psz, INT *len) DECLSPEC_HIDDEN;
 void ME_EndToUnicode(BOOL unicode, 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..66c0cab 100644
--- a/dlls/riched20/string.c
+++ b/dlls/riched20/string.c
@@ -172,17 +172,28 @@ ME_CallWordBreakProc(ME_TextEditor *editor, WCHAR *str, INT len, INT start, INT
   }
 }
 
-LPWSTR ME_ToUnicode(BOOL unicode, LPVOID psz)
+LPWSTR ME_ToUnicode(BOOL unicode, LPVOID psz, INT *len)
 {
   assert(psz != NULL);
 
   if (unicode)
+  {
+    if(len) *len = lstrlenW(psz);
     return psz;
+  }
   else {
     WCHAR *tmp;
     int nChars = MultiByteToWideChar(CP_ACP, 0, psz, -1, NULL, 0);
+
+    if(!nChars)
+    {
+      if(len) *len = 0;
+      return NULL;
+    }
+
     if((tmp = ALLOC_N_OBJ(WCHAR, nChars)) != NULL)
       MultiByteToWideChar(CP_ACP, 0, psz, -1, tmp, nChars);
+    if(len) *len = nChars - 1;
     return tmp;
   }
 }
-- 
1.7.10.4


More information about the wine-patches mailing list