[PATCH] user32: Scroll listbox item completely into view on LB_SETCURSEL.

Alex Henrie alexhenrie24 at gmail.com
Thu Jul 16 02:05:24 CDT 2015


Fixes https://bugs.winehq.org/show_bug.cgi?id=38806
---
 dlls/user32/listbox.c       |  2 +-
 dlls/user32/tests/listbox.c | 35 +++++++++++++++++++++++++++++++++--
 2 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/dlls/user32/listbox.c b/dlls/user32/listbox.c
index 4853c3f..612c6b6 100644
--- a/dlls/user32/listbox.c
+++ b/dlls/user32/listbox.c
@@ -2854,7 +2854,7 @@ LRESULT ListBoxWndProc_common( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam
 
     case LB_SETCURSEL:
         if (IS_MULTISELECT(descr)) return LB_ERR;
-        LISTBOX_SetCaretIndex( descr, wParam, FALSE );
+        LISTBOX_SetCaretIndex( descr, wParam, TRUE );
         ret = LISTBOX_SetSelection( descr, wParam, TRUE, FALSE );
 	if (ret != LB_ERR) ret = descr->selected_item;
 	return ret;
diff --git a/dlls/user32/tests/listbox.c b/dlls/user32/tests/listbox.c
index d99a82c..da76312 100644
--- a/dlls/user32/tests/listbox.c
+++ b/dlls/user32/tests/listbox.c
@@ -349,7 +349,7 @@ static void test_ownerdraw(void)
   ok(exp.caret == got.caret, "expected caret %d, got %d\n", exp.caret, got.caret); \
   ok(exp.selcount == got.selcount, "expected selcount %d, got %d\n", exp.selcount, got.selcount);
 
-static void test_selection(void)
+static void test_LB_SELITEMRANGE(void)
 {
     static const struct listbox_stat test_nosel = { 0, LB_ERR, 0, 0 };
     static const struct listbox_stat test_1 = { 0, LB_ERR, 0, 2 };
@@ -429,6 +429,36 @@ static void test_selection(void)
     DestroyWindow(hLB);
 }
 
+static void test_LB_SETCURSEL(void)
+{
+    HWND parent, hLB;
+    INT ret;
+
+    trace("testing LB_SETCURSEL\n");
+
+    parent = create_parent();
+    assert(parent);
+
+    hLB = create_listbox(LBS_NOINTEGRALHEIGHT | WS_CHILD, parent);
+    assert(hLB);
+
+    SendMessageA(hLB, LB_ADDSTRING, 0, (LPARAM)"Fifth added");
+    SendMessageA(hLB, LB_ADDSTRING, 0, (LPARAM)"Sixth added");
+    SendMessageA(hLB, LB_ADDSTRING, 0, (LPARAM)"Seventh added");
+
+    ret = SendMessageA(hLB, LB_SETCURSEL, 5, 0);
+    ok(ret == 5, "LB_SETCURSEL returned %d instead of 5\n", ret);
+    ret = GetScrollPos(hLB, SB_VERT);
+    ok(ret == 0, "expected vscroll 0, got %d\n", ret);
+
+    ret = SendMessageA(hLB, LB_SETCURSEL, 6, 0);
+    ok(ret == 6, "LB_SETCURSEL returned %d instead of 6\n", ret);
+    ret = GetScrollPos(hLB, SB_VERT);
+    ok(ret == 1, "expected vscroll 1, got %d\n", ret);
+
+    DestroyWindow(hLB);
+}
+
 static void test_listbox_height(void)
 {
     HWND hList;
@@ -1766,7 +1796,8 @@ START_TEST(listbox)
 
   check_item_height();
   test_ownerdraw();
-  test_selection();
+  test_LB_SELITEMRANGE();
+  test_LB_SETCURSEL();
   test_listbox_height();
   test_itemfrompoint();
   test_listbox_item_data();
-- 
2.4.5




More information about the wine-patches mailing list