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 "gtkstylepropertiesprivate.h"
27 #include "gtktypebuiltins.h"
28 #include "gtkthemingengineprivate.h"
30 #include "gtkwidget.h"
31 #include "gtkwindow.h"
32 #include "gtkprivate.h"
33 #include "gtksymboliccolorprivate.h"
34 #include "gtkanimationdescription.h"
35 #include "gtktimeline.h"
36 #include "gtkiconfactory.h"
37 #include "gtkwidgetpath.h"
38 #include "gtkwidgetprivate.h"
39 #include "gtkstylecascadeprivate.h"
40 #include "gtkstyleproviderprivate.h"
41 #include "gtksettings.h"
44 * SECTION:gtkstylecontext
45 * @Short_description: Rendering UI elements
46 * @Title: GtkStyleContext
48 * #GtkStyleContext is an object that stores styling information affecting
49 * a widget defined by #GtkWidgetPath.
51 * In order to construct the final style information, #GtkStyleContext
52 * queries information from all attached #GtkStyleProviders. Style providers
53 * can be either attached explicitly to the context through
54 * gtk_style_context_add_provider(), or to the screen through
55 * gtk_style_context_add_provider_for_screen(). The resulting style is a
56 * combination of all providers' information in priority order.
58 * For GTK+ widgets, any #GtkStyleContext returned by
59 * gtk_widget_get_style_context() will already have a #GtkWidgetPath, a
60 * #GdkScreen and RTL/LTR information set. The style context will be also
61 * updated automatically if any of these settings change on the widget.
63 * If you are using the theming layer standalone, you will need to set a
64 * widget path and a screen yourself to the created style context through
65 * gtk_style_context_set_path() and gtk_style_context_set_screen(), as well
66 * as updating the context yourself using gtk_style_context_invalidate()
67 * whenever any of the conditions change, such as a change in the
68 * #GtkSettings:gtk-theme-name setting or a hierarchy change in the rendered
71 * <refsect2 id="gtkstylecontext-animations">
72 * <title>Transition animations</title>
74 * #GtkStyleContext has built-in support for state change transitions.
75 * Note that these animations respect the #GtkSettings:gtk-enable-animations
79 * For simple widgets where state changes affect the whole widget area,
80 * calling gtk_style_context_notify_state_change() with a %NULL region
81 * is sufficient to trigger the transition animation. And GTK+ already
82 * does that when gtk_widget_set_state() or gtk_widget_set_state_flags()
86 * If a widget needs to declare several animatable regions (i.e. not
87 * affecting the whole widget area), its #GtkWidget::draw signal handler
88 * needs to wrap the render operations for the different regions with
89 * calls to gtk_style_context_push_animatable_region() and
90 * gtk_style_context_pop_animatable_region(). These functions take an
91 * identifier for the region which must be unique within the style context.
92 * For simple widgets with a fixed set of animatable regions, using an
93 * enumeration works well:
96 * <title>Using an enumeration to identify animatable regions</title>
107 * spin_button_draw (GtkWidget *widget,
110 * GtkStyleContext *context;
112 * context = gtk_widget_get_style_context (widget);
114 * gtk_style_context_push_animatable_region (context,
115 * GUINT_TO_POINTER (REGION_ENTRY));
117 * gtk_render_background (cr, 0, 0, 100, 30);
118 * gtk_render_frame (cr, 0, 0, 100, 30);
120 * gtk_style_context_pop_animatable_region (context);
127 * For complex widgets with an arbitrary number of animatable regions, it
128 * is up to the implementation to come up with a way to uniquely identify
129 * each animatable region. Using pointers to internal structs is one way
133 * <title>Using struct pointers to identify animatable regions</title>
136 * notebook_draw_tab (GtkWidget *widget,
137 * NotebookPage *page,
140 * gtk_style_context_push_animatable_region (context, page);
141 * gtk_render_extension (cr, page->x, page->y, page->width, page->height);
142 * gtk_style_context_pop_animatable_region (context);
147 * The widget also needs to notify the style context about a state change
148 * for a given animatable region so the animation is triggered.
151 * <title>Triggering a state change animation on a region</title>
154 * notebook_motion_notify (GtkWidget *widget,
155 * GdkEventMotion *event)
157 * GtkStyleContext *context;
158 * NotebookPage *page;
160 * context = gtk_widget_get_style_context (widget);
161 * page = find_page_under_pointer (widget, event);
162 * gtk_style_context_notify_state_change (context,
163 * gtk_widget_get_window (widget),
165 * GTK_STATE_PRELIGHT,
172 * gtk_style_context_notify_state_change() accepts %NULL region IDs as a
173 * special value, in this case, the whole widget area will be updated
177 * <refsect2 id="gtkstylecontext-classes">
178 * <title>Style classes and regions</title>
180 * Widgets can add style classes to their context, which can be used
181 * to associate different styles by class (see <xref linkend="gtkcssprovider-selectors"/>). Theme engines can also use style classes to vary their
182 * rendering. GTK+ has a number of predefined style classes:
183 * #GTK_STYLE_CLASS_CELL,
184 * #GTK_STYLE_CLASS_ENTRY,
185 * #GTK_STYLE_CLASS_BUTTON,
186 * #GTK_STYLE_CLASS_COMBOBOX_ENTRY,
187 * #GTK_STYLE_CLASS_CALENDAR,
188 * #GTK_STYLE_CLASS_SLIDER,
189 * #GTK_STYLE_CLASS_BACKGROUND,
190 * #GTK_STYLE_CLASS_RUBBERBAND,
191 * #GTK_STYLE_CLASS_TOOLTIP,
192 * #GTK_STYLE_CLASS_MENU,
193 * #GTK_STYLE_CLASS_MENUBAR,
194 * #GTK_STYLE_CLASS_MENUITEM,
195 * #GTK_STYLE_CLASS_TOOLBAR,
196 * #GTK_STYLE_CLASS_PRIMARY_TOOLBAR,
197 * #GTK_STYLE_CLASS_INLINE_TOOLBAR,
198 * #GTK_STYLE_CLASS_RADIO,
199 * #GTK_STYLE_CLASS_CHECK,
200 * #GTK_STYLE_CLASS_TROUGH,
201 * #GTK_STYLE_CLASS_SCROLLBAR,
202 * #GTK_STYLE_CLASS_SCALE,
203 * #GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE,
204 * #GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW,
205 * #GTK_STYLE_CLASS_HEADER,
206 * #GTK_STYLE_CLASS_ACCELERATOR,
207 * #GTK_STYLE_CLASS_GRIP,
208 * #GTK_STYLE_CLASS_DOCK,
209 * #GTK_STYLE_CLASS_PROGRESSBAR,
210 * #GTK_STYLE_CLASS_SPINNER,
211 * #GTK_STYLE_CLASS_EXPANDER,
212 * #GTK_STYLE_CLASS_SPINBUTTON,
213 * #GTK_STYLE_CLASS_NOTEBOOK,
214 * #GTK_STYLE_CLASS_VIEW,
215 * #GTK_STYLE_CLASS_SIDEBAR,
216 * #GTK_STYLE_CLASS_IMAGE,
217 * #GTK_STYLE_CLASS_HIGHLIGHT,
218 * #GTK_STYLE_CLASS_FRAME,
219 * #GTK_STYLE_CLASS_DND,
220 * #GTK_STYLE_CLASS_PANE_SEPARATOR,
221 * #GTK_STYLE_CLASS_SEPARATOR,
222 * #GTK_STYLE_CLASS_INFO,
223 * #GTK_STYLE_CLASS_WARNING,
224 * #GTK_STYLE_CLASS_QUESTION,
225 * #GTK_STYLE_CLASS_ERROR,
226 * #GTK_STYLE_CLASS_HORIZONTAL,
227 * #GTK_STYLE_CLASS_VERTICAL,
228 * #GTK_STYLE_CLASS_TOP,
229 * #GTK_STYLE_CLASS_BOTTOM,
230 * #GTK_STYLE_CLASS_LEFT,
231 * #GTK_STYLE_CLASS_RIGHT,
234 * Widgets can also add regions with flags to their context.
235 * The regions used by GTK+ widgets are:
240 * <entry>Region</entry>
241 * <entry>Flags</entry>
242 * <entry>Macro</entry>
243 * <entry>Used by</entry>
249 * <entry>even, odd</entry>
250 * <entry>GTK_STYLE_REGION_ROW</entry>
251 * <entry>#GtkTreeView</entry>
254 * <entry>column</entry>
255 * <entry>first, last, sorted</entry>
256 * <entry>GTK_STYLE_REGION_COLUMN</entry>
257 * <entry>#GtkTreeView</entry>
260 * <entry>column-header</entry>
262 * <entry>GTK_STYLE_REGION_COLUMN_HEADER</entry>
267 * <entry>even, odd, first, last</entry>
268 * <entry>GTK_STYLE_REGION_TAB</entry>
269 * <entry>#GtkNotebook</entry>
276 * <refsect2 id="gtkstylecontext-custom-styling">
277 * <title>Custom styling in UI libraries and applications</title>
279 * If you are developing a library with custom #GtkWidget<!-- -->s that
280 * render differently than standard components, you may need to add a
281 * #GtkStyleProvider yourself with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK
282 * priority, either a #GtkCssProvider or a custom object implementing the
283 * #GtkStyleProvider interface. This way theming engines may still attempt
284 * to style your UI elements in a different way if needed so.
287 * If you are using custom styling on an applications, you probably want then
288 * to make your style information prevail to the theme's, so you must use
289 * a #GtkStyleProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
290 * priority, keep in mind that the user settings in
291 * <filename><replaceable>XDG_CONFIG_HOME</replaceable>/gtk-3.0/gtk.css</filename> will
292 * still take precedence over your changes, as it uses the
293 * %GTK_STYLE_PROVIDER_PRIORITY_USER priority.
296 * If a custom theming engine is needed, you probably want to implement a
297 * #GtkStyleProvider yourself so it points to your #GtkThemingEngine
298 * implementation, as #GtkCssProvider uses gtk_theming_engine_load()
299 * which loads the theming engine module from the standard paths.
304 typedef struct GtkStyleInfo GtkStyleInfo;
305 typedef struct GtkRegion GtkRegion;
306 typedef struct PropertyValue PropertyValue;
307 typedef struct AnimationInfo AnimationInfo;
308 typedef struct StyleData StyleData;
313 GtkRegionFlags flags;
326 GArray *style_classes;
328 GtkJunctionSides junction_sides;
329 GtkStateFlags state_flags;
334 GtkCssComputedValues *store;
335 GArray *property_cache;
340 GtkTimeline *timeline;
344 /* Region stack (until region_id) at the time of
345 * rendering, this is used for nested cancellation.
347 GSList *parent_regions;
351 gboolean target_value;
353 cairo_region_t *invalidation_region;
357 struct _GtkStyleContextPrivate
361 GtkStyleCascade *cascade;
363 GtkStyleContext *parent;
366 GtkWidgetPath *widget_path;
367 GHashTable *style_data;
369 StyleData *current_data;
370 GtkStateFlags current_state;
372 GSList *animation_regions;
375 GtkThemingEngine *theming_engine;
377 GtkTextDirection direction;
379 guint animations_invalidated : 1;
380 guint invalidating_context : 1;
395 static guint signals[LAST_SIGNAL] = { 0 };
397 static void gtk_style_context_finalize (GObject *object);
399 static void gtk_style_context_impl_set_property (GObject *object,
403 static void gtk_style_context_impl_get_property (GObject *object,
407 static GtkSymbolicColor *
408 gtk_style_context_color_lookup_func (gpointer contextp,
412 G_DEFINE_TYPE (GtkStyleContext, gtk_style_context, G_TYPE_OBJECT)
415 gtk_style_context_real_changed (GtkStyleContext *context)
417 GtkStyleContextPrivate *priv = context->priv;
420 _gtk_widget_style_context_invalidated (priv->widget);
424 gtk_style_context_class_init (GtkStyleContextClass *klass)
426 GObjectClass *object_class = G_OBJECT_CLASS (klass);
428 object_class->finalize = gtk_style_context_finalize;
429 object_class->set_property = gtk_style_context_impl_set_property;
430 object_class->get_property = gtk_style_context_impl_get_property;
432 klass->changed = gtk_style_context_real_changed;
435 g_signal_new (I_("changed"),
436 G_TYPE_FROM_CLASS (object_class),
438 G_STRUCT_OFFSET (GtkStyleContextClass, changed),
440 g_cclosure_marshal_VOID__VOID,
443 g_object_class_install_property (object_class,
445 g_param_spec_object ("screen",
447 P_("The associated GdkScreen"),
449 GTK_PARAM_READWRITE));
450 g_object_class_install_property (object_class,
452 g_param_spec_enum ("direction",
454 P_("Text direction"),
455 GTK_TYPE_TEXT_DIRECTION,
457 GTK_PARAM_READWRITE));
459 * GtkStyleContext:parent:
461 * Sets or gets the style context's parent. See gtk_style_context_set_parent()
466 g_object_class_install_property (object_class,
468 g_param_spec_object ("parent",
470 P_("The parent style context"),
471 GTK_TYPE_STYLE_CONTEXT,
472 GTK_PARAM_READWRITE));
474 g_type_class_add_private (object_class, sizeof (GtkStyleContextPrivate));
477 static GtkStyleInfo *
478 style_info_new (void)
482 info = g_slice_new0 (GtkStyleInfo);
483 info->style_classes = g_array_new (FALSE, FALSE, sizeof (GQuark));
484 info->regions = g_array_new (FALSE, FALSE, sizeof (GtkRegion));
490 style_info_free (GtkStyleInfo *info)
492 g_array_free (info->style_classes, TRUE);
493 g_array_free (info->regions, TRUE);
494 g_slice_free (GtkStyleInfo, info);
497 static GtkStyleInfo *
498 style_info_copy (const GtkStyleInfo *info)
502 copy = style_info_new ();
503 g_array_insert_vals (copy->style_classes, 0,
504 info->style_classes->data,
505 info->style_classes->len);
507 g_array_insert_vals (copy->regions, 0,
511 copy->junction_sides = info->junction_sides;
512 copy->state_flags = info->state_flags;
518 style_info_hash (gconstpointer elem)
520 const GtkStyleInfo *info;
525 for (i = 0; i < info->style_classes->len; i++)
527 hash += g_array_index (info->style_classes, GQuark, i);
531 for (i = 0; i < info->regions->len; i++)
535 region = &g_array_index (info->regions, GtkRegion, i);
536 hash += region->class_quark;
537 hash += region->flags;
541 return hash ^ info->state_flags;
545 style_info_equal (gconstpointer elem1,
548 const GtkStyleInfo *info1, *info2;
553 if (info1->state_flags != info2->state_flags)
556 if (info1->junction_sides != info2->junction_sides)
559 if (info1->style_classes->len != info2->style_classes->len)
562 if (memcmp (info1->style_classes->data,
563 info2->style_classes->data,
564 info1->style_classes->len * sizeof (GQuark)) != 0)
567 if (info1->regions->len != info2->regions->len)
570 if (memcmp (info1->regions->data,
571 info2->regions->data,
572 info1->regions->len * sizeof (GtkRegion)) != 0)
579 style_data_new (void)
583 data = g_slice_new0 (StyleData);
589 clear_property_cache (StyleData *data)
593 if (!data->property_cache)
596 for (i = 0; i < data->property_cache->len; i++)
598 PropertyValue *node = &g_array_index (data->property_cache, PropertyValue, i);
600 g_param_spec_unref (node->pspec);
601 g_value_unset (&node->value);
604 g_array_free (data->property_cache, TRUE);
605 data->property_cache = NULL;
609 style_data_free (StyleData *data)
611 g_object_unref (data->store);
612 clear_property_cache (data);
614 g_slice_free (StyleData, data);
618 gtk_style_context_init (GtkStyleContext *style_context)
620 GtkStyleContextPrivate *priv;
623 priv = style_context->priv = G_TYPE_INSTANCE_GET_PRIVATE (style_context,
624 GTK_TYPE_STYLE_CONTEXT,
625 GtkStyleContextPrivate);
627 priv->style_data = g_hash_table_new_full (style_info_hash,
629 (GDestroyNotify) style_info_free,
630 (GDestroyNotify) style_data_free);
631 priv->theming_engine = g_object_ref ((gpointer) gtk_theming_engine_load (NULL));
633 priv->direction = GTK_TEXT_DIR_LTR;
635 priv->screen = gdk_screen_get_default ();
636 priv->cascade = _gtk_style_cascade_get_for_screen (priv->screen);
637 g_object_ref (priv->cascade);
639 /* Create default info store */
640 info = style_info_new ();
641 priv->info_stack = g_slist_prepend (priv->info_stack, info);
645 animation_info_free (AnimationInfo *info)
647 g_object_unref (info->timeline);
648 g_object_unref (info->window);
650 if (info->invalidation_region)
651 cairo_region_destroy (info->invalidation_region);
653 g_array_free (info->rectangles, TRUE);
654 g_slist_free (info->parent_regions);
655 g_slice_free (AnimationInfo, info);
658 static AnimationInfo *
659 animation_info_lookup_by_timeline (GtkStyleContext *context,
660 GtkTimeline *timeline)
662 GtkStyleContextPrivate *priv;
666 priv = context->priv;
668 for (l = priv->animations; l; l = l->next)
672 if (info->timeline == timeline)
680 timeline_frame_cb (GtkTimeline *timeline,
684 GtkStyleContextPrivate *priv;
685 GtkStyleContext *context;
689 priv = context->priv;
690 info = animation_info_lookup_by_timeline (context, timeline);
692 g_assert (info != NULL);
694 /* Cancel transition if window is gone */
695 if (gdk_window_is_destroyed (info->window) ||
696 !gdk_window_is_visible (info->window))
698 priv->animations = g_slist_remove (priv->animations, info);
699 animation_info_free (info);
703 if (info->invalidation_region &&
704 !cairo_region_is_empty (info->invalidation_region))
705 gdk_window_invalidate_region (info->window, info->invalidation_region, TRUE);
707 gdk_window_invalidate_rect (info->window, NULL, TRUE);
711 timeline_finished_cb (GtkTimeline *timeline,
714 GtkStyleContextPrivate *priv;
715 GtkStyleContext *context;
719 priv = context->priv;
720 info = animation_info_lookup_by_timeline (context, timeline);
722 g_assert (info != NULL);
724 priv->animations = g_slist_remove (priv->animations, info);
726 /* Invalidate one last time the area, so the final content is painted */
727 if (info->invalidation_region &&
728 !cairo_region_is_empty (info->invalidation_region))
729 gdk_window_invalidate_region (info->window, info->invalidation_region, TRUE);
731 gdk_window_invalidate_rect (info->window, NULL, TRUE);
733 animation_info_free (info);
736 static AnimationInfo *
737 animation_info_new (GtkStyleContext *context,
740 GtkTimelineProgressType progress_type,
743 gboolean target_value,
748 info = g_slice_new0 (AnimationInfo);
750 info->rectangles = g_array_new (FALSE, FALSE, sizeof (cairo_rectangle_int_t));
751 info->timeline = _gtk_timeline_new (duration);
752 info->window = g_object_ref (window);
754 info->target_value = target_value;
755 info->region_id = region_id;
757 _gtk_timeline_set_progress_type (info->timeline, progress_type);
758 _gtk_timeline_set_loop (info->timeline, loop);
760 if (!loop && !target_value)
762 _gtk_timeline_set_direction (info->timeline, GTK_TIMELINE_DIRECTION_BACKWARD);
763 _gtk_timeline_rewind (info->timeline);
766 g_signal_connect (info->timeline, "frame",
767 G_CALLBACK (timeline_frame_cb), context);
768 g_signal_connect (info->timeline, "finished",
769 G_CALLBACK (timeline_finished_cb), context);
771 _gtk_timeline_start (info->timeline);
776 static AnimationInfo *
777 animation_info_lookup (GtkStyleContext *context,
781 GtkStyleContextPrivate *priv;
784 priv = context->priv;
786 for (l = priv->animations; l; l = l->next)
792 if (info->state == state &&
793 info->region_id == region_id)
801 gtk_style_context_finalize (GObject *object)
803 GtkStyleContextPrivate *priv;
804 GtkStyleContext *style_context;
807 style_context = GTK_STYLE_CONTEXT (object);
808 priv = style_context->priv;
810 /* children hold a reference to us */
811 g_assert (priv->children == NULL);
813 gtk_style_context_set_parent (style_context, NULL);
815 if (priv->widget_path)
816 gtk_widget_path_free (priv->widget_path);
818 g_hash_table_destroy (priv->style_data);
820 g_object_unref (priv->cascade);
822 g_slist_free_full (priv->info_stack, (GDestroyNotify) style_info_free);
824 g_slist_free (priv->animation_regions);
826 for (l = priv->animations; l; l = l->next)
827 animation_info_free ((AnimationInfo *) l->data);
829 g_slist_free (priv->animations);
831 if (priv->theming_engine)
832 g_object_unref (priv->theming_engine);
834 G_OBJECT_CLASS (gtk_style_context_parent_class)->finalize (object);
838 gtk_style_context_impl_set_property (GObject *object,
843 GtkStyleContext *style_context;
845 style_context = GTK_STYLE_CONTEXT (object);
850 gtk_style_context_set_screen (style_context,
851 g_value_get_object (value));
854 gtk_style_context_set_direction (style_context,
855 g_value_get_enum (value));
858 gtk_style_context_set_parent (style_context,
859 g_value_get_object (value));
862 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
868 gtk_style_context_impl_get_property (GObject *object,
873 GtkStyleContext *style_context;
874 GtkStyleContextPrivate *priv;
876 style_context = GTK_STYLE_CONTEXT (object);
877 priv = style_context->priv;
882 g_value_set_object (value, priv->screen);
885 g_value_set_enum (value, priv->direction);
888 g_value_set_object (value, priv->parent);
891 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
897 build_properties (GtkStyleContext *context,
898 StyleData *style_data,
902 GtkStyleContextPrivate *priv;
903 GtkCssMatcher matcher;
904 GtkCssLookup *lookup;
906 priv = context->priv;
908 _gtk_css_matcher_init (&matcher, path, state);
909 lookup = _gtk_css_lookup_new ();
911 _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
915 style_data->store = _gtk_css_computed_values_new ();
916 _gtk_css_lookup_resolve (lookup, context, style_data->store);
917 _gtk_css_lookup_free (lookup);
920 static GtkWidgetPath *
921 create_query_path (GtkStyleContext *context)
923 GtkStyleContextPrivate *priv;
928 priv = context->priv;
929 path = gtk_widget_path_copy (priv->widget ? gtk_widget_get_path (priv->widget) : priv->widget_path);
930 pos = gtk_widget_path_length (path) - 1;
932 info = priv->info_stack->data;
934 /* Set widget regions */
935 for (i = 0; i < info->regions->len; i++)
939 region = &g_array_index (info->regions, GtkRegion, i);
940 gtk_widget_path_iter_add_region (path, pos,
941 g_quark_to_string (region->class_quark),
945 /* Set widget classes */
946 for (i = 0; i < info->style_classes->len; i++)
950 quark = g_array_index (info->style_classes, GQuark, i);
951 gtk_widget_path_iter_add_class (path, pos,
952 g_quark_to_string (quark));
959 style_data_lookup (GtkStyleContext *context,
962 GtkStyleContextPrivate *priv;
964 gboolean state_mismatch;
967 priv = context->priv;
968 state_mismatch = ((GtkStyleInfo *) priv->info_stack->data)->state_flags != state;
970 /* Current data in use is cached, just return it */
971 if (priv->current_data && priv->current_state == state)
972 return priv->current_data;
974 g_assert (priv->widget != NULL || priv->widget_path != NULL);
976 if (G_UNLIKELY (state_mismatch))
978 gtk_style_context_save (context);
979 gtk_style_context_set_state (context, state);
982 priv->current_data = g_hash_table_lookup (priv->style_data, priv->info_stack->data);
983 priv->current_state = state;
985 if (!priv->current_data)
989 path = create_query_path (context);
991 priv->current_data = style_data_new ();
992 g_hash_table_insert (priv->style_data,
993 style_info_copy (priv->info_stack->data),
996 build_properties (context, priv->current_data, path, state);
998 gtk_widget_path_free (path);
1001 data = priv->current_data;
1003 if (priv->theming_engine)
1004 g_object_unref (priv->theming_engine);
1006 v = _gtk_css_computed_values_get_value_by_name (priv->current_data->store, "engine");
1008 priv->theming_engine = _gtk_css_value_dup_object (v);
1010 priv->theming_engine = g_object_ref (gtk_theming_engine_load (NULL));
1012 if (G_UNLIKELY (state_mismatch))
1013 gtk_style_context_restore (context);
1019 * gtk_style_context_new:
1021 * Creates a standalone #GtkStyleContext, this style context
1022 * won't be attached to any widget, so you may want
1023 * to call gtk_style_context_set_path() yourself.
1026 * This function is only useful when using the theming layer
1027 * separated from GTK+, if you are using #GtkStyleContext to
1028 * theme #GtkWidget<!-- -->s, use gtk_widget_get_style_context()
1029 * in order to get a style context ready to theme the widget.
1032 * Returns: A newly created #GtkStyleContext.
1035 gtk_style_context_new (void)
1037 return g_object_new (GTK_TYPE_STYLE_CONTEXT, NULL);
1041 _gtk_style_context_set_widget (GtkStyleContext *context,
1044 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1045 g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget));
1047 context->priv->widget = widget;
1051 * gtk_style_context_add_provider:
1052 * @context: a #GtkStyleContext
1053 * @provider: a #GtkStyleProvider
1054 * @priority: the priority of the style provider. The lower
1055 * it is, the earlier it will be used in the style
1056 * construction. Typically this will be in the range
1057 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1058 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1060 * Adds a style provider to @context, to be used in style construction.
1062 * <note><para>If both priorities are the same, A #GtkStyleProvider
1063 * added through this function takes precedence over another added
1064 * through gtk_style_context_add_provider_for_screen().</para></note>
1069 gtk_style_context_add_provider (GtkStyleContext *context,
1070 GtkStyleProvider *provider,
1073 GtkStyleContextPrivate *priv;
1075 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1076 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1078 priv = context->priv;
1080 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
1082 GtkStyleCascade *new_cascade;
1084 new_cascade = _gtk_style_cascade_new ();
1085 _gtk_style_cascade_set_parent (new_cascade, priv->cascade);
1086 g_object_unref (priv->cascade);
1087 priv->cascade = new_cascade;
1090 _gtk_style_cascade_add_provider (priv->cascade, provider, priority);
1092 gtk_style_context_invalidate (context);
1096 * gtk_style_context_remove_provider:
1097 * @context: a #GtkStyleContext
1098 * @provider: a #GtkStyleProvider
1100 * Removes @provider from the style providers list in @context.
1105 gtk_style_context_remove_provider (GtkStyleContext *context,
1106 GtkStyleProvider *provider)
1108 GtkStyleContextPrivate *priv;
1110 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1111 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1113 priv = context->priv;
1115 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
1118 _gtk_style_cascade_remove_provider (priv->cascade, provider);
1122 * gtk_style_context_reset_widgets:
1123 * @screen: a #GdkScreen
1125 * This function recomputes the styles for all widgets under a particular
1126 * #GdkScreen. This is useful when some global parameter has changed that
1127 * affects the appearance of all widgets, because when a widget gets a new
1128 * style, it will both redraw and recompute any cached information about
1129 * its appearance. As an example, it is used when the color scheme changes
1130 * in the related #GtkSettings object.
1135 gtk_style_context_reset_widgets (GdkScreen *screen)
1137 GList *list, *toplevels;
1139 _gtk_icon_set_invalidate_caches ();
1141 toplevels = gtk_window_list_toplevels ();
1142 g_list_foreach (toplevels, (GFunc) g_object_ref, NULL);
1144 for (list = toplevels; list; list = list->next)
1146 if (gtk_widget_get_screen (list->data) == screen)
1147 gtk_widget_reset_style (list->data);
1149 g_object_unref (list->data);
1152 g_list_free (toplevels);
1156 * gtk_style_context_add_provider_for_screen:
1157 * @screen: a #GdkScreen
1158 * @provider: a #GtkStyleProvider
1159 * @priority: the priority of the style provider. The lower
1160 * it is, the earlier it will be used in the style
1161 * construction. Typically this will be in the range
1162 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1163 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1165 * Adds a global style provider to @screen, which will be used
1166 * in style construction for all #GtkStyleContext<!-- -->s under
1169 * GTK+ uses this to make styling information from #GtkSettings
1172 * <note><para>If both priorities are the same, A #GtkStyleProvider
1173 * added through gtk_style_context_add_provider() takes precedence
1174 * over another added through this function.</para></note>
1179 gtk_style_context_add_provider_for_screen (GdkScreen *screen,
1180 GtkStyleProvider *provider,
1183 GtkStyleCascade *cascade;
1185 g_return_if_fail (GDK_IS_SCREEN (screen));
1186 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1188 cascade = _gtk_style_cascade_get_for_screen (screen);
1189 _gtk_style_cascade_add_provider (cascade, provider, priority);
1193 * gtk_style_context_remove_provider_for_screen:
1194 * @screen: a #GdkScreen
1195 * @provider: a #GtkStyleProvider
1197 * Removes @provider from the global style providers list in @screen.
1202 gtk_style_context_remove_provider_for_screen (GdkScreen *screen,
1203 GtkStyleProvider *provider)
1205 GtkStyleCascade *cascade;
1207 g_return_if_fail (GDK_IS_SCREEN (screen));
1208 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1210 cascade = _gtk_style_cascade_get_for_screen (screen);
1211 _gtk_style_cascade_remove_provider (cascade, provider);
1215 * gtk_style_context_get_section:
1216 * @context: a #GtkStyleContext
1217 * @property: style property name
1219 * Queries the location in the CSS where @property was defined for the
1220 * current @context. Note that the state to be queried is taken from
1221 * gtk_style_context_get_state().
1223 * If the location is not available, %NULL will be returned. The
1224 * location might not be available for various reasons, such as the
1225 * property being overridden, @property not naming a supported CSS
1226 * property or tracking of definitions being disabled for performance
1229 * Shorthand CSS properties cannot be queried for a location and will
1230 * always return %NULL.
1232 * Returns: %NULL or the section where value was defined
1235 gtk_style_context_get_section (GtkStyleContext *context,
1236 const gchar *property)
1238 GtkStyleContextPrivate *priv;
1239 GtkStyleProperty *prop;
1242 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1243 g_return_val_if_fail (property != NULL, NULL);
1245 priv = context->priv;
1246 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
1248 prop = _gtk_style_property_lookup (property);
1249 if (!GTK_IS_CSS_STYLE_PROPERTY (prop))
1252 data = style_data_lookup (context, gtk_style_context_get_state (context));
1253 return _gtk_css_computed_values_get_section (data->store, _gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (prop)));
1256 static GtkCssValue *
1257 gtk_style_context_query_func (guint id,
1260 return _gtk_css_computed_values_get_value (values, id);
1264 * gtk_style_context_get_property:
1265 * @context: a #GtkStyleContext
1266 * @property: style property name
1267 * @state: state to retrieve the property value for
1268 * @value: (out) (transfer full): return location for the style property value
1270 * Gets a style property from @context for the given state.
1272 * When @value is no longer needed, g_value_unset() must be called
1273 * to free any allocated memory.
1278 gtk_style_context_get_property (GtkStyleContext *context,
1279 const gchar *property,
1280 GtkStateFlags state,
1283 GtkStyleContextPrivate *priv;
1284 GtkStyleProperty *prop;
1288 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1289 g_return_if_fail (property != NULL);
1290 g_return_if_fail (value != NULL);
1292 priv = context->priv;
1293 g_return_if_fail (priv->widget != NULL || priv->widget_path != NULL);
1295 prop = _gtk_style_property_lookup (property);
1298 g_warning ("Style property \"%s\" is not registered", property);
1301 if (_gtk_style_property_get_value_type (prop) == G_TYPE_NONE)
1303 g_warning ("Style property \"%s\" is not gettable", property);
1307 data = style_data_lookup (context, state);
1308 v = _gtk_style_property_query (prop, gtk_style_context_query_func, data->store);
1309 _gtk_css_value_init_gvalue (v, value);
1310 _gtk_css_value_unref (v);
1314 * gtk_style_context_get_valist:
1315 * @context: a #GtkStyleContext
1316 * @state: state to retrieve the property values for
1317 * @args: va_list of property name/return location pairs, followed by %NULL
1319 * Retrieves several style property values from @context for a given state.
1324 gtk_style_context_get_valist (GtkStyleContext *context,
1325 GtkStateFlags state,
1328 const gchar *property_name;
1330 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1332 property_name = va_arg (args, const gchar *);
1334 while (property_name)
1336 gchar *error = NULL;
1337 GValue value = G_VALUE_INIT;
1339 gtk_style_context_get_property (context,
1344 G_VALUE_LCOPY (&value, args, 0, &error);
1345 g_value_unset (&value);
1349 g_warning ("Could not get style property \"%s\": %s", property_name, error);
1354 property_name = va_arg (args, const gchar *);
1359 * gtk_style_context_get:
1360 * @context: a #GtkStyleContext
1361 * @state: state to retrieve the property values for
1362 * @...: property name /return value pairs, followed by %NULL
1364 * Retrieves several style property values from @context for a
1370 gtk_style_context_get (GtkStyleContext *context,
1371 GtkStateFlags state,
1376 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1378 va_start (args, state);
1379 gtk_style_context_get_valist (context, state, args);
1384 * gtk_style_context_set_state:
1385 * @context: a #GtkStyleContext
1386 * @flags: state to represent
1388 * Sets the state to be used when rendering with any
1389 * of the gtk_render_*() functions.
1394 gtk_style_context_set_state (GtkStyleContext *context,
1395 GtkStateFlags flags)
1397 GtkStyleContextPrivate *priv;
1400 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1402 priv = context->priv;
1403 info = priv->info_stack->data;
1404 info->state_flags = flags;
1408 * gtk_style_context_get_state:
1409 * @context: a #GtkStyleContext
1411 * Returns the state used when rendering.
1413 * Returns: the state flags
1418 gtk_style_context_get_state (GtkStyleContext *context)
1420 GtkStyleContextPrivate *priv;
1423 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
1425 priv = context->priv;
1426 info = priv->info_stack->data;
1428 return info->state_flags;
1432 context_has_animatable_region (GtkStyleContext *context,
1435 GtkStyleContextPrivate *priv;
1437 /* NULL region_id means everything
1438 * rendered through the style context
1443 priv = context->priv;
1444 return g_slist_find (priv->animation_regions, region_id) != NULL;
1448 * gtk_style_context_state_is_running:
1449 * @context: a #GtkStyleContext
1450 * @state: a widget state
1451 * @progress: (out): return location for the transition progress
1453 * Returns %TRUE if there is a transition animation running for the
1454 * current region (see gtk_style_context_push_animatable_region()).
1456 * If @progress is not %NULL, the animation progress will be returned
1457 * there, 0.0 means the state is closest to being unset, while 1.0 means
1458 * it's closest to being set. This means transition animation will
1459 * run from 0 to 1 when @state is being set and from 1 to 0 when
1462 * Returns: %TRUE if there is a running transition animation for @state.
1467 gtk_style_context_state_is_running (GtkStyleContext *context,
1471 GtkStyleContextPrivate *priv;
1472 AnimationInfo *info;
1475 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1477 priv = context->priv;
1479 for (l = priv->animations; l; l = l->next)
1483 if (info->state == state &&
1484 context_has_animatable_region (context, info->region_id))
1487 *progress = _gtk_timeline_get_progress (info->timeline);
1497 * gtk_style_context_set_path:
1498 * @context: a #GtkStyleContext
1499 * @path: a #GtkWidgetPath
1501 * Sets the #GtkWidgetPath used for style matching. As a
1502 * consequence, the style will be regenerated to match
1503 * the new given path.
1505 * If you are using a #GtkStyleContext returned from
1506 * gtk_widget_get_style_context(), you do not need to call
1512 gtk_style_context_set_path (GtkStyleContext *context,
1513 GtkWidgetPath *path)
1515 GtkStyleContextPrivate *priv;
1517 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1518 g_return_if_fail (path != NULL);
1520 priv = context->priv;
1521 g_return_if_fail (priv->widget == NULL);
1523 if (priv->widget_path)
1525 gtk_widget_path_free (priv->widget_path);
1526 priv->widget_path = NULL;
1530 priv->widget_path = gtk_widget_path_copy (path);
1532 gtk_style_context_invalidate (context);
1536 * gtk_style_context_get_path:
1537 * @context: a #GtkStyleContext
1539 * Returns the widget path used for style matching.
1541 * Returns: (transfer none): A #GtkWidgetPath
1545 const GtkWidgetPath *
1546 gtk_style_context_get_path (GtkStyleContext *context)
1548 GtkStyleContextPrivate *priv;
1550 priv = context->priv;
1552 return gtk_widget_get_path (priv->widget);
1554 return priv->widget_path;
1558 * gtk_style_context_set_parent:
1559 * @context: a #GtkStyleContext
1560 * @parent: (allow-none): the new parent or %NULL
1562 * Sets the parent style context for @context. The parent style
1563 * context is used to implement
1564 * <ulink url="http://www.w3.org/TR/css3-cascade/#inheritance">inheritance</ulink>
1567 * If you are using a #GtkStyleContext returned from
1568 * gtk_widget_get_style_context(), the parent will be set for you.
1573 gtk_style_context_set_parent (GtkStyleContext *context,
1574 GtkStyleContext *parent)
1576 GtkStyleContextPrivate *priv;
1578 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1579 g_return_if_fail (parent == NULL || GTK_IS_STYLE_CONTEXT (parent));
1581 priv = context->priv;
1583 if (priv->parent == parent)
1588 parent->priv->children = g_slist_prepend (parent->priv->children, context);
1589 g_object_ref (parent);
1594 priv->parent->priv->children = g_slist_remove (priv->parent->priv->children, context);
1595 g_object_unref (priv->parent);
1598 priv->parent = parent;
1600 g_object_notify (G_OBJECT (context), "parent");
1601 gtk_style_context_invalidate (context);
1605 * gtk_style_context_get_parent:
1606 * @context: a #GtkStyleContext
1608 * Gets the parent context set via gtk_style_context_set_parent().
1609 * See that function for details.
1611 * Returns: (transfer none): the parent context or %NULL
1616 gtk_style_context_get_parent (GtkStyleContext *context)
1618 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1620 return context->priv->parent;
1624 * gtk_style_context_save:
1625 * @context: a #GtkStyleContext
1627 * Saves the @context state, so all modifications done through
1628 * gtk_style_context_add_class(), gtk_style_context_remove_class(),
1629 * gtk_style_context_add_region(), gtk_style_context_remove_region()
1630 * or gtk_style_context_set_junction_sides() can be reverted in one
1631 * go through gtk_style_context_restore().
1636 gtk_style_context_save (GtkStyleContext *context)
1638 GtkStyleContextPrivate *priv;
1641 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1643 priv = context->priv;
1645 g_assert (priv->info_stack != NULL);
1647 info = style_info_copy (priv->info_stack->data);
1648 priv->info_stack = g_slist_prepend (priv->info_stack, info);
1652 * gtk_style_context_restore:
1653 * @context: a #GtkStyleContext
1655 * Restores @context state to a previous stage.
1656 * See gtk_style_context_save().
1661 gtk_style_context_restore (GtkStyleContext *context)
1663 GtkStyleContextPrivate *priv;
1666 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1668 priv = context->priv;
1670 if (priv->info_stack)
1672 info = priv->info_stack->data;
1673 priv->info_stack = g_slist_remove (priv->info_stack, info);
1674 style_info_free (info);
1677 if (!priv->info_stack)
1679 g_warning ("Unpaired gtk_style_context_restore() call");
1681 /* Create default region */
1682 info = style_info_new ();
1683 priv->info_stack = g_slist_prepend (priv->info_stack, info);
1686 priv->current_data = NULL;
1690 style_class_find (GArray *array,
1695 gboolean found = FALSE;
1701 if (!array || array->len == 0)
1705 max = array->len - 1;
1711 mid = (min + max) / 2;
1712 item = g_array_index (array, GQuark, mid);
1714 if (class_quark == item)
1719 else if (class_quark > item)
1720 min = pos = mid + 1;
1727 while (!found && min <= max);
1736 region_find (GArray *array,
1741 gboolean found = FALSE;
1747 if (!array || array->len == 0)
1751 max = array->len - 1;
1757 mid = (min + max) / 2;
1758 region = &g_array_index (array, GtkRegion, mid);
1760 if (region->class_quark == class_quark)
1765 else if (region->class_quark > class_quark)
1766 min = pos = mid + 1;
1773 while (!found && min <= max);
1782 * gtk_style_context_add_class:
1783 * @context: a #GtkStyleContext
1784 * @class_name: class name to use in styling
1786 * Adds a style class to @context, so posterior calls to
1787 * gtk_style_context_get() or any of the gtk_render_*()
1788 * functions will make use of this new class for styling.
1790 * In the CSS file format, a #GtkEntry defining an "entry"
1791 * class, would be matched by:
1794 * GtkEntry.entry { ... }
1797 * While any widget defining an "entry" class would be
1806 gtk_style_context_add_class (GtkStyleContext *context,
1807 const gchar *class_name)
1809 GtkStyleContextPrivate *priv;
1814 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1815 g_return_if_fail (class_name != NULL);
1817 priv = context->priv;
1818 class_quark = g_quark_from_string (class_name);
1820 g_assert (priv->info_stack != NULL);
1821 info = priv->info_stack->data;
1823 if (!style_class_find (info->style_classes, class_quark, &position))
1825 g_array_insert_val (info->style_classes, position, class_quark);
1827 /* Unset current data, as it likely changed due to the class change */
1828 priv->current_data = NULL;
1833 * gtk_style_context_remove_class:
1834 * @context: a #GtkStyleContext
1835 * @class_name: class name to remove
1837 * Removes @class_name from @context.
1842 gtk_style_context_remove_class (GtkStyleContext *context,
1843 const gchar *class_name)
1845 GtkStyleContextPrivate *priv;
1850 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1851 g_return_if_fail (class_name != NULL);
1853 class_quark = g_quark_try_string (class_name);
1858 priv = context->priv;
1860 g_assert (priv->info_stack != NULL);
1861 info = priv->info_stack->data;
1863 if (style_class_find (info->style_classes, class_quark, &position))
1865 g_array_remove_index (info->style_classes, position);
1867 /* Unset current data, as it likely changed due to the class change */
1868 priv->current_data = NULL;
1873 * gtk_style_context_has_class:
1874 * @context: a #GtkStyleContext
1875 * @class_name: a class name
1877 * Returns %TRUE if @context currently has defined the
1880 * Returns: %TRUE if @context has @class_name defined
1885 gtk_style_context_has_class (GtkStyleContext *context,
1886 const gchar *class_name)
1888 GtkStyleContextPrivate *priv;
1892 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1893 g_return_val_if_fail (class_name != NULL, FALSE);
1895 class_quark = g_quark_try_string (class_name);
1900 priv = context->priv;
1902 g_assert (priv->info_stack != NULL);
1903 info = priv->info_stack->data;
1905 if (style_class_find (info->style_classes, class_quark, NULL))
1912 * gtk_style_context_list_classes:
1913 * @context: a #GtkStyleContext
1915 * Returns the list of classes currently defined in @context.
1917 * Returns: (transfer container) (element-type utf8): a #GList of
1918 * strings with the currently defined classes. The contents
1919 * of the list are owned by GTK+, but you must free the list
1920 * itself with g_list_free() when you are done with it.
1925 gtk_style_context_list_classes (GtkStyleContext *context)
1927 GtkStyleContextPrivate *priv;
1929 GList *classes = NULL;
1932 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1934 priv = context->priv;
1936 g_assert (priv->info_stack != NULL);
1937 info = priv->info_stack->data;
1939 for (i = 0; i < info->style_classes->len; i++)
1943 quark = g_array_index (info->style_classes, GQuark, i);
1944 classes = g_list_prepend (classes, (gchar *) g_quark_to_string (quark));
1951 * gtk_style_context_list_regions:
1952 * @context: a #GtkStyleContext
1954 * Returns the list of regions currently defined in @context.
1956 * Returns: (transfer container) (element-type utf8): a #GList of
1957 * strings with the currently defined regions. The contents
1958 * of the list are owned by GTK+, but you must free the list
1959 * itself with g_list_free() when you are done with it.
1964 gtk_style_context_list_regions (GtkStyleContext *context)
1966 GtkStyleContextPrivate *priv;
1968 GList *classes = NULL;
1971 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1973 priv = context->priv;
1975 g_assert (priv->info_stack != NULL);
1976 info = priv->info_stack->data;
1978 for (i = 0; i < info->regions->len; i++)
1981 const gchar *class_name;
1983 region = &g_array_index (info->regions, GtkRegion, i);
1985 class_name = g_quark_to_string (region->class_quark);
1986 classes = g_list_prepend (classes, (gchar *) class_name);
1993 _gtk_style_context_check_region_name (const gchar *str)
1995 g_return_val_if_fail (str != NULL, FALSE);
1997 if (!g_ascii_islower (str[0]))
2003 !g_ascii_islower (*str))
2013 * gtk_style_context_add_region:
2014 * @context: a #GtkStyleContext
2015 * @region_name: region name to use in styling
2016 * @flags: flags that apply to the region
2018 * Adds a region to @context, so posterior calls to
2019 * gtk_style_context_get() or any of the gtk_render_*()
2020 * functions will make use of this new region for styling.
2022 * In the CSS file format, a #GtkTreeView defining a "row"
2023 * region, would be matched by:
2026 * GtkTreeView row { ... }
2029 * Pseudo-classes are used for matching @flags, so the two
2032 * GtkTreeView row:nth-child(even) { ... }
2033 * GtkTreeView row:nth-child(odd) { ... }
2036 * would apply to even and odd rows, respectively.
2038 * <note><para>Region names must only contain lowercase letters
2039 * and '-', starting always with a lowercase letter.</para></note>
2044 gtk_style_context_add_region (GtkStyleContext *context,
2045 const gchar *region_name,
2046 GtkRegionFlags flags)
2048 GtkStyleContextPrivate *priv;
2050 GQuark region_quark;
2053 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2054 g_return_if_fail (region_name != NULL);
2055 g_return_if_fail (_gtk_style_context_check_region_name (region_name));
2057 priv = context->priv;
2058 region_quark = g_quark_from_string (region_name);
2060 g_assert (priv->info_stack != NULL);
2061 info = priv->info_stack->data;
2063 if (!region_find (info->regions, region_quark, &position))
2067 region.class_quark = region_quark;
2068 region.flags = flags;
2070 g_array_insert_val (info->regions, position, region);
2072 /* Unset current data, as it likely changed due to the region change */
2073 priv->current_data = NULL;
2078 * gtk_style_context_remove_region:
2079 * @context: a #GtkStyleContext
2080 * @region_name: region name to unset
2082 * Removes a region from @context.
2087 gtk_style_context_remove_region (GtkStyleContext *context,
2088 const gchar *region_name)
2090 GtkStyleContextPrivate *priv;
2092 GQuark region_quark;
2095 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2096 g_return_if_fail (region_name != NULL);
2098 region_quark = g_quark_try_string (region_name);
2103 priv = context->priv;
2105 g_assert (priv->info_stack != NULL);
2106 info = priv->info_stack->data;
2108 if (region_find (info->regions, region_quark, &position))
2110 g_array_remove_index (info->regions, position);
2112 /* Unset current data, as it likely changed due to the region change */
2113 priv->current_data = NULL;
2118 * gtk_style_context_has_region:
2119 * @context: a #GtkStyleContext
2120 * @region_name: a region name
2121 * @flags_return: (out) (allow-none): return location for region flags
2123 * Returns %TRUE if @context has the region defined.
2124 * If @flags_return is not %NULL, it is set to the flags
2125 * affecting the region.
2127 * Returns: %TRUE if region is defined
2132 gtk_style_context_has_region (GtkStyleContext *context,
2133 const gchar *region_name,
2134 GtkRegionFlags *flags_return)
2136 GtkStyleContextPrivate *priv;
2138 GQuark region_quark;
2141 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2142 g_return_val_if_fail (region_name != NULL, FALSE);
2147 region_quark = g_quark_try_string (region_name);
2152 priv = context->priv;
2154 g_assert (priv->info_stack != NULL);
2155 info = priv->info_stack->data;
2157 if (region_find (info->regions, region_quark, &position))
2163 region = &g_array_index (info->regions, GtkRegion, position);
2164 *flags_return = region->flags;
2173 style_property_values_cmp (gconstpointer bsearch_node1,
2174 gconstpointer bsearch_node2)
2176 const PropertyValue *val1 = bsearch_node1;
2177 const PropertyValue *val2 = bsearch_node2;
2179 if (val1->widget_type != val2->widget_type)
2180 return val1->widget_type < val2->widget_type ? -1 : 1;
2182 if (val1->pspec != val2->pspec)
2183 return val1->pspec < val2->pspec ? -1 : 1;
2185 if (val1->state != val2->state)
2186 return val1->state < val2->state ? -1 : 1;
2192 _gtk_style_context_peek_property (GtkStyleContext *context,
2193 const char *property_name)
2195 StyleData *data = style_data_lookup (context, gtk_style_context_get_state (context));
2197 return _gtk_css_computed_values_get_value_by_name (data->store, property_name);
2201 _gtk_style_context_get_number (GtkStyleContext *context,
2202 const char *property_name,
2203 double one_hundred_percent)
2207 value = _gtk_style_context_peek_property (context, property_name);
2208 return _gtk_css_number_get (_gtk_css_value_get_number (value), one_hundred_percent);
2212 _gtk_style_context_peek_style_property (GtkStyleContext *context,
2214 GtkStateFlags state,
2217 GtkStyleContextPrivate *priv;
2218 PropertyValue *pcache, key = { 0 };
2222 priv = context->priv;
2223 data = style_data_lookup (context, state);
2225 key.widget_type = widget_type;
2229 /* need value cache array */
2230 if (!data->property_cache)
2231 data->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
2234 pcache = bsearch (&key,
2235 data->property_cache->data, data->property_cache->len,
2236 sizeof (PropertyValue), style_property_values_cmp);
2238 return &pcache->value;
2242 while (i < data->property_cache->len &&
2243 style_property_values_cmp (&key, &g_array_index (data->property_cache, PropertyValue, i)) >= 0)
2246 g_array_insert_val (data->property_cache, i, key);
2247 pcache = &g_array_index (data->property_cache, PropertyValue, i);
2249 /* cache miss, initialize value type, then set contents */
2250 g_param_spec_ref (pcache->pspec);
2251 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2253 if (priv->widget || priv->widget_path)
2255 if (gtk_style_provider_get_style_property (GTK_STYLE_PROVIDER (priv->cascade),
2256 priv->widget ? gtk_widget_get_path (priv->widget)
2257 : priv->widget_path,
2258 state, pspec, &pcache->value))
2260 /* Resolve symbolic colors to GdkColor/GdkRGBA */
2261 if (G_VALUE_TYPE (&pcache->value) == GTK_TYPE_SYMBOLIC_COLOR)
2263 GtkSymbolicColor *color;
2266 color = g_value_dup_boxed (&pcache->value);
2268 g_value_unset (&pcache->value);
2270 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2271 g_value_init (&pcache->value, GDK_TYPE_RGBA);
2273 g_value_init (&pcache->value, GDK_TYPE_COLOR);
2275 if (_gtk_style_context_resolve_color (context, color, &rgba))
2277 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2278 g_value_set_boxed (&pcache->value, &rgba);
2283 rgb.red = rgba.red * 65535. + 0.5;
2284 rgb.green = rgba.green * 65535. + 0.5;
2285 rgb.blue = rgba.blue * 65535. + 0.5;
2287 g_value_set_boxed (&pcache->value, &rgb);
2291 g_param_value_set_default (pspec, &pcache->value);
2293 gtk_symbolic_color_unref (color);
2296 return &pcache->value;
2300 /* not supplied by any provider, revert to default */
2301 g_param_value_set_default (pspec, &pcache->value);
2303 return &pcache->value;
2307 * gtk_style_context_get_style_property:
2308 * @context: a #GtkStyleContext
2309 * @property_name: the name of the widget style property
2310 * @value: Return location for the property value
2312 * Gets the value for a widget style property.
2314 * When @value is no longer needed, g_value_unset() must be called
2315 * to free any allocated memory.
2318 gtk_style_context_get_style_property (GtkStyleContext *context,
2319 const gchar *property_name,
2322 GtkStyleContextPrivate *priv;
2323 GtkWidgetClass *widget_class;
2324 GtkStateFlags state;
2326 const GValue *peek_value;
2329 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2330 g_return_if_fail (property_name != NULL);
2331 g_return_if_fail (value != NULL);
2333 priv = context->priv;
2337 widget_type = G_OBJECT_TYPE (priv->widget);
2341 if (!priv->widget_path)
2344 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2346 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2348 g_warning ("%s: can't get style properties for non-widget class `%s'",
2350 g_type_name (widget_type));
2355 widget_class = g_type_class_ref (widget_type);
2356 pspec = gtk_widget_class_find_style_property (widget_class, property_name);
2357 g_type_class_unref (widget_class);
2361 g_warning ("%s: widget class `%s' has no style property named `%s'",
2363 g_type_name (widget_type),
2368 state = gtk_style_context_get_state (context);
2369 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2372 if (G_VALUE_TYPE (value) == G_VALUE_TYPE (peek_value))
2373 g_value_copy (peek_value, value);
2374 else if (g_value_type_transformable (G_VALUE_TYPE (peek_value), G_VALUE_TYPE (value)))
2375 g_value_transform (peek_value, value);
2377 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
2379 G_VALUE_TYPE_NAME (peek_value),
2380 G_VALUE_TYPE_NAME (value));
2384 * gtk_style_context_get_style_valist:
2385 * @context: a #GtkStyleContext
2386 * @args: va_list of property name/return location pairs, followed by %NULL
2388 * Retrieves several widget style properties from @context according to the
2394 gtk_style_context_get_style_valist (GtkStyleContext *context,
2397 GtkStyleContextPrivate *priv;
2398 const gchar *prop_name;
2399 GtkStateFlags state;
2402 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2404 prop_name = va_arg (args, const gchar *);
2405 priv = context->priv;
2409 widget_type = G_OBJECT_TYPE (priv->widget);
2413 if (!priv->widget_path)
2416 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2418 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2420 g_warning ("%s: can't get style properties for non-widget class `%s'",
2422 g_type_name (widget_type));
2427 state = gtk_style_context_get_state (context);
2431 GtkWidgetClass *widget_class;
2433 const GValue *peek_value;
2436 widget_class = g_type_class_ref (widget_type);
2437 pspec = gtk_widget_class_find_style_property (widget_class, prop_name);
2438 g_type_class_unref (widget_class);
2442 g_warning ("%s: widget class `%s' has no style property named `%s'",
2444 g_type_name (widget_type),
2449 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2452 G_VALUE_LCOPY (peek_value, args, 0, &error);
2456 g_warning ("can't retrieve style property `%s' of type `%s': %s",
2458 G_VALUE_TYPE_NAME (peek_value),
2463 prop_name = va_arg (args, const gchar *);
2468 * gtk_style_context_get_style:
2469 * @context: a #GtkStyleContext
2470 * @...: property name /return value pairs, followed by %NULL
2472 * Retrieves several widget style properties from @context according to the
2478 gtk_style_context_get_style (GtkStyleContext *context,
2483 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2485 va_start (args, context);
2486 gtk_style_context_get_style_valist (context, args);
2492 * gtk_style_context_lookup_icon_set:
2493 * @context: a #GtkStyleContext
2494 * @stock_id: an icon name
2496 * Looks up @stock_id in the icon factories associated to @context and
2497 * the default icon factory, returning an icon set if found, otherwise
2500 * Returns: (transfer none): The looked up %GtkIconSet, or %NULL
2503 gtk_style_context_lookup_icon_set (GtkStyleContext *context,
2504 const gchar *stock_id)
2506 GtkStyleContextPrivate *priv;
2508 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2509 g_return_val_if_fail (stock_id != NULL, NULL);
2511 priv = context->priv;
2512 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
2514 return gtk_icon_factory_lookup_default (stock_id);
2518 * gtk_style_context_set_screen:
2519 * @context: a #GtkStyleContext
2520 * @screen: a #GdkScreen
2522 * Attaches @context to the given screen.
2524 * The screen is used to add style information from 'global' style
2525 * providers, such as the screens #GtkSettings instance.
2527 * If you are using a #GtkStyleContext returned from
2528 * gtk_widget_get_style_context(), you do not need to
2529 * call this yourself.
2534 gtk_style_context_set_screen (GtkStyleContext *context,
2537 GtkStyleContextPrivate *priv;
2539 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2540 g_return_if_fail (GDK_IS_SCREEN (screen));
2542 priv = context->priv;
2543 if (priv->screen == screen)
2546 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
2548 g_object_unref (priv->cascade);
2549 priv->cascade = _gtk_style_cascade_get_for_screen (screen);
2550 g_object_ref (priv->cascade);
2554 _gtk_style_cascade_set_parent (priv->cascade, _gtk_style_cascade_get_for_screen (screen));
2557 priv->screen = screen;
2559 g_object_notify (G_OBJECT (context), "screen");
2561 gtk_style_context_invalidate (context);
2565 * gtk_style_context_get_screen:
2566 * @context: a #GtkStyleContext
2568 * Returns the #GdkScreen to which @context is attached.
2570 * Returns: (transfer none): a #GdkScreen.
2573 gtk_style_context_get_screen (GtkStyleContext *context)
2575 GtkStyleContextPrivate *priv;
2577 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2579 priv = context->priv;
2580 return priv->screen;
2584 * gtk_style_context_set_direction:
2585 * @context: a #GtkStyleContext
2586 * @direction: the new direction.
2588 * Sets the reading direction for rendering purposes.
2590 * If you are using a #GtkStyleContext returned from
2591 * gtk_widget_get_style_context(), you do not need to
2592 * call this yourself.
2597 gtk_style_context_set_direction (GtkStyleContext *context,
2598 GtkTextDirection direction)
2600 GtkStyleContextPrivate *priv;
2602 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2604 priv = context->priv;
2605 priv->direction = direction;
2607 g_object_notify (G_OBJECT (context), "direction");
2611 * gtk_style_context_get_direction:
2612 * @context: a #GtkStyleContext
2614 * Returns the widget direction used for rendering.
2616 * Returns: the widget direction
2621 gtk_style_context_get_direction (GtkStyleContext *context)
2623 GtkStyleContextPrivate *priv;
2625 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), GTK_TEXT_DIR_LTR);
2627 priv = context->priv;
2628 return priv->direction;
2632 * gtk_style_context_set_junction_sides:
2633 * @context: a #GtkStyleContext
2634 * @sides: sides where rendered elements are visually connected to
2637 * Sets the sides where rendered elements (mostly through
2638 * gtk_render_frame()) will visually connect with other visual elements.
2640 * This is merely a hint that may or may not be honored
2641 * by theming engines.
2643 * Container widgets are expected to set junction hints as appropriate
2644 * for their children, so it should not normally be necessary to call
2645 * this function manually.
2650 gtk_style_context_set_junction_sides (GtkStyleContext *context,
2651 GtkJunctionSides sides)
2653 GtkStyleContextPrivate *priv;
2656 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2658 priv = context->priv;
2659 info = priv->info_stack->data;
2660 info->junction_sides = sides;
2664 * gtk_style_context_get_junction_sides:
2665 * @context: a #GtkStyleContext
2667 * Returns the sides where rendered elements connect visually with others.
2669 * Returns: the junction sides
2674 gtk_style_context_get_junction_sides (GtkStyleContext *context)
2676 GtkStyleContextPrivate *priv;
2679 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
2681 priv = context->priv;
2682 info = priv->info_stack->data;
2683 return info->junction_sides;
2686 static GtkSymbolicColor *
2687 gtk_style_context_color_lookup_func (gpointer contextp,
2690 GtkStyleContext *context = contextp;
2692 return _gtk_style_provider_private_get_color (GTK_STYLE_PROVIDER_PRIVATE (context->priv->cascade), name);
2696 _gtk_style_context_resolve_color_value (GtkStyleContext *context,
2697 GtkSymbolicColor *color)
2699 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2700 g_return_val_if_fail (color != NULL, FALSE);
2702 return _gtk_symbolic_color_resolve_full (color,
2703 gtk_style_context_color_lookup_func,
2709 _gtk_style_context_resolve_color (GtkStyleContext *context,
2710 GtkSymbolicColor *color,
2715 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2716 g_return_val_if_fail (color != NULL, FALSE);
2717 g_return_val_if_fail (result != NULL, FALSE);
2719 val = _gtk_symbolic_color_resolve_full (color,
2720 gtk_style_context_color_lookup_func,
2725 *result = *_gtk_css_value_get_rgba (val);
2726 _gtk_css_value_unref (val);
2731 * gtk_style_context_lookup_color:
2732 * @context: a #GtkStyleContext
2733 * @color_name: color name to lookup
2734 * @color: (out): Return location for the looked up color
2736 * Looks up and resolves a color name in the @context color map.
2738 * Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
2741 gtk_style_context_lookup_color (GtkStyleContext *context,
2742 const gchar *color_name,
2745 GtkSymbolicColor *sym_color;
2747 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2748 g_return_val_if_fail (color_name != NULL, FALSE);
2749 g_return_val_if_fail (color != NULL, FALSE);
2751 sym_color = gtk_style_context_color_lookup_func (context, color_name);
2752 if (sym_color == NULL)
2755 return _gtk_style_context_resolve_color (context, sym_color, color);
2759 * gtk_style_context_notify_state_change:
2760 * @context: a #GtkStyleContext
2761 * @window: a #GdkWindow
2762 * @region_id: (allow-none): animatable region to notify on, or %NULL.
2763 * See gtk_style_context_push_animatable_region()
2764 * @state: state to trigger transition for
2765 * @state_value: %TRUE if @state is the state we are changing to,
2766 * %FALSE if we are changing away from it
2768 * Notifies a state change on @context, so if the current style makes use
2769 * of transition animations, one will be started so all rendered elements
2770 * under @region_id are animated for state @state being set to value
2773 * The @window parameter is used in order to invalidate the rendered area
2774 * as the animation runs, so make sure it is the same window that is being
2775 * rendered on by the gtk_render_*() functions.
2777 * If @region_id is %NULL, all rendered elements using @context will be
2778 * affected by this state transition.
2780 * As a practical example, a #GtkButton notifying a state transition on
2781 * the prelight state:
2783 * gtk_style_context_notify_state_change (context,
2784 * gtk_widget_get_window (widget),
2786 * GTK_STATE_PRELIGHT,
2787 * button->in_button);
2790 * Can be handled in the CSS file like this:
2793 * background-color: #f00
2797 * background-color: #fff;
2798 * transition: 200ms linear
2802 * This combination will animate the button background from red to white
2803 * if a pointer enters the button, and back to red if the pointer leaves
2806 * Note that @state is used when finding the transition parameters, which
2807 * is why the style places the transition under the :hover pseudo-class.
2812 gtk_style_context_notify_state_change (GtkStyleContext *context,
2816 gboolean state_value)
2818 GtkStyleContextPrivate *priv;
2819 GtkAnimationDescription *desc;
2820 AnimationInfo *info;
2821 GtkStateFlags flags;
2825 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2826 g_return_if_fail (GDK_IS_WINDOW (window));
2827 g_return_if_fail (state > GTK_STATE_NORMAL && state <= GTK_STATE_FOCUSED);
2829 priv = context->priv;
2830 g_return_if_fail (priv->widget != NULL || priv->widget_path != NULL);
2832 state_value = (state_value == TRUE);
2836 case GTK_STATE_ACTIVE:
2837 flags = GTK_STATE_FLAG_ACTIVE;
2839 case GTK_STATE_PRELIGHT:
2840 flags = GTK_STATE_FLAG_PRELIGHT;
2842 case GTK_STATE_SELECTED:
2843 flags = GTK_STATE_FLAG_SELECTED;
2845 case GTK_STATE_INSENSITIVE:
2846 flags = GTK_STATE_FLAG_INSENSITIVE;
2848 case GTK_STATE_INCONSISTENT:
2849 flags = GTK_STATE_FLAG_INCONSISTENT;
2851 case GTK_STATE_FOCUSED:
2852 flags = GTK_STATE_FLAG_FOCUSED;
2854 case GTK_STATE_NORMAL:
2860 /* Find out if there is any animation description for the given
2861 * state, it will fallback to the normal state as well if necessary.
2863 data = style_data_lookup (context, flags);
2864 v = _gtk_css_computed_values_get_value_by_name (data->store, "transition");
2867 desc = _gtk_css_value_get_boxed (v);
2871 if (_gtk_animation_description_get_duration (desc) == 0)
2874 info = animation_info_lookup (context, region_id, state);
2877 info->target_value != state_value)
2879 /* Target values are the opposite */
2880 if (!_gtk_timeline_get_loop (info->timeline))
2882 /* Reverse the animation */
2883 if (_gtk_timeline_get_direction (info->timeline) == GTK_TIMELINE_DIRECTION_FORWARD)
2884 _gtk_timeline_set_direction (info->timeline, GTK_TIMELINE_DIRECTION_BACKWARD);
2886 _gtk_timeline_set_direction (info->timeline, GTK_TIMELINE_DIRECTION_FORWARD);
2888 info->target_value = state_value;
2892 /* Take it out of its looping state */
2893 _gtk_timeline_set_loop (info->timeline, FALSE);
2897 (!_gtk_animation_description_get_loop (desc) ||
2900 info = animation_info_new (context, region_id,
2901 _gtk_animation_description_get_duration (desc),
2902 _gtk_animation_description_get_progress_type (desc),
2903 _gtk_animation_description_get_loop (desc),
2904 state, state_value, window);
2906 priv->animations = g_slist_prepend (priv->animations, info);
2907 priv->animations_invalidated = TRUE;
2912 * gtk_style_context_cancel_animations:
2913 * @context: a #GtkStyleContext
2914 * @region_id: (allow-none): animatable region to stop, or %NULL.
2915 * See gtk_style_context_push_animatable_region()
2917 * Stops all running animations for @region_id and all animatable
2918 * regions underneath.
2920 * A %NULL @region_id will stop all ongoing animations in @context,
2921 * when dealing with a #GtkStyleContext obtained through
2922 * gtk_widget_get_style_context(), this is normally done for you
2923 * in all circumstances you would expect all widget to be stopped,
2924 * so this should be only used in complex widgets with different
2925 * animatable regions.
2930 gtk_style_context_cancel_animations (GtkStyleContext *context,
2933 GtkStyleContextPrivate *priv;
2934 AnimationInfo *info;
2937 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2939 priv = context->priv;
2940 l = priv->animations;
2948 info->region_id == region_id ||
2949 g_slist_find (info->parent_regions, region_id))
2951 priv->animations = g_slist_remove (priv->animations, info);
2952 animation_info_free (info);
2958 is_parent_of (GdkWindow *parent,
2961 GtkWidget *child_widget, *parent_widget;
2964 gdk_window_get_user_data (child, (gpointer *) &child_widget);
2965 gdk_window_get_user_data (parent, (gpointer *) &parent_widget);
2967 if (child_widget != parent_widget &&
2968 !gtk_widget_is_ancestor (child_widget, parent_widget))
2975 if (window == parent)
2978 window = gdk_window_get_parent (window);
2985 * gtk_style_context_scroll_animations:
2986 * @context: a #GtkStyleContext
2987 * @window: a #GdkWindow used previously in
2988 * gtk_style_context_notify_state_change()
2989 * @dx: Amount to scroll in the X axis
2990 * @dy: Amount to scroll in the Y axis
2992 * This function is analogous to gdk_window_scroll(), and
2993 * should be called together with it so the invalidation
2994 * areas for any ongoing animation are scrolled together
3000 gtk_style_context_scroll_animations (GtkStyleContext *context,
3005 GtkStyleContextPrivate *priv;
3006 AnimationInfo *info;
3009 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3010 g_return_if_fail (GDK_IS_WINDOW (window));
3012 priv = context->priv;
3013 l = priv->animations;
3020 if (info->invalidation_region &&
3021 (window == info->window ||
3022 is_parent_of (window, info->window)))
3023 cairo_region_translate (info->invalidation_region, dx, dy);
3028 * gtk_style_context_push_animatable_region:
3029 * @context: a #GtkStyleContext
3030 * @region_id: unique identifier for the animatable region
3032 * Pushes an animatable region, so all further gtk_render_*() calls between
3033 * this call and the following gtk_style_context_pop_animatable_region()
3034 * will potentially show transition animations for this region if
3035 * gtk_style_context_notify_state_change() is called for a given state,
3036 * and the current theme/style defines transition animations for state
3039 * The @region_id used must be unique in @context so the theming engine
3040 * can uniquely identify rendered elements subject to a state transition.
3045 gtk_style_context_push_animatable_region (GtkStyleContext *context,
3048 GtkStyleContextPrivate *priv;
3050 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3051 g_return_if_fail (region_id != NULL);
3053 priv = context->priv;
3054 priv->animation_regions = g_slist_prepend (priv->animation_regions, region_id);
3058 * gtk_style_context_pop_animatable_region:
3059 * @context: a #GtkStyleContext
3061 * Pops an animatable region from @context.
3062 * See gtk_style_context_push_animatable_region().
3067 gtk_style_context_pop_animatable_region (GtkStyleContext *context)
3069 GtkStyleContextPrivate *priv;
3071 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3073 priv = context->priv;
3074 priv->animation_regions = g_slist_delete_link (priv->animation_regions,
3075 priv->animation_regions);
3079 _gtk_style_context_invalidate_animation_areas (GtkStyleContext *context)
3081 GtkStyleContextPrivate *priv;
3084 priv = context->priv;
3086 for (l = priv->animations; l; l = l->next)
3088 AnimationInfo *info;
3092 /* A NULL invalidation region means it has to be recreated on
3093 * the next expose event, this happens usually after a widget
3094 * allocation change, so the next expose after it will update
3095 * the invalidation region.
3097 if (info->invalidation_region)
3099 cairo_region_destroy (info->invalidation_region);
3100 info->invalidation_region = NULL;
3104 priv->animations_invalidated = TRUE;
3108 _gtk_style_context_coalesce_animation_areas (GtkStyleContext *context,
3111 GtkStyleContextPrivate *priv;
3114 priv = context->priv;
3116 if (!priv->animations_invalidated)
3119 l = priv->animations;
3123 AnimationInfo *info;
3132 if (info->invalidation_region)
3135 if (info->rectangles->len == 0)
3138 info->invalidation_region = cairo_region_create ();
3139 _gtk_widget_get_translation_to_window (widget, info->window, &rel_x, &rel_y);
3141 for (i = 0; i < info->rectangles->len; i++)
3143 cairo_rectangle_int_t *rect;
3145 rect = &g_array_index (info->rectangles, cairo_rectangle_int_t, i);
3147 /* These are widget relative coordinates,
3148 * so have them inverted to be window relative
3153 cairo_region_union_rectangle (info->invalidation_region, rect);
3156 g_array_remove_range (info->rectangles, 0, info->rectangles->len);
3159 priv->animations_invalidated = FALSE;
3163 store_animation_region (GtkStyleContext *context,
3169 GtkStyleContextPrivate *priv;
3172 priv = context->priv;
3174 if (!priv->animations_invalidated)
3177 for (l = priv->animations; l; l = l->next)
3179 AnimationInfo *info;
3183 /* The animation doesn't need updating
3184 * the invalidation area, bail out.
3186 if (info->invalidation_region)
3189 if (context_has_animatable_region (context, info->region_id))
3191 cairo_rectangle_int_t rect;
3195 rect.width = (gint) width;
3196 rect.height = (gint) height;
3198 g_array_append_val (info->rectangles, rect);
3200 if (!info->parent_regions)
3202 GSList *parent_regions;
3204 parent_regions = g_slist_find (priv->animation_regions, info->region_id);
3205 info->parent_regions = g_slist_copy (parent_regions);
3212 _gtk_style_context_queue_invalidate (GtkStyleContext *context,
3213 GtkCssChange change)
3215 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3216 g_return_if_fail (change != 0);
3218 gtk_style_context_invalidate (context);
3222 * gtk_style_context_invalidate:
3223 * @context: a #GtkStyleContext.
3225 * Invalidates @context style information, so it will be reconstructed
3228 * If you're using a #GtkStyleContext returned from
3229 * gtk_widget_get_style_context(), you do not need to
3230 * call this yourself.
3235 gtk_style_context_invalidate (GtkStyleContext *context)
3237 GtkStyleContextPrivate *priv;
3239 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3241 priv = context->priv;
3243 /* Avoid reentrancy */
3244 if (priv->invalidating_context)
3247 priv->invalidating_context = TRUE;
3249 g_hash_table_remove_all (priv->style_data);
3250 priv->current_data = NULL;
3252 g_signal_emit (context, signals[CHANGED], 0);
3254 priv->invalidating_context = FALSE;
3258 * gtk_style_context_set_background:
3259 * @context: a #GtkStyleContext
3260 * @window: a #GdkWindow
3262 * Sets the background of @window to the background pattern or
3263 * color specified in @context for its current state.
3268 gtk_style_context_set_background (GtkStyleContext *context,
3271 GtkStateFlags state;
3272 cairo_pattern_t *pattern;
3275 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3276 g_return_if_fail (GDK_IS_WINDOW (window));
3278 state = gtk_style_context_get_state (context);
3279 gtk_style_context_get (context, state,
3280 "background-image", &pattern,
3284 gdk_window_set_background_pattern (window, pattern);
3285 cairo_pattern_destroy (pattern);
3289 gtk_style_context_get (context, state,
3290 "background-color", &color,
3294 gdk_window_set_background_rgba (window, color);
3295 gdk_rgba_free (color);
3300 * gtk_style_context_get_color:
3301 * @context: a #GtkStyleContext
3302 * @state: state to retrieve the color for
3303 * @color: (out): return value for the foreground color
3305 * Gets the foreground color for a given state.
3310 gtk_style_context_get_color (GtkStyleContext *context,
3311 GtkStateFlags state,
3316 g_return_if_fail (color != NULL);
3317 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3319 gtk_style_context_get (context,
3329 * gtk_style_context_get_background_color:
3330 * @context: a #GtkStyleContext
3331 * @state: state to retrieve the color for
3332 * @color: (out): return value for the background color
3334 * Gets the background color for a given state.
3339 gtk_style_context_get_background_color (GtkStyleContext *context,
3340 GtkStateFlags state,
3345 g_return_if_fail (color != NULL);
3346 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3348 gtk_style_context_get (context,
3350 "background-color", &c,
3358 * gtk_style_context_get_border_color:
3359 * @context: a #GtkStyleContext
3360 * @state: state to retrieve the color for
3361 * @color: (out): return value for the border color
3363 * Gets the border color for a given state.
3368 gtk_style_context_get_border_color (GtkStyleContext *context,
3369 GtkStateFlags state,
3374 g_return_if_fail (color != NULL);
3375 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3377 gtk_style_context_get (context,
3387 * gtk_style_context_get_border:
3388 * @context: a #GtkStyleContext
3389 * @state: state to retrieve the border for
3390 * @border: (out): return value for the border settings
3392 * Gets the border for a given state as a #GtkBorder.
3393 * See %GTK_STYLE_PROPERTY_BORDER_WIDTH.
3398 gtk_style_context_get_border (GtkStyleContext *context,
3399 GtkStateFlags state,
3402 int top, left, bottom, right;
3404 g_return_if_fail (border != NULL);
3405 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3407 gtk_style_context_get (context,
3409 "border-top-width", &top,
3410 "border-left-width", &left,
3411 "border-bottom-width", &bottom,
3412 "border-right-width", &right,
3416 border->left = left;
3417 border->bottom = bottom;
3418 border->right = right;
3422 * gtk_style_context_get_padding:
3423 * @context: a #GtkStyleContext
3424 * @state: state to retrieve the padding for
3425 * @padding: (out): return value for the padding settings
3427 * Gets the padding for a given state as a #GtkBorder.
3428 * See %GTK_STYLE_PROPERTY_PADDING.
3433 gtk_style_context_get_padding (GtkStyleContext *context,
3434 GtkStateFlags state,
3437 int top, left, bottom, right;
3439 g_return_if_fail (padding != NULL);
3440 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3442 gtk_style_context_get (context,
3444 "padding-top", &top,
3445 "padding-left", &left,
3446 "padding-bottom", &bottom,
3447 "padding-right", &right,
3451 padding->left = left;
3452 padding->bottom = bottom;
3453 padding->right = right;
3457 * gtk_style_context_get_margin:
3458 * @context: a #GtkStyleContext
3459 * @state: state to retrieve the border for
3460 * @margin: (out): return value for the margin settings
3462 * Gets the margin for a given state as a #GtkBorder.
3463 * See %GTK_STYLE_PROPERTY_MARGIN.
3468 gtk_style_context_get_margin (GtkStyleContext *context,
3469 GtkStateFlags state,
3472 int top, left, bottom, right;
3474 g_return_if_fail (margin != NULL);
3475 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3477 gtk_style_context_get (context,
3480 "margin-left", &left,
3481 "margin-bottom", &bottom,
3482 "margin-right", &right,
3486 margin->left = left;
3487 margin->bottom = bottom;
3488 margin->right = right;
3492 * gtk_style_context_get_font:
3493 * @context: a #GtkStyleContext
3494 * @state: state to retrieve the font for
3496 * Returns the font description for a given state. The returned
3497 * object is const and will remain valid until the
3498 * #GtkStyleContext::changed signal happens.
3500 * Returns: (transfer none): the #PangoFontDescription for the given
3501 * state. This object is owned by GTK+ and should not be
3506 const PangoFontDescription *
3507 gtk_style_context_get_font (GtkStyleContext *context,
3508 GtkStateFlags state)
3510 GtkStyleContextPrivate *priv;
3512 PangoFontDescription *description;
3514 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
3516 priv = context->priv;
3517 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
3519 data = style_data_lookup (context, state);
3521 /* Yuck, fonts are created on-demand but we don't return a ref.
3522 * Do bad things to achieve this requirement */
3523 description = g_object_get_data (G_OBJECT (data->store), "font-cache-for-get_font");
3524 if (description == NULL)
3526 gtk_style_context_get (context, state, "font", &description, NULL);
3527 g_object_set_data_full (G_OBJECT (data->store),
3528 "font-cache-for-get_font",
3530 (GDestroyNotify) pango_font_description_free);
3536 get_cursor_color (GtkStyleContext *context,
3540 GdkColor *style_color;
3542 gtk_style_context_get_style (context,
3543 primary ? "cursor-color" : "secondary-cursor-color",
3549 color->red = style_color->red / 65535.0;
3550 color->green = style_color->green / 65535.0;
3551 color->blue = style_color->blue / 65535.0;
3554 gdk_color_free (style_color);
3558 gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, color);
3564 gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &bg);
3566 color->red = (color->red + bg.red) * 0.5;
3567 color->green = (color->green + bg.green) * 0.5;
3568 color->blue = (color->blue + bg.blue) * 0.5;
3574 _gtk_style_context_get_cursor_color (GtkStyleContext *context,
3575 GdkRGBA *primary_color,
3576 GdkRGBA *secondary_color)
3579 get_cursor_color (context, TRUE, primary_color);
3581 if (secondary_color)
3582 get_cursor_color (context, FALSE, secondary_color);
3589 * @context: a #GtkStyleContext
3591 * @x: X origin of the rectangle
3592 * @y: Y origin of the rectangle
3593 * @width: rectangle width
3594 * @height: rectangle height
3596 * Renders a checkmark (as in a #GtkCheckButton).
3598 * The %GTK_STATE_FLAG_ACTIVE state determines whether the check is
3599 * on or off, and %GTK_STATE_FLAG_INCONSISTENT determines whether it
3600 * should be marked as undefined.
3603 * <title>Typical checkmark rendering</title>
3604 * <inlinegraphic fileref="checks.png" format="PNG"/>
3610 gtk_render_check (GtkStyleContext *context,
3617 GtkStyleContextPrivate *priv;
3618 GtkThemingEngineClass *engine_class;
3620 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3621 g_return_if_fail (cr != NULL);
3623 if (width <= 0 || height <= 0)
3626 priv = context->priv;
3627 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3631 store_animation_region (context, x, y, width, height);
3633 _gtk_theming_engine_set_context (priv->theming_engine, context);
3634 engine_class->render_check (priv->theming_engine, cr,
3635 x, y, width, height);
3641 * gtk_render_option:
3642 * @context: a #GtkStyleContext
3644 * @x: X origin of the rectangle
3645 * @y: Y origin of the rectangle
3646 * @width: rectangle width
3647 * @height: rectangle height
3649 * Renders an option mark (as in a #GtkRadioButton), the %GTK_STATE_FLAG_ACTIVE
3650 * state will determine whether the option is on or off, and
3651 * %GTK_STATE_FLAG_INCONSISTENT whether it should be marked as undefined.
3654 * <title>Typical option mark rendering</title>
3655 * <inlinegraphic fileref="options.png" format="PNG"/>
3661 gtk_render_option (GtkStyleContext *context,
3668 GtkStyleContextPrivate *priv;
3669 GtkThemingEngineClass *engine_class;
3671 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3672 g_return_if_fail (cr != NULL);
3674 if (width <= 0 || height <= 0)
3677 priv = context->priv;
3678 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3682 store_animation_region (context, x, y, width, height);
3684 _gtk_theming_engine_set_context (priv->theming_engine, context);
3685 engine_class->render_option (priv->theming_engine, cr,
3686 x, y, width, height);
3693 * @context: a #GtkStyleContext
3695 * @angle: arrow angle from 0 to 2 * %G_PI, being 0 the arrow pointing to the north
3696 * @x: X origin of the render area
3697 * @y: Y origin of the render area
3698 * @size: square side for render area
3700 * Renders an arrow pointing to @angle.
3703 * <title>Typical arrow rendering at 0, 1&solidus;2 π, π and 3&solidus;2 π</title>
3704 * <inlinegraphic fileref="arrows.png" format="PNG"/>
3710 gtk_render_arrow (GtkStyleContext *context,
3717 GtkStyleContextPrivate *priv;
3718 GtkThemingEngineClass *engine_class;
3720 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3721 g_return_if_fail (cr != NULL);
3726 priv = context->priv;
3727 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3731 gtk_style_context_save (context);
3732 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ARROW);
3734 store_animation_region (context, x, y, size, size);
3736 _gtk_theming_engine_set_context (priv->theming_engine, context);
3737 engine_class->render_arrow (priv->theming_engine, cr,
3740 gtk_style_context_restore (context);
3745 * gtk_render_background:
3746 * @context: a #GtkStyleContext
3748 * @x: X origin of the rectangle
3749 * @y: Y origin of the rectangle
3750 * @width: rectangle width
3751 * @height: rectangle height
3753 * Renders the background of an element.
3756 * <title>Typical background rendering, showing the effect of
3757 * <parameter>background-image</parameter>,
3758 * <parameter>border-width</parameter> and
3759 * <parameter>border-radius</parameter></title>
3760 * <inlinegraphic fileref="background.png" format="PNG"/>
3766 gtk_render_background (GtkStyleContext *context,
3773 GtkStyleContextPrivate *priv;
3774 GtkThemingEngineClass *engine_class;
3776 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3777 g_return_if_fail (cr != NULL);
3779 if (width <= 0 || height <= 0)
3782 priv = context->priv;
3783 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3787 store_animation_region (context, x, y, width, height);
3789 _gtk_theming_engine_set_context (priv->theming_engine, context);
3790 engine_class->render_background (priv->theming_engine, cr, x, y, width, height);
3797 * @context: a #GtkStyleContext
3799 * @x: X origin of the rectangle
3800 * @y: Y origin of the rectangle
3801 * @width: rectangle width
3802 * @height: rectangle height
3804 * Renders a frame around the rectangle defined by @x, @y, @width, @height.
3807 * <title>Examples of frame rendering, showing the effect of
3808 * <parameter>border-image</parameter>,
3809 * <parameter>border-color</parameter>,
3810 * <parameter>border-width</parameter>,
3811 * <parameter>border-radius</parameter> and
3813 * <inlinegraphic fileref="frames.png" format="PNG"/>
3819 gtk_render_frame (GtkStyleContext *context,
3826 GtkStyleContextPrivate *priv;
3827 GtkThemingEngineClass *engine_class;
3829 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3830 g_return_if_fail (cr != NULL);
3832 if (width <= 0 || height <= 0)
3835 priv = context->priv;
3836 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3840 store_animation_region (context, x, y, width, height);
3842 _gtk_theming_engine_set_context (priv->theming_engine, context);
3843 engine_class->render_frame (priv->theming_engine, cr, x, y, width, height);
3849 * gtk_render_expander:
3850 * @context: a #GtkStyleContext
3852 * @x: X origin of the rectangle
3853 * @y: Y origin of the rectangle
3854 * @width: rectangle width
3855 * @height: rectangle height
3857 * Renders an expander (as used in #GtkTreeView and #GtkExpander) in the area
3858 * defined by @x, @y, @width, @height. The state %GTK_STATE_FLAG_ACTIVE
3859 * determines whether the expander is collapsed or expanded.
3862 * <title>Typical expander rendering</title>
3863 * <inlinegraphic fileref="expanders.png" format="PNG"/>
3869 gtk_render_expander (GtkStyleContext *context,
3876 GtkStyleContextPrivate *priv;
3877 GtkThemingEngineClass *engine_class;
3879 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3880 g_return_if_fail (cr != NULL);
3882 if (width <= 0 || height <= 0)
3885 priv = context->priv;
3886 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3890 store_animation_region (context, x, y, width, height);
3892 _gtk_theming_engine_set_context (priv->theming_engine, context);
3893 engine_class->render_expander (priv->theming_engine, cr, x, y, width, height);
3900 * @context: a #GtkStyleContext
3902 * @x: X origin of the rectangle
3903 * @y: Y origin of the rectangle
3904 * @width: rectangle width
3905 * @height: rectangle height
3907 * Renders a focus indicator on the rectangle determined by @x, @y, @width, @height.
3909 * <title>Typical focus rendering</title>
3910 * <inlinegraphic fileref="focus.png" format="PNG"/>
3916 gtk_render_focus (GtkStyleContext *context,
3923 GtkStyleContextPrivate *priv;
3924 GtkThemingEngineClass *engine_class;
3926 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3927 g_return_if_fail (cr != NULL);
3929 if (width <= 0 || height <= 0)
3932 priv = context->priv;
3933 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3937 store_animation_region (context, x, y, width, height);
3939 _gtk_theming_engine_set_context (priv->theming_engine, context);
3940 engine_class->render_focus (priv->theming_engine, cr, x, y, width, height);
3946 * gtk_render_layout:
3947 * @context: a #GtkStyleContext
3951 * @layout: the #PangoLayout to render
3953 * Renders @layout on the coordinates @x, @y
3958 gtk_render_layout (GtkStyleContext *context,
3962 PangoLayout *layout)
3964 GtkStyleContextPrivate *priv;
3965 GtkThemingEngineClass *engine_class;
3966 PangoRectangle extents;
3968 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3969 g_return_if_fail (PANGO_IS_LAYOUT (layout));
3970 g_return_if_fail (cr != NULL);
3972 priv = context->priv;
3973 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3977 pango_layout_get_extents (layout, &extents, NULL);
3979 store_animation_region (context,
3985 _gtk_theming_engine_set_context (priv->theming_engine, context);
3986 engine_class->render_layout (priv->theming_engine, cr, x, y, layout);
3993 * @context: a #GtkStyleContext
3995 * @x0: X coordinate for the origin of the line
3996 * @y0: Y coordinate for the origin of the line
3997 * @x1: X coordinate for the end of the line
3998 * @y1: Y coordinate for the end of the line
4000 * Renders a line from (x0, y0) to (x1, y1).
4005 gtk_render_line (GtkStyleContext *context,
4012 GtkStyleContextPrivate *priv;
4013 GtkThemingEngineClass *engine_class;
4015 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4016 g_return_if_fail (cr != NULL);
4018 priv = context->priv;
4019 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4023 _gtk_theming_engine_set_context (priv->theming_engine, context);
4024 engine_class->render_line (priv->theming_engine, cr, x0, y0, x1, y1);
4030 * gtk_render_slider:
4031 * @context: a #GtkStyleContext
4033 * @x: X origin of the rectangle
4034 * @y: Y origin of the rectangle
4035 * @width: rectangle width
4036 * @height: rectangle height
4037 * @orientation: orientation of the slider
4039 * Renders a slider (as in #GtkScale) in the rectangle defined by @x, @y,
4040 * @width, @height. @orientation defines whether the slider is vertical
4044 * <title>Typical slider rendering</title>
4045 * <inlinegraphic fileref="sliders.png" format="PNG"/>
4051 gtk_render_slider (GtkStyleContext *context,
4057 GtkOrientation orientation)
4059 GtkStyleContextPrivate *priv;
4060 GtkThemingEngineClass *engine_class;
4062 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4063 g_return_if_fail (cr != NULL);
4065 if (width <= 0 || height <= 0)
4068 priv = context->priv;
4069 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4073 store_animation_region (context, x, y, width, height);
4075 _gtk_theming_engine_set_context (priv->theming_engine, context);
4076 engine_class->render_slider (priv->theming_engine, cr, x, y, width, height, orientation);
4082 * gtk_render_frame_gap:
4083 * @context: a #GtkStyleContext
4085 * @x: X origin of the rectangle
4086 * @y: Y origin of the rectangle
4087 * @width: rectangle width
4088 * @height: rectangle height
4089 * @gap_side: side where the gap is
4090 * @xy0_gap: initial coordinate (X or Y depending on @gap_side) for the gap
4091 * @xy1_gap: end coordinate (X or Y depending on @gap_side) for the gap
4093 * Renders a frame around the rectangle defined by (@x, @y, @width, @height),
4094 * leaving a gap on one side. @xy0_gap and @xy1_gap will mean X coordinates
4095 * for %GTK_POS_TOP and %GTK_POS_BOTTOM gap sides, and Y coordinates for
4096 * %GTK_POS_LEFT and %GTK_POS_RIGHT.
4099 * <title>Typical rendering of a frame with a gap</title>
4100 * <inlinegraphic fileref="frame-gap.png" format="PNG"/>
4106 gtk_render_frame_gap (GtkStyleContext *context,
4112 GtkPositionType gap_side,
4116 GtkStyleContextPrivate *priv;
4117 GtkThemingEngineClass *engine_class;
4119 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4120 g_return_if_fail (cr != NULL);
4121 g_return_if_fail (xy0_gap <= xy1_gap);
4122 g_return_if_fail (xy0_gap >= 0);
4124 if (width <= 0 || height <= 0)
4127 if (gap_side == GTK_POS_LEFT ||
4128 gap_side == GTK_POS_RIGHT)
4129 g_return_if_fail (xy1_gap <= height);
4131 g_return_if_fail (xy1_gap <= width);
4133 priv = context->priv;
4134 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4138 store_animation_region (context, x, y, width, height);
4140 _gtk_theming_engine_set_context (priv->theming_engine, context);
4141 engine_class->render_frame_gap (priv->theming_engine, cr,
4142 x, y, width, height, gap_side,
4149 * gtk_render_extension:
4150 * @context: a #GtkStyleContext
4152 * @x: X origin of the rectangle
4153 * @y: Y origin of the rectangle
4154 * @width: rectangle width
4155 * @height: rectangle height
4156 * @gap_side: side where the gap is
4158 * Renders a extension (as in a #GtkNotebook tab) in the rectangle
4159 * defined by @x, @y, @width, @height. The side where the extension
4160 * connects to is defined by @gap_side.
4163 * <title>Typical extension rendering</title>
4164 * <inlinegraphic fileref="extensions.png" format="PNG"/>
4170 gtk_render_extension (GtkStyleContext *context,
4176 GtkPositionType gap_side)
4178 GtkStyleContextPrivate *priv;
4179 GtkThemingEngineClass *engine_class;
4181 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4182 g_return_if_fail (cr != NULL);
4184 if (width <= 0 || height <= 0)
4187 priv = context->priv;
4188 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4192 store_animation_region (context, x, y, width, height);
4194 _gtk_theming_engine_set_context (priv->theming_engine, context);
4195 engine_class->render_extension (priv->theming_engine, cr, x, y, width, height, gap_side);
4201 * gtk_render_handle:
4202 * @context: a #GtkStyleContext
4204 * @x: X origin of the rectangle
4205 * @y: Y origin of the rectangle
4206 * @width: rectangle width
4207 * @height: rectangle height
4209 * Renders a handle (as in #GtkHandleBox, #GtkPaned and
4210 * #GtkWindow<!-- -->'s resize grip), in the rectangle
4211 * determined by @x, @y, @width, @height.
4214 * <title>Handles rendered for the paned and grip classes</title>
4215 * <inlinegraphic fileref="handles.png" format="PNG"/>
4221 gtk_render_handle (GtkStyleContext *context,
4228 GtkStyleContextPrivate *priv;
4229 GtkThemingEngineClass *engine_class;
4231 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4232 g_return_if_fail (cr != NULL);
4234 if (width <= 0 || height <= 0)
4237 priv = context->priv;
4238 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4242 store_animation_region (context, x, y, width, height);
4244 _gtk_theming_engine_set_context (priv->theming_engine, context);
4245 engine_class->render_handle (priv->theming_engine, cr, x, y, width, height);
4251 * gtk_render_activity:
4252 * @context: a #GtkStyleContext
4254 * @x: X origin of the rectangle
4255 * @y: Y origin of the rectangle
4256 * @width: rectangle width
4257 * @height: rectangle height
4259 * Renders an activity area (Such as in #GtkSpinner or the
4260 * fill line in #GtkRange), the state %GTK_STATE_FLAG_ACTIVE
4261 * determines whether there is activity going on.
4266 gtk_render_activity (GtkStyleContext *context,
4273 GtkStyleContextPrivate *priv;
4274 GtkThemingEngineClass *engine_class;
4276 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4277 g_return_if_fail (cr != NULL);
4279 if (width <= 0 || height <= 0)
4282 priv = context->priv;
4283 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4287 store_animation_region (context, x, y, width, height);
4289 _gtk_theming_engine_set_context (priv->theming_engine, context);
4290 engine_class->render_activity (priv->theming_engine, cr, x, y, width, height);
4296 * gtk_render_icon_pixbuf:
4297 * @context: a #GtkStyleContext
4298 * @source: the #GtkIconSource specifying the icon to render
4299 * @size: (type int): the size to render the icon at. A size of (GtkIconSize) -1
4300 * means render at the size of the source and don't scale.
4302 * Renders the icon specified by @source at the given @size, returning the result
4305 * Returns: (transfer full): a newly-created #GdkPixbuf containing the rendered icon
4310 gtk_render_icon_pixbuf (GtkStyleContext *context,
4311 const GtkIconSource *source,
4314 GtkStyleContextPrivate *priv;
4315 GtkThemingEngineClass *engine_class;
4317 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
4318 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
4319 g_return_val_if_fail (source != NULL, NULL);
4321 priv = context->priv;
4322 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4324 _gtk_theming_engine_set_context (priv->theming_engine, context);
4325 return engine_class->render_icon_pixbuf (priv->theming_engine, source, size);
4330 * @context: a #GtkStyleContext
4332 * @pixbuf: a #GdkPixbuf containing the icon to draw
4333 * @x: X position for the @pixbuf
4334 * @y: Y position for the @pixbuf
4336 * Renders the icon in @pixbuf at the specified @x and @y coordinates.
4341 gtk_render_icon (GtkStyleContext *context,
4347 GtkStyleContextPrivate *priv;
4348 GtkThemingEngineClass *engine_class;
4350 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4351 g_return_if_fail (cr != NULL);
4353 priv = context->priv;
4354 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4358 store_animation_region (context,
4360 gdk_pixbuf_get_width (pixbuf),
4361 gdk_pixbuf_get_height (pixbuf));
4363 _gtk_theming_engine_set_context (priv->theming_engine, context);
4364 engine_class->render_icon (priv->theming_engine, cr, pixbuf, x, y);
4370 draw_insertion_cursor (GtkStyleContext *context,
4375 gboolean is_primary,
4376 PangoDirection direction,
4377 gboolean draw_arrow)
4380 GdkRGBA primary_color;
4381 GdkRGBA secondary_color;
4382 gfloat cursor_aspect_ratio;
4388 _gtk_style_context_get_cursor_color (context, &primary_color, &secondary_color);
4389 gdk_cairo_set_source_rgba (cr, is_primary ? &primary_color : &secondary_color);
4391 /* When changing the shape or size of the cursor here,
4392 * propagate the changes to gtktextview.c:text_window_invalidate_cursors().
4395 gtk_style_context_get_style (context,
4396 "cursor-aspect-ratio", &cursor_aspect_ratio,
4399 stem_width = height * cursor_aspect_ratio + 1;
4401 /* put (stem_width % 2) on the proper side of the cursor */
4402 if (direction == PANGO_DIRECTION_LTR)
4403 offset = stem_width / 2;
4405 offset = stem_width - stem_width / 2;
4407 cairo_rectangle (cr, x - offset, y, stem_width, height);
4415 arrow_width = stem_width + 1;
4417 if (direction == PANGO_DIRECTION_RTL)
4419 ax = x - offset - 1;
4420 ay = y + height - arrow_width * 2 - arrow_width + 1;
4422 cairo_move_to (cr, ax, ay + 1);
4423 cairo_line_to (cr, ax - arrow_width, ay + arrow_width);
4424 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4427 else if (direction == PANGO_DIRECTION_LTR)
4429 ax = x + stem_width - offset;
4430 ay = y + height - arrow_width * 2 - arrow_width + 1;
4432 cairo_move_to (cr, ax, ay + 1);
4433 cairo_line_to (cr, ax + arrow_width, ay + arrow_width);
4434 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4438 g_assert_not_reached();
4445 * gtk_render_insertion_cursor:
4446 * @context: a #GtkStyleContext
4450 * @layout: the #PangoLayout of the text
4451 * @index: the index in the #PangoLayout
4452 * @direction: the #PangoDirection of the text
4454 * Draws a text caret on @cr at the specified index of @layout.
4459 gtk_render_insertion_cursor (GtkStyleContext *context,
4463 PangoLayout *layout,
4465 PangoDirection direction)
4467 GtkStyleContextPrivate *priv;
4468 gboolean split_cursor;
4469 PangoRectangle strong_pos, weak_pos;
4470 PangoRectangle *cursor1, *cursor2;
4471 PangoDirection keymap_direction;
4472 PangoDirection direction2;
4474 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4475 g_return_if_fail (cr != NULL);
4476 g_return_if_fail (PANGO_IS_LAYOUT (layout));
4477 g_return_if_fail (index >= 0);
4479 priv = context->priv;
4481 g_object_get (gtk_settings_get_for_screen (priv->screen),
4482 "gtk-split-cursor", &split_cursor,
4485 keymap_direction = gdk_keymap_get_direction (gdk_keymap_get_for_display (gdk_screen_get_display (priv->screen)));
4487 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4489 direction2 = PANGO_DIRECTION_NEUTRAL;
4493 cursor1 = &strong_pos;
4495 if (strong_pos.x != weak_pos.x || strong_pos.y != weak_pos.y)
4497 direction2 = (direction == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
4498 cursor2 = &weak_pos;
4503 if (keymap_direction == direction)
4504 cursor1 = &strong_pos;
4506 cursor1 = &weak_pos;
4509 draw_insertion_cursor (context,
4511 x + PANGO_PIXELS (cursor1->x),
4512 y + PANGO_PIXELS (cursor1->y),
4513 PANGO_PIXELS (cursor1->height),
4516 direction2 != PANGO_DIRECTION_NEUTRAL);
4518 if (direction2 != PANGO_DIRECTION_NEUTRAL)
4520 draw_insertion_cursor (context,
4522 x + PANGO_PIXELS (cursor2->x),
4523 y + PANGO_PIXELS (cursor2->y),
4524 PANGO_PIXELS (cursor2->height),
4532 * gtk_draw_insertion_cursor:
4533 * @widget: a #GtkWidget
4534 * @cr: cairo context to draw to
4535 * @location: location where to draw the cursor (@location->width is ignored)
4536 * @is_primary: if the cursor should be the primary cursor color.
4537 * @direction: whether the cursor is left-to-right or
4538 * right-to-left. Should never be #GTK_TEXT_DIR_NONE
4539 * @draw_arrow: %TRUE to draw a directional arrow on the
4540 * cursor. Should be %FALSE unless the cursor is split.
4542 * Draws a text caret on @cr at @location. This is not a style function
4543 * but merely a convenience function for drawing the standard cursor shape.
4546 * Deprecated: 3.4: Use gtk_render_insertion_cursor() instead.
4549 gtk_draw_insertion_cursor (GtkWidget *widget,
4551 const GdkRectangle *location,
4552 gboolean is_primary,
4553 GtkTextDirection direction,
4554 gboolean draw_arrow)
4556 GtkStyleContext *context;
4558 g_return_if_fail (GTK_IS_WIDGET (widget));
4559 g_return_if_fail (cr != NULL);
4560 g_return_if_fail (location != NULL);
4561 g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
4563 context = gtk_widget_get_style_context (widget);
4565 draw_insertion_cursor (context, cr,
4566 location->x, location->y, location->height,
4568 (direction == GTK_TEXT_DIR_RTL) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR,
4572 static AtkAttributeSet *
4573 add_attribute (AtkAttributeSet *attributes,
4574 AtkTextAttribute attr,
4579 at = g_new (AtkAttribute, 1);
4580 at->name = g_strdup (atk_text_attribute_get_name (attr));
4581 at->value = g_strdup (value);
4583 return g_slist_prepend (attributes, at);
4587 * _gtk_style_context_get_attributes:
4588 * @attributes: a #AtkAttributeSet to add attributes to
4589 * @context: the #GtkStyleContext to get attributes from
4590 * @flags: the state to use with @context
4592 * Adds the foreground and background color from @context to
4593 * @attributes, after translating them to ATK attributes.
4595 * This is a convenience function that can be used in
4596 * implementing the #AtkText interface in widgets.
4598 * Returns: the modified #AtkAttributeSet
4601 _gtk_style_context_get_attributes (AtkAttributeSet *attributes,
4602 GtkStyleContext *context,
4603 GtkStateFlags flags)
4608 gtk_style_context_get_background_color (context, flags, &color);
4609 value = g_strdup_printf ("%u,%u,%u",
4610 (guint) ceil (color.red * 65536 - color.red),
4611 (guint) ceil (color.green * 65536 - color.green),
4612 (guint) ceil (color.blue * 65536 - color.blue));
4613 attributes = add_attribute (attributes, ATK_TEXT_ATTR_BG_COLOR, value);
4616 gtk_style_context_get_color (context, flags, &color);
4617 value = g_strdup_printf ("%u,%u,%u",
4618 (guint) ceil (color.red * 65536 - color.red),
4619 (guint) ceil (color.green * 65536 - color.green),
4620 (guint) ceil (color.blue * 65536 - color.blue));
4621 attributes = add_attribute (attributes, ATK_TEXT_ATTR_FG_COLOR, value);