1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2010 Carlos Garnacho <carlosg@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
23 #include <gobject/gvaluecollector.h>
25 #include "gtkstylecontextprivate.h"
26 #include "gtkcontainerprivate.h"
27 #include "gtkcssenginevalueprivate.h"
28 #include "gtkcssnumbervalueprivate.h"
29 #include "gtkcssrgbavalueprivate.h"
31 #include "gtkstylepropertiesprivate.h"
32 #include "gtktypebuiltins.h"
33 #include "gtkthemingengineprivate.h"
35 #include "gtkwidget.h"
36 #include "gtkwindow.h"
37 #include "gtkprivate.h"
38 #include "gtksymboliccolorprivate.h"
39 #include "gtkiconfactory.h"
40 #include "gtkwidgetpath.h"
41 #include "gtkwidgetprivate.h"
42 #include "gtkstylecascadeprivate.h"
43 #include "gtkstyleproviderprivate.h"
44 #include "gtksettings.h"
45 #include "gtksettingsprivate.h"
48 * SECTION:gtkstylecontext
49 * @Short_description: Rendering UI elements
50 * @Title: GtkStyleContext
52 * #GtkStyleContext is an object that stores styling information affecting
53 * a widget defined by #GtkWidgetPath.
55 * In order to construct the final style information, #GtkStyleContext
56 * queries information from all attached #GtkStyleProviders. Style providers
57 * can be either attached explicitly to the context through
58 * gtk_style_context_add_provider(), or to the screen through
59 * gtk_style_context_add_provider_for_screen(). The resulting style is a
60 * combination of all providers' information in priority order.
62 * For GTK+ widgets, any #GtkStyleContext returned by
63 * gtk_widget_get_style_context() will already have a #GtkWidgetPath, a
64 * #GdkScreen and RTL/LTR information set. The style context will be also
65 * updated automatically if any of these settings change on the widget.
67 * If you are using the theming layer standalone, you will need to set a
68 * widget path and a screen yourself to the created style context through
69 * gtk_style_context_set_path() and gtk_style_context_set_screen(), as well
70 * as updating the context yourself using gtk_style_context_invalidate()
71 * whenever any of the conditions change, such as a change in the
72 * #GtkSettings:gtk-theme-name setting or a hierarchy change in the rendered
75 * <refsect2 id="gtkstylecontext-animations">
76 * <title>Transition animations</title>
78 * #GtkStyleContext has built-in support for state change transitions.
79 * Note that these animations respect the #GtkSettings:gtk-enable-animations
83 * For simple widgets where state changes affect the whole widget area,
84 * calling gtk_style_context_notify_state_change() with a %NULL region
85 * is sufficient to trigger the transition animation. And GTK+ already
86 * does that when gtk_widget_set_state() or gtk_widget_set_state_flags()
90 * If a widget needs to declare several animatable regions (i.e. not
91 * affecting the whole widget area), its #GtkWidget::draw signal handler
92 * needs to wrap the render operations for the different regions with
93 * calls to gtk_style_context_push_animatable_region() and
94 * gtk_style_context_pop_animatable_region(). These functions take an
95 * identifier for the region which must be unique within the style context.
96 * For simple widgets with a fixed set of animatable regions, using an
97 * enumeration works well:
100 * <title>Using an enumeration to identify animatable regions</title>
111 * spin_button_draw (GtkWidget *widget,
114 * GtkStyleContext *context;
116 * context = gtk_widget_get_style_context (widget);
118 * gtk_style_context_push_animatable_region (context,
119 * GUINT_TO_POINTER (REGION_ENTRY));
121 * gtk_render_background (cr, 0, 0, 100, 30);
122 * gtk_render_frame (cr, 0, 0, 100, 30);
124 * gtk_style_context_pop_animatable_region (context);
131 * For complex widgets with an arbitrary number of animatable regions, it
132 * is up to the implementation to come up with a way to uniquely identify
133 * each animatable region. Using pointers to internal structs is one way
137 * <title>Using struct pointers to identify animatable regions</title>
140 * notebook_draw_tab (GtkWidget *widget,
141 * NotebookPage *page,
144 * gtk_style_context_push_animatable_region (context, page);
145 * gtk_render_extension (cr, page->x, page->y, page->width, page->height);
146 * gtk_style_context_pop_animatable_region (context);
151 * The widget also needs to notify the style context about a state change
152 * for a given animatable region so the animation is triggered.
155 * <title>Triggering a state change animation on a region</title>
158 * notebook_motion_notify (GtkWidget *widget,
159 * GdkEventMotion *event)
161 * GtkStyleContext *context;
162 * NotebookPage *page;
164 * context = gtk_widget_get_style_context (widget);
165 * page = find_page_under_pointer (widget, event);
166 * gtk_style_context_notify_state_change (context,
167 * gtk_widget_get_window (widget),
169 * GTK_STATE_PRELIGHT,
176 * gtk_style_context_notify_state_change() accepts %NULL region IDs as a
177 * special value, in this case, the whole widget area will be updated
181 * <refsect2 id="gtkstylecontext-classes">
182 * <title>Style classes and regions</title>
184 * Widgets can add style classes to their context, which can be used
185 * to associate different styles by class (see <xref linkend="gtkcssprovider-selectors"/>). Theme engines can also use style classes to vary their
186 * rendering. GTK+ has a number of predefined style classes:
187 * #GTK_STYLE_CLASS_CELL,
188 * #GTK_STYLE_CLASS_ENTRY,
189 * #GTK_STYLE_CLASS_BUTTON,
190 * #GTK_STYLE_CLASS_COMBOBOX_ENTRY,
191 * #GTK_STYLE_CLASS_CALENDAR,
192 * #GTK_STYLE_CLASS_SLIDER,
193 * #GTK_STYLE_CLASS_BACKGROUND,
194 * #GTK_STYLE_CLASS_RUBBERBAND,
195 * #GTK_STYLE_CLASS_TOOLTIP,
196 * #GTK_STYLE_CLASS_MENU,
197 * #GTK_STYLE_CLASS_MENUBAR,
198 * #GTK_STYLE_CLASS_MENUITEM,
199 * #GTK_STYLE_CLASS_TOOLBAR,
200 * #GTK_STYLE_CLASS_PRIMARY_TOOLBAR,
201 * #GTK_STYLE_CLASS_INLINE_TOOLBAR,
202 * #GTK_STYLE_CLASS_RADIO,
203 * #GTK_STYLE_CLASS_CHECK,
204 * #GTK_STYLE_CLASS_TROUGH,
205 * #GTK_STYLE_CLASS_SCROLLBAR,
206 * #GTK_STYLE_CLASS_SCALE,
207 * #GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE,
208 * #GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW,
209 * #GTK_STYLE_CLASS_HEADER,
210 * #GTK_STYLE_CLASS_ACCELERATOR,
211 * #GTK_STYLE_CLASS_GRIP,
212 * #GTK_STYLE_CLASS_DOCK,
213 * #GTK_STYLE_CLASS_PROGRESSBAR,
214 * #GTK_STYLE_CLASS_SPINNER,
215 * #GTK_STYLE_CLASS_EXPANDER,
216 * #GTK_STYLE_CLASS_SPINBUTTON,
217 * #GTK_STYLE_CLASS_NOTEBOOK,
218 * #GTK_STYLE_CLASS_VIEW,
219 * #GTK_STYLE_CLASS_SIDEBAR,
220 * #GTK_STYLE_CLASS_IMAGE,
221 * #GTK_STYLE_CLASS_HIGHLIGHT,
222 * #GTK_STYLE_CLASS_FRAME,
223 * #GTK_STYLE_CLASS_DND,
224 * #GTK_STYLE_CLASS_PANE_SEPARATOR,
225 * #GTK_STYLE_CLASS_SEPARATOR,
226 * #GTK_STYLE_CLASS_INFO,
227 * #GTK_STYLE_CLASS_WARNING,
228 * #GTK_STYLE_CLASS_QUESTION,
229 * #GTK_STYLE_CLASS_ERROR,
230 * #GTK_STYLE_CLASS_HORIZONTAL,
231 * #GTK_STYLE_CLASS_VERTICAL,
232 * #GTK_STYLE_CLASS_TOP,
233 * #GTK_STYLE_CLASS_BOTTOM,
234 * #GTK_STYLE_CLASS_LEFT,
235 * #GTK_STYLE_CLASS_RIGHT,
238 * Widgets can also add regions with flags to their context.
239 * The regions used by GTK+ widgets are:
244 * <entry>Region</entry>
245 * <entry>Flags</entry>
246 * <entry>Macro</entry>
247 * <entry>Used by</entry>
253 * <entry>even, odd</entry>
254 * <entry>GTK_STYLE_REGION_ROW</entry>
255 * <entry>#GtkTreeView</entry>
258 * <entry>column</entry>
259 * <entry>first, last, sorted</entry>
260 * <entry>GTK_STYLE_REGION_COLUMN</entry>
261 * <entry>#GtkTreeView</entry>
264 * <entry>column-header</entry>
266 * <entry>GTK_STYLE_REGION_COLUMN_HEADER</entry>
271 * <entry>even, odd, first, last</entry>
272 * <entry>GTK_STYLE_REGION_TAB</entry>
273 * <entry>#GtkNotebook</entry>
280 * <refsect2 id="gtkstylecontext-custom-styling">
281 * <title>Custom styling in UI libraries and applications</title>
283 * If you are developing a library with custom #GtkWidget<!-- -->s that
284 * render differently than standard components, you may need to add a
285 * #GtkStyleProvider yourself with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK
286 * priority, either a #GtkCssProvider or a custom object implementing the
287 * #GtkStyleProvider interface. This way theming engines may still attempt
288 * to style your UI elements in a different way if needed so.
291 * If you are using custom styling on an applications, you probably want then
292 * to make your style information prevail to the theme's, so you must use
293 * a #GtkStyleProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
294 * priority, keep in mind that the user settings in
295 * <filename><replaceable>XDG_CONFIG_HOME</replaceable>/gtk-3.0/gtk.css</filename> will
296 * still take precedence over your changes, as it uses the
297 * %GTK_STYLE_PROVIDER_PRIORITY_USER priority.
300 * If a custom theming engine is needed, you probably want to implement a
301 * #GtkStyleProvider yourself so it points to your #GtkThemingEngine
302 * implementation, as #GtkCssProvider uses gtk_theming_engine_load()
303 * which loads the theming engine module from the standard paths.
308 /* When these change we do a full restyling. Otherwise we try to figure out
309 * if we need to change things. */
310 #define GTK_STYLE_CONTEXT_RADICAL_CHANGE (GTK_CSS_CHANGE_NAME | GTK_CSS_CHANGE_CLASS | GTK_CSS_CHANGE_SOURCE)
311 /* When these change we don't clear the cache. This takes more memory but makes
312 * things go faster. */
313 #define GTK_STYLE_CONTEXT_CACHED_CHANGE (GTK_CSS_CHANGE_STATE)
315 typedef struct GtkStyleInfo GtkStyleInfo;
316 typedef struct GtkRegion GtkRegion;
317 typedef struct PropertyValue PropertyValue;
318 typedef struct StyleData StyleData;
323 GtkRegionFlags flags;
337 GArray *style_classes;
339 GtkJunctionSides junction_sides;
340 GtkStateFlags state_flags;
346 GtkCssComputedValues *store;
347 GArray *property_cache;
351 struct _GtkStyleContextPrivate
355 GtkStyleCascade *cascade;
357 GtkStyleContext *animation_list_prev;
358 GtkStyleContext *animation_list_next;
360 GtkStyleContext *parent;
363 GtkWidgetPath *widget_path;
364 GHashTable *style_data;
367 GtkTextDirection direction;
369 GtkCssChange relevant_changes;
370 GtkCssChange pending_changes;
372 guint invalidating_context : 1;
388 static guint signals[LAST_SIGNAL] = { 0 };
389 static GtkStyleContext *_running_animations = NULL;
390 guint _running_animations_timer_id = 0;
392 static void gtk_style_context_finalize (GObject *object);
394 static void gtk_style_context_impl_set_property (GObject *object,
398 static void gtk_style_context_impl_get_property (GObject *object,
402 static StyleData *style_data_lookup (GtkStyleContext *context);
405 G_DEFINE_TYPE (GtkStyleContext, gtk_style_context, G_TYPE_OBJECT)
408 gtk_style_context_real_changed (GtkStyleContext *context)
410 GtkStyleContextPrivate *priv = context->priv;
413 _gtk_widget_style_context_invalidated (priv->widget);
417 gtk_style_context_class_init (GtkStyleContextClass *klass)
419 GObjectClass *object_class = G_OBJECT_CLASS (klass);
421 object_class->finalize = gtk_style_context_finalize;
422 object_class->set_property = gtk_style_context_impl_set_property;
423 object_class->get_property = gtk_style_context_impl_get_property;
425 klass->changed = gtk_style_context_real_changed;
428 g_signal_new (I_("changed"),
429 G_TYPE_FROM_CLASS (object_class),
431 G_STRUCT_OFFSET (GtkStyleContextClass, changed),
433 g_cclosure_marshal_VOID__VOID,
436 g_object_class_install_property (object_class,
438 g_param_spec_object ("screen",
440 P_("The associated GdkScreen"),
442 GTK_PARAM_READWRITE));
443 g_object_class_install_property (object_class,
445 g_param_spec_enum ("direction",
447 P_("Text direction"),
448 GTK_TYPE_TEXT_DIRECTION,
450 GTK_PARAM_READWRITE));
452 * GtkStyleContext:parent:
454 * Sets or gets the style context's parent. See gtk_style_context_set_parent()
459 g_object_class_install_property (object_class,
461 g_param_spec_object ("parent",
463 P_("The parent style context"),
464 GTK_TYPE_STYLE_CONTEXT,
465 GTK_PARAM_READWRITE));
467 g_type_class_add_private (object_class, sizeof (GtkStyleContextPrivate));
471 style_data_new (void)
475 data = g_slice_new0 (StyleData);
482 clear_property_cache (StyleData *data)
486 if (!data->property_cache)
489 for (i = 0; i < data->property_cache->len; i++)
491 PropertyValue *node = &g_array_index (data->property_cache, PropertyValue, i);
493 g_param_spec_unref (node->pspec);
494 g_value_unset (&node->value);
497 g_array_free (data->property_cache, TRUE);
498 data->property_cache = NULL;
502 style_data_ref (StyleData *style_data)
504 style_data->ref_count++;
510 style_data_unref (StyleData *data)
514 if (data->ref_count > 0)
517 g_object_unref (data->store);
518 clear_property_cache (data);
520 g_slice_free (StyleData, data);
524 style_data_is_animating (StyleData *style_data)
526 return !_gtk_css_computed_values_is_static (style_data->store);
529 static GtkStyleInfo *
530 style_info_new (void)
534 info = g_slice_new0 (GtkStyleInfo);
535 info->style_classes = g_array_new (FALSE, FALSE, sizeof (GQuark));
536 info->regions = g_array_new (FALSE, FALSE, sizeof (GtkRegion));
542 style_info_set_data (GtkStyleInfo *info,
545 if (info->data == data)
549 style_data_ref (data);
552 style_data_unref (info->data);
558 style_info_free (GtkStyleInfo *info)
560 style_info_set_data (info, NULL);
561 g_array_free (info->style_classes, TRUE);
562 g_array_free (info->regions, TRUE);
563 g_slice_free (GtkStyleInfo, info);
566 static GtkStyleInfo *
567 style_info_pop (GtkStyleInfo *info)
569 GtkStyleInfo *next = info->next;
571 style_info_free (info);
576 static GtkStyleInfo *
577 style_info_copy (GtkStyleInfo *info)
581 copy = style_info_new ();
582 g_array_insert_vals (copy->style_classes, 0,
583 info->style_classes->data,
584 info->style_classes->len);
586 g_array_insert_vals (copy->regions, 0,
591 copy->junction_sides = info->junction_sides;
592 copy->state_flags = info->state_flags;
593 style_info_set_data (copy, info->data);
599 style_info_hash (gconstpointer elem)
601 const GtkStyleInfo *info;
606 for (i = 0; i < info->style_classes->len; i++)
608 hash += g_array_index (info->style_classes, GQuark, i);
612 for (i = 0; i < info->regions->len; i++)
616 region = &g_array_index (info->regions, GtkRegion, i);
617 hash += region->class_quark;
618 hash += region->flags;
622 return hash ^ info->state_flags;
626 style_info_equal (gconstpointer elem1,
629 const GtkStyleInfo *info1, *info2;
634 if (info1->state_flags != info2->state_flags)
637 if (info1->junction_sides != info2->junction_sides)
640 if (info1->style_classes->len != info2->style_classes->len)
643 if (memcmp (info1->style_classes->data,
644 info2->style_classes->data,
645 info1->style_classes->len * sizeof (GQuark)) != 0)
648 if (info1->regions->len != info2->regions->len)
651 if (memcmp (info1->regions->data,
652 info2->regions->data,
653 info1->regions->len * sizeof (GtkRegion)) != 0)
660 gtk_style_context_cascade_changed (GtkStyleCascade *cascade,
661 GtkStyleContext *context)
663 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_SOURCE);
667 gtk_style_context_set_cascade (GtkStyleContext *context,
668 GtkStyleCascade *cascade)
670 GtkStyleContextPrivate *priv;
672 priv = context->priv;
674 if (priv->cascade == cascade)
679 g_object_ref (cascade);
680 g_signal_connect (cascade,
681 "-gtk-private-changed",
682 G_CALLBACK (gtk_style_context_cascade_changed),
688 g_signal_handlers_disconnect_by_func (priv->cascade,
689 gtk_style_context_cascade_changed,
691 g_object_unref (priv->cascade);
694 priv->cascade = cascade;
697 gtk_style_context_cascade_changed (cascade, context);
700 GtkStyleProviderPrivate *
701 _gtk_style_context_get_style_provider (GtkStyleContext *context)
703 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
705 return GTK_STYLE_PROVIDER_PRIVATE (context->priv->cascade);
709 gtk_style_context_init (GtkStyleContext *style_context)
711 GtkStyleContextPrivate *priv;
713 priv = style_context->priv = G_TYPE_INSTANCE_GET_PRIVATE (style_context,
714 GTK_TYPE_STYLE_CONTEXT,
715 GtkStyleContextPrivate);
717 priv->style_data = g_hash_table_new_full (style_info_hash,
719 (GDestroyNotify) style_info_free,
720 (GDestroyNotify) style_data_unref);
722 priv->direction = GTK_TEXT_DIR_LTR;
724 priv->screen = gdk_screen_get_default ();
725 priv->relevant_changes = GTK_CSS_CHANGE_ANY;
727 /* Create default info store */
728 priv->info = style_info_new ();
730 gtk_style_context_set_cascade (style_context,
731 _gtk_style_cascade_get_for_screen (priv->screen));
735 gtk_style_context_do_animations (gpointer unused)
737 GtkStyleContext *context;
739 for (context = _running_animations;
741 context = context->priv->animation_list_next)
743 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANIMATE);
750 gtk_style_context_is_animating (GtkStyleContext *context)
752 GtkStyleContextPrivate *priv = context->priv;
754 return priv->animation_list_prev != NULL
755 || _running_animations == context;
759 gtk_style_context_stop_animating (GtkStyleContext *context)
761 GtkStyleContextPrivate *priv = context->priv;
763 if (!gtk_style_context_is_animating (context))
766 if (priv->animation_list_prev == NULL)
768 _running_animations = priv->animation_list_next;
770 if (_running_animations == NULL)
772 /* we were the last animation */
773 g_source_remove (_running_animations_timer_id);
774 _running_animations_timer_id = 0;
778 priv->animation_list_prev->priv->animation_list_next = priv->animation_list_next;
780 if (priv->animation_list_next)
781 priv->animation_list_next->priv->animation_list_prev = priv->animation_list_prev;
783 priv->animation_list_next = NULL;
784 priv->animation_list_prev = NULL;
788 gtk_style_context_start_animating (GtkStyleContext *context)
790 GtkStyleContextPrivate *priv = context->priv;
792 if (gtk_style_context_is_animating (context))
795 if (_running_animations == NULL)
797 _running_animations_timer_id = gdk_threads_add_timeout (25,
798 gtk_style_context_do_animations,
800 _running_animations = context;
804 priv->animation_list_next = _running_animations;
805 _running_animations->priv->animation_list_prev = context;
806 _running_animations = context;
811 gtk_style_context_should_animate (GtkStyleContext *context)
813 GtkStyleContextPrivate *priv;
817 priv = context->priv;
819 if (priv->widget == NULL)
822 if (!gtk_widget_get_mapped (priv->widget))
825 data = style_data_lookup (context);
826 if (!style_data_is_animating (data))
829 g_object_get (gtk_widget_get_settings (context->priv->widget),
830 "gtk-enable-animations", &animate,
837 _gtk_style_context_update_animating (GtkStyleContext *context)
839 if (gtk_style_context_should_animate (context))
840 gtk_style_context_start_animating (context);
842 gtk_style_context_stop_animating (context);
846 gtk_style_context_finalize (GObject *object)
848 GtkStyleContextPrivate *priv;
849 GtkStyleContext *style_context;
851 style_context = GTK_STYLE_CONTEXT (object);
852 priv = style_context->priv;
854 gtk_style_context_stop_animating (style_context);
856 /* children hold a reference to us */
857 g_assert (priv->children == NULL);
859 gtk_style_context_set_parent (style_context, NULL);
861 gtk_style_context_set_cascade (style_context, NULL);
863 if (priv->widget_path)
864 gtk_widget_path_free (priv->widget_path);
866 g_hash_table_destroy (priv->style_data);
869 priv->info = style_info_pop (priv->info);
871 G_OBJECT_CLASS (gtk_style_context_parent_class)->finalize (object);
875 gtk_style_context_impl_set_property (GObject *object,
880 GtkStyleContext *style_context;
882 style_context = GTK_STYLE_CONTEXT (object);
887 gtk_style_context_set_screen (style_context,
888 g_value_get_object (value));
891 gtk_style_context_set_direction (style_context,
892 g_value_get_enum (value));
895 gtk_style_context_set_parent (style_context,
896 g_value_get_object (value));
899 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
905 gtk_style_context_impl_get_property (GObject *object,
910 GtkStyleContext *style_context;
911 GtkStyleContextPrivate *priv;
913 style_context = GTK_STYLE_CONTEXT (object);
914 priv = style_context->priv;
919 g_value_set_object (value, priv->screen);
922 g_value_set_enum (value, priv->direction);
925 g_value_set_object (value, priv->parent);
928 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
933 static GtkWidgetPath *
934 create_query_path (GtkStyleContext *context,
937 GtkStyleContextPrivate *priv;
941 priv = context->priv;
942 path = priv->widget ? _gtk_widget_create_path (priv->widget) : gtk_widget_path_copy (priv->widget_path);
943 pos = gtk_widget_path_length (path) - 1;
945 /* Set widget regions */
946 for (i = 0; i < info->regions->len; i++)
950 region = &g_array_index (info->regions, GtkRegion, i);
951 gtk_widget_path_iter_add_region (path, pos,
952 g_quark_to_string (region->class_quark),
956 /* Set widget classes */
957 for (i = 0; i < info->style_classes->len; i++)
961 quark = g_array_index (info->style_classes, GQuark, i);
962 gtk_widget_path_iter_add_class (path, pos,
963 g_quark_to_string (quark));
970 build_properties (GtkStyleContext *context,
971 GtkCssComputedValues *values,
973 const GtkBitmask *relevant_changes)
975 GtkStyleContextPrivate *priv;
976 GtkCssMatcher matcher;
978 GtkCssLookup *lookup;
980 priv = context->priv;
982 path = create_query_path (context, info);
983 lookup = _gtk_css_lookup_new (relevant_changes);
985 if (_gtk_css_matcher_init (&matcher, path, info->state_flags))
986 _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
990 _gtk_css_lookup_resolve (lookup, context, values);
992 _gtk_css_lookup_free (lookup);
993 gtk_widget_path_free (path);
997 style_data_lookup (GtkStyleContext *context)
999 GtkStyleContextPrivate *priv;
1003 priv = context->priv;
1006 /* Current data in use is cached, just return it */
1010 g_assert (priv->widget != NULL || priv->widget_path != NULL);
1012 data = g_hash_table_lookup (priv->style_data, info);
1015 style_info_set_data (info, data);
1019 data = style_data_new ();
1020 data->store = _gtk_css_computed_values_new ();
1021 style_info_set_data (info, data);
1022 g_hash_table_insert (priv->style_data,
1023 style_info_copy (info),
1026 build_properties (context, data->store, info, NULL);
1032 style_data_lookup_for_state (GtkStyleContext *context,
1033 GtkStateFlags state)
1037 if (context->priv->info->state_flags == state)
1038 return style_data_lookup (context);
1040 gtk_style_context_save (context);
1041 gtk_style_context_set_state (context, state);
1042 data = style_data_lookup (context);
1043 gtk_style_context_restore (context);
1049 gtk_style_context_set_invalid (GtkStyleContext *context,
1052 GtkStyleContextPrivate *priv;
1054 priv = context->priv;
1056 if (priv->invalid == invalid)
1059 priv->invalid = invalid;
1064 gtk_style_context_set_invalid (priv->parent, TRUE);
1065 else if (GTK_IS_RESIZE_CONTAINER (priv->widget))
1066 _gtk_container_queue_restyle (GTK_CONTAINER (priv->widget));
1070 /* returns TRUE if someone called gtk_style_context_save() but hasn't
1071 * called gtk_style_context_restore() yet.
1072 * In those situations we don't invalidate the context when somebody
1073 * changes state/regions/classes.
1076 gtk_style_context_is_saved (GtkStyleContext *context)
1078 return context->priv->info->next != NULL;
1082 gtk_style_context_queue_invalidate_internal (GtkStyleContext *context,
1083 GtkCssChange change)
1085 GtkStyleContextPrivate *priv = context->priv;
1086 GtkStyleInfo *info = priv->info;
1088 if (gtk_style_context_is_saved (context))
1090 style_info_set_data (info, NULL);
1094 _gtk_style_context_queue_invalidate (context, change);
1095 /* XXX: We need to invalidate siblings here somehow */
1100 * gtk_style_context_new:
1102 * Creates a standalone #GtkStyleContext, this style context
1103 * won't be attached to any widget, so you may want
1104 * to call gtk_style_context_set_path() yourself.
1107 * This function is only useful when using the theming layer
1108 * separated from GTK+, if you are using #GtkStyleContext to
1109 * theme #GtkWidget<!-- -->s, use gtk_widget_get_style_context()
1110 * in order to get a style context ready to theme the widget.
1113 * Returns: A newly created #GtkStyleContext.
1116 gtk_style_context_new (void)
1118 return g_object_new (GTK_TYPE_STYLE_CONTEXT, NULL);
1122 _gtk_style_context_set_widget (GtkStyleContext *context,
1125 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1126 g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget));
1128 context->priv->widget = widget;
1130 _gtk_style_context_update_animating (context);
1132 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY_SELF);
1136 * gtk_style_context_add_provider:
1137 * @context: a #GtkStyleContext
1138 * @provider: a #GtkStyleProvider
1139 * @priority: the priority of the style provider. The lower
1140 * it is, the earlier it will be used in the style
1141 * construction. Typically this will be in the range
1142 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1143 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1145 * Adds a style provider to @context, to be used in style construction.
1146 * Note that a style provider added by this function only affects
1147 * the style of the widget to which @context belongs. If you want
1148 * to affect the style of all widgets, use
1149 * gtk_style_context_add_provider_for_screen().
1151 * <note><para>If both priorities are the same, A #GtkStyleProvider
1152 * added through this function takes precedence over another added
1153 * through gtk_style_context_add_provider_for_screen().</para></note>
1158 gtk_style_context_add_provider (GtkStyleContext *context,
1159 GtkStyleProvider *provider,
1162 GtkStyleContextPrivate *priv;
1164 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1165 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1167 priv = context->priv;
1169 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
1171 GtkStyleCascade *new_cascade;
1173 new_cascade = _gtk_style_cascade_new ();
1174 _gtk_style_cascade_set_parent (new_cascade, priv->cascade);
1175 _gtk_style_cascade_add_provider (new_cascade, provider, priority);
1176 gtk_style_context_set_cascade (context, new_cascade);
1177 g_object_unref (new_cascade);
1181 _gtk_style_cascade_add_provider (priv->cascade, provider, priority);
1186 * gtk_style_context_remove_provider:
1187 * @context: a #GtkStyleContext
1188 * @provider: a #GtkStyleProvider
1190 * Removes @provider from the style providers list in @context.
1195 gtk_style_context_remove_provider (GtkStyleContext *context,
1196 GtkStyleProvider *provider)
1198 GtkStyleContextPrivate *priv;
1200 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1201 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1203 priv = context->priv;
1205 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
1208 _gtk_style_cascade_remove_provider (priv->cascade, provider);
1212 * gtk_style_context_reset_widgets:
1213 * @screen: a #GdkScreen
1215 * This function recomputes the styles for all widgets under a particular
1216 * #GdkScreen. This is useful when some global parameter has changed that
1217 * affects the appearance of all widgets, because when a widget gets a new
1218 * style, it will both redraw and recompute any cached information about
1219 * its appearance. As an example, it is used when the color scheme changes
1220 * in the related #GtkSettings object.
1225 gtk_style_context_reset_widgets (GdkScreen *screen)
1227 GList *list, *toplevels;
1229 _gtk_icon_set_invalidate_caches ();
1231 toplevels = gtk_window_list_toplevels ();
1232 g_list_foreach (toplevels, (GFunc) g_object_ref, NULL);
1234 for (list = toplevels; list; list = list->next)
1236 if (gtk_widget_get_screen (list->data) == screen)
1237 gtk_widget_reset_style (list->data);
1239 g_object_unref (list->data);
1242 g_list_free (toplevels);
1246 * gtk_style_context_add_provider_for_screen:
1247 * @screen: a #GdkScreen
1248 * @provider: a #GtkStyleProvider
1249 * @priority: the priority of the style provider. The lower
1250 * it is, the earlier it will be used in the style
1251 * construction. Typically this will be in the range
1252 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1253 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1255 * Adds a global style provider to @screen, which will be used
1256 * in style construction for all #GtkStyleContexts under @screen.
1258 * GTK+ uses this to make styling information from #GtkSettings
1261 * <note><para>If both priorities are the same, A #GtkStyleProvider
1262 * added through gtk_style_context_add_provider() takes precedence
1263 * over another added through this function.</para></note>
1268 gtk_style_context_add_provider_for_screen (GdkScreen *screen,
1269 GtkStyleProvider *provider,
1272 GtkStyleCascade *cascade;
1274 g_return_if_fail (GDK_IS_SCREEN (screen));
1275 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1276 g_return_if_fail (!GTK_IS_SETTINGS (provider) || _gtk_settings_get_screen (GTK_SETTINGS (provider)) == screen);
1278 cascade = _gtk_style_cascade_get_for_screen (screen);
1279 _gtk_style_cascade_add_provider (cascade, provider, priority);
1283 * gtk_style_context_remove_provider_for_screen:
1284 * @screen: a #GdkScreen
1285 * @provider: a #GtkStyleProvider
1287 * Removes @provider from the global style providers list in @screen.
1292 gtk_style_context_remove_provider_for_screen (GdkScreen *screen,
1293 GtkStyleProvider *provider)
1295 GtkStyleCascade *cascade;
1297 g_return_if_fail (GDK_IS_SCREEN (screen));
1298 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1299 g_return_if_fail (!GTK_IS_SETTINGS (provider));
1301 cascade = _gtk_style_cascade_get_for_screen (screen);
1302 _gtk_style_cascade_remove_provider (cascade, provider);
1306 * gtk_style_context_get_section:
1307 * @context: a #GtkStyleContext
1308 * @property: style property name
1310 * Queries the location in the CSS where @property was defined for the
1311 * current @context. Note that the state to be queried is taken from
1312 * gtk_style_context_get_state().
1314 * If the location is not available, %NULL will be returned. The
1315 * location might not be available for various reasons, such as the
1316 * property being overridden, @property not naming a supported CSS
1317 * property or tracking of definitions being disabled for performance
1320 * Shorthand CSS properties cannot be queried for a location and will
1321 * always return %NULL.
1323 * Returns: %NULL or the section where value was defined
1326 gtk_style_context_get_section (GtkStyleContext *context,
1327 const gchar *property)
1329 GtkStyleContextPrivate *priv;
1330 GtkStyleProperty *prop;
1333 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1334 g_return_val_if_fail (property != NULL, NULL);
1336 priv = context->priv;
1337 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
1339 prop = _gtk_style_property_lookup (property);
1340 if (!GTK_IS_CSS_STYLE_PROPERTY (prop))
1343 data = style_data_lookup (context);
1344 return _gtk_css_computed_values_get_section (data->store, _gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (prop)));
1347 static GtkCssValue *
1348 gtk_style_context_query_func (guint id,
1351 return _gtk_css_computed_values_get_value (values, id);
1355 * gtk_style_context_get_property:
1356 * @context: a #GtkStyleContext
1357 * @property: style property name
1358 * @state: state to retrieve the property value for
1359 * @value: (out) (transfer full): return location for the style property value
1361 * Gets a style property from @context for the given state.
1363 * When @value is no longer needed, g_value_unset() must be called
1364 * to free any allocated memory.
1369 gtk_style_context_get_property (GtkStyleContext *context,
1370 const gchar *property,
1371 GtkStateFlags state,
1374 GtkStyleContextPrivate *priv;
1375 GtkStyleProperty *prop;
1378 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1379 g_return_if_fail (property != NULL);
1380 g_return_if_fail (value != NULL);
1382 priv = context->priv;
1383 g_return_if_fail (priv->widget != NULL || priv->widget_path != NULL);
1385 prop = _gtk_style_property_lookup (property);
1388 g_warning ("Style property \"%s\" is not registered", property);
1391 if (_gtk_style_property_get_value_type (prop) == G_TYPE_NONE)
1393 g_warning ("Style property \"%s\" is not gettable", property);
1397 data = style_data_lookup_for_state (context, state);
1398 _gtk_style_property_query (prop, value, gtk_style_context_query_func, data->store);
1402 * gtk_style_context_get_valist:
1403 * @context: a #GtkStyleContext
1404 * @state: state to retrieve the property values for
1405 * @args: va_list of property name/return location pairs, followed by %NULL
1407 * Retrieves several style property values from @context for a given state.
1412 gtk_style_context_get_valist (GtkStyleContext *context,
1413 GtkStateFlags state,
1416 const gchar *property_name;
1418 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1420 property_name = va_arg (args, const gchar *);
1422 while (property_name)
1424 gchar *error = NULL;
1425 GValue value = G_VALUE_INIT;
1427 gtk_style_context_get_property (context,
1432 G_VALUE_LCOPY (&value, args, 0, &error);
1433 g_value_unset (&value);
1437 g_warning ("Could not get style property \"%s\": %s", property_name, error);
1442 property_name = va_arg (args, const gchar *);
1447 * gtk_style_context_get:
1448 * @context: a #GtkStyleContext
1449 * @state: state to retrieve the property values for
1450 * @...: property name /return value pairs, followed by %NULL
1452 * Retrieves several style property values from @context for a
1458 gtk_style_context_get (GtkStyleContext *context,
1459 GtkStateFlags state,
1464 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1466 va_start (args, state);
1467 gtk_style_context_get_valist (context, state, args);
1472 * gtk_style_context_set_state:
1473 * @context: a #GtkStyleContext
1474 * @flags: state to represent
1476 * Sets the state to be used when rendering with any
1477 * of the gtk_render_*() functions.
1482 gtk_style_context_set_state (GtkStyleContext *context,
1483 GtkStateFlags flags)
1485 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1487 context->priv->info->state_flags = flags;
1489 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_STATE);
1493 * gtk_style_context_get_state:
1494 * @context: a #GtkStyleContext
1496 * Returns the state used when rendering.
1498 * Returns: the state flags
1503 gtk_style_context_get_state (GtkStyleContext *context)
1505 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
1507 return context->priv->info->state_flags;
1511 * gtk_style_context_state_is_running:
1512 * @context: a #GtkStyleContext
1513 * @state: a widget state
1514 * @progress: (out): return location for the transition progress
1516 * Returns %TRUE if there is a transition animation running for the
1517 * current region (see gtk_style_context_push_animatable_region()).
1519 * If @progress is not %NULL, the animation progress will be returned
1520 * there, 0.0 means the state is closest to being unset, while 1.0 means
1521 * it's closest to being set. This means transition animation will
1522 * run from 0 to 1 when @state is being set and from 1 to 0 when
1525 * Returns: %TRUE if there is a running transition animation for @state.
1529 * Deprecated: 3.6: This function always returns %FALSE
1532 gtk_style_context_state_is_running (GtkStyleContext *context,
1536 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1542 * gtk_style_context_set_path:
1543 * @context: a #GtkStyleContext
1544 * @path: a #GtkWidgetPath
1546 * Sets the #GtkWidgetPath used for style matching. As a
1547 * consequence, the style will be regenerated to match
1548 * the new given path.
1550 * If you are using a #GtkStyleContext returned from
1551 * gtk_widget_get_style_context(), you do not need to call
1557 gtk_style_context_set_path (GtkStyleContext *context,
1558 GtkWidgetPath *path)
1560 GtkStyleContextPrivate *priv;
1562 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1563 g_return_if_fail (path != NULL);
1565 priv = context->priv;
1566 g_return_if_fail (priv->widget == NULL);
1568 if (priv->widget_path)
1570 gtk_widget_path_free (priv->widget_path);
1571 priv->widget_path = NULL;
1575 priv->widget_path = gtk_widget_path_copy (path);
1577 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY);
1581 * gtk_style_context_get_path:
1582 * @context: a #GtkStyleContext
1584 * Returns the widget path used for style matching.
1586 * Returns: (transfer none): A #GtkWidgetPath
1590 const GtkWidgetPath *
1591 gtk_style_context_get_path (GtkStyleContext *context)
1593 GtkStyleContextPrivate *priv;
1595 priv = context->priv;
1597 return gtk_widget_get_path (priv->widget);
1599 return priv->widget_path;
1603 * gtk_style_context_set_parent:
1604 * @context: a #GtkStyleContext
1605 * @parent: (allow-none): the new parent or %NULL
1607 * Sets the parent style context for @context. The parent style
1608 * context is used to implement
1609 * <ulink url="http://www.w3.org/TR/css3-cascade/#inheritance">inheritance</ulink>
1612 * If you are using a #GtkStyleContext returned from
1613 * gtk_widget_get_style_context(), the parent will be set for you.
1618 gtk_style_context_set_parent (GtkStyleContext *context,
1619 GtkStyleContext *parent)
1621 GtkStyleContextPrivate *priv;
1623 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1624 g_return_if_fail (parent == NULL || GTK_IS_STYLE_CONTEXT (parent));
1626 priv = context->priv;
1628 if (priv->parent == parent)
1633 parent->priv->children = g_slist_prepend (parent->priv->children, context);
1634 g_object_ref (parent);
1636 gtk_style_context_set_invalid (parent, TRUE);
1641 priv->parent->priv->children = g_slist_remove (priv->parent->priv->children, context);
1642 g_object_unref (priv->parent);
1645 priv->parent = parent;
1647 g_object_notify (G_OBJECT (context), "parent");
1648 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY_PARENT | GTK_CSS_CHANGE_ANY_SIBLING);
1652 * gtk_style_context_get_parent:
1653 * @context: a #GtkStyleContext
1655 * Gets the parent context set via gtk_style_context_set_parent().
1656 * See that function for details.
1658 * Returns: (transfer none): the parent context or %NULL
1663 gtk_style_context_get_parent (GtkStyleContext *context)
1665 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1667 return context->priv->parent;
1671 * gtk_style_context_save:
1672 * @context: a #GtkStyleContext
1674 * Saves the @context state, so all modifications done through
1675 * gtk_style_context_add_class(), gtk_style_context_remove_class(),
1676 * gtk_style_context_add_region(), gtk_style_context_remove_region()
1677 * or gtk_style_context_set_junction_sides() can be reverted in one
1678 * go through gtk_style_context_restore().
1683 gtk_style_context_save (GtkStyleContext *context)
1685 GtkStyleContextPrivate *priv;
1687 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1689 priv = context->priv;
1691 priv->info = style_info_copy (priv->info);
1692 /* Need to unset animations here because we can not know what style
1693 * class potential transitions came from once we save().
1695 if (priv->info->data && style_data_is_animating (priv->info->data))
1696 style_info_set_data (priv->info, NULL);
1700 * gtk_style_context_restore:
1701 * @context: a #GtkStyleContext
1703 * Restores @context state to a previous stage.
1704 * See gtk_style_context_save().
1709 gtk_style_context_restore (GtkStyleContext *context)
1711 GtkStyleContextPrivate *priv;
1713 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1715 priv = context->priv;
1717 priv->info = style_info_pop (priv->info);
1721 g_warning ("Unpaired gtk_style_context_restore() call");
1723 /* Create default region */
1724 priv->info = style_info_new ();
1729 style_class_find (GArray *array,
1734 gboolean found = FALSE;
1740 if (!array || array->len == 0)
1744 max = array->len - 1;
1750 mid = (min + max) / 2;
1751 item = g_array_index (array, GQuark, mid);
1753 if (class_quark == item)
1758 else if (class_quark > item)
1759 min = pos = mid + 1;
1766 while (!found && min <= max);
1775 region_find (GArray *array,
1780 gboolean found = FALSE;
1786 if (!array || array->len == 0)
1790 max = array->len - 1;
1796 mid = (min + max) / 2;
1797 region = &g_array_index (array, GtkRegion, mid);
1799 if (region->class_quark == class_quark)
1804 else if (region->class_quark > class_quark)
1805 min = pos = mid + 1;
1812 while (!found && min <= max);
1821 * gtk_style_context_add_class:
1822 * @context: a #GtkStyleContext
1823 * @class_name: class name to use in styling
1825 * Adds a style class to @context, so posterior calls to
1826 * gtk_style_context_get() or any of the gtk_render_*()
1827 * functions will make use of this new class for styling.
1829 * In the CSS file format, a #GtkEntry defining an "entry"
1830 * class, would be matched by:
1833 * GtkEntry.entry { ... }
1836 * While any widget defining an "entry" class would be
1845 gtk_style_context_add_class (GtkStyleContext *context,
1846 const gchar *class_name)
1848 GtkStyleContextPrivate *priv;
1853 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1854 g_return_if_fail (class_name != NULL);
1856 priv = context->priv;
1857 class_quark = g_quark_from_string (class_name);
1861 if (!style_class_find (info->style_classes, class_quark, &position))
1863 g_array_insert_val (info->style_classes, position, class_quark);
1865 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_CLASS);
1870 * gtk_style_context_remove_class:
1871 * @context: a #GtkStyleContext
1872 * @class_name: class name to remove
1874 * Removes @class_name from @context.
1879 gtk_style_context_remove_class (GtkStyleContext *context,
1880 const gchar *class_name)
1882 GtkStyleContextPrivate *priv;
1887 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1888 g_return_if_fail (class_name != NULL);
1890 class_quark = g_quark_try_string (class_name);
1895 priv = context->priv;
1899 if (style_class_find (info->style_classes, class_quark, &position))
1901 g_array_remove_index (info->style_classes, position);
1903 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_CLASS);
1908 * gtk_style_context_has_class:
1909 * @context: a #GtkStyleContext
1910 * @class_name: a class name
1912 * Returns %TRUE if @context currently has defined the
1915 * Returns: %TRUE if @context has @class_name defined
1920 gtk_style_context_has_class (GtkStyleContext *context,
1921 const gchar *class_name)
1923 GtkStyleContextPrivate *priv;
1927 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1928 g_return_val_if_fail (class_name != NULL, FALSE);
1930 class_quark = g_quark_try_string (class_name);
1935 priv = context->priv;
1939 if (style_class_find (info->style_classes, class_quark, NULL))
1946 * gtk_style_context_list_classes:
1947 * @context: a #GtkStyleContext
1949 * Returns the list of classes currently defined in @context.
1951 * Returns: (transfer container) (element-type utf8): a #GList of
1952 * strings with the currently defined classes. The contents
1953 * of the list are owned by GTK+, but you must free the list
1954 * itself with g_list_free() when you are done with it.
1959 gtk_style_context_list_classes (GtkStyleContext *context)
1961 GtkStyleContextPrivate *priv;
1963 GList *classes = NULL;
1966 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1968 priv = context->priv;
1972 for (i = 0; i < info->style_classes->len; i++)
1976 quark = g_array_index (info->style_classes, GQuark, i);
1977 classes = g_list_prepend (classes, (gchar *) g_quark_to_string (quark));
1984 * gtk_style_context_list_regions:
1985 * @context: a #GtkStyleContext
1987 * Returns the list of regions currently defined in @context.
1989 * Returns: (transfer container) (element-type utf8): a #GList of
1990 * strings with the currently defined regions. The contents
1991 * of the list are owned by GTK+, but you must free the list
1992 * itself with g_list_free() when you are done with it.
1997 gtk_style_context_list_regions (GtkStyleContext *context)
1999 GtkStyleContextPrivate *priv;
2001 GList *classes = NULL;
2004 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2006 priv = context->priv;
2010 for (i = 0; i < info->regions->len; i++)
2013 const gchar *class_name;
2015 region = &g_array_index (info->regions, GtkRegion, i);
2017 class_name = g_quark_to_string (region->class_quark);
2018 classes = g_list_prepend (classes, (gchar *) class_name);
2025 _gtk_style_context_check_region_name (const gchar *str)
2027 g_return_val_if_fail (str != NULL, FALSE);
2029 if (!g_ascii_islower (str[0]))
2035 !g_ascii_islower (*str))
2045 * gtk_style_context_add_region:
2046 * @context: a #GtkStyleContext
2047 * @region_name: region name to use in styling
2048 * @flags: flags that apply to the region
2050 * Adds a region to @context, so posterior calls to
2051 * gtk_style_context_get() or any of the gtk_render_*()
2052 * functions will make use of this new region for styling.
2054 * In the CSS file format, a #GtkTreeView defining a "row"
2055 * region, would be matched by:
2058 * GtkTreeView row { ... }
2061 * Pseudo-classes are used for matching @flags, so the two
2064 * GtkTreeView row:nth-child(even) { ... }
2065 * GtkTreeView row:nth-child(odd) { ... }
2068 * would apply to even and odd rows, respectively.
2070 * <note><para>Region names must only contain lowercase letters
2071 * and '-', starting always with a lowercase letter.</para></note>
2076 gtk_style_context_add_region (GtkStyleContext *context,
2077 const gchar *region_name,
2078 GtkRegionFlags flags)
2080 GtkStyleContextPrivate *priv;
2082 GQuark region_quark;
2085 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2086 g_return_if_fail (region_name != NULL);
2087 g_return_if_fail (_gtk_style_context_check_region_name (region_name));
2089 priv = context->priv;
2090 region_quark = g_quark_from_string (region_name);
2094 if (!region_find (info->regions, region_quark, &position))
2098 region.class_quark = region_quark;
2099 region.flags = flags;
2101 g_array_insert_val (info->regions, position, region);
2103 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_REGION);
2108 * gtk_style_context_remove_region:
2109 * @context: a #GtkStyleContext
2110 * @region_name: region name to unset
2112 * Removes a region from @context.
2117 gtk_style_context_remove_region (GtkStyleContext *context,
2118 const gchar *region_name)
2120 GtkStyleContextPrivate *priv;
2122 GQuark region_quark;
2125 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2126 g_return_if_fail (region_name != NULL);
2128 region_quark = g_quark_try_string (region_name);
2133 priv = context->priv;
2137 if (region_find (info->regions, region_quark, &position))
2139 g_array_remove_index (info->regions, position);
2141 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_REGION);
2146 * gtk_style_context_has_region:
2147 * @context: a #GtkStyleContext
2148 * @region_name: a region name
2149 * @flags_return: (out) (allow-none): return location for region flags
2151 * Returns %TRUE if @context has the region defined.
2152 * If @flags_return is not %NULL, it is set to the flags
2153 * affecting the region.
2155 * Returns: %TRUE if region is defined
2160 gtk_style_context_has_region (GtkStyleContext *context,
2161 const gchar *region_name,
2162 GtkRegionFlags *flags_return)
2164 GtkStyleContextPrivate *priv;
2166 GQuark region_quark;
2169 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2170 g_return_val_if_fail (region_name != NULL, FALSE);
2175 region_quark = g_quark_try_string (region_name);
2180 priv = context->priv;
2184 if (region_find (info->regions, region_quark, &position))
2190 region = &g_array_index (info->regions, GtkRegion, position);
2191 *flags_return = region->flags;
2200 style_property_values_cmp (gconstpointer bsearch_node1,
2201 gconstpointer bsearch_node2)
2203 const PropertyValue *val1 = bsearch_node1;
2204 const PropertyValue *val2 = bsearch_node2;
2206 if (val1->widget_type != val2->widget_type)
2207 return val1->widget_type < val2->widget_type ? -1 : 1;
2209 if (val1->pspec != val2->pspec)
2210 return val1->pspec < val2->pspec ? -1 : 1;
2212 if (val1->state != val2->state)
2213 return val1->state < val2->state ? -1 : 1;
2219 _gtk_style_context_peek_property (GtkStyleContext *context,
2222 StyleData *data = style_data_lookup (context);
2224 return _gtk_css_computed_values_get_value (data->store, property_id);
2228 _gtk_style_context_get_number (GtkStyleContext *context,
2230 double one_hundred_percent)
2234 value = _gtk_style_context_peek_property (context, property_id);
2235 return _gtk_css_number_value_get (value, one_hundred_percent);
2239 _gtk_style_context_peek_style_property (GtkStyleContext *context,
2241 GtkStateFlags state,
2244 GtkStyleContextPrivate *priv;
2245 PropertyValue *pcache, key = { 0 };
2249 priv = context->priv;
2251 data = style_data_lookup_for_state (context, state);
2253 key.widget_type = widget_type;
2257 /* need value cache array */
2258 if (!data->property_cache)
2259 data->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
2262 pcache = bsearch (&key,
2263 data->property_cache->data, data->property_cache->len,
2264 sizeof (PropertyValue), style_property_values_cmp);
2266 return &pcache->value;
2270 while (i < data->property_cache->len &&
2271 style_property_values_cmp (&key, &g_array_index (data->property_cache, PropertyValue, i)) >= 0)
2274 g_array_insert_val (data->property_cache, i, key);
2275 pcache = &g_array_index (data->property_cache, PropertyValue, i);
2277 /* cache miss, initialize value type, then set contents */
2278 g_param_spec_ref (pcache->pspec);
2279 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2281 if (priv->widget || priv->widget_path)
2283 GtkWidgetPath *widget_path = priv->widget ? _gtk_widget_create_path (priv->widget) : priv->widget_path;
2285 if (gtk_style_provider_get_style_property (GTK_STYLE_PROVIDER (priv->cascade),
2287 state, pspec, &pcache->value))
2289 /* Resolve symbolic colors to GdkColor/GdkRGBA */
2290 if (G_VALUE_TYPE (&pcache->value) == GTK_TYPE_SYMBOLIC_COLOR)
2292 GtkSymbolicColor *color;
2295 color = g_value_dup_boxed (&pcache->value);
2297 g_value_unset (&pcache->value);
2299 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2300 g_value_init (&pcache->value, GDK_TYPE_RGBA);
2302 g_value_init (&pcache->value, GDK_TYPE_COLOR);
2304 if (_gtk_style_context_resolve_color (context, color, &rgba, NULL))
2306 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2307 g_value_set_boxed (&pcache->value, &rgba);
2312 rgb.red = rgba.red * 65535. + 0.5;
2313 rgb.green = rgba.green * 65535. + 0.5;
2314 rgb.blue = rgba.blue * 65535. + 0.5;
2316 g_value_set_boxed (&pcache->value, &rgb);
2320 g_param_value_set_default (pspec, &pcache->value);
2322 gtk_symbolic_color_unref (color);
2326 gtk_widget_path_free (widget_path);
2328 return &pcache->value;
2332 gtk_widget_path_free (widget_path);
2335 /* not supplied by any provider, revert to default */
2336 g_param_value_set_default (pspec, &pcache->value);
2338 return &pcache->value;
2342 * gtk_style_context_get_style_property:
2343 * @context: a #GtkStyleContext
2344 * @property_name: the name of the widget style property
2345 * @value: Return location for the property value
2347 * Gets the value for a widget style property.
2349 * When @value is no longer needed, g_value_unset() must be called
2350 * to free any allocated memory.
2353 gtk_style_context_get_style_property (GtkStyleContext *context,
2354 const gchar *property_name,
2357 GtkStyleContextPrivate *priv;
2358 GtkWidgetClass *widget_class;
2359 GtkStateFlags state;
2361 const GValue *peek_value;
2364 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2365 g_return_if_fail (property_name != NULL);
2366 g_return_if_fail (value != NULL);
2368 priv = context->priv;
2372 widget_type = G_OBJECT_TYPE (priv->widget);
2376 if (!priv->widget_path)
2379 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2381 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2383 g_warning ("%s: can't get style properties for non-widget class `%s'",
2385 g_type_name (widget_type));
2390 widget_class = g_type_class_ref (widget_type);
2391 pspec = gtk_widget_class_find_style_property (widget_class, property_name);
2392 g_type_class_unref (widget_class);
2396 g_warning ("%s: widget class `%s' has no style property named `%s'",
2398 g_type_name (widget_type),
2403 state = gtk_style_context_get_state (context);
2404 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2407 if (G_VALUE_TYPE (value) == G_VALUE_TYPE (peek_value))
2408 g_value_copy (peek_value, value);
2409 else if (g_value_type_transformable (G_VALUE_TYPE (peek_value), G_VALUE_TYPE (value)))
2410 g_value_transform (peek_value, value);
2412 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
2414 G_VALUE_TYPE_NAME (peek_value),
2415 G_VALUE_TYPE_NAME (value));
2419 * gtk_style_context_get_style_valist:
2420 * @context: a #GtkStyleContext
2421 * @args: va_list of property name/return location pairs, followed by %NULL
2423 * Retrieves several widget style properties from @context according to the
2429 gtk_style_context_get_style_valist (GtkStyleContext *context,
2432 GtkStyleContextPrivate *priv;
2433 const gchar *prop_name;
2434 GtkStateFlags state;
2437 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2439 prop_name = va_arg (args, const gchar *);
2440 priv = context->priv;
2444 widget_type = G_OBJECT_TYPE (priv->widget);
2448 if (!priv->widget_path)
2451 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2453 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2455 g_warning ("%s: can't get style properties for non-widget class `%s'",
2457 g_type_name (widget_type));
2462 state = gtk_style_context_get_state (context);
2466 GtkWidgetClass *widget_class;
2468 const GValue *peek_value;
2471 widget_class = g_type_class_ref (widget_type);
2472 pspec = gtk_widget_class_find_style_property (widget_class, prop_name);
2473 g_type_class_unref (widget_class);
2477 g_warning ("%s: widget class `%s' has no style property named `%s'",
2479 g_type_name (widget_type),
2484 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2487 G_VALUE_LCOPY (peek_value, args, 0, &error);
2491 g_warning ("can't retrieve style property `%s' of type `%s': %s",
2493 G_VALUE_TYPE_NAME (peek_value),
2499 prop_name = va_arg (args, const gchar *);
2504 * gtk_style_context_get_style:
2505 * @context: a #GtkStyleContext
2506 * @...: property name /return value pairs, followed by %NULL
2508 * Retrieves several widget style properties from @context according to the
2514 gtk_style_context_get_style (GtkStyleContext *context,
2519 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2521 va_start (args, context);
2522 gtk_style_context_get_style_valist (context, args);
2528 * gtk_style_context_lookup_icon_set:
2529 * @context: a #GtkStyleContext
2530 * @stock_id: an icon name
2532 * Looks up @stock_id in the icon factories associated to @context and
2533 * the default icon factory, returning an icon set if found, otherwise
2536 * Returns: (transfer none): The looked up %GtkIconSet, or %NULL
2539 gtk_style_context_lookup_icon_set (GtkStyleContext *context,
2540 const gchar *stock_id)
2542 GtkStyleContextPrivate *priv;
2544 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2545 g_return_val_if_fail (stock_id != NULL, NULL);
2547 priv = context->priv;
2548 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
2550 return gtk_icon_factory_lookup_default (stock_id);
2554 * gtk_style_context_set_screen:
2555 * @context: a #GtkStyleContext
2556 * @screen: a #GdkScreen
2558 * Attaches @context to the given screen.
2560 * The screen is used to add style information from 'global' style
2561 * providers, such as the screens #GtkSettings instance.
2563 * If you are using a #GtkStyleContext returned from
2564 * gtk_widget_get_style_context(), you do not need to
2565 * call this yourself.
2570 gtk_style_context_set_screen (GtkStyleContext *context,
2573 GtkStyleContextPrivate *priv;
2575 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2576 g_return_if_fail (GDK_IS_SCREEN (screen));
2578 priv = context->priv;
2579 if (priv->screen == screen)
2582 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
2584 gtk_style_context_set_cascade (context, _gtk_style_cascade_get_for_screen (screen));
2588 _gtk_style_cascade_set_parent (priv->cascade, _gtk_style_cascade_get_for_screen (screen));
2591 priv->screen = screen;
2593 g_object_notify (G_OBJECT (context), "screen");
2597 * gtk_style_context_get_screen:
2598 * @context: a #GtkStyleContext
2600 * Returns the #GdkScreen to which @context is attached.
2602 * Returns: (transfer none): a #GdkScreen.
2605 gtk_style_context_get_screen (GtkStyleContext *context)
2607 GtkStyleContextPrivate *priv;
2609 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2611 priv = context->priv;
2612 return priv->screen;
2616 * gtk_style_context_set_direction:
2617 * @context: a #GtkStyleContext
2618 * @direction: the new direction.
2620 * Sets the reading direction for rendering purposes.
2622 * If you are using a #GtkStyleContext returned from
2623 * gtk_widget_get_style_context(), you do not need to
2624 * call this yourself.
2629 gtk_style_context_set_direction (GtkStyleContext *context,
2630 GtkTextDirection direction)
2632 GtkStyleContextPrivate *priv;
2634 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2636 priv = context->priv;
2637 priv->direction = direction;
2639 g_object_notify (G_OBJECT (context), "direction");
2643 * gtk_style_context_get_direction:
2644 * @context: a #GtkStyleContext
2646 * Returns the widget direction used for rendering.
2648 * Returns: the widget direction
2653 gtk_style_context_get_direction (GtkStyleContext *context)
2655 GtkStyleContextPrivate *priv;
2657 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), GTK_TEXT_DIR_LTR);
2659 priv = context->priv;
2660 return priv->direction;
2664 * gtk_style_context_set_junction_sides:
2665 * @context: a #GtkStyleContext
2666 * @sides: sides where rendered elements are visually connected to
2669 * Sets the sides where rendered elements (mostly through
2670 * gtk_render_frame()) will visually connect with other visual elements.
2672 * This is merely a hint that may or may not be honored
2673 * by theming engines.
2675 * Container widgets are expected to set junction hints as appropriate
2676 * for their children, so it should not normally be necessary to call
2677 * this function manually.
2682 gtk_style_context_set_junction_sides (GtkStyleContext *context,
2683 GtkJunctionSides sides)
2685 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2687 context->priv->info->junction_sides = sides;
2691 * gtk_style_context_get_junction_sides:
2692 * @context: a #GtkStyleContext
2694 * Returns the sides where rendered elements connect visually with others.
2696 * Returns: the junction sides
2701 gtk_style_context_get_junction_sides (GtkStyleContext *context)
2703 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
2705 return context->priv->info->junction_sides;
2709 _gtk_style_context_resolve_color_value (GtkStyleContext *context,
2710 GtkCssValue *current,
2711 GtkCssDependencies current_deps,
2713 GtkCssDependencies *dependencies)
2715 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2716 g_return_val_if_fail (current != NULL, FALSE);
2717 g_return_val_if_fail (color != NULL, FALSE);
2719 return _gtk_symbolic_color_resolve_full ((GtkSymbolicColor *) color,
2720 GTK_STYLE_PROVIDER_PRIVATE (context->priv->cascade),
2728 _gtk_style_context_resolve_color (GtkStyleContext *context,
2729 GtkSymbolicColor *color,
2731 GtkCssDependencies *dependencies)
2735 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2736 g_return_val_if_fail (color != NULL, FALSE);
2737 g_return_val_if_fail (result != NULL, FALSE);
2739 val = _gtk_symbolic_color_resolve_full (color,
2740 GTK_STYLE_PROVIDER_PRIVATE (context->priv->cascade),
2741 _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR),
2742 GTK_CSS_DEPENDS_ON_COLOR,
2747 *result = *_gtk_css_rgba_value_get_rgba (val);
2748 _gtk_css_value_unref (val);
2753 * gtk_style_context_lookup_color:
2754 * @context: a #GtkStyleContext
2755 * @color_name: color name to lookup
2756 * @color: (out): Return location for the looked up color
2758 * Looks up and resolves a color name in the @context color map.
2760 * Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
2763 gtk_style_context_lookup_color (GtkStyleContext *context,
2764 const gchar *color_name,
2767 GtkSymbolicColor *sym_color;
2769 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2770 g_return_val_if_fail (color_name != NULL, FALSE);
2771 g_return_val_if_fail (color != NULL, FALSE);
2773 sym_color = _gtk_style_provider_private_get_color (GTK_STYLE_PROVIDER_PRIVATE (context->priv->cascade), color_name);
2774 if (sym_color == NULL)
2777 return _gtk_style_context_resolve_color (context, sym_color, color, NULL);
2781 * gtk_style_context_notify_state_change:
2782 * @context: a #GtkStyleContext
2783 * @window: a #GdkWindow
2784 * @region_id: (allow-none): animatable region to notify on, or %NULL.
2785 * See gtk_style_context_push_animatable_region()
2786 * @state: state to trigger transition for
2787 * @state_value: %TRUE if @state is the state we are changing to,
2788 * %FALSE if we are changing away from it
2790 * Notifies a state change on @context, so if the current style makes use
2791 * of transition animations, one will be started so all rendered elements
2792 * under @region_id are animated for state @state being set to value
2795 * The @window parameter is used in order to invalidate the rendered area
2796 * as the animation runs, so make sure it is the same window that is being
2797 * rendered on by the gtk_render_*() functions.
2799 * If @region_id is %NULL, all rendered elements using @context will be
2800 * affected by this state transition.
2802 * As a practical example, a #GtkButton notifying a state transition on
2803 * the prelight state:
2805 * gtk_style_context_notify_state_change (context,
2806 * gtk_widget_get_window (widget),
2808 * GTK_STATE_PRELIGHT,
2809 * button->in_button);
2812 * Can be handled in the CSS file like this:
2815 * background-color: #f00
2819 * background-color: #fff;
2820 * transition: 200ms linear
2824 * This combination will animate the button background from red to white
2825 * if a pointer enters the button, and back to red if the pointer leaves
2828 * Note that @state is used when finding the transition parameters, which
2829 * is why the style places the transition under the :hover pseudo-class.
2833 * Deprecated: 3.6: This function does nothing.
2836 gtk_style_context_notify_state_change (GtkStyleContext *context,
2840 gboolean state_value)
2842 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2843 g_return_if_fail (GDK_IS_WINDOW (window));
2844 g_return_if_fail (state > GTK_STATE_NORMAL && state <= GTK_STATE_FOCUSED);
2845 g_return_if_fail (context->priv->widget != NULL || context->priv->widget_path != NULL);
2849 * gtk_style_context_cancel_animations:
2850 * @context: a #GtkStyleContext
2851 * @region_id: (allow-none): animatable region to stop, or %NULL.
2852 * See gtk_style_context_push_animatable_region()
2854 * Stops all running animations for @region_id and all animatable
2855 * regions underneath.
2857 * A %NULL @region_id will stop all ongoing animations in @context,
2858 * when dealing with a #GtkStyleContext obtained through
2859 * gtk_widget_get_style_context(), this is normally done for you
2860 * in all circumstances you would expect all widget to be stopped,
2861 * so this should be only used in complex widgets with different
2862 * animatable regions.
2866 * Deprecated: 3.6: This function does nothing.
2869 gtk_style_context_cancel_animations (GtkStyleContext *context,
2872 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2876 * gtk_style_context_scroll_animations:
2877 * @context: a #GtkStyleContext
2878 * @window: a #GdkWindow used previously in
2879 * gtk_style_context_notify_state_change()
2880 * @dx: Amount to scroll in the X axis
2881 * @dy: Amount to scroll in the Y axis
2883 * This function is analogous to gdk_window_scroll(), and
2884 * should be called together with it so the invalidation
2885 * areas for any ongoing animation are scrolled together
2890 * Deprecated: 3.6: This function does nothing.
2893 gtk_style_context_scroll_animations (GtkStyleContext *context,
2898 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2899 g_return_if_fail (GDK_IS_WINDOW (window));
2903 * gtk_style_context_push_animatable_region:
2904 * @context: a #GtkStyleContext
2905 * @region_id: unique identifier for the animatable region
2907 * Pushes an animatable region, so all further gtk_render_*() calls between
2908 * this call and the following gtk_style_context_pop_animatable_region()
2909 * will potentially show transition animations for this region if
2910 * gtk_style_context_notify_state_change() is called for a given state,
2911 * and the current theme/style defines transition animations for state
2914 * The @region_id used must be unique in @context so the theming engine
2915 * can uniquely identify rendered elements subject to a state transition.
2919 * Deprecated: 3.6: This function does nothing.
2922 gtk_style_context_push_animatable_region (GtkStyleContext *context,
2925 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2926 g_return_if_fail (region_id != NULL);
2930 * gtk_style_context_pop_animatable_region:
2931 * @context: a #GtkStyleContext
2933 * Pops an animatable region from @context.
2934 * See gtk_style_context_push_animatable_region().
2938 * Deprecated: 3.6: This function does nothing.
2941 gtk_style_context_pop_animatable_region (GtkStyleContext *context)
2943 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2947 gtk_style_context_clear_cache (GtkStyleContext *context)
2949 GtkStyleContextPrivate *priv;
2952 priv = context->priv;
2954 for (info = priv->info; info; info = info->next)
2956 style_info_set_data (info, NULL);
2958 g_hash_table_remove_all (priv->style_data);
2962 gtk_style_context_update_cache (GtkStyleContext *context,
2963 const GtkBitmask *parent_changes)
2965 GtkStyleContextPrivate *priv;
2966 GHashTableIter iter;
2967 gpointer key, value;
2969 priv = context->priv;
2971 g_hash_table_iter_init (&iter, priv->style_data);
2972 while (g_hash_table_iter_next (&iter, &key, &value))
2974 GtkStyleInfo *info = key;
2975 StyleData *data = value;
2976 GtkBitmask *changes;
2978 changes = _gtk_bitmask_copy (parent_changes);
2979 changes = _gtk_bitmask_intersect (changes, data->store->depends_on_parent);
2980 if (_gtk_bitmask_get (changes, GTK_CSS_PROPERTY_COLOR))
2981 changes = _gtk_bitmask_union (changes, data->store->depends_on_color);
2982 if (_gtk_bitmask_get (changes, GTK_CSS_PROPERTY_FONT_SIZE))
2983 changes = _gtk_bitmask_union (changes, data->store->depends_on_font_size);
2985 build_properties (context, data->store, info, changes);
2990 gtk_style_context_do_invalidate (GtkStyleContext *context)
2992 GtkStyleContextPrivate *priv;
2994 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2996 priv = context->priv;
2998 /* Avoid reentrancy */
2999 if (priv->invalidating_context)
3002 priv->invalidating_context = TRUE;
3004 g_signal_emit (context, signals[CHANGED], 0);
3006 priv->invalidating_context = FALSE;
3010 gtk_style_context_update_animations (GtkStyleContext *context,
3013 GtkBitmask *differences;
3014 StyleData *style_data;
3016 style_data = style_data_lookup (context);
3018 differences = _gtk_css_computed_values_advance (style_data->store,
3021 if (_gtk_css_computed_values_is_static (style_data->store))
3022 _gtk_style_context_update_animating (context);
3028 gtk_style_context_needs_full_revalidate (GtkStyleContext *context,
3029 GtkCssChange change)
3031 GtkStyleContextPrivate *priv = context->priv;
3033 /* Try to avoid invalidating if we can */
3034 if (change & GTK_STYLE_CONTEXT_RADICAL_CHANGE)
3036 priv->relevant_changes = GTK_CSS_CHANGE_ANY;
3040 if (priv->relevant_changes == GTK_CSS_CHANGE_ANY)
3042 GtkWidgetPath *path;
3043 GtkCssMatcher matcher;
3045 path = create_query_path (context, priv->info);
3046 if (_gtk_css_matcher_init (&matcher, path, priv->info->state_flags))
3047 priv->relevant_changes = _gtk_style_provider_private_get_change (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
3050 priv->relevant_changes = 0;
3052 priv->relevant_changes &= ~GTK_STYLE_CONTEXT_RADICAL_CHANGE;
3054 gtk_widget_path_unref (path);
3058 if (priv->relevant_changes & change)
3065 gtk_style_context_should_create_transitions (GtkStyleContext *context)
3067 GtkStyleContextPrivate *priv;
3070 priv = context->priv;
3072 if (priv->widget == NULL)
3075 if (!gtk_widget_get_mapped (priv->widget))
3078 g_object_get (gtk_widget_get_settings (context->priv->widget),
3079 "gtk-enable-animations", &animate,
3086 _gtk_style_context_validate (GtkStyleContext *context,
3088 GtkCssChange change,
3089 const GtkBitmask *parent_changes)
3091 GtkStyleContextPrivate *priv;
3094 GtkBitmask *changes;
3097 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3099 priv = context->priv;
3101 change |= priv->pending_changes;
3103 /* If you run your application with
3104 * GTK_DEBUG=no-css-cache
3105 * every invalidation will purge the cache and completely query
3106 * everything anew form the cache. This is slow (in particular
3107 * when animating), but useful for figuring out bugs.
3109 * We achieve that by pretending that everything that could have
3110 * changed has and so we of course totally need to redo everything.
3112 * Note that this also completely revalidates child widgets all
3115 if (G_UNLIKELY (gtk_get_debug_flags () & GTK_DEBUG_NO_CSS_CACHE))
3116 change = GTK_CSS_CHANGE_ANY;
3118 if (!priv->invalid && change == 0 && _gtk_bitmask_is_empty (parent_changes))
3121 priv->pending_changes = 0;
3122 gtk_style_context_set_invalid (context, FALSE);
3126 current = style_data_ref (info->data);
3130 /* Try to avoid invalidating if we can */
3131 if (current == NULL ||
3132 gtk_style_context_needs_full_revalidate (context, change))
3136 if ((priv->relevant_changes & change) & ~GTK_STYLE_CONTEXT_CACHED_CHANGE)
3138 gtk_style_context_clear_cache (context);
3142 gtk_style_context_update_cache (context, parent_changes);
3143 style_info_set_data (info, NULL);
3146 data = style_data_lookup (context);
3148 _gtk_css_computed_values_create_animations (data->store,
3150 current && gtk_style_context_should_create_transitions (context) ? current->store : NULL,
3152 if (_gtk_css_computed_values_is_static (data->store))
3153 change &= ~GTK_CSS_CHANGE_ANIMATE;
3155 change |= GTK_CSS_CHANGE_ANIMATE;
3156 _gtk_style_context_update_animating (context);
3160 changes = _gtk_css_computed_values_get_difference (data->store, current->store);
3162 /* In the case where we keep the cache, we want unanimated values */
3163 _gtk_css_computed_values_cancel_animations (current->store);
3167 changes = _gtk_bitmask_new ();
3168 changes = _gtk_bitmask_invert_range (changes, 0, _gtk_css_style_property_get_n_properties ());
3173 changes = _gtk_bitmask_copy (parent_changes);
3174 changes = _gtk_bitmask_intersect (changes, current->store->depends_on_parent);
3175 if (_gtk_bitmask_get (changes, GTK_CSS_PROPERTY_COLOR))
3176 changes = _gtk_bitmask_union (changes, current->store->depends_on_color);
3177 if (_gtk_bitmask_get (changes, GTK_CSS_PROPERTY_FONT_SIZE))
3178 changes = _gtk_bitmask_union (changes, current->store->depends_on_font_size);
3180 gtk_style_context_update_cache (context, parent_changes);
3184 style_data_unref (current);
3186 if (change & GTK_CSS_CHANGE_ANIMATE &&
3187 gtk_style_context_is_animating (context))
3189 GtkBitmask *animation_changes;
3191 animation_changes = gtk_style_context_update_animations (context, timestamp);
3192 changes = _gtk_bitmask_union (changes, animation_changes);
3193 _gtk_bitmask_free (animation_changes);
3196 if (!_gtk_bitmask_is_empty (changes))
3197 gtk_style_context_do_invalidate (context);
3199 change = _gtk_css_change_for_child (change);
3200 for (list = priv->children; list; list = list->next)
3202 _gtk_style_context_validate (list->data, timestamp, change, changes);
3205 _gtk_bitmask_free (changes);
3209 _gtk_style_context_queue_invalidate (GtkStyleContext *context,
3210 GtkCssChange change)
3212 GtkStyleContextPrivate *priv;
3214 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3215 g_return_if_fail (change != 0);
3217 priv = context->priv;
3219 if (priv->widget != NULL)
3221 priv->pending_changes |= change;
3222 gtk_style_context_set_invalid (context, TRUE);
3224 else if (priv->widget_path == NULL)
3226 gtk_style_context_invalidate (context);
3231 * gtk_style_context_invalidate:
3232 * @context: a #GtkStyleContext.
3234 * Invalidates @context style information, so it will be reconstructed
3237 * If you're using a #GtkStyleContext returned from
3238 * gtk_widget_get_style_context(), you do not need to
3239 * call this yourself.
3244 gtk_style_context_invalidate (GtkStyleContext *context)
3246 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3248 gtk_style_context_clear_cache (context);
3249 gtk_style_context_do_invalidate (context);
3253 * gtk_style_context_set_background:
3254 * @context: a #GtkStyleContext
3255 * @window: a #GdkWindow
3257 * Sets the background of @window to the background pattern or
3258 * color specified in @context for its current state.
3263 gtk_style_context_set_background (GtkStyleContext *context,
3266 GtkStateFlags state;
3267 cairo_pattern_t *pattern;
3270 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3271 g_return_if_fail (GDK_IS_WINDOW (window));
3273 state = gtk_style_context_get_state (context);
3274 gtk_style_context_get (context, state,
3275 "background-image", &pattern,
3279 gdk_window_set_background_pattern (window, pattern);
3280 cairo_pattern_destroy (pattern);
3284 gtk_style_context_get (context, state,
3285 "background-color", &color,
3289 gdk_window_set_background_rgba (window, color);
3290 gdk_rgba_free (color);
3295 * gtk_style_context_get_color:
3296 * @context: a #GtkStyleContext
3297 * @state: state to retrieve the color for
3298 * @color: (out): return value for the foreground color
3300 * Gets the foreground color for a given state.
3305 gtk_style_context_get_color (GtkStyleContext *context,
3306 GtkStateFlags state,
3311 g_return_if_fail (color != NULL);
3312 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3314 gtk_style_context_get (context,
3324 * gtk_style_context_get_background_color:
3325 * @context: a #GtkStyleContext
3326 * @state: state to retrieve the color for
3327 * @color: (out): return value for the background color
3329 * Gets the background color for a given state.
3334 gtk_style_context_get_background_color (GtkStyleContext *context,
3335 GtkStateFlags state,
3340 g_return_if_fail (color != NULL);
3341 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3343 gtk_style_context_get (context,
3345 "background-color", &c,
3353 * gtk_style_context_get_border_color:
3354 * @context: a #GtkStyleContext
3355 * @state: state to retrieve the color for
3356 * @color: (out): return value for the border color
3358 * Gets the border color for a given state.
3363 gtk_style_context_get_border_color (GtkStyleContext *context,
3364 GtkStateFlags state,
3369 g_return_if_fail (color != NULL);
3370 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3372 gtk_style_context_get (context,
3382 * gtk_style_context_get_border:
3383 * @context: a #GtkStyleContext
3384 * @state: state to retrieve the border for
3385 * @border: (out): return value for the border settings
3387 * Gets the border for a given state as a #GtkBorder.
3388 * See %GTK_STYLE_PROPERTY_BORDER_WIDTH.
3393 gtk_style_context_get_border (GtkStyleContext *context,
3394 GtkStateFlags state,
3397 int top, left, bottom, right;
3399 g_return_if_fail (border != NULL);
3400 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3402 gtk_style_context_get (context,
3404 "border-top-width", &top,
3405 "border-left-width", &left,
3406 "border-bottom-width", &bottom,
3407 "border-right-width", &right,
3411 border->left = left;
3412 border->bottom = bottom;
3413 border->right = right;
3417 * gtk_style_context_get_padding:
3418 * @context: a #GtkStyleContext
3419 * @state: state to retrieve the padding for
3420 * @padding: (out): return value for the padding settings
3422 * Gets the padding for a given state as a #GtkBorder.
3423 * See %GTK_STYLE_PROPERTY_PADDING.
3428 gtk_style_context_get_padding (GtkStyleContext *context,
3429 GtkStateFlags state,
3432 int top, left, bottom, right;
3434 g_return_if_fail (padding != NULL);
3435 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3437 gtk_style_context_get (context,
3439 "padding-top", &top,
3440 "padding-left", &left,
3441 "padding-bottom", &bottom,
3442 "padding-right", &right,
3446 padding->left = left;
3447 padding->bottom = bottom;
3448 padding->right = right;
3452 * gtk_style_context_get_margin:
3453 * @context: a #GtkStyleContext
3454 * @state: state to retrieve the border for
3455 * @margin: (out): return value for the margin settings
3457 * Gets the margin for a given state as a #GtkBorder.
3458 * See %GTK_STYLE_PROPERTY_MARGIN.
3463 gtk_style_context_get_margin (GtkStyleContext *context,
3464 GtkStateFlags state,
3467 int top, left, bottom, right;
3469 g_return_if_fail (margin != NULL);
3470 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3472 gtk_style_context_get (context,
3475 "margin-left", &left,
3476 "margin-bottom", &bottom,
3477 "margin-right", &right,
3481 margin->left = left;
3482 margin->bottom = bottom;
3483 margin->right = right;
3487 * gtk_style_context_get_font:
3488 * @context: a #GtkStyleContext
3489 * @state: state to retrieve the font for
3491 * Returns the font description for a given state. The returned
3492 * object is const and will remain valid until the
3493 * #GtkStyleContext::changed signal happens.
3495 * Returns: (transfer none): the #PangoFontDescription for the given
3496 * state. This object is owned by GTK+ and should not be
3501 const PangoFontDescription *
3502 gtk_style_context_get_font (GtkStyleContext *context,
3503 GtkStateFlags state)
3505 GtkStyleContextPrivate *priv;
3507 PangoFontDescription *description;
3509 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
3511 priv = context->priv;
3512 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
3514 data = style_data_lookup_for_state (context, state);
3516 /* Yuck, fonts are created on-demand but we don't return a ref.
3517 * Do bad things to achieve this requirement */
3518 description = g_object_get_data (G_OBJECT (data->store), "font-cache-for-get_font");
3519 if (description == NULL)
3521 gtk_style_context_get (context, state, "font", &description, NULL);
3522 g_object_set_data_full (G_OBJECT (data->store),
3523 "font-cache-for-get_font",
3525 (GDestroyNotify) pango_font_description_free);
3531 get_cursor_color (GtkStyleContext *context,
3535 GdkColor *style_color;
3537 gtk_style_context_get_style (context,
3538 primary ? "cursor-color" : "secondary-cursor-color",
3544 color->red = style_color->red / 65535.0;
3545 color->green = style_color->green / 65535.0;
3546 color->blue = style_color->blue / 65535.0;
3549 gdk_color_free (style_color);
3553 gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, color);
3559 gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &bg);
3561 color->red = (color->red + bg.red) * 0.5;
3562 color->green = (color->green + bg.green) * 0.5;
3563 color->blue = (color->blue + bg.blue) * 0.5;
3569 _gtk_style_context_get_cursor_color (GtkStyleContext *context,
3570 GdkRGBA *primary_color,
3571 GdkRGBA *secondary_color)
3574 get_cursor_color (context, TRUE, primary_color);
3576 if (secondary_color)
3577 get_cursor_color (context, FALSE, secondary_color);
3584 * @context: a #GtkStyleContext
3586 * @x: X origin of the rectangle
3587 * @y: Y origin of the rectangle
3588 * @width: rectangle width
3589 * @height: rectangle height
3591 * Renders a checkmark (as in a #GtkCheckButton).
3593 * The %GTK_STATE_FLAG_ACTIVE state determines whether the check is
3594 * on or off, and %GTK_STATE_FLAG_INCONSISTENT determines whether it
3595 * should be marked as undefined.
3598 * <title>Typical checkmark rendering</title>
3599 * <inlinegraphic fileref="checks.png" format="PNG"/>
3605 gtk_render_check (GtkStyleContext *context,
3612 GtkThemingEngineClass *engine_class;
3613 GtkThemingEngine *engine;
3615 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3616 g_return_if_fail (cr != NULL);
3618 if (width <= 0 || height <= 0)
3621 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3622 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3627 _gtk_theming_engine_set_context (engine, context);
3628 engine_class->render_check (engine, cr,
3629 x, y, width, height);
3635 * gtk_render_option:
3636 * @context: a #GtkStyleContext
3638 * @x: X origin of the rectangle
3639 * @y: Y origin of the rectangle
3640 * @width: rectangle width
3641 * @height: rectangle height
3643 * Renders an option mark (as in a #GtkRadioButton), the %GTK_STATE_FLAG_ACTIVE
3644 * state will determine whether the option is on or off, and
3645 * %GTK_STATE_FLAG_INCONSISTENT whether it should be marked as undefined.
3648 * <title>Typical option mark rendering</title>
3649 * <inlinegraphic fileref="options.png" format="PNG"/>
3655 gtk_render_option (GtkStyleContext *context,
3662 GtkThemingEngineClass *engine_class;
3663 GtkThemingEngine *engine;
3665 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3666 g_return_if_fail (cr != NULL);
3668 if (width <= 0 || height <= 0)
3671 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3672 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3676 _gtk_theming_engine_set_context (engine, context);
3677 engine_class->render_option (engine, cr,
3678 x, y, width, height);
3685 * @context: a #GtkStyleContext
3687 * @angle: arrow angle from 0 to 2 * %G_PI, being 0 the arrow pointing to the north
3688 * @x: X origin of the render area
3689 * @y: Y origin of the render area
3690 * @size: square side for render area
3692 * Renders an arrow pointing to @angle.
3695 * <title>Typical arrow rendering at 0, 1&solidus;2 π, π and 3&solidus;2 π</title>
3696 * <inlinegraphic fileref="arrows.png" format="PNG"/>
3702 gtk_render_arrow (GtkStyleContext *context,
3709 GtkThemingEngineClass *engine_class;
3710 GtkThemingEngine *engine;
3712 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3713 g_return_if_fail (cr != NULL);
3718 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3719 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3723 gtk_style_context_save (context);
3724 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ARROW);
3726 _gtk_theming_engine_set_context (engine, context);
3727 engine_class->render_arrow (engine, cr,
3730 gtk_style_context_restore (context);
3735 * gtk_render_background:
3736 * @context: a #GtkStyleContext
3738 * @x: X origin of the rectangle
3739 * @y: Y origin of the rectangle
3740 * @width: rectangle width
3741 * @height: rectangle height
3743 * Renders the background of an element.
3746 * <title>Typical background rendering, showing the effect of
3747 * <parameter>background-image</parameter>,
3748 * <parameter>border-width</parameter> and
3749 * <parameter>border-radius</parameter></title>
3750 * <inlinegraphic fileref="background.png" format="PNG"/>
3756 gtk_render_background (GtkStyleContext *context,
3763 GtkThemingEngineClass *engine_class;
3764 GtkThemingEngine *engine;
3766 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3767 g_return_if_fail (cr != NULL);
3769 if (width <= 0 || height <= 0)
3772 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3773 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3777 _gtk_theming_engine_set_context (engine, context);
3778 engine_class->render_background (engine, cr, x, y, width, height);
3785 * @context: a #GtkStyleContext
3787 * @x: X origin of the rectangle
3788 * @y: Y origin of the rectangle
3789 * @width: rectangle width
3790 * @height: rectangle height
3792 * Renders a frame around the rectangle defined by @x, @y, @width, @height.
3795 * <title>Examples of frame rendering, showing the effect of
3796 * <parameter>border-image</parameter>,
3797 * <parameter>border-color</parameter>,
3798 * <parameter>border-width</parameter>,
3799 * <parameter>border-radius</parameter> and
3801 * <inlinegraphic fileref="frames.png" format="PNG"/>
3807 gtk_render_frame (GtkStyleContext *context,
3814 GtkThemingEngineClass *engine_class;
3815 GtkThemingEngine *engine;
3817 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3818 g_return_if_fail (cr != NULL);
3820 if (width <= 0 || height <= 0)
3823 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3824 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3828 _gtk_theming_engine_set_context (engine, context);
3829 engine_class->render_frame (engine, cr, x, y, width, height);
3835 * gtk_render_expander:
3836 * @context: a #GtkStyleContext
3838 * @x: X origin of the rectangle
3839 * @y: Y origin of the rectangle
3840 * @width: rectangle width
3841 * @height: rectangle height
3843 * Renders an expander (as used in #GtkTreeView and #GtkExpander) in the area
3844 * defined by @x, @y, @width, @height. The state %GTK_STATE_FLAG_ACTIVE
3845 * determines whether the expander is collapsed or expanded.
3848 * <title>Typical expander rendering</title>
3849 * <inlinegraphic fileref="expanders.png" format="PNG"/>
3855 gtk_render_expander (GtkStyleContext *context,
3862 GtkThemingEngineClass *engine_class;
3863 GtkThemingEngine *engine;
3865 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3866 g_return_if_fail (cr != NULL);
3868 if (width <= 0 || height <= 0)
3871 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3872 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3876 _gtk_theming_engine_set_context (engine, context);
3877 engine_class->render_expander (engine, cr, x, y, width, height);
3884 * @context: a #GtkStyleContext
3886 * @x: X origin of the rectangle
3887 * @y: Y origin of the rectangle
3888 * @width: rectangle width
3889 * @height: rectangle height
3891 * Renders a focus indicator on the rectangle determined by @x, @y, @width, @height.
3893 * <title>Typical focus rendering</title>
3894 * <inlinegraphic fileref="focus.png" format="PNG"/>
3900 gtk_render_focus (GtkStyleContext *context,
3907 GtkThemingEngineClass *engine_class;
3908 GtkThemingEngine *engine;
3910 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3911 g_return_if_fail (cr != NULL);
3913 if (width <= 0 || height <= 0)
3916 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3917 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3921 _gtk_theming_engine_set_context (engine, context);
3922 engine_class->render_focus (engine, cr, x, y, width, height);
3928 * gtk_render_layout:
3929 * @context: a #GtkStyleContext
3933 * @layout: the #PangoLayout to render
3935 * Renders @layout on the coordinates @x, @y
3940 gtk_render_layout (GtkStyleContext *context,
3944 PangoLayout *layout)
3946 GtkThemingEngineClass *engine_class;
3947 GtkThemingEngine *engine;
3948 PangoRectangle extents;
3950 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3951 g_return_if_fail (PANGO_IS_LAYOUT (layout));
3952 g_return_if_fail (cr != NULL);
3954 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3955 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3959 pango_layout_get_extents (layout, &extents, NULL);
3961 _gtk_theming_engine_set_context (engine, context);
3962 engine_class->render_layout (engine, cr, x, y, layout);
3969 * @context: a #GtkStyleContext
3971 * @x0: X coordinate for the origin of the line
3972 * @y0: Y coordinate for the origin of the line
3973 * @x1: X coordinate for the end of the line
3974 * @y1: Y coordinate for the end of the line
3976 * Renders a line from (x0, y0) to (x1, y1).
3981 gtk_render_line (GtkStyleContext *context,
3988 GtkThemingEngineClass *engine_class;
3989 GtkThemingEngine *engine;
3991 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3992 g_return_if_fail (cr != NULL);
3994 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3995 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3999 _gtk_theming_engine_set_context (engine, context);
4000 engine_class->render_line (engine, cr, x0, y0, x1, y1);
4006 * gtk_render_slider:
4007 * @context: a #GtkStyleContext
4009 * @x: X origin of the rectangle
4010 * @y: Y origin of the rectangle
4011 * @width: rectangle width
4012 * @height: rectangle height
4013 * @orientation: orientation of the slider
4015 * Renders a slider (as in #GtkScale) in the rectangle defined by @x, @y,
4016 * @width, @height. @orientation defines whether the slider is vertical
4020 * <title>Typical slider rendering</title>
4021 * <inlinegraphic fileref="sliders.png" format="PNG"/>
4027 gtk_render_slider (GtkStyleContext *context,
4033 GtkOrientation orientation)
4035 GtkThemingEngineClass *engine_class;
4036 GtkThemingEngine *engine;
4038 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4039 g_return_if_fail (cr != NULL);
4041 if (width <= 0 || height <= 0)
4044 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4045 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4049 _gtk_theming_engine_set_context (engine, context);
4050 engine_class->render_slider (engine, cr, x, y, width, height, orientation);
4056 * gtk_render_frame_gap:
4057 * @context: a #GtkStyleContext
4059 * @x: X origin of the rectangle
4060 * @y: Y origin of the rectangle
4061 * @width: rectangle width
4062 * @height: rectangle height
4063 * @gap_side: side where the gap is
4064 * @xy0_gap: initial coordinate (X or Y depending on @gap_side) for the gap
4065 * @xy1_gap: end coordinate (X or Y depending on @gap_side) for the gap
4067 * Renders a frame around the rectangle defined by (@x, @y, @width, @height),
4068 * leaving a gap on one side. @xy0_gap and @xy1_gap will mean X coordinates
4069 * for %GTK_POS_TOP and %GTK_POS_BOTTOM gap sides, and Y coordinates for
4070 * %GTK_POS_LEFT and %GTK_POS_RIGHT.
4073 * <title>Typical rendering of a frame with a gap</title>
4074 * <inlinegraphic fileref="frame-gap.png" format="PNG"/>
4080 gtk_render_frame_gap (GtkStyleContext *context,
4086 GtkPositionType gap_side,
4090 GtkThemingEngineClass *engine_class;
4091 GtkThemingEngine *engine;
4093 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4094 g_return_if_fail (cr != NULL);
4095 g_return_if_fail (xy0_gap <= xy1_gap);
4096 g_return_if_fail (xy0_gap >= 0);
4098 if (width <= 0 || height <= 0)
4101 if (gap_side == GTK_POS_LEFT ||
4102 gap_side == GTK_POS_RIGHT)
4103 g_return_if_fail (xy1_gap <= height);
4105 g_return_if_fail (xy1_gap <= width);
4107 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4108 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4112 _gtk_theming_engine_set_context (engine, context);
4113 engine_class->render_frame_gap (engine, cr,
4114 x, y, width, height, gap_side,
4121 * gtk_render_extension:
4122 * @context: a #GtkStyleContext
4124 * @x: X origin of the rectangle
4125 * @y: Y origin of the rectangle
4126 * @width: rectangle width
4127 * @height: rectangle height
4128 * @gap_side: side where the gap is
4130 * Renders a extension (as in a #GtkNotebook tab) in the rectangle
4131 * defined by @x, @y, @width, @height. The side where the extension
4132 * connects to is defined by @gap_side.
4135 * <title>Typical extension rendering</title>
4136 * <inlinegraphic fileref="extensions.png" format="PNG"/>
4142 gtk_render_extension (GtkStyleContext *context,
4148 GtkPositionType gap_side)
4150 GtkThemingEngineClass *engine_class;
4151 GtkThemingEngine *engine;
4153 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4154 g_return_if_fail (cr != NULL);
4156 if (width <= 0 || height <= 0)
4159 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4160 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4164 _gtk_theming_engine_set_context (engine, context);
4165 engine_class->render_extension (engine, cr, x, y, width, height, gap_side);
4171 * gtk_render_handle:
4172 * @context: a #GtkStyleContext
4174 * @x: X origin of the rectangle
4175 * @y: Y origin of the rectangle
4176 * @width: rectangle width
4177 * @height: rectangle height
4179 * Renders a handle (as in #GtkHandleBox, #GtkPaned and
4180 * #GtkWindow<!-- -->'s resize grip), in the rectangle
4181 * determined by @x, @y, @width, @height.
4184 * <title>Handles rendered for the paned and grip classes</title>
4185 * <inlinegraphic fileref="handles.png" format="PNG"/>
4191 gtk_render_handle (GtkStyleContext *context,
4198 GtkThemingEngineClass *engine_class;
4199 GtkThemingEngine *engine;
4201 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4202 g_return_if_fail (cr != NULL);
4204 if (width <= 0 || height <= 0)
4207 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4208 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4212 _gtk_theming_engine_set_context (engine, context);
4213 engine_class->render_handle (engine, cr, x, y, width, height);
4219 * gtk_render_activity:
4220 * @context: a #GtkStyleContext
4222 * @x: X origin of the rectangle
4223 * @y: Y origin of the rectangle
4224 * @width: rectangle width
4225 * @height: rectangle height
4227 * Renders an activity area (Such as in #GtkSpinner or the
4228 * fill line in #GtkRange), the state %GTK_STATE_FLAG_ACTIVE
4229 * determines whether there is activity going on.
4234 gtk_render_activity (GtkStyleContext *context,
4241 GtkThemingEngineClass *engine_class;
4242 GtkThemingEngine *engine;
4244 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4245 g_return_if_fail (cr != NULL);
4247 if (width <= 0 || height <= 0)
4250 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4251 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4255 _gtk_theming_engine_set_context (engine, context);
4256 engine_class->render_activity (engine, cr, x, y, width, height);
4262 * gtk_render_icon_pixbuf:
4263 * @context: a #GtkStyleContext
4264 * @source: the #GtkIconSource specifying the icon to render
4265 * @size: (type int): the size to render the icon at. A size of (GtkIconSize) -1
4266 * means render at the size of the source and don't scale.
4268 * Renders the icon specified by @source at the given @size, returning the result
4271 * Returns: (transfer full): a newly-created #GdkPixbuf containing the rendered icon
4276 gtk_render_icon_pixbuf (GtkStyleContext *context,
4277 const GtkIconSource *source,
4280 GtkThemingEngineClass *engine_class;
4281 GtkThemingEngine *engine;
4283 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
4284 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
4285 g_return_val_if_fail (source != NULL, 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);
4290 _gtk_theming_engine_set_context (engine, context);
4291 return engine_class->render_icon_pixbuf (engine, source, size);
4296 * @context: a #GtkStyleContext
4298 * @pixbuf: a #GdkPixbuf containing the icon to draw
4299 * @x: X position for the @pixbuf
4300 * @y: Y position for the @pixbuf
4302 * Renders the icon in @pixbuf at the specified @x and @y coordinates.
4307 gtk_render_icon (GtkStyleContext *context,
4313 GtkThemingEngineClass *engine_class;
4314 GtkThemingEngine *engine;
4316 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4317 g_return_if_fail (cr != NULL);
4319 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4320 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4324 _gtk_theming_engine_set_context (engine, context);
4325 engine_class->render_icon (engine, cr, pixbuf, x, y);
4331 draw_insertion_cursor (GtkStyleContext *context,
4336 gboolean is_primary,
4337 PangoDirection direction,
4338 gboolean draw_arrow)
4341 GdkRGBA primary_color;
4342 GdkRGBA secondary_color;
4343 gfloat cursor_aspect_ratio;
4349 _gtk_style_context_get_cursor_color (context, &primary_color, &secondary_color);
4350 gdk_cairo_set_source_rgba (cr, is_primary ? &primary_color : &secondary_color);
4352 /* When changing the shape or size of the cursor here,
4353 * propagate the changes to gtktextview.c:text_window_invalidate_cursors().
4356 gtk_style_context_get_style (context,
4357 "cursor-aspect-ratio", &cursor_aspect_ratio,
4360 stem_width = height * cursor_aspect_ratio + 1;
4362 /* put (stem_width % 2) on the proper side of the cursor */
4363 if (direction == PANGO_DIRECTION_LTR)
4364 offset = stem_width / 2;
4366 offset = stem_width - stem_width / 2;
4368 cairo_rectangle (cr, x - offset, y, stem_width, height);
4376 arrow_width = stem_width + 1;
4378 if (direction == PANGO_DIRECTION_RTL)
4380 ax = x - offset - 1;
4381 ay = y + height - arrow_width * 2 - arrow_width + 1;
4383 cairo_move_to (cr, ax, ay + 1);
4384 cairo_line_to (cr, ax - arrow_width, ay + arrow_width);
4385 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4388 else if (direction == PANGO_DIRECTION_LTR)
4390 ax = x + stem_width - offset;
4391 ay = y + height - arrow_width * 2 - arrow_width + 1;
4393 cairo_move_to (cr, ax, ay + 1);
4394 cairo_line_to (cr, ax + arrow_width, ay + arrow_width);
4395 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4399 g_assert_not_reached();
4406 * gtk_render_insertion_cursor:
4407 * @context: a #GtkStyleContext
4411 * @layout: the #PangoLayout of the text
4412 * @index: the index in the #PangoLayout
4413 * @direction: the #PangoDirection of the text
4415 * Draws a text caret on @cr at the specified index of @layout.
4420 gtk_render_insertion_cursor (GtkStyleContext *context,
4424 PangoLayout *layout,
4426 PangoDirection direction)
4428 GtkStyleContextPrivate *priv;
4429 gboolean split_cursor;
4430 PangoRectangle strong_pos, weak_pos;
4431 PangoRectangle *cursor1, *cursor2;
4432 PangoDirection keymap_direction;
4433 PangoDirection direction2;
4435 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4436 g_return_if_fail (cr != NULL);
4437 g_return_if_fail (PANGO_IS_LAYOUT (layout));
4438 g_return_if_fail (index >= 0);
4440 priv = context->priv;
4442 g_object_get (gtk_settings_get_for_screen (priv->screen),
4443 "gtk-split-cursor", &split_cursor,
4446 keymap_direction = gdk_keymap_get_direction (gdk_keymap_get_for_display (gdk_screen_get_display (priv->screen)));
4448 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4450 direction2 = PANGO_DIRECTION_NEUTRAL;
4454 cursor1 = &strong_pos;
4456 if (strong_pos.x != weak_pos.x || strong_pos.y != weak_pos.y)
4458 direction2 = (direction == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
4459 cursor2 = &weak_pos;
4464 if (keymap_direction == direction)
4465 cursor1 = &strong_pos;
4467 cursor1 = &weak_pos;
4470 draw_insertion_cursor (context,
4472 x + PANGO_PIXELS (cursor1->x),
4473 y + PANGO_PIXELS (cursor1->y),
4474 PANGO_PIXELS (cursor1->height),
4477 direction2 != PANGO_DIRECTION_NEUTRAL);
4479 if (direction2 != PANGO_DIRECTION_NEUTRAL)
4481 draw_insertion_cursor (context,
4483 x + PANGO_PIXELS (cursor2->x),
4484 y + PANGO_PIXELS (cursor2->y),
4485 PANGO_PIXELS (cursor2->height),
4493 * gtk_draw_insertion_cursor:
4494 * @widget: a #GtkWidget
4495 * @cr: cairo context to draw to
4496 * @location: location where to draw the cursor (@location->width is ignored)
4497 * @is_primary: if the cursor should be the primary cursor color.
4498 * @direction: whether the cursor is left-to-right or
4499 * right-to-left. Should never be #GTK_TEXT_DIR_NONE
4500 * @draw_arrow: %TRUE to draw a directional arrow on the
4501 * cursor. Should be %FALSE unless the cursor is split.
4503 * Draws a text caret on @cr at @location. This is not a style function
4504 * but merely a convenience function for drawing the standard cursor shape.
4507 * Deprecated: 3.4: Use gtk_render_insertion_cursor() instead.
4510 gtk_draw_insertion_cursor (GtkWidget *widget,
4512 const GdkRectangle *location,
4513 gboolean is_primary,
4514 GtkTextDirection direction,
4515 gboolean draw_arrow)
4517 GtkStyleContext *context;
4519 g_return_if_fail (GTK_IS_WIDGET (widget));
4520 g_return_if_fail (cr != NULL);
4521 g_return_if_fail (location != NULL);
4522 g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
4524 context = gtk_widget_get_style_context (widget);
4526 draw_insertion_cursor (context, cr,
4527 location->x, location->y, location->height,
4529 (direction == GTK_TEXT_DIR_RTL) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR,
4533 static AtkAttributeSet *
4534 add_attribute (AtkAttributeSet *attributes,
4535 AtkTextAttribute attr,
4540 at = g_new (AtkAttribute, 1);
4541 at->name = g_strdup (atk_text_attribute_get_name (attr));
4542 at->value = g_strdup (value);
4544 return g_slist_prepend (attributes, at);
4548 * _gtk_style_context_get_attributes:
4549 * @attributes: a #AtkAttributeSet to add attributes to
4550 * @context: the #GtkStyleContext to get attributes from
4551 * @flags: the state to use with @context
4553 * Adds the foreground and background color from @context to
4554 * @attributes, after translating them to ATK attributes.
4556 * This is a convenience function that can be used in
4557 * implementing the #AtkText interface in widgets.
4559 * Returns: the modified #AtkAttributeSet
4562 _gtk_style_context_get_attributes (AtkAttributeSet *attributes,
4563 GtkStyleContext *context,
4564 GtkStateFlags flags)
4569 gtk_style_context_get_background_color (context, flags, &color);
4570 value = g_strdup_printf ("%u,%u,%u",
4571 (guint) ceil (color.red * 65536 - color.red),
4572 (guint) ceil (color.green * 65536 - color.green),
4573 (guint) ceil (color.blue * 65536 - color.blue));
4574 attributes = add_attribute (attributes, ATK_TEXT_ATTR_BG_COLOR, value);
4577 gtk_style_context_get_color (context, flags, &color);
4578 value = g_strdup_printf ("%u,%u,%u",
4579 (guint) ceil (color.red * 65536 - color.red),
4580 (guint) ceil (color.green * 65536 - color.green),
4581 (guint) ceil (color.blue * 65536 - color.blue));
4582 attributes = add_attribute (attributes, ATK_TEXT_ATTR_FG_COLOR, value);