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.
22 static void gtk_bin_class_init (GtkBinClass *klass);
23 static void gtk_bin_init (GtkBin *bin);
24 static void gtk_bin_map (GtkWidget *widget);
25 static void gtk_bin_unmap (GtkWidget *widget);
26 static void gtk_bin_draw (GtkWidget *widget,
28 static gint gtk_bin_expose (GtkWidget *widget,
29 GdkEventExpose *event);
30 static void gtk_bin_add (GtkContainer *container,
32 static void gtk_bin_remove (GtkContainer *container,
34 static void gtk_bin_foreach (GtkContainer *container,
36 gpointer callback_data);
37 static GtkType gtk_bin_child_type (GtkContainer*container);
40 static GtkContainerClass *parent_class = NULL;
44 gtk_bin_get_type (void)
46 static guint bin_type = 0;
50 GtkTypeInfo bin_info =
55 (GtkClassInitFunc) gtk_bin_class_init,
56 (GtkObjectInitFunc) gtk_bin_init,
57 /* reversed_1 */ NULL,
58 /* reversed_2 */ NULL,
59 (GtkClassInitFunc) NULL,
62 bin_type = gtk_type_unique (GTK_TYPE_CONTAINER, &bin_info);
69 gtk_bin_class_init (GtkBinClass *class)
71 GtkObjectClass *object_class;
72 GtkWidgetClass *widget_class;
73 GtkContainerClass *container_class;
75 object_class = (GtkObjectClass*) class;
76 widget_class = (GtkWidgetClass*) class;
77 container_class = (GtkContainerClass*) class;
79 parent_class = gtk_type_class (GTK_TYPE_CONTAINER);
81 widget_class->map = gtk_bin_map;
82 widget_class->unmap = gtk_bin_unmap;
83 widget_class->draw = gtk_bin_draw;
84 widget_class->expose_event = gtk_bin_expose;
86 container_class->add = gtk_bin_add;
87 container_class->remove = gtk_bin_remove;
88 container_class->foreach = gtk_bin_foreach;
89 container_class->child_type = gtk_bin_child_type;
93 gtk_bin_init (GtkBin *bin)
95 GTK_WIDGET_SET_FLAGS (bin, GTK_NO_WINDOW);
102 gtk_bin_child_type (GtkContainer *container)
104 if (!GTK_BIN (container)->child)
105 return GTK_TYPE_WIDGET;
107 return GTK_TYPE_NONE;
111 gtk_bin_map (GtkWidget *widget)
115 g_return_if_fail (widget != NULL);
116 g_return_if_fail (GTK_IS_BIN (widget));
118 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
119 bin = GTK_BIN (widget);
121 if (!GTK_WIDGET_NO_WINDOW (widget))
122 gdk_window_show (widget->window);
124 gtk_widget_queue_draw (widget);
127 GTK_WIDGET_VISIBLE (bin->child) &&
128 !GTK_WIDGET_MAPPED (bin->child))
129 gtk_widget_map (bin->child);
133 gtk_bin_unmap (GtkWidget *widget)
137 g_return_if_fail (widget != NULL);
138 g_return_if_fail (GTK_IS_BIN (widget));
140 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
141 bin = GTK_BIN (widget);
143 if (GTK_WIDGET_NO_WINDOW (widget))
144 gdk_window_clear_area (widget->window,
145 widget->allocation.x,
146 widget->allocation.y,
147 widget->allocation.width,
148 widget->allocation.height);
150 gdk_window_hide (widget->window);
153 GTK_WIDGET_VISIBLE (bin->child) &&
154 GTK_WIDGET_MAPPED (bin->child))
155 gtk_widget_unmap (bin->child);
159 gtk_bin_draw (GtkWidget *widget,
163 GdkRectangle child_area;
165 g_return_if_fail (widget != NULL);
166 g_return_if_fail (GTK_IS_BIN (widget));
168 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_MAPPED (widget))
170 bin = GTK_BIN (widget);
173 gtk_widget_intersect (bin->child, area, &child_area))
174 gtk_widget_draw (bin->child, &child_area);
179 gtk_bin_expose (GtkWidget *widget,
180 GdkEventExpose *event)
183 GdkEventExpose child_event;
185 g_return_val_if_fail (widget != NULL, FALSE);
186 g_return_val_if_fail (GTK_IS_BIN (widget), FALSE);
187 g_return_val_if_fail (event != NULL, FALSE);
189 if (GTK_WIDGET_DRAWABLE (widget))
191 bin = GTK_BIN (widget);
193 child_event = *event;
195 GTK_WIDGET_NO_WINDOW (bin->child) &&
196 gtk_widget_intersect (bin->child, &event->area, &child_event.area))
197 gtk_widget_event (bin->child, (GdkEvent*) &child_event);
205 gtk_bin_add (GtkContainer *container,
210 g_return_if_fail (container != NULL);
211 g_return_if_fail (GTK_IS_BIN (container));
212 g_return_if_fail (widget != NULL);
214 bin = GTK_BIN (container);
215 g_return_if_fail (bin->child == NULL);
217 gtk_widget_set_parent (widget, GTK_WIDGET (container));
219 if (GTK_WIDGET_VISIBLE (widget->parent))
221 if (GTK_WIDGET_REALIZED (widget->parent) &&
222 !GTK_WIDGET_REALIZED (widget))
223 gtk_widget_realize (widget);
225 if (GTK_WIDGET_MAPPED (widget->parent) &&
226 !GTK_WIDGET_MAPPED (widget))
227 gtk_widget_map (widget);
232 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (container))
233 gtk_widget_queue_resize (widget);
237 gtk_bin_remove (GtkContainer *container,
242 g_return_if_fail (container != NULL);
243 g_return_if_fail (GTK_IS_BIN (container));
244 g_return_if_fail (widget != NULL);
246 bin = GTK_BIN (container);
248 if (bin->child == widget)
250 gboolean widget_was_visible = GTK_WIDGET_VISIBLE (widget);
252 gtk_widget_unparent (widget);
255 /* queue resize regardless of GTK_WIDGET_VISIBLE (container),
256 * since that's what is needed by toplevels, which derive from GtkBin.
258 if (widget_was_visible)
259 gtk_widget_queue_resize (GTK_WIDGET (container));
264 gtk_bin_foreach (GtkContainer *container,
265 GtkCallback callback,
266 gpointer callback_data)
270 g_return_if_fail (container != NULL);
271 g_return_if_fail (GTK_IS_BIN (container));
272 g_return_if_fail (callback != NULL);
274 bin = GTK_BIN (container);
277 (* callback) (bin->child, callback_data);