Commit 874c5508 authored by Gabriel Ivăncescu's avatar Gabriel Ivăncescu Committed by Alexandre Julliard

comctl32/listbox: Rewrite FindString to use helpers and avoid the macro.

parent 2fddd621
...@@ -965,46 +965,42 @@ static INT LISTBOX_FindFileStrPos( LB_DESCR *descr, LPCWSTR str ) ...@@ -965,46 +965,42 @@ static INT LISTBOX_FindFileStrPos( LB_DESCR *descr, LPCWSTR str )
*/ */
static INT LISTBOX_FindString( LB_DESCR *descr, INT start, LPCWSTR str, BOOL exact ) static INT LISTBOX_FindString( LB_DESCR *descr, INT start, LPCWSTR str, BOOL exact )
{ {
INT i; INT i, index;
LB_ITEMDATA *item;
if (descr->style & LBS_NODATA) return LB_ERR; if (descr->style & LBS_NODATA) return LB_ERR;
if (start >= descr->nb_items) start = -1; start++;
item = descr->items + start + 1; if (start >= descr->nb_items) start = 0;
if (HAS_STRINGS(descr)) if (HAS_STRINGS(descr))
{ {
if (!str || ! str[0] ) return LB_ERR; if (!str || ! str[0] ) return LB_ERR;
if (exact) if (exact)
{ {
for (i = start + 1; i < descr->nb_items; i++, item++) for (i = 0, index = start; i < descr->nb_items; i++, index++)
if (!LISTBOX_lstrcmpiW( descr->locale, str, item->str )) return i; {
for (i = 0, item = descr->items; i <= start; i++, item++) if (index == descr->nb_items) index = 0;
if (!LISTBOX_lstrcmpiW( descr->locale, str, item->str )) return i; if (!LISTBOX_lstrcmpiW(descr->locale, str, get_item_string(descr, index)))
return index;
}
} }
else else
{ {
/* Special case for drives and directories: ignore prefix */ /* Special case for drives and directories: ignore prefix */
#define CHECK_DRIVE(item) \
if ((item)->str[0] == '[') \
{ \
if (!strncmpiW( str, (item)->str+1, len )) return i; \
if (((item)->str[1] == '-') && !strncmpiW(str, (item)->str+2, len)) \
return i; \
}
INT len = strlenW(str); INT len = strlenW(str);
for (i = start + 1; i < descr->nb_items; i++, item++) WCHAR *item_str;
{
if (!strncmpiW( str, item->str, len )) return i; for (i = 0, index = start; i < descr->nb_items; i++, index++)
CHECK_DRIVE(item);
}
for (i = 0, item = descr->items; i <= start; i++, item++)
{ {
if (!strncmpiW( str, item->str, len )) return i; if (index == descr->nb_items) index = 0;
CHECK_DRIVE(item); item_str = get_item_string(descr, index);
if (!strncmpiW(str, item_str, len)) return index;
if (item_str[0] == '[')
{
if (!strncmpiW(str, item_str + 1, len)) return index;
if (item_str[1] == '-' && !strncmpiW(str, item_str + 2, len)) return index;
}
} }
#undef CHECK_DRIVE
} }
} }
else else
...@@ -1014,10 +1010,11 @@ static INT LISTBOX_FindString( LB_DESCR *descr, INT start, LPCWSTR str, BOOL exa ...@@ -1014,10 +1010,11 @@ static INT LISTBOX_FindString( LB_DESCR *descr, INT start, LPCWSTR str, BOOL exa
return LISTBOX_FindStringPos( descr, str, TRUE ); return LISTBOX_FindStringPos( descr, str, TRUE );
/* Otherwise use a linear search */ /* Otherwise use a linear search */
for (i = start + 1; i < descr->nb_items; i++, item++) for (i = 0, index = start; i < descr->nb_items; i++, index++)
if (item->data == (ULONG_PTR)str) return i; {
for (i = 0, item = descr->items; i <= start; i++, item++) if (index == descr->nb_items) index = 0;
if (item->data == (ULONG_PTR)str) return i; if (get_item_data(descr, index) == (ULONG_PTR)str) return index;
}
} }
return LB_ERR; return LB_ERR;
} }
......
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