changeset 14824:6ec7e963d186

[gaim-migrate @ 17591] This fixes at least some issues with wide-characters in the tree-widget. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Fri, 27 Oct 2006 18:30:56 +0000
parents 10244943bbc9
children a02c29df922f
files console/libgnt/gnttree.c console/libgnt/gntutils.c
diffstat 2 files changed, 9 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/console/libgnt/gnttree.c	Fri Oct 27 18:19:40 2006 +0000
+++ b/console/libgnt/gnttree.c	Fri Oct 27 18:30:56 2006 +0000
@@ -196,8 +196,8 @@
 	for (i = 0, iter = row->columns; i < tree->ncol && iter; i++, iter = iter->next)
 	{
 		GntTreeCol *col = iter->data;
-		char *text;
-		int len = g_utf8_strlen(col->text, -1);
+		const char *text;
+		int len = gnt_util_onscreen_width(col->text, NULL);
 		int fl = 0;
 
 		if (i == 0)
@@ -235,7 +235,7 @@
 			len = tree->columns[i].width;
 		}
 
-		text = g_utf8_offset_to_pointer(col->text, len - fl);
+		text = gnt_util_onscreen_width_to_pointer(col->text, len - fl, NULL);
 		string = g_string_append_len(string, col->text, text - col->text);
 		if (len < tree->columns[i].width && iter->next)
 			g_string_append_printf(string, "%*s", tree->columns[i].width - len, "");
@@ -324,6 +324,7 @@
 		tree->top = get_prev_n(tree->current, rows);
 
 	row = tree->top;
+	scrcol = widget->priv.width - 1 - 2 * pos;  /* exclude the borders and the scrollbar */
 	for (i = start + pos; row && i < widget->priv.height - pos;
 				i++, row = get_next(row))
 	{
@@ -335,10 +336,10 @@
 
 		str = update_row_text(tree, row);
 
-		if ((wr = g_utf8_strlen(str, -1)) >= widget->priv.width - 1 - pos)
+		if ((wr = gnt_util_onscreen_width(str, NULL)) > scrcol)
 		{
 			/* XXX: ellipsize */
-			char *s = g_utf8_offset_to_pointer(str, widget->priv.width - 1 - pos);
+			char *s = (char*)gnt_util_onscreen_width_to_pointer(str, scrcol, &wr);
 			*s = '\0';
 		}
 
@@ -368,7 +369,7 @@
 
 		wbkgdset(widget->window, '\0' | attr);
 		mvwprintw(widget->window, i, pos, str);
-		whline(widget->window, ' ', widget->priv.width - pos * 2 - g_utf8_strlen(str, -1) - 1);
+		whline(widget->window, ' ', scrcol - wr);
 		tree->bottom = row;
 		g_free(str);
 		tree_mark_columns(tree, pos, i,
@@ -385,7 +386,7 @@
 		i++;
 	}
 
-	scrcol = widget->priv.width - pos - 1;
+	scrcol = widget->priv.width - pos - 1;  /* position of the scrollbar */
 	rows--;
 	if (rows > 0)
 	{
--- a/console/libgnt/gntutils.c	Fri Oct 27 18:19:40 2006 +0000
+++ b/console/libgnt/gntutils.c	Fri Oct 27 18:30:56 2006 +0000
@@ -60,7 +60,7 @@
 	const char *str = string;
 
 	if (len <= 0) {
-		len = g_utf8_strlen(string, -1);
+		len = gnt_util_onscreen_width(string, NULL);
 	}
 
 	while (width < len && *str) {