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);
39 static GtkContainerClass *parent_class = NULL;
45 static guint bin_type = 0;
49 GtkTypeInfo bin_info =
54 (GtkClassInitFunc) gtk_bin_class_init,
55 (GtkObjectInitFunc) gtk_bin_init,
60 bin_type = gtk_type_unique (gtk_container_get_type (), &bin_info);
67 gtk_bin_class_init (GtkBinClass *class)
69 GtkObjectClass *object_class;
70 GtkWidgetClass *widget_class;
71 GtkContainerClass *container_class;
73 object_class = (GtkObjectClass*) class;
74 widget_class = (GtkWidgetClass*) class;
75 container_class = (GtkContainerClass*) class;
77 parent_class = gtk_type_class (gtk_container_get_type ());
79 widget_class->map = gtk_bin_map;
80 widget_class->unmap = gtk_bin_unmap;
81 widget_class->draw = gtk_bin_draw;
82 widget_class->expose_event = gtk_bin_expose;
84 container_class->add = gtk_bin_add;
85 container_class->remove = gtk_bin_remove;
86 container_class->foreach = gtk_bin_foreach;
90 gtk_bin_init (GtkBin *bin)
92 GTK_WIDGET_SET_FLAGS (bin, GTK_NO_WINDOW);
99 gtk_bin_map (GtkWidget *widget)
103 g_return_if_fail (widget != NULL);
104 g_return_if_fail (GTK_IS_BIN (widget));
106 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
107 bin = GTK_BIN (widget);
109 if (!GTK_WIDGET_NO_WINDOW (widget))
110 gdk_window_show (widget->window);
112 gtk_widget_queue_draw (widget);
115 GTK_WIDGET_VISIBLE (bin->child) &&
116 !GTK_WIDGET_MAPPED (bin->child))
117 gtk_widget_map (bin->child);
121 gtk_bin_unmap (GtkWidget *widget)
125 g_return_if_fail (widget != NULL);
126 g_return_if_fail (GTK_IS_BIN (widget));
128 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
129 bin = GTK_BIN (widget);
131 if (GTK_WIDGET_NO_WINDOW (widget))
132 gdk_window_clear_area (widget->window,
133 widget->allocation.x,
134 widget->allocation.y,
135 widget->allocation.width,
136 widget->allocation.height);
138 gdk_window_hide (widget->window);
141 GTK_WIDGET_VISIBLE (bin->child) &&
142 GTK_WIDGET_MAPPED (bin->child))
143 gtk_widget_unmap (bin->child);
147 gtk_bin_draw (GtkWidget *widget,
151 GdkRectangle child_area;
153 g_return_if_fail (widget != NULL);
154 g_return_if_fail (GTK_IS_BIN (widget));
156 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_MAPPED (widget))
158 bin = GTK_BIN (widget);
161 gtk_widget_intersect (bin->child, area, &child_area))
162 gtk_widget_draw (bin->child, &child_area);
167 gtk_bin_expose (GtkWidget *widget,
168 GdkEventExpose *event)
171 GdkEventExpose child_event;
173 g_return_val_if_fail (widget != NULL, FALSE);
174 g_return_val_if_fail (GTK_IS_BIN (widget), FALSE);
175 g_return_val_if_fail (event != NULL, FALSE);
177 if (GTK_WIDGET_DRAWABLE (widget))
179 bin = GTK_BIN (widget);
181 child_event = *event;
183 GTK_WIDGET_NO_WINDOW (bin->child) &&
184 gtk_widget_intersect (bin->child, &event->area, &child_event.area))
185 gtk_widget_event (bin->child, (GdkEvent*) &child_event);
193 gtk_bin_add (GtkContainer *container,
198 g_return_if_fail (container != NULL);
199 g_return_if_fail (GTK_IS_BIN (container));
200 g_return_if_fail (widget != NULL);
202 bin = GTK_BIN (container);
203 g_return_if_fail (bin->child == NULL);
205 gtk_widget_set_parent (widget, GTK_WIDGET (container));
207 if (GTK_WIDGET_VISIBLE (widget->parent))
209 if (GTK_WIDGET_REALIZED (widget->parent) &&
210 !GTK_WIDGET_REALIZED (widget))
211 gtk_widget_realize (widget);
213 if (GTK_WIDGET_MAPPED (widget->parent) &&
214 !GTK_WIDGET_MAPPED (widget))
215 gtk_widget_map (widget);
220 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (container))
221 gtk_widget_queue_resize (widget);
225 gtk_bin_remove (GtkContainer *container,
230 g_return_if_fail (container != NULL);
231 g_return_if_fail (GTK_IS_BIN (container));
232 g_return_if_fail (widget != NULL);
234 bin = GTK_BIN (container);
236 if (bin->child == widget)
238 gboolean widget_was_visible = GTK_WIDGET_VISIBLE (widget);
240 gtk_widget_unparent (widget);
243 if (widget_was_visible && GTK_WIDGET_VISIBLE (container))
244 gtk_widget_queue_resize (GTK_WIDGET (container));
249 gtk_bin_foreach (GtkContainer *container,
250 GtkCallback callback,
251 gpointer callback_data)
255 g_return_if_fail (container != NULL);
256 g_return_if_fail (GTK_IS_BIN (container));
257 g_return_if_fail (callback != NULL);
259 bin = GTK_BIN (container);
262 (* callback) (bin->child, callback_data);