changeset 13936:669898e6aa11

[gaim-migrate @ 16467] Minor enhancements for the combobox. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sun, 09 Jul 2006 00:54:31 +0000
parents cd2da4b079cf
children af23525bcb31
files console/libgnt/gntcombobox.c console/libgnt/gnttree.c console/libgnt/test/combo.c
diffstat 3 files changed, 22 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/console/libgnt/gntcombobox.c	Sat Jul 08 23:58:20 2006 +0000
+++ b/console/libgnt/gntcombobox.c	Sun Jul 09 00:54:31 2006 +0000
@@ -33,6 +33,7 @@
 	GntComboBox *box = GNT_COMBO_BOX(widget);
 	const char *text = NULL;
 	GntColorType type;
+	int len;
 	
 	if (box->dropdown)
 	{
@@ -43,14 +44,28 @@
 	if (text == NULL)
 		text = "";
 
+	text = g_strdup(text);
+
 	if (gnt_widget_has_focus(widget))
 		type = GNT_COLOR_HIGHLIGHT;
 	else
 		type = GNT_COLOR_NORMAL;
 
 	wbkgdset(widget->window, '\0' | COLOR_PAIR(type));
+
+	if ((len = g_utf8_strlen(text, -1)) > widget->priv.width - 4)
+	{
+		char *s = g_utf8_offset_to_pointer(text, widget->priv.width - 4);
+		*s = '\0';
+		len = widget->priv.width - 4;
+	}
+
 	mvwprintw(widget->window, 1, 1, text);
+	whline(widget->window, '\0' | COLOR_PAIR(type), widget->priv.width - 4 - len);
+	mvwaddch(widget->window, 1, widget->priv.width - 3, ACS_VLINE | COLOR_PAIR(GNT_COLOR_NORMAL));
+	mvwaddch(widget->window, 1, widget->priv.width - 2, ACS_DARROW | COLOR_PAIR(GNT_COLOR_NORMAL));
 
+	g_free(text);
 	DEBUG;
 }
 
@@ -164,6 +179,7 @@
 
 	box = gnt_box_new(FALSE, FALSE);
 	GNT_WIDGET_SET_FLAGS(box, GNT_WIDGET_NO_SHADOW | GNT_WIDGET_NO_BORDER);
+	gnt_box_set_pad(GNT_BOX(box), 0);
 	gnt_box_add_widget(GNT_BOX(box), combo->dropdown);
 	
 	DEBUG;
--- a/console/libgnt/gnttree.c	Sat Jul 08 23:58:20 2006 +0000
+++ b/console/libgnt/gnttree.c	Sun Jul 09 00:54:31 2006 +0000
@@ -201,11 +201,13 @@
 			g_snprintf(format, sizeof(format) - 1, "[%c] ", row->isselected ? 'X' : ' ');
 		}
 
-		/* XXX: Need a utf8 version of snprintf */
-		if ((wr = g_snprintf(str, widget->priv.width, "%s%s", format, row->text)) >= widget->priv.width)
+		g_snprintf(str, sizeof(str) - 1, "%s%s", format, row->text);
+
+		if ((wr = g_utf8_strlen(str, -1)) >= widget->priv.width - 1 - pos)
 		{
 			/* XXX: ellipsize */
-			str[widget->priv.width - 1 - pos] = 0;
+			char *s = g_utf8_offset_to_pointer(str, widget->priv.width - 1 - pos);
+			*s = '\0';
 		}
 		else
 		{
--- a/console/libgnt/test/combo.c	Sat Jul 08 23:58:20 2006 +0000
+++ b/console/libgnt/test/combo.c	Sun Jul 09 00:54:31 2006 +0000
@@ -17,7 +17,7 @@
 	combo = gnt_combo_box_new();
 	gnt_combo_box_add_data(GNT_COMBO_BOX(combo), "1", "1");
 	gnt_combo_box_add_data(GNT_COMBO_BOX(combo), "2", "2");
-	gnt_combo_box_add_data(GNT_COMBO_BOX(combo), "3", "3");
+	gnt_combo_box_add_data(GNT_COMBO_BOX(combo), "3", "3abcdefghijklmnopqrstuvwxyz");
 	gnt_combo_box_add_data(GNT_COMBO_BOX(combo), "4", "4");
 	gnt_combo_box_add_data(GNT_COMBO_BOX(combo), "5", "5");
 	gnt_combo_box_add_data(GNT_COMBO_BOX(combo), "6", "6");