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, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
22 #include "gtkcsslookupprivate.h"
24 #include "gtkcsstypesprivate.h"
25 #include "gtkprivatetypebuiltins.h"
26 #include "gtkcssstylepropertyprivate.h"
27 #include "gtkstylepropertiesprivate.h"
30 GtkCssSection *section;
32 const GValue *computed;
35 struct _GtkCssLookup {
37 GtkCssLookupValue values[1];
41 _gtk_css_lookup_new (void)
44 guint n = _gtk_css_style_property_get_n_properties ();
46 lookup = g_malloc0 (sizeof (GtkCssLookup) + sizeof (GtkCssLookupValue) * n);
47 lookup->missing = _gtk_bitmask_new ();
48 _gtk_bitmask_invert_range (lookup->missing, 0, n);
54 _gtk_css_lookup_free (GtkCssLookup *lookup)
56 g_return_if_fail (lookup != NULL);
58 _gtk_bitmask_free (lookup->missing);
63 _gtk_css_lookup_get_missing (const GtkCssLookup *lookup)
65 g_return_val_if_fail (lookup != NULL, NULL);
67 return lookup->missing;
71 _gtk_css_lookup_is_missing (const GtkCssLookup *lookup,
74 g_return_val_if_fail (lookup != NULL, FALSE);
76 return _gtk_bitmask_get (lookup->missing, id);
80 * _gtk_css_lookup_set:
82 * @id: id of the property to set, see _gtk_style_property_get_id()
83 * @section: (allow-none): The @section the value was defined in or %NULL
84 * @value: the "cascading value" to use
86 * Sets the @value for a given @id. No value may have been set for @id
87 * before. See _gtk_css_lookup_is_missing(). This function is used to
88 * set the "winning declaration" of a lookup. Note that for performance
89 * reasons @value and @section are not copied. It is your responsibility
90 * to ensure they are kept alive until _gtk_css_lookup_free() is called.
93 _gtk_css_lookup_set (GtkCssLookup *lookup,
95 GtkCssSection *section,
98 g_return_if_fail (lookup != NULL);
99 g_return_if_fail (_gtk_bitmask_get (lookup->missing, id));
100 g_return_if_fail (value != NULL);
102 _gtk_bitmask_set (lookup->missing, id, FALSE);
103 lookup->values[id].value = value;
104 lookup->values[id].section = section;
108 * _gtk_css_lookup_set_computed:
109 * @lookup: the lookup
110 * @id: id of the property to set, see _gtk_style_property_get_id()
111 * @section: (allow-none): The @section the value was defined in or %NULL
112 * @value: the "computed value" to use
114 * Sets the @value for a given @id. No value may have been set for @id
115 * before. See _gtk_css_lookup_is_missing(). This function is used to
116 * set the "winning declaration" of a lookup. Note that for performance
117 * reasons @value and @section are not copied. It is your responsibility
118 * to ensure they are kept alive until _gtk_css_lookup_free() is called.
120 * As opposed to _gtk_css_lookup_set(), this function forces a computed
121 * value and will not cause computation to happen. In particular, with this
122 * method relative lengths or symbolic colors can not be used. This is
123 * usually only useful for doing overrides. It should not be used for proper
127 _gtk_css_lookup_set_computed (GtkCssLookup *lookup,
129 GtkCssSection *section,
132 g_return_if_fail (lookup != NULL);
133 g_return_if_fail (_gtk_bitmask_get (lookup->missing, id));
134 g_return_if_fail (value != NULL);
136 _gtk_bitmask_set (lookup->missing, id, FALSE);
137 lookup->values[id].computed = value;
138 lookup->values[id].section = section;
142 * _gtk_css_lookup_resolve:
143 * @lookup: the lookup
144 * @context: the context the values are resolved for
145 * @values: a new #GtkCssComputedValues to be filled with the new properties
147 * Resolves the current lookup into a styleproperties object. This is done
148 * by converting from the "winning declaration" to the "computed value".
150 * XXX: This bypasses the notion of "specified value". If this ever becomes
151 * an issue, go fix it.
154 _gtk_css_lookup_resolve (GtkCssLookup *lookup,
155 GtkStyleContext *context,
156 GtkCssComputedValues *values)
160 g_return_if_fail (lookup != NULL);
161 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
162 g_return_if_fail (GTK_IS_CSS_COMPUTED_VALUES (values));
164 n = _gtk_css_style_property_get_n_properties ();
166 for (i = 0; i < n; i++)
168 if (lookup->values[i].computed)
169 _gtk_css_computed_values_set_value (values,
171 lookup->values[i].computed,
172 lookup->values[i].section);
174 _gtk_css_computed_values_compute_value (values,
177 lookup->values[i].value,
178 lookup->values[i].section);