changeset 14123:f8ab496671fa

[gaim-migrate @ 16761] Show scrollbars in trees and textviews. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Tue, 15 Aug 2006 02:45:52 +0000
parents dabbcb9b013d
children e5db1a91e190
files console/libgnt/gntmain.c console/libgnt/gnttextview.c console/libgnt/gnttree.c console/libgnt/test/multiwin.c
diffstat 4 files changed, 96 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/console/libgnt/gntmain.c	Mon Aug 14 21:46:17 2006 +0000
+++ b/console/libgnt/gntmain.c	Tue Aug 15 02:45:52 2006 +0000
@@ -403,6 +403,8 @@
 						ch = '^'; break;
 					case '.':
 						ch = 'v'; break;
+					case 'a':
+						ch = '#'; break;
 					default:
 						ch = ' '; break;
 				}
--- a/console/libgnt/gnttextview.c	Mon Aug 14 21:46:17 2006 +0000
+++ b/console/libgnt/gnttextview.c	Tue Aug 15 02:45:52 2006 +0000
@@ -26,6 +26,7 @@
 	GntTextView *view = GNT_TEXT_VIEW(widget);
 	int i = 0;
 	GList *lines;
+	int showing, position, rows, scrcol;
 
 	werase(widget->window);
 
@@ -45,18 +46,35 @@
 				whline(widget->window, ' ' | seg->flags, widget->priv.width - line->length - 1);
 		}
 	}
-	
-	mvwaddch(widget->window, 0,
-			widget->priv.width - 1,
-			lines ? 
-			ACS_UARROW | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D) :
-			' '| COLOR_PAIR(GNT_COLOR_NORMAL));
+
+	scrcol = widget->priv.width - 1;
+	rows = widget->priv.height - 2;
+	if (rows > 0)
+	{
+
+		showing = rows * rows / g_list_length(g_list_first(view->list)) + 1;
+		showing = MIN(rows, showing);
+
+		position = showing * g_list_length(view->list) / rows;
+		position = MAX((lines != NULL), position);
 
-	mvwaddch(widget->window, widget->priv.height - 1,
-			widget->priv.width - 1,
-			(view->list && view->list->prev) ? 
-			ACS_DARROW | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D) :
-			' '| COLOR_PAIR(GNT_COLOR_NORMAL));
+		if (showing + position > rows)
+			position = rows - showing;
+		
+		if (showing + position == rows && view->list && view->list->prev)
+			position = MAX(1, rows - 1 - showing);
+		else if (showing + position < rows && view->list && !view->list->prev)
+			position = rows - showing;
+
+		mvwvline(widget->window, position + 1, scrcol,
+				ACS_CKBOARD | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D), showing);
+	}
+
+	mvwaddch(widget->window, 0, scrcol,
+			(lines ? ACS_UARROW : ' ') | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D));
+	mvwaddch(widget->window, widget->priv.height - 1, scrcol,
+			((view->list && view->list->prev) ? ACS_DARROW : ' ') |
+				COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D));
 
 	DEBUG;
 }
@@ -133,7 +151,7 @@
 	GNT_WIDGET_SET_FLAGS(GNT_WIDGET(instance), GNT_WIDGET_GROW_Y);
 
 	widget->priv.minw = 5;
-	widget->priv.minh = 1;
+	widget->priv.minh = 2;
 	DEBUG;
 }
 
--- a/console/libgnt/gnttree.c	Mon Aug 14 21:46:17 2006 +0000
+++ b/console/libgnt/gnttree.c	Tue Aug 15 02:45:52 2006 +0000
@@ -246,10 +246,11 @@
 static void
 redraw_tree(GntTree *tree)
 {
-	int start;
+	int start, i;
 	GntWidget *widget = GNT_WIDGET(tree);
 	GntTreeRow *row;
-	int pos, up, down, nr;
+	int pos, up, down;
+	int showing, position, rows, scrcol;
 
 	if (!GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_MAPPED))
 		return;
@@ -273,7 +274,7 @@
 		int x = pos;
 
 		mvwhline(widget->window, pos + 1, pos, ACS_HLINE | COLOR_PAIR(GNT_COLOR_NORMAL),
-				widget->priv.width - pos - 1);
+				widget->priv.width - pos);
 		
 		for (i = 0; i < tree->ncol; i++)
 		{
@@ -291,11 +292,11 @@
 		start = 2;
 	}
 
-	nr = widget->priv.height - pos * 2 - start - 1;
-	tree->bottom = get_next_n_opt(tree->top, nr, &down);
-	if (down < nr)
+	rows = widget->priv.height - pos * 2 - start - 1;
+	tree->bottom = get_next_n_opt(tree->top, rows, &down);
+	if (down < rows)
 	{
-		tree->top = get_prev_n(tree->bottom, nr);
+		tree->top = get_prev_n(tree->bottom, rows);
 		if (tree->top == NULL)
 			tree->top = tree->root;
 	}
@@ -304,17 +305,11 @@
 	if (up < 0)
 		tree->top = tree->current;
 	else if (up >= widget->priv.height - pos)
