1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2010 Carlos Garnacho <carlosg@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
25 #include <gobject/gvaluecollector.h>
27 #include "gtkstylecontextprivate.h"
28 #include "gtkstylepropertiesprivate.h"
29 #include "gtktypebuiltins.h"
30 #include "gtkthemingengine.h"
32 #include "gtkwidget.h"
33 #include "gtkwindow.h"
34 #include "gtkprivate.h"
35 #include "gtksymboliccolorprivate.h"
36 #include "gtkanimationdescription.h"
37 #include "gtktimeline.h"
38 #include "gtkiconfactory.h"
39 #include "gtkwidgetprivate.h"
40 #include "gtkstyleproviderprivate.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,
917 GtkStyleProviderData *local_data, *global_data;
919 local_data = local->data;
920 global_data = global->data;
922 if (local_data->priority < global_data->priority)
923 return (ascending) ? local : global;
925 return (ascending) ? global : local;
936 build_properties (GtkStyleContext *context,
937 StyleData *style_data,
941 GtkStyleContextPrivate *priv;
942 GList *elem, *list, *global_list = NULL;
943 GtkCssLookup *lookup;
945 priv = context->priv;
946 list = priv->providers_last;
950 global_list = g_object_get_qdata (G_OBJECT (priv->screen), provider_list_quark);
951 global_list = g_list_last (global_list);
954 lookup = _gtk_css_lookup_new ();
956 while ((elem = find_next_candidate (list, global_list, FALSE)) != NULL)
958 GtkStyleProviderData *data;
959 GtkStyleProperties *provider_style;
966 global_list = global_list->prev;
968 if (GTK_IS_STYLE_PROVIDER_PRIVATE (data->provider))
970 _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (data->provider),
977 provider_style = gtk_style_provider_get_style (data->provider, path);
981 _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (provider_style),
985 g_object_unref (provider_style);
990 style_data->store = _gtk_css_computed_values_new ();
991 _gtk_css_lookup_resolve (lookup, context, style_data->store);
992 _gtk_css_lookup_free (lookup);
996 build_icon_factories (GtkStyleContext *context,
997 StyleData *style_data,
1000 GtkStyleContextPrivate *priv;
1001 GList *elem, *list, *global_list = NULL;
1003 priv = context->priv;
1004 list = priv->providers_last;
1008 global_list = g_object_get_qdata (G_OBJECT (priv->screen), provider_list_quark);
1009 global_list = g_list_last (global_list);
1012 while ((elem = find_next_candidate (list, global_list, FALSE)) != NULL)
1014 GtkIconFactory *factory;
1015 GtkStyleProviderData *data;
1022 global_list = global_list->prev;
1024 factory = gtk_style_provider_get_icon_factory (data->provider, path);
1027 style_data->icon_factories = g_slist_prepend (style_data->icon_factories, factory);
1031 static GtkWidgetPath *
1032 create_query_path (GtkStyleContext *context)
1034 GtkStyleContextPrivate *priv;
1035 GtkWidgetPath *path;
1039 priv = context->priv;
1040 path = gtk_widget_path_copy (priv->widget_path);
1041 pos = gtk_widget_path_length (path) - 1;
1043 info = priv->info_stack->data;
1045 /* Set widget regions */
1046 for (i = 0; i < info->regions->len; i++)
1050 region = &g_array_index (info->regions, GtkRegion, i);
1051 gtk_widget_path_iter_add_region (path, pos,
1052 g_quark_to_string (region->class_quark),
1056 /* Set widget classes */
1057 for (i = 0; i < info->style_classes->len; i++)
1061 quark = g_array_index (info->style_classes, GQuark, i);
1062 gtk_widget_path_iter_add_class (path, pos,
1063 g_quark_to_string (quark));
1070 style_data_lookup (GtkStyleContext *context,
1071 GtkStateFlags state)
1073 GtkStyleContextPrivate *priv;
1075 gboolean state_mismatch;
1078 priv = context->priv;
1079 state_mismatch = ((GtkStyleInfo *) priv->info_stack->data)->state_flags != state;
1081 /* Current data in use is cached, just return it */
1082 if (priv->current_data && priv->current_state == state)
1083 return priv->current_data;
1085 g_assert (priv->widget_path != NULL);
1087 if (G_UNLIKELY (state_mismatch))
1089 gtk_style_context_save (context);
1090 gtk_style_context_set_state (context, state);
1093 priv->current_data = g_hash_table_lookup (priv->style_data, priv->info_stack->data);
1094 priv->current_state = state;
1096 if (!priv->current_data)
1098 GtkWidgetPath *path;
1100 priv->current_data = style_data_new ();
1101 g_hash_table_insert (priv->style_data,
1102 style_info_copy (priv->info_stack->data),
1103 priv->current_data);
1105 path = create_query_path (context);
1107 build_properties (context, priv->current_data, path, state);
1108 build_icon_factories (context, priv->current_data, path);
1110 gtk_widget_path_free (path);
1113 data = priv->current_data;
1115 if (priv->theming_engine)
1116 g_object_unref (priv->theming_engine);
1118 v = _gtk_css_computed_values_get_value_by_name (priv->current_data->store, "engine");
1120 priv->theming_engine = g_value_dup_object (v);
1122 priv->theming_engine = g_object_ref (gtk_theming_engine_load (NULL));
1124 if (G_UNLIKELY (state_mismatch))
1125 gtk_style_context_restore (context);
1131 style_provider_add (GList **list,
1132 GtkStyleProvider *provider,
1135 GtkStyleProviderData *new_data;
1136 gboolean added = FALSE;
1139 new_data = style_provider_data_new (provider, priority);
1143 GtkStyleProviderData *data;
1147 /* Provider was already attached to the style
1148 * context, remove in order to add the new data
1150 if (data->provider == provider)
1157 /* Remove and free link */
1158 *list = g_list_remove_link (*list, link);
1159 style_provider_data_free (link->data);
1160 g_list_free_1 (link);
1166 data->priority > priority)
1168 *list = g_list_insert_before (*list, l, new_data);
1176 *list = g_list_append (*list, new_data);
1180 style_provider_remove (GList **list,
1181 GtkStyleProvider *provider)
1187 GtkStyleProviderData *data;
1191 if (data->provider == provider)
1193 *list = g_list_remove_link (*list, l);
1194 style_provider_data_free (l->data);
1207 * gtk_style_context_new:
1209 * Creates a standalone #GtkStyleContext, this style context
1210 * won't be attached to any widget, so you may want
1211 * to call gtk_style_context_set_path() yourself.
1214 * This function is only useful when using the theming layer
1215 * separated from GTK+, if you are using #GtkStyleContext to
1216 * theme #GtkWidget<!-- -->s, use gtk_widget_get_style_context()
1217 * in order to get a style context ready to theme the widget.
1220 * Returns: A newly created #GtkStyleContext.
1223 gtk_style_context_new (void)
1225 return g_object_new (GTK_TYPE_STYLE_CONTEXT, NULL);
1229 * gtk_style_context_add_provider:
1230 * @context: a #GtkStyleContext
1231 * @provider: a #GtkStyleProvider
1232 * @priority: the priority of the style provider. The lower
1233 * it is, the earlier it will be used in the style
1234 * construction. Typically this will be in the range
1235 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1236 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1238 * Adds a style provider to @context, to be used in style construction.
1240 * <note><para>If both priorities are the same, A #GtkStyleProvider
1241 * added through this function takes precedence over another added
1242 * through gtk_style_context_add_provider_for_screen().</para></note>
1247 gtk_style_context_add_provider (GtkStyleContext *context,
1248 GtkStyleProvider *provider,
1251 GtkStyleContextPrivate *priv;
1253 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1254 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1256 priv = context->priv;
1257 style_provider_add (&priv->providers, provider, priority);
1258 priv->providers_last = g_list_last (priv->providers);
1260 gtk_style_context_invalidate (context);
1264 * gtk_style_context_remove_provider:
1265 * @context: a #GtkStyleContext
1266 * @provider: a #GtkStyleProvider
1268 * Removes @provider from the style providers list in @context.
1273 gtk_style_context_remove_provider (GtkStyleContext *context,
1274 GtkStyleProvider *provider)
1276 GtkStyleContextPrivate *priv;
1278 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1279 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1281 priv = context->priv;
1283 if (style_provider_remove (&priv->providers, provider))
1285 priv->providers_last = g_list_last (priv->providers);
1287 gtk_style_context_invalidate (context);
1292 * gtk_style_context_reset_widgets:
1293 * @screen: a #GdkScreen
1295 * This function recomputes the styles for all widgets under a particular
1296 * #GdkScreen. This is useful when some global parameter has changed that
1297 * affects the appearance of all widgets, because when a widget gets a new
1298 * style, it will both redraw and recompute any cached information about
1299 * its appearance. As an example, it is used when the color scheme changes
1300 * in the related #GtkSettings object.
1305 gtk_style_context_reset_widgets (GdkScreen *screen)
1307 GList *list, *toplevels;
1309 _gtk_icon_set_invalidate_caches ();
1311 toplevels = gtk_window_list_toplevels ();
1312 g_list_foreach (toplevels, (GFunc) g_object_ref, NULL);
1314 for (list = toplevels; list; list = list->next)
1316 if (gtk_widget_get_screen (list->data) == screen)
1317 gtk_widget_reset_style (list->data);
1319 g_object_unref (list->data);
1322 g_list_free (toplevels);
1326 * gtk_style_context_add_provider_for_screen:
1327 * @screen: a #GdkScreen
1328 * @provider: a #GtkStyleProvider
1329 * @priority: the priority of the style provider. The lower
1330 * it is, the earlier it will be used in the style
1331 * construction. Typically this will be in the range
1332 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1333 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1335 * Adds a global style provider to @screen, which will be used
1336 * in style construction for all #GtkStyleContext<!-- -->s under
1339 * GTK+ uses this to make styling information from #GtkSettings
1342 * <note><para>If both priorities are the same, A #GtkStyleProvider
1343 * added through gtk_style_context_add_provider() takes precedence
1344 * over another added through this function.</para></note>
1349 gtk_style_context_add_provider_for_screen (GdkScreen *screen,
1350 GtkStyleProvider *provider,
1353 GList *providers, *list;
1355 g_return_if_fail (GDK_IS_SCREEN (screen));
1356 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1358 if (G_UNLIKELY (!provider_list_quark))
1359 provider_list_quark = g_quark_from_static_string ("gtk-provider-list-quark");
1361 list = providers = g_object_get_qdata (G_OBJECT (screen), provider_list_quark);
1362 style_provider_add (&list, provider, priority);
1364 if (list != providers)
1365 g_object_set_qdata (G_OBJECT (screen), provider_list_quark, list);
1367 gtk_style_context_reset_widgets (screen);
1371 * gtk_style_context_remove_provider_for_screen:
1372 * @screen: a #GdkScreen
1373 * @provider: a #GtkStyleProvider
1375 * Removes @provider from the global style providers list in @screen.
1380 gtk_style_context_remove_provider_for_screen (GdkScreen *screen,
1381 GtkStyleProvider *provider)
1383 GList *providers, *list;
1385 g_return_if_fail (GDK_IS_SCREEN (screen));
1386 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1388 if (G_UNLIKELY (!provider_list_quark))
1391 list = providers = g_object_get_qdata (G_OBJECT (screen), provider_list_quark);
1393 if (style_provider_remove (&list, provider))
1395 if (list != providers)
1396 g_object_set_qdata (G_OBJECT (screen), provider_list_quark, list);
1398 gtk_style_context_reset_widgets (screen);
1403 * gtk_style_context_get_section:
1404 * @context: a #GtkStyleContext
1405 * @property: style property name
1407 * Queries the location in the CSS where @property was defined for the
1408 * current @context. Note that the state to be queried is taken from
1409 * gtk_style_context_get_state().
1411 * If the location is not available, %NULL will be returned. The
1412 * location might not be available for various reasons, such as the
1413 * property being overridden, @property not naming a supported CSS
1414 * property or tracking of definitions being disabled for performance
1417 * Shorthand CSS properties cannot be queried for a location and will
1418 * always return %NULL.
1420 * Returns: %NULL or the section where value was defined
1423 gtk_style_context_get_section (GtkStyleContext *context,
1424 const gchar *property)
1426 GtkStyleContextPrivate *priv;
1427 GtkStyleProperty *prop;
1430 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1431 g_return_val_if_fail (property != NULL, NULL);
1433 priv = context->priv;
1434 g_return_val_if_fail (priv->widget_path != NULL, NULL);
1436 prop = _gtk_style_property_lookup (property);
1437 if (!GTK_IS_CSS_STYLE_PROPERTY (prop))
1440 data = style_data_lookup (context, gtk_style_context_get_state (context));
1441 return _gtk_css_computed_values_get_section (data->store, _gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (prop)));
1444 static const GValue *
1445 gtk_style_context_query_func (guint id,
1448 return _gtk_css_computed_values_get_value (values, id);
1452 * gtk_style_context_get_property:
1453 * @context: a #GtkStyleContext
1454 * @property: style property name
1455 * @state: state to retrieve the property value for
1456 * @value: (out) (transfer full): return location for the style property value
1458 * Gets a style property from @context for the given state.
1460 * When @value is no longer needed, g_value_unset() must be called
1461 * to free any allocated memory.
1466 gtk_style_context_get_property (GtkStyleContext *context,
1467 const gchar *property,
1468 GtkStateFlags state,
1471 GtkStyleContextPrivate *priv;
1472 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 _gtk_style_property_query (prop, value, gtk_style_context_query_func, data->store);
1499 * gtk_style_context_get_valist:
1500 * @context: a #GtkStyleContext
1501 * @state: state to retrieve the property values for
1502 * @args: va_list of property name/return location pairs, followed by %NULL
1504 * Retrieves several style property values from @context for a given state.
1509 gtk_style_context_get_valist (GtkStyleContext *context,
1510 GtkStateFlags state,
1513 const gchar *property_name;
1515 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1517 property_name = va_arg (args, const gchar *);
1519 while (property_name)
1521 gchar *error = NULL;
1522 GValue value = G_VALUE_INIT;
1524 gtk_style_context_get_property (context,
1529 G_VALUE_LCOPY (&value, args, 0, &error);
1530 g_value_unset (&value);
1534 g_warning ("Could not get style property \"%s\": %s", property_name, error);
1539 property_name = va_arg (args, const gchar *);
1544 * gtk_style_context_get:
1545 * @context: a #GtkStyleContext
1546 * @state: state to retrieve the property values for
1547 * @...: property name /return value pairs, followed by %NULL
1549 * Retrieves several style property values from @context for a
1555 gtk_style_context_get (GtkStyleContext *context,
1556 GtkStateFlags state,
1561 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1563 va_start (args, state);
1564 gtk_style_context_get_valist (context, state, args);
1569 * gtk_style_context_set_state:
1570 * @context: a #GtkStyleContext
1571 * @flags: state to represent
1573 * Sets the state to be used when rendering with any
1574 * of the gtk_render_*() functions.
1579 gtk_style_context_set_state (GtkStyleContext *context,
1580 GtkStateFlags flags)
1582 GtkStyleContextPrivate *priv;
1585 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1587 priv = context->priv;
1588 info = priv->info_stack->data;
1589 info->state_flags = flags;
1593 * gtk_style_context_get_state:
1594 * @context: a #GtkStyleContext
1596 * Returns the state used when rendering.
1598 * Returns: the state flags
1603 gtk_style_context_get_state (GtkStyleContext *context)
1605 GtkStyleContextPrivate *priv;
1608 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
1610 priv = context->priv;
1611 info = priv->info_stack->data;
1613 return info->state_flags;
1617 context_has_animatable_region (GtkStyleContext *context,
1620 GtkStyleContextPrivate *priv;
1622 /* NULL region_id means everything
1623 * rendered through the style context
1628 priv = context->priv;
1629 return g_slist_find (priv->animation_regions, region_id) != NULL;
1633 * gtk_style_context_state_is_running:
1634 * @context: a #GtkStyleContext
1635 * @state: a widget state
1636 * @progress: (out): return location for the transition progress
1638 * Returns %TRUE if there is a transition animation running for the
1639 * current region (see gtk_style_context_push_animatable_region()).
1641 * If @progress is not %NULL, the animation progress will be returned
1642 * there, 0.0 means the state is closest to being unset, while 1.0 means
1643 * it's closest to being set. This means transition animation will
1644 * run from 0 to 1 when @state is being set and from 1 to 0 when
1647 * Returns: %TRUE if there is a running transition animation for @state.
1652 gtk_style_context_state_is_running (GtkStyleContext *context,
1656 GtkStyleContextPrivate *priv;
1657 AnimationInfo *info;
1660 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1662 priv = context->priv;
1664 for (l = priv->animations; l; l = l->next)
1668 if (info->state == state &&
1669 context_has_animatable_region (context, info->region_id))
1672 *progress = _gtk_timeline_get_progress (info->timeline);
1682 * gtk_style_context_set_path:
1683 * @context: a #GtkStyleContext
1684 * @path: a #GtkWidgetPath
1686 * Sets the #GtkWidgetPath used for style matching. As a
1687 * consequence, the style will be regenerated to match
1688 * the new given path.
1690 * If you are using a #GtkStyleContext returned from
1691 * gtk_widget_get_style_context(), you do not need to call
1697 gtk_style_context_set_path (GtkStyleContext *context,
1698 GtkWidgetPath *path)
1700 GtkStyleContextPrivate *priv;
1702 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1703 g_return_if_fail (path != NULL);
1705 priv = context->priv;
1707 if (priv->widget_path)
1709 gtk_widget_path_free (priv->widget_path);
1710 priv->widget_path = NULL;
1714 priv->widget_path = gtk_widget_path_copy (path);
1716 gtk_style_context_invalidate (context);
1720 * gtk_style_context_get_path:
1721 * @context: a #GtkStyleContext
1723 * Returns the widget path used for style matching.
1725 * Returns: (transfer none): A #GtkWidgetPath
1729 const GtkWidgetPath *
1730 gtk_style_context_get_path (GtkStyleContext *context)
1732 GtkStyleContextPrivate *priv;
1734 priv = context->priv;
1735 return priv->widget_path;
1739 * gtk_style_context_set_parent:
1740 * @context: a #GtkStyleContext
1741 * @parent: (allow-none): the new parent or %NULL
1743 * Sets the parent style context for @context. The parent style
1744 * context is used to implement
1745 * <ulink url="http://www.w3.org/TR/css3-cascade/#inheritance">inheritance</ulink>
1748 * If you are using a #GtkStyleContext returned from
1749 * gtk_widget_get_style_context(), the parent will be set for you.
1754 gtk_style_context_set_parent (GtkStyleContext *context,
1755 GtkStyleContext *parent)
1757 GtkStyleContextPrivate *priv;
1759 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1760 g_return_if_fail (parent == NULL || GTK_IS_STYLE_CONTEXT (parent));
1762 priv = context->priv;
1764 if (priv->parent == parent)
1768 g_object_ref (parent);
1771 g_object_unref (priv->parent);
1773 priv->parent = parent;
1775 g_object_notify (G_OBJECT (context), "parent");
1776 gtk_style_context_invalidate (context);
1780 * gtk_style_context_get_parent:
1781 * @context: a #GtkStyleContext
1783 * Gets the parent context set via gtk_style_context_set_parent().
1784 * See that function for details.
1786 * Returns: (transfer none): the parent context or %NULL
1791 gtk_style_context_get_parent (GtkStyleContext *context)
1793 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1795 return context->priv->parent;
1799 * gtk_style_context_save:
1800 * @context: a #GtkStyleContext
1802 * Saves the @context state, so all modifications done through
1803 * gtk_style_context_add_class(), gtk_style_context_remove_class(),
1804 * gtk_style_context_add_region(), gtk_style_context_remove_region()
1805 * or gtk_style_context_set_junction_sides() can be reverted in one
1806 * go through gtk_style_context_restore().
1811 gtk_style_context_save (GtkStyleContext *context)
1813 GtkStyleContextPrivate *priv;
1816 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1818 priv = context->priv;
1820 g_assert (priv->info_stack != NULL);
1822 info = style_info_copy (priv->info_stack->data);
1823 priv->info_stack = g_slist_prepend (priv->info_stack, info);
1827 * gtk_style_context_restore:
1828 * @context: a #GtkStyleContext
1830 * Restores @context state to a previous stage.
1831 * See gtk_style_context_save().
1836 gtk_style_context_restore (GtkStyleContext *context)
1838 GtkStyleContextPrivate *priv;
1841 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1843 priv = context->priv;
1845 if (priv->info_stack)
1847 info = priv->info_stack->data;
1848 priv->info_stack = g_slist_remove (priv->info_stack, info);
1849 style_info_free (info);
1852 if (!priv->info_stack)
1854 g_warning ("Unpaired gtk_style_context_restore() call");
1856 /* Create default region */
1857 info = style_info_new ();
1858 priv->info_stack = g_slist_prepend (priv->info_stack, info);
1861 priv->current_data = NULL;
1865 style_class_find (GArray *array,
1870 gboolean found = FALSE;
1876 if (!array || array->len == 0)
1880 max = array->len - 1;
1886 mid = (min + max) / 2;
1887 item = g_array_index (array, GQuark, mid);
1889 if (class_quark == item)
1894 else if (class_quark > item)
1895 min = pos = mid + 1;
1902 while (!found && min <= max);
1911 region_find (GArray *array,
1916 gboolean found = FALSE;
1922 if (!array || array->len == 0)
1926 max = array->len - 1;
1932 mid = (min + max) / 2;
1933 region = &g_array_index (array, GtkRegion, mid);
1935 if (region->class_quark == class_quark)
1940 else if (region->class_quark > class_quark)
1941 min = pos = mid + 1;
1948 while (!found && min <= max);
1957 * gtk_style_context_add_class:
1958 * @context: a #GtkStyleContext
1959 * @class_name: class name to use in styling
1961 * Adds a style class to @context, so posterior calls to
1962 * gtk_style_context_get() or any of the gtk_render_*()
1963 * functions will make use of this new class for styling.
1965 * In the CSS file format, a #GtkEntry defining an "entry"
1966 * class, would be matched by:
1969 * GtkEntry.entry { ... }
1972 * While any widget defining an "entry" class would be
1981 gtk_style_context_add_class (GtkStyleContext *context,
1982 const gchar *class_name)
1984 GtkStyleContextPrivate *priv;
1989 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1990 g_return_if_fail (class_name != NULL);
1992 priv = context->priv;
1993 class_quark = g_quark_from_string (class_name);
1995 g_assert (priv->info_stack != NULL);
1996 info = priv->info_stack->data;
1998 if (!style_class_find (info->style_classes, class_quark, &position))
2000 g_array_insert_val (info->style_classes, position, class_quark);
2002 /* Unset current data, as it likely changed due to the class change */
2003 priv->current_data = NULL;
2008 * gtk_style_context_remove_class:
2009 * @context: a #GtkStyleContext
2010 * @class_name: class name to remove
2012 * Removes @class_name from @context.
2017 gtk_style_context_remove_class (GtkStyleContext *context,
2018 const gchar *class_name)
2020 GtkStyleContextPrivate *priv;
2025 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2026 g_return_if_fail (class_name != NULL);
2028 class_quark = g_quark_try_string (class_name);
2033 priv = context->priv;
2035 g_assert (priv->info_stack != NULL);
2036 info = priv->info_stack->data;
2038 if (style_class_find (info->style_classes, class_quark, &position))
2040 g_array_remove_index (info->style_classes, position);
2042 /* Unset current data, as it likely changed due to the class change */
2043 priv->current_data = NULL;
2048 * gtk_style_context_has_class:
2049 * @context: a #GtkStyleContext
2050 * @class_name: a class name
2052 * Returns %TRUE if @context currently has defined the
2055 * Returns: %TRUE if @context has @class_name defined
2060 gtk_style_context_has_class (GtkStyleContext *context,
2061 const gchar *class_name)
2063 GtkStyleContextPrivate *priv;
2067 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2068 g_return_val_if_fail (class_name != NULL, FALSE);
2070 class_quark = g_quark_try_string (class_name);
2075 priv = context->priv;
2077 g_assert (priv->info_stack != NULL);
2078 info = priv->info_stack->data;
2080 if (style_class_find (info->style_classes, class_quark, NULL))
2087 * gtk_style_context_list_classes:
2088 * @context: a #GtkStyleContext
2090 * Returns the list of classes currently defined in @context.
2092 * Returns: (transfer container) (element-type utf8): a #GList of
2093 * strings with the currently defined classes. The contents
2094 * of the list are owned by GTK+, but you must free the list
2095 * itself with g_list_free() when you are done with it.
2100 gtk_style_context_list_classes (GtkStyleContext *context)
2102 GtkStyleContextPrivate *priv;
2104 GList *classes = NULL;
2107 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2109 priv = context->priv;
2111 g_assert (priv->info_stack != NULL);
2112 info = priv->info_stack->data;
2114 for (i = 0; i < info->style_classes->len; i++)
2118 quark = g_array_index (info->style_classes, GQuark, i);
2119 classes = g_list_prepend (classes, (gchar *) g_quark_to_string (quark));
2126 * gtk_style_context_list_regions:
2127 * @context: a #GtkStyleContext
2129 * Returns the list of regions currently defined in @context.
2131 * Returns: (transfer container) (element-type utf8): a #GList of
2132 * strings with the currently defined regions. The contents
2133 * of the list are owned by GTK+, but you must free the list
2134 * itself with g_list_free() when you are done with it.
2139 gtk_style_context_list_regions (GtkStyleContext *context)
2141 GtkStyleContextPrivate *priv;
2143 GList *classes = NULL;
2146 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2148 priv = context->priv;
2150 g_assert (priv->info_stack != NULL);
2151 info = priv->info_stack->data;
2153 for (i = 0; i < info->regions->len; i++)
2156 const gchar *class_name;
2158 region = &g_array_index (info->regions, GtkRegion, i);
2160 class_name = g_quark_to_string (region->class_quark);
2161 classes = g_list_prepend (classes, (gchar *) class_name);
2168 _gtk_style_context_check_region_name (const gchar *str)
2170 g_return_val_if_fail (str != NULL, FALSE);
2172 if (!g_ascii_islower (str[0]))
2178 !g_ascii_islower (*str))
2188 * gtk_style_context_add_region:
2189 * @context: a #GtkStyleContext
2190 * @region_name: region name to use in styling
2191 * @flags: flags that apply to the region
2193 * Adds a region to @context, so posterior calls to
2194 * gtk_style_context_get() or any of the gtk_render_*()
2195 * functions will make use of this new region for styling.
2197 * In the CSS file format, a #GtkTreeView defining a "row"
2198 * region, would be matched by:
2201 * GtkTreeView row { ... }
2204 * Pseudo-classes are used for matching @flags, so the two
2207 * GtkTreeView row:nth-child(even) { ... }
2208 * GtkTreeView row:nth-child(odd) { ... }
2211 * would apply to even and odd rows, respectively.
2213 * <note><para>Region names must only contain lowercase letters
2214 * and '-', starting always with a lowercase letter.</para></note>
2219 gtk_style_context_add_region (GtkStyleContext *context,
2220 const gchar *region_name,
2221 GtkRegionFlags flags)
2223 GtkStyleContextPrivate *priv;
2225 GQuark region_quark;
2228 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2229 g_return_if_fail (region_name != NULL);
2230 g_return_if_fail (_gtk_style_context_check_region_name (region_name));
2232 priv = context->priv;
2233 region_quark = g_quark_from_string (region_name);
2235 g_assert (priv->info_stack != NULL);
2236 info = priv->info_stack->data;
2238 if (!region_find (info->regions, region_quark, &position))
2242 region.class_quark = region_quark;
2243 region.flags = flags;
2245 g_array_insert_val (info->regions, position, region);
2247 /* Unset current data, as it likely changed due to the region change */
2248 priv->current_data = NULL;
2253 * gtk_style_context_remove_region:
2254 * @context: a #GtkStyleContext
2255 * @region_name: region name to unset
2257 * Removes a region from @context.
2262 gtk_style_context_remove_region (GtkStyleContext *context,
2263 const gchar *region_name)
2265 GtkStyleContextPrivate *priv;
2267 GQuark region_quark;
2270 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2271 g_return_if_fail (region_name != NULL);
2273 region_quark = g_quark_try_string (region_name);
2278 priv = context->priv;
2280 g_assert (priv->info_stack != NULL);
2281 info = priv->info_stack->data;
2283 if (region_find (info->regions, region_quark, &position))
2285 g_array_remove_index (info->regions, position);
2287 /* Unset current data, as it likely changed due to the region change */
2288 priv->current_data = NULL;
2293 * gtk_style_context_has_region:
2294 * @context: a #GtkStyleContext
2295 * @region_name: a region name
2296 * @flags_return: (out) (allow-none): return location for region flags
2298 * Returns %TRUE if @context has the region defined.
2299 * If @flags_return is not %NULL, it is set to the flags
2300 * affecting the region.
2302 * Returns: %TRUE if region is defined
2307 gtk_style_context_has_region (GtkStyleContext *context,
2308 const gchar *region_name,
2309 GtkRegionFlags *flags_return)
2311 GtkStyleContextPrivate *priv;
2313 GQuark region_quark;
2316 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2317 g_return_val_if_fail (region_name != NULL, FALSE);
2322 region_quark = g_quark_try_string (region_name);
2327 priv = context->priv;
2329 g_assert (priv->info_stack != NULL);
2330 info = priv->info_stack->data;
2332 if (region_find (info->regions, region_quark, &position))
2338 region = &g_array_index (info->regions, GtkRegion, position);
2339 *flags_return = region->flags;
2348 style_property_values_cmp (gconstpointer bsearch_node1,
2349 gconstpointer bsearch_node2)
2351 const PropertyValue *val1 = bsearch_node1;
2352 const PropertyValue *val2 = bsearch_node2;
2354 if (val1->widget_type != val2->widget_type)
2355 return val1->widget_type < val2->widget_type ? -1 : 1;
2357 if (val1->pspec != val2->pspec)
2358 return val1->pspec < val2->pspec ? -1 : 1;
2360 if (val1->state != val2->state)
2361 return val1->state < val2->state ? -1 : 1;
2367 _gtk_style_context_peek_property (GtkStyleContext *context,
2368 const char *property_name)
2370 StyleData *data = style_data_lookup (context, gtk_style_context_get_state (context));
2372 return _gtk_css_computed_values_get_value_by_name (data->store, property_name);
2376 _gtk_style_context_get_number (GtkStyleContext *context,
2377 const char *property_name,
2378 double one_hundred_percent)
2380 const GValue *value;
2382 value = _gtk_style_context_peek_property (context, property_name);
2383 return _gtk_css_number_get (g_value_get_boxed (value), one_hundred_percent);
2387 _gtk_style_context_peek_style_property (GtkStyleContext *context,
2389 GtkStateFlags state,
2392 GtkStyleContextPrivate *priv;
2393 PropertyValue *pcache, key = { 0 };
2394 GList *global_list = NULL;
2398 priv = context->priv;
2399 data = style_data_lookup (context, state);
2401 key.widget_type = widget_type;
2405 /* need value cache array */
2406 if (!data->property_cache)
2407 data->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
2410 pcache = bsearch (&key,
2411 data->property_cache->data, data->property_cache->len,
2412 sizeof (PropertyValue), style_property_values_cmp);
2414 return &pcache->value;
2418 while (i < data->property_cache->len &&
2419 style_property_values_cmp (&key, &g_array_index (data->property_cache, PropertyValue, i)) >= 0)
2422 g_array_insert_val (data->property_cache, i, key);
2423 pcache = &g_array_index (data->property_cache, PropertyValue, i);
2425 /* cache miss, initialize value type, then set contents */
2426 g_param_spec_ref (pcache->pspec);
2427 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2431 global_list = g_object_get_qdata (G_OBJECT (priv->screen), provider_list_quark);
2432 global_list = g_list_last (global_list);
2435 if (priv->widget_path)
2437 GList *list, *global, *elem;
2439 list = priv->providers_last;
2440 global = global_list;
2442 while ((elem = find_next_candidate (list, global, FALSE)) != NULL)
2444 GtkStyleProviderData *provider_data;
2446 provider_data = elem->data;
2451 global = global->prev;
2453 if (gtk_style_provider_get_style_property (provider_data->provider,
2454 priv->widget_path, state,
2455 pspec, &pcache->value))
2457 /* Resolve symbolic colors to GdkColor/GdkRGBA */
2458 if (G_VALUE_TYPE (&pcache->value) == GTK_TYPE_SYMBOLIC_COLOR)
2460 GtkSymbolicColor *color;
2463 color = g_value_dup_boxed (&pcache->value);
2465 g_value_unset (&pcache->value);
2467 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2468 g_value_init (&pcache->value, GDK_TYPE_RGBA);
2470 g_value_init (&pcache->value, GDK_TYPE_COLOR);
2472 if (_gtk_style_context_resolve_color (context, color, &rgba))
2474 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2475 g_value_set_boxed (&pcache->value, &rgba);
2480 rgb.red = rgba.red * 65535. + 0.5;
2481 rgb.green = rgba.green * 65535. + 0.5;
2482 rgb.blue = rgba.blue * 65535. + 0.5;
2484 g_value_set_boxed (&pcache->value, &rgb);
2488 g_param_value_set_default (pspec, &pcache->value);
2490 gtk_symbolic_color_unref (color);
2493 return &pcache->value;
2498 /* not supplied by any provider, revert to default */
2499 g_param_value_set_default (pspec, &pcache->value);
2501 return &pcache->value;
2505 * gtk_style_context_get_style_property:
2506 * @context: a #GtkStyleContext
2507 * @property_name: the name of the widget style property
2508 * @value: Return location for the property value
2510 * Gets the value for a widget style property.
2512 * When @value is no longer needed, g_value_unset() must be called
2513 * to free any allocated memory.
2516 gtk_style_context_get_style_property (GtkStyleContext *context,
2517 const gchar *property_name,
2520 GtkStyleContextPrivate *priv;
2521 GtkWidgetClass *widget_class;
2522 GtkStateFlags state;
2524 const GValue *peek_value;
2527 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2528 g_return_if_fail (property_name != NULL);
2529 g_return_if_fail (value != NULL);
2531 priv = context->priv;
2533 if (!priv->widget_path)
2536 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2538 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2540 g_warning ("%s: can't get style properties for non-widget class `%s'",
2542 g_type_name (widget_type));
2546 widget_class = g_type_class_ref (widget_type);
2547 pspec = gtk_widget_class_find_style_property (widget_class, property_name);
2548 g_type_class_unref (widget_class);
2552 g_warning ("%s: widget class `%s' has no style property named `%s'",
2554 g_type_name (widget_type),
2559 state = gtk_style_context_get_state (context);
2560 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2563 if (G_VALUE_TYPE (value) == G_VALUE_TYPE (peek_value))
2564 g_value_copy (peek_value, value);
2565 else if (g_value_type_transformable (G_VALUE_TYPE (peek_value), G_VALUE_TYPE (value)))
2566 g_value_transform (peek_value, value);
2568 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
2570 G_VALUE_TYPE_NAME (peek_value),
2571 G_VALUE_TYPE_NAME (value));
2575 * gtk_style_context_get_style_valist:
2576 * @context: a #GtkStyleContext
2577 * @args: va_list of property name/return location pairs, followed by %NULL
2579 * Retrieves several widget style properties from @context according to the
2585 gtk_style_context_get_style_valist (GtkStyleContext *context,
2588 GtkStyleContextPrivate *priv;
2589 const gchar *prop_name;
2590 GtkStateFlags state;
2593 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2595 prop_name = va_arg (args, const gchar *);
2596 priv = context->priv;
2598 if (!priv->widget_path)
2601 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2603 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2605 g_warning ("%s: can't get style properties for non-widget class `%s'",
2607 g_type_name (widget_type));
2611 state = gtk_style_context_get_state (context);
2615 GtkWidgetClass *widget_class;
2617 const GValue *peek_value;
2620 widget_class = g_type_class_ref (widget_type);
2621 pspec = gtk_widget_class_find_style_property (widget_class, prop_name);
2622 g_type_class_unref (widget_class);
2626 g_warning ("%s: widget class `%s' has no style property named `%s'",
2628 g_type_name (widget_type),
2633 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2636 G_VALUE_LCOPY (peek_value, args, 0, &error);
2640 g_warning ("can't retrieve style property `%s' of type `%s': %s",
2642 G_VALUE_TYPE_NAME (peek_value),
2647 prop_name = va_arg (args, const gchar *);
2652 * gtk_style_context_get_style:
2653 * @context: a #GtkStyleContext
2654 * @...: property name /return value pairs, followed by %NULL
2656 * Retrieves several widget style properties from @context according to the
2662 gtk_style_context_get_style (GtkStyleContext *context,
2667 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2669 va_start (args, context);
2670 gtk_style_context_get_style_valist (context, args);
2676 * gtk_style_context_lookup_icon_set:
2677 * @context: a #GtkStyleContext
2678 * @stock_id: an icon name
2680 * Looks up @stock_id in the icon factories associated to @context and
2681 * the default icon factory, returning an icon set if found, otherwise
2684 * Returns: (transfer none): The looked up %GtkIconSet, or %NULL
2687 gtk_style_context_lookup_icon_set (GtkStyleContext *context,
2688 const gchar *stock_id)
2690 GtkStyleContextPrivate *priv;
2694 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2695 g_return_val_if_fail (stock_id != NULL, NULL);
2697 priv = context->priv;
2698 g_return_val_if_fail (priv->widget_path != NULL, NULL);
2700 data = style_data_lookup (context, 0);
2702 for (list = data->icon_factories; list; list = list->next)
2704 GtkIconFactory *factory;
2705 GtkIconSet *icon_set;
2707 factory = list->data;
2708 icon_set = gtk_icon_factory_lookup (factory, stock_id);
2714 return gtk_icon_factory_lookup_default (stock_id);
2718 * gtk_style_context_set_screen:
2719 * @context: a #GtkStyleContext
2720 * @screen: a #GdkScreen
2722 * Attaches @context to the given screen.
2724 * The screen is used to add style information from 'global' style
2725 * providers, such as the screens #GtkSettings instance.
2727 * If you are using a #GtkStyleContext returned from
2728 * gtk_widget_get_style_context(), you do not need to
2729 * call this yourself.
2734 gtk_style_context_set_screen (GtkStyleContext *context,
2737 GtkStyleContextPrivate *priv;
2739 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2740 g_return_if_fail (GDK_IS_SCREEN (screen));
2742 priv = context->priv;
2743 if (priv->screen == screen)
2746 priv->screen = screen;
2748 g_object_notify (G_OBJECT (context), "screen");
2750 gtk_style_context_invalidate (context);
2754 * gtk_style_context_get_screen:
2755 * @context: a #GtkStyleContext
2757 * Returns the #GdkScreen to which @context is attached.
2759 * Returns: (transfer none): a #GdkScreen.
2762 gtk_style_context_get_screen (GtkStyleContext *context)
2764 GtkStyleContextPrivate *priv;
2766 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2768 priv = context->priv;
2769 return priv->screen;
2773 * gtk_style_context_set_direction:
2774 * @context: a #GtkStyleContext
2775 * @direction: the new direction.
2777 * Sets the reading direction for rendering purposes.
2779 * If you are using a #GtkStyleContext returned from
2780 * gtk_widget_get_style_context(), you do not need to
2781 * call this yourself.
2786 gtk_style_context_set_direction (GtkStyleContext *context,
2787 GtkTextDirection direction)
2789 GtkStyleContextPrivate *priv;
2791 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2793 priv = context->priv;
2794 priv->direction = direction;
2796 g_object_notify (G_OBJECT (context), "direction");
2800 * gtk_style_context_get_direction:
2801 * @context: a #GtkStyleContext
2803 * Returns the widget direction used for rendering.
2805 * Returns: the widget direction
2810 gtk_style_context_get_direction (GtkStyleContext *context)
2812 GtkStyleContextPrivate *priv;
2814 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), GTK_TEXT_DIR_LTR);
2816 priv = context->priv;
2817 return priv->direction;
2821 * gtk_style_context_set_junction_sides:
2822 * @context: a #GtkStyleContext
2823 * @sides: sides where rendered elements are visually connected to
2826 * Sets the sides where rendered elements (mostly through
2827 * gtk_render_frame()) will visually connect with other visual elements.
2829 * This is merely a hint that may or may not be honored
2830 * by theming engines.
2832 * Container widgets are expected to set junction hints as appropriate
2833 * for their children, so it should not normally be necessary to call
2834 * this function manually.
2839 gtk_style_context_set_junction_sides (GtkStyleContext *context,
2840 GtkJunctionSides sides)
2842 GtkStyleContextPrivate *priv;
2845 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2847 priv = context->priv;
2848 info = priv->info_stack->data;
2849 info->junction_sides = sides;
2853 * gtk_style_context_get_junction_sides:
2854 * @context: a #GtkStyleContext
2856 * Returns the sides where rendered elements connect visually with others.
2858 * Returns: the junction sides
2863 gtk_style_context_get_junction_sides (GtkStyleContext *context)
2865 GtkStyleContextPrivate *priv;
2868 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
2870 priv = context->priv;
2871 info = priv->info_stack->data;
2872 return info->junction_sides;
2875 static GtkSymbolicColor *
2876 gtk_style_context_color_lookup_func (gpointer contextp,
2879 GtkSymbolicColor *sym_color;
2880 GtkStyleContext *context = contextp;
2881 GtkStyleContextPrivate *priv = context->priv;
2882 GList *elem, *list, *global_list = NULL;
2884 list = priv->providers_last;
2887 global_list = g_object_get_qdata (G_OBJECT (priv->screen), provider_list_quark);
2888 global_list = g_list_last (global_list);
2893 while (sym_color == NULL &&
2894 (elem = find_next_candidate (list, global_list, FALSE)) != NULL)
2896 GtkStyleProviderData *data;
2903 global_list = global_list->prev;
2905 if (GTK_IS_STYLE_PROVIDER_PRIVATE (data->provider))
2907 sym_color = _gtk_style_provider_private_get_color (GTK_STYLE_PROVIDER_PRIVATE (data->provider),
2912 /* If somebody hits this code path, shout at them */
2921 _gtk_style_context_resolve_color (GtkStyleContext *context,
2922 GtkSymbolicColor *color,
2925 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2926 g_return_val_if_fail (color != NULL, FALSE);
2927 g_return_val_if_fail (result != NULL, FALSE);
2929 return _gtk_symbolic_color_resolve_full (color,
2930 gtk_style_context_color_lookup_func,
2936 * gtk_style_context_lookup_color:
2937 * @context: a #GtkStyleContext
2938 * @color_name: color name to lookup
2939 * @color: (out): Return location for the looked up color
2941 * Looks up and resolves a color name in the @context color map.
2943 * Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
2946 gtk_style_context_lookup_color (GtkStyleContext *context,
2947 const gchar *color_name,
2950 GtkSymbolicColor *sym_color;
2952 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2953 g_return_val_if_fail (color_name != NULL, FALSE);
2954 g_return_val_if_fail (color != NULL, FALSE);
2956 sym_color = gtk_style_context_color_lookup_func (context, color_name);
2957 if (sym_color == NULL)
2960 return _gtk_style_context_resolve_color (context, sym_color, color);
2964 * gtk_style_context_notify_state_change:
2965 * @context: a #GtkStyleContext
2966 * @window: a #GdkWindow
2967 * @region_id: (allow-none): animatable region to notify on, or %NULL.
2968 * See gtk_style_context_push_animatable_region()
2969 * @state: state to trigger transition for
2970 * @state_value: %TRUE if @state is the state we are changing to,
2971 * %FALSE if we are changing away from it
2973 * Notifies a state change on @context, so if the current style makes use
2974 * of transition animations, one will be started so all rendered elements
2975 * under @region_id are animated for state @state being set to value
2978 * The @window parameter is used in order to invalidate the rendered area
2979 * as the animation runs, so make sure it is the same window that is being
2980 * rendered on by the gtk_render_*() functions.
2982 * If @region_id is %NULL, all rendered elements using @context will be
2983 * affected by this state transition.
2985 * As a practical example, a #GtkButton notifying a state transition on
2986 * the prelight state:
2988 * gtk_style_context_notify_state_change (context,
2989 * gtk_widget_get_window (widget),
2991 * GTK_STATE_PRELIGHT,
2992 * button->in_button);
2995 * Can be handled in the CSS file like this:
2998 * background-color: #f00
3002 * background-color: #fff;
3003 * transition: 200ms linear
3007 * This combination will animate the button background from red to white
3008 * if a pointer enters the button, and back to red if the pointer leaves
3011 * Note that @state is used when finding the transition parameters, which
3012 * is why the style places the transition under the :hover pseudo-class.
3017 gtk_style_context_notify_state_change (GtkStyleContext *context,
3021 gboolean state_value)
3023 GtkStyleContextPrivate *priv;
3024 GtkAnimationDescription *desc;
3025 AnimationInfo *info;
3026 GtkStateFlags flags;
3030 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3031 g_return_if_fail (GDK_IS_WINDOW (window));
3032 g_return_if_fail (state > GTK_STATE_NORMAL && state <= GTK_STATE_FOCUSED);
3034 priv = context->priv;
3035 g_return_if_fail (priv->widget_path != NULL);
3037 state_value = (state_value == TRUE);
3041 case GTK_STATE_ACTIVE:
3042 flags = GTK_STATE_FLAG_ACTIVE;
3044 case GTK_STATE_PRELIGHT:
3045 flags = GTK_STATE_FLAG_PRELIGHT;
3047 case GTK_STATE_SELECTED:
3048 flags = GTK_STATE_FLAG_SELECTED;
3050 case GTK_STATE_INSENSITIVE:
3051 flags = GTK_STATE_FLAG_INSENSITIVE;
3053 case GTK_STATE_INCONSISTENT:
3054 flags = GTK_STATE_FLAG_INCONSISTENT;
3056 case GTK_STATE_FOCUSED:
3057 flags = GTK_STATE_FLAG_FOCUSED;
3059 case GTK_STATE_NORMAL:
3065 /* Find out if there is any animation description for the given
3066 * state, it will fallback to the normal state as well if necessary.
3068 data = style_data_lookup (context, flags);
3069 v = _gtk_css_computed_values_get_value_by_name (data->store, "transition");
3072 desc = g_value_get_boxed (v);
3076 if (_gtk_animation_description_get_duration (desc) == 0)
3079 info = animation_info_lookup (context, region_id, state);
3082 info->target_value != state_value)
3084 /* Target values are the opposite */
3085 if (!_gtk_timeline_get_loop (info->timeline))
3087 /* Reverse the animation */
3088 if (_gtk_timeline_get_direction (info->timeline) == GTK_TIMELINE_DIRECTION_FORWARD)
3089 _gtk_timeline_set_direction (info->timeline, GTK_TIMELINE_DIRECTION_BACKWARD);
3091 _gtk_timeline_set_direction (info->timeline, GTK_TIMELINE_DIRECTION_FORWARD);
3093 info->target_value = state_value;
3097 /* Take it out of its looping state */
3098 _gtk_timeline_set_loop (info->timeline, FALSE);
3102 (!_gtk_animation_description_get_loop (desc) ||
3105 info = animation_info_new (context, region_id,
3106 _gtk_animation_description_get_duration (desc),
3107 _gtk_animation_description_get_progress_type (desc),
3108 _gtk_animation_description_get_loop (desc),
3109 state, state_value, window);
3111 priv->animations = g_slist_prepend (priv->animations, info);
3112 priv->animations_invalidated = TRUE;
3117 * gtk_style_context_cancel_animations:
3118 * @context: a #GtkStyleContext
3119 * @region_id: (allow-none): animatable region to stop, or %NULL.
3120 * See gtk_style_context_push_animatable_region()
3122 * Stops all running animations for @region_id and all animatable
3123 * regions underneath.
3125 * A %NULL @region_id will stop all ongoing animations in @context,
3126 * when dealing with a #GtkStyleContext obtained through
3127 * gtk_widget_get_style_context(), this is normally done for you
3128 * in all circumstances you would expect all widget to be stopped,
3129 * so this should be only used in complex widgets with different
3130 * animatable regions.
3135 gtk_style_context_cancel_animations (GtkStyleContext *context,
3138 GtkStyleContextPrivate *priv;
3139 AnimationInfo *info;
3142 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3144 priv = context->priv;
3145 l = priv->animations;
3153 info->region_id == region_id ||
3154 g_slist_find (info->parent_regions, region_id))
3156 priv->animations = g_slist_remove (priv->animations, info);
3157 animation_info_free (info);
3163 is_parent_of (GdkWindow *parent,
3166 GtkWidget *child_widget, *parent_widget;
3169 gdk_window_get_user_data (child, (gpointer *) &child_widget);
3170 gdk_window_get_user_data (parent, (gpointer *) &parent_widget);
3172 if (child_widget != parent_widget &&
3173 !gtk_widget_is_ancestor (child_widget, parent_widget))
3180 if (window == parent)
3183 window = gdk_window_get_parent (window);
3190 * gtk_style_context_scroll_animations:
3191 * @context: a #GtkStyleContext
3192 * @window: a #GdkWindow used previously in
3193 * gtk_style_context_notify_state_change()
3194 * @dx: Amount to scroll in the X axis
3195 * @dy: Amount to scroll in the Y axis
3197 * This function is analogous to gdk_window_scroll(), and
3198 * should be called together with it so the invalidation
3199 * areas for any ongoing animation are scrolled together
3205 gtk_style_context_scroll_animations (GtkStyleContext *context,
3210 GtkStyleContextPrivate *priv;
3211 AnimationInfo *info;
3214 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3215 g_return_if_fail (GDK_IS_WINDOW (window));
3217 priv = context->priv;
3218 l = priv->animations;
3225 if (info->invalidation_region &&
3226 (window == info->window ||
3227 is_parent_of (window, info->window)))
3228 cairo_region_translate (info->invalidation_region, dx, dy);
3233 * gtk_style_context_push_animatable_region:
3234 * @context: a #GtkStyleContext
3235 * @region_id: unique identifier for the animatable region
3237 * Pushes an animatable region, so all further gtk_render_*() calls between
3238 * this call and the following gtk_style_context_pop_animatable_region()
3239 * will potentially show transition animations for this region if
3240 * gtk_style_context_notify_state_change() is called for a given state,
3241 * and the current theme/style defines transition animations for state
3244 * The @region_id used must be unique in @context so the theming engine
3245 * can uniquely identify rendered elements subject to a state transition.
3250 gtk_style_context_push_animatable_region (GtkStyleContext *context,
3253 GtkStyleContextPrivate *priv;
3255 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3256 g_return_if_fail (region_id != NULL);
3258 priv = context->priv;
3259 priv->animation_regions = g_slist_prepend (priv->animation_regions, region_id);
3263 * gtk_style_context_pop_animatable_region:
3264 * @context: a #GtkStyleContext
3266 * Pops an animatable region from @context.
3267 * See gtk_style_context_push_animatable_region().
3272 gtk_style_context_pop_animatable_region (GtkStyleContext *context)
3274 GtkStyleContextPrivate *priv;
3276 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3278 priv = context->priv;
3279 priv->animation_regions = g_slist_delete_link (priv->animation_regions,
3280 priv->animation_regions);
3284 _gtk_style_context_invalidate_animation_areas (GtkStyleContext *context)
3286 GtkStyleContextPrivate *priv;
3289 priv = context->priv;
3291 for (l = priv->animations; l; l = l->next)
3293 AnimationInfo *info;
3297 /* A NULL invalidation region means it has to be recreated on
3298 * the next expose event, this happens usually after a widget
3299 * allocation change, so the next expose after it will update
3300 * the invalidation region.
3302 if (info->invalidation_region)
3304 cairo_region_destroy (info->invalidation_region);
3305 info->invalidation_region = NULL;
3309 priv->animations_invalidated = TRUE;
3313 _gtk_style_context_coalesce_animation_areas (GtkStyleContext *context,
3316 GtkStyleContextPrivate *priv;
3319 priv = context->priv;
3321 if (!priv->animations_invalidated)
3324 l = priv->animations;
3328 AnimationInfo *info;
3337 if (info->invalidation_region)
3340 if (info->rectangles->len == 0)
3343 info->invalidation_region = cairo_region_create ();
3344 _gtk_widget_get_translation_to_window (widget, info->window, &rel_x, &rel_y);
3346 for (i = 0; i < info->rectangles->len; i++)
3348 cairo_rectangle_int_t *rect;
3350 rect = &g_array_index (info->rectangles, cairo_rectangle_int_t, i);
3352 /* These are widget relative coordinates,
3353 * so have them inverted to be window relative
3358 cairo_region_union_rectangle (info->invalidation_region, rect);
3361 g_array_remove_range (info->rectangles, 0, info->rectangles->len);
3364 priv->animations_invalidated = FALSE;
3368 store_animation_region (GtkStyleContext *context,
3374 GtkStyleContextPrivate *priv;
3377 priv = context->priv;
3379 if (!priv->animations_invalidated)
3382 for (l = priv->animations; l; l = l->next)
3384 AnimationInfo *info;
3388 /* The animation doesn't need updating
3389 * the invalidation area, bail out.
3391 if (info->invalidation_region)
3394 if (context_has_animatable_region (context, info->region_id))
3396 cairo_rectangle_int_t rect;
3400 rect.width = (gint) width;
3401 rect.height = (gint) height;
3403 g_array_append_val (info->rectangles, rect);
3405 if (!info->parent_regions)
3407 GSList *parent_regions;
3409 parent_regions = g_slist_find (priv->animation_regions, info->region_id);
3410 info->parent_regions = g_slist_copy (parent_regions);
3417 * gtk_style_context_invalidate:
3418 * @context: a #GtkStyleContext.
3420 * Invalidates @context style information, so it will be reconstructed
3423 * If you're using a #GtkStyleContext returned from
3424 * gtk_widget_get_style_context(), you do not need to
3425 * call this yourself.
3430 gtk_style_context_invalidate (GtkStyleContext *context)
3432 GtkStyleContextPrivate *priv;
3434 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3436 priv = context->priv;
3438 /* Avoid reentrancy */
3439 if (priv->invalidating_context)
3442 priv->invalidating_context = TRUE;
3444 g_hash_table_remove_all (priv->style_data);
3445 priv->current_data = NULL;
3447 g_signal_emit (context, signals[CHANGED], 0);
3449 priv->invalidating_context = FALSE;
3453 * gtk_style_context_set_background:
3454 * @context: a #GtkStyleContext
3455 * @window: a #GdkWindow
3457 * Sets the background of @window to the background pattern or
3458 * color specified in @context for its current state.
3463 gtk_style_context_set_background (GtkStyleContext *context,
3466 GtkStateFlags state;
3467 cairo_pattern_t *pattern;
3470 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3471 g_return_if_fail (GDK_IS_WINDOW (window));
3473 state = gtk_style_context_get_state (context);
3474 gtk_style_context_get (context, state,
3475 "background-image", &pattern,
3479 gdk_window_set_background_pattern (window, pattern);
3480 cairo_pattern_destroy (pattern);
3484 gtk_style_context_get (context, state,
3485 "background-color", &color,
3489 gdk_window_set_background_rgba (window, color);
3490 gdk_rgba_free (color);
3495 * gtk_style_context_get_color:
3496 * @context: a #GtkStyleContext
3497 * @state: state to retrieve the color for
3498 * @color: (out): return value for the foreground color
3500 * Gets the foreground color for a given state.
3505 gtk_style_context_get_color (GtkStyleContext *context,
3506 GtkStateFlags state,
3511 g_return_if_fail (color != NULL);
3512 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3514 gtk_style_context_get (context,
3524 * gtk_style_context_get_background_color:
3525 * @context: a #GtkStyleContext
3526 * @state: state to retrieve the color for
3527 * @color: (out): return value for the background color
3529 * Gets the background color for a given state.
3534 gtk_style_context_get_background_color (GtkStyleContext *context,
3535 GtkStateFlags state,
3540 g_return_if_fail (color != NULL);
3541 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3543 gtk_style_context_get (context,
3545 "background-color", &c,
3553 * gtk_style_context_get_border_color:
3554 * @context: a #GtkStyleContext
3555 * @state: state to retrieve the color for
3556 * @color: (out): return value for the border color
3558 * Gets the border color for a given state.
3563 gtk_style_context_get_border_color (GtkStyleContext *context,
3564 GtkStateFlags state,
3569 g_return_if_fail (color != NULL);
3570 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3572 gtk_style_context_get (context,
3582 * gtk_style_context_get_border:
3583 * @context: a #GtkStyleContext
3584 * @state: state to retrieve the border for
3585 * @border: (out): return value for the border settings
3587 * Gets the border for a given state as a #GtkBorder.
3588 * See %GTK_STYLE_PROPERTY_BORDER_WIDTH.
3593 gtk_style_context_get_border (GtkStyleContext *context,
3594 GtkStateFlags state,
3597 int top, left, bottom, right;
3599 g_return_if_fail (border != NULL);
3600 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3602 gtk_style_context_get (context,
3604 "border-top-width", &top,
3605 "border-left-width", &left,
3606 "border-bottom-width", &bottom,
3607 "border-right-width", &right,
3611 border->left = left;
3612 border->bottom = bottom;
3613 border->right = right;
3617 * gtk_style_context_get_padding:
3618 * @context: a #GtkStyleContext
3619 * @state: state to retrieve the padding for
3620 * @padding: (out): return value for the padding settings
3622 * Gets the padding for a given state as a #GtkBorder.
3623 * See %GTK_STYLE_PROPERTY_PADDING.
3628 gtk_style_context_get_padding (GtkStyleContext *context,
3629 GtkStateFlags state,
3632 int top, left, bottom, right;
3634 g_return_if_fail (padding != NULL);
3635 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3637 gtk_style_context_get (context,
3639 "padding-top", &top,
3640 "padding-left", &left,
3641 "padding-bottom", &bottom,
3642 "padding-right", &right,
3646 padding->left = left;
3647 padding->bottom = bottom;
3648 padding->right = right;
3652 * gtk_style_context_get_margin:
3653 * @context: a #GtkStyleContext
3654 * @state: state to retrieve the border for
3655 * @margin: (out): return value for the margin settings
3657 * Gets the margin for a given state as a #GtkBorder.
3658 * See %GTK_STYLE_PROPERTY_MARGIN.
3663 gtk_style_context_get_margin (GtkStyleContext *context,
3664 GtkStateFlags state,
3667 int top, left, bottom, right;
3669 g_return_if_fail (margin != NULL);
3670 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3672 gtk_style_context_get (context,
3675 "margin-left", &left,
3676 "margin-bottom", &bottom,
3677 "margin-right", &right,
3681 margin->left = left;
3682 margin->bottom = bottom;
3683 margin->right = right;
3687 * gtk_style_context_get_font:
3688 * @context: a #GtkStyleContext
3689 * @state: state to retrieve the font for
3691 * Returns the font description for a given state. The returned
3692 * object is const and will remain valid until the
3693 * #GtkStyleContext::changed signal happens.
3695 * Returns: (transfer none): the #PangoFontDescription for the given
3696 * state. This object is owned by GTK+ and should not be
3701 const PangoFontDescription *
3702 gtk_style_context_get_font (GtkStyleContext *context,
3703 GtkStateFlags state)
3705 GtkStyleContextPrivate *priv;
3707 PangoFontDescription *description;
3709 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
3711 priv = context->priv;
3712 g_return_val_if_fail (priv->widget_path != NULL, NULL);
3714 data = style_data_lookup (context, state);
3716 /* Yuck, fonts are created on-demand but we don't return a ref.
3717 * Do bad things to achieve this requirement */
3718 description = g_object_get_data (G_OBJECT (data->store), "font-cache-for-get_font");
3719 if (description == NULL)
3721 gtk_style_context_get (context, state, "font", &description, NULL);
3722 g_object_set_data_full (G_OBJECT (data->store),
3723 "font-cache-for-get_font",
3725 (GDestroyNotify) pango_font_description_free);
3731 get_cursor_color (GtkStyleContext *context,
3735 GdkColor *style_color;
3737 gtk_style_context_get_style (context,
3738 primary ? "cursor-color" : "secondary-cursor-color",
3744 color->red = style_color->red / 65535.0;
3745 color->green = style_color->green / 65535.0;
3746 color->blue = style_color->blue / 65535.0;
3749 gdk_color_free (style_color);
3753 gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, color);
3759 gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &bg);
3761 color->red = (color->red + bg.red) * 0.5;
3762 color->green = (color->green + bg.green) * 0.5;
3763 color->blue = (color->blue + bg.blue) * 0.5;
3769 _gtk_style_context_get_cursor_color (GtkStyleContext *context,
3770 GdkRGBA *primary_color,
3771 GdkRGBA *secondary_color)
3774 get_cursor_color (context, TRUE, primary_color);
3776 if (secondary_color)
3777 get_cursor_color (context, FALSE, secondary_color);
3784 * @context: a #GtkStyleContext
3786 * @x: X origin of the rectangle
3787 * @y: Y origin of the rectangle
3788 * @width: rectangle width
3789 * @height: rectangle height
3791 * Renders a checkmark (as in a #GtkCheckButton).
3793 * The %GTK_STATE_FLAG_ACTIVE state determines whether the check is
3794 * on or off, and %GTK_STATE_FLAG_INCONSISTENT determines whether it
3795 * should be marked as undefined.
3798 * <title>Typical checkmark rendering</title>
3799 * <inlinegraphic fileref="checks.png" format="PNG"/>
3805 gtk_render_check (GtkStyleContext *context,
3812 GtkStyleContextPrivate *priv;
3813 GtkThemingEngineClass *engine_class;
3815 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3816 g_return_if_fail (cr != NULL);
3818 if (width <= 0 || height <= 0)
3821 priv = context->priv;
3822 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3826 store_animation_region (context, x, y, width, height);
3828 _gtk_theming_engine_set_context (priv->theming_engine, context);
3829 engine_class->render_check (priv->theming_engine, cr,
3830 x, y, width, height);
3836 * gtk_render_option:
3837 * @context: a #GtkStyleContext
3839 * @x: X origin of the rectangle
3840 * @y: Y origin of the rectangle
3841 * @width: rectangle width
3842 * @height: rectangle height
3844 * Renders an option mark (as in a #GtkRadioButton), the %GTK_STATE_FLAG_ACTIVE
3845 * state will determine whether the option is on or off, and
3846 * %GTK_STATE_FLAG_INCONSISTENT whether it should be marked as undefined.
3849 * <title>Typical option mark rendering</title>
3850 * <inlinegraphic fileref="options.png" format="PNG"/>
3856 gtk_render_option (GtkStyleContext *context,
3863 GtkStyleContextPrivate *priv;
3864 GtkThemingEngineClass *engine_class;
3866 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3867 g_return_if_fail (cr != NULL);
3869 if (width <= 0 || height <= 0)
3872 priv = context->priv;
3873 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3877 store_animation_region (context, x, y, width, height);
3879 _gtk_theming_engine_set_context (priv->theming_engine, context);
3880 engine_class->render_option (priv->theming_engine, cr,
3881 x, y, width, height);
3888 * @context: a #GtkStyleContext
3890 * @angle: arrow angle from 0 to 2 * %G_PI, being 0 the arrow pointing to the north
3891 * @x: X origin of the render area
3892 * @y: Y origin of the render area
3893 * @size: square side for render area
3895 * Renders an arrow pointing to @angle.
3898 * <title>Typical arrow rendering at 0, 1&solidus;2 π, π and 3&solidus;2 π</title>
3899 * <inlinegraphic fileref="arrows.png" format="PNG"/>
3905 gtk_render_arrow (GtkStyleContext *context,
3912 GtkStyleContextPrivate *priv;
3913 GtkThemingEngineClass *engine_class;
3915 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3916 g_return_if_fail (cr != NULL);
3921 priv = context->priv;
3922 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3926 gtk_style_context_save (context);
3927 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ARROW);
3929 store_animation_region (context, x, y, size, size);
3931 _gtk_theming_engine_set_context (priv->theming_engine, context);
3932 engine_class->render_arrow (priv->theming_engine, cr,
3935 gtk_style_context_restore (context);
3940 * gtk_render_background:
3941 * @context: a #GtkStyleContext
3943 * @x: X origin of the rectangle
3944 * @y: Y origin of the rectangle
3945 * @width: rectangle width
3946 * @height: rectangle height
3948 * Renders the background of an element.
3951 * <title>Typical background rendering, showing the effect of
3952 * <parameter>background-image</parameter>,
3953 * <parameter>border-width</parameter> and
3954 * <parameter>border-radius</parameter></title>
3955 * <inlinegraphic fileref="background.png" format="PNG"/>
3961 gtk_render_background (GtkStyleContext *context,
3968 GtkStyleContextPrivate *priv;
3969 GtkThemingEngineClass *engine_class;
3971 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3972 g_return_if_fail (cr != NULL);
3974 if (width <= 0 || height <= 0)
3977 priv = context->priv;
3978 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3982 store_animation_region (context, x, y, width, height);
3984 _gtk_theming_engine_set_context (priv->theming_engine, context);
3985 engine_class->render_background (priv->theming_engine, cr, x, y, width, height);
3992 * @context: a #GtkStyleContext
3994 * @x: X origin of the rectangle
3995 * @y: Y origin of the rectangle
3996 * @width: rectangle width
3997 * @height: rectangle height
3999 * Renders a frame around the rectangle defined by @x, @y, @width, @height.
4002 * <title>Examples of frame rendering, showing the effect of
4003 * <parameter>border-image</parameter>,
4004 * <parameter>border-color</parameter>,
4005 * <parameter>border-width</parameter>,
4006 * <parameter>border-radius</parameter> and
4008 * <inlinegraphic fileref="frames.png" format="PNG"/>
4014 gtk_render_frame (GtkStyleContext *context,
4021 GtkStyleContextPrivate *priv;
4022 GtkThemingEngineClass *engine_class;
4024 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4025 g_return_if_fail (cr != NULL);
4027 if (width <= 0 || height <= 0)
4030 priv = context->priv;
4031 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4035 store_animation_region (context, x, y, width, height);
4037 _gtk_theming_engine_set_context (priv->theming_engine, context);
4038 engine_class->render_frame (priv->theming_engine, cr, x, y, width, height);
4044 * gtk_render_expander:
4045 * @context: a #GtkStyleContext
4047 * @x: X origin of the rectangle
4048 * @y: Y origin of the rectangle
4049 * @width: rectangle width
4050 * @height: rectangle height
4052 * Renders an expander (as used in #GtkTreeView and #GtkExpander) in the area
4053 * defined by @x, @y, @width, @height. The state %GTK_STATE_FLAG_ACTIVE
4054 * determines whether the expander is collapsed or expanded.
4057 * <title>Typical expander rendering</title>
4058 * <inlinegraphic fileref="expanders.png" format="PNG"/>
4064 gtk_render_expander (GtkStyleContext *context,
4071 GtkStyleContextPrivate *priv;
4072 GtkThemingEngineClass *engine_class;
4074 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4075 g_return_if_fail (cr != NULL);
4077 if (width <= 0 || height <= 0)
4080 priv = context->priv;
4081 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4085 store_animation_region (context, x, y, width, height);
4087 _gtk_theming_engine_set_context (priv->theming_engine, context);
4088 engine_class->render_expander (priv->theming_engine, cr, x, y, width, height);
4095 * @context: a #GtkStyleContext
4097 * @x: X origin of the rectangle
4098 * @y: Y origin of the rectangle
4099 * @width: rectangle width
4100 * @height: rectangle height
4102 * Renders a focus indicator on the rectangle determined by @x, @y, @width, @height.
4104 * <title>Typical focus rendering</title>
4105 * <inlinegraphic fileref="focus.png" format="PNG"/>
4111 gtk_render_focus (GtkStyleContext *context,
4118 GtkStyleContextPrivate *priv;
4119 GtkThemingEngineClass *engine_class;
4121 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4122 g_return_if_fail (cr != NULL);
4124 if (width <= 0 || height <= 0)
4127 priv = context->priv;
4128 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4132 store_animation_region (context, x, y, width, height);
4134 _gtk_theming_engine_set_context (priv->theming_engine, context);
4135 engine_class->render_focus (priv->theming_engine, cr, x, y, width, height);
4141 * gtk_render_layout:
4142 * @context: a #GtkStyleContext
4146 * @layout: the #PangoLayout to render
4148 * Renders @layout on the coordinates @x, @y
4153 gtk_render_layout (GtkStyleContext *context,
4157 PangoLayout *layout)
4159 GtkStyleContextPrivate *priv;
4160 GtkThemingEngineClass *engine_class;
4161 PangoRectangle extents;
4163 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4164 g_return_if_fail (PANGO_IS_LAYOUT (layout));
4165 g_return_if_fail (cr != NULL);
4167 priv = context->priv;
4168 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4172 pango_layout_get_extents (layout, &extents, NULL);
4174 store_animation_region (context,
4180 _gtk_theming_engine_set_context (priv->theming_engine, context);
4181 engine_class->render_layout (priv->theming_engine, cr, x, y, layout);
4188 * @context: a #GtkStyleContext
4190 * @x0: X coordinate for the origin of the line
4191 * @y0: Y coordinate for the origin of the line
4192 * @x1: X coordinate for the end of the line
4193 * @y1: Y coordinate for the end of the line
4195 * Renders a line from (x0, y0) to (x1, y1).
4200 gtk_render_line (GtkStyleContext *context,
4207 GtkStyleContextPrivate *priv;
4208 GtkThemingEngineClass *engine_class;
4210 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4211 g_return_if_fail (cr != NULL);
4213 priv = context->priv;
4214 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4218 _gtk_theming_engine_set_context (priv->theming_engine, context);
4219 engine_class->render_line (priv->theming_engine, cr, x0, y0, x1, y1);
4225 * gtk_render_slider:
4226 * @context: a #GtkStyleContext
4228 * @x: X origin of the rectangle
4229 * @y: Y origin of the rectangle
4230 * @width: rectangle width
4231 * @height: rectangle height
4232 * @orientation: orientation of the slider
4234 * Renders a slider (as in #GtkScale) in the rectangle defined by @x, @y,
4235 * @width, @height. @orientation defines whether the slider is vertical
4239 * <title>Typical slider rendering</title>
4240 * <inlinegraphic fileref="sliders.png" format="PNG"/>
4246 gtk_render_slider (GtkStyleContext *context,
4252 GtkOrientation orientation)
4254 GtkStyleContextPrivate *priv;
4255 GtkThemingEngineClass *engine_class;
4257 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4258 g_return_if_fail (cr != NULL);
4260 if (width <= 0 || height <= 0)
4263 priv = context->priv;
4264 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4268 store_animation_region (context, x, y, width, height);
4270 _gtk_theming_engine_set_context (priv->theming_engine, context);
4271 engine_class->render_slider (priv->theming_engine, cr, x, y, width, height, orientation);
4277 * gtk_render_frame_gap:
4278 * @context: a #GtkStyleContext
4280 * @x: X origin of the rectangle
4281 * @y: Y origin of the rectangle
4282 * @width: rectangle width
4283 * @height: rectangle height
4284 * @gap_side: side where the gap is
4285 * @xy0_gap: initial coordinate (X or Y depending on @gap_side) for the gap
4286 * @xy1_gap: end coordinate (X or Y depending on @gap_side) for the gap
4288 * Renders a frame around the rectangle defined by (@x, @y, @width, @height),
4289 * leaving a gap on one side. @xy0_gap and @xy1_gap will mean X coordinates
4290 * for %GTK_POS_TOP and %GTK_POS_BOTTOM gap sides, and Y coordinates for
4291 * %GTK_POS_LEFT and %GTK_POS_RIGHT.
4294 * <title>Typical rendering of a frame with a gap</title>
4295 * <inlinegraphic fileref="frame-gap.png" format="PNG"/>
4301 gtk_render_frame_gap (GtkStyleContext *context,
4307 GtkPositionType gap_side,
4311 GtkStyleContextPrivate *priv;
4312 GtkThemingEngineClass *engine_class;
4314 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4315 g_return_if_fail (cr != NULL);
4316 g_return_if_fail (xy0_gap <= xy1_gap);
4317 g_return_if_fail (xy0_gap >= 0);
4319 if (width <= 0 || height <= 0)
4322 if (gap_side == GTK_POS_LEFT ||
4323 gap_side == GTK_POS_RIGHT)
4324 g_return_if_fail (xy1_gap <= height);
4326 g_return_if_fail (xy1_gap <= width);
4328 priv = context->priv;
4329 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4333 store_animation_region (context, x, y, width, height);
4335 _gtk_theming_engine_set_context (priv->theming_engine, context);
4336 engine_class->render_frame_gap (priv->theming_engine, cr,
4337 x, y, width, height, gap_side,
4344 * gtk_render_extension:
4345 * @context: a #GtkStyleContext
4347 * @x: X origin of the rectangle
4348 * @y: Y origin of the rectangle
4349 * @width: rectangle width
4350 * @height: rectangle height
4351 * @gap_side: side where the gap is
4353 * Renders a extension (as in a #GtkNotebook tab) in the rectangle
4354 * defined by @x, @y, @width, @height. The side where the extension
4355 * connects to is defined by @gap_side.
4358 * <title>Typical extension rendering</title>
4359 * <inlinegraphic fileref="extensions.png" format="PNG"/>
4365 gtk_render_extension (GtkStyleContext *context,
4371 GtkPositionType gap_side)
4373 GtkStyleContextPrivate *priv;
4374 GtkThemingEngineClass *engine_class;
4376 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4377 g_return_if_fail (cr != NULL);
4379 if (width <= 0 || height <= 0)
4382 priv = context->priv;
4383 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4387 store_animation_region (context, x, y, width, height);
4389 _gtk_theming_engine_set_context (priv->theming_engine, context);
4390 engine_class->render_extension (priv->theming_engine, cr, x, y, width, height, gap_side);
4396 * gtk_render_handle:
4397 * @context: a #GtkStyleContext
4399 * @x: X origin of the rectangle
4400 * @y: Y origin of the rectangle
4401 * @width: rectangle width
4402 * @height: rectangle height
4404 * Renders a handle (as in #GtkHandleBox, #GtkPaned and
4405 * #GtkWindow<!-- -->'s resize grip), in the rectangle
4406 * determined by @x, @y, @width, @height.
4409 * <title>Handles rendered for the paned and grip classes</title>
4410 * <inlinegraphic fileref="handles.png" format="PNG"/>
4416 gtk_render_handle (GtkStyleContext *context,
4423 GtkStyleContextPrivate *priv;
4424 GtkThemingEngineClass *engine_class;
4426 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4427 g_return_if_fail (cr != NULL);
4429 if (width <= 0 || height <= 0)
4432 priv = context->priv;
4433 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4437 store_animation_region (context, x, y, width, height);
4439 _gtk_theming_engine_set_context (priv->theming_engine, context);
4440 engine_class->render_handle (priv->theming_engine, cr, x, y, width, height);
4446 * gtk_render_activity:
4447 * @context: a #GtkStyleContext
4449 * @x: X origin of the rectangle
4450 * @y: Y origin of the rectangle
4451 * @width: rectangle width
4452 * @height: rectangle height
4454 * Renders an activity area (Such as in #GtkSpinner or the
4455 * fill line in #GtkRange), the state %GTK_STATE_FLAG_ACTIVE
4456 * determines whether there is activity going on.
4461 gtk_render_activity (GtkStyleContext *context,
4468 GtkStyleContextPrivate *priv;
4469 GtkThemingEngineClass *engine_class;
4471 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4472 g_return_if_fail (cr != NULL);
4474 if (width <= 0 || height <= 0)
4477 priv = context->priv;
4478 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4482 store_animation_region (context, x, y, width, height);
4484 _gtk_theming_engine_set_context (priv->theming_engine, context);
4485 engine_class->render_activity (priv->theming_engine, cr, x, y, width, height);
4491 * gtk_render_icon_pixbuf:
4492 * @context: a #GtkStyleContext
4493 * @source: the #GtkIconSource specifying the icon to render
4494 * @size: (type int): the size to render the icon at. A size of (GtkIconSize) -1
4495 * means render at the size of the source and don't scale.
4497 * Renders the icon specified by @source at the given @size, returning the result
4500 * Returns: (transfer full): a newly-created #GdkPixbuf containing the rendered icon
4505 gtk_render_icon_pixbuf (GtkStyleContext *context,
4506 const GtkIconSource *source,
4509 GtkStyleContextPrivate *priv;
4510 GtkThemingEngineClass *engine_class;
4512 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
4513 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
4514 g_return_val_if_fail (source != NULL, NULL);
4516 priv = context->priv;
4517 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4519 _gtk_theming_engine_set_context (priv->theming_engine, context);
4520 return engine_class->render_icon_pixbuf (priv->theming_engine, source, size);
4525 * @context: a #GtkStyleContext
4527 * @pixbuf: a #GdkPixbuf containing the icon to draw
4528 * @x: X position for the @pixbuf
4529 * @y: Y position for the @pixbuf
4531 * Renders the icon in @pixbuf at the specified @x and @y coordinates.
4536 gtk_render_icon (GtkStyleContext *context,
4542 GtkStyleContextPrivate *priv;
4543 GtkThemingEngineClass *engine_class;
4545 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4546 g_return_if_fail (cr != NULL);
4548 priv = context->priv;
4549 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4553 store_animation_region (context,
4555 gdk_pixbuf_get_width (pixbuf),
4556 gdk_pixbuf_get_height (pixbuf));
4558 _gtk_theming_engine_set_context (priv->theming_engine, context);
4559 engine_class->render_icon (priv->theming_engine, cr, pixbuf, x, y);
4565 draw_insertion_cursor (GtkStyleContext *context,
4570 gboolean is_primary,
4571 PangoDirection direction,
4572 gboolean draw_arrow)
4575 GdkRGBA primary_color;
4576 GdkRGBA secondary_color;
4577 gfloat cursor_aspect_ratio;
4583 _gtk_style_context_get_cursor_color (context, &primary_color, &secondary_color);
4584 gdk_cairo_set_source_rgba (cr, is_primary ? &primary_color : &secondary_color);
4586 /* When changing the shape or size of the cursor here,
4587 * propagate the changes to gtktextview.c:text_window_invalidate_cursors().
4590 gtk_style_context_get_style (context,
4591 "cursor-aspect-ratio", &cursor_aspect_ratio,
4594 stem_width = height * cursor_aspect_ratio + 1;
4596 /* put (stem_width % 2) on the proper side of the cursor */
4597 if (direction == PANGO_DIRECTION_LTR)
4598 offset = stem_width / 2;
4600 offset = stem_width - stem_width / 2;
4602 cairo_rectangle (cr, x - offset, y, stem_width, height);
4610 arrow_width = stem_width + 1;
4612 if (direction == PANGO_DIRECTION_RTL)
4614 ax = x - offset - 1;
4615 ay = y + height - arrow_width * 2 - arrow_width + 1;
4617 cairo_move_to (cr, ax, ay + 1);
4618 cairo_line_to (cr, ax - arrow_width, ay + arrow_width);
4619 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4622 else if (direction == PANGO_DIRECTION_LTR)
4624 ax = x + stem_width - offset;
4625 ay = y + height - arrow_width * 2 - arrow_width + 1;
4627 cairo_move_to (cr, ax, ay + 1);
4628 cairo_line_to (cr, ax + arrow_width, ay + arrow_width);
4629 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4633 g_assert_not_reached();
4640 * gtk_render_insertion_cursor:
4641 * @context: a #GtkStyleContext
4645 * @layout: the #PangoLayout of the text
4646 * @index: the index in the #PangoLayout
4647 * @direction: the #PangoDirection of the text
4649 * Draws a text caret on @cr at the specified index of @layout.
4654 gtk_render_insertion_cursor (GtkStyleContext *context,
4658 PangoLayout *layout,
4660 PangoDirection direction)
4662 GtkStyleContextPrivate *priv;
4663 gboolean split_cursor;
4664 PangoRectangle strong_pos, weak_pos;
4665 PangoRectangle *cursor1, *cursor2;
4666 PangoDirection keymap_direction;
4667 PangoDirection direction2;
4669 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4670 g_return_if_fail (cr != NULL);
4671 g_return_if_fail (PANGO_IS_LAYOUT (layout));
4672 g_return_if_fail (index >= 0);
4674 priv = context->priv;
4676 g_object_get (gtk_settings_get_for_screen (priv->screen),
4677 "gtk-split-cursor", &split_cursor,
4680 keymap_direction = gdk_keymap_get_direction (gdk_keymap_get_for_display (gdk_screen_get_display (priv->screen)));
4682 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4684 direction2 = PANGO_DIRECTION_NEUTRAL;
4688 cursor1 = &strong_pos;
4690 if (strong_pos.x != weak_pos.x || strong_pos.y != weak_pos.y)
4692 direction2 = (direction == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
4693 cursor2 = &weak_pos;
4698 if (keymap_direction == direction)
4699 cursor1 = &strong_pos;
4701 cursor1 = &weak_pos;
4704 draw_insertion_cursor (context,
4706 x + PANGO_PIXELS (cursor1->x),
4707 y + PANGO_PIXELS (cursor1->y),
4708 PANGO_PIXELS (cursor1->height),
4711 direction2 != PANGO_DIRECTION_NEUTRAL);
4713 if (direction2 != PANGO_DIRECTION_NEUTRAL)
4715 draw_insertion_cursor (context,
4717 x + PANGO_PIXELS (cursor2->x),
4718 y + PANGO_PIXELS (cursor2->y),
4719 PANGO_PIXELS (cursor2->height),
4727 * gtk_draw_insertion_cursor:
4728 * @widget: a #GtkWidget
4729 * @cr: cairo context to draw to
4730 * @location: location where to draw the cursor (@location->width is ignored)
4731 * @is_primary: if the cursor should be the primary cursor color.
4732 * @direction: whether the cursor is left-to-right or
4733 * right-to-left. Should never be #GTK_TEXT_DIR_NONE
4734 * @draw_arrow: %TRUE to draw a directional arrow on the
4735 * cursor. Should be %FALSE unless the cursor is split.
4737 * Draws a text caret on @cr at @location. This is not a style function
4738 * but merely a convenience function for drawing the standard cursor shape.
4743 gtk_draw_insertion_cursor (GtkWidget *widget,
4745 const GdkRectangle *location,
4746 gboolean is_primary,
4747 GtkTextDirection direction,
4748 gboolean draw_arrow)
4750 GtkStyleContext *context;
4752 g_return_if_fail (GTK_IS_WIDGET (widget));
4753 g_return_if_fail (cr != NULL);
4754 g_return_if_fail (location != NULL);
4755 g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
4757 context = gtk_widget_get_style_context (widget);
4759 draw_insertion_cursor (context, cr,
4760 location->x, location->y, location->height,
4762 (direction == GTK_TEXT_DIR_RTL) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR,
4766 static AtkAttributeSet *
4767 add_attribute (AtkAttributeSet *attributes,
4768 AtkTextAttribute attr,
4773 at = g_new (AtkAttribute, 1);
4774 at->name = g_strdup (atk_text_attribute_get_name (attr));
4775 at->value = g_strdup (value);
4777 return g_slist_prepend (attributes, at);
4781 * _gtk_style_context_get_attributes:
4782 * @attributes: a #AtkAttributeSet to add attributes to
4783 * @context: the #GtkStyleContext to get attributes from
4784 * @flags: the state to use with @context
4786 * Adds the foreground and background color from @context to
4787 * @attributes, after translating them to ATK attributes.
4789 * This is a convenience function that can be used in
4790 * implementing the #AtkText interface in widgets.
4792 * Returns: the modified #AtkAttributeSet
4795 _gtk_style_context_get_attributes (AtkAttributeSet *attributes,
4796 GtkStyleContext *context,
4797 GtkStateFlags flags)
4802 gtk_style_context_get_background_color (context, flags, &color);
4803 value = g_strdup_printf ("%u,%u,%u",
4804 (guint) ceil (color.red * 65536 - color.red),
4805 (guint) ceil (color.green * 65536 - color.green),
4806 (guint) ceil (color.blue * 65536 - color.blue));
4807 attributes = add_attribute (attributes, ATK_TEXT_ATTR_BG_COLOR, value);
4810 gtk_style_context_get_color (context, flags, &color);
4811 value = g_strdup_printf ("%u,%u,%u",
4812 (guint) ceil (color.red * 65536 - color.red),
4813 (guint) ceil (color.green * 65536 - color.green),
4814 (guint) ceil (color.blue * 65536 - color.blue));
4815 attributes = add_attribute (attributes, ATK_TEXT_ATTR_FG_COLOR, value);