user32/listbox: Resize the entire item array at once in SetCount.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com> Signed-off-by: Huw Davies <huw@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
f72204abd6
commit
3ef790b968
|
@ -139,6 +139,12 @@ static BOOL resize_storage(LB_DESCR *descr, UINT items_size)
|
||||||
descr->items_size = items_size;
|
descr->items_size = items_size;
|
||||||
descr->items = items;
|
descr->items = items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((descr->style & LBS_NODATA) && items_size > descr->nb_items)
|
||||||
|
{
|
||||||
|
memset(&descr->items[descr->nb_items], 0,
|
||||||
|
(items_size - descr->nb_items) * sizeof(LB_ITEMDATA));
|
||||||
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1751,9 +1757,9 @@ static void LISTBOX_ResetContent( LB_DESCR *descr )
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* LISTBOX_SetCount
|
* LISTBOX_SetCount
|
||||||
*/
|
*/
|
||||||
static LRESULT LISTBOX_SetCount( LB_DESCR *descr, INT count )
|
static LRESULT LISTBOX_SetCount( LB_DESCR *descr, UINT count )
|
||||||
{
|
{
|
||||||
LRESULT ret;
|
UINT orig_num = descr->nb_items;
|
||||||
|
|
||||||
if (!(descr->style & LBS_NODATA))
|
if (!(descr->style & LBS_NODATA))
|
||||||
{
|
{
|
||||||
|
@ -1761,19 +1767,30 @@ static LRESULT LISTBOX_SetCount( LB_DESCR *descr, INT count )
|
||||||
return LB_ERR;
|
return LB_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME: this is far from optimal... */
|
if (!resize_storage(descr, count))
|
||||||
if (count > descr->nb_items)
|
return LB_ERRSPACE;
|
||||||
|
descr->nb_items = count;
|
||||||
|
|
||||||
|
if (count)
|
||||||
{
|
{
|
||||||
while (count > descr->nb_items)
|
LISTBOX_UpdateScroll(descr);
|
||||||
if ((ret = LISTBOX_InsertString( descr, -1, 0 )) < 0)
|
if (count < orig_num)
|
||||||
return ret;
|
{
|
||||||
}
|
descr->anchor_item = min(descr->anchor_item, count - 1);
|
||||||
else if (count < descr->nb_items)
|
if (descr->selected_item >= count)
|
||||||
{
|
descr->selected_item = -1;
|
||||||
while (count < descr->nb_items)
|
|
||||||
if ((ret = LISTBOX_RemoveItem( descr, (descr->nb_items - 1) )) < 0)
|
/* If we removed the scrollbar, reset the top of the list */
|
||||||
return ret;
|
if (count <= descr->page_size && orig_num > descr->page_size)
|
||||||
|
LISTBOX_SetTopItem(descr, 0, TRUE);
|
||||||
|
|
||||||
|
descr->focus_item = min(descr->focus_item, count - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If it was empty before growing, set focus to the first item */
|
||||||
|
else if (orig_num == 0) LISTBOX_SetCaretIndex(descr, 0, FALSE);
|
||||||
}
|
}
|
||||||
|
else SendMessageW(descr->self, LB_RESETCONTENT, 0, 0);
|
||||||
|
|
||||||
InvalidateRect( descr->self, NULL, TRUE );
|
InvalidateRect( descr->self, NULL, TRUE );
|
||||||
return LB_OKAY;
|
return LB_OKAY;
|
||||||
|
|
Loading…
Reference in New Issue