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 "gtkeventbox.h"
29 #include "gtkpixmap.h"
31 #include "gtksignal.h"
32 #define GTK_ENABLE_BROKEN
34 #include "gtktreeitem.h"
36 #include "tree_plus.xpm"
37 #include "tree_minus.xpm"
39 #define DEFAULT_DELTA 9
47 typedef struct _GtkTreePixmaps GtkTreePixmaps;
49 struct _GtkTreePixmaps {
51 GdkColormap *colormap;
53 GdkPixmap *pixmap_plus;
54 GdkPixmap *pixmap_minus;
56 GdkBitmap *mask_minus;
59 static GList *pixmaps = NULL;
61 static void gtk_tree_item_class_init (GtkTreeItemClass *klass);
62 static void gtk_tree_item_init (GtkTreeItem *tree_item);
63 static void gtk_tree_item_realize (GtkWidget *widget);
64 static void gtk_tree_item_size_request (GtkWidget *widget,
65 GtkRequisition *requisition);
66 static void gtk_tree_item_size_allocate (GtkWidget *widget,
67 GtkAllocation *allocation);
68 static void gtk_tree_item_paint (GtkWidget *widget,
70 static gint gtk_tree_item_button_press (GtkWidget *widget,
71 GdkEventButton *event);
72 static gint gtk_tree_item_expose (GtkWidget *widget,
73 GdkEventExpose *event);
74 static void gtk_tree_item_forall (GtkContainer *container,
75 gboolean include_internals,
77 gpointer callback_data);
79 static void gtk_real_tree_item_select (GtkItem *item);
80 static void gtk_real_tree_item_deselect (GtkItem *item);
81 static void gtk_real_tree_item_toggle (GtkItem *item);
82 static void gtk_real_tree_item_expand (GtkTreeItem *item);
83 static void gtk_real_tree_item_collapse (GtkTreeItem *item);
84 static void gtk_real_tree_item_expand (GtkTreeItem *item);
85 static void gtk_real_tree_item_collapse (GtkTreeItem *item);
86 static void gtk_tree_item_destroy (GtkObject *object);
87 static gint gtk_tree_item_subtree_button_click (GtkWidget *widget);
88 static void gtk_tree_item_subtree_button_changed_state (GtkWidget *widget);
90 static void gtk_tree_item_map(GtkWidget*);
91 static void gtk_tree_item_unmap(GtkWidget*);
93 static void gtk_tree_item_add_pixmaps (GtkTreeItem *tree_item);
94 static void gtk_tree_item_remove_pixmaps (GtkTreeItem *tree_item);
96 static GtkItemClass *parent_class = NULL;
97 static guint tree_item_signals[LAST_SIGNAL] = { 0 };
100 gtk_tree_item_get_type (void)
102 static GtkType tree_item_type = 0;
106 static const GtkTypeInfo tree_item_info =
109 sizeof (GtkTreeItem),
110 sizeof (GtkTreeItemClass),
111 (GtkClassInitFunc) gtk_tree_item_class_init,
112 (GtkObjectInitFunc) gtk_tree_item_init,
113 /* reserved_1 */ NULL,
114 /* reserved_2 */ NULL,
115 (GtkClassInitFunc) NULL,
118 tree_item_type = gtk_type_unique (gtk_item_get_type (), &tree_item_info);
121 return tree_item_type;
125 gtk_tree_item_class_init (GtkTreeItemClass *class)
127 GtkObjectClass *object_class;
128 GtkWidgetClass *widget_class;
129 GtkContainerClass *container_class;
130 GtkItemClass *item_class;
132 parent_class = gtk_type_class (GTK_TYPE_ITEM);
134 object_class = (GtkObjectClass*) class;
135 widget_class = (GtkWidgetClass*) class;
136 item_class = (GtkItemClass*) class;
137 container_class = (GtkContainerClass*) class;
139 object_class->destroy = gtk_tree_item_destroy;
141 widget_class->realize = gtk_tree_item_realize;
142 widget_class->size_request = gtk_tree_item_size_request;
143 widget_class->size_allocate = gtk_tree_item_size_allocate;
144 widget_class->button_press_event = gtk_tree_item_button_press;
145 widget_class->expose_event = gtk_tree_item_expose;
146 widget_class->map = gtk_tree_item_map;
147 widget_class->unmap = gtk_tree_item_unmap;
149 container_class->forall = gtk_tree_item_forall;
151 item_class->select = gtk_real_tree_item_select;
152 item_class->deselect = gtk_real_tree_item_deselect;
153 item_class->toggle = gtk_real_tree_item_toggle;
155 class->expand = gtk_real_tree_item_expand;
156 class->collapse = gtk_real_tree_item_collapse;
158 tree_item_signals[EXPAND_TREE] =
159 gtk_signal_new ("expand",
161 GTK_CLASS_TYPE (object_class),
162 GTK_SIGNAL_OFFSET (GtkTreeItemClass, expand),
163 gtk_marshal_VOID__VOID,
165 tree_item_signals[COLLAPSE_TREE] =
166 gtk_signal_new ("collapse",
168 GTK_CLASS_TYPE (object_class),
169 GTK_SIGNAL_OFFSET (GtkTreeItemClass, collapse),
170 gtk_marshal_VOID__VOID,
174 /* callback for event box mouse event */
176 gtk_tree_item_subtree_button_click (GtkWidget *widget)
180 g_return_val_if_fail (GTK_IS_EVENT_BOX (widget), FALSE);
182 item = (GtkTreeItem*) gtk_object_get_user_data (GTK_OBJECT (widget));
183 if (!GTK_WIDGET_IS_SENSITIVE (item))
187 gtk_tree_item_collapse (item);
189 gtk_tree_item_expand (item);
194 /* callback for event box state changed */
196 gtk_tree_item_subtree_button_changed_state (GtkWidget *widget)
198 g_return_if_fail (GTK_IS_EVENT_BOX (widget));
200 if (GTK_WIDGET_VISIBLE (widget))
203 if (widget->state == GTK_STATE_NORMAL)
204 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
206 gdk_window_set_background (widget->window, &widget->style->bg[widget->state]);
208 if (GTK_WIDGET_DRAWABLE (widget))
209 gdk_window_clear_area (widget->window, 0, 0,
210 widget->allocation.width, widget->allocation.height);
215 gtk_tree_item_init (GtkTreeItem *tree_item)
217 GtkWidget *eventbox, *pixmapwid;
219 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
221 tree_item->expanded = FALSE;
222 tree_item->subtree = NULL;
223 GTK_WIDGET_SET_FLAGS (tree_item, GTK_CAN_FOCUS);
225 /* create an event box containing one pixmaps */
226 eventbox = gtk_event_box_new();
227 gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK);
228 gtk_signal_connect(GTK_OBJECT(eventbox), "state_changed",
229 (GtkSignalFunc)gtk_tree_item_subtree_button_changed_state,
231 gtk_signal_connect(GTK_OBJECT(eventbox), "realize",
232 (GtkSignalFunc)gtk_tree_item_subtree_button_changed_state,
234 gtk_signal_connect(GTK_OBJECT(eventbox), "button_press_event",
235 (GtkSignalFunc)gtk_tree_item_subtree_button_click,
237 gtk_object_set_user_data(GTK_OBJECT(eventbox), tree_item);
238 tree_item->pixmaps_box = eventbox;
240 /* create pixmap for button '+' */
241 pixmapwid = gtk_type_new (gtk_pixmap_get_type ());
242 if (!tree_item->expanded)
243 gtk_container_add (GTK_CONTAINER (eventbox), pixmapwid);
244 gtk_widget_show (pixmapwid);
245 tree_item->plus_pix_widget = pixmapwid;
246 gtk_widget_ref (tree_item->plus_pix_widget);
247 gtk_object_sink (GTK_OBJECT (tree_item->plus_pix_widget));
249 /* create pixmap for button '-' */
250 pixmapwid = gtk_type_new (gtk_pixmap_get_type ());
251 if (tree_item->expanded)
252 gtk_container_add (GTK_CONTAINER (eventbox), pixmapwid);
253 gtk_widget_show (pixmapwid);
254 tree_item->minus_pix_widget = pixmapwid;
255 gtk_widget_ref (tree_item->minus_pix_widget);
256 gtk_object_sink (GTK_OBJECT (tree_item->minus_pix_widget));
258 gtk_widget_set_parent (eventbox, GTK_WIDGET (tree_item));
263 gtk_tree_item_new (void)
265 GtkWidget *tree_item;
267 tree_item = GTK_WIDGET (gtk_type_new (gtk_tree_item_get_type ()));
273 gtk_tree_item_new_with_label (const gchar *label)
275 GtkWidget *tree_item;
276 GtkWidget *label_widget;
278 tree_item = gtk_tree_item_new ();
279 label_widget = gtk_label_new (label);
280 gtk_misc_set_alignment (GTK_MISC (label_widget), 0.0, 0.5);
282 gtk_container_add (GTK_CONTAINER (tree_item), label_widget);
283 gtk_widget_show (label_widget);
290 gtk_tree_item_set_subtree (GtkTreeItem *tree_item,
293 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
294 g_return_if_fail (GTK_IS_TREE (subtree));
296 if (tree_item->subtree)
298 g_warning("there is already a subtree for this tree item\n");
302 tree_item->subtree = subtree;
303 GTK_TREE (subtree)->tree_owner = GTK_WIDGET (tree_item);
305 /* show subtree button */
306 if (tree_item->pixmaps_box)
307 gtk_widget_show (tree_item->pixmaps_box);
309 if (tree_item->expanded)
310 gtk_widget_show (subtree);
312 gtk_widget_hide (subtree);
314 gtk_widget_set_parent (subtree, GTK_WIDGET (tree_item)->parent);
316 if (GTK_WIDGET_REALIZED (subtree->parent))
317 gtk_widget_realize (subtree);
319 if (GTK_WIDGET_VISIBLE (subtree->parent) && GTK_WIDGET_VISIBLE (subtree))
321 if (GTK_WIDGET_MAPPED (subtree->parent))
322 gtk_widget_map (subtree);
324 gtk_widget_queue_resize (subtree);
329 gtk_tree_item_select (GtkTreeItem *tree_item)
331 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
333 gtk_item_select (GTK_ITEM (tree_item));
337 gtk_tree_item_deselect (GtkTreeItem *tree_item)
339 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
341 gtk_item_deselect (GTK_ITEM (tree_item));
345 gtk_tree_item_expand (GtkTreeItem *tree_item)
347 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
349 gtk_signal_emit (GTK_OBJECT (tree_item), tree_item_signals[EXPAND_TREE], NULL);
353 gtk_tree_item_collapse (GtkTreeItem *tree_item)
355 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
357 gtk_signal_emit (GTK_OBJECT (tree_item), tree_item_signals[COLLAPSE_TREE], NULL);
361 gtk_tree_item_add_pixmaps (GtkTreeItem *tree_item)
364 GdkColormap *colormap;
365 GtkTreePixmaps *pixmap_node = NULL;
367 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
369 if (tree_item->pixmaps)
372 colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_item));
377 pixmap_node = (GtkTreePixmaps *)tmp_list->data;
379 if (pixmap_node->colormap == colormap)
382 tmp_list = tmp_list->next;
387 pixmap_node->refcount++;
388 tree_item->pixmaps = tmp_list;
392 pixmap_node = g_new (GtkTreePixmaps, 1);
394 pixmap_node->colormap = colormap;
395 gdk_colormap_ref (colormap);
397 pixmap_node->refcount = 1;
399 /* create pixmaps for plus icon */
400 pixmap_node->pixmap_plus =
401 gdk_pixmap_create_from_xpm_d (GTK_WIDGET (tree_item)->window,
402 &pixmap_node->mask_plus,
406 /* create pixmaps for minus icon */
407 pixmap_node->pixmap_minus =
408 gdk_pixmap_create_from_xpm_d (GTK_WIDGET (tree_item)->window,
409 &pixmap_node->mask_minus,
413 tree_item->pixmaps = pixmaps = g_list_prepend (pixmaps, pixmap_node);
416 gtk_pixmap_set (GTK_PIXMAP (tree_item->plus_pix_widget),
417 pixmap_node->pixmap_plus, pixmap_node->mask_plus);
418 gtk_pixmap_set (GTK_PIXMAP (tree_item->minus_pix_widget),
419 pixmap_node->pixmap_minus, pixmap_node->mask_minus);
423 gtk_tree_item_remove_pixmaps (GtkTreeItem *tree_item)
425 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
427 if (tree_item->pixmaps)
429 GtkTreePixmaps *pixmap_node = (GtkTreePixmaps *)tree_item->pixmaps->data;
431 g_assert (pixmap_node->refcount > 0);
433 if (--pixmap_node->refcount == 0)
435 gdk_colormap_unref (pixmap_node->colormap);
436 gdk_pixmap_unref (pixmap_node->pixmap_plus);
437 gdk_bitmap_unref (pixmap_node->mask_plus);
438 gdk_pixmap_unref (pixmap_node->pixmap_minus);
439 gdk_bitmap_unref (pixmap_node->mask_minus);
441 pixmaps = g_list_remove_link (pixmaps, tree_item->pixmaps);
442 g_list_free_1 (tree_item->pixmaps);
443 g_free (pixmap_node);
446 tree_item->pixmaps = NULL;
451 gtk_tree_item_realize (GtkWidget *widget)
453 g_return_if_fail (GTK_IS_TREE_ITEM (widget));
455 if (GTK_WIDGET_CLASS (parent_class)->realize)
456 (* GTK_WIDGET_CLASS (parent_class)->realize) (widget);
458 gdk_window_set_background (widget->window,
459 &widget->style->base[GTK_STATE_NORMAL]);
461 gtk_tree_item_add_pixmaps (GTK_TREE_ITEM (widget));
465 gtk_tree_item_size_request (GtkWidget *widget,
466 GtkRequisition *requisition)
470 GtkRequisition child_requisition;
472 g_return_if_fail (GTK_IS_TREE_ITEM (widget));
473 g_return_if_fail (requisition != NULL);
475 bin = GTK_BIN (widget);
476 item = GTK_TREE_ITEM(widget);
478 requisition->width = (GTK_CONTAINER (widget)->border_width +
479 widget->style->xthickness) * 2;
480 requisition->height = GTK_CONTAINER (widget)->border_width * 2;
482 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
484 GtkRequisition pix_requisition;
486 gtk_widget_size_request (bin->child, &child_requisition);
488 requisition->width += child_requisition.width;
490 gtk_widget_size_request (item->pixmaps_box,
492 requisition->width += pix_requisition.width + DEFAULT_DELTA +
493 GTK_TREE (widget->parent)->current_indent;
495 requisition->height += MAX (child_requisition.height,
496 pix_requisition.height);
501 gtk_tree_item_size_allocate (GtkWidget *widget,
502 GtkAllocation *allocation)
506 GtkAllocation child_allocation;
510 g_return_if_fail (GTK_IS_TREE_ITEM (widget));
511 g_return_if_fail (allocation != NULL);
513 widget->allocation = *allocation;
514 if (GTK_WIDGET_REALIZED (widget))
515 gdk_window_move_resize (widget->window,
516 allocation->x, allocation->y,
517 allocation->width, allocation->height);
519 bin = GTK_BIN (widget);
520 item = GTK_TREE_ITEM(widget);
524 border_width = (GTK_CONTAINER (widget)->border_width +
525 widget->style->xthickness);
527 child_allocation.x = border_width + GTK_TREE(widget->parent)->current_indent;
528 child_allocation.y = GTK_CONTAINER (widget)->border_width;
530 child_allocation.width = item->pixmaps_box->requisition.width;
531 child_allocation.height = item->pixmaps_box->requisition.height;
533 temp = allocation->height - child_allocation.height;
534 child_allocation.y += ( temp / 2 ) + ( temp % 2 );
536 gtk_widget_size_allocate (item->pixmaps_box, &child_allocation);
538 child_allocation.y = GTK_CONTAINER (widget)->border_width;
539 child_allocation.height = MAX (1, (gint)allocation->height - child_allocation.y * 2);
540 child_allocation.x += item->pixmaps_box->requisition.width+DEFAULT_DELTA;
542 child_allocation.width =
543 MAX (1, (gint)allocation->width - ((gint)child_allocation.x + border_width));
545 gtk_widget_size_allocate (bin->child, &child_allocation);
550 gtk_tree_item_draw_lines (GtkWidget *widget)
554 guint lx1, ly1, lx2, ly2;
557 g_return_if_fail (GTK_IS_TREE_ITEM (widget));
559 item = GTK_TREE_ITEM(widget);
560 tree = GTK_TREE(widget->parent);
562 if (!tree->view_line)
565 gc = widget->style->text_gc[GTK_STATE_NORMAL];
567 /* draw vertical line */
568 lx1 = item->pixmaps_box->allocation.width;
569 lx1 = lx2 = ((lx1 / 2) + (lx1 % 2) +
570 GTK_CONTAINER (widget)->border_width + 1 + tree->current_indent);
572 ly2 = widget->allocation.height;
574 if (g_list_last (tree->children)->data == widget)
575 ly2 = (ly2 / 2) + (ly2 % 2);
577 if (tree != tree->root_tree)
578 gdk_draw_line (widget->window, gc, lx1, ly1, lx2, ly2);
580 /* draw vertical line for subtree connecting */
581 if(g_list_last(tree->children)->data != (gpointer)widget)
582 ly2 = (ly2 / 2) + (ly2 % 2);
584 lx2 += DEFAULT_DELTA;
586 if (item->subtree && item->expanded)
587 gdk_draw_line (widget->window, gc,
588 lx2, ly2, lx2, widget->allocation.height);
590 /* draw horizontal line */
594 gdk_draw_line (widget->window, gc, lx1, ly1, lx2, ly2);
596 lx2 -= DEFAULT_DELTA+2;
598 ly2 = widget->allocation.height;
600 if (tree != tree->root_tree)
602 item = GTK_TREE_ITEM (tree->tree_owner);
603 tree = GTK_TREE (GTK_WIDGET (tree)->parent);
604 while (tree != tree->root_tree)
606 lx1 = lx2 -= tree->indent_value;
608 if (g_list_last (tree->children)->data != item)
609 gdk_draw_line (widget->window, gc, lx1, ly1, lx2, ly2);
610 item = GTK_TREE_ITEM (tree->tree_owner);
611 tree = GTK_TREE (GTK_WIDGET (tree)->parent);
617 gtk_tree_item_paint (GtkWidget *widget,
621 GdkRectangle child_area, item_area;
622 GtkTreeItem* tree_item;
624 g_return_if_fail (GTK_IS_TREE_ITEM (widget));
625 g_return_if_fail (area != NULL);
627 /* FIXME: We should honor tree->view_mode, here - I think
628 * the desired effect is that when the mode is VIEW_ITEM,
629 * only the subitem is drawn as selected, not the entire
630 * line. (Like the way that the tree in Windows Explorer
633 if (GTK_WIDGET_DRAWABLE (widget))
635 bin = GTK_BIN (widget);
636 tree_item = GTK_TREE_ITEM(widget);
638 if (widget->state == GTK_STATE_NORMAL)
640 gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
641 gdk_window_clear_area (widget->window, area->x, area->y, area->width, area->height);
645 if (!GTK_WIDGET_IS_SENSITIVE (widget))
646 gtk_paint_flat_box(widget->style, widget->window,
647 widget->state, GTK_STATE_INSENSITIVE,
648 area, widget, "treeitem",
651 gtk_paint_flat_box(widget->style, widget->window,
652 widget->state, GTK_SHADOW_ETCHED_OUT,
653 area, widget, "treeitem",
657 /* draw left size of tree item */
660 item_area.width = (tree_item->pixmaps_box->allocation.width + DEFAULT_DELTA +
661 GTK_TREE (widget->parent)->current_indent + 2);
662 item_area.height = widget->allocation.height;
665 if (gdk_rectangle_intersect(&item_area, area, &child_area))
668 gtk_tree_item_draw_lines(widget);
670 if (tree_item->pixmaps_box &&
671 GTK_WIDGET_VISIBLE(tree_item->pixmaps_box) &&
672 gtk_widget_intersect (tree_item->pixmaps_box, area, &child_area))
673 gtk_widget_draw (tree_item->pixmaps_box, &child_area);
676 if (GTK_WIDGET_HAS_FOCUS (widget))
677 gtk_paint_focus (widget->style, widget->window,
678 NULL, widget, "treeitem",
680 widget->allocation.width - 1,
681 widget->allocation.height - 1);
687 gtk_tree_item_button_press (GtkWidget *widget,
688 GdkEventButton *event)
691 g_return_val_if_fail (GTK_IS_TREE_ITEM (widget), FALSE);
692 g_return_val_if_fail (event != NULL, FALSE);
694 if (event->type == GDK_BUTTON_PRESS
695 && GTK_WIDGET_IS_SENSITIVE(widget)
696 && !GTK_WIDGET_HAS_FOCUS (widget))
697 gtk_widget_grab_focus (widget);
699 return (event->type == GDK_BUTTON_PRESS && GTK_WIDGET_IS_SENSITIVE(widget));
703 gtk_tree_item_expose (GtkWidget *widget,
704 GdkEventExpose *event)
706 g_return_val_if_fail (GTK_IS_TREE_ITEM (widget), FALSE);
707 g_return_val_if_fail (event != NULL, FALSE);
709 if (GTK_WIDGET_DRAWABLE (widget))
711 gtk_tree_item_paint (widget, &event->area);
713 (* GTK_WIDGET_CLASS (parent_class)->expose_event) (widget, event);
720 gtk_real_tree_item_select (GtkItem *item)
722 GtkTreeItem *tree_item;
725 g_return_if_fail (GTK_IS_TREE_ITEM (item));
727 tree_item = GTK_TREE_ITEM (item);
728 widget = GTK_WIDGET (item);
730 gtk_widget_set_state (GTK_WIDGET (item), GTK_STATE_SELECTED);
732 if (!widget->parent || GTK_TREE (widget->parent)->view_mode == GTK_TREE_VIEW_LINE)
733 gtk_widget_set_state (GTK_TREE_ITEM (item)->pixmaps_box, GTK_STATE_SELECTED);
737 gtk_real_tree_item_deselect (GtkItem *item)
739 GtkTreeItem *tree_item;
742 g_return_if_fail (GTK_IS_TREE_ITEM (item));
744 tree_item = GTK_TREE_ITEM (item);
745 widget = GTK_WIDGET (item);
747 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
749 if (!widget->parent || GTK_TREE (widget->parent)->view_mode == GTK_TREE_VIEW_LINE)
750 gtk_widget_set_state (tree_item->pixmaps_box, GTK_STATE_NORMAL);
754 gtk_real_tree_item_toggle (GtkItem *item)
756 g_return_if_fail (GTK_IS_TREE_ITEM (item));
758 if(!GTK_WIDGET_IS_SENSITIVE(item))
761 if (GTK_WIDGET (item)->parent && GTK_IS_TREE (GTK_WIDGET (item)->parent))
762 gtk_tree_select_child (GTK_TREE (GTK_WIDGET (item)->parent),
766 /* Should we really bother with this bit? A listitem not in a list?
767 * -Johannes Keukelaar
768 * yes, always be on the safe side!
771 if (GTK_WIDGET (item)->state == GTK_STATE_SELECTED)
772 gtk_widget_set_state (GTK_WIDGET (item), GTK_STATE_NORMAL);
774 gtk_widget_set_state (GTK_WIDGET (item), GTK_STATE_SELECTED);
779 gtk_real_tree_item_expand (GtkTreeItem *tree_item)
783 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
785 if (tree_item->subtree && !tree_item->expanded)
787 tree = GTK_TREE (GTK_WIDGET (tree_item)->parent);
789 /* hide subtree widget */
790 gtk_widget_show (tree_item->subtree);
792 /* hide button '+' and show button '-' */
793 if (tree_item->pixmaps_box)
795 gtk_container_remove (GTK_CONTAINER (tree_item->pixmaps_box),
796 tree_item->plus_pix_widget);
797 gtk_container_add (GTK_CONTAINER (tree_item->pixmaps_box),
798 tree_item->minus_pix_widget);
801 gtk_widget_queue_resize (GTK_WIDGET (tree->root_tree));
802 tree_item->expanded = TRUE;
807 gtk_real_tree_item_collapse (GtkTreeItem *tree_item)
811 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
813 if (tree_item->subtree && tree_item->expanded)
815 tree = GTK_TREE (GTK_WIDGET (tree_item)->parent);
817 /* hide subtree widget */
818 gtk_widget_hide (tree_item->subtree);
820 /* hide button '-' and show button '+' */
821 if (tree_item->pixmaps_box)
823 gtk_container_remove (GTK_CONTAINER (tree_item->pixmaps_box),
824 tree_item->minus_pix_widget);
825 gtk_container_add (GTK_CONTAINER (tree_item->pixmaps_box),
826 tree_item->plus_pix_widget);
829 gtk_widget_queue_resize (GTK_WIDGET (tree->root_tree));
830 tree_item->expanded = FALSE;
835 gtk_tree_item_destroy (GtkObject *object)
840 g_return_if_fail (GTK_IS_TREE_ITEM (object));
843 g_message("+ gtk_tree_item_destroy [object %#x]\n", (int)object);
844 #endif /* TREE_DEBUG */
846 item = GTK_TREE_ITEM(object);
848 /* free sub tree if it exist */
849 child = item->subtree;
852 gtk_widget_ref (child);
853 gtk_widget_unparent (child);
854 gtk_widget_destroy (child);
855 gtk_widget_unref (child);
856 item->subtree = NULL;
859 /* free pixmaps box */
860 child = item->pixmaps_box;
863 gtk_widget_ref (child);
864 gtk_widget_unparent (child);
865 gtk_widget_destroy (child);
866 gtk_widget_unref (child);
867 item->pixmaps_box = NULL;
871 /* destroy plus pixmap */
872 if (item->plus_pix_widget)
874 gtk_widget_destroy (item->plus_pix_widget);
875 gtk_widget_unref (item->plus_pix_widget);
876 item->plus_pix_widget = NULL;
879 /* destroy minus pixmap */
880 if (item->minus_pix_widget)
882 gtk_widget_destroy (item->minus_pix_widget);
883 gtk_widget_unref (item->minus_pix_widget);
884 item->minus_pix_widget = NULL;
887 /* By removing the pixmaps here, and not in unrealize, we depend on
888 * the fact that a widget can never change colormap or visual.
890 gtk_tree_item_remove_pixmaps (item);
892 GTK_OBJECT_CLASS (parent_class)->destroy (object);
895 g_message("- gtk_tree_item_destroy\n");
896 #endif /* TREE_DEBUG */
900 gtk_tree_item_remove_subtree (GtkTreeItem* item)
902 g_return_if_fail (GTK_IS_TREE_ITEM(item));
903 g_return_if_fail (item->subtree != NULL);
905 if (GTK_TREE (item->subtree)->children)
907 /* The following call will remove the children and call
908 * gtk_tree_item_remove_subtree() again. So we are done.
910 gtk_tree_remove_items (GTK_TREE (item->subtree),
911 GTK_TREE (item->subtree)->children);
915 if (GTK_WIDGET_MAPPED (item->subtree))
916 gtk_widget_unmap (item->subtree);
918 gtk_widget_unparent (item->subtree);
920 if (item->pixmaps_box)
921 gtk_widget_hide (item->pixmaps_box);
923 item->subtree = NULL;
927 item->expanded = FALSE;
928 if (item->pixmaps_box)
930 gtk_container_remove (GTK_CONTAINER (item->pixmaps_box),
931 item->minus_pix_widget);
932 gtk_container_add (GTK_CONTAINER (item->pixmaps_box),
933 item->plus_pix_widget);
939 gtk_tree_item_map (GtkWidget *widget)
944 g_return_if_fail (GTK_IS_TREE_ITEM (widget));
946 bin = GTK_BIN (widget);
947 item = GTK_TREE_ITEM(widget);
949 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
951 if(item->pixmaps_box &&
952 GTK_WIDGET_VISIBLE (item->pixmaps_box) &&
953 !GTK_WIDGET_MAPPED (item->pixmaps_box))
954 gtk_widget_map (item->pixmaps_box);
957 GTK_WIDGET_VISIBLE (bin->child) &&
958 !GTK_WIDGET_MAPPED (bin->child))
959 gtk_widget_map (bin->child);
961 gdk_window_show (widget->window);
965 gtk_tree_item_unmap (GtkWidget *widget)
970 g_return_if_fail (GTK_IS_TREE_ITEM (widget));
972 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
973 bin = GTK_BIN (widget);
974 item = GTK_TREE_ITEM(widget);
976 gdk_window_hide (widget->window);
978 if(item->pixmaps_box &&
979 GTK_WIDGET_VISIBLE (item->pixmaps_box) &&
980 GTK_WIDGET_MAPPED (item->pixmaps_box))
981 gtk_widget_unmap (bin->child);
984 GTK_WIDGET_VISIBLE (bin->child) &&
985 GTK_WIDGET_MAPPED (bin->child))
986 gtk_widget_unmap (bin->child);
990 gtk_tree_item_forall (GtkContainer *container,
991 gboolean include_internals,
992 GtkCallback callback,
993 gpointer callback_data)
996 GtkTreeItem *tree_item;
998 g_return_if_fail (GTK_IS_TREE_ITEM (container));
999 g_return_if_fail (callback != NULL);
1001 bin = GTK_BIN (container);
1002 tree_item = GTK_TREE_ITEM (container);
1005 (* callback) (bin->child, callback_data);
1006 if (include_internals && tree_item->subtree)
1007 (* callback) (tree_item->subtree, callback_data);