1/* GTK - The GIMP Toolkit
2 * Copyright (C) 2010 Carlos Garnacho <carlosg@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 "gtkprivate.h"
24
25/**
26 * GtkStyleProvider:
27 *
28 * `GtkStyleProvider` is an interface for style information used by
29 * `GtkStyleContext`.
30 *
31 * See [method@Gtk.StyleContext.add_provider] and
32 * [func@Gtk.StyleContext.add_provider_for_display] for
33 * adding `GtkStyleProviders`.
34 *
35 * GTK uses the `GtkStyleProvider` implementation for CSS in
36 * [class@Gtk.CssProvider].
37 */
38
39enum {
40 CHANGED,
41 LAST_SIGNAL
42};
43
44G_DEFINE_INTERFACE (GtkStyleProvider, gtk_style_provider, G_TYPE_OBJECT)
45
46static guint signals[LAST_SIGNAL];
47
48static void
49gtk_style_provider_default_init (GtkStyleProviderInterface *iface)
50{
51 signals[CHANGED] = g_signal_new (I_("gtk-private-changed"),
52 G_TYPE_FROM_INTERFACE (iface),
53 signal_flags: G_SIGNAL_RUN_LAST,
54 G_STRUCT_OFFSET (GtkStyleProviderInterface, changed),
55 NULL, NULL,
56 NULL,
57 G_TYPE_NONE, n_params: 0);
58
59}
60
61GtkCssValue *
62gtk_style_provider_get_color (GtkStyleProvider *provider,
63 const char *name)
64{
65 GtkStyleProviderInterface *iface;
66
67 /* for compat with gtk_symbolic_color_resolve() */
68 if (provider == NULL)
69 return NULL;
70
71 gtk_internal_return_val_if_fail (GTK_IS_STYLE_PROVIDER (provider), NULL);
72
73 iface = GTK_STYLE_PROVIDER_GET_INTERFACE (provider);
74
75 if (!iface->get_color)
76 return NULL;
77
78 return iface->get_color (provider, name);
79}
80
81GtkCssKeyframes *
82gtk_style_provider_get_keyframes (GtkStyleProvider *provider,
83 const char *name)
84{
85 GtkStyleProviderInterface *iface;
86
87 gtk_internal_return_val_if_fail (GTK_IS_STYLE_PROVIDER (provider), NULL);
88 gtk_internal_return_val_if_fail (name != NULL, NULL);
89
90 iface = GTK_STYLE_PROVIDER_GET_INTERFACE (provider);
91
92 if (!iface->get_keyframes)
93 return NULL;
94
95 return iface->get_keyframes (provider, name);
96}
97
98void
99gtk_style_provider_lookup (GtkStyleProvider *provider,
100 const GtkCountingBloomFilter *filter,
101 GtkCssNode *node,
102 GtkCssLookup *lookup,
103 GtkCssChange *out_change)
104{
105 GtkStyleProviderInterface *iface;
106
107 gtk_internal_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
108 gtk_internal_return_if_fail (GTK_IS_CSS_NODE (node));
109 gtk_internal_return_if_fail (lookup != NULL);
110
111 if (out_change)
112 *out_change = 0;
113
114 iface = GTK_STYLE_PROVIDER_GET_INTERFACE (provider);
115
116 if (!iface->lookup)
117 return;
118
119 iface->lookup (provider, filter, node, lookup, out_change);
120}
121
122void
123gtk_style_provider_changed (GtkStyleProvider *provider)
124{
125 gtk_internal_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
126
127 g_signal_emit (instance: provider, signal_id: signals[CHANGED], detail: 0);
128}
129
130GtkSettings *
131gtk_style_provider_get_settings (GtkStyleProvider *provider)
132{
133 GtkStyleProviderInterface *iface;
134
135 gtk_internal_return_val_if_fail (GTK_IS_STYLE_PROVIDER (provider), NULL);
136
137 iface = GTK_STYLE_PROVIDER_GET_INTERFACE (provider);
138
139 if (!iface->get_settings)
140 return NULL;
141
142 return iface->get_settings (provider);
143}
144
145int
146gtk_style_provider_get_scale (GtkStyleProvider *provider)
147{
148 GtkStyleProviderInterface *iface;
149
150 gtk_internal_return_val_if_fail (GTK_IS_STYLE_PROVIDER (provider), 1);
151
152 iface = GTK_STYLE_PROVIDER_GET_INTERFACE (provider);
153
154 if (!iface->get_scale)
155 return 1;
156
157 return iface->get_scale (provider);
158}
159
160void
161gtk_style_provider_emit_error (GtkStyleProvider *provider,
162 GtkCssSection *section,
163 GError *error)
164{
165 GtkStyleProviderInterface *iface;
166
167 iface = GTK_STYLE_PROVIDER_GET_INTERFACE (provider);
168
169 if (iface->emit_error)
170 iface->emit_error (provider, section, error);
171}
172

source code of gtk/gtk/gtkstyleprovider.c