From 70f65529a58458ee889b85e3a19331a96340c53f Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 9 Aug 2010 23:08:39 -0400 Subject: [PATCH] Make it possible to make the expander label fill the entire space This adds a boolean GtkExpander::label-fill property and uses it when allocating space to the label. Based on a patch by Matt Barnes, bug 614049. --- docs/reference/gtk/gtk-sections.txt | 2 + gtk/gtk.symbols | 2 + gtk/gtkexpander.c | 101 +++++++++++++++++++++++++--- gtk/gtkexpander.h | 3 + 4 files changed, 99 insertions(+), 9 deletions(-) diff --git a/docs/reference/gtk/gtk-sections.txt b/docs/reference/gtk/gtk-sections.txt index 536b6bf91..d06abeea9 100644 --- a/docs/reference/gtk/gtk-sections.txt +++ b/docs/reference/gtk/gtk-sections.txt @@ -1462,6 +1462,8 @@ gtk_expander_set_use_markup gtk_expander_get_use_markup gtk_expander_set_label_widget gtk_expander_get_label_widget +gtk_expander_set_label_fill +gtk_expander_get_label_fill GTK_TYPE_EXPANDER GTK_EXPANDER_CLASS diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols index c73a97574..f3d255715 100644 --- a/gtk/gtk.symbols +++ b/gtk/gtk.symbols @@ -1493,6 +1493,7 @@ gtk_event_box_set_visible_window #if IN_FILE(__GTK_EXPANDER_C__) gtk_expander_get_expanded gtk_expander_get_label +gtk_expander_get_label_fill gtk_expander_get_label_widget gtk_expander_get_spacing gtk_expander_get_type G_GNUC_CONST @@ -1502,6 +1503,7 @@ gtk_expander_new gtk_expander_new_with_mnemonic gtk_expander_set_expanded gtk_expander_set_label +gtk_expander_set_label_fill gtk_expander_set_label_widget gtk_expander_set_spacing gtk_expander_set_use_markup diff --git a/gtk/gtkexpander.c b/gtk/gtkexpander.c index b7a61f735..efd6b5da9 100644 --- a/gtk/gtkexpander.c +++ b/gtk/gtkexpander.c @@ -49,7 +49,8 @@ enum PROP_USE_UNDERLINE, PROP_USE_MARKUP, PROP_SPACING, - PROP_LABEL_WIDGET + PROP_LABEL_WIDGET, + PROP_LABEL_FILL }; struct _GtkExpanderPrivate @@ -67,6 +68,7 @@ struct _GtkExpanderPrivate guint use_markup : 1; guint button_down : 1; guint prelight : 1; + guint label_fill : 1; }; static void gtk_expander_set_property (GObject *object, @@ -231,6 +233,14 @@ gtk_expander_class_init (GtkExpanderClass *klass) GTK_TYPE_WIDGET, GTK_PARAM_READWRITE)); + g_object_class_install_property (gobject_class, + PROP_LABEL_FILL, + g_param_spec_boolean ("label-fill", + P_("Label fill"), + P_("Whether the label widget should fill all available horizontal space"), + FALSE, + GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT)); + gtk_widget_class_install_style_property (widget_class, g_param_spec_int ("expander-size", P_("Expander Size"), @@ -281,6 +291,7 @@ gtk_expander_init (GtkExpander *expander) priv->use_markup = FALSE; priv->button_down = FALSE; priv->prelight = FALSE; + priv->label_fill = FALSE; priv->expand_timer = 0; gtk_drag_dest_set (GTK_WIDGET (expander), 0, NULL, 0, 0); @@ -335,6 +346,9 @@ gtk_expander_set_property (GObject *object, case PROP_LABEL_WIDGET: gtk_expander_set_label_widget (expander, g_value_get_object (value)); break; + case PROP_LABEL_FILL: + gtk_expander_set_label_fill (expander, g_value_get_boolean (value)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -372,6 +386,9 @@ gtk_expander_get_property (GObject *object, priv->label_widget ? G_OBJECT (priv->label_widget) : NULL); break; + case PROP_LABEL_FILL: + g_value_set_boolean (value, priv->label_fill); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -636,7 +653,11 @@ gtk_expander_size_allocate (GtkWidget *widget, ltr = gtk_widget_get_direction (widget) != GTK_TEXT_DIR_RTL; - if (ltr) + if (priv->label_fill) + label_allocation.x = (widget->allocation.x + + border_width + focus_width + focus_pad + + expander_size + 2 * expander_spacing); + else if (ltr) label_allocation.x = (widget->allocation.x + border_width + focus_width + focus_pad + expander_size + 2 * expander_spacing); @@ -648,10 +669,15 @@ gtk_expander_size_allocate (GtkWidget *widget, label_allocation.y = widget->allocation.y + border_width + focus_width + focus_pad; - label_allocation.width = MIN (label_requisition.width, - allocation->width - 2 * border_width - - expander_size - 2 * expander_spacing - - 2 * focus_width - 2 * focus_pad); + if (priv->fill_label) + label_allocation.width = allocation->width - 2 * border_width - + expander_size - 2 * expander_spacing - + 2 * focus_width - 2 * focus_pad; + else + label_allocation.width = MIN (label_requisition.width, + allocation->width - 2 * border_width - + expander_size - 2 * expander_spacing - + 2 * focus_width - 2 * focus_pad); label_allocation.width = MAX (label_allocation.width, 1); label_allocation.height = MIN (label_requisition.height, @@ -676,9 +702,9 @@ gtk_expander_size_allocate (GtkWidget *widget, get_expander_bounds (expander, &rect); gdk_window_move_resize (priv->event_window, - allocation->x + border_width, - allocation->y + border_width, - MAX (allocation->width - 2 * border_width, 1), + allocation->x + border_width, + allocation->y + border_width, + MAX (allocation->width - 2 * border_width, 1), MAX (rect.height, label_height - 2 * border_width)); } @@ -1744,5 +1770,62 @@ gtk_expander_get_label_widget (GtkExpander *expander) return expander->priv->label_widget; } +<<<<<<< HEAD #define __GTK_EXPANDER_C__ #include "gtkaliasdef.c" +======= +/** + * gtk_expander_set_label_fill: + * @expander: a #GtkExpander + * @label_fill: %TRUE if the label should should fill all available horizontal + * space + * + * Sets whether the label widget should fill all available horizontal space + * allocated to @expander. + * + * Since: 2.22 + */ +void +gtk_expander_set_label_fill (GtkExpander *expander, + gboolean label_fill) +{ + GtkExpanderPrivate *priv; + + g_return_if_fail (GTK_IS_EXPANDER (expander)); + + priv = expander->priv; + + label_fill = label_fill != FALSE; + + if (priv->label_fill != label_fill) + { + priv->label_fill = label_fill; + + if (priv->label_widget != NULL) + gtk_widget_queue_resize (GTK_WIDGET (expander)); + + g_object_notify (G_OBJECT (expander), "label-fill"); + } +} + +/** + * gtk_expander_get_label_fill: + * @expander: a #GtkExpander + * + * Returns whether the label widget will fill all available horizontal + * space allocated to @expander. + * + * Return value: %TRUE if the label widget will fill all available horizontal + * space + * + * Since: 2.22 + */ +gboolean +gtk_expander_get_label_fill (GtkExpander *expander) +{ + g_return_val_if_fail (GTK_IS_EXPANDER (expander), FALSE); + + return expander->priv->label_fill; +} + +>>>>>>> 79ef5de... Make it possible to make the expander label fill the entire space diff --git a/gtk/gtkexpander.h b/gtk/gtkexpander.h index dc07a6ce7..6ed1e1a03 100644 --- a/gtk/gtkexpander.h +++ b/gtk/gtkexpander.h @@ -89,6 +89,9 @@ gboolean gtk_expander_get_use_markup (GtkExpander *expander); void gtk_expander_set_label_widget (GtkExpander *expander, GtkWidget *label_widget); GtkWidget *gtk_expander_get_label_widget (GtkExpander *expander); +void gtk_expander_set_label_fill (GtkExpander *expander, + gboolean label_fill); +gboolean gtk_expander_get_label_fill (GtkExpander *expander); G_END_DECLS