]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
added 'hide_checkbox' and 'unselectable' options to CheckboxTree r0-50-28
authorcrutcher <crutcher>
Thu, 5 Jul 2001 16:30:36 +0000 (16:30 +0000)
committercrutcher <crutcher>
Thu, 5 Jul 2001 16:30:36 +0000 (16:30 +0000)
checkboxtree.c
newt.h
newt.spec
snack.py
snackmodule.c

index cf3ff41d7c711cdb7e7e3c96ea5906caefe903f1..c5131c71ee7c1441d24d52da17d5f6802258e6fa 100644 (file)
@@ -316,10 +316,13 @@ newtComponent newtCheckboxTreeMulti(int left, int top, int height, char *seq, in
     ct->firstItem = NULL;
     ct->currItem = NULL;
     ct->flatList = NULL;
-       if (seq)
-         ct->seq = strdup(seq);
-       else
-         ct->seq = strdup(" *");
+
+    ct->flags = flags;
+
+    if (seq)
+       ct->seq = strdup(seq);
+    else
+       ct->seq = strdup(" *");
     if (flags & NEWT_FLAG_SCROLL) {
        ct->sb = newtVerticalScrollbar(left, top, height,
                                       COLORSET_LISTBOX, COLORSET_ACTLISTBOX);
@@ -369,7 +372,7 @@ int ctSetItem(newtComponent co, struct items *item, enum newtFlagsSense sense)
        case NEWT_FLAGS_TOGGLE:
            if (item->branch)
              item->selected = !item->selected;
-           else {
+           else if (!(ct->flags & NEWT_CHECKBOXTREE_UNSELECTABLE)) {
                    item->selected++;
                    if (item->selected==strlen(ct->seq))
                      item->selected = 0;
@@ -444,13 +447,21 @@ static void ctDraw(newtComponent co) {
            else
                SLsmg_write_string("<+> ");
        } else {
-           char tmp[5];
-           snprintf(tmp,5,"[%c] ",ct->seq[(*item)->selected]);
-           SLsmg_write_string(tmp);
+           if (ct->flags & NEWT_CHECKBOXTREE_HIDE_BOX) {
+               if ((*item)->selected)
+                   SLsmg_set_color(NEWT_COLORSET_ACTLISTBOX);
+           } else {
+               char tmp[5];
+               snprintf(tmp,5,"[%c] ",ct->seq[(*item)->selected]);
+               SLsmg_write_string(tmp);
+           }
        }
 
        SLsmg_write_nstring((*item)->text, co->width - 4 - 
                                           (3 * (*item)->depth));
+
+       SLsmg_set_color(NEWT_COLORSET_LISTBOX);
+
        item++;
        i++;
     }
diff --git a/newt.h b/newt.h
index 3854240114e0d906c96a0e71be03acef54d06038..22aa24a45aaa26f3fb0ed65d29689b969b88f84f 100644 (file)
--- a/newt.h
+++ b/newt.h
@@ -77,6 +77,9 @@ enum newtFlagsSense { NEWT_FLAGS_SET, NEWT_FLAGS_RESET, NEWT_FLAGS_TOGGLE };
 #define NEWT_FD_WRITE          (1 << 1)
 #define NEWT_FD_EXCEPT         (1 << 2)
 
+#define NEWT_CHECKBOXTREE_UNSELECTABLE (1 << 12)
+#define NEWT_CHECKBOXTREE_HIDE_BOX     (1 << 13)
+
 #define NEWT_CHECKBOXTREE_COLLAPSED    '\0'
 #define NEWT_CHECKBOXTREE_EXPANDED     '\1'
 #define NEWT_CHECKBOXTREE_UNSELECTED   ' '
@@ -194,7 +197,7 @@ void newtCheckboxTreeSetEntry(newtComponent co, const void * data,
 char newtCheckboxTreeGetEntryValue(newtComponent co, const void * data);
 void newtCheckboxTreeSetEntryValue(newtComponent co, const void * data,
                                   char value);
-    
 newtComponent newtTextboxReflowed(int left, int top, char * text, int width,
                                  int flexDown, int flexUp, int flags);
 newtComponent newtTextbox(int left, int top, int width, int height, int flags);
index 185ad8f186ae2c37c924fd08b868eb13e093f505..47f16d3cadfa8d6e8f99e65fe38e320296a28904 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.27
+%define version 0.50.28
 Version: %{version}
 Release: 1
 Copyright: LGPL
@@ -105,6 +105,9 @@ rm -rf $RPM_BUILD_ROOT
 %endif
 
 %changelog
+* Thu Jul 05 2001 Crutcher Dunnavant <crutcher@redhat.com>
+- added 'hide_checkbox' and 'unselectable' options to CheckboxTrees
+
 * Mon Jun 25 2001 Jeremy Katz <katzj@redhat.com>
 - ClistBox -> Clistbox for API consistency
 - fixup replace() method of Clistbox
index 04607569ead758a4e666e0671cab8830b19987b2..2b39821a19646ca0fb33e84ed95f3970d40690a3 100644 (file)
--- a/snack.py
+++ b/snack.py
@@ -477,8 +477,8 @@ class CheckboxTree(Widget):
        curr = self.w.checkboxtreeGetCurrent()
        return self.key2item[curr]
 
-    def __init__(self, height, scroll = 0):
-       self.w = _snack.checkboxtree(height, scroll)
+    def __init__(self, height, scroll = 0, hide_checkbox = 0, unselectable = 0):
+       self.w = _snack.checkboxtree(height, scroll, hide_checkbox, unselectable)
        self.key2item = {}
        self.item2key = {}
 
index d42d52bb2dc9dcfd8700f1f09955cab9320303c2..db27b6cfe3e3f8e58115d2bc03cf5aff386b19fc 100644 (file)
@@ -55,7 +55,7 @@ static PyObject * setHelpCallback(PyObject * s, PyObject * args);
 static PyObject * reflowText(PyObject * s, PyObject * args);
 static snackWidget * textWidget(PyObject * s, PyObject * args);
 static PyObject * ternaryWindow(PyObject * s, PyObject * args);
-static snackWidget * checkboxTreeWidget(PyObject * s, PyObject * args);
+static snackWidget * checkboxTreeWidget(PyObject * s, PyObject * args, PyObject * kwargs);
 
 static PyMethodDef snackModuleMethods[] = {
     { "button", (PyCFunction) buttonWidget, METH_VARARGS, NULL },
@@ -88,7 +88,7 @@ static PyMethodDef snackModuleMethods[] = {
     { "suspendcallback", setSuspendCallback, METH_VARARGS, NULL },
     { "ternary", ternaryWindow, METH_VARARGS, NULL },
     { "textbox", (PyCFunction) textWidget, METH_VARARGS, NULL },
-    { "checkboxtree", (PyCFunction) checkboxTreeWidget, METH_VARARGS, NULL },
+    { "checkboxtree", (PyCFunction) checkboxTreeWidget, METH_VARARGS | METH_KEYWORDS, NULL },
     { NULL }
 } ;
 
@@ -225,7 +225,7 @@ static PyMethodDef widgetMethods[] = {
     { "checkboxtreeSetEntryValue", (PyCFunction) widgetCheckboxTreeSetEntryValue,
       METH_VARARGS, NULL },
     { "checkboxtreeGetSelection", (PyCFunction) widgetCheckboxTreeGetSel,
-      METH_VARARGS, NULL },
+      METH_VARARGS, NULL },  
     { "entrySetFlags", (PyCFunction) widgetEntrySetFlags, METH_VARARGS, NULL },
     { "checkboxSetFlags", (PyCFunction) widgetCheckboxSetFlags, METH_VARARGS, NULL },
     { "checkboxSetValue", (PyCFunction) widgetCheckboxSetValue, METH_VARARGS, NULL },
@@ -1031,17 +1031,25 @@ static PyObject * widgetListboxClear(snackWidget * s, PyObject * args) {
 static void emptyDestructor(PyObject * s) {
 }
 
-static snackWidget * checkboxTreeWidget(PyObject * s, PyObject * args) {
+static snackWidget * checkboxTreeWidget(PyObject * s, PyObject * args, PyObject * kwargs) {
     int height;
     int scrollBar = 0;
+    int hide_checkbox = 0;
+    int unselectable = 0;
+    int flags;
     snackWidget * widget;
+    const char *kw[] = {"height", "scrollbar", "hide_checkbox", "unselectable", NULL};
     
-    if (!PyArg_ParseTuple(args, "i|i", &height, &scrollBar))
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i|iii", (char **) kw,
+               &height, &scrollBar, &hide_checkbox, &unselectable))
        return NULL;
 
+    flags = (scrollBar ? NEWT_FLAG_SCROLL : 0) |
+       (hide_checkbox ? NEWT_CHECKBOXTREE_HIDE_BOX : 0) |    
+       (unselectable ? NEWT_CHECKBOXTREE_UNSELECTABLE : 0);
+
     widget = snackWidgetNew ();
-    widget->co = newtCheckboxTree(-1, -1, height,
-                                 scrollBar ? NEWT_FLAG_SCROLL : 0);
+    widget->co = newtCheckboxTree(-1, -1, height, flags);
 
     widget->anint = 1;