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 GtkStyleProperties *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_style_properties_new ();
991 _gtk_style_properties_set_color_lookup_func (style_data->store,
992 gtk_style_context_color_lookup_func,
994 _gtk_css_lookup_resolve (lookup, context, style_data->store);
995 _gtk_css_lookup_free (lookup);
999 build_icon_factories (GtkStyleContext *context,
1000 StyleData *style_data,
1001 GtkWidgetPath *path)
1003 GtkStyleContextPrivate *priv;
1004 GList *elem, *list, *global_list = NULL;
1006 priv = context->priv;
1007 list = priv->providers_last;
1011 global_list = g_object_get_qdata (G_OBJECT (priv->screen), provider_list_quark);
1012 global_list = g_list_last (global_list);
1015 while ((elem = find_next_candidate (list, global_list, FALSE)) != NULL)
1017 GtkIconFactory *factory;
1018 GtkStyleProviderData *data;
1025 global_list = global_list->prev;
1027 factory = gtk_style_provider_get_icon_factory (data->provider, path);
1030 style_data->icon_factories = g_slist_prepend (style_data->icon_factories, factory);
1034 static GtkWidgetPath *
1035 create_query_path (GtkStyleContext *context)
1037 GtkStyleContextPrivate *priv;
1038 GtkWidgetPath *path;
1042 priv = context->priv;
1043 path = gtk_widget_path_copy (priv->widget_path);
1044 pos = gtk_widget_path_length (path) - 1;
1046 info = priv->info_stack->data;
1048 /* Set widget regions */
1049 for (i = 0; i < info->regions->len; i++)
1053 region = &g_array_index (info->regions, GtkRegion, i);
1054 gtk_widget_path_iter_add_region (path, pos,
1055 g_quark_to_string (region->class_quark),
1059 /* Set widget classes */
1060 for (i = 0; i < info->style_classes->len; i++)
1064 quark = g_array_index (info->style_classes, GQuark, i);
1065 gtk_widget_path_iter_add_class (path, pos,
1066 g_quark_to_string (quark));
1073 style_data_lookup (GtkStyleContext *context,
1074 GtkStateFlags state)
1076 GtkStyleContextPrivate *priv;
1078 gboolean state_mismatch;
1080 priv = context->priv;
1081 state_mismatch = ((GtkStyleInfo *) priv->info_stack->data)->state_flags != state;
1083 /* Current data in use is cached, just return it */
1084 if (priv->current_data && priv->current_state == state)
1085 return priv->current_data;
1087 g_assert (priv->widget_path != NULL);
1089 if (G_UNLIKELY (state_mismatch))
1091 gtk_style_context_save (context);
1092 gtk_style_context_set_state (context, state);
1095 priv->current_data = g_hash_table_lookup (priv->style_data, priv->info_stack->data);
1096 priv->current_state = state;
1098 if (!priv->current_data)
1100 GtkWidgetPath *path;
1102 priv->current_data = style_data_new ();
1103 g_hash_table_insert (priv->style_data,
1104 style_info_copy (priv->info_stack->data),
1105 priv->current_data);
1107 path = create_query_path (context);
1109 build_properties (context, priv->current_data, path, state);
1110 build_icon_factories (context, priv->current_data, path);
1112 gtk_widget_path_free (path);
1115 data = priv->current_data;
1117 if (priv->theming_engine)
1118 g_object_unref (priv->theming_engine);
1120 gtk_style_properties_get (priv->current_data->store, 0,
1121 "engine", &priv->theming_engine,
1124 if (!priv->theming_engine)
1125 priv->theming_engine = g_object_ref (gtk_theming_engine_load (NULL));
1127 if (G_UNLIKELY (state_mismatch))
1128 gtk_style_context_restore (context);
1134 style_provider_add (GList **list,
1135 GtkStyleProvider *provider,
1138 GtkStyleProviderData *new_data;
1139 gboolean added = FALSE;
1142 new_data = style_provider_data_new (provider, priority);
1146 GtkStyleProviderData *data;
1150 /* Provider was already attached to the style
1151 * context, remove in order to add the new data
1153 if (data->provider == provider)
1160 /* Remove and free link */
1161 *list = g_list_remove_link (*list, link);
1162 style_provider_data_free (link->data);
1163 g_list_free_1 (link);
1169 data->priority > priority)
1171 *list = g_list_insert_before (*list, l, new_data);
1179 *list = g_list_append (*list, new_data);
1183 style_provider_remove (GList **list,
1184 GtkStyleProvider *provider)
1190 GtkStyleProviderData *data;
1194 if (data->provider == provider)
1196 *list = g_list_remove_link (*list, l);
1197 style_provider_data_free (l->data);
1210 * gtk_style_context_new:
1212 * Creates a standalone #GtkStyleContext, this style context
1213 * won't be attached to any widget, so you may want
1214 * to call gtk_style_context_set_path() yourself.
1217 * This function is only useful when using the theming layer
1218 * separated from GTK+, if you are using #GtkStyleContext to
1219 * theme #GtkWidget<!-- -->s, use gtk_widget_get_style_context()
1220 * in order to get a style context ready to theme the widget.
1223 * Returns: A newly created #GtkStyleContext.
1226 gtk_style_context_new (void)
1228 return g_object_new (GTK_TYPE_STYLE_CONTEXT, NULL);
1232 * gtk_style_context_add_provider:
1233 * @context: a #GtkStyleContext
1234 * @provider: a #GtkStyleProvider
1235 * @priority: the priority of the style provider. The lower
1236 * it is, the earlier it will be used in the style
1237 * construction. Typically this will be in the range
1238 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1239 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1241 * Adds a style provider to @context, to be used in style construction.
1243 * <note><para>If both priorities are the same, A #GtkStyleProvider
1244 * added through this function takes precedence over another added
1245 * through gtk_style_context_add_provider_for_screen().</para></note>
1250 gtk_style_context_add_provider (GtkStyleContext *context,
1251 GtkStyleProvider *provider,
1254 GtkStyleContextPrivate *priv;
1256 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1257 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1259 priv = context->priv;
1260 style_provider_add (&priv->providers, provider, priority);
1261 priv->providers_last = g_list_last (priv->providers);
1263 gtk_style_context_invalidate (context);
1267 * gtk_style_context_remove_provider:
1268 * @context: a #GtkStyleContext
1269 * @provider: a #GtkStyleProvider
1271 * Removes @provider from the style providers list in @context.
1276 gtk_style_context_remove_provider (GtkStyleContext *context,
1277 GtkStyleProvider *provider)
1279 GtkStyleContextPrivate *priv;
1281 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1282 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1284 priv = context->priv;
1286 if (style_provider_remove (&priv->providers, provider))
1288 priv->providers_last = g_list_last (priv->providers);
1290 gtk_style_context_invalidate (context);
1295 * gtk_style_context_reset_widgets:
1296 * @screen: a #GdkScreen
1298 * This function recomputes the styles for all widgets under a particular
1299 * #GdkScreen. This is useful when some global parameter has changed that
1300 * affects the appearance of all widgets, because when a widget gets a new
1301 * style, it will both redraw and recompute any cached information about
1302 * its appearance. As an example, it is used when the color scheme changes
1303 * in the related #GtkSettings object.
1308 gtk_style_context_reset_widgets (GdkScreen *screen)
1310 GList *list, *toplevels;
1312 _gtk_icon_set_invalidate_caches ();
1314 toplevels = gtk_window_list_toplevels ();
1315 g_list_foreach (toplevels, (GFunc) g_object_ref, NULL);
1317 for (list = toplevels; list; list = list->next)
1319 if (gtk_widget_get_screen (list->data) == screen)
1320 gtk_widget_reset_style (list->data);
1322 g_object_unref (list->data);
1325 g_list_free (toplevels);
1329 * gtk_style_context_add_provider_for_screen:
1330 * @screen: a #GdkScreen
1331 * @provider: a #GtkStyleProvider
1332 * @priority: the priority of the style provider. The lower
1333 * it is, the earlier it will be used in the style
1334 * construction. Typically this will be in the range
1335 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1336 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1338 * Adds a global style provider to @screen, which will be used
1339 * in style construction for all #GtkStyleContext<!-- -->s under
1342 * GTK+ uses this to make styling information from #GtkSettings
1345 * <note><para>If both priorities are the same, A #GtkStyleProvider
1346 * added through gtk_style_context_add_provider() takes precedence
1347 * over another added through this function.</para></note>
1352 gtk_style_context_add_provider_for_screen (GdkScreen *screen,
1353 GtkStyleProvider *provider,
1356 GList *providers, *list;
1358 g_return_if_fail (GDK_IS_SCREEN (screen));
1359 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1361 if (G_UNLIKELY (!provider_list_quark))
1362 provider_list_quark = g_quark_from_static_string ("gtk-provider-list-quark");
1364 list = providers = g_object_get_qdata (G_OBJECT (screen), provider_list_quark);
1365 style_provider_add (&list, provider, priority);
1367 if (list != providers)
1368 g_object_set_qdata (G_OBJECT (screen), provider_list_quark, list);
1370 gtk_style_context_reset_widgets (screen);
1374 * gtk_style_context_remove_provider_for_screen:
1375 * @screen: a #GdkScreen
1376 * @provider: a #GtkStyleProvider
1378 * Removes @provider from the global style providers list in @screen.
1383 gtk_style_context_remove_provider_for_screen (GdkScreen *screen,
1384 GtkStyleProvider *provider)
1386 GList *providers, *list;
1388 g_return_if_fail (GDK_IS_SCREEN (screen));
1389 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1391 if (G_UNLIKELY (!provider_list_quark))
1394 list = providers = g_object_get_qdata (G_OBJECT (screen), provider_list_quark);
1396 if (style_provider_remove (&list, provider))
1398 if (list != providers)
1399 g_object_set_qdata (G_OBJECT (screen), provider_list_quark, list);
1401 gtk_style_context_reset_widgets (screen);
1406 * gtk_style_context_get_property:
1407 * @context: a #GtkStyleContext
1408 * @property: style property name
1409 * @state: state to retrieve the property value for
1410 * @value: (out) (transfer full): return location for the style property value
1412 * Gets a style property from @context for the given state.
1414 * When @value is no longer needed, g_value_unset() must be called
1415 * to free any allocated memory.
1420 gtk_style_context_get_property (GtkStyleContext *context,
1421 const gchar *property,
1422 GtkStateFlags state,
1425 GtkStyleContextPrivate *priv;
1428 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1429 g_return_if_fail (property != NULL);
1430 g_return_if_fail (value != NULL);
1432 priv = context->priv;
1434 g_return_if_fail (priv->widget_path != NULL);
1436 data = style_data_lookup (context, state);
1437 gtk_style_properties_get_property (data->store, property, 0, value);
1441 * gtk_style_context_get_valist:
1442 * @context: a #GtkStyleContext
1443 * @state: state to retrieve the property values for
1444 * @args: va_list of property name/return location pairs, followed by %NULL
1446 * Retrieves several style property values from @context for a given state.
1451 gtk_style_context_get_valist (GtkStyleContext *context,
1452 GtkStateFlags state,
1455 GtkStyleContextPrivate *priv;
1458 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1460 priv = context->priv;
1461 g_return_if_fail (priv->widget_path != NULL);
1463 data = style_data_lookup (context, state);
1464 gtk_style_properties_get_valist (data->store, 0, args);
1468 * gtk_style_context_get:
1469 * @context: a #GtkStyleContext
1470 * @state: state to retrieve the property values for
1471 * @...: property name /return value pairs, followed by %NULL
1473 * Retrieves several style property values from @context for a
1479 gtk_style_context_get (GtkStyleContext *context,
1480 GtkStateFlags state,
1483 GtkStyleContextPrivate *priv;
1487 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1489 priv = context->priv;
1490 g_return_if_fail (priv->widget_path != NULL);
1492 data = style_data_lookup (context, state);
1494 va_start (args, state);
1495 gtk_style_properties_get_valist (data->store, 0, args);
1500 * gtk_style_context_set_state:
1501 * @context: a #GtkStyleContext
1502 * @flags: state to represent
1504 * Sets the state to be used when rendering with any
1505 * of the gtk_render_*() functions.
1510 gtk_style_context_set_state (GtkStyleContext *context,
1511 GtkStateFlags flags)
1513 GtkStyleContextPrivate *priv;
1516 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1518 priv = context->priv;
1519 info = priv->info_stack->data;
1520 info->state_flags = flags;
1524 * gtk_style_context_get_state:
1525 * @context: a #GtkStyleContext
1527 * Returns the state used when rendering.
1529 * Returns: the state flags
1534 gtk_style_context_get_state (GtkStyleContext *context)
1536 GtkStyleContextPrivate *priv;
1539 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
1541 priv = context->priv;
1542 info = priv->info_stack->data;
1544 return info->state_flags;
1548 context_has_animatable_region (GtkStyleContext *context,
1551 GtkStyleContextPrivate *priv;
1553 /* NULL region_id means everything
1554 * rendered through the style context
1559 priv = context->priv;
1560 return g_slist_find (priv->animation_regions, region_id) != NULL;
1564 * gtk_style_context_state_is_running:
1565 * @context: a #GtkStyleContext
1566 * @state: a widget state
1567 * @progress: (out): return location for the transition progress
1569 * Returns %TRUE if there is a transition animation running for the
1570 * current region (see gtk_style_context_push_animatable_region()).
1572 * If @progress is not %NULL, the animation progress will be returned
1573 * there, 0.0 means the state is closest to being unset, while 1.0 means
1574 * it's closest to being set. This means transition animation will
1575 * run from 0 to 1 when @state is being set and from 1 to 0 when
1578 * Returns: %TRUE if there is a running transition animation for @state.
1583 gtk_style_context_state_is_running (GtkStyleContext *context,
1587 GtkStyleContextPrivate *priv;
1588 AnimationInfo *info;
1591 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1593 priv = context->priv;
1595 for (l = priv->animations; l; l = l->next)
1599 if (info->state == state &&
1600 context_has_animatable_region (context, info->region_id))
1603 *progress = _gtk_timeline_get_progress (info->timeline);
1613 * gtk_style_context_set_path:
1614 * @context: a #GtkStyleContext
1615 * @path: a #GtkWidgetPath
1617 * Sets the #GtkWidgetPath used for style matching. As a
1618 * consequence, the style will be regenerated to match
1619 * the new given path.
1621 * If you are using a #GtkStyleContext returned from
1622 * gtk_widget_get_style_context(), you do not need to call
1628 gtk_style_context_set_path (GtkStyleContext *context,
1629 GtkWidgetPath *path)
1631 GtkStyleContextPrivate *priv;
1633 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1634 g_return_if_fail (path != NULL);
1636 priv = context->priv;
1638 if (priv->widget_path)
1640 gtk_widget_path_free (priv->widget_path);
1641 priv->widget_path = NULL;
1645 priv->widget_path = gtk_widget_path_copy (path);
1647 gtk_style_context_invalidate (context);
1651 * gtk_style_context_get_path:
1652 * @context: a #GtkStyleContext
1654 * Returns the widget path used for style matching.
1656 * Returns: (transfer none): A #GtkWidgetPath
1660 const GtkWidgetPath *
1661 gtk_style_context_get_path (GtkStyleContext *context)
1663 GtkStyleContextPrivate *priv;
1665 priv = context->priv;
1666 return priv->widget_path;
1670 * gtk_style_context_set_parent:
1671 * @context: a #GtkStyleContext
1672 * @parent: (allow-none): the new parent or %NULL
1674 * Sets the parent style context for @context. The parent style
1675 * context is used to implement
1676 * <ulink url="http://www.w3.org/TR/css3-cascade/#inheritance">inheritance</ulink>
1679 * If you are using a #GtkStyleContext returned from
1680 * gtk_widget_get_style_context(), the parent will be set for you.
1685 gtk_style_context_set_parent (GtkStyleContext *context,
1686 GtkStyleContext *parent)
1688 GtkStyleContextPrivate *priv;
1690 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1691 g_return_if_fail (parent == NULL || GTK_IS_STYLE_CONTEXT (parent));
1693 priv = context->priv;
1695 if (priv->parent == parent)
1699 g_object_ref (parent);
1702 g_object_unref (priv->parent);
1704 priv->parent = parent;
1706 g_object_notify (G_OBJECT (context), "parent");
1707 gtk_style_context_invalidate (context);
1711 * gtk_style_context_get_parent:
1712 * @context: a #GtkStyleContext
1714 * Gets the parent context set via gtk_style_context_set_parent().
1715 * See that function for details.
1717 * Returns: (transfer none): the parent context or %NULL
1722 gtk_style_context_get_parent (GtkStyleContext *context)
1724 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1726 return context->priv->parent;
1730 * gtk_style_context_save:
1731 * @context: a #GtkStyleContext
1733 * Saves the @context state, so all modifications done through
1734 * gtk_style_context_add_class(), gtk_style_context_remove_class(),
1735 * gtk_style_context_add_region(), gtk_style_context_remove_region()
1736 * or gtk_style_context_set_junction_sides() can be reverted in one
1737 * go through gtk_style_context_restore().
1742 gtk_style_context_save (GtkStyleContext *context)
1744 GtkStyleContextPrivate *priv;
1747 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1749 priv = context->priv;
1751 g_assert (priv->info_stack != NULL);
1753 info = style_info_copy (priv->info_stack->data);
1754 priv->info_stack = g_slist_prepend (priv->info_stack, info);
1758 * gtk_style_context_restore:
1759 * @context: a #GtkStyleContext
1761 * Restores @context state to a previous stage.
1762 * See gtk_style_context_save().
1767 gtk_style_context_restore (GtkStyleContext *context)
1769 GtkStyleContextPrivate *priv;
1772 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1774 priv = context->priv;
1776 if (priv->info_stack)
1778 info = priv->info_stack->data;
1779 priv->info_stack = g_slist_remove (priv->info_stack, info);
1780 style_info_free (info);
1783 if (!priv->info_stack)
1785 g_warning ("Unpaired gtk_style_context_restore() call");
1787 /* Create default region */
1788 info = style_info_new ();
1789 priv->info_stack = g_slist_prepend (priv->info_stack, info);
1792 priv->current_data = NULL;
1796 style_class_find (GArray *array,
1801 gboolean found = FALSE;
1807 if (!array || array->len == 0)
1811 max = array->len - 1;
1817 mid = (min + max) / 2;
1818 item = g_array_index (array, GQuark, mid);
1820 if (class_quark == item)
1825 else if (class_quark > item)
1826 min = pos = mid + 1;
1833 while (!found && min <= max);
1842 region_find (GArray *array,
1847 gboolean found = FALSE;
1853 if (!array || array->len == 0)
1857 max = array->len - 1;
1863 mid = (min + max) / 2;
1864 region = &g_array_index (array, GtkRegion, mid);
1866 if (region->class_quark == class_quark)
1871 else if (region->class_quark > class_quark)
1872 min = pos = mid + 1;
1879 while (!found && min <= max);
1888 * gtk_style_context_add_class:
1889 * @context: a #GtkStyleContext
1890 * @class_name: class name to use in styling
1892 * Adds a style class to @context, so posterior calls to
1893 * gtk_style_context_get() or any of the gtk_render_*()
1894 * functions will make use of this new class for styling.
1896 * In the CSS file format, a #GtkEntry defining an "entry"
1897 * class, would be matched by:
1900 * GtkEntry.entry { ... }
1903 * While any widget defining an "entry" class would be
1912 gtk_style_context_add_class (GtkStyleContext *context,
1913 const gchar *class_name)
1915 GtkStyleContextPrivate *priv;
1920 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1921 g_return_if_fail (class_name != NULL);
1923 priv = context->priv;
1924 class_quark = g_quark_from_string (class_name);
1926 g_assert (priv->info_stack != NULL);
1927 info = priv->info_stack->data;
1929 if (!style_class_find (info->style_classes, class_quark, &position))
1931 g_array_insert_val (info->style_classes, position, class_quark);
1933 /* Unset current data, as it likely changed due to the class change */
1934 priv->current_data = NULL;
1939 * gtk_style_context_remove_class:
1940 * @context: a #GtkStyleContext
1941 * @class_name: class name to remove
1943 * Removes @class_name from @context.
1948 gtk_style_context_remove_class (GtkStyleContext *context,
1949 const gchar *class_name)
1951 GtkStyleContextPrivate *priv;
1956 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1957 g_return_if_fail (class_name != NULL);
1959 class_quark = g_quark_try_string (class_name);
1964 priv = context->priv;
1966 g_assert (priv->info_stack != NULL);
1967 info = priv->info_stack->data;
1969 if (style_class_find (info->style_classes, class_quark, &position))
1971 g_array_remove_index (info->style_classes, position);
1973 /* Unset current data, as it likely changed due to the class change */
1974 priv->current_data = NULL;
1979 * gtk_style_context_has_class:
1980 * @context: a #GtkStyleContext
1981 * @class_name: a class name
1983 * Returns %TRUE if @context currently has defined the
1986 * Returns: %TRUE if @context has @class_name defined
1991 gtk_style_context_has_class (GtkStyleContext *context,
1992 const gchar *class_name)
1994 GtkStyleContextPrivate *priv;
1998 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1999 g_return_val_if_fail (class_name != NULL, FALSE);
2001 class_quark = g_quark_try_string (class_name);
2006 priv = context->priv;
2008 g_assert (priv->info_stack != NULL);
2009 info = priv->info_stack->data;
2011 if (style_class_find (info->style_classes, class_quark, NULL))
2018 * gtk_style_context_list_classes:
2019 * @context: a #GtkStyleContext
2021 * Returns the list of classes currently defined in @context.
2023 * Returns: (transfer container) (element-type utf8): a #GList of
2024 * strings with the currently defined classes. The contents
2025 * of the list are owned by GTK+, but you must free the list
2026 * itself with g_list_free() when you are done with it.
2031 gtk_style_context_list_classes (GtkStyleContext *context)
2033 GtkStyleContextPrivate *priv;
2035 GList *classes = NULL;
2038 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2040 priv = context->priv;
2042 g_assert (priv->info_stack != NULL);
2043 info = priv->info_stack->data;
2045 for (i = 0; i < info->style_classes->len; i++)
2049 quark = g_array_index (info->style_classes, GQuark, i);
2050 classes = g_list_prepend (classes, (gchar *) g_quark_to_string (quark));
2057 * gtk_style_context_list_regions:
2058 * @context: a #GtkStyleContext
2060 * Returns the list of regions currently defined in @context.
2062 * Returns: (transfer container) (element-type utf8): a #GList of
2063 * strings with the currently defined regions. The contents
2064 * of the list are owned by GTK+, but you must free the list
2065 * itself with g_list_free() when you are done with it.
2070 gtk_style_context_list_regions (GtkStyleContext *context)
2072 GtkStyleContextPrivate *priv;
2074 GList *classes = NULL;
2077 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2079 priv = context->priv;
2081 g_assert (priv->info_stack != NULL);
2082 info = priv->info_stack->data;
2084 for (i = 0; i < info->regions->len; i++)
2087 const gchar *class_name;
2089 region = &g_array_index (info->regions, GtkRegion, i);
2091 class_name = g_quark_to_string (region->class_quark);
2092 classes = g_list_prepend (classes, (gchar *) class_name);
2099 _gtk_style_context_check_region_name (const gchar *str)
2101 g_return_val_if_fail (str != NULL, FALSE);
2103 if (!g_ascii_islower (str[0]))
2109 !g_ascii_islower (*str))
2119 * gtk_style_context_add_region:
2120 * @context: a #GtkStyleContext
2121 * @region_name: region name to use in styling
2122 * @flags: flags that apply to the region
2124 * Adds a region to @context, so posterior calls to
2125 * gtk_style_context_get() or any of the gtk_render_*()
2126 * functions will make use of this new region for styling.
2128 * In the CSS file format, a #GtkTreeView defining a "row"
2129 * region, would be matched by:
2132 * GtkTreeView row { ... }
2135 * Pseudo-classes are used for matching @flags, so the two
2138 * GtkTreeView row:nth-child(even) { ... }
2139 * GtkTreeView row:nth-child(odd) { ... }
2142 * would apply to even and odd rows, respectively.
2144 * <note><para>Region names must only contain lowercase letters
2145 * and '-', starting always with a lowercase letter.</para></note>
2150 gtk_style_context_add_region (GtkStyleContext *context,
2151 const gchar *region_name,
2152 GtkRegionFlags flags)
2154 GtkStyleContextPrivate *priv;
2156 GQuark region_quark;
2159 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2160 g_return_if_fail (region_name != NULL);
2161 g_return_if_fail (_gtk_style_context_check_region_name (region_name));
2163 priv = context->priv;
2164 region_quark = g_quark_from_string (region_name);
2166 g_assert (priv->info_stack != NULL);
2167 info = priv->info_stack->data;
2169 if (!region_find (info->regions, region_quark, &position))
2173 region.class_quark = region_quark;
2174 region.flags = flags;
2176 g_array_insert_val (info->regions, position, region);
2178 /* Unset current data, as it likely changed due to the region change */
2179 priv->current_data = NULL;
2184 * gtk_style_context_remove_region:
2185 * @context: a #GtkStyleContext
2186 * @region_name: region name to unset
2188 * Removes a region from @context.
2193 gtk_style_context_remove_region (GtkStyleContext *context,
2194 const gchar *region_name)
2196 GtkStyleContextPrivate *priv;
2198 GQuark region_quark;
2201 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2202 g_return_if_fail (region_name != NULL);
2204 region_quark = g_quark_try_string (region_name);
2209 priv = context->priv;
2211 g_assert (priv->info_stack != NULL);
2212 info = priv->info_stack->data;
2214 if (region_find (info->regions, region_quark, &position))
2216 g_array_remove_index (info->regions, position);
2218 /* Unset current data, as it likely changed due to the region change */
2219 priv->current_data = NULL;
2224 * gtk_style_context_has_region:
2225 * @context: a #GtkStyleContext
2226 * @region_name: a region name
2227 * @flags_return: (out) (allow-none): return location for region flags
2229 * Returns %TRUE if @context has the region defined.
2230 * If @flags_return is not %NULL, it is set to the flags
2231 * affecting the region.
2233 * Returns: %TRUE if region is defined
2238 gtk_style_context_has_region (GtkStyleContext *context,
2239 const gchar *region_name,
2240 GtkRegionFlags *flags_return)
2242 GtkStyleContextPrivate *priv;
2244 GQuark region_quark;
2247 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2248 g_return_val_if_fail (region_name != NULL, FALSE);
2253 region_quark = g_quark_try_string (region_name);
2258 priv = context->priv;
2260 g_assert (priv->info_stack != NULL);
2261 info = priv->info_stack->data;
2263 if (region_find (info->regions, region_quark, &position))
2269 region = &g_array_index (info->regions, GtkRegion, position);
2270 *flags_return = region->flags;
2279 style_property_values_cmp (gconstpointer bsearch_node1,
2280 gconstpointer bsearch_node2)
2282 const PropertyValue *val1 = bsearch_node1;
2283 const PropertyValue *val2 = bsearch_node2;
2285 if (val1->widget_type != val2->widget_type)
2286 return val1->widget_type < val2->widget_type ? -1 : 1;
2288 if (val1->pspec != val2->pspec)
2289 return val1->pspec < val2->pspec ? -1 : 1;
2291 if (val1->state != val2->state)
2292 return val1->state < val2->state ? -1 : 1;
2298 _gtk_style_context_peek_property (GtkStyleContext *context,
2299 const char *property_name)
2301 GtkStyleProperty *property;
2304 property = _gtk_style_property_lookup (property_name);
2305 if (!GTK_IS_CSS_STYLE_PROPERTY (property))
2307 g_warning ("Style property \"%s\" does not exist", property_name);
2311 data = style_data_lookup (context, gtk_style_context_get_state (context));
2313 return _gtk_style_properties_peek_property (data->store,
2314 GTK_CSS_STYLE_PROPERTY (property),
2319 _gtk_style_context_peek_style_property (GtkStyleContext *context,
2321 GtkStateFlags state,
2324 GtkStyleContextPrivate *priv;
2325 PropertyValue *pcache, key = { 0 };
2326 GList *global_list = NULL;
2330 priv = context->priv;
2331 data = style_data_lookup (context, state);
2333 key.widget_type = widget_type;
2337 /* need value cache array */
2338 if (!data->property_cache)
2339 data->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
2342 pcache = bsearch (&key,
2343 data->property_cache->data, data->property_cache->len,
2344 sizeof (PropertyValue), style_property_values_cmp);
2346 return &pcache->value;
2350 while (i < data->property_cache->len &&
2351 style_property_values_cmp (&key, &g_array_index (data->property_cache, PropertyValue, i)) >= 0)
2354 g_array_insert_val (data->property_cache, i, key);
2355 pcache = &g_array_index (data->property_cache, PropertyValue, i);
2357 /* cache miss, initialize value type, then set contents */
2358 g_param_spec_ref (pcache->pspec);
2359 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2363 global_list = g_object_get_qdata (G_OBJECT (priv->screen), provider_list_quark);
2364 global_list = g_list_last (global_list);
2367 if (priv->widget_path)
2369 GList *list, *global, *elem;
2371 list = priv->providers_last;
2372 global = global_list;
2374 while ((elem = find_next_candidate (list, global, FALSE)) != NULL)
2376 GtkStyleProviderData *provider_data;
2378 provider_data = elem->data;
2383 global = global->prev;
2385 if (gtk_style_provider_get_style_property (provider_data->provider,
2386 priv->widget_path, state,
2387 pspec, &pcache->value))
2389 /* Resolve symbolic colors to GdkColor/GdkRGBA */
2390 if (G_VALUE_TYPE (&pcache->value) == GTK_TYPE_SYMBOLIC_COLOR)
2392 GtkSymbolicColor *color;
2395 color = g_value_dup_boxed (&pcache->value);
2397 g_value_unset (&pcache->value);
2399 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2400 g_value_init (&pcache->value, GDK_TYPE_RGBA);
2402 g_value_init (&pcache->value, GDK_TYPE_COLOR);
2404 if (gtk_symbolic_color_resolve (color, data->store, &rgba))
2406 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2407 g_value_set_boxed (&pcache->value, &rgba);
2412 rgb.red = rgba.red * 65535. + 0.5;
2413 rgb.green = rgba.green * 65535. + 0.5;
2414 rgb.blue = rgba.blue * 65535. + 0.5;
2416 g_value_set_boxed (&pcache->value, &rgb);
2420 g_param_value_set_default (pspec, &pcache->value);
2422 gtk_symbolic_color_unref (color);
2425 return &pcache->value;
2430 /* not supplied by any provider, revert to default */
2431 g_param_value_set_default (pspec, &pcache->value);
2433 return &pcache->value;
2437 * gtk_style_context_get_style_property:
2438 * @context: a #GtkStyleContext
2439 * @property_name: the name of the widget style property
2440 * @value: Return location for the property value
2442 * Gets the value for a widget style property.
2444 * When @value is no longer needed, g_value_unset() must be called
2445 * to free any allocated memory.
2448 gtk_style_context_get_style_property (GtkStyleContext *context,
2449 const gchar *property_name,
2452 GtkStyleContextPrivate *priv;
2453 GtkWidgetClass *widget_class;
2454 GtkStateFlags state;
2456 const GValue *peek_value;
2459 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2460 g_return_if_fail (property_name != NULL);
2461 g_return_if_fail (value != NULL);
2463 priv = context->priv;
2465 if (!priv->widget_path)
2468 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2470 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2472 g_warning ("%s: can't get style properties for non-widget class `%s'",
2474 g_type_name (widget_type));
2478 widget_class = g_type_class_ref (widget_type);
2479 pspec = gtk_widget_class_find_style_property (widget_class, property_name);
2480 g_type_class_unref (widget_class);
2484 g_warning ("%s: widget class `%s' has no style property named `%s'",
2486 g_type_name (widget_type),
2491 state = gtk_style_context_get_state (context);
2492 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2495 if (G_VALUE_TYPE (value) == G_VALUE_TYPE (peek_value))
2496 g_value_copy (peek_value, value);
2497 else if (g_value_type_transformable (G_VALUE_TYPE (peek_value), G_VALUE_TYPE (value)))
2498 g_value_transform (peek_value, value);
2500 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
2502 G_VALUE_TYPE_NAME (peek_value),
2503 G_VALUE_TYPE_NAME (value));
2507 * gtk_style_context_get_style_valist:
2508 * @context: a #GtkStyleContext
2509 * @args: va_list of property name/return location pairs, followed by %NULL
2511 * Retrieves several widget style properties from @context according to the
2517 gtk_style_context_get_style_valist (GtkStyleContext *context,
2520 GtkStyleContextPrivate *priv;
2521 const gchar *prop_name;
2522 GtkStateFlags state;
2525 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2527 prop_name = va_arg (args, const gchar *);
2528 priv = context->priv;
2530 if (!priv->widget_path)
2533 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2535 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2537 g_warning ("%s: can't get style properties for non-widget class `%s'",
2539 g_type_name (widget_type));
2543 state = gtk_style_context_get_state (context);
2547 GtkWidgetClass *widget_class;
2549 const GValue *peek_value;
2552 widget_class = g_type_class_ref (widget_type);
2553 pspec = gtk_widget_class_find_style_property (widget_class, prop_name);
2554 g_type_class_unref (widget_class);
2558 g_warning ("%s: widget class `%s' has no style property named `%s'",
2560 g_type_name (widget_type),
2565 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2568 G_VALUE_LCOPY (peek_value, args, 0, &error);
2572 g_warning ("can't retrieve style property `%s' of type `%s': %s",
2574 G_VALUE_TYPE_NAME (peek_value),
2579 prop_name = va_arg (args, const gchar *);
2584 * gtk_style_context_get_style:
2585 * @context: a #GtkStyleContext
2586 * @...: property name /return value pairs, followed by %NULL
2588 * Retrieves several widget style properties from @context according to the
2594 gtk_style_context_get_style (GtkStyleContext *context,
2599 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2601 va_start (args, context);
2602 gtk_style_context_get_style_valist (context, args);
2608 * gtk_style_context_lookup_icon_set:
2609 * @context: a #GtkStyleContext
2610 * @stock_id: an icon name
2612 * Looks up @stock_id in the icon factories associated to @context and
2613 * the default icon factory, returning an icon set if found, otherwise
2616 * Returns: (transfer none): The looked up %GtkIconSet, or %NULL
2619 gtk_style_context_lookup_icon_set (GtkStyleContext *context,
2620 const gchar *stock_id)
2622 GtkStyleContextPrivate *priv;
2626 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2627 g_return_val_if_fail (stock_id != NULL, NULL);
2629 priv = context->priv;
2630 g_return_val_if_fail (priv->widget_path != NULL, NULL);
2632 data = style_data_lookup (context, 0);
2634 for (list = data->icon_factories; list; list = list->next)
2636 GtkIconFactory *factory;
2637 GtkIconSet *icon_set;
2639 factory = list->data;
2640 icon_set = gtk_icon_factory_lookup (factory, stock_id);
2646 return gtk_icon_factory_lookup_default (stock_id);
2650 * gtk_style_context_set_screen:
2651 * @context: a #GtkStyleContext
2652 * @screen: a #GdkScreen
2654 * Attaches @context to the given screen.
2656 * The screen is used to add style information from 'global' style
2657 * providers, such as the screens #GtkSettings instance.
2659 * If you are using a #GtkStyleContext returned from
2660 * gtk_widget_get_style_context(), you do not need to
2661 * call this yourself.
2666 gtk_style_context_set_screen (GtkStyleContext *context,
2669 GtkStyleContextPrivate *priv;
2671 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2672 g_return_if_fail (GDK_IS_SCREEN (screen));
2674 priv = context->priv;
2675 if (priv->screen == screen)
2678 priv->screen = screen;
2680 g_object_notify (G_OBJECT (context), "screen");
2682 gtk_style_context_invalidate (context);
2686 * gtk_style_context_get_screen:
2687 * @context: a #GtkStyleContext
2689 * Returns the #GdkScreen to which @context is attached.
2691 * Returns: (transfer none): a #GdkScreen.
2694 gtk_style_context_get_screen (GtkStyleContext *context)
2696 GtkStyleContextPrivate *priv;
2698 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2700 priv = context->priv;
2701 return priv->screen;
2705 * gtk_style_context_set_direction:
2706 * @context: a #GtkStyleContext
2707 * @direction: the new direction.
2709 * Sets the reading direction for rendering purposes.
2711 * If you are using a #GtkStyleContext returned from
2712 * gtk_widget_get_style_context(), you do not need to
2713 * call this yourself.
2718 gtk_style_context_set_direction (GtkStyleContext *context,
2719 GtkTextDirection direction)
2721 GtkStyleContextPrivate *priv;
2723 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2725 priv = context->priv;
2726 priv->direction = direction;
2728 g_object_notify (G_OBJECT (context), "direction");
2732 * gtk_style_context_get_direction:
2733 * @context: a #GtkStyleContext
2735 * Returns the widget direction used for rendering.
2737 * Returns: the widget direction
2742 gtk_style_context_get_direction (GtkStyleContext *context)
2744 GtkStyleContextPrivate *priv;
2746 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), GTK_TEXT_DIR_LTR);
2748 priv = context->priv;
2749 return priv->direction;
2753 * gtk_style_context_set_junction_sides:
2754 * @context: a #GtkStyleContext
2755 * @sides: sides where rendered elements are visually connected to
2758 * Sets the sides where rendered elements (mostly through
2759 * gtk_render_frame()) will visually connect with other visual elements.
2761 * This is merely a hint that may or may not be honored
2762 * by theming engines.
2764 * Container widgets are expected to set junction hints as appropriate
2765 * for their children, so it should not normally be necessary to call
2766 * this function manually.
2771 gtk_style_context_set_junction_sides (GtkStyleContext *context,
2772 GtkJunctionSides sides)
2774 GtkStyleContextPrivate *priv;
2777 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2779 priv = context->priv;
2780 info = priv->info_stack->data;
2781 info->junction_sides = sides;
2785 * gtk_style_context_get_junction_sides:
2786 * @context: a #GtkStyleContext
2788 * Returns the sides where rendered elements connect visually with others.
2790 * Returns: the junction sides
2795 gtk_style_context_get_junction_sides (GtkStyleContext *context)
2797 GtkStyleContextPrivate *priv;
2800 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
2802 priv = context->priv;
2803 info = priv->info_stack->data;
2804 return info->junction_sides;
2807 static GtkSymbolicColor *
2808 gtk_style_context_color_lookup_func (gpointer contextp,
2811 GtkSymbolicColor *sym_color;
2812 GtkStyleContext *context = contextp;
2813 GtkStyleContextPrivate *priv = context->priv;
2814 GList *elem, *list, *global_list = NULL;
2816 list = priv->providers_last;
2819 global_list = g_object_get_qdata (G_OBJECT (priv->screen), provider_list_quark);
2820 global_list = g_list_last (global_list);
2825 while (sym_color == NULL &&
2826 (elem = find_next_candidate (list, global_list, FALSE)) != NULL)
2828 GtkStyleProviderData *data;
2835 global_list = global_list->prev;
2837 if (GTK_IS_STYLE_PROVIDER_PRIVATE (data->provider))
2839 sym_color = _gtk_style_provider_private_get_color (GTK_STYLE_PROVIDER_PRIVATE (data->provider),
2844 /* If somebody hits this code path, shout at them */
2853 _gtk_style_context_resolve_color (GtkStyleContext *context,
2854 GtkSymbolicColor *color,
2857 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2858 g_return_val_if_fail (color != NULL, FALSE);
2859 g_return_val_if_fail (result != NULL, FALSE);
2861 return _gtk_symbolic_color_resolve_full (color,
2862 gtk_style_context_color_lookup_func,
2868 * gtk_style_context_lookup_color:
2869 * @context: a #GtkStyleContext
2870 * @color_name: color name to lookup
2871 * @color: (out): Return location for the looked up color
2873 * Looks up and resolves a color name in the @context color map.
2875 * Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
2878 gtk_style_context_lookup_color (GtkStyleContext *context,
2879 const gchar *color_name,
2882 GtkSymbolicColor *sym_color;
2884 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2885 g_return_val_if_fail (color_name != NULL, FALSE);
2886 g_return_val_if_fail (color != NULL, FALSE);
2888 sym_color = gtk_style_context_color_lookup_func (context, color_name);
2889 if (sym_color == NULL)
2892 return _gtk_style_context_resolve_color (context, sym_color, color);
2896 * gtk_style_context_notify_state_change:
2897 * @context: a #GtkStyleContext
2898 * @window: a #GdkWindow
2899 * @region_id: (allow-none): animatable region to notify on, or %NULL.
2900 * See gtk_style_context_push_animatable_region()
2901 * @state: state to trigger transition for
2902 * @state_value: %TRUE if @state is the state we are changing to,
2903 * %FALSE if we are changing away from it
2905 * Notifies a state change on @context, so if the current style makes use
2906 * of transition animations, one will be started so all rendered elements
2907 * under @region_id are animated for state @state being set to value
2910 * The @window parameter is used in order to invalidate the rendered area
2911 * as the animation runs, so make sure it is the same window that is being
2912 * rendered on by the gtk_render_*() functions.
2914 * If @region_id is %NULL, all rendered elements using @context will be
2915 * affected by this state transition.
2917 * As a practical example, a #GtkButton notifying a state transition on
2918 * the prelight state:
2920 * gtk_style_context_notify_state_change (context,
2921 * gtk_widget_get_window (widget),
2923 * GTK_STATE_PRELIGHT,
2924 * button->in_button);
2927 * Can be handled in the CSS file like this:
2930 * background-color: #f00
2934 * background-color: #fff;
2935 * transition: 200ms linear
2939 * This combination will animate the button background from red to white
2940 * if a pointer enters the button, and back to red if the pointer leaves
2943 * Note that @state is used when finding the transition parameters, which
2944 * is why the style places the transition under the :hover pseudo-class.
2949 gtk_style_context_notify_state_change (GtkStyleContext *context,
2953 gboolean state_value)
2955 GtkStyleContextPrivate *priv;
2956 GtkAnimationDescription *desc;
2957 AnimationInfo *info;
2958 GtkStateFlags flags;
2961 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2962 g_return_if_fail (GDK_IS_WINDOW (window));
2963 g_return_if_fail (state > GTK_STATE_NORMAL && state <= GTK_STATE_FOCUSED);
2965 priv = context->priv;
2966 g_return_if_fail (priv->widget_path != NULL);
2968 state_value = (state_value == TRUE);
2972 case GTK_STATE_ACTIVE:
2973 flags = GTK_STATE_FLAG_ACTIVE;
2975 case GTK_STATE_PRELIGHT:
2976 flags = GTK_STATE_FLAG_PRELIGHT;
2978 case GTK_STATE_SELECTED:
2979 flags = GTK_STATE_FLAG_SELECTED;
2981 case GTK_STATE_INSENSITIVE:
2982 flags = GTK_STATE_FLAG_INSENSITIVE;
2984 case GTK_STATE_INCONSISTENT:
2985 flags = GTK_STATE_FLAG_INCONSISTENT;
2987 case GTK_STATE_FOCUSED:
2988 flags = GTK_STATE_FLAG_FOCUSED;
2990 case GTK_STATE_NORMAL:
2996 /* Find out if there is any animation description for the given
2997 * state, it will fallback to the normal state as well if necessary.
2999 data = style_data_lookup (context, flags);
3000 gtk_style_properties_get (data->store, 0,
3001 "transition", &desc,
3007 if (_gtk_animation_description_get_duration (desc) == 0)
3009 _gtk_animation_description_unref (desc);
3013 info = animation_info_lookup (context, region_id, state);
3016 info->target_value != state_value)
3018 /* Target values are the opposite */
3019 if (!_gtk_timeline_get_loop (info->timeline))
3021 /* Reverse the animation */
3022 if (_gtk_timeline_get_direction (info->timeline) == GTK_TIMELINE_DIRECTION_FORWARD)
3023 _gtk_timeline_set_direction (info->timeline, GTK_TIMELINE_DIRECTION_BACKWARD);
3025 _gtk_timeline_set_direction (info->timeline, GTK_TIMELINE_DIRECTION_FORWARD);
3027 info->target_value = state_value;
3031 /* Take it out of its looping state */
3032 _gtk_timeline_set_loop (info->timeline, FALSE);
3036 (!_gtk_animation_description_get_loop (desc) ||
3039 info = animation_info_new (context, region_id,
3040 _gtk_animation_description_get_duration (desc),
3041 _gtk_animation_description_get_progress_type (desc),
3042 _gtk_animation_description_get_loop (desc),
3043 state, state_value, window);
3045 priv->animations = g_slist_prepend (priv->animations, info);
3046 priv->animations_invalidated = TRUE;
3049 _gtk_animation_description_unref (desc);
3053 * gtk_style_context_cancel_animations:
3054 * @context: a #GtkStyleContext
3055 * @region_id: (allow-none): animatable region to stop, or %NULL.
3056 * See gtk_style_context_push_animatable_region()
3058 * Stops all running animations for @region_id and all animatable
3059 * regions underneath.
3061 * A %NULL @region_id will stop all ongoing animations in @context,
3062 * when dealing with a #GtkStyleContext obtained through
3063 * gtk_widget_get_style_context(), this is normally done for you
3064 * in all circumstances you would expect all widget to be stopped,
3065 * so this should be only used in complex widgets with different
3066 * animatable regions.
3071 gtk_style_context_cancel_animations (GtkStyleContext *context,
3074 GtkStyleContextPrivate *priv;
3075 AnimationInfo *info;
3078 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3080 priv = context->priv;
3081 l = priv->animations;
3089 info->region_id == region_id ||
3090 g_slist_find (info->parent_regions, region_id))
3092 priv->animations = g_slist_remove (priv->animations, info);
3093 animation_info_free (info);
3099 is_parent_of (GdkWindow *parent,
3102 GtkWidget *child_widget, *parent_widget;
3105 gdk_window_get_user_data (child, (gpointer *) &child_widget);
3106 gdk_window_get_user_data (parent, (gpointer *) &parent_widget);
3108 if (child_widget != parent_widget &&
3109 !gtk_widget_is_ancestor (child_widget, parent_widget))
3116 if (window == parent)
3119 window = gdk_window_get_parent (window);
3126 * gtk_style_context_scroll_animations:
3127 * @context: a #GtkStyleContext
3128 * @window: a #GdkWindow used previously in
3129 * gtk_style_context_notify_state_change()
3130 * @dx: Amount to scroll in the X axis
3131 * @dy: Amount to scroll in the Y axis
3133 * This function is analogous to gdk_window_scroll(), and
3134 * should be called together with it so the invalidation
3135 * areas for any ongoing animation are scrolled together
3141 gtk_style_context_scroll_animations (GtkStyleContext *context,
3146 GtkStyleContextPrivate *priv;
3147 AnimationInfo *info;
3150 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3151 g_return_if_fail (GDK_IS_WINDOW (window));
3153 priv = context->priv;
3154 l = priv->animations;
3161 if (info->invalidation_region &&
3162 (window == info->window ||
3163 is_parent_of (window, info->window)))
3164 cairo_region_translate (info->invalidation_region, dx, dy);
3169 * gtk_style_context_push_animatable_region:
3170 * @context: a #GtkStyleContext
3171 * @region_id: unique identifier for the animatable region
3173 * Pushes an animatable region, so all further gtk_render_*() calls between
3174 * this call and the following gtk_style_context_pop_animatable_region()
3175 * will potentially show transition animations for this region if
3176 * gtk_style_context_notify_state_change() is called for a given state,
3177 * and the current theme/style defines transition animations for state
3180 * The @region_id used must be unique in @context so the theming engine
3181 * can uniquely identify rendered elements subject to a state transition.
3186 gtk_style_context_push_animatable_region (GtkStyleContext *context,
3189 GtkStyleContextPrivate *priv;
3191 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3192 g_return_if_fail (region_id != NULL);
3194 priv = context->priv;
3195 priv->animation_regions = g_slist_prepend (priv->animation_regions, region_id);
3199 * gtk_style_context_pop_animatable_region:
3200 * @context: a #GtkStyleContext
3202 * Pops an animatable region from @context.
3203 * See gtk_style_context_push_animatable_region().
3208 gtk_style_context_pop_animatable_region (GtkStyleContext *context)
3210 GtkStyleContextPrivate *priv;
3212 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3214 priv = context->priv;
3215 priv->animation_regions = g_slist_delete_link (priv->animation_regions,
3216 priv->animation_regions);
3220 _gtk_style_context_invalidate_animation_areas (GtkStyleContext *context)
3222 GtkStyleContextPrivate *priv;
3225 priv = context->priv;
3227 for (l = priv->animations; l; l = l->next)
3229 AnimationInfo *info;
3233 /* A NULL invalidation region means it has to be recreated on
3234 * the next expose event, this happens usually after a widget
3235 * allocation change, so the next expose after it will update
3236 * the invalidation region.
3238 if (info->invalidation_region)
3240 cairo_region_destroy (info->invalidation_region);
3241 info->invalidation_region = NULL;
3245 priv->animations_invalidated = TRUE;
3249 _gtk_style_context_coalesce_animation_areas (GtkStyleContext *context,
3252 GtkStyleContextPrivate *priv;
3255 priv = context->priv;
3257 if (!priv->animations_invalidated)
3260 l = priv->animations;
3264 AnimationInfo *info;
3273 if (info->invalidation_region)
3276 if (info->rectangles->len == 0)
3279 info->invalidation_region = cairo_region_create ();
3280 _gtk_widget_get_translation_to_window (widget, info->window, &rel_x, &rel_y);
3282 for (i = 0; i < info->rectangles->len; i++)
3284 cairo_rectangle_int_t *rect;
3286 rect = &g_array_index (info->rectangles, cairo_rectangle_int_t, i);
3288 /* These are widget relative coordinates,
3289 * so have them inverted to be window relative
3294 cairo_region_union_rectangle (info->invalidation_region, rect);
3297 g_array_remove_range (info->rectangles, 0, info->rectangles->len);
3300 priv->animations_invalidated = FALSE;
3304 store_animation_region (GtkStyleContext *context,
3310 GtkStyleContextPrivate *priv;
3313 priv = context->priv;
3315 if (!priv->animations_invalidated)
3318 for (l = priv->animations; l; l = l->next)
3320 AnimationInfo *info;
3324 /* The animation doesn't need updating
3325 * the invalidation area, bail out.
3327 if (info->invalidation_region)
3330 if (context_has_animatable_region (context, info->region_id))
3332 cairo_rectangle_int_t rect;
3336 rect.width = (gint) width;
3337 rect.height = (gint) height;
3339 g_array_append_val (info->rectangles, rect);
3341 if (!info->parent_regions)
3343 GSList *parent_regions;
3345 parent_regions = g_slist_find (priv->animation_regions, info->region_id);
3346 info->parent_regions = g_slist_copy (parent_regions);
3353 * gtk_style_context_invalidate:
3354 * @context: a #GtkStyleContext.
3356 * Invalidates @context style information, so it will be reconstructed
3359 * If you're using a #GtkStyleContext returned from
3360 * gtk_widget_get_style_context(), you do not need to
3361 * call this yourself.
3366 gtk_style_context_invalidate (GtkStyleContext *context)
3368 GtkStyleContextPrivate *priv;
3370 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3372 priv = context->priv;
3374 /* Avoid reentrancy */
3375 if (priv->invalidating_context)
3378 priv->invalidating_context = TRUE;
3380 g_hash_table_remove_all (priv->style_data);
3381 priv->current_data = NULL;
3383 g_signal_emit (context, signals[CHANGED], 0);
3385 priv->invalidating_context = FALSE;
3389 * gtk_style_context_set_background:
3390 * @context: a #GtkStyleContext
3391 * @window: a #GdkWindow
3393 * Sets the background of @window to the background pattern or
3394 * color specified in @context for its current state.
3399 gtk_style_context_set_background (GtkStyleContext *context,
3402 GtkStateFlags state;
3403 cairo_pattern_t *pattern;
3406 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3407 g_return_if_fail (GDK_IS_WINDOW (window));
3409 state = gtk_style_context_get_state (context);
3410 gtk_style_context_get (context, state,
3411 "background-image", &pattern,
3415 gdk_window_set_background_pattern (window, pattern);
3416 cairo_pattern_destroy (pattern);
3420 gtk_style_context_get (context, state,
3421 "background-color", &color,
3425 gdk_window_set_background_rgba (window, color);
3426 gdk_rgba_free (color);
3431 * gtk_style_context_get_color:
3432 * @context: a #GtkStyleContext
3433 * @state: state to retrieve the color for
3434 * @color: (out): return value for the foreground color
3436 * Gets the foreground color for a given state.
3441 gtk_style_context_get_color (GtkStyleContext *context,
3442 GtkStateFlags state,
3447 g_return_if_fail (color != NULL);
3448 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3450 gtk_style_context_get (context,
3460 * gtk_style_context_get_background_color:
3461 * @context: a #GtkStyleContext
3462 * @state: state to retrieve the color for
3463 * @color: (out): return value for the background color
3465 * Gets the background color for a given state.
3470 gtk_style_context_get_background_color (GtkStyleContext *context,
3471 GtkStateFlags state,
3476 g_return_if_fail (color != NULL);
3477 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3479 gtk_style_context_get (context,
3481 "background-color", &c,
3489 * gtk_style_context_get_border_color:
3490 * @context: a #GtkStyleContext
3491 * @state: state to retrieve the color for
3492 * @color: (out): return value for the border color
3494 * Gets the border color for a given state.
3499 gtk_style_context_get_border_color (GtkStyleContext *context,
3500 GtkStateFlags state,
3505 g_return_if_fail (color != NULL);
3506 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3508 gtk_style_context_get (context,
3518 * gtk_style_context_get_border:
3519 * @context: a #GtkStyleContext
3520 * @state: state to retrieve the border for
3521 * @border: (out): return value for the border settings
3523 * Gets the border for a given state as a #GtkBorder.
3524 * See %GTK_STYLE_PROPERTY_BORDER_WIDTH.
3529 gtk_style_context_get_border (GtkStyleContext *context,
3530 GtkStateFlags state,
3533 GtkStyleContextPrivate *priv;
3535 int top, left, bottom, right;
3537 g_return_if_fail (border != NULL);
3538 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3540 priv = context->priv;
3541 g_return_if_fail (priv->widget_path != NULL);
3543 data = style_data_lookup (context, state);
3544 gtk_style_properties_get (data->store,
3546 "border-top-width", &top,
3547 "border-left-width", &left,
3548 "border-bottom-width", &bottom,
3549 "border-right-width", &right,
3553 border->left = left;
3554 border->bottom = bottom;
3555 border->right = right;
3559 * gtk_style_context_get_padding:
3560 * @context: a #GtkStyleContext
3561 * @state: state to retrieve the padding for
3562 * @padding: (out): return value for the padding settings
3564 * Gets the padding for a given state as a #GtkBorder.
3565 * See %GTK_STYLE_PROPERTY_PADDING.
3570 gtk_style_context_get_padding (GtkStyleContext *context,
3571 GtkStateFlags state,
3574 GtkStyleContextPrivate *priv;
3576 int top, left, bottom, right;
3578 g_return_if_fail (padding != NULL);
3579 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3581 priv = context->priv;
3582 g_return_if_fail (priv->widget_path != NULL);
3584 data = style_data_lookup (context, state);
3585 gtk_style_properties_get (data->store,
3587 "padding-top", &top,
3588 "padding-left", &left,
3589 "padding-bottom", &bottom,
3590 "padding-right", &right,
3594 padding->left = left;
3595 padding->bottom = bottom;
3596 padding->right = right;
3600 * gtk_style_context_get_margin:
3601 * @context: a #GtkStyleContext
3602 * @state: state to retrieve the border for
3603 * @margin: (out): return value for the margin settings
3605 * Gets the margin for a given state as a #GtkBorder.
3606 * See %GTK_STYLE_PROPERTY_MARGIN.
3611 gtk_style_context_get_margin (GtkStyleContext *context,
3612 GtkStateFlags state,
3615 GtkStyleContextPrivate *priv;
3617 int top, left, bottom, right;
3619 g_return_if_fail (margin != NULL);
3620 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3622 priv = context->priv;
3623 g_return_if_fail (priv->widget_path != NULL);
3625 data = style_data_lookup (context, state);
3626 gtk_style_properties_get (data->store,
3629 "margin-left", &left,
3630 "margin-bottom", &bottom,
3631 "margin-right", &right,
3635 margin->left = left;
3636 margin->bottom = bottom;
3637 margin->right = right;
3641 * gtk_style_context_get_font:
3642 * @context: a #GtkStyleContext
3643 * @state: state to retrieve the font for
3645 * Returns the font description for a given state. The returned
3646 * object is const and will remain valid until the
3647 * #GtkStyleContext::changed signal happens.
3649 * Returns: (transfer none): the #PangoFontDescription for the given
3650 * state. This object is owned by GTK+ and should not be
3655 const PangoFontDescription *
3656 gtk_style_context_get_font (GtkStyleContext *context,
3657 GtkStateFlags state)
3659 GtkStyleContextPrivate *priv;
3661 GHashTable *font_cache;
3662 PangoFontDescription *description;
3664 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
3666 priv = context->priv;
3667 g_return_val_if_fail (priv->widget_path != NULL, NULL);
3669 data = style_data_lookup (context, state);
3671 /* Yuck, fonts are created on-demand but we don't return a ref.
3672 * Do bad things to achieve this requirement */
3673 font_cache = g_object_get_data (G_OBJECT (data->store), "font-cache-for-get_font");
3676 description = g_hash_table_lookup (font_cache, GUINT_TO_POINTER (state));
3680 font_cache = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) pango_font_description_free);
3681 g_object_set_data_full (G_OBJECT (data->store),
3682 "font-cache-for-get_font",
3684 (GDestroyNotify) g_hash_table_unref);
3688 if (description == NULL)
3690 gtk_style_properties_get (data->store, 0, "font", &description, NULL);
3691 g_hash_table_insert (font_cache, GUINT_TO_POINTER (state), description);
3698 get_cursor_color (GtkStyleContext *context,
3702 GdkColor *style_color;
3704 gtk_style_context_get_style (context,
3705 primary ? "cursor-color" : "secondary-cursor-color",
3711 color->red = style_color->red / 65535.0;
3712 color->green = style_color->green / 65535.0;
3713 color->blue = style_color->blue / 65535.0;
3716 gdk_color_free (style_color);
3720 gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, color);
3726 gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &bg);
3728 color->red = (color->red + bg.red) * 0.5;
3729 color->green = (color->green + bg.green) * 0.5;
3730 color->blue = (color->blue + bg.blue) * 0.5;
3736 _gtk_style_context_get_cursor_color (GtkStyleContext *context,
3737 GdkRGBA *primary_color,
3738 GdkRGBA *secondary_color)
3741 get_cursor_color (context, TRUE, primary_color);
3743 if (secondary_color)
3744 get_cursor_color (context, FALSE, secondary_color);
3751 * @context: a #GtkStyleContext
3753 * @x: X origin of the rectangle
3754 * @y: Y origin of the rectangle
3755 * @width: rectangle width
3756 * @height: rectangle height
3758 * Renders a checkmark (as in a #GtkCheckButton).
3760 * The %GTK_STATE_FLAG_ACTIVE state determines whether the check is
3761 * on or off, and %GTK_STATE_FLAG_INCONSISTENT determines whether it
3762 * should be marked as undefined.
3765 * <title>Typical checkmark rendering</title>
3766 * <inlinegraphic fileref="checks.png" format="PNG"/>
3772 gtk_render_check (GtkStyleContext *context,
3779 GtkStyleContextPrivate *priv;
3780 GtkThemingEngineClass *engine_class;
3782 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3783 g_return_if_fail (cr != NULL);
3785 if (width <= 0 || height <= 0)
3788 priv = context->priv;
3789 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3793 store_animation_region (context, x, y, width, height);
3795 _gtk_theming_engine_set_context (priv->theming_engine, context);
3796 engine_class->render_check (priv->theming_engine, cr,
3797 x, y, width, height);
3803 * gtk_render_option:
3804 * @context: a #GtkStyleContext
3806 * @x: X origin of the rectangle
3807 * @y: Y origin of the rectangle
3808 * @width: rectangle width
3809 * @height: rectangle height
3811 * Renders an option mark (as in a #GtkRadioButton), the %GTK_STATE_FLAG_ACTIVE
3812 * state will determine whether the option is on or off, and
3813 * %GTK_STATE_FLAG_INCONSISTENT whether it should be marked as undefined.
3816 * <title>Typical option mark rendering</title>
3817 * <inlinegraphic fileref="options.png" format="PNG"/>
3823 gtk_render_option (GtkStyleContext *context,
3830 GtkStyleContextPrivate *priv;
3831 GtkThemingEngineClass *engine_class;
3833 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3834 g_return_if_fail (cr != NULL);
3836 if (width <= 0 || height <= 0)
3839 priv = context->priv;
3840 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3844 store_animation_region (context, x, y, width, height);
3846 _gtk_theming_engine_set_context (priv->theming_engine, context);
3847 engine_class->render_option (priv->theming_engine, cr,
3848 x, y, width, height);
3855 * @context: a #GtkStyleContext
3857 * @angle: arrow angle from 0 to 2 * %G_PI, being 0 the arrow pointing to the north
3858 * @x: X origin of the render area
3859 * @y: Y origin of the render area
3860 * @size: square side for render area
3862 * Renders an arrow pointing to @angle.
3865 * <title>Typical arrow rendering at 0, 1&solidus;2 π, π and 3&solidus;2 π</title>
3866 * <inlinegraphic fileref="arrows.png" format="PNG"/>
3872 gtk_render_arrow (GtkStyleContext *context,
3879 GtkStyleContextPrivate *priv;
3880 GtkThemingEngineClass *engine_class;
3882 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3883 g_return_if_fail (cr != NULL);
3888 priv = context->priv;
3889 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3893 gtk_style_context_save (context);
3894 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ARROW);
3896 store_animation_region (context, x, y, size, size);
3898 _gtk_theming_engine_set_context (priv->theming_engine, context);
3899 engine_class->render_arrow (priv->theming_engine, cr,
3902 gtk_style_context_restore (context);
3907 * gtk_render_background:
3908 * @context: a #GtkStyleContext
3910 * @x: X origin of the rectangle
3911 * @y: Y origin of the rectangle
3912 * @width: rectangle width
3913 * @height: rectangle height
3915 * Renders the background of an element.
3918 * <title>Typical background rendering, showing the effect of
3919 * <parameter>background-image</parameter>,
3920 * <parameter>border-width</parameter> and
3921 * <parameter>border-radius</parameter></title>
3922 * <inlinegraphic fileref="background.png" format="PNG"/>
3928 gtk_render_background (GtkStyleContext *context,
3935 GtkStyleContextPrivate *priv;
3936 GtkThemingEngineClass *engine_class;
3938 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3939 g_return_if_fail (cr != NULL);
3941 if (width <= 0 || height <= 0)
3944 priv = context->priv;
3945 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3949 store_animation_region (context, x, y, width, height);
3951 _gtk_theming_engine_set_context (priv->theming_engine, context);
3952 engine_class->render_background (priv->theming_engine, cr, x, y, width, height);
3959 * @context: a #GtkStyleContext
3961 * @x: X origin of the rectangle
3962 * @y: Y origin of the rectangle
3963 * @width: rectangle width
3964 * @height: rectangle height
3966 * Renders a frame around the rectangle defined by @x, @y, @width, @height.
3969 * <title>Examples of frame rendering, showing the effect of
3970 * <parameter>border-image</parameter>,
3971 * <parameter>border-color</parameter>,
3972 * <parameter>border-width</parameter>,
3973 * <parameter>border-radius</parameter> and
3975 * <inlinegraphic fileref="frames.png" format="PNG"/>
3981 gtk_render_frame (GtkStyleContext *context,
3988 GtkStyleContextPrivate *priv;
3989 GtkThemingEngineClass *engine_class;
3991 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3992 g_return_if_fail (cr != NULL);
3994 if (width <= 0 || height <= 0)
3997 priv = context->priv;
3998 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4002 store_animation_region (context, x, y, width, height);
4004 _gtk_theming_engine_set_context (priv->theming_engine, context);
4005 engine_class->render_frame (priv->theming_engine, cr, x, y, width, height);
4011 * gtk_render_expander:
4012 * @context: a #GtkStyleContext
4014 * @x: X origin of the rectangle
4015 * @y: Y origin of the rectangle
4016 * @width: rectangle width
4017 * @height: rectangle height
4019 * Renders an expander (as used in #GtkTreeView and #GtkExpander) in the area
4020 * defined by @x, @y, @width, @height. The state %GTK_STATE_FLAG_ACTIVE
4021 * determines whether the expander is collapsed or expanded.
4024 * <title>Typical expander rendering</title>
4025 * <inlinegraphic fileref="expanders.png" format="PNG"/>
4031 gtk_render_expander (GtkStyleContext *context,
4038 GtkStyleContextPrivate *priv;
4039 GtkThemingEngineClass *engine_class;
4041 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4042 g_return_if_fail (cr != NULL);
4044 if (width <= 0 || height <= 0)
4047 priv = context->priv;
4048 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4052 store_animation_region (context, x, y, width, height);
4054 _gtk_theming_engine_set_context (priv->theming_engine, context);
4055 engine_class->render_expander (priv->theming_engine, cr, x, y, width, height);
4062 * @context: a #GtkStyleContext
4064 * @x: X origin of the rectangle
4065 * @y: Y origin of the rectangle
4066 * @width: rectangle width
4067 * @height: rectangle height
4069 * Renders a focus indicator on the rectangle determined by @x, @y, @width, @height.
4071 * <title>Typical focus rendering</title>
4072 * <inlinegraphic fileref="focus.png" format="PNG"/>
4078 gtk_render_focus (GtkStyleContext *context,
4085 GtkStyleContextPrivate *priv;
4086 GtkThemingEngineClass *engine_class;
4088 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4089 g_return_if_fail (cr != NULL);
4091 if (width <= 0 || height <= 0)
4094 priv = context->priv;
4095 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4099 store_animation_region (context, x, y, width, height);
4101 _gtk_theming_engine_set_context (priv->theming_engine, context);
4102 engine_class->render_focus (priv->theming_engine, cr, x, y, width, height);
4108 * gtk_render_layout:
4109 * @context: a #GtkStyleContext
4113 * @layout: the #PangoLayout to render
4115 * Renders @layout on the coordinates @x, @y
4120 gtk_render_layout (GtkStyleContext *context,
4124 PangoLayout *layout)
4126 GtkStyleContextPrivate *priv;
4127 GtkThemingEngineClass *engine_class;
4128 PangoRectangle extents;
4130 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4131 g_return_if_fail (PANGO_IS_LAYOUT (layout));
4132 g_return_if_fail (cr != NULL);
4134 priv = context->priv;
4135 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4139 pango_layout_get_extents (layout, &extents, NULL);
4141 store_animation_region (context,
4147 _gtk_theming_engine_set_context (priv->theming_engine, context);
4148 engine_class->render_layout (priv->theming_engine, cr, x, y, layout);
4155 * @context: a #GtkStyleContext
4157 * @x0: X coordinate for the origin of the line
4158 * @y0: Y coordinate for the origin of the line
4159 * @x1: X coordinate for the end of the line
4160 * @y1: Y coordinate for the end of the line
4162 * Renders a line from (x0, y0) to (x1, y1).
4167 gtk_render_line (GtkStyleContext *context,
4174 GtkStyleContextPrivate *priv;
4175 GtkThemingEngineClass *engine_class;
4177 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4178 g_return_if_fail (cr != NULL);
4180 priv = context->priv;
4181 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4185 _gtk_theming_engine_set_context (priv->theming_engine, context);
4186 engine_class->render_line (priv->theming_engine, cr, x0, y0, x1, y1);
4192 * gtk_render_slider:
4193 * @context: a #GtkStyleContext
4195 * @x: X origin of the rectangle
4196 * @y: Y origin of the rectangle
4197 * @width: rectangle width
4198 * @height: rectangle height
4199 * @orientation: orientation of the slider
4201 * Renders a slider (as in #GtkScale) in the rectangle defined by @x, @y,
4202 * @width, @height. @orientation defines whether the slider is vertical
4206 * <title>Typical slider rendering</title>
4207 * <inlinegraphic fileref="sliders.png" format="PNG"/>
4213 gtk_render_slider (GtkStyleContext *context,
4219 GtkOrientation orientation)
4221 GtkStyleContextPrivate *priv;
4222 GtkThemingEngineClass *engine_class;
4224 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4225 g_return_if_fail (cr != NULL);
4227 if (width <= 0 || height <= 0)
4230 priv = context->priv;
4231 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4235 store_animation_region (context, x, y, width, height);
4237 _gtk_theming_engine_set_context (priv->theming_engine, context);
4238 engine_class->render_slider (priv->theming_engine, cr, x, y, width, height, orientation);
4244 * gtk_render_frame_gap:
4245 * @context: a #GtkStyleContext
4247 * @x: X origin of the rectangle
4248 * @y: Y origin of the rectangle
4249 * @width: rectangle width
4250 * @height: rectangle height
4251 * @gap_side: side where the gap is
4252 * @xy0_gap: initial coordinate (X or Y depending on @gap_side) for the gap
4253 * @xy1_gap: end coordinate (X or Y depending on @gap_side) for the gap
4255 * Renders a frame around the rectangle defined by (@x, @y, @width, @height),
4256 * leaving a gap on one side. @xy0_gap and @xy1_gap will mean X coordinates
4257 * for %GTK_POS_TOP and %GTK_POS_BOTTOM gap sides, and Y coordinates for
4258 * %GTK_POS_LEFT and %GTK_POS_RIGHT.
4261 * <title>Typical rendering of a frame with a gap</title>
4262 * <inlinegraphic fileref="frame-gap.png" format="PNG"/>
4268 gtk_render_frame_gap (GtkStyleContext *context,
4274 GtkPositionType gap_side,
4278 GtkStyleContextPrivate *priv;
4279 GtkThemingEngineClass *engine_class;
4281 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4282 g_return_if_fail (cr != NULL);
4283 g_return_if_fail (xy0_gap <= xy1_gap);
4284 g_return_if_fail (xy0_gap >= 0);
4286 if (width <= 0 || height <= 0)
4289 if (gap_side == GTK_POS_LEFT ||
4290 gap_side == GTK_POS_RIGHT)
4291 g_return_if_fail (xy1_gap <= height);
4293 g_return_if_fail (xy1_gap <= width);
4295 priv = context->priv;
4296 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4300 store_animation_region (context, x, y, width, height);
4302 _gtk_theming_engine_set_context (priv->theming_engine, context);
4303 engine_class->render_frame_gap (priv->theming_engine, cr,
4304 x, y, width, height, gap_side,
4311 * gtk_render_extension:
4312 * @context: a #GtkStyleContext
4314 * @x: X origin of the rectangle
4315 * @y: Y origin of the rectangle
4316 * @width: rectangle width
4317 * @height: rectangle height
4318 * @gap_side: side where the gap is
4320 * Renders a extension (as in a #GtkNotebook tab) in the rectangle
4321 * defined by @x, @y, @width, @height. The side where the extension
4322 * connects to is defined by @gap_side.
4325 * <title>Typical extension rendering</title>
4326 * <inlinegraphic fileref="extensions.png" format="PNG"/>
4332 gtk_render_extension (GtkStyleContext *context,
4338 GtkPositionType gap_side)
4340 GtkStyleContextPrivate *priv;
4341 GtkThemingEngineClass *engine_class;
4343 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4344 g_return_if_fail (cr != NULL);
4346 if (width <= 0 || height <= 0)
4349 priv = context->priv;
4350 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4354 store_animation_region (context, x, y, width, height);
4356 _gtk_theming_engine_set_context (priv->theming_engine, context);
4357 engine_class->render_extension (priv->theming_engine, cr, x, y, width, height, gap_side);
4363 * gtk_render_handle:
4364 * @context: a #GtkStyleContext
4366 * @x: X origin of the rectangle
4367 * @y: Y origin of the rectangle
4368 * @width: rectangle width
4369 * @height: rectangle height
4371 * Renders a handle (as in #GtkHandleBox, #GtkPaned and
4372 * #GtkWindow<!-- -->'s resize grip), in the rectangle
4373 * determined by @x, @y, @width, @height.
4376 * <title>Handles rendered for the paned and grip classes</title>
4377 * <inlinegraphic fileref="handles.png" format="PNG"/>
4383 gtk_render_handle (GtkStyleContext *context,
4390 GtkStyleContextPrivate *priv;
4391 GtkThemingEngineClass *engine_class;
4393 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4394 g_return_if_fail (cr != NULL);
4396 if (width <= 0 || height <= 0)
4399 priv = context->priv;
4400 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4404 store_animation_region (context, x, y, width, height);
4406 _gtk_theming_engine_set_context (priv->theming_engine, context);
4407 engine_class->render_handle (priv->theming_engine, cr, x, y, width, height);
4413 * gtk_render_activity:
4414 * @context: a #GtkStyleContext
4416 * @x: X origin of the rectangle
4417 * @y: Y origin of the rectangle
4418 * @width: rectangle width
4419 * @height: rectangle height
4421 * Renders an activity area (Such as in #GtkSpinner or the
4422 * fill line in #GtkRange), the state %GTK_STATE_FLAG_ACTIVE
4423 * determines whether there is activity going on.
4428 gtk_render_activity (GtkStyleContext *context,
4435 GtkStyleContextPrivate *priv;
4436 GtkThemingEngineClass *engine_class;
4438 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4439 g_return_if_fail (cr != NULL);
4441 if (width <= 0 || height <= 0)
4444 priv = context->priv;
4445 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4449 store_animation_region (context, x, y, width, height);
4451 _gtk_theming_engine_set_context (priv->theming_engine, context);
4452 engine_class->render_activity (priv->theming_engine, cr, x, y, width, height);
4458 * gtk_render_icon_pixbuf:
4459 * @context: a #GtkStyleContext
4460 * @source: the #GtkIconSource specifying the icon to render
4461 * @size: (type int): the size to render the icon at. A size of (GtkIconSize) -1
4462 * means render at the size of the source and don't scale.
4464 * Renders the icon specified by @source at the given @size, returning the result
4467 * Returns: (transfer full): a newly-created #GdkPixbuf containing the rendered icon
4472 gtk_render_icon_pixbuf (GtkStyleContext *context,
4473 const GtkIconSource *source,
4476 GtkStyleContextPrivate *priv;
4477 GtkThemingEngineClass *engine_class;
4479 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
4480 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
4481 g_return_val_if_fail (source != NULL, NULL);
4483 priv = context->priv;
4484 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4486 _gtk_theming_engine_set_context (priv->theming_engine, context);
4487 return engine_class->render_icon_pixbuf (priv->theming_engine, source, size);
4492 * @context: a #GtkStyleContext
4494 * @pixbuf: a #GdkPixbuf containing the icon to draw
4495 * @x: X position for the @pixbuf
4496 * @y: Y position for the @pixbuf
4498 * Renders the icon in @pixbuf at the specified @x and @y coordinates.
4503 gtk_render_icon (GtkStyleContext *context,
4509 GtkStyleContextPrivate *priv;
4510 GtkThemingEngineClass *engine_class;
4512 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4513 g_return_if_fail (cr != NULL);
4515 priv = context->priv;
4516 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4520 store_animation_region (context,
4522 gdk_pixbuf_get_width (pixbuf),
4523 gdk_pixbuf_get_height (pixbuf));
4525 _gtk_theming_engine_set_context (priv->theming_engine, context);
4526 engine_class->render_icon (priv->theming_engine, cr, pixbuf, x, y);
4532 draw_insertion_cursor (GtkStyleContext *context,
4537 gboolean is_primary,
4538 PangoDirection direction,
4539 gboolean draw_arrow)
4542 GdkRGBA primary_color;
4543 GdkRGBA secondary_color;
4544 gfloat cursor_aspect_ratio;
4550 _gtk_style_context_get_cursor_color (context, &primary_color, &secondary_color);
4551 gdk_cairo_set_source_rgba (cr, is_primary ? &primary_color : &secondary_color);
4553 /* When changing the shape or size of the cursor here,
4554 * propagate the changes to gtktextview.c:text_window_invalidate_cursors().
4557 gtk_style_context_get_style (context,
4558 "cursor-aspect-ratio", &cursor_aspect_ratio,
4561 stem_width = height * cursor_aspect_ratio + 1;
4563 /* put (stem_width % 2) on the proper side of the cursor */
4564 if (direction == PANGO_DIRECTION_LTR)
4565 offset = stem_width / 2;
4567 offset = stem_width - stem_width / 2;
4569 cairo_rectangle (cr, x - offset, y, stem_width, height);
4577 arrow_width = stem_width + 1;
4579 if (direction == PANGO_DIRECTION_RTL)
4581 ax = x - offset - 1;
4582 ay = y + height - arrow_width * 2 - arrow_width + 1;
4584 cairo_move_to (cr, ax, ay + 1);
4585 cairo_line_to (cr, ax - arrow_width, ay + arrow_width);
4586 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4589 else if (direction == PANGO_DIRECTION_LTR)
4591 ax = x + stem_width - offset;
4592 ay = y + height - arrow_width * 2 - arrow_width + 1;
4594 cairo_move_to (cr, ax, ay + 1);
4595 cairo_line_to (cr, ax + arrow_width, ay + arrow_width);
4596 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4600 g_assert_not_reached();
4607 * gtk_render_insertion_cursor:
4608 * @context: a #GtkStyleContext
4612 * @layout: the #PangoLayout of the text
4613 * @index: the index in the #PangoLayout
4614 * @direction: the #PangoDirection of the text
4616 * Draws a text caret on @cr at the specified index of @layout.
4621 gtk_render_insertion_cursor (GtkStyleContext *context,
4625 PangoLayout *layout,
4627 PangoDirection direction)
4629 GtkStyleContextPrivate *priv;
4630 gboolean split_cursor;
4631 PangoRectangle strong_pos, weak_pos;
4632 PangoRectangle *cursor1, *cursor2;
4633 PangoDirection keymap_direction;
4634 PangoDirection direction2;
4636 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4637 g_return_if_fail (cr != NULL);
4638 g_return_if_fail (PANGO_IS_LAYOUT (layout));
4639 g_return_if_fail (index >= 0);
4641 priv = context->priv;
4643 g_object_get (gtk_settings_get_for_screen (priv->screen),
4644 "gtk-split-cursor", &split_cursor,
4647 keymap_direction = gdk_keymap_get_direction (gdk_keymap_get_for_display (gdk_screen_get_display (priv->screen)));
4649 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4651 direction2 = PANGO_DIRECTION_NEUTRAL;
4655 cursor1 = &strong_pos;
4657 if (strong_pos.x != weak_pos.x || strong_pos.y != weak_pos.y)
4659 direction2 = (direction == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
4660 cursor2 = &weak_pos;
4665 if (keymap_direction == direction)
4666 cursor1 = &strong_pos;
4668 cursor1 = &weak_pos;
4671 draw_insertion_cursor (context,
4673 x + PANGO_PIXELS (cursor1->x),
4674 y + PANGO_PIXELS (cursor1->y),
4675 PANGO_PIXELS (cursor1->height),
4678 direction2 != PANGO_DIRECTION_NEUTRAL);
4680 if (direction2 != PANGO_DIRECTION_NEUTRAL)
4682 draw_insertion_cursor (context,
4684 x + PANGO_PIXELS (cursor2->x),
4685 y + PANGO_PIXELS (cursor2->y),
4686 PANGO_PIXELS (cursor2->height),
4694 * gtk_draw_insertion_cursor:
4695 * @widget: a #GtkWidget
4696 * @cr: cairo context to draw to
4697 * @location: location where to draw the cursor (@location->width is ignored)
4698 * @is_primary: if the cursor should be the primary cursor color.
4699 * @direction: whether the cursor is left-to-right or
4700 * right-to-left. Should never be #GTK_TEXT_DIR_NONE
4701 * @draw_arrow: %TRUE to draw a directional arrow on the
4702 * cursor. Should be %FALSE unless the cursor is split.
4704 * Draws a text caret on @cr at @location. This is not a style function
4705 * but merely a convenience function for drawing the standard cursor shape.
4710 gtk_draw_insertion_cursor (GtkWidget *widget,
4712 const GdkRectangle *location,
4713 gboolean is_primary,
4714 GtkTextDirection direction,
4715 gboolean draw_arrow)
4717 GtkStyleContext *context;
4719 g_return_if_fail (GTK_IS_WIDGET (widget));
4720 g_return_if_fail (cr != NULL);
4721 g_return_if_fail (location != NULL);
4722 g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
4724 context = gtk_widget_get_style_context (widget);
4726 draw_insertion_cursor (context, cr,
4727 location->x, location->y, location->height,
4729 (direction == GTK_TEXT_DIR_RTL) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR,
4733 static AtkAttributeSet *
4734 add_attribute (AtkAttributeSet *attributes,
4735 AtkTextAttribute attr,
4740 at = g_new (AtkAttribute, 1);
4741 at->name = g_strdup (atk_text_attribute_get_name (attr));
4742 at->value = g_strdup (value);
4744 return g_slist_prepend (attributes, at);
4748 * _gtk_style_context_get_attributes:
4749 * @attributes: a #AtkAttributeSet to add attributes to
4750 * @context: the #GtkStyleContext to get attributes from
4751 * @flags: the state to use with @context
4753 * Adds the foreground and background color from @context to
4754 * @attributes, after translating them to ATK attributes.
4756 * This is a convenience function that can be used in
4757 * implementing the #AtkText interface in widgets.
4759 * Returns: the modified #AtkAttributeSet
4762 _gtk_style_context_get_attributes (AtkAttributeSet *attributes,
4763 GtkStyleContext *context,
4764 GtkStateFlags flags)
4769 gtk_style_context_get_background_color (context, flags, &color);
4770 value = g_strdup_printf ("%u,%u,%u",
4771 (guint) ceil (color.red * 65536 - color.red),
4772 (guint) ceil (color.green * 65536 - color.green),
4773 (guint) ceil (color.blue * 65536 - color.blue));
4774 attributes = add_attribute (attributes, ATK_TEXT_ATTR_BG_COLOR, value);
4777 gtk_style_context_get_color (context, flags, &color);
4778 value = g_strdup_printf ("%u,%u,%u",
4779 (guint) ceil (color.red * 65536 - color.red),
4780 (guint) ceil (color.green * 65536 - color.green),
4781 (guint) ceil (color.blue * 65536 - color.blue));
4782 attributes = add_attribute (attributes, ATK_TEXT_ATTR_FG_COLOR, value);