]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
- fix screen corruption when half of double width character is overwritten
authormlichvar <mlichvar>
Fri, 15 Sep 2006 13:38:21 +0000 (13:38 +0000)
committermlichvar <mlichvar>
Fri, 15 Sep 2006 13:38:21 +0000 (13:38 +0000)
  (#137957)
- fix double width character handling in checkboxtree and listbox

checkboxtree.c
listbox.c
newt.c
newt_pr.h

index bfdde5f6f329674fc1203cb0ff8ab2b8a742dac4..61907180c056e798ca0a4db5697d2a6602da4f8d 100644 (file)
@@ -490,8 +490,17 @@ static void ctDraw(newtComponent co) {
            currRow = co->top + i;
        }
 
-       SLsmg_write_nstring((*item)->text, co->width - 4 - 
-                                          (3 * (*item)->depth));
+       j = 4 + (3 * (*item)->depth);
+       SLsmg_write_nstring(NULL, co->width - j);
+       newtGotorc(co->top + i, co->left + j);
+       if (wstrlen((*item)->text, -1) > co->width - j) {
+           char *tmp;
+           tmp = strdup((*item)->text);
+           trim_string(tmp, co->width - j);
+           SLsmg_write_string(tmp);
+           free(tmp);
+       } else
+           SLsmg_write_string((*item)->text);
 
        item++;
        i++;
index 3ab7c4fb203e82d74bf569835295cc2feca70e70..d0ac5d333c1a8cdbb49050678f942ceef3994720 100644 (file)
--- a/listbox.c
+++ b/listbox.c
@@ -527,7 +527,16 @@ static void listboxDraw(newtComponent co)
        else
            SLsmg_set_color(NEWT_COLORSET_LISTBOX);
 
-       SLsmg_write_nstring(item->text, li->curWidth);
+       SLsmg_write_nstring(NULL, li->curWidth);
+       newtGotorc(co->top + i + li->bdyAdjust, co->left + li->bdxAdjust);
+       if (wstrlen(item->text, -1) > li->curWidth) {
+           char *tmp;
+           tmp = strdup(item->text);
+           trim_string(tmp, li->curWidth);
+           SLsmg_write_string(tmp);
+           free(tmp);
+       } else
+           SLsmg_write_string(item->text);
 
        if (li->flags & NEWT_FLAG_MULTIPLE) {
            newtGotorc(co->top + i + li->bdyAdjust, co->left + li->bdxAdjust);
diff --git a/newt.c b/newt.c
index 68c363bd9e89d224f815394dce0639dc3c3c2949..b56de524bcf6a0702cfe165bf2f71d06c8eb26f7 100644 (file)
--- a/newt.c
+++ b/newt.c
@@ -184,12 +184,13 @@ int _newt_wstrlen(const char *str, int len) {
 void trim_string(char *title, int chrs)
 {
        char *p = title;
-       int ln = chrs;
+       int ln;
        int x = 0,y = 0;
        wchar_t tmp;
        mbstate_t ps;
 
        memset(&ps, 0, sizeof(ps));
+       ln = strlen(title);
 
        while (*p) {
                x = mbrtowc(&tmp, p, ln, &ps);
@@ -198,12 +199,13 @@ void trim_string(char *title, int chrs)
                        return;
                }
                y = wcwidth(tmp);
-               if (y > ln) {
+               if (y > chrs) {
                        *p = '\0';
                        return;
                } else {
                        p += x;
-                       ln -= y;
+                       ln -= x;
+                       chrs -= y;
                }
        }       
 }
@@ -638,10 +640,10 @@ int newtOpenWindow(int left, int top,
     currentWindow->height = height;
     currentWindow->title = title ? strdup(title) : NULL;
 
-    currentWindow->buffer = malloc(sizeof(SLsmg_Char_Type) * (width + 3) * (height + 3));
+    currentWindow->buffer = malloc(sizeof(SLsmg_Char_Type) * (width + 5) * (height + 3));
 
     row = top - 1;
-    col = left - 1;
+    col = left - 2;
     /* clip to the current screen bounds - msw */
     if (row < 0)
        row = 0;
@@ -655,8 +657,8 @@ int newtOpenWindow(int left, int top,
     for (j = 0; j < height + 3; j++, row++) {
        SLsmg_gotorc(row, col);
        SLsmg_read_raw(currentWindow->buffer + n,
-                      currentWindow->width + 3);
-       n += currentWindow->width + 3;
+                      currentWindow->width + 5);
+       n += currentWindow->width + 5;
     }
 
     newtTrashScreen();
@@ -732,7 +734,7 @@ void newtPopWindow(void) {
     row = col = 0;
 
     row = currentWindow->top - 1;
-    col = currentWindow->left - 1;
+    col = currentWindow->left - 2;
     if (row < 0)
        row = 0;
     if (col < 0)
@@ -740,8 +742,8 @@ void newtPopWindow(void) {
     for (j = 0; j < currentWindow->height + 3; j++, row++) {
        SLsmg_gotorc(row, col);
        SLsmg_write_raw(currentWindow->buffer + n,
-                       currentWindow->width + 3);
-       n += currentWindow->width + 3;
+                       currentWindow->width + 5);
+       n += currentWindow->width + 5;
     }
 
     free(currentWindow->buffer);
index aee3f5c6cc926b5e4345f49505c1edaf2459e4e2..cc839ad22e358dce6db420add2f404710955a702 100644 (file)
--- a/newt_pr.h
+++ b/newt_pr.h
@@ -82,5 +82,6 @@ struct eventResult newtDefaultEventHandler(newtComponent c,
 
 int _newt_wstrlen(const char *str, int len);
 #define wstrlen(str,len) _newt_wstrlen((str),(len))
+void trim_string(char *title, int chrs);
 
 #endif /* H_NEWT_PR */