changeset 1629:f8503019ac38

better implementation of tree_view_row_get_visibility, gtk_tree_view_set_cursor is not sufficient in some cases, call also tree_view_row_make_visible
author nadvornik
date Sat, 06 Jun 2009 16:14:07 +0000
parents 738b70daa3af
children 0204d7c830fb
files src/ui_tree_edit.c src/view_dir_tree.c
diffstat 2 files changed, 50 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/ui_tree_edit.c	Sat Jun 06 15:33:56 2009 +0000
+++ b/src/ui_tree_edit.c	Sat Jun 06 16:14:07 2009 +0000
@@ -343,6 +343,51 @@
 	*height = MIN(*height, wy + wh - (*y));
 }
 
+#if GTK_CHECK_VERSION(2,8,0)
+/* an implementation that uses gtk_tree_view_get_visible_range */
+gint tree_view_row_get_visibility(GtkTreeView *widget, GtkTreeIter *iter, gboolean fully_visible)
+{
+	GtkTreeModel *store;
+	GtkTreePath *tpath, *start_path, *end_path;
+	gint ret = 0;
+
+	if (!gtk_tree_view_get_visible_range(widget, &start_path, &end_path)) return -1; /* we will most probably scroll down, needed for tree_view_row_make_visible */
+
+	store = gtk_tree_view_get_model(widget);
+	tpath = gtk_tree_model_get_path(store, iter);
+
+	if (fully_visible)
+		{
+		if (gtk_tree_path_compare(tpath, start_path) <= 0)
+			{
+			ret = -1;
+			}
+		else if (gtk_tree_path_compare(tpath, end_path) >= 0)
+			{
+			ret = 1;
+			}
+		}
+	else
+		{
+		if (gtk_tree_path_compare(tpath, start_path) < 0)
+			{
+			ret = -1;
+			}
+		else if (gtk_tree_path_compare(tpath, end_path) > 0)
+			{
+			ret = 1;
+			}
+		}
+
+	gtk_tree_path_free(tpath);
+	gtk_tree_path_free(start_path);
+	gtk_tree_path_free(end_path);
+	return ret;
+}
+
+#else 
+/* an implementation that uses gtk_tree_view_get_visible_rect, it seems to be more error prone than the variant above */
+
 gint tree_view_row_get_visibility(GtkTreeView *widget, GtkTreeIter *iter, gboolean fully_visible)
 {
 	GtkTreeModel *store;
@@ -379,6 +424,7 @@
 	if (cy > vrect.y + vrect.height) return 1;
 	return 0;
 }
+#endif
 
 gint tree_view_row_make_visible(GtkTreeView *widget, GtkTreeIter *iter, gboolean center)
 {
--- a/src/view_dir_tree.c	Sat Jun 06 15:33:56 2009 +0000
+++ b/src/view_dir_tree.c	Sat Jun 06 16:14:07 2009 +0000
@@ -720,6 +720,10 @@
 			{
 			/* setting the cursor scrolls the view; do not do that unless it is necessary */
 			gtk_tree_view_set_cursor(GTK_TREE_VIEW(vd->view), tpath, NULL, FALSE);
+			
+			/* gtk_tree_view_set_cursor scrolls the window itself, but it sometimes
+			   does not work (switch from dir_list to dir_tree) */
+			tree_view_row_make_visible(GTK_TREE_VIEW(vd->view), &iter, TRUE);
 			}
 		gtk_tree_path_free(tpath);
 		gtk_tree_path_free(old_tpath);