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/.
30 static void gtk_bin_class_init (GtkBinClass *klass);
31 static void gtk_bin_init (GtkBin *bin);
32 static void gtk_bin_map (GtkWidget *widget);
33 static void gtk_bin_unmap (GtkWidget *widget);
34 static void gtk_bin_draw (GtkWidget *widget,
36 static gint gtk_bin_expose (GtkWidget *widget,
37 GdkEventExpose *event);
38 static void gtk_bin_add (GtkContainer *container,
40 static void gtk_bin_remove (GtkContainer *container,
42 static void gtk_bin_forall (GtkContainer *container,
43 gboolean include_internals,
45 gpointer callback_data);
46 static GtkType gtk_bin_child_type (GtkContainer*container);
49 static GtkContainerClass *parent_class = NULL;
53 gtk_bin_get_type (void)
55 static guint bin_type = 0;
59 static const GtkTypeInfo bin_info =
64 (GtkClassInitFunc) gtk_bin_class_init,
65 (GtkObjectInitFunc) gtk_bin_init,
66 /* reserved_1 */ NULL,
67 /* reserved_2 */ NULL,
68 (GtkClassInitFunc) NULL,
71 bin_type = gtk_type_unique (GTK_TYPE_CONTAINER, &bin_info);
78 gtk_bin_class_init (GtkBinClass *class)
80 GtkObjectClass *object_class;
81 GtkWidgetClass *widget_class;
82 GtkContainerClass *container_class;
84 object_class = (GtkObjectClass*) class;
85 widget_class = (GtkWidgetClass*) class;
86 container_class = (GtkContainerClass*) class;
88 parent_class = gtk_type_class (GTK_TYPE_CONTAINER);
90 widget_class->map = gtk_bin_map;
91 widget_class->unmap = gtk_bin_unmap;
92 widget_class->draw = gtk_bin_draw;
93 widget_class->expose_event = gtk_bin_expose;
95 container_class->add = gtk_bin_add;
96 container_class->remove = gtk_bin_remove;
97 container_class->forall = gtk_bin_forall;
98 container_class->child_type = gtk_bin_child_type;
102 gtk_bin_init (GtkBin *bin)
104 GTK_WIDGET_SET_FLAGS (bin, GTK_NO_WINDOW);
111 gtk_bin_child_type (GtkContainer *container)
113 if (!GTK_BIN (container)->child)
114 return GTK_TYPE_WIDGET;
116 return GTK_TYPE_NONE;
120 gtk_bin_map (GtkWidget *widget)
124 g_return_if_fail (widget != NULL);
125 g_return_if_fail (GTK_IS_BIN (widget));
127 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
128 bin = GTK_BIN (widget);
131 GTK_WIDGET_VISIBLE (bin->child) &&
132 !GTK_WIDGET_MAPPED (bin->child))
133 gtk_widget_map (bin->child);
135 if (!GTK_WIDGET_NO_WINDOW (widget))
136 gdk_window_show (widget->window);
140 gtk_bin_unmap (GtkWidget *widget)
144 g_return_if_fail (widget != NULL);
145 g_return_if_fail (GTK_IS_BIN (widget));
147 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
148 bin = GTK_BIN (widget);
150 if (!GTK_WIDGET_NO_WINDOW (widget))
151 gdk_window_hide (widget->window);
153 if (bin->child && GTK_WIDGET_MAPPED (bin->child))
154 gtk_widget_unmap (bin->child);
158 gtk_bin_draw (GtkWidget *widget,
162 GdkRectangle child_area;
164 g_return_if_fail (widget != NULL);
165 g_return_if_fail (GTK_IS_BIN (widget));
167 bin = GTK_BIN (widget);
169 if (GTK_WIDGET_DRAWABLE (bin))
171 if (bin->child && GTK_WIDGET_DRAWABLE (bin->child) &&
172 gtk_widget_intersect (bin->child, area, &child_area))
173 gtk_widget_draw (bin->child, &child_area);
178 gtk_bin_expose (GtkWidget *widget,
179 GdkEventExpose *event)
182 GdkEventExpose child_event;
184 g_return_val_if_fail (widget != NULL, FALSE);
185 g_return_val_if_fail (GTK_IS_BIN (widget), FALSE);
186 g_return_val_if_fail (event != NULL, FALSE);
188 if (GTK_WIDGET_DRAWABLE (widget))
190 bin = GTK_BIN (widget);
192 child_event = *event;
193 if (bin->child && GTK_WIDGET_DRAWABLE (bin->child) &&
194 GTK_WIDGET_NO_WINDOW (bin->child) &&
195 gtk_widget_intersect (bin->child, &event->area, &child_event.area))
196 gtk_widget_event (bin->child, (GdkEvent*) &child_event);
204 gtk_bin_add (GtkContainer *container,
209 g_return_if_fail (container != NULL);
210 g_return_if_fail (GTK_IS_BIN (container));
211 g_return_if_fail (child != NULL);
212 g_return_if_fail (GTK_IS_WIDGET (child));
214 bin = GTK_BIN (container);
215 g_return_if_fail (bin->child == NULL);
217 gtk_widget_set_parent (child, GTK_WIDGET (bin));
220 if (GTK_WIDGET_REALIZED (child->parent))
221 gtk_widget_realize (child);
223 if (GTK_WIDGET_VISIBLE (child->parent) && GTK_WIDGET_VISIBLE (child))
225 if (GTK_WIDGET_MAPPED (child->parent))
226 gtk_widget_map (child);
228 gtk_widget_queue_resize (child);
233 gtk_bin_remove (GtkContainer *container,
237 gboolean widget_was_visible;
239 g_return_if_fail (container != NULL);
240 g_return_if_fail (GTK_IS_BIN (container));
241 g_return_if_fail (child != NULL);
242 g_return_if_fail (GTK_IS_WIDGET (child));
244 bin = GTK_BIN (container);
245 g_return_if_fail (bin->child == child);
247 widget_was_visible = GTK_WIDGET_VISIBLE (child);
249 gtk_widget_unparent (child);
252 /* queue resize regardless of GTK_WIDGET_VISIBLE (container),
253 * since that's what is needed by toplevels, which derive from GtkBin.
255 if (widget_was_visible)
256 gtk_widget_queue_resize (GTK_WIDGET (container));
260 gtk_bin_forall (GtkContainer *container,
261 gboolean include_internals,
262 GtkCallback callback,
263 gpointer callback_data)
267 g_return_if_fail (container != NULL);
268 g_return_if_fail (GTK_IS_BIN (container));
269 g_return_if_fail (callback != NULL);
271 bin = GTK_BIN (container);
274 (* callback) (bin->child, callback_data);