Module: wine Branch: master Commit: acec891ac292caf7330658ae6216f6ccda3df238 URL: http://source.winehq.org/git/wine.git/?a=commit;h=acec891ac292caf7330658ae62...
Author: Alex Villacís Lasso a_villacis@palosanto.com Date: Sat Jun 21 15:50:12 2008 -0500
richedit: EM_POSFROMCHAR should take into account scrollbar position. With tests.
---
dlls/riched20/editor.c | 9 ++++++ dlls/riched20/tests/editor.c | 55 +++++++++++++++++++++++++++++++++++++- dlls/riched32/tests/editor.c | 59 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 119 insertions(+), 4 deletions(-)
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c index 4d6cdd9..60db1bf 100644 --- a/dlls/riched20/editor.c +++ b/dlls/riched20/editor.c @@ -2899,6 +2899,7 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, ME_DisplayItem *pRun; int nCharOfs, nOffset, nLength; POINTL pt = {0,0}; + SCROLLINFO si;
nCharOfs = wParam; /* detect which API version we're dealing with */ @@ -2917,6 +2918,14 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, pt.y = editor->pBuffer->pLast->member.para.nYPos; } pt.x += editor->selofs; + + si.cbSize = sizeof(si); + si.fMask = SIF_POS; + if (GetScrollInfo(editor->hWnd, SB_VERT, &si)) pt.y -= si.nPos; + si.cbSize = sizeof(si); + si.fMask = SIF_POS; + if (GetScrollInfo(editor->hWnd, SB_HORZ, &si)) pt.x -= si.nPos; + if (wParam >= 0x40000) { *(POINTL *)wParam = pt; } diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c index d51da22..68e1d7e 100644 --- a/dlls/riched20/tests/editor.c +++ b/dlls/riched20/tests/editor.c @@ -400,10 +400,19 @@ static void test_EM_SCROLLCARET(void) static void test_EM_POSFROMCHAR(void) { HWND hwndRichEdit = new_richedit(NULL); - unsigned int i; + int i; LRESULT result; unsigned int height = 0; - unsigned int xpos = 0; + int xpos = 0; + static const char text[] = "aa\n" + "this is a long line of text that should be longer than the " + "control's width\n" + "cc\n" + "dd\n" + "ee\n" + "ff\n" + "gg\n" + "hh\n";
/* Fill the control to lines to ensure that most of them are offscreen */ for (i = 0; i < 50; i++) @@ -460,6 +469,48 @@ static void test_EM_POSFROMCHAR(void) ok(HIWORD(result) == 50 * height, "EM_POSFROMCHAR reports y=%d, expected %d\n", HIWORD(result), 50 * height); ok(LOWORD(result) == xpos, "EM_POSFROMCHAR reports x=%d, expected 1\n", LOWORD(result));
+ /* Testing that vertical scrolling does, in fact, have an effect on EM_POSFROMCHAR */ + SendMessage(hwndRichEdit, EM_SCROLL, SB_LINEDOWN, 0); /* line down */ + for (i = 0; i < 50; i++) + { + /* All the lines are 16 characters long */ + result = SendMessage(hwndRichEdit, EM_POSFROMCHAR, i * 16, 0); + ok((signed short)(HIWORD(result)) == (i - 1) * height, + "EM_POSFROMCHAR reports y=%hd, expected %d\n", + (signed short)(HIWORD(result)), (i - 1) * height); + ok(LOWORD(result) == xpos, "EM_POSFROMCHAR reports x=%d, expected 1\n", LOWORD(result)); + } + + /* Testing position at end of text */ + result = SendMessage(hwndRichEdit, EM_POSFROMCHAR, 50 * 16, 0); + ok(HIWORD(result) == (50 - 1) * height, "EM_POSFROMCHAR reports y=%d, expected %d\n", HIWORD(result), (50 - 1) * height); + ok(LOWORD(result) == xpos, "EM_POSFROMCHAR reports x=%d, expected 1\n", LOWORD(result)); + + /* Testing position way past end of text */ + result = SendMessage(hwndRichEdit, EM_POSFROMCHAR, 55 * 16, 0); + ok(HIWORD(result) == (50 - 1) * height, "EM_POSFROMCHAR reports y=%d, expected %d\n", HIWORD(result), (50 - 1) * height); + ok(LOWORD(result) == xpos, "EM_POSFROMCHAR reports x=%d, expected 1\n", LOWORD(result)); + + /* Testing that horizontal scrolling does, in fact, have an effect on EM_POSFROMCHAR */ + SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) text); + SendMessage(hwndRichEdit, EM_SCROLL, SB_LINEUP, 0); /* line up */ + + result = SendMessage(hwndRichEdit, EM_POSFROMCHAR, 0, 0); + ok(HIWORD(result) == 0, "EM_POSFROMCHAR reports y=%d, expected 0\n", HIWORD(result)); + todo_wine { + ok(LOWORD(result) == 1, "EM_POSFROMCHAR reports x=%d, expected 1\n", LOWORD(result)); + } + xpos = LOWORD(result); + + SendMessage(hwndRichEdit, WM_HSCROLL, SB_LINERIGHT, 0); + result = SendMessage(hwndRichEdit, EM_POSFROMCHAR, 0, 0); + ok(HIWORD(result) == 0, "EM_POSFROMCHAR reports y=%d, expected 0\n", HIWORD(result)); + todo_wine { + /* Fails on builtin because horizontal scrollbar is not being shown */ + ok((signed short)(LOWORD(result)) < xpos, + "EM_POSFROMCHAR reports x=%hd, expected value less than %d\n", + (signed short)(LOWORD(result)), xpos); + } DestroyWindow(hwndRichEdit); }
diff --git a/dlls/riched32/tests/editor.c b/dlls/riched32/tests/editor.c index 13e2245..63a63f1 100644 --- a/dlls/riched32/tests/editor.c +++ b/dlls/riched32/tests/editor.c @@ -699,11 +699,20 @@ static void test_EM_FINDTEXT(void) static void test_EM_POSFROMCHAR(void) { HWND hwndRichEdit = new_richedit(NULL); - unsigned int i; + int i; POINTL pl; LRESULT result; unsigned int height = 0; - unsigned int xpos = 0; + int xpos = 0; + static const char text[] = "aa\n" + "this is a long line of text that should be longer than the " + "control's width\n" + "cc\n" + "dd\n" + "ee\n" + "ff\n" + "gg\n" + "hh\n";
/* Fill the control to lines to ensure that most of them are offscreen */ for (i = 0; i < 50; i++) @@ -763,6 +772,52 @@ static void test_EM_POSFROMCHAR(void) ok(pl.y == 50 * height, "EM_POSFROMCHAR reports y=%d, expected %d\n", pl.y, 50 * height); ok(pl.x == xpos, "EM_POSFROMCHAR reports x=%d, expected 1\n", pl.x);
+ + /* Testing that vertical scrolling does, in fact, have an effect on EM_POSFROMCHAR */ + SendMessage(hwndRichEdit, EM_SCROLL, SB_LINEDOWN, 0); /* line down */ + for (i = 0; i < 50; i++) + { + /* All the lines are 16 characters long */ + result = SendMessage(hwndRichEdit, EM_POSFROMCHAR, (WPARAM)&pl, i * 16); + ok(result == 0, "EM_POSFROMCHAR returned %ld, expected 0\n", result); + ok(pl.y == (i - 1) * height, + "EM_POSFROMCHAR reports y=%d, expected %d\n", + pl.y, (i - 1) * height); + ok(pl.x == xpos, "EM_POSFROMCHAR reports x=%d, expected 1\n", pl.x); + } + + /* Testing position at end of text */ + result = SendMessage(hwndRichEdit, EM_POSFROMCHAR, (WPARAM)&pl, 50 * 16); + ok(result == 0, "EM_POSFROMCHAR returned %ld, expected 0\n", result); + ok(pl.y == (50 - 1) * height, "EM_POSFROMCHAR reports y=%d, expected %d\n", pl.y, (50 - 1) * height); + ok(pl.x == xpos, "EM_POSFROMCHAR reports x=%d, expected 1\n", pl.x); + + /* Testing position way past end of text */ + result = SendMessage(hwndRichEdit, EM_POSFROMCHAR, (WPARAM)&pl, 55 * 16); + ok(result == 0, "EM_POSFROMCHAR returned %ld, expected 0\n", result); + ok(pl.y == (50 - 1) * height, "EM_POSFROMCHAR reports y=%d, expected %d\n", pl.y, (50 - 1) * height); + ok(pl.x == xpos, "EM_POSFROMCHAR reports x=%d, expected 1\n", pl.x); + + /* Testing that horizontal scrolling does, in fact, have an effect on EM_POSFROMCHAR */ + SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) text); + SendMessage(hwndRichEdit, EM_SCROLL, SB_LINEUP, 0); /* line up */ + + result = SendMessage(hwndRichEdit, EM_POSFROMCHAR, (WPARAM)&pl, 0); + ok(result == 0, "EM_POSFROMCHAR returned %ld, expected 0\n", result); + ok(pl.y == 0, "EM_POSFROMCHAR reports y=%d, expected 0\n", pl.y); + todo_wine { + ok(pl.x == 1, "EM_POSFROMCHAR reports x=%d, expected 1\n", pl.x); + } + xpos = pl.x; + + SendMessage(hwndRichEdit, WM_HSCROLL, SB_LINERIGHT, 0); + result = SendMessage(hwndRichEdit, EM_POSFROMCHAR, (WPARAM)&pl, 0); + ok(result == 0, "EM_POSFROMCHAR returned %ld, expected 0\n", result); + ok(pl.y == 0, "EM_POSFROMCHAR reports y=%d, expected 0\n", pl.y); + todo_wine { + /* Fails on builtin because horizontal scrollbar is not being shown */ + ok(pl.x < xpos, "EM_POSFROMCHAR reports x=%hd, expected value less than %d\n", pl.x, xpos); + } DestroyWindow(hwndRichEdit); }