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 GtkCssValue *current,
2530 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2531 g_return_val_if_fail (current != NULL, FALSE);
2532 g_return_val_if_fail (color != NULL, FALSE);
2534 return _gtk_symbolic_color_resolve_full ((GtkSymbolicColor *) color,
2536 gtk_style_context_color_lookup_func,
2542 _gtk_style_context_resolve_color (GtkStyleContext *context,
2543 GtkSymbolicColor *color,
2548 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2549 g_return_val_if_fail (color != NULL, FALSE);
2550 g_return_val_if_fail (result != NULL, FALSE);
2552 val = _gtk_symbolic_color_resolve_full (color,
2553 _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR),
2554 gtk_style_context_color_lookup_func,
2559 *result = *_gtk_css_rgba_value_get_rgba (val);
2560 _gtk_css_value_unref (val);
2565 * gtk_style_context_lookup_color:
2566 * @context: a #GtkStyleContext
2567 * @color_name: color name to lookup
2568 * @color: (out): Return location for the looked up color
2570 * Looks up and resolves a color name in the @context color map.
2572 * Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
2575 gtk_style_context_lookup_color (GtkStyleContext *context,
2576 const gchar *color_name,
2579 GtkSymbolicColor *sym_color;
2581 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2582 g_return_val_if_fail (color_name != NULL, FALSE);
2583 g_return_val_if_fail (color != NULL, FALSE);
2585 sym_color = gtk_style_context_color_lookup_func (context, color_name);
2586 if (sym_color == NULL)
2589 return _gtk_style_context_resolve_color (context, sym_color, color);
2593 * gtk_style_context_notify_state_change:
2594 * @context: a #GtkStyleContext
2595 * @window: a #GdkWindow
2596 * @region_id: (allow-none): animatable region to notify on, or %NULL.
2597 * See gtk_style_context_push_animatable_region()
2598 * @state: state to trigger transition for
2599 * @state_value: %TRUE if @state is the state we are changing to,
2600 * %FALSE if we are changing away from it
2602 * Notifies a state change on @context, so if the current style makes use
2603 * of transition animations, one will be started so all rendered elements
2604 * under @region_id are animated for state @state being set to value
2607 * The @window parameter is used in order to invalidate the rendered area
2608 * as the animation runs, so make sure it is the same window that is being
2609 * rendered on by the gtk_render_*() functions.
2611 * If @region_id is %NULL, all rendered elements using @context will be
2612 * affected by this state transition.
2614 * As a practical example, a #GtkButton notifying a state transition on
2615 * the prelight state:
2617 * gtk_style_context_notify_state_change (context,
2618 * gtk_widget_get_window (widget),
2620 * GTK_STATE_PRELIGHT,
2621 * button->in_button);
2624 * Can be handled in the CSS file like this:
2627 * background-color: #f00
2631 * background-color: #fff;
2632 * transition: 200ms linear
2636 * This combination will animate the button background from red to white
2637 * if a pointer enters the button, and back to red if the pointer leaves
2640 * Note that @state is used when finding the transition parameters, which
2641 * is why the style places the transition under the :hover pseudo-class.
2645 * Deprecated: 3.6: This function does nothing.
2648 gtk_style_context_notify_state_change (GtkStyleContext *context,
2652 gboolean state_value)
2654 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2655 g_return_if_fail (GDK_IS_WINDOW (window));
2656 g_return_if_fail (state > GTK_STATE_NORMAL && state <= GTK_STATE_FOCUSED);
2657 g_return_if_fail (context->priv->widget != NULL || context->priv->widget_path != NULL);
2661 * gtk_style_context_cancel_animations:
2662 * @context: a #GtkStyleContext
2663 * @region_id: (allow-none): animatable region to stop, or %NULL.
2664 * See gtk_style_context_push_animatable_region()
2666 * Stops all running animations for @region_id and all animatable
2667 * regions underneath.
2669 * A %NULL @region_id will stop all ongoing animations in @context,
2670 * when dealing with a #GtkStyleContext obtained through
2671 * gtk_widget_get_style_context(), this is normally done for you
2672 * in all circumstances you would expect all widget to be stopped,
2673 * so this should be only used in complex widgets with different
2674 * animatable regions.
2678 * Deprecated: 3.6: This function does nothing.
2681 gtk_style_context_cancel_animations (GtkStyleContext *context,
2684 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2688 * gtk_style_context_scroll_animations:
2689 * @context: a #GtkStyleContext
2690 * @window: a #GdkWindow used previously in
2691 * gtk_style_context_notify_state_change()
2692 * @dx: Amount to scroll in the X axis
2693 * @dy: Amount to scroll in the Y axis
2695 * This function is analogous to gdk_window_scroll(), and
2696 * should be called together with it so the invalidation
2697 * areas for any ongoing animation are scrolled together
2702 * Deprecated: 3.6: This function does nothing.
2705 gtk_style_context_scroll_animations (GtkStyleContext *context,
2710 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2711 g_return_if_fail (GDK_IS_WINDOW (window));
2715 * gtk_style_context_push_animatable_region:
2716 * @context: a #GtkStyleContext
2717 * @region_id: unique identifier for the animatable region
2719 * Pushes an animatable region, so all further gtk_render_*() calls between
2720 * this call and the following gtk_style_context_pop_animatable_region()
2721 * will potentially show transition animations for this region if
2722 * gtk_style_context_notify_state_change() is called for a given state,
2723 * and the current theme/style defines transition animations for state
2726 * The @region_id used must be unique in @context so the theming engine
2727 * can uniquely identify rendered elements subject to a state transition.
2731 * Deprecated: 3.6: This function does nothing.
2734 gtk_style_context_push_animatable_region (GtkStyleContext *context,
2737 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2738 g_return_if_fail (region_id != NULL);
2742 * gtk_style_context_pop_animatable_region:
2743 * @context: a #GtkStyleContext
2745 * Pops an animatable region from @context.
2746 * See gtk_style_context_push_animatable_region().
2750 * Deprecated: 3.6: This function does nothing.
2753 gtk_style_context_pop_animatable_region (GtkStyleContext *context)
2755 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2759 gtk_style_context_clear_cache (GtkStyleContext *context)
2761 GtkStyleContextPrivate *priv;
2764 priv = context->priv;
2766 for (list = priv->info_stack; list; list = list->next)
2768 GtkStyleInfo *info = list->data;
2771 g_hash_table_remove_all (priv->style_data);
2775 gtk_style_context_do_invalidate (GtkStyleContext *context)
2777 GtkStyleContextPrivate *priv;
2779 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2781 priv = context->priv;
2783 /* Avoid reentrancy */
2784 if (priv->invalidating_context)
2787 priv->invalidating_context = TRUE;
2789 g_signal_emit (context, signals[CHANGED], 0);
2791 priv->invalidating_context = FALSE;
2795 _gtk_style_context_validate (GtkStyleContext *context,
2796 GtkCssChange change)
2798 GtkStyleContextPrivate *priv;
2801 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2803 priv = context->priv;
2805 change |= priv->pending_changes;
2807 if (!priv->invalid && change == 0)
2810 priv->pending_changes = 0;
2811 gtk_style_context_set_invalid (context, FALSE);
2813 /* Try to avoid invalidating if we can */
2814 if (change & GTK_STYLE_CONTEXT_RADICAL_CHANGE)
2816 priv->relevant_changes = GTK_CSS_CHANGE_ANY;
2820 if (priv->relevant_changes == GTK_CSS_CHANGE_ANY)
2822 GtkWidgetPath *path;
2823 GtkCssMatcher matcher;
2825 path = create_query_path (context);
2826 _gtk_css_matcher_init (&matcher, path, ((GtkStyleInfo *) priv->info_stack->data)->state_flags);
2828 priv->relevant_changes = _gtk_style_provider_private_get_change (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
2830 priv->relevant_changes &= ~GTK_STYLE_CONTEXT_RADICAL_CHANGE;
2832 gtk_widget_path_unref (path);
2836 if (priv->relevant_changes & change)
2838 GtkStyleInfo *info = priv->info_stack->data;
2840 if ((priv->relevant_changes & change) & ~GTK_STYLE_CONTEXT_CACHED_CHANGE)
2841 gtk_style_context_clear_cache (context);
2844 gtk_style_context_do_invalidate (context);
2847 change = _gtk_css_change_for_child (change);
2848 for (list = priv->children; list; list = list->next)
2850 _gtk_style_context_validate (list->data, change);
2855 _gtk_style_context_queue_invalidate (GtkStyleContext *context,
2856 GtkCssChange change)
2858 GtkStyleContextPrivate *priv;
2860 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2861 g_return_if_fail (change != 0);
2863 priv = context->priv;
2865 if (priv->widget == NULL && priv->widget_path == NULL)
2868 priv->pending_changes |= change;
2869 gtk_style_context_set_invalid (context, TRUE);
2873 * gtk_style_context_invalidate:
2874 * @context: a #GtkStyleContext.
2876 * Invalidates @context style information, so it will be reconstructed
2879 * If you're using a #GtkStyleContext returned from
2880 * gtk_widget_get_style_context(), you do not need to
2881 * call this yourself.
2886 gtk_style_context_invalidate (GtkStyleContext *context)
2888 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2890 gtk_style_context_clear_cache (context);
2891 gtk_style_context_do_invalidate (context);
2895 * gtk_style_context_set_background:
2896 * @context: a #GtkStyleContext
2897 * @window: a #GdkWindow
2899 * Sets the background of @window to the background pattern or
2900 * color specified in @context for its current state.
2905 gtk_style_context_set_background (GtkStyleContext *context,
2908 GtkStateFlags state;
2909 cairo_pattern_t *pattern;
2912 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2913 g_return_if_fail (GDK_IS_WINDOW (window));
2915 state = gtk_style_context_get_state (context);
2916 gtk_style_context_get (context, state,
2917 "background-image", &pattern,
2921 gdk_window_set_background_pattern (window, pattern);
2922 cairo_pattern_destroy (pattern);
2926 gtk_style_context_get (context, state,
2927 "background-color", &color,
2931 gdk_window_set_background_rgba (window, color);
2932 gdk_rgba_free (color);
2937 * gtk_style_context_get_color:
2938 * @context: a #GtkStyleContext
2939 * @state: state to retrieve the color for
2940 * @color: (out): return value for the foreground color
2942 * Gets the foreground color for a given state.
2947 gtk_style_context_get_color (GtkStyleContext *context,
2948 GtkStateFlags state,
2953 g_return_if_fail (color != NULL);
2954 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2956 gtk_style_context_get (context,
2966 * gtk_style_context_get_background_color:
2967 * @context: a #GtkStyleContext
2968 * @state: state to retrieve the color for
2969 * @color: (out): return value for the background color
2971 * Gets the background color for a given state.
2976 gtk_style_context_get_background_color (GtkStyleContext *context,
2977 GtkStateFlags state,
2982 g_return_if_fail (color != NULL);
2983 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2985 gtk_style_context_get (context,
2987 "background-color", &c,
2995 * gtk_style_context_get_border_color:
2996 * @context: a #GtkStyleContext
2997 * @state: state to retrieve the color for
2998 * @color: (out): return value for the border color
3000 * Gets the border color for a given state.
3005 gtk_style_context_get_border_color (GtkStyleContext *context,
3006 GtkStateFlags state,
3011 g_return_if_fail (color != NULL);
3012 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3014 gtk_style_context_get (context,
3024 * gtk_style_context_get_border:
3025 * @context: a #GtkStyleContext
3026 * @state: state to retrieve the border for
3027 * @border: (out): return value for the border settings
3029 * Gets the border for a given state as a #GtkBorder.
3030 * See %GTK_STYLE_PROPERTY_BORDER_WIDTH.
3035 gtk_style_context_get_border (GtkStyleContext *context,
3036 GtkStateFlags state,
3039 int top, left, bottom, right;
3041 g_return_if_fail (border != NULL);
3042 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3044 gtk_style_context_get (context,
3046 "border-top-width", &top,
3047 "border-left-width", &left,
3048 "border-bottom-width", &bottom,
3049 "border-right-width", &right,
3053 border->left = left;
3054 border->bottom = bottom;
3055 border->right = right;
3059 * gtk_style_context_get_padding:
3060 * @context: a #GtkStyleContext
3061 * @state: state to retrieve the padding for
3062 * @padding: (out): return value for the padding settings
3064 * Gets the padding for a given state as a #GtkBorder.
3065 * See %GTK_STYLE_PROPERTY_PADDING.
3070 gtk_style_context_get_padding (GtkStyleContext *context,
3071 GtkStateFlags state,
3074 int top, left, bottom, right;
3076 g_return_if_fail (padding != NULL);
3077 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3079 gtk_style_context_get (context,
3081 "padding-top", &top,
3082 "padding-left", &left,
3083 "padding-bottom", &bottom,
3084 "padding-right", &right,
3088 padding->left = left;
3089 padding->bottom = bottom;
3090 padding->right = right;
3094 * gtk_style_context_get_margin:
3095 * @context: a #GtkStyleContext
3096 * @state: state to retrieve the border for
3097 * @margin: (out): return value for the margin settings
3099 * Gets the margin for a given state as a #GtkBorder.
3100 * See %GTK_STYLE_PROPERTY_MARGIN.
3105 gtk_style_context_get_margin (GtkStyleContext *context,
3106 GtkStateFlags state,
3109 int top, left, bottom, right;
3111 g_return_if_fail (margin != NULL);
3112 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3114 gtk_style_context_get (context,
3117 "margin-left", &left,
3118 "margin-bottom", &bottom,
3119 "margin-right", &right,
3123 margin->left = left;
3124 margin->bottom = bottom;
3125 margin->right = right;
3129 * gtk_style_context_get_font:
3130 * @context: a #GtkStyleContext
3131 * @state: state to retrieve the font for
3133 * Returns the font description for a given state. The returned
3134 * object is const and will remain valid until the
3135 * #GtkStyleContext::changed signal happens.
3137 * Returns: (transfer none): the #PangoFontDescription for the given
3138 * state. This object is owned by GTK+ and should not be
3143 const PangoFontDescription *
3144 gtk_style_context_get_font (GtkStyleContext *context,
3145 GtkStateFlags state)
3147 GtkStyleContextPrivate *priv;
3149 PangoFontDescription *description;
3151 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
3153 priv = context->priv;
3154 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
3156 gtk_style_context_save (context);
3157 gtk_style_context_set_state (context, state);
3158 data = style_data_lookup (context);
3159 gtk_style_context_restore (context);
3161 /* Yuck, fonts are created on-demand but we don't return a ref.
3162 * Do bad things to achieve this requirement */
3163 description = g_object_get_data (G_OBJECT (data->store), "font-cache-for-get_font");
3164 if (description == NULL)
3166 gtk_style_context_get (context, state, "font", &description, NULL);
3167 g_object_set_data_full (G_OBJECT (data->store),
3168 "font-cache-for-get_font",
3170 (GDestroyNotify) pango_font_description_free);
3176 get_cursor_color (GtkStyleContext *context,
3180 GdkColor *style_color;
3182 gtk_style_context_get_style (context,
3183 primary ? "cursor-color" : "secondary-cursor-color",
3189 color->red = style_color->red / 65535.0;
3190 color->green = style_color->green / 65535.0;
3191 color->blue = style_color->blue / 65535.0;
3194 gdk_color_free (style_color);
3198 gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, color);
3204 gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &bg);
3206 color->red = (color->red + bg.red) * 0.5;
3207 color->green = (color->green + bg.green) * 0.5;
3208 color->blue = (color->blue + bg.blue) * 0.5;
3214 _gtk_style_context_get_cursor_color (GtkStyleContext *context,
3215 GdkRGBA *primary_color,
3216 GdkRGBA *secondary_color)
3219 get_cursor_color (context, TRUE, primary_color);
3221 if (secondary_color)
3222 get_cursor_color (context, FALSE, secondary_color);
3229 * @context: a #GtkStyleContext
3231 * @x: X origin of the rectangle
3232 * @y: Y origin of the rectangle
3233 * @width: rectangle width
3234 * @height: rectangle height
3236 * Renders a checkmark (as in a #GtkCheckButton).
3238 * The %GTK_STATE_FLAG_ACTIVE state determines whether the check is
3239 * on or off, and %GTK_STATE_FLAG_INCONSISTENT determines whether it
3240 * should be marked as undefined.
3243 * <title>Typical checkmark rendering</title>
3244 * <inlinegraphic fileref="checks.png" format="PNG"/>
3250 gtk_render_check (GtkStyleContext *context,
3257 GtkStyleContextPrivate *priv;
3258 GtkThemingEngineClass *engine_class;
3260 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3261 g_return_if_fail (cr != NULL);
3263 if (width <= 0 || height <= 0)
3266 priv = context->priv;
3267 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3272 _gtk_theming_engine_set_context (priv->theming_engine, context);
3273 engine_class->render_check (priv->theming_engine, cr,
3274 x, y, width, height);
3280 * gtk_render_option:
3281 * @context: a #GtkStyleContext
3283 * @x: X origin of the rectangle
3284 * @y: Y origin of the rectangle
3285 * @width: rectangle width
3286 * @height: rectangle height
3288 * Renders an option mark (as in a #GtkRadioButton), the %GTK_STATE_FLAG_ACTIVE
3289 * state will determine whether the option is on or off, and
3290 * %GTK_STATE_FLAG_INCONSISTENT whether it should be marked as undefined.
3293 * <title>Typical option mark rendering</title>
3294 * <inlinegraphic fileref="options.png" format="PNG"/>
3300 gtk_render_option (GtkStyleContext *context,
3307 GtkStyleContextPrivate *priv;
3308 GtkThemingEngineClass *engine_class;
3310 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3311 g_return_if_fail (cr != NULL);
3313 if (width <= 0 || height <= 0)
3316 priv = context->priv;
3317 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3321 _gtk_theming_engine_set_context (priv->theming_engine, context);
3322 engine_class->render_option (priv->theming_engine, cr,
3323 x, y, width, height);
3330 * @context: a #GtkStyleContext
3332 * @angle: arrow angle from 0 to 2 * %G_PI, being 0 the arrow pointing to the north
3333 * @x: X origin of the render area
3334 * @y: Y origin of the render area
3335 * @size: square side for render area
3337 * Renders an arrow pointing to @angle.
3340 * <title>Typical arrow rendering at 0, 1&solidus;2 π, π and 3&solidus;2 π</title>
3341 * <inlinegraphic fileref="arrows.png" format="PNG"/>
3347 gtk_render_arrow (GtkStyleContext *context,
3354 GtkStyleContextPrivate *priv;
3355 GtkThemingEngineClass *engine_class;
3357 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3358 g_return_if_fail (cr != NULL);
3363 priv = context->priv;
3364 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3368 gtk_style_context_save (context);
3369 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ARROW);
3371 _gtk_theming_engine_set_context (priv->theming_engine, context);
3372 engine_class->render_arrow (priv->theming_engine, cr,
3375 gtk_style_context_restore (context);
3380 * gtk_render_background:
3381 * @context: a #GtkStyleContext
3383 * @x: X origin of the rectangle
3384 * @y: Y origin of the rectangle
3385 * @width: rectangle width
3386 * @height: rectangle height
3388 * Renders the background of an element.
3391 * <title>Typical background rendering, showing the effect of
3392 * <parameter>background-image</parameter>,
3393 * <parameter>border-width</parameter> and
3394 * <parameter>border-radius</parameter></title>
3395 * <inlinegraphic fileref="background.png" format="PNG"/>
3401 gtk_render_background (GtkStyleContext *context,
3408 GtkStyleContextPrivate *priv;
3409 GtkThemingEngineClass *engine_class;
3411 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3412 g_return_if_fail (cr != NULL);
3414 if (width <= 0 || height <= 0)
3417 priv = context->priv;
3418 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3422 _gtk_theming_engine_set_context (priv->theming_engine, context);
3423 engine_class->render_background (priv->theming_engine, cr, x, y, width, height);
3430 * @context: a #GtkStyleContext
3432 * @x: X origin of the rectangle
3433 * @y: Y origin of the rectangle
3434 * @width: rectangle width
3435 * @height: rectangle height
3437 * Renders a frame around the rectangle defined by @x, @y, @width, @height.
3440 * <title>Examples of frame rendering, showing the effect of
3441 * <parameter>border-image</parameter>,
3442 * <parameter>border-color</parameter>,
3443 * <parameter>border-width</parameter>,
3444 * <parameter>border-radius</parameter> and
3446 * <inlinegraphic fileref="frames.png" format="PNG"/>
3452 gtk_render_frame (GtkStyleContext *context,
3459 GtkStyleContextPrivate *priv;
3460 GtkThemingEngineClass *engine_class;
3462 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3463 g_return_if_fail (cr != NULL);
3465 if (width <= 0 || height <= 0)
3468 priv = context->priv;
3469 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3473 _gtk_theming_engine_set_context (priv->theming_engine, context);
3474 engine_class->render_frame (priv->theming_engine, cr, x, y, width, height);
3480 * gtk_render_expander:
3481 * @context: a #GtkStyleContext
3483 * @x: X origin of the rectangle
3484 * @y: Y origin of the rectangle
3485 * @width: rectangle width
3486 * @height: rectangle height
3488 * Renders an expander (as used in #GtkTreeView and #GtkExpander) in the area
3489 * defined by @x, @y, @width, @height. The state %GTK_STATE_FLAG_ACTIVE
3490 * determines whether the expander is collapsed or expanded.
3493 * <title>Typical expander rendering</title>
3494 * <inlinegraphic fileref="expanders.png" format="PNG"/>
3500 gtk_render_expander (GtkStyleContext *context,
3507 GtkStyleContextPrivate *priv;
3508 GtkThemingEngineClass *engine_class;
3510 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3511 g_return_if_fail (cr != NULL);
3513 if (width <= 0 || height <= 0)
3516 priv = context->priv;
3517 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3521 _gtk_theming_engine_set_context (priv->theming_engine, context);
3522 engine_class->render_expander (priv->theming_engine, cr, x, y, width, height);
3529 * @context: a #GtkStyleContext
3531 * @x: X origin of the rectangle
3532 * @y: Y origin of the rectangle
3533 * @width: rectangle width
3534 * @height: rectangle height
3536 * Renders a focus indicator on the rectangle determined by @x, @y, @width, @height.
3538 * <title>Typical focus rendering</title>
3539 * <inlinegraphic fileref="focus.png" format="PNG"/>
3545 gtk_render_focus (GtkStyleContext *context,
3552 GtkStyleContextPrivate *priv;
3553 GtkThemingEngineClass *engine_class;
3555 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3556 g_return_if_fail (cr != NULL);
3558 if (width <= 0 || height <= 0)
3561 priv = context->priv;
3562 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3566 _gtk_theming_engine_set_context (priv->theming_engine, context);
3567 engine_class->render_focus (priv->theming_engine, cr, x, y, width, height);
3573 * gtk_render_layout:
3574 * @context: a #GtkStyleContext
3578 * @layout: the #PangoLayout to render
3580 * Renders @layout on the coordinates @x, @y
3585 gtk_render_layout (GtkStyleContext *context,
3589 PangoLayout *layout)
3591 GtkStyleContextPrivate *priv;
3592 GtkThemingEngineClass *engine_class;
3593 PangoRectangle extents;
3595 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3596 g_return_if_fail (PANGO_IS_LAYOUT (layout));
3597 g_return_if_fail (cr != NULL);
3599 priv = context->priv;
3600 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3604 pango_layout_get_extents (layout, &extents, NULL);
3606 _gtk_theming_engine_set_context (priv->theming_engine, context);
3607 engine_class->render_layout (priv->theming_engine, cr, x, y, layout);
3614 * @context: a #GtkStyleContext
3616 * @x0: X coordinate for the origin of the line
3617 * @y0: Y coordinate for the origin of the line
3618 * @x1: X coordinate for the end of the line
3619 * @y1: Y coordinate for the end of the line
3621 * Renders a line from (x0, y0) to (x1, y1).
3626 gtk_render_line (GtkStyleContext *context,
3633 GtkStyleContextPrivate *priv;
3634 GtkThemingEngineClass *engine_class;
3636 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3637 g_return_if_fail (cr != NULL);
3639 priv = context->priv;
3640 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3644 _gtk_theming_engine_set_context (priv->theming_engine, context);
3645 engine_class->render_line (priv->theming_engine, cr, x0, y0, x1, y1);
3651 * gtk_render_slider:
3652 * @context: a #GtkStyleContext
3654 * @x: X origin of the rectangle
3655 * @y: Y origin of the rectangle
3656 * @width: rectangle width
3657 * @height: rectangle height
3658 * @orientation: orientation of the slider
3660 * Renders a slider (as in #GtkScale) in the rectangle defined by @x, @y,
3661 * @width, @height. @orientation defines whether the slider is vertical
3665 * <title>Typical slider rendering</title>
3666 * <inlinegraphic fileref="sliders.png" format="PNG"/>
3672 gtk_render_slider (GtkStyleContext *context,
3678 GtkOrientation orientation)
3680 GtkStyleContextPrivate *priv;
3681 GtkThemingEngineClass *engine_class;
3683 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3684 g_return_if_fail (cr != NULL);
3686 if (width <= 0 || height <= 0)
3689 priv = context->priv;
3690 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3694 _gtk_theming_engine_set_context (priv->theming_engine, context);
3695 engine_class->render_slider (priv->theming_engine, cr, x, y, width, height, orientation);
3701 * gtk_render_frame_gap:
3702 * @context: a #GtkStyleContext
3704 * @x: X origin of the rectangle
3705 * @y: Y origin of the rectangle
3706 * @width: rectangle width
3707 * @height: rectangle height
3708 * @gap_side: side where the gap is
3709 * @xy0_gap: initial coordinate (X or Y depending on @gap_side) for the gap
3710 * @xy1_gap: end coordinate (X or Y depending on @gap_side) for the gap
3712 * Renders a frame around the rectangle defined by (@x, @y, @width, @height),
3713 * leaving a gap on one side. @xy0_gap and @xy1_gap will mean X coordinates
3714 * for %GTK_POS_TOP and %GTK_POS_BOTTOM gap sides, and Y coordinates for
3715 * %GTK_POS_LEFT and %GTK_POS_RIGHT.
3718 * <title>Typical rendering of a frame with a gap</title>
3719 * <inlinegraphic fileref="frame-gap.png" format="PNG"/>
3725 gtk_render_frame_gap (GtkStyleContext *context,
3731 GtkPositionType gap_side,
3735 GtkStyleContextPrivate *priv;
3736 GtkThemingEngineClass *engine_class;
3738 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3739 g_return_if_fail (cr != NULL);
3740 g_return_if_fail (xy0_gap <= xy1_gap);
3741 g_return_if_fail (xy0_gap >= 0);
3743 if (width <= 0 || height <= 0)
3746 if (gap_side == GTK_POS_LEFT ||
3747 gap_side == GTK_POS_RIGHT)
3748 g_return_if_fail (xy1_gap <= height);
3750 g_return_if_fail (xy1_gap <= width);
3752 priv = context->priv;
3753 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3757 _gtk_theming_engine_set_context (priv->theming_engine, context);
3758 engine_class->render_frame_gap (priv->theming_engine, cr,
3759 x, y, width, height, gap_side,
3766 * gtk_render_extension:
3767 * @context: a #GtkStyleContext
3769 * @x: X origin of the rectangle
3770 * @y: Y origin of the rectangle
3771 * @width: rectangle width
3772 * @height: rectangle height
3773 * @gap_side: side where the gap is
3775 * Renders a extension (as in a #GtkNotebook tab) in the rectangle
3776 * defined by @x, @y, @width, @height. The side where the extension
3777 * connects to is defined by @gap_side.
3780 * <title>Typical extension rendering</title>
3781 * <inlinegraphic fileref="extensions.png" format="PNG"/>
3787 gtk_render_extension (GtkStyleContext *context,
3793 GtkPositionType gap_side)
3795 GtkStyleContextPrivate *priv;
3796 GtkThemingEngineClass *engine_class;
3798 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3799 g_return_if_fail (cr != NULL);
3801 if (width <= 0 || height <= 0)
3804 priv = context->priv;
3805 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3809 _gtk_theming_engine_set_context (priv->theming_engine, context);
3810 engine_class->render_extension (priv->theming_engine, cr, x, y, width, height, gap_side);
3816 * gtk_render_handle:
3817 * @context: a #GtkStyleContext
3819 * @x: X origin of the rectangle
3820 * @y: Y origin of the rectangle
3821 * @width: rectangle width
3822 * @height: rectangle height
3824 * Renders a handle (as in #GtkHandleBox, #GtkPaned and
3825 * #GtkWindow<!-- -->'s resize grip), in the rectangle
3826 * determined by @x, @y, @width, @height.
3829 * <title>Handles rendered for the paned and grip classes</title>
3830 * <inlinegraphic fileref="handles.png" format="PNG"/>
3836 gtk_render_handle (GtkStyleContext *context,
3843 GtkStyleContextPrivate *priv;
3844 GtkThemingEngineClass *engine_class;
3846 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3847 g_return_if_fail (cr != NULL);
3849 if (width <= 0 || height <= 0)
3852 priv = context->priv;
3853 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3857 _gtk_theming_engine_set_context (priv->theming_engine, context);
3858 engine_class->render_handle (priv->theming_engine, cr, x, y, width, height);
3864 * gtk_render_activity:
3865 * @context: a #GtkStyleContext
3867 * @x: X origin of the rectangle
3868 * @y: Y origin of the rectangle
3869 * @width: rectangle width
3870 * @height: rectangle height
3872 * Renders an activity area (Such as in #GtkSpinner or the
3873 * fill line in #GtkRange), the state %GTK_STATE_FLAG_ACTIVE
3874 * determines whether there is activity going on.
3879 gtk_render_activity (GtkStyleContext *context,
3886 GtkStyleContextPrivate *priv;
3887 GtkThemingEngineClass *engine_class;
3889 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3890 g_return_if_fail (cr != NULL);
3892 if (width <= 0 || height <= 0)
3895 priv = context->priv;
3896 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3900 _gtk_theming_engine_set_context (priv->theming_engine, context);
3901 engine_class->render_activity (priv->theming_engine, cr, x, y, width, height);
3907 * gtk_render_icon_pixbuf:
3908 * @context: a #GtkStyleContext
3909 * @source: the #GtkIconSource specifying the icon to render
3910 * @size: (type int): the size to render the icon at. A size of (GtkIconSize) -1
3911 * means render at the size of the source and don't scale.
3913 * Renders the icon specified by @source at the given @size, returning the result
3916 * Returns: (transfer full): a newly-created #GdkPixbuf containing the rendered icon
3921 gtk_render_icon_pixbuf (GtkStyleContext *context,
3922 const GtkIconSource *source,
3925 GtkStyleContextPrivate *priv;
3926 GtkThemingEngineClass *engine_class;
3928 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
3929 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
3930 g_return_val_if_fail (source != NULL, NULL);
3932 priv = context->priv;
3933 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3935 _gtk_theming_engine_set_context (priv->theming_engine, context);
3936 return engine_class->render_icon_pixbuf (priv->theming_engine, source, size);
3941 * @context: a #GtkStyleContext
3943 * @pixbuf: a #GdkPixbuf containing the icon to draw
3944 * @x: X position for the @pixbuf
3945 * @y: Y position for the @pixbuf
3947 * Renders the icon in @pixbuf at the specified @x and @y coordinates.
3952 gtk_render_icon (GtkStyleContext *context,
3958 GtkStyleContextPrivate *priv;
3959 GtkThemingEngineClass *engine_class;
3961 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3962 g_return_if_fail (cr != NULL);
3964 priv = context->priv;
3965 engine_class = GTK_THEMING_ENGINE_GET_CLASS (priv->theming_engine);
3969 _gtk_theming_engine_set_context (priv->theming_engine, context);
3970 engine_class->render_icon (priv->theming_engine, cr, pixbuf, x, y);
3976 draw_insertion_cursor (GtkStyleContext *context,
3981 gboolean is_primary,
3982 PangoDirection direction,
3983 gboolean draw_arrow)
3986 GdkRGBA primary_color;
3987 GdkRGBA secondary_color;
3988 gfloat cursor_aspect_ratio;
3994 _gtk_style_context_get_cursor_color (context, &primary_color, &secondary_color);
3995 gdk_cairo_set_source_rgba (cr, is_primary ? &primary_color : &secondary_color);
3997 /* When changing the shape or size of the cursor here,
3998 * propagate the changes to gtktextview.c:text_window_invalidate_cursors().
4001 gtk_style_context_get_style (context,
4002 "cursor-aspect-ratio", &cursor_aspect_ratio,
4005 stem_width = height * cursor_aspect_ratio + 1;
4007 /* put (stem_width % 2) on the proper side of the cursor */
4008 if (direction == PANGO_DIRECTION_LTR)
4009 offset = stem_width / 2;
4011 offset = stem_width - stem_width / 2;
4013 cairo_rectangle (cr, x - offset, y, stem_width, height);
4021 arrow_width = stem_width + 1;
4023 if (direction == PANGO_DIRECTION_RTL)
4025 ax = x - offset - 1;
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);
4033 else if (direction == PANGO_DIRECTION_LTR)
4035 ax = x + stem_width - offset;
4036 ay = y + height - arrow_width * 2 - arrow_width + 1;
4038 cairo_move_to (cr, ax, ay + 1);
4039 cairo_line_to (cr, ax + arrow_width, ay + arrow_width);
4040 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4044 g_assert_not_reached();
4051 * gtk_render_insertion_cursor:
4052 * @context: a #GtkStyleContext
4056 * @layout: the #PangoLayout of the text
4057 * @index: the index in the #PangoLayout
4058 * @direction: the #PangoDirection of the text
4060 * Draws a text caret on @cr at the specified index of @layout.
4065 gtk_render_insertion_cursor (GtkStyleContext *context,
4069 PangoLayout *layout,
4071 PangoDirection direction)
4073 GtkStyleContextPrivate *priv;
4074 gboolean split_cursor;
4075 PangoRectangle strong_pos, weak_pos;
4076 PangoRectangle *cursor1, *cursor2;
4077 PangoDirection keymap_direction;
4078 PangoDirection direction2;
4080 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4081 g_return_if_fail (cr != NULL);
4082 g_return_if_fail (PANGO_IS_LAYOUT (layout));
4083 g_return_if_fail (index >= 0);
4085 priv = context->priv;
4087 g_object_get (gtk_settings_get_for_screen (priv->screen),
4088 "gtk-split-cursor", &split_cursor,
4091 keymap_direction = gdk_keymap_get_direction (gdk_keymap_get_for_display (gdk_screen_get_display (priv->screen)));
4093 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4095 direction2 = PANGO_DIRECTION_NEUTRAL;
4099 cursor1 = &strong_pos;
4101 if (strong_pos.x != weak_pos.x || strong_pos.y != weak_pos.y)
4103 direction2 = (direction == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
4104 cursor2 = &weak_pos;
4109 if (keymap_direction == direction)
4110 cursor1 = &strong_pos;
4112 cursor1 = &weak_pos;
4115 draw_insertion_cursor (context,
4117 x + PANGO_PIXELS (cursor1->x),
4118 y + PANGO_PIXELS (cursor1->y),
4119 PANGO_PIXELS (cursor1->height),
4122 direction2 != PANGO_DIRECTION_NEUTRAL);
4124 if (direction2 != PANGO_DIRECTION_NEUTRAL)
4126 draw_insertion_cursor (context,
4128 x + PANGO_PIXELS (cursor2->x),
4129 y + PANGO_PIXELS (cursor2->y),
4130 PANGO_PIXELS (cursor2->height),
4138 * gtk_draw_insertion_cursor:
4139 * @widget: a #GtkWidget
4140 * @cr: cairo context to draw to
4141 * @location: location where to draw the cursor (@location->width is ignored)
4142 * @is_primary: if the cursor should be the primary cursor color.
4143 * @direction: whether the cursor is left-to-right or
4144 * right-to-left. Should never be #GTK_TEXT_DIR_NONE
4145 * @draw_arrow: %TRUE to draw a directional arrow on the
4146 * cursor. Should be %FALSE unless the cursor is split.
4148 * Draws a text caret on @cr at @location. This is not a style function
4149 * but merely a convenience function for drawing the standard cursor shape.
4152 * Deprecated: 3.4: Use gtk_render_insertion_cursor() instead.
4155 gtk_draw_insertion_cursor (GtkWidget *widget,
4157 const GdkRectangle *location,
4158 gboolean is_primary,
4159 GtkTextDirection direction,
4160 gboolean draw_arrow)
4162 GtkStyleContext *context;
4164 g_return_if_fail (GTK_IS_WIDGET (widget));
4165 g_return_if_fail (cr != NULL);
4166 g_return_if_fail (location != NULL);
4167 g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
4169 context = gtk_widget_get_style_context (widget);
4171 draw_insertion_cursor (context, cr,
4172 location->x, location->y, location->height,
4174 (direction == GTK_TEXT_DIR_RTL) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR,
4178 static AtkAttributeSet *
4179 add_attribute (AtkAttributeSet *attributes,
4180 AtkTextAttribute attr,
4185 at = g_new (AtkAttribute, 1);
4186 at->name = g_strdup (atk_text_attribute_get_name (attr));
4187 at->value = g_strdup (value);
4189 return g_slist_prepend (attributes, at);
4193 * _gtk_style_context_get_attributes:
4194 * @attributes: a #AtkAttributeSet to add attributes to
4195 * @context: the #GtkStyleContext to get attributes from
4196 * @flags: the state to use with @context
4198 * Adds the foreground and background color from @context to
4199 * @attributes, after translating them to ATK attributes.
4201 * This is a convenience function that can be used in
4202 * implementing the #AtkText interface in widgets.
4204 * Returns: the modified #AtkAttributeSet
4207 _gtk_style_context_get_attributes (AtkAttributeSet *attributes,
4208 GtkStyleContext *context,
4209 GtkStateFlags flags)
4214 gtk_style_context_get_background_color (context, flags, &color);
4215 value = g_strdup_printf ("%u,%u,%u",
4216 (guint) ceil (color.red * 65536 - color.red),
4217 (guint) ceil (color.green * 65536 - color.green),
4218 (guint) ceil (color.blue * 65536 - color.blue));
4219 attributes = add_attribute (attributes, ATK_TEXT_ATTR_BG_COLOR, value);
4222 gtk_style_context_get_color (context, flags, &color);
4223 value = g_strdup_printf ("%u,%u,%u",
4224 (guint) ceil (color.red * 65536 - color.red),
4225 (guint) ceil (color.green * 65536 - color.green),
4226 (guint) ceil (color.blue * 65536 - color.blue));
4227 attributes = add_attribute (attributes, ATK_TEXT_ATTR_FG_COLOR, value);