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.
248 * The select function should return %TRUE if the state of the node may be toggled,
249 * and %FALSE if the state of the node should be left unchanged.
252 gtk_tree_selection_set_select_function (GtkTreeSelection *selection,
253 GtkTreeSelectionFunc func,
255 GtkDestroyNotify destroy)
257 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
258 g_return_if_fail (func != NULL);
260 selection->user_func = func;
261 selection->user_data = data;
262 selection->destroy = destroy;
266 * gtk_tree_selection_get_user_data:
267 * @selection: A #GtkTreeSelection.
269 * Returns the user data for the selection function.
271 * Return value: The user data.
274 gtk_tree_selection_get_user_data (GtkTreeSelection *selection)
276 g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), NULL);
278 return selection->user_data;
282 * gtk_tree_selection_get_tree_view:
283 * @selection: A #GtkTreeSelection
285 * Returns the tree view associated with @selection.
287 * Return value: A #GtkTreeView
290 gtk_tree_selection_get_tree_view (GtkTreeSelection *selection)
292 g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), NULL);
294 return selection->tree_view;
298 * gtk_tree_selection_get_selected:
299 * @selection: A #GtkTreeSelection.
300 * @model: A pointer set to the #GtkTreeModel, or NULL.
301 * @iter: The #GtkTreeIter, or NULL.
303 * Sets @iter to the currently selected node if @selection is set to
304 * #GTK_SELECTION_SINGLE or #GTK_SELECTION_BROWSE. @iter may be NULL if you
305 * just want to test if @selection has any selected nodes. @model is filled
306 * with the current model as a convenience. This function will not work if you
307 * use @selection is #GTK_SELECTION_MULTIPLE.
309 * Return value: TRUE, if there is a selected node.
312 gtk_tree_selection_get_selected (GtkTreeSelection *selection,
313 GtkTreeModel **model,
318 GtkTreePath *anchor_path;
321 g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), FALSE);
322 g_return_val_if_fail (selection->type != GTK_SELECTION_MULTIPLE, FALSE);
323 g_return_val_if_fail (selection->tree_view != NULL, FALSE);
324 g_return_val_if_fail (selection->tree_view->priv->model != NULL, FALSE);
327 *model = selection->tree_view->priv->model;
329 if (selection->tree_view->priv->anchor == NULL)
332 anchor_path = gtk_tree_row_reference_get_path (selection->tree_view->priv->anchor);
334 if (anchor_path == NULL)
339 gtk_tree_path_free (anchor_path);
345 if (!_gtk_tree_view_find_node (selection->tree_view,
349 ! GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
351 /* We don't want to return the anchor if it isn't actually selected.
357 retval = gtk_tree_model_get_iter (selection->tree_view->priv->model,
362 gtk_tree_path_free (anchor_path);
368 * gtk_tree_selection_selected_foreach:
369 * @selection: A #GtkTreeSelection.
370 * @func: The function to call for each selected node.
371 * @data: user data to pass to the function.
373 * Calls a function for each selected node.
376 gtk_tree_selection_selected_foreach (GtkTreeSelection *selection,
377 GtkTreeSelectionForeachFunc func,
385 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
386 g_return_if_fail (selection->tree_view != NULL);
387 g_return_if_fail (selection->tree_view->priv->model != NULL);
390 selection->tree_view->priv->tree == NULL ||
391 selection->tree_view->priv->tree->root == NULL)
394 if (selection->type == GTK_SELECTION_SINGLE ||
395 selection->type == GTK_SELECTION_BROWSE)
397 if (gtk_tree_row_reference_valid (selection->tree_view->priv->anchor))
399 path = gtk_tree_row_reference_get_path (selection->tree_view->priv->anchor);
400 gtk_tree_model_get_iter (selection->tree_view->priv->model, &iter, path);
401 (* func) (selection->tree_view->priv->model, path, &iter, data);
402 gtk_tree_path_free (path);
407 tree = selection->tree_view->priv->tree;
408 node = selection->tree_view->priv->tree->root;
410 while (node->left != tree->nil)
413 /* find the node internally */
414 path = gtk_tree_path_new_root ();
415 gtk_tree_model_get_iter (selection->tree_view->priv->model,
420 if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
421 (* func) (selection->tree_view->priv->model, path, &iter, data);
427 tree = node->children;
429 while (node->left != tree->nil)
432 has_child = gtk_tree_model_iter_children (selection->tree_view->priv->model, &iter, &tmp);
433 gtk_tree_path_append_index (path, 0);
435 TREE_VIEW_INTERNAL_ASSERT_VOID (has_child);
439 gboolean done = FALSE;
442 node = _gtk_rbtree_next (tree, node);
447 has_next = gtk_tree_model_iter_next (selection->tree_view->priv->model, &iter);
449 gtk_tree_path_next (path);
452 TREE_VIEW_INTERNAL_ASSERT_VOID (has_next);
457 GtkTreeIter tmp_iter = iter;
459 node = tree->parent_node;
460 tree = tree->parent_tree;
463 gtk_tree_path_free (path);
464 /* we've run out of tree */
465 /* We're done with this function */
468 has_parent = gtk_tree_model_iter_parent (selection->tree_view->priv->model, &iter, &tmp_iter);
469 gtk_tree_path_up (path);
471 TREE_VIEW_INTERNAL_ASSERT_VOID (has_parent);
481 * gtk_tree_selection_select_path:
482 * @selection: A #GtkTreeSelection.
483 * @path: The #GtkTreePath to be selected.
485 * Select the row at @path.
488 gtk_tree_selection_select_path (GtkTreeSelection *selection,
493 GdkModifierType state = 0;
495 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
496 g_return_if_fail (selection->tree_view != NULL);
497 g_return_if_fail (path != NULL);
499 _gtk_tree_view_find_node (selection->tree_view,
504 if (node == NULL || GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
507 if (selection->type == GTK_SELECTION_MULTIPLE)
508 state = GDK_CONTROL_MASK;
510 _gtk_tree_selection_internal_select_node (selection,
518 * gtk_tree_selection_unselect_path:
519 * @selection: A #GtkTreeSelection.
520 * @path: The #GtkTreePath to be unselected.
522 * Unselects the row at @path.
525 gtk_tree_selection_unselect_path (GtkTreeSelection *selection,
531 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
532 g_return_if_fail (selection->tree_view != NULL);
533 g_return_if_fail (path != NULL);
535 _gtk_tree_view_find_node (selection->tree_view,
540 if (node == NULL || !GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
543 _gtk_tree_selection_internal_select_node (selection,
551 * gtk_tree_selection_select_iter:
552 * @selection: A #GtkTreeSelection.
553 * @iter: The #GtkTreeIter to be selected.
555 * Selects the specified iterator.
558 gtk_tree_selection_select_iter (GtkTreeSelection *selection,
563 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
564 g_return_if_fail (selection->tree_view != NULL);
565 g_return_if_fail (selection->tree_view->priv->model != NULL);
566 g_return_if_fail (iter != NULL);
568 path = gtk_tree_model_get_path (selection->tree_view->priv->model,
574 gtk_tree_selection_select_path (selection, path);
575 gtk_tree_path_free (path);
580 * gtk_tree_selection_unselect_iter:
581 * @selection: A #GtkTreeSelection.
582 * @iter: The #GtkTreeIter to be unselected.
584 * Unselects the specified iterator.
587 gtk_tree_selection_unselect_iter (GtkTreeSelection *selection,
592 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
593 g_return_if_fail (selection->tree_view != NULL);
594 g_return_if_fail (selection->tree_view->priv->model != NULL);
595 g_return_if_fail (iter != NULL);
597 path = gtk_tree_model_get_path (selection->tree_view->priv->model,
603 gtk_tree_selection_select_path (selection, path);
604 gtk_tree_path_free (path);
607 /* Wish I was in python, right now... */
609 GtkTreeSelection *selection;
614 select_all_helper (GtkRBTree *tree,
618 struct _TempTuple *tuple = data;
621 _gtk_rbtree_traverse (node->children,
622 node->children->root,
626 if (!GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
628 tuple->dirty = gtk_tree_selection_real_select_node (tuple->selection, tree, node, TRUE) || tuple->dirty;
633 /* We have a real_{un,}select_all function that doesn't emit the signal, so we
634 * can use it in other places without fear of the signal being emitted.
637 gtk_tree_selection_real_select_all (GtkTreeSelection *selection)
639 struct _TempTuple *tuple;
641 if (selection->tree_view->priv->tree == NULL)
644 /* Mark all nodes selected */
645 tuple = g_new (struct _TempTuple, 1);
646 tuple->selection = selection;
647 tuple->dirty = FALSE;
649 _gtk_rbtree_traverse (selection->tree_view->priv->tree,
650 selection->tree_view->priv->tree->root,
664 * gtk_tree_selection_select_all:
665 * @selection: A #GtkTreeSelection.
667 * Selects all the nodes. @selection is must be set to #GTK_SELECTION_MULTIPLE
671 gtk_tree_selection_select_all (GtkTreeSelection *selection)
673 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
674 g_return_if_fail (selection->tree_view != NULL);
675 if (selection->tree_view->priv->tree == NULL)
677 g_return_if_fail (selection->type == GTK_SELECTION_MULTIPLE);
679 if (gtk_tree_selection_real_select_all (selection))
680 g_signal_emit (G_OBJECT (selection), tree_selection_signals[CHANGED], 0);
684 unselect_all_helper (GtkRBTree *tree,
688 struct _TempTuple *tuple = data;
691 _gtk_rbtree_traverse (node->children,
692 node->children->root,
696 if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
698 tuple->dirty = gtk_tree_selection_real_select_node (tuple->selection, tree, node, FALSE) || tuple->dirty;
703 gtk_tree_selection_real_unselect_all (GtkTreeSelection *selection)
705 struct _TempTuple *tuple;
707 if (selection->type == GTK_SELECTION_SINGLE ||
708 selection->type == GTK_SELECTION_BROWSE)
710 GtkRBTree *tree = NULL;
711 GtkRBNode *node = NULL;
712 GtkTreePath *anchor_path;
714 if (selection->tree_view->priv->anchor == NULL)
717 anchor_path = gtk_tree_row_reference_get_path (selection->tree_view->priv->anchor);
719 if (anchor_path == NULL)
722 _gtk_tree_view_find_node (selection->tree_view,
727 gtk_tree_path_free (anchor_path);
732 if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
734 if (gtk_tree_selection_real_select_node (selection, tree, node, FALSE))
736 gtk_tree_row_reference_free (selection->tree_view->priv->anchor);
737 selection->tree_view->priv->anchor = NULL;
745 tuple = g_new (struct _TempTuple, 1);
746 tuple->selection = selection;
747 tuple->dirty = FALSE;
749 _gtk_rbtree_traverse (selection->tree_view->priv->tree,
750 selection->tree_view->priv->tree->root,
766 * gtk_tree_selection_unselect_all:
767 * @selection: A #GtkTreeSelection.
769 * Unselects all the nodes.
772 gtk_tree_selection_unselect_all (GtkTreeSelection *selection)
774 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
775 g_return_if_fail (selection->tree_view != NULL);
776 if (selection->tree_view->priv->tree == NULL)
779 if (selection->tree_view->priv->tree == NULL)
782 if (gtk_tree_selection_real_unselect_all (selection))
783 g_signal_emit (G_OBJECT (selection), tree_selection_signals[CHANGED], 0);
787 gtk_tree_selection_real_select_range (GtkTreeSelection *selection,
788 GtkTreePath *start_path,
789 GtkTreePath *end_path)
791 GtkRBNode *start_node, *end_node;
792 GtkRBTree *start_tree, *end_tree;
793 gboolean dirty = FALSE;
795 switch (gtk_tree_path_compare (start_path, end_path))
798 _gtk_tree_view_find_node (selection->tree_view,
802 _gtk_tree_view_find_node (selection->tree_view,
808 _gtk_tree_view_find_node (selection->tree_view,
812 end_tree = start_tree;
813 end_node = start_node;
816 _gtk_tree_view_find_node (selection->tree_view,
820 _gtk_tree_view_find_node (selection->tree_view,
827 g_return_val_if_fail (start_node != NULL, FALSE);
828 g_return_val_if_fail (end_node != NULL, FALSE);
832 dirty |= gtk_tree_selection_real_select_node (selection, start_tree, start_node, TRUE);
834 if (start_node == end_node)
837 if (start_node->children)
839 start_tree = start_node->children;
840 start_node = start_tree->root;
841 while (start_node->left != start_tree->nil)
842 start_node = start_node->left;
846 _gtk_rbtree_next_full (start_tree, start_node, &start_tree, &start_node);
847 if (start_tree == NULL)
849 /* we just ran out of tree. That means someone passed in bogus values.
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_SELECTION_SINGLE ||
898 selection->type == GTK_SELECTION_BROWSE)
900 /* Did we try to select the same node again? */
901 if (selection->type == GTK_SELECTION_SINGLE &&
902 anchor_path && gtk_tree_path_compare (path, anchor_path) == 0)
904 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
906 dirty = gtk_tree_selection_real_unselect_all (selection);
911 /* FIXME: We only want to select the new node if we can unselect the
912 * old one, and we can select the new one. We are currently
913 * unselecting the old one first, then trying the new one. */
916 dirty = gtk_tree_selection_real_unselect_all (selection);
919 if (selection->tree_view->priv->anchor)
920 gtk_tree_row_reference_free (selection->tree_view->priv->anchor);
921 if (gtk_tree_selection_real_select_node (selection, tree, node, TRUE))
923 selection->tree_view->priv->anchor =
924 gtk_tree_row_reference_new_proxy (G_OBJECT (selection->tree_view), selection->tree_view->priv->model, path);
930 if (gtk_tree_selection_real_select_node (selection, tree, node, TRUE))
933 selection->tree_view->priv->anchor =
934 gtk_tree_row_reference_new_proxy (G_OBJECT (selection->tree_view), selection->tree_view->priv->model, path);
939 else if (selection->type == GTK_SELECTION_MULTIPLE)
941 if (((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK) && (anchor_path == NULL))
943 if (selection->tree_view->priv->anchor)
944 gtk_tree_row_reference_free (selection->tree_view->priv->anchor);
946 selection->tree_view->priv->anchor =
947 gtk_tree_row_reference_new_proxy (G_OBJECT (selection->tree_view), selection->tree_view->priv->model, path);
948 dirty = gtk_tree_selection_real_select_node (selection, tree, node, TRUE);
950 else if ((state & (GDK_CONTROL_MASK|GDK_SHIFT_MASK)) == (GDK_SHIFT_MASK|GDK_CONTROL_MASK))
952 gtk_tree_selection_select_range (selection,
956 else if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
959 if (selection->tree_view->priv->anchor)
960 gtk_tree_row_reference_free (selection->tree_view->priv->anchor);
962 selection->tree_view->priv->anchor =
963 gtk_tree_row_reference_new_proxy (G_OBJECT (selection->tree_view), selection->tree_view->priv->model, path);
965 if ((flags & GTK_RBNODE_IS_SELECTED) == GTK_RBNODE_IS_SELECTED)
966 dirty |= gtk_tree_selection_real_select_node (selection, tree, node, FALSE);
968 dirty |= gtk_tree_selection_real_select_node (selection, tree, node, TRUE);
970 else if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
972 dirty = gtk_tree_selection_real_unselect_all (selection);
973 dirty |= gtk_tree_selection_real_select_range (selection,
979 dirty = gtk_tree_selection_real_unselect_all (selection);
981 if (selection->tree_view->priv->anchor)
982 gtk_tree_row_reference_free (selection->tree_view->priv->anchor);
984 selection->tree_view->priv->anchor =
985 gtk_tree_row_reference_new_proxy (G_OBJECT (selection->tree_view), selection->tree_view->priv->model, path);
987 dirty |= gtk_tree_selection_real_select_node (selection, tree, node, TRUE);
992 gtk_tree_path_free (anchor_path);
995 g_signal_emit (G_OBJECT (selection), tree_selection_signals[CHANGED], 0);
998 /* NOTE: Any {un,}selection ever done _MUST_ be done through this function!
1002 gtk_tree_selection_real_select_node (GtkTreeSelection *selection,
1007 gboolean selected = FALSE;
1008 GtkTreePath *path = NULL;
1010 if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED) != select)
1012 path = _gtk_tree_view_find_path (selection->tree_view, tree, node);
1013 if (selection->user_func)
1015 if ((*selection->user_func) (selection, selection->tree_view->priv->model, path,
1016 GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED),
1017 selection->user_data))
1022 gtk_tree_path_free (path);
1025 if (selected == TRUE)
1027 node->flags ^= GTK_RBNODE_IS_SELECTED;
1029 /* FIXME: just draw the one node*/
1030 gtk_widget_queue_draw (GTK_WIDGET (selection->tree_view));