1 | /* GTK - The GIMP Toolkit |
2 | * Copyright (C) 2011 Benjamin Otte <otte@gnome.org> |
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 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, see <http://www.gnu.org/licenses/>. |
16 | */ |
17 | |
18 | #include "config.h" |
19 | |
20 | #include "gtkcsslookupprivate.h" |
21 | |
22 | #include "gtkcssstylepropertyprivate.h" |
23 | #include "gtkcsstypesprivate.h" |
24 | #include "gtkprivatetypebuiltins.h" |
25 | #include "gtkprivate.h" |
26 | |
27 | void |
28 | _gtk_css_lookup_init (GtkCssLookup *lookup) |
29 | { |
30 | memset (s: lookup, c: 0, n: sizeof (*lookup)); |
31 | |
32 | lookup->set_values = _gtk_bitmask_new (); |
33 | } |
34 | |
35 | void |
36 | _gtk_css_lookup_destroy (GtkCssLookup *lookup) |
37 | { |
38 | _gtk_bitmask_free (mask: lookup->set_values); |
39 | } |
40 | |
41 | gboolean |
42 | _gtk_css_lookup_is_missing (const GtkCssLookup *lookup, |
43 | guint id) |
44 | { |
45 | gtk_internal_return_val_if_fail (lookup != NULL, FALSE); |
46 | |
47 | return !_gtk_bitmask_get (mask: lookup->set_values, index_: id); |
48 | } |
49 | |
50 | /** |
51 | * _gtk_css_lookup_set: |
52 | * @lookup: the lookup |
53 | * @id: id of the property to set, see _gtk_style_property_get_id() |
54 | * @section: (nullable): The @section the value was defined in |
55 | * @value: the “cascading value” to use |
56 | * |
57 | * Sets the @value for a given @id. No value may have been set for @id |
58 | * before. See _gtk_css_lookup_is_missing(). This function is used to |
59 | * set the “winning declaration” of a lookup. Note that for performance |
60 | * reasons @value and @section are not copied. It is your responsibility |
61 | * to ensure they are kept alive until _gtk_css_lookup_free() is called. |
62 | **/ |
63 | void |
64 | _gtk_css_lookup_set (GtkCssLookup *lookup, |
65 | guint id, |
66 | GtkCssSection *section, |
67 | GtkCssValue *value) |
68 | { |
69 | gtk_internal_return_if_fail (lookup != NULL); |
70 | gtk_internal_return_if_fail (value != NULL); |
71 | gtk_internal_return_if_fail (lookup->values[id].value == NULL); |
72 | |
73 | lookup->values[id].value = value; |
74 | lookup->values[id].section = section; |
75 | lookup->set_values = _gtk_bitmask_set (mask: lookup->set_values, index_: id, TRUE); |
76 | } |
77 | |