1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2011 Benjamin Otte <otte@gnome.org>
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 of the License, or (at your option) any later version.
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.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
20 #include "gtkcsslookupprivate.h"
22 #include "gtkcsstypesprivate.h"
23 #include "gtkprivatetypebuiltins.h"
24 #include "gtkcssstylepropertyprivate.h"
25 #include "gtkstylepropertiesprivate.h"
28 GtkCssSection *section;
30 const GValue *computed;
33 struct _GtkCssLookup {
35 GtkCssLookupValue values[1];
39 _gtk_css_lookup_new (void)
42 guint n = _gtk_css_style_property_get_n_properties ();
44 lookup = g_malloc0 (sizeof (GtkCssLookup) + sizeof (GtkCssLookupValue) * n);
45 lookup->missing = _gtk_bitmask_new ();
46 lookup->missing = _gtk_bitmask_invert_range (lookup->missing, 0, n);
52 _gtk_css_lookup_free (GtkCssLookup *lookup)
54 g_return_if_fail (lookup != NULL);
56 _gtk_bitmask_free (lookup->missing);
61 _gtk_css_lookup_get_missing (const GtkCssLookup *lookup)
63 g_return_val_if_fail (lookup != NULL, NULL);
65 return lookup->missing;
69 _gtk_css_lookup_is_missing (const GtkCssLookup *lookup,
72 g_return_val_if_fail (lookup != NULL, FALSE);
74 return _gtk_bitmask_get (lookup->missing, id);
78 * _gtk_css_lookup_set:
80 * @id: id of the property to set, see _gtk_style_property_get_id()
81 * @section: (allow-none): The @section the value was defined in or %NULL
82 * @value: the "cascading value" to use
84 * Sets the @value for a given @id. No value may have been set for @id
85 * before. See _gtk_css_lookup_is_missing(). This function is used to
86 * set the "winning declaration" of a lookup. Note that for performance
87 * reasons @value and @section are not copied. It is your responsibility
88 * to ensure they are kept alive until _gtk_css_lookup_free() is called.
91 _gtk_css_lookup_set (GtkCssLookup *lookup,
93 GtkCssSection *section,
96 g_return_if_fail (lookup != NULL);
97 g_return_if_fail (_gtk_bitmask_get (lookup->missing, id));
98 g_return_if_fail (value != NULL);
100 lookup->missing = _gtk_bitmask_set (lookup->missing, id, FALSE);
101 lookup->values[id].value = value;
102 lookup->values[id].section = section;
106 * _gtk_css_lookup_set_computed:
107 * @lookup: the lookup
108 * @id: id of the property to set, see _gtk_style_property_get_id()
109 * @section: (allow-none): The @section the value was defined in or %NULL
110 * @value: the "computed value" to use
112 * Sets the @value for a given @id. No value may have been set for @id
113 * before. See _gtk_css_lookup_is_missing(). This function is used to
114 * set the "winning declaration" of a lookup. Note that for performance
115 * reasons @value and @section are not copied. It is your responsibility
116 * to ensure they are kept alive until _gtk_css_lookup_free() is called.
118 * As opposed to _gtk_css_lookup_set(), this function forces a computed
119 * value and will not cause computation to happen. In particular, with this
120 * method relative lengths or symbolic colors can not be used. This is
121 * usually only useful for doing overrides. It should not be used for proper
125 _gtk_css_lookup_set_computed (GtkCssLookup *lookup,
127 GtkCssSection *section,
130 g_return_if_fail (lookup != NULL);
131 g_return_if_fail (_gtk_bitmask_get (lookup->missing, id));
132 g_return_if_fail (value != NULL);
134 lookup->missing = _gtk_bitmask_set (lookup->missing, id, FALSE);
135 lookup->values[id].computed = value;
136 lookup->values[id].section = section;
140 * _gtk_css_lookup_resolve:
141 * @lookup: the lookup
142 * @context: the context the values are resolved for
143 * @values: a new #GtkCssComputedValues to be filled with the new properties
145 * Resolves the current lookup into a styleproperties object. This is done
146 * by converting from the "winning declaration" to the "computed value".
148 * XXX: This bypasses the notion of "specified value". If this ever becomes
149 * an issue, go fix it.
152 _gtk_css_lookup_resolve (GtkCssLookup *lookup,
153 GtkStyleContext *context,
154 GtkCssComputedValues *values)
158 g_return_if_fail (lookup != NULL);
159 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
160 g_return_if_fail (GTK_IS_CSS_COMPUTED_VALUES (values));
162 n = _gtk_css_style_property_get_n_properties ();
164 for (i = 0; i < n; i++)
166 if (lookup->values[i].computed)
167 _gtk_css_computed_values_set_value (values,
169 lookup->values[i].computed,
170 lookup->values[i].section);
172 _gtk_css_computed_values_compute_value (values,
175 lookup->values[i].value,
176 lookup->values[i].section);