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/.
28 #include "gtktreeitem.h"
30 #include "gtksignal.h"
40 static void gtk_tree_class_init (GtkTreeClass *klass);
41 static void gtk_tree_init (GtkTree *tree);
42 static void gtk_tree_destroy (GtkObject *object);
43 static void gtk_tree_map (GtkWidget *widget);
44 static void gtk_tree_unmap (GtkWidget *widget);
45 static void gtk_tree_realize (GtkWidget *widget);
46 static gint gtk_tree_expose (GtkWidget *widget,
47 GdkEventExpose *event);
48 static gint gtk_tree_motion_notify (GtkWidget *widget,
49 GdkEventMotion *event);
50 static gint gtk_tree_button_press (GtkWidget *widget,
51 GdkEventButton *event);
52 static gint gtk_tree_button_release (GtkWidget *widget,
53 GdkEventButton *event);
54 static void gtk_tree_size_request (GtkWidget *widget,
55 GtkRequisition *requisition);
56 static void gtk_tree_size_allocate (GtkWidget *widget,
57 GtkAllocation *allocation);
58 static void gtk_tree_add (GtkContainer *container,
60 static void gtk_tree_forall (GtkContainer *container,
61 gboolean include_internals,
63 gpointer callback_data);
65 static void gtk_real_tree_select_child (GtkTree *tree,
67 static void gtk_real_tree_unselect_child (GtkTree *tree,
70 static GtkType gtk_tree_child_type (GtkContainer *container);
72 static GtkContainerClass *parent_class = NULL;
73 static guint tree_signals[LAST_SIGNAL] = { 0 };
76 gtk_tree_get_type (void)
78 static GtkType tree_type = 0;
82 static const GtkTypeInfo tree_info =
86 sizeof (GtkTreeClass),
87 (GtkClassInitFunc) gtk_tree_class_init,
88 (GtkObjectInitFunc) gtk_tree_init,
89 /* reserved_1 */ NULL,
90 /* reserved_2 */ NULL,
91 (GtkClassInitFunc) NULL,
94 tree_type = gtk_type_unique (gtk_container_get_type (), &tree_info);
101 gtk_tree_class_init (GtkTreeClass *class)
103 GtkObjectClass *object_class;
104 GtkWidgetClass *widget_class;
105 GtkContainerClass *container_class;
107 object_class = (GtkObjectClass*) class;
108 widget_class = (GtkWidgetClass*) class;
109 container_class = (GtkContainerClass*) class;
111 parent_class = gtk_type_class (gtk_container_get_type ());
114 object_class->destroy = gtk_tree_destroy;
116 widget_class->map = gtk_tree_map;
117 widget_class->unmap = gtk_tree_unmap;
118 widget_class->realize = gtk_tree_realize;
119 widget_class->expose_event = gtk_tree_expose;
120 widget_class->motion_notify_event = gtk_tree_motion_notify;
121 widget_class->button_press_event = gtk_tree_button_press;
122 widget_class->button_release_event = gtk_tree_button_release;
123 widget_class->size_request = gtk_tree_size_request;
124 widget_class->size_allocate = gtk_tree_size_allocate;
126 container_class->add = gtk_tree_add;
127 container_class->remove =
128 (void (*)(GtkContainer *, GtkWidget *)) gtk_tree_remove_item;
129 container_class->forall = gtk_tree_forall;
130 container_class->child_type = gtk_tree_child_type;
132 class->selection_changed = NULL;
133 class->select_child = gtk_real_tree_select_child;
134 class->unselect_child = gtk_real_tree_unselect_child;
136 tree_signals[SELECTION_CHANGED] =
137 gtk_signal_new ("selection_changed",
139 GTK_CLASS_TYPE (object_class),
140 GTK_SIGNAL_OFFSET (GtkTreeClass, selection_changed),
141 gtk_marshal_VOID__VOID,
143 tree_signals[SELECT_CHILD] =
144 gtk_signal_new ("select_child",
146 GTK_CLASS_TYPE (object_class),
147 GTK_SIGNAL_OFFSET (GtkTreeClass, select_child),
148 gtk_marshal_VOID__POINTER,
151 tree_signals[UNSELECT_CHILD] =
152 gtk_signal_new ("unselect_child",
154 GTK_CLASS_TYPE (object_class),
155 GTK_SIGNAL_OFFSET (GtkTreeClass, unselect_child),
156 gtk_marshal_VOID__POINTER,
162 gtk_tree_child_type (GtkContainer *container)
164 return GTK_TYPE_TREE_ITEM;
168 gtk_tree_init (GtkTree *tree)
170 tree->children = NULL;
171 tree->root_tree = NULL;
172 tree->selection = NULL;
173 tree->tree_owner = NULL;
174 tree->selection_mode = GTK_SELECTION_SINGLE;
175 tree->indent_value = 9;
176 tree->current_indent = 0;
178 tree->view_mode = GTK_TREE_VIEW_LINE;
185 return GTK_WIDGET (gtk_type_new (gtk_tree_get_type ()));
189 gtk_tree_append (GtkTree *tree,
190 GtkWidget *tree_item)
192 g_return_if_fail (tree != NULL);
193 g_return_if_fail (GTK_IS_TREE (tree));
194 g_return_if_fail (tree_item != NULL);
195 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
197 gtk_tree_insert (tree, tree_item, -1);
201 gtk_tree_prepend (GtkTree *tree,
202 GtkWidget *tree_item)
204 g_return_if_fail (tree != NULL);
205 g_return_if_fail (GTK_IS_TREE (tree));
206 g_return_if_fail (tree_item != NULL);
207 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
209 gtk_tree_insert (tree, tree_item, 0);
213 gtk_tree_insert (GtkTree *tree,
214 GtkWidget *tree_item,
219 g_return_if_fail (tree != NULL);
220 g_return_if_fail (GTK_IS_TREE (tree));
221 g_return_if_fail (tree_item != NULL);
222 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
224 nchildren = g_list_length (tree->children);
226 if ((position < 0) || (position > nchildren))
227 position = nchildren;
229 if (position == nchildren)
230 tree->children = g_list_append (tree->children, tree_item);
232 tree->children = g_list_insert (tree->children, tree_item, position);
234 gtk_widget_set_parent (tree_item, GTK_WIDGET (tree));
236 if (GTK_WIDGET_REALIZED (tree_item->parent))
237 gtk_widget_realize (tree_item);
239 if (GTK_WIDGET_VISIBLE (tree_item->parent) && GTK_WIDGET_VISIBLE (tree_item))
241 if (GTK_WIDGET_MAPPED (tree_item->parent))
242 gtk_widget_map (tree_item);
244 gtk_widget_queue_resize (tree_item);
249 gtk_tree_add (GtkContainer *container,
254 g_return_if_fail (container != NULL);
255 g_return_if_fail (GTK_IS_TREE (container));
256 g_return_if_fail (GTK_IS_TREE_ITEM (child));
258 tree = GTK_TREE (container);
260 tree->children = g_list_append (tree->children, child);
262 gtk_widget_set_parent (child, GTK_WIDGET (container));
264 if (GTK_WIDGET_REALIZED (child->parent))
265 gtk_widget_realize (child);
267 if (GTK_WIDGET_VISIBLE (child->parent) && GTK_WIDGET_VISIBLE (child))
269 if (GTK_WIDGET_MAPPED (child->parent))
270 gtk_widget_map (child);
272 gtk_widget_queue_resize (child);
275 if (!tree->selection && (tree->selection_mode == GTK_SELECTION_BROWSE))
276 gtk_tree_select_child (tree, child);
280 gtk_tree_button_press (GtkWidget *widget,
281 GdkEventButton *event)
286 g_return_val_if_fail (widget != NULL, FALSE);
287 g_return_val_if_fail (GTK_IS_TREE (widget), FALSE);
288 g_return_val_if_fail (event != NULL, FALSE);
290 tree = GTK_TREE (widget);
291 item = gtk_get_event_widget ((GdkEvent*) event);
293 while (item && !GTK_IS_TREE_ITEM (item))
296 if (!item || (item->parent != widget))
299 switch(event->button)
302 gtk_tree_select_child (tree, item);
305 if(GTK_TREE_ITEM(item)->subtree) gtk_tree_item_expand(GTK_TREE_ITEM(item));
308 if(GTK_TREE_ITEM(item)->subtree) gtk_tree_item_collapse(GTK_TREE_ITEM(item));
316 gtk_tree_button_release (GtkWidget *widget,
317 GdkEventButton *event)
322 g_return_val_if_fail (widget != NULL, FALSE);
323 g_return_val_if_fail (GTK_IS_TREE (widget), FALSE);
324 g_return_val_if_fail (event != NULL, FALSE);
326 tree = GTK_TREE (widget);
327 item = gtk_get_event_widget ((GdkEvent*) event);
333 gtk_tree_child_position (GtkTree *tree,
340 g_return_val_if_fail (tree != NULL, -1);
341 g_return_val_if_fail (GTK_IS_TREE (tree), -1);
342 g_return_val_if_fail (child != NULL, -1);
345 children = tree->children;
349 if (child == GTK_WIDGET (children->data))
353 children = children->next;
361 gtk_tree_clear_items (GtkTree *tree,
371 g_return_if_fail (tree != NULL);
372 g_return_if_fail (GTK_IS_TREE (tree));
374 nchildren = g_list_length (tree->children);
378 if ((end < 0) || (end > nchildren))
384 tmp_list = g_list_nth (tree->children, start);
387 while (tmp_list && index <= end)
389 widget = tmp_list->data;
390 tmp_list = tmp_list->next;
393 clear_list = g_list_prepend (clear_list, widget);
396 gtk_tree_remove_items (tree, clear_list);
401 gtk_tree_destroy (GtkObject *object)
407 g_return_if_fail (object != NULL);
408 g_return_if_fail (GTK_IS_TREE (object));
410 tree = GTK_TREE (object);
412 children = tree->children;
415 child = children->data;
416 children = children->next;
418 gtk_widget_ref (child);
419 gtk_widget_unparent (child);
420 gtk_widget_destroy (child);
421 gtk_widget_unref (child);
424 g_list_free (tree->children);
425 tree->children = NULL;
427 if (tree->root_tree == tree)
430 for (node = tree->selection; node; node = node->next)
431 gtk_widget_unref ((GtkWidget *)node->data);
432 g_list_free (tree->selection);
433 tree->selection = NULL;
436 if (GTK_OBJECT_CLASS (parent_class)->destroy)
437 (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
441 gtk_tree_expose (GtkWidget *widget,
442 GdkEventExpose *event)
446 GdkEventExpose child_event;
450 g_return_val_if_fail (widget != NULL, FALSE);
451 g_return_val_if_fail (GTK_IS_TREE (widget), FALSE);
452 g_return_val_if_fail (event != NULL, FALSE);
454 if (GTK_WIDGET_DRAWABLE (widget))
456 tree = GTK_TREE (widget);
458 child_event = *event;
460 children = tree->children;
463 child = children->data;
464 children = children->next;
466 if (GTK_WIDGET_NO_WINDOW (child) &&
467 gtk_widget_intersect (child, &event->area, &child_event.area))
468 gtk_widget_event (child, (GdkEvent*) &child_event);
477 gtk_tree_forall (GtkContainer *container,
478 gboolean include_internals,
479 GtkCallback callback,
480 gpointer callback_data)
487 g_return_if_fail (container != NULL);
488 g_return_if_fail (GTK_IS_TREE (container));
489 g_return_if_fail (callback != NULL);
491 tree = GTK_TREE (container);
492 children = tree->children;
496 child = children->data;
497 children = children->next;
499 (* callback) (child, callback_data);
504 gtk_tree_map (GtkWidget *widget)
511 g_return_if_fail (widget != NULL);
512 g_return_if_fail (GTK_IS_TREE (widget));
514 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
515 tree = GTK_TREE (widget);
517 if(GTK_IS_TREE(widget->parent))
519 /* set root tree for this tree */
520 tree->root_tree = GTK_TREE(widget->parent)->root_tree;
522 tree->level = GTK_TREE(GTK_WIDGET(tree)->parent)->level+1;
523 tree->indent_value = GTK_TREE(GTK_WIDGET(tree)->parent)->indent_value;
524 tree->current_indent = GTK_TREE(GTK_WIDGET(tree)->parent)->current_indent +
526 tree->view_mode = GTK_TREE(GTK_WIDGET(tree)->parent)->view_mode;
527 tree->view_line = GTK_TREE(GTK_WIDGET(tree)->parent)->view_line;
530 tree->root_tree = tree;
532 children = tree->children;
535 child = children->data;
536 children = children->next;
538 if (GTK_WIDGET_VISIBLE (child) &&
539 !GTK_WIDGET_MAPPED (child))
540 gtk_widget_map (child);
542 if (GTK_TREE_ITEM (child)->subtree)
544 child = GTK_WIDGET (GTK_TREE_ITEM (child)->subtree);
546 if (GTK_WIDGET_VISIBLE (child) && !GTK_WIDGET_MAPPED (child))
547 gtk_widget_map (child);
551 gdk_window_show (widget->window);
555 gtk_tree_motion_notify (GtkWidget *widget,
556 GdkEventMotion *event)
558 g_return_val_if_fail (widget != NULL, FALSE);
559 g_return_val_if_fail (GTK_IS_TREE (widget), FALSE);
560 g_return_val_if_fail (event != NULL, FALSE);
563 g_message("gtk_tree_motion_notify\n");
564 #endif /* TREE_DEBUG */
570 gtk_tree_realize (GtkWidget *widget)
572 GdkWindowAttr attributes;
573 gint attributes_mask;
576 g_return_if_fail (widget != NULL);
577 g_return_if_fail (GTK_IS_TREE (widget));
579 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
581 attributes.window_type = GDK_WINDOW_CHILD;
582 attributes.x = widget->allocation.x;
583 attributes.y = widget->allocation.y;
584 attributes.width = widget->allocation.width;
585 attributes.height = widget->allocation.height;
586 attributes.wclass = GDK_INPUT_OUTPUT;
587 attributes.visual = gtk_widget_get_visual (widget);
588 attributes.colormap = gtk_widget_get_colormap (widget);
589 attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
591 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
593 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
594 gdk_window_set_user_data (widget->window, widget);
596 widget->style = gtk_style_attach (widget->style, widget->window);
597 gdk_window_set_background (widget->window,
598 &widget->style->base[GTK_STATE_NORMAL]);
602 gtk_tree_remove_item (GtkTree *container,
607 g_return_if_fail (container != NULL);
608 g_return_if_fail (GTK_IS_TREE (container));
609 g_return_if_fail (widget != NULL);
610 g_return_if_fail (container == GTK_TREE (widget->parent));
612 item_list = g_list_append (NULL, widget);
614 gtk_tree_remove_items (GTK_TREE (container), item_list);
616 g_list_free (item_list);
619 /* used by gtk_tree_remove_items to make the function independant of
620 order in list of items to remove.
621 Sort item bu depth in tree */
623 gtk_tree_sort_item_by_depth(GtkWidget* a, GtkWidget* b)
625 if((GTK_TREE(a->parent)->level) < (GTK_TREE(b->parent)->level))
627 if((GTK_TREE(a->parent)->level) > (GTK_TREE(b->parent)->level))
634 gtk_tree_remove_items (GtkTree *tree,
638 GList *selected_widgets;
644 g_return_if_fail (tree != NULL);
645 g_return_if_fail (GTK_IS_TREE (tree));
648 g_message("+ gtk_tree_remove_items [ tree %#x items list %#x ]\n", (int)tree, (int)items);
649 #endif /* TREE_DEBUG */
651 /* We may not yet be mapped, so we actively have to find our
655 root_tree = tree->root_tree;
658 GtkWidget *tmp = GTK_WIDGET (tree);
659 while (tmp->parent && GTK_IS_TREE (tmp->parent))
662 root_tree = GTK_TREE (tmp);
666 selected_widgets = NULL;
671 g_message("* sort list by depth\n");
672 #endif /* TREE_DEBUG */
678 g_message ("* item [%#x] depth [%d]\n",
680 (int)GTK_TREE(GTK_WIDGET(tmp_list->data)->parent)->level);
681 #endif /* TREE_DEBUG */
683 sorted_list = g_list_insert_sorted(sorted_list,
685 (GCompareFunc)gtk_tree_sort_item_by_depth);
686 tmp_list = g_list_next(tmp_list);
690 /* print sorted list */
691 g_message("* sorted list result\n");
692 tmp_list = sorted_list;
695 g_message("* item [%#x] depth [%d]\n",
697 (int)GTK_TREE(GTK_WIDGET(tmp_list->data)->parent)->level);
698 tmp_list = g_list_next(tmp_list);
700 #endif /* TREE_DEBUG */
703 g_message("* scan sorted list\n");
704 #endif /* TREE_DEBUG */
706 tmp_list = sorted_list;
709 widget = tmp_list->data;
710 tmp_list = tmp_list->next;
713 g_message("* item [%#x] subtree [%#x]\n",
714 (int)widget, (int)GTK_TREE_ITEM_SUBTREE(widget));
715 #endif /* TREE_DEBUG */
717 /* get real owner of this widget */
718 real_tree = GTK_TREE(widget->parent);
720 g_message("* subtree having this widget [%#x]\n", (int)real_tree);
721 #endif /* TREE_DEBUG */
724 if (widget->state == GTK_STATE_SELECTED)
726 selected_widgets = g_list_prepend (selected_widgets, widget);
728 g_message("* selected widget - adding it in selected list [%#x]\n",
729 (int)selected_widgets);
730 #endif /* TREE_DEBUG */
733 /* remove this item from its real parent */
735 g_message("* remove widget from its owner tree\n");
736 #endif /* TREE_DEBUG */
737 real_tree->children = g_list_remove (real_tree->children, widget);
739 /* remove subtree associate at this item if it exist */
740 if(GTK_TREE_ITEM(widget)->subtree)
743 g_message("* remove subtree associate at this item [%#x]\n",
744 (int) GTK_TREE_ITEM(widget)->subtree);
745 #endif /* TREE_DEBUG */
746 if (GTK_WIDGET_MAPPED (GTK_TREE_ITEM(widget)->subtree))
747 gtk_widget_unmap (GTK_TREE_ITEM(widget)->subtree);
749 gtk_widget_unparent (GTK_TREE_ITEM(widget)->subtree);
750 GTK_TREE_ITEM(widget)->subtree = NULL;
753 /* really remove widget for this item */
755 g_message("* unmap and unparent widget [%#x]\n", (int)widget);
756 #endif /* TREE_DEBUG */
757 if (GTK_WIDGET_MAPPED (widget))
758 gtk_widget_unmap (widget);
760 gtk_widget_unparent (widget);
762 /* delete subtree if there is no children in it */
763 if(real_tree->children == NULL &&
764 real_tree != root_tree)
767 g_message("* owner tree don't have children ... destroy it\n");
768 #endif /* TREE_DEBUG */
769 gtk_tree_item_remove_subtree(GTK_TREE_ITEM(real_tree->tree_owner));
773 g_message("* next item in list\n");
774 #endif /* TREE_DEBUG */
777 if (selected_widgets)
780 g_message("* scan selected item list\n");
781 #endif /* TREE_DEBUG */
782 tmp_list = selected_widgets;
785 widget = tmp_list->data;
786 tmp_list = tmp_list->next;
789 g_message("* widget [%#x] subtree [%#x]\n",
790 (int)widget, (int)GTK_TREE_ITEM_SUBTREE(widget));
791 #endif /* TREE_DEBUG */
793 /* remove widget of selection */
794 root_tree->selection = g_list_remove (root_tree->selection, widget);
796 /* unref it to authorize is destruction */
797 gtk_widget_unref (widget);
800 /* emit only one selection_changed signal */
801 gtk_signal_emit (GTK_OBJECT (root_tree),
802 tree_signals[SELECTION_CHANGED]);
806 g_message("* free selected_widgets list\n");
807 #endif /* TREE_DEBUG */
808 g_list_free (selected_widgets);
809 g_list_free (sorted_list);
811 if (root_tree->children && !root_tree->selection &&
812 (root_tree->selection_mode == GTK_SELECTION_BROWSE))
815 g_message("* BROWSE mode, select another item\n");
816 #endif /* TREE_DEBUG */
817 widget = root_tree->children->data;
818 gtk_tree_select_child (root_tree, widget);
821 if (GTK_WIDGET_VISIBLE (root_tree))
824 g_message("* query queue resizing for root_tree\n");
825 #endif /* TREE_DEBUG */
826 gtk_widget_queue_resize (GTK_WIDGET (root_tree));
831 gtk_tree_select_child (GtkTree *tree,
832 GtkWidget *tree_item)
834 g_return_if_fail (tree != NULL);
835 g_return_if_fail (GTK_IS_TREE (tree));
836 g_return_if_fail (tree_item != NULL);
837 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
839 gtk_signal_emit (GTK_OBJECT (tree), tree_signals[SELECT_CHILD], tree_item);
843 gtk_tree_select_item (GtkTree *tree,
848 g_return_if_fail (tree != NULL);
849 g_return_if_fail (GTK_IS_TREE (tree));
851 tmp_list = g_list_nth (tree->children, item);
853 gtk_tree_select_child (tree, GTK_WIDGET (tmp_list->data));
858 gtk_tree_size_allocate (GtkWidget *widget,
859 GtkAllocation *allocation)
862 GtkWidget *child, *subtree;
863 GtkAllocation child_allocation;
867 g_return_if_fail (widget != NULL);
868 g_return_if_fail (GTK_IS_TREE (widget));
869 g_return_if_fail (allocation != NULL);
871 tree = GTK_TREE (widget);
873 widget->allocation = *allocation;
874 if (GTK_WIDGET_REALIZED (widget))
875 gdk_window_move_resize (widget->window,
876 allocation->x, allocation->y,
877 allocation->width, allocation->height);
881 child_allocation.x = GTK_CONTAINER (tree)->border_width;
882 child_allocation.y = GTK_CONTAINER (tree)->border_width;
883 child_allocation.width = MAX (1, (gint)allocation->width - child_allocation.x * 2);
885 children = tree->children;
889 child = children->data;
890 children = children->next;
892 if (GTK_WIDGET_VISIBLE (child))
894 GtkRequisition child_requisition;
895 gtk_widget_get_child_requisition (child, &child_requisition);
897 child_allocation.height = child_requisition.height;
899 gtk_widget_size_allocate (child, &child_allocation);
901 child_allocation.y += child_allocation.height;
903 if((subtree = GTK_TREE_ITEM(child)->subtree))
904 if(GTK_WIDGET_VISIBLE (subtree))
906 child_allocation.height = subtree->requisition.height;
907 gtk_widget_size_allocate (subtree, &child_allocation);
908 child_allocation.y += child_allocation.height;
917 gtk_tree_size_request (GtkWidget *widget,
918 GtkRequisition *requisition)
921 GtkWidget *child, *subtree;
923 GtkRequisition child_requisition;
926 g_return_if_fail (widget != NULL);
927 g_return_if_fail (GTK_IS_TREE (widget));
928 g_return_if_fail (requisition != NULL);
930 tree = GTK_TREE (widget);
931 requisition->width = 0;
932 requisition->height = 0;
934 children = tree->children;
937 child = children->data;
938 children = children->next;
940 if (GTK_WIDGET_VISIBLE (child))
942 gtk_widget_size_request (child, &child_requisition);
944 requisition->width = MAX (requisition->width, child_requisition.width);
945 requisition->height += child_requisition.height;
947 if((subtree = GTK_TREE_ITEM(child)->subtree) &&
948 GTK_WIDGET_VISIBLE (subtree))
950 gtk_widget_size_request (subtree, &child_requisition);
952 requisition->width = MAX (requisition->width,
953 child_requisition.width);
955 requisition->height += child_requisition.height;
960 requisition->width += GTK_CONTAINER (tree)->border_width * 2;
961 requisition->height += GTK_CONTAINER (tree)->border_width * 2;
963 requisition->width = MAX (requisition->width, 1);
964 requisition->height = MAX (requisition->height, 1);
969 gtk_tree_unmap (GtkWidget *widget)
972 g_return_if_fail (widget != NULL);
973 g_return_if_fail (GTK_IS_TREE (widget));
975 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
976 gdk_window_hide (widget->window);
981 gtk_tree_unselect_child (GtkTree *tree,
982 GtkWidget *tree_item)
984 g_return_if_fail (tree != NULL);
985 g_return_if_fail (GTK_IS_TREE (tree));
986 g_return_if_fail (tree_item != NULL);
987 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
989 gtk_signal_emit (GTK_OBJECT (tree), tree_signals[UNSELECT_CHILD], tree_item);
993 gtk_tree_unselect_item (GtkTree *tree,
998 g_return_if_fail (tree != NULL);
999 g_return_if_fail (GTK_IS_TREE (tree));
1001 tmp_list = g_list_nth (tree->children, item);
1003 gtk_tree_unselect_child (tree, GTK_WIDGET (tmp_list->data));
1008 gtk_real_tree_select_child (GtkTree *tree,
1011 GList *selection, *root_selection;
1013 GtkWidget *tmp_item;
1015 g_return_if_fail (tree != NULL);
1016 g_return_if_fail (GTK_IS_TREE (tree));
1017 g_return_if_fail (child != NULL);
1018 g_return_if_fail (GTK_IS_TREE_ITEM (child));
1020 if (!tree->root_tree)
1022 g_warning (G_STRLOC ": unable to select a child in a tree prior to realization");
1026 root_selection = tree->root_tree->selection;
1028 switch (tree->root_tree->selection_mode)
1030 case GTK_SELECTION_SINGLE:
1032 selection = root_selection;
1034 /* remove old selection list */
1037 tmp_item = selection->data;
1039 if (tmp_item != child)
1041 gtk_tree_item_deselect (GTK_TREE_ITEM (tmp_item));
1043 tmp_list = selection;
1044 selection = selection->next;
1046 root_selection = g_list_remove_link (root_selection, tmp_list);
1047 gtk_widget_unref (tmp_item);
1049 g_list_free (tmp_list);
1052 selection = selection->next;
1055 if (child->state == GTK_STATE_NORMAL)
1057 gtk_tree_item_select (GTK_TREE_ITEM (child));
1058 root_selection = g_list_prepend (root_selection, child);
1059 gtk_widget_ref (child);
1061 else if (child->state == GTK_STATE_SELECTED)
1063 gtk_tree_item_deselect (GTK_TREE_ITEM (child));
1064 root_selection = g_list_remove (root_selection, child);
1065 gtk_widget_unref (child);
1068 tree->root_tree->selection = root_selection;
1070 gtk_signal_emit (GTK_OBJECT (tree->root_tree),
1071 tree_signals[SELECTION_CHANGED]);
1075 case GTK_SELECTION_BROWSE:
1076 selection = root_selection;
1080 tmp_item = selection->data;
1082 if (tmp_item != child)
1084 gtk_tree_item_deselect (GTK_TREE_ITEM (tmp_item));
1086 tmp_list = selection;
1087 selection = selection->next;
1089 root_selection = g_list_remove_link (root_selection, tmp_list);
1090 gtk_widget_unref (tmp_item);
1092 g_list_free (tmp_list);
1095 selection = selection->next;
1098 tree->root_tree->selection = root_selection;
1100 if (child->state == GTK_STATE_NORMAL)
1102 gtk_tree_item_select (GTK_TREE_ITEM (child));
1103 root_selection = g_list_prepend (root_selection, child);
1104 gtk_widget_ref (child);
1105 tree->root_tree->selection = root_selection;
1106 gtk_signal_emit (GTK_OBJECT (tree->root_tree),
1107 tree_signals[SELECTION_CHANGED]);
1111 case GTK_SELECTION_MULTIPLE:
1112 if (child->state == GTK_STATE_NORMAL)
1114 gtk_tree_item_select (GTK_TREE_ITEM (child));
1115 root_selection = g_list_prepend (root_selection, child);
1116 gtk_widget_ref (child);
1117 tree->root_tree->selection = root_selection;
1118 gtk_signal_emit (GTK_OBJECT (tree->root_tree),
1119 tree_signals[SELECTION_CHANGED]);
1121 else if (child->state == GTK_STATE_SELECTED)
1123 gtk_tree_item_deselect (GTK_TREE_ITEM (child));
1124 root_selection = g_list_remove (root_selection, child);
1125 gtk_widget_unref (child);
1126 tree->root_tree->selection = root_selection;
1127 gtk_signal_emit (GTK_OBJECT (tree->root_tree),
1128 tree_signals[SELECTION_CHANGED]);
1132 case GTK_SELECTION_EXTENDED:
1138 gtk_real_tree_unselect_child (GtkTree *tree,
1141 g_return_if_fail (tree != NULL);
1142 g_return_if_fail (GTK_IS_TREE (tree));
1143 g_return_if_fail (child != NULL);
1144 g_return_if_fail (GTK_IS_TREE_ITEM (child));
1146 switch (tree->selection_mode)
1148 case GTK_SELECTION_SINGLE:
1149 case GTK_SELECTION_MULTIPLE:
1150 case GTK_SELECTION_BROWSE:
1151 if (child->state == GTK_STATE_SELECTED)
1153 GtkTree* root_tree = GTK_TREE_ROOT_TREE(tree);
1154 gtk_tree_item_deselect (GTK_TREE_ITEM (child));
1155 root_tree->selection = g_list_remove (root_tree->selection, child);
1156 gtk_widget_unref (child);
1157 gtk_signal_emit (GTK_OBJECT (tree->root_tree),
1158 tree_signals[SELECTION_CHANGED]);
1162 case GTK_SELECTION_EXTENDED:
1168 gtk_tree_set_selection_mode (GtkTree *tree,
1169 GtkSelectionMode mode)
1171 g_return_if_fail (tree != NULL);
1172 g_return_if_fail (GTK_IS_TREE (tree));
1174 tree->selection_mode = mode;
1178 gtk_tree_set_view_mode (GtkTree *tree,
1179 GtkTreeViewMode mode)
1181 g_return_if_fail (tree != NULL);
1182 g_return_if_fail (GTK_IS_TREE (tree));
1184 tree->view_mode = mode;
1188 gtk_tree_set_view_lines (GtkTree *tree,
1191 g_return_if_fail (tree != NULL);
1192 g_return_if_fail (GTK_IS_TREE (tree));
1194 tree->view_line = flag;