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 "gtkcssenginevalueprivate.h"
27 #include "gtkcssrgbavalueprivate.h"
28 #include "gtkstylepropertiesprivate.h"
29 #include "gtktypebuiltins.h"
30 #include "gtkthemingengineprivate.h"
32 #include "gtkwidget.h"
33 #include "gtkwindow.h"
34 #include "gtkprivate.h"
35 #include "gtksymboliccolorprivate.h"
36 #include "gtkcssnumbervalueprivate.h"
37 #include "gtkiconfactory.h"
38 #include "gtkwidgetpath.h"
39 #include "gtkwidgetprivate.h"
40 #include "gtkstylecascadeprivate.h"
41 #include "gtkstyleproviderprivate.h"
42 #include "gtksettings.h"
45 * SECTION:gtkstylecontext
46 * @Short_description: Rendering UI elements
47 * @Title: GtkStyleContext
49 * #GtkStyleContext is an object that stores styling information affecting
50 * a widget defined by #GtkWidgetPath.
52 * In order to construct the final style information, #GtkStyleContext
53 * queries information from all attached #GtkStyleProviders. Style providers
54 * can be either attached explicitly to the context through
55 * gtk_style_context_add_provider(), or to the screen through
56 * gtk_style_context_add_provider_for_screen(). The resulting style is a
57 * combination of all providers' information in priority order.
59 * For GTK+ widgets, any #GtkStyleContext returned by
60 * gtk_widget_get_style_context() will already have a #GtkWidgetPath, a
61 * #GdkScreen and RTL/LTR information set. The style context will be also
62 * updated automatically if any of these settings change on the widget.
64 * If you are using the theming layer standalone, you will need to set a
65 * widget path and a screen yourself to the created style context through
66 * gtk_style_context_set_path() and gtk_style_context_set_screen(), as well
67 * as updating the context yourself using gtk_style_context_invalidate()
68 * whenever any of the conditions change, such as a change in the
69 * #GtkSettings:gtk-theme-name setting or a hierarchy change in the rendered
72 * <refsect2 id="gtkstylecontext-animations">
73 * <title>Transition animations</title>
75 * #GtkStyleContext has built-in support for state change transitions.
76 * Note that these animations respect the #GtkSettings:gtk-enable-animations
80 * For simple widgets where state changes affect the whole widget area,
81 * calling gtk_style_context_notify_state_change() with a %NULL region
82 * is sufficient to trigger the transition animation. And GTK+ already
83 * does that when gtk_widget_set_state() or gtk_widget_set_state_flags()
87 * If a widget needs to declare several animatable regions (i.e. not
88 * affecting the whole widget area), its #GtkWidget::draw signal handler
89 * needs to wrap the render operations for the different regions with
90 * calls to gtk_style_context_push_animatable_region() and
91 * gtk_style_context_pop_animatable_region(). These functions take an
92 * identifier for the region which must be unique within the style context.
93 * For simple widgets with a fixed set of animatable regions, using an
94 * enumeration works well:
97 * <title>Using an enumeration to identify animatable regions</title>
108 * spin_button_draw (GtkWidget *widget,
111 * GtkStyleContext *context;
113 * context = gtk_widget_get_style_context (widget);
115 * gtk_style_context_push_animatable_region (context,
116 * GUINT_TO_POINTER (REGION_ENTRY));
118 * gtk_render_background (cr, 0, 0, 100, 30);
119 * gtk_render_frame (cr, 0, 0, 100, 30);
121 * gtk_style_context_pop_animatable_region (context);
128 * For complex widgets with an arbitrary number of animatable regions, it
129 * is up to the implementation to come up with a way to uniquely identify
130 * each animatable region. Using pointers to internal structs is one way
134 * <title>Using struct pointers to identify animatable regions</title>
137 * notebook_draw_tab (GtkWidget *widget,
138 * NotebookPage *page,
141 * gtk_style_context_push_animatable_region (context, page);
142 * gtk_render_extension (cr, page->x, page->y, page->width, page->height);
143 * gtk_style_context_pop_animatable_region (context);
148 * The widget also needs to notify the style context about a state change
149 * for a given animatable region so the animation is triggered.
152 * <title>Triggering a state change animation on a region</title>
155 * notebook_motion_notify (GtkWidget *widget,
156 * GdkEventMotion *event)
158 * GtkStyleContext *context;
159 * NotebookPage *page;
161 * context = gtk_widget_get_style_context (widget);
162 * page = find_page_under_pointer (widget, event);
163 * gtk_style_context_notify_state_change (context,
164 * gtk_widget_get_window (widget),
166 * GTK_STATE_PRELIGHT,
173 * gtk_style_context_notify_state_change() accepts %NULL region IDs as a
174 * special value, in this case, the whole widget area will be updated
178 * <refsect2 id="gtkstylecontext-classes">
179 * <title>Style classes and regions</title>
181 * Widgets can add style classes to their context, which can be used
182 * to associate different styles by class (see <xref linkend="gtkcssprovider-selectors"/>). Theme engines can also use style classes to vary their
183 * rendering. GTK+ has a number of predefined style classes:
184 * #GTK_STYLE_CLASS_CELL,
185 * #GTK_STYLE_CLASS_ENTRY,
186 * #GTK_STYLE_CLASS_BUTTON,
187 * #GTK_STYLE_CLASS_COMBOBOX_ENTRY,
188 * #GTK_STYLE_CLASS_CALENDAR,
189 * #GTK_STYLE_CLASS_SLIDER,
190 * #GTK_STYLE_CLASS_BACKGROUND,
191 * #GTK_STYLE_CLASS_RUBBERBAND,
192 * #GTK_STYLE_CLASS_TOOLTIP,
193 * #GTK_STYLE_CLASS_MENU,
194 * #GTK_STYLE_CLASS_MENUBAR,
195 * #GTK_STYLE_CLASS_MENUITEM,
196 * #GTK_STYLE_CLASS_TOOLBAR,
197 * #GTK_STYLE_CLASS_PRIMARY_TOOLBAR,
198 * #GTK_STYLE_CLASS_INLINE_TOOLBAR,
199 * #GTK_STYLE_CLASS_RADIO,
200 * #GTK_STYLE_CLASS_CHECK,
201 * #GTK_STYLE_CLASS_TROUGH,
202 * #GTK_STYLE_CLASS_SCROLLBAR,
203 * #GTK_STYLE_CLASS_SCALE,
204 * #GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE,
205 * #GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW,
206 * #GTK_STYLE_CLASS_HEADER,
207 * #GTK_STYLE_CLASS_ACCELERATOR,
208 * #GTK_STYLE_CLASS_GRIP,
209 * #GTK_STYLE_CLASS_DOCK,
210 * #GTK_STYLE_CLASS_PROGRESSBAR,
211 * #GTK_STYLE_CLASS_SPINNER,
212 * #GTK_STYLE_CLASS_EXPANDER,
213 * #GTK_STYLE_CLASS_SPINBUTTON,
214 * #GTK_STYLE_CLASS_NOTEBOOK,
215 * #GTK_STYLE_CLASS_VIEW,
216 * #GTK_STYLE_CLASS_SIDEBAR,
217 * #GTK_STYLE_CLASS_IMAGE,
218 * #GTK_STYLE_CLASS_HIGHLIGHT,
219 * #GTK_STYLE_CLASS_FRAME,
220 * #GTK_STYLE_CLASS_DND,
221 * #GTK_STYLE_CLASS_PANE_SEPARATOR,
222 * #GTK_STYLE_CLASS_SEPARATOR,
223 * #GTK_STYLE_CLASS_INFO,
224 * #GTK_STYLE_CLASS_WARNING,
225 * #GTK_STYLE_CLASS_QUESTION,
226 * #GTK_STYLE_CLASS_ERROR,
227 * #GTK_STYLE_CLASS_HORIZONTAL,
228 * #GTK_STYLE_CLASS_VERTICAL,
229 * #GTK_STYLE_CLASS_TOP,
230 * #GTK_STYLE_CLASS_BOTTOM,
231 * #GTK_STYLE_CLASS_LEFT,
232 * #GTK_STYLE_CLASS_RIGHT,
235 * Widgets can also add regions with flags to their context.
236 * The regions used by GTK+ widgets are:
241 * <entry>Region</entry>
242 * <entry>Flags</entry>
243 * <entry>Macro</entry>
244 * <entry>Used by</entry>
250 * <entry>even, odd</entry>
251 * <entry>GTK_STYLE_REGION_ROW</entry>
252 * <entry>#GtkTreeView</entry>
255 * <entry>column</entry>
256 * <entry>first, last, sorted</entry>
257 * <entry>GTK_STYLE_REGION_COLUMN</entry>
258 * <entry>#GtkTreeView</entry>
261 * <entry>column-header</entry>
263 * <entry>GTK_STYLE_REGION_COLUMN_HEADER</entry>
268 * <entry>even, odd, first, last</entry>
269 * <entry>GTK_STYLE_REGION_TAB</entry>
270 * <entry>#GtkNotebook</entry>
277 * <refsect2 id="gtkstylecontext-custom-styling">
278 * <title>Custom styling in UI libraries and applications</title>
280 * If you are developing a library with custom #GtkWidget<!-- -->s that
281 * render differently than standard components, you may need to add a
282 * #GtkStyleProvider yourself with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK
283 * priority, either a #GtkCssProvider or a custom object implementing the
284 * #GtkStyleProvider interface. This way theming engines may still attempt
285 * to style your UI elements in a different way if needed so.
288 * If you are using custom styling on an applications, you probably want then
289 * to make your style information prevail to the theme's, so you must use
290 * a #GtkStyleProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
291 * priority, keep in mind that the user settings in
292 * <filename><replaceable>XDG_CONFIG_HOME</replaceable>/gtk-3.0/gtk.css</filename> will
293 * still take precedence over your changes, as it uses the
294 * %GTK_STYLE_PROVIDER_PRIORITY_USER priority.
297 * If a custom theming engine is needed, you probably want to implement a
298 * #GtkStyleProvider yourself so it points to your #GtkThemingEngine
299 * implementation, as #GtkCssProvider uses gtk_theming_engine_load()
300 * which loads the theming engine module from the standard paths.
305 /* When these change we do a full restyling. Otherwise we try to figure out
306 * if we need to change things. */
307 #define GTK_STYLE_CONTEXT_RADICAL_CHANGE (GTK_CSS_CHANGE_NAME | GTK_CSS_CHANGE_CLASS)
308 /* When these change we don't clear the cache. This takes more memory but makes
309 * things go faster. */
310 #define GTK_STYLE_CONTEXT_CACHED_CHANGE (GTK_CSS_CHANGE_STATE)
312 typedef struct GtkStyleInfo GtkStyleInfo;
313 typedef struct GtkRegion GtkRegion;
314 typedef struct PropertyValue PropertyValue;
315 typedef struct StyleData StyleData;
320 GtkRegionFlags flags;
333 GArray *style_classes;
335 GtkJunctionSides junction_sides;
336 GtkStateFlags state_flags;
342 GtkCssComputedValues *store;
343 GArray *property_cache;
346 struct _GtkStyleContextPrivate
350 GtkStyleCascade *cascade;
352 GtkStyleContext *parent;
355 GtkWidgetPath *widget_path;
356 GHashTable *style_data;
359 GtkTextDirection direction;
361 GtkCssChange relevant_changes;
362 GtkCssChange pending_changes;
364 guint invalidating_context : 1;
380 static guint signals[LAST_SIGNAL] = { 0 };
382 static void gtk_style_context_finalize (GObject *object);
384 static void gtk_style_context_impl_set_property (GObject *object,
388 static void gtk_style_context_impl_get_property (GObject *object,
392 static GtkSymbolicColor *
393 gtk_style_context_color_lookup_func (gpointer contextp,
397 G_DEFINE_TYPE (GtkStyleContext, gtk_style_context, G_TYPE_OBJECT)
400 gtk_style_context_real_changed (GtkStyleContext *context)
402 GtkStyleContextPrivate *priv = context->priv;
405 _gtk_widget_style_context_invalidated (priv->widget);
409 gtk_style_context_class_init (GtkStyleContextClass *klass)
411 GObjectClass *object_class = G_OBJECT_CLASS (klass);
413 object_class->finalize = gtk_style_context_finalize;
414 object_class->set_property = gtk_style_context_impl_set_property;
415 object_class->get_property = gtk_style_context_impl_get_property;
417 klass->changed = gtk_style_context_real_changed;
420 g_signal_new (I_("changed"),
421 G_TYPE_FROM_CLASS (object_class),
423 G_STRUCT_OFFSET (GtkStyleContextClass, changed),
425 g_cclosure_marshal_VOID__VOID,
428 g_object_class_install_property (object_class,
430 g_param_spec_object ("screen",
432 P_("The associated GdkScreen"),
434 GTK_PARAM_READWRITE));
435 g_object_class_install_property (object_class,
437 g_param_spec_enum ("direction",
439 P_("Text direction"),
440 GTK_TYPE_TEXT_DIRECTION,
442 GTK_PARAM_READWRITE));
444 * GtkStyleContext:parent:
446 * Sets or gets the style context's parent. See gtk_style_context_set_parent()
451 g_object_class_install_property (object_class,
453 g_param_spec_object ("parent",
455 P_("The parent style context"),
456 GTK_TYPE_STYLE_CONTEXT,
457 GTK_PARAM_READWRITE));
459 g_type_class_add_private (object_class, sizeof (GtkStyleContextPrivate));
462 static GtkStyleInfo *
463 style_info_new (void)
467 info = g_slice_new0 (GtkStyleInfo);
468 info->style_classes = g_array_new (FALSE, FALSE, sizeof (GQuark));
469 info->regions = g_array_new (FALSE, FALSE, sizeof (GtkRegion));
475 style_info_free (GtkStyleInfo *info)
477 g_array_free (info->style_classes, TRUE);
478 g_array_free (info->regions, TRUE);
479 g_slice_free (GtkStyleInfo, info);
482 static GtkStyleInfo *
483 style_info_copy (const GtkStyleInfo *info)
487 copy = style_info_new ();
488 g_array_insert_vals (copy->style_classes, 0,
489 info->style_classes->data,
490 info->style_classes->len);
492 g_array_insert_vals (copy->regions, 0,
496 copy->junction_sides = info->junction_sides;
497 copy->state_flags = info->state_flags;
498 copy->data = info->data;
504 style_info_hash (gconstpointer elem)
506 const GtkStyleInfo *info;
511 for (i = 0; i < info->style_classes->len; i++)
513 hash += g_array_index (info->style_classes, GQuark, i);
517 for (i = 0; i < info->regions->len; i++)
521 region = &g_array_index (info->regions, GtkRegion, i);
522 hash += region->class_quark;
523 hash += region->flags;
527 return hash ^ info->state_flags;
531 style_info_equal (gconstpointer elem1,
534 const GtkStyleInfo *info1, *info2;
539 if (info1->state_flags != info2->state_flags)
542 if (info1->junction_sides != info2->junction_sides)
545 if (info1->style_classes->len != info2->style_classes->len)
548 if (memcmp (info1->style_classes->data,
549 info2->style_classes->data,
550 info1->style_classes->len * sizeof (GQuark)) != 0)
553 if (info1->regions->len != info2->regions->len)
556 if (memcmp (info1->regions->data,
557 info2->regions->data,
558 info1->regions->len * sizeof (GtkRegion)) != 0)
565 style_data_new (void)
569 data = g_slice_new0 (StyleData);
575 clear_property_cache (StyleData *data)
579 if (!data->property_cache)
582 for (i = 0; i < data->property_cache->len; i++)
584 PropertyValue *node = &g_array_index (data->property_cache, PropertyValue, i);
586 g_param_spec_unref (node->pspec);
587 g_value_unset (&node->value);
590 g_array_free (data->property_cache, TRUE);
591 data->property_cache = NULL;
595 style_data_free (StyleData *data)
597 g_object_unref (data->store);
598 clear_property_cache (data);
600 g_slice_free (StyleData, data);
604 gtk_style_context_init (GtkStyleContext *style_context)
606 GtkStyleContextPrivate *priv;
609 priv = style_context->priv = G_TYPE_INSTANCE_GET_PRIVATE (style_context,
610 GTK_TYPE_STYLE_CONTEXT,
611 GtkStyleContextPrivate);
613 priv->style_data = g_hash_table_new_full (style_info_hash,
615 (GDestroyNotify) style_info_free,
616 (GDestroyNotify) style_data_free);
618 priv->direction = GTK_TEXT_DIR_LTR;
620 priv->screen = gdk_screen_get_default ();
621 priv->cascade = _gtk_style_cascade_get_for_screen (priv->screen);
622 g_object_ref (priv->cascade);
623 priv->relevant_changes = GTK_CSS_CHANGE_ANY;
625 /* Create default info store */
626 info = style_info_new ();
627 priv->info_stack = g_slist_prepend (priv->info_stack, info);
631 gtk_style_context_finalize (GObject *object)
633 GtkStyleContextPrivate *priv;
634 GtkStyleContext *style_context;
636 style_context = GTK_STYLE_CONTEXT (object);
637 priv = style_context->priv;
639 /* children hold a reference to us */
640 g_assert (priv->children == NULL);
642 gtk_style_context_set_parent (style_context, NULL);
644 if (priv->widget_path)
645 gtk_widget_path_free (priv->widget_path);
647 g_hash_table_destroy (priv->style_data);
649 g_object_unref (priv->cascade);
651 g_slist_free_full (priv->info_stack, (GDestroyNotify) style_info_free);
653 G_OBJECT_CLASS (gtk_style_context_parent_class)->finalize (object);
657 gtk_style_context_impl_set_property (GObject *object,
662 GtkStyleContext *style_context;
664 style_context = GTK_STYLE_CONTEXT (object);
669 gtk_style_context_set_screen (style_context,
670 g_value_get_object (value));
673 gtk_style_context_set_direction (style_context,
674 g_value_get_enum (value));
677 gtk_style_context_set_parent (style_context,
678 g_value_get_object (value));
681 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
687 gtk_style_context_impl_get_property (GObject *object,
692 GtkStyleContext *style_context;
693 GtkStyleContextPrivate *priv;
695 style_context = GTK_STYLE_CONTEXT (object);
696 priv = style_context->priv;
701 g_value_set_object (value, priv->screen);
704 g_value_set_enum (value, priv->direction);
707 g_value_set_object (value, priv->parent);
710 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
716 build_properties (GtkStyleContext *context,
717 StyleData *style_data,
721 GtkStyleContextPrivate *priv;
722 GtkCssMatcher matcher;
723 GtkCssLookup *lookup;
725 priv = context->priv;
727 _gtk_css_matcher_init (&matcher, path, state);
728 lookup = _gtk_css_lookup_new ();
730 _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
734 style_data->store = _gtk_css_computed_values_new ();
735 _gtk_css_lookup_resolve (lookup, context, style_data->store);
736 _gtk_css_lookup_free (lookup);
739 static GtkWidgetPath *
740 create_query_path (GtkStyleContext *context)
742 GtkStyleContextPrivate *priv;
747 priv = context->priv;
748 path = priv->widget ? _gtk_widget_create_path (priv->widget) : gtk_widget_path_copy (priv->widget_path);
749 pos = gtk_widget_path_length (path) - 1;
751 info = priv->info_stack->data;
753 /* Set widget regions */
754 for (i = 0; i < info->regions->len; i++)
758 region = &g_array_index (info->regions, GtkRegion, i);
759 gtk_widget_path_iter_add_region (path, pos,
760 g_quark_to_string (region->class_quark),
764 /* Set widget classes */
765 for (i = 0; i < info->style_classes->len; i++)
769 quark = g_array_index (info->style_classes, GQuark, i);
770 gtk_widget_path_iter_add_class (path, pos,
771 g_quark_to_string (quark));
778 style_data_lookup (GtkStyleContext *context)
780 GtkStyleContextPrivate *priv;
783 priv = context->priv;
784 info = priv->info_stack->data;
786 /* Current data in use is cached, just return it */
790 g_assert (priv->widget != NULL || priv->widget_path != NULL);
792 info->data = g_hash_table_lookup (priv->style_data, info);
798 path = create_query_path (context);
800 info->data = style_data_new ();
801 g_hash_table_insert (priv->style_data,
802 style_info_copy (info),
805 build_properties (context, info->data, path, info->state_flags);
807 gtk_widget_path_free (path);
814 gtk_style_context_set_invalid (GtkStyleContext *context,
817 GtkStyleContextPrivate *priv;
819 priv = context->priv;
821 if (priv->invalid == invalid)
824 priv->invalid = invalid;
829 gtk_style_context_set_invalid (priv->parent, TRUE);
830 else if (priv->widget)
831 gtk_widget_queue_resize (priv->widget);
835 /* returns TRUE if someone called gtk_style_context_save() but hasn't
836 * called gtk_style_context_restore() yet.
837 * In those situations we don't invalidate the context when somebody
838 * changes state/regions/classes.
841 gtk_style_context_is_saved (GtkStyleContext *context)
843 return context->priv->info_stack->next != NULL;
847 gtk_style_context_queue_invalidate_internal (GtkStyleContext *context,
850 GtkStyleContextPrivate *priv = context->priv;
851 GtkStyleInfo *info = priv->info_stack->data;
853 if (gtk_style_context_is_saved (context))
859 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_STATE);
860 /* XXX: We need to invalidate siblings here somehow */
865 * gtk_style_context_new:
867 * Creates a standalone #GtkStyleContext, this style context
868 * won't be attached to any widget, so you may want
869 * to call gtk_style_context_set_path() yourself.
872 * This function is only useful when using the theming layer
873 * separated from GTK+, if you are using #GtkStyleContext to
874 * theme #GtkWidget<!-- -->s, use gtk_widget_get_style_context()
875 * in order to get a style context ready to theme the widget.
878 * Returns: A newly created #GtkStyleContext.
881 gtk_style_context_new (void)
883 return g_object_new (GTK_TYPE_STYLE_CONTEXT, NULL);
887 _gtk_style_context_set_widget (GtkStyleContext *context,
890 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
891 g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget));
893 context->priv->widget = widget;
895 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY_SELF);
899 * gtk_style_context_add_provider:
900 * @context: a #GtkStyleContext
901 * @provider: a #GtkStyleProvider
902 * @priority: the priority of the style provider. The lower
903 * it is, the earlier it will be used in the style
904 * construction. Typically this will be in the range
905 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
906 * %GTK_STYLE_PROVIDER_PRIORITY_USER
908 * Adds a style provider to @context, to be used in style construction.
910 * <note><para>If both priorities are the same, A #GtkStyleProvider
911 * added through this function takes precedence over another added
912 * through gtk_style_context_add_provider_for_screen().</para></note>
917 gtk_style_context_add_provider (GtkStyleContext *context,
918 GtkStyleProvider *provider,
921 GtkStyleContextPrivate *priv;
923 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
924 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
926 priv = context->priv;
928 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
930 GtkStyleCascade *new_cascade;
932 new_cascade = _gtk_style_cascade_new ();
933 _gtk_style_cascade_set_parent (new_cascade, priv->cascade);
934 g_object_unref (priv->cascade);
935 priv->cascade = new_cascade;
938 _gtk_style_cascade_add_provider (priv->cascade, provider, priority);
940 gtk_style_context_invalidate (context);
944 * gtk_style_context_remove_provider:
945 * @context: a #GtkStyleContext
946 * @provider: a #GtkStyleProvider
948 * Removes @provider from the style providers list in @context.
953 gtk_style_context_remove_provider (GtkStyleContext *context,
954 GtkStyleProvider *provider)
956 GtkStyleContextPrivate *priv;
958 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
959 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
961 priv = context->priv;
963 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
966 _gtk_style_cascade_remove_provider (priv->cascade, provider);
970 * gtk_style_context_reset_widgets:
971 * @screen: a #GdkScreen
973 * This function recomputes the styles for all widgets under a particular
974 * #GdkScreen. This is useful when some global parameter has changed that
975 * affects the appearance of all widgets, because when a widget gets a new
976 * style, it will both redraw and recompute any cached information about
977 * its appearance. As an example, it is used when the color scheme changes
978 * in the related #GtkSettings object.
983 gtk_style_context_reset_widgets (GdkScreen *screen)
985 GList *list, *toplevels;
987 _gtk_icon_set_invalidate_caches ();
989 toplevels = gtk_window_list_toplevels ();
990 g_list_foreach (toplevels, (GFunc) g_object_ref, NULL);
992 for (list = toplevels; list; list = list->next)
994 if (gtk_widget_get_screen (list->data) == screen)
995 gtk_widget_reset_style (list->data);
997 g_object_unref (list->data);
1000 g_list_free (toplevels);
1004 * gtk_style_context_add_provider_for_screen:
1005 * @screen: a #GdkScreen
1006 * @provider: a #GtkStyleProvider
1007 * @priority: the priority of the style provider. The lower
1008 * it is, the earlier it will be used in the style
1009 * construction. Typically this will be in the range
1010 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1011 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1013 * Adds a global style provider to @screen, which will be used
1014 * in style construction for all #GtkStyleContext<!-- -->s under
1017 * GTK+ uses this to make styling information from #GtkSettings
1020 * <note><para>If both priorities are the same, A #GtkStyleProvider
1021 * added through gtk_style_context_add_provider() takes precedence
1022 * over another added through this function.</para></note>
1027 gtk_style_context_add_provider_for_screen (GdkScreen *screen,
1028 GtkStyleProvider *provider,
1031 GtkStyleCascade *cascade;
1033 g_return_if_fail (GDK_IS_SCREEN (screen));
1034 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1036 cascade = _gtk_style_cascade_get_for_screen (screen);
1037 _gtk_style_cascade_add_provider (cascade, provider, priority);
1041 * gtk_style_context_remove_provider_for_screen:
1042 * @screen: a #GdkScreen
1043 * @provider: a #GtkStyleProvider
1045 * Removes @provider from the global style providers list in @screen.
1050 gtk_style_context_remove_provider_for_screen (GdkScreen *screen,
1051 GtkStyleProvider *provider)
1053 GtkStyleCascade *cascade;
1055 g_return_if_fail (GDK_IS_SCREEN (screen));
1056 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1058 cascade = _gtk_style_cascade_get_for_screen (screen);
1059 _gtk_style_cascade_remove_provider (cascade, provider);
1063 * gtk_style_context_get_section:
1064 * @context: a #GtkStyleContext
1065 * @property: style property name
1067 * Queries the location in the CSS where @property was defined for the
1068 * current @context. Note that the state to be queried is taken from
1069 * gtk_style_context_get_state().
1071 * If the location is not available, %NULL will be returned. The
1072 * location might not be available for various reasons, such as the
1073 * property being overridden, @property not naming a supported CSS
1074 * property or tracking of definitions being disabled for performance
1077 * Shorthand CSS properties cannot be queried for a location and will
1078 * always return %NULL.
1080 * Returns: %NULL or the section where value was defined
1083 gtk_style_context_get_section (GtkStyleContext *context,
1084 const gchar *property)
1086 GtkStyleContextPrivate *priv;
1087 GtkStyleProperty *prop;
1090 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1091 g_return_val_if_fail (property != NULL, NULL);
1093 priv = context->priv;
1094 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
1096 prop = _gtk_style_property_lookup (property);
1097 if (!GTK_IS_CSS_STYLE_PROPERTY (prop))
1100 data = style_data_lookup (context);
1101 return _gtk_css_computed_values_get_section (data->store, _gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (prop)));
1104 static GtkCssValue *
1105 gtk_style_context_query_func (guint id,
1108 return _gtk_css_computed_values_get_value (values, id);
1112 * gtk_style_context_get_property:
1113 * @context: a #GtkStyleContext
1114 * @property: style property name
1115 * @state: state to retrieve the property value for
1116 * @value: (out) (transfer full): return location for the style property value
1118 * Gets a style property from @context for the given state.
1120 * When @value is no longer needed, g_value_unset() must be called
1121 * to free any allocated memory.
1126 gtk_style_context_get_property (GtkStyleContext *context,
1127 const gchar *property,
1128 GtkStateFlags state,
1131 GtkStyleContextPrivate *priv;
1132 GtkStyleProperty *prop;
1135 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1136 g_return_if_fail (property != NULL);
1137 g_return_if_fail (value != NULL);
1139 priv = context->priv;
1140 g_return_if_fail (priv->widget != NULL || priv->widget_path != NULL);
1142 prop = _gtk_style_property_lookup (property);
1145 g_warning ("Style property \"%s\" is not registered", property);
1148 if (_gtk_style_property_get_value_type (prop) == G_TYPE_NONE)
1150 g_warning ("Style property \"%s\" is not gettable", property);
1154 gtk_style_context_save (context);
1155 gtk_style_context_set_state (context, state);
1156 data = style_data_lookup (context);
1157 _gtk_style_property_query (prop, value, gtk_style_context_query_func, data->store);
1158 gtk_style_context_restore (context);
1162 * gtk_style_context_get_valist:
1163 * @context: a #GtkStyleContext
1164 * @state: state to retrieve the property values for
1165 * @args: va_list of property name/return location pairs, followed by %NULL
1167 * Retrieves several style property values from @context for a given state.
1172 gtk_style_context_get_valist (GtkStyleContext *context,
1173 GtkStateFlags state,
1176 const gchar *property_name;
1178 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1180 property_name = va_arg (args, const gchar *);
1182 while (property_name)
1184 gchar *error = NULL;
1185 GValue value = G_VALUE_INIT;
1187 gtk_style_context_get_property (context,
1192 G_VALUE_LCOPY (&value, args, 0, &error);
1193 g_value_unset (&value);
1197 g_warning ("Could not get style property \"%s\": %s", property_name, error);
1202 property_name = va_arg (args, const gchar *);
1207 * gtk_style_context_get:
1208 * @context: a #GtkStyleContext
1209 * @state: state to retrieve the property values for
1210 * @...: property name /return value pairs, followed by %NULL
1212 * Retrieves several style property values from @context for a
1218 gtk_style_context_get (GtkStyleContext *context,
1219 GtkStateFlags state,
1224 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1226 va_start (args, state);
1227 gtk_style_context_get_valist (context, state, args);
1232 * gtk_style_context_set_state:
1233 * @context: a #GtkStyleContext
1234 * @flags: state to represent
1236 * Sets the state to be used when rendering with any
1237 * of the gtk_render_*() functions.
1242 gtk_style_context_set_state (GtkStyleContext *context,
1243 GtkStateFlags flags)
1245 GtkStyleContextPrivate *priv;
1248 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1250 priv = context->priv;
1251 info = priv->info_stack->data;
1252 info->state_flags = flags;
1254 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_STATE);
1258 * gtk_style_context_get_state:
1259 * @context: a #GtkStyleContext
1261 * Returns the state used when rendering.
1263 * Returns: the state flags
1268 gtk_style_context_get_state (GtkStyleContext *context)
1270 GtkStyleContextPrivate *priv;
1273 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
1275 priv = context->priv;
1276 info = priv->info_stack->data;
1278 return info->state_flags;
1282 * gtk_style_context_state_is_running:
1283 * @context: a #GtkStyleContext
1284 * @state: a widget state
1285 * @progress: (out): return location for the transition progress
1287 * Returns %TRUE if there is a transition animation running for the
1288 * current region (see gtk_style_context_push_animatable_region()).
1290 * If @progress is not %NULL, the animation progress will be returned
1291 * there, 0.0 means the state is closest to being unset, while 1.0 means
1292 * it's closest to being set. This means transition animation will
1293 * run from 0 to 1 when @state is being set and from 1 to 0 when
1296 * Returns: %TRUE if there is a running transition animation for @state.
1300 * Deprecated: 3.6: This function always returns %FALSE
1303 gtk_style_context_state_is_running (GtkStyleContext *context,
1307 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1313 * gtk_style_context_set_path:
1314 * @context: a #GtkStyleContext
1315 * @path: a #GtkWidgetPath
1317 * Sets the #GtkWidgetPath used for style matching. As a
1318 * consequence, the style will be regenerated to match
1319 * the new given path.
1321 * If you are using a #GtkStyleContext returned from
1322 * gtk_widget_get_style_context(), you do not need to call
1328 gtk_style_context_set_path (GtkStyleContext *context,
1329 GtkWidgetPath *path)
1331 GtkStyleContextPrivate *priv;
1333 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1334 g_return_if_fail (path != NULL);
1336 priv = context->priv;
1337 g_return_if_fail (priv->widget == NULL);
1339 if (priv->widget_path)
1341 gtk_widget_path_free (priv->widget_path);
1342 priv->widget_path = NULL;
1346 priv->widget_path = gtk_widget_path_copy (path);
1348 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY);
1352 * gtk_style_context_get_path:
1353 * @context: a #GtkStyleContext
1355 * Returns the widget path used for style matching.
1357 * Returns: (transfer none): A #GtkWidgetPath
1361 const GtkWidgetPath *
1362 gtk_style_context_get_path (GtkStyleContext *context)
1364 GtkStyleContextPrivate *priv;
1366 priv = context->priv;
1368 return gtk_widget_get_path (priv->widget);
1370 return priv->widget_path;
1374 * gtk_style_context_set_parent:
1375 * @context: a #GtkStyleContext
1376 * @parent: (allow-none): the new parent or %NULL
1378 * Sets the parent style context for @context. The parent style
1379 * context is used to implement
1380 * <ulink url="http://www.w3.org/TR/css3-cascade/#inheritance">inheritance</ulink>
1383 * If you are using a #GtkStyleContext returned from
1384 * gtk_widget_get_style_context(), the parent will be set for you.
1389 gtk_style_context_set_parent (GtkStyleContext *context,
1390 GtkStyleContext *parent)
1392 GtkStyleContextPrivate *priv;
1394 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1395 g_return_if_fail (parent == NULL || GTK_IS_STYLE_CONTEXT (parent));
1397 priv = context->priv;
1399 if (priv->parent == parent)
1404 parent->priv->children = g_slist_prepend (parent->priv->children, context);
1405 g_object_ref (parent);
1407 gtk_style_context_set_invalid (parent, TRUE);
1412 priv->parent->priv->children = g_slist_remove (priv->parent->priv->children, context);
1413 g_object_unref (priv->parent);
1416 priv->parent = parent;
1418 g_object_notify (G_OBJECT (context), "parent");
1419 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY_PARENT | GTK_CSS_CHANGE_ANY_SIBLING);
1423 * gtk_style_context_get_parent:
1424 * @context: a #GtkStyleContext
1426 * Gets the parent context set via gtk_style_context_set_parent().
1427 * See that function for details.
1429 * Returns: (transfer none): the parent context or %NULL
1434 gtk_style_context_get_parent (GtkStyleContext *context)
1436 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1438 return context->priv->parent;
1442 * gtk_style_context_save:
1443 * @context: a #GtkStyleContext
1445 * Saves the @context state, so all modifications done through
1446 * gtk_style_context_add_class(), gtk_style_context_remove_class(),
1447 * gtk_style_context_add_region(), gtk_style_context_remove_region()
1448 * or gtk_style_context_set_junction_sides() can be reverted in one
1449 * go through gtk_style_context_restore().
1454 gtk_style_context_save (GtkStyleContext *context)
1456 GtkStyleContextPrivate *priv;
1459 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1461 priv = context->priv;
1463 g_assert (priv->info_stack != NULL);
1465 info = style_info_copy (priv->info_stack->data);
1466 priv->info_stack = g_slist_prepend (priv->info_stack, info);
1470 * gtk_style_context_restore:
1471 * @context: a #GtkStyleContext
1473 * Restores @context state to a previous stage.
1474 * See gtk_style_context_save().
1479 gtk_style_context_restore (GtkStyleContext *context)
1481 GtkStyleContextPrivate *priv;
1484 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1486 priv = context->priv;
1488 if (priv->info_stack)
1490 info = priv->info_stack->data;
1491 priv->info_stack = g_slist_remove (priv->info_stack, info);
1492 style_info_free (info);
1495 if (!priv->info_stack)
1497 g_warning ("Unpaired gtk_style_context_restore() call");
1499 /* Create default region */
1500 info = style_info_new ();
1501 priv->info_stack = g_slist_prepend (priv->info_stack, info);
1506 style_class_find (GArray *array,
1511 gboolean found = FALSE;
1517 if (!array || array->len == 0)
1521 max = array->len - 1;
1527 mid = (min + max) / 2;
1528 item = g_array_index (array, GQuark, mid);
1530 if (class_quark == item)
1535 else if (class_quark > item)
1536 min = pos = mid + 1;
1543 while (!found && min <= max);
1552 region_find (GArray *array,
1557 gboolean found = FALSE;
1563 if (!array || array->len == 0)
1567 max = array->len - 1;
1573 mid = (min + max) / 2;
1574 region = &g_array_index (array, GtkRegion, mid);
1576 if (region->class_quark == class_quark)
1581 else if (region->class_quark > class_quark)
1582 min = pos = mid + 1;
1589 while (!found && min <= max);
1598 * gtk_style_context_add_class:
1599 * @context: a #GtkStyleContext
1600 * @class_name: class name to use in styling
1602 * Adds a style class to @context, so posterior calls to
1603 * gtk_style_context_get() or any of the gtk_render_*()
1604 * functions will make use of this new class for styling.
1606 * In the CSS file format, a #GtkEntry defining an "entry"
1607 * class, would be matched by:
1610 * GtkEntry.entry { ... }
1613 * While any widget defining an "entry" class would be
1622 gtk_style_context_add_class (GtkStyleContext *context,
1623 const gchar *class_name)
1625 GtkStyleContextPrivate *priv;
1630 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1631 g_return_if_fail (class_name != NULL);
1633 priv = context->priv;
1634 class_quark = g_quark_from_string (class_name);
1636 g_assert (priv->info_stack != NULL);
1637 info = priv->info_stack->data;
1639 if (!style_class_find (info->style_classes, class_quark, &position))
1641 g_array_insert_val (info->style_classes, position, class_quark);
1643 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_CLASS);
1648 * gtk_style_context_remove_class:
1649 * @context: a #GtkStyleContext
1650 * @class_name: class name to remove
1652 * Removes @class_name from @context.
1657 gtk_style_context_remove_class (GtkStyleContext *context,
1658 const gchar *class_name)
1660 GtkStyleContextPrivate *priv;
1665 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1666 g_return_if_fail (class_name != NULL);
1668 class_quark = g_quark_try_string (class_name);
1673 priv = context->priv;
1675 g_assert (priv->info_stack != NULL);
1676 info = priv->info_stack->data;
1678 if (style_class_find (info->style_classes, class_quark, &position))
1680 g_array_remove_index (info->style_classes, position);
1682 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_CLASS);
1687 * gtk_style_context_has_class:
1688 * @context: a #GtkStyleContext
1689 * @class_name: a class name
1691 * Returns %TRUE if @context currently has defined the
1694 * Returns: %TRUE if @context has @class_name defined
1699 gtk_style_context_has_class (GtkStyleContext *context,
1700 const gchar *class_name)
1702 GtkStyleContextPrivate *priv;
1706 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1707 g_return_val_if_fail (class_name != NULL, FALSE);
1709 class_quark = g_quark_try_string (class_name);
1714 priv = context->priv;
1716 g_assert (priv->info_stack != NULL);
1717 info = priv->info_stack->data;
1719 if (style_class_find (info->style_classes, class_quark, NULL))
1726 * gtk_style_context_list_classes:
1727 * @context: a #GtkStyleContext
1729 * Returns the list of classes currently defined in @context.
1731 * Returns: (transfer container) (element-type utf8): a #GList of
1732 * strings with the currently defined classes. The contents
1733 * of the list are owned by GTK+, but you must free the list
1734 * itself with g_list_free() when you are done with it.
1739 gtk_style_context_list_classes (GtkStyleContext *context)
1741 GtkStyleContextPrivate *priv;
1743 GList *classes = NULL;
1746 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1748 priv = context->priv;
1750 g_assert (priv->info_stack != NULL);
1751 info = priv->info_stack->data;
1753 for (i = 0; i < info->style_classes->len; i++)
1757 quark = g_array_index (info->style_classes, GQuark, i);
1758 classes = g_list_prepend (classes, (gchar *) g_quark_to_string (quark));
1765 * gtk_style_context_list_regions:
1766 * @context: a #GtkStyleContext
1768 * Returns the list of regions currently defined in @context.
1770 * Returns: (transfer container) (element-type utf8): a #GList of
1771 * strings with the currently defined regions. The contents
1772 * of the list are owned by GTK+, but you must free the list
1773 * itself with g_list_free() when you are done with it.
1778 gtk_style_context_list_regions (GtkStyleContext *context)
1780 GtkStyleContextPrivate *priv;
1782 GList *classes = NULL;
1785 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1787 priv = context->priv;
1789 g_assert (priv->info_stack != NULL);
1790 info = priv->info_stack->data;
1792 for (i = 0; i < info->regions->len; i++)
1795 const gchar *class_name;
1797 region = &g_array_index (info->regions, GtkRegion, i);
1799 class_name = g_quark_to_string (region->class_quark);
1800 classes = g_list_prepend (classes, (gchar *) class_name);
1807 _gtk_style_context_check_region_name (const gchar *str)
1809 g_return_val_if_fail (str != NULL, FALSE);
1811 if (!g_ascii_islower (str[0]))
1817 !g_ascii_islower (*str))
1827 * gtk_style_context_add_region:
1828 * @context: a #GtkStyleContext
1829 * @region_name: region name to use in styling
1830 * @flags: flags that apply to the region
1832 * Adds a region to @context, so posterior calls to
1833 * gtk_style_context_get() or any of the gtk_render_*()
1834 * functions will make use of this new region for styling.
1836 * In the CSS file format, a #GtkTreeView defining a "row"
1837 * region, would be matched by:
1840 * GtkTreeView row { ... }
1843 * Pseudo-classes are used for matching @flags, so the two
1846 * GtkTreeView row:nth-child(even) { ... }
1847 * GtkTreeView row:nth-child(odd) { ... }
1850 * would apply to even and odd rows, respectively.
1852 * <note><para>Region names must only contain lowercase letters
1853 * and '-', starting always with a lowercase letter.</para></note>
1858 gtk_style_context_add_region (GtkStyleContext *context,
1859 const gchar *region_name,
1860 GtkRegionFlags flags)
1862 GtkStyleContextPrivate *priv;
1864 GQuark region_quark;
1867 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1868 g_return_if_fail (region_name != NULL);
1869 g_return_if_fail (_gtk_style_context_check_region_name (region_name));
1871 priv = context->priv;
1872 region_quark = g_quark_from_string (region_name);
1874 g_assert (priv->info_stack != NULL);
1875 info = priv->info_stack->data;
1877 if (!region_find (info->regions, region_quark, &position))
1881 region.class_quark = region_quark;
1882 region.flags = flags;
1884 g_array_insert_val (info->regions, position, region);
1886 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_REGION);
1891 * gtk_style_context_remove_region:
1892 * @context: a #GtkStyleContext
1893 * @region_name: region name to unset
1895 * Removes a region from @context.
1900 gtk_style_context_remove_region (GtkStyleContext *context,
1901 const gchar *region_name)
1903 GtkStyleContextPrivate *priv;
1905 GQuark region_quark;
1908 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1909 g_return_if_fail (region_name != NULL);
1911 region_quark = g_quark_try_string (region_name);
1916 priv = context->priv;
1918 g_assert (priv->info_stack != NULL);
1919 info = priv->info_stack->data;
1921 if (region_find (info->regions, region_quark, &position))
1923 g_array_remove_index (info->regions, position);
1925 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_REGION);
1930 * gtk_style_context_has_region:
1931 * @context: a #GtkStyleContext
1932 * @region_name: a region name
1933 * @flags_return: (out) (allow-none): return location for region flags
1935 * Returns %TRUE if @context has the region defined.
1936 * If @flags_return is not %NULL, it is set to the flags
1937 * affecting the region.
1939 * Returns: %TRUE if region is defined
1944 gtk_style_context_has_region (GtkStyleContext *context,
1945 const gchar *region_name,
1946 GtkRegionFlags *flags_return)
1948 GtkStyleContextPrivate *priv;
1950 GQuark region_quark;
1953 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1954 g_return_val_if_fail (region_name != NULL, FALSE);
1959 region_quark = g_quark_try_string (region_name);
1964 priv = context->priv;
1966 g_assert (priv->info_stack != NULL);
1967 info = priv->info_stack->data;
1969 if (region_find (info->regions, region_quark, &position))
1975 region = &g_array_index (info->regions, GtkRegion, position);
1976 *flags_return = region->flags;
1985 style_property_values_cmp (gconstpointer bsearch_node1,
1986 gconstpointer bsearch_node2)
1988 const PropertyValue *val1 = bsearch_node1;
1989 const PropertyValue *val2 = bsearch_node2;
1991 if (val1->widget_type != val2->widget_type)
1992 return val1->widget_type < val2->widget_type ? -1 : 1;
1994 if (val1->pspec != val2->pspec)
1995 return val1->pspec < val2->pspec ? -1 : 1;
1997 if (val1->state != val2->state)
1998 return val1->state < val2->state ? -1 : 1;
2004 _gtk_style_context_peek_property (GtkStyleContext *context,
2007 StyleData *data = style_data_lookup (context);
2009 return _gtk_css_computed_values_get_value (data->store, property_id);
2013 _gtk_style_context_get_number (GtkStyleContext *context,
2015 double one_hundred_percent)
2019 value = _gtk_style_context_peek_property (context, property_id);
2020 return _gtk_css_number_value_get (value, one_hundred_percent);
2024 _gtk_style_context_peek_style_property (GtkStyleContext *context,
2026 GtkStateFlags state,
2029 GtkStyleContextPrivate *priv;
2030 PropertyValue *pcache, key = { 0 };
2034 priv = context->priv;
2036 gtk_style_context_save (context);
2037 gtk_style_context_set_state (context, state);
2038 data = style_data_lookup (context);
2039 gtk_style_context_restore (context);
2041 key.widget_type = widget_type;
2045 /* need value cache array */
2046 if (!data->property_cache)
2047 data->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
2050 pcache = bsearch (&key,
2051 data->property_cache->data, data->property_cache->len,
2052 sizeof (PropertyValue), style_property_values_cmp);
2054 return &pcache->value;
2058 while (i < data->property_cache->len &&
2059 style_property_values_cmp (&key, &g_array_index (data->property_cache, PropertyValue, i)) >= 0)
2062 g_array_insert_val (data->property_cache, i, key);
2063 pcache = &g_array_index (data->property_cache, PropertyValue, i);
2065 /* cache miss, initialize value type, then set contents */
2066 g_param_spec_ref (pcache->pspec);
2067 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2069 if (priv->widget || priv->widget_path)
2071 GtkWidgetPath *widget_path = priv->widget ? _gtk_widget_create_path (priv->widget) : priv->widget_path;
2073 if (gtk_style_provider_get_style_property (GTK_STYLE_PROVIDER (priv->cascade),
2075 state, pspec, &pcache->value))
2077 /* Resolve symbolic colors to GdkColor/GdkRGBA */
2078 if (G_VALUE_TYPE (&pcache->value) == GTK_TYPE_SYMBOLIC_COLOR)
2080 GtkSymbolicColor *color;
2083 color = g_value_dup_boxed (&pcache->value);
2085 g_value_unset (&pcache->value);
2087 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2088 g_value_init (&pcache->value, GDK_TYPE_RGBA);
2090 g_value_init (&pcache->value, GDK_TYPE_COLOR);
2092 if (_gtk_style_context_resolve_color (context, color, &rgba))
2094 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2095 g_value_set_boxed (&pcache->value, &rgba);
2100 rgb.red = rgba.red * 65535. + 0.5;
2101 rgb.green = rgba.green * 65535. + 0.5;
2102 rgb.blue = rgba.blue * 65535. + 0.5;
2104 g_value_set_boxed (&pcache->value, &rgb);
2108 g_param_value_set_default (pspec, &pcache->value);
2110 gtk_symbolic_color_unref (color);
2114 gtk_widget_path_free (widget_path);
2116 return &pcache->value;
2120 gtk_widget_path_free (widget_path);
2123 /* not supplied by any provider, revert to default */
2124 g_param_value_set_default (pspec, &pcache->value);
2126 return &pcache->value;
2130 * gtk_style_context_get_style_property:
2131 * @context: a #GtkStyleContext
2132 * @property_name: the name of the widget style property
2133 * @value: Return location for the property value
2135 * Gets the value for a widget style property.
2137 * When @value is no longer needed, g_value_unset() must be called
2138 * to free any allocated memory.
2141 gtk_style_context_get_style_property (GtkStyleContext *context,
2142 const gchar *property_name,
2145 GtkStyleContextPrivate *priv;
2146 GtkWidgetClass *widget_class;
2147 GtkStateFlags state;
2149 const GValue *peek_value;
2152 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2153 g_return_if_fail (property_name != NULL);
2154 g_return_if_fail (value != NULL);
2156 priv = context->priv;
2160 widget_type = G_OBJECT_TYPE (priv->widget);
2164 if (!priv->widget_path)
2167 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2169 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2171 g_warning ("%s: can't get style properties for non-widget class `%s'",
2173 g_type_name (widget_type));
2178 widget_class = g_type_class_ref (widget_type);
2179 pspec = gtk_widget_class_find_style_property (widget_class, property_name);
2180 g_type_class_unref (widget_class);
2184 g_warning ("%s: widget class `%s' has no style property named `%s'",
2186 g_type_name (widget_type),
2191 state = gtk_style_context_get_state (context);
2192 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2195 if (G_VALUE_TYPE (value) == G_VALUE_TYPE (peek_value))
2196 g_value_copy (peek_value, value);
2197 else if (g_value_type_transformable (G_VALUE_TYPE (peek_value), G_VALUE_TYPE (value)))
2198 g_value_transform (peek_value, value);
2200 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
2202 G_VALUE_TYPE_NAME (peek_value),
2203 G_VALUE_TYPE_NAME (value));
2207 * gtk_style_context_get_style_valist:
2208 * @context: a #GtkStyleContext
2209 * @args: va_list of property name/return location pairs, followed by %NULL
2211 * Retrieves several widget style properties from @context according to the
2217 gtk_style_context_get_style_valist (GtkStyleContext *context,
2220 GtkStyleContextPrivate *priv;
2221 const gchar *prop_name;
2222 GtkStateFlags state;
2225 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2227 prop_name = va_arg (args, const gchar *);
2228 priv = context->priv;
2232 widget_type = G_OBJECT_TYPE (priv->widget);
2236 if (!priv->widget_path)
2239 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2241 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2243 g_warning ("%s: can't get style properties for non-widget class `%s'",
2245 g_type_name (widget_type));
2250 state = gtk_style_context_get_state (context);
2254 GtkWidgetClass *widget_class;
2256 const GValue *peek_value;
2259 widget_class = g_type_class_ref (widget_type);
2260 pspec = gtk_widget_class_find_style_property (widget_class, prop_name);
2261 g_type_class_unref (widget_class);
2265 g_warning ("%s: widget class `%s' has no style property named `%s'",
2267 g_type_name (widget_type),
2272 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2275 G_VALUE_LCOPY (peek_value, args, 0, &error);
2279 g_warning ("can't retrieve style property `%s' of type `%s': %s",
2281 G_VALUE_TYPE_NAME (peek_value),
2287 prop_name = va_arg (args, const gchar *);
2292 * gtk_style_context_get_style:
2293 * @context: a #GtkStyleContext
2294 * @...: property name /return value pairs, followed by %NULL
2296 * Retrieves several widget style properties from @context according to the
2302 gtk_style_context_get_style (GtkStyleContext *context,
2307 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2309 va_start (args, context);
2310 gtk_style_context_get_style_valist (context, args);
2316 * gtk_style_context_lookup_icon_set:
2317 * @context: a #GtkStyleContext
2318 * @stock_id: an icon name
2320 * Looks up @stock_id in the icon factories associated to @context and
2321 * the default icon factory, returning an icon set if found, otherwise
2324 * Returns: (transfer none): The looked up %GtkIconSet, or %NULL
2327 gtk_style_context_lookup_icon_set (GtkStyleContext *context,
2328 const gchar *stock_id)
2330 GtkStyleContextPrivate *priv;
2332 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2333 g_return_val_if_fail (stock_id != NULL, NULL);
2335 priv = context->priv;
2336 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
2338 return gtk_icon_factory_lookup_default (stock_id);
2342 * gtk_style_context_set_screen:
2343 * @context: a #GtkStyleContext
2344 * @screen: a #GdkScreen
2346 * Attaches @context to the given screen.
2348 * The screen is used to add style information from 'global' style
2349 * providers, such as the screens #GtkSettings instance.
2351 * If you are using a #GtkStyleContext returned from
2352 * gtk_widget_get_style_context(), you do not need to
2353 * call this yourself.
2358 gtk_style_context_set_screen (GtkStyleContext *context,
2361 GtkStyleContextPrivate *priv;
2363 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2364 g_return_if_fail (GDK_IS_SCREEN (screen));
2366 priv = context->priv;
2367 if (priv->screen == screen)
2370 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
2372 g_object_unref (priv->cascade);
2373 priv->cascade = _gtk_style_cascade_get_for_screen (screen);
2374 g_object_ref (priv->cascade);
2378 _gtk_style_cascade_set_parent (priv->cascade, _gtk_style_cascade_get_for_screen (screen));
2381 priv->screen = screen;
2383 g_object_notify (G_OBJECT (context), "screen");
2385 gtk_style_context_invalidate (context);
2389 * gtk_style_context_get_screen:
2390 * @context: a #GtkStyleContext
2392 * Returns the #GdkScreen to which @context is attached.
2394 * Returns: (transfer none): a #GdkScreen.
2397 gtk_style_context_get_screen (GtkStyleContext *context)
2399 GtkStyleContextPrivate *priv;
2401 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2403 priv = context->priv;
2404 return priv->screen;
2408 * gtk_style_context_set_direction:
2409 * @context: a #GtkStyleContext
2410 * @direction: the new direction.
2412 * Sets the reading direction for rendering purposes.
2414 * If you are using a #GtkStyleContext returned from
2415 * gtk_widget_get_style_context(), you do not need to
2416 * call this yourself.
2421 gtk_style_context_set_direction (GtkStyleContext *context,
2422 GtkTextDirection direction)
2424 GtkStyleContextPrivate *priv;
2426 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2428 priv = context->priv;
2429 priv->direction = direction;
2431 g_object_notify (G_OBJECT (context), "direction");
2435 * gtk_style_context_get_direction:
2436 * @context: a #GtkStyleContext
2438 * Returns the widget direction used for rendering.
2440 * Returns: the widget direction
2445 gtk_style_context_get_direction (GtkStyleContext *context)
2447 GtkStyleContextPrivate *priv;
2449 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), GTK_TEXT_DIR_LTR);
2451 priv = context->priv;
2452 return priv->direction;
2456 * gtk_style_context_set_junction_sides:
2457 * @context: a #GtkStyleContext
2458 * @sides: sides where rendered elements are visually connected to
2461 * Sets the sides where rendered elements (mostly through
2462 * gtk_render_frame()) will visually connect with other visual elements.
2464 * This is merely a hint that may or may not be honored
2465 * by theming engines.
2467 * Container widgets are expected to set junction hints as appropriate
2468 * for their children, so it should not normally be necessary to call
2469 * this function manually.
2474 gtk_style_context_set_junction_sides (GtkStyleContext *context,
2475 GtkJunctionSides sides)
2477 GtkStyleContextPrivate *priv;
2480 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2482 priv = context->priv;
2483 info = priv->info_stack->data;
2484 info->junction_sides = sides;
2488 * gtk_style_context_get_junction_sides:
2489 * @context: a #GtkStyleContext
2491 * Returns the sides where rendered elements connect visually with others.
2493 * Returns: the junction sides
2498 gtk_style_context_get_junction_sides (GtkStyleContext *context)
2500 GtkStyleContextPrivate *priv;
2503 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
2505 priv = context->priv;
2506 info = priv->info_stack->data;
2507 return info->junction_sides;
2510 static GtkSymbolicColor *
2511 gtk_style_context_color_lookup_func (gpointer contextp,
2514 GtkStyleContext *context = contextp;
2516 return _gtk_style_provider_private_get_color (GTK_STYLE_PROVIDER_PRIVATE (context->priv->cascade), name);
2520 _gtk_style_context_resolve_color_value (GtkStyleContext *context,
2521 GtkCssValue *current,
2524 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2525 g_return_val_if_fail (current != NULL, FALSE);
2526 g_return_val_if_fail (color != NULL, FALSE);
2528 return _gtk_symbolic_color_resolve_full ((GtkSymbolicColor *) color,
2530 gtk_style_context_color_lookup_func,
2536 _gtk_style_context_resolve_color (GtkStyleContext *context,
2537 GtkSymbolicColor *color,
2542 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2543 g_return_val_if_fail (color != NULL, FALSE);
2544 g_return_val_if_fail (result != NULL, FALSE);
2546 val = _gtk_symbolic_color_resolve_full (color,
2547 _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR),
2548 gtk_style_context_color_lookup_func,
2553 *result = *_gtk_css_rgba_value_get_rgba (val);
2554 _gtk_css_value_unref (val);
2559 * gtk_style_context_lookup_color:
2560 * @context: a #GtkStyleContext
2561 * @color_name: color name to lookup
2562 * @color: (out): Return location for the looked up color
2564 * Looks up and resolves a color name in the @context color map.
2566 * Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
2569 gtk_style_context_lookup_color (GtkStyleContext *context,
2570 const gchar *color_name,
2573 GtkSymbolicColor *sym_color;
2575 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2576 g_return_val_if_fail (color_name != NULL, FALSE);
2577 g_return_val_if_fail (color != NULL, FALSE);
2579 sym_color = gtk_style_context_color_lookup_func (context, color_name);
2580 if (sym_color == NULL)
2583 return _gtk_style_context_resolve_color (context, sym_color, color);
2587 * gtk_style_context_notify_state_change:
2588 * @context: a #GtkStyleContext
2589 * @window: a #GdkWindow
2590 * @region_id: (allow-none): animatable region to notify on, or %NULL.
2591 * See gtk_style_context_push_animatable_region()
2592 * @state: state to trigger transition for
2593 * @state_value: %TRUE if @state is the state we are changing to,
2594 * %FALSE if we are changing away from it
2596 * Notifies a state change on @context, so if the current style makes use
2597 * of transition animations, one will be started so all rendered elements
2598 * under @region_id are animated for state @state being set to value
2601 * The @window parameter is used in order to invalidate the rendered area
2602 * as the animation runs, so make sure it is the same window that is being
2603 * rendered on by the gtk_render_*() functions.
2605 * If @region_id is %NULL, all rendered elements using @context will be
2606 * affected by this state transition.
2608 * As a practical example, a #GtkButton notifying a state transition on
2609 * the prelight state:
2611 * gtk_style_context_notify_state_change (context,
2612 * gtk_widget_get_window (widget),
2614 * GTK_STATE_PRELIGHT,
2615 * button->in_button);
2618 * Can be handled in the CSS file like this:
2621 * background-color: #f00
2625 * background-color: #fff;
2626 * transition: 200ms linear
2630 * This combination will animate the button background from red to white
2631 * if a pointer enters the button, and back to red if the pointer leaves
2634 * Note that @state is used when finding the transition parameters, which
2635 * is why the style places the transition under the :hover pseudo-class.
2639 * Deprecated: 3.6: This function does nothing.
2642 gtk_style_context_notify_state_change (GtkStyleContext *context,
2646 gboolean state_value)
2648 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2649 g_return_if_fail (GDK_IS_WINDOW (window));
2650 g_return_if_fail (state > GTK_STATE_NORMAL && state <= GTK_STATE_FOCUSED);
2651 g_return_if_fail (context->priv->widget != NULL || context->priv->widget_path != NULL);
2655 * gtk_style_context_cancel_animations:
2656 * @context: a #GtkStyleContext
2657 * @region_id: (allow-none): animatable region to stop, or %NULL.
2658 * See gtk_style_context_push_animatable_region()
2660 * Stops all running animations for @region_id and all animatable
2661 * regions underneath.
2663 * A %NULL @region_id will stop all ongoing animations in @context,
2664 * when dealing with a #GtkStyleContext obtained through
2665 * gtk_widget_get_style_context(), this is normally done for you
2666 * in all circumstances you would expect all widget to be stopped,
2667 * so this should be only used in complex widgets with different
2668 * animatable regions.
2672 * Deprecated: 3.6: This function does nothing.
2675 gtk_style_context_cancel_animations (GtkStyleContext *context,
2678 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2682 * gtk_style_context_scroll_animations:
2683 * @context: a #GtkStyleContext
2684 * @window: a #GdkWindow used previously in
2685 * gtk_style_context_notify_state_change()
2686 * @dx: Amount to scroll in the X axis
2687 * @dy: Amount to scroll in the Y axis
2689 * This function is analogous to gdk_window_scroll(), and
2690 * should be called together with it so the invalidation
2691 * areas for any ongoing animation are scrolled together
2696 * Deprecated: 3.6: This function does nothing.
2699 gtk_style_context_scroll_animations (GtkStyleContext *context,
2704 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2705 g_return_if_fail (GDK_IS_WINDOW (window));
2709 * gtk_style_context_push_animatable_region:
2710 * @context: a #GtkStyleContext
2711 * @region_id: unique identifier for the animatable region
2713 * Pushes an animatable region, so all further gtk_render_*() calls between
2714 * this call and the following gtk_style_context_pop_animatable_region()
2715 * will potentially show transition animations for this region if
2716 * gtk_style_context_notify_state_change() is called for a given state,
2717 * and the current theme/style defines transition animations for state
2720 * The @region_id used must be unique in @context so the theming engine
2721 * can uniquely identify rendered elements subject to a state transition.
2725 * Deprecated: 3.6: This function does nothing.
2728 gtk_style_context_push_animatable_region (GtkStyleContext *context,
2731 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2732 g_return_if_fail (region_id != NULL);
2736 * gtk_style_context_pop_animatable_region:
2737 * @context: a #GtkStyleContext
2739 * Pops an animatable region from @context.
2740 * See gtk_style_context_push_animatable_region().
2744 * Deprecated: 3.6: This function does nothing.
2747 gtk_style_context_pop_animatable_region (GtkStyleContext *context)
2749 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2753 gtk_style_context_clear_cache (GtkStyleContext *context)
2755 GtkStyleContextPrivate *priv;
2758 priv = context->priv;
2760 for (list = priv->info_stack; list; list = list->next)
2762 GtkStyleInfo *info = list->data;
2765 g_hash_table_remove_all (priv->style_data);
2769 gtk_style_context_do_invalidate (GtkStyleContext *context)
2771 GtkStyleContextPrivate *priv;
2773 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2775 priv = context->priv;
2777 /* Avoid reentrancy */
2778 if (priv->invalidating_context)
2781 priv->invalidating_context = TRUE;
2783 g_signal_emit (context, signals[CHANGED], 0);
2785 priv->invalidating_context = FALSE;
2789 _gtk_style_context_validate (GtkStyleContext *context,
2791 GtkCssChange change)
2793 GtkStyleContextPrivate *priv;
2796 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2798 priv = context->priv;
2800 change |= priv->pending_changes;
2802 if (!priv->invalid && change == 0)
2805 priv->pending_changes = 0;
2806 gtk_style_context_set_invalid (context, FALSE);
2808 /* Try to avoid invalidating if we can */
2809 if (change & GTK_STYLE_CONTEXT_RADICAL_CHANGE)
2811 priv->relevant_changes = GTK_CSS_CHANGE_ANY;
2815 if (priv->relevant_changes == GTK_CSS_CHANGE_ANY)
2817 GtkWidgetPath *path;
2818 GtkCssMatcher matcher;
2820 path = create_query_path (context);
2821 _gtk_css_matcher_init (&matcher, path, ((GtkStyleInfo *) priv->info_stack->data)->state_flags);
2823 priv->relevant_changes = _gtk_style_provider_private_get_change (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
2825 priv->relevant_changes &= ~GTK_STYLE_CONTEXT_RADICAL_CHANGE;
2827 gtk_widget_path_unref (path);
2831 if (priv->relevant_changes & change)
2833 GtkStyleInfo *info = priv->info_stack->data;
2834 GtkCssComputedValues *old, *new;
2836 old = info->data ? g_object_ref (info->data->store) : NULL;
2838 if ((priv->relevant_changes & change) & ~GTK_STYLE_CONTEXT_CACHED_CHANGE)
2839 gtk_style_context_clear_cache (context);
2845 GtkBitmask *bitmask;
2847 new = style_data_lookup (context)->store;
2849 bitmask = _gtk_css_computed_values_get_difference (new, old);
2850 if (!_gtk_bitmask_is_empty (bitmask))
2851 gtk_style_context_do_invalidate (context);
2853 _gtk_bitmask_free (bitmask);
2854 g_object_unref (old);
2857 gtk_style_context_do_invalidate (context);
2861 change = _gtk_css_change_for_child (change);
2862 for (list = priv->children; list; list = list->next)
2864 _gtk_style_context_validate (list->data, timestamp, change);
2869 _gtk_style_context_queue_invalidate (GtkStyleContext *context,
2870 GtkCssChange change)
2872 GtkStyleContextPrivate *priv;
2874 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2875 g_return_if_fail (change != 0);
2877 priv = context->priv;
2879 if (priv->widget == NULL && priv->widget_path == NULL)
2882 priv->pending_changes |= change;
2883 gtk_style_context_set_invalid (context, TRUE);
2887 * gtk_style_context_invalidate:
2888 * @context: a #GtkStyleContext.
2890 * Invalidates @context style information, so it will be reconstructed
2893 * If you're using a #GtkStyleContext returned from
2894 * gtk_widget_get_style_context(), you do not need to
2895 * call this yourself.
2900 gtk_style_context_invalidate (GtkStyleContext *context)
2902 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2904 gtk_style_context_clear_cache (context);
2905 gtk_style_context_do_invalidate (context);
2909 * gtk_style_context_set_background:
2910 * @context: a #GtkStyleContext
2911 * @window: a #GdkWindow
2913 * Sets the background of @window to the background pattern or
2914 * color specified in @context for its current state.
2919 gtk_style_context_set_background (GtkStyleContext *context,
2922 GtkStateFlags state;
2923 cairo_pattern_t *pattern;
2926 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2927 g_return_if_fail (GDK_IS_WINDOW (window));
2929 state = gtk_style_context_get_state (context);
2930 gtk_style_context_get (context, state,
2931 "background-image", &pattern,
2935 gdk_window_set_background_pattern (window, pattern);
2936 cairo_pattern_destroy (pattern);
2940 gtk_style_context_get (context, state,
2941 "background-color", &color,
2945 gdk_window_set_background_rgba (window, color);
2946 gdk_rgba_free (color);
2951 * gtk_style_context_get_color:
2952 * @context: a #GtkStyleContext
2953 * @state: state to retrieve the color for
2954 * @color: (out): return value for the foreground color
2956 * Gets the foreground color for a given state.
2961 gtk_style_context_get_color (GtkStyleContext *context,
2962 GtkStateFlags state,
2967 g_return_if_fail (color != NULL);
2968 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2970 gtk_style_context_get (context,
2980 * gtk_style_context_get_background_color:
2981 * @context: a #GtkStyleContext
2982 * @state: state to retrieve the color for
2983 * @color: (out): return value for the background color
2985 * Gets the background color for a given state.
2990 gtk_style_context_get_background_color (GtkStyleContext *context,
2991 GtkStateFlags state,
2996 g_return_if_fail (color != NULL);
2997 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2999 gtk_style_context_get (context,
3001 "background-color", &c,
3009 * gtk_style_context_get_border_color:
3010 * @context: a #GtkStyleContext
3011 * @state: state to retrieve the color for
3012 * @color: (out): return value for the border color
3014 * Gets the border color for a given state.
3019 gtk_style_context_get_border_color (GtkStyleContext *context,
3020 GtkStateFlags state,
3025 g_return_if_fail (color != NULL);
3026 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3028 gtk_style_context_get (context,
3038 * gtk_style_context_get_border:
3039 * @context: a #GtkStyleContext
3040 * @state: state to retrieve the border for
3041 * @border: (out): return value for the border settings
3043 * Gets the border for a given state as a #GtkBorder.
3044 * See %GTK_STYLE_PROPERTY_BORDER_WIDTH.
3049 gtk_style_context_get_border (GtkStyleContext *context,
3050 GtkStateFlags state,
3053 int top, left, bottom, right;
3055 g_return_if_fail (border != NULL);
3056 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3058 gtk_style_context_get (context,
3060 "border-top-width", &top,
3061 "border-left-width", &left,
3062 "border-bottom-width", &bottom,
3063 "border-right-width", &right,
3067 border->left = left;
3068 border->bottom = bottom;
3069 border->right = right;
3073 * gtk_style_context_get_padding:
3074 * @context: a #GtkStyleContext
3075 * @state: state to retrieve the padding for
3076 * @padding: (out): return value for the padding settings
3078 * Gets the padding for a given state as a #GtkBorder.
3079 * See %GTK_STYLE_PROPERTY_PADDING.
3084 gtk_style_context_get_padding (GtkStyleContext *context,
3085 GtkStateFlags state,
3088 int top, left, bottom, right;
3090 g_return_if_fail (padding != NULL);
3091 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3093 gtk_style_context_get (context,
3095 "padding-top", &top,
3096 "padding-left", &left,
3097 "padding-bottom", &bottom,
3098 "padding-right", &right,
3102 padding->left = left;
3103 padding->bottom = bottom;
3104 padding->right = right;
3108 * gtk_style_context_get_margin:
3109 * @context: a #GtkStyleContext
3110 * @state: state to retrieve the border for
3111 * @margin: (out): return value for the margin settings
3113 * Gets the margin for a given state as a #GtkBorder.
3114 * See %GTK_STYLE_PROPERTY_MARGIN.
3119 gtk_style_context_get_margin (GtkStyleContext *context,
3120 GtkStateFlags state,
3123 int top, left, bottom, right;
3125 g_return_if_fail (margin != NULL);
3126 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3128 gtk_style_context_get (context,
3131 "margin-left", &left,
3132 "margin-bottom", &bottom,
3133 "margin-right", &right,
3137 margin->left = left;
3138 margin->bottom = bottom;
3139 margin->right = right;
3143 * gtk_style_context_get_font:
3144 * @context: a #GtkStyleContext
3145 * @state: state to retrieve the font for
3147 * Returns the font description for a given state. The returned
3148 * object is const and will remain valid until the
3149 * #GtkStyleContext::changed signal happens.
3151 * Returns: (transfer none): the #PangoFontDescription for the given
3152 * state. This object is owned by GTK+ and should not be
3157 const PangoFontDescription *
3158 gtk_style_context_get_font (GtkStyleContext *context,
3159 GtkStateFlags state)
3161 GtkStyleContextPrivate *priv;
3163 PangoFontDescription *description;
3165 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
3167 priv = context->priv;
3168 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
3170 gtk_style_context_save (context);
3171 gtk_style_context_set_state (context, state);
3172 data = style_data_lookup (context);
3173 gtk_style_context_restore (context);
3175 /* Yuck, fonts are created on-demand but we don't return a ref.
3176 * Do bad things to achieve this requirement */
3177 description = g_object_get_data (G_OBJECT (data->store), "font-cache-for-get_font");
3178 if (description == NULL)
3180 gtk_style_context_get (context, state, "font", &description, NULL);
3181 g_object_set_data_full (G_OBJECT (data->store),
3182 "font-cache-for-get_font",
3184 (GDestroyNotify) pango_font_description_free);
3190 get_cursor_color (GtkStyleContext *context,
3194 GdkColor *style_color;
3196 gtk_style_context_get_style (context,
3197 primary ? "cursor-color" : "secondary-cursor-color",
3203 color->red = style_color->red / 65535.0;
3204 color->green = style_color->green / 65535.0;
3205 color->blue = style_color->blue / 65535.0;
3208 gdk_color_free (style_color);
3212 gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, color);
3218 gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &bg);
3220 color->red = (color->red + bg.red) * 0.5;
3221 color->green = (color->green + bg.green) * 0.5;
3222 color->blue = (color->blue + bg.blue) * 0.5;
3228 _gtk_style_context_get_cursor_color (GtkStyleContext *context,
3229 GdkRGBA *primary_color,
3230 GdkRGBA *secondary_color)
3233 get_cursor_color (context, TRUE, primary_color);
3235 if (secondary_color)
3236 get_cursor_color (context, FALSE, secondary_color);
3243 * @context: a #GtkStyleContext
3245 * @x: X origin of the rectangle
3246 * @y: Y origin of the rectangle
3247 * @width: rectangle width
3248 * @height: rectangle height
3250 * Renders a checkmark (as in a #GtkCheckButton).
3252 * The %GTK_STATE_FLAG_ACTIVE state determines whether the check is
3253 * on or off, and %GTK_STATE_FLAG_INCONSISTENT determines whether it
3254 * should be marked as undefined.
3257 * <title>Typical checkmark rendering</title>
3258 * <inlinegraphic fileref="checks.png" format="PNG"/>
3264 gtk_render_check (GtkStyleContext *context,
3271 GtkThemingEngineClass *engine_class;
3272 GtkThemingEngine *engine;
3274 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3275 g_return_if_fail (cr != NULL);
3277 if (width <= 0 || height <= 0)
3280 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3281 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3286 _gtk_theming_engine_set_context (engine, context);
3287 engine_class->render_check (engine, cr,
3288 x, y, width, height);
3294 * gtk_render_option:
3295 * @context: a #GtkStyleContext
3297 * @x: X origin of the rectangle
3298 * @y: Y origin of the rectangle
3299 * @width: rectangle width
3300 * @height: rectangle height
3302 * Renders an option mark (as in a #GtkRadioButton), the %GTK_STATE_FLAG_ACTIVE
3303 * state will determine whether the option is on or off, and
3304 * %GTK_STATE_FLAG_INCONSISTENT whether it should be marked as undefined.
3307 * <title>Typical option mark rendering</title>
3308 * <inlinegraphic fileref="options.png" format="PNG"/>
3314 gtk_render_option (GtkStyleContext *context,
3321 GtkThemingEngineClass *engine_class;
3322 GtkThemingEngine *engine;
3324 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3325 g_return_if_fail (cr != NULL);
3327 if (width <= 0 || height <= 0)
3330 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3331 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3335 _gtk_theming_engine_set_context (engine, context);
3336 engine_class->render_option (engine, cr,
3337 x, y, width, height);
3344 * @context: a #GtkStyleContext
3346 * @angle: arrow angle from 0 to 2 * %G_PI, being 0 the arrow pointing to the north
3347 * @x: X origin of the render area
3348 * @y: Y origin of the render area
3349 * @size: square side for render area
3351 * Renders an arrow pointing to @angle.
3354 * <title>Typical arrow rendering at 0, 1&solidus;2 π, π and 3&solidus;2 π</title>
3355 * <inlinegraphic fileref="arrows.png" format="PNG"/>
3361 gtk_render_arrow (GtkStyleContext *context,
3368 GtkThemingEngineClass *engine_class;
3369 GtkThemingEngine *engine;
3371 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3372 g_return_if_fail (cr != NULL);
3377 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3378 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3382 gtk_style_context_save (context);
3383 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ARROW);
3385 _gtk_theming_engine_set_context (engine, context);
3386 engine_class->render_arrow (engine, cr,
3389 gtk_style_context_restore (context);
3394 * gtk_render_background:
3395 * @context: a #GtkStyleContext
3397 * @x: X origin of the rectangle
3398 * @y: Y origin of the rectangle
3399 * @width: rectangle width
3400 * @height: rectangle height
3402 * Renders the background of an element.
3405 * <title>Typical background rendering, showing the effect of
3406 * <parameter>background-image</parameter>,
3407 * <parameter>border-width</parameter> and
3408 * <parameter>border-radius</parameter></title>
3409 * <inlinegraphic fileref="background.png" format="PNG"/>
3415 gtk_render_background (GtkStyleContext *context,
3422 GtkThemingEngineClass *engine_class;
3423 GtkThemingEngine *engine;
3425 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3426 g_return_if_fail (cr != NULL);
3428 if (width <= 0 || height <= 0)
3431 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3432 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3436 _gtk_theming_engine_set_context (engine, context);
3437 engine_class->render_background (engine, cr, x, y, width, height);
3444 * @context: a #GtkStyleContext
3446 * @x: X origin of the rectangle
3447 * @y: Y origin of the rectangle
3448 * @width: rectangle width
3449 * @height: rectangle height
3451 * Renders a frame around the rectangle defined by @x, @y, @width, @height.
3454 * <title>Examples of frame rendering, showing the effect of
3455 * <parameter>border-image</parameter>,
3456 * <parameter>border-color</parameter>,
3457 * <parameter>border-width</parameter>,
3458 * <parameter>border-radius</parameter> and
3460 * <inlinegraphic fileref="frames.png" format="PNG"/>
3466 gtk_render_frame (GtkStyleContext *context,
3473 GtkThemingEngineClass *engine_class;
3474 GtkThemingEngine *engine;
3476 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3477 g_return_if_fail (cr != NULL);
3479 if (width <= 0 || height <= 0)
3482 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3483 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3487 _gtk_theming_engine_set_context (engine, context);
3488 engine_class->render_frame (engine, cr, x, y, width, height);
3494 * gtk_render_expander:
3495 * @context: a #GtkStyleContext
3497 * @x: X origin of the rectangle
3498 * @y: Y origin of the rectangle
3499 * @width: rectangle width
3500 * @height: rectangle height
3502 * Renders an expander (as used in #GtkTreeView and #GtkExpander) in the area
3503 * defined by @x, @y, @width, @height. The state %GTK_STATE_FLAG_ACTIVE
3504 * determines whether the expander is collapsed or expanded.
3507 * <title>Typical expander rendering</title>
3508 * <inlinegraphic fileref="expanders.png" format="PNG"/>
3514 gtk_render_expander (GtkStyleContext *context,
3521 GtkThemingEngineClass *engine_class;
3522 GtkThemingEngine *engine;
3524 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3525 g_return_if_fail (cr != NULL);
3527 if (width <= 0 || height <= 0)
3530 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3531 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3535 _gtk_theming_engine_set_context (engine, context);
3536 engine_class->render_expander (engine, cr, x, y, width, height);
3543 * @context: a #GtkStyleContext
3545 * @x: X origin of the rectangle
3546 * @y: Y origin of the rectangle
3547 * @width: rectangle width
3548 * @height: rectangle height
3550 * Renders a focus indicator on the rectangle determined by @x, @y, @width, @height.
3552 * <title>Typical focus rendering</title>
3553 * <inlinegraphic fileref="focus.png" format="PNG"/>
3559 gtk_render_focus (GtkStyleContext *context,
3566 GtkThemingEngineClass *engine_class;
3567 GtkThemingEngine *engine;
3569 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3570 g_return_if_fail (cr != NULL);
3572 if (width <= 0 || height <= 0)
3575 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3576 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3580 _gtk_theming_engine_set_context (engine, context);
3581 engine_class->render_focus (engine, cr, x, y, width, height);
3587 * gtk_render_layout:
3588 * @context: a #GtkStyleContext
3592 * @layout: the #PangoLayout to render
3594 * Renders @layout on the coordinates @x, @y
3599 gtk_render_layout (GtkStyleContext *context,
3603 PangoLayout *layout)
3605 GtkThemingEngineClass *engine_class;
3606 GtkThemingEngine *engine;
3607 PangoRectangle extents;
3609 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3610 g_return_if_fail (PANGO_IS_LAYOUT (layout));
3611 g_return_if_fail (cr != NULL);
3613 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3614 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3618 pango_layout_get_extents (layout, &extents, NULL);
3620 _gtk_theming_engine_set_context (engine, context);
3621 engine_class->render_layout (engine, cr, x, y, layout);
3628 * @context: a #GtkStyleContext
3630 * @x0: X coordinate for the origin of the line
3631 * @y0: Y coordinate for the origin of the line
3632 * @x1: X coordinate for the end of the line
3633 * @y1: Y coordinate for the end of the line
3635 * Renders a line from (x0, y0) to (x1, y1).
3640 gtk_render_line (GtkStyleContext *context,
3647 GtkThemingEngineClass *engine_class;
3648 GtkThemingEngine *engine;
3650 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3651 g_return_if_fail (cr != NULL);
3653 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3654 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3658 _gtk_theming_engine_set_context (engine, context);
3659 engine_class->render_line (engine, cr, x0, y0, x1, y1);
3665 * gtk_render_slider:
3666 * @context: a #GtkStyleContext
3668 * @x: X origin of the rectangle
3669 * @y: Y origin of the rectangle
3670 * @width: rectangle width
3671 * @height: rectangle height
3672 * @orientation: orientation of the slider
3674 * Renders a slider (as in #GtkScale) in the rectangle defined by @x, @y,
3675 * @width, @height. @orientation defines whether the slider is vertical
3679 * <title>Typical slider rendering</title>
3680 * <inlinegraphic fileref="sliders.png" format="PNG"/>
3686 gtk_render_slider (GtkStyleContext *context,
3692 GtkOrientation orientation)
3694 GtkThemingEngineClass *engine_class;
3695 GtkThemingEngine *engine;
3697 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3698 g_return_if_fail (cr != NULL);
3700 if (width <= 0 || height <= 0)
3703 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3704 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3708 _gtk_theming_engine_set_context (engine, context);
3709 engine_class->render_slider (engine, cr, x, y, width, height, orientation);
3715 * gtk_render_frame_gap:
3716 * @context: a #GtkStyleContext
3718 * @x: X origin of the rectangle
3719 * @y: Y origin of the rectangle
3720 * @width: rectangle width
3721 * @height: rectangle height
3722 * @gap_side: side where the gap is
3723 * @xy0_gap: initial coordinate (X or Y depending on @gap_side) for the gap
3724 * @xy1_gap: end coordinate (X or Y depending on @gap_side) for the gap
3726 * Renders a frame around the rectangle defined by (@x, @y, @width, @height),
3727 * leaving a gap on one side. @xy0_gap and @xy1_gap will mean X coordinates
3728 * for %GTK_POS_TOP and %GTK_POS_BOTTOM gap sides, and Y coordinates for
3729 * %GTK_POS_LEFT and %GTK_POS_RIGHT.
3732 * <title>Typical rendering of a frame with a gap</title>
3733 * <inlinegraphic fileref="frame-gap.png" format="PNG"/>
3739 gtk_render_frame_gap (GtkStyleContext *context,
3745 GtkPositionType gap_side,
3749 GtkThemingEngineClass *engine_class;
3750 GtkThemingEngine *engine;
3752 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3753 g_return_if_fail (cr != NULL);
3754 g_return_if_fail (xy0_gap <= xy1_gap);
3755 g_return_if_fail (xy0_gap >= 0);
3757 if (width <= 0 || height <= 0)
3760 if (gap_side == GTK_POS_LEFT ||
3761 gap_side == GTK_POS_RIGHT)
3762 g_return_if_fail (xy1_gap <= height);
3764 g_return_if_fail (xy1_gap <= width);
3766 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3767 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3771 _gtk_theming_engine_set_context (engine, context);
3772 engine_class->render_frame_gap (engine, cr,
3773 x, y, width, height, gap_side,
3780 * gtk_render_extension:
3781 * @context: a #GtkStyleContext
3783 * @x: X origin of the rectangle
3784 * @y: Y origin of the rectangle
3785 * @width: rectangle width
3786 * @height: rectangle height
3787 * @gap_side: side where the gap is
3789 * Renders a extension (as in a #GtkNotebook tab) in the rectangle
3790 * defined by @x, @y, @width, @height. The side where the extension
3791 * connects to is defined by @gap_side.
3794 * <title>Typical extension rendering</title>
3795 * <inlinegraphic fileref="extensions.png" format="PNG"/>
3801 gtk_render_extension (GtkStyleContext *context,
3807 GtkPositionType gap_side)
3809 GtkThemingEngineClass *engine_class;
3810 GtkThemingEngine *engine;
3812 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3813 g_return_if_fail (cr != NULL);
3815 if (width <= 0 || height <= 0)
3818 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3819 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3823 _gtk_theming_engine_set_context (engine, context);
3824 engine_class->render_extension (engine, cr, x, y, width, height, gap_side);
3830 * gtk_render_handle:
3831 * @context: a #GtkStyleContext
3833 * @x: X origin of the rectangle
3834 * @y: Y origin of the rectangle
3835 * @width: rectangle width
3836 * @height: rectangle height
3838 * Renders a handle (as in #GtkHandleBox, #GtkPaned and
3839 * #GtkWindow<!-- -->'s resize grip), in the rectangle
3840 * determined by @x, @y, @width, @height.
3843 * <title>Handles rendered for the paned and grip classes</title>
3844 * <inlinegraphic fileref="handles.png" format="PNG"/>
3850 gtk_render_handle (GtkStyleContext *context,
3857 GtkThemingEngineClass *engine_class;
3858 GtkThemingEngine *engine;
3860 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3861 g_return_if_fail (cr != NULL);
3863 if (width <= 0 || height <= 0)
3866 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3867 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3871 _gtk_theming_engine_set_context (engine, context);
3872 engine_class->render_handle (engine, cr, x, y, width, height);
3878 * gtk_render_activity:
3879 * @context: a #GtkStyleContext
3881 * @x: X origin of the rectangle
3882 * @y: Y origin of the rectangle
3883 * @width: rectangle width
3884 * @height: rectangle height
3886 * Renders an activity area (Such as in #GtkSpinner or the
3887 * fill line in #GtkRange), the state %GTK_STATE_FLAG_ACTIVE
3888 * determines whether there is activity going on.
3893 gtk_render_activity (GtkStyleContext *context,
3900 GtkThemingEngineClass *engine_class;
3901 GtkThemingEngine *engine;
3903 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3904 g_return_if_fail (cr != NULL);
3906 if (width <= 0 || height <= 0)
3909 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3910 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3914 _gtk_theming_engine_set_context (engine, context);
3915 engine_class->render_activity (engine, cr, x, y, width, height);
3921 * gtk_render_icon_pixbuf:
3922 * @context: a #GtkStyleContext
3923 * @source: the #GtkIconSource specifying the icon to render
3924 * @size: (type int): the size to render the icon at. A size of (GtkIconSize) -1
3925 * means render at the size of the source and don't scale.
3927 * Renders the icon specified by @source at the given @size, returning the result
3930 * Returns: (transfer full): a newly-created #GdkPixbuf containing the rendered icon
3935 gtk_render_icon_pixbuf (GtkStyleContext *context,
3936 const GtkIconSource *source,
3939 GtkThemingEngineClass *engine_class;
3940 GtkThemingEngine *engine;
3942 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
3943 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
3944 g_return_val_if_fail (source != NULL, NULL);
3946 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3947 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3949 _gtk_theming_engine_set_context (engine, context);
3950 return engine_class->render_icon_pixbuf (engine, source, size);
3955 * @context: a #GtkStyleContext
3957 * @pixbuf: a #GdkPixbuf containing the icon to draw
3958 * @x: X position for the @pixbuf
3959 * @y: Y position for the @pixbuf
3961 * Renders the icon in @pixbuf at the specified @x and @y coordinates.
3966 gtk_render_icon (GtkStyleContext *context,
3972 GtkThemingEngineClass *engine_class;
3973 GtkThemingEngine *engine;
3975 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3976 g_return_if_fail (cr != NULL);
3978 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3979 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3983 _gtk_theming_engine_set_context (engine, context);
3984 engine_class->render_icon (engine, cr, pixbuf, x, y);
3990 draw_insertion_cursor (GtkStyleContext *context,
3995 gboolean is_primary,
3996 PangoDirection direction,
3997 gboolean draw_arrow)
4000 GdkRGBA primary_color;
4001 GdkRGBA secondary_color;
4002 gfloat cursor_aspect_ratio;
4008 _gtk_style_context_get_cursor_color (context, &primary_color, &secondary_color);
4009 gdk_cairo_set_source_rgba (cr, is_primary ? &primary_color : &secondary_color);
4011 /* When changing the shape or size of the cursor here,
4012 * propagate the changes to gtktextview.c:text_window_invalidate_cursors().
4015 gtk_style_context_get_style (context,
4016 "cursor-aspect-ratio", &cursor_aspect_ratio,
4019 stem_width = height * cursor_aspect_ratio + 1;
4021 /* put (stem_width % 2) on the proper side of the cursor */
4022 if (direction == PANGO_DIRECTION_LTR)
4023 offset = stem_width / 2;
4025 offset = stem_width - stem_width / 2;
4027 cairo_rectangle (cr, x - offset, y, stem_width, height);
4035 arrow_width = stem_width + 1;
4037 if (direction == PANGO_DIRECTION_RTL)
4039 ax = x - offset - 1;
4040 ay = y + height - arrow_width * 2 - arrow_width + 1;
4042 cairo_move_to (cr, ax, ay + 1);
4043 cairo_line_to (cr, ax - arrow_width, ay + arrow_width);
4044 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4047 else if (direction == PANGO_DIRECTION_LTR)
4049 ax = x + stem_width - offset;
4050 ay = y + height - arrow_width * 2 - arrow_width + 1;
4052 cairo_move_to (cr, ax, ay + 1);
4053 cairo_line_to (cr, ax + arrow_width, ay + arrow_width);
4054 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4058 g_assert_not_reached();
4065 * gtk_render_insertion_cursor:
4066 * @context: a #GtkStyleContext
4070 * @layout: the #PangoLayout of the text
4071 * @index: the index in the #PangoLayout
4072 * @direction: the #PangoDirection of the text
4074 * Draws a text caret on @cr at the specified index of @layout.
4079 gtk_render_insertion_cursor (GtkStyleContext *context,
4083 PangoLayout *layout,
4085 PangoDirection direction)
4087 GtkStyleContextPrivate *priv;
4088 gboolean split_cursor;
4089 PangoRectangle strong_pos, weak_pos;
4090 PangoRectangle *cursor1, *cursor2;
4091 PangoDirection keymap_direction;
4092 PangoDirection direction2;
4094 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4095 g_return_if_fail (cr != NULL);
4096 g_return_if_fail (PANGO_IS_LAYOUT (layout));
4097 g_return_if_fail (index >= 0);
4099 priv = context->priv;
4101 g_object_get (gtk_settings_get_for_screen (priv->screen),
4102 "gtk-split-cursor", &split_cursor,
4105 keymap_direction = gdk_keymap_get_direction (gdk_keymap_get_for_display (gdk_screen_get_display (priv->screen)));
4107 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4109 direction2 = PANGO_DIRECTION_NEUTRAL;
4113 cursor1 = &strong_pos;
4115 if (strong_pos.x != weak_pos.x || strong_pos.y != weak_pos.y)
4117 direction2 = (direction == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
4118 cursor2 = &weak_pos;
4123 if (keymap_direction == direction)
4124 cursor1 = &strong_pos;
4126 cursor1 = &weak_pos;
4129 draw_insertion_cursor (context,
4131 x + PANGO_PIXELS (cursor1->x),
4132 y + PANGO_PIXELS (cursor1->y),
4133 PANGO_PIXELS (cursor1->height),
4136 direction2 != PANGO_DIRECTION_NEUTRAL);
4138 if (direction2 != PANGO_DIRECTION_NEUTRAL)
4140 draw_insertion_cursor (context,
4142 x + PANGO_PIXELS (cursor2->x),
4143 y + PANGO_PIXELS (cursor2->y),
4144 PANGO_PIXELS (cursor2->height),
4152 * gtk_draw_insertion_cursor:
4153 * @widget: a #GtkWidget
4154 * @cr: cairo context to draw to
4155 * @location: location where to draw the cursor (@location->width is ignored)
4156 * @is_primary: if the cursor should be the primary cursor color.
4157 * @direction: whether the cursor is left-to-right or
4158 * right-to-left. Should never be #GTK_TEXT_DIR_NONE
4159 * @draw_arrow: %TRUE to draw a directional arrow on the
4160 * cursor. Should be %FALSE unless the cursor is split.
4162 * Draws a text caret on @cr at @location. This is not a style function
4163 * but merely a convenience function for drawing the standard cursor shape.
4166 * Deprecated: 3.4: Use gtk_render_insertion_cursor() instead.
4169 gtk_draw_insertion_cursor (GtkWidget *widget,
4171 const GdkRectangle *location,
4172 gboolean is_primary,
4173 GtkTextDirection direction,
4174 gboolean draw_arrow)
4176 GtkStyleContext *context;
4178 g_return_if_fail (GTK_IS_WIDGET (widget));
4179 g_return_if_fail (cr != NULL);
4180 g_return_if_fail (location != NULL);
4181 g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
4183 context = gtk_widget_get_style_context (widget);
4185 draw_insertion_cursor (context, cr,
4186 location->x, location->y, location->height,
4188 (direction == GTK_TEXT_DIR_RTL) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR,
4192 static AtkAttributeSet *
4193 add_attribute (AtkAttributeSet *attributes,
4194 AtkTextAttribute attr,
4199 at = g_new (AtkAttribute, 1);
4200 at->name = g_strdup (atk_text_attribute_get_name (attr));
4201 at->value = g_strdup (value);
4203 return g_slist_prepend (attributes, at);
4207 * _gtk_style_context_get_attributes:
4208 * @attributes: a #AtkAttributeSet to add attributes to
4209 * @context: the #GtkStyleContext to get attributes from
4210 * @flags: the state to use with @context
4212 * Adds the foreground and background color from @context to
4213 * @attributes, after translating them to ATK attributes.
4215 * This is a convenience function that can be used in
4216 * implementing the #AtkText interface in widgets.
4218 * Returns: the modified #AtkAttributeSet
4221 _gtk_style_context_get_attributes (AtkAttributeSet *attributes,
4222 GtkStyleContext *context,
4223 GtkStateFlags flags)
4228 gtk_style_context_get_background_color (context, flags, &color);
4229 value = g_strdup_printf ("%u,%u,%u",
4230 (guint) ceil (color.red * 65536 - color.red),
4231 (guint) ceil (color.green * 65536 - color.green),
4232 (guint) ceil (color.blue * 65536 - color.blue));
4233 attributes = add_attribute (attributes, ATK_TEXT_ATTR_BG_COLOR, value);
4236 gtk_style_context_get_color (context, flags, &color);
4237 value = g_strdup_printf ("%u,%u,%u",
4238 (guint) ceil (color.red * 65536 - color.red),
4239 (guint) ceil (color.green * 65536 - color.green),
4240 (guint) ceil (color.blue * 65536 - color.blue));
4241 attributes = add_attribute (attributes, ATK_TEXT_ATTR_FG_COLOR, value);