Richedit: fix bug 14280, EM_SETTEXTTEX obeys ST_SELECTION with RTF inputs
Dustin Brody
ne4 at parsoma.net
Wed Jul 23 04:48:42 CDT 2008
* Richedit: fix bug 14280, EM_SETTEXTTEX obeys ST_SELECTION with RTF inputs
EM_SETTEXTEX which supposedly obeys ST_SELECTION (see
http://msdn.microsoft.com/en-us/library/bb787954(VS.85).aspx ) but
the EM_SETTEXTEX handler ignores it, calling
ME_StreamInRTFString(editor, 0, (char *)lParam);" either way, which
via ME_StreamInRTFString causes ME_StreamIn to delete the entire
buffer and not just just that one selection. This patch fixes that
behaviour by calling ME_StreamInRTFString to trigger SFF_SELECTION
being passed to ME_StreamIn.
I have checked that Windows XP does obey the ST_SELECTION flag as
documented by MSDN.
---
dlls/riched20/editor.c | 2 +-
dlls/riched20/tests/editor.c | 85 ++++++++++++++++++++++++++++++++++++++----
2 files changed, 78 insertions(+), 9 deletions(-)
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index 2dd758a..5a44747 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -2301,7 +2301,7 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam,
style = ME_GetSelectionInsertStyle(editor);
ME_InternalDeleteText(editor, from, to - from);
if (pStruct->codepage != 1200 && lParam && !strncmp((char *)lParam, "{\\rtf", 5))
- ME_StreamInRTFString(editor, 0, (char *)lParam);
+ ME_StreamInRTFString(editor, 1, (char *)lParam);
else ME_InsertTextFromCursor(editor, 0, wszText, len, style);
ME_ReleaseStyle(style);
diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c
index 8a55197..2821891 100644
--- a/dlls/riched20/tests/editor.c
+++ b/dlls/riched20/tests/editor.c
@@ -2458,6 +2458,12 @@ static void test_EM_SETTEXTEX(void)
WCHAR TestItem1[] = {'T', 'e', 's', 't',
'S', 'o', 'm', 'e',
'T', 'e', 'x', 't', 0};
+ WCHAR TestItem1alt[] = {'T', 'T', 'e', 's',
+ 't', 'S', 'o', 'm',
+ 'e', 'T', 'e', 'x',
+ 't', 't', 'S', 'o',
+ 'm', 'e', 'T', 'e',
+ 'x', 't', 0};
WCHAR TestItem2[] = {'T', 'e', 's', 't',
'S', 'o', 'm', 'e',
'T', 'e', 'x', 't',
@@ -2486,6 +2492,7 @@ static void test_EM_SETTEXTEX(void)
' ','\r', 0};
#define MAX_BUF_LEN 1024
WCHAR buf[MAX_BUF_LEN];
+ char bufACP[MAX_BUF_LEN];
char * p;
int result;
CHARRANGE cr;
@@ -2505,7 +2512,7 @@ static void test_EM_SETTEXTEX(void)
"EM_GETTEXTEX results not what was set by EM_SETTEXTEX\n");
/* Unlike WM_SETTEXT/WM_GETTEXT pair, EM_SETTEXTEX/EM_GETTEXTEX does not
- convert \r to \r\n on return
+ convert \r to \r\n on return: !ST_SELECTION && Unicode && !\rtf
*/
setText.codepage = 1200; /* no constant for unicode */
getText.codepage = 1200; /* no constant for unicode */
@@ -2551,7 +2558,7 @@ static void test_EM_SETTEXTEX(void)
"EM_GETTEXTEX results not what was set by EM_SETTEXTEX\n");
- /* \r\n pairs get changed into \r */
+ /* \r\n pairs get changed into \r: !ST_SELECTION && Unicode && !\rtf */
setText.codepage = 1200; /* no constant for unicode */
getText.codepage = 1200; /* no constant for unicode */
getText.cb = MAX_BUF_LEN;
@@ -2564,7 +2571,7 @@ static void test_EM_SETTEXTEX(void)
ok(lstrcmpW(buf, TestItem3_after) == 0,
"EM_SETTEXTEX did not convert properly\n");
- /* \n also gets changed to \r */
+ /* \n also gets changed to \r: !ST_SELECTION && Unicode && !\rtf */
setText.codepage = 1200; /* no constant for unicode */
getText.codepage = 1200; /* no constant for unicode */
getText.cb = MAX_BUF_LEN;
@@ -2577,7 +2584,7 @@ static void test_EM_SETTEXTEX(void)
ok(lstrcmpW(buf, TestItem3_after) == 0,
"EM_SETTEXTEX did not convert properly\n");
- /* \r\r\n gets changed into single space */
+ /* \r\r\n gets changed into single space: !ST_SELECTION && Unicode && !\rtf */
setText.codepage = 1200; /* no constant for unicode */
getText.codepage = 1200; /* no constant for unicode */
getText.cb = MAX_BUF_LEN;
@@ -2590,6 +2597,7 @@ static void test_EM_SETTEXTEX(void)
ok(lstrcmpW(buf, TestItem4_after) == 0,
"EM_SETTEXTEX did not convert properly\n");
+ /* !ST_SELECTION && Unicode && !\rtf */
result = SendMessage(hwndRichEdit, EM_SETTEXTEX,
(WPARAM)&setText, (LPARAM) NULL);
SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buf);
@@ -2599,14 +2607,14 @@ static void test_EM_SETTEXTEX(void)
ok(lstrlenW(buf) == 0,
"EM_SETTEXTEX with NULL lParam should clear rich edit.\n");
- /* put some text back */
+ /* put some text back: !ST_SELECTION && Unicode && !\rtf */
setText.flags = 0;
SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM) TestItem1);
/* select some text */
cr.cpMax = 1;
cr.cpMin = 3;
SendMessage(hwndRichEdit, EM_EXSETSEL, 0, (LPARAM) &cr);
- /* replace current selection */
+ /* replace current selection: ST_SELECTION && Unicode && !\rtf */
setText.flags = ST_SELECTION;
result = SendMessage(hwndRichEdit, EM_SETTEXTEX,
(WPARAM)&setText, (LPARAM) NULL);
@@ -2615,14 +2623,14 @@ static void test_EM_SETTEXTEX(void)
" with no text should return 0. Got %i\n",
result);
- /* put some text back */
+ /* put some text back: !ST_SELECTION && Unicode && !\rtf */
setText.flags = 0;
SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM) TestItem1);
/* select some text */
cr.cpMax = 1;
cr.cpMin = 3;
SendMessage(hwndRichEdit, EM_EXSETSEL, 0, (LPARAM) &cr);
- /* replace current selection */
+ /* replace current selection: ST_SELECTION && Unicode && !\rtf */
setText.flags = ST_SELECTION;
result = SendMessage(hwndRichEdit, EM_SETTEXTEX,
(WPARAM)&setText, (LPARAM) TestItem1);
@@ -2647,6 +2655,7 @@ static void test_EM_SETTEXTEX(void)
(WPARAM)(SF_RTF), (LPARAM)&es);
trace("EM_STREAMOUT produced: \n%s\n", (char *)buf);
+ /* !ST_SELECTION && !Unicode && \rtf */
setText.codepage = CP_ACP;/* EM_STREAMOUT saved as ANSI string */
getText.codepage = 1200; /* no constant for unicode */
getText.cb = MAX_BUF_LEN;
@@ -2660,6 +2669,66 @@ static void test_EM_SETTEXTEX(void)
ok(lstrcmpW(buf, TestItem1) == 0,
"EM_GETTEXTEX results not what was set by EM_SETTEXTEX\n");
+ /* The following test demonstrates that EM_SETTEXTEX supports RTF strings with a selection */
+ 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);
+
+ /* select some text */
+ cr.cpMax = 1;
+ cr.cpMin = 3;
+ SendMessage(hwndRichEdit, EM_EXSETSEL, 0, (LPARAM) &cr);
+
+ /* ST_SELECTION && !Unicode && \rtf */
+ 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 = ST_SELECTION;
+ SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM) buf);
+ SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buf);
+ ok(lstrcmpW(buf, TestItem1alt) == 0,
+ "EM_GETTEXTEX results not what was set by EM_SETTEXTEX when"
+ " using ST_SELECTION on an RTF string and non-Unicode\n");
+
+ /* The following test demonstrates that EM_SETTEXTEX replacing a selection */
+ setText.codepage = 1200; /* no constant for unicode */
+ getText.codepage = CP_ACP;
+ getText.cb = MAX_BUF_LEN;
+
+ setText.flags = 0;
+ SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM) TestItem1); /* TestItem1 */
+ SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) bufACP);
+
+ /* select some text */
+ cr.cpMax = 1;
+ cr.cpMin = 3;
+ SendMessage(hwndRichEdit, EM_EXSETSEL, 0, (LPARAM) &cr);
+
+ /* ST_SELECTION && !Unicode && !\rtf */
+ setText.codepage = CP_ACP;
+ getText.codepage = 1200; /* no constant for unicode */
+ getText.cb = MAX_BUF_LEN;
+ getText.flags = GT_DEFAULT;
+ getText.lpDefaultChar = NULL;
+ getText.lpUsedDefChar = NULL;
+
+ setText.flags = ST_SELECTION;
+ SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM) bufACP);
+ SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buf);
+ ok(lstrcmpW(buf, TestItem1alt) == 0,
+ "EM_GETTEXTEX results not what was set by EM_SETTEXTEX when"
+ " using ST_SELECTION and non-Unicode\n");
+
DestroyWindow(hwndRichEdit);
}
--
1.5.4.3
More information about the wine-patches
mailing list