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 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.
21 * Modified by the GTK+ Team and others 1997-1999. 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 void gtk_tree_draw (GtkWidget *widget,
48 static gint gtk_tree_expose (GtkWidget *widget,
49 GdkEventExpose *event);
50 static gint gtk_tree_motion_notify (GtkWidget *widget,
51 GdkEventMotion *event);
52 static gint gtk_tree_button_press (GtkWidget *widget,
53 GdkEventButton *event);
54 static gint gtk_tree_button_release (GtkWidget *widget,
55 GdkEventButton *event);
56 static void gtk_tree_size_request (GtkWidget *widget,
57 GtkRequisition *requisition);
58 static void gtk_tree_size_allocate (GtkWidget *widget,
59 GtkAllocation *allocation);
60 static void gtk_tree_add (GtkContainer *container,
62 static void gtk_tree_forall (GtkContainer *container,
63 gboolean include_internals,
65 gpointer callback_data);
67 static void gtk_real_tree_select_child (GtkTree *tree,
69 static void gtk_real_tree_unselect_child (GtkTree *tree,
72 static GtkType gtk_tree_child_type (GtkContainer *container);
74 static GtkContainerClass *parent_class = NULL;
75 static guint tree_signals[LAST_SIGNAL] = { 0 };
78 gtk_tree_get_type (void)
80 static GtkType tree_type = 0;
84 static const GtkTypeInfo tree_info =
88 sizeof (GtkTreeClass),
89 (GtkClassInitFunc) gtk_tree_class_init,
90 (GtkObjectInitFunc) gtk_tree_init,
91 /* reserved_1 */ NULL,
92 /* reserved_2 */ NULL,
93 (GtkClassInitFunc) NULL,
96 tree_type = gtk_type_unique (gtk_container_get_type (), &tree_info);
103 gtk_tree_class_init (GtkTreeClass *class)
105 GtkObjectClass *object_class;
106 GtkWidgetClass *widget_class;
107 GtkContainerClass *container_class;
109 object_class = (GtkObjectClass*) class;
110 widget_class = (GtkWidgetClass*) class;
111 container_class = (GtkContainerClass*) class;
113 parent_class = gtk_type_class (gtk_container_get_type ());
115 tree_signals[SELECTION_CHANGED] =
116 gtk_signal_new ("selection_changed",
118 GTK_CLASS_TYPE (object_class),
119 GTK_SIGNAL_OFFSET (GtkTreeClass, selection_changed),
120 gtk_marshal_NONE__NONE,
122 tree_signals[SELECT_CHILD] =
123 gtk_signal_new ("select_child",
125 GTK_CLASS_TYPE (object_class),
126 GTK_SIGNAL_OFFSET (GtkTreeClass, select_child),
127 gtk_marshal_NONE__POINTER,
130 tree_signals[UNSELECT_CHILD] =
131 gtk_signal_new ("unselect_child",
133 GTK_CLASS_TYPE (object_class),
134 GTK_SIGNAL_OFFSET (GtkTreeClass, unselect_child),
135 gtk_marshal_NONE__POINTER,
139 gtk_object_class_add_signals (object_class, tree_signals, LAST_SIGNAL);
141 object_class->destroy = gtk_tree_destroy;
143 widget_class->map = gtk_tree_map;
144 widget_class->unmap = gtk_tree_unmap;
145 widget_class->realize = gtk_tree_realize;
146 widget_class->draw = gtk_tree_draw;
147 widget_class->expose_event = gtk_tree_expose;
148 widget_class->motion_notify_event = gtk_tree_motion_notify;
149 widget_class->button_press_event = gtk_tree_button_press;
150 widget_class->button_release_event = gtk_tree_button_release;
151 widget_class->size_request = gtk_tree_size_request;
152 widget_class->size_allocate = gtk_tree_size_allocate;
154 container_class->add = gtk_tree_add;
155 container_class->remove =
156 (void (*)(GtkContainer *, GtkWidget *)) gtk_tree_remove_item;
157 container_class->forall = gtk_tree_forall;
158 container_class->child_type = gtk_tree_child_type;
160 class->selection_changed = NULL;
161 class->select_child = gtk_real_tree_select_child;
162 class->unselect_child = gtk_real_tree_unselect_child;
166 gtk_tree_child_type (GtkContainer *container)
168 return GTK_TYPE_TREE_ITEM;
172 gtk_tree_init (GtkTree *tree)
174 tree->children = NULL;
175 tree->root_tree = NULL;
176 tree->selection = NULL;
177 tree->tree_owner = NULL;
178 tree->selection_mode = GTK_SELECTION_SINGLE;
179 tree->indent_value = 9;
180 tree->current_indent = 0;
182 tree->view_mode = GTK_TREE_VIEW_LINE;
189 return GTK_WIDGET (gtk_type_new (gtk_tree_get_type ()));
193 gtk_tree_append (GtkTree *tree,
194 GtkWidget *tree_item)
196 g_return_if_fail (tree != NULL);
197 g_return_if_fail (GTK_IS_TREE (tree));
198 g_return_if_fail (tree_item != NULL);
199 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
201 gtk_tree_insert (tree, tree_item, -1);
205 gtk_tree_prepend (GtkTree *tree,
206 GtkWidget *tree_item)
208 g_return_if_fail (tree != NULL);
209 g_return_if_fail (GTK_IS_TREE (tree));
210 g_return_if_fail (tree_item != NULL);
211 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
213 gtk_tree_insert (tree, tree_item, 0);
217 gtk_tree_insert (GtkTree *tree,
218 GtkWidget *tree_item,
223 g_return_if_fail (tree != NULL);
224 g_return_if_fail (GTK_IS_TREE (tree));
225 g_return_if_fail (tree_item != NULL);
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));
240 if (GTK_WIDGET_REALIZED (tree_item->parent))
241 gtk_widget_realize (tree_item);
243 if (GTK_WIDGET_VISIBLE (tree_item->parent) && GTK_WIDGET_VISIBLE (tree_item))
245 if (GTK_WIDGET_MAPPED (tree_item->parent))
246 gtk_widget_map (tree_item);
248 gtk_widget_queue_resize (tree_item);
253 gtk_tree_add (GtkContainer *container,
258 g_return_if_fail (container != NULL);
259 g_return_if_fail (GTK_IS_TREE (container));
260 g_return_if_fail (GTK_IS_TREE_ITEM (child));
262 tree = GTK_TREE (container);
264 tree->children = g_list_append (tree->children, child);
266 gtk_widget_set_parent (child, GTK_WIDGET (container));
268 if (GTK_WIDGET_REALIZED (child->parent))
269 gtk_widget_realize (child);
271 if (GTK_WIDGET_VISIBLE (child->parent) && GTK_WIDGET_VISIBLE (child))
273 if (GTK_WIDGET_MAPPED (child->parent))
274 gtk_widget_map (child);
276 gtk_widget_queue_resize (child);
279 if (!tree->selection && (tree->selection_mode == GTK_SELECTION_BROWSE))
280 gtk_tree_select_child (tree, child);
284 gtk_tree_button_press (GtkWidget *widget,
285 GdkEventButton *event)
290 g_return_val_if_fail (widget != NULL, FALSE);
291 g_return_val_if_fail (GTK_IS_TREE (widget), FALSE);
292 g_return_val_if_fail (event != NULL, FALSE);
294 tree = GTK_TREE (widget);
295 item = gtk_get_event_widget ((GdkEvent*) event);
297 while (item && !GTK_IS_TREE_ITEM (item))
300 if (!item || (item->parent != widget))
303 switch(event->button)
306 gtk_tree_select_child (tree, item);
309 if(GTK_TREE_ITEM(item)->subtree) gtk_tree_item_expand(GTK_TREE_ITEM(item));
312 if(GTK_TREE_ITEM(item)->subtree) gtk_tree_item_collapse(GTK_TREE_ITEM(item));
320 gtk_tree_button_release (GtkWidget *widget,
321 GdkEventButton *event)
326 g_return_val_if_fail (widget != NULL, FALSE);
327 g_return_val_if_fail (GTK_IS_TREE (widget), FALSE);
328 g_return_val_if_fail (event != NULL, FALSE);
330 tree = GTK_TREE (widget);
331 item = gtk_get_event_widget ((GdkEvent*) event);
337 gtk_tree_child_position (GtkTree *tree,
344 g_return_val_if_fail (tree != NULL, -1);
345 g_return_val_if_fail (GTK_IS_TREE (tree), -1);
346 g_return_val_if_fail (child != NULL, -1);
349 children = tree->children;
353 if (child == GTK_WIDGET (children->data))
357 children = children->next;
365 gtk_tree_clear_items (GtkTree *tree,
375 g_return_if_fail (tree != NULL);
376 g_return_if_fail (GTK_IS_TREE (tree));
378 nchildren = g_list_length (tree->children);
382 if ((end < 0) || (end > nchildren))
388 tmp_list = g_list_nth (tree->children, start);
391 while (tmp_list && index <= end)
393 widget = tmp_list->data;
394 tmp_list = tmp_list->next;
397 clear_list = g_list_prepend (clear_list, widget);
400 gtk_tree_remove_items (tree, clear_list);
405 gtk_tree_destroy (GtkObject *object)
411 g_return_if_fail (object != NULL);
412 g_return_if_fail (GTK_IS_TREE (object));
414 tree = GTK_TREE (object);
416 children = tree->children;
419 child = children->data;
420 children = children->next;
422 gtk_widget_ref (child);
423 gtk_widget_unparent (child);
424 gtk_widget_destroy (child);
425 gtk_widget_unref (child);
428 g_list_free (tree->children);
429 tree->children = NULL;
431 if (tree->root_tree == tree)
434 for (node = tree->selection; node; node = node->next)
435 gtk_widget_unref ((GtkWidget *)node->data);
436 g_list_free (tree->selection);
437 tree->selection = NULL;
440 if (GTK_OBJECT_CLASS (parent_class)->destroy)
441 (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
445 gtk_tree_draw (GtkWidget *widget,
451 GdkRectangle child_area;
455 g_return_if_fail (widget != NULL);
456 g_return_if_fail (GTK_IS_TREE (widget));
457 g_return_if_fail (area != NULL);
459 if (GTK_WIDGET_DRAWABLE (widget))
461 tree = GTK_TREE (widget);
463 children = tree->children;
466 child = children->data;
467 children = children->next;
469 if (gtk_widget_intersect (child, area, &child_area))
470 gtk_widget_draw (child, &child_area);
472 if((subtree = GTK_TREE_ITEM(child)->subtree) &&
473 GTK_WIDGET_VISIBLE(subtree) &&
474 gtk_widget_intersect (subtree, area, &child_area))
475 gtk_widget_draw (subtree, &child_area);
482 gtk_tree_expose (GtkWidget *widget,
483 GdkEventExpose *event)
487 GdkEventExpose child_event;
491 g_return_val_if_fail (widget != NULL, FALSE);
492 g_return_val_if_fail (GTK_IS_TREE (widget), FALSE);
493 g_return_val_if_fail (event != NULL, FALSE);
495 if (GTK_WIDGET_DRAWABLE (widget))
497 tree = GTK_TREE (widget);
499 child_event = *event;
501 children = tree->children;
504 child = children->data;
505 children = children->next;
507 if (GTK_WIDGET_NO_WINDOW (child) &&
508 gtk_widget_intersect (child, &event->area, &child_event.area))
509 gtk_widget_event (child, (GdkEvent*) &child_event);
518 gtk_tree_forall (GtkContainer *container,
519 gboolean include_internals,
520 GtkCallback callback,
521 gpointer callback_data)
528 g_return_if_fail (container != NULL);
529 g_return_if_fail (GTK_IS_TREE (container));
530 g_return_if_fail (callback != NULL);
532 tree = GTK_TREE (container);
533 children = tree->children;
537 child = children->data;
538 children = children->next;
540 (* callback) (child, callback_data);
545 gtk_tree_map (GtkWidget *widget)
552 g_return_if_fail (widget != NULL);
553 g_return_if_fail (GTK_IS_TREE (widget));
555 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
556 tree = GTK_TREE (widget);
558 if(GTK_IS_TREE(widget->parent))
560 /* set root tree for this tree */
561 tree->root_tree = GTK_TREE(widget->parent)->root_tree;
563 tree->level = GTK_TREE(GTK_WIDGET(tree)->parent)->level+1;
564 tree->indent_value = GTK_TREE(GTK_WIDGET(tree)->parent)->indent_value;
565 tree->current_indent = GTK_TREE(GTK_WIDGET(tree)->parent)->current_indent +
567 tree->view_mode = GTK_TREE(GTK_WIDGET(tree)->parent)->view_mode;
568 tree->view_line = GTK_TREE(GTK_WIDGET(tree)->parent)->view_line;
571 tree->root_tree = tree;
573 children = tree->children;
576 child = children->data;
577 children = children->next;
579 if (GTK_WIDGET_VISIBLE (child) &&
580 !GTK_WIDGET_MAPPED (child))
581 gtk_widget_map (child);
583 if (GTK_TREE_ITEM (child)->subtree)
585 child = GTK_WIDGET (GTK_TREE_ITEM (child)->subtree);
587 if (GTK_WIDGET_VISIBLE (child) && !GTK_WIDGET_MAPPED (child))
588 gtk_widget_map (child);
592 gdk_window_show (widget->window);
596 gtk_tree_motion_notify (GtkWidget *widget,
597 GdkEventMotion *event)
599 g_return_val_if_fail (widget != NULL, FALSE);
600 g_return_val_if_fail (GTK_IS_TREE (widget), FALSE);
601 g_return_val_if_fail (event != NULL, FALSE);
604 g_message("gtk_tree_motion_notify\n");
605 #endif /* TREE_DEBUG */
611 gtk_tree_realize (GtkWidget *widget)
613 GdkWindowAttr attributes;
614 gint attributes_mask;
617 g_return_if_fail (widget != NULL);
618 g_return_if_fail (GTK_IS_TREE (widget));
620 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
622 attributes.window_type = GDK_WINDOW_CHILD;
623 attributes.x = widget->allocation.x;
624 attributes.y = widget->allocation.y;
625 attributes.width = widget->allocation.width;
626 attributes.height = widget->allocation.height;
627 attributes.wclass = GDK_INPUT_OUTPUT;
628 attributes.visual = gtk_widget_get_visual (widget);
629 attributes.colormap = gtk_widget_get_colormap (widget);
630 attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
632 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
634 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
635 gdk_window_set_user_data (widget->window, widget);
637 widget->style = gtk_style_attach (widget->style, widget->window);
638 gdk_window_set_background (widget->window,
639 &widget->style->base[GTK_STATE_NORMAL]);
643 gtk_tree_remove_item (GtkTree *container,
648 g_return_if_fail (container != NULL);
649 g_return_if_fail (GTK_IS_TREE (container));
650 g_return_if_fail (widget != NULL);
651 g_return_if_fail (container == GTK_TREE (widget->parent));
653 item_list = g_list_append (NULL, widget);
655 gtk_tree_remove_items (GTK_TREE (container), item_list);
657 g_list_free (item_list);
660 /* used by gtk_tree_remove_items to make the function independant of
661 order in list of items to remove.
662 Sort item bu depth in tree */
664 gtk_tree_sort_item_by_depth(GtkWidget* a, GtkWidget* b)
666 if((GTK_TREE(a->parent)->level) < (GTK_TREE(b->parent)->level))
668 if((GTK_TREE(a->parent)->level) > (GTK_TREE(b->parent)->level))
675 gtk_tree_remove_items (GtkTree *tree,
679 GList *selected_widgets;
685 g_return_if_fail (tree != NULL);
686 g_return_if_fail (GTK_IS_TREE (tree));
689 g_message("+ gtk_tree_remove_items [ tree %#x items list %#x ]\n", (int)tree, (int)items);
690 #endif /* TREE_DEBUG */
692 /* We may not yet be mapped, so we actively have to find our
696 root_tree = tree->root_tree;
699 GtkWidget *tmp = GTK_WIDGET (tree);
700 while (tmp->parent && GTK_IS_TREE (tmp->parent))
703 root_tree = GTK_TREE (tmp);
707 selected_widgets = NULL;
712 g_message("* sort list by depth\n");
713 #endif /* TREE_DEBUG */
719 g_message ("* item [%#x] depth [%d]\n",
721 (int)GTK_TREE(GTK_WIDGET(tmp_list->data)->parent)->level);
722 #endif /* TREE_DEBUG */
724 sorted_list = g_list_insert_sorted(sorted_list,
726 (GCompareFunc)gtk_tree_sort_item_by_depth);
727 tmp_list = g_list_next(tmp_list);
731 /* print sorted list */
732 g_message("* sorted list result\n");
733 tmp_list = sorted_list;
736 g_message("* item [%#x] depth [%d]\n",
738 (int)GTK_TREE(GTK_WIDGET(tmp_list->data)->parent)->level);
739 tmp_list = g_list_next(tmp_list);
741 #endif /* TREE_DEBUG */
744 g_message("* scan sorted list\n");
745 #endif /* TREE_DEBUG */
747 tmp_list = sorted_list;
750 widget = tmp_list->data;
751 tmp_list = tmp_list->next;
754 g_message("* item [%#x] subtree [%#x]\n",
755 (int)widget, (int)GTK_TREE_ITEM_SUBTREE(widget));
756 #endif /* TREE_DEBUG */
758 /* get real owner of this widget */
759 real_tree = GTK_TREE(widget->parent);
761 g_message("* subtree having this widget [%#x]\n", (int)real_tree);
762 #endif /* TREE_DEBUG */
765 if (widget->state == GTK_STATE_SELECTED)
767 selected_widgets = g_list_prepend (selected_widgets, widget);
769 g_message("* selected widget - adding it in selected list [%#x]\n",
770 (int)selected_widgets);
771 #endif /* TREE_DEBUG */
774 /* remove this item from its real parent */
776 g_message("* remove widget from its owner tree\n");
777 #endif /* TREE_DEBUG */
778 real_tree->children = g_list_remove (real_tree->children, widget);
780 /* remove subtree associate at this item if it exist */
781 if(GTK_TREE_ITEM(widget)->subtree)
784 g_message("* remove subtree associate at this item [%#x]\n",
785 (int) GTK_TREE_ITEM(widget)->subtree);
786 #endif /* TREE_DEBUG */
787 if (GTK_WIDGET_MAPPED (GTK_TREE_ITEM(widget)->subtree))
788 gtk_widget_unmap (GTK_TREE_ITEM(widget)->subtree);
790 gtk_widget_unparent (GTK_TREE_ITEM(widget)->subtree);
791 GTK_TREE_ITEM(widget)->subtree = NULL;
794 /* really remove widget for this item */
796 g_message("* unmap and unparent widget [%#x]\n", (int)widget);
797 #endif /* TREE_DEBUG */
798 if (GTK_WIDGET_MAPPED (widget))
799 gtk_widget_unmap (widget);
801 gtk_widget_unparent (widget);
803 /* delete subtree if there is no children in it */
804 if(real_tree->children == NULL &&
805 real_tree != root_tree)
808 g_message("* owner tree don't have children ... destroy it\n");
809 #endif /* TREE_DEBUG */
810 gtk_tree_item_remove_subtree(GTK_TREE_ITEM(real_tree->tree_owner));
814 g_message("* next item in list\n");
815 #endif /* TREE_DEBUG */
818 if (selected_widgets)
821 g_message("* scan selected item list\n");
822 #endif /* TREE_DEBUG */
823 tmp_list = selected_widgets;
826 widget = tmp_list->data;
827 tmp_list = tmp_list->next;
830 g_message("* widget [%#x] subtree [%#x]\n",
831 (int)widget, (int)GTK_TREE_ITEM_SUBTREE(widget));
832 #endif /* TREE_DEBUG */
834 /* remove widget of selection */
835 root_tree->selection = g_list_remove (root_tree->selection, widget);
837 /* unref it to authorize is destruction */
838 gtk_widget_unref (widget);
841 /* emit only one selection_changed signal */
842 gtk_signal_emit (GTK_OBJECT (root_tree),
843 tree_signals[SELECTION_CHANGED]);
847 g_message("* free selected_widgets list\n");
848 #endif /* TREE_DEBUG */
849 g_list_free (selected_widgets);
850 g_list_free (sorted_list);
852 if (root_tree->children && !root_tree->selection &&
853 (root_tree->selection_mode == GTK_SELECTION_BROWSE))
856 g_message("* BROWSE mode, select another item\n");
857 #endif /* TREE_DEBUG */
858 widget = root_tree->children->data;
859 gtk_tree_select_child (root_tree, widget);
862 if (GTK_WIDGET_VISIBLE (root_tree))
865 g_message("* query queue resizing for root_tree\n");
866 #endif /* TREE_DEBUG */
867 gtk_widget_queue_resize (GTK_WIDGET (root_tree));
872 gtk_tree_select_child (GtkTree *tree,
873 GtkWidget *tree_item)
875 g_return_if_fail (tree != NULL);
876 g_return_if_fail (GTK_IS_TREE (tree));
877 g_return_if_fail (tree_item != NULL);
878 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
880 gtk_signal_emit (GTK_OBJECT (tree), tree_signals[SELECT_CHILD], tree_item);
884 gtk_tree_select_item (GtkTree *tree,
889 g_return_if_fail (tree != NULL);
890 g_return_if_fail (GTK_IS_TREE (tree));
892 tmp_list = g_list_nth (tree->children, item);
894 gtk_tree_select_child (tree, GTK_WIDGET (tmp_list->data));
899 gtk_tree_size_allocate (GtkWidget *widget,
900 GtkAllocation *allocation)
903 GtkWidget *child, *subtree;
904 GtkAllocation child_allocation;
908 g_return_if_fail (widget != NULL);
909 g_return_if_fail (GTK_IS_TREE (widget));
910 g_return_if_fail (allocation != NULL);
912 tree = GTK_TREE (widget);
914 widget->allocation = *allocation;
915 if (GTK_WIDGET_REALIZED (widget))
916 gdk_window_move_resize (widget->window,
917 allocation->x, allocation->y,
918 allocation->width, allocation->height);
922 child_allocation.x = GTK_CONTAINER (tree)->border_width;
923 child_allocation.y = GTK_CONTAINER (tree)->border_width;
924 child_allocation.width = MAX (1, (gint)allocation->width - child_allocation.x * 2);
926 children = tree->children;
930 child = children->data;
931 children = children->next;
933 if (GTK_WIDGET_VISIBLE (child))
935 GtkRequisition child_requisition;
936 gtk_widget_get_child_requisition (child, &child_requisition);
938 child_allocation.height = child_requisition.height;
940 gtk_widget_size_allocate (child, &child_allocation);
942 child_allocation.y += child_allocation.height;
944 if((subtree = GTK_TREE_ITEM(child)->subtree))
945 if(GTK_WIDGET_VISIBLE (subtree))
947 child_allocation.height = subtree->requisition.height;
948 gtk_widget_size_allocate (subtree, &child_allocation);
949 child_allocation.y += child_allocation.height;
958 gtk_tree_size_request (GtkWidget *widget,
959 GtkRequisition *requisition)
962 GtkWidget *child, *subtree;
964 GtkRequisition child_requisition;
967 g_return_if_fail (widget != NULL);
968 g_return_if_fail (GTK_IS_TREE (widget));
969 g_return_if_fail (requisition != NULL);
971 tree = GTK_TREE (widget);
972 requisition->width = 0;
973 requisition->height = 0;
975 children = tree->children;
978 child = children->data;
979 children = children->next;
981 if (GTK_WIDGET_VISIBLE (child))
983 gtk_widget_size_request (child, &child_requisition);
985 requisition->width = MAX (requisition->width, child_requisition.width);
986 requisition->height += child_requisition.height;
988 if((subtree = GTK_TREE_ITEM(child)->subtree) &&
989 GTK_WIDGET_VISIBLE (subtree))
991 gtk_widget_size_request (subtree, &child_requisition);
993 requisition->width = MAX (requisition->width,
994 child_requisition.width);
996 requisition->height += child_requisition.height;
1001 requisition->width += GTK_CONTAINER (tree)->border_width * 2;
1002 requisition->height += GTK_CONTAINER (tree)->border_width * 2;
1004 requisition->width = MAX (requisition->width, 1);
1005 requisition->height = MAX (requisition->height, 1);
1010 gtk_tree_unmap (GtkWidget *widget)
1013 g_return_if_fail (widget != NULL);
1014 g_return_if_fail (GTK_IS_TREE (widget));
1016 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
1017 gdk_window_hide (widget->window);
1022 gtk_tree_unselect_child (GtkTree *tree,
1023 GtkWidget *tree_item)
1025 g_return_if_fail (tree != NULL);
1026 g_return_if_fail (GTK_IS_TREE (tree));
1027 g_return_if_fail (tree_item != NULL);
1028 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
1030 gtk_signal_emit (GTK_OBJECT (tree), tree_signals[UNSELECT_CHILD], tree_item);
1034 gtk_tree_unselect_item (GtkTree *tree,
1039 g_return_if_fail (tree != NULL);
1040 g_return_if_fail (GTK_IS_TREE (tree));
1042 tmp_list = g_list_nth (tree->children, item);
1044 gtk_tree_unselect_child (tree, GTK_WIDGET (tmp_list->data));
1049 gtk_real_tree_select_child (GtkTree *tree,
1052 GList *selection, *root_selection;
1054 GtkWidget *tmp_item;
1056 g_return_if_fail (tree != NULL);
1057 g_return_if_fail (GTK_IS_TREE (tree));
1058 g_return_if_fail (child != NULL);
1059 g_return_if_fail (GTK_IS_TREE_ITEM (child));
1061 root_selection = tree->root_tree->selection;
1063 switch (tree->root_tree->selection_mode)
1065 case GTK_SELECTION_SINGLE:
1067 selection = root_selection;
1069 /* remove old selection list */
1072 tmp_item = selection->data;
1074 if (tmp_item != child)
1076 gtk_tree_item_deselect (GTK_TREE_ITEM (tmp_item));
1078 tmp_list = selection;
1079 selection = selection->next;
1081 root_selection = g_list_remove_link (root_selection, tmp_list);
1082 gtk_widget_unref (tmp_item);
1084 g_list_free (tmp_list);
1087 selection = selection->next;
1090 if (child->state == GTK_STATE_NORMAL)
1092 gtk_tree_item_select (GTK_TREE_ITEM (child));
1093 root_selection = g_list_prepend (root_selection, child);
1094 gtk_widget_ref (child);
1096 else if (child->state == GTK_STATE_SELECTED)
1098 gtk_tree_item_deselect (GTK_TREE_ITEM (child));
1099 root_selection = g_list_remove (root_selection, child);
1100 gtk_widget_unref (child);
1103 tree->root_tree->selection = root_selection;
1105 gtk_signal_emit (GTK_OBJECT (tree->root_tree),
1106 tree_signals[SELECTION_CHANGED]);
1110 case GTK_SELECTION_BROWSE:
1111 selection = root_selection;
1115 tmp_item = selection->data;
1117 if (tmp_item != child)
1119 gtk_tree_item_deselect (GTK_TREE_ITEM (tmp_item));
1121 tmp_list = selection;
1122 selection = selection->next;
1124 root_selection = g_list_remove_link (root_selection, tmp_list);
1125 gtk_widget_unref (tmp_item);
1127 g_list_free (tmp_list);
1130 selection = selection->next;
1133 tree->root_tree->selection = root_selection;
1135 if (child->state == GTK_STATE_NORMAL)
1137 gtk_tree_item_select (GTK_TREE_ITEM (child));
1138 root_selection = g_list_prepend (root_selection, child);
1139 gtk_widget_ref (child);
1140 tree->root_tree->selection = root_selection;
1141 gtk_signal_emit (GTK_OBJECT (tree->root_tree),
1142 tree_signals[SELECTION_CHANGED]);
1146 case GTK_SELECTION_MULTIPLE:
1147 if (child->state == GTK_STATE_NORMAL)
1149 gtk_tree_item_select (GTK_TREE_ITEM (child));
1150 root_selection = g_list_prepend (root_selection, child);
1151 gtk_widget_ref (child);
1152 tree->root_tree->selection = root_selection;
1153 gtk_signal_emit (GTK_OBJECT (tree->root_tree),
1154 tree_signals[SELECTION_CHANGED]);
1156 else if (child->state == GTK_STATE_SELECTED)
1158 gtk_tree_item_deselect (GTK_TREE_ITEM (child));
1159 root_selection = g_list_remove (root_selection, child);
1160 gtk_widget_unref (child);
1161 tree->root_tree->selection = root_selection;
1162 gtk_signal_emit (GTK_OBJECT (tree->root_tree),
1163 tree_signals[SELECTION_CHANGED]);
1167 case GTK_SELECTION_EXTENDED:
1173 gtk_real_tree_unselect_child (GtkTree *tree,
1176 g_return_if_fail (tree != NULL);
1177 g_return_if_fail (GTK_IS_TREE (tree));
1178 g_return_if_fail (child != NULL);
1179 g_return_if_fail (GTK_IS_TREE_ITEM (child));
1181 switch (tree->selection_mode)
1183 case GTK_SELECTION_SINGLE:
1184 case GTK_SELECTION_MULTIPLE:
1185 case GTK_SELECTION_BROWSE:
1186 if (child->state == GTK_STATE_SELECTED)
1188 GtkTree* root_tree = GTK_TREE_ROOT_TREE(tree);
1189 gtk_tree_item_deselect (GTK_TREE_ITEM (child));
1190 root_tree->selection = g_list_remove (root_tree->selection, child);
1191 gtk_widget_unref (child);
1192 gtk_signal_emit (GTK_OBJECT (tree->root_tree),
1193 tree_signals[SELECTION_CHANGED]);
1197 case GTK_SELECTION_EXTENDED:
1203 gtk_tree_set_selection_mode (GtkTree *tree,
1204 GtkSelectionMode mode)
1206 g_return_if_fail (tree != NULL);
1207 g_return_if_fail (GTK_IS_TREE (tree));
1209 tree->selection_mode = mode;
1213 gtk_tree_set_view_mode (GtkTree *tree,
1214 GtkTreeViewMode mode)
1216 g_return_if_fail (tree != NULL);
1217 g_return_if_fail (GTK_IS_TREE (tree));
1219 tree->view_mode = mode;
1223 gtk_tree_set_view_lines (GtkTree *tree,
1226 g_return_if_fail (tree != NULL);
1227 g_return_if_fail (GTK_IS_TREE (tree));
1229 tree->view_line = flag;