[PATCH v4 4/7] comctl32/listbox: Use a helper to retrieve item data by index
Gabriel Ivăncescu
gabrielopcode at gmail.com
Tue Feb 12 07:47:00 CST 2019
Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
---
dlls/comctl32/listbox.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/dlls/comctl32/listbox.c b/dlls/comctl32/listbox.c
index c84d317..34d555a 100644
--- a/dlls/comctl32/listbox.c
+++ b/dlls/comctl32/listbox.c
@@ -127,6 +127,11 @@ static TIMER_DIRECTION LISTBOX_Timer = LB_TIMER_NONE;
static LRESULT LISTBOX_GetItemRect( const LB_DESCR *descr, INT index, RECT *rect );
+static ULONG_PTR get_item_data( const LB_DESCR *descr, UINT index )
+{
+ return (descr->style & LBS_NODATA) ? 0 : descr->items[index].data;
+}
+
static BOOL resize_storage(LB_DESCR *descr, UINT items_size)
{
LB_ITEMDATA *items;
@@ -565,7 +570,7 @@ static void LISTBOX_PaintItem( LB_DESCR *descr, HDC hdc, const RECT *rect,
if (focused)
dis.itemState |= ODS_FOCUS;
if (!IsWindowEnabled(descr->self)) dis.itemState |= ODS_DISABLED;
- dis.itemData = item ? item->data : 0;
+ dis.itemData = get_item_data(descr, index);
dis.rcItem = *rect;
TRACE("[%p]: drawitem %d (%s) action=%02x state=%02x rect=%s\n",
descr->self, index, item ? debugstr_w(item->str) : "", action,
@@ -788,8 +793,7 @@ static LRESULT LISTBOX_GetText( LB_DESCR *descr, INT index, LPWSTR buffer, BOOL
} else
{
if (buffer)
- *((ULONG_PTR *)buffer) = (descr->style & LBS_NODATA)
- ? 0 : descr->items[index].data;
+ *((ULONG_PTR *)buffer) = get_item_data(descr, index);
len = sizeof(ULONG_PTR);
}
return len;
@@ -837,7 +841,7 @@ static INT LISTBOX_FindStringPos( LB_DESCR *descr, LPCWSTR str, BOOL exact )
/* note that some application (MetaStock) expects the second item
* to be in the listbox */
cis.itemID1 = index;
- cis.itemData1 = descr->items[index].data;
+ cis.itemData1 = get_item_data(descr, index);
cis.itemID2 = -1;
cis.itemData2 = (ULONG_PTR)str;
cis.dwLocaleId = descr->locale;
@@ -1641,7 +1645,7 @@ static LRESULT LISTBOX_InsertString( LB_DESCR *descr, INT index, LPCWSTR str )
static void LISTBOX_DeleteItem( LB_DESCR *descr, INT index )
{
/* save the item data before it gets freed by LB_RESETCONTENT */
- ULONG_PTR item_data = descr->items[index].data;
+ ULONG_PTR item_data = get_item_data(descr, index);
LPWSTR item_str = descr->items[index].str;
if (!descr->nb_items)
@@ -2643,7 +2647,7 @@ static LRESULT CALLBACK LISTBOX_WindowProc( HWND hwnd, UINT msg, WPARAM wParam,
SetLastError(ERROR_INVALID_INDEX);
return LB_ERR;
}
- return (descr->style & LBS_NODATA) ? 0 : descr->items[wParam].data;
+ return get_item_data(descr, wParam);
case LB_SETITEMDATA:
if (((INT)wParam < 0) || ((INT)wParam >= descr->nb_items))
--
2.20.1
More information about the wine-devel
mailing list