]> Pileus Git - ~andy/gtk/blob - gtk/gtkcssmatcherprivate.h
matcher: Turn GtkCssMatcher into a union
[~andy/gtk] / gtk / gtkcssmatcherprivate.h
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 2012 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 #ifndef __GTK_CSS_MATCHER_PRIVATE_H__
19 #define __GTK_CSS_MATCHER_PRIVATE_H__
20
21 #include <gtk/gtkenums.h>
22 #include <gtk/gtktypes.h>
23
24 G_BEGIN_DECLS
25
26 typedef union _GtkCssMatcher GtkCssMatcher;
27 typedef struct _GtkCssMatcherWidgetPath GtkCssMatcherWidgetPath;
28 typedef struct _GtkCssMatcherClass GtkCssMatcherClass;
29
30 struct _GtkCssMatcherClass {
31   gboolean        (* get_parent)                  (GtkCssMatcher          *matcher,
32                                                    const GtkCssMatcher    *child);
33   gboolean        (* get_previous)                (GtkCssMatcher          *matcher,
34                                                    const GtkCssMatcher    *next);
35
36   GtkStateFlags   (* get_state)                   (const GtkCssMatcher   *matcher);
37   gboolean        (* has_name)                    (const GtkCssMatcher   *matcher,
38                                                    const char            *name);
39   gboolean        (* has_class)                   (const GtkCssMatcher   *matcher,
40                                                    const char            *class_name);
41   gboolean        (* has_id)                      (const GtkCssMatcher   *matcher,
42                                                    const char            *id);
43   gboolean        (* has_regions)                 (const GtkCssMatcher   *matcher);
44   gboolean        (* has_region)                  (const GtkCssMatcher   *matcher,
45                                                    const char            *region,
46                                                    GtkRegionFlags         flags);
47   guint           (* get_sibling_index)           (const GtkCssMatcher   *matcher);
48   guint           (* get_n_siblings)              (const GtkCssMatcher   *matcher);
49 };
50
51 struct _GtkCssMatcherWidgetPath {
52   const GtkCssMatcherClass *klass;
53   const GtkWidgetPath      *path;
54   GtkStateFlags             state_flags;
55   guint                     index;
56   guint                     sibling_index;
57 };
58
59 union _GtkCssMatcher {
60   const GtkCssMatcherClass *klass;
61   GtkCssMatcherWidgetPath   path;
62 };
63
64 void              _gtk_css_matcher_init           (GtkCssMatcher          *matcher,
65                                                    const GtkWidgetPath    *path,
66                                                    GtkStateFlags           state);
67
68 static inline gboolean
69 _gtk_css_matcher_get_parent (GtkCssMatcher       *matcher,
70                              const GtkCssMatcher *child)
71 {
72   return child->klass->get_parent (matcher, child);
73 }
74
75 static inline gboolean
76 _gtk_css_matcher_get_previous (GtkCssMatcher       *matcher,
77                                const GtkCssMatcher *next)
78 {
79   return next->klass->get_previous (matcher, next);
80 }
81
82 static inline GtkStateFlags
83 _gtk_css_matcher_get_state (const GtkCssMatcher *matcher)
84 {
85   return matcher->klass->get_state (matcher);
86 }
87
88 static inline gboolean
89 _gtk_css_matcher_has_name (const GtkCssMatcher *matcher,
90                            const char          *name)
91 {
92   return matcher->klass->has_name (matcher, name);
93 }
94
95 static inline gboolean
96 _gtk_css_matcher_has_class (const GtkCssMatcher *matcher,
97                             const char          *class_name)
98 {
99   return matcher->klass->has_class (matcher, class_name);
100 }
101
102 static inline gboolean
103 _gtk_css_matcher_has_id (const GtkCssMatcher *matcher,
104                          const char          *id)
105 {
106   return matcher->klass->has_id (matcher, id);
107 }
108
109
110 static inline gboolean
111 _gtk_css_matcher_has_regions (const GtkCssMatcher *matcher)
112 {
113   return matcher->klass->has_regions (matcher);
114 }
115
116 static inline gboolean
117 _gtk_css_matcher_has_region (const GtkCssMatcher *matcher,
118                              const char          *region,
119                              GtkRegionFlags       flags)
120 {
121   return matcher->klass->has_region (matcher, region, flags);
122 }
123
124 static inline guint
125 _gtk_css_matcher_get_sibling_index (const GtkCssMatcher *matcher)
126 {
127   return matcher->klass->get_sibling_index (matcher);
128 }
129
130 static inline guint
131 _gtk_css_matcher_get_n_siblings (const GtkCssMatcher *matcher)
132 {
133   return matcher->klass->get_n_siblings (matcher);
134 }
135
136
137 G_END_DECLS
138
139 #endif /* __GTK_CSS_MATCHER_PRIVATE_H__ */