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/.
30 static void gtk_bin_class_init (GtkBinClass *klass);
31 static void gtk_bin_init (GtkBin *bin);
32 static void gtk_bin_add (GtkContainer *container,
34 static void gtk_bin_remove (GtkContainer *container,
36 static void gtk_bin_forall (GtkContainer *container,
37 gboolean include_internals,
39 gpointer callback_data);
40 static GtkType gtk_bin_child_type (GtkContainer*container);
43 static GtkContainerClass *parent_class = NULL;
47 gtk_bin_get_type (void)
49 static GtkType bin_type = 0;
53 static const GTypeInfo bin_info =
57 NULL, /* base_finalize */
58 (GClassInitFunc) gtk_bin_class_init,
59 NULL, /* class_finalize */
60 NULL, /* class_data */
63 (GInstanceInitFunc) gtk_bin_init,
64 NULL, /* value_table */
67 bin_type = g_type_register_static (GTK_TYPE_CONTAINER, "GtkBin",
68 &bin_info, G_TYPE_FLAG_ABSTRACT);
75 gtk_bin_class_init (GtkBinClass *class)
77 GtkObjectClass *object_class;
78 GtkWidgetClass *widget_class;
79 GtkContainerClass *container_class;
81 object_class = (GtkObjectClass*) class;
82 widget_class = (GtkWidgetClass*) class;
83 container_class = (GtkContainerClass*) class;
85 parent_class = gtk_type_class (GTK_TYPE_CONTAINER);
87 container_class->add = gtk_bin_add;
88 container_class->remove = gtk_bin_remove;
89 container_class->forall = gtk_bin_forall;
90 container_class->child_type = gtk_bin_child_type;
94 gtk_bin_init (GtkBin *bin)
96 GTK_WIDGET_SET_FLAGS (bin, GTK_NO_WINDOW);
103 gtk_bin_child_type (GtkContainer *container)
105 if (!GTK_BIN (container)->child)
106 return GTK_TYPE_WIDGET;
108 return GTK_TYPE_NONE;
112 gtk_bin_add (GtkContainer *container,
115 GtkBin *bin = GTK_BIN (container);
117 g_return_if_fail (GTK_IS_WIDGET (child));
119 if (bin->child != NULL)
121 g_warning ("Attempting to add a widget with type %s to a %s, "
122 "but as a GtkBin subclass a %s can only contain one widget at a time; "
123 "it already contains a widget of type %s",
124 g_type_name (G_OBJECT_TYPE (child)),
125 g_type_name (G_OBJECT_TYPE (bin)),
126 g_type_name (G_OBJECT_TYPE (bin)),
127 g_type_name (G_OBJECT_TYPE (bin->child)));
131 gtk_widget_set_parent (child, GTK_WIDGET (bin));
136 gtk_bin_remove (GtkContainer *container,
139 GtkBin *bin = GTK_BIN (container);
140 gboolean widget_was_visible;
142 g_return_if_fail (GTK_IS_WIDGET (child));
143 g_return_if_fail (bin->child == child);
145 widget_was_visible = GTK_WIDGET_VISIBLE (child);
147 gtk_widget_unparent (child);
150 /* queue resize regardless of GTK_WIDGET_VISIBLE (container),
151 * since that's what is needed by toplevels, which derive from GtkBin.
153 if (widget_was_visible)
154 gtk_widget_queue_resize (GTK_WIDGET (container));
158 gtk_bin_forall (GtkContainer *container,
159 gboolean include_internals,
160 GtkCallback callback,
161 gpointer callback_data)
163 GtkBin *bin = GTK_BIN (container);
165 g_return_if_fail (callback != NULL);
168 (* callback) (bin->child, callback_data);
175 * Gets the child of the #GtkBin, or %NULL if the bin contains
176 * no child widget. The returned widget does not have a reference
177 * added, so you do not need to unref it.
179 * Return value: pointer to child of the #GtkBin
182 gtk_bin_get_child (GtkBin *bin)
184 g_return_val_if_fail (GTK_IS_BIN (bin), NULL);