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_TREE_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);
105 * _gtk_tree_selection_new:
107 * Creates a new #GtkTreeSelection object. This function should not be invoked,
108 * as each #GtkTreeView will create it's own #GtkTreeSelection.
110 * Return value: A newly created #GtkTreeSelection object.
113 _gtk_tree_selection_new (void)
115 GtkTreeSelection *selection;
117 selection = GTK_TREE_SELECTION (g_object_new (GTK_TYPE_TREE_SELECTION, NULL));
123 * _gtk_tree_selection_new_with_tree_view:
124 * @tree_view: The #GtkTreeView.
126 * Creates a new #GtkTreeSelection object. This function should not be invoked,
127 * as each #GtkTreeView will create it's own #GtkTreeSelection.
129 * Return value: A newly created #GtkTreeSelection object.
132 _gtk_tree_selection_new_with_tree_view (GtkTreeView *tree_view)
134 GtkTreeSelection *selection;
136 g_return_val_if_fail (tree_view != NULL, NULL);
137 g_return_val_if_fail (GTK_IS_TREE_VIEW (tree_view), NULL);
139 selection = _gtk_tree_selection_new ();
140 _gtk_tree_selection_set_tree_view (selection, tree_view);
146 * _gtk_tree_selection_set_tree_view:
147 * @selection: A #GtkTreeSelection.
148 * @tree_view: The #GtkTreeView.
150 * Sets the #GtkTreeView of @selection. This function should not be invoked, as
151 * it is used internally by #GtkTreeView.
154 _gtk_tree_selection_set_tree_view (GtkTreeSelection *selection,
155 GtkTreeView *tree_view)
157 g_return_if_fail (selection != NULL);
158 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
159 if (tree_view != NULL)
160 g_return_if_fail (GTK_IS_TREE_VIEW (tree_view));
162 selection->tree_view = tree_view;
166 * gtk_tree_selection_set_mode:
167 * @selection: A #GtkTreeSelection.
168 * @type: The selection mode
170 * Sets the selection mode of the @selection. If the previous type was
171 * #GTK_TREE_SELECTION_MULTI and @type is #GTK_TREE_SELECTION_SINGLE, then
172 * the anchor is kept selected, if it was previously selected.
175 gtk_tree_selection_set_mode (GtkTreeSelection *selection,
176 GtkTreeSelectionMode type)
178 g_return_if_fail (selection != NULL);
179 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
181 if (selection->type == type)
184 if (type == GTK_TREE_SELECTION_SINGLE)
186 GtkRBTree *tree = NULL;
187 GtkRBNode *node = NULL;
188 gint selected = FALSE;
190 if (selection->tree_view->priv->anchor)
192 GtkTreePath *anchor_path;
194 anchor_path = gtk_tree_row_reference_get_path (selection->tree_view->priv->anchor);
198 _gtk_tree_view_find_node (selection->tree_view,
203 if (node && GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
206 gtk_tree_path_free (anchor_path);
209 /* FIXME: if user_func is set, then it needs to unconditionally unselect
212 gtk_tree_selection_unselect_all (selection);
214 /* FIXME are we properly emitting the selection_changed signal here? */
215 if (node && selected)
216 GTK_RBNODE_SET_FLAG (node, GTK_RBNODE_IS_SELECTED);
218 selection->type = type;
222 * gtk_tree_selection_get_mode:
223 * @selection: a #GtkTreeSelection
225 * Gets the selection mode for @selection. See
226 * gtk_tree_selection_set_mode().
228 * Return value: the current selection mode
231 gtk_tree_selection_get_mode (GtkTreeSelection *selection)
233 g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), GTK_TREE_SELECTION_SINGLE);
235 return selection->type;
239 * gtk_tree_selection_set_select_function:
240 * @selection: A #GtkTreeSelection.
241 * @func: The selection function.
242 * @data: The selection function's data.
243 * @destroy: The destroy function for user data. May be NULL.
245 * Sets the selection function. If set, this function is called before any node
246 * is selected or unselected, giving some control over which nodes are selected.
249 gtk_tree_selection_set_select_function (GtkTreeSelection *selection,
250 GtkTreeSelectionFunc func,
252 GtkDestroyNotify destroy)
254 g_return_if_fail (selection != NULL);
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 (selection != NULL, NULL);
275 g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), NULL);
277 return selection->user_data;
281 gtk_tree_selection_get_tree_view (GtkTreeSelection *selection)
283 g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), NULL);
285 return selection->tree_view;
289 * gtk_tree_selection_get_selected:
290 * @selection: A #GtkTreeSelection.
291 * @model: A pointer set to the #GtkTreeModel, or NULL.
292 * @iter: The #GtkTreeIter, or NULL.
294 * Sets @iter to the currently selected node if @selection is set to
295 * #GTK_TREE_SELECTION_SINGLE. @iter may be NULL if you just want to test if
296 * @selection has any selected nodes. @model is filled with the current model
297 * as a convenience. This function will not work if you use @selection is
298 * #GTK_TREE_SELECTION_MULTI.
300 * Return value: TRUE, if there is a selected node.
303 gtk_tree_selection_get_selected (GtkTreeSelection *selection,
304 GtkTreeModel **model,
309 GtkTreePath *anchor_path;
312 g_return_val_if_fail (selection != NULL, FALSE);
313 g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), FALSE);
314 g_return_val_if_fail (selection->type == GTK_TREE_SELECTION_SINGLE, FALSE);
315 g_return_val_if_fail (selection->tree_view != NULL, FALSE);
316 g_return_val_if_fail (selection->tree_view->priv->model != NULL, FALSE);
319 *model = selection->tree_view->priv->model;
321 if (selection->tree_view->priv->anchor == NULL)
324 anchor_path = gtk_tree_row_reference_get_path (selection->tree_view->priv->anchor);
326 if (anchor_path == NULL)
331 gtk_tree_path_free (anchor_path);
337 if (!_gtk_tree_view_find_node (selection->tree_view,
341 ! GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
343 /* We don't want to return the anchor if it isn't actually selected.
349 retval = gtk_tree_model_get_iter (selection->tree_view->priv->model,
354 gtk_tree_path_free (anchor_path);
360 * gtk_tree_selection_selected_foreach:
361 * @selection: A #GtkTreeSelection.
362 * @func: The function to call for each selected node.
363 * @data: user data to pass to the function.
365 * Calls a function for each selected node.
368 gtk_tree_selection_selected_foreach (GtkTreeSelection *selection,
369 GtkTreeSelectionForeachFunc func,
377 g_return_if_fail (selection != NULL);
378 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
379 g_return_if_fail (selection->tree_view != NULL);
380 g_return_if_fail (selection->tree_view->priv->model != NULL);
383 selection->tree_view->priv->tree == NULL ||
384 selection->tree_view->priv->tree->root == NULL)
387 if (selection->type == GTK_TREE_SELECTION_SINGLE)
389 if (gtk_tree_selection_get_selected (selection, NULL, &iter))
390 (* func) (selection->tree_view->priv->model, &iter, data);
394 tree = selection->tree_view->priv->tree;
395 node = selection->tree_view->priv->tree->root;
397 while (node->left != tree->nil)
400 /* find the node internally */
401 path = gtk_tree_path_new_root ();
402 gtk_tree_model_get_iter (selection->tree_view->priv->model,
404 gtk_tree_path_free (path);
408 if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
409 (* func) (selection->tree_view->priv->model, &iter, data);
415 tree = node->children;
417 while (node->left != tree->nil)
420 has_child = gtk_tree_model_iter_children (selection->tree_view->priv->model, &iter, &tmp);
423 TREE_VIEW_INTERNAL_ASSERT_VOID (has_child);
427 gboolean done = FALSE;
430 node = _gtk_rbtree_next (tree, node);
435 has_next = gtk_tree_model_iter_next (selection->tree_view->priv->model, &iter);
439 TREE_VIEW_INTERNAL_ASSERT_VOID (has_next);
444 GtkTreeIter tmp_iter = iter;
446 node = tree->parent_node;
447 tree = tree->parent_tree;
449 /* we've run out of tree */
450 /* We're done with this function */
452 has_parent = gtk_tree_model_iter_parent (selection->tree_view->priv->model, &iter, &tmp_iter);
455 TREE_VIEW_INTERNAL_ASSERT_VOID (has_parent);
465 * gtk_tree_selection_select_path:
466 * @selection: A #GtkTreeSelection.
467 * @path: The #GtkTreePath to be selected.
469 * Select the row at @path.
472 gtk_tree_selection_select_path (GtkTreeSelection *selection,
477 GdkModifierType state = 0;
479 g_return_if_fail (selection != NULL);
480 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
481 g_return_if_fail (selection->tree_view != NULL);
482 g_return_if_fail (path != NULL);
484 _gtk_tree_view_find_node (selection->tree_view,
489 if (node == NULL || GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
492 if (selection->type == GTK_TREE_SELECTION_MULTI)
493 state = GDK_CONTROL_MASK;
495 _gtk_tree_selection_internal_select_node (selection,
503 * gtk_tree_selection_unselect_path:
504 * @selection: A #GtkTreeSelection.
505 * @path: The #GtkTreePath to be unselected.
507 * Unselects the row at @path.
510 gtk_tree_selection_unselect_path (GtkTreeSelection *selection,
516 g_return_if_fail (selection != NULL);
517 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
518 g_return_if_fail (selection->tree_view != NULL);
519 g_return_if_fail (path != NULL);
521 _gtk_tree_view_find_node (selection->tree_view,
526 if (node == NULL || !GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
529 _gtk_tree_selection_internal_select_node (selection,
537 * gtk_tree_selection_select_iter:
538 * @selection: A #GtkTreeSelection.
539 * @iter: The #GtkTreeIter to be selected.
541 * Selects the specified iterator.
544 gtk_tree_selection_select_iter (GtkTreeSelection *selection,
549 g_return_if_fail (selection != NULL);
550 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
551 g_return_if_fail (selection->tree_view != NULL);
552 g_return_if_fail (selection->tree_view->priv->model != NULL);
553 g_return_if_fail (iter != NULL);
555 path = gtk_tree_model_get_path (selection->tree_view->priv->model,
561 gtk_tree_selection_select_path (selection, path);
562 gtk_tree_path_free (path);
567 * gtk_tree_selection_unselect_iter:
568 * @selection: A #GtkTreeSelection.
569 * @iter: The #GtkTreeIter to be unselected.
571 * Unselects the specified iterator.
574 gtk_tree_selection_unselect_iter (GtkTreeSelection *selection,
579 g_return_if_fail (selection != NULL);
580 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
581 g_return_if_fail (selection->tree_view != NULL);
582 g_return_if_fail (selection->tree_view->priv->model != NULL);
583 g_return_if_fail (iter != NULL);
585 path = gtk_tree_model_get_path (selection->tree_view->priv->model,
591 gtk_tree_selection_select_path (selection, path);
592 gtk_tree_path_free (path);
595 /* Wish I was in python, right now... */
597 GtkTreeSelection *selection;
602 select_all_helper (GtkRBTree *tree,
606 struct _TempTuple *tuple = data;
609 _gtk_rbtree_traverse (node->children,
610 node->children->root,
614 if (!GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
616 tuple->dirty = gtk_tree_selection_real_select_node (tuple->selection, tree, node, TRUE) || tuple->dirty;
621 /* We have a real_{un,}select_all function that doesn't emit the signal, so we
622 * can use it in other places without fear of the signal being emitted.
625 gtk_tree_selection_real_select_all (GtkTreeSelection *selection)
627 struct _TempTuple *tuple;
629 if (selection->tree_view->priv->tree == NULL)
632 /* Mark all nodes selected */
633 tuple = g_new (struct _TempTuple, 1);
634 tuple->selection = selection;
635 tuple->dirty = FALSE;
637 _gtk_rbtree_traverse (selection->tree_view->priv->tree,
638 selection->tree_view->priv->tree->root,
652 * gtk_tree_selection_select_all:
653 * @selection: A #GtkTreeSelection.
655 * Selects all the nodes. @selection is must be set to
656 * #GTK_TREE_SELECTION_MULTI mode.
659 gtk_tree_selection_select_all (GtkTreeSelection *selection)
661 g_return_if_fail (selection != NULL);
662 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
663 g_return_if_fail (selection->tree_view != NULL);
664 g_return_if_fail (selection->tree_view->priv->tree != NULL);
665 g_return_if_fail (selection->type != GTK_TREE_SELECTION_MULTI);
667 if (gtk_tree_selection_real_select_all (selection))
668 g_signal_emit (G_OBJECT (selection), tree_selection_signals[CHANGED], 0);
672 unselect_all_helper (GtkRBTree *tree,
676 struct _TempTuple *tuple = data;
679 _gtk_rbtree_traverse (node->children,
680 node->children->root,
684 if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
686 tuple->dirty = gtk_tree_selection_real_select_node (tuple->selection, tree, node, FALSE) || tuple->dirty;
691 gtk_tree_selection_real_unselect_all (GtkTreeSelection *selection)
693 struct _TempTuple *tuple;
695 if (selection->type == GTK_TREE_SELECTION_SINGLE)
697 GtkRBTree *tree = NULL;
698 GtkRBNode *node = NULL;
699 GtkTreePath *anchor_path;
701 if (selection->tree_view->priv->anchor == NULL)
704 anchor_path = gtk_tree_row_reference_get_path (selection->tree_view->priv->anchor);
706 if (anchor_path == NULL)
709 _gtk_tree_view_find_node (selection->tree_view,
714 gtk_tree_path_free (anchor_path);
719 if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
721 if (gtk_tree_selection_real_select_node (selection, tree, node, FALSE))
723 gtk_tree_row_reference_free (selection->tree_view->priv->anchor);
724 selection->tree_view->priv->anchor = NULL;
732 tuple = g_new (struct _TempTuple, 1);
733 tuple->selection = selection;
734 tuple->dirty = FALSE;
736 _gtk_rbtree_traverse (selection->tree_view->priv->tree,
737 selection->tree_view->priv->tree->root,
753 * gtk_tree_selection_unselect_all:
754 * @selection: A #GtkTreeSelection.
756 * Unselects all the nodes.
759 gtk_tree_selection_unselect_all (GtkTreeSelection *selection)
761 g_return_if_fail (selection != NULL);
762 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
763 g_return_if_fail (selection->tree_view != NULL);
764 g_return_if_fail (selection->tree_view->priv->tree != NULL);
765 if (selection->tree_view->priv->tree == NULL)
768 if (gtk_tree_selection_real_unselect_all (selection))
769 g_signal_emit (G_OBJECT (selection), tree_selection_signals[CHANGED], 0);
773 gtk_tree_selection_real_select_range (GtkTreeSelection *selection,
774 GtkTreePath *start_path,
775 GtkTreePath *end_path)
777 GtkRBNode *start_node, *end_node;
778 GtkRBTree *start_tree, *end_tree;
779 gboolean dirty = FALSE;
781 switch (gtk_tree_path_compare (start_path, end_path))
784 _gtk_tree_view_find_node (selection->tree_view,
788 _gtk_tree_view_find_node (selection->tree_view,
794 _gtk_tree_view_find_node (selection->tree_view,
798 end_tree = start_tree;
799 end_node = start_node;
802 _gtk_tree_view_find_node (selection->tree_view,
806 _gtk_tree_view_find_node (selection->tree_view,
813 g_return_val_if_fail (start_node != NULL, FALSE);
814 g_return_val_if_fail (end_node != NULL, FALSE);
818 if (GTK_RBNODE_FLAG_SET (start_node, GTK_RBNODE_IS_SELECTED))
820 dirty = gtk_tree_selection_real_select_node (selection, start_tree, start_node, FALSE);
823 if (start_node == end_node)
826 if (start_node->children)
828 start_tree = start_node->children;
829 start_node = start_tree->root;
830 while (start_node->left != start_tree->nil)
831 start_node = start_node->left;
835 gboolean done = FALSE;
838 start_node = _gtk_rbtree_next (start_tree, start_node);
839 if (start_node != NULL)
845 start_node = start_tree->parent_node;
846 start_tree = start_tree->parent_tree;
847 if (start_tree == NULL)
848 /* FIXME should this really be silent, or should it g_warning? */
849 /* we've run out of tree */
850 /* This means we never found end node!! */
863 * gtk_tree_selection_select_range:
864 * @selection: A #GtkTreeSelection.
865 * @start_path: The initial node of the range.
866 * @end_path: The final node of the range.
868 * Selects a range of nodes, determined by @start_path and @end_path inclusive.
871 gtk_tree_selection_select_range (GtkTreeSelection *selection,
872 GtkTreePath *start_path,
873 GtkTreePath *end_path)
875 g_return_if_fail (selection != NULL);
876 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
877 g_return_if_fail (selection->tree_view != NULL);
879 if (gtk_tree_selection_real_select_range (selection, start_path, end_path))
880 gtk_signal_emit (G_OBJECT (selection), tree_selection_signals[CHANGED], 0);
883 /* Called internally by gtktreeview.c It handles actually selecting the tree.
886 _gtk_tree_selection_internal_select_node (GtkTreeSelection *selection,
890 GdkModifierType state)
894 GtkTreePath *anchor_path = NULL;
897 if (selection->tree_view->priv->anchor)
898 anchor_path = gtk_tree_row_reference_get_path (selection->tree_view->priv->anchor);
900 if (selection->type == GTK_TREE_SELECTION_SINGLE)
902 /* Did we try to select the same node again? */
903 if (anchor_path && gtk_tree_path_compare (path, anchor_path) == 0)
905 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
907 dirty = gtk_tree_selection_real_unselect_all (selection);
912 /* FIXME: We only want to select the new node if we can unselect the
913 * old one, and we can select the new one. We are currently
914 * unselecting the old one first, then trying the new one. */
917 dirty = gtk_tree_selection_real_unselect_all (selection);
920 if (selection->tree_view->priv->anchor)
921 gtk_tree_row_reference_free (selection->tree_view->priv->anchor);
922 if (gtk_tree_selection_real_select_node (selection, tree, node, TRUE))
924 selection->tree_view->priv->anchor =
925 gtk_tree_row_reference_new_proxy (G_OBJECT (selection->tree_view), selection->tree_view->priv->model, path);
931 if (gtk_tree_selection_real_select_node (selection, tree, node, TRUE))
934 selection->tree_view->priv->anchor =
935 gtk_tree_row_reference_new_proxy (G_OBJECT (selection->tree_view), selection->tree_view->priv->model, path);
940 else if (selection->type == GTK_TREE_SELECTION_MULTI)
942 if (((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK) && (anchor_path == NULL))
944 if (selection->tree_view->priv->anchor)
945 gtk_tree_row_reference_free (selection->tree_view->priv->anchor);
947 selection->tree_view->priv->anchor =
948 gtk_tree_row_reference_new_proxy (G_OBJECT (selection->tree_view), selection->tree_view->priv->model, path);
949 dirty = gtk_tree_selection_real_select_node (selection, tree, node, TRUE);
951 else if ((state & (GDK_CONTROL_MASK|GDK_SHIFT_MASK)) == (GDK_SHIFT_MASK|GDK_CONTROL_MASK))
953 gtk_tree_selection_select_range (selection,
957 else if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
960 if (selection->tree_view->priv->anchor)
961 gtk_tree_row_reference_free (selection->tree_view->priv->anchor);
963 selection->tree_view->priv->anchor =
964 gtk_tree_row_reference_new_proxy (G_OBJECT (selection->tree_view), selection->tree_view->priv->model, path);
966 if ((flags & GTK_RBNODE_IS_SELECTED) == GTK_RBNODE_IS_SELECTED)
967 dirty |= gtk_tree_selection_real_select_node (selection, tree, node, FALSE);
969 dirty |= gtk_tree_selection_real_select_node (selection, tree, node, TRUE);
971 else if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
973 dirty = gtk_tree_selection_real_unselect_all (selection);
974 dirty |= gtk_tree_selection_real_select_range (selection,
980 dirty = gtk_tree_selection_real_unselect_all (selection);
982 if (selection->tree_view->priv->anchor)
983 gtk_tree_row_reference_free (selection->tree_view->priv->anchor);
985 selection->tree_view->priv->anchor =
986 gtk_tree_row_reference_new_proxy (G_OBJECT (selection->tree_view), selection->tree_view->priv->model, path);
988 dirty |= gtk_tree_selection_real_select_node (selection, tree, node, TRUE);
993 gtk_tree_path_free (anchor_path);
996 g_signal_emit (G_OBJECT (selection), tree_selection_signals[CHANGED], 0);
999 /* NOTE: Any {un,}selection ever done _MUST_ be done through this function!
1002 /* FIXME: user_func can screw up GTK_TREE_SELECTION_SINGLE. If it prevents
1003 * unselection of a node, it can keep more then one node selected.
1005 /* Perhaps the correct solution is to prevent selecting the new node, if
1006 * we fail to unselect the old node.
1009 gtk_tree_selection_real_select_node (GtkTreeSelection *selection,
1014 gboolean selected = FALSE;
1015 GtkTreePath *path = NULL;
1017 if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED) != select)
1019 path = _gtk_tree_view_find_path (selection->tree_view, tree, node);
1020 if (selection->user_func)
1022 if ((*selection->user_func) (selection, selection->tree_view->priv->model, path, selection->user_data))
1027 gtk_tree_path_free (path);
1030 if (selected == TRUE)
1032 node->flags ^= GTK_RBNODE_IS_SELECTED;
1034 /* FIXME: just draw the one node*/
1035 gtk_widget_queue_draw (GTK_WIDGET (selection->tree_view));