From: mlichvar Date: Fri, 15 Sep 2006 13:38:21 +0000 (+0000) Subject: - fix screen corruption when half of double width character is overwritten X-Git-Tag: r0-52-3~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b9b1302c497a5fc55cf735c53087ae924cb6ccb6;p=thirdparty%2Fnewt.git - fix screen corruption when half of double width character is overwritten (#137957) - fix double width character handling in checkboxtree and listbox --- diff --git a/checkboxtree.c b/checkboxtree.c index bfdde5f..6190718 100644 --- a/checkboxtree.c +++ b/checkboxtree.c @@ -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++; diff --git a/listbox.c b/listbox.c index 3ab7c4f..d0ac5d3 100644 --- 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 68c363b..b56de52 100644 --- 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); diff --git a/newt_pr.h b/newt_pr.h index aee3f5c..cc839ad 100644 --- 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 */