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_row_reference_valid (selection->tree_view->priv->anchor))
391 path = gtk_tree_row_reference_get_path (selection->tree_view->priv->anchor);
392 gtk_tree_model_get_iter (selection->tree_view->priv->model, &iter, path);
393 (* func) (selection->tree_view->priv->model, path, &iter, data);
394 gtk_tree_path_free (path);
399 tree = selection->tree_view->priv->tree;
400 node = selection->tree_view->priv->tree->root;
402 while (node->left != tree->nil)
405 /* find the node internally */
406 path = gtk_tree_path_new_root ();
407 gtk_tree_model_get_iter (selection->tree_view->priv->model,
412 if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
413 (* func) (selection->tree_view->priv->model, path, &iter, data);
419 tree = node->children;
421 while (node->left != tree->nil)
424 has_child = gtk_tree_model_iter_children (selection->tree_view->priv->model, &iter, &tmp);
425 gtk_tree_path_append_index (path, 0);
427 TREE_VIEW_INTERNAL_ASSERT_VOID (has_child);
431 gboolean done = FALSE;
434 node = _gtk_rbtree_next (tree, node);
439 has_next = gtk_tree_model_iter_next (selection->tree_view->priv->model, &iter);
441 gtk_tree_path_next (path);
444 TREE_VIEW_INTERNAL_ASSERT_VOID (has_next);
449 GtkTreeIter tmp_iter = iter;
451 node = tree->parent_node;
452 tree = tree->parent_tree;
455 gtk_tree_path_free (path);
456 /* we've run out of tree */
457 /* We're done with this function */
460 has_parent = gtk_tree_model_iter_parent (selection->tree_view->priv->model, &iter, &tmp_iter);
461 gtk_tree_path_up (path);
463 TREE_VIEW_INTERNAL_ASSERT_VOID (has_parent);
473 * gtk_tree_selection_select_path:
474 * @selection: A #GtkTreeSelection.
475 * @path: The #GtkTreePath to be selected.
477 * Select the row at @path.
480 gtk_tree_selection_select_path (GtkTreeSelection *selection,
485 GdkModifierType state = 0;
487 g_return_if_fail (selection != NULL);
488 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
489 g_return_if_fail (selection->tree_view != NULL);
490 g_return_if_fail (path != NULL);
492 _gtk_tree_view_find_node (selection->tree_view,
497 if (node == NULL || GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
500 if (selection->type == GTK_TREE_SELECTION_MULTI)
501 state = GDK_CONTROL_MASK;
503 _gtk_tree_selection_internal_select_node (selection,
511 * gtk_tree_selection_unselect_path:
512 * @selection: A #GtkTreeSelection.
513 * @path: The #GtkTreePath to be unselected.
515 * Unselects the row at @path.
518 gtk_tree_selection_unselect_path (GtkTreeSelection *selection,
524 g_return_if_fail (selection != NULL);
525 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
526 g_return_if_fail (selection->tree_view != NULL);
527 g_return_if_fail (path != NULL);
529 _gtk_tree_view_find_node (selection->tree_view,
534 if (node == NULL || !GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
537 _gtk_tree_selection_internal_select_node (selection,
545 * gtk_tree_selection_select_iter:
546 * @selection: A #GtkTreeSelection.
547 * @iter: The #GtkTreeIter to be selected.
549 * Selects the specified iterator.
552 gtk_tree_selection_select_iter (GtkTreeSelection *selection,
557 g_return_if_fail (selection != NULL);
558 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
559 g_return_if_fail (selection->tree_view != NULL);
560 g_return_if_fail (selection->tree_view->priv->model != NULL);
561 g_return_if_fail (iter != NULL);
563 path = gtk_tree_model_get_path (selection->tree_view->priv->model,
569 gtk_tree_selection_select_path (selection, path);
570 gtk_tree_path_free (path);
575 * gtk_tree_selection_unselect_iter:
576 * @selection: A #GtkTreeSelection.
577 * @iter: The #GtkTreeIter to be unselected.
579 * Unselects the specified iterator.
582 gtk_tree_selection_unselect_iter (GtkTreeSelection *selection,
587 g_return_if_fail (selection != NULL);
588 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
589 g_return_if_fail (selection->tree_view != NULL);
590 g_return_if_fail (selection->tree_view->priv->model != NULL);
591 g_return_if_fail (iter != NULL);
593 path = gtk_tree_model_get_path (selection->tree_view->priv->model,
599 gtk_tree_selection_select_path (selection, path);
600 gtk_tree_path_free (path);
603 /* Wish I was in python, right now... */
605 GtkTreeSelection *selection;
610 select_all_helper (GtkRBTree *tree,
614 struct _TempTuple *tuple = data;
617 _gtk_rbtree_traverse (node->children,
618 node->children->root,
622 if (!GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
624 tuple->dirty = gtk_tree_selection_real_select_node (tuple->selection, tree, node, TRUE) || tuple->dirty;
629 /* We have a real_{un,}select_all function that doesn't emit the signal, so we
630 * can use it in other places without fear of the signal being emitted.
633 gtk_tree_selection_real_select_all (GtkTreeSelection *selection)
635 struct _TempTuple *tuple;
637 if (selection->tree_view->priv->tree == NULL)
640 /* Mark all nodes selected */
641 tuple = g_new (struct _TempTuple, 1);
642 tuple->selection = selection;
643 tuple->dirty = FALSE;
645 _gtk_rbtree_traverse (selection->tree_view->priv->tree,
646 selection->tree_view->priv->tree->root,
660 * gtk_tree_selection_select_all:
661 * @selection: A #GtkTreeSelection.
663 * Selects all the nodes. @selection is must be set to
664 * #GTK_TREE_SELECTION_MULTI mode.
667 gtk_tree_selection_select_all (GtkTreeSelection *selection)
669 g_return_if_fail (selection != NULL);
670 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
671 g_return_if_fail (selection->tree_view != NULL);
672 g_return_if_fail (selection->tree_view->priv->tree != NULL);
673 g_return_if_fail (selection->type != GTK_TREE_SELECTION_MULTI);
675 if (gtk_tree_selection_real_select_all (selection))
676 g_signal_emit (G_OBJECT (selection), tree_selection_signals[CHANGED], 0);
680 unselect_all_helper (GtkRBTree *tree,
684 struct _TempTuple *tuple = data;
687 _gtk_rbtree_traverse (node->children,
688 node->children->root,
692 if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
694 tuple->dirty = gtk_tree_selection_real_select_node (tuple->selection, tree, node, FALSE) || tuple->dirty;
699 gtk_tree_selection_real_unselect_all (GtkTreeSelection *selection)
701 struct _TempTuple *tuple;
703 if (selection->type == GTK_TREE_SELECTION_SINGLE)
705 GtkRBTree *tree = NULL;
706 GtkRBNode *node = NULL;
707 GtkTreePath *anchor_path;
709 if (selection->tree_view->priv->anchor == NULL)
712 anchor_path = gtk_tree_row_reference_get_path (selection->tree_view->priv->anchor);
714 if (anchor_path == NULL)
717 _gtk_tree_view_find_node (selection->tree_view,
722 gtk_tree_path_free (anchor_path);
727 if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
729 if (gtk_tree_selection_real_select_node (selection, tree, node, FALSE))
731 gtk_tree_row_reference_free (selection->tree_view->priv->anchor);
732 selection->tree_view->priv->anchor = NULL;
740 tuple = g_new (struct _TempTuple, 1);
741 tuple->selection = selection;
742 tuple->dirty = FALSE;
744 _gtk_rbtree_traverse (selection->tree_view->priv->tree,
745 selection->tree_view->priv->tree->root,
761 * gtk_tree_selection_unselect_all:
762 * @selection: A #GtkTreeSelection.
764 * Unselects all the nodes.
767 gtk_tree_selection_unselect_all (GtkTreeSelection *selection)
769 g_return_if_fail (selection != NULL);
770 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
771 g_return_if_fail (selection->tree_view != NULL);
772 g_return_if_fail (selection->tree_view->priv->tree != NULL);
773 if (selection->tree_view->priv->tree == NULL)
776 if (gtk_tree_selection_real_unselect_all (selection))
777 g_signal_emit (G_OBJECT (selection), tree_selection_signals[CHANGED], 0);
781 gtk_tree_selection_real_select_range (GtkTreeSelection *selection,
782 GtkTreePath *start_path,
783 GtkTreePath *end_path)
785 GtkRBNode *start_node, *end_node;
786 GtkRBTree *start_tree, *end_tree;
787 gboolean dirty = FALSE;
789 switch (gtk_tree_path_compare (start_path, end_path))
792 _gtk_tree_view_find_node (selection->tree_view,
796 _gtk_tree_view_find_node (selection->tree_view,
802 _gtk_tree_view_find_node (selection->tree_view,
806 end_tree = start_tree;
807 end_node = start_node;
810 _gtk_tree_view_find_node (selection->tree_view,
814 _gtk_tree_view_find_node (selection->tree_view,
821 g_return_val_if_fail (start_node != NULL, FALSE);
822 g_return_val_if_fail (end_node != NULL, FALSE);
826 if (GTK_RBNODE_FLAG_SET (start_node, GTK_RBNODE_IS_SELECTED))
828 dirty = gtk_tree_selection_real_select_node (selection, start_tree, start_node, FALSE);
831 if (start_node == end_node)
834 if (start_node->children)
836 start_tree = start_node->children;
837 start_node = start_tree->root;
838 while (start_node->left != start_tree->nil)
839 start_node = start_node->left;
843 gboolean done = FALSE;
846 start_node = _gtk_rbtree_next (start_tree, start_node);
847 if (start_node != NULL)
853 start_node = start_tree->parent_node;
854 start_tree = start_tree->parent_tree;
855 if (start_tree == NULL)
856 /* FIXME should this really be silent, or should it g_warning? */
857 /* we've run out of tree */
858 /* This means we never found end node!! */
871 * gtk_tree_selection_select_range:
872 * @selection: A #GtkTreeSelection.
873 * @start_path: The initial node of the range.
874 * @end_path: The final node of the range.
876 * Selects a range of nodes, determined by @start_path and @end_path inclusive.
879 gtk_tree_selection_select_range (GtkTreeSelection *selection,
880 GtkTreePath *start_path,
881 GtkTreePath *end_path)
883 g_return_if_fail (selection != NULL);
884 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
885 g_return_if_fail (selection->tree_view != NULL);
887 if (gtk_tree_selection_real_select_range (selection, start_path, end_path))
888 g_signal_emit (G_OBJECT (selection), tree_selection_signals[CHANGED], 0);
891 /* Called internally by gtktreeview.c It handles actually selecting the tree.
894 _gtk_tree_selection_internal_select_node (GtkTreeSelection *selection,
898 GdkModifierType state)
902 GtkTreePath *anchor_path = NULL;
905 if (selection->tree_view->priv->anchor)
906 anchor_path = gtk_tree_row_reference_get_path (selection->tree_view->priv->anchor);
908 if (selection->type == GTK_TREE_SELECTION_SINGLE)
910 /* Did we try to select the same node again? */
911 if (anchor_path && gtk_tree_path_compare (path, anchor_path) == 0)
913 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
915 dirty = gtk_tree_selection_real_unselect_all (selection);
920 /* FIXME: We only want to select the new node if we can unselect the
921 * old one, and we can select the new one. We are currently
922 * unselecting the old one first, then trying the new one. */
925 dirty = gtk_tree_selection_real_unselect_all (selection);
928 if (selection->tree_view->priv->anchor)
929 gtk_tree_row_reference_free (selection->tree_view->priv->anchor);
930 if (gtk_tree_selection_real_select_node (selection, tree, node, TRUE))
932 selection->tree_view->priv->anchor =
933 gtk_tree_row_reference_new_proxy (G_OBJECT (selection->tree_view), selection->tree_view->priv->model, path);
939 if (gtk_tree_selection_real_select_node (selection, tree, node, TRUE))
942 selection->tree_view->priv->anchor =
943 gtk_tree_row_reference_new_proxy (G_OBJECT (selection->tree_view), selection->tree_view->priv->model, path);
948 else if (selection->type == GTK_TREE_SELECTION_MULTI)
950 if (((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK) && (anchor_path == NULL))
952 if (selection->tree_view->priv->anchor)
953 gtk_tree_row_reference_free (selection->tree_view->priv->anchor);
955 selection->tree_view->priv->anchor =
956 gtk_tree_row_reference_new_proxy (G_OBJECT (selection->tree_view), selection->tree_view->priv->model, path);
957 dirty = gtk_tree_selection_real_select_node (selection, tree, node, TRUE);
959 else if ((state & (GDK_CONTROL_MASK|GDK_SHIFT_MASK)) == (GDK_SHIFT_MASK|GDK_CONTROL_MASK))
961 gtk_tree_selection_select_range (selection,
965 else if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
968 if (selection->tree_view->priv->anchor)
969 gtk_tree_row_reference_free (selection->tree_view->priv->anchor);
971 selection->tree_view->priv->anchor =
972 gtk_tree_row_reference_new_proxy (G_OBJECT (selection->tree_view), selection->tree_view->priv->model, path);
974 if ((flags & GTK_RBNODE_IS_SELECTED) == GTK_RBNODE_IS_SELECTED)
975 dirty |= gtk_tree_selection_real_select_node (selection, tree, node, FALSE);
977 dirty |= gtk_tree_selection_real_select_node (selection, tree, node, TRUE);
979 else if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
981 dirty = gtk_tree_selection_real_unselect_all (selection);
982 dirty |= gtk_tree_selection_real_select_range (selection,
988 dirty = gtk_tree_selection_real_unselect_all (selection);
990 if (selection->tree_view->priv->anchor)
991 gtk_tree_row_reference_free (selection->tree_view->priv->anchor);
993 selection->tree_view->priv->anchor =
994 gtk_tree_row_reference_new_proxy (G_OBJECT (selection->tree_view), selection->tree_view->priv->model, path);
996 dirty |= gtk_tree_selection_real_select_node (selection, tree, node, TRUE);
1001 gtk_tree_path_free (anchor_path);
1004 g_signal_emit (G_OBJECT (selection), tree_selection_signals[CHANGED], 0);
1007 /* NOTE: Any {un,}selection ever done _MUST_ be done through this function!
1010 /* FIXME: user_func can screw up GTK_TREE_SELECTION_SINGLE. If it prevents
1011 * unselection of a node, it can keep more then one node selected.
1013 /* Perhaps the correct solution is to prevent selecting the new node, if
1014 * we fail to unselect the old node.
1017 gtk_tree_selection_real_select_node (GtkTreeSelection *selection,
1022 gboolean selected = FALSE;
1023 GtkTreePath *path = NULL;
1025 if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED) != select)
1027 path = _gtk_tree_view_find_path (selection->tree_view, tree, node);
1028 if (selection->user_func)
1030 if ((*selection->user_func) (selection, selection->tree_view->priv->model, path, selection->user_data))
1035 gtk_tree_path_free (path);
1038 if (selected == TRUE)
1040 node->flags ^= GTK_RBNODE_IS_SELECTED;
1042 /* FIXME: just draw the one node*/
1043 gtk_widget_queue_draw (GTK_WIDGET (selection->tree_view));