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

comctl32/listbox: Use a helper to retrieve item string by index.

parent e16d591d
...@@ -158,6 +158,11 @@ static ULONG_PTR get_item_data( const LB_DESCR *descr, UINT index ) ...@@ -158,6 +158,11 @@ static ULONG_PTR get_item_data( const LB_DESCR *descr, UINT index )
return (descr->style & LBS_NODATA) ? 0 : descr->items[index].data; return (descr->style & LBS_NODATA) ? 0 : descr->items[index].data;
} }
static WCHAR *get_item_string( const LB_DESCR *descr, UINT index )
{
return HAS_STRINGS(descr) ? descr->items[index].str : NULL;
}
static BOOL is_item_selected( const LB_DESCR *descr, UINT index ) static BOOL is_item_selected( const LB_DESCR *descr, UINT index )
{ {
if (!(descr->style & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL))) if (!(descr->style & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)))
...@@ -526,11 +531,11 @@ static void LISTBOX_PaintItem( LB_DESCR *descr, HDC hdc, const RECT *rect, ...@@ -526,11 +531,11 @@ static void LISTBOX_PaintItem( LB_DESCR *descr, HDC hdc, const RECT *rect,
INT index, UINT action, BOOL ignoreFocus ) INT index, UINT action, BOOL ignoreFocus )
{ {
BOOL selected = FALSE, focused; BOOL selected = FALSE, focused;
LB_ITEMDATA *item = NULL; WCHAR *item_str = NULL;
if (index < descr->nb_items) if (index < descr->nb_items)
{ {
item = &descr->items[index]; item_str = get_item_string(descr, index);
selected = is_item_selected(descr, index); selected = is_item_selected(descr, index);
} }
...@@ -573,7 +578,7 @@ static void LISTBOX_PaintItem( LB_DESCR *descr, HDC hdc, const RECT *rect, ...@@ -573,7 +578,7 @@ static void LISTBOX_PaintItem( LB_DESCR *descr, HDC hdc, const RECT *rect,
dis.itemData = get_item_data(descr, index); dis.itemData = get_item_data(descr, index);
dis.rcItem = *rect; dis.rcItem = *rect;
TRACE("[%p]: drawitem %d (%s) action=%02x state=%02x rect=%s\n", TRACE("[%p]: drawitem %d (%s) action=%02x state=%02x rect=%s\n",
descr->self, index, item ? debugstr_w(item->str) : "", action, descr->self, index, debugstr_w(item_str), action,
dis.itemState, wine_dbgstr_rect(rect) ); dis.itemState, wine_dbgstr_rect(rect) );
SendMessageW(descr->owner, WM_DRAWITEM, dis.CtlID, (LPARAM)&dis); SendMessageW(descr->owner, WM_DRAWITEM, dis.CtlID, (LPARAM)&dis);
SelectClipRgn( hdc, hrgn ); SelectClipRgn( hdc, hrgn );
...@@ -595,22 +600,22 @@ static void LISTBOX_PaintItem( LB_DESCR *descr, HDC hdc, const RECT *rect, ...@@ -595,22 +600,22 @@ static void LISTBOX_PaintItem( LB_DESCR *descr, HDC hdc, const RECT *rect,
} }
TRACE("[%p]: painting %d (%s) action=%02x rect=%s\n", TRACE("[%p]: painting %d (%s) action=%02x rect=%s\n",
descr->self, index, item ? debugstr_w(item->str) : "", action, descr->self, index, debugstr_w(item_str), action,
wine_dbgstr_rect(rect) ); wine_dbgstr_rect(rect) );
if (!item) if (!item_str)
ExtTextOutW( hdc, rect->left + 1, rect->top, ExtTextOutW( hdc, rect->left + 1, rect->top,
ETO_OPAQUE | ETO_CLIPPED, rect, NULL, 0, NULL ); ETO_OPAQUE | ETO_CLIPPED, rect, NULL, 0, NULL );
else if (!(descr->style & LBS_USETABSTOPS)) else if (!(descr->style & LBS_USETABSTOPS))
ExtTextOutW( hdc, rect->left + 1, rect->top, ExtTextOutW( hdc, rect->left + 1, rect->top,
ETO_OPAQUE | ETO_CLIPPED, rect, item->str, ETO_OPAQUE | ETO_CLIPPED, rect, item_str,
strlenW(item->str), NULL ); strlenW(item_str), NULL );
else else
{ {
/* Output empty string to paint background in the full width. */ /* Output empty string to paint background in the full width. */
ExtTextOutW( hdc, rect->left + 1, rect->top, ExtTextOutW( hdc, rect->left + 1, rect->top,
ETO_OPAQUE | ETO_CLIPPED, rect, NULL, 0, NULL ); ETO_OPAQUE | ETO_CLIPPED, rect, NULL, 0, NULL );
TabbedTextOutW( hdc, rect->left + 1 , rect->top, TabbedTextOutW( hdc, rect->left + 1 , rect->top,
item->str, strlenW(item->str), item_str, strlenW(item_str),
descr->nb_tabs, descr->tabs, 0); descr->nb_tabs, descr->tabs, 0);
} }
if (selected) if (selected)
...@@ -773,14 +778,16 @@ static LRESULT LISTBOX_GetText( LB_DESCR *descr, INT index, LPWSTR buffer, BOOL ...@@ -773,14 +778,16 @@ static LRESULT LISTBOX_GetText( LB_DESCR *descr, INT index, LPWSTR buffer, BOOL
if (HAS_STRINGS(descr)) if (HAS_STRINGS(descr))
{ {
WCHAR *str = get_item_string(descr, index);
if (!buffer) if (!buffer)
return strlenW(descr->items[index].str); return strlenW(str);
TRACE("index %d (0x%04x) %s\n", index, index, debugstr_w(descr->items[index].str)); TRACE("index %d (0x%04x) %s\n", index, index, debugstr_w(str));
__TRY /* hide a Delphi bug that passes a read-only buffer */ __TRY /* hide a Delphi bug that passes a read-only buffer */
{ {
strcpyW( buffer, descr->items[index].str ); strcpyW(buffer, str);
len = strlenW(buffer); len = strlenW(buffer);
} }
__EXCEPT_PAGE_FAULT __EXCEPT_PAGE_FAULT
...@@ -829,7 +836,7 @@ static INT LISTBOX_FindStringPos( LB_DESCR *descr, LPCWSTR str, BOOL exact ) ...@@ -829,7 +836,7 @@ static INT LISTBOX_FindStringPos( LB_DESCR *descr, LPCWSTR str, BOOL exact )
{ {
index = (min + max) / 2; index = (min + max) / 2;
if (HAS_STRINGS(descr)) if (HAS_STRINGS(descr))
res = LISTBOX_lstrcmpiW( descr->locale, descr->items[index].str, str ); res = LISTBOX_lstrcmpiW( descr->locale, get_item_string(descr, index), str );
else else
{ {
COMPAREITEMSTRUCT cis; COMPAREITEMSTRUCT cis;
...@@ -872,7 +879,7 @@ static INT LISTBOX_FindFileStrPos( LB_DESCR *descr, LPCWSTR str ) ...@@ -872,7 +879,7 @@ static INT LISTBOX_FindFileStrPos( LB_DESCR *descr, LPCWSTR str )
while (min != max) while (min != max)
{ {
INT index = (min + max) / 2; INT index = (min + max) / 2;
LPCWSTR p = descr->items[index].str; LPCWSTR p = get_item_string(descr, index);
if (*p == '[') /* drive or directory */ if (*p == '[') /* drive or directory */
{ {
if (*str != '[') res = -1; if (*str != '[') res = -1;
...@@ -1646,7 +1653,7 @@ static void LISTBOX_DeleteItem( LB_DESCR *descr, INT index ) ...@@ -1646,7 +1653,7 @@ static void LISTBOX_DeleteItem( LB_DESCR *descr, INT index )
{ {
/* save the item data before it gets freed by LB_RESETCONTENT */ /* save the item data before it gets freed by LB_RESETCONTENT */
ULONG_PTR item_data = get_item_data(descr, index); ULONG_PTR item_data = get_item_data(descr, index);
LPWSTR item_str = descr->items[index].str; LPWSTR item_str = get_item_string(descr, index);
if (!descr->nb_items) if (!descr->nb_items)
SendMessageW( descr->self, LB_RESETCONTENT, 0, 0 ); SendMessageW( descr->self, LB_RESETCONTENT, 0, 0 );
...@@ -1668,8 +1675,7 @@ static void LISTBOX_DeleteItem( LB_DESCR *descr, INT index ) ...@@ -1668,8 +1675,7 @@ static void LISTBOX_DeleteItem( LB_DESCR *descr, INT index )
dis.itemData = item_data; dis.itemData = item_data;
SendMessageW( descr->owner, WM_DELETEITEM, id, (LPARAM)&dis ); SendMessageW( descr->owner, WM_DELETEITEM, id, (LPARAM)&dis );
} }
if (HAS_STRINGS(descr)) HeapFree( GetProcessHeap(), 0, item_str );
HeapFree( GetProcessHeap(), 0, item_str );
} }
...@@ -2672,7 +2678,7 @@ static LRESULT CALLBACK LISTBOX_WindowProc( HWND hwnd, UINT msg, WPARAM wParam, ...@@ -2672,7 +2678,7 @@ static LRESULT CALLBACK LISTBOX_WindowProc( HWND hwnd, UINT msg, WPARAM wParam,
return LB_ERR; return LB_ERR;
} }
if (!HAS_STRINGS(descr)) return sizeof(ULONG_PTR); if (!HAS_STRINGS(descr)) return sizeof(ULONG_PTR);
return strlenW( descr->items[wParam].str ); return strlenW(get_item_string(descr, wParam));
case LB_GETCURSEL: case LB_GETCURSEL:
if (descr->nb_items == 0) if (descr->nb_items == 0)
......
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