File: | ctk/ctkcssstylechange.c |
Warning: | line 72, 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) 2015 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 "ctkcssstylechangeprivate.h" | |||
21 | ||||
22 | #include "ctkcssstylepropertyprivate.h" | |||
23 | ||||
24 | void | |||
25 | ctk_css_style_change_init (CtkCssStyleChange *change, | |||
26 | CtkCssStyle *old_style, | |||
27 | CtkCssStyle *new_style) | |||
28 | { | |||
29 | change->old_style = g_object_ref (old_style)((__typeof__ (old_style)) (g_object_ref) (old_style)); | |||
30 | change->new_style = g_object_ref (new_style)((__typeof__ (new_style)) (g_object_ref) (new_style)); | |||
31 | ||||
32 | change->n_compared = 0; | |||
33 | ||||
34 | change->affects = 0; | |||
35 | change->changes = _ctk_bitmask_new (); | |||
36 | ||||
37 | /* Make sure we don't do extra work if old and new are equal. */ | |||
38 | if (old_style == new_style) | |||
39 | change->n_compared = CTK_CSS_PROPERTY_N_PROPERTIES; | |||
40 | } | |||
41 | ||||
42 | void | |||
43 | ctk_css_style_change_finish (CtkCssStyleChange *change) | |||
44 | { | |||
45 | g_object_unref (change->old_style); | |||
46 | g_object_unref (change->new_style); | |||
47 | _ctk_bitmask_free (change->changes); | |||
48 | } | |||
49 | ||||
50 | CtkCssStyle * | |||
51 | ctk_css_style_change_get_old_style (CtkCssStyleChange *change) | |||
52 | { | |||
53 | return change->old_style; | |||
54 | } | |||
55 | ||||
56 | CtkCssStyle * | |||
57 | ctk_css_style_change_get_new_style (CtkCssStyleChange *change) | |||
58 | { | |||
59 | return change->new_style; | |||
60 | } | |||
61 | ||||
62 | static gboolean | |||
63 | ctk_css_style_compare_next_value (CtkCssStyleChange *change) | |||
64 | { | |||
65 | if (change->n_compared == CTK_CSS_PROPERTY_N_PROPERTIES) | |||
66 | return FALSE(0); | |||
67 | ||||
68 | if (!_ctk_css_value_equal (ctk_css_style_get_value (change->old_style, change->n_compared), | |||
69 | ctk_css_style_get_value (change->new_style, change->n_compared))) | |||
70 | { | |||
71 | change->affects |= _ctk_css_style_property_get_affects (_ctk_css_style_property_lookup_by_id (change->n_compared)); | |||
72 | change->changes = _ctk_bitmask_set (change->changes, change->n_compared, TRUE(!(0))); | |||
| ||||
73 | } | |||
74 | ||||
75 | change->n_compared++; | |||
76 | ||||
77 | return TRUE(!(0)); | |||
78 | } | |||
79 | ||||
80 | gboolean | |||
81 | ctk_css_style_change_has_change (CtkCssStyleChange *change) | |||
82 | { | |||
83 | do { | |||
84 | if (!_ctk_bitmask_is_empty (change->changes)) | |||
| ||||
85 | return TRUE(!(0)); | |||
86 | } while (ctk_css_style_compare_next_value (change)); | |||
87 | ||||
88 | return FALSE(0); | |||
89 | } | |||
90 | ||||
91 | gboolean | |||
92 | ctk_css_style_change_affects (CtkCssStyleChange *change, | |||
93 | CtkCssAffects affects) | |||
94 | { | |||
95 | do { | |||
96 | if (change->affects & affects) | |||
97 | return TRUE(!(0)); | |||
98 | } while (ctk_css_style_compare_next_value (change)); | |||
99 | ||||
100 | return FALSE(0); | |||
101 | } | |||
102 | ||||
103 | gboolean | |||
104 | ctk_css_style_change_changes_property (CtkCssStyleChange *change, | |||
105 | guint id) | |||
106 | { | |||
107 | while (change->n_compared <= id) | |||
108 | ctk_css_style_compare_next_value (change); | |||
109 | ||||
110 | return _ctk_bitmask_get (change->changes, id); | |||
111 | } | |||
112 | ||||
113 | void | |||
114 | ctk_css_style_change_print (CtkCssStyleChange *change, | |||
115 | GString *string) | |||
116 | { | |||
117 | int i; | |||
118 | CtkCssStyle *old = ctk_css_style_change_get_old_style (change); | |||
119 | CtkCssStyle *new = ctk_css_style_change_get_new_style (change); | |||
120 | ||||
121 | for (i = 0; i < CTK_CSS_PROPERTY_N_PROPERTIES; i ++) | |||
122 | { | |||
123 | if (ctk_css_style_change_changes_property (change, i)) | |||
124 | { | |||
125 | CtkCssStyleProperty *prop; | |||
126 | CtkCssValue *value; | |||
127 | const char *name; | |||
128 | ||||
129 | prop = _ctk_css_style_property_lookup_by_id (i); | |||
130 | name = _ctk_style_property_get_name (CTK_STYLE_PROPERTY (prop)((((CtkStyleProperty*) (void *) g_type_check_instance_cast (( GTypeInstance*) (prop), ((_ctk_style_property_get_type ())))) ))); | |||
131 | ||||
132 | value = ctk_css_style_get_value (old, i); | |||
133 | _ctk_css_value_print (value, string); | |||
134 | ||||
135 | g_string_append_printf (string, "%s: ", name); | |||
136 | _ctk_css_value_print (value, string); | |||
137 | g_string_append (string, "\n")(__builtin_constant_p ("\n") ? __extension__ ({ const char * const __val = ("\n"); g_string_append_len_inline (string, __val, ( __val != ((void*)0)) ? (gssize) strlen (((__val) + !(__val))) : (gssize) -1); }) : g_string_append_len_inline (string, "\n" , (gssize) -1)); | |||
138 | ||||
139 | g_string_append_printf (string, "%s: ", name); | |||
140 | value = ctk_css_style_get_value (new, i); | |||
141 | _ctk_css_value_print (value, string); | |||
142 | g_string_append (string, "\n")(__builtin_constant_p ("\n") ? __extension__ ({ const char * const __val = ("\n"); g_string_append_len_inline (string, __val, ( __val != ((void*)0)) ? (gssize) strlen (((__val) + !(__val))) : (gssize) -1); }) : g_string_append_len_inline (string, "\n" , (gssize) -1)); | |||
143 | } | |||
144 | } | |||
145 | ||||
146 | } | |||
147 | ||||
148 | char * | |||
149 | ctk_css_style_change_to_string (CtkCssStyleChange *change) | |||
150 | { | |||
151 | GString *string = g_string_new (""); | |||
152 | ||||
153 | ctk_css_style_change_print (change, string); | |||
154 | ||||
155 | return g_string_free (string, FALSE)(__builtin_constant_p ((0)) ? (((0)) ? (g_string_free) ((string ), ((0))) : g_string_free_and_steal (string)) : (g_string_free ) ((string), ((0)))); | |||
156 | } |