1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2010 Carlos Garnacho <carlosg@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
23 #include <gobject/gvaluecollector.h>
25 #include "gtkstylecontextprivate.h"
26 #include "gtkcontainerprivate.h"
27 #include "gtkcsscolorvalueprivate.h"
28 #include "gtkcsscornervalueprivate.h"
29 #include "gtkcssenginevalueprivate.h"
30 #include "gtkcssnumbervalueprivate.h"
31 #include "gtkcssrgbavalueprivate.h"
33 #include "gtkstylepropertiesprivate.h"
34 #include "gtktypebuiltins.h"
35 #include "gtkthemingengineprivate.h"
37 #include "gtkwidget.h"
38 #include "gtkwindow.h"
39 #include "gtkprivate.h"
40 #include "gtkiconfactory.h"
41 #include "gtkwidgetpath.h"
42 #include "gtkwidgetprivate.h"
43 #include "gtkstylecascadeprivate.h"
44 #include "gtkstyleproviderprivate.h"
45 #include "gtksettings.h"
46 #include "gtksettingsprivate.h"
48 #include "deprecated/gtkgradientprivate.h"
49 #include "deprecated/gtksymboliccolorprivate.h"
52 * SECTION:gtkstylecontext
53 * @Short_description: Rendering UI elements
54 * @Title: GtkStyleContext
56 * #GtkStyleContext is an object that stores styling information affecting
57 * a widget defined by #GtkWidgetPath.
59 * In order to construct the final style information, #GtkStyleContext
60 * queries information from all attached #GtkStyleProviders. Style providers
61 * can be either attached explicitly to the context through
62 * gtk_style_context_add_provider(), or to the screen through
63 * gtk_style_context_add_provider_for_screen(). The resulting style is a
64 * combination of all providers' information in priority order.
66 * For GTK+ widgets, any #GtkStyleContext returned by
67 * gtk_widget_get_style_context() will already have a #GtkWidgetPath, a
68 * #GdkScreen and RTL/LTR information set. The style context will be also
69 * updated automatically if any of these settings change on the widget.
71 * If you are using the theming layer standalone, you will need to set a
72 * widget path and a screen yourself to the created style context through
73 * gtk_style_context_set_path() and gtk_style_context_set_screen(), as well
74 * as updating the context yourself using gtk_style_context_invalidate()
75 * whenever any of the conditions change, such as a change in the
76 * #GtkSettings:gtk-theme-name setting or a hierarchy change in the rendered
79 * <refsect2 id="gtkstylecontext-animations">
80 * <title>Transition animations</title>
82 * #GtkStyleContext has built-in support for state change transitions.
83 * Note that these animations respect the #GtkSettings:gtk-enable-animations
87 * For simple widgets where state changes affect the whole widget area,
88 * calling gtk_style_context_notify_state_change() with a %NULL region
89 * is sufficient to trigger the transition animation. And GTK+ already
90 * does that when gtk_widget_set_state() or gtk_widget_set_state_flags()
94 * If a widget needs to declare several animatable regions (i.e. not
95 * affecting the whole widget area), its #GtkWidget::draw signal handler
96 * needs to wrap the render operations for the different regions with
97 * calls to gtk_style_context_push_animatable_region() and
98 * gtk_style_context_pop_animatable_region(). These functions take an
99 * identifier for the region which must be unique within the style context.
100 * For simple widgets with a fixed set of animatable regions, using an
101 * enumeration works well:
104 * <title>Using an enumeration to identify animatable regions</title>
115 * spin_button_draw (GtkWidget *widget,
118 * GtkStyleContext *context;
120 * context = gtk_widget_get_style_context (widget);
122 * gtk_style_context_push_animatable_region (context,
123 * GUINT_TO_POINTER (REGION_ENTRY));
125 * gtk_render_background (cr, 0, 0, 100, 30);
126 * gtk_render_frame (cr, 0, 0, 100, 30);
128 * gtk_style_context_pop_animatable_region (context);
135 * For complex widgets with an arbitrary number of animatable regions, it
136 * is up to the implementation to come up with a way to uniquely identify
137 * each animatable region. Using pointers to internal structs is one way
141 * <title>Using struct pointers to identify animatable regions</title>
144 * notebook_draw_tab (GtkWidget *widget,
145 * NotebookPage *page,
148 * gtk_style_context_push_animatable_region (context, page);
149 * gtk_render_extension (cr, page->x, page->y, page->width, page->height);
150 * gtk_style_context_pop_animatable_region (context);
155 * The widget also needs to notify the style context about a state change
156 * for a given animatable region so the animation is triggered.
159 * <title>Triggering a state change animation on a region</title>
162 * notebook_motion_notify (GtkWidget *widget,
163 * GdkEventMotion *event)
165 * GtkStyleContext *context;
166 * NotebookPage *page;
168 * context = gtk_widget_get_style_context (widget);
169 * page = find_page_under_pointer (widget, event);
170 * gtk_style_context_notify_state_change (context,
171 * gtk_widget_get_window (widget),
173 * GTK_STATE_PRELIGHT,
180 * gtk_style_context_notify_state_change() accepts %NULL region IDs as a
181 * special value, in this case, the whole widget area will be updated
185 * <refsect2 id="gtkstylecontext-classes">
186 * <title>Style classes and regions</title>
188 * Widgets can add style classes to their context, which can be used
189 * to associate different styles by class (see <xref linkend="gtkcssprovider-selectors"/>). Theme engines can also use style classes to vary their
190 * rendering. GTK+ has a number of predefined style classes:
191 * #GTK_STYLE_CLASS_CELL,
192 * #GTK_STYLE_CLASS_ENTRY,
193 * #GTK_STYLE_CLASS_BUTTON,
194 * #GTK_STYLE_CLASS_COMBOBOX_ENTRY,
195 * #GTK_STYLE_CLASS_CALENDAR,
196 * #GTK_STYLE_CLASS_SLIDER,
197 * #GTK_STYLE_CLASS_BACKGROUND,
198 * #GTK_STYLE_CLASS_RUBBERBAND,
199 * #GTK_STYLE_CLASS_TOOLTIP,
200 * #GTK_STYLE_CLASS_MENU,
201 * #GTK_STYLE_CLASS_MENUBAR,
202 * #GTK_STYLE_CLASS_MENUITEM,
203 * #GTK_STYLE_CLASS_TOOLBAR,
204 * #GTK_STYLE_CLASS_PRIMARY_TOOLBAR,
205 * #GTK_STYLE_CLASS_INLINE_TOOLBAR,
206 * #GTK_STYLE_CLASS_RADIO,
207 * #GTK_STYLE_CLASS_CHECK,
208 * #GTK_STYLE_CLASS_TROUGH,
209 * #GTK_STYLE_CLASS_SCROLLBAR,
210 * #GTK_STYLE_CLASS_SCALE,
211 * #GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE,
212 * #GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW,
213 * #GTK_STYLE_CLASS_HEADER,
214 * #GTK_STYLE_CLASS_ACCELERATOR,
215 * #GTK_STYLE_CLASS_GRIP,
216 * #GTK_STYLE_CLASS_DOCK,
217 * #GTK_STYLE_CLASS_PROGRESSBAR,
218 * #GTK_STYLE_CLASS_SPINNER,
219 * #GTK_STYLE_CLASS_EXPANDER,
220 * #GTK_STYLE_CLASS_SPINBUTTON,
221 * #GTK_STYLE_CLASS_NOTEBOOK,
222 * #GTK_STYLE_CLASS_VIEW,
223 * #GTK_STYLE_CLASS_SIDEBAR,
224 * #GTK_STYLE_CLASS_IMAGE,
225 * #GTK_STYLE_CLASS_HIGHLIGHT,
226 * #GTK_STYLE_CLASS_FRAME,
227 * #GTK_STYLE_CLASS_DND,
228 * #GTK_STYLE_CLASS_PANE_SEPARATOR,
229 * #GTK_STYLE_CLASS_SEPARATOR,
230 * #GTK_STYLE_CLASS_INFO,
231 * #GTK_STYLE_CLASS_WARNING,
232 * #GTK_STYLE_CLASS_QUESTION,
233 * #GTK_STYLE_CLASS_ERROR,
234 * #GTK_STYLE_CLASS_HORIZONTAL,
235 * #GTK_STYLE_CLASS_VERTICAL,
236 * #GTK_STYLE_CLASS_TOP,
237 * #GTK_STYLE_CLASS_BOTTOM,
238 * #GTK_STYLE_CLASS_LEFT,
239 * #GTK_STYLE_CLASS_RIGHT,
242 * Widgets can also add regions with flags to their context.
243 * The regions used by GTK+ widgets are:
248 * <entry>Region</entry>
249 * <entry>Flags</entry>
250 * <entry>Macro</entry>
251 * <entry>Used by</entry>
257 * <entry>even, odd</entry>
258 * <entry>GTK_STYLE_REGION_ROW</entry>
259 * <entry>#GtkTreeView</entry>
262 * <entry>column</entry>
263 * <entry>first, last, sorted</entry>
264 * <entry>GTK_STYLE_REGION_COLUMN</entry>
265 * <entry>#GtkTreeView</entry>
268 * <entry>column-header</entry>
270 * <entry>GTK_STYLE_REGION_COLUMN_HEADER</entry>
275 * <entry>even, odd, first, last</entry>
276 * <entry>GTK_STYLE_REGION_TAB</entry>
277 * <entry>#GtkNotebook</entry>
284 * <refsect2 id="gtkstylecontext-custom-styling">
285 * <title>Custom styling in UI libraries and applications</title>
287 * If you are developing a library with custom #GtkWidget<!-- -->s that
288 * render differently than standard components, you may need to add a
289 * #GtkStyleProvider yourself with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK
290 * priority, either a #GtkCssProvider or a custom object implementing the
291 * #GtkStyleProvider interface. This way theming engines may still attempt
292 * to style your UI elements in a different way if needed so.
295 * If you are using custom styling on an applications, you probably want then
296 * to make your style information prevail to the theme's, so you must use
297 * a #GtkStyleProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
298 * priority, keep in mind that the user settings in
299 * <filename><replaceable>XDG_CONFIG_HOME</replaceable>/gtk-3.0/gtk.css</filename> will
300 * still take precedence over your changes, as it uses the
301 * %GTK_STYLE_PROVIDER_PRIORITY_USER priority.
304 * If a custom theming engine is needed, you probably want to implement a
305 * #GtkStyleProvider yourself so it points to your #GtkThemingEngine
306 * implementation, as #GtkCssProvider uses gtk_theming_engine_load()
307 * which loads the theming engine module from the standard paths.
312 /* When these change we do a full restyling. Otherwise we try to figure out
313 * if we need to change things. */
314 #define GTK_STYLE_CONTEXT_RADICAL_CHANGE (GTK_CSS_CHANGE_NAME | GTK_CSS_CHANGE_CLASS | GTK_CSS_CHANGE_SOURCE)
315 /* When these change we don't clear the cache. This takes more memory but makes
316 * things go faster. */
317 #define GTK_STYLE_CONTEXT_CACHED_CHANGE (GTK_CSS_CHANGE_STATE)
319 typedef struct GtkStyleInfo GtkStyleInfo;
320 typedef struct GtkRegion GtkRegion;
321 typedef struct PropertyValue PropertyValue;
322 typedef struct StyleData StyleData;
327 GtkRegionFlags flags;
341 GArray *style_classes;
343 GtkJunctionSides junction_sides;
344 GtkStateFlags state_flags;
350 GtkCssComputedValues *store;
351 GArray *property_cache;
355 struct _GtkStyleContextPrivate
359 GtkStyleCascade *cascade;
361 GtkStyleContext *animation_list_prev;
362 GtkStyleContext *animation_list_next;
364 GtkStyleContext *parent;
367 GtkWidgetPath *widget_path;
368 GHashTable *style_data;
371 GtkCssChange relevant_changes;
372 GtkCssChange pending_changes;
374 const GtkBitmask *invalidating_context;
390 static guint signals[LAST_SIGNAL] = { 0 };
391 static GtkStyleContext *_running_animations = NULL;
392 guint _running_animations_timer_id = 0;
394 static void gtk_style_context_finalize (GObject *object);
396 static void gtk_style_context_impl_set_property (GObject *object,
400 static void gtk_style_context_impl_get_property (GObject *object,
404 static StyleData *style_data_lookup (GtkStyleContext *context);
407 G_DEFINE_TYPE (GtkStyleContext, gtk_style_context, G_TYPE_OBJECT)
410 gtk_style_context_real_changed (GtkStyleContext *context)
412 GtkStyleContextPrivate *priv = context->priv;
415 _gtk_widget_style_context_invalidated (priv->widget);
419 gtk_style_context_class_init (GtkStyleContextClass *klass)
421 GObjectClass *object_class = G_OBJECT_CLASS (klass);
423 object_class->finalize = gtk_style_context_finalize;
424 object_class->set_property = gtk_style_context_impl_set_property;
425 object_class->get_property = gtk_style_context_impl_get_property;
427 klass->changed = gtk_style_context_real_changed;
430 g_signal_new (I_("changed"),
431 G_TYPE_FROM_CLASS (object_class),
433 G_STRUCT_OFFSET (GtkStyleContextClass, changed),
435 g_cclosure_marshal_VOID__VOID,
438 g_object_class_install_property (object_class,
440 g_param_spec_object ("screen",
442 P_("The associated GdkScreen"),
444 GTK_PARAM_READWRITE));
445 g_object_class_install_property (object_class,
447 g_param_spec_enum ("direction",
449 P_("Text direction"),
450 GTK_TYPE_TEXT_DIRECTION,
452 GTK_PARAM_READWRITE));
454 * GtkStyleContext:parent:
456 * Sets or gets the style context's parent. See gtk_style_context_set_parent()
461 g_object_class_install_property (object_class,
463 g_param_spec_object ("parent",
465 P_("The parent style context"),
466 GTK_TYPE_STYLE_CONTEXT,
467 GTK_PARAM_READWRITE));
469 g_type_class_add_private (object_class, sizeof (GtkStyleContextPrivate));
473 style_data_new (void)
477 data = g_slice_new0 (StyleData);
484 clear_property_cache (StyleData *data)
488 if (!data->property_cache)
491 for (i = 0; i < data->property_cache->len; i++)
493 PropertyValue *node = &g_array_index (data->property_cache, PropertyValue, i);
495 g_param_spec_unref (node->pspec);
496 g_value_unset (&node->value);
499 g_array_free (data->property_cache, TRUE);
500 data->property_cache = NULL;
504 style_data_ref (StyleData *style_data)
506 style_data->ref_count++;
512 style_data_unref (StyleData *data)
516 if (data->ref_count > 0)
519 g_object_unref (data->store);
520 clear_property_cache (data);
522 g_slice_free (StyleData, data);
526 style_data_is_animating (StyleData *style_data)
528 return !_gtk_css_computed_values_is_static (style_data->store);
531 static GtkStyleInfo *
532 style_info_new (void)
536 info = g_slice_new0 (GtkStyleInfo);
537 info->style_classes = g_array_new (FALSE, FALSE, sizeof (GQuark));
538 info->regions = g_array_new (FALSE, FALSE, sizeof (GtkRegion));
544 style_info_set_data (GtkStyleInfo *info,
547 if (info->data == data)
551 style_data_ref (data);
554 style_data_unref (info->data);
560 style_info_free (GtkStyleInfo *info)
562 style_info_set_data (info, NULL);
563 g_array_free (info->style_classes, TRUE);
564 g_array_free (info->regions, TRUE);
565 g_slice_free (GtkStyleInfo, info);
568 static GtkStyleInfo *
569 style_info_pop (GtkStyleInfo *info)
571 GtkStyleInfo *next = info->next;
573 style_info_free (info);
578 static GtkStyleInfo *
579 style_info_copy (GtkStyleInfo *info)
583 copy = style_info_new ();
584 g_array_insert_vals (copy->style_classes, 0,
585 info->style_classes->data,
586 info->style_classes->len);
588 g_array_insert_vals (copy->regions, 0,
593 copy->junction_sides = info->junction_sides;
594 copy->state_flags = info->state_flags;
595 style_info_set_data (copy, info->data);
601 style_info_hash (gconstpointer elem)
603 const GtkStyleInfo *info;
608 for (i = 0; i < info->style_classes->len; i++)
610 hash += g_array_index (info->style_classes, GQuark, i);
614 for (i = 0; i < info->regions->len; i++)
618 region = &g_array_index (info->regions, GtkRegion, i);
619 hash += region->class_quark;
620 hash += region->flags;
624 return hash ^ info->state_flags;
628 style_info_equal (gconstpointer elem1,
631 const GtkStyleInfo *info1, *info2;
636 if (info1->state_flags != info2->state_flags)
639 if (info1->junction_sides != info2->junction_sides)
642 if (info1->style_classes->len != info2->style_classes->len)
645 if (memcmp (info1->style_classes->data,
646 info2->style_classes->data,
647 info1->style_classes->len * sizeof (GQuark)) != 0)
650 if (info1->regions->len != info2->regions->len)
653 if (memcmp (info1->regions->data,
654 info2->regions->data,
655 info1->regions->len * sizeof (GtkRegion)) != 0)
662 gtk_style_context_cascade_changed (GtkStyleCascade *cascade,
663 GtkStyleContext *context)
665 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_SOURCE);
669 gtk_style_context_set_cascade (GtkStyleContext *context,
670 GtkStyleCascade *cascade)
672 GtkStyleContextPrivate *priv;
674 priv = context->priv;
676 if (priv->cascade == cascade)
681 g_object_ref (cascade);
682 g_signal_connect (cascade,
683 "-gtk-private-changed",
684 G_CALLBACK (gtk_style_context_cascade_changed),
690 g_signal_handlers_disconnect_by_func (priv->cascade,
691 gtk_style_context_cascade_changed,
693 g_object_unref (priv->cascade);
696 priv->cascade = cascade;
699 gtk_style_context_cascade_changed (cascade, context);
703 gtk_style_context_init (GtkStyleContext *style_context)
705 GtkStyleContextPrivate *priv;
707 priv = style_context->priv = G_TYPE_INSTANCE_GET_PRIVATE (style_context,
708 GTK_TYPE_STYLE_CONTEXT,
709 GtkStyleContextPrivate);
711 priv->style_data = g_hash_table_new_full (style_info_hash,
713 (GDestroyNotify) style_info_free,
714 (GDestroyNotify) style_data_unref);
716 priv->screen = gdk_screen_get_default ();
717 priv->relevant_changes = GTK_CSS_CHANGE_ANY;
719 /* Create default info store */
720 priv->info = style_info_new ();
721 priv->info->state_flags = GTK_STATE_FLAG_DIR_LTR;
723 gtk_style_context_set_cascade (style_context,
724 _gtk_style_cascade_get_for_screen (priv->screen));
728 gtk_style_context_do_animations (gpointer unused)
730 GtkStyleContext *context;
732 for (context = _running_animations;
734 context = context->priv->animation_list_next)
736 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANIMATE);
743 gtk_style_context_is_animating (GtkStyleContext *context)
745 GtkStyleContextPrivate *priv = context->priv;
747 return priv->animation_list_prev != NULL
748 || _running_animations == context;
752 gtk_style_context_stop_animating (GtkStyleContext *context)
754 GtkStyleContextPrivate *priv = context->priv;
756 if (!gtk_style_context_is_animating (context))
759 if (priv->animation_list_prev == NULL)
761 _running_animations = priv->animation_list_next;
763 if (_running_animations == NULL)
765 /* we were the last animation */
766 g_source_remove (_running_animations_timer_id);
767 _running_animations_timer_id = 0;
771 priv->animation_list_prev->priv->animation_list_next = priv->animation_list_next;
773 if (priv->animation_list_next)
774 priv->animation_list_next->priv->animation_list_prev = priv->animation_list_prev;
776 priv->animation_list_next = NULL;
777 priv->animation_list_prev = NULL;
781 gtk_style_context_start_animating (GtkStyleContext *context)
783 GtkStyleContextPrivate *priv = context->priv;
785 if (gtk_style_context_is_animating (context))
788 if (_running_animations == NULL)
790 _running_animations_timer_id = gdk_threads_add_timeout (25,
791 gtk_style_context_do_animations,
793 _running_animations = context;
797 priv->animation_list_next = _running_animations;
798 _running_animations->priv->animation_list_prev = context;
799 _running_animations = context;
804 gtk_style_context_should_animate (GtkStyleContext *context)
806 GtkStyleContextPrivate *priv;
810 priv = context->priv;
812 if (priv->widget == NULL)
815 if (!gtk_widget_get_mapped (priv->widget))
818 data = style_data_lookup (context);
819 if (!style_data_is_animating (data))
822 g_object_get (gtk_widget_get_settings (context->priv->widget),
823 "gtk-enable-animations", &animate,
830 _gtk_style_context_update_animating (GtkStyleContext *context)
832 if (gtk_style_context_should_animate (context))
833 gtk_style_context_start_animating (context);
835 gtk_style_context_stop_animating (context);
839 gtk_style_context_finalize (GObject *object)
841 GtkStyleContextPrivate *priv;
842 GtkStyleContext *style_context;
844 style_context = GTK_STYLE_CONTEXT (object);
845 priv = style_context->priv;
847 gtk_style_context_stop_animating (style_context);
849 /* children hold a reference to us */
850 g_assert (priv->children == NULL);
852 gtk_style_context_set_parent (style_context, NULL);
854 gtk_style_context_set_cascade (style_context, NULL);
856 if (priv->widget_path)
857 gtk_widget_path_free (priv->widget_path);
859 g_hash_table_destroy (priv->style_data);
862 priv->info = style_info_pop (priv->info);
864 G_OBJECT_CLASS (gtk_style_context_parent_class)->finalize (object);
868 gtk_style_context_impl_set_property (GObject *object,
873 GtkStyleContext *style_context;
875 style_context = GTK_STYLE_CONTEXT (object);
880 gtk_style_context_set_screen (style_context,
881 g_value_get_object (value));
884 G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
885 gtk_style_context_set_direction (style_context,
886 g_value_get_enum (value));
887 G_GNUC_END_IGNORE_DEPRECATIONS;
890 gtk_style_context_set_parent (style_context,
891 g_value_get_object (value));
894 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
900 gtk_style_context_impl_get_property (GObject *object,
905 GtkStyleContext *style_context;
906 GtkStyleContextPrivate *priv;
908 style_context = GTK_STYLE_CONTEXT (object);
909 priv = style_context->priv;
914 g_value_set_object (value, priv->screen);
917 G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
918 g_value_set_enum (value, gtk_style_context_get_direction (style_context));
919 G_GNUC_END_IGNORE_DEPRECATIONS;
922 g_value_set_object (value, priv->parent);
925 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
930 static GtkWidgetPath *
931 create_query_path (GtkStyleContext *context,
934 GtkStyleContextPrivate *priv;
938 priv = context->priv;
939 path = priv->widget ? _gtk_widget_create_path (priv->widget) : gtk_widget_path_copy (priv->widget_path);
940 pos = gtk_widget_path_length (path) - 1;
942 /* Set widget regions */
943 for (i = 0; i < info->regions->len; i++)
947 region = &g_array_index (info->regions, GtkRegion, i);
948 gtk_widget_path_iter_add_region (path, pos,
949 g_quark_to_string (region->class_quark),
953 /* Set widget classes */
954 for (i = 0; i < info->style_classes->len; i++)
958 quark = g_array_index (info->style_classes, GQuark, i);
959 gtk_widget_path_iter_add_class (path, pos,
960 g_quark_to_string (quark));
967 build_properties (GtkStyleContext *context,
968 GtkCssComputedValues *values,
970 const GtkBitmask *relevant_changes)
972 GtkStyleContextPrivate *priv;
973 GtkCssMatcher matcher;
975 GtkCssLookup *lookup;
977 priv = context->priv;
979 path = create_query_path (context, info);
980 lookup = _gtk_css_lookup_new (relevant_changes);
982 if (_gtk_css_matcher_init (&matcher, path, info->state_flags))
983 _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
987 _gtk_css_lookup_resolve (lookup,
988 GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
990 priv->parent ? style_data_lookup (priv->parent)->store : NULL);
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 GtkStateFlags old_flags;
1486 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1488 old_flags = context->priv->info->state_flags;
1489 if (old_flags == flags)
1492 context->priv->info->state_flags = flags;
1494 if (((old_flags ^ flags) & (GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL)) &&
1495 !gtk_style_context_is_saved (context))
1496 g_object_notify (G_OBJECT (context), "direction");
1498 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_STATE);
1502 * gtk_style_context_get_state:
1503 * @context: a #GtkStyleContext
1505 * Returns the state used when rendering.
1507 * Returns: the state flags
1512 gtk_style_context_get_state (GtkStyleContext *context)
1514 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
1516 return context->priv->info->state_flags;
1520 * gtk_style_context_state_is_running:
1521 * @context: a #GtkStyleContext
1522 * @state: a widget state
1523 * @progress: (out): return location for the transition progress
1525 * Returns %TRUE if there is a transition animation running for the
1526 * current region (see gtk_style_context_push_animatable_region()).
1528 * If @progress is not %NULL, the animation progress will be returned
1529 * there, 0.0 means the state is closest to being unset, while 1.0 means
1530 * it's closest to being set. This means transition animation will
1531 * run from 0 to 1 when @state is being set and from 1 to 0 when
1534 * Returns: %TRUE if there is a running transition animation for @state.
1538 * Deprecated: 3.6: This function always returns %FALSE
1541 gtk_style_context_state_is_running (GtkStyleContext *context,
1545 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1551 * gtk_style_context_set_path:
1552 * @context: a #GtkStyleContext
1553 * @path: a #GtkWidgetPath
1555 * Sets the #GtkWidgetPath used for style matching. As a
1556 * consequence, the style will be regenerated to match
1557 * the new given path.
1559 * If you are using a #GtkStyleContext returned from
1560 * gtk_widget_get_style_context(), you do not need to call
1566 gtk_style_context_set_path (GtkStyleContext *context,
1567 GtkWidgetPath *path)
1569 GtkStyleContextPrivate *priv;
1571 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1572 g_return_if_fail (path != NULL);
1574 priv = context->priv;
1575 g_return_if_fail (priv->widget == NULL);
1577 if (priv->widget_path)
1579 gtk_widget_path_free (priv->widget_path);
1580 priv->widget_path = NULL;
1584 priv->widget_path = gtk_widget_path_copy (path);
1586 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY);
1590 * gtk_style_context_get_path:
1591 * @context: a #GtkStyleContext
1593 * Returns the widget path used for style matching.
1595 * Returns: (transfer none): A #GtkWidgetPath
1599 const GtkWidgetPath *
1600 gtk_style_context_get_path (GtkStyleContext *context)
1602 GtkStyleContextPrivate *priv;
1604 priv = context->priv;
1606 return gtk_widget_get_path (priv->widget);
1608 return priv->widget_path;
1612 * gtk_style_context_set_parent:
1613 * @context: a #GtkStyleContext
1614 * @parent: (allow-none): the new parent or %NULL
1616 * Sets the parent style context for @context. The parent style
1617 * context is used to implement
1618 * <ulink url="http://www.w3.org/TR/css3-cascade/#inheritance">inheritance</ulink>
1621 * If you are using a #GtkStyleContext returned from
1622 * gtk_widget_get_style_context(), the parent will be set for you.
1627 gtk_style_context_set_parent (GtkStyleContext *context,
1628 GtkStyleContext *parent)
1630 GtkStyleContextPrivate *priv;
1632 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1633 g_return_if_fail (parent == NULL || GTK_IS_STYLE_CONTEXT (parent));
1635 priv = context->priv;
1637 if (priv->parent == parent)
1642 parent->priv->children = g_slist_prepend (parent->priv->children, context);
1643 g_object_ref (parent);
1645 gtk_style_context_set_invalid (parent, TRUE);
1650 priv->parent->priv->children = g_slist_remove (priv->parent->priv->children, context);
1651 g_object_unref (priv->parent);
1654 priv->parent = parent;
1656 g_object_notify (G_OBJECT (context), "parent");
1657 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY_PARENT | GTK_CSS_CHANGE_ANY_SIBLING);
1661 * gtk_style_context_get_parent:
1662 * @context: a #GtkStyleContext
1664 * Gets the parent context set via gtk_style_context_set_parent().
1665 * See that function for details.
1667 * Returns: (transfer none): the parent context or %NULL
1672 gtk_style_context_get_parent (GtkStyleContext *context)
1674 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1676 return context->priv->parent;
1680 * gtk_style_context_save:
1681 * @context: a #GtkStyleContext
1683 * Saves the @context state, so all modifications done through
1684 * gtk_style_context_add_class(), gtk_style_context_remove_class(),
1685 * gtk_style_context_add_region(), gtk_style_context_remove_region()
1686 * or gtk_style_context_set_junction_sides() can be reverted in one
1687 * go through gtk_style_context_restore().
1692 gtk_style_context_save (GtkStyleContext *context)
1694 GtkStyleContextPrivate *priv;
1696 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1698 priv = context->priv;
1700 priv->info = style_info_copy (priv->info);
1701 /* Need to unset animations here because we can not know what style
1702 * class potential transitions came from once we save().
1704 if (priv->info->data && style_data_is_animating (priv->info->data))
1705 style_info_set_data (priv->info, NULL);
1709 * gtk_style_context_restore:
1710 * @context: a #GtkStyleContext
1712 * Restores @context state to a previous stage.
1713 * See gtk_style_context_save().
1718 gtk_style_context_restore (GtkStyleContext *context)
1720 GtkStyleContextPrivate *priv;
1722 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1724 priv = context->priv;
1726 priv->info = style_info_pop (priv->info);
1730 g_warning ("Unpaired gtk_style_context_restore() call");
1732 /* Create default region */
1733 priv->info = style_info_new ();
1738 style_class_find (GArray *array,
1743 gboolean found = FALSE;
1749 if (!array || array->len == 0)
1753 max = array->len - 1;
1759 mid = (min + max) / 2;
1760 item = g_array_index (array, GQuark, mid);
1762 if (class_quark == item)
1767 else if (class_quark > item)
1768 min = pos = mid + 1;
1775 while (!found && min <= max);
1784 region_find (GArray *array,
1789 gboolean found = FALSE;
1795 if (!array || array->len == 0)
1799 max = array->len - 1;
1805 mid = (min + max) / 2;
1806 region = &g_array_index (array, GtkRegion, mid);
1808 if (region->class_quark == class_quark)
1813 else if (region->class_quark > class_quark)
1814 min = pos = mid + 1;
1821 while (!found && min <= max);
1830 * gtk_style_context_add_class:
1831 * @context: a #GtkStyleContext
1832 * @class_name: class name to use in styling
1834 * Adds a style class to @context, so posterior calls to
1835 * gtk_style_context_get() or any of the gtk_render_*()
1836 * functions will make use of this new class for styling.
1838 * In the CSS file format, a #GtkEntry defining an "entry"
1839 * class, would be matched by:
1842 * GtkEntry.entry { ... }
1845 * While any widget defining an "entry" class would be
1854 gtk_style_context_add_class (GtkStyleContext *context,
1855 const gchar *class_name)
1857 GtkStyleContextPrivate *priv;
1862 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1863 g_return_if_fail (class_name != NULL);
1865 priv = context->priv;
1866 class_quark = g_quark_from_string (class_name);
1870 if (!style_class_find (info->style_classes, class_quark, &position))
1872 g_array_insert_val (info->style_classes, position, class_quark);
1874 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_CLASS);
1879 * gtk_style_context_remove_class:
1880 * @context: a #GtkStyleContext
1881 * @class_name: class name to remove
1883 * Removes @class_name from @context.
1888 gtk_style_context_remove_class (GtkStyleContext *context,
1889 const gchar *class_name)
1891 GtkStyleContextPrivate *priv;
1896 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1897 g_return_if_fail (class_name != NULL);
1899 class_quark = g_quark_try_string (class_name);
1904 priv = context->priv;
1908 if (style_class_find (info->style_classes, class_quark, &position))
1910 g_array_remove_index (info->style_classes, position);
1912 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_CLASS);
1917 * gtk_style_context_has_class:
1918 * @context: a #GtkStyleContext
1919 * @class_name: a class name
1921 * Returns %TRUE if @context currently has defined the
1924 * Returns: %TRUE if @context has @class_name defined
1929 gtk_style_context_has_class (GtkStyleContext *context,
1930 const gchar *class_name)
1932 GtkStyleContextPrivate *priv;
1936 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1937 g_return_val_if_fail (class_name != NULL, FALSE);
1939 class_quark = g_quark_try_string (class_name);
1944 priv = context->priv;
1948 if (style_class_find (info->style_classes, class_quark, NULL))
1955 * gtk_style_context_list_classes:
1956 * @context: a #GtkStyleContext
1958 * Returns the list of classes currently defined in @context.
1960 * Returns: (transfer container) (element-type utf8): a #GList of
1961 * strings with the currently defined classes. The contents
1962 * of the list are owned by GTK+, but you must free the list
1963 * itself with g_list_free() when you are done with it.
1968 gtk_style_context_list_classes (GtkStyleContext *context)
1970 GtkStyleContextPrivate *priv;
1972 GList *classes = NULL;
1975 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1977 priv = context->priv;
1981 for (i = 0; i < info->style_classes->len; i++)
1985 quark = g_array_index (info->style_classes, GQuark, i);
1986 classes = g_list_prepend (classes, (gchar *) g_quark_to_string (quark));
1993 * gtk_style_context_list_regions:
1994 * @context: a #GtkStyleContext
1996 * Returns the list of regions currently defined in @context.
1998 * Returns: (transfer container) (element-type utf8): a #GList of
1999 * strings with the currently defined regions. The contents
2000 * of the list are owned by GTK+, but you must free the list
2001 * itself with g_list_free() when you are done with it.
2006 gtk_style_context_list_regions (GtkStyleContext *context)
2008 GtkStyleContextPrivate *priv;
2010 GList *classes = NULL;
2013 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2015 priv = context->priv;
2019 for (i = 0; i < info->regions->len; i++)
2022 const gchar *class_name;
2024 region = &g_array_index (info->regions, GtkRegion, i);
2026 class_name = g_quark_to_string (region->class_quark);
2027 classes = g_list_prepend (classes, (gchar *) class_name);
2034 _gtk_style_context_check_region_name (const gchar *str)
2036 g_return_val_if_fail (str != NULL, FALSE);
2038 if (!g_ascii_islower (str[0]))
2044 !g_ascii_islower (*str))
2054 * gtk_style_context_add_region:
2055 * @context: a #GtkStyleContext
2056 * @region_name: region name to use in styling
2057 * @flags: flags that apply to the region
2059 * Adds a region to @context, so posterior calls to
2060 * gtk_style_context_get() or any of the gtk_render_*()
2061 * functions will make use of this new region for styling.
2063 * In the CSS file format, a #GtkTreeView defining a "row"
2064 * region, would be matched by:
2067 * GtkTreeView row { ... }
2070 * Pseudo-classes are used for matching @flags, so the two
2073 * GtkTreeView row:nth-child(even) { ... }
2074 * GtkTreeView row:nth-child(odd) { ... }
2077 * would apply to even and odd rows, respectively.
2079 * <note><para>Region names must only contain lowercase letters
2080 * and '-', starting always with a lowercase letter.</para></note>
2085 gtk_style_context_add_region (GtkStyleContext *context,
2086 const gchar *region_name,
2087 GtkRegionFlags flags)
2089 GtkStyleContextPrivate *priv;
2091 GQuark region_quark;
2094 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2095 g_return_if_fail (region_name != NULL);
2096 g_return_if_fail (_gtk_style_context_check_region_name (region_name));
2098 priv = context->priv;
2099 region_quark = g_quark_from_string (region_name);
2103 if (!region_find (info->regions, region_quark, &position))
2107 region.class_quark = region_quark;
2108 region.flags = flags;
2110 g_array_insert_val (info->regions, position, region);
2112 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_REGION);
2117 * gtk_style_context_remove_region:
2118 * @context: a #GtkStyleContext
2119 * @region_name: region name to unset
2121 * Removes a region from @context.
2126 gtk_style_context_remove_region (GtkStyleContext *context,
2127 const gchar *region_name)
2129 GtkStyleContextPrivate *priv;
2131 GQuark region_quark;
2134 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2135 g_return_if_fail (region_name != NULL);
2137 region_quark = g_quark_try_string (region_name);
2142 priv = context->priv;
2146 if (region_find (info->regions, region_quark, &position))
2148 g_array_remove_index (info->regions, position);
2150 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_REGION);
2155 * gtk_style_context_has_region:
2156 * @context: a #GtkStyleContext
2157 * @region_name: a region name
2158 * @flags_return: (out) (allow-none): return location for region flags
2160 * Returns %TRUE if @context has the region defined.
2161 * If @flags_return is not %NULL, it is set to the flags
2162 * affecting the region.
2164 * Returns: %TRUE if region is defined
2169 gtk_style_context_has_region (GtkStyleContext *context,
2170 const gchar *region_name,
2171 GtkRegionFlags *flags_return)
2173 GtkStyleContextPrivate *priv;
2175 GQuark region_quark;
2178 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2179 g_return_val_if_fail (region_name != NULL, FALSE);
2184 region_quark = g_quark_try_string (region_name);
2189 priv = context->priv;
2193 if (region_find (info->regions, region_quark, &position))
2199 region = &g_array_index (info->regions, GtkRegion, position);
2200 *flags_return = region->flags;
2209 style_property_values_cmp (gconstpointer bsearch_node1,
2210 gconstpointer bsearch_node2)
2212 const PropertyValue *val1 = bsearch_node1;
2213 const PropertyValue *val2 = bsearch_node2;
2215 if (val1->widget_type != val2->widget_type)
2216 return val1->widget_type < val2->widget_type ? -1 : 1;
2218 if (val1->pspec != val2->pspec)
2219 return val1->pspec < val2->pspec ? -1 : 1;
2221 if (val1->state != val2->state)
2222 return val1->state < val2->state ? -1 : 1;
2228 _gtk_style_context_peek_property (GtkStyleContext *context,
2231 StyleData *data = style_data_lookup (context);
2233 return _gtk_css_computed_values_get_value (data->store, property_id);
2237 _gtk_style_context_peek_style_property (GtkStyleContext *context,
2239 GtkStateFlags state,
2242 GtkStyleContextPrivate *priv;
2243 PropertyValue *pcache, key = { 0 };
2247 priv = context->priv;
2249 data = style_data_lookup_for_state (context, state);
2251 key.widget_type = widget_type;
2255 /* need value cache array */
2256 if (!data->property_cache)
2257 data->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
2260 pcache = bsearch (&key,
2261 data->property_cache->data, data->property_cache->len,
2262 sizeof (PropertyValue), style_property_values_cmp);
2264 return &pcache->value;
2268 while (i < data->property_cache->len &&
2269 style_property_values_cmp (&key, &g_array_index (data->property_cache, PropertyValue, i)) >= 0)
2272 g_array_insert_val (data->property_cache, i, key);
2273 pcache = &g_array_index (data->property_cache, PropertyValue, i);
2275 /* cache miss, initialize value type, then set contents */
2276 g_param_spec_ref (pcache->pspec);
2277 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2279 if (priv->widget || priv->widget_path)
2281 GtkWidgetPath *widget_path = priv->widget ? _gtk_widget_create_path (priv->widget) : priv->widget_path;
2283 if (gtk_style_provider_get_style_property (GTK_STYLE_PROVIDER (priv->cascade),
2285 state, pspec, &pcache->value))
2287 G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
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, _gtk_symbolic_color_get_css_value (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);
2325 G_GNUC_END_IGNORE_DEPRECATIONS;
2328 gtk_widget_path_free (widget_path);
2330 return &pcache->value;
2334 gtk_widget_path_free (widget_path);
2337 /* not supplied by any provider, revert to default */
2338 g_param_value_set_default (pspec, &pcache->value);
2340 return &pcache->value;
2344 * gtk_style_context_get_style_property:
2345 * @context: a #GtkStyleContext
2346 * @property_name: the name of the widget style property
2347 * @value: Return location for the property value
2349 * Gets the value for a widget style property.
2351 * When @value is no longer needed, g_value_unset() must be called
2352 * to free any allocated memory.
2355 gtk_style_context_get_style_property (GtkStyleContext *context,
2356 const gchar *property_name,
2359 GtkStyleContextPrivate *priv;
2360 GtkWidgetClass *widget_class;
2361 GtkStateFlags state;
2363 const GValue *peek_value;
2366 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2367 g_return_if_fail (property_name != NULL);
2368 g_return_if_fail (value != NULL);
2370 priv = context->priv;
2374 widget_type = G_OBJECT_TYPE (priv->widget);
2378 if (!priv->widget_path)
2381 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2383 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2385 g_warning ("%s: can't get style properties for non-widget class `%s'",
2387 g_type_name (widget_type));
2392 widget_class = g_type_class_ref (widget_type);
2393 pspec = gtk_widget_class_find_style_property (widget_class, property_name);
2394 g_type_class_unref (widget_class);
2398 g_warning ("%s: widget class `%s' has no style property named `%s'",
2400 g_type_name (widget_type),
2405 state = gtk_style_context_get_state (context);
2406 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2409 if (G_VALUE_TYPE (value) == G_VALUE_TYPE (peek_value))
2410 g_value_copy (peek_value, value);
2411 else if (g_value_type_transformable (G_VALUE_TYPE (peek_value), G_VALUE_TYPE (value)))
2412 g_value_transform (peek_value, value);
2414 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
2416 G_VALUE_TYPE_NAME (peek_value),
2417 G_VALUE_TYPE_NAME (value));
2421 * gtk_style_context_get_style_valist:
2422 * @context: a #GtkStyleContext
2423 * @args: va_list of property name/return location pairs, followed by %NULL
2425 * Retrieves several widget style properties from @context according to the
2431 gtk_style_context_get_style_valist (GtkStyleContext *context,
2434 GtkStyleContextPrivate *priv;
2435 const gchar *prop_name;
2436 GtkStateFlags state;
2439 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2441 prop_name = va_arg (args, const gchar *);
2442 priv = context->priv;
2446 widget_type = G_OBJECT_TYPE (priv->widget);
2450 if (!priv->widget_path)
2453 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2455 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2457 g_warning ("%s: can't get style properties for non-widget class `%s'",
2459 g_type_name (widget_type));
2464 state = gtk_style_context_get_state (context);
2468 GtkWidgetClass *widget_class;
2470 const GValue *peek_value;
2473 widget_class = g_type_class_ref (widget_type);
2474 pspec = gtk_widget_class_find_style_property (widget_class, prop_name);
2475 g_type_class_unref (widget_class);
2479 g_warning ("%s: widget class `%s' has no style property named `%s'",
2481 g_type_name (widget_type),
2486 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2489 G_VALUE_LCOPY (peek_value, args, 0, &error);
2493 g_warning ("can't retrieve style property `%s' of type `%s': %s",
2495 G_VALUE_TYPE_NAME (peek_value),
2501 prop_name = va_arg (args, const gchar *);
2506 * gtk_style_context_get_style:
2507 * @context: a #GtkStyleContext
2508 * @...: property name /return value pairs, followed by %NULL
2510 * Retrieves several widget style properties from @context according to the
2516 gtk_style_context_get_style (GtkStyleContext *context,
2521 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2523 va_start (args, context);
2524 gtk_style_context_get_style_valist (context, args);
2530 * gtk_style_context_lookup_icon_set:
2531 * @context: a #GtkStyleContext
2532 * @stock_id: an icon name
2534 * Looks up @stock_id in the icon factories associated to @context and
2535 * the default icon factory, returning an icon set if found, otherwise
2538 * Returns: (transfer none): The looked up %GtkIconSet, or %NULL
2541 gtk_style_context_lookup_icon_set (GtkStyleContext *context,
2542 const gchar *stock_id)
2544 GtkStyleContextPrivate *priv;
2546 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2547 g_return_val_if_fail (stock_id != NULL, NULL);
2549 priv = context->priv;
2550 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
2552 return gtk_icon_factory_lookup_default (stock_id);
2556 * gtk_style_context_set_screen:
2557 * @context: a #GtkStyleContext
2558 * @screen: a #GdkScreen
2560 * Attaches @context to the given screen.
2562 * The screen is used to add style information from 'global' style
2563 * providers, such as the screens #GtkSettings instance.
2565 * If you are using a #GtkStyleContext returned from
2566 * gtk_widget_get_style_context(), you do not need to
2567 * call this yourself.
2572 gtk_style_context_set_screen (GtkStyleContext *context,
2575 GtkStyleContextPrivate *priv;
2577 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2578 g_return_if_fail (GDK_IS_SCREEN (screen));
2580 priv = context->priv;
2581 if (priv->screen == screen)
2584 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
2586 gtk_style_context_set_cascade (context, _gtk_style_cascade_get_for_screen (screen));
2590 _gtk_style_cascade_set_parent (priv->cascade, _gtk_style_cascade_get_for_screen (screen));
2593 priv->screen = screen;
2595 g_object_notify (G_OBJECT (context), "screen");
2599 * gtk_style_context_get_screen:
2600 * @context: a #GtkStyleContext
2602 * Returns the #GdkScreen to which @context is attached.
2604 * Returns: (transfer none): a #GdkScreen.
2607 gtk_style_context_get_screen (GtkStyleContext *context)
2609 GtkStyleContextPrivate *priv;
2611 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2613 priv = context->priv;
2614 return priv->screen;
2618 * gtk_style_context_set_direction:
2619 * @context: a #GtkStyleContext
2620 * @direction: the new direction.
2622 * Sets the reading direction for rendering purposes.
2624 * If you are using a #GtkStyleContext returned from
2625 * gtk_widget_get_style_context(), you do not need to
2626 * call this yourself.
2630 * Deprecated: 3.8: Use gtk_style_context_set_state() with
2631 * #GTK_STATE_FLAG_DIR_LTR and #GTK_STATE_FLAG_DIR_RTL
2635 gtk_style_context_set_direction (GtkStyleContext *context,
2636 GtkTextDirection direction)
2638 GtkStateFlags state;
2640 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2642 state = gtk_style_context_get_state (context);
2643 state &= ~(GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL);
2647 case GTK_TEXT_DIR_LTR:
2648 state |= GTK_STATE_FLAG_DIR_LTR;
2651 case GTK_TEXT_DIR_RTL:
2652 state |= GTK_STATE_FLAG_DIR_RTL;
2655 case GTK_TEXT_DIR_NONE:
2660 gtk_style_context_set_state (context, state);
2664 * gtk_style_context_get_direction:
2665 * @context: a #GtkStyleContext
2667 * Returns the widget direction used for rendering.
2669 * Returns: the widget direction
2673 * Deprecated: 3.8: Use gtk_style_context_get_state() and
2674 * check for #GTK_STATE_FLAG_DIR_LTR and
2675 * #GTK_STATE_FLAG_DIR_RTL instead.
2678 gtk_style_context_get_direction (GtkStyleContext *context)
2680 GtkStateFlags state;
2682 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), GTK_TEXT_DIR_LTR);
2684 state = gtk_style_context_get_state (context);
2686 if (state & GTK_STATE_FLAG_DIR_LTR)
2687 return GTK_TEXT_DIR_LTR;
2688 else if (state & GTK_STATE_FLAG_DIR_RTL)
2689 return GTK_TEXT_DIR_RTL;
2691 return GTK_TEXT_DIR_NONE;
2695 * gtk_style_context_set_junction_sides:
2696 * @context: a #GtkStyleContext
2697 * @sides: sides where rendered elements are visually connected to
2700 * Sets the sides where rendered elements (mostly through
2701 * gtk_render_frame()) will visually connect with other visual elements.
2703 * This is merely a hint that may or may not be honored
2704 * by theming engines.
2706 * Container widgets are expected to set junction hints as appropriate
2707 * for their children, so it should not normally be necessary to call
2708 * this function manually.
2713 gtk_style_context_set_junction_sides (GtkStyleContext *context,
2714 GtkJunctionSides sides)
2716 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2718 context->priv->info->junction_sides = sides;
2722 * gtk_style_context_get_junction_sides:
2723 * @context: a #GtkStyleContext
2725 * Returns the sides where rendered elements connect visually with others.
2727 * Returns: the junction sides
2732 gtk_style_context_get_junction_sides (GtkStyleContext *context)
2734 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
2736 return context->priv->info->junction_sides;
2740 _gtk_style_context_resolve_color (GtkStyleContext *context,
2743 GtkCssDependencies *dependencies)
2747 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2748 g_return_val_if_fail (color != NULL, FALSE);
2749 g_return_val_if_fail (result != NULL, FALSE);
2751 val = _gtk_css_color_value_resolve (color,
2752 GTK_STYLE_PROVIDER_PRIVATE (context->priv->cascade),
2753 _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR),
2754 GTK_CSS_DEPENDS_ON_COLOR,
2759 *result = *_gtk_css_rgba_value_get_rgba (val);
2760 _gtk_css_value_unref (val);
2765 * gtk_style_context_lookup_color:
2766 * @context: a #GtkStyleContext
2767 * @color_name: color name to lookup
2768 * @color: (out): Return location for the looked up color
2770 * Looks up and resolves a color name in the @context color map.
2772 * Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
2775 gtk_style_context_lookup_color (GtkStyleContext *context,
2776 const gchar *color_name,
2781 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2782 g_return_val_if_fail (color_name != NULL, FALSE);
2783 g_return_val_if_fail (color != NULL, FALSE);
2785 value = _gtk_style_provider_private_get_color (GTK_STYLE_PROVIDER_PRIVATE (context->priv->cascade), color_name);
2789 return _gtk_style_context_resolve_color (context, value, color, NULL);
2793 * gtk_style_context_notify_state_change:
2794 * @context: a #GtkStyleContext
2795 * @window: a #GdkWindow
2796 * @region_id: (allow-none): animatable region to notify on, or %NULL.
2797 * See gtk_style_context_push_animatable_region()
2798 * @state: state to trigger transition for
2799 * @state_value: %TRUE if @state is the state we are changing to,
2800 * %FALSE if we are changing away from it
2802 * Notifies a state change on @context, so if the current style makes use
2803 * of transition animations, one will be started so all rendered elements
2804 * under @region_id are animated for state @state being set to value
2807 * The @window parameter is used in order to invalidate the rendered area
2808 * as the animation runs, so make sure it is the same window that is being
2809 * rendered on by the gtk_render_*() functions.
2811 * If @region_id is %NULL, all rendered elements using @context will be
2812 * affected by this state transition.
2814 * As a practical example, a #GtkButton notifying a state transition on
2815 * the prelight state:
2817 * gtk_style_context_notify_state_change (context,
2818 * gtk_widget_get_window (widget),
2820 * GTK_STATE_PRELIGHT,
2821 * button->in_button);
2824 * Can be handled in the CSS file like this:
2827 * background-color: #f00
2831 * background-color: #fff;
2832 * transition: 200ms linear
2836 * This combination will animate the button background from red to white
2837 * if a pointer enters the button, and back to red if the pointer leaves
2840 * Note that @state is used when finding the transition parameters, which
2841 * is why the style places the transition under the :hover pseudo-class.
2845 * Deprecated: 3.6: This function does nothing.
2848 gtk_style_context_notify_state_change (GtkStyleContext *context,
2852 gboolean state_value)
2854 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2855 g_return_if_fail (GDK_IS_WINDOW (window));
2856 g_return_if_fail (state > GTK_STATE_NORMAL && state <= GTK_STATE_FOCUSED);
2857 g_return_if_fail (context->priv->widget != NULL || context->priv->widget_path != NULL);
2861 * gtk_style_context_cancel_animations:
2862 * @context: a #GtkStyleContext
2863 * @region_id: (allow-none): animatable region to stop, or %NULL.
2864 * See gtk_style_context_push_animatable_region()
2866 * Stops all running animations for @region_id and all animatable
2867 * regions underneath.
2869 * A %NULL @region_id will stop all ongoing animations in @context,
2870 * when dealing with a #GtkStyleContext obtained through
2871 * gtk_widget_get_style_context(), this is normally done for you
2872 * in all circumstances you would expect all widget to be stopped,
2873 * so this should be only used in complex widgets with different
2874 * animatable regions.
2878 * Deprecated: 3.6: This function does nothing.
2881 gtk_style_context_cancel_animations (GtkStyleContext *context,
2884 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2888 * gtk_style_context_scroll_animations:
2889 * @context: a #GtkStyleContext
2890 * @window: a #GdkWindow used previously in
2891 * gtk_style_context_notify_state_change()
2892 * @dx: Amount to scroll in the X axis
2893 * @dy: Amount to scroll in the Y axis
2895 * This function is analogous to gdk_window_scroll(), and
2896 * should be called together with it so the invalidation
2897 * areas for any ongoing animation are scrolled together
2902 * Deprecated: 3.6: This function does nothing.
2905 gtk_style_context_scroll_animations (GtkStyleContext *context,
2910 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2911 g_return_if_fail (GDK_IS_WINDOW (window));
2915 * gtk_style_context_push_animatable_region:
2916 * @context: a #GtkStyleContext
2917 * @region_id: unique identifier for the animatable region
2919 * Pushes an animatable region, so all further gtk_render_*() calls between
2920 * this call and the following gtk_style_context_pop_animatable_region()
2921 * will potentially show transition animations for this region if
2922 * gtk_style_context_notify_state_change() is called for a given state,
2923 * and the current theme/style defines transition animations for state
2926 * The @region_id used must be unique in @context so the theming engine
2927 * can uniquely identify rendered elements subject to a state transition.
2931 * Deprecated: 3.6: This function does nothing.
2934 gtk_style_context_push_animatable_region (GtkStyleContext *context,
2937 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2938 g_return_if_fail (region_id != NULL);
2942 * gtk_style_context_pop_animatable_region:
2943 * @context: a #GtkStyleContext
2945 * Pops an animatable region from @context.
2946 * See gtk_style_context_push_animatable_region().
2950 * Deprecated: 3.6: This function does nothing.
2953 gtk_style_context_pop_animatable_region (GtkStyleContext *context)
2955 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2959 gtk_style_context_clear_cache (GtkStyleContext *context)
2961 GtkStyleContextPrivate *priv;
2964 priv = context->priv;
2966 for (info = priv->info; info; info = info->next)
2968 style_info_set_data (info, NULL);
2970 g_hash_table_remove_all (priv->style_data);
2974 gtk_style_context_update_cache (GtkStyleContext *context,
2975 const GtkBitmask *parent_changes)
2977 GtkStyleContextPrivate *priv;
2978 GHashTableIter iter;
2979 gpointer key, value;
2981 if (_gtk_bitmask_is_empty (parent_changes))
2984 priv = context->priv;
2986 g_hash_table_iter_init (&iter, priv->style_data);
2987 while (g_hash_table_iter_next (&iter, &key, &value))
2989 GtkStyleInfo *info = key;
2990 StyleData *data = value;
2991 GtkBitmask *changes;
2993 changes = _gtk_css_computed_values_compute_dependencies (data->store, parent_changes);
2995 if (!_gtk_bitmask_is_empty (changes))
2996 build_properties (context, data->store, info, changes);
2998 _gtk_bitmask_free (changes);
3003 gtk_style_context_do_invalidate (GtkStyleContext *context,
3004 const GtkBitmask *changes)
3006 GtkStyleContextPrivate *priv;
3008 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3010 priv = context->priv;
3012 /* Avoid reentrancy */
3013 if (priv->invalidating_context)
3016 priv->invalidating_context = changes;
3018 g_signal_emit (context, signals[CHANGED], 0);
3020 priv->invalidating_context = NULL;
3024 gtk_style_context_update_animations (GtkStyleContext *context,
3027 GtkBitmask *differences;
3028 StyleData *style_data;
3030 style_data = style_data_lookup (context);
3032 differences = _gtk_css_computed_values_advance (style_data->store,
3035 if (_gtk_css_computed_values_is_static (style_data->store))
3036 _gtk_style_context_update_animating (context);
3042 gtk_style_context_needs_full_revalidate (GtkStyleContext *context,
3043 GtkCssChange change)
3045 GtkStyleContextPrivate *priv = context->priv;
3047 /* Try to avoid invalidating if we can */
3048 if (change & GTK_STYLE_CONTEXT_RADICAL_CHANGE)
3050 priv->relevant_changes = GTK_CSS_CHANGE_ANY;
3054 if (priv->relevant_changes == GTK_CSS_CHANGE_ANY)
3056 GtkWidgetPath *path;
3057 GtkCssMatcher matcher, superset;
3059 path = create_query_path (context, priv->info);
3060 if (_gtk_css_matcher_init (&matcher, path, priv->info->state_flags))
3062 _gtk_css_matcher_superset_init (&superset, &matcher, GTK_STYLE_CONTEXT_RADICAL_CHANGE & ~GTK_CSS_CHANGE_SOURCE);
3063 priv->relevant_changes = _gtk_style_provider_private_get_change (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
3067 priv->relevant_changes = 0;
3069 priv->relevant_changes &= ~GTK_STYLE_CONTEXT_RADICAL_CHANGE;
3071 gtk_widget_path_unref (path);
3075 if (priv->relevant_changes & change)
3082 gtk_style_context_should_create_transitions (GtkStyleContext *context)
3084 GtkStyleContextPrivate *priv;
3087 priv = context->priv;
3089 if (priv->widget == NULL)
3092 if (!gtk_widget_get_mapped (priv->widget))
3095 g_object_get (gtk_widget_get_settings (context->priv->widget),
3096 "gtk-enable-animations", &animate,
3103 _gtk_style_context_validate (GtkStyleContext *context,
3105 GtkCssChange change,
3106 const GtkBitmask *parent_changes)
3108 GtkStyleContextPrivate *priv;
3111 GtkBitmask *changes;
3114 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3116 priv = context->priv;
3118 change |= priv->pending_changes;
3120 /* If you run your application with
3121 * GTK_DEBUG=no-css-cache
3122 * every invalidation will purge the cache and completely query
3123 * everything anew form the cache. This is slow (in particular
3124 * when animating), but useful for figuring out bugs.
3126 * We achieve that by pretending that everything that could have
3127 * changed has and so we of course totally need to redo everything.
3129 * Note that this also completely revalidates child widgets all
3132 if (G_UNLIKELY (gtk_get_debug_flags () & GTK_DEBUG_NO_CSS_CACHE))
3133 change = GTK_CSS_CHANGE_ANY;
3135 if (!priv->invalid && change == 0 && _gtk_bitmask_is_empty (parent_changes))
3138 priv->pending_changes = 0;
3139 gtk_style_context_set_invalid (context, FALSE);
3143 current = style_data_ref (info->data);
3147 /* Try to avoid invalidating if we can */
3148 if (current == NULL ||
3149 gtk_style_context_needs_full_revalidate (context, change))
3153 if ((priv->relevant_changes & change) & ~GTK_STYLE_CONTEXT_CACHED_CHANGE)
3155 gtk_style_context_clear_cache (context);
3159 gtk_style_context_update_cache (context, parent_changes);
3160 style_info_set_data (info, NULL);
3163 data = style_data_lookup (context);
3165 _gtk_css_computed_values_create_animations (data->store,
3166 priv->parent ? style_data_lookup (priv->parent)->store : NULL,
3168 GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
3169 current && gtk_style_context_should_create_transitions (context) ? current->store : NULL);
3170 if (_gtk_css_computed_values_is_static (data->store))
3171 change &= ~GTK_CSS_CHANGE_ANIMATE;
3173 change |= GTK_CSS_CHANGE_ANIMATE;
3174 _gtk_style_context_update_animating (context);
3178 changes = _gtk_css_computed_values_get_difference (data->store, current->store);
3180 /* In the case where we keep the cache, we want unanimated values */
3181 _gtk_css_computed_values_cancel_animations (current->store);
3185 changes = _gtk_bitmask_new ();
3186 changes = _gtk_bitmask_invert_range (changes, 0, _gtk_css_style_property_get_n_properties ());
3191 changes = _gtk_css_computed_values_compute_dependencies (current->store, parent_changes);
3193 gtk_style_context_update_cache (context, parent_changes);
3197 style_data_unref (current);
3199 if (change & GTK_CSS_CHANGE_ANIMATE &&
3200 gtk_style_context_is_animating (context))
3202 GtkBitmask *animation_changes;
3204 animation_changes = gtk_style_context_update_animations (context, timestamp);
3205 changes = _gtk_bitmask_union (changes, animation_changes);
3206 _gtk_bitmask_free (animation_changes);
3209 if (!_gtk_bitmask_is_empty (changes) || (change & GTK_CSS_CHANGE_FORCE_INVALIDATE))
3210 gtk_style_context_do_invalidate (context, changes);
3212 change = _gtk_css_change_for_child (change);
3213 for (list = priv->children; list; list = list->next)
3215 _gtk_style_context_validate (list->data, timestamp, change, changes);
3218 _gtk_bitmask_free (changes);
3222 _gtk_style_context_queue_invalidate (GtkStyleContext *context,
3223 GtkCssChange change)
3225 GtkStyleContextPrivate *priv;
3227 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3228 g_return_if_fail (change != 0);
3230 priv = context->priv;
3232 if (priv->widget != NULL)
3234 priv->pending_changes |= change;
3235 gtk_style_context_set_invalid (context, TRUE);
3237 else if (priv->widget_path == NULL)
3239 gtk_style_context_invalidate (context);
3244 * gtk_style_context_invalidate:
3245 * @context: a #GtkStyleContext.
3247 * Invalidates @context style information, so it will be reconstructed
3250 * If you're using a #GtkStyleContext returned from
3251 * gtk_widget_get_style_context(), you do not need to
3252 * call this yourself.
3257 gtk_style_context_invalidate (GtkStyleContext *context)
3259 GtkBitmask *changes;
3261 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3263 gtk_style_context_clear_cache (context);
3265 changes = _gtk_bitmask_new ();
3266 changes = _gtk_bitmask_invert_range (changes,
3268 _gtk_css_style_property_get_n_properties ());
3269 gtk_style_context_do_invalidate (context, changes);
3270 _gtk_bitmask_free (changes);
3274 corner_value_is_right_angle (GtkCssValue *value)
3276 return _gtk_css_corner_value_get_x (value, 100) <= 0.0 &&
3277 _gtk_css_corner_value_get_y (value, 100) <= 0.0;
3281 * gtk_style_context_set_background:
3282 * @context: a #GtkStyleContext
3283 * @window: a #GdkWindow
3285 * Sets the background of @window to the background pattern or
3286 * color specified in @context for its current state.
3291 gtk_style_context_set_background (GtkStyleContext *context,
3294 const GdkRGBA *color;
3296 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3297 g_return_if_fail (GDK_IS_WINDOW (window));
3299 /* This is a sophisitcated optimization.
3300 * If we know the GDK window's background will be opaque, we mark
3301 * it as opaque. This is so GDK can do all the optimizations it does
3302 * for opaque windows and be fast.
3303 * This is mainly used when scrolling.
3305 * We could indeed just set black instead of the color we have.
3307 color = _gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BACKGROUND_COLOR));
3309 if (color->alpha >= 1.0 &&
3310 corner_value_is_right_angle (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_TOP_LEFT_RADIUS)) &&
3311 corner_value_is_right_angle (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_TOP_RIGHT_RADIUS)) &&
3312 corner_value_is_right_angle (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_BOTTOM_RIGHT_RADIUS)) &&
3313 corner_value_is_right_angle (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_BOTTOM_LEFT_RADIUS)))
3315 gdk_window_set_background_rgba (window, color);
3319 GdkRGBA transparent = { 0.0, 0.0, 0.0, 0.0 };
3320 gdk_window_set_background_rgba (window, &transparent);
3325 * gtk_style_context_get_color:
3326 * @context: a #GtkStyleContext
3327 * @state: state to retrieve the color for
3328 * @color: (out): return value for the foreground color
3330 * Gets the foreground color for a given state.
3335 gtk_style_context_get_color (GtkStyleContext *context,
3336 GtkStateFlags state,
3341 g_return_if_fail (color != NULL);
3342 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3344 gtk_style_context_get (context,
3354 * gtk_style_context_get_background_color:
3355 * @context: a #GtkStyleContext
3356 * @state: state to retrieve the color for
3357 * @color: (out): return value for the background color
3359 * Gets the background color for a given state.
3364 gtk_style_context_get_background_color (GtkStyleContext *context,
3365 GtkStateFlags state,
3370 g_return_if_fail (color != NULL);
3371 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3373 gtk_style_context_get (context,
3375 "background-color", &c,
3383 * gtk_style_context_get_border_color:
3384 * @context: a #GtkStyleContext
3385 * @state: state to retrieve the color for
3386 * @color: (out): return value for the border color
3388 * Gets the border color for a given state.
3393 gtk_style_context_get_border_color (GtkStyleContext *context,
3394 GtkStateFlags state,
3399 g_return_if_fail (color != NULL);
3400 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3402 gtk_style_context_get (context,
3412 * gtk_style_context_get_border:
3413 * @context: a #GtkStyleContext
3414 * @state: state to retrieve the border for
3415 * @border: (out): return value for the border settings
3417 * Gets the border for a given state as a #GtkBorder.
3418 * See %GTK_STYLE_PROPERTY_BORDER_WIDTH.
3423 gtk_style_context_get_border (GtkStyleContext *context,
3424 GtkStateFlags state,
3427 int top, left, bottom, right;
3429 g_return_if_fail (border != NULL);
3430 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3432 gtk_style_context_get (context,
3434 "border-top-width", &top,
3435 "border-left-width", &left,
3436 "border-bottom-width", &bottom,
3437 "border-right-width", &right,
3441 border->left = left;
3442 border->bottom = bottom;
3443 border->right = right;
3447 * gtk_style_context_get_padding:
3448 * @context: a #GtkStyleContext
3449 * @state: state to retrieve the padding for
3450 * @padding: (out): return value for the padding settings
3452 * Gets the padding for a given state as a #GtkBorder.
3453 * See %GTK_STYLE_PROPERTY_PADDING.
3458 gtk_style_context_get_padding (GtkStyleContext *context,
3459 GtkStateFlags state,
3462 int top, left, bottom, right;
3464 g_return_if_fail (padding != NULL);
3465 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3467 gtk_style_context_get (context,
3469 "padding-top", &top,
3470 "padding-left", &left,
3471 "padding-bottom", &bottom,
3472 "padding-right", &right,
3476 padding->left = left;
3477 padding->bottom = bottom;
3478 padding->right = right;
3482 * gtk_style_context_get_margin:
3483 * @context: a #GtkStyleContext
3484 * @state: state to retrieve the border for
3485 * @margin: (out): return value for the margin settings
3487 * Gets the margin for a given state as a #GtkBorder.
3488 * See %GTK_STYLE_PROPERTY_MARGIN.
3493 gtk_style_context_get_margin (GtkStyleContext *context,
3494 GtkStateFlags state,
3497 int top, left, bottom, right;
3499 g_return_if_fail (margin != NULL);
3500 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3502 gtk_style_context_get (context,
3505 "margin-left", &left,
3506 "margin-bottom", &bottom,
3507 "margin-right", &right,
3511 margin->left = left;
3512 margin->bottom = bottom;
3513 margin->right = right;
3517 * gtk_style_context_get_font:
3518 * @context: a #GtkStyleContext
3519 * @state: state to retrieve the font for
3521 * Returns the font description for a given state. The returned
3522 * object is const and will remain valid until the
3523 * #GtkStyleContext::changed signal happens.
3525 * Returns: (transfer none): the #PangoFontDescription for the given
3526 * state. This object is owned by GTK+ and should not be
3531 * Deprecated: 3.8: Use gtk_style_context_get() for "font" or
3532 * subproperties instead.
3534 const PangoFontDescription *
3535 gtk_style_context_get_font (GtkStyleContext *context,
3536 GtkStateFlags state)
3538 GtkStyleContextPrivate *priv;
3540 PangoFontDescription *description, *previous;
3542 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
3544 priv = context->priv;
3545 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
3547 data = style_data_lookup_for_state (context, state);
3549 /* Yuck, fonts are created on-demand but we don't return a ref.
3550 * Do bad things to achieve this requirement */
3551 gtk_style_context_get (context, state, "font", &description, NULL);
3553 previous = g_object_get_data (G_OBJECT (data->store), "font-cache-for-get_font");
3557 pango_font_description_merge (previous, description, TRUE);
3558 pango_font_description_free (description);
3559 description = previous;
3563 g_object_set_data_full (G_OBJECT (data->store),
3564 "font-cache-for-get_font",
3566 (GDestroyNotify) pango_font_description_free);
3573 get_cursor_color (GtkStyleContext *context,
3577 GdkColor *style_color;
3579 gtk_style_context_get_style (context,
3580 primary ? "cursor-color" : "secondary-cursor-color",
3586 color->red = style_color->red / 65535.0;
3587 color->green = style_color->green / 65535.0;
3588 color->blue = style_color->blue / 65535.0;
3591 gdk_color_free (style_color);
3595 gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, color);
3601 gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &bg);
3603 color->red = (color->red + bg.red) * 0.5;
3604 color->green = (color->green + bg.green) * 0.5;
3605 color->blue = (color->blue + bg.blue) * 0.5;
3611 _gtk_style_context_get_cursor_color (GtkStyleContext *context,
3612 GdkRGBA *primary_color,
3613 GdkRGBA *secondary_color)
3616 get_cursor_color (context, TRUE, primary_color);
3618 if (secondary_color)
3619 get_cursor_color (context, FALSE, secondary_color);
3626 * @context: a #GtkStyleContext
3628 * @x: X origin of the rectangle
3629 * @y: Y origin of the rectangle
3630 * @width: rectangle width
3631 * @height: rectangle height
3633 * Renders a checkmark (as in a #GtkCheckButton).
3635 * The %GTK_STATE_FLAG_ACTIVE state determines whether the check is
3636 * on or off, and %GTK_STATE_FLAG_INCONSISTENT determines whether it
3637 * should be marked as undefined.
3640 * <title>Typical checkmark rendering</title>
3641 * <inlinegraphic fileref="checks.png" format="PNG"/>
3647 gtk_render_check (GtkStyleContext *context,
3654 GtkThemingEngineClass *engine_class;
3655 GtkThemingEngine *engine;
3657 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3658 g_return_if_fail (cr != NULL);
3660 if (width <= 0 || height <= 0)
3663 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3664 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3669 _gtk_theming_engine_set_context (engine, context);
3670 engine_class->render_check (engine, cr,
3671 x, y, width, height);
3677 * gtk_render_option:
3678 * @context: a #GtkStyleContext
3680 * @x: X origin of the rectangle
3681 * @y: Y origin of the rectangle
3682 * @width: rectangle width
3683 * @height: rectangle height
3685 * Renders an option mark (as in a #GtkRadioButton), the %GTK_STATE_FLAG_ACTIVE
3686 * state will determine whether the option is on or off, and
3687 * %GTK_STATE_FLAG_INCONSISTENT whether it should be marked as undefined.
3690 * <title>Typical option mark rendering</title>
3691 * <inlinegraphic fileref="options.png" format="PNG"/>
3697 gtk_render_option (GtkStyleContext *context,
3704 GtkThemingEngineClass *engine_class;
3705 GtkThemingEngine *engine;
3707 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3708 g_return_if_fail (cr != NULL);
3710 if (width <= 0 || height <= 0)
3713 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3714 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3718 _gtk_theming_engine_set_context (engine, context);
3719 engine_class->render_option (engine, cr,
3720 x, y, width, height);
3727 * @context: a #GtkStyleContext
3729 * @angle: arrow angle from 0 to 2 * %G_PI, being 0 the arrow pointing to the north
3730 * @x: X origin of the render area
3731 * @y: Y origin of the render area
3732 * @size: square side for render area
3734 * Renders an arrow pointing to @angle.
3737 * <title>Typical arrow rendering at 0, 1&solidus;2 π, π and 3&solidus;2 π</title>
3738 * <inlinegraphic fileref="arrows.png" format="PNG"/>
3744 gtk_render_arrow (GtkStyleContext *context,
3751 GtkThemingEngineClass *engine_class;
3752 GtkThemingEngine *engine;
3754 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3755 g_return_if_fail (cr != NULL);
3760 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3761 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3765 gtk_style_context_save (context);
3766 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ARROW);
3768 _gtk_theming_engine_set_context (engine, context);
3769 engine_class->render_arrow (engine, cr,
3772 gtk_style_context_restore (context);
3777 * gtk_render_background:
3778 * @context: a #GtkStyleContext
3780 * @x: X origin of the rectangle
3781 * @y: Y origin of the rectangle
3782 * @width: rectangle width
3783 * @height: rectangle height
3785 * Renders the background of an element.
3788 * <title>Typical background rendering, showing the effect of
3789 * <parameter>background-image</parameter>,
3790 * <parameter>border-width</parameter> and
3791 * <parameter>border-radius</parameter></title>
3792 * <inlinegraphic fileref="background.png" format="PNG"/>
3798 gtk_render_background (GtkStyleContext *context,
3805 GtkThemingEngineClass *engine_class;
3806 GtkThemingEngine *engine;
3808 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3809 g_return_if_fail (cr != NULL);
3811 if (width <= 0 || height <= 0)
3814 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3815 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3819 _gtk_theming_engine_set_context (engine, context);
3820 engine_class->render_background (engine, cr, x, y, width, height);
3827 * @context: a #GtkStyleContext
3829 * @x: X origin of the rectangle
3830 * @y: Y origin of the rectangle
3831 * @width: rectangle width
3832 * @height: rectangle height
3834 * Renders a frame around the rectangle defined by @x, @y, @width, @height.
3837 * <title>Examples of frame rendering, showing the effect of
3838 * <parameter>border-image</parameter>,
3839 * <parameter>border-color</parameter>,
3840 * <parameter>border-width</parameter>,
3841 * <parameter>border-radius</parameter> and
3843 * <inlinegraphic fileref="frames.png" format="PNG"/>
3849 gtk_render_frame (GtkStyleContext *context,
3856 GtkThemingEngineClass *engine_class;
3857 GtkThemingEngine *engine;
3859 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3860 g_return_if_fail (cr != NULL);
3862 if (width <= 0 || height <= 0)
3865 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3866 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3870 _gtk_theming_engine_set_context (engine, context);
3871 engine_class->render_frame (engine, cr, x, y, width, height);
3877 * gtk_render_expander:
3878 * @context: a #GtkStyleContext
3880 * @x: X origin of the rectangle
3881 * @y: Y origin of the rectangle
3882 * @width: rectangle width
3883 * @height: rectangle height
3885 * Renders an expander (as used in #GtkTreeView and #GtkExpander) in the area
3886 * defined by @x, @y, @width, @height. The state %GTK_STATE_FLAG_ACTIVE
3887 * determines whether the expander is collapsed or expanded.
3890 * <title>Typical expander rendering</title>
3891 * <inlinegraphic fileref="expanders.png" format="PNG"/>
3897 gtk_render_expander (GtkStyleContext *context,
3904 GtkThemingEngineClass *engine_class;
3905 GtkThemingEngine *engine;
3907 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3908 g_return_if_fail (cr != NULL);
3910 if (width <= 0 || height <= 0)
3913 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3914 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3918 _gtk_theming_engine_set_context (engine, context);
3919 engine_class->render_expander (engine, cr, x, y, width, height);
3926 * @context: a #GtkStyleContext
3928 * @x: X origin of the rectangle
3929 * @y: Y origin of the rectangle
3930 * @width: rectangle width
3931 * @height: rectangle height
3933 * Renders a focus indicator on the rectangle determined by @x, @y, @width, @height.
3935 * <title>Typical focus rendering</title>
3936 * <inlinegraphic fileref="focus.png" format="PNG"/>
3942 gtk_render_focus (GtkStyleContext *context,
3949 GtkThemingEngineClass *engine_class;
3950 GtkThemingEngine *engine;
3952 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3953 g_return_if_fail (cr != NULL);
3955 if (width <= 0 || height <= 0)
3958 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3959 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3963 _gtk_theming_engine_set_context (engine, context);
3964 engine_class->render_focus (engine, cr, x, y, width, height);
3970 * gtk_render_layout:
3971 * @context: a #GtkStyleContext
3975 * @layout: the #PangoLayout to render
3977 * Renders @layout on the coordinates @x, @y
3982 gtk_render_layout (GtkStyleContext *context,
3986 PangoLayout *layout)
3988 GtkThemingEngineClass *engine_class;
3989 GtkThemingEngine *engine;
3990 PangoRectangle extents;
3992 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3993 g_return_if_fail (PANGO_IS_LAYOUT (layout));
3994 g_return_if_fail (cr != NULL);
3996 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3997 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4001 pango_layout_get_extents (layout, &extents, NULL);
4003 _gtk_theming_engine_set_context (engine, context);
4004 engine_class->render_layout (engine, cr, x, y, layout);
4011 * @context: a #GtkStyleContext
4013 * @x0: X coordinate for the origin of the line
4014 * @y0: Y coordinate for the origin of the line
4015 * @x1: X coordinate for the end of the line
4016 * @y1: Y coordinate for the end of the line
4018 * Renders a line from (x0, y0) to (x1, y1).
4023 gtk_render_line (GtkStyleContext *context,
4030 GtkThemingEngineClass *engine_class;
4031 GtkThemingEngine *engine;
4033 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4034 g_return_if_fail (cr != NULL);
4036 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4037 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4041 _gtk_theming_engine_set_context (engine, context);
4042 engine_class->render_line (engine, cr, x0, y0, x1, y1);
4048 * gtk_render_slider:
4049 * @context: a #GtkStyleContext
4051 * @x: X origin of the rectangle
4052 * @y: Y origin of the rectangle
4053 * @width: rectangle width
4054 * @height: rectangle height
4055 * @orientation: orientation of the slider
4057 * Renders a slider (as in #GtkScale) in the rectangle defined by @x, @y,
4058 * @width, @height. @orientation defines whether the slider is vertical
4062 * <title>Typical slider rendering</title>
4063 * <inlinegraphic fileref="sliders.png" format="PNG"/>
4069 gtk_render_slider (GtkStyleContext *context,
4075 GtkOrientation orientation)
4077 GtkThemingEngineClass *engine_class;
4078 GtkThemingEngine *engine;
4080 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4081 g_return_if_fail (cr != NULL);
4083 if (width <= 0 || height <= 0)
4086 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4087 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4091 _gtk_theming_engine_set_context (engine, context);
4092 engine_class->render_slider (engine, cr, x, y, width, height, orientation);
4098 * gtk_render_frame_gap:
4099 * @context: a #GtkStyleContext
4101 * @x: X origin of the rectangle
4102 * @y: Y origin of the rectangle
4103 * @width: rectangle width
4104 * @height: rectangle height
4105 * @gap_side: side where the gap is
4106 * @xy0_gap: initial coordinate (X or Y depending on @gap_side) for the gap
4107 * @xy1_gap: end coordinate (X or Y depending on @gap_side) for the gap
4109 * Renders a frame around the rectangle defined by (@x, @y, @width, @height),
4110 * leaving a gap on one side. @xy0_gap and @xy1_gap will mean X coordinates
4111 * for %GTK_POS_TOP and %GTK_POS_BOTTOM gap sides, and Y coordinates for
4112 * %GTK_POS_LEFT and %GTK_POS_RIGHT.
4115 * <title>Typical rendering of a frame with a gap</title>
4116 * <inlinegraphic fileref="frame-gap.png" format="PNG"/>
4122 gtk_render_frame_gap (GtkStyleContext *context,
4128 GtkPositionType gap_side,
4132 GtkThemingEngineClass *engine_class;
4133 GtkThemingEngine *engine;
4135 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4136 g_return_if_fail (cr != NULL);
4137 g_return_if_fail (xy0_gap <= xy1_gap);
4138 g_return_if_fail (xy0_gap >= 0);
4140 if (width <= 0 || height <= 0)
4143 if (gap_side == GTK_POS_LEFT ||
4144 gap_side == GTK_POS_RIGHT)
4145 g_return_if_fail (xy1_gap <= height);
4147 g_return_if_fail (xy1_gap <= width);
4149 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4150 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4154 _gtk_theming_engine_set_context (engine, context);
4155 engine_class->render_frame_gap (engine, cr,
4156 x, y, width, height, gap_side,
4163 * gtk_render_extension:
4164 * @context: a #GtkStyleContext
4166 * @x: X origin of the rectangle
4167 * @y: Y origin of the rectangle
4168 * @width: rectangle width
4169 * @height: rectangle height
4170 * @gap_side: side where the gap is
4172 * Renders a extension (as in a #GtkNotebook tab) in the rectangle
4173 * defined by @x, @y, @width, @height. The side where the extension
4174 * connects to is defined by @gap_side.
4177 * <title>Typical extension rendering</title>
4178 * <inlinegraphic fileref="extensions.png" format="PNG"/>
4184 gtk_render_extension (GtkStyleContext *context,
4190 GtkPositionType gap_side)
4192 GtkThemingEngineClass *engine_class;
4193 GtkThemingEngine *engine;
4195 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4196 g_return_if_fail (cr != NULL);
4198 if (width <= 0 || height <= 0)
4201 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4202 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4206 _gtk_theming_engine_set_context (engine, context);
4207 engine_class->render_extension (engine, cr, x, y, width, height, gap_side);
4213 * gtk_render_handle:
4214 * @context: a #GtkStyleContext
4216 * @x: X origin of the rectangle
4217 * @y: Y origin of the rectangle
4218 * @width: rectangle width
4219 * @height: rectangle height
4221 * Renders a handle (as in #GtkHandleBox, #GtkPaned and
4222 * #GtkWindow<!-- -->'s resize grip), in the rectangle
4223 * determined by @x, @y, @width, @height.
4226 * <title>Handles rendered for the paned and grip classes</title>
4227 * <inlinegraphic fileref="handles.png" format="PNG"/>
4233 gtk_render_handle (GtkStyleContext *context,
4240 GtkThemingEngineClass *engine_class;
4241 GtkThemingEngine *engine;
4243 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4244 g_return_if_fail (cr != NULL);
4246 if (width <= 0 || height <= 0)
4249 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4250 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4254 _gtk_theming_engine_set_context (engine, context);
4255 engine_class->render_handle (engine, cr, x, y, width, height);
4261 * gtk_render_activity:
4262 * @context: a #GtkStyleContext
4264 * @x: X origin of the rectangle
4265 * @y: Y origin of the rectangle
4266 * @width: rectangle width
4267 * @height: rectangle height
4269 * Renders an activity area (Such as in #GtkSpinner or the
4270 * fill line in #GtkRange), the state %GTK_STATE_FLAG_ACTIVE
4271 * determines whether there is activity going on.
4276 gtk_render_activity (GtkStyleContext *context,
4283 GtkThemingEngineClass *engine_class;
4284 GtkThemingEngine *engine;
4286 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4287 g_return_if_fail (cr != NULL);
4289 if (width <= 0 || height <= 0)
4292 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4293 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4297 _gtk_theming_engine_set_context (engine, context);
4298 engine_class->render_activity (engine, cr, x, y, width, height);
4304 * gtk_render_icon_pixbuf:
4305 * @context: a #GtkStyleContext
4306 * @source: the #GtkIconSource specifying the icon to render
4307 * @size: (type int): the size to render the icon at. A size of (GtkIconSize) -1
4308 * means render at the size of the source and don't scale.
4310 * Renders the icon specified by @source at the given @size, returning the result
4313 * Returns: (transfer full): a newly-created #GdkPixbuf containing the rendered icon
4318 gtk_render_icon_pixbuf (GtkStyleContext *context,
4319 const GtkIconSource *source,
4322 GtkThemingEngineClass *engine_class;
4323 GtkThemingEngine *engine;
4325 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
4326 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
4327 g_return_val_if_fail (source != NULL, NULL);
4329 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4330 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4332 _gtk_theming_engine_set_context (engine, context);
4333 return engine_class->render_icon_pixbuf (engine, source, size);
4338 * @context: a #GtkStyleContext
4340 * @pixbuf: a #GdkPixbuf containing the icon to draw
4341 * @x: X position for the @pixbuf
4342 * @y: Y position for the @pixbuf
4344 * Renders the icon in @pixbuf at the specified @x and @y coordinates.
4349 gtk_render_icon (GtkStyleContext *context,
4355 GtkThemingEngineClass *engine_class;
4356 GtkThemingEngine *engine;
4358 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4359 g_return_if_fail (cr != NULL);
4361 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4362 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4366 _gtk_theming_engine_set_context (engine, context);
4367 engine_class->render_icon (engine, cr, pixbuf, x, y);
4373 draw_insertion_cursor (GtkStyleContext *context,
4378 gboolean is_primary,
4379 PangoDirection direction,
4380 gboolean draw_arrow)
4383 GdkRGBA primary_color;
4384 GdkRGBA secondary_color;
4385 gfloat cursor_aspect_ratio;
4391 _gtk_style_context_get_cursor_color (context, &primary_color, &secondary_color);
4392 gdk_cairo_set_source_rgba (cr, is_primary ? &primary_color : &secondary_color);
4394 /* When changing the shape or size of the cursor here,
4395 * propagate the changes to gtktextview.c:text_window_invalidate_cursors().
4398 gtk_style_context_get_style (context,
4399 "cursor-aspect-ratio", &cursor_aspect_ratio,
4402 stem_width = height * cursor_aspect_ratio + 1;
4404 /* put (stem_width % 2) on the proper side of the cursor */
4405 if (direction == PANGO_DIRECTION_LTR)
4406 offset = stem_width / 2;
4408 offset = stem_width - stem_width / 2;
4410 cairo_rectangle (cr, x - offset, y, stem_width, height);
4418 arrow_width = stem_width + 1;
4420 if (direction == PANGO_DIRECTION_RTL)
4422 ax = x - offset - 1;
4423 ay = y + height - arrow_width * 2 - arrow_width + 1;
4425 cairo_move_to (cr, ax, ay + 1);
4426 cairo_line_to (cr, ax - arrow_width, ay + arrow_width);
4427 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4430 else if (direction == PANGO_DIRECTION_LTR)
4432 ax = x + stem_width - offset;
4433 ay = y + height - arrow_width * 2 - arrow_width + 1;
4435 cairo_move_to (cr, ax, ay + 1);
4436 cairo_line_to (cr, ax + arrow_width, ay + arrow_width);
4437 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4441 g_assert_not_reached();
4448 * gtk_render_insertion_cursor:
4449 * @context: a #GtkStyleContext
4453 * @layout: the #PangoLayout of the text
4454 * @index: the index in the #PangoLayout
4455 * @direction: the #PangoDirection of the text
4457 * Draws a text caret on @cr at the specified index of @layout.
4462 gtk_render_insertion_cursor (GtkStyleContext *context,
4466 PangoLayout *layout,
4468 PangoDirection direction)
4470 GtkStyleContextPrivate *priv;
4471 gboolean split_cursor;
4472 PangoRectangle strong_pos, weak_pos;
4473 PangoRectangle *cursor1, *cursor2;
4474 PangoDirection keymap_direction;
4475 PangoDirection direction2;
4477 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4478 g_return_if_fail (cr != NULL);
4479 g_return_if_fail (PANGO_IS_LAYOUT (layout));
4480 g_return_if_fail (index >= 0);
4482 priv = context->priv;
4484 g_object_get (gtk_settings_get_for_screen (priv->screen),
4485 "gtk-split-cursor", &split_cursor,
4488 keymap_direction = gdk_keymap_get_direction (gdk_keymap_get_for_display (gdk_screen_get_display (priv->screen)));
4490 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4492 direction2 = PANGO_DIRECTION_NEUTRAL;
4496 cursor1 = &strong_pos;
4498 if (strong_pos.x != weak_pos.x || strong_pos.y != weak_pos.y)
4500 direction2 = (direction == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
4501 cursor2 = &weak_pos;
4506 if (keymap_direction == direction)
4507 cursor1 = &strong_pos;
4509 cursor1 = &weak_pos;
4512 draw_insertion_cursor (context,
4514 x + PANGO_PIXELS (cursor1->x),
4515 y + PANGO_PIXELS (cursor1->y),
4516 PANGO_PIXELS (cursor1->height),
4519 direction2 != PANGO_DIRECTION_NEUTRAL);
4521 if (direction2 != PANGO_DIRECTION_NEUTRAL)
4523 draw_insertion_cursor (context,
4525 x + PANGO_PIXELS (cursor2->x),
4526 y + PANGO_PIXELS (cursor2->y),
4527 PANGO_PIXELS (cursor2->height),
4535 * gtk_draw_insertion_cursor:
4536 * @widget: a #GtkWidget
4537 * @cr: cairo context to draw to
4538 * @location: location where to draw the cursor (@location->width is ignored)
4539 * @is_primary: if the cursor should be the primary cursor color.
4540 * @direction: whether the cursor is left-to-right or
4541 * right-to-left. Should never be #GTK_TEXT_DIR_NONE
4542 * @draw_arrow: %TRUE to draw a directional arrow on the
4543 * cursor. Should be %FALSE unless the cursor is split.
4545 * Draws a text caret on @cr at @location. This is not a style function
4546 * but merely a convenience function for drawing the standard cursor shape.
4549 * Deprecated: 3.4: Use gtk_render_insertion_cursor() instead.
4552 gtk_draw_insertion_cursor (GtkWidget *widget,
4554 const GdkRectangle *location,
4555 gboolean is_primary,
4556 GtkTextDirection direction,
4557 gboolean draw_arrow)
4559 GtkStyleContext *context;
4561 g_return_if_fail (GTK_IS_WIDGET (widget));
4562 g_return_if_fail (cr != NULL);
4563 g_return_if_fail (location != NULL);
4564 g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
4566 context = gtk_widget_get_style_context (widget);
4568 draw_insertion_cursor (context, cr,
4569 location->x, location->y, location->height,
4571 (direction == GTK_TEXT_DIR_RTL) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR,
4576 * _gtk_style_context_get_changes:
4577 * @context: the context to query
4579 * Queries the context for the changes for the currently executing
4580 * GtkStyleContext::invalidate signal. If no signal is currently
4581 * emitted, this function returns %NULL.
4583 * FIXME 4.0: Make this part of the signal.
4585 * Returns: %NULL or the currently invalidating changes
4588 _gtk_style_context_get_changes (GtkStyleContext *context)
4590 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
4592 return context->priv->invalidating_context;
4595 static AtkAttributeSet *
4596 add_attribute (AtkAttributeSet *attributes,
4597 AtkTextAttribute attr,
4602 at = g_new (AtkAttribute, 1);
4603 at->name = g_strdup (atk_text_attribute_get_name (attr));
4604 at->value = g_strdup (value);
4606 return g_slist_prepend (attributes, at);
4610 * _gtk_style_context_get_attributes:
4611 * @attributes: a #AtkAttributeSet to add attributes to
4612 * @context: the #GtkStyleContext to get attributes from
4613 * @flags: the state to use with @context
4615 * Adds the foreground and background color from @context to
4616 * @attributes, after translating them to ATK attributes.
4618 * This is a convenience function that can be used in
4619 * implementing the #AtkText interface in widgets.
4621 * Returns: the modified #AtkAttributeSet
4624 _gtk_style_context_get_attributes (AtkAttributeSet *attributes,
4625 GtkStyleContext *context,
4626 GtkStateFlags flags)
4631 gtk_style_context_get_background_color (context, flags, &color);
4632 value = g_strdup_printf ("%u,%u,%u",
4633 (guint) ceil (color.red * 65536 - color.red),
4634 (guint) ceil (color.green * 65536 - color.green),
4635 (guint) ceil (color.blue * 65536 - color.blue));
4636 attributes = add_attribute (attributes, ATK_TEXT_ATTR_BG_COLOR, value);
4639 gtk_style_context_get_color (context, flags, &color);
4640 value = g_strdup_printf ("%u,%u,%u",
4641 (guint) ceil (color.red * 65536 - color.red),
4642 (guint) ceil (color.green * 65536 - color.green),
4643 (guint) ceil (color.blue * 65536 - color.blue));
4644 attributes = add_attribute (attributes, ATK_TEXT_ATTR_FG_COLOR, value);
4651 gtk_gradient_resolve_for_context (GtkGradient *gradient,
4652 GtkStyleContext *context)
4654 GtkStyleContextPrivate *priv = context->priv;
4655 GtkCssDependencies ignored = 0;
4657 g_return_val_if_fail (gradient != NULL, NULL);
4658 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
4660 return _gtk_gradient_resolve_full (gradient,
4661 GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
4662 style_data_lookup (context)->store,
4663 priv->parent ? style_data_lookup (priv->parent)->store : NULL,