From: Jactry Zeng Subject: [PATCH 4/4] riched20: Add UTF8 support for EM_SETTEXTEX. (try 4) Message-Id: <5229ABC5.6040604@gmail.com> Date: Fri, 06 Sep 2013 18:17:41 +0800 From 40bc918c5c435e59125ded17ffd670a0b5e37183 Mon Sep 17 00:00:00 2001 From: Jactry Zeng Date: Fri, 6 Sep 2013 11:05:29 +0800 Subject: [PATCH 4/4] riched20: Add UTF8 support for EM_SETTEXTEX. To: wine-patches Reply-To: wine-devel --- dlls/riched20/editor.c | 8 +++++++- dlls/riched20/tests/editor.c | 8 ++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c index 819eb64..6a1be45 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, int 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 == CP_UNICODE; + 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,6 +3316,10 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, len = lParam ? strlen((char *)lParam) : 0; } } else { + if(bUTF8) { + lParam = lParam + 3; + pStruct->codepage = CP_UTF8; + } wszText = lParam ? ME_ToUnicode(pStruct->codepage, (void *)lParam, &len) : NULL; ME_InsertTextFromCursor(editor, 0, wszText, len, style); ME_EndToUnicode(pStruct->codepage, wszText); diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c index 15e1132..426f16a 100644 --- a/dlls/riched20/tests/editor.c +++ b/dlls/riched20/tests/editor.c @@ -3918,17 +3918,17 @@ static void test_EM_SETTEXTEX(void) setText.codepage = CP_ACP; SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM)"\xef\xbb\xbfTestUTF8WithBOM"); result = SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM)bufACP); - todo_wine ok(result == 15, "EM_SETTEXTEX: Test UTF8 with BOM returned %d, expected 15\n", result); + ok(result == 15, "EM_SETTEXTEX: Test UTF8 with BOM returned %d, expected 15\n", result); result = strcmp(bufACP, "TestUTF8WithBOM"); - todo_wine ok(result == 0, "EM_SETTEXTEX: Test UTF8 with BOM set wrong text: Result: %s\n", bufACP); + ok(result == 0, "EM_SETTEXTEX: Test UTF8 with BOM set wrong text: Result: %s\n", bufACP); setText.flags = 0; setText.codepage = CP_UTF8; SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM)"\xef\xbb\xbfTestUTF8WithBOM"); result = SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM)bufACP); - todo_wine ok(result == 15, "EM_SETTEXTEX: Test UTF8 with BOM returned %d, expected 15\n", result); + ok(result == 15, "EM_SETTEXTEX: Test UTF8 with BOM returned %d, expected 15\n", result); result = strcmp(bufACP, "TestUTF8WithBOM"); - todo_wine ok(result == 0, "EM_SETTEXTEX: Test UTF8 with BOM set wrong text: Result: %s\n", bufACP); + ok(result == 0, "EM_SETTEXTEX: Test UTF8 with BOM set wrong text: Result: %s\n", bufACP); DestroyWindow(hwndRichEdit); } -- 1.7.10.4