Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com ---
The case where count < descr->nb_items isn't really optimal, just stops redrawing right now. The other case (growing) should be optimal now, though.
dlls/comctl32/listbox.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/dlls/comctl32/listbox.c b/dlls/comctl32/listbox.c index 2137ef8..01588bb 100644 --- a/dlls/comctl32/listbox.c +++ b/dlls/comctl32/listbox.c @@ -1758,18 +1758,31 @@ static LRESULT LISTBOX_SetCount( LB_DESCR *descr, INT count ) return LB_ERR; }
- /* FIXME: this is far from optimal... */ if (count > descr->nb_items) { - while (count > descr->nb_items) - if ((ret = LISTBOX_InsertString( descr, -1, 0 )) < 0) - return ret; + INT num = descr->nb_items; + if ((ret = LISTBOX_InitStorage(descr, count - num)) != LB_OKAY) + return ret; + memset(&descr->items[num], 0, (count - num) * sizeof(*descr->items)); + descr->nb_items = count; + + LISTBOX_UpdateScroll(descr); + LISTBOX_InvalidateItems(descr, num); + + /* If listbox was empty, set focus to the first item */ + if (count == 1) LISTBOX_SetCaretIndex(descr, 0, FALSE); } else if (count < descr->nb_items) { + /* FIXME: This is not really optimal */ + DWORD oldstyle = descr->style; + LISTBOX_SetRedraw(descr, FALSE); + while (count < descr->nb_items) if ((ret = LISTBOX_RemoveItem( descr, (descr->nb_items - 1) )) < 0) - return ret; + break; + if (!(oldstyle & LBS_NOREDRAW)) LISTBOX_SetRedraw(descr, TRUE); + if (ret < 0) return ret; }
InvalidateRect( descr->self, NULL, TRUE );