]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
More misc listbox changes.
authorsopwith <sopwith>
Mon, 18 Aug 1997 20:16:36 +0000 (20:16 +0000)
committersopwith <sopwith>
Mon, 18 Aug 1997 20:16:36 +0000 (20:16 +0000)
listbox.c
newt.h
test.c

index a116307be68b3da412c2f12c15e383b97e95edf6..272fc3ea639ac7b04409ee8304708598ce2ba192 100644 (file)
--- a/listbox.c
+++ b/listbox.c
@@ -186,24 +186,24 @@ void newtListboxClearSelection(newtComponent co)
 }
 
 /* Free the returned array after use, but NOT the values in the array */
-void ** newtListboxGetSelection(newtComponent co)
+void ** newtListboxGetSelection(newtComponent co, int *numitems)
 {
     struct listbox * li;
     int i;
     void **retval;
     struct items *item;
 
-    if(!co) return NULL;
+    if(!co || !numitems) return NULL;
 
     li = co->data;
     if(!li || !li->numSelected) return NULL;
 
-    retval = malloc((li->numSelected + 1) * sizeof(void *));
+    retval = malloc(li->numSelected * sizeof(void *));
     for(i = 0, item = li->boxItems; item != NULL;
        item = item->next)
        if(item->isSelected)
            retval[i++] = item->data;
-    retval[i] = NULL;
+    *numitems = li->numSelected;
     return retval;
 }
 
diff --git a/newt.h b/newt.h
index 8136b24b33deefa0b202a01316936da155029061..10eaf6778754ed62514d937e8714dc98d87adc57 100644 (file)
--- a/newt.h
+++ b/newt.h
@@ -139,7 +139,7 @@ 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 **newtListboxGetSelection(newtComponent co, int *numitems);
 void newtListboxClearSelection(newtComponent co);
 void newtListboxSelectItem(newtComponent co, int item,
        enum newtFlagsSense sense);
diff --git a/test.c b/test.c
index 7b246dd0284575daf02937e185d56ae0004ed17c..4ff32e5234fb5a8fc5729fa241f9f47ef2204d77 100644 (file)
--- a/test.c
+++ b/test.c
@@ -37,7 +37,7 @@ void main(void) {
     char results[10];
     char * enr2, * enr3, * scaleVal;
     void ** selectedList;
-    int i;
+    int i, numsel;
     char buf[20];
 
     newtInit();
@@ -119,7 +119,7 @@ void main(void) {
     enr2 = strdup(enr2);
     enr3 = strdup(enr3);
 
-    selectedList = newtListboxGetSelection(lb);
+    selectedList = newtListboxGetSelection(lb, &numsel);
 
     newtFormDestroy(f);
 
@@ -133,7 +133,7 @@ void main(void) {
 
     if(selectedList) {
        printf("\nSelected listbox items:\n");
-       for(i = 0; selectedList[i]; i++)
+       for(i = 0; i < numsel; i++)
            puts(selectedList[i]);
     }
 }