1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2011 Benjamin Otte <otte@gnome.org>
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 "gtkcsstypesprivate.h"
22 #include "gtkcssnumbervalueprivate.h"
23 #include "gtkstylecontextprivate.h"
25 typedef struct _GtkCssChangeTranslation GtkCssChangeTranslation;
26 struct _GtkCssChangeTranslation {
32 gtk_css_change_translate (GtkCssChange match,
33 const GtkCssChangeTranslation *translations,
36 GtkCssChange result = match;
39 for (i = 0; i < n_translations; i++)
41 if (match & translations[i].from)
43 result &= ~translations[i].from;
44 result |= translations[i].to;
52 _gtk_css_change_for_sibling (GtkCssChange match)
54 static const GtkCssChangeTranslation table[] = {
55 { GTK_CSS_CHANGE_CLASS, GTK_CSS_CHANGE_SIBLING_CLASS },
56 { GTK_CSS_CHANGE_NAME, GTK_CSS_CHANGE_SIBLING_NAME },
57 { GTK_CSS_CHANGE_POSITION, GTK_CSS_CHANGE_SIBLING_POSITION },
58 { GTK_CSS_CHANGE_STATE, GTK_CSS_CHANGE_SIBLING_STATE },
59 { GTK_CSS_CHANGE_SOURCE, 0 },
60 { GTK_CSS_CHANGE_ANIMATE, 0 }
63 return gtk_css_change_translate (match, table, G_N_ELEMENTS (table));
67 _gtk_css_change_for_child (GtkCssChange match)
69 static const GtkCssChangeTranslation table[] = {
70 { GTK_CSS_CHANGE_CLASS, GTK_CSS_CHANGE_PARENT_CLASS },
71 { GTK_CSS_CHANGE_NAME, GTK_CSS_CHANGE_PARENT_NAME },
72 { GTK_CSS_CHANGE_POSITION, GTK_CSS_CHANGE_PARENT_POSITION },
73 { GTK_CSS_CHANGE_STATE, GTK_CSS_CHANGE_PARENT_STATE },
74 { GTK_CSS_CHANGE_SIBLING_CLASS, GTK_CSS_CHANGE_PARENT_SIBLING_CLASS },
75 { GTK_CSS_CHANGE_SIBLING_NAME, GTK_CSS_CHANGE_PARENT_SIBLING_NAME },
76 { GTK_CSS_CHANGE_SIBLING_POSITION, GTK_CSS_CHANGE_PARENT_SIBLING_POSITION },
77 { GTK_CSS_CHANGE_SIBLING_STATE, GTK_CSS_CHANGE_PARENT_SIBLING_STATE },
78 { GTK_CSS_CHANGE_SOURCE, 0 },
79 { GTK_CSS_CHANGE_ANIMATE, 0 }
82 return gtk_css_change_translate (match, table, G_N_ELEMENTS (table));
86 _gtk_css_dependencies_union (GtkCssDependencies first,
87 GtkCssDependencies second)
89 return (first & ~GTK_CSS_EQUALS_PARENT) | ((first & GTK_CSS_EQUALS_PARENT) ? GTK_CSS_DEPENDS_ON_PARENT : 0)
90 | (second & ~GTK_CSS_EQUALS_PARENT) | ((second & GTK_CSS_EQUALS_PARENT) ? GTK_CSS_DEPENDS_ON_PARENT : 0);