]> Pileus Git - ~andy/gtk/blob - gtk/gtkbin.c
Updated Spanish translation
[~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 /**
28  * SECTION:gtkbin
29  * @Short_description: A container with just one child
30  * @Title: GtkBin
31  *
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.
35  *
36  * Many GTK+ widgets are subclasses of #GtkBin, including #GtkWindow,
37  * #GtkButton, #GtkFrame, #GtkHandleBox or #GtkScrolledWindow.
38  */
39
40 #include "config.h"
41 #include "gtkbin.h"
42 #include "gtkintl.h"
43 #include "gtkalias.h"
44
45 static void gtk_bin_add         (GtkContainer   *container,
46                                  GtkWidget      *widget);
47 static void gtk_bin_remove      (GtkContainer   *container,
48                                  GtkWidget      *widget);
49 static void gtk_bin_forall      (GtkContainer   *container,
50                                  gboolean       include_internals,
51                                  GtkCallback     callback,
52                                  gpointer        callback_data);
53 static GType gtk_bin_child_type (GtkContainer   *container);
54
55
56 G_DEFINE_ABSTRACT_TYPE (GtkBin, gtk_bin, GTK_TYPE_CONTAINER)
57
58 static void
59 gtk_bin_class_init (GtkBinClass *class)
60 {
61   GtkContainerClass *container_class;
62
63   container_class = (GtkContainerClass*) class;
64
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;
69 }
70
71 static void
72 gtk_bin_init (GtkBin *bin)
73 {
74   gtk_widget_set_has_window (GTK_WIDGET (bin), FALSE);
75
76   bin->child = NULL;
77 }
78
79
80 static GType
81 gtk_bin_child_type (GtkContainer *container)
82 {
83   if (!GTK_BIN (container)->child)
84     return GTK_TYPE_WIDGET;
85   else
86     return G_TYPE_NONE;
87 }
88
89 static void
90 gtk_bin_add (GtkContainer *container,
91              GtkWidget    *child)
92 {
93   GtkBin *bin = GTK_BIN (container);
94
95   if (bin->child != NULL)
96     {
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)));
104       return;
105     }
106
107   gtk_widget_set_parent (child, GTK_WIDGET (bin));
108   bin->child = child;
109 }
110
111 static void
112 gtk_bin_remove (GtkContainer *container,
113                 GtkWidget    *child)
114 {
115   GtkBin *bin = GTK_BIN (container);
116   gboolean widget_was_visible;
117
118   g_return_if_fail (bin->child == child);
119
120   widget_was_visible = gtk_widget_get_visible (child);
121   
122   gtk_widget_unparent (child);
123   bin->child = NULL;
124   
125   /* queue resize regardless of gtk_widget_get_visible (container),
126    * since that's what is needed by toplevels, which derive from GtkBin.
127    */
128   if (widget_was_visible)
129     gtk_widget_queue_resize (GTK_WIDGET (container));
130 }
131
132 static void
133 gtk_bin_forall (GtkContainer *container,
134                 gboolean      include_internals,
135                 GtkCallback   callback,
136                 gpointer      callback_data)
137 {
138   GtkBin *bin = GTK_BIN (container);
139
140   if (bin->child)
141     (* callback) (bin->child, callback_data);
142 }
143
144 /**
145  * gtk_bin_get_child:
146  * @bin: a #GtkBin
147  * 
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.
151  *
152  * Return value: (transfer none): pointer to child of the #GtkBin
153  **/
154 GtkWidget*
155 gtk_bin_get_child (GtkBin *bin)
156 {
157   g_return_val_if_fail (GTK_IS_BIN (bin), NULL);
158
159   return bin->child;
160 }
161
162 #define __GTK_BIN_C__
163 #include "gtkaliasdef.c"