1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 Base class for widgets which contain other widgets
7 <!-- ##### SECTION Long_Description ##### -->
9 A GTK+ user interface is constructed by nesting widgets inside widgets.
10 Container widgets are the inner nodes in the resulting tree of widgets:
11 they contain other widgets. So, for example, you might have a #GtkWindow
12 containing a #GtkFrame containing a GtkLabel. If you wanted an image instead
13 of a textual label inside the frame, you might replace the #GtkLabel widget
14 with a #GtkImage widget.
17 There are two major kinds of container widgets in GTK+. Both are subclasses
18 of the abstract #GtkContainer base class.
21 The first type of container widget has a single child widget and derives
22 from #GtkBin. These containers are <firstterm>decorators</firstterm>, which
23 add some kind of functionality to the child. For example, a #GtkButton makes
24 its child into a clickable button; a #GtkFrame draws a frame around its child
25 and a #GtkWindow places its child widget inside a top-level window.
28 The second type of container can have more than one child; its purpose is to
29 manage <firstterm>layout</firstterm>. This means that these containers assign
30 sizes and positions to their children. For example, a #GtkHBox arranges its
31 children in a horizontal row, and a #GtkTable arranges the widgets it contains
32 in a two-dimensional grid.
35 To fulfill its task, a layout container must negotiate the size requirements
36 with its parent and its children. This negotiation is carried out in two
37 phases, <firstterm>size requisition</firstterm> and <firstterm>size
38 allocation</firstterm>.
40 <refsect2 id="size-requisition"><title>Size Requisition</title>
42 The size requisition of a widget is it's desired width and height.
43 This is represented by a #GtkRequisition.
46 How a widget determines its desired size depends on the widget.
47 A #GtkLabel, for example, requests enough space to display all its text.
48 Container widgets generally base their size request on the requisitions
52 The size requisition phase of the widget layout process operates top-down.
53 It starts at a top-level widget, typically a #GtkWindow. The top-level widget
54 asks its child for its size requisition by calling gtk_widget_size_request().
55 To determine its requisition, the child asks its own children for their
56 requisitions and so on. Finally, the top-level widget will get a requisition
60 <refsect2 id="size-allocation"><title>Size Allocation</title>
62 When the top-level widget has determined how much space its child would like
63 to have, the second phase of the size negotiation, size allocation, begins.
64 Depending on its configuration (see gtk_window_set_resizable()), the top-level
65 widget may be able to expand in order to satisfy the size request or it may
66 have to ignore the size request and keep its fixed size. It then tells its
67 child widget how much space it gets by calling gtk_widget_size_allocate().
68 The child widget divides the space among its children and tells each child
69 how much space it got, and so on. Under normal circumstances, a #GtkWindow
70 will always give its child the amount of space the child requested.
73 A child's size allocation is represented by a #GtkAllocation. This struct
74 contains not only a width and height, but also a position (i.e. X and Y
75 coordinates), so that containers can tell their children not only how much
76 space they have gotten, but also where they are positioned inside the space
77 available to the container.
80 Widgets are required to honor the size allocation they receive; a size
81 request is only a request, and widgets must be able to cope with any size.
84 <refsect2 id="child-properties"><title>Child properties</title>
86 <structname>GtkContainer</structname> introduces <firstterm>child
87 properties</firstterm> - these are object properties that are not specific
88 to either the container or the contained widget, but rather to their relation.
89 Typical examples of child properties are the position or pack-type of a widget
90 which is contained in a #GtkBox.</para>
92 Use gtk_container_class_install_child_property() to install child properties
93 for a container class and gtk_container_class_find_child_property() or
94 gtk_container_class_list_child_properties() to get information about existing
98 To set the value of a child property, use gtk_container_child_set_property(),
99 gtk_container_child_set() or gtk_container_child_set_valist().
100 To obtain the value of a child property, use
101 gtk_container_child_get_property(), gtk_container_child_get() or
102 gtk_container_child_get_valist(). To emit notification about child property
103 changes, use gtk_widget_child_notify().
107 <refsect2 id="GtkContainer-BUILDER-UI">
108 <title>GtkContainer as GtkBuildable</title>
110 The GtkContainer implementation of the GtkBuildable interface
111 supports a <packing> element for children, which can
112 contain multiple <property> elements that specify
113 child properties for the child.
116 <title>Child properties in UI definitions</title>
117 <programlisting><![CDATA[
118 <object class="GtkVBox">
120 <object class="GtkLabel"/>
122 <property name="pack-type">start</property>
129 Since 2.16, child properties can also be marked as translatable using
130 the same "translatable", "comments" and "context" attributes that are used
131 for regular properties.
135 <!-- ##### SECTION See_Also ##### -->
140 <!-- ##### SECTION Stability_Level ##### -->
143 <!-- ##### STRUCT GtkContainer ##### -->
149 <!-- ##### SIGNAL GtkContainer::add ##### -->
154 @container: the object which received the signal.
157 <!-- ##### SIGNAL GtkContainer::check-resize ##### -->
162 @container: the object which received the signal.
164 <!-- ##### SIGNAL GtkContainer::remove ##### -->
169 @container: the object which received the signal.
172 <!-- ##### SIGNAL GtkContainer::set-focus-child ##### -->
177 @container: the object which received the signal.
180 <!-- ##### ARG GtkContainer:border-width ##### -->
185 <!-- ##### ARG GtkContainer:child ##### -->
190 <!-- ##### ARG GtkContainer:resize-mode ##### -->
195 <!-- ##### MACRO GTK_IS_RESIZE_CONTAINER ##### -->
203 <!-- ##### MACRO GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID ##### -->
205 This macro should be used to emit a standard warning about unexpected
206 properties in set_child_property() and get_child_property() implementations.
209 @object: the #GObject on which set_child_property() or get_child_property()
211 @property_id: the numeric id of the property
212 @pspec: the #GParamSpec of the property
215 <!-- ##### MACRO gtk_container_border_width ##### -->
217 Does the same as gtk_container_set_border_width().
220 @Deprecated: Use gtk_container_set_border_width() instead.
223 <!-- ##### FUNCTION gtk_container_add ##### -->
232 <!-- ##### FUNCTION gtk_container_remove ##### -->
241 <!-- ##### FUNCTION gtk_container_add_with_properties ##### -->
252 <!-- ##### FUNCTION gtk_container_get_resize_mode ##### -->
261 <!-- ##### FUNCTION gtk_container_set_resize_mode ##### -->
270 <!-- ##### FUNCTION gtk_container_check_resize ##### -->
278 <!-- ##### FUNCTION gtk_container_foreach ##### -->
288 <!-- ##### FUNCTION gtk_container_foreach_full ##### -->
298 @Deprecated: Use gtk_container_foreach() instead.
301 <!-- ##### MACRO gtk_container_children ##### -->
303 Does the same as gtk_container_get_children().
306 @Deprecated: Use gtk_container_get_children() instead.
309 <!-- ##### FUNCTION gtk_container_get_children ##### -->
318 <!-- ##### FUNCTION gtk_container_set_reallocate_redraws ##### -->
327 <!-- ##### FUNCTION gtk_container_get_focus_child ##### -->
336 <!-- ##### FUNCTION gtk_container_set_focus_child ##### -->
345 <!-- ##### FUNCTION gtk_container_get_focus_vadjustment ##### -->
354 <!-- ##### FUNCTION gtk_container_set_focus_vadjustment ##### -->
363 <!-- ##### FUNCTION gtk_container_get_focus_hadjustment ##### -->
372 <!-- ##### FUNCTION gtk_container_set_focus_hadjustment ##### -->
381 <!-- ##### FUNCTION gtk_container_resize_children ##### -->
389 <!-- ##### FUNCTION gtk_container_child_type ##### -->
398 <!-- ##### FUNCTION gtk_container_child_get ##### -->
409 <!-- ##### FUNCTION gtk_container_child_set ##### -->
420 <!-- ##### FUNCTION gtk_container_child_get_property ##### -->
431 <!-- ##### FUNCTION gtk_container_child_set_property ##### -->
442 <!-- ##### FUNCTION gtk_container_child_get_valist ##### -->
449 @first_property_name:
453 <!-- ##### FUNCTION gtk_container_child_set_valist ##### -->
460 @first_property_name:
464 <!-- ##### FUNCTION gtk_container_forall ##### -->
474 <!-- ##### FUNCTION gtk_container_get_border_width ##### -->
483 <!-- ##### FUNCTION gtk_container_set_border_width ##### -->
492 <!-- ##### FUNCTION gtk_container_propagate_expose ##### -->
502 <!-- ##### FUNCTION gtk_container_get_focus_chain ##### -->
512 <!-- ##### FUNCTION gtk_container_set_focus_chain ##### -->
521 <!-- ##### FUNCTION gtk_container_unset_focus_chain ##### -->
529 <!-- ##### FUNCTION gtk_container_class_find_child_property ##### -->
539 <!-- ##### FUNCTION gtk_container_class_install_child_property ##### -->
549 <!-- ##### FUNCTION gtk_container_class_list_child_properties ##### -->