=?UTF-8?Q?Gabriel=20Iv=C4=83ncescu=20?=: comctl32/listbox: Use a helper to retrieve item data by index.

Alexandre Julliard julliard at winehq.org
Thu Feb 14 16:19:11 CST 2019


Module: wine
Branch: master
Commit: e16d591dc802dc913acc7db288f774b06cb28030
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=e16d591dc802dc913acc7db288f774b06cb28030

Author: Gabriel Ivăncescu <gabrielopcode at gmail.com>
Date:   Wed Feb 13 16:36:16 2019 +0200

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

Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 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 5c58214..61bb9da 100644
--- a/dlls/comctl32/listbox.c
+++ b/dlls/comctl32/listbox.c
@@ -153,6 +153,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)))
@@ -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))




More information about the wine-cvs mailing list