shorthand: Add a property for all subproperties

This commit is contained in:
Benjamin Otte
2011-12-31 16:31:25 +01:00
parent 4383701e25
commit 2128b356b2
3 changed files with 91 additions and 0 deletions

View File

@ -22,15 +22,80 @@
#include "gtkcssshorthandpropertyprivate.h" #include "gtkcssshorthandpropertyprivate.h"
#include "gtkintl.h"
enum {
PROP_0,
PROP_SUBPROPERTIES,
};
G_DEFINE_TYPE (GtkCssShorthandProperty, _gtk_css_shorthand_property, GTK_TYPE_STYLE_PROPERTY) G_DEFINE_TYPE (GtkCssShorthandProperty, _gtk_css_shorthand_property, GTK_TYPE_STYLE_PROPERTY)
static void
gtk_css_shorthand_property_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GtkCssShorthandProperty *property = GTK_CSS_SHORTHAND_PROPERTY (object);
const char **subproperties;
guint i;
switch (prop_id)
{
case PROP_SUBPROPERTIES:
subproperties = g_value_get_boxed (value);
g_assert (subproperties);
for (i = 0; subproperties[i] != NULL; i++)
{
GtkStyleProperty *subproperty = _gtk_style_property_lookup (subproperties[i]);
g_assert (GTK_IS_CSS_STYLE_PROPERTY (subproperty));
g_ptr_array_add (property->subproperties, subproperty);
}
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void static void
_gtk_css_shorthand_property_class_init (GtkCssShorthandPropertyClass *klass) _gtk_css_shorthand_property_class_init (GtkCssShorthandPropertyClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->set_property = gtk_css_shorthand_property_set_property;
g_object_class_install_property (object_class,
PROP_SUBPROPERTIES,
g_param_spec_boxed ("subproperties",
P_("Subproperties"),
P_("The list of subproperties"),
G_TYPE_STRV,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
} }
static void static void
_gtk_css_shorthand_property_init (GtkCssShorthandProperty *shorthand) _gtk_css_shorthand_property_init (GtkCssShorthandProperty *shorthand)
{ {
shorthand->subproperties = g_ptr_array_new_with_free_func (g_object_unref);
}
GtkCssStyleProperty *
_gtk_css_shorthand_property_get_subproperty (GtkCssShorthandProperty *shorthand,
guint property)
{
g_return_val_if_fail (GTK_IS_CSS_SHORTHAND_PROPERTY (shorthand), NULL);
g_return_val_if_fail (property < shorthand->subproperties->len, NULL);
return g_ptr_array_index (shorthand->subproperties, property);
}
guint
_gtk_css_shorthand_property_get_n_subproperties (GtkCssShorthandProperty *shorthand)
{
g_return_val_if_fail (GTK_IS_CSS_SHORTHAND_PROPERTY (shorthand), 0);
return shorthand->subproperties->len;
} }

View File

@ -767,6 +767,7 @@ unset_border_image (GtkStyleProperties *props,
static void static void
_gtk_css_shorthand_property_register (GParamSpec *pspec, _gtk_css_shorthand_property_register (GParamSpec *pspec,
const char **subproperties,
GtkStylePropertyFlags flags, GtkStylePropertyFlags flags,
GtkStylePropertyParser property_parse_func, GtkStylePropertyParser property_parse_func,
GtkStyleUnpackFunc unpack_func, GtkStyleUnpackFunc unpack_func,
@ -783,6 +784,7 @@ _gtk_css_shorthand_property_register (GParamSpec *pspec,
node = g_object_new (GTK_TYPE_CSS_SHORTHAND_PROPERTY, node = g_object_new (GTK_TYPE_CSS_SHORTHAND_PROPERTY,
"name", pspec->name, "name", pspec->name,
"subproperties", subproperties,
NULL); NULL);
node->flags = flags; node->flags = flags;
@ -798,10 +800,20 @@ _gtk_css_shorthand_property_register (GParamSpec *pspec,
void void
_gtk_css_shorthand_property_init_properties (void) _gtk_css_shorthand_property_init_properties (void)
{ {
const char *font_subproperties[] = { "font-family", "font-style", "font-variant", "font-weight", "font-size", NULL };
const char *margin_subproperties[] = { "margin-top", "margin-right", "margin-bottom", "margin-left", NULL };
const char *padding_subproperties[] = { "padding-top", "padding-right", "padding-bottom", "padding-left", NULL };
const char *border_width_subproperties[] = { "border-top-width", "border-right-width", "border-bottom-width", "border-left-width", NULL };
const char *border_radius_subproperties[] = { "border-top-left-radius", "border-top-right-radius",
"border-bottom-right-radius", "border-bottom-left-radius", NULL };
const char *border_color_subproperties[] = { "border-top-color", "border-right-color", "border-bottom-color", "border-left-color", NULL };
const char *border_image_subproperties[] = { "border-image-source", "border-image-slice", "border-image-width", "border-image-repeat", NULL };
_gtk_css_shorthand_property_register (g_param_spec_boxed ("font", _gtk_css_shorthand_property_register (g_param_spec_boxed ("font",
"Font Description", "Font Description",
"Font Description", "Font Description",
PANGO_TYPE_FONT_DESCRIPTION, 0), PANGO_TYPE_FONT_DESCRIPTION, 0),
font_subproperties,
GTK_STYLE_PROPERTY_INHERIT, GTK_STYLE_PROPERTY_INHERIT,
NULL, NULL,
unpack_font_description, unpack_font_description,
@ -814,6 +826,7 @@ _gtk_css_shorthand_property_init_properties (void)
"Margin", "Margin",
"Margin", "Margin",
GTK_TYPE_BORDER, 0), GTK_TYPE_BORDER, 0),
margin_subproperties,
0, 0,
NULL, NULL,
unpack_margin, unpack_margin,
@ -826,6 +839,7 @@ _gtk_css_shorthand_property_init_properties (void)
"Padding", "Padding",
"Padding", "Padding",
GTK_TYPE_BORDER, 0), GTK_TYPE_BORDER, 0),
padding_subproperties,
0, 0,
NULL, NULL,
unpack_padding, unpack_padding,
@ -838,6 +852,7 @@ _gtk_css_shorthand_property_init_properties (void)
"Border width", "Border width",
"Border width, in pixels", "Border width, in pixels",
GTK_TYPE_BORDER, 0), GTK_TYPE_BORDER, 0),
border_width_subproperties,
0, 0,
NULL, NULL,
unpack_border_width, unpack_border_width,
@ -850,6 +865,7 @@ _gtk_css_shorthand_property_init_properties (void)
"Border radius", "Border radius",
"Border radius, in pixels", "Border radius, in pixels",
0, G_MAXINT, 0, 0), 0, G_MAXINT, 0, 0),
border_radius_subproperties,
0, 0,
NULL, NULL,
unpack_border_radius, unpack_border_radius,
@ -862,6 +878,7 @@ _gtk_css_shorthand_property_init_properties (void)
"Border color", "Border color",
"Border color", "Border color",
GDK_TYPE_RGBA, 0), GDK_TYPE_RGBA, 0),
border_color_subproperties,
0, 0,
NULL, NULL,
unpack_border_color, unpack_border_color,
@ -874,6 +891,7 @@ _gtk_css_shorthand_property_init_properties (void)
"Border Image", "Border Image",
"Border Image", "Border Image",
GTK_TYPE_BORDER_IMAGE, 0), GTK_TYPE_BORDER_IMAGE, 0),
border_image_subproperties,
0, 0,
NULL, NULL,
_gtk_border_image_unpack, _gtk_border_image_unpack,

