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
gtk_widget_queue_clear (widget);
153
gdk_window_hide (widget->window);
155
if (bin->child && GTK_WIDGET_MAPPED (bin->child))
156
gtk_widget_unmap (bin->child);
160
gtk_bin_draw (GtkWidget *widget,
164
GdkRectangle child_area;
166
g_return_if_fail (widget != NULL);
167
g_return_if_fail (GTK_IS_BIN (widget));
169
bin = GTK_BIN (widget);
171
if (GTK_WIDGET_DRAWABLE (bin))
173
if (bin->child && GTK_WIDGET_DRAWABLE (bin->child) &&
174
gtk_widget_intersect (bin->child, area, &child_area))
175
gtk_widget_draw (bin->child, &child_area);
180
gtk_bin_expose (GtkWidget *widget,
181
GdkEventExpose *event)
184
GdkEventExpose child_event;
186
g_return_val_if_fail (widget != NULL, FALSE);
187
g_return_val_if_fail (GTK_IS_BIN (widget), FALSE);
188
g_return_val_if_fail (event != NULL, FALSE);
190
if (GTK_WIDGET_DRAWABLE (widget))
192
bin = GTK_BIN (widget);
194
child_event = *event;
195
if (bin->child && GTK_WIDGET_DRAWABLE (bin->child) &&
196
GTK_WIDGET_NO_WINDOW (bin->child) &&
197
gtk_widget_intersect (bin->child, &event->area, &child_event.area))
198
gtk_widget_event (bin->child, (GdkEvent*) &child_event);
206
gtk_bin_add (GtkContainer *container,
211
g_return_if_fail (container != NULL);
212
g_return_if_fail (GTK_IS_BIN (container));
213
g_return_if_fail (child != NULL);
214
g_return_if_fail (GTK_IS_WIDGET (child));
216
bin = GTK_BIN (container);
217
g_return_if_fail (bin->child == NULL);
219
gtk_widget_set_parent (child, GTK_WIDGET (bin));
222
if (GTK_WIDGET_REALIZED (child->parent))
223
gtk_widget_realize (child);
225
if (GTK_WIDGET_VISIBLE (child->parent) && GTK_WIDGET_VISIBLE (child))
227
if (GTK_WIDGET_MAPPED (child->parent))
228
gtk_widget_map (child);
230
gtk_widget_queue_resize (child);
235
gtk_bin_remove (GtkContainer *container,
239
gboolean widget_was_visible;
241
g_return_if_fail (container != NULL);
242
g_return_if_fail (GTK_IS_BIN (container));
243
g_return_if_fail (child != NULL);
244
g_return_if_fail (GTK_IS_WIDGET (child));
246
bin = GTK_BIN (container);
247
g_return_if_fail (bin->child == child);
249
widget_was_visible = GTK_WIDGET_VISIBLE (child);
251
gtk_widget_unparent (child);
254
/* queue resize regardless of GTK_WIDGET_VISIBLE (container),
255
* since that's what is needed by toplevels, which derive from GtkBin.
257
if (widget_was_visible)
258
gtk_widget_queue_resize (GTK_WIDGET (container));
262
gtk_bin_forall (GtkContainer *container,
263
gboolean include_internals,
264
GtkCallback callback,
265
gpointer callback_data)
269
g_return_if_fail (container != NULL);
270
g_return_if_fail (GTK_IS_BIN (container));
271
g_return_if_fail (callback != NULL);
273
bin = GTK_BIN (container);
276
(* callback) (bin->child, callback_data);