-		tree->top = get_prev_n(tree->current, nr);
-
-	mvwaddch(widget->window, start + pos,
-			widget->priv.width - pos - 1,
-			(tree->top != tree->root) ? 
-			ACS_UARROW | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D) :
-			' '| COLOR_PAIR(GNT_COLOR_NORMAL));
+		tree->top = get_prev_n(tree->current, rows);
 
 	row = tree->top;
-	for (start = start + pos; row && start < widget->priv.height - pos;
-				start++, row = get_next(row))
+	for (i = start + pos; row && i < widget->priv.height - pos;
+				i++, row = get_next(row))
 	{
 		char *str;
 		int wr;
@@ -356,28 +351,56 @@
 		}
 
 		wbkgdset(widget->window, '\0' | attr);
-		mvwprintw(widget->window, start, pos, str);
+		mvwprintw(widget->window, i, pos, str);
 		whline(widget->window, ' ', widget->priv.width - pos * 2 - g_utf8_strlen(str, -1) - 1);
 		tree->bottom = row;
 		g_free(str);
-		tree_mark_columns(tree, pos, start, ACS_VLINE | attr);
+		tree_mark_columns(tree, pos, i, ACS_VLINE | attr);
+	}
+
+	wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL));
+	while (i < widget->priv.height - pos)
+	{
+		mvwhline(widget->window, i, pos, ' ',
+				widget->priv.width - pos * 2 - 1);
+		tree_mark_columns(tree, pos, i, ACS_VLINE);
+		i++;
 	}
 
-	mvwaddch(widget->window, widget->priv.height - pos - 1,
-			widget->priv.width - pos - 1,
-			get_next(tree->bottom) ? 
-			ACS_DARROW | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D) :
-			' '| COLOR_PAIR(GNT_COLOR_NORMAL));
+	scrcol = widget->priv.width - pos - 1;
+	rows--;
+	if (rows > 0)
+	{
+		get_next_n_opt(tree->root, g_list_length(tree->list), &i);
+		showing = rows * rows / MAX(i, 1) + 1;
+		showing = MIN(rows, showing);
+
+		position = showing * get_distance(tree->root, tree->top) / rows;
+		position = MAX((tree->top != tree->root), position);
+
+		if (showing + position > rows)
+			position = rows - showing;
 
-	wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL));
-	while (start < widget->priv.height - pos)
-	{
-		mvwhline(widget->window, start, pos, ' ',
-				widget->priv.width - pos * 2 - 1);
-		tree_mark_columns(tree, pos, start, ACS_VLINE);
-		start++;
+		if (showing + position == rows  && row)
+			position = MAX(0, rows - 1 - showing);
+		else if (showing + position < rows && !row)
+			position = rows - showing;
+
+		position += pos + start + 1;
+
+		mvwvline(widget->window, pos + start + 1, scrcol,
+				' ' | COLOR_PAIR(GNT_COLOR_NORMAL), rows);
+		mvwvline(widget->window, position, scrcol,
+				ACS_CKBOARD | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D), showing);
 	}
 
+	mvwaddch(widget->window, start + pos, scrcol,
+			((tree->top != tree->root) ?  ACS_UARROW : ' ') |
+				COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D));
+
+	mvwaddch(widget->window, widget->priv.height - pos - 1, scrcol,
+			(row ?  ACS_DARROW : ' ') | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D));
+
 	gnt_widget_queue_update(widget);
 }
 
@@ -550,7 +573,7 @@
 	GntWidget *widget = GNT_WIDGET(instance);
 	GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_X | GNT_WIDGET_GROW_Y);
 	widget->priv.minw = 4;
-	widget->priv.minh = 3;
+	widget->priv.minh = 4;
 	DEBUG;
 }
 
@@ -1007,7 +1030,7 @@
 	va_start(args, tree);
 	for (i = 0; i < tree->ncol; i++)
 	{
-		list = g_list_append(list, va_arg(args, const char *));
+		list = g_list_append(list, va_arg(args, char *));
 	}
 	va_end(args);
 
@@ -1041,6 +1064,7 @@
 void gnt_tree_set_show_title(GntTree *tree, gboolean set)
 {
 	tree->show_title = set;
+	GNT_WIDGET(tree)->priv.minh = (set ? 6 : 4);
 }
 
 void gnt_tree_set_compare_func(GntTree *tree, GCompareFunc func)
--- a/console/libgnt/test/multiwin.c	Mon Aug 14 21:46:17 2006 +0000
+++ b/console/libgnt/test/multiwin.c	Tue Aug 15 02:45:52 2006 +0000
@@ -62,6 +62,14 @@
 
 	gnt_tree_add_row_after(GNT_TREE(tree), "6", gnt_tree_create_row(GNT_TREE(tree), "6", " long text", "a2"), "4", NULL);
 
+	int i;
+	for (i = 110; i < 130; i++)
+	{
+		char *s;
+		s = g_strdup_printf("%d", i); /* XXX: yes, leaking */
+		gnt_tree_add_row_after(GNT_TREE(tree), s, gnt_tree_create_row(GNT_TREE(tree), s, " long text", "a2"), "4", NULL);
+	}
+
 	gnt_tree_set_row_flags(GNT_TREE(tree), "e", GNT_TEXT_FLAG_DIM);
 
 	gnt_tree_set_selected(GNT_TREE(tree), "2");