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_set_data (GtkStyleInfo *info,
539 if (info->data == data)
543 style_data_ref (data);
546 style_data_unref (info->data);
552 style_info_free (GtkStyleInfo *info)
554 style_info_set_data (info, NULL);
555 g_array_free (info->style_classes, TRUE);
556 g_array_free (info->regions, TRUE);
557 g_slice_free (GtkStyleInfo, info);
560 static GtkStyleInfo *
561 style_info_pop (GtkStyleInfo *info)
563 GtkStyleInfo *next = info->next;
565 style_info_free (info);
570 static GtkStyleInfo *
571 style_info_copy (GtkStyleInfo *info)
575 copy = style_info_new ();
576 g_array_insert_vals (copy->style_classes, 0,
577 info->style_classes->data,
578 info->style_classes->len);
580 g_array_insert_vals (copy->regions, 0,
585 copy->junction_sides = info->junction_sides;
586 copy->state_flags = info->state_flags;
587 style_info_set_data (copy, info->data);
593 style_info_hash (gconstpointer elem)
595 const GtkStyleInfo *info;
600 for (i = 0; i < info->style_classes->len; i++)
602 hash += g_array_index (info->style_classes, GQuark, i);
606 for (i = 0; i < info->regions->len; i++)
610 region = &g_array_index (info->regions, GtkRegion, i);
611 hash += region->class_quark;
612 hash += region->flags;
616 return hash ^ info->state_flags;
620 style_info_equal (gconstpointer elem1,
623 const GtkStyleInfo *info1, *info2;
628 if (info1->state_flags != info2->state_flags)
631 if (info1->junction_sides != info2->junction_sides)
634 if (info1->style_classes->len != info2->style_classes->len)
637 if (memcmp (info1->style_classes->data,
638 info2->style_classes->data,
639 info1->style_classes->len * sizeof (GQuark)) != 0)
642 if (info1->regions->len != info2->regions->len)
645 if (memcmp (info1->regions->data,
646 info2->regions->data,
647 info1->regions->len * sizeof (GtkRegion)) != 0)
654 gtk_style_context_cascade_changed (GtkStyleCascade *cascade,
655 GtkStyleContext *context)
657 GtkStyleContextPrivate *priv = context->priv;
660 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_SOURCE);
662 gtk_style_context_invalidate (context);
666 gtk_style_context_set_cascade (GtkStyleContext *context,
667 GtkStyleCascade *cascade)
669 GtkStyleContextPrivate *priv;
671 priv = context->priv;
673 if (priv->cascade == cascade)
678 g_object_ref (cascade);
679 g_signal_connect (cascade,
680 "-gtk-private-changed",
681 G_CALLBACK (gtk_style_context_cascade_changed),
687 g_signal_handlers_disconnect_by_func (priv->cascade,
688 gtk_style_context_cascade_changed,
690 g_object_unref (priv->cascade);
693 priv->cascade = cascade;
696 gtk_style_context_cascade_changed (cascade, context);
700 gtk_style_context_init (GtkStyleContext *style_context)
702 GtkStyleContextPrivate *priv;
704 priv = style_context->priv = G_TYPE_INSTANCE_GET_PRIVATE (style_context,
705 GTK_TYPE_STYLE_CONTEXT,
706 GtkStyleContextPrivate);
708 priv->style_data = g_hash_table_new_full (style_info_hash,
710 (GDestroyNotify) style_info_free,
711 (GDestroyNotify) style_data_unref);
713 priv->direction = GTK_TEXT_DIR_LTR;
715 priv->screen = gdk_screen_get_default ();
716 priv->relevant_changes = GTK_CSS_CHANGE_ANY;
718 /* Create default info store */
719 priv->info = style_info_new ();
721 gtk_style_context_set_cascade (style_context,
722 _gtk_style_cascade_get_for_screen (priv->screen));
726 gtk_style_context_do_animations (gpointer unused)
728 GtkStyleContext *context;
730 for (context = _running_animations;
732 context = context->priv->animation_list_next)
734 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANIMATE);
741 gtk_style_context_is_animating (GtkStyleContext *context)
743 GtkStyleContextPrivate *priv = context->priv;
745 return priv->animation_list_prev != NULL
746 || _running_animations == context;
750 gtk_style_context_stop_animating (GtkStyleContext *context)
752 GtkStyleContextPrivate *priv = context->priv;
754 if (!gtk_style_context_is_animating (context))
757 if (priv->animation_list_prev == NULL)
759 _running_animations = priv->animation_list_next;
761 if (_running_animations == NULL)
763 /* we were the last animation */
764 g_source_remove (_running_animations_timer_id);
765 _running_animations_timer_id = 0;
769 priv->animation_list_prev->priv->animation_list_next = priv->animation_list_next;
771 if (priv->animation_list_next)
772 priv->animation_list_next->priv->animation_list_prev = priv->animation_list_prev;
774 priv->animation_list_next = NULL;
775 priv->animation_list_prev = NULL;
778 static void G_GNUC_UNUSED
779 gtk_style_context_start_animating (GtkStyleContext *context)
781 GtkStyleContextPrivate *priv = context->priv;
783 if (gtk_style_context_is_animating (context))
786 if (_running_animations == NULL)
788 _running_animations_timer_id = gdk_threads_add_timeout (25,
789 gtk_style_context_do_animations,
791 _running_animations = context;
795 priv->animation_list_next = _running_animations;
796 _running_animations->priv->animation_list_prev = context;
797 _running_animations = context;
802 gtk_style_context_finalize (GObject *object)
804 GtkStyleContextPrivate *priv;
805 GtkStyleContext *style_context;
807 style_context = GTK_STYLE_CONTEXT (object);
808 priv = style_context->priv;
810 _gtk_style_context_stop_animations (style_context);
812 /* children hold a reference to us */
813 g_assert (priv->children == NULL);
815 gtk_style_context_set_parent (style_context, NULL);
817 gtk_style_context_set_cascade (style_context, NULL);
819 if (priv->widget_path)
820 gtk_widget_path_free (priv->widget_path);
822 g_hash_table_destroy (priv->style_data);
825 priv->info = style_info_pop (priv->info);
827 G_OBJECT_CLASS (gtk_style_context_parent_class)->finalize (object);
831 gtk_style_context_impl_set_property (GObject *object,
836 GtkStyleContext *style_context;
838 style_context = GTK_STYLE_CONTEXT (object);
843 gtk_style_context_set_screen (style_context,
844 g_value_get_object (value));
847 gtk_style_context_set_direction (style_context,
848 g_value_get_enum (value));
851 gtk_style_context_set_parent (style_context,
852 g_value_get_object (value));
855 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
861 gtk_style_context_impl_get_property (GObject *object,
866 GtkStyleContext *style_context;
867 GtkStyleContextPrivate *priv;
869 style_context = GTK_STYLE_CONTEXT (object);
870 priv = style_context->priv;
875 g_value_set_object (value, priv->screen);
878 g_value_set_enum (value, priv->direction);
881 g_value_set_object (value, priv->parent);
884 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
890 build_properties (GtkStyleContext *context,
891 StyleData *style_data,
895 GtkStyleContextPrivate *priv;
896 GtkCssMatcher matcher;
897 GtkCssLookup *lookup;
899 priv = context->priv;
901 _gtk_css_matcher_init (&matcher, path, state);
902 lookup = _gtk_css_lookup_new ();
904 _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
908 style_data->store = _gtk_css_computed_values_new ();
909 _gtk_css_lookup_resolve (lookup, context, style_data->store);
910 _gtk_css_lookup_free (lookup);
913 static GtkWidgetPath *
914 create_query_path (GtkStyleContext *context)
916 GtkStyleContextPrivate *priv;
921 priv = context->priv;
922 path = priv->widget ? _gtk_widget_create_path (priv->widget) : gtk_widget_path_copy (priv->widget_path);
923 pos = gtk_widget_path_length (path) - 1;
927 /* Set widget regions */
928 for (i = 0; i < info->regions->len; i++)
932 region = &g_array_index (info->regions, GtkRegion, i);
933 gtk_widget_path_iter_add_region (path, pos,
934 g_quark_to_string (region->class_quark),
938 /* Set widget classes */
939 for (i = 0; i < info->style_classes->len; i++)
943 quark = g_array_index (info->style_classes, GQuark, i);
944 gtk_widget_path_iter_add_class (path, pos,
945 g_quark_to_string (quark));
952 style_data_lookup (GtkStyleContext *context)
954 GtkStyleContextPrivate *priv;
959 priv = context->priv;
962 /* Current data in use is cached, just return it */
966 g_assert (priv->widget != NULL || priv->widget_path != NULL);
968 data = g_hash_table_lookup (priv->style_data, info);
971 style_info_set_data (info, data);
975 path = create_query_path (context);
977 data = style_data_new ();
978 style_info_set_data (info, data);
979 g_hash_table_insert (priv->style_data,
980 style_info_copy (info),
983 build_properties (context, data, path, info->state_flags);
985 gtk_widget_path_free (path);
991 gtk_style_context_set_invalid (GtkStyleContext *context,
994 GtkStyleContextPrivate *priv;
996 priv = context->priv;
998 if (priv->invalid == invalid)
1001 priv->invalid = invalid;
1006 gtk_style_context_set_invalid (priv->parent, TRUE);
1007 else if (GTK_IS_RESIZE_CONTAINER (priv->widget))
1008 _gtk_container_queue_resize_handler (GTK_CONTAINER (priv->widget));
1012 /* returns TRUE if someone called gtk_style_context_save() but hasn't
1013 * called gtk_style_context_restore() yet.
1014 * In those situations we don't invalidate the context when somebody
1015 * changes state/regions/classes.
1018 gtk_style_context_is_saved (GtkStyleContext *context)
1020 return context->priv->info->next != NULL;
1024 gtk_style_context_queue_invalidate_internal (GtkStyleContext *context,
1025 GtkCssChange change)
1027 GtkStyleContextPrivate *priv = context->priv;
1028 GtkStyleInfo *info = priv->info;
1030 if (gtk_style_context_is_saved (context))
1032 style_info_set_data (info, NULL);
1036 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_STATE);
1037 /* XXX: We need to invalidate siblings here somehow */
1042 * gtk_style_context_new:
1044 * Creates a standalone #GtkStyleContext, this style context
1045 * won't be attached to any widget, so you may want
1046 * to call gtk_style_context_set_path() yourself.
1049 * This function is only useful when using the theming layer
1050 * separated from GTK+, if you are using #GtkStyleContext to
1051 * theme #GtkWidget<!-- -->s, use gtk_widget_get_style_context()
1052 * in order to get a style context ready to theme the widget.
1055 * Returns: A newly created #GtkStyleContext.
1058 gtk_style_context_new (void)
1060 return g_object_new (GTK_TYPE_STYLE_CONTEXT, NULL);
1064 _gtk_style_context_set_widget (GtkStyleContext *context,
1067 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1068 g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget));
1070 context->priv->widget = widget;
1072 _gtk_style_context_stop_animations (context);
1074 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY_SELF);
1078 * gtk_style_context_add_provider:
1079 * @context: a #GtkStyleContext
1080 * @provider: a #GtkStyleProvider
1081 * @priority: the priority of the style provider. The lower
1082 * it is, the earlier it will be used in the style
1083 * construction. Typically this will be in the range
1084 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1085 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1087 * Adds a style provider to @context, to be used in style construction.
1089 * <note><para>If both priorities are the same, A #GtkStyleProvider
1090 * added through this function takes precedence over another added
1091 * through gtk_style_context_add_provider_for_screen().</para></note>
1096 gtk_style_context_add_provider (GtkStyleContext *context,
1097 GtkStyleProvider *provider,
1100 GtkStyleContextPrivate *priv;
1102 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1103 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1105 priv = context->priv;
1107 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
1109 GtkStyleCascade *new_cascade;
1111 new_cascade = _gtk_style_cascade_new ();
1112 _gtk_style_cascade_set_parent (new_cascade, priv->cascade);
1113 _gtk_style_cascade_add_provider (new_cascade, provider, priority);
1114 gtk_style_context_set_cascade (context, new_cascade);
1115 g_object_unref (new_cascade);
1119 _gtk_style_cascade_add_provider (priv->cascade, provider, priority);
1124 * gtk_style_context_remove_provider:
1125 * @context: a #GtkStyleContext
1126 * @provider: a #GtkStyleProvider
1128 * Removes @provider from the style providers list in @context.
1133 gtk_style_context_remove_provider (GtkStyleContext *context,
1134 GtkStyleProvider *provider)
1136 GtkStyleContextPrivate *priv;
1138 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1139 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1141 priv = context->priv;
1143 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
1146 _gtk_style_cascade_remove_provider (priv->cascade, provider);
1150 * gtk_style_context_reset_widgets:
1151 * @screen: a #GdkScreen
1153 * This function recomputes the styles for all widgets under a particular
1154 * #GdkScreen. This is useful when some global parameter has changed that
1155 * affects the appearance of all widgets, because when a widget gets a new
1156 * style, it will both redraw and recompute any cached information about
1157 * its appearance. As an example, it is used when the color scheme changes
1158 * in the related #GtkSettings object.
1163 gtk_style_context_reset_widgets (GdkScreen *screen)
1165 GList *list, *toplevels;
1167 _gtk_icon_set_invalidate_caches ();
1169 toplevels = gtk_window_list_toplevels ();
1170 g_list_foreach (toplevels, (GFunc) g_object_ref, NULL);
1172 for (list = toplevels; list; list = list->next)
1174 if (gtk_widget_get_screen (list->data) == screen)
1175 gtk_widget_reset_style (list->data);
1177 g_object_unref (list->data);
1180 g_list_free (toplevels);
1184 * gtk_style_context_add_provider_for_screen:
1185 * @screen: a #GdkScreen
1186 * @provider: a #GtkStyleProvider
1187 * @priority: the priority of the style provider. The lower
1188 * it is, the earlier it will be used in the style
1189 * construction. Typically this will be in the range
1190 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1191 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1193 * Adds a global style provider to @screen, which will be used
1194 * in style construction for all #GtkStyleContext<!-- -->s under
1197 * GTK+ uses this to make styling information from #GtkSettings
1200 * <note><para>If both priorities are the same, A #GtkStyleProvider
1201 * added through gtk_style_context_add_provider() takes precedence
1202 * over another added through this function.</para></note>
1207 gtk_style_context_add_provider_for_screen (GdkScreen *screen,
1208 GtkStyleProvider *provider,
1211 GtkStyleCascade *cascade;
1213 g_return_if_fail (GDK_IS_SCREEN (screen));
1214 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1216 cascade = _gtk_style_cascade_get_for_screen (screen);
1217 _gtk_style_cascade_add_provider (cascade, provider, priority);
1221 * gtk_style_context_remove_provider_for_screen:
1222 * @screen: a #GdkScreen
1223 * @provider: a #GtkStyleProvider
1225 * Removes @provider from the global style providers list in @screen.
1230 gtk_style_context_remove_provider_for_screen (GdkScreen *screen,
1231 GtkStyleProvider *provider)
1233 GtkStyleCascade *cascade;
1235 g_return_if_fail (GDK_IS_SCREEN (screen));
1236 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1238 cascade = _gtk_style_cascade_get_for_screen (screen);
1239 _gtk_style_cascade_remove_provider (cascade, provider);
1243 * gtk_style_context_get_section:
1244 * @context: a #GtkStyleContext
1245 * @property: style property name
1247 * Queries the location in the CSS where @property was defined for the
1248 * current @context. Note that the state to be queried is taken from
1249 * gtk_style_context_get_state().
1251 * If the location is not available, %NULL will be returned. The
1252 * location might not be available for various reasons, such as the
1253 * property being overridden, @property not naming a supported CSS
1254 * property or tracking of definitions being disabled for performance
1257 * Shorthand CSS properties cannot be queried for a location and will
1258 * always return %NULL.
1260 * Returns: %NULL or the section where value was defined
1263 gtk_style_context_get_section (GtkStyleContext *context,
1264 const gchar *property)
1266 GtkStyleContextPrivate *priv;
1267 GtkStyleProperty *prop;
1270 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1271 g_return_val_if_fail (property != NULL, NULL);
1273 priv = context->priv;
1274 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
1276 prop = _gtk_style_property_lookup (property);
1277 if (!GTK_IS_CSS_STYLE_PROPERTY (prop))
1280 data = style_data_lookup (context);
1281 return _gtk_css_computed_values_get_section (data->store, _gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (prop)));
1284 static GtkCssValue *
1285 gtk_style_context_query_func (guint id,
1288 return _gtk_css_computed_values_get_value (values, id);
1292 * gtk_style_context_get_property:
1293 * @context: a #GtkStyleContext
1294 * @property: style property name
1295 * @state: state to retrieve the property value for
1296 * @value: (out) (transfer full): return location for the style property value
1298 * Gets a style property from @context for the given state.
1300 * When @value is no longer needed, g_value_unset() must be called
1301 * to free any allocated memory.
1306 gtk_style_context_get_property (GtkStyleContext *context,
1307 const gchar *property,
1308 GtkStateFlags state,
1311 GtkStyleContextPrivate *priv;
1312 GtkStyleProperty *prop;
1315 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1316 g_return_if_fail (property != NULL);
1317 g_return_if_fail (value != NULL);
1319 priv = context->priv;
1320 g_return_if_fail (priv->widget != NULL || priv->widget_path != NULL);
1322 prop = _gtk_style_property_lookup (property);
1325 g_warning ("Style property \"%s\" is not registered", property);
1328 if (_gtk_style_property_get_value_type (prop) == G_TYPE_NONE)
1330 g_warning ("Style property \"%s\" is not gettable", property);
1334 gtk_style_context_save (context);
1335 gtk_style_context_set_state (context, state);
1336 data = style_data_lookup (context);
1337 _gtk_style_property_query (prop, value, gtk_style_context_query_func, data->store);
1338 gtk_style_context_restore (context);
1342 * gtk_style_context_get_valist:
1343 * @context: a #GtkStyleContext
1344 * @state: state to retrieve the property values for
1345 * @args: va_list of property name/return location pairs, followed by %NULL
1347 * Retrieves several style property values from @context for a given state.
1352 gtk_style_context_get_valist (GtkStyleContext *context,
1353 GtkStateFlags state,
1356 const gchar *property_name;
1358 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1360 property_name = va_arg (args, const gchar *);
1362 while (property_name)
1364 gchar *error = NULL;
1365 GValue value = G_VALUE_INIT;
1367 gtk_style_context_get_property (context,
1372 G_VALUE_LCOPY (&value, args, 0, &error);
1373 g_value_unset (&value);
1377 g_warning ("Could not get style property \"%s\": %s", property_name, error);
1382 property_name = va_arg (args, const gchar *);
1387 * gtk_style_context_get:
1388 * @context: a #GtkStyleContext
1389 * @state: state to retrieve the property values for
1390 * @...: property name /return value pairs, followed by %NULL
1392 * Retrieves several style property values from @context for a
1398 gtk_style_context_get (GtkStyleContext *context,
1399 GtkStateFlags state,
1404 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1406 va_start (args, state);
1407 gtk_style_context_get_valist (context, state, args);
1412 * gtk_style_context_set_state:
1413 * @context: a #GtkStyleContext
1414 * @flags: state to represent
1416 * Sets the state to be used when rendering with any
1417 * of the gtk_render_*() functions.
1422 gtk_style_context_set_state (GtkStyleContext *context,
1423 GtkStateFlags flags)
1425 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1427 context->priv->info->state_flags = flags;
1429 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_STATE);
1433 * gtk_style_context_get_state:
1434 * @context: a #GtkStyleContext
1436 * Returns the state used when rendering.
1438 * Returns: the state flags
1443 gtk_style_context_get_state (GtkStyleContext *context)
1445 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
1447 return context->priv->info->state_flags;
1451 * gtk_style_context_state_is_running:
1452 * @context: a #GtkStyleContext
1453 * @state: a widget state
1454 * @progress: (out): return location for the transition progress
1456 * Returns %TRUE if there is a transition animation running for the
1457 * current region (see gtk_style_context_push_animatable_region()).
1459 * If @progress is not %NULL, the animation progress will be returned
1460 * there, 0.0 means the state is closest to being unset, while 1.0 means
1461 * it's closest to being set. This means transition animation will
1462 * run from 0 to 1 when @state is being set and from 1 to 0 when
1465 * Returns: %TRUE if there is a running transition animation for @state.
1469 * Deprecated: 3.6: This function always returns %FALSE
1472 gtk_style_context_state_is_running (GtkStyleContext *context,
1476 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1482 * gtk_style_context_set_path:
1483 * @context: a #GtkStyleContext
1484 * @path: a #GtkWidgetPath
1486 * Sets the #GtkWidgetPath used for style matching. As a
1487 * consequence, the style will be regenerated to match
1488 * the new given path.
1490 * If you are using a #GtkStyleContext returned from
1491 * gtk_widget_get_style_context(), you do not need to call
1497 gtk_style_context_set_path (GtkStyleContext *context,
1498 GtkWidgetPath *path)
1500 GtkStyleContextPrivate *priv;
1502 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1503 g_return_if_fail (path != NULL);
1505 priv = context->priv;
1506 g_return_if_fail (priv->widget == NULL);
1508 if (priv->widget_path)
1510 gtk_widget_path_free (priv->widget_path);
1511 priv->widget_path = NULL;
1515 priv->widget_path = gtk_widget_path_copy (path);
1517 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY);
1521 * gtk_style_context_get_path:
1522 * @context: a #GtkStyleContext
1524 * Returns the widget path used for style matching.
1526 * Returns: (transfer none): A #GtkWidgetPath
1530 const GtkWidgetPath *
1531 gtk_style_context_get_path (GtkStyleContext *context)
1533 GtkStyleContextPrivate *priv;
1535 priv = context->priv;
1537 return gtk_widget_get_path (priv->widget);
1539 return priv->widget_path;
1543 * gtk_style_context_set_parent:
1544 * @context: a #GtkStyleContext
1545 * @parent: (allow-none): the new parent or %NULL
1547 * Sets the parent style context for @context. The parent style
1548 * context is used to implement
1549 * <ulink url="http://www.w3.org/TR/css3-cascade/#inheritance">inheritance</ulink>
1552 * If you are using a #GtkStyleContext returned from
1553 * gtk_widget_get_style_context(), the parent will be set for you.
1558 gtk_style_context_set_parent (GtkStyleContext *context,
1559 GtkStyleContext *parent)
1561 GtkStyleContextPrivate *priv;
1563 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1564 g_return_if_fail (parent == NULL || GTK_IS_STYLE_CONTEXT (parent));
1566 priv = context->priv;
1568 if (priv->parent == parent)
1573 parent->priv->children = g_slist_prepend (parent->priv->children, context);
1574 g_object_ref (parent);
1576 gtk_style_context_set_invalid (parent, TRUE);
1581 priv->parent->priv->children = g_slist_remove (priv->parent->priv->children, context);
1582 g_object_unref (priv->parent);
1585 priv->parent = parent;
1587 g_object_notify (G_OBJECT (context), "parent");
1588 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY_PARENT | GTK_CSS_CHANGE_ANY_SIBLING);
1592 * gtk_style_context_get_parent:
1593 * @context: a #GtkStyleContext
1595 * Gets the parent context set via gtk_style_context_set_parent().
1596 * See that function for details.
1598 * Returns: (transfer none): the parent context or %NULL
1603 gtk_style_context_get_parent (GtkStyleContext *context)
1605 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1607 return context->priv->parent;
1611 * gtk_style_context_save:
1612 * @context: a #GtkStyleContext
1614 * Saves the @context state, so all modifications done through
1615 * gtk_style_context_add_class(), gtk_style_context_remove_class(),
1616 * gtk_style_context_add_region(), gtk_style_context_remove_region()
1617 * or gtk_style_context_set_junction_sides() can be reverted in one
1618 * go through gtk_style_context_restore().
1623 gtk_style_context_save (GtkStyleContext *context)
1625 GtkStyleContextPrivate *priv;
1627 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1629 priv = context->priv;
1631 priv->info = style_info_copy (priv->info);
1635 * gtk_style_context_restore:
1636 * @context: a #GtkStyleContext
1638 * Restores @context state to a previous stage.
1639 * See gtk_style_context_save().
1644 gtk_style_context_restore (GtkStyleContext *context)
1646 GtkStyleContextPrivate *priv;
1648 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1650 priv = context->priv;
1652 priv->info = style_info_pop (priv->info);
1656 g_warning ("Unpaired gtk_style_context_restore() call");
1658 /* Create default region */
1659 priv->info = style_info_new ();
1664 style_class_find (GArray *array,
1669 gboolean found = FALSE;
1675 if (!array || array->len == 0)
1679 max = array->len - 1;
1685 mid = (min + max) / 2;
1686 item = g_array_index (array, GQuark, mid);
1688 if (class_quark == item)
1693 else if (class_quark > item)
1694 min = pos = mid + 1;
1701 while (!found && min <= max);
1710 region_find (GArray *array,
1715 gboolean found = FALSE;
1721 if (!array || array->len == 0)
1725 max = array->len - 1;
1731 mid = (min + max) / 2;
1732 region = &g_array_index (array, GtkRegion, mid);
1734 if (region->class_quark == class_quark)
1739 else if (region->class_quark > class_quark)
1740 min = pos = mid + 1;
1747 while (!found && min <= max);
1756 * gtk_style_context_add_class:
1757 * @context: a #GtkStyleContext
1758 * @class_name: class name to use in styling
1760 * Adds a style class to @context, so posterior calls to
1761 * gtk_style_context_get() or any of the gtk_render_*()
1762 * functions will make use of this new class for styling.
1764 * In the CSS file format, a #GtkEntry defining an "entry"
1765 * class, would be matched by:
1768 * GtkEntry.entry { ... }
1771 * While any widget defining an "entry" class would be
1780 gtk_style_context_add_class (GtkStyleContext *context,
1781 const gchar *class_name)
1783 GtkStyleContextPrivate *priv;
1788 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1789 g_return_if_fail (class_name != NULL);
1791 priv = context->priv;
1792 class_quark = g_quark_from_string (class_name);
1796 if (!style_class_find (info->style_classes, class_quark, &position))
1798 g_array_insert_val (info->style_classes, position, class_quark);
1800 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_CLASS);
1805 * gtk_style_context_remove_class:
1806 * @context: a #GtkStyleContext
1807 * @class_name: class name to remove
1809 * Removes @class_name from @context.
1814 gtk_style_context_remove_class (GtkStyleContext *context,
1815 const gchar *class_name)
1817 GtkStyleContextPrivate *priv;
1822 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1823 g_return_if_fail (class_name != NULL);
1825 class_quark = g_quark_try_string (class_name);
1830 priv = context->priv;
1834 if (style_class_find (info->style_classes, class_quark, &position))
1836 g_array_remove_index (info->style_classes, position);
1838 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_CLASS);
1843 * gtk_style_context_has_class:
1844 * @context: a #GtkStyleContext
1845 * @class_name: a class name
1847 * Returns %TRUE if @context currently has defined the
1850 * Returns: %TRUE if @context has @class_name defined
1855 gtk_style_context_has_class (GtkStyleContext *context,
1856 const gchar *class_name)
1858 GtkStyleContextPrivate *priv;
1862 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1863 g_return_val_if_fail (class_name != NULL, FALSE);
1865 class_quark = g_quark_try_string (class_name);
1870 priv = context->priv;
1874 if (style_class_find (info->style_classes, class_quark, NULL))
1881 * gtk_style_context_list_classes:
1882 * @context: a #GtkStyleContext
1884 * Returns the list of classes currently defined in @context.
1886 * Returns: (transfer container) (element-type utf8): a #GList of
1887 * strings with the currently defined classes. The contents
1888 * of the list are owned by GTK+, but you must free the list
1889 * itself with g_list_free() when you are done with it.
1894 gtk_style_context_list_classes (GtkStyleContext *context)
1896 GtkStyleContextPrivate *priv;
1898 GList *classes = NULL;
1901 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1903 priv = context->priv;
1907 for (i = 0; i < info->style_classes->len; i++)
1911 quark = g_array_index (info->style_classes, GQuark, i);
1912 classes = g_list_prepend (classes, (gchar *) g_quark_to_string (quark));
1919 * gtk_style_context_list_regions:
1920 * @context: a #GtkStyleContext
1922 * Returns the list of regions currently defined in @context.
1924 * Returns: (transfer container) (element-type utf8): a #GList of
1925 * strings with the currently defined regions. The contents
1926 * of the list are owned by GTK+, but you must free the list
1927 * itself with g_list_free() when you are done with it.
1932 gtk_style_context_list_regions (GtkStyleContext *context)
1934 GtkStyleContextPrivate *priv;
1936 GList *classes = NULL;
1939 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1941 priv = context->priv;
1945 for (i = 0; i < info->regions->len; i++)
1948 const gchar *class_name;
1950 region = &g_array_index (info->regions, GtkRegion, i);
1952 class_name = g_quark_to_string (region->class_quark);
1953 classes = g_list_prepend (classes, (gchar *) class_name);
1960 _gtk_style_context_check_region_name (const gchar *str)
1962 g_return_val_if_fail (str != NULL, FALSE);
1964 if (!g_ascii_islower (str[0]))
1970 !g_ascii_islower (*str))
1980 * gtk_style_context_add_region:
1981 * @context: a #GtkStyleContext
1982 * @region_name: region name to use in styling
1983 * @flags: flags that apply to the region
1985 * Adds a region to @context, so posterior calls to
1986 * gtk_style_context_get() or any of the gtk_render_*()
1987 * functions will make use of this new region for styling.
1989 * In the CSS file format, a #GtkTreeView defining a "row"
1990 * region, would be matched by:
1993 * GtkTreeView row { ... }
1996 * Pseudo-classes are used for matching @flags, so the two
1999 * GtkTreeView row:nth-child(even) { ... }
2000 * GtkTreeView row:nth-child(odd) { ... }
2003 * would apply to even and odd rows, respectively.
2005 * <note><para>Region names must only contain lowercase letters
2006 * and '-', starting always with a lowercase letter.</para></note>
2011 gtk_style_context_add_region (GtkStyleContext *context,
2012 const gchar *region_name,
2013 GtkRegionFlags flags)
2015 GtkStyleContextPrivate *priv;
2017 GQuark region_quark;
2020 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2021 g_return_if_fail (region_name != NULL);
2022 g_return_if_fail (_gtk_style_context_check_region_name (region_name));
2024 priv = context->priv;
2025 region_quark = g_quark_from_string (region_name);
2029 if (!region_find (info->regions, region_quark, &position))
2033 region.class_quark = region_quark;
2034 region.flags = flags;
2036 g_array_insert_val (info->regions, position, region);
2038 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_REGION);
2043 * gtk_style_context_remove_region:
2044 * @context: a #GtkStyleContext
2045 * @region_name: region name to unset
2047 * Removes a region from @context.
2052 gtk_style_context_remove_region (GtkStyleContext *context,
2053 const gchar *region_name)
2055 GtkStyleContextPrivate *priv;
2057 GQuark region_quark;
2060 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2061 g_return_if_fail (region_name != NULL);
2063 region_quark = g_quark_try_string (region_name);
2068 priv = context->priv;
2072 if (region_find (info->regions, region_quark, &position))
2074 g_array_remove_index (info->regions, position);
2076 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_REGION);
2081 * gtk_style_context_has_region:
2082 * @context: a #GtkStyleContext
2083 * @region_name: a region name
2084 * @flags_return: (out) (allow-none): return location for region flags
2086 * Returns %TRUE if @context has the region defined.
2087 * If @flags_return is not %NULL, it is set to the flags
2088 * affecting the region.
2090 * Returns: %TRUE if region is defined
2095 gtk_style_context_has_region (GtkStyleContext *context,
2096 const gchar *region_name,
2097 GtkRegionFlags *flags_return)
2099 GtkStyleContextPrivate *priv;
2101 GQuark region_quark;
2104 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2105 g_return_val_if_fail (region_name != NULL, FALSE);
2110 region_quark = g_quark_try_string (region_name);
2115 priv = context->priv;
2119 if (region_find (info->regions, region_quark, &position))
2125 region = &g_array_index (info->regions, GtkRegion, position);
2126 *flags_return = region->flags;
2135 style_property_values_cmp (gconstpointer bsearch_node1,
2136 gconstpointer bsearch_node2)
2138 const PropertyValue *val1 = bsearch_node1;
2139 const PropertyValue *val2 = bsearch_node2;
2141 if (val1->widget_type != val2->widget_type)
2142 return val1->widget_type < val2->widget_type ? -1 : 1;
2144 if (val1->pspec != val2->pspec)
2145 return val1->pspec < val2->pspec ? -1 : 1;
2147 if (val1->state != val2->state)
2148 return val1->state < val2->state ? -1 : 1;
2154 _gtk_style_context_peek_property (GtkStyleContext *context,
2157 StyleData *data = style_data_lookup (context);
2159 return _gtk_css_computed_values_get_value (data->store, property_id);
2163 _gtk_style_context_get_number (GtkStyleContext *context,
2165 double one_hundred_percent)
2169 value = _gtk_style_context_peek_property (context, property_id);
2170 return _gtk_css_number_value_get (value, one_hundred_percent);
2174 _gtk_style_context_peek_style_property (GtkStyleContext *context,
2176 GtkStateFlags state,
2179 GtkStyleContextPrivate *priv;
2180 PropertyValue *pcache, key = { 0 };
2184 priv = context->priv;
2186 gtk_style_context_save (context);
2187 gtk_style_context_set_state (context, state);
2188 data = style_data_lookup (context);
2189 gtk_style_context_restore (context);
2191 key.widget_type = widget_type;
2195 /* need value cache array */
2196 if (!data->property_cache)
2197 data->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
2200 pcache = bsearch (&key,
2201 data->property_cache->data, data->property_cache->len,
2202 sizeof (PropertyValue), style_property_values_cmp);
2204 return &pcache->value;
2208 while (i < data->property_cache->len &&
2209 style_property_values_cmp (&key, &g_array_index (data->property_cache, PropertyValue, i)) >= 0)
2212 g_array_insert_val (data->property_cache, i, key);
2213 pcache = &g_array_index (data->property_cache, PropertyValue, i);
2215 /* cache miss, initialize value type, then set contents */
2216 g_param_spec_ref (pcache->pspec);
2217 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2219 if (priv->widget || priv->widget_path)
2221 GtkWidgetPath *widget_path = priv->widget ? _gtk_widget_create_path (priv->widget) : priv->widget_path;
2223 if (gtk_style_provider_get_style_property (GTK_STYLE_PROVIDER (priv->cascade),
2225 state, pspec, &pcache->value))
2227 /* Resolve symbolic colors to GdkColor/GdkRGBA */
2228 if (G_VALUE_TYPE (&pcache->value) == GTK_TYPE_SYMBOLIC_COLOR)
2230 GtkSymbolicColor *color;
2233 color = g_value_dup_boxed (&pcache->value);
2235 g_value_unset (&pcache->value);
2237 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2238 g_value_init (&pcache->value, GDK_TYPE_RGBA);
2240 g_value_init (&pcache->value, GDK_TYPE_COLOR);
2242 if (_gtk_style_context_resolve_color (context, color, &rgba))
2244 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2245 g_value_set_boxed (&pcache->value, &rgba);
2250 rgb.red = rgba.red * 65535. + 0.5;
2251 rgb.green = rgba.green * 65535. + 0.5;
2252 rgb.blue = rgba.blue * 65535. + 0.5;
2254 g_value_set_boxed (&pcache->value, &rgb);
2258 g_param_value_set_default (pspec, &pcache->value);
2260 gtk_symbolic_color_unref (color);
2264 gtk_widget_path_free (widget_path);
2266 return &pcache->value;
2270 gtk_widget_path_free (widget_path);
2273 /* not supplied by any provider, revert to default */
2274 g_param_value_set_default (pspec, &pcache->value);
2276 return &pcache->value;
2280 * gtk_style_context_get_style_property:
2281 * @context: a #GtkStyleContext
2282 * @property_name: the name of the widget style property
2283 * @value: Return location for the property value
2285 * Gets the value for a widget style property.
2287 * When @value is no longer needed, g_value_unset() must be called
2288 * to free any allocated memory.
2291 gtk_style_context_get_style_property (GtkStyleContext *context,
2292 const gchar *property_name,
2295 GtkStyleContextPrivate *priv;
2296 GtkWidgetClass *widget_class;
2297 GtkStateFlags state;
2299 const GValue *peek_value;
2302 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2303 g_return_if_fail (property_name != NULL);
2304 g_return_if_fail (value != NULL);
2306 priv = context->priv;
2310 widget_type = G_OBJECT_TYPE (priv->widget);
2314 if (!priv->widget_path)
2317 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2319 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2321 g_warning ("%s: can't get style properties for non-widget class `%s'",
2323 g_type_name (widget_type));
2328 widget_class = g_type_class_ref (widget_type);
2329 pspec = gtk_widget_class_find_style_property (widget_class, property_name);
2330 g_type_class_unref (widget_class);
2334 g_warning ("%s: widget class `%s' has no style property named `%s'",
2336 g_type_name (widget_type),
2341 state = gtk_style_context_get_state (context);
2342 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2345 if (G_VALUE_TYPE (value) == G_VALUE_TYPE (peek_value))
2346 g_value_copy (peek_value, value);
2347 else if (g_value_type_transformable (G_VALUE_TYPE (peek_value), G_VALUE_TYPE (value)))
2348 g_value_transform (peek_value, value);
2350 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
2352 G_VALUE_TYPE_NAME (peek_value),
2353 G_VALUE_TYPE_NAME (value));
2357 * gtk_style_context_get_style_valist:
2358 * @context: a #GtkStyleContext
2359 * @args: va_list of property name/return location pairs, followed by %NULL
2361 * Retrieves several widget style properties from @context according to the
2367 gtk_style_context_get_style_valist (GtkStyleContext *context,
2370 GtkStyleContextPrivate *priv;
2371 const gchar *prop_name;
2372 GtkStateFlags state;
2375 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2377 prop_name = va_arg (args, const gchar *);
2378 priv = context->priv;
2382 widget_type = G_OBJECT_TYPE (priv->widget);
2386 if (!priv->widget_path)
2389 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2391 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2393 g_warning ("%s: can't get style properties for non-widget class `%s'",
2395 g_type_name (widget_type));
2400 state = gtk_style_context_get_state (context);
2404 GtkWidgetClass *widget_class;
2406 const GValue *peek_value;
2409 widget_class = g_type_class_ref (widget_type);
2410 pspec = gtk_widget_class_find_style_property (widget_class, prop_name);
2411 g_type_class_unref (widget_class);
2415 g_warning ("%s: widget class `%s' has no style property named `%s'",
2417 g_type_name (widget_type),
2422 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2425 G_VALUE_LCOPY (peek_value, args, 0, &error);
2429 g_warning ("can't retrieve style property `%s' of type `%s': %s",
2431 G_VALUE_TYPE_NAME (peek_value),
2437 prop_name = va_arg (args, const gchar *);
2442 * gtk_style_context_get_style:
2443 * @context: a #GtkStyleContext
2444 * @...: property name /return value pairs, followed by %NULL
2446 * Retrieves several widget style properties from @context according to the
2452 gtk_style_context_get_style (GtkStyleContext *context,
2457 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2459 va_start (args, context);
2460 gtk_style_context_get_style_valist (context, args);
2466 * gtk_style_context_lookup_icon_set:
2467 * @context: a #GtkStyleContext
2468 * @stock_id: an icon name
2470 * Looks up @stock_id in the icon factories associated to @context and
2471 * the default icon factory, returning an icon set if found, otherwise
2474 * Returns: (transfer none): The looked up %GtkIconSet, or %NULL
2477 gtk_style_context_lookup_icon_set (GtkStyleContext *context,
2478 const gchar *stock_id)
2480 GtkStyleContextPrivate *priv;
2482 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2483 g_return_val_if_fail (stock_id != NULL, NULL);
2485 priv = context->priv;
2486 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
2488 return gtk_icon_factory_lookup_default (stock_id);
2492 * gtk_style_context_set_screen:
2493 * @context: a #GtkStyleContext
2494 * @screen: a #GdkScreen
2496 * Attaches @context to the given screen.
2498 * The screen is used to add style information from 'global' style
2499 * providers, such as the screens #GtkSettings instance.
2501 * If you are using a #GtkStyleContext returned from
2502 * gtk_widget_get_style_context(), you do not need to
2503 * call this yourself.
2508 gtk_style_context_set_screen (GtkStyleContext *context,
2511 GtkStyleContextPrivate *priv;
2513 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2514 g_return_if_fail (GDK_IS_SCREEN (screen));
2516 priv = context->priv;
2517 if (priv->screen == screen)
2520 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
2522 gtk_style_context_set_cascade (context, _gtk_style_cascade_get_for_screen (screen));
2526 _gtk_style_cascade_set_parent (priv->cascade, _gtk_style_cascade_get_for_screen (screen));
2529 priv->screen = screen;
2531 g_object_notify (G_OBJECT (context), "screen");
2533 gtk_style_context_invalidate (context);
2537 * gtk_style_context_get_screen:
2538 * @context: a #GtkStyleContext
2540 * Returns the #GdkScreen to which @context is attached.
2542 * Returns: (transfer none): a #GdkScreen.
2545 gtk_style_context_get_screen (GtkStyleContext *context)
2547 GtkStyleContextPrivate *priv;
2549 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2551 priv = context->priv;
2552 return priv->screen;
2556 * gtk_style_context_set_direction:
2557 * @context: a #GtkStyleContext
2558 * @direction: the new direction.
2560 * Sets the reading direction for rendering purposes.
2562 * If you are using a #GtkStyleContext returned from
2563 * gtk_widget_get_style_context(), you do not need to
2564 * call this yourself.
2569 gtk_style_context_set_direction (GtkStyleContext *context,
2570 GtkTextDirection direction)
2572 GtkStyleContextPrivate *priv;
2574 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2576 priv = context->priv;
2577 priv->direction = direction;
2579 g_object_notify (G_OBJECT (context), "direction");
2583 * gtk_style_context_get_direction:
2584 * @context: a #GtkStyleContext
2586 * Returns the widget direction used for rendering.
2588 * Returns: the widget direction
2593 gtk_style_context_get_direction (GtkStyleContext *context)
2595 GtkStyleContextPrivate *priv;
2597 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), GTK_TEXT_DIR_LTR);
2599 priv = context->priv;
2600 return priv->direction;
2604 * gtk_style_context_set_junction_sides:
2605 * @context: a #GtkStyleContext
2606 * @sides: sides where rendered elements are visually connected to
2609 * Sets the sides where rendered elements (mostly through
2610 * gtk_render_frame()) will visually connect with other visual elements.
2612 * This is merely a hint that may or may not be honored
2613 * by theming engines.
2615 * Container widgets are expected to set junction hints as appropriate
2616 * for their children, so it should not normally be necessary to call
2617 * this function manually.
2622 gtk_style_context_set_junction_sides (GtkStyleContext *context,
2623 GtkJunctionSides sides)
2625 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2627 context->priv->info->junction_sides = sides;
2631 * gtk_style_context_get_junction_sides:
2632 * @context: a #GtkStyleContext
2634 * Returns the sides where rendered elements connect visually with others.
2636 * Returns: the junction sides
2641 gtk_style_context_get_junction_sides (GtkStyleContext *context)
2643 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
2645 return context->priv->info->junction_sides;
2648 static GtkSymbolicColor *
2649 gtk_style_context_color_lookup_func (gpointer contextp,
2652 GtkStyleContext *context = contextp;
2654 return _gtk_style_provider_private_get_color (GTK_STYLE_PROVIDER_PRIVATE (context->priv->cascade), name);
2658 _gtk_style_context_resolve_color_value (GtkStyleContext *context,
2659 GtkCssValue *current,
2662 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2663 g_return_val_if_fail (current != NULL, FALSE);
2664 g_return_val_if_fail (color != NULL, FALSE);
2666 return _gtk_symbolic_color_resolve_full ((GtkSymbolicColor *) color,
2668 gtk_style_context_color_lookup_func,
2674 _gtk_style_context_resolve_color (GtkStyleContext *context,
2675 GtkSymbolicColor *color,
2680 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2681 g_return_val_if_fail (color != NULL, FALSE);
2682 g_return_val_if_fail (result != NULL, FALSE);
2684 val = _gtk_symbolic_color_resolve_full (color,
2685 _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR),
2686 gtk_style_context_color_lookup_func,
2691 *result = *_gtk_css_rgba_value_get_rgba (val);
2692 _gtk_css_value_unref (val);
2697 * gtk_style_context_lookup_color:
2698 * @context: a #GtkStyleContext
2699 * @color_name: color name to lookup
2700 * @color: (out): Return location for the looked up color
2702 * Looks up and resolves a color name in the @context color map.
2704 * Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
2707 gtk_style_context_lookup_color (GtkStyleContext *context,
2708 const gchar *color_name,
2711 GtkSymbolicColor *sym_color;
2713 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2714 g_return_val_if_fail (color_name != NULL, FALSE);
2715 g_return_val_if_fail (color != NULL, FALSE);
2717 sym_color = gtk_style_context_color_lookup_func (context, color_name);
2718 if (sym_color == NULL)
2721 return _gtk_style_context_resolve_color (context, sym_color, color);
2725 * gtk_style_context_notify_state_change:
2726 * @context: a #GtkStyleContext
2727 * @window: a #GdkWindow
2728 * @region_id: (allow-none): animatable region to notify on, or %NULL.
2729 * See gtk_style_context_push_animatable_region()
2730 * @state: state to trigger transition for
2731 * @state_value: %TRUE if @state is the state we are changing to,
2732 * %FALSE if we are changing away from it
2734 * Notifies a state change on @context, so if the current style makes use
2735 * of transition animations, one will be started so all rendered elements
2736 * under @region_id are animated for state @state being set to value
2739 * The @window parameter is used in order to invalidate the rendered area
2740 * as the animation runs, so make sure it is the same window that is being
2741 * rendered on by the gtk_render_*() functions.
2743 * If @region_id is %NULL, all rendered elements using @context will be
2744 * affected by this state transition.
2746 * As a practical example, a #GtkButton notifying a state transition on
2747 * the prelight state:
2749 * gtk_style_context_notify_state_change (context,
2750 * gtk_widget_get_window (widget),
2752 * GTK_STATE_PRELIGHT,
2753 * button->in_button);
2756 * Can be handled in the CSS file like this:
2759 * background-color: #f00
2763 * background-color: #fff;
2764 * transition: 200ms linear
2768 * This combination will animate the button background from red to white
2769 * if a pointer enters the button, and back to red if the pointer leaves
2772 * Note that @state is used when finding the transition parameters, which
2773 * is why the style places the transition under the :hover pseudo-class.
2777 * Deprecated: 3.6: This function does nothing.
2780 gtk_style_context_notify_state_change (GtkStyleContext *context,
2784 gboolean state_value)
2786 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2787 g_return_if_fail (GDK_IS_WINDOW (window));
2788 g_return_if_fail (state > GTK_STATE_NORMAL && state <= GTK_STATE_FOCUSED);
2789 g_return_if_fail (context->priv->widget != NULL || context->priv->widget_path != NULL);
2793 * gtk_style_context_cancel_animations:
2794 * @context: a #GtkStyleContext
2795 * @region_id: (allow-none): animatable region to stop, or %NULL.
2796 * See gtk_style_context_push_animatable_region()
2798 * Stops all running animations for @region_id and all animatable
2799 * regions underneath.
2801 * A %NULL @region_id will stop all ongoing animations in @context,
2802 * when dealing with a #GtkStyleContext obtained through
2803 * gtk_widget_get_style_context(), this is normally done for you
2804 * in all circumstances you would expect all widget to be stopped,
2805 * so this should be only used in complex widgets with different
2806 * animatable regions.
2810 * Deprecated: 3.6: This function does nothing.
2813 gtk_style_context_cancel_animations (GtkStyleContext *context,
2816 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2820 * gtk_style_context_scroll_animations:
2821 * @context: a #GtkStyleContext
2822 * @window: a #GdkWindow used previously in
2823 * gtk_style_context_notify_state_change()
2824 * @dx: Amount to scroll in the X axis
2825 * @dy: Amount to scroll in the Y axis
2827 * This function is analogous to gdk_window_scroll(), and
2828 * should be called together with it so the invalidation
2829 * areas for any ongoing animation are scrolled together
2834 * Deprecated: 3.6: This function does nothing.
2837 gtk_style_context_scroll_animations (GtkStyleContext *context,
2842 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2843 g_return_if_fail (GDK_IS_WINDOW (window));
2847 * gtk_style_context_push_animatable_region:
2848 * @context: a #GtkStyleContext
2849 * @region_id: unique identifier for the animatable region
2851 * Pushes an animatable region, so all further gtk_render_*() calls between
2852 * this call and the following gtk_style_context_pop_animatable_region()
2853 * will potentially show transition animations for this region if
2854 * gtk_style_context_notify_state_change() is called for a given state,
2855 * and the current theme/style defines transition animations for state
2858 * The @region_id used must be unique in @context so the theming engine
2859 * can uniquely identify rendered elements subject to a state transition.
2863 * Deprecated: 3.6: This function does nothing.
2866 gtk_style_context_push_animatable_region (GtkStyleContext *context,
2869 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2870 g_return_if_fail (region_id != NULL);
2874 * gtk_style_context_pop_animatable_region:
2875 * @context: a #GtkStyleContext
2877 * Pops an animatable region from @context.
2878 * See gtk_style_context_push_animatable_region().
2882 * Deprecated: 3.6: This function does nothing.
2885 gtk_style_context_pop_animatable_region (GtkStyleContext *context)
2887 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2891 gtk_style_context_clear_cache (GtkStyleContext *context)
2893 GtkStyleContextPrivate *priv;
2896 priv = context->priv;
2898 for (info = priv->info; info; info = info->next)
2900 style_info_set_data (info, NULL);
2902 g_hash_table_remove_all (priv->style_data);
2906 gtk_style_context_do_invalidate (GtkStyleContext *context)
2908 GtkStyleContextPrivate *priv;
2910 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2912 priv = context->priv;
2914 /* Avoid reentrancy */
2915 if (priv->invalidating_context)
2918 priv->invalidating_context = TRUE;
2920 g_signal_emit (context, signals[CHANGED], 0);
2922 priv->invalidating_context = FALSE;
2926 _gtk_style_context_stop_animations (GtkStyleContext *context)
2928 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2930 if (!gtk_style_context_is_animating (context))
2933 gtk_style_context_stop_animating (context);
2937 _gtk_style_context_validate (GtkStyleContext *context,
2939 GtkCssChange change)
2941 GtkStyleContextPrivate *priv;
2942 GtkBitmask *changes;
2945 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2947 priv = context->priv;
2949 change |= priv->pending_changes;
2951 if (!priv->invalid && change == 0)
2954 priv->pending_changes = 0;
2955 gtk_style_context_set_invalid (context, FALSE);
2957 /* Try to avoid invalidating if we can */
2958 if (change & GTK_STYLE_CONTEXT_RADICAL_CHANGE)
2960 priv->relevant_changes = GTK_CSS_CHANGE_ANY;
2964 if (priv->relevant_changes == GTK_CSS_CHANGE_ANY)
2966 GtkWidgetPath *path;
2967 GtkCssMatcher matcher;
2969 path = create_query_path (context);
2970 _gtk_css_matcher_init (&matcher, path, priv->info->state_flags);
2972 priv->relevant_changes = _gtk_style_provider_private_get_change (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
2974 priv->relevant_changes &= ~GTK_STYLE_CONTEXT_RADICAL_CHANGE;
2976 gtk_widget_path_unref (path);
2980 if (priv->relevant_changes & change)
2982 GtkStyleInfo *info = priv->info;
2983 GtkCssComputedValues *old, *new;
2985 old = info->data ? g_object_ref (info->data->store) : NULL;
2987 if ((priv->relevant_changes & change) & ~GTK_STYLE_CONTEXT_CACHED_CHANGE)
2988 gtk_style_context_clear_cache (context);
2990 style_info_set_data (info, NULL);
2994 new = style_data_lookup (context)->store;
2996 changes = _gtk_css_computed_values_get_difference (new, old);
2998 g_object_unref (old);
3002 changes = _gtk_bitmask_new ();
3003 changes = _gtk_bitmask_invert_range (changes, 0, _gtk_css_style_property_get_n_properties ());
3007 changes = _gtk_bitmask_new ();
3009 if (!_gtk_bitmask_is_empty (changes))
3010 gtk_style_context_do_invalidate (context);
3012 change = _gtk_css_change_for_child (change);
3013 for (list = priv->children; list; list = list->next)
3015 _gtk_style_context_validate (list->data, timestamp, change);
3018 _gtk_bitmask_free (changes);
3022 _gtk_style_context_queue_invalidate (GtkStyleContext *context,
3023 GtkCssChange change)
3025 GtkStyleContextPrivate *priv;
3027 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3028 g_return_if_fail (change != 0);
3030 priv = context->priv;
3032 if (priv->widget == NULL && priv->widget_path == NULL)
3035 priv->pending_changes |= change;
3036 gtk_style_context_set_invalid (context, TRUE);
3040 * gtk_style_context_invalidate:
3041 * @context: a #GtkStyleContext.
3043 * Invalidates @context style information, so it will be reconstructed
3046 * If you're using a #GtkStyleContext returned from
3047 * gtk_widget_get_style_context(), you do not need to
3048 * call this yourself.
3053 gtk_style_context_invalidate (GtkStyleContext *context)
3055 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3057 gtk_style_context_clear_cache (context);
3058 gtk_style_context_do_invalidate (context);
3062 * gtk_style_context_set_background:
3063 * @context: a #GtkStyleContext
3064 * @window: a #GdkWindow
3066 * Sets the background of @window to the background pattern or
3067 * color specified in @context for its current state.
3072 gtk_style_context_set_background (GtkStyleContext *context,
3075 GtkStateFlags state;
3076 cairo_pattern_t *pattern;
3079 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3080 g_return_if_fail (GDK_IS_WINDOW (window));
3082 state = gtk_style_context_get_state (context);
3083 gtk_style_context_get (context, state,
3084 "background-image", &pattern,
3088 gdk_window_set_background_pattern (window, pattern);
3089 cairo_pattern_destroy (pattern);
3093 gtk_style_context_get (context, state,
3094 "background-color", &color,
3098 gdk_window_set_background_rgba (window, color);
3099 gdk_rgba_free (color);
3104 * gtk_style_context_get_color:
3105 * @context: a #GtkStyleContext
3106 * @state: state to retrieve the color for
3107 * @color: (out): return value for the foreground color
3109 * Gets the foreground color for a given state.
3114 gtk_style_context_get_color (GtkStyleContext *context,
3115 GtkStateFlags state,
3120 g_return_if_fail (color != NULL);
3121 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3123 gtk_style_context_get (context,
3133 * gtk_style_context_get_background_color:
3134 * @context: a #GtkStyleContext
3135 * @state: state to retrieve the color for
3136 * @color: (out): return value for the background color
3138 * Gets the background color for a given state.
3143 gtk_style_context_get_background_color (GtkStyleContext *context,
3144 GtkStateFlags state,
3149 g_return_if_fail (color != NULL);
3150 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3152 gtk_style_context_get (context,
3154 "background-color", &c,
3162 * gtk_style_context_get_border_color:
3163 * @context: a #GtkStyleContext
3164 * @state: state to retrieve the color for
3165 * @color: (out): return value for the border color
3167 * Gets the border color for a given state.
3172 gtk_style_context_get_border_color (GtkStyleContext *context,
3173 GtkStateFlags state,
3178 g_return_if_fail (color != NULL);
3179 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3181 gtk_style_context_get (context,
3191 * gtk_style_context_get_border:
3192 * @context: a #GtkStyleContext
3193 * @state: state to retrieve the border for
3194 * @border: (out): return value for the border settings
3196 * Gets the border for a given state as a #GtkBorder.
3197 * See %GTK_STYLE_PROPERTY_BORDER_WIDTH.
3202 gtk_style_context_get_border (GtkStyleContext *context,
3203 GtkStateFlags state,
3206 int top, left, bottom, right;
3208 g_return_if_fail (border != NULL);
3209 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3211 gtk_style_context_get (context,
3213 "border-top-width", &top,
3214 "border-left-width", &left,
3215 "border-bottom-width", &bottom,
3216 "border-right-width", &right,
3220 border->left = left;
3221 border->bottom = bottom;
3222 border->right = right;
3226 * gtk_style_context_get_padding:
3227 * @context: a #GtkStyleContext
3228 * @state: state to retrieve the padding for
3229 * @padding: (out): return value for the padding settings
3231 * Gets the padding for a given state as a #GtkBorder.
3232 * See %GTK_STYLE_PROPERTY_PADDING.
3237 gtk_style_context_get_padding (GtkStyleContext *context,
3238 GtkStateFlags state,
3241 int top, left, bottom, right;
3243 g_return_if_fail (padding != NULL);
3244 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3246 gtk_style_context_get (context,
3248 "padding-top", &top,
3249 "padding-left", &left,
3250 "padding-bottom", &bottom,
3251 "padding-right", &right,
3255 padding->left = left;
3256 padding->bottom = bottom;
3257 padding->right = right;
3261 * gtk_style_context_get_margin:
3262 * @context: a #GtkStyleContext
3263 * @state: state to retrieve the border for
3264 * @margin: (out): return value for the margin settings
3266 * Gets the margin for a given state as a #GtkBorder.
3267 * See %GTK_STYLE_PROPERTY_MARGIN.
3272 gtk_style_context_get_margin (GtkStyleContext *context,
3273 GtkStateFlags state,
3276 int top, left, bottom, right;
3278 g_return_if_fail (margin != NULL);
3279 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3281 gtk_style_context_get (context,
3284 "margin-left", &left,
3285 "margin-bottom", &bottom,
3286 "margin-right", &right,
3290 margin->left = left;
3291 margin->bottom = bottom;
3292 margin->right = right;
3296 * gtk_style_context_get_font:
3297 * @context: a #GtkStyleContext
3298 * @state: state to retrieve the font for
3300 * Returns the font description for a given state. The returned
3301 * object is const and will remain valid until the
3302 * #GtkStyleContext::changed signal happens.
3304 * Returns: (transfer none): the #PangoFontDescription for the given
3305 * state. This object is owned by GTK+ and should not be
3310 const PangoFontDescription *
3311 gtk_style_context_get_font (GtkStyleContext *context,
3312 GtkStateFlags state)
3314 GtkStyleContextPrivate *priv;
3316 PangoFontDescription *description;
3318 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
3320 priv = context->priv;
3321 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
3323 gtk_style_context_save (context);
3324 gtk_style_context_set_state (context, state);
3325 data = style_data_lookup (context);
3326 gtk_style_context_restore (context);
3328 /* Yuck, fonts are created on-demand but we don't return a ref.
3329 * Do bad things to achieve this requirement */
3330 description = g_object_get_data (G_OBJECT (data->store), "font-cache-for-get_font");
3331 if (description == NULL)
3333 gtk_style_context_get (context, state, "font", &description, NULL);
3334 g_object_set_data_full (G_OBJECT (data->store),
3335 "font-cache-for-get_font",
3337 (GDestroyNotify) pango_font_description_free);
3343 get_cursor_color (GtkStyleContext *context,
3347 GdkColor *style_color;
3349 gtk_style_context_get_style (context,
3350 primary ? "cursor-color" : "secondary-cursor-color",
3356 color->red = style_color->red / 65535.0;
3357 color->green = style_color->green / 65535.0;
3358 color->blue = style_color->blue / 65535.0;
3361 gdk_color_free (style_color);
3365 gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, color);
3371 gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &bg);
3373 color->red = (color->red + bg.red) * 0.5;
3374 color->green = (color->green + bg.green) * 0.5;
3375 color->blue = (color->blue + bg.blue) * 0.5;
3381 _gtk_style_context_get_cursor_color (GtkStyleContext *context,
3382 GdkRGBA *primary_color,
3383 GdkRGBA *secondary_color)
3386 get_cursor_color (context, TRUE, primary_color);
3388 if (secondary_color)
3389 get_cursor_color (context, FALSE, secondary_color);
3396 * @context: a #GtkStyleContext
3398 * @x: X origin of the rectangle
3399 * @y: Y origin of the rectangle
3400 * @width: rectangle width
3401 * @height: rectangle height
3403 * Renders a checkmark (as in a #GtkCheckButton).
3405 * The %GTK_STATE_FLAG_ACTIVE state determines whether the check is
3406 * on or off, and %GTK_STATE_FLAG_INCONSISTENT determines whether it
3407 * should be marked as undefined.
3410 * <title>Typical checkmark rendering</title>
3411 * <inlinegraphic fileref="checks.png" format="PNG"/>
3417 gtk_render_check (GtkStyleContext *context,
3424 GtkThemingEngineClass *engine_class;
3425 GtkThemingEngine *engine;
3427 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3428 g_return_if_fail (cr != NULL);
3430 if (width <= 0 || height <= 0)
3433 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3434 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3439 _gtk_theming_engine_set_context (engine, context);
3440 engine_class->render_check (engine, cr,
3441 x, y, width, height);
3447 * gtk_render_option:
3448 * @context: a #GtkStyleContext
3450 * @x: X origin of the rectangle
3451 * @y: Y origin of the rectangle
3452 * @width: rectangle width
3453 * @height: rectangle height
3455 * Renders an option mark (as in a #GtkRadioButton), the %GTK_STATE_FLAG_ACTIVE
3456 * state will determine whether the option is on or off, and
3457 * %GTK_STATE_FLAG_INCONSISTENT whether it should be marked as undefined.
3460 * <title>Typical option mark rendering</title>
3461 * <inlinegraphic fileref="options.png" format="PNG"/>
3467 gtk_render_option (GtkStyleContext *context,
3474 GtkThemingEngineClass *engine_class;
3475 GtkThemingEngine *engine;
3477 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3478 g_return_if_fail (cr != NULL);
3480 if (width <= 0 || height <= 0)
3483 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3484 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3488 _gtk_theming_engine_set_context (engine, context);
3489 engine_class->render_option (engine, cr,
3490 x, y, width, height);
3497 * @context: a #GtkStyleContext
3499 * @angle: arrow angle from 0 to 2 * %G_PI, being 0 the arrow pointing to the north
3500 * @x: X origin of the render area
3501 * @y: Y origin of the render area
3502 * @size: square side for render area
3504 * Renders an arrow pointing to @angle.
3507 * <title>Typical arrow rendering at 0, 1&solidus;2 π, π and 3&solidus;2 π</title>
3508 * <inlinegraphic fileref="arrows.png" format="PNG"/>
3514 gtk_render_arrow (GtkStyleContext *context,
3521 GtkThemingEngineClass *engine_class;
3522 GtkThemingEngine *engine;
3524 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3525 g_return_if_fail (cr != NULL);
3530 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3531 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3535 gtk_style_context_save (context);
3536 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ARROW);
3538 _gtk_theming_engine_set_context (engine, context);
3539 engine_class->render_arrow (engine, cr,
3542 gtk_style_context_restore (context);
3547 * gtk_render_background:
3548 * @context: a #GtkStyleContext
3550 * @x: X origin of the rectangle
3551 * @y: Y origin of the rectangle
3552 * @width: rectangle width
3553 * @height: rectangle height
3555 * Renders the background of an element.
3558 * <title>Typical background rendering, showing the effect of
3559 * <parameter>background-image</parameter>,
3560 * <parameter>border-width</parameter> and
3561 * <parameter>border-radius</parameter></title>
3562 * <inlinegraphic fileref="background.png" format="PNG"/>
3568 gtk_render_background (GtkStyleContext *context,
3575 GtkThemingEngineClass *engine_class;
3576 GtkThemingEngine *engine;
3578 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3579 g_return_if_fail (cr != NULL);
3581 if (width <= 0 || height <= 0)
3584 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3585 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3589 _gtk_theming_engine_set_context (engine, context);
3590 engine_class->render_background (engine, cr, x, y, width, height);
3597 * @context: a #GtkStyleContext
3599 * @x: X origin of the rectangle
3600 * @y: Y origin of the rectangle
3601 * @width: rectangle width
3602 * @height: rectangle height
3604 * Renders a frame around the rectangle defined by @x, @y, @width, @height.
3607 * <title>Examples of frame rendering, showing the effect of
3608 * <parameter>border-image</parameter>,
3609 * <parameter>border-color</parameter>,
3610 * <parameter>border-width</parameter>,
3611 * <parameter>border-radius</parameter> and
3613 * <inlinegraphic fileref="frames.png" format="PNG"/>
3619 gtk_render_frame (GtkStyleContext *context,
3626 GtkThemingEngineClass *engine_class;
3627 GtkThemingEngine *engine;
3629 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3630 g_return_if_fail (cr != NULL);
3632 if (width <= 0 || height <= 0)
3635 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3636 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3640 _gtk_theming_engine_set_context (engine, context);
3641 engine_class->render_frame (engine, cr, x, y, width, height);
3647 * gtk_render_expander:
3648 * @context: a #GtkStyleContext
3650 * @x: X origin of the rectangle
3651 * @y: Y origin of the rectangle
3652 * @width: rectangle width
3653 * @height: rectangle height
3655 * Renders an expander (as used in #GtkTreeView and #GtkExpander) in the area
3656 * defined by @x, @y, @width, @height. The state %GTK_STATE_FLAG_ACTIVE
3657 * determines whether the expander is collapsed or expanded.
3660 * <title>Typical expander rendering</title>
3661 * <inlinegraphic fileref="expanders.png" format="PNG"/>
3667 gtk_render_expander (GtkStyleContext *context,
3674 GtkThemingEngineClass *engine_class;
3675 GtkThemingEngine *engine;
3677 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3678 g_return_if_fail (cr != NULL);
3680 if (width <= 0 || height <= 0)
3683 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3684 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3688 _gtk_theming_engine_set_context (engine, context);
3689 engine_class->render_expander (engine, cr, x, y, width, height);
3696 * @context: a #GtkStyleContext
3698 * @x: X origin of the rectangle
3699 * @y: Y origin of the rectangle
3700 * @width: rectangle width
3701 * @height: rectangle height
3703 * Renders a focus indicator on the rectangle determined by @x, @y, @width, @height.
3705 * <title>Typical focus rendering</title>
3706 * <inlinegraphic fileref="focus.png" format="PNG"/>
3712 gtk_render_focus (GtkStyleContext *context,
3719 GtkThemingEngineClass *engine_class;
3720 GtkThemingEngine *engine;
3722 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3723 g_return_if_fail (cr != NULL);
3725 if (width <= 0 || height <= 0)
3728 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3729 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3733 _gtk_theming_engine_set_context (engine, context);
3734 engine_class->render_focus (engine, cr, x, y, width, height);
3740 * gtk_render_layout:
3741 * @context: a #GtkStyleContext
3745 * @layout: the #PangoLayout to render
3747 * Renders @layout on the coordinates @x, @y
3752 gtk_render_layout (GtkStyleContext *context,
3756 PangoLayout *layout)
3758 GtkThemingEngineClass *engine_class;
3759 GtkThemingEngine *engine;
3760 PangoRectangle extents;
3762 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3763 g_return_if_fail (PANGO_IS_LAYOUT (layout));
3764 g_return_if_fail (cr != NULL);
3766 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3767 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3771 pango_layout_get_extents (layout, &extents, NULL);
3773 _gtk_theming_engine_set_context (engine, context);
3774 engine_class->render_layout (engine, cr, x, y, layout);
3781 * @context: a #GtkStyleContext
3783 * @x0: X coordinate for the origin of the line
3784 * @y0: Y coordinate for the origin of the line
3785 * @x1: X coordinate for the end of the line
3786 * @y1: Y coordinate for the end of the line
3788 * Renders a line from (x0, y0) to (x1, y1).
3793 gtk_render_line (GtkStyleContext *context,
3800 GtkThemingEngineClass *engine_class;
3801 GtkThemingEngine *engine;
3803 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3804 g_return_if_fail (cr != NULL);
3806 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3807 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3811 _gtk_theming_engine_set_context (engine, context);
3812 engine_class->render_line (engine, cr, x0, y0, x1, y1);
3818 * gtk_render_slider:
3819 * @context: a #GtkStyleContext
3821 * @x: X origin of the rectangle
3822 * @y: Y origin of the rectangle
3823 * @width: rectangle width
3824 * @height: rectangle height
3825 * @orientation: orientation of the slider
3827 * Renders a slider (as in #GtkScale) in the rectangle defined by @x, @y,
3828 * @width, @height. @orientation defines whether the slider is vertical
3832 * <title>Typical slider rendering</title>
3833 * <inlinegraphic fileref="sliders.png" format="PNG"/>
3839 gtk_render_slider (GtkStyleContext *context,
3845 GtkOrientation orientation)
3847 GtkThemingEngineClass *engine_class;
3848 GtkThemingEngine *engine;
3850 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3851 g_return_if_fail (cr != NULL);
3853 if (width <= 0 || height <= 0)
3856 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3857 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3861 _gtk_theming_engine_set_context (engine, context);
3862 engine_class->render_slider (engine, cr, x, y, width, height, orientation);
3868 * gtk_render_frame_gap:
3869 * @context: a #GtkStyleContext
3871 * @x: X origin of the rectangle
3872 * @y: Y origin of the rectangle
3873 * @width: rectangle width
3874 * @height: rectangle height
3875 * @gap_side: side where the gap is
3876 * @xy0_gap: initial coordinate (X or Y depending on @gap_side) for the gap
3877 * @xy1_gap: end coordinate (X or Y depending on @gap_side) for the gap
3879 * Renders a frame around the rectangle defined by (@x, @y, @width, @height),
3880 * leaving a gap on one side. @xy0_gap and @xy1_gap will mean X coordinates
3881 * for %GTK_POS_TOP and %GTK_POS_BOTTOM gap sides, and Y coordinates for
3882 * %GTK_POS_LEFT and %GTK_POS_RIGHT.
3885 * <title>Typical rendering of a frame with a gap</title>
3886 * <inlinegraphic fileref="frame-gap.png" format="PNG"/>
3892 gtk_render_frame_gap (GtkStyleContext *context,
3898 GtkPositionType gap_side,
3902 GtkThemingEngineClass *engine_class;
3903 GtkThemingEngine *engine;
3905 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3906 g_return_if_fail (cr != NULL);
3907 g_return_if_fail (xy0_gap <= xy1_gap);
3908 g_return_if_fail (xy0_gap >= 0);
3910 if (width <= 0 || height <= 0)
3913 if (gap_side == GTK_POS_LEFT ||
3914 gap_side == GTK_POS_RIGHT)
3915 g_return_if_fail (xy1_gap <= height);
3917 g_return_if_fail (xy1_gap <= width);
3919 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3920 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3924 _gtk_theming_engine_set_context (engine, context);
3925 engine_class->render_frame_gap (engine, cr,
3926 x, y, width, height, gap_side,
3933 * gtk_render_extension:
3934 * @context: a #GtkStyleContext
3936 * @x: X origin of the rectangle
3937 * @y: Y origin of the rectangle
3938 * @width: rectangle width
3939 * @height: rectangle height
3940 * @gap_side: side where the gap is
3942 * Renders a extension (as in a #GtkNotebook tab) in the rectangle
3943 * defined by @x, @y, @width, @height. The side where the extension
3944 * connects to is defined by @gap_side.
3947 * <title>Typical extension rendering</title>
3948 * <inlinegraphic fileref="extensions.png" format="PNG"/>
3954 gtk_render_extension (GtkStyleContext *context,
3960 GtkPositionType gap_side)
3962 GtkThemingEngineClass *engine_class;
3963 GtkThemingEngine *engine;
3965 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3966 g_return_if_fail (cr != NULL);
3968 if (width <= 0 || height <= 0)
3971 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3972 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3976 _gtk_theming_engine_set_context (engine, context);
3977 engine_class->render_extension (engine, cr, x, y, width, height, gap_side);
3983 * gtk_render_handle:
3984 * @context: a #GtkStyleContext
3986 * @x: X origin of the rectangle
3987 * @y: Y origin of the rectangle
3988 * @width: rectangle width
3989 * @height: rectangle height
3991 * Renders a handle (as in #GtkHandleBox, #GtkPaned and
3992 * #GtkWindow<!-- -->'s resize grip), in the rectangle
3993 * determined by @x, @y, @width, @height.
3996 * <title>Handles rendered for the paned and grip classes</title>
3997 * <inlinegraphic fileref="handles.png" format="PNG"/>
4003 gtk_render_handle (GtkStyleContext *context,
4010 GtkThemingEngineClass *engine_class;
4011 GtkThemingEngine *engine;
4013 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4014 g_return_if_fail (cr != NULL);
4016 if (width <= 0 || height <= 0)
4019 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4020 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4024 _gtk_theming_engine_set_context (engine, context);
4025 engine_class->render_handle (engine, cr, x, y, width, height);
4031 * gtk_render_activity:
4032 * @context: a #GtkStyleContext
4034 * @x: X origin of the rectangle
4035 * @y: Y origin of the rectangle
4036 * @width: rectangle width
4037 * @height: rectangle height
4039 * Renders an activity area (Such as in #GtkSpinner or the
4040 * fill line in #GtkRange), the state %GTK_STATE_FLAG_ACTIVE
4041 * determines whether there is activity going on.
4046 gtk_render_activity (GtkStyleContext *context,
4053 GtkThemingEngineClass *engine_class;
4054 GtkThemingEngine *engine;
4056 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4057 g_return_if_fail (cr != NULL);
4059 if (width <= 0 || height <= 0)
4062 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4063 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4067 _gtk_theming_engine_set_context (engine, context);
4068 engine_class->render_activity (engine, cr, x, y, width, height);
4074 * gtk_render_icon_pixbuf:
4075 * @context: a #GtkStyleContext
4076 * @source: the #GtkIconSource specifying the icon to render
4077 * @size: (type int): the size to render the icon at. A size of (GtkIconSize) -1
4078 * means render at the size of the source and don't scale.
4080 * Renders the icon specified by @source at the given @size, returning the result
4083 * Returns: (transfer full): a newly-created #GdkPixbuf containing the rendered icon
4088 gtk_render_icon_pixbuf (GtkStyleContext *context,
4089 const GtkIconSource *source,
4092 GtkThemingEngineClass *engine_class;
4093 GtkThemingEngine *engine;
4095 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
4096 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
4097 g_return_val_if_fail (source != NULL, NULL);
4099 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4100 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4102 _gtk_theming_engine_set_context (engine, context);
4103 return engine_class->render_icon_pixbuf (engine, source, size);
4108 * @context: a #GtkStyleContext
4110 * @pixbuf: a #GdkPixbuf containing the icon to draw
4111 * @x: X position for the @pixbuf
4112 * @y: Y position for the @pixbuf
4114 * Renders the icon in @pixbuf at the specified @x and @y coordinates.
4119 gtk_render_icon (GtkStyleContext *context,
4125 GtkThemingEngineClass *engine_class;
4126 GtkThemingEngine *engine;
4128 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4129 g_return_if_fail (cr != NULL);
4131 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4132 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4136 _gtk_theming_engine_set_context (engine, context);
4137 engine_class->render_icon (engine, cr, pixbuf, x, y);
4143 draw_insertion_cursor (GtkStyleContext *context,
4148 gboolean is_primary,
4149 PangoDirection direction,
4150 gboolean draw_arrow)
4153 GdkRGBA primary_color;
4154 GdkRGBA secondary_color;
4155 gfloat cursor_aspect_ratio;
4161 _gtk_style_context_get_cursor_color (context, &primary_color, &secondary_color);
4162 gdk_cairo_set_source_rgba (cr, is_primary ? &primary_color : &secondary_color);
4164 /* When changing the shape or size of the cursor here,
4165 * propagate the changes to gtktextview.c:text_window_invalidate_cursors().
4168 gtk_style_context_get_style (context,
4169 "cursor-aspect-ratio", &cursor_aspect_ratio,
4172 stem_width = height * cursor_aspect_ratio + 1;
4174 /* put (stem_width % 2) on the proper side of the cursor */
4175 if (direction == PANGO_DIRECTION_LTR)
4176 offset = stem_width / 2;
4178 offset = stem_width - stem_width / 2;
4180 cairo_rectangle (cr, x - offset, y, stem_width, height);
4188 arrow_width = stem_width + 1;
4190 if (direction == PANGO_DIRECTION_RTL)
4192 ax = x - offset - 1;
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);
4200 else if (direction == PANGO_DIRECTION_LTR)
4202 ax = x + stem_width - offset;
4203 ay = y + height - arrow_width * 2 - arrow_width + 1;
4205 cairo_move_to (cr, ax, ay + 1);
4206 cairo_line_to (cr, ax + arrow_width, ay + arrow_width);
4207 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4211 g_assert_not_reached();
4218 * gtk_render_insertion_cursor:
4219 * @context: a #GtkStyleContext
4223 * @layout: the #PangoLayout of the text
4224 * @index: the index in the #PangoLayout
4225 * @direction: the #PangoDirection of the text
4227 * Draws a text caret on @cr at the specified index of @layout.
4232 gtk_render_insertion_cursor (GtkStyleContext *context,
4236 PangoLayout *layout,
4238 PangoDirection direction)
4240 GtkStyleContextPrivate *priv;
4241 gboolean split_cursor;
4242 PangoRectangle strong_pos, weak_pos;
4243 PangoRectangle *cursor1, *cursor2;
4244 PangoDirection keymap_direction;
4245 PangoDirection direction2;
4247 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4248 g_return_if_fail (cr != NULL);
4249 g_return_if_fail (PANGO_IS_LAYOUT (layout));
4250 g_return_if_fail (index >= 0);
4252 priv = context->priv;
4254 g_object_get (gtk_settings_get_for_screen (priv->screen),
4255 "gtk-split-cursor", &split_cursor,
4258 keymap_direction = gdk_keymap_get_direction (gdk_keymap_get_for_display (gdk_screen_get_display (priv->screen)));
4260 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4262 direction2 = PANGO_DIRECTION_NEUTRAL;
4266 cursor1 = &strong_pos;
4268 if (strong_pos.x != weak_pos.x || strong_pos.y != weak_pos.y)
4270 direction2 = (direction == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
4271 cursor2 = &weak_pos;
4276 if (keymap_direction == direction)
4277 cursor1 = &strong_pos;
4279 cursor1 = &weak_pos;
4282 draw_insertion_cursor (context,
4284 x + PANGO_PIXELS (cursor1->x),
4285 y + PANGO_PIXELS (cursor1->y),
4286 PANGO_PIXELS (cursor1->height),
4289 direction2 != PANGO_DIRECTION_NEUTRAL);
4291 if (direction2 != PANGO_DIRECTION_NEUTRAL)
4293 draw_insertion_cursor (context,
4295 x + PANGO_PIXELS (cursor2->x),
4296 y + PANGO_PIXELS (cursor2->y),
4297 PANGO_PIXELS (cursor2->height),
4305 * gtk_draw_insertion_cursor:
4306 * @widget: a #GtkWidget
4307 * @cr: cairo context to draw to
4308 * @location: location where to draw the cursor (@location->width is ignored)
4309 * @is_primary: if the cursor should be the primary cursor color.
4310 * @direction: whether the cursor is left-to-right or
4311 * right-to-left. Should never be #GTK_TEXT_DIR_NONE
4312 * @draw_arrow: %TRUE to draw a directional arrow on the
4313 * cursor. Should be %FALSE unless the cursor is split.
4315 * Draws a text caret on @cr at @location. This is not a style function
4316 * but merely a convenience function for drawing the standard cursor shape.
4319 * Deprecated: 3.4: Use gtk_render_insertion_cursor() instead.
4322 gtk_draw_insertion_cursor (GtkWidget *widget,
4324 const GdkRectangle *location,
4325 gboolean is_primary,
4326 GtkTextDirection direction,
4327 gboolean draw_arrow)
4329 GtkStyleContext *context;
4331 g_return_if_fail (GTK_IS_WIDGET (widget));
4332 g_return_if_fail (cr != NULL);
4333 g_return_if_fail (location != NULL);
4334 g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
4336 context = gtk_widget_get_style_context (widget);
4338 draw_insertion_cursor (context, cr,
4339 location->x, location->y, location->height,
4341 (direction == GTK_TEXT_DIR_RTL) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR,
4345 static AtkAttributeSet *
4346 add_attribute (AtkAttributeSet *attributes,
4347 AtkTextAttribute attr,
4352 at = g_new (AtkAttribute, 1);
4353 at->name = g_strdup (atk_text_attribute_get_name (attr));
4354 at->value = g_strdup (value);
4356 return g_slist_prepend (attributes, at);
4360 * _gtk_style_context_get_attributes:
4361 * @attributes: a #AtkAttributeSet to add attributes to
4362 * @context: the #GtkStyleContext to get attributes from
4363 * @flags: the state to use with @context
4365 * Adds the foreground and background color from @context to
4366 * @attributes, after translating them to ATK attributes.
4368 * This is a convenience function that can be used in
4369 * implementing the #AtkText interface in widgets.
4371 * Returns: the modified #AtkAttributeSet
4374 _gtk_style_context_get_attributes (AtkAttributeSet *attributes,
4375 GtkStyleContext *context,
4376 GtkStateFlags flags)
4381 gtk_style_context_get_background_color (context, flags, &color);
4382 value = g_strdup_printf ("%u,%u,%u",
4383 (guint) ceil (color.red * 65536 - color.red),
4384 (guint) ceil (color.green * 65536 - color.green),
4385 (guint) ceil (color.blue * 65536 - color.blue));
4386 attributes = add_attribute (attributes, ATK_TEXT_ATTR_BG_COLOR, value);
4389 gtk_style_context_get_color (context, flags, &color);
4390 value = g_strdup_printf ("%u,%u,%u",
4391 (guint) ceil (color.red * 65536 - color.red),
4392 (guint) ceil (color.green * 65536 - color.green),
4393 (guint) ceil (color.blue * 65536 - color.blue));
4394 attributes = add_attribute (attributes, ATK_TEXT_ATTR_FG_COLOR, value);