From: ewt Date: Thu, 1 Feb 2001 20:46:44 +0000 (+0000) Subject: added newtCheckboxTreeSetCurrent() and snack binding X-Git-Tag: r0-50-20~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5160fc228f93d9e016bc8220e7e394eb53319f90;p=thirdparty%2Fnewt.git added newtCheckboxTreeSetCurrent() and snack binding --- diff --git a/CHANGES b/CHANGES index c14da3d..1b581a9 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,8 @@ -1.59 -> 0.50.10 +*************** +THIS FILE IS OBSOLETE -- UPDATE THE SPEC FILE INSTEAD +*************** + +0.59 -> 0.50.10 - added support for help - added cusor on/off stuff diff --git a/checkboxtree.c b/checkboxtree.c index d9cdaca..e70e54e 100644 --- a/checkboxtree.c +++ b/checkboxtree.c @@ -18,8 +18,6 @@ struct items { struct CheckboxTree { newtComponent sb; - int curWidth; /* size of text w/o scrollbar or border*/ - int curHeight; /* size of text w/o border */ struct items * itemlist; struct items ** flatList, ** currItem, ** firstItem; int flatCount; @@ -712,3 +710,43 @@ void newtCheckboxTreeSetEntryValue(newtComponent co, const void * data, char val ctDraw(co); } + +void newtCheckboxTreeSetCurrent(newtComponent co, void * data) { + struct CheckboxTree * ct = co->data; + int * path; + int i, j, itemsAfter; + struct items * treeTop, * item; + + path = newtCheckboxTreeFindItem(co, data); + if (!path) return; + + /* traverse the path and turn on all of the branches to this point */ + for (i = 0, treeTop = ct->itemlist; path[i + 1] != NEWT_ARG_LAST; i++) { + for (j = 0, item = treeTop; j < path[i]; j++) + item = item->next; + + item->selected = 1; + treeTop = item->branch; + } + + buildFlatList(co); + + item = findItem(ct->itemlist, data); + + i = 0; + while (ct->flatList[i] != item) i++; + + /* choose the top item */ + j = i - (co->height / 2); + + if ((j + co->height) > ct->flatCount) + j = ct->flatCount - co->height; + + if (j < 0) + j = 0; + + ct->firstItem = ct->flatList + j; + ct->currItem = ct->flatList + i; + + ctDraw(co); +} diff --git a/newt.h b/newt.h index 58ad90a..afa972b 100644 --- a/newt.h +++ b/newt.h @@ -178,6 +178,7 @@ newtComponent newtCheckboxTree(int left, int top, int height, int flags); newtComponent newtCheckboxTreeMulti(int left, int top, int height, char *seq, int flags); const void ** newtCheckboxTreeGetSelection(newtComponent co, int *numitems); const void * newtCheckboxTreeGetCurrent(newtComponent co); +void newtCheckboxTreeSetCurrent(newtComponent co, void * item); const void ** newtCheckboxTreeGetMultiSelection(newtComponent co, int *numitems, char seqnum); /* last item is NEWT_ARG_LAST for all of these */ int newtCheckboxTreeAddItem(newtComponent co, diff --git a/newt.spec b/newt.spec index 0d66574..f137210 100644 --- a/newt.spec +++ b/newt.spec @@ -1,6 +1,6 @@ Summary: A development library for text mode user interfaces. Name: newt -%define version 0.50.19 +%define version 0.50.20 Version: %{version} Release: 3 Copyright: LGPL @@ -104,6 +104,10 @@ rm -rf $RPM_BUILD_ROOT %endif %changelog +* Thu Feb 01 2001 Erik Troan +- gave up on separate CHANGES file +- added newtCheckboxTreeSetCurrent() and snack binding + * Mon Jan 22 2001 Than Ngo - don't build newt-python2 sub package. diff --git a/snack.py b/snack.py index b819d8e..9c6efac 100644 --- a/snack.py +++ b/snack.py @@ -467,6 +467,9 @@ class CheckboxTree(Widget): def setEntry(self, item, text): self.w.checkboxtreeSetEntry(self.item2key[item], text) + def setCurrent(self, item): + self.w.checkboxtreeSetCurrent(self.item2key[item]) + def setEntryValue(self, item, selected = 1): self.w.checkboxtreeSetEntryValue(self.item2key[item], selected) diff --git a/snackmodule.c b/snackmodule.c index a02ec05..6749119 100644 --- a/snackmodule.c +++ b/snackmodule.c @@ -184,6 +184,7 @@ static PyObject * widgetCheckboxTreeAddItem(snackWidget * s, PyObject * args); static PyObject * widgetCheckboxTreeGetSel(snackWidget * s, PyObject * args); static PyObject * widgetCheckboxTreeGetCur(snackWidget * s, PyObject * args); static PyObject * widgetCheckboxTreeSetEntry(snackWidget * s, PyObject * args); +static PyObject * widgetCheckboxTreeSetCurrent(snackWidget * s, PyObject * args); static PyObject * widgetCheckboxTreeSetEntryValue(snackWidget * s, PyObject * args); static PyObject * widgetCheckboxTreeGetEntryValue(snackWidget * s, PyObject * args); static PyObject * widgetEntrySetFlags(snackWidget * s, PyObject * args); @@ -210,6 +211,8 @@ static PyMethodDef widgetMethods[] = { METH_VARARGS, NULL }, { "checkboxtreeSetEntry", (PyCFunction) widgetCheckboxTreeSetEntry, METH_VARARGS, NULL }, + { "checkboxtreeSetCurrent", (PyCFunction) widgetCheckboxTreeSetCurrent, + METH_VARARGS, NULL }, { "checkboxtreeSetEntryValue", (PyCFunction) widgetCheckboxTreeSetEntryValue, METH_VARARGS, NULL }, { "checkboxtreeGetSelection", (PyCFunction) widgetCheckboxTreeGetSel, @@ -1044,6 +1047,17 @@ static PyObject * widgetCheckboxTreeSetEntry(snackWidget * s, PyObject * args) { return Py_None; } +static PyObject * widgetCheckboxTreeSetCurrent(snackWidget * s, PyObject * args) { + int data; + + if (!PyArg_ParseTuple(args, "i", &data)) return NULL; + + newtCheckboxTreeSetCurrent(s->co, (void *)data); + + Py_INCREF(Py_None); + return Py_None; +} + static PyObject * widgetCheckboxTreeSetEntryValue(snackWidget * s, PyObject * args) { int data; int isOn = 1; diff --git a/testtree.c b/testtree.c index 4beecc4..70523d7 100644 --- a/testtree.c +++ b/testtree.c @@ -43,13 +43,14 @@ int main(void) { newtCheckboxTreeAddItem(checktree, "Donuts", (void *) 12, NEWT_FLAG_SELECTED, NEWT_ARG_APPEND, NEWT_ARG_LAST); - newtCheckboxTreeAddItem(checktree, "Bavarian Cream", (void *) 12, + + newtCheckboxTreeAddItem(checktree, "Bavarian Cream", (void *) 301, NEWT_FLAG_SELECTED, 9, NEWT_ARG_APPEND, NEWT_ARG_LAST); - newtCheckboxTreeAddItem(checktree, "Honey dipped", (void *) 12, + newtCheckboxTreeAddItem(checktree, "Honey dipped", (void *) 302, NEWT_FLAG_SELECTED, 9, NEWT_ARG_APPEND, NEWT_ARG_LAST); - newtCheckboxTreeAddItem(checktree, "Jelly", (void *) 12, + newtCheckboxTreeAddItem(checktree, "Jelly", (void *) 303, NEWT_FLAG_SELECTED, 9, NEWT_ARG_APPEND, NEWT_ARG_LAST); @@ -87,6 +88,8 @@ int main(void) { newtCheckboxTreeAddItem(checktree, "Thirteen", (void *) 213, 0, 1, 1, NEWT_ARG_APPEND, NEWT_ARG_LAST); + newtCheckboxTreeSetCurrent(checktree, (void *) 12); + button = newtButton(-1, -1, "Exit"); grid = newtCreateGrid(1, 2);