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;
364 GtkWidgetPath *widget_path;
365 GHashTable *style_data;
367 StyleData *current_data;
368 GtkStateFlags current_state;
370 GSList *animation_regions;
373 GtkThemingEngine *theming_engine;
375 GtkTextDirection direction;
377 guint animations_invalidated : 1;
378 guint invalidating_context : 1;
393 static guint signals[LAST_SIGNAL] = { 0 };
395 static void gtk_style_context_finalize (GObject *object);
397 static void gtk_style_context_impl_set_property (GObject *object,
401 static void gtk_style_context_impl_get_property (GObject *object,
405 static GtkSymbolicColor *
406 gtk_style_context_color_lookup_func (gpointer contextp,
410 G_DEFINE_TYPE (GtkStyleContext, gtk_style_context, G_TYPE_OBJECT)
413 gtk_style_context_class_init (GtkStyleContextClass *klass)
415 GObjectClass *object_class = G_OBJECT_CLASS (klass);
417 object_class->finalize = gtk_style_context_finalize;
418 object_class->set_property = gtk_style_context_impl_set_property;
419 object_class->get_property = gtk_style_context_impl_get_property;
422 g_signal_new (I_("changed"),
423 G_TYPE_FROM_CLASS (object_class),
425 G_STRUCT_OFFSET (GtkStyleContextClass, changed),
427 g_cclosure_marshal_VOID__VOID,
430 g_object_class_install_property (object_class,
432 g_param_spec_object ("screen",
434 P_("The associated GdkScreen"),
436 GTK_PARAM_READWRITE));
437 g_object_class_install_property (object_class,
439 g_param_spec_enum ("direction",
441 P_("Text direction"),
442 GTK_TYPE_TEXT_DIRECTION,
444 GTK_PARAM_READWRITE));
446 * GtkStyleContext:parent:
448 * Sets or gets the style context's parent. See gtk_style_context_set_parent()
453 g_object_class_install_property (object_class,
455 g_param_spec_object ("parent",
457 P_("The parent style context"),
458 GTK_TYPE_STYLE_CONTEXT,
459 GTK_PARAM_READWRITE));
461 g_type_class_add_private (object_class, sizeof (GtkStyleContextPrivate));
464 static GtkStyleInfo *
465 style_info_new (void)
469 info = g_slice_new0 (GtkStyleInfo);
470 info->style_classes = g_array_new (FALSE, FALSE, sizeof (GQuark));
471 info->regions = g_array_new (FALSE, FALSE, sizeof (GtkRegion));
477 style_info_free (GtkStyleInfo *info)
479 g_array_free (info->style_classes, TRUE);
480 g_array_free (info->regions, TRUE);
481 g_slice_free (GtkStyleInfo, info);
484 static GtkStyleInfo *
485 style_info_copy (const GtkStyleInfo *info)
489 copy = style_info_new ();
490 g_array_insert_vals (copy->style_classes, 0,
491 info->style_classes->data,
492 info->style_classes->len);
494 g_array_insert_vals (copy->regions, 0,
498 copy->junction_sides = info->junction_sides;
499 copy->state_flags = info->state_flags;
505 style_info_hash (gconstpointer elem)
507 const GtkStyleInfo *info;
512 for (i = 0; i < info->style_classes->len; i++)
514 hash += g_array_index (info->style_classes, GQuark, i);
518 for (i = 0; i < info->regions->len; i++)
522 region = &g_array_index (info->regions, GtkRegion, i);
523 hash += region->class_quark;
524 hash += region->flags;
528 return hash ^ info->state_flags;
532 style_info_equal (gconstpointer elem1,
535 const GtkStyleInfo *info1, *info2;
540 if (info1->state_flags != info2->state_flags)
543 if (info1->junction_sides != info2->junction_sides)
546 if (info1->style_classes->len != info2->style_classes->len)
549 if (memcmp (info1->style_classes->data,
550 info2->style_classes->data,
551 info1->style_classes->len * sizeof (GQuark)) != 0)
554 if (info1->regions->len != info2->regions->len)
557 if (memcmp (info1->regions->data,
558 info2->regions->data,
559 info1->regions->len * sizeof (GtkRegion)) != 0)
566 style_data_new (void)
570 data = g_slice_new0 (StyleData);
576 clear_property_cache (StyleData *data)
580 if (!data->property_cache)
583 for (i = 0; i < data->property_cache->len; i++)
585 PropertyValue *node = &g_array_index (data->property_cache, PropertyValue, i);
587 g_param_spec_unref (node->pspec);
588 g_value_unset (&node->value);
591 g_array_free (data->property_cache, TRUE);
592 data->property_cache = NULL;
596 style_data_free (StyleData *data)
598 g_object_unref (data->store);
599 clear_property_cache (data);
601 g_slice_free (StyleData, data);
605 gtk_style_context_init (GtkStyleContext *style_context)
607 GtkStyleContextPrivate *priv;
610 priv = style_context->priv = G_TYPE_INSTANCE_GET_PRIVATE (style_context,
611 GTK_TYPE_STYLE_CONTEXT,
612 GtkStyleContextPrivate);
614 priv->style_data = g_hash_table_new_full (style_info_hash,
616 (GDestroyNotify) style_info_free,
617 (GDestroyNotify) style_data_free);
618 priv->theming_engine = g_object_ref ((gpointer) gtk_theming_engine_load (NULL));
620 priv->direction = GTK_TEXT_DIR_LTR;
622 priv->screen = gdk_screen_get_default ();
623 priv->cascade = _gtk_style_cascade_get_for_screen (priv->screen);
624 g_object_ref (priv->cascade);
626 /* Create default info store */
627 info = style_info_new ();
628 priv->info_stack = g_slist_prepend (priv->info_stack, info);
632 animation_info_free (AnimationInfo *info)
634 g_object_unref (info->timeline);
635 g_object_unref (info->window);
637 if (info->invalidation_region)
638 cairo_region_destroy (info->invalidation_region);
640 g_array_free (info->rectangles, TRUE);
641 g_slist_free (info->parent_regions);
642 g_slice_free (AnimationInfo, info);
645 static AnimationInfo *
646 animation_info_lookup_by_timeline (GtkStyleContext *context,
647 GtkTimeline *timeline)
649 GtkStyleContextPrivate *priv;
653 priv = context->priv;
655 for (l = priv->animations; l; l = l->next)
659 if (info->timeline == timeline)
667 timeline_frame_cb (GtkTimeline *timeline,
671 GtkStyleContextPrivate *priv;
672 GtkStyleContext *context;
676 priv = context->priv;
677 info = animation_info_lookup_by_timeline (context, timeline);
679 g_assert (info != NULL);
681 /* Cancel transition if window is gone */
682 if (gdk_window_is_destroyed (info->window) ||
683 !gdk_window_is_visible (info->window))
685 priv->animations = g_slist_remove (priv->animations, info);
686 animation_info_free (info);
690 if (info->invalidation_region &&
691 !cairo_region_is_empty (info->invalidation_region))
692 gdk_window_invalidate_region (info->window, info->invalidation_region, TRUE);
694 gdk_window_invalidate_rect (info->window, NULL, TRUE);
698 timeline_finished_cb (GtkTimeline *timeline,
701 GtkStyleContextPrivate *priv;
702 GtkStyleContext *context;
706 priv = context->priv;
707 info = animation_info_lookup_by_timeline (context, timeline);
709 g_assert (info != NULL);
711 priv->animations = g_slist_remove (priv->animations, info);
713 /* Invalidate one last time the area, so the final content is painted */
714 if (info->invalidation_region &&
715 !cairo_region_is_empty (info->invalidation_region))
716 gdk_window_invalidate_region (info->window, info->invalidation_region, TRUE);
718 gdk_window_invalidate_rect (info->window, NULL, TRUE);
720 animation_info_free (info);
723 static AnimationInfo *
724 animation_info_new (GtkStyleContext *context,
727 GtkTimelineProgressType progress_type,
730 gboolean target_value,
735 info = g_slice_new0 (AnimationInfo);
737 info->rectangles = g_array_new (FALSE, FALSE, sizeof (cairo_rectangle_int_t));
738 info->timeline = _gtk_timeline_new (duration);
739 info->window = g_object_ref (window);
741 info->target_value = target_value;
742 info->region_id = region_id;
744 _gtk_timeline_set_progress_type (info->timeline, progress_type);
745 _gtk_timeline_set_loop (info->timeline, loop);
747 if (!loop && !target_value)
749 _gtk_timeline_set_direction (info->timeline, GTK_TIMELINE_DIRECTION_BACKWARD);
750 _gtk_timeline_rewind (info->timeline);
753 g_signal_connect (info->timeline, "frame",
754 G_CALLBACK (timeline_frame_cb), context);
755 g_signal_connect (info->timeline, "finished",
756 G_CALLBACK (timeline_finished_cb), context);
758 _gtk_timeline_start (info->timeline);
763 static AnimationInfo *
764 animation_info_lookup (GtkStyleContext *context,
768 GtkStyleContextPrivate *priv;
771 priv = context->priv;
773 for (l = priv->animations; l; l = l->next)
779 if (info->state == state &&
780 info->region_id == region_id)
788 gtk_style_context_finalize (GObject *object)
790 GtkStyleContextPrivate *priv;
791 GtkStyleContext *style_context;
794 style_context = GTK_STYLE_CONTEXT (object);
795 priv = style_context->priv;
797 gtk_style_context_set_parent (style_context, NULL);
799 if (priv->widget_path)
800 gtk_widget_path_free (priv->widget_path);
802 g_hash_table_destroy (priv->style_data);
804 g_object_unref (priv->cascade);
806 g_slist_free_full (priv->info_stack, (GDestroyNotify) style_info_free);
808 g_slist_free (priv->animation_regions);
810 for (l = priv->animations; l; l = l->next)
811 animation_info_free ((AnimationInfo *) l->data);
813 g_slist_free (priv->animations);
815 if (priv->theming_engine)
816 g_object_unref (priv->theming_engine);
818 G_OBJECT_CLASS (gtk_style_context_parent_class)->finalize (object);
822 gtk_style_context_impl_set_property (GObject *object,
827 GtkStyleContext *style_context;
829 style_context = GTK_STYLE_CONTEXT (object);
834 gtk_style_context_set_screen (style_context,
835 g_value_get_object (value));
838 gtk_style_context_set_direction (style_context,
839 g_value_get_enum (value));
842 gtk_style_context_set_parent (style_context,
843 g_value_get_object (value));
846 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
852 gtk_style_context_impl_get_property (GObject *object,
857 GtkStyleContext *style_context;
858 GtkStyleContextPrivate *priv;
860 style_context = GTK_STYLE_CONTEXT (object);
861 priv = style_context->priv;
866 g_value_set_object (value, priv->screen);
869 g_value_set_enum (value, priv->direction);
872 g_value_set_object (value, priv->parent);
875 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
881 build_properties (GtkStyleContext *context,
882 StyleData *style_data,
886 GtkStyleContextPrivate *priv;
887 GtkCssLookup *lookup;
889 priv = context->priv;
891 lookup = _gtk_css_lookup_new ();
893 _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
898 style_data->store = _gtk_css_computed_values_new ();
899 _gtk_css_lookup_resolve (lookup, context, style_data->store);
900 _gtk_css_lookup_free (lookup);
903 static GtkWidgetPath *
904 create_query_path (GtkStyleContext *context)
906 GtkStyleContextPrivate *priv;
911 priv = context->priv;
912 path = gtk_widget_path_copy (priv->widget_path);
913 pos = gtk_widget_path_length (path) - 1;
915 info = priv->info_stack->data;
917 /* Set widget regions */
918 for (i = 0; i < info->regions->len; i++)
922 region = &g_array_index (info->regions, GtkRegion, i);
923 gtk_widget_path_iter_add_region (path, pos,
924 g_quark_to_string (region->class_quark),
928 /* Set widget classes */
929 for (i = 0; i < info->style_classes->len; i++)
933 quark = g_array_index (info->style_classes, GQuark, i);
934 gtk_widget_path_iter_add_class (path, pos,
935 g_quark_to_string (quark));
942 style_data_lookup (GtkStyleContext *context,
945 GtkStyleContextPrivate *priv;
947 gboolean state_mismatch;
950 priv = context->priv;
951 state_mismatch = ((GtkStyleInfo *) priv->info_stack->data)->state_flags != state;
953 /* Current data in use is cached, just return it */
954 if (priv->current_data && priv->current_state == state)
955 return priv->current_data;
957 g_assert (priv->widget_path != NULL);
959 if (G_UNLIKELY (state_mismatch))
961 gtk_style_context_save (context);
962 gtk_style_context_set_state (context, state);
965 priv->current_data = g_hash_table_lookup (priv->style_data, priv->info_stack->data);
966 priv->current_state = state;
968 if (!priv->current_data)
972 priv->current_data = style_data_new ();
973 g_hash_table_insert (priv->style_data,
974 style_info_copy (priv->info_stack->data),
977 path = create_query_path (context);
979 build_properties (context, priv->current_data, path, state);
981 gtk_widget_path_free (path);
984 data = priv->current_data;
986 if (priv->theming_engine)
987 g_object_unref (priv->theming_engine);
989 v = _gtk_css_computed_values_get_value_by_name (priv->current_data->store, "engine");
991 priv->theming_engine = _gtk_css_value_dup_object (v);
993 priv->theming_engine = g_object_ref (gtk_theming_engine_load (NULL));
995 if (G_UNLIKELY (state_mismatch))
996 gtk_style_context_restore (context);
1002 * gtk_style_context_new:
1004 * Creates a standalone #GtkStyleContext, this style context
1005 * won't be attached to any widget, so you may want
1006 * to call gtk_style_context_set_path() yourself.
1009 * This function is only useful when using the theming layer
1010 * separated from GTK+, if you are using #GtkStyleContext to
1011 * theme #GtkWidget<!-- -->s, use gtk_widget_get_style_context()
1012 * in order to get a style context ready to theme the widget.
1015 * Returns: A newly created #GtkStyleContext.
1018 gtk_style_context_new (void)
1020 return g_object_new (GTK_TYPE_STYLE_CONTEXT, NULL);
1024 * gtk_style_context_add_provider:
1025 * @context: a #GtkStyleContext
1026 * @provider: a #GtkStyleProvider
1027 * @priority: the priority of the style provider. The lower
1028 * it is, the earlier it will be used in the style
1029 * construction. Typically this will be in the range
1030 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1031 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1033 * Adds a style provider to @context, to be used in style construction.
1035 * <note><para>If both priorities are the same, A #GtkStyleProvider
1036 * added through this function takes precedence over another added
1037 * through gtk_style_context_add_provider_for_screen().</para></note>
1042 gtk_style_context_add_provider (GtkStyleContext *context,
1043 GtkStyleProvider *provider,
1046 GtkStyleContextPrivate *priv;
1048 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1049 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1051 priv = context->priv;
1053 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
1055 GtkStyleCascade *new_cascade;
1057 new_cascade = _gtk_style_cascade_new ();
1058 _gtk_style_cascade_set_parent (new_cascade, priv->cascade);
1059 g_object_unref (priv->cascade);
1060 priv->cascade = new_cascade;
1063 _gtk_style_cascade_add_provider (priv->cascade, provider, priority);
1065 gtk_style_context_invalidate (context);
1069 * gtk_style_context_remove_provider:
1070 * @context: a #GtkStyleContext
1071 * @provider: a #GtkStyleProvider
1073 * Removes @provider from the style providers list in @context.
1078 gtk_style_context_remove_provider (GtkStyleContext *context,
1079 GtkStyleProvider *provider)
1081 GtkStyleContextPrivate *priv;
1083 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1084 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1086 priv = context->priv;
1088 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
1091 _gtk_style_cascade_remove_provider (priv->cascade, provider);
1095 * gtk_style_context_reset_widgets:
1096 * @screen: a #GdkScreen
1098 * This function recomputes the styles for all widgets under a particular
1099 * #GdkScreen. This is useful when some global parameter has changed that
1100 * affects the appearance of all widgets, because when a widget gets a new
1101 * style, it will both redraw and recompute any cached information about
1102 * its appearance. As an example, it is used when the color scheme changes
1103 * in the related #GtkSettings object.
1108 gtk_style_context_reset_widgets (GdkScreen *screen)
1110 GList *list, *toplevels;
1112 _gtk_icon_set_invalidate_caches ();
1114 toplevels = gtk_window_list_toplevels ();
1115 g_list_foreach (toplevels, (GFunc) g_object_ref, NULL);
1117 for (list = toplevels; list; list = list->next)
1119 if (gtk_widget_get_screen (list->data) == screen)
1120 gtk_widget_reset_style (list->data);
1122 g_object_unref (list->data);
1125 g_list_free (toplevels);
1129 * gtk_style_context_add_provider_for_screen:
1130 * @screen: a #GdkScreen
1131 * @provider: a #GtkStyleProvider
1132 * @priority: the priority of the style provider. The lower
1133 * it is, the earlier it will be used in the style
1134 * construction. Typically this will be in the range
1135 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1136 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1138 * Adds a global style provider to @screen, which will be used
1139 * in style construction for all #GtkStyleContext<!-- -->s under
1142 * GTK+ uses this to make styling information from #GtkSettings
1145 * <note><para>If both priorities are the same, A #GtkStyleProvider
1146 * added through gtk_style_context_add_provider() takes precedence
1147 * over another added through this function.</para></note>
1152 gtk_style_context_add_provider_for_screen (GdkScreen *screen,
1153 GtkStyleProvider *provider,
1156 GtkStyleCascade *cascade;
1158 g_return_if_fail (GDK_IS_SCREEN (screen));
1159 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1161 cascade = _gtk_style_cascade_get_for_screen (screen);
1162 _gtk_style_cascade_add_provider (cascade, provider, priority);
1166 * gtk_style_context_remove_provider_for_screen:
1167 * @screen: a #GdkScreen
1168 * @provider: a #GtkStyleProvider
1170 * Removes @provider from the global style providers list in @screen.
1175 gtk_style_context_remove_provider_for_screen (GdkScreen *screen,
1176 GtkStyleProvider *provider)
1178 GtkStyleCascade *cascade;
1180 g_return_if_fail (GDK_IS_SCREEN (screen));
1181 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1183 cascade = _gtk_style_cascade_get_for_screen (screen);
1184 _gtk_style_cascade_remove_provider (cascade, provider);
1188 * gtk_style_context_get_section:
1189 * @context: a #GtkStyleContext
1190 * @property: style property name
1192 * Queries the location in the CSS where @property was defined for the
1193 * current @context. Note that the state to be queried is taken from
1194 * gtk_style_context_get_state().
1196 * If the location is not available, %NULL will be returned. The
1197 * location might not be available for various reasons, such as the
1198 * property being overridden, @property not naming a supported CSS
1199 * property or tracking of definitions being disabled for performance
1202 * Shorthand CSS properties cannot be queried for a location and will
1203 * always return %NULL.
1205 * Returns: %NULL or the section where value was defined
1208 gtk_style_context_get_section (GtkStyleContext *context,
1209 const gchar *property)
1211 GtkStyleContextPrivate *priv;
1212 GtkStyleProperty *prop;
1215 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1216 g_return_val_if_fail (property != NULL, NULL);
1218 priv = context->priv;
1219 g_return_val_if_fail (priv->widget_path != NULL, NULL);
1221 prop = _gtk_style_property_lookup (property);
1222 if (!GTK_IS_CSS_STYLE_PROPERTY (prop))
1225 data = style_data_lookup (context, gtk_style_context_get_state (context));
1226 return _gtk_css_computed_values_get_section (data->store, _gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (prop)));
1229 static GtkCssValue *
1230 gtk_style_context_query_func (guint id,
1233 return _gtk_css_computed_values_get_value (values, id);
1237 * gtk_style_context_get_property:
1238 * @context: a #GtkStyleContext
1239 * @property: style property name
1240 * @state: state to retrieve the property value for
1241 * @value: (out) (transfer full): return location for the style property value
1243 * Gets a style property from @context for the given state.
1245 * When @value is no longer needed, g_value_unset() must be called
1246 * to free any allocated memory.
1251 gtk_style_context_get_property (GtkStyleContext *context,
1252 const gchar *property,
1253 GtkStateFlags state,
1256 GtkStyleContextPrivate *priv;
1257 GtkStyleProperty *prop;
1261 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1262 g_return_if_fail (property != NULL);
1263 g_return_if_fail (value != NULL);
1265 priv = context->priv;
1266 g_return_if_fail (priv->widget_path != NULL);
1268 prop = _gtk_style_property_lookup (property);
1271 g_warning ("Style property \"%s\" is not registered", property);
1274 if (_gtk_style_property_get_value_type (prop) == G_TYPE_NONE)
1276 g_warning ("Style property \"%s\" is not gettable", property);
1280 data = style_data_lookup (context, state);
1281 v = _gtk_style_property_query (prop, gtk_style_context_query_func, data->store);
1282 _gtk_css_value_init_gvalue (v, value);
1283 _gtk_css_value_unref (v);
1287 * gtk_style_context_get_valist:
1288 * @context: a #GtkStyleContext
1289 * @state: state to retrieve the property values for
1290 * @args: va_list of property name/return location pairs, followed by %NULL
1292 * Retrieves several style property values from @context for a given state.
1297 gtk_style_context_get_valist (GtkStyleContext *context,
1298 GtkStateFlags state,
1301 const gchar *property_name;
1303 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1305 property_name = va_arg (args, const gchar *);
1307 while (property_name)
1309 gchar *error = NULL;
1310 GValue value = G_VALUE_INIT;
1312 gtk_style_context_get_property (context,
1317 G_VALUE_LCOPY (&value, args, 0, &error);
1318 g_value_unset (&value);
1322 g_warning ("Could not get style property \"%s\": %s", property_name, error);
1327 property_name = va_arg (args, const gchar *);
1332 * gtk_style_context_get:
1333 * @context: a #GtkStyleContext
1334 * @state: state to retrieve the property values for
1335 * @...: property name /return value pairs, followed by %NULL
1337 * Retrieves several style property values from @context for a
1343 gtk_style_context_get (GtkStyleContext *context,
1344 GtkStateFlags state,
1349 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1351 va_start (args, state);
1352 gtk_style_context_get_valist (context, state, args);
1357 * gtk_style_context_set_state:
1358 * @context: a #GtkStyleContext
1359 * @flags: state to represent
1361 * Sets the state to be used when rendering with any
1362 * of the gtk_render_*() functions.
1367 gtk_style_context_set_state (GtkStyleContext *context,
1368 GtkStateFlags flags)
1370 GtkStyleContextPrivate *priv;
1373 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1375 priv = context->priv;
1376 info = priv->info_stack->data;
1377 info->state_flags = flags;
1381 * gtk_style_context_get_state:
1382 * @context: a #GtkStyleContext
1384 * Returns the state used when rendering.
1386 * Returns: the state flags
1391 gtk_style_context_get_state (GtkStyleContext *context)
1393 GtkStyleContextPrivate *priv;
1396 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
1398 priv = context->priv;
1399 info = priv->info_stack->data;
1401 return info->state_flags;
1405 context_has_animatable_region (GtkStyleContext *context,
1408 GtkStyleContextPrivate *priv;
1410 /* NULL region_id means everything
1411 * rendered through the style context
1416 priv = context->priv;
1417 return g_slist_find (priv->animation_regions, region_id) != NULL;
1421 * gtk_style_context_state_is_running:
1422 * @context: a #GtkStyleContext
1423 * @state: a widget state
1424 * @progress: (out): return location for the transition progress
1426 * Returns %TRUE if there is a transition animation running for the
1427 * current region (see gtk_style_context_push_animatable_region()).
1429 * If @progress is not %NULL, the animation progress will be returned
1430 * there, 0.0 means the state is closest to being unset, while 1.0 means
1431 * it's closest to being set. This means transition animation will
1432 * run from 0 to 1 when @state is being set and from 1 to 0 when
1435 * Returns: %TRUE if there is a running transition animation for @state.
1440 gtk_style_context_state_is_running (GtkStyleContext *context,
1444 GtkStyleContextPrivate *priv;
1445 AnimationInfo *info;
1448 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1450 priv = context->priv;
1452 for (l = priv->animations; l; l = l->next)
1456 if (info->state == state &&
1457 context_has_animatable_region (context, info->region_id))
1460 *progress = _gtk_timeline_get_progress (info->timeline);
1470 * gtk_style_context_set_path:
1471 * @context: a #GtkStyleContext
1472 * @path: a #GtkWidgetPath
1474 * Sets the #GtkWidgetPath used for style matching. As a
1475 * consequence, the style will be regenerated to match
1476 * the new given path.
1478 * If you are using a #GtkStyleContext returned from
1479 * gtk_widget_get_style_context(), you do not need to call
1485 gtk_style_context_set_path (GtkStyleContext *context,
1486 GtkWidgetPath *path)
1488 GtkStyleContextPrivate *priv;
1490 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1491 g_return_if_fail (path != NULL);
1493 priv = context->priv;
1495 if (priv->widget_path)
1497 gtk_widget_path_free (priv->widget_path);
1498 priv->widget_path = NULL;
1502 priv->widget_path = gtk_widget_path_copy (path);
1504 gtk_style_context_invalidate (context);
1508 * gtk_style_context_get_path:
1509 * @context: a #GtkStyleContext
1511 * Returns the widget path used for style matching.
1513 * Returns: (transfer none): A #GtkWidgetPath
1517 const GtkWidgetPath *
1518 gtk_style_context_get_path (GtkStyleContext *context)
1520 GtkStyleContextPrivate *priv;
1522 priv = context->priv;
1523 return priv->widget_path;
1527 * gtk_style_context_set_parent:
1528 * @context: a #GtkStyleContext
1529 * @parent: (allow-none): the new parent or %NULL
1531 * Sets the parent style context for @context. The parent style
1532 * context is used to implement
1533 * <ulink url="http://www.w3.org/TR/css3-cascade/#inheritance">inheritance</ulink>
1536 * If you are using a #GtkStyleContext returned from
1537 * gtk_widget_get_style_context(), the parent will be set for you.
1542 gtk_style_context_set_parent (GtkStyleContext *context,
1543 GtkStyleContext *parent)
1545 GtkStyleContextPrivate *priv;
1547 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1548 g_return_if_fail (parent == NULL || GTK_IS_STYLE_CONTEXT (parent));
1550 priv = context->priv;
1552 if (priv->parent == parent)
1556 g_object_ref (parent);
1559 g_object_unref (priv->parent);
1561 priv->parent = parent;
1563 g_object_notify (G_OBJECT (context), "parent");
1564 gtk_style_context_invalidate (context);
1568 * gtk_style_context_get_parent:
1569 * @context: a #GtkStyleContext
1571 * Gets the parent context set via gtk_style_context_set_parent().
1572 * See that function for details.
1574 * Returns: (transfer none): the parent context or %NULL
1579 gtk_style_context_get_parent (GtkStyleContext *context)
1581 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1583 return context->priv->parent;
1587 * gtk_style_context_save:
1588 * @context: a #GtkStyleContext
1590 * Saves the @context state, so all modifications done through
1591 * gtk_style_context_add_class(), gtk_style_context_remove_class(),
1592 * gtk_style_context_add_region(), gtk_style_context_remove_region()
1593 * or gtk_style_context_set_junction_sides() can be reverted in one
1594 * go through gtk_style_context_restore().
1599 gtk_style_context_save (GtkStyleContext *context)
1601 GtkStyleContextPrivate *priv;
1604 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1606 priv = context->priv;
1608 g_assert (priv->info_stack != NULL);
1610 info = style_info_copy (priv->info_stack->data);
1611 priv->info_stack = g_slist_prepend (priv->info_stack, info);
1615 * gtk_style_context_restore:
1616 * @context: a #GtkStyleContext
1618 * Restores @context state to a previous stage.
1619 * See gtk_style_context_save().
1624 gtk_style_context_restore (GtkStyleContext *context)
1626 GtkStyleContextPrivate *priv;
1629 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1631 priv = context->priv;
1633 if (priv->info_stack)
1635 info = priv->info_stack->data;
1636 priv->info_stack = g_slist_remove (priv->info_stack, info);
1637 style_info_free (info);
1640 if (!priv->info_stack)
1642 g_warning ("Unpaired gtk_style_context_restore() call");
1644 /* Create default region */
1645 info = style_info_new ();
1646 priv->info_stack = g_slist_prepend (priv->info_stack, info);
1649 priv->current_data = NULL;
1653 style_class_find (GArray *array,
1658 gboolean found = FALSE;
1664 if (!array || array->len == 0)
1668 max = array->len - 1;
1674 mid = (min + max) / 2;
1675 item = g_array_index (array, GQuark, mid);
1677 if (class_quark == item)
1682 else if (class_quark > item)
1683 min = pos = mid + 1;
1690 while (!found && min <= max);
1699 region_find (GArray *array,
1704 gboolean found = FALSE;
1710 if (!array || array->len == 0)
1714 max = array->len - 1;
1720 mid = (min + max) / 2;
1721 region = &g_array_index (array, GtkRegion, mid);
1723 if (region->class_quark == class_quark)
1728 else if (region->class_quark > class_quark)
1729 min = pos = mid + 1;
1736 while (!found && min <= max);
1745 * gtk_style_context_add_class:
1746 * @context: a #GtkStyleContext
1747 * @class_name: class name to use in styling
1749 * Adds a style class to @context, so posterior calls to
1750 * gtk_style_context_get() or any of the gtk_render_*()
1751 * functions will make use of this new class for styling.
1753 * In the CSS file format, a #GtkEntry defining an "entry"
1754 * class, would be matched by:
1757 * GtkEntry.entry { ... }
1760 * While any widget defining an "entry" class would be
1769 gtk_style_context_add_class (GtkStyleContext *context,
1770 const gchar *class_name)
1772 GtkStyleContextPrivate *priv;
1777 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1778 g_return_if_fail (class_name != NULL);
1780 priv = context->priv;
1781 class_quark = g_quark_from_string (class_name);
1783 g_assert (priv->info_stack != NULL);
1784 info = priv->info_stack->data;
1786 if (!style_class_find (info->style_classes, class_quark, &position))
1788 g_array_insert_val (info->style_classes, position, class_quark);
1790 /* Unset current data, as it likely changed due to the class change */
1791 priv->current_data = NULL;
1796 * gtk_style_context_remove_class:
1797 * @context: a #GtkStyleContext
1798 * @class_name: class name to remove
1800 * Removes @class_name from @context.
1805 gtk_style_context_remove_class (GtkStyleContext *context,
1806 const gchar *class_name)
1808 GtkStyleContextPrivate *priv;
1813 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1814 g_return_if_fail (class_name != NULL);
1816 class_quark = g_quark_try_string (class_name);
1821 priv = context->priv;
1823 g_assert (priv->info_stack != NULL);
1824 info = priv->info_stack->data;
1826 if (style_class_find (info->style_classes, class_quark, &position))
1828 g_array_remove_index (info->style_classes, position);
1830 /* Unset current data, as it likely changed due to the class change */
1831 priv->current_data = NULL;
1836 * gtk_style_context_has_class:
1837 * @context: a #GtkStyleContext
1838 * @class_name: a class name
1840 * Returns %TRUE if @context currently has defined the
1843 * Returns: %TRUE if @context has @class_name defined
1848 gtk_style_context_has_class (GtkStyleContext *context,
1849 const gchar *class_name)
1851 GtkStyleContextPrivate *priv;
1855 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1856 g_return_val_if_fail (class_name != NULL, FALSE);
1858 class_quark = g_quark_try_string (class_name);
1863 priv = context->priv;
1865 g_assert (priv->info_stack != NULL);
1866 info = priv->info_stack->data;
1868 if (style_class_find (info->style_classes, class_quark, NULL))
1875 * gtk_style_context_list_classes:
1876 * @context: a #GtkStyleContext
1878 * Returns the list of classes currently defined in @context.
1880 * Returns: (transfer container) (element-type utf8): a #GList of
1881 * strings with the currently defined classes. The contents
1882 * of the list are owned by GTK+, but you must free the list
1883 * itself with g_list_free() when you are done with it.
1888 gtk_style_context_list_classes (GtkStyleContext *context)
1890 GtkStyleContextPrivate *priv;
1892 GList *classes = NULL;
1895 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1897 priv = context->priv;
1899 g_assert (priv->info_stack != NULL);
1900 info = priv->info_stack->data;
1902 for (i = 0; i < info->style_classes->len; i++)
1906 quark = g_array_index (info->style_classes, GQuark, i);
1907 classes = g_list_prepend (classes, (gchar *) g_quark_to_string (quark));
1914 * gtk_style_context_list_regions:
1915 * @context: a #GtkStyleContext
1917 * Returns the list of regions currently defined in @context.
1919 * Returns: (transfer container) (element-type utf8): a #GList of
1920 * strings with the currently defined regions. The contents
1921 * of the list are owned by GTK+, but you must free the list
1922 * itself with g_list_free() when you are done with it.
1927 gtk_style_context_list_regions (GtkStyleContext *context)
1929 GtkStyleContextPrivate *priv;
1931 GList *classes = NULL;
1934 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1936 priv = context->priv;
1938 g_assert (priv->info_stack != NULL);
1939 info = priv->info_stack->data;
1941 for (i = 0; i < info->regions->len; i++)
1944 const gchar *class_name;
1946 region = &g_array_index (info->regions, GtkRegion, i);
1948 class_name = g_quark_to_string (region->class_quark);
1949 classes = g_list_prepend (classes, (gchar *) class_name);
1956 _gtk_style_context_check_region_name (const gchar *str)
1958 g_return_val_if_fail (str != NULL, FALSE);
1960 if (!g_ascii_islower (str[0]))
1966 !g_ascii_islower (*str))
1976 * gtk_style_context_add_region:
1977 * @context: a #GtkStyleContext
1978 * @region_name: region name to use in styling
1979 * @flags: flags that apply to the region
1981 * Adds a region to @context, so posterior calls to
1982 * gtk_style_context_get() or any of the gtk_render_*()
1983 * functions will make use of this new region for styling.
1985 * In the CSS file format, a #GtkTreeView defining a "row"
1986 * region, would be matched by:
1989 * GtkTreeView row { ... }
1992 * Pseudo-classes are used for matching @flags, so the two
1995 * GtkTreeView row:nth-child(even) { ... }
1996 * GtkTreeView row:nth-child(odd) { ... }
1999 * would apply to even and odd rows, respectively.
2001 * <note><para>Region names must only contain lowercase letters
2002 * and '-', starting always with a lowercase letter.</para></note>
2007 gtk_style_context_add_region (GtkStyleContext *context,
2008 const gchar *region_name,
2009 GtkRegionFlags flags)
2011 GtkStyleContextPrivate *priv;
2013 GQuark region_quark;
2016 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2017 g_return_if_fail (region_name != NULL);
2018 g_return_if_fail (_gtk_style_context_check_region_name (region_name));
2020 priv = context->priv;
2021 region_quark = g_quark_from_string (region_name);
2023 g_assert (priv->info_stack != NULL);
2024 info = priv->info_stack->data;
2026 if (!region_find (info->regions, region_quark, &position))
2030 region.class_quark = region_quark;
2031 region.flags = flags;
2033 g_array_insert_val (info->regions, position, region);
2035 /* Unset current data, as it likely changed due to the region change */
2036 priv->current_data = NULL;
2041 * gtk_style_context_remove_region:
2042 * @context: a #GtkStyleContext
2043 * @region_name: region name to unset
2045 * Removes a region from @context.
2050 gtk_style_context_remove_region (GtkStyleContext *context,
2051 const gchar *region_name)
2053 GtkStyleContextPrivate *priv;
2055 GQuark region_quark;
2058 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2059 g_return_if_fail (region_name != NULL);
2061 region_quark = g_quark_try_string (region_name);
2066 priv = context->priv;
2068 g_assert (priv->info_stack != NULL);
2069 info = priv->info_stack->data;
2071 if (region_find (info->regions, region_quark, &position))
2073 g_array_remove_index (info->regions, position);
2075 /* Unset current data, as it likely changed due to the region change */
2076 priv->current_data = NULL;
2081 * gtk_style_context_has_region:
2082 * @context: a #GtkStyleContext
2083 * @region_name: a region name
2084 * @flags_return: (out) (allow-none): return location for region flags
2086 * Returns %TRUE if @context has the region defined.
2087 * If @flags_return is not %NULL, it is set to the flags
2088 * affecting the region.
2090 * Returns: %TRUE if region is defined
2095 gtk_style_context_has_region (GtkStyleContext *context,
2096 const gchar *region_name,
2097 GtkRegionFlags *flags_return)
2099 GtkStyleContextPrivate *priv;
2101 GQuark region_quark;
2104 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2105 g_return_val_if_fail (region_name != NULL, FALSE);
2110 region_quark = g_quark_try_string (region_name);
2115 priv = context->priv;
2117 g_assert (priv->info_stack != NULL);
2118 info = priv->info_stack->data;
2120 if (region_find (info->regions, region_quark, &position))
2126 region = &g_array_index (info->regions, GtkRegion, position);
2127 *flags_return = region->flags;
2136 style_property_values_cmp (gconstpointer bsearch_node1,
2137 gconstpointer bsearch_node2)
2139 const PropertyValue *val1 = bsearch_node1;
2140 const PropertyValue *val2 = bsearch_node2;
2142 if (val1->widget_type != val2->widget_type)
2143 return val1->widget_type < val2->widget_type ? -1 : 1;
2145 if (val1->pspec != val2->pspec)
2146 return val1->pspec < val2->pspec ? -1 : 1;
2148 if (val1->state != val2->state)
2149 return val1->state < val2->state ? -1 : 1;
2155 _gtk_style_context_peek_property (GtkStyleContext *context,
2156 const char *property_name)
2158 StyleData *data = style_data_lookup (context, gtk_style_context_get_state (context));
2160 return _gtk_css_computed_values_get_value_by_name (data->store, property_name);
2164 _gtk_style_context_get_number (GtkStyleContext *context,
2165 const char *property_name,
2166 double one_hundred_percent)
2170 value = _gtk_style_context_peek_property (context, property_name);
2171 return _gtk_css_number_get (_gtk_css_value_get_number (value), one_hundred_percent);
2175 _gtk_style_context_peek_style_property (GtkStyleContext *context,
2177 GtkStateFlags state,
2180 GtkStyleContextPrivate *priv;
2181 PropertyValue *pcache, key = { 0 };
2185 priv = context->priv;
2186 data = style_data_lookup (context, state);
2188 key.widget_type = widget_type;
2192 /* need value cache array */
2193 if (!data->property_cache)
2194 data->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
2197 pcache = bsearch (&key,
2198 data->property_cache->data, data->property_cache->len,
2199 sizeof (PropertyValue), style_property_values_cmp);
2201 return &pcache->value;
2205 while (i < data->property_cache->len &&
2206 style_property_values_cmp (&key, &g_array_index (data->property_cache, PropertyValue, i)) >= 0)
2209 g_array_insert_val (data->property_cache, i, key);
2210 pcache = &g_array_index (data->property_cache, PropertyValue, i);
2212 /* cache miss, initialize value type, then set contents */
2213 g_param_spec_ref (pcache->pspec);
2214 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2216 if (priv->widget_path)
2218 if (gtk_style_provider_get_style_property (GTK_STYLE_PROVIDER (priv->cascade),
2219 priv->widget_path, state,
2220 pspec, &pcache->value))
2222 /* Resolve symbolic colors to GdkColor/GdkRGBA */
2223 if (G_VALUE_TYPE (&pcache->value) == GTK_TYPE_SYMBOLIC_COLOR)
2225 GtkSymbolicColor *color;
2228 color = g_value_dup_boxed (&pcache->value);
2230 g_value_unset (&pcache->value);
2232 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2233 g_value_init (&pcache->value, GDK_TYPE_RGBA);
2235 g_value_init (&pcache->value, GDK_TYPE_COLOR);
2237 if (_gtk_style_context_resolve_color (context, color, &rgba))
2239 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2240 g_value_set_boxed (&pcache->value, &rgba);
2245 rgb.red = rgba.red * 65535. + 0.5;
2246 rgb.green = rgba.green * 65535. + 0.5;
2247 rgb.blue = rgba.blue * 65535. + 0.5;
2249 g_value_set_boxed (&pcache->value, &rgb);
2253 g_param_value_set_default (pspec, &pcache->value);
2255 gtk_symbolic_color_unref (color);
2258 return &pcache->value;
2262 /* not supplied by any provider, revert to default */
2263 g_param_value_set_default (pspec, &pcache->value);
2265 return &pcache->value;
2269 * gtk_style_context_get_style_property:
2270 * @context: a #GtkStyleContext
2271 * @property_name: the name of the widget style property
2272 * @value: Return location for the property value
2274 * Gets the value for a widget style property.
2276 * When @value is no longer needed, g_value_unset() must be called
2277 * to free any allocated memory.
2280 gtk_style_context_get_style_property (GtkStyleContext *context,
2281 const gchar *property_name,
2284 GtkStyleContextPrivate *priv;
2285 GtkWidgetClass *widget_class;
2286 GtkStateFlags state;
2288 const GValue *peek_value;
2291 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2292 g_return_if_fail (property_name != NULL);
2293 g_return_if_fail (value != NULL);
2295 priv = context->priv;
2297 if (!priv->widget_path)
2300 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2302 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2304 g_warning ("%s: can't get style properties for non-widget class `%s'",
2306 g_type_name (widget_type));
2310 widget_class = g_type_class_ref (widget_type);
2311 pspec = gtk_widget_class_find_style_property (widget_class, property_name);
2312 g_type_class_unref (widget_class);
2316 g_warning ("%s: widget class `%s' has no style property named `%s'",
2318 g_type_name (widget_type),
2323 state = gtk_style_context_get_state (context);
2324 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2327 if (G_VALUE_TYPE (value) == G_VALUE_TYPE (peek_value))
2328 g_value_copy (peek_value, value);
2329 else if (g_value_type_transformable (G_VALUE_TYPE (peek_value), G_VALUE_TYPE (value)))
2330 g_value_transform (peek_value, value);
2332 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
2334 G_VALUE_TYPE_NAME (peek_value),
2335 G_VALUE_TYPE_NAME (value));
2339 * gtk_style_context_get_style_valist:
2340 * @context: a #GtkStyleContext
2341 * @args: va_list of property name/return location pairs, followed by %NULL
2343 * Retrieves several widget style properties from @context according to the
2349 gtk_style_context_get_style_valist (GtkStyleContext *context,
2352 GtkStyleContextPrivate *priv;
2353 const gchar *prop_name;
2354 GtkStateFlags state;
2357 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2359 prop_name = va_arg (args, const gchar *);
2360 priv = context->priv;
2362 if (!priv->widget_path)
2365 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2367 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2369 g_warning ("%s: can't get style properties for non-widget class `%s'",
2371 g_type_name (widget_type));
2375 state = gtk_style_context_get_state (context);
2379 GtkWidgetClass *widget_class;
2381 const GValue *peek_value;
2384 widget_class = g_type_class_ref (widget_type);
2385 pspec = gtk_widget_class_find_style_property (widget_class, prop_name);
2386 g_type_class_unref (widget_class);
2390 g_warning ("%s: widget class `%s' has no style property named `%s'",
2392 g_type_name (widget_type),
2397 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2400 G_VALUE_LCOPY (peek_value, args, 0, &error);
2404 g_warning ("can't retrieve style property `%s' of type `%s': %s",
2406 G_VALUE_TYPE_NAME (peek_value),
2411 prop_name = va_arg (args, const gchar *);
2416 * gtk_style_context_get_style:
2417 * @context: a #GtkStyleContext
2418 * @...: property name /return value pairs, followed by %NULL
2420 * Retrieves several widget style properties from @context according to the
2426 gtk_style_context_get_style (GtkStyleContext *context,
2431 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2433 va_start (args, context);
2434 gtk_style_context_get_style_valist (context, args);
2440 * gtk_style_context_lookup_icon_set:
2441 * @context: a #GtkStyleContext
2442 * @stock_id: an icon name
2444 * Looks up @stock_id in the icon factories associated to @context and
2445 * the default icon factory, returning an icon set if found, otherwise
2448 * Returns: (transfer none): The looked up %GtkIconSet, or %NULL
2451 gtk_style_context_lookup_icon_set (GtkStyleContext *context,
2452 const gchar *stock_id)
2454 GtkStyleContextPrivate *priv;
2456 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2457 g_return_val_if_fail (stock_id != NULL, NULL);
2459 priv = context->priv;
2460 g_return_val_if_fail (priv->widget_path != NULL, NULL);
2462 return gtk_icon_factory_lookup_default (stock_id);
2466 * gtk_style_context_set_screen:
2467 * @context: a #GtkStyleContext
2468 * @screen: a #GdkScreen
2470 * Attaches @context to the given screen.
2472 * The screen is used to add style information from 'global' style
2473 * providers, such as the screens #GtkSettings instance.
2475 * If you are using a #GtkStyleContext returned from
2476 * gtk_widget_get_style_context(), you do not need to
2477 * call this yourself.
2482 gtk_style_context_set_screen (GtkStyleContext *context,
2485 GtkStyleContextPrivate *priv;
2487 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2488 g_return_if_fail (GDK_IS_SCREEN (screen));
2490 priv = context->priv;
2491 if (priv->screen == screen)
2494 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
2496 g_object_unref (priv->cascade);
2497 priv->cascade = _gtk_style_cascade_get_for_screen (screen);
2498 g_object_ref (priv->cascade);
2502 _gtk_style_cascade_set_parent (priv->cascade, _gtk_style_cascade_get_for_screen (screen));
2505 priv->screen = screen;
2507 g_object_notify (G_OBJECT (context), "screen");
2509 gtk_style_context_invalidate (context);
2513 * gtk_style_context_get_screen:
2514 * @context: a #GtkStyleContext
2516 * Returns the #GdkScreen to which @context is attached.
2518 * Returns: (transfer none): a #GdkScreen.
2521 gtk_style_context_get_screen (GtkStyleContext *context)
2523 GtkStyleContextPrivate *priv;
2525 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2527 priv = context->priv;
2528 return priv->screen;
2532 * gtk_style_context_set_direction:
2533 * @context: a #GtkStyleContext
2534 * @direction: the new direction.
2536 * Sets the reading direction for rendering purposes.
2538 * If you are using a #GtkStyleContext returned from
2539 * gtk_widget_get_style_context(), you do not need to
2540 * call this yourself.
2545 gtk_style_context_set_direction (GtkStyleContext *context,
2546 GtkTextDirection direction)
2548 GtkStyleContextPrivate *priv;
2550 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2552 priv = context->priv;
2553 priv->direction = direction;
2555 g_object_notify (G_OBJECT (context), "direction");
2559 * gtk_style_context_get_direction:
2560 * @context: a #GtkStyleContext
2562 * Returns the widget direction used for rendering.
2564 * Returns: the widget direction
2569 gtk_style_context_get_direction (GtkStyleContext *context)
2571 GtkStyleContextPrivate *priv;
2573 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), GTK_TEXT_DIR_LTR);
2575 priv = context->priv;
2576 return priv->direction;
2580 * gtk_style_context_set_junction_sides:
2581 * @context: a #GtkStyleContext
2582 * @sides: sides where rendered elements are visually connected to
2585 * Sets the sides where rendered elements (mostly through
2586 * gtk_render_frame()) will visually connect with other visual elements.
2588 * This is merely a hint that may or may not be honored
2589 * by theming engines.
2591 * Container widgets are expected to set junction hints as appropriate
2592 * for their children, so it should not normally be necessary to call
2593 * this function manually.
2598 gtk_style_context_set_junction_sides (GtkStyleContext *context,
2599 GtkJunctionSides sides)
2601 GtkStyleContextPrivate *priv;
2604 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2606 priv = context->priv;
2607 info = priv->info_stack->data;
2608 info->junction_sides = sides;
2612 * gtk_style_context_get_junction_sides:
2613 * @context: a #GtkStyleContext
2615 * Returns the sides where rendered elements connect visually with others.
2617 * Returns: the junction sides
2622 gtk_style_context_get_junction_sides (GtkStyleContext *context)
2624 GtkStyleContextPrivate *priv;
2627 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
2629 priv = context->priv;
2630 info = priv->info_stack->data;
2631 return info->junction_sides;
2634 static GtkSymbolicColor *
2635 gtk_style_context_color_lookup_func (gpointer contextp,
2638 GtkStyleContext *context = contextp;
2640 return _gtk_style_provider_private_get_color (GTK_STYLE_PROVIDER_PRIVATE (context->priv->cascade), name);
2644 _gtk_style_context_resolve_color_value (GtkStyleContext *context,
2645 GtkSymbolicColor *color)
2647 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2648 g_return_val_if_fail (color != NULL, FALSE);
2650 return _gtk_symbolic_color_resolve_full (color,
2651 gtk_style_context_color_lookup_func,
2657 _gtk_style_context_resolve_color (GtkStyleContext *context,
2658 GtkSymbolicColor *color,
2663 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2664 g_return_val_if_fail (color != NULL, FALSE);
2665 g_return_val_if_fail (result != NULL, FALSE);
2667 val = _gtk_symbolic_color_resolve_full (color,
2668 gtk_style_context_color_lookup_func,
2673 *result = *_gtk_css_value_get_rgba (val);
2674 _gtk_css_value_unref (val);
2679 * gtk_style_context_lookup_color:
2680 * @context: a #GtkStyleContext
2681 * @color_name: color name to lookup
2682 * @color: (out): Return location for the looked up color
2684 * Looks up and resolves a color name in the @context color map.
2686 * Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
2689 gtk_style_context_lookup_color (GtkStyleContext *context,
2690 const gchar *color_name,
2693 GtkSymbolicColor *sym_color;
2695 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2696 g_return_val_if_fail (color_name != NULL, FALSE);
2697 g_return_val_if_fail (color != NULL, FALSE);
2699 sym_color = gtk_style_context_color_lookup_func (context, color_name);
2700 if (sym_color == NULL)
2703 return _gtk_style_context_resolve_color (context, sym_color, color);
2707 * gtk_style_context_notify_state_change:
2708 * @context: a #GtkStyleContext
2709 * @window: a #GdkWindow
2710 * @region_id: (allow-none): animatable region to notify on, or %NULL.
2711 * See gtk_style_context_push_animatable_region()
2712 * @state: state to trigger transition for
2713 * @state_value: %TRUE if @state is the state we are changing to,
2714 * %FALSE if we are changing away from it
2716 * Notifies a state change on @context, so if the current style makes use
2717 * of transition animations, one will be started so all rendered elements
2718 * under @region_id are animated for state @state being set to value
2721 * The @window parameter is used in order to invalidate the rendered area
2722 * as the animation runs, so make sure it is the same window that is being
2723 * rendered on by the gtk_render_*() functions.
2725 * If @region_id is %NULL, all rendered elements using @context will be
2726 * affected by this state transition.
2728 * As a practical example, a #GtkButton notifying a state transition on
2729 * the prelight state:
2731 * gtk_style_context_notify_state_change (context,
2732 * gtk_widget_get_window (widget),
2734 * GTK_STATE_PRELIGHT,
2735 * button->in_button);
2738 * Can be handled in the CSS file like this:
2741 * background-color: #f00
2745 * background-color: #fff;
2746 * transition: 200ms linear
2750 * This combination will animate the button background from red to white
2751 * if a pointer enters the button, and back to red if the pointer leaves
2754 * Note that @state is used when finding the transition parameters, which
2755 * is why the style places the transition under the :hover pseudo-class.
2760 gtk_style_context_notify_state_change (GtkStyleContext *context,
2764 gboolean state_value)
2766 GtkStyleContextPrivate *priv;
2767 GtkAnimationDescription *desc;
2768 AnimationInfo *info;
2769 GtkStateFlags flags;
2773 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2774 g_return_if_fail (GDK_IS_WINDOW (window));
2775 g_return_if_fail (state > GTK_STATE_NORMAL && state <= GTK_STATE_FOCUSED);
2777 priv = context->priv;
2778 g_return_if_fail (priv->widget_path != NULL);
2780 state_value = (state_value == TRUE);
2784 case GTK_STATE_ACTIVE:
2785 flags = GTK_STATE_FLAG_ACTIVE;
2787 case GTK_STATE_PRELIGHT:
2788 flags = GTK_STATE_FLAG_PRELIGHT;
2790 case GTK_STATE_SELECTED:
2791 flags = GTK_STATE_FLAG_SELECTED;
2793 case GTK_STATE_INSENSITIVE:
2794 flags = GTK_STATE_FLAG_INSENSITIVE;
2796 case GTK_STATE_INCONSISTENT:
2797 flags = GTK_STATE_FLAG_INCONSISTENT;
2799 case GTK_STATE_FOCUSED:
2800 flags = GTK_STATE_FLAG_FOCUSED;
2802 case GTK_STATE_NORMAL:
2808 /* Find out if there is any animation description for the given
2809 * state, it will fallback to the normal state as well if necessary.
2811 data = style_data_lookup (context, flags);
2812 v = _gtk_css_computed_values_get_value_by_name (data->store, "transition");
2815 desc = _gtk_css_value_get_boxed (v);
2819 if (_gtk_animation_description_get_duration (desc) == 0)
2822 info = animation_info_lookup (context, region_id, state);
2825 info->target_value != state_value)
2827 /* Target values are the opposite */
2828 if (!_gtk_timeline_get_loop (info->timeline))
2830 /* Reverse the animation */
2831 if (_gtk_timeline_get_direction (info->timeline) == GTK_TIMELINE_DIRECTION_FORWARD)
2832 _gtk_timeline_set_direction (info->timeline, GTK_TIMELINE_DIRECTION_BACKWARD);
2834 _gtk_timeline_set_direction (info->timeline, GTK_TIMELINE_DIRECTION_FORWARD);
2836 info->target_value = state_value;
2840 /* Take it out of its looping state */
2841 _gtk_timeline_set_loop (info->timeline, FALSE);
2845 (!_gtk_animation_description_get_loop (desc) ||
2848 info = animation_info_new (context, region_id,
2849 _gtk_animation_description_get_duration (desc),
2850 _gtk_animation_description_get_progress_type (desc),
2851 _gtk_animation_description_get_loop (desc),
2852 state, state_value, window);
2854 priv->animations = g_slist_prepend (priv->animations, info);
2855 priv->animations_invalidated = TRUE;
2860 * gtk_style_context_cancel_animations:
2861 * @context: a #GtkStyleContext
2862 * @region_id: (allow-none): animatable region to stop, or %NULL.
2863 * See gtk_style_context_push_animatable_region()
2865 * Stops all running animations for @region_id and all animatable
2866 * regions underneath.
2868 * A %NULL @region_id will stop all ongoing animations in @context,
2869 * when dealing with a #GtkStyleContext obtained through
2870 * gtk_widget_get_style_context(), this is normally done for you
2871 * in all circumstances you would expect all widget to be stopped,
2872 * so this should be only used in complex widgets with different
2873 * animatable regions.
2878 gtk_style_context_cancel_animations (GtkStyleContext *context,
2881 GtkStyleContextPrivate *priv;
2882 AnimationInfo *info;
2885 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2887 priv = context->priv;
2888 l = priv->animations;
2896 info->region_id == region_id ||
2897 g_slist_find (info->parent_regions, region_id))
2899 priv->animations = g_slist_remove (priv->animations, info);
2900 animation_info_free (info);
2906 is_parent_of (GdkWindow *parent,
2909 GtkWidget *child_widget, *parent_widget;
2912 gdk_window_get_user_data (child, (gpointer *) &child_widget);
2913 gdk_window_get_user_data (parent, (gpointer *) &parent_widget);
2915 if (child_widget != parent_widget &&
2916 !gtk_widget_is_ancestor (child_widget, parent_widget))
2923 if (window == parent)
2926 window = gdk_window_get_parent (window);
2933 * gtk_style_context_scroll_animations:
2934 * @context: a #GtkStyleContext
2935 * @window: a #GdkWindow used previously in
2936 * gtk_style_context_notify_state_change()
2937 * @dx: Amount to scroll in the X axis
2938 * @dy: Amount to scroll in the Y axis
2940 * This function is analogous to gdk_window_scroll(), and
2941 * should be called together with it so the invalidation
2942 * areas for any ongoing animation are scrolled together
2948 gtk_style_context_scroll_animations (GtkStyleContext *context,
2953 GtkStyleContextPrivate *priv;
2954 AnimationInfo *info;
2957 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2958 g_return_if_fail (GDK_IS_WINDOW (window));
2960 priv = context->priv;
2961 l = priv->animations;
2968 if (info->invalidation_region &&
2969 (window == info->window ||
2970 is_parent_of (window, info->window)))
2971 cairo_region_translate (info->invalidation_region, dx, dy);
2976 * gtk_style_context_push_animatable_region:
2977 * @context: a #GtkStyleContext
2978 * @region_id: unique identifier for the animatable region
2980 * Pushes an animatable region, so all further gtk_render_*() calls between
2981 * this call and the following gtk_style_context_pop_animatable_region()
2982 * will potentially show transition animations for this region if
2983 * gtk_style_context_notify_state_change() is called for a given state,
2984 * and the current theme/style defines transition animations for state
2987 * The @region_id used must be unique in @context so the theming engine
2988 * can uniquely identify rendered elements subject to a state transition.
2993 gtk_style_context_push_animatable_region (GtkStyleContext *context,
2996 GtkStyleContextPrivate *priv;
2998 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2999 g_return_if_fail (region_id != NULL);
3001 priv = context->priv;
3002 priv->animation_regions = g_slist_prepend (priv->animation_regions, region_id);
3006 * gtk_style_context_pop_animatable_region:
3007 * @context: a #GtkStyleContext
3009 * Pops an animatable region from @context.
3010 * See gtk_style_context_push_animatable_region().
3015 gtk_style_context_pop_animatable_region (GtkStyleContext *context)
3017 GtkStyleContextPrivate *priv;
3019 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3021 priv = context->priv;
3022 priv->animation_regions = g_slist_delete_link (priv->animation_regions,
3023 priv->animation_regions);
3027 _gtk_style_context_invalidate_animation_areas (GtkStyleContext *context)
3029 GtkStyleContextPrivate *priv;
3032 priv = context->priv;
3034 for (l = priv->animations; l; l = l->next)
3036 AnimationInfo *info;
3040 /* A NULL invalidation region means it has to be recreated on
3041 * the next expose event, this happens usually after a widget
3042 * allocation change, so the next expose after it will update
3043 * the invalidation region.
3045 if (info->invalidation_region)
3047 cairo_region_destroy (info->invalidation_region);
3048 info->invalidation_region = NULL;
3052 priv->animations_invalidated = TRUE;
3056 _gtk_style_context_coalesce_animation_areas (GtkStyleContext *context,
3059 GtkStyleContextPrivate *priv;
3062 priv = context->priv;
3064 if (!priv->animations_invalidated)
3067 l = priv->animations;
3071 AnimationInfo *info;
3080 if (info->invalidation_region)
3083 if (info->rectangles->len == 0)
3086 info->invalidation_region = cairo_region_create ();
3087 _gtk_widget_get_translation_to_window (widget, info->window, &rel_x, &rel_y);
3089 for (i = 0; i < info->rectangles->len; i++)
3091 cairo_rectangle_int_t *rect;
3093 rect = &g_array_index (info->rectangles, cairo_rectangle_int_t, i);
3095 /* These are widget relative coordinates,
3096 * so have them inverted to be window relative
3101 cairo_region_union_rectangle (info->invalidation_region, rect);
3104 g_array_remove_range (info->rectangles, 0, info->rectangles->len);
3107 priv->animations_invalidated = FALSE;
3111 store_animation_region (GtkStyleContext *context,
3117 GtkStyleContextPrivate *priv;
3120 priv = context->priv;
3122 if (!priv->animations_invalidated)
3125 for (l = priv->animations; l; l = l->next)
3127 AnimationInfo *info;
3131 /* The animation doesn't need updating
3132 * the invalidation area, bail out.
3134 if (info->invalidation_region)
3137 if (context_has_animatable_region (context, info->region_id))
3139 cairo_rectangle_int_t rect;
3143 rect.width = (gint) width;
3144 rect.height = (gint) height;
3146 g_array_append_val (info->rectangles, rect);
3148 if (!info->parent_regions)
3150 GSList *parent_regions;
3152 parent_regions = g_slist_find (priv->animation_regions, info->region_id);
3153 info->parent_regions = g_slist_copy (parent_regions);
3160 * gtk_style_context_invalidate:
3161 * @context: a #GtkStyleContext.
3163 * Invalidates @context style information, so it will be reconstructed
3166 * If you're using a #GtkStyleContext returned from
3167 * gtk_widget_get_style_context(), you do not need to
3168 * call this yourself.
3173 gtk_style_context_invalidate (GtkStyleContext *context)
3175 GtkStyleContextPrivate *priv;
3177 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3179 priv = context->priv;
3181 /* Avoid reentrancy */
3182 if (priv->invalidating_context)
3185 priv->invalidating_context = TRUE;
3187 g_hash_table_remove_all (priv->style_data);
3188 priv->current_data = NULL;
3190 g_signal_emit (context, signals[CHANGED], 0);
3192 priv->invalidating_context = FALSE;
3196 * gtk_style_context_set_background:
3197 * @context: a #GtkStyleContext
3198 * @window: a #GdkWindow
3200 * Sets the background of @window to the background pattern or
3201 * color specified in @context for its current state.
3206 gtk_style_context_set_background (GtkStyleContext *context,
3209 GtkStateFlags state;
3210 cairo_pattern_t *pattern;
3213 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3214 g_return_if_fail (GDK_IS_WINDOW (window));
3216 state = gtk_style_context_get_state (context);
3217 gtk_style_context_get (context, state,
3218 "background-image", &pattern,
3222 gdk_window_set_background_pattern (window, pattern);
3223 cairo_pattern_destroy (pattern);
3227 gtk_style_context_get (context, state,
3228 "background-color", &color,
3232 gdk_window_set_background_rgba (window, color);
3233 gdk_rgba_free (color);
3238 * gtk_style_context_get_color:
3239 * @context: a #GtkStyleContext
3240 * @state: state to retrieve the color for
3241 * @color: (out): return value for the foreground color
3243 * Gets the foreground color for a given state.
3248 gtk_style_context_get_color (GtkStyleContext *context,
3249 GtkStateFlags state,
3254 g_return_if_fail (color != NULL);
3255 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3257 gtk_style_context_get (context,
3267 * gtk_style_context_get_background_color:
3268 * @context: a #GtkStyleContext
3269 * @state: state to retrieve the color for
3270 * @color: (out): return value for the background color
3272 * Gets the background color for a given state.
3277 gtk_style_context_get_background_color (GtkStyleContext *context,
3278 GtkStateFlags state,
3283 g_return_if_fail (color != NULL);
3284 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3286 gtk_style_context_get (context,
3288 "background-color", &c,
3296 * gtk_style_context_get_border_color:
3297 * @context: a #GtkStyleContext
3298 * @state: state to retrieve the color for
3299 * @color: (out): return value for the border color
3301 * Gets the border color for a given state.
3306 gtk_style_context_get_border_color (GtkStyleContext *context,
3307 GtkStateFlags state,
3312 g_return_if_fail (color != NULL);
3313 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3315 gtk_style_context_get (context,
3325 * gtk_style_context_get_border:
3326 * @context: a #GtkStyleContext
3327 * @state: state to retrieve the border for
3328 * @border: (out): return value for the border settings
3330 * Gets the border for a given state as a #GtkBorder.
3331 * See %GTK_STYLE_PROPERTY_BORDER_WIDTH.
3336 gtk_style_context_get_border (GtkStyleContext *context,
3337 GtkStateFlags state,
3340 int top, left, bottom, right;
3342 g_return_if_fail (border != NULL);
3343 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3345 gtk_style_context_get (context,
3347 "border-top-width", &top,
3348 "border-left-width", &left,
3349 "border-bottom-width", &bottom,
3350 "border-right-width", &right,
3354 border->left = left;
3355 border->bottom = bottom;
3356 border->right = right;
3360 * gtk_style_context_get_padding:
3361 * @context: a #GtkStyleContext
3362 * @state: state to retrieve the padding for
3363 * @padding: (out): return value for the padding settings
3365 * Gets the padding for a given state as a #GtkBorder.
3366 * See %GTK_STYLE_PROPERTY_PADDING.
3371 gtk_style_context_get_padding (GtkStyleContext *context,
3372 GtkStateFlags state,
3375 int top, left, bottom, right;
3377 g_return_if_fail (padding != NULL);
3378 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3380 gtk_style_context_get (context,
3382 "padding-top", &top,
3383 "padding-left", &left,
3384 "padding-bottom", &bottom,
3385 "padding-right", &right,
3389 padding->left = left;
3390 padding->bottom = bottom;
3391 padding->right = right;
3395 * gtk_style_context_get_margin:
3396 * @context: a #GtkStyleContext
3397 * @state: state to retrieve the border for
3398 * @margin: (out): return value for the margin settings
3400 * Gets the margin for a given state as a #GtkBorder.
3401 * See %GTK_STYLE_PROPERTY_MARGIN.
3406 gtk_style_context_get_margin (GtkStyleContext *context,
3407 GtkStateFlags state,
3410 int top, left, bottom, right;
3412 g_return_if_fail (margin != NULL);
3413 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3415 gtk_style_context_get (context,
3418 "margin-left", &left,
3419 "margin-bottom", &bottom,
3420 "margin-right", &right,
3424 margin->left = left;
3425 margin->bottom = bottom;
3426 margin->right = right;
3430 * gtk_style_context_get_font:
3431 * @context: a #GtkStyleContext
3432 * @state: state to retrieve the font for
3434 * Returns the font description for a given state. The returned
3435 * object is const and will remain valid until the
3436 * #GtkStyleContext::changed signal happens.
3438 * Returns: (transfer none): the #PangoFontDescription for the given
3439 * state. This object is owned by GTK+ and should not be
3444 const PangoFontDescription *
3445 gtk_style_context_get_font (GtkStyleContext *context,
3446 GtkStateFlags state)
3448 GtkStyleContextPrivate *priv;
3450 PangoFontDescription *description;
3452 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
3454 priv = context->priv;
3455 g_return_val_if_fail (priv->widget_path != NULL, NULL);
3457 data = style_data_lookup (context, state);
3459 /* Yuck, fonts are created on-demand but we don't return a ref.
3460 * Do bad things to achieve this requirement */
3461 description = g_object_get_data (G_OBJECT (data->store), "font-cache-for-get_font");
3462 if (description == NULL)
3464 gtk_style_context_get (context, state, "font", &description, NULL);
3465 g_object_set_data_full (G_OBJECT (data->store),
3466 "font-cache-for-get_font",
3468 (GDestroyNotify) pango_font_description_free);
3474 get_cursor_color (GtkStyleContext *context,
3478 GdkColor *style_color;
3480 gtk_style_context_get_style (context,
3481 primary ? "cursor-color" : "secondary-cursor-color",
3487 color->red = style_color->red / 65535.0;
3488 color->green = style_color->green / 65535.0;
3489 color->blue = style_color->blue / 65535.0;
3492 gdk_color_free (style_color);
3496 gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, color);
3502 gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &bg);
3504 color->red = (color->red + bg.red) * 0.5;
3505 color->green = (color->green + bg.green) * 0.5;
3506 color->blue = (color->blue + bg.blue) * 0.5;
3512 _gtk_style_context_get_cursor_color (GtkStyleContext *context,
3513 GdkRGBA *primary_color,
3514 GdkRGBA *secondary_color)
3517 get_cursor_color (context, TRUE, primary_color);
3519 if (secondary_color)
3520 get_cursor_color (context, FALSE, secondary_color);
3527 * @context: a #GtkStyleContext
3529 * @x: X origin of the rectangle
3530 * @y: Y origin of the rectangle
3531 * @width: rectangle width
3532 * @height: rectangle height
3534 * Renders a checkmark (as in a #GtkCheckButton).
3536 * The %GTK_STATE_FLAG_ACTIVE state determines whether the check is
3537 * on or off, and %GTK_STATE_FLAG_INCONSISTENT determines whether it
3538 * should be marked as undefined.
3541 * <title>Typical checkmark rendering</title>
3542 * <inlinegraphic fileref="checks.png" format="PNG"/>
3548 gtk_render_check (GtkStyleContext *context,
3555 GtkStyleContextPrivate *priv;
3556 GtkThemingEngineClass *engine_class;
3558 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3559 g_return_if_fail (cr != NULL);
3561 if (width <= 0 || height <= 0)
3564 priv = context->priv;
3565 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3569 store_animation_region (context, x, y, width, height);
3571 _gtk_theming_engine_set_context (priv->theming_engine, context);
3572 engine_class->render_check (priv->theming_engine, cr,
3573 x, y, width, height);
3579 * gtk_render_option:
3580 * @context: a #GtkStyleContext
3582 * @x: X origin of the rectangle
3583 * @y: Y origin of the rectangle
3584 * @width: rectangle width
3585 * @height: rectangle height
3587 * Renders an option mark (as in a #GtkRadioButton), the %GTK_STATE_FLAG_ACTIVE
3588 * state will determine whether the option is on or off, and
3589 * %GTK_STATE_FLAG_INCONSISTENT whether it should be marked as undefined.
3592 * <title>Typical option mark rendering</title>
3593 * <inlinegraphic fileref="options.png" format="PNG"/>
3599 gtk_render_option (GtkStyleContext *context,
3606 GtkStyleContextPrivate *priv;
3607 GtkThemingEngineClass *engine_class;
3609 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3610 g_return_if_fail (cr != NULL);
3612 if (width <= 0 || height <= 0)
3615 priv = context->priv;
3616 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3620 store_animation_region (context, x, y, width, height);
3622 _gtk_theming_engine_set_context (priv->theming_engine, context);
3623 engine_class->render_option (priv->theming_engine, cr,
3624 x, y, width, height);
3631 * @context: a #GtkStyleContext
3633 * @angle: arrow angle from 0 to 2 * %G_PI, being 0 the arrow pointing to the north
3634 * @x: X origin of the render area
3635 * @y: Y origin of the render area
3636 * @size: square side for render area
3638 * Renders an arrow pointing to @angle.
3641 * <title>Typical arrow rendering at 0, 1&solidus;2 π, π and 3&solidus;2 π</title>
3642 * <inlinegraphic fileref="arrows.png" format="PNG"/>
3648 gtk_render_arrow (GtkStyleContext *context,
3655 GtkStyleContextPrivate *priv;
3656 GtkThemingEngineClass *engine_class;
3658 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3659 g_return_if_fail (cr != NULL);
3664 priv = context->priv;
3665 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3669 gtk_style_context_save (context);
3670 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ARROW);
3672 store_animation_region (context, x, y, size, size);
3674 _gtk_theming_engine_set_context (priv->theming_engine, context);
3675 engine_class->render_arrow (priv->theming_engine, cr,
3678 gtk_style_context_restore (context);
3683 * gtk_render_background:
3684 * @context: a #GtkStyleContext
3686 * @x: X origin of the rectangle
3687 * @y: Y origin of the rectangle
3688 * @width: rectangle width
3689 * @height: rectangle height
3691 * Renders the background of an element.
3694 * <title>Typical background rendering, showing the effect of
3695 * <parameter>background-image</parameter>,
3696 * <parameter>border-width</parameter> and
3697 * <parameter>border-radius</parameter></title>
3698 * <inlinegraphic fileref="background.png" format="PNG"/>
3704 gtk_render_background (GtkStyleContext *context,
3711 GtkStyleContextPrivate *priv;
3712 GtkThemingEngineClass *engine_class;
3714 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3715 g_return_if_fail (cr != NULL);
3717 if (width <= 0 || height <= 0)
3720 priv = context->priv;
3721 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3725 store_animation_region (context, x, y, width, height);
3727 _gtk_theming_engine_set_context (priv->theming_engine, context);
3728 engine_class->render_background (priv->theming_engine, cr, x, y, width, height);
3735 * @context: a #GtkStyleContext
3737 * @x: X origin of the rectangle
3738 * @y: Y origin of the rectangle
3739 * @width: rectangle width
3740 * @height: rectangle height
3742 * Renders a frame around the rectangle defined by @x, @y, @width, @height.
3745 * <title>Examples of frame rendering, showing the effect of
3746 * <parameter>border-image</parameter>,
3747 * <parameter>border-color</parameter>,
3748 * <parameter>border-width</parameter>,
3749 * <parameter>border-radius</parameter> and
3751 * <inlinegraphic fileref="frames.png" format="PNG"/>
3757 gtk_render_frame (GtkStyleContext *context,
3764 GtkStyleContextPrivate *priv;
3765 GtkThemingEngineClass *engine_class;
3767 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3768 g_return_if_fail (cr != NULL);
3770 if (width <= 0 || height <= 0)
3773 priv = context->priv;
3774 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3778 store_animation_region (context, x, y, width, height);
3780 _gtk_theming_engine_set_context (priv->theming_engine, context);
3781 engine_class->render_frame (priv->theming_engine, cr, x, y, width, height);
3787 * gtk_render_expander:
3788 * @context: a #GtkStyleContext
3790 * @x: X origin of the rectangle
3791 * @y: Y origin of the rectangle
3792 * @width: rectangle width
3793 * @height: rectangle height
3795 * Renders an expander (as used in #GtkTreeView and #GtkExpander) in the area
3796 * defined by @x, @y, @width, @height. The state %GTK_STATE_FLAG_ACTIVE
3797 * determines whether the expander is collapsed or expanded.
3800 * <title>Typical expander rendering</title>
3801 * <inlinegraphic fileref="expanders.png" format="PNG"/>
3807 gtk_render_expander (GtkStyleContext *context,
3814 GtkStyleContextPrivate *priv;
3815 GtkThemingEngineClass *engine_class;
3817 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3818 g_return_if_fail (cr != NULL);
3820 if (width <= 0 || height <= 0)
3823 priv = context->priv;
3824 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3828 store_animation_region (context, x, y, width, height);
3830 _gtk_theming_engine_set_context (priv->theming_engine, context);
3831 engine_class->render_expander (priv->theming_engine, cr, x, y, width, height);
3838 * @context: a #GtkStyleContext
3840 * @x: X origin of the rectangle
3841 * @y: Y origin of the rectangle
3842 * @width: rectangle width
3843 * @height: rectangle height
3845 * Renders a focus indicator on the rectangle determined by @x, @y, @width, @height.
3847 * <title>Typical focus rendering</title>
3848 * <inlinegraphic fileref="focus.png" format="PNG"/>
3854 gtk_render_focus (GtkStyleContext *context,
3861 GtkStyleContextPrivate *priv;
3862 GtkThemingEngineClass *engine_class;
3864 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3865 g_return_if_fail (cr != NULL);
3867 if (width <= 0 || height <= 0)
3870 priv = context->priv;
3871 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3875 store_animation_region (context, x, y, width, height);
3877 _gtk_theming_engine_set_context (priv->theming_engine, context);
3878 engine_class->render_focus (priv->theming_engine, cr, x, y, width, height);
3884 * gtk_render_layout:
3885 * @context: a #GtkStyleContext
3889 * @layout: the #PangoLayout to render
3891 * Renders @layout on the coordinates @x, @y
3896 gtk_render_layout (GtkStyleContext *context,
3900 PangoLayout *layout)
3902 GtkStyleContextPrivate *priv;
3903 GtkThemingEngineClass *engine_class;
3904 PangoRectangle extents;
3906 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3907 g_return_if_fail (PANGO_IS_LAYOUT (layout));
3908 g_return_if_fail (cr != NULL);
3910 priv = context->priv;
3911 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3915 pango_layout_get_extents (layout, &extents, NULL);
3917 store_animation_region (context,
3923 _gtk_theming_engine_set_context (priv->theming_engine, context);
3924 engine_class->render_layout (priv->theming_engine, cr, x, y, layout);
3931 * @context: a #GtkStyleContext
3933 * @x0: X coordinate for the origin of the line
3934 * @y0: Y coordinate for the origin of the line
3935 * @x1: X coordinate for the end of the line
3936 * @y1: Y coordinate for the end of the line
3938 * Renders a line from (x0, y0) to (x1, y1).
3943 gtk_render_line (GtkStyleContext *context,
3950 GtkStyleContextPrivate *priv;
3951 GtkThemingEngineClass *engine_class;
3953 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3954 g_return_if_fail (cr != NULL);
3956 priv = context->priv;
3957 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3961 _gtk_theming_engine_set_context (priv->theming_engine, context);
3962 engine_class->render_line (priv->theming_engine, cr, x0, y0, x1, y1);
3968 * gtk_render_slider:
3969 * @context: a #GtkStyleContext
3971 * @x: X origin of the rectangle
3972 * @y: Y origin of the rectangle
3973 * @width: rectangle width
3974 * @height: rectangle height
3975 * @orientation: orientation of the slider
3977 * Renders a slider (as in #GtkScale) in the rectangle defined by @x, @y,
3978 * @width, @height. @orientation defines whether the slider is vertical
3982 * <title>Typical slider rendering</title>
3983 * <inlinegraphic fileref="sliders.png" format="PNG"/>
3989 gtk_render_slider (GtkStyleContext *context,
3995 GtkOrientation orientation)
3997 GtkStyleContextPrivate *priv;
3998 GtkThemingEngineClass *engine_class;
4000 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4001 g_return_if_fail (cr != NULL);
4003 if (width <= 0 || height <= 0)
4006 priv = context->priv;
4007 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4011 store_animation_region (context, x, y, width, height);
4013 _gtk_theming_engine_set_context (priv->theming_engine, context);
4014 engine_class->render_slider (priv->theming_engine, cr, x, y, width, height, orientation);
4020 * gtk_render_frame_gap:
4021 * @context: a #GtkStyleContext
4023 * @x: X origin of the rectangle
4024 * @y: Y origin of the rectangle
4025 * @width: rectangle width
4026 * @height: rectangle height
4027 * @gap_side: side where the gap is
4028 * @xy0_gap: initial coordinate (X or Y depending on @gap_side) for the gap
4029 * @xy1_gap: end coordinate (X or Y depending on @gap_side) for the gap
4031 * Renders a frame around the rectangle defined by (@x, @y, @width, @height),
4032 * leaving a gap on one side. @xy0_gap and @xy1_gap will mean X coordinates
4033 * for %GTK_POS_TOP and %GTK_POS_BOTTOM gap sides, and Y coordinates for
4034 * %GTK_POS_LEFT and %GTK_POS_RIGHT.
4037 * <title>Typical rendering of a frame with a gap</title>
4038 * <inlinegraphic fileref="frame-gap.png" format="PNG"/>
4044 gtk_render_frame_gap (GtkStyleContext *context,
4050 GtkPositionType gap_side,
4054 GtkStyleContextPrivate *priv;
4055 GtkThemingEngineClass *engine_class;
4057 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4058 g_return_if_fail (cr != NULL);
4059 g_return_if_fail (xy0_gap <= xy1_gap);
4060 g_return_if_fail (xy0_gap >= 0);
4062 if (width <= 0 || height <= 0)
4065 if (gap_side == GTK_POS_LEFT ||
4066 gap_side == GTK_POS_RIGHT)
4067 g_return_if_fail (xy1_gap <= height);
4069 g_return_if_fail (xy1_gap <= width);
4071 priv = context->priv;
4072 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4076 store_animation_region (context, x, y, width, height);
4078 _gtk_theming_engine_set_context (priv->theming_engine, context);
4079 engine_class->render_frame_gap (priv->theming_engine, cr,
4080 x, y, width, height, gap_side,
4087 * gtk_render_extension:
4088 * @context: a #GtkStyleContext
4090 * @x: X origin of the rectangle
4091 * @y: Y origin of the rectangle
4092 * @width: rectangle width
4093 * @height: rectangle height
4094 * @gap_side: side where the gap is
4096 * Renders a extension (as in a #GtkNotebook tab) in the rectangle
4097 * defined by @x, @y, @width, @height. The side where the extension
4098 * connects to is defined by @gap_side.
4101 * <title>Typical extension rendering</title>
4102 * <inlinegraphic fileref="extensions.png" format="PNG"/>
4108 gtk_render_extension (GtkStyleContext *context,
4114 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);
4122 if (width <= 0 || height <= 0)
4125 priv = context->priv;
4126 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4130 store_animation_region (context, x, y, width, height);
4132 _gtk_theming_engine_set_context (priv->theming_engine, context);
4133 engine_class->render_extension (priv->theming_engine, cr, x, y, width, height, gap_side);
4139 * gtk_render_handle:
4140 * @context: a #GtkStyleContext
4142 * @x: X origin of the rectangle
4143 * @y: Y origin of the rectangle
4144 * @width: rectangle width
4145 * @height: rectangle height
4147 * Renders a handle (as in #GtkHandleBox, #GtkPaned and
4148 * #GtkWindow<!-- -->'s resize grip), in the rectangle
4149 * determined by @x, @y, @width, @height.
4152 * <title>Handles rendered for the paned and grip classes</title>
4153 * <inlinegraphic fileref="handles.png" format="PNG"/>
4159 gtk_render_handle (GtkStyleContext *context,
4166 GtkStyleContextPrivate *priv;
4167 GtkThemingEngineClass *engine_class;
4169 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4170 g_return_if_fail (cr != NULL);
4172 if (width <= 0 || height <= 0)
4175 priv = context->priv;
4176 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4180 store_animation_region (context, x, y, width, height);
4182 _gtk_theming_engine_set_context (priv->theming_engine, context);
4183 engine_class->render_handle (priv->theming_engine, cr, x, y, width, height);
4189 * gtk_render_activity:
4190 * @context: a #GtkStyleContext
4192 * @x: X origin of the rectangle
4193 * @y: Y origin of the rectangle
4194 * @width: rectangle width
4195 * @height: rectangle height
4197 * Renders an activity area (Such as in #GtkSpinner or the
4198 * fill line in #GtkRange), the state %GTK_STATE_FLAG_ACTIVE
4199 * determines whether there is activity going on.
4204 gtk_render_activity (GtkStyleContext *context,
4211 GtkStyleContextPrivate *priv;
4212 GtkThemingEngineClass *engine_class;
4214 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4215 g_return_if_fail (cr != NULL);
4217 if (width <= 0 || height <= 0)
4220 priv = context->priv;
4221 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4225 store_animation_region (context, x, y, width, height);
4227 _gtk_theming_engine_set_context (priv->theming_engine, context);
4228 engine_class->render_activity (priv->theming_engine, cr, x, y, width, height);
4234 * gtk_render_icon_pixbuf:
4235 * @context: a #GtkStyleContext
4236 * @source: the #GtkIconSource specifying the icon to render
4237 * @size: (type int): the size to render the icon at. A size of (GtkIconSize) -1
4238 * means render at the size of the source and don't scale.
4240 * Renders the icon specified by @source at the given @size, returning the result
4243 * Returns: (transfer full): a newly-created #GdkPixbuf containing the rendered icon
4248 gtk_render_icon_pixbuf (GtkStyleContext *context,
4249 const GtkIconSource *source,
4252 GtkStyleContextPrivate *priv;
4253 GtkThemingEngineClass *engine_class;
4255 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
4256 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
4257 g_return_val_if_fail (source != NULL, NULL);
4259 priv = context->priv;
4260 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4262 _gtk_theming_engine_set_context (priv->theming_engine, context);
4263 return engine_class->render_icon_pixbuf (priv->theming_engine, source, size);
4268 * @context: a #GtkStyleContext
4270 * @pixbuf: a #GdkPixbuf containing the icon to draw
4271 * @x: X position for the @pixbuf
4272 * @y: Y position for the @pixbuf
4274 * Renders the icon in @pixbuf at the specified @x and @y coordinates.
4279 gtk_render_icon (GtkStyleContext *context,
4285 GtkStyleContextPrivate *priv;
4286 GtkThemingEngineClass *engine_class;
4288 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4289 g_return_if_fail (cr != NULL);
4291 priv = context->priv;
4292 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
4296 store_animation_region (context,
4298 gdk_pixbuf_get_width (pixbuf),
4299 gdk_pixbuf_get_height (pixbuf));
4301 _gtk_theming_engine_set_context (priv->theming_engine, context);
4302 engine_class->render_icon (priv->theming_engine, cr, pixbuf, x, y);
4308 draw_insertion_cursor (GtkStyleContext *context,
4313 gboolean is_primary,
4314 PangoDirection direction,
4315 gboolean draw_arrow)
4318 GdkRGBA primary_color;
4319 GdkRGBA secondary_color;
4320 gfloat cursor_aspect_ratio;
4326 _gtk_style_context_get_cursor_color (context, &primary_color, &secondary_color);
4327 gdk_cairo_set_source_rgba (cr, is_primary ? &primary_color : &secondary_color);
4329 /* When changing the shape or size of the cursor here,
4330 * propagate the changes to gtktextview.c:text_window_invalidate_cursors().
4333 gtk_style_context_get_style (context,
4334 "cursor-aspect-ratio", &cursor_aspect_ratio,
4337 stem_width = height * cursor_aspect_ratio + 1;
4339 /* put (stem_width % 2) on the proper side of the cursor */
4340 if (direction == PANGO_DIRECTION_LTR)
4341 offset = stem_width / 2;
4343 offset = stem_width - stem_width / 2;
4345 cairo_rectangle (cr, x - offset, y, stem_width, height);
4353 arrow_width = stem_width + 1;
4355 if (direction == PANGO_DIRECTION_RTL)
4357 ax = x - offset - 1;
4358 ay = y + height - arrow_width * 2 - arrow_width + 1;
4360 cairo_move_to (cr, ax, ay + 1);
4361 cairo_line_to (cr, ax - arrow_width, ay + arrow_width);
4362 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4365 else if (direction == PANGO_DIRECTION_LTR)
4367 ax = x + stem_width - offset;
4368 ay = y + height - arrow_width * 2 - arrow_width + 1;
4370 cairo_move_to (cr, ax, ay + 1);
4371 cairo_line_to (cr, ax + arrow_width, ay + arrow_width);
4372 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4376 g_assert_not_reached();
4383 * gtk_render_insertion_cursor:
4384 * @context: a #GtkStyleContext
4388 * @layout: the #PangoLayout of the text
4389 * @index: the index in the #PangoLayout
4390 * @direction: the #PangoDirection of the text
4392 * Draws a text caret on @cr at the specified index of @layout.
4397 gtk_render_insertion_cursor (GtkStyleContext *context,
4401 PangoLayout *layout,
4403 PangoDirection direction)
4405 GtkStyleContextPrivate *priv;
4406 gboolean split_cursor;
4407 PangoRectangle strong_pos, weak_pos;
4408 PangoRectangle *cursor1, *cursor2;
4409 PangoDirection keymap_direction;
4410 PangoDirection direction2;
4412 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4413 g_return_if_fail (cr != NULL);
4414 g_return_if_fail (PANGO_IS_LAYOUT (layout));
4415 g_return_if_fail (index >= 0);
4417 priv = context->priv;
4419 g_object_get (gtk_settings_get_for_screen (priv->screen),
4420 "gtk-split-cursor", &split_cursor,
4423 keymap_direction = gdk_keymap_get_direction (gdk_keymap_get_for_display (gdk_screen_get_display (priv->screen)));
4425 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4427 direction2 = PANGO_DIRECTION_NEUTRAL;
4431 cursor1 = &strong_pos;
4433 if (strong_pos.x != weak_pos.x || strong_pos.y != weak_pos.y)
4435 direction2 = (direction == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
4436 cursor2 = &weak_pos;
4441 if (keymap_direction == direction)
4442 cursor1 = &strong_pos;
4444 cursor1 = &weak_pos;
4447 draw_insertion_cursor (context,
4449 x + PANGO_PIXELS (cursor1->x),
4450 y + PANGO_PIXELS (cursor1->y),
4451 PANGO_PIXELS (cursor1->height),
4454 direction2 != PANGO_DIRECTION_NEUTRAL);
4456 if (direction2 != PANGO_DIRECTION_NEUTRAL)
4458 draw_insertion_cursor (context,
4460 x + PANGO_PIXELS (cursor2->x),
4461 y + PANGO_PIXELS (cursor2->y),
4462 PANGO_PIXELS (cursor2->height),
4470 * gtk_draw_insertion_cursor:
4471 * @widget: a #GtkWidget
4472 * @cr: cairo context to draw to
4473 * @location: location where to draw the cursor (@location->width is ignored)
4474 * @is_primary: if the cursor should be the primary cursor color.
4475 * @direction: whether the cursor is left-to-right or
4476 * right-to-left. Should never be #GTK_TEXT_DIR_NONE
4477 * @draw_arrow: %TRUE to draw a directional arrow on the
4478 * cursor. Should be %FALSE unless the cursor is split.
4480 * Draws a text caret on @cr at @location. This is not a style function
4481 * but merely a convenience function for drawing the standard cursor shape.
4484 * Deprecated: 3.4: Use gtk_render_insertion_cursor() instead.
4487 gtk_draw_insertion_cursor (GtkWidget *widget,
4489 const GdkRectangle *location,
4490 gboolean is_primary,
4491 GtkTextDirection direction,
4492 gboolean draw_arrow)
4494 GtkStyleContext *context;
4496 g_return_if_fail (GTK_IS_WIDGET (widget));
4497 g_return_if_fail (cr != NULL);
4498 g_return_if_fail (location != NULL);
4499 g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
4501 context = gtk_widget_get_style_context (widget);
4503 draw_insertion_cursor (context, cr,
4504 location->x, location->y, location->height,
4506 (direction == GTK_TEXT_DIR_RTL) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR,
4510 static AtkAttributeSet *
4511 add_attribute (AtkAttributeSet *attributes,
4512 AtkTextAttribute attr,
4517 at = g_new (AtkAttribute, 1);
4518 at->name = g_strdup (atk_text_attribute_get_name (attr));
4519 at->value = g_strdup (value);
4521 return g_slist_prepend (attributes, at);
4525 * _gtk_style_context_get_attributes:
4526 * @attributes: a #AtkAttributeSet to add attributes to
4527 * @context: the #GtkStyleContext to get attributes from
4528 * @flags: the state to use with @context
4530 * Adds the foreground and background color from @context to
4531 * @attributes, after translating them to ATK attributes.
4533 * This is a convenience function that can be used in
4534 * implementing the #AtkText interface in widgets.
4536 * Returns: the modified #AtkAttributeSet
4539 _gtk_style_context_get_attributes (AtkAttributeSet *attributes,
4540 GtkStyleContext *context,
4541 GtkStateFlags flags)
4546 gtk_style_context_get_background_color (context, flags, &color);
4547 value = g_strdup_printf ("%u,%u,%u",
4548 (guint) ceil (color.red * 65536 - color.red),
4549 (guint) ceil (color.green * 65536 - color.green),
4550 (guint) ceil (color.blue * 65536 - color.blue));
4551 attributes = add_attribute (attributes, ATK_TEXT_ATTR_BG_COLOR, value);
4554 gtk_style_context_get_color (context, flags, &color);
4555 value = g_strdup_printf ("%u,%u,%u",
4556 (guint) ceil (color.red * 65536 - color.red),
4557 (guint) ceil (color.green * 65536 - color.green),
4558 (guint) ceil (color.blue * 65536 - color.blue));
4559 attributes = add_attribute (attributes, ATK_TEXT_ATTR_FG_COLOR, value);