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 64bcdb78e0
commit 70f65529a5
4 changed files with 99 additions and 9 deletions

View File

@ -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
<SUBSECTION Standard>
GTK_TYPE_EXPANDER
GTK_EXPANDER_CLASS

View File

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

View File

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

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