Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/user32/listbox.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/dlls/user32/listbox.c b/dlls/user32/listbox.c index c8bd148..a8de8d3 100644 --- a/dlls/user32/listbox.c +++ b/dlls/user32/listbox.c @@ -1763,18 +1763,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 );