Commit acec891a authored by Alex Villacís Lasso's avatar Alex Villacís Lasso Committed by Alexandre Julliard

richedit: EM_POSFROMCHAR should take into account scrollbar position. With tests.

parent 3cc6e236
......@@ -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;
}
......
......@@ -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);
}
......
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment