From 6f8957156e4207cbce33be76eef7291c70075810 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Thu, 8 Oct 2020 17:03:25 +0300 Subject: [PATCH] comctl32/ipaddress: Select field contents on IPM_SETFOCUS. Signed-off-by: Nikolay Sivov Signed-off-by: Alexandre Julliard --- dlls/comctl32/ipaddress.c | 1 + dlls/comctl32/tests/ipaddress.c | 54 +++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/dlls/comctl32/ipaddress.c b/dlls/comctl32/ipaddress.c index c75a1085650..d415a96fb74 100644 --- a/dlls/comctl32/ipaddress.c +++ b/dlls/comctl32/ipaddress.c @@ -393,6 +393,7 @@ static void IPADDRESS_SetFocusToField (const IPADDRESS_INFO *infoPtr, INT index) if (index > 3 || index < 0) index=0; + SendMessageW (infoPtr->Part[index].EditHwnd, EM_SETSEL, 0, -1); SetFocus (infoPtr->Part[index].EditHwnd); } diff --git a/dlls/comctl32/tests/ipaddress.c b/dlls/comctl32/tests/ipaddress.c index cc79b7bf11b..5a5aafe7aa8 100644 --- a/dlls/comctl32/tests/ipaddress.c +++ b/dlls/comctl32/tests/ipaddress.c @@ -62,17 +62,71 @@ static void test_get_set_text(void) DestroyWindow(hwnd); } +struct child_enum +{ + HWND fields[4]; + unsigned int count; +}; + +static BOOL CALLBACK test_child_enum_proc(HWND hwnd, LPARAM param) +{ + struct child_enum *child_enum = (struct child_enum *)param; + char buff[16] = { 0 }; + unsigned int index; + + GetWindowTextA(hwnd, buff, ARRAY_SIZE(buff)); + index = atoi(buff); + ok(index < 4, "Unexpected index.\n"); + if (index < 4) + child_enum->fields[index] = hwnd; + + return ++child_enum->count < 4; +} + +static void test_IPM_SETFOCUS(void) +{ + struct child_enum child_enum = {{ 0 }}; + unsigned int ret, from, to, i; + HWND hwnd; + + hwnd = create_ipaddress_control(); + ok(!!hwnd, "Failed to create control.\n"); + + ret = SendMessageA(hwnd, IPM_SETADDRESS, 0, MAKEIPADDRESS(0, 1, 2, 3)); + ok(ret, "Unexpected return value %u.\n", ret); + + EnumChildWindows(hwnd, test_child_enum_proc, (LPARAM)&child_enum); + ok(child_enum.count == 4, "Unexpected child count %u.\n", child_enum.count); + + for (i = 0; i < 3; ++i) + SendMessageA(child_enum.fields[i], EM_SETSEL, -1, 0); + + SendMessageA(child_enum.fields[0], EM_GETSEL, (WPARAM)&from, (LPARAM)&to); + ok(from == 0 && to == 0, "Unexpected selection %u x %u.\n", from, to); + + ret = SendMessageA(hwnd, IPM_SETFOCUS, 0, 0); +todo_wine + ok(ret, "Unexpected return value %u.\n", ret); + + SendMessageA(child_enum.fields[0], EM_GETSEL, (WPARAM)&from, (LPARAM)&to); + ok(from == 0 && to == 1, "Unexpected selection %u x %u.\n", from, to); + + DestroyWindow(hwnd); +} + START_TEST(ipaddress) { ULONG_PTR cookie; HANDLE ctxt; test_get_set_text(); + test_IPM_SETFOCUS(); if (!load_v6_module(&cookie, &ctxt)) return; test_get_set_text(); + test_IPM_SETFOCUS(); unload_v6_module(cookie, ctxt); }