From 7ea3dccd74b5fdcef5425d16ace7635ac5fa8b0c Mon Sep 17 00:00:00 2001 From: ewt Date: Thu, 20 Jun 1996 02:49:26 +0000 Subject: [PATCH] added newtFormSetCurrent(), newtListboxSetCurrent() --- form.c | 19 +++++++++++++++++++ listbox.c | 6 ++++++ newt.h | 2 ++ 3 files changed, 27 insertions(+) diff --git a/form.c b/form.c index bf355f9..4f8577c 100644 --- a/form.c +++ b/form.c @@ -88,6 +88,25 @@ newtComponent newtFormGetCurrent(newtComponent co) { return form->elements[form->currComp].co; } +void newtFormSetCurrent(newtComponent co, newtComponent subco) { + struct form * form = co->data; + int i, new; + + for (i = 0; i < form->numComps; i++) { + if (form->elements[i].co == subco) break; + } + + if (form->elements[i].co != subco) return; + new = i; + + if (!componentFits(co, new)) { + gotoComponent(form, -1); + form->vertOffset = form->elements[new].top - co->top - 1; + } + + gotoComponent(form, new); +} + void newtFormSetHeight(newtComponent co, int height) { struct form * form = co->data; diff --git a/listbox.c b/listbox.c index 383aea6..fb3a860 100644 --- a/listbox.c +++ b/listbox.c @@ -59,6 +59,12 @@ newtComponent newtListbox(int left, int top, int height, int flags) { return co; } +void newtListboxSetCurrent(newtComponent co, int num) { + struct listbox * li = co->data; + + newtFormSetCurrent(li->form, li->items[num]); +} + void * newtListboxGetCurrent(newtComponent co) { struct listbox * li = co->data; newtComponent curr; diff --git a/newt.h b/newt.h index ec1c932..ff05892 100644 --- a/newt.h +++ b/newt.h @@ -61,6 +61,7 @@ void newtScrollbarSet(newtComponent co, int where, int total); newtComponent newtListbox(int left, int top, int height, int flags); /* return the data passed to AddEntry */ void * newtListboxGetCurrent(newtComponent co); +void newtListboxSetCurrent(newtComponent co, int num); void newtListboxAddEntry(newtComponent co, char * text, void * data); void newtListboxSetEntry(newtComponent co, int num, char * text); @@ -72,6 +73,7 @@ void newtTextboxSetText(newtComponent co, const char * text); newtComponent newtForm(newtComponent vertBar); newtComponent newtFormGetCurrent(newtComponent co); +void newtFormSetCurrent(newtComponent co, newtComponent subco); void newtFormAddComponent(newtComponent form, newtComponent co); void newtFormAddComponents(newtComponent form, ...); void newtFormSetHeight(newtComponent co, int height); -- 2.47.2