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