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 *parent;
364 GtkWidgetPath *widget_path;
365 GHashTable *style_data;
368 GdkFrameClock *frame_clock;
369 guint frame_clock_update_id;
371 GtkCssChange relevant_changes;
372 GtkCssChange pending_changes;
374 const GtkBitmask *invalidating_context;
392 static guint signals[LAST_SIGNAL] = { 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 static void gtk_style_context_disconnect_update (GtkStyleContext *context);
408 static void gtk_style_context_connect_update (GtkStyleContext *context);
410 G_DEFINE_TYPE (GtkStyleContext, gtk_style_context, G_TYPE_OBJECT)
413 gtk_style_context_real_changed (GtkStyleContext *context)
415 GtkStyleContextPrivate *priv = context->priv;
418 _gtk_widget_style_context_invalidated (priv->widget);
422 gtk_style_context_class_init (GtkStyleContextClass *klass)
424 GObjectClass *object_class = G_OBJECT_CLASS (klass);
426 object_class->finalize = gtk_style_context_finalize;
427 object_class->set_property = gtk_style_context_impl_set_property;
428 object_class->get_property = gtk_style_context_impl_get_property;
430 klass->changed = gtk_style_context_real_changed;
433 g_signal_new (I_("changed"),
434 G_TYPE_FROM_CLASS (object_class),
436 G_STRUCT_OFFSET (GtkStyleContextClass, changed),
438 g_cclosure_marshal_VOID__VOID,
441 g_object_class_install_property (object_class,
443 g_param_spec_object ("screen",
445 P_("The associated GdkScreen"),
447 GTK_PARAM_READWRITE));
448 g_object_class_install_property (object_class,
450 g_param_spec_object ("paint-clock",
452 P_("The associated GdkFrameClock"),
453 GDK_TYPE_FRAME_CLOCK,
454 GTK_PARAM_READWRITE));
455 g_object_class_install_property (object_class,
457 g_param_spec_enum ("direction",
459 P_("Text direction"),
460 GTK_TYPE_TEXT_DIRECTION,
462 GTK_PARAM_READWRITE));
464 * GtkStyleContext:parent:
466 * Sets or gets the style context's parent. See gtk_style_context_set_parent()
471 g_object_class_install_property (object_class,
473 g_param_spec_object ("parent",
475 P_("The parent style context"),
476 GTK_TYPE_STYLE_CONTEXT,
477 GTK_PARAM_READWRITE));
479 g_type_class_add_private (object_class, sizeof (GtkStyleContextPrivate));
483 style_data_new (void)
487 data = g_slice_new0 (StyleData);
494 clear_property_cache (StyleData *data)
498 if (!data->property_cache)
501 for (i = 0; i < data->property_cache->len; i++)
503 PropertyValue *node = &g_array_index (data->property_cache, PropertyValue, i);
505 g_param_spec_unref (node->pspec);
506 g_value_unset (&node->value);
509 g_array_free (data->property_cache, TRUE);
510 data->property_cache = NULL;
514 style_data_ref (StyleData *style_data)
516 style_data->ref_count++;
522 style_data_unref (StyleData *data)
526 if (data->ref_count > 0)
529 g_object_unref (data->store);
530 clear_property_cache (data);
532 g_slice_free (StyleData, data);
536 style_data_is_animating (StyleData *style_data)
538 return !_gtk_css_computed_values_is_static (style_data->store);
541 static GtkStyleInfo *
542 style_info_new (void)
546 info = g_slice_new0 (GtkStyleInfo);
547 info->style_classes = g_array_new (FALSE, FALSE, sizeof (GQuark));
548 info->regions = g_array_new (FALSE, FALSE, sizeof (GtkRegion));
554 style_info_set_data (GtkStyleInfo *info,
557 if (info->data == data)
561 style_data_ref (data);
564 style_data_unref (info->data);
570 style_info_free (GtkStyleInfo *info)
572 style_info_set_data (info, NULL);
573 g_array_free (info->style_classes, TRUE);
574 g_array_free (info->regions, TRUE);
575 g_slice_free (GtkStyleInfo, info);
578 static GtkStyleInfo *
579 style_info_pop (GtkStyleInfo *info)
581 GtkStyleInfo *next = info->next;
583 style_info_free (info);
588 static GtkStyleInfo *
589 style_info_copy (GtkStyleInfo *info)
593 copy = style_info_new ();
594 g_array_insert_vals (copy->style_classes, 0,
595 info->style_classes->data,
596 info->style_classes->len);
598 g_array_insert_vals (copy->regions, 0,
603 copy->junction_sides = info->junction_sides;
604 copy->state_flags = info->state_flags;
605 style_info_set_data (copy, info->data);
611 style_info_hash (gconstpointer elem)
613 const GtkStyleInfo *info;
618 for (i = 0; i < info->style_classes->len; i++)
620 hash += g_array_index (info->style_classes, GQuark, i);
624 for (i = 0; i < info->regions->len; i++)
628 region = &g_array_index (info->regions, GtkRegion, i);
629 hash += region->class_quark;
630 hash += region->flags;
634 return hash ^ info->state_flags;
638 style_info_equal (gconstpointer elem1,
641 const GtkStyleInfo *info1, *info2;
646 if (info1->state_flags != info2->state_flags)
649 if (info1->junction_sides != info2->junction_sides)
652 if (info1->style_classes->len != info2->style_classes->len)
655 if (memcmp (info1->style_classes->data,
656 info2->style_classes->data,
657 info1->style_classes->len * sizeof (GQuark)) != 0)
660 if (info1->regions->len != info2->regions->len)
663 if (memcmp (info1->regions->data,
664 info2->regions->data,
665 info1->regions->len * sizeof (GtkRegion)) != 0)
672 gtk_style_context_cascade_changed (GtkStyleCascade *cascade,
673 GtkStyleContext *context)
675 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_SOURCE);
679 gtk_style_context_set_cascade (GtkStyleContext *context,
680 GtkStyleCascade *cascade)
682 GtkStyleContextPrivate *priv;
684 priv = context->priv;
686 if (priv->cascade == cascade)
691 g_object_ref (cascade);
692 g_signal_connect (cascade,
693 "-gtk-private-changed",
694 G_CALLBACK (gtk_style_context_cascade_changed),
700 g_signal_handlers_disconnect_by_func (priv->cascade,
701 gtk_style_context_cascade_changed,
703 g_object_unref (priv->cascade);
706 priv->cascade = cascade;
709 gtk_style_context_cascade_changed (cascade, context);
713 gtk_style_context_init (GtkStyleContext *style_context)
715 GtkStyleContextPrivate *priv;
717 priv = style_context->priv = G_TYPE_INSTANCE_GET_PRIVATE (style_context,
718 GTK_TYPE_STYLE_CONTEXT,
719 GtkStyleContextPrivate);
721 priv->style_data = g_hash_table_new_full (style_info_hash,
723 (GDestroyNotify) style_info_free,
724 (GDestroyNotify) style_data_unref);
726 priv->screen = gdk_screen_get_default ();
727 priv->relevant_changes = GTK_CSS_CHANGE_ANY;
729 /* Create default info store */
730 priv->info = style_info_new ();
731 priv->info->state_flags = GTK_STATE_FLAG_DIR_LTR;
733 gtk_style_context_set_cascade (style_context,
734 _gtk_style_cascade_get_for_screen (priv->screen));
738 gtk_style_context_update (GdkFrameClock *clock,
739 GtkStyleContext *context)
741 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANIMATE);
745 gtk_style_context_is_animating (GtkStyleContext *context)
747 GtkStyleContextPrivate *priv = context->priv;
749 return priv->animating;
753 gtk_style_context_disconnect_update (GtkStyleContext *context)
755 GtkStyleContextPrivate *priv = context->priv;
757 if (priv->frame_clock && priv->frame_clock_update_id)
759 g_signal_handler_disconnect (priv->frame_clock,
760 priv->frame_clock_update_id);
761 priv->frame_clock_update_id = 0;
762 gdk_frame_clock_end_updating (priv->frame_clock);
767 gtk_style_context_connect_update (GtkStyleContext *context)
769 GtkStyleContextPrivate *priv = context->priv;
771 if (priv->frame_clock && priv->frame_clock_update_id == 0)
773 priv->frame_clock_update_id = g_signal_connect (priv->frame_clock,
775 G_CALLBACK (gtk_style_context_update),
777 gdk_frame_clock_begin_updating (priv->frame_clock);
782 gtk_style_context_stop_animating (GtkStyleContext *context)
784 GtkStyleContextPrivate *priv = context->priv;
786 if (!gtk_style_context_is_animating (context))
789 priv->animating = FALSE;
791 gtk_style_context_disconnect_update (context);
795 gtk_style_context_start_animating (GtkStyleContext *context)
797 GtkStyleContextPrivate *priv = context->priv;
799 if (gtk_style_context_is_animating (context))
802 priv->animating = TRUE;
804 gtk_style_context_connect_update (context);
808 gtk_style_context_should_animate (GtkStyleContext *context)
810 GtkStyleContextPrivate *priv;
814 priv = context->priv;
816 if (priv->widget == NULL)
819 if (!gtk_widget_get_mapped (priv->widget))
822 data = style_data_lookup (context);
823 if (!style_data_is_animating (data))
826 g_object_get (gtk_widget_get_settings (context->priv->widget),
827 "gtk-enable-animations", &animate,
834 _gtk_style_context_update_animating (GtkStyleContext *context)
836 if (gtk_style_context_should_animate (context))
837 gtk_style_context_start_animating (context);
839 gtk_style_context_stop_animating (context);
843 gtk_style_context_finalize (GObject *object)
845 GtkStyleContextPrivate *priv;
846 GtkStyleContext *style_context;
848 style_context = GTK_STYLE_CONTEXT (object);
849 priv = style_context->priv;
851 gtk_style_context_stop_animating (style_context);
853 /* children hold a reference to us */
854 g_assert (priv->children == NULL);
856 gtk_style_context_set_parent (style_context, NULL);
858 gtk_style_context_set_cascade (style_context, NULL);
860 if (priv->widget_path)
861 gtk_widget_path_free (priv->widget_path);
863 g_hash_table_destroy (priv->style_data);
866 priv->info = style_info_pop (priv->info);
868 G_OBJECT_CLASS (gtk_style_context_parent_class)->finalize (object);
872 gtk_style_context_impl_set_property (GObject *object,
877 GtkStyleContext *style_context;
879 style_context = GTK_STYLE_CONTEXT (object);
884 gtk_style_context_set_screen (style_context,
885 g_value_get_object (value));
888 G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
889 gtk_style_context_set_direction (style_context,
890 g_value_get_enum (value));
891 G_GNUC_END_IGNORE_DEPRECATIONS;
893 case PROP_FRAME_CLOCK:
894 gtk_style_context_set_frame_clock (style_context,
895 g_value_get_object (value));
898 gtk_style_context_set_parent (style_context,
899 g_value_get_object (value));
902 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
908 gtk_style_context_impl_get_property (GObject *object,
913 GtkStyleContext *style_context;
914 GtkStyleContextPrivate *priv;
916 style_context = GTK_STYLE_CONTEXT (object);
917 priv = style_context->priv;
922 g_value_set_object (value, priv->screen);
925 G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
926 g_value_set_enum (value, gtk_style_context_get_direction (style_context));
927 G_GNUC_END_IGNORE_DEPRECATIONS;
929 case PROP_FRAME_CLOCK:
930 g_value_set_object (value, priv->frame_clock);
933 g_value_set_object (value, priv->parent);
936 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
941 static GtkWidgetPath *
942 create_query_path (GtkStyleContext *context,
945 GtkStyleContextPrivate *priv;
949 priv = context->priv;
950 path = priv->widget ? _gtk_widget_create_path (priv->widget) : gtk_widget_path_copy (priv->widget_path);
951 pos = gtk_widget_path_length (path) - 1;
953 /* Set widget regions */
954 for (i = 0; i < info->regions->len; i++)
958 region = &g_array_index (info->regions, GtkRegion, i);
959 gtk_widget_path_iter_add_region (path, pos,
960 g_quark_to_string (region->class_quark),
964 /* Set widget classes */
965 for (i = 0; i < info->style_classes->len; i++)
969 quark = g_array_index (info->style_classes, GQuark, i);
970 gtk_widget_path_iter_add_class (path, pos,
971 g_quark_to_string (quark));
978 build_properties (GtkStyleContext *context,
979 GtkCssComputedValues *values,
981 const GtkBitmask *relevant_changes)
983 GtkStyleContextPrivate *priv;
984 GtkCssMatcher matcher;
986 GtkCssLookup *lookup;
988 priv = context->priv;
990 path = create_query_path (context, info);
991 lookup = _gtk_css_lookup_new (relevant_changes);
993 if (_gtk_css_matcher_init (&matcher, path, info->state_flags))
994 _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
998 _gtk_css_lookup_resolve (lookup,
999 GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
1001 priv->parent ? style_data_lookup (priv->parent)->store : NULL);
1003 _gtk_css_lookup_free (lookup);
1004 gtk_widget_path_free (path);
1008 style_data_lookup (GtkStyleContext *context)
1010 GtkStyleContextPrivate *priv;
1014 priv = context->priv;
1017 /* Current data in use is cached, just return it */
1021 g_assert (priv->widget != NULL || priv->widget_path != NULL);
1023 data = g_hash_table_lookup (priv->style_data, info);
1026 style_info_set_data (info, data);
1030 data = style_data_new ();
1031 data->store = _gtk_css_computed_values_new ();
1032 style_info_set_data (info, data);
1033 g_hash_table_insert (priv->style_data,
1034 style_info_copy (info),
1037 build_properties (context, data->store, info, NULL);
1043 style_data_lookup_for_state (GtkStyleContext *context,
1044 GtkStateFlags state)
1048 if (context->priv->info->state_flags == state)
1049 return style_data_lookup (context);
1051 gtk_style_context_save (context);
1052 gtk_style_context_set_state (context, state);
1053 data = style_data_lookup (context);
1054 gtk_style_context_restore (context);
1060 gtk_style_context_set_invalid (GtkStyleContext *context,
1063 GtkStyleContextPrivate *priv;
1065 priv = context->priv;
1067 if (priv->invalid == invalid)
1070 priv->invalid = invalid;
1075 gtk_style_context_set_invalid (priv->parent, TRUE);
1076 else if (GTK_IS_RESIZE_CONTAINER (priv->widget))
1077 _gtk_container_queue_restyle (GTK_CONTAINER (priv->widget));
1081 /* returns TRUE if someone called gtk_style_context_save() but hasn't
1082 * called gtk_style_context_restore() yet.
1083 * In those situations we don't invalidate the context when somebody
1084 * changes state/regions/classes.
1087 gtk_style_context_is_saved (GtkStyleContext *context)
1089 return context->priv->info->next != NULL;
1093 gtk_style_context_queue_invalidate_internal (GtkStyleContext *context,
1094 GtkCssChange change)
1096 GtkStyleContextPrivate *priv = context->priv;
1097 GtkStyleInfo *info = priv->info;
1099 if (gtk_style_context_is_saved (context))
1101 style_info_set_data (info, NULL);
1105 _gtk_style_context_queue_invalidate (context, change);
1106 /* XXX: We need to invalidate siblings here somehow */
1111 * gtk_style_context_new:
1113 * Creates a standalone #GtkStyleContext, this style context
1114 * won't be attached to any widget, so you may want
1115 * to call gtk_style_context_set_path() yourself.
1118 * This function is only useful when using the theming layer
1119 * separated from GTK+, if you are using #GtkStyleContext to
1120 * theme #GtkWidget<!-- -->s, use gtk_widget_get_style_context()
1121 * in order to get a style context ready to theme the widget.
1124 * Returns: A newly created #GtkStyleContext.
1127 gtk_style_context_new (void)
1129 return g_object_new (GTK_TYPE_STYLE_CONTEXT, NULL);
1133 _gtk_style_context_set_widget (GtkStyleContext *context,
1136 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1137 g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget));
1139 context->priv->widget = widget;
1141 _gtk_style_context_update_animating (context);
1143 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY_SELF);
1147 * gtk_style_context_add_provider:
1148 * @context: a #GtkStyleContext
1149 * @provider: a #GtkStyleProvider
1150 * @priority: the priority of the style provider. The lower
1151 * it is, the earlier it will be used in the style
1152 * construction. Typically this will be in the range
1153 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1154 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1156 * Adds a style provider to @context, to be used in style construction.
1157 * Note that a style provider added by this function only affects
1158 * the style of the widget to which @context belongs. If you want
1159 * to affect the style of all widgets, use
1160 * gtk_style_context_add_provider_for_screen().
1162 * <note><para>If both priorities are the same, A #GtkStyleProvider
1163 * added through this function takes precedence over another added
1164 * through gtk_style_context_add_provider_for_screen().</para></note>
1169 gtk_style_context_add_provider (GtkStyleContext *context,
1170 GtkStyleProvider *provider,
1173 GtkStyleContextPrivate *priv;
1175 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1176 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1178 priv = context->priv;
1180 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
1182 GtkStyleCascade *new_cascade;
1184 new_cascade = _gtk_style_cascade_new ();
1185 _gtk_style_cascade_set_parent (new_cascade, priv->cascade);
1186 _gtk_style_cascade_add_provider (new_cascade, provider, priority);
1187 gtk_style_context_set_cascade (context, new_cascade);
1188 g_object_unref (new_cascade);
1192 _gtk_style_cascade_add_provider (priv->cascade, provider, priority);
1197 * gtk_style_context_remove_provider:
1198 * @context: a #GtkStyleContext
1199 * @provider: a #GtkStyleProvider
1201 * Removes @provider from the style providers list in @context.
1206 gtk_style_context_remove_provider (GtkStyleContext *context,
1207 GtkStyleProvider *provider)
1209 GtkStyleContextPrivate *priv;
1211 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1212 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1214 priv = context->priv;
1216 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
1219 _gtk_style_cascade_remove_provider (priv->cascade, provider);
1223 * gtk_style_context_reset_widgets:
1224 * @screen: a #GdkScreen
1226 * This function recomputes the styles for all widgets under a particular
1227 * #GdkScreen. This is useful when some global parameter has changed that
1228 * affects the appearance of all widgets, because when a widget gets a new
1229 * style, it will both redraw and recompute any cached information about
1230 * its appearance. As an example, it is used when the color scheme changes
1231 * in the related #GtkSettings object.
1236 gtk_style_context_reset_widgets (GdkScreen *screen)
1238 GList *list, *toplevels;
1240 _gtk_icon_set_invalidate_caches ();
1242 toplevels = gtk_window_list_toplevels ();
1243 g_list_foreach (toplevels, (GFunc) g_object_ref, NULL);
1245 for (list = toplevels; list; list = list->next)
1247 if (gtk_widget_get_screen (list->data) == screen)
1248 gtk_widget_reset_style (list->data);
1250 g_object_unref (list->data);
1253 g_list_free (toplevels);
1257 * gtk_style_context_add_provider_for_screen:
1258 * @screen: a #GdkScreen
1259 * @provider: a #GtkStyleProvider
1260 * @priority: the priority of the style provider. The lower
1261 * it is, the earlier it will be used in the style
1262 * construction. Typically this will be in the range
1263 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1264 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1266 * Adds a global style provider to @screen, which will be used
1267 * in style construction for all #GtkStyleContexts under @screen.
1269 * GTK+ uses this to make styling information from #GtkSettings
1272 * <note><para>If both priorities are the same, A #GtkStyleProvider
1273 * added through gtk_style_context_add_provider() takes precedence
1274 * over another added through this function.</para></note>
1279 gtk_style_context_add_provider_for_screen (GdkScreen *screen,
1280 GtkStyleProvider *provider,
1283 GtkStyleCascade *cascade;
1285 g_return_if_fail (GDK_IS_SCREEN (screen));
1286 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1287 g_return_if_fail (!GTK_IS_SETTINGS (provider) || _gtk_settings_get_screen (GTK_SETTINGS (provider)) == screen);
1289 cascade = _gtk_style_cascade_get_for_screen (screen);
1290 _gtk_style_cascade_add_provider (cascade, provider, priority);
1294 * gtk_style_context_remove_provider_for_screen:
1295 * @screen: a #GdkScreen
1296 * @provider: a #GtkStyleProvider
1298 * Removes @provider from the global style providers list in @screen.
1303 gtk_style_context_remove_provider_for_screen (GdkScreen *screen,
1304 GtkStyleProvider *provider)
1306 GtkStyleCascade *cascade;
1308 g_return_if_fail (GDK_IS_SCREEN (screen));
1309 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1310 g_return_if_fail (!GTK_IS_SETTINGS (provider));
1312 cascade = _gtk_style_cascade_get_for_screen (screen);
1313 _gtk_style_cascade_remove_provider (cascade, provider);
1317 * gtk_style_context_get_section:
1318 * @context: a #GtkStyleContext
1319 * @property: style property name
1321 * Queries the location in the CSS where @property was defined for the
1322 * current @context. Note that the state to be queried is taken from
1323 * gtk_style_context_get_state().
1325 * If the location is not available, %NULL will be returned. The
1326 * location might not be available for various reasons, such as the
1327 * property being overridden, @property not naming a supported CSS
1328 * property or tracking of definitions being disabled for performance
1331 * Shorthand CSS properties cannot be queried for a location and will
1332 * always return %NULL.
1334 * Returns: %NULL or the section where value was defined
1337 gtk_style_context_get_section (GtkStyleContext *context,
1338 const gchar *property)
1340 GtkStyleContextPrivate *priv;
1341 GtkStyleProperty *prop;
1344 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1345 g_return_val_if_fail (property != NULL, NULL);
1347 priv = context->priv;
1348 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
1350 prop = _gtk_style_property_lookup (property);
1351 if (!GTK_IS_CSS_STYLE_PROPERTY (prop))
1354 data = style_data_lookup (context);
1355 return _gtk_css_computed_values_get_section (data->store, _gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (prop)));
1358 static GtkCssValue *
1359 gtk_style_context_query_func (guint id,
1362 return _gtk_css_computed_values_get_value (values, id);
1366 * gtk_style_context_get_property:
1367 * @context: a #GtkStyleContext
1368 * @property: style property name
1369 * @state: state to retrieve the property value for
1370 * @value: (out) (transfer full): return location for the style property value
1372 * Gets a style property from @context for the given state.
1374 * When @value is no longer needed, g_value_unset() must be called
1375 * to free any allocated memory.
1380 gtk_style_context_get_property (GtkStyleContext *context,
1381 const gchar *property,
1382 GtkStateFlags state,
1385 GtkStyleContextPrivate *priv;
1386 GtkStyleProperty *prop;
1389 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1390 g_return_if_fail (property != NULL);
1391 g_return_if_fail (value != NULL);
1393 priv = context->priv;
1394 g_return_if_fail (priv->widget != NULL || priv->widget_path != NULL);
1396 prop = _gtk_style_property_lookup (property);
1399 g_warning ("Style property \"%s\" is not registered", property);
1402 if (_gtk_style_property_get_value_type (prop) == G_TYPE_NONE)
1404 g_warning ("Style property \"%s\" is not gettable", property);
1408 data = style_data_lookup_for_state (context, state);
1409 _gtk_style_property_query (prop, value, gtk_style_context_query_func, data->store);
1413 * gtk_style_context_get_valist:
1414 * @context: a #GtkStyleContext
1415 * @state: state to retrieve the property values for
1416 * @args: va_list of property name/return location pairs, followed by %NULL
1418 * Retrieves several style property values from @context for a given state.
1423 gtk_style_context_get_valist (GtkStyleContext *context,
1424 GtkStateFlags state,
1427 const gchar *property_name;
1429 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1431 property_name = va_arg (args, const gchar *);
1433 while (property_name)
1435 gchar *error = NULL;
1436 GValue value = G_VALUE_INIT;
1438 gtk_style_context_get_property (context,
1443 G_VALUE_LCOPY (&value, args, 0, &error);
1444 g_value_unset (&value);
1448 g_warning ("Could not get style property \"%s\": %s", property_name, error);
1453 property_name = va_arg (args, const gchar *);
1458 * gtk_style_context_get:
1459 * @context: a #GtkStyleContext
1460 * @state: state to retrieve the property values for
1461 * @...: property name /return value pairs, followed by %NULL
1463 * Retrieves several style property values from @context for a
1469 gtk_style_context_get (GtkStyleContext *context,
1470 GtkStateFlags state,
1475 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1477 va_start (args, state);
1478 gtk_style_context_get_valist (context, state, args);
1483 * gtk_style_context_set_state:
1484 * @context: a #GtkStyleContext
1485 * @flags: state to represent
1487 * Sets the state to be used when rendering with any
1488 * of the gtk_render_*() functions.
1493 gtk_style_context_set_state (GtkStyleContext *context,
1494 GtkStateFlags flags)
1496 GtkStateFlags old_flags;
1497 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1499 old_flags = context->priv->info->state_flags;
1500 if (old_flags == flags)
1503 context->priv->info->state_flags = flags;
1505 if (((old_flags ^ flags) & (GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL)) &&
1506 !gtk_style_context_is_saved (context))
1507 g_object_notify (G_OBJECT (context), "direction");
1509 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_STATE);
1513 * gtk_style_context_get_state:
1514 * @context: a #GtkStyleContext
1516 * Returns the state used when rendering.
1518 * Returns: the state flags
1523 gtk_style_context_get_state (GtkStyleContext *context)
1525 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
1527 return context->priv->info->state_flags;
1531 * gtk_style_context_state_is_running:
1532 * @context: a #GtkStyleContext
1533 * @state: a widget state
1534 * @progress: (out): return location for the transition progress
1536 * Returns %TRUE if there is a transition animation running for the
1537 * current region (see gtk_style_context_push_animatable_region()).
1539 * If @progress is not %NULL, the animation progress will be returned
1540 * there, 0.0 means the state is closest to being unset, while 1.0 means
1541 * it's closest to being set. This means transition animation will
1542 * run from 0 to 1 when @state is being set and from 1 to 0 when
1545 * Returns: %TRUE if there is a running transition animation for @state.
1549 * Deprecated: 3.6: This function always returns %FALSE
1552 gtk_style_context_state_is_running (GtkStyleContext *context,
1556 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1562 * gtk_style_context_set_path:
1563 * @context: a #GtkStyleContext
1564 * @path: a #GtkWidgetPath
1566 * Sets the #GtkWidgetPath used for style matching. As a
1567 * consequence, the style will be regenerated to match
1568 * the new given path.
1570 * If you are using a #GtkStyleContext returned from
1571 * gtk_widget_get_style_context(), you do not need to call
1577 gtk_style_context_set_path (GtkStyleContext *context,
1578 GtkWidgetPath *path)
1580 GtkStyleContextPrivate *priv;
1582 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1583 g_return_if_fail (path != NULL);
1585 priv = context->priv;
1586 g_return_if_fail (priv->widget == NULL);
1588 if (priv->widget_path)
1590 gtk_widget_path_free (priv->widget_path);
1591 priv->widget_path = NULL;
1595 priv->widget_path = gtk_widget_path_copy (path);
1597 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY);
1601 * gtk_style_context_get_path:
1602 * @context: a #GtkStyleContext
1604 * Returns the widget path used for style matching.
1606 * Returns: (transfer none): A #GtkWidgetPath
1610 const GtkWidgetPath *
1611 gtk_style_context_get_path (GtkStyleContext *context)
1613 GtkStyleContextPrivate *priv;
1615 priv = context->priv;
1617 return gtk_widget_get_path (priv->widget);
1619 return priv->widget_path;
1623 * gtk_style_context_set_parent:
1624 * @context: a #GtkStyleContext
1625 * @parent: (allow-none): the new parent or %NULL
1627 * Sets the parent style context for @context. The parent style
1628 * context is used to implement
1629 * <ulink url="http://www.w3.org/TR/css3-cascade/#inheritance">inheritance</ulink>
1632 * If you are using a #GtkStyleContext returned from
1633 * gtk_widget_get_style_context(), the parent will be set for you.
1638 gtk_style_context_set_parent (GtkStyleContext *context,
1639 GtkStyleContext *parent)
1641 GtkStyleContextPrivate *priv;
1643 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1644 g_return_if_fail (parent == NULL || GTK_IS_STYLE_CONTEXT (parent));
1646 priv = context->priv;
1648 if (priv->parent == parent)
1653 parent->priv->children = g_slist_prepend (parent->priv->children, context);
1654 g_object_ref (parent);
1656 gtk_style_context_set_invalid (parent, TRUE);
1661 priv->parent->priv->children = g_slist_remove (priv->parent->priv->children, context);
1662 g_object_unref (priv->parent);
1665 priv->parent = parent;
1667 g_object_notify (G_OBJECT (context), "parent");
1668 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY_PARENT | GTK_CSS_CHANGE_ANY_SIBLING);
1672 * gtk_style_context_get_parent:
1673 * @context: a #GtkStyleContext
1675 * Gets the parent context set via gtk_style_context_set_parent().
1676 * See that function for details.
1678 * Returns: (transfer none): the parent context or %NULL
1683 gtk_style_context_get_parent (GtkStyleContext *context)
1685 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1687 return context->priv->parent;
1691 * gtk_style_context_save:
1692 * @context: a #GtkStyleContext
1694 * Saves the @context state, so all modifications done through
1695 * gtk_style_context_add_class(), gtk_style_context_remove_class(),
1696 * gtk_style_context_add_region(), gtk_style_context_remove_region()
1697 * or gtk_style_context_set_junction_sides() can be reverted in one
1698 * go through gtk_style_context_restore().
1703 gtk_style_context_save (GtkStyleContext *context)
1705 GtkStyleContextPrivate *priv;
1707 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1709 priv = context->priv;
1711 priv->info = style_info_copy (priv->info);
1712 /* Need to unset animations here because we can not know what style
1713 * class potential transitions came from once we save().
1715 if (priv->info->data && style_data_is_animating (priv->info->data))
1716 style_info_set_data (priv->info, NULL);
1720 * gtk_style_context_restore:
1721 * @context: a #GtkStyleContext
1723 * Restores @context state to a previous stage.
1724 * See gtk_style_context_save().
1729 gtk_style_context_restore (GtkStyleContext *context)
1731 GtkStyleContextPrivate *priv;
1733 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1735 priv = context->priv;
1737 priv->info = style_info_pop (priv->info);
1741 g_warning ("Unpaired gtk_style_context_restore() call");
1743 /* Create default region */
1744 priv->info = style_info_new ();
1749 style_class_find (GArray *array,
1754 gboolean found = FALSE;
1760 if (!array || array->len == 0)
1764 max = array->len - 1;
1770 mid = (min + max) / 2;
1771 item = g_array_index (array, GQuark, mid);
1773 if (class_quark == item)
1778 else if (class_quark > item)
1779 min = pos = mid + 1;
1786 while (!found && min <= max);
1795 region_find (GArray *array,
1800 gboolean found = FALSE;
1806 if (!array || array->len == 0)
1810 max = array->len - 1;
1816 mid = (min + max) / 2;
1817 region = &g_array_index (array, GtkRegion, mid);
1819 if (region->class_quark == class_quark)
1824 else if (region->class_quark > class_quark)
1825 min = pos = mid + 1;
1832 while (!found && min <= max);
1841 * gtk_style_context_add_class:
1842 * @context: a #GtkStyleContext
1843 * @class_name: class name to use in styling
1845 * Adds a style class to @context, so posterior calls to
1846 * gtk_style_context_get() or any of the gtk_render_*()
1847 * functions will make use of this new class for styling.
1849 * In the CSS file format, a #GtkEntry defining an "entry"
1850 * class, would be matched by:
1853 * GtkEntry.entry { ... }
1856 * While any widget defining an "entry" class would be
1865 gtk_style_context_add_class (GtkStyleContext *context,
1866 const gchar *class_name)
1868 GtkStyleContextPrivate *priv;
1873 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1874 g_return_if_fail (class_name != NULL);
1876 priv = context->priv;
1877 class_quark = g_quark_from_string (class_name);
1881 if (!style_class_find (info->style_classes, class_quark, &position))
1883 g_array_insert_val (info->style_classes, position, class_quark);
1885 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_CLASS);
1890 * gtk_style_context_remove_class:
1891 * @context: a #GtkStyleContext
1892 * @class_name: class name to remove
1894 * Removes @class_name from @context.
1899 gtk_style_context_remove_class (GtkStyleContext *context,
1900 const gchar *class_name)
1902 GtkStyleContextPrivate *priv;
1907 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1908 g_return_if_fail (class_name != NULL);
1910 class_quark = g_quark_try_string (class_name);
1915 priv = context->priv;
1919 if (style_class_find (info->style_classes, class_quark, &position))
1921 g_array_remove_index (info->style_classes, position);
1923 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_CLASS);
1928 * gtk_style_context_has_class:
1929 * @context: a #GtkStyleContext
1930 * @class_name: a class name
1932 * Returns %TRUE if @context currently has defined the
1935 * Returns: %TRUE if @context has @class_name defined
1940 gtk_style_context_has_class (GtkStyleContext *context,
1941 const gchar *class_name)
1943 GtkStyleContextPrivate *priv;
1947 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1948 g_return_val_if_fail (class_name != NULL, FALSE);
1950 class_quark = g_quark_try_string (class_name);
1955 priv = context->priv;
1959 if (style_class_find (info->style_classes, class_quark, NULL))
1966 * gtk_style_context_list_classes:
1967 * @context: a #GtkStyleContext
1969 * Returns the list of classes currently defined in @context.
1971 * Returns: (transfer container) (element-type utf8): a #GList of
1972 * strings with the currently defined classes. The contents
1973 * of the list are owned by GTK+, but you must free the list
1974 * itself with g_list_free() when you are done with it.
1979 gtk_style_context_list_classes (GtkStyleContext *context)
1981 GtkStyleContextPrivate *priv;
1983 GList *classes = NULL;
1986 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1988 priv = context->priv;
1992 for (i = 0; i < info->style_classes->len; i++)
1996 quark = g_array_index (info->style_classes, GQuark, i);
1997 classes = g_list_prepend (classes, (gchar *) g_quark_to_string (quark));
2004 * gtk_style_context_list_regions:
2005 * @context: a #GtkStyleContext
2007 * Returns the list of regions currently defined in @context.
2009 * Returns: (transfer container) (element-type utf8): a #GList of
2010 * strings with the currently defined regions. The contents
2011 * of the list are owned by GTK+, but you must free the list
2012 * itself with g_list_free() when you are done with it.
2017 gtk_style_context_list_regions (GtkStyleContext *context)
2019 GtkStyleContextPrivate *priv;
2021 GList *classes = NULL;
2024 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2026 priv = context->priv;
2030 for (i = 0; i < info->regions->len; i++)
2033 const gchar *class_name;
2035 region = &g_array_index (info->regions, GtkRegion, i);
2037 class_name = g_quark_to_string (region->class_quark);
2038 classes = g_list_prepend (classes, (gchar *) class_name);
2045 _gtk_style_context_check_region_name (const gchar *str)
2047 g_return_val_if_fail (str != NULL, FALSE);
2049 if (!g_ascii_islower (str[0]))
2055 !g_ascii_islower (*str))
2065 * gtk_style_context_add_region:
2066 * @context: a #GtkStyleContext
2067 * @region_name: region name to use in styling
2068 * @flags: flags that apply to the region
2070 * Adds a region to @context, so posterior calls to
2071 * gtk_style_context_get() or any of the gtk_render_*()
2072 * functions will make use of this new region for styling.
2074 * In the CSS file format, a #GtkTreeView defining a "row"
2075 * region, would be matched by:
2078 * GtkTreeView row { ... }
2081 * Pseudo-classes are used for matching @flags, so the two
2084 * GtkTreeView row:nth-child(even) { ... }
2085 * GtkTreeView row:nth-child(odd) { ... }
2088 * would apply to even and odd rows, respectively.
2090 * <note><para>Region names must only contain lowercase letters
2091 * and '-', starting always with a lowercase letter.</para></note>
2096 gtk_style_context_add_region (GtkStyleContext *context,
2097 const gchar *region_name,
2098 GtkRegionFlags flags)
2100 GtkStyleContextPrivate *priv;
2102 GQuark region_quark;
2105 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2106 g_return_if_fail (region_name != NULL);
2107 g_return_if_fail (_gtk_style_context_check_region_name (region_name));
2109 priv = context->priv;
2110 region_quark = g_quark_from_string (region_name);
2114 if (!region_find (info->regions, region_quark, &position))
2118 region.class_quark = region_quark;
2119 region.flags = flags;
2121 g_array_insert_val (info->regions, position, region);
2123 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_REGION);
2128 * gtk_style_context_remove_region:
2129 * @context: a #GtkStyleContext
2130 * @region_name: region name to unset
2132 * Removes a region from @context.
2137 gtk_style_context_remove_region (GtkStyleContext *context,
2138 const gchar *region_name)
2140 GtkStyleContextPrivate *priv;
2142 GQuark region_quark;
2145 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2146 g_return_if_fail (region_name != NULL);
2148 region_quark = g_quark_try_string (region_name);
2153 priv = context->priv;
2157 if (region_find (info->regions, region_quark, &position))
2159 g_array_remove_index (info->regions, position);
2161 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_REGION);
2166 * gtk_style_context_has_region:
2167 * @context: a #GtkStyleContext
2168 * @region_name: a region name
2169 * @flags_return: (out) (allow-none): return location for region flags
2171 * Returns %TRUE if @context has the region defined.
2172 * If @flags_return is not %NULL, it is set to the flags
2173 * affecting the region.
2175 * Returns: %TRUE if region is defined
2180 gtk_style_context_has_region (GtkStyleContext *context,
2181 const gchar *region_name,
2182 GtkRegionFlags *flags_return)
2184 GtkStyleContextPrivate *priv;
2186 GQuark region_quark;
2189 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2190 g_return_val_if_fail (region_name != NULL, FALSE);
2195 region_quark = g_quark_try_string (region_name);
2200 priv = context->priv;
2204 if (region_find (info->regions, region_quark, &position))
2210 region = &g_array_index (info->regions, GtkRegion, position);
2211 *flags_return = region->flags;
2220 style_property_values_cmp (gconstpointer bsearch_node1,
2221 gconstpointer bsearch_node2)
2223 const PropertyValue *val1 = bsearch_node1;
2224 const PropertyValue *val2 = bsearch_node2;
2226 if (val1->widget_type != val2->widget_type)
2227 return val1->widget_type < val2->widget_type ? -1 : 1;
2229 if (val1->pspec != val2->pspec)
2230 return val1->pspec < val2->pspec ? -1 : 1;
2232 if (val1->state != val2->state)
2233 return val1->state < val2->state ? -1 : 1;
2239 _gtk_style_context_peek_property (GtkStyleContext *context,
2242 StyleData *data = style_data_lookup (context);
2244 return _gtk_css_computed_values_get_value (data->store, property_id);
2248 _gtk_style_context_peek_style_property (GtkStyleContext *context,
2250 GtkStateFlags state,
2253 GtkStyleContextPrivate *priv;
2254 PropertyValue *pcache, key = { 0 };
2258 priv = context->priv;
2260 data = style_data_lookup_for_state (context, state);
2262 key.widget_type = widget_type;
2266 /* need value cache array */
2267 if (!data->property_cache)
2268 data->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
2271 pcache = bsearch (&key,
2272 data->property_cache->data, data->property_cache->len,
2273 sizeof (PropertyValue), style_property_values_cmp);
2275 return &pcache->value;
2279 while (i < data->property_cache->len &&
2280 style_property_values_cmp (&key, &g_array_index (data->property_cache, PropertyValue, i)) >= 0)
2283 g_array_insert_val (data->property_cache, i, key);
2284 pcache = &g_array_index (data->property_cache, PropertyValue, i);
2286 /* cache miss, initialize value type, then set contents */
2287 g_param_spec_ref (pcache->pspec);
2288 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2290 if (priv->widget || priv->widget_path)
2292 GtkWidgetPath *widget_path = priv->widget ? _gtk_widget_create_path (priv->widget) : priv->widget_path;
2294 if (gtk_style_provider_get_style_property (GTK_STYLE_PROVIDER (priv->cascade),
2296 state, pspec, &pcache->value))
2298 G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
2300 /* Resolve symbolic colors to GdkColor/GdkRGBA */
2301 if (G_VALUE_TYPE (&pcache->value) == GTK_TYPE_SYMBOLIC_COLOR)
2303 GtkSymbolicColor *color;
2306 color = g_value_dup_boxed (&pcache->value);
2308 g_value_unset (&pcache->value);
2310 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2311 g_value_init (&pcache->value, GDK_TYPE_RGBA);
2313 g_value_init (&pcache->value, GDK_TYPE_COLOR);
2315 if (_gtk_style_context_resolve_color (context, _gtk_symbolic_color_get_css_value (color), &rgba, NULL))
2317 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2318 g_value_set_boxed (&pcache->value, &rgba);
2323 rgb.red = rgba.red * 65535. + 0.5;
2324 rgb.green = rgba.green * 65535. + 0.5;
2325 rgb.blue = rgba.blue * 65535. + 0.5;
2327 g_value_set_boxed (&pcache->value, &rgb);
2331 g_param_value_set_default (pspec, &pcache->value);
2333 gtk_symbolic_color_unref (color);
2336 G_GNUC_END_IGNORE_DEPRECATIONS;
2339 gtk_widget_path_free (widget_path);
2341 return &pcache->value;
2345 gtk_widget_path_free (widget_path);
2348 /* not supplied by any provider, revert to default */
2349 g_param_value_set_default (pspec, &pcache->value);
2351 return &pcache->value;
2355 * gtk_style_context_get_style_property:
2356 * @context: a #GtkStyleContext
2357 * @property_name: the name of the widget style property
2358 * @value: Return location for the property value
2360 * Gets the value for a widget style property.
2362 * When @value is no longer needed, g_value_unset() must be called
2363 * to free any allocated memory.
2366 gtk_style_context_get_style_property (GtkStyleContext *context,
2367 const gchar *property_name,
2370 GtkStyleContextPrivate *priv;
2371 GtkWidgetClass *widget_class;
2372 GtkStateFlags state;
2374 const GValue *peek_value;
2377 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2378 g_return_if_fail (property_name != NULL);
2379 g_return_if_fail (value != NULL);
2381 priv = context->priv;
2385 widget_type = G_OBJECT_TYPE (priv->widget);
2389 if (!priv->widget_path)
2392 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2394 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2396 g_warning ("%s: can't get style properties for non-widget class `%s'",
2398 g_type_name (widget_type));
2403 widget_class = g_type_class_ref (widget_type);
2404 pspec = gtk_widget_class_find_style_property (widget_class, property_name);
2405 g_type_class_unref (widget_class);
2409 g_warning ("%s: widget class `%s' has no style property named `%s'",
2411 g_type_name (widget_type),
2416 state = gtk_style_context_get_state (context);
2417 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2420 if (G_VALUE_TYPE (value) == G_VALUE_TYPE (peek_value))
2421 g_value_copy (peek_value, value);
2422 else if (g_value_type_transformable (G_VALUE_TYPE (peek_value), G_VALUE_TYPE (value)))
2423 g_value_transform (peek_value, value);
2425 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
2427 G_VALUE_TYPE_NAME (peek_value),
2428 G_VALUE_TYPE_NAME (value));
2432 * gtk_style_context_get_style_valist:
2433 * @context: a #GtkStyleContext
2434 * @args: va_list of property name/return location pairs, followed by %NULL
2436 * Retrieves several widget style properties from @context according to the
2442 gtk_style_context_get_style_valist (GtkStyleContext *context,
2445 GtkStyleContextPrivate *priv;
2446 const gchar *prop_name;
2447 GtkStateFlags state;
2450 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2452 prop_name = va_arg (args, const gchar *);
2453 priv = context->priv;
2457 widget_type = G_OBJECT_TYPE (priv->widget);
2461 if (!priv->widget_path)
2464 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2466 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2468 g_warning ("%s: can't get style properties for non-widget class `%s'",
2470 g_type_name (widget_type));
2475 state = gtk_style_context_get_state (context);
2479 GtkWidgetClass *widget_class;
2481 const GValue *peek_value;
2484 widget_class = g_type_class_ref (widget_type);
2485 pspec = gtk_widget_class_find_style_property (widget_class, prop_name);
2486 g_type_class_unref (widget_class);
2490 g_warning ("%s: widget class `%s' has no style property named `%s'",
2492 g_type_name (widget_type),
2497 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2500 G_VALUE_LCOPY (peek_value, args, 0, &error);
2504 g_warning ("can't retrieve style property `%s' of type `%s': %s",
2506 G_VALUE_TYPE_NAME (peek_value),
2512 prop_name = va_arg (args, const gchar *);
2517 * gtk_style_context_get_style:
2518 * @context: a #GtkStyleContext
2519 * @...: property name /return value pairs, followed by %NULL
2521 * Retrieves several widget style properties from @context according to the
2527 gtk_style_context_get_style (GtkStyleContext *context,
2532 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2534 va_start (args, context);
2535 gtk_style_context_get_style_valist (context, args);
2541 * gtk_style_context_lookup_icon_set:
2542 * @context: a #GtkStyleContext
2543 * @stock_id: an icon name
2545 * Looks up @stock_id in the icon factories associated to @context and
2546 * the default icon factory, returning an icon set if found, otherwise
2549 * Returns: (transfer none): The looked up %GtkIconSet, or %NULL
2552 gtk_style_context_lookup_icon_set (GtkStyleContext *context,
2553 const gchar *stock_id)
2555 GtkStyleContextPrivate *priv;
2557 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2558 g_return_val_if_fail (stock_id != NULL, NULL);
2560 priv = context->priv;
2561 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
2563 return gtk_icon_factory_lookup_default (stock_id);
2567 * gtk_style_context_set_screen:
2568 * @context: a #GtkStyleContext
2569 * @screen: a #GdkScreen
2571 * Attaches @context to the given screen.
2573 * The screen is used to add style information from 'global' style
2574 * providers, such as the screens #GtkSettings instance.
2576 * If you are using a #GtkStyleContext returned from
2577 * gtk_widget_get_style_context(), you do not need to
2578 * call this yourself.
2583 gtk_style_context_set_screen (GtkStyleContext *context,
2586 GtkStyleContextPrivate *priv;
2588 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2589 g_return_if_fail (GDK_IS_SCREEN (screen));
2591 priv = context->priv;
2592 if (priv->screen == screen)
2595 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
2597 gtk_style_context_set_cascade (context, _gtk_style_cascade_get_for_screen (screen));
2601 _gtk_style_cascade_set_parent (priv->cascade, _gtk_style_cascade_get_for_screen (screen));
2604 priv->screen = screen;
2606 g_object_notify (G_OBJECT (context), "screen");
2610 * gtk_style_context_get_screen:
2611 * @context: a #GtkStyleContext
2613 * Returns the #GdkScreen to which @context is attached.
2615 * Returns: (transfer none): a #GdkScreen.
2618 gtk_style_context_get_screen (GtkStyleContext *context)
2620 GtkStyleContextPrivate *priv;
2622 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2624 priv = context->priv;
2625 return priv->screen;
2629 * gtk_style_context_set_frame_clock:
2630 * @context: a #GdkFrameClock
2631 * @frame_clock: a #GdkFrameClock
2633 * Attaches @context to the given frame clock.
2635 * The frame clock is used for the timing of animations.
2637 * If you are using a #GtkStyleContext returned from
2638 * gtk_widget_get_style_context(), you do not need to
2639 * call this yourself.
2644 gtk_style_context_set_frame_clock (GtkStyleContext *context,
2645 GdkFrameClock *frame_clock)
2647 GtkStyleContextPrivate *priv;
2649 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2650 g_return_if_fail (frame_clock == NULL || GDK_IS_FRAME_CLOCK (frame_clock));
2652 priv = context->priv;
2653 if (priv->frame_clock == frame_clock)
2656 if (priv->animating)
2657 gtk_style_context_disconnect_update (context);
2659 if (priv->frame_clock)
2660 g_object_unref (priv->frame_clock);
2661 priv->frame_clock = frame_clock;
2662 if (priv->frame_clock)
2663 g_object_ref (priv->frame_clock);
2665 if (priv->animating)
2666 gtk_style_context_connect_update (context);
2668 g_object_notify (G_OBJECT (context), "paint-clock");
2672 * gtk_style_context_get_frame_clock:
2673 * @context: a #GtkStyleContext
2675 * Returns the #GdkFrameClock to which @context is attached.
2677 * Returns: (transfer none): a #GdkFrameClock, or %NULL
2678 * if @context does not have an attached frame clock.
2682 gtk_style_context_get_frame_clock (GtkStyleContext *context)
2684 GtkStyleContextPrivate *priv;
2686 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2688 priv = context->priv;
2689 return priv->frame_clock;
2693 * gtk_style_context_set_direction:
2694 * @context: a #GtkStyleContext
2695 * @direction: the new direction.
2697 * Sets the reading direction for rendering purposes.
2699 * If you are using a #GtkStyleContext returned from
2700 * gtk_widget_get_style_context(), you do not need to
2701 * call this yourself.
2705 * Deprecated: 3.8: Use gtk_style_context_set_state() with
2706 * #GTK_STATE_FLAG_DIR_LTR and #GTK_STATE_FLAG_DIR_RTL
2710 gtk_style_context_set_direction (GtkStyleContext *context,
2711 GtkTextDirection direction)
2713 GtkStateFlags state;
2715 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2717 state = gtk_style_context_get_state (context);
2718 state &= ~(GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL);
2722 case GTK_TEXT_DIR_LTR:
2723 state |= GTK_STATE_FLAG_DIR_LTR;
2726 case GTK_TEXT_DIR_RTL:
2727 state |= GTK_STATE_FLAG_DIR_RTL;
2730 case GTK_TEXT_DIR_NONE:
2735 gtk_style_context_set_state (context, state);
2739 * gtk_style_context_get_direction:
2740 * @context: a #GtkStyleContext
2742 * Returns the widget direction used for rendering.
2744 * Returns: the widget direction
2748 * Deprecated: 3.8: Use gtk_style_context_get_state() and
2749 * check for #GTK_STATE_FLAG_DIR_LTR and
2750 * #GTK_STATE_FLAG_DIR_RTL instead.
2753 gtk_style_context_get_direction (GtkStyleContext *context)
2755 GtkStateFlags state;
2757 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), GTK_TEXT_DIR_LTR);
2759 state = gtk_style_context_get_state (context);
2761 if (state & GTK_STATE_FLAG_DIR_LTR)
2762 return GTK_TEXT_DIR_LTR;
2763 else if (state & GTK_STATE_FLAG_DIR_RTL)
2764 return GTK_TEXT_DIR_RTL;
2766 return GTK_TEXT_DIR_NONE;
2770 * gtk_style_context_set_junction_sides:
2771 * @context: a #GtkStyleContext
2772 * @sides: sides where rendered elements are visually connected to
2775 * Sets the sides where rendered elements (mostly through
2776 * gtk_render_frame()) will visually connect with other visual elements.
2778 * This is merely a hint that may or may not be honored
2779 * by theming engines.
2781 * Container widgets are expected to set junction hints as appropriate
2782 * for their children, so it should not normally be necessary to call
2783 * this function manually.
2788 gtk_style_context_set_junction_sides (GtkStyleContext *context,
2789 GtkJunctionSides sides)
2791 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2793 context->priv->info->junction_sides = sides;
2797 * gtk_style_context_get_junction_sides:
2798 * @context: a #GtkStyleContext
2800 * Returns the sides where rendered elements connect visually with others.
2802 * Returns: the junction sides
2807 gtk_style_context_get_junction_sides (GtkStyleContext *context)
2809 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
2811 return context->priv->info->junction_sides;
2815 _gtk_style_context_resolve_color (GtkStyleContext *context,
2818 GtkCssDependencies *dependencies)
2822 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2823 g_return_val_if_fail (color != NULL, FALSE);
2824 g_return_val_if_fail (result != NULL, FALSE);
2826 val = _gtk_css_color_value_resolve (color,
2827 GTK_STYLE_PROVIDER_PRIVATE (context->priv->cascade),
2828 _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR),
2829 GTK_CSS_DEPENDS_ON_COLOR,
2834 *result = *_gtk_css_rgba_value_get_rgba (val);
2835 _gtk_css_value_unref (val);
2840 * gtk_style_context_lookup_color:
2841 * @context: a #GtkStyleContext
2842 * @color_name: color name to lookup
2843 * @color: (out): Return location for the looked up color
2845 * Looks up and resolves a color name in the @context color map.
2847 * Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
2850 gtk_style_context_lookup_color (GtkStyleContext *context,
2851 const gchar *color_name,
2856 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2857 g_return_val_if_fail (color_name != NULL, FALSE);
2858 g_return_val_if_fail (color != NULL, FALSE);
2860 value = _gtk_style_provider_private_get_color (GTK_STYLE_PROVIDER_PRIVATE (context->priv->cascade), color_name);
2864 return _gtk_style_context_resolve_color (context, value, color, NULL);
2868 * gtk_style_context_notify_state_change:
2869 * @context: a #GtkStyleContext
2870 * @window: a #GdkWindow
2871 * @region_id: (allow-none): animatable region to notify on, or %NULL.
2872 * See gtk_style_context_push_animatable_region()
2873 * @state: state to trigger transition for
2874 * @state_value: %TRUE if @state is the state we are changing to,
2875 * %FALSE if we are changing away from it
2877 * Notifies a state change on @context, so if the current style makes use
2878 * of transition animations, one will be started so all rendered elements
2879 * under @region_id are animated for state @state being set to value
2882 * The @window parameter is used in order to invalidate the rendered area
2883 * as the animation runs, so make sure it is the same window that is being
2884 * rendered on by the gtk_render_*() functions.
2886 * If @region_id is %NULL, all rendered elements using @context will be
2887 * affected by this state transition.
2889 * As a practical example, a #GtkButton notifying a state transition on
2890 * the prelight state:
2892 * gtk_style_context_notify_state_change (context,
2893 * gtk_widget_get_window (widget),
2895 * GTK_STATE_PRELIGHT,
2896 * button->in_button);
2899 * Can be handled in the CSS file like this:
2902 * background-color: #f00
2906 * background-color: #fff;
2907 * transition: 200ms linear
2911 * This combination will animate the button background from red to white
2912 * if a pointer enters the button, and back to red if the pointer leaves
2915 * Note that @state is used when finding the transition parameters, which
2916 * is why the style places the transition under the :hover pseudo-class.
2920 * Deprecated: 3.6: This function does nothing.
2923 gtk_style_context_notify_state_change (GtkStyleContext *context,
2927 gboolean state_value)
2929 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2930 g_return_if_fail (GDK_IS_WINDOW (window));
2931 g_return_if_fail (state > GTK_STATE_NORMAL && state <= GTK_STATE_FOCUSED);
2932 g_return_if_fail (context->priv->widget != NULL || context->priv->widget_path != NULL);
2936 * gtk_style_context_cancel_animations:
2937 * @context: a #GtkStyleContext
2938 * @region_id: (allow-none): animatable region to stop, or %NULL.
2939 * See gtk_style_context_push_animatable_region()
2941 * Stops all running animations for @region_id and all animatable
2942 * regions underneath.
2944 * A %NULL @region_id will stop all ongoing animations in @context,
2945 * when dealing with a #GtkStyleContext obtained through
2946 * gtk_widget_get_style_context(), this is normally done for you
2947 * in all circumstances you would expect all widget to be stopped,
2948 * so this should be only used in complex widgets with different
2949 * animatable regions.
2953 * Deprecated: 3.6: This function does nothing.
2956 gtk_style_context_cancel_animations (GtkStyleContext *context,
2959 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2963 * gtk_style_context_scroll_animations:
2964 * @context: a #GtkStyleContext
2965 * @window: a #GdkWindow used previously in
2966 * gtk_style_context_notify_state_change()
2967 * @dx: Amount to scroll in the X axis
2968 * @dy: Amount to scroll in the Y axis
2970 * This function is analogous to gdk_window_scroll(), and
2971 * should be called together with it so the invalidation
2972 * areas for any ongoing animation are scrolled together
2977 * Deprecated: 3.6: This function does nothing.
2980 gtk_style_context_scroll_animations (GtkStyleContext *context,
2985 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2986 g_return_if_fail (GDK_IS_WINDOW (window));
2990 * gtk_style_context_push_animatable_region:
2991 * @context: a #GtkStyleContext
2992 * @region_id: unique identifier for the animatable region
2994 * Pushes an animatable region, so all further gtk_render_*() calls between
2995 * this call and the following gtk_style_context_pop_animatable_region()
2996 * will potentially show transition animations for this region if
2997 * gtk_style_context_notify_state_change() is called for a given state,
2998 * and the current theme/style defines transition animations for state
3001 * The @region_id used must be unique in @context so the theming engine
3002 * can uniquely identify rendered elements subject to a state transition.
3006 * Deprecated: 3.6: This function does nothing.
3009 gtk_style_context_push_animatable_region (GtkStyleContext *context,
3012 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3013 g_return_if_fail (region_id != NULL);
3017 * gtk_style_context_pop_animatable_region:
3018 * @context: a #GtkStyleContext
3020 * Pops an animatable region from @context.
3021 * See gtk_style_context_push_animatable_region().
3025 * Deprecated: 3.6: This function does nothing.
3028 gtk_style_context_pop_animatable_region (GtkStyleContext *context)
3030 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3034 gtk_style_context_clear_cache (GtkStyleContext *context)
3036 GtkStyleContextPrivate *priv;
3039 priv = context->priv;
3041 for (info = priv->info; info; info = info->next)
3043 style_info_set_data (info, NULL);
3045 g_hash_table_remove_all (priv->style_data);
3049 gtk_style_context_update_cache (GtkStyleContext *context,
3050 const GtkBitmask *parent_changes)
3052 GtkStyleContextPrivate *priv;
3053 GHashTableIter iter;
3054 gpointer key, value;
3056 if (_gtk_bitmask_is_empty (parent_changes))
3059 priv = context->priv;
3061 g_hash_table_iter_init (&iter, priv->style_data);
3062 while (g_hash_table_iter_next (&iter, &key, &value))
3064 GtkStyleInfo *info = key;
3065 StyleData *data = value;
3066 GtkBitmask *changes;
3068 changes = _gtk_css_computed_values_compute_dependencies (data->store, parent_changes);
3070 if (!_gtk_bitmask_is_empty (changes))
3071 build_properties (context, data->store, info, changes);
3073 _gtk_bitmask_free (changes);
3078 gtk_style_context_do_invalidate (GtkStyleContext *context,
3079 const GtkBitmask *changes)
3081 GtkStyleContextPrivate *priv;
3083 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3085 priv = context->priv;
3087 /* Avoid reentrancy */
3088 if (priv->invalidating_context)
3091 priv->invalidating_context = changes;
3093 g_signal_emit (context, signals[CHANGED], 0);
3095 priv->invalidating_context = NULL;
3099 gtk_style_context_update_animations (GtkStyleContext *context,
3102 GtkBitmask *differences;
3103 StyleData *style_data;
3105 style_data = style_data_lookup (context);
3107 differences = _gtk_css_computed_values_advance (style_data->store,
3110 if (_gtk_css_computed_values_is_static (style_data->store))
3111 _gtk_style_context_update_animating (context);
3117 gtk_style_context_needs_full_revalidate (GtkStyleContext *context,
3118 GtkCssChange change)
3120 GtkStyleContextPrivate *priv = context->priv;
3122 /* Try to avoid invalidating if we can */
3123 if (change & GTK_STYLE_CONTEXT_RADICAL_CHANGE)
3125 priv->relevant_changes = GTK_CSS_CHANGE_ANY;
3129 if (priv->relevant_changes == GTK_CSS_CHANGE_ANY)
3131 GtkWidgetPath *path;
3132 GtkCssMatcher matcher, superset;
3134 path = create_query_path (context, priv->info);
3135 if (_gtk_css_matcher_init (&matcher, path, priv->info->state_flags))
3137 _gtk_css_matcher_superset_init (&superset, &matcher, GTK_STYLE_CONTEXT_RADICAL_CHANGE & ~GTK_CSS_CHANGE_SOURCE);
3138 priv->relevant_changes = _gtk_style_provider_private_get_change (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
3142 priv->relevant_changes = 0;
3144 priv->relevant_changes &= ~GTK_STYLE_CONTEXT_RADICAL_CHANGE;
3146 gtk_widget_path_unref (path);
3150 if (priv->relevant_changes & change)
3157 gtk_style_context_should_create_transitions (GtkStyleContext *context)
3159 GtkStyleContextPrivate *priv;
3162 priv = context->priv;
3164 if (priv->widget == NULL)
3167 if (!gtk_widget_get_mapped (priv->widget))
3170 g_object_get (gtk_widget_get_settings (context->priv->widget),
3171 "gtk-enable-animations", &animate,
3178 _gtk_style_context_validate (GtkStyleContext *context,
3180 GtkCssChange change,
3181 const GtkBitmask *parent_changes)
3183 GtkStyleContextPrivate *priv;
3186 GtkBitmask *changes;
3189 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3191 priv = context->priv;
3193 change |= priv->pending_changes;
3195 /* If you run your application with
3196 * GTK_DEBUG=no-css-cache
3197 * every invalidation will purge the cache and completely query
3198 * everything anew form the cache. This is slow (in particular
3199 * when animating), but useful for figuring out bugs.
3201 * We achieve that by pretending that everything that could have
3202 * changed has and so we of course totally need to redo everything.
3204 * Note that this also completely revalidates child widgets all
3207 if (G_UNLIKELY (gtk_get_debug_flags () & GTK_DEBUG_NO_CSS_CACHE))
3208 change = GTK_CSS_CHANGE_ANY;
3210 if (!priv->invalid && change == 0 && _gtk_bitmask_is_empty (parent_changes))
3213 priv->pending_changes = 0;
3214 gtk_style_context_set_invalid (context, FALSE);
3218 current = style_data_ref (info->data);
3222 /* Try to avoid invalidating if we can */
3223 if (current == NULL ||
3224 gtk_style_context_needs_full_revalidate (context, change))
3228 if ((priv->relevant_changes & change) & ~GTK_STYLE_CONTEXT_CACHED_CHANGE)
3230 gtk_style_context_clear_cache (context);
3234 gtk_style_context_update_cache (context, parent_changes);
3235 style_info_set_data (info, NULL);
3238 data = style_data_lookup (context);
3240 _gtk_css_computed_values_create_animations (data->store,
3241 priv->parent ? style_data_lookup (priv->parent)->store : NULL,
3243 GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
3244 current && gtk_style_context_should_create_transitions (context) ? current->store : NULL);
3245 if (_gtk_css_computed_values_is_static (data->store))
3246 change &= ~GTK_CSS_CHANGE_ANIMATE;
3248 change |= GTK_CSS_CHANGE_ANIMATE;
3249 _gtk_style_context_update_animating (context);
3253 changes = _gtk_css_computed_values_get_difference (data->store, current->store);
3255 /* In the case where we keep the cache, we want unanimated values */
3256 _gtk_css_computed_values_cancel_animations (current->store);
3260 changes = _gtk_bitmask_new ();
3261 changes = _gtk_bitmask_invert_range (changes, 0, _gtk_css_style_property_get_n_properties ());
3266 changes = _gtk_css_computed_values_compute_dependencies (current->store, parent_changes);
3268 gtk_style_context_update_cache (context, parent_changes);
3272 style_data_unref (current);
3274 if (change & GTK_CSS_CHANGE_ANIMATE &&
3275 gtk_style_context_is_animating (context))
3277 GtkBitmask *animation_changes;
3279 animation_changes = gtk_style_context_update_animations (context, timestamp);
3280 changes = _gtk_bitmask_union (changes, animation_changes);
3281 _gtk_bitmask_free (animation_changes);
3284 if (change & GTK_CSS_CHANGE_FORCE_INVALIDATE)
3286 GtkBitmask *full = _gtk_bitmask_new ();
3287 full = _gtk_bitmask_invert_range (full,
3289 _gtk_css_style_property_get_n_properties ());
3290 gtk_style_context_do_invalidate (context, full);
3291 _gtk_bitmask_free (full);
3293 else if (!_gtk_bitmask_is_empty (changes))
3295 gtk_style_context_do_invalidate (context, changes);
3298 change = _gtk_css_change_for_child (change);
3299 for (list = priv->children; list; list = list->next)
3301 _gtk_style_context_validate (list->data, timestamp, change, changes);
3304 _gtk_bitmask_free (changes);
3308 _gtk_style_context_queue_invalidate (GtkStyleContext *context,
3309 GtkCssChange change)
3311 GtkStyleContextPrivate *priv;
3313 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3314 g_return_if_fail (change != 0);
3316 priv = context->priv;
3318 if (priv->widget != NULL)
3320 priv->pending_changes |= change;
3321 gtk_style_context_set_invalid (context, TRUE);
3323 else if (priv->widget_path == NULL)
3325 gtk_style_context_invalidate (context);
3330 * gtk_style_context_invalidate:
3331 * @context: a #GtkStyleContext.
3333 * Invalidates @context style information, so it will be reconstructed
3336 * If you're using a #GtkStyleContext returned from
3337 * gtk_widget_get_style_context(), you do not need to
3338 * call this yourself.
3343 gtk_style_context_invalidate (GtkStyleContext *context)
3345 GtkBitmask *changes;
3347 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3349 gtk_style_context_clear_cache (context);
3351 changes = _gtk_bitmask_new ();
3352 changes = _gtk_bitmask_invert_range (changes,
3354 _gtk_css_style_property_get_n_properties ());
3355 gtk_style_context_do_invalidate (context, changes);
3356 _gtk_bitmask_free (changes);
3360 corner_value_is_right_angle (GtkCssValue *value)
3362 return _gtk_css_corner_value_get_x (value, 100) <= 0.0 &&
3363 _gtk_css_corner_value_get_y (value, 100) <= 0.0;
3367 * gtk_style_context_set_background:
3368 * @context: a #GtkStyleContext
3369 * @window: a #GdkWindow
3371 * Sets the background of @window to the background pattern or
3372 * color specified in @context for its current state.
3377 gtk_style_context_set_background (GtkStyleContext *context,
3380 const GdkRGBA *color;
3382 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3383 g_return_if_fail (GDK_IS_WINDOW (window));
3385 /* This is a sophisitcated optimization.
3386 * If we know the GDK window's background will be opaque, we mark
3387 * it as opaque. This is so GDK can do all the optimizations it does
3388 * for opaque windows and be fast.
3389 * This is mainly used when scrolling.
3391 * We could indeed just set black instead of the color we have.
3393 color = _gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BACKGROUND_COLOR));
3395 if (color->alpha >= 1.0 &&
3396 corner_value_is_right_angle (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_TOP_LEFT_RADIUS)) &&
3397 corner_value_is_right_angle (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_TOP_RIGHT_RADIUS)) &&
3398 corner_value_is_right_angle (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_BOTTOM_RIGHT_RADIUS)) &&
3399 corner_value_is_right_angle (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_BOTTOM_LEFT_RADIUS)))
3401 gdk_window_set_background_rgba (window, color);
3405 GdkRGBA transparent = { 0.0, 0.0, 0.0, 0.0 };
3406 gdk_window_set_background_rgba (window, &transparent);
3411 * gtk_style_context_get_color:
3412 * @context: a #GtkStyleContext
3413 * @state: state to retrieve the color for
3414 * @color: (out): return value for the foreground color
3416 * Gets the foreground color for a given state.
3421 gtk_style_context_get_color (GtkStyleContext *context,
3422 GtkStateFlags state,
3427 g_return_if_fail (color != NULL);
3428 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3430 gtk_style_context_get (context,
3440 * gtk_style_context_get_background_color:
3441 * @context: a #GtkStyleContext
3442 * @state: state to retrieve the color for
3443 * @color: (out): return value for the background color
3445 * Gets the background color for a given state.
3450 gtk_style_context_get_background_color (GtkStyleContext *context,
3451 GtkStateFlags state,
3456 g_return_if_fail (color != NULL);
3457 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3459 gtk_style_context_get (context,
3461 "background-color", &c,
3469 * gtk_style_context_get_border_color:
3470 * @context: a #GtkStyleContext
3471 * @state: state to retrieve the color for
3472 * @color: (out): return value for the border color
3474 * Gets the border color for a given state.
3479 gtk_style_context_get_border_color (GtkStyleContext *context,
3480 GtkStateFlags state,
3485 g_return_if_fail (color != NULL);
3486 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3488 gtk_style_context_get (context,
3498 * gtk_style_context_get_border:
3499 * @context: a #GtkStyleContext
3500 * @state: state to retrieve the border for
3501 * @border: (out): return value for the border settings
3503 * Gets the border for a given state as a #GtkBorder.
3504 * See %GTK_STYLE_PROPERTY_BORDER_WIDTH.
3509 gtk_style_context_get_border (GtkStyleContext *context,
3510 GtkStateFlags state,
3513 int top, left, bottom, right;
3515 g_return_if_fail (border != NULL);
3516 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3518 gtk_style_context_get (context,
3520 "border-top-width", &top,
3521 "border-left-width", &left,
3522 "border-bottom-width", &bottom,
3523 "border-right-width", &right,
3527 border->left = left;
3528 border->bottom = bottom;
3529 border->right = right;
3533 * gtk_style_context_get_padding:
3534 * @context: a #GtkStyleContext
3535 * @state: state to retrieve the padding for
3536 * @padding: (out): return value for the padding settings
3538 * Gets the padding for a given state as a #GtkBorder.
3539 * See %GTK_STYLE_PROPERTY_PADDING.
3544 gtk_style_context_get_padding (GtkStyleContext *context,
3545 GtkStateFlags state,
3548 int top, left, bottom, right;
3550 g_return_if_fail (padding != NULL);
3551 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3553 gtk_style_context_get (context,
3555 "padding-top", &top,
3556 "padding-left", &left,
3557 "padding-bottom", &bottom,
3558 "padding-right", &right,
3562 padding->left = left;
3563 padding->bottom = bottom;
3564 padding->right = right;
3568 * gtk_style_context_get_margin:
3569 * @context: a #GtkStyleContext
3570 * @state: state to retrieve the border for
3571 * @margin: (out): return value for the margin settings
3573 * Gets the margin for a given state as a #GtkBorder.
3574 * See %GTK_STYLE_PROPERTY_MARGIN.
3579 gtk_style_context_get_margin (GtkStyleContext *context,
3580 GtkStateFlags state,
3583 int top, left, bottom, right;
3585 g_return_if_fail (margin != NULL);
3586 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3588 gtk_style_context_get (context,
3591 "margin-left", &left,
3592 "margin-bottom", &bottom,
3593 "margin-right", &right,
3597 margin->left = left;
3598 margin->bottom = bottom;
3599 margin->right = right;
3603 * gtk_style_context_get_font:
3604 * @context: a #GtkStyleContext
3605 * @state: state to retrieve the font for
3607 * Returns the font description for a given state. The returned
3608 * object is const and will remain valid until the
3609 * #GtkStyleContext::changed signal happens.
3611 * Returns: (transfer none): the #PangoFontDescription for the given
3612 * state. This object is owned by GTK+ and should not be
3617 * Deprecated: 3.8: Use gtk_style_context_get() for "font" or
3618 * subproperties instead.
3620 const PangoFontDescription *
3621 gtk_style_context_get_font (GtkStyleContext *context,
3622 GtkStateFlags state)
3624 GtkStyleContextPrivate *priv;
3626 PangoFontDescription *description, *previous;
3628 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
3630 priv = context->priv;
3631 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
3633 data = style_data_lookup_for_state (context, state);
3635 /* Yuck, fonts are created on-demand but we don't return a ref.
3636 * Do bad things to achieve this requirement */
3637 gtk_style_context_get (context, state, "font", &description, NULL);
3639 previous = g_object_get_data (G_OBJECT (data->store), "font-cache-for-get_font");
3643 pango_font_description_merge (previous, description, TRUE);
3644 pango_font_description_free (description);
3645 description = previous;
3649 g_object_set_data_full (G_OBJECT (data->store),
3650 "font-cache-for-get_font",
3652 (GDestroyNotify) pango_font_description_free);
3659 get_cursor_color (GtkStyleContext *context,
3663 GdkColor *style_color;
3665 gtk_style_context_get_style (context,
3666 primary ? "cursor-color" : "secondary-cursor-color",
3672 color->red = style_color->red / 65535.0;
3673 color->green = style_color->green / 65535.0;
3674 color->blue = style_color->blue / 65535.0;
3677 gdk_color_free (style_color);
3681 gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, color);
3687 gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &bg);
3689 color->red = (color->red + bg.red) * 0.5;
3690 color->green = (color->green + bg.green) * 0.5;
3691 color->blue = (color->blue + bg.blue) * 0.5;
3697 _gtk_style_context_get_cursor_color (GtkStyleContext *context,
3698 GdkRGBA *primary_color,
3699 GdkRGBA *secondary_color)
3702 get_cursor_color (context, TRUE, primary_color);
3704 if (secondary_color)
3705 get_cursor_color (context, FALSE, secondary_color);
3712 * @context: a #GtkStyleContext
3714 * @x: X origin of the rectangle
3715 * @y: Y origin of the rectangle
3716 * @width: rectangle width
3717 * @height: rectangle height
3719 * Renders a checkmark (as in a #GtkCheckButton).
3721 * The %GTK_STATE_FLAG_ACTIVE state determines whether the check is
3722 * on or off, and %GTK_STATE_FLAG_INCONSISTENT determines whether it
3723 * should be marked as undefined.
3726 * <title>Typical checkmark rendering</title>
3727 * <inlinegraphic fileref="checks.png" format="PNG"/>
3733 gtk_render_check (GtkStyleContext *context,
3740 GtkThemingEngineClass *engine_class;
3741 GtkThemingEngine *engine;
3743 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3744 g_return_if_fail (cr != NULL);
3746 if (width <= 0 || height <= 0)
3749 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3750 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3755 _gtk_theming_engine_set_context (engine, context);
3756 engine_class->render_check (engine, cr,
3757 x, y, width, height);
3763 * gtk_render_option:
3764 * @context: a #GtkStyleContext
3766 * @x: X origin of the rectangle
3767 * @y: Y origin of the rectangle
3768 * @width: rectangle width
3769 * @height: rectangle height
3771 * Renders an option mark (as in a #GtkRadioButton), the %GTK_STATE_FLAG_ACTIVE
3772 * state will determine whether the option is on or off, and
3773 * %GTK_STATE_FLAG_INCONSISTENT whether it should be marked as undefined.
3776 * <title>Typical option mark rendering</title>
3777 * <inlinegraphic fileref="options.png" format="PNG"/>
3783 gtk_render_option (GtkStyleContext *context,
3790 GtkThemingEngineClass *engine_class;
3791 GtkThemingEngine *engine;
3793 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3794 g_return_if_fail (cr != NULL);
3796 if (width <= 0 || height <= 0)
3799 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3800 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3804 _gtk_theming_engine_set_context (engine, context);
3805 engine_class->render_option (engine, cr,
3806 x, y, width, height);
3813 * @context: a #GtkStyleContext
3815 * @angle: arrow angle from 0 to 2 * %G_PI, being 0 the arrow pointing to the north
3816 * @x: X origin of the render area
3817 * @y: Y origin of the render area
3818 * @size: square side for render area
3820 * Renders an arrow pointing to @angle.
3823 * <title>Typical arrow rendering at 0, 1&solidus;2 π, π and 3&solidus;2 π</title>
3824 * <inlinegraphic fileref="arrows.png" format="PNG"/>
3830 gtk_render_arrow (GtkStyleContext *context,
3837 GtkThemingEngineClass *engine_class;
3838 GtkThemingEngine *engine;
3840 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3841 g_return_if_fail (cr != NULL);
3846 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3847 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3851 gtk_style_context_save (context);
3852 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ARROW);
3854 _gtk_theming_engine_set_context (engine, context);
3855 engine_class->render_arrow (engine, cr,
3858 gtk_style_context_restore (context);
3863 * gtk_render_background:
3864 * @context: a #GtkStyleContext
3866 * @x: X origin of the rectangle
3867 * @y: Y origin of the rectangle
3868 * @width: rectangle width
3869 * @height: rectangle height
3871 * Renders the background of an element.
3874 * <title>Typical background rendering, showing the effect of
3875 * <parameter>background-image</parameter>,
3876 * <parameter>border-width</parameter> and
3877 * <parameter>border-radius</parameter></title>
3878 * <inlinegraphic fileref="background.png" format="PNG"/>
3884 gtk_render_background (GtkStyleContext *context,
3891 GtkThemingEngineClass *engine_class;
3892 GtkThemingEngine *engine;
3894 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3895 g_return_if_fail (cr != NULL);
3897 if (width <= 0 || height <= 0)
3900 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3901 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3905 _gtk_theming_engine_set_context (engine, context);
3906 engine_class->render_background (engine, cr, x, y, width, height);
3913 * @context: a #GtkStyleContext
3915 * @x: X origin of the rectangle
3916 * @y: Y origin of the rectangle
3917 * @width: rectangle width
3918 * @height: rectangle height
3920 * Renders a frame around the rectangle defined by @x, @y, @width, @height.
3923 * <title>Examples of frame rendering, showing the effect of
3924 * <parameter>border-image</parameter>,
3925 * <parameter>border-color</parameter>,
3926 * <parameter>border-width</parameter>,
3927 * <parameter>border-radius</parameter> and
3929 * <inlinegraphic fileref="frames.png" format="PNG"/>
3935 gtk_render_frame (GtkStyleContext *context,
3942 GtkThemingEngineClass *engine_class;
3943 GtkThemingEngine *engine;
3945 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3946 g_return_if_fail (cr != NULL);
3948 if (width <= 0 || height <= 0)
3951 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3952 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3956 _gtk_theming_engine_set_context (engine, context);
3957 engine_class->render_frame (engine, cr, x, y, width, height);
3963 * gtk_render_expander:
3964 * @context: a #GtkStyleContext
3966 * @x: X origin of the rectangle
3967 * @y: Y origin of the rectangle
3968 * @width: rectangle width
3969 * @height: rectangle height
3971 * Renders an expander (as used in #GtkTreeView and #GtkExpander) in the area
3972 * defined by @x, @y, @width, @height. The state %GTK_STATE_FLAG_ACTIVE
3973 * determines whether the expander is collapsed or expanded.
3976 * <title>Typical expander rendering</title>
3977 * <inlinegraphic fileref="expanders.png" format="PNG"/>
3983 gtk_render_expander (GtkStyleContext *context,
3990 GtkThemingEngineClass *engine_class;
3991 GtkThemingEngine *engine;
3993 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3994 g_return_if_fail (cr != NULL);
3996 if (width <= 0 || height <= 0)
3999 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4000 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4004 _gtk_theming_engine_set_context (engine, context);
4005 engine_class->render_expander (engine, cr, x, y, width, height);
4012 * @context: a #GtkStyleContext
4014 * @x: X origin of the rectangle
4015 * @y: Y origin of the rectangle
4016 * @width: rectangle width
4017 * @height: rectangle height
4019 * Renders a focus indicator on the rectangle determined by @x, @y, @width, @height.
4021 * <title>Typical focus rendering</title>
4022 * <inlinegraphic fileref="focus.png" format="PNG"/>
4028 gtk_render_focus (GtkStyleContext *context,
4035 GtkThemingEngineClass *engine_class;
4036 GtkThemingEngine *engine;
4038 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4039 g_return_if_fail (cr != NULL);
4041 if (width <= 0 || height <= 0)
4044 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4045 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4049 _gtk_theming_engine_set_context (engine, context);
4050 engine_class->render_focus (engine, cr, x, y, width, height);
4056 * gtk_render_layout:
4057 * @context: a #GtkStyleContext
4061 * @layout: the #PangoLayout to render
4063 * Renders @layout on the coordinates @x, @y
4068 gtk_render_layout (GtkStyleContext *context,
4072 PangoLayout *layout)
4074 GtkThemingEngineClass *engine_class;
4075 GtkThemingEngine *engine;
4076 PangoRectangle extents;
4078 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4079 g_return_if_fail (PANGO_IS_LAYOUT (layout));
4080 g_return_if_fail (cr != NULL);
4082 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4083 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4087 pango_layout_get_extents (layout, &extents, NULL);
4089 _gtk_theming_engine_set_context (engine, context);
4090 engine_class->render_layout (engine, cr, x, y, layout);
4097 * @context: a #GtkStyleContext
4099 * @x0: X coordinate for the origin of the line
4100 * @y0: Y coordinate for the origin of the line
4101 * @x1: X coordinate for the end of the line
4102 * @y1: Y coordinate for the end of the line
4104 * Renders a line from (x0, y0) to (x1, y1).
4109 gtk_render_line (GtkStyleContext *context,
4116 GtkThemingEngineClass *engine_class;
4117 GtkThemingEngine *engine;
4119 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4120 g_return_if_fail (cr != NULL);
4122 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4123 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4127 _gtk_theming_engine_set_context (engine, context);
4128 engine_class->render_line (engine, cr, x0, y0, x1, y1);
4134 * gtk_render_slider:
4135 * @context: a #GtkStyleContext
4137 * @x: X origin of the rectangle
4138 * @y: Y origin of the rectangle
4139 * @width: rectangle width
4140 * @height: rectangle height
4141 * @orientation: orientation of the slider
4143 * Renders a slider (as in #GtkScale) in the rectangle defined by @x, @y,
4144 * @width, @height. @orientation defines whether the slider is vertical
4148 * <title>Typical slider rendering</title>
4149 * <inlinegraphic fileref="sliders.png" format="PNG"/>
4155 gtk_render_slider (GtkStyleContext *context,
4161 GtkOrientation orientation)
4163 GtkThemingEngineClass *engine_class;
4164 GtkThemingEngine *engine;
4166 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4167 g_return_if_fail (cr != NULL);
4169 if (width <= 0 || height <= 0)
4172 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4173 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4177 _gtk_theming_engine_set_context (engine, context);
4178 engine_class->render_slider (engine, cr, x, y, width, height, orientation);
4184 * gtk_render_frame_gap:
4185 * @context: a #GtkStyleContext
4187 * @x: X origin of the rectangle
4188 * @y: Y origin of the rectangle
4189 * @width: rectangle width
4190 * @height: rectangle height
4191 * @gap_side: side where the gap is
4192 * @xy0_gap: initial coordinate (X or Y depending on @gap_side) for the gap
4193 * @xy1_gap: end coordinate (X or Y depending on @gap_side) for the gap
4195 * Renders a frame around the rectangle defined by (@x, @y, @width, @height),
4196 * leaving a gap on one side. @xy0_gap and @xy1_gap will mean X coordinates
4197 * for %GTK_POS_TOP and %GTK_POS_BOTTOM gap sides, and Y coordinates for
4198 * %GTK_POS_LEFT and %GTK_POS_RIGHT.
4201 * <title>Typical rendering of a frame with a gap</title>
4202 * <inlinegraphic fileref="frame-gap.png" format="PNG"/>
4208 gtk_render_frame_gap (GtkStyleContext *context,
4214 GtkPositionType gap_side,
4218 GtkThemingEngineClass *engine_class;
4219 GtkThemingEngine *engine;
4221 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4222 g_return_if_fail (cr != NULL);
4223 g_return_if_fail (xy0_gap <= xy1_gap);
4224 g_return_if_fail (xy0_gap >= 0);
4226 if (width <= 0 || height <= 0)
4229 if (gap_side == GTK_POS_LEFT ||
4230 gap_side == GTK_POS_RIGHT)
4231 g_return_if_fail (xy1_gap <= height);
4233 g_return_if_fail (xy1_gap <= width);
4235 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4236 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4240 _gtk_theming_engine_set_context (engine, context);
4241 engine_class->render_frame_gap (engine, cr,
4242 x, y, width, height, gap_side,
4249 * gtk_render_extension:
4250 * @context: a #GtkStyleContext
4252 * @x: X origin of the rectangle
4253 * @y: Y origin of the rectangle
4254 * @width: rectangle width
4255 * @height: rectangle height
4256 * @gap_side: side where the gap is
4258 * Renders a extension (as in a #GtkNotebook tab) in the rectangle
4259 * defined by @x, @y, @width, @height. The side where the extension
4260 * connects to is defined by @gap_side.
4263 * <title>Typical extension rendering</title>
4264 * <inlinegraphic fileref="extensions.png" format="PNG"/>
4270 gtk_render_extension (GtkStyleContext *context,
4276 GtkPositionType gap_side)
4278 GtkThemingEngineClass *engine_class;
4279 GtkThemingEngine *engine;
4281 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4282 g_return_if_fail (cr != NULL);
4284 if (width <= 0 || height <= 0)
4287 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4288 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4292 _gtk_theming_engine_set_context (engine, context);
4293 engine_class->render_extension (engine, cr, x, y, width, height, gap_side);
4299 * gtk_render_handle:
4300 * @context: a #GtkStyleContext
4302 * @x: X origin of the rectangle
4303 * @y: Y origin of the rectangle
4304 * @width: rectangle width
4305 * @height: rectangle height
4307 * Renders a handle (as in #GtkHandleBox, #GtkPaned and
4308 * #GtkWindow<!-- -->'s resize grip), in the rectangle
4309 * determined by @x, @y, @width, @height.
4312 * <title>Handles rendered for the paned and grip classes</title>
4313 * <inlinegraphic fileref="handles.png" format="PNG"/>
4319 gtk_render_handle (GtkStyleContext *context,
4326 GtkThemingEngineClass *engine_class;
4327 GtkThemingEngine *engine;
4329 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4330 g_return_if_fail (cr != NULL);
4332 if (width <= 0 || height <= 0)
4335 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4336 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4340 _gtk_theming_engine_set_context (engine, context);
4341 engine_class->render_handle (engine, cr, x, y, width, height);
4347 * gtk_render_activity:
4348 * @context: a #GtkStyleContext
4350 * @x: X origin of the rectangle
4351 * @y: Y origin of the rectangle
4352 * @width: rectangle width
4353 * @height: rectangle height
4355 * Renders an activity area (Such as in #GtkSpinner or the
4356 * fill line in #GtkRange), the state %GTK_STATE_FLAG_ACTIVE
4357 * determines whether there is activity going on.
4362 gtk_render_activity (GtkStyleContext *context,
4369 GtkThemingEngineClass *engine_class;
4370 GtkThemingEngine *engine;
4372 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4373 g_return_if_fail (cr != NULL);
4375 if (width <= 0 || height <= 0)
4378 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4379 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4383 _gtk_theming_engine_set_context (engine, context);
4384 engine_class->render_activity (engine, cr, x, y, width, height);
4390 * gtk_render_icon_pixbuf:
4391 * @context: a #GtkStyleContext
4392 * @source: the #GtkIconSource specifying the icon to render
4393 * @size: (type int): the size to render the icon at. A size of (GtkIconSize) -1
4394 * means render at the size of the source and don't scale.
4396 * Renders the icon specified by @source at the given @size, returning the result
4399 * Returns: (transfer full): a newly-created #GdkPixbuf containing the rendered icon
4404 gtk_render_icon_pixbuf (GtkStyleContext *context,
4405 const GtkIconSource *source,
4408 GtkThemingEngineClass *engine_class;
4409 GtkThemingEngine *engine;
4411 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
4412 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
4413 g_return_val_if_fail (source != NULL, NULL);
4415 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4416 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4418 _gtk_theming_engine_set_context (engine, context);
4419 return engine_class->render_icon_pixbuf (engine, source, size);
4424 * @context: a #GtkStyleContext
4426 * @pixbuf: a #GdkPixbuf containing the icon to draw
4427 * @x: X position for the @pixbuf
4428 * @y: Y position for the @pixbuf
4430 * Renders the icon in @pixbuf at the specified @x and @y coordinates.
4435 gtk_render_icon (GtkStyleContext *context,
4441 GtkThemingEngineClass *engine_class;
4442 GtkThemingEngine *engine;
4444 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4445 g_return_if_fail (cr != NULL);
4447 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4448 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4452 _gtk_theming_engine_set_context (engine, context);
4453 engine_class->render_icon (engine, cr, pixbuf, x, y);
4459 draw_insertion_cursor (GtkStyleContext *context,
4464 gboolean is_primary,
4465 PangoDirection direction,
4466 gboolean draw_arrow)
4469 GdkRGBA primary_color;
4470 GdkRGBA secondary_color;
4471 gfloat cursor_aspect_ratio;
4477 _gtk_style_context_get_cursor_color (context, &primary_color, &secondary_color);
4478 gdk_cairo_set_source_rgba (cr, is_primary ? &primary_color : &secondary_color);
4480 /* When changing the shape or size of the cursor here,
4481 * propagate the changes to gtktextview.c:text_window_invalidate_cursors().
4484 gtk_style_context_get_style (context,
4485 "cursor-aspect-ratio", &cursor_aspect_ratio,
4488 stem_width = height * cursor_aspect_ratio + 1;
4490 /* put (stem_width % 2) on the proper side of the cursor */
4491 if (direction == PANGO_DIRECTION_LTR)
4492 offset = stem_width / 2;
4494 offset = stem_width - stem_width / 2;
4496 cairo_rectangle (cr, x - offset, y, stem_width, height);
4504 arrow_width = stem_width + 1;
4506 if (direction == PANGO_DIRECTION_RTL)
4508 ax = x - offset - 1;
4509 ay = y + height - arrow_width * 2 - arrow_width + 1;
4511 cairo_move_to (cr, ax, ay + 1);
4512 cairo_line_to (cr, ax - arrow_width, ay + arrow_width);
4513 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4516 else if (direction == PANGO_DIRECTION_LTR)
4518 ax = x + stem_width - offset;
4519 ay = y + height - arrow_width * 2 - arrow_width + 1;
4521 cairo_move_to (cr, ax, ay + 1);
4522 cairo_line_to (cr, ax + arrow_width, ay + arrow_width);
4523 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4527 g_assert_not_reached();
4534 * gtk_render_insertion_cursor:
4535 * @context: a #GtkStyleContext
4539 * @layout: the #PangoLayout of the text
4540 * @index: the index in the #PangoLayout
4541 * @direction: the #PangoDirection of the text
4543 * Draws a text caret on @cr at the specified index of @layout.
4548 gtk_render_insertion_cursor (GtkStyleContext *context,
4552 PangoLayout *layout,
4554 PangoDirection direction)
4556 GtkStyleContextPrivate *priv;
4557 gboolean split_cursor;
4558 PangoRectangle strong_pos, weak_pos;
4559 PangoRectangle *cursor1, *cursor2;
4560 PangoDirection keymap_direction;
4561 PangoDirection direction2;
4563 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4564 g_return_if_fail (cr != NULL);
4565 g_return_if_fail (PANGO_IS_LAYOUT (layout));
4566 g_return_if_fail (index >= 0);
4568 priv = context->priv;
4570 g_object_get (gtk_settings_get_for_screen (priv->screen),
4571 "gtk-split-cursor", &split_cursor,
4574 keymap_direction = gdk_keymap_get_direction (gdk_keymap_get_for_display (gdk_screen_get_display (priv->screen)));
4576 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4578 direction2 = PANGO_DIRECTION_NEUTRAL;
4582 cursor1 = &strong_pos;
4584 if (strong_pos.x != weak_pos.x || strong_pos.y != weak_pos.y)
4586 direction2 = (direction == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
4587 cursor2 = &weak_pos;
4592 if (keymap_direction == direction)
4593 cursor1 = &strong_pos;
4595 cursor1 = &weak_pos;
4598 draw_insertion_cursor (context,
4600 x + PANGO_PIXELS (cursor1->x),
4601 y + PANGO_PIXELS (cursor1->y),
4602 PANGO_PIXELS (cursor1->height),
4605 direction2 != PANGO_DIRECTION_NEUTRAL);
4607 if (direction2 != PANGO_DIRECTION_NEUTRAL)
4609 draw_insertion_cursor (context,
4611 x + PANGO_PIXELS (cursor2->x),
4612 y + PANGO_PIXELS (cursor2->y),
4613 PANGO_PIXELS (cursor2->height),
4621 * gtk_draw_insertion_cursor:
4622 * @widget: a #GtkWidget
4623 * @cr: cairo context to draw to
4624 * @location: location where to draw the cursor (@location->width is ignored)
4625 * @is_primary: if the cursor should be the primary cursor color.
4626 * @direction: whether the cursor is left-to-right or
4627 * right-to-left. Should never be #GTK_TEXT_DIR_NONE
4628 * @draw_arrow: %TRUE to draw a directional arrow on the
4629 * cursor. Should be %FALSE unless the cursor is split.
4631 * Draws a text caret on @cr at @location. This is not a style function
4632 * but merely a convenience function for drawing the standard cursor shape.
4635 * Deprecated: 3.4: Use gtk_render_insertion_cursor() instead.
4638 gtk_draw_insertion_cursor (GtkWidget *widget,
4640 const GdkRectangle *location,
4641 gboolean is_primary,
4642 GtkTextDirection direction,
4643 gboolean draw_arrow)
4645 GtkStyleContext *context;
4647 g_return_if_fail (GTK_IS_WIDGET (widget));
4648 g_return_if_fail (cr != NULL);
4649 g_return_if_fail (location != NULL);
4650 g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
4652 context = gtk_widget_get_style_context (widget);
4654 draw_insertion_cursor (context, cr,
4655 location->x, location->y, location->height,
4657 (direction == GTK_TEXT_DIR_RTL) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR,
4662 * _gtk_style_context_get_changes:
4663 * @context: the context to query
4665 * Queries the context for the changes for the currently executing
4666 * GtkStyleContext::invalidate signal. If no signal is currently
4667 * emitted, this function returns %NULL.
4669 * FIXME 4.0: Make this part of the signal.
4671 * Returns: %NULL or the currently invalidating changes
4674 _gtk_style_context_get_changes (GtkStyleContext *context)
4676 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
4678 return context->priv->invalidating_context;
4681 static AtkAttributeSet *
4682 add_attribute (AtkAttributeSet *attributes,
4683 AtkTextAttribute attr,
4688 at = g_new (AtkAttribute, 1);
4689 at->name = g_strdup (atk_text_attribute_get_name (attr));
4690 at->value = g_strdup (value);
4692 return g_slist_prepend (attributes, at);
4696 * _gtk_style_context_get_attributes:
4697 * @attributes: a #AtkAttributeSet to add attributes to
4698 * @context: the #GtkStyleContext to get attributes from
4699 * @flags: the state to use with @context
4701 * Adds the foreground and background color from @context to
4702 * @attributes, after translating them to ATK attributes.
4704 * This is a convenience function that can be used in
4705 * implementing the #AtkText interface in widgets.
4707 * Returns: the modified #AtkAttributeSet
4710 _gtk_style_context_get_attributes (AtkAttributeSet *attributes,
4711 GtkStyleContext *context,
4712 GtkStateFlags flags)
4717 gtk_style_context_get_background_color (context, flags, &color);
4718 value = g_strdup_printf ("%u,%u,%u",
4719 (guint) ceil (color.red * 65536 - color.red),
4720 (guint) ceil (color.green * 65536 - color.green),
4721 (guint) ceil (color.blue * 65536 - color.blue));
4722 attributes = add_attribute (attributes, ATK_TEXT_ATTR_BG_COLOR, value);
4725 gtk_style_context_get_color (context, flags, &color);
4726 value = g_strdup_printf ("%u,%u,%u",
4727 (guint) ceil (color.red * 65536 - color.red),
4728 (guint) ceil (color.green * 65536 - color.green),
4729 (guint) ceil (color.blue * 65536 - color.blue));
4730 attributes = add_attribute (attributes, ATK_TEXT_ATTR_FG_COLOR, value);
4737 gtk_gradient_resolve_for_context (GtkGradient *gradient,
4738 GtkStyleContext *context)
4740 GtkStyleContextPrivate *priv = context->priv;
4741 GtkCssDependencies ignored = 0;
4743 g_return_val_if_fail (gradient != NULL, NULL);
4744 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
4746 return _gtk_gradient_resolve_full (gradient,
4747 GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
4748 style_data_lookup (context)->store,
4749 priv->parent ? style_data_lookup (priv->parent)->store : NULL,