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 "gtkcssanimatedvaluesprivate.h"
28 #include "gtkcssenginevalueprivate.h"
29 #include "gtkcssnumbervalueprivate.h"
30 #include "gtkcssrgbavalueprivate.h"
32 #include "gtkstylepropertiesprivate.h"
33 #include "gtktypebuiltins.h"
34 #include "gtkthemingengineprivate.h"
36 #include "gtkwidget.h"
37 #include "gtkwindow.h"
38 #include "gtkprivate.h"
39 #include "gtksymboliccolorprivate.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"
49 * SECTION:gtkstylecontext
50 * @Short_description: Rendering UI elements
51 * @Title: GtkStyleContext
53 * #GtkStyleContext is an object that stores styling information affecting
54 * a widget defined by #GtkWidgetPath.
56 * In order to construct the final style information, #GtkStyleContext
57 * queries information from all attached #GtkStyleProviders. Style providers
58 * can be either attached explicitly to the context through
59 * gtk_style_context_add_provider(), or to the screen through
60 * gtk_style_context_add_provider_for_screen(). The resulting style is a
61 * combination of all providers' information in priority order.
63 * For GTK+ widgets, any #GtkStyleContext returned by
64 * gtk_widget_get_style_context() will already have a #GtkWidgetPath, a
65 * #GdkScreen and RTL/LTR information set. The style context will be also
66 * updated automatically if any of these settings change on the widget.
68 * If you are using the theming layer standalone, you will need to set a
69 * widget path and a screen yourself to the created style context through
70 * gtk_style_context_set_path() and gtk_style_context_set_screen(), as well
71 * as updating the context yourself using gtk_style_context_invalidate()
72 * whenever any of the conditions change, such as a change in the
73 * #GtkSettings:gtk-theme-name setting or a hierarchy change in the rendered
76 * <refsect2 id="gtkstylecontext-animations">
77 * <title>Transition animations</title>
79 * #GtkStyleContext has built-in support for state change transitions.
80 * Note that these animations respect the #GtkSettings:gtk-enable-animations
84 * For simple widgets where state changes affect the whole widget area,
85 * calling gtk_style_context_notify_state_change() with a %NULL region
86 * is sufficient to trigger the transition animation. And GTK+ already
87 * does that when gtk_widget_set_state() or gtk_widget_set_state_flags()
91 * If a widget needs to declare several animatable regions (i.e. not
92 * affecting the whole widget area), its #GtkWidget::draw signal handler
93 * needs to wrap the render operations for the different regions with
94 * calls to gtk_style_context_push_animatable_region() and
95 * gtk_style_context_pop_animatable_region(). These functions take an
96 * identifier for the region which must be unique within the style context.
97 * For simple widgets with a fixed set of animatable regions, using an
98 * enumeration works well:
101 * <title>Using an enumeration to identify animatable regions</title>
112 * spin_button_draw (GtkWidget *widget,
115 * GtkStyleContext *context;
117 * context = gtk_widget_get_style_context (widget);
119 * gtk_style_context_push_animatable_region (context,
120 * GUINT_TO_POINTER (REGION_ENTRY));
122 * gtk_render_background (cr, 0, 0, 100, 30);
123 * gtk_render_frame (cr, 0, 0, 100, 30);
125 * gtk_style_context_pop_animatable_region (context);
132 * For complex widgets with an arbitrary number of animatable regions, it
133 * is up to the implementation to come up with a way to uniquely identify
134 * each animatable region. Using pointers to internal structs is one way
138 * <title>Using struct pointers to identify animatable regions</title>
141 * notebook_draw_tab (GtkWidget *widget,
142 * NotebookPage *page,
145 * gtk_style_context_push_animatable_region (context, page);
146 * gtk_render_extension (cr, page->x, page->y, page->width, page->height);
147 * gtk_style_context_pop_animatable_region (context);
152 * The widget also needs to notify the style context about a state change
153 * for a given animatable region so the animation is triggered.
156 * <title>Triggering a state change animation on a region</title>
159 * notebook_motion_notify (GtkWidget *widget,
160 * GdkEventMotion *event)
162 * GtkStyleContext *context;
163 * NotebookPage *page;
165 * context = gtk_widget_get_style_context (widget);
166 * page = find_page_under_pointer (widget, event);
167 * gtk_style_context_notify_state_change (context,
168 * gtk_widget_get_window (widget),
170 * GTK_STATE_PRELIGHT,
177 * gtk_style_context_notify_state_change() accepts %NULL region IDs as a
178 * special value, in this case, the whole widget area will be updated
182 * <refsect2 id="gtkstylecontext-classes">
183 * <title>Style classes and regions</title>
185 * Widgets can add style classes to their context, which can be used
186 * to associate different styles by class (see <xref linkend="gtkcssprovider-selectors"/>). Theme engines can also use style classes to vary their
187 * rendering. GTK+ has a number of predefined style classes:
188 * #GTK_STYLE_CLASS_CELL,
189 * #GTK_STYLE_CLASS_ENTRY,
190 * #GTK_STYLE_CLASS_BUTTON,
191 * #GTK_STYLE_CLASS_COMBOBOX_ENTRY,
192 * #GTK_STYLE_CLASS_CALENDAR,
193 * #GTK_STYLE_CLASS_SLIDER,
194 * #GTK_STYLE_CLASS_BACKGROUND,
195 * #GTK_STYLE_CLASS_RUBBERBAND,
196 * #GTK_STYLE_CLASS_TOOLTIP,
197 * #GTK_STYLE_CLASS_MENU,
198 * #GTK_STYLE_CLASS_MENUBAR,
199 * #GTK_STYLE_CLASS_MENUITEM,
200 * #GTK_STYLE_CLASS_TOOLBAR,
201 * #GTK_STYLE_CLASS_PRIMARY_TOOLBAR,
202 * #GTK_STYLE_CLASS_INLINE_TOOLBAR,
203 * #GTK_STYLE_CLASS_RADIO,
204 * #GTK_STYLE_CLASS_CHECK,
205 * #GTK_STYLE_CLASS_TROUGH,
206 * #GTK_STYLE_CLASS_SCROLLBAR,
207 * #GTK_STYLE_CLASS_SCALE,
208 * #GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE,
209 * #GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW,
210 * #GTK_STYLE_CLASS_HEADER,
211 * #GTK_STYLE_CLASS_ACCELERATOR,
212 * #GTK_STYLE_CLASS_GRIP,
213 * #GTK_STYLE_CLASS_DOCK,
214 * #GTK_STYLE_CLASS_PROGRESSBAR,
215 * #GTK_STYLE_CLASS_SPINNER,
216 * #GTK_STYLE_CLASS_EXPANDER,
217 * #GTK_STYLE_CLASS_SPINBUTTON,
218 * #GTK_STYLE_CLASS_NOTEBOOK,
219 * #GTK_STYLE_CLASS_VIEW,
220 * #GTK_STYLE_CLASS_SIDEBAR,
221 * #GTK_STYLE_CLASS_IMAGE,
222 * #GTK_STYLE_CLASS_HIGHLIGHT,
223 * #GTK_STYLE_CLASS_FRAME,
224 * #GTK_STYLE_CLASS_DND,
225 * #GTK_STYLE_CLASS_PANE_SEPARATOR,
226 * #GTK_STYLE_CLASS_SEPARATOR,
227 * #GTK_STYLE_CLASS_INFO,
228 * #GTK_STYLE_CLASS_WARNING,
229 * #GTK_STYLE_CLASS_QUESTION,
230 * #GTK_STYLE_CLASS_ERROR,
231 * #GTK_STYLE_CLASS_HORIZONTAL,
232 * #GTK_STYLE_CLASS_VERTICAL,
233 * #GTK_STYLE_CLASS_TOP,
234 * #GTK_STYLE_CLASS_BOTTOM,
235 * #GTK_STYLE_CLASS_LEFT,
236 * #GTK_STYLE_CLASS_RIGHT,
239 * Widgets can also add regions with flags to their context.
240 * The regions used by GTK+ widgets are:
245 * <entry>Region</entry>
246 * <entry>Flags</entry>
247 * <entry>Macro</entry>
248 * <entry>Used by</entry>
254 * <entry>even, odd</entry>
255 * <entry>GTK_STYLE_REGION_ROW</entry>
256 * <entry>#GtkTreeView</entry>
259 * <entry>column</entry>
260 * <entry>first, last, sorted</entry>
261 * <entry>GTK_STYLE_REGION_COLUMN</entry>
262 * <entry>#GtkTreeView</entry>
265 * <entry>column-header</entry>
267 * <entry>GTK_STYLE_REGION_COLUMN_HEADER</entry>
272 * <entry>even, odd, first, last</entry>
273 * <entry>GTK_STYLE_REGION_TAB</entry>
274 * <entry>#GtkNotebook</entry>
281 * <refsect2 id="gtkstylecontext-custom-styling">
282 * <title>Custom styling in UI libraries and applications</title>
284 * If you are developing a library with custom #GtkWidget<!-- -->s that
285 * render differently than standard components, you may need to add a
286 * #GtkStyleProvider yourself with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK
287 * priority, either a #GtkCssProvider or a custom object implementing the
288 * #GtkStyleProvider interface. This way theming engines may still attempt
289 * to style your UI elements in a different way if needed so.
292 * If you are using custom styling on an applications, you probably want then
293 * to make your style information prevail to the theme's, so you must use
294 * a #GtkStyleProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
295 * priority, keep in mind that the user settings in
296 * <filename><replaceable>XDG_CONFIG_HOME</replaceable>/gtk-3.0/gtk.css</filename> will
297 * still take precedence over your changes, as it uses the
298 * %GTK_STYLE_PROVIDER_PRIORITY_USER priority.
301 * If a custom theming engine is needed, you probably want to implement a
302 * #GtkStyleProvider yourself so it points to your #GtkThemingEngine
303 * implementation, as #GtkCssProvider uses gtk_theming_engine_load()
304 * which loads the theming engine module from the standard paths.
309 /* When these change we do a full restyling. Otherwise we try to figure out
310 * if we need to change things. */
311 #define GTK_STYLE_CONTEXT_RADICAL_CHANGE (GTK_CSS_CHANGE_NAME | GTK_CSS_CHANGE_CLASS | GTK_CSS_CHANGE_SOURCE)
312 /* When these change we don't clear the cache. This takes more memory but makes
313 * things go faster. */
314 #define GTK_STYLE_CONTEXT_CACHED_CHANGE (GTK_CSS_CHANGE_STATE)
316 typedef struct GtkStyleInfo GtkStyleInfo;
317 typedef struct GtkRegion GtkRegion;
318 typedef struct PropertyValue PropertyValue;
319 typedef struct StyleData StyleData;
324 GtkRegionFlags flags;
338 GArray *style_classes;
340 GtkJunctionSides junction_sides;
341 GtkStateFlags state_flags;
347 GtkCssComputedValues *store;
348 GArray *property_cache;
352 struct _GtkStyleContextPrivate
356 GtkStyleCascade *cascade;
358 GtkStyleContext *animation_list_prev;
359 GtkStyleContext *animation_list_next;
361 GtkStyleContext *parent;
364 GtkWidgetPath *widget_path;
365 GHashTable *style_data;
368 GtkTextDirection direction;
370 GtkCssChange relevant_changes;
371 GtkCssChange pending_changes;
373 guint invalidating_context : 1;
389 static guint signals[LAST_SIGNAL] = { 0 };
390 static GtkStyleContext *_running_animations = NULL;
391 guint _running_animations_timer_id = 0;
393 static void gtk_style_context_finalize (GObject *object);
395 static void gtk_style_context_impl_set_property (GObject *object,
399 static void gtk_style_context_impl_get_property (GObject *object,
403 static GtkSymbolicColor *
404 gtk_style_context_color_lookup_func (gpointer contextp,
408 G_DEFINE_TYPE (GtkStyleContext, gtk_style_context, G_TYPE_OBJECT)
411 gtk_style_context_real_changed (GtkStyleContext *context)
413 GtkStyleContextPrivate *priv = context->priv;
416 _gtk_widget_style_context_invalidated (priv->widget);
420 gtk_style_context_class_init (GtkStyleContextClass *klass)
422 GObjectClass *object_class = G_OBJECT_CLASS (klass);
424 object_class->finalize = gtk_style_context_finalize;
425 object_class->set_property = gtk_style_context_impl_set_property;
426 object_class->get_property = gtk_style_context_impl_get_property;
428 klass->changed = gtk_style_context_real_changed;
431 g_signal_new (I_("changed"),
432 G_TYPE_FROM_CLASS (object_class),
434 G_STRUCT_OFFSET (GtkStyleContextClass, changed),
436 g_cclosure_marshal_VOID__VOID,
439 g_object_class_install_property (object_class,
441 g_param_spec_object ("screen",
443 P_("The associated GdkScreen"),
445 GTK_PARAM_READWRITE));
446 g_object_class_install_property (object_class,
448 g_param_spec_enum ("direction",
450 P_("Text direction"),
451 GTK_TYPE_TEXT_DIRECTION,
453 GTK_PARAM_READWRITE));
455 * GtkStyleContext:parent:
457 * Sets or gets the style context's parent. See gtk_style_context_set_parent()
462 g_object_class_install_property (object_class,
464 g_param_spec_object ("parent",
466 P_("The parent style context"),
467 GTK_TYPE_STYLE_CONTEXT,
468 GTK_PARAM_READWRITE));
470 g_type_class_add_private (object_class, sizeof (GtkStyleContextPrivate));
474 style_data_new (void)
478 data = g_slice_new0 (StyleData);
485 clear_property_cache (StyleData *data)
489 if (!data->property_cache)
492 for (i = 0; i < data->property_cache->len; i++)
494 PropertyValue *node = &g_array_index (data->property_cache, PropertyValue, i);
496 g_param_spec_unref (node->pspec);
497 g_value_unset (&node->value);
500 g_array_free (data->property_cache, TRUE);
501 data->property_cache = NULL;
505 style_data_ref (StyleData *style_data)
507 style_data->ref_count++;
513 style_data_unref (StyleData *data)
517 if (data->ref_count > 0)
520 g_object_unref (data->store);
521 clear_property_cache (data);
523 g_slice_free (StyleData, data);
527 style_data_is_animating (StyleData *style_data)
529 return GTK_IS_CSS_ANIMATED_VALUES (style_data->store);
532 static GtkStyleInfo *
533 style_info_new (void)
537 info = g_slice_new0 (GtkStyleInfo);
538 info->style_classes = g_array_new (FALSE, FALSE, sizeof (GQuark));
539 info->regions = g_array_new (FALSE, FALSE, sizeof (GtkRegion));
545 style_info_set_data (GtkStyleInfo *info,
548 if (info->data == data)
552 style_data_ref (data);
555 style_data_unref (info->data);
561 style_info_free (GtkStyleInfo *info)
563 style_info_set_data (info, NULL);
564 g_array_free (info->style_classes, TRUE);
565 g_array_free (info->regions, TRUE);
566 g_slice_free (GtkStyleInfo, info);
569 static GtkStyleInfo *
570 style_info_pop (GtkStyleInfo *info)
572 GtkStyleInfo *next = info->next;
574 style_info_free (info);
579 static GtkStyleInfo *
580 style_info_copy (GtkStyleInfo *info)
584 copy = style_info_new ();
585 g_array_insert_vals (copy->style_classes, 0,
586 info->style_classes->data,
587 info->style_classes->len);
589 g_array_insert_vals (copy->regions, 0,
594 copy->junction_sides = info->junction_sides;
595 copy->state_flags = info->state_flags;
596 style_info_set_data (copy, info->data);
602 style_info_hash (gconstpointer elem)
604 const GtkStyleInfo *info;
609 for (i = 0; i < info->style_classes->len; i++)
611 hash += g_array_index (info->style_classes, GQuark, i);
615 for (i = 0; i < info->regions->len; i++)
619 region = &g_array_index (info->regions, GtkRegion, i);
620 hash += region->class_quark;
621 hash += region->flags;
625 return hash ^ info->state_flags;
629 style_info_equal (gconstpointer elem1,
632 const GtkStyleInfo *info1, *info2;
637 if (info1->state_flags != info2->state_flags)
640 if (info1->junction_sides != info2->junction_sides)
643 if (info1->style_classes->len != info2->style_classes->len)
646 if (memcmp (info1->style_classes->data,
647 info2->style_classes->data,
648 info1->style_classes->len * sizeof (GQuark)) != 0)
651 if (info1->regions->len != info2->regions->len)
654 if (memcmp (info1->regions->data,
655 info2->regions->data,
656 info1->regions->len * sizeof (GtkRegion)) != 0)
663 gtk_style_context_cascade_changed (GtkStyleCascade *cascade,
664 GtkStyleContext *context)
666 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_SOURCE);
670 gtk_style_context_set_cascade (GtkStyleContext *context,
671 GtkStyleCascade *cascade)
673 GtkStyleContextPrivate *priv;
675 priv = context->priv;
677 if (priv->cascade == cascade)
682 g_object_ref (cascade);
683 g_signal_connect (cascade,
684 "-gtk-private-changed",
685 G_CALLBACK (gtk_style_context_cascade_changed),
691 g_signal_handlers_disconnect_by_func (priv->cascade,
692 gtk_style_context_cascade_changed,
694 g_object_unref (priv->cascade);
697 priv->cascade = cascade;
700 gtk_style_context_cascade_changed (cascade, context);
704 gtk_style_context_init (GtkStyleContext *style_context)
706 GtkStyleContextPrivate *priv;
708 priv = style_context->priv = G_TYPE_INSTANCE_GET_PRIVATE (style_context,
709 GTK_TYPE_STYLE_CONTEXT,
710 GtkStyleContextPrivate);
712 priv->style_data = g_hash_table_new_full (style_info_hash,
714 (GDestroyNotify) style_info_free,
715 (GDestroyNotify) style_data_unref);
717 priv->direction = GTK_TEXT_DIR_LTR;
719 priv->screen = gdk_screen_get_default ();
720 priv->relevant_changes = GTK_CSS_CHANGE_ANY;
722 /* Create default info store */
723 priv->info = style_info_new ();
725 gtk_style_context_set_cascade (style_context,
726 _gtk_style_cascade_get_for_screen (priv->screen));
730 gtk_style_context_do_animations (gpointer unused)
732 GtkStyleContext *context;
734 for (context = _running_animations;
736 context = context->priv->animation_list_next)
738 _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->animation_list_prev != NULL
750 || _running_animations == context;
754 gtk_style_context_stop_animating (GtkStyleContext *context)
756 GtkStyleContextPrivate *priv = context->priv;
758 if (!gtk_style_context_is_animating (context))
761 if (priv->animation_list_prev == NULL)
763 _running_animations = priv->animation_list_next;
765 if (_running_animations == NULL)
767 /* we were the last animation */
768 g_source_remove (_running_animations_timer_id);
769 _running_animations_timer_id = 0;
773 priv->animation_list_prev->priv->animation_list_next = priv->animation_list_next;
775 if (priv->animation_list_next)
776 priv->animation_list_next->priv->animation_list_prev = priv->animation_list_prev;
778 priv->animation_list_next = NULL;
779 priv->animation_list_prev = NULL;
783 gtk_style_context_start_animating (GtkStyleContext *context)
785 GtkStyleContextPrivate *priv = context->priv;
787 if (gtk_style_context_is_animating (context))
790 if (_running_animations == NULL)
792 _running_animations_timer_id = gdk_threads_add_timeout (25,
793 gtk_style_context_do_animations,
795 _running_animations = context;
799 priv->animation_list_next = _running_animations;
800 _running_animations->priv->animation_list_prev = context;
801 _running_animations = context;
806 gtk_style_context_finalize (GObject *object)
808 GtkStyleContextPrivate *priv;
809 GtkStyleContext *style_context;
811 style_context = GTK_STYLE_CONTEXT (object);
812 priv = style_context->priv;
814 _gtk_style_context_stop_animations (style_context);
816 /* children hold a reference to us */
817 g_assert (priv->children == NULL);
819 gtk_style_context_set_parent (style_context, NULL);
821 gtk_style_context_set_cascade (style_context, NULL);
823 if (priv->widget_path)
824 gtk_widget_path_free (priv->widget_path);
826 g_hash_table_destroy (priv->style_data);
829 priv->info = style_info_pop (priv->info);
831 G_OBJECT_CLASS (gtk_style_context_parent_class)->finalize (object);
835 gtk_style_context_impl_set_property (GObject *object,
840 GtkStyleContext *style_context;
842 style_context = GTK_STYLE_CONTEXT (object);
847 gtk_style_context_set_screen (style_context,
848 g_value_get_object (value));
851 gtk_style_context_set_direction (style_context,
852 g_value_get_enum (value));
855 gtk_style_context_set_parent (style_context,
856 g_value_get_object (value));
859 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
865 gtk_style_context_impl_get_property (GObject *object,
870 GtkStyleContext *style_context;
871 GtkStyleContextPrivate *priv;
873 style_context = GTK_STYLE_CONTEXT (object);
874 priv = style_context->priv;
879 g_value_set_object (value, priv->screen);
882 g_value_set_enum (value, priv->direction);
885 g_value_set_object (value, priv->parent);
888 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
894 build_properties (GtkStyleContext *context,
895 StyleData *style_data,
899 GtkStyleContextPrivate *priv;
900 GtkCssMatcher matcher;
901 GtkCssLookup *lookup;
903 priv = context->priv;
905 lookup = _gtk_css_lookup_new ();
907 if (_gtk_css_matcher_init (&matcher, path, state))
908 _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
912 style_data->store = _gtk_css_computed_values_new ();
913 _gtk_css_lookup_resolve (lookup, context, style_data->store);
914 _gtk_css_lookup_free (lookup);
917 static GtkWidgetPath *
918 create_query_path (GtkStyleContext *context)
920 GtkStyleContextPrivate *priv;
925 priv = context->priv;
926 path = priv->widget ? _gtk_widget_create_path (priv->widget) : gtk_widget_path_copy (priv->widget_path);
927 pos = gtk_widget_path_length (path) - 1;
931 /* Set widget regions */
932 for (i = 0; i < info->regions->len; i++)
936 region = &g_array_index (info->regions, GtkRegion, i);
937 gtk_widget_path_iter_add_region (path, pos,
938 g_quark_to_string (region->class_quark),
942 /* Set widget classes */
943 for (i = 0; i < info->style_classes->len; i++)
947 quark = g_array_index (info->style_classes, GQuark, i);
948 gtk_widget_path_iter_add_class (path, pos,
949 g_quark_to_string (quark));
956 style_data_lookup (GtkStyleContext *context)
958 GtkStyleContextPrivate *priv;
963 priv = context->priv;
966 /* Current data in use is cached, just return it */
970 g_assert (priv->widget != NULL || priv->widget_path != NULL);
972 data = g_hash_table_lookup (priv->style_data, info);
975 style_info_set_data (info, data);
979 path = create_query_path (context);
981 data = style_data_new ();
982 style_info_set_data (info, data);
983 g_hash_table_insert (priv->style_data,
984 style_info_copy (info),
987 build_properties (context, data, path, info->state_flags);
989 gtk_widget_path_free (path);
995 style_data_lookup_for_state (GtkStyleContext *context,
1000 if (context->priv->info->state_flags == state)
1001 return style_data_lookup (context);
1003 gtk_style_context_save (context);
1004 gtk_style_context_set_state (context, state);
1005 data = style_data_lookup (context);
1006 gtk_style_context_restore (context);
1012 gtk_style_context_set_invalid (GtkStyleContext *context,
1015 GtkStyleContextPrivate *priv;
1017 priv = context->priv;
1019 if (priv->invalid == invalid)
1022 priv->invalid = invalid;
1027 gtk_style_context_set_invalid (priv->parent, TRUE);
1028 else if (GTK_IS_RESIZE_CONTAINER (priv->widget))
1029 _gtk_container_queue_restyle (GTK_CONTAINER (priv->widget));
1033 /* returns TRUE if someone called gtk_style_context_save() but hasn't
1034 * called gtk_style_context_restore() yet.
1035 * In those situations we don't invalidate the context when somebody
1036 * changes state/regions/classes.
1039 gtk_style_context_is_saved (GtkStyleContext *context)
1041 return context->priv->info->next != NULL;
1045 gtk_style_context_queue_invalidate_internal (GtkStyleContext *context,
1046 GtkCssChange change)
1048 GtkStyleContextPrivate *priv = context->priv;
1049 GtkStyleInfo *info = priv->info;
1051 if (gtk_style_context_is_saved (context))
1053 style_info_set_data (info, NULL);
1057 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_STATE);
1058 /* XXX: We need to invalidate siblings here somehow */
1063 * gtk_style_context_new:
1065 * Creates a standalone #GtkStyleContext, this style context
1066 * won't be attached to any widget, so you may want
1067 * to call gtk_style_context_set_path() yourself.
1070 * This function is only useful when using the theming layer
1071 * separated from GTK+, if you are using #GtkStyleContext to
1072 * theme #GtkWidget<!-- -->s, use gtk_widget_get_style_context()
1073 * in order to get a style context ready to theme the widget.
1076 * Returns: A newly created #GtkStyleContext.
1079 gtk_style_context_new (void)
1081 return g_object_new (GTK_TYPE_STYLE_CONTEXT, NULL);
1085 _gtk_style_context_set_widget (GtkStyleContext *context,
1088 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1089 g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget));
1091 context->priv->widget = widget;
1093 _gtk_style_context_stop_animations (context);
1095 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY_SELF);
1099 * gtk_style_context_add_provider:
1100 * @context: a #GtkStyleContext
1101 * @provider: a #GtkStyleProvider
1102 * @priority: the priority of the style provider. The lower
1103 * it is, the earlier it will be used in the style
1104 * construction. Typically this will be in the range
1105 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1106 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1108 * Adds a style provider to @context, to be used in style construction.
1110 * <note><para>If both priorities are the same, A #GtkStyleProvider
1111 * added through this function takes precedence over another added
1112 * through gtk_style_context_add_provider_for_screen().</para></note>
1117 gtk_style_context_add_provider (GtkStyleContext *context,
1118 GtkStyleProvider *provider,
1121 GtkStyleContextPrivate *priv;
1123 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1124 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1126 priv = context->priv;
1128 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
1130 GtkStyleCascade *new_cascade;
1132 new_cascade = _gtk_style_cascade_new ();
1133 _gtk_style_cascade_set_parent (new_cascade, priv->cascade);
1134 _gtk_style_cascade_add_provider (new_cascade, provider, priority);
1135 gtk_style_context_set_cascade (context, new_cascade);
1136 g_object_unref (new_cascade);
1140 _gtk_style_cascade_add_provider (priv->cascade, provider, priority);
1145 * gtk_style_context_remove_provider:
1146 * @context: a #GtkStyleContext
1147 * @provider: a #GtkStyleProvider
1149 * Removes @provider from the style providers list in @context.
1154 gtk_style_context_remove_provider (GtkStyleContext *context,
1155 GtkStyleProvider *provider)
1157 GtkStyleContextPrivate *priv;
1159 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1160 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1162 priv = context->priv;
1164 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
1167 _gtk_style_cascade_remove_provider (priv->cascade, provider);
1171 * gtk_style_context_reset_widgets:
1172 * @screen: a #GdkScreen
1174 * This function recomputes the styles for all widgets under a particular
1175 * #GdkScreen. This is useful when some global parameter has changed that
1176 * affects the appearance of all widgets, because when a widget gets a new
1177 * style, it will both redraw and recompute any cached information about
1178 * its appearance. As an example, it is used when the color scheme changes
1179 * in the related #GtkSettings object.
1184 gtk_style_context_reset_widgets (GdkScreen *screen)
1186 GList *list, *toplevels;
1188 _gtk_icon_set_invalidate_caches ();
1190 toplevels = gtk_window_list_toplevels ();
1191 g_list_foreach (toplevels, (GFunc) g_object_ref, NULL);
1193 for (list = toplevels; list; list = list->next)
1195 if (gtk_widget_get_screen (list->data) == screen)
1196 gtk_widget_reset_style (list->data);
1198 g_object_unref (list->data);
1201 g_list_free (toplevels);
1205 * gtk_style_context_add_provider_for_screen:
1206 * @screen: a #GdkScreen
1207 * @provider: a #GtkStyleProvider
1208 * @priority: the priority of the style provider. The lower
1209 * it is, the earlier it will be used in the style
1210 * construction. Typically this will be in the range
1211 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1212 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1214 * Adds a global style provider to @screen, which will be used
1215 * in style construction for all #GtkStyleContext<!-- -->s under
1218 * GTK+ uses this to make styling information from #GtkSettings
1221 * <note><para>If both priorities are the same, A #GtkStyleProvider
1222 * added through gtk_style_context_add_provider() takes precedence
1223 * over another added through this function.</para></note>
1228 gtk_style_context_add_provider_for_screen (GdkScreen *screen,
1229 GtkStyleProvider *provider,
1232 GtkStyleCascade *cascade;
1234 g_return_if_fail (GDK_IS_SCREEN (screen));
1235 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1236 g_return_if_fail (!GTK_IS_SETTINGS (provider) || _gtk_settings_get_screen (GTK_SETTINGS (provider)) == screen);
1238 cascade = _gtk_style_cascade_get_for_screen (screen);
1239 _gtk_style_cascade_add_provider (cascade, provider, priority);
1243 * gtk_style_context_remove_provider_for_screen:
1244 * @screen: a #GdkScreen
1245 * @provider: a #GtkStyleProvider
1247 * Removes @provider from the global style providers list in @screen.
1252 gtk_style_context_remove_provider_for_screen (GdkScreen *screen,
1253 GtkStyleProvider *provider)
1255 GtkStyleCascade *cascade;
1257 g_return_if_fail (GDK_IS_SCREEN (screen));
1258 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1259 g_return_if_fail (!GTK_IS_SETTINGS (provider));
1261 cascade = _gtk_style_cascade_get_for_screen (screen);
1262 _gtk_style_cascade_remove_provider (cascade, provider);
1266 * gtk_style_context_get_section:
1267 * @context: a #GtkStyleContext
1268 * @property: style property name
1270 * Queries the location in the CSS where @property was defined for the
1271 * current @context. Note that the state to be queried is taken from
1272 * gtk_style_context_get_state().
1274 * If the location is not available, %NULL will be returned. The
1275 * location might not be available for various reasons, such as the
1276 * property being overridden, @property not naming a supported CSS
1277 * property or tracking of definitions being disabled for performance
1280 * Shorthand CSS properties cannot be queried for a location and will
1281 * always return %NULL.
1283 * Returns: %NULL or the section where value was defined
1286 gtk_style_context_get_section (GtkStyleContext *context,
1287 const gchar *property)
1289 GtkStyleContextPrivate *priv;
1290 GtkStyleProperty *prop;
1293 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1294 g_return_val_if_fail (property != NULL, NULL);
1296 priv = context->priv;
1297 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
1299 prop = _gtk_style_property_lookup (property);
1300 if (!GTK_IS_CSS_STYLE_PROPERTY (prop))
1303 data = style_data_lookup (context);
1304 return _gtk_css_computed_values_get_section (data->store, _gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (prop)));
1307 static GtkCssValue *
1308 gtk_style_context_query_func (guint id,
1311 return _gtk_css_computed_values_get_value (values, id);
1315 * gtk_style_context_get_property:
1316 * @context: a #GtkStyleContext
1317 * @property: style property name
1318 * @state: state to retrieve the property value for
1319 * @value: (out) (transfer full): return location for the style property value
1321 * Gets a style property from @context for the given state.
1323 * When @value is no longer needed, g_value_unset() must be called
1324 * to free any allocated memory.
1329 gtk_style_context_get_property (GtkStyleContext *context,
1330 const gchar *property,
1331 GtkStateFlags state,
1334 GtkStyleContextPrivate *priv;
1335 GtkStyleProperty *prop;
1338 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1339 g_return_if_fail (property != NULL);
1340 g_return_if_fail (value != NULL);
1342 priv = context->priv;
1343 g_return_if_fail (priv->widget != NULL || priv->widget_path != NULL);
1345 prop = _gtk_style_property_lookup (property);
1348 g_warning ("Style property \"%s\" is not registered", property);
1351 if (_gtk_style_property_get_value_type (prop) == G_TYPE_NONE)
1353 g_warning ("Style property \"%s\" is not gettable", property);
1357 data = style_data_lookup_for_state (context, state);
1358 _gtk_style_property_query (prop, value, gtk_style_context_query_func, data->store);
1362 * gtk_style_context_get_valist:
1363 * @context: a #GtkStyleContext
1364 * @state: state to retrieve the property values for
1365 * @args: va_list of property name/return location pairs, followed by %NULL
1367 * Retrieves several style property values from @context for a given state.
1372 gtk_style_context_get_valist (GtkStyleContext *context,
1373 GtkStateFlags state,
1376 const gchar *property_name;
1378 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1380 property_name = va_arg (args, const gchar *);
1382 while (property_name)
1384 gchar *error = NULL;
1385 GValue value = G_VALUE_INIT;
1387 gtk_style_context_get_property (context,
1392 G_VALUE_LCOPY (&value, args, 0, &error);
1393 g_value_unset (&value);
1397 g_warning ("Could not get style property \"%s\": %s", property_name, error);
1402 property_name = va_arg (args, const gchar *);
1407 * gtk_style_context_get:
1408 * @context: a #GtkStyleContext
1409 * @state: state to retrieve the property values for
1410 * @...: property name /return value pairs, followed by %NULL
1412 * Retrieves several style property values from @context for a
1418 gtk_style_context_get (GtkStyleContext *context,
1419 GtkStateFlags state,
1424 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1426 va_start (args, state);
1427 gtk_style_context_get_valist (context, state, args);
1432 * gtk_style_context_set_state:
1433 * @context: a #GtkStyleContext
1434 * @flags: state to represent
1436 * Sets the state to be used when rendering with any
1437 * of the gtk_render_*() functions.
1442 gtk_style_context_set_state (GtkStyleContext *context,
1443 GtkStateFlags flags)
1445 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1447 context->priv->info->state_flags = flags;
1449 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_STATE);
1453 * gtk_style_context_get_state:
1454 * @context: a #GtkStyleContext
1456 * Returns the state used when rendering.
1458 * Returns: the state flags
1463 gtk_style_context_get_state (GtkStyleContext *context)
1465 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
1467 return context->priv->info->state_flags;
1471 * gtk_style_context_state_is_running:
1472 * @context: a #GtkStyleContext
1473 * @state: a widget state
1474 * @progress: (out): return location for the transition progress
1476 * Returns %TRUE if there is a transition animation running for the
1477 * current region (see gtk_style_context_push_animatable_region()).
1479 * If @progress is not %NULL, the animation progress will be returned
1480 * there, 0.0 means the state is closest to being unset, while 1.0 means
1481 * it's closest to being set. This means transition animation will
1482 * run from 0 to 1 when @state is being set and from 1 to 0 when
1485 * Returns: %TRUE if there is a running transition animation for @state.
1489 * Deprecated: 3.6: This function always returns %FALSE
1492 gtk_style_context_state_is_running (GtkStyleContext *context,
1496 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1502 * gtk_style_context_set_path:
1503 * @context: a #GtkStyleContext
1504 * @path: a #GtkWidgetPath
1506 * Sets the #GtkWidgetPath used for style matching. As a
1507 * consequence, the style will be regenerated to match
1508 * the new given path.
1510 * If you are using a #GtkStyleContext returned from
1511 * gtk_widget_get_style_context(), you do not need to call
1517 gtk_style_context_set_path (GtkStyleContext *context,
1518 GtkWidgetPath *path)
1520 GtkStyleContextPrivate *priv;
1522 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1523 g_return_if_fail (path != NULL);
1525 priv = context->priv;
1526 g_return_if_fail (priv->widget == NULL);
1528 if (priv->widget_path)
1530 gtk_widget_path_free (priv->widget_path);
1531 priv->widget_path = NULL;
1535 priv->widget_path = gtk_widget_path_copy (path);
1537 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY);
1541 * gtk_style_context_get_path:
1542 * @context: a #GtkStyleContext
1544 * Returns the widget path used for style matching.
1546 * Returns: (transfer none): A #GtkWidgetPath
1550 const GtkWidgetPath *
1551 gtk_style_context_get_path (GtkStyleContext *context)
1553 GtkStyleContextPrivate *priv;
1555 priv = context->priv;
1557 return gtk_widget_get_path (priv->widget);
1559 return priv->widget_path;
1563 * gtk_style_context_set_parent:
1564 * @context: a #GtkStyleContext
1565 * @parent: (allow-none): the new parent or %NULL
1567 * Sets the parent style context for @context. The parent style
1568 * context is used to implement
1569 * <ulink url="http://www.w3.org/TR/css3-cascade/#inheritance">inheritance</ulink>
1572 * If you are using a #GtkStyleContext returned from
1573 * gtk_widget_get_style_context(), the parent will be set for you.
1578 gtk_style_context_set_parent (GtkStyleContext *context,
1579 GtkStyleContext *parent)
1581 GtkStyleContextPrivate *priv;
1583 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1584 g_return_if_fail (parent == NULL || GTK_IS_STYLE_CONTEXT (parent));
1586 priv = context->priv;
1588 if (priv->parent == parent)
1593 parent->priv->children = g_slist_prepend (parent->priv->children, context);
1594 g_object_ref (parent);
1596 gtk_style_context_set_invalid (parent, TRUE);
1601 priv->parent->priv->children = g_slist_remove (priv->parent->priv->children, context);
1602 g_object_unref (priv->parent);
1605 priv->parent = parent;
1607 g_object_notify (G_OBJECT (context), "parent");
1608 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY_PARENT | GTK_CSS_CHANGE_ANY_SIBLING);
1612 * gtk_style_context_get_parent:
1613 * @context: a #GtkStyleContext
1615 * Gets the parent context set via gtk_style_context_set_parent().
1616 * See that function for details.
1618 * Returns: (transfer none): the parent context or %NULL
1623 gtk_style_context_get_parent (GtkStyleContext *context)
1625 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1627 return context->priv->parent;
1631 * gtk_style_context_save:
1632 * @context: a #GtkStyleContext
1634 * Saves the @context state, so all modifications done through
1635 * gtk_style_context_add_class(), gtk_style_context_remove_class(),
1636 * gtk_style_context_add_region(), gtk_style_context_remove_region()
1637 * or gtk_style_context_set_junction_sides() can be reverted in one
1638 * go through gtk_style_context_restore().
1643 gtk_style_context_save (GtkStyleContext *context)
1645 GtkStyleContextPrivate *priv;
1647 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1649 priv = context->priv;
1651 priv->info = style_info_copy (priv->info);
1652 /* Need to unset animations here because we can not know what style
1653 * class potential transitions came from once we save().
1655 if (priv->info->data && style_data_is_animating (priv->info->data))
1656 style_info_set_data (priv->info, NULL);
1660 * gtk_style_context_restore:
1661 * @context: a #GtkStyleContext
1663 * Restores @context state to a previous stage.
1664 * See gtk_style_context_save().
1669 gtk_style_context_restore (GtkStyleContext *context)
1671 GtkStyleContextPrivate *priv;
1673 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1675 priv = context->priv;
1677 priv->info = style_info_pop (priv->info);
1681 g_warning ("Unpaired gtk_style_context_restore() call");
1683 /* Create default region */
1684 priv->info = style_info_new ();
1689 style_class_find (GArray *array,
1694 gboolean found = FALSE;
1700 if (!array || array->len == 0)
1704 max = array->len - 1;
1710 mid = (min + max) / 2;
1711 item = g_array_index (array, GQuark, mid);
1713 if (class_quark == item)
1718 else if (class_quark > item)
1719 min = pos = mid + 1;
1726 while (!found && min <= max);
1735 region_find (GArray *array,
1740 gboolean found = FALSE;
1746 if (!array || array->len == 0)
1750 max = array->len - 1;
1756 mid = (min + max) / 2;
1757 region = &g_array_index (array, GtkRegion, mid);
1759 if (region->class_quark == class_quark)
1764 else if (region->class_quark > class_quark)
1765 min = pos = mid + 1;
1772 while (!found && min <= max);
1781 * gtk_style_context_add_class:
1782 * @context: a #GtkStyleContext
1783 * @class_name: class name to use in styling
1785 * Adds a style class to @context, so posterior calls to
1786 * gtk_style_context_get() or any of the gtk_render_*()
1787 * functions will make use of this new class for styling.
1789 * In the CSS file format, a #GtkEntry defining an "entry"
1790 * class, would be matched by:
1793 * GtkEntry.entry { ... }
1796 * While any widget defining an "entry" class would be
1805 gtk_style_context_add_class (GtkStyleContext *context,
1806 const gchar *class_name)
1808 GtkStyleContextPrivate *priv;
1813 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1814 g_return_if_fail (class_name != NULL);
1816 priv = context->priv;
1817 class_quark = g_quark_from_string (class_name);
1821 if (!style_class_find (info->style_classes, class_quark, &position))
1823 g_array_insert_val (info->style_classes, position, class_quark);
1825 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_CLASS);
1830 * gtk_style_context_remove_class:
1831 * @context: a #GtkStyleContext
1832 * @class_name: class name to remove
1834 * Removes @class_name from @context.
1839 gtk_style_context_remove_class (GtkStyleContext *context,
1840 const gchar *class_name)
1842 GtkStyleContextPrivate *priv;
1847 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1848 g_return_if_fail (class_name != NULL);
1850 class_quark = g_quark_try_string (class_name);
1855 priv = context->priv;
1859 if (style_class_find (info->style_classes, class_quark, &position))
1861 g_array_remove_index (info->style_classes, position);
1863 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_CLASS);
1868 * gtk_style_context_has_class:
1869 * @context: a #GtkStyleContext
1870 * @class_name: a class name
1872 * Returns %TRUE if @context currently has defined the
1875 * Returns: %TRUE if @context has @class_name defined
1880 gtk_style_context_has_class (GtkStyleContext *context,
1881 const gchar *class_name)
1883 GtkStyleContextPrivate *priv;
1887 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1888 g_return_val_if_fail (class_name != NULL, FALSE);
1890 class_quark = g_quark_try_string (class_name);
1895 priv = context->priv;
1899 if (style_class_find (info->style_classes, class_quark, NULL))
1906 * gtk_style_context_list_classes:
1907 * @context: a #GtkStyleContext
1909 * Returns the list of classes currently defined in @context.
1911 * Returns: (transfer container) (element-type utf8): a #GList of
1912 * strings with the currently defined classes. The contents
1913 * of the list are owned by GTK+, but you must free the list
1914 * itself with g_list_free() when you are done with it.
1919 gtk_style_context_list_classes (GtkStyleContext *context)
1921 GtkStyleContextPrivate *priv;
1923 GList *classes = NULL;
1926 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1928 priv = context->priv;
1932 for (i = 0; i < info->style_classes->len; i++)
1936 quark = g_array_index (info->style_classes, GQuark, i);
1937 classes = g_list_prepend (classes, (gchar *) g_quark_to_string (quark));
1944 * gtk_style_context_list_regions:
1945 * @context: a #GtkStyleContext
1947 * Returns the list of regions currently defined in @context.
1949 * Returns: (transfer container) (element-type utf8): a #GList of
1950 * strings with the currently defined regions. The contents
1951 * of the list are owned by GTK+, but you must free the list
1952 * itself with g_list_free() when you are done with it.
1957 gtk_style_context_list_regions (GtkStyleContext *context)
1959 GtkStyleContextPrivate *priv;
1961 GList *classes = NULL;
1964 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1966 priv = context->priv;
1970 for (i = 0; i < info->regions->len; i++)
1973 const gchar *class_name;
1975 region = &g_array_index (info->regions, GtkRegion, i);
1977 class_name = g_quark_to_string (region->class_quark);
1978 classes = g_list_prepend (classes, (gchar *) class_name);
1985 _gtk_style_context_check_region_name (const gchar *str)
1987 g_return_val_if_fail (str != NULL, FALSE);
1989 if (!g_ascii_islower (str[0]))
1995 !g_ascii_islower (*str))
2005 * gtk_style_context_add_region:
2006 * @context: a #GtkStyleContext
2007 * @region_name: region name to use in styling
2008 * @flags: flags that apply to the region
2010 * Adds a region to @context, so posterior calls to
2011 * gtk_style_context_get() or any of the gtk_render_*()
2012 * functions will make use of this new region for styling.
2014 * In the CSS file format, a #GtkTreeView defining a "row"
2015 * region, would be matched by:
2018 * GtkTreeView row { ... }
2021 * Pseudo-classes are used for matching @flags, so the two
2024 * GtkTreeView row:nth-child(even) { ... }
2025 * GtkTreeView row:nth-child(odd) { ... }
2028 * would apply to even and odd rows, respectively.
2030 * <note><para>Region names must only contain lowercase letters
2031 * and '-', starting always with a lowercase letter.</para></note>
2036 gtk_style_context_add_region (GtkStyleContext *context,
2037 const gchar *region_name,
2038 GtkRegionFlags flags)
2040 GtkStyleContextPrivate *priv;
2042 GQuark region_quark;
2045 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2046 g_return_if_fail (region_name != NULL);
2047 g_return_if_fail (_gtk_style_context_check_region_name (region_name));
2049 priv = context->priv;
2050 region_quark = g_quark_from_string (region_name);
2054 if (!region_find (info->regions, region_quark, &position))
2058 region.class_quark = region_quark;
2059 region.flags = flags;
2061 g_array_insert_val (info->regions, position, region);
2063 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_REGION);
2068 * gtk_style_context_remove_region:
2069 * @context: a #GtkStyleContext
2070 * @region_name: region name to unset
2072 * Removes a region from @context.
2077 gtk_style_context_remove_region (GtkStyleContext *context,
2078 const gchar *region_name)
2080 GtkStyleContextPrivate *priv;
2082 GQuark region_quark;
2085 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2086 g_return_if_fail (region_name != NULL);
2088 region_quark = g_quark_try_string (region_name);
2093 priv = context->priv;
2097 if (region_find (info->regions, region_quark, &position))
2099 g_array_remove_index (info->regions, position);
2101 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_REGION);
2106 * gtk_style_context_has_region:
2107 * @context: a #GtkStyleContext
2108 * @region_name: a region name
2109 * @flags_return: (out) (allow-none): return location for region flags
2111 * Returns %TRUE if @context has the region defined.
2112 * If @flags_return is not %NULL, it is set to the flags
2113 * affecting the region.
2115 * Returns: %TRUE if region is defined
2120 gtk_style_context_has_region (GtkStyleContext *context,
2121 const gchar *region_name,
2122 GtkRegionFlags *flags_return)
2124 GtkStyleContextPrivate *priv;
2126 GQuark region_quark;
2129 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2130 g_return_val_if_fail (region_name != NULL, FALSE);
2135 region_quark = g_quark_try_string (region_name);
2140 priv = context->priv;
2144 if (region_find (info->regions, region_quark, &position))
2150 region = &g_array_index (info->regions, GtkRegion, position);
2151 *flags_return = region->flags;
2160 style_property_values_cmp (gconstpointer bsearch_node1,
2161 gconstpointer bsearch_node2)
2163 const PropertyValue *val1 = bsearch_node1;
2164 const PropertyValue *val2 = bsearch_node2;
2166 if (val1->widget_type != val2->widget_type)
2167 return val1->widget_type < val2->widget_type ? -1 : 1;
2169 if (val1->pspec != val2->pspec)
2170 return val1->pspec < val2->pspec ? -1 : 1;
2172 if (val1->state != val2->state)
2173 return val1->state < val2->state ? -1 : 1;
2179 _gtk_style_context_peek_property (GtkStyleContext *context,
2182 StyleData *data = style_data_lookup (context);
2184 return _gtk_css_computed_values_get_value (data->store, property_id);
2188 _gtk_style_context_get_number (GtkStyleContext *context,
2190 double one_hundred_percent)
2194 value = _gtk_style_context_peek_property (context, property_id);
2195 return _gtk_css_number_value_get (value, one_hundred_percent);
2199 _gtk_style_context_peek_style_property (GtkStyleContext *context,
2201 GtkStateFlags state,
2204 GtkStyleContextPrivate *priv;
2205 PropertyValue *pcache, key = { 0 };
2209 priv = context->priv;
2211 data = style_data_lookup_for_state (context, state);
2213 key.widget_type = widget_type;
2217 /* need value cache array */
2218 if (!data->property_cache)
2219 data->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
2222 pcache = bsearch (&key,
2223 data->property_cache->data, data->property_cache->len,
2224 sizeof (PropertyValue), style_property_values_cmp);
2226 return &pcache->value;
2230 while (i < data->property_cache->len &&
2231 style_property_values_cmp (&key, &g_array_index (data->property_cache, PropertyValue, i)) >= 0)
2234 g_array_insert_val (data->property_cache, i, key);
2235 pcache = &g_array_index (data->property_cache, PropertyValue, i);
2237 /* cache miss, initialize value type, then set contents */
2238 g_param_spec_ref (pcache->pspec);
2239 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2241 if (priv->widget || priv->widget_path)
2243 GtkWidgetPath *widget_path = priv->widget ? _gtk_widget_create_path (priv->widget) : priv->widget_path;
2245 if (gtk_style_provider_get_style_property (GTK_STYLE_PROVIDER (priv->cascade),
2247 state, pspec, &pcache->value))
2249 /* Resolve symbolic colors to GdkColor/GdkRGBA */
2250 if (G_VALUE_TYPE (&pcache->value) == GTK_TYPE_SYMBOLIC_COLOR)
2252 GtkSymbolicColor *color;
2255 color = g_value_dup_boxed (&pcache->value);
2257 g_value_unset (&pcache->value);
2259 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2260 g_value_init (&pcache->value, GDK_TYPE_RGBA);
2262 g_value_init (&pcache->value, GDK_TYPE_COLOR);
2264 if (_gtk_style_context_resolve_color (context, color, &rgba))
2266 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2267 g_value_set_boxed (&pcache->value, &rgba);
2272 rgb.red = rgba.red * 65535. + 0.5;
2273 rgb.green = rgba.green * 65535. + 0.5;
2274 rgb.blue = rgba.blue * 65535. + 0.5;
2276 g_value_set_boxed (&pcache->value, &rgb);
2280 g_param_value_set_default (pspec, &pcache->value);
2282 gtk_symbolic_color_unref (color);
2286 gtk_widget_path_free (widget_path);
2288 return &pcache->value;
2292 gtk_widget_path_free (widget_path);
2295 /* not supplied by any provider, revert to default */
2296 g_param_value_set_default (pspec, &pcache->value);
2298 return &pcache->value;
2302 * gtk_style_context_get_style_property:
2303 * @context: a #GtkStyleContext
2304 * @property_name: the name of the widget style property
2305 * @value: Return location for the property value
2307 * Gets the value for a widget style property.
2309 * When @value is no longer needed, g_value_unset() must be called
2310 * to free any allocated memory.
2313 gtk_style_context_get_style_property (GtkStyleContext *context,
2314 const gchar *property_name,
2317 GtkStyleContextPrivate *priv;
2318 GtkWidgetClass *widget_class;
2319 GtkStateFlags state;
2321 const GValue *peek_value;
2324 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2325 g_return_if_fail (property_name != NULL);
2326 g_return_if_fail (value != NULL);
2328 priv = context->priv;
2332 widget_type = G_OBJECT_TYPE (priv->widget);
2336 if (!priv->widget_path)
2339 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2341 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2343 g_warning ("%s: can't get style properties for non-widget class `%s'",
2345 g_type_name (widget_type));
2350 widget_class = g_type_class_ref (widget_type);
2351 pspec = gtk_widget_class_find_style_property (widget_class, property_name);
2352 g_type_class_unref (widget_class);
2356 g_warning ("%s: widget class `%s' has no style property named `%s'",
2358 g_type_name (widget_type),
2363 state = gtk_style_context_get_state (context);
2364 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2367 if (G_VALUE_TYPE (value) == G_VALUE_TYPE (peek_value))
2368 g_value_copy (peek_value, value);
2369 else if (g_value_type_transformable (G_VALUE_TYPE (peek_value), G_VALUE_TYPE (value)))
2370 g_value_transform (peek_value, value);
2372 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
2374 G_VALUE_TYPE_NAME (peek_value),
2375 G_VALUE_TYPE_NAME (value));
2379 * gtk_style_context_get_style_valist:
2380 * @context: a #GtkStyleContext
2381 * @args: va_list of property name/return location pairs, followed by %NULL
2383 * Retrieves several widget style properties from @context according to the
2389 gtk_style_context_get_style_valist (GtkStyleContext *context,
2392 GtkStyleContextPrivate *priv;
2393 const gchar *prop_name;
2394 GtkStateFlags state;
2397 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2399 prop_name = va_arg (args, const gchar *);
2400 priv = context->priv;
2404 widget_type = G_OBJECT_TYPE (priv->widget);
2408 if (!priv->widget_path)
2411 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2413 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2415 g_warning ("%s: can't get style properties for non-widget class `%s'",
2417 g_type_name (widget_type));
2422 state = gtk_style_context_get_state (context);
2426 GtkWidgetClass *widget_class;
2428 const GValue *peek_value;
2431 widget_class = g_type_class_ref (widget_type);
2432 pspec = gtk_widget_class_find_style_property (widget_class, prop_name);
2433 g_type_class_unref (widget_class);
2437 g_warning ("%s: widget class `%s' has no style property named `%s'",
2439 g_type_name (widget_type),
2444 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2447 G_VALUE_LCOPY (peek_value, args, 0, &error);
2451 g_warning ("can't retrieve style property `%s' of type `%s': %s",
2453 G_VALUE_TYPE_NAME (peek_value),
2459 prop_name = va_arg (args, const gchar *);
2464 * gtk_style_context_get_style:
2465 * @context: a #GtkStyleContext
2466 * @...: property name /return value pairs, followed by %NULL
2468 * Retrieves several widget style properties from @context according to the
2474 gtk_style_context_get_style (GtkStyleContext *context,
2479 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2481 va_start (args, context);
2482 gtk_style_context_get_style_valist (context, args);
2488 * gtk_style_context_lookup_icon_set:
2489 * @context: a #GtkStyleContext
2490 * @stock_id: an icon name
2492 * Looks up @stock_id in the icon factories associated to @context and
2493 * the default icon factory, returning an icon set if found, otherwise
2496 * Returns: (transfer none): The looked up %GtkIconSet, or %NULL
2499 gtk_style_context_lookup_icon_set (GtkStyleContext *context,
2500 const gchar *stock_id)
2502 GtkStyleContextPrivate *priv;
2504 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2505 g_return_val_if_fail (stock_id != NULL, NULL);
2507 priv = context->priv;
2508 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
2510 return gtk_icon_factory_lookup_default (stock_id);
2514 * gtk_style_context_set_screen:
2515 * @context: a #GtkStyleContext
2516 * @screen: a #GdkScreen
2518 * Attaches @context to the given screen.
2520 * The screen is used to add style information from 'global' style
2521 * providers, such as the screens #GtkSettings instance.
2523 * If you are using a #GtkStyleContext returned from
2524 * gtk_widget_get_style_context(), you do not need to
2525 * call this yourself.
2530 gtk_style_context_set_screen (GtkStyleContext *context,
2533 GtkStyleContextPrivate *priv;
2535 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2536 g_return_if_fail (GDK_IS_SCREEN (screen));
2538 priv = context->priv;
2539 if (priv->screen == screen)
2542 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
2544 gtk_style_context_set_cascade (context, _gtk_style_cascade_get_for_screen (screen));
2548 _gtk_style_cascade_set_parent (priv->cascade, _gtk_style_cascade_get_for_screen (screen));
2551 priv->screen = screen;
2553 g_object_notify (G_OBJECT (context), "screen");
2557 * gtk_style_context_get_screen:
2558 * @context: a #GtkStyleContext
2560 * Returns the #GdkScreen to which @context is attached.
2562 * Returns: (transfer none): a #GdkScreen.
2565 gtk_style_context_get_screen (GtkStyleContext *context)
2567 GtkStyleContextPrivate *priv;
2569 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2571 priv = context->priv;
2572 return priv->screen;
2576 * gtk_style_context_set_direction:
2577 * @context: a #GtkStyleContext
2578 * @direction: the new direction.
2580 * Sets the reading direction for rendering purposes.
2582 * If you are using a #GtkStyleContext returned from
2583 * gtk_widget_get_style_context(), you do not need to
2584 * call this yourself.
2589 gtk_style_context_set_direction (GtkStyleContext *context,
2590 GtkTextDirection direction)
2592 GtkStyleContextPrivate *priv;
2594 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2596 priv = context->priv;
2597 priv->direction = direction;
2599 g_object_notify (G_OBJECT (context), "direction");
2603 * gtk_style_context_get_direction:
2604 * @context: a #GtkStyleContext
2606 * Returns the widget direction used for rendering.
2608 * Returns: the widget direction
2613 gtk_style_context_get_direction (GtkStyleContext *context)
2615 GtkStyleContextPrivate *priv;
2617 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), GTK_TEXT_DIR_LTR);
2619 priv = context->priv;
2620 return priv->direction;
2624 * gtk_style_context_set_junction_sides:
2625 * @context: a #GtkStyleContext
2626 * @sides: sides where rendered elements are visually connected to
2629 * Sets the sides where rendered elements (mostly through
2630 * gtk_render_frame()) will visually connect with other visual elements.
2632 * This is merely a hint that may or may not be honored
2633 * by theming engines.
2635 * Container widgets are expected to set junction hints as appropriate
2636 * for their children, so it should not normally be necessary to call
2637 * this function manually.
2642 gtk_style_context_set_junction_sides (GtkStyleContext *context,
2643 GtkJunctionSides sides)
2645 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2647 context->priv->info->junction_sides = sides;
2651 * gtk_style_context_get_junction_sides:
2652 * @context: a #GtkStyleContext
2654 * Returns the sides where rendered elements connect visually with others.
2656 * Returns: the junction sides
2661 gtk_style_context_get_junction_sides (GtkStyleContext *context)
2663 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
2665 return context->priv->info->junction_sides;
2668 static GtkSymbolicColor *
2669 gtk_style_context_color_lookup_func (gpointer contextp,
2672 GtkStyleContext *context = contextp;
2674 return _gtk_style_provider_private_get_color (GTK_STYLE_PROVIDER_PRIVATE (context->priv->cascade), name);
2678 _gtk_style_context_resolve_color_value (GtkStyleContext *context,
2679 GtkCssValue *current,
2682 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2683 g_return_val_if_fail (current != NULL, FALSE);
2684 g_return_val_if_fail (color != NULL, FALSE);
2686 return _gtk_symbolic_color_resolve_full ((GtkSymbolicColor *) color,
2688 gtk_style_context_color_lookup_func,
2694 _gtk_style_context_resolve_color (GtkStyleContext *context,
2695 GtkSymbolicColor *color,
2700 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2701 g_return_val_if_fail (color != NULL, FALSE);
2702 g_return_val_if_fail (result != NULL, FALSE);
2704 val = _gtk_symbolic_color_resolve_full (color,
2705 _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR),
2706 gtk_style_context_color_lookup_func,
2711 *result = *_gtk_css_rgba_value_get_rgba (val);
2712 _gtk_css_value_unref (val);
2717 * gtk_style_context_lookup_color:
2718 * @context: a #GtkStyleContext
2719 * @color_name: color name to lookup
2720 * @color: (out): Return location for the looked up color
2722 * Looks up and resolves a color name in the @context color map.
2724 * Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
2727 gtk_style_context_lookup_color (GtkStyleContext *context,
2728 const gchar *color_name,
2731 GtkSymbolicColor *sym_color;
2733 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2734 g_return_val_if_fail (color_name != NULL, FALSE);
2735 g_return_val_if_fail (color != NULL, FALSE);
2737 sym_color = gtk_style_context_color_lookup_func (context, color_name);
2738 if (sym_color == NULL)
2741 return _gtk_style_context_resolve_color (context, sym_color, color);
2745 * gtk_style_context_notify_state_change:
2746 * @context: a #GtkStyleContext
2747 * @window: a #GdkWindow
2748 * @region_id: (allow-none): animatable region to notify on, or %NULL.
2749 * See gtk_style_context_push_animatable_region()
2750 * @state: state to trigger transition for
2751 * @state_value: %TRUE if @state is the state we are changing to,
2752 * %FALSE if we are changing away from it
2754 * Notifies a state change on @context, so if the current style makes use
2755 * of transition animations, one will be started so all rendered elements
2756 * under @region_id are animated for state @state being set to value
2759 * The @window parameter is used in order to invalidate the rendered area
2760 * as the animation runs, so make sure it is the same window that is being
2761 * rendered on by the gtk_render_*() functions.
2763 * If @region_id is %NULL, all rendered elements using @context will be
2764 * affected by this state transition.
2766 * As a practical example, a #GtkButton notifying a state transition on
2767 * the prelight state:
2769 * gtk_style_context_notify_state_change (context,
2770 * gtk_widget_get_window (widget),
2772 * GTK_STATE_PRELIGHT,
2773 * button->in_button);
2776 * Can be handled in the CSS file like this:
2779 * background-color: #f00
2783 * background-color: #fff;
2784 * transition: 200ms linear
2788 * This combination will animate the button background from red to white
2789 * if a pointer enters the button, and back to red if the pointer leaves
2792 * Note that @state is used when finding the transition parameters, which
2793 * is why the style places the transition under the :hover pseudo-class.
2797 * Deprecated: 3.6: This function does nothing.
2800 gtk_style_context_notify_state_change (GtkStyleContext *context,
2804 gboolean state_value)
2806 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2807 g_return_if_fail (GDK_IS_WINDOW (window));
2808 g_return_if_fail (state > GTK_STATE_NORMAL && state <= GTK_STATE_FOCUSED);
2809 g_return_if_fail (context->priv->widget != NULL || context->priv->widget_path != NULL);
2813 * gtk_style_context_cancel_animations:
2814 * @context: a #GtkStyleContext
2815 * @region_id: (allow-none): animatable region to stop, or %NULL.
2816 * See gtk_style_context_push_animatable_region()
2818 * Stops all running animations for @region_id and all animatable
2819 * regions underneath.
2821 * A %NULL @region_id will stop all ongoing animations in @context,
2822 * when dealing with a #GtkStyleContext obtained through
2823 * gtk_widget_get_style_context(), this is normally done for you
2824 * in all circumstances you would expect all widget to be stopped,
2825 * so this should be only used in complex widgets with different
2826 * animatable regions.
2830 * Deprecated: 3.6: This function does nothing.
2833 gtk_style_context_cancel_animations (GtkStyleContext *context,
2836 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2840 * gtk_style_context_scroll_animations:
2841 * @context: a #GtkStyleContext
2842 * @window: a #GdkWindow used previously in
2843 * gtk_style_context_notify_state_change()
2844 * @dx: Amount to scroll in the X axis
2845 * @dy: Amount to scroll in the Y axis
2847 * This function is analogous to gdk_window_scroll(), and
2848 * should be called together with it so the invalidation
2849 * areas for any ongoing animation are scrolled together
2854 * Deprecated: 3.6: This function does nothing.
2857 gtk_style_context_scroll_animations (GtkStyleContext *context,
2862 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2863 g_return_if_fail (GDK_IS_WINDOW (window));
2867 * gtk_style_context_push_animatable_region:
2868 * @context: a #GtkStyleContext
2869 * @region_id: unique identifier for the animatable region
2871 * Pushes an animatable region, so all further gtk_render_*() calls between
2872 * this call and the following gtk_style_context_pop_animatable_region()
2873 * will potentially show transition animations for this region if
2874 * gtk_style_context_notify_state_change() is called for a given state,
2875 * and the current theme/style defines transition animations for state
2878 * The @region_id used must be unique in @context so the theming engine
2879 * can uniquely identify rendered elements subject to a state transition.
2883 * Deprecated: 3.6: This function does nothing.
2886 gtk_style_context_push_animatable_region (GtkStyleContext *context,
2889 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2890 g_return_if_fail (region_id != NULL);
2894 * gtk_style_context_pop_animatable_region:
2895 * @context: a #GtkStyleContext
2897 * Pops an animatable region from @context.
2898 * See gtk_style_context_push_animatable_region().
2902 * Deprecated: 3.6: This function does nothing.
2905 gtk_style_context_pop_animatable_region (GtkStyleContext *context)
2907 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2911 gtk_style_context_clear_cache (GtkStyleContext *context)
2913 GtkStyleContextPrivate *priv;
2916 priv = context->priv;
2918 for (info = priv->info; info; info = info->next)
2920 style_info_set_data (info, NULL);
2922 g_hash_table_remove_all (priv->style_data);
2926 gtk_style_context_do_invalidate (GtkStyleContext *context)
2928 GtkStyleContextPrivate *priv;
2930 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2932 priv = context->priv;
2934 /* Avoid reentrancy */
2935 if (priv->invalidating_context)
2938 priv->invalidating_context = TRUE;
2940 g_signal_emit (context, signals[CHANGED], 0);
2942 priv->invalidating_context = FALSE;
2946 _gtk_style_context_stop_animations (GtkStyleContext *context)
2948 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2950 if (!gtk_style_context_is_animating (context))
2953 style_info_set_data (context->priv->info, NULL);
2955 gtk_style_context_stop_animating (context);
2959 gtk_style_context_update_animations (GtkStyleContext *context,
2962 GtkBitmask *differences;
2963 StyleData *style_data;
2965 style_data = style_data_lookup (context);
2967 differences = _gtk_css_animated_values_advance (GTK_CSS_ANIMATED_VALUES (style_data->store),
2970 if (_gtk_css_animated_values_is_finished (GTK_CSS_ANIMATED_VALUES (style_data->store)))
2971 _gtk_style_context_stop_animations (context);
2977 gtk_style_context_should_animate (GtkStyleContext *context)
2979 GtkStyleContextPrivate *priv;
2982 priv = context->priv;
2984 if (priv->widget == NULL)
2987 if (!gtk_widget_get_mapped (priv->widget))
2990 g_object_get (gtk_widget_get_settings (context->priv->widget),
2991 "gtk-enable-animations", &animate,
2998 gtk_style_context_start_animations (GtkStyleContext *context,
2999 GtkCssComputedValues *previous,
3002 StyleData *animated;
3004 if (!gtk_style_context_should_animate (context))
3006 gtk_style_context_stop_animating (context);
3010 animated = style_data_new ();
3011 animated->store = _gtk_css_animated_values_new (style_data_lookup (context)->store,
3015 if (_gtk_css_animated_values_is_finished (GTK_CSS_ANIMATED_VALUES (animated->store)))
3017 style_data_unref (animated);
3018 gtk_style_context_stop_animating (context);
3022 style_info_set_data (context->priv->info, animated);
3023 style_data_unref (animated);
3024 gtk_style_context_start_animating (context);
3028 _gtk_style_context_validate (GtkStyleContext *context,
3030 GtkCssChange change)
3032 GtkStyleContextPrivate *priv;
3033 GtkBitmask *changes;
3036 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3038 priv = context->priv;
3040 change |= priv->pending_changes;
3042 /* If you run your application with
3043 * GTK_DEBUG=no-css-cache
3044 * every invalidation will purge the cache and completely query
3045 * everything anew form the cache. This is slow (in particular
3046 * when animating), but useful for figuring out bugs.
3048 * We achieve that by pretending that everything that could have
3049 * changed has and so we of course totally need to redo everything.
3051 * Note that this also completely revalidates child widgets all
3054 if (G_UNLIKELY (gtk_get_debug_flags () & GTK_DEBUG_NO_CSS_CACHE))
3055 change = GTK_CSS_CHANGE_ANY;
3057 if (!priv->invalid && change == 0)
3060 priv->pending_changes = 0;
3061 gtk_style_context_set_invalid (context, FALSE);
3063 /* Try to avoid invalidating if we can */
3064 if (change & GTK_STYLE_CONTEXT_RADICAL_CHANGE)
3066 priv->relevant_changes = GTK_CSS_CHANGE_ANY;
3070 if (priv->relevant_changes == GTK_CSS_CHANGE_ANY)
3072 GtkWidgetPath *path;
3073 GtkCssMatcher matcher;
3075 path = create_query_path (context);
3076 if (_gtk_css_matcher_init (&matcher, path, priv->info->state_flags))
3077 priv->relevant_changes = _gtk_style_provider_private_get_change (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
3080 priv->relevant_changes = 0;
3082 priv->relevant_changes &= ~GTK_STYLE_CONTEXT_RADICAL_CHANGE;
3084 gtk_widget_path_unref (path);
3088 if (priv->relevant_changes & change)
3090 GtkStyleInfo *info = priv->info;
3094 current = style_data_ref (info->data);
3098 if ((priv->relevant_changes & change) & ~GTK_STYLE_CONTEXT_CACHED_CHANGE)
3099 gtk_style_context_clear_cache (context);
3101 style_info_set_data (info, NULL);
3107 gtk_style_context_start_animations (context, current->store, timestamp);
3108 change &= ~GTK_CSS_CHANGE_ANIMATE;
3110 data = style_data_lookup (context);
3112 changes = _gtk_css_computed_values_get_difference (data->store, current->store);
3114 style_data_unref (current);
3118 changes = _gtk_bitmask_new ();
3119 changes = _gtk_bitmask_invert_range (changes, 0, _gtk_css_style_property_get_n_properties ());
3123 changes = _gtk_bitmask_new ();
3125 if (change & GTK_CSS_CHANGE_ANIMATE &&
3126 gtk_style_context_is_animating (context))
3128 GtkBitmask *animation_changes;
3130 animation_changes = gtk_style_context_update_animations (context, timestamp);
3131 changes = _gtk_bitmask_union (changes, animation_changes);
3132 _gtk_bitmask_free (animation_changes);
3135 if (!_gtk_bitmask_is_empty (changes))
3136 gtk_style_context_do_invalidate (context);
3138 change = _gtk_css_change_for_child (change);
3139 for (list = priv->children; list; list = list->next)
3141 _gtk_style_context_validate (list->data, timestamp, change);
3144 _gtk_bitmask_free (changes);
3148 _gtk_style_context_queue_invalidate (GtkStyleContext *context,
3149 GtkCssChange change)
3151 GtkStyleContextPrivate *priv;
3153 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3154 g_return_if_fail (change != 0);
3156 priv = context->priv;
3158 if (priv->widget != NULL)
3160 priv->pending_changes |= change;
3161 gtk_style_context_set_invalid (context, TRUE);
3163 else if (priv->widget_path == NULL)
3165 gtk_style_context_invalidate (context);
3170 * gtk_style_context_invalidate:
3171 * @context: a #GtkStyleContext.
3173 * Invalidates @context style information, so it will be reconstructed
3176 * If you're using a #GtkStyleContext returned from
3177 * gtk_widget_get_style_context(), you do not need to
3178 * call this yourself.
3183 gtk_style_context_invalidate (GtkStyleContext *context)
3185 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3187 gtk_style_context_clear_cache (context);
3188 gtk_style_context_do_invalidate (context);
3192 * gtk_style_context_set_background:
3193 * @context: a #GtkStyleContext
3194 * @window: a #GdkWindow
3196 * Sets the background of @window to the background pattern or
3197 * color specified in @context for its current state.
3202 gtk_style_context_set_background (GtkStyleContext *context,
3205 GtkStateFlags state;
3206 cairo_pattern_t *pattern;
3209 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3210 g_return_if_fail (GDK_IS_WINDOW (window));
3212 state = gtk_style_context_get_state (context);
3213 gtk_style_context_get (context, state,
3214 "background-image", &pattern,
3218 gdk_window_set_background_pattern (window, pattern);
3219 cairo_pattern_destroy (pattern);
3223 gtk_style_context_get (context, state,
3224 "background-color", &color,
3228 gdk_window_set_background_rgba (window, color);
3229 gdk_rgba_free (color);
3234 * gtk_style_context_get_color:
3235 * @context: a #GtkStyleContext
3236 * @state: state to retrieve the color for
3237 * @color: (out): return value for the foreground color
3239 * Gets the foreground color for a given state.
3244 gtk_style_context_get_color (GtkStyleContext *context,
3245 GtkStateFlags state,
3250 g_return_if_fail (color != NULL);
3251 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3253 gtk_style_context_get (context,
3263 * gtk_style_context_get_background_color:
3264 * @context: a #GtkStyleContext
3265 * @state: state to retrieve the color for
3266 * @color: (out): return value for the background color
3268 * Gets the background color for a given state.
3273 gtk_style_context_get_background_color (GtkStyleContext *context,
3274 GtkStateFlags state,
3279 g_return_if_fail (color != NULL);
3280 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3282 gtk_style_context_get (context,
3284 "background-color", &c,
3292 * gtk_style_context_get_border_color:
3293 * @context: a #GtkStyleContext
3294 * @state: state to retrieve the color for
3295 * @color: (out): return value for the border color
3297 * Gets the border color for a given state.
3302 gtk_style_context_get_border_color (GtkStyleContext *context,
3303 GtkStateFlags state,
3308 g_return_if_fail (color != NULL);
3309 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3311 gtk_style_context_get (context,
3321 * gtk_style_context_get_border:
3322 * @context: a #GtkStyleContext
3323 * @state: state to retrieve the border for
3324 * @border: (out): return value for the border settings
3326 * Gets the border for a given state as a #GtkBorder.
3327 * See %GTK_STYLE_PROPERTY_BORDER_WIDTH.
3332 gtk_style_context_get_border (GtkStyleContext *context,
3333 GtkStateFlags state,
3336 int top, left, bottom, right;
3338 g_return_if_fail (border != NULL);
3339 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3341 gtk_style_context_get (context,
3343 "border-top-width", &top,
3344 "border-left-width", &left,
3345 "border-bottom-width", &bottom,
3346 "border-right-width", &right,
3350 border->left = left;
3351 border->bottom = bottom;
3352 border->right = right;
3356 * gtk_style_context_get_padding:
3357 * @context: a #GtkStyleContext
3358 * @state: state to retrieve the padding for
3359 * @padding: (out): return value for the padding settings
3361 * Gets the padding for a given state as a #GtkBorder.
3362 * See %GTK_STYLE_PROPERTY_PADDING.
3367 gtk_style_context_get_padding (GtkStyleContext *context,
3368 GtkStateFlags state,
3371 int top, left, bottom, right;
3373 g_return_if_fail (padding != NULL);
3374 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3376 gtk_style_context_get (context,
3378 "padding-top", &top,
3379 "padding-left", &left,
3380 "padding-bottom", &bottom,
3381 "padding-right", &right,
3385 padding->left = left;
3386 padding->bottom = bottom;
3387 padding->right = right;
3391 * gtk_style_context_get_margin:
3392 * @context: a #GtkStyleContext
3393 * @state: state to retrieve the border for
3394 * @margin: (out): return value for the margin settings
3396 * Gets the margin for a given state as a #GtkBorder.
3397 * See %GTK_STYLE_PROPERTY_MARGIN.
3402 gtk_style_context_get_margin (GtkStyleContext *context,
3403 GtkStateFlags state,
3406 int top, left, bottom, right;
3408 g_return_if_fail (margin != NULL);
3409 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3411 gtk_style_context_get (context,
3414 "margin-left", &left,
3415 "margin-bottom", &bottom,
3416 "margin-right", &right,
3420 margin->left = left;
3421 margin->bottom = bottom;
3422 margin->right = right;
3426 * gtk_style_context_get_font:
3427 * @context: a #GtkStyleContext
3428 * @state: state to retrieve the font for
3430 * Returns the font description for a given state. The returned
3431 * object is const and will remain valid until the
3432 * #GtkStyleContext::changed signal happens.
3434 * Returns: (transfer none): the #PangoFontDescription for the given
3435 * state. This object is owned by GTK+ and should not be
3440 const PangoFontDescription *
3441 gtk_style_context_get_font (GtkStyleContext *context,
3442 GtkStateFlags state)
3444 GtkStyleContextPrivate *priv;
3446 PangoFontDescription *description;
3448 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
3450 priv = context->priv;
3451 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
3453 data = style_data_lookup_for_state (context, state);
3455 /* Yuck, fonts are created on-demand but we don't return a ref.
3456 * Do bad things to achieve this requirement */
3457 description = g_object_get_data (G_OBJECT (data->store), "font-cache-for-get_font");
3458 if (description == NULL)
3460 gtk_style_context_get (context, state, "font", &description, NULL);
3461 g_object_set_data_full (G_OBJECT (data->store),
3462 "font-cache-for-get_font",
3464 (GDestroyNotify) pango_font_description_free);
3470 get_cursor_color (GtkStyleContext *context,
3474 GdkColor *style_color;
3476 gtk_style_context_get_style (context,
3477 primary ? "cursor-color" : "secondary-cursor-color",
3483 color->red = style_color->red / 65535.0;
3484 color->green = style_color->green / 65535.0;
3485 color->blue = style_color->blue / 65535.0;
3488 gdk_color_free (style_color);
3492 gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, color);
3498 gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &bg);
3500 color->red = (color->red + bg.red) * 0.5;
3501 color->green = (color->green + bg.green) * 0.5;
3502 color->blue = (color->blue + bg.blue) * 0.5;
3508 _gtk_style_context_get_cursor_color (GtkStyleContext *context,
3509 GdkRGBA *primary_color,
3510 GdkRGBA *secondary_color)
3513 get_cursor_color (context, TRUE, primary_color);
3515 if (secondary_color)
3516 get_cursor_color (context, FALSE, secondary_color);
3523 * @context: a #GtkStyleContext
3525 * @x: X origin of the rectangle
3526 * @y: Y origin of the rectangle
3527 * @width: rectangle width
3528 * @height: rectangle height
3530 * Renders a checkmark (as in a #GtkCheckButton).
3532 * The %GTK_STATE_FLAG_ACTIVE state determines whether the check is
3533 * on or off, and %GTK_STATE_FLAG_INCONSISTENT determines whether it
3534 * should be marked as undefined.
3537 * <title>Typical checkmark rendering</title>
3538 * <inlinegraphic fileref="checks.png" format="PNG"/>
3544 gtk_render_check (GtkStyleContext *context,
3551 GtkThemingEngineClass *engine_class;
3552 GtkThemingEngine *engine;
3554 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3555 g_return_if_fail (cr != NULL);
3557 if (width <= 0 || height <= 0)
3560 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3561 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3566 _gtk_theming_engine_set_context (engine, context);
3567 engine_class->render_check (engine, cr,
3568 x, y, width, height);
3574 * gtk_render_option:
3575 * @context: a #GtkStyleContext
3577 * @x: X origin of the rectangle
3578 * @y: Y origin of the rectangle
3579 * @width: rectangle width
3580 * @height: rectangle height
3582 * Renders an option mark (as in a #GtkRadioButton), the %GTK_STATE_FLAG_ACTIVE
3583 * state will determine whether the option is on or off, and
3584 * %GTK_STATE_FLAG_INCONSISTENT whether it should be marked as undefined.
3587 * <title>Typical option mark rendering</title>
3588 * <inlinegraphic fileref="options.png" format="PNG"/>
3594 gtk_render_option (GtkStyleContext *context,
3601 GtkThemingEngineClass *engine_class;
3602 GtkThemingEngine *engine;
3604 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3605 g_return_if_fail (cr != NULL);
3607 if (width <= 0 || height <= 0)
3610 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3611 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3615 _gtk_theming_engine_set_context (engine, context);
3616 engine_class->render_option (engine, cr,
3617 x, y, width, height);
3624 * @context: a #GtkStyleContext
3626 * @angle: arrow angle from 0 to 2 * %G_PI, being 0 the arrow pointing to the north
3627 * @x: X origin of the render area
3628 * @y: Y origin of the render area
3629 * @size: square side for render area
3631 * Renders an arrow pointing to @angle.
3634 * <title>Typical arrow rendering at 0, 1&solidus;2 π, π and 3&solidus;2 π</title>
3635 * <inlinegraphic fileref="arrows.png" format="PNG"/>
3641 gtk_render_arrow (GtkStyleContext *context,
3648 GtkThemingEngineClass *engine_class;
3649 GtkThemingEngine *engine;
3651 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3652 g_return_if_fail (cr != NULL);
3657 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3658 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3662 gtk_style_context_save (context);
3663 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ARROW);
3665 _gtk_theming_engine_set_context (engine, context);
3666 engine_class->render_arrow (engine, cr,
3669 gtk_style_context_restore (context);
3674 * gtk_render_background:
3675 * @context: a #GtkStyleContext
3677 * @x: X origin of the rectangle
3678 * @y: Y origin of the rectangle
3679 * @width: rectangle width
3680 * @height: rectangle height
3682 * Renders the background of an element.
3685 * <title>Typical background rendering, showing the effect of
3686 * <parameter>background-image</parameter>,
3687 * <parameter>border-width</parameter> and
3688 * <parameter>border-radius</parameter></title>
3689 * <inlinegraphic fileref="background.png" format="PNG"/>
3695 gtk_render_background (GtkStyleContext *context,
3702 GtkThemingEngineClass *engine_class;
3703 GtkThemingEngine *engine;
3705 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3706 g_return_if_fail (cr != NULL);
3708 if (width <= 0 || height <= 0)
3711 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3712 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3716 _gtk_theming_engine_set_context (engine, context);
3717 engine_class->render_background (engine, cr, x, y, width, height);
3724 * @context: a #GtkStyleContext
3726 * @x: X origin of the rectangle
3727 * @y: Y origin of the rectangle
3728 * @width: rectangle width
3729 * @height: rectangle height
3731 * Renders a frame around the rectangle defined by @x, @y, @width, @height.
3734 * <title>Examples of frame rendering, showing the effect of
3735 * <parameter>border-image</parameter>,
3736 * <parameter>border-color</parameter>,
3737 * <parameter>border-width</parameter>,
3738 * <parameter>border-radius</parameter> and
3740 * <inlinegraphic fileref="frames.png" format="PNG"/>
3746 gtk_render_frame (GtkStyleContext *context,
3753 GtkThemingEngineClass *engine_class;
3754 GtkThemingEngine *engine;
3756 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3757 g_return_if_fail (cr != NULL);
3759 if (width <= 0 || height <= 0)
3762 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3763 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3767 _gtk_theming_engine_set_context (engine, context);
3768 engine_class->render_frame (engine, cr, x, y, width, height);
3774 * gtk_render_expander:
3775 * @context: a #GtkStyleContext
3777 * @x: X origin of the rectangle
3778 * @y: Y origin of the rectangle
3779 * @width: rectangle width
3780 * @height: rectangle height
3782 * Renders an expander (as used in #GtkTreeView and #GtkExpander) in the area
3783 * defined by @x, @y, @width, @height. The state %GTK_STATE_FLAG_ACTIVE
3784 * determines whether the expander is collapsed or expanded.
3787 * <title>Typical expander rendering</title>
3788 * <inlinegraphic fileref="expanders.png" format="PNG"/>
3794 gtk_render_expander (GtkStyleContext *context,
3801 GtkThemingEngineClass *engine_class;
3802 GtkThemingEngine *engine;
3804 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3805 g_return_if_fail (cr != NULL);
3807 if (width <= 0 || height <= 0)
3810 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3811 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3815 _gtk_theming_engine_set_context (engine, context);
3816 engine_class->render_expander (engine, cr, x, y, width, height);
3823 * @context: a #GtkStyleContext
3825 * @x: X origin of the rectangle
3826 * @y: Y origin of the rectangle
3827 * @width: rectangle width
3828 * @height: rectangle height
3830 * Renders a focus indicator on the rectangle determined by @x, @y, @width, @height.
3832 * <title>Typical focus rendering</title>
3833 * <inlinegraphic fileref="focus.png" format="PNG"/>
3839 gtk_render_focus (GtkStyleContext *context,
3846 GtkThemingEngineClass *engine_class;
3847 GtkThemingEngine *engine;
3849 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3850 g_return_if_fail (cr != NULL);
3852 if (width <= 0 || height <= 0)
3855 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3856 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3860 _gtk_theming_engine_set_context (engine, context);
3861 engine_class->render_focus (engine, cr, x, y, width, height);
3867 * gtk_render_layout:
3868 * @context: a #GtkStyleContext
3872 * @layout: the #PangoLayout to render
3874 * Renders @layout on the coordinates @x, @y
3879 gtk_render_layout (GtkStyleContext *context,
3883 PangoLayout *layout)
3885 GtkThemingEngineClass *engine_class;
3886 GtkThemingEngine *engine;
3887 PangoRectangle extents;
3889 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3890 g_return_if_fail (PANGO_IS_LAYOUT (layout));
3891 g_return_if_fail (cr != NULL);
3893 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3894 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3898 pango_layout_get_extents (layout, &extents, NULL);
3900 _gtk_theming_engine_set_context (engine, context);
3901 engine_class->render_layout (engine, cr, x, y, layout);
3908 * @context: a #GtkStyleContext
3910 * @x0: X coordinate for the origin of the line
3911 * @y0: Y coordinate for the origin of the line
3912 * @x1: X coordinate for the end of the line
3913 * @y1: Y coordinate for the end of the line
3915 * Renders a line from (x0, y0) to (x1, y1).
3920 gtk_render_line (GtkStyleContext *context,
3927 GtkThemingEngineClass *engine_class;
3928 GtkThemingEngine *engine;
3930 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3931 g_return_if_fail (cr != NULL);
3933 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3934 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3938 _gtk_theming_engine_set_context (engine, context);
3939 engine_class->render_line (engine, cr, x0, y0, x1, y1);
3945 * gtk_render_slider:
3946 * @context: a #GtkStyleContext
3948 * @x: X origin of the rectangle
3949 * @y: Y origin of the rectangle
3950 * @width: rectangle width
3951 * @height: rectangle height
3952 * @orientation: orientation of the slider
3954 * Renders a slider (as in #GtkScale) in the rectangle defined by @x, @y,
3955 * @width, @height. @orientation defines whether the slider is vertical
3959 * <title>Typical slider rendering</title>
3960 * <inlinegraphic fileref="sliders.png" format="PNG"/>
3966 gtk_render_slider (GtkStyleContext *context,
3972 GtkOrientation orientation)
3974 GtkThemingEngineClass *engine_class;
3975 GtkThemingEngine *engine;
3977 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3978 g_return_if_fail (cr != NULL);
3980 if (width <= 0 || height <= 0)
3983 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3984 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3988 _gtk_theming_engine_set_context (engine, context);
3989 engine_class->render_slider (engine, cr, x, y, width, height, orientation);
3995 * gtk_render_frame_gap:
3996 * @context: a #GtkStyleContext
3998 * @x: X origin of the rectangle
3999 * @y: Y origin of the rectangle
4000 * @width: rectangle width
4001 * @height: rectangle height
4002 * @gap_side: side where the gap is
4003 * @xy0_gap: initial coordinate (X or Y depending on @gap_side) for the gap
4004 * @xy1_gap: end coordinate (X or Y depending on @gap_side) for the gap
4006 * Renders a frame around the rectangle defined by (@x, @y, @width, @height),
4007 * leaving a gap on one side. @xy0_gap and @xy1_gap will mean X coordinates
4008 * for %GTK_POS_TOP and %GTK_POS_BOTTOM gap sides, and Y coordinates for
4009 * %GTK_POS_LEFT and %GTK_POS_RIGHT.
4012 * <title>Typical rendering of a frame with a gap</title>
4013 * <inlinegraphic fileref="frame-gap.png" format="PNG"/>
4019 gtk_render_frame_gap (GtkStyleContext *context,
4025 GtkPositionType gap_side,
4029 GtkThemingEngineClass *engine_class;
4030 GtkThemingEngine *engine;
4032 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4033 g_return_if_fail (cr != NULL);
4034 g_return_if_fail (xy0_gap <= xy1_gap);
4035 g_return_if_fail (xy0_gap >= 0);
4037 if (width <= 0 || height <= 0)
4040 if (gap_side == GTK_POS_LEFT ||
4041 gap_side == GTK_POS_RIGHT)
4042 g_return_if_fail (xy1_gap <= height);
4044 g_return_if_fail (xy1_gap <= width);
4046 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4047 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4051 _gtk_theming_engine_set_context (engine, context);
4052 engine_class->render_frame_gap (engine, cr,
4053 x, y, width, height, gap_side,
4060 * gtk_render_extension:
4061 * @context: a #GtkStyleContext
4063 * @x: X origin of the rectangle
4064 * @y: Y origin of the rectangle
4065 * @width: rectangle width
4066 * @height: rectangle height
4067 * @gap_side: side where the gap is
4069 * Renders a extension (as in a #GtkNotebook tab) in the rectangle
4070 * defined by @x, @y, @width, @height. The side where the extension
4071 * connects to is defined by @gap_side.
4074 * <title>Typical extension rendering</title>
4075 * <inlinegraphic fileref="extensions.png" format="PNG"/>
4081 gtk_render_extension (GtkStyleContext *context,
4087 GtkPositionType gap_side)
4089 GtkThemingEngineClass *engine_class;
4090 GtkThemingEngine *engine;
4092 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4093 g_return_if_fail (cr != NULL);
4095 if (width <= 0 || height <= 0)
4098 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4099 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4103 _gtk_theming_engine_set_context (engine, context);
4104 engine_class->render_extension (engine, cr, x, y, width, height, gap_side);
4110 * gtk_render_handle:
4111 * @context: a #GtkStyleContext
4113 * @x: X origin of the rectangle
4114 * @y: Y origin of the rectangle
4115 * @width: rectangle width
4116 * @height: rectangle height
4118 * Renders a handle (as in #GtkHandleBox, #GtkPaned and
4119 * #GtkWindow<!-- -->'s resize grip), in the rectangle
4120 * determined by @x, @y, @width, @height.
4123 * <title>Handles rendered for the paned and grip classes</title>
4124 * <inlinegraphic fileref="handles.png" format="PNG"/>
4130 gtk_render_handle (GtkStyleContext *context,
4137 GtkThemingEngineClass *engine_class;
4138 GtkThemingEngine *engine;
4140 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4141 g_return_if_fail (cr != NULL);
4143 if (width <= 0 || height <= 0)
4146 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4147 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4151 _gtk_theming_engine_set_context (engine, context);
4152 engine_class->render_handle (engine, cr, x, y, width, height);
4158 * gtk_render_activity:
4159 * @context: a #GtkStyleContext
4161 * @x: X origin of the rectangle
4162 * @y: Y origin of the rectangle
4163 * @width: rectangle width
4164 * @height: rectangle height
4166 * Renders an activity area (Such as in #GtkSpinner or the
4167 * fill line in #GtkRange), the state %GTK_STATE_FLAG_ACTIVE
4168 * determines whether there is activity going on.
4173 gtk_render_activity (GtkStyleContext *context,
4180 GtkThemingEngineClass *engine_class;
4181 GtkThemingEngine *engine;
4183 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4184 g_return_if_fail (cr != NULL);
4186 if (width <= 0 || height <= 0)
4189 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4190 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4194 _gtk_theming_engine_set_context (engine, context);
4195 engine_class->render_activity (engine, cr, x, y, width, height);
4201 * gtk_render_icon_pixbuf:
4202 * @context: a #GtkStyleContext
4203 * @source: the #GtkIconSource specifying the icon to render
4204 * @size: (type int): the size to render the icon at. A size of (GtkIconSize) -1
4205 * means render at the size of the source and don't scale.
4207 * Renders the icon specified by @source at the given @size, returning the result
4210 * Returns: (transfer full): a newly-created #GdkPixbuf containing the rendered icon
4215 gtk_render_icon_pixbuf (GtkStyleContext *context,
4216 const GtkIconSource *source,
4219 GtkThemingEngineClass *engine_class;
4220 GtkThemingEngine *engine;
4222 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
4223 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
4224 g_return_val_if_fail (source != NULL, NULL);
4226 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4227 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4229 _gtk_theming_engine_set_context (engine, context);
4230 return engine_class->render_icon_pixbuf (engine, source, size);
4235 * @context: a #GtkStyleContext
4237 * @pixbuf: a #GdkPixbuf containing the icon to draw
4238 * @x: X position for the @pixbuf
4239 * @y: Y position for the @pixbuf
4241 * Renders the icon in @pixbuf at the specified @x and @y coordinates.
4246 gtk_render_icon (GtkStyleContext *context,
4252 GtkThemingEngineClass *engine_class;
4253 GtkThemingEngine *engine;
4255 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4256 g_return_if_fail (cr != NULL);
4258 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4259 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4263 _gtk_theming_engine_set_context (engine, context);
4264 engine_class->render_icon (engine, cr, pixbuf, x, y);
4270 draw_insertion_cursor (GtkStyleContext *context,
4275 gboolean is_primary,
4276 PangoDirection direction,
4277 gboolean draw_arrow)
4280 GdkRGBA primary_color;
4281 GdkRGBA secondary_color;
4282 gfloat cursor_aspect_ratio;
4288 _gtk_style_context_get_cursor_color (context, &primary_color, &secondary_color);
4289 gdk_cairo_set_source_rgba (cr, is_primary ? &primary_color : &secondary_color);
4291 /* When changing the shape or size of the cursor here,
4292 * propagate the changes to gtktextview.c:text_window_invalidate_cursors().
4295 gtk_style_context_get_style (context,
4296 "cursor-aspect-ratio", &cursor_aspect_ratio,
4299 stem_width = height * cursor_aspect_ratio + 1;
4301 /* put (stem_width % 2) on the proper side of the cursor */
4302 if (direction == PANGO_DIRECTION_LTR)
4303 offset = stem_width / 2;
4305 offset = stem_width - stem_width / 2;
4307 cairo_rectangle (cr, x - offset, y, stem_width, height);
4315 arrow_width = stem_width + 1;
4317 if (direction == PANGO_DIRECTION_RTL)
4319 ax = x - offset - 1;
4320 ay = y + height - arrow_width * 2 - arrow_width + 1;
4322 cairo_move_to (cr, ax, ay + 1);
4323 cairo_line_to (cr, ax - arrow_width, ay + arrow_width);
4324 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4327 else if (direction == PANGO_DIRECTION_LTR)
4329 ax = x + stem_width - offset;
4330 ay = y + height - arrow_width * 2 - arrow_width + 1;
4332 cairo_move_to (cr, ax, ay + 1);
4333 cairo_line_to (cr, ax + arrow_width, ay + arrow_width);
4334 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4338 g_assert_not_reached();
4345 * gtk_render_insertion_cursor:
4346 * @context: a #GtkStyleContext
4350 * @layout: the #PangoLayout of the text
4351 * @index: the index in the #PangoLayout
4352 * @direction: the #PangoDirection of the text
4354 * Draws a text caret on @cr at the specified index of @layout.
4359 gtk_render_insertion_cursor (GtkStyleContext *context,
4363 PangoLayout *layout,
4365 PangoDirection direction)
4367 GtkStyleContextPrivate *priv;
4368 gboolean split_cursor;
4369 PangoRectangle strong_pos, weak_pos;
4370 PangoRectangle *cursor1, *cursor2;
4371 PangoDirection keymap_direction;
4372 PangoDirection direction2;
4374 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4375 g_return_if_fail (cr != NULL);
4376 g_return_if_fail (PANGO_IS_LAYOUT (layout));
4377 g_return_if_fail (index >= 0);
4379 priv = context->priv;
4381 g_object_get (gtk_settings_get_for_screen (priv->screen),
4382 "gtk-split-cursor", &split_cursor,
4385 keymap_direction = gdk_keymap_get_direction (gdk_keymap_get_for_display (gdk_screen_get_display (priv->screen)));
4387 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4389 direction2 = PANGO_DIRECTION_NEUTRAL;
4393 cursor1 = &strong_pos;
4395 if (strong_pos.x != weak_pos.x || strong_pos.y != weak_pos.y)
4397 direction2 = (direction == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
4398 cursor2 = &weak_pos;
4403 if (keymap_direction == direction)
4404 cursor1 = &strong_pos;
4406 cursor1 = &weak_pos;
4409 draw_insertion_cursor (context,
4411 x + PANGO_PIXELS (cursor1->x),
4412 y + PANGO_PIXELS (cursor1->y),
4413 PANGO_PIXELS (cursor1->height),
4416 direction2 != PANGO_DIRECTION_NEUTRAL);
4418 if (direction2 != PANGO_DIRECTION_NEUTRAL)
4420 draw_insertion_cursor (context,
4422 x + PANGO_PIXELS (cursor2->x),
4423 y + PANGO_PIXELS (cursor2->y),
4424 PANGO_PIXELS (cursor2->height),
4432 * gtk_draw_insertion_cursor:
4433 * @widget: a #GtkWidget
4434 * @cr: cairo context to draw to
4435 * @location: location where to draw the cursor (@location->width is ignored)
4436 * @is_primary: if the cursor should be the primary cursor color.
4437 * @direction: whether the cursor is left-to-right or
4438 * right-to-left. Should never be #GTK_TEXT_DIR_NONE
4439 * @draw_arrow: %TRUE to draw a directional arrow on the
4440 * cursor. Should be %FALSE unless the cursor is split.
4442 * Draws a text caret on @cr at @location. This is not a style function
4443 * but merely a convenience function for drawing the standard cursor shape.
4446 * Deprecated: 3.4: Use gtk_render_insertion_cursor() instead.
4449 gtk_draw_insertion_cursor (GtkWidget *widget,
4451 const GdkRectangle *location,
4452 gboolean is_primary,
4453 GtkTextDirection direction,
4454 gboolean draw_arrow)
4456 GtkStyleContext *context;
4458 g_return_if_fail (GTK_IS_WIDGET (widget));
4459 g_return_if_fail (cr != NULL);
4460 g_return_if_fail (location != NULL);
4461 g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
4463 context = gtk_widget_get_style_context (widget);
4465 draw_insertion_cursor (context, cr,
4466 location->x, location->y, location->height,
4468 (direction == GTK_TEXT_DIR_RTL) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR,
4472 static AtkAttributeSet *
4473 add_attribute (AtkAttributeSet *attributes,
4474 AtkTextAttribute attr,
4479 at = g_new (AtkAttribute, 1);
4480 at->name = g_strdup (atk_text_attribute_get_name (attr));
4481 at->value = g_strdup (value);
4483 return g_slist_prepend (attributes, at);
4487 * _gtk_style_context_get_attributes:
4488 * @attributes: a #AtkAttributeSet to add attributes to
4489 * @context: the #GtkStyleContext to get attributes from
4490 * @flags: the state to use with @context
4492 * Adds the foreground and background color from @context to
4493 * @attributes, after translating them to ATK attributes.
4495 * This is a convenience function that can be used in
4496 * implementing the #AtkText interface in widgets.
4498 * Returns: the modified #AtkAttributeSet
4501 _gtk_style_context_get_attributes (AtkAttributeSet *attributes,
4502 GtkStyleContext *context,
4503 GtkStateFlags flags)
4508 gtk_style_context_get_background_color (context, flags, &color);
4509 value = g_strdup_printf ("%u,%u,%u",
4510 (guint) ceil (color.red * 65536 - color.red),
4511 (guint) ceil (color.green * 65536 - color.green),
4512 (guint) ceil (color.blue * 65536 - color.blue));
4513 attributes = add_attribute (attributes, ATK_TEXT_ATTR_BG_COLOR, value);
4516 gtk_style_context_get_color (context, flags, &color);
4517 value = g_strdup_printf ("%u,%u,%u",
4518 (guint) ceil (color.red * 65536 - color.red),
4519 (guint) ceil (color.green * 65536 - color.green),
4520 (guint) ceil (color.blue * 65536 - color.blue));
4521 attributes = add_attribute (attributes, ATK_TEXT_ATTR_FG_COLOR, value);