Commit 88214a58 authored by Jactry Zeng's avatar Jactry Zeng Committed by Alexandre Julliard

riched20: Add UTF8 support for EM_SETTEXTEX.

parent eb8f4751
......@@ -3329,8 +3329,9 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
SETTEXTEX *pStruct = (SETTEXTEX *)wParam;
int from, to, len;
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;
......@@ -3339,6 +3340,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),
......@@ -3364,9 +3366,15 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
len = lParam ? strlen((char *)lParam) : 0;
}
} else {
wszText = ME_ToUnicode(pStruct->codepage, (void *)lParam, &len);
ME_InsertTextFromCursor(editor, 0, wszText, len, style);
ME_EndToUnicode(pStruct->codepage, wszText);
if (bUTF8 && !bUnicode) {
wszText = ME_ToUnicode(CP_UTF8, (void *)(lParam+3), &len);
ME_InsertTextFromCursor(editor, 0, wszText, len, style);
ME_EndToUnicode(CP_UTF8, wszText);
} else {
wszText = ME_ToUnicode(pStruct->codepage, (void *)lParam, &len);
ME_InsertTextFromCursor(editor, 0, wszText, len, style);
ME_EndToUnicode(pStruct->codepage, wszText);
}
}
if (bSelection) {
......
......@@ -3901,17 +3901,17 @@ static void test_EM_SETTEXTEX(void)
setText.codepage = CP_ACP;
SendMessageA(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM)"\xef\xbb\xbfTestUTF8WithBOM");
result = SendMessageA(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;
SendMessageA(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM)"\xef\xbb\xbfTestUTF8WithBOM");
result = SendMessageA(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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment