changeset 15776:b5c4de70577d

Display selected double-width cell chars properly and select the correct number of bytes when these characters are on a selection line. fix a typo
author Richard Nelson <wabz@pidgin.im>
date Tue, 06 Mar 2007 03:01:59 +0000
parents f3ebd1c17c7b
children 909e59dae123
files console/libgnt/gntentry.c console/libgnt/gnttextview.c
diffstat 2 files changed, 28 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/console/libgnt/gntentry.c	Tue Mar 06 00:06:58 2007 +0000
+++ b/console/libgnt/gntentry.c	Tue Mar 06 03:01:59 2007 +0000
@@ -693,7 +693,7 @@
 				GNT_KEY_CTRL_DOWN, NULL);
 	gnt_bindable_class_register_action(bindable, "history-next", history_next,
 				GNT_KEY_CTRL_UP, NULL);
-	gnt_bindable_class_register_action(bindable, "clipboard-past", clipboard_paste,
+	gnt_bindable_class_register_action(bindable, "clipboard-paste", clipboard_paste,
 				GNT_KEY_CTRL_V, NULL);
 
 	gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), GNT_BINDABLE_CLASS(klass));
--- a/console/libgnt/gnttextview.c	Tue Mar 06 00:06:58 2007 +0000
+++ b/console/libgnt/gnttextview.c	Tue Mar 06 03:01:59 2007 +0000
@@ -69,13 +69,17 @@
 				(select_end <= view->string->str + seg->end && select_start <= view->string->str + seg->start))) {
 				char *cur = view->string->str + seg->start;
 				while (*cur != '\0') {
+					gchar *last = g_utf8_next_char(cur);
+					gchar *str;
 					if (cur >= select_start && cur <= select_end)
 						fl |= A_REVERSE;
 					else
 						fl = seg->flags;
+					str = g_strndup(cur, last - cur);
 					wattrset(widget->window, fl);
-					waddch(widget->window, *cur);
-					cur++;
+					waddstr(widget->window, str);
+					g_free(str);
+					cur = g_utf8_next_char(cur);
 				}
 			} else {
 				wattrset(widget->window, fl);
@@ -187,20 +191,23 @@
 static char *
 gnt_text_view_get_p(GntTextView *view, int x, int y)
 {
-	int i;
+	int i = 0;
 	GntWidget *wid = GNT_WIDGET(view);
 	GntTextLine *line;
 	GList *lines;
 	GList *segs;
 	GntTextSegment *seg;
+	gchar *pos;
 
 	y = wid->priv.height - y;
 	if (g_list_length(view->list) < y) {
 		x = 0;
-		y = g_list_length(view->list);
+		y = g_list_length(view->list) - 1;
 	}
 
 	lines = g_list_nth(view->list, y - 1);
+	if (!lines)
+		return NULL;
 	do {
 		line = lines->data;
 		lines = lines->next;
@@ -210,8 +217,17 @@
 		return NULL;
 	segs = line->segments;
 	seg = (GntTextSegment *)segs->data;
-	i = 0;
-	return view->string->str + seg->start + MIN(x, line->length);
+	pos = view->string->str + seg->start;
+	x = MIN(x, line->length);
+	while (++i <= x) {
+		gunichar *u;
+		pos = g_utf8_next_char(pos);
+		u = g_utf8_to_ucs4(pos, -1, NULL, NULL, NULL);
+		if (u && g_unichar_iswide_cjk(*u))
+			i++;
+		g_free(u);
+	}
+	return pos;
 }
 
 static GString *
@@ -219,7 +235,7 @@
 {
 	gchar *start = c;
 	gchar *end = c;
-	gchar *t;
+	gchar *t, *endsize;
 	while (t = g_utf8_prev_char(start)) {
 		if (!g_ascii_isspace(*t)) {
 			if (start == view->string->str)
@@ -236,7 +252,8 @@
 	}
 	select_start = start;
 	select_end = end;
-	return g_string_new_len(start, end - start + 1);
+	endsize = g_utf8_next_char(select_end); /* End at the correct byte */
+	return g_string_new_len(start, endsize - start);
 }
 
 static gboolean too_slow(gpointer n)
@@ -276,7 +293,8 @@
 					return;
 				}
 			} else {
-				clip = g_string_new_len(select_start, select_end - select_start + 1);
+				gchar *endsize = g_utf8_next_char(select_end); /* End at the correct byte */
+				clip = g_string_new_len(select_start, endsize - select_start);
 			}
 			gnt_widget_draw(widget);
 			gnt_set_clipboard_string(clip->str);