From 3cc6e2365a7742317b12ec44c0b49773cc17e654 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alex=20Villac=C3=ADs=20Lasso?= Date: Mon, 23 Jun 2008 13:49:49 -0500 Subject: [PATCH] richedit: When returning position through wParam pointer, EM_POSFROMCHAR must return 0 as LRESULT. Add tests for EM_POSFROMCHAR for 1.0 and 2.0. --- dlls/riched20/editor.c | 2 +- dlls/riched20/tests/editor.c | 67 ++++++++++++++++++++++++++++++++++ dlls/riched20/wrap.c | 3 ++ dlls/riched32/tests/editor.c | 70 ++++++++++++++++++++++++++++++++++++ 4 files changed, 141 insertions(+), 1 deletion(-) diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c index 899b82f085..4d6cdd9c0a 100644 --- a/dlls/riched20/editor.c +++ b/dlls/riched20/editor.c @@ -2920,7 +2920,7 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, if (wParam >= 0x40000) { *(POINTL *)wParam = pt; } - return MAKELONG( pt.x, pt.y ); + return (wParam >= 0x40000) ? 0 : MAKELONG( pt.x, pt.y ); } case WM_CREATE: if (GetWindowLongW(hWnd, GWL_STYLE) & WS_HSCROLL) diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c index c9aa1949d9..d51da22684 100644 --- a/dlls/riched20/tests/editor.c +++ b/dlls/riched20/tests/editor.c @@ -397,6 +397,72 @@ static void test_EM_SCROLLCARET(void) DestroyWindow(hwndRichEdit); } +static void test_EM_POSFROMCHAR(void) +{ + HWND hwndRichEdit = new_richedit(NULL); + unsigned int i; + LRESULT result; + unsigned int height = 0; + unsigned int xpos = 0; + + /* Fill the control to lines to ensure that most of them are offscreen */ + for (i = 0; i < 50; i++) + { + /* Do not modify the string; it is exactly 16 characters long. */ + SendMessage(hwndRichEdit, EM_SETSEL, 0, 0); + SendMessage(hwndRichEdit, EM_REPLACESEL, 0, (LPARAM)"0123456789ABCDE\n"); + } + + /* + Richedit 1.0 receives a POINTL* on wParam and character offset on lParam, returns void. + Richedit 2.0 receives character offset on wParam, ignores lParam, returns MAKELONG(x,y) + Richedit 3.0 accepts either of the above API conventions. + */ + + /* Testing Richedit 2.0 API format */ + + /* Testing start of lines. X-offset should be constant on all cases (native is 1). + Since all lines are identical and drawn with the same font, + they should have the same height... right? + */ + for (i = 0; i < 50; i++) + { + /* All the lines are 16 characters long */ + result = SendMessage(hwndRichEdit, EM_POSFROMCHAR, i * 16, 0); + if (i == 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); + } + else if (i == 1) + { + ok(HIWORD(result) > 0, "EM_POSFROMCHAR reports y=%d, expected > 0\n", HIWORD(result)); + ok(LOWORD(result) == xpos, "EM_POSFROMCHAR reports x=%d, expected 1\n", LOWORD(result)); + height = HIWORD(result); + } + else + { + ok(HIWORD(result) == i * height, "EM_POSFROMCHAR reports y=%d, expected %d\n", HIWORD(result), i * 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 * 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 position way past end of text */ + result = SendMessage(hwndRichEdit, EM_POSFROMCHAR, 55 * 16, 0); + 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)); + + DestroyWindow(hwndRichEdit); +} + static void test_EM_SETCHARFORMAT(void) { HWND hwndRichEdit = new_richedit(NULL); @@ -4170,6 +4236,7 @@ START_TEST( editor ) test_WM_CHAR(); test_EM_FINDTEXT(); test_EM_GETLINE(); + test_EM_POSFROMCHAR(); test_EM_SCROLLCARET(); test_EM_SCROLL(); test_WM_SETTEXT(); diff --git a/dlls/riched20/wrap.c b/dlls/riched20/wrap.c index da5fef7359..3230ff76dc 100644 --- a/dlls/riched20/wrap.c +++ b/dlls/riched20/wrap.c @@ -471,6 +471,7 @@ BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor) { ME_Context c; BOOL bModified = FALSE; int yStart = -1; + int yLastPos = 0; ME_InitContext(&c, editor, GetDC(editor->hWnd)); editor->nHeight = 0; @@ -496,6 +497,7 @@ BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor) { bModified = bModified | bRedraw; + yLastPos = c.pt.y; c.pt.y += item->member.para.nHeight; item = item->member.para.next_para; } @@ -503,6 +505,7 @@ BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor) { editor->sizeWindow.cy = c.rcView.bottom-c.rcView.top; editor->nTotalLength = c.pt.y; + editor->pBuffer->pLast->member.para.nYPos = yLastPos; ME_DestroyContext(&c, editor->hWnd); diff --git a/dlls/riched32/tests/editor.c b/dlls/riched32/tests/editor.c index ff82654ff6..13e2245fbf 100644 --- a/dlls/riched32/tests/editor.c +++ b/dlls/riched32/tests/editor.c @@ -696,6 +696,75 @@ static void test_EM_FINDTEXT(void) DestroyWindow(hwndRichEdit); } +static void test_EM_POSFROMCHAR(void) +{ + HWND hwndRichEdit = new_richedit(NULL); + unsigned int i; + POINTL pl; + LRESULT result; + unsigned int height = 0; + unsigned int xpos = 0; + + /* Fill the control to lines to ensure that most of them are offscreen */ + for (i = 0; i < 50; i++) + { + /* Do not modify the string; it is exactly 16 characters long. */ + SendMessage(hwndRichEdit, EM_SETSEL, 0, 0); + SendMessage(hwndRichEdit, EM_REPLACESEL, 0, (LPARAM)"0123456789ABCD\r\n"); + } + + /* + Richedit 1.0 receives a POINTL* on wParam and character offset on lParam, returns void. + Richedit 2.0 receives character offset on wParam, ignores lParam, returns MAKELONG(x,y) + Richedit 3.0 accepts either of the above API conventions. + */ + + /* Testing Richedit 1.0 API format */ + + /* Testing start of lines. X-offset should be constant on all cases (native is 1). + Since all lines are identical and drawn with the same font, + they should have the same height... right? + */ + 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); + if (i == 0) + { + 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; + } + else if (i == 1) + { + ok(pl.y > 0, "EM_POSFROMCHAR reports y=%d, expected > 0\n", pl.y); + ok(pl.x == xpos, "EM_POSFROMCHAR reports x=%d, expected 1\n", pl.x); + height = pl.y; + } + else + { + ok(pl.y == i * height, "EM_POSFROMCHAR reports y=%d, expected %d\n", pl.y, i * 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 * 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 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 * 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); + + DestroyWindow(hwndRichEdit); +} START_TEST( editor ) @@ -717,6 +786,7 @@ START_TEST( editor ) test_EM_GETLINE(); test_EM_LINELENGTH(); test_EM_FINDTEXT(); + test_EM_POSFROMCHAR(); /* Set the environment variable WINETEST_RICHED32 to keep windows * responsive and open for 30 seconds. This is useful for debugging. -- 2.32.0.93.g670b81a890