[2/2] richedit: EM_SETTEXTEX detects ascii richtext with unicode codepage. (Fixes Bug 6661)
Dylan Smith
dylan.ah.smith at gmail.com
Fri Jan 16 19:38:24 CST 2009
---
dlls/riched20/editor.c | 56 ++++++++++++++++++++++++++---------------
dlls/riched20/tests/editor.c | 3 +-
2 files changed, 36 insertions(+), 23 deletions(-)
-------------- next part --------------
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index b67ca60..e3920d4 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -3208,42 +3208,56 @@ static LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
{
LPWSTR wszText;
SETTEXTEX *pStruct = (SETTEXTEX *)wParam;
- size_t len;
+ size_t len = 0;
int from, to;
ME_Style *style;
+ BOOL bRtf, bUnicode, bSelection;
int oldModify = editor->nModifyStep;
if (!pStruct) return 0;
+ /* If we detect ascii rtf at the start of the string,
+ * we know it isn't unicode. */
+ bRtf = (lParam && (!strncmp((char *)lParam, "{\\rtf", 5) ||
+ !strncmp((char *)lParam, "{\\urtf}", 6)));
+ bUnicode = !bRtf && pStruct->codepage == 1200;
+
TRACE("EM_SETTEXTEX - %s, flags %d, cp %d\n",
- pStruct->codepage == 1200 ? debugstr_w((LPCWSTR)lParam) : debugstr_a((LPCSTR)lParam),
+ bUnicode ? debugstr_w((LPCWSTR)lParam) : debugstr_a((LPCSTR)lParam),
pStruct->flags, pStruct->codepage);
- /* FIXME: make use of pStruct->codepage in the to unicode translation */
- wszText = lParam ? ME_ToUnicode(pStruct->codepage == 1200, (void *)lParam) : NULL;
- len = wszText ? lstrlenW(wszText) : 0;
-
- if (pStruct->flags & ST_SELECTION) {
+ bSelection = (pStruct->flags & ST_SELECTION) != 0;
+ if (bSelection) {
ME_GetSelection(editor, &from, &to);
style = ME_GetSelectionInsertStyle(editor);
ME_InternalDeleteText(editor, from, to - from, FALSE);
- if (pStruct->codepage != 1200 && lParam &&
- (!strncmp((char *)lParam, "{\\rtf", 5) || !strncmp((char *)lParam, "{\\urtf}", 6)))
- ME_StreamInRTFString(editor, 1, (char *)lParam);
- else ME_InsertTextFromCursor(editor, 0, wszText, len, style);
- ME_ReleaseStyle(style);
+ } else {
+ ME_InternalDeleteText(editor, 0, ME_GetTextLength(editor), FALSE);
+ style = editor->pBuffer->pDefaultStyle;
+ }
- if (editor->AutoURLDetect_bEnable) ME_UpdateSelectionLinkAttribute(editor);
+ if (bRtf) {
+ ME_StreamInRTFString(editor, bSelection, (char *)lParam);
+ if (bSelection) {
+ /* FIXME: The length returned is doesn't include the rtf control
+ * characters, only the actual text. */
+ 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;
+ ME_InsertTextFromCursor(editor, 0, wszText, len, style);
}
- else {
- ME_InternalDeleteText(editor, 0, ME_GetTextLength(editor), FALSE);
- if (pStruct->codepage != 1200 && lParam &&
- (!strncmp((char *)lParam, "{\\rtf", 5) || !strncmp((char *)lParam, "{\\urtf}", 6)))
- ME_StreamInRTFString(editor, 0, (char *)lParam);
- else ME_InsertTextFromCursor(editor, 0, wszText, len, editor->pBuffer->pDefaultStyle);
- len = 1;
- if (editor->AutoURLDetect_bEnable) ME_UpdateLinkAttribute(editor, 0, -1);
+ if (bSelection) {
+ ME_ReleaseStyle(style);
+ if (editor->AutoURLDetect_bEnable)
+ ME_UpdateSelectionLinkAttribute(editor);
+ } else {
+ len = 1;
+ if (editor->AutoURLDetect_bEnable)
+ ME_UpdateLinkAttribute(editor, 0, -1);
}
ME_CommitUndo(editor);
if (!(pStruct->flags & ST_KEEPUNDO))
diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c
index 2cf9a10..1d5a04d 100644
--- a/dlls/riched20/tests/editor.c
+++ b/dlls/riched20/tests/editor.c
@@ -3576,8 +3576,7 @@ static void test_EM_SETTEXTEX(void)
result = SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM) "{\\rtf not unicode}");
todo_wine ok(result == 11, "EM_SETTEXTEX incorrectly returned %d\n", result);
SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) bufACP);
- todo_wine ok(lstrcmpA(bufACP, "not unicode") == 0,
- "'%s' != 'not unicode'\n", bufACP);
+ ok(lstrcmpA(bufACP, "not unicode") == 0, "'%s' != 'not unicode'\n", bufACP);
/* The following test demonstrates that EM_SETTEXTEX supports RTF strings with a selection */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) "TestSomeText"); /* TestItem1 */
More information about the wine-patches
mailing list