diff console/libgnt/gnttree.c @ 13931:917a71dd02eb

[gaim-migrate @ 16458] Add text-attributes for rows in a GntTree. Use this feature to dim idle buddies in the buddylist. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sat, 08 Jul 2006 07:13:29 +0000
parents 3dbcbc5e57e1
children ef0d515b9f97
line wrap: on
line diff
--- a/console/libgnt/gnttree.c	Sat Jul 08 02:11:11 2006 +0000
+++ b/console/libgnt/gnttree.c	Sat Jul 08 07:13:29 2006 +0000
@@ -25,6 +25,7 @@
 	gboolean choice;            /* Is this a choice-box?
 	                               If choice is true, then child will be NULL */
 	gboolean isselected;
+	GntTextFormatFlags flags;
 
 	GntTreeRow *parent;
 	GntTreeRow *child;
@@ -180,6 +181,9 @@
 		int wr;
 		char format[16] = "";
 
+		GntTextFormatFlags flags = row->flags;
+		int attr = 0;
+
 		deep = TRUE;
 
 		if (row->parent == NULL && row->child)
@@ -208,25 +212,38 @@
 				str[wr++] = ' ';
 			str[wr] = 0;
 		}
-		
+
+		if (flags & GNT_TEXT_FLAG_BOLD)
+			attr |= A_BOLD;
+		if (flags & GNT_TEXT_FLAG_UNDERLINE)
+			attr |= A_UNDERLINE;
+		if (flags & GNT_TEXT_FLAG_BLINK)
+			attr |= A_BLINK;
+
 		if (row == tree->current)
 		{
 			if (gnt_widget_has_focus(widget))
-				wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_HIGHLIGHT));
+				attr |= COLOR_PAIR(GNT_COLOR_HIGHLIGHT);
 			else
-				wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D));
-			mvwprintw(widget->window, start, pos, str);
-			whline(widget->window, ' ', widget->priv.width - pos * 2 - g_utf8_strlen(str, -1));
-			wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL));
+				attr |= COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D);
 		}
 		else
 		{
-			mvwprintw(widget->window, start, pos, str);
-			whline(widget->window, ' ', widget->priv.width - pos * 2 - g_utf8_strlen(str, -1));
+			if (flags & GNT_TEXT_FLAG_DIM)
+				attr |= (A_DIM | COLOR_PAIR(GNT_COLOR_DISABLED));
+			else if (flags & GNT_TEXT_FLAG_HIGHLIGHT)
+				attr |= (A_DIM | COLOR_PAIR(GNT_COLOR_HIGHLIGHT));
+			else
+				attr |= COLOR_PAIR(GNT_COLOR_NORMAL);
 		}
+
+		wbkgdset(widget->window, '\0' | attr);
+		mvwprintw(widget->window, start, pos, str);
+		whline(widget->window, ' ', widget->priv.width - pos * 2 - g_utf8_strlen(str, -1));
 		tree->bottom = row;
 	}
 
+	wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL));
 	while (start < widget->priv.height - pos)
 	{
 		mvwhline(widget->window, start, pos, ' ',
@@ -682,3 +699,13 @@
 	return row->isselected;
 }
 
+void gnt_tree_set_row_flags(GntTree *tree, void *key, GntTextFormatFlags flags)
+{
+	GntTreeRow *row = g_hash_table_lookup(tree->hash, key);
+	if (!row)
+		return;
+
+	row->flags = flags;
+	redraw_tree(tree);
+}
+