Commit 36350845 authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

riched20: Return the nearest char pos if the coords are outside the format rect.

For the two tests that remain todo_wine, the results differ between riched20 and msftedit, with Wine's implementation matching msftedit. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=52041Signed-off-by: 's avatarHuw Davies <huw@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 11b15054
......@@ -993,32 +993,17 @@ static BOOL cursor_from_virtual_coords( ME_TextEditor *editor, int x, int y,
*
* x & y are pixel positions in client coordinates.
*
* isExact will be set to TRUE if the run is directly under the pixel
* position, FALSE if it not, unless isExact is set to NULL.
*
* return FALSE if outside client area and the cursor is not set,
* otherwise TRUE is returned.
* return TRUE if the run is directly under the pixel
* position, FALSE if it not.
*/
BOOL ME_CharFromPos(ME_TextEditor *editor, int x, int y,
ME_Cursor *cursor, BOOL *isExact)
BOOL cursor_from_coords( ME_TextEditor *editor, int x, int y, ME_Cursor *cursor )
{
RECT rc;
BOOL bResult;
ITextHost_TxGetClientRect(editor->texthost, &rc);
if (x < 0 || y < 0 || x >= rc.right || y >= rc.bottom) {
if (isExact) *isExact = FALSE;
return FALSE;
}
x += editor->horz_si.nPos;
y += editor->vert_si.nPos;
bResult = cursor_from_virtual_coords( editor, x, y, cursor, FALSE );
if (isExact) *isExact = bResult;
return TRUE;
x += editor->horz_si.nPos;
y += editor->vert_si.nPos;
return cursor_from_virtual_coords( editor, x, y, cursor, FALSE );
}
/* Extends the selection with a word, line, or paragraph selection type.
*
* The selection is anchored by editor->pCursors[2-3] such that the text
......
......@@ -2815,7 +2815,6 @@ static BOOL is_link( ME_Run *run )
void editor_set_cursor( ME_TextEditor *editor, int x, int y )
{
ME_Cursor pos;
BOOL is_exact;
static HCURSOR cursor_arrow, cursor_hand, cursor_ibeam, cursor_reverse;
HCURSOR cursor;
......@@ -2838,22 +2837,18 @@ void editor_set_cursor( ME_TextEditor *editor, int x, int y )
else cursor = cursor_ibeam;
}
else if (x < editor->rcFormat.left) cursor = cursor_reverse;
else
else if (cursor_from_coords( editor, x, y, &pos ))
{
ME_CharFromPos( editor, x, y, &pos, &is_exact );
if (is_exact)
{
ME_Run *run = pos.run;
ME_Run *run = pos.run;
if (is_link( run )) cursor = cursor_hand;
if (is_link( run )) cursor = cursor_hand;
else if (ME_IsSelection( editor ))
{
int start, end, offset = ME_GetCursorOfs( &pos );
else if (ME_IsSelection( editor ))
{
int start, end, offset = ME_GetCursorOfs( &pos );
ME_GetSelectionOfs( editor, &start, &end );
if (start <= offset && end >= offset) cursor = cursor_arrow;
}
ME_GetSelectionOfs( editor, &start, &end );
if (start <= offset && end >= offset) cursor = cursor_arrow;
}
}
......@@ -3113,15 +3108,13 @@ static inline int calc_wheel_change( int *remain, int amount_per_click )
void link_notify(ME_TextEditor *editor, UINT msg, WPARAM wParam, LPARAM lParam)
{
int x,y;
BOOL isExact;
ME_Cursor cursor; /* The start of the clicked text. */
ME_Run *run;
ENLINK info;
x = (short)LOWORD(lParam);
y = (short)HIWORD(lParam);
ME_CharFromPos(editor, x, y, &cursor, &isExact);
if (!isExact) return;
if (!cursor_from_coords( editor, x, y, &cursor )) return;
if (is_link( cursor.run ))
{ /* The clicked run has CFE_LINK set */
......@@ -3853,11 +3846,10 @@ LRESULT editor_handle_message( ME_TextEditor *editor, UINT msg, WPARAM wParam,
case EM_CHARFROMPOS:
{
ME_Cursor cursor;
if (ME_CharFromPos(editor, ((POINTL *)lParam)->x, ((POINTL *)lParam)->y,
&cursor, NULL))
return ME_GetCursorOfs(&cursor);
else
return -1;
POINTL *pt = (POINTL *)lParam;
cursor_from_coords(editor, pt->x, pt->y, &cursor);
return ME_GetCursorOfs(&cursor);
}
case EM_POSFROMCHAR:
{
......
......@@ -164,6 +164,7 @@ static inline ME_DisplayItem *run_get_di( ME_Run *run )
/* caret.c */
void cursor_coords( ME_TextEditor *editor, ME_Cursor *cursor, int *x, int *y, int *height ) DECLSPEC_HIDDEN;
BOOL cursor_from_coords( ME_TextEditor *editor, int x, int y, ME_Cursor *cursor ) DECLSPEC_HIDDEN;
void ME_SetCursorToStart(ME_TextEditor *editor, ME_Cursor *cursor) DECLSPEC_HIDDEN;
int set_selection_cursors(ME_TextEditor *editor, int from, int to) DECLSPEC_HIDDEN;
BOOL ME_MoveCursorWords(ME_TextEditor *editor, ME_Cursor *cursor, int nRelOfs) DECLSPEC_HIDDEN;
......@@ -171,11 +172,10 @@ void hide_caret(ME_TextEditor *ed) DECLSPEC_HIDDEN;
void show_caret(ME_TextEditor *ed) DECLSPEC_HIDDEN;
void update_caret(ME_TextEditor *ed) DECLSPEC_HIDDEN;
void create_caret(ME_TextEditor *ed) DECLSPEC_HIDDEN;
BOOL ME_CharFromPos(ME_TextEditor *editor, int x, int y, ME_Cursor *cursor, BOOL *isExact) DECLSPEC_HIDDEN;
void ME_LButtonDown(ME_TextEditor *editor, int x, int y, int clickNum) DECLSPEC_HIDDEN;
void ME_MouseMove(ME_TextEditor *editor, int x, int y) DECLSPEC_HIDDEN;
BOOL ME_DeleteTextAtCursor(ME_TextEditor *editor, int nCursor, int nChars) DECLSPEC_HIDDEN;
void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor,
void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor,
const WCHAR *str, int len, ME_Style *style) DECLSPEC_HIDDEN;
void ME_InsertEndRowFromCursor(ME_TextEditor *editor, int nCursor) DECLSPEC_HIDDEN;
int ME_MoveCursorChars(ME_TextEditor *editor, ME_Cursor *cursor, int nRelOfs, BOOL final_eop) DECLSPEC_HIDDEN;
......
......@@ -7228,32 +7228,34 @@ static void test_EM_CHARFROMPOS(void)
point.x = -1;
point.y = 40;
result = SendMessageA(hwnd, EM_CHARFROMPOS, 0, (LPARAM)&point);
todo_wine ok(result == 34, "expected character index of 34 but got %d\n", result);
ok(result == 34, "expected character index of 34 but got %d\n", result);
point.x = 1000;
point.y = 0;
result = SendMessageA(hwnd, EM_CHARFROMPOS, 0, (LPARAM)&point);
todo_wine ok(result == 33, "expected character index of 33 but got %d\n", result);
ok(result == 33, "expected character index of 33 but got %d\n", result);
point.x = 1000;
point.y = 36;
result = SendMessageA(hwnd, EM_CHARFROMPOS, 0, (LPARAM)&point);
todo_wine ok(result == 39, "expected character index of 39 but got %d\n", result);
ok(result == 39, "expected character index of 39 but got %d\n", result);
point.x = 1000;
point.y = -1;
result = SendMessageA(hwnd, EM_CHARFROMPOS, 0, (LPARAM)&point);
/* This differs from the msftedit result */
todo_wine ok(result == 0, "expected character index of 0 but got %d\n", result);
point.x = 1000;
point.y = rcClient.bottom + 1;
result = SendMessageA(hwnd, EM_CHARFROMPOS, 0, (LPARAM)&point);
/* This differs from the msftedit result */
todo_wine ok(result == 34, "expected character index of 34 but got %d\n", result);
point.x = 1000;
point.y = rcClient.bottom;
result = SendMessageA(hwnd, EM_CHARFROMPOS, 0, (LPARAM)&point);
todo_wine ok(result == 39, "expected character index of 39 but got %d\n", result);
ok(result == 39, "expected character index of 39 but got %d\n", result);
DestroyWindow(hwnd);
}
......
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