]> Pileus Git - ~andy/gtk/blob - gtk/gtkcssshorthandproperty.c
64c8633d033466a4e9ab85947b4409f0d635aa3e
[~andy/gtk] / gtk / gtkcssshorthandproperty.c
1 /*
2  * Copyright © 2011 Red Hat Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  *
18  * Authors: Benjamin Otte <otte@gnome.org>
19  */
20
21 #include "config.h"
22
23 #include "gtkcssshorthandpropertyprivate.h"
24
25 #include "gtkintl.h"
26
27 enum {
28   PROP_0,
29   PROP_SUBPROPERTIES,
30 };
31
32 G_DEFINE_TYPE (GtkCssShorthandProperty, _gtk_css_shorthand_property, GTK_TYPE_STYLE_PROPERTY)
33
34 static void
35 gtk_css_shorthand_property_set_property (GObject      *object,
36                                          guint         prop_id,
37                                          const GValue *value,
38                                          GParamSpec   *pspec)
39 {
40   GtkCssShorthandProperty *property = GTK_CSS_SHORTHAND_PROPERTY (object);
41   const char **subproperties;
42   guint i;
43
44   switch (prop_id)
45     {
46     case PROP_SUBPROPERTIES:
47       subproperties = g_value_get_boxed (value);
48       g_assert (subproperties);
49       for (i = 0; subproperties[i] != NULL; i++)
50         {
51           GtkStyleProperty *subproperty = _gtk_style_property_lookup (subproperties[i]);
52           g_assert (GTK_IS_CSS_STYLE_PROPERTY (subproperty));
53           g_ptr_array_add (property->subproperties, subproperty);
54         }
55       break;
56     default:
57       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
58       break;
59     }
60 }
61
62 static void
63 _gtk_css_shorthand_property_class_init (GtkCssShorthandPropertyClass *klass)
64 {
65   GObjectClass *object_class = G_OBJECT_CLASS (klass);
66
67   object_class->set_property = gtk_css_shorthand_property_set_property;
68
69   g_object_class_install_property (object_class,
70                                    PROP_SUBPROPERTIES,
71                                    g_param_spec_boxed ("subproperties",
72                                                        P_("Subproperties"),
73                                                        P_("The list of subproperties"),
74                                                        G_TYPE_STRV,
75                                                        G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
76 }
77
78 static void
79 _gtk_css_shorthand_property_init (GtkCssShorthandProperty *shorthand)
80 {
81   shorthand->subproperties = g_ptr_array_new_with_free_func (g_object_unref);
82 }
83
84 GtkCssStyleProperty *
85 _gtk_css_shorthand_property_get_subproperty (GtkCssShorthandProperty *shorthand,
86                                              guint                    property)
87 {
88   g_return_val_if_fail (GTK_IS_CSS_SHORTHAND_PROPERTY (shorthand), NULL);
89   g_return_val_if_fail (property < shorthand->subproperties->len, NULL);
90
91   return g_ptr_array_index (shorthand->subproperties, property);
92 }
93
94 guint
95 _gtk_css_shorthand_property_get_n_subproperties (GtkCssShorthandProperty *shorthand)
96 {
97   g_return_val_if_fail (GTK_IS_CSS_SHORTHAND_PROPERTY (shorthand), 0);
98   
99   return shorthand->subproperties->len;
100 }
101