richedit: Fixed EM_POSFROMCHAR for pos of text length.

For some reason EM_POSFROMCHAR was returning 0 when the position was
equal to the end of the text, or beyond the end of the text. Instead
it should use the position at the end of the text for both these
cases.  The x value was also seen to be offset by 1 according to the
tests.
This commit is contained in:
Dylan Smith 2008-10-22 02:22:41 -04:00 committed by Alexandre Julliard
parent 31951a099d
commit 46d79b0363
3 changed files with 9 additions and 20 deletions

View File

@ -3543,18 +3543,15 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam,
if (wParam >= 0x40000)
nCharOfs = lParam;
nLength = ME_GetTextLength(editor);
if (nCharOfs < nLength) {
ME_RunOfsFromCharOfs(editor, nCharOfs, &pRun, &nOffset);
assert(pRun->type == diRun);
pt.y = pRun->member.run.pt.y;
pt.x = pRun->member.run.pt.x + ME_PointFromChar(editor, &pRun->member.run, nOffset);
pt.y += ME_GetParagraph(pRun)->member.para.pt.y;
} else {
pt.x = 0;
pt.y = editor->pBuffer->pLast->member.para.pt.y;
}
nCharOfs = min(nCharOfs, nLength);
ME_RunOfsFromCharOfs(editor, nCharOfs, &pRun, &nOffset);
assert(pRun->type == diRun);
pt.y = pRun->member.run.pt.y;
pt.x = pRun->member.run.pt.x + ME_PointFromChar(editor, &pRun->member.run, nOffset);
pt.y += ME_GetParagraph(pRun)->member.para.pt.y;
pt.x += editor->selofs;
pt.x++; /* for some reason native offsets x by one */
si.cbSize = sizeof(si);
si.fMask = SIF_POS;

View File

@ -567,9 +567,7 @@ static void test_EM_POSFROMCHAR(void)
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)
@ -623,9 +621,7 @@ static void test_EM_POSFROMCHAR(void)
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);
@ -647,7 +643,7 @@ static void test_EM_POSFROMCHAR(void)
xpos = pt.x;
SendMessage(hwndRichEdit, EM_POSFROMCHAR, (WPARAM)&pt,
SendMessage(hwndRichEdit, WM_GETTEXTLENGTH, 0, 0));
todo_wine ok(pt.x > xpos, "pt.x = %d\n", pt.x);
ok(pt.x > xpos, "pt.x = %d\n", pt.x);
xpos = pt.x;
SendMessage(hwndRichEdit, EM_POSFROMCHAR, (WPARAM)&pt,
SendMessage(hwndRichEdit, WM_GETTEXTLENGTH, 0, 0)+1);

View File

@ -742,9 +742,7 @@ static void test_EM_POSFROMCHAR(void)
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)
@ -805,9 +803,7 @@ static void test_EM_POSFROMCHAR(void)
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);