[gtk+] shorthand: Add a property for all subproperties
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] shorthand: Add a property for all subproperties
- Date: Mon, 9 Jan 2012 17:46:18 +0000 (UTC)
commit 2128b356b2b2e9b14d1a33ef29bd435f1a52c153
Author: Benjamin Otte <otte redhat com>
Date: Sat Dec 31 16:31:25 2011 +0100
shorthand: Add a property for all subproperties
gtk/gtkcssshorthandproperty.c | 65 ++++++++++++++++++++++++++++++++++
gtk/gtkcssshorthandpropertyimpl.c | 18 +++++++++
gtk/gtkcssshorthandpropertyprivate.h | 8 ++++
3 files changed, 91 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkcssshorthandproperty.c b/gtk/gtkcssshorthandproperty.c
index 6c29a69..64c8633 100644
--- a/gtk/gtkcssshorthandproperty.c
+++ b/gtk/gtkcssshorthandproperty.c
@@ -22,15 +22,80 @@
#include "gtkcssshorthandpropertyprivate.h"
+#include "gtkintl.h"
+
+enum {
+ PROP_0,
+ PROP_SUBPROPERTIES,
+};
+
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
_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
_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;
}
diff --git a/gtk/gtkcssshorthandpropertyimpl.c b/gtk/gtkcssshorthandpropertyimpl.c
index 85da098..4f2a5cc 100644
--- a/gtk/gtkcssshorthandpropertyimpl.c
+++ b/gtk/gtkcssshorthandpropertyimpl.c
@@ -767,6 +767,7 @@ unset_border_image (GtkStyleProperties *props,
static void
_gtk_css_shorthand_property_register (GParamSpec *pspec,
+ const char **subproperties,
GtkStylePropertyFlags flags,
GtkStylePropertyParser property_parse_func,
GtkStyleUnpackFunc unpack_func,
@@ -783,6 +784,7 @@ _gtk_css_shorthand_property_register (GParamSpec *pspec,
node = g_object_new (GTK_TYPE_CSS_SHORTHAND_PROPERTY,
"name", pspec->name,
+ "subproperties", subproperties,
NULL);
node->flags = flags;
@@ -798,10 +800,20 @@ _gtk_css_shorthand_property_register (GParamSpec *pspec,
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",
"Font Description",
"Font Description",
PANGO_TYPE_FONT_DESCRIPTION, 0),
+ font_subproperties,
GTK_STYLE_PROPERTY_INHERIT,
NULL,
unpack_font_description,
@@ -814,6 +826,7 @@ _gtk_css_shorthand_property_init_properties (void)
"Margin",
"Margin",
GTK_TYPE_BORDER, 0),
+ margin_subproperties,
0,
NULL,
unpack_margin,
@@ -826,6 +839,7 @@ _gtk_css_shorthand_property_init_properties (void)
"Padding",
"Padding",
GTK_TYPE_BORDER, 0),
+ padding_subproperties,
0,
NULL,
unpack_padding,
@@ -838,6 +852,7 @@ _gtk_css_shorthand_property_init_properties (void)
"Border width",
"Border width, in pixels",
GTK_TYPE_BORDER, 0),
+ border_width_subproperties,
0,
NULL,
unpack_border_width,
@@ -850,6 +865,7 @@ _gtk_css_shorthand_property_init_properties (void)
"Border radius",
"Border radius, in pixels",
0, G_MAXINT, 0, 0),
+ border_radius_subproperties,
0,
NULL,
unpack_border_radius,
@@ -862,6 +878,7 @@ _gtk_css_shorthand_property_init_properties (void)
"Border color",
"Border color",
GDK_TYPE_RGBA, 0),
+ border_color_subproperties,
0,
NULL,
unpack_border_color,
@@ -874,6 +891,7 @@ _gtk_css_shorthand_property_init_properties (void)
"Border Image",
"Border Image",
GTK_TYPE_BORDER_IMAGE, 0),
+ border_image_subproperties,
0,
NULL,
_gtk_border_image_unpack,
diff --git a/gtk/gtkcssshorthandpropertyprivate.h b/gtk/gtkcssshorthandpropertyprivate.h
index 50eaa2b..c53bed7 100644
--- a/gtk/gtkcssshorthandpropertyprivate.h
+++ b/gtk/gtkcssshorthandpropertyprivate.h
@@ -23,6 +23,8 @@
#include <glib-object.h>
+#include "gtk/gtkcssparserprivate.h"
+#include "gtk/gtkcssstylepropertyprivate.h"
#include "gtk/gtkstylepropertyprivate.h"
G_BEGIN_DECLS
@@ -40,6 +42,8 @@ typedef struct _GtkCssShorthandPropertyClass GtkCssShorthandPropertyClass;
struct _GtkCssShorthandProperty
{
GtkStyleProperty parent;
+
+ GPtrArray *subproperties;
};
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;
+GtkCssStyleProperty * _gtk_css_shorthand_property_get_subproperty (GtkCssShorthandProperty *shorthand,
+ guint property);
+guint _gtk_css_shorthand_property_get_n_subproperties (GtkCssShorthandProperty *shorthand);
+
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]