changeset 15970:790d1d003825

Allow making some columns invisible.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Fri, 30 Mar 2007 05:32:40 +0000
parents 43182e0e58c0
children 05d347516fcd 71fddbec98e4
files finch/libgnt/gntbutton.c finch/libgnt/gnttree.c finch/libgnt/gnttree.h
diffstat 3 files changed, 42 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/finch/libgnt/gntbutton.c	Thu Mar 29 20:30:46 2007 +0000
+++ b/finch/libgnt/gntbutton.c	Fri Mar 30 05:32:40 2007 +0000
@@ -87,8 +87,6 @@
 	GntButton *button = GNT_BUTTON(instance);
 	button->priv = g_new0(GntButtonPriv, 1);
 
-	GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_X);
-
 	widget->priv.minw = 4;
 	widget->priv.minh = 3;
 	GNTDEBUG;
--- a/finch/libgnt/gnttree.c	Thu Mar 29 20:30:46 2007 +0000
+++ b/finch/libgnt/gnttree.c	Fri Mar 30 05:32:40 2007 +0000
@@ -222,6 +222,7 @@
 	GString *string = g_string_new(NULL);
 	GList *iter;
 	int i;
+	gboolean notfirst = FALSE;
 
 	for (i = 0, iter = row->columns; i < tree->ncol && iter; i++, iter = iter->next)
 	{
@@ -231,6 +232,9 @@
 		int fl = 0;
 		gboolean cut = FALSE;
 
+		if (tree->columns[i].invisible)
+			continue;
+
 		if (i == 0)
 		{
 			if (row->choice)
@@ -258,8 +262,12 @@
 			}
 			len += fl;
 		}
+		else if (notfirst)
+			g_string_append_c(string, '|');
 		else
-			g_string_append_c(string, '|');
+			g_string_append_c(string, ' ');
+
+		notfirst = TRUE;
 
 		if (len > tree->columns[i].width) {
 			len = tree->columns[i].width - 1;
@@ -281,17 +289,24 @@
 	return g_string_free(string, FALSE);
 }
 
+#define NEXT_X x += tree->columns[i].width + (i > 0 ? 1 : 0)
+
 static void
 tree_mark_columns(GntTree *tree, int pos, int y, chtype type)
 {
 	GntWidget *widget = GNT_WIDGET(tree);
 	int i;
 	int x = pos;
+	gboolean notfirst = FALSE;
 
 	for (i = 0; i < tree->ncol - 1; i++)
 	{
-		x += tree->columns[i].width;
-		mvwaddch(widget->window, y, x + i, type);
+		if (!tree->columns[i].invisible) {
+			notfirst = TRUE;
+			NEXT_X;
+		}
+		if (!tree->columns[i+1].invisible && notfirst)
+			mvwaddch(widget->window, y, x, type);
 	}
 }
 
@@ -327,11 +342,16 @@
 
 		mvwhline(widget->window, pos + 1, pos, ACS_HLINE | COLOR_PAIR(GNT_COLOR_NORMAL),
 				widget->priv.width - pos - 1);
-		
+		mvwhline(widget->window, pos, pos, ' ' | COLOR_PAIR(GNT_COLOR_NORMAL),
+				widget->priv.width - pos - 1);
+
 		for (i = 0; i < tree->ncol; i++)
 		{
-			mvwaddstr(widget->window, pos, x + i, tree->columns[i].title);
-			x += tree->columns[i].width;
+			if (tree->columns[i].invisible) {
+				continue;
+			}
+			mvwaddstr(widget->window, pos, x + 1, tree->columns[i].title);
+			NEXT_X;
 		}
 		if (pos)
 		{
@@ -491,8 +511,9 @@
 		GntTree *tree = GNT_TREE(widget);
 		int i, width = 0;
 		for (i = 0; i < tree->ncol; i++)
-			width += tree->columns[i].width;
-		widget->priv.width = width + i;
+			if (!tree->columns[i].invisible)
+				width += tree->columns[i].width + 1;
+		widget->priv.width = width;
 	}
 }
 
@@ -1484,7 +1505,8 @@
 	twidth = 1 + 2 * (!GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_NO_BORDER));
 	for (i = 0; i < tree->ncol; i++) {
 		gnt_tree_set_col_width(tree, i, widths[i]);
-		twidth += widths[i] + (tree->show_separator ? 1 : 0) + 1;
+		if (!tree->columns[i].invisible)
+			twidth += widths[i] + (tree->show_separator ? 1 : 0) + 1;
 	}
 	g_free(widths);
 
@@ -1499,3 +1521,9 @@
 	tree->hash = g_hash_table_new_full(hash, eq, kd, free_tree_row);
 }
 
+void gnt_tree_set_column_visible(GntTree *tree, int col, gboolean vis)
+{
+	g_return_if_fail(col < tree->ncol);
+	tree->columns[col].invisible = !vis;
+}
+
--- a/finch/libgnt/gnttree.h	Thu Mar 29 20:30:46 2007 +0000
+++ b/finch/libgnt/gnttree.h	Fri Mar 30 05:32:40 2007 +0000
@@ -48,6 +48,7 @@
 	{
 		int width;
 		char *title;
+		gboolean invisible;
 	} *columns;             /* Would a GList be better? */
 	gboolean show_title;
 	gboolean show_separator; /* Whether to show column separators */
@@ -140,6 +141,10 @@
 
 void gnt_tree_set_hash_fns(GntTree *tree, gpointer hash, gpointer eq, gpointer kd);
 
+/* This can be useful when, for example, we want to store some data
+ * which we don't want/need to display. */
+void gnt_tree_set_column_visible(GntTree *tree, int col, gboolean vis);
+
 G_END_DECLS
 
 /* The following functions should NOT be used by applications. */