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. The basic form of this negotiation is
37 carried out in two phases, <firstterm>size requisition</firstterm> and
38 <firstterm>size allocation</firstterm>, which are implemented by the
39 size_request() and size_allocate() virtual functions in #GtkWidget.
42 GTK+ also supports a more complicated form of size negotiation called
43 <firstterm>width-for-height</firstterm> (and its dual
44 <firstterm>height-for-width</firstterm>). See #GtkExtendedLayout
45 to learn more about width-for-height geometry management.
47 <refsect2 id="size-requisition"><title>Size Requisition</title>
49 The size requisition of a widget is it's desired width and height.
50 This is represented by a #GtkRequisition.
53 How a widget determines its desired size depends on the widget.
54 A #GtkLabel, for example, requests enough space to display all its text.
55 Container widgets generally base their size request on the requisitions
59 The size requisition phase of the widget layout process operates top-down.
60 It starts at a top-level widget, typically a #GtkWindow. The top-level widget
61 asks its child for its size requisition by calling gtk_widget_size_request().
62 To determine its requisition, the child asks its own children for their
63 requisitions and so on. Finally, the top-level widget will get a requisition
67 <refsect2 id="size-allocation"><title>Size Allocation</title>
69 When the top-level widget has determined how much space its child would like
70 to have, the second phase of the size negotiation, size allocation, begins.
71 Depending on its configuration (see gtk_window_set_resizable()), the top-level
72 widget may be able to expand in order to satisfy the size request or it may
73 have to ignore the size request and keep its fixed size. It then tells its
74 child widget how much space it gets by calling gtk_widget_size_allocate().
75 The child widget divides the space among its children and tells each child
76 how much space it got, and so on. Under normal circumstances, a #GtkWindow
77 will always give its child the amount of space the child requested.
80 A child's size allocation is represented by a #GtkAllocation. This struct
81 contains not only a width and height, but also a position (i.e. X and Y
82 coordinates), so that containers can tell their children not only how much
83 space they have gotten, but also where they are positioned inside the space
84 available to the container.
87 Widgets are required to honor the size allocation they receive; a size
88 request is only a request, and widgets must be able to cope with any size.
91 <refsect2 id="child-properties"><title>Child properties</title>
93 <structname>GtkContainer</structname> introduces <firstterm>child
94 properties</firstterm> - these are object properties that are not specific
95 to either the container or the contained widget, but rather to their relation.
96 Typical examples of child properties are the position or pack-type of a widget
97 which is contained in a #GtkBox.</para>
99 Use gtk_container_class_install_child_property() to install child properties
100 for a container class and gtk_container_class_find_child_property() or
101 gtk_container_class_list_child_properties() to get information about existing
105 To set the value of a child property, use gtk_container_child_set_property(),
106 gtk_container_child_set() or gtk_container_child_set_valist().
107 To obtain the value of a child property, use
108 gtk_container_child_get_property(), gtk_container_child_get() or
109 gtk_container_child_get_valist(). To emit notification about child property
110 changes, use gtk_widget_child_notify().
114 <refsect2 id="GtkContainer-BUILDER-UI">
115 <title>GtkContainer as GtkBuildable</title>
117 The GtkContainer implementation of the GtkBuildable interface
118 supports a <packing> element for children, which can
119 contain multiple <property> elements that specify
120 child properties for the child.
123 <title>Child properties in UI definitions</title>
124 <programlisting><![CDATA[
125 <object class="GtkVBox">
127 <object class="GtkLabel"/>
129 <property name="pack-type">start</property>
136 Since 2.16, child properties can also be marked as translatable using
137 the same "translatable", "comments" and "context" attributes that are used
138 for regular properties.
142 <!-- ##### SECTION See_Also ##### -->
147 <!-- ##### SECTION Stability_Level ##### -->
150 <!-- ##### SECTION Image ##### -->
153 <!-- ##### STRUCT GtkContainer ##### -->
159 <!-- ##### SIGNAL GtkContainer::add ##### -->
164 @container: the object which received the signal.
167 <!-- ##### SIGNAL GtkContainer::check-resize ##### -->
172 @container: the object which received the signal.
174 <!-- ##### SIGNAL GtkContainer::remove ##### -->
179 @container: the object which received the signal.
182 <!-- ##### SIGNAL GtkContainer::set-focus-child ##### -->
187 @container: the object which received the signal.
190 <!-- ##### ARG GtkContainer:border-width ##### -->
195 <!-- ##### ARG GtkContainer:child ##### -->
200 <!-- ##### ARG GtkContainer:resize-mode ##### -->
205 <!-- ##### MACRO GTK_IS_RESIZE_CONTAINER ##### -->
213 <!-- ##### MACRO GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID ##### -->
215 This macro should be used to emit a standard warning about unexpected
216 properties in set_child_property() and get_child_property() implementations.
219 @object: the #GObject on which set_child_property() or get_child_property()
221 @property_id: the numeric id of the property
222 @pspec: the #GParamSpec of the property
225 <!-- ##### FUNCTION gtk_container_add ##### -->
234 <!-- ##### FUNCTION gtk_container_remove ##### -->
243 <!-- ##### FUNCTION gtk_container_add_with_properties ##### -->
254 <!-- ##### FUNCTION gtk_container_get_resize_mode ##### -->
263 <!-- ##### FUNCTION gtk_container_set_resize_mode ##### -->
272 <!-- ##### FUNCTION gtk_container_check_resize ##### -->
280 <!-- ##### FUNCTION gtk_container_foreach ##### -->
290 <!-- ##### FUNCTION gtk_container_get_children ##### -->
299 <!-- ##### FUNCTION gtk_container_set_reallocate_redraws ##### -->
308 <!-- ##### FUNCTION gtk_container_get_focus_child ##### -->
317 <!-- ##### FUNCTION gtk_container_set_focus_child ##### -->
326 <!-- ##### FUNCTION gtk_container_get_focus_vadjustment ##### -->
335 <!-- ##### FUNCTION gtk_container_set_focus_vadjustment ##### -->
344 <!-- ##### FUNCTION gtk_container_get_focus_hadjustment ##### -->
353 <!-- ##### FUNCTION gtk_container_set_focus_hadjustment ##### -->
362 <!-- ##### FUNCTION gtk_container_resize_children ##### -->
370 <!-- ##### FUNCTION gtk_container_child_type ##### -->
379 <!-- ##### FUNCTION gtk_container_child_get ##### -->
390 <!-- ##### FUNCTION gtk_container_child_set ##### -->
401 <!-- ##### FUNCTION gtk_container_child_get_property ##### -->
412 <!-- ##### FUNCTION gtk_container_child_set_property ##### -->
423 <!-- ##### FUNCTION gtk_container_child_get_valist ##### -->
430 @first_property_name:
434 <!-- ##### FUNCTION gtk_container_child_set_valist ##### -->
441 @first_property_name:
445 <!-- ##### FUNCTION gtk_container_forall ##### -->
455 <!-- ##### FUNCTION gtk_container_get_border_width ##### -->
464 <!-- ##### FUNCTION gtk_container_set_border_width ##### -->
473 <!-- ##### FUNCTION gtk_container_propagate_expose ##### -->
483 <!-- ##### FUNCTION gtk_container_get_focus_chain ##### -->
493 <!-- ##### FUNCTION gtk_container_set_focus_chain ##### -->
502 <!-- ##### FUNCTION gtk_container_unset_focus_chain ##### -->
510 <!-- ##### FUNCTION gtk_container_class_find_child_property ##### -->
520 <!-- ##### FUNCTION gtk_container_class_install_child_property ##### -->
530 <!-- ##### FUNCTION gtk_container_class_list_child_properties ##### -->