1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser 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 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser 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.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
27 #undef GTK_DISABLE_DEPRECATED
31 #include "gtkmarshalers.h"
32 #include "gtksignal.h"
35 #define GTK_ENABLE_BROKEN
37 #include "gtktreeitem.h"
49 static void gtk_tree_class_init (GtkTreeClass *klass);
50 static void gtk_tree_init (GtkTree *tree);
51 static void gtk_tree_destroy (GtkObject *object);
52 static void gtk_tree_map (GtkWidget *widget);
53 static void gtk_tree_parent_set (GtkWidget *widget,
54 GtkWidget *previous_parent);
55 static void gtk_tree_unmap (GtkWidget *widget);
56 static void gtk_tree_realize (GtkWidget *widget);
57 static gint gtk_tree_motion_notify (GtkWidget *widget,
58 GdkEventMotion *event);
59 static gint gtk_tree_button_press (GtkWidget *widget,
60 GdkEventButton *event);
61 static gint gtk_tree_button_release (GtkWidget *widget,
62 GdkEventButton *event);
63 static void gtk_tree_size_request (GtkWidget *widget,
64 GtkRequisition *requisition);
65 static void gtk_tree_size_allocate (GtkWidget *widget,
66 GtkAllocation *allocation);
67 static void gtk_tree_add (GtkContainer *container,
69 static void gtk_tree_forall (GtkContainer *container,
70 gboolean include_internals,
72 gpointer callback_data);
74 static void gtk_real_tree_select_child (GtkTree *tree,
76 static void gtk_real_tree_unselect_child (GtkTree *tree,
79 static GtkType gtk_tree_child_type (GtkContainer *container);
81 static GtkContainerClass *parent_class = NULL;
82 static guint tree_signals[LAST_SIGNAL] = { 0 };
85 gtk_tree_get_type (void)
87 static GtkType tree_type = 0;
91 static const GtkTypeInfo tree_info =
95 sizeof (GtkTreeClass),
96 (GtkClassInitFunc) gtk_tree_class_init,
97 (GtkObjectInitFunc) gtk_tree_init,
98 /* reserved_1 */ NULL,
99 /* reserved_2 */ NULL,
100 (GtkClassInitFunc) NULL,
104 tree_type = gtk_type_unique (gtk_container_get_type (), &tree_info);
111 gtk_tree_class_init (GtkTreeClass *class)
113 GtkObjectClass *object_class;
114 GtkWidgetClass *widget_class;
115 GtkContainerClass *container_class;
117 object_class = (GtkObjectClass*) class;
118 widget_class = (GtkWidgetClass*) class;
119 container_class = (GtkContainerClass*) class;
121 parent_class = gtk_type_class (gtk_container_get_type ());
124 object_class->destroy = gtk_tree_destroy;
126 widget_class->map = gtk_tree_map;
127 widget_class->unmap = gtk_tree_unmap;
128 widget_class->parent_set = gtk_tree_parent_set;
129 widget_class->realize = gtk_tree_realize;
130 widget_class->motion_notify_event = gtk_tree_motion_notify;
131 widget_class->button_press_event = gtk_tree_button_press;
132 widget_class->button_release_event = gtk_tree_button_release;
133 widget_class->size_request = gtk_tree_size_request;
134 widget_class->size_allocate = gtk_tree_size_allocate;
136 container_class->add = gtk_tree_add;
137 container_class->remove =
138 (void (*)(GtkContainer *, GtkWidget *)) gtk_tree_remove_item;
139 container_class->forall = gtk_tree_forall;
140 container_class->child_type = gtk_tree_child_type;
142 class->selection_changed = NULL;
143 class->select_child = gtk_real_tree_select_child;
144 class->unselect_child = gtk_real_tree_unselect_child;
146 tree_signals[SELECTION_CHANGED] =
147 gtk_signal_new (I_("selection-changed"),
149 GTK_CLASS_TYPE (object_class),
150 GTK_SIGNAL_OFFSET (GtkTreeClass, selection_changed),
151 _gtk_marshal_VOID__VOID,
153 tree_signals[SELECT_CHILD] =
154 gtk_signal_new (I_("select-child"),
156 GTK_CLASS_TYPE (object_class),
157 GTK_SIGNAL_OFFSET (GtkTreeClass, select_child),
158 _gtk_marshal_VOID__OBJECT,
161 tree_signals[UNSELECT_CHILD] =
162 gtk_signal_new (I_("unselect-child"),
164 GTK_CLASS_TYPE (object_class),
165 GTK_SIGNAL_OFFSET (GtkTreeClass, unselect_child),
166 _gtk_marshal_VOID__OBJECT,
172 gtk_tree_child_type (GtkContainer *container)
174 return GTK_TYPE_TREE_ITEM;
178 gtk_tree_init (GtkTree *tree)
180 tree->children = NULL;
181 tree->root_tree = tree;
182 tree->selection = NULL;
183 tree->tree_owner = NULL;
184 tree->selection_mode = GTK_SELECTION_SINGLE;
185 tree->indent_value = 9;
186 tree->current_indent = 0;
188 tree->view_mode = GTK_TREE_VIEW_LINE;
189 tree->view_line = TRUE;
195 return GTK_WIDGET (gtk_type_new (gtk_tree_get_type ()));
199 gtk_tree_append (GtkTree *tree,
200 GtkWidget *tree_item)
202 g_return_if_fail (GTK_IS_TREE (tree));
203 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
205 gtk_tree_insert (tree, tree_item, -1);
209 gtk_tree_prepend (GtkTree *tree,
210 GtkWidget *tree_item)
212 g_return_if_fail (GTK_IS_TREE (tree));
213 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
215 gtk_tree_insert (tree, tree_item, 0);
219 gtk_tree_insert (GtkTree *tree,
220 GtkWidget *tree_item,
225 g_return_if_fail (GTK_IS_TREE (tree));
226 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
228 nchildren = g_list_length (tree->children);
230 if ((position < 0) || (position > nchildren))
231 position = nchildren;
233 if (position == nchildren)
234 tree->children = g_list_append (tree->children, tree_item);
236 tree->children = g_list_insert (tree->children, tree_item, position);
238 gtk_widget_set_parent (tree_item, GTK_WIDGET (tree));
242 gtk_tree_add (GtkContainer *container,
247 g_return_if_fail (GTK_IS_TREE (container));
248 g_return_if_fail (GTK_IS_TREE_ITEM (child));
250 tree = GTK_TREE (container);
252 tree->children = g_list_append (tree->children, child);
254 gtk_widget_set_parent (child, GTK_WIDGET (container));
256 if (!tree->selection && (tree->selection_mode == GTK_SELECTION_BROWSE))
257 gtk_tree_select_child (tree, child);
261 gtk_tree_button_press (GtkWidget *widget,
262 GdkEventButton *event)
267 g_return_val_if_fail (GTK_IS_TREE (widget), FALSE);
268 g_return_val_if_fail (event != NULL, FALSE);
270 tree = GTK_TREE (widget);
271 item = gtk_get_event_widget ((GdkEvent*) event);
273 while (item && !GTK_IS_TREE_ITEM (item))
276 if (!item || (item->parent != widget))
279 switch(event->button)
282 gtk_tree_select_child (tree, item);
285 if(GTK_TREE_ITEM(item)->subtree) gtk_tree_item_expand(GTK_TREE_ITEM(item));
288 if(GTK_TREE_ITEM(item)->subtree) gtk_tree_item_collapse(GTK_TREE_ITEM(item));
296 gtk_tree_button_release (GtkWidget *widget,
297 GdkEventButton *event)
302 g_return_val_if_fail (GTK_IS_TREE (widget), FALSE);
303 g_return_val_if_fail (event != NULL, FALSE);
305 tree = GTK_TREE (widget);
306 item = gtk_get_event_widget ((GdkEvent*) event);
312 gtk_tree_child_position (GtkTree *tree,
319 g_return_val_if_fail (GTK_IS_TREE (tree), -1);
320 g_return_val_if_fail (child != NULL, -1);
323 children = tree->children;
327 if (child == GTK_WIDGET (children->data))
331 children = children->next;
339 gtk_tree_clear_items (GtkTree *tree,
349 g_return_if_fail (GTK_IS_TREE (tree));
351 nchildren = g_list_length (tree->children);
355 if ((end < 0) || (end > nchildren))
361 tmp_list = g_list_nth (tree->children, start);
364 while (tmp_list && index <= end)
366 widget = tmp_list->data;
367 tmp_list = tmp_list->next;
370 clear_list = g_list_prepend (clear_list, widget);
373 gtk_tree_remove_items (tree, clear_list);
378 gtk_tree_destroy (GtkObject *object)
384 g_return_if_fail (GTK_IS_TREE (object));
386 tree = GTK_TREE (object);
388 children = tree->children;
391 child = children->data;
392 children = children->next;
394 g_object_ref (child);
395 gtk_widget_unparent (child);
396 gtk_widget_destroy (child);
397 g_object_unref (child);
400 g_list_free (tree->children);
401 tree->children = NULL;
403 if (tree->root_tree == tree)
406 for (node = tree->selection; node; node = node->next)
407 g_object_unref (node->data);
408 g_list_free (tree->selection);
409 tree->selection = NULL;
412 GTK_OBJECT_CLASS (parent_class)->destroy (object);
416 gtk_tree_forall (GtkContainer *container,
417 gboolean include_internals,
418 GtkCallback callback,
419 gpointer callback_data)
426 g_return_if_fail (GTK_IS_TREE (container));
427 g_return_if_fail (callback != NULL);
429 tree = GTK_TREE (container);
430 children = tree->children;
434 child = children->data;
435 children = children->next;
437 (* callback) (child, callback_data);
442 gtk_tree_unselect_all (GtkTree *tree)
444 GList *tmp_list, *selection;
447 selection = tree->selection;
448 tree->selection = NULL;
450 tmp_list = selection;
453 tmp_item = selection->data;
455 if (tmp_item->parent &&
456 GTK_IS_TREE (tmp_item->parent) &&
457 GTK_TREE (tmp_item->parent)->root_tree == tree)
458 gtk_tree_item_deselect (GTK_TREE_ITEM (tmp_item));
460 g_object_unref (tmp_item);
462 tmp_list = tmp_list->next;
465 g_list_free (selection);
469 gtk_tree_parent_set (GtkWidget *widget,
470 GtkWidget *previous_parent)
472 GtkTree *tree = GTK_TREE (widget);
476 if (GTK_IS_TREE (widget->parent))
478 gtk_tree_unselect_all (tree);
480 /* set root tree for this tree */
481 tree->root_tree = GTK_TREE(widget->parent)->root_tree;
483 tree->level = GTK_TREE(GTK_WIDGET(tree)->parent)->level+1;
484 tree->indent_value = GTK_TREE(GTK_WIDGET(tree)->parent)->indent_value;
485 tree->current_indent = GTK_TREE(GTK_WIDGET(tree)->parent)->current_indent +
487 tree->view_mode = GTK_TREE(GTK_WIDGET(tree)->parent)->view_mode;
488 tree->view_line = GTK_TREE(GTK_WIDGET(tree)->parent)->view_line;
492 tree->root_tree = tree;
495 tree->current_indent = 0;
498 children = tree->children;
501 child = children->data;
502 children = children->next;
504 if (GTK_TREE_ITEM (child)->subtree)
505 gtk_tree_parent_set (GTK_TREE_ITEM (child)->subtree, child);
510 gtk_tree_map (GtkWidget *widget)
512 GtkTree *tree = GTK_TREE (widget);
516 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
518 children = tree->children;
521 child = children->data;
522 children = children->next;
524 if (gtk_widget_get_visible (child) &&
525 !GTK_WIDGET_MAPPED (child))
526 gtk_widget_map (child);
528 if (GTK_TREE_ITEM (child)->subtree)
530 child = GTK_WIDGET (GTK_TREE_ITEM (child)->subtree);
532 if (gtk_widget_get_visible (child) && !GTK_WIDGET_MAPPED (child))
533 gtk_widget_map (child);
537 gdk_window_show (widget->window);
541 gtk_tree_motion_notify (GtkWidget *widget,
542 GdkEventMotion *event)
544 g_return_val_if_fail (GTK_IS_TREE (widget), FALSE);
545 g_return_val_if_fail (event != NULL, FALSE);
548 g_message("gtk_tree_motion_notify\n");
549 #endif /* TREE_DEBUG */
555 gtk_tree_realize (GtkWidget *widget)
557 GdkWindowAttr attributes;
558 gint attributes_mask;
561 g_return_if_fail (GTK_IS_TREE (widget));
563 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
565 attributes.window_type = GDK_WINDOW_CHILD;
566 attributes.x = widget->allocation.x;
567 attributes.y = widget->allocation.y;
568 attributes.width = widget->allocation.width;
569 attributes.height = widget->allocation.height;
570 attributes.wclass = GDK_INPUT_OUTPUT;
571 attributes.visual = gtk_widget_get_visual (widget);
572 attributes.colormap = gtk_widget_get_colormap (widget);
573 attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
575 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
577 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
578 gdk_window_set_user_data (widget->window, widget);
580 widget->style = gtk_style_attach (widget->style, widget->window);
581 gdk_window_set_background (widget->window,
582 &widget->style->base[GTK_STATE_NORMAL]);
586 gtk_tree_remove_item (GtkTree *container,
591 g_return_if_fail (GTK_IS_TREE (container));
592 g_return_if_fail (widget != NULL);
593 g_return_if_fail (container == GTK_TREE (widget->parent));
595 item_list = g_list_append (NULL, widget);
597 gtk_tree_remove_items (GTK_TREE (container), item_list);
599 g_list_free (item_list);
602 /* used by gtk_tree_remove_items to make the function independent of
603 order in list of items to remove.
604 Sort item by depth in tree */
606 gtk_tree_sort_item_by_depth(GtkWidget* a, GtkWidget* b)
608 if((GTK_TREE(a->parent)->level) < (GTK_TREE(b->parent)->level))
610 if((GTK_TREE(a->parent)->level) > (GTK_TREE(b->parent)->level))
617 gtk_tree_remove_items (GtkTree *tree,
621 GList *selected_widgets;
627 g_return_if_fail (GTK_IS_TREE (tree));
630 g_message("+ gtk_tree_remove_items [ tree %#x items list %#x ]\n", (int)tree, (int)items);
631 #endif /* TREE_DEBUG */
633 /* We may not yet be mapped, so we actively have to find our
637 root_tree = tree->root_tree;
640 GtkWidget *tmp = GTK_WIDGET (tree);
641 while (GTK_IS_TREE (tmp->parent))
644 root_tree = GTK_TREE (tmp);
648 selected_widgets = NULL;
653 g_message("* sort list by depth\n");
654 #endif /* TREE_DEBUG */
660 g_message ("* item [%#x] depth [%d]\n",
662 (int)GTK_TREE(GTK_WIDGET(tmp_list->data)->parent)->level);
663 #endif /* TREE_DEBUG */
665 sorted_list = g_list_insert_sorted(sorted_list,
667 (GCompareFunc)gtk_tree_sort_item_by_depth);
668 tmp_list = g_list_next(tmp_list);
672 /* print sorted list */
673 g_message("* sorted list result\n");
674 tmp_list = sorted_list;
677 g_message("* item [%#x] depth [%d]\n",
679 (int)GTK_TREE(GTK_WIDGET(tmp_list->data)->parent)->level);
680 tmp_list = g_list_next(tmp_list);
682 #endif /* TREE_DEBUG */
685 g_message("* scan sorted list\n");
686 #endif /* TREE_DEBUG */
688 tmp_list = sorted_list;
691 widget = tmp_list->data;
692 tmp_list = tmp_list->next;
695 g_message("* item [%#x] subtree [%#x]\n",
696 (int)widget, (int)GTK_TREE_ITEM_SUBTREE(widget));
697 #endif /* TREE_DEBUG */
699 /* get real owner of this widget */
700 real_tree = GTK_TREE(widget->parent);
702 g_message("* subtree having this widget [%#x]\n", (int)real_tree);
703 #endif /* TREE_DEBUG */
706 if (widget->state == GTK_STATE_SELECTED)
708 selected_widgets = g_list_prepend (selected_widgets, widget);
710 g_message("* selected widget - adding it in selected list [%#x]\n",
711 (int)selected_widgets);
712 #endif /* TREE_DEBUG */
715 /* remove this item from its real parent */
717 g_message("* remove widget from its owner tree\n");
718 #endif /* TREE_DEBUG */
719 real_tree->children = g_list_remove (real_tree->children, widget);
721 /* remove subtree associate at this item if it exist */
722 if(GTK_TREE_ITEM(widget)->subtree)
725 g_message("* remove subtree associate at this item [%#x]\n",
726 (int) GTK_TREE_ITEM(widget)->subtree);
727 #endif /* TREE_DEBUG */
728 if (GTK_WIDGET_MAPPED (GTK_TREE_ITEM(widget)->subtree))
729 gtk_widget_unmap (GTK_TREE_ITEM(widget)->subtree);
731 gtk_widget_unparent (GTK_TREE_ITEM(widget)->subtree);
732 GTK_TREE_ITEM(widget)->subtree = NULL;
735 /* really remove widget for this item */
737 g_message("* unmap and unparent widget [%#x]\n", (int)widget);
738 #endif /* TREE_DEBUG */
739 if (GTK_WIDGET_MAPPED (widget))
740 gtk_widget_unmap (widget);
742 gtk_widget_unparent (widget);
744 /* delete subtree if there is no children in it */
745 if(real_tree->children == NULL &&
746 real_tree != root_tree)
749 g_message("* owner tree don't have children ... destroy it\n");
750 #endif /* TREE_DEBUG */
751 gtk_tree_item_remove_subtree(GTK_TREE_ITEM(real_tree->tree_owner));
755 g_message("* next item in list\n");
756 #endif /* TREE_DEBUG */
759 if (selected_widgets)
762 g_message("* scan selected item list\n");
763 #endif /* TREE_DEBUG */
764 tmp_list = selected_widgets;
767 widget = tmp_list->data;
768 tmp_list = tmp_list->next;
771 g_message("* widget [%#x] subtree [%#x]\n",
772 (int)widget, (int)GTK_TREE_ITEM_SUBTREE(widget));
773 #endif /* TREE_DEBUG */
775 /* remove widget of selection */
776 root_tree->selection = g_list_remove (root_tree->selection, widget);
778 /* unref it to authorize is destruction */
779 g_object_unref (widget);
782 /* emit only one selection_changed signal */
783 gtk_signal_emit (GTK_OBJECT (root_tree),
784 tree_signals[SELECTION_CHANGED]);
788 g_message("* free selected_widgets list\n");
789 #endif /* TREE_DEBUG */
790 g_list_free (selected_widgets);
791 g_list_free (sorted_list);
793 if (root_tree->children && !root_tree->selection &&
794 (root_tree->selection_mode == GTK_SELECTION_BROWSE))
797 g_message("* BROWSE mode, select another item\n");
798 #endif /* TREE_DEBUG */
799 widget = root_tree->children->data;
800 gtk_tree_select_child (root_tree, widget);
803 if (gtk_widget_get_visible (GTK_WIDGET (root_tree)))
806 g_message("* query queue resizing for root_tree\n");
807 #endif /* TREE_DEBUG */
808 gtk_widget_queue_resize (GTK_WIDGET (root_tree));
813 gtk_tree_select_child (GtkTree *tree,
814 GtkWidget *tree_item)
816 g_return_if_fail (GTK_IS_TREE (tree));
817 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
819 gtk_signal_emit (GTK_OBJECT (tree), tree_signals[SELECT_CHILD], tree_item);
823 gtk_tree_select_item (GtkTree *tree,
828 g_return_if_fail (GTK_IS_TREE (tree));
830 tmp_list = g_list_nth (tree->children, item);
832 gtk_tree_select_child (tree, GTK_WIDGET (tmp_list->data));
837 gtk_tree_size_allocate (GtkWidget *widget,
838 GtkAllocation *allocation)
841 GtkWidget *child, *subtree;
842 GtkAllocation child_allocation;
846 g_return_if_fail (GTK_IS_TREE (widget));
847 g_return_if_fail (allocation != NULL);
849 tree = GTK_TREE (widget);
851 widget->allocation = *allocation;
852 if (GTK_WIDGET_REALIZED (widget))
853 gdk_window_move_resize (widget->window,
854 allocation->x, allocation->y,
855 allocation->width, allocation->height);
859 child_allocation.x = GTK_CONTAINER (tree)->border_width;
860 child_allocation.y = GTK_CONTAINER (tree)->border_width;
861 child_allocation.width = MAX (1, (gint)allocation->width - child_allocation.x * 2);
863 children = tree->children;
867 child = children->data;
868 children = children->next;
870 if (gtk_widget_get_visible (child))
872 GtkRequisition child_requisition;
873 gtk_widget_get_child_requisition (child, &child_requisition);
875 child_allocation.height = child_requisition.height;
877 gtk_widget_size_allocate (child, &child_allocation);
879 child_allocation.y += child_allocation.height;
881 if((subtree = GTK_TREE_ITEM(child)->subtree))
882 if(gtk_widget_get_visible (subtree))
884 child_allocation.height = subtree->requisition.height;
885 gtk_widget_size_allocate (subtree, &child_allocation);
886 child_allocation.y += child_allocation.height;
895 gtk_tree_size_request (GtkWidget *widget,
896 GtkRequisition *requisition)
899 GtkWidget *child, *subtree;
901 GtkRequisition child_requisition;
904 g_return_if_fail (GTK_IS_TREE (widget));
905 g_return_if_fail (requisition != NULL);
907 tree = GTK_TREE (widget);
908 requisition->width = 0;
909 requisition->height = 0;
911 children = tree->children;
914 child = children->data;
915 children = children->next;
917 if (gtk_widget_get_visible (child))
919 gtk_widget_size_request (child, &child_requisition);
921 requisition->width = MAX (requisition->width, child_requisition.width);
922 requisition->height += child_requisition.height;
924 if((subtree = GTK_TREE_ITEM(child)->subtree) &&
925 gtk_widget_get_visible (subtree))
927 gtk_widget_size_request (subtree, &child_requisition);
929 requisition->width = MAX (requisition->width,
930 child_requisition.width);
932 requisition->height += child_requisition.height;
937 requisition->width += GTK_CONTAINER (tree)->border_width * 2;
938 requisition->height += GTK_CONTAINER (tree)->border_width * 2;
940 requisition->width = MAX (requisition->width, 1);
941 requisition->height = MAX (requisition->height, 1);
946 gtk_tree_unmap (GtkWidget *widget)
949 g_return_if_fail (GTK_IS_TREE (widget));
951 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
952 gdk_window_hide (widget->window);
957 gtk_tree_unselect_child (GtkTree *tree,
958 GtkWidget *tree_item)
960 g_return_if_fail (GTK_IS_TREE (tree));
961 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
963 gtk_signal_emit (GTK_OBJECT (tree), tree_signals[UNSELECT_CHILD], tree_item);
967 gtk_tree_unselect_item (GtkTree *tree,
972 g_return_if_fail (GTK_IS_TREE (tree));
974 tmp_list = g_list_nth (tree->children, item);
976 gtk_tree_unselect_child (tree, GTK_WIDGET (tmp_list->data));
981 gtk_real_tree_select_child (GtkTree *tree,
984 GList *selection, *root_selection;
988 g_return_if_fail (GTK_IS_TREE (tree));
989 g_return_if_fail (GTK_IS_TREE_ITEM (child));
991 root_selection = tree->root_tree->selection;
993 switch (tree->root_tree->selection_mode)
995 case GTK_SELECTION_SINGLE:
997 selection = root_selection;
999 /* remove old selection list */
1002 tmp_item = selection->data;
1004 if (tmp_item != child)
1006 gtk_tree_item_deselect (GTK_TREE_ITEM (tmp_item));
1008 tmp_list = selection;
1009 selection = selection->next;
1011 root_selection = g_list_remove_link (root_selection, tmp_list);
1012 g_object_unref (tmp_item);
1014 g_list_free (tmp_list);
1017 selection = selection->next;
1020 if (child->state == GTK_STATE_NORMAL)
1022 gtk_tree_item_select (GTK_TREE_ITEM (child));
1023 root_selection = g_list_prepend (root_selection, child);
1024 g_object_ref (child);
1026 else if (child->state == GTK_STATE_SELECTED)
1028 gtk_tree_item_deselect (GTK_TREE_ITEM (child));
1029 root_selection = g_list_remove (root_selection, child);
1030 g_object_unref (child);
1033 tree->root_tree->selection = root_selection;
1035 gtk_signal_emit (GTK_OBJECT (tree->root_tree),
1036 tree_signals[SELECTION_CHANGED]);
1040 case GTK_SELECTION_BROWSE:
1041 selection = root_selection;
1045 tmp_item = selection->data;
1047 if (tmp_item != child)
1049 gtk_tree_item_deselect (GTK_TREE_ITEM (tmp_item));
1051 tmp_list = selection;
1052 selection = selection->next;
1054 root_selection = g_list_remove_link (root_selection, tmp_list);
1055 g_object_unref (tmp_item);
1057 g_list_free (tmp_list);
1060 selection = selection->next;
1063 tree->root_tree->selection = root_selection;
1065 if (child->state == GTK_STATE_NORMAL)
1067 gtk_tree_item_select (GTK_TREE_ITEM (child));
1068 root_selection = g_list_prepend (root_selection, child);
1069 g_object_ref (child);
1070 tree->root_tree->selection = root_selection;
1071 gtk_signal_emit (GTK_OBJECT (tree->root_tree),
1072 tree_signals[SELECTION_CHANGED]);
1076 case GTK_SELECTION_MULTIPLE:
1082 gtk_real_tree_unselect_child (GtkTree *tree,
1085 g_return_if_fail (GTK_IS_TREE (tree));
1086 g_return_if_fail (GTK_IS_TREE_ITEM (child));
1088 switch (tree->selection_mode)
1090 case GTK_SELECTION_SINGLE:
1091 case GTK_SELECTION_BROWSE:
1092 if (child->state == GTK_STATE_SELECTED)
1094 GtkTree* root_tree = GTK_TREE_ROOT_TREE(tree);
1095 gtk_tree_item_deselect (GTK_TREE_ITEM (child));
1096 root_tree->selection = g_list_remove (root_tree->selection, child);
1097 g_object_unref (child);
1098 gtk_signal_emit (GTK_OBJECT (tree->root_tree),
1099 tree_signals[SELECTION_CHANGED]);
1103 case GTK_SELECTION_MULTIPLE:
1109 gtk_tree_set_selection_mode (GtkTree *tree,
1110 GtkSelectionMode mode)
1112 g_return_if_fail (GTK_IS_TREE (tree));
1114 tree->selection_mode = mode;
1118 gtk_tree_set_view_mode (GtkTree *tree,
1119 GtkTreeViewMode mode)
1121 g_return_if_fail (GTK_IS_TREE (tree));
1123 tree->view_mode = mode;
1127 gtk_tree_set_view_lines (GtkTree *tree,
1130 g_return_if_fail (GTK_IS_TREE (tree));
1132 tree->view_line = flag;
1135 #define __GTK_TREE_C__
1136 #include "gtkaliasdef.c"