From: msw Date: Wed, 5 Feb 2003 07:11:35 +0000 (+0000) Subject: - fixed help line drawing in UTF-8 (#81718) X-Git-Tag: r0-51-3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ce11acc8966aa11b76857083bce03b72c81467dd;p=thirdparty%2Fnewt.git - fixed help line drawing in UTF-8 (#81718) - calculate the width of text in entries using wstrlen - always set component width to the new label width in newtLabelSetText - fixed snack.CListbox to work properly with UTF-8 (#81718) --- diff --git a/configure.in b/configure.in index 925c4cd..8eae3ff 100644 --- a/configure.in +++ b/configure.in @@ -5,7 +5,7 @@ AC_CONFIG_HEADER(config.h) VERSION=$(awk '/^%define version/ {print $3}' $srcdir/newt.spec) -VERSION=0.51.3 +VERSION=0.51.4 SONAME=0.51 AC_SUBST(VERSION) AC_SUBST(SONAME) diff --git a/entry.c b/entry.c index 21ab00c..2b28954 100644 --- a/entry.c +++ b/entry.c @@ -155,7 +155,7 @@ static void entryDraw(newtComponent co) { chptr = tmpptr; } - len = strlen(chptr); + len = wstrlen(chptr, -1); if (len <= co->width) { i = len; diff --git a/label.c b/label.c index 3d81935..ad8665b 100644 --- a/label.c +++ b/label.c @@ -47,6 +47,7 @@ void newtLabelSetText(newtComponent co, const char * text) { int newLength; struct label * la = co->data; + co->width = wstrlen(text,-1); newLength = strlen(text); if (newLength <= la->length) { memset(la->text, ' ', la->length); @@ -55,7 +56,6 @@ void newtLabelSetText(newtComponent co, const char * text) { free(la->text); la->text = strdup(text); la->length = newLength; - co->width = wstrlen(text,-1); } labelDraw(co); diff --git a/newt.c b/newt.c index 3b6dae0..1fe3fc7 100644 --- a/newt.c +++ b/newt.c @@ -653,15 +653,23 @@ void newtRedrawHelpLine(void) { SLsmg_set_color(NEWT_COLORSET_HELPLINE); - buf = alloca(SLtt_Screen_Cols + 1); - memset(buf, ' ', SLtt_Screen_Cols); - buf[SLtt_Screen_Cols] = '\0'; - if (currentHelpline) { - int len = wstrlen(*currentHelpline, -1); - if (SLtt_Screen_Cols < len) - len = SLtt_Screen_Cols; - memcpy(buf, *currentHelpline, len); + /* buffer size needs to be wide enough to hold all the multibyte + currentHelpline + all the single byte ' ' to fill the line */ + int wlen = wstrlen(*currentHelpline, -1); + int len; + + if (wlen > SLtt_Screen_Cols) + wlen = SLtt_Screen_Cols; + len = strlen(*currentHelpline) + (SLtt_Screen_Cols - wlen); + buf = alloca(len + 1); + memset(buf, ' ', len); + memcpy(buf, *currentHelpline, strlen(*currentHelpline)); + buf[len] = '\0'; + } else { + buf = alloca(SLtt_Screen_Cols + 1); + memset(buf, ' ', SLtt_Screen_Cols); + buf[SLtt_Screen_Cols] = '\0'; } SLsmg_gotorc(SLtt_Screen_Rows - 1, 0); SLsmg_write_string(buf); diff --git a/newt.spec b/newt.spec index 89d65ec..aca314a 100644 --- a/newt.spec +++ b/newt.spec @@ -2,9 +2,9 @@ Summary: A development library for text mode user interfaces. Name: newt -%define version 0.51.3 +%define version 0.51.4 Version: %{version} -Release: 2 +Release: 1 License: LGPL Group: System Environment/Libraries Source: newt-%{version}.tar.gz @@ -83,6 +83,12 @@ rm -rf $RPM_BUILD_ROOT %{_libdir}/libnewt.so %changelog +* Wed Feb 5 2003 Matt Wilson 0.51.4-1 +- fixed help line drawing in UTF-8 (#81718) +- calculate the width of text in entries using wstrlen +- always set component width to the new label width in newtLabelSetText +- fixed snack.CListbox to work properly with UTF-8 (#81718) + * Tue Feb 04 2003 Florian La Roche - add symlink to shared lib diff --git a/snack.py b/snack.py index f8ca13e..422aab3 100644 --- a/snack.py +++ b/snack.py @@ -592,9 +592,10 @@ def EntryWindow(screen, title, text, prompts, allowCancel = 1, width = 40, return (bb.buttonPressed(result), tuple(entryValues)) class CListbox(Grid): - def __init__(self, height, cols, col_widths, scroll = 0, returnExit = 0, - width = 0, col_pad = 1, col_text_align = None, - col_labels = None, col_label_align = None): + def __init__(self, height, cols, col_widths, scroll = 0, + returnExit = 0, width = 0, col_pad = 1, + col_text_align = None, col_labels = None, + col_label_align = None, adjust_width=0): self.cols = cols self.col_widths = col_widths[:] @@ -605,9 +606,9 @@ class CListbox(Grid): Grid.__init__(self, 1, 2) box_y = 1 - lstr = self.colFormText(col_labels, col_label_align) + lstr = self.colFormText(col_labels, col_label_align, + adjust_width=adjust_width) self.label = Label(lstr) - self.setField(self.label, 0, 0, anchorLeft=1) else: @@ -618,14 +619,22 @@ class CListbox(Grid): self.listbox = Listbox(height, scroll, returnExit, width) self.setField(self.listbox, 0, box_y, anchorRight=1) - def colFormText(self, col_text, align = None): + def colFormText(self, col_text, align = None, adjust_width=0): i = 0 str = "" c_len = len(col_text) while (i < self.cols) and (i < c_len): - cstr = col_text[i][:self.col_widths[i]] - delta = self.col_widths[i] - len(cstr) + cstr = col_text[i] + cstrlen = _snack.wstrlen(cstr) + if self.col_widths[i] < cstrlen: + if adjust_width: + self.col_widths[i] = cstrlen + else: + cstr = cstr[:self.col_widths[i]] + + delta = self.col_widths[i] - _snack.wstrlen(cstr) + if delta > 0: if align == None: a = LEFT diff --git a/snackmodule.c b/snackmodule.c index cb89f8c..f992e44 100644 --- a/snackmodule.c +++ b/snackmodule.c @@ -13,6 +13,7 @@ #include "Python.h" #include "newt.h" +#include "newt_pr.h" typedef struct snackWidget_s snackWidget; typedef struct snackGrid_s snackGrid; @@ -63,6 +64,7 @@ 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, PyObject * kwargs); +static PyObject * pywstrlen(PyObject * s, PyObject * args); static PyMethodDef snackModuleMethods[] = { { "button", (PyCFunction) buttonWidget, METH_VARARGS, NULL }, @@ -96,6 +98,7 @@ static PyMethodDef snackModuleMethods[] = { { "ternary", ternaryWindow, METH_VARARGS, NULL }, { "textbox", (PyCFunction) textWidget, METH_VARARGS, NULL }, { "checkboxtree", (PyCFunction) checkboxTreeWidget, METH_VARARGS | METH_KEYWORDS, NULL }, + { "wstrlen", (PyCFunction) pywstrlen, METH_VARARGS | METH_KEYWORDS, NULL }, { NULL } } ; @@ -1203,6 +1206,16 @@ static PyObject * widgetCheckboxTreeGetSel(snackWidget * s, return sel; } +static PyObject * pywstrlen(PyObject * s, PyObject * args) +{ + char *str; + int len = -1; + + if (!PyArg_ParseTuple(args, "s|i", &str, &len)) return NULL; + + return PyInt_FromLong(wstrlen(str, len)); +} + void init_snack(void) { PyObject * d, * m;