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/.
29 * @Short_description: A container with just one child
32 * The #GtkBin widget is a container with just one child.
33 * It is not very useful itself, but it is useful for deriving subclasses,
34 * since it provides common code needed for handling a single child widget.
36 * Many GTK+ widgets are subclasses of #GtkBin, including #GtkWindow,
37 * #GtkButton, #GtkFrame, #GtkHandleBox or #GtkScrolledWindow.
45 static void gtk_bin_add (GtkContainer *container,
47 static void gtk_bin_remove (GtkContainer *container,
49 static void gtk_bin_forall (GtkContainer *container,
50 gboolean include_internals,
52 gpointer callback_data);
53 static GType gtk_bin_child_type (GtkContainer *container);
56 G_DEFINE_ABSTRACT_TYPE (GtkBin, gtk_bin, GTK_TYPE_CONTAINER)
59 gtk_bin_class_init (GtkBinClass *class)
61 GtkContainerClass *container_class;
63 container_class = (GtkContainerClass*) class;
65 container_class->add = gtk_bin_add;
66 container_class->remove = gtk_bin_remove;
67 container_class->forall = gtk_bin_forall;
68 container_class->child_type = gtk_bin_child_type;
72 gtk_bin_init (GtkBin *bin)
74 gtk_widget_set_has_window (GTK_WIDGET (bin), FALSE);
81 gtk_bin_child_type (GtkContainer *container)
83 if (!GTK_BIN (container)->child)
84 return GTK_TYPE_WIDGET;
90 gtk_bin_add (GtkContainer *container,
93 GtkBin *bin = GTK_BIN (container);
95 if (bin->child != NULL)
97 g_warning ("Attempting to add a widget with type %s to a %s, "
98 "but as a GtkBin subclass a %s can only contain one widget at a time; "
99 "it already contains a widget of type %s",
100 g_type_name (G_OBJECT_TYPE (child)),
101 g_type_name (G_OBJECT_TYPE (bin)),
102 g_type_name (G_OBJECT_TYPE (bin)),
103 g_type_name (G_OBJECT_TYPE (bin->child)));
107 gtk_widget_set_parent (child, GTK_WIDGET (bin));
112 gtk_bin_remove (GtkContainer *container,
115 GtkBin *bin = GTK_BIN (container);
116 gboolean widget_was_visible;
118 g_return_if_fail (bin->child == child);
120 widget_was_visible = gtk_widget_get_visible (child);
122 gtk_widget_unparent (child);
125 /* queue resize regardless of gtk_widget_get_visible (container),
126 * since that's what is needed by toplevels, which derive from GtkBin.
128 if (widget_was_visible)
129 gtk_widget_queue_resize (GTK_WIDGET (container));
133 gtk_bin_forall (GtkContainer *container,
134 gboolean include_internals,
135 GtkCallback callback,
136 gpointer callback_data)
138 GtkBin *bin = GTK_BIN (container);
141 (* callback) (bin->child, callback_data);
148 * Gets the child of the #GtkBin, or %NULL if the bin contains
149 * no child widget. The returned widget does not have a reference
150 * added, so you do not need to unref it.
152 * Return value: (transfer none): pointer to child of the #GtkBin
155 gtk_bin_get_child (GtkBin *bin)
157 g_return_val_if_fail (GTK_IS_BIN (bin), NULL);
162 #define __GTK_BIN_C__
163 #include "gtkaliasdef.c"