Commit 02c36b52 authored by Dmitry Timoshkov's avatar Dmitry Timoshkov Committed by Alexandre Julliard

comctl32/listbox: Fix the listbox sorting algorithm.

parent 7decba4e
...@@ -791,10 +791,11 @@ static INT LISTBOX_FindStringPos( LB_DESCR *descr, LPCWSTR str, BOOL exact ) ...@@ -791,10 +791,11 @@ static INT LISTBOX_FindStringPos( LB_DESCR *descr, LPCWSTR str, BOOL exact )
{ {
INT index, min, max, res; INT index, min, max, res;
if (!(descr->style & LBS_SORT)) return -1; /* Add it at the end */ if (!descr->nb_items || !(descr->style & LBS_SORT)) return -1; /* Add it at the end */
min = 0; min = 0;
max = descr->nb_items; max = descr->nb_items - 1;
while (min != max) while (min <= max)
{ {
index = (min + max) / 2; index = (min + max) / 2;
if (HAS_STRINGS(descr)) if (HAS_STRINGS(descr))
...@@ -817,10 +818,10 @@ static INT LISTBOX_FindStringPos( LB_DESCR *descr, LPCWSTR str, BOOL exact ) ...@@ -817,10 +818,10 @@ static INT LISTBOX_FindStringPos( LB_DESCR *descr, LPCWSTR str, BOOL exact )
res = SendMessageW( descr->owner, WM_COMPAREITEM, id, (LPARAM)&cis ); res = SendMessageW( descr->owner, WM_COMPAREITEM, id, (LPARAM)&cis );
} }
if (!res) return index; if (!res) return index;
if (res > 0) max = index; if (res > 0) max = index - 1;
else min = index + 1; else min = index + 1;
} }
return exact ? -1 : max; return exact ? -1 : min;
} }
......
...@@ -2032,7 +2032,7 @@ static void test_WM_MEASUREITEM(void) ...@@ -2032,7 +2032,7 @@ static void test_WM_MEASUREITEM(void)
ret = SendMessageA(listbox, LB_ADDSTRING, 0, (LPARAM)"item 2"); ret = SendMessageA(listbox, LB_ADDSTRING, 0, (LPARAM)"item 2");
ok(ret == 2, "expected 2, got %ld\n", ret); ok(ret == 2, "expected 2, got %ld\n", ret);
ok_sequence(sequences, PARENT_SEQ_INDEX, lb_addstring_sort_parent_seq, "LB_ADDSTRING (LBS_SORT)", TRUE); ok_sequence(sequences, PARENT_SEQ_INDEX, lb_addstring_sort_parent_seq, "LB_ADDSTRING (LBS_SORT)", FALSE);
DestroyWindow(listbox); DestroyWindow(listbox);
/* LBS_HASSTRINGS */ /* LBS_HASSTRINGS */
......
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