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 "gtkcssrgbavalueprivate.h"
27 #include "gtkstylepropertiesprivate.h"
28 #include "gtktypebuiltins.h"
29 #include "gtkthemingengineprivate.h"
31 #include "gtkwidget.h"
32 #include "gtkwindow.h"
33 #include "gtkprivate.h"
34 #include "gtksymboliccolorprivate.h"
35 #include "gtkanimationdescription.h"
36 #include "gtkcssnumbervalueprivate.h"
37 #include "gtktimeline.h"
38 #include "gtkiconfactory.h"
39 #include "gtkwidgetpath.h"
40 #include "gtkwidgetprivate.h"
41 #include "gtkstylecascadeprivate.h"
42 #include "gtkstyleproviderprivate.h"
43 #include "gtksettings.h"
46 * SECTION:gtkstylecontext
47 * @Short_description: Rendering UI elements
48 * @Title: GtkStyleContext
50 * #GtkStyleContext is an object that stores styling information affecting
51 * a widget defined by #GtkWidgetPath.
53 * In order to construct the final style information, #GtkStyleContext
54 * queries information from all attached #GtkStyleProviders. Style providers
55 * can be either attached explicitly to the context through
56 * gtk_style_context_add_provider(), or to the screen through
57 * gtk_style_context_add_provider_for_screen(). The resulting style is a
58 * combination of all providers' information in priority order.
60 * For GTK+ widgets, any #GtkStyleContext returned by
61 * gtk_widget_get_style_context() will already have a #GtkWidgetPath, a
62 * #GdkScreen and RTL/LTR information set. The style context will be also
63 * updated automatically if any of these settings change on the widget.
65 * If you are using the theming layer standalone, you will need to set a
66 * widget path and a screen yourself to the created style context through
67 * gtk_style_context_set_path() and gtk_style_context_set_screen(), as well
68 * as updating the context yourself using gtk_style_context_invalidate()
69 * whenever any of the conditions change, such as a change in the
70 * #GtkSettings:gtk-theme-name setting or a hierarchy change in the rendered
73 * <refsect2 id="gtkstylecontext-animations">
74 * <title>Transition animations</title>
76 * #GtkStyleContext has built-in support for state change transitions.
77 * Note that these animations respect the #GtkSettings:gtk-enable-animations
81 * For simple widgets where state changes affect the whole widget area,
82 * calling gtk_style_context_notify_state_change() with a %NULL region
83 * is sufficient to trigger the transition animation. And GTK+ already
84 * does that when gtk_widget_set_state() or gtk_widget_set_state_flags()
88 * If a widget needs to declare several animatable regions (i.e. not
89 * affecting the whole widget area), its #GtkWidget::draw signal handler
90 * needs to wrap the render operations for the different regions with
91 * calls to gtk_style_context_push_animatable_region() and
92 * gtk_style_context_pop_animatable_region(). These functions take an
93 * identifier for the region which must be unique within the style context.
94 * For simple widgets with a fixed set of animatable regions, using an
95 * enumeration works well:
98 * <title>Using an enumeration to identify animatable regions</title>
109 * spin_button_draw (GtkWidget *widget,
112 * GtkStyleContext *context;
114 * context = gtk_widget_get_style_context (widget);
116 * gtk_style_context_push_animatable_region (context,
117 * GUINT_TO_POINTER (REGION_ENTRY));
119 * gtk_render_background (cr, 0, 0, 100, 30);
120 * gtk_render_frame (cr, 0, 0, 100, 30);
122 * gtk_style_context_pop_animatable_region (context);
129 * For complex widgets with an arbitrary number of animatable regions, it
130 * is up to the implementation to come up with a way to uniquely identify
131 * each animatable region. Using pointers to internal structs is one way
135 * <title>Using struct pointers to identify animatable regions</title>
138 * notebook_draw_tab (GtkWidget *widget,
139 * NotebookPage *page,
142 * gtk_style_context_push_animatable_region (context, page);
143 * gtk_render_extension (cr, page->x, page->y, page->width, page->height);
144 * gtk_style_context_pop_animatable_region (context);
149 * The widget also needs to notify the style context about a state change
150 * for a given animatable region so the animation is triggered.
153 * <title>Triggering a state change animation on a region</title>
156 * notebook_motion_notify (GtkWidget *widget,
157 * GdkEventMotion *event)
159 * GtkStyleContext *context;
160 * NotebookPage *page;
162 * context = gtk_widget_get_style_context (widget);
163 * page = find_page_under_pointer (widget, event);
164 * gtk_style_context_notify_state_change (context,
165 * gtk_widget_get_window (widget),
167 * GTK_STATE_PRELIGHT,
174 * gtk_style_context_notify_state_change() accepts %NULL region IDs as a
175 * special value, in this case, the whole widget area will be updated
179 * <refsect2 id="gtkstylecontext-classes">
180 * <title>Style classes and regions</title>
182 * Widgets can add style classes to their context, which can be used
183 * to associate different styles by class (see <xref linkend="gtkcssprovider-selectors"/>). Theme engines can also use style classes to vary their
184 * rendering. GTK+ has a number of predefined style classes:
185 * #GTK_STYLE_CLASS_CELL,
186 * #GTK_STYLE_CLASS_ENTRY,
187 * #GTK_STYLE_CLASS_BUTTON,
188 * #GTK_STYLE_CLASS_COMBOBOX_ENTRY,
189 * #GTK_STYLE_CLASS_CALENDAR,
190 * #GTK_STYLE_CLASS_SLIDER,
191 * #GTK_STYLE_CLASS_BACKGROUND,
192 * #GTK_STYLE_CLASS_RUBBERBAND,
193 * #GTK_STYLE_CLASS_TOOLTIP,
194 * #GTK_STYLE_CLASS_MENU,
195 * #GTK_STYLE_CLASS_MENUBAR,
196 * #GTK_STYLE_CLASS_MENUITEM,
197 * #GTK_STYLE_CLASS_TOOLBAR,
198 * #GTK_STYLE_CLASS_PRIMARY_TOOLBAR,
199 * #GTK_STYLE_CLASS_INLINE_TOOLBAR,
200 * #GTK_STYLE_CLASS_RADIO,
201 * #GTK_STYLE_CLASS_CHECK,
202 * #GTK_STYLE_CLASS_TROUGH,
203 * #GTK_STYLE_CLASS_SCROLLBAR,
204 * #GTK_STYLE_CLASS_SCALE,
205 * #GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE,
206 * #GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW,
207 * #GTK_STYLE_CLASS_HEADER,
208 * #GTK_STYLE_CLASS_ACCELERATOR,
209 * #GTK_STYLE_CLASS_GRIP,
210 * #GTK_STYLE_CLASS_DOCK,
211 * #GTK_STYLE_CLASS_PROGRESSBAR,
212 * #GTK_STYLE_CLASS_SPINNER,
213 * #GTK_STYLE_CLASS_EXPANDER,
214 * #GTK_STYLE_CLASS_SPINBUTTON,
215 * #GTK_STYLE_CLASS_NOTEBOOK,
216 * #GTK_STYLE_CLASS_VIEW,
217 * #GTK_STYLE_CLASS_SIDEBAR,
218 * #GTK_STYLE_CLASS_IMAGE,
219 * #GTK_STYLE_CLASS_HIGHLIGHT,
220 * #GTK_STYLE_CLASS_FRAME,
221 * #GTK_STYLE_CLASS_DND,
222 * #GTK_STYLE_CLASS_PANE_SEPARATOR,
223 * #GTK_STYLE_CLASS_SEPARATOR,
224 * #GTK_STYLE_CLASS_INFO,
225 * #GTK_STYLE_CLASS_WARNING,
226 * #GTK_STYLE_CLASS_QUESTION,
227 * #GTK_STYLE_CLASS_ERROR,
228 * #GTK_STYLE_CLASS_HORIZONTAL,
229 * #GTK_STYLE_CLASS_VERTICAL,
230 * #GTK_STYLE_CLASS_TOP,
231 * #GTK_STYLE_CLASS_BOTTOM,
232 * #GTK_STYLE_CLASS_LEFT,
233 * #GTK_STYLE_CLASS_RIGHT,
236 * Widgets can also add regions with flags to their context.
237 * The regions used by GTK+ widgets are:
242 * <entry>Region</entry>
243 * <entry>Flags</entry>
244 * <entry>Macro</entry>
245 * <entry>Used by</entry>
251 * <entry>even, odd</entry>
252 * <entry>GTK_STYLE_REGION_ROW</entry>
253 * <entry>#GtkTreeView</entry>
256 * <entry>column</entry>
257 * <entry>first, last, sorted</entry>
258 * <entry>GTK_STYLE_REGION_COLUMN</entry>
259 * <entry>#GtkTreeView</entry>
262 * <entry>column-header</entry>
264 * <entry>GTK_STYLE_REGION_COLUMN_HEADER</entry>
269 * <entry>even, odd, first, last</entry>
270 * <entry>GTK_STYLE_REGION_TAB</entry>
271 * <entry>#GtkNotebook</entry>
278 * <refsect2 id="gtkstylecontext-custom-styling">
279 * <title>Custom styling in UI libraries and applications</title>
281 * If you are developing a library with custom #GtkWidget<!-- -->s that
282 * render differently than standard components, you may need to add a
283 * #GtkStyleProvider yourself with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK
284 * priority, either a #GtkCssProvider or a custom object implementing the
285 * #GtkStyleProvider interface. This way theming engines may still attempt
286 * to style your UI elements in a different way if needed so.
289 * If you are using custom styling on an applications, you probably want then
290 * to make your style information prevail to the theme's, so you must use
291 * a #GtkStyleProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
292 * priority, keep in mind that the user settings in
293 * <filename><replaceable>XDG_CONFIG_HOME</replaceable>/gtk-3.0/gtk.css</filename> will
294 * still take precedence over your changes, as it uses the
295 * %GTK_STYLE_PROVIDER_PRIORITY_USER priority.
298 * If a custom theming engine is needed, you probably want to implement a
299 * #GtkStyleProvider yourself so it points to your #GtkThemingEngine
300 * implementation, as #GtkCssProvider uses gtk_theming_engine_load()
301 * which loads the theming engine module from the standard paths.
306 /* When these change we do a full restyling. Otherwise we try to figure out
307 * if we need to change things. */
308 #define GTK_STYLE_CONTEXT_RADICAL_CHANGE (GTK_CSS_CHANGE_NAME | GTK_CSS_CHANGE_CLASS)
309 /* When these change we don't clear the cache. This takes more memory but makes
310 * things go faster. */
311 #define GTK_STYLE_CONTEXT_CACHED_CHANGE (GTK_CSS_CHANGE_STATE)
313 typedef struct GtkStyleInfo GtkStyleInfo;
314 typedef struct GtkRegion GtkRegion;
315 typedef struct PropertyValue PropertyValue;
316 typedef struct AnimationInfo AnimationInfo;
317 typedef struct StyleData StyleData;
322 GtkRegionFlags flags;
335 GArray *style_classes;
337 GtkJunctionSides junction_sides;
338 GtkStateFlags state_flags;
344 GtkCssComputedValues *store;
345 GArray *property_cache;
350 GtkTimeline *timeline;
354 /* Region stack (until region_id) at the time of
355 * rendering, this is used for nested cancellation.
357 GSList *parent_regions;
361 gboolean target_value;
363 cairo_region_t *invalidation_region;
367 struct _GtkStyleContextPrivate
371 GtkStyleCascade *cascade;
373 GtkStyleContext *parent;
376 GtkWidgetPath *widget_path;
377 GHashTable *style_data;
380 GSList *animation_regions;
383 GtkThemingEngine *theming_engine;
385 GtkTextDirection direction;
387 GtkCssChange relevant_changes;
388 GtkCssChange pending_changes;
390 guint animations_invalidated : 1;
391 guint invalidating_context : 1;
407 static guint signals[LAST_SIGNAL] = { 0 };
409 static void gtk_style_context_finalize (GObject *object);
411 static void gtk_style_context_impl_set_property (GObject *object,
415 static void gtk_style_context_impl_get_property (GObject *object,
419 static GtkSymbolicColor *
420 gtk_style_context_color_lookup_func (gpointer contextp,
424 G_DEFINE_TYPE (GtkStyleContext, gtk_style_context, G_TYPE_OBJECT)
427 gtk_style_context_real_changed (GtkStyleContext *context)
429 GtkStyleContextPrivate *priv = context->priv;
432 _gtk_widget_style_context_invalidated (priv->widget);
436 gtk_style_context_class_init (GtkStyleContextClass *klass)
438 GObjectClass *object_class = G_OBJECT_CLASS (klass);
440 object_class->finalize = gtk_style_context_finalize;
441 object_class->set_property = gtk_style_context_impl_set_property;
442 object_class->get_property = gtk_style_context_impl_get_property;
444 klass->changed = gtk_style_context_real_changed;
447 g_signal_new (I_("changed"),
448 G_TYPE_FROM_CLASS (object_class),
450 G_STRUCT_OFFSET (GtkStyleContextClass, changed),
452 g_cclosure_marshal_VOID__VOID,
455 g_object_class_install_property (object_class,
457 g_param_spec_object ("screen",
459 P_("The associated GdkScreen"),
461 GTK_PARAM_READWRITE));
462 g_object_class_install_property (object_class,
464 g_param_spec_enum ("direction",
466 P_("Text direction"),
467 GTK_TYPE_TEXT_DIRECTION,
469 GTK_PARAM_READWRITE));
471 * GtkStyleContext:parent:
473 * Sets or gets the style context's parent. See gtk_style_context_set_parent()
478 g_object_class_install_property (object_class,
480 g_param_spec_object ("parent",
482 P_("The parent style context"),
483 GTK_TYPE_STYLE_CONTEXT,
484 GTK_PARAM_READWRITE));
486 g_type_class_add_private (object_class, sizeof (GtkStyleContextPrivate));
489 static GtkStyleInfo *
490 style_info_new (void)
494 info = g_slice_new0 (GtkStyleInfo);
495 info->style_classes = g_array_new (FALSE, FALSE, sizeof (GQuark));
496 info->regions = g_array_new (FALSE, FALSE, sizeof (GtkRegion));
502 style_info_free (GtkStyleInfo *info)
504 g_array_free (info->style_classes, TRUE);
505 g_array_free (info->regions, TRUE);
506 g_slice_free (GtkStyleInfo, info);
509 static GtkStyleInfo *
510 style_info_copy (const GtkStyleInfo *info)
514 copy = style_info_new ();
515 g_array_insert_vals (copy->style_classes, 0,
516 info->style_classes->data,
517 info->style_classes->len);
519 g_array_insert_vals (copy->regions, 0,
523 copy->junction_sides = info->junction_sides;
524 copy->state_flags = info->state_flags;
525 copy->data = info->data;
531 style_info_hash (gconstpointer elem)
533 const GtkStyleInfo *info;
538 for (i = 0; i < info->style_classes->len; i++)
540 hash += g_array_index (info->style_classes, GQuark, i);
544 for (i = 0; i < info->regions->len; i++)
548 region = &g_array_index (info->regions, GtkRegion, i);
549 hash += region->class_quark;
550 hash += region->flags;
554 return hash ^ info->state_flags;
558 style_info_equal (gconstpointer elem1,
561 const GtkStyleInfo *info1, *info2;
566 if (info1->state_flags != info2->state_flags)
569 if (info1->junction_sides != info2->junction_sides)
572 if (info1->style_classes->len != info2->style_classes->len)
575 if (memcmp (info1->style_classes->data,
576 info2->style_classes->data,
577 info1->style_classes->len * sizeof (GQuark)) != 0)
580 if (info1->regions->len != info2->regions->len)
583 if (memcmp (info1->regions->data,
584 info2->regions->data,
585 info1->regions->len * sizeof (GtkRegion)) != 0)
592 style_data_new (void)
596 data = g_slice_new0 (StyleData);
602 clear_property_cache (StyleData *data)
606 if (!data->property_cache)
609 for (i = 0; i < data->property_cache->len; i++)
611 PropertyValue *node = &g_array_index (data->property_cache, PropertyValue, i);
613 g_param_spec_unref (node->pspec);
614 g_value_unset (&node->value);
617 g_array_free (data->property_cache, TRUE);
618 data->property_cache = NULL;
622 style_data_free (StyleData *data)
624 g_object_unref (data->store);
625 clear_property_cache (data);
627 g_slice_free (StyleData, data);
631 gtk_style_context_init (GtkStyleContext *style_context)
633 GtkStyleContextPrivate *priv;
636 priv = style_context->priv = G_TYPE_INSTANCE_GET_PRIVATE (style_context,
637 GTK_TYPE_STYLE_CONTEXT,
638 GtkStyleContextPrivate);
640 priv->style_data = g_hash_table_new_full (style_info_hash,
642 (GDestroyNotify) style_info_free,
643 (GDestroyNotify) style_data_free);
644 priv->theming_engine = g_object_ref ((gpointer) gtk_theming_engine_load (NULL));
646 priv->direction = GTK_TEXT_DIR_LTR;
648 priv->screen = gdk_screen_get_default ();
649 priv->cascade = _gtk_style_cascade_get_for_screen (priv->screen);
650 g_object_ref (priv->cascade);
651 priv->relevant_changes = GTK_CSS_CHANGE_ANY;
653 /* Create default info store */
654 info = style_info_new ();
655 priv->info_stack = g_slist_prepend (priv->info_stack, info);
659 animation_info_free (AnimationInfo *info)
661 g_object_unref (info->timeline);
662 g_object_unref (info->window);
664 if (info->invalidation_region)
665 cairo_region_destroy (info->invalidation_region);
667 g_array_free (info->rectangles, TRUE);
668 g_slist_free (info->parent_regions);
669 g_slice_free (AnimationInfo, info);
672 static AnimationInfo *
673 animation_info_lookup_by_timeline (GtkStyleContext *context,
674 GtkTimeline *timeline)
676 GtkStyleContextPrivate *priv;
680 priv = context->priv;
682 for (l = priv->animations; l; l = l->next)
686 if (info->timeline == timeline)
694 timeline_frame_cb (GtkTimeline *timeline,
698 GtkStyleContextPrivate *priv;
699 GtkStyleContext *context;
703 priv = context->priv;
704 info = animation_info_lookup_by_timeline (context, timeline);
706 g_assert (info != NULL);
708 /* Cancel transition if window is gone */
709 if (gdk_window_is_destroyed (info->window) ||
710 !gdk_window_is_visible (info->window))
712 priv->animations = g_slist_remove (priv->animations, info);
713 animation_info_free (info);
717 if (info->invalidation_region &&
718 !cairo_region_is_empty (info->invalidation_region))
719 gdk_window_invalidate_region (info->window, info->invalidation_region, TRUE);
721 gdk_window_invalidate_rect (info->window, NULL, TRUE);
725 timeline_finished_cb (GtkTimeline *timeline,
728 GtkStyleContextPrivate *priv;
729 GtkStyleContext *context;
733 priv = context->priv;
734 info = animation_info_lookup_by_timeline (context, timeline);
736 g_assert (info != NULL);
738 priv->animations = g_slist_remove (priv->animations, info);
740 /* Invalidate one last time the area, so the final content is painted */
741 if (info->invalidation_region &&
742 !cairo_region_is_empty (info->invalidation_region))
743 gdk_window_invalidate_region (info->window, info->invalidation_region, TRUE);
745 gdk_window_invalidate_rect (info->window, NULL, TRUE);
747 animation_info_free (info);
750 static AnimationInfo *
751 animation_info_new (GtkStyleContext *context,
754 GtkTimelineProgressType progress_type,
757 gboolean target_value,
762 info = g_slice_new0 (AnimationInfo);
764 info->rectangles = g_array_new (FALSE, FALSE, sizeof (cairo_rectangle_int_t));
765 info->timeline = _gtk_timeline_new (duration);
766 info->window = g_object_ref (window);
768 info->target_value = target_value;
769 info->region_id = region_id;
771 _gtk_timeline_set_progress_type (info->timeline, progress_type);
772 _gtk_timeline_set_loop (info->timeline, loop);
774 if (!loop && !target_value)
776 _gtk_timeline_set_direction (info->timeline, GTK_TIMELINE_DIRECTION_BACKWARD);
777 _gtk_timeline_rewind (info->timeline);
780 g_signal_connect (info->timeline, "frame",
781 G_CALLBACK (timeline_frame_cb), context);
782 g_signal_connect (info->timeline, "finished",
783 G_CALLBACK (timeline_finished_cb), context);
785 _gtk_timeline_start (info->timeline);
790 static AnimationInfo *
791 animation_info_lookup (GtkStyleContext *context,
795 GtkStyleContextPrivate *priv;
798 priv = context->priv;
800 for (l = priv->animations; l; l = l->next)
806 if (info->state == state &&
807 info->region_id == region_id)
815 gtk_style_context_finalize (GObject *object)
817 GtkStyleContextPrivate *priv;
818 GtkStyleContext *style_context;
821 style_context = GTK_STYLE_CONTEXT (object);
822 priv = style_context->priv;
824 /* children hold a reference to us */
825 g_assert (priv->children == NULL);
827 gtk_style_context_set_parent (style_context, NULL);
829 if (priv->widget_path)
830 gtk_widget_path_free (priv->widget_path);
832 g_hash_table_destroy (priv->style_data);
834 g_object_unref (priv->cascade);
836 g_slist_free_full (priv->info_stack, (GDestroyNotify) style_info_free);
838 g_slist_free (priv->animation_regions);
840 for (l = priv->animations; l; l = l->next)
841 animation_info_free ((AnimationInfo *) l->data);
843 g_slist_free (priv->animations);
845 if (priv->theming_engine)
846 g_object_unref (priv->theming_engine);
848 G_OBJECT_CLASS (gtk_style_context_parent_class)->finalize (object);
852 gtk_style_context_impl_set_property (GObject *object,
857 GtkStyleContext *style_context;
859 style_context = GTK_STYLE_CONTEXT (object);
864 gtk_style_context_set_screen (style_context,
865 g_value_get_object (value));
868 gtk_style_context_set_direction (style_context,
869 g_value_get_enum (value));
872 gtk_style_context_set_parent (style_context,
873 g_value_get_object (value));
876 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
882 gtk_style_context_impl_get_property (GObject *object,
887 GtkStyleContext *style_context;
888 GtkStyleContextPrivate *priv;
890 style_context = GTK_STYLE_CONTEXT (object);
891 priv = style_context->priv;
896 g_value_set_object (value, priv->screen);
899 g_value_set_enum (value, priv->direction);
902 g_value_set_object (value, priv->parent);
905 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
911 build_properties (GtkStyleContext *context,
912 StyleData *style_data,
916 GtkStyleContextPrivate *priv;
917 GtkCssMatcher matcher;
918 GtkCssLookup *lookup;
920 priv = context->priv;
922 _gtk_css_matcher_init (&matcher, path, state);
923 lookup = _gtk_css_lookup_new ();
925 _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
929 style_data->store = _gtk_css_computed_values_new ();
930 _gtk_css_lookup_resolve (lookup, context, style_data->store);
931 _gtk_css_lookup_free (lookup);
934 static GtkWidgetPath *
935 create_query_path (GtkStyleContext *context)
937 GtkStyleContextPrivate *priv;
942 priv = context->priv;
943 path = gtk_widget_path_copy (priv->widget ? gtk_widget_get_path (priv->widget) : priv->widget_path);
944 pos = gtk_widget_path_length (path) - 1;
946 info = priv->info_stack->data;
948 /* Set widget regions */
949 for (i = 0; i < info->regions->len; i++)
953 region = &g_array_index (info->regions, GtkRegion, i);
954 gtk_widget_path_iter_add_region (path, pos,
955 g_quark_to_string (region->class_quark),
959 /* Set widget classes */
960 for (i = 0; i < info->style_classes->len; i++)
964 quark = g_array_index (info->style_classes, GQuark, i);
965 gtk_widget_path_iter_add_class (path, pos,
966 g_quark_to_string (quark));
973 style_data_lookup (GtkStyleContext *context)
975 GtkStyleContextPrivate *priv;
979 priv = context->priv;
980 info = priv->info_stack->data;
982 /* Current data in use is cached, just return it */
986 g_assert (priv->widget != NULL || priv->widget_path != NULL);
988 info->data = g_hash_table_lookup (priv->style_data, info);
994 path = create_query_path (context);
996 info->data = style_data_new ();
997 g_hash_table_insert (priv->style_data,
998 style_info_copy (info),
1001 build_properties (context, info->data, path, info->state_flags);
1003 gtk_widget_path_free (path);
1006 if (priv->theming_engine)
1007 g_object_unref (priv->theming_engine);
1009 v = _gtk_css_computed_values_get_value_by_name (info->data->store, "engine");
1011 priv->theming_engine = _gtk_css_value_dup_object (v);
1013 priv->theming_engine = g_object_ref (gtk_theming_engine_load (NULL));
1019 gtk_style_context_set_invalid (GtkStyleContext *context,
1022 GtkStyleContextPrivate *priv;
1024 priv = context->priv;
1026 if (priv->invalid == invalid)
1029 priv->invalid = invalid;
1034 gtk_widget_queue_resize (priv->widget);
1036 gtk_style_context_set_invalid (priv->parent, TRUE);
1040 /* returns TRUE if someone called gtk_style_context_save() but hasn't
1041 * called gtk_style_context_restore() yet.
1042 * In those situations we don't invalidate the context when somebody
1043 * changes state/regions/classes.
1046 gtk_style_context_is_saved (GtkStyleContext *context)
1048 return context->priv->info_stack->next != NULL;
1052 gtk_style_context_queue_invalidate_internal (GtkStyleContext *context,
1053 GtkCssChange change)
1055 GtkStyleContextPrivate *priv = context->priv;
1056 GtkStyleInfo *info = priv->info_stack->data;
1058 if (gtk_style_context_is_saved (context))
1064 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_STATE);
1065 /* XXX: We need to invalidate siblings here somehow */
1070 * gtk_style_context_new:
1072 * Creates a standalone #GtkStyleContext, this style context
1073 * won't be attached to any widget, so you may want
1074 * to call gtk_style_context_set_path() yourself.
1077 * This function is only useful when using the theming layer
1078 * separated from GTK+, if you are using #GtkStyleContext to
1079 * theme #GtkWidget<!-- -->s, use gtk_widget_get_style_context()
1080 * in order to get a style context ready to theme the widget.
1083 * Returns: A newly created #GtkStyleContext.
1086 gtk_style_context_new (void)
1088 return g_object_new (GTK_TYPE_STYLE_CONTEXT, NULL);
1092 _gtk_style_context_set_widget (GtkStyleContext *context,
1095 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1096 g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget));
1098 context->priv->widget = widget;
1100 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY_SELF);
1104 * gtk_style_context_add_provider:
1105 * @context: a #GtkStyleContext
1106 * @provider: a #GtkStyleProvider
1107 * @priority: the priority of the style provider. The lower
1108 * it is, the earlier it will be used in the style
1109 * construction. Typically this will be in the range
1110 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1111 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1113 * Adds a style provider to @context, to be used in style construction.
1115 * <note><para>If both priorities are the same, A #GtkStyleProvider
1116 * added through this function takes precedence over another added
1117 * through gtk_style_context_add_provider_for_screen().</para></note>
1122 gtk_style_context_add_provider (GtkStyleContext *context,
1123 GtkStyleProvider *provider,
1126 GtkStyleContextPrivate *priv;
1128 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1129 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1131 priv = context->priv;
1133 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
1135 GtkStyleCascade *new_cascade;
1137 new_cascade = _gtk_style_cascade_new ();
1138 _gtk_style_cascade_set_parent (new_cascade, priv->cascade);
1139 g_object_unref (priv->cascade);
1140 priv->cascade = new_cascade;
1143 _gtk_style_cascade_add_provider (priv->cascade, provider, priority);
1145 gtk_style_context_invalidate (context);
1149 * gtk_style_context_remove_provider:
1150 * @context: a #GtkStyleContext
1151 * @provider: a #GtkStyleProvider
1153 * Removes @provider from the style providers list in @context.
1158 gtk_style_context_remove_provider (GtkStyleContext *context,
1159 GtkStyleProvider *provider)
1161 GtkStyleContextPrivate *priv;
1163 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1164 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1166 priv = context->priv;
1168 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
1171 _gtk_style_cascade_remove_provider (priv->cascade, provider);
1175 * gtk_style_context_reset_widgets:
1176 * @screen: a #GdkScreen
1178 * This function recomputes the styles for all widgets under a particular
1179 * #GdkScreen. This is useful when some global parameter has changed that
1180 * affects the appearance of all widgets, because when a widget gets a new
1181 * style, it will both redraw and recompute any cached information about
1182 * its appearance. As an example, it is used when the color scheme changes
1183 * in the related #GtkSettings object.
1188 gtk_style_context_reset_widgets (GdkScreen *screen)
1190 GList *list, *toplevels;
1192 _gtk_icon_set_invalidate_caches ();
1194 toplevels = gtk_window_list_toplevels ();
1195 g_list_foreach (toplevels, (GFunc) g_object_ref, NULL);
1197 for (list = toplevels; list; list = list->next)
1199 if (gtk_widget_get_screen (list->data) == screen)
1200 gtk_widget_reset_style (list->data);
1202 g_object_unref (list->data);
1205 g_list_free (toplevels);
1209 * gtk_style_context_add_provider_for_screen:
1210 * @screen: a #GdkScreen
1211 * @provider: a #GtkStyleProvider
1212 * @priority: the priority of the style provider. The lower
1213 * it is, the earlier it will be used in the style
1214 * construction. Typically this will be in the range
1215 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1216 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1218 * Adds a global style provider to @screen, which will be used
1219 * in style construction for all #GtkStyleContext<!-- -->s under
1222 * GTK+ uses this to make styling information from #GtkSettings
1225 * <note><para>If both priorities are the same, A #GtkStyleProvider
1226 * added through gtk_style_context_add_provider() takes precedence
1227 * over another added through this function.</para></note>
1232 gtk_style_context_add_provider_for_screen (GdkScreen *screen,
1233 GtkStyleProvider *provider,
1236 GtkStyleCascade *cascade;
1238 g_return_if_fail (GDK_IS_SCREEN (screen));
1239 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1241 cascade = _gtk_style_cascade_get_for_screen (screen);
1242 _gtk_style_cascade_add_provider (cascade, provider, priority);
1246 * gtk_style_context_remove_provider_for_screen:
1247 * @screen: a #GdkScreen
1248 * @provider: a #GtkStyleProvider
1250 * Removes @provider from the global style providers list in @screen.
1255 gtk_style_context_remove_provider_for_screen (GdkScreen *screen,
1256 GtkStyleProvider *provider)
1258 GtkStyleCascade *cascade;
1260 g_return_if_fail (GDK_IS_SCREEN (screen));
1261 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1263 cascade = _gtk_style_cascade_get_for_screen (screen);
1264 _gtk_style_cascade_remove_provider (cascade, provider);
1268 * gtk_style_context_get_section:
1269 * @context: a #GtkStyleContext
1270 * @property: style property name
1272 * Queries the location in the CSS where @property was defined for the
1273 * current @context. Note that the state to be queried is taken from
1274 * gtk_style_context_get_state().
1276 * If the location is not available, %NULL will be returned. The
1277 * location might not be available for various reasons, such as the
1278 * property being overridden, @property not naming a supported CSS
1279 * property or tracking of definitions being disabled for performance
1282 * Shorthand CSS properties cannot be queried for a location and will
1283 * always return %NULL.
1285 * Returns: %NULL or the section where value was defined
1288 gtk_style_context_get_section (GtkStyleContext *context,
1289 const gchar *property)
1291 GtkStyleContextPrivate *priv;
1292 GtkStyleProperty *prop;
1295 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1296 g_return_val_if_fail (property != NULL, NULL);
1298 priv = context->priv;
1299 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
1301 prop = _gtk_style_property_lookup (property);
1302 if (!GTK_IS_CSS_STYLE_PROPERTY (prop))
1305 data = style_data_lookup (context);
1306 return _gtk_css_computed_values_get_section (data->store, _gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (prop)));
1309 static GtkCssValue *
1310 gtk_style_context_query_func (guint id,
1313 return _gtk_css_computed_values_get_value (values, id);
1317 * gtk_style_context_get_property:
1318 * @context: a #GtkStyleContext
1319 * @property: style property name
1320 * @state: state to retrieve the property value for
1321 * @value: (out) (transfer full): return location for the style property value
1323 * Gets a style property from @context for the given state.
1325 * When @value is no longer needed, g_value_unset() must be called
1326 * to free any allocated memory.
1331 gtk_style_context_get_property (GtkStyleContext *context,
1332 const gchar *property,
1333 GtkStateFlags state,
1336 GtkStyleContextPrivate *priv;
1337 GtkStyleProperty *prop;
1340 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1341 g_return_if_fail (property != NULL);
1342 g_return_if_fail (value != NULL);
1344 priv = context->priv;
1345 g_return_if_fail (priv->widget != NULL || priv->widget_path != NULL);
1347 prop = _gtk_style_property_lookup (property);
1350 g_warning ("Style property \"%s\" is not registered", property);
1353 if (_gtk_style_property_get_value_type (prop) == G_TYPE_NONE)
1355 g_warning ("Style property \"%s\" is not gettable", property);
1359 gtk_style_context_save (context);
1360 gtk_style_context_set_state (context, state);
1361 data = style_data_lookup (context);
1362 _gtk_style_property_query (prop, value, gtk_style_context_query_func, data->store);
1363 gtk_style_context_restore (context);
1367 * gtk_style_context_get_valist:
1368 * @context: a #GtkStyleContext
1369 * @state: state to retrieve the property values for
1370 * @args: va_list of property name/return location pairs, followed by %NULL
1372 * Retrieves several style property values from @context for a given state.
1377 gtk_style_context_get_valist (GtkStyleContext *context,
1378 GtkStateFlags state,
1381 const gchar *property_name;
1383 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1385 property_name = va_arg (args, const gchar *);
1387 while (property_name)
1389 gchar *error = NULL;
1390 GValue value = G_VALUE_INIT;
1392 gtk_style_context_get_property (context,
1397 G_VALUE_LCOPY (&value, args, 0, &error);
1398 g_value_unset (&value);
1402 g_warning ("Could not get style property \"%s\": %s", property_name, error);
1407 property_name = va_arg (args, const gchar *);
1412 * gtk_style_context_get:
1413 * @context: a #GtkStyleContext
1414 * @state: state to retrieve the property values for
1415 * @...: property name /return value pairs, followed by %NULL
1417 * Retrieves several style property values from @context for a
1423 gtk_style_context_get (GtkStyleContext *context,
1424 GtkStateFlags state,
1429 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1431 va_start (args, state);
1432 gtk_style_context_get_valist (context, state, args);
1437 * gtk_style_context_set_state:
1438 * @context: a #GtkStyleContext
1439 * @flags: state to represent
1441 * Sets the state to be used when rendering with any
1442 * of the gtk_render_*() functions.
1447 gtk_style_context_set_state (GtkStyleContext *context,
1448 GtkStateFlags flags)
1450 GtkStyleContextPrivate *priv;
1453 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1455 priv = context->priv;
1456 info = priv->info_stack->data;
1457 info->state_flags = flags;
1459 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_STATE);
1463 * gtk_style_context_get_state:
1464 * @context: a #GtkStyleContext
1466 * Returns the state used when rendering.
1468 * Returns: the state flags
1473 gtk_style_context_get_state (GtkStyleContext *context)
1475 GtkStyleContextPrivate *priv;
1478 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
1480 priv = context->priv;
1481 info = priv->info_stack->data;
1483 return info->state_flags;
1487 context_has_animatable_region (GtkStyleContext *context,
1490 GtkStyleContextPrivate *priv;
1492 /* NULL region_id means everything
1493 * rendered through the style context
1498 priv = context->priv;
1499 return g_slist_find (priv->animation_regions, region_id) != NULL;
1503 * gtk_style_context_state_is_running:
1504 * @context: a #GtkStyleContext
1505 * @state: a widget state
1506 * @progress: (out): return location for the transition progress
1508 * Returns %TRUE if there is a transition animation running for the
1509 * current region (see gtk_style_context_push_animatable_region()).
1511 * If @progress is not %NULL, the animation progress will be returned
1512 * there, 0.0 means the state is closest to being unset, while 1.0 means
1513 * it's closest to being set. This means transition animation will
1514 * run from 0 to 1 when @state is being set and from 1 to 0 when
1517 * Returns: %TRUE if there is a running transition animation for @state.
1522 gtk_style_context_state_is_running (GtkStyleContext *context,
1526 GtkStyleContextPrivate *priv;
1527 AnimationInfo *info;
1530 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1532 priv = context->priv;
1534 for (l = priv->animations; l; l = l->next)
1538 if (info->state == state &&
1539 context_has_animatable_region (context, info->region_id))
1542 *progress = _gtk_timeline_get_progress (info->timeline);
1552 * gtk_style_context_set_path:
1553 * @context: a #GtkStyleContext
1554 * @path: a #GtkWidgetPath
1556 * Sets the #GtkWidgetPath used for style matching. As a
1557 * consequence, the style will be regenerated to match
1558 * the new given path.
1560 * If you are using a #GtkStyleContext returned from
1561 * gtk_widget_get_style_context(), you do not need to call
1567 gtk_style_context_set_path (GtkStyleContext *context,
1568 GtkWidgetPath *path)
1570 GtkStyleContextPrivate *priv;
1572 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1573 g_return_if_fail (path != NULL);
1575 priv = context->priv;
1576 g_return_if_fail (priv->widget == NULL);
1578 if (priv->widget_path)
1580 gtk_widget_path_free (priv->widget_path);
1581 priv->widget_path = NULL;
1585 priv->widget_path = gtk_widget_path_copy (path);
1587 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY);
1591 * gtk_style_context_get_path:
1592 * @context: a #GtkStyleContext
1594 * Returns the widget path used for style matching.
1596 * Returns: (transfer none): A #GtkWidgetPath
1600 const GtkWidgetPath *
1601 gtk_style_context_get_path (GtkStyleContext *context)
1603 GtkStyleContextPrivate *priv;
1605 priv = context->priv;
1607 return gtk_widget_get_path (priv->widget);
1609 return priv->widget_path;
1613 * gtk_style_context_set_parent:
1614 * @context: a #GtkStyleContext
1615 * @parent: (allow-none): the new parent or %NULL
1617 * Sets the parent style context for @context. The parent style
1618 * context is used to implement
1619 * <ulink url="http://www.w3.org/TR/css3-cascade/#inheritance">inheritance</ulink>
1622 * If you are using a #GtkStyleContext returned from
1623 * gtk_widget_get_style_context(), the parent will be set for you.
1628 gtk_style_context_set_parent (GtkStyleContext *context,
1629 GtkStyleContext *parent)
1631 GtkStyleContextPrivate *priv;
1633 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1634 g_return_if_fail (parent == NULL || GTK_IS_STYLE_CONTEXT (parent));
1636 priv = context->priv;
1638 if (priv->parent == parent)
1643 parent->priv->children = g_slist_prepend (parent->priv->children, context);
1644 g_object_ref (parent);
1646 gtk_style_context_set_invalid (parent, TRUE);
1651 priv->parent->priv->children = g_slist_remove (priv->parent->priv->children, context);
1652 g_object_unref (priv->parent);
1655 priv->parent = parent;
1657 g_object_notify (G_OBJECT (context), "parent");
1658 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY_PARENT | GTK_CSS_CHANGE_ANY_SIBLING);
1662 * gtk_style_context_get_parent:
1663 * @context: a #GtkStyleContext
1665 * Gets the parent context set via gtk_style_context_set_parent().
1666 * See that function for details.
1668 * Returns: (transfer none): the parent context or %NULL
1673 gtk_style_context_get_parent (GtkStyleContext *context)
1675 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1677 return context->priv->parent;
1681 * gtk_style_context_save:
1682 * @context: a #GtkStyleContext
1684 * Saves the @context state, so all modifications done through
1685 * gtk_style_context_add_class(), gtk_style_context_remove_class(),
1686 * gtk_style_context_add_region(), gtk_style_context_remove_region()
1687 * or gtk_style_context_set_junction_sides() can be reverted in one
1688 * go through gtk_style_context_restore().
1693 gtk_style_context_save (GtkStyleContext *context)
1695 GtkStyleContextPrivate *priv;
1698 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1700 priv = context->priv;
1702 g_assert (priv->info_stack != NULL);
1704 info = style_info_copy (priv->info_stack->data);
1705 priv->info_stack = g_slist_prepend (priv->info_stack, info);
1709 * gtk_style_context_restore:
1710 * @context: a #GtkStyleContext
1712 * Restores @context state to a previous stage.
1713 * See gtk_style_context_save().
1718 gtk_style_context_restore (GtkStyleContext *context)
1720 GtkStyleContextPrivate *priv;
1723 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1725 priv = context->priv;
1727 if (priv->info_stack)
1729 info = priv->info_stack->data;
1730 priv->info_stack = g_slist_remove (priv->info_stack, info);
1731 style_info_free (info);
1734 if (!priv->info_stack)
1736 g_warning ("Unpaired gtk_style_context_restore() call");
1738 /* Create default region */
1739 info = style_info_new ();
1740 priv->info_stack = g_slist_prepend (priv->info_stack, info);
1745 style_class_find (GArray *array,
1750 gboolean found = FALSE;
1756 if (!array || array->len == 0)
1760 max = array->len - 1;
1766 mid = (min + max) / 2;
1767 item = g_array_index (array, GQuark, mid);
1769 if (class_quark == item)
1774 else if (class_quark > item)
1775 min = pos = mid + 1;
1782 while (!found && min <= max);
1791 region_find (GArray *array,
1796 gboolean found = FALSE;
1802 if (!array || array->len == 0)
1806 max = array->len - 1;
1812 mid = (min + max) / 2;
1813 region = &g_array_index (array, GtkRegion, mid);
1815 if (region->class_quark == class_quark)
1820 else if (region->class_quark > class_quark)
1821 min = pos = mid + 1;
1828 while (!found && min <= max);
1837 * gtk_style_context_add_class:
1838 * @context: a #GtkStyleContext
1839 * @class_name: class name to use in styling
1841 * Adds a style class to @context, so posterior calls to
1842 * gtk_style_context_get() or any of the gtk_render_*()
1843 * functions will make use of this new class for styling.
1845 * In the CSS file format, a #GtkEntry defining an "entry"
1846 * class, would be matched by:
1849 * GtkEntry.entry { ... }
1852 * While any widget defining an "entry" class would be
1861 gtk_style_context_add_class (GtkStyleContext *context,
1862 const gchar *class_name)
1864 GtkStyleContextPrivate *priv;
1869 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1870 g_return_if_fail (class_name != NULL);
1872 priv = context->priv;
1873 class_quark = g_quark_from_string (class_name);
1875 g_assert (priv->info_stack != NULL);
1876 info = priv->info_stack->data;
1878 if (!style_class_find (info->style_classes, class_quark, &position))
1880 g_array_insert_val (info->style_classes, position, class_quark);
1882 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_CLASS);
1887 * gtk_style_context_remove_class:
1888 * @context: a #GtkStyleContext
1889 * @class_name: class name to remove
1891 * Removes @class_name from @context.
1896 gtk_style_context_remove_class (GtkStyleContext *context,
1897 const gchar *class_name)
1899 GtkStyleContextPrivate *priv;
1904 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1905 g_return_if_fail (class_name != NULL);
1907 class_quark = g_quark_try_string (class_name);
1912 priv = context->priv;
1914 g_assert (priv->info_stack != NULL);
1915 info = priv->info_stack->data;
1917 if (style_class_find (info->style_classes, class_quark, &position))
1919 g_array_remove_index (info->style_classes, position);
1921 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_CLASS);
1926 * gtk_style_context_has_class:
1927 * @context: a #GtkStyleContext
1928 * @class_name: a class name
1930 * Returns %TRUE if @context currently has defined the
1933 * Returns: %TRUE if @context has @class_name defined
1938 gtk_style_context_has_class (GtkStyleContext *context,
1939 const gchar *class_name)
1941 GtkStyleContextPrivate *priv;
1945 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1946 g_return_val_if_fail (class_name != NULL, FALSE);
1948 class_quark = g_quark_try_string (class_name);
1953 priv = context->priv;
1955 g_assert (priv->info_stack != NULL);
1956 info = priv->info_stack->data;
1958 if (style_class_find (info->style_classes, class_quark, NULL))
1965 * gtk_style_context_list_classes:
1966 * @context: a #GtkStyleContext
1968 * Returns the list of classes currently defined in @context.
1970 * Returns: (transfer container) (element-type utf8): a #GList of
1971 * strings with the currently defined classes. The contents
1972 * of the list are owned by GTK+, but you must free the list
1973 * itself with g_list_free() when you are done with it.
1978 gtk_style_context_list_classes (GtkStyleContext *context)
1980 GtkStyleContextPrivate *priv;
1982 GList *classes = NULL;
1985 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1987 priv = context->priv;
1989 g_assert (priv->info_stack != NULL);
1990 info = priv->info_stack->data;
1992 for (i = 0; i < info->style_classes->len; i++)
1996 quark = g_array_index (info->style_classes, GQuark, i);
1997 classes = g_list_prepend (classes, (gchar *) g_quark_to_string (quark));
2004 * gtk_style_context_list_regions:
2005 * @context: a #GtkStyleContext
2007 * Returns the list of regions currently defined in @context.
2009 * Returns: (transfer container) (element-type utf8): a #GList of
2010 * strings with the currently defined regions. The contents
2011 * of the list are owned by GTK+, but you must free the list
2012 * itself with g_list_free() when you are done with it.
2017 gtk_style_context_list_regions (GtkStyleContext *context)
2019 GtkStyleContextPrivate *priv;
2021 GList *classes = NULL;
2024 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2026 priv = context->priv;
2028 g_assert (priv->info_stack != NULL);
2029 info = priv->info_stack->data;
2031 for (i = 0; i < info->regions->len; i++)
2034 const gchar *class_name;
2036 region = &g_array_index (info->regions, GtkRegion, i);
2038 class_name = g_quark_to_string (region->class_quark);
2039 classes = g_list_prepend (classes, (gchar *) class_name);
2046 _gtk_style_context_check_region_name (const gchar *str)
2048 g_return_val_if_fail (str != NULL, FALSE);
2050 if (!g_ascii_islower (str[0]))
2056 !g_ascii_islower (*str))
2066 * gtk_style_context_add_region:
2067 * @context: a #GtkStyleContext
2068 * @region_name: region name to use in styling
2069 * @flags: flags that apply to the region
2071 * Adds a region to @context, so posterior calls to
2072 * gtk_style_context_get() or any of the gtk_render_*()
2073 * functions will make use of this new region for styling.
2075 * In the CSS file format, a #GtkTreeView defining a "row"
2076 * region, would be matched by:
2079 * GtkTreeView row { ... }
2082 * Pseudo-classes are used for matching @flags, so the two
2085 * GtkTreeView row:nth-child(even) { ... }
2086 * GtkTreeView row:nth-child(odd) { ... }
2089 * would apply to even and odd rows, respectively.
2091 * <note><para>Region names must only contain lowercase letters
2092 * and '-', starting always with a lowercase letter.</para></note>
2097 gtk_style_context_add_region (GtkStyleContext *context,
2098 const gchar *region_name,
2099 GtkRegionFlags flags)
2101 GtkStyleContextPrivate *priv;
2103 GQuark region_quark;
2106 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2107 g_return_if_fail (region_name != NULL);
2108 g_return_if_fail (_gtk_style_context_check_region_name (region_name));
2110 priv = context->priv;
2111 region_quark = g_quark_from_string (region_name);
2113 g_assert (priv->info_stack != NULL);
2114 info = priv->info_stack->data;
2116 if (!region_find (info->regions, region_quark, &position))
2120 region.class_quark = region_quark;
2121 region.flags = flags;
2123 g_array_insert_val (info->regions, position, region);
2125 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_REGION);
2130 * gtk_style_context_remove_region:
2131 * @context: a #GtkStyleContext
2132 * @region_name: region name to unset
2134 * Removes a region from @context.
2139 gtk_style_context_remove_region (GtkStyleContext *context,
2140 const gchar *region_name)
2142 GtkStyleContextPrivate *priv;
2144 GQuark region_quark;
2147 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2148 g_return_if_fail (region_name != NULL);
2150 region_quark = g_quark_try_string (region_name);
2155 priv = context->priv;
2157 g_assert (priv->info_stack != NULL);
2158 info = priv->info_stack->data;
2160 if (region_find (info->regions, region_quark, &position))
2162 g_array_remove_index (info->regions, position);
2164 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_REGION);
2169 * gtk_style_context_has_region:
2170 * @context: a #GtkStyleContext
2171 * @region_name: a region name
2172 * @flags_return: (out) (allow-none): return location for region flags
2174 * Returns %TRUE if @context has the region defined.
2175 * If @flags_return is not %NULL, it is set to the flags
2176 * affecting the region.
2178 * Returns: %TRUE if region is defined
2183 gtk_style_context_has_region (GtkStyleContext *context,
2184 const gchar *region_name,
2185 GtkRegionFlags *flags_return)
2187 GtkStyleContextPrivate *priv;
2189 GQuark region_quark;
2192 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2193 g_return_val_if_fail (region_name != NULL, FALSE);
2198 region_quark = g_quark_try_string (region_name);
2203 priv = context->priv;
2205 g_assert (priv->info_stack != NULL);
2206 info = priv->info_stack->data;
2208 if (region_find (info->regions, region_quark, &position))
2214 region = &g_array_index (info->regions, GtkRegion, position);
2215 *flags_return = region->flags;
2224 style_property_values_cmp (gconstpointer bsearch_node1,
2225 gconstpointer bsearch_node2)
2227 const PropertyValue *val1 = bsearch_node1;
2228 const PropertyValue *val2 = bsearch_node2;
2230 if (val1->widget_type != val2->widget_type)
2231 return val1->widget_type < val2->widget_type ? -1 : 1;
2233 if (val1->pspec != val2->pspec)
2234 return val1->pspec < val2->pspec ? -1 : 1;
2236 if (val1->state != val2->state)
2237 return val1->state < val2->state ? -1 : 1;
2243 _gtk_style_context_peek_property (GtkStyleContext *context,
2244 const char *property_name)
2246 StyleData *data = style_data_lookup (context);
2248 return _gtk_css_computed_values_get_value_by_name (data->store, property_name);
2252 _gtk_style_context_get_number (GtkStyleContext *context,
2253 const char *property_name,
2254 double one_hundred_percent)
2258 value = _gtk_style_context_peek_property (context, property_name);
2259 return _gtk_css_number_value_get (value, one_hundred_percent);
2263 _gtk_style_context_peek_style_property (GtkStyleContext *context,
2265 GtkStateFlags state,
2268 GtkStyleContextPrivate *priv;
2269 PropertyValue *pcache, key = { 0 };
2273 priv = context->priv;
2275 gtk_style_context_save (context);
2276 gtk_style_context_set_state (context, state);
2277 data = style_data_lookup (context);
2278 gtk_style_context_restore (context);
2280 key.widget_type = widget_type;
2284 /* need value cache array */
2285 if (!data->property_cache)
2286 data->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
2289 pcache = bsearch (&key,
2290 data->property_cache->data, data->property_cache->len,
2291 sizeof (PropertyValue), style_property_values_cmp);
2293 return &pcache->value;
2297 while (i < data->property_cache->len &&
2298 style_property_values_cmp (&key, &g_array_index (data->property_cache, PropertyValue, i)) >= 0)
2301 g_array_insert_val (data->property_cache, i, key);
2302 pcache = &g_array_index (data->property_cache, PropertyValue, i);
2304 /* cache miss, initialize value type, then set contents */
2305 g_param_spec_ref (pcache->pspec);
2306 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2308 if (priv->widget || priv->widget_path)
2310 if (gtk_style_provider_get_style_property (GTK_STYLE_PROVIDER (priv->cascade),
2311 priv->widget ? gtk_widget_get_path (priv->widget)
2312 : priv->widget_path,
2313 state, pspec, &pcache->value))
2315 /* Resolve symbolic colors to GdkColor/GdkRGBA */
2316 if (G_VALUE_TYPE (&pcache->value) == GTK_TYPE_SYMBOLIC_COLOR)
2318 GtkSymbolicColor *color;
2321 color = g_value_dup_boxed (&pcache->value);
2323 g_value_unset (&pcache->value);
2325 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2326 g_value_init (&pcache->value, GDK_TYPE_RGBA);
2328 g_value_init (&pcache->value, GDK_TYPE_COLOR);
2330 if (_gtk_style_context_resolve_color (context, color, &rgba))
2332 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2333 g_value_set_boxed (&pcache->value, &rgba);
2338 rgb.red = rgba.red * 65535. + 0.5;
2339 rgb.green = rgba.green * 65535. + 0.5;
2340 rgb.blue = rgba.blue * 65535. + 0.5;
2342 g_value_set_boxed (&pcache->value, &rgb);
2346 g_param_value_set_default (pspec, &pcache->value);
2348 gtk_symbolic_color_unref (color);
2351 return &pcache->value;
2355 /* not supplied by any provider, revert to default */
2356 g_param_value_set_default (pspec, &pcache->value);
2358 return &pcache->value;
2362 * gtk_style_context_get_style_property:
2363 * @context: a #GtkStyleContext
2364 * @property_name: the name of the widget style property
2365 * @value: Return location for the property value
2367 * Gets the value for a widget style property.
2369 * When @value is no longer needed, g_value_unset() must be called
2370 * to free any allocated memory.
2373 gtk_style_context_get_style_property (GtkStyleContext *context,
2374 const gchar *property_name,
2377 GtkStyleContextPrivate *priv;
2378 GtkWidgetClass *widget_class;
2379 GtkStateFlags state;
2381 const GValue *peek_value;
2384 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2385 g_return_if_fail (property_name != NULL);
2386 g_return_if_fail (value != NULL);
2388 priv = context->priv;
2392 widget_type = G_OBJECT_TYPE (priv->widget);
2396 if (!priv->widget_path)
2399 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2401 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2403 g_warning ("%s: can't get style properties for non-widget class `%s'",
2405 g_type_name (widget_type));
2410 widget_class = g_type_class_ref (widget_type);
2411 pspec = gtk_widget_class_find_style_property (widget_class, property_name);
2412 g_type_class_unref (widget_class);
2416 g_warning ("%s: widget class `%s' has no style property named `%s'",
2418 g_type_name (widget_type),
2423 state = gtk_style_context_get_state (context);
2424 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2427 if (G_VALUE_TYPE (value) == G_VALUE_TYPE (peek_value))
2428 g_value_copy (peek_value, value);
2429 else if (g_value_type_transformable (G_VALUE_TYPE (peek_value), G_VALUE_TYPE (value)))
2430 g_value_transform (peek_value, value);
2432 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
2434 G_VALUE_TYPE_NAME (peek_value),
2435 G_VALUE_TYPE_NAME (value));
2439 * gtk_style_context_get_style_valist:
2440 * @context: a #GtkStyleContext
2441 * @args: va_list of property name/return location pairs, followed by %NULL
2443 * Retrieves several widget style properties from @context according to the
2449 gtk_style_context_get_style_valist (GtkStyleContext *context,
2452 GtkStyleContextPrivate *priv;
2453 const gchar *prop_name;
2454 GtkStateFlags state;
2457 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2459 prop_name = va_arg (args, const gchar *);
2460 priv = context->priv;
2464 widget_type = G_OBJECT_TYPE (priv->widget);
2468 if (!priv->widget_path)
2471 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2473 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2475 g_warning ("%s: can't get style properties for non-widget class `%s'",
2477 g_type_name (widget_type));
2482 state = gtk_style_context_get_state (context);
2486 GtkWidgetClass *widget_class;
2488 const GValue *peek_value;
2491 widget_class = g_type_class_ref (widget_type);
2492 pspec = gtk_widget_class_find_style_property (widget_class, prop_name);
2493 g_type_class_unref (widget_class);
2497 g_warning ("%s: widget class `%s' has no style property named `%s'",
2499 g_type_name (widget_type),
2504 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2507 G_VALUE_LCOPY (peek_value, args, 0, &error);
2511 g_warning ("can't retrieve style property `%s' of type `%s': %s",
2513 G_VALUE_TYPE_NAME (peek_value),
2519 prop_name = va_arg (args, const gchar *);
2524 * gtk_style_context_get_style:
2525 * @context: a #GtkStyleContext
2526 * @...: property name /return value pairs, followed by %NULL
2528 * Retrieves several widget style properties from @context according to the
2534 gtk_style_context_get_style (GtkStyleContext *context,
2539 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2541 va_start (args, context);
2542 gtk_style_context_get_style_valist (context, args);
2548 * gtk_style_context_lookup_icon_set:
2549 * @context: a #GtkStyleContext
2550 * @stock_id: an icon name
2552 * Looks up @stock_id in the icon factories associated to @context and
2553 * the default icon factory, returning an icon set if found, otherwise
2556 * Returns: (transfer none): The looked up %GtkIconSet, or %NULL
2559 gtk_style_context_lookup_icon_set (GtkStyleContext *context,
2560 const gchar *stock_id)
2562 GtkStyleContextPrivate *priv;
2564 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2565 g_return_val_if_fail (stock_id != NULL, NULL);
2567 priv = context->priv;
2568 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
2570 return gtk_icon_factory_lookup_default (stock_id);
2574 * gtk_style_context_set_screen:
2575 * @context: a #GtkStyleContext
2576 * @screen: a #GdkScreen
2578 * Attaches @context to the given screen.
2580 * The screen is used to add style information from 'global' style
2581 * providers, such as the screens #GtkSettings instance.
2583 * If you are using a #GtkStyleContext returned from
2584 * gtk_widget_get_style_context(), you do not need to
2585 * call this yourself.
2590 gtk_style_context_set_screen (GtkStyleContext *context,
2593 GtkStyleContextPrivate *priv;
2595 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2596 g_return_if_fail (GDK_IS_SCREEN (screen));
2598 priv = context->priv;
2599 if (priv->screen == screen)
2602 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
2604 g_object_unref (priv->cascade);
2605 priv->cascade = _gtk_style_cascade_get_for_screen (screen);
2606 g_object_ref (priv->cascade);
2610 _gtk_style_cascade_set_parent (priv->cascade, _gtk_style_cascade_get_for_screen (screen));
2613 priv->screen = screen;
2615 g_object_notify (G_OBJECT (context), "screen");
2617 gtk_style_context_invalidate (context);
2621 * gtk_style_context_get_screen:
2622 * @context: a #GtkStyleContext
2624 * Returns the #GdkScreen to which @context is attached.
2626 * Returns: (transfer none): a #GdkScreen.
2629 gtk_style_context_get_screen (GtkStyleContext *context)
2631 GtkStyleContextPrivate *priv;
2633 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2635 priv = context->priv;
2636 return priv->screen;
2640 * gtk_style_context_set_direction:
2641 * @context: a #GtkStyleContext
2642 * @direction: the new direction.
2644 * Sets the reading direction for rendering purposes.
2646 * If you are using a #GtkStyleContext returned from
2647 * gtk_widget_get_style_context(), you do not need to
2648 * call this yourself.
2653 gtk_style_context_set_direction (GtkStyleContext *context,
2654 GtkTextDirection direction)
2656 GtkStyleContextPrivate *priv;
2658 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2660 priv = context->priv;
2661 priv->direction = direction;
2663 g_object_notify (G_OBJECT (context), "direction");
2667 * gtk_style_context_get_direction:
2668 * @context: a #GtkStyleContext
2670 * Returns the widget direction used for rendering.
2672 * Returns: the widget direction
2677 gtk_style_context_get_direction (GtkStyleContext *context)
2679 GtkStyleContextPrivate *priv;
2681 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), GTK_TEXT_DIR_LTR);
2683 priv = context->priv;
2684 return priv->direction;
2688 * gtk_style_context_set_junction_sides:
2689 * @context: a #GtkStyleContext
2690 * @sides: sides where rendered elements are visually connected to
2693 * Sets the sides where rendered elements (mostly through
2694 * gtk_render_frame()) will visually connect with other visual elements.
2696 * This is merely a hint that may or may not be honored
2697 * by theming engines.
2699 * Container widgets are expected to set junction hints as appropriate
2700 * for their children, so it should not normally be necessary to call
2701 * this function manually.
2706 gtk_style_context_set_junction_sides (GtkStyleContext *context,
2707 GtkJunctionSides sides)
2709 GtkStyleContextPrivate *priv;
2712 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2714 priv = context->priv;
2715 info = priv->info_stack->data;
2716 info->junction_sides = sides;
2720 * gtk_style_context_get_junction_sides:
2721 * @context: a #GtkStyleContext
2723 * Returns the sides where rendered elements connect visually with others.
2725 * Returns: the junction sides
2730 gtk_style_context_get_junction_sides (GtkStyleContext *context)
2732 GtkStyleContextPrivate *priv;
2735 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
2737 priv = context->priv;
2738 info = priv->info_stack->data;
2739 return info->junction_sides;
2742 static GtkSymbolicColor *
2743 gtk_style_context_color_lookup_func (gpointer contextp,
2746 GtkStyleContext *context = contextp;
2748 return _gtk_style_provider_private_get_color (GTK_STYLE_PROVIDER_PRIVATE (context->priv->cascade), name);
2752 _gtk_style_context_resolve_color_value (GtkStyleContext *context,
2753 GtkSymbolicColor *color)
2755 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2756 g_return_val_if_fail (color != NULL, FALSE);
2758 return _gtk_symbolic_color_resolve_full (color,
2759 gtk_style_context_color_lookup_func,
2765 _gtk_style_context_resolve_color (GtkStyleContext *context,
2766 GtkSymbolicColor *color,
2771 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2772 g_return_val_if_fail (color != NULL, FALSE);
2773 g_return_val_if_fail (result != NULL, FALSE);
2775 val = _gtk_symbolic_color_resolve_full (color,
2776 gtk_style_context_color_lookup_func,
2781 *result = *_gtk_css_rgba_value_get_rgba (val);
2782 _gtk_css_value_unref (val);
2787 * gtk_style_context_lookup_color:
2788 * @context: a #GtkStyleContext
2789 * @color_name: color name to lookup
2790 * @color: (out): Return location for the looked up color
2792 * Looks up and resolves a color name in the @context color map.
2794 * Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
2797 gtk_style_context_lookup_color (GtkStyleContext *context,
2798 const gchar *color_name,
2801 GtkSymbolicColor *sym_color;
2803 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2804 g_return_val_if_fail (color_name != NULL, FALSE);
2805 g_return_val_if_fail (color != NULL, FALSE);
2807 sym_color = gtk_style_context_color_lookup_func (context, color_name);
2808 if (sym_color == NULL)
2811 return _gtk_style_context_resolve_color (context, sym_color, color);
2815 * gtk_style_context_notify_state_change:
2816 * @context: a #GtkStyleContext
2817 * @window: a #GdkWindow
2818 * @region_id: (allow-none): animatable region to notify on, or %NULL.
2819 * See gtk_style_context_push_animatable_region()
2820 * @state: state to trigger transition for
2821 * @state_value: %TRUE if @state is the state we are changing to,
2822 * %FALSE if we are changing away from it
2824 * Notifies a state change on @context, so if the current style makes use
2825 * of transition animations, one will be started so all rendered elements
2826 * under @region_id are animated for state @state being set to value
2829 * The @window parameter is used in order to invalidate the rendered area
2830 * as the animation runs, so make sure it is the same window that is being
2831 * rendered on by the gtk_render_*() functions.
2833 * If @region_id is %NULL, all rendered elements using @context will be
2834 * affected by this state transition.
2836 * As a practical example, a #GtkButton notifying a state transition on
2837 * the prelight state:
2839 * gtk_style_context_notify_state_change (context,
2840 * gtk_widget_get_window (widget),
2842 * GTK_STATE_PRELIGHT,
2843 * button->in_button);
2846 * Can be handled in the CSS file like this:
2849 * background-color: #f00
2853 * background-color: #fff;
2854 * transition: 200ms linear
2858 * This combination will animate the button background from red to white
2859 * if a pointer enters the button, and back to red if the pointer leaves
2862 * Note that @state is used when finding the transition parameters, which
2863 * is why the style places the transition under the :hover pseudo-class.
2868 gtk_style_context_notify_state_change (GtkStyleContext *context,
2872 gboolean state_value)
2874 GtkStyleContextPrivate *priv;
2875 GtkAnimationDescription *desc;
2876 AnimationInfo *info;
2877 GtkStateFlags flags;
2881 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2882 g_return_if_fail (GDK_IS_WINDOW (window));
2883 g_return_if_fail (state > GTK_STATE_NORMAL && state <= GTK_STATE_FOCUSED);
2885 priv = context->priv;
2886 g_return_if_fail (priv->widget != NULL || priv->widget_path != NULL);
2888 state_value = (state_value == TRUE);
2892 case GTK_STATE_ACTIVE:
2893 flags = GTK_STATE_FLAG_ACTIVE;
2895 case GTK_STATE_PRELIGHT:
2896 flags = GTK_STATE_FLAG_PRELIGHT;
2898 case GTK_STATE_SELECTED:
2899 flags = GTK_STATE_FLAG_SELECTED;
2901 case GTK_STATE_INSENSITIVE:
2902 flags = GTK_STATE_FLAG_INSENSITIVE;
2904 case GTK_STATE_INCONSISTENT:
2905 flags = GTK_STATE_FLAG_INCONSISTENT;
2907 case GTK_STATE_FOCUSED:
2908 flags = GTK_STATE_FLAG_FOCUSED;
2910 case GTK_STATE_NORMAL:
2916 /* Find out if there is any animation description for the given
2917 * state, it will fallback to the normal state as well if necessary.
2919 gtk_style_context_save (context);
2920 gtk_style_context_set_state (context, flags);
2921 data = style_data_lookup (context);
2922 gtk_style_context_restore (context);
2923 v = _gtk_css_computed_values_get_value_by_name (data->store, "transition");
2926 desc = _gtk_css_value_get_boxed (v);
2930 if (_gtk_animation_description_get_duration (desc) == 0)
2933 info = animation_info_lookup (context, region_id, state);
2936 info->target_value != state_value)
2938 /* Target values are the opposite */
2939 if (!_gtk_timeline_get_loop (info->timeline))
2941 /* Reverse the animation */
2942 if (_gtk_timeline_get_direction (info->timeline) == GTK_TIMELINE_DIRECTION_FORWARD)
2943 _gtk_timeline_set_direction (info->timeline, GTK_TIMELINE_DIRECTION_BACKWARD);
2945 _gtk_timeline_set_direction (info->timeline, GTK_TIMELINE_DIRECTION_FORWARD);
2947 info->target_value = state_value;
2951 /* Take it out of its looping state */
2952 _gtk_timeline_set_loop (info->timeline, FALSE);
2956 (!_gtk_animation_description_get_loop (desc) ||
2959 info = animation_info_new (context, region_id,
2960 _gtk_animation_description_get_duration (desc),
2961 _gtk_animation_description_get_progress_type (desc),
2962 _gtk_animation_description_get_loop (desc),
2963 state, state_value, window);
2965 priv->animations = g_slist_prepend (priv->animations, info);
2966 priv->animations_invalidated = TRUE;
2971 * gtk_style_context_cancel_animations:
2972 * @context: a #GtkStyleContext
2973 * @region_id: (allow-none): animatable region to stop, or %NULL.
2974 * See gtk_style_context_push_animatable_region()
2976 * Stops all running animations for @region_id and all animatable
2977 * regions underneath.
2979 * A %NULL @region_id will stop all ongoing animations in @context,
2980 * when dealing with a #GtkStyleContext obtained through
2981 * gtk_widget_get_style_context(), this is normally done for you
2982 * in all circumstances you would expect all widget to be stopped,
2983 * so this should be only used in complex widgets with different
2984 * animatable regions.
2989 gtk_style_context_cancel_animations (GtkStyleContext *context,
2992 GtkStyleContextPrivate *priv;
2993 AnimationInfo *info;
2996 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2998 priv = context->priv;
2999 l = priv->animations;
3007 info->region_id == region_id ||
3008 g_slist_find (info->parent_regions, region_id))
3010 priv->animations = g_slist_remove (priv->animations, info);
3011 animation_info_free (info);
3017 is_parent_of (GdkWindow *parent,
3020 GtkWidget *child_widget, *parent_widget;
3023 gdk_window_get_user_data (child, (gpointer *) &child_widget);
3024 gdk_window_get_user_data (parent, (gpointer *) &parent_widget);
3026 if (child_widget != parent_widget &&
3027 !gtk_widget_is_ancestor (child_widget, parent_widget))
3034 if (window == parent)
3037 window = gdk_window_get_parent (window);
3044 * gtk_style_context_scroll_animations:
3045 * @context: a #GtkStyleContext
3046 * @window: a #GdkWindow used previously in
3047 * gtk_style_context_notify_state_change()
3048 * @dx: Amount to scroll in the X axis
3049 * @dy: Amount to scroll in the Y axis
3051 * This function is analogous to gdk_window_scroll(), and
3052 * should be called together with it so the invalidation
3053 * areas for any ongoing animation are scrolled together
3059 gtk_style_context_scroll_animations (GtkStyleContext *context,
3064 GtkStyleContextPrivate *priv;
3065 AnimationInfo *info;
3068 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3069 g_return_if_fail (GDK_IS_WINDOW (window));
3071 priv = context->priv;
3072 l = priv->animations;
3079 if (info->invalidation_region &&
3080 (window == info->window ||
3081 is_parent_of (window, info->window)))
3082 cairo_region_translate (info->invalidation_region, dx, dy);
3087 * gtk_style_context_push_animatable_region:
3088 * @context: a #GtkStyleContext
3089 * @region_id: unique identifier for the animatable region
3091 * Pushes an animatable region, so all further gtk_render_*() calls between
3092 * this call and the following gtk_style_context_pop_animatable_region()
3093 * will potentially show transition animations for this region if
3094 * gtk_style_context_notify_state_change() is called for a given state,
3095 * and the current theme/style defines transition animations for state
3098 * The @region_id used must be unique in @context so the theming engine
3099 * can uniquely identify rendered elements subject to a state transition.
3104 gtk_style_context_push_animatable_region (GtkStyleContext *context,
3107 GtkStyleContextPrivate *priv;
3109 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3110 g_return_if_fail (region_id != NULL);
3112 priv = context->priv;
3113 priv->animation_regions = g_slist_prepend (priv->animation_regions, region_id);
3117 * gtk_style_context_pop_animatable_region:
3118 * @context: a #GtkStyleContext
3120 * Pops an animatable region from @context.
3121 * See gtk_style_context_push_animatable_region().
3126 gtk_style_context_pop_animatable_region (GtkStyleContext *context)
3128 GtkStyleContextPrivate *priv;
3130 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3132 priv = context->priv;
3133 priv->animation_regions = g_slist_delete_link (priv->animation_regions,
3134 priv->animation_regions);
3138 _gtk_style_context_invalidate_animation_areas (GtkStyleContext *context)
3140 GtkStyleContextPrivate *priv;
3143 priv = context->priv;
3145 for (l = priv->animations; l; l = l->next)
3147 AnimationInfo *info;
3151 /* A NULL invalidation region means it has to be recreated on
3152 * the next expose event, this happens usually after a widget
3153 * allocation change, so the next expose after it will update
3154 * the invalidation region.
3156 if (info->invalidation_region)
3158 cairo_region_destroy (info->invalidation_region);
3159 info->invalidation_region = NULL;
3163 priv->animations_invalidated = TRUE;
3167 _gtk_style_context_coalesce_animation_areas (GtkStyleContext *context,
3170 GtkStyleContextPrivate *priv;
3173 priv = context->priv;
3175 if (!priv->animations_invalidated)
3178 l = priv->animations;
3182 AnimationInfo *info;
3191 if (info->invalidation_region)
3194 if (info->rectangles->len == 0)
3197 info->invalidation_region = cairo_region_create ();
3198 _gtk_widget_get_translation_to_window (widget, info->window, &rel_x, &rel_y);
3200 for (i = 0; i < info->rectangles->len; i++)
3202 cairo_rectangle_int_t *rect;
3204 rect = &g_array_index (info->rectangles, cairo_rectangle_int_t, i);
3206 /* These are widget relative coordinates,
3207 * so have them inverted to be window relative
3212 cairo_region_union_rectangle (info->invalidation_region, rect);
3215 g_array_remove_range (info->rectangles, 0, info->rectangles->len);
3218 priv->animations_invalidated = FALSE;
3222 store_animation_region (GtkStyleContext *context,
3228 GtkStyleContextPrivate *priv;
3231 priv = context->priv;
3233 if (!priv->animations_invalidated)
3236 for (l = priv->animations; l; l = l->next)
3238 AnimationInfo *info;
3242 /* The animation doesn't need updating
3243 * the invalidation area, bail out.
3245 if (info->invalidation_region)
3248 if (context_has_animatable_region (context, info->region_id))
3250 cairo_rectangle_int_t rect;
3254 rect.width = (gint) width;
3255 rect.height = (gint) height;
3257 g_array_append_val (info->rectangles, rect);
3259 if (!info->parent_regions)
3261 GSList *parent_regions;
3263 parent_regions = g_slist_find (priv->animation_regions, info->region_id);
3264 info->parent_regions = g_slist_copy (parent_regions);
3271 gtk_style_context_do_invalidate (GtkStyleContext *context,
3272 gboolean clear_caches)
3274 GtkStyleContextPrivate *priv;
3276 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3278 priv = context->priv;
3280 /* Avoid reentrancy */
3281 if (priv->invalidating_context)
3284 priv->invalidating_context = TRUE;
3290 for (list = priv->info_stack; list; list = list->next)
3292 GtkStyleInfo *info = list->data;
3295 g_hash_table_remove_all (priv->style_data);
3298 g_signal_emit (context, signals[CHANGED], 0);
3300 priv->invalidating_context = FALSE;
3304 _gtk_style_context_validate (GtkStyleContext *context,
3305 GtkCssChange change)
3307 GtkStyleContextPrivate *priv;
3310 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3312 priv = context->priv;
3314 change |= priv->pending_changes;
3316 if (!priv->invalid && change == 0)
3319 priv->pending_changes = 0;
3320 gtk_style_context_set_invalid (context, FALSE);
3322 /* Try to avoid invalidating if we can */
3323 if (change & GTK_STYLE_CONTEXT_RADICAL_CHANGE)
3325 priv->relevant_changes = GTK_CSS_CHANGE_ANY;
3329 if (priv->relevant_changes == GTK_CSS_CHANGE_ANY)
3331 GtkWidgetPath *path;
3332 GtkCssMatcher matcher;
3334 path = create_query_path (context);
3335 _gtk_css_matcher_init (&matcher, path, ((GtkStyleInfo *) priv->info_stack->data)->state_flags);
3337 priv->relevant_changes = _gtk_style_provider_private_get_change (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
3339 priv->relevant_changes &= ~GTK_STYLE_CONTEXT_RADICAL_CHANGE;
3341 gtk_widget_path_unref (path);
3345 if (priv->relevant_changes & change)
3347 GtkStyleInfo *info = priv->info_stack->data;
3348 gboolean clear_cache = ((priv->relevant_changes & change) & ~GTK_STYLE_CONTEXT_CACHED_CHANGE) != 0;
3351 gtk_style_context_do_invalidate (context, clear_cache);
3354 change = _gtk_css_change_for_child (change);
3355 for (list = priv->children; list; list = list->next)
3357 _gtk_style_context_validate (list->data, change);
3362 _gtk_style_context_queue_invalidate (GtkStyleContext *context,
3363 GtkCssChange change)
3365 GtkStyleContextPrivate *priv;
3367 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3368 g_return_if_fail (change != 0);
3370 priv = context->priv;
3372 if (priv->widget == NULL && priv->widget_path == NULL)
3375 priv->pending_changes |= change;
3376 gtk_style_context_set_invalid (context, TRUE);
3380 * gtk_style_context_invalidate:
3381 * @context: a #GtkStyleContext.
3383 * Invalidates @context style information, so it will be reconstructed
3386 * If you're using a #GtkStyleContext returned from
3387 * gtk_widget_get_style_context(), you do not need to
3388 * call this yourself.
3393 gtk_style_context_invalidate (GtkStyleContext *context)
3395 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3397 gtk_style_context_do_invalidate (context, TRUE);
3401 * gtk_style_context_set_background:
3402 * @context: a #GtkStyleContext
3403 * @window: a #GdkWindow
3405 * Sets the background of @window to the background pattern or
3406 * color specified in @context for its current state.
3411 gtk_style_context_set_background (GtkStyleContext *context,
3414 GtkStateFlags state;
3415 cairo_pattern_t *pattern;
3418 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3419 g_return_if_fail (GDK_IS_WINDOW (window));
3421 state = gtk_style_context_get_state (context);
3422 gtk_style_context_get (context, state,
3423 "background-image", &pattern,
3427 gdk_window_set_background_pattern (window, pattern);
3428 cairo_pattern_destroy (pattern);
3432 gtk_style_context_get (context, state,
3433 "background-color", &color,
3437 gdk_window_set_background_rgba (window, color);
3438 gdk_rgba_free (color);
3443 * gtk_style_context_get_color:
3444 * @context: a #GtkStyleContext
3445 * @state: state to retrieve the color for
3446 * @color: (out): return value for the foreground color
3448 * Gets the foreground color for a given state.
3453 gtk_style_context_get_color (GtkStyleContext *context,
3454 GtkStateFlags state,
3459 g_return_if_fail (color != NULL);
3460 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3462 gtk_style_context_get (context,
3472 * gtk_style_context_get_background_color:
3473 * @context: a #GtkStyleContext
3474 * @state: state to retrieve the color for
3475 * @color: (out): return value for the background color
3477 * Gets the background color for a given state.
3482 gtk_style_context_get_background_color (GtkStyleContext *context,
3483 GtkStateFlags state,
3488 g_return_if_fail (color != NULL);
3489 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3491 gtk_style_context_get (context,
3493 "background-color", &c,
3501 * gtk_style_context_get_border_color:
3502 * @context: a #GtkStyleContext
3503 * @state: state to retrieve the color for
3504 * @color: (out): return value for the border color
3506 * Gets the border color for a given state.
3511 gtk_style_context_get_border_color (GtkStyleContext *context,
3512 GtkStateFlags state,
3517 g_return_if_fail (color != NULL);
3518 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3520 gtk_style_context_get (context,
3530 * gtk_style_context_get_border:
3531 * @context: a #GtkStyleContext
3532 * @state: state to retrieve the border for
3533 * @border: (out): return value for the border settings
3535 * Gets the border for a given state as a #GtkBorder.
3536 * See %GTK_STYLE_PROPERTY_BORDER_WIDTH.
3541 gtk_style_context_get_border (GtkStyleContext *context,
3542 GtkStateFlags state,
3545 int top, left, bottom, right;
3547 g_return_if_fail (border != NULL);
3548 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3550 gtk_style_context_get (context,
3552 "border-top-width", &top,
3553 "border-left-width", &left,
3554 "border-bottom-width", &bottom,
3555 "border-right-width", &right,
3559 border->left = left;
3560 border->bottom = bottom;
3561 border->right = right;
3565 * gtk_style_context_get_padding:
3566 * @context: a #GtkStyleContext
3567 * @state: state to retrieve the padding for
3568 * @padding: (out): return value for the padding settings
3570 * Gets the padding for a given state as a #GtkBorder.
3571 * See %GTK_STYLE_PROPERTY_PADDING.
3576 gtk_style_context_get_padding (GtkStyleContext *context,
3577 GtkStateFlags state,
3580 int top, left, bottom, right;
3582 g_return_if_fail (padding != NULL);
3583 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3585 gtk_style_context_get (context,
3587 "padding-top", &top,
3588 "padding-left", &left,
3589 "padding-bottom", &bottom,
3590 "padding-right", &right,
3594 padding->left = left;
3595 padding->bottom = bottom;
3596 padding->right = right;
3600 * gtk_style_context_get_margin:
3601 * @context: a #GtkStyleContext
3602 * @state: state to retrieve the border for
3603 * @margin: (out): return value for the margin settings
3605 * Gets the margin for a given state as a #GtkBorder.
3606 * See %GTK_STYLE_PROPERTY_MARGIN.
3611 gtk_style_context_get_margin (GtkStyleContext *context,
3612 GtkStateFlags state,
3615 int top, left, bottom, right;
3617 g_return_if_fail (margin != NULL);
3618 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3620 gtk_style_context_get (context,
3623 "margin-left", &left,
3624 "margin-bottom", &bottom,
3625 "margin-right", &right,
3629 margin->left = left;
3630 margin->bottom = bottom;
3631 margin->right = right;
3635 * gtk_style_context_get_font:
3636 * @context: a #GtkStyleContext
3637 * @state: state to retrieve the font for
3639 * Returns the font description for a given state. The returned
3640 * object is const and will remain valid until the
3641 * #GtkStyleContext::changed signal happens.
3643 * Returns: (transfer none): the #PangoFontDescription for the given
3644 * state. This object is owned by GTK+ and should not be
3649 const PangoFontDescription *
3650 gtk_style_context_get_font (GtkStyleContext *context,
3651 GtkStateFlags state)
3653 GtkStyleContextPrivate *priv;
3655 PangoFontDescription *description;
3657 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
3659 priv = context->priv;
3660 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
3662 gtk_style_context_save (context);
3663 gtk_style_context_set_state (context, state);
3664 data = style_data_lookup (context);
3665 gtk_style_context_restore (context);
3667 /* Yuck, fonts are created on-demand but we don't return a ref.
3668 * Do bad things to achieve this requirement */
3669 description = g_object_get_data (G_OBJECT (data->store), "font-cache-for-get_font");
3670 if (description == NULL)
3672 gtk_style_context_get (context, state, "font", &description, NULL);
3673 g_object_set_data_full (G_OBJECT (data->store),
3674 "font-cache-for-get_font",
3676 (GDestroyNotify) pango_font_description_free);
3682 get_cursor_color (GtkStyleContext *context,
3686 GdkColor *style_color;
3688 gtk_style_context_get_style (context,
3689 primary ? "cursor-color" : "secondary-cursor-color",
3695 color->red = style_color->red / 65535.0;
3696 color->green = style_color->green / 65535.0;
3697 color->blue = style_color->blue / 65535.0;
3700 gdk_color_free (style_color);
3704 gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, color);
3710 gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &bg);
3712 color->red = (color->red + bg.red) * 0.5;
3713 color->green = (color->green + bg.green) * 0.5;
3714 color->blue = (color->blue + bg.blue) * 0.5;
3720 _gtk_style_context_get_cursor_color (GtkStyleContext *context,
3721 GdkRGBA *primary_color,
3722 GdkRGBA *secondary_color)
3725 get_cursor_color (context, TRUE, primary_color);
3727 if (secondary_color)
3728 get_cursor_color (context, FALSE, secondary_color);
3735 * @context: a #GtkStyleContext
3737 * @x: X origin of the rectangle
3738 * @y: Y origin of the rectangle
3739 * @width: rectangle width
3740 * @height: rectangle height
3742 * Renders a checkmark (as in a #GtkCheckButton).
3744 * The %GTK_STATE_FLAG_ACTIVE state determines whether the check is
3745 * on or off, and %GTK_STATE_FLAG_INCONSISTENT determines whether it
3746 * should be marked as undefined.
3749 * <title>Typical checkmark rendering</title>
3750 * <inlinegraphic fileref="checks.png" format="PNG"/>
3756 gtk_render_check (GtkStyleContext *context,
3763 GtkStyleContextPrivate *priv;
3764 GtkThemingEngineClass *engine_class;
3766 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3767 g_return_if_fail (cr != NULL);
3769 if (width <= 0 || height <= 0)
3772 priv = context->priv;
3773 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3777 store_animation_region (context, x, y, width, height);
3779 _gtk_theming_engine_set_context (priv->theming_engine, context);
3780 engine_class->render_check (priv->theming_engine, cr,
3781 x, y, width, height);
3787 * gtk_render_option:
3788 * @context: a #GtkStyleContext
3790 * @x: X origin of the rectangle
3791 * @y: Y origin of the rectangle
3792 * @width: rectangle width
3793 * @height: rectangle height
3795 * Renders an option mark (as in a #GtkRadioButton), the %GTK_STATE_FLAG_ACTIVE
3796 * state will determine whether the option is on or off, and
3797 * %GTK_STATE_FLAG_INCONSISTENT whether it should be marked as undefined.
3800 * <title>Typical option mark rendering</title>
3801 * <inlinegraphic fileref="options.png" format="PNG"/>
3807 gtk_render_option (GtkStyleContext *context,
3814 GtkStyleContextPrivate *priv;
3815 GtkThemingEngineClass *engine_class;
3817 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3818 g_return_if_fail (cr != NULL);
3820 if (width <= 0 || height <= 0)
3823 priv = context->priv;
3824 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3828 store_animation_region (context, x, y, width, height);
3830 _gtk_theming_engine_set_context (priv->theming_engine, context);
3831 engine_class->render_option (priv->theming_engine, cr,
3832 x, y, width, height);
3839 * @context: a #GtkStyleContext
3841 * @angle: arrow angle from 0 to 2 * %G_PI, being 0 the arrow pointing to the north
3842 * @x: X origin of the render area
3843 * @y: Y origin of the render area
3844 * @size: square side for render area
3846 * Renders an arrow pointing to @angle.
3849 * <title>Typical arrow rendering at 0, 1&solidus;2 π, π and 3&solidus;2 π</title>
3850 * <inlinegraphic fileref="arrows.png" format="PNG"/>
3856 gtk_render_arrow (GtkStyleContext *context,
3863 GtkStyleContextPrivate *priv;
3864 GtkThemingEngineClass *engine_class;
3866 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3867 g_return_if_fail (cr != NULL);
3872 priv = context->priv;
3873 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3877 gtk_style_context_save (context);
3878 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ARROW);
3880 store_animation_region (context, x, y, size, size);
3882 _gtk_theming_engine_set_context (priv->theming_engine, context);
3883 engine_class->render_arrow (priv->theming_engine, cr,
3886 gtk_style_context_restore (context);
3891 * gtk_render_background:
3892 * @context: a #GtkStyleContext
3894 * @x: X origin of the rectangle
3895 * @y: Y origin of the rectangle
3896 * @width: rectangle width
3897 * @height: rectangle height
3899 * Renders the background of an element.
3902 * <title>Typical background rendering, showing the effect of
3903 * <parameter>background-image</parameter>,
3904 * <parameter>border-width</parameter> and
3905 * <parameter>border-radius</parameter></title>
3906 * <inlinegraphic fileref="background.png" format="PNG"/>
3912 gtk_render_background (GtkStyleContext *context,
3919 GtkStyleContextPrivate *priv;
3920 GtkThemingEngineClass *engine_class;
3922 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3923 g_return_if_fail (cr != NULL);
3925 if (width <= 0 || height <= 0)
3928 priv = context->priv;
3929 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3933 store_animation_region (context, x, y, width, height);
3935 _gtk_theming_engine_set_context (priv->theming_engine, context);
3936 engine_class->render_background (priv->theming_engine, cr, x, y, width, height);
3943 * @context: a #GtkStyleContext
3945 * @x: X origin of the rectangle
3946 * @y: Y origin of the rectangle
3947 * @width: rectangle width
3948 * @height: rectangle height
3950 * Renders a frame around the rectangle defined by @x, @y, @width, @height.
3953 * <title>Examples of frame rendering, showing the effect of
3954 * <parameter>border-image</parameter>,
3955 * <parameter>border-color</parameter>,
3956 * <parameter>border-width</parameter>,
3957 * <parameter>border-radius</parameter> and
3959 * <inlinegraphic fileref="frames.png" format="PNG"/>
3965 gtk_render_frame (GtkStyleContext *context,
3972 GtkStyleContextPrivate *priv;
3973 GtkThemingEngineClass *engine_class;
3975 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3976 g_return_if_fail (cr != NULL);
3978 if (width <= 0 || height <= 0)
3981 priv = context->priv;
3982 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3986 store_animation_region (context, x, y, width, height);
3988 _gtk_theming_engine_set_context (priv->theming_engine, context);
3989 engine_class->render_frame (priv->theming_engine, cr, x, y, width, height);
3995 * gtk_render_expander:
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
4003 * Renders an expander (as used in #GtkTreeView and #GtkExpander) in the area
4004 * defined by @x, @y, @width, @height. The state %GTK_STATE_FLAG_ACTIVE
4005 * determines whether the expander is collapsed or expanded.
4008 * <title>Typical expander rendering</title>
4009 * <inlinegraphic fileref="expanders.png" format="PNG"/>
4015 gtk_render_expander (GtkStyleContext *context,
4022 GtkStyleContextPrivate *priv;
4023 GtkThemingEngineClass *engine_class;
4025 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4026 g_return_if_fail (cr != NULL);
4028 if (width <= 0 || height <= 0)
4031 priv = context->priv;
4032 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4036 store_animation_region (context, x, y, width, height);
4038 _gtk_theming_engine_set_context (priv->theming_engine, context);
4039 engine_class->render_expander (priv->theming_engine, cr, x, y, width, height);
4046 * @context: a #GtkStyleContext
4048 * @x: X origin of the rectangle
4049 * @y: Y origin of the rectangle
4050 * @width: rectangle width
4051 * @height: rectangle height
4053 * Renders a focus indicator on the rectangle determined by @x, @y, @width, @height.
4055 * <title>Typical focus rendering</title>
4056 * <inlinegraphic fileref="focus.png" format="PNG"/>
4062 gtk_render_focus (GtkStyleContext *context,
4069 GtkStyleContextPrivate *priv;
4070 GtkThemingEngineClass *engine_class;
4072 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4073 g_return_if_fail (cr != NULL);
4075 if (width <= 0 || height <= 0)
4078 priv = context->priv;
4079 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4083 store_animation_region (context, x, y, width, height);
4085 _gtk_theming_engine_set_context (priv->theming_engine, context);
4086 engine_class->render_focus (priv->theming_engine, cr, x, y, width, height);
4092 * gtk_render_layout:
4093 * @context: a #GtkStyleContext
4097 * @layout: the #PangoLayout to render
4099 * Renders @layout on the coordinates @x, @y
4104 gtk_render_layout (GtkStyleContext *context,
4108 PangoLayout *layout)
4110 GtkStyleContextPrivate *priv;
4111 GtkThemingEngineClass *engine_class;
4112 PangoRectangle extents;
4114 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4115 g_return_if_fail (PANGO_IS_LAYOUT (layout));
4116 g_return_if_fail (cr != NULL);
4118 priv = context->priv;
4119 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4123 pango_layout_get_extents (layout, &extents, NULL);
4125 store_animation_region (context,
4131 _gtk_theming_engine_set_context (priv->theming_engine, context);
4132 engine_class->render_layout (priv->theming_engine, cr, x, y, layout);
4139 * @context: a #GtkStyleContext
4141 * @x0: X coordinate for the origin of the line
4142 * @y0: Y coordinate for the origin of the line
4143 * @x1: X coordinate for the end of the line
4144 * @y1: Y coordinate for the end of the line
4146 * Renders a line from (x0, y0) to (x1, y1).
4151 gtk_render_line (GtkStyleContext *context,
4158 GtkStyleContextPrivate *priv;
4159 GtkThemingEngineClass *engine_class;
4161 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4162 g_return_if_fail (cr != NULL);
4164 priv = context->priv;
4165 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4169 _gtk_theming_engine_set_context (priv->theming_engine, context);
4170 engine_class->render_line (priv->theming_engine, cr, x0, y0, x1, y1);
4176 * gtk_render_slider:
4177 * @context: a #GtkStyleContext
4179 * @x: X origin of the rectangle
4180 * @y: Y origin of the rectangle
4181 * @width: rectangle width
4182 * @height: rectangle height
4183 * @orientation: orientation of the slider
4185 * Renders a slider (as in #GtkScale) in the rectangle defined by @x, @y,
4186 * @width, @height. @orientation defines whether the slider is vertical
4190 * <title>Typical slider rendering</title>
4191 * <inlinegraphic fileref="sliders.png" format="PNG"/>
4197 gtk_render_slider (GtkStyleContext *context,
4203 GtkOrientation orientation)
4205 GtkStyleContextPrivate *priv;
4206 GtkThemingEngineClass *engine_class;
4208 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4209 g_return_if_fail (cr != NULL);
4211 if (width <= 0 || height <= 0)
4214 priv = context->priv;
4215 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4219 store_animation_region (context, x, y, width, height);
4221 _gtk_theming_engine_set_context (priv->theming_engine, context);
4222 engine_class->render_slider (priv->theming_engine, cr, x, y, width, height, orientation);
4228 * gtk_render_frame_gap:
4229 * @context: a #GtkStyleContext
4231 * @x: X origin of the rectangle
4232 * @y: Y origin of the rectangle
4233 * @width: rectangle width
4234 * @height: rectangle height
4235 * @gap_side: side where the gap is
4236 * @xy0_gap: initial coordinate (X or Y depending on @gap_side) for the gap
4237 * @xy1_gap: end coordinate (X or Y depending on @gap_side) for the gap
4239 * Renders a frame around the rectangle defined by (@x, @y, @width, @height),
4240 * leaving a gap on one side. @xy0_gap and @xy1_gap will mean X coordinates
4241 * for %GTK_POS_TOP and %GTK_POS_BOTTOM gap sides, and Y coordinates for
4242 * %GTK_POS_LEFT and %GTK_POS_RIGHT.
4245 * <title>Typical rendering of a frame with a gap</title>
4246 * <inlinegraphic fileref="frame-gap.png" format="PNG"/>
4252 gtk_render_frame_gap (GtkStyleContext *context,
4258 GtkPositionType gap_side,
4262 GtkStyleContextPrivate *priv;
4263 GtkThemingEngineClass *engine_class;
4265 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4266 g_return_if_fail (cr != NULL);
4267 g_return_if_fail (xy0_gap <= xy1_gap);
4268 g_return_if_fail (xy0_gap >= 0);
4270 if (width <= 0 || height <= 0)
4273 if (gap_side == GTK_POS_LEFT ||
4274 gap_side == GTK_POS_RIGHT)
4275 g_return_if_fail (xy1_gap <= height);
4277 g_return_if_fail (xy1_gap <= width);
4279 priv = context->priv;
4280 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4284 store_animation_region (context, x, y, width, height);
4286 _gtk_theming_engine_set_context (priv->theming_engine, context);
4287 engine_class->render_frame_gap (priv->theming_engine, cr,
4288 x, y, width, height, gap_side,
4295 * gtk_render_extension:
4296 * @context: a #GtkStyleContext
4298 * @x: X origin of the rectangle
4299 * @y: Y origin of the rectangle
4300 * @width: rectangle width
4301 * @height: rectangle height
4302 * @gap_side: side where the gap is
4304 * Renders a extension (as in a #GtkNotebook tab) in the rectangle
4305 * defined by @x, @y, @width, @height. The side where the extension
4306 * connects to is defined by @gap_side.
4309 * <title>Typical extension rendering</title>
4310 * <inlinegraphic fileref="extensions.png" format="PNG"/>
4316 gtk_render_extension (GtkStyleContext *context,
4322 GtkPositionType gap_side)
4324 GtkStyleContextPrivate *priv;
4325 GtkThemingEngineClass *engine_class;
4327 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4328 g_return_if_fail (cr != NULL);
4330 if (width <= 0 || height <= 0)
4333 priv = context->priv;
4334 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4338 store_animation_region (context, x, y, width, height);
4340 _gtk_theming_engine_set_context (priv->theming_engine, context);
4341 engine_class->render_extension (priv->theming_engine, cr, x, y, width, height, gap_side);
4347 * gtk_render_handle:
4348 * @context: a #GtkStyleContext
4350 * @x: X origin of the rectangle
4351 * @y: Y origin of the rectangle
4352 * @width: rectangle width
4353 * @height: rectangle height
4355 * Renders a handle (as in #GtkHandleBox, #GtkPaned and
4356 * #GtkWindow<!-- -->'s resize grip), in the rectangle
4357 * determined by @x, @y, @width, @height.
4360 * <title>Handles rendered for the paned and grip classes</title>
4361 * <inlinegraphic fileref="handles.png" format="PNG"/>
4367 gtk_render_handle (GtkStyleContext *context,
4374 GtkStyleContextPrivate *priv;
4375 GtkThemingEngineClass *engine_class;
4377 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4378 g_return_if_fail (cr != NULL);
4380 if (width <= 0 || height <= 0)
4383 priv = context->priv;
4384 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4388 store_animation_region (context, x, y, width, height);
4390 _gtk_theming_engine_set_context (priv->theming_engine, context);
4391 engine_class->render_handle (priv->theming_engine, cr, x, y, width, height);
4397 * gtk_render_activity:
4398 * @context: a #GtkStyleContext
4400 * @x: X origin of the rectangle
4401 * @y: Y origin of the rectangle
4402 * @width: rectangle width
4403 * @height: rectangle height
4405 * Renders an activity area (Such as in #GtkSpinner or the
4406 * fill line in #GtkRange), the state %GTK_STATE_FLAG_ACTIVE
4407 * determines whether there is activity going on.
4412 gtk_render_activity (GtkStyleContext *context,
4419 GtkStyleContextPrivate *priv;
4420 GtkThemingEngineClass *engine_class;
4422 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4423 g_return_if_fail (cr != NULL);
4425 if (width <= 0 || height <= 0)
4428 priv = context->priv;
4429 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4433 store_animation_region (context, x, y, width, height);
4435 _gtk_theming_engine_set_context (priv->theming_engine, context);
4436 engine_class->render_activity (priv->theming_engine, cr, x, y, width, height);
4442 * gtk_render_icon_pixbuf:
4443 * @context: a #GtkStyleContext
4444 * @source: the #GtkIconSource specifying the icon to render
4445 * @size: (type int): the size to render the icon at. A size of (GtkIconSize) -1
4446 * means render at the size of the source and don't scale.
4448 * Renders the icon specified by @source at the given @size, returning the result
4451 * Returns: (transfer full): a newly-created #GdkPixbuf containing the rendered icon
4456 gtk_render_icon_pixbuf (GtkStyleContext *context,
4457 const GtkIconSource *source,
4460 GtkStyleContextPrivate *priv;
4461 GtkThemingEngineClass *engine_class;
4463 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
4464 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
4465 g_return_val_if_fail (source != NULL, NULL);
4467 priv = context->priv;
4468 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4470 _gtk_theming_engine_set_context (priv->theming_engine, context);
4471 return engine_class->render_icon_pixbuf (priv->theming_engine, source, size);
4476 * @context: a #GtkStyleContext
4478 * @pixbuf: a #GdkPixbuf containing the icon to draw
4479 * @x: X position for the @pixbuf
4480 * @y: Y position for the @pixbuf
4482 * Renders the icon in @pixbuf at the specified @x and @y coordinates.
4487 gtk_render_icon (GtkStyleContext *context,
4493 GtkStyleContextPrivate *priv;
4494 GtkThemingEngineClass *engine_class;
4496 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4497 g_return_if_fail (cr != NULL);
4499 priv = context->priv;
4500 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4504 store_animation_region (context,
4506 gdk_pixbuf_get_width (pixbuf),
4507 gdk_pixbuf_get_height (pixbuf));
4509 _gtk_theming_engine_set_context (priv->theming_engine, context);
4510 engine_class->render_icon (priv->theming_engine, cr, pixbuf, x, y);
4516 draw_insertion_cursor (GtkStyleContext *context,
4521 gboolean is_primary,
4522 PangoDirection direction,
4523 gboolean draw_arrow)
4526 GdkRGBA primary_color;
4527 GdkRGBA secondary_color;
4528 gfloat cursor_aspect_ratio;
4534 _gtk_style_context_get_cursor_color (context, &primary_color, &secondary_color);
4535 gdk_cairo_set_source_rgba (cr, is_primary ? &primary_color : &secondary_color);
4537 /* When changing the shape or size of the cursor here,
4538 * propagate the changes to gtktextview.c:text_window_invalidate_cursors().
4541 gtk_style_context_get_style (context,
4542 "cursor-aspect-ratio", &cursor_aspect_ratio,
4545 stem_width = height * cursor_aspect_ratio + 1;
4547 /* put (stem_width % 2) on the proper side of the cursor */
4548 if (direction == PANGO_DIRECTION_LTR)
4549 offset = stem_width / 2;
4551 offset = stem_width - stem_width / 2;
4553 cairo_rectangle (cr, x - offset, y, stem_width, height);
4561 arrow_width = stem_width + 1;
4563 if (direction == PANGO_DIRECTION_RTL)
4565 ax = x - offset - 1;
4566 ay = y + height - arrow_width * 2 - arrow_width + 1;
4568 cairo_move_to (cr, ax, ay + 1);
4569 cairo_line_to (cr, ax - arrow_width, ay + arrow_width);
4570 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4573 else if (direction == PANGO_DIRECTION_LTR)
4575 ax = x + stem_width - offset;
4576 ay = y + height - arrow_width * 2 - arrow_width + 1;
4578 cairo_move_to (cr, ax, ay + 1);
4579 cairo_line_to (cr, ax + arrow_width, ay + arrow_width);
4580 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4584 g_assert_not_reached();
4591 * gtk_render_insertion_cursor:
4592 * @context: a #GtkStyleContext
4596 * @layout: the #PangoLayout of the text
4597 * @index: the index in the #PangoLayout
4598 * @direction: the #PangoDirection of the text
4600 * Draws a text caret on @cr at the specified index of @layout.
4605 gtk_render_insertion_cursor (GtkStyleContext *context,
4609 PangoLayout *layout,
4611 PangoDirection direction)
4613 GtkStyleContextPrivate *priv;
4614 gboolean split_cursor;
4615 PangoRectangle strong_pos, weak_pos;
4616 PangoRectangle *cursor1, *cursor2;
4617 PangoDirection keymap_direction;
4618 PangoDirection direction2;
4620 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4621 g_return_if_fail (cr != NULL);
4622 g_return_if_fail (PANGO_IS_LAYOUT (layout));
4623 g_return_if_fail (index >= 0);
4625 priv = context->priv;
4627 g_object_get (gtk_settings_get_for_screen (priv->screen),
4628 "gtk-split-cursor", &split_cursor,
4631 keymap_direction = gdk_keymap_get_direction (gdk_keymap_get_for_display (gdk_screen_get_display (priv->screen)));
4633 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4635 direction2 = PANGO_DIRECTION_NEUTRAL;
4639 cursor1 = &strong_pos;
4641 if (strong_pos.x != weak_pos.x || strong_pos.y != weak_pos.y)
4643 direction2 = (direction == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
4644 cursor2 = &weak_pos;
4649 if (keymap_direction == direction)
4650 cursor1 = &strong_pos;
4652 cursor1 = &weak_pos;
4655 draw_insertion_cursor (context,
4657 x + PANGO_PIXELS (cursor1->x),
4658 y + PANGO_PIXELS (cursor1->y),
4659 PANGO_PIXELS (cursor1->height),
4662 direction2 != PANGO_DIRECTION_NEUTRAL);
4664 if (direction2 != PANGO_DIRECTION_NEUTRAL)
4666 draw_insertion_cursor (context,
4668 x + PANGO_PIXELS (cursor2->x),
4669 y + PANGO_PIXELS (cursor2->y),
4670 PANGO_PIXELS (cursor2->height),
4678 * gtk_draw_insertion_cursor:
4679 * @widget: a #GtkWidget
4680 * @cr: cairo context to draw to
4681 * @location: location where to draw the cursor (@location->width is ignored)
4682 * @is_primary: if the cursor should be the primary cursor color.
4683 * @direction: whether the cursor is left-to-right or
4684 * right-to-left. Should never be #GTK_TEXT_DIR_NONE
4685 * @draw_arrow: %TRUE to draw a directional arrow on the
4686 * cursor. Should be %FALSE unless the cursor is split.
4688 * Draws a text caret on @cr at @location. This is not a style function
4689 * but merely a convenience function for drawing the standard cursor shape.
4692 * Deprecated: 3.4: Use gtk_render_insertion_cursor() instead.
4695 gtk_draw_insertion_cursor (GtkWidget *widget,
4697 const GdkRectangle *location,
4698 gboolean is_primary,
4699 GtkTextDirection direction,
4700 gboolean draw_arrow)
4702 GtkStyleContext *context;
4704 g_return_if_fail (GTK_IS_WIDGET (widget));
4705 g_return_if_fail (cr != NULL);
4706 g_return_if_fail (location != NULL);
4707 g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
4709 context = gtk_widget_get_style_context (widget);
4711 draw_insertion_cursor (context, cr,
4712 location->x, location->y, location->height,
4714 (direction == GTK_TEXT_DIR_RTL) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR,
4718 static AtkAttributeSet *
4719 add_attribute (AtkAttributeSet *attributes,
4720 AtkTextAttribute attr,
4725 at = g_new (AtkAttribute, 1);
4726 at->name = g_strdup (atk_text_attribute_get_name (attr));
4727 at->value = g_strdup (value);
4729 return g_slist_prepend (attributes, at);
4733 * _gtk_style_context_get_attributes:
4734 * @attributes: a #AtkAttributeSet to add attributes to
4735 * @context: the #GtkStyleContext to get attributes from
4736 * @flags: the state to use with @context
4738 * Adds the foreground and background color from @context to
4739 * @attributes, after translating them to ATK attributes.
4741 * This is a convenience function that can be used in
4742 * implementing the #AtkText interface in widgets.
4744 * Returns: the modified #AtkAttributeSet
4747 _gtk_style_context_get_attributes (AtkAttributeSet *attributes,
4748 GtkStyleContext *context,
4749 GtkStateFlags flags)
4754 gtk_style_context_get_background_color (context, flags, &color);
4755 value = g_strdup_printf ("%u,%u,%u",
4756 (guint) ceil (color.red * 65536 - color.red),
4757 (guint) ceil (color.green * 65536 - color.green),
4758 (guint) ceil (color.blue * 65536 - color.blue));
4759 attributes = add_attribute (attributes, ATK_TEXT_ATTR_BG_COLOR, value);
4762 gtk_style_context_get_color (context, flags, &color);
4763 value = g_strdup_printf ("%u,%u,%u",
4764 (guint) ceil (color.red * 65536 - color.red),
4765 (guint) ceil (color.green * 65536 - color.green),
4766 (guint) ceil (color.blue * 65536 - color.blue));
4767 attributes = add_attribute (attributes, ATK_TEXT_ATTR_FG_COLOR, value);