1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2010 Carlos Garnacho <carlosg@gnome.org>
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.
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.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
24 #include <gobject/gvaluecollector.h>
26 #include "gtkstylecontext.h"
27 #include "gtktypebuiltins.h"
28 #include "gtkthemingengine.h"
30 #include "gtkwidget.h"
31 #include "gtkwindow.h"
32 #include "gtkprivate.h"
33 #include "gtksymboliccolor.h"
34 #include "gtkanimationdescription.h"
35 #include "gtktimeline.h"
36 #include "gtkiconfactory.h"
39 * SECTION:gtkstylecontext
40 * @Short_description: Rendering UI elements
41 * @Title: GtkStyleContext
43 * #GtkStyleContext is an object that stores styling information affecting
44 * a widget defined by #GtkWidgetPath.
46 * In order to construct the final style information, #GtkStyleContext
47 * queries information from all attached #GtkStyleProviders. Style providers
48 * can be either attached explicitly to the context through
49 * gtk_style_context_add_provider(), or to the screen through
50 * gtk_style_context_add_provider_for_screen(). The resulting style is a
51 * combination of all provider's information in priority order.
53 * For GTK+ widgets, any #GtkStyleContext returned by
54 * gtk_widget_get_style_context() will already have a #GtkWidgetPath, a
55 * #GdkScreen and RTL/LTR information set, the style context will be also
56 * updated automatically if any of these settings change on the widget.
58 * If you are using are the theming layer standalone, you will need to set a
59 * widget path and a screen yourself to the created style context through
60 * gtk_style_context_set_path() and gtk_style_context_set_screen(), as well
61 * as updating the context yourself using gtk_style_context_invalidate()
62 * whenever any of the conditions change, such as a change in the
63 * #GtkSettings:gtk-theme-name setting or a hierarchy change in the rendered
66 * <refsect2 id="gtkstylecontext-animations">
67 * <title>Transition animations</title>
69 * #GtkStyleContext has built-in support for state change transitions.
70 * Note that these animations respect the #GtkSettings:gtk-enable-animations
74 * For simple widgets where state changes affect the whole widget area,
75 * calling gtk_style_context_notify_state_change() with a %NULL region
76 * is sufficient to trigger the transition animation. And GTK+ already
77 * does that when gtk_widget_set_state() or gtk_widget_set_state_flags()
81 * If a widget needs to declare several animatable regions (i.e. not
82 * affecting the whole widget area), its #GtkWidget::draw signal handler
83 * needs to wrap the render operations for the different regions with
84 * calls to gtk_style_context_push_animatable_region() and
85 * gtk_style_context_pop_animatable_region(). These functions take an
86 * identifier for the region which must be unique within the style context.
87 * For simple widgets with a fixed set of animatable regions, using an
88 * enumeration works well:
91 * <title>Using an enumeration to identify animatable regions</title>
102 * spin_button_draw (GtkWidget *widget,
105 * GtkStyleContext *context;
107 * context = gtk_widget_get_style_context (widget);
109 * gtk_style_context_push_animatable_region (context,
110 * GUINT_TO_POINTER (REGION_ENTRY));
112 * gtk_render_background (cr, 0, 0, 100, 30);
113 * gtk_render_frame (cr, 0, 0, 100, 30);
115 * gtk_style_context_pop_animatable_region (context);
122 * For complex widgets with an arbitrary number of animatable regions, it
123 * is up to the implementation to come up with a way to uniquely identify
124 * each animatable region. Using pointers to internal structs is one way
128 * <title>Using struct pointers to identify animatable regions</title>
131 * notebook_draw_tab (GtkWidget *widget,
132 * NotebookPage *page,
135 * gtk_style_context_push_animatable_region (context, page);
136 * gtk_render_extension (cr, page->x, page->y, page->width, page->height);
137 * gtk_style_context_pop_animatable_region (context);
142 * The widget also needs to notify the style context about a state change
143 * for a given animatable region so the animation is triggered.
146 * <title>Triggering a state change animation on a region</title>
149 * notebook_motion_notify (GtkWidget *widget,
150 * GdkEventMotion *event)
152 * GtkStyleContext *context;
153 * NotebookPage *page;
155 * context = gtk_widget_get_style_context (widget);
156 * page = find_page_under_pointer (widget, event);
157 * gtk_style_context_notify_state_change (context,
158 * gtk_widget_get_window (widget),
160 * GTK_STATE_PRELIGHT,
167 * gtk_style_context_notify_state_change() accepts %NULL region IDs as a
168 * special value, in this case, the whole widget area will be updated
172 * <refsect2 id="gtkstylecontext-classes">
173 * <title>Style classes and regions</title>
175 * Widgets can add style classes to their context, which can be used
176 * to associate different styles by class (see <xref linkend="gtkcssprovider-selectors"/>). Theme engines can also use style classes to vary their
177 * rendering. GTK+ has a number of predefined style classes:
182 * <entry>Style class</entry>
183 * <entry>Macro</entry>
184 * <entry>Used by</entry>
189 * <entry>button</entry>
190 * <entry>GTK_STYLE_CLASS_BUTTON</entry>
191 * <entry>#GtkButton, #GtkToggleButton, #GtkRadioButton, #GtkCheckButton</entry>
194 * <entry>default</entry>
195 * <entry>GTK_STYLE_CLASS_DEFAULT</entry>
196 * <entry>#GtkButton</entry>
199 * <entry>check</entry>
200 * <entry>GTK_STYLE_CLASS_CHECK</entry>
201 * <entry>#GtkCheckButton, #GtkCheckMenuItem, #GtkCellRendererToggle</entry>
204 * <entry>radio</entry>
205 * <entry>GTK_STYLE_CLASS_RADIO</entry>
206 * <entry>#GtkRadioButton, #GtkRadioMenuItem, #GtkCellRendererToggle</entry>
209 * <entry>arrow</entry>
210 * <entry>GTK_STYLE_CLASS_ARROW</entry>
211 * <entry>#GtkArrow</entry>
214 * <entry>calendar</entry>
215 * <entry>GTK_STYLE_CLASS_CALENDAR</entry>
216 * <entry>#GtkCalendar</entry>
219 * <entry>entry</entry>
220 * <entry>GTK_STYLE_CLASS_ENTRY</entry>
221 * <entry>#GtkEntry</entry>
224 * <entry>cell</entry>
225 * <entry>GTK_STYLE_CLASS_CELL</entry>
226 * <entry>#GtkCellRendererToggle</entry>
229 * <entry>menu</entry>
230 * <entry>GTK_STYLE_CLASS_MENU</entry>
231 * <entry>#GtkMenu, #GtkMenuItem, #GtkCheckMenuItem, #GtkRadioMenuItem</entry>
234 * <entry>expander</entry>
235 * <entry>GTK_STYLE_CLASS_EXPANDER</entry>
236 * <entry>#GtkExpander</entry>
239 * <entry>tooltip</entry>
240 * <entry>GTK_STYLE_CLASS_TOOLTIP</entry>
241 * <entry>#GtkTooltip</entry>
244 * <entry>frame</entry>
245 * <entry>GTK_STYLE_CLASS_FRAME</entry>
246 * <entry>#GtkFrame</entry>
249 * <entry>scrolled-window</entry>
251 * <entry>#GtkScrolledWindow</entry>
254 * <entry>viewport</entry>
256 * <entry>#GtkViewport</entry>
259 * <entry>trough</entry>
260 * <entry>GTK_STYLE_CLASS_TROUGH</entry>
261 * <entry>#GtkScrollbar, #GtkProgressBar, #GtkScale</entry>
264 * <entry>progressbar</entry>
265 * <entry>GTK_STYLE_CLASS_PROGRESSBAR</entry>
266 * <entry>#GtkProgressBar, #GtkCellRendererProgress</entry>
269 * <entry>slider</entry>
270 * <entry>GTK_STYLE_CLASS_SLIDER</entry>
271 * <entry>#GtkScrollbar, #GtkScale</entry>
274 * <entry>menuitem</entry>
275 * <entry>GTK_STYLE_CLASS_MENUITEM</entry>
276 * <entry>#GtkMenuItem</entry>
279 * <entry>popup</entry>
281 * <entry>#GtkMenu</entry>
284 * <entry>accelerator</entry>
285 * <entry>GTK_STYLE_CLASS_ACCELERATOR</entry>
286 * <entry>#GtkAccelLabel</entry>
289 * <entry>menubar</entry>
290 * <entry>GTK_STYLE_CLASS_MENUBAR</entry>
291 * <entry>#GtkMenuBar</entry>
294 * <entry>toolbar</entry>
295 * <entry>GTK_STYLE_CLASS_TOOLBAR</entry>
296 * <entry>#GtkToolbar</entry>
299 * <entry>dock</entry>
300 * <entry>GTK_STYLE_CLASS_DOCK</entry>
301 * <entry>#GtkHandleBox</entry>
304 * <entry>notebook</entry>
306 * <entry>#GtkNotebook</entry>
309 * <entry>background</entry>
310 * <entry>GTK_STYLE_CLASS_BACKGROUND</entry>
311 * <entry>#GtkWindow</entry>
314 * <entry>rubberband</entry>
315 * <entry>GTK_STYLE_CLASS_RUBBERBAND</entry>
319 * <entry>header</entry>
320 * <entry>GTK_STYLE_CLASS_HEADER</entry>
324 * <entry>grip</entry>
325 * <entry>GTK_STYLE_CLASS_GRIP</entry>
326 * <entry>#GtkWindow</entry>
329 * <entry>spinner</entry>
330 * <entry>GTK_STYLE_CLASS_SPINNER</entry>
331 * <entry>#GtkSpinner</entry>
338 * Widgets can also add regions with flags to their context.
339 * The regions used by GTK+ widgets are:
344 * <entry>Region</entry>
345 * <entry>Flags</entry>
346 * <entry>Macro</entry>
347 * <entry>Used by</entry>
353 * <entry>even, odd</entry>
354 * <entry>GTK_STYLE_REGION_ROW</entry>
355 * <entry>#GtkTreeView</entry>
358 * <entry>column</entry>
359 * <entry>first, last, sorted</entry>
360 * <entry>GTK_STYLE_REGION_COLUMN</entry>
361 * <entry>#GtkTreeView</entry>
364 * <entry>column-header</entry>
366 * <entry>GTK_STYLE_REGION_COLUMN_HEADER</entry>
371 * <entry>even, odd, first, last</entry>
372 * <entry>GTK_STYLE_REGION_TAB</entry>
373 * <entry>#GtkNotebook</entry>
380 * <refsect2 id="gtkstylecontext-custom-styling">
381 * <title>Custom styling in UI libraries and applications</title>
383 * If you are developing a library with custom #GtkWidget<!-- -->s that
384 * render differently than standard components, you may need to add a
385 * #GtkStyleProvider yourself with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK
386 * priority, either a #GtkCssProvider or a custom object implementing the
387 * #GtkStyleProvider interface. This way theming engines may still attempt
388 * to style your UI elements in a different way if needed so.
391 * If you are using custom styling on an applications, you probably want then
392 * to make your style information prevail to the theme's, so you must use
393 * a #GtkStyleProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
394 * priority, keep in mind that the user settings in
395 * <filename><replaceable>XDG_CONFIG_HOME</replaceable>/gtk-3.0/gtk.css</filename> will
396 * still take precedence over your changes, as it uses the
397 * %GTK_STYLE_PROVIDER_PRIORITY_USER priority.
400 * If a custom theming engine is needed, you probably want to implement a
401 * #GtkStyleProvider yourself so it points to your #GtkThemingEngine
402 * implementation, as #GtkCssProvider uses gtk_theming_engine_load()
403 * which loads the theming engine module from the standard paths.
408 typedef struct GtkStyleContextPrivate GtkStyleContextPrivate;
409 typedef struct GtkStyleProviderData GtkStyleProviderData;
410 typedef struct GtkStyleInfo GtkStyleInfo;
411 typedef struct GtkRegion GtkRegion;
412 typedef struct PropertyValue PropertyValue;
413 typedef struct AnimationInfo AnimationInfo;
414 typedef struct StyleData StyleData;
419 GtkRegionFlags flags;
422 struct GtkStyleProviderData
424 GtkStyleProvider *provider;
438 GArray *style_classes;
440 GtkJunctionSides junction_sides;
441 GtkStateFlags state_flags;
446 GtkStyleProperties *store;
447 GSList *icon_factories;
448 GArray *property_cache;
453 GtkTimeline *timeline;
458 gboolean target_value;
460 cairo_region_t *invalidation_region;
464 struct GtkStyleContextPrivate
469 GList *providers_last;
471 GtkWidgetPath *widget_path;
472 GHashTable *style_data;
474 StyleData *current_data;
476 GSList *animation_regions;
479 guint animations_invalidated : 1;
480 guint invalidating_context : 1;
482 GtkThemingEngine *theming_engine;
484 GtkTextDirection direction;
498 guint signals[LAST_SIGNAL] = { 0 };
500 static GQuark provider_list_quark = 0;
502 static void gtk_style_context_finalize (GObject *object);
504 static void gtk_style_context_impl_set_property (GObject *object,
508 static void gtk_style_context_impl_get_property (GObject *object,
514 G_DEFINE_TYPE (GtkStyleContext, gtk_style_context, G_TYPE_OBJECT)
517 gtk_style_context_class_init (GtkStyleContextClass *klass)
519 GObjectClass *object_class = G_OBJECT_CLASS (klass);
521 object_class->finalize = gtk_style_context_finalize;
522 object_class->set_property = gtk_style_context_impl_set_property;
523 object_class->get_property = gtk_style_context_impl_get_property;
526 g_signal_new (I_("changed"),
527 G_TYPE_FROM_CLASS (object_class),
529 G_STRUCT_OFFSET (GtkStyleContextClass, changed),
531 g_cclosure_marshal_VOID__VOID,
534 g_object_class_install_property (object_class,
536 g_param_spec_object ("screen",
538 P_("The associated GdkScreen"),
540 GTK_PARAM_READWRITE));
541 g_object_class_install_property (object_class,
543 g_param_spec_enum ("direction",
545 P_("Text direction"),
546 GTK_TYPE_TEXT_DIRECTION,
548 GTK_PARAM_READWRITE));
550 g_type_class_add_private (object_class, sizeof (GtkStyleContextPrivate));
553 static GtkStyleInfo *
554 style_info_new (void)
558 info = g_slice_new0 (GtkStyleInfo);
559 info->style_classes = g_array_new (FALSE, FALSE, sizeof (GQuark));
560 info->regions = g_array_new (FALSE, FALSE, sizeof (GtkRegion));
566 style_info_free (GtkStyleInfo *info)
568 g_array_free (info->style_classes, TRUE);
569 g_array_free (info->regions, TRUE);
570 g_slice_free (GtkStyleInfo, info);
573 static GtkStyleInfo *
574 style_info_copy (const GtkStyleInfo *info)
578 copy = style_info_new ();
579 g_array_insert_vals (copy->style_classes, 0,
580 info->style_classes->data,
581 info->style_classes->len);
583 g_array_insert_vals (copy->regions, 0,
587 copy->junction_sides = info->junction_sides;
588 copy->state_flags = info->state_flags;
594 style_info_hash (gconstpointer elem)
596 const GtkStyleInfo *info;
601 for (i = 0; i < info->style_classes->len; i++)
603 hash += g_array_index (info->style_classes, GQuark, i);
607 for (i = 0; i < info->regions->len; i++)
611 region = &g_array_index (info->regions, GtkRegion, i);
612 hash += region->class_quark;
613 hash += region->flags;
621 style_info_equal (gconstpointer elem1,
624 const GtkStyleInfo *info1, *info2;
629 if (info1->junction_sides != info2->junction_sides)
632 if (info1->style_classes->len != info2->style_classes->len)
635 if (memcmp (info1->style_classes->data,
636 info2->style_classes->data,
637 info1->style_classes->len * sizeof (GQuark)) != 0)
640 if (info1->regions->len != info2->regions->len)
643 if (memcmp (info1->regions->data,
644 info2->regions->data,
645 info1->regions->len * sizeof (GtkRegion)) != 0)
652 style_data_new (void)
656 data = g_slice_new0 (StyleData);
657 data->store = gtk_style_properties_new ();
663 clear_property_cache (StyleData *data)
667 if (!data->property_cache)
670 for (i = 0; i < data->property_cache->len; i++)
672 PropertyValue *node = &g_array_index (data->property_cache, PropertyValue, i);
674 g_param_spec_unref (node->pspec);
675 g_value_unset (&node->value);
678 g_array_free (data->property_cache, TRUE);
679 data->property_cache = NULL;
683 style_data_free (StyleData *data)
685 g_object_unref (data->store);
686 clear_property_cache (data);
688 g_slist_foreach (data->icon_factories, (GFunc) g_object_unref, NULL);
689 g_slist_free (data->icon_factories);
691 g_slice_free (StyleData, data);
695 gtk_style_context_init (GtkStyleContext *style_context)
697 GtkStyleContextPrivate *priv;
700 priv = style_context->priv = G_TYPE_INSTANCE_GET_PRIVATE (style_context,
701 GTK_TYPE_STYLE_CONTEXT,
702 GtkStyleContextPrivate);
704 priv->style_data = g_hash_table_new_full (style_info_hash,
706 (GDestroyNotify) style_info_free,
707 (GDestroyNotify) style_data_free);
708 priv->theming_engine = g_object_ref ((gpointer) gtk_theming_engine_load (NULL));
710 priv->direction = GTK_TEXT_DIR_RTL;
712 priv->screen = gdk_screen_get_default ();
714 /* Create default info store */
715 info = style_info_new ();
716 priv->info_stack = g_slist_prepend (priv->info_stack, info);
719 static GtkStyleProviderData *
720 style_provider_data_new (GtkStyleProvider *provider,
723 GtkStyleProviderData *data;
725 data = g_slice_new (GtkStyleProviderData);
726 data->provider = g_object_ref (provider);
727 data->priority = priority;
733 style_provider_data_free (GtkStyleProviderData *data)
735 g_object_unref (data->provider);
736 g_slice_free (GtkStyleProviderData, data);
740 animation_info_free (AnimationInfo *info)
742 g_object_unref (info->timeline);
743 g_object_unref (info->window);
745 if (info->invalidation_region)
746 cairo_region_destroy (info->invalidation_region);
748 g_array_free (info->rectangles, TRUE);
749 g_slice_free (AnimationInfo, info);
752 static AnimationInfo *
753 animation_info_lookup_by_timeline (GtkStyleContext *context,
754 GtkTimeline *timeline)
756 GtkStyleContextPrivate *priv;
760 priv = context->priv;
762 for (l = priv->animations; l; l = l->next)
766 if (info->timeline == timeline)
774 timeline_frame_cb (GtkTimeline *timeline,
778 GtkStyleContextPrivate *priv;
779 GtkStyleContext *context;
783 priv = context->priv;
784 info = animation_info_lookup_by_timeline (context, timeline);
786 g_assert (info != NULL);
788 /* Cancel transition if window is gone */
789 if (gdk_window_is_destroyed (info->window) ||
790 !gdk_window_is_visible (info->window))
792 priv->animations = g_slist_remove (priv->animations, info);
793 animation_info_free (info);
797 if (info->invalidation_region &&
798 !cairo_region_is_empty (info->invalidation_region))
799 gdk_window_invalidate_region (info->window, info->invalidation_region, TRUE);
801 gdk_window_invalidate_rect (info->window, NULL, TRUE);
805 timeline_finished_cb (GtkTimeline *timeline,
808 GtkStyleContextPrivate *priv;
809 GtkStyleContext *context;
813 priv = context->priv;
814 info = animation_info_lookup_by_timeline (context, timeline);
816 g_assert (info != NULL);
818 priv->animations = g_slist_remove (priv->animations, info);
820 /* Invalidate one last time the area, so the final content is painted */
821 if (info->invalidation_region &&
822 !cairo_region_is_empty (info->invalidation_region))
823 gdk_window_invalidate_region (info->window, info->invalidation_region, TRUE);
825 gdk_window_invalidate_rect (info->window, NULL, TRUE);
827 animation_info_free (info);
830 static AnimationInfo *
831 animation_info_new (GtkStyleContext *context,
834 GtkTimelineProgressType progress_type,
837 gboolean target_value,
842 info = g_slice_new0 (AnimationInfo);
844 info->rectangles = g_array_new (FALSE, FALSE, sizeof (cairo_rectangle_int_t));
845 info->timeline = gtk_timeline_new (duration);
846 info->window = g_object_ref (window);
848 info->target_value = target_value;
849 info->region_id = region_id;
851 gtk_timeline_set_progress_type (info->timeline, progress_type);
852 gtk_timeline_set_loop (info->timeline, loop);
854 if (!loop && !target_value)
856 gtk_timeline_set_direction (info->timeline, GTK_TIMELINE_DIRECTION_BACKWARD);
857 gtk_timeline_rewind (info->timeline);
860 g_signal_connect (info->timeline, "frame",
861 G_CALLBACK (timeline_frame_cb), context);
862 g_signal_connect (info->timeline, "finished",
863 G_CALLBACK (timeline_finished_cb), context);
865 gtk_timeline_start (info->timeline);
870 static AnimationInfo *
871 animation_info_lookup (GtkStyleContext *context,
875 GtkStyleContextPrivate *priv;
878 priv = context->priv;
880 for (l = priv->animations; l; l = l->next)
886 if (info->state == state &&
887 info->region_id == region_id)
895 gtk_style_context_finalize (GObject *object)
897 GtkStyleContextPrivate *priv;
898 GtkStyleContext *style_context;
901 style_context = GTK_STYLE_CONTEXT (object);
902 priv = style_context->priv;
904 if (priv->widget_path)
905 gtk_widget_path_free (priv->widget_path);
907 g_hash_table_destroy (priv->style_data);
909 g_list_foreach (priv->providers, (GFunc) style_provider_data_free, NULL);
910 g_list_free (priv->providers);
912 g_slist_foreach (priv->info_stack, (GFunc) style_info_free, NULL);
913 g_slist_free (priv->info_stack);
915 g_slist_free (priv->animation_regions);
917 for (l = priv->animations; l; l = l->next)
918 animation_info_free ((AnimationInfo *) l->data);
920 g_slist_free (priv->animations);
922 if (priv->theming_engine)
923 g_object_unref (priv->theming_engine);
925 G_OBJECT_CLASS (gtk_style_context_parent_class)->finalize (object);
929 gtk_style_context_impl_set_property (GObject *object,
934 GtkStyleContextPrivate *priv;
935 GtkStyleContext *style_context;
937 style_context = GTK_STYLE_CONTEXT (object);
938 priv = style_context->priv;
943 gtk_style_context_set_screen (style_context,
944 g_value_get_object (value));
947 gtk_style_context_set_direction (style_context,
948 g_value_get_enum (value));
951 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
957 gtk_style_context_impl_get_property (GObject *object,
962 GtkStyleContextPrivate *priv;
963 GtkStyleContext *style_context;
965 style_context = GTK_STYLE_CONTEXT (object);
966 priv = style_context->priv;
971 g_value_set_object (value, priv->screen);
974 g_value_set_enum (value, priv->direction);
977 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
983 find_next_candidate (GList *local,
989 GtkStyleProviderData *local_data, *global_data;
991 local_data = local->data;
992 global_data = global->data;
994 if (local_data->priority < global_data->priority)
995 return (ascending) ? local : global;
997 return (ascending) ? global : local;
1008 build_properties (GtkStyleContext *context,
1009 StyleData *style_data,
1010 GtkWidgetPath *path)
1012 GtkStyleContextPrivate *priv;
1013 GList *elem, *list, *global_list = NULL;
1015 priv = context->priv;
1016 list = priv->providers;
1019 global_list = g_object_get_qdata (G_OBJECT (priv->screen), provider_list_quark);
1021 while ((elem = find_next_candidate (list, global_list, TRUE)) != NULL)
1023 GtkStyleProviderData *data;
1024 GtkStyleProperties *provider_style;
1031 global_list = global_list->next;
1033 provider_style = gtk_style_provider_get_style (data->provider, path);
1037 gtk_style_properties_merge (style_data->store, provider_style, TRUE);
1038 g_object_unref (provider_style);
1044 build_icon_factories (GtkStyleContext *context,
1045 StyleData *style_data,
1046 GtkWidgetPath *path)
1048 GtkStyleContextPrivate *priv;
1049 GList *elem, *list, *global_list = NULL;
1051 priv = context->priv;
1052 list = priv->providers_last;
1056 global_list = g_object_get_qdata (G_OBJECT (priv->screen), provider_list_quark);
1057 global_list = g_list_last (global_list);
1060 while ((elem = find_next_candidate (list, global_list, FALSE)) != NULL)
1062 GtkIconFactory *factory;
1063 GtkStyleProviderData *data;
1070 global_list = global_list->prev;
1072 factory = gtk_style_provider_get_icon_factory (data->provider, path);
1075 style_data->icon_factories = g_slist_prepend (style_data->icon_factories, factory);
1080 create_query_path (GtkStyleContext *context)
1082 GtkStyleContextPrivate *priv;
1083 GtkWidgetPath *path;
1087 priv = context->priv;
1088 path = gtk_widget_path_copy (priv->widget_path);
1089 pos = gtk_widget_path_length (path) - 1;
1091 info = priv->info_stack->data;
1093 /* Set widget regions */
1094 for (i = 0; i < info->regions->len; i++)
1098 region = &g_array_index (info->regions, GtkRegion, i);
1099 gtk_widget_path_iter_add_region (path, pos,
1100 g_quark_to_string (region->class_quark),
1104 /* Set widget classes */
1105 for (i = 0; i < info->style_classes->len; i++)
1109 quark = g_array_index (info->style_classes, GQuark, i);
1110 gtk_widget_path_iter_add_class (path, pos,
1111 g_quark_to_string (quark));
1118 style_data_lookup (GtkStyleContext *context)
1120 GtkStyleContextPrivate *priv;
1123 priv = context->priv;
1125 /* Current data in use is cached, just return it */
1126 if (priv->current_data)
1127 return priv->current_data;
1129 g_assert (priv->widget_path != NULL);
1131 data = g_hash_table_lookup (priv->style_data, priv->info_stack->data);
1135 GtkWidgetPath *path;
1137 data = style_data_new ();
1138 path = create_query_path (context);
1140 build_properties (context, data, path);
1141 build_icon_factories (context, data, path);
1143 g_hash_table_insert (priv->style_data,
1144 style_info_copy (priv->info_stack->data),
1147 gtk_widget_path_free (path);
1150 priv->current_data = data;
1152 if (priv->theming_engine)
1153 g_object_unref (priv->theming_engine);
1155 gtk_style_properties_get (data->store, 0,
1156 "engine", &priv->theming_engine,
1162 style_provider_add (GList **list,
1163 GtkStyleProvider *provider,
1166 GtkStyleProviderData *new_data;
1167 gboolean added = FALSE;
1170 new_data = style_provider_data_new (provider, priority);
1174 GtkStyleProviderData *data;
1178 /* Provider was already attached to the style
1179 * context, remove in order to add the new data
1181 if (data->provider == provider)
1188 /* Remove and free link */
1189 *list = g_list_remove_link (*list, link);
1190 style_provider_data_free (link->data);
1191 g_list_free_1 (link);
1197 data->priority > priority)
1199 *list = g_list_insert_before (*list, l, new_data);
1207 *list = g_list_append (*list, new_data);
1211 style_provider_remove (GList **list,
1212 GtkStyleProvider *provider)
1218 GtkStyleProviderData *data;
1222 if (data->provider == provider)
1224 *list = g_list_remove_link (*list, l);
1225 style_provider_data_free (l->data);
1238 * gtk_style_context_new:
1240 * Creates a standalone #GtkStyleContext, this style context
1241 * won't be attached to any widget, so you may want
1242 * to call gtk_style_context_set_path() yourself.
1245 * This function is only useful when using the theming layer
1246 * separated from GTK+, if you are using #GtkStyleContext to
1247 * theme #GtkWidget<!-- -->s, use gtk_widget_get_style_context()
1248 * in order to get a style context ready to theme the widget.
1251 * Returns: A newly created #GtkStyleContext.
1254 gtk_style_context_new (void)
1256 return g_object_new (GTK_TYPE_STYLE_CONTEXT, NULL);
1260 * gtk_style_context_add_provider:
1261 * @context: a #GtkStyleContext
1262 * @provider: a #GtkStyleProvider
1263 * @priority: the priority of the style provider. The lower
1264 * it is, the earlier it will be used in the style
1265 * construction. Typically this will be in the range
1266 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1267 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1269 * Adds a style provider to @context, to be used in style construction.
1274 gtk_style_context_add_provider (GtkStyleContext *context,
1275 GtkStyleProvider *provider,
1278 GtkStyleContextPrivate *priv;
1280 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1281 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1283 priv = context->priv;
1284 style_provider_add (&priv->providers, provider, priority);
1285 priv->providers_last = g_list_last (priv->providers);
1287 gtk_style_context_invalidate (context);
1291 * gtk_style_context_remove_provider:
1292 * @context: a #GtkStyleContext
1293 * @provider: a #GtkStyleProvider
1295 * Removes @provider from the style providers list in @context.
1300 gtk_style_context_remove_provider (GtkStyleContext *context,
1301 GtkStyleProvider *provider)
1303 GtkStyleContextPrivate *priv;
1305 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1306 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1308 priv = context->priv;
1310 if (style_provider_remove (&priv->providers, provider))
1312 priv->providers_last = g_list_last (priv->providers);
1314 gtk_style_context_invalidate (context);
1319 * gtk_style_context_reset_widgets:
1320 * @screen: a #GdkScreen
1322 * This function recomputes the styles for all widgets under a particular
1323 * #GdkScreen. This is useful when some global parameter has changed that
1324 * affects the appearance of all widgets, because when a widget gets a new
1325 * style, it will both redraw and recompute any cached information about
1326 * its appearance. As an example, it is used when the color scheme changes
1327 * in the related #GtkSettings object.
1332 gtk_style_context_reset_widgets (GdkScreen *screen)
1334 GList *list, *toplevels;
1336 _gtk_icon_set_invalidate_caches ();
1338 toplevels = gtk_window_list_toplevels ();
1339 g_list_foreach (toplevels, (GFunc) g_object_ref, NULL);
1341 for (list = toplevels; list; list = list->next)
1343 if (gtk_widget_get_screen (list->data) == screen)
1344 gtk_widget_reset_style (list->data);
1346 g_object_unref (list->data);
1349 g_list_free (toplevels);
1353 * gtk_style_context_add_provider_for_screen:
1354 * @screen: a #GdkScreen
1355 * @provider: a #GtkStyleProvider
1356 * @priority: the priority of the style provider. The lower
1357 * it is, the earlier it will be used in the style
1358 * construction. Typically this will be in the range
1359 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1360 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1362 * Adds a global style provider to @screen, which will be used
1363 * in style construction for all #GtkStyleContext<!-- -->s under
1366 * GTK+ uses this to make styling information from #GtkSettings
1372 gtk_style_context_add_provider_for_screen (GdkScreen *screen,
1373 GtkStyleProvider *provider,
1376 GList *providers, *list;
1378 g_return_if_fail (GDK_IS_SCREEN (screen));
1379 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1381 if (G_UNLIKELY (!provider_list_quark))
1382 provider_list_quark = g_quark_from_static_string ("gtk-provider-list-quark");
1384 list = providers = g_object_get_qdata (G_OBJECT (screen), provider_list_quark);
1385 style_provider_add (&list, provider, priority);
1387 if (list != providers)
1388 g_object_set_qdata (G_OBJECT (screen), provider_list_quark, list);
1390 gtk_style_context_reset_widgets (screen);
1394 * gtk_style_context_remove_provider_for_screen:
1395 * @screen: a #GdkScreen
1396 * @provider: a #GtkStyleProvider
1398 * Removes @provider from the global style providers list in @screen.
1403 gtk_style_context_remove_provider_for_screen (GdkScreen *screen,
1404 GtkStyleProvider *provider)
1406 GList *providers, *list;
1408 g_return_if_fail (GDK_IS_SCREEN (screen));
1409 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1411 if (G_UNLIKELY (!provider_list_quark))
1414 list = providers = g_object_get_qdata (G_OBJECT (screen), provider_list_quark);
1416 if (style_provider_remove (&list, provider))
1418 if (list != providers)
1419 g_object_set_qdata (G_OBJECT (screen), provider_list_quark, list);
1421 gtk_style_context_reset_widgets (screen);
1426 * gtk_style_context_get_property:
1427 * @context: a #GtkStyleContext
1428 * @property: style property name
1429 * @state: state to retrieve the property value for
1430 * @value: (out) (transfer full): return location for the style property value
1432 * Gets a style property from @context for the given state.
1434 * When @value is no longer needed, g_value_unset() must be called
1435 * to free any allocated memory.
1440 gtk_style_context_get_property (GtkStyleContext *context,
1441 const gchar *property,
1442 GtkStateFlags state,
1445 GtkStyleContextPrivate *priv;
1448 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1449 g_return_if_fail (property != NULL);
1450 g_return_if_fail (value != NULL);
1452 priv = context->priv;
1454 g_return_if_fail (priv->widget_path != NULL);
1456 data = style_data_lookup (context);
1457 gtk_style_properties_get_property (data->store, property, state, value);
1461 * gtk_style_context_get_valist:
1462 * @context: a #GtkStyleContext
1463 * @state: state to retrieve the property values for
1464 * @args: va_list of property name/return location pairs, followed by %NULL
1466 * Retrieves several style property values from @context for a given state.
1471 gtk_style_context_get_valist (GtkStyleContext *context,
1472 GtkStateFlags state,
1475 GtkStyleContextPrivate *priv;
1478 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1480 priv = context->priv;
1481 g_return_if_fail (priv->widget_path != NULL);
1483 data = style_data_lookup (context);
1484 gtk_style_properties_get_valist (data->store, state, args);
1488 * gtk_style_context_get:
1489 * @context: a #GtkStyleContext
1490 * @state: state to retrieve the property values for
1491 * @...: property name /return value pairs, followed by %NULL
1493 * Retrieves several style property values from @context for a
1499 gtk_style_context_get (GtkStyleContext *context,
1500 GtkStateFlags state,
1503 GtkStyleContextPrivate *priv;
1507 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1509 priv = context->priv;
1510 g_return_if_fail (priv->widget_path != NULL);
1512 data = style_data_lookup (context);
1514 va_start (args, state);
1515 gtk_style_properties_get_valist (data->store, state, args);
1520 * gtk_style_context_set_state:
1521 * @context: a #GtkStyleContext
1522 * @flags: state to represent
1524 * Sets the state to be used when rendering with any
1525 * of the gtk_render_*() functions.
1530 gtk_style_context_set_state (GtkStyleContext *context,
1531 GtkStateFlags flags)
1533 GtkStyleContextPrivate *priv;
1536 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1538 priv = context->priv;
1539 info = priv->info_stack->data;
1540 info->state_flags = flags;
1544 * gtk_style_context_get_state:
1545 * @context: a #GtkStyleContext
1547 * Returns the state used when rendering.
1549 * Returns: the state flags
1554 gtk_style_context_get_state (GtkStyleContext *context)
1556 GtkStyleContextPrivate *priv;
1559 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
1561 priv = context->priv;
1562 info = priv->info_stack->data;
1564 return info->state_flags;
1568 context_has_animatable_region (GtkStyleContext *context,
1571 GtkStyleContextPrivate *priv;
1574 /* NULL region_id means everything
1575 * rendered through the style context
1580 priv = context->priv;
1582 for (r = priv->animation_regions; r; r = r->next)
1584 if (r->data == region_id)
1592 * gtk_style_context_state_is_running:
1593 * @context: a #GtkStyleContext
1594 * @state: a widget state
1595 * @progress: (out): return location for the transition progress
1597 * Returns %TRUE if there is a transition animation running for the
1598 * current region (see gtk_style_context_push_animatable_region()).
1600 * If @progress is not %NULL, the animation progress will be returned
1601 * there, 0.0 means the state is closest to being unset, while 1.0 means
1602 * it's closest to being set. This means transition animation will
1603 * run from 0 to 1 when @state is being set and from 1 to 0 when
1606 * Returns: %TRUE if there is a running transition animation for @state.
1611 gtk_style_context_state_is_running (GtkStyleContext *context,
1615 GtkStyleContextPrivate *priv;
1616 AnimationInfo *info;
1619 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1621 priv = context->priv;
1623 for (l = priv->animations; l; l = l->next)
1627 if (info->state == state &&
1628 context_has_animatable_region (context, info->region_id))
1631 *progress = gtk_timeline_get_progress (info->timeline);
1641 * gtk_style_context_set_path:
1642 * @context: a #GtkStyleContext
1643 * @path: a #GtkWidgetPath
1645 * Sets the #GtkWidgetPath used for style matching. As a
1646 * consequence, the style will be regenerated to match
1647 * the new given path.
1649 * If you are using a #GtkStyleContext returned from
1650 * gtk_widget_get_style_context(), you do not need to call
1656 gtk_style_context_set_path (GtkStyleContext *context,
1657 GtkWidgetPath *path)
1659 GtkStyleContextPrivate *priv;
1661 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1662 g_return_if_fail (path != NULL);
1664 priv = context->priv;
1666 if (priv->widget_path)
1668 gtk_widget_path_free (priv->widget_path);
1669 priv->widget_path = NULL;
1673 priv->widget_path = gtk_widget_path_copy (path);
1675 gtk_style_context_invalidate (context);
1679 * gtk_style_context_get_path:
1680 * @context: a #GtkStyleContext
1682 * Returns the widget path used for style matching.
1684 * Returns: (transfer none): A #GtkWidgetPath
1688 G_CONST_RETURN GtkWidgetPath *
1689 gtk_style_context_get_path (GtkStyleContext *context)
1691 GtkStyleContextPrivate *priv;
1693 priv = context->priv;
1694 return priv->widget_path;
1698 * gtk_style_context_save:
1699 * @context: a #GtkStyleContext
1701 * Saves the @context state, so all modifications done through
1702 * gtk_style_context_add_class(), gtk_style_context_remove_class(),
1703 * gtk_style_context_add_region(), gtk_style_context_remove_region()
1704 * or gtk_style_context_set_junction_sides() can be reverted in one
1705 * go through gtk_style_context_restore().
1710 gtk_style_context_save (GtkStyleContext *context)
1712 GtkStyleContextPrivate *priv;
1715 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1717 priv = context->priv;
1719 g_assert (priv->info_stack != NULL);
1721 info = style_info_copy (priv->info_stack->data);
1722 priv->info_stack = g_slist_prepend (priv->info_stack, info);
1726 * gtk_style_context_restore:
1727 * @context: a #GtkStyleContext
1729 * Restores @context state to a previous stage.
1730 * See gtk_style_context_save().
1735 gtk_style_context_restore (GtkStyleContext *context)
1737 GtkStyleContextPrivate *priv;
1740 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1742 priv = context->priv;
1744 if (priv->info_stack)
1746 info = priv->info_stack->data;
1747 priv->info_stack = g_slist_remove (priv->info_stack, info);
1748 style_info_free (info);
1751 if (!priv->info_stack)
1753 g_warning ("Unpaired gtk_style_context_restore() call");
1755 /* Create default region */
1756 info = style_info_new ();
1757 priv->info_stack = g_slist_prepend (priv->info_stack, info);
1760 priv->current_data = NULL;
1764 style_class_find (GArray *array,
1769 gboolean found = FALSE;
1775 if (!array || array->len == 0)
1779 max = array->len - 1;
1785 mid = (min + max) / 2;
1786 item = g_array_index (array, GQuark, mid);
1788 if (class_quark == item)
1793 else if (class_quark > item)
1794 min = pos = mid + 1;
1801 while (!found && min <= max);
1810 region_find (GArray *array,
1815 gboolean found = FALSE;
1821 if (!array || array->len == 0)
1825 max = array->len - 1;
1831 mid = (min + max) / 2;
1832 region = &g_array_index (array, GtkRegion, mid);
1834 if (region->class_quark == class_quark)
1839 else if (region->class_quark > class_quark)
1840 min = pos = mid + 1;
1847 while (!found && min <= max);
1856 * gtk_style_context_add_class:
1857 * @context: a #GtkStyleContext
1858 * @class_name: class name to use in styling
1860 * Adds a style class to @context, so posterior calls to
1861 * gtk_style_context_get() or any of the gtk_render_*()
1862 * functions will make use of this new class for styling.
1864 * In the CSS file format, a #GtkEntry defining an "entry"
1865 * class, would be matched by:
1868 * GtkEntry.entry { ... }
1871 * While any widget defining an "entry" class would be
1880 gtk_style_context_add_class (GtkStyleContext *context,
1881 const gchar *class_name)
1883 GtkStyleContextPrivate *priv;
1888 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1889 g_return_if_fail (class_name != NULL);
1891 priv = context->priv;
1892 class_quark = g_quark_from_string (class_name);
1894 g_assert (priv->info_stack != NULL);
1895 info = priv->info_stack->data;
1897 if (!style_class_find (info->style_classes, class_quark, &position))
1899 g_array_insert_val (info->style_classes, position, class_quark);
1901 /* Unset current data, as it likely changed due to the class change */
1902 priv->current_data = NULL;
1907 * gtk_style_context_remove_class:
1908 * @context: a #GtkStyleContext
1909 * @class_name: class name to remove
1911 * Removes @class_name from @context.
1916 gtk_style_context_remove_class (GtkStyleContext *context,
1917 const gchar *class_name)
1919 GtkStyleContextPrivate *priv;
1924 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1925 g_return_if_fail (class_name != NULL);
1927 class_quark = g_quark_try_string (class_name);
1932 priv = context->priv;
1934 g_assert (priv->info_stack != NULL);
1935 info = priv->info_stack->data;
1937 if (style_class_find (info->style_classes, class_quark, &position))
1939 g_array_remove_index (info->style_classes, position);
1941 /* Unset current data, as it likely changed due to the class change */
1942 priv->current_data = NULL;
1947 * gtk_style_context_has_class:
1948 * @context: a #GtkStyleContext
1949 * @class_name: a class name
1951 * Returns %TRUE if @context currently has defined the
1954 * Returns: %TRUE if @context has @class_name defined
1959 gtk_style_context_has_class (GtkStyleContext *context,
1960 const gchar *class_name)
1962 GtkStyleContextPrivate *priv;
1966 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1967 g_return_val_if_fail (class_name != NULL, FALSE);
1969 class_quark = g_quark_try_string (class_name);
1974 priv = context->priv;
1976 g_assert (priv->info_stack != NULL);
1977 info = priv->info_stack->data;
1979 if (style_class_find (info->style_classes, class_quark, NULL))
1986 * gtk_style_context_list_classes:
1987 * @context: a #GtkStyleContext
1989 * Returns the list of classes currently defined in @context.
1991 * Returns: (transfer container) (element-type utf8): a #GList of
1992 * strings with the currently defined classes. The contents
1993 * of the list are owned by GTK+, but you must free the list
1994 * itself with g_list_free() when you are done with it.
1999 gtk_style_context_list_classes (GtkStyleContext *context)
2001 GtkStyleContextPrivate *priv;
2003 GList *classes = NULL;
2006 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2008 priv = context->priv;
2010 g_assert (priv->info_stack != NULL);
2011 info = priv->info_stack->data;
2013 for (i = 0; i < info->style_classes->len; i++)
2017 quark = g_array_index (info->style_classes, GQuark, i);
2018 classes = g_list_prepend (classes, (gchar *) g_quark_to_string (quark));
2025 * gtk_style_context_list_regions:
2026 * @context: a #GtkStyleContext
2028 * Returns the list of regions currently defined in @context.
2030 * Returns: (transfer container) (element-type utf8): a #GList of
2031 * strings with the currently defined regions. The contents
2032 * of the list are owned by GTK+, but you must free the list
2033 * itself with g_list_free() when you are done with it.
2038 gtk_style_context_list_regions (GtkStyleContext *context)
2040 GtkStyleContextPrivate *priv;
2042 GList *classes = NULL;
2045 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2047 priv = context->priv;
2049 g_assert (priv->info_stack != NULL);
2050 info = priv->info_stack->data;
2052 for (i = 0; i < info->regions->len; i++)
2055 const gchar *class_name;
2057 region = &g_array_index (info->regions, GtkRegion, i);
2059 class_name = g_quark_to_string (region->class_quark);
2060 classes = g_list_prepend (classes, (gchar *) class_name);
2067 * gtk_style_context_add_region:
2068 * @context: a #GtkStyleContext
2069 * @region_name: region name to use in styling
2070 * @flags: flags that apply to the region
2072 * Adds a region to @context, so posterior calls to
2073 * gtk_style_context_get() or any of the gtk_render_*()
2074 * functions will make use of this new region for styling.
2076 * In the CSS file format, a #GtkTreeView defining a "row"
2077 * region, would be matched by:
2080 * GtkTreeView row { ... }
2083 * Pseudo-classes are used for matching @flags, so the two
2086 * GtkTreeView row:nth-child (even) { ... }
2087 * GtkTreeView row:nth-child (odd) { ... }
2090 * would apply to even and odd rows, respectively.
2095 gtk_style_context_add_region (GtkStyleContext *context,
2096 const gchar *region_name,
2097 GtkRegionFlags flags)
2099 GtkStyleContextPrivate *priv;
2101 GQuark region_quark;
2104 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2105 g_return_if_fail (region_name != NULL);
2107 priv = context->priv;
2108 region_quark = g_quark_from_string (region_name);
2110 g_assert (priv->info_stack != NULL);
2111 info = priv->info_stack->data;
2113 if (!region_find (info->regions, region_quark, &position))
2117 region.class_quark = region_quark;
2118 region.flags = flags;
2120 g_array_insert_val (info->regions, position, region);
2122 /* Unset current data, as it likely changed due to the region change */
2123 priv->current_data = NULL;
2128 * gtk_style_context_remove_region:
2129 * @context: a #GtkStyleContext
2130 * @region_name: region name to unset
2132 * Removes a region from @context.
2137 gtk_style_context_remove_region (GtkStyleContext *context,
2138 const gchar *region_name)
2140 GtkStyleContextPrivate *priv;
2142 GQuark region_quark;
2145 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2146 g_return_if_fail (region_name != NULL);
2148 region_quark = g_quark_try_string (region_name);
2153 priv = context->priv;
2155 g_assert (priv->info_stack != NULL);
2156 info = priv->info_stack->data;
2158 if (region_find (info->regions, region_quark, &position))
2160 g_array_remove_index (info->regions, position);
2162 /* Unset current data, as it likely changed due to the region change */
2163 priv->current_data = NULL;
2168 * gtk_style_context_has_region:
2169 * @context: a #GtkStyleContext
2170 * @region_name: a region name
2171 * @flags_return: (out) (allow-none): return location for region flags
2173 * Returns %TRUE if @context has the region defined.
2174 * If @flags_return is not %NULL, it is set to the flags
2175 * affecting the region.
2177 * Returns: %TRUE if region is defined
2182 gtk_style_context_has_region (GtkStyleContext *context,
2183 const gchar *region_name,
2184 GtkRegionFlags *flags_return)
2186 GtkStyleContextPrivate *priv;
2188 GQuark region_quark;
2191 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2192 g_return_val_if_fail (region_name != NULL, FALSE);
2197 region_quark = g_quark_try_string (region_name);
2202 priv = context->priv;
2204 g_assert (priv->info_stack != NULL);
2205 info = priv->info_stack->data;
2207 if (region_find (info->regions, region_quark, &position))
2213 region = &g_array_index (info->regions, GtkRegion, position);
2214 *flags_return = region->flags;
2223 style_property_values_cmp (gconstpointer bsearch_node1,
2224 gconstpointer bsearch_node2)
2226 const PropertyValue *val1 = bsearch_node1;
2227 const PropertyValue *val2 = bsearch_node2;
2229 if (val1->widget_type != val2->widget_type)
2230 return val1->widget_type < val2->widget_type ? -1 : 1;
2232 if (val1->pspec != val2->pspec)
2233 return val1->pspec < val2->pspec ? -1 : 1;
2235 if (val1->state != val2->state)
2236 return val1->state < val2->state ? -1 : 1;
2242 _gtk_style_context_peek_style_property (GtkStyleContext *context,
2244 GtkStateFlags state,
2247 GtkStyleContextPrivate *priv;
2248 PropertyValue *pcache, key = { 0 };
2249 GList *global_list = NULL;
2253 priv = context->priv;
2254 data = style_data_lookup (context);
2256 key.widget_type = widget_type;
2260 /* need value cache array */
2261 if (!data->property_cache)
2262 data->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
2265 pcache = bsearch (&key,
2266 data->property_cache->data, data->property_cache->len,
2267 sizeof (PropertyValue), style_property_values_cmp);
2269 return &pcache->value;
2273 while (i < data->property_cache->len &&
2274 style_property_values_cmp (&key, &g_array_index (data->property_cache, PropertyValue, i)) >= 0)
2277 g_array_insert_val (data->property_cache, i, key);
2278 pcache = &g_array_index (data->property_cache, PropertyValue, i);
2280 /* cache miss, initialize value type, then set contents */
2281 g_param_spec_ref (pcache->pspec);
2282 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2286 global_list = g_object_get_qdata (G_OBJECT (priv->screen), provider_list_quark);
2287 global_list = g_list_last (global_list);
2290 if (priv->widget_path)
2292 GList *list, *global, *elem;
2294 list = priv->providers_last;
2295 global = global_list;
2297 while ((elem = find_next_candidate (list, global, FALSE)) != NULL)
2299 GtkStyleProviderData *provider_data;
2301 provider_data = elem->data;
2306 global = global->prev;
2308 if (gtk_style_provider_get_style_property (provider_data->provider,
2309 priv->widget_path, state,
2310 pspec, &pcache->value))
2312 /* Resolve symbolic colors to GdkColor/GdkRGBA */
2313 if (G_VALUE_TYPE (&pcache->value) == GTK_TYPE_SYMBOLIC_COLOR)
2315 GtkSymbolicColor *color;
2318 color = g_value_get_boxed (&pcache->value);
2320 if (gtk_symbolic_color_resolve (color, data->store, &rgba))
2322 g_value_unset (&pcache->value);
2324 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2326 g_value_init (&pcache->value, GDK_TYPE_RGBA);
2327 g_value_set_boxed (&pcache->value, &rgba);
2333 rgb.red = rgba.red * 65535. + 0.5;
2334 rgb.green = rgba.green * 65535. + 0.5;
2335 rgb.blue = rgba.blue * 65535. + 0.5;
2337 g_value_init (&pcache->value, GDK_TYPE_COLOR);
2338 g_value_set_boxed (&pcache->value, &rgb);
2342 g_param_value_set_default (pspec, &pcache->value);
2345 return &pcache->value;
2350 /* not supplied by any provider, revert to default */
2351 g_param_value_set_default (pspec, &pcache->value);
2353 return &pcache->value;
2357 * gtk_style_context_get_style_property:
2358 * @context: a #GtkStyleContext
2359 * @property_name: the name of the widget style property
2360 * @value: (out) (transfer full): Return location for the property value
2362 * Gets the value for a widget style property.
2364 * When @value is no longer needed, g_value_unset() must be called
2365 * to free any allocated memory.
2368 gtk_style_context_get_style_property (GtkStyleContext *context,
2369 const gchar *property_name,
2372 GtkStyleContextPrivate *priv;
2373 GtkWidgetClass *widget_class;
2374 GtkStateFlags state;
2376 const GValue *peek_value;
2379 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2380 g_return_if_fail (property_name != NULL);
2381 g_return_if_fail (value != NULL);
2383 priv = context->priv;
2385 if (!priv->widget_path)
2388 widget_type = gtk_widget_path_get_widget_type (priv->widget_path);
2390 widget_class = g_type_class_ref (widget_type);
2391 pspec = gtk_widget_class_find_style_property (widget_class, property_name);
2392 g_type_class_unref (widget_class);
2396 g_warning ("%s: widget class `%s' has no style property named `%s'",
2398 g_type_name (widget_type),
2403 state = gtk_style_context_get_state (context);
2404 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2407 if (G_VALUE_TYPE (value) == G_VALUE_TYPE (peek_value))
2408 g_value_copy (peek_value, value);
2409 else if (g_value_type_transformable (G_VALUE_TYPE (peek_value), G_VALUE_TYPE (value)))
2410 g_value_transform (peek_value, value);
2412 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
2414 G_VALUE_TYPE_NAME (peek_value),
2415 G_VALUE_TYPE_NAME (value));
2419 * gtk_style_context_get_style_valist:
2420 * @context: a #GtkStyleContext
2421 * @args: va_list of property name/return location pairs, followed by %NULL
2423 * Retrieves several widget style properties from @context according to the
2429 gtk_style_context_get_style_valist (GtkStyleContext *context,
2432 GtkStyleContextPrivate *priv;
2433 const gchar *prop_name;
2434 GtkStateFlags state;
2436 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2438 prop_name = va_arg (args, const gchar *);
2439 priv = context->priv;
2441 if (!priv->widget_path)
2444 state = gtk_style_context_get_state (context);
2448 GtkWidgetClass *widget_class;
2450 const GValue *peek_value;
2454 widget_type = gtk_widget_path_get_widget_type (priv->widget_path);
2456 widget_class = g_type_class_ref (widget_type);
2457 pspec = gtk_widget_class_find_style_property (widget_class, prop_name);
2458 g_type_class_unref (widget_class);
2462 g_warning ("%s: widget class `%s' has no style property named `%s'",
2464 g_type_name (widget_type),
2469 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2472 G_VALUE_LCOPY (peek_value, args, 0, &error);
2476 g_warning ("can't retrieve style property `%s' of type `%s': %s",
2478 G_VALUE_TYPE_NAME (peek_value),
2483 prop_name = va_arg (args, const gchar *);
2488 * gtk_style_context_get_style:
2489 * @context: a #GtkStyleContext
2490 * @...: property name /return value pairs, followed by %NULL
2492 * Retrieves several widget style properties from @context according to the
2498 gtk_style_context_get_style (GtkStyleContext *context,
2503 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2505 va_start (args, context);
2506 gtk_style_context_get_style_valist (context, args);
2512 * gtk_style_context_lookup_icon_set:
2513 * @context: a #GtkStyleContext
2514 * @stock_id: an icon name
2516 * Looks up @stock_id in the icon factories associated to @context and
2517 * the default icon factory, returning an icon set if found, otherwise
2520 * Returns: (transfer none): The looked up %GtkIconSet, or %NULL
2523 gtk_style_context_lookup_icon_set (GtkStyleContext *context,
2524 const gchar *stock_id)
2526 GtkStyleContextPrivate *priv;
2530 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2531 g_return_val_if_fail (stock_id != NULL, NULL);
2533 priv = context->priv;
2534 g_return_val_if_fail (priv->widget_path != NULL, NULL);
2536 data = style_data_lookup (context);
2538 for (list = data->icon_factories; list; list = list->next)
2540 GtkIconFactory *factory;
2541 GtkIconSet *icon_set;
2543 factory = list->data;
2544 icon_set = gtk_icon_factory_lookup (factory, stock_id);
2550 return gtk_icon_factory_lookup_default (stock_id);
2554 * gtk_style_context_set_screen:
2555 * @context: a #GtkStyleContext
2556 * @screen: a #GdkScreen
2558 * Attaches @context to the given screen.
2560 * The screen is used to add style information from 'global' style
2561 * providers, such as the screens #GtkSettings instance.
2563 * If you are using a #GtkStyleContext returned from
2564 * gtk_widget_get_style_context(), you do not need to
2565 * call this yourself.
2570 gtk_style_context_set_screen (GtkStyleContext *context,
2573 GtkStyleContextPrivate *priv;
2575 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2576 g_return_if_fail (GDK_IS_SCREEN (screen));
2578 priv = context->priv;
2579 if (priv->screen == screen)
2582 priv->screen = screen;
2584 g_object_notify (G_OBJECT (context), "screen");
2586 gtk_style_context_invalidate (context);
2590 * gtk_style_context_get_screen:
2591 * @context: a #GtkStyleContext
2593 * Returns the #GdkScreen to which @context is attached.
2595 * Returns: a #GdkScreen.
2598 gtk_style_context_get_screen (GtkStyleContext *context)
2600 GtkStyleContextPrivate *priv;
2602 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2604 priv = context->priv;
2605 return priv->screen;
2609 * gtk_style_context_set_direction:
2610 * @context: a #GtkStyleContext
2611 * @direction: the new direction.
2613 * Sets the reading direction for rendering purposes.
2615 * If you are using a #GtkStyleContext returned from
2616 * gtk_widget_get_style_context(), you do not need to
2617 * call this yourself.
2622 gtk_style_context_set_direction (GtkStyleContext *context,
2623 GtkTextDirection direction)
2625 GtkStyleContextPrivate *priv;
2627 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2629 priv = context->priv;
2630 priv->direction = direction;
2632 g_object_notify (G_OBJECT (context), "direction");
2636 * gtk_style_context_get_direction:
2637 * @context: a #GtkStyleContext
2639 * Returns the widget direction used for rendering.
2641 * Returns: the widget direction
2646 gtk_style_context_get_direction (GtkStyleContext *context)
2648 GtkStyleContextPrivate *priv;
2650 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), GTK_TEXT_DIR_LTR);
2652 priv = context->priv;
2653 return priv->direction;
2657 * gtk_style_context_set_junction_sides:
2658 * @context: a #GtkStyleContext
2659 * @sides: sides where rendered elements are visually connected to
2662 * Sets the sides where rendered elements (mostly through
2663 * gtk_render_frame()) will visually connect with other visual elements.
2665 * This is merely a hint that may or may not be honored
2666 * by theming engines.
2668 * Container widgets are expected to set junction hints as appropriate
2669 * for their children, so it should not normally be necessary to call
2670 * this function manually.
2675 gtk_style_context_set_junction_sides (GtkStyleContext *context,
2676 GtkJunctionSides sides)
2678 GtkStyleContextPrivate *priv;
2681 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2683 priv = context->priv;
2684 info = priv->info_stack->data;
2685 info->junction_sides = sides;
2689 * gtk_style_context_get_junction_sides:
2690 * @context: a #GtkStyleContext
2692 * Returns the sides where rendered elements connect visually with others.
2694 * Returns: the junction sides
2699 gtk_style_context_get_junction_sides (GtkStyleContext *context)
2701 GtkStyleContextPrivate *priv;
2704 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
2706 priv = context->priv;
2707 info = priv->info_stack->data;
2708 return info->junction_sides;
2712 * gtk_style_context_lookup_color:
2713 * @context: a #GtkStyleContext
2714 * @color_name: color name to lookup
2715 * @color: (out): Return location for the looked up color
2717 * Looks up and resolves a color name in the @context color map.
2719 * Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
2722 gtk_style_context_lookup_color (GtkStyleContext *context,
2723 const gchar *color_name,
2726 GtkStyleContextPrivate *priv;
2727 GtkSymbolicColor *sym_color;
2730 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2731 g_return_val_if_fail (color_name != NULL, FALSE);
2732 g_return_val_if_fail (color != NULL, FALSE);
2734 priv = context->priv;
2735 g_return_val_if_fail (priv->widget_path != NULL, FALSE);
2737 data = style_data_lookup (context);
2738 sym_color = gtk_style_properties_lookup_color (data->store, color_name);
2743 return gtk_symbolic_color_resolve (sym_color, data->store, color);
2747 * gtk_style_context_notify_state_change:
2748 * @context: a #GtkStyleContext
2749 * @window: a #GdkWindow
2750 * @region_id: (allow-none): animatable region to notify on, or %NULL.
2751 * See gtk_style_context_push_animatable_region()
2752 * @state: state to trigger transition for
2753 * @state_value: %TRUE if @state is the state we are changing to,
2754 * %FALSE if we are changing away from it
2756 * Notifies a state change on @context, so if the current style makes use
2757 * of transition animations, one will be started so all rendered elements
2758 * under @region_id are animated for state @state being set to value
2761 * The @window parameter is used in order to invalidate the rendered area
2762 * as the animation runs, so make sure it is the same window that is being
2763 * rendered on by the gtk_render_*() functions.
2765 * If @region_id is %NULL, all rendered elements using @context will be
2766 * affected by this state transition.
2768 * As a practical example, a #GtkButton notifying a state transition on
2769 * the prelight state:
2771 * gtk_style_context_notify_state_change (context,
2772 * gtk_widget_get_window (widget),
2774 * GTK_STATE_PRELIGHT,
2775 * button->in_button);
2778 * Can be handled in the CSS file like this:
2781 * background-color: #f00
2785 * background-color: #fff;
2786 * transition: 200ms linear
2790 * This combination will animate the button background from red to white
2791 * if a pointer enters the button, and back to red if the pointer leaves
2794 * Note that @state is used when finding the transition parameters, which
2795 * is why the style places the transition under the :hover pseudo-class.
2800 gtk_style_context_notify_state_change (GtkStyleContext *context,
2804 gboolean state_value)
2806 GtkStyleContextPrivate *priv;
2807 GtkAnimationDescription *desc;
2808 AnimationInfo *info;
2809 GtkStateFlags flags;
2812 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2813 g_return_if_fail (GDK_IS_WINDOW (window));
2814 g_return_if_fail (state > GTK_STATE_NORMAL && state <= GTK_STATE_FOCUSED);
2816 priv = context->priv;
2817 g_return_if_fail (priv->widget_path != NULL);
2819 state_value = (state_value == TRUE);
2823 case GTK_STATE_ACTIVE:
2824 flags = GTK_STATE_FLAG_ACTIVE;
2826 case GTK_STATE_PRELIGHT:
2827 flags = GTK_STATE_FLAG_PRELIGHT;
2829 case GTK_STATE_SELECTED:
2830 flags = GTK_STATE_FLAG_SELECTED;
2832 case GTK_STATE_INSENSITIVE:
2833 flags = GTK_STATE_FLAG_INSENSITIVE;
2835 case GTK_STATE_INCONSISTENT:
2836 flags = GTK_STATE_FLAG_INCONSISTENT;
2838 case GTK_STATE_FOCUSED:
2839 flags = GTK_STATE_FLAG_FOCUSED;
2841 case GTK_STATE_NORMAL:
2847 /* Find out if there is any animation description for the given
2848 * state, it will fallback to the normal state as well if necessary.
2850 data = style_data_lookup (context);
2851 gtk_style_properties_get (data->store, flags,
2852 "transition", &desc,
2858 if (gtk_animation_description_get_duration (desc) == 0)
2860 gtk_animation_description_unref (desc);
2864 info = animation_info_lookup (context, region_id, state);
2867 info->target_value != state_value)
2869 /* Target values are the opposite */
2870 if (!gtk_timeline_get_loop (info->timeline))
2872 /* Reverse the animation */
2873 if (gtk_timeline_get_direction (info->timeline) == GTK_TIMELINE_DIRECTION_FORWARD)
2874 gtk_timeline_set_direction (info->timeline, GTK_TIMELINE_DIRECTION_BACKWARD);
2876 gtk_timeline_set_direction (info->timeline, GTK_TIMELINE_DIRECTION_FORWARD);
2878 info->target_value = state_value;
2882 /* Take it out of its looping state */
2883 gtk_timeline_set_loop (info->timeline, FALSE);
2887 (!gtk_animation_description_get_loop (desc) ||
2890 info = animation_info_new (context, region_id,
2891 gtk_animation_description_get_duration (desc),
2892 gtk_animation_description_get_progress_type (desc),
2893 gtk_animation_description_get_loop (desc),
2894 state, state_value, window);
2896 priv->animations = g_slist_prepend (priv->animations, info);
2897 priv->animations_invalidated = TRUE;
2900 gtk_animation_description_unref (desc);
2904 * gtk_style_context_push_animatable_region:
2905 * @context: a #GtkStyleContext
2906 * @region_id: unique identifier for the animatable region
2908 * Pushes an animatable region, so all further gtk_render_*() calls between
2909 * this call and the following gtk_style_context_pop_animatable_region()
2910 * will potentially show transition animations for this region if
2911 * gtk_style_context_notify_state_change() is called for a given state,
2912 * and the current theme/style defines transition animations for state
2915 * The @region_id used must be unique in @context so the theming engine
2916 * can uniquely identify rendered elements subject to a state transition.
2921 gtk_style_context_push_animatable_region (GtkStyleContext *context,
2924 GtkStyleContextPrivate *priv;
2926 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2927 g_return_if_fail (region_id != NULL);
2929 priv = context->priv;
2930 priv->animation_regions = g_slist_prepend (priv->animation_regions, region_id);
2934 * gtk_style_context_pop_animatable_region:
2935 * @context: a #GtkStyleContext
2937 * Pops an animatable region from @context.
2938 * See gtk_style_context_push_animatable_region().
2943 gtk_style_context_pop_animatable_region (GtkStyleContext *context)
2945 GtkStyleContextPrivate *priv;
2947 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2949 priv = context->priv;
2950 priv->animation_regions = g_slist_delete_link (priv->animation_regions,
2951 priv->animation_regions);
2955 _gtk_style_context_invalidate_animation_areas (GtkStyleContext *context)
2957 GtkStyleContextPrivate *priv;
2960 priv = context->priv;
2962 for (l = priv->animations; l; l = l->next)
2964 AnimationInfo *info;
2968 /* A NULL invalidation region means it has to be recreated on
2969 * the next expose event, this happens usually after a widget
2970 * allocation change, so the next expose after it will update
2971 * the invalidation region.
2973 if (info->invalidation_region)
2975 cairo_region_destroy (info->invalidation_region);
2976 info->invalidation_region = NULL;
2980 priv->animations_invalidated = TRUE;
2984 _gtk_style_context_coalesce_animation_areas (GtkStyleContext *context,
2988 GtkStyleContextPrivate *priv;
2991 priv = context->priv;
2993 if (!priv->animations_invalidated)
2996 l = priv->animations;
3000 AnimationInfo *info;
3008 if (info->invalidation_region)
3011 /* There's not much point in keeping the animation running */
3012 if (info->rectangles->len == 0)
3014 priv->animations = g_slist_remove (priv->animations, info);
3015 animation_info_free (info);
3019 info->invalidation_region = cairo_region_create ();
3021 for (i = 0; i < info->rectangles->len; i++)
3023 cairo_rectangle_int_t *rect;
3025 rect = &g_array_index (info->rectangles, cairo_rectangle_int_t, i);
3029 cairo_region_union_rectangle (info->invalidation_region, rect);
3032 g_array_remove_range (info->rectangles, 0, info->rectangles->len);
3035 priv->animations_invalidated = FALSE;
3039 store_animation_region (GtkStyleContext *context,
3045 GtkStyleContextPrivate *priv;
3048 priv = context->priv;
3050 if (!priv->animations_invalidated)
3053 for (l = priv->animations; l; l = l->next)
3055 AnimationInfo *info;
3059 /* The animation doesn't need updating
3060 * the invalidation area, bail out.
3062 if (info->invalidation_region)
3065 if (context_has_animatable_region (context, info->region_id))
3067 cairo_rectangle_int_t rect;
3071 rect.width = (gint) width;
3072 rect.height = (gint) height;
3074 g_array_append_val (info->rectangles, rect);
3080 * gtk_style_context_invalidate:
3081 * @context: a #GtkStyleContext.
3083 * Invalidates @context style information, so it will be reconstructed
3086 * If you're using a #GtkStyleContext returned from
3087 * gtk_widget_get_style_context(), you do not need to
3088 * call this yourself.
3093 gtk_style_context_invalidate (GtkStyleContext *context)
3095 GtkStyleContextPrivate *priv;
3097 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3099 priv = context->priv;
3101 /* Avoid reentrancy */
3102 if (priv->invalidating_context)
3105 priv->invalidating_context = TRUE;
3107 g_hash_table_remove_all (priv->style_data);
3108 priv->current_data = NULL;
3110 g_signal_emit (context, signals[CHANGED], 0);
3112 priv->invalidating_context = FALSE;
3116 * gtk_style_context_set_background:
3117 * @context: a #GtkStyleContext
3118 * @window: a #GdkWindow
3120 * Sets the background of @window to the background pattern or
3121 * color specified in @context for its current state.
3126 gtk_style_context_set_background (GtkStyleContext *context,
3129 GtkStateFlags state;
3130 cairo_pattern_t *pattern;
3133 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3134 g_return_if_fail (GDK_IS_WINDOW (window));
3136 state = gtk_style_context_get_state (context);
3137 gtk_style_context_get (context, state,
3138 "background-image", &pattern,
3142 gdk_window_set_background_pattern (window, pattern);
3143 cairo_pattern_destroy (pattern);
3147 gtk_style_context_get (context, state,
3148 "background-color", &color,
3152 gdk_window_set_background_rgba (window, color);
3153 gdk_rgba_free (color);
3158 * gtk_style_context_get_color:
3159 * @context: a #GtkStyleContext
3160 * @state: state to retrieve the color for
3161 * @color: (out): return value for the foreground color
3163 * Gets the foreground color for a given state.
3168 gtk_style_context_get_color (GtkStyleContext *context,
3169 GtkStateFlags state,
3172 GtkStyleContextPrivate *priv;
3174 const GValue *value;
3177 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3179 priv = context->priv;
3180 g_return_if_fail (priv->widget_path != NULL);
3182 data = style_data_lookup (context);
3183 value = _gtk_style_properties_peek_property (data->store,
3185 c = g_value_get_boxed (value);
3190 * gtk_style_context_get_background_color:
3191 * @context: a #GtkStyleContext
3192 * @state: state to retrieve the color for
3193 * @color: (out): return value for the background color
3195 * Gets the background color for a given state.
3200 gtk_style_context_get_background_color (GtkStyleContext *context,
3201 GtkStateFlags state,
3204 GtkStyleContextPrivate *priv;
3206 const GValue *value;
3209 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3211 priv = context->priv;
3212 g_return_if_fail (priv->widget_path != NULL);
3214 data = style_data_lookup (context);
3215 value = _gtk_style_properties_peek_property (data->store,
3216 "background-color", state);
3217 c = g_value_get_boxed (value);
3222 * gtk_style_context_get_border_color:
3223 * @context: a #GtkStyleContext
3224 * @state: state to retrieve the color for
3225 * @color: (out): return value for the border color
3227 * Gets the border color for a given state.
3232 gtk_style_context_get_border_color (GtkStyleContext *context,
3233 GtkStateFlags state,
3236 GtkStyleContextPrivate *priv;
3238 const GValue *value;
3241 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3243 priv = context->priv;
3244 g_return_if_fail (priv->widget_path != NULL);
3246 data = style_data_lookup (context);
3247 value = _gtk_style_properties_peek_property (data->store,
3248 "border-color", state);
3249 c = g_value_get_boxed (value);
3254 * gtk_style_context_get_border:
3255 * @context: a #GtkStyleContext
3256 * @state: state to retrieve the border for
3257 * @color: (out): return value for the border settings
3259 * Gets the border for a given state as a #GtkBorder.
3264 gtk_style_context_get_border (GtkStyleContext *context,
3265 GtkStateFlags state,
3268 GtkStyleContextPrivate *priv;
3270 const GValue *value;
3273 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3275 priv = context->priv;
3276 g_return_if_fail (priv->widget_path != NULL);
3278 data = style_data_lookup (context);
3279 value = _gtk_style_properties_peek_property (data->store,
3280 "border-width", state);
3281 b = g_value_get_boxed (value);
3286 * gtk_style_context_get_padding:
3287 * @context: a #GtkStyleContext
3288 * @state: state to retrieve the padding for
3289 * @color: (out): return value for the padding settings
3291 * Gets the padding for a given state as a #GtkBorder.
3296 gtk_style_context_get_padding (GtkStyleContext *context,
3297 GtkStateFlags state,
3300 GtkStyleContextPrivate *priv;
3302 const GValue *value;
3305 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3307 priv = context->priv;
3308 g_return_if_fail (priv->widget_path != NULL);
3310 data = style_data_lookup (context);
3311 value = _gtk_style_properties_peek_property (data->store,
3313 b = g_value_get_boxed (value);
3318 * gtk_style_context_get_margin:
3319 * @context: a #GtkStyleContext
3320 * @state: state to retrieve the border for
3321 * @color: (out): return value for the margin settings
3323 * Gets the margin for a given state as a #GtkBorder.
3328 gtk_style_context_get_margin (GtkStyleContext *context,
3329 GtkStateFlags state,
3332 GtkStyleContextPrivate *priv;
3334 const GValue *value;
3337 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3339 priv = context->priv;
3340 g_return_if_fail (priv->widget_path != NULL);
3342 data = style_data_lookup (context);
3343 value = _gtk_style_properties_peek_property (data->store,
3345 b = g_value_get_boxed (value);
3353 * @context: a #GtkStyleContext
3355 * @x: X origin of the rectangle
3356 * @y: Y origin of the rectangle
3357 * @width: rectangle width
3358 * @height: rectangle height
3360 * Renders a checkmark (as in a #GtkCheckButton).
3362 * The %GTK_STATE_FLAG_ACTIVE state determines whether the check is
3363 * on or off, and %GTK_STATE_FLAG_INCONSISTENT determines whether it
3364 * should be marked as undefined.
3367 * <title>Typical checkmark rendering</title>
3368 * <inlinegraphic fileref="checks.png" format="PNG"/>
3374 gtk_render_check (GtkStyleContext *context,
3381 GtkStyleContextPrivate *priv;
3382 GtkThemingEngineClass *engine_class;
3384 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3385 g_return_if_fail (cr != NULL);
3387 priv = context->priv;
3388 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3390 store_animation_region (context, x, y, width, height);
3392 _gtk_theming_engine_set_context (priv->theming_engine, context);
3393 engine_class->render_check (priv->theming_engine, cr,
3394 x, y, width, height);
3398 * gtk_render_option:
3399 * @context: a #GtkStyleContext
3401 * @x: X origin of the rectangle
3402 * @y: Y origin of the rectangle
3403 * @width: rectangle width
3404 * @height: rectangle height
3406 * Renders an option mark (as in a #GtkRadioButton), the %GTK_STATE_FLAG_ACTIVE
3407 * state will determine whether the option is on or off, and
3408 * %GTK_STATE_FLAG_INCONSISTENT whether it should be marked as undefined.
3411 * <title>Typical option mark rendering</title>
3412 * <inlinegraphic fileref="options.png" format="PNG"/>
3418 gtk_render_option (GtkStyleContext *context,
3425 GtkStyleContextPrivate *priv;
3426 GtkThemingEngineClass *engine_class;
3428 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3429 g_return_if_fail (cr != NULL);
3431 priv = context->priv;
3432 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3434 store_animation_region (context, x, y, width, height);
3436 _gtk_theming_engine_set_context (priv->theming_engine, context);
3437 engine_class->render_option (priv->theming_engine, cr,
3438 x, y, width, height);
3443 * @context: a #GtkStyleContext
3445 * @angle: arrow angle from 0 to 2 * %G_PI, being 0 the arrow pointing to the north
3446 * @x: Center X for the render area
3447 * @y: Center Y for the render area
3448 * @size: square side for render area
3450 * Renders an arrow pointing to @angle.
3453 * <title>Typical arrow rendering at 0, 1&solidus;2 π, π and 3&solidus;2 π</title>
3454 * <inlinegraphic fileref="arrows.png" format="PNG"/>
3460 gtk_render_arrow (GtkStyleContext *context,
3467 GtkStyleContextPrivate *priv;
3468 GtkThemingEngineClass *engine_class;
3470 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3471 g_return_if_fail (cr != NULL);
3473 priv = context->priv;
3474 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3476 store_animation_region (context, x, y, size, size);
3478 _gtk_theming_engine_set_context (priv->theming_engine, context);
3479 engine_class->render_arrow (priv->theming_engine, cr,
3484 * gtk_render_background:
3485 * @context: a #GtkStyleContext
3487 * @x: X origin of the rectangle
3488 * @y: Y origin of the rectangle
3489 * @width: rectangle width
3490 * @height: rectangle height
3492 * Renders the background of an element.
3495 * <title>Typical background rendering, showing the effect of
3496 * <parameter>background-image</parameter>,
3497 * <parameter>border-width</parameter> and
3498 * <parameter>border-radius</parameter></title>
3499 * <inlinegraphic fileref="background.png" format="PNG"/>
3505 gtk_render_background (GtkStyleContext *context,
3512 GtkStyleContextPrivate *priv;
3513 GtkThemingEngineClass *engine_class;
3515 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3516 g_return_if_fail (cr != NULL);
3518 priv = context->priv;
3519 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3521 store_animation_region (context, x, y, width, height);
3523 _gtk_theming_engine_set_context (priv->theming_engine, context);
3524 engine_class->render_background (priv->theming_engine, cr, x, y, width, height);
3529 * @context: a #GtkStyleContext
3531 * @x: X origin of the rectangle
3532 * @y: Y origin of the rectangle
3533 * @width: rectangle width
3534 * @height: rectangle height
3536 * Renders a frame around the rectangle defined by @x, @y, @width, @height.
3539 * <title>Examples of frame rendering, showing the effect of
3540 * <parameter>border-image</parameter>,
3541 * <parameter>border-color</parameter>,
3542 * <parameter>border-width</parameter>,
3543 * <parameter>border-radius</parameter> and
3545 * <inlinegraphic fileref="frames.png" format="PNG"/>
3551 gtk_render_frame (GtkStyleContext *context,
3558 GtkStyleContextPrivate *priv;
3559 GtkThemingEngineClass *engine_class;
3561 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3562 g_return_if_fail (cr != NULL);
3564 priv = context->priv;
3565 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3567 store_animation_region (context, x, y, width, height);
3569 _gtk_theming_engine_set_context (priv->theming_engine, context);
3570 engine_class->render_frame (priv->theming_engine, cr, x, y, width, height);
3574 * gtk_render_expander:
3575 * @context: a #GtkStyleContext
3577 * @x: X origin of the rectangle
3578 * @y: Y origin of the rectangle
3579 * @width: rectangle width
3580 * @height: rectangle height
3582 * Renders an expander (as used in #GtkTreeView and #GtkExpander) in the area
3583 * defined by @x, @y, @width, @height. The state %GTK_STATE_FLAG_ACTIVE
3584 * determines whether the expander is collapsed or expanded.
3587 * <title>Typical expander rendering</title>
3588 * <inlinegraphic fileref="expanders.png" format="PNG"/>
3594 gtk_render_expander (GtkStyleContext *context,
3601 GtkStyleContextPrivate *priv;
3602 GtkThemingEngineClass *engine_class;
3604 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3605 g_return_if_fail (cr != NULL);
3607 priv = context->priv;
3608 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3610 store_animation_region (context, x, y, width, height);
3612 _gtk_theming_engine_set_context (priv->theming_engine, context);
3613 engine_class->render_expander (priv->theming_engine, cr, x, y, width, height);
3618 * @context: a #GtkStyleContext
3620 * @x: X origin of the rectangle
3621 * @y: Y origin of the rectangle
3622 * @width: rectangle width
3623 * @height: rectangle height
3625 * Renders a focus indicator on the rectangle determined by @x, @y, @width, @height.
3627 * <title>Typical focus rendering</title>
3628 * <inlinegraphic fileref="focus.png" format="PNG"/>
3634 gtk_render_focus (GtkStyleContext *context,
3641 GtkStyleContextPrivate *priv;
3642 GtkThemingEngineClass *engine_class;
3644 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3645 g_return_if_fail (cr != NULL);
3647 priv = context->priv;
3648 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3650 store_animation_region (context, x, y, width, height);
3652 _gtk_theming_engine_set_context (priv->theming_engine, context);
3653 engine_class->render_focus (priv->theming_engine, cr, x, y, width, height);
3657 * gtk_render_layout:
3658 * @context: a #GtkStyleContext
3662 * @layout: the #PangoLayout to render
3664 * Renders @layout on the coordinates @x, @y
3669 gtk_render_layout (GtkStyleContext *context,
3673 PangoLayout *layout)
3675 GtkStyleContextPrivate *priv;
3676 GtkThemingEngineClass *engine_class;
3677 PangoRectangle extents;
3679 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3680 g_return_if_fail (cr != NULL);
3682 priv = context->priv;
3683 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3685 pango_layout_get_extents (layout, &extents, NULL);
3687 store_animation_region (context,
3693 _gtk_theming_engine_set_context (priv->theming_engine, context);
3694 engine_class->render_layout (priv->theming_engine, cr, x, y, layout);
3699 * @context: a #GtkStyleContext
3701 * @x0: X coordinate for the origin of the line
3702 * @y0: Y coordinate for the origin of the line
3703 * @x1: X coordinate for the end of the line
3704 * @y1: Y coordinate for the end of the line
3706 * Renders a line from (x0, y0) to (x1, y1).
3711 gtk_render_line (GtkStyleContext *context,
3718 GtkStyleContextPrivate *priv;
3719 GtkThemingEngineClass *engine_class;
3721 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3722 g_return_if_fail (cr != NULL);
3724 priv = context->priv;
3725 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3727 _gtk_theming_engine_set_context (priv->theming_engine, context);
3728 engine_class->render_line (priv->theming_engine, cr, x0, y0, x1, y1);
3732 * gtk_render_slider:
3733 * @context: a #GtkStyleContext
3735 * @x: X origin of the rectangle
3736 * @y: Y origin of the rectangle
3737 * @width: rectangle width
3738 * @height: rectangle height
3739 * @orientation: orientation of the slider
3741 * Renders a slider (as in #GtkScale) in the rectangle defined by @x, @y,
3742 * @width, @height. @orientation defines whether the slider is vertical
3746 * <title>Typical slider rendering</title>
3747 * <inlinegraphic fileref="sliders.png" format="PNG"/>
3753 gtk_render_slider (GtkStyleContext *context,
3759 GtkOrientation orientation)
3761 GtkStyleContextPrivate *priv;
3762 GtkThemingEngineClass *engine_class;
3764 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3765 g_return_if_fail (cr != NULL);
3767 priv = context->priv;
3768 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3770 store_animation_region (context, x, y, width, height);
3772 _gtk_theming_engine_set_context (priv->theming_engine, context);
3773 engine_class->render_slider (priv->theming_engine, cr, x, y, width, height, orientation);
3777 * gtk_render_frame_gap:
3778 * @context: a #GtkStyleContext
3780 * @x: X origin of the rectangle
3781 * @y: Y origin of the rectangle
3782 * @width: rectangle width
3783 * @height: rectangle height
3784 * @gap_side: side where the gap is
3785 * @xy0_gap: initial coordinate (X or Y depending on @gap_side) for the gap
3786 * @xy1_gap: end coordinate (X or Y depending on @gap_side) for the gap
3788 * Renders a frame around the rectangle defined by (@x, @y, @width, @height),
3789 * leaving a gap on one side. @xy0_gap and @xy1_gap will mean X coordinates
3790 * for %GTK_POS_TOP and %GTK_POS_BOTTOM gap sides, and Y coordinates for
3791 * %GTK_POS_LEFT and %GTK_POS_RIGHT.
3794 * <title>Typical rendering of a frame with a gap</title>
3795 * <inlinegraphic fileref="frame-gap.png" format="PNG"/>
3801 gtk_render_frame_gap (GtkStyleContext *context,
3807 GtkPositionType gap_side,
3811 GtkStyleContextPrivate *priv;
3812 GtkThemingEngineClass *engine_class;
3814 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3815 g_return_if_fail (cr != NULL);
3817 priv = context->priv;
3818 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3820 store_animation_region (context, x, y, width, height);
3822 _gtk_theming_engine_set_context (priv->theming_engine, context);
3823 engine_class->render_frame_gap (priv->theming_engine, cr,
3824 x, y, width, height, gap_side,
3829 * gtk_render_extension:
3830 * @context: a #GtkStyleContext
3832 * @x: X origin of the rectangle
3833 * @y: Y origin of the rectangle
3834 * @width: rectangle width
3835 * @height: rectangle height
3836 * @gap_side: side where the gap is
3838 * Renders a extension (as in a #GtkNotebook tab) in the rectangle
3839 * defined by @x, @y, @width, @height. The side where the extension
3840 * connects to is defined by @gap_side.
3843 * <title>Typical extension rendering</title>
3844 * <inlinegraphic fileref="extensions.png" format="PNG"/>
3850 gtk_render_extension (GtkStyleContext *context,
3856 GtkPositionType gap_side)
3858 GtkStyleContextPrivate *priv;
3859 GtkThemingEngineClass *engine_class;
3861 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3862 g_return_if_fail (cr != NULL);
3864 priv = context->priv;
3865 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3867 store_animation_region (context, x, y, width, height);
3869 _gtk_theming_engine_set_context (priv->theming_engine, context);
3870 engine_class->render_extension (priv->theming_engine, cr, x, y, width, height, gap_side);
3874 * gtk_render_handle:
3875 * @context: a #GtkStyleContext
3877 * @x: X origin of the rectangle
3878 * @y: Y origin of the rectangle
3879 * @width: rectangle width
3880 * @height: rectangle height
3882 * Renders a handle (as in #GtkHandleBox, #GtkPaned and
3883 * #GtkWindow<!-- -->'s resize grip), in the rectangle
3884 * determined by @x, @y, @width, @height.
3887 * <title>Handles rendered for the paned and grip classes</title>
3888 * <inlinegraphic fileref="handles.png" format="PNG"/>
3894 gtk_render_handle (GtkStyleContext *context,
3901 GtkStyleContextPrivate *priv;
3902 GtkThemingEngineClass *engine_class;
3904 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3905 g_return_if_fail (cr != NULL);
3907 priv = context->priv;
3908 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3910 store_animation_region (context, x, y, width, height);
3912 _gtk_theming_engine_set_context (priv->theming_engine, context);
3913 engine_class->render_handle (priv->theming_engine, cr, x, y, width, height);
3917 * gtk_render_activity:
3918 * @context: a #GtkStyleContext
3920 * @x: X origin of the rectangle
3921 * @y: Y origin of the rectangle
3922 * @width: rectangle width
3923 * @height: rectangle height
3925 * Renders an activity area (Such as in #GtkSpinner or the
3926 * fill line in #GtkRange), the state %GTK_STATE_FLAG_ACTIVE
3927 * determines whether there is activity going on.
3932 gtk_render_activity (GtkStyleContext *context,
3939 GtkStyleContextPrivate *priv;
3940 GtkThemingEngineClass *engine_class;
3942 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3943 g_return_if_fail (cr != NULL);
3945 priv = context->priv;
3946 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3948 store_animation_region (context, x, y, width, height);
3950 _gtk_theming_engine_set_context (priv->theming_engine, context);
3951 engine_class->render_activity (priv->theming_engine, cr, x, y, width, height);
3955 * gtk_render_icon_pixbuf:
3956 * @context: a #GtkStyleContext
3957 * @source: the #GtkIconSource specifying the icon to render
3958 * @size: (type int): the size to render the icon at. A size of (GtkIconSize) -1
3959 * means render at the size of the source and don't scale.
3961 * Renders the icon specified by @source at the given @size, returning the result
3964 * Returns: (transfer full): a newly-created #GdkPixbuf containing the rendered icon
3969 gtk_render_icon_pixbuf (GtkStyleContext *context,
3970 const GtkIconSource *source,
3973 GtkStyleContextPrivate *priv;
3974 GtkThemingEngineClass *engine_class;
3976 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
3977 g_return_val_if_fail (size == -1 || size <= GTK_ICON_SIZE_DIALOG, NULL);
3978 g_return_val_if_fail (source != NULL, NULL);
3980 priv = context->priv;
3981 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3983 _gtk_theming_engine_set_context (priv->theming_engine, context);
3984 return engine_class->render_icon_pixbuf (priv->theming_engine, source, size);