[PATCH v2 2/2] comctl32/edit: In EM_POSFROMCHAR return correct position for empty lines
Fabian Maurer
dark.shadow4 at web.de
Wed Jun 12 16:30:37 CDT 2019
Fix with permission from ROS Jira
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=47305
Signed-off-by: Fabian Maurer <dark.shadow4 at web.de>
---
dlls/comctl32/edit.c | 2 +-
dlls/comctl32/tests/edit.c | 17 +++++++++++++++++
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/dlls/comctl32/edit.c b/dlls/comctl32/edit.c
index e64e260bd7..6d8c07273c 100644
--- a/dlls/comctl32/edit.c
+++ b/dlls/comctl32/edit.c
@@ -1043,7 +1043,7 @@ static LRESULT EDIT_EM_PosFromChar(EDITSTATE *es, INT index, BOOL after_wrap)
x -= es->x_offset;
}
else
- x = es->x_offset;
+ x = (lw > 0 ? es->x_offset : -es->x_offset);
if (es->style & ES_RIGHT)
x = w - (lw - x);
diff --git a/dlls/comctl32/tests/edit.c b/dlls/comctl32/tests/edit.c
index f454434a0c..5254baa4a1 100644
--- a/dlls/comctl32/tests/edit.c
+++ b/dlls/comctl32/tests/edit.c
@@ -1189,6 +1189,8 @@ static void test_char_from_pos(void)
{
int lo, hi, mid, ret, i;
HWND hwEdit;
+ HDC dc;
+ SIZE size;
hwEdit = create_editcontrol(ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
SendMessageA(hwEdit, WM_SETTEXT, 0, (LPARAM)"aa");
@@ -1321,6 +1323,21 @@ static void test_char_from_pos(void)
ret = SendMessageA(hwEdit, EM_POSFROMCHAR, 2, 0);
ok(-1 == ret, "expected -1 got %d\n", ret);
DestroyWindow(hwEdit);
+
+ /* Test newline when the edit control is scrolled to the right */
+
+ hwEdit = create_editcontrol(ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
+ SendMessageA(hwEdit, WM_SETTEXT, 0, (LPARAM)"wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww\r\n\r\n");
+ SendMessageA(hwEdit, EM_SETSEL, 40, 40);
+
+ dc = GetDC(hwEdit);
+ GetTextExtentPoint32A(dc, "w", 1, &size);
+ ReleaseDC(hwEdit, dc);
+ lo = (short)LOWORD(SendMessageA(hwEdit, EM_POSFROMCHAR, 42, 0));
+ ret = (short)LOWORD(SendMessageA(hwEdit, EM_POSFROMCHAR, 40, 0));
+ ret += size.cx * (-40); /* Calculate expected position, 40 characters to the left */
+ ok(ret == lo, "expected %d got %d\n", ret, lo);
+ DestroyWindow(hwEdit);
}
/* Test if creating edit control without ES_AUTOHSCROLL and ES_AUTOVSCROLL
--
2.22.0
More information about the wine-devel
mailing list