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 "gtkcssanimatedvaluesprivate.h"
28 #include "gtkcssenginevalueprivate.h"
29 #include "gtkcssnumbervalueprivate.h"
30 #include "gtkcssrgbavalueprivate.h"
31 #include "gtkstylepropertiesprivate.h"
32 #include "gtktypebuiltins.h"
33 #include "gtkthemingengineprivate.h"
35 #include "gtkwidget.h"
36 #include "gtkwindow.h"
37 #include "gtkprivate.h"
38 #include "gtksymboliccolorprivate.h"
39 #include "gtkiconfactory.h"
40 #include "gtkwidgetpath.h"
41 #include "gtkwidgetprivate.h"
42 #include "gtkstylecascadeprivate.h"
43 #include "gtkstyleproviderprivate.h"
44 #include "gtksettings.h"
47 * SECTION:gtkstylecontext
48 * @Short_description: Rendering UI elements
49 * @Title: GtkStyleContext
51 * #GtkStyleContext is an object that stores styling information affecting
52 * a widget defined by #GtkWidgetPath.
54 * In order to construct the final style information, #GtkStyleContext
55 * queries information from all attached #GtkStyleProviders. Style providers
56 * can be either attached explicitly to the context through
57 * gtk_style_context_add_provider(), or to the screen through
58 * gtk_style_context_add_provider_for_screen(). The resulting style is a
59 * combination of all providers' information in priority order.
61 * For GTK+ widgets, any #GtkStyleContext returned by
62 * gtk_widget_get_style_context() will already have a #GtkWidgetPath, a
63 * #GdkScreen and RTL/LTR information set. The style context will be also
64 * updated automatically if any of these settings change on the widget.
66 * If you are using the theming layer standalone, you will need to set a
67 * widget path and a screen yourself to the created style context through
68 * gtk_style_context_set_path() and gtk_style_context_set_screen(), as well
69 * as updating the context yourself using gtk_style_context_invalidate()
70 * whenever any of the conditions change, such as a change in the
71 * #GtkSettings:gtk-theme-name setting or a hierarchy change in the rendered
74 * <refsect2 id="gtkstylecontext-animations">
75 * <title>Transition animations</title>
77 * #GtkStyleContext has built-in support for state change transitions.
78 * Note that these animations respect the #GtkSettings:gtk-enable-animations
82 * For simple widgets where state changes affect the whole widget area,
83 * calling gtk_style_context_notify_state_change() with a %NULL region
84 * is sufficient to trigger the transition animation. And GTK+ already
85 * does that when gtk_widget_set_state() or gtk_widget_set_state_flags()
89 * If a widget needs to declare several animatable regions (i.e. not
90 * affecting the whole widget area), its #GtkWidget::draw signal handler
91 * needs to wrap the render operations for the different regions with
92 * calls to gtk_style_context_push_animatable_region() and
93 * gtk_style_context_pop_animatable_region(). These functions take an
94 * identifier for the region which must be unique within the style context.
95 * For simple widgets with a fixed set of animatable regions, using an
96 * enumeration works well:
99 * <title>Using an enumeration to identify animatable regions</title>
110 * spin_button_draw (GtkWidget *widget,
113 * GtkStyleContext *context;
115 * context = gtk_widget_get_style_context (widget);
117 * gtk_style_context_push_animatable_region (context,
118 * GUINT_TO_POINTER (REGION_ENTRY));
120 * gtk_render_background (cr, 0, 0, 100, 30);
121 * gtk_render_frame (cr, 0, 0, 100, 30);
123 * gtk_style_context_pop_animatable_region (context);
130 * For complex widgets with an arbitrary number of animatable regions, it
131 * is up to the implementation to come up with a way to uniquely identify
132 * each animatable region. Using pointers to internal structs is one way
136 * <title>Using struct pointers to identify animatable regions</title>
139 * notebook_draw_tab (GtkWidget *widget,
140 * NotebookPage *page,
143 * gtk_style_context_push_animatable_region (context, page);
144 * gtk_render_extension (cr, page->x, page->y, page->width, page->height);
145 * gtk_style_context_pop_animatable_region (context);
150 * The widget also needs to notify the style context about a state change
151 * for a given animatable region so the animation is triggered.
154 * <title>Triggering a state change animation on a region</title>
157 * notebook_motion_notify (GtkWidget *widget,
158 * GdkEventMotion *event)
160 * GtkStyleContext *context;
161 * NotebookPage *page;
163 * context = gtk_widget_get_style_context (widget);
164 * page = find_page_under_pointer (widget, event);
165 * gtk_style_context_notify_state_change (context,
166 * gtk_widget_get_window (widget),
168 * GTK_STATE_PRELIGHT,
175 * gtk_style_context_notify_state_change() accepts %NULL region IDs as a
176 * special value, in this case, the whole widget area will be updated
180 * <refsect2 id="gtkstylecontext-classes">
181 * <title>Style classes and regions</title>
183 * Widgets can add style classes to their context, which can be used
184 * to associate different styles by class (see <xref linkend="gtkcssprovider-selectors"/>). Theme engines can also use style classes to vary their
185 * rendering. GTK+ has a number of predefined style classes:
186 * #GTK_STYLE_CLASS_CELL,
187 * #GTK_STYLE_CLASS_ENTRY,
188 * #GTK_STYLE_CLASS_BUTTON,
189 * #GTK_STYLE_CLASS_COMBOBOX_ENTRY,
190 * #GTK_STYLE_CLASS_CALENDAR,
191 * #GTK_STYLE_CLASS_SLIDER,
192 * #GTK_STYLE_CLASS_BACKGROUND,
193 * #GTK_STYLE_CLASS_RUBBERBAND,
194 * #GTK_STYLE_CLASS_TOOLTIP,
195 * #GTK_STYLE_CLASS_MENU,
196 * #GTK_STYLE_CLASS_MENUBAR,
197 * #GTK_STYLE_CLASS_MENUITEM,
198 * #GTK_STYLE_CLASS_TOOLBAR,
199 * #GTK_STYLE_CLASS_PRIMARY_TOOLBAR,
200 * #GTK_STYLE_CLASS_INLINE_TOOLBAR,
201 * #GTK_STYLE_CLASS_RADIO,
202 * #GTK_STYLE_CLASS_CHECK,
203 * #GTK_STYLE_CLASS_TROUGH,
204 * #GTK_STYLE_CLASS_SCROLLBAR,
205 * #GTK_STYLE_CLASS_SCALE,
206 * #GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE,
207 * #GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW,
208 * #GTK_STYLE_CLASS_HEADER,
209 * #GTK_STYLE_CLASS_ACCELERATOR,
210 * #GTK_STYLE_CLASS_GRIP,
211 * #GTK_STYLE_CLASS_DOCK,
212 * #GTK_STYLE_CLASS_PROGRESSBAR,
213 * #GTK_STYLE_CLASS_SPINNER,
214 * #GTK_STYLE_CLASS_EXPANDER,
215 * #GTK_STYLE_CLASS_SPINBUTTON,
216 * #GTK_STYLE_CLASS_NOTEBOOK,
217 * #GTK_STYLE_CLASS_VIEW,
218 * #GTK_STYLE_CLASS_SIDEBAR,
219 * #GTK_STYLE_CLASS_IMAGE,
220 * #GTK_STYLE_CLASS_HIGHLIGHT,
221 * #GTK_STYLE_CLASS_FRAME,
222 * #GTK_STYLE_CLASS_DND,
223 * #GTK_STYLE_CLASS_PANE_SEPARATOR,
224 * #GTK_STYLE_CLASS_SEPARATOR,
225 * #GTK_STYLE_CLASS_INFO,
226 * #GTK_STYLE_CLASS_WARNING,
227 * #GTK_STYLE_CLASS_QUESTION,
228 * #GTK_STYLE_CLASS_ERROR,
229 * #GTK_STYLE_CLASS_HORIZONTAL,
230 * #GTK_STYLE_CLASS_VERTICAL,
231 * #GTK_STYLE_CLASS_TOP,
232 * #GTK_STYLE_CLASS_BOTTOM,
233 * #GTK_STYLE_CLASS_LEFT,
234 * #GTK_STYLE_CLASS_RIGHT,
237 * Widgets can also add regions with flags to their context.
238 * The regions used by GTK+ widgets are:
243 * <entry>Region</entry>
244 * <entry>Flags</entry>
245 * <entry>Macro</entry>
246 * <entry>Used by</entry>
252 * <entry>even, odd</entry>
253 * <entry>GTK_STYLE_REGION_ROW</entry>
254 * <entry>#GtkTreeView</entry>
257 * <entry>column</entry>
258 * <entry>first, last, sorted</entry>
259 * <entry>GTK_STYLE_REGION_COLUMN</entry>
260 * <entry>#GtkTreeView</entry>
263 * <entry>column-header</entry>
265 * <entry>GTK_STYLE_REGION_COLUMN_HEADER</entry>
270 * <entry>even, odd, first, last</entry>
271 * <entry>GTK_STYLE_REGION_TAB</entry>
272 * <entry>#GtkNotebook</entry>
279 * <refsect2 id="gtkstylecontext-custom-styling">
280 * <title>Custom styling in UI libraries and applications</title>
282 * If you are developing a library with custom #GtkWidget<!-- -->s that
283 * render differently than standard components, you may need to add a
284 * #GtkStyleProvider yourself with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK
285 * priority, either a #GtkCssProvider or a custom object implementing the
286 * #GtkStyleProvider interface. This way theming engines may still attempt
287 * to style your UI elements in a different way if needed so.
290 * If you are using custom styling on an applications, you probably want then
291 * to make your style information prevail to the theme's, so you must use
292 * a #GtkStyleProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
293 * priority, keep in mind that the user settings in
294 * <filename><replaceable>XDG_CONFIG_HOME</replaceable>/gtk-3.0/gtk.css</filename> will
295 * still take precedence over your changes, as it uses the
296 * %GTK_STYLE_PROVIDER_PRIORITY_USER priority.
299 * If a custom theming engine is needed, you probably want to implement a
300 * #GtkStyleProvider yourself so it points to your #GtkThemingEngine
301 * implementation, as #GtkCssProvider uses gtk_theming_engine_load()
302 * which loads the theming engine module from the standard paths.
307 /* When these change we do a full restyling. Otherwise we try to figure out
308 * if we need to change things. */
309 #define GTK_STYLE_CONTEXT_RADICAL_CHANGE (GTK_CSS_CHANGE_NAME | GTK_CSS_CHANGE_CLASS | GTK_CSS_CHANGE_SOURCE)
310 /* When these change we don't clear the cache. This takes more memory but makes
311 * things go faster. */
312 #define GTK_STYLE_CONTEXT_CACHED_CHANGE (GTK_CSS_CHANGE_STATE)
314 typedef struct GtkStyleInfo GtkStyleInfo;
315 typedef struct GtkRegion GtkRegion;
316 typedef struct PropertyValue PropertyValue;
317 typedef struct StyleData StyleData;
322 GtkRegionFlags flags;
336 GArray *style_classes;
338 GtkJunctionSides junction_sides;
339 GtkStateFlags state_flags;
345 GtkCssComputedValues *store;
346 GArray *property_cache;
350 struct _GtkStyleContextPrivate
354 GtkStyleCascade *cascade;
356 GtkStyleContext *animation_list_prev;
357 GtkStyleContext *animation_list_next;
359 GtkStyleContext *parent;
362 GtkWidgetPath *widget_path;
363 GHashTable *style_data;
366 GtkTextDirection direction;
368 GtkCssChange relevant_changes;
369 GtkCssChange pending_changes;
371 guint invalidating_context : 1;
387 static guint signals[LAST_SIGNAL] = { 0 };
388 static GtkStyleContext *_running_animations = NULL;
389 guint _running_animations_timer_id = 0;
391 static void gtk_style_context_finalize (GObject *object);
393 static void gtk_style_context_impl_set_property (GObject *object,
397 static void gtk_style_context_impl_get_property (GObject *object,
401 static GtkSymbolicColor *
402 gtk_style_context_color_lookup_func (gpointer contextp,
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_IS_CSS_ANIMATED_VALUES (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 GtkStyleContextPrivate *priv = context->priv;
667 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_SOURCE);
669 gtk_style_context_invalidate (context);
673 gtk_style_context_set_cascade (GtkStyleContext *context,
674 GtkStyleCascade *cascade)
676 GtkStyleContextPrivate *priv;
678 priv = context->priv;
680 if (priv->cascade == cascade)
685 g_object_ref (cascade);
686 g_signal_connect (cascade,
687 "-gtk-private-changed",
688 G_CALLBACK (gtk_style_context_cascade_changed),
694 g_signal_handlers_disconnect_by_func (priv->cascade,
695 gtk_style_context_cascade_changed,
697 g_object_unref (priv->cascade);
700 priv->cascade = cascade;
703 gtk_style_context_cascade_changed (cascade, context);
707 gtk_style_context_init (GtkStyleContext *style_context)
709 GtkStyleContextPrivate *priv;
711 priv = style_context->priv = G_TYPE_INSTANCE_GET_PRIVATE (style_context,
712 GTK_TYPE_STYLE_CONTEXT,
713 GtkStyleContextPrivate);
715 priv->style_data = g_hash_table_new_full (style_info_hash,
717 (GDestroyNotify) style_info_free,
718 (GDestroyNotify) style_data_unref);
720 priv->direction = GTK_TEXT_DIR_LTR;
722 priv->screen = gdk_screen_get_default ();
723 priv->relevant_changes = GTK_CSS_CHANGE_ANY;
725 /* Create default info store */
726 priv->info = style_info_new ();
728 gtk_style_context_set_cascade (style_context,
729 _gtk_style_cascade_get_for_screen (priv->screen));
733 gtk_style_context_do_animations (gpointer unused)
735 GtkStyleContext *context;
737 for (context = _running_animations;
739 context = context->priv->animation_list_next)
741 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANIMATE);
748 gtk_style_context_is_animating (GtkStyleContext *context)
750 GtkStyleContextPrivate *priv = context->priv;
752 return priv->animation_list_prev != NULL
753 || _running_animations == context;
757 gtk_style_context_stop_animating (GtkStyleContext *context)
759 GtkStyleContextPrivate *priv = context->priv;
761 if (!gtk_style_context_is_animating (context))
764 if (priv->animation_list_prev == NULL)
766 _running_animations = priv->animation_list_next;
768 if (_running_animations == NULL)
770 /* we were the last animation */
771 g_source_remove (_running_animations_timer_id);
772 _running_animations_timer_id = 0;
776 priv->animation_list_prev->priv->animation_list_next = priv->animation_list_next;
778 if (priv->animation_list_next)
779 priv->animation_list_next->priv->animation_list_prev = priv->animation_list_prev;
781 priv->animation_list_next = NULL;
782 priv->animation_list_prev = NULL;
786 gtk_style_context_start_animating (GtkStyleContext *context)
788 GtkStyleContextPrivate *priv = context->priv;
790 if (gtk_style_context_is_animating (context))
793 if (_running_animations == NULL)
795 _running_animations_timer_id = gdk_threads_add_timeout (25,
796 gtk_style_context_do_animations,
798 _running_animations = context;
802 priv->animation_list_next = _running_animations;
803 _running_animations->priv->animation_list_prev = context;
804 _running_animations = context;
809 gtk_style_context_finalize (GObject *object)
811 GtkStyleContextPrivate *priv;
812 GtkStyleContext *style_context;
814 style_context = GTK_STYLE_CONTEXT (object);
815 priv = style_context->priv;
817 _gtk_style_context_stop_animations (style_context);
819 /* children hold a reference to us */
820 g_assert (priv->children == NULL);
822 gtk_style_context_set_parent (style_context, NULL);
824 gtk_style_context_set_cascade (style_context, NULL);
826 if (priv->widget_path)
827 gtk_widget_path_free (priv->widget_path);
829 g_hash_table_destroy (priv->style_data);
832 priv->info = style_info_pop (priv->info);
834 G_OBJECT_CLASS (gtk_style_context_parent_class)->finalize (object);
838 gtk_style_context_impl_set_property (GObject *object,
843 GtkStyleContext *style_context;
845 style_context = GTK_STYLE_CONTEXT (object);
850 gtk_style_context_set_screen (style_context,
851 g_value_get_object (value));
854 gtk_style_context_set_direction (style_context,
855 g_value_get_enum (value));
858 gtk_style_context_set_parent (style_context,
859 g_value_get_object (value));
862 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
868 gtk_style_context_impl_get_property (GObject *object,
873 GtkStyleContext *style_context;
874 GtkStyleContextPrivate *priv;
876 style_context = GTK_STYLE_CONTEXT (object);
877 priv = style_context->priv;
882 g_value_set_object (value, priv->screen);
885 g_value_set_enum (value, priv->direction);
888 g_value_set_object (value, priv->parent);
891 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
897 build_properties (GtkStyleContext *context,
898 StyleData *style_data,
902 GtkStyleContextPrivate *priv;
903 GtkCssMatcher matcher;
904 GtkCssLookup *lookup;
906 priv = context->priv;
908 lookup = _gtk_css_lookup_new ();
910 if (_gtk_css_matcher_init (&matcher, path, state))
911 _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
915 style_data->store = _gtk_css_computed_values_new ();
916 _gtk_css_lookup_resolve (lookup, context, style_data->store);
917 _gtk_css_lookup_free (lookup);
920 static GtkWidgetPath *
921 create_query_path (GtkStyleContext *context)
923 GtkStyleContextPrivate *priv;
928 priv = context->priv;
929 path = priv->widget ? _gtk_widget_create_path (priv->widget) : gtk_widget_path_copy (priv->widget_path);
930 pos = gtk_widget_path_length (path) - 1;
934 /* Set widget regions */
935 for (i = 0; i < info->regions->len; i++)
939 region = &g_array_index (info->regions, GtkRegion, i);
940 gtk_widget_path_iter_add_region (path, pos,
941 g_quark_to_string (region->class_quark),
945 /* Set widget classes */
946 for (i = 0; i < info->style_classes->len; i++)
950 quark = g_array_index (info->style_classes, GQuark, i);
951 gtk_widget_path_iter_add_class (path, pos,
952 g_quark_to_string (quark));
959 style_data_lookup (GtkStyleContext *context)
961 GtkStyleContextPrivate *priv;
966 priv = context->priv;
969 /* Current data in use is cached, just return it */
973 g_assert (priv->widget != NULL || priv->widget_path != NULL);
975 data = g_hash_table_lookup (priv->style_data, info);
978 style_info_set_data (info, data);
982 path = create_query_path (context);
984 data = style_data_new ();
985 style_info_set_data (info, data);
986 g_hash_table_insert (priv->style_data,
987 style_info_copy (info),
990 build_properties (context, data, path, info->state_flags);
992 gtk_widget_path_free (path);
998 style_data_lookup_for_state (GtkStyleContext *context,
1003 if (context->priv->info->state_flags == state)
1004 return style_data_lookup (context);
1006 gtk_style_context_save (context);
1007 gtk_style_context_set_state (context, state);
1008 data = style_data_lookup (context);
1009 gtk_style_context_restore (context);
1015 gtk_style_context_set_invalid (GtkStyleContext *context,
1018 GtkStyleContextPrivate *priv;
1020 priv = context->priv;
1022 if (priv->invalid == invalid)
1025 priv->invalid = invalid;
1030 gtk_style_context_set_invalid (priv->parent, TRUE);
1031 else if (GTK_IS_RESIZE_CONTAINER (priv->widget))
1032 _gtk_container_queue_restyle (GTK_CONTAINER (priv->widget));
1036 /* returns TRUE if someone called gtk_style_context_save() but hasn't
1037 * called gtk_style_context_restore() yet.
1038 * In those situations we don't invalidate the context when somebody
1039 * changes state/regions/classes.
1042 gtk_style_context_is_saved (GtkStyleContext *context)
1044 return context->priv->info->next != NULL;
1048 gtk_style_context_queue_invalidate_internal (GtkStyleContext *context,
1049 GtkCssChange change)
1051 GtkStyleContextPrivate *priv = context->priv;
1052 GtkStyleInfo *info = priv->info;
1054 if (gtk_style_context_is_saved (context))
1056 style_info_set_data (info, NULL);
1060 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_STATE);
1061 /* XXX: We need to invalidate siblings here somehow */
1066 * gtk_style_context_new:
1068 * Creates a standalone #GtkStyleContext, this style context
1069 * won't be attached to any widget, so you may want
1070 * to call gtk_style_context_set_path() yourself.
1073 * This function is only useful when using the theming layer
1074 * separated from GTK+, if you are using #GtkStyleContext to
1075 * theme #GtkWidget<!-- -->s, use gtk_widget_get_style_context()
1076 * in order to get a style context ready to theme the widget.
1079 * Returns: A newly created #GtkStyleContext.
1082 gtk_style_context_new (void)
1084 return g_object_new (GTK_TYPE_STYLE_CONTEXT, NULL);
1088 _gtk_style_context_set_widget (GtkStyleContext *context,
1091 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1092 g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget));
1094 context->priv->widget = widget;
1096 _gtk_style_context_stop_animations (context);
1098 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY_SELF);
1102 * gtk_style_context_add_provider:
1103 * @context: a #GtkStyleContext
1104 * @provider: a #GtkStyleProvider
1105 * @priority: the priority of the style provider. The lower
1106 * it is, the earlier it will be used in the style
1107 * construction. Typically this will be in the range
1108 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1109 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1111 * Adds a style provider to @context, to be used in style construction.
1113 * <note><para>If both priorities are the same, A #GtkStyleProvider
1114 * added through this function takes precedence over another added
1115 * through gtk_style_context_add_provider_for_screen().</para></note>
1120 gtk_style_context_add_provider (GtkStyleContext *context,
1121 GtkStyleProvider *provider,
1124 GtkStyleContextPrivate *priv;
1126 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1127 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1129 priv = context->priv;
1131 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
1133 GtkStyleCascade *new_cascade;
1135 new_cascade = _gtk_style_cascade_new ();
1136 _gtk_style_cascade_set_parent (new_cascade, priv->cascade);
1137 _gtk_style_cascade_add_provider (new_cascade, provider, priority);
1138 gtk_style_context_set_cascade (context, new_cascade);
1139 g_object_unref (new_cascade);
1143 _gtk_style_cascade_add_provider (priv->cascade, provider, priority);
1148 * gtk_style_context_remove_provider:
1149 * @context: a #GtkStyleContext
1150 * @provider: a #GtkStyleProvider
1152 * Removes @provider from the style providers list in @context.
1157 gtk_style_context_remove_provider (GtkStyleContext *context,
1158 GtkStyleProvider *provider)
1160 GtkStyleContextPrivate *priv;
1162 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1163 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1165 priv = context->priv;
1167 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
1170 _gtk_style_cascade_remove_provider (priv->cascade, provider);
1174 * gtk_style_context_reset_widgets:
1175 * @screen: a #GdkScreen
1177 * This function recomputes the styles for all widgets under a particular
1178 * #GdkScreen. This is useful when some global parameter has changed that
1179 * affects the appearance of all widgets, because when a widget gets a new
1180 * style, it will both redraw and recompute any cached information about
1181 * its appearance. As an example, it is used when the color scheme changes
1182 * in the related #GtkSettings object.
1187 gtk_style_context_reset_widgets (GdkScreen *screen)
1189 GList *list, *toplevels;
1191 _gtk_icon_set_invalidate_caches ();
1193 toplevels = gtk_window_list_toplevels ();
1194 g_list_foreach (toplevels, (GFunc) g_object_ref, NULL);
1196 for (list = toplevels; list; list = list->next)
1198 if (gtk_widget_get_screen (list->data) == screen)
1199 gtk_widget_reset_style (list->data);
1201 g_object_unref (list->data);
1204 g_list_free (toplevels);
1208 * gtk_style_context_add_provider_for_screen:
1209 * @screen: a #GdkScreen
1210 * @provider: a #GtkStyleProvider
1211 * @priority: the priority of the style provider. The lower
1212 * it is, the earlier it will be used in the style
1213 * construction. Typically this will be in the range
1214 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1215 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1217 * Adds a global style provider to @screen, which will be used
1218 * in style construction for all #GtkStyleContext<!-- -->s under
1221 * GTK+ uses this to make styling information from #GtkSettings
1224 * <note><para>If both priorities are the same, A #GtkStyleProvider
1225 * added through gtk_style_context_add_provider() takes precedence
1226 * over another added through this function.</para></note>
1231 gtk_style_context_add_provider_for_screen (GdkScreen *screen,
1232 GtkStyleProvider *provider,
1235 GtkStyleCascade *cascade;
1237 g_return_if_fail (GDK_IS_SCREEN (screen));
1238 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1240 cascade = _gtk_style_cascade_get_for_screen (screen);
1241 _gtk_style_cascade_add_provider (cascade, provider, priority);
1245 * gtk_style_context_remove_provider_for_screen:
1246 * @screen: a #GdkScreen
1247 * @provider: a #GtkStyleProvider
1249 * Removes @provider from the global style providers list in @screen.
1254 gtk_style_context_remove_provider_for_screen (GdkScreen *screen,
1255 GtkStyleProvider *provider)
1257 GtkStyleCascade *cascade;
1259 g_return_if_fail (GDK_IS_SCREEN (screen));
1260 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1262 cascade = _gtk_style_cascade_get_for_screen (screen);
1263 _gtk_style_cascade_remove_provider (cascade, provider);
1267 * gtk_style_context_get_section:
1268 * @context: a #GtkStyleContext
1269 * @property: style property name
1271 * Queries the location in the CSS where @property was defined for the
1272 * current @context. Note that the state to be queried is taken from
1273 * gtk_style_context_get_state().
1275 * If the location is not available, %NULL will be returned. The
1276 * location might not be available for various reasons, such as the
1277 * property being overridden, @property not naming a supported CSS
1278 * property or tracking of definitions being disabled for performance
1281 * Shorthand CSS properties cannot be queried for a location and will
1282 * always return %NULL.
1284 * Returns: %NULL or the section where value was defined
1287 gtk_style_context_get_section (GtkStyleContext *context,
1288 const gchar *property)
1290 GtkStyleContextPrivate *priv;
1291 GtkStyleProperty *prop;
1294 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1295 g_return_val_if_fail (property != NULL, NULL);
1297 priv = context->priv;
1298 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
1300 prop = _gtk_style_property_lookup (property);
1301 if (!GTK_IS_CSS_STYLE_PROPERTY (prop))
1304 data = style_data_lookup (context);
1305 return _gtk_css_computed_values_get_section (data->store, _gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (prop)));
1308 static GtkCssValue *
1309 gtk_style_context_query_func (guint id,
1312 return _gtk_css_computed_values_get_value (values, id);
1316 * gtk_style_context_get_property:
1317 * @context: a #GtkStyleContext
1318 * @property: style property name
1319 * @state: state to retrieve the property value for
1320 * @value: (out) (transfer full): return location for the style property value
1322 * Gets a style property from @context for the given state.
1324 * When @value is no longer needed, g_value_unset() must be called
1325 * to free any allocated memory.
1330 gtk_style_context_get_property (GtkStyleContext *context,
1331 const gchar *property,
1332 GtkStateFlags state,
1335 GtkStyleContextPrivate *priv;
1336 GtkStyleProperty *prop;
1339 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1340 g_return_if_fail (property != NULL);
1341 g_return_if_fail (value != NULL);
1343 priv = context->priv;
1344 g_return_if_fail (priv->widget != NULL || priv->widget_path != NULL);
1346 prop = _gtk_style_property_lookup (property);
1349 g_warning ("Style property \"%s\" is not registered", property);
1352 if (_gtk_style_property_get_value_type (prop) == G_TYPE_NONE)
1354 g_warning ("Style property \"%s\" is not gettable", property);
1358 data = style_data_lookup_for_state (context, state);
1359 _gtk_style_property_query (prop, value, gtk_style_context_query_func, data->store);
1363 * gtk_style_context_get_valist:
1364 * @context: a #GtkStyleContext
1365 * @state: state to retrieve the property values for
1366 * @args: va_list of property name/return location pairs, followed by %NULL
1368 * Retrieves several style property values from @context for a given state.
1373 gtk_style_context_get_valist (GtkStyleContext *context,
1374 GtkStateFlags state,
1377 const gchar *property_name;
1379 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1381 property_name = va_arg (args, const gchar *);
1383 while (property_name)
1385 gchar *error = NULL;
1386 GValue value = G_VALUE_INIT;
1388 gtk_style_context_get_property (context,
1393 G_VALUE_LCOPY (&value, args, 0, &error);
1394 g_value_unset (&value);
1398 g_warning ("Could not get style property \"%s\": %s", property_name, error);
1403 property_name = va_arg (args, const gchar *);
1408 * gtk_style_context_get:
1409 * @context: a #GtkStyleContext
1410 * @state: state to retrieve the property values for
1411 * @...: property name /return value pairs, followed by %NULL
1413 * Retrieves several style property values from @context for a
1419 gtk_style_context_get (GtkStyleContext *context,
1420 GtkStateFlags state,
1425 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1427 va_start (args, state);
1428 gtk_style_context_get_valist (context, state, args);
1433 * gtk_style_context_set_state:
1434 * @context: a #GtkStyleContext
1435 * @flags: state to represent
1437 * Sets the state to be used when rendering with any
1438 * of the gtk_render_*() functions.
1443 gtk_style_context_set_state (GtkStyleContext *context,
1444 GtkStateFlags flags)
1446 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1448 context->priv->info->state_flags = flags;
1450 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_STATE);
1454 * gtk_style_context_get_state:
1455 * @context: a #GtkStyleContext
1457 * Returns the state used when rendering.
1459 * Returns: the state flags
1464 gtk_style_context_get_state (GtkStyleContext *context)
1466 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
1468 return context->priv->info->state_flags;
1472 * gtk_style_context_state_is_running:
1473 * @context: a #GtkStyleContext
1474 * @state: a widget state
1475 * @progress: (out): return location for the transition progress
1477 * Returns %TRUE if there is a transition animation running for the
1478 * current region (see gtk_style_context_push_animatable_region()).
1480 * If @progress is not %NULL, the animation progress will be returned
1481 * there, 0.0 means the state is closest to being unset, while 1.0 means
1482 * it's closest to being set. This means transition animation will
1483 * run from 0 to 1 when @state is being set and from 1 to 0 when
1486 * Returns: %TRUE if there is a running transition animation for @state.
1490 * Deprecated: 3.6: This function always returns %FALSE
1493 gtk_style_context_state_is_running (GtkStyleContext *context,
1497 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1503 * gtk_style_context_set_path:
1504 * @context: a #GtkStyleContext
1505 * @path: a #GtkWidgetPath
1507 * Sets the #GtkWidgetPath used for style matching. As a
1508 * consequence, the style will be regenerated to match
1509 * the new given path.
1511 * If you are using a #GtkStyleContext returned from
1512 * gtk_widget_get_style_context(), you do not need to call
1518 gtk_style_context_set_path (GtkStyleContext *context,
1519 GtkWidgetPath *path)
1521 GtkStyleContextPrivate *priv;
1523 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1524 g_return_if_fail (path != NULL);
1526 priv = context->priv;
1527 g_return_if_fail (priv->widget == NULL);
1529 if (priv->widget_path)
1531 gtk_widget_path_free (priv->widget_path);
1532 priv->widget_path = NULL;
1536 priv->widget_path = gtk_widget_path_copy (path);
1538 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY);
1542 * gtk_style_context_get_path:
1543 * @context: a #GtkStyleContext
1545 * Returns the widget path used for style matching.
1547 * Returns: (transfer none): A #GtkWidgetPath
1551 const GtkWidgetPath *
1552 gtk_style_context_get_path (GtkStyleContext *context)
1554 GtkStyleContextPrivate *priv;
1556 priv = context->priv;
1558 return gtk_widget_get_path (priv->widget);
1560 return priv->widget_path;
1564 * gtk_style_context_set_parent:
1565 * @context: a #GtkStyleContext
1566 * @parent: (allow-none): the new parent or %NULL
1568 * Sets the parent style context for @context. The parent style
1569 * context is used to implement
1570 * <ulink url="http://www.w3.org/TR/css3-cascade/#inheritance">inheritance</ulink>
1573 * If you are using a #GtkStyleContext returned from
1574 * gtk_widget_get_style_context(), the parent will be set for you.
1579 gtk_style_context_set_parent (GtkStyleContext *context,
1580 GtkStyleContext *parent)
1582 GtkStyleContextPrivate *priv;
1584 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1585 g_return_if_fail (parent == NULL || GTK_IS_STYLE_CONTEXT (parent));
1587 priv = context->priv;
1589 if (priv->parent == parent)
1594 parent->priv->children = g_slist_prepend (parent->priv->children, context);
1595 g_object_ref (parent);
1597 gtk_style_context_set_invalid (parent, TRUE);
1602 priv->parent->priv->children = g_slist_remove (priv->parent->priv->children, context);
1603 g_object_unref (priv->parent);
1606 priv->parent = parent;
1608 g_object_notify (G_OBJECT (context), "parent");
1609 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY_PARENT | GTK_CSS_CHANGE_ANY_SIBLING);
1613 * gtk_style_context_get_parent:
1614 * @context: a #GtkStyleContext
1616 * Gets the parent context set via gtk_style_context_set_parent().
1617 * See that function for details.
1619 * Returns: (transfer none): the parent context or %NULL
1624 gtk_style_context_get_parent (GtkStyleContext *context)
1626 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1628 return context->priv->parent;
1632 * gtk_style_context_save:
1633 * @context: a #GtkStyleContext
1635 * Saves the @context state, so all modifications done through
1636 * gtk_style_context_add_class(), gtk_style_context_remove_class(),
1637 * gtk_style_context_add_region(), gtk_style_context_remove_region()
1638 * or gtk_style_context_set_junction_sides() can be reverted in one
1639 * go through gtk_style_context_restore().
1644 gtk_style_context_save (GtkStyleContext *context)
1646 GtkStyleContextPrivate *priv;
1648 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1650 priv = context->priv;
1652 priv->info = style_info_copy (priv->info);
1653 /* Need to unset animations here because we can not know what style
1654 * class potential transitions came from once we save().
1656 if (priv->info->data && style_data_is_animating (priv->info->data))
1657 style_info_set_data (priv->info, NULL);
1661 * gtk_style_context_restore:
1662 * @context: a #GtkStyleContext
1664 * Restores @context state to a previous stage.
1665 * See gtk_style_context_save().
1670 gtk_style_context_restore (GtkStyleContext *context)
1672 GtkStyleContextPrivate *priv;
1674 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1676 priv = context->priv;
1678 priv->info = style_info_pop (priv->info);
1682 g_warning ("Unpaired gtk_style_context_restore() call");
1684 /* Create default region */
1685 priv->info = style_info_new ();
1690 style_class_find (GArray *array,
1695 gboolean found = FALSE;
1701 if (!array || array->len == 0)
1705 max = array->len - 1;
1711 mid = (min + max) / 2;
1712 item = g_array_index (array, GQuark, mid);
1714 if (class_quark == item)
1719 else if (class_quark > item)
1720 min = pos = mid + 1;
1727 while (!found && min <= max);
1736 region_find (GArray *array,
1741 gboolean found = FALSE;
1747 if (!array || array->len == 0)
1751 max = array->len - 1;
1757 mid = (min + max) / 2;
1758 region = &g_array_index (array, GtkRegion, mid);
1760 if (region->class_quark == class_quark)
1765 else if (region->class_quark > class_quark)
1766 min = pos = mid + 1;
1773 while (!found && min <= max);
1782 * gtk_style_context_add_class:
1783 * @context: a #GtkStyleContext
1784 * @class_name: class name to use in styling
1786 * Adds a style class to @context, so posterior calls to
1787 * gtk_style_context_get() or any of the gtk_render_*()
1788 * functions will make use of this new class for styling.
1790 * In the CSS file format, a #GtkEntry defining an "entry"
1791 * class, would be matched by:
1794 * GtkEntry.entry { ... }
1797 * While any widget defining an "entry" class would be
1806 gtk_style_context_add_class (GtkStyleContext *context,
1807 const gchar *class_name)
1809 GtkStyleContextPrivate *priv;
1814 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1815 g_return_if_fail (class_name != NULL);
1817 priv = context->priv;
1818 class_quark = g_quark_from_string (class_name);
1822 if (!style_class_find (info->style_classes, class_quark, &position))
1824 g_array_insert_val (info->style_classes, position, class_quark);
1826 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_CLASS);
1831 * gtk_style_context_remove_class:
1832 * @context: a #GtkStyleContext
1833 * @class_name: class name to remove
1835 * Removes @class_name from @context.
1840 gtk_style_context_remove_class (GtkStyleContext *context,
1841 const gchar *class_name)
1843 GtkStyleContextPrivate *priv;
1848 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1849 g_return_if_fail (class_name != NULL);
1851 class_quark = g_quark_try_string (class_name);
1856 priv = context->priv;
1860 if (style_class_find (info->style_classes, class_quark, &position))
1862 g_array_remove_index (info->style_classes, position);
1864 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_CLASS);
1869 * gtk_style_context_has_class:
1870 * @context: a #GtkStyleContext
1871 * @class_name: a class name
1873 * Returns %TRUE if @context currently has defined the
1876 * Returns: %TRUE if @context has @class_name defined
1881 gtk_style_context_has_class (GtkStyleContext *context,
1882 const gchar *class_name)
1884 GtkStyleContextPrivate *priv;
1888 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1889 g_return_val_if_fail (class_name != NULL, FALSE);
1891 class_quark = g_quark_try_string (class_name);
1896 priv = context->priv;
1900 if (style_class_find (info->style_classes, class_quark, NULL))
1907 * gtk_style_context_list_classes:
1908 * @context: a #GtkStyleContext
1910 * Returns the list of classes currently defined in @context.
1912 * Returns: (transfer container) (element-type utf8): a #GList of
1913 * strings with the currently defined classes. The contents
1914 * of the list are owned by GTK+, but you must free the list
1915 * itself with g_list_free() when you are done with it.
1920 gtk_style_context_list_classes (GtkStyleContext *context)
1922 GtkStyleContextPrivate *priv;
1924 GList *classes = NULL;
1927 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1929 priv = context->priv;
1933 for (i = 0; i < info->style_classes->len; i++)
1937 quark = g_array_index (info->style_classes, GQuark, i);
1938 classes = g_list_prepend (classes, (gchar *) g_quark_to_string (quark));
1945 * gtk_style_context_list_regions:
1946 * @context: a #GtkStyleContext
1948 * Returns the list of regions currently defined in @context.
1950 * Returns: (transfer container) (element-type utf8): a #GList of
1951 * strings with the currently defined regions. The contents
1952 * of the list are owned by GTK+, but you must free the list
1953 * itself with g_list_free() when you are done with it.
1958 gtk_style_context_list_regions (GtkStyleContext *context)
1960 GtkStyleContextPrivate *priv;
1962 GList *classes = NULL;
1965 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1967 priv = context->priv;
1971 for (i = 0; i < info->regions->len; i++)
1974 const gchar *class_name;
1976 region = &g_array_index (info->regions, GtkRegion, i);
1978 class_name = g_quark_to_string (region->class_quark);
1979 classes = g_list_prepend (classes, (gchar *) class_name);
1986 _gtk_style_context_check_region_name (const gchar *str)
1988 g_return_val_if_fail (str != NULL, FALSE);
1990 if (!g_ascii_islower (str[0]))
1996 !g_ascii_islower (*str))
2006 * gtk_style_context_add_region:
2007 * @context: a #GtkStyleContext
2008 * @region_name: region name to use in styling
2009 * @flags: flags that apply to the region
2011 * Adds a region to @context, so posterior calls to
2012 * gtk_style_context_get() or any of the gtk_render_*()
2013 * functions will make use of this new region for styling.
2015 * In the CSS file format, a #GtkTreeView defining a "row"
2016 * region, would be matched by:
2019 * GtkTreeView row { ... }
2022 * Pseudo-classes are used for matching @flags, so the two
2025 * GtkTreeView row:nth-child(even) { ... }
2026 * GtkTreeView row:nth-child(odd) { ... }
2029 * would apply to even and odd rows, respectively.
2031 * <note><para>Region names must only contain lowercase letters
2032 * and '-', starting always with a lowercase letter.</para></note>
2037 gtk_style_context_add_region (GtkStyleContext *context,
2038 const gchar *region_name,
2039 GtkRegionFlags flags)
2041 GtkStyleContextPrivate *priv;
2043 GQuark region_quark;
2046 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2047 g_return_if_fail (region_name != NULL);
2048 g_return_if_fail (_gtk_style_context_check_region_name (region_name));
2050 priv = context->priv;
2051 region_quark = g_quark_from_string (region_name);
2055 if (!region_find (info->regions, region_quark, &position))
2059 region.class_quark = region_quark;
2060 region.flags = flags;
2062 g_array_insert_val (info->regions, position, region);
2064 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_REGION);
2069 * gtk_style_context_remove_region:
2070 * @context: a #GtkStyleContext
2071 * @region_name: region name to unset
2073 * Removes a region from @context.
2078 gtk_style_context_remove_region (GtkStyleContext *context,
2079 const gchar *region_name)
2081 GtkStyleContextPrivate *priv;
2083 GQuark region_quark;
2086 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2087 g_return_if_fail (region_name != NULL);
2089 region_quark = g_quark_try_string (region_name);
2094 priv = context->priv;
2098 if (region_find (info->regions, region_quark, &position))
2100 g_array_remove_index (info->regions, position);
2102 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_REGION);
2107 * gtk_style_context_has_region:
2108 * @context: a #GtkStyleContext
2109 * @region_name: a region name
2110 * @flags_return: (out) (allow-none): return location for region flags
2112 * Returns %TRUE if @context has the region defined.
2113 * If @flags_return is not %NULL, it is set to the flags
2114 * affecting the region.
2116 * Returns: %TRUE if region is defined
2121 gtk_style_context_has_region (GtkStyleContext *context,
2122 const gchar *region_name,
2123 GtkRegionFlags *flags_return)
2125 GtkStyleContextPrivate *priv;
2127 GQuark region_quark;
2130 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2131 g_return_val_if_fail (region_name != NULL, FALSE);
2136 region_quark = g_quark_try_string (region_name);
2141 priv = context->priv;
2145 if (region_find (info->regions, region_quark, &position))
2151 region = &g_array_index (info->regions, GtkRegion, position);
2152 *flags_return = region->flags;
2161 style_property_values_cmp (gconstpointer bsearch_node1,
2162 gconstpointer bsearch_node2)
2164 const PropertyValue *val1 = bsearch_node1;
2165 const PropertyValue *val2 = bsearch_node2;
2167 if (val1->widget_type != val2->widget_type)
2168 return val1->widget_type < val2->widget_type ? -1 : 1;
2170 if (val1->pspec != val2->pspec)
2171 return val1->pspec < val2->pspec ? -1 : 1;
2173 if (val1->state != val2->state)
2174 return val1->state < val2->state ? -1 : 1;
2180 _gtk_style_context_peek_property (GtkStyleContext *context,
2183 StyleData *data = style_data_lookup (context);
2185 return _gtk_css_computed_values_get_value (data->store, property_id);
2189 _gtk_style_context_get_number (GtkStyleContext *context,
2191 double one_hundred_percent)
2195 value = _gtk_style_context_peek_property (context, property_id);
2196 return _gtk_css_number_value_get (value, one_hundred_percent);
2200 _gtk_style_context_peek_style_property (GtkStyleContext *context,
2202 GtkStateFlags state,
2205 GtkStyleContextPrivate *priv;
2206 PropertyValue *pcache, key = { 0 };
2210 priv = context->priv;
2212 data = style_data_lookup_for_state (context, state);
2214 key.widget_type = widget_type;
2218 /* need value cache array */
2219 if (!data->property_cache)
2220 data->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
2223 pcache = bsearch (&key,
2224 data->property_cache->data, data->property_cache->len,
2225 sizeof (PropertyValue), style_property_values_cmp);
2227 return &pcache->value;
2231 while (i < data->property_cache->len &&
2232 style_property_values_cmp (&key, &g_array_index (data->property_cache, PropertyValue, i)) >= 0)
2235 g_array_insert_val (data->property_cache, i, key);
2236 pcache = &g_array_index (data->property_cache, PropertyValue, i);
2238 /* cache miss, initialize value type, then set contents */
2239 g_param_spec_ref (pcache->pspec);
2240 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2242 if (priv->widget || priv->widget_path)
2244 GtkWidgetPath *widget_path = priv->widget ? _gtk_widget_create_path (priv->widget) : priv->widget_path;
2246 if (gtk_style_provider_get_style_property (GTK_STYLE_PROVIDER (priv->cascade),
2248 state, pspec, &pcache->value))
2250 /* Resolve symbolic colors to GdkColor/GdkRGBA */
2251 if (G_VALUE_TYPE (&pcache->value) == GTK_TYPE_SYMBOLIC_COLOR)
2253 GtkSymbolicColor *color;
2256 color = g_value_dup_boxed (&pcache->value);
2258 g_value_unset (&pcache->value);
2260 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2261 g_value_init (&pcache->value, GDK_TYPE_RGBA);
2263 g_value_init (&pcache->value, GDK_TYPE_COLOR);
2265 if (_gtk_style_context_resolve_color (context, color, &rgba))
2267 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2268 g_value_set_boxed (&pcache->value, &rgba);
2273 rgb.red = rgba.red * 65535. + 0.5;
2274 rgb.green = rgba.green * 65535. + 0.5;
2275 rgb.blue = rgba.blue * 65535. + 0.5;
2277 g_value_set_boxed (&pcache->value, &rgb);
2281 g_param_value_set_default (pspec, &pcache->value);
2283 gtk_symbolic_color_unref (color);
2287 gtk_widget_path_free (widget_path);
2289 return &pcache->value;
2293 gtk_widget_path_free (widget_path);
2296 /* not supplied by any provider, revert to default */
2297 g_param_value_set_default (pspec, &pcache->value);
2299 return &pcache->value;
2303 * gtk_style_context_get_style_property:
2304 * @context: a #GtkStyleContext
2305 * @property_name: the name of the widget style property
2306 * @value: Return location for the property value
2308 * Gets the value for a widget style property.
2310 * When @value is no longer needed, g_value_unset() must be called
2311 * to free any allocated memory.
2314 gtk_style_context_get_style_property (GtkStyleContext *context,
2315 const gchar *property_name,
2318 GtkStyleContextPrivate *priv;
2319 GtkWidgetClass *widget_class;
2320 GtkStateFlags state;
2322 const GValue *peek_value;
2325 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2326 g_return_if_fail (property_name != NULL);
2327 g_return_if_fail (value != NULL);
2329 priv = context->priv;
2333 widget_type = G_OBJECT_TYPE (priv->widget);
2337 if (!priv->widget_path)
2340 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2342 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2344 g_warning ("%s: can't get style properties for non-widget class `%s'",
2346 g_type_name (widget_type));
2351 widget_class = g_type_class_ref (widget_type);
2352 pspec = gtk_widget_class_find_style_property (widget_class, property_name);
2353 g_type_class_unref (widget_class);
2357 g_warning ("%s: widget class `%s' has no style property named `%s'",
2359 g_type_name (widget_type),
2364 state = gtk_style_context_get_state (context);
2365 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2368 if (G_VALUE_TYPE (value) == G_VALUE_TYPE (peek_value))
2369 g_value_copy (peek_value, value);
2370 else if (g_value_type_transformable (G_VALUE_TYPE (peek_value), G_VALUE_TYPE (value)))
2371 g_value_transform (peek_value, value);
2373 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
2375 G_VALUE_TYPE_NAME (peek_value),
2376 G_VALUE_TYPE_NAME (value));
2380 * gtk_style_context_get_style_valist:
2381 * @context: a #GtkStyleContext
2382 * @args: va_list of property name/return location pairs, followed by %NULL
2384 * Retrieves several widget style properties from @context according to the
2390 gtk_style_context_get_style_valist (GtkStyleContext *context,
2393 GtkStyleContextPrivate *priv;
2394 const gchar *prop_name;
2395 GtkStateFlags state;
2398 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2400 prop_name = va_arg (args, const gchar *);
2401 priv = context->priv;
2405 widget_type = G_OBJECT_TYPE (priv->widget);
2409 if (!priv->widget_path)
2412 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2414 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2416 g_warning ("%s: can't get style properties for non-widget class `%s'",
2418 g_type_name (widget_type));
2423 state = gtk_style_context_get_state (context);
2427 GtkWidgetClass *widget_class;
2429 const GValue *peek_value;
2432 widget_class = g_type_class_ref (widget_type);
2433 pspec = gtk_widget_class_find_style_property (widget_class, prop_name);
2434 g_type_class_unref (widget_class);
2438 g_warning ("%s: widget class `%s' has no style property named `%s'",
2440 g_type_name (widget_type),
2445 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2448 G_VALUE_LCOPY (peek_value, args, 0, &error);
2452 g_warning ("can't retrieve style property `%s' of type `%s': %s",
2454 G_VALUE_TYPE_NAME (peek_value),
2460 prop_name = va_arg (args, const gchar *);
2465 * gtk_style_context_get_style:
2466 * @context: a #GtkStyleContext
2467 * @...: property name /return value pairs, followed by %NULL
2469 * Retrieves several widget style properties from @context according to the
2475 gtk_style_context_get_style (GtkStyleContext *context,
2480 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2482 va_start (args, context);
2483 gtk_style_context_get_style_valist (context, args);
2489 * gtk_style_context_lookup_icon_set:
2490 * @context: a #GtkStyleContext
2491 * @stock_id: an icon name
2493 * Looks up @stock_id in the icon factories associated to @context and
2494 * the default icon factory, returning an icon set if found, otherwise
2497 * Returns: (transfer none): The looked up %GtkIconSet, or %NULL
2500 gtk_style_context_lookup_icon_set (GtkStyleContext *context,
2501 const gchar *stock_id)
2503 GtkStyleContextPrivate *priv;
2505 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2506 g_return_val_if_fail (stock_id != NULL, NULL);
2508 priv = context->priv;
2509 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
2511 return gtk_icon_factory_lookup_default (stock_id);
2515 * gtk_style_context_set_screen:
2516 * @context: a #GtkStyleContext
2517 * @screen: a #GdkScreen
2519 * Attaches @context to the given screen.
2521 * The screen is used to add style information from 'global' style
2522 * providers, such as the screens #GtkSettings instance.
2524 * If you are using a #GtkStyleContext returned from
2525 * gtk_widget_get_style_context(), you do not need to
2526 * call this yourself.
2531 gtk_style_context_set_screen (GtkStyleContext *context,
2534 GtkStyleContextPrivate *priv;
2536 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2537 g_return_if_fail (GDK_IS_SCREEN (screen));
2539 priv = context->priv;
2540 if (priv->screen == screen)
2543 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
2545 gtk_style_context_set_cascade (context, _gtk_style_cascade_get_for_screen (screen));
2549 _gtk_style_cascade_set_parent (priv->cascade, _gtk_style_cascade_get_for_screen (screen));
2552 priv->screen = screen;
2554 g_object_notify (G_OBJECT (context), "screen");
2556 gtk_style_context_invalidate (context);
2560 * gtk_style_context_get_screen:
2561 * @context: a #GtkStyleContext
2563 * Returns the #GdkScreen to which @context is attached.
2565 * Returns: (transfer none): a #GdkScreen.
2568 gtk_style_context_get_screen (GtkStyleContext *context)
2570 GtkStyleContextPrivate *priv;
2572 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2574 priv = context->priv;
2575 return priv->screen;
2579 * gtk_style_context_set_direction:
2580 * @context: a #GtkStyleContext
2581 * @direction: the new direction.
2583 * Sets the reading direction for rendering purposes.
2585 * If you are using a #GtkStyleContext returned from
2586 * gtk_widget_get_style_context(), you do not need to
2587 * call this yourself.
2592 gtk_style_context_set_direction (GtkStyleContext *context,
2593 GtkTextDirection direction)
2595 GtkStyleContextPrivate *priv;
2597 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2599 priv = context->priv;
2600 priv->direction = direction;
2602 g_object_notify (G_OBJECT (context), "direction");
2606 * gtk_style_context_get_direction:
2607 * @context: a #GtkStyleContext
2609 * Returns the widget direction used for rendering.
2611 * Returns: the widget direction
2616 gtk_style_context_get_direction (GtkStyleContext *context)
2618 GtkStyleContextPrivate *priv;
2620 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), GTK_TEXT_DIR_LTR);
2622 priv = context->priv;
2623 return priv->direction;
2627 * gtk_style_context_set_junction_sides:
2628 * @context: a #GtkStyleContext
2629 * @sides: sides where rendered elements are visually connected to
2632 * Sets the sides where rendered elements (mostly through
2633 * gtk_render_frame()) will visually connect with other visual elements.
2635 * This is merely a hint that may or may not be honored
2636 * by theming engines.
2638 * Container widgets are expected to set junction hints as appropriate
2639 * for their children, so it should not normally be necessary to call
2640 * this function manually.
2645 gtk_style_context_set_junction_sides (GtkStyleContext *context,
2646 GtkJunctionSides sides)
2648 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2650 context->priv->info->junction_sides = sides;
2654 * gtk_style_context_get_junction_sides:
2655 * @context: a #GtkStyleContext
2657 * Returns the sides where rendered elements connect visually with others.
2659 * Returns: the junction sides
2664 gtk_style_context_get_junction_sides (GtkStyleContext *context)
2666 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
2668 return context->priv->info->junction_sides;
2671 static GtkSymbolicColor *
2672 gtk_style_context_color_lookup_func (gpointer contextp,
2675 GtkStyleContext *context = contextp;
2677 return _gtk_style_provider_private_get_color (GTK_STYLE_PROVIDER_PRIVATE (context->priv->cascade), name);
2681 _gtk_style_context_resolve_color_value (GtkStyleContext *context,
2682 GtkCssValue *current,
2685 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2686 g_return_val_if_fail (current != NULL, FALSE);
2687 g_return_val_if_fail (color != NULL, FALSE);
2689 return _gtk_symbolic_color_resolve_full ((GtkSymbolicColor *) color,
2691 gtk_style_context_color_lookup_func,
2697 _gtk_style_context_resolve_color (GtkStyleContext *context,
2698 GtkSymbolicColor *color,
2703 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2704 g_return_val_if_fail (color != NULL, FALSE);
2705 g_return_val_if_fail (result != NULL, FALSE);
2707 val = _gtk_symbolic_color_resolve_full (color,
2708 _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR),
2709 gtk_style_context_color_lookup_func,
2714 *result = *_gtk_css_rgba_value_get_rgba (val);
2715 _gtk_css_value_unref (val);
2720 * gtk_style_context_lookup_color:
2721 * @context: a #GtkStyleContext
2722 * @color_name: color name to lookup
2723 * @color: (out): Return location for the looked up color
2725 * Looks up and resolves a color name in the @context color map.
2727 * Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
2730 gtk_style_context_lookup_color (GtkStyleContext *context,
2731 const gchar *color_name,
2734 GtkSymbolicColor *sym_color;
2736 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2737 g_return_val_if_fail (color_name != NULL, FALSE);
2738 g_return_val_if_fail (color != NULL, FALSE);
2740 sym_color = gtk_style_context_color_lookup_func (context, color_name);
2741 if (sym_color == NULL)
2744 return _gtk_style_context_resolve_color (context, sym_color, color);
2748 * gtk_style_context_notify_state_change:
2749 * @context: a #GtkStyleContext
2750 * @window: a #GdkWindow
2751 * @region_id: (allow-none): animatable region to notify on, or %NULL.
2752 * See gtk_style_context_push_animatable_region()
2753 * @state: state to trigger transition for
2754 * @state_value: %TRUE if @state is the state we are changing to,
2755 * %FALSE if we are changing away from it
2757 * Notifies a state change on @context, so if the current style makes use
2758 * of transition animations, one will be started so all rendered elements
2759 * under @region_id are animated for state @state being set to value
2762 * The @window parameter is used in order to invalidate the rendered area
2763 * as the animation runs, so make sure it is the same window that is being
2764 * rendered on by the gtk_render_*() functions.
2766 * If @region_id is %NULL, all rendered elements using @context will be
2767 * affected by this state transition.
2769 * As a practical example, a #GtkButton notifying a state transition on
2770 * the prelight state:
2772 * gtk_style_context_notify_state_change (context,
2773 * gtk_widget_get_window (widget),
2775 * GTK_STATE_PRELIGHT,
2776 * button->in_button);
2779 * Can be handled in the CSS file like this:
2782 * background-color: #f00
2786 * background-color: #fff;
2787 * transition: 200ms linear
2791 * This combination will animate the button background from red to white
2792 * if a pointer enters the button, and back to red if the pointer leaves
2795 * Note that @state is used when finding the transition parameters, which
2796 * is why the style places the transition under the :hover pseudo-class.
2800 * Deprecated: 3.6: This function does nothing.
2803 gtk_style_context_notify_state_change (GtkStyleContext *context,
2807 gboolean state_value)
2809 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2810 g_return_if_fail (GDK_IS_WINDOW (window));
2811 g_return_if_fail (state > GTK_STATE_NORMAL && state <= GTK_STATE_FOCUSED);
2812 g_return_if_fail (context->priv->widget != NULL || context->priv->widget_path != NULL);
2816 * gtk_style_context_cancel_animations:
2817 * @context: a #GtkStyleContext
2818 * @region_id: (allow-none): animatable region to stop, or %NULL.
2819 * See gtk_style_context_push_animatable_region()
2821 * Stops all running animations for @region_id and all animatable
2822 * regions underneath.
2824 * A %NULL @region_id will stop all ongoing animations in @context,
2825 * when dealing with a #GtkStyleContext obtained through
2826 * gtk_widget_get_style_context(), this is normally done for you
2827 * in all circumstances you would expect all widget to be stopped,
2828 * so this should be only used in complex widgets with different
2829 * animatable regions.
2833 * Deprecated: 3.6: This function does nothing.
2836 gtk_style_context_cancel_animations (GtkStyleContext *context,
2839 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2843 * gtk_style_context_scroll_animations:
2844 * @context: a #GtkStyleContext
2845 * @window: a #GdkWindow used previously in
2846 * gtk_style_context_notify_state_change()
2847 * @dx: Amount to scroll in the X axis
2848 * @dy: Amount to scroll in the Y axis
2850 * This function is analogous to gdk_window_scroll(), and
2851 * should be called together with it so the invalidation
2852 * areas for any ongoing animation are scrolled together
2857 * Deprecated: 3.6: This function does nothing.
2860 gtk_style_context_scroll_animations (GtkStyleContext *context,
2865 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2866 g_return_if_fail (GDK_IS_WINDOW (window));
2870 * gtk_style_context_push_animatable_region:
2871 * @context: a #GtkStyleContext
2872 * @region_id: unique identifier for the animatable region
2874 * Pushes an animatable region, so all further gtk_render_*() calls between
2875 * this call and the following gtk_style_context_pop_animatable_region()
2876 * will potentially show transition animations for this region if
2877 * gtk_style_context_notify_state_change() is called for a given state,
2878 * and the current theme/style defines transition animations for state
2881 * The @region_id used must be unique in @context so the theming engine
2882 * can uniquely identify rendered elements subject to a state transition.
2886 * Deprecated: 3.6: This function does nothing.
2889 gtk_style_context_push_animatable_region (GtkStyleContext *context,
2892 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2893 g_return_if_fail (region_id != NULL);
2897 * gtk_style_context_pop_animatable_region:
2898 * @context: a #GtkStyleContext
2900 * Pops an animatable region from @context.
2901 * See gtk_style_context_push_animatable_region().
2905 * Deprecated: 3.6: This function does nothing.
2908 gtk_style_context_pop_animatable_region (GtkStyleContext *context)
2910 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2914 gtk_style_context_clear_cache (GtkStyleContext *context)
2916 GtkStyleContextPrivate *priv;
2919 priv = context->priv;
2921 for (info = priv->info; info; info = info->next)
2923 style_info_set_data (info, NULL);
2925 g_hash_table_remove_all (priv->style_data);
2929 gtk_style_context_do_invalidate (GtkStyleContext *context)
2931 GtkStyleContextPrivate *priv;
2933 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2935 priv = context->priv;
2937 /* Avoid reentrancy */
2938 if (priv->invalidating_context)
2941 priv->invalidating_context = TRUE;
2943 g_signal_emit (context, signals[CHANGED], 0);
2945 priv->invalidating_context = FALSE;
2949 _gtk_style_context_stop_animations (GtkStyleContext *context)
2951 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2953 if (!gtk_style_context_is_animating (context))
2956 style_info_set_data (context->priv->info, NULL);
2958 gtk_style_context_stop_animating (context);
2962 gtk_style_context_update_animations (GtkStyleContext *context,
2965 GtkBitmask *differences;
2966 StyleData *style_data;
2968 style_data = style_data_lookup (context);
2970 differences = _gtk_css_animated_values_advance (GTK_CSS_ANIMATED_VALUES (style_data->store),
2973 if (_gtk_css_animated_values_is_finished (GTK_CSS_ANIMATED_VALUES (style_data->store)))
2974 _gtk_style_context_stop_animations (context);
2980 gtk_style_context_should_animate (GtkStyleContext *context)
2982 GtkStyleContextPrivate *priv;
2985 priv = context->priv;
2987 if (priv->widget == NULL)
2990 if (!gtk_widget_get_mapped (priv->widget))
2993 g_object_get (gtk_widget_get_settings (context->priv->widget),
2994 "gtk-enable-animations", &animate,
3001 gtk_style_context_start_animations (GtkStyleContext *context,
3002 GtkCssComputedValues *previous,
3005 StyleData *animated;
3007 if (!gtk_style_context_should_animate (context))
3009 gtk_style_context_stop_animating (context);
3013 animated = style_data_new ();
3014 animated->store = _gtk_css_animated_values_new (style_data_lookup (context)->store,
3018 if (_gtk_css_animated_values_is_finished (GTK_CSS_ANIMATED_VALUES (animated->store)))
3020 style_data_unref (animated);
3021 gtk_style_context_stop_animating (context);
3025 style_info_set_data (context->priv->info, animated);
3026 style_data_unref (animated);
3027 gtk_style_context_start_animating (context);
3031 _gtk_style_context_validate (GtkStyleContext *context,
3033 GtkCssChange change)
3035 GtkStyleContextPrivate *priv;
3036 GtkBitmask *changes;
3039 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3041 priv = context->priv;
3043 change |= priv->pending_changes;
3045 if (!priv->invalid && change == 0)
3048 priv->pending_changes = 0;
3049 gtk_style_context_set_invalid (context, FALSE);
3051 /* Try to avoid invalidating if we can */
3052 if (change & GTK_STYLE_CONTEXT_RADICAL_CHANGE)
3054 priv->relevant_changes = GTK_CSS_CHANGE_ANY;
3058 if (priv->relevant_changes == GTK_CSS_CHANGE_ANY)
3060 GtkWidgetPath *path;
3061 GtkCssMatcher matcher;
3063 path = create_query_path (context);
3064 if (_gtk_css_matcher_init (&matcher, path, priv->info->state_flags))
3065 priv->relevant_changes = _gtk_style_provider_private_get_change (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
3068 priv->relevant_changes = 0;
3070 priv->relevant_changes &= ~GTK_STYLE_CONTEXT_RADICAL_CHANGE;
3072 gtk_widget_path_unref (path);
3076 if (priv->relevant_changes & change)
3078 GtkStyleInfo *info = priv->info;
3082 current = style_data_ref (info->data);
3086 if ((priv->relevant_changes & change) & ~GTK_STYLE_CONTEXT_CACHED_CHANGE)
3087 gtk_style_context_clear_cache (context);
3089 style_info_set_data (info, NULL);
3095 gtk_style_context_start_animations (context, current->store, timestamp);
3096 change &= ~GTK_CSS_CHANGE_ANIMATE;
3098 data = style_data_lookup (context);
3100 changes = _gtk_css_computed_values_get_difference (data->store, current->store);
3102 style_data_unref (current);
3106 changes = _gtk_bitmask_new ();
3107 changes = _gtk_bitmask_invert_range (changes, 0, _gtk_css_style_property_get_n_properties ());
3111 changes = _gtk_bitmask_new ();
3113 if (change & GTK_CSS_CHANGE_ANIMATE &&
3114 gtk_style_context_is_animating (context))
3116 GtkBitmask *animation_changes;
3118 animation_changes = gtk_style_context_update_animations (context, timestamp);
3119 changes = _gtk_bitmask_union (changes, animation_changes);
3120 _gtk_bitmask_free (animation_changes);
3123 if (!_gtk_bitmask_is_empty (changes))
3124 gtk_style_context_do_invalidate (context);
3126 change = _gtk_css_change_for_child (change);
3127 for (list = priv->children; list; list = list->next)
3129 _gtk_style_context_validate (list->data, timestamp, change);
3132 _gtk_bitmask_free (changes);
3136 _gtk_style_context_queue_invalidate (GtkStyleContext *context,
3137 GtkCssChange change)
3139 GtkStyleContextPrivate *priv;
3141 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3142 g_return_if_fail (change != 0);
3144 priv = context->priv;
3146 if (priv->widget == NULL && priv->widget_path == NULL)
3149 priv->pending_changes |= change;
3150 gtk_style_context_set_invalid (context, TRUE);
3154 * gtk_style_context_invalidate:
3155 * @context: a #GtkStyleContext.
3157 * Invalidates @context style information, so it will be reconstructed
3160 * If you're using a #GtkStyleContext returned from
3161 * gtk_widget_get_style_context(), you do not need to
3162 * call this yourself.
3167 gtk_style_context_invalidate (GtkStyleContext *context)
3169 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3171 gtk_style_context_clear_cache (context);
3172 gtk_style_context_do_invalidate (context);
3176 * gtk_style_context_set_background:
3177 * @context: a #GtkStyleContext
3178 * @window: a #GdkWindow
3180 * Sets the background of @window to the background pattern or
3181 * color specified in @context for its current state.
3186 gtk_style_context_set_background (GtkStyleContext *context,
3189 GtkStateFlags state;
3190 cairo_pattern_t *pattern;
3193 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3194 g_return_if_fail (GDK_IS_WINDOW (window));
3196 state = gtk_style_context_get_state (context);
3197 gtk_style_context_get (context, state,
3198 "background-image", &pattern,
3202 gdk_window_set_background_pattern (window, pattern);
3203 cairo_pattern_destroy (pattern);
3207 gtk_style_context_get (context, state,
3208 "background-color", &color,
3212 gdk_window_set_background_rgba (window, color);
3213 gdk_rgba_free (color);
3218 * gtk_style_context_get_color:
3219 * @context: a #GtkStyleContext
3220 * @state: state to retrieve the color for
3221 * @color: (out): return value for the foreground color
3223 * Gets the foreground color for a given state.
3228 gtk_style_context_get_color (GtkStyleContext *context,
3229 GtkStateFlags state,
3234 g_return_if_fail (color != NULL);
3235 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3237 gtk_style_context_get (context,
3247 * gtk_style_context_get_background_color:
3248 * @context: a #GtkStyleContext
3249 * @state: state to retrieve the color for
3250 * @color: (out): return value for the background color
3252 * Gets the background color for a given state.
3257 gtk_style_context_get_background_color (GtkStyleContext *context,
3258 GtkStateFlags state,
3263 g_return_if_fail (color != NULL);
3264 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3266 gtk_style_context_get (context,
3268 "background-color", &c,
3276 * gtk_style_context_get_border_color:
3277 * @context: a #GtkStyleContext
3278 * @state: state to retrieve the color for
3279 * @color: (out): return value for the border color
3281 * Gets the border color for a given state.
3286 gtk_style_context_get_border_color (GtkStyleContext *context,
3287 GtkStateFlags state,
3292 g_return_if_fail (color != NULL);
3293 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3295 gtk_style_context_get (context,
3305 * gtk_style_context_get_border:
3306 * @context: a #GtkStyleContext
3307 * @state: state to retrieve the border for
3308 * @border: (out): return value for the border settings
3310 * Gets the border for a given state as a #GtkBorder.
3311 * See %GTK_STYLE_PROPERTY_BORDER_WIDTH.
3316 gtk_style_context_get_border (GtkStyleContext *context,
3317 GtkStateFlags state,
3320 int top, left, bottom, right;
3322 g_return_if_fail (border != NULL);
3323 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3325 gtk_style_context_get (context,
3327 "border-top-width", &top,
3328 "border-left-width", &left,
3329 "border-bottom-width", &bottom,
3330 "border-right-width", &right,
3334 border->left = left;
3335 border->bottom = bottom;
3336 border->right = right;
3340 * gtk_style_context_get_padding:
3341 * @context: a #GtkStyleContext
3342 * @state: state to retrieve the padding for
3343 * @padding: (out): return value for the padding settings
3345 * Gets the padding for a given state as a #GtkBorder.
3346 * See %GTK_STYLE_PROPERTY_PADDING.
3351 gtk_style_context_get_padding (GtkStyleContext *context,
3352 GtkStateFlags state,
3355 int top, left, bottom, right;
3357 g_return_if_fail (padding != NULL);
3358 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3360 gtk_style_context_get (context,
3362 "padding-top", &top,
3363 "padding-left", &left,
3364 "padding-bottom", &bottom,
3365 "padding-right", &right,
3369 padding->left = left;
3370 padding->bottom = bottom;
3371 padding->right = right;
3375 * gtk_style_context_get_margin:
3376 * @context: a #GtkStyleContext
3377 * @state: state to retrieve the border for
3378 * @margin: (out): return value for the margin settings
3380 * Gets the margin for a given state as a #GtkBorder.
3381 * See %GTK_STYLE_PROPERTY_MARGIN.
3386 gtk_style_context_get_margin (GtkStyleContext *context,
3387 GtkStateFlags state,
3390 int top, left, bottom, right;
3392 g_return_if_fail (margin != NULL);
3393 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3395 gtk_style_context_get (context,
3398 "margin-left", &left,
3399 "margin-bottom", &bottom,
3400 "margin-right", &right,
3404 margin->left = left;
3405 margin->bottom = bottom;
3406 margin->right = right;
3410 * gtk_style_context_get_font:
3411 * @context: a #GtkStyleContext
3412 * @state: state to retrieve the font for
3414 * Returns the font description for a given state. The returned
3415 * object is const and will remain valid until the
3416 * #GtkStyleContext::changed signal happens.
3418 * Returns: (transfer none): the #PangoFontDescription for the given
3419 * state. This object is owned by GTK+ and should not be
3424 const PangoFontDescription *
3425 gtk_style_context_get_font (GtkStyleContext *context,
3426 GtkStateFlags state)
3428 GtkStyleContextPrivate *priv;
3430 PangoFontDescription *description;
3432 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
3434 priv = context->priv;
3435 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
3437 data = style_data_lookup_for_state (context, state);
3439 /* Yuck, fonts are created on-demand but we don't return a ref.
3440 * Do bad things to achieve this requirement */
3441 description = g_object_get_data (G_OBJECT (data->store), "font-cache-for-get_font");
3442 if (description == NULL)
3444 gtk_style_context_get (context, state, "font", &description, NULL);
3445 g_object_set_data_full (G_OBJECT (data->store),
3446 "font-cache-for-get_font",
3448 (GDestroyNotify) pango_font_description_free);
3454 get_cursor_color (GtkStyleContext *context,
3458 GdkColor *style_color;
3460 gtk_style_context_get_style (context,
3461 primary ? "cursor-color" : "secondary-cursor-color",
3467 color->red = style_color->red / 65535.0;
3468 color->green = style_color->green / 65535.0;
3469 color->blue = style_color->blue / 65535.0;
3472 gdk_color_free (style_color);
3476 gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, color);
3482 gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &bg);
3484 color->red = (color->red + bg.red) * 0.5;
3485 color->green = (color->green + bg.green) * 0.5;
3486 color->blue = (color->blue + bg.blue) * 0.5;
3492 _gtk_style_context_get_cursor_color (GtkStyleContext *context,
3493 GdkRGBA *primary_color,
3494 GdkRGBA *secondary_color)
3497 get_cursor_color (context, TRUE, primary_color);
3499 if (secondary_color)
3500 get_cursor_color (context, FALSE, secondary_color);
3507 * @context: a #GtkStyleContext
3509 * @x: X origin of the rectangle
3510 * @y: Y origin of the rectangle
3511 * @width: rectangle width
3512 * @height: rectangle height
3514 * Renders a checkmark (as in a #GtkCheckButton).
3516 * The %GTK_STATE_FLAG_ACTIVE state determines whether the check is
3517 * on or off, and %GTK_STATE_FLAG_INCONSISTENT determines whether it
3518 * should be marked as undefined.
3521 * <title>Typical checkmark rendering</title>
3522 * <inlinegraphic fileref="checks.png" format="PNG"/>
3528 gtk_render_check (GtkStyleContext *context,
3535 GtkThemingEngineClass *engine_class;
3536 GtkThemingEngine *engine;
3538 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3539 g_return_if_fail (cr != NULL);
3541 if (width <= 0 || height <= 0)
3544 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3545 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3550 _gtk_theming_engine_set_context (engine, context);
3551 engine_class->render_check (engine, cr,
3552 x, y, width, height);
3558 * gtk_render_option:
3559 * @context: a #GtkStyleContext
3561 * @x: X origin of the rectangle
3562 * @y: Y origin of the rectangle
3563 * @width: rectangle width
3564 * @height: rectangle height
3566 * Renders an option mark (as in a #GtkRadioButton), the %GTK_STATE_FLAG_ACTIVE
3567 * state will determine whether the option is on or off, and
3568 * %GTK_STATE_FLAG_INCONSISTENT whether it should be marked as undefined.
3571 * <title>Typical option mark rendering</title>
3572 * <inlinegraphic fileref="options.png" format="PNG"/>
3578 gtk_render_option (GtkStyleContext *context,
3585 GtkThemingEngineClass *engine_class;
3586 GtkThemingEngine *engine;
3588 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3589 g_return_if_fail (cr != NULL);
3591 if (width <= 0 || height <= 0)
3594 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3595 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3599 _gtk_theming_engine_set_context (engine, context);
3600 engine_class->render_option (engine, cr,
3601 x, y, width, height);
3608 * @context: a #GtkStyleContext
3610 * @angle: arrow angle from 0 to 2 * %G_PI, being 0 the arrow pointing to the north
3611 * @x: X origin of the render area
3612 * @y: Y origin of the render area
3613 * @size: square side for render area
3615 * Renders an arrow pointing to @angle.
3618 * <title>Typical arrow rendering at 0, 1&solidus;2 π, π and 3&solidus;2 π</title>
3619 * <inlinegraphic fileref="arrows.png" format="PNG"/>
3625 gtk_render_arrow (GtkStyleContext *context,
3632 GtkThemingEngineClass *engine_class;
3633 GtkThemingEngine *engine;
3635 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3636 g_return_if_fail (cr != NULL);
3641 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3642 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3646 gtk_style_context_save (context);
3647 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ARROW);
3649 _gtk_theming_engine_set_context (engine, context);
3650 engine_class->render_arrow (engine, cr,
3653 gtk_style_context_restore (context);
3658 * gtk_render_background:
3659 * @context: a #GtkStyleContext
3661 * @x: X origin of the rectangle
3662 * @y: Y origin of the rectangle
3663 * @width: rectangle width
3664 * @height: rectangle height
3666 * Renders the background of an element.
3669 * <title>Typical background rendering, showing the effect of
3670 * <parameter>background-image</parameter>,
3671 * <parameter>border-width</parameter> and
3672 * <parameter>border-radius</parameter></title>
3673 * <inlinegraphic fileref="background.png" format="PNG"/>
3679 gtk_render_background (GtkStyleContext *context,
3686 GtkThemingEngineClass *engine_class;
3687 GtkThemingEngine *engine;
3689 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3690 g_return_if_fail (cr != NULL);
3692 if (width <= 0 || height <= 0)
3695 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3696 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3700 _gtk_theming_engine_set_context (engine, context);
3701 engine_class->render_background (engine, cr, x, y, width, height);
3708 * @context: a #GtkStyleContext
3710 * @x: X origin of the rectangle
3711 * @y: Y origin of the rectangle
3712 * @width: rectangle width
3713 * @height: rectangle height
3715 * Renders a frame around the rectangle defined by @x, @y, @width, @height.
3718 * <title>Examples of frame rendering, showing the effect of
3719 * <parameter>border-image</parameter>,
3720 * <parameter>border-color</parameter>,
3721 * <parameter>border-width</parameter>,
3722 * <parameter>border-radius</parameter> and
3724 * <inlinegraphic fileref="frames.png" format="PNG"/>
3730 gtk_render_frame (GtkStyleContext *context,
3737 GtkThemingEngineClass *engine_class;
3738 GtkThemingEngine *engine;
3740 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3741 g_return_if_fail (cr != NULL);
3743 if (width <= 0 || height <= 0)
3746 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3747 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3751 _gtk_theming_engine_set_context (engine, context);
3752 engine_class->render_frame (engine, cr, x, y, width, height);
3758 * gtk_render_expander:
3759 * @context: a #GtkStyleContext
3761 * @x: X origin of the rectangle
3762 * @y: Y origin of the rectangle
3763 * @width: rectangle width
3764 * @height: rectangle height
3766 * Renders an expander (as used in #GtkTreeView and #GtkExpander) in the area
3767 * defined by @x, @y, @width, @height. The state %GTK_STATE_FLAG_ACTIVE
3768 * determines whether the expander is collapsed or expanded.
3771 * <title>Typical expander rendering</title>
3772 * <inlinegraphic fileref="expanders.png" format="PNG"/>
3778 gtk_render_expander (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_expander (engine, cr, x, y, width, height);
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 a focus indicator on the rectangle determined by @x, @y, @width, @height.
3816 * <title>Typical focus rendering</title>
3817 * <inlinegraphic fileref="focus.png" format="PNG"/>
3823 gtk_render_focus (GtkStyleContext *context,
3830 GtkThemingEngineClass *engine_class;
3831 GtkThemingEngine *engine;
3833 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3834 g_return_if_fail (cr != NULL);
3836 if (width <= 0 || height <= 0)
3839 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3840 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3844 _gtk_theming_engine_set_context (engine, context);
3845 engine_class->render_focus (engine, cr, x, y, width, height);
3851 * gtk_render_layout:
3852 * @context: a #GtkStyleContext
3856 * @layout: the #PangoLayout to render
3858 * Renders @layout on the coordinates @x, @y
3863 gtk_render_layout (GtkStyleContext *context,
3867 PangoLayout *layout)
3869 GtkThemingEngineClass *engine_class;
3870 GtkThemingEngine *engine;
3871 PangoRectangle extents;
3873 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3874 g_return_if_fail (PANGO_IS_LAYOUT (layout));
3875 g_return_if_fail (cr != NULL);
3877 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3878 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3882 pango_layout_get_extents (layout, &extents, NULL);
3884 _gtk_theming_engine_set_context (engine, context);
3885 engine_class->render_layout (engine, cr, x, y, layout);
3892 * @context: a #GtkStyleContext
3894 * @x0: X coordinate for the origin of the line
3895 * @y0: Y coordinate for the origin of the line
3896 * @x1: X coordinate for the end of the line
3897 * @y1: Y coordinate for the end of the line
3899 * Renders a line from (x0, y0) to (x1, y1).
3904 gtk_render_line (GtkStyleContext *context,
3911 GtkThemingEngineClass *engine_class;
3912 GtkThemingEngine *engine;
3914 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3915 g_return_if_fail (cr != NULL);
3917 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3918 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3922 _gtk_theming_engine_set_context (engine, context);
3923 engine_class->render_line (engine, cr, x0, y0, x1, y1);
3929 * gtk_render_slider:
3930 * @context: a #GtkStyleContext
3932 * @x: X origin of the rectangle
3933 * @y: Y origin of the rectangle
3934 * @width: rectangle width
3935 * @height: rectangle height
3936 * @orientation: orientation of the slider
3938 * Renders a slider (as in #GtkScale) in the rectangle defined by @x, @y,
3939 * @width, @height. @orientation defines whether the slider is vertical
3943 * <title>Typical slider rendering</title>
3944 * <inlinegraphic fileref="sliders.png" format="PNG"/>
3950 gtk_render_slider (GtkStyleContext *context,
3956 GtkOrientation orientation)
3958 GtkThemingEngineClass *engine_class;
3959 GtkThemingEngine *engine;
3961 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3962 g_return_if_fail (cr != NULL);
3964 if (width <= 0 || height <= 0)
3967 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3968 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3972 _gtk_theming_engine_set_context (engine, context);
3973 engine_class->render_slider (engine, cr, x, y, width, height, orientation);
3979 * gtk_render_frame_gap:
3980 * @context: a #GtkStyleContext
3982 * @x: X origin of the rectangle
3983 * @y: Y origin of the rectangle
3984 * @width: rectangle width
3985 * @height: rectangle height
3986 * @gap_side: side where the gap is
3987 * @xy0_gap: initial coordinate (X or Y depending on @gap_side) for the gap
3988 * @xy1_gap: end coordinate (X or Y depending on @gap_side) for the gap
3990 * Renders a frame around the rectangle defined by (@x, @y, @width, @height),
3991 * leaving a gap on one side. @xy0_gap and @xy1_gap will mean X coordinates
3992 * for %GTK_POS_TOP and %GTK_POS_BOTTOM gap sides, and Y coordinates for
3993 * %GTK_POS_LEFT and %GTK_POS_RIGHT.
3996 * <title>Typical rendering of a frame with a gap</title>
3997 * <inlinegraphic fileref="frame-gap.png" format="PNG"/>
4003 gtk_render_frame_gap (GtkStyleContext *context,
4009 GtkPositionType gap_side,
4013 GtkThemingEngineClass *engine_class;
4014 GtkThemingEngine *engine;
4016 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4017 g_return_if_fail (cr != NULL);
4018 g_return_if_fail (xy0_gap <= xy1_gap);
4019 g_return_if_fail (xy0_gap >= 0);
4021 if (width <= 0 || height <= 0)
4024 if (gap_side == GTK_POS_LEFT ||
4025 gap_side == GTK_POS_RIGHT)
4026 g_return_if_fail (xy1_gap <= height);
4028 g_return_if_fail (xy1_gap <= width);
4030 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4031 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4035 _gtk_theming_engine_set_context (engine, context);
4036 engine_class->render_frame_gap (engine, cr,
4037 x, y, width, height, gap_side,
4044 * gtk_render_extension:
4045 * @context: a #GtkStyleContext
4047 * @x: X origin of the rectangle
4048 * @y: Y origin of the rectangle
4049 * @width: rectangle width
4050 * @height: rectangle height
4051 * @gap_side: side where the gap is
4053 * Renders a extension (as in a #GtkNotebook tab) in the rectangle
4054 * defined by @x, @y, @width, @height. The side where the extension
4055 * connects to is defined by @gap_side.
4058 * <title>Typical extension rendering</title>
4059 * <inlinegraphic fileref="extensions.png" format="PNG"/>
4065 gtk_render_extension (GtkStyleContext *context,
4071 GtkPositionType gap_side)
4073 GtkThemingEngineClass *engine_class;
4074 GtkThemingEngine *engine;
4076 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4077 g_return_if_fail (cr != NULL);
4079 if (width <= 0 || height <= 0)
4082 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4083 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4087 _gtk_theming_engine_set_context (engine, context);
4088 engine_class->render_extension (engine, cr, x, y, width, height, gap_side);
4094 * gtk_render_handle:
4095 * @context: a #GtkStyleContext
4097 * @x: X origin of the rectangle
4098 * @y: Y origin of the rectangle
4099 * @width: rectangle width
4100 * @height: rectangle height
4102 * Renders a handle (as in #GtkHandleBox, #GtkPaned and
4103 * #GtkWindow<!-- -->'s resize grip), in the rectangle
4104 * determined by @x, @y, @width, @height.
4107 * <title>Handles rendered for the paned and grip classes</title>
4108 * <inlinegraphic fileref="handles.png" format="PNG"/>
4114 gtk_render_handle (GtkStyleContext *context,
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_handle (engine, cr, x, y, width, height);
4142 * gtk_render_activity:
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 an activity area (Such as in #GtkSpinner or the
4151 * fill line in #GtkRange), the state %GTK_STATE_FLAG_ACTIVE
4152 * determines whether there is activity going on.
4157 gtk_render_activity (GtkStyleContext *context,
4164 GtkThemingEngineClass *engine_class;
4165 GtkThemingEngine *engine;
4167 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4168 g_return_if_fail (cr != NULL);
4170 if (width <= 0 || height <= 0)
4173 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4174 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4178 _gtk_theming_engine_set_context (engine, context);
4179 engine_class->render_activity (engine, cr, x, y, width, height);
4185 * gtk_render_icon_pixbuf:
4186 * @context: a #GtkStyleContext
4187 * @source: the #GtkIconSource specifying the icon to render
4188 * @size: (type int): the size to render the icon at. A size of (GtkIconSize) -1
4189 * means render at the size of the source and don't scale.
4191 * Renders the icon specified by @source at the given @size, returning the result
4194 * Returns: (transfer full): a newly-created #GdkPixbuf containing the rendered icon
4199 gtk_render_icon_pixbuf (GtkStyleContext *context,
4200 const GtkIconSource *source,
4203 GtkThemingEngineClass *engine_class;
4204 GtkThemingEngine *engine;
4206 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
4207 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
4208 g_return_val_if_fail (source != NULL, NULL);
4210 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4211 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4213 _gtk_theming_engine_set_context (engine, context);
4214 return engine_class->render_icon_pixbuf (engine, source, size);
4219 * @context: a #GtkStyleContext
4221 * @pixbuf: a #GdkPixbuf containing the icon to draw
4222 * @x: X position for the @pixbuf
4223 * @y: Y position for the @pixbuf
4225 * Renders the icon in @pixbuf at the specified @x and @y coordinates.
4230 gtk_render_icon (GtkStyleContext *context,
4236 GtkThemingEngineClass *engine_class;
4237 GtkThemingEngine *engine;
4239 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4240 g_return_if_fail (cr != NULL);
4242 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4243 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4247 _gtk_theming_engine_set_context (engine, context);
4248 engine_class->render_icon (engine, cr, pixbuf, x, y);
4254 draw_insertion_cursor (GtkStyleContext *context,
4259 gboolean is_primary,
4260 PangoDirection direction,
4261 gboolean draw_arrow)
4264 GdkRGBA primary_color;
4265 GdkRGBA secondary_color;
4266 gfloat cursor_aspect_ratio;
4272 _gtk_style_context_get_cursor_color (context, &primary_color, &secondary_color);
4273 gdk_cairo_set_source_rgba (cr, is_primary ? &primary_color : &secondary_color);
4275 /* When changing the shape or size of the cursor here,
4276 * propagate the changes to gtktextview.c:text_window_invalidate_cursors().
4279 gtk_style_context_get_style (context,
4280 "cursor-aspect-ratio", &cursor_aspect_ratio,
4283 stem_width = height * cursor_aspect_ratio + 1;
4285 /* put (stem_width % 2) on the proper side of the cursor */
4286 if (direction == PANGO_DIRECTION_LTR)
4287 offset = stem_width / 2;
4289 offset = stem_width - stem_width / 2;
4291 cairo_rectangle (cr, x - offset, y, stem_width, height);
4299 arrow_width = stem_width + 1;
4301 if (direction == PANGO_DIRECTION_RTL)
4303 ax = x - offset - 1;
4304 ay = y + height - arrow_width * 2 - arrow_width + 1;
4306 cairo_move_to (cr, ax, ay + 1);
4307 cairo_line_to (cr, ax - arrow_width, ay + arrow_width);
4308 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4311 else if (direction == PANGO_DIRECTION_LTR)
4313 ax = x + stem_width - offset;
4314 ay = y + height - arrow_width * 2 - arrow_width + 1;
4316 cairo_move_to (cr, ax, ay + 1);
4317 cairo_line_to (cr, ax + arrow_width, ay + arrow_width);
4318 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4322 g_assert_not_reached();
4329 * gtk_render_insertion_cursor:
4330 * @context: a #GtkStyleContext
4334 * @layout: the #PangoLayout of the text
4335 * @index: the index in the #PangoLayout
4336 * @direction: the #PangoDirection of the text
4338 * Draws a text caret on @cr at the specified index of @layout.
4343 gtk_render_insertion_cursor (GtkStyleContext *context,
4347 PangoLayout *layout,
4349 PangoDirection direction)
4351 GtkStyleContextPrivate *priv;
4352 gboolean split_cursor;
4353 PangoRectangle strong_pos, weak_pos;
4354 PangoRectangle *cursor1, *cursor2;
4355 PangoDirection keymap_direction;
4356 PangoDirection direction2;
4358 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4359 g_return_if_fail (cr != NULL);
4360 g_return_if_fail (PANGO_IS_LAYOUT (layout));
4361 g_return_if_fail (index >= 0);
4363 priv = context->priv;
4365 g_object_get (gtk_settings_get_for_screen (priv->screen),
4366 "gtk-split-cursor", &split_cursor,
4369 keymap_direction = gdk_keymap_get_direction (gdk_keymap_get_for_display (gdk_screen_get_display (priv->screen)));
4371 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4373 direction2 = PANGO_DIRECTION_NEUTRAL;
4377 cursor1 = &strong_pos;
4379 if (strong_pos.x != weak_pos.x || strong_pos.y != weak_pos.y)
4381 direction2 = (direction == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
4382 cursor2 = &weak_pos;
4387 if (keymap_direction == direction)
4388 cursor1 = &strong_pos;
4390 cursor1 = &weak_pos;
4393 draw_insertion_cursor (context,
4395 x + PANGO_PIXELS (cursor1->x),
4396 y + PANGO_PIXELS (cursor1->y),
4397 PANGO_PIXELS (cursor1->height),
4400 direction2 != PANGO_DIRECTION_NEUTRAL);
4402 if (direction2 != PANGO_DIRECTION_NEUTRAL)
4404 draw_insertion_cursor (context,
4406 x + PANGO_PIXELS (cursor2->x),
4407 y + PANGO_PIXELS (cursor2->y),
4408 PANGO_PIXELS (cursor2->height),
4416 * gtk_draw_insertion_cursor:
4417 * @widget: a #GtkWidget
4418 * @cr: cairo context to draw to
4419 * @location: location where to draw the cursor (@location->width is ignored)
4420 * @is_primary: if the cursor should be the primary cursor color.
4421 * @direction: whether the cursor is left-to-right or
4422 * right-to-left. Should never be #GTK_TEXT_DIR_NONE
4423 * @draw_arrow: %TRUE to draw a directional arrow on the
4424 * cursor. Should be %FALSE unless the cursor is split.
4426 * Draws a text caret on @cr at @location. This is not a style function
4427 * but merely a convenience function for drawing the standard cursor shape.
4430 * Deprecated: 3.4: Use gtk_render_insertion_cursor() instead.
4433 gtk_draw_insertion_cursor (GtkWidget *widget,
4435 const GdkRectangle *location,
4436 gboolean is_primary,
4437 GtkTextDirection direction,
4438 gboolean draw_arrow)
4440 GtkStyleContext *context;
4442 g_return_if_fail (GTK_IS_WIDGET (widget));
4443 g_return_if_fail (cr != NULL);
4444 g_return_if_fail (location != NULL);
4445 g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
4447 context = gtk_widget_get_style_context (widget);
4449 draw_insertion_cursor (context, cr,
4450 location->x, location->y, location->height,
4452 (direction == GTK_TEXT_DIR_RTL) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR,
4456 static AtkAttributeSet *
4457 add_attribute (AtkAttributeSet *attributes,
4458 AtkTextAttribute attr,
4463 at = g_new (AtkAttribute, 1);
4464 at->name = g_strdup (atk_text_attribute_get_name (attr));
4465 at->value = g_strdup (value);
4467 return g_slist_prepend (attributes, at);
4471 * _gtk_style_context_get_attributes:
4472 * @attributes: a #AtkAttributeSet to add attributes to
4473 * @context: the #GtkStyleContext to get attributes from
4474 * @flags: the state to use with @context
4476 * Adds the foreground and background color from @context to
4477 * @attributes, after translating them to ATK attributes.
4479 * This is a convenience function that can be used in
4480 * implementing the #AtkText interface in widgets.
4482 * Returns: the modified #AtkAttributeSet
4485 _gtk_style_context_get_attributes (AtkAttributeSet *attributes,
4486 GtkStyleContext *context,
4487 GtkStateFlags flags)
4492 gtk_style_context_get_background_color (context, flags, &color);
4493 value = g_strdup_printf ("%u,%u,%u",
4494 (guint) ceil (color.red * 65536 - color.red),
4495 (guint) ceil (color.green * 65536 - color.green),
4496 (guint) ceil (color.blue * 65536 - color.blue));
4497 attributes = add_attribute (attributes, ATK_TEXT_ATTR_BG_COLOR, value);
4500 gtk_style_context_get_color (context, flags, &color);
4501 value = g_strdup_printf ("%u,%u,%u",
4502 (guint) ceil (color.red * 65536 - color.red),
4503 (guint) ceil (color.green * 65536 - color.green),
4504 (guint) ceil (color.blue * 65536 - color.blue));
4505 attributes = add_attribute (attributes, ATK_TEXT_ATTR_FG_COLOR, value);