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, then the anchor is kept selected, if it was
173 * previously selected.
176 gtk_tree_selection_set_mode (GtkTreeSelection *selection,
177 GtkSelectionMode type)
179 GtkTreeSelectionFunc tmp_func;
180 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
182 if (selection->type == type)
186 if (type == GTK_SELECTION_NONE)
188 gtk_tree_row_reference_free (selection->tree_view->priv->anchor);
189 /* We do this so that we unconditionally unset all rows
191 tmp_func = selection->user_func;
192 selection->user_func = NULL;
193 gtk_tree_selection_unselect_all (selection);
194 selection->user_func = tmp_func;
196 else if (type == GTK_SELECTION_SINGLE ||
197 type == GTK_SELECTION_BROWSE)
199 GtkRBTree *tree = NULL;
200 GtkRBNode *node = NULL;
201 gint selected = FALSE;
202 GtkTreePath *anchor_path = NULL;
204 if (selection->tree_view->priv->anchor)
206 anchor_path = gtk_tree_row_reference_get_path (selection->tree_view->priv->anchor);
210 _gtk_tree_view_find_node (selection->tree_view,
215 if (node && GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
220 /* We do this so that we unconditionally unset all rows
222 tmp_func = selection->user_func;
223 selection->user_func = NULL;
224 gtk_tree_selection_unselect_all (selection);
225 selection->user_func = tmp_func;
227 if (node && selected)
228 _gtk_tree_selection_internal_select_node (selection,
234 gtk_tree_path_free (anchor_path);
237 selection->type = type;
241 * gtk_tree_selection_get_mode:
242 * @selection: a #GtkTreeSelection
244 * Gets the selection mode for @selection. See
245 * gtk_tree_selection_set_mode().
247 * Return value: the current selection mode
250 gtk_tree_selection_get_mode (GtkTreeSelection *selection)
252 g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), GTK_SELECTION_SINGLE);
254 return selection->type;
258 * gtk_tree_selection_set_select_function:
259 * @selection: A #GtkTreeSelection.
260 * @func: The selection function.
261 * @data: The selection function's data.
262 * @destroy: The destroy function for user data. May be NULL.
264 * Sets the selection function. If set, this function is called before any node
265 * is selected or unselected, giving some control over which nodes are selected.
266 * The select function should return %TRUE if the state of the node may be toggled,
267 * and %FALSE if the state of the node should be left unchanged.
270 gtk_tree_selection_set_select_function (GtkTreeSelection *selection,
271 GtkTreeSelectionFunc func,
273 GtkDestroyNotify destroy)
275 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
276 g_return_if_fail (func != NULL);
278 selection->user_func = func;
279 selection->user_data = data;
280 selection->destroy = destroy;
284 * gtk_tree_selection_get_user_data:
285 * @selection: A #GtkTreeSelection.
287 * Returns the user data for the selection function.
289 * Return value: The user data.
292 gtk_tree_selection_get_user_data (GtkTreeSelection *selection)
294 g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), NULL);
296 return selection->user_data;
300 * gtk_tree_selection_get_tree_view:
301 * @selection: A #GtkTreeSelection
303 * Returns the tree view associated with @selection.
305 * Return value: A #GtkTreeView
308 gtk_tree_selection_get_tree_view (GtkTreeSelection *selection)
310 g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), NULL);
312 return selection->tree_view;
316 * gtk_tree_selection_get_selected:
317 * @selection: A #GtkTreeSelection.
318 * @model: A pointer set to the #GtkTreeModel, or NULL.
319 * @iter: The #GtkTreeIter, or NULL.
321 * Sets @iter to the currently selected node if @selection is set to
322 * #GTK_SELECTION_SINGLE or #GTK_SELECTION_BROWSE. @iter may be NULL if you
323 * just want to test if @selection has any selected nodes. @model is filled
324 * with the current model as a convenience. This function will not work if you
325 * use @selection is #GTK_SELECTION_MULTIPLE.
327 * Return value: TRUE, if there is a selected node.
330 gtk_tree_selection_get_selected (GtkTreeSelection *selection,
331 GtkTreeModel **model,
336 GtkTreePath *anchor_path;
339 g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), FALSE);
340 g_return_val_if_fail (selection->type != GTK_SELECTION_MULTIPLE, FALSE);
341 g_return_val_if_fail (selection->tree_view != NULL, FALSE);
342 g_return_val_if_fail (selection->tree_view->priv->model != NULL, FALSE);
345 *model = selection->tree_view->priv->model;
347 if (selection->tree_view->priv->anchor == NULL)
350 anchor_path = gtk_tree_row_reference_get_path (selection->tree_view->priv->anchor);
352 if (anchor_path == NULL)
357 gtk_tree_path_free (anchor_path);
363 if (!_gtk_tree_view_find_node (selection->tree_view,
367 ! GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
369 /* We don't want to return the anchor if it isn't actually selected.
375 retval = gtk_tree_model_get_iter (selection->tree_view->priv->model,
380 gtk_tree_path_free (anchor_path);
386 * gtk_tree_selection_selected_foreach:
387 * @selection: A #GtkTreeSelection.
388 * @func: The function to call for each selected node.
389 * @data: user data to pass to the function.
391 * Calls a function for each selected node.
394 gtk_tree_selection_selected_foreach (GtkTreeSelection *selection,
395 GtkTreeSelectionForeachFunc func,
403 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
404 g_return_if_fail (selection->tree_view != NULL);
405 g_return_if_fail (selection->tree_view->priv->model != NULL);
408 selection->tree_view->priv->tree == NULL ||
409 selection->tree_view->priv->tree->root == NULL)
412 if (selection->type == GTK_SELECTION_SINGLE ||
413 selection->type == GTK_SELECTION_BROWSE)
415 if (gtk_tree_row_reference_valid (selection->tree_view->priv->anchor))
417 path = gtk_tree_row_reference_get_path (selection->tree_view->priv->anchor);
418 gtk_tree_model_get_iter (selection->tree_view->priv->model, &iter, path);
419 (* func) (selection->tree_view->priv->model, path, &iter, data);
420 gtk_tree_path_free (path);
425 tree = selection->tree_view->priv->tree;
426 node = selection->tree_view->priv->tree->root;
428 while (node->left != tree->nil)
431 /* find the node internally */
432 path = gtk_tree_path_new_root ();
433 gtk_tree_model_get_iter (selection->tree_view->priv->model,
438 if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
439 (* func) (selection->tree_view->priv->model, path, &iter, data);
445 tree = node->children;
447 while (node->left != tree->nil)
450 has_child = gtk_tree_model_iter_children (selection->tree_view->priv->model, &iter, &tmp);
451 gtk_tree_path_append_index (path, 0);
453 TREE_VIEW_INTERNAL_ASSERT_VOID (has_child);
457 gboolean done = FALSE;
460 node = _gtk_rbtree_next (tree, node);
465 has_next = gtk_tree_model_iter_next (selection->tree_view->priv->model, &iter);
467 gtk_tree_path_next (path);
470 TREE_VIEW_INTERNAL_ASSERT_VOID (has_next);
475 GtkTreeIter tmp_iter = iter;
477 node = tree->parent_node;
478 tree = tree->parent_tree;
481 gtk_tree_path_free (path);
482 /* we've run out of tree */
483 /* We're done with this function */
486 has_parent = gtk_tree_model_iter_parent (selection->tree_view->priv->model, &iter, &tmp_iter);
487 gtk_tree_path_up (path);
489 TREE_VIEW_INTERNAL_ASSERT_VOID (has_parent);
499 * gtk_tree_selection_select_path:
500 * @selection: A #GtkTreeSelection.
501 * @path: The #GtkTreePath to be selected.
503 * Select the row at @path.
506 gtk_tree_selection_select_path (GtkTreeSelection *selection,
511 GdkModifierType state = 0;
513 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
514 g_return_if_fail (selection->tree_view != NULL);
515 g_return_if_fail (path != NULL);
517 _gtk_tree_view_find_node (selection->tree_view,
522 if (node == NULL || GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
525 if (selection->type == GTK_SELECTION_MULTIPLE)
526 state = GDK_CONTROL_MASK;
528 _gtk_tree_selection_internal_select_node (selection,
536 * gtk_tree_selection_unselect_path:
537 * @selection: A #GtkTreeSelection.
538 * @path: The #GtkTreePath to be unselected.
540 * Unselects the row at @path.
543 gtk_tree_selection_unselect_path (GtkTreeSelection *selection,
549 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
550 g_return_if_fail (selection->tree_view != NULL);
551 g_return_if_fail (path != NULL);
553 _gtk_tree_view_find_node (selection->tree_view,
558 if (node == NULL || !GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
561 _gtk_tree_selection_internal_select_node (selection,
569 * gtk_tree_selection_select_iter:
570 * @selection: A #GtkTreeSelection.
571 * @iter: The #GtkTreeIter to be selected.
573 * Selects the specified iterator.
576 gtk_tree_selection_select_iter (GtkTreeSelection *selection,
581 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
582 g_return_if_fail (selection->tree_view != NULL);
583 g_return_if_fail (selection->tree_view->priv->model != NULL);
584 g_return_if_fail (iter != NULL);
586 path = gtk_tree_model_get_path (selection->tree_view->priv->model,
592 gtk_tree_selection_select_path (selection, path);
593 gtk_tree_path_free (path);
598 * gtk_tree_selection_unselect_iter:
599 * @selection: A #GtkTreeSelection.
600 * @iter: The #GtkTreeIter to be unselected.
602 * Unselects the specified iterator.
605 gtk_tree_selection_unselect_iter (GtkTreeSelection *selection,
610 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
611 g_return_if_fail (selection->tree_view != NULL);
612 g_return_if_fail (selection->tree_view->priv->model != NULL);
613 g_return_if_fail (iter != NULL);
615 path = gtk_tree_model_get_path (selection->tree_view->priv->model,
621 gtk_tree_selection_select_path (selection, path);
622 gtk_tree_path_free (path);
626 * gtk_tree_selection_path_is_selected:
627 * @selection: A #GtkTreeSelection.
628 * @path: A #GtkTreePath to check selection on.
630 * Returns %TRUE if the row pointed to by @path is currently selected. If @path
631 * does not point to a valid location, %FALSE is returned
633 * Return value: %TRUE if @path is selected.
636 gtk_tree_selection_path_is_selected (GtkTreeSelection *selection,
642 g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), FALSE);
643 g_return_val_if_fail (path != NULL, FALSE);
644 g_return_val_if_fail (selection->tree_view != NULL, FALSE);
645 g_return_val_if_fail (selection->tree_view->priv->model != NULL, FALSE);
647 _gtk_tree_view_find_node (selection->tree_view,
652 if ((node == NULL) || !GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
659 * gtk_tree_selection_iter_is_selected:
660 * @selection: A #GtkTreeSelection
661 * @iter: A valid #GtkTreeIter
663 * Returns %TRUE if the row pointed to by @path is currently selected.
665 * Return value: %TRUE, if @iter is selected
668 gtk_tree_selection_iter_is_selected (GtkTreeSelection *selection,
674 g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), FALSE);
675 g_return_val_if_fail (iter != NULL, FALSE);
676 g_return_val_if_fail (selection->tree_view != NULL, FALSE);
677 g_return_val_if_fail (selection->tree_view->priv->model != NULL, FALSE);
679 path = gtk_tree_model_get_path (selection->tree_view->priv->model, iter);
683 retval = gtk_tree_selection_path_is_selected (selection, path);
684 gtk_tree_path_free (path);
690 /* Wish I was in python, right now... */
692 GtkTreeSelection *selection;
697 select_all_helper (GtkRBTree *tree,
701 struct _TempTuple *tuple = data;
704 _gtk_rbtree_traverse (node->children,
705 node->children->root,
709 if (!GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
711 tuple->dirty = gtk_tree_selection_real_select_node (tuple->selection, tree, node, TRUE) || tuple->dirty;
716 /* We have a real_{un,}select_all function that doesn't emit the signal, so we
717 * can use it in other places without fear of the signal being emitted.
720 gtk_tree_selection_real_select_all (GtkTreeSelection *selection)
722 struct _TempTuple *tuple;
724 if (selection->tree_view->priv->tree == NULL)
727 /* Mark all nodes selected */
728 tuple = g_new (struct _TempTuple, 1);
729 tuple->selection = selection;
730 tuple->dirty = FALSE;
732 _gtk_rbtree_traverse (selection->tree_view->priv->tree,
733 selection->tree_view->priv->tree->root,
747 * gtk_tree_selection_select_all:
748 * @selection: A #GtkTreeSelection.
750 * Selects all the nodes. @selection is must be set to #GTK_SELECTION_MULTIPLE
754 gtk_tree_selection_select_all (GtkTreeSelection *selection)
756 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
757 g_return_if_fail (selection->tree_view != NULL);
758 if (selection->tree_view->priv->tree == NULL)
760 g_return_if_fail (selection->type == GTK_SELECTION_MULTIPLE);
762 if (gtk_tree_selection_real_select_all (selection))
763 g_signal_emit (G_OBJECT (selection), tree_selection_signals[CHANGED], 0);
767 unselect_all_helper (GtkRBTree *tree,
771 struct _TempTuple *tuple = data;
774 _gtk_rbtree_traverse (node->children,
775 node->children->root,
779 if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
781 tuple->dirty = gtk_tree_selection_real_select_node (tuple->selection, tree, node, FALSE) || tuple->dirty;
786 gtk_tree_selection_real_unselect_all (GtkTreeSelection *selection)
788 struct _TempTuple *tuple;
790 if (selection->type == GTK_SELECTION_SINGLE ||
791 selection->type == GTK_SELECTION_BROWSE)
793 GtkRBTree *tree = NULL;
794 GtkRBNode *node = NULL;
795 GtkTreePath *anchor_path;
797 if (selection->tree_view->priv->anchor == NULL)
800 anchor_path = gtk_tree_row_reference_get_path (selection->tree_view->priv->anchor);
802 if (anchor_path == NULL)
805 _gtk_tree_view_find_node (selection->tree_view,
810 gtk_tree_path_free (anchor_path);
815 if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
817 if (gtk_tree_selection_real_select_node (selection, tree, node, FALSE))
819 gtk_tree_row_reference_free (selection->tree_view->priv->anchor);
820 selection->tree_view->priv->anchor = NULL;
828 tuple = g_new (struct _TempTuple, 1);
829 tuple->selection = selection;
830 tuple->dirty = FALSE;
832 _gtk_rbtree_traverse (selection->tree_view->priv->tree,
833 selection->tree_view->priv->tree->root,
849 * gtk_tree_selection_unselect_all:
850 * @selection: A #GtkTreeSelection.
852 * Unselects all the nodes.
855 gtk_tree_selection_unselect_all (GtkTreeSelection *selection)
857 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
858 g_return_if_fail (selection->tree_view != NULL);
859 if (selection->tree_view->priv->tree == NULL)
862 if (selection->tree_view->priv->tree == NULL)
865 if (gtk_tree_selection_real_unselect_all (selection))
866 g_signal_emit (G_OBJECT (selection), tree_selection_signals[CHANGED], 0);
870 gtk_tree_selection_real_select_range (GtkTreeSelection *selection,
871 GtkTreePath *start_path,
872 GtkTreePath *end_path)
874 GtkRBNode *start_node, *end_node;
875 GtkRBTree *start_tree, *end_tree;
876 gboolean dirty = FALSE;
878 switch (gtk_tree_path_compare (start_path, end_path))
881 _gtk_tree_view_find_node (selection->tree_view,
885 _gtk_tree_view_find_node (selection->tree_view,
891 _gtk_tree_view_find_node (selection->tree_view,
895 end_tree = start_tree;
896 end_node = start_node;
899 _gtk_tree_view_find_node (selection->tree_view,
903 _gtk_tree_view_find_node (selection->tree_view,
910 g_return_val_if_fail (start_node != NULL, FALSE);
911 g_return_val_if_fail (end_node != NULL, FALSE);
915 dirty |= gtk_tree_selection_real_select_node (selection, start_tree, start_node, TRUE);
917 if (start_node == end_node)
920 if (start_node->children)
922 start_tree = start_node->children;
923 start_node = start_tree->root;
924 while (start_node->left != start_tree->nil)
925 start_node = start_node->left;
929 _gtk_rbtree_next_full (start_tree, start_node, &start_tree, &start_node);
930 if (start_tree == NULL)
932 /* we just ran out of tree. That means someone passed in bogus values.
944 * gtk_tree_selection_select_range:
945 * @selection: A #GtkTreeSelection.
946 * @start_path: The initial node of the range.
947 * @end_path: The final node of the range.
949 * Selects a range of nodes, determined by @start_path and @end_path inclusive.
952 gtk_tree_selection_select_range (GtkTreeSelection *selection,
953 GtkTreePath *start_path,
954 GtkTreePath *end_path)
956 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
957 g_return_if_fail (selection->tree_view != NULL);
959 if (gtk_tree_selection_real_select_range (selection, start_path, end_path))
960 g_signal_emit (G_OBJECT (selection), tree_selection_signals[CHANGED], 0);
963 /* Called internally by gtktreeview.c It handles actually selecting the tree.
966 _gtk_tree_selection_internal_select_node (GtkTreeSelection *selection,
970 GdkModifierType state)
974 GtkTreePath *anchor_path = NULL;
976 if (selection->type == GTK_SELECTION_NONE)
979 if (selection->tree_view->priv->anchor)
980 anchor_path = gtk_tree_row_reference_get_path (selection->tree_view->priv->anchor);
982 if (selection->type == GTK_SELECTION_SINGLE ||
983 selection->type == GTK_SELECTION_BROWSE)
985 /* Did we try to select the same node again? */
986 if (selection->type == GTK_SELECTION_SINGLE &&
987 anchor_path && gtk_tree_path_compare (path, anchor_path) == 0)
989 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
991 dirty = gtk_tree_selection_real_unselect_all (selection);
996 /* FIXME: We only want to select the new node if we can unselect the
997 * old one, and we can select the new one. We are currently
998 * unselecting the old one first, then trying the new one. */
1001 dirty = gtk_tree_selection_real_unselect_all (selection);
1004 if (selection->tree_view->priv->anchor)
1005 gtk_tree_row_reference_free (selection->tree_view->priv->anchor);
1006 if (gtk_tree_selection_real_select_node (selection, tree, node, TRUE))
1008 selection->tree_view->priv->anchor =
1009 gtk_tree_row_reference_new_proxy (G_OBJECT (selection->tree_view), selection->tree_view->priv->model, path);
1015 if (gtk_tree_selection_real_select_node (selection, tree, node, TRUE))
1018 selection->tree_view->priv->anchor =
1019 gtk_tree_row_reference_new_proxy (G_OBJECT (selection->tree_view), selection->tree_view->priv->model, path);
1024 else if (selection->type == GTK_SELECTION_MULTIPLE)
1026 if (((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK) && (anchor_path == NULL))
1028 if (selection->tree_view->priv->anchor)
1029 gtk_tree_row_reference_free (selection->tree_view->priv->anchor);
1031 selection->tree_view->priv->anchor =
1032 gtk_tree_row_reference_new_proxy (G_OBJECT (selection->tree_view), selection->tree_view->priv->model, path);
1033 dirty = gtk_tree_selection_real_select_node (selection, tree, node, TRUE);
1035 else if ((state & (GDK_CONTROL_MASK|GDK_SHIFT_MASK)) == (GDK_SHIFT_MASK|GDK_CONTROL_MASK))
1037 gtk_tree_selection_select_range (selection,
1041 else if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
1043 flags = node->flags;
1044 if (selection->tree_view->priv->anchor)
1045 gtk_tree_row_reference_free (selection->tree_view->priv->anchor);
1047 selection->tree_view->priv->anchor =
1048 gtk_tree_row_reference_new_proxy (G_OBJECT (selection->tree_view), selection->tree_view->priv->model, path);
1050 if ((flags & GTK_RBNODE_IS_SELECTED) == GTK_RBNODE_IS_SELECTED)
1051 dirty |= gtk_tree_selection_real_select_node (selection, tree, node, FALSE);
1053 dirty |= gtk_tree_selection_real_select_node (selection, tree, node, TRUE);
1055 else if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
1057 dirty = gtk_tree_selection_real_unselect_all (selection);
1058 dirty |= gtk_tree_selection_real_select_range (selection,
1064 dirty = gtk_tree_selection_real_unselect_all (selection);
1066 if (selection->tree_view->priv->anchor)
1067 gtk_tree_row_reference_free (selection->tree_view->priv->anchor);
1069 selection->tree_view->priv->anchor =
1070 gtk_tree_row_reference_new_proxy (G_OBJECT (selection->tree_view), selection->tree_view->priv->model, path);
1072 dirty |= gtk_tree_selection_real_select_node (selection, tree, node, TRUE);
1077 gtk_tree_path_free (anchor_path);
1080 g_signal_emit (G_OBJECT (selection), tree_selection_signals[CHANGED], 0);
1083 /* NOTE: Any {un,}selection ever done _MUST_ be done through this function!
1087 gtk_tree_selection_real_select_node (GtkTreeSelection *selection,
1092 gboolean selected = FALSE;
1093 GtkTreePath *path = NULL;
1095 if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED) != select)
1097 path = _gtk_tree_view_find_path (selection->tree_view, tree, node);
1098 if (selection->user_func)
1100 if ((*selection->user_func) (selection, selection->tree_view->priv->model, path,
1101 GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED),
1102 selection->user_data))
1107 gtk_tree_path_free (path);
1110 if (selected == TRUE)
1112 node->flags ^= GTK_RBNODE_IS_SELECTED;
1114 /* FIXME: just draw the one node*/
1115 gtk_widget_queue_draw (GTK_WIDGET (selection->tree_view));