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 "gtkcsscolorvalueprivate.h"
28 #include "gtkcssenginevalueprivate.h"
29 #include "gtkcssnumbervalueprivate.h"
30 #include "gtkcssrgbavalueprivate.h"
32 #include "gtkgradientprivate.h"
33 #include "gtkstylepropertiesprivate.h"
34 #include "gtktypebuiltins.h"
35 #include "gtkthemingengineprivate.h"
37 #include "gtkwidget.h"
38 #include "gtkwindow.h"
39 #include "gtkprivate.h"
40 #include "gtksymboliccolorprivate.h"
41 #include "gtkiconfactory.h"
42 #include "gtkwidgetpath.h"
43 #include "gtkwidgetprivate.h"
44 #include "gtkstylecascadeprivate.h"
45 #include "gtkstyleproviderprivate.h"
46 #include "gtksettings.h"
47 #include "gtksettingsprivate.h"
50 * SECTION:gtkstylecontext
51 * @Short_description: Rendering UI elements
52 * @Title: GtkStyleContext
54 * #GtkStyleContext is an object that stores styling information affecting
55 * a widget defined by #GtkWidgetPath.
57 * In order to construct the final style information, #GtkStyleContext
58 * queries information from all attached #GtkStyleProviders. Style providers
59 * can be either attached explicitly to the context through
60 * gtk_style_context_add_provider(), or to the screen through
61 * gtk_style_context_add_provider_for_screen(). The resulting style is a
62 * combination of all providers' information in priority order.
64 * For GTK+ widgets, any #GtkStyleContext returned by
65 * gtk_widget_get_style_context() will already have a #GtkWidgetPath, a
66 * #GdkScreen and RTL/LTR information set. The style context will be also
67 * updated automatically if any of these settings change on the widget.
69 * If you are using the theming layer standalone, you will need to set a
70 * widget path and a screen yourself to the created style context through
71 * gtk_style_context_set_path() and gtk_style_context_set_screen(), as well
72 * as updating the context yourself using gtk_style_context_invalidate()
73 * whenever any of the conditions change, such as a change in the
74 * #GtkSettings:gtk-theme-name setting or a hierarchy change in the rendered
77 * <refsect2 id="gtkstylecontext-animations">
78 * <title>Transition animations</title>
80 * #GtkStyleContext has built-in support for state change transitions.
81 * Note that these animations respect the #GtkSettings:gtk-enable-animations
85 * For simple widgets where state changes affect the whole widget area,
86 * calling gtk_style_context_notify_state_change() with a %NULL region
87 * is sufficient to trigger the transition animation. And GTK+ already
88 * does that when gtk_widget_set_state() or gtk_widget_set_state_flags()
92 * If a widget needs to declare several animatable regions (i.e. not
93 * affecting the whole widget area), its #GtkWidget::draw signal handler
94 * needs to wrap the render operations for the different regions with
95 * calls to gtk_style_context_push_animatable_region() and
96 * gtk_style_context_pop_animatable_region(). These functions take an
97 * identifier for the region which must be unique within the style context.
98 * For simple widgets with a fixed set of animatable regions, using an
99 * enumeration works well:
102 * <title>Using an enumeration to identify animatable regions</title>
113 * spin_button_draw (GtkWidget *widget,
116 * GtkStyleContext *context;
118 * context = gtk_widget_get_style_context (widget);
120 * gtk_style_context_push_animatable_region (context,
121 * GUINT_TO_POINTER (REGION_ENTRY));
123 * gtk_render_background (cr, 0, 0, 100, 30);
124 * gtk_render_frame (cr, 0, 0, 100, 30);
126 * gtk_style_context_pop_animatable_region (context);
133 * For complex widgets with an arbitrary number of animatable regions, it
134 * is up to the implementation to come up with a way to uniquely identify
135 * each animatable region. Using pointers to internal structs is one way
139 * <title>Using struct pointers to identify animatable regions</title>
142 * notebook_draw_tab (GtkWidget *widget,
143 * NotebookPage *page,
146 * gtk_style_context_push_animatable_region (context, page);
147 * gtk_render_extension (cr, page->x, page->y, page->width, page->height);
148 * gtk_style_context_pop_animatable_region (context);
153 * The widget also needs to notify the style context about a state change
154 * for a given animatable region so the animation is triggered.
157 * <title>Triggering a state change animation on a region</title>
160 * notebook_motion_notify (GtkWidget *widget,
161 * GdkEventMotion *event)
163 * GtkStyleContext *context;
164 * NotebookPage *page;
166 * context = gtk_widget_get_style_context (widget);
167 * page = find_page_under_pointer (widget, event);
168 * gtk_style_context_notify_state_change (context,
169 * gtk_widget_get_window (widget),
171 * GTK_STATE_PRELIGHT,
178 * gtk_style_context_notify_state_change() accepts %NULL region IDs as a
179 * special value, in this case, the whole widget area will be updated
183 * <refsect2 id="gtkstylecontext-classes">
184 * <title>Style classes and regions</title>
186 * Widgets can add style classes to their context, which can be used
187 * to associate different styles by class (see <xref linkend="gtkcssprovider-selectors"/>). Theme engines can also use style classes to vary their
188 * rendering. GTK+ has a number of predefined style classes:
189 * #GTK_STYLE_CLASS_CELL,
190 * #GTK_STYLE_CLASS_ENTRY,
191 * #GTK_STYLE_CLASS_BUTTON,
192 * #GTK_STYLE_CLASS_COMBOBOX_ENTRY,
193 * #GTK_STYLE_CLASS_CALENDAR,
194 * #GTK_STYLE_CLASS_SLIDER,
195 * #GTK_STYLE_CLASS_BACKGROUND,
196 * #GTK_STYLE_CLASS_RUBBERBAND,
197 * #GTK_STYLE_CLASS_TOOLTIP,
198 * #GTK_STYLE_CLASS_MENU,
199 * #GTK_STYLE_CLASS_MENUBAR,
200 * #GTK_STYLE_CLASS_MENUITEM,
201 * #GTK_STYLE_CLASS_TOOLBAR,
202 * #GTK_STYLE_CLASS_PRIMARY_TOOLBAR,
203 * #GTK_STYLE_CLASS_INLINE_TOOLBAR,
204 * #GTK_STYLE_CLASS_RADIO,
205 * #GTK_STYLE_CLASS_CHECK,
206 * #GTK_STYLE_CLASS_TROUGH,
207 * #GTK_STYLE_CLASS_SCROLLBAR,
208 * #GTK_STYLE_CLASS_SCALE,
209 * #GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE,
210 * #GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW,
211 * #GTK_STYLE_CLASS_HEADER,
212 * #GTK_STYLE_CLASS_ACCELERATOR,
213 * #GTK_STYLE_CLASS_GRIP,
214 * #GTK_STYLE_CLASS_DOCK,
215 * #GTK_STYLE_CLASS_PROGRESSBAR,
216 * #GTK_STYLE_CLASS_SPINNER,
217 * #GTK_STYLE_CLASS_EXPANDER,
218 * #GTK_STYLE_CLASS_SPINBUTTON,
219 * #GTK_STYLE_CLASS_NOTEBOOK,
220 * #GTK_STYLE_CLASS_VIEW,
221 * #GTK_STYLE_CLASS_SIDEBAR,
222 * #GTK_STYLE_CLASS_IMAGE,
223 * #GTK_STYLE_CLASS_HIGHLIGHT,
224 * #GTK_STYLE_CLASS_FRAME,
225 * #GTK_STYLE_CLASS_DND,
226 * #GTK_STYLE_CLASS_PANE_SEPARATOR,
227 * #GTK_STYLE_CLASS_SEPARATOR,
228 * #GTK_STYLE_CLASS_INFO,
229 * #GTK_STYLE_CLASS_WARNING,
230 * #GTK_STYLE_CLASS_QUESTION,
231 * #GTK_STYLE_CLASS_ERROR,
232 * #GTK_STYLE_CLASS_HORIZONTAL,
233 * #GTK_STYLE_CLASS_VERTICAL,
234 * #GTK_STYLE_CLASS_TOP,
235 * #GTK_STYLE_CLASS_BOTTOM,
236 * #GTK_STYLE_CLASS_LEFT,
237 * #GTK_STYLE_CLASS_RIGHT,
240 * Widgets can also add regions with flags to their context.
241 * The regions used by GTK+ widgets are:
246 * <entry>Region</entry>
247 * <entry>Flags</entry>
248 * <entry>Macro</entry>
249 * <entry>Used by</entry>
255 * <entry>even, odd</entry>
256 * <entry>GTK_STYLE_REGION_ROW</entry>
257 * <entry>#GtkTreeView</entry>
260 * <entry>column</entry>
261 * <entry>first, last, sorted</entry>
262 * <entry>GTK_STYLE_REGION_COLUMN</entry>
263 * <entry>#GtkTreeView</entry>
266 * <entry>column-header</entry>
268 * <entry>GTK_STYLE_REGION_COLUMN_HEADER</entry>
273 * <entry>even, odd, first, last</entry>
274 * <entry>GTK_STYLE_REGION_TAB</entry>
275 * <entry>#GtkNotebook</entry>
282 * <refsect2 id="gtkstylecontext-custom-styling">
283 * <title>Custom styling in UI libraries and applications</title>
285 * If you are developing a library with custom #GtkWidget<!-- -->s that
286 * render differently than standard components, you may need to add a
287 * #GtkStyleProvider yourself with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK
288 * priority, either a #GtkCssProvider or a custom object implementing the
289 * #GtkStyleProvider interface. This way theming engines may still attempt
290 * to style your UI elements in a different way if needed so.
293 * If you are using custom styling on an applications, you probably want then
294 * to make your style information prevail to the theme's, so you must use
295 * a #GtkStyleProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
296 * priority, keep in mind that the user settings in
297 * <filename><replaceable>XDG_CONFIG_HOME</replaceable>/gtk-3.0/gtk.css</filename> will
298 * still take precedence over your changes, as it uses the
299 * %GTK_STYLE_PROVIDER_PRIORITY_USER priority.
302 * If a custom theming engine is needed, you probably want to implement a
303 * #GtkStyleProvider yourself so it points to your #GtkThemingEngine
304 * implementation, as #GtkCssProvider uses gtk_theming_engine_load()
305 * which loads the theming engine module from the standard paths.
310 /* When these change we do a full restyling. Otherwise we try to figure out
311 * if we need to change things. */
312 #define GTK_STYLE_CONTEXT_RADICAL_CHANGE (GTK_CSS_CHANGE_NAME | GTK_CSS_CHANGE_CLASS | GTK_CSS_CHANGE_SOURCE)
313 /* When these change we don't clear the cache. This takes more memory but makes
314 * things go faster. */
315 #define GTK_STYLE_CONTEXT_CACHED_CHANGE (GTK_CSS_CHANGE_STATE)
317 typedef struct GtkStyleInfo GtkStyleInfo;
318 typedef struct GtkRegion GtkRegion;
319 typedef struct PropertyValue PropertyValue;
320 typedef struct StyleData StyleData;
325 GtkRegionFlags flags;
339 GArray *style_classes;
341 GtkJunctionSides junction_sides;
342 GtkStateFlags state_flags;
348 GtkCssComputedValues *store;
349 GArray *property_cache;
353 struct _GtkStyleContextPrivate
357 GtkStyleCascade *cascade;
359 GtkStyleContext *animation_list_prev;
360 GtkStyleContext *animation_list_next;
362 GtkStyleContext *parent;
365 GtkWidgetPath *widget_path;
366 GHashTable *style_data;
369 GtkTextDirection direction;
371 GtkCssChange relevant_changes;
372 GtkCssChange pending_changes;
374 guint invalidating_context : 1;
390 static guint signals[LAST_SIGNAL] = { 0 };
391 static GtkStyleContext *_running_animations = NULL;
392 guint _running_animations_timer_id = 0;
394 static void gtk_style_context_finalize (GObject *object);
396 static void gtk_style_context_impl_set_property (GObject *object,
400 static void gtk_style_context_impl_get_property (GObject *object,
404 static StyleData *style_data_lookup (GtkStyleContext *context);
407 G_DEFINE_TYPE (GtkStyleContext, gtk_style_context, G_TYPE_OBJECT)
410 gtk_style_context_real_changed (GtkStyleContext *context)
412 GtkStyleContextPrivate *priv = context->priv;
415 _gtk_widget_style_context_invalidated (priv->widget);
419 gtk_style_context_class_init (GtkStyleContextClass *klass)
421 GObjectClass *object_class = G_OBJECT_CLASS (klass);
423 object_class->finalize = gtk_style_context_finalize;
424 object_class->set_property = gtk_style_context_impl_set_property;
425 object_class->get_property = gtk_style_context_impl_get_property;
427 klass->changed = gtk_style_context_real_changed;
430 g_signal_new (I_("changed"),
431 G_TYPE_FROM_CLASS (object_class),
433 G_STRUCT_OFFSET (GtkStyleContextClass, changed),
435 g_cclosure_marshal_VOID__VOID,
438 g_object_class_install_property (object_class,
440 g_param_spec_object ("screen",
442 P_("The associated GdkScreen"),
444 GTK_PARAM_READWRITE));
445 g_object_class_install_property (object_class,
447 g_param_spec_enum ("direction",
449 P_("Text direction"),
450 GTK_TYPE_TEXT_DIRECTION,
452 GTK_PARAM_READWRITE));
454 * GtkStyleContext:parent:
456 * Sets or gets the style context's parent. See gtk_style_context_set_parent()
461 g_object_class_install_property (object_class,
463 g_param_spec_object ("parent",
465 P_("The parent style context"),
466 GTK_TYPE_STYLE_CONTEXT,
467 GTK_PARAM_READWRITE));
469 g_type_class_add_private (object_class, sizeof (GtkStyleContextPrivate));
473 style_data_new (void)
477 data = g_slice_new0 (StyleData);
484 clear_property_cache (StyleData *data)
488 if (!data->property_cache)
491 for (i = 0; i < data->property_cache->len; i++)
493 PropertyValue *node = &g_array_index (data->property_cache, PropertyValue, i);
495 g_param_spec_unref (node->pspec);
496 g_value_unset (&node->value);
499 g_array_free (data->property_cache, TRUE);
500 data->property_cache = NULL;
504 style_data_ref (StyleData *style_data)
506 style_data->ref_count++;
512 style_data_unref (StyleData *data)
516 if (data->ref_count > 0)
519 g_object_unref (data->store);
520 clear_property_cache (data);
522 g_slice_free (StyleData, data);
526 style_data_is_animating (StyleData *style_data)
528 return !_gtk_css_computed_values_is_static (style_data->store);
531 static GtkStyleInfo *
532 style_info_new (void)
536 info = g_slice_new0 (GtkStyleInfo);
537 info->style_classes = g_array_new (FALSE, FALSE, sizeof (GQuark));
538 info->regions = g_array_new (FALSE, FALSE, sizeof (GtkRegion));
544 style_info_set_data (GtkStyleInfo *info,
547 if (info->data == data)
551 style_data_ref (data);
554 style_data_unref (info->data);
560 style_info_free (GtkStyleInfo *info)
562 style_info_set_data (info, NULL);
563 g_array_free (info->style_classes, TRUE);
564 g_array_free (info->regions, TRUE);
565 g_slice_free (GtkStyleInfo, info);
568 static GtkStyleInfo *
569 style_info_pop (GtkStyleInfo *info)
571 GtkStyleInfo *next = info->next;
573 style_info_free (info);
578 static GtkStyleInfo *
579 style_info_copy (GtkStyleInfo *info)
583 copy = style_info_new ();
584 g_array_insert_vals (copy->style_classes, 0,
585 info->style_classes->data,
586 info->style_classes->len);
588 g_array_insert_vals (copy->regions, 0,
593 copy->junction_sides = info->junction_sides;
594 copy->state_flags = info->state_flags;
595 style_info_set_data (copy, info->data);
601 style_info_hash (gconstpointer elem)
603 const GtkStyleInfo *info;
608 for (i = 0; i < info->style_classes->len; i++)
610 hash += g_array_index (info->style_classes, GQuark, i);
614 for (i = 0; i < info->regions->len; i++)
618 region = &g_array_index (info->regions, GtkRegion, i);
619 hash += region->class_quark;
620 hash += region->flags;
624 return hash ^ info->state_flags;
628 style_info_equal (gconstpointer elem1,
631 const GtkStyleInfo *info1, *info2;
636 if (info1->state_flags != info2->state_flags)
639 if (info1->junction_sides != info2->junction_sides)
642 if (info1->style_classes->len != info2->style_classes->len)
645 if (memcmp (info1->style_classes->data,
646 info2->style_classes->data,
647 info1->style_classes->len * sizeof (GQuark)) != 0)
650 if (info1->regions->len != info2->regions->len)
653 if (memcmp (info1->regions->data,
654 info2->regions->data,
655 info1->regions->len * sizeof (GtkRegion)) != 0)
662 gtk_style_context_cascade_changed (GtkStyleCascade *cascade,
663 GtkStyleContext *context)
665 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_SOURCE);
669 gtk_style_context_set_cascade (GtkStyleContext *context,
670 GtkStyleCascade *cascade)
672 GtkStyleContextPrivate *priv;
674 priv = context->priv;
676 if (priv->cascade == cascade)
681 g_object_ref (cascade);
682 g_signal_connect (cascade,
683 "-gtk-private-changed",
684 G_CALLBACK (gtk_style_context_cascade_changed),
690 g_signal_handlers_disconnect_by_func (priv->cascade,
691 gtk_style_context_cascade_changed,
693 g_object_unref (priv->cascade);
696 priv->cascade = cascade;
699 gtk_style_context_cascade_changed (cascade, context);
703 gtk_style_context_init (GtkStyleContext *style_context)
705 GtkStyleContextPrivate *priv;
707 priv = style_context->priv = G_TYPE_INSTANCE_GET_PRIVATE (style_context,
708 GTK_TYPE_STYLE_CONTEXT,
709 GtkStyleContextPrivate);
711 priv->style_data = g_hash_table_new_full (style_info_hash,
713 (GDestroyNotify) style_info_free,
714 (GDestroyNotify) style_data_unref);
716 priv->direction = GTK_TEXT_DIR_LTR;
718 priv->screen = gdk_screen_get_default ();
719 priv->relevant_changes = GTK_CSS_CHANGE_ANY;
721 /* Create default info store */
722 priv->info = style_info_new ();
724 gtk_style_context_set_cascade (style_context,
725 _gtk_style_cascade_get_for_screen (priv->screen));
729 gtk_style_context_do_animations (gpointer unused)
731 GtkStyleContext *context;
733 for (context = _running_animations;
735 context = context->priv->animation_list_next)
737 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANIMATE);
744 gtk_style_context_is_animating (GtkStyleContext *context)
746 GtkStyleContextPrivate *priv = context->priv;
748 return priv->animation_list_prev != NULL
749 || _running_animations == context;
753 gtk_style_context_stop_animating (GtkStyleContext *context)
755 GtkStyleContextPrivate *priv = context->priv;
757 if (!gtk_style_context_is_animating (context))
760 if (priv->animation_list_prev == NULL)
762 _running_animations = priv->animation_list_next;
764 if (_running_animations == NULL)
766 /* we were the last animation */
767 g_source_remove (_running_animations_timer_id);
768 _running_animations_timer_id = 0;
772 priv->animation_list_prev->priv->animation_list_next = priv->animation_list_next;
774 if (priv->animation_list_next)
775 priv->animation_list_next->priv->animation_list_prev = priv->animation_list_prev;
777 priv->animation_list_next = NULL;
778 priv->animation_list_prev = NULL;
782 gtk_style_context_start_animating (GtkStyleContext *context)
784 GtkStyleContextPrivate *priv = context->priv;
786 if (gtk_style_context_is_animating (context))
789 if (_running_animations == NULL)
791 _running_animations_timer_id = gdk_threads_add_timeout (25,
792 gtk_style_context_do_animations,
794 _running_animations = context;
798 priv->animation_list_next = _running_animations;
799 _running_animations->priv->animation_list_prev = context;
800 _running_animations = context;
805 gtk_style_context_should_animate (GtkStyleContext *context)
807 GtkStyleContextPrivate *priv;
811 priv = context->priv;
813 if (priv->widget == NULL)
816 if (!gtk_widget_get_mapped (priv->widget))
819 data = style_data_lookup (context);
820 if (!style_data_is_animating (data))
823 g_object_get (gtk_widget_get_settings (context->priv->widget),
824 "gtk-enable-animations", &animate,
831 _gtk_style_context_update_animating (GtkStyleContext *context)
833 if (gtk_style_context_should_animate (context))
834 gtk_style_context_start_animating (context);
836 gtk_style_context_stop_animating (context);
840 gtk_style_context_finalize (GObject *object)
842 GtkStyleContextPrivate *priv;
843 GtkStyleContext *style_context;
845 style_context = GTK_STYLE_CONTEXT (object);
846 priv = style_context->priv;
848 gtk_style_context_stop_animating (style_context);
850 /* children hold a reference to us */
851 g_assert (priv->children == NULL);
853 gtk_style_context_set_parent (style_context, NULL);
855 gtk_style_context_set_cascade (style_context, NULL);
857 if (priv->widget_path)
858 gtk_widget_path_free (priv->widget_path);
860 g_hash_table_destroy (priv->style_data);
863 priv->info = style_info_pop (priv->info);
865 G_OBJECT_CLASS (gtk_style_context_parent_class)->finalize (object);
869 gtk_style_context_impl_set_property (GObject *object,
874 GtkStyleContext *style_context;
876 style_context = GTK_STYLE_CONTEXT (object);
881 gtk_style_context_set_screen (style_context,
882 g_value_get_object (value));
885 gtk_style_context_set_direction (style_context,
886 g_value_get_enum (value));
889 gtk_style_context_set_parent (style_context,
890 g_value_get_object (value));
893 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
899 gtk_style_context_impl_get_property (GObject *object,
904 GtkStyleContext *style_context;
905 GtkStyleContextPrivate *priv;
907 style_context = GTK_STYLE_CONTEXT (object);
908 priv = style_context->priv;
913 g_value_set_object (value, priv->screen);
916 g_value_set_enum (value, priv->direction);
919 g_value_set_object (value, priv->parent);
922 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
927 static GtkWidgetPath *
928 create_query_path (GtkStyleContext *context,
931 GtkStyleContextPrivate *priv;
935 priv = context->priv;
936 path = priv->widget ? _gtk_widget_create_path (priv->widget) : gtk_widget_path_copy (priv->widget_path);
937 pos = gtk_widget_path_length (path) - 1;
939 /* Set widget regions */
940 for (i = 0; i < info->regions->len; i++)
944 region = &g_array_index (info->regions, GtkRegion, i);
945 gtk_widget_path_iter_add_region (path, pos,
946 g_quark_to_string (region->class_quark),
950 /* Set widget classes */
951 for (i = 0; i < info->style_classes->len; i++)
955 quark = g_array_index (info->style_classes, GQuark, i);
956 gtk_widget_path_iter_add_class (path, pos,
957 g_quark_to_string (quark));
964 build_properties (GtkStyleContext *context,
965 GtkCssComputedValues *values,
967 const GtkBitmask *relevant_changes)
969 GtkStyleContextPrivate *priv;
970 GtkCssMatcher matcher;
972 GtkCssLookup *lookup;
974 priv = context->priv;
976 path = create_query_path (context, info);
977 lookup = _gtk_css_lookup_new (relevant_changes);
979 if (_gtk_css_matcher_init (&matcher, path, info->state_flags))
980 _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
984 _gtk_css_lookup_resolve (lookup,
985 GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
987 priv->parent ? style_data_lookup (priv->parent)->store : NULL);
989 _gtk_css_lookup_free (lookup);
990 gtk_widget_path_free (path);
994 style_data_lookup (GtkStyleContext *context)
996 GtkStyleContextPrivate *priv;
1000 priv = context->priv;
1003 /* Current data in use is cached, just return it */
1007 g_assert (priv->widget != NULL || priv->widget_path != NULL);
1009 data = g_hash_table_lookup (priv->style_data, info);
1012 style_info_set_data (info, data);
1016 data = style_data_new ();
1017 data->store = _gtk_css_computed_values_new ();
1018 style_info_set_data (info, data);
1019 g_hash_table_insert (priv->style_data,
1020 style_info_copy (info),
1023 build_properties (context, data->store, info, NULL);
1029 style_data_lookup_for_state (GtkStyleContext *context,
1030 GtkStateFlags state)
1034 if (context->priv->info->state_flags == state)
1035 return style_data_lookup (context);
1037 gtk_style_context_save (context);
1038 gtk_style_context_set_state (context, state);
1039 data = style_data_lookup (context);
1040 gtk_style_context_restore (context);
1046 gtk_style_context_set_invalid (GtkStyleContext *context,
1049 GtkStyleContextPrivate *priv;
1051 priv = context->priv;
1053 if (priv->invalid == invalid)
1056 priv->invalid = invalid;
1061 gtk_style_context_set_invalid (priv->parent, TRUE);
1062 else if (GTK_IS_RESIZE_CONTAINER (priv->widget))
1063 _gtk_container_queue_restyle (GTK_CONTAINER (priv->widget));
1067 /* returns TRUE if someone called gtk_style_context_save() but hasn't
1068 * called gtk_style_context_restore() yet.
1069 * In those situations we don't invalidate the context when somebody
1070 * changes state/regions/classes.
1073 gtk_style_context_is_saved (GtkStyleContext *context)
1075 return context->priv->info->next != NULL;
1079 gtk_style_context_queue_invalidate_internal (GtkStyleContext *context,
1080 GtkCssChange change)
1082 GtkStyleContextPrivate *priv = context->priv;
1083 GtkStyleInfo *info = priv->info;
1085 if (gtk_style_context_is_saved (context))
1087 style_info_set_data (info, NULL);
1091 _gtk_style_context_queue_invalidate (context, change);
1092 /* XXX: We need to invalidate siblings here somehow */
1097 * gtk_style_context_new:
1099 * Creates a standalone #GtkStyleContext, this style context
1100 * won't be attached to any widget, so you may want
1101 * to call gtk_style_context_set_path() yourself.
1104 * This function is only useful when using the theming layer
1105 * separated from GTK+, if you are using #GtkStyleContext to
1106 * theme #GtkWidget<!-- -->s, use gtk_widget_get_style_context()
1107 * in order to get a style context ready to theme the widget.
1110 * Returns: A newly created #GtkStyleContext.
1113 gtk_style_context_new (void)
1115 return g_object_new (GTK_TYPE_STYLE_CONTEXT, NULL);
1119 _gtk_style_context_set_widget (GtkStyleContext *context,
1122 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1123 g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget));
1125 context->priv->widget = widget;
1127 _gtk_style_context_update_animating (context);
1129 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY_SELF);
1133 * gtk_style_context_add_provider:
1134 * @context: a #GtkStyleContext
1135 * @provider: a #GtkStyleProvider
1136 * @priority: the priority of the style provider. The lower
1137 * it is, the earlier it will be used in the style
1138 * construction. Typically this will be in the range
1139 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1140 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1142 * Adds a style provider to @context, to be used in style construction.
1143 * Note that a style provider added by this function only affects
1144 * the style of the widget to which @context belongs. If you want
1145 * to affect the style of all widgets, use
1146 * gtk_style_context_add_provider_for_screen().
1148 * <note><para>If both priorities are the same, A #GtkStyleProvider
1149 * added through this function takes precedence over another added
1150 * through gtk_style_context_add_provider_for_screen().</para></note>
1155 gtk_style_context_add_provider (GtkStyleContext *context,
1156 GtkStyleProvider *provider,
1159 GtkStyleContextPrivate *priv;
1161 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1162 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1164 priv = context->priv;
1166 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
1168 GtkStyleCascade *new_cascade;
1170 new_cascade = _gtk_style_cascade_new ();
1171 _gtk_style_cascade_set_parent (new_cascade, priv->cascade);
1172 _gtk_style_cascade_add_provider (new_cascade, provider, priority);
1173 gtk_style_context_set_cascade (context, new_cascade);
1174 g_object_unref (new_cascade);
1178 _gtk_style_cascade_add_provider (priv->cascade, provider, priority);
1183 * gtk_style_context_remove_provider:
1184 * @context: a #GtkStyleContext
1185 * @provider: a #GtkStyleProvider
1187 * Removes @provider from the style providers list in @context.
1192 gtk_style_context_remove_provider (GtkStyleContext *context,
1193 GtkStyleProvider *provider)
1195 GtkStyleContextPrivate *priv;
1197 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1198 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1200 priv = context->priv;
1202 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
1205 _gtk_style_cascade_remove_provider (priv->cascade, provider);
1209 * gtk_style_context_reset_widgets:
1210 * @screen: a #GdkScreen
1212 * This function recomputes the styles for all widgets under a particular
1213 * #GdkScreen. This is useful when some global parameter has changed that
1214 * affects the appearance of all widgets, because when a widget gets a new
1215 * style, it will both redraw and recompute any cached information about
1216 * its appearance. As an example, it is used when the color scheme changes
1217 * in the related #GtkSettings object.
1222 gtk_style_context_reset_widgets (GdkScreen *screen)
1224 GList *list, *toplevels;
1226 _gtk_icon_set_invalidate_caches ();
1228 toplevels = gtk_window_list_toplevels ();
1229 g_list_foreach (toplevels, (GFunc) g_object_ref, NULL);
1231 for (list = toplevels; list; list = list->next)
1233 if (gtk_widget_get_screen (list->data) == screen)
1234 gtk_widget_reset_style (list->data);
1236 g_object_unref (list->data);
1239 g_list_free (toplevels);
1243 * gtk_style_context_add_provider_for_screen:
1244 * @screen: a #GdkScreen
1245 * @provider: a #GtkStyleProvider
1246 * @priority: the priority of the style provider. The lower
1247 * it is, the earlier it will be used in the style
1248 * construction. Typically this will be in the range
1249 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1250 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1252 * Adds a global style provider to @screen, which will be used
1253 * in style construction for all #GtkStyleContexts under @screen.
1255 * GTK+ uses this to make styling information from #GtkSettings
1258 * <note><para>If both priorities are the same, A #GtkStyleProvider
1259 * added through gtk_style_context_add_provider() takes precedence
1260 * over another added through this function.</para></note>
1265 gtk_style_context_add_provider_for_screen (GdkScreen *screen,
1266 GtkStyleProvider *provider,
1269 GtkStyleCascade *cascade;
1271 g_return_if_fail (GDK_IS_SCREEN (screen));
1272 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1273 g_return_if_fail (!GTK_IS_SETTINGS (provider) || _gtk_settings_get_screen (GTK_SETTINGS (provider)) == screen);
1275 cascade = _gtk_style_cascade_get_for_screen (screen);
1276 _gtk_style_cascade_add_provider (cascade, provider, priority);
1280 * gtk_style_context_remove_provider_for_screen:
1281 * @screen: a #GdkScreen
1282 * @provider: a #GtkStyleProvider
1284 * Removes @provider from the global style providers list in @screen.
1289 gtk_style_context_remove_provider_for_screen (GdkScreen *screen,
1290 GtkStyleProvider *provider)
1292 GtkStyleCascade *cascade;
1294 g_return_if_fail (GDK_IS_SCREEN (screen));
1295 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1296 g_return_if_fail (!GTK_IS_SETTINGS (provider));
1298 cascade = _gtk_style_cascade_get_for_screen (screen);
1299 _gtk_style_cascade_remove_provider (cascade, provider);
1303 * gtk_style_context_get_section:
1304 * @context: a #GtkStyleContext
1305 * @property: style property name
1307 * Queries the location in the CSS where @property was defined for the
1308 * current @context. Note that the state to be queried is taken from
1309 * gtk_style_context_get_state().
1311 * If the location is not available, %NULL will be returned. The
1312 * location might not be available for various reasons, such as the
1313 * property being overridden, @property not naming a supported CSS
1314 * property or tracking of definitions being disabled for performance
1317 * Shorthand CSS properties cannot be queried for a location and will
1318 * always return %NULL.
1320 * Returns: %NULL or the section where value was defined
1323 gtk_style_context_get_section (GtkStyleContext *context,
1324 const gchar *property)
1326 GtkStyleContextPrivate *priv;
1327 GtkStyleProperty *prop;
1330 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1331 g_return_val_if_fail (property != NULL, NULL);
1333 priv = context->priv;
1334 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
1336 prop = _gtk_style_property_lookup (property);
1337 if (!GTK_IS_CSS_STYLE_PROPERTY (prop))
1340 data = style_data_lookup (context);
1341 return _gtk_css_computed_values_get_section (data->store, _gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (prop)));
1344 static GtkCssValue *
1345 gtk_style_context_query_func (guint id,
1348 return _gtk_css_computed_values_get_value (values, id);
1352 * gtk_style_context_get_property:
1353 * @context: a #GtkStyleContext
1354 * @property: style property name
1355 * @state: state to retrieve the property value for
1356 * @value: (out) (transfer full): return location for the style property value
1358 * Gets a style property from @context for the given state.
1360 * When @value is no longer needed, g_value_unset() must be called
1361 * to free any allocated memory.
1366 gtk_style_context_get_property (GtkStyleContext *context,
1367 const gchar *property,
1368 GtkStateFlags state,
1371 GtkStyleContextPrivate *priv;
1372 GtkStyleProperty *prop;
1375 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1376 g_return_if_fail (property != NULL);
1377 g_return_if_fail (value != NULL);
1379 priv = context->priv;
1380 g_return_if_fail (priv->widget != NULL || priv->widget_path != NULL);
1382 prop = _gtk_style_property_lookup (property);
1385 g_warning ("Style property \"%s\" is not registered", property);
1388 if (_gtk_style_property_get_value_type (prop) == G_TYPE_NONE)
1390 g_warning ("Style property \"%s\" is not gettable", property);
1394 data = style_data_lookup_for_state (context, state);
1395 _gtk_style_property_query (prop, value, gtk_style_context_query_func, data->store);
1399 * gtk_style_context_get_valist:
1400 * @context: a #GtkStyleContext
1401 * @state: state to retrieve the property values for
1402 * @args: va_list of property name/return location pairs, followed by %NULL
1404 * Retrieves several style property values from @context for a given state.
1409 gtk_style_context_get_valist (GtkStyleContext *context,
1410 GtkStateFlags state,
1413 const gchar *property_name;
1415 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1417 property_name = va_arg (args, const gchar *);
1419 while (property_name)
1421 gchar *error = NULL;
1422 GValue value = G_VALUE_INIT;
1424 gtk_style_context_get_property (context,
1429 G_VALUE_LCOPY (&value, args, 0, &error);
1430 g_value_unset (&value);
1434 g_warning ("Could not get style property \"%s\": %s", property_name, error);
1439 property_name = va_arg (args, const gchar *);
1444 * gtk_style_context_get:
1445 * @context: a #GtkStyleContext
1446 * @state: state to retrieve the property values for
1447 * @...: property name /return value pairs, followed by %NULL
1449 * Retrieves several style property values from @context for a
1455 gtk_style_context_get (GtkStyleContext *context,
1456 GtkStateFlags state,
1461 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1463 va_start (args, state);
1464 gtk_style_context_get_valist (context, state, args);
1469 * gtk_style_context_set_state:
1470 * @context: a #GtkStyleContext
1471 * @flags: state to represent
1473 * Sets the state to be used when rendering with any
1474 * of the gtk_render_*() functions.
1479 gtk_style_context_set_state (GtkStyleContext *context,
1480 GtkStateFlags flags)
1482 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1484 context->priv->info->state_flags = flags;
1486 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_STATE);
1490 * gtk_style_context_get_state:
1491 * @context: a #GtkStyleContext
1493 * Returns the state used when rendering.
1495 * Returns: the state flags
1500 gtk_style_context_get_state (GtkStyleContext *context)
1502 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
1504 return context->priv->info->state_flags;
1508 * gtk_style_context_state_is_running:
1509 * @context: a #GtkStyleContext
1510 * @state: a widget state
1511 * @progress: (out): return location for the transition progress
1513 * Returns %TRUE if there is a transition animation running for the
1514 * current region (see gtk_style_context_push_animatable_region()).
1516 * If @progress is not %NULL, the animation progress will be returned
1517 * there, 0.0 means the state is closest to being unset, while 1.0 means
1518 * it's closest to being set. This means transition animation will
1519 * run from 0 to 1 when @state is being set and from 1 to 0 when
1522 * Returns: %TRUE if there is a running transition animation for @state.
1526 * Deprecated: 3.6: This function always returns %FALSE
1529 gtk_style_context_state_is_running (GtkStyleContext *context,
1533 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1539 * gtk_style_context_set_path:
1540 * @context: a #GtkStyleContext
1541 * @path: a #GtkWidgetPath
1543 * Sets the #GtkWidgetPath used for style matching. As a
1544 * consequence, the style will be regenerated to match
1545 * the new given path.
1547 * If you are using a #GtkStyleContext returned from
1548 * gtk_widget_get_style_context(), you do not need to call
1554 gtk_style_context_set_path (GtkStyleContext *context,
1555 GtkWidgetPath *path)
1557 GtkStyleContextPrivate *priv;
1559 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1560 g_return_if_fail (path != NULL);
1562 priv = context->priv;
1563 g_return_if_fail (priv->widget == NULL);
1565 if (priv->widget_path)
1567 gtk_widget_path_free (priv->widget_path);
1568 priv->widget_path = NULL;
1572 priv->widget_path = gtk_widget_path_copy (path);
1574 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY);
1578 * gtk_style_context_get_path:
1579 * @context: a #GtkStyleContext
1581 * Returns the widget path used for style matching.
1583 * Returns: (transfer none): A #GtkWidgetPath
1587 const GtkWidgetPath *
1588 gtk_style_context_get_path (GtkStyleContext *context)
1590 GtkStyleContextPrivate *priv;
1592 priv = context->priv;
1594 return gtk_widget_get_path (priv->widget);
1596 return priv->widget_path;
1600 * gtk_style_context_set_parent:
1601 * @context: a #GtkStyleContext
1602 * @parent: (allow-none): the new parent or %NULL
1604 * Sets the parent style context for @context. The parent style
1605 * context is used to implement
1606 * <ulink url="http://www.w3.org/TR/css3-cascade/#inheritance">inheritance</ulink>
1609 * If you are using a #GtkStyleContext returned from
1610 * gtk_widget_get_style_context(), the parent will be set for you.
1615 gtk_style_context_set_parent (GtkStyleContext *context,
1616 GtkStyleContext *parent)
1618 GtkStyleContextPrivate *priv;
1620 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1621 g_return_if_fail (parent == NULL || GTK_IS_STYLE_CONTEXT (parent));
1623 priv = context->priv;
1625 if (priv->parent == parent)
1630 parent->priv->children = g_slist_prepend (parent->priv->children, context);
1631 g_object_ref (parent);
1633 gtk_style_context_set_invalid (parent, TRUE);
1638 priv->parent->priv->children = g_slist_remove (priv->parent->priv->children, context);
1639 g_object_unref (priv->parent);
1642 priv->parent = parent;
1644 g_object_notify (G_OBJECT (context), "parent");
1645 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY_PARENT | GTK_CSS_CHANGE_ANY_SIBLING);
1649 * gtk_style_context_get_parent:
1650 * @context: a #GtkStyleContext
1652 * Gets the parent context set via gtk_style_context_set_parent().
1653 * See that function for details.
1655 * Returns: (transfer none): the parent context or %NULL
1660 gtk_style_context_get_parent (GtkStyleContext *context)
1662 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1664 return context->priv->parent;
1668 * gtk_style_context_save:
1669 * @context: a #GtkStyleContext
1671 * Saves the @context state, so all modifications done through
1672 * gtk_style_context_add_class(), gtk_style_context_remove_class(),
1673 * gtk_style_context_add_region(), gtk_style_context_remove_region()
1674 * or gtk_style_context_set_junction_sides() can be reverted in one
1675 * go through gtk_style_context_restore().
1680 gtk_style_context_save (GtkStyleContext *context)
1682 GtkStyleContextPrivate *priv;
1684 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1686 priv = context->priv;
1688 priv->info = style_info_copy (priv->info);
1689 /* Need to unset animations here because we can not know what style
1690 * class potential transitions came from once we save().
1692 if (priv->info->data && style_data_is_animating (priv->info->data))
1693 style_info_set_data (priv->info, NULL);
1697 * gtk_style_context_restore:
1698 * @context: a #GtkStyleContext
1700 * Restores @context state to a previous stage.
1701 * See gtk_style_context_save().
1706 gtk_style_context_restore (GtkStyleContext *context)
1708 GtkStyleContextPrivate *priv;
1710 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1712 priv = context->priv;
1714 priv->info = style_info_pop (priv->info);
1718 g_warning ("Unpaired gtk_style_context_restore() call");
1720 /* Create default region */
1721 priv->info = style_info_new ();
1726 style_class_find (GArray *array,
1731 gboolean found = FALSE;
1737 if (!array || array->len == 0)
1741 max = array->len - 1;
1747 mid = (min + max) / 2;
1748 item = g_array_index (array, GQuark, mid);
1750 if (class_quark == item)
1755 else if (class_quark > item)
1756 min = pos = mid + 1;
1763 while (!found && min <= max);
1772 region_find (GArray *array,
1777 gboolean found = FALSE;
1783 if (!array || array->len == 0)
1787 max = array->len - 1;
1793 mid = (min + max) / 2;
1794 region = &g_array_index (array, GtkRegion, mid);
1796 if (region->class_quark == class_quark)
1801 else if (region->class_quark > class_quark)
1802 min = pos = mid + 1;
1809 while (!found && min <= max);
1818 * gtk_style_context_add_class:
1819 * @context: a #GtkStyleContext
1820 * @class_name: class name to use in styling
1822 * Adds a style class to @context, so posterior calls to
1823 * gtk_style_context_get() or any of the gtk_render_*()
1824 * functions will make use of this new class for styling.
1826 * In the CSS file format, a #GtkEntry defining an "entry"
1827 * class, would be matched by:
1830 * GtkEntry.entry { ... }
1833 * While any widget defining an "entry" class would be
1842 gtk_style_context_add_class (GtkStyleContext *context,
1843 const gchar *class_name)
1845 GtkStyleContextPrivate *priv;
1850 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1851 g_return_if_fail (class_name != NULL);
1853 priv = context->priv;
1854 class_quark = g_quark_from_string (class_name);
1858 if (!style_class_find (info->style_classes, class_quark, &position))
1860 g_array_insert_val (info->style_classes, position, class_quark);
1862 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_CLASS);
1867 * gtk_style_context_remove_class:
1868 * @context: a #GtkStyleContext
1869 * @class_name: class name to remove
1871 * Removes @class_name from @context.
1876 gtk_style_context_remove_class (GtkStyleContext *context,
1877 const gchar *class_name)
1879 GtkStyleContextPrivate *priv;
1884 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1885 g_return_if_fail (class_name != NULL);
1887 class_quark = g_quark_try_string (class_name);
1892 priv = context->priv;
1896 if (style_class_find (info->style_classes, class_quark, &position))
1898 g_array_remove_index (info->style_classes, position);
1900 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_CLASS);
1905 * gtk_style_context_has_class:
1906 * @context: a #GtkStyleContext
1907 * @class_name: a class name
1909 * Returns %TRUE if @context currently has defined the
1912 * Returns: %TRUE if @context has @class_name defined
1917 gtk_style_context_has_class (GtkStyleContext *context,
1918 const gchar *class_name)
1920 GtkStyleContextPrivate *priv;
1924 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1925 g_return_val_if_fail (class_name != NULL, FALSE);
1927 class_quark = g_quark_try_string (class_name);
1932 priv = context->priv;
1936 if (style_class_find (info->style_classes, class_quark, NULL))
1943 * gtk_style_context_list_classes:
1944 * @context: a #GtkStyleContext
1946 * Returns the list of classes currently defined in @context.
1948 * Returns: (transfer container) (element-type utf8): a #GList of
1949 * strings with the currently defined classes. The contents
1950 * of the list are owned by GTK+, but you must free the list
1951 * itself with g_list_free() when you are done with it.
1956 gtk_style_context_list_classes (GtkStyleContext *context)
1958 GtkStyleContextPrivate *priv;
1960 GList *classes = NULL;
1963 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1965 priv = context->priv;
1969 for (i = 0; i < info->style_classes->len; i++)
1973 quark = g_array_index (info->style_classes, GQuark, i);
1974 classes = g_list_prepend (classes, (gchar *) g_quark_to_string (quark));
1981 * gtk_style_context_list_regions:
1982 * @context: a #GtkStyleContext
1984 * Returns the list of regions currently defined in @context.
1986 * Returns: (transfer container) (element-type utf8): a #GList of
1987 * strings with the currently defined regions. The contents
1988 * of the list are owned by GTK+, but you must free the list
1989 * itself with g_list_free() when you are done with it.
1994 gtk_style_context_list_regions (GtkStyleContext *context)
1996 GtkStyleContextPrivate *priv;
1998 GList *classes = NULL;
2001 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2003 priv = context->priv;
2007 for (i = 0; i < info->regions->len; i++)
2010 const gchar *class_name;
2012 region = &g_array_index (info->regions, GtkRegion, i);
2014 class_name = g_quark_to_string (region->class_quark);
2015 classes = g_list_prepend (classes, (gchar *) class_name);
2022 _gtk_style_context_check_region_name (const gchar *str)
2024 g_return_val_if_fail (str != NULL, FALSE);
2026 if (!g_ascii_islower (str[0]))
2032 !g_ascii_islower (*str))
2042 * gtk_style_context_add_region:
2043 * @context: a #GtkStyleContext
2044 * @region_name: region name to use in styling
2045 * @flags: flags that apply to the region
2047 * Adds a region to @context, so posterior calls to
2048 * gtk_style_context_get() or any of the gtk_render_*()
2049 * functions will make use of this new region for styling.
2051 * In the CSS file format, a #GtkTreeView defining a "row"
2052 * region, would be matched by:
2055 * GtkTreeView row { ... }
2058 * Pseudo-classes are used for matching @flags, so the two
2061 * GtkTreeView row:nth-child(even) { ... }
2062 * GtkTreeView row:nth-child(odd) { ... }
2065 * would apply to even and odd rows, respectively.
2067 * <note><para>Region names must only contain lowercase letters
2068 * and '-', starting always with a lowercase letter.</para></note>
2073 gtk_style_context_add_region (GtkStyleContext *context,
2074 const gchar *region_name,
2075 GtkRegionFlags flags)
2077 GtkStyleContextPrivate *priv;
2079 GQuark region_quark;
2082 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2083 g_return_if_fail (region_name != NULL);
2084 g_return_if_fail (_gtk_style_context_check_region_name (region_name));
2086 priv = context->priv;
2087 region_quark = g_quark_from_string (region_name);
2091 if (!region_find (info->regions, region_quark, &position))
2095 region.class_quark = region_quark;
2096 region.flags = flags;
2098 g_array_insert_val (info->regions, position, region);
2100 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_REGION);
2105 * gtk_style_context_remove_region:
2106 * @context: a #GtkStyleContext
2107 * @region_name: region name to unset
2109 * Removes a region from @context.
2114 gtk_style_context_remove_region (GtkStyleContext *context,
2115 const gchar *region_name)
2117 GtkStyleContextPrivate *priv;
2119 GQuark region_quark;
2122 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2123 g_return_if_fail (region_name != NULL);
2125 region_quark = g_quark_try_string (region_name);
2130 priv = context->priv;
2134 if (region_find (info->regions, region_quark, &position))
2136 g_array_remove_index (info->regions, position);
2138 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_REGION);
2143 * gtk_style_context_has_region:
2144 * @context: a #GtkStyleContext
2145 * @region_name: a region name
2146 * @flags_return: (out) (allow-none): return location for region flags
2148 * Returns %TRUE if @context has the region defined.
2149 * If @flags_return is not %NULL, it is set to the flags
2150 * affecting the region.
2152 * Returns: %TRUE if region is defined
2157 gtk_style_context_has_region (GtkStyleContext *context,
2158 const gchar *region_name,
2159 GtkRegionFlags *flags_return)
2161 GtkStyleContextPrivate *priv;
2163 GQuark region_quark;
2166 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2167 g_return_val_if_fail (region_name != NULL, FALSE);
2172 region_quark = g_quark_try_string (region_name);
2177 priv = context->priv;
2181 if (region_find (info->regions, region_quark, &position))
2187 region = &g_array_index (info->regions, GtkRegion, position);
2188 *flags_return = region->flags;
2197 style_property_values_cmp (gconstpointer bsearch_node1,
2198 gconstpointer bsearch_node2)
2200 const PropertyValue *val1 = bsearch_node1;
2201 const PropertyValue *val2 = bsearch_node2;
2203 if (val1->widget_type != val2->widget_type)
2204 return val1->widget_type < val2->widget_type ? -1 : 1;
2206 if (val1->pspec != val2->pspec)
2207 return val1->pspec < val2->pspec ? -1 : 1;
2209 if (val1->state != val2->state)
2210 return val1->state < val2->state ? -1 : 1;
2216 _gtk_style_context_peek_property (GtkStyleContext *context,
2219 StyleData *data = style_data_lookup (context);
2221 return _gtk_css_computed_values_get_value (data->store, property_id);
2225 _gtk_style_context_get_number (GtkStyleContext *context,
2227 double one_hundred_percent)
2231 value = _gtk_style_context_peek_property (context, property_id);
2232 return _gtk_css_number_value_get (value, one_hundred_percent);
2236 _gtk_style_context_peek_style_property (GtkStyleContext *context,
2238 GtkStateFlags state,
2241 GtkStyleContextPrivate *priv;
2242 PropertyValue *pcache, key = { 0 };
2246 priv = context->priv;
2248 data = style_data_lookup_for_state (context, state);
2250 key.widget_type = widget_type;
2254 /* need value cache array */
2255 if (!data->property_cache)
2256 data->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
2259 pcache = bsearch (&key,
2260 data->property_cache->data, data->property_cache->len,
2261 sizeof (PropertyValue), style_property_values_cmp);
2263 return &pcache->value;
2267 while (i < data->property_cache->len &&
2268 style_property_values_cmp (&key, &g_array_index (data->property_cache, PropertyValue, i)) >= 0)
2271 g_array_insert_val (data->property_cache, i, key);
2272 pcache = &g_array_index (data->property_cache, PropertyValue, i);
2274 /* cache miss, initialize value type, then set contents */
2275 g_param_spec_ref (pcache->pspec);
2276 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2278 if (priv->widget || priv->widget_path)
2280 GtkWidgetPath *widget_path = priv->widget ? _gtk_widget_create_path (priv->widget) : priv->widget_path;
2282 if (gtk_style_provider_get_style_property (GTK_STYLE_PROVIDER (priv->cascade),
2284 state, pspec, &pcache->value))
2286 /* Resolve symbolic colors to GdkColor/GdkRGBA */
2287 if (G_VALUE_TYPE (&pcache->value) == GTK_TYPE_SYMBOLIC_COLOR)
2289 GtkSymbolicColor *color;
2292 color = g_value_dup_boxed (&pcache->value);
2294 g_value_unset (&pcache->value);
2296 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2297 g_value_init (&pcache->value, GDK_TYPE_RGBA);
2299 g_value_init (&pcache->value, GDK_TYPE_COLOR);
2301 if (_gtk_style_context_resolve_color (context, _gtk_symbolic_color_get_css_value (color), &rgba, NULL))
2303 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2304 g_value_set_boxed (&pcache->value, &rgba);
2309 rgb.red = rgba.red * 65535. + 0.5;
2310 rgb.green = rgba.green * 65535. + 0.5;
2311 rgb.blue = rgba.blue * 65535. + 0.5;
2313 g_value_set_boxed (&pcache->value, &rgb);
2317 g_param_value_set_default (pspec, &pcache->value);
2319 gtk_symbolic_color_unref (color);
2323 gtk_widget_path_free (widget_path);
2325 return &pcache->value;
2329 gtk_widget_path_free (widget_path);
2332 /* not supplied by any provider, revert to default */
2333 g_param_value_set_default (pspec, &pcache->value);
2335 return &pcache->value;
2339 * gtk_style_context_get_style_property:
2340 * @context: a #GtkStyleContext
2341 * @property_name: the name of the widget style property
2342 * @value: Return location for the property value
2344 * Gets the value for a widget style property.
2346 * When @value is no longer needed, g_value_unset() must be called
2347 * to free any allocated memory.
2350 gtk_style_context_get_style_property (GtkStyleContext *context,
2351 const gchar *property_name,
2354 GtkStyleContextPrivate *priv;
2355 GtkWidgetClass *widget_class;
2356 GtkStateFlags state;
2358 const GValue *peek_value;
2361 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2362 g_return_if_fail (property_name != NULL);
2363 g_return_if_fail (value != NULL);
2365 priv = context->priv;
2369 widget_type = G_OBJECT_TYPE (priv->widget);
2373 if (!priv->widget_path)
2376 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2378 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2380 g_warning ("%s: can't get style properties for non-widget class `%s'",
2382 g_type_name (widget_type));
2387 widget_class = g_type_class_ref (widget_type);
2388 pspec = gtk_widget_class_find_style_property (widget_class, property_name);
2389 g_type_class_unref (widget_class);
2393 g_warning ("%s: widget class `%s' has no style property named `%s'",
2395 g_type_name (widget_type),
2400 state = gtk_style_context_get_state (context);
2401 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2404 if (G_VALUE_TYPE (value) == G_VALUE_TYPE (peek_value))
2405 g_value_copy (peek_value, value);
2406 else if (g_value_type_transformable (G_VALUE_TYPE (peek_value), G_VALUE_TYPE (value)))
2407 g_value_transform (peek_value, value);
2409 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
2411 G_VALUE_TYPE_NAME (peek_value),
2412 G_VALUE_TYPE_NAME (value));
2416 * gtk_style_context_get_style_valist:
2417 * @context: a #GtkStyleContext
2418 * @args: va_list of property name/return location pairs, followed by %NULL
2420 * Retrieves several widget style properties from @context according to the
2426 gtk_style_context_get_style_valist (GtkStyleContext *context,
2429 GtkStyleContextPrivate *priv;
2430 const gchar *prop_name;
2431 GtkStateFlags state;
2434 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2436 prop_name = va_arg (args, const gchar *);
2437 priv = context->priv;
2441 widget_type = G_OBJECT_TYPE (priv->widget);
2445 if (!priv->widget_path)
2448 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2450 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2452 g_warning ("%s: can't get style properties for non-widget class `%s'",
2454 g_type_name (widget_type));
2459 state = gtk_style_context_get_state (context);
2463 GtkWidgetClass *widget_class;
2465 const GValue *peek_value;
2468 widget_class = g_type_class_ref (widget_type);
2469 pspec = gtk_widget_class_find_style_property (widget_class, prop_name);
2470 g_type_class_unref (widget_class);
2474 g_warning ("%s: widget class `%s' has no style property named `%s'",
2476 g_type_name (widget_type),
2481 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2484 G_VALUE_LCOPY (peek_value, args, 0, &error);
2488 g_warning ("can't retrieve style property `%s' of type `%s': %s",
2490 G_VALUE_TYPE_NAME (peek_value),
2496 prop_name = va_arg (args, const gchar *);
2501 * gtk_style_context_get_style:
2502 * @context: a #GtkStyleContext
2503 * @...: property name /return value pairs, followed by %NULL
2505 * Retrieves several widget style properties from @context according to the
2511 gtk_style_context_get_style (GtkStyleContext *context,
2516 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2518 va_start (args, context);
2519 gtk_style_context_get_style_valist (context, args);
2525 * gtk_style_context_lookup_icon_set:
2526 * @context: a #GtkStyleContext
2527 * @stock_id: an icon name
2529 * Looks up @stock_id in the icon factories associated to @context and
2530 * the default icon factory, returning an icon set if found, otherwise
2533 * Returns: (transfer none): The looked up %GtkIconSet, or %NULL
2536 gtk_style_context_lookup_icon_set (GtkStyleContext *context,
2537 const gchar *stock_id)
2539 GtkStyleContextPrivate *priv;
2541 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2542 g_return_val_if_fail (stock_id != NULL, NULL);
2544 priv = context->priv;
2545 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
2547 return gtk_icon_factory_lookup_default (stock_id);
2551 * gtk_style_context_set_screen:
2552 * @context: a #GtkStyleContext
2553 * @screen: a #GdkScreen
2555 * Attaches @context to the given screen.
2557 * The screen is used to add style information from 'global' style
2558 * providers, such as the screens #GtkSettings instance.
2560 * If you are using a #GtkStyleContext returned from
2561 * gtk_widget_get_style_context(), you do not need to
2562 * call this yourself.
2567 gtk_style_context_set_screen (GtkStyleContext *context,
2570 GtkStyleContextPrivate *priv;
2572 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2573 g_return_if_fail (GDK_IS_SCREEN (screen));
2575 priv = context->priv;
2576 if (priv->screen == screen)
2579 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
2581 gtk_style_context_set_cascade (context, _gtk_style_cascade_get_for_screen (screen));
2585 _gtk_style_cascade_set_parent (priv->cascade, _gtk_style_cascade_get_for_screen (screen));
2588 priv->screen = screen;
2590 g_object_notify (G_OBJECT (context), "screen");
2594 * gtk_style_context_get_screen:
2595 * @context: a #GtkStyleContext
2597 * Returns the #GdkScreen to which @context is attached.
2599 * Returns: (transfer none): a #GdkScreen.
2602 gtk_style_context_get_screen (GtkStyleContext *context)
2604 GtkStyleContextPrivate *priv;
2606 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2608 priv = context->priv;
2609 return priv->screen;
2613 * gtk_style_context_set_direction:
2614 * @context: a #GtkStyleContext
2615 * @direction: the new direction.
2617 * Sets the reading direction for rendering purposes.
2619 * If you are using a #GtkStyleContext returned from
2620 * gtk_widget_get_style_context(), you do not need to
2621 * call this yourself.
2626 gtk_style_context_set_direction (GtkStyleContext *context,
2627 GtkTextDirection direction)
2629 GtkStyleContextPrivate *priv;
2631 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2633 priv = context->priv;
2634 priv->direction = direction;
2636 g_object_notify (G_OBJECT (context), "direction");
2640 * gtk_style_context_get_direction:
2641 * @context: a #GtkStyleContext
2643 * Returns the widget direction used for rendering.
2645 * Returns: the widget direction
2650 gtk_style_context_get_direction (GtkStyleContext *context)
2652 GtkStyleContextPrivate *priv;
2654 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), GTK_TEXT_DIR_LTR);
2656 priv = context->priv;
2657 return priv->direction;
2661 * gtk_style_context_set_junction_sides:
2662 * @context: a #GtkStyleContext
2663 * @sides: sides where rendered elements are visually connected to
2666 * Sets the sides where rendered elements (mostly through
2667 * gtk_render_frame()) will visually connect with other visual elements.
2669 * This is merely a hint that may or may not be honored
2670 * by theming engines.
2672 * Container widgets are expected to set junction hints as appropriate
2673 * for their children, so it should not normally be necessary to call
2674 * this function manually.
2679 gtk_style_context_set_junction_sides (GtkStyleContext *context,
2680 GtkJunctionSides sides)
2682 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2684 context->priv->info->junction_sides = sides;
2688 * gtk_style_context_get_junction_sides:
2689 * @context: a #GtkStyleContext
2691 * Returns the sides where rendered elements connect visually with others.
2693 * Returns: the junction sides
2698 gtk_style_context_get_junction_sides (GtkStyleContext *context)
2700 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
2702 return context->priv->info->junction_sides;
2706 _gtk_style_context_resolve_color (GtkStyleContext *context,
2709 GtkCssDependencies *dependencies)
2713 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2714 g_return_val_if_fail (color != NULL, FALSE);
2715 g_return_val_if_fail (result != NULL, FALSE);
2717 val = _gtk_css_color_value_resolve (color,
2718 GTK_STYLE_PROVIDER_PRIVATE (context->priv->cascade),
2719 _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR),
2720 GTK_CSS_DEPENDS_ON_COLOR,
2725 *result = *_gtk_css_rgba_value_get_rgba (val);
2726 _gtk_css_value_unref (val);
2731 * gtk_style_context_lookup_color:
2732 * @context: a #GtkStyleContext
2733 * @color_name: color name to lookup
2734 * @color: (out): Return location for the looked up color
2736 * Looks up and resolves a color name in the @context color map.
2738 * Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
2741 gtk_style_context_lookup_color (GtkStyleContext *context,
2742 const gchar *color_name,
2747 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2748 g_return_val_if_fail (color_name != NULL, FALSE);
2749 g_return_val_if_fail (color != NULL, FALSE);
2751 value = _gtk_style_provider_private_get_color (GTK_STYLE_PROVIDER_PRIVATE (context->priv->cascade), color_name);
2755 return _gtk_style_context_resolve_color (context, value, color, NULL);
2759 * gtk_style_context_notify_state_change:
2760 * @context: a #GtkStyleContext
2761 * @window: a #GdkWindow
2762 * @region_id: (allow-none): animatable region to notify on, or %NULL.
2763 * See gtk_style_context_push_animatable_region()
2764 * @state: state to trigger transition for
2765 * @state_value: %TRUE if @state is the state we are changing to,
2766 * %FALSE if we are changing away from it
2768 * Notifies a state change on @context, so if the current style makes use
2769 * of transition animations, one will be started so all rendered elements
2770 * under @region_id are animated for state @state being set to value
2773 * The @window parameter is used in order to invalidate the rendered area
2774 * as the animation runs, so make sure it is the same window that is being
2775 * rendered on by the gtk_render_*() functions.
2777 * If @region_id is %NULL, all rendered elements using @context will be
2778 * affected by this state transition.
2780 * As a practical example, a #GtkButton notifying a state transition on
2781 * the prelight state:
2783 * gtk_style_context_notify_state_change (context,
2784 * gtk_widget_get_window (widget),
2786 * GTK_STATE_PRELIGHT,
2787 * button->in_button);
2790 * Can be handled in the CSS file like this:
2793 * background-color: #f00
2797 * background-color: #fff;
2798 * transition: 200ms linear
2802 * This combination will animate the button background from red to white
2803 * if a pointer enters the button, and back to red if the pointer leaves
2806 * Note that @state is used when finding the transition parameters, which
2807 * is why the style places the transition under the :hover pseudo-class.
2811 * Deprecated: 3.6: This function does nothing.
2814 gtk_style_context_notify_state_change (GtkStyleContext *context,
2818 gboolean state_value)
2820 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2821 g_return_if_fail (GDK_IS_WINDOW (window));
2822 g_return_if_fail (state > GTK_STATE_NORMAL && state <= GTK_STATE_FOCUSED);
2823 g_return_if_fail (context->priv->widget != NULL || context->priv->widget_path != NULL);
2827 * gtk_style_context_cancel_animations:
2828 * @context: a #GtkStyleContext
2829 * @region_id: (allow-none): animatable region to stop, or %NULL.
2830 * See gtk_style_context_push_animatable_region()
2832 * Stops all running animations for @region_id and all animatable
2833 * regions underneath.
2835 * A %NULL @region_id will stop all ongoing animations in @context,
2836 * when dealing with a #GtkStyleContext obtained through
2837 * gtk_widget_get_style_context(), this is normally done for you
2838 * in all circumstances you would expect all widget to be stopped,
2839 * so this should be only used in complex widgets with different
2840 * animatable regions.
2844 * Deprecated: 3.6: This function does nothing.
2847 gtk_style_context_cancel_animations (GtkStyleContext *context,
2850 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2854 * gtk_style_context_scroll_animations:
2855 * @context: a #GtkStyleContext
2856 * @window: a #GdkWindow used previously in
2857 * gtk_style_context_notify_state_change()
2858 * @dx: Amount to scroll in the X axis
2859 * @dy: Amount to scroll in the Y axis
2861 * This function is analogous to gdk_window_scroll(), and
2862 * should be called together with it so the invalidation
2863 * areas for any ongoing animation are scrolled together
2868 * Deprecated: 3.6: This function does nothing.
2871 gtk_style_context_scroll_animations (GtkStyleContext *context,
2876 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2877 g_return_if_fail (GDK_IS_WINDOW (window));
2881 * gtk_style_context_push_animatable_region:
2882 * @context: a #GtkStyleContext
2883 * @region_id: unique identifier for the animatable region
2885 * Pushes an animatable region, so all further gtk_render_*() calls between
2886 * this call and the following gtk_style_context_pop_animatable_region()
2887 * will potentially show transition animations for this region if
2888 * gtk_style_context_notify_state_change() is called for a given state,
2889 * and the current theme/style defines transition animations for state
2892 * The @region_id used must be unique in @context so the theming engine
2893 * can uniquely identify rendered elements subject to a state transition.
2897 * Deprecated: 3.6: This function does nothing.
2900 gtk_style_context_push_animatable_region (GtkStyleContext *context,
2903 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2904 g_return_if_fail (region_id != NULL);
2908 * gtk_style_context_pop_animatable_region:
2909 * @context: a #GtkStyleContext
2911 * Pops an animatable region from @context.
2912 * See gtk_style_context_push_animatable_region().
2916 * Deprecated: 3.6: This function does nothing.
2919 gtk_style_context_pop_animatable_region (GtkStyleContext *context)
2921 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2925 gtk_style_context_clear_cache (GtkStyleContext *context)
2927 GtkStyleContextPrivate *priv;
2930 priv = context->priv;
2932 for (info = priv->info; info; info = info->next)
2934 style_info_set_data (info, NULL);
2936 g_hash_table_remove_all (priv->style_data);
2940 gtk_style_context_update_cache (GtkStyleContext *context,
2941 const GtkBitmask *parent_changes)
2943 GtkStyleContextPrivate *priv;
2944 GHashTableIter iter;
2945 gpointer key, value;
2947 if (_gtk_bitmask_is_empty (parent_changes))
2950 priv = context->priv;
2952 g_hash_table_iter_init (&iter, priv->style_data);
2953 while (g_hash_table_iter_next (&iter, &key, &value))
2955 GtkStyleInfo *info = key;
2956 StyleData *data = value;
2957 GtkBitmask *changes;
2959 changes = _gtk_css_computed_values_compute_dependencies (data->store, parent_changes);
2961 if (!_gtk_bitmask_is_empty (changes))
2962 build_properties (context, data->store, info, changes);
2964 _gtk_bitmask_free (changes);
2969 gtk_style_context_do_invalidate (GtkStyleContext *context)
2971 GtkStyleContextPrivate *priv;
2973 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2975 priv = context->priv;
2977 /* Avoid reentrancy */
2978 if (priv->invalidating_context)
2981 priv->invalidating_context = TRUE;
2983 g_signal_emit (context, signals[CHANGED], 0);
2985 priv->invalidating_context = FALSE;
2989 gtk_style_context_update_animations (GtkStyleContext *context,
2992 GtkBitmask *differences;
2993 StyleData *style_data;
2995 style_data = style_data_lookup (context);
2997 differences = _gtk_css_computed_values_advance (style_data->store,
3000 if (_gtk_css_computed_values_is_static (style_data->store))
3001 _gtk_style_context_update_animating (context);
3007 gtk_style_context_needs_full_revalidate (GtkStyleContext *context,
3008 GtkCssChange change)
3010 GtkStyleContextPrivate *priv = context->priv;
3012 /* Try to avoid invalidating if we can */
3013 if (change & GTK_STYLE_CONTEXT_RADICAL_CHANGE)
3015 priv->relevant_changes = GTK_CSS_CHANGE_ANY;
3019 if (priv->relevant_changes == GTK_CSS_CHANGE_ANY)
3021 GtkWidgetPath *path;
3022 GtkCssMatcher matcher, superset;
3024 path = create_query_path (context, priv->info);
3025 if (_gtk_css_matcher_init (&matcher, path, priv->info->state_flags))
3027 _gtk_css_matcher_superset_init (&superset, &matcher, GTK_STYLE_CONTEXT_RADICAL_CHANGE & ~GTK_CSS_CHANGE_SOURCE);
3028 priv->relevant_changes = _gtk_style_provider_private_get_change (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
3032 priv->relevant_changes = 0;
3034 priv->relevant_changes &= ~GTK_STYLE_CONTEXT_RADICAL_CHANGE;
3036 gtk_widget_path_unref (path);
3040 if (priv->relevant_changes & change)
3047 gtk_style_context_should_create_transitions (GtkStyleContext *context)
3049 GtkStyleContextPrivate *priv;
3052 priv = context->priv;
3054 if (priv->widget == NULL)
3057 if (!gtk_widget_get_mapped (priv->widget))
3060 g_object_get (gtk_widget_get_settings (context->priv->widget),
3061 "gtk-enable-animations", &animate,
3068 _gtk_style_context_validate (GtkStyleContext *context,
3070 GtkCssChange change,
3071 const GtkBitmask *parent_changes)
3073 GtkStyleContextPrivate *priv;
3076 GtkBitmask *changes;
3079 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3081 priv = context->priv;
3083 change |= priv->pending_changes;
3085 /* If you run your application with
3086 * GTK_DEBUG=no-css-cache
3087 * every invalidation will purge the cache and completely query
3088 * everything anew form the cache. This is slow (in particular
3089 * when animating), but useful for figuring out bugs.
3091 * We achieve that by pretending that everything that could have
3092 * changed has and so we of course totally need to redo everything.
3094 * Note that this also completely revalidates child widgets all
3097 if (G_UNLIKELY (gtk_get_debug_flags () & GTK_DEBUG_NO_CSS_CACHE))
3098 change = GTK_CSS_CHANGE_ANY;
3100 if (!priv->invalid && change == 0 && _gtk_bitmask_is_empty (parent_changes))
3103 priv->pending_changes = 0;
3104 gtk_style_context_set_invalid (context, FALSE);
3108 current = style_data_ref (info->data);
3112 /* Try to avoid invalidating if we can */
3113 if (current == NULL ||
3114 gtk_style_context_needs_full_revalidate (context, change))
3118 if ((priv->relevant_changes & change) & ~GTK_STYLE_CONTEXT_CACHED_CHANGE)
3120 gtk_style_context_clear_cache (context);
3124 gtk_style_context_update_cache (context, parent_changes);
3125 style_info_set_data (info, NULL);
3128 data = style_data_lookup (context);
3130 _gtk_css_computed_values_create_animations (data->store,
3131 priv->parent ? style_data_lookup (priv->parent)->store : NULL,
3133 GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
3134 current && gtk_style_context_should_create_transitions (context) ? current->store : NULL);
3135 if (_gtk_css_computed_values_is_static (data->store))
3136 change &= ~GTK_CSS_CHANGE_ANIMATE;
3138 change |= GTK_CSS_CHANGE_ANIMATE;
3139 _gtk_style_context_update_animating (context);
3143 changes = _gtk_css_computed_values_get_difference (data->store, current->store);
3145 /* In the case where we keep the cache, we want unanimated values */
3146 _gtk_css_computed_values_cancel_animations (current->store);
3150 changes = _gtk_bitmask_new ();
3151 changes = _gtk_bitmask_invert_range (changes, 0, _gtk_css_style_property_get_n_properties ());
3156 changes = _gtk_css_computed_values_compute_dependencies (current->store, parent_changes);
3158 gtk_style_context_update_cache (context, parent_changes);
3162 style_data_unref (current);
3164 if (change & GTK_CSS_CHANGE_ANIMATE &&
3165 gtk_style_context_is_animating (context))
3167 GtkBitmask *animation_changes;
3169 animation_changes = gtk_style_context_update_animations (context, timestamp);
3170 changes = _gtk_bitmask_union (changes, animation_changes);
3171 _gtk_bitmask_free (animation_changes);
3174 if (!_gtk_bitmask_is_empty (changes) || (change & GTK_CSS_CHANGE_FORCE_INVALIDATE))
3175 gtk_style_context_do_invalidate (context);
3177 change = _gtk_css_change_for_child (change);
3178 for (list = priv->children; list; list = list->next)
3180 _gtk_style_context_validate (list->data, timestamp, change, changes);
3183 _gtk_bitmask_free (changes);
3187 _gtk_style_context_queue_invalidate (GtkStyleContext *context,
3188 GtkCssChange change)
3190 GtkStyleContextPrivate *priv;
3192 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3193 g_return_if_fail (change != 0);
3195 priv = context->priv;
3197 if (priv->widget != NULL)
3199 priv->pending_changes |= change;
3200 gtk_style_context_set_invalid (context, TRUE);
3202 else if (priv->widget_path == NULL)
3204 gtk_style_context_invalidate (context);
3209 * gtk_style_context_invalidate:
3210 * @context: a #GtkStyleContext.
3212 * Invalidates @context style information, so it will be reconstructed
3215 * If you're using a #GtkStyleContext returned from
3216 * gtk_widget_get_style_context(), you do not need to
3217 * call this yourself.
3222 gtk_style_context_invalidate (GtkStyleContext *context)
3224 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3226 gtk_style_context_clear_cache (context);
3227 gtk_style_context_do_invalidate (context);
3231 * gtk_style_context_set_background:
3232 * @context: a #GtkStyleContext
3233 * @window: a #GdkWindow
3235 * Sets the background of @window to the background pattern or
3236 * color specified in @context for its current state.
3241 gtk_style_context_set_background (GtkStyleContext *context,
3244 GtkStateFlags state;
3247 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3248 g_return_if_fail (GDK_IS_WINDOW (window));
3250 state = gtk_style_context_get_state (context);
3252 gtk_style_context_get (context, state,
3253 "background-color", &color,
3257 gdk_window_set_background_rgba (window, color);
3258 gdk_rgba_free (color);
3263 * gtk_style_context_get_color:
3264 * @context: a #GtkStyleContext
3265 * @state: state to retrieve the color for
3266 * @color: (out): return value for the foreground color
3268 * Gets the foreground color for a given state.
3273 gtk_style_context_get_color (GtkStyleContext *context,
3274 GtkStateFlags state,
3279 g_return_if_fail (color != NULL);
3280 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3282 gtk_style_context_get (context,
3292 * gtk_style_context_get_background_color:
3293 * @context: a #GtkStyleContext
3294 * @state: state to retrieve the color for
3295 * @color: (out): return value for the background color
3297 * Gets the background color for a given state.
3302 gtk_style_context_get_background_color (GtkStyleContext *context,
3303 GtkStateFlags state,
3308 g_return_if_fail (color != NULL);
3309 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3311 gtk_style_context_get (context,
3313 "background-color", &c,
3321 * gtk_style_context_get_border_color:
3322 * @context: a #GtkStyleContext
3323 * @state: state to retrieve the color for
3324 * @color: (out): return value for the border color
3326 * Gets the border color for a given state.
3331 gtk_style_context_get_border_color (GtkStyleContext *context,
3332 GtkStateFlags state,
3337 g_return_if_fail (color != NULL);
3338 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3340 gtk_style_context_get (context,
3350 * gtk_style_context_get_border:
3351 * @context: a #GtkStyleContext
3352 * @state: state to retrieve the border for
3353 * @border: (out): return value for the border settings
3355 * Gets the border for a given state as a #GtkBorder.
3356 * See %GTK_STYLE_PROPERTY_BORDER_WIDTH.
3361 gtk_style_context_get_border (GtkStyleContext *context,
3362 GtkStateFlags state,
3365 int top, left, bottom, right;
3367 g_return_if_fail (border != NULL);
3368 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3370 gtk_style_context_get (context,
3372 "border-top-width", &top,
3373 "border-left-width", &left,
3374 "border-bottom-width", &bottom,
3375 "border-right-width", &right,
3379 border->left = left;
3380 border->bottom = bottom;
3381 border->right = right;
3385 * gtk_style_context_get_padding:
3386 * @context: a #GtkStyleContext
3387 * @state: state to retrieve the padding for
3388 * @padding: (out): return value for the padding settings
3390 * Gets the padding for a given state as a #GtkBorder.
3391 * See %GTK_STYLE_PROPERTY_PADDING.
3396 gtk_style_context_get_padding (GtkStyleContext *context,
3397 GtkStateFlags state,
3400 int top, left, bottom, right;
3402 g_return_if_fail (padding != NULL);
3403 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3405 gtk_style_context_get (context,
3407 "padding-top", &top,
3408 "padding-left", &left,
3409 "padding-bottom", &bottom,
3410 "padding-right", &right,
3414 padding->left = left;
3415 padding->bottom = bottom;
3416 padding->right = right;
3420 * gtk_style_context_get_margin:
3421 * @context: a #GtkStyleContext
3422 * @state: state to retrieve the border for
3423 * @margin: (out): return value for the margin settings
3425 * Gets the margin for a given state as a #GtkBorder.
3426 * See %GTK_STYLE_PROPERTY_MARGIN.
3431 gtk_style_context_get_margin (GtkStyleContext *context,
3432 GtkStateFlags state,
3435 int top, left, bottom, right;
3437 g_return_if_fail (margin != NULL);
3438 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3440 gtk_style_context_get (context,
3443 "margin-left", &left,
3444 "margin-bottom", &bottom,
3445 "margin-right", &right,
3449 margin->left = left;
3450 margin->bottom = bottom;
3451 margin->right = right;
3455 * gtk_style_context_get_font:
3456 * @context: a #GtkStyleContext
3457 * @state: state to retrieve the font for
3459 * Returns the font description for a given state. The returned
3460 * object is const and will remain valid until the
3461 * #GtkStyleContext::changed signal happens.
3463 * Returns: (transfer none): the #PangoFontDescription for the given
3464 * state. This object is owned by GTK+ and should not be
3469 const PangoFontDescription *
3470 gtk_style_context_get_font (GtkStyleContext *context,
3471 GtkStateFlags state)
3473 GtkStyleContextPrivate *priv;
3475 PangoFontDescription *description;
3477 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
3479 priv = context->priv;
3480 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
3482 data = style_data_lookup_for_state (context, state);
3484 /* Yuck, fonts are created on-demand but we don't return a ref.
3485 * Do bad things to achieve this requirement */
3486 description = g_object_get_data (G_OBJECT (data->store), "font-cache-for-get_font");
3487 if (description == NULL)
3489 gtk_style_context_get (context, state, "font", &description, NULL);
3490 g_object_set_data_full (G_OBJECT (data->store),
3491 "font-cache-for-get_font",
3493 (GDestroyNotify) pango_font_description_free);
3499 get_cursor_color (GtkStyleContext *context,
3503 GdkColor *style_color;
3505 gtk_style_context_get_style (context,
3506 primary ? "cursor-color" : "secondary-cursor-color",
3512 color->red = style_color->red / 65535.0;
3513 color->green = style_color->green / 65535.0;
3514 color->blue = style_color->blue / 65535.0;
3517 gdk_color_free (style_color);
3521 gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, color);
3527 gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &bg);
3529 color->red = (color->red + bg.red) * 0.5;
3530 color->green = (color->green + bg.green) * 0.5;
3531 color->blue = (color->blue + bg.blue) * 0.5;
3537 _gtk_style_context_get_cursor_color (GtkStyleContext *context,
3538 GdkRGBA *primary_color,
3539 GdkRGBA *secondary_color)
3542 get_cursor_color (context, TRUE, primary_color);
3544 if (secondary_color)
3545 get_cursor_color (context, FALSE, secondary_color);
3552 * @context: a #GtkStyleContext
3554 * @x: X origin of the rectangle
3555 * @y: Y origin of the rectangle
3556 * @width: rectangle width
3557 * @height: rectangle height
3559 * Renders a checkmark (as in a #GtkCheckButton).
3561 * The %GTK_STATE_FLAG_ACTIVE state determines whether the check is
3562 * on or off, and %GTK_STATE_FLAG_INCONSISTENT determines whether it
3563 * should be marked as undefined.
3566 * <title>Typical checkmark rendering</title>
3567 * <inlinegraphic fileref="checks.png" format="PNG"/>
3573 gtk_render_check (GtkStyleContext *context,
3580 GtkThemingEngineClass *engine_class;
3581 GtkThemingEngine *engine;
3583 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3584 g_return_if_fail (cr != NULL);
3586 if (width <= 0 || height <= 0)
3589 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3590 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3595 _gtk_theming_engine_set_context (engine, context);
3596 engine_class->render_check (engine, cr,
3597 x, y, width, height);
3603 * gtk_render_option:
3604 * @context: a #GtkStyleContext
3606 * @x: X origin of the rectangle
3607 * @y: Y origin of the rectangle
3608 * @width: rectangle width
3609 * @height: rectangle height
3611 * Renders an option mark (as in a #GtkRadioButton), the %GTK_STATE_FLAG_ACTIVE
3612 * state will determine whether the option is on or off, and
3613 * %GTK_STATE_FLAG_INCONSISTENT whether it should be marked as undefined.
3616 * <title>Typical option mark rendering</title>
3617 * <inlinegraphic fileref="options.png" format="PNG"/>
3623 gtk_render_option (GtkStyleContext *context,
3630 GtkThemingEngineClass *engine_class;
3631 GtkThemingEngine *engine;
3633 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3634 g_return_if_fail (cr != NULL);
3636 if (width <= 0 || height <= 0)
3639 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3640 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3644 _gtk_theming_engine_set_context (engine, context);
3645 engine_class->render_option (engine, cr,
3646 x, y, width, height);
3653 * @context: a #GtkStyleContext
3655 * @angle: arrow angle from 0 to 2 * %G_PI, being 0 the arrow pointing to the north
3656 * @x: X origin of the render area
3657 * @y: Y origin of the render area
3658 * @size: square side for render area
3660 * Renders an arrow pointing to @angle.
3663 * <title>Typical arrow rendering at 0, 1&solidus;2 π, π and 3&solidus;2 π</title>
3664 * <inlinegraphic fileref="arrows.png" format="PNG"/>
3670 gtk_render_arrow (GtkStyleContext *context,
3677 GtkThemingEngineClass *engine_class;
3678 GtkThemingEngine *engine;
3680 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3681 g_return_if_fail (cr != NULL);
3686 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3687 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3691 gtk_style_context_save (context);
3692 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ARROW);
3694 _gtk_theming_engine_set_context (engine, context);
3695 engine_class->render_arrow (engine, cr,
3698 gtk_style_context_restore (context);
3703 * gtk_render_background:
3704 * @context: a #GtkStyleContext
3706 * @x: X origin of the rectangle
3707 * @y: Y origin of the rectangle
3708 * @width: rectangle width
3709 * @height: rectangle height
3711 * Renders the background of an element.
3714 * <title>Typical background rendering, showing the effect of
3715 * <parameter>background-image</parameter>,
3716 * <parameter>border-width</parameter> and
3717 * <parameter>border-radius</parameter></title>
3718 * <inlinegraphic fileref="background.png" format="PNG"/>
3724 gtk_render_background (GtkStyleContext *context,
3731 GtkThemingEngineClass *engine_class;
3732 GtkThemingEngine *engine;
3734 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3735 g_return_if_fail (cr != NULL);
3737 if (width <= 0 || height <= 0)
3740 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3741 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3745 _gtk_theming_engine_set_context (engine, context);
3746 engine_class->render_background (engine, cr, x, y, width, height);
3753 * @context: a #GtkStyleContext
3755 * @x: X origin of the rectangle
3756 * @y: Y origin of the rectangle
3757 * @width: rectangle width
3758 * @height: rectangle height
3760 * Renders a frame around the rectangle defined by @x, @y, @width, @height.
3763 * <title>Examples of frame rendering, showing the effect of
3764 * <parameter>border-image</parameter>,
3765 * <parameter>border-color</parameter>,
3766 * <parameter>border-width</parameter>,
3767 * <parameter>border-radius</parameter> and
3769 * <inlinegraphic fileref="frames.png" format="PNG"/>
3775 gtk_render_frame (GtkStyleContext *context,
3782 GtkThemingEngineClass *engine_class;
3783 GtkThemingEngine *engine;
3785 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3786 g_return_if_fail (cr != NULL);
3788 if (width <= 0 || height <= 0)
3791 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3792 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3796 _gtk_theming_engine_set_context (engine, context);
3797 engine_class->render_frame (engine, cr, x, y, width, height);
3803 * gtk_render_expander:
3804 * @context: a #GtkStyleContext
3806 * @x: X origin of the rectangle
3807 * @y: Y origin of the rectangle
3808 * @width: rectangle width
3809 * @height: rectangle height
3811 * Renders an expander (as used in #GtkTreeView and #GtkExpander) in the area
3812 * defined by @x, @y, @width, @height. The state %GTK_STATE_FLAG_ACTIVE
3813 * determines whether the expander is collapsed or expanded.
3816 * <title>Typical expander rendering</title>
3817 * <inlinegraphic fileref="expanders.png" format="PNG"/>
3823 gtk_render_expander (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_expander (engine, cr, x, y, width, height);
3852 * @context: a #GtkStyleContext
3854 * @x: X origin of the rectangle
3855 * @y: Y origin of the rectangle
3856 * @width: rectangle width
3857 * @height: rectangle height
3859 * Renders a focus indicator on the rectangle determined by @x, @y, @width, @height.
3861 * <title>Typical focus rendering</title>
3862 * <inlinegraphic fileref="focus.png" format="PNG"/>
3868 gtk_render_focus (GtkStyleContext *context,
3875 GtkThemingEngineClass *engine_class;
3876 GtkThemingEngine *engine;
3878 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3879 g_return_if_fail (cr != NULL);
3881 if (width <= 0 || height <= 0)
3884 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3885 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3889 _gtk_theming_engine_set_context (engine, context);
3890 engine_class->render_focus (engine, cr, x, y, width, height);
3896 * gtk_render_layout:
3897 * @context: a #GtkStyleContext
3901 * @layout: the #PangoLayout to render
3903 * Renders @layout on the coordinates @x, @y
3908 gtk_render_layout (GtkStyleContext *context,
3912 PangoLayout *layout)
3914 GtkThemingEngineClass *engine_class;
3915 GtkThemingEngine *engine;
3916 PangoRectangle extents;
3918 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3919 g_return_if_fail (PANGO_IS_LAYOUT (layout));
3920 g_return_if_fail (cr != NULL);
3922 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3923 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3927 pango_layout_get_extents (layout, &extents, NULL);
3929 _gtk_theming_engine_set_context (engine, context);
3930 engine_class->render_layout (engine, cr, x, y, layout);
3937 * @context: a #GtkStyleContext
3939 * @x0: X coordinate for the origin of the line
3940 * @y0: Y coordinate for the origin of the line
3941 * @x1: X coordinate for the end of the line
3942 * @y1: Y coordinate for the end of the line
3944 * Renders a line from (x0, y0) to (x1, y1).
3949 gtk_render_line (GtkStyleContext *context,
3956 GtkThemingEngineClass *engine_class;
3957 GtkThemingEngine *engine;
3959 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3960 g_return_if_fail (cr != NULL);
3962 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3963 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3967 _gtk_theming_engine_set_context (engine, context);
3968 engine_class->render_line (engine, cr, x0, y0, x1, y1);
3974 * gtk_render_slider:
3975 * @context: a #GtkStyleContext
3977 * @x: X origin of the rectangle
3978 * @y: Y origin of the rectangle
3979 * @width: rectangle width
3980 * @height: rectangle height
3981 * @orientation: orientation of the slider
3983 * Renders a slider (as in #GtkScale) in the rectangle defined by @x, @y,
3984 * @width, @height. @orientation defines whether the slider is vertical
3988 * <title>Typical slider rendering</title>
3989 * <inlinegraphic fileref="sliders.png" format="PNG"/>
3995 gtk_render_slider (GtkStyleContext *context,
4001 GtkOrientation orientation)
4003 GtkThemingEngineClass *engine_class;
4004 GtkThemingEngine *engine;
4006 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4007 g_return_if_fail (cr != NULL);
4009 if (width <= 0 || height <= 0)
4012 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4013 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4017 _gtk_theming_engine_set_context (engine, context);
4018 engine_class->render_slider (engine, cr, x, y, width, height, orientation);
4024 * gtk_render_frame_gap:
4025 * @context: a #GtkStyleContext
4027 * @x: X origin of the rectangle
4028 * @y: Y origin of the rectangle
4029 * @width: rectangle width
4030 * @height: rectangle height
4031 * @gap_side: side where the gap is
4032 * @xy0_gap: initial coordinate (X or Y depending on @gap_side) for the gap
4033 * @xy1_gap: end coordinate (X or Y depending on @gap_side) for the gap
4035 * Renders a frame around the rectangle defined by (@x, @y, @width, @height),
4036 * leaving a gap on one side. @xy0_gap and @xy1_gap will mean X coordinates
4037 * for %GTK_POS_TOP and %GTK_POS_BOTTOM gap sides, and Y coordinates for
4038 * %GTK_POS_LEFT and %GTK_POS_RIGHT.
4041 * <title>Typical rendering of a frame with a gap</title>
4042 * <inlinegraphic fileref="frame-gap.png" format="PNG"/>
4048 gtk_render_frame_gap (GtkStyleContext *context,
4054 GtkPositionType gap_side,
4058 GtkThemingEngineClass *engine_class;
4059 GtkThemingEngine *engine;
4061 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4062 g_return_if_fail (cr != NULL);
4063 g_return_if_fail (xy0_gap <= xy1_gap);
4064 g_return_if_fail (xy0_gap >= 0);
4066 if (width <= 0 || height <= 0)
4069 if (gap_side == GTK_POS_LEFT ||
4070 gap_side == GTK_POS_RIGHT)
4071 g_return_if_fail (xy1_gap <= height);
4073 g_return_if_fail (xy1_gap <= width);
4075 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4076 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4080 _gtk_theming_engine_set_context (engine, context);
4081 engine_class->render_frame_gap (engine, cr,
4082 x, y, width, height, gap_side,
4089 * gtk_render_extension:
4090 * @context: a #GtkStyleContext
4092 * @x: X origin of the rectangle
4093 * @y: Y origin of the rectangle
4094 * @width: rectangle width
4095 * @height: rectangle height
4096 * @gap_side: side where the gap is
4098 * Renders a extension (as in a #GtkNotebook tab) in the rectangle
4099 * defined by @x, @y, @width, @height. The side where the extension
4100 * connects to is defined by @gap_side.
4103 * <title>Typical extension rendering</title>
4104 * <inlinegraphic fileref="extensions.png" format="PNG"/>
4110 gtk_render_extension (GtkStyleContext *context,
4116 GtkPositionType gap_side)
4118 GtkThemingEngineClass *engine_class;
4119 GtkThemingEngine *engine;
4121 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4122 g_return_if_fail (cr != NULL);
4124 if (width <= 0 || height <= 0)
4127 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4128 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4132 _gtk_theming_engine_set_context (engine, context);
4133 engine_class->render_extension (engine, cr, x, y, width, height, gap_side);
4139 * gtk_render_handle:
4140 * @context: a #GtkStyleContext
4142 * @x: X origin of the rectangle
4143 * @y: Y origin of the rectangle
4144 * @width: rectangle width
4145 * @height: rectangle height
4147 * Renders a handle (as in #GtkHandleBox, #GtkPaned and
4148 * #GtkWindow<!-- -->'s resize grip), in the rectangle
4149 * determined by @x, @y, @width, @height.
4152 * <title>Handles rendered for the paned and grip classes</title>
4153 * <inlinegraphic fileref="handles.png" format="PNG"/>
4159 gtk_render_handle (GtkStyleContext *context,
4166 GtkThemingEngineClass *engine_class;
4167 GtkThemingEngine *engine;
4169 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4170 g_return_if_fail (cr != NULL);
4172 if (width <= 0 || height <= 0)
4175 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4176 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4180 _gtk_theming_engine_set_context (engine, context);
4181 engine_class->render_handle (engine, cr, x, y, width, height);
4187 * gtk_render_activity:
4188 * @context: a #GtkStyleContext
4190 * @x: X origin of the rectangle
4191 * @y: Y origin of the rectangle
4192 * @width: rectangle width
4193 * @height: rectangle height
4195 * Renders an activity area (Such as in #GtkSpinner or the
4196 * fill line in #GtkRange), the state %GTK_STATE_FLAG_ACTIVE
4197 * determines whether there is activity going on.
4202 gtk_render_activity (GtkStyleContext *context,
4209 GtkThemingEngineClass *engine_class;
4210 GtkThemingEngine *engine;
4212 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4213 g_return_if_fail (cr != NULL);
4215 if (width <= 0 || height <= 0)
4218 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4219 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4223 _gtk_theming_engine_set_context (engine, context);
4224 engine_class->render_activity (engine, cr, x, y, width, height);
4230 * gtk_render_icon_pixbuf:
4231 * @context: a #GtkStyleContext
4232 * @source: the #GtkIconSource specifying the icon to render
4233 * @size: (type int): the size to render the icon at. A size of (GtkIconSize) -1
4234 * means render at the size of the source and don't scale.
4236 * Renders the icon specified by @source at the given @size, returning the result
4239 * Returns: (transfer full): a newly-created #GdkPixbuf containing the rendered icon
4244 gtk_render_icon_pixbuf (GtkStyleContext *context,
4245 const GtkIconSource *source,
4248 GtkThemingEngineClass *engine_class;
4249 GtkThemingEngine *engine;
4251 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
4252 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
4253 g_return_val_if_fail (source != NULL, NULL);
4255 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4256 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4258 _gtk_theming_engine_set_context (engine, context);
4259 return engine_class->render_icon_pixbuf (engine, source, size);
4264 * @context: a #GtkStyleContext
4266 * @pixbuf: a #GdkPixbuf containing the icon to draw
4267 * @x: X position for the @pixbuf
4268 * @y: Y position for the @pixbuf
4270 * Renders the icon in @pixbuf at the specified @x and @y coordinates.
4275 gtk_render_icon (GtkStyleContext *context,
4281 GtkThemingEngineClass *engine_class;
4282 GtkThemingEngine *engine;
4284 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4285 g_return_if_fail (cr != NULL);
4287 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4288 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4292 _gtk_theming_engine_set_context (engine, context);
4293 engine_class->render_icon (engine, cr, pixbuf, x, y);
4299 draw_insertion_cursor (GtkStyleContext *context,
4304 gboolean is_primary,
4305 PangoDirection direction,
4306 gboolean draw_arrow)
4309 GdkRGBA primary_color;
4310 GdkRGBA secondary_color;
4311 gfloat cursor_aspect_ratio;
4317 _gtk_style_context_get_cursor_color (context, &primary_color, &secondary_color);
4318 gdk_cairo_set_source_rgba (cr, is_primary ? &primary_color : &secondary_color);
4320 /* When changing the shape or size of the cursor here,
4321 * propagate the changes to gtktextview.c:text_window_invalidate_cursors().
4324 gtk_style_context_get_style (context,
4325 "cursor-aspect-ratio", &cursor_aspect_ratio,
4328 stem_width = height * cursor_aspect_ratio + 1;
4330 /* put (stem_width % 2) on the proper side of the cursor */
4331 if (direction == PANGO_DIRECTION_LTR)
4332 offset = stem_width / 2;
4334 offset = stem_width - stem_width / 2;
4336 cairo_rectangle (cr, x - offset, y, stem_width, height);
4344 arrow_width = stem_width + 1;
4346 if (direction == PANGO_DIRECTION_RTL)
4348 ax = x - offset - 1;
4349 ay = y + height - arrow_width * 2 - arrow_width + 1;
4351 cairo_move_to (cr, ax, ay + 1);
4352 cairo_line_to (cr, ax - arrow_width, ay + arrow_width);
4353 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4356 else if (direction == PANGO_DIRECTION_LTR)
4358 ax = x + stem_width - offset;
4359 ay = y + height - arrow_width * 2 - arrow_width + 1;
4361 cairo_move_to (cr, ax, ay + 1);
4362 cairo_line_to (cr, ax + arrow_width, ay + arrow_width);
4363 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4367 g_assert_not_reached();
4374 * gtk_render_insertion_cursor:
4375 * @context: a #GtkStyleContext
4379 * @layout: the #PangoLayout of the text
4380 * @index: the index in the #PangoLayout
4381 * @direction: the #PangoDirection of the text
4383 * Draws a text caret on @cr at the specified index of @layout.
4388 gtk_render_insertion_cursor (GtkStyleContext *context,
4392 PangoLayout *layout,
4394 PangoDirection direction)
4396 GtkStyleContextPrivate *priv;
4397 gboolean split_cursor;
4398 PangoRectangle strong_pos, weak_pos;
4399 PangoRectangle *cursor1, *cursor2;
4400 PangoDirection keymap_direction;
4401 PangoDirection direction2;
4403 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4404 g_return_if_fail (cr != NULL);
4405 g_return_if_fail (PANGO_IS_LAYOUT (layout));
4406 g_return_if_fail (index >= 0);
4408 priv = context->priv;
4410 g_object_get (gtk_settings_get_for_screen (priv->screen),
4411 "gtk-split-cursor", &split_cursor,
4414 keymap_direction = gdk_keymap_get_direction (gdk_keymap_get_for_display (gdk_screen_get_display (priv->screen)));
4416 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4418 direction2 = PANGO_DIRECTION_NEUTRAL;
4422 cursor1 = &strong_pos;
4424 if (strong_pos.x != weak_pos.x || strong_pos.y != weak_pos.y)
4426 direction2 = (direction == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
4427 cursor2 = &weak_pos;
4432 if (keymap_direction == direction)
4433 cursor1 = &strong_pos;
4435 cursor1 = &weak_pos;
4438 draw_insertion_cursor (context,
4440 x + PANGO_PIXELS (cursor1->x),
4441 y + PANGO_PIXELS (cursor1->y),
4442 PANGO_PIXELS (cursor1->height),
4445 direction2 != PANGO_DIRECTION_NEUTRAL);
4447 if (direction2 != PANGO_DIRECTION_NEUTRAL)
4449 draw_insertion_cursor (context,
4451 x + PANGO_PIXELS (cursor2->x),
4452 y + PANGO_PIXELS (cursor2->y),
4453 PANGO_PIXELS (cursor2->height),
4461 * gtk_draw_insertion_cursor:
4462 * @widget: a #GtkWidget
4463 * @cr: cairo context to draw to
4464 * @location: location where to draw the cursor (@location->width is ignored)
4465 * @is_primary: if the cursor should be the primary cursor color.
4466 * @direction: whether the cursor is left-to-right or
4467 * right-to-left. Should never be #GTK_TEXT_DIR_NONE
4468 * @draw_arrow: %TRUE to draw a directional arrow on the
4469 * cursor. Should be %FALSE unless the cursor is split.
4471 * Draws a text caret on @cr at @location. This is not a style function
4472 * but merely a convenience function for drawing the standard cursor shape.
4475 * Deprecated: 3.4: Use gtk_render_insertion_cursor() instead.
4478 gtk_draw_insertion_cursor (GtkWidget *widget,
4480 const GdkRectangle *location,
4481 gboolean is_primary,
4482 GtkTextDirection direction,
4483 gboolean draw_arrow)
4485 GtkStyleContext *context;
4487 g_return_if_fail (GTK_IS_WIDGET (widget));
4488 g_return_if_fail (cr != NULL);
4489 g_return_if_fail (location != NULL);
4490 g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
4492 context = gtk_widget_get_style_context (widget);
4494 draw_insertion_cursor (context, cr,
4495 location->x, location->y, location->height,
4497 (direction == GTK_TEXT_DIR_RTL) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR,
4501 static AtkAttributeSet *
4502 add_attribute (AtkAttributeSet *attributes,
4503 AtkTextAttribute attr,
4508 at = g_new (AtkAttribute, 1);
4509 at->name = g_strdup (atk_text_attribute_get_name (attr));
4510 at->value = g_strdup (value);
4512 return g_slist_prepend (attributes, at);
4516 * _gtk_style_context_get_attributes:
4517 * @attributes: a #AtkAttributeSet to add attributes to
4518 * @context: the #GtkStyleContext to get attributes from
4519 * @flags: the state to use with @context
4521 * Adds the foreground and background color from @context to
4522 * @attributes, after translating them to ATK attributes.
4524 * This is a convenience function that can be used in
4525 * implementing the #AtkText interface in widgets.
4527 * Returns: the modified #AtkAttributeSet
4530 _gtk_style_context_get_attributes (AtkAttributeSet *attributes,
4531 GtkStyleContext *context,
4532 GtkStateFlags flags)
4537 gtk_style_context_get_background_color (context, flags, &color);
4538 value = g_strdup_printf ("%u,%u,%u",
4539 (guint) ceil (color.red * 65536 - color.red),
4540 (guint) ceil (color.green * 65536 - color.green),
4541 (guint) ceil (color.blue * 65536 - color.blue));
4542 attributes = add_attribute (attributes, ATK_TEXT_ATTR_BG_COLOR, value);
4545 gtk_style_context_get_color (context, flags, &color);
4546 value = g_strdup_printf ("%u,%u,%u",
4547 (guint) ceil (color.red * 65536 - color.red),
4548 (guint) ceil (color.green * 65536 - color.green),
4549 (guint) ceil (color.blue * 65536 - color.blue));
4550 attributes = add_attribute (attributes, ATK_TEXT_ATTR_FG_COLOR, value);
4557 gtk_gradient_resolve_for_context (GtkGradient *gradient,
4558 GtkStyleContext *context)
4560 GtkStyleContextPrivate *priv = context->priv;
4561 GtkCssDependencies ignored = 0;
4563 g_return_val_if_fail (gradient != NULL, NULL);
4564 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
4566 return _gtk_gradient_resolve_full (gradient,
4567 GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
4568 style_data_lookup (context)->store,
4569 priv->parent ? style_data_lookup (priv->parent)->store : NULL,