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/.
33 static void gtk_bin_class_init (GtkBinClass *klass);
34 static void gtk_bin_init (GtkBin *bin);
35 static void gtk_bin_add (GtkContainer *container,
37 static void gtk_bin_remove (GtkContainer *container,
39 static void gtk_bin_forall (GtkContainer *container,
40 gboolean include_internals,
42 gpointer callback_data);
43 static GType gtk_bin_child_type (GtkContainer *container);
46 static GtkContainerClass *parent_class = NULL;
50 gtk_bin_get_type (void)
52 static GType bin_type = 0;
56 static const GTypeInfo bin_info =
60 NULL, /* base_finalize */
61 (GClassInitFunc) gtk_bin_class_init,
62 NULL, /* class_finalize */
63 NULL, /* class_data */
66 (GInstanceInitFunc) gtk_bin_init,
67 NULL, /* value_table */
70 bin_type = g_type_register_static (GTK_TYPE_CONTAINER, I_("GtkBin"),
71 &bin_info, G_TYPE_FLAG_ABSTRACT);
78 gtk_bin_class_init (GtkBinClass *class)
80 GtkContainerClass *container_class;
82 container_class = (GtkContainerClass*) class;
84 parent_class = g_type_class_peek_parent (class);
86 container_class->add = gtk_bin_add;
87 container_class->remove = gtk_bin_remove;
88 container_class->forall = gtk_bin_forall;
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;
111 gtk_bin_add (GtkContainer *container,
114 GtkBin *bin = GTK_BIN (container);
116 g_return_if_fail (GTK_IS_WIDGET (child));
118 if (bin->child != NULL)
120 g_warning ("Attempting to add a widget with type %s to a %s, "
121 "but as a GtkBin subclass a %s can only contain one widget at a time; "
122 "it already contains a widget of type %s",
123 g_type_name (G_OBJECT_TYPE (child)),
124 g_type_name (G_OBJECT_TYPE (bin)),
125 g_type_name (G_OBJECT_TYPE (bin)),
126 g_type_name (G_OBJECT_TYPE (bin->child)));
130 gtk_widget_set_parent (child, GTK_WIDGET (bin));
135 gtk_bin_remove (GtkContainer *container,
138 GtkBin *bin = GTK_BIN (container);
139 gboolean widget_was_visible;
141 g_return_if_fail (GTK_IS_WIDGET (child));
142 g_return_if_fail (bin->child == child);
144 widget_was_visible = GTK_WIDGET_VISIBLE (child);
146 gtk_widget_unparent (child);
149 /* queue resize regardless of GTK_WIDGET_VISIBLE (container),
150 * since that's what is needed by toplevels, which derive from GtkBin.
152 if (widget_was_visible)
153 gtk_widget_queue_resize (GTK_WIDGET (container));
157 gtk_bin_forall (GtkContainer *container,
158 gboolean include_internals,
159 GtkCallback callback,
160 gpointer callback_data)
162 GtkBin *bin = GTK_BIN (container);
164 g_return_if_fail (callback != NULL);
167 (* callback) (bin->child, callback_data);
174 * Gets the child of the #GtkBin, or %NULL if the bin contains
175 * no child widget. The returned widget does not have a reference
176 * added, so you do not need to unref it.
178 * Return value: pointer to child of the #GtkBin
181 gtk_bin_get_child (GtkBin *bin)
183 g_return_val_if_fail (GTK_IS_BIN (bin), NULL);
188 #define __GTK_BIN_C__
189 #include "gtkaliasdef.c"