]> Pileus Git - ~andy/gtk/blob - gtk/gtkbin.c
Add hidden aliases for exported symbols which are used internally in order
[~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 <config.h>
28 #include "gtkalias.h"
29 #include "gtkbin.h"
30
31
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,
35                                  GtkWidget      *widget);
36 static void gtk_bin_remove      (GtkContainer   *container,
37                                  GtkWidget      *widget);
38 static void gtk_bin_forall      (GtkContainer   *container,
39                                  gboolean       include_internals,
40                                  GtkCallback     callback,
41                                  gpointer        callback_data);
42 static GType gtk_bin_child_type (GtkContainer   *container);
43
44
45 static GtkContainerClass *parent_class = NULL;
46
47
48 GType
49 gtk_bin_get_type (void)
50 {
51   static GType bin_type = 0;
52
53   if (!bin_type)
54     {
55       static const GTypeInfo bin_info =
56       {
57         sizeof (GtkBinClass),
58         NULL,           /* base_init */
59         NULL,           /* base_finalize */
60         (GClassInitFunc) gtk_bin_class_init,
61         NULL,           /* class_finalize */
62         NULL,           /* class_data */
63         sizeof (GtkBin),
64         0,              /* n_preallocs */
65         (GInstanceInitFunc) gtk_bin_init,
66         NULL,           /* value_table */
67       };
68
69       bin_type = g_type_register_static (GTK_TYPE_CONTAINER, "GtkBin", 
70                                          &bin_info, G_TYPE_FLAG_ABSTRACT);
71     }
72
73   return bin_type;
74 }
75
76 static void
77 gtk_bin_class_init (GtkBinClass *class)
78 {
79   GtkContainerClass *container_class;
80
81   container_class = (GtkContainerClass*) class;
82
83   parent_class = g_type_class_peek_parent (class);
84
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;
89 }
90
91 static void
92 gtk_bin_init (GtkBin *bin)
93 {
94   GTK_WIDGET_SET_FLAGS (bin, GTK_NO_WINDOW);
95
96   bin->child = NULL;
97 }
98
99
100 static GType
101 gtk_bin_child_type (GtkContainer *container)
102 {
103   if (!GTK_BIN (container)->child)
104     return GTK_TYPE_WIDGET;
105   else
106     return G_TYPE_NONE;
107 }
108
109 static void
110 gtk_bin_add (GtkContainer *container,
111              GtkWidget    *child)
112 {
113   GtkBin *bin = GTK_BIN (container);
114
115   g_return_if_fail (GTK_IS_WIDGET (child));
116
117   if (bin->child != NULL)
118     {
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)));
126       return;
127     }
128
129   gtk_widget_set_parent (child, GTK_WIDGET (bin));
130   bin->child = child;
131 }
132
133 static void
134 gtk_bin_remove (GtkContainer *container,
135                 GtkWidget    *child)
136 {
137   GtkBin *bin = GTK_BIN (container);
138   gboolean widget_was_visible;
139
140   g_return_if_fail (GTK_IS_WIDGET (child));
141   g_return_if_fail (bin->child == child);
142
143   widget_was_visible = GTK_WIDGET_VISIBLE (child);
144   
145   gtk_widget_unparent (child);
146   bin->child = NULL;
147   
148   /* queue resize regardless of GTK_WIDGET_VISIBLE (container),
149    * since that's what is needed by toplevels, which derive from GtkBin.
150    */
151   if (widget_was_visible)
152     gtk_widget_queue_resize (GTK_WIDGET (container));
153 }
154
155 static void
156 gtk_bin_forall (GtkContainer *container,
157                 gboolean      include_internals,
158                 GtkCallback   callback,
159                 gpointer      callback_data)
160 {
161   GtkBin *bin = GTK_BIN (container);
162
163   g_return_if_fail (callback != NULL);
164
165   if (bin->child)
166     (* callback) (bin->child, callback_data);
167 }
168
169 /**
170  * gtk_bin_get_child:
171  * @bin: a #GtkBin
172  * 
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.
176  * 
177  * Return value: pointer to child of the #GtkBin
178  **/
179 GtkWidget*
180 gtk_bin_get_child (GtkBin *bin)
181 {
182   g_return_val_if_fail (GTK_IS_BIN (bin), NULL);
183
184   return bin->child;
185 }