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 "gtkmarshalers.h"
32 #include "gtksignal.h"
33 #define GTK_ENABLE_BROKEN
35 #include "gtktreeitem.h"
37 #include "tree_plus.xpm"
38 #include "tree_minus.xpm"
40 #define DEFAULT_DELTA 9
48 typedef struct _GtkTreePixmaps GtkTreePixmaps;
50 struct _GtkTreePixmaps {
52 GdkColormap *colormap;
54 GdkPixmap *pixmap_plus;
55 GdkPixmap *pixmap_minus;
57 GdkBitmap *mask_minus;
60 static GList *pixmaps = NULL;
62 static void gtk_tree_item_class_init (GtkTreeItemClass *klass);
63 static void gtk_tree_item_init (GtkTreeItem *tree_item);
64 static void gtk_tree_item_realize (GtkWidget *widget);
65 static void gtk_tree_item_size_request (GtkWidget *widget,
66 GtkRequisition *requisition);
67 static void gtk_tree_item_size_allocate (GtkWidget *widget,
68 GtkAllocation *allocation);
69 static void gtk_tree_item_paint (GtkWidget *widget,
71 static gint gtk_tree_item_button_press (GtkWidget *widget,
72 GdkEventButton *event);
73 static gint gtk_tree_item_expose (GtkWidget *widget,
74 GdkEventExpose *event);
75 static void gtk_tree_item_forall (GtkContainer *container,
76 gboolean include_internals,
78 gpointer callback_data);
80 static void gtk_real_tree_item_select (GtkItem *item);
81 static void gtk_real_tree_item_deselect (GtkItem *item);
82 static void gtk_real_tree_item_toggle (GtkItem *item);
83 static void gtk_real_tree_item_expand (GtkTreeItem *item);
84 static void gtk_real_tree_item_collapse (GtkTreeItem *item);
85 static void gtk_real_tree_item_expand (GtkTreeItem *item);
86 static void gtk_real_tree_item_collapse (GtkTreeItem *item);
87 static void gtk_tree_item_destroy (GtkObject *object);
88 static gint gtk_tree_item_subtree_button_click (GtkWidget *widget);
89 static void gtk_tree_item_subtree_button_changed_state (GtkWidget *widget);
91 static void gtk_tree_item_map(GtkWidget*);
92 static void gtk_tree_item_unmap(GtkWidget*);
94 static void gtk_tree_item_add_pixmaps (GtkTreeItem *tree_item);
95 static void gtk_tree_item_remove_pixmaps (GtkTreeItem *tree_item);
97 static GtkItemClass *parent_class = NULL;
98 static guint tree_item_signals[LAST_SIGNAL] = { 0 };
101 gtk_tree_item_get_type (void)
103 static GtkType tree_item_type = 0;
107 static const GtkTypeInfo tree_item_info =
110 sizeof (GtkTreeItem),
111 sizeof (GtkTreeItemClass),
112 (GtkClassInitFunc) gtk_tree_item_class_init,
113 (GtkObjectInitFunc) gtk_tree_item_init,
114 /* reserved_1 */ NULL,
115 /* reserved_2 */ NULL,
116 (GtkClassInitFunc) NULL,
119 tree_item_type = gtk_type_unique (gtk_item_get_type (), &tree_item_info);
122 return tree_item_type;
126 gtk_tree_item_class_init (GtkTreeItemClass *class)
128 GtkObjectClass *object_class;
129 GtkWidgetClass *widget_class;
130 GtkContainerClass *container_class;
131 GtkItemClass *item_class;
133 parent_class = gtk_type_class (GTK_TYPE_ITEM);
135 object_class = (GtkObjectClass*) class;
136 widget_class = (GtkWidgetClass*) class;
137 item_class = (GtkItemClass*) class;
138 container_class = (GtkContainerClass*) class;
140 object_class->destroy = gtk_tree_item_destroy;
142 widget_class->realize = gtk_tree_item_realize;
143 widget_class->size_request = gtk_tree_item_size_request;
144 widget_class->size_allocate = gtk_tree_item_size_allocate;
145 widget_class->button_press_event = gtk_tree_item_button_press;
146 widget_class->expose_event = gtk_tree_item_expose;
147 widget_class->map = gtk_tree_item_map;
148 widget_class->unmap = gtk_tree_item_unmap;
150 container_class->forall = gtk_tree_item_forall;
152 item_class->select = gtk_real_tree_item_select;
153 item_class->deselect = gtk_real_tree_item_deselect;
154 item_class->toggle = gtk_real_tree_item_toggle;
156 class->expand = gtk_real_tree_item_expand;
157 class->collapse = gtk_real_tree_item_collapse;
159 tree_item_signals[EXPAND_TREE] =
160 gtk_signal_new ("expand",
162 GTK_CLASS_TYPE (object_class),
163 GTK_SIGNAL_OFFSET (GtkTreeItemClass, expand),
164 _gtk_marshal_VOID__VOID,
166 tree_item_signals[COLLAPSE_TREE] =
167 gtk_signal_new ("collapse",
169 GTK_CLASS_TYPE (object_class),
170 GTK_SIGNAL_OFFSET (GtkTreeItemClass, collapse),
171 _gtk_marshal_VOID__VOID,
175 /* callback for event box mouse event */
177 gtk_tree_item_subtree_button_click (GtkWidget *widget)
181 g_return_val_if_fail (GTK_IS_EVENT_BOX (widget), FALSE);
183 item = (GtkTreeItem*) gtk_object_get_user_data (GTK_OBJECT (widget));
184 if (!GTK_WIDGET_IS_SENSITIVE (item))
188 gtk_tree_item_collapse (item);
190 gtk_tree_item_expand (item);
195 /* callback for event box state changed */
197 gtk_tree_item_subtree_button_changed_state (GtkWidget *widget)
199 g_return_if_fail (GTK_IS_EVENT_BOX (widget));
201 if (GTK_WIDGET_VISIBLE (widget))
204 if (widget->state == GTK_STATE_NORMAL)
205 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
207 gdk_window_set_background (widget->window, &widget->style->bg[widget->state]);
209 if (GTK_WIDGET_DRAWABLE (widget))
210 gdk_window_clear_area (widget->window, 0, 0,
211 widget->allocation.width, widget->allocation.height);
216 gtk_tree_item_init (GtkTreeItem *tree_item)
218 GtkWidget *eventbox, *pixmapwid;
220 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
222 tree_item->expanded = FALSE;
223 tree_item->subtree = NULL;
224 GTK_WIDGET_SET_FLAGS (tree_item, GTK_CAN_FOCUS);
226 /* create an event box containing one pixmaps */
227 eventbox = gtk_event_box_new();
228 gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK);
229 gtk_signal_connect(GTK_OBJECT(eventbox), "state_changed",
230 (GtkSignalFunc)gtk_tree_item_subtree_button_changed_state,
232 gtk_signal_connect(GTK_OBJECT(eventbox), "realize",
233 (GtkSignalFunc)gtk_tree_item_subtree_button_changed_state,
235 gtk_signal_connect(GTK_OBJECT(eventbox), "button_press_event",
236 (GtkSignalFunc)gtk_tree_item_subtree_button_click,
238 gtk_object_set_user_data(GTK_OBJECT(eventbox), tree_item);
239 tree_item->pixmaps_box = eventbox;
241 /* create pixmap for button '+' */
242 pixmapwid = gtk_type_new (gtk_pixmap_get_type ());
243 if (!tree_item->expanded)
244 gtk_container_add (GTK_CONTAINER (eventbox), pixmapwid);
245 gtk_widget_show (pixmapwid);
246 tree_item->plus_pix_widget = pixmapwid;
247 gtk_widget_ref (tree_item->plus_pix_widget);
248 gtk_object_sink (GTK_OBJECT (tree_item->plus_pix_widget));
250 /* create pixmap for button '-' */
251 pixmapwid = gtk_type_new (gtk_pixmap_get_type ());
252 if (tree_item->expanded)
253 gtk_container_add (GTK_CONTAINER (eventbox), pixmapwid);
254 gtk_widget_show (pixmapwid);
255 tree_item->minus_pix_widget = pixmapwid;
256 gtk_widget_ref (tree_item->minus_pix_widget);
257 gtk_object_sink (GTK_OBJECT (tree_item->minus_pix_widget));
259 gtk_widget_set_parent (eventbox, GTK_WIDGET (tree_item));
264 gtk_tree_item_new (void)
266 GtkWidget *tree_item;
268 tree_item = GTK_WIDGET (gtk_type_new (gtk_tree_item_get_type ()));
274 gtk_tree_item_new_with_label (const gchar *label)
276 GtkWidget *tree_item;
277 GtkWidget *label_widget;
279 tree_item = gtk_tree_item_new ();
280 label_widget = gtk_label_new (label);
281 gtk_misc_set_alignment (GTK_MISC (label_widget), 0.0, 0.5);
283 gtk_container_add (GTK_CONTAINER (tree_item), label_widget);
284 gtk_widget_show (label_widget);
291 gtk_tree_item_set_subtree (GtkTreeItem *tree_item,
294 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
295 g_return_if_fail (GTK_IS_TREE (subtree));
297 if (tree_item->subtree)
299 g_warning("there is already a subtree for this tree item\n");
303 tree_item->subtree = subtree;
304 GTK_TREE (subtree)->tree_owner = GTK_WIDGET (tree_item);
306 /* show subtree button */
307 if (tree_item->pixmaps_box)
308 gtk_widget_show (tree_item->pixmaps_box);
310 if (tree_item->expanded)
311 gtk_widget_show (subtree);
313 gtk_widget_hide (subtree);
315 gtk_widget_set_parent (subtree, GTK_WIDGET (tree_item)->parent);
319 gtk_tree_item_select (GtkTreeItem *tree_item)
321 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
323 gtk_item_select (GTK_ITEM (tree_item));
327 gtk_tree_item_deselect (GtkTreeItem *tree_item)
329 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
331 gtk_item_deselect (GTK_ITEM (tree_item));
335 gtk_tree_item_expand (GtkTreeItem *tree_item)
337 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
339 gtk_signal_emit (GTK_OBJECT (tree_item), tree_item_signals[EXPAND_TREE], NULL);
343 gtk_tree_item_collapse (GtkTreeItem *tree_item)
345 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
347 gtk_signal_emit (GTK_OBJECT (tree_item), tree_item_signals[COLLAPSE_TREE], NULL);
351 gtk_tree_item_add_pixmaps (GtkTreeItem *tree_item)
354 GdkColormap *colormap;
355 GtkTreePixmaps *pixmap_node = NULL;
357 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
359 if (tree_item->pixmaps)
362 colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_item));
367 pixmap_node = (GtkTreePixmaps *)tmp_list->data;
369 if (pixmap_node->colormap == colormap)
372 tmp_list = tmp_list->next;
377 pixmap_node->refcount++;
378 tree_item->pixmaps = tmp_list;
382 pixmap_node = g_new (GtkTreePixmaps, 1);
384 pixmap_node->colormap = colormap;
385 gdk_colormap_ref (colormap);
387 pixmap_node->refcount = 1;
389 /* create pixmaps for plus icon */
390 pixmap_node->pixmap_plus =
391 gdk_pixmap_create_from_xpm_d (GTK_WIDGET (tree_item)->window,
392 &pixmap_node->mask_plus,
396 /* create pixmaps for minus icon */
397 pixmap_node->pixmap_minus =
398 gdk_pixmap_create_from_xpm_d (GTK_WIDGET (tree_item)->window,
399 &pixmap_node->mask_minus,
403 tree_item->pixmaps = pixmaps = g_list_prepend (pixmaps, pixmap_node);
406 gtk_pixmap_set (GTK_PIXMAP (tree_item->plus_pix_widget),
407 pixmap_node->pixmap_plus, pixmap_node->mask_plus);
408 gtk_pixmap_set (GTK_PIXMAP (tree_item->minus_pix_widget),
409 pixmap_node->pixmap_minus, pixmap_node->mask_minus);
413 gtk_tree_item_remove_pixmaps (GtkTreeItem *tree_item)
415 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
417 if (tree_item->pixmaps)
419 GtkTreePixmaps *pixmap_node = (GtkTreePixmaps *)tree_item->pixmaps->data;
421 g_assert (pixmap_node->refcount > 0);
423 if (--pixmap_node->refcount == 0)
425 gdk_colormap_unref (pixmap_node->colormap);
426 gdk_pixmap_unref (pixmap_node->pixmap_plus);
427 gdk_bitmap_unref (pixmap_node->mask_plus);
428 gdk_pixmap_unref (pixmap_node->pixmap_minus);
429 gdk_bitmap_unref (pixmap_node->mask_minus);
431 pixmaps = g_list_remove_link (pixmaps, tree_item->pixmaps);
432 g_list_free_1 (tree_item->pixmaps);
433 g_free (pixmap_node);
436 tree_item->pixmaps = NULL;
441 gtk_tree_item_realize (GtkWidget *widget)
443 g_return_if_fail (GTK_IS_TREE_ITEM (widget));
445 if (GTK_WIDGET_CLASS (parent_class)->realize)
446 (* GTK_WIDGET_CLASS (parent_class)->realize) (widget);
448 gdk_window_set_background (widget->window,
449 &widget->style->base[GTK_STATE_NORMAL]);
451 gtk_tree_item_add_pixmaps (GTK_TREE_ITEM (widget));
455 gtk_tree_item_size_request (GtkWidget *widget,
456 GtkRequisition *requisition)
460 GtkRequisition child_requisition;
462 g_return_if_fail (GTK_IS_TREE_ITEM (widget));
463 g_return_if_fail (requisition != NULL);
465 bin = GTK_BIN (widget);
466 item = GTK_TREE_ITEM(widget);
468 requisition->width = (GTK_CONTAINER (widget)->border_width +
469 widget->style->xthickness) * 2;
470 requisition->height = GTK_CONTAINER (widget)->border_width * 2;
472 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
474 GtkRequisition pix_requisition;
476 gtk_widget_size_request (bin->child, &child_requisition);
478 requisition->width += child_requisition.width;
480 gtk_widget_size_request (item->pixmaps_box,
482 requisition->width += pix_requisition.width + DEFAULT_DELTA +
483 GTK_TREE (widget->parent)->current_indent;
485 requisition->height += MAX (child_requisition.height,
486 pix_requisition.height);
491 gtk_tree_item_size_allocate (GtkWidget *widget,
492 GtkAllocation *allocation)
496 GtkAllocation child_allocation;
500 g_return_if_fail (GTK_IS_TREE_ITEM (widget));
501 g_return_if_fail (allocation != NULL);
503 widget->allocation = *allocation;
504 if (GTK_WIDGET_REALIZED (widget))
505 gdk_window_move_resize (widget->window,
506 allocation->x, allocation->y,
507 allocation->width, allocation->height);
509 bin = GTK_BIN (widget);
510 item = GTK_TREE_ITEM(widget);
514 border_width = (GTK_CONTAINER (widget)->border_width +
515 widget->style->xthickness);
517 child_allocation.x = border_width + GTK_TREE(widget->parent)->current_indent;
518 child_allocation.y = GTK_CONTAINER (widget)->border_width;
520 child_allocation.width = item->pixmaps_box->requisition.width;
521 child_allocation.height = item->pixmaps_box->requisition.height;
523 temp = allocation->height - child_allocation.height;
524 child_allocation.y += ( temp / 2 ) + ( temp % 2 );
526 gtk_widget_size_allocate (item->pixmaps_box, &child_allocation);
528 child_allocation.y = GTK_CONTAINER (widget)->border_width;
529 child_allocation.height = MAX (1, (gint)allocation->height - child_allocation.y * 2);
530 child_allocation.x += item->pixmaps_box->requisition.width+DEFAULT_DELTA;
532 child_allocation.width =
533 MAX (1, (gint)allocation->width - ((gint)child_allocation.x + border_width));
535 gtk_widget_size_allocate (bin->child, &child_allocation);
540 gtk_tree_item_draw_lines (GtkWidget *widget)
544 guint lx1, ly1, lx2, ly2;
547 g_return_if_fail (GTK_IS_TREE_ITEM (widget));
549 item = GTK_TREE_ITEM(widget);
550 tree = GTK_TREE(widget->parent);
552 if (!tree->view_line)
555 gc = widget->style->text_gc[GTK_STATE_NORMAL];
557 /* draw vertical line */
558 lx1 = item->pixmaps_box->allocation.width;
559 lx1 = lx2 = ((lx1 / 2) + (lx1 % 2) +
560 GTK_CONTAINER (widget)->border_width + 1 + tree->current_indent);
562 ly2 = widget->allocation.height;
564 if (g_list_last (tree->children)->data == widget)
565 ly2 = (ly2 / 2) + (ly2 % 2);
567 if (tree != tree->root_tree)
568 gdk_draw_line (widget->window, gc, lx1, ly1, lx2, ly2);
570 /* draw vertical line for subtree connecting */
571 if(g_list_last(tree->children)->data != (gpointer)widget)
572 ly2 = (ly2 / 2) + (ly2 % 2);
574 lx2 += DEFAULT_DELTA;
576 if (item->subtree && item->expanded)
577 gdk_draw_line (widget->window, gc,
578 lx2, ly2, lx2, widget->allocation.height);
580 /* draw horizontal line */
584 gdk_draw_line (widget->window, gc, lx1, ly1, lx2, ly2);
586 lx2 -= DEFAULT_DELTA+2;
588 ly2 = widget->allocation.height;
590 if (tree != tree->root_tree)
592 item = GTK_TREE_ITEM (tree->tree_owner);
593 tree = GTK_TREE (GTK_WIDGET (tree)->parent);
594 while (tree != tree->root_tree)
596 lx1 = lx2 -= tree->indent_value;
598 if (g_list_last (tree->children)->data != item)
599 gdk_draw_line (widget->window, gc, lx1, ly1, lx2, ly2);
600 item = GTK_TREE_ITEM (tree->tree_owner);
601 tree = GTK_TREE (GTK_WIDGET (tree)->parent);
607 gtk_tree_item_paint (GtkWidget *widget,
611 GdkRectangle child_area, item_area;
612 GtkTreeItem* tree_item;
614 g_return_if_fail (GTK_IS_TREE_ITEM (widget));
615 g_return_if_fail (area != NULL);
617 /* FIXME: We should honor tree->view_mode, here - I think
618 * the desired effect is that when the mode is VIEW_ITEM,
619 * only the subitem is drawn as selected, not the entire
620 * line. (Like the way that the tree in Windows Explorer
623 if (GTK_WIDGET_DRAWABLE (widget))
625 bin = GTK_BIN (widget);
626 tree_item = GTK_TREE_ITEM(widget);
628 if (widget->state == GTK_STATE_NORMAL)
630 gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
631 gdk_window_clear_area (widget->window, area->x, area->y, area->width, area->height);
635 if (!GTK_WIDGET_IS_SENSITIVE (widget))
636 gtk_paint_flat_box(widget->style, widget->window,
637 widget->state, GTK_STATE_INSENSITIVE,
638 area, widget, "treeitem",
641 gtk_paint_flat_box(widget->style, widget->window,
642 widget->state, GTK_SHADOW_ETCHED_OUT,
643 area, widget, "treeitem",
647 /* draw left size of tree item */
650 item_area.width = (tree_item->pixmaps_box->allocation.width + DEFAULT_DELTA +
651 GTK_TREE (widget->parent)->current_indent + 2);
652 item_area.height = widget->allocation.height;
655 if (gdk_rectangle_intersect(&item_area, area, &child_area))
658 gtk_tree_item_draw_lines(widget);
660 if (tree_item->pixmaps_box &&
661 GTK_WIDGET_VISIBLE(tree_item->pixmaps_box) &&
662 gtk_widget_intersect (tree_item->pixmaps_box, area, &child_area))
663 gtk_widget_draw (tree_item->pixmaps_box, &child_area);
666 if (GTK_WIDGET_HAS_FOCUS (widget))
667 gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget),
668 NULL, widget, "treeitem",
670 widget->allocation.width,
671 widget->allocation.height);
677 gtk_tree_item_button_press (GtkWidget *widget,
678 GdkEventButton *event)
681 g_return_val_if_fail (GTK_IS_TREE_ITEM (widget), FALSE);
682 g_return_val_if_fail (event != NULL, FALSE);
684 if (event->type == GDK_BUTTON_PRESS
685 && GTK_WIDGET_IS_SENSITIVE(widget)
686 && !GTK_WIDGET_HAS_FOCUS (widget))
687 gtk_widget_grab_focus (widget);
689 return (event->type == GDK_BUTTON_PRESS && GTK_WIDGET_IS_SENSITIVE(widget));
693 gtk_tree_item_expose_child (GtkWidget *child,
694 gpointer client_data)
697 GtkWidget *container;
698 GdkEventExpose *event;
699 } *data = client_data;
700 GdkEventExpose child_event;
702 if (GTK_WIDGET_DRAWABLE (child) &&
703 GTK_WIDGET_NO_WINDOW (child) &&
704 (child->window == data->event->window))
706 child_event = *data->event;
708 child_event.region = gtk_widget_region_intersect (child,
709 data->event->region);
710 if (!gdk_region_empty (child_event.region))
712 gdk_region_get_clipbox (child_event.region, &child_event.area);
713 gtk_widget_send_expose (child, (GdkEvent *) &child_event);
715 gdk_region_destroy (child_event.region);
720 gtk_tree_item_expose (GtkWidget *widget,
721 GdkEventExpose *event)
724 GtkWidget *container;
725 GdkEventExpose *event;
728 g_return_val_if_fail (GTK_IS_TREE_ITEM (widget), FALSE);
729 g_return_val_if_fail (event != NULL, FALSE);
731 if (GTK_WIDGET_DRAWABLE (widget))
733 gtk_tree_item_paint (widget, &event->area);
735 data.container = widget;
738 gtk_container_forall (GTK_CONTAINER (widget),
739 gtk_tree_item_expose_child,
747 gtk_real_tree_item_select (GtkItem *item)
749 GtkTreeItem *tree_item;
752 g_return_if_fail (GTK_IS_TREE_ITEM (item));
754 tree_item = GTK_TREE_ITEM (item);
755 widget = GTK_WIDGET (item);
757 gtk_widget_set_state (GTK_WIDGET (item), GTK_STATE_SELECTED);
759 if (!widget->parent || GTK_TREE (widget->parent)->view_mode == GTK_TREE_VIEW_LINE)
760 gtk_widget_set_state (GTK_TREE_ITEM (item)->pixmaps_box, GTK_STATE_SELECTED);
764 gtk_real_tree_item_deselect (GtkItem *item)
766 GtkTreeItem *tree_item;
769 g_return_if_fail (GTK_IS_TREE_ITEM (item));
771 tree_item = GTK_TREE_ITEM (item);
772 widget = GTK_WIDGET (item);
774 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
776 if (!widget->parent || GTK_TREE (widget->parent)->view_mode == GTK_TREE_VIEW_LINE)
777 gtk_widget_set_state (tree_item->pixmaps_box, GTK_STATE_NORMAL);
781 gtk_real_tree_item_toggle (GtkItem *item)
783 g_return_if_fail (GTK_IS_TREE_ITEM (item));
785 if(!GTK_WIDGET_IS_SENSITIVE(item))
788 if (GTK_WIDGET (item)->parent && GTK_IS_TREE (GTK_WIDGET (item)->parent))
789 gtk_tree_select_child (GTK_TREE (GTK_WIDGET (item)->parent),
793 /* Should we really bother with this bit? A listitem not in a list?
794 * -Johannes Keukelaar
795 * yes, always be on the safe side!
798 if (GTK_WIDGET (item)->state == GTK_STATE_SELECTED)
799 gtk_widget_set_state (GTK_WIDGET (item), GTK_STATE_NORMAL);
801 gtk_widget_set_state (GTK_WIDGET (item), GTK_STATE_SELECTED);
806 gtk_real_tree_item_expand (GtkTreeItem *tree_item)
810 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
812 if (tree_item->subtree && !tree_item->expanded)
814 tree = GTK_TREE (GTK_WIDGET (tree_item)->parent);
816 /* hide subtree widget */
817 gtk_widget_show (tree_item->subtree);
819 /* hide button '+' and show button '-' */
820 if (tree_item->pixmaps_box)
822 gtk_container_remove (GTK_CONTAINER (tree_item->pixmaps_box),
823 tree_item->plus_pix_widget);
824 gtk_container_add (GTK_CONTAINER (tree_item->pixmaps_box),
825 tree_item->minus_pix_widget);
828 gtk_widget_queue_resize (GTK_WIDGET (tree->root_tree));
829 tree_item->expanded = TRUE;
834 gtk_real_tree_item_collapse (GtkTreeItem *tree_item)
838 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
840 if (tree_item->subtree && tree_item->expanded)
842 tree = GTK_TREE (GTK_WIDGET (tree_item)->parent);
844 /* hide subtree widget */
845 gtk_widget_hide (tree_item->subtree);
847 /* hide button '-' and show button '+' */
848 if (tree_item->pixmaps_box)
850 gtk_container_remove (GTK_CONTAINER (tree_item->pixmaps_box),
851 tree_item->minus_pix_widget);
852 gtk_container_add (GTK_CONTAINER (tree_item->pixmaps_box),
853 tree_item->plus_pix_widget);
856 gtk_widget_queue_resize (GTK_WIDGET (tree->root_tree));
857 tree_item->expanded = FALSE;
862 gtk_tree_item_destroy (GtkObject *object)
867 g_return_if_fail (GTK_IS_TREE_ITEM (object));
870 g_message("+ gtk_tree_item_destroy [object %#x]\n", (int)object);
871 #endif /* TREE_DEBUG */
873 item = GTK_TREE_ITEM(object);
875 /* free sub tree if it exist */
876 child = item->subtree;
879 gtk_widget_ref (child);
880 gtk_widget_unparent (child);
881 gtk_widget_destroy (child);
882 gtk_widget_unref (child);
883 item->subtree = NULL;
886 /* free pixmaps box */
887 child = item->pixmaps_box;
890 gtk_widget_ref (child);
891 gtk_widget_unparent (child);
892 gtk_widget_destroy (child);
893 gtk_widget_unref (child);
894 item->pixmaps_box = NULL;
898 /* destroy plus pixmap */
899 if (item->plus_pix_widget)
901 gtk_widget_destroy (item->plus_pix_widget);
902 gtk_widget_unref (item->plus_pix_widget);
903 item->plus_pix_widget = NULL;
906 /* destroy minus pixmap */
907 if (item->minus_pix_widget)
909 gtk_widget_destroy (item->minus_pix_widget);
910 gtk_widget_unref (item->minus_pix_widget);
911 item->minus_pix_widget = NULL;
914 /* By removing the pixmaps here, and not in unrealize, we depend on
915 * the fact that a widget can never change colormap or visual.
917 gtk_tree_item_remove_pixmaps (item);
919 GTK_OBJECT_CLASS (parent_class)->destroy (object);
922 g_message("- gtk_tree_item_destroy\n");
923 #endif /* TREE_DEBUG */
927 gtk_tree_item_remove_subtree (GtkTreeItem* item)
929 g_return_if_fail (GTK_IS_TREE_ITEM(item));
930 g_return_if_fail (item->subtree != NULL);
932 if (GTK_TREE (item->subtree)->children)
934 /* The following call will remove the children and call
935 * gtk_tree_item_remove_subtree() again. So we are done.
937 gtk_tree_remove_items (GTK_TREE (item->subtree),
938 GTK_TREE (item->subtree)->children);
942 if (GTK_WIDGET_MAPPED (item->subtree))
943 gtk_widget_unmap (item->subtree);
945 gtk_widget_unparent (item->subtree);
947 if (item->pixmaps_box)
948 gtk_widget_hide (item->pixmaps_box);
950 item->subtree = NULL;
954 item->expanded = FALSE;
955 if (item->pixmaps_box)
957 gtk_container_remove (GTK_CONTAINER (item->pixmaps_box),
958 item->minus_pix_widget);
959 gtk_container_add (GTK_CONTAINER (item->pixmaps_box),
960 item->plus_pix_widget);
966 gtk_tree_item_map (GtkWidget *widget)
971 g_return_if_fail (GTK_IS_TREE_ITEM (widget));
973 bin = GTK_BIN (widget);
974 item = GTK_TREE_ITEM(widget);
976 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
978 if(item->pixmaps_box &&
979 GTK_WIDGET_VISIBLE (item->pixmaps_box) &&
980 !GTK_WIDGET_MAPPED (item->pixmaps_box))
981 gtk_widget_map (item->pixmaps_box);
984 GTK_WIDGET_VISIBLE (bin->child) &&
985 !GTK_WIDGET_MAPPED (bin->child))
986 gtk_widget_map (bin->child);
988 gdk_window_show (widget->window);
992 gtk_tree_item_unmap (GtkWidget *widget)
997 g_return_if_fail (GTK_IS_TREE_ITEM (widget));
999 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
1000 bin = GTK_BIN (widget);
1001 item = GTK_TREE_ITEM(widget);
1003 gdk_window_hide (widget->window);
1005 if(item->pixmaps_box &&
1006 GTK_WIDGET_VISIBLE (item->pixmaps_box) &&
1007 GTK_WIDGET_MAPPED (item->pixmaps_box))
1008 gtk_widget_unmap (bin->child);
1011 GTK_WIDGET_VISIBLE (bin->child) &&
1012 GTK_WIDGET_MAPPED (bin->child))
1013 gtk_widget_unmap (bin->child);
1017 gtk_tree_item_forall (GtkContainer *container,
1018 gboolean include_internals,
1019 GtkCallback callback,
1020 gpointer callback_data)
1023 GtkTreeItem *tree_item;
1025 g_return_if_fail (GTK_IS_TREE_ITEM (container));
1026 g_return_if_fail (callback != NULL);
1028 bin = GTK_BIN (container);
1029 tree_item = GTK_TREE_ITEM (container);
1032 (* callback) (bin->child, callback_data);
1033 if (include_internals && tree_item->subtree)
1034 (* callback) (tree_item->subtree, callback_data);