1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2011 Red Hat, Inc.
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, see <http://www.gnu.org/licenses/>.
20 #include "gtkcssbordervalueprivate.h"
22 #include "gtkcssnumbervalueprivate.h"
27 GtkCssValue *values[4];
31 gtk_css_value_border_free (GtkCssValue *value)
35 for (i = 0; i < 4; i++)
38 _gtk_css_value_unref (value->values[i]);
41 g_slice_free (GtkCssValue, value);
45 gtk_css_value_border_equal (const GtkCssValue *value1,
46 const GtkCssValue *value2)
50 if (value1->fill != value2->fill)
53 for (i = 0; i < 4; i++)
55 if (!_gtk_css_value_equal0 (value1->values[i], value2->values[i]))
63 gtk_css_value_border_transition (GtkCssValue *start,
71 gtk_css_value_border_print (const GtkCssValue *value,
76 if (!_gtk_css_value_equal0 (value->values[GTK_CSS_RIGHT], value->values[GTK_CSS_LEFT]))
78 else if (!_gtk_css_value_equal0 (value->values[GTK_CSS_TOP], value->values[GTK_CSS_BOTTOM]))
80 else if (!_gtk_css_value_equal0 (value->values[GTK_CSS_TOP], value->values[GTK_CSS_RIGHT]))
85 for (i = 0; i < n; i++)
88 g_string_append_c (string, ' ');
90 if (value->values[i] == NULL)
91 g_string_append (string, "auto");
93 _gtk_css_value_print (value->values[i], string);
97 g_string_append (string, " fill");
100 static const GtkCssValueClass GTK_CSS_VALUE_BORDER = {
101 gtk_css_value_border_free,
102 gtk_css_value_border_equal,
103 gtk_css_value_border_transition,
104 gtk_css_value_border_print
108 _gtk_css_border_value_new (GtkCssValue *top,
115 result = _gtk_css_value_new (GtkCssValue, >K_CSS_VALUE_BORDER);
116 result->values[GTK_CSS_TOP] = top;
117 result->values[GTK_CSS_RIGHT] = right;
118 result->values[GTK_CSS_BOTTOM] = bottom;
119 result->values[GTK_CSS_LEFT] = left;
125 _gtk_css_border_value_parse (GtkCssParser *parser,
126 GtkCssNumberParseFlags flags,
133 result = _gtk_css_border_value_new (NULL, NULL, NULL, NULL);
136 result->fill = _gtk_css_parser_try (parser, "fill", TRUE);
138 for (i = 0; i < 4; i++)
140 if (allow_auto && _gtk_css_parser_try (parser, "auto", TRUE))
143 if (!_gtk_css_parser_has_number (parser))
146 result->values[i] = _gtk_css_number_value_parse (parser, flags);
147 if (result->values[i] == NULL)
149 _gtk_css_value_unref (result);
156 _gtk_css_parser_error (parser, "Expected a number");
157 _gtk_css_value_unref (result);
161 if (allow_fill && !result->fill)
162 result->fill = _gtk_css_parser_try (parser, "fill", TRUE);
166 if (result->values[(i - 1) >> 1])
167 result->values[i] = _gtk_css_value_ref (result->values[(i - 1) >> 1]);
174 _gtk_css_border_value_get_top (const GtkCssValue *value)
176 g_return_val_if_fail (value->class == >K_CSS_VALUE_BORDER, NULL);
178 return value->values[GTK_CSS_TOP];
182 _gtk_css_border_value_get_right (const GtkCssValue *value)
184 g_return_val_if_fail (value->class == >K_CSS_VALUE_BORDER, NULL);
186 return value->values[GTK_CSS_RIGHT];
190 _gtk_css_border_value_get_bottom (const GtkCssValue *value)
192 g_return_val_if_fail (value->class == >K_CSS_VALUE_BORDER, NULL);
194 return value->values[GTK_CSS_BOTTOM];
198 _gtk_css_border_value_get_left (const GtkCssValue *value)
200 g_return_val_if_fail (value->class == >K_CSS_VALUE_BORDER, NULL);
202 return value->values[GTK_CSS_LEFT];
206 _gtk_css_border_value_compute (GtkCssValue *value,
207 GtkStyleContext *context)
209 GtkCssValue *computed;
210 gboolean changed = FALSE;
213 g_return_val_if_fail (value->class == >K_CSS_VALUE_BORDER, NULL);
215 computed = _gtk_css_border_value_new (NULL, NULL, NULL, NULL);
216 computed->fill = value->fill;
218 for (i = 0; i < 4; i++)
220 if (value->values[i])
222 computed->values[i] = _gtk_css_number_value_compute (value->values[i], context);
223 changed |= (computed->values[i] != value->values[i]);
229 _gtk_css_value_unref (computed);
230 return _gtk_css_value_ref (value);