comctl32/listbox: Store the items array size instead of using HeapSize().

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Gabriel Ivăncescu 2018-11-28 14:09:15 +03:00 committed by Alexandre Julliard
parent 40e16ac150
commit ece6dfe52c
1 changed files with 14 additions and 7 deletions

View File

@ -72,6 +72,7 @@ typedef struct
INT height; /* Window height */ INT height; /* Window height */
LB_ITEMDATA *items; /* Array of items */ LB_ITEMDATA *items; /* Array of items */
INT nb_items; /* Number of items */ INT nb_items; /* Number of items */
UINT items_size; /* Total number of allocated items in the array */
INT top_item; /* Top visible item */ INT top_item; /* Top visible item */
INT selected_item; /* Selected item */ INT selected_item; /* Selected item */
INT focus_item; /* Item that has the focus */ INT focus_item; /* Item that has the focus */
@ -688,7 +689,7 @@ static LRESULT LISTBOX_InitStorage( LB_DESCR *descr, INT nb_items )
nb_items += LB_ARRAY_GRANULARITY - 1; nb_items += LB_ARRAY_GRANULARITY - 1;
nb_items -= (nb_items % LB_ARRAY_GRANULARITY); nb_items -= (nb_items % LB_ARRAY_GRANULARITY);
if (descr->items) { if (descr->items) {
nb_items += HeapSize( GetProcessHeap(), 0, descr->items ) / sizeof(*item); nb_items += descr->items_size;
item = HeapReAlloc( GetProcessHeap(), 0, descr->items, item = HeapReAlloc( GetProcessHeap(), 0, descr->items,
nb_items * sizeof(LB_ITEMDATA)); nb_items * sizeof(LB_ITEMDATA));
} }
@ -702,6 +703,7 @@ static LRESULT LISTBOX_InitStorage( LB_DESCR *descr, INT nb_items )
SEND_NOTIFICATION( descr, LBN_ERRSPACE ); SEND_NOTIFICATION( descr, LBN_ERRSPACE );
return LB_ERRSPACE; return LB_ERRSPACE;
} }
descr->items_size = nb_items;
descr->items = item; descr->items = item;
return LB_OKAY; return LB_OKAY;
} }
@ -1528,12 +1530,10 @@ static LRESULT LISTBOX_InsertItem( LB_DESCR *descr, INT index,
if (index == -1) index = descr->nb_items; if (index == -1) index = descr->nb_items;
else if ((index < 0) || (index > descr->nb_items)) return LB_ERR; else if ((index < 0) || (index > descr->nb_items)) return LB_ERR;
if (!descr->items) max_items = 0; if (descr->nb_items == descr->items_size)
else max_items = HeapSize( GetProcessHeap(), 0, descr->items ) / sizeof(*item);
if (descr->nb_items == max_items)
{ {
/* We need to grow the array */ /* We need to grow the array */
max_items += LB_ARRAY_GRANULARITY; max_items = descr->items_size + LB_ARRAY_GRANULARITY;
if (descr->items) if (descr->items)
item = HeapReAlloc( GetProcessHeap(), 0, descr->items, item = HeapReAlloc( GetProcessHeap(), 0, descr->items,
max_items * sizeof(LB_ITEMDATA) ); max_items * sizeof(LB_ITEMDATA) );
@ -1545,6 +1545,7 @@ static LRESULT LISTBOX_InsertItem( LB_DESCR *descr, INT index,
SEND_NOTIFICATION( descr, LBN_ERRSPACE ); SEND_NOTIFICATION( descr, LBN_ERRSPACE );
return LB_ERRSPACE; return LB_ERRSPACE;
} }
descr->items_size = max_items;
descr->items = item; descr->items = item;
} }
@ -1704,13 +1705,17 @@ static LRESULT LISTBOX_RemoveItem( LB_DESCR *descr, INT index )
/* Shrink the item array if possible */ /* Shrink the item array if possible */
max_items = HeapSize( GetProcessHeap(), 0, descr->items ) / sizeof(LB_ITEMDATA); max_items = descr->items_size;
if (descr->nb_items < max_items - 2*LB_ARRAY_GRANULARITY) if (descr->nb_items < max_items - 2*LB_ARRAY_GRANULARITY)
{ {
max_items -= LB_ARRAY_GRANULARITY; max_items -= LB_ARRAY_GRANULARITY;
item = HeapReAlloc( GetProcessHeap(), 0, descr->items, item = HeapReAlloc( GetProcessHeap(), 0, descr->items,
max_items * sizeof(LB_ITEMDATA) ); max_items * sizeof(LB_ITEMDATA) );
if (item) descr->items = item; if (item)
{
descr->items_size = max_items;
descr->items = item;
}
} }
/* Repaint the items */ /* Repaint the items */
@ -1756,6 +1761,7 @@ static void LISTBOX_ResetContent( LB_DESCR *descr )
descr->selected_item = -1; descr->selected_item = -1;
descr->focus_item = 0; descr->focus_item = 0;
descr->anchor_item = -1; descr->anchor_item = -1;
descr->items_size = 0;
descr->items = NULL; descr->items = NULL;
} }
@ -2493,6 +2499,7 @@ static BOOL LISTBOX_Create( HWND hwnd, LPHEADCOMBO lphc )
descr->width = rect.right - rect.left; descr->width = rect.right - rect.left;
descr->height = rect.bottom - rect.top; descr->height = rect.bottom - rect.top;
descr->items = NULL; descr->items = NULL;
descr->items_size = 0;
descr->nb_items = 0; descr->nb_items = 0;
descr->top_item = 0; descr->top_item = 0;
descr->selected_item = -1; descr->selected_item = -1;