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++;
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);
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);
return;
}
y = wcwidth(tmp);
- if (y > ln) {
+ if (y > chrs) {
*p = '\0';
return;
} else {
p += x;
- ln -= y;
+ ln -= x;
+ chrs -= y;
}
}
}
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;
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();
row = col = 0;
row = currentWindow->top - 1;
- col = currentWindow->left - 1;
+ col = currentWindow->left - 2;
if (row < 0)
row = 0;
if (col < 0)
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);
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 */