From: Jonathan Blandford Date: Thu, 7 Mar 2002 08:03:09 +0000 (+0000) Subject: start implementing X-Git-Url: http://pileus.org/git/?p=~andy%2Fgtk;a=commitdiff_plain;h=110e1cd7115b252efef82914fa8df7c6fe83a410 start implementing Thu Mar 7 02:58:16 2002 Jonathan Blandford * gtk/tmpl/gtkliststore.sgml: start implementing * gtk/question_index.sgml: "I can set with the tree, but not get???!?!" Wed Mar 6 23:20:51 2002 Jonathan Blandford and Kristian Rietveld Finishing touch for 2.0.0 release, fixes #70782, #72729, the 'stealth' bug and other last-minute minor issues. * gtk/gtktreeview.c (gtk_tree_view_bin_expose): set dnd dest line drawing right. We can't draw the line at the position of the next row, because that one still has to be drawn. So draw everthing at a -1 offset. (validate_visible_area): add check for invalid descendants and NULL scroll_to_path path, get scrolling right. Also, fix the area_above value. Pretty amazing I got it wrong. (get_logical_dest_row): add gtk-tree-model-drop-append magic, so dragging a row to the end of the model works right. (gtk_tree_view_get_dest_row_at_pos): minor floating point fix (gtk_tree_view_start_editing): add call to validate_row (gtk_tree_view_tree_to_widget_coords): Never subtract HEADER_HEIGHT from y values anymore!!! (gtk_tree_view_widget_coords_to_tree): ditto. (gtk_tree_view_scroll_to_point): allow -1 as values for the scroll_to coords (gtk_tree_view_move_cursor_page_up_down): Don't need scroll_to_y as clamp_node_visible will make it work. * gtk/gtktreestore.c (gtk_tree_store_drag_data_received): also check path depth, as we can't get iters from empty paths * gtk/gtkliststore.c (gtk_list_store_drag_data_received): handle gtk-tree-model-drop-append * gtk/gtktreednd.c (gtk_tree_set_row_drag_data): free path_str * tests/testtreeflow.c (main): select path where we are scrolling to --- diff --git a/ChangeLog b/ChangeLog index 2f67c70e5..eff277e92 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,38 @@ +Wed Mar 6 23:20:51 2002 Jonathan Blandford +and Kristian Rietveld + + Finishing touch for 2.0.0 release, fixes #70782, #72729, the + 'stealth' bug and other last-minute minor issues. + + * gtk/gtktreeview.c (gtk_tree_view_bin_expose): set dnd dest line + drawing right. We can't draw the line at the position of the next + row, because that one still has to be drawn. So draw everthing at + a -1 offset. + (validate_visible_area): add check for invalid descendants and + NULL scroll_to_path path, get scrolling right. Also, fix the + area_above value. Pretty amazing I got it wrong. + (get_logical_dest_row): add gtk-tree-model-drop-append magic, so + dragging a row to the end of the model works right. + (gtk_tree_view_get_dest_row_at_pos): minor floating point fix + (gtk_tree_view_start_editing): add call to validate_row + (gtk_tree_view_tree_to_widget_coords): Never subtract + HEADER_HEIGHT from y values anymore!!! + (gtk_tree_view_widget_coords_to_tree): ditto. + (gtk_tree_view_scroll_to_point): allow -1 as values for the + scroll_to coords + (gtk_tree_view_move_cursor_page_up_down): Don't need scroll_to_y + as clamp_node_visible will make it work. + + * gtk/gtktreestore.c (gtk_tree_store_drag_data_received): also check + path depth, as we can't get iters from empty paths + + * gtk/gtkliststore.c (gtk_list_store_drag_data_received): handle + gtk-tree-model-drop-append + + * gtk/gtktreednd.c (gtk_tree_set_row_drag_data): free path_str + + * tests/testtreeflow.c (main): select path where we are scrolling to + 2002-03-06 Darin Adler * gtk/gtktreemodelsort.c: (gtk_tree_model_sort_insert_value): diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 2f67c70e5..eff277e92 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,38 @@ +Wed Mar 6 23:20:51 2002 Jonathan Blandford +and Kristian Rietveld + + Finishing touch for 2.0.0 release, fixes #70782, #72729, the + 'stealth' bug and other last-minute minor issues. + + * gtk/gtktreeview.c (gtk_tree_view_bin_expose): set dnd dest line + drawing right. We can't draw the line at the position of the next + row, because that one still has to be drawn. So draw everthing at + a -1 offset. + (validate_visible_area): add check for invalid descendants and + NULL scroll_to_path path, get scrolling right. Also, fix the + area_above value. Pretty amazing I got it wrong. + (get_logical_dest_row): add gtk-tree-model-drop-append magic, so + dragging a row to the end of the model works right. + (gtk_tree_view_get_dest_row_at_pos): minor floating point fix + (gtk_tree_view_start_editing): add call to validate_row + (gtk_tree_view_tree_to_widget_coords): Never subtract + HEADER_HEIGHT from y values anymore!!! + (gtk_tree_view_widget_coords_to_tree): ditto. + (gtk_tree_view_scroll_to_point): allow -1 as values for the + scroll_to coords + (gtk_tree_view_move_cursor_page_up_down): Don't need scroll_to_y + as clamp_node_visible will make it work. + + * gtk/gtktreestore.c (gtk_tree_store_drag_data_received): also check + path depth, as we can't get iters from empty paths + + * gtk/gtkliststore.c (gtk_list_store_drag_data_received): handle + gtk-tree-model-drop-append + + * gtk/gtktreednd.c (gtk_tree_set_row_drag_data): free path_str + + * tests/testtreeflow.c (main): select path where we are scrolling to + 2002-03-06 Darin Adler * gtk/gtktreemodelsort.c: (gtk_tree_model_sort_insert_value): diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 2f67c70e5..eff277e92 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,38 @@ +Wed Mar 6 23:20:51 2002 Jonathan Blandford +and Kristian Rietveld + + Finishing touch for 2.0.0 release, fixes #70782, #72729, the + 'stealth' bug and other last-minute minor issues. + + * gtk/gtktreeview.c (gtk_tree_view_bin_expose): set dnd dest line + drawing right. We can't draw the line at the position of the next + row, because that one still has to be drawn. So draw everthing at + a -1 offset. + (validate_visible_area): add check for invalid descendants and + NULL scroll_to_path path, get scrolling right. Also, fix the + area_above value. Pretty amazing I got it wrong. + (get_logical_dest_row): add gtk-tree-model-drop-append magic, so + dragging a row to the end of the model works right. + (gtk_tree_view_get_dest_row_at_pos): minor floating point fix + (gtk_tree_view_start_editing): add call to validate_row + (gtk_tree_view_tree_to_widget_coords): Never subtract + HEADER_HEIGHT from y values anymore!!! + (gtk_tree_view_widget_coords_to_tree): ditto. + (gtk_tree_view_scroll_to_point): allow -1 as values for the + scroll_to coords + (gtk_tree_view_move_cursor_page_up_down): Don't need scroll_to_y + as clamp_node_visible will make it work. + + * gtk/gtktreestore.c (gtk_tree_store_drag_data_received): also check + path depth, as we can't get iters from empty paths + + * gtk/gtkliststore.c (gtk_list_store_drag_data_received): handle + gtk-tree-model-drop-append + + * gtk/gtktreednd.c (gtk_tree_set_row_drag_data): free path_str + + * tests/testtreeflow.c (main): select path where we are scrolling to + 2002-03-06 Darin Adler * gtk/gtktreemodelsort.c: (gtk_tree_model_sort_insert_value): diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 2f67c70e5..eff277e92 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,38 @@ +Wed Mar 6 23:20:51 2002 Jonathan Blandford +and Kristian Rietveld + + Finishing touch for 2.0.0 release, fixes #70782, #72729, the + 'stealth' bug and other last-minute minor issues. + + * gtk/gtktreeview.c (gtk_tree_view_bin_expose): set dnd dest line + drawing right. We can't draw the line at the position of the next + row, because that one still has to be drawn. So draw everthing at + a -1 offset. + (validate_visible_area): add check for invalid descendants and + NULL scroll_to_path path, get scrolling right. Also, fix the + area_above value. Pretty amazing I got it wrong. + (get_logical_dest_row): add gtk-tree-model-drop-append magic, so + dragging a row to the end of the model works right. + (gtk_tree_view_get_dest_row_at_pos): minor floating point fix + (gtk_tree_view_start_editing): add call to validate_row + (gtk_tree_view_tree_to_widget_coords): Never subtract + HEADER_HEIGHT from y values anymore!!! + (gtk_tree_view_widget_coords_to_tree): ditto. + (gtk_tree_view_scroll_to_point): allow -1 as values for the + scroll_to coords + (gtk_tree_view_move_cursor_page_up_down): Don't need scroll_to_y + as clamp_node_visible will make it work. + + * gtk/gtktreestore.c (gtk_tree_store_drag_data_received): also check + path depth, as we can't get iters from empty paths + + * gtk/gtkliststore.c (gtk_list_store_drag_data_received): handle + gtk-tree-model-drop-append + + * gtk/gtktreednd.c (gtk_tree_set_row_drag_data): free path_str + + * tests/testtreeflow.c (main): select path where we are scrolling to + 2002-03-06 Darin Adler * gtk/gtktreemodelsort.c: (gtk_tree_model_sort_insert_value): diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 2f67c70e5..eff277e92 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,38 @@ +Wed Mar 6 23:20:51 2002 Jonathan Blandford +and Kristian Rietveld + + Finishing touch for 2.0.0 release, fixes #70782, #72729, the + 'stealth' bug and other last-minute minor issues. + + * gtk/gtktreeview.c (gtk_tree_view_bin_expose): set dnd dest line + drawing right. We can't draw the line at the position of the next + row, because that one still has to be drawn. So draw everthing at + a -1 offset. + (validate_visible_area): add check for invalid descendants and + NULL scroll_to_path path, get scrolling right. Also, fix the + area_above value. Pretty amazing I got it wrong. + (get_logical_dest_row): add gtk-tree-model-drop-append magic, so + dragging a row to the end of the model works right. + (gtk_tree_view_get_dest_row_at_pos): minor floating point fix + (gtk_tree_view_start_editing): add call to validate_row + (gtk_tree_view_tree_to_widget_coords): Never subtract + HEADER_HEIGHT from y values anymore!!! + (gtk_tree_view_widget_coords_to_tree): ditto. + (gtk_tree_view_scroll_to_point): allow -1 as values for the + scroll_to coords + (gtk_tree_view_move_cursor_page_up_down): Don't need scroll_to_y + as clamp_node_visible will make it work. + + * gtk/gtktreestore.c (gtk_tree_store_drag_data_received): also check + path depth, as we can't get iters from empty paths + + * gtk/gtkliststore.c (gtk_list_store_drag_data_received): handle + gtk-tree-model-drop-append + + * gtk/gtktreednd.c (gtk_tree_set_row_drag_data): free path_str + + * tests/testtreeflow.c (main): select path where we are scrolling to + 2002-03-06 Darin Adler * gtk/gtktreemodelsort.c: (gtk_tree_model_sort_insert_value): diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 2f67c70e5..eff277e92 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,38 @@ +Wed Mar 6 23:20:51 2002 Jonathan Blandford +and Kristian Rietveld + + Finishing touch for 2.0.0 release, fixes #70782, #72729, the + 'stealth' bug and other last-minute minor issues. + + * gtk/gtktreeview.c (gtk_tree_view_bin_expose): set dnd dest line + drawing right. We can't draw the line at the position of the next + row, because that one still has to be drawn. So draw everthing at + a -1 offset. + (validate_visible_area): add check for invalid descendants and + NULL scroll_to_path path, get scrolling right. Also, fix the + area_above value. Pretty amazing I got it wrong. + (get_logical_dest_row): add gtk-tree-model-drop-append magic, so + dragging a row to the end of the model works right. + (gtk_tree_view_get_dest_row_at_pos): minor floating point fix + (gtk_tree_view_start_editing): add call to validate_row + (gtk_tree_view_tree_to_widget_coords): Never subtract + HEADER_HEIGHT from y values anymore!!! + (gtk_tree_view_widget_coords_to_tree): ditto. + (gtk_tree_view_scroll_to_point): allow -1 as values for the + scroll_to coords + (gtk_tree_view_move_cursor_page_up_down): Don't need scroll_to_y + as clamp_node_visible will make it work. + + * gtk/gtktreestore.c (gtk_tree_store_drag_data_received): also check + path depth, as we can't get iters from empty paths + + * gtk/gtkliststore.c (gtk_list_store_drag_data_received): handle + gtk-tree-model-drop-append + + * gtk/gtktreednd.c (gtk_tree_set_row_drag_data): free path_str + + * tests/testtreeflow.c (main): select path where we are scrolling to + 2002-03-06 Darin Adler * gtk/gtktreemodelsort.c: (gtk_tree_model_sort_insert_value): diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 2f67c70e5..eff277e92 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,38 @@ +Wed Mar 6 23:20:51 2002 Jonathan Blandford +and Kristian Rietveld + + Finishing touch for 2.0.0 release, fixes #70782, #72729, the + 'stealth' bug and other last-minute minor issues. + + * gtk/gtktreeview.c (gtk_tree_view_bin_expose): set dnd dest line + drawing right. We can't draw the line at the position of the next + row, because that one still has to be drawn. So draw everthing at + a -1 offset. + (validate_visible_area): add check for invalid descendants and + NULL scroll_to_path path, get scrolling right. Also, fix the + area_above value. Pretty amazing I got it wrong. + (get_logical_dest_row): add gtk-tree-model-drop-append magic, so + dragging a row to the end of the model works right. + (gtk_tree_view_get_dest_row_at_pos): minor floating point fix + (gtk_tree_view_start_editing): add call to validate_row + (gtk_tree_view_tree_to_widget_coords): Never subtract + HEADER_HEIGHT from y values anymore!!! + (gtk_tree_view_widget_coords_to_tree): ditto. + (gtk_tree_view_scroll_to_point): allow -1 as values for the + scroll_to coords + (gtk_tree_view_move_cursor_page_up_down): Don't need scroll_to_y + as clamp_node_visible will make it work. + + * gtk/gtktreestore.c (gtk_tree_store_drag_data_received): also check + path depth, as we can't get iters from empty paths + + * gtk/gtkliststore.c (gtk_list_store_drag_data_received): handle + gtk-tree-model-drop-append + + * gtk/gtktreednd.c (gtk_tree_set_row_drag_data): free path_str + + * tests/testtreeflow.c (main): select path where we are scrolling to + 2002-03-06 Darin Adler * gtk/gtktreemodelsort.c: (gtk_tree_model_sort_insert_value): diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index 4b2c0c9fa..682f0c83e 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,3 +1,10 @@ +Thu Mar 7 02:58:16 2002 Jonathan Blandford + + * gtk/tmpl/gtkliststore.sgml: start implementing + + * gtk/question_index.sgml: "I can set with the tree, but not + get???!?!" + Wed Mar 6 18:11:05 2002 Owen Taylor * gtk/resources.sgml: Mention the need to subscribe diff --git a/docs/reference/gtk/question_index.sgml b/docs/reference/gtk/question_index.sgml index 5ec2b48dd..871e8e179 100644 --- a/docs/reference/gtk/question_index.sgml +++ b/docs/reference/gtk/question_index.sgml @@ -503,6 +503,31 @@ column. + + +I can set data easily on my GtkTreeStore/GtkListStore models using gtk_list_store_set() and gtk_tree_store_set(), but can't read + it back? + + + + +Both the GtkTreeStore and the GtkListStore implement the + GtkTreeModel + interface. Consequentially, the can use any function + this interface implements. The easiest way to read a + set of data back is to use + gtk_tree_model_get(). + + + + diff --git a/docs/reference/gtk/tmpl/gtkliststore.sgml b/docs/reference/gtk/tmpl/gtkliststore.sgml index b4aafd71f..b0d2f7040 100644 --- a/docs/reference/gtk/tmpl/gtkliststore.sgml +++ b/docs/reference/gtk/tmpl/gtkliststore.sgml @@ -6,7 +6,12 @@ GtkListStore - +The #GtkListStore object is a list model for use with a #GtkTreeView +widget. It implements the #GtkTreeModel interface, and consequentialy, +can use all of the methods available there. It also implements the +#GtkTreeSortable interface so you can sort the list using the view. +Finally, it also implements the tree drag and +drop interfaces. diff --git a/gtk/gtkliststore.c b/gtk/gtkliststore.c index 004abc5ce..a8bedeecd 100644 --- a/gtk/gtkliststore.c +++ b/gtk/gtkliststore.c @@ -1437,13 +1437,20 @@ gtk_list_store_drag_data_received (GtkTreeDragDest *drag_dest, prev)) { GtkTreeIter tmp_iter = dest_iter; - gtk_list_store_insert_after (GTK_LIST_STORE (tree_model), - &dest_iter, - &tmp_iter); + + if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_model), "gtk-tree-model-drop-append"))) + gtk_list_store_append (GTK_LIST_STORE (tree_model), &dest_iter); + else + gtk_list_store_insert_after (GTK_LIST_STORE (tree_model), + &dest_iter, &tmp_iter); + retval = TRUE; } } + g_object_set_data (G_OBJECT (tree_model), "gtk-tree-model-drop-append", + NULL); + gtk_tree_path_free (prev); /* If we succeeded in creating dest_iter, copy data from src diff --git a/gtk/gtktreednd.c b/gtk/gtktreednd.c index 22873b126..8fbeabb2d 100644 --- a/gtk/gtktreednd.c +++ b/gtk/gtktreednd.c @@ -256,6 +256,8 @@ gtk_tree_set_row_drag_data (GtkSelectionData *selection_data, trd = g_malloc (struct_size); strcpy (trd->path, path_str); + + g_free (path_str); trd->model = tree_model; diff --git a/gtk/gtktreestore.c b/gtk/gtktreestore.c index 38164bb59..5b52b7437 100644 --- a/gtk/gtktreestore.c +++ b/gtk/gtktreestore.c @@ -1653,7 +1653,8 @@ gtk_tree_store_drag_data_received (GtkTreeDragDest *drag_dest, /* Get the parent, NULL if parent is the root */ dest_parent_p = NULL; parent = gtk_tree_path_copy (dest); - if (gtk_tree_path_up (parent)) + if (gtk_tree_path_up (parent) && + gtk_tree_path_get_depth (parent) > 0) { gtk_tree_model_get_iter (tree_model, &dest_parent, diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c index 0863568c9..2d952b19b 100644 --- a/gtk/gtktreeview.c +++ b/gtk/gtktreeview.c @@ -42,7 +42,7 @@ #define GTK_TREE_VIEW_SEARCH_DIALOG_KEY "gtk-tree-view-search-dialog" #define GTK_TREE_VIEW_PRIORITY_VALIDATE (GDK_PRIORITY_REDRAW + 5) -#define GTK_TREE_VIEW_NUM_ROWS_PER_IDLE 50 +#define GTK_TREE_VIEW_NUM_ROWS_PER_IDLE 500 #define SCROLL_EDGE_SIZE 15 #define EXPANDER_EXTRA_PADDING 4 @@ -2951,11 +2951,13 @@ gtk_tree_view_bin_expose (GtkWidget *widget, switch (tree_view->priv->drag_dest_pos) { case GTK_TREE_VIEW_DROP_BEFORE: - highlight_y = background_area.y - vertical_separator/2; + highlight_y = background_area.y - 1; + if (highlight_y < 0) + highlight_y = 0; break; case GTK_TREE_VIEW_DROP_AFTER: - highlight_y = background_area.y + background_area.height + vertical_separator/2; + highlight_y = background_area.y + background_area.height - 1; break; case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: @@ -3662,6 +3664,10 @@ validate_visible_area (GtkTreeView *tree_view) if (tree_view->priv->tree == NULL) return; + if (! GTK_RBNODE_FLAG_SET (tree_view->priv->tree->root, GTK_RBNODE_DESCENDANTS_INVALID) && + tree_view->priv->scroll_to_path == NULL) + return; + total_height = GTK_WIDGET (tree_view)->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view); /* First, we check to see if we need to scroll anywhere @@ -3684,12 +3690,13 @@ validate_visible_area (GtkTreeView *tree_view) gint height = MAX (GTK_RBNODE_GET_HEIGHT (node), tree_view->priv->expander_size); area_above = (total_height - height) * tree_view->priv->scroll_to_row_align; - area_below = total_height - height - area_above; + area_below = total_height - area_above - height; area_above = MAX (area_above, 0); area_below = MAX (area_below, 0); } else { + /* FIXME: */ g_warning ("non use_align not implemented yet"); gtk_tree_path_free (path); path = NULL; @@ -3818,23 +3825,27 @@ validate_visible_area (GtkTreeView *tree_view) } gtk_tree_path_free (path); - /* If we ran out of tree, and have extra area_below left, we need to remove it from the area_above */ + /* If we ran out of tree, and have extra area_below left, we need to remove it + * from the area_above */ if (area_below > 0) area_above += area_below; _gtk_tree_view_find_node (tree_view, above_path, &tree, &node); - _gtk_rbtree_prev_full (tree, node, &tree, &node); - if (! gtk_tree_path_prev (above_path) && node != NULL) - { - gtk_tree_path_free (above_path); - above_path = _gtk_tree_view_find_path (tree_view, tree, node); - } - while (node != NULL && area_above > 0) + /* We walk backwards */ + do { - /* We walk ever so slowly backwards... */ + _gtk_rbtree_prev_full (tree, node, &tree, &node); + if (! gtk_tree_path_prev (above_path) && node != NULL) + { + gtk_tree_path_free (above_path); + above_path = _gtk_tree_view_find_path (tree_view, tree, node); + } gtk_tree_model_get_iter (tree_view->priv->model, &iter, above_path); + if (node == NULL) + break; + if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_INVALID) || GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_COLUMN_INVALID)) { @@ -3843,29 +3854,24 @@ validate_visible_area (GtkTreeView *tree_view) size_changed = TRUE; } area_above -= MAX (GTK_RBNODE_GET_HEIGHT (node), tree_view->priv->expander_size); - - _gtk_rbtree_prev_full (tree, node, &tree, &node); - if (! gtk_tree_path_prev (above_path) && node) - { - gtk_tree_path_free (above_path); - above_path = _gtk_tree_view_find_path (tree_view, tree, node); - } modify_dy = TRUE; } + while (area_above > 0); /* if we walk backwards at all, then we need to reset our dy. */ - if (modify_dy && node != NULL) + if (modify_dy) { - gtk_tree_row_reference_free (tree_view->priv->top_row); - tree_view->priv->top_row = - gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, above_path); - tree_view->priv->top_row_dy = - area_above; + if (node != NULL) + { + tree_view->priv->dy = _gtk_rbtree_node_find_offset (tree, node) - area_above; + } + else + { + tree_view->priv->dy = 0; + } + gtk_adjustment_set_value (tree_view->priv->vadjustment, tree_view->priv->dy); need_redraw = TRUE; } - else - { - /* hrm. */ - } if (tree_view->priv->scroll_to_path) { @@ -4544,8 +4550,22 @@ get_logical_dest_row (GtkTreeView *tree_view) } else { + GtkTreeIter iter; + GtkTreeModel *model = gtk_tree_view_get_model (tree_view); + g_assert (pos == GTK_TREE_VIEW_DROP_AFTER); - gtk_tree_path_next (path); + + gtk_tree_model_get_iter (model, &iter, path); + + if (!gtk_tree_model_iter_next (model, &iter)) + g_object_set_data (G_OBJECT (model), "gtk-tree-model-drop-append", + GINT_TO_POINTER (1)); + else + { + g_object_set_data (G_OBJECT (model), "gtk-tree-model-drop-append", + NULL); + gtk_tree_path_next (path); + } } return path; @@ -6146,31 +6166,26 @@ gtk_tree_view_clamp_node_visible (GtkTreeView *tree_view, GtkRBTree *tree, GtkRBNode *node) { - gint offset; - gint real_height; + GdkRectangle cell_rect; + GdkRectangle vis_rect; + gint dest_y; /* We process updates because we want to clear old selected items when we scroll. * if this is removed, we get a "selection streak" at the bottom. */ if (GTK_WIDGET_REALIZED (tree_view)) gdk_window_process_updates (tree_view->priv->bin_window, TRUE); + cell_rect.y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, BACKGROUND_FIRST_PIXEL (tree_view, tree, node)); + cell_rect.height = BACKGROUND_HEIGHT (node); + gtk_tree_view_get_visible_rect (tree_view, &vis_rect); - real_height = MAX (GTK_RBNODE_GET_HEIGHT (node), tree_view->priv->expander_size); - - offset = _gtk_rbtree_node_find_offset (tree, node); + dest_y = vis_rect.y; - /* we reverse the order, b/c in the unusual case of the - * node's height being taller then the visible area, we'd rather - * have the node flush to the top - */ - if (offset + real_height > - tree_view->priv->vadjustment->value + tree_view->priv->vadjustment->page_size) - gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), - offset + real_height - - tree_view->priv->vadjustment->page_size); - if (offset < tree_view->priv->vadjustment->value) - gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), - offset); + if (cell_rect.y + cell_rect.height > vis_rect.y + vis_rect.height) + dest_y = cell_rect.y + cell_rect.height - vis_rect.height; + if (cell_rect.y < vis_rect.y) + dest_y = cell_rect.y; + gtk_tree_view_scroll_to_point (tree_view, -1, dest_y); } static void @@ -6874,7 +6889,6 @@ gtk_tree_view_move_cursor_page_up_down (GtkTreeView *tree_view, cursor_path = _gtk_tree_view_find_path (tree_view, cursor_tree, cursor_node); g_return_if_fail (cursor_path != NULL); gtk_tree_view_real_set_cursor (tree_view, cursor_path, TRUE); - gtk_tree_view_scroll_to_point (tree_view, -1, y); gtk_tree_view_clamp_node_visible (tree_view, cursor_tree, cursor_node); gtk_tree_path_free (cursor_path); } @@ -7629,7 +7643,7 @@ gtk_tree_view_set_headers_visible (GtkTreeView *tree_view, gdk_window_get_position (tree_view->priv->bin_window, &x, &y); if (headers_visible) { - gdk_window_move_resize (tree_view->priv->bin_window, x + TREE_VIEW_HEADER_HEIGHT (tree_view), y, tree_view->priv->width, GTK_WIDGET (tree_view)->allocation.height - + TREE_VIEW_HEADER_HEIGHT (tree_view)); + gdk_window_move_resize (tree_view->priv->bin_window, x, y + TREE_VIEW_HEADER_HEIGHT (tree_view), tree_view->priv->width, GTK_WIDGET (tree_view)->allocation.height - + TREE_VIEW_HEADER_HEIGHT (tree_view)); if (GTK_WIDGET_MAPPED (tree_view)) gtk_tree_view_map_buttons (tree_view); @@ -8197,14 +8211,16 @@ gtk_tree_view_set_column_drag_function (GtkTreeView *tree_view, /** * gtk_tree_view_scroll_to_point: * @tree_view: a #GtkTreeView - * @tree_x: X coordinate of new top-left pixel of visible area - * @tree_y: Y coordinate of new top-left pixel of visible area + * @tree_x: X coordinate of new top-left pixel of visible area, or -1 + * @tree_y: Y coordinate of new top-left pixel of visible area, or -1 * * Scrolls the tree view such that the top-left corner of the visible * area is @tree_x, @tree_y, where @tree_x and @tree_y are specified * in tree window coordinates. The @tree_view must be realized before * this function is called. If it isn't, you probably want to be * using gtk_tree_view_scroll_to_cell(). + * + * If either @tree_x or @tree_y are -1, then that direction isn't scrolled. **/ void gtk_tree_view_scroll_to_point (GtkTreeView *tree_view, @@ -8220,8 +8236,10 @@ gtk_tree_view_scroll_to_point (GtkTreeView *tree_view, hadj = tree_view->priv->hadjustment; vadj = tree_view->priv->vadjustment; - gtk_adjustment_set_value (hadj, CLAMP (tree_x, hadj->lower, hadj->upper - hadj->page_size)); - gtk_adjustment_set_value (vadj, CLAMP (tree_y, vadj->lower, vadj->upper - vadj->page_size)); + if (tree_x != -1) + gtk_adjustment_set_value (hadj, CLAMP (tree_x, hadj->lower, hadj->upper - hadj->page_size)); + if (tree_y != -1) + gtk_adjustment_set_value (vadj, CLAMP (tree_y, vadj->lower, vadj->upper - vadj->page_size)); } /** @@ -8245,6 +8263,10 @@ gtk_tree_view_scroll_to_point (GtkTreeView *tree_view, * tree does the minimum amount of work to scroll the cell onto the screen. * This means that the cell will be scrolled to the edge closest to it's current * position. If the cell is currently visible on the screen, nothing is done. + * + * This function only works if the model is set, and @path is a valid row on the + * model. If the model changes before the @tree_view is realized, the centered + * path will be modified to reflect this change. **/ void gtk_tree_view_scroll_to_cell (GtkTreeView *tree_view, @@ -8255,69 +8277,90 @@ gtk_tree_view_scroll_to_cell (GtkTreeView *tree_view, gfloat col_align) { g_return_if_fail (GTK_IS_TREE_VIEW (tree_view)); + g_return_if_fail (tree_view->priv->model != NULL); + g_return_if_fail (tree_view->priv->tree != NULL); g_return_if_fail (row_align >= 0.0 && row_align <= 1.0); g_return_if_fail (col_align >= 0.0 && col_align <= 1.0); g_return_if_fail (path != NULL || column != NULL); +#if 0 + g_print ("gtk_tree_view_scroll_to_cell:\npath: %s\ncolumn: %s\nuse_align: %d\nrow_align: %f\ncol_align: %f\n", + gtk_tree_path_to_string (path), column?"non-null":"null", use_align, row_align, col_align); +#endif row_align = CLAMP (row_align, 0.0, 1.0); col_align = CLAMP (col_align, 0.0, 1.0); - if (tree_view->priv->scroll_to_path) - gtk_tree_row_reference_free (tree_view->priv->scroll_to_path); - - tree_view->priv->scroll_to_path = NULL; - tree_view->priv->scroll_to_column = NULL; - if (path) - tree_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path); - if (column) - tree_view->priv->scroll_to_column = column; - tree_view->priv->scroll_to_use_align = use_align; - tree_view->priv->scroll_to_row_align = row_align; - tree_view->priv->scroll_to_col_align = col_align; + /* Note: Despite the benefits that come from having one code path for the + * scrolling code, we short-circuit validate_visible_area's immplementation as + * it is much slower than just going to the point. + */ + if (! GTK_WIDGET_REALIZED (tree_view) || + GTK_RBNODE_FLAG_SET (tree_view->priv->tree->root, GTK_RBNODE_DESCENDANTS_INVALID)) + { + if (tree_view->priv->scroll_to_path) + gtk_tree_row_reference_free (tree_view->priv->scroll_to_path); - install_presize_handler (tree_view); -} -#if 0 - gtk_tree_view_get_cell_area (tree_view, path, column, &cell_rect); - gtk_tree_view_get_visible_rect (tree_view, &vis_rect); + tree_view->priv->scroll_to_path = NULL; + tree_view->priv->scroll_to_column = NULL; - dest_x = vis_rect.x; - dest_y = vis_rect.y; + if (path) + tree_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path); + if (column) + tree_view->priv->scroll_to_column = column; + tree_view->priv->scroll_to_use_align = use_align; + tree_view->priv->scroll_to_row_align = row_align; + tree_view->priv->scroll_to_col_align = col_align; - if (column) - { - if (use_align) - { - dest_x = cell_rect.x + cell_rect.width * row_align - vis_rect.width * row_align; - } - else - { - if (cell_rect.x < vis_rect.x) - dest_x = cell_rect.x - vis_rect.width * within_margin; - else if (cell_rect.x + cell_rect.width > vis_rect.x + vis_rect.width) - dest_x = cell_rect.x + cell_rect.width - vis_rect.width * (1 - within_margin); - } + install_presize_handler (tree_view); } - - if (path) + else { - if (use_align) + GdkRectangle cell_rect; + GdkRectangle vis_rect; + gint dest_x, dest_y; + + gtk_tree_view_get_cell_area (tree_view, path, column, &cell_rect); + gtk_tree_view_widget_to_tree_coords (tree_view, cell_rect.x, cell_rect.y, &(cell_rect.x), &(cell_rect.y)); + gtk_tree_view_get_visible_rect (tree_view, &vis_rect); + + dest_x = vis_rect.x; + dest_y = vis_rect.y; + + if (column) { - dest_y = cell_rect.y + cell_rect.height * col_align - vis_rect.height * col_align; + if (use_align) + { + dest_x = cell_rect.x - ((vis_rect.width - cell_rect.width) * col_align); + } + else + { + if (cell_rect.x < vis_rect.x) + dest_x = cell_rect.x; + if (cell_rect.x + cell_rect.width > vis_rect.x + vis_rect.width) + dest_x = cell_rect.x + cell_rect.width - vis_rect.width; + } } - else + + if (path) { - if (cell_rect.y < vis_rect.y) - dest_y = cell_rect.y - vis_rect.height * within_margin; - else if (cell_rect.y + cell_rect.height > vis_rect.y + vis_rect.height) - dest_y = cell_rect.y + cell_rect.height - vis_rect.height * (1 - within_margin); + if (use_align) + { + dest_y = cell_rect.y - ((vis_rect.height - cell_rect.height) * row_align); + dest_y = MAX (dest_y, 0); + } + else + { + if (cell_rect.y < vis_rect.y) + dest_y = cell_rect.y; + if (cell_rect.y + cell_rect.height > vis_rect.y + vis_rect.height) + dest_y = cell_rect.y + cell_rect.height - vis_rect.height; + } } - } - - gtk_tree_view_scroll_to_point (tree_view, dest_x, dest_y); -#endif + gtk_tree_view_scroll_to_point (tree_view, dest_x, dest_y); + } +} /** * gtk_tree_view_row_activated: @@ -9377,7 +9420,7 @@ gtk_tree_view_widget_to_tree_coords (GtkTreeView *tree_view, if (tx) *tx = wx + tree_view->priv->hadjustment->value; if (ty) - *ty = wy + tree_view->priv->dy - TREE_VIEW_HEADER_HEIGHT (tree_view); + *ty = wy + tree_view->priv->dy; } /** @@ -9404,7 +9447,7 @@ gtk_tree_view_tree_to_widget_coords (GtkTreeView *tree_view, if (wx) *wx = tx - tree_view->priv->hadjustment->value; if (wy) - *wy = ty - tree_view->priv->dy + TREE_VIEW_HEADER_HEIGHT (tree_view); + *wy = ty - tree_view->priv->dy; } static void @@ -9656,7 +9699,7 @@ gtk_tree_view_get_dest_row_at_pos (GtkTreeView *tree_view, { *pos = GTK_TREE_VIEW_DROP_INTO_OR_BEFORE; } - else if (offset_into_row < third * 2) + else if (offset_into_row < third * 2.0) { *pos = GTK_TREE_VIEW_DROP_INTO_OR_AFTER; } @@ -10397,6 +10440,9 @@ gtk_tree_view_start_editing (GtkTreeView *tree_view, path_string = gtk_tree_path_to_string (cursor_path); gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path); + + validate_row (tree_view, cursor_tree, cursor_node, &iter, cursor_path); + gtk_tree_view_column_cell_set_cell_data (tree_view->priv->focus_column, tree_view->priv->model, &iter, diff --git a/tests/testtreeflow.c b/tests/testtreeflow.c index fae2579ac..306fd5b91 100644 --- a/tests/testtreeflow.c +++ b/tests/testtreeflow.c @@ -128,6 +128,7 @@ main (int argc, char *argv[]) tree_view = gtk_tree_view_new_with_model (model); gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (tree_view), path, NULL, TRUE, 0.5, 0.0); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)); + gtk_tree_selection_select_path (selection, path); gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree_view), TRUE); gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), FALSE); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),