| File: | ctk/ctkcsslookup.c |
| Warning: | line 40, column 23 Using a fixed address is not portable because that address will probably not be valid in all environments or platforms |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* CTK - 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 "ctkcsslookupprivate.h" | |||
| 21 | ||||
| 22 | #include "ctkcssstylepropertyprivate.h" | |||
| 23 | #include "ctkcsstypesprivate.h" | |||
| 24 | #include "ctkprivatetypebuiltins.h" | |||
| 25 | #include "ctkprivate.h" | |||
| 26 | ||||
| 27 | CtkCssLookup * | |||
| 28 | _ctk_css_lookup_new (const CtkBitmask *relevant) | |||
| 29 | { | |||
| 30 | CtkCssLookup *lookup; | |||
| 31 | ||||
| 32 | lookup = g_malloc0 (sizeof (CtkCssLookup)); | |||
| 33 | ||||
| 34 | if (relevant) | |||
| ||||
| 35 | { | |||
| 36 | lookup->missing = _ctk_bitmask_copy (relevant); | |||
| 37 | } | |||
| 38 | else | |||
| 39 | { | |||
| 40 | lookup->missing = _ctk_bitmask_new (); | |||
| ||||
| 41 | lookup->missing = _ctk_bitmask_invert_range (lookup->missing, 0, CTK_CSS_PROPERTY_N_PROPERTIES); | |||
| 42 | } | |||
| 43 | ||||
| 44 | return lookup; | |||
| 45 | } | |||
| 46 | ||||
| 47 | void | |||
| 48 | _ctk_css_lookup_free (CtkCssLookup *lookup) | |||
| 49 | { | |||
| 50 | ctk_internal_return_if_fail (lookup != NULL)do { if ((lookup != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "lookup != ((void*)0)"); return; } } while (0); | |||
| 51 | ||||
| 52 | _ctk_bitmask_free (lookup->missing); | |||
| 53 | g_free (lookup); | |||
| 54 | } | |||
| 55 | ||||
| 56 | gboolean | |||
| 57 | _ctk_css_lookup_is_missing (const CtkCssLookup *lookup, | |||
| 58 | guint id) | |||
| 59 | { | |||
| 60 | ctk_internal_return_val_if_fail (lookup != NULL, FALSE)do { if ((lookup != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "lookup != ((void*)0)"); return ((0)); } } while (0); | |||
| 61 | ||||
| 62 | return _ctk_bitmask_get (lookup->missing, id); | |||
| 63 | } | |||
| 64 | ||||
| 65 | /** | |||
| 66 | * _ctk_css_lookup_set: | |||
| 67 | * @lookup: the lookup | |||
| 68 | * @id: id of the property to set, see _ctk_style_property_get_id() | |||
| 69 | * @section: (allow-none): The @section the value was defined in or %NULL | |||
| 70 | * @value: the “cascading value” to use | |||
| 71 | * | |||
| 72 | * Sets the @value for a given @id. No value may have been set for @id | |||
| 73 | * before. See _ctk_css_lookup_is_missing(). This function is used to | |||
| 74 | * set the “winning declaration” of a lookup. Note that for performance | |||
| 75 | * reasons @value and @section are not copied. It is your responsibility | |||
| 76 | * to ensure they are kept alive until _ctk_css_lookup_free() is called. | |||
| 77 | **/ | |||
| 78 | void | |||
| 79 | _ctk_css_lookup_set (CtkCssLookup *lookup, | |||
| 80 | guint id, | |||
| 81 | CtkCssSection *section, | |||
| 82 | CtkCssValue *value) | |||
| 83 | { | |||
| 84 | ctk_internal_return_if_fail (lookup != NULL)do { if ((lookup != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "lookup != ((void*)0)"); return; } } while (0); | |||
| 85 | ctk_internal_return_if_fail (_ctk_bitmask_get (lookup->missing, id))do { if ((_ctk_bitmask_get (lookup->missing, id))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__) ), "_ctk_bitmask_get (lookup->missing, id)"); return; } } while (0); | |||
| 86 | ctk_internal_return_if_fail (value != NULL)do { if ((value != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "value != ((void*)0)"); return ; } } while (0); | |||
| 87 | ||||
| 88 | lookup->missing = _ctk_bitmask_set (lookup->missing, id, FALSE(0)); | |||
| 89 | lookup->values[id].value = value; | |||
| 90 | lookup->values[id].section = section; | |||
| 91 | } | |||
| 92 | ||||
| 93 | /** | |||
| 94 | * _ctk_css_lookup_resolve: | |||
| 95 | * @lookup: the lookup | |||
| 96 | * @context: the context the values are resolved for | |||
| 97 | * @values: a new #CtkCssStyle to be filled with the new properties | |||
| 98 | * | |||
| 99 | * Resolves the current lookup into a styleproperties object. This is done | |||
| 100 | * by converting from the “winning declaration” to the “computed value”. | |||
| 101 | * | |||
| 102 | * XXX: This bypasses the notion of “specified value”. If this ever becomes | |||
| 103 | * an issue, go fix it. | |||
| 104 | **/ | |||
| 105 | void | |||
| 106 | _ctk_css_lookup_resolve (CtkCssLookup *lookup, | |||
| 107 | CtkStyleProviderPrivate *provider, | |||
| 108 | CtkCssStaticStyle *style, | |||
| 109 | CtkCssStyle *parent_style) | |||
| 110 | { | |||
| 111 | guint i; | |||
| 112 | ||||
| 113 | ctk_internal_return_if_fail (lookup != NULL)do { if ((lookup != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "lookup != ((void*)0)"); return; } } while (0); | |||
| 114 | ctk_internal_return_if_fail (CTK_IS_STYLE_PROVIDER_PRIVATE (provider))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((provider)); GType __t = ((_ctk_style_provider_private_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ((provider)); GType __t = ((_ctk_style_provider_private_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; }))))" ); return; } } while (0); | |||
| 115 | ctk_internal_return_if_fail (CTK_IS_CSS_STATIC_STYLE (style))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) (style); GType __t = ((ctk_css_static_style_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0) ); else __r = g_type_check_instance_is_a (__inst, __t); __r; } )))))) { } else { g_return_if_fail_warning ("Ctk", ((const char *) (__func__)), "(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) (style); GType __t = ((ctk_css_static_style_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; }))))" ); return; } } while (0); | |||
| 116 | ctk_internal_return_if_fail (parent_style == NULL || CTK_IS_CSS_STYLE (parent_style))do { if ((parent_style == ((void*)0) || (((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) (parent_style); GType __t = ((ctk_css_style_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "parent_style == ((void*)0) || (((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) (parent_style); GType __t = ((ctk_css_style_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; }))))" ); return; } } while (0); | |||
| 117 | ||||
| 118 | for (i = 0; i < CTK_CSS_PROPERTY_N_PROPERTIES; i++) | |||
| 119 | { | |||
| 120 | if (lookup->values[i].value || | |||
| 121 | _ctk_bitmask_get (lookup->missing, i)) | |||
| 122 | ctk_css_static_style_compute_value (style, | |||
| 123 | provider, | |||
| 124 | parent_style, | |||
| 125 | i, | |||
| 126 | lookup->values[i].value, | |||
| 127 | lookup->values[i].section); | |||
| 128 | /* else not a relevant property */ | |||
| 129 | } | |||
| 130 | } |