[sysprof/newui: 23/24] Improved scrolling



commit 7adb36b772937dc17c03936f36e9cb618fb4e062
Author: SÃren Sandmann Pedersen <ssp l3000 localdomain>
Date:   Thu Nov 11 15:13:04 2010 -0500

    Improved scrolling

 sysprof.c     |   98 ++++++++++++++++++++++++++++++++-------------------------
 sysprof.glade |    2 +-
 2 files changed, 56 insertions(+), 44 deletions(-)
---
diff --git a/sysprof.c b/sysprof.c
index b913f9f..208cb89 100644
--- a/sysprof.c
+++ b/sysprof.c
@@ -68,6 +68,7 @@ struct Application
     GtkWidget *		open_item;
     GtkWidget *		about_item;
     GtkWidget *		quit_item;
+    GtkWidget *		scrolled_window;
 
     GtkTreeSelection *	object_selection;
 
@@ -839,19 +840,21 @@ expand_descendants_tree (Application *app, gpointer object)
     int max_rows = 40; /* FIXME */
     double top_value = 0.0;
     GtkTreePath *first_path;
+    GtkTreePath *target;
+    GdkRectangle rect;
     GList *list;
-
+    GtkAdjustment *adj;
+    
     if (!(first_path = find_object (model, object)))
 	return;
 
+    target = gtk_tree_path_copy (first_path);
+    
+    gtk_tree_view_set_cursor (app->descendants_view, target,
+			      NULL, FALSE);
+
     gtk_tree_view_collapse_all (app->descendants_view);
 
-    gtk_tree_view_set_cursor (app->descendants_view, first_path,
-			      NULL, FALSE);
-    
-    gtk_tree_view_scroll_to_cell (app->descendants_view, first_path, NULL,
-				  FALSE, 0, 0);
-    
     all_paths = g_list_prepend (all_paths, first_path);
 
     n_rows = 1;
@@ -888,7 +891,7 @@ expand_descendants_tree (Application *app, gpointer object)
 
 		if (value < 0)
 		    value = 100.0;
-		
+
 		if (value >= best_value)
 		{
 		    best_value = value;
@@ -940,6 +943,16 @@ expand_descendants_tree (Application *app, gpointer object)
     for (list = all_paths; list != NULL; list = list->next)
 	gtk_tree_path_free (list->data);
 
+    gtk_tree_view_get_cell_area (app->descendants_view, target,
+				 NULL, &rect);
+
+    adj = gtk_scrolled_window_get_vadjustment (app->scrolled_window);
+
+    gtk_tree_view_convert_bin_window_to_tree_coords (
+	app->descendants_view, 0, rect.y, NULL, &rect.y);
+
+    gtk_adjustment_set_value (adj, rect.y - 18);
+
     g_list_free (all_paths);
 }
 
@@ -989,25 +1002,25 @@ gather_widgets (Application *app)
 	const char *name;
     } WidgetInfo;
 
-    const WidgetInfo widgets[] =
-	{
-	    { &app->main_window, "main_window" },
-	    { &app->start_button, "start_button" },
-	    { &app->profile_button, "profile_button" },
-	    { &app->reset_button, "reset_button" },
-	    { &app->save_as_button, "save_as_button" },
-	    { &app->dummy_button, "dummy_button" },
-	    { &app->samples_label, "samples_label" },
-	    { &app->samples_hbox, "samples_hbox" },
-	    { &app->start_item, "start_item" },
-	    { &app->profile_item, "profile_item" },
-	    { &app->reset_item, "reset_item" },
-	    { &app->open_item, "open_item" },
-	    { &app->save_as_item, "save_as_item" },
-	    { &app->quit_item, "quit" },
-	    { &app->about_item, "about" },
-	    { &app->descendants_view, "descendants_view" },
-	};
+    const WidgetInfo widgets[] = {
+	{ &app->main_window, "main_window" },
+	{ &app->start_button, "start_button" },
+	{ &app->profile_button, "profile_button" },
+	{ &app->reset_button, "reset_button" },
+	{ &app->save_as_button, "save_as_button" },
+	{ &app->dummy_button, "dummy_button" },
+	{ &app->samples_label, "samples_label" },
+	{ &app->samples_hbox, "samples_hbox" },
+	{ &app->start_item, "start_item" },
+	{ &app->profile_item, "profile_item" },
+	{ &app->reset_item, "reset_item" },
+	{ &app->open_item, "open_item" },
+	{ &app->save_as_item, "save_as_item" },
+	{ &app->quit_item, "quit" },
+	{ &app->about_item, "about" },
+	{ &app->descendants_view, "descendants_view" },
+	{ &app->scrolled_window, "scrolled_window" },
+    };
 
     GladeXML *xml = glade_xml_new (GLADE_FILE, NULL, NULL);
     int i;
@@ -1035,22 +1048,21 @@ connect_signals (Application *app)
 	gpointer data;
     } SignalInfo;
 
-    const SignalInfo signals[] =
-	{
-	    { app->main_window, "delete_event", on_delete, NULL },
-	    { app->start_button, "toggled", on_start_toggled, app },
-	    { app->profile_button, "toggled", on_profile_toggled, app },
-	    { app->reset_button, "clicked", on_reset_clicked, app },
-	    { app->save_as_button, "clicked", on_save_as_clicked, app },
-	    { app->start_item, "activate", on_menu_item_activated, app->start_button },
-	    { app->profile_item, "activate", on_menu_item_activated, app->profile_button },
-	    { app->reset_item, "activate", on_reset_clicked, app },
-	    { app->open_item, "activate", on_open_clicked, app },
-	    { app->save_as_item, "activate", on_save_as_clicked, app },
-	    { app->quit_item, "activate", on_delete, NULL },
-	    { app->about_item, "activate", on_about_activated, app },
-	    { app->descendants_view, "row-activated", on_descendants_row_activated, app },
-	};
+    const SignalInfo signals[] = {
+	{ app->main_window, "delete_event", on_delete, NULL },
+	{ app->start_button, "toggled", on_start_toggled, app },
+	{ app->profile_button, "toggled", on_profile_toggled, app },
+	{ app->reset_button, "clicked", on_reset_clicked, app },
+	{ app->save_as_button, "clicked", on_save_as_clicked, app },
+	{ app->start_item, "activate", on_menu_item_activated, app->start_button },
+	{ app->profile_item, "activate", on_menu_item_activated, app->profile_button },
+	{ app->reset_item, "activate", on_reset_clicked, app },
+	{ app->open_item, "activate", on_open_clicked, app },
+	{ app->save_as_item, "activate", on_save_as_clicked, app },
+	{ app->quit_item, "activate", on_delete, NULL },
+	{ app->about_item, "activate", on_about_activated, app },
+	{ app->descendants_view, "row-activated", on_descendants_row_activated, app },
+    };
 
     int i;
 
diff --git a/sysprof.glade b/sysprof.glade
index cacdb87..175f0dc 100644
--- a/sysprof.glade
+++ b/sysprof.glade
@@ -640,7 +640,7 @@
       </child>
 
       <child>
-	<widget class="GtkScrolledWindow" id="scrolledwindow2">
+	<widget class="GtkScrolledWindow" id="scrolled_window">
 	  <property name="visible">True</property>
 	  <property name="can_focus">True</property>
 	  <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]