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 "gtkcontainerprivate.h"
27 #include "gtkcssenginevalueprivate.h"
28 #include "gtkcssrgbavalueprivate.h"
29 #include "gtkstylepropertiesprivate.h"
30 #include "gtktypebuiltins.h"
31 #include "gtkthemingengineprivate.h"
33 #include "gtkwidget.h"
34 #include "gtkwindow.h"
35 #include "gtkprivate.h"
36 #include "gtksymboliccolorprivate.h"
37 #include "gtkcssnumbervalueprivate.h"
38 #include "gtkiconfactory.h"
39 #include "gtkwidgetpath.h"
40 #include "gtkwidgetprivate.h"
41 #include "gtkstylecascadeprivate.h"
42 #include "gtkstyleproviderprivate.h"
43 #include "gtksettings.h"
46 * SECTION:gtkstylecontext
47 * @Short_description: Rendering UI elements
48 * @Title: GtkStyleContext
50 * #GtkStyleContext is an object that stores styling information affecting
51 * a widget defined by #GtkWidgetPath.
53 * In order to construct the final style information, #GtkStyleContext
54 * queries information from all attached #GtkStyleProviders. Style providers
55 * can be either attached explicitly to the context through
56 * gtk_style_context_add_provider(), or to the screen through
57 * gtk_style_context_add_provider_for_screen(). The resulting style is a
58 * combination of all providers' information in priority order.
60 * For GTK+ widgets, any #GtkStyleContext returned by
61 * gtk_widget_get_style_context() will already have a #GtkWidgetPath, a
62 * #GdkScreen and RTL/LTR information set. The style context will be also
63 * updated automatically if any of these settings change on the widget.
65 * If you are using the theming layer standalone, you will need to set a
66 * widget path and a screen yourself to the created style context through
67 * gtk_style_context_set_path() and gtk_style_context_set_screen(), as well
68 * as updating the context yourself using gtk_style_context_invalidate()
69 * whenever any of the conditions change, such as a change in the
70 * #GtkSettings:gtk-theme-name setting or a hierarchy change in the rendered
73 * <refsect2 id="gtkstylecontext-animations">
74 * <title>Transition animations</title>
76 * #GtkStyleContext has built-in support for state change transitions.
77 * Note that these animations respect the #GtkSettings:gtk-enable-animations
81 * For simple widgets where state changes affect the whole widget area,
82 * calling gtk_style_context_notify_state_change() with a %NULL region
83 * is sufficient to trigger the transition animation. And GTK+ already
84 * does that when gtk_widget_set_state() or gtk_widget_set_state_flags()
88 * If a widget needs to declare several animatable regions (i.e. not
89 * affecting the whole widget area), its #GtkWidget::draw signal handler
90 * needs to wrap the render operations for the different regions with
91 * calls to gtk_style_context_push_animatable_region() and
92 * gtk_style_context_pop_animatable_region(). These functions take an
93 * identifier for the region which must be unique within the style context.
94 * For simple widgets with a fixed set of animatable regions, using an
95 * enumeration works well:
98 * <title>Using an enumeration to identify animatable regions</title>
109 * spin_button_draw (GtkWidget *widget,
112 * GtkStyleContext *context;
114 * context = gtk_widget_get_style_context (widget);
116 * gtk_style_context_push_animatable_region (context,
117 * GUINT_TO_POINTER (REGION_ENTRY));
119 * gtk_render_background (cr, 0, 0, 100, 30);
120 * gtk_render_frame (cr, 0, 0, 100, 30);
122 * gtk_style_context_pop_animatable_region (context);
129 * For complex widgets with an arbitrary number of animatable regions, it
130 * is up to the implementation to come up with a way to uniquely identify
131 * each animatable region. Using pointers to internal structs is one way
135 * <title>Using struct pointers to identify animatable regions</title>
138 * notebook_draw_tab (GtkWidget *widget,
139 * NotebookPage *page,
142 * gtk_style_context_push_animatable_region (context, page);
143 * gtk_render_extension (cr, page->x, page->y, page->width, page->height);
144 * gtk_style_context_pop_animatable_region (context);
149 * The widget also needs to notify the style context about a state change
150 * for a given animatable region so the animation is triggered.
153 * <title>Triggering a state change animation on a region</title>
156 * notebook_motion_notify (GtkWidget *widget,
157 * GdkEventMotion *event)
159 * GtkStyleContext *context;
160 * NotebookPage *page;
162 * context = gtk_widget_get_style_context (widget);
163 * page = find_page_under_pointer (widget, event);
164 * gtk_style_context_notify_state_change (context,
165 * gtk_widget_get_window (widget),
167 * GTK_STATE_PRELIGHT,
174 * gtk_style_context_notify_state_change() accepts %NULL region IDs as a
175 * special value, in this case, the whole widget area will be updated
179 * <refsect2 id="gtkstylecontext-classes">
180 * <title>Style classes and regions</title>
182 * Widgets can add style classes to their context, which can be used
183 * to associate different styles by class (see <xref linkend="gtkcssprovider-selectors"/>). Theme engines can also use style classes to vary their
184 * rendering. GTK+ has a number of predefined style classes:
185 * #GTK_STYLE_CLASS_CELL,
186 * #GTK_STYLE_CLASS_ENTRY,
187 * #GTK_STYLE_CLASS_BUTTON,
188 * #GTK_STYLE_CLASS_COMBOBOX_ENTRY,
189 * #GTK_STYLE_CLASS_CALENDAR,
190 * #GTK_STYLE_CLASS_SLIDER,
191 * #GTK_STYLE_CLASS_BACKGROUND,
192 * #GTK_STYLE_CLASS_RUBBERBAND,
193 * #GTK_STYLE_CLASS_TOOLTIP,
194 * #GTK_STYLE_CLASS_MENU,
195 * #GTK_STYLE_CLASS_MENUBAR,
196 * #GTK_STYLE_CLASS_MENUITEM,
197 * #GTK_STYLE_CLASS_TOOLBAR,
198 * #GTK_STYLE_CLASS_PRIMARY_TOOLBAR,
199 * #GTK_STYLE_CLASS_INLINE_TOOLBAR,
200 * #GTK_STYLE_CLASS_RADIO,
201 * #GTK_STYLE_CLASS_CHECK,
202 * #GTK_STYLE_CLASS_TROUGH,
203 * #GTK_STYLE_CLASS_SCROLLBAR,
204 * #GTK_STYLE_CLASS_SCALE,
205 * #GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE,
206 * #GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW,
207 * #GTK_STYLE_CLASS_HEADER,
208 * #GTK_STYLE_CLASS_ACCELERATOR,
209 * #GTK_STYLE_CLASS_GRIP,
210 * #GTK_STYLE_CLASS_DOCK,
211 * #GTK_STYLE_CLASS_PROGRESSBAR,
212 * #GTK_STYLE_CLASS_SPINNER,
213 * #GTK_STYLE_CLASS_EXPANDER,
214 * #GTK_STYLE_CLASS_SPINBUTTON,
215 * #GTK_STYLE_CLASS_NOTEBOOK,
216 * #GTK_STYLE_CLASS_VIEW,
217 * #GTK_STYLE_CLASS_SIDEBAR,
218 * #GTK_STYLE_CLASS_IMAGE,
219 * #GTK_STYLE_CLASS_HIGHLIGHT,
220 * #GTK_STYLE_CLASS_FRAME,
221 * #GTK_STYLE_CLASS_DND,
222 * #GTK_STYLE_CLASS_PANE_SEPARATOR,
223 * #GTK_STYLE_CLASS_SEPARATOR,
224 * #GTK_STYLE_CLASS_INFO,
225 * #GTK_STYLE_CLASS_WARNING,
226 * #GTK_STYLE_CLASS_QUESTION,
227 * #GTK_STYLE_CLASS_ERROR,
228 * #GTK_STYLE_CLASS_HORIZONTAL,
229 * #GTK_STYLE_CLASS_VERTICAL,
230 * #GTK_STYLE_CLASS_TOP,
231 * #GTK_STYLE_CLASS_BOTTOM,
232 * #GTK_STYLE_CLASS_LEFT,
233 * #GTK_STYLE_CLASS_RIGHT,
236 * Widgets can also add regions with flags to their context.
237 * The regions used by GTK+ widgets are:
242 * <entry>Region</entry>
243 * <entry>Flags</entry>
244 * <entry>Macro</entry>
245 * <entry>Used by</entry>
251 * <entry>even, odd</entry>
252 * <entry>GTK_STYLE_REGION_ROW</entry>
253 * <entry>#GtkTreeView</entry>
256 * <entry>column</entry>
257 * <entry>first, last, sorted</entry>
258 * <entry>GTK_STYLE_REGION_COLUMN</entry>
259 * <entry>#GtkTreeView</entry>
262 * <entry>column-header</entry>
264 * <entry>GTK_STYLE_REGION_COLUMN_HEADER</entry>
269 * <entry>even, odd, first, last</entry>
270 * <entry>GTK_STYLE_REGION_TAB</entry>
271 * <entry>#GtkNotebook</entry>
278 * <refsect2 id="gtkstylecontext-custom-styling">
279 * <title>Custom styling in UI libraries and applications</title>
281 * If you are developing a library with custom #GtkWidget<!-- -->s that
282 * render differently than standard components, you may need to add a
283 * #GtkStyleProvider yourself with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK
284 * priority, either a #GtkCssProvider or a custom object implementing the
285 * #GtkStyleProvider interface. This way theming engines may still attempt
286 * to style your UI elements in a different way if needed so.
289 * If you are using custom styling on an applications, you probably want then
290 * to make your style information prevail to the theme's, so you must use
291 * a #GtkStyleProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
292 * priority, keep in mind that the user settings in
293 * <filename><replaceable>XDG_CONFIG_HOME</replaceable>/gtk-3.0/gtk.css</filename> will
294 * still take precedence over your changes, as it uses the
295 * %GTK_STYLE_PROVIDER_PRIORITY_USER priority.
298 * If a custom theming engine is needed, you probably want to implement a
299 * #GtkStyleProvider yourself so it points to your #GtkThemingEngine
300 * implementation, as #GtkCssProvider uses gtk_theming_engine_load()
301 * which loads the theming engine module from the standard paths.
306 /* When these change we do a full restyling. Otherwise we try to figure out
307 * if we need to change things. */
308 #define GTK_STYLE_CONTEXT_RADICAL_CHANGE (GTK_CSS_CHANGE_NAME | GTK_CSS_CHANGE_CLASS | GTK_CSS_CHANGE_SOURCE)
309 /* When these change we don't clear the cache. This takes more memory but makes
310 * things go faster. */
311 #define GTK_STYLE_CONTEXT_CACHED_CHANGE (GTK_CSS_CHANGE_STATE)
313 typedef struct GtkStyleInfo GtkStyleInfo;
314 typedef struct GtkRegion GtkRegion;
315 typedef struct PropertyValue PropertyValue;
316 typedef struct StyleData StyleData;
321 GtkRegionFlags flags;
335 GArray *style_classes;
337 GtkJunctionSides junction_sides;
338 GtkStateFlags state_flags;
344 GtkCssComputedValues *store;
345 GArray *property_cache;
349 struct _GtkStyleContextPrivate
353 GtkStyleCascade *cascade;
355 GtkStyleContext *animation_list_prev;
356 GtkStyleContext *animation_list_next;
358 GtkStyleContext *parent;
361 GtkWidgetPath *widget_path;
362 GHashTable *style_data;
365 GtkTextDirection direction;
367 GtkCssChange relevant_changes;
368 GtkCssChange pending_changes;
370 guint invalidating_context : 1;
386 static guint signals[LAST_SIGNAL] = { 0 };
387 static GtkStyleContext *_running_animations = NULL;
388 guint _running_animations_timer_id = 0;
390 static void gtk_style_context_finalize (GObject *object);
392 static void gtk_style_context_impl_set_property (GObject *object,
396 static void gtk_style_context_impl_get_property (GObject *object,
400 static GtkSymbolicColor *
401 gtk_style_context_color_lookup_func (gpointer contextp,
405 G_DEFINE_TYPE (GtkStyleContext, gtk_style_context, G_TYPE_OBJECT)
408 gtk_style_context_real_changed (GtkStyleContext *context)
410 GtkStyleContextPrivate *priv = context->priv;
413 _gtk_widget_style_context_invalidated (priv->widget);
417 gtk_style_context_class_init (GtkStyleContextClass *klass)
419 GObjectClass *object_class = G_OBJECT_CLASS (klass);
421 object_class->finalize = gtk_style_context_finalize;
422 object_class->set_property = gtk_style_context_impl_set_property;
423 object_class->get_property = gtk_style_context_impl_get_property;
425 klass->changed = gtk_style_context_real_changed;
428 g_signal_new (I_("changed"),
429 G_TYPE_FROM_CLASS (object_class),
431 G_STRUCT_OFFSET (GtkStyleContextClass, changed),
433 g_cclosure_marshal_VOID__VOID,
436 g_object_class_install_property (object_class,
438 g_param_spec_object ("screen",
440 P_("The associated GdkScreen"),
442 GTK_PARAM_READWRITE));
443 g_object_class_install_property (object_class,
445 g_param_spec_enum ("direction",
447 P_("Text direction"),
448 GTK_TYPE_TEXT_DIRECTION,
450 GTK_PARAM_READWRITE));
452 * GtkStyleContext:parent:
454 * Sets or gets the style context's parent. See gtk_style_context_set_parent()
459 g_object_class_install_property (object_class,
461 g_param_spec_object ("parent",
463 P_("The parent style context"),
464 GTK_TYPE_STYLE_CONTEXT,
465 GTK_PARAM_READWRITE));
467 g_type_class_add_private (object_class, sizeof (GtkStyleContextPrivate));
471 style_data_new (void)
475 data = g_slice_new0 (StyleData);
482 clear_property_cache (StyleData *data)
486 if (!data->property_cache)
489 for (i = 0; i < data->property_cache->len; i++)
491 PropertyValue *node = &g_array_index (data->property_cache, PropertyValue, i);
493 g_param_spec_unref (node->pspec);
494 g_value_unset (&node->value);
497 g_array_free (data->property_cache, TRUE);
498 data->property_cache = NULL;
502 style_data_ref (StyleData *style_data)
504 style_data->ref_count++;
510 style_data_unref (StyleData *data)
514 if (data->ref_count > 0)
517 g_object_unref (data->store);
518 clear_property_cache (data);
520 g_slice_free (StyleData, data);
523 static GtkStyleInfo *
524 style_info_new (void)
528 info = g_slice_new0 (GtkStyleInfo);
529 info->style_classes = g_array_new (FALSE, FALSE, sizeof (GQuark));
530 info->regions = g_array_new (FALSE, FALSE, sizeof (GtkRegion));
536 style_info_free (GtkStyleInfo *info)
539 style_data_unref (info->data);
540 g_array_free (info->style_classes, TRUE);
541 g_array_free (info->regions, TRUE);
542 g_slice_free (GtkStyleInfo, info);
545 static GtkStyleInfo *
546 style_info_pop (GtkStyleInfo *info)
548 GtkStyleInfo *next = info->next;
550 style_info_free (info);
555 static GtkStyleInfo *
556 style_info_copy (GtkStyleInfo *info)
560 copy = style_info_new ();
561 g_array_insert_vals (copy->style_classes, 0,
562 info->style_classes->data,
563 info->style_classes->len);
565 g_array_insert_vals (copy->regions, 0,
570 copy->junction_sides = info->junction_sides;
571 copy->state_flags = info->state_flags;
573 copy->data = style_data_ref (info->data);
579 style_info_hash (gconstpointer elem)
581 const GtkStyleInfo *info;
586 for (i = 0; i < info->style_classes->len; i++)
588 hash += g_array_index (info->style_classes, GQuark, i);
592 for (i = 0; i < info->regions->len; i++)
596 region = &g_array_index (info->regions, GtkRegion, i);
597 hash += region->class_quark;
598 hash += region->flags;
602 return hash ^ info->state_flags;
606 style_info_equal (gconstpointer elem1,
609 const GtkStyleInfo *info1, *info2;
614 if (info1->state_flags != info2->state_flags)
617 if (info1->junction_sides != info2->junction_sides)
620 if (info1->style_classes->len != info2->style_classes->len)
623 if (memcmp (info1->style_classes->data,
624 info2->style_classes->data,
625 info1->style_classes->len * sizeof (GQuark)) != 0)
628 if (info1->regions->len != info2->regions->len)
631 if (memcmp (info1->regions->data,
632 info2->regions->data,
633 info1->regions->len * sizeof (GtkRegion)) != 0)
640 gtk_style_context_cascade_changed (GtkStyleCascade *cascade,
641 GtkStyleContext *context)
643 GtkStyleContextPrivate *priv = context->priv;
646 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_SOURCE);
648 gtk_style_context_invalidate (context);
652 gtk_style_context_set_cascade (GtkStyleContext *context,
653 GtkStyleCascade *cascade)
655 GtkStyleContextPrivate *priv;
657 priv = context->priv;
659 if (priv->cascade == cascade)
664 g_object_ref (cascade);
665 g_signal_connect (cascade,
666 "-gtk-private-changed",
667 G_CALLBACK (gtk_style_context_cascade_changed),
673 g_signal_handlers_disconnect_by_func (priv->cascade,
674 gtk_style_context_cascade_changed,
676 g_object_unref (priv->cascade);
679 priv->cascade = cascade;
682 gtk_style_context_cascade_changed (cascade, context);
686 gtk_style_context_init (GtkStyleContext *style_context)
688 GtkStyleContextPrivate *priv;
690 priv = style_context->priv = G_TYPE_INSTANCE_GET_PRIVATE (style_context,
691 GTK_TYPE_STYLE_CONTEXT,
692 GtkStyleContextPrivate);
694 priv->style_data = g_hash_table_new_full (style_info_hash,
696 (GDestroyNotify) style_info_free,
697 (GDestroyNotify) style_data_unref);
699 priv->direction = GTK_TEXT_DIR_LTR;
701 priv->screen = gdk_screen_get_default ();
702 priv->relevant_changes = GTK_CSS_CHANGE_ANY;
704 /* Create default info store */
705 priv->info = style_info_new ();
707 gtk_style_context_set_cascade (style_context,
708 _gtk_style_cascade_get_for_screen (priv->screen));
712 gtk_style_context_do_animations (gpointer unused)
714 GtkStyleContext *context;
716 for (context = _running_animations;
718 context = context->priv->animation_list_next)
720 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANIMATE);
727 gtk_style_context_is_animating (GtkStyleContext *context)
729 GtkStyleContextPrivate *priv = context->priv;
731 return priv->animation_list_prev != NULL
732 || _running_animations == context;
736 gtk_style_context_stop_animating (GtkStyleContext *context)
738 GtkStyleContextPrivate *priv = context->priv;
740 if (!gtk_style_context_is_animating (context))
743 if (priv->animation_list_prev == NULL)
745 _running_animations = priv->animation_list_next;
747 if (_running_animations == NULL)
749 /* we were the last animation */
750 g_source_remove (_running_animations_timer_id);
751 _running_animations_timer_id = 0;
755 priv->animation_list_prev->priv->animation_list_next = priv->animation_list_next;
757 if (priv->animation_list_next)
758 priv->animation_list_next->priv->animation_list_prev = priv->animation_list_prev;
760 priv->animation_list_next = NULL;
761 priv->animation_list_prev = NULL;
764 static void G_GNUC_UNUSED
765 gtk_style_context_start_animating (GtkStyleContext *context)
767 GtkStyleContextPrivate *priv = context->priv;
769 if (gtk_style_context_is_animating (context))
772 if (_running_animations == NULL)
774 _running_animations_timer_id = gdk_threads_add_timeout (25,
775 gtk_style_context_do_animations,
777 _running_animations = context;
781 priv->animation_list_next = _running_animations;
782 _running_animations->priv->animation_list_prev = context;
783 _running_animations = context;
788 gtk_style_context_finalize (GObject *object)
790 GtkStyleContextPrivate *priv;
791 GtkStyleContext *style_context;
793 style_context = GTK_STYLE_CONTEXT (object);
794 priv = style_context->priv;
796 _gtk_style_context_stop_animations (style_context);
798 /* children hold a reference to us */
799 g_assert (priv->children == NULL);
801 gtk_style_context_set_parent (style_context, NULL);
803 gtk_style_context_set_cascade (style_context, NULL);
805 if (priv->widget_path)
806 gtk_widget_path_free (priv->widget_path);
808 g_hash_table_destroy (priv->style_data);
811 priv->info = style_info_pop (priv->info);
813 G_OBJECT_CLASS (gtk_style_context_parent_class)->finalize (object);
817 gtk_style_context_impl_set_property (GObject *object,
822 GtkStyleContext *style_context;
824 style_context = GTK_STYLE_CONTEXT (object);
829 gtk_style_context_set_screen (style_context,
830 g_value_get_object (value));
833 gtk_style_context_set_direction (style_context,
834 g_value_get_enum (value));
837 gtk_style_context_set_parent (style_context,
838 g_value_get_object (value));
841 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
847 gtk_style_context_impl_get_property (GObject *object,
852 GtkStyleContext *style_context;
853 GtkStyleContextPrivate *priv;
855 style_context = GTK_STYLE_CONTEXT (object);
856 priv = style_context->priv;
861 g_value_set_object (value, priv->screen);
864 g_value_set_enum (value, priv->direction);
867 g_value_set_object (value, priv->parent);
870 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
876 build_properties (GtkStyleContext *context,
877 StyleData *style_data,
881 GtkStyleContextPrivate *priv;
882 GtkCssMatcher matcher;
883 GtkCssLookup *lookup;
885 priv = context->priv;
887 _gtk_css_matcher_init (&matcher, path, state);
888 lookup = _gtk_css_lookup_new ();
890 _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
894 style_data->store = _gtk_css_computed_values_new ();
895 _gtk_css_lookup_resolve (lookup, context, style_data->store);
896 _gtk_css_lookup_free (lookup);
899 static GtkWidgetPath *
900 create_query_path (GtkStyleContext *context)
902 GtkStyleContextPrivate *priv;
907 priv = context->priv;
908 path = priv->widget ? _gtk_widget_create_path (priv->widget) : gtk_widget_path_copy (priv->widget_path);
909 pos = gtk_widget_path_length (path) - 1;
913 /* Set widget regions */
914 for (i = 0; i < info->regions->len; i++)
918 region = &g_array_index (info->regions, GtkRegion, i);
919 gtk_widget_path_iter_add_region (path, pos,
920 g_quark_to_string (region->class_quark),
924 /* Set widget classes */
925 for (i = 0; i < info->style_classes->len; i++)
929 quark = g_array_index (info->style_classes, GQuark, i);
930 gtk_widget_path_iter_add_class (path, pos,
931 g_quark_to_string (quark));
938 style_data_lookup (GtkStyleContext *context)
940 GtkStyleContextPrivate *priv;
943 priv = context->priv;
946 /* Current data in use is cached, just return it */
950 g_assert (priv->widget != NULL || priv->widget_path != NULL);
952 info->data = g_hash_table_lookup (priv->style_data, info);
956 style_data_ref (info->data);
962 path = create_query_path (context);
964 info->data = style_data_new ();
965 g_hash_table_insert (priv->style_data,
966 style_info_copy (info),
967 style_data_ref (info->data));
969 build_properties (context, info->data, path, info->state_flags);
971 gtk_widget_path_free (path);
978 gtk_style_context_set_invalid (GtkStyleContext *context,
981 GtkStyleContextPrivate *priv;
983 priv = context->priv;
985 if (priv->invalid == invalid)
988 priv->invalid = invalid;
993 gtk_style_context_set_invalid (priv->parent, TRUE);
994 else if (GTK_IS_RESIZE_CONTAINER (priv->widget))
995 _gtk_container_queue_resize_handler (GTK_CONTAINER (priv->widget));
999 /* returns TRUE if someone called gtk_style_context_save() but hasn't
1000 * called gtk_style_context_restore() yet.
1001 * In those situations we don't invalidate the context when somebody
1002 * changes state/regions/classes.
1005 gtk_style_context_is_saved (GtkStyleContext *context)
1007 return context->priv->info->next != NULL;
1011 gtk_style_context_queue_invalidate_internal (GtkStyleContext *context,
1012 GtkCssChange change)
1014 GtkStyleContextPrivate *priv = context->priv;
1015 GtkStyleInfo *info = priv->info;
1017 if (gtk_style_context_is_saved (context))
1021 style_data_unref (info->data);
1027 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_STATE);
1028 /* XXX: We need to invalidate siblings here somehow */
1033 * gtk_style_context_new:
1035 * Creates a standalone #GtkStyleContext, this style context
1036 * won't be attached to any widget, so you may want
1037 * to call gtk_style_context_set_path() yourself.
1040 * This function is only useful when using the theming layer
1041 * separated from GTK+, if you are using #GtkStyleContext to
1042 * theme #GtkWidget<!-- -->s, use gtk_widget_get_style_context()
1043 * in order to get a style context ready to theme the widget.
1046 * Returns: A newly created #GtkStyleContext.
1049 gtk_style_context_new (void)
1051 return g_object_new (GTK_TYPE_STYLE_CONTEXT, NULL);
1055 _gtk_style_context_set_widget (GtkStyleContext *context,
1058 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1059 g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget));
1061 context->priv->widget = widget;
1063 _gtk_style_context_stop_animations (context);
1065 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY_SELF);
1069 * gtk_style_context_add_provider:
1070 * @context: a #GtkStyleContext
1071 * @provider: a #GtkStyleProvider
1072 * @priority: the priority of the style provider. The lower
1073 * it is, the earlier it will be used in the style
1074 * construction. Typically this will be in the range
1075 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1076 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1078 * Adds a style provider to @context, to be used in style construction.
1080 * <note><para>If both priorities are the same, A #GtkStyleProvider
1081 * added through this function takes precedence over another added
1082 * through gtk_style_context_add_provider_for_screen().</para></note>
1087 gtk_style_context_add_provider (GtkStyleContext *context,
1088 GtkStyleProvider *provider,
1091 GtkStyleContextPrivate *priv;
1093 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1094 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1096 priv = context->priv;
1098 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
1100 GtkStyleCascade *new_cascade;
1102 new_cascade = _gtk_style_cascade_new ();
1103 _gtk_style_cascade_set_parent (new_cascade, priv->cascade);
1104 _gtk_style_cascade_add_provider (new_cascade, provider, priority);
1105 gtk_style_context_set_cascade (context, new_cascade);
1106 g_object_unref (new_cascade);
1110 _gtk_style_cascade_add_provider (priv->cascade, provider, priority);
1115 * gtk_style_context_remove_provider:
1116 * @context: a #GtkStyleContext
1117 * @provider: a #GtkStyleProvider
1119 * Removes @provider from the style providers list in @context.
1124 gtk_style_context_remove_provider (GtkStyleContext *context,
1125 GtkStyleProvider *provider)
1127 GtkStyleContextPrivate *priv;
1129 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1130 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1132 priv = context->priv;
1134 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
1137 _gtk_style_cascade_remove_provider (priv->cascade, provider);
1141 * gtk_style_context_reset_widgets:
1142 * @screen: a #GdkScreen
1144 * This function recomputes the styles for all widgets under a particular
1145 * #GdkScreen. This is useful when some global parameter has changed that
1146 * affects the appearance of all widgets, because when a widget gets a new
1147 * style, it will both redraw and recompute any cached information about
1148 * its appearance. As an example, it is used when the color scheme changes
1149 * in the related #GtkSettings object.
1154 gtk_style_context_reset_widgets (GdkScreen *screen)
1156 GList *list, *toplevels;
1158 _gtk_icon_set_invalidate_caches ();
1160 toplevels = gtk_window_list_toplevels ();
1161 g_list_foreach (toplevels, (GFunc) g_object_ref, NULL);
1163 for (list = toplevels; list; list = list->next)
1165 if (gtk_widget_get_screen (list->data) == screen)
1166 gtk_widget_reset_style (list->data);
1168 g_object_unref (list->data);
1171 g_list_free (toplevels);
1175 * gtk_style_context_add_provider_for_screen:
1176 * @screen: a #GdkScreen
1177 * @provider: a #GtkStyleProvider
1178 * @priority: the priority of the style provider. The lower
1179 * it is, the earlier it will be used in the style
1180 * construction. Typically this will be in the range
1181 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1182 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1184 * Adds a global style provider to @screen, which will be used
1185 * in style construction for all #GtkStyleContext<!-- -->s under
1188 * GTK+ uses this to make styling information from #GtkSettings
1191 * <note><para>If both priorities are the same, A #GtkStyleProvider
1192 * added through gtk_style_context_add_provider() takes precedence
1193 * over another added through this function.</para></note>
1198 gtk_style_context_add_provider_for_screen (GdkScreen *screen,
1199 GtkStyleProvider *provider,
1202 GtkStyleCascade *cascade;
1204 g_return_if_fail (GDK_IS_SCREEN (screen));
1205 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1207 cascade = _gtk_style_cascade_get_for_screen (screen);
1208 _gtk_style_cascade_add_provider (cascade, provider, priority);
1212 * gtk_style_context_remove_provider_for_screen:
1213 * @screen: a #GdkScreen
1214 * @provider: a #GtkStyleProvider
1216 * Removes @provider from the global style providers list in @screen.
1221 gtk_style_context_remove_provider_for_screen (GdkScreen *screen,
1222 GtkStyleProvider *provider)
1224 GtkStyleCascade *cascade;
1226 g_return_if_fail (GDK_IS_SCREEN (screen));
1227 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1229 cascade = _gtk_style_cascade_get_for_screen (screen);
1230 _gtk_style_cascade_remove_provider (cascade, provider);
1234 * gtk_style_context_get_section:
1235 * @context: a #GtkStyleContext
1236 * @property: style property name
1238 * Queries the location in the CSS where @property was defined for the
1239 * current @context. Note that the state to be queried is taken from
1240 * gtk_style_context_get_state().
1242 * If the location is not available, %NULL will be returned. The
1243 * location might not be available for various reasons, such as the
1244 * property being overridden, @property not naming a supported CSS
1245 * property or tracking of definitions being disabled for performance
1248 * Shorthand CSS properties cannot be queried for a location and will
1249 * always return %NULL.
1251 * Returns: %NULL or the section where value was defined
1254 gtk_style_context_get_section (GtkStyleContext *context,
1255 const gchar *property)
1257 GtkStyleContextPrivate *priv;
1258 GtkStyleProperty *prop;
1261 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1262 g_return_val_if_fail (property != NULL, NULL);
1264 priv = context->priv;
1265 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
1267 prop = _gtk_style_property_lookup (property);
1268 if (!GTK_IS_CSS_STYLE_PROPERTY (prop))
1271 data = style_data_lookup (context);
1272 return _gtk_css_computed_values_get_section (data->store, _gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (prop)));
1275 static GtkCssValue *
1276 gtk_style_context_query_func (guint id,
1279 return _gtk_css_computed_values_get_value (values, id);
1283 * gtk_style_context_get_property:
1284 * @context: a #GtkStyleContext
1285 * @property: style property name
1286 * @state: state to retrieve the property value for
1287 * @value: (out) (transfer full): return location for the style property value
1289 * Gets a style property from @context for the given state.
1291 * When @value is no longer needed, g_value_unset() must be called
1292 * to free any allocated memory.
1297 gtk_style_context_get_property (GtkStyleContext *context,
1298 const gchar *property,
1299 GtkStateFlags state,
1302 GtkStyleContextPrivate *priv;
1303 GtkStyleProperty *prop;
1306 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1307 g_return_if_fail (property != NULL);
1308 g_return_if_fail (value != NULL);
1310 priv = context->priv;
1311 g_return_if_fail (priv->widget != NULL || priv->widget_path != NULL);
1313 prop = _gtk_style_property_lookup (property);
1316 g_warning ("Style property \"%s\" is not registered", property);
1319 if (_gtk_style_property_get_value_type (prop) == G_TYPE_NONE)
1321 g_warning ("Style property \"%s\" is not gettable", property);
1325 gtk_style_context_save (context);
1326 gtk_style_context_set_state (context, state);
1327 data = style_data_lookup (context);
1328 _gtk_style_property_query (prop, value, gtk_style_context_query_func, data->store);
1329 gtk_style_context_restore (context);
1333 * gtk_style_context_get_valist:
1334 * @context: a #GtkStyleContext
1335 * @state: state to retrieve the property values for
1336 * @args: va_list of property name/return location pairs, followed by %NULL
1338 * Retrieves several style property values from @context for a given state.
1343 gtk_style_context_get_valist (GtkStyleContext *context,
1344 GtkStateFlags state,
1347 const gchar *property_name;
1349 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1351 property_name = va_arg (args, const gchar *);
1353 while (property_name)
1355 gchar *error = NULL;
1356 GValue value = G_VALUE_INIT;
1358 gtk_style_context_get_property (context,
1363 G_VALUE_LCOPY (&value, args, 0, &error);
1364 g_value_unset (&value);
1368 g_warning ("Could not get style property \"%s\": %s", property_name, error);
1373 property_name = va_arg (args, const gchar *);
1378 * gtk_style_context_get:
1379 * @context: a #GtkStyleContext
1380 * @state: state to retrieve the property values for
1381 * @...: property name /return value pairs, followed by %NULL
1383 * Retrieves several style property values from @context for a
1389 gtk_style_context_get (GtkStyleContext *context,
1390 GtkStateFlags state,
1395 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1397 va_start (args, state);
1398 gtk_style_context_get_valist (context, state, args);
1403 * gtk_style_context_set_state:
1404 * @context: a #GtkStyleContext
1405 * @flags: state to represent
1407 * Sets the state to be used when rendering with any
1408 * of the gtk_render_*() functions.
1413 gtk_style_context_set_state (GtkStyleContext *context,
1414 GtkStateFlags flags)
1416 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1418 context->priv->info->state_flags = flags;
1420 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_STATE);
1424 * gtk_style_context_get_state:
1425 * @context: a #GtkStyleContext
1427 * Returns the state used when rendering.
1429 * Returns: the state flags
1434 gtk_style_context_get_state (GtkStyleContext *context)
1436 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
1438 return context->priv->info->state_flags;
1442 * gtk_style_context_state_is_running:
1443 * @context: a #GtkStyleContext
1444 * @state: a widget state
1445 * @progress: (out): return location for the transition progress
1447 * Returns %TRUE if there is a transition animation running for the
1448 * current region (see gtk_style_context_push_animatable_region()).
1450 * If @progress is not %NULL, the animation progress will be returned
1451 * there, 0.0 means the state is closest to being unset, while 1.0 means
1452 * it's closest to being set. This means transition animation will
1453 * run from 0 to 1 when @state is being set and from 1 to 0 when
1456 * Returns: %TRUE if there is a running transition animation for @state.
1460 * Deprecated: 3.6: This function always returns %FALSE
1463 gtk_style_context_state_is_running (GtkStyleContext *context,
1467 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1473 * gtk_style_context_set_path:
1474 * @context: a #GtkStyleContext
1475 * @path: a #GtkWidgetPath
1477 * Sets the #GtkWidgetPath used for style matching. As a
1478 * consequence, the style will be regenerated to match
1479 * the new given path.
1481 * If you are using a #GtkStyleContext returned from
1482 * gtk_widget_get_style_context(), you do not need to call
1488 gtk_style_context_set_path (GtkStyleContext *context,
1489 GtkWidgetPath *path)
1491 GtkStyleContextPrivate *priv;
1493 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1494 g_return_if_fail (path != NULL);
1496 priv = context->priv;
1497 g_return_if_fail (priv->widget == NULL);
1499 if (priv->widget_path)
1501 gtk_widget_path_free (priv->widget_path);
1502 priv->widget_path = NULL;
1506 priv->widget_path = gtk_widget_path_copy (path);
1508 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY);
1512 * gtk_style_context_get_path:
1513 * @context: a #GtkStyleContext
1515 * Returns the widget path used for style matching.
1517 * Returns: (transfer none): A #GtkWidgetPath
1521 const GtkWidgetPath *
1522 gtk_style_context_get_path (GtkStyleContext *context)
1524 GtkStyleContextPrivate *priv;
1526 priv = context->priv;
1528 return gtk_widget_get_path (priv->widget);
1530 return priv->widget_path;
1534 * gtk_style_context_set_parent:
1535 * @context: a #GtkStyleContext
1536 * @parent: (allow-none): the new parent or %NULL
1538 * Sets the parent style context for @context. The parent style
1539 * context is used to implement
1540 * <ulink url="http://www.w3.org/TR/css3-cascade/#inheritance">inheritance</ulink>
1543 * If you are using a #GtkStyleContext returned from
1544 * gtk_widget_get_style_context(), the parent will be set for you.
1549 gtk_style_context_set_parent (GtkStyleContext *context,
1550 GtkStyleContext *parent)
1552 GtkStyleContextPrivate *priv;
1554 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1555 g_return_if_fail (parent == NULL || GTK_IS_STYLE_CONTEXT (parent));
1557 priv = context->priv;
1559 if (priv->parent == parent)
1564 parent->priv->children = g_slist_prepend (parent->priv->children, context);
1565 g_object_ref (parent);
1567 gtk_style_context_set_invalid (parent, TRUE);
1572 priv->parent->priv->children = g_slist_remove (priv->parent->priv->children, context);
1573 g_object_unref (priv->parent);
1576 priv->parent = parent;
1578 g_object_notify (G_OBJECT (context), "parent");
1579 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY_PARENT | GTK_CSS_CHANGE_ANY_SIBLING);
1583 * gtk_style_context_get_parent:
1584 * @context: a #GtkStyleContext
1586 * Gets the parent context set via gtk_style_context_set_parent().
1587 * See that function for details.
1589 * Returns: (transfer none): the parent context or %NULL
1594 gtk_style_context_get_parent (GtkStyleContext *context)
1596 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1598 return context->priv->parent;
1602 * gtk_style_context_save:
1603 * @context: a #GtkStyleContext
1605 * Saves the @context state, so all modifications done through
1606 * gtk_style_context_add_class(), gtk_style_context_remove_class(),
1607 * gtk_style_context_add_region(), gtk_style_context_remove_region()
1608 * or gtk_style_context_set_junction_sides() can be reverted in one
1609 * go through gtk_style_context_restore().
1614 gtk_style_context_save (GtkStyleContext *context)
1616 GtkStyleContextPrivate *priv;
1618 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1620 priv = context->priv;
1622 priv->info = style_info_copy (priv->info);
1626 * gtk_style_context_restore:
1627 * @context: a #GtkStyleContext
1629 * Restores @context state to a previous stage.
1630 * See gtk_style_context_save().
1635 gtk_style_context_restore (GtkStyleContext *context)
1637 GtkStyleContextPrivate *priv;
1639 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1641 priv = context->priv;
1643 priv->info = style_info_pop (priv->info);
1647 g_warning ("Unpaired gtk_style_context_restore() call");
1649 /* Create default region */
1650 priv->info = style_info_new ();
1655 style_class_find (GArray *array,
1660 gboolean found = FALSE;
1666 if (!array || array->len == 0)
1670 max = array->len - 1;
1676 mid = (min + max) / 2;
1677 item = g_array_index (array, GQuark, mid);
1679 if (class_quark == item)
1684 else if (class_quark > item)
1685 min = pos = mid + 1;
1692 while (!found && min <= max);
1701 region_find (GArray *array,
1706 gboolean found = FALSE;
1712 if (!array || array->len == 0)
1716 max = array->len - 1;
1722 mid = (min + max) / 2;
1723 region = &g_array_index (array, GtkRegion, mid);
1725 if (region->class_quark == class_quark)
1730 else if (region->class_quark > class_quark)
1731 min = pos = mid + 1;
1738 while (!found && min <= max);
1747 * gtk_style_context_add_class:
1748 * @context: a #GtkStyleContext
1749 * @class_name: class name to use in styling
1751 * Adds a style class to @context, so posterior calls to
1752 * gtk_style_context_get() or any of the gtk_render_*()
1753 * functions will make use of this new class for styling.
1755 * In the CSS file format, a #GtkEntry defining an "entry"
1756 * class, would be matched by:
1759 * GtkEntry.entry { ... }
1762 * While any widget defining an "entry" class would be
1771 gtk_style_context_add_class (GtkStyleContext *context,
1772 const gchar *class_name)
1774 GtkStyleContextPrivate *priv;
1779 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1780 g_return_if_fail (class_name != NULL);
1782 priv = context->priv;
1783 class_quark = g_quark_from_string (class_name);
1787 if (!style_class_find (info->style_classes, class_quark, &position))
1789 g_array_insert_val (info->style_classes, position, class_quark);
1791 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_CLASS);
1796 * gtk_style_context_remove_class:
1797 * @context: a #GtkStyleContext
1798 * @class_name: class name to remove
1800 * Removes @class_name from @context.
1805 gtk_style_context_remove_class (GtkStyleContext *context,
1806 const gchar *class_name)
1808 GtkStyleContextPrivate *priv;
1813 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1814 g_return_if_fail (class_name != NULL);
1816 class_quark = g_quark_try_string (class_name);
1821 priv = context->priv;
1825 if (style_class_find (info->style_classes, class_quark, &position))
1827 g_array_remove_index (info->style_classes, position);
1829 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_CLASS);
1834 * gtk_style_context_has_class:
1835 * @context: a #GtkStyleContext
1836 * @class_name: a class name
1838 * Returns %TRUE if @context currently has defined the
1841 * Returns: %TRUE if @context has @class_name defined
1846 gtk_style_context_has_class (GtkStyleContext *context,
1847 const gchar *class_name)
1849 GtkStyleContextPrivate *priv;
1853 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1854 g_return_val_if_fail (class_name != NULL, FALSE);
1856 class_quark = g_quark_try_string (class_name);
1861 priv = context->priv;
1865 if (style_class_find (info->style_classes, class_quark, NULL))
1872 * gtk_style_context_list_classes:
1873 * @context: a #GtkStyleContext
1875 * Returns the list of classes currently defined in @context.
1877 * Returns: (transfer container) (element-type utf8): a #GList of
1878 * strings with the currently defined classes. The contents
1879 * of the list are owned by GTK+, but you must free the list
1880 * itself with g_list_free() when you are done with it.
1885 gtk_style_context_list_classes (GtkStyleContext *context)
1887 GtkStyleContextPrivate *priv;
1889 GList *classes = NULL;
1892 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1894 priv = context->priv;
1898 for (i = 0; i < info->style_classes->len; i++)
1902 quark = g_array_index (info->style_classes, GQuark, i);
1903 classes = g_list_prepend (classes, (gchar *) g_quark_to_string (quark));
1910 * gtk_style_context_list_regions:
1911 * @context: a #GtkStyleContext
1913 * Returns the list of regions currently defined in @context.
1915 * Returns: (transfer container) (element-type utf8): a #GList of
1916 * strings with the currently defined regions. The contents
1917 * of the list are owned by GTK+, but you must free the list
1918 * itself with g_list_free() when you are done with it.
1923 gtk_style_context_list_regions (GtkStyleContext *context)
1925 GtkStyleContextPrivate *priv;
1927 GList *classes = NULL;
1930 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1932 priv = context->priv;
1936 for (i = 0; i < info->regions->len; i++)
1939 const gchar *class_name;
1941 region = &g_array_index (info->regions, GtkRegion, i);
1943 class_name = g_quark_to_string (region->class_quark);
1944 classes = g_list_prepend (classes, (gchar *) class_name);
1951 _gtk_style_context_check_region_name (const gchar *str)
1953 g_return_val_if_fail (str != NULL, FALSE);
1955 if (!g_ascii_islower (str[0]))
1961 !g_ascii_islower (*str))
1971 * gtk_style_context_add_region:
1972 * @context: a #GtkStyleContext
1973 * @region_name: region name to use in styling
1974 * @flags: flags that apply to the region
1976 * Adds a region to @context, so posterior calls to
1977 * gtk_style_context_get() or any of the gtk_render_*()
1978 * functions will make use of this new region for styling.
1980 * In the CSS file format, a #GtkTreeView defining a "row"
1981 * region, would be matched by:
1984 * GtkTreeView row { ... }
1987 * Pseudo-classes are used for matching @flags, so the two
1990 * GtkTreeView row:nth-child(even) { ... }
1991 * GtkTreeView row:nth-child(odd) { ... }
1994 * would apply to even and odd rows, respectively.
1996 * <note><para>Region names must only contain lowercase letters
1997 * and '-', starting always with a lowercase letter.</para></note>
2002 gtk_style_context_add_region (GtkStyleContext *context,
2003 const gchar *region_name,
2004 GtkRegionFlags flags)
2006 GtkStyleContextPrivate *priv;
2008 GQuark region_quark;
2011 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2012 g_return_if_fail (region_name != NULL);
2013 g_return_if_fail (_gtk_style_context_check_region_name (region_name));
2015 priv = context->priv;
2016 region_quark = g_quark_from_string (region_name);
2020 if (!region_find (info->regions, region_quark, &position))
2024 region.class_quark = region_quark;
2025 region.flags = flags;
2027 g_array_insert_val (info->regions, position, region);
2029 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_REGION);
2034 * gtk_style_context_remove_region:
2035 * @context: a #GtkStyleContext
2036 * @region_name: region name to unset
2038 * Removes a region from @context.
2043 gtk_style_context_remove_region (GtkStyleContext *context,
2044 const gchar *region_name)
2046 GtkStyleContextPrivate *priv;
2048 GQuark region_quark;
2051 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2052 g_return_if_fail (region_name != NULL);
2054 region_quark = g_quark_try_string (region_name);
2059 priv = context->priv;
2063 if (region_find (info->regions, region_quark, &position))
2065 g_array_remove_index (info->regions, position);
2067 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_REGION);
2072 * gtk_style_context_has_region:
2073 * @context: a #GtkStyleContext
2074 * @region_name: a region name
2075 * @flags_return: (out) (allow-none): return location for region flags
2077 * Returns %TRUE if @context has the region defined.
2078 * If @flags_return is not %NULL, it is set to the flags
2079 * affecting the region.
2081 * Returns: %TRUE if region is defined
2086 gtk_style_context_has_region (GtkStyleContext *context,
2087 const gchar *region_name,
2088 GtkRegionFlags *flags_return)
2090 GtkStyleContextPrivate *priv;
2092 GQuark region_quark;
2095 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2096 g_return_val_if_fail (region_name != NULL, FALSE);
2101 region_quark = g_quark_try_string (region_name);
2106 priv = context->priv;
2110 if (region_find (info->regions, region_quark, &position))
2116 region = &g_array_index (info->regions, GtkRegion, position);
2117 *flags_return = region->flags;
2126 style_property_values_cmp (gconstpointer bsearch_node1,
2127 gconstpointer bsearch_node2)
2129 const PropertyValue *val1 = bsearch_node1;
2130 const PropertyValue *val2 = bsearch_node2;
2132 if (val1->widget_type != val2->widget_type)
2133 return val1->widget_type < val2->widget_type ? -1 : 1;
2135 if (val1->pspec != val2->pspec)
2136 return val1->pspec < val2->pspec ? -1 : 1;
2138 if (val1->state != val2->state)
2139 return val1->state < val2->state ? -1 : 1;
2145 _gtk_style_context_peek_property (GtkStyleContext *context,
2148 StyleData *data = style_data_lookup (context);
2150 return _gtk_css_computed_values_get_value (data->store, property_id);
2154 _gtk_style_context_get_number (GtkStyleContext *context,
2156 double one_hundred_percent)
2160 value = _gtk_style_context_peek_property (context, property_id);
2161 return _gtk_css_number_value_get (value, one_hundred_percent);
2165 _gtk_style_context_peek_style_property (GtkStyleContext *context,
2167 GtkStateFlags state,
2170 GtkStyleContextPrivate *priv;
2171 PropertyValue *pcache, key = { 0 };
2175 priv = context->priv;
2177 gtk_style_context_save (context);
2178 gtk_style_context_set_state (context, state);
2179 data = style_data_lookup (context);
2180 gtk_style_context_restore (context);
2182 key.widget_type = widget_type;
2186 /* need value cache array */
2187 if (!data->property_cache)
2188 data->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
2191 pcache = bsearch (&key,
2192 data->property_cache->data, data->property_cache->len,
2193 sizeof (PropertyValue), style_property_values_cmp);
2195 return &pcache->value;
2199 while (i < data->property_cache->len &&
2200 style_property_values_cmp (&key, &g_array_index (data->property_cache, PropertyValue, i)) >= 0)
2203 g_array_insert_val (data->property_cache, i, key);
2204 pcache = &g_array_index (data->property_cache, PropertyValue, i);
2206 /* cache miss, initialize value type, then set contents */
2207 g_param_spec_ref (pcache->pspec);
2208 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2210 if (priv->widget || priv->widget_path)
2212 GtkWidgetPath *widget_path = priv->widget ? _gtk_widget_create_path (priv->widget) : priv->widget_path;
2214 if (gtk_style_provider_get_style_property (GTK_STYLE_PROVIDER (priv->cascade),
2216 state, pspec, &pcache->value))
2218 /* Resolve symbolic colors to GdkColor/GdkRGBA */
2219 if (G_VALUE_TYPE (&pcache->value) == GTK_TYPE_SYMBOLIC_COLOR)
2221 GtkSymbolicColor *color;
2224 color = g_value_dup_boxed (&pcache->value);
2226 g_value_unset (&pcache->value);
2228 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2229 g_value_init (&pcache->value, GDK_TYPE_RGBA);
2231 g_value_init (&pcache->value, GDK_TYPE_COLOR);
2233 if (_gtk_style_context_resolve_color (context, color, &rgba))
2235 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2236 g_value_set_boxed (&pcache->value, &rgba);
2241 rgb.red = rgba.red * 65535. + 0.5;
2242 rgb.green = rgba.green * 65535. + 0.5;
2243 rgb.blue = rgba.blue * 65535. + 0.5;
2245 g_value_set_boxed (&pcache->value, &rgb);
2249 g_param_value_set_default (pspec, &pcache->value);
2251 gtk_symbolic_color_unref (color);
2255 gtk_widget_path_free (widget_path);
2257 return &pcache->value;
2261 gtk_widget_path_free (widget_path);
2264 /* not supplied by any provider, revert to default */
2265 g_param_value_set_default (pspec, &pcache->value);
2267 return &pcache->value;
2271 * gtk_style_context_get_style_property:
2272 * @context: a #GtkStyleContext
2273 * @property_name: the name of the widget style property
2274 * @value: Return location for the property value
2276 * Gets the value for a widget style property.
2278 * When @value is no longer needed, g_value_unset() must be called
2279 * to free any allocated memory.
2282 gtk_style_context_get_style_property (GtkStyleContext *context,
2283 const gchar *property_name,
2286 GtkStyleContextPrivate *priv;
2287 GtkWidgetClass *widget_class;
2288 GtkStateFlags state;
2290 const GValue *peek_value;
2293 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2294 g_return_if_fail (property_name != NULL);
2295 g_return_if_fail (value != NULL);
2297 priv = context->priv;
2301 widget_type = G_OBJECT_TYPE (priv->widget);
2305 if (!priv->widget_path)
2308 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2310 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2312 g_warning ("%s: can't get style properties for non-widget class `%s'",
2314 g_type_name (widget_type));
2319 widget_class = g_type_class_ref (widget_type);
2320 pspec = gtk_widget_class_find_style_property (widget_class, property_name);
2321 g_type_class_unref (widget_class);
2325 g_warning ("%s: widget class `%s' has no style property named `%s'",
2327 g_type_name (widget_type),
2332 state = gtk_style_context_get_state (context);
2333 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2336 if (G_VALUE_TYPE (value) == G_VALUE_TYPE (peek_value))
2337 g_value_copy (peek_value, value);
2338 else if (g_value_type_transformable (G_VALUE_TYPE (peek_value), G_VALUE_TYPE (value)))
2339 g_value_transform (peek_value, value);
2341 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
2343 G_VALUE_TYPE_NAME (peek_value),
2344 G_VALUE_TYPE_NAME (value));
2348 * gtk_style_context_get_style_valist:
2349 * @context: a #GtkStyleContext
2350 * @args: va_list of property name/return location pairs, followed by %NULL
2352 * Retrieves several widget style properties from @context according to the
2358 gtk_style_context_get_style_valist (GtkStyleContext *context,
2361 GtkStyleContextPrivate *priv;
2362 const gchar *prop_name;
2363 GtkStateFlags state;
2366 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2368 prop_name = va_arg (args, const gchar *);
2369 priv = context->priv;
2373 widget_type = G_OBJECT_TYPE (priv->widget);
2377 if (!priv->widget_path)
2380 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2382 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2384 g_warning ("%s: can't get style properties for non-widget class `%s'",
2386 g_type_name (widget_type));
2391 state = gtk_style_context_get_state (context);
2395 GtkWidgetClass *widget_class;
2397 const GValue *peek_value;
2400 widget_class = g_type_class_ref (widget_type);
2401 pspec = gtk_widget_class_find_style_property (widget_class, prop_name);
2402 g_type_class_unref (widget_class);
2406 g_warning ("%s: widget class `%s' has no style property named `%s'",
2408 g_type_name (widget_type),
2413 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2416 G_VALUE_LCOPY (peek_value, args, 0, &error);
2420 g_warning ("can't retrieve style property `%s' of type `%s': %s",
2422 G_VALUE_TYPE_NAME (peek_value),
2428 prop_name = va_arg (args, const gchar *);
2433 * gtk_style_context_get_style:
2434 * @context: a #GtkStyleContext
2435 * @...: property name /return value pairs, followed by %NULL
2437 * Retrieves several widget style properties from @context according to the
2443 gtk_style_context_get_style (GtkStyleContext *context,
2448 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2450 va_start (args, context);
2451 gtk_style_context_get_style_valist (context, args);
2457 * gtk_style_context_lookup_icon_set:
2458 * @context: a #GtkStyleContext
2459 * @stock_id: an icon name
2461 * Looks up @stock_id in the icon factories associated to @context and
2462 * the default icon factory, returning an icon set if found, otherwise
2465 * Returns: (transfer none): The looked up %GtkIconSet, or %NULL
2468 gtk_style_context_lookup_icon_set (GtkStyleContext *context,
2469 const gchar *stock_id)
2471 GtkStyleContextPrivate *priv;
2473 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2474 g_return_val_if_fail (stock_id != NULL, NULL);
2476 priv = context->priv;
2477 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
2479 return gtk_icon_factory_lookup_default (stock_id);
2483 * gtk_style_context_set_screen:
2484 * @context: a #GtkStyleContext
2485 * @screen: a #GdkScreen
2487 * Attaches @context to the given screen.
2489 * The screen is used to add style information from 'global' style
2490 * providers, such as the screens #GtkSettings instance.
2492 * If you are using a #GtkStyleContext returned from
2493 * gtk_widget_get_style_context(), you do not need to
2494 * call this yourself.
2499 gtk_style_context_set_screen (GtkStyleContext *context,
2502 GtkStyleContextPrivate *priv;
2504 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2505 g_return_if_fail (GDK_IS_SCREEN (screen));
2507 priv = context->priv;
2508 if (priv->screen == screen)
2511 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
2513 gtk_style_context_set_cascade (context, _gtk_style_cascade_get_for_screen (screen));
2517 _gtk_style_cascade_set_parent (priv->cascade, _gtk_style_cascade_get_for_screen (screen));
2520 priv->screen = screen;
2522 g_object_notify (G_OBJECT (context), "screen");
2524 gtk_style_context_invalidate (context);
2528 * gtk_style_context_get_screen:
2529 * @context: a #GtkStyleContext
2531 * Returns the #GdkScreen to which @context is attached.
2533 * Returns: (transfer none): a #GdkScreen.
2536 gtk_style_context_get_screen (GtkStyleContext *context)
2538 GtkStyleContextPrivate *priv;
2540 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2542 priv = context->priv;
2543 return priv->screen;
2547 * gtk_style_context_set_direction:
2548 * @context: a #GtkStyleContext
2549 * @direction: the new direction.
2551 * Sets the reading direction for rendering purposes.
2553 * If you are using a #GtkStyleContext returned from
2554 * gtk_widget_get_style_context(), you do not need to
2555 * call this yourself.
2560 gtk_style_context_set_direction (GtkStyleContext *context,
2561 GtkTextDirection direction)
2563 GtkStyleContextPrivate *priv;
2565 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2567 priv = context->priv;
2568 priv->direction = direction;
2570 g_object_notify (G_OBJECT (context), "direction");
2574 * gtk_style_context_get_direction:
2575 * @context: a #GtkStyleContext
2577 * Returns the widget direction used for rendering.
2579 * Returns: the widget direction
2584 gtk_style_context_get_direction (GtkStyleContext *context)
2586 GtkStyleContextPrivate *priv;
2588 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), GTK_TEXT_DIR_LTR);
2590 priv = context->priv;
2591 return priv->direction;
2595 * gtk_style_context_set_junction_sides:
2596 * @context: a #GtkStyleContext
2597 * @sides: sides where rendered elements are visually connected to
2600 * Sets the sides where rendered elements (mostly through
2601 * gtk_render_frame()) will visually connect with other visual elements.
2603 * This is merely a hint that may or may not be honored
2604 * by theming engines.
2606 * Container widgets are expected to set junction hints as appropriate
2607 * for their children, so it should not normally be necessary to call
2608 * this function manually.
2613 gtk_style_context_set_junction_sides (GtkStyleContext *context,
2614 GtkJunctionSides sides)
2616 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2618 context->priv->info->junction_sides = sides;
2622 * gtk_style_context_get_junction_sides:
2623 * @context: a #GtkStyleContext
2625 * Returns the sides where rendered elements connect visually with others.
2627 * Returns: the junction sides
2632 gtk_style_context_get_junction_sides (GtkStyleContext *context)
2634 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
2636 return context->priv->info->junction_sides;
2639 static GtkSymbolicColor *
2640 gtk_style_context_color_lookup_func (gpointer contextp,
2643 GtkStyleContext *context = contextp;
2645 return _gtk_style_provider_private_get_color (GTK_STYLE_PROVIDER_PRIVATE (context->priv->cascade), name);
2649 _gtk_style_context_resolve_color_value (GtkStyleContext *context,
2650 GtkCssValue *current,
2653 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2654 g_return_val_if_fail (current != NULL, FALSE);
2655 g_return_val_if_fail (color != NULL, FALSE);
2657 return _gtk_symbolic_color_resolve_full ((GtkSymbolicColor *) color,
2659 gtk_style_context_color_lookup_func,
2665 _gtk_style_context_resolve_color (GtkStyleContext *context,
2666 GtkSymbolicColor *color,
2671 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2672 g_return_val_if_fail (color != NULL, FALSE);
2673 g_return_val_if_fail (result != NULL, FALSE);
2675 val = _gtk_symbolic_color_resolve_full (color,
2676 _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR),
2677 gtk_style_context_color_lookup_func,
2682 *result = *_gtk_css_rgba_value_get_rgba (val);
2683 _gtk_css_value_unref (val);
2688 * gtk_style_context_lookup_color:
2689 * @context: a #GtkStyleContext
2690 * @color_name: color name to lookup
2691 * @color: (out): Return location for the looked up color
2693 * Looks up and resolves a color name in the @context color map.
2695 * Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
2698 gtk_style_context_lookup_color (GtkStyleContext *context,
2699 const gchar *color_name,
2702 GtkSymbolicColor *sym_color;
2704 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2705 g_return_val_if_fail (color_name != NULL, FALSE);
2706 g_return_val_if_fail (color != NULL, FALSE);
2708 sym_color = gtk_style_context_color_lookup_func (context, color_name);
2709 if (sym_color == NULL)
2712 return _gtk_style_context_resolve_color (context, sym_color, color);
2716 * gtk_style_context_notify_state_change:
2717 * @context: a #GtkStyleContext
2718 * @window: a #GdkWindow
2719 * @region_id: (allow-none): animatable region to notify on, or %NULL.
2720 * See gtk_style_context_push_animatable_region()
2721 * @state: state to trigger transition for
2722 * @state_value: %TRUE if @state is the state we are changing to,
2723 * %FALSE if we are changing away from it
2725 * Notifies a state change on @context, so if the current style makes use
2726 * of transition animations, one will be started so all rendered elements
2727 * under @region_id are animated for state @state being set to value
2730 * The @window parameter is used in order to invalidate the rendered area
2731 * as the animation runs, so make sure it is the same window that is being
2732 * rendered on by the gtk_render_*() functions.
2734 * If @region_id is %NULL, all rendered elements using @context will be
2735 * affected by this state transition.
2737 * As a practical example, a #GtkButton notifying a state transition on
2738 * the prelight state:
2740 * gtk_style_context_notify_state_change (context,
2741 * gtk_widget_get_window (widget),
2743 * GTK_STATE_PRELIGHT,
2744 * button->in_button);
2747 * Can be handled in the CSS file like this:
2750 * background-color: #f00
2754 * background-color: #fff;
2755 * transition: 200ms linear
2759 * This combination will animate the button background from red to white
2760 * if a pointer enters the button, and back to red if the pointer leaves
2763 * Note that @state is used when finding the transition parameters, which
2764 * is why the style places the transition under the :hover pseudo-class.
2768 * Deprecated: 3.6: This function does nothing.
2771 gtk_style_context_notify_state_change (GtkStyleContext *context,
2775 gboolean state_value)
2777 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2778 g_return_if_fail (GDK_IS_WINDOW (window));
2779 g_return_if_fail (state > GTK_STATE_NORMAL && state <= GTK_STATE_FOCUSED);
2780 g_return_if_fail (context->priv->widget != NULL || context->priv->widget_path != NULL);
2784 * gtk_style_context_cancel_animations:
2785 * @context: a #GtkStyleContext
2786 * @region_id: (allow-none): animatable region to stop, or %NULL.
2787 * See gtk_style_context_push_animatable_region()
2789 * Stops all running animations for @region_id and all animatable
2790 * regions underneath.
2792 * A %NULL @region_id will stop all ongoing animations in @context,
2793 * when dealing with a #GtkStyleContext obtained through
2794 * gtk_widget_get_style_context(), this is normally done for you
2795 * in all circumstances you would expect all widget to be stopped,
2796 * so this should be only used in complex widgets with different
2797 * animatable regions.
2801 * Deprecated: 3.6: This function does nothing.
2804 gtk_style_context_cancel_animations (GtkStyleContext *context,
2807 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2811 * gtk_style_context_scroll_animations:
2812 * @context: a #GtkStyleContext
2813 * @window: a #GdkWindow used previously in
2814 * gtk_style_context_notify_state_change()
2815 * @dx: Amount to scroll in the X axis
2816 * @dy: Amount to scroll in the Y axis
2818 * This function is analogous to gdk_window_scroll(), and
2819 * should be called together with it so the invalidation
2820 * areas for any ongoing animation are scrolled together
2825 * Deprecated: 3.6: This function does nothing.
2828 gtk_style_context_scroll_animations (GtkStyleContext *context,
2833 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2834 g_return_if_fail (GDK_IS_WINDOW (window));
2838 * gtk_style_context_push_animatable_region:
2839 * @context: a #GtkStyleContext
2840 * @region_id: unique identifier for the animatable region
2842 * Pushes an animatable region, so all further gtk_render_*() calls between
2843 * this call and the following gtk_style_context_pop_animatable_region()
2844 * will potentially show transition animations for this region if
2845 * gtk_style_context_notify_state_change() is called for a given state,
2846 * and the current theme/style defines transition animations for state
2849 * The @region_id used must be unique in @context so the theming engine
2850 * can uniquely identify rendered elements subject to a state transition.
2854 * Deprecated: 3.6: This function does nothing.
2857 gtk_style_context_push_animatable_region (GtkStyleContext *context,
2860 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2861 g_return_if_fail (region_id != NULL);
2865 * gtk_style_context_pop_animatable_region:
2866 * @context: a #GtkStyleContext
2868 * Pops an animatable region from @context.
2869 * See gtk_style_context_push_animatable_region().
2873 * Deprecated: 3.6: This function does nothing.
2876 gtk_style_context_pop_animatable_region (GtkStyleContext *context)
2878 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2882 gtk_style_context_clear_cache (GtkStyleContext *context)
2884 GtkStyleContextPrivate *priv;
2887 priv = context->priv;
2889 for (info = priv->info; info; info = info->next)
2893 style_data_unref (info->data);
2897 g_hash_table_remove_all (priv->style_data);
2901 gtk_style_context_do_invalidate (GtkStyleContext *context)
2903 GtkStyleContextPrivate *priv;
2905 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2907 priv = context->priv;
2909 /* Avoid reentrancy */
2910 if (priv->invalidating_context)
2913 priv->invalidating_context = TRUE;
2915 g_signal_emit (context, signals[CHANGED], 0);
2917 priv->invalidating_context = FALSE;
2921 _gtk_style_context_stop_animations (GtkStyleContext *context)
2923 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2925 if (!gtk_style_context_is_animating (context))
2928 gtk_style_context_stop_animating (context);
2932 _gtk_style_context_validate (GtkStyleContext *context,
2934 GtkCssChange change)
2936 GtkStyleContextPrivate *priv;
2939 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2941 priv = context->priv;
2943 change |= priv->pending_changes;
2945 if (!priv->invalid && change == 0)
2948 priv->pending_changes = 0;
2949 gtk_style_context_set_invalid (context, FALSE);
2951 /* Try to avoid invalidating if we can */
2952 if (change & GTK_STYLE_CONTEXT_RADICAL_CHANGE)
2954 priv->relevant_changes = GTK_CSS_CHANGE_ANY;
2958 if (priv->relevant_changes == GTK_CSS_CHANGE_ANY)
2960 GtkWidgetPath *path;
2961 GtkCssMatcher matcher;
2963 path = create_query_path (context);
2964 _gtk_css_matcher_init (&matcher, path, priv->info->state_flags);
2966 priv->relevant_changes = _gtk_style_provider_private_get_change (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
2968 priv->relevant_changes &= ~GTK_STYLE_CONTEXT_RADICAL_CHANGE;
2970 gtk_widget_path_unref (path);
2974 if (priv->relevant_changes & change)
2976 GtkStyleInfo *info = priv->info;
2977 GtkCssComputedValues *old, *new;
2979 old = info->data ? g_object_ref (info->data->store) : NULL;
2981 if ((priv->relevant_changes & change) & ~GTK_STYLE_CONTEXT_CACHED_CHANGE)
2982 gtk_style_context_clear_cache (context);
2988 GtkBitmask *bitmask;
2990 new = style_data_lookup (context)->store;
2992 bitmask = _gtk_css_computed_values_get_difference (new, old);
2993 if (!_gtk_bitmask_is_empty (bitmask))
2994 gtk_style_context_do_invalidate (context);
2996 _gtk_bitmask_free (bitmask);
2997 g_object_unref (old);
3000 gtk_style_context_do_invalidate (context);
3004 change = _gtk_css_change_for_child (change);
3005 for (list = priv->children; list; list = list->next)
3007 _gtk_style_context_validate (list->data, timestamp, change);
3012 _gtk_style_context_queue_invalidate (GtkStyleContext *context,
3013 GtkCssChange change)
3015 GtkStyleContextPrivate *priv;
3017 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3018 g_return_if_fail (change != 0);
3020 priv = context->priv;
3022 if (priv->widget == NULL && priv->widget_path == NULL)
3025 priv->pending_changes |= change;
3026 gtk_style_context_set_invalid (context, TRUE);
3030 * gtk_style_context_invalidate:
3031 * @context: a #GtkStyleContext.
3033 * Invalidates @context style information, so it will be reconstructed
3036 * If you're using a #GtkStyleContext returned from
3037 * gtk_widget_get_style_context(), you do not need to
3038 * call this yourself.
3043 gtk_style_context_invalidate (GtkStyleContext *context)
3045 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3047 gtk_style_context_clear_cache (context);
3048 gtk_style_context_do_invalidate (context);
3052 * gtk_style_context_set_background:
3053 * @context: a #GtkStyleContext
3054 * @window: a #GdkWindow
3056 * Sets the background of @window to the background pattern or
3057 * color specified in @context for its current state.
3062 gtk_style_context_set_background (GtkStyleContext *context,
3065 GtkStateFlags state;
3066 cairo_pattern_t *pattern;
3069 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3070 g_return_if_fail (GDK_IS_WINDOW (window));
3072 state = gtk_style_context_get_state (context);
3073 gtk_style_context_get (context, state,
3074 "background-image", &pattern,
3078 gdk_window_set_background_pattern (window, pattern);
3079 cairo_pattern_destroy (pattern);
3083 gtk_style_context_get (context, state,
3084 "background-color", &color,
3088 gdk_window_set_background_rgba (window, color);
3089 gdk_rgba_free (color);
3094 * gtk_style_context_get_color:
3095 * @context: a #GtkStyleContext
3096 * @state: state to retrieve the color for
3097 * @color: (out): return value for the foreground color
3099 * Gets the foreground color for a given state.
3104 gtk_style_context_get_color (GtkStyleContext *context,
3105 GtkStateFlags state,
3110 g_return_if_fail (color != NULL);
3111 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3113 gtk_style_context_get (context,
3123 * gtk_style_context_get_background_color:
3124 * @context: a #GtkStyleContext
3125 * @state: state to retrieve the color for
3126 * @color: (out): return value for the background color
3128 * Gets the background color for a given state.
3133 gtk_style_context_get_background_color (GtkStyleContext *context,
3134 GtkStateFlags state,
3139 g_return_if_fail (color != NULL);
3140 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3142 gtk_style_context_get (context,
3144 "background-color", &c,
3152 * gtk_style_context_get_border_color:
3153 * @context: a #GtkStyleContext
3154 * @state: state to retrieve the color for
3155 * @color: (out): return value for the border color
3157 * Gets the border color for a given state.
3162 gtk_style_context_get_border_color (GtkStyleContext *context,
3163 GtkStateFlags state,
3168 g_return_if_fail (color != NULL);
3169 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3171 gtk_style_context_get (context,
3181 * gtk_style_context_get_border:
3182 * @context: a #GtkStyleContext
3183 * @state: state to retrieve the border for
3184 * @border: (out): return value for the border settings
3186 * Gets the border for a given state as a #GtkBorder.
3187 * See %GTK_STYLE_PROPERTY_BORDER_WIDTH.
3192 gtk_style_context_get_border (GtkStyleContext *context,
3193 GtkStateFlags state,
3196 int top, left, bottom, right;
3198 g_return_if_fail (border != NULL);
3199 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3201 gtk_style_context_get (context,
3203 "border-top-width", &top,
3204 "border-left-width", &left,
3205 "border-bottom-width", &bottom,
3206 "border-right-width", &right,
3210 border->left = left;
3211 border->bottom = bottom;
3212 border->right = right;
3216 * gtk_style_context_get_padding:
3217 * @context: a #GtkStyleContext
3218 * @state: state to retrieve the padding for
3219 * @padding: (out): return value for the padding settings
3221 * Gets the padding for a given state as a #GtkBorder.
3222 * See %GTK_STYLE_PROPERTY_PADDING.
3227 gtk_style_context_get_padding (GtkStyleContext *context,
3228 GtkStateFlags state,
3231 int top, left, bottom, right;
3233 g_return_if_fail (padding != NULL);
3234 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3236 gtk_style_context_get (context,
3238 "padding-top", &top,
3239 "padding-left", &left,
3240 "padding-bottom", &bottom,
3241 "padding-right", &right,
3245 padding->left = left;
3246 padding->bottom = bottom;
3247 padding->right = right;
3251 * gtk_style_context_get_margin:
3252 * @context: a #GtkStyleContext
3253 * @state: state to retrieve the border for
3254 * @margin: (out): return value for the margin settings
3256 * Gets the margin for a given state as a #GtkBorder.
3257 * See %GTK_STYLE_PROPERTY_MARGIN.
3262 gtk_style_context_get_margin (GtkStyleContext *context,
3263 GtkStateFlags state,
3266 int top, left, bottom, right;
3268 g_return_if_fail (margin != NULL);
3269 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3271 gtk_style_context_get (context,
3274 "margin-left", &left,
3275 "margin-bottom", &bottom,
3276 "margin-right", &right,
3280 margin->left = left;
3281 margin->bottom = bottom;
3282 margin->right = right;
3286 * gtk_style_context_get_font:
3287 * @context: a #GtkStyleContext
3288 * @state: state to retrieve the font for
3290 * Returns the font description for a given state. The returned
3291 * object is const and will remain valid until the
3292 * #GtkStyleContext::changed signal happens.
3294 * Returns: (transfer none): the #PangoFontDescription for the given
3295 * state. This object is owned by GTK+ and should not be
3300 const PangoFontDescription *
3301 gtk_style_context_get_font (GtkStyleContext *context,
3302 GtkStateFlags state)
3304 GtkStyleContextPrivate *priv;
3306 PangoFontDescription *description;
3308 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
3310 priv = context->priv;
3311 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
3313 gtk_style_context_save (context);
3314 gtk_style_context_set_state (context, state);
3315 data = style_data_lookup (context);
3316 gtk_style_context_restore (context);
3318 /* Yuck, fonts are created on-demand but we don't return a ref.
3319 * Do bad things to achieve this requirement */
3320 description = g_object_get_data (G_OBJECT (data->store), "font-cache-for-get_font");
3321 if (description == NULL)
3323 gtk_style_context_get (context, state, "font", &description, NULL);
3324 g_object_set_data_full (G_OBJECT (data->store),
3325 "font-cache-for-get_font",
3327 (GDestroyNotify) pango_font_description_free);
3333 get_cursor_color (GtkStyleContext *context,
3337 GdkColor *style_color;
3339 gtk_style_context_get_style (context,
3340 primary ? "cursor-color" : "secondary-cursor-color",
3346 color->red = style_color->red / 65535.0;
3347 color->green = style_color->green / 65535.0;
3348 color->blue = style_color->blue / 65535.0;
3351 gdk_color_free (style_color);
3355 gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, color);
3361 gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &bg);
3363 color->red = (color->red + bg.red) * 0.5;
3364 color->green = (color->green + bg.green) * 0.5;
3365 color->blue = (color->blue + bg.blue) * 0.5;
3371 _gtk_style_context_get_cursor_color (GtkStyleContext *context,
3372 GdkRGBA *primary_color,
3373 GdkRGBA *secondary_color)
3376 get_cursor_color (context, TRUE, primary_color);
3378 if (secondary_color)
3379 get_cursor_color (context, FALSE, secondary_color);
3386 * @context: a #GtkStyleContext
3388 * @x: X origin of the rectangle
3389 * @y: Y origin of the rectangle
3390 * @width: rectangle width
3391 * @height: rectangle height
3393 * Renders a checkmark (as in a #GtkCheckButton).
3395 * The %GTK_STATE_FLAG_ACTIVE state determines whether the check is
3396 * on or off, and %GTK_STATE_FLAG_INCONSISTENT determines whether it
3397 * should be marked as undefined.
3400 * <title>Typical checkmark rendering</title>
3401 * <inlinegraphic fileref="checks.png" format="PNG"/>
3407 gtk_render_check (GtkStyleContext *context,
3414 GtkThemingEngineClass *engine_class;
3415 GtkThemingEngine *engine;
3417 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3418 g_return_if_fail (cr != NULL);
3420 if (width <= 0 || height <= 0)
3423 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3424 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3429 _gtk_theming_engine_set_context (engine, context);
3430 engine_class->render_check (engine, cr,
3431 x, y, width, height);
3437 * gtk_render_option:
3438 * @context: a #GtkStyleContext
3440 * @x: X origin of the rectangle
3441 * @y: Y origin of the rectangle
3442 * @width: rectangle width
3443 * @height: rectangle height
3445 * Renders an option mark (as in a #GtkRadioButton), the %GTK_STATE_FLAG_ACTIVE
3446 * state will determine whether the option is on or off, and
3447 * %GTK_STATE_FLAG_INCONSISTENT whether it should be marked as undefined.
3450 * <title>Typical option mark rendering</title>
3451 * <inlinegraphic fileref="options.png" format="PNG"/>
3457 gtk_render_option (GtkStyleContext *context,
3464 GtkThemingEngineClass *engine_class;
3465 GtkThemingEngine *engine;
3467 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3468 g_return_if_fail (cr != NULL);
3470 if (width <= 0 || height <= 0)
3473 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3474 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3478 _gtk_theming_engine_set_context (engine, context);
3479 engine_class->render_option (engine, cr,
3480 x, y, width, height);
3487 * @context: a #GtkStyleContext
3489 * @angle: arrow angle from 0 to 2 * %G_PI, being 0 the arrow pointing to the north
3490 * @x: X origin of the render area
3491 * @y: Y origin of the render area
3492 * @size: square side for render area
3494 * Renders an arrow pointing to @angle.
3497 * <title>Typical arrow rendering at 0, 1&solidus;2 π, π and 3&solidus;2 π</title>
3498 * <inlinegraphic fileref="arrows.png" format="PNG"/>
3504 gtk_render_arrow (GtkStyleContext *context,
3511 GtkThemingEngineClass *engine_class;
3512 GtkThemingEngine *engine;
3514 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3515 g_return_if_fail (cr != NULL);
3520 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3521 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3525 gtk_style_context_save (context);
3526 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ARROW);
3528 _gtk_theming_engine_set_context (engine, context);
3529 engine_class->render_arrow (engine, cr,
3532 gtk_style_context_restore (context);
3537 * gtk_render_background:
3538 * @context: a #GtkStyleContext
3540 * @x: X origin of the rectangle
3541 * @y: Y origin of the rectangle
3542 * @width: rectangle width
3543 * @height: rectangle height
3545 * Renders the background of an element.
3548 * <title>Typical background rendering, showing the effect of
3549 * <parameter>background-image</parameter>,
3550 * <parameter>border-width</parameter> and
3551 * <parameter>border-radius</parameter></title>
3552 * <inlinegraphic fileref="background.png" format="PNG"/>
3558 gtk_render_background (GtkStyleContext *context,
3565 GtkThemingEngineClass *engine_class;
3566 GtkThemingEngine *engine;
3568 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3569 g_return_if_fail (cr != NULL);
3571 if (width <= 0 || height <= 0)
3574 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3575 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3579 _gtk_theming_engine_set_context (engine, context);
3580 engine_class->render_background (engine, cr, x, y, width, height);
3587 * @context: a #GtkStyleContext
3589 * @x: X origin of the rectangle
3590 * @y: Y origin of the rectangle
3591 * @width: rectangle width
3592 * @height: rectangle height
3594 * Renders a frame around the rectangle defined by @x, @y, @width, @height.
3597 * <title>Examples of frame rendering, showing the effect of
3598 * <parameter>border-image</parameter>,
3599 * <parameter>border-color</parameter>,
3600 * <parameter>border-width</parameter>,
3601 * <parameter>border-radius</parameter> and
3603 * <inlinegraphic fileref="frames.png" format="PNG"/>
3609 gtk_render_frame (GtkStyleContext *context,
3616 GtkThemingEngineClass *engine_class;
3617 GtkThemingEngine *engine;
3619 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3620 g_return_if_fail (cr != NULL);
3622 if (width <= 0 || height <= 0)
3625 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3626 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3630 _gtk_theming_engine_set_context (engine, context);
3631 engine_class->render_frame (engine, cr, x, y, width, height);
3637 * gtk_render_expander:
3638 * @context: a #GtkStyleContext
3640 * @x: X origin of the rectangle
3641 * @y: Y origin of the rectangle
3642 * @width: rectangle width
3643 * @height: rectangle height
3645 * Renders an expander (as used in #GtkTreeView and #GtkExpander) in the area
3646 * defined by @x, @y, @width, @height. The state %GTK_STATE_FLAG_ACTIVE
3647 * determines whether the expander is collapsed or expanded.
3650 * <title>Typical expander rendering</title>
3651 * <inlinegraphic fileref="expanders.png" format="PNG"/>
3657 gtk_render_expander (GtkStyleContext *context,
3664 GtkThemingEngineClass *engine_class;
3665 GtkThemingEngine *engine;
3667 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3668 g_return_if_fail (cr != NULL);
3670 if (width <= 0 || height <= 0)
3673 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3674 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3678 _gtk_theming_engine_set_context (engine, context);
3679 engine_class->render_expander (engine, cr, x, y, width, height);
3686 * @context: a #GtkStyleContext
3688 * @x: X origin of the rectangle
3689 * @y: Y origin of the rectangle
3690 * @width: rectangle width
3691 * @height: rectangle height
3693 * Renders a focus indicator on the rectangle determined by @x, @y, @width, @height.
3695 * <title>Typical focus rendering</title>
3696 * <inlinegraphic fileref="focus.png" format="PNG"/>
3702 gtk_render_focus (GtkStyleContext *context,
3709 GtkThemingEngineClass *engine_class;
3710 GtkThemingEngine *engine;
3712 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3713 g_return_if_fail (cr != NULL);
3715 if (width <= 0 || height <= 0)
3718 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3719 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3723 _gtk_theming_engine_set_context (engine, context);
3724 engine_class->render_focus (engine, cr, x, y, width, height);
3730 * gtk_render_layout:
3731 * @context: a #GtkStyleContext
3735 * @layout: the #PangoLayout to render
3737 * Renders @layout on the coordinates @x, @y
3742 gtk_render_layout (GtkStyleContext *context,
3746 PangoLayout *layout)
3748 GtkThemingEngineClass *engine_class;
3749 GtkThemingEngine *engine;
3750 PangoRectangle extents;
3752 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3753 g_return_if_fail (PANGO_IS_LAYOUT (layout));
3754 g_return_if_fail (cr != NULL);
3756 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3757 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3761 pango_layout_get_extents (layout, &extents, NULL);
3763 _gtk_theming_engine_set_context (engine, context);
3764 engine_class->render_layout (engine, cr, x, y, layout);
3771 * @context: a #GtkStyleContext
3773 * @x0: X coordinate for the origin of the line
3774 * @y0: Y coordinate for the origin of the line
3775 * @x1: X coordinate for the end of the line
3776 * @y1: Y coordinate for the end of the line
3778 * Renders a line from (x0, y0) to (x1, y1).
3783 gtk_render_line (GtkStyleContext *context,
3790 GtkThemingEngineClass *engine_class;
3791 GtkThemingEngine *engine;
3793 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3794 g_return_if_fail (cr != NULL);
3796 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3797 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3801 _gtk_theming_engine_set_context (engine, context);
3802 engine_class->render_line (engine, cr, x0, y0, x1, y1);
3808 * gtk_render_slider:
3809 * @context: a #GtkStyleContext
3811 * @x: X origin of the rectangle
3812 * @y: Y origin of the rectangle
3813 * @width: rectangle width
3814 * @height: rectangle height
3815 * @orientation: orientation of the slider
3817 * Renders a slider (as in #GtkScale) in the rectangle defined by @x, @y,
3818 * @width, @height. @orientation defines whether the slider is vertical
3822 * <title>Typical slider rendering</title>
3823 * <inlinegraphic fileref="sliders.png" format="PNG"/>
3829 gtk_render_slider (GtkStyleContext *context,
3835 GtkOrientation orientation)
3837 GtkThemingEngineClass *engine_class;
3838 GtkThemingEngine *engine;
3840 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3841 g_return_if_fail (cr != NULL);
3843 if (width <= 0 || height <= 0)
3846 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3847 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3851 _gtk_theming_engine_set_context (engine, context);
3852 engine_class->render_slider (engine, cr, x, y, width, height, orientation);
3858 * gtk_render_frame_gap:
3859 * @context: a #GtkStyleContext
3861 * @x: X origin of the rectangle
3862 * @y: Y origin of the rectangle
3863 * @width: rectangle width
3864 * @height: rectangle height
3865 * @gap_side: side where the gap is
3866 * @xy0_gap: initial coordinate (X or Y depending on @gap_side) for the gap
3867 * @xy1_gap: end coordinate (X or Y depending on @gap_side) for the gap
3869 * Renders a frame around the rectangle defined by (@x, @y, @width, @height),
3870 * leaving a gap on one side. @xy0_gap and @xy1_gap will mean X coordinates
3871 * for %GTK_POS_TOP and %GTK_POS_BOTTOM gap sides, and Y coordinates for
3872 * %GTK_POS_LEFT and %GTK_POS_RIGHT.
3875 * <title>Typical rendering of a frame with a gap</title>
3876 * <inlinegraphic fileref="frame-gap.png" format="PNG"/>
3882 gtk_render_frame_gap (GtkStyleContext *context,
3888 GtkPositionType gap_side,
3892 GtkThemingEngineClass *engine_class;
3893 GtkThemingEngine *engine;
3895 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3896 g_return_if_fail (cr != NULL);
3897 g_return_if_fail (xy0_gap <= xy1_gap);
3898 g_return_if_fail (xy0_gap >= 0);
3900 if (width <= 0 || height <= 0)
3903 if (gap_side == GTK_POS_LEFT ||
3904 gap_side == GTK_POS_RIGHT)
3905 g_return_if_fail (xy1_gap <= height);
3907 g_return_if_fail (xy1_gap <= width);
3909 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3910 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3914 _gtk_theming_engine_set_context (engine, context);
3915 engine_class->render_frame_gap (engine, cr,
3916 x, y, width, height, gap_side,
3923 * gtk_render_extension:
3924 * @context: a #GtkStyleContext
3926 * @x: X origin of the rectangle
3927 * @y: Y origin of the rectangle
3928 * @width: rectangle width
3929 * @height: rectangle height
3930 * @gap_side: side where the gap is
3932 * Renders a extension (as in a #GtkNotebook tab) in the rectangle
3933 * defined by @x, @y, @width, @height. The side where the extension
3934 * connects to is defined by @gap_side.
3937 * <title>Typical extension rendering</title>
3938 * <inlinegraphic fileref="extensions.png" format="PNG"/>
3944 gtk_render_extension (GtkStyleContext *context,
3950 GtkPositionType gap_side)
3952 GtkThemingEngineClass *engine_class;
3953 GtkThemingEngine *engine;
3955 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3956 g_return_if_fail (cr != NULL);
3958 if (width <= 0 || height <= 0)
3961 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3962 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3966 _gtk_theming_engine_set_context (engine, context);
3967 engine_class->render_extension (engine, cr, x, y, width, height, gap_side);
3973 * gtk_render_handle:
3974 * @context: a #GtkStyleContext
3976 * @x: X origin of the rectangle
3977 * @y: Y origin of the rectangle
3978 * @width: rectangle width
3979 * @height: rectangle height
3981 * Renders a handle (as in #GtkHandleBox, #GtkPaned and
3982 * #GtkWindow<!-- -->'s resize grip), in the rectangle
3983 * determined by @x, @y, @width, @height.
3986 * <title>Handles rendered for the paned and grip classes</title>
3987 * <inlinegraphic fileref="handles.png" format="PNG"/>
3993 gtk_render_handle (GtkStyleContext *context,
4000 GtkThemingEngineClass *engine_class;
4001 GtkThemingEngine *engine;
4003 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4004 g_return_if_fail (cr != NULL);
4006 if (width <= 0 || height <= 0)
4009 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4010 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4014 _gtk_theming_engine_set_context (engine, context);
4015 engine_class->render_handle (engine, cr, x, y, width, height);
4021 * gtk_render_activity:
4022 * @context: a #GtkStyleContext
4024 * @x: X origin of the rectangle
4025 * @y: Y origin of the rectangle
4026 * @width: rectangle width
4027 * @height: rectangle height
4029 * Renders an activity area (Such as in #GtkSpinner or the
4030 * fill line in #GtkRange), the state %GTK_STATE_FLAG_ACTIVE
4031 * determines whether there is activity going on.
4036 gtk_render_activity (GtkStyleContext *context,
4043 GtkThemingEngineClass *engine_class;
4044 GtkThemingEngine *engine;
4046 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4047 g_return_if_fail (cr != NULL);
4049 if (width <= 0 || height <= 0)
4052 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4053 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4057 _gtk_theming_engine_set_context (engine, context);
4058 engine_class->render_activity (engine, cr, x, y, width, height);
4064 * gtk_render_icon_pixbuf:
4065 * @context: a #GtkStyleContext
4066 * @source: the #GtkIconSource specifying the icon to render
4067 * @size: (type int): the size to render the icon at. A size of (GtkIconSize) -1
4068 * means render at the size of the source and don't scale.
4070 * Renders the icon specified by @source at the given @size, returning the result
4073 * Returns: (transfer full): a newly-created #GdkPixbuf containing the rendered icon
4078 gtk_render_icon_pixbuf (GtkStyleContext *context,
4079 const GtkIconSource *source,
4082 GtkThemingEngineClass *engine_class;
4083 GtkThemingEngine *engine;
4085 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
4086 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
4087 g_return_val_if_fail (source != NULL, NULL);
4089 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4090 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4092 _gtk_theming_engine_set_context (engine, context);
4093 return engine_class->render_icon_pixbuf (engine, source, size);
4098 * @context: a #GtkStyleContext
4100 * @pixbuf: a #GdkPixbuf containing the icon to draw
4101 * @x: X position for the @pixbuf
4102 * @y: Y position for the @pixbuf
4104 * Renders the icon in @pixbuf at the specified @x and @y coordinates.
4109 gtk_render_icon (GtkStyleContext *context,
4115 GtkThemingEngineClass *engine_class;
4116 GtkThemingEngine *engine;
4118 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4119 g_return_if_fail (cr != NULL);
4121 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4122 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4126 _gtk_theming_engine_set_context (engine, context);
4127 engine_class->render_icon (engine, cr, pixbuf, x, y);
4133 draw_insertion_cursor (GtkStyleContext *context,
4138 gboolean is_primary,
4139 PangoDirection direction,
4140 gboolean draw_arrow)
4143 GdkRGBA primary_color;
4144 GdkRGBA secondary_color;
4145 gfloat cursor_aspect_ratio;
4151 _gtk_style_context_get_cursor_color (context, &primary_color, &secondary_color);
4152 gdk_cairo_set_source_rgba (cr, is_primary ? &primary_color : &secondary_color);
4154 /* When changing the shape or size of the cursor here,
4155 * propagate the changes to gtktextview.c:text_window_invalidate_cursors().
4158 gtk_style_context_get_style (context,
4159 "cursor-aspect-ratio", &cursor_aspect_ratio,
4162 stem_width = height * cursor_aspect_ratio + 1;
4164 /* put (stem_width % 2) on the proper side of the cursor */
4165 if (direction == PANGO_DIRECTION_LTR)
4166 offset = stem_width / 2;
4168 offset = stem_width - stem_width / 2;
4170 cairo_rectangle (cr, x - offset, y, stem_width, height);
4178 arrow_width = stem_width + 1;
4180 if (direction == PANGO_DIRECTION_RTL)
4182 ax = x - offset - 1;
4183 ay = y + height - arrow_width * 2 - arrow_width + 1;
4185 cairo_move_to (cr, ax, ay + 1);
4186 cairo_line_to (cr, ax - arrow_width, ay + arrow_width);
4187 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4190 else if (direction == PANGO_DIRECTION_LTR)
4192 ax = x + stem_width - offset;
4193 ay = y + height - arrow_width * 2 - arrow_width + 1;
4195 cairo_move_to (cr, ax, ay + 1);
4196 cairo_line_to (cr, ax + arrow_width, ay + arrow_width);
4197 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4201 g_assert_not_reached();
4208 * gtk_render_insertion_cursor:
4209 * @context: a #GtkStyleContext
4213 * @layout: the #PangoLayout of the text
4214 * @index: the index in the #PangoLayout
4215 * @direction: the #PangoDirection of the text
4217 * Draws a text caret on @cr at the specified index of @layout.
4222 gtk_render_insertion_cursor (GtkStyleContext *context,
4226 PangoLayout *layout,
4228 PangoDirection direction)
4230 GtkStyleContextPrivate *priv;
4231 gboolean split_cursor;
4232 PangoRectangle strong_pos, weak_pos;
4233 PangoRectangle *cursor1, *cursor2;
4234 PangoDirection keymap_direction;
4235 PangoDirection direction2;
4237 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4238 g_return_if_fail (cr != NULL);
4239 g_return_if_fail (PANGO_IS_LAYOUT (layout));
4240 g_return_if_fail (index >= 0);
4242 priv = context->priv;
4244 g_object_get (gtk_settings_get_for_screen (priv->screen),
4245 "gtk-split-cursor", &split_cursor,
4248 keymap_direction = gdk_keymap_get_direction (gdk_keymap_get_for_display (gdk_screen_get_display (priv->screen)));
4250 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4252 direction2 = PANGO_DIRECTION_NEUTRAL;
4256 cursor1 = &strong_pos;
4258 if (strong_pos.x != weak_pos.x || strong_pos.y != weak_pos.y)
4260 direction2 = (direction == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
4261 cursor2 = &weak_pos;
4266 if (keymap_direction == direction)
4267 cursor1 = &strong_pos;
4269 cursor1 = &weak_pos;
4272 draw_insertion_cursor (context,
4274 x + PANGO_PIXELS (cursor1->x),
4275 y + PANGO_PIXELS (cursor1->y),
4276 PANGO_PIXELS (cursor1->height),
4279 direction2 != PANGO_DIRECTION_NEUTRAL);
4281 if (direction2 != PANGO_DIRECTION_NEUTRAL)
4283 draw_insertion_cursor (context,
4285 x + PANGO_PIXELS (cursor2->x),
4286 y + PANGO_PIXELS (cursor2->y),
4287 PANGO_PIXELS (cursor2->height),
4295 * gtk_draw_insertion_cursor:
4296 * @widget: a #GtkWidget
4297 * @cr: cairo context to draw to
4298 * @location: location where to draw the cursor (@location->width is ignored)
4299 * @is_primary: if the cursor should be the primary cursor color.
4300 * @direction: whether the cursor is left-to-right or
4301 * right-to-left. Should never be #GTK_TEXT_DIR_NONE
4302 * @draw_arrow: %TRUE to draw a directional arrow on the
4303 * cursor. Should be %FALSE unless the cursor is split.
4305 * Draws a text caret on @cr at @location. This is not a style function
4306 * but merely a convenience function for drawing the standard cursor shape.
4309 * Deprecated: 3.4: Use gtk_render_insertion_cursor() instead.
4312 gtk_draw_insertion_cursor (GtkWidget *widget,
4314 const GdkRectangle *location,
4315 gboolean is_primary,
4316 GtkTextDirection direction,
4317 gboolean draw_arrow)
4319 GtkStyleContext *context;
4321 g_return_if_fail (GTK_IS_WIDGET (widget));
4322 g_return_if_fail (cr != NULL);
4323 g_return_if_fail (location != NULL);
4324 g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
4326 context = gtk_widget_get_style_context (widget);
4328 draw_insertion_cursor (context, cr,
4329 location->x, location->y, location->height,
4331 (direction == GTK_TEXT_DIR_RTL) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR,
4335 static AtkAttributeSet *
4336 add_attribute (AtkAttributeSet *attributes,
4337 AtkTextAttribute attr,
4342 at = g_new (AtkAttribute, 1);
4343 at->name = g_strdup (atk_text_attribute_get_name (attr));
4344 at->value = g_strdup (value);
4346 return g_slist_prepend (attributes, at);
4350 * _gtk_style_context_get_attributes:
4351 * @attributes: a #AtkAttributeSet to add attributes to
4352 * @context: the #GtkStyleContext to get attributes from
4353 * @flags: the state to use with @context
4355 * Adds the foreground and background color from @context to
4356 * @attributes, after translating them to ATK attributes.
4358 * This is a convenience function that can be used in
4359 * implementing the #AtkText interface in widgets.
4361 * Returns: the modified #AtkAttributeSet
4364 _gtk_style_context_get_attributes (AtkAttributeSet *attributes,
4365 GtkStyleContext *context,
4366 GtkStateFlags flags)
4371 gtk_style_context_get_background_color (context, flags, &color);
4372 value = g_strdup_printf ("%u,%u,%u",
4373 (guint) ceil (color.red * 65536 - color.red),
4374 (guint) ceil (color.green * 65536 - color.green),
4375 (guint) ceil (color.blue * 65536 - color.blue));
4376 attributes = add_attribute (attributes, ATK_TEXT_ATTR_BG_COLOR, value);
4379 gtk_style_context_get_color (context, flags, &color);
4380 value = g_strdup_printf ("%u,%u,%u",
4381 (guint) ceil (color.red * 65536 - color.red),
4382 (guint) ceil (color.green * 65536 - color.green),
4383 (guint) ceil (color.blue * 65536 - color.blue));
4384 attributes = add_attribute (attributes, ATK_TEXT_ATTR_FG_COLOR, value);