riched20: implement EM_SCROLL and its tests
adlr at ucla.edu
adlr at ucla.edu
Sat Feb 18 13:06:23 CST 2006
My name is Andrew de los Reyes. I'm a resident of Los Angeles, CA,
USA, and I currently attend UCLA. I hereby certify that I wrote this
code without copying from anyone else's sources, and I've never seen
any secret Microsoft source code.
License: LGPL
---
ChangeLog:
Implement EM_SCROLL and its tests
---
editor.c | 46 +++++++++++++++++-
tests/editor.c | 143 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 188 insertions(+), 1 deletion(-)
diff -r -u wine/dlls/riched20/editor.c wine.good/dlls/riched20/editor.c
--- wine/dlls/riched20/editor.c 2006-02-14 23:15:03.000000000 -0800
+++ wine.good/dlls/riched20/editor.c 2006-02-15 16:53:09.000000000 -0800
@@ -1318,7 +1318,6 @@
UNSUPPORTED_MSG(EM_HIDESELECTION)
UNSUPPORTED_MSG(EM_LIMITTEXT) /* also known as EM_SETLIMITTEXT */
UNSUPPORTED_MSG(EM_PASTESPECIAL)
- UNSUPPORTED_MSG(EM_SCROLL)
UNSUPPORTED_MSG(EM_SCROLLCARET)
UNSUPPORTED_MSG(EM_SELECTIONTYPE)
UNSUPPORTED_MSG(EM_SETBIDIOPTIONS)
@@ -2055,6 +2054,51 @@
}
return 0;
}
+ case EM_SCROLL: /* partially copied from WM_VSCROLL */
+ {
+ int nEnd;
+ int nPos = editor->nScrollPosY;
+ int origNPos = editor->nScrollPosY;
+ int lineHeight = 24;
+ if (editor && editor->pBuffer && editor->pBuffer->pDefaultStyle)
+ lineHeight = editor->pBuffer->pDefaultStyle->tm.tmHeight;
+ if (lineHeight <= 0) lineHeight = 24;
+ switch(LOWORD(wParam)) {
+ case SB_LINEUP:
+ nPos -= lineHeight;
+ if (nPos<0) nPos = 0;
+ break;
+ case SB_LINEDOWN:
+ {
+ nEnd = editor->nTotalLength - editor->sizeWindow.cy;
+ if (nEnd < 0) nEnd = 0;
+ nPos += lineHeight;
+ if (nPos>=nEnd) nPos = nEnd;
+ break;
+ }
+ case SB_PAGEUP:
+ nPos -= editor->sizeWindow.cy;
+ if (nPos<0) nPos = 0;
+ break;
+ case SB_PAGEDOWN:
+ nEnd = editor->nTotalLength - editor->sizeWindow.cy;
+ if (nEnd < 0) nEnd = 0;
+ nPos += editor->sizeWindow.cy;
+ if (nPos>=nEnd) nPos = nEnd;
+ break;
+ }
+ if (nPos != editor->nScrollPosY) {
+ int dy = editor->nScrollPosY - nPos;
+ editor->nScrollPosY = nPos;
+ SetScrollPos(hWnd, SB_VERT, nPos, TRUE);
+ if (editor->bRedraw)
+ {
+ ScrollWindow(hWnd, 0, dy, NULL, NULL);
+ UpdateWindow(hWnd);
+ }
+ }
+ return 0x00010000 | (((nPos - origNPos)/lineHeight) & 0xffff);
+ }
case WM_VSCROLL:
{
int nPos = editor->nScrollPosY;
diff -r -u wine/dlls/riched20/tests/editor.c wine.good/dlls/riched20/tests/editor.c
--- wine/dlls/riched20/tests/editor.c 2006-02-11 11:40:52.000000000 -0800
+++ wine.good/dlls/riched20/tests/editor.c 2006-02-15 16:51:56.000000000 -0800
@@ -157,6 +157,148 @@
DestroyWindow(hwndRichEdit);
}
+static void test_EM_SCROLL()
+{
+ int i, j;
+ int r; /* return value */
+ int expr; /* expected return value */
+ HWND hwndRichEdit = new_richedit(NULL);
+ int y_before, y_after; /* units of lines of text */
+
+ /* test a richedit box containing a single line of text */
+ SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) "a");/* one line of text */
+ expr = 0x00010000;
+ for (i = 0; i < 4; i++) {
+ int cmd;
+ switch (i) {
+ case 0: cmd = SB_PAGEDOWN; break;
+ case 1: cmd = SB_PAGEUP; break;
+ case 2: cmd = SB_LINEDOWN; break;
+ case 3: cmd = SB_LINEUP; break;
+ }
+
+ r = SendMessage(hwndRichEdit, EM_SCROLL, cmd, 0);
+ y_after = SendMessage(hwndRichEdit, EM_GETFIRSTVISIBLELINE, 0, 0);
+ ok(expr == r, "EM_SCROLL improper return value returned (i == %d). "
+ "Got 0x%08x, expected 0x%08x\n", i, r, expr);
+ ok(y_after == 0, "EM_SCROLL improper scroll. scrolled to line %d, not 1 "
+ "(i == %d)\n", y_after, i);
+ }
+
+ /*
+ * test a richedit box that will scroll. There are two general
+ * cases: the case without any long lines and the case with a long
+ * line.
+ */
+ for (i = 0; i < 2; i++) { /* iterate through different bodies of text */
+ if (i == 0)
+ SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) "a\nb\nc\nd\ne");
+ else
+ SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)
+ "a LONG LINE LONG LINE LONG LINE LONG LINE LONG LINE "
+ "LONG LINE LONG LINE LONG LINE LONG LINE LONG LINE "
+ "LONG LINE \nb\nc\nd\ne");
+ for (j = 0; j < 12; j++) /* reset scrol position to top */
+ SendMessage(hwndRichEdit, EM_SCROLL, SB_PAGEUP, 0);
+
+ /* get first visible line */
+ y_before = SendMessage(hwndRichEdit, EM_GETFIRSTVISIBLELINE, 0, 0);
+ r = SendMessage(hwndRichEdit, EM_SCROLL, SB_PAGEDOWN, 0); /* page down */
+
+ /* get new current first visible line */
+ y_after = SendMessage(hwndRichEdit, EM_GETFIRSTVISIBLELINE, 0, 0);
+
+ ok(((r & 0xffffff00) == 0x00010000) &&
+ ((r & 0x000000ff) != 0x00000000),
+ "EM_SCROLL page down didn't scroll by a small positive number of "
+ "lines (r == 0x%08x)\n", r);
+ ok(y_after > y_before, "EM_SCROLL page down not functioning "
+ "(line %d scrolled to line %d\n", y_before, y_after);
+
+ y_before = y_after;
+
+ r = SendMessage(hwndRichEdit, EM_SCROLL, SB_PAGEUP, 0); /* page up */
+ y_after = SendMessage(hwndRichEdit, EM_GETFIRSTVISIBLELINE, 0, 0);
+ ok(((r & 0xffffff00) == 0x0001ff00),
+ "EM_SCROLL page up didn't scroll by a small negative number of lines "
+ "(r == 0x%08x)\n", r);
+ ok(y_after < y_before, "EM_SCROLL page up not functioning (line "
+ "%d scrolled to line %d\n", y_before, y_after);
+
+ y_before = y_after;
+
+ r = SendMessage(hwndRichEdit, EM_SCROLL, SB_LINEDOWN, 0); /* line down */
+
+ y_after = SendMessage(hwndRichEdit, EM_GETFIRSTVISIBLELINE, 0, 0);
+
+ ok(r == 0x00010001, "EM_SCROLL line down didn't scroll by one line "
+ "(r == 0x%08x)\n", r);
+ ok(y_after -1 == y_before, "EM_SCROLL line down didn't go down by "
+ "1 line (%d scrolled to %d)\n", y_before, y_after);
+
+ y_before = y_after;
+
+ r = SendMessage(hwndRichEdit, EM_SCROLL, SB_LINEUP, 0); /* line up */
+
+ y_after = SendMessage(hwndRichEdit, EM_GETFIRSTVISIBLELINE, 0, 0);
+
+ ok(r == 0x0001ffff, "EM_SCROLL line up didn't scroll by one line "
+ "(r == 0x%08x)\n", r);
+ ok(y_after +1 == y_before, "EM_SCROLL line up didn't go up by 1 "
+ "line (%d scrolled to %d)\n", y_before, y_after);
+
+ y_before = y_after;
+
+ r = SendMessage(hwndRichEdit, EM_SCROLL,
+ SB_LINEUP, 0); /* lineup beyond top */
+
+ y_after = SendMessage(hwndRichEdit, EM_GETFIRSTVISIBLELINE, 0, 0);
+
+ ok(r == 0x00010000,
+ "EM_SCROLL line up returned indicating movement (0x%08x)\n", r);
+ ok(y_before == y_after,
+ "EM_SCROLL line up beyond top worked (%d)\n", y_after);
+
+ y_before = y_after;
+
+ r = SendMessage(hwndRichEdit, EM_SCROLL,
+ SB_PAGEUP, 0);/*page up beyond top */
+
+ y_after = SendMessage(hwndRichEdit, EM_GETFIRSTVISIBLELINE, 0, 0);
+
+ ok(r == 0x00010000,
+ "EM_SCROLL page up returned indicating movement (0x%08x)\n", r);
+ ok(y_before == y_after,
+ "EM_SCROLL page up beyond top worked (%d)\n", y_after);
+
+ for (j = 0; j < 12; j++) /* page down all the way to the bottom */
+ SendMessage(hwndRichEdit, EM_SCROLL, SB_PAGEDOWN, 0);
+ y_before = SendMessage(hwndRichEdit, EM_GETFIRSTVISIBLELINE, 0, 0);
+ r = SendMessage(hwndRichEdit, EM_SCROLL,
+ SB_PAGEDOWN, 0); /* page down beyond bot */
+ y_after = SendMessage(hwndRichEdit, EM_GETFIRSTVISIBLELINE, 0, 0);
+
+ ok(r == 0x00010000,
+ "EM_SCROLL page down returned indicating movement (0x%08x)\n", r);
+ ok(y_before == y_after,
+ "EM_SCROLL page down beyond bottom worked (%d -> %d)\n",
+ y_before, y_after);
+
+ y_before = SendMessage(hwndRichEdit, EM_GETFIRSTVISIBLELINE, 0, 0);
+ SendMessage(hwndRichEdit, EM_SCROLL,
+ SB_LINEDOWN, 0); /* line down beyond bot */
+ y_after = SendMessage(hwndRichEdit, EM_GETFIRSTVISIBLELINE, 0, 0);
+
+ ok(r == 0x00010000,
+ "EM_SCROLL line down returned indicating movement (0x%08x)\n", r);
+ ok(y_before == y_after,
+ "EM_SCROLL line down beyond bottom worked (%d -> %d)\n",
+ y_before, y_after);
+ }
+ DestroyWindow(hwndRichEdit);
+}
+
+
START_TEST( editor )
{
MSG msg;
@@ -169,6 +311,7 @@
test_EM_FINDTEXT();
test_EM_FINDTEXTEX();
+ test_EM_SCROLL();
/* Set the environment variable WINETEST_RICHED20 to keep windows
* responsive and open for 30 seconds. This is useful for debugging.
More information about the wine-patches
mailing list