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 GtkThemingEngine *theming_engine;
361 GtkTextDirection direction;
363 GtkCssChange relevant_changes;
364 GtkCssChange pending_changes;
366 guint invalidating_context : 1;
382 static guint signals[LAST_SIGNAL] = { 0 };
384 static void gtk_style_context_finalize (GObject *object);
386 static void gtk_style_context_impl_set_property (GObject *object,
390 static void gtk_style_context_impl_get_property (GObject *object,
394 static GtkSymbolicColor *
395 gtk_style_context_color_lookup_func (gpointer contextp,
399 G_DEFINE_TYPE (GtkStyleContext, gtk_style_context, G_TYPE_OBJECT)
402 gtk_style_context_real_changed (GtkStyleContext *context)
404 GtkStyleContextPrivate *priv = context->priv;
407 _gtk_widget_style_context_invalidated (priv->widget);
411 gtk_style_context_class_init (GtkStyleContextClass *klass)
413 GObjectClass *object_class = G_OBJECT_CLASS (klass);
415 object_class->finalize = gtk_style_context_finalize;
416 object_class->set_property = gtk_style_context_impl_set_property;
417 object_class->get_property = gtk_style_context_impl_get_property;
419 klass->changed = gtk_style_context_real_changed;
422 g_signal_new (I_("changed"),
423 G_TYPE_FROM_CLASS (object_class),
425 G_STRUCT_OFFSET (GtkStyleContextClass, changed),
427 g_cclosure_marshal_VOID__VOID,
430 g_object_class_install_property (object_class,
432 g_param_spec_object ("screen",
434 P_("The associated GdkScreen"),
436 GTK_PARAM_READWRITE));
437 g_object_class_install_property (object_class,
439 g_param_spec_enum ("direction",
441 P_("Text direction"),
442 GTK_TYPE_TEXT_DIRECTION,
444 GTK_PARAM_READWRITE));
446 * GtkStyleContext:parent:
448 * Sets or gets the style context's parent. See gtk_style_context_set_parent()
453 g_object_class_install_property (object_class,
455 g_param_spec_object ("parent",
457 P_("The parent style context"),
458 GTK_TYPE_STYLE_CONTEXT,
459 GTK_PARAM_READWRITE));
461 g_type_class_add_private (object_class, sizeof (GtkStyleContextPrivate));
464 static GtkStyleInfo *
465 style_info_new (void)
469 info = g_slice_new0 (GtkStyleInfo);
470 info->style_classes = g_array_new (FALSE, FALSE, sizeof (GQuark));
471 info->regions = g_array_new (FALSE, FALSE, sizeof (GtkRegion));
477 style_info_free (GtkStyleInfo *info)
479 g_array_free (info->style_classes, TRUE);
480 g_array_free (info->regions, TRUE);
481 g_slice_free (GtkStyleInfo, info);
484 static GtkStyleInfo *
485 style_info_copy (const GtkStyleInfo *info)
489 copy = style_info_new ();
490 g_array_insert_vals (copy->style_classes, 0,
491 info->style_classes->data,
492 info->style_classes->len);
494 g_array_insert_vals (copy->regions, 0,
498 copy->junction_sides = info->junction_sides;
499 copy->state_flags = info->state_flags;
500 copy->data = info->data;
506 style_info_hash (gconstpointer elem)
508 const GtkStyleInfo *info;
513 for (i = 0; i < info->style_classes->len; i++)
515 hash += g_array_index (info->style_classes, GQuark, i);
519 for (i = 0; i < info->regions->len; i++)
523 region = &g_array_index (info->regions, GtkRegion, i);
524 hash += region->class_quark;
525 hash += region->flags;
529 return hash ^ info->state_flags;
533 style_info_equal (gconstpointer elem1,
536 const GtkStyleInfo *info1, *info2;
541 if (info1->state_flags != info2->state_flags)
544 if (info1->junction_sides != info2->junction_sides)
547 if (info1->style_classes->len != info2->style_classes->len)
550 if (memcmp (info1->style_classes->data,
551 info2->style_classes->data,
552 info1->style_classes->len * sizeof (GQuark)) != 0)
555 if (info1->regions->len != info2->regions->len)
558 if (memcmp (info1->regions->data,
559 info2->regions->data,
560 info1->regions->len * sizeof (GtkRegion)) != 0)
567 style_data_new (void)
571 data = g_slice_new0 (StyleData);
577 clear_property_cache (StyleData *data)
581 if (!data->property_cache)
584 for (i = 0; i < data->property_cache->len; i++)
586 PropertyValue *node = &g_array_index (data->property_cache, PropertyValue, i);
588 g_param_spec_unref (node->pspec);
589 g_value_unset (&node->value);
592 g_array_free (data->property_cache, TRUE);
593 data->property_cache = NULL;
597 style_data_free (StyleData *data)
599 g_object_unref (data->store);
600 clear_property_cache (data);
602 g_slice_free (StyleData, data);
606 gtk_style_context_init (GtkStyleContext *style_context)
608 GtkStyleContextPrivate *priv;
611 priv = style_context->priv = G_TYPE_INSTANCE_GET_PRIVATE (style_context,
612 GTK_TYPE_STYLE_CONTEXT,
613 GtkStyleContextPrivate);
615 priv->style_data = g_hash_table_new_full (style_info_hash,
617 (GDestroyNotify) style_info_free,
618 (GDestroyNotify) style_data_free);
619 priv->theming_engine = g_object_ref ((gpointer) gtk_theming_engine_load (NULL));
621 priv->direction = GTK_TEXT_DIR_LTR;
623 priv->screen = gdk_screen_get_default ();
624 priv->cascade = _gtk_style_cascade_get_for_screen (priv->screen);
625 g_object_ref (priv->cascade);
626 priv->relevant_changes = GTK_CSS_CHANGE_ANY;
628 /* Create default info store */
629 info = style_info_new ();
630 priv->info_stack = g_slist_prepend (priv->info_stack, info);
634 gtk_style_context_finalize (GObject *object)
636 GtkStyleContextPrivate *priv;
637 GtkStyleContext *style_context;
639 style_context = GTK_STYLE_CONTEXT (object);
640 priv = style_context->priv;
642 /* children hold a reference to us */
643 g_assert (priv->children == NULL);
645 gtk_style_context_set_parent (style_context, NULL);
647 if (priv->widget_path)
648 gtk_widget_path_free (priv->widget_path);
650 g_hash_table_destroy (priv->style_data);
652 g_object_unref (priv->cascade);
654 g_slist_free_full (priv->info_stack, (GDestroyNotify) style_info_free);
656 if (priv->theming_engine)
657 g_object_unref (priv->theming_engine);
659 G_OBJECT_CLASS (gtk_style_context_parent_class)->finalize (object);
663 gtk_style_context_impl_set_property (GObject *object,
668 GtkStyleContext *style_context;
670 style_context = GTK_STYLE_CONTEXT (object);
675 gtk_style_context_set_screen (style_context,
676 g_value_get_object (value));
679 gtk_style_context_set_direction (style_context,
680 g_value_get_enum (value));
683 gtk_style_context_set_parent (style_context,
684 g_value_get_object (value));
687 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
693 gtk_style_context_impl_get_property (GObject *object,
698 GtkStyleContext *style_context;
699 GtkStyleContextPrivate *priv;
701 style_context = GTK_STYLE_CONTEXT (object);
702 priv = style_context->priv;
707 g_value_set_object (value, priv->screen);
710 g_value_set_enum (value, priv->direction);
713 g_value_set_object (value, priv->parent);
716 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
722 build_properties (GtkStyleContext *context,
723 StyleData *style_data,
727 GtkStyleContextPrivate *priv;
728 GtkCssMatcher matcher;
729 GtkCssLookup *lookup;
731 priv = context->priv;
733 _gtk_css_matcher_init (&matcher, path, state);
734 lookup = _gtk_css_lookup_new ();
736 _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
740 style_data->store = _gtk_css_computed_values_new ();
741 _gtk_css_lookup_resolve (lookup, context, style_data->store);
742 _gtk_css_lookup_free (lookup);
745 static GtkWidgetPath *
746 create_query_path (GtkStyleContext *context)
748 GtkStyleContextPrivate *priv;
753 priv = context->priv;
754 path = gtk_widget_path_copy (priv->widget ? gtk_widget_get_path (priv->widget) : priv->widget_path);
755 pos = gtk_widget_path_length (path) - 1;
757 info = priv->info_stack->data;
759 /* Set widget regions */
760 for (i = 0; i < info->regions->len; i++)
764 region = &g_array_index (info->regions, GtkRegion, i);
765 gtk_widget_path_iter_add_region (path, pos,
766 g_quark_to_string (region->class_quark),
770 /* Set widget classes */
771 for (i = 0; i < info->style_classes->len; i++)
775 quark = g_array_index (info->style_classes, GQuark, i);
776 gtk_widget_path_iter_add_class (path, pos,
777 g_quark_to_string (quark));
784 style_data_lookup (GtkStyleContext *context)
786 GtkStyleContextPrivate *priv;
789 priv = context->priv;
790 info = priv->info_stack->data;
792 /* Current data in use is cached, just return it */
796 g_assert (priv->widget != NULL || priv->widget_path != NULL);
798 info->data = g_hash_table_lookup (priv->style_data, info);
804 path = create_query_path (context);
806 info->data = style_data_new ();
807 g_hash_table_insert (priv->style_data,
808 style_info_copy (info),
811 build_properties (context, info->data, path, info->state_flags);
813 gtk_widget_path_free (path);
816 if (priv->theming_engine)
817 g_object_unref (priv->theming_engine);
819 priv->theming_engine = g_object_ref (
820 _gtk_css_engine_value_get_engine (
821 _gtk_css_computed_values_get_value (info->data->store, GTK_CSS_PROPERTY_ENGINE)));
827 gtk_style_context_set_invalid (GtkStyleContext *context,
830 GtkStyleContextPrivate *priv;
832 priv = context->priv;
834 if (priv->invalid == invalid)
837 priv->invalid = invalid;
842 gtk_style_context_set_invalid (priv->parent, TRUE);
843 else if (priv->widget)
844 gtk_widget_queue_resize (priv->widget);
848 /* returns TRUE if someone called gtk_style_context_save() but hasn't
849 * called gtk_style_context_restore() yet.
850 * In those situations we don't invalidate the context when somebody
851 * changes state/regions/classes.
854 gtk_style_context_is_saved (GtkStyleContext *context)
856 return context->priv->info_stack->next != NULL;
860 gtk_style_context_queue_invalidate_internal (GtkStyleContext *context,
863 GtkStyleContextPrivate *priv = context->priv;
864 GtkStyleInfo *info = priv->info_stack->data;
866 if (gtk_style_context_is_saved (context))
872 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_STATE);
873 /* XXX: We need to invalidate siblings here somehow */
878 * gtk_style_context_new:
880 * Creates a standalone #GtkStyleContext, this style context
881 * won't be attached to any widget, so you may want
882 * to call gtk_style_context_set_path() yourself.
885 * This function is only useful when using the theming layer
886 * separated from GTK+, if you are using #GtkStyleContext to
887 * theme #GtkWidget<!-- -->s, use gtk_widget_get_style_context()
888 * in order to get a style context ready to theme the widget.
891 * Returns: A newly created #GtkStyleContext.
894 gtk_style_context_new (void)
896 return g_object_new (GTK_TYPE_STYLE_CONTEXT, NULL);
900 _gtk_style_context_set_widget (GtkStyleContext *context,
903 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
904 g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget));
906 context->priv->widget = widget;
908 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY_SELF);
912 * gtk_style_context_add_provider:
913 * @context: a #GtkStyleContext
914 * @provider: a #GtkStyleProvider
915 * @priority: the priority of the style provider. The lower
916 * it is, the earlier it will be used in the style
917 * construction. Typically this will be in the range
918 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
919 * %GTK_STYLE_PROVIDER_PRIORITY_USER
921 * Adds a style provider to @context, to be used in style construction.
923 * <note><para>If both priorities are the same, A #GtkStyleProvider
924 * added through this function takes precedence over another added
925 * through gtk_style_context_add_provider_for_screen().</para></note>
930 gtk_style_context_add_provider (GtkStyleContext *context,
931 GtkStyleProvider *provider,
934 GtkStyleContextPrivate *priv;
936 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
937 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
939 priv = context->priv;
941 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
943 GtkStyleCascade *new_cascade;
945 new_cascade = _gtk_style_cascade_new ();
946 _gtk_style_cascade_set_parent (new_cascade, priv->cascade);
947 g_object_unref (priv->cascade);
948 priv->cascade = new_cascade;
951 _gtk_style_cascade_add_provider (priv->cascade, provider, priority);
953 gtk_style_context_invalidate (context);
957 * gtk_style_context_remove_provider:
958 * @context: a #GtkStyleContext
959 * @provider: a #GtkStyleProvider
961 * Removes @provider from the style providers list in @context.
966 gtk_style_context_remove_provider (GtkStyleContext *context,
967 GtkStyleProvider *provider)
969 GtkStyleContextPrivate *priv;
971 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
972 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
974 priv = context->priv;
976 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
979 _gtk_style_cascade_remove_provider (priv->cascade, provider);
983 * gtk_style_context_reset_widgets:
984 * @screen: a #GdkScreen
986 * This function recomputes the styles for all widgets under a particular
987 * #GdkScreen. This is useful when some global parameter has changed that
988 * affects the appearance of all widgets, because when a widget gets a new
989 * style, it will both redraw and recompute any cached information about
990 * its appearance. As an example, it is used when the color scheme changes
991 * in the related #GtkSettings object.
996 gtk_style_context_reset_widgets (GdkScreen *screen)
998 GList *list, *toplevels;
1000 _gtk_icon_set_invalidate_caches ();
1002 toplevels = gtk_window_list_toplevels ();
1003 g_list_foreach (toplevels, (GFunc) g_object_ref, NULL);
1005 for (list = toplevels; list; list = list->next)
1007 if (gtk_widget_get_screen (list->data) == screen)
1008 gtk_widget_reset_style (list->data);
1010 g_object_unref (list->data);
1013 g_list_free (toplevels);
1017 * gtk_style_context_add_provider_for_screen:
1018 * @screen: a #GdkScreen
1019 * @provider: a #GtkStyleProvider
1020 * @priority: the priority of the style provider. The lower
1021 * it is, the earlier it will be used in the style
1022 * construction. Typically this will be in the range
1023 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1024 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1026 * Adds a global style provider to @screen, which will be used
1027 * in style construction for all #GtkStyleContext<!-- -->s under
1030 * GTK+ uses this to make styling information from #GtkSettings
1033 * <note><para>If both priorities are the same, A #GtkStyleProvider
1034 * added through gtk_style_context_add_provider() takes precedence
1035 * over another added through this function.</para></note>
1040 gtk_style_context_add_provider_for_screen (GdkScreen *screen,
1041 GtkStyleProvider *provider,
1044 GtkStyleCascade *cascade;
1046 g_return_if_fail (GDK_IS_SCREEN (screen));
1047 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1049 cascade = _gtk_style_cascade_get_for_screen (screen);
1050 _gtk_style_cascade_add_provider (cascade, provider, priority);
1054 * gtk_style_context_remove_provider_for_screen:
1055 * @screen: a #GdkScreen
1056 * @provider: a #GtkStyleProvider
1058 * Removes @provider from the global style providers list in @screen.
1063 gtk_style_context_remove_provider_for_screen (GdkScreen *screen,
1064 GtkStyleProvider *provider)
1066 GtkStyleCascade *cascade;
1068 g_return_if_fail (GDK_IS_SCREEN (screen));
1069 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1071 cascade = _gtk_style_cascade_get_for_screen (screen);
1072 _gtk_style_cascade_remove_provider (cascade, provider);
1076 * gtk_style_context_get_section:
1077 * @context: a #GtkStyleContext
1078 * @property: style property name
1080 * Queries the location in the CSS where @property was defined for the
1081 * current @context. Note that the state to be queried is taken from
1082 * gtk_style_context_get_state().
1084 * If the location is not available, %NULL will be returned. The
1085 * location might not be available for various reasons, such as the
1086 * property being overridden, @property not naming a supported CSS
1087 * property or tracking of definitions being disabled for performance
1090 * Shorthand CSS properties cannot be queried for a location and will
1091 * always return %NULL.
1093 * Returns: %NULL or the section where value was defined
1096 gtk_style_context_get_section (GtkStyleContext *context,
1097 const gchar *property)
1099 GtkStyleContextPrivate *priv;
1100 GtkStyleProperty *prop;
1103 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1104 g_return_val_if_fail (property != NULL, NULL);
1106 priv = context->priv;
1107 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
1109 prop = _gtk_style_property_lookup (property);
1110 if (!GTK_IS_CSS_STYLE_PROPERTY (prop))
1113 data = style_data_lookup (context);
1114 return _gtk_css_computed_values_get_section (data->store, _gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (prop)));
1117 static GtkCssValue *
1118 gtk_style_context_query_func (guint id,
1121 return _gtk_css_computed_values_get_value (values, id);
1125 * gtk_style_context_get_property:
1126 * @context: a #GtkStyleContext
1127 * @property: style property name
1128 * @state: state to retrieve the property value for
1129 * @value: (out) (transfer full): return location for the style property value
1131 * Gets a style property from @context for the given state.
1133 * When @value is no longer needed, g_value_unset() must be called
1134 * to free any allocated memory.
1139 gtk_style_context_get_property (GtkStyleContext *context,
1140 const gchar *property,
1141 GtkStateFlags state,
1144 GtkStyleContextPrivate *priv;
1145 GtkStyleProperty *prop;
1148 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1149 g_return_if_fail (property != NULL);
1150 g_return_if_fail (value != NULL);
1152 priv = context->priv;
1153 g_return_if_fail (priv->widget != NULL || priv->widget_path != NULL);
1155 prop = _gtk_style_property_lookup (property);
1158 g_warning ("Style property \"%s\" is not registered", property);
1161 if (_gtk_style_property_get_value_type (prop) == G_TYPE_NONE)
1163 g_warning ("Style property \"%s\" is not gettable", property);
1167 gtk_style_context_save (context);
1168 gtk_style_context_set_state (context, state);
1169 data = style_data_lookup (context);
1170 _gtk_style_property_query (prop, value, gtk_style_context_query_func, data->store);
1171 gtk_style_context_restore (context);
1175 * gtk_style_context_get_valist:
1176 * @context: a #GtkStyleContext
1177 * @state: state to retrieve the property values for
1178 * @args: va_list of property name/return location pairs, followed by %NULL
1180 * Retrieves several style property values from @context for a given state.
1185 gtk_style_context_get_valist (GtkStyleContext *context,
1186 GtkStateFlags state,
1189 const gchar *property_name;
1191 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1193 property_name = va_arg (args, const gchar *);
1195 while (property_name)
1197 gchar *error = NULL;
1198 GValue value = G_VALUE_INIT;
1200 gtk_style_context_get_property (context,
1205 G_VALUE_LCOPY (&value, args, 0, &error);
1206 g_value_unset (&value);
1210 g_warning ("Could not get style property \"%s\": %s", property_name, error);
1215 property_name = va_arg (args, const gchar *);
1220 * gtk_style_context_get:
1221 * @context: a #GtkStyleContext
1222 * @state: state to retrieve the property values for
1223 * @...: property name /return value pairs, followed by %NULL
1225 * Retrieves several style property values from @context for a
1231 gtk_style_context_get (GtkStyleContext *context,
1232 GtkStateFlags state,
1237 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1239 va_start (args, state);
1240 gtk_style_context_get_valist (context, state, args);
1245 * gtk_style_context_set_state:
1246 * @context: a #GtkStyleContext
1247 * @flags: state to represent
1249 * Sets the state to be used when rendering with any
1250 * of the gtk_render_*() functions.
1255 gtk_style_context_set_state (GtkStyleContext *context,
1256 GtkStateFlags flags)
1258 GtkStyleContextPrivate *priv;
1261 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1263 priv = context->priv;
1264 info = priv->info_stack->data;
1265 info->state_flags = flags;
1267 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_STATE);
1271 * gtk_style_context_get_state:
1272 * @context: a #GtkStyleContext
1274 * Returns the state used when rendering.
1276 * Returns: the state flags
1281 gtk_style_context_get_state (GtkStyleContext *context)
1283 GtkStyleContextPrivate *priv;
1286 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
1288 priv = context->priv;
1289 info = priv->info_stack->data;
1291 return info->state_flags;
1295 * gtk_style_context_state_is_running:
1296 * @context: a #GtkStyleContext
1297 * @state: a widget state
1298 * @progress: (out): return location for the transition progress
1300 * Returns %TRUE if there is a transition animation running for the
1301 * current region (see gtk_style_context_push_animatable_region()).
1303 * If @progress is not %NULL, the animation progress will be returned
1304 * there, 0.0 means the state is closest to being unset, while 1.0 means
1305 * it's closest to being set. This means transition animation will
1306 * run from 0 to 1 when @state is being set and from 1 to 0 when
1309 * Returns: %TRUE if there is a running transition animation for @state.
1313 * Deprecated: 3.6: This function always returns %FALSE
1316 gtk_style_context_state_is_running (GtkStyleContext *context,
1320 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1326 * gtk_style_context_set_path:
1327 * @context: a #GtkStyleContext
1328 * @path: a #GtkWidgetPath
1330 * Sets the #GtkWidgetPath used for style matching. As a
1331 * consequence, the style will be regenerated to match
1332 * the new given path.
1334 * If you are using a #GtkStyleContext returned from
1335 * gtk_widget_get_style_context(), you do not need to call
1341 gtk_style_context_set_path (GtkStyleContext *context,
1342 GtkWidgetPath *path)
1344 GtkStyleContextPrivate *priv;
1346 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1347 g_return_if_fail (path != NULL);
1349 priv = context->priv;
1350 g_return_if_fail (priv->widget == NULL);
1352 if (priv->widget_path)
1354 gtk_widget_path_free (priv->widget_path);
1355 priv->widget_path = NULL;
1359 priv->widget_path = gtk_widget_path_copy (path);
1361 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY);
1365 * gtk_style_context_get_path:
1366 * @context: a #GtkStyleContext
1368 * Returns the widget path used for style matching.
1370 * Returns: (transfer none): A #GtkWidgetPath
1374 const GtkWidgetPath *
1375 gtk_style_context_get_path (GtkStyleContext *context)
1377 GtkStyleContextPrivate *priv;
1379 priv = context->priv;
1381 return gtk_widget_get_path (priv->widget);
1383 return priv->widget_path;
1387 * gtk_style_context_set_parent:
1388 * @context: a #GtkStyleContext
1389 * @parent: (allow-none): the new parent or %NULL
1391 * Sets the parent style context for @context. The parent style
1392 * context is used to implement
1393 * <ulink url="http://www.w3.org/TR/css3-cascade/#inheritance">inheritance</ulink>
1396 * If you are using a #GtkStyleContext returned from
1397 * gtk_widget_get_style_context(), the parent will be set for you.
1402 gtk_style_context_set_parent (GtkStyleContext *context,
1403 GtkStyleContext *parent)
1405 GtkStyleContextPrivate *priv;
1407 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1408 g_return_if_fail (parent == NULL || GTK_IS_STYLE_CONTEXT (parent));
1410 priv = context->priv;
1412 if (priv->parent == parent)
1417 parent->priv->children = g_slist_prepend (parent->priv->children, context);
1418 g_object_ref (parent);
1420 gtk_style_context_set_invalid (parent, TRUE);
1425 priv->parent->priv->children = g_slist_remove (priv->parent->priv->children, context);
1426 g_object_unref (priv->parent);
1429 priv->parent = parent;
1431 g_object_notify (G_OBJECT (context), "parent");
1432 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY_PARENT | GTK_CSS_CHANGE_ANY_SIBLING);
1436 * gtk_style_context_get_parent:
1437 * @context: a #GtkStyleContext
1439 * Gets the parent context set via gtk_style_context_set_parent().
1440 * See that function for details.
1442 * Returns: (transfer none): the parent context or %NULL
1447 gtk_style_context_get_parent (GtkStyleContext *context)
1449 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1451 return context->priv->parent;
1455 * gtk_style_context_save:
1456 * @context: a #GtkStyleContext
1458 * Saves the @context state, so all modifications done through
1459 * gtk_style_context_add_class(), gtk_style_context_remove_class(),
1460 * gtk_style_context_add_region(), gtk_style_context_remove_region()
1461 * or gtk_style_context_set_junction_sides() can be reverted in one
1462 * go through gtk_style_context_restore().
1467 gtk_style_context_save (GtkStyleContext *context)
1469 GtkStyleContextPrivate *priv;
1472 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1474 priv = context->priv;
1476 g_assert (priv->info_stack != NULL);
1478 info = style_info_copy (priv->info_stack->data);
1479 priv->info_stack = g_slist_prepend (priv->info_stack, info);
1483 * gtk_style_context_restore:
1484 * @context: a #GtkStyleContext
1486 * Restores @context state to a previous stage.
1487 * See gtk_style_context_save().
1492 gtk_style_context_restore (GtkStyleContext *context)
1494 GtkStyleContextPrivate *priv;
1497 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1499 priv = context->priv;
1501 if (priv->info_stack)
1503 info = priv->info_stack->data;
1504 priv->info_stack = g_slist_remove (priv->info_stack, info);
1505 style_info_free (info);
1508 if (!priv->info_stack)
1510 g_warning ("Unpaired gtk_style_context_restore() call");
1512 /* Create default region */
1513 info = style_info_new ();
1514 priv->info_stack = g_slist_prepend (priv->info_stack, info);
1519 style_class_find (GArray *array,
1524 gboolean found = FALSE;
1530 if (!array || array->len == 0)
1534 max = array->len - 1;
1540 mid = (min + max) / 2;
1541 item = g_array_index (array, GQuark, mid);
1543 if (class_quark == item)
1548 else if (class_quark > item)
1549 min = pos = mid + 1;
1556 while (!found && min <= max);
1565 region_find (GArray *array,
1570 gboolean found = FALSE;
1576 if (!array || array->len == 0)
1580 max = array->len - 1;
1586 mid = (min + max) / 2;
1587 region = &g_array_index (array, GtkRegion, mid);
1589 if (region->class_quark == class_quark)
1594 else if (region->class_quark > class_quark)
1595 min = pos = mid + 1;
1602 while (!found && min <= max);
1611 * gtk_style_context_add_class:
1612 * @context: a #GtkStyleContext
1613 * @class_name: class name to use in styling
1615 * Adds a style class to @context, so posterior calls to
1616 * gtk_style_context_get() or any of the gtk_render_*()
1617 * functions will make use of this new class for styling.
1619 * In the CSS file format, a #GtkEntry defining an "entry"
1620 * class, would be matched by:
1623 * GtkEntry.entry { ... }
1626 * While any widget defining an "entry" class would be
1635 gtk_style_context_add_class (GtkStyleContext *context,
1636 const gchar *class_name)
1638 GtkStyleContextPrivate *priv;
1643 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1644 g_return_if_fail (class_name != NULL);
1646 priv = context->priv;
1647 class_quark = g_quark_from_string (class_name);
1649 g_assert (priv->info_stack != NULL);
1650 info = priv->info_stack->data;
1652 if (!style_class_find (info->style_classes, class_quark, &position))
1654 g_array_insert_val (info->style_classes, position, class_quark);
1656 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_CLASS);
1661 * gtk_style_context_remove_class:
1662 * @context: a #GtkStyleContext
1663 * @class_name: class name to remove
1665 * Removes @class_name from @context.
1670 gtk_style_context_remove_class (GtkStyleContext *context,
1671 const gchar *class_name)
1673 GtkStyleContextPrivate *priv;
1678 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1679 g_return_if_fail (class_name != NULL);
1681 class_quark = g_quark_try_string (class_name);
1686 priv = context->priv;
1688 g_assert (priv->info_stack != NULL);
1689 info = priv->info_stack->data;
1691 if (style_class_find (info->style_classes, class_quark, &position))
1693 g_array_remove_index (info->style_classes, position);
1695 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_CLASS);
1700 * gtk_style_context_has_class:
1701 * @context: a #GtkStyleContext
1702 * @class_name: a class name
1704 * Returns %TRUE if @context currently has defined the
1707 * Returns: %TRUE if @context has @class_name defined
1712 gtk_style_context_has_class (GtkStyleContext *context,
1713 const gchar *class_name)
1715 GtkStyleContextPrivate *priv;
1719 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1720 g_return_val_if_fail (class_name != NULL, FALSE);
1722 class_quark = g_quark_try_string (class_name);
1727 priv = context->priv;
1729 g_assert (priv->info_stack != NULL);
1730 info = priv->info_stack->data;
1732 if (style_class_find (info->style_classes, class_quark, NULL))
1739 * gtk_style_context_list_classes:
1740 * @context: a #GtkStyleContext
1742 * Returns the list of classes currently defined in @context.
1744 * Returns: (transfer container) (element-type utf8): a #GList of
1745 * strings with the currently defined classes. The contents
1746 * of the list are owned by GTK+, but you must free the list
1747 * itself with g_list_free() when you are done with it.
1752 gtk_style_context_list_classes (GtkStyleContext *context)
1754 GtkStyleContextPrivate *priv;
1756 GList *classes = NULL;
1759 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1761 priv = context->priv;
1763 g_assert (priv->info_stack != NULL);
1764 info = priv->info_stack->data;
1766 for (i = 0; i < info->style_classes->len; i++)
1770 quark = g_array_index (info->style_classes, GQuark, i);
1771 classes = g_list_prepend (classes, (gchar *) g_quark_to_string (quark));
1778 * gtk_style_context_list_regions:
1779 * @context: a #GtkStyleContext
1781 * Returns the list of regions currently defined in @context.
1783 * Returns: (transfer container) (element-type utf8): a #GList of
1784 * strings with the currently defined regions. The contents
1785 * of the list are owned by GTK+, but you must free the list
1786 * itself with g_list_free() when you are done with it.
1791 gtk_style_context_list_regions (GtkStyleContext *context)
1793 GtkStyleContextPrivate *priv;
1795 GList *classes = NULL;
1798 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1800 priv = context->priv;
1802 g_assert (priv->info_stack != NULL);
1803 info = priv->info_stack->data;
1805 for (i = 0; i < info->regions->len; i++)
1808 const gchar *class_name;
1810 region = &g_array_index (info->regions, GtkRegion, i);
1812 class_name = g_quark_to_string (region->class_quark);
1813 classes = g_list_prepend (classes, (gchar *) class_name);
1820 _gtk_style_context_check_region_name (const gchar *str)
1822 g_return_val_if_fail (str != NULL, FALSE);
1824 if (!g_ascii_islower (str[0]))
1830 !g_ascii_islower (*str))
1840 * gtk_style_context_add_region:
1841 * @context: a #GtkStyleContext
1842 * @region_name: region name to use in styling
1843 * @flags: flags that apply to the region
1845 * Adds a region to @context, so posterior calls to
1846 * gtk_style_context_get() or any of the gtk_render_*()
1847 * functions will make use of this new region for styling.
1849 * In the CSS file format, a #GtkTreeView defining a "row"
1850 * region, would be matched by:
1853 * GtkTreeView row { ... }
1856 * Pseudo-classes are used for matching @flags, so the two
1859 * GtkTreeView row:nth-child(even) { ... }
1860 * GtkTreeView row:nth-child(odd) { ... }
1863 * would apply to even and odd rows, respectively.
1865 * <note><para>Region names must only contain lowercase letters
1866 * and '-', starting always with a lowercase letter.</para></note>
1871 gtk_style_context_add_region (GtkStyleContext *context,
1872 const gchar *region_name,
1873 GtkRegionFlags flags)
1875 GtkStyleContextPrivate *priv;
1877 GQuark region_quark;
1880 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1881 g_return_if_fail (region_name != NULL);
1882 g_return_if_fail (_gtk_style_context_check_region_name (region_name));
1884 priv = context->priv;
1885 region_quark = g_quark_from_string (region_name);
1887 g_assert (priv->info_stack != NULL);
1888 info = priv->info_stack->data;
1890 if (!region_find (info->regions, region_quark, &position))
1894 region.class_quark = region_quark;
1895 region.flags = flags;
1897 g_array_insert_val (info->regions, position, region);
1899 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_REGION);
1904 * gtk_style_context_remove_region:
1905 * @context: a #GtkStyleContext
1906 * @region_name: region name to unset
1908 * Removes a region from @context.
1913 gtk_style_context_remove_region (GtkStyleContext *context,
1914 const gchar *region_name)
1916 GtkStyleContextPrivate *priv;
1918 GQuark region_quark;
1921 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1922 g_return_if_fail (region_name != NULL);
1924 region_quark = g_quark_try_string (region_name);
1929 priv = context->priv;
1931 g_assert (priv->info_stack != NULL);
1932 info = priv->info_stack->data;
1934 if (region_find (info->regions, region_quark, &position))
1936 g_array_remove_index (info->regions, position);
1938 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_REGION);
1943 * gtk_style_context_has_region:
1944 * @context: a #GtkStyleContext
1945 * @region_name: a region name
1946 * @flags_return: (out) (allow-none): return location for region flags
1948 * Returns %TRUE if @context has the region defined.
1949 * If @flags_return is not %NULL, it is set to the flags
1950 * affecting the region.
1952 * Returns: %TRUE if region is defined
1957 gtk_style_context_has_region (GtkStyleContext *context,
1958 const gchar *region_name,
1959 GtkRegionFlags *flags_return)
1961 GtkStyleContextPrivate *priv;
1963 GQuark region_quark;
1966 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1967 g_return_val_if_fail (region_name != NULL, FALSE);
1972 region_quark = g_quark_try_string (region_name);
1977 priv = context->priv;
1979 g_assert (priv->info_stack != NULL);
1980 info = priv->info_stack->data;
1982 if (region_find (info->regions, region_quark, &position))
1988 region = &g_array_index (info->regions, GtkRegion, position);
1989 *flags_return = region->flags;
1998 style_property_values_cmp (gconstpointer bsearch_node1,
1999 gconstpointer bsearch_node2)
2001 const PropertyValue *val1 = bsearch_node1;
2002 const PropertyValue *val2 = bsearch_node2;
2004 if (val1->widget_type != val2->widget_type)
2005 return val1->widget_type < val2->widget_type ? -1 : 1;
2007 if (val1->pspec != val2->pspec)
2008 return val1->pspec < val2->pspec ? -1 : 1;
2010 if (val1->state != val2->state)
2011 return val1->state < val2->state ? -1 : 1;
2017 _gtk_style_context_peek_property (GtkStyleContext *context,
2020 StyleData *data = style_data_lookup (context);
2022 return _gtk_css_computed_values_get_value (data->store, property_id);
2026 _gtk_style_context_get_number (GtkStyleContext *context,
2028 double one_hundred_percent)
2032 value = _gtk_style_context_peek_property (context, property_id);
2033 return _gtk_css_number_value_get (value, one_hundred_percent);
2037 _gtk_style_context_peek_style_property (GtkStyleContext *context,
2039 GtkStateFlags state,
2042 GtkStyleContextPrivate *priv;
2043 PropertyValue *pcache, key = { 0 };
2047 priv = context->priv;
2049 gtk_style_context_save (context);
2050 gtk_style_context_set_state (context, state);
2051 data = style_data_lookup (context);
2052 gtk_style_context_restore (context);
2054 key.widget_type = widget_type;
2058 /* need value cache array */
2059 if (!data->property_cache)
2060 data->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
2063 pcache = bsearch (&key,
2064 data->property_cache->data, data->property_cache->len,
2065 sizeof (PropertyValue), style_property_values_cmp);
2067 return &pcache->value;
2071 while (i < data->property_cache->len &&
2072 style_property_values_cmp (&key, &g_array_index (data->property_cache, PropertyValue, i)) >= 0)
2075 g_array_insert_val (data->property_cache, i, key);
2076 pcache = &g_array_index (data->property_cache, PropertyValue, i);
2078 /* cache miss, initialize value type, then set contents */
2079 g_param_spec_ref (pcache->pspec);
2080 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2082 if (priv->widget || priv->widget_path)
2084 if (gtk_style_provider_get_style_property (GTK_STYLE_PROVIDER (priv->cascade),
2085 priv->widget ? gtk_widget_get_path (priv->widget)
2086 : priv->widget_path,
2087 state, pspec, &pcache->value))
2089 /* Resolve symbolic colors to GdkColor/GdkRGBA */
2090 if (G_VALUE_TYPE (&pcache->value) == GTK_TYPE_SYMBOLIC_COLOR)
2092 GtkSymbolicColor *color;
2095 color = g_value_dup_boxed (&pcache->value);
2097 g_value_unset (&pcache->value);
2099 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2100 g_value_init (&pcache->value, GDK_TYPE_RGBA);
2102 g_value_init (&pcache->value, GDK_TYPE_COLOR);
2104 if (_gtk_style_context_resolve_color (context, color, &rgba))
2106 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2107 g_value_set_boxed (&pcache->value, &rgba);
2112 rgb.red = rgba.red * 65535. + 0.5;
2113 rgb.green = rgba.green * 65535. + 0.5;
2114 rgb.blue = rgba.blue * 65535. + 0.5;
2116 g_value_set_boxed (&pcache->value, &rgb);
2120 g_param_value_set_default (pspec, &pcache->value);
2122 gtk_symbolic_color_unref (color);
2125 return &pcache->value;
2129 /* not supplied by any provider, revert to default */
2130 g_param_value_set_default (pspec, &pcache->value);
2132 return &pcache->value;
2136 * gtk_style_context_get_style_property:
2137 * @context: a #GtkStyleContext
2138 * @property_name: the name of the widget style property
2139 * @value: Return location for the property value
2141 * Gets the value for a widget style property.
2143 * When @value is no longer needed, g_value_unset() must be called
2144 * to free any allocated memory.
2147 gtk_style_context_get_style_property (GtkStyleContext *context,
2148 const gchar *property_name,
2151 GtkStyleContextPrivate *priv;
2152 GtkWidgetClass *widget_class;
2153 GtkStateFlags state;
2155 const GValue *peek_value;
2158 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2159 g_return_if_fail (property_name != NULL);
2160 g_return_if_fail (value != NULL);
2162 priv = context->priv;
2166 widget_type = G_OBJECT_TYPE (priv->widget);
2170 if (!priv->widget_path)
2173 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2175 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2177 g_warning ("%s: can't get style properties for non-widget class `%s'",
2179 g_type_name (widget_type));
2184 widget_class = g_type_class_ref (widget_type);
2185 pspec = gtk_widget_class_find_style_property (widget_class, property_name);
2186 g_type_class_unref (widget_class);
2190 g_warning ("%s: widget class `%s' has no style property named `%s'",
2192 g_type_name (widget_type),
2197 state = gtk_style_context_get_state (context);
2198 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2201 if (G_VALUE_TYPE (value) == G_VALUE_TYPE (peek_value))
2202 g_value_copy (peek_value, value);
2203 else if (g_value_type_transformable (G_VALUE_TYPE (peek_value), G_VALUE_TYPE (value)))
2204 g_value_transform (peek_value, value);
2206 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
2208 G_VALUE_TYPE_NAME (peek_value),
2209 G_VALUE_TYPE_NAME (value));
2213 * gtk_style_context_get_style_valist:
2214 * @context: a #GtkStyleContext
2215 * @args: va_list of property name/return location pairs, followed by %NULL
2217 * Retrieves several widget style properties from @context according to the
2223 gtk_style_context_get_style_valist (GtkStyleContext *context,
2226 GtkStyleContextPrivate *priv;
2227 const gchar *prop_name;
2228 GtkStateFlags state;
2231 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2233 prop_name = va_arg (args, const gchar *);
2234 priv = context->priv;
2238 widget_type = G_OBJECT_TYPE (priv->widget);
2242 if (!priv->widget_path)
2245 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2247 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2249 g_warning ("%s: can't get style properties for non-widget class `%s'",
2251 g_type_name (widget_type));
2256 state = gtk_style_context_get_state (context);
2260 GtkWidgetClass *widget_class;
2262 const GValue *peek_value;
2265 widget_class = g_type_class_ref (widget_type);
2266 pspec = gtk_widget_class_find_style_property (widget_class, prop_name);
2267 g_type_class_unref (widget_class);
2271 g_warning ("%s: widget class `%s' has no style property named `%s'",
2273 g_type_name (widget_type),
2278 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2281 G_VALUE_LCOPY (peek_value, args, 0, &error);
2285 g_warning ("can't retrieve style property `%s' of type `%s': %s",
2287 G_VALUE_TYPE_NAME (peek_value),
2293 prop_name = va_arg (args, const gchar *);
2298 * gtk_style_context_get_style:
2299 * @context: a #GtkStyleContext
2300 * @...: property name /return value pairs, followed by %NULL
2302 * Retrieves several widget style properties from @context according to the
2308 gtk_style_context_get_style (GtkStyleContext *context,
2313 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2315 va_start (args, context);
2316 gtk_style_context_get_style_valist (context, args);
2322 * gtk_style_context_lookup_icon_set:
2323 * @context: a #GtkStyleContext
2324 * @stock_id: an icon name
2326 * Looks up @stock_id in the icon factories associated to @context and
2327 * the default icon factory, returning an icon set if found, otherwise
2330 * Returns: (transfer none): The looked up %GtkIconSet, or %NULL
2333 gtk_style_context_lookup_icon_set (GtkStyleContext *context,
2334 const gchar *stock_id)
2336 GtkStyleContextPrivate *priv;
2338 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2339 g_return_val_if_fail (stock_id != NULL, NULL);
2341 priv = context->priv;
2342 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
2344 return gtk_icon_factory_lookup_default (stock_id);
2348 * gtk_style_context_set_screen:
2349 * @context: a #GtkStyleContext
2350 * @screen: a #GdkScreen
2352 * Attaches @context to the given screen.
2354 * The screen is used to add style information from 'global' style
2355 * providers, such as the screens #GtkSettings instance.
2357 * If you are using a #GtkStyleContext returned from
2358 * gtk_widget_get_style_context(), you do not need to
2359 * call this yourself.
2364 gtk_style_context_set_screen (GtkStyleContext *context,
2367 GtkStyleContextPrivate *priv;
2369 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2370 g_return_if_fail (GDK_IS_SCREEN (screen));
2372 priv = context->priv;
2373 if (priv->screen == screen)
2376 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
2378 g_object_unref (priv->cascade);
2379 priv->cascade = _gtk_style_cascade_get_for_screen (screen);
2380 g_object_ref (priv->cascade);
2384 _gtk_style_cascade_set_parent (priv->cascade, _gtk_style_cascade_get_for_screen (screen));
2387 priv->screen = screen;
2389 g_object_notify (G_OBJECT (context), "screen");
2391 gtk_style_context_invalidate (context);
2395 * gtk_style_context_get_screen:
2396 * @context: a #GtkStyleContext
2398 * Returns the #GdkScreen to which @context is attached.
2400 * Returns: (transfer none): a #GdkScreen.
2403 gtk_style_context_get_screen (GtkStyleContext *context)
2405 GtkStyleContextPrivate *priv;
2407 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2409 priv = context->priv;
2410 return priv->screen;
2414 * gtk_style_context_set_direction:
2415 * @context: a #GtkStyleContext
2416 * @direction: the new direction.
2418 * Sets the reading direction for rendering purposes.
2420 * If you are using a #GtkStyleContext returned from
2421 * gtk_widget_get_style_context(), you do not need to
2422 * call this yourself.
2427 gtk_style_context_set_direction (GtkStyleContext *context,
2428 GtkTextDirection direction)
2430 GtkStyleContextPrivate *priv;
2432 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2434 priv = context->priv;
2435 priv->direction = direction;
2437 g_object_notify (G_OBJECT (context), "direction");
2441 * gtk_style_context_get_direction:
2442 * @context: a #GtkStyleContext
2444 * Returns the widget direction used for rendering.
2446 * Returns: the widget direction
2451 gtk_style_context_get_direction (GtkStyleContext *context)
2453 GtkStyleContextPrivate *priv;
2455 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), GTK_TEXT_DIR_LTR);
2457 priv = context->priv;
2458 return priv->direction;
2462 * gtk_style_context_set_junction_sides:
2463 * @context: a #GtkStyleContext
2464 * @sides: sides where rendered elements are visually connected to
2467 * Sets the sides where rendered elements (mostly through
2468 * gtk_render_frame()) will visually connect with other visual elements.
2470 * This is merely a hint that may or may not be honored
2471 * by theming engines.
2473 * Container widgets are expected to set junction hints as appropriate
2474 * for their children, so it should not normally be necessary to call
2475 * this function manually.
2480 gtk_style_context_set_junction_sides (GtkStyleContext *context,
2481 GtkJunctionSides sides)
2483 GtkStyleContextPrivate *priv;
2486 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2488 priv = context->priv;
2489 info = priv->info_stack->data;
2490 info->junction_sides = sides;
2494 * gtk_style_context_get_junction_sides:
2495 * @context: a #GtkStyleContext
2497 * Returns the sides where rendered elements connect visually with others.
2499 * Returns: the junction sides
2504 gtk_style_context_get_junction_sides (GtkStyleContext *context)
2506 GtkStyleContextPrivate *priv;
2509 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
2511 priv = context->priv;
2512 info = priv->info_stack->data;
2513 return info->junction_sides;
2516 static GtkSymbolicColor *
2517 gtk_style_context_color_lookup_func (gpointer contextp,
2520 GtkStyleContext *context = contextp;
2522 return _gtk_style_provider_private_get_color (GTK_STYLE_PROVIDER_PRIVATE (context->priv->cascade), name);
2526 _gtk_style_context_resolve_color_value (GtkStyleContext *context,
2527 GtkSymbolicColor *color)
2529 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2530 g_return_val_if_fail (color != NULL, FALSE);
2532 return _gtk_symbolic_color_resolve_full (color,
2533 gtk_style_context_color_lookup_func,
2539 _gtk_style_context_resolve_color (GtkStyleContext *context,
2540 GtkSymbolicColor *color,
2545 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2546 g_return_val_if_fail (color != NULL, FALSE);
2547 g_return_val_if_fail (result != NULL, FALSE);
2549 val = _gtk_symbolic_color_resolve_full (color,
2550 gtk_style_context_color_lookup_func,
2555 *result = *_gtk_css_rgba_value_get_rgba (val);
2556 _gtk_css_value_unref (val);
2561 * gtk_style_context_lookup_color:
2562 * @context: a #GtkStyleContext
2563 * @color_name: color name to lookup
2564 * @color: (out): Return location for the looked up color
2566 * Looks up and resolves a color name in the @context color map.
2568 * Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
2571 gtk_style_context_lookup_color (GtkStyleContext *context,
2572 const gchar *color_name,
2575 GtkSymbolicColor *sym_color;
2577 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2578 g_return_val_if_fail (color_name != NULL, FALSE);
2579 g_return_val_if_fail (color != NULL, FALSE);
2581 sym_color = gtk_style_context_color_lookup_func (context, color_name);
2582 if (sym_color == NULL)
2585 return _gtk_style_context_resolve_color (context, sym_color, color);
2589 * gtk_style_context_notify_state_change:
2590 * @context: a #GtkStyleContext
2591 * @window: a #GdkWindow
2592 * @region_id: (allow-none): animatable region to notify on, or %NULL.
2593 * See gtk_style_context_push_animatable_region()
2594 * @state: state to trigger transition for
2595 * @state_value: %TRUE if @state is the state we are changing to,
2596 * %FALSE if we are changing away from it
2598 * Notifies a state change on @context, so if the current style makes use
2599 * of transition animations, one will be started so all rendered elements
2600 * under @region_id are animated for state @state being set to value
2603 * The @window parameter is used in order to invalidate the rendered area
2604 * as the animation runs, so make sure it is the same window that is being
2605 * rendered on by the gtk_render_*() functions.
2607 * If @region_id is %NULL, all rendered elements using @context will be
2608 * affected by this state transition.
2610 * As a practical example, a #GtkButton notifying a state transition on
2611 * the prelight state:
2613 * gtk_style_context_notify_state_change (context,
2614 * gtk_widget_get_window (widget),
2616 * GTK_STATE_PRELIGHT,
2617 * button->in_button);
2620 * Can be handled in the CSS file like this:
2623 * background-color: #f00
2627 * background-color: #fff;
2628 * transition: 200ms linear
2632 * This combination will animate the button background from red to white
2633 * if a pointer enters the button, and back to red if the pointer leaves
2636 * Note that @state is used when finding the transition parameters, which
2637 * is why the style places the transition under the :hover pseudo-class.
2641 * Deprecated: 3.6: This function does nothing.
2644 gtk_style_context_notify_state_change (GtkStyleContext *context,
2648 gboolean state_value)
2650 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2651 g_return_if_fail (GDK_IS_WINDOW (window));
2652 g_return_if_fail (state > GTK_STATE_NORMAL && state <= GTK_STATE_FOCUSED);
2653 g_return_if_fail (context->priv->widget != NULL || context->priv->widget_path != NULL);
2657 * gtk_style_context_cancel_animations:
2658 * @context: a #GtkStyleContext
2659 * @region_id: (allow-none): animatable region to stop, or %NULL.
2660 * See gtk_style_context_push_animatable_region()
2662 * Stops all running animations for @region_id and all animatable
2663 * regions underneath.
2665 * A %NULL @region_id will stop all ongoing animations in @context,
2666 * when dealing with a #GtkStyleContext obtained through
2667 * gtk_widget_get_style_context(), this is normally done for you
2668 * in all circumstances you would expect all widget to be stopped,
2669 * so this should be only used in complex widgets with different
2670 * animatable regions.
2674 * Deprecated: 3.6: This function does nothing.
2677 gtk_style_context_cancel_animations (GtkStyleContext *context,
2680 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2684 * gtk_style_context_scroll_animations:
2685 * @context: a #GtkStyleContext
2686 * @window: a #GdkWindow used previously in
2687 * gtk_style_context_notify_state_change()
2688 * @dx: Amount to scroll in the X axis
2689 * @dy: Amount to scroll in the Y axis
2691 * This function is analogous to gdk_window_scroll(), and
2692 * should be called together with it so the invalidation
2693 * areas for any ongoing animation are scrolled together
2698 * Deprecated: 3.6: This function does nothing.
2701 gtk_style_context_scroll_animations (GtkStyleContext *context,
2706 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2707 g_return_if_fail (GDK_IS_WINDOW (window));
2711 * gtk_style_context_push_animatable_region:
2712 * @context: a #GtkStyleContext
2713 * @region_id: unique identifier for the animatable region
2715 * Pushes an animatable region, so all further gtk_render_*() calls between
2716 * this call and the following gtk_style_context_pop_animatable_region()
2717 * will potentially show transition animations for this region if
2718 * gtk_style_context_notify_state_change() is called for a given state,
2719 * and the current theme/style defines transition animations for state
2722 * The @region_id used must be unique in @context so the theming engine
2723 * can uniquely identify rendered elements subject to a state transition.
2727 * Deprecated: 3.6: This function does nothing.
2730 gtk_style_context_push_animatable_region (GtkStyleContext *context,
2733 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2734 g_return_if_fail (region_id != NULL);
2738 * gtk_style_context_pop_animatable_region:
2739 * @context: a #GtkStyleContext
2741 * Pops an animatable region from @context.
2742 * See gtk_style_context_push_animatable_region().
2746 * Deprecated: 3.6: This function does nothing.
2749 gtk_style_context_pop_animatable_region (GtkStyleContext *context)
2751 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2755 gtk_style_context_do_invalidate (GtkStyleContext *context,
2756 gboolean clear_caches)
2758 GtkStyleContextPrivate *priv;
2760 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2762 priv = context->priv;
2764 /* Avoid reentrancy */
2765 if (priv->invalidating_context)
2768 priv->invalidating_context = TRUE;
2774 for (list = priv->info_stack; list; list = list->next)
2776 GtkStyleInfo *info = list->data;
2779 g_hash_table_remove_all (priv->style_data);
2782 g_signal_emit (context, signals[CHANGED], 0);
2784 priv->invalidating_context = FALSE;
2788 _gtk_style_context_validate (GtkStyleContext *context,
2789 GtkCssChange change)
2791 GtkStyleContextPrivate *priv;
2794 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2796 priv = context->priv;
2798 change |= priv->pending_changes;
2800 if (!priv->invalid && change == 0)
2803 priv->pending_changes = 0;
2804 gtk_style_context_set_invalid (context, FALSE);
2806 /* Try to avoid invalidating if we can */
2807 if (change & GTK_STYLE_CONTEXT_RADICAL_CHANGE)
2809 priv->relevant_changes = GTK_CSS_CHANGE_ANY;
2813 if (priv->relevant_changes == GTK_CSS_CHANGE_ANY)
2815 GtkWidgetPath *path;
2816 GtkCssMatcher matcher;
2818 path = create_query_path (context);
2819 _gtk_css_matcher_init (&matcher, path, ((GtkStyleInfo *) priv->info_stack->data)->state_flags);
2821 priv->relevant_changes = _gtk_style_provider_private_get_change (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
2823 priv->relevant_changes &= ~GTK_STYLE_CONTEXT_RADICAL_CHANGE;
2825 gtk_widget_path_unref (path);
2829 if (priv->relevant_changes & change)
2831 GtkStyleInfo *info = priv->info_stack->data;
2832 gboolean clear_cache = ((priv->relevant_changes & change) & ~GTK_STYLE_CONTEXT_CACHED_CHANGE) != 0;
2835 gtk_style_context_do_invalidate (context, clear_cache);
2838 change = _gtk_css_change_for_child (change);
2839 for (list = priv->children; list; list = list->next)
2841 _gtk_style_context_validate (list->data, change);
2846 _gtk_style_context_queue_invalidate (GtkStyleContext *context,
2847 GtkCssChange change)
2849 GtkStyleContextPrivate *priv;
2851 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2852 g_return_if_fail (change != 0);
2854 priv = context->priv;
2856 if (priv->widget == NULL && priv->widget_path == NULL)
2859 priv->pending_changes |= change;
2860 gtk_style_context_set_invalid (context, TRUE);
2864 * gtk_style_context_invalidate:
2865 * @context: a #GtkStyleContext.
2867 * Invalidates @context style information, so it will be reconstructed
2870 * If you're using a #GtkStyleContext returned from
2871 * gtk_widget_get_style_context(), you do not need to
2872 * call this yourself.
2877 gtk_style_context_invalidate (GtkStyleContext *context)
2879 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2881 gtk_style_context_do_invalidate (context, TRUE);
2885 * gtk_style_context_set_background:
2886 * @context: a #GtkStyleContext
2887 * @window: a #GdkWindow
2889 * Sets the background of @window to the background pattern or
2890 * color specified in @context for its current state.
2895 gtk_style_context_set_background (GtkStyleContext *context,
2898 GtkStateFlags state;
2899 cairo_pattern_t *pattern;
2902 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2903 g_return_if_fail (GDK_IS_WINDOW (window));
2905 state = gtk_style_context_get_state (context);
2906 gtk_style_context_get (context, state,
2907 "background-image", &pattern,
2911 gdk_window_set_background_pattern (window, pattern);
2912 cairo_pattern_destroy (pattern);
2916 gtk_style_context_get (context, state,
2917 "background-color", &color,
2921 gdk_window_set_background_rgba (window, color);
2922 gdk_rgba_free (color);
2927 * gtk_style_context_get_color:
2928 * @context: a #GtkStyleContext
2929 * @state: state to retrieve the color for
2930 * @color: (out): return value for the foreground color
2932 * Gets the foreground color for a given state.
2937 gtk_style_context_get_color (GtkStyleContext *context,
2938 GtkStateFlags state,
2943 g_return_if_fail (color != NULL);
2944 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2946 gtk_style_context_get (context,
2956 * gtk_style_context_get_background_color:
2957 * @context: a #GtkStyleContext
2958 * @state: state to retrieve the color for
2959 * @color: (out): return value for the background color
2961 * Gets the background color for a given state.
2966 gtk_style_context_get_background_color (GtkStyleContext *context,
2967 GtkStateFlags state,
2972 g_return_if_fail (color != NULL);
2973 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2975 gtk_style_context_get (context,
2977 "background-color", &c,
2985 * gtk_style_context_get_border_color:
2986 * @context: a #GtkStyleContext
2987 * @state: state to retrieve the color for
2988 * @color: (out): return value for the border color
2990 * Gets the border color for a given state.
2995 gtk_style_context_get_border_color (GtkStyleContext *context,
2996 GtkStateFlags state,
3001 g_return_if_fail (color != NULL);
3002 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3004 gtk_style_context_get (context,
3014 * gtk_style_context_get_border:
3015 * @context: a #GtkStyleContext
3016 * @state: state to retrieve the border for
3017 * @border: (out): return value for the border settings
3019 * Gets the border for a given state as a #GtkBorder.
3020 * See %GTK_STYLE_PROPERTY_BORDER_WIDTH.
3025 gtk_style_context_get_border (GtkStyleContext *context,
3026 GtkStateFlags state,
3029 int top, left, bottom, right;
3031 g_return_if_fail (border != NULL);
3032 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3034 gtk_style_context_get (context,
3036 "border-top-width", &top,
3037 "border-left-width", &left,
3038 "border-bottom-width", &bottom,
3039 "border-right-width", &right,
3043 border->left = left;
3044 border->bottom = bottom;
3045 border->right = right;
3049 * gtk_style_context_get_padding:
3050 * @context: a #GtkStyleContext
3051 * @state: state to retrieve the padding for
3052 * @padding: (out): return value for the padding settings
3054 * Gets the padding for a given state as a #GtkBorder.
3055 * See %GTK_STYLE_PROPERTY_PADDING.
3060 gtk_style_context_get_padding (GtkStyleContext *context,
3061 GtkStateFlags state,
3064 int top, left, bottom, right;
3066 g_return_if_fail (padding != NULL);
3067 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3069 gtk_style_context_get (context,
3071 "padding-top", &top,
3072 "padding-left", &left,
3073 "padding-bottom", &bottom,
3074 "padding-right", &right,
3078 padding->left = left;
3079 padding->bottom = bottom;
3080 padding->right = right;
3084 * gtk_style_context_get_margin:
3085 * @context: a #GtkStyleContext
3086 * @state: state to retrieve the border for
3087 * @margin: (out): return value for the margin settings
3089 * Gets the margin for a given state as a #GtkBorder.
3090 * See %GTK_STYLE_PROPERTY_MARGIN.
3095 gtk_style_context_get_margin (GtkStyleContext *context,
3096 GtkStateFlags state,
3099 int top, left, bottom, right;
3101 g_return_if_fail (margin != NULL);
3102 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3104 gtk_style_context_get (context,
3107 "margin-left", &left,
3108 "margin-bottom", &bottom,
3109 "margin-right", &right,
3113 margin->left = left;
3114 margin->bottom = bottom;
3115 margin->right = right;
3119 * gtk_style_context_get_font:
3120 * @context: a #GtkStyleContext
3121 * @state: state to retrieve the font for
3123 * Returns the font description for a given state. The returned
3124 * object is const and will remain valid until the
3125 * #GtkStyleContext::changed signal happens.
3127 * Returns: (transfer none): the #PangoFontDescription for the given
3128 * state. This object is owned by GTK+ and should not be
3133 const PangoFontDescription *
3134 gtk_style_context_get_font (GtkStyleContext *context,
3135 GtkStateFlags state)
3137 GtkStyleContextPrivate *priv;
3139 PangoFontDescription *description;
3141 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
3143 priv = context->priv;
3144 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
3146 gtk_style_context_save (context);
3147 gtk_style_context_set_state (context, state);
3148 data = style_data_lookup (context);
3149 gtk_style_context_restore (context);
3151 /* Yuck, fonts are created on-demand but we don't return a ref.
3152 * Do bad things to achieve this requirement */
3153 description = g_object_get_data (G_OBJECT (data->store), "font-cache-for-get_font");
3154 if (description == NULL)
3156 gtk_style_context_get (context, state, "font", &description, NULL);
3157 g_object_set_data_full (G_OBJECT (data->store),
3158 "font-cache-for-get_font",
3160 (GDestroyNotify) pango_font_description_free);
3166 get_cursor_color (GtkStyleContext *context,
3170 GdkColor *style_color;
3172 gtk_style_context_get_style (context,
3173 primary ? "cursor-color" : "secondary-cursor-color",
3179 color->red = style_color->red / 65535.0;
3180 color->green = style_color->green / 65535.0;
3181 color->blue = style_color->blue / 65535.0;
3184 gdk_color_free (style_color);
3188 gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, color);
3194 gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &bg);
3196 color->red = (color->red + bg.red) * 0.5;
3197 color->green = (color->green + bg.green) * 0.5;
3198 color->blue = (color->blue + bg.blue) * 0.5;
3204 _gtk_style_context_get_cursor_color (GtkStyleContext *context,
3205 GdkRGBA *primary_color,
3206 GdkRGBA *secondary_color)
3209 get_cursor_color (context, TRUE, primary_color);
3211 if (secondary_color)
3212 get_cursor_color (context, FALSE, secondary_color);
3219 * @context: a #GtkStyleContext
3221 * @x: X origin of the rectangle
3222 * @y: Y origin of the rectangle
3223 * @width: rectangle width
3224 * @height: rectangle height
3226 * Renders a checkmark (as in a #GtkCheckButton).
3228 * The %GTK_STATE_FLAG_ACTIVE state determines whether the check is
3229 * on or off, and %GTK_STATE_FLAG_INCONSISTENT determines whether it
3230 * should be marked as undefined.
3233 * <title>Typical checkmark rendering</title>
3234 * <inlinegraphic fileref="checks.png" format="PNG"/>
3240 gtk_render_check (GtkStyleContext *context,
3247 GtkStyleContextPrivate *priv;
3248 GtkThemingEngineClass *engine_class;
3250 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3251 g_return_if_fail (cr != NULL);
3253 if (width <= 0 || height <= 0)
3256 priv = context->priv;
3257 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3262 _gtk_theming_engine_set_context (priv->theming_engine, context);
3263 engine_class->render_check (priv->theming_engine, cr,
3264 x, y, width, height);
3270 * gtk_render_option:
3271 * @context: a #GtkStyleContext
3273 * @x: X origin of the rectangle
3274 * @y: Y origin of the rectangle
3275 * @width: rectangle width
3276 * @height: rectangle height
3278 * Renders an option mark (as in a #GtkRadioButton), the %GTK_STATE_FLAG_ACTIVE
3279 * state will determine whether the option is on or off, and
3280 * %GTK_STATE_FLAG_INCONSISTENT whether it should be marked as undefined.
3283 * <title>Typical option mark rendering</title>
3284 * <inlinegraphic fileref="options.png" format="PNG"/>
3290 gtk_render_option (GtkStyleContext *context,
3297 GtkStyleContextPrivate *priv;
3298 GtkThemingEngineClass *engine_class;
3300 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3301 g_return_if_fail (cr != NULL);
3303 if (width <= 0 || height <= 0)
3306 priv = context->priv;
3307 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3311 _gtk_theming_engine_set_context (priv->theming_engine, context);
3312 engine_class->render_option (priv->theming_engine, cr,
3313 x, y, width, height);
3320 * @context: a #GtkStyleContext
3322 * @angle: arrow angle from 0 to 2 * %G_PI, being 0 the arrow pointing to the north
3323 * @x: X origin of the render area
3324 * @y: Y origin of the render area
3325 * @size: square side for render area
3327 * Renders an arrow pointing to @angle.
3330 * <title>Typical arrow rendering at 0, 1&solidus;2 π, π and 3&solidus;2 π</title>
3331 * <inlinegraphic fileref="arrows.png" format="PNG"/>
3337 gtk_render_arrow (GtkStyleContext *context,
3344 GtkStyleContextPrivate *priv;
3345 GtkThemingEngineClass *engine_class;
3347 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3348 g_return_if_fail (cr != NULL);
3353 priv = context->priv;
3354 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3358 gtk_style_context_save (context);
3359 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ARROW);
3361 _gtk_theming_engine_set_context (priv->theming_engine, context);
3362 engine_class->render_arrow (priv->theming_engine, cr,
3365 gtk_style_context_restore (context);
3370 * gtk_render_background:
3371 * @context: a #GtkStyleContext
3373 * @x: X origin of the rectangle
3374 * @y: Y origin of the rectangle
3375 * @width: rectangle width
3376 * @height: rectangle height
3378 * Renders the background of an element.
3381 * <title>Typical background rendering, showing the effect of
3382 * <parameter>background-image</parameter>,
3383 * <parameter>border-width</parameter> and
3384 * <parameter>border-radius</parameter></title>
3385 * <inlinegraphic fileref="background.png" format="PNG"/>
3391 gtk_render_background (GtkStyleContext *context,
3398 GtkStyleContextPrivate *priv;
3399 GtkThemingEngineClass *engine_class;
3401 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3402 g_return_if_fail (cr != NULL);
3404 if (width <= 0 || height <= 0)
3407 priv = context->priv;
3408 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3412 _gtk_theming_engine_set_context (priv->theming_engine, context);
3413 engine_class->render_background (priv->theming_engine, cr, x, y, width, height);
3420 * @context: a #GtkStyleContext
3422 * @x: X origin of the rectangle
3423 * @y: Y origin of the rectangle
3424 * @width: rectangle width
3425 * @height: rectangle height
3427 * Renders a frame around the rectangle defined by @x, @y, @width, @height.
3430 * <title>Examples of frame rendering, showing the effect of
3431 * <parameter>border-image</parameter>,
3432 * <parameter>border-color</parameter>,
3433 * <parameter>border-width</parameter>,
3434 * <parameter>border-radius</parameter> and
3436 * <inlinegraphic fileref="frames.png" format="PNG"/>
3442 gtk_render_frame (GtkStyleContext *context,
3449 GtkStyleContextPrivate *priv;
3450 GtkThemingEngineClass *engine_class;
3452 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3453 g_return_if_fail (cr != NULL);
3455 if (width <= 0 || height <= 0)
3458 priv = context->priv;
3459 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3463 _gtk_theming_engine_set_context (priv->theming_engine, context);
3464 engine_class->render_frame (priv->theming_engine, cr, x, y, width, height);
3470 * gtk_render_expander:
3471 * @context: a #GtkStyleContext
3473 * @x: X origin of the rectangle
3474 * @y: Y origin of the rectangle
3475 * @width: rectangle width
3476 * @height: rectangle height
3478 * Renders an expander (as used in #GtkTreeView and #GtkExpander) in the area
3479 * defined by @x, @y, @width, @height. The state %GTK_STATE_FLAG_ACTIVE
3480 * determines whether the expander is collapsed or expanded.
3483 * <title>Typical expander rendering</title>
3484 * <inlinegraphic fileref="expanders.png" format="PNG"/>
3490 gtk_render_expander (GtkStyleContext *context,
3497 GtkStyleContextPrivate *priv;
3498 GtkThemingEngineClass *engine_class;
3500 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3501 g_return_if_fail (cr != NULL);
3503 if (width <= 0 || height <= 0)
3506 priv = context->priv;
3507 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3511 _gtk_theming_engine_set_context (priv->theming_engine, context);
3512 engine_class->render_expander (priv->theming_engine, cr, x, y, width, height);
3519 * @context: a #GtkStyleContext
3521 * @x: X origin of the rectangle
3522 * @y: Y origin of the rectangle
3523 * @width: rectangle width
3524 * @height: rectangle height
3526 * Renders a focus indicator on the rectangle determined by @x, @y, @width, @height.
3528 * <title>Typical focus rendering</title>
3529 * <inlinegraphic fileref="focus.png" format="PNG"/>
3535 gtk_render_focus (GtkStyleContext *context,
3542 GtkStyleContextPrivate *priv;
3543 GtkThemingEngineClass *engine_class;
3545 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3546 g_return_if_fail (cr != NULL);
3548 if (width <= 0 || height <= 0)
3551 priv = context->priv;
3552 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3556 _gtk_theming_engine_set_context (priv->theming_engine, context);
3557 engine_class->render_focus (priv->theming_engine, cr, x, y, width, height);
3563 * gtk_render_layout:
3564 * @context: a #GtkStyleContext
3568 * @layout: the #PangoLayout to render
3570 * Renders @layout on the coordinates @x, @y
3575 gtk_render_layout (GtkStyleContext *context,
3579 PangoLayout *layout)
3581 GtkStyleContextPrivate *priv;
3582 GtkThemingEngineClass *engine_class;
3583 PangoRectangle extents;
3585 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3586 g_return_if_fail (PANGO_IS_LAYOUT (layout));
3587 g_return_if_fail (cr != NULL);
3589 priv = context->priv;
3590 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3594 pango_layout_get_extents (layout, &extents, NULL);
3596 _gtk_theming_engine_set_context (priv->theming_engine, context);
3597 engine_class->render_layout (priv->theming_engine, cr, x, y, layout);
3604 * @context: a #GtkStyleContext
3606 * @x0: X coordinate for the origin of the line
3607 * @y0: Y coordinate for the origin of the line
3608 * @x1: X coordinate for the end of the line
3609 * @y1: Y coordinate for the end of the line
3611 * Renders a line from (x0, y0) to (x1, y1).
3616 gtk_render_line (GtkStyleContext *context,
3623 GtkStyleContextPrivate *priv;
3624 GtkThemingEngineClass *engine_class;
3626 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3627 g_return_if_fail (cr != NULL);
3629 priv = context->priv;
3630 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3634 _gtk_theming_engine_set_context (priv->theming_engine, context);
3635 engine_class->render_line (priv->theming_engine, cr, x0, y0, x1, y1);
3641 * gtk_render_slider:
3642 * @context: a #GtkStyleContext
3644 * @x: X origin of the rectangle
3645 * @y: Y origin of the rectangle
3646 * @width: rectangle width
3647 * @height: rectangle height
3648 * @orientation: orientation of the slider
3650 * Renders a slider (as in #GtkScale) in the rectangle defined by @x, @y,
3651 * @width, @height. @orientation defines whether the slider is vertical
3655 * <title>Typical slider rendering</title>
3656 * <inlinegraphic fileref="sliders.png" format="PNG"/>
3662 gtk_render_slider (GtkStyleContext *context,
3668 GtkOrientation orientation)
3670 GtkStyleContextPrivate *priv;
3671 GtkThemingEngineClass *engine_class;
3673 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3674 g_return_if_fail (cr != NULL);
3676 if (width <= 0 || height <= 0)
3679 priv = context->priv;
3680 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3684 _gtk_theming_engine_set_context (priv->theming_engine, context);
3685 engine_class->render_slider (priv->theming_engine, cr, x, y, width, height, orientation);
3691 * gtk_render_frame_gap:
3692 * @context: a #GtkStyleContext
3694 * @x: X origin of the rectangle
3695 * @y: Y origin of the rectangle
3696 * @width: rectangle width
3697 * @height: rectangle height
3698 * @gap_side: side where the gap is
3699 * @xy0_gap: initial coordinate (X or Y depending on @gap_side) for the gap
3700 * @xy1_gap: end coordinate (X or Y depending on @gap_side) for the gap
3702 * Renders a frame around the rectangle defined by (@x, @y, @width, @height),
3703 * leaving a gap on one side. @xy0_gap and @xy1_gap will mean X coordinates
3704 * for %GTK_POS_TOP and %GTK_POS_BOTTOM gap sides, and Y coordinates for
3705 * %GTK_POS_LEFT and %GTK_POS_RIGHT.
3708 * <title>Typical rendering of a frame with a gap</title>
3709 * <inlinegraphic fileref="frame-gap.png" format="PNG"/>
3715 gtk_render_frame_gap (GtkStyleContext *context,
3721 GtkPositionType gap_side,
3725 GtkStyleContextPrivate *priv;
3726 GtkThemingEngineClass *engine_class;
3728 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3729 g_return_if_fail (cr != NULL);
3730 g_return_if_fail (xy0_gap <= xy1_gap);
3731 g_return_if_fail (xy0_gap >= 0);
3733 if (width <= 0 || height <= 0)
3736 if (gap_side == GTK_POS_LEFT ||
3737 gap_side == GTK_POS_RIGHT)
3738 g_return_if_fail (xy1_gap <= height);
3740 g_return_if_fail (xy1_gap <= width);
3742 priv = context->priv;
3743 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3747 _gtk_theming_engine_set_context (priv->theming_engine, context);
3748 engine_class->render_frame_gap (priv->theming_engine, cr,
3749 x, y, width, height, gap_side,
3756 * gtk_render_extension:
3757 * @context: a #GtkStyleContext
3759 * @x: X origin of the rectangle
3760 * @y: Y origin of the rectangle
3761 * @width: rectangle width
3762 * @height: rectangle height
3763 * @gap_side: side where the gap is
3765 * Renders a extension (as in a #GtkNotebook tab) in the rectangle
3766 * defined by @x, @y, @width, @height. The side where the extension
3767 * connects to is defined by @gap_side.
3770 * <title>Typical extension rendering</title>
3771 * <inlinegraphic fileref="extensions.png" format="PNG"/>
3777 gtk_render_extension (GtkStyleContext *context,
3783 GtkPositionType gap_side)
3785 GtkStyleContextPrivate *priv;
3786 GtkThemingEngineClass *engine_class;
3788 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3789 g_return_if_fail (cr != NULL);
3791 if (width <= 0 || height <= 0)
3794 priv = context->priv;
3795 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3799 _gtk_theming_engine_set_context (priv->theming_engine, context);
3800 engine_class->render_extension (priv->theming_engine, cr, x, y, width, height, gap_side);
3806 * gtk_render_handle:
3807 * @context: a #GtkStyleContext
3809 * @x: X origin of the rectangle
3810 * @y: Y origin of the rectangle
3811 * @width: rectangle width
3812 * @height: rectangle height
3814 * Renders a handle (as in #GtkHandleBox, #GtkPaned and
3815 * #GtkWindow<!-- -->'s resize grip), in the rectangle
3816 * determined by @x, @y, @width, @height.
3819 * <title>Handles rendered for the paned and grip classes</title>
3820 * <inlinegraphic fileref="handles.png" format="PNG"/>
3826 gtk_render_handle (GtkStyleContext *context,
3833 GtkStyleContextPrivate *priv;
3834 GtkThemingEngineClass *engine_class;
3836 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3837 g_return_if_fail (cr != NULL);
3839 if (width <= 0 || height <= 0)
3842 priv = context->priv;
3843 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3847 _gtk_theming_engine_set_context (priv->theming_engine, context);
3848 engine_class->render_handle (priv->theming_engine, cr, x, y, width, height);
3854 * gtk_render_activity:
3855 * @context: a #GtkStyleContext
3857 * @x: X origin of the rectangle
3858 * @y: Y origin of the rectangle
3859 * @width: rectangle width
3860 * @height: rectangle height
3862 * Renders an activity area (Such as in #GtkSpinner or the
3863 * fill line in #GtkRange), the state %GTK_STATE_FLAG_ACTIVE
3864 * determines whether there is activity going on.
3869 gtk_render_activity (GtkStyleContext *context,
3876 GtkStyleContextPrivate *priv;
3877 GtkThemingEngineClass *engine_class;
3879 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3880 g_return_if_fail (cr != NULL);
3882 if (width <= 0 || height <= 0)
3885 priv = context->priv;
3886 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3890 _gtk_theming_engine_set_context (priv->theming_engine, context);
3891 engine_class->render_activity (priv->theming_engine, cr, x, y, width, height);
3897 * gtk_render_icon_pixbuf:
3898 * @context: a #GtkStyleContext
3899 * @source: the #GtkIconSource specifying the icon to render
3900 * @size: (type int): the size to render the icon at. A size of (GtkIconSize) -1
3901 * means render at the size of the source and don't scale.
3903 * Renders the icon specified by @source at the given @size, returning the result
3906 * Returns: (transfer full): a newly-created #GdkPixbuf containing the rendered icon
3911 gtk_render_icon_pixbuf (GtkStyleContext *context,
3912 const GtkIconSource *source,
3915 GtkStyleContextPrivate *priv;
3916 GtkThemingEngineClass *engine_class;
3918 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
3919 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
3920 g_return_val_if_fail (source != NULL, NULL);
3922 priv = context->priv;
3923 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3925 _gtk_theming_engine_set_context (priv->theming_engine, context);
3926 return engine_class->render_icon_pixbuf (priv->theming_engine, source, size);
3931 * @context: a #GtkStyleContext
3933 * @pixbuf: a #GdkPixbuf containing the icon to draw
3934 * @x: X position for the @pixbuf
3935 * @y: Y position for the @pixbuf
3937 * Renders the icon in @pixbuf at the specified @x and @y coordinates.
3942 gtk_render_icon (GtkStyleContext *context,
3948 GtkStyleContextPrivate *priv;
3949 GtkThemingEngineClass *engine_class;
3951 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3952 g_return_if_fail (cr != NULL);
3954 priv = context->priv;
3955 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3959 _gtk_theming_engine_set_context (priv->theming_engine, context);
3960 engine_class->render_icon (priv->theming_engine, cr, pixbuf, x, y);
3966 draw_insertion_cursor (GtkStyleContext *context,
3971 gboolean is_primary,
3972 PangoDirection direction,
3973 gboolean draw_arrow)
3976 GdkRGBA primary_color;
3977 GdkRGBA secondary_color;
3978 gfloat cursor_aspect_ratio;
3984 _gtk_style_context_get_cursor_color (context, &primary_color, &secondary_color);
3985 gdk_cairo_set_source_rgba (cr, is_primary ? &primary_color : &secondary_color);
3987 /* When changing the shape or size of the cursor here,
3988 * propagate the changes to gtktextview.c:text_window_invalidate_cursors().
3991 gtk_style_context_get_style (context,
3992 "cursor-aspect-ratio", &cursor_aspect_ratio,
3995 stem_width = height * cursor_aspect_ratio + 1;
3997 /* put (stem_width % 2) on the proper side of the cursor */
3998 if (direction == PANGO_DIRECTION_LTR)
3999 offset = stem_width / 2;
4001 offset = stem_width - stem_width / 2;
4003 cairo_rectangle (cr, x - offset, y, stem_width, height);
4011 arrow_width = stem_width + 1;
4013 if (direction == PANGO_DIRECTION_RTL)
4015 ax = x - offset - 1;
4016 ay = y + height - arrow_width * 2 - arrow_width + 1;
4018 cairo_move_to (cr, ax, ay + 1);
4019 cairo_line_to (cr, ax - arrow_width, ay + arrow_width);
4020 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4023 else if (direction == PANGO_DIRECTION_LTR)
4025 ax = x + stem_width - offset;
4026 ay = y + height - arrow_width * 2 - arrow_width + 1;
4028 cairo_move_to (cr, ax, ay + 1);
4029 cairo_line_to (cr, ax + arrow_width, ay + arrow_width);
4030 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4034 g_assert_not_reached();
4041 * gtk_render_insertion_cursor:
4042 * @context: a #GtkStyleContext
4046 * @layout: the #PangoLayout of the text
4047 * @index: the index in the #PangoLayout
4048 * @direction: the #PangoDirection of the text
4050 * Draws a text caret on @cr at the specified index of @layout.
4055 gtk_render_insertion_cursor (GtkStyleContext *context,
4059 PangoLayout *layout,
4061 PangoDirection direction)
4063 GtkStyleContextPrivate *priv;
4064 gboolean split_cursor;
4065 PangoRectangle strong_pos, weak_pos;
4066 PangoRectangle *cursor1, *cursor2;
4067 PangoDirection keymap_direction;
4068 PangoDirection direction2;
4070 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4071 g_return_if_fail (cr != NULL);
4072 g_return_if_fail (PANGO_IS_LAYOUT (layout));
4073 g_return_if_fail (index >= 0);
4075 priv = context->priv;
4077 g_object_get (gtk_settings_get_for_screen (priv->screen),
4078 "gtk-split-cursor", &split_cursor,
4081 keymap_direction = gdk_keymap_get_direction (gdk_keymap_get_for_display (gdk_screen_get_display (priv->screen)));
4083 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4085 direction2 = PANGO_DIRECTION_NEUTRAL;
4089 cursor1 = &strong_pos;
4091 if (strong_pos.x != weak_pos.x || strong_pos.y != weak_pos.y)
4093 direction2 = (direction == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
4094 cursor2 = &weak_pos;
4099 if (keymap_direction == direction)
4100 cursor1 = &strong_pos;
4102 cursor1 = &weak_pos;
4105 draw_insertion_cursor (context,
4107 x + PANGO_PIXELS (cursor1->x),
4108 y + PANGO_PIXELS (cursor1->y),
4109 PANGO_PIXELS (cursor1->height),
4112 direction2 != PANGO_DIRECTION_NEUTRAL);
4114 if (direction2 != PANGO_DIRECTION_NEUTRAL)
4116 draw_insertion_cursor (context,
4118 x + PANGO_PIXELS (cursor2->x),
4119 y + PANGO_PIXELS (cursor2->y),
4120 PANGO_PIXELS (cursor2->height),
4128 * gtk_draw_insertion_cursor:
4129 * @widget: a #GtkWidget
4130 * @cr: cairo context to draw to
4131 * @location: location where to draw the cursor (@location->width is ignored)
4132 * @is_primary: if the cursor should be the primary cursor color.
4133 * @direction: whether the cursor is left-to-right or
4134 * right-to-left. Should never be #GTK_TEXT_DIR_NONE
4135 * @draw_arrow: %TRUE to draw a directional arrow on the
4136 * cursor. Should be %FALSE unless the cursor is split.
4138 * Draws a text caret on @cr at @location. This is not a style function
4139 * but merely a convenience function for drawing the standard cursor shape.
4142 * Deprecated: 3.4: Use gtk_render_insertion_cursor() instead.
4145 gtk_draw_insertion_cursor (GtkWidget *widget,
4147 const GdkRectangle *location,
4148 gboolean is_primary,
4149 GtkTextDirection direction,
4150 gboolean draw_arrow)
4152 GtkStyleContext *context;
4154 g_return_if_fail (GTK_IS_WIDGET (widget));
4155 g_return_if_fail (cr != NULL);
4156 g_return_if_fail (location != NULL);
4157 g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
4159 context = gtk_widget_get_style_context (widget);
4161 draw_insertion_cursor (context, cr,
4162 location->x, location->y, location->height,
4164 (direction == GTK_TEXT_DIR_RTL) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR,
4168 static AtkAttributeSet *
4169 add_attribute (AtkAttributeSet *attributes,
4170 AtkTextAttribute attr,
4175 at = g_new (AtkAttribute, 1);
4176 at->name = g_strdup (atk_text_attribute_get_name (attr));
4177 at->value = g_strdup (value);
4179 return g_slist_prepend (attributes, at);
4183 * _gtk_style_context_get_attributes:
4184 * @attributes: a #AtkAttributeSet to add attributes to
4185 * @context: the #GtkStyleContext to get attributes from
4186 * @flags: the state to use with @context
4188 * Adds the foreground and background color from @context to
4189 * @attributes, after translating them to ATK attributes.
4191 * This is a convenience function that can be used in
4192 * implementing the #AtkText interface in widgets.
4194 * Returns: the modified #AtkAttributeSet
4197 _gtk_style_context_get_attributes (AtkAttributeSet *attributes,
4198 GtkStyleContext *context,
4199 GtkStateFlags flags)
4204 gtk_style_context_get_background_color (context, flags, &color);
4205 value = g_strdup_printf ("%u,%u,%u",
4206 (guint) ceil (color.red * 65536 - color.red),
4207 (guint) ceil (color.green * 65536 - color.green),
4208 (guint) ceil (color.blue * 65536 - color.blue));
4209 attributes = add_attribute (attributes, ATK_TEXT_ATTR_BG_COLOR, value);
4212 gtk_style_context_get_color (context, flags, &color);
4213 value = g_strdup_printf ("%u,%u,%u",
4214 (guint) ceil (color.red * 65536 - color.red),
4215 (guint) ceil (color.green * 65536 - color.green),
4216 (guint) ceil (color.blue * 65536 - color.blue));
4217 attributes = add_attribute (attributes, ATK_TEXT_ATTR_FG_COLOR, value);