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

comctl32/listbox: Use a helper to get the size of an item.

parent b60108e0
...@@ -127,6 +127,11 @@ static TIMER_DIRECTION LISTBOX_Timer = LB_TIMER_NONE; ...@@ -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 LRESULT LISTBOX_GetItemRect( const LB_DESCR *descr, INT index, RECT *rect );
static size_t get_sizeof_item( const LB_DESCR *descr )
{
return sizeof(LB_ITEMDATA);
}
static BOOL resize_storage(LB_DESCR *descr, UINT items_size) static BOOL resize_storage(LB_DESCR *descr, UINT items_size)
{ {
LB_ITEMDATA *items; LB_ITEMDATA *items;
...@@ -137,7 +142,7 @@ static BOOL resize_storage(LB_DESCR *descr, UINT items_size) ...@@ -137,7 +142,7 @@ static BOOL resize_storage(LB_DESCR *descr, UINT items_size)
items_size = (items_size + LB_ARRAY_GRANULARITY - 1) & ~(LB_ARRAY_GRANULARITY - 1); items_size = (items_size + LB_ARRAY_GRANULARITY - 1) & ~(LB_ARRAY_GRANULARITY - 1);
if ((descr->style & (LBS_NODATA | LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != LBS_NODATA) if ((descr->style & (LBS_NODATA | LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != LBS_NODATA)
{ {
items = heap_realloc(descr->items, items_size * sizeof(LB_ITEMDATA)); items = heap_realloc(descr->items, items_size * get_sizeof_item(descr));
if (!items) if (!items)
{ {
SEND_NOTIFICATION(descr, LBN_ERRSPACE); SEND_NOTIFICATION(descr, LBN_ERRSPACE);
...@@ -151,7 +156,7 @@ static BOOL resize_storage(LB_DESCR *descr, UINT items_size) ...@@ -151,7 +156,7 @@ static BOOL resize_storage(LB_DESCR *descr, UINT items_size)
if ((descr->style & LBS_NODATA) && descr->items && items_size > descr->nb_items) if ((descr->style & LBS_NODATA) && descr->items && items_size > descr->nb_items)
{ {
memset(&descr->items[descr->nb_items], 0, memset(&descr->items[descr->nb_items], 0,
(items_size - descr->nb_items) * sizeof(LB_ITEMDATA)); (items_size - descr->nb_items) * get_sizeof_item(descr));
} }
return TRUE; return TRUE;
} }
...@@ -201,24 +206,26 @@ static void set_item_selected_state(LB_DESCR *descr, UINT index, BOOL state) ...@@ -201,24 +206,26 @@ static void set_item_selected_state(LB_DESCR *descr, UINT index, BOOL state)
static void insert_item_data(LB_DESCR *descr, UINT index) static void insert_item_data(LB_DESCR *descr, UINT index)
{ {
size_t size = get_sizeof_item(descr);
LB_ITEMDATA *item; LB_ITEMDATA *item;
if (!descr->items) return; if (!descr->items) return;
item = descr->items + index; item = descr->items + index;
if (index < descr->nb_items) if (index < descr->nb_items)
memmove(item + 1, item, (descr->nb_items - index) * sizeof(LB_ITEMDATA)); memmove(item + 1, item, (descr->nb_items - index) * size);
} }
static void remove_item_data(LB_DESCR *descr, UINT index) static void remove_item_data(LB_DESCR *descr, UINT index)
{ {
size_t size = get_sizeof_item(descr);
LB_ITEMDATA *item; LB_ITEMDATA *item;
if (!descr->items) return; if (!descr->items) return;
item = descr->items + index; item = descr->items + index;
if (index < descr->nb_items) if (index < descr->nb_items)
memmove(item, item + 1, (descr->nb_items - index) * sizeof(LB_ITEMDATA)); memmove(item, item + 1, (descr->nb_items - index) * size);
} }
/*********************************************************************** /***********************************************************************
......
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