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 (GTK_IS_TREE_VIEW (tree_view), NULL);
138 selection = _gtk_tree_selection_new ();
139 _gtk_tree_selection_set_tree_view (selection, tree_view);
145 * _gtk_tree_selection_set_tree_view:
146 * @selection: A #GtkTreeSelection.
147 * @tree_view: The #GtkTreeView.
149 * Sets the #GtkTreeView of @selection. This function should not be invoked, as
150 * it is used internally by #GtkTreeView.
153 _gtk_tree_selection_set_tree_view (GtkTreeSelection *selection,
154 GtkTreeView *tree_view)
156 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
157 if (tree_view != NULL)
158 g_return_if_fail (GTK_IS_TREE_VIEW (tree_view));
160 selection->tree_view = tree_view;
164 * gtk_tree_selection_set_mode:
165 * @selection: A #GtkTreeSelection.
166 * @type: The selection mode
168 * Sets the selection mode of the @selection. If the previous type was
169 * #GTK_TREE_SELECTION_MULTI and @type is #GTK_TREE_SELECTION_SINGLE, then
170 * the anchor is kept selected, if it was previously selected.
173 gtk_tree_selection_set_mode (GtkTreeSelection *selection,
174 GtkTreeSelectionMode type)
176 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
178 if (selection->type == type)
181 if (type == GTK_TREE_SELECTION_SINGLE)
183 GtkRBTree *tree = NULL;
184 GtkRBNode *node = NULL;
185 gint selected = FALSE;
187 if (selection->tree_view->priv->anchor)
189 GtkTreePath *anchor_path;
191 anchor_path = gtk_tree_row_reference_get_path (selection->tree_view->priv->anchor);
195 _gtk_tree_view_find_node (selection->tree_view,
200 if (node && GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
203 gtk_tree_path_free (anchor_path);
206 /* FIXME: if user_func is set, then it needs to unconditionally unselect
209 gtk_tree_selection_unselect_all (selection);
211 /* FIXME are we properly emitting the selection_changed signal here? */
212 if (node && selected)
213 GTK_RBNODE_SET_FLAG (node, GTK_RBNODE_IS_SELECTED);
215 selection->type = type;
219 * gtk_tree_selection_get_mode:
220 * @selection: a #GtkTreeSelection
222 * Gets the selection mode for @selection. See
223 * gtk_tree_selection_set_mode().
225 * Return value: the current selection mode
228 gtk_tree_selection_get_mode (GtkTreeSelection *selection)
230 g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), GTK_TREE_SELECTION_SINGLE);
232 return selection->type;
236 * gtk_tree_selection_set_select_function:
237 * @selection: A #GtkTreeSelection.
238 * @func: The selection function.
239 * @data: The selection function's data.
240 * @destroy: The destroy function for user data. May be NULL.
242 * Sets the selection function. If set, this function is called before any node
243 * is selected or unselected, giving some control over which nodes are selected.
246 gtk_tree_selection_set_select_function (GtkTreeSelection *selection,
247 GtkTreeSelectionFunc func,
249 GtkDestroyNotify destroy)
251 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
252 g_return_if_fail (func != NULL);
254 selection->user_func = func;
255 selection->user_data = data;
256 selection->destroy = destroy;
260 * gtk_tree_selection_get_user_data:
261 * @selection: A #GtkTreeSelection.
263 * Returns the user data for the selection function.
265 * Return value: The user data.
268 gtk_tree_selection_get_user_data (GtkTreeSelection *selection)
270 g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), NULL);
272 return selection->user_data;
276 gtk_tree_selection_get_tree_view (GtkTreeSelection *selection)
278 g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), NULL);
280 return selection->tree_view;
284 * gtk_tree_selection_get_selected:
285 * @selection: A #GtkTreeSelection.
286 * @model: A pointer set to the #GtkTreeModel, or NULL.
287 * @iter: The #GtkTreeIter, or NULL.
289 * Sets @iter to the currently selected node if @selection is set to
290 * #GTK_TREE_SELECTION_SINGLE. @iter may be NULL if you just want to test if
291 * @selection has any selected nodes. @model is filled with the current model
292 * as a convenience. This function will not work if you use @selection is
293 * #GTK_TREE_SELECTION_MULTI.
295 * Return value: TRUE, if there is a selected node.
298 gtk_tree_selection_get_selected (GtkTreeSelection *selection,
299 GtkTreeModel **model,
304 GtkTreePath *anchor_path;
307 g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), FALSE);
308 g_return_val_if_fail (selection->type == GTK_TREE_SELECTION_SINGLE, FALSE);
309 g_return_val_if_fail (selection->tree_view != NULL, FALSE);
310 g_return_val_if_fail (selection->tree_view->priv->model != NULL, FALSE);
313 *model = selection->tree_view->priv->model;
315 if (selection->tree_view->priv->anchor == NULL)
318 anchor_path = gtk_tree_row_reference_get_path (selection->tree_view->priv->anchor);
320 if (anchor_path == NULL)
325 gtk_tree_path_free (anchor_path);
331 if (!_gtk_tree_view_find_node (selection->tree_view,
335 ! GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
337 /* We don't want to return the anchor if it isn't actually selected.
343 retval = gtk_tree_model_get_iter (selection->tree_view->priv->model,
348 gtk_tree_path_free (anchor_path);
354 * gtk_tree_selection_selected_foreach:
355 * @selection: A #GtkTreeSelection.
356 * @func: The function to call for each selected node.
357 * @data: user data to pass to the function.
359 * Calls a function for each selected node.
362 gtk_tree_selection_selected_foreach (GtkTreeSelection *selection,
363 GtkTreeSelectionForeachFunc func,
371 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
372 g_return_if_fail (selection->tree_view != NULL);
373 g_return_if_fail (selection->tree_view->priv->model != NULL);
376 selection->tree_view->priv->tree == NULL ||
377 selection->tree_view->priv->tree->root == NULL)
380 if (selection->type == GTK_TREE_SELECTION_SINGLE)
382 if (gtk_tree_row_reference_valid (selection->tree_view->priv->anchor))
384 path = gtk_tree_row_reference_get_path (selection->tree_view->priv->anchor);
385 gtk_tree_model_get_iter (selection->tree_view->priv->model, &iter, path);
386 (* func) (selection->tree_view->priv->model, path, &iter, data);
387 gtk_tree_path_free (path);
392 tree = selection->tree_view->priv->tree;
393 node = selection->tree_view->priv->tree->root;
395 while (node->left != tree->nil)
398 /* find the node internally */
399 path = gtk_tree_path_new_root ();
400 gtk_tree_model_get_iter (selection->tree_view->priv->model,
405 if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
406 (* func) (selection->tree_view->priv->model, path, &iter, data);
412 tree = node->children;
414 while (node->left != tree->nil)
417 has_child = gtk_tree_model_iter_children (selection->tree_view->priv->model, &iter, &tmp);
418 gtk_tree_path_append_index (path, 0);
420 TREE_VIEW_INTERNAL_ASSERT_VOID (has_child);
424 gboolean done = FALSE;
427 node = _gtk_rbtree_next (tree, node);
432 has_next = gtk_tree_model_iter_next (selection->tree_view->priv->model, &iter);
434 gtk_tree_path_next (path);
437 TREE_VIEW_INTERNAL_ASSERT_VOID (has_next);
442 GtkTreeIter tmp_iter = iter;
444 node = tree->parent_node;
445 tree = tree->parent_tree;
448 gtk_tree_path_free (path);
449 /* we've run out of tree */
450 /* We're done with this function */
453 has_parent = gtk_tree_model_iter_parent (selection->tree_view->priv->model, &iter, &tmp_iter);
454 gtk_tree_path_up (path);
456 TREE_VIEW_INTERNAL_ASSERT_VOID (has_parent);
466 * gtk_tree_selection_select_path:
467 * @selection: A #GtkTreeSelection.
468 * @path: The #GtkTreePath to be selected.
470 * Select the row at @path.
473 gtk_tree_selection_select_path (GtkTreeSelection *selection,
478 GdkModifierType state = 0;
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 (GTK_IS_TREE_SELECTION (selection));
517 g_return_if_fail (selection->tree_view != NULL);
518 g_return_if_fail (path != NULL);
520 _gtk_tree_view_find_node (selection->tree_view,
525 if (node == NULL || !GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
528 _gtk_tree_selection_internal_select_node (selection,
536 * gtk_tree_selection_select_iter:
537 * @selection: A #GtkTreeSelection.
538 * @iter: The #GtkTreeIter to be selected.
540 * Selects the specified iterator.
543 gtk_tree_selection_select_iter (GtkTreeSelection *selection,
548 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
549 g_return_if_fail (selection->tree_view != NULL);
550 g_return_if_fail (selection->tree_view->priv->model != NULL);
551 g_return_if_fail (iter != NULL);
553 path = gtk_tree_model_get_path (selection->tree_view->priv->model,
559 gtk_tree_selection_select_path (selection, path);
560 gtk_tree_path_free (path);
565 * gtk_tree_selection_unselect_iter:
566 * @selection: A #GtkTreeSelection.
567 * @iter: The #GtkTreeIter to be unselected.
569 * Unselects the specified iterator.
572 gtk_tree_selection_unselect_iter (GtkTreeSelection *selection,
577 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
578 g_return_if_fail (selection->tree_view != NULL);
579 g_return_if_fail (selection->tree_view->priv->model != NULL);
580 g_return_if_fail (iter != NULL);
582 path = gtk_tree_model_get_path (selection->tree_view->priv->model,
588 gtk_tree_selection_select_path (selection, path);
589 gtk_tree_path_free (path);
592 /* Wish I was in python, right now... */
594 GtkTreeSelection *selection;
599 select_all_helper (GtkRBTree *tree,
603 struct _TempTuple *tuple = data;
606 _gtk_rbtree_traverse (node->children,
607 node->children->root,
611 if (!GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
613 tuple->dirty = gtk_tree_selection_real_select_node (tuple->selection, tree, node, TRUE) || tuple->dirty;
618 /* We have a real_{un,}select_all function that doesn't emit the signal, so we
619 * can use it in other places without fear of the signal being emitted.
622 gtk_tree_selection_real_select_all (GtkTreeSelection *selection)
624 struct _TempTuple *tuple;
626 if (selection->tree_view->priv->tree == NULL)
629 /* Mark all nodes selected */
630 tuple = g_new (struct _TempTuple, 1);
631 tuple->selection = selection;
632 tuple->dirty = FALSE;
634 _gtk_rbtree_traverse (selection->tree_view->priv->tree,
635 selection->tree_view->priv->tree->root,
649 * gtk_tree_selection_select_all:
650 * @selection: A #GtkTreeSelection.
652 * Selects all the nodes. @selection is must be set to
653 * #GTK_TREE_SELECTION_MULTI mode.
656 gtk_tree_selection_select_all (GtkTreeSelection *selection)
658 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
659 g_return_if_fail (selection->tree_view != NULL);
660 if (selection->tree_view->priv->tree == NULL)
662 g_return_if_fail (selection->type != GTK_TREE_SELECTION_MULTI);
664 if (gtk_tree_selection_real_select_all (selection))
665 g_signal_emit (G_OBJECT (selection), tree_selection_signals[CHANGED], 0);
669 unselect_all_helper (GtkRBTree *tree,
673 struct _TempTuple *tuple = data;
676 _gtk_rbtree_traverse (node->children,
677 node->children->root,
681 if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
683 tuple->dirty = gtk_tree_selection_real_select_node (tuple->selection, tree, node, FALSE) || tuple->dirty;
688 gtk_tree_selection_real_unselect_all (GtkTreeSelection *selection)
690 struct _TempTuple *tuple;
692 if (selection->type == GTK_TREE_SELECTION_SINGLE)
694 GtkRBTree *tree = NULL;
695 GtkRBNode *node = NULL;
696 GtkTreePath *anchor_path;
698 if (selection->tree_view->priv->anchor == NULL)
701 anchor_path = gtk_tree_row_reference_get_path (selection->tree_view->priv->anchor);
703 if (anchor_path == NULL)
706 _gtk_tree_view_find_node (selection->tree_view,
711 gtk_tree_path_free (anchor_path);
716 if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
718 if (gtk_tree_selection_real_select_node (selection, tree, node, FALSE))
720 gtk_tree_row_reference_free (selection->tree_view->priv->anchor);
721 selection->tree_view->priv->anchor = NULL;
729 tuple = g_new (struct _TempTuple, 1);
730 tuple->selection = selection;
731 tuple->dirty = FALSE;
733 _gtk_rbtree_traverse (selection->tree_view->priv->tree,
734 selection->tree_view->priv->tree->root,
750 * gtk_tree_selection_unselect_all:
751 * @selection: A #GtkTreeSelection.
753 * Unselects all the nodes.
756 gtk_tree_selection_unselect_all (GtkTreeSelection *selection)
758 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
759 g_return_if_fail (selection->tree_view != NULL);
760 if (selection->tree_view->priv->tree == NULL)
763 if (selection->tree_view->priv->tree == NULL)
766 if (gtk_tree_selection_real_unselect_all (selection))
767 g_signal_emit (G_OBJECT (selection), tree_selection_signals[CHANGED], 0);
771 gtk_tree_selection_real_select_range (GtkTreeSelection *selection,
772 GtkTreePath *start_path,
773 GtkTreePath *end_path)
775 GtkRBNode *start_node, *end_node;
776 GtkRBTree *start_tree, *end_tree;
777 gboolean dirty = FALSE;
779 switch (gtk_tree_path_compare (start_path, end_path))
782 _gtk_tree_view_find_node (selection->tree_view,
786 _gtk_tree_view_find_node (selection->tree_view,
792 _gtk_tree_view_find_node (selection->tree_view,
796 end_tree = start_tree;
797 end_node = start_node;
800 _gtk_tree_view_find_node (selection->tree_view,
804 _gtk_tree_view_find_node (selection->tree_view,
811 g_return_val_if_fail (start_node != NULL, FALSE);
812 g_return_val_if_fail (end_node != NULL, FALSE);
816 if (GTK_RBNODE_FLAG_SET (start_node, GTK_RBNODE_IS_SELECTED))
818 dirty = gtk_tree_selection_real_select_node (selection, start_tree, start_node, FALSE);
821 if (start_node == end_node)
824 if (start_node->children)
826 start_tree = start_node->children;
827 start_node = start_tree->root;
828 while (start_node->left != start_tree->nil)
829 start_node = start_node->left;
833 gboolean done = FALSE;
836 start_node = _gtk_rbtree_next (start_tree, start_node);
837 if (start_node != NULL)
843 start_node = start_tree->parent_node;
844 start_tree = start_tree->parent_tree;
845 if (start_tree == NULL)
846 /* FIXME should this really be silent, or should it g_warning? */
847 /* we've run out of tree */
848 /* This means we never found end node!! */
861 * gtk_tree_selection_select_range:
862 * @selection: A #GtkTreeSelection.
863 * @start_path: The initial node of the range.
864 * @end_path: The final node of the range.
866 * Selects a range of nodes, determined by @start_path and @end_path inclusive.
869 gtk_tree_selection_select_range (GtkTreeSelection *selection,
870 GtkTreePath *start_path,
871 GtkTreePath *end_path)
873 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
874 g_return_if_fail (selection->tree_view != NULL);
876 if (gtk_tree_selection_real_select_range (selection, start_path, end_path))
877 g_signal_emit (G_OBJECT (selection), tree_selection_signals[CHANGED], 0);
880 /* Called internally by gtktreeview.c It handles actually selecting the tree.
883 _gtk_tree_selection_internal_select_node (GtkTreeSelection *selection,
887 GdkModifierType state)
891 GtkTreePath *anchor_path = NULL;
894 if (selection->tree_view->priv->anchor)
895 anchor_path = gtk_tree_row_reference_get_path (selection->tree_view->priv->anchor);
897 if (selection->type == GTK_TREE_SELECTION_SINGLE)
899 /* Did we try to select the same node again? */
900 if (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_TREE_SELECTION_MULTI)
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!
999 /* FIXME: user_func can screw up GTK_TREE_SELECTION_SINGLE. If it prevents
1000 * unselection of a node, it can keep more then one node selected.
1002 /* Perhaps the correct solution is to prevent selecting the new node, if
1003 * we fail to unselect the old node.
1006 gtk_tree_selection_real_select_node (GtkTreeSelection *selection,
1011 gboolean selected = FALSE;
1012 GtkTreePath *path = NULL;
1014 if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED) != select)
1016 path = _gtk_tree_view_find_path (selection->tree_view, tree, node);
1017 if (selection->user_func)
1019 if ((*selection->user_func) (selection, selection->tree_view->priv->model, path, selection->user_data))
1024 gtk_tree_path_free (path);
1027 if (selected == TRUE)
1029 node->flags ^= GTK_RBNODE_IS_SELECTED;
1031 /* FIXME: just draw the one node*/
1032 gtk_widget_queue_draw (GTK_WIDGET (selection->tree_view));