richedit: EM_SETTEXTEX detects ascii richtext with Unicode codepage.
This commit is contained in:
parent
164778452c
commit
b4babc16bb
@ -3208,42 +3208,56 @@ static LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
|
|||||||
{
|
{
|
||||||
LPWSTR wszText;
|
LPWSTR wszText;
|
||||||
SETTEXTEX *pStruct = (SETTEXTEX *)wParam;
|
SETTEXTEX *pStruct = (SETTEXTEX *)wParam;
|
||||||
size_t len;
|
size_t len = 0;
|
||||||
int from, to;
|
int from, to;
|
||||||
ME_Style *style;
|
ME_Style *style;
|
||||||
|
BOOL bRtf, bUnicode, bSelection;
|
||||||
int oldModify = editor->nModifyStep;
|
int oldModify = editor->nModifyStep;
|
||||||
|
|
||||||
if (!pStruct) return 0;
|
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",
|
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);
|
pStruct->flags, pStruct->codepage);
|
||||||
|
|
||||||
/* FIXME: make use of pStruct->codepage in the to unicode translation */
|
bSelection = (pStruct->flags & ST_SELECTION) != 0;
|
||||||
wszText = lParam ? ME_ToUnicode(pStruct->codepage == 1200, (void *)lParam) : NULL;
|
if (bSelection) {
|
||||||
len = wszText ? lstrlenW(wszText) : 0;
|
|
||||||
|
|
||||||
if (pStruct->flags & ST_SELECTION) {
|
|
||||||
ME_GetSelection(editor, &from, &to);
|
ME_GetSelection(editor, &from, &to);
|
||||||
style = ME_GetSelectionInsertStyle(editor);
|
style = ME_GetSelectionInsertStyle(editor);
|
||||||
ME_InternalDeleteText(editor, from, to - from, FALSE);
|
ME_InternalDeleteText(editor, from, to - from, FALSE);
|
||||||
if (pStruct->codepage != 1200 && lParam &&
|
} else {
|
||||||
(!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);
|
|
||||||
|
|
||||||
if (editor->AutoURLDetect_bEnable) ME_UpdateSelectionLinkAttribute(editor);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ME_InternalDeleteText(editor, 0, ME_GetTextLength(editor), FALSE);
|
ME_InternalDeleteText(editor, 0, ME_GetTextLength(editor), FALSE);
|
||||||
if (pStruct->codepage != 1200 && lParam &&
|
style = editor->pBuffer->pDefaultStyle;
|
||||||
(!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 (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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
ME_CommitUndo(editor);
|
||||||
if (!(pStruct->flags & ST_KEEPUNDO))
|
if (!(pStruct->flags & ST_KEEPUNDO))
|
||||||
|
@ -3576,8 +3576,7 @@ static void test_EM_SETTEXTEX(void)
|
|||||||
result = SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM) "{\\rtf not unicode}");
|
result = SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM) "{\\rtf not unicode}");
|
||||||
todo_wine ok(result == 11, "EM_SETTEXTEX incorrectly returned %d\n", result);
|
todo_wine ok(result == 11, "EM_SETTEXTEX incorrectly returned %d\n", result);
|
||||||
SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) bufACP);
|
SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) bufACP);
|
||||||
todo_wine ok(lstrcmpA(bufACP, "not unicode") == 0,
|
ok(lstrcmpA(bufACP, "not unicode") == 0, "'%s' != 'not unicode'\n", bufACP);
|
||||||
"'%s' != 'not unicode'\n", bufACP);
|
|
||||||
|
|
||||||
/* The following test demonstrates that EM_SETTEXTEX supports RTF strings with a selection */
|
/* The following test demonstrates that EM_SETTEXTEX supports RTF strings with a selection */
|
||||||
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) "TestSomeText"); /* TestItem1 */
|
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) "TestSomeText"); /* TestItem1 */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user