]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
added width to CheckboxTree r0-50-29
authorcrutcher <crutcher>
Thu, 5 Jul 2001 19:53:44 +0000 (19:53 +0000)
committercrutcher <crutcher>
Thu, 5 Jul 2001 19:53:44 +0000 (19:53 +0000)
checkboxtree.c
configure.in
newt.h
newt.spec
snack.py
snackmodule.c

index c5131c71ee7c1441d24d52da17d5f6802258e6fa..cc8288d07025b0a41fed220032bfb67bad5b1073 100644 (file)
@@ -22,7 +22,9 @@ struct CheckboxTree {
     struct items ** flatList, ** currItem, ** firstItem;
     int flatCount;
     int flags;
-    int pad;
+    int sbAdjust;
+    int curWidth;
+    int userHasSetWidth;
     char * seq;
     char * result;
 };
@@ -37,6 +39,8 @@ static void buildFlatList(newtComponent co);
 static void doBuildFlatList(struct CheckboxTree * ct, struct items * item);
 enum countWhat { COUNT_EXPOSED=0, COUNT_SELECTED=1 };
 static int countItems(struct items * item, enum countWhat justExposed);
+static inline void updateWidth(newtComponent co, struct CheckboxTree * ct,
+                               int maxField);
 
 static struct componentOps ctOps = {
     ctDraw,
@@ -46,6 +50,15 @@ static struct componentOps ctOps = {
     ctMapped,
 } ;
 
+static inline void updateWidth(newtComponent co, struct CheckboxTree * ct,
+                               int maxField) {
+    ct->curWidth = maxField;
+    co->width = ct->curWidth + ct->sbAdjust;
+
+    if (ct->sb)
+       ct->sb->left = co->left + co->width - 1;
+}
+
 static int countItems(struct items * item, enum countWhat what) {
     int count = 0;
 
@@ -231,8 +244,8 @@ int newtCheckboxTreeAddArray(newtComponent co,
 
     i = 4 + (3 * item->depth);
 
-    if ((strlen(text) + i + ct->pad) > co->width) {
-       co->width = strlen(text) + i + ct->pad;
+    if ((ct->userHasSetWidth == 0) && ((strlen(text) + i + ct->sbAdjust) > co->width)) {
+       updateWidth(co, ct, strlen(text) + i);
     }
 
     return 0;
@@ -264,6 +277,16 @@ static void listSelected(struct items * items, int * num, const void ** list, in
     }
 }
 
+void newtCheckboxTreeSetWidth(newtComponent co, int width) {
+    struct CheckboxTree * ct = co->data;
+
+    co->width = width;
+    ct->curWidth = co->width - ct->sbAdjust;
+    ct->userHasSetWidth = 1;
+    if (ct->sb) ct->sb->left = co->width + co->left - 1;
+    ctDraw(co);
+}
+
 const void ** newtCheckboxTreeGetSelection(newtComponent co, int *numitems)
 {
     return newtCheckboxTreeGetMultiSelection(co, numitems, 0);
@@ -312,6 +335,8 @@ newtComponent newtCheckboxTreeMulti(int left, int top, int height, char *seq, in
     co->height = height;
     co->width = 0;
     co->isMapped = 0;
+    ct->curWidth = 0;
+    ct->userHasSetWidth = 0;
     ct->itemlist = NULL;
     ct->firstItem = NULL;
     ct->currItem = NULL;
@@ -326,10 +351,10 @@ newtComponent newtCheckboxTreeMulti(int left, int top, int height, char *seq, in
     if (flags & NEWT_FLAG_SCROLL) {
        ct->sb = newtVerticalScrollbar(left, top, height,
                                       COLORSET_LISTBOX, COLORSET_ACTLISTBOX);
-       ct->pad = 2;
+       ct->sbAdjust = 2;
     } else {
        ct->sb = NULL;
-       ct->pad = 0;
+       ct->sbAdjust = 0;
     }
     
     return co;
@@ -681,8 +706,8 @@ void newtCheckboxTreeSetEntry(newtComponent co, const void * data, const char *
 
     i = 4 + (3 * item->depth);
 
-    if ((strlen(text) + i + ct->pad) > co->width) {
-       co->width = strlen(text) + i + ct->pad;
+    if ((ct->userHasSetWidth == 0) && ((strlen(text) + i + ct->sbAdjust) > co->width)) {
+       updateWidth(co, ct, strlen(text) + i);
     }
 
     ctDraw(co);
index 5352fe58e1b749120a9c63b9267c5eca1d9cb0f4..8c2e29b765390eaf7c69295f79217106632d5205 100644 (file)
@@ -5,7 +5,7 @@ AC_CONFIG_HEADER(config.h)
 
 VERSION=$(awk '/^%define version/ {print $3}' newt.spec)
 
-VERSION=0.50.27
+VERSION=0.50.29
 SONAME=0.50
 AC_SUBST(VERSION)
 AC_SUBST(SONAME)
diff --git a/newt.h b/newt.h
index 22aa24a45aaa26f3fb0ed65d29689b969b88f84f..7e958270bd5834f16f1a5251a7247cbd9d999123 100644 (file)
--- a/newt.h
+++ b/newt.h
@@ -194,6 +194,7 @@ int newtCheckboxTreeAddArray(newtComponent co,
 int * newtCheckboxTreeFindItem(newtComponent co, void * data);
 void newtCheckboxTreeSetEntry(newtComponent co, const void * data,
                              const char * text);
+void newtCheckboxTreeSetWidth(newtComponent co, int width);
 char newtCheckboxTreeGetEntryValue(newtComponent co, const void * data);
 void newtCheckboxTreeSetEntryValue(newtComponent co, const void * data,
                                   char value);
index 47f16d3cadfa8d6e8f99e65fe38e320296a28904..c7a06cdabbfeb20a265425794f200dca2c217515 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.28
+%define version 0.50.29
 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>
+- taught CheckboxTrees about width. Whohoo! 2-D!!!
+
 * Thu Jul 05 2001 Crutcher Dunnavant <crutcher@redhat.com>
 - added 'hide_checkbox' and 'unselectable' options to CheckboxTrees
 
index 2b39821a19646ca0fb33e84ed95f3970d40690a3..cfebde4ebfdba72419f20c45531e1fdf04c0c960 100644 (file)
--- a/snack.py
+++ b/snack.py
@@ -477,10 +477,12 @@ class CheckboxTree(Widget):
        curr = self.w.checkboxtreeGetCurrent()
        return self.key2item[curr]
 
-    def __init__(self, height, scroll = 0, hide_checkbox = 0, unselectable = 0):
+    def __init__(self, height, width = None, scroll = 0, hide_checkbox = 0, unselectable = 0):
        self.w = _snack.checkboxtree(height, scroll, hide_checkbox, unselectable)
        self.key2item = {}
        self.item2key = {}
+       if (width):
+           self.w.checkboxtreeSetWidth(width)
 
     def getSelection(self):
         selection = []
index db27b6cfe3e3f8e58115d2bc03cf5aff386b19fc..d02f7b83498779f901e92b6cea6fab3d6ae1e463 100644 (file)
@@ -192,6 +192,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 * widgetCheckboxTreeSetWidth(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);
@@ -220,6 +221,7 @@ static PyMethodDef widgetMethods[] = {
       METH_VARARGS, NULL },
     { "checkboxtreeSetEntry", (PyCFunction) widgetCheckboxTreeSetEntry,
       METH_VARARGS, NULL },
+    { "checkboxtreeSetWidth", (PyCFunction) widgetCheckboxTreeSetWidth, METH_VARARGS, NULL },
     { "checkboxtreeSetCurrent", (PyCFunction) widgetCheckboxTreeSetCurrent,
       METH_VARARGS, NULL },
     { "checkboxtreeSetEntryValue", (PyCFunction) widgetCheckboxTreeSetEntryValue,
@@ -1100,6 +1102,18 @@ static PyObject * widgetCheckboxTreeSetEntry(snackWidget * s, PyObject * args) {
     return Py_None;
 }
 
+static PyObject * widgetCheckboxTreeSetWidth(snackWidget * s, PyObject * args) {
+    int width;
+
+    if (!PyArg_ParseTuple(args, "i", &width))
+       return NULL;
+
+    newtCheckboxTreeSetWidth(s->co, width);
+
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
 static PyObject * widgetCheckboxTreeSetCurrent(snackWidget * s, PyObject * args) {
     int data;