]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
added newtCheckboxTreeSetCurrent() and snack binding
authorewt <ewt>
Thu, 1 Feb 2001 20:46:44 +0000 (20:46 +0000)
committerewt <ewt>
Thu, 1 Feb 2001 20:46:44 +0000 (20:46 +0000)
CHANGES
checkboxtree.c
newt.h
newt.spec
snack.py
snackmodule.c
testtree.c

diff --git a/CHANGES b/CHANGES
index c14da3dfff2313ed65bf3c1437f8a6dbf206c4ba..1b581a9080b3b0f2ba18c655adf405f3637263fb 100644 (file)
--- 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
 
index d9cdacaa7cbac87aae4877c6cce198123159a786..e70e54ebfe78d3928167170d6fa60fdcdb4d9706 100644 (file)
@@ -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 58ad90a5c88ffd04384f191357f0c04a926b1a9a..afa972bd273279561b195e73dab171b4a866c339 100644 (file)
--- 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, 
index 0d66574db942e2f0b52169c425ed2f5fb1e9dd93..f137210bee55ac517527b163025b3071ed09c89e 100644 (file)
--- 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 <ewt@redhat.com>
+- gave up on separate CHANGES file
+- added newtCheckboxTreeSetCurrent() and snack binding
+
 * Mon Jan 22 2001 Than Ngo <than@redhat.com>
 - don't build newt-python2 sub package.
 
index b819d8e5c48cd1b6ceb2a5776c5a44ddbc3313ef..9c6efac4b782f5d7866432909461d650bd339024 100644 (file)
--- 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)
 
index a02ec0536cb1c6340e88cb3a6fb6cc4062f9c3cf..6749119cdbcc3b82bd834973a9d5d1c9c5ed372e 100644 (file)
@@ -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;
index 4beecc4d717310b6efe3e4124f969aeaeb212fe1..70523d71e622ae99e3dff2a2c631401601f2b3a1 100644 (file)
@@ -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);