Commit 46ff4a6f authored by Alex Villacís Lasso's avatar Alex Villacís Lasso Committed by Alexandre Julliard

riched20: EM_SETTEXTEX supports RTF strings, with tests.

parent dfcebfb2
...@@ -115,7 +115,7 @@ ...@@ -115,7 +115,7 @@
+ EM_SETSCROLLPOS 3.0 + EM_SETSCROLLPOS 3.0
- EM_SETTABSTOPS 3.0 - EM_SETTABSTOPS 3.0
- EM_SETTARGETDEVICE (partial) - EM_SETTARGETDEVICE (partial)
+ EM_SETTEXTEX 3.0 (no rich text insertion handling, proper style?) + EM_SETTEXTEX 3.0 (proper style?)
- EM_SETTEXTMODE 2.0 - EM_SETTEXTMODE 2.0
- EM_SETTYPOGRAPHYOPTIONS 3.0 - EM_SETTYPOGRAPHYOPTIONS 3.0
+ EM_SETUNDOLIMIT 2.0 + EM_SETUNDOLIMIT 2.0
...@@ -2117,17 +2117,20 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, ...@@ -2117,17 +2117,20 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam,
wszText = lParam ? ME_ToUnicode(pStruct->codepage == 1200, (void *)lParam) : NULL; wszText = lParam ? ME_ToUnicode(pStruct->codepage == 1200, (void *)lParam) : NULL;
len = wszText ? lstrlenW(wszText) : 0; len = wszText ? lstrlenW(wszText) : 0;
/* FIXME: this should support RTF strings too, according to MSDN */
if (pStruct->flags & ST_SELECTION) { 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); ME_InternalDeleteText(editor, from, to - from);
ME_InsertTextFromCursor(editor, 0, wszText, len, style); if (pStruct->codepage != 1200 && lParam && !strncmp((char *)lParam, "{\\rtf", 5))
ME_StreamInRTFString(editor, 0, (char *)lParam);
else ME_InsertTextFromCursor(editor, 0, wszText, len, style);
ME_ReleaseStyle(style); ME_ReleaseStyle(style);
} }
else { else {
ME_InternalDeleteText(editor, 0, ME_GetTextLength(editor)); ME_InternalDeleteText(editor, 0, ME_GetTextLength(editor));
ME_InsertTextFromCursor(editor, 0, wszText, len, editor->pBuffer->pDefaultStyle); if (pStruct->codepage != 1200 && lParam && !strncmp((char *)lParam, "{\\rtf", 5))
ME_StreamInRTFString(editor, 0, (char *)lParam);
else ME_InsertTextFromCursor(editor, 0, wszText, len, editor->pBuffer->pDefaultStyle);
len = 1; len = 1;
} }
ME_CommitUndo(editor); ME_CommitUndo(editor);
......
...@@ -1041,6 +1041,20 @@ static void test_ES_PASSWORD(void) ...@@ -1041,6 +1041,20 @@ static void test_ES_PASSWORD(void)
DestroyWindow(hwndRichEdit); DestroyWindow(hwndRichEdit);
} }
static DWORD CALLBACK test_WM_SETTEXT_esCallback(DWORD_PTR dwCookie,
LPBYTE pbBuff,
LONG cb,
LONG *pcb)
{
char** str = (char**)dwCookie;
*pcb = cb;
if (*pcb > 0) {
memcpy(*str, pbBuff, *pcb);
*str += *pcb;
}
return 0;
}
static void test_WM_SETTEXT() static void test_WM_SETTEXT()
{ {
HWND hwndRichEdit = new_richedit(NULL); HWND hwndRichEdit = new_richedit(NULL);
...@@ -1057,8 +1071,11 @@ static void test_WM_SETTEXT() ...@@ -1057,8 +1071,11 @@ static void test_WM_SETTEXT()
const char * TestItem6_after = "TestSomeText \r\nTestSomeText"; const char * TestItem6_after = "TestSomeText \r\nTestSomeText";
const char * TestItem7 = "TestSomeText\r\n\r\r\n\rTestSomeText"; const char * TestItem7 = "TestSomeText\r\n\r\r\n\rTestSomeText";
const char * TestItem7_after = "TestSomeText\r\n \r\nTestSomeText"; const char * TestItem7_after = "TestSomeText\r\n \r\nTestSomeText";
char buf[1024] = {0}; char buf[1024] = {0};
LRESULT result; LRESULT result;
EDITSTREAM es;
char * p;
/* This test attempts to show that WM_SETTEXT on a riched20 control causes /* This test attempts to show that WM_SETTEXT on a riched20 control causes
any solitary \r to be converted to \r\n on return. Properly paired any solitary \r to be converted to \r\n on return. Properly paired
...@@ -1086,6 +1103,18 @@ static void test_WM_SETTEXT() ...@@ -1086,6 +1103,18 @@ static void test_WM_SETTEXT()
TEST_SETTEXT(TestItem6, TestItem6_after) TEST_SETTEXT(TestItem6, TestItem6_after)
TEST_SETTEXT(TestItem7, TestItem7_after) TEST_SETTEXT(TestItem7, TestItem7_after)
/* The following test demonstrates that WM_SETTEXT supports RTF strings */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) TestItem1);
p = buf;
es.dwCookie = (DWORD_PTR)&p;
es.dwError = 0;
es.pfnCallback = test_WM_SETTEXT_esCallback;
memset(buf, 0, sizeof(buf));
SendMessage(hwndRichEdit, EM_STREAMOUT,
(WPARAM)(SF_RTF), (LPARAM)&es);
trace("EM_STREAMOUT produced: \n%s\n", buf);
TEST_SETTEXT(buf, TestItem1)
#undef TEST_SETTEXT #undef TEST_SETTEXT
DestroyWindow(hwndRichEdit); DestroyWindow(hwndRichEdit);
} }
...@@ -1126,8 +1155,10 @@ static void test_EM_SETTEXTEX(void) ...@@ -1126,8 +1155,10 @@ static void test_EM_SETTEXTEX(void)
' ','\r', 0}; ' ','\r', 0};
#define MAX_BUF_LEN 1024 #define MAX_BUF_LEN 1024
WCHAR buf[MAX_BUF_LEN]; WCHAR buf[MAX_BUF_LEN];
char * p;
int result; int result;
CHARRANGE cr; CHARRANGE cr;
EDITSTREAM es;
setText.codepage = 1200; /* no constant for unicode */ setText.codepage = 1200; /* no constant for unicode */
getText.codepage = 1200; /* no constant for unicode */ getText.codepage = 1200; /* no constant for unicode */
...@@ -1274,6 +1305,31 @@ static void test_EM_SETTEXTEX(void) ...@@ -1274,6 +1305,31 @@ static void test_EM_SETTEXTEX(void)
"EM_SETTEXTEX to replace selection with more text failed: %i.\n", "EM_SETTEXTEX to replace selection with more text failed: %i.\n",
lstrlenW(buf) ); lstrlenW(buf) );
/* The following test demonstrates that EM_SETTEXTEX supports RTF strings */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) "TestSomeText"); /* TestItem1 */
p = (char *)buf;
es.dwCookie = (DWORD_PTR)&p;
es.dwError = 0;
es.pfnCallback = test_WM_SETTEXT_esCallback;
memset(buf, 0, sizeof(buf));
SendMessage(hwndRichEdit, EM_STREAMOUT,
(WPARAM)(SF_RTF), (LPARAM)&es);
trace("EM_STREAMOUT produced: \n%s\n", (char *)buf);
setText.codepage = CP_ACP;/* EM_STREAMOUT saved as ANSI string */
getText.codepage = 1200; /* no constant for unicode */
getText.cb = MAX_BUF_LEN;
getText.flags = GT_DEFAULT;
getText.lpDefaultChar = NULL;
getText.lpUsedDefChar = NULL;
setText.flags = 0;
SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM) buf);
SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buf);
ok(lstrcmpW(buf, TestItem1) == 0,
"EM_GETTEXTEX results not what was set by EM_SETTEXTEX\n");
DestroyWindow(hwndRichEdit); 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