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 (!_gtk_bitmask_is_empty (changes) || (change & GTK_CSS_CHANGE_FORCE_INVALIDATE))
3285 gtk_style_context_do_invalidate (context, changes);
3287 change = _gtk_css_change_for_child (change);
3288 for (list = priv->children; list; list = list->next)
3290 _gtk_style_context_validate (list->data, timestamp, change, changes);
3293 _gtk_bitmask_free (changes);
3297 _gtk_style_context_queue_invalidate (GtkStyleContext *context,
3298 GtkCssChange change)
3300 GtkStyleContextPrivate *priv;
3302 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3303 g_return_if_fail (change != 0);
3305 priv = context->priv;
3307 if (priv->widget != NULL)
3309 priv->pending_changes |= change;
3310 gtk_style_context_set_invalid (context, TRUE);
3312 else if (priv->widget_path == NULL)
3314 gtk_style_context_invalidate (context);
3319 * gtk_style_context_invalidate:
3320 * @context: a #GtkStyleContext.
3322 * Invalidates @context style information, so it will be reconstructed
3325 * If you're using a #GtkStyleContext returned from
3326 * gtk_widget_get_style_context(), you do not need to
3327 * call this yourself.
3332 gtk_style_context_invalidate (GtkStyleContext *context)
3334 GtkBitmask *changes;
3336 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3338 gtk_style_context_clear_cache (context);
3340 changes = _gtk_bitmask_new ();
3341 changes = _gtk_bitmask_invert_range (changes,
3343 _gtk_css_style_property_get_n_properties ());
3344 gtk_style_context_do_invalidate (context, changes);
3345 _gtk_bitmask_free (changes);
3349 corner_value_is_right_angle (GtkCssValue *value)
3351 return _gtk_css_corner_value_get_x (value, 100) <= 0.0 &&
3352 _gtk_css_corner_value_get_y (value, 100) <= 0.0;
3356 * gtk_style_context_set_background:
3357 * @context: a #GtkStyleContext
3358 * @window: a #GdkWindow
3360 * Sets the background of @window to the background pattern or
3361 * color specified in @context for its current state.
3366 gtk_style_context_set_background (GtkStyleContext *context,
3369 const GdkRGBA *color;
3371 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3372 g_return_if_fail (GDK_IS_WINDOW (window));
3374 /* This is a sophisitcated optimization.
3375 * If we know the GDK window's background will be opaque, we mark
3376 * it as opaque. This is so GDK can do all the optimizations it does
3377 * for opaque windows and be fast.
3378 * This is mainly used when scrolling.
3380 * We could indeed just set black instead of the color we have.
3382 color = _gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BACKGROUND_COLOR));
3384 if (color->alpha >= 1.0 &&
3385 corner_value_is_right_angle (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_TOP_LEFT_RADIUS)) &&
3386 corner_value_is_right_angle (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_TOP_RIGHT_RADIUS)) &&
3387 corner_value_is_right_angle (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_BOTTOM_RIGHT_RADIUS)) &&
3388 corner_value_is_right_angle (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_BOTTOM_LEFT_RADIUS)))
3390 gdk_window_set_background_rgba (window, color);
3394 GdkRGBA transparent = { 0.0, 0.0, 0.0, 0.0 };
3395 gdk_window_set_background_rgba (window, &transparent);
3400 * gtk_style_context_get_color:
3401 * @context: a #GtkStyleContext
3402 * @state: state to retrieve the color for
3403 * @color: (out): return value for the foreground color
3405 * Gets the foreground color for a given state.
3410 gtk_style_context_get_color (GtkStyleContext *context,
3411 GtkStateFlags state,
3416 g_return_if_fail (color != NULL);
3417 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3419 gtk_style_context_get (context,
3429 * gtk_style_context_get_background_color:
3430 * @context: a #GtkStyleContext
3431 * @state: state to retrieve the color for
3432 * @color: (out): return value for the background color
3434 * Gets the background color for a given state.
3439 gtk_style_context_get_background_color (GtkStyleContext *context,
3440 GtkStateFlags state,
3445 g_return_if_fail (color != NULL);
3446 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3448 gtk_style_context_get (context,
3450 "background-color", &c,
3458 * gtk_style_context_get_border_color:
3459 * @context: a #GtkStyleContext
3460 * @state: state to retrieve the color for
3461 * @color: (out): return value for the border color
3463 * Gets the border color for a given state.
3468 gtk_style_context_get_border_color (GtkStyleContext *context,
3469 GtkStateFlags state,
3474 g_return_if_fail (color != NULL);
3475 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3477 gtk_style_context_get (context,
3487 * gtk_style_context_get_border:
3488 * @context: a #GtkStyleContext
3489 * @state: state to retrieve the border for
3490 * @border: (out): return value for the border settings
3492 * Gets the border for a given state as a #GtkBorder.
3493 * See %GTK_STYLE_PROPERTY_BORDER_WIDTH.
3498 gtk_style_context_get_border (GtkStyleContext *context,
3499 GtkStateFlags state,
3502 int top, left, bottom, right;
3504 g_return_if_fail (border != NULL);
3505 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3507 gtk_style_context_get (context,
3509 "border-top-width", &top,
3510 "border-left-width", &left,
3511 "border-bottom-width", &bottom,
3512 "border-right-width", &right,
3516 border->left = left;
3517 border->bottom = bottom;
3518 border->right = right;
3522 * gtk_style_context_get_padding:
3523 * @context: a #GtkStyleContext
3524 * @state: state to retrieve the padding for
3525 * @padding: (out): return value for the padding settings
3527 * Gets the padding for a given state as a #GtkBorder.
3528 * See %GTK_STYLE_PROPERTY_PADDING.
3533 gtk_style_context_get_padding (GtkStyleContext *context,
3534 GtkStateFlags state,
3537 int top, left, bottom, right;
3539 g_return_if_fail (padding != NULL);
3540 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3542 gtk_style_context_get (context,
3544 "padding-top", &top,
3545 "padding-left", &left,
3546 "padding-bottom", &bottom,
3547 "padding-right", &right,
3551 padding->left = left;
3552 padding->bottom = bottom;
3553 padding->right = right;
3557 * gtk_style_context_get_margin:
3558 * @context: a #GtkStyleContext
3559 * @state: state to retrieve the border for
3560 * @margin: (out): return value for the margin settings
3562 * Gets the margin for a given state as a #GtkBorder.
3563 * See %GTK_STYLE_PROPERTY_MARGIN.
3568 gtk_style_context_get_margin (GtkStyleContext *context,
3569 GtkStateFlags state,
3572 int top, left, bottom, right;
3574 g_return_if_fail (margin != NULL);
3575 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3577 gtk_style_context_get (context,
3580 "margin-left", &left,
3581 "margin-bottom", &bottom,
3582 "margin-right", &right,
3586 margin->left = left;
3587 margin->bottom = bottom;
3588 margin->right = right;
3592 * gtk_style_context_get_font:
3593 * @context: a #GtkStyleContext
3594 * @state: state to retrieve the font for
3596 * Returns the font description for a given state. The returned
3597 * object is const and will remain valid until the
3598 * #GtkStyleContext::changed signal happens.
3600 * Returns: (transfer none): the #PangoFontDescription for the given
3601 * state. This object is owned by GTK+ and should not be
3606 * Deprecated: 3.8: Use gtk_style_context_get() for "font" or
3607 * subproperties instead.
3609 const PangoFontDescription *
3610 gtk_style_context_get_font (GtkStyleContext *context,
3611 GtkStateFlags state)
3613 GtkStyleContextPrivate *priv;
3615 PangoFontDescription *description, *previous;
3617 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
3619 priv = context->priv;
3620 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
3622 data = style_data_lookup_for_state (context, state);
3624 /* Yuck, fonts are created on-demand but we don't return a ref.
3625 * Do bad things to achieve this requirement */
3626 gtk_style_context_get (context, state, "font", &description, NULL);
3628 previous = g_object_get_data (G_OBJECT (data->store), "font-cache-for-get_font");
3632 pango_font_description_merge (previous, description, TRUE);
3633 pango_font_description_free (description);
3634 description = previous;
3638 g_object_set_data_full (G_OBJECT (data->store),
3639 "font-cache-for-get_font",
3641 (GDestroyNotify) pango_font_description_free);
3648 get_cursor_color (GtkStyleContext *context,
3652 GdkColor *style_color;
3654 gtk_style_context_get_style (context,
3655 primary ? "cursor-color" : "secondary-cursor-color",
3661 color->red = style_color->red / 65535.0;
3662 color->green = style_color->green / 65535.0;
3663 color->blue = style_color->blue / 65535.0;
3666 gdk_color_free (style_color);
3670 gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, color);
3676 gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &bg);
3678 color->red = (color->red + bg.red) * 0.5;
3679 color->green = (color->green + bg.green) * 0.5;
3680 color->blue = (color->blue + bg.blue) * 0.5;
3686 _gtk_style_context_get_cursor_color (GtkStyleContext *context,
3687 GdkRGBA *primary_color,
3688 GdkRGBA *secondary_color)
3691 get_cursor_color (context, TRUE, primary_color);
3693 if (secondary_color)
3694 get_cursor_color (context, FALSE, secondary_color);
3701 * @context: a #GtkStyleContext
3703 * @x: X origin of the rectangle
3704 * @y: Y origin of the rectangle
3705 * @width: rectangle width
3706 * @height: rectangle height
3708 * Renders a checkmark (as in a #GtkCheckButton).
3710 * The %GTK_STATE_FLAG_ACTIVE state determines whether the check is
3711 * on or off, and %GTK_STATE_FLAG_INCONSISTENT determines whether it
3712 * should be marked as undefined.
3715 * <title>Typical checkmark rendering</title>
3716 * <inlinegraphic fileref="checks.png" format="PNG"/>
3722 gtk_render_check (GtkStyleContext *context,
3729 GtkThemingEngineClass *engine_class;
3730 GtkThemingEngine *engine;
3732 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3733 g_return_if_fail (cr != NULL);
3735 if (width <= 0 || height <= 0)
3738 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3739 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3744 _gtk_theming_engine_set_context (engine, context);
3745 engine_class->render_check (engine, cr,
3746 x, y, width, height);
3752 * gtk_render_option:
3753 * @context: a #GtkStyleContext
3755 * @x: X origin of the rectangle
3756 * @y: Y origin of the rectangle
3757 * @width: rectangle width
3758 * @height: rectangle height
3760 * Renders an option mark (as in a #GtkRadioButton), the %GTK_STATE_FLAG_ACTIVE
3761 * state will determine whether the option is on or off, and
3762 * %GTK_STATE_FLAG_INCONSISTENT whether it should be marked as undefined.
3765 * <title>Typical option mark rendering</title>
3766 * <inlinegraphic fileref="options.png" format="PNG"/>
3772 gtk_render_option (GtkStyleContext *context,
3779 GtkThemingEngineClass *engine_class;
3780 GtkThemingEngine *engine;
3782 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3783 g_return_if_fail (cr != NULL);
3785 if (width <= 0 || height <= 0)
3788 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3789 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3793 _gtk_theming_engine_set_context (engine, context);
3794 engine_class->render_option (engine, cr,
3795 x, y, width, height);
3802 * @context: a #GtkStyleContext
3804 * @angle: arrow angle from 0 to 2 * %G_PI, being 0 the arrow pointing to the north
3805 * @x: X origin of the render area
3806 * @y: Y origin of the render area
3807 * @size: square side for render area
3809 * Renders an arrow pointing to @angle.
3812 * <title>Typical arrow rendering at 0, 1&solidus;2 π, π and 3&solidus;2 π</title>
3813 * <inlinegraphic fileref="arrows.png" format="PNG"/>
3819 gtk_render_arrow (GtkStyleContext *context,
3826 GtkThemingEngineClass *engine_class;
3827 GtkThemingEngine *engine;
3829 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3830 g_return_if_fail (cr != NULL);
3835 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3836 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3840 gtk_style_context_save (context);
3841 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ARROW);
3843 _gtk_theming_engine_set_context (engine, context);
3844 engine_class->render_arrow (engine, cr,
3847 gtk_style_context_restore (context);
3852 * gtk_render_background:
3853 * @context: a #GtkStyleContext
3855 * @x: X origin of the rectangle
3856 * @y: Y origin of the rectangle
3857 * @width: rectangle width
3858 * @height: rectangle height
3860 * Renders the background of an element.
3863 * <title>Typical background rendering, showing the effect of
3864 * <parameter>background-image</parameter>,
3865 * <parameter>border-width</parameter> and
3866 * <parameter>border-radius</parameter></title>
3867 * <inlinegraphic fileref="background.png" format="PNG"/>
3873 gtk_render_background (GtkStyleContext *context,
3880 GtkThemingEngineClass *engine_class;
3881 GtkThemingEngine *engine;
3883 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3884 g_return_if_fail (cr != NULL);
3886 if (width <= 0 || height <= 0)
3889 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3890 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3894 _gtk_theming_engine_set_context (engine, context);
3895 engine_class->render_background (engine, cr, x, y, width, height);
3902 * @context: a #GtkStyleContext
3904 * @x: X origin of the rectangle
3905 * @y: Y origin of the rectangle
3906 * @width: rectangle width
3907 * @height: rectangle height
3909 * Renders a frame around the rectangle defined by @x, @y, @width, @height.
3912 * <title>Examples of frame rendering, showing the effect of
3913 * <parameter>border-image</parameter>,
3914 * <parameter>border-color</parameter>,
3915 * <parameter>border-width</parameter>,
3916 * <parameter>border-radius</parameter> and
3918 * <inlinegraphic fileref="frames.png" format="PNG"/>
3924 gtk_render_frame (GtkStyleContext *context,
3931 GtkThemingEngineClass *engine_class;
3932 GtkThemingEngine *engine;
3934 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3935 g_return_if_fail (cr != NULL);
3937 if (width <= 0 || height <= 0)
3940 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3941 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3945 _gtk_theming_engine_set_context (engine, context);
3946 engine_class->render_frame (engine, cr, x, y, width, height);
3952 * gtk_render_expander:
3953 * @context: a #GtkStyleContext
3955 * @x: X origin of the rectangle
3956 * @y: Y origin of the rectangle
3957 * @width: rectangle width
3958 * @height: rectangle height
3960 * Renders an expander (as used in #GtkTreeView and #GtkExpander) in the area
3961 * defined by @x, @y, @width, @height. The state %GTK_STATE_FLAG_ACTIVE
3962 * determines whether the expander is collapsed or expanded.
3965 * <title>Typical expander rendering</title>
3966 * <inlinegraphic fileref="expanders.png" format="PNG"/>
3972 gtk_render_expander (GtkStyleContext *context,
3979 GtkThemingEngineClass *engine_class;
3980 GtkThemingEngine *engine;
3982 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3983 g_return_if_fail (cr != NULL);
3985 if (width <= 0 || height <= 0)
3988 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3989 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3993 _gtk_theming_engine_set_context (engine, context);
3994 engine_class->render_expander (engine, cr, x, y, width, height);
4001 * @context: a #GtkStyleContext
4003 * @x: X origin of the rectangle
4004 * @y: Y origin of the rectangle
4005 * @width: rectangle width
4006 * @height: rectangle height
4008 * Renders a focus indicator on the rectangle determined by @x, @y, @width, @height.
4010 * <title>Typical focus rendering</title>
4011 * <inlinegraphic fileref="focus.png" format="PNG"/>
4017 gtk_render_focus (GtkStyleContext *context,
4024 GtkThemingEngineClass *engine_class;
4025 GtkThemingEngine *engine;
4027 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4028 g_return_if_fail (cr != NULL);
4030 if (width <= 0 || height <= 0)
4033 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4034 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4038 _gtk_theming_engine_set_context (engine, context);
4039 engine_class->render_focus (engine, cr, x, y, width, height);
4045 * gtk_render_layout:
4046 * @context: a #GtkStyleContext
4050 * @layout: the #PangoLayout to render
4052 * Renders @layout on the coordinates @x, @y
4057 gtk_render_layout (GtkStyleContext *context,
4061 PangoLayout *layout)
4063 GtkThemingEngineClass *engine_class;
4064 GtkThemingEngine *engine;
4065 PangoRectangle extents;
4067 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4068 g_return_if_fail (PANGO_IS_LAYOUT (layout));
4069 g_return_if_fail (cr != NULL);
4071 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4072 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4076 pango_layout_get_extents (layout, &extents, NULL);
4078 _gtk_theming_engine_set_context (engine, context);
4079 engine_class->render_layout (engine, cr, x, y, layout);
4086 * @context: a #GtkStyleContext
4088 * @x0: X coordinate for the origin of the line
4089 * @y0: Y coordinate for the origin of the line
4090 * @x1: X coordinate for the end of the line
4091 * @y1: Y coordinate for the end of the line
4093 * Renders a line from (x0, y0) to (x1, y1).
4098 gtk_render_line (GtkStyleContext *context,
4105 GtkThemingEngineClass *engine_class;
4106 GtkThemingEngine *engine;
4108 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4109 g_return_if_fail (cr != NULL);
4111 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4112 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4116 _gtk_theming_engine_set_context (engine, context);
4117 engine_class->render_line (engine, cr, x0, y0, x1, y1);
4123 * gtk_render_slider:
4124 * @context: a #GtkStyleContext
4126 * @x: X origin of the rectangle
4127 * @y: Y origin of the rectangle
4128 * @width: rectangle width
4129 * @height: rectangle height
4130 * @orientation: orientation of the slider
4132 * Renders a slider (as in #GtkScale) in the rectangle defined by @x, @y,
4133 * @width, @height. @orientation defines whether the slider is vertical
4137 * <title>Typical slider rendering</title>
4138 * <inlinegraphic fileref="sliders.png" format="PNG"/>
4144 gtk_render_slider (GtkStyleContext *context,
4150 GtkOrientation orientation)
4152 GtkThemingEngineClass *engine_class;
4153 GtkThemingEngine *engine;
4155 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4156 g_return_if_fail (cr != NULL);
4158 if (width <= 0 || height <= 0)
4161 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4162 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4166 _gtk_theming_engine_set_context (engine, context);
4167 engine_class->render_slider (engine, cr, x, y, width, height, orientation);
4173 * gtk_render_frame_gap:
4174 * @context: a #GtkStyleContext
4176 * @x: X origin of the rectangle
4177 * @y: Y origin of the rectangle
4178 * @width: rectangle width
4179 * @height: rectangle height
4180 * @gap_side: side where the gap is
4181 * @xy0_gap: initial coordinate (X or Y depending on @gap_side) for the gap
4182 * @xy1_gap: end coordinate (X or Y depending on @gap_side) for the gap
4184 * Renders a frame around the rectangle defined by (@x, @y, @width, @height),
4185 * leaving a gap on one side. @xy0_gap and @xy1_gap will mean X coordinates
4186 * for %GTK_POS_TOP and %GTK_POS_BOTTOM gap sides, and Y coordinates for
4187 * %GTK_POS_LEFT and %GTK_POS_RIGHT.
4190 * <title>Typical rendering of a frame with a gap</title>
4191 * <inlinegraphic fileref="frame-gap.png" format="PNG"/>
4197 gtk_render_frame_gap (GtkStyleContext *context,
4203 GtkPositionType gap_side,
4207 GtkThemingEngineClass *engine_class;
4208 GtkThemingEngine *engine;
4210 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4211 g_return_if_fail (cr != NULL);
4212 g_return_if_fail (xy0_gap <= xy1_gap);
4213 g_return_if_fail (xy0_gap >= 0);
4215 if (width <= 0 || height <= 0)
4218 if (gap_side == GTK_POS_LEFT ||
4219 gap_side == GTK_POS_RIGHT)
4220 g_return_if_fail (xy1_gap <= height);
4222 g_return_if_fail (xy1_gap <= width);
4224 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4225 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4229 _gtk_theming_engine_set_context (engine, context);
4230 engine_class->render_frame_gap (engine, cr,
4231 x, y, width, height, gap_side,
4238 * gtk_render_extension:
4239 * @context: a #GtkStyleContext
4241 * @x: X origin of the rectangle
4242 * @y: Y origin of the rectangle
4243 * @width: rectangle width
4244 * @height: rectangle height
4245 * @gap_side: side where the gap is
4247 * Renders a extension (as in a #GtkNotebook tab) in the rectangle
4248 * defined by @x, @y, @width, @height. The side where the extension
4249 * connects to is defined by @gap_side.
4252 * <title>Typical extension rendering</title>
4253 * <inlinegraphic fileref="extensions.png" format="PNG"/>
4259 gtk_render_extension (GtkStyleContext *context,
4265 GtkPositionType gap_side)
4267 GtkThemingEngineClass *engine_class;
4268 GtkThemingEngine *engine;
4270 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4271 g_return_if_fail (cr != NULL);
4273 if (width <= 0 || height <= 0)
4276 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4277 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4281 _gtk_theming_engine_set_context (engine, context);
4282 engine_class->render_extension (engine, cr, x, y, width, height, gap_side);
4288 * gtk_render_handle:
4289 * @context: a #GtkStyleContext
4291 * @x: X origin of the rectangle
4292 * @y: Y origin of the rectangle
4293 * @width: rectangle width
4294 * @height: rectangle height
4296 * Renders a handle (as in #GtkHandleBox, #GtkPaned and
4297 * #GtkWindow<!-- -->'s resize grip), in the rectangle
4298 * determined by @x, @y, @width, @height.
4301 * <title>Handles rendered for the paned and grip classes</title>
4302 * <inlinegraphic fileref="handles.png" format="PNG"/>
4308 gtk_render_handle (GtkStyleContext *context,
4315 GtkThemingEngineClass *engine_class;
4316 GtkThemingEngine *engine;
4318 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4319 g_return_if_fail (cr != NULL);
4321 if (width <= 0 || height <= 0)
4324 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4325 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4329 _gtk_theming_engine_set_context (engine, context);
4330 engine_class->render_handle (engine, cr, x, y, width, height);
4336 * gtk_render_activity:
4337 * @context: a #GtkStyleContext
4339 * @x: X origin of the rectangle
4340 * @y: Y origin of the rectangle
4341 * @width: rectangle width
4342 * @height: rectangle height
4344 * Renders an activity area (Such as in #GtkSpinner or the
4345 * fill line in #GtkRange), the state %GTK_STATE_FLAG_ACTIVE
4346 * determines whether there is activity going on.
4351 gtk_render_activity (GtkStyleContext *context,
4358 GtkThemingEngineClass *engine_class;
4359 GtkThemingEngine *engine;
4361 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4362 g_return_if_fail (cr != NULL);
4364 if (width <= 0 || height <= 0)
4367 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4368 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4372 _gtk_theming_engine_set_context (engine, context);
4373 engine_class->render_activity (engine, cr, x, y, width, height);
4379 * gtk_render_icon_pixbuf:
4380 * @context: a #GtkStyleContext
4381 * @source: the #GtkIconSource specifying the icon to render
4382 * @size: (type int): the size to render the icon at. A size of (GtkIconSize) -1
4383 * means render at the size of the source and don't scale.
4385 * Renders the icon specified by @source at the given @size, returning the result
4388 * Returns: (transfer full): a newly-created #GdkPixbuf containing the rendered icon
4393 gtk_render_icon_pixbuf (GtkStyleContext *context,
4394 const GtkIconSource *source,
4397 GtkThemingEngineClass *engine_class;
4398 GtkThemingEngine *engine;
4400 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
4401 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
4402 g_return_val_if_fail (source != NULL, NULL);
4404 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4405 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4407 _gtk_theming_engine_set_context (engine, context);
4408 return engine_class->render_icon_pixbuf (engine, source, size);
4413 * @context: a #GtkStyleContext
4415 * @pixbuf: a #GdkPixbuf containing the icon to draw
4416 * @x: X position for the @pixbuf
4417 * @y: Y position for the @pixbuf
4419 * Renders the icon in @pixbuf at the specified @x and @y coordinates.
4424 gtk_render_icon (GtkStyleContext *context,
4430 GtkThemingEngineClass *engine_class;
4431 GtkThemingEngine *engine;
4433 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4434 g_return_if_fail (cr != NULL);
4436 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4437 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4441 _gtk_theming_engine_set_context (engine, context);
4442 engine_class->render_icon (engine, cr, pixbuf, x, y);
4448 draw_insertion_cursor (GtkStyleContext *context,
4453 gboolean is_primary,
4454 PangoDirection direction,
4455 gboolean draw_arrow)
4458 GdkRGBA primary_color;
4459 GdkRGBA secondary_color;
4460 gfloat cursor_aspect_ratio;
4466 _gtk_style_context_get_cursor_color (context, &primary_color, &secondary_color);
4467 gdk_cairo_set_source_rgba (cr, is_primary ? &primary_color : &secondary_color);
4469 /* When changing the shape or size of the cursor here,
4470 * propagate the changes to gtktextview.c:text_window_invalidate_cursors().
4473 gtk_style_context_get_style (context,
4474 "cursor-aspect-ratio", &cursor_aspect_ratio,
4477 stem_width = height * cursor_aspect_ratio + 1;
4479 /* put (stem_width % 2) on the proper side of the cursor */
4480 if (direction == PANGO_DIRECTION_LTR)
4481 offset = stem_width / 2;
4483 offset = stem_width - stem_width / 2;
4485 cairo_rectangle (cr, x - offset, y, stem_width, height);
4493 arrow_width = stem_width + 1;
4495 if (direction == PANGO_DIRECTION_RTL)
4497 ax = x - offset - 1;
4498 ay = y + height - arrow_width * 2 - arrow_width + 1;
4500 cairo_move_to (cr, ax, ay + 1);
4501 cairo_line_to (cr, ax - arrow_width, ay + arrow_width);
4502 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4505 else if (direction == PANGO_DIRECTION_LTR)
4507 ax = x + stem_width - offset;
4508 ay = y + height - arrow_width * 2 - arrow_width + 1;
4510 cairo_move_to (cr, ax, ay + 1);
4511 cairo_line_to (cr, ax + arrow_width, ay + arrow_width);
4512 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4516 g_assert_not_reached();
4523 * gtk_render_insertion_cursor:
4524 * @context: a #GtkStyleContext
4528 * @layout: the #PangoLayout of the text
4529 * @index: the index in the #PangoLayout
4530 * @direction: the #PangoDirection of the text
4532 * Draws a text caret on @cr at the specified index of @layout.
4537 gtk_render_insertion_cursor (GtkStyleContext *context,
4541 PangoLayout *layout,
4543 PangoDirection direction)
4545 GtkStyleContextPrivate *priv;
4546 gboolean split_cursor;
4547 PangoRectangle strong_pos, weak_pos;
4548 PangoRectangle *cursor1, *cursor2;
4549 PangoDirection keymap_direction;
4550 PangoDirection direction2;
4552 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4553 g_return_if_fail (cr != NULL);
4554 g_return_if_fail (PANGO_IS_LAYOUT (layout));
4555 g_return_if_fail (index >= 0);
4557 priv = context->priv;
4559 g_object_get (gtk_settings_get_for_screen (priv->screen),
4560 "gtk-split-cursor", &split_cursor,
4563 keymap_direction = gdk_keymap_get_direction (gdk_keymap_get_for_display (gdk_screen_get_display (priv->screen)));
4565 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4567 direction2 = PANGO_DIRECTION_NEUTRAL;
4571 cursor1 = &strong_pos;
4573 if (strong_pos.x != weak_pos.x || strong_pos.y != weak_pos.y)
4575 direction2 = (direction == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
4576 cursor2 = &weak_pos;
4581 if (keymap_direction == direction)
4582 cursor1 = &strong_pos;
4584 cursor1 = &weak_pos;
4587 draw_insertion_cursor (context,
4589 x + PANGO_PIXELS (cursor1->x),
4590 y + PANGO_PIXELS (cursor1->y),
4591 PANGO_PIXELS (cursor1->height),
4594 direction2 != PANGO_DIRECTION_NEUTRAL);
4596 if (direction2 != PANGO_DIRECTION_NEUTRAL)
4598 draw_insertion_cursor (context,
4600 x + PANGO_PIXELS (cursor2->x),
4601 y + PANGO_PIXELS (cursor2->y),
4602 PANGO_PIXELS (cursor2->height),
4610 * gtk_draw_insertion_cursor:
4611 * @widget: a #GtkWidget
4612 * @cr: cairo context to draw to
4613 * @location: location where to draw the cursor (@location->width is ignored)
4614 * @is_primary: if the cursor should be the primary cursor color.
4615 * @direction: whether the cursor is left-to-right or
4616 * right-to-left. Should never be #GTK_TEXT_DIR_NONE
4617 * @draw_arrow: %TRUE to draw a directional arrow on the
4618 * cursor. Should be %FALSE unless the cursor is split.
4620 * Draws a text caret on @cr at @location. This is not a style function
4621 * but merely a convenience function for drawing the standard cursor shape.
4624 * Deprecated: 3.4: Use gtk_render_insertion_cursor() instead.
4627 gtk_draw_insertion_cursor (GtkWidget *widget,
4629 const GdkRectangle *location,
4630 gboolean is_primary,
4631 GtkTextDirection direction,
4632 gboolean draw_arrow)
4634 GtkStyleContext *context;
4636 g_return_if_fail (GTK_IS_WIDGET (widget));
4637 g_return_if_fail (cr != NULL);
4638 g_return_if_fail (location != NULL);
4639 g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
4641 context = gtk_widget_get_style_context (widget);
4643 draw_insertion_cursor (context, cr,
4644 location->x, location->y, location->height,
4646 (direction == GTK_TEXT_DIR_RTL) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR,
4651 * _gtk_style_context_get_changes:
4652 * @context: the context to query
4654 * Queries the context for the changes for the currently executing
4655 * GtkStyleContext::invalidate signal. If no signal is currently
4656 * emitted, this function returns %NULL.
4658 * FIXME 4.0: Make this part of the signal.
4660 * Returns: %NULL or the currently invalidating changes
4663 _gtk_style_context_get_changes (GtkStyleContext *context)
4665 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
4667 return context->priv->invalidating_context;
4670 static AtkAttributeSet *
4671 add_attribute (AtkAttributeSet *attributes,
4672 AtkTextAttribute attr,
4677 at = g_new (AtkAttribute, 1);
4678 at->name = g_strdup (atk_text_attribute_get_name (attr));
4679 at->value = g_strdup (value);
4681 return g_slist_prepend (attributes, at);
4685 * _gtk_style_context_get_attributes:
4686 * @attributes: a #AtkAttributeSet to add attributes to
4687 * @context: the #GtkStyleContext to get attributes from
4688 * @flags: the state to use with @context
4690 * Adds the foreground and background color from @context to
4691 * @attributes, after translating them to ATK attributes.
4693 * This is a convenience function that can be used in
4694 * implementing the #AtkText interface in widgets.
4696 * Returns: the modified #AtkAttributeSet
4699 _gtk_style_context_get_attributes (AtkAttributeSet *attributes,
4700 GtkStyleContext *context,
4701 GtkStateFlags flags)
4706 gtk_style_context_get_background_color (context, flags, &color);
4707 value = g_strdup_printf ("%u,%u,%u",
4708 (guint) ceil (color.red * 65536 - color.red),
4709 (guint) ceil (color.green * 65536 - color.green),
4710 (guint) ceil (color.blue * 65536 - color.blue));
4711 attributes = add_attribute (attributes, ATK_TEXT_ATTR_BG_COLOR, value);
4714 gtk_style_context_get_color (context, flags, &color);
4715 value = g_strdup_printf ("%u,%u,%u",
4716 (guint) ceil (color.red * 65536 - color.red),
4717 (guint) ceil (color.green * 65536 - color.green),
4718 (guint) ceil (color.blue * 65536 - color.blue));
4719 attributes = add_attribute (attributes, ATK_TEXT_ATTR_FG_COLOR, value);
4726 gtk_gradient_resolve_for_context (GtkGradient *gradient,
4727 GtkStyleContext *context)
4729 GtkStyleContextPrivate *priv = context->priv;
4730 GtkCssDependencies ignored = 0;
4732 g_return_val_if_fail (gradient != NULL, NULL);
4733 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
4735 return _gtk_gradient_resolve_full (gradient,
4736 GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
4737 style_data_lookup (context)->store,
4738 priv->parent ? style_data_lookup (priv->parent)->store : NULL,