From 1270687440369efa3aad794ba49214cebee98d83 Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Fri, 16 Apr 1999 18:25:00 +0000 Subject: [PATCH] 1999-04-16 Federico Mena Quintero * gscreen.c (panel_tree_check_auto_expand): Enabled auto-collapse functionality again. Made the code a simpler by using gtk_dtree_is_ancestor(). * gtkdtree.c (gtk_dtree_is_ancestor): New function to test whether a node is an ancestor of a child. This does the same as gtk_ctree_is_ancestor(), but much more efficiently. GtkCTree seems to use the pessimal algorithm for this. (gtk_dtree_collapse): Slight optimization: do not re-select if the node is already selected. (gtk_dtree_collapse): Do not freeze/thaw the tree while collapsing/selecting. * gmain.c: Removed crufty old SM code. --- gnome/ChangeLog | 17 ++++++++++ gnome/gmain.c | 71 -------------------------------------- gnome/gscreen.c | 88 ++++++++++++++++++++++-------------------------- gnome/gtkdtree.c | 33 +++++++++++++++--- gnome/gtkdtree.h | 2 ++ 5 files changed, 88 insertions(+), 123 deletions(-) diff --git a/gnome/ChangeLog b/gnome/ChangeLog index b52f61db7..65dfc864a 100644 --- a/gnome/ChangeLog +++ b/gnome/ChangeLog @@ -1,3 +1,20 @@ +1999-04-16 Federico Mena Quintero + + * gscreen.c (panel_tree_check_auto_expand): Enabled auto-collapse + functionality again. Made the code a simpler by using + gtk_dtree_is_ancestor(). + + * gtkdtree.c (gtk_dtree_is_ancestor): New function to test whether + a node is an ancestor of a child. This does the same as + gtk_ctree_is_ancestor(), but much more efficiently. GtkCTree + seems to use the pessimal algorithm for this. + (gtk_dtree_collapse): Slight optimization: do not re-select if the + node is already selected. + (gtk_dtree_collapse): Do not freeze/thaw the tree while + collapsing/selecting. + + * gmain.c: Removed crufty old SM code. + 1999-04-15 Federico Mena Quintero * gscreen.c (panel_setup_drag_scroll): Made it not return diff --git a/gnome/gmain.c b/gnome/gmain.c index 6c8dddeb5..9e78cbed3 100644 --- a/gnome/gmain.c +++ b/gnome/gmain.c @@ -528,78 +528,7 @@ gmc_do_quit (void) quit = 1; dlg_stop (desktop_dlg); } -#if 0 -static void -session_die (void) -{ - gmc_do_quit (); -} -/* - * Save the session callback - */ -static int -session_save_state (GnomeClient *client, gint phase, GnomeRestartStyle save_style, gint shutdown, - GnomeInteractStyle interact_style, gint fast, gpointer client_data) -{ - char *sess_id; - char **argv = g_malloc (sizeof (char *) * ((g_list_length (containers) * 3) + 2)); - GList *l, *free_list = 0; - int i; - - sess_id = gnome_client_get_id (client); - - argv [0] = client_data; - for (i = 1, l = containers; l; l = l->next){ - PanelContainer *pc = l->data; - char *geom; - - geom = gnome_geometry_string (GTK_WIDGET (pc->panel->widget.wdata)->window); - - argv [i++] = pc->panel->cwd; - argv [i++] = "--geometry"; - argv [i++] = geom; - free_list = g_list_append (free_list, geom); - } - - /* If no windows were open */ - if (i == 1){ - argv [i++] = "--nowindows"; - } - - argv [i] = NULL; - gnome_client_set_clone_command (client, i, argv); - gnome_client_set_restart_command (client, i, argv); - gnome_config_sync (); - - for (l = free_list; l; l = l->next) - g_free (l->data); - g_list_free (free_list); - - g_free (argv); - - if (shutdown){ - quit = 1; - dlg_stop (midnight_dlg); - } - return 1; -} - -void -session_management_setup (char *name) -{ - session_client = gnome_master_client (); - - if (session_client){ - gnome_client_set_restart_style (session_client, - finish_program ? GNOME_RESTART_NEVER : GNOME_RESTART_IMMEDIATELY); - gtk_signal_connect (GTK_OBJECT (session_client), "save_yourself", - GTK_SIGNAL_FUNC (session_save_state), name); - gtk_signal_connect (GTK_OBJECT (session_client), "die", - GTK_SIGNAL_FUNC (session_die), NULL); - } -} -#endif /* * Configures the GtkWindow/GnomeDialog from a WPanel. * diff --git a/gnome/gscreen.c b/gnome/gscreen.c index 708e763ab..19a326b41 100644 --- a/gnome/gscreen.c +++ b/gnome/gscreen.c @@ -1980,8 +1980,6 @@ tree_drag_open_directory (gpointer data) WPanel *panel; GtkDTree *dtree; GtkCTreeNode *node; - int row, col; - int on_row; panel = data; dtree = GTK_DTREE (panel->tree); @@ -1989,67 +1987,59 @@ tree_drag_open_directory (gpointer data) node = gtk_ctree_node_nth (GTK_CTREE (panel->tree), panel->drag_tree_row); g_assert (node != NULL); - if (!GTK_CTREE_ROW (node)->expanded) + if (!GTK_CTREE_ROW (node)->expanded) { dtree->auto_expanded_nodes = g_list_append (dtree->auto_expanded_nodes, node); - - gtk_ctree_expand (GTK_CTREE (panel->tree), node); + gtk_ctree_expand (GTK_CTREE (panel->tree), node); + } return FALSE; } +/* Handles automatic collapsing of the tree nodes when doing drag and drop */ static void panel_tree_check_auto_expand (WPanel *panel, GtkCTreeNode *current) { - GtkDTree *dtree = GTK_DTREE (panel->tree); - GList *tmp_list = dtree->auto_expanded_nodes; -#if 0 - GtkCList *clist = GTK_CLIST (dtree); + GtkDTree *dtree; + GtkCTree *ctree; + GtkCList *clist; + GList *free_list; + GList *tmp_list; gint row, old_y, new_y; -#endif - if (current) { - while (tmp_list) { - GtkCTreeNode *parent_node = tmp_list->data; - GtkCTreeNode *tmp_node = current; + dtree = GTK_DTREE (panel->tree); + ctree = GTK_CTREE (panel->tree); + clist = GTK_CLIST (panel->tree); + tmp_list = dtree->auto_expanded_nodes; - while (tmp_node) { - if (tmp_node == parent_node) - break; - tmp_node = GTK_CTREE_ROW (tmp_node)->parent; - } - if (!tmp_node) /* parent not found */ + if (current) + for (; tmp_list; tmp_list = tmp_list->next) + if (!gtk_dtree_is_ancestor (dtree, tmp_list->data, current)) break; - - tmp_list = tmp_list->next; - } - } - /* Collapse the rows as necessary. If possible, try to do - * so that the "current" stays the same place on the - * screen + /* Collapse the rows as necessary. If possible, try to do so that the + * "current" stays the same place on the screen. */ -#if 0 - /* This behaviour is confusing --jrb and quartic (and MS, apparently)*/ if (tmp_list) { if (current) { - row = g_list_position (clist->row_list, (GList *)current); + row = g_list_position (clist->row_list, (GList *) current); old_y = row * clist->row_height - clist->vadjustment->value; } - - free_list = tmp_list; - while (tmp_list) { - gtk_ctree_collapse (GTK_CTREE (panel->tree), tmp_list->data); - tmp_list = tmp_list->next; - } + free_list = tmp_list; + + for (; tmp_list; tmp_list = tmp_list->next) + gtk_ctree_collapse (GTK_CTREE (panel->tree), tmp_list->data); + + /* We have to calculate the row position again because rows may + * have shifted during the collapse. + */ if (current) { - row = g_list_position (clist->row_list, (GList *)current); + row = g_list_position (clist->row_list, (GList *) current); new_y = row * clist->row_height - clist->vadjustment->value; - if (new_y != old_y) { + if (new_y != old_y) gtk_adjustment_set_value (clist->vadjustment, clist->vadjustment->value + new_y - old_y); - } } if (free_list->prev) @@ -2060,7 +2050,6 @@ panel_tree_check_auto_expand (WPanel *panel, GtkCTreeNode *current) free_list->prev = NULL; g_list_free (free_list); } -#endif } /** @@ -2128,6 +2117,7 @@ panel_tree_drag_motion (GtkWidget *widget, GdkDragContext *context, int x, int y GtkDTree *dtree; WPanel *panel; int on_row, row, col; + GtkCTreeNode *node; GdkDragAction action; GtkWidget *source_widget; char *row_path; @@ -2159,15 +2149,14 @@ panel_tree_drag_motion (GtkWidget *widget, GdkDragContext *context, int x, int y action = 0; if (on_row) { - row_path = gtk_dtree_get_row_path (dtree, - gtk_ctree_node_nth (GTK_CTREE (dtree), row), - 0); + node = gtk_ctree_node_nth (GTK_CTREE (dtree), row); + row_path = gtk_dtree_get_row_path (dtree, node, 0); if (row != panel->drag_tree_row) { /* Highlight the row by selecting it */ -#if 0 - panel_tree_check_auto_expand (GTK_CTREE (widget), row); -#endif + + panel_tree_check_auto_expand (panel, node); + dtree->internal = TRUE; gtk_clist_select_row (GTK_CLIST (widget), row, 0); dtree->internal = FALSE; @@ -2215,8 +2204,10 @@ panel_tree_drag_motion (GtkWidget *widget, GdkDragContext *context, int x, int y g_free (parent_dir); g_free (row_path); - } else + } else { panel->drag_tree_row = -1; + panel_tree_check_auto_expand (panel, NULL); + } gdk_drag_status (context, action, time); return TRUE; @@ -2244,6 +2235,9 @@ panel_tree_drag_leave (GtkWidget *widget, GdkDragContext *context, guint time, g panel->drag_tree_fe = NULL; } + if (panel->drag_tree_row != -1) + panel_tree_check_auto_expand (panel, NULL); + panel->drag_tree_row = -1; } diff --git a/gnome/gtkdtree.c b/gnome/gtkdtree.c index 6ac281a9d..4a470226d 100644 --- a/gnome/gtkdtree.c +++ b/gnome/gtkdtree.c @@ -459,18 +459,14 @@ gtk_dtree_collapse (GtkCTree *ctree, GtkCTreeNode *node) if (!sel) do_select = TRUE; else { - if (gtk_ctree_is_ancestor (ctree, node, sel->data)) + if (node != sel->data && gtk_dtree_is_ancestor (GTK_DTREE (ctree), node, sel->data)) do_select = TRUE; } - gtk_clist_freeze (GTK_CLIST (ctree)); - (* parent_class->tree_collapse) (ctree, node); if (do_select) gtk_ctree_select (ctree, node); - - gtk_clist_thaw (GTK_CLIST (ctree)); } /* @@ -808,3 +804,30 @@ gtk_dtree_get_type (void) return dtree_type; } + +/** + * gtk_dtree_is_ancestor: + * @dtree: A tree + * @node: The presumed ancestor node + * @child: The presumed child node + * + * Tests whether a node is an ancestor of a child node. This does this in + * O(height of child), instead of O(number of children in node), like GtkCTree + * does. + * + * Return value: TRUE if the node is an ancestor of the child, FALSE otherwise. + **/ +gboolean +gtk_dtree_is_ancestor (GtkDTree *dtree, GtkCTreeNode *node, GtkCTreeNode *child) +{ + g_return_val_if_fail (dtree != NULL, FALSE); + g_return_val_if_fail (GTK_IS_DTREE (dtree), FALSE); + g_return_val_if_fail (node != NULL, FALSE); + g_return_val_if_fail (child != NULL, FALSE); + + for (; child; child = GTK_CTREE_ROW (child)->parent) + if (child == node) + return TRUE; + + return FALSE; +} diff --git a/gnome/gtkdtree.h b/gnome/gtkdtree.h index 54a0542cc..f817b4958 100644 --- a/gnome/gtkdtree.h +++ b/gnome/gtkdtree.h @@ -55,4 +55,6 @@ char *gtk_dtree_get_row_path (GtkDTree *ctree, gint column); void gtk_dtree_construct (GtkDTree *dtree); +gboolean gtk_dtree_is_ancestor (GtkDTree *dtree, GtkCTreeNode *node, GtkCTreeNode *child); + #endif