]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
Added newtListboxClear - it seems to be done frequently via
authorsopwith <sopwith>
Wed, 30 Jul 1997 05:17:28 +0000 (05:17 +0000)
committersopwith <sopwith>
Wed, 30 Jul 1997 05:17:28 +0000 (05:17 +0000)
newtListboxDeleteEntry from apps.

listbox.c
newt.h

index 46f59db7495e7b3cb0f561050192a4b6783a5c77..2a9d90d4af4b3994f382ebd5687e83c8bb438a33 100644 (file)
--- 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 4beb2e3087a7b409fb69f64ece66aa30ef66e127..d0dc528e6a256268ac1770ded2f1e479144da7d5 100644 (file)
--- 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);