From: sopwith Date: Wed, 30 Jul 1997 05:17:28 +0000 (+0000) Subject: Added newtListboxClear - it seems to be done frequently via X-Git-Tag: r0-12~51 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=49a541f29fc8ce34115407af7302f905e947ce6b;p=thirdparty%2Fnewt.git Added newtListboxClear - it seems to be done frequently via newtListboxDeleteEntry from apps. --- diff --git a/listbox.c b/listbox.c index 46f59db..2a9d90d 100644 --- a/listbox.c +++ b/listbox.c @@ -241,6 +241,9 @@ void newtListboxSetData(newtComponent co, int num, void * data) { int newtListboxAddEntry(newtComponent co, char * text, void * data) { struct listbox * li = co->data; +#if 1 + newtListboxInsertEntry(co, text, data, li->numItems + 1); +#else struct items *item; if(li->boxItems) { @@ -270,6 +273,7 @@ int newtListboxAddEntry(newtComponent co, char * text, void * data) { listboxDraw(co); return li->numItems; +#endif } @@ -366,6 +370,23 @@ int newtListboxDeleteEntry(newtComponent co, int num) { return li->numItems; } +void newtListboxClear(newtComponent co) +{ + struct listbox * li; + struct items *anitem, *nextitem; + if(co == NULL || (li = co->data) == NULL) + return; + for(anitem = li->boxItems; anitem != NULL; anitem = nextitem) { + nextitem = anitem->next; + free(anitem->key); + free(anitem); + } + li->numItems = li->numSelected = li->currItem = li->startShowItem = 0; + li->boxItems = NULL; + if(li->userHasSetWidth == 0) + li->curWidth = 0; +} + /* If you don't want to get back the text, pass in NULL for the ptr-ptr. Same goes for the data. */ void newtListboxGetEntry(newtComponent co, int num, char **text, void **data) { diff --git a/newt.h b/newt.h index 4beb2e3..d0dc528 100644 --- a/newt.h +++ b/newt.h @@ -135,6 +135,7 @@ void newtListboxSetData(newtComponent co, int num, void * data); int newtListboxAddEntry(newtComponent co, char * text, void * data); int newtListboxInsertEntry(newtComponent co, char * text, void * data, int num); int newtListboxDeleteEntry(newtComponent co, int num); +void newtListboxClear(newtComponent co); /* removes all entries from listbox */ void newtListboxGetEntry(newtComponent co, int num, char **text, void **data); void **newtListboxGetSelection(newtComponent co); void newtListboxClearSelection(newtComponent co);