W Wrapl, The Programming Language

Libraries:Gtk:Gtk:Container

Types

T

Inherits from:

A GTK+ user interface is constructed by nesting widgets inside widgets. Container widgets are the inner nodes in the resulting tree of widgets: they contain other widgets. So, for example, you might have a Gtk.Gtk.Window.T containing a Gtk.Gtk.Frame.T containing a GtkLabel. If you wanted an image instead of a textual label inside the frame, you might replace the Gtk.Gtk.Label.T widget with a Gtk.Gtk.Image.T widget.

There are two major kinds of container widgets in GTK+. Both are subclasses of the abstract T base class.

The first type of container widget has a single child widget and derives from Gtk.Gtk.Bin.T. These containers are decorators, which add some kind of functionality to the child. For example, a Gtk.Gtk.Button.T makes its child into a clickable button; a Gtk.Gtk.Frame.T draws a frame around its child and a Gtk.Gtk.Window.T places its child widget inside a top-level window.

The second type of container can have more than one child; its purpose is to manage layout. This means that these containers assign sizes and positions to their children. For example, a Gtk.Gtk.HBox.T arranges its children in a horizontal row, and a Gtk.Gtk.Table.T arranges the widgets it contains in a two-dimensional grid.

To fulfill its task, a layout container must negotiate the size requirements with its parent and its children. This negotiation is carried out in two phases, size requisition and size allocation.

Size Requisition

The size requisition of a widget is it's desired width and height. This is represented by a Gtk.Gtk.Requisition.T.

How a widget determines its desired size depends on the widget. A Gtk.Gtk.Label.T, for example, requests enough space to display all its text. Container widgets generally base their size request on the requisitions of their children.

The size requisition phase of the widget layout process operates top-down. It starts at a top-level widget, typically a Gtk.Gtk.Window.T. The top-level widget asks its child for its size requisition by calling Gtk.Gtk.Widget.SizeRequest. To determine its requisition, the child asks its own children for their requisitions and so on. Finally, the top-level widget will get a requisition back from its child.


Size Allocation

When the top-level widget has determined how much space its child would like to have, the second phase of the size negotiation, size allocation, begins. Depending on its configuration (see Gtk.Gtk.Window.SetResizable), the top-level widget may be able to expand in order to satisfy the size request or it may have to ignore the size request and keep its fixed size. It then tells its child widget how much space it gets by calling Gtk.Gtk.Widget.SizeAllocate. The child widget divides the space among its children and tells each child how much space it got, and so on. Under normal circumstances, a Gtk.Gtk.Window.T will always give its child the amount of space the child requested.

A child's size allocation is represented by a GtkAllocation. This struct contains not only a width and height, but also a position (i.e. X and Y coordinates), so that containers can tell their children not only how much space they have gotten, but also where they are positioned inside the space available to the container.

Widgets are required to honor the size allocation they receive; a size request is only a request, and widgets must be able to cope with any size.


Child properties

GtkContainer introduces child properties - these are object properties that are not specific to either the container or the contained widget, but rather to their relation. Typical examples of child properties are the position or pack-type of a widget which is contained in a Gtk.Gtk.Box.T.

Use ClassInstallChildProperty to install child properties for a container class and ClassFindChildProperty or ClassListChildProperties to get information about existing child properties.

To set the value of a child property, use ChildSetProperty, ChildSet or ChildSetValist. To obtain the value of a child property, use ChildGetProperty, ChildGet or ChildGetValist. To emit notification about child property changes, use Gtk.Gtk.Widget.ChildNotify.


GtkContainer as GtkBuildable

The GtkContainer implementation of the GtkBuildable interface supports a <packing> element for children, which can contain multiple <property> elements that specify child properties for the child.

Example 55. Child properties in UI definitions

1
2
3
4
5
6
7
8
<object class="GtkVBox">
  <child>
    <object class="GtkLabel"/>
    <packing>
      <property name="pack-type">start</property>
    </packing>
  </child>
</object>


Since 2.16, child properties can also be marked as translatable using the same "translatable", "comments" and "context" attributes that are used for regular properties.



Constants

Nil : T

Functions

