richedit: Added test for scroll position after EM_SETTEXTEX.

Dylan Smith dylan.ah.smith at gmail.com
Wed Jan 21 09:09:58 CST 2009


I encountered this odd case when testing a bug in the World of Warcraft
demo installer, where the scroll position was near the bottom of the
EULA instead of at the top.  This wasn't really an issue for that
application, but this may be annoying in another application, in which
case I hope the added tests will help.
---
 dlls/riched20/tests/editor.c |   74 +++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 73 insertions(+), 1 deletions(-)
-------------- next part --------------
diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c
index aa78e2a..244ab09 100644
--- a/dlls/riched20/tests/editor.c
+++ b/dlls/riched20/tests/editor.c
@@ -3345,7 +3345,9 @@ static void test_EM_STREAMOUT(void)
 
 static void test_EM_SETTEXTEX(void)
 {
-  HWND hwndRichEdit = new_richedit(NULL);
+  HWND hwndRichEdit, parent;
+  SCROLLINFO si;
+  int sel_start, sel_end;
   SETTEXTEX setText;
   GETTEXTEX getText;
   WCHAR TestItem1[] = {'T', 'e', 's', 't', 
@@ -3392,6 +3394,76 @@ static void test_EM_SETTEXTEX(void)
   int result;
   CHARRANGE cr;
   EDITSTREAM es;
+  WNDCLASSA cls;
+
+  /* Test the scroll position with and without a parent window.
+   *
+   * For some reason the scroll position is 0 after EM_SETTEXTEX
+   * with the ST_SELECTION flag only when the control has a parent
+   * window, even though the selection is at the end. */
+  cls.style = 0;
+  cls.lpfnWndProc = DefWindowProcA;
+  cls.cbClsExtra = 0;
+  cls.cbWndExtra = 0;
+  cls.hInstance = GetModuleHandleA(0);
+  cls.hIcon = 0;
+  cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
+  cls.hbrBackground = GetStockObject(WHITE_BRUSH);
+  cls.lpszMenuName = NULL;
+  cls.lpszClassName = "ParentTestClass";
+  if(!RegisterClassA(&cls)) assert(0);
+
+  parent = CreateWindow(cls.lpszClassName, NULL, WS_POPUP|WS_VISIBLE,
+                        0, 0, 200, 60, NULL, NULL, NULL, NULL);
+  ok (parent != 0, "Failed to create parent window\n");
+
+  hwndRichEdit = CreateWindowEx(0,
+                        RICHEDIT_CLASS, NULL,
+                        ES_MULTILINE|WS_VSCROLL|WS_VISIBLE|WS_CHILD,
+                        0, 0, 200, 60, parent, NULL,
+                        hmoduleRichEdit, NULL);
+
+  setText.codepage = CP_ACP;
+  setText.flags = ST_SELECTION;
+  SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText,
+              (LPARAM)"{\\rtf 1\\par 2\\par 3\\par 4\\par 5\\par 6\\par 7\\par 8\\par 9\\par}");
+  si.cbSize = sizeof(si);
+  si.fMask = SIF_ALL;
+  GetScrollInfo(hwndRichEdit, SB_VERT, &si);
+  todo_wine ok(si.nPos == 0, "Position is incorrectly at %d\n", si.nPos);
+  SendMessage(hwndRichEdit, EM_GETSEL, (WPARAM)&sel_start, (LPARAM)&sel_end);
+  ok(sel_start == 18, "Selection start incorrectly at %d\n", sel_start);
+  ok(sel_end == 18, "Selection end incorrectly at %d\n", sel_end);
+
+  DestroyWindow(parent);
+
+  /* Test without a parent window */
+  hwndRichEdit = new_richedit(NULL);
+  setText.codepage = CP_ACP;
+  setText.flags = ST_SELECTION;
+  SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText,
+              (LPARAM)"{\\rtf 1\\par 2\\par 3\\par 4\\par 5\\par 6\\par 7\\par 8\\par 9\\par}");
+  si.cbSize = sizeof(si);
+  si.fMask = SIF_ALL;
+  GetScrollInfo(hwndRichEdit, SB_VERT, &si);
+  ok(si.nPos != 0, "Position is incorrectly at %d\n", si.nPos);
+  SendMessage(hwndRichEdit, EM_GETSEL, (WPARAM)&sel_start, (LPARAM)&sel_end);
+  ok(sel_start == 18, "Selection start incorrectly at %d\n", sel_start);
+  ok(sel_end == 18, "Selection end incorrectly at %d\n", sel_end);
+
+  /* The scroll position should also be 0 after EM_SETTEXTEX with ST_DEFAULT,
+   * but this time it is because the selection is at the beginning. */
+  setText.codepage = CP_ACP;
+  setText.flags = ST_DEFAULT;
+  SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText,
+              (LPARAM)"{\\rtf 1\\par 2\\par 3\\par 4\\par 5\\par 6\\par 7\\par 8\\par 9\\par}");
+  si.cbSize = sizeof(si);
+  si.fMask = SIF_ALL;
+  GetScrollInfo(hwndRichEdit, SB_VERT, &si);
+  ok(si.nPos == 0, "Position is incorrectly at %d\n", si.nPos);
+  SendMessage(hwndRichEdit, EM_GETSEL, (WPARAM)&sel_start, (LPARAM)&sel_end);
+  ok(sel_start == 0, "Selection start incorrectly at %d\n", sel_start);
+  ok(sel_end == 0, "Selection end incorrectly at %d\n", sel_end);
 
   setText.codepage = 1200;  /* no constant for unicode */
   getText.codepage = 1200;  /* no constant for unicode */


More information about the wine-patches mailing list