2 * Copyright (C) 2000 Red Hat, Inc., Jonathan Blandford <jrb@redhat.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 #include "gtktreeselection.h"
21 #include "gtktreeprivate.h"
22 #include "gtkrbtree.h"
23 #include "gtksignal.h"
25 static void gtk_tree_selection_init (GtkTreeSelection *selection);
26 static void gtk_tree_selection_class_init (GtkTreeSelectionClass *class);
28 static void gtk_tree_selection_finalize (GObject *object);
29 static gint gtk_tree_selection_real_select_all (GtkTreeSelection *selection);
30 static gint gtk_tree_selection_real_unselect_all (GtkTreeSelection *selection);
31 static gint gtk_tree_selection_real_select_node (GtkTreeSelection *selection,
42 static GObjectClass *parent_class = NULL;
43 static guint tree_selection_signals [LAST_SIGNAL] = { 0 };
46 gtk_tree_selection_get_type (void)
48 static GtkType selection_type = 0;
52 static const GTypeInfo selection_info =
54 sizeof (GtkTreeSelectionClass),
56 NULL, /* base_finalize */
57 (GClassInitFunc) gtk_tree_selection_class_init,
58 NULL, /* class_finalize */
59 NULL, /* class_data */
60 sizeof (GtkTreeSelection),
62 (GInstanceInitFunc) gtk_tree_selection_init
65 selection_type = g_type_register_static (G_TYPE_OBJECT, "GtkTreeSelection", &selection_info, 0);
68 return selection_type;
72 gtk_tree_selection_class_init (GtkTreeSelectionClass *class)
74 GObjectClass *object_class;
76 object_class = (GObjectClass*) class;
77 parent_class = g_type_class_peek_parent (class);
79 object_class->finalize = gtk_tree_selection_finalize;
80 class->changed = NULL;
82 tree_selection_signals[CHANGED] =
83 gtk_signal_new ("changed",
85 GTK_CLASS_TYPE (object_class),
86 GTK_SIGNAL_OFFSET (GtkTreeSelectionClass, changed),
87 gtk_marshal_VOID__VOID,
92 gtk_tree_selection_init (GtkTreeSelection *selection)
94 selection->type = GTK_SELECTION_SINGLE;
98 gtk_tree_selection_finalize (GObject *object)
100 if (GTK_TREE_SELECTION (object)->destroy)
101 (* GTK_TREE_SELECTION (object)->destroy) (GTK_TREE_SELECTION (object)->user_data);
103 /* chain parent_class' handler */
104 G_OBJECT_CLASS (parent_class)->finalize (object);
108 * _gtk_tree_selection_new:
110 * Creates a new #GtkTreeSelection object. This function should not be invoked,
111 * as each #GtkTreeView will create it's own #GtkTreeSelection.
113 * Return value: A newly created #GtkTreeSelection object.
116 _gtk_tree_selection_new (void)
118 GtkTreeSelection *selection;
120 selection = GTK_TREE_SELECTION (g_object_new (GTK_TYPE_TREE_SELECTION, NULL));
126 * _gtk_tree_selection_new_with_tree_view:
127 * @tree_view: The #GtkTreeView.
129 * Creates a new #GtkTreeSelection object. This function should not be invoked,
130 * as each #GtkTreeView will create it's own #GtkTreeSelection.
132 * Return value: A newly created #GtkTreeSelection object.
135 _gtk_tree_selection_new_with_tree_view (GtkTreeView *tree_view)
137 GtkTreeSelection *selection;
139 g_return_val_if_fail (GTK_IS_TREE_VIEW (tree_view), NULL);
141 selection = _gtk_tree_selection_new ();
142 _gtk_tree_selection_set_tree_view (selection, tree_view);
148 * _gtk_tree_selection_set_tree_view:
149 * @selection: A #GtkTreeSelection.
150 * @tree_view: The #GtkTreeView.
152 * Sets the #GtkTreeView of @selection. This function should not be invoked, as
153 * it is used internally by #GtkTreeView.
156 _gtk_tree_selection_set_tree_view (GtkTreeSelection *selection,
157 GtkTreeView *tree_view)
159 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
160 if (tree_view != NULL)
161 g_return_if_fail (GTK_IS_TREE_VIEW (tree_view));
163 selection->tree_view = tree_view;
167 * gtk_tree_selection_set_mode:
168 * @selection: A #GtkTreeSelection.
169 * @type: The selection mode
171 * Sets the selection mode of the @selection. If the previous type was
172 * #GTK_SELECTION_MULTIPLE and, then the anchor is kept selected, if it was
173 * previously selected.
176 gtk_tree_selection_set_mode (GtkTreeSelection *selection,
177 GtkSelectionMode type)
179 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
181 if (selection->type == type)
184 if (type == GTK_SELECTION_SINGLE ||
185 type == GTK_SELECTION_BROWSE)
187 GtkRBTree *tree = NULL;
188 GtkRBNode *node = NULL;
189 gint selected = FALSE;
191 if (selection->tree_view->priv->anchor)
193 GtkTreePath *anchor_path;
195 anchor_path = gtk_tree_row_reference_get_path (selection->tree_view->priv->anchor);
199 _gtk_tree_view_find_node (selection->tree_view,
204 if (node && GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
207 gtk_tree_path_free (anchor_path);
210 /* FIXME: if user_func is set, then it needs to unconditionally unselect
213 gtk_tree_selection_unselect_all (selection);
215 /* FIXME are we properly emitting the selection_changed signal here? */
216 if (node && selected)
217 GTK_RBNODE_SET_FLAG (node, GTK_RBNODE_IS_SELECTED);
219 selection->type = type;
223 * gtk_tree_selection_get_mode:
224 * @selection: a #GtkTreeSelection
226 * Gets the selection mode for @selection. See
227 * gtk_tree_selection_set_mode().
229 * Return value: the current selection mode
232 gtk_tree_selection_get_mode (GtkTreeSelection *selection)
234 g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), GTK_SELECTION_SINGLE);
236 return selection->type;
240 * gtk_tree_selection_set_select_function:
241 * @selection: A #GtkTreeSelection.
242 * @func: The selection function.
243 * @data: The selection function's data.
244 * @destroy: The destroy function for user data. May be NULL.
246 * Sets the selection function. If set, this function is called before any node
247 * is selected or unselected, giving some control over which nodes are selected.
250 gtk_tree_selection_set_select_function (GtkTreeSelection *selection,
251 GtkTreeSelectionFunc func,
253 GtkDestroyNotify destroy)
255 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
256 g_return_if_fail (func != NULL);
258 selection->user_func = func;
259 selection->user_data = data;
260 selection->destroy = destroy;
264 * gtk_tree_selection_get_user_data:
265 * @selection: A #GtkTreeSelection.
267 * Returns the user data for the selection function.
269 * Return value: The user data.
272 gtk_tree_selection_get_user_data (GtkTreeSelection *selection)
274 g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), NULL);
276 return selection->user_data;
280 * gtk_tree_selection_get_tree_view:
281 * @selection: A #GtkTreeSelection
283 * Returns the tree view associated with @selection.
285 * Return value: A #GtkTreeView
288 gtk_tree_selection_get_tree_view (GtkTreeSelection *selection)
290 g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), NULL);
292 return selection->tree_view;
296 * gtk_tree_selection_get_selected:
297 * @selection: A #GtkTreeSelection.
298 * @model: A pointer set to the #GtkTreeModel, or NULL.
299 * @iter: The #GtkTreeIter, or NULL.
301 * Sets @iter to the currently selected node if @selection is set to
302 * #GTK_SELECTION_SINGLE or #GTK_SELECTION_BROWSE. @iter may be NULL if you
303 * just want to test if @selection has any selected nodes. @model is filled
304 * with the current model as a convenience. This function will not work if you
305 * use @selection is #GTK_SELECTION_MULTIPLE.
307 * Return value: TRUE, if there is a selected node.
310 gtk_tree_selection_get_selected (GtkTreeSelection *selection,
311 GtkTreeModel **model,
316 GtkTreePath *anchor_path;
319 g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), FALSE);
320 g_return_val_if_fail (selection->type != GTK_SELECTION_MULTIPLE, FALSE);
321 g_return_val_if_fail (selection->tree_view != NULL, FALSE);
322 g_return_val_if_fail (selection->tree_view->priv->model != NULL, FALSE);
325 *model = selection->tree_view->priv->model;
327 if (selection->tree_view->priv->anchor == NULL)
330 anchor_path = gtk_tree_row_reference_get_path (selection->tree_view->priv->anchor);
332 if (anchor_path == NULL)
337 gtk_tree_path_free (anchor_path);
343 if (!_gtk_tree_view_find_node (selection->tree_view,
347 ! GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
349 /* We don't want to return the anchor if it isn't actually selected.
355 retval = gtk_tree_model_get_iter (selection->tree_view->priv->model,
360 gtk_tree_path_free (anchor_path);
366 * gtk_tree_selection_selected_foreach:
367 * @selection: A #GtkTreeSelection.
368 * @func: The function to call for each selected node.
369 * @data: user data to pass to the function.
371 * Calls a function for each selected node.
374 gtk_tree_selection_selected_foreach (GtkTreeSelection *selection,
375 GtkTreeSelectionForeachFunc func,
383 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
384 g_return_if_fail (selection->tree_view != NULL);
385 g_return_if_fail (selection->tree_view->priv->model != NULL);
388 selection->tree_view->priv->tree == NULL ||
389 selection->tree_view->priv->tree->root == NULL)
392 if (selection->type == GTK_SELECTION_SINGLE ||
393 selection->type == GTK_SELECTION_BROWSE)
395 if (gtk_tree_row_reference_valid (selection->tree_view->priv->anchor))
397 path = gtk_tree_row_reference_get_path (selection->tree_view->priv->anchor);
398 gtk_tree_model_get_iter (selection->tree_view->priv->model, &iter, path);
399 (* func) (selection->tree_view->priv->model, path, &iter, data);
400 gtk_tree_path_free (path);
405 tree = selection->tree_view->priv->tree;
406 node = selection->tree_view->priv->tree->root;
408 while (node->left != tree->nil)
411 /* find the node internally */
412 path = gtk_tree_path_new_root ();
413 gtk_tree_model_get_iter (selection->tree_view->priv->model,
418 if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
419 (* func) (selection->tree_view->priv->model, path, &iter, data);
425 tree = node->children;
427 while (node->left != tree->nil)
430 has_child = gtk_tree_model_iter_children (selection->tree_view->priv->model, &iter, &tmp);
431 gtk_tree_path_append_index (path, 0);
433 TREE_VIEW_INTERNAL_ASSERT_VOID (has_child);
437 gboolean done = FALSE;
440 node = _gtk_rbtree_next (tree, node);
445 has_next = gtk_tree_model_iter_next (selection->tree_view->priv->model, &iter);
447 gtk_tree_path_next (path);
450 TREE_VIEW_INTERNAL_ASSERT_VOID (has_next);
455 GtkTreeIter tmp_iter = iter;
457 node = tree->parent_node;
458 tree = tree->parent_tree;
461 gtk_tree_path_free (path);
462 /* we've run out of tree */
463 /* We're done with this function */
466 has_parent = gtk_tree_model_iter_parent (selection->tree_view->priv->model, &iter, &tmp_iter);
467 gtk_tree_path_up (path);
469 TREE_VIEW_INTERNAL_ASSERT_VOID (has_parent);
479 * gtk_tree_selection_select_path:
480 * @selection: A #GtkTreeSelection.
481 * @path: The #GtkTreePath to be selected.
483 * Select the row at @path.
486 gtk_tree_selection_select_path (GtkTreeSelection *selection,
491 GdkModifierType state = 0;
493 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
494 g_return_if_fail (selection->tree_view != NULL);
495 g_return_if_fail (path != NULL);
497 _gtk_tree_view_find_node (selection->tree_view,
502 if (node == NULL || GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
505 if (selection->type == GTK_SELECTION_MULTIPLE)
506 state = GDK_CONTROL_MASK;
508 _gtk_tree_selection_internal_select_node (selection,
516 * gtk_tree_selection_unselect_path:
517 * @selection: A #GtkTreeSelection.
518 * @path: The #GtkTreePath to be unselected.
520 * Unselects the row at @path.
523 gtk_tree_selection_unselect_path (GtkTreeSelection *selection,
529 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
530 g_return_if_fail (selection->tree_view != NULL);
531 g_return_if_fail (path != NULL);
533 _gtk_tree_view_find_node (selection->tree_view,
538 if (node == NULL || !GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
541 _gtk_tree_selection_internal_select_node (selection,
549 * gtk_tree_selection_select_iter:
550 * @selection: A #GtkTreeSelection.
551 * @iter: The #GtkTreeIter to be selected.
553 * Selects the specified iterator.
556 gtk_tree_selection_select_iter (GtkTreeSelection *selection,
561 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
562 g_return_if_fail (selection->tree_view != NULL);
563 g_return_if_fail (selection->tree_view->priv->model != NULL);
564 g_return_if_fail (iter != NULL);
566 path = gtk_tree_model_get_path (selection->tree_view->priv->model,
572 gtk_tree_selection_select_path (selection, path);
573 gtk_tree_path_free (path);
578 * gtk_tree_selection_unselect_iter:
579 * @selection: A #GtkTreeSelection.
580 * @iter: The #GtkTreeIter to be unselected.
582 * Unselects the specified iterator.
585 gtk_tree_selection_unselect_iter (GtkTreeSelection *selection,
590 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
591 g_return_if_fail (selection->tree_view != NULL);
592 g_return_if_fail (selection->tree_view->priv->model != NULL);
593 g_return_if_fail (iter != NULL);
595 path = gtk_tree_model_get_path (selection->tree_view->priv->model,
601 gtk_tree_selection_select_path (selection, path);
602 gtk_tree_path_free (path);
605 /* Wish I was in python, right now... */
607 GtkTreeSelection *selection;
612 select_all_helper (GtkRBTree *tree,
616 struct _TempTuple *tuple = data;
619 _gtk_rbtree_traverse (node->children,
620 node->children->root,
624 if (!GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
626 tuple->dirty = gtk_tree_selection_real_select_node (tuple->selection, tree, node, TRUE) || tuple->dirty;
631 /* We have a real_{un,}select_all function that doesn't emit the signal, so we
632 * can use it in other places without fear of the signal being emitted.
635 gtk_tree_selection_real_select_all (GtkTreeSelection *selection)
637 struct _TempTuple *tuple;
639 if (selection->tree_view->priv->tree == NULL)
642 /* Mark all nodes selected */
643 tuple = g_new (struct _TempTuple, 1);
644 tuple->selection = selection;
645 tuple->dirty = FALSE;
647 _gtk_rbtree_traverse (selection->tree_view->priv->tree,
648 selection->tree_view->priv->tree->root,
662 * gtk_tree_selection_select_all:
663 * @selection: A #GtkTreeSelection.
665 * Selects all the nodes. @selection is must be set to #GTK_SELECTION_MULTIPLE
669 gtk_tree_selection_select_all (GtkTreeSelection *selection)
671 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
672 g_return_if_fail (selection->tree_view != NULL);
673 if (selection->tree_view->priv->tree == NULL)
675 g_return_if_fail (selection->type == GTK_SELECTION_MULTIPLE);
677 if (gtk_tree_selection_real_select_all (selection))
678 g_signal_emit (G_OBJECT (selection), tree_selection_signals[CHANGED], 0);
682 unselect_all_helper (GtkRBTree *tree,
686 struct _TempTuple *tuple = data;
689 _gtk_rbtree_traverse (node->children,
690 node->children->root,
694 if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
696 tuple->dirty = gtk_tree_selection_real_select_node (tuple->selection, tree, node, FALSE) || tuple->dirty;
701 gtk_tree_selection_real_unselect_all (GtkTreeSelection *selection)
703 struct _TempTuple *tuple;
705 if (selection->type == GTK_SELECTION_SINGLE ||
706 selection->type == GTK_SELECTION_BROWSE)
708 GtkRBTree *tree = NULL;
709 GtkRBNode *node = NULL;
710 GtkTreePath *anchor_path;
712 if (selection->tree_view->priv->anchor == NULL)
715 anchor_path = gtk_tree_row_reference_get_path (selection->tree_view->priv->anchor);
717 if (anchor_path == NULL)
720 _gtk_tree_view_find_node (selection->tree_view,
725 gtk_tree_path_free (anchor_path);
730 if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
732 if (gtk_tree_selection_real_select_node (selection, tree, node, FALSE))
734 gtk_tree_row_reference_free (selection->tree_view->priv->anchor);
735 selection->tree_view->priv->anchor = NULL;
743 tuple = g_new (struct _TempTuple, 1);
744 tuple->selection = selection;
745 tuple->dirty = FALSE;
747 _gtk_rbtree_traverse (selection->tree_view->priv->tree,
748 selection->tree_view->priv->tree->root,
764 * gtk_tree_selection_unselect_all:
765 * @selection: A #GtkTreeSelection.
767 * Unselects all the nodes.
770 gtk_tree_selection_unselect_all (GtkTreeSelection *selection)
772 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
773 g_return_if_fail (selection->tree_view != NULL);
774 if (selection->tree_view->priv->tree == NULL)
777 if (selection->tree_view->priv->tree == NULL)
780 if (gtk_tree_selection_real_unselect_all (selection))
781 g_signal_emit (G_OBJECT (selection), tree_selection_signals[CHANGED], 0);
785 gtk_tree_selection_real_select_range (GtkTreeSelection *selection,
786 GtkTreePath *start_path,
787 GtkTreePath *end_path)
789 GtkRBNode *start_node, *end_node;
790 GtkRBTree *start_tree, *end_tree;
791 gboolean dirty = FALSE;
793 switch (gtk_tree_path_compare (start_path, end_path))
796 _gtk_tree_view_find_node (selection->tree_view,
800 _gtk_tree_view_find_node (selection->tree_view,
806 _gtk_tree_view_find_node (selection->tree_view,
810 end_tree = start_tree;
811 end_node = start_node;
814 _gtk_tree_view_find_node (selection->tree_view,
818 _gtk_tree_view_find_node (selection->tree_view,
825 g_return_val_if_fail (start_node != NULL, FALSE);
826 g_return_val_if_fail (end_node != NULL, FALSE);
830 dirty |= gtk_tree_selection_real_select_node (selection, start_tree, start_node, TRUE);
832 if (start_node == end_node)
835 if (start_node->children)
837 start_tree = start_node->children;
838 start_node = start_tree->root;
839 while (start_node->left != start_tree->nil)
840 start_node = start_node->left;
844 _gtk_rbtree_next_full (start_tree, start_node, &start_tree, &start_node);
845 if (start_tree == NULL)
847 /* we just ran out of tree. That means someone passed in bogus values.
859 * gtk_tree_selection_select_range:
860 * @selection: A #GtkTreeSelection.
861 * @start_path: The initial node of the range.
862 * @end_path: The final node of the range.
864 * Selects a range of nodes, determined by @start_path and @end_path inclusive.
867 gtk_tree_selection_select_range (GtkTreeSelection *selection,
868 GtkTreePath *start_path,
869 GtkTreePath *end_path)
871 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
872 g_return_if_fail (selection->tree_view != NULL);
874 if (gtk_tree_selection_real_select_range (selection, start_path, end_path))
875 g_signal_emit (G_OBJECT (selection), tree_selection_signals[CHANGED], 0);
878 /* Called internally by gtktreeview.c It handles actually selecting the tree.
881 _gtk_tree_selection_internal_select_node (GtkTreeSelection *selection,
885 GdkModifierType state)
889 GtkTreePath *anchor_path = NULL;
892 if (selection->tree_view->priv->anchor)
893 anchor_path = gtk_tree_row_reference_get_path (selection->tree_view->priv->anchor);
895 if (selection->type == GTK_SELECTION_SINGLE ||
896 selection->type == GTK_SELECTION_BROWSE)
898 /* Did we try to select the same node again? */
899 if (selection->type == GTK_SELECTION_SINGLE &&
900 anchor_path && gtk_tree_path_compare (path, anchor_path) == 0)
902 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
904 dirty = gtk_tree_selection_real_unselect_all (selection);
909 /* FIXME: We only want to select the new node if we can unselect the
910 * old one, and we can select the new one. We are currently
911 * unselecting the old one first, then trying the new one. */
914 dirty = gtk_tree_selection_real_unselect_all (selection);
917 if (selection->tree_view->priv->anchor)
918 gtk_tree_row_reference_free (selection->tree_view->priv->anchor);
919 if (gtk_tree_selection_real_select_node (selection, tree, node, TRUE))
921 selection->tree_view->priv->anchor =
922 gtk_tree_row_reference_new_proxy (G_OBJECT (selection->tree_view), selection->tree_view->priv->model, path);
928 if (gtk_tree_selection_real_select_node (selection, tree, node, TRUE))
931 selection->tree_view->priv->anchor =
932 gtk_tree_row_reference_new_proxy (G_OBJECT (selection->tree_view), selection->tree_view->priv->model, path);
937 else if (selection->type == GTK_SELECTION_MULTIPLE)
939 if (((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK) && (anchor_path == NULL))
941 if (selection->tree_view->priv->anchor)
942 gtk_tree_row_reference_free (selection->tree_view->priv->anchor);
944 selection->tree_view->priv->anchor =
945 gtk_tree_row_reference_new_proxy (G_OBJECT (selection->tree_view), selection->tree_view->priv->model, path);
946 dirty = gtk_tree_selection_real_select_node (selection, tree, node, TRUE);
948 else if ((state & (GDK_CONTROL_MASK|GDK_SHIFT_MASK)) == (GDK_SHIFT_MASK|GDK_CONTROL_MASK))
950 gtk_tree_selection_select_range (selection,
954 else if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
957 if (selection->tree_view->priv->anchor)
958 gtk_tree_row_reference_free (selection->tree_view->priv->anchor);
960 selection->tree_view->priv->anchor =
961 gtk_tree_row_reference_new_proxy (G_OBJECT (selection->tree_view), selection->tree_view->priv->model, path);
963 if ((flags & GTK_RBNODE_IS_SELECTED) == GTK_RBNODE_IS_SELECTED)
964 dirty |= gtk_tree_selection_real_select_node (selection, tree, node, FALSE);
966 dirty |= gtk_tree_selection_real_select_node (selection, tree, node, TRUE);
968 else if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
970 dirty = gtk_tree_selection_real_unselect_all (selection);
971 dirty |= gtk_tree_selection_real_select_range (selection,
977 dirty = gtk_tree_selection_real_unselect_all (selection);
979 if (selection->tree_view->priv->anchor)
980 gtk_tree_row_reference_free (selection->tree_view->priv->anchor);
982 selection->tree_view->priv->anchor =
983 gtk_tree_row_reference_new_proxy (G_OBJECT (selection->tree_view), selection->tree_view->priv->model, path);
985 dirty |= gtk_tree_selection_real_select_node (selection, tree, node, TRUE);
990 gtk_tree_path_free (anchor_path);
993 g_signal_emit (G_OBJECT (selection), tree_selection_signals[CHANGED], 0);
996 /* NOTE: Any {un,}selection ever done _MUST_ be done through this function!
1000 gtk_tree_selection_real_select_node (GtkTreeSelection *selection,
1005 gboolean selected = FALSE;
1006 GtkTreePath *path = NULL;
1008 if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED) != select)
1010 path = _gtk_tree_view_find_path (selection->tree_view, tree, node);
1011 if (selection->user_func)
1013 if ((*selection->user_func) (selection, selection->tree_view->priv->model, path, selection->user_data))
1018 gtk_tree_path_free (path);
1021 if (selected == TRUE)
1023 node->flags ^= GTK_RBNODE_IS_SELECTED;
1025 /* FIXME: just draw the one node*/
1026 gtk_widget_queue_draw (GTK_WIDGET (selection->tree_view));