Commit 031856eb authored by Havoc Pennington's avatar Havoc Pennington Committed by Matthias Clasen

Add horizontal and vertical expand flags, compute_expand() to GtkWidget

GtkWidget now has flags for horizontal and vertical expand, and
a compute_expand() method. compute_expand() is used by containers
to set a default expand flag. (If a widget has expand set explicitly,
it always overrides the results of compute_expand.)

GtkContainer has a default implementation of compute_expand which
simply walks over all child widgets and sets expand=TRUE
if any child is expanding.

The overall effect is that you only have to set expand on
leaf nodes in the widget tree, while previously you had to
set expand all the way up the tree as you packed every
container. Also, now containers need not have their own child
properties for expand.

For old containers which do have "expand" child properties,
they should override compute_expand and include the child
properties in whether the container is expand=TRUE.
Also, the old container should use
"child_prop_expand || gtk_widget_compute_expand()" everywhere
it previously used simply "child_prop_expand"
parent 7d5a85c3
......@@ -302,6 +302,9 @@ static void gtk_container_add_unimplemented (GtkContainer *container
static void gtk_container_remove_unimplemented (GtkContainer *container,
GtkWidget *widget);
static void gtk_container_real_check_resize (GtkContainer *container);
static void gtk_container_compute_expand (GtkWidget *widget,
gboolean *hexpand_p,
gboolean *vexpand_p);
static gboolean gtk_container_focus (GtkWidget *widget,
GtkDirectionType direction);
static void gtk_container_real_set_focus_child (GtkContainer *container,
......@@ -443,6 +446,7 @@ gtk_container_class_init (GtkContainerClass *class)
gobject_class->get_property = gtk_container_get_property;
widget_class->destroy = gtk_container_destroy;
widget_class->compute_expand = gtk_container_compute_expand;
widget_class->show_all = gtk_container_show_all;
widget_class->hide_all = gtk_container_hide_all;
widget_class->draw = gtk_container_draw;
......@@ -2069,6 +2073,53 @@ _gtk_container_child_composite_name (GtkContainer *container,
return NULL;
typedef struct {
gboolean hexpand;
gboolean vexpand;
} ComputeExpandData;
static void
gtk_container_compute_expand_callback (GtkWidget *widget,
gpointer client_data)
ComputeExpandData *data = client_data;
/* note that we don't get_expand on the child if we already know we
* have to expand, so we only recurse into children until we find
* one that expands and then we basically don't do any more
* work. This means that we can leave some children in a
* need_compute_expand state, which is fine, as long as GtkWidget
* doesn't rely on an invariant that "if a child has
* need_compute_expand, its parents also do"
* gtk_widget_compute_expand() always returns FALSE if the
* child is !visible so that's taken care of.
data->hexpand = data->hexpand ||
gtk_widget_compute_expand (widget, GTK_ORIENTATION_HORIZONTAL);
data->vexpand = data->vexpand ||
gtk_widget_compute_expand (widget, GTK_ORIENTATION_VERTICAL);
static void
gtk_container_compute_expand (GtkWidget *widget,
gboolean *hexpand_p,
gboolean *vexpand_p)
ComputeExpandData data;
data.hexpand = FALSE;
data.vexpand = FALSE;
gtk_container_forall (GTK_CONTAINER (widget),
*hexpand_p = data.hexpand;
*vexpand_p = data.vexpand;
static void
gtk_container_real_set_focus_child (GtkContainer *container,
GtkWidget *child)
This diff is collapsed.
......@@ -366,6 +366,11 @@ struct _GtkWidgetClass
gboolean keyboard_tooltip,
GtkTooltip *tooltip);
/*< public >*/
void (* compute_expand) (GtkWidget *widget,
gboolean *hexpand_p,
gboolean *vexpand_p);
void (* adjust_size_request) (GtkWidget *widget,
GtkOrientation orientation,
gint for_size,
......@@ -642,6 +647,25 @@ GtkSettings* gtk_widget_get_settings (GtkWidget *widget);
GtkClipboard *gtk_widget_get_clipboard (GtkWidget *widget,
GdkAtom selection);
/* Expand flags and related support */
gboolean gtk_widget_get_hexpand (GtkWidget *widget);
void gtk_widget_set_hexpand (GtkWidget *widget,
gboolean expand);
gboolean gtk_widget_get_hexpand_set (GtkWidget *widget);
void gtk_widget_set_hexpand_set (GtkWidget *widget,
gboolean set);
gboolean gtk_widget_get_vexpand (GtkWidget *widget);
void gtk_widget_set_vexpand (GtkWidget *widget,
gboolean expand);
gboolean gtk_widget_get_vexpand_set (GtkWidget *widget);
void gtk_widget_set_vexpand_set (GtkWidget *widget,
gboolean set);
void gtk_widget_queue_compute_expand (GtkWidget *widget);
gboolean gtk_widget_compute_expand (GtkWidget *widget,
GtkOrientation orientation);
/* Multidevice support */
gboolean gtk_widget_get_support_multidevice (GtkWidget *widget);
void gtk_widget_set_support_multidevice (GtkWidget *widget,
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment