]> Pileus Git - ~andy/gtk/blob - gtk/gtkbin.c
Deprecation cleanup
[~andy/gtk] / gtk / gtkbin.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 /*
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/. 
25  */
26
27 #include "gtkbin.h"
28
29
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,
33                                  GtkWidget      *widget);
34 static void gtk_bin_remove      (GtkContainer   *container,
35                                  GtkWidget      *widget);
36 static void gtk_bin_forall      (GtkContainer   *container,
37                                  gboolean       include_internals,
38                                  GtkCallback     callback,
39                                  gpointer        callback_data);
40 static GType gtk_bin_child_type (GtkContainer   *container);
41
42
43 static GtkContainerClass *parent_class = NULL;
44
45
46 GType
47 gtk_bin_get_type (void)
48 {
49   static GType bin_type = 0;
50
51   if (!bin_type)
52     {
53       static const GTypeInfo bin_info =
54       {
55         sizeof (GtkBinClass),
56         NULL,           /* base_init */
57         NULL,           /* base_finalize */
58         (GClassInitFunc) gtk_bin_class_init,
59         NULL,           /* class_finalize */
60         NULL,           /* class_data */
61         sizeof (GtkBin),
62         0,              /* n_preallocs */
63         (GInstanceInitFunc) gtk_bin_init,
64         NULL,           /* value_table */
65       };
66
67       bin_type = g_type_register_static (GTK_TYPE_CONTAINER, "GtkBin", 
68                                          &bin_info, G_TYPE_FLAG_ABSTRACT);
69     }
70
71   return bin_type;
72 }
73
74 static void
75 gtk_bin_class_init (GtkBinClass *class)
76 {
77   GtkContainerClass *container_class;
78
79   container_class = (GtkContainerClass*) class;
80
81   parent_class = g_type_class_peek_parent (class);
82
83   container_class->add = gtk_bin_add;
84   container_class->remove = gtk_bin_remove;
85   container_class->forall = gtk_bin_forall;
86   container_class->child_type = gtk_bin_child_type;
87 }
88
89 static void
90 gtk_bin_init (GtkBin *bin)
91 {
92   GTK_WIDGET_SET_FLAGS (bin, GTK_NO_WINDOW);
93
94   bin->child = NULL;
95 }
96
97
98 static GType
99 gtk_bin_child_type (GtkContainer *container)
100 {
101   if (!GTK_BIN (container)->child)
102     return GTK_TYPE_WIDGET;
103   else
104     return G_TYPE_NONE;
105 }
106
107 static void
108 gtk_bin_add (GtkContainer *container,
109              GtkWidget    *child)
110 {
111   GtkBin *bin = GTK_BIN (container);
112
113   g_return_if_fail (GTK_IS_WIDGET (child));
114
115   if (bin->child != NULL)
116     {
117       g_warning ("Attempting to add a widget with type %s to a %s, "
118                  "but as a GtkBin subclass a %s can only contain one widget at a time; "
119                  "it already contains a widget of type %s",
120                  g_type_name (G_OBJECT_TYPE (child)),
121                  g_type_name (G_OBJECT_TYPE (bin)),
122                  g_type_name (G_OBJECT_TYPE (bin)),
123                  g_type_name (G_OBJECT_TYPE (bin->child)));
124       return;
125     }
126
127   gtk_widget_set_parent (child, GTK_WIDGET (bin));
128   bin->child = child;
129 }
130
131 static void
132 gtk_bin_remove (GtkContainer *container,
133                 GtkWidget    *child)
134 {
135   GtkBin *bin = GTK_BIN (container);
136   gboolean widget_was_visible;
137
138   g_return_if_fail (GTK_IS_WIDGET (child));
139   g_return_if_fail (bin->child == child);
140
141   widget_was_visible = GTK_WIDGET_VISIBLE (child);
142   
143   gtk_widget_unparent (child);
144   bin->child = NULL;
145   
146   /* queue resize regardless of GTK_WIDGET_VISIBLE (container),
147    * since that's what is needed by toplevels, which derive from GtkBin.
148    */
149   if (widget_was_visible)
150     gtk_widget_queue_resize (GTK_WIDGET (container));
151 }
152
153 static void
154 gtk_bin_forall (GtkContainer *container,
155                 gboolean      include_internals,
156                 GtkCallback   callback,
157                 gpointer      callback_data)
158 {
159   GtkBin *bin = GTK_BIN (container);
160
161   g_return_if_fail (callback != NULL);
162
163   if (bin->child)
164     (* callback) (bin->child, callback_data);
165 }
166
167 /**
168  * gtk_bin_get_child:
169  * @bin: a #GtkBin
170  * 
171  * Gets the child of the #GtkBin, or %NULL if the bin contains
172  * no child widget. The returned widget does not have a reference
173  * added, so you do not need to unref it.
174  * 
175  * Return value: pointer to child of the #GtkBin
176  **/
177 GtkWidget*
178 gtk_bin_get_child (GtkBin *bin)
179 {
180   g_return_val_if_fail (GTK_IS_BIN (bin), NULL);
181
182   return bin->child;
183 }