From: crutcher Date: Thu, 5 Jul 2001 19:53:44 +0000 (+0000) Subject: added width to CheckboxTree X-Git-Tag: r0-50-29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d8c97d41c75f9ca1a290b02005cbf3bb2d8d52d4;p=thirdparty%2Fnewt.git added width to CheckboxTree --- diff --git a/checkboxtree.c b/checkboxtree.c index c5131c7..cc8288d 100644 --- a/checkboxtree.c +++ b/checkboxtree.c @@ -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); diff --git a/configure.in b/configure.in index 5352fe5..8c2e29b 100644 --- a/configure.in +++ b/configure.in @@ -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 22aa24a..7e95827 100644 --- 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); diff --git a/newt.spec b/newt.spec index 47f16d3..c7a06cd 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.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 +- taught CheckboxTrees about width. Whohoo! 2-D!!! + * Thu Jul 05 2001 Crutcher Dunnavant - added 'hide_checkbox' and 'unselectable' options to CheckboxTrees diff --git a/snack.py b/snack.py index 2b39821..cfebde4 100644 --- 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 = [] diff --git a/snackmodule.c b/snackmodule.c index db27b6c..d02f7b8 100644 --- a/snackmodule.c +++ b/snackmodule.c @@ -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;