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 "gtkstyleproviderprivate.h"
21 
22 #include "gtkintl.h"
23 #include "gtkstyleprovider.h"
24 #include "gtkprivate.h"
25 
26 enum {
27   CHANGED,
28   LAST_SIGNAL
29 };
30 
G_DEFINE_INTERFACE(GtkStyleProviderPrivate,_gtk_style_provider_private,GTK_TYPE_STYLE_PROVIDER)31 G_DEFINE_INTERFACE (GtkStyleProviderPrivate, _gtk_style_provider_private, GTK_TYPE_STYLE_PROVIDER)
32 
33 static guint signals[LAST_SIGNAL];
34 
35 static void
36 _gtk_style_provider_private_default_init (GtkStyleProviderPrivateInterface *iface)
37 {
38   signals[CHANGED] = g_signal_new (I_("-gtk-private-changed"),
39                                    G_TYPE_FROM_INTERFACE (iface),
40                                    G_SIGNAL_RUN_LAST,
41                                    G_STRUCT_OFFSET (GtkStyleProviderPrivateInterface, changed),
42                                    NULL, NULL,
43                                    NULL,
44                                    G_TYPE_NONE, 0);
45 
46 }
47 
48 GtkCssValue *
_gtk_style_provider_private_get_color(GtkStyleProviderPrivate * provider,const char * name)49 _gtk_style_provider_private_get_color (GtkStyleProviderPrivate *provider,
50                                        const char              *name)
51 {
52   GtkStyleProviderPrivateInterface *iface;
53 
54   /* for compat with gtk_symbolic_color_resolve() */
55   if (provider == NULL)
56     return NULL;
57 
58   gtk_internal_return_val_if_fail (GTK_IS_STYLE_PROVIDER_PRIVATE (provider), NULL);
59 
60   iface = GTK_STYLE_PROVIDER_PRIVATE_GET_INTERFACE (provider);
61 
62   if (!iface->get_color)
63     return NULL;
64 
65   return iface->get_color (provider, name);
66 }
67 
68 GtkCssKeyframes *
_gtk_style_provider_private_get_keyframes(GtkStyleProviderPrivate * provider,const char * name)69 _gtk_style_provider_private_get_keyframes (GtkStyleProviderPrivate *provider,
70                                            const char              *name)
71 {
72   GtkStyleProviderPrivateInterface *iface;
73 
74   gtk_internal_return_val_if_fail (GTK_IS_STYLE_PROVIDER_PRIVATE (provider), NULL);
75   gtk_internal_return_val_if_fail (name != NULL, NULL);
76 
77   iface = GTK_STYLE_PROVIDER_PRIVATE_GET_INTERFACE (provider);
78 
79   if (!iface->get_keyframes)
80     return NULL;
81 
82   return iface->get_keyframes (provider, name);
83 }
84 
85 void
_gtk_style_provider_private_lookup(GtkStyleProviderPrivate * provider,const GtkCssMatcher * matcher,GtkCssLookup * lookup,GtkCssChange * out_change)86 _gtk_style_provider_private_lookup (GtkStyleProviderPrivate *provider,
87                                     const GtkCssMatcher     *matcher,
88                                     GtkCssLookup            *lookup,
89                                     GtkCssChange            *out_change)
90 {
91   GtkStyleProviderPrivateInterface *iface;
92 
93   gtk_internal_return_if_fail (GTK_IS_STYLE_PROVIDER_PRIVATE (provider));
94   gtk_internal_return_if_fail (matcher != NULL);
95   gtk_internal_return_if_fail (lookup != NULL);
96 
97   if (out_change)
98     *out_change = 0;
99 
100   iface = GTK_STYLE_PROVIDER_PRIVATE_GET_INTERFACE (provider);
101 
102   if (!iface->lookup)
103     return;
104 
105   iface->lookup (provider, matcher, lookup, out_change);
106 }
107 
108 void
_gtk_style_provider_private_changed(GtkStyleProviderPrivate * provider)109 _gtk_style_provider_private_changed (GtkStyleProviderPrivate *provider)
110 {
111   gtk_internal_return_if_fail (GTK_IS_STYLE_PROVIDER_PRIVATE (provider));
112 
113   g_signal_emit (provider, signals[CHANGED], 0);
114 }
115 
116 GtkSettings *
_gtk_style_provider_private_get_settings(GtkStyleProviderPrivate * provider)117 _gtk_style_provider_private_get_settings (GtkStyleProviderPrivate *provider)
118 {
119   GtkStyleProviderPrivateInterface *iface;
120 
121   g_return_val_if_fail (GTK_IS_STYLE_PROVIDER_PRIVATE (provider), NULL);
122 
123   iface = GTK_STYLE_PROVIDER_PRIVATE_GET_INTERFACE (provider);
124 
125   if (!iface->get_settings)
126     return NULL;
127 
128   return iface->get_settings (provider);
129 }
130 
131 int
_gtk_style_provider_private_get_scale(GtkStyleProviderPrivate * provider)132 _gtk_style_provider_private_get_scale (GtkStyleProviderPrivate *provider)
133 {
134   GtkStyleProviderPrivateInterface *iface;
135 
136   gtk_internal_return_val_if_fail (GTK_IS_STYLE_PROVIDER_PRIVATE (provider), 1);
137 
138   iface = GTK_STYLE_PROVIDER_PRIVATE_GET_INTERFACE (provider);
139 
140   if (!iface->get_scale)
141     return 1;
142 
143   return iface->get_scale (provider);
144 }
145 
146 void
_gtk_style_provider_private_emit_error(GtkStyleProviderPrivate * provider,GtkCssSection * section,GError * error)147 _gtk_style_provider_private_emit_error (GtkStyleProviderPrivate *provider,
148                                         GtkCssSection           *section,
149                                         GError                  *error)
150 {
151   GtkStyleProviderPrivateInterface *iface;
152 
153   iface = GTK_STYLE_PROVIDER_PRIVATE_GET_INTERFACE (provider);
154 
155   if (iface->emit_error)
156     iface->emit_error (provider, section, error);
157 }
158