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, see <http://www.gnu.org/licenses/>.
23 #include <gobject/gvaluecollector.h>
25 #include "gtkstylecontextprivate.h"
26 #include "gtkstylepropertiesprivate.h"
27 #include "gtktypebuiltins.h"
28 #include "gtkthemingengineprivate.h"
30 #include "gtkwidget.h"
31 #include "gtkwindow.h"
32 #include "gtkprivate.h"
33 #include "gtksymboliccolorprivate.h"
34 #include "gtkanimationdescription.h"
35 #include "gtktimeline.h"
36 #include "gtkiconfactory.h"
37 #include "gtkwidgetpath.h"
38 #include "gtkwidgetprivate.h"
39 #include "gtkstyleproviderprivate.h"
40 #include "gtksettings.h"
43 * SECTION:gtkstylecontext
44 * @Short_description: Rendering UI elements
45 * @Title: GtkStyleContext
47 * #GtkStyleContext is an object that stores styling information affecting
48 * a widget defined by #GtkWidgetPath.
50 * In order to construct the final style information, #GtkStyleContext
51 * queries information from all attached #GtkStyleProviders. Style providers
52 * can be either attached explicitly to the context through
53 * gtk_style_context_add_provider(), or to the screen through
54 * gtk_style_context_add_provider_for_screen(). The resulting style is a
55 * combination of all providers' information in priority order.
57 * For GTK+ widgets, any #GtkStyleContext returned by
58 * gtk_widget_get_style_context() will already have a #GtkWidgetPath, a
59 * #GdkScreen and RTL/LTR information set. The style context will be also
60 * updated automatically if any of these settings change on the widget.
62 * If you are using the theming layer standalone, you will need to set a
63 * widget path and a screen yourself to the created style context through
64 * gtk_style_context_set_path() and gtk_style_context_set_screen(), as well
65 * as updating the context yourself using gtk_style_context_invalidate()
66 * whenever any of the conditions change, such as a change in the
67 * #GtkSettings:gtk-theme-name setting or a hierarchy change in the rendered
70 * <refsect2 id="gtkstylecontext-animations">
71 * <title>Transition animations</title>
73 * #GtkStyleContext has built-in support for state change transitions.
74 * Note that these animations respect the #GtkSettings:gtk-enable-animations
78 * For simple widgets where state changes affect the whole widget area,
79 * calling gtk_style_context_notify_state_change() with a %NULL region
80 * is sufficient to trigger the transition animation. And GTK+ already
81 * does that when gtk_widget_set_state() or gtk_widget_set_state_flags()
85 * If a widget needs to declare several animatable regions (i.e. not
86 * affecting the whole widget area), its #GtkWidget::draw signal handler
87 * needs to wrap the render operations for the different regions with
88 * calls to gtk_style_context_push_animatable_region() and
89 * gtk_style_context_pop_animatable_region(). These functions take an
90 * identifier for the region which must be unique within the style context.
91 * For simple widgets with a fixed set of animatable regions, using an
92 * enumeration works well:
95 * <title>Using an enumeration to identify animatable regions</title>
106 * spin_button_draw (GtkWidget *widget,
109 * GtkStyleContext *context;
111 * context = gtk_widget_get_style_context (widget);
113 * gtk_style_context_push_animatable_region (context,
114 * GUINT_TO_POINTER (REGION_ENTRY));
116 * gtk_render_background (cr, 0, 0, 100, 30);
117 * gtk_render_frame (cr, 0, 0, 100, 30);
119 * gtk_style_context_pop_animatable_region (context);
126 * For complex widgets with an arbitrary number of animatable regions, it
127 * is up to the implementation to come up with a way to uniquely identify
128 * each animatable region. Using pointers to internal structs is one way
132 * <title>Using struct pointers to identify animatable regions</title>
135 * notebook_draw_tab (GtkWidget *widget,
136 * NotebookPage *page,
139 * gtk_style_context_push_animatable_region (context, page);
140 * gtk_render_extension (cr, page->x, page->y, page->width, page->height);
141 * gtk_style_context_pop_animatable_region (context);
146 * The widget also needs to notify the style context about a state change
147 * for a given animatable region so the animation is triggered.
150 * <title>Triggering a state change animation on a region</title>
153 * notebook_motion_notify (GtkWidget *widget,
154 * GdkEventMotion *event)
156 * GtkStyleContext *context;
157 * NotebookPage *page;
159 * context = gtk_widget_get_style_context (widget);
160 * page = find_page_under_pointer (widget, event);
161 * gtk_style_context_notify_state_change (context,
162 * gtk_widget_get_window (widget),
164 * GTK_STATE_PRELIGHT,
171 * gtk_style_context_notify_state_change() accepts %NULL region IDs as a
172 * special value, in this case, the whole widget area will be updated
176 * <refsect2 id="gtkstylecontext-classes">
177 * <title>Style classes and regions</title>
179 * Widgets can add style classes to their context, which can be used
180 * to associate different styles by class (see <xref linkend="gtkcssprovider-selectors"/>). Theme engines can also use style classes to vary their
181 * rendering. GTK+ has a number of predefined style classes:
182 * #GTK_STYLE_CLASS_CELL,
183 * #GTK_STYLE_CLASS_ENTRY,
184 * #GTK_STYLE_CLASS_BUTTON,
185 * #GTK_STYLE_CLASS_COMBOBOX_ENTRY,
186 * #GTK_STYLE_CLASS_CALENDAR,
187 * #GTK_STYLE_CLASS_SLIDER,
188 * #GTK_STYLE_CLASS_BACKGROUND,
189 * #GTK_STYLE_CLASS_RUBBERBAND,
190 * #GTK_STYLE_CLASS_TOOLTIP,
191 * #GTK_STYLE_CLASS_MENU,
192 * #GTK_STYLE_CLASS_MENUBAR,
193 * #GTK_STYLE_CLASS_MENUITEM,
194 * #GTK_STYLE_CLASS_TOOLBAR,
195 * #GTK_STYLE_CLASS_PRIMARY_TOOLBAR,
196 * #GTK_STYLE_CLASS_INLINE_TOOLBAR,
197 * #GTK_STYLE_CLASS_RADIO,
198 * #GTK_STYLE_CLASS_CHECK,
199 * #GTK_STYLE_CLASS_TROUGH,
200 * #GTK_STYLE_CLASS_SCROLLBAR,
201 * #GTK_STYLE_CLASS_SCALE,
202 * #GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE,
203 * #GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW,
204 * #GTK_STYLE_CLASS_HEADER,
205 * #GTK_STYLE_CLASS_ACCELERATOR,
206 * #GTK_STYLE_CLASS_GRIP,
207 * #GTK_STYLE_CLASS_DOCK,
208 * #GTK_STYLE_CLASS_PROGRESSBAR,
209 * #GTK_STYLE_CLASS_SPINNER,
210 * #GTK_STYLE_CLASS_EXPANDER,
211 * #GTK_STYLE_CLASS_SPINBUTTON,
212 * #GTK_STYLE_CLASS_NOTEBOOK,
213 * #GTK_STYLE_CLASS_VIEW,
214 * #GTK_STYLE_CLASS_SIDEBAR,
215 * #GTK_STYLE_CLASS_IMAGE,
216 * #GTK_STYLE_CLASS_HIGHLIGHT,
217 * #GTK_STYLE_CLASS_FRAME,
218 * #GTK_STYLE_CLASS_DND,
219 * #GTK_STYLE_CLASS_PANE_SEPARATOR,
220 * #GTK_STYLE_CLASS_SEPARATOR,
221 * #GTK_STYLE_CLASS_INFO,
222 * #GTK_STYLE_CLASS_WARNING,
223 * #GTK_STYLE_CLASS_QUESTION,
224 * #GTK_STYLE_CLASS_ERROR,
225 * #GTK_STYLE_CLASS_HORIZONTAL,
226 * #GTK_STYLE_CLASS_VERTICAL,
227 * #GTK_STYLE_CLASS_TOP,
228 * #GTK_STYLE_CLASS_BOTTOM,
229 * #GTK_STYLE_CLASS_LEFT,
230 * #GTK_STYLE_CLASS_RIGHT,
233 * Widgets can also add regions with flags to their context.
234 * The regions used by GTK+ widgets are:
239 * <entry>Region</entry>
240 * <entry>Flags</entry>
241 * <entry>Macro</entry>
242 * <entry>Used by</entry>
248 * <entry>even, odd</entry>
249 * <entry>GTK_STYLE_REGION_ROW</entry>
250 * <entry>#GtkTreeView</entry>
253 * <entry>column</entry>
254 * <entry>first, last, sorted</entry>
255 * <entry>GTK_STYLE_REGION_COLUMN</entry>
256 * <entry>#GtkTreeView</entry>
259 * <entry>column-header</entry>
261 * <entry>GTK_STYLE_REGION_COLUMN_HEADER</entry>
266 * <entry>even, odd, first, last</entry>
267 * <entry>GTK_STYLE_REGION_TAB</entry>
268 * <entry>#GtkNotebook</entry>
275 * <refsect2 id="gtkstylecontext-custom-styling">
276 * <title>Custom styling in UI libraries and applications</title>
278 * If you are developing a library with custom #GtkWidget<!-- -->s that
279 * render differently than standard components, you may need to add a
280 * #GtkStyleProvider yourself with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK
281 * priority, either a #GtkCssProvider or a custom object implementing the
282 * #GtkStyleProvider interface. This way theming engines may still attempt
283 * to style your UI elements in a different way if needed so.
286 * If you are using custom styling on an applications, you probably want then
287 * to make your style information prevail to the theme's, so you must use
288 * a #GtkStyleProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
289 * priority, keep in mind that the user settings in
290 * <filename><replaceable>XDG_CONFIG_HOME</replaceable>/gtk-3.0/gtk.css</filename> will
291 * still take precedence over your changes, as it uses the
292 * %GTK_STYLE_PROVIDER_PRIORITY_USER priority.
295 * If a custom theming engine is needed, you probably want to implement a
296 * #GtkStyleProvider yourself so it points to your #GtkThemingEngine
297 * implementation, as #GtkCssProvider uses gtk_theming_engine_load()
298 * which loads the theming engine module from the standard paths.
303 typedef struct GtkStyleProviderData GtkStyleProviderData;
304 typedef struct GtkStyleInfo GtkStyleInfo;
305 typedef struct GtkRegion GtkRegion;
306 typedef struct PropertyValue PropertyValue;
307 typedef struct AnimationInfo AnimationInfo;
308 typedef struct StyleData StyleData;
313 GtkRegionFlags flags;
316 struct GtkStyleProviderData
318 GtkStyleProvider *provider;
332 GArray *style_classes;
334 GtkJunctionSides junction_sides;
335 GtkStateFlags state_flags;
340 GtkCssComputedValues *store;
341 GSList *icon_factories;
342 GArray *property_cache;
347 GtkTimeline *timeline;
351 /* Region stack (until region_id) at the time of
352 * rendering, this is used for nested cancellation.
354 GSList *parent_regions;
358 gboolean target_value;
360 cairo_region_t *invalidation_region;
364 struct _GtkStyleContextPrivate
369 GList *providers_last;
371 GtkStyleContext *parent;
372 GtkWidgetPath *widget_path;
373 GHashTable *style_data;
375 StyleData *current_data;
376 GtkStateFlags current_state;
378 GSList *animation_regions;
381 GtkThemingEngine *theming_engine;
383 GtkTextDirection direction;
385 guint animations_invalidated : 1;
386 guint invalidating_context : 1;
401 static guint signals[LAST_SIGNAL] = { 0 };
403 static GQuark provider_list_quark = 0;
405 static void gtk_style_context_finalize (GObject *object);
407 static void gtk_style_context_impl_set_property (GObject *object,
411 static void gtk_style_context_impl_get_property (GObject *object,
415 static GtkSymbolicColor *
416 gtk_style_context_color_lookup_func (gpointer contextp,
420 G_DEFINE_TYPE (GtkStyleContext, gtk_style_context, G_TYPE_OBJECT)
423 gtk_style_context_class_init (GtkStyleContextClass *klass)
425 GObjectClass *object_class = G_OBJECT_CLASS (klass);
427 object_class->finalize = gtk_style_context_finalize;
428 object_class->set_property = gtk_style_context_impl_set_property;
429 object_class->get_property = gtk_style_context_impl_get_property;
432 g_signal_new (I_("changed"),
433 G_TYPE_FROM_CLASS (object_class),
435 G_STRUCT_OFFSET (GtkStyleContextClass, changed),
437 g_cclosure_marshal_VOID__VOID,
440 g_object_class_install_property (object_class,
442 g_param_spec_object ("screen",
444 P_("The associated GdkScreen"),
446 GTK_PARAM_READWRITE));
447 g_object_class_install_property (object_class,
449 g_param_spec_enum ("direction",
451 P_("Text direction"),
452 GTK_TYPE_TEXT_DIRECTION,
454 GTK_PARAM_READWRITE));
456 * GtkStyleContext:parent:
458 * Sets or gets the style context's parent. See gtk_style_context_set_parent()
463 g_object_class_install_property (object_class,
465 g_param_spec_object ("parent",
467 P_("The parent style context"),
468 GTK_TYPE_STYLE_CONTEXT,
469 GTK_PARAM_READWRITE));
471 g_type_class_add_private (object_class, sizeof (GtkStyleContextPrivate));
474 static GtkStyleInfo *
475 style_info_new (void)
479 info = g_slice_new0 (GtkStyleInfo);
480 info->style_classes = g_array_new (FALSE, FALSE, sizeof (GQuark));
481 info->regions = g_array_new (FALSE, FALSE, sizeof (GtkRegion));
487 style_info_free (GtkStyleInfo *info)
489 g_array_free (info->style_classes, TRUE);
490 g_array_free (info->regions, TRUE);
491 g_slice_free (GtkStyleInfo, info);
494 static GtkStyleInfo *
495 style_info_copy (const GtkStyleInfo *info)
499 copy = style_info_new ();
500 g_array_insert_vals (copy->style_classes, 0,
501 info->style_classes->data,
502 info->style_classes->len);
504 g_array_insert_vals (copy->regions, 0,
508 copy->junction_sides = info->junction_sides;
509 copy->state_flags = info->state_flags;
515 style_info_hash (gconstpointer elem)
517 const GtkStyleInfo *info;
522 for (i = 0; i < info->style_classes->len; i++)
524 hash += g_array_index (info->style_classes, GQuark, i);
528 for (i = 0; i < info->regions->len; i++)
532 region = &g_array_index (info->regions, GtkRegion, i);
533 hash += region->class_quark;
534 hash += region->flags;
538 return hash ^ info->state_flags;
542 style_info_equal (gconstpointer elem1,
545 const GtkStyleInfo *info1, *info2;
550 if (info1->state_flags != info2->state_flags)
553 if (info1->junction_sides != info2->junction_sides)
556 if (info1->style_classes->len != info2->style_classes->len)
559 if (memcmp (info1->style_classes->data,
560 info2->style_classes->data,
561 info1->style_classes->len * sizeof (GQuark)) != 0)
564 if (info1->regions->len != info2->regions->len)
567 if (memcmp (info1->regions->data,
568 info2->regions->data,
569 info1->regions->len * sizeof (GtkRegion)) != 0)
576 style_data_new (void)
580 data = g_slice_new0 (StyleData);
586 clear_property_cache (StyleData *data)
590 if (!data->property_cache)
593 for (i = 0; i < data->property_cache->len; i++)
595 PropertyValue *node = &g_array_index (data->property_cache, PropertyValue, i);
597 g_param_spec_unref (node->pspec);
598 g_value_unset (&node->value);
601 g_array_free (data->property_cache, TRUE);
602 data->property_cache = NULL;
606 style_data_free (StyleData *data)
608 g_object_unref (data->store);
609 clear_property_cache (data);
611 g_slist_free_full (data->icon_factories, g_object_unref);
613 g_slice_free (StyleData, data);
617 gtk_style_context_init (GtkStyleContext *style_context)
619 GtkStyleContextPrivate *priv;
622 priv = style_context->priv = G_TYPE_INSTANCE_GET_PRIVATE (style_context,
623 GTK_TYPE_STYLE_CONTEXT,
624 GtkStyleContextPrivate);
626 priv->style_data = g_hash_table_new_full (style_info_hash,
628 (GDestroyNotify) style_info_free,
629 (GDestroyNotify) style_data_free);
630 priv->theming_engine = g_object_ref ((gpointer) gtk_theming_engine_load (NULL));
632 priv->direction = GTK_TEXT_DIR_LTR;
634 priv->screen = gdk_screen_get_default ();
636 /* Create default info store */
637 info = style_info_new ();
638 priv->info_stack = g_slist_prepend (priv->info_stack, info);
641 static GtkStyleProviderData *
642 style_provider_data_new (GtkStyleProvider *provider,
645 GtkStyleProviderData *data;
647 data = g_slice_new (GtkStyleProviderData);
648 data->provider = g_object_ref (provider);
649 data->priority = priority;
655 style_provider_data_free (GtkStyleProviderData *data)
657 g_object_unref (data->provider);
658 g_slice_free (GtkStyleProviderData, data);
662 animation_info_free (AnimationInfo *info)
664 g_object_unref (info->timeline);
665 g_object_unref (info->window);
667 if (info->invalidation_region)
668 cairo_region_destroy (info->invalidation_region);
670 g_array_free (info->rectangles, TRUE);
671 g_slist_free (info->parent_regions);
672 g_slice_free (AnimationInfo, info);
675 static AnimationInfo *
676 animation_info_lookup_by_timeline (GtkStyleContext *context,
677 GtkTimeline *timeline)
679 GtkStyleContextPrivate *priv;
683 priv = context->priv;
685 for (l = priv->animations; l; l = l->next)
689 if (info->timeline == timeline)
697 timeline_frame_cb (GtkTimeline *timeline,
701 GtkStyleContextPrivate *priv;
702 GtkStyleContext *context;
706 priv = context->priv;
707 info = animation_info_lookup_by_timeline (context, timeline);
709 g_assert (info != NULL);
711 /* Cancel transition if window is gone */
712 if (gdk_window_is_destroyed (info->window) ||
713 !gdk_window_is_visible (info->window))
715 priv->animations = g_slist_remove (priv->animations, info);
716 animation_info_free (info);
720 if (info->invalidation_region &&
721 !cairo_region_is_empty (info->invalidation_region))
722 gdk_window_invalidate_region (info->window, info->invalidation_region, TRUE);
724 gdk_window_invalidate_rect (info->window, NULL, TRUE);
728 timeline_finished_cb (GtkTimeline *timeline,
731 GtkStyleContextPrivate *priv;
732 GtkStyleContext *context;
736 priv = context->priv;
737 info = animation_info_lookup_by_timeline (context, timeline);
739 g_assert (info != NULL);
741 priv->animations = g_slist_remove (priv->animations, info);
743 /* Invalidate one last time the area, so the final content is painted */
744 if (info->invalidation_region &&
745 !cairo_region_is_empty (info->invalidation_region))
746 gdk_window_invalidate_region (info->window, info->invalidation_region, TRUE);
748 gdk_window_invalidate_rect (info->window, NULL, TRUE);
750 animation_info_free (info);
753 static AnimationInfo *
754 animation_info_new (GtkStyleContext *context,
757 GtkTimelineProgressType progress_type,
760 gboolean target_value,
765 info = g_slice_new0 (AnimationInfo);
767 info->rectangles = g_array_new (FALSE, FALSE, sizeof (cairo_rectangle_int_t));
768 info->timeline = _gtk_timeline_new (duration);
769 info->window = g_object_ref (window);
771 info->target_value = target_value;
772 info->region_id = region_id;
774 _gtk_timeline_set_progress_type (info->timeline, progress_type);
775 _gtk_timeline_set_loop (info->timeline, loop);
777 if (!loop && !target_value)
779 _gtk_timeline_set_direction (info->timeline, GTK_TIMELINE_DIRECTION_BACKWARD);
780 _gtk_timeline_rewind (info->timeline);
783 g_signal_connect (info->timeline, "frame",
784 G_CALLBACK (timeline_frame_cb), context);
785 g_signal_connect (info->timeline, "finished",
786 G_CALLBACK (timeline_finished_cb), context);
788 _gtk_timeline_start (info->timeline);
793 static AnimationInfo *
794 animation_info_lookup (GtkStyleContext *context,
798 GtkStyleContextPrivate *priv;
801 priv = context->priv;
803 for (l = priv->animations; l; l = l->next)
809 if (info->state == state &&
810 info->region_id == region_id)
818 gtk_style_context_finalize (GObject *object)
820 GtkStyleContextPrivate *priv;
821 GtkStyleContext *style_context;
824 style_context = GTK_STYLE_CONTEXT (object);
825 priv = style_context->priv;
827 gtk_style_context_set_parent (style_context, NULL);
829 if (priv->widget_path)
830 gtk_widget_path_free (priv->widget_path);
832 g_hash_table_destroy (priv->style_data);
834 g_list_free_full (priv->providers, (GDestroyNotify) style_provider_data_free);
836 g_slist_free_full (priv->info_stack, (GDestroyNotify) style_info_free);
838 g_slist_free (priv->animation_regions);
840 for (l = priv->animations; l; l = l->next)
841 animation_info_free ((AnimationInfo *) l->data);
843 g_slist_free (priv->animations);
845 if (priv->theming_engine)
846 g_object_unref (priv->theming_engine);
848 G_OBJECT_CLASS (gtk_style_context_parent_class)->finalize (object);
852 gtk_style_context_impl_set_property (GObject *object,
857 GtkStyleContext *style_context;
859 style_context = GTK_STYLE_CONTEXT (object);
864 gtk_style_context_set_screen (style_context,
865 g_value_get_object (value));
868 gtk_style_context_set_direction (style_context,
869 g_value_get_enum (value));
872 gtk_style_context_set_parent (style_context,
873 g_value_get_object (value));
876 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
882 gtk_style_context_impl_get_property (GObject *object,
887 GtkStyleContext *style_context;
888 GtkStyleContextPrivate *priv;
890 style_context = GTK_STYLE_CONTEXT (object);
891 priv = style_context->priv;
896 g_value_set_object (value, priv->screen);
899 g_value_set_enum (value, priv->direction);
902 g_value_set_object (value, priv->parent);
905 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
911 find_next_candidate (GList *local,
916 GtkStyleProviderData *local_data, *global_data;
918 local_data = local->data;
919 global_data = global->data;
921 if (local_data->priority < global_data->priority)
935 build_properties (GtkStyleContext *context,
936 StyleData *style_data,
940 GtkStyleContextPrivate *priv;
941 GList *elem, *list, *global_list = NULL;
942 GtkCssLookup *lookup;
944 priv = context->priv;
945 list = priv->providers_last;
949 global_list = g_object_get_qdata (G_OBJECT (priv->screen), provider_list_quark);
950 global_list = g_list_last (global_list);
953 lookup = _gtk_css_lookup_new ();
955 while ((elem = find_next_candidate (list, global_list)) != NULL)
957 GtkStyleProviderData *data;
958 GtkStyleProperties *provider_style;
965 global_list = global_list->prev;
967 if (GTK_IS_STYLE_PROVIDER_PRIVATE (data->provider))
969 _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (data->provider),
976 provider_style = gtk_style_provider_get_style (data->provider, path);
980 _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (provider_style),
984 g_object_unref (provider_style);
989 style_data->store = _gtk_css_computed_values_new ();
990 _gtk_css_lookup_resolve (lookup, context, style_data->store);
991 _gtk_css_lookup_free (lookup);
995 build_icon_factories (GtkStyleContext *context,
996 StyleData *style_data,
999 GtkStyleContextPrivate *priv;
1000 GList *elem, *list, *global_list = NULL;
1002 priv = context->priv;
1003 list = priv->providers_last;
1007 global_list = g_object_get_qdata (G_OBJECT (priv->screen), provider_list_quark);
1008 global_list = g_list_last (global_list);
1011 while ((elem = find_next_candidate (list, global_list)) != NULL)
1013 GtkIconFactory *factory;
1014 GtkStyleProviderData *data;
1021 global_list = global_list->prev;
1023 factory = gtk_style_provider_get_icon_factory (data->provider, path);
1026 style_data->icon_factories = g_slist_prepend (style_data->icon_factories, factory);
1030 static GtkWidgetPath *
1031 create_query_path (GtkStyleContext *context)
1033 GtkStyleContextPrivate *priv;
1034 GtkWidgetPath *path;
1038 priv = context->priv;
1039 path = gtk_widget_path_copy (priv->widget_path);
1040 pos = gtk_widget_path_length (path) - 1;
1042 info = priv->info_stack->data;
1044 /* Set widget regions */
1045 for (i = 0; i < info->regions->len; i++)
1049 region = &g_array_index (info->regions, GtkRegion, i);
1050 gtk_widget_path_iter_add_region (path, pos,
1051 g_quark_to_string (region->class_quark),
1055 /* Set widget classes */
1056 for (i = 0; i < info->style_classes->len; i++)
1060 quark = g_array_index (info->style_classes, GQuark, i);
1061 gtk_widget_path_iter_add_class (path, pos,
1062 g_quark_to_string (quark));
1069 style_data_lookup (GtkStyleContext *context,
1070 GtkStateFlags state)
1072 GtkStyleContextPrivate *priv;
1074 gboolean state_mismatch;
1077 priv = context->priv;
1078 state_mismatch = ((GtkStyleInfo *) priv->info_stack->data)->state_flags != state;
1080 /* Current data in use is cached, just return it */
1081 if (priv->current_data && priv->current_state == state)
1082 return priv->current_data;
1084 g_assert (priv->widget_path != NULL);
1086 if (G_UNLIKELY (state_mismatch))
1088 gtk_style_context_save (context);
1089 gtk_style_context_set_state (context, state);
1092 priv->current_data = g_hash_table_lookup (priv->style_data, priv->info_stack->data);
1093 priv->current_state = state;
1095 if (!priv->current_data)
1097 GtkWidgetPath *path;
1099 priv->current_data = style_data_new ();
1100 g_hash_table_insert (priv->style_data,
1101 style_info_copy (priv->info_stack->data),
1102 priv->current_data);
1104 path = create_query_path (context);
1106 build_properties (context, priv->current_data, path, state);
1107 build_icon_factories (context, priv->current_data, path);
1109 gtk_widget_path_free (path);
1112 data = priv->current_data;
1114 if (priv->theming_engine)
1115 g_object_unref (priv->theming_engine);
1117 v = _gtk_css_computed_values_get_value_by_name (priv->current_data->store, "engine");
1119 priv->theming_engine = _gtk_css_value_dup_object (v);
1121 priv->theming_engine = g_object_ref (gtk_theming_engine_load (NULL));
1123 if (G_UNLIKELY (state_mismatch))
1124 gtk_style_context_restore (context);
1130 style_provider_add (GList **list,
1131 GtkStyleProvider *provider,
1134 GtkStyleProviderData *new_data;
1135 gboolean added = FALSE;
1138 new_data = style_provider_data_new (provider, priority);
1142 GtkStyleProviderData *data;
1146 /* Provider was already attached to the style
1147 * context, remove in order to add the new data
1149 if (data->provider == provider)
1156 /* Remove and free link */
1157 *list = g_list_remove_link (*list, link);
1158 style_provider_data_free (link->data);
1159 g_list_free_1 (link);
1165 data->priority > priority)
1167 *list = g_list_insert_before (*list, l, new_data);
1175 *list = g_list_append (*list, new_data);
1179 style_provider_remove (GList **list,
1180 GtkStyleProvider *provider)
1186 GtkStyleProviderData *data;
1190 if (data->provider == provider)
1192 *list = g_list_remove_link (*list, l);
1193 style_provider_data_free (l->data);
1206 * gtk_style_context_new:
1208 * Creates a standalone #GtkStyleContext, this style context
1209 * won't be attached to any widget, so you may want
1210 * to call gtk_style_context_set_path() yourself.
1213 * This function is only useful when using the theming layer
1214 * separated from GTK+, if you are using #GtkStyleContext to
1215 * theme #GtkWidget<!-- -->s, use gtk_widget_get_style_context()
1216 * in order to get a style context ready to theme the widget.
1219 * Returns: A newly created #GtkStyleContext.
1222 gtk_style_context_new (void)
1224 return g_object_new (GTK_TYPE_STYLE_CONTEXT, NULL);
1228 * gtk_style_context_add_provider:
1229 * @context: a #GtkStyleContext
1230 * @provider: a #GtkStyleProvider
1231 * @priority: the priority of the style provider. The lower
1232 * it is, the earlier it will be used in the style
1233 * construction. Typically this will be in the range
1234 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1235 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1237 * Adds a style provider to @context, to be used in style construction.
1239 * <note><para>If both priorities are the same, A #GtkStyleProvider
1240 * added through this function takes precedence over another added
1241 * through gtk_style_context_add_provider_for_screen().</para></note>
1246 gtk_style_context_add_provider (GtkStyleContext *context,
1247 GtkStyleProvider *provider,
1250 GtkStyleContextPrivate *priv;
1252 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1253 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1255 priv = context->priv;
1256 style_provider_add (&priv->providers, provider, priority);
1257 priv->providers_last = g_list_last (priv->providers);
1259 gtk_style_context_invalidate (context);
1263 * gtk_style_context_remove_provider:
1264 * @context: a #GtkStyleContext
1265 * @provider: a #GtkStyleProvider
1267 * Removes @provider from the style providers list in @context.
1272 gtk_style_context_remove_provider (GtkStyleContext *context,
1273 GtkStyleProvider *provider)
1275 GtkStyleContextPrivate *priv;
1277 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1278 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1280 priv = context->priv;
1282 if (style_provider_remove (&priv->providers, provider))
1284 priv->providers_last = g_list_last (priv->providers);
1286 gtk_style_context_invalidate (context);
1291 * gtk_style_context_reset_widgets:
1292 * @screen: a #GdkScreen
1294 * This function recomputes the styles for all widgets under a particular
1295 * #GdkScreen. This is useful when some global parameter has changed that
1296 * affects the appearance of all widgets, because when a widget gets a new
1297 * style, it will both redraw and recompute any cached information about
1298 * its appearance. As an example, it is used when the color scheme changes
1299 * in the related #GtkSettings object.
1304 gtk_style_context_reset_widgets (GdkScreen *screen)
1306 GList *list, *toplevels;
1308 _gtk_icon_set_invalidate_caches ();
1310 toplevels = gtk_window_list_toplevels ();
1311 g_list_foreach (toplevels, (GFunc) g_object_ref, NULL);
1313 for (list = toplevels; list; list = list->next)
1315 if (gtk_widget_get_screen (list->data) == screen)
1316 gtk_widget_reset_style (list->data);
1318 g_object_unref (list->data);
1321 g_list_free (toplevels);
1325 * gtk_style_context_add_provider_for_screen:
1326 * @screen: a #GdkScreen
1327 * @provider: a #GtkStyleProvider
1328 * @priority: the priority of the style provider. The lower
1329 * it is, the earlier it will be used in the style
1330 * construction. Typically this will be in the range
1331 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1332 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1334 * Adds a global style provider to @screen, which will be used
1335 * in style construction for all #GtkStyleContext<!-- -->s under
1338 * GTK+ uses this to make styling information from #GtkSettings
1341 * <note><para>If both priorities are the same, A #GtkStyleProvider
1342 * added through gtk_style_context_add_provider() takes precedence
1343 * over another added through this function.</para></note>
1348 gtk_style_context_add_provider_for_screen (GdkScreen *screen,
1349 GtkStyleProvider *provider,
1352 GList *providers, *list;
1354 g_return_if_fail (GDK_IS_SCREEN (screen));
1355 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1357 if (G_UNLIKELY (!provider_list_quark))
1358 provider_list_quark = g_quark_from_static_string ("gtk-provider-list-quark");
1360 list = providers = g_object_get_qdata (G_OBJECT (screen), provider_list_quark);
1361 style_provider_add (&list, provider, priority);
1363 if (list != providers)
1364 g_object_set_qdata (G_OBJECT (screen), provider_list_quark, list);
1366 gtk_style_context_reset_widgets (screen);
1370 * gtk_style_context_remove_provider_for_screen:
1371 * @screen: a #GdkScreen
1372 * @provider: a #GtkStyleProvider
1374 * Removes @provider from the global style providers list in @screen.
1379 gtk_style_context_remove_provider_for_screen (GdkScreen *screen,
1380 GtkStyleProvider *provider)
1382 GList *providers, *list;
1384 g_return_if_fail (GDK_IS_SCREEN (screen));
1385 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1387 if (G_UNLIKELY (!provider_list_quark))
1390 list = providers = g_object_get_qdata (G_OBJECT (screen), provider_list_quark);
1392 if (style_provider_remove (&list, provider))
1394 if (list != providers)
1395 g_object_set_qdata (G_OBJECT (screen), provider_list_quark, list);
1397 gtk_style_context_reset_widgets (screen);
1402 * gtk_style_context_get_section:
1403 * @context: a #GtkStyleContext
1404 * @property: style property name
1406 * Queries the location in the CSS where @property was defined for the
1407 * current @context. Note that the state to be queried is taken from
1408 * gtk_style_context_get_state().
1410 * If the location is not available, %NULL will be returned. The
1411 * location might not be available for various reasons, such as the
1412 * property being overridden, @property not naming a supported CSS
1413 * property or tracking of definitions being disabled for performance
1416 * Shorthand CSS properties cannot be queried for a location and will
1417 * always return %NULL.
1419 * Returns: %NULL or the section where value was defined
1422 gtk_style_context_get_section (GtkStyleContext *context,
1423 const gchar *property)
1425 GtkStyleContextPrivate *priv;
1426 GtkStyleProperty *prop;
1429 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1430 g_return_val_if_fail (property != NULL, NULL);
1432 priv = context->priv;
1433 g_return_val_if_fail (priv->widget_path != NULL, NULL);
1435 prop = _gtk_style_property_lookup (property);
1436 if (!GTK_IS_CSS_STYLE_PROPERTY (prop))
1439 data = style_data_lookup (context, gtk_style_context_get_state (context));
1440 return _gtk_css_computed_values_get_section (data->store, _gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (prop)));
1443 static GtkCssValue *
1444 gtk_style_context_query_func (guint id,
1447 return _gtk_css_computed_values_get_value (values, id);
1451 * gtk_style_context_get_property:
1452 * @context: a #GtkStyleContext
1453 * @property: style property name
1454 * @state: state to retrieve the property value for
1455 * @value: (out) (transfer full): return location for the style property value
1457 * Gets a style property from @context for the given state.
1459 * When @value is no longer needed, g_value_unset() must be called
1460 * to free any allocated memory.
1465 gtk_style_context_get_property (GtkStyleContext *context,
1466 const gchar *property,
1467 GtkStateFlags state,
1470 GtkStyleContextPrivate *priv;
1471 GtkStyleProperty *prop;
1475 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1476 g_return_if_fail (property != NULL);
1477 g_return_if_fail (value != NULL);
1479 priv = context->priv;
1480 g_return_if_fail (priv->widget_path != NULL);
1482 prop = _gtk_style_property_lookup (property);
1485 g_warning ("Style property \"%s\" is not registered", property);
1488 if (_gtk_style_property_get_value_type (prop) == G_TYPE_NONE)
1490 g_warning ("Style property \"%s\" is not gettable", property);
1494 data = style_data_lookup (context, state);
1495 v = _gtk_style_property_query (prop, gtk_style_context_query_func, data->store);
1496 _gtk_css_value_init_gvalue (v, value);
1497 _gtk_css_value_unref (v);
1501 * gtk_style_context_get_valist:
1502 * @context: a #GtkStyleContext
1503 * @state: state to retrieve the property values for
1504 * @args: va_list of property name/return location pairs, followed by %NULL
1506 * Retrieves several style property values from @context for a given state.
1511 gtk_style_context_get_valist (GtkStyleContext *context,
1512 GtkStateFlags state,
1515 const gchar *property_name;
1517 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1519 property_name = va_arg (args, const gchar *);
1521 while (property_name)
1523 gchar *error = NULL;
1524 GValue value = G_VALUE_INIT;
1526 gtk_style_context_get_property (context,
1531 G_VALUE_LCOPY (&value, args, 0, &error);
1532 g_value_unset (&value);
1536 g_warning ("Could not get style property \"%s\": %s", property_name, error);
1541 property_name = va_arg (args, const gchar *);
1546 * gtk_style_context_get:
1547 * @context: a #GtkStyleContext
1548 * @state: state to retrieve the property values for
1549 * @...: property name /return value pairs, followed by %NULL
1551 * Retrieves several style property values from @context for a
1557 gtk_style_context_get (GtkStyleContext *context,
1558 GtkStateFlags state,
1563 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1565 va_start (args, state);
1566 gtk_style_context_get_valist (context, state, args);
1571 * gtk_style_context_set_state:
1572 * @context: a #GtkStyleContext
1573 * @flags: state to represent
1575 * Sets the state to be used when rendering with any
1576 * of the gtk_render_*() functions.
1581 gtk_style_context_set_state (GtkStyleContext *context,
1582 GtkStateFlags flags)
1584 GtkStyleContextPrivate *priv;
1587 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1589 priv = context->priv;
1590 info = priv->info_stack->data;
1591 info->state_flags = flags;
1595 * gtk_style_context_get_state:
1596 * @context: a #GtkStyleContext
1598 * Returns the state used when rendering.
1600 * Returns: the state flags
1605 gtk_style_context_get_state (GtkStyleContext *context)
1607 GtkStyleContextPrivate *priv;
1610 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
1612 priv = context->priv;
1613 info = priv->info_stack->data;
1615 return info->state_flags;
1619 context_has_animatable_region (GtkStyleContext *context,
1622 GtkStyleContextPrivate *priv;
1624 /* NULL region_id means everything
1625 * rendered through the style context
1630 priv = context->priv;
1631 return g_slist_find (priv->animation_regions, region_id) != NULL;
1635 * gtk_style_context_state_is_running:
1636 * @context: a #GtkStyleContext
1637 * @state: a widget state
1638 * @progress: (out): return location for the transition progress
1640 * Returns %TRUE if there is a transition animation running for the
1641 * current region (see gtk_style_context_push_animatable_region()).
1643 * If @progress is not %NULL, the animation progress will be returned
1644 * there, 0.0 means the state is closest to being unset, while 1.0 means
1645 * it's closest to being set. This means transition animation will
1646 * run from 0 to 1 when @state is being set and from 1 to 0 when
1649 * Returns: %TRUE if there is a running transition animation for @state.
1654 gtk_style_context_state_is_running (GtkStyleContext *context,
1658 GtkStyleContextPrivate *priv;
1659 AnimationInfo *info;
1662 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1664 priv = context->priv;
1666 for (l = priv->animations; l; l = l->next)
1670 if (info->state == state &&
1671 context_has_animatable_region (context, info->region_id))
1674 *progress = _gtk_timeline_get_progress (info->timeline);
1684 * gtk_style_context_set_path:
1685 * @context: a #GtkStyleContext
1686 * @path: a #GtkWidgetPath
1688 * Sets the #GtkWidgetPath used for style matching. As a
1689 * consequence, the style will be regenerated to match
1690 * the new given path.
1692 * If you are using a #GtkStyleContext returned from
1693 * gtk_widget_get_style_context(), you do not need to call
1699 gtk_style_context_set_path (GtkStyleContext *context,
1700 GtkWidgetPath *path)
1702 GtkStyleContextPrivate *priv;
1704 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1705 g_return_if_fail (path != NULL);
1707 priv = context->priv;
1709 if (priv->widget_path)
1711 gtk_widget_path_free (priv->widget_path);
1712 priv->widget_path = NULL;
1716 priv->widget_path = gtk_widget_path_copy (path);
1718 gtk_style_context_invalidate (context);
1722 * gtk_style_context_get_path:
1723 * @context: a #GtkStyleContext
1725 * Returns the widget path used for style matching.
1727 * Returns: (transfer none): A #GtkWidgetPath
1731 const GtkWidgetPath *
1732 gtk_style_context_get_path (GtkStyleContext *context)
1734 GtkStyleContextPrivate *priv;
1736 priv = context->priv;
1737 return priv->widget_path;
1741 * gtk_style_context_set_parent:
1742 * @context: a #GtkStyleContext
1743 * @parent: (allow-none): the new parent or %NULL
1745 * Sets the parent style context for @context. The parent style
1746 * context is used to implement
1747 * <ulink url="http://www.w3.org/TR/css3-cascade/#inheritance">inheritance</ulink>
1750 * If you are using a #GtkStyleContext returned from
1751 * gtk_widget_get_style_context(), the parent will be set for you.
1756 gtk_style_context_set_parent (GtkStyleContext *context,
1757 GtkStyleContext *parent)
1759 GtkStyleContextPrivate *priv;
1761 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1762 g_return_if_fail (parent == NULL || GTK_IS_STYLE_CONTEXT (parent));
1764 priv = context->priv;
1766 if (priv->parent == parent)
1770 g_object_ref (parent);
1773 g_object_unref (priv->parent);
1775 priv->parent = parent;
1777 g_object_notify (G_OBJECT (context), "parent");
1778 gtk_style_context_invalidate (context);
1782 * gtk_style_context_get_parent:
1783 * @context: a #GtkStyleContext
1785 * Gets the parent context set via gtk_style_context_set_parent().
1786 * See that function for details.
1788 * Returns: (transfer none): the parent context or %NULL
1793 gtk_style_context_get_parent (GtkStyleContext *context)
1795 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1797 return context->priv->parent;
1801 * gtk_style_context_save:
1802 * @context: a #GtkStyleContext
1804 * Saves the @context state, so all modifications done through
1805 * gtk_style_context_add_class(), gtk_style_context_remove_class(),
1806 * gtk_style_context_add_region(), gtk_style_context_remove_region()
1807 * or gtk_style_context_set_junction_sides() can be reverted in one
1808 * go through gtk_style_context_restore().
1813 gtk_style_context_save (GtkStyleContext *context)
1815 GtkStyleContextPrivate *priv;
1818 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1820 priv = context->priv;
1822 g_assert (priv->info_stack != NULL);
1824 info = style_info_copy (priv->info_stack->data);
1825 priv->info_stack = g_slist_prepend (priv->info_stack, info);
1829 * gtk_style_context_restore:
1830 * @context: a #GtkStyleContext
1832 * Restores @context state to a previous stage.
1833 * See gtk_style_context_save().
1838 gtk_style_context_restore (GtkStyleContext *context)
1840 GtkStyleContextPrivate *priv;
1843 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1845 priv = context->priv;
1847 if (priv->info_stack)
1849 info = priv->info_stack->data;
1850 priv->info_stack = g_slist_remove (priv->info_stack, info);
1851 style_info_free (info);
1854 if (!priv->info_stack)
1856 g_warning ("Unpaired gtk_style_context_restore() call");
1858 /* Create default region */
1859 info = style_info_new ();
1860 priv->info_stack = g_slist_prepend (priv->info_stack, info);
1863 priv->current_data = NULL;
1867 style_class_find (GArray *array,
1872 gboolean found = FALSE;
1878 if (!array || array->len == 0)
1882 max = array->len - 1;
1888 mid = (min + max) / 2;
1889 item = g_array_index (array, GQuark, mid);
1891 if (class_quark == item)
1896 else if (class_quark > item)
1897 min = pos = mid + 1;
1904 while (!found && min <= max);
1913 region_find (GArray *array,
1918 gboolean found = FALSE;
1924 if (!array || array->len == 0)
1928 max = array->len - 1;
1934 mid = (min + max) / 2;
1935 region = &g_array_index (array, GtkRegion, mid);
1937 if (region->class_quark == class_quark)
1942 else if (region->class_quark > class_quark)
1943 min = pos = mid + 1;
1950 while (!found && min <= max);
1959 * gtk_style_context_add_class:
1960 * @context: a #GtkStyleContext
1961 * @class_name: class name to use in styling
1963 * Adds a style class to @context, so posterior calls to
1964 * gtk_style_context_get() or any of the gtk_render_*()
1965 * functions will make use of this new class for styling.
1967 * In the CSS file format, a #GtkEntry defining an "entry"
1968 * class, would be matched by:
1971 * GtkEntry.entry { ... }
1974 * While any widget defining an "entry" class would be
1983 gtk_style_context_add_class (GtkStyleContext *context,
1984 const gchar *class_name)
1986 GtkStyleContextPrivate *priv;
1991 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1992 g_return_if_fail (class_name != NULL);
1994 priv = context->priv;
1995 class_quark = g_quark_from_string (class_name);
1997 g_assert (priv->info_stack != NULL);
1998 info = priv->info_stack->data;
2000 if (!style_class_find (info->style_classes, class_quark, &position))
2002 g_array_insert_val (info->style_classes, position, class_quark);
2004 /* Unset current data, as it likely changed due to the class change */
2005 priv->current_data = NULL;
2010 * gtk_style_context_remove_class:
2011 * @context: a #GtkStyleContext
2012 * @class_name: class name to remove
2014 * Removes @class_name from @context.
2019 gtk_style_context_remove_class (GtkStyleContext *context,
2020 const gchar *class_name)
2022 GtkStyleContextPrivate *priv;
2027 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2028 g_return_if_fail (class_name != NULL);
2030 class_quark = g_quark_try_string (class_name);
2035 priv = context->priv;
2037 g_assert (priv->info_stack != NULL);
2038 info = priv->info_stack->data;
2040 if (style_class_find (info->style_classes, class_quark, &position))
2042 g_array_remove_index (info->style_classes, position);
2044 /* Unset current data, as it likely changed due to the class change */
2045 priv->current_data = NULL;
2050 * gtk_style_context_has_class:
2051 * @context: a #GtkStyleContext
2052 * @class_name: a class name
2054 * Returns %TRUE if @context currently has defined the
2057 * Returns: %TRUE if @context has @class_name defined
2062 gtk_style_context_has_class (GtkStyleContext *context,
2063 const gchar *class_name)
2065 GtkStyleContextPrivate *priv;
2069 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2070 g_return_val_if_fail (class_name != NULL, FALSE);
2072 class_quark = g_quark_try_string (class_name);
2077 priv = context->priv;
2079 g_assert (priv->info_stack != NULL);
2080 info = priv->info_stack->data;
2082 if (style_class_find (info->style_classes, class_quark, NULL))
2089 * gtk_style_context_list_classes:
2090 * @context: a #GtkStyleContext
2092 * Returns the list of classes currently defined in @context.
2094 * Returns: (transfer container) (element-type utf8): a #GList of
2095 * strings with the currently defined classes. The contents
2096 * of the list are owned by GTK+, but you must free the list
2097 * itself with g_list_free() when you are done with it.
2102 gtk_style_context_list_classes (GtkStyleContext *context)
2104 GtkStyleContextPrivate *priv;
2106 GList *classes = NULL;
2109 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2111 priv = context->priv;
2113 g_assert (priv->info_stack != NULL);
2114 info = priv->info_stack->data;
2116 for (i = 0; i < info->style_classes->len; i++)
2120 quark = g_array_index (info->style_classes, GQuark, i);
2121 classes = g_list_prepend (classes, (gchar *) g_quark_to_string (quark));
2128 * gtk_style_context_list_regions:
2129 * @context: a #GtkStyleContext
2131 * Returns the list of regions currently defined in @context.
2133 * Returns: (transfer container) (element-type utf8): a #GList of
2134 * strings with the currently defined regions. The contents
2135 * of the list are owned by GTK+, but you must free the list
2136 * itself with g_list_free() when you are done with it.
2141 gtk_style_context_list_regions (GtkStyleContext *context)
2143 GtkStyleContextPrivate *priv;
2145 GList *classes = NULL;
2148 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2150 priv = context->priv;
2152 g_assert (priv->info_stack != NULL);
2153 info = priv->info_stack->data;
2155 for (i = 0; i < info->regions->len; i++)
2158 const gchar *class_name;
2160 region = &g_array_index (info->regions, GtkRegion, i);
2162 class_name = g_quark_to_string (region->class_quark);
2163 classes = g_list_prepend (classes, (gchar *) class_name);
2170 _gtk_style_context_check_region_name (const gchar *str)
2172 g_return_val_if_fail (str != NULL, FALSE);
2174 if (!g_ascii_islower (str[0]))
2180 !g_ascii_islower (*str))
2190 * gtk_style_context_add_region:
2191 * @context: a #GtkStyleContext
2192 * @region_name: region name to use in styling
2193 * @flags: flags that apply to the region
2195 * Adds a region to @context, so posterior calls to
2196 * gtk_style_context_get() or any of the gtk_render_*()
2197 * functions will make use of this new region for styling.
2199 * In the CSS file format, a #GtkTreeView defining a "row"
2200 * region, would be matched by:
2203 * GtkTreeView row { ... }
2206 * Pseudo-classes are used for matching @flags, so the two
2209 * GtkTreeView row:nth-child(even) { ... }
2210 * GtkTreeView row:nth-child(odd) { ... }
2213 * would apply to even and odd rows, respectively.
2215 * <note><para>Region names must only contain lowercase letters
2216 * and '-', starting always with a lowercase letter.</para></note>
2221 gtk_style_context_add_region (GtkStyleContext *context,
2222 const gchar *region_name,
2223 GtkRegionFlags flags)
2225 GtkStyleContextPrivate *priv;
2227 GQuark region_quark;
2230 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2231 g_return_if_fail (region_name != NULL);
2232 g_return_if_fail (_gtk_style_context_check_region_name (region_name));
2234 priv = context->priv;
2235 region_quark = g_quark_from_string (region_name);
2237 g_assert (priv->info_stack != NULL);
2238 info = priv->info_stack->data;
2240 if (!region_find (info->regions, region_quark, &position))
2244 region.class_quark = region_quark;
2245 region.flags = flags;
2247 g_array_insert_val (info->regions, position, region);
2249 /* Unset current data, as it likely changed due to the region change */
2250 priv->current_data = NULL;
2255 * gtk_style_context_remove_region:
2256 * @context: a #GtkStyleContext
2257 * @region_name: region name to unset
2259 * Removes a region from @context.
2264 gtk_style_context_remove_region (GtkStyleContext *context,
2265 const gchar *region_name)
2267 GtkStyleContextPrivate *priv;
2269 GQuark region_quark;
2272 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2273 g_return_if_fail (region_name != NULL);
2275 region_quark = g_quark_try_string (region_name);
2280 priv = context->priv;
2282 g_assert (priv->info_stack != NULL);
2283 info = priv->info_stack->data;
2285 if (region_find (info->regions, region_quark, &position))
2287 g_array_remove_index (info->regions, position);
2289 /* Unset current data, as it likely changed due to the region change */
2290 priv->current_data = NULL;
2295 * gtk_style_context_has_region:
2296 * @context: a #GtkStyleContext
2297 * @region_name: a region name
2298 * @flags_return: (out) (allow-none): return location for region flags
2300 * Returns %TRUE if @context has the region defined.
2301 * If @flags_return is not %NULL, it is set to the flags
2302 * affecting the region.
2304 * Returns: %TRUE if region is defined
2309 gtk_style_context_has_region (GtkStyleContext *context,
2310 const gchar *region_name,
2311 GtkRegionFlags *flags_return)
2313 GtkStyleContextPrivate *priv;
2315 GQuark region_quark;
2318 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2319 g_return_val_if_fail (region_name != NULL, FALSE);
2324 region_quark = g_quark_try_string (region_name);
2329 priv = context->priv;
2331 g_assert (priv->info_stack != NULL);
2332 info = priv->info_stack->data;
2334 if (region_find (info->regions, region_quark, &position))
2340 region = &g_array_index (info->regions, GtkRegion, position);
2341 *flags_return = region->flags;
2350 style_property_values_cmp (gconstpointer bsearch_node1,
2351 gconstpointer bsearch_node2)
2353 const PropertyValue *val1 = bsearch_node1;
2354 const PropertyValue *val2 = bsearch_node2;
2356 if (val1->widget_type != val2->widget_type)
2357 return val1->widget_type < val2->widget_type ? -1 : 1;
2359 if (val1->pspec != val2->pspec)
2360 return val1->pspec < val2->pspec ? -1 : 1;
2362 if (val1->state != val2->state)
2363 return val1->state < val2->state ? -1 : 1;
2369 _gtk_style_context_peek_property (GtkStyleContext *context,
2370 const char *property_name)
2372 StyleData *data = style_data_lookup (context, gtk_style_context_get_state (context));
2374 return _gtk_css_computed_values_get_value_by_name (data->store, property_name);
2378 _gtk_style_context_get_number (GtkStyleContext *context,
2379 const char *property_name,
2380 double one_hundred_percent)
2384 value = _gtk_style_context_peek_property (context, property_name);
2385 return _gtk_css_number_get (_gtk_css_value_get_number (value), one_hundred_percent);
2389 _gtk_style_context_peek_style_property (GtkStyleContext *context,
2391 GtkStateFlags state,
2394 GtkStyleContextPrivate *priv;
2395 PropertyValue *pcache, key = { 0 };
2396 GList *global_list = NULL;
2400 priv = context->priv;
2401 data = style_data_lookup (context, state);
2403 key.widget_type = widget_type;
2407 /* need value cache array */
2408 if (!data->property_cache)
2409 data->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
2412 pcache = bsearch (&key,
2413 data->property_cache->data, data->property_cache->len,
2414 sizeof (PropertyValue), style_property_values_cmp);
2416 return &pcache->value;
2420 while (i < data->property_cache->len &&
2421 style_property_values_cmp (&key, &g_array_index (data->property_cache, PropertyValue, i)) >= 0)
2424 g_array_insert_val (data->property_cache, i, key);
2425 pcache = &g_array_index (data->property_cache, PropertyValue, i);
2427 /* cache miss, initialize value type, then set contents */
2428 g_param_spec_ref (pcache->pspec);
2429 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2433 global_list = g_object_get_qdata (G_OBJECT (priv->screen), provider_list_quark);
2434 global_list = g_list_last (global_list);
2437 if (priv->widget_path)
2439 GList *list, *global, *elem;
2441 list = priv->providers_last;
2442 global = global_list;
2444 while ((elem = find_next_candidate (list, global)) != NULL)
2446 GtkStyleProviderData *provider_data;
2448 provider_data = elem->data;
2453 global = global->prev;
2455 if (gtk_style_provider_get_style_property (provider_data->provider,
2456 priv->widget_path, state,
2457 pspec, &pcache->value))
2459 /* Resolve symbolic colors to GdkColor/GdkRGBA */
2460 if (G_VALUE_TYPE (&pcache->value) == GTK_TYPE_SYMBOLIC_COLOR)
2462 GtkSymbolicColor *color;
2465 color = g_value_dup_boxed (&pcache->value);
2467 g_value_unset (&pcache->value);
2469 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2470 g_value_init (&pcache->value, GDK_TYPE_RGBA);
2472 g_value_init (&pcache->value, GDK_TYPE_COLOR);
2474 if (_gtk_style_context_resolve_color (context, color, &rgba))
2476 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2477 g_value_set_boxed (&pcache->value, &rgba);
2482 rgb.red = rgba.red * 65535. + 0.5;
2483 rgb.green = rgba.green * 65535. + 0.5;
2484 rgb.blue = rgba.blue * 65535. + 0.5;
2486 g_value_set_boxed (&pcache->value, &rgb);
2490 g_param_value_set_default (pspec, &pcache->value);
2492 gtk_symbolic_color_unref (color);
2495 return &pcache->value;
2500 /* not supplied by any provider, revert to default */
2501 g_param_value_set_default (pspec, &pcache->value);
2503 return &pcache->value;
2507 * gtk_style_context_get_style_property:
2508 * @context: a #GtkStyleContext
2509 * @property_name: the name of the widget style property
2510 * @value: Return location for the property value
2512 * Gets the value for a widget style property.
2514 * When @value is no longer needed, g_value_unset() must be called
2515 * to free any allocated memory.
2518 gtk_style_context_get_style_property (GtkStyleContext *context,
2519 const gchar *property_name,
2522 GtkStyleContextPrivate *priv;
2523 GtkWidgetClass *widget_class;
2524 GtkStateFlags state;
2526 const GValue *peek_value;
2529 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2530 g_return_if_fail (property_name != NULL);
2531 g_return_if_fail (value != NULL);
2533 priv = context->priv;
2535 if (!priv->widget_path)
2538 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2540 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2542 g_warning ("%s: can't get style properties for non-widget class `%s'",
2544 g_type_name (widget_type));
2548 widget_class = g_type_class_ref (widget_type);
2549 pspec = gtk_widget_class_find_style_property (widget_class, property_name);
2550 g_type_class_unref (widget_class);
2554 g_warning ("%s: widget class `%s' has no style property named `%s'",
2556 g_type_name (widget_type),
2561 state = gtk_style_context_get_state (context);
2562 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2565 if (G_VALUE_TYPE (value) == G_VALUE_TYPE (peek_value))
2566 g_value_copy (peek_value, value);
2567 else if (g_value_type_transformable (G_VALUE_TYPE (peek_value), G_VALUE_TYPE (value)))
2568 g_value_transform (peek_value, value);
2570 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
2572 G_VALUE_TYPE_NAME (peek_value),
2573 G_VALUE_TYPE_NAME (value));
2577 * gtk_style_context_get_style_valist:
2578 * @context: a #GtkStyleContext
2579 * @args: va_list of property name/return location pairs, followed by %NULL
2581 * Retrieves several widget style properties from @context according to the
2587 gtk_style_context_get_style_valist (GtkStyleContext *context,
2590 GtkStyleContextPrivate *priv;
2591 const gchar *prop_name;
2592 GtkStateFlags state;
2595 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2597 prop_name = va_arg (args, const gchar *);
2598 priv = context->priv;
2600 if (!priv->widget_path)
2603 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2605 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2607 g_warning ("%s: can't get style properties for non-widget class `%s'",
2609 g_type_name (widget_type));
2613 state = gtk_style_context_get_state (context);
2617 GtkWidgetClass *widget_class;
2619 const GValue *peek_value;
2622 widget_class = g_type_class_ref (widget_type);
2623 pspec = gtk_widget_class_find_style_property (widget_class, prop_name);
2624 g_type_class_unref (widget_class);
2628 g_warning ("%s: widget class `%s' has no style property named `%s'",
2630 g_type_name (widget_type),
2635 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2638 G_VALUE_LCOPY (peek_value, args, 0, &error);
2642 g_warning ("can't retrieve style property `%s' of type `%s': %s",
2644 G_VALUE_TYPE_NAME (peek_value),
2649 prop_name = va_arg (args, const gchar *);
2654 * gtk_style_context_get_style:
2655 * @context: a #GtkStyleContext
2656 * @...: property name /return value pairs, followed by %NULL
2658 * Retrieves several widget style properties from @context according to the
2664 gtk_style_context_get_style (GtkStyleContext *context,
2669 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2671 va_start (args, context);
2672 gtk_style_context_get_style_valist (context, args);
2678 * gtk_style_context_lookup_icon_set:
2679 * @context: a #GtkStyleContext
2680 * @stock_id: an icon name
2682 * Looks up @stock_id in the icon factories associated to @context and
2683 * the default icon factory, returning an icon set if found, otherwise
2686 * Returns: (transfer none): The looked up %GtkIconSet, or %NULL
2689 gtk_style_context_lookup_icon_set (GtkStyleContext *context,
2690 const gchar *stock_id)
2692 GtkStyleContextPrivate *priv;
2696 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2697 g_return_val_if_fail (stock_id != NULL, NULL);
2699 priv = context->priv;
2700 g_return_val_if_fail (priv->widget_path != NULL, NULL);
2702 data = style_data_lookup (context, 0);
2704 for (list = data->icon_factories; list; list = list->next)
2706 GtkIconFactory *factory;
2707 GtkIconSet *icon_set;
2709 factory = list->data;
2710 icon_set = gtk_icon_factory_lookup (factory, stock_id);
2716 return gtk_icon_factory_lookup_default (stock_id);
2720 * gtk_style_context_set_screen:
2721 * @context: a #GtkStyleContext
2722 * @screen: a #GdkScreen
2724 * Attaches @context to the given screen.
2726 * The screen is used to add style information from 'global' style
2727 * providers, such as the screens #GtkSettings instance.
2729 * If you are using a #GtkStyleContext returned from
2730 * gtk_widget_get_style_context(), you do not need to
2731 * call this yourself.
2736 gtk_style_context_set_screen (GtkStyleContext *context,
2739 GtkStyleContextPrivate *priv;
2741 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2742 g_return_if_fail (GDK_IS_SCREEN (screen));
2744 priv = context->priv;
2745 if (priv->screen == screen)
2748 priv->screen = screen;
2750 g_object_notify (G_OBJECT (context), "screen");
2752 gtk_style_context_invalidate (context);
2756 * gtk_style_context_get_screen:
2757 * @context: a #GtkStyleContext
2759 * Returns the #GdkScreen to which @context is attached.
2761 * Returns: (transfer none): a #GdkScreen.
2764 gtk_style_context_get_screen (GtkStyleContext *context)
2766 GtkStyleContextPrivate *priv;
2768 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2770 priv = context->priv;
2771 return priv->screen;
2775 * gtk_style_context_set_direction:
2776 * @context: a #GtkStyleContext
2777 * @direction: the new direction.
2779 * Sets the reading direction for rendering purposes.
2781 * If you are using a #GtkStyleContext returned from
2782 * gtk_widget_get_style_context(), you do not need to
2783 * call this yourself.
2788 gtk_style_context_set_direction (GtkStyleContext *context,
2789 GtkTextDirection direction)
2791 GtkStyleContextPrivate *priv;
2793 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2795 priv = context->priv;
2796 priv->direction = direction;
2798 g_object_notify (G_OBJECT (context), "direction");
2802 * gtk_style_context_get_direction:
2803 * @context: a #GtkStyleContext
2805 * Returns the widget direction used for rendering.
2807 * Returns: the widget direction
2812 gtk_style_context_get_direction (GtkStyleContext *context)
2814 GtkStyleContextPrivate *priv;
2816 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), GTK_TEXT_DIR_LTR);
2818 priv = context->priv;
2819 return priv->direction;
2823 * gtk_style_context_set_junction_sides:
2824 * @context: a #GtkStyleContext
2825 * @sides: sides where rendered elements are visually connected to
2828 * Sets the sides where rendered elements (mostly through
2829 * gtk_render_frame()) will visually connect with other visual elements.
2831 * This is merely a hint that may or may not be honored
2832 * by theming engines.
2834 * Container widgets are expected to set junction hints as appropriate
2835 * for their children, so it should not normally be necessary to call
2836 * this function manually.
2841 gtk_style_context_set_junction_sides (GtkStyleContext *context,
2842 GtkJunctionSides sides)
2844 GtkStyleContextPrivate *priv;
2847 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2849 priv = context->priv;
2850 info = priv->info_stack->data;
2851 info->junction_sides = sides;
2855 * gtk_style_context_get_junction_sides:
2856 * @context: a #GtkStyleContext
2858 * Returns the sides where rendered elements connect visually with others.
2860 * Returns: the junction sides
2865 gtk_style_context_get_junction_sides (GtkStyleContext *context)
2867 GtkStyleContextPrivate *priv;
2870 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
2872 priv = context->priv;
2873 info = priv->info_stack->data;
2874 return info->junction_sides;
2877 static GtkSymbolicColor *
2878 gtk_style_context_color_lookup_func (gpointer contextp,
2881 GtkSymbolicColor *sym_color;
2882 GtkStyleContext *context = contextp;
2883 GtkStyleContextPrivate *priv = context->priv;
2884 GList *elem, *list, *global_list = NULL;
2886 list = priv->providers_last;
2889 global_list = g_object_get_qdata (G_OBJECT (priv->screen), provider_list_quark);
2890 global_list = g_list_last (global_list);
2895 while (sym_color == NULL &&
2896 (elem = find_next_candidate (list, global_list)) != NULL)
2898 GtkStyleProviderData *data;
2905 global_list = global_list->prev;
2907 if (GTK_IS_STYLE_PROVIDER_PRIVATE (data->provider))
2909 sym_color = _gtk_style_provider_private_get_color (GTK_STYLE_PROVIDER_PRIVATE (data->provider),
2914 /* If somebody hits this code path, shout at them */
2923 _gtk_style_context_resolve_color_value (GtkStyleContext *context,
2924 GtkSymbolicColor *color)
2926 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2927 g_return_val_if_fail (color != NULL, FALSE);
2929 return _gtk_symbolic_color_resolve_full (color,
2930 gtk_style_context_color_lookup_func,
2936 _gtk_style_context_resolve_color (GtkStyleContext *context,
2937 GtkSymbolicColor *color,
2942 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2943 g_return_val_if_fail (color != NULL, FALSE);
2944 g_return_val_if_fail (result != NULL, FALSE);
2946 val = _gtk_symbolic_color_resolve_full (color,
2947 gtk_style_context_color_lookup_func,
2952 *result = *_gtk_css_value_get_rgba (val);
2953 _gtk_css_value_unref (val);
2958 * gtk_style_context_lookup_color:
2959 * @context: a #GtkStyleContext
2960 * @color_name: color name to lookup
2961 * @color: (out): Return location for the looked up color
2963 * Looks up and resolves a color name in the @context color map.
2965 * Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
2968 gtk_style_context_lookup_color (GtkStyleContext *context,
2969 const gchar *color_name,
2972 GtkSymbolicColor *sym_color;
2974 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2975 g_return_val_if_fail (color_name != NULL, FALSE);
2976 g_return_val_if_fail (color != NULL, FALSE);
2978 sym_color = gtk_style_context_color_lookup_func (context, color_name);
2979 if (sym_color == NULL)
2982 return _gtk_style_context_resolve_color (context, sym_color, color);
2986 * gtk_style_context_notify_state_change:
2987 * @context: a #GtkStyleContext
2988 * @window: a #GdkWindow
2989 * @region_id: (allow-none): animatable region to notify on, or %NULL.
2990 * See gtk_style_context_push_animatable_region()
2991 * @state: state to trigger transition for
2992 * @state_value: %TRUE if @state is the state we are changing to,
2993 * %FALSE if we are changing away from it
2995 * Notifies a state change on @context, so if the current style makes use
2996 * of transition animations, one will be started so all rendered elements
2997 * under @region_id are animated for state @state being set to value
3000 * The @window parameter is used in order to invalidate the rendered area
3001 * as the animation runs, so make sure it is the same window that is being
3002 * rendered on by the gtk_render_*() functions.
3004 * If @region_id is %NULL, all rendered elements using @context will be
3005 * affected by this state transition.
3007 * As a practical example, a #GtkButton notifying a state transition on
3008 * the prelight state:
3010 * gtk_style_context_notify_state_change (context,
3011 * gtk_widget_get_window (widget),
3013 * GTK_STATE_PRELIGHT,
3014 * button->in_button);
3017 * Can be handled in the CSS file like this:
3020 * background-color: #f00
3024 * background-color: #fff;
3025 * transition: 200ms linear
3029 * This combination will animate the button background from red to white
3030 * if a pointer enters the button, and back to red if the pointer leaves
3033 * Note that @state is used when finding the transition parameters, which
3034 * is why the style places the transition under the :hover pseudo-class.
3039 gtk_style_context_notify_state_change (GtkStyleContext *context,
3043 gboolean state_value)
3045 GtkStyleContextPrivate *priv;
3046 GtkAnimationDescription *desc;
3047 AnimationInfo *info;
3048 GtkStateFlags flags;
3052 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3053 g_return_if_fail (GDK_IS_WINDOW (window));
3054 g_return_if_fail (state > GTK_STATE_NORMAL && state <= GTK_STATE_FOCUSED);
3056 priv = context->priv;
3057 g_return_if_fail (priv->widget_path != NULL);
3059 state_value = (state_value == TRUE);
3063 case GTK_STATE_ACTIVE:
3064 flags = GTK_STATE_FLAG_ACTIVE;
3066 case GTK_STATE_PRELIGHT:
3067 flags = GTK_STATE_FLAG_PRELIGHT;
3069 case GTK_STATE_SELECTED:
3070 flags = GTK_STATE_FLAG_SELECTED;
3072 case GTK_STATE_INSENSITIVE:
3073 flags = GTK_STATE_FLAG_INSENSITIVE;
3075 case GTK_STATE_INCONSISTENT:
3076 flags = GTK_STATE_FLAG_INCONSISTENT;
3078 case GTK_STATE_FOCUSED:
3079 flags = GTK_STATE_FLAG_FOCUSED;
3081 case GTK_STATE_NORMAL:
3087 /* Find out if there is any animation description for the given
3088 * state, it will fallback to the normal state as well if necessary.
3090 data = style_data_lookup (context, flags);
3091 v = _gtk_css_computed_values_get_value_by_name (data->store, "transition");
3094 desc = _gtk_css_value_get_boxed (v);
3098 if (_gtk_animation_description_get_duration (desc) == 0)
3101 info = animation_info_lookup (context, region_id, state);
3104 info->target_value != state_value)
3106 /* Target values are the opposite */
3107 if (!_gtk_timeline_get_loop (info->timeline))
3109 /* Reverse the animation */
3110 if (_gtk_timeline_get_direction (info->timeline) == GTK_TIMELINE_DIRECTION_FORWARD)
3111 _gtk_timeline_set_direction (info->timeline, GTK_TIMELINE_DIRECTION_BACKWARD);
3113 _gtk_timeline_set_direction (info->timeline, GTK_TIMELINE_DIRECTION_FORWARD);
3115 info->target_value = state_value;
3119 /* Take it out of its looping state */
3120 _gtk_timeline_set_loop (info->timeline, FALSE);
3124 (!_gtk_animation_description_get_loop (desc) ||
3127 info = animation_info_new (context, region_id,
3128 _gtk_animation_description_get_duration (desc),
3129 _gtk_animation_description_get_progress_type (desc),
3130 _gtk_animation_description_get_loop (desc),
3131 state, state_value, window);
3133 priv->animations = g_slist_prepend (priv->animations, info);
3134 priv->animations_invalidated = TRUE;
3139 * gtk_style_context_cancel_animations:
3140 * @context: a #GtkStyleContext
3141 * @region_id: (allow-none): animatable region to stop, or %NULL.
3142 * See gtk_style_context_push_animatable_region()
3144 * Stops all running animations for @region_id and all animatable
3145 * regions underneath.
3147 * A %NULL @region_id will stop all ongoing animations in @context,
3148 * when dealing with a #GtkStyleContext obtained through
3149 * gtk_widget_get_style_context(), this is normally done for you
3150 * in all circumstances you would expect all widget to be stopped,
3151 * so this should be only used in complex widgets with different
3152 * animatable regions.
3157 gtk_style_context_cancel_animations (GtkStyleContext *context,
3160 GtkStyleContextPrivate *priv;
3161 AnimationInfo *info;
3164 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3166 priv = context->priv;
3167 l = priv->animations;
3175 info->region_id == region_id ||
3176 g_slist_find (info->parent_regions, region_id))
3178 priv->animations = g_slist_remove (priv->animations, info);
3179 animation_info_free (info);
3185 is_parent_of (GdkWindow *parent,
3188 GtkWidget *child_widget, *parent_widget;
3191 gdk_window_get_user_data (child, (gpointer *) &child_widget);
3192 gdk_window_get_user_data (parent, (gpointer *) &parent_widget);
3194 if (child_widget != parent_widget &&
3195 !gtk_widget_is_ancestor (child_widget, parent_widget))
3202 if (window == parent)
3205 window = gdk_window_get_parent (window);
3212 * gtk_style_context_scroll_animations:
3213 * @context: a #GtkStyleContext
3214 * @window: a #GdkWindow used previously in
3215 * gtk_style_context_notify_state_change()
3216 * @dx: Amount to scroll in the X axis
3217 * @dy: Amount to scroll in the Y axis
3219 * This function is analogous to gdk_window_scroll(), and
3220 * should be called together with it so the invalidation
3221 * areas for any ongoing animation are scrolled together
3227 gtk_style_context_scroll_animations (GtkStyleContext *context,
3232 GtkStyleContextPrivate *priv;
3233 AnimationInfo *info;
3236 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3237 g_return_if_fail (GDK_IS_WINDOW (window));
3239 priv = context->priv;
3240 l = priv->animations;
3247 if (info->invalidation_region &&
3248 (window == info->window ||
3249 is_parent_of (window, info->window)))
3250 cairo_region_translate (info->invalidation_region, dx, dy);
3255 * gtk_style_context_push_animatable_region:
3256 * @context: a #GtkStyleContext
3257 * @region_id: unique identifier for the animatable region
3259 * Pushes an animatable region, so all further gtk_render_*() calls between
3260 * this call and the following gtk_style_context_pop_animatable_region()
3261 * will potentially show transition animations for this region if
3262 * gtk_style_context_notify_state_change() is called for a given state,
3263 * and the current theme/style defines transition animations for state
3266 * The @region_id used must be unique in @context so the theming engine
3267 * can uniquely identify rendered elements subject to a state transition.
3272 gtk_style_context_push_animatable_region (GtkStyleContext *context,
3275 GtkStyleContextPrivate *priv;
3277 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3278 g_return_if_fail (region_id != NULL);
3280 priv = context->priv;
3281 priv->animation_regions = g_slist_prepend (priv->animation_regions, region_id);
3285 * gtk_style_context_pop_animatable_region:
3286 * @context: a #GtkStyleContext
3288 * Pops an animatable region from @context.
3289 * See gtk_style_context_push_animatable_region().
3294 gtk_style_context_pop_animatable_region (GtkStyleContext *context)
3296 GtkStyleContextPrivate *priv;
3298 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3300 priv = context->priv;
3301 priv->animation_regions = g_slist_delete_link (priv->animation_regions,
3302 priv->animation_regions);
3306 _gtk_style_context_invalidate_animation_areas (GtkStyleContext *context)
3308 GtkStyleContextPrivate *priv;
3311 priv = context->priv;
3313 for (l = priv->animations; l; l = l->next)
3315 AnimationInfo *info;
3319 /* A NULL invalidation region means it has to be recreated on
3320 * the next expose event, this happens usually after a widget
3321 * allocation change, so the next expose after it will update
3322 * the invalidation region.
3324 if (info->invalidation_region)
3326 cairo_region_destroy (info->invalidation_region);
3327 info->invalidation_region = NULL;
3331 priv->animations_invalidated = TRUE;
3335 _gtk_style_context_coalesce_animation_areas (GtkStyleContext *context,
3338 GtkStyleContextPrivate *priv;
3341 priv = context->priv;
3343 if (!priv->animations_invalidated)
3346 l = priv->animations;
3350 AnimationInfo *info;
3359 if (info->invalidation_region)
3362 if (info->rectangles->len == 0)
3365 info->invalidation_region = cairo_region_create ();
3366 _gtk_widget_get_translation_to_window (widget, info->window, &rel_x, &rel_y);
3368 for (i = 0; i < info->rectangles->len; i++)
3370 cairo_rectangle_int_t *rect;
3372 rect = &g_array_index (info->rectangles, cairo_rectangle_int_t, i);
3374 /* These are widget relative coordinates,
3375 * so have them inverted to be window relative
3380 cairo_region_union_rectangle (info->invalidation_region, rect);
3383 g_array_remove_range (info->rectangles, 0, info->rectangles->len);
3386 priv->animations_invalidated = FALSE;
3390 store_animation_region (GtkStyleContext *context,
3396 GtkStyleContextPrivate *priv;
3399 priv = context->priv;
3401 if (!priv->animations_invalidated)
3404 for (l = priv->animations; l; l = l->next)
3406 AnimationInfo *info;
3410 /* The animation doesn't need updating
3411 * the invalidation area, bail out.
3413 if (info->invalidation_region)
3416 if (context_has_animatable_region (context, info->region_id))
3418 cairo_rectangle_int_t rect;
3422 rect.width = (gint) width;
3423 rect.height = (gint) height;
3425 g_array_append_val (info->rectangles, rect);
3427 if (!info->parent_regions)
3429 GSList *parent_regions;
3431 parent_regions = g_slist_find (priv->animation_regions, info->region_id);
3432 info->parent_regions = g_slist_copy (parent_regions);
3439 * gtk_style_context_invalidate:
3440 * @context: a #GtkStyleContext.
3442 * Invalidates @context style information, so it will be reconstructed
3445 * If you're using a #GtkStyleContext returned from
3446 * gtk_widget_get_style_context(), you do not need to
3447 * call this yourself.
3452 gtk_style_context_invalidate (GtkStyleContext *context)
3454 GtkStyleContextPrivate *priv;
3456 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3458 priv = context->priv;
3460 /* Avoid reentrancy */
3461 if (priv->invalidating_context)
3464 priv->invalidating_context = TRUE;
3466 g_hash_table_remove_all (priv->style_data);
3467 priv->current_data = NULL;
3469 g_signal_emit (context, signals[CHANGED], 0);
3471 priv->invalidating_context = FALSE;
3475 * gtk_style_context_set_background:
3476 * @context: a #GtkStyleContext
3477 * @window: a #GdkWindow
3479 * Sets the background of @window to the background pattern or
3480 * color specified in @context for its current state.
3485 gtk_style_context_set_background (GtkStyleContext *context,
3488 GtkStateFlags state;
3489 cairo_pattern_t *pattern;
3492 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3493 g_return_if_fail (GDK_IS_WINDOW (window));
3495 state = gtk_style_context_get_state (context);
3496 gtk_style_context_get (context, state,
3497 "background-image", &pattern,
3501 gdk_window_set_background_pattern (window, pattern);
3502 cairo_pattern_destroy (pattern);
3506 gtk_style_context_get (context, state,
3507 "background-color", &color,
3511 gdk_window_set_background_rgba (window, color);
3512 gdk_rgba_free (color);
3517 * gtk_style_context_get_color:
3518 * @context: a #GtkStyleContext
3519 * @state: state to retrieve the color for
3520 * @color: (out): return value for the foreground color
3522 * Gets the foreground color for a given state.
3527 gtk_style_context_get_color (GtkStyleContext *context,
3528 GtkStateFlags state,
3533 g_return_if_fail (color != NULL);
3534 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3536 gtk_style_context_get (context,
3546 * gtk_style_context_get_background_color:
3547 * @context: a #GtkStyleContext
3548 * @state: state to retrieve the color for
3549 * @color: (out): return value for the background color
3551 * Gets the background color for a given state.
3556 gtk_style_context_get_background_color (GtkStyleContext *context,
3557 GtkStateFlags state,
3562 g_return_if_fail (color != NULL);
3563 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3565 gtk_style_context_get (context,
3567 "background-color", &c,
3575 * gtk_style_context_get_border_color:
3576 * @context: a #GtkStyleContext
3577 * @state: state to retrieve the color for
3578 * @color: (out): return value for the border color
3580 * Gets the border color for a given state.
3585 gtk_style_context_get_border_color (GtkStyleContext *context,
3586 GtkStateFlags state,
3591 g_return_if_fail (color != NULL);
3592 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3594 gtk_style_context_get (context,
3604 * gtk_style_context_get_border:
3605 * @context: a #GtkStyleContext
3606 * @state: state to retrieve the border for
3607 * @border: (out): return value for the border settings
3609 * Gets the border for a given state as a #GtkBorder.
3610 * See %GTK_STYLE_PROPERTY_BORDER_WIDTH.
3615 gtk_style_context_get_border (GtkStyleContext *context,
3616 GtkStateFlags state,
3619 int top, left, bottom, right;
3621 g_return_if_fail (border != NULL);
3622 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3624 gtk_style_context_get (context,
3626 "border-top-width", &top,
3627 "border-left-width", &left,
3628 "border-bottom-width", &bottom,
3629 "border-right-width", &right,
3633 border->left = left;
3634 border->bottom = bottom;
3635 border->right = right;
3639 * gtk_style_context_get_padding:
3640 * @context: a #GtkStyleContext
3641 * @state: state to retrieve the padding for
3642 * @padding: (out): return value for the padding settings
3644 * Gets the padding for a given state as a #GtkBorder.
3645 * See %GTK_STYLE_PROPERTY_PADDING.
3650 gtk_style_context_get_padding (GtkStyleContext *context,
3651 GtkStateFlags state,
3654 int top, left, bottom, right;
3656 g_return_if_fail (padding != NULL);
3657 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3659 gtk_style_context_get (context,
3661 "padding-top", &top,
3662 "padding-left", &left,
3663 "padding-bottom", &bottom,
3664 "padding-right", &right,
3668 padding->left = left;
3669 padding->bottom = bottom;
3670 padding->right = right;
3674 * gtk_style_context_get_margin:
3675 * @context: a #GtkStyleContext
3676 * @state: state to retrieve the border for
3677 * @margin: (out): return value for the margin settings
3679 * Gets the margin for a given state as a #GtkBorder.
3680 * See %GTK_STYLE_PROPERTY_MARGIN.
3685 gtk_style_context_get_margin (GtkStyleContext *context,
3686 GtkStateFlags state,
3689 int top, left, bottom, right;
3691 g_return_if_fail (margin != NULL);
3692 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3694 gtk_style_context_get (context,
3697 "margin-left", &left,
3698 "margin-bottom", &bottom,
3699 "margin-right", &right,
3703 margin->left = left;
3704 margin->bottom = bottom;
3705 margin->right = right;
3709 * gtk_style_context_get_font:
3710 * @context: a #GtkStyleContext
3711 * @state: state to retrieve the font for
3713 * Returns the font description for a given state. The returned
3714 * object is const and will remain valid until the
3715 * #GtkStyleContext::changed signal happens.
3717 * Returns: (transfer none): the #PangoFontDescription for the given
3718 * state. This object is owned by GTK+ and should not be
3723 const PangoFontDescription *
3724 gtk_style_context_get_font (GtkStyleContext *context,
3725 GtkStateFlags state)
3727 GtkStyleContextPrivate *priv;
3729 PangoFontDescription *description;
3731 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
3733 priv = context->priv;
3734 g_return_val_if_fail (priv->widget_path != NULL, NULL);
3736 data = style_data_lookup (context, state);
3738 /* Yuck, fonts are created on-demand but we don't return a ref.
3739 * Do bad things to achieve this requirement */
3740 description = g_object_get_data (G_OBJECT (data->store), "font-cache-for-get_font");
3741 if (description == NULL)
3743 gtk_style_context_get (context, state, "font", &description, NULL);
3744 g_object_set_data_full (G_OBJECT (data->store),
3745 "font-cache-for-get_font",
3747 (GDestroyNotify) pango_font_description_free);
3753 get_cursor_color (GtkStyleContext *context,
3757 GdkColor *style_color;
3759 gtk_style_context_get_style (context,
3760 primary ? "cursor-color" : "secondary-cursor-color",
3766 color->red = style_color->red / 65535.0;
3767 color->green = style_color->green / 65535.0;
3768 color->blue = style_color->blue / 65535.0;
3771 gdk_color_free (style_color);
3775 gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, color);
3781 gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &bg);
3783 color->red = (color->red + bg.red) * 0.5;
3784 color->green = (color->green + bg.green) * 0.5;
3785 color->blue = (color->blue + bg.blue) * 0.5;
3791 _gtk_style_context_get_cursor_color (GtkStyleContext *context,
3792 GdkRGBA *primary_color,
3793 GdkRGBA *secondary_color)
3796 get_cursor_color (context, TRUE, primary_color);
3798 if (secondary_color)
3799 get_cursor_color (context, FALSE, secondary_color);
3806 * @context: a #GtkStyleContext
3808 * @x: X origin of the rectangle
3809 * @y: Y origin of the rectangle
3810 * @width: rectangle width
3811 * @height: rectangle height
3813 * Renders a checkmark (as in a #GtkCheckButton).
3815 * The %GTK_STATE_FLAG_ACTIVE state determines whether the check is
3816 * on or off, and %GTK_STATE_FLAG_INCONSISTENT determines whether it
3817 * should be marked as undefined.
3820 * <title>Typical checkmark rendering</title>
3821 * <inlinegraphic fileref="checks.png" format="PNG"/>
3827 gtk_render_check (GtkStyleContext *context,
3834 GtkStyleContextPrivate *priv;
3835 GtkThemingEngineClass *engine_class;
3837 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3838 g_return_if_fail (cr != NULL);
3840 if (width <= 0 || height <= 0)
3843 priv = context->priv;
3844 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3848 store_animation_region (context, x, y, width, height);
3850 _gtk_theming_engine_set_context (priv->theming_engine, context);
3851 engine_class->render_check (priv->theming_engine, cr,
3852 x, y, width, height);
3858 * gtk_render_option:
3859 * @context: a #GtkStyleContext
3861 * @x: X origin of the rectangle
3862 * @y: Y origin of the rectangle
3863 * @width: rectangle width
3864 * @height: rectangle height
3866 * Renders an option mark (as in a #GtkRadioButton), the %GTK_STATE_FLAG_ACTIVE
3867 * state will determine whether the option is on or off, and
3868 * %GTK_STATE_FLAG_INCONSISTENT whether it should be marked as undefined.
3871 * <title>Typical option mark rendering</title>
3872 * <inlinegraphic fileref="options.png" format="PNG"/>
3878 gtk_render_option (GtkStyleContext *context,
3885 GtkStyleContextPrivate *priv;
3886 GtkThemingEngineClass *engine_class;
3888 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3889 g_return_if_fail (cr != NULL);
3891 if (width <= 0 || height <= 0)
3894 priv = context->priv;
3895 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3899 store_animation_region (context, x, y, width, height);
3901 _gtk_theming_engine_set_context (priv->theming_engine, context);
3902 engine_class->render_option (priv->theming_engine, cr,
3903 x, y, width, height);
3910 * @context: a #GtkStyleContext
3912 * @angle: arrow angle from 0 to 2 * %G_PI, being 0 the arrow pointing to the north
3913 * @x: X origin of the render area
3914 * @y: Y origin of the render area
3915 * @size: square side for render area
3917 * Renders an arrow pointing to @angle.
3920 * <title>Typical arrow rendering at 0, 1&solidus;2 π, π and 3&solidus;2 π</title>
3921 * <inlinegraphic fileref="arrows.png" format="PNG"/>
3927 gtk_render_arrow (GtkStyleContext *context,
3934 GtkStyleContextPrivate *priv;
3935 GtkThemingEngineClass *engine_class;
3937 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3938 g_return_if_fail (cr != NULL);
3943 priv = context->priv;
3944 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3948 gtk_style_context_save (context);
3949 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ARROW);
3951 store_animation_region (context, x, y, size, size);
3953 _gtk_theming_engine_set_context (priv->theming_engine, context);
3954 engine_class->render_arrow (priv->theming_engine, cr,
3957 gtk_style_context_restore (context);
3962 * gtk_render_background:
3963 * @context: a #GtkStyleContext
3965 * @x: X origin of the rectangle
3966 * @y: Y origin of the rectangle
3967 * @width: rectangle width
3968 * @height: rectangle height
3970 * Renders the background of an element.
3973 * <title>Typical background rendering, showing the effect of
3974 * <parameter>background-image</parameter>,
3975 * <parameter>border-width</parameter> and
3976 * <parameter>border-radius</parameter></title>
3977 * <inlinegraphic fileref="background.png" format="PNG"/>
3983 gtk_render_background (GtkStyleContext *context,
3990 GtkStyleContextPrivate *priv;
3991 GtkThemingEngineClass *engine_class;
3993 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3994 g_return_if_fail (cr != NULL);
3996 if (width <= 0 || height <= 0)
3999 priv = context->priv;
4000 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4004 store_animation_region (context, x, y, width, height);
4006 _gtk_theming_engine_set_context (priv->theming_engine, context);
4007 engine_class->render_background (priv->theming_engine, cr, x, y, width, height);
4014 * @context: a #GtkStyleContext
4016 * @x: X origin of the rectangle
4017 * @y: Y origin of the rectangle
4018 * @width: rectangle width
4019 * @height: rectangle height
4021 * Renders a frame around the rectangle defined by @x, @y, @width, @height.
4024 * <title>Examples of frame rendering, showing the effect of
4025 * <parameter>border-image</parameter>,
4026 * <parameter>border-color</parameter>,
4027 * <parameter>border-width</parameter>,
4028 * <parameter>border-radius</parameter> and
4030 * <inlinegraphic fileref="frames.png" format="PNG"/>
4036 gtk_render_frame (GtkStyleContext *context,
4043 GtkStyleContextPrivate *priv;
4044 GtkThemingEngineClass *engine_class;
4046 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4047 g_return_if_fail (cr != NULL);
4049 if (width <= 0 || height <= 0)
4052 priv = context->priv;
4053 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4057 store_animation_region (context, x, y, width, height);
4059 _gtk_theming_engine_set_context (priv->theming_engine, context);
4060 engine_class->render_frame (priv->theming_engine, cr, x, y, width, height);
4066 * gtk_render_expander:
4067 * @context: a #GtkStyleContext
4069 * @x: X origin of the rectangle
4070 * @y: Y origin of the rectangle
4071 * @width: rectangle width
4072 * @height: rectangle height
4074 * Renders an expander (as used in #GtkTreeView and #GtkExpander) in the area
4075 * defined by @x, @y, @width, @height. The state %GTK_STATE_FLAG_ACTIVE
4076 * determines whether the expander is collapsed or expanded.
4079 * <title>Typical expander rendering</title>
4080 * <inlinegraphic fileref="expanders.png" format="PNG"/>
4086 gtk_render_expander (GtkStyleContext *context,
4093 GtkStyleContextPrivate *priv;
4094 GtkThemingEngineClass *engine_class;
4096 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4097 g_return_if_fail (cr != NULL);
4099 if (width <= 0 || height <= 0)
4102 priv = context->priv;
4103 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4107 store_animation_region (context, x, y, width, height);
4109 _gtk_theming_engine_set_context (priv->theming_engine, context);
4110 engine_class->render_expander (priv->theming_engine, cr, x, y, width, height);
4117 * @context: a #GtkStyleContext
4119 * @x: X origin of the rectangle
4120 * @y: Y origin of the rectangle
4121 * @width: rectangle width
4122 * @height: rectangle height
4124 * Renders a focus indicator on the rectangle determined by @x, @y, @width, @height.
4126 * <title>Typical focus rendering</title>
4127 * <inlinegraphic fileref="focus.png" format="PNG"/>
4133 gtk_render_focus (GtkStyleContext *context,
4140 GtkStyleContextPrivate *priv;
4141 GtkThemingEngineClass *engine_class;
4143 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4144 g_return_if_fail (cr != NULL);
4146 if (width <= 0 || height <= 0)
4149 priv = context->priv;
4150 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4154 store_animation_region (context, x, y, width, height);
4156 _gtk_theming_engine_set_context (priv->theming_engine, context);
4157 engine_class->render_focus (priv->theming_engine, cr, x, y, width, height);
4163 * gtk_render_layout:
4164 * @context: a #GtkStyleContext
4168 * @layout: the #PangoLayout to render
4170 * Renders @layout on the coordinates @x, @y
4175 gtk_render_layout (GtkStyleContext *context,
4179 PangoLayout *layout)
4181 GtkStyleContextPrivate *priv;
4182 GtkThemingEngineClass *engine_class;
4183 PangoRectangle extents;
4185 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4186 g_return_if_fail (PANGO_IS_LAYOUT (layout));
4187 g_return_if_fail (cr != NULL);
4189 priv = context->priv;
4190 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4194 pango_layout_get_extents (layout, &extents, NULL);
4196 store_animation_region (context,
4202 _gtk_theming_engine_set_context (priv->theming_engine, context);
4203 engine_class->render_layout (priv->theming_engine, cr, x, y, layout);
4210 * @context: a #GtkStyleContext
4212 * @x0: X coordinate for the origin of the line
4213 * @y0: Y coordinate for the origin of the line
4214 * @x1: X coordinate for the end of the line
4215 * @y1: Y coordinate for the end of the line
4217 * Renders a line from (x0, y0) to (x1, y1).
4222 gtk_render_line (GtkStyleContext *context,
4229 GtkStyleContextPrivate *priv;
4230 GtkThemingEngineClass *engine_class;
4232 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4233 g_return_if_fail (cr != NULL);
4235 priv = context->priv;
4236 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4240 _gtk_theming_engine_set_context (priv->theming_engine, context);
4241 engine_class->render_line (priv->theming_engine, cr, x0, y0, x1, y1);
4247 * gtk_render_slider:
4248 * @context: a #GtkStyleContext
4250 * @x: X origin of the rectangle
4251 * @y: Y origin of the rectangle
4252 * @width: rectangle width
4253 * @height: rectangle height
4254 * @orientation: orientation of the slider
4256 * Renders a slider (as in #GtkScale) in the rectangle defined by @x, @y,
4257 * @width, @height. @orientation defines whether the slider is vertical
4261 * <title>Typical slider rendering</title>
4262 * <inlinegraphic fileref="sliders.png" format="PNG"/>
4268 gtk_render_slider (GtkStyleContext *context,
4274 GtkOrientation orientation)
4276 GtkStyleContextPrivate *priv;
4277 GtkThemingEngineClass *engine_class;
4279 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4280 g_return_if_fail (cr != NULL);
4282 if (width <= 0 || height <= 0)
4285 priv = context->priv;
4286 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4290 store_animation_region (context, x, y, width, height);
4292 _gtk_theming_engine_set_context (priv->theming_engine, context);
4293 engine_class->render_slider (priv->theming_engine, cr, x, y, width, height, orientation);
4299 * gtk_render_frame_gap:
4300 * @context: a #GtkStyleContext
4302 * @x: X origin of the rectangle
4303 * @y: Y origin of the rectangle
4304 * @width: rectangle width
4305 * @height: rectangle height
4306 * @gap_side: side where the gap is
4307 * @xy0_gap: initial coordinate (X or Y depending on @gap_side) for the gap
4308 * @xy1_gap: end coordinate (X or Y depending on @gap_side) for the gap
4310 * Renders a frame around the rectangle defined by (@x, @y, @width, @height),
4311 * leaving a gap on one side. @xy0_gap and @xy1_gap will mean X coordinates
4312 * for %GTK_POS_TOP and %GTK_POS_BOTTOM gap sides, and Y coordinates for
4313 * %GTK_POS_LEFT and %GTK_POS_RIGHT.
4316 * <title>Typical rendering of a frame with a gap</title>
4317 * <inlinegraphic fileref="frame-gap.png" format="PNG"/>
4323 gtk_render_frame_gap (GtkStyleContext *context,
4329 GtkPositionType gap_side,
4333 GtkStyleContextPrivate *priv;
4334 GtkThemingEngineClass *engine_class;
4336 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4337 g_return_if_fail (cr != NULL);
4338 g_return_if_fail (xy0_gap <= xy1_gap);
4339 g_return_if_fail (xy0_gap >= 0);
4341 if (width <= 0 || height <= 0)
4344 if (gap_side == GTK_POS_LEFT ||
4345 gap_side == GTK_POS_RIGHT)
4346 g_return_if_fail (xy1_gap <= height);
4348 g_return_if_fail (xy1_gap <= width);
4350 priv = context->priv;
4351 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4355 store_animation_region (context, x, y, width, height);
4357 _gtk_theming_engine_set_context (priv->theming_engine, context);
4358 engine_class->render_frame_gap (priv->theming_engine, cr,
4359 x, y, width, height, gap_side,
4366 * gtk_render_extension:
4367 * @context: a #GtkStyleContext
4369 * @x: X origin of the rectangle
4370 * @y: Y origin of the rectangle
4371 * @width: rectangle width
4372 * @height: rectangle height
4373 * @gap_side: side where the gap is
4375 * Renders a extension (as in a #GtkNotebook tab) in the rectangle
4376 * defined by @x, @y, @width, @height. The side where the extension
4377 * connects to is defined by @gap_side.
4380 * <title>Typical extension rendering</title>
4381 * <inlinegraphic fileref="extensions.png" format="PNG"/>
4387 gtk_render_extension (GtkStyleContext *context,
4393 GtkPositionType gap_side)
4395 GtkStyleContextPrivate *priv;
4396 GtkThemingEngineClass *engine_class;
4398 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4399 g_return_if_fail (cr != NULL);
4401 if (width <= 0 || height <= 0)
4404 priv = context->priv;
4405 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4409 store_animation_region (context, x, y, width, height);
4411 _gtk_theming_engine_set_context (priv->theming_engine, context);
4412 engine_class->render_extension (priv->theming_engine, cr, x, y, width, height, gap_side);
4418 * gtk_render_handle:
4419 * @context: a #GtkStyleContext
4421 * @x: X origin of the rectangle
4422 * @y: Y origin of the rectangle
4423 * @width: rectangle width
4424 * @height: rectangle height
4426 * Renders a handle (as in #GtkHandleBox, #GtkPaned and
4427 * #GtkWindow<!-- -->'s resize grip), in the rectangle
4428 * determined by @x, @y, @width, @height.
4431 * <title>Handles rendered for the paned and grip classes</title>
4432 * <inlinegraphic fileref="handles.png" format="PNG"/>
4438 gtk_render_handle (GtkStyleContext *context,
4445 GtkStyleContextPrivate *priv;
4446 GtkThemingEngineClass *engine_class;
4448 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4449 g_return_if_fail (cr != NULL);
4451 if (width <= 0 || height <= 0)
4454 priv = context->priv;
4455 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4459 store_animation_region (context, x, y, width, height);
4461 _gtk_theming_engine_set_context (priv->theming_engine, context);
4462 engine_class->render_handle (priv->theming_engine, cr, x, y, width, height);
4468 * gtk_render_activity:
4469 * @context: a #GtkStyleContext
4471 * @x: X origin of the rectangle
4472 * @y: Y origin of the rectangle
4473 * @width: rectangle width
4474 * @height: rectangle height
4476 * Renders an activity area (Such as in #GtkSpinner or the
4477 * fill line in #GtkRange), the state %GTK_STATE_FLAG_ACTIVE
4478 * determines whether there is activity going on.
4483 gtk_render_activity (GtkStyleContext *context,
4490 GtkStyleContextPrivate *priv;
4491 GtkThemingEngineClass *engine_class;
4493 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4494 g_return_if_fail (cr != NULL);
4496 if (width <= 0 || height <= 0)
4499 priv = context->priv;
4500 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4504 store_animation_region (context, x, y, width, height);
4506 _gtk_theming_engine_set_context (priv->theming_engine, context);
4507 engine_class->render_activity (priv->theming_engine, cr, x, y, width, height);
4513 * gtk_render_icon_pixbuf:
4514 * @context: a #GtkStyleContext
4515 * @source: the #GtkIconSource specifying the icon to render
4516 * @size: (type int): the size to render the icon at. A size of (GtkIconSize) -1
4517 * means render at the size of the source and don't scale.
4519 * Renders the icon specified by @source at the given @size, returning the result
4522 * Returns: (transfer full): a newly-created #GdkPixbuf containing the rendered icon
4527 gtk_render_icon_pixbuf (GtkStyleContext *context,
4528 const GtkIconSource *source,
4531 GtkStyleContextPrivate *priv;
4532 GtkThemingEngineClass *engine_class;
4534 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
4535 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
4536 g_return_val_if_fail (source != NULL, NULL);
4538 priv = context->priv;
4539 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4541 _gtk_theming_engine_set_context (priv->theming_engine, context);
4542 return engine_class->render_icon_pixbuf (priv->theming_engine, source, size);
4547 * @context: a #GtkStyleContext
4549 * @pixbuf: a #GdkPixbuf containing the icon to draw
4550 * @x: X position for the @pixbuf
4551 * @y: Y position for the @pixbuf
4553 * Renders the icon in @pixbuf at the specified @x and @y coordinates.
4558 gtk_render_icon (GtkStyleContext *context,
4564 GtkStyleContextPrivate *priv;
4565 GtkThemingEngineClass *engine_class;
4567 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4568 g_return_if_fail (cr != NULL);
4570 priv = context->priv;
4571 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4575 store_animation_region (context,
4577 gdk_pixbuf_get_width (pixbuf),
4578 gdk_pixbuf_get_height (pixbuf));
4580 _gtk_theming_engine_set_context (priv->theming_engine, context);
4581 engine_class->render_icon (priv->theming_engine, cr, pixbuf, x, y);
4587 draw_insertion_cursor (GtkStyleContext *context,
4592 gboolean is_primary,
4593 PangoDirection direction,
4594 gboolean draw_arrow)
4597 GdkRGBA primary_color;
4598 GdkRGBA secondary_color;
4599 gfloat cursor_aspect_ratio;
4605 _gtk_style_context_get_cursor_color (context, &primary_color, &secondary_color);
4606 gdk_cairo_set_source_rgba (cr, is_primary ? &primary_color : &secondary_color);
4608 /* When changing the shape or size of the cursor here,
4609 * propagate the changes to gtktextview.c:text_window_invalidate_cursors().
4612 gtk_style_context_get_style (context,
4613 "cursor-aspect-ratio", &cursor_aspect_ratio,
4616 stem_width = height * cursor_aspect_ratio + 1;
4618 /* put (stem_width % 2) on the proper side of the cursor */
4619 if (direction == PANGO_DIRECTION_LTR)
4620 offset = stem_width / 2;
4622 offset = stem_width - stem_width / 2;
4624 cairo_rectangle (cr, x - offset, y, stem_width, height);
4632 arrow_width = stem_width + 1;
4634 if (direction == PANGO_DIRECTION_RTL)
4636 ax = x - offset - 1;
4637 ay = y + height - arrow_width * 2 - arrow_width + 1;
4639 cairo_move_to (cr, ax, ay + 1);
4640 cairo_line_to (cr, ax - arrow_width, ay + arrow_width);
4641 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4644 else if (direction == PANGO_DIRECTION_LTR)
4646 ax = x + stem_width - offset;
4647 ay = y + height - arrow_width * 2 - arrow_width + 1;
4649 cairo_move_to (cr, ax, ay + 1);
4650 cairo_line_to (cr, ax + arrow_width, ay + arrow_width);
4651 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4655 g_assert_not_reached();
4662 * gtk_render_insertion_cursor:
4663 * @context: a #GtkStyleContext
4667 * @layout: the #PangoLayout of the text
4668 * @index: the index in the #PangoLayout
4669 * @direction: the #PangoDirection of the text
4671 * Draws a text caret on @cr at the specified index of @layout.
4676 gtk_render_insertion_cursor (GtkStyleContext *context,
4680 PangoLayout *layout,
4682 PangoDirection direction)
4684 GtkStyleContextPrivate *priv;
4685 gboolean split_cursor;
4686 PangoRectangle strong_pos, weak_pos;
4687 PangoRectangle *cursor1, *cursor2;
4688 PangoDirection keymap_direction;
4689 PangoDirection direction2;
4691 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4692 g_return_if_fail (cr != NULL);
4693 g_return_if_fail (PANGO_IS_LAYOUT (layout));
4694 g_return_if_fail (index >= 0);
4696 priv = context->priv;
4698 g_object_get (gtk_settings_get_for_screen (priv->screen),
4699 "gtk-split-cursor", &split_cursor,
4702 keymap_direction = gdk_keymap_get_direction (gdk_keymap_get_for_display (gdk_screen_get_display (priv->screen)));
4704 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4706 direction2 = PANGO_DIRECTION_NEUTRAL;
4710 cursor1 = &strong_pos;
4712 if (strong_pos.x != weak_pos.x || strong_pos.y != weak_pos.y)
4714 direction2 = (direction == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
4715 cursor2 = &weak_pos;
4720 if (keymap_direction == direction)
4721 cursor1 = &strong_pos;
4723 cursor1 = &weak_pos;
4726 draw_insertion_cursor (context,
4728 x + PANGO_PIXELS (cursor1->x),
4729 y + PANGO_PIXELS (cursor1->y),
4730 PANGO_PIXELS (cursor1->height),
4733 direction2 != PANGO_DIRECTION_NEUTRAL);
4735 if (direction2 != PANGO_DIRECTION_NEUTRAL)
4737 draw_insertion_cursor (context,
4739 x + PANGO_PIXELS (cursor2->x),
4740 y + PANGO_PIXELS (cursor2->y),
4741 PANGO_PIXELS (cursor2->height),
4749 * gtk_draw_insertion_cursor:
4750 * @widget: a #GtkWidget
4751 * @cr: cairo context to draw to
4752 * @location: location where to draw the cursor (@location->width is ignored)
4753 * @is_primary: if the cursor should be the primary cursor color.
4754 * @direction: whether the cursor is left-to-right or
4755 * right-to-left. Should never be #GTK_TEXT_DIR_NONE
4756 * @draw_arrow: %TRUE to draw a directional arrow on the
4757 * cursor. Should be %FALSE unless the cursor is split.
4759 * Draws a text caret on @cr at @location. This is not a style function
4760 * but merely a convenience function for drawing the standard cursor shape.
4763 * Deprecated: 3.4: Use gtk_render_insertion_cursor() instead.
4766 gtk_draw_insertion_cursor (GtkWidget *widget,
4768 const GdkRectangle *location,
4769 gboolean is_primary,
4770 GtkTextDirection direction,
4771 gboolean draw_arrow)
4773 GtkStyleContext *context;
4775 g_return_if_fail (GTK_IS_WIDGET (widget));
4776 g_return_if_fail (cr != NULL);
4777 g_return_if_fail (location != NULL);
4778 g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
4780 context = gtk_widget_get_style_context (widget);
4782 draw_insertion_cursor (context, cr,
4783 location->x, location->y, location->height,
4785 (direction == GTK_TEXT_DIR_RTL) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR,
4789 static AtkAttributeSet *
4790 add_attribute (AtkAttributeSet *attributes,
4791 AtkTextAttribute attr,
4796 at = g_new (AtkAttribute, 1);
4797 at->name = g_strdup (atk_text_attribute_get_name (attr));
4798 at->value = g_strdup (value);
4800 return g_slist_prepend (attributes, at);
4804 * _gtk_style_context_get_attributes:
4805 * @attributes: a #AtkAttributeSet to add attributes to
4806 * @context: the #GtkStyleContext to get attributes from
4807 * @flags: the state to use with @context
4809 * Adds the foreground and background color from @context to
4810 * @attributes, after translating them to ATK attributes.
4812 * This is a convenience function that can be used in
4813 * implementing the #AtkText interface in widgets.
4815 * Returns: the modified #AtkAttributeSet
4818 _gtk_style_context_get_attributes (AtkAttributeSet *attributes,
4819 GtkStyleContext *context,
4820 GtkStateFlags flags)
4825 gtk_style_context_get_background_color (context, flags, &color);
4826 value = g_strdup_printf ("%u,%u,%u",
4827 (guint) ceil (color.red * 65536 - color.red),
4828 (guint) ceil (color.green * 65536 - color.green),
4829 (guint) ceil (color.blue * 65536 - color.blue));
4830 attributes = add_attribute (attributes, ATK_TEXT_ATTR_BG_COLOR, value);
4833 gtk_style_context_get_color (context, flags, &color);
4834 value = g_strdup_printf ("%u,%u,%u",
4835 (guint) ceil (color.red * 65536 - color.red),
4836 (guint) ceil (color.green * 65536 - color.green),
4837 (guint) ceil (color.blue * 65536 - color.blue));
4838 attributes = add_attribute (attributes, ATK_TEXT_ATTR_FG_COLOR, value);