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/.
32 static void gtk_bin_class_init (GtkBinClass *klass);
33 static void gtk_bin_init (GtkBin *bin);
34 static void gtk_bin_add (GtkContainer *container,
36 static void gtk_bin_remove (GtkContainer *container,
38 static void gtk_bin_forall (GtkContainer *container,
39 gboolean include_internals,
41 gpointer callback_data);
42 static GType gtk_bin_child_type (GtkContainer *container);
45 static GtkContainerClass *parent_class = NULL;
49 gtk_bin_get_type (void)
51 static GType bin_type = 0;
55 static const GTypeInfo bin_info =
59 NULL, /* base_finalize */
60 (GClassInitFunc) gtk_bin_class_init,
61 NULL, /* class_finalize */
62 NULL, /* class_data */
65 (GInstanceInitFunc) gtk_bin_init,
66 NULL, /* value_table */
69 bin_type = g_type_register_static (GTK_TYPE_CONTAINER, "GtkBin",
70 &bin_info, G_TYPE_FLAG_ABSTRACT);
77 gtk_bin_class_init (GtkBinClass *class)
79 GtkContainerClass *container_class;
81 container_class = (GtkContainerClass*) class;
83 parent_class = g_type_class_peek_parent (class);
85 container_class->add = gtk_bin_add;
86 container_class->remove = gtk_bin_remove;
87 container_class->forall = gtk_bin_forall;
88 container_class->child_type = gtk_bin_child_type;
92 gtk_bin_init (GtkBin *bin)
94 GTK_WIDGET_SET_FLAGS (bin, GTK_NO_WINDOW);
101 gtk_bin_child_type (GtkContainer *container)
103 if (!GTK_BIN (container)->child)
104 return GTK_TYPE_WIDGET;
110 gtk_bin_add (GtkContainer *container,
113 GtkBin *bin = GTK_BIN (container);
115 g_return_if_fail (GTK_IS_WIDGET (child));
117 if (bin->child != NULL)
119 g_warning ("Attempting to add a widget with type %s to a %s, "
120 "but as a GtkBin subclass a %s can only contain one widget at a time; "
121 "it already contains a widget of type %s",
122 g_type_name (G_OBJECT_TYPE (child)),
123 g_type_name (G_OBJECT_TYPE (bin)),
124 g_type_name (G_OBJECT_TYPE (bin)),
125 g_type_name (G_OBJECT_TYPE (bin->child)));
129 gtk_widget_set_parent (child, GTK_WIDGET (bin));
134 gtk_bin_remove (GtkContainer *container,
137 GtkBin *bin = GTK_BIN (container);
138 gboolean widget_was_visible;
140 g_return_if_fail (GTK_IS_WIDGET (child));
141 g_return_if_fail (bin->child == child);
143 widget_was_visible = GTK_WIDGET_VISIBLE (child);
145 gtk_widget_unparent (child);
148 /* queue resize regardless of GTK_WIDGET_VISIBLE (container),
149 * since that's what is needed by toplevels, which derive from GtkBin.
151 if (widget_was_visible)
152 gtk_widget_queue_resize (GTK_WIDGET (container));
156 gtk_bin_forall (GtkContainer *container,
157 gboolean include_internals,
158 GtkCallback callback,
159 gpointer callback_data)
161 GtkBin *bin = GTK_BIN (container);
163 g_return_if_fail (callback != NULL);
166 (* callback) (bin->child, callback_data);
173 * Gets the child of the #GtkBin, or %NULL if the bin contains
174 * no child widget. The returned widget does not have a reference
175 * added, so you do not need to unref it.
177 * Return value: pointer to child of the #GtkBin
180 gtk_bin_get_child (GtkBin *bin)
182 g_return_val_if_fail (GTK_IS_BIN (bin), NULL);