style: Convert border-width to a shorthand

Add the corresponding properties it refers to, too:
- border-top-width
- border-left-width
- border-bottom-width
- border-right-width
This commit is contained in:
Benjamin Otte 2011-05-22 00:10:43 +02:00
parent 42a4bd1c5b
commit f5c7cefcca
4 changed files with 143 additions and 18 deletions

View File

@ -690,10 +690,37 @@
* </entry> * </entry>
* </row> * </row>
* <row> * <row>
* <entry>border-width</entry> * <entry>border-top-width</entry>
* <entry>integer</entry> * <entry>integer</entry>
* <entry>#gint</entry> * <entry>#gint</entry>
* <entry>border-width: 5;</entry> * <entry>border-top-width: 5;</entry>
* </row>
* <row>
* <entry>border-left-width</entry>
* <entry>integer</entry>
* <entry>#gint</entry>
* <entry>border-left-width: 5;</entry>
* </row>
* <row>
* <entry>border-bottom-width</entry>
* <entry>integer</entry>
* <entry>#gint</entry>
* <entry>border-bottom-width: 5;</entry>
* </row>
* <row>
* <entry>border-right-width</entry>
* <entry>integer</entry>
* <entry>#gint</entry>
* <entry>border-right-width: 5;</entry>
* </row>
* <row>
* <entry>border-width</entry>
* <entry morerows="1">#GtkBorder</entry>
* <entry morerows="1"><literallayout>border-width: 1;
* border-width: 1 2;
* border-width: 1 2 3;
* border-width: 1 2 3 5;</literallayout>
* </entry>
* </row> * </row>
* <row> * <row>
* <entry>border-radius</entry> * <entry>border-radius</entry>

View File

@ -3474,28 +3474,27 @@ gtk_style_context_get_border (GtkStyleContext *context,
{ {
GtkStyleContextPrivate *priv; GtkStyleContextPrivate *priv;
StyleData *data; StyleData *data;
const GValue *value; int top, left, bottom, right;
GtkBorder *b;
g_return_if_fail (border != NULL); g_return_if_fail (border != NULL);
*border = fallback_border;
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context)); g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
priv = context->priv; priv = context->priv;
g_return_if_fail (priv->widget_path != NULL); g_return_if_fail (priv->widget_path != NULL);
data = style_data_lookup (context); data = style_data_lookup (context);
value = _gtk_style_properties_peek_property (data->store, gtk_style_properties_get (data->store,
"border-width", state,
state, "border-top-width", &top,
NULL); "border-left-width", &left,
"border-bottom-width", &bottom,
"border-right-width", &right,
NULL);
if (value) border->top = top;
{ border->left = left;
b = g_value_get_boxed (value); border->bottom = bottom;
*border = *b; border->right = right;
}
} }
/** /**

View File

@ -1160,6 +1160,83 @@ bindings_value_to_string (const GValue *value)
return g_string_free (str, FALSE); return g_string_free (str, FALSE);
} }
/*** PACKING ***/
static GParameter *
unpack_border (const GValue *value,
guint *n_params,
const char *top,
const char *left,
const char *bottom,
const char *right)
{
GParameter *parameter = g_new0 (GParameter, 4);
GtkBorder *border = g_value_get_boxed (value);
parameter[0].name = top;
g_value_init (&parameter[0].value, G_TYPE_INT);
g_value_set_int (&parameter[0].value, border->top);
parameter[1].name = left;
g_value_init (&parameter[1].value, G_TYPE_INT);
g_value_set_int (&parameter[1].value, border->left);
parameter[2].name = bottom;
g_value_init (&parameter[2].value, G_TYPE_INT);
g_value_set_int (&parameter[2].value, border->bottom);
parameter[3].name = right;
g_value_init (&parameter[3].value, G_TYPE_INT);
g_value_set_int (&parameter[3].value, border->right);
*n_params = 4;
return parameter;
}
static void
pack_border (GValue *value,
GtkStyleProperties *props,
GtkStateFlags state,
const char *top,
const char *left,
const char *bottom,
const char *right)
{
GtkBorder border;
int t, l, b, r;
gtk_style_properties_get (props,
state,
top, &t,
left, &l,
bottom, &b,
right, &r,
NULL);
border.top = t;
border.left = l;
border.bottom = b;
border.right = r;
g_value_set_boxed (value, &border);
}
static GParameter *
unpack_border_width (const GValue *value,
guint *n_params)
{
return unpack_border (value, n_params,
"border-top-width", "border-left-width",
"border-bottom-width", "border-right-width");
}
static void
pack_border_width (GValue *value,
GtkStyleProperties *props,
GtkStateFlags state)
{
pack_border (value, props, state,
"border-top-width", "border-left-width",
"border-bottom-width", "border-right-width");
}
/*** API ***/ /*** API ***/
static void static void
@ -1368,10 +1445,32 @@ gtk_style_property_init (void)
"Padding", "Padding",
GTK_TYPE_BORDER, 0)); GTK_TYPE_BORDER, 0));
gtk_style_properties_register_property (NULL, gtk_style_properties_register_property (NULL,
g_param_spec_boxed ("border-width", g_param_spec_int ("border-top-width",
"border top width",
"Border width at top",
0, G_MAXINT, 0, 0));
gtk_style_properties_register_property (NULL,
g_param_spec_int ("border-left-width",
"border left width",
"Border width at left",
0, G_MAXINT, 0, 0));
gtk_style_properties_register_property (NULL,
g_param_spec_int ("border-bottom-width",
"border bottom width",
"Border width at bottom",
0, G_MAXINT, 0, 0));
gtk_style_properties_register_property (NULL,
g_param_spec_int ("border-right-width",
"border right width",
"Border width at right",
0, G_MAXINT, 0, 0));
_gtk_style_property_register (g_param_spec_boxed ("border-width",
"Border width", "Border width",
"Border width, in pixels", "Border width, in pixels",
GTK_TYPE_BORDER, 0)); GTK_TYPE_BORDER, 0),
NULL,
unpack_border_width,
pack_border_width);
gtk_style_properties_register_property (NULL, gtk_style_properties_register_property (NULL,
g_param_spec_int ("border-radius", g_param_spec_int ("border-radius",
"Border radius", "Border radius",

View File

@ -30,7 +30,7 @@ typedef GParameter * (* GtkStyleUnpackFunc) (const GValue
guint *n_params); guint *n_params);
typedef void (* GtkStylePackFunc) (GValue *value, typedef void (* GtkStylePackFunc) (GValue *value,
GtkStyleProperties *props, GtkStyleProperties *props,
GtkStateFlags flags); GtkStateFlags state);
struct _GtkStyleProperty struct _GtkStyleProperty
{ {