ClassFindChildProperty(cclass @ Std.Object.T, property_name @ Std.String.T) : Gtk.GObject.GParamSpec.T

Finds a child property of a container class by name.

cclass a GtkContainerClass. [type GtkContainerClass]
property_name the name of the child property to find
Returns the GParamSpec of the child property or NULL if class has no child property with that name. [transfer none]


ClassInstallChildProperty(cclass @ Std.Object.T, property_id @ Std.Integer.SmallT, pspec @ Gtk.GObject.GParamSpec.T) : Std.Object.T

Installs a child property on a container class.

cclass a GtkContainerClass
property_id the id for the property
pspec the GParamSpec for the property


ClassListChildProperties(cclass @ Std.Object.T, n_properties @ Std.Object.T) : Std.Object.T

Returns all child properties of a container class.

cclass a GtkContainerClass. [type GtkContainerClass]
n_properties location to return the number of child properties found
Returns a newly allocated NULL-terminated array of GParamSpec*. The array must be freed with g_free(). [array length=n_properties][transfer container]


GetType() : Gtk.GObject.Type.T



Methods

:Add(self @ T, widget @ Gtk.Gtk.Widget.T) : Std.Object.T

Adds widget to container. Typically used for simple containers such as Gtk.Gtk.Window.T, Gtk.Gtk.Frame.T, or Gtk.Gtk.Button.T; for more complicated layout containers such as Gtk.Gtk.Box.T or Gtk.Gtk.Table.T, this function will pick default packing parameters that may not be correct. So consider functions such as Gtk.Gtk.Box.PackStart and Gtk.Gtk.Table.Attach as an alternative to Add in those cases. A widget may be added to only one container at a time; you can't place the same widget inside two different containers.

container a T
widget a widget to be placed inside container


:AddWithProperties(self @ T, widget @ Gtk.Gtk.Widget.T, first_prop_name @ Std.String.T, ... @ Std.Object.T) : Std.Object.T

Adds widget to container, setting child properties at the same time. See Add and ChildSet for more details.

container a T
widget a widget to be placed inside container
first_prop_name the name of the first child property to set


:CheckResize(self @ T) : Std.Object.T



:ChildGet(self @ T, child @ Gtk.Gtk.Widget.T, first_prop_name @ Std.String.T, ... @ Std.Object.T) : Std.Object.T

Gets the values of one or more child properties for child and container.

container a T
child a widget which is a child of container
first_prop_name the name of the first property to get


:ChildGetProperty(self @ T, child @ Gtk.Gtk.Widget.T, property_name @ Std.String.T, value @ Gtk.GObject.Value.T) : Std.Object.T

Gets the value of a child property for child and container.

container a T
child a widget which is a child of container
property_name the name of the property to get
value a location to return the value


:ChildGetValist(self @ T, child @ Gtk.Gtk.Widget.T, first_property_name @ Std.String.T, var_args @ Agg.List.T) : Std.Object.T

Gets the values of one or more child properties for child and container.

container a T
child a widget which is a child of container
first_property_name the name of the first property to get
var_args return location for the first property, followed optionally by more name/return location pairs, followed by NULL


:ChildSet(self @ T, child @ Gtk.Gtk.Widget.T, first_prop_name @ Std.String.T, ... @ Std.Object.T) : Std.Object.T

Sets one or more child properties for child and container.

container a T
child a widget which is a child of container
first_prop_name the name of the first property to set


:ChildSetProperty(self @ T, child @ Gtk.Gtk.Widget.T, property_name @ Std.String.T, value @ Gtk.GObject.Value.T) : Std.Object.T

Sets a child property for child and container.

container a T
child a widget which is a child of container
property_name the name of the property to set
value the value to set the property to


:ChildSetValist(self @ T, child @ Gtk.Gtk.Widget.T, first_property_name @ Std.String.T, var_args @ Agg.List.T) : Std.Object.T

Sets one or more child properties for child and container.

container a T
child a widget which is a child of container
first_property_name the name of the first property to set
var_args a NULL-terminated list of property names and values, starting with first_prop_name


:ChildType(self @ T) : Gtk.GObject.Type.T

Returns the type of the children supported by the container.

