From: ewt Date: Mon, 3 Nov 1997 15:42:20 +0000 (+0000) Subject: added newtListboxSetCurrentByKey() X-Git-Tag: r0-20~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d58783651f325a50d16b4a4845a486a4811d5b59;p=thirdparty%2Fnewt.git added newtListboxSetCurrentByKey() --- diff --git a/listbox.c b/listbox.c index f15c5dc..3fb300d 100644 --- a/listbox.c +++ b/listbox.c @@ -135,9 +135,23 @@ static inline void updateWidth(newtComponent co, struct listbox * li, li->sb->left = co->left + co->width - 1; } +void newtListboxSetCurrentByKey(newtComponent co, void * key) { + struct listbox * li = co->data; + struct items * item; + int i; + + item = li->boxItems, i = 0; + while (item && item->data != key) + item = item->next, i++; + + if (item) + newtListboxSetCurrent(co, i); +} + void newtListboxSetCurrent(newtComponent co, int num) { struct listbox * li = co->data; + if (num >= li->numItems) li->currItem = li->numItems - 1; else if (num < 0) @@ -153,13 +167,14 @@ void newtListboxSetCurrent(newtComponent co, int num) li->startShowItem = li->numItems - co->height; if(li->startShowItem < 0) li->startShowItem = 0; + newtListboxRealSetCurrent(co); } -static void -newtListboxRealSetCurrent(newtComponent co) +static void newtListboxRealSetCurrent(newtComponent co) { struct listbox * li = co->data; + if(li->sb) newtScrollbarSet(li->sb, li->currItem + 1, li->numItems); listboxDraw(co); diff --git a/newt.h b/newt.h index 9b3f6d7..f43813c 100644 --- a/newt.h +++ b/newt.h @@ -134,6 +134,7 @@ void newtScrollbarSet(newtComponent co, int where, int total); newtComponent newtListbox(int left, int top, int height, int flags); void * newtListboxGetCurrent(newtComponent co); void newtListboxSetCurrent(newtComponent co, int num); +void newtListboxSetCurrentByKey(newtComponent co, void * key); void newtListboxSetText(newtComponent co, int num, const char * text); void newtListboxSetEntry(newtComponent co, int num, const char * text); void newtListboxSetWidth(newtComponent co, int width);