]> Pileus Git - ~andy/gtk/blob - gtk/gtkstyleprovider.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / gtk / gtkstyleprovider.c
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 "gtkstyleprovider.h"
21
22 #include "gtkintl.h"
23 #include "gtkprivate.h"
24 #include "gtkwidgetpath.h"
25
26 /**
27  * SECTION:gtkstyleprovider
28  * @Short_description: Interface to provide style information to GtkStyleContext
29  * @Title: GtkStyleProvider
30  * @See_also: #GtkStyleContext, #GtkCssProvider
31  *
32  * GtkStyleProvider is an interface used to provide style information to a #GtkStyleContext.
33  * See gtk_style_context_add_provider() and gtk_style_context_add_provider_for_screen().
34  */
35
36 static void gtk_style_provider_iface_init (gpointer g_iface);
37
38 GType
39 gtk_style_provider_get_type (void)
40 {
41   static GType style_provider_type = 0;
42
43   if (!style_provider_type)
44     style_provider_type = g_type_register_static_simple (G_TYPE_INTERFACE,
45                                                          I_("GtkStyleProvider"),
46                                                          sizeof (GtkStyleProviderIface),
47                                                          (GClassInitFunc) gtk_style_provider_iface_init,
48                                                          0, NULL, 0);
49   return style_provider_type;
50 }
51
52 static void
53 gtk_style_provider_iface_init (gpointer g_iface)
54 {
55 }
56
57 /**
58  * gtk_style_provider_get_style:
59  * @provider: a #GtkStyleProvider
60  * @path: #GtkWidgetPath to query
61  *
62  * Returns the style settings affecting a widget defined by @path, or %NULL if
63  * @provider doesn't contemplate styling @path.
64  *
65  * Returns: (transfer full): a #GtkStyleProperties containing the
66  * style settings affecting @path
67  *
68  * Since: 3.0
69  *
70  * Deprecated: 3.8: Will always return %NULL for all GTK-provided style providers
71  *     as the interface cannot correctly work the way CSS is specified.
72  **/
73 GtkStyleProperties *
74 gtk_style_provider_get_style (GtkStyleProvider *provider,
75                               GtkWidgetPath    *path)
76 {
77   GtkStyleProviderIface *iface;
78
79   g_return_val_if_fail (GTK_IS_STYLE_PROVIDER (provider), NULL);
80
81   iface = GTK_STYLE_PROVIDER_GET_IFACE (provider);
82
83   if (!iface->get_style)
84     return NULL;
85
86   return iface->get_style (provider, path);
87 }
88
89 /**
90  * gtk_style_provider_get_style_property:
91  * @provider: a #GtkStyleProvider
92  * @path: #GtkWidgetPath to query
93  * @state: state to query the style property for
94  * @pspec: The #GParamSpec to query
95  * @value: (out): return location for the property value
96  *
97  * Looks up a widget style property as defined by @provider for
98  * the widget represented by @path.
99  *
100  * Returns: %TRUE if the property was found and has a value, %FALSE otherwise
101  *
102  * Since: 3.0
103  **/
104 gboolean
105 gtk_style_provider_get_style_property (GtkStyleProvider *provider,
106                                        GtkWidgetPath    *path,
107                                        GtkStateFlags     state,
108                                        GParamSpec       *pspec,
109                                        GValue           *value)
110 {
111   GtkStyleProviderIface *iface;
112
113   g_return_val_if_fail (GTK_IS_STYLE_PROVIDER (provider), FALSE);
114   g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
115   g_return_val_if_fail (path != NULL, FALSE);
116   g_return_val_if_fail (g_type_is_a (gtk_widget_path_get_object_type (path), pspec->owner_type), FALSE);
117   g_return_val_if_fail (value != NULL, FALSE);
118
119   iface = GTK_STYLE_PROVIDER_GET_IFACE (provider);
120
121   if (!iface->get_style_property)
122     return FALSE;
123
124   return iface->get_style_property (provider, path, state, pspec, value);
125 }
126
127 /**
128  * gtk_style_provider_get_icon_factory:
129  * @provider: a #GtkStyleProvider
130  * @path: #GtkWidgetPath to query
131  *
132  * Returns the #GtkIconFactory defined to be in use for @path, or %NULL if none
133  * is defined.
134  *
135  * Returns: (transfer none): The icon factory to use for @path, or %NULL
136  *
137  * Since: 3.0
138  *
139  * Deprecated: 3.8: Will always return %NULL for all GTK-provided style providers.
140  **/
141 GtkIconFactory *
142 gtk_style_provider_get_icon_factory (GtkStyleProvider *provider,
143                                      GtkWidgetPath    *path)
144 {
145   GtkStyleProviderIface *iface;
146
147   g_return_val_if_fail (GTK_IS_STYLE_PROVIDER (provider), NULL);
148   g_return_val_if_fail (path != NULL, NULL);
149
150   iface = GTK_STYLE_PROVIDER_GET_IFACE (provider);
151
152   if (!iface->get_icon_factory)
153     return NULL;
154
155   return iface->get_icon_factory (provider, path);
156 }