Note that this may return G_TYPE_NONE to indicate that no more children can be added, e.g. for a Gtk.Gtk.Paned.T which already has two children.

container a T
Returns a GType.


:Forall(self @ T, callback @ Std.Function.T, callback_data @ Std.Address.T) : Std.Object.T

Invokes callback on each child of container, including children that are considered "internal" (implementation details of the container). "Internal" children generally weren't added by the user of the container, but were added by the container implementation itself. Most applications should use Foreach, rather than Forall.

container a T
callback a callback
callback_data callback user data


:Foreach(self @ T, callback @ Std.Function.T, callback_data @ Std.Address.T) : Std.Object.T

Invokes callback on each non-internal child of container. See Forall for details on what constitutes an "internal" child. Most applications should use Foreach, rather than Forall.

container a T
callback a callback. [scope call]
callback_data callback user data


:ForeachFull(self @ T, callback @ Std.Function.T, marshal @ Std.Function.T, callback_data @ Std.Address.T, notify @ Std.Function.T) : Std.Object.T

Warning

ForeachFull is deprecated and should not be used in newly-written code. Use Foreach instead.



:GetBorderWidth(self @ T) : Std.Integer.SmallT

Retrieves the border width of the container. See SetBorderWidth.

container a T
Returns the current border width


:GetChildren(self @ T) : Std.Object.T

Returns the container's non-internal children. See Forall for details on what constitutes an "internal" child.

container a T
Returns a newly-allocated list of the container's non-internal children. [element-type GtkWidget][transfer container]


:GetFocusChain(self @ T, focusable_widgets @ Std.Object.T) : Std.Symbol.T

Retrieves the focus chain of the container, if one has been set explicitly. If no focus chain has been explicitly set, GTK+ computes the focus chain based on the positions of the children. In that case, GTK+ stores NULL in focusable_widgets and returns FALSE.

container a T
focusable_widgets location to store the focus chain of the container, or NULL. You should free this list using g_list_free() when you are done with it, however no additional reference count is added to the individual widgets in the focus chain. [element-type GtkWidget][out][transfer container]
Returns TRUE if the focus chain of the container has been set explicitly.


:GetFocusChild(self @ T) : Gtk.Gtk.Widget.T

Returns the current focus child widget inside container. This is not the currently focused widget. That can be obtained by calling Gtk.Gtk.Window.GetFocus.

container a T
Returns The child widget which will receive the focus inside container when the conatiner is focussed, or NULL if none is set. [transfer none]


:GetFocusHadjustment(self @ T) : Gtk.Gtk.Adjustment.T

Retrieves the horizontal focus adjustment for the container. See SetFocusHadjustment.

container a T
Returns the horizontal focus adjustment, or NULL if none has been set. [transfer none]


:GetFocusVadjustment(self @ T) : Gtk.Gtk.Adjustment.T

Retrieves the vertical focus adjustment for the container. See SetFocusVadjustment.

container a T
Returns the vertical focus adjustment, or NULL if none has been set. [transfer none]


:GetResizeMode(self @ T) : Gtk.Gtk.ResizeMode.T

Returns the resize mode for the container. See SetResizeMode.

container a T
Returns the current resize mode


:PropagateExpose(self @ T, child @ Gtk.Gtk.Widget.T, event @ Gtk.Gdk.EventExpose.T) : Std.Object.T

When a container receives an expose event, it must send synthetic expose events to all children that don't have their own GdkWindows. This function provides a convenient way of doing this. A container, when it receives an expose event, calls PropagateExpose once for each child, passing in the event the container received.

PropagateExpose takes care of deciding whether an expose event needs to be sent to the child, intersecting the event's area with the child area, and sending the event.

In most cases, a container can simply either simply inherit the "expose" implementation from T, or, do some drawing and then chain to the ::expose implementation from T.

Note that the ::expose-event signal has been replaced by a ::draw signal in GTK+ 3, and consequently, PropagateExpose has been replaced by gtk_container_propagate_draw(). The GTK+ 3 migration guide for hints on how to port from ::expose-event to ::draw.

container a T
child a child of container
event a expose event sent to container


:Remove(self @ T, widget @ Gtk.Gtk.Widget.T) : Std.Object.T

