]> Pileus Git - ~andy/gtk/blob - gtk/gtkcsstypes.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / gtk / gtkcsstypes.c
1 /* GTK - 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 "gtkcsstypesprivate.h"
21
22 #include "gtkcssnumbervalueprivate.h"
23 #include "gtkstylecontextprivate.h"
24
25 typedef struct _GtkCssChangeTranslation GtkCssChangeTranslation;
26 struct _GtkCssChangeTranslation {
27   GtkCssChange from;
28   GtkCssChange to;
29 };
30
31 static GtkCssChange
32 gtk_css_change_translate (GtkCssChange                   match,
33                          const GtkCssChangeTranslation *translations,
34                          guint                         n_translations)
35 {
36   GtkCssChange result = match;
37   guint i;
38
39   for (i = 0; i < n_translations; i++)
40     {
41       if (match & translations[i].from)
42         {
43           result &= ~translations[i].from;
44           result |= translations[i].to;
45         }
46     }
47
48   return result;
49 }
50
51 GtkCssChange
52 _gtk_css_change_for_sibling (GtkCssChange match)
53 {
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 }
61   };
62
63   return gtk_css_change_translate (match, table, G_N_ELEMENTS (table)); 
64 }
65
66 GtkCssChange
67 _gtk_css_change_for_child (GtkCssChange match)
68 {
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 }
80   };
81
82   return gtk_css_change_translate (match, table, G_N_ELEMENTS (table)); 
83 }
84
85 GtkCssDependencies
86 _gtk_css_dependencies_union (GtkCssDependencies first,
87                              GtkCssDependencies second)
88 {
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);
91 }
92