View File

@ -23,6 +23,8 @@
#include <glib-object.h> #include <glib-object.h>
#include "gtk/gtkcssparserprivate.h"
#include "gtk/gtkcssstylepropertyprivate.h"
#include "gtk/gtkstylepropertyprivate.h" #include "gtk/gtkstylepropertyprivate.h"
G_BEGIN_DECLS G_BEGIN_DECLS
@ -40,6 +42,8 @@ typedef struct _GtkCssShorthandPropertyClass GtkCssShorthandPropertyClass;
struct _GtkCssShorthandProperty struct _GtkCssShorthandProperty
{ {
GtkStyleProperty parent; GtkStyleProperty parent;
GPtrArray *subproperties;
}; };
struct _GtkCssShorthandPropertyClass struct _GtkCssShorthandPropertyClass
@ -51,6 +55,10 @@ void _gtk_css_shorthand_property_init_properties (void);
GType _gtk_css_shorthand_property_get_type (void) G_GNUC_CONST; GType _gtk_css_shorthand_property_get_type (void) G_GNUC_CONST;
GtkCssStyleProperty * _gtk_css_shorthand_property_get_subproperty (GtkCssShorthandProperty *shorthand,
guint property);
guint _gtk_css_shorthand_property_get_n_subproperties (GtkCssShorthandProperty *shorthand);
G_END_DECLS G_END_DECLS