]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
added newtListboxSetCurrentByKey()
authorewt <ewt>
Mon, 3 Nov 1997 15:42:20 +0000 (15:42 +0000)
committerewt <ewt>
Mon, 3 Nov 1997 15:42:20 +0000 (15:42 +0000)
listbox.c
newt.h

index f15c5dc4ac533e6d0358aea3b6f9c56c03711274..3fb300dcb7febc4418849d2180e5efc32fe3f6c4 100644 (file)
--- 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 9b3f6d789d650ebc7e94472c0f646eaf3e957302..f43813cf15e2283f5878477d57b42f1f01d7f6ce 100644 (file)
--- 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);