typedef struct _GtkContainerClass GtkContainerClass;
struct _GtkContainerClass
{
GtkWidgetClass parent_class;
guint n_child_args;
void (* add) (GtkContainer *container,
GtkWidget *widget);
void (* remove) (GtkContainer *container,
GtkWidget *widget);
void (* check_resize) (GtkContainer *container);
void (* forall) (GtkContainer *container,
gboolean include_internals,
GtkCallback callback,
gpointer callbabck_data);
gint (* focus) (GtkContainer *container,
GtkDirectionType direction);
void (* set_focus_child) (GtkContainer *container,
GtkWidget *widget);
GtkType (*child_type) (GtkContainer *container);
void (*set_child_arg) (GtkContainer *container,
GtkWidget *child,
GtkArg *arg,
guint arg_id);
void (*get_child_arg) (GtkContainer *container,
GtkWidget *child,
GtkArg *arg,
guint arg_id);
gchar* (*composite_name) (GtkContainer *container,
GtkWidget *child);
/* Padding for future expansion */
GtkFunction pad1;
GtkFunction pad2;
};
|
Many of these class functions do not have corresponding
signals. add, remove, check_resize, focus, and set_focus_child methods are default
handlers for signals with the same name. The others are
just methods.
The check_resize method
recalculates layout if necessary; it is invoked by the
idle handler installed by
gtk_widget_queue_resize(). As the previous section
mentioned, subclasses should not have to concern
themselves with this process.
The focus and set_focus_child methods
handle moving focus around a
GtkWindow. Users can move the focus with the arrow
keys and the tab key. This results in emissions of the
"focus" signal, with the
direction argument
indicating which way the focus should move. The
possible directions are:
GTK_DIR_TAB_FORWARD,
GTK_DIR_TAB_BACKWARD,
GTK_DIR_UP,
GTK_DIR_DOWN,
GTK_DIR_LEFT, and
GTK_DIR_RIGHT.
GtkContainer provides a default implementation
based on the geometric location of child widgets; it
works fine for most standard layout containers, such as
GtkBox and GtkTable. It should also work for GtkBin subclasses. More
elaborate or unusual containers, such as the tree and
list widgets, or
GtkNotebook, override this method. The focus method should return
TRUE if an appropriate
child was found and the focus was moved (using gtk_widget_grab_focus()).
The set_focus_child
method is used by
gtk_widget_grab_focus() to set the focus child of
a container.
gtk_widget_grab_focus() can be invoked by the
focus method of a
container, or by a widget implementation (for example,
GtkEntry grabs the focus if
the user clicks on it). The default implementation
simply sets the
focus_child field of the container, and
increments the child's reference count.
composite_name returns
a special name for a child when it's a part of a
particular container. For example, the composite names
of the two GtkScrollbar
widgets in a
GtkScrolledWindow are "hscrollbar" and
"vscrollbar." These names allow themes to specify
widget attributes precisely. The default implementation
of this method should always work fine; it returns the
name set with
gtk_widget_set_composite_name().
n_child_args, set_child_arg, and get_child_arg are exactly
analagous to the
n_args, get_arg,
and set_arg fields of
GtkObjectClass. the section
called Using Object Arguments in Your Own GtkObject Subclass in the
chapter called The GTK+ Object and Type
System mentions this briefly. Child arguments
are used to get and set attributes of the
container-child unit, such as the packing parameters
for GtkBox or the attachment
parameters for GtkTable. In
contrast, normal object arguments set the
characteristics of a single object in isolation. Though
the implementation differs, child arguments work almost
exactly like the object arguments described in the chapter called The GTK+
Object and Type System. The only visible
difference is that the get and set functions take a
container and a widget as arguments, instead of a
single object.
The following section introduces the remaining
functions in GtkContainer by
describing their implementation in GtkBin.