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=52041 Signed-off-by: Huw Davies huw@codeweavers.com --- dlls/riched20/caret.c | 27 ++++++--------------------- dlls/riched20/editor.c | 34 +++++++++++++--------------------- dlls/riched20/editor.h | 4 ++-- dlls/riched20/tests/editor.c | 10 ++++++---- 4 files changed, 27 insertions(+), 48 deletions(-)
diff --git a/dlls/riched20/caret.c b/dlls/riched20/caret.c index beac8af50a1..ebc137ebf85 100644 --- a/dlls/riched20/caret.c +++ b/dlls/riched20/caret.c @@ -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 diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c index 3bf499681ed..429f023ebe4 100644 --- a/dlls/riched20/editor.c +++ b/dlls/riched20/editor.c @@ -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: { diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h index 7bdd1bf5efe..8a46e942581 100644 --- a/dlls/riched20/editor.h +++ b/dlls/riched20/editor.h @@ -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; diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c index ab74e0ef1ab..85f7c00383a 100644 --- a/dlls/riched20/tests/editor.c +++ b/dlls/riched20/tests/editor.c @@ -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); }