From: sopwith Date: Mon, 18 Aug 1997 20:16:36 +0000 (+0000) Subject: More misc listbox changes. X-Git-Tag: r0-12~47 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cb586ef61fdc58daa80808949bfc5923bc92d24a;p=thirdparty%2Fnewt.git More misc listbox changes. --- diff --git a/listbox.c b/listbox.c index a116307..272fc3e 100644 --- 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 8136b24..10eaf67 100644 --- 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 7b246dd..4ff32e5 100644 --- 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]); } }