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.
This commit is contained in:
Matthias Clasen 2010-08-09 23:08:39 -04:00
parent 7844d3b8db
commit 79ef5de505
4 changed files with 96 additions and 13 deletions

View File

@ -1154,6 +1154,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
<SUBSECTION Standard>
GTK_TYPE_EXPANDER
GTK_EXPANDER_CLASS

View File

@ -1206,6 +1206,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
@ -1215,6 +1216,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

View File

@ -48,7 +48,8 @@ enum
PROP_USE_UNDERLINE,
PROP_USE_MARKUP,
PROP_SPACING,
PROP_LABEL_WIDGET
PROP_LABEL_WIDGET,
PROP_LABEL_FILL
};
struct _GtkExpanderPrivate
@ -66,6 +67,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,
@ -247,6 +249,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"),
@ -299,6 +309,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);
@ -353,6 +364,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;
@ -390,6 +404,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;
@ -578,8 +595,8 @@ gtk_expander_size_allocate (GtkWidget *widget,
/* Calculate some offsets/padding first */
label_xoffset = border_width + expander_size + focus_width + 2 * expander_spacing + focus_pad;
label_xpad = 2 * border_width + expander_size + 2 * focus_width + 2 * expander_spacing + 2 * focus_pad;
label_xoffset = border_width + expander_size + focus_width + 2 * expander_spacing + focus_pad;
label_xpad = 2 * border_width + expander_size + 2 * focus_width + 2 * expander_spacing + 2 * focus_pad;
child_yoffset = border_width + priv->spacing + (interior_focus ? 0 : 2 * focus_width + 2 * focus_pad);
child_ypad = 2 * border_width + priv->spacing + (interior_focus ? 0 : 2 * focus_width + 2 * focus_pad);
@ -595,7 +612,10 @@ gtk_expander_size_allocate (GtkWidget *widget,
gtk_size_request_get_width (GTK_SIZE_REQUEST (priv->label_widget), NULL, &natural_label_width);
label_allocation.width = MIN (natural_label_width, allocation->width - label_xpad);
if (priv->label_fill)
label_allocation.width = allocation->width - label_xpad;
else
label_allocation.width = MIN (natural_label_width, allocation->width - label_xpad);
label_allocation.width = MAX (label_allocation.width, 1);
/* We distribute the minimum height to the label widget and prioritize
@ -605,13 +625,14 @@ gtk_expander_size_allocate (GtkWidget *widget,
ltr = gtk_widget_get_direction (widget) != GTK_TEXT_DIR_RTL;
if (ltr)
label_allocation.x =
widget->allocation.x + label_xoffset;
if (priv->label_fill)
label_allocation.x = widget->allocation.x + label_xoffset;
else if (ltr)
label_allocation.x = widget->allocation.x + label_xoffset;
else
label_allocation.x =
widget->allocation.x + widget->allocation.width -
(label_allocation.width + label_xoffset);
label_allocation.x =
widget->allocation.x + widget->allocation.width -
(label_allocation.width + label_xoffset);
label_allocation.y = widget->allocation.y + border_width + focus_width + focus_pad;
label_allocation.height = MIN (label_height,
@ -636,9 +657,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));
}
@ -1933,3 +1954,58 @@ gtk_expander_get_label_widget (GtkExpander *expander)
return expander->priv->label_widget;
}
/**
* 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;
}

View File

@ -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