1/* GTK - 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 "gtkcssstylechangeprivate.h"
21
22#include "gtkcssstylepropertyprivate.h"
23
24static void
25compute_change (GtkCssStyleChange *change)
26{
27 gboolean color_changed = FALSE;
28
29 if (change->old_style->core != change->new_style->core)
30 {
31 gtk_css_core_values_compute_changes_and_affects (style1: change->old_style,
32 style2: change->new_style,
33 changes: &change->changes,
34 affects: &change->affects);
35 color_changed = _gtk_bitmask_get (mask: change->changes, index_: GTK_CSS_PROPERTY_COLOR);
36 }
37
38 if (change->old_style->background != change->new_style->background)
39 gtk_css_background_values_compute_changes_and_affects (style1: change->old_style,
40 style2: change->new_style,
41 changes: &change->changes,
42 affects: &change->affects);
43
44 if (change->old_style->border != change->new_style->border ||
45 (color_changed && (change->old_style->border->border_top_color == NULL ||
46 change->old_style->border->border_right_color == NULL ||
47 change->old_style->border->border_bottom_color == NULL ||
48 change->old_style->border->border_left_color == NULL)))
49 gtk_css_border_values_compute_changes_and_affects (style1: change->old_style,
50 style2: change->new_style,
51 changes: &change->changes,
52 affects: &change->affects);
53
54 if (change->old_style->icon != change->new_style->icon)
55 gtk_css_icon_values_compute_changes_and_affects (style1: change->old_style,
56 style2: change->new_style,
57 changes: &change->changes,
58 affects: &change->affects);
59
60 if (change->old_style->outline != change->new_style->outline ||
61 (color_changed && change->old_style->outline->outline_color == NULL))
62 gtk_css_outline_values_compute_changes_and_affects (style1: change->old_style,
63 style2: change->new_style,
64 changes: &change->changes,
65 affects: &change->affects);
66
67 if (change->old_style->font != change->new_style->font ||
68 (color_changed && (change->old_style->font->caret_color == NULL ||
69 change->old_style->font->secondary_caret_color == NULL)))
70 gtk_css_font_values_compute_changes_and_affects (style1: change->old_style,
71 style2: change->new_style,
72 changes: &change->changes,
73 affects: &change->affects);
74
75 if (change->old_style->font_variant != change->new_style->font_variant ||
76 (color_changed && change->old_style->font_variant->text_decoration_color == NULL))
77 gtk_css_font_variant_values_compute_changes_and_affects (style1: change->old_style,
78 style2: change->new_style,
79 changes: &change->changes,
80 affects: &change->affects);
81
82 if (change->old_style->animation != change->new_style->animation)
83 gtk_css_animation_values_compute_changes_and_affects (style1: change->old_style,
84 style2: change->new_style,
85 changes: &change->changes,
86 affects: &change->affects);
87
88 if (change->old_style->transition != change->new_style->transition)
89 gtk_css_transition_values_compute_changes_and_affects (style1: change->old_style,
90 style2: change->new_style,
91 changes: &change->changes,
92 affects: &change->affects);
93
94 if (change->old_style->size != change->new_style->size)
95 gtk_css_size_values_compute_changes_and_affects (style1: change->old_style,
96 style2: change->new_style,
97 changes: &change->changes,
98 affects: &change->affects);
99
100 if (change->old_style->other != change->new_style->other)
101 gtk_css_other_values_compute_changes_and_affects (style1: change->old_style,
102 style2: change->new_style,
103 changes: &change->changes,
104 affects: &change->affects);
105}
106
107void
108gtk_css_style_change_init (GtkCssStyleChange *change,
109 GtkCssStyle *old_style,
110 GtkCssStyle *new_style)
111{
112 change->old_style = g_object_ref (old_style);
113 change->new_style = g_object_ref (new_style);
114
115 change->affects = 0;
116 change->changes = _gtk_bitmask_new ();
117
118 if (old_style != new_style)
119 compute_change (change);
120}
121
122void
123gtk_css_style_change_finish (GtkCssStyleChange *change)
124{
125 g_object_unref (object: change->old_style);
126 g_object_unref (object: change->new_style);
127 _gtk_bitmask_free (mask: change->changes);
128}
129
130GtkCssStyle *
131gtk_css_style_change_get_old_style (GtkCssStyleChange *change)
132{
133 return change->old_style;
134}
135
136GtkCssStyle *
137gtk_css_style_change_get_new_style (GtkCssStyleChange *change)
138{
139 return change->new_style;
140}
141
142gboolean
143gtk_css_style_change_has_change (GtkCssStyleChange *change)
144{
145 return !_gtk_bitmask_is_empty (mask: change->changes);
146}
147
148gboolean
149gtk_css_style_change_affects (GtkCssStyleChange *change,
150 GtkCssAffects affects)
151{
152 return (change->affects & affects) != 0;
153}
154
155gboolean
156gtk_css_style_change_changes_property (GtkCssStyleChange *change,
157 guint id)
158{
159 return _gtk_bitmask_get (mask: change->changes, index_: id);
160}
161
162void
163gtk_css_style_change_print (GtkCssStyleChange *change,
164 GString *string)
165{
166 int i;
167 GtkCssStyle *old = gtk_css_style_change_get_old_style (change);
168 GtkCssStyle *new = gtk_css_style_change_get_new_style (change);
169
170 for (i = 0; i < GTK_CSS_PROPERTY_N_PROPERTIES; i ++)
171 {
172 if (gtk_css_style_change_changes_property (change, id: i))
173 {
174 GtkCssStyleProperty *prop;
175 GtkCssValue *value;
176 const char *name;
177
178 prop = _gtk_css_style_property_lookup_by_id (id: i);
179 name = _gtk_style_property_get_name (GTK_STYLE_PROPERTY (prop));
180
181 g_string_append_printf (string, format: "%s: ", name);
182 value = gtk_css_style_get_value (style: old, id: i);
183 _gtk_css_value_print (value, string);
184 g_string_append (string, val: "\n");
185
186 g_string_append_printf (string, format: "%s: ", name);
187 value = gtk_css_style_get_value (style: new, id: i);
188 _gtk_css_value_print (value, string);
189 g_string_append (string, val: "\n");
190 }
191 }
192
193}
194
195char *
196gtk_css_style_change_to_string (GtkCssStyleChange *change)
197{
198 GString *string = g_string_new (init: "");
199
200 gtk_css_style_change_print (change, string);
201
202 return g_string_free (string, FALSE);
203}
204

source code of gtk/gtk/gtkcssstylechange.c