[2/2] [try3] Richedit: fix bug 14280, EM_SETTEXTTEX obeys ST_SELECTION with RTF inputs

Dustin Brody ne4 at parsoma.net
Mon Jul 28 20:26:11 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/tests/editor.c |   85 ++++++++++++++++++++++++++++++++++++++----
 1 files changed, 77 insertions(+), 8 deletions(-)

diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c
index e6bc67f..15cef75 100644
--- a/dlls/riched20/tests/editor.c
+++ b/dlls/riched20/tests/editor.c
@@ -3180,6 +3180,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',
@@ -3208,6 +3214,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;
@@ -3227,7 +3234,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 */
@@ -3273,7 +3280,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;
@@ -3286,7 +3293,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;
@@ -3299,7 +3306,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;
@@ -3312,6 +3319,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);
@@ -3321,14 +3329,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);
@@ -3337,14 +3345,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);
@@ -3369,6 +3377,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;
@@ -3382,6 +3391,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