From: ewt Date: Sun, 31 Mar 1996 00:51:54 +0000 (+0000) Subject: Initial revision X-Git-Tag: 0-1~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=962b92a599902af65907705e8384862aba3fce83;p=thirdparty%2Fnewt.git Initial revision --- diff --git a/listbox.c b/listbox.c new file mode 100644 index 0000000..79b86d4 --- /dev/null +++ b/listbox.c @@ -0,0 +1,100 @@ +#include +#include +#include + +#include "newt.h" +#include "newt_pr.h" + +struct listbox { + newtComponent * items, form; + int numItems; + int allocedItems; + int flags; + int curr; +}; + +static void listboxDraw(newtComponent co); +static void listboxDestroy(newtComponent co); +static struct eventResult listboxEvent(newtComponent co, struct event ev); + +static struct componentOps listboxOps = { + listboxDraw, + listboxEvent, + listboxDestroy, +} ; + +newtComponent newtListbox(int left, int top, int height, int flags) { + newtComponent co; + struct listbox * li; + + co = malloc(sizeof(*co)); + li = malloc(sizeof(struct listbox)); + + li->allocedItems = 5; + li->numItems = 0; + li->flags = 0; + li->items = malloc(li->allocedItems * sizeof(*li->items)); + li->form = newtForm(); + + if (height) + newtFormSetHeight(li->form, height); + + co->data = li; + co->left = left; + co->top = top; + co->height = li->form->height; + co->width = li->form->width; + co->ops = &listboxOps; + co->takesFocus = 1; + + return co; +} + +void newtListboxAddEntry(newtComponent co, char * text) { + struct listbox * li = co->data; + + if (li->numItems == li->allocedItems) { + li->allocedItems += 5; + li->items = realloc(li->items, li->allocedItems * sizeof(*li->items)); + } + + if (li->numItems) + li->items[li->numItems] = newtListitem(co->left, + li->numItems + co->top, + text, 0, + li->items[li->numItems - 1]); + else + li->items[li->numItems] = newtListitem(co->left, + li->numItems + co->top, + text, 0, NULL); + + /*newtLabelColor(li->items[li->numItems], COLORSET_ACTLISTBOX, + COLORSET_LISTBOX);*/ + + newtFormAddComponent(li->form, li->items[li->numItems]); + li->numItems++; + + co->height = li->form->height; + co->width = li->form->width; +} + +static void listboxDraw(newtComponent co) { + struct listbox * li = co->data; + + li->form->ops->draw(li->form); +} + +static struct eventResult listboxEvent(newtComponent co, struct event ev) { + struct listbox * li = co->data; + + return li->form->ops->event(li->form, ev); +} + +static void listboxDestroy(newtComponent co) { + struct listbox * li = co->data; + + li->form->ops->destroy(li->form); + free(li->items); + free(li); + free(co); +}