[PATCH 5/9] user32/listbox: Use a helper to retrieve item data by index

Gabriel Iv─âncescu gabrielopcode at gmail.com
Thu Feb 14 06:06:44 CST 2019


Signed-off-by: Gabriel Iv─âncescu <gabrielopcode at gmail.com>
---
 dlls/user32/listbox.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/dlls/user32/listbox.c b/dlls/user32/listbox.c
index 0e0399f..70b55e1 100644
--- a/dlls/user32/listbox.c
+++ b/dlls/user32/listbox.c
@@ -148,6 +148,11 @@ static BOOL resize_storage(LB_DESCR *descr, UINT items_size)
     return TRUE;
 }
 
+static ULONG_PTR get_item_data( const LB_DESCR *descr, UINT index )
+{
+    return (descr->style & LBS_NODATA) ? 0 : descr->items[index].data;
+}
+
 static BOOL is_item_selected( const LB_DESCR *descr, UINT index )
 {
     if (!(descr->style & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)))
@@ -590,7 +595,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,
@@ -825,8 +830,7 @@ static LRESULT LISTBOX_GetText( LB_DESCR *descr, INT index, LPWSTR buffer, BOOL
         __ENDTRY
     } 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;
@@ -874,7 +878,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;
@@ -1650,7 +1654,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)
@@ -2701,7 +2705,7 @@ LRESULT ListBoxWndProc_common( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam
             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