Removes widget from container. widget must be inside container. Note that container will own a reference to widget, and that this may be the last reference held; so removing a widget from its container can destroy that widget. If you want to use widget again, you need to add a reference to it while it's not inside a container, using g_object_ref(). If you don't want to use widget again it's usually more efficient to simply destroy it directly using Gtk.Gtk.Widget.Destroy since this will remove it from the container and help break any circular reference count cycles.

container a T
widget a current child of container


:ResizeChildren(self @ T) : Std.Object.T



:SetBorderWidth(self @ T, border_width @ Std.Integer.SmallT) : Std.Object.T

Sets the border width of the container.

The border width of a container is the amount of space to leave around the outside of the container. The only exception to this is Gtk.Gtk.Window.T; because toplevel windows can't leave space outside, they leave the space inside. The border is added on all sides of the container. To add space to only one side, one approach is to create a Gtk.Gtk.Alignment.T widget, call Gtk.Gtk.Widget.SetSizeRequest to give it a size, and place it on the side of the container as a spacer.

container a T
border_width amount of blank space to leave outside the container. Valid values are in the range 0-65535 pixels.


:SetFocusChain(self @ T, focusable_widgets @ Std.Object.T) : Std.Object.T

Sets a focus chain, overriding the one computed automatically by GTK+.

In principle each widget in the chain should be a descendant of the container, but this is not enforced by this method, since it's allowed to set the focus chain before you pack the widgets, or have a widget in the chain that isn't always packed. The necessary checks are done when the focus chain is actually traversed.

container a T
focusable_widgets the new focus chain. [transfer none][element-type GtkWidget]


:SetFocusChild(self @ T, child @ Gtk.Gtk.Widget.T) : Std.Object.T

Sets, or unsets if child is NULL, the focused child of container.

This function emits the GtkContainer::set_focus_child signal of container. Implementations of T can override the default behaviour by overriding the class closure of this signal.

This is function is mostly meant to be used by widgets. Applications can use Gtk.Gtk.Widget.GrabFocus to manualy set the focus to a specific widget.

container a T
child a Gtk.Gtk.Widget.T, or NULL. [allow-none]


:SetFocusHadjustment(self @ T, adjustment @ Gtk.Gtk.Adjustment.T) : Std.Object.T

Hooks up an adjustment to focus handling in a container, so when a child of the container is focused, the adjustment is scrolled to show that widget. This function sets the horizontal alignment. See Gtk.Gtk.ScrolledWindow.GetHadjustment for a typical way of obtaining the adjustment and SetFocusVadjustment for setting the vertical adjustment.

The adjustments have to be in pixel units and in the same coordinate system as the allocation for immediate children of the container.

container a T
adjustment an adjustment which should be adjusted when the focus is moved among the descendents of container


:SetFocusVadjustment(self @ T, adjustment @ Gtk.Gtk.Adjustment.T) : Std.Object.T

Hooks up an adjustment to focus handling in a container, so when a child of the container is focused, the adjustment is scrolled to show that widget. This function sets the vertical alignment. See Gtk.Gtk.ScrolledWindow.GetVadjustment for a typical way of obtaining the adjustment and SetFocusHadjustment for setting the horizontal adjustment.

The adjustments have to be in pixel units and in the same coordinate system as the allocation for immediate children of the container.

container a T
adjustment an adjustment which should be adjusted when the focus is moved among the descendents of container


:SetReallocateRedraws(self @ T, needs_redraws @ Std.Symbol.T) : Std.Object.T

Sets the reallocate_redraws flag of the container to the given value.

Containers requesting reallocation redraws get automatically redrawn if any of their children changed allocation.

container a T
needs_redraws the new value for the container's reallocate_redraws flag


:SetResizeMode(self @ T, resize_mode @ Gtk.Gtk.ResizeMode.T) : Std.Object.T

Sets the resize mode for the container.

The resize mode of a container determines whether a resize request will be passed to the container's parent, queued for later execution or executed immediately.

container a T
resize_mode the new resize mode


:UnsetFocusChain(self @ T) : Std.Object.T

Removes a focus chain explicitly set with SetFocusChain.

container a T