]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
- fixed help line drawing in UTF-8 (#81718) r0-51-3
authormsw <msw>
Wed, 5 Feb 2003 07:11:35 +0000 (07:11 +0000)
committermsw <msw>
Wed, 5 Feb 2003 07:11:35 +0000 (07:11 +0000)
- 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)

configure.in
entry.c
label.c
newt.c
newt.spec
snack.py
snackmodule.c

index 925c4cda276083d4653b7037dba0cb8e1964c08a..8eae3ff227227f40aaeeff635fdb09e9d0ef4158 100644 (file)
@@ -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 21ab00c01367938f5f0062089a4d039b51dcdf11..2b289549b749759be5efb8dc5c9664bfeecc66bc 100644 (file)
--- 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 3d81935437a3e67a19c6591c95652be60bbeb0fd..ad8665b82068cea9a6b3f76478f3ae6de31b0c7e 100644 (file)
--- 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 3b6dae0940eaef987e8783616023ef01b641b93e..1fe3fc77f799a03817e92719566fb8e2c69ea67f 100644 (file)
--- 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);
index 89d65ec8a677586228ae68fcf84d88a38bd2bf59..aca314a2900a091af196b1fbe534258b01d3c567 100644 (file)
--- 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 <msw@redhat.com> 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 <Florian.LaRoche@redhat.de>
 - add symlink to shared lib
 
index f8ca13e1e5bcbf4e9dc80a309c0efce4a93adbde..422aab347084bf7289266ec1b86bae5a942ca629 100644 (file)
--- 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
index cb89f8c8014ff59a4b4f9112b59c02a804dcc78e..f992e44692a893d8556cd3da3cc32479cadaf652 100644 (file)
@@ -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;