1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2010 Carlos Garnacho <carlosg@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
23 #include <gobject/gvaluecollector.h>
25 #include "gtkstylecontextprivate.h"
26 #include "gtkcontainerprivate.h"
27 #include "gtkcssenginevalueprivate.h"
28 #include "gtkcssnumbervalueprivate.h"
29 #include "gtkcssrgbavalueprivate.h"
31 #include "gtkgradientprivate.h"
32 #include "gtkstylepropertiesprivate.h"
33 #include "gtktypebuiltins.h"
34 #include "gtkthemingengineprivate.h"
36 #include "gtkwidget.h"
37 #include "gtkwindow.h"
38 #include "gtkprivate.h"
39 #include "gtksymboliccolorprivate.h"
40 #include "gtkiconfactory.h"
41 #include "gtkwidgetpath.h"
42 #include "gtkwidgetprivate.h"
43 #include "gtkstylecascadeprivate.h"
44 #include "gtkstyleproviderprivate.h"
45 #include "gtksettings.h"
46 #include "gtksettingsprivate.h"
49 * SECTION:gtkstylecontext
50 * @Short_description: Rendering UI elements
51 * @Title: GtkStyleContext
53 * #GtkStyleContext is an object that stores styling information affecting
54 * a widget defined by #GtkWidgetPath.
56 * In order to construct the final style information, #GtkStyleContext
57 * queries information from all attached #GtkStyleProviders. Style providers
58 * can be either attached explicitly to the context through
59 * gtk_style_context_add_provider(), or to the screen through
60 * gtk_style_context_add_provider_for_screen(). The resulting style is a
61 * combination of all providers' information in priority order.
63 * For GTK+ widgets, any #GtkStyleContext returned by
64 * gtk_widget_get_style_context() will already have a #GtkWidgetPath, a
65 * #GdkScreen and RTL/LTR information set. The style context will be also
66 * updated automatically if any of these settings change on the widget.
68 * If you are using the theming layer standalone, you will need to set a
69 * widget path and a screen yourself to the created style context through
70 * gtk_style_context_set_path() and gtk_style_context_set_screen(), as well
71 * as updating the context yourself using gtk_style_context_invalidate()
72 * whenever any of the conditions change, such as a change in the
73 * #GtkSettings:gtk-theme-name setting or a hierarchy change in the rendered
76 * <refsect2 id="gtkstylecontext-animations">
77 * <title>Transition animations</title>
79 * #GtkStyleContext has built-in support for state change transitions.
80 * Note that these animations respect the #GtkSettings:gtk-enable-animations
84 * For simple widgets where state changes affect the whole widget area,
85 * calling gtk_style_context_notify_state_change() with a %NULL region
86 * is sufficient to trigger the transition animation. And GTK+ already
87 * does that when gtk_widget_set_state() or gtk_widget_set_state_flags()
91 * If a widget needs to declare several animatable regions (i.e. not
92 * affecting the whole widget area), its #GtkWidget::draw signal handler
93 * needs to wrap the render operations for the different regions with
94 * calls to gtk_style_context_push_animatable_region() and
95 * gtk_style_context_pop_animatable_region(). These functions take an
96 * identifier for the region which must be unique within the style context.
97 * For simple widgets with a fixed set of animatable regions, using an
98 * enumeration works well:
101 * <title>Using an enumeration to identify animatable regions</title>
112 * spin_button_draw (GtkWidget *widget,
115 * GtkStyleContext *context;
117 * context = gtk_widget_get_style_context (widget);
119 * gtk_style_context_push_animatable_region (context,
120 * GUINT_TO_POINTER (REGION_ENTRY));
122 * gtk_render_background (cr, 0, 0, 100, 30);
123 * gtk_render_frame (cr, 0, 0, 100, 30);
125 * gtk_style_context_pop_animatable_region (context);
132 * For complex widgets with an arbitrary number of animatable regions, it
133 * is up to the implementation to come up with a way to uniquely identify
134 * each animatable region. Using pointers to internal structs is one way
138 * <title>Using struct pointers to identify animatable regions</title>
141 * notebook_draw_tab (GtkWidget *widget,
142 * NotebookPage *page,
145 * gtk_style_context_push_animatable_region (context, page);
146 * gtk_render_extension (cr, page->x, page->y, page->width, page->height);
147 * gtk_style_context_pop_animatable_region (context);
152 * The widget also needs to notify the style context about a state change
153 * for a given animatable region so the animation is triggered.
156 * <title>Triggering a state change animation on a region</title>
159 * notebook_motion_notify (GtkWidget *widget,
160 * GdkEventMotion *event)
162 * GtkStyleContext *context;
163 * NotebookPage *page;
165 * context = gtk_widget_get_style_context (widget);
166 * page = find_page_under_pointer (widget, event);
167 * gtk_style_context_notify_state_change (context,
168 * gtk_widget_get_window (widget),
170 * GTK_STATE_PRELIGHT,
177 * gtk_style_context_notify_state_change() accepts %NULL region IDs as a
178 * special value, in this case, the whole widget area will be updated
182 * <refsect2 id="gtkstylecontext-classes">
183 * <title>Style classes and regions</title>
185 * Widgets can add style classes to their context, which can be used
186 * to associate different styles by class (see <xref linkend="gtkcssprovider-selectors"/>). Theme engines can also use style classes to vary their
187 * rendering. GTK+ has a number of predefined style classes:
188 * #GTK_STYLE_CLASS_CELL,
189 * #GTK_STYLE_CLASS_ENTRY,
190 * #GTK_STYLE_CLASS_BUTTON,
191 * #GTK_STYLE_CLASS_COMBOBOX_ENTRY,
192 * #GTK_STYLE_CLASS_CALENDAR,
193 * #GTK_STYLE_CLASS_SLIDER,
194 * #GTK_STYLE_CLASS_BACKGROUND,
195 * #GTK_STYLE_CLASS_RUBBERBAND,
196 * #GTK_STYLE_CLASS_TOOLTIP,
197 * #GTK_STYLE_CLASS_MENU,
198 * #GTK_STYLE_CLASS_MENUBAR,
199 * #GTK_STYLE_CLASS_MENUITEM,
200 * #GTK_STYLE_CLASS_TOOLBAR,
201 * #GTK_STYLE_CLASS_PRIMARY_TOOLBAR,
202 * #GTK_STYLE_CLASS_INLINE_TOOLBAR,
203 * #GTK_STYLE_CLASS_RADIO,
204 * #GTK_STYLE_CLASS_CHECK,
205 * #GTK_STYLE_CLASS_TROUGH,
206 * #GTK_STYLE_CLASS_SCROLLBAR,
207 * #GTK_STYLE_CLASS_SCALE,
208 * #GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE,
209 * #GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW,
210 * #GTK_STYLE_CLASS_HEADER,
211 * #GTK_STYLE_CLASS_ACCELERATOR,
212 * #GTK_STYLE_CLASS_GRIP,
213 * #GTK_STYLE_CLASS_DOCK,
214 * #GTK_STYLE_CLASS_PROGRESSBAR,
215 * #GTK_STYLE_CLASS_SPINNER,
216 * #GTK_STYLE_CLASS_EXPANDER,
217 * #GTK_STYLE_CLASS_SPINBUTTON,
218 * #GTK_STYLE_CLASS_NOTEBOOK,
219 * #GTK_STYLE_CLASS_VIEW,
220 * #GTK_STYLE_CLASS_SIDEBAR,
221 * #GTK_STYLE_CLASS_IMAGE,
222 * #GTK_STYLE_CLASS_HIGHLIGHT,
223 * #GTK_STYLE_CLASS_FRAME,
224 * #GTK_STYLE_CLASS_DND,
225 * #GTK_STYLE_CLASS_PANE_SEPARATOR,
226 * #GTK_STYLE_CLASS_SEPARATOR,
227 * #GTK_STYLE_CLASS_INFO,
228 * #GTK_STYLE_CLASS_WARNING,
229 * #GTK_STYLE_CLASS_QUESTION,
230 * #GTK_STYLE_CLASS_ERROR,
231 * #GTK_STYLE_CLASS_HORIZONTAL,
232 * #GTK_STYLE_CLASS_VERTICAL,
233 * #GTK_STYLE_CLASS_TOP,
234 * #GTK_STYLE_CLASS_BOTTOM,
235 * #GTK_STYLE_CLASS_LEFT,
236 * #GTK_STYLE_CLASS_RIGHT,
239 * Widgets can also add regions with flags to their context.
240 * The regions used by GTK+ widgets are:
245 * <entry>Region</entry>
246 * <entry>Flags</entry>
247 * <entry>Macro</entry>
248 * <entry>Used by</entry>
254 * <entry>even, odd</entry>
255 * <entry>GTK_STYLE_REGION_ROW</entry>
256 * <entry>#GtkTreeView</entry>
259 * <entry>column</entry>
260 * <entry>first, last, sorted</entry>
261 * <entry>GTK_STYLE_REGION_COLUMN</entry>
262 * <entry>#GtkTreeView</entry>
265 * <entry>column-header</entry>
267 * <entry>GTK_STYLE_REGION_COLUMN_HEADER</entry>
272 * <entry>even, odd, first, last</entry>
273 * <entry>GTK_STYLE_REGION_TAB</entry>
274 * <entry>#GtkNotebook</entry>
281 * <refsect2 id="gtkstylecontext-custom-styling">
282 * <title>Custom styling in UI libraries and applications</title>
284 * If you are developing a library with custom #GtkWidget<!-- -->s that
285 * render differently than standard components, you may need to add a
286 * #GtkStyleProvider yourself with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK
287 * priority, either a #GtkCssProvider or a custom object implementing the
288 * #GtkStyleProvider interface. This way theming engines may still attempt
289 * to style your UI elements in a different way if needed so.
292 * If you are using custom styling on an applications, you probably want then
293 * to make your style information prevail to the theme's, so you must use
294 * a #GtkStyleProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
295 * priority, keep in mind that the user settings in
296 * <filename><replaceable>XDG_CONFIG_HOME</replaceable>/gtk-3.0/gtk.css</filename> will
297 * still take precedence over your changes, as it uses the
298 * %GTK_STYLE_PROVIDER_PRIORITY_USER priority.
301 * If a custom theming engine is needed, you probably want to implement a
302 * #GtkStyleProvider yourself so it points to your #GtkThemingEngine
303 * implementation, as #GtkCssProvider uses gtk_theming_engine_load()
304 * which loads the theming engine module from the standard paths.
309 /* When these change we do a full restyling. Otherwise we try to figure out
310 * if we need to change things. */
311 #define GTK_STYLE_CONTEXT_RADICAL_CHANGE (GTK_CSS_CHANGE_NAME | GTK_CSS_CHANGE_CLASS | GTK_CSS_CHANGE_SOURCE)
312 /* When these change we don't clear the cache. This takes more memory but makes
313 * things go faster. */
314 #define GTK_STYLE_CONTEXT_CACHED_CHANGE (GTK_CSS_CHANGE_STATE)
316 typedef struct GtkStyleInfo GtkStyleInfo;
317 typedef struct GtkRegion GtkRegion;
318 typedef struct PropertyValue PropertyValue;
319 typedef struct StyleData StyleData;
324 GtkRegionFlags flags;
338 GArray *style_classes;
340 GtkJunctionSides junction_sides;
341 GtkStateFlags state_flags;
347 GtkCssComputedValues *store;
348 GArray *property_cache;
352 struct _GtkStyleContextPrivate
356 GtkStyleCascade *cascade;
358 GtkStyleContext *animation_list_prev;
359 GtkStyleContext *animation_list_next;
361 GtkStyleContext *parent;
364 GtkWidgetPath *widget_path;
365 GHashTable *style_data;
368 GtkTextDirection direction;
370 GtkCssChange relevant_changes;
371 GtkCssChange pending_changes;
373 guint invalidating_context : 1;
389 static guint signals[LAST_SIGNAL] = { 0 };
390 static GtkStyleContext *_running_animations = NULL;
391 guint _running_animations_timer_id = 0;
393 static void gtk_style_context_finalize (GObject *object);
395 static void gtk_style_context_impl_set_property (GObject *object,
399 static void gtk_style_context_impl_get_property (GObject *object,
403 static StyleData *style_data_lookup (GtkStyleContext *context);
406 G_DEFINE_TYPE (GtkStyleContext, gtk_style_context, G_TYPE_OBJECT)
409 gtk_style_context_real_changed (GtkStyleContext *context)
411 GtkStyleContextPrivate *priv = context->priv;
414 _gtk_widget_style_context_invalidated (priv->widget);
418 gtk_style_context_class_init (GtkStyleContextClass *klass)
420 GObjectClass *object_class = G_OBJECT_CLASS (klass);
422 object_class->finalize = gtk_style_context_finalize;
423 object_class->set_property = gtk_style_context_impl_set_property;
424 object_class->get_property = gtk_style_context_impl_get_property;
426 klass->changed = gtk_style_context_real_changed;
429 g_signal_new (I_("changed"),
430 G_TYPE_FROM_CLASS (object_class),
432 G_STRUCT_OFFSET (GtkStyleContextClass, changed),
434 g_cclosure_marshal_VOID__VOID,
437 g_object_class_install_property (object_class,
439 g_param_spec_object ("screen",
441 P_("The associated GdkScreen"),
443 GTK_PARAM_READWRITE));
444 g_object_class_install_property (object_class,
446 g_param_spec_enum ("direction",
448 P_("Text direction"),
449 GTK_TYPE_TEXT_DIRECTION,
451 GTK_PARAM_READWRITE));
453 * GtkStyleContext:parent:
455 * Sets or gets the style context's parent. See gtk_style_context_set_parent()
460 g_object_class_install_property (object_class,
462 g_param_spec_object ("parent",
464 P_("The parent style context"),
465 GTK_TYPE_STYLE_CONTEXT,
466 GTK_PARAM_READWRITE));
468 g_type_class_add_private (object_class, sizeof (GtkStyleContextPrivate));
472 style_data_new (void)
476 data = g_slice_new0 (StyleData);
483 clear_property_cache (StyleData *data)
487 if (!data->property_cache)
490 for (i = 0; i < data->property_cache->len; i++)
492 PropertyValue *node = &g_array_index (data->property_cache, PropertyValue, i);
494 g_param_spec_unref (node->pspec);
495 g_value_unset (&node->value);
498 g_array_free (data->property_cache, TRUE);
499 data->property_cache = NULL;
503 style_data_ref (StyleData *style_data)
505 style_data->ref_count++;
511 style_data_unref (StyleData *data)
515 if (data->ref_count > 0)
518 g_object_unref (data->store);
519 clear_property_cache (data);
521 g_slice_free (StyleData, data);
525 style_data_is_animating (StyleData *style_data)
527 return !_gtk_css_computed_values_is_static (style_data->store);
530 static GtkStyleInfo *
531 style_info_new (void)
535 info = g_slice_new0 (GtkStyleInfo);
536 info->style_classes = g_array_new (FALSE, FALSE, sizeof (GQuark));
537 info->regions = g_array_new (FALSE, FALSE, sizeof (GtkRegion));
543 style_info_set_data (GtkStyleInfo *info,
546 if (info->data == data)
550 style_data_ref (data);
553 style_data_unref (info->data);
559 style_info_free (GtkStyleInfo *info)
561 style_info_set_data (info, NULL);
562 g_array_free (info->style_classes, TRUE);
563 g_array_free (info->regions, TRUE);
564 g_slice_free (GtkStyleInfo, info);
567 static GtkStyleInfo *
568 style_info_pop (GtkStyleInfo *info)
570 GtkStyleInfo *next = info->next;
572 style_info_free (info);
577 static GtkStyleInfo *
578 style_info_copy (GtkStyleInfo *info)
582 copy = style_info_new ();
583 g_array_insert_vals (copy->style_classes, 0,
584 info->style_classes->data,
585 info->style_classes->len);
587 g_array_insert_vals (copy->regions, 0,
592 copy->junction_sides = info->junction_sides;
593 copy->state_flags = info->state_flags;
594 style_info_set_data (copy, info->data);
600 style_info_hash (gconstpointer elem)
602 const GtkStyleInfo *info;
607 for (i = 0; i < info->style_classes->len; i++)
609 hash += g_array_index (info->style_classes, GQuark, i);
613 for (i = 0; i < info->regions->len; i++)
617 region = &g_array_index (info->regions, GtkRegion, i);
618 hash += region->class_quark;
619 hash += region->flags;
623 return hash ^ info->state_flags;
627 style_info_equal (gconstpointer elem1,
630 const GtkStyleInfo *info1, *info2;
635 if (info1->state_flags != info2->state_flags)
638 if (info1->junction_sides != info2->junction_sides)
641 if (info1->style_classes->len != info2->style_classes->len)
644 if (memcmp (info1->style_classes->data,
645 info2->style_classes->data,
646 info1->style_classes->len * sizeof (GQuark)) != 0)
649 if (info1->regions->len != info2->regions->len)
652 if (memcmp (info1->regions->data,
653 info2->regions->data,
654 info1->regions->len * sizeof (GtkRegion)) != 0)
661 gtk_style_context_cascade_changed (GtkStyleCascade *cascade,
662 GtkStyleContext *context)
664 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_SOURCE);
668 gtk_style_context_set_cascade (GtkStyleContext *context,
669 GtkStyleCascade *cascade)
671 GtkStyleContextPrivate *priv;
673 priv = context->priv;
675 if (priv->cascade == cascade)
680 g_object_ref (cascade);
681 g_signal_connect (cascade,
682 "-gtk-private-changed",
683 G_CALLBACK (gtk_style_context_cascade_changed),
689 g_signal_handlers_disconnect_by_func (priv->cascade,
690 gtk_style_context_cascade_changed,
692 g_object_unref (priv->cascade);
695 priv->cascade = cascade;
698 gtk_style_context_cascade_changed (cascade, context);
702 gtk_style_context_init (GtkStyleContext *style_context)
704 GtkStyleContextPrivate *priv;
706 priv = style_context->priv = G_TYPE_INSTANCE_GET_PRIVATE (style_context,
707 GTK_TYPE_STYLE_CONTEXT,
708 GtkStyleContextPrivate);
710 priv->style_data = g_hash_table_new_full (style_info_hash,
712 (GDestroyNotify) style_info_free,
713 (GDestroyNotify) style_data_unref);
715 priv->direction = GTK_TEXT_DIR_LTR;
717 priv->screen = gdk_screen_get_default ();
718 priv->relevant_changes = GTK_CSS_CHANGE_ANY;
720 /* Create default info store */
721 priv->info = style_info_new ();
723 gtk_style_context_set_cascade (style_context,
724 _gtk_style_cascade_get_for_screen (priv->screen));
728 gtk_style_context_do_animations (gpointer unused)
730 GtkStyleContext *context;
732 for (context = _running_animations;
734 context = context->priv->animation_list_next)
736 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANIMATE);
743 gtk_style_context_is_animating (GtkStyleContext *context)
745 GtkStyleContextPrivate *priv = context->priv;
747 return priv->animation_list_prev != NULL
748 || _running_animations == context;
752 gtk_style_context_stop_animating (GtkStyleContext *context)
754 GtkStyleContextPrivate *priv = context->priv;
756 if (!gtk_style_context_is_animating (context))
759 if (priv->animation_list_prev == NULL)
761 _running_animations = priv->animation_list_next;
763 if (_running_animations == NULL)
765 /* we were the last animation */
766 g_source_remove (_running_animations_timer_id);
767 _running_animations_timer_id = 0;
771 priv->animation_list_prev->priv->animation_list_next = priv->animation_list_next;
773 if (priv->animation_list_next)
774 priv->animation_list_next->priv->animation_list_prev = priv->animation_list_prev;
776 priv->animation_list_next = NULL;
777 priv->animation_list_prev = NULL;
781 gtk_style_context_start_animating (GtkStyleContext *context)
783 GtkStyleContextPrivate *priv = context->priv;
785 if (gtk_style_context_is_animating (context))
788 if (_running_animations == NULL)
790 _running_animations_timer_id = gdk_threads_add_timeout (25,
791 gtk_style_context_do_animations,
793 _running_animations = context;
797 priv->animation_list_next = _running_animations;
798 _running_animations->priv->animation_list_prev = context;
799 _running_animations = context;
804 gtk_style_context_should_animate (GtkStyleContext *context)
806 GtkStyleContextPrivate *priv;
810 priv = context->priv;
812 if (priv->widget == NULL)
815 if (!gtk_widget_get_mapped (priv->widget))
818 data = style_data_lookup (context);
819 if (!style_data_is_animating (data))
822 g_object_get (gtk_widget_get_settings (context->priv->widget),
823 "gtk-enable-animations", &animate,
830 _gtk_style_context_update_animating (GtkStyleContext *context)
832 if (gtk_style_context_should_animate (context))
833 gtk_style_context_start_animating (context);
835 gtk_style_context_stop_animating (context);
839 gtk_style_context_finalize (GObject *object)
841 GtkStyleContextPrivate *priv;
842 GtkStyleContext *style_context;
844 style_context = GTK_STYLE_CONTEXT (object);
845 priv = style_context->priv;
847 gtk_style_context_stop_animating (style_context);
849 /* children hold a reference to us */
850 g_assert (priv->children == NULL);
852 gtk_style_context_set_parent (style_context, NULL);
854 gtk_style_context_set_cascade (style_context, NULL);
856 if (priv->widget_path)
857 gtk_widget_path_free (priv->widget_path);
859 g_hash_table_destroy (priv->style_data);
862 priv->info = style_info_pop (priv->info);
864 G_OBJECT_CLASS (gtk_style_context_parent_class)->finalize (object);
868 gtk_style_context_impl_set_property (GObject *object,
873 GtkStyleContext *style_context;
875 style_context = GTK_STYLE_CONTEXT (object);
880 gtk_style_context_set_screen (style_context,
881 g_value_get_object (value));
884 gtk_style_context_set_direction (style_context,
885 g_value_get_enum (value));
888 gtk_style_context_set_parent (style_context,
889 g_value_get_object (value));
892 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
898 gtk_style_context_impl_get_property (GObject *object,
903 GtkStyleContext *style_context;
904 GtkStyleContextPrivate *priv;
906 style_context = GTK_STYLE_CONTEXT (object);
907 priv = style_context->priv;
912 g_value_set_object (value, priv->screen);
915 g_value_set_enum (value, priv->direction);
918 g_value_set_object (value, priv->parent);
921 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
926 static GtkWidgetPath *
927 create_query_path (GtkStyleContext *context,
930 GtkStyleContextPrivate *priv;
934 priv = context->priv;
935 path = priv->widget ? _gtk_widget_create_path (priv->widget) : gtk_widget_path_copy (priv->widget_path);
936 pos = gtk_widget_path_length (path) - 1;
938 /* Set widget regions */
939 for (i = 0; i < info->regions->len; i++)
943 region = &g_array_index (info->regions, GtkRegion, i);
944 gtk_widget_path_iter_add_region (path, pos,
945 g_quark_to_string (region->class_quark),
949 /* Set widget classes */
950 for (i = 0; i < info->style_classes->len; i++)
954 quark = g_array_index (info->style_classes, GQuark, i);
955 gtk_widget_path_iter_add_class (path, pos,
956 g_quark_to_string (quark));
963 build_properties (GtkStyleContext *context,
964 GtkCssComputedValues *values,
966 const GtkBitmask *relevant_changes)
968 GtkStyleContextPrivate *priv;
969 GtkCssMatcher matcher;
971 GtkCssLookup *lookup;
973 priv = context->priv;
975 path = create_query_path (context, info);
976 lookup = _gtk_css_lookup_new (relevant_changes);
978 if (_gtk_css_matcher_init (&matcher, path, info->state_flags))
979 _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
983 _gtk_css_lookup_resolve (lookup,
984 GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
986 priv->parent ? style_data_lookup (priv->parent)->store : NULL);
988 _gtk_css_lookup_free (lookup);
989 gtk_widget_path_free (path);
993 style_data_lookup (GtkStyleContext *context)
995 GtkStyleContextPrivate *priv;
999 priv = context->priv;
1002 /* Current data in use is cached, just return it */
1006 g_assert (priv->widget != NULL || priv->widget_path != NULL);
1008 data = g_hash_table_lookup (priv->style_data, info);
1011 style_info_set_data (info, data);
1015 data = style_data_new ();
1016 data->store = _gtk_css_computed_values_new ();
1017 style_info_set_data (info, data);
1018 g_hash_table_insert (priv->style_data,
1019 style_info_copy (info),
1022 build_properties (context, data->store, info, NULL);
1028 style_data_lookup_for_state (GtkStyleContext *context,
1029 GtkStateFlags state)
1033 if (context->priv->info->state_flags == state)
1034 return style_data_lookup (context);
1036 gtk_style_context_save (context);
1037 gtk_style_context_set_state (context, state);
1038 data = style_data_lookup (context);
1039 gtk_style_context_restore (context);
1045 gtk_style_context_set_invalid (GtkStyleContext *context,
1048 GtkStyleContextPrivate *priv;
1050 priv = context->priv;
1052 if (priv->invalid == invalid)
1055 priv->invalid = invalid;
1060 gtk_style_context_set_invalid (priv->parent, TRUE);
1061 else if (GTK_IS_RESIZE_CONTAINER (priv->widget))
1062 _gtk_container_queue_restyle (GTK_CONTAINER (priv->widget));
1066 /* returns TRUE if someone called gtk_style_context_save() but hasn't
1067 * called gtk_style_context_restore() yet.
1068 * In those situations we don't invalidate the context when somebody
1069 * changes state/regions/classes.
1072 gtk_style_context_is_saved (GtkStyleContext *context)
1074 return context->priv->info->next != NULL;
1078 gtk_style_context_queue_invalidate_internal (GtkStyleContext *context,
1079 GtkCssChange change)
1081 GtkStyleContextPrivate *priv = context->priv;
1082 GtkStyleInfo *info = priv->info;
1084 if (gtk_style_context_is_saved (context))
1086 style_info_set_data (info, NULL);
1090 _gtk_style_context_queue_invalidate (context, change);
1091 /* XXX: We need to invalidate siblings here somehow */
1096 * gtk_style_context_new:
1098 * Creates a standalone #GtkStyleContext, this style context
1099 * won't be attached to any widget, so you may want
1100 * to call gtk_style_context_set_path() yourself.
1103 * This function is only useful when using the theming layer
1104 * separated from GTK+, if you are using #GtkStyleContext to
1105 * theme #GtkWidget<!-- -->s, use gtk_widget_get_style_context()
1106 * in order to get a style context ready to theme the widget.
1109 * Returns: A newly created #GtkStyleContext.
1112 gtk_style_context_new (void)
1114 return g_object_new (GTK_TYPE_STYLE_CONTEXT, NULL);
1118 _gtk_style_context_set_widget (GtkStyleContext *context,
1121 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1122 g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget));
1124 context->priv->widget = widget;
1126 _gtk_style_context_update_animating (context);
1128 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY_SELF);
1132 * gtk_style_context_add_provider:
1133 * @context: a #GtkStyleContext
1134 * @provider: a #GtkStyleProvider
1135 * @priority: the priority of the style provider. The lower
1136 * it is, the earlier it will be used in the style
1137 * construction. Typically this will be in the range
1138 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1139 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1141 * Adds a style provider to @context, to be used in style construction.
1142 * Note that a style provider added by this function only affects
1143 * the style of the widget to which @context belongs. If you want
1144 * to affect the style of all widgets, use
1145 * gtk_style_context_add_provider_for_screen().
1147 * <note><para>If both priorities are the same, A #GtkStyleProvider
1148 * added through this function takes precedence over another added
1149 * through gtk_style_context_add_provider_for_screen().</para></note>
1154 gtk_style_context_add_provider (GtkStyleContext *context,
1155 GtkStyleProvider *provider,
1158 GtkStyleContextPrivate *priv;
1160 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1161 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1163 priv = context->priv;
1165 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
1167 GtkStyleCascade *new_cascade;
1169 new_cascade = _gtk_style_cascade_new ();
1170 _gtk_style_cascade_set_parent (new_cascade, priv->cascade);
1171 _gtk_style_cascade_add_provider (new_cascade, provider, priority);
1172 gtk_style_context_set_cascade (context, new_cascade);
1173 g_object_unref (new_cascade);
1177 _gtk_style_cascade_add_provider (priv->cascade, provider, priority);
1182 * gtk_style_context_remove_provider:
1183 * @context: a #GtkStyleContext
1184 * @provider: a #GtkStyleProvider
1186 * Removes @provider from the style providers list in @context.
1191 gtk_style_context_remove_provider (GtkStyleContext *context,
1192 GtkStyleProvider *provider)
1194 GtkStyleContextPrivate *priv;
1196 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1197 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1199 priv = context->priv;
1201 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
1204 _gtk_style_cascade_remove_provider (priv->cascade, provider);
1208 * gtk_style_context_reset_widgets:
1209 * @screen: a #GdkScreen
1211 * This function recomputes the styles for all widgets under a particular
1212 * #GdkScreen. This is useful when some global parameter has changed that
1213 * affects the appearance of all widgets, because when a widget gets a new
1214 * style, it will both redraw and recompute any cached information about
1215 * its appearance. As an example, it is used when the color scheme changes
1216 * in the related #GtkSettings object.
1221 gtk_style_context_reset_widgets (GdkScreen *screen)
1223 GList *list, *toplevels;
1225 _gtk_icon_set_invalidate_caches ();
1227 toplevels = gtk_window_list_toplevels ();
1228 g_list_foreach (toplevels, (GFunc) g_object_ref, NULL);
1230 for (list = toplevels; list; list = list->next)
1232 if (gtk_widget_get_screen (list->data) == screen)
1233 gtk_widget_reset_style (list->data);
1235 g_object_unref (list->data);
1238 g_list_free (toplevels);
1242 * gtk_style_context_add_provider_for_screen:
1243 * @screen: a #GdkScreen
1244 * @provider: a #GtkStyleProvider
1245 * @priority: the priority of the style provider. The lower
1246 * it is, the earlier it will be used in the style
1247 * construction. Typically this will be in the range
1248 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1249 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1251 * Adds a global style provider to @screen, which will be used
1252 * in style construction for all #GtkStyleContexts under @screen.
1254 * GTK+ uses this to make styling information from #GtkSettings
1257 * <note><para>If both priorities are the same, A #GtkStyleProvider
1258 * added through gtk_style_context_add_provider() takes precedence
1259 * over another added through this function.</para></note>
1264 gtk_style_context_add_provider_for_screen (GdkScreen *screen,
1265 GtkStyleProvider *provider,
1268 GtkStyleCascade *cascade;
1270 g_return_if_fail (GDK_IS_SCREEN (screen));
1271 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1272 g_return_if_fail (!GTK_IS_SETTINGS (provider) || _gtk_settings_get_screen (GTK_SETTINGS (provider)) == screen);
1274 cascade = _gtk_style_cascade_get_for_screen (screen);
1275 _gtk_style_cascade_add_provider (cascade, provider, priority);
1279 * gtk_style_context_remove_provider_for_screen:
1280 * @screen: a #GdkScreen
1281 * @provider: a #GtkStyleProvider
1283 * Removes @provider from the global style providers list in @screen.
1288 gtk_style_context_remove_provider_for_screen (GdkScreen *screen,
1289 GtkStyleProvider *provider)
1291 GtkStyleCascade *cascade;
1293 g_return_if_fail (GDK_IS_SCREEN (screen));
1294 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1295 g_return_if_fail (!GTK_IS_SETTINGS (provider));
1297 cascade = _gtk_style_cascade_get_for_screen (screen);
1298 _gtk_style_cascade_remove_provider (cascade, provider);
1302 * gtk_style_context_get_section:
1303 * @context: a #GtkStyleContext
1304 * @property: style property name
1306 * Queries the location in the CSS where @property was defined for the
1307 * current @context. Note that the state to be queried is taken from
1308 * gtk_style_context_get_state().
1310 * If the location is not available, %NULL will be returned. The
1311 * location might not be available for various reasons, such as the
1312 * property being overridden, @property not naming a supported CSS
1313 * property or tracking of definitions being disabled for performance
1316 * Shorthand CSS properties cannot be queried for a location and will
1317 * always return %NULL.
1319 * Returns: %NULL or the section where value was defined
1322 gtk_style_context_get_section (GtkStyleContext *context,
1323 const gchar *property)
1325 GtkStyleContextPrivate *priv;
1326 GtkStyleProperty *prop;
1329 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1330 g_return_val_if_fail (property != NULL, NULL);
1332 priv = context->priv;
1333 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
1335 prop = _gtk_style_property_lookup (property);
1336 if (!GTK_IS_CSS_STYLE_PROPERTY (prop))
1339 data = style_data_lookup (context);
1340 return _gtk_css_computed_values_get_section (data->store, _gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (prop)));
1343 static GtkCssValue *
1344 gtk_style_context_query_func (guint id,
1347 return _gtk_css_computed_values_get_value (values, id);
1351 * gtk_style_context_get_property:
1352 * @context: a #GtkStyleContext
1353 * @property: style property name
1354 * @state: state to retrieve the property value for
1355 * @value: (out) (transfer full): return location for the style property value
1357 * Gets a style property from @context for the given state.
1359 * When @value is no longer needed, g_value_unset() must be called
1360 * to free any allocated memory.
1365 gtk_style_context_get_property (GtkStyleContext *context,
1366 const gchar *property,
1367 GtkStateFlags state,
1370 GtkStyleContextPrivate *priv;
1371 GtkStyleProperty *prop;
1374 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1375 g_return_if_fail (property != NULL);
1376 g_return_if_fail (value != NULL);
1378 priv = context->priv;
1379 g_return_if_fail (priv->widget != NULL || priv->widget_path != NULL);
1381 prop = _gtk_style_property_lookup (property);
1384 g_warning ("Style property \"%s\" is not registered", property);
1387 if (_gtk_style_property_get_value_type (prop) == G_TYPE_NONE)
1389 g_warning ("Style property \"%s\" is not gettable", property);
1393 data = style_data_lookup_for_state (context, state);
1394 _gtk_style_property_query (prop, value, gtk_style_context_query_func, data->store);
1398 * gtk_style_context_get_valist:
1399 * @context: a #GtkStyleContext
1400 * @state: state to retrieve the property values for
1401 * @args: va_list of property name/return location pairs, followed by %NULL
1403 * Retrieves several style property values from @context for a given state.
1408 gtk_style_context_get_valist (GtkStyleContext *context,
1409 GtkStateFlags state,
1412 const gchar *property_name;
1414 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1416 property_name = va_arg (args, const gchar *);
1418 while (property_name)
1420 gchar *error = NULL;
1421 GValue value = G_VALUE_INIT;
1423 gtk_style_context_get_property (context,
1428 G_VALUE_LCOPY (&value, args, 0, &error);
1429 g_value_unset (&value);
1433 g_warning ("Could not get style property \"%s\": %s", property_name, error);
1438 property_name = va_arg (args, const gchar *);
1443 * gtk_style_context_get:
1444 * @context: a #GtkStyleContext
1445 * @state: state to retrieve the property values for
1446 * @...: property name /return value pairs, followed by %NULL
1448 * Retrieves several style property values from @context for a
1454 gtk_style_context_get (GtkStyleContext *context,
1455 GtkStateFlags state,
1460 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1462 va_start (args, state);
1463 gtk_style_context_get_valist (context, state, args);
1468 * gtk_style_context_set_state:
1469 * @context: a #GtkStyleContext
1470 * @flags: state to represent
1472 * Sets the state to be used when rendering with any
1473 * of the gtk_render_*() functions.
1478 gtk_style_context_set_state (GtkStyleContext *context,
1479 GtkStateFlags flags)
1481 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1483 context->priv->info->state_flags = flags;
1485 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_STATE);
1489 * gtk_style_context_get_state:
1490 * @context: a #GtkStyleContext
1492 * Returns the state used when rendering.
1494 * Returns: the state flags
1499 gtk_style_context_get_state (GtkStyleContext *context)
1501 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
1503 return context->priv->info->state_flags;
1507 * gtk_style_context_state_is_running:
1508 * @context: a #GtkStyleContext
1509 * @state: a widget state
1510 * @progress: (out): return location for the transition progress
1512 * Returns %TRUE if there is a transition animation running for the
1513 * current region (see gtk_style_context_push_animatable_region()).
1515 * If @progress is not %NULL, the animation progress will be returned
1516 * there, 0.0 means the state is closest to being unset, while 1.0 means
1517 * it's closest to being set. This means transition animation will
1518 * run from 0 to 1 when @state is being set and from 1 to 0 when
1521 * Returns: %TRUE if there is a running transition animation for @state.
1525 * Deprecated: 3.6: This function always returns %FALSE
1528 gtk_style_context_state_is_running (GtkStyleContext *context,
1532 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1538 * gtk_style_context_set_path:
1539 * @context: a #GtkStyleContext
1540 * @path: a #GtkWidgetPath
1542 * Sets the #GtkWidgetPath used for style matching. As a
1543 * consequence, the style will be regenerated to match
1544 * the new given path.
1546 * If you are using a #GtkStyleContext returned from
1547 * gtk_widget_get_style_context(), you do not need to call
1553 gtk_style_context_set_path (GtkStyleContext *context,
1554 GtkWidgetPath *path)
1556 GtkStyleContextPrivate *priv;
1558 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1559 g_return_if_fail (path != NULL);
1561 priv = context->priv;
1562 g_return_if_fail (priv->widget == NULL);
1564 if (priv->widget_path)
1566 gtk_widget_path_free (priv->widget_path);
1567 priv->widget_path = NULL;
1571 priv->widget_path = gtk_widget_path_copy (path);
1573 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY);
1577 * gtk_style_context_get_path:
1578 * @context: a #GtkStyleContext
1580 * Returns the widget path used for style matching.
1582 * Returns: (transfer none): A #GtkWidgetPath
1586 const GtkWidgetPath *
1587 gtk_style_context_get_path (GtkStyleContext *context)
1589 GtkStyleContextPrivate *priv;
1591 priv = context->priv;
1593 return gtk_widget_get_path (priv->widget);
1595 return priv->widget_path;
1599 * gtk_style_context_set_parent:
1600 * @context: a #GtkStyleContext
1601 * @parent: (allow-none): the new parent or %NULL
1603 * Sets the parent style context for @context. The parent style
1604 * context is used to implement
1605 * <ulink url="http://www.w3.org/TR/css3-cascade/#inheritance">inheritance</ulink>
1608 * If you are using a #GtkStyleContext returned from
1609 * gtk_widget_get_style_context(), the parent will be set for you.
1614 gtk_style_context_set_parent (GtkStyleContext *context,
1615 GtkStyleContext *parent)
1617 GtkStyleContextPrivate *priv;
1619 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1620 g_return_if_fail (parent == NULL || GTK_IS_STYLE_CONTEXT (parent));
1622 priv = context->priv;
1624 if (priv->parent == parent)
1629 parent->priv->children = g_slist_prepend (parent->priv->children, context);
1630 g_object_ref (parent);
1632 gtk_style_context_set_invalid (parent, TRUE);
1637 priv->parent->priv->children = g_slist_remove (priv->parent->priv->children, context);
1638 g_object_unref (priv->parent);
1641 priv->parent = parent;
1643 g_object_notify (G_OBJECT (context), "parent");
1644 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY_PARENT | GTK_CSS_CHANGE_ANY_SIBLING);
1648 * gtk_style_context_get_parent:
1649 * @context: a #GtkStyleContext
1651 * Gets the parent context set via gtk_style_context_set_parent().
1652 * See that function for details.
1654 * Returns: (transfer none): the parent context or %NULL
1659 gtk_style_context_get_parent (GtkStyleContext *context)
1661 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1663 return context->priv->parent;
1667 * gtk_style_context_save:
1668 * @context: a #GtkStyleContext
1670 * Saves the @context state, so all modifications done through
1671 * gtk_style_context_add_class(), gtk_style_context_remove_class(),
1672 * gtk_style_context_add_region(), gtk_style_context_remove_region()
1673 * or gtk_style_context_set_junction_sides() can be reverted in one
1674 * go through gtk_style_context_restore().
1679 gtk_style_context_save (GtkStyleContext *context)
1681 GtkStyleContextPrivate *priv;
1683 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1685 priv = context->priv;
1687 priv->info = style_info_copy (priv->info);
1688 /* Need to unset animations here because we can not know what style
1689 * class potential transitions came from once we save().
1691 if (priv->info->data && style_data_is_animating (priv->info->data))
1692 style_info_set_data (priv->info, NULL);
1696 * gtk_style_context_restore:
1697 * @context: a #GtkStyleContext
1699 * Restores @context state to a previous stage.
1700 * See gtk_style_context_save().
1705 gtk_style_context_restore (GtkStyleContext *context)
1707 GtkStyleContextPrivate *priv;
1709 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1711 priv = context->priv;
1713 priv->info = style_info_pop (priv->info);
1717 g_warning ("Unpaired gtk_style_context_restore() call");
1719 /* Create default region */
1720 priv->info = style_info_new ();
1725 style_class_find (GArray *array,
1730 gboolean found = FALSE;
1736 if (!array || array->len == 0)
1740 max = array->len - 1;
1746 mid = (min + max) / 2;
1747 item = g_array_index (array, GQuark, mid);
1749 if (class_quark == item)
1754 else if (class_quark > item)
1755 min = pos = mid + 1;
1762 while (!found && min <= max);
1771 region_find (GArray *array,
1776 gboolean found = FALSE;
1782 if (!array || array->len == 0)
1786 max = array->len - 1;
1792 mid = (min + max) / 2;
1793 region = &g_array_index (array, GtkRegion, mid);
1795 if (region->class_quark == class_quark)
1800 else if (region->class_quark > class_quark)
1801 min = pos = mid + 1;
1808 while (!found && min <= max);
1817 * gtk_style_context_add_class:
1818 * @context: a #GtkStyleContext
1819 * @class_name: class name to use in styling
1821 * Adds a style class to @context, so posterior calls to
1822 * gtk_style_context_get() or any of the gtk_render_*()
1823 * functions will make use of this new class for styling.
1825 * In the CSS file format, a #GtkEntry defining an "entry"
1826 * class, would be matched by:
1829 * GtkEntry.entry { ... }
1832 * While any widget defining an "entry" class would be
1841 gtk_style_context_add_class (GtkStyleContext *context,
1842 const gchar *class_name)
1844 GtkStyleContextPrivate *priv;
1849 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1850 g_return_if_fail (class_name != NULL);
1852 priv = context->priv;
1853 class_quark = g_quark_from_string (class_name);
1857 if (!style_class_find (info->style_classes, class_quark, &position))
1859 g_array_insert_val (info->style_classes, position, class_quark);
1861 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_CLASS);
1866 * gtk_style_context_remove_class:
1867 * @context: a #GtkStyleContext
1868 * @class_name: class name to remove
1870 * Removes @class_name from @context.
1875 gtk_style_context_remove_class (GtkStyleContext *context,
1876 const gchar *class_name)
1878 GtkStyleContextPrivate *priv;
1883 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1884 g_return_if_fail (class_name != NULL);
1886 class_quark = g_quark_try_string (class_name);
1891 priv = context->priv;
1895 if (style_class_find (info->style_classes, class_quark, &position))
1897 g_array_remove_index (info->style_classes, position);
1899 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_CLASS);
1904 * gtk_style_context_has_class:
1905 * @context: a #GtkStyleContext
1906 * @class_name: a class name
1908 * Returns %TRUE if @context currently has defined the
1911 * Returns: %TRUE if @context has @class_name defined
1916 gtk_style_context_has_class (GtkStyleContext *context,
1917 const gchar *class_name)
1919 GtkStyleContextPrivate *priv;
1923 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1924 g_return_val_if_fail (class_name != NULL, FALSE);
1926 class_quark = g_quark_try_string (class_name);
1931 priv = context->priv;
1935 if (style_class_find (info->style_classes, class_quark, NULL))
1942 * gtk_style_context_list_classes:
1943 * @context: a #GtkStyleContext
1945 * Returns the list of classes currently defined in @context.
1947 * Returns: (transfer container) (element-type utf8): a #GList of
1948 * strings with the currently defined classes. The contents
1949 * of the list are owned by GTK+, but you must free the list
1950 * itself with g_list_free() when you are done with it.
1955 gtk_style_context_list_classes (GtkStyleContext *context)
1957 GtkStyleContextPrivate *priv;
1959 GList *classes = NULL;
1962 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1964 priv = context->priv;
1968 for (i = 0; i < info->style_classes->len; i++)
1972 quark = g_array_index (info->style_classes, GQuark, i);
1973 classes = g_list_prepend (classes, (gchar *) g_quark_to_string (quark));
1980 * gtk_style_context_list_regions:
1981 * @context: a #GtkStyleContext
1983 * Returns the list of regions currently defined in @context.
1985 * Returns: (transfer container) (element-type utf8): a #GList of
1986 * strings with the currently defined regions. The contents
1987 * of the list are owned by GTK+, but you must free the list
1988 * itself with g_list_free() when you are done with it.
1993 gtk_style_context_list_regions (GtkStyleContext *context)
1995 GtkStyleContextPrivate *priv;
1997 GList *classes = NULL;
2000 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2002 priv = context->priv;
2006 for (i = 0; i < info->regions->len; i++)
2009 const gchar *class_name;
2011 region = &g_array_index (info->regions, GtkRegion, i);
2013 class_name = g_quark_to_string (region->class_quark);
2014 classes = g_list_prepend (classes, (gchar *) class_name);
2021 _gtk_style_context_check_region_name (const gchar *str)
2023 g_return_val_if_fail (str != NULL, FALSE);
2025 if (!g_ascii_islower (str[0]))
2031 !g_ascii_islower (*str))
2041 * gtk_style_context_add_region:
2042 * @context: a #GtkStyleContext
2043 * @region_name: region name to use in styling
2044 * @flags: flags that apply to the region
2046 * Adds a region to @context, so posterior calls to
2047 * gtk_style_context_get() or any of the gtk_render_*()
2048 * functions will make use of this new region for styling.
2050 * In the CSS file format, a #GtkTreeView defining a "row"
2051 * region, would be matched by:
2054 * GtkTreeView row { ... }
2057 * Pseudo-classes are used for matching @flags, so the two
2060 * GtkTreeView row:nth-child(even) { ... }
2061 * GtkTreeView row:nth-child(odd) { ... }
2064 * would apply to even and odd rows, respectively.
2066 * <note><para>Region names must only contain lowercase letters
2067 * and '-', starting always with a lowercase letter.</para></note>
2072 gtk_style_context_add_region (GtkStyleContext *context,
2073 const gchar *region_name,
2074 GtkRegionFlags flags)
2076 GtkStyleContextPrivate *priv;
2078 GQuark region_quark;
2081 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2082 g_return_if_fail (region_name != NULL);
2083 g_return_if_fail (_gtk_style_context_check_region_name (region_name));
2085 priv = context->priv;
2086 region_quark = g_quark_from_string (region_name);
2090 if (!region_find (info->regions, region_quark, &position))
2094 region.class_quark = region_quark;
2095 region.flags = flags;
2097 g_array_insert_val (info->regions, position, region);
2099 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_REGION);
2104 * gtk_style_context_remove_region:
2105 * @context: a #GtkStyleContext
2106 * @region_name: region name to unset
2108 * Removes a region from @context.
2113 gtk_style_context_remove_region (GtkStyleContext *context,
2114 const gchar *region_name)
2116 GtkStyleContextPrivate *priv;
2118 GQuark region_quark;
2121 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2122 g_return_if_fail (region_name != NULL);
2124 region_quark = g_quark_try_string (region_name);
2129 priv = context->priv;
2133 if (region_find (info->regions, region_quark, &position))
2135 g_array_remove_index (info->regions, position);
2137 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_REGION);
2142 * gtk_style_context_has_region:
2143 * @context: a #GtkStyleContext
2144 * @region_name: a region name
2145 * @flags_return: (out) (allow-none): return location for region flags
2147 * Returns %TRUE if @context has the region defined.
2148 * If @flags_return is not %NULL, it is set to the flags
2149 * affecting the region.
2151 * Returns: %TRUE if region is defined
2156 gtk_style_context_has_region (GtkStyleContext *context,
2157 const gchar *region_name,
2158 GtkRegionFlags *flags_return)
2160 GtkStyleContextPrivate *priv;
2162 GQuark region_quark;
2165 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2166 g_return_val_if_fail (region_name != NULL, FALSE);
2171 region_quark = g_quark_try_string (region_name);
2176 priv = context->priv;
2180 if (region_find (info->regions, region_quark, &position))
2186 region = &g_array_index (info->regions, GtkRegion, position);
2187 *flags_return = region->flags;
2196 style_property_values_cmp (gconstpointer bsearch_node1,
2197 gconstpointer bsearch_node2)
2199 const PropertyValue *val1 = bsearch_node1;
2200 const PropertyValue *val2 = bsearch_node2;
2202 if (val1->widget_type != val2->widget_type)
2203 return val1->widget_type < val2->widget_type ? -1 : 1;
2205 if (val1->pspec != val2->pspec)
2206 return val1->pspec < val2->pspec ? -1 : 1;
2208 if (val1->state != val2->state)
2209 return val1->state < val2->state ? -1 : 1;
2215 _gtk_style_context_peek_property (GtkStyleContext *context,
2218 StyleData *data = style_data_lookup (context);
2220 return _gtk_css_computed_values_get_value (data->store, property_id);
2224 _gtk_style_context_get_number (GtkStyleContext *context,
2226 double one_hundred_percent)
2230 value = _gtk_style_context_peek_property (context, property_id);
2231 return _gtk_css_number_value_get (value, one_hundred_percent);
2235 _gtk_style_context_peek_style_property (GtkStyleContext *context,
2237 GtkStateFlags state,
2240 GtkStyleContextPrivate *priv;
2241 PropertyValue *pcache, key = { 0 };
2245 priv = context->priv;
2247 data = style_data_lookup_for_state (context, state);
2249 key.widget_type = widget_type;
2253 /* need value cache array */
2254 if (!data->property_cache)
2255 data->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
2258 pcache = bsearch (&key,
2259 data->property_cache->data, data->property_cache->len,
2260 sizeof (PropertyValue), style_property_values_cmp);
2262 return &pcache->value;
2266 while (i < data->property_cache->len &&
2267 style_property_values_cmp (&key, &g_array_index (data->property_cache, PropertyValue, i)) >= 0)
2270 g_array_insert_val (data->property_cache, i, key);
2271 pcache = &g_array_index (data->property_cache, PropertyValue, i);
2273 /* cache miss, initialize value type, then set contents */
2274 g_param_spec_ref (pcache->pspec);
2275 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2277 if (priv->widget || priv->widget_path)
2279 GtkWidgetPath *widget_path = priv->widget ? _gtk_widget_create_path (priv->widget) : priv->widget_path;
2281 if (gtk_style_provider_get_style_property (GTK_STYLE_PROVIDER (priv->cascade),
2283 state, pspec, &pcache->value))
2285 /* Resolve symbolic colors to GdkColor/GdkRGBA */
2286 if (G_VALUE_TYPE (&pcache->value) == GTK_TYPE_SYMBOLIC_COLOR)
2288 GtkSymbolicColor *color;
2291 color = g_value_dup_boxed (&pcache->value);
2293 g_value_unset (&pcache->value);
2295 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2296 g_value_init (&pcache->value, GDK_TYPE_RGBA);
2298 g_value_init (&pcache->value, GDK_TYPE_COLOR);
2300 if (_gtk_style_context_resolve_color (context, color, &rgba, NULL))
2302 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2303 g_value_set_boxed (&pcache->value, &rgba);
2308 rgb.red = rgba.red * 65535. + 0.5;
2309 rgb.green = rgba.green * 65535. + 0.5;
2310 rgb.blue = rgba.blue * 65535. + 0.5;
2312 g_value_set_boxed (&pcache->value, &rgb);
2316 g_param_value_set_default (pspec, &pcache->value);
2318 gtk_symbolic_color_unref (color);
2322 gtk_widget_path_free (widget_path);
2324 return &pcache->value;
2328 gtk_widget_path_free (widget_path);
2331 /* not supplied by any provider, revert to default */
2332 g_param_value_set_default (pspec, &pcache->value);
2334 return &pcache->value;
2338 * gtk_style_context_get_style_property:
2339 * @context: a #GtkStyleContext
2340 * @property_name: the name of the widget style property
2341 * @value: Return location for the property value
2343 * Gets the value for a widget style property.
2345 * When @value is no longer needed, g_value_unset() must be called
2346 * to free any allocated memory.
2349 gtk_style_context_get_style_property (GtkStyleContext *context,
2350 const gchar *property_name,
2353 GtkStyleContextPrivate *priv;
2354 GtkWidgetClass *widget_class;
2355 GtkStateFlags state;
2357 const GValue *peek_value;
2360 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2361 g_return_if_fail (property_name != NULL);
2362 g_return_if_fail (value != NULL);
2364 priv = context->priv;
2368 widget_type = G_OBJECT_TYPE (priv->widget);
2372 if (!priv->widget_path)
2375 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2377 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2379 g_warning ("%s: can't get style properties for non-widget class `%s'",
2381 g_type_name (widget_type));
2386 widget_class = g_type_class_ref (widget_type);
2387 pspec = gtk_widget_class_find_style_property (widget_class, property_name);
2388 g_type_class_unref (widget_class);
2392 g_warning ("%s: widget class `%s' has no style property named `%s'",
2394 g_type_name (widget_type),
2399 state = gtk_style_context_get_state (context);
2400 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2403 if (G_VALUE_TYPE (value) == G_VALUE_TYPE (peek_value))
2404 g_value_copy (peek_value, value);
2405 else if (g_value_type_transformable (G_VALUE_TYPE (peek_value), G_VALUE_TYPE (value)))
2406 g_value_transform (peek_value, value);
2408 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
2410 G_VALUE_TYPE_NAME (peek_value),
2411 G_VALUE_TYPE_NAME (value));
2415 * gtk_style_context_get_style_valist:
2416 * @context: a #GtkStyleContext
2417 * @args: va_list of property name/return location pairs, followed by %NULL
2419 * Retrieves several widget style properties from @context according to the
2425 gtk_style_context_get_style_valist (GtkStyleContext *context,
2428 GtkStyleContextPrivate *priv;
2429 const gchar *prop_name;
2430 GtkStateFlags state;
2433 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2435 prop_name = va_arg (args, const gchar *);
2436 priv = context->priv;
2440 widget_type = G_OBJECT_TYPE (priv->widget);
2444 if (!priv->widget_path)
2447 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2449 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2451 g_warning ("%s: can't get style properties for non-widget class `%s'",
2453 g_type_name (widget_type));
2458 state = gtk_style_context_get_state (context);
2462 GtkWidgetClass *widget_class;
2464 const GValue *peek_value;
2467 widget_class = g_type_class_ref (widget_type);
2468 pspec = gtk_widget_class_find_style_property (widget_class, prop_name);
2469 g_type_class_unref (widget_class);
2473 g_warning ("%s: widget class `%s' has no style property named `%s'",
2475 g_type_name (widget_type),
2480 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2483 G_VALUE_LCOPY (peek_value, args, 0, &error);
2487 g_warning ("can't retrieve style property `%s' of type `%s': %s",
2489 G_VALUE_TYPE_NAME (peek_value),
2495 prop_name = va_arg (args, const gchar *);
2500 * gtk_style_context_get_style:
2501 * @context: a #GtkStyleContext
2502 * @...: property name /return value pairs, followed by %NULL
2504 * Retrieves several widget style properties from @context according to the
2510 gtk_style_context_get_style (GtkStyleContext *context,
2515 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2517 va_start (args, context);
2518 gtk_style_context_get_style_valist (context, args);
2524 * gtk_style_context_lookup_icon_set:
2525 * @context: a #GtkStyleContext
2526 * @stock_id: an icon name
2528 * Looks up @stock_id in the icon factories associated to @context and
2529 * the default icon factory, returning an icon set if found, otherwise
2532 * Returns: (transfer none): The looked up %GtkIconSet, or %NULL
2535 gtk_style_context_lookup_icon_set (GtkStyleContext *context,
2536 const gchar *stock_id)
2538 GtkStyleContextPrivate *priv;
2540 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2541 g_return_val_if_fail (stock_id != NULL, NULL);
2543 priv = context->priv;
2544 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
2546 return gtk_icon_factory_lookup_default (stock_id);
2550 * gtk_style_context_set_screen:
2551 * @context: a #GtkStyleContext
2552 * @screen: a #GdkScreen
2554 * Attaches @context to the given screen.
2556 * The screen is used to add style information from 'global' style
2557 * providers, such as the screens #GtkSettings instance.
2559 * If you are using a #GtkStyleContext returned from
2560 * gtk_widget_get_style_context(), you do not need to
2561 * call this yourself.
2566 gtk_style_context_set_screen (GtkStyleContext *context,
2569 GtkStyleContextPrivate *priv;
2571 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2572 g_return_if_fail (GDK_IS_SCREEN (screen));
2574 priv = context->priv;
2575 if (priv->screen == screen)
2578 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
2580 gtk_style_context_set_cascade (context, _gtk_style_cascade_get_for_screen (screen));
2584 _gtk_style_cascade_set_parent (priv->cascade, _gtk_style_cascade_get_for_screen (screen));
2587 priv->screen = screen;
2589 g_object_notify (G_OBJECT (context), "screen");
2593 * gtk_style_context_get_screen:
2594 * @context: a #GtkStyleContext
2596 * Returns the #GdkScreen to which @context is attached.
2598 * Returns: (transfer none): a #GdkScreen.
2601 gtk_style_context_get_screen (GtkStyleContext *context)
2603 GtkStyleContextPrivate *priv;
2605 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2607 priv = context->priv;
2608 return priv->screen;
2612 * gtk_style_context_set_direction:
2613 * @context: a #GtkStyleContext
2614 * @direction: the new direction.
2616 * Sets the reading direction for rendering purposes.
2618 * If you are using a #GtkStyleContext returned from
2619 * gtk_widget_get_style_context(), you do not need to
2620 * call this yourself.
2625 gtk_style_context_set_direction (GtkStyleContext *context,
2626 GtkTextDirection direction)
2628 GtkStyleContextPrivate *priv;
2630 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2632 priv = context->priv;
2633 priv->direction = direction;
2635 g_object_notify (G_OBJECT (context), "direction");
2639 * gtk_style_context_get_direction:
2640 * @context: a #GtkStyleContext
2642 * Returns the widget direction used for rendering.
2644 * Returns: the widget direction
2649 gtk_style_context_get_direction (GtkStyleContext *context)
2651 GtkStyleContextPrivate *priv;
2653 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), GTK_TEXT_DIR_LTR);
2655 priv = context->priv;
2656 return priv->direction;
2660 * gtk_style_context_set_junction_sides:
2661 * @context: a #GtkStyleContext
2662 * @sides: sides where rendered elements are visually connected to
2665 * Sets the sides where rendered elements (mostly through
2666 * gtk_render_frame()) will visually connect with other visual elements.
2668 * This is merely a hint that may or may not be honored
2669 * by theming engines.
2671 * Container widgets are expected to set junction hints as appropriate
2672 * for their children, so it should not normally be necessary to call
2673 * this function manually.
2678 gtk_style_context_set_junction_sides (GtkStyleContext *context,
2679 GtkJunctionSides sides)
2681 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2683 context->priv->info->junction_sides = sides;
2687 * gtk_style_context_get_junction_sides:
2688 * @context: a #GtkStyleContext
2690 * Returns the sides where rendered elements connect visually with others.
2692 * Returns: the junction sides
2697 gtk_style_context_get_junction_sides (GtkStyleContext *context)
2699 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
2701 return context->priv->info->junction_sides;
2705 _gtk_style_context_resolve_color (GtkStyleContext *context,
2706 GtkSymbolicColor *color,
2708 GtkCssDependencies *dependencies)
2712 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2713 g_return_val_if_fail (color != NULL, FALSE);
2714 g_return_val_if_fail (result != NULL, FALSE);
2716 val = _gtk_symbolic_color_resolve_full (color,
2717 GTK_STYLE_PROVIDER_PRIVATE (context->priv->cascade),
2718 _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR),
2719 GTK_CSS_DEPENDS_ON_COLOR,
2724 *result = *_gtk_css_rgba_value_get_rgba (val);
2725 _gtk_css_value_unref (val);
2730 * gtk_style_context_lookup_color:
2731 * @context: a #GtkStyleContext
2732 * @color_name: color name to lookup
2733 * @color: (out): Return location for the looked up color
2735 * Looks up and resolves a color name in the @context color map.
2737 * Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
2740 gtk_style_context_lookup_color (GtkStyleContext *context,
2741 const gchar *color_name,
2744 GtkSymbolicColor *sym_color;
2746 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2747 g_return_val_if_fail (color_name != NULL, FALSE);
2748 g_return_val_if_fail (color != NULL, FALSE);
2750 sym_color = _gtk_style_provider_private_get_color (GTK_STYLE_PROVIDER_PRIVATE (context->priv->cascade), color_name);
2751 if (sym_color == NULL)
2754 return _gtk_style_context_resolve_color (context, sym_color, color, NULL);
2758 * gtk_style_context_notify_state_change:
2759 * @context: a #GtkStyleContext
2760 * @window: a #GdkWindow
2761 * @region_id: (allow-none): animatable region to notify on, or %NULL.
2762 * See gtk_style_context_push_animatable_region()
2763 * @state: state to trigger transition for
2764 * @state_value: %TRUE if @state is the state we are changing to,
2765 * %FALSE if we are changing away from it
2767 * Notifies a state change on @context, so if the current style makes use
2768 * of transition animations, one will be started so all rendered elements
2769 * under @region_id are animated for state @state being set to value
2772 * The @window parameter is used in order to invalidate the rendered area
2773 * as the animation runs, so make sure it is the same window that is being
2774 * rendered on by the gtk_render_*() functions.
2776 * If @region_id is %NULL, all rendered elements using @context will be
2777 * affected by this state transition.
2779 * As a practical example, a #GtkButton notifying a state transition on
2780 * the prelight state:
2782 * gtk_style_context_notify_state_change (context,
2783 * gtk_widget_get_window (widget),
2785 * GTK_STATE_PRELIGHT,
2786 * button->in_button);
2789 * Can be handled in the CSS file like this:
2792 * background-color: #f00
2796 * background-color: #fff;
2797 * transition: 200ms linear
2801 * This combination will animate the button background from red to white
2802 * if a pointer enters the button, and back to red if the pointer leaves
2805 * Note that @state is used when finding the transition parameters, which
2806 * is why the style places the transition under the :hover pseudo-class.
2810 * Deprecated: 3.6: This function does nothing.
2813 gtk_style_context_notify_state_change (GtkStyleContext *context,
2817 gboolean state_value)
2819 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2820 g_return_if_fail (GDK_IS_WINDOW (window));
2821 g_return_if_fail (state > GTK_STATE_NORMAL && state <= GTK_STATE_FOCUSED);
2822 g_return_if_fail (context->priv->widget != NULL || context->priv->widget_path != NULL);
2826 * gtk_style_context_cancel_animations:
2827 * @context: a #GtkStyleContext
2828 * @region_id: (allow-none): animatable region to stop, or %NULL.
2829 * See gtk_style_context_push_animatable_region()
2831 * Stops all running animations for @region_id and all animatable
2832 * regions underneath.
2834 * A %NULL @region_id will stop all ongoing animations in @context,
2835 * when dealing with a #GtkStyleContext obtained through
2836 * gtk_widget_get_style_context(), this is normally done for you
2837 * in all circumstances you would expect all widget to be stopped,
2838 * so this should be only used in complex widgets with different
2839 * animatable regions.
2843 * Deprecated: 3.6: This function does nothing.
2846 gtk_style_context_cancel_animations (GtkStyleContext *context,
2849 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2853 * gtk_style_context_scroll_animations:
2854 * @context: a #GtkStyleContext
2855 * @window: a #GdkWindow used previously in
2856 * gtk_style_context_notify_state_change()
2857 * @dx: Amount to scroll in the X axis
2858 * @dy: Amount to scroll in the Y axis
2860 * This function is analogous to gdk_window_scroll(), and
2861 * should be called together with it so the invalidation
2862 * areas for any ongoing animation are scrolled together
2867 * Deprecated: 3.6: This function does nothing.
2870 gtk_style_context_scroll_animations (GtkStyleContext *context,
2875 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2876 g_return_if_fail (GDK_IS_WINDOW (window));
2880 * gtk_style_context_push_animatable_region:
2881 * @context: a #GtkStyleContext
2882 * @region_id: unique identifier for the animatable region
2884 * Pushes an animatable region, so all further gtk_render_*() calls between
2885 * this call and the following gtk_style_context_pop_animatable_region()
2886 * will potentially show transition animations for this region if
2887 * gtk_style_context_notify_state_change() is called for a given state,
2888 * and the current theme/style defines transition animations for state
2891 * The @region_id used must be unique in @context so the theming engine
2892 * can uniquely identify rendered elements subject to a state transition.
2896 * Deprecated: 3.6: This function does nothing.
2899 gtk_style_context_push_animatable_region (GtkStyleContext *context,
2902 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2903 g_return_if_fail (region_id != NULL);
2907 * gtk_style_context_pop_animatable_region:
2908 * @context: a #GtkStyleContext
2910 * Pops an animatable region from @context.
2911 * See gtk_style_context_push_animatable_region().
2915 * Deprecated: 3.6: This function does nothing.
2918 gtk_style_context_pop_animatable_region (GtkStyleContext *context)
2920 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2924 gtk_style_context_clear_cache (GtkStyleContext *context)
2926 GtkStyleContextPrivate *priv;
2929 priv = context->priv;
2931 for (info = priv->info; info; info = info->next)
2933 style_info_set_data (info, NULL);
2935 g_hash_table_remove_all (priv->style_data);
2939 gtk_style_context_update_cache (GtkStyleContext *context,
2940 const GtkBitmask *parent_changes)
2942 GtkStyleContextPrivate *priv;
2943 GHashTableIter iter;
2944 gpointer key, value;
2946 priv = context->priv;
2948 g_hash_table_iter_init (&iter, priv->style_data);
2949 while (g_hash_table_iter_next (&iter, &key, &value))
2951 GtkStyleInfo *info = key;
2952 StyleData *data = value;
2953 GtkBitmask *changes;
2955 changes = _gtk_bitmask_copy (parent_changes);
2956 changes = _gtk_bitmask_intersect (changes, data->store->depends_on_parent);
2957 if (_gtk_bitmask_get (changes, GTK_CSS_PROPERTY_COLOR))
2958 changes = _gtk_bitmask_union (changes, data->store->depends_on_color);
2959 if (_gtk_bitmask_get (changes, GTK_CSS_PROPERTY_FONT_SIZE))
2960 changes = _gtk_bitmask_union (changes, data->store->depends_on_font_size);
2962 build_properties (context, data->store, info, changes);
2967 gtk_style_context_do_invalidate (GtkStyleContext *context)
2969 GtkStyleContextPrivate *priv;
2971 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2973 priv = context->priv;
2975 /* Avoid reentrancy */
2976 if (priv->invalidating_context)
2979 priv->invalidating_context = TRUE;
2981 g_signal_emit (context, signals[CHANGED], 0);
2983 priv->invalidating_context = FALSE;
2987 gtk_style_context_update_animations (GtkStyleContext *context,
2990 GtkBitmask *differences;
2991 StyleData *style_data;
2993 style_data = style_data_lookup (context);
2995 differences = _gtk_css_computed_values_advance (style_data->store,
2998 if (_gtk_css_computed_values_is_static (style_data->store))
2999 _gtk_style_context_update_animating (context);
3005 gtk_style_context_needs_full_revalidate (GtkStyleContext *context,
3006 GtkCssChange change)
3008 GtkStyleContextPrivate *priv = context->priv;
3010 /* Try to avoid invalidating if we can */
3011 if (change & GTK_STYLE_CONTEXT_RADICAL_CHANGE)
3013 priv->relevant_changes = GTK_CSS_CHANGE_ANY;
3017 if (priv->relevant_changes == GTK_CSS_CHANGE_ANY)
3019 GtkWidgetPath *path;
3020 GtkCssMatcher matcher, superset;
3022 path = create_query_path (context, priv->info);
3023 if (_gtk_css_matcher_init (&matcher, path, priv->info->state_flags))
3025 _gtk_css_matcher_superset_init (&superset, &matcher, GTK_STYLE_CONTEXT_RADICAL_CHANGE & ~GTK_CSS_CHANGE_SOURCE);
3026 priv->relevant_changes = _gtk_style_provider_private_get_change (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
3030 priv->relevant_changes = 0;
3032 priv->relevant_changes &= ~GTK_STYLE_CONTEXT_RADICAL_CHANGE;
3034 gtk_widget_path_unref (path);
3038 if (priv->relevant_changes & change)
3045 gtk_style_context_should_create_transitions (GtkStyleContext *context)
3047 GtkStyleContextPrivate *priv;
3050 priv = context->priv;
3052 if (priv->widget == NULL)
3055 if (!gtk_widget_get_mapped (priv->widget))
3058 g_object_get (gtk_widget_get_settings (context->priv->widget),
3059 "gtk-enable-animations", &animate,
3066 _gtk_style_context_validate (GtkStyleContext *context,
3068 GtkCssChange change,
3069 const GtkBitmask *parent_changes)
3071 GtkStyleContextPrivate *priv;
3074 GtkBitmask *changes;
3077 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3079 priv = context->priv;
3081 change |= priv->pending_changes;
3083 /* If you run your application with
3084 * GTK_DEBUG=no-css-cache
3085 * every invalidation will purge the cache and completely query
3086 * everything anew form the cache. This is slow (in particular
3087 * when animating), but useful for figuring out bugs.
3089 * We achieve that by pretending that everything that could have
3090 * changed has and so we of course totally need to redo everything.
3092 * Note that this also completely revalidates child widgets all
3095 if (G_UNLIKELY (gtk_get_debug_flags () & GTK_DEBUG_NO_CSS_CACHE))
3096 change = GTK_CSS_CHANGE_ANY;
3098 if (!priv->invalid && change == 0 && _gtk_bitmask_is_empty (parent_changes))
3101 priv->pending_changes = 0;
3102 gtk_style_context_set_invalid (context, FALSE);
3106 current = style_data_ref (info->data);
3110 /* Try to avoid invalidating if we can */
3111 if (current == NULL ||
3112 gtk_style_context_needs_full_revalidate (context, change))
3116 if ((priv->relevant_changes & change) & ~GTK_STYLE_CONTEXT_CACHED_CHANGE)
3118 gtk_style_context_clear_cache (context);
3122 gtk_style_context_update_cache (context, parent_changes);
3123 style_info_set_data (info, NULL);
3126 data = style_data_lookup (context);
3128 _gtk_css_computed_values_create_animations (data->store,
3129 priv->parent ? style_data_lookup (priv->parent)->store : NULL,
3131 GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
3132 current && gtk_style_context_should_create_transitions (context) ? current->store : NULL);
3133 if (_gtk_css_computed_values_is_static (data->store))
3134 change &= ~GTK_CSS_CHANGE_ANIMATE;
3136 change |= GTK_CSS_CHANGE_ANIMATE;
3137 _gtk_style_context_update_animating (context);
3141 changes = _gtk_css_computed_values_get_difference (data->store, current->store);
3143 /* In the case where we keep the cache, we want unanimated values */
3144 _gtk_css_computed_values_cancel_animations (current->store);
3148 changes = _gtk_bitmask_new ();
3149 changes = _gtk_bitmask_invert_range (changes, 0, _gtk_css_style_property_get_n_properties ());
3154 changes = _gtk_bitmask_copy (parent_changes);
3155 changes = _gtk_bitmask_intersect (changes, current->store->depends_on_parent);
3156 if (_gtk_bitmask_get (changes, GTK_CSS_PROPERTY_COLOR))
3157 changes = _gtk_bitmask_union (changes, current->store->depends_on_color);
3158 if (_gtk_bitmask_get (changes, GTK_CSS_PROPERTY_FONT_SIZE))
3159 changes = _gtk_bitmask_union (changes, current->store->depends_on_font_size);
3161 gtk_style_context_update_cache (context, parent_changes);
3165 style_data_unref (current);
3167 if (change & GTK_CSS_CHANGE_ANIMATE &&
3168 gtk_style_context_is_animating (context))
3170 GtkBitmask *animation_changes;
3172 animation_changes = gtk_style_context_update_animations (context, timestamp);
3173 changes = _gtk_bitmask_union (changes, animation_changes);
3174 _gtk_bitmask_free (animation_changes);
3177 if (!_gtk_bitmask_is_empty (changes))
3178 gtk_style_context_do_invalidate (context);
3180 change = _gtk_css_change_for_child (change);
3181 for (list = priv->children; list; list = list->next)
3183 _gtk_style_context_validate (list->data, timestamp, change, changes);
3186 _gtk_bitmask_free (changes);
3190 _gtk_style_context_queue_invalidate (GtkStyleContext *context,
3191 GtkCssChange change)
3193 GtkStyleContextPrivate *priv;
3195 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3196 g_return_if_fail (change != 0);
3198 priv = context->priv;
3200 if (priv->widget != NULL)
3202 priv->pending_changes |= change;
3203 gtk_style_context_set_invalid (context, TRUE);
3205 else if (priv->widget_path == NULL)
3207 gtk_style_context_invalidate (context);
3212 * gtk_style_context_invalidate:
3213 * @context: a #GtkStyleContext.
3215 * Invalidates @context style information, so it will be reconstructed
3218 * If you're using a #GtkStyleContext returned from
3219 * gtk_widget_get_style_context(), you do not need to
3220 * call this yourself.
3225 gtk_style_context_invalidate (GtkStyleContext *context)
3227 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3229 gtk_style_context_clear_cache (context);
3230 gtk_style_context_do_invalidate (context);
3234 * gtk_style_context_set_background:
3235 * @context: a #GtkStyleContext
3236 * @window: a #GdkWindow
3238 * Sets the background of @window to the background pattern or
3239 * color specified in @context for its current state.
3244 gtk_style_context_set_background (GtkStyleContext *context,
3247 GtkStateFlags state;
3250 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3251 g_return_if_fail (GDK_IS_WINDOW (window));
3253 state = gtk_style_context_get_state (context);
3255 gtk_style_context_get (context, state,
3256 "background-color", &color,
3260 gdk_window_set_background_rgba (window, color);
3261 gdk_rgba_free (color);
3266 * gtk_style_context_get_color:
3267 * @context: a #GtkStyleContext
3268 * @state: state to retrieve the color for
3269 * @color: (out): return value for the foreground color
3271 * Gets the foreground color for a given state.
3276 gtk_style_context_get_color (GtkStyleContext *context,
3277 GtkStateFlags state,
3282 g_return_if_fail (color != NULL);
3283 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3285 gtk_style_context_get (context,
3295 * gtk_style_context_get_background_color:
3296 * @context: a #GtkStyleContext
3297 * @state: state to retrieve the color for
3298 * @color: (out): return value for the background color
3300 * Gets the background color for a given state.
3305 gtk_style_context_get_background_color (GtkStyleContext *context,
3306 GtkStateFlags state,
3311 g_return_if_fail (color != NULL);
3312 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3314 gtk_style_context_get (context,
3316 "background-color", &c,
3324 * gtk_style_context_get_border_color:
3325 * @context: a #GtkStyleContext
3326 * @state: state to retrieve the color for
3327 * @color: (out): return value for the border color
3329 * Gets the border color for a given state.
3334 gtk_style_context_get_border_color (GtkStyleContext *context,
3335 GtkStateFlags state,
3340 g_return_if_fail (color != NULL);
3341 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3343 gtk_style_context_get (context,
3353 * gtk_style_context_get_border:
3354 * @context: a #GtkStyleContext
3355 * @state: state to retrieve the border for
3356 * @border: (out): return value for the border settings
3358 * Gets the border for a given state as a #GtkBorder.
3359 * See %GTK_STYLE_PROPERTY_BORDER_WIDTH.
3364 gtk_style_context_get_border (GtkStyleContext *context,
3365 GtkStateFlags state,
3368 int top, left, bottom, right;
3370 g_return_if_fail (border != NULL);
3371 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3373 gtk_style_context_get (context,
3375 "border-top-width", &top,
3376 "border-left-width", &left,
3377 "border-bottom-width", &bottom,
3378 "border-right-width", &right,
3382 border->left = left;
3383 border->bottom = bottom;
3384 border->right = right;
3388 * gtk_style_context_get_padding:
3389 * @context: a #GtkStyleContext
3390 * @state: state to retrieve the padding for
3391 * @padding: (out): return value for the padding settings
3393 * Gets the padding for a given state as a #GtkBorder.
3394 * See %GTK_STYLE_PROPERTY_PADDING.
3399 gtk_style_context_get_padding (GtkStyleContext *context,
3400 GtkStateFlags state,
3403 int top, left, bottom, right;
3405 g_return_if_fail (padding != NULL);
3406 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3408 gtk_style_context_get (context,
3410 "padding-top", &top,
3411 "padding-left", &left,
3412 "padding-bottom", &bottom,
3413 "padding-right", &right,
3417 padding->left = left;
3418 padding->bottom = bottom;
3419 padding->right = right;
3423 * gtk_style_context_get_margin:
3424 * @context: a #GtkStyleContext
3425 * @state: state to retrieve the border for
3426 * @margin: (out): return value for the margin settings
3428 * Gets the margin for a given state as a #GtkBorder.
3429 * See %GTK_STYLE_PROPERTY_MARGIN.
3434 gtk_style_context_get_margin (GtkStyleContext *context,
3435 GtkStateFlags state,
3438 int top, left, bottom, right;
3440 g_return_if_fail (margin != NULL);
3441 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3443 gtk_style_context_get (context,
3446 "margin-left", &left,
3447 "margin-bottom", &bottom,
3448 "margin-right", &right,
3452 margin->left = left;
3453 margin->bottom = bottom;
3454 margin->right = right;
3458 * gtk_style_context_get_font:
3459 * @context: a #GtkStyleContext
3460 * @state: state to retrieve the font for
3462 * Returns the font description for a given state. The returned
3463 * object is const and will remain valid until the
3464 * #GtkStyleContext::changed signal happens.
3466 * Returns: (transfer none): the #PangoFontDescription for the given
3467 * state. This object is owned by GTK+ and should not be
3472 const PangoFontDescription *
3473 gtk_style_context_get_font (GtkStyleContext *context,
3474 GtkStateFlags state)
3476 GtkStyleContextPrivate *priv;
3478 PangoFontDescription *description;
3480 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
3482 priv = context->priv;
3483 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
3485 data = style_data_lookup_for_state (context, state);
3487 /* Yuck, fonts are created on-demand but we don't return a ref.
3488 * Do bad things to achieve this requirement */
3489 description = g_object_get_data (G_OBJECT (data->store), "font-cache-for-get_font");
3490 if (description == NULL)
3492 gtk_style_context_get (context, state, "font", &description, NULL);
3493 g_object_set_data_full (G_OBJECT (data->store),
3494 "font-cache-for-get_font",
3496 (GDestroyNotify) pango_font_description_free);
3502 get_cursor_color (GtkStyleContext *context,
3506 GdkColor *style_color;
3508 gtk_style_context_get_style (context,
3509 primary ? "cursor-color" : "secondary-cursor-color",
3515 color->red = style_color->red / 65535.0;
3516 color->green = style_color->green / 65535.0;
3517 color->blue = style_color->blue / 65535.0;
3520 gdk_color_free (style_color);
3524 gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, color);
3530 gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &bg);
3532 color->red = (color->red + bg.red) * 0.5;
3533 color->green = (color->green + bg.green) * 0.5;
3534 color->blue = (color->blue + bg.blue) * 0.5;
3540 _gtk_style_context_get_cursor_color (GtkStyleContext *context,
3541 GdkRGBA *primary_color,
3542 GdkRGBA *secondary_color)
3545 get_cursor_color (context, TRUE, primary_color);
3547 if (secondary_color)
3548 get_cursor_color (context, FALSE, secondary_color);
3555 * @context: a #GtkStyleContext
3557 * @x: X origin of the rectangle
3558 * @y: Y origin of the rectangle
3559 * @width: rectangle width
3560 * @height: rectangle height
3562 * Renders a checkmark (as in a #GtkCheckButton).
3564 * The %GTK_STATE_FLAG_ACTIVE state determines whether the check is
3565 * on or off, and %GTK_STATE_FLAG_INCONSISTENT determines whether it
3566 * should be marked as undefined.
3569 * <title>Typical checkmark rendering</title>
3570 * <inlinegraphic fileref="checks.png" format="PNG"/>
3576 gtk_render_check (GtkStyleContext *context,
3583 GtkThemingEngineClass *engine_class;
3584 GtkThemingEngine *engine;
3586 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3587 g_return_if_fail (cr != NULL);
3589 if (width <= 0 || height <= 0)
3592 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3593 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3598 _gtk_theming_engine_set_context (engine, context);
3599 engine_class->render_check (engine, cr,
3600 x, y, width, height);
3606 * gtk_render_option:
3607 * @context: a #GtkStyleContext
3609 * @x: X origin of the rectangle
3610 * @y: Y origin of the rectangle
3611 * @width: rectangle width
3612 * @height: rectangle height
3614 * Renders an option mark (as in a #GtkRadioButton), the %GTK_STATE_FLAG_ACTIVE
3615 * state will determine whether the option is on or off, and
3616 * %GTK_STATE_FLAG_INCONSISTENT whether it should be marked as undefined.
3619 * <title>Typical option mark rendering</title>
3620 * <inlinegraphic fileref="options.png" format="PNG"/>
3626 gtk_render_option (GtkStyleContext *context,
3633 GtkThemingEngineClass *engine_class;
3634 GtkThemingEngine *engine;
3636 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3637 g_return_if_fail (cr != NULL);
3639 if (width <= 0 || height <= 0)
3642 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3643 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3647 _gtk_theming_engine_set_context (engine, context);
3648 engine_class->render_option (engine, cr,
3649 x, y, width, height);
3656 * @context: a #GtkStyleContext
3658 * @angle: arrow angle from 0 to 2 * %G_PI, being 0 the arrow pointing to the north
3659 * @x: X origin of the render area
3660 * @y: Y origin of the render area
3661 * @size: square side for render area
3663 * Renders an arrow pointing to @angle.
3666 * <title>Typical arrow rendering at 0, 1&solidus;2 π, π and 3&solidus;2 π</title>
3667 * <inlinegraphic fileref="arrows.png" format="PNG"/>
3673 gtk_render_arrow (GtkStyleContext *context,
3680 GtkThemingEngineClass *engine_class;
3681 GtkThemingEngine *engine;
3683 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3684 g_return_if_fail (cr != NULL);
3689 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3690 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3694 gtk_style_context_save (context);
3695 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ARROW);
3697 _gtk_theming_engine_set_context (engine, context);
3698 engine_class->render_arrow (engine, cr,
3701 gtk_style_context_restore (context);
3706 * gtk_render_background:
3707 * @context: a #GtkStyleContext
3709 * @x: X origin of the rectangle
3710 * @y: Y origin of the rectangle
3711 * @width: rectangle width
3712 * @height: rectangle height
3714 * Renders the background of an element.
3717 * <title>Typical background rendering, showing the effect of
3718 * <parameter>background-image</parameter>,
3719 * <parameter>border-width</parameter> and
3720 * <parameter>border-radius</parameter></title>
3721 * <inlinegraphic fileref="background.png" format="PNG"/>
3727 gtk_render_background (GtkStyleContext *context,
3734 GtkThemingEngineClass *engine_class;
3735 GtkThemingEngine *engine;
3737 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3738 g_return_if_fail (cr != NULL);
3740 if (width <= 0 || height <= 0)
3743 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3744 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3748 _gtk_theming_engine_set_context (engine, context);
3749 engine_class->render_background (engine, cr, x, y, width, height);
3756 * @context: a #GtkStyleContext
3758 * @x: X origin of the rectangle
3759 * @y: Y origin of the rectangle
3760 * @width: rectangle width
3761 * @height: rectangle height
3763 * Renders a frame around the rectangle defined by @x, @y, @width, @height.
3766 * <title>Examples of frame rendering, showing the effect of
3767 * <parameter>border-image</parameter>,
3768 * <parameter>border-color</parameter>,
3769 * <parameter>border-width</parameter>,
3770 * <parameter>border-radius</parameter> and
3772 * <inlinegraphic fileref="frames.png" format="PNG"/>
3778 gtk_render_frame (GtkStyleContext *context,
3785 GtkThemingEngineClass *engine_class;
3786 GtkThemingEngine *engine;
3788 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3789 g_return_if_fail (cr != NULL);
3791 if (width <= 0 || height <= 0)
3794 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3795 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3799 _gtk_theming_engine_set_context (engine, context);
3800 engine_class->render_frame (engine, cr, x, y, width, height);
3806 * gtk_render_expander:
3807 * @context: a #GtkStyleContext
3809 * @x: X origin of the rectangle
3810 * @y: Y origin of the rectangle
3811 * @width: rectangle width
3812 * @height: rectangle height
3814 * Renders an expander (as used in #GtkTreeView and #GtkExpander) in the area
3815 * defined by @x, @y, @width, @height. The state %GTK_STATE_FLAG_ACTIVE
3816 * determines whether the expander is collapsed or expanded.
3819 * <title>Typical expander rendering</title>
3820 * <inlinegraphic fileref="expanders.png" format="PNG"/>
3826 gtk_render_expander (GtkStyleContext *context,
3833 GtkThemingEngineClass *engine_class;
3834 GtkThemingEngine *engine;
3836 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3837 g_return_if_fail (cr != NULL);
3839 if (width <= 0 || height <= 0)
3842 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3843 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3847 _gtk_theming_engine_set_context (engine, context);
3848 engine_class->render_expander (engine, cr, x, y, width, height);
3855 * @context: a #GtkStyleContext
3857 * @x: X origin of the rectangle
3858 * @y: Y origin of the rectangle
3859 * @width: rectangle width
3860 * @height: rectangle height
3862 * Renders a focus indicator on the rectangle determined by @x, @y, @width, @height.
3864 * <title>Typical focus rendering</title>
3865 * <inlinegraphic fileref="focus.png" format="PNG"/>
3871 gtk_render_focus (GtkStyleContext *context,
3878 GtkThemingEngineClass *engine_class;
3879 GtkThemingEngine *engine;
3881 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3882 g_return_if_fail (cr != NULL);
3884 if (width <= 0 || height <= 0)
3887 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3888 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3892 _gtk_theming_engine_set_context (engine, context);
3893 engine_class->render_focus (engine, cr, x, y, width, height);
3899 * gtk_render_layout:
3900 * @context: a #GtkStyleContext
3904 * @layout: the #PangoLayout to render
3906 * Renders @layout on the coordinates @x, @y
3911 gtk_render_layout (GtkStyleContext *context,
3915 PangoLayout *layout)
3917 GtkThemingEngineClass *engine_class;
3918 GtkThemingEngine *engine;
3919 PangoRectangle extents;
3921 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3922 g_return_if_fail (PANGO_IS_LAYOUT (layout));
3923 g_return_if_fail (cr != NULL);
3925 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3926 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3930 pango_layout_get_extents (layout, &extents, NULL);
3932 _gtk_theming_engine_set_context (engine, context);
3933 engine_class->render_layout (engine, cr, x, y, layout);
3940 * @context: a #GtkStyleContext
3942 * @x0: X coordinate for the origin of the line
3943 * @y0: Y coordinate for the origin of the line
3944 * @x1: X coordinate for the end of the line
3945 * @y1: Y coordinate for the end of the line
3947 * Renders a line from (x0, y0) to (x1, y1).
3952 gtk_render_line (GtkStyleContext *context,
3959 GtkThemingEngineClass *engine_class;
3960 GtkThemingEngine *engine;
3962 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3963 g_return_if_fail (cr != NULL);
3965 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3966 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3970 _gtk_theming_engine_set_context (engine, context);
3971 engine_class->render_line (engine, cr, x0, y0, x1, y1);
3977 * gtk_render_slider:
3978 * @context: a #GtkStyleContext
3980 * @x: X origin of the rectangle
3981 * @y: Y origin of the rectangle
3982 * @width: rectangle width
3983 * @height: rectangle height
3984 * @orientation: orientation of the slider
3986 * Renders a slider (as in #GtkScale) in the rectangle defined by @x, @y,
3987 * @width, @height. @orientation defines whether the slider is vertical
3991 * <title>Typical slider rendering</title>
3992 * <inlinegraphic fileref="sliders.png" format="PNG"/>
3998 gtk_render_slider (GtkStyleContext *context,
4004 GtkOrientation orientation)
4006 GtkThemingEngineClass *engine_class;
4007 GtkThemingEngine *engine;
4009 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4010 g_return_if_fail (cr != NULL);
4012 if (width <= 0 || height <= 0)
4015 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4016 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4020 _gtk_theming_engine_set_context (engine, context);
4021 engine_class->render_slider (engine, cr, x, y, width, height, orientation);
4027 * gtk_render_frame_gap:
4028 * @context: a #GtkStyleContext
4030 * @x: X origin of the rectangle
4031 * @y: Y origin of the rectangle
4032 * @width: rectangle width
4033 * @height: rectangle height
4034 * @gap_side: side where the gap is
4035 * @xy0_gap: initial coordinate (X or Y depending on @gap_side) for the gap
4036 * @xy1_gap: end coordinate (X or Y depending on @gap_side) for the gap
4038 * Renders a frame around the rectangle defined by (@x, @y, @width, @height),
4039 * leaving a gap on one side. @xy0_gap and @xy1_gap will mean X coordinates
4040 * for %GTK_POS_TOP and %GTK_POS_BOTTOM gap sides, and Y coordinates for
4041 * %GTK_POS_LEFT and %GTK_POS_RIGHT.
4044 * <title>Typical rendering of a frame with a gap</title>
4045 * <inlinegraphic fileref="frame-gap.png" format="PNG"/>
4051 gtk_render_frame_gap (GtkStyleContext *context,
4057 GtkPositionType gap_side,
4061 GtkThemingEngineClass *engine_class;
4062 GtkThemingEngine *engine;
4064 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4065 g_return_if_fail (cr != NULL);
4066 g_return_if_fail (xy0_gap <= xy1_gap);
4067 g_return_if_fail (xy0_gap >= 0);
4069 if (width <= 0 || height <= 0)
4072 if (gap_side == GTK_POS_LEFT ||
4073 gap_side == GTK_POS_RIGHT)
4074 g_return_if_fail (xy1_gap <= height);
4076 g_return_if_fail (xy1_gap <= width);
4078 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4079 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4083 _gtk_theming_engine_set_context (engine, context);
4084 engine_class->render_frame_gap (engine, cr,
4085 x, y, width, height, gap_side,
4092 * gtk_render_extension:
4093 * @context: a #GtkStyleContext
4095 * @x: X origin of the rectangle
4096 * @y: Y origin of the rectangle
4097 * @width: rectangle width
4098 * @height: rectangle height
4099 * @gap_side: side where the gap is
4101 * Renders a extension (as in a #GtkNotebook tab) in the rectangle
4102 * defined by @x, @y, @width, @height. The side where the extension
4103 * connects to is defined by @gap_side.
4106 * <title>Typical extension rendering</title>
4107 * <inlinegraphic fileref="extensions.png" format="PNG"/>
4113 gtk_render_extension (GtkStyleContext *context,
4119 GtkPositionType gap_side)
4121 GtkThemingEngineClass *engine_class;
4122 GtkThemingEngine *engine;
4124 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4125 g_return_if_fail (cr != NULL);
4127 if (width <= 0 || height <= 0)
4130 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4131 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4135 _gtk_theming_engine_set_context (engine, context);
4136 engine_class->render_extension (engine, cr, x, y, width, height, gap_side);
4142 * gtk_render_handle:
4143 * @context: a #GtkStyleContext
4145 * @x: X origin of the rectangle
4146 * @y: Y origin of the rectangle
4147 * @width: rectangle width
4148 * @height: rectangle height
4150 * Renders a handle (as in #GtkHandleBox, #GtkPaned and
4151 * #GtkWindow<!-- -->'s resize grip), in the rectangle
4152 * determined by @x, @y, @width, @height.
4155 * <title>Handles rendered for the paned and grip classes</title>
4156 * <inlinegraphic fileref="handles.png" format="PNG"/>
4162 gtk_render_handle (GtkStyleContext *context,
4169 GtkThemingEngineClass *engine_class;
4170 GtkThemingEngine *engine;
4172 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4173 g_return_if_fail (cr != NULL);
4175 if (width <= 0 || height <= 0)
4178 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4179 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4183 _gtk_theming_engine_set_context (engine, context);
4184 engine_class->render_handle (engine, cr, x, y, width, height);
4190 * gtk_render_activity:
4191 * @context: a #GtkStyleContext
4193 * @x: X origin of the rectangle
4194 * @y: Y origin of the rectangle
4195 * @width: rectangle width
4196 * @height: rectangle height
4198 * Renders an activity area (Such as in #GtkSpinner or the
4199 * fill line in #GtkRange), the state %GTK_STATE_FLAG_ACTIVE
4200 * determines whether there is activity going on.
4205 gtk_render_activity (GtkStyleContext *context,
4212 GtkThemingEngineClass *engine_class;
4213 GtkThemingEngine *engine;
4215 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4216 g_return_if_fail (cr != NULL);
4218 if (width <= 0 || height <= 0)
4221 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4222 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4226 _gtk_theming_engine_set_context (engine, context);
4227 engine_class->render_activity (engine, cr, x, y, width, height);
4233 * gtk_render_icon_pixbuf:
4234 * @context: a #GtkStyleContext
4235 * @source: the #GtkIconSource specifying the icon to render
4236 * @size: (type int): the size to render the icon at. A size of (GtkIconSize) -1
4237 * means render at the size of the source and don't scale.
4239 * Renders the icon specified by @source at the given @size, returning the result
4242 * Returns: (transfer full): a newly-created #GdkPixbuf containing the rendered icon
4247 gtk_render_icon_pixbuf (GtkStyleContext *context,
4248 const GtkIconSource *source,
4251 GtkThemingEngineClass *engine_class;
4252 GtkThemingEngine *engine;
4254 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
4255 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
4256 g_return_val_if_fail (source != NULL, NULL);
4258 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4259 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4261 _gtk_theming_engine_set_context (engine, context);
4262 return engine_class->render_icon_pixbuf (engine, source, size);
4267 * @context: a #GtkStyleContext
4269 * @pixbuf: a #GdkPixbuf containing the icon to draw
4270 * @x: X position for the @pixbuf
4271 * @y: Y position for the @pixbuf
4273 * Renders the icon in @pixbuf at the specified @x and @y coordinates.
4278 gtk_render_icon (GtkStyleContext *context,
4284 GtkThemingEngineClass *engine_class;
4285 GtkThemingEngine *engine;
4287 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4288 g_return_if_fail (cr != NULL);
4290 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4291 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4295 _gtk_theming_engine_set_context (engine, context);
4296 engine_class->render_icon (engine, cr, pixbuf, x, y);
4302 draw_insertion_cursor (GtkStyleContext *context,
4307 gboolean is_primary,
4308 PangoDirection direction,
4309 gboolean draw_arrow)
4312 GdkRGBA primary_color;
4313 GdkRGBA secondary_color;
4314 gfloat cursor_aspect_ratio;
4320 _gtk_style_context_get_cursor_color (context, &primary_color, &secondary_color);
4321 gdk_cairo_set_source_rgba (cr, is_primary ? &primary_color : &secondary_color);
4323 /* When changing the shape or size of the cursor here,
4324 * propagate the changes to gtktextview.c:text_window_invalidate_cursors().
4327 gtk_style_context_get_style (context,
4328 "cursor-aspect-ratio", &cursor_aspect_ratio,
4331 stem_width = height * cursor_aspect_ratio + 1;
4333 /* put (stem_width % 2) on the proper side of the cursor */
4334 if (direction == PANGO_DIRECTION_LTR)
4335 offset = stem_width / 2;
4337 offset = stem_width - stem_width / 2;
4339 cairo_rectangle (cr, x - offset, y, stem_width, height);
4347 arrow_width = stem_width + 1;
4349 if (direction == PANGO_DIRECTION_RTL)
4351 ax = x - offset - 1;
4352 ay = y + height - arrow_width * 2 - arrow_width + 1;
4354 cairo_move_to (cr, ax, ay + 1);
4355 cairo_line_to (cr, ax - arrow_width, ay + arrow_width);
4356 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4359 else if (direction == PANGO_DIRECTION_LTR)
4361 ax = x + stem_width - offset;
4362 ay = y + height - arrow_width * 2 - arrow_width + 1;
4364 cairo_move_to (cr, ax, ay + 1);
4365 cairo_line_to (cr, ax + arrow_width, ay + arrow_width);
4366 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4370 g_assert_not_reached();
4377 * gtk_render_insertion_cursor:
4378 * @context: a #GtkStyleContext
4382 * @layout: the #PangoLayout of the text
4383 * @index: the index in the #PangoLayout
4384 * @direction: the #PangoDirection of the text
4386 * Draws a text caret on @cr at the specified index of @layout.
4391 gtk_render_insertion_cursor (GtkStyleContext *context,
4395 PangoLayout *layout,
4397 PangoDirection direction)
4399 GtkStyleContextPrivate *priv;
4400 gboolean split_cursor;
4401 PangoRectangle strong_pos, weak_pos;
4402 PangoRectangle *cursor1, *cursor2;
4403 PangoDirection keymap_direction;
4404 PangoDirection direction2;
4406 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4407 g_return_if_fail (cr != NULL);
4408 g_return_if_fail (PANGO_IS_LAYOUT (layout));
4409 g_return_if_fail (index >= 0);
4411 priv = context->priv;
4413 g_object_get (gtk_settings_get_for_screen (priv->screen),
4414 "gtk-split-cursor", &split_cursor,
4417 keymap_direction = gdk_keymap_get_direction (gdk_keymap_get_for_display (gdk_screen_get_display (priv->screen)));
4419 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4421 direction2 = PANGO_DIRECTION_NEUTRAL;
4425 cursor1 = &strong_pos;
4427 if (strong_pos.x != weak_pos.x || strong_pos.y != weak_pos.y)
4429 direction2 = (direction == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
4430 cursor2 = &weak_pos;
4435 if (keymap_direction == direction)
4436 cursor1 = &strong_pos;
4438 cursor1 = &weak_pos;
4441 draw_insertion_cursor (context,
4443 x + PANGO_PIXELS (cursor1->x),
4444 y + PANGO_PIXELS (cursor1->y),
4445 PANGO_PIXELS (cursor1->height),
4448 direction2 != PANGO_DIRECTION_NEUTRAL);
4450 if (direction2 != PANGO_DIRECTION_NEUTRAL)
4452 draw_insertion_cursor (context,
4454 x + PANGO_PIXELS (cursor2->x),
4455 y + PANGO_PIXELS (cursor2->y),
4456 PANGO_PIXELS (cursor2->height),
4464 * gtk_draw_insertion_cursor:
4465 * @widget: a #GtkWidget
4466 * @cr: cairo context to draw to
4467 * @location: location where to draw the cursor (@location->width is ignored)
4468 * @is_primary: if the cursor should be the primary cursor color.
4469 * @direction: whether the cursor is left-to-right or
4470 * right-to-left. Should never be #GTK_TEXT_DIR_NONE
4471 * @draw_arrow: %TRUE to draw a directional arrow on the
4472 * cursor. Should be %FALSE unless the cursor is split.
4474 * Draws a text caret on @cr at @location. This is not a style function
4475 * but merely a convenience function for drawing the standard cursor shape.
4478 * Deprecated: 3.4: Use gtk_render_insertion_cursor() instead.
4481 gtk_draw_insertion_cursor (GtkWidget *widget,
4483 const GdkRectangle *location,
4484 gboolean is_primary,
4485 GtkTextDirection direction,
4486 gboolean draw_arrow)
4488 GtkStyleContext *context;
4490 g_return_if_fail (GTK_IS_WIDGET (widget));
4491 g_return_if_fail (cr != NULL);
4492 g_return_if_fail (location != NULL);
4493 g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
4495 context = gtk_widget_get_style_context (widget);
4497 draw_insertion_cursor (context, cr,
4498 location->x, location->y, location->height,
4500 (direction == GTK_TEXT_DIR_RTL) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR,
4504 static AtkAttributeSet *
4505 add_attribute (AtkAttributeSet *attributes,
4506 AtkTextAttribute attr,
4511 at = g_new (AtkAttribute, 1);
4512 at->name = g_strdup (atk_text_attribute_get_name (attr));
4513 at->value = g_strdup (value);
4515 return g_slist_prepend (attributes, at);
4519 * _gtk_style_context_get_attributes:
4520 * @attributes: a #AtkAttributeSet to add attributes to
4521 * @context: the #GtkStyleContext to get attributes from
4522 * @flags: the state to use with @context
4524 * Adds the foreground and background color from @context to
4525 * @attributes, after translating them to ATK attributes.
4527 * This is a convenience function that can be used in
4528 * implementing the #AtkText interface in widgets.
4530 * Returns: the modified #AtkAttributeSet
4533 _gtk_style_context_get_attributes (AtkAttributeSet *attributes,
4534 GtkStyleContext *context,
4535 GtkStateFlags flags)
4540 gtk_style_context_get_background_color (context, flags, &color);
4541 value = g_strdup_printf ("%u,%u,%u",
4542 (guint) ceil (color.red * 65536 - color.red),
4543 (guint) ceil (color.green * 65536 - color.green),
4544 (guint) ceil (color.blue * 65536 - color.blue));
4545 attributes = add_attribute (attributes, ATK_TEXT_ATTR_BG_COLOR, value);
4548 gtk_style_context_get_color (context, flags, &color);
4549 value = g_strdup_printf ("%u,%u,%u",
4550 (guint) ceil (color.red * 65536 - color.red),
4551 (guint) ceil (color.green * 65536 - color.green),
4552 (guint) ceil (color.blue * 65536 - color.blue));
4553 attributes = add_attribute (attributes, ATK_TEXT_ATTR_FG_COLOR, value);
4560 gtk_gradient_resolve_for_context (GtkGradient *gradient,
4561 GtkStyleContext *context)
4563 GtkStyleContextPrivate *priv = context->priv;
4564 GtkCssDependencies ignored = 0;
4566 g_return_val_if_fail (gradient != NULL, NULL);
4567 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
4569 return _gtk_gradient_resolve_full (gradient,
4570 GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
4571 style_data_lookup (context)->store,
4572 priv->parent ? style_data_lookup (priv->parent)->store : NULL,