1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
27 #undef GTK_DISABLE_DEPRECATED
30 #include "gtkeventbox.h"
31 #include "gtkpixmap.h"
33 #include "gtkmarshalers.h"
34 #include "gtksignal.h"
35 #define GTK_ENABLE_BROKEN
37 #include "gtktreeitem.h"
39 #include "tree_plus.xpm"
40 #include "tree_minus.xpm"
42 #define DEFAULT_DELTA 9
50 typedef struct _GtkTreePixmaps GtkTreePixmaps;
52 struct _GtkTreePixmaps {
54 GdkColormap *colormap;
56 GdkPixmap *pixmap_plus;
57 GdkPixmap *pixmap_minus;
59 GdkBitmap *mask_minus;
62 static GList *pixmaps = NULL;
64 static void gtk_tree_item_class_init (GtkTreeItemClass *klass);
65 static void gtk_tree_item_init (GtkTreeItem *tree_item);
66 static void gtk_tree_item_realize (GtkWidget *widget);
67 static void gtk_tree_item_size_request (GtkWidget *widget,
68 GtkRequisition *requisition);
69 static void gtk_tree_item_size_allocate (GtkWidget *widget,
70 GtkAllocation *allocation);
71 static void gtk_tree_item_paint (GtkWidget *widget,
73 static gint gtk_tree_item_button_press (GtkWidget *widget,
74 GdkEventButton *event);
75 static gint gtk_tree_item_expose (GtkWidget *widget,
76 GdkEventExpose *event);
77 static void gtk_tree_item_forall (GtkContainer *container,
78 gboolean include_internals,
80 gpointer callback_data);
82 static void gtk_real_tree_item_select (GtkItem *item);
83 static void gtk_real_tree_item_deselect (GtkItem *item);
84 static void gtk_real_tree_item_toggle (GtkItem *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_real_tree_item_expand (GtkTreeItem *item);
88 static void gtk_real_tree_item_collapse (GtkTreeItem *item);
89 static void gtk_tree_item_destroy (GtkObject *object);
90 static gint gtk_tree_item_subtree_button_click (GtkWidget *widget);
91 static void gtk_tree_item_subtree_button_changed_state (GtkWidget *widget);
93 static void gtk_tree_item_map(GtkWidget*);
94 static void gtk_tree_item_unmap(GtkWidget*);
96 static void gtk_tree_item_add_pixmaps (GtkTreeItem *tree_item);
97 static void gtk_tree_item_remove_pixmaps (GtkTreeItem *tree_item);
99 static GtkItemClass *parent_class = NULL;
100 static guint tree_item_signals[LAST_SIGNAL] = { 0 };
103 gtk_tree_item_get_type (void)
105 static GtkType tree_item_type = 0;
109 static const GtkTypeInfo tree_item_info =
112 sizeof (GtkTreeItem),
113 sizeof (GtkTreeItemClass),
114 (GtkClassInitFunc) gtk_tree_item_class_init,
115 (GtkObjectInitFunc) gtk_tree_item_init,
116 /* reserved_1 */ NULL,
117 /* reserved_2 */ NULL,
118 (GtkClassInitFunc) NULL,
121 tree_item_type = gtk_type_unique (gtk_item_get_type (), &tree_item_info);
124 return tree_item_type;
128 gtk_tree_item_class_init (GtkTreeItemClass *class)
130 GtkObjectClass *object_class;
131 GtkWidgetClass *widget_class;
132 GtkContainerClass *container_class;
133 GtkItemClass *item_class;
135 parent_class = gtk_type_class (GTK_TYPE_ITEM);
137 object_class = (GtkObjectClass*) class;
138 widget_class = (GtkWidgetClass*) class;
139 item_class = (GtkItemClass*) class;
140 container_class = (GtkContainerClass*) class;
142 object_class->destroy = gtk_tree_item_destroy;
144 widget_class->realize = gtk_tree_item_realize;
145 widget_class->size_request = gtk_tree_item_size_request;
146 widget_class->size_allocate = gtk_tree_item_size_allocate;
147 widget_class->button_press_event = gtk_tree_item_button_press;
148 widget_class->expose_event = gtk_tree_item_expose;
149 widget_class->map = gtk_tree_item_map;
150 widget_class->unmap = gtk_tree_item_unmap;
152 container_class->forall = gtk_tree_item_forall;
154 item_class->select = gtk_real_tree_item_select;
155 item_class->deselect = gtk_real_tree_item_deselect;
156 item_class->toggle = gtk_real_tree_item_toggle;
158 class->expand = gtk_real_tree_item_expand;
159 class->collapse = gtk_real_tree_item_collapse;
161 tree_item_signals[EXPAND_TREE] =
162 gtk_signal_new ("expand",
164 GTK_CLASS_TYPE (object_class),
165 GTK_SIGNAL_OFFSET (GtkTreeItemClass, expand),
166 _gtk_marshal_VOID__VOID,
168 tree_item_signals[COLLAPSE_TREE] =
169 gtk_signal_new ("collapse",
171 GTK_CLASS_TYPE (object_class),
172 GTK_SIGNAL_OFFSET (GtkTreeItemClass, collapse),
173 _gtk_marshal_VOID__VOID,
177 /* callback for event box mouse event */
179 gtk_tree_item_subtree_button_click (GtkWidget *widget)
183 g_return_val_if_fail (GTK_IS_EVENT_BOX (widget), FALSE);
185 item = (GtkTreeItem*) gtk_object_get_user_data (GTK_OBJECT (widget));
186 if (!GTK_WIDGET_IS_SENSITIVE (item))
190 gtk_tree_item_collapse (item);
192 gtk_tree_item_expand (item);
197 /* callback for event box state changed */
199 gtk_tree_item_subtree_button_changed_state (GtkWidget *widget)
201 g_return_if_fail (GTK_IS_EVENT_BOX (widget));
203 if (GTK_WIDGET_VISIBLE (widget))
206 if (widget->state == GTK_STATE_NORMAL)
207 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
209 gdk_window_set_background (widget->window, &widget->style->bg[widget->state]);
211 if (GTK_WIDGET_DRAWABLE (widget))
212 gdk_window_clear_area (widget->window, 0, 0,
213 widget->allocation.width, widget->allocation.height);
218 gtk_tree_item_init (GtkTreeItem *tree_item)
220 GtkWidget *eventbox, *pixmapwid;
222 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
224 tree_item->expanded = FALSE;
225 tree_item->subtree = NULL;
226 GTK_WIDGET_SET_FLAGS (tree_item, GTK_CAN_FOCUS);
228 /* create an event box containing one pixmaps */
229 eventbox = gtk_event_box_new();
230 gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK);
231 gtk_signal_connect(GTK_OBJECT(eventbox), "state_changed",
232 (GtkSignalFunc)gtk_tree_item_subtree_button_changed_state,
234 gtk_signal_connect(GTK_OBJECT(eventbox), "realize",
235 (GtkSignalFunc)gtk_tree_item_subtree_button_changed_state,
237 gtk_signal_connect(GTK_OBJECT(eventbox), "button_press_event",
238 (GtkSignalFunc)gtk_tree_item_subtree_button_click,
240 gtk_object_set_user_data(GTK_OBJECT(eventbox), tree_item);
241 tree_item->pixmaps_box = eventbox;
243 /* create pixmap for button '+' */
244 pixmapwid = gtk_type_new (gtk_pixmap_get_type ());
245 if (!tree_item->expanded)
246 gtk_container_add (GTK_CONTAINER (eventbox), pixmapwid);
247 gtk_widget_show (pixmapwid);
248 tree_item->plus_pix_widget = pixmapwid;
249 gtk_widget_ref (tree_item->plus_pix_widget);
250 gtk_object_sink (GTK_OBJECT (tree_item->plus_pix_widget));
252 /* create pixmap for button '-' */
253 pixmapwid = gtk_type_new (gtk_pixmap_get_type ());
254 if (tree_item->expanded)
255 gtk_container_add (GTK_CONTAINER (eventbox), pixmapwid);
256 gtk_widget_show (pixmapwid);
257 tree_item->minus_pix_widget = pixmapwid;
258 gtk_widget_ref (tree_item->minus_pix_widget);
259 gtk_object_sink (GTK_OBJECT (tree_item->minus_pix_widget));
261 gtk_widget_set_parent (eventbox, GTK_WIDGET (tree_item));
266 gtk_tree_item_new (void)
268 GtkWidget *tree_item;
270 tree_item = GTK_WIDGET (gtk_type_new (gtk_tree_item_get_type ()));
276 gtk_tree_item_new_with_label (const gchar *label)
278 GtkWidget *tree_item;
279 GtkWidget *label_widget;
281 tree_item = gtk_tree_item_new ();
282 label_widget = gtk_label_new (label);
283 gtk_misc_set_alignment (GTK_MISC (label_widget), 0.0, 0.5);
285 gtk_container_add (GTK_CONTAINER (tree_item), label_widget);
286 gtk_widget_show (label_widget);
293 gtk_tree_item_set_subtree (GtkTreeItem *tree_item,
296 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
297 g_return_if_fail (GTK_IS_TREE (subtree));
299 if (tree_item->subtree)
301 g_warning("there is already a subtree for this tree item\n");
305 tree_item->subtree = subtree;
306 GTK_TREE (subtree)->tree_owner = GTK_WIDGET (tree_item);
308 /* show subtree button */
309 if (tree_item->pixmaps_box)
310 gtk_widget_show (tree_item->pixmaps_box);
312 if (tree_item->expanded)
313 gtk_widget_show (subtree);
315 gtk_widget_hide (subtree);
317 gtk_widget_set_parent (subtree, GTK_WIDGET (tree_item)->parent);
321 gtk_tree_item_select (GtkTreeItem *tree_item)
323 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
325 gtk_item_select (GTK_ITEM (tree_item));
329 gtk_tree_item_deselect (GtkTreeItem *tree_item)
331 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
333 gtk_item_deselect (GTK_ITEM (tree_item));
337 gtk_tree_item_expand (GtkTreeItem *tree_item)
339 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
341 gtk_signal_emit (GTK_OBJECT (tree_item), tree_item_signals[EXPAND_TREE], NULL);
345 gtk_tree_item_collapse (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[COLLAPSE_TREE], NULL);
353 gtk_tree_item_add_pixmaps (GtkTreeItem *tree_item)
356 GdkColormap *colormap;
357 GtkTreePixmaps *pixmap_node = NULL;
359 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
361 if (tree_item->pixmaps)
364 colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_item));
369 pixmap_node = (GtkTreePixmaps *)tmp_list->data;
371 if (pixmap_node->colormap == colormap)
374 tmp_list = tmp_list->next;
379 pixmap_node->refcount++;
380 tree_item->pixmaps = tmp_list;
384 pixmap_node = g_new (GtkTreePixmaps, 1);
386 pixmap_node->colormap = colormap;
387 g_object_ref (colormap);
389 pixmap_node->refcount = 1;
391 /* create pixmaps for plus icon */
392 pixmap_node->pixmap_plus =
393 gdk_pixmap_create_from_xpm_d (GTK_WIDGET (tree_item)->window,
394 &pixmap_node->mask_plus,
398 /* create pixmaps for minus icon */
399 pixmap_node->pixmap_minus =
400 gdk_pixmap_create_from_xpm_d (GTK_WIDGET (tree_item)->window,
401 &pixmap_node->mask_minus,
405 tree_item->pixmaps = pixmaps = g_list_prepend (pixmaps, pixmap_node);
408 gtk_pixmap_set (GTK_PIXMAP (tree_item->plus_pix_widget),
409 pixmap_node->pixmap_plus, pixmap_node->mask_plus);
410 gtk_pixmap_set (GTK_PIXMAP (tree_item->minus_pix_widget),
411 pixmap_node->pixmap_minus, pixmap_node->mask_minus);
415 gtk_tree_item_remove_pixmaps (GtkTreeItem *tree_item)
417 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
419 if (tree_item->pixmaps)
421 GtkTreePixmaps *pixmap_node = (GtkTreePixmaps *)tree_item->pixmaps->data;
423 g_assert (pixmap_node->refcount > 0);
425 if (--pixmap_node->refcount == 0)
427 g_object_unref (pixmap_node->colormap);
428 g_object_unref (pixmap_node->pixmap_plus);
429 g_object_unref (pixmap_node->mask_plus);
430 g_object_unref (pixmap_node->pixmap_minus);
431 g_object_unref (pixmap_node->mask_minus);
433 pixmaps = g_list_remove_link (pixmaps, tree_item->pixmaps);
434 g_list_free_1 (tree_item->pixmaps);
435 g_free (pixmap_node);
438 tree_item->pixmaps = NULL;
443 gtk_tree_item_realize (GtkWidget *widget)
445 g_return_if_fail (GTK_IS_TREE_ITEM (widget));
447 if (GTK_WIDGET_CLASS (parent_class)->realize)
448 (* GTK_WIDGET_CLASS (parent_class)->realize) (widget);
450 gdk_window_set_background (widget->window,
451 &widget->style->base[GTK_STATE_NORMAL]);
453 gtk_tree_item_add_pixmaps (GTK_TREE_ITEM (widget));
457 gtk_tree_item_size_request (GtkWidget *widget,
458 GtkRequisition *requisition)
462 GtkRequisition child_requisition;
464 g_return_if_fail (GTK_IS_TREE_ITEM (widget));
465 g_return_if_fail (requisition != NULL);
467 bin = GTK_BIN (widget);
468 item = GTK_TREE_ITEM(widget);
470 requisition->width = (GTK_CONTAINER (widget)->border_width +
471 widget->style->xthickness) * 2;
472 requisition->height = GTK_CONTAINER (widget)->border_width * 2;
474 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
476 GtkRequisition pix_requisition;
478 gtk_widget_size_request (bin->child, &child_requisition);
480 requisition->width += child_requisition.width;
482 gtk_widget_size_request (item->pixmaps_box,
484 requisition->width += pix_requisition.width + DEFAULT_DELTA +
485 GTK_TREE (widget->parent)->current_indent;
487 requisition->height += MAX (child_requisition.height,
488 pix_requisition.height);
493 gtk_tree_item_size_allocate (GtkWidget *widget,
494 GtkAllocation *allocation)
498 GtkAllocation child_allocation;
502 g_return_if_fail (GTK_IS_TREE_ITEM (widget));
503 g_return_if_fail (allocation != NULL);
505 widget->allocation = *allocation;
506 if (GTK_WIDGET_REALIZED (widget))
507 gdk_window_move_resize (widget->window,
508 allocation->x, allocation->y,
509 allocation->width, allocation->height);
511 bin = GTK_BIN (widget);
512 item = GTK_TREE_ITEM(widget);
516 border_width = (GTK_CONTAINER (widget)->border_width +
517 widget->style->xthickness);
519 child_allocation.x = border_width + GTK_TREE(widget->parent)->current_indent;
520 child_allocation.y = GTK_CONTAINER (widget)->border_width;
522 child_allocation.width = item->pixmaps_box->requisition.width;
523 child_allocation.height = item->pixmaps_box->requisition.height;
525 temp = allocation->height - child_allocation.height;
526 child_allocation.y += ( temp / 2 ) + ( temp % 2 );
528 gtk_widget_size_allocate (item->pixmaps_box, &child_allocation);
530 child_allocation.y = GTK_CONTAINER (widget)->border_width;
531 child_allocation.height = MAX (1, (gint)allocation->height - child_allocation.y * 2);
532 child_allocation.x += item->pixmaps_box->requisition.width+DEFAULT_DELTA;
534 child_allocation.width =
535 MAX (1, (gint)allocation->width - ((gint)child_allocation.x + border_width));
537 gtk_widget_size_allocate (bin->child, &child_allocation);
542 gtk_tree_item_draw_lines (GtkWidget *widget)
546 guint lx1, ly1, lx2, ly2;
549 g_return_if_fail (GTK_IS_TREE_ITEM (widget));
551 item = GTK_TREE_ITEM(widget);
552 tree = GTK_TREE(widget->parent);
554 if (!tree->view_line)
557 gc = widget->style->text_gc[GTK_STATE_NORMAL];
559 /* draw vertical line */
560 lx1 = item->pixmaps_box->allocation.width;
561 lx1 = lx2 = ((lx1 / 2) + (lx1 % 2) +
562 GTK_CONTAINER (widget)->border_width + 1 + tree->current_indent);
564 ly2 = widget->allocation.height;
566 if (g_list_last (tree->children)->data == widget)
567 ly2 = (ly2 / 2) + (ly2 % 2);
569 if (tree != tree->root_tree)
570 gdk_draw_line (widget->window, gc, lx1, ly1, lx2, ly2);
572 /* draw vertical line for subtree connecting */
573 if(g_list_last(tree->children)->data != (gpointer)widget)
574 ly2 = (ly2 / 2) + (ly2 % 2);
576 lx2 += DEFAULT_DELTA;
578 if (item->subtree && item->expanded)
579 gdk_draw_line (widget->window, gc,
580 lx2, ly2, lx2, widget->allocation.height);
582 /* draw horizontal line */
586 gdk_draw_line (widget->window, gc, lx1, ly1, lx2, ly2);
588 lx2 -= DEFAULT_DELTA+2;
590 ly2 = widget->allocation.height;
592 if (tree != tree->root_tree)
594 item = GTK_TREE_ITEM (tree->tree_owner);
595 tree = GTK_TREE (GTK_WIDGET (tree)->parent);
596 while (tree != tree->root_tree)
598 lx1 = lx2 -= tree->indent_value;
600 if (g_list_last (tree->children)->data != item)
601 gdk_draw_line (widget->window, gc, lx1, ly1, lx2, ly2);
602 item = GTK_TREE_ITEM (tree->tree_owner);
603 tree = GTK_TREE (GTK_WIDGET (tree)->parent);
609 gtk_tree_item_paint (GtkWidget *widget,
613 GdkRectangle child_area, item_area;
614 GtkTreeItem* tree_item;
616 g_return_if_fail (GTK_IS_TREE_ITEM (widget));
617 g_return_if_fail (area != NULL);
619 /* FIXME: We should honor tree->view_mode, here - I think
620 * the desired effect is that when the mode is VIEW_ITEM,
621 * only the subitem is drawn as selected, not the entire
622 * line. (Like the way that the tree in Windows Explorer
625 if (GTK_WIDGET_DRAWABLE (widget))
627 bin = GTK_BIN (widget);
628 tree_item = GTK_TREE_ITEM(widget);
630 if (widget->state == GTK_STATE_NORMAL)
632 gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
633 gdk_window_clear_area (widget->window, area->x, area->y, area->width, area->height);
637 if (!GTK_WIDGET_IS_SENSITIVE (widget))
638 gtk_paint_flat_box(widget->style, widget->window,
639 widget->state, GTK_SHADOW_NONE,
640 area, widget, "treeitem",
643 gtk_paint_flat_box(widget->style, widget->window,
644 widget->state, GTK_SHADOW_ETCHED_OUT,
645 area, widget, "treeitem",
649 /* draw left size of tree item */
652 item_area.width = (tree_item->pixmaps_box->allocation.width + DEFAULT_DELTA +
653 GTK_TREE (widget->parent)->current_indent + 2);
654 item_area.height = widget->allocation.height;
657 if (gdk_rectangle_intersect(&item_area, area, &child_area))
660 gtk_tree_item_draw_lines(widget);
662 if (tree_item->pixmaps_box &&
663 GTK_WIDGET_VISIBLE(tree_item->pixmaps_box) &&
664 gtk_widget_intersect (tree_item->pixmaps_box, area, &child_area))
665 gtk_widget_draw (tree_item->pixmaps_box, &child_area);
668 if (GTK_WIDGET_HAS_FOCUS (widget))
669 gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget),
670 NULL, widget, "treeitem",
672 widget->allocation.width,
673 widget->allocation.height);
679 gtk_tree_item_button_press (GtkWidget *widget,
680 GdkEventButton *event)
683 g_return_val_if_fail (GTK_IS_TREE_ITEM (widget), FALSE);
684 g_return_val_if_fail (event != NULL, FALSE);
686 if (event->type == GDK_BUTTON_PRESS
687 && GTK_WIDGET_IS_SENSITIVE(widget)
688 && !GTK_WIDGET_HAS_FOCUS (widget))
689 gtk_widget_grab_focus (widget);
691 return (event->type == GDK_BUTTON_PRESS && GTK_WIDGET_IS_SENSITIVE(widget));
695 gtk_tree_item_expose_child (GtkWidget *child,
696 gpointer client_data)
699 GtkWidget *container;
700 GdkEventExpose *event;
701 } *data = client_data;
703 if (GTK_WIDGET_DRAWABLE (child) &&
704 GTK_WIDGET_NO_WINDOW (child) &&
705 (child->window == data->event->window))
707 GdkEvent *child_event = gdk_event_new (GDK_EXPOSE);
708 child_event->expose = *data->event;
709 g_object_ref (child_event->expose.window);
711 child_event->expose.region = gtk_widget_region_intersect (child,
712 data->event->region);
713 if (!gdk_region_empty (child_event->expose.region))
715 gdk_region_get_clipbox (child_event->expose.region, &child_event->expose.area);
716 gtk_widget_send_expose (child, child_event);
718 gdk_event_free (child_event);
723 gtk_tree_item_expose (GtkWidget *widget,
724 GdkEventExpose *event)
727 GtkWidget *container;
728 GdkEventExpose *event;
731 g_return_val_if_fail (GTK_IS_TREE_ITEM (widget), FALSE);
732 g_return_val_if_fail (event != NULL, FALSE);
734 if (GTK_WIDGET_DRAWABLE (widget))
736 gtk_tree_item_paint (widget, &event->area);
738 data.container = widget;
741 gtk_container_forall (GTK_CONTAINER (widget),
742 gtk_tree_item_expose_child,
750 gtk_real_tree_item_select (GtkItem *item)
752 GtkTreeItem *tree_item;
755 g_return_if_fail (GTK_IS_TREE_ITEM (item));
757 tree_item = GTK_TREE_ITEM (item);
758 widget = GTK_WIDGET (item);
760 gtk_widget_set_state (GTK_WIDGET (item), GTK_STATE_SELECTED);
762 if (!widget->parent || GTK_TREE (widget->parent)->view_mode == GTK_TREE_VIEW_LINE)
763 gtk_widget_set_state (GTK_TREE_ITEM (item)->pixmaps_box, GTK_STATE_SELECTED);
767 gtk_real_tree_item_deselect (GtkItem *item)
769 GtkTreeItem *tree_item;
772 g_return_if_fail (GTK_IS_TREE_ITEM (item));
774 tree_item = GTK_TREE_ITEM (item);
775 widget = GTK_WIDGET (item);
777 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
779 if (!widget->parent || GTK_TREE (widget->parent)->view_mode == GTK_TREE_VIEW_LINE)
780 gtk_widget_set_state (tree_item->pixmaps_box, GTK_STATE_NORMAL);
784 gtk_real_tree_item_toggle (GtkItem *item)
786 g_return_if_fail (GTK_IS_TREE_ITEM (item));
788 if(!GTK_WIDGET_IS_SENSITIVE(item))
791 if (GTK_WIDGET (item)->parent && GTK_IS_TREE (GTK_WIDGET (item)->parent))
792 gtk_tree_select_child (GTK_TREE (GTK_WIDGET (item)->parent),
796 /* Should we really bother with this bit? A listitem not in a list?
797 * -Johannes Keukelaar
798 * yes, always be on the safe side!
801 if (GTK_WIDGET (item)->state == GTK_STATE_SELECTED)
802 gtk_widget_set_state (GTK_WIDGET (item), GTK_STATE_NORMAL);
804 gtk_widget_set_state (GTK_WIDGET (item), GTK_STATE_SELECTED);
809 gtk_real_tree_item_expand (GtkTreeItem *tree_item)
813 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
815 if (tree_item->subtree && !tree_item->expanded)
817 tree = GTK_TREE (GTK_WIDGET (tree_item)->parent);
819 /* hide subtree widget */
820 gtk_widget_show (tree_item->subtree);
822 /* hide button '+' and show button '-' */
823 if (tree_item->pixmaps_box)
825 gtk_container_remove (GTK_CONTAINER (tree_item->pixmaps_box),
826 tree_item->plus_pix_widget);
827 gtk_container_add (GTK_CONTAINER (tree_item->pixmaps_box),
828 tree_item->minus_pix_widget);
831 gtk_widget_queue_resize (GTK_WIDGET (tree->root_tree));
832 tree_item->expanded = TRUE;
837 gtk_real_tree_item_collapse (GtkTreeItem *tree_item)
841 g_return_if_fail (GTK_IS_TREE_ITEM (tree_item));
843 if (tree_item->subtree && tree_item->expanded)
845 tree = GTK_TREE (GTK_WIDGET (tree_item)->parent);
847 /* hide subtree widget */
848 gtk_widget_hide (tree_item->subtree);
850 /* hide button '-' and show button '+' */
851 if (tree_item->pixmaps_box)
853 gtk_container_remove (GTK_CONTAINER (tree_item->pixmaps_box),
854 tree_item->minus_pix_widget);
855 gtk_container_add (GTK_CONTAINER (tree_item->pixmaps_box),
856 tree_item->plus_pix_widget);
859 gtk_widget_queue_resize (GTK_WIDGET (tree->root_tree));
860 tree_item->expanded = FALSE;
865 gtk_tree_item_destroy (GtkObject *object)
870 g_return_if_fail (GTK_IS_TREE_ITEM (object));
873 g_message("+ gtk_tree_item_destroy [object %#x]\n", (int)object);
874 #endif /* TREE_DEBUG */
876 item = GTK_TREE_ITEM(object);
878 /* free sub tree if it exist */
879 child = item->subtree;
882 gtk_widget_ref (child);
883 gtk_widget_unparent (child);
884 gtk_widget_destroy (child);
885 gtk_widget_unref (child);
886 item->subtree = NULL;
889 /* free pixmaps box */
890 child = item->pixmaps_box;
893 gtk_widget_ref (child);
894 gtk_widget_unparent (child);
895 gtk_widget_destroy (child);
896 gtk_widget_unref (child);
897 item->pixmaps_box = NULL;
901 /* destroy plus pixmap */
902 if (item->plus_pix_widget)
904 gtk_widget_destroy (item->plus_pix_widget);
905 gtk_widget_unref (item->plus_pix_widget);
906 item->plus_pix_widget = NULL;
909 /* destroy minus pixmap */
910 if (item->minus_pix_widget)
912 gtk_widget_destroy (item->minus_pix_widget);
913 gtk_widget_unref (item->minus_pix_widget);
914 item->minus_pix_widget = NULL;
917 /* By removing the pixmaps here, and not in unrealize, we depend on
918 * the fact that a widget can never change colormap or visual.
920 gtk_tree_item_remove_pixmaps (item);
922 GTK_OBJECT_CLASS (parent_class)->destroy (object);
925 g_message("- gtk_tree_item_destroy\n");
926 #endif /* TREE_DEBUG */
930 gtk_tree_item_remove_subtree (GtkTreeItem* item)
932 g_return_if_fail (GTK_IS_TREE_ITEM(item));
933 g_return_if_fail (item->subtree != NULL);
935 if (GTK_TREE (item->subtree)->children)
937 /* The following call will remove the children and call
938 * gtk_tree_item_remove_subtree() again. So we are done.
940 gtk_tree_remove_items (GTK_TREE (item->subtree),
941 GTK_TREE (item->subtree)->children);
945 if (GTK_WIDGET_MAPPED (item->subtree))
946 gtk_widget_unmap (item->subtree);
948 gtk_widget_unparent (item->subtree);
950 if (item->pixmaps_box)
951 gtk_widget_hide (item->pixmaps_box);
953 item->subtree = NULL;
957 item->expanded = FALSE;
958 if (item->pixmaps_box)
960 gtk_container_remove (GTK_CONTAINER (item->pixmaps_box),
961 item->minus_pix_widget);
962 gtk_container_add (GTK_CONTAINER (item->pixmaps_box),
963 item->plus_pix_widget);
969 gtk_tree_item_map (GtkWidget *widget)
974 g_return_if_fail (GTK_IS_TREE_ITEM (widget));
976 bin = GTK_BIN (widget);
977 item = GTK_TREE_ITEM(widget);
979 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
981 if(item->pixmaps_box &&
982 GTK_WIDGET_VISIBLE (item->pixmaps_box) &&
983 !GTK_WIDGET_MAPPED (item->pixmaps_box))
984 gtk_widget_map (item->pixmaps_box);
987 GTK_WIDGET_VISIBLE (bin->child) &&
988 !GTK_WIDGET_MAPPED (bin->child))
989 gtk_widget_map (bin->child);
991 gdk_window_show (widget->window);
995 gtk_tree_item_unmap (GtkWidget *widget)
1000 g_return_if_fail (GTK_IS_TREE_ITEM (widget));
1002 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
1003 bin = GTK_BIN (widget);
1004 item = GTK_TREE_ITEM(widget);
1006 gdk_window_hide (widget->window);
1008 if(item->pixmaps_box &&
1009 GTK_WIDGET_VISIBLE (item->pixmaps_box) &&
1010 GTK_WIDGET_MAPPED (item->pixmaps_box))
1011 gtk_widget_unmap (bin->child);
1014 GTK_WIDGET_VISIBLE (bin->child) &&
1015 GTK_WIDGET_MAPPED (bin->child))
1016 gtk_widget_unmap (bin->child);
1020 gtk_tree_item_forall (GtkContainer *container,
1021 gboolean include_internals,
1022 GtkCallback callback,
1023 gpointer callback_data)
1026 GtkTreeItem *tree_item;
1028 g_return_if_fail (GTK_IS_TREE_ITEM (container));
1029 g_return_if_fail (callback != NULL);
1031 bin = GTK_BIN (container);
1032 tree_item = GTK_TREE_ITEM (container);
1035 (* callback) (bin->child, callback_data);
1036 if (include_internals && tree_item->subtree)
1037 (* callback) (tree_item->subtree, callback_data);