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 "gtkcsscolorvalueprivate.h"
28 #include "gtkcsscornervalueprivate.h"
29 #include "gtkcssenginevalueprivate.h"
30 #include "gtkcssnumbervalueprivate.h"
31 #include "gtkcssrgbavalueprivate.h"
33 #include "gtkstylepropertiesprivate.h"
34 #include "gtktypebuiltins.h"
35 #include "gtkthemingengineprivate.h"
37 #include "gtkwidget.h"
38 #include "gtkwindow.h"
39 #include "gtkprivate.h"
40 #include "gtkiconfactory.h"
41 #include "gtkwidgetpath.h"
42 #include "gtkwidgetprivate.h"
43 #include "gtkstylecascadeprivate.h"
44 #include "gtkstyleproviderprivate.h"
45 #include "gtksettings.h"
46 #include "gtksettingsprivate.h"
48 #include "deprecated/gtkgradientprivate.h"
49 #include "deprecated/gtksymboliccolorprivate.h"
52 * SECTION:gtkstylecontext
53 * @Short_description: Rendering UI elements
54 * @Title: GtkStyleContext
56 * #GtkStyleContext is an object that stores styling information affecting
57 * a widget defined by #GtkWidgetPath.
59 * In order to construct the final style information, #GtkStyleContext
60 * queries information from all attached #GtkStyleProviders. Style providers
61 * can be either attached explicitly to the context through
62 * gtk_style_context_add_provider(), or to the screen through
63 * gtk_style_context_add_provider_for_screen(). The resulting style is a
64 * combination of all providers' information in priority order.
66 * For GTK+ widgets, any #GtkStyleContext returned by
67 * gtk_widget_get_style_context() will already have a #GtkWidgetPath, a
68 * #GdkScreen and RTL/LTR information set. The style context will be also
69 * updated automatically if any of these settings change on the widget.
71 * If you are using the theming layer standalone, you will need to set a
72 * widget path and a screen yourself to the created style context through
73 * gtk_style_context_set_path() and gtk_style_context_set_screen(), as well
74 * as updating the context yourself using gtk_style_context_invalidate()
75 * whenever any of the conditions change, such as a change in the
76 * #GtkSettings:gtk-theme-name setting or a hierarchy change in the rendered
79 * <refsect2 id="gtkstylecontext-animations">
80 * <title>Transition animations</title>
82 * #GtkStyleContext has built-in support for state change transitions.
83 * Note that these animations respect the #GtkSettings:gtk-enable-animations
87 * For simple widgets where state changes affect the whole widget area,
88 * calling gtk_style_context_notify_state_change() with a %NULL region
89 * is sufficient to trigger the transition animation. And GTK+ already
90 * does that when gtk_widget_set_state() or gtk_widget_set_state_flags()
94 * If a widget needs to declare several animatable regions (i.e. not
95 * affecting the whole widget area), its #GtkWidget::draw signal handler
96 * needs to wrap the render operations for the different regions with
97 * calls to gtk_style_context_push_animatable_region() and
98 * gtk_style_context_pop_animatable_region(). These functions take an
99 * identifier for the region which must be unique within the style context.
100 * For simple widgets with a fixed set of animatable regions, using an
101 * enumeration works well:
104 * <title>Using an enumeration to identify animatable regions</title>
115 * spin_button_draw (GtkWidget *widget,
118 * GtkStyleContext *context;
120 * context = gtk_widget_get_style_context (widget);
122 * gtk_style_context_push_animatable_region (context,
123 * GUINT_TO_POINTER (REGION_ENTRY));
125 * gtk_render_background (cr, 0, 0, 100, 30);
126 * gtk_render_frame (cr, 0, 0, 100, 30);
128 * gtk_style_context_pop_animatable_region (context);
135 * For complex widgets with an arbitrary number of animatable regions, it
136 * is up to the implementation to come up with a way to uniquely identify
137 * each animatable region. Using pointers to internal structs is one way
141 * <title>Using struct pointers to identify animatable regions</title>
144 * notebook_draw_tab (GtkWidget *widget,
145 * NotebookPage *page,
148 * gtk_style_context_push_animatable_region (context, page);
149 * gtk_render_extension (cr, page->x, page->y, page->width, page->height);
150 * gtk_style_context_pop_animatable_region (context);
155 * The widget also needs to notify the style context about a state change
156 * for a given animatable region so the animation is triggered.
159 * <title>Triggering a state change animation on a region</title>
162 * notebook_motion_notify (GtkWidget *widget,
163 * GdkEventMotion *event)
165 * GtkStyleContext *context;
166 * NotebookPage *page;
168 * context = gtk_widget_get_style_context (widget);
169 * page = find_page_under_pointer (widget, event);
170 * gtk_style_context_notify_state_change (context,
171 * gtk_widget_get_window (widget),
173 * GTK_STATE_PRELIGHT,
180 * gtk_style_context_notify_state_change() accepts %NULL region IDs as a
181 * special value, in this case, the whole widget area will be updated
185 * <refsect2 id="gtkstylecontext-classes">
186 * <title>Style classes and regions</title>
188 * Widgets can add style classes to their context, which can be used
189 * to associate different styles by class (see <xref linkend="gtkcssprovider-selectors"/>). Theme engines can also use style classes to vary their
190 * rendering. GTK+ has a number of predefined style classes:
191 * #GTK_STYLE_CLASS_CELL,
192 * #GTK_STYLE_CLASS_ENTRY,
193 * #GTK_STYLE_CLASS_BUTTON,
194 * #GTK_STYLE_CLASS_COMBOBOX_ENTRY,
195 * #GTK_STYLE_CLASS_CALENDAR,
196 * #GTK_STYLE_CLASS_SLIDER,
197 * #GTK_STYLE_CLASS_BACKGROUND,
198 * #GTK_STYLE_CLASS_RUBBERBAND,
199 * #GTK_STYLE_CLASS_TOOLTIP,
200 * #GTK_STYLE_CLASS_MENU,
201 * #GTK_STYLE_CLASS_MENUBAR,
202 * #GTK_STYLE_CLASS_MENUITEM,
203 * #GTK_STYLE_CLASS_TOOLBAR,
204 * #GTK_STYLE_CLASS_PRIMARY_TOOLBAR,
205 * #GTK_STYLE_CLASS_INLINE_TOOLBAR,
206 * #GTK_STYLE_CLASS_RADIO,
207 * #GTK_STYLE_CLASS_CHECK,
208 * #GTK_STYLE_CLASS_TROUGH,
209 * #GTK_STYLE_CLASS_SCROLLBAR,
210 * #GTK_STYLE_CLASS_SCALE,
211 * #GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE,
212 * #GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW,
213 * #GTK_STYLE_CLASS_HEADER,
214 * #GTK_STYLE_CLASS_ACCELERATOR,
215 * #GTK_STYLE_CLASS_GRIP,
216 * #GTK_STYLE_CLASS_DOCK,
217 * #GTK_STYLE_CLASS_PROGRESSBAR,
218 * #GTK_STYLE_CLASS_SPINNER,
219 * #GTK_STYLE_CLASS_EXPANDER,
220 * #GTK_STYLE_CLASS_SPINBUTTON,
221 * #GTK_STYLE_CLASS_NOTEBOOK,
222 * #GTK_STYLE_CLASS_VIEW,
223 * #GTK_STYLE_CLASS_SIDEBAR,
224 * #GTK_STYLE_CLASS_IMAGE,
225 * #GTK_STYLE_CLASS_HIGHLIGHT,
226 * #GTK_STYLE_CLASS_FRAME,
227 * #GTK_STYLE_CLASS_DND,
228 * #GTK_STYLE_CLASS_PANE_SEPARATOR,
229 * #GTK_STYLE_CLASS_SEPARATOR,
230 * #GTK_STYLE_CLASS_INFO,
231 * #GTK_STYLE_CLASS_WARNING,
232 * #GTK_STYLE_CLASS_QUESTION,
233 * #GTK_STYLE_CLASS_ERROR,
234 * #GTK_STYLE_CLASS_HORIZONTAL,
235 * #GTK_STYLE_CLASS_VERTICAL,
236 * #GTK_STYLE_CLASS_TOP,
237 * #GTK_STYLE_CLASS_BOTTOM,
238 * #GTK_STYLE_CLASS_LEFT,
239 * #GTK_STYLE_CLASS_RIGHT,
242 * Widgets can also add regions with flags to their context.
243 * The regions used by GTK+ widgets are:
248 * <entry>Region</entry>
249 * <entry>Flags</entry>
250 * <entry>Macro</entry>
251 * <entry>Used by</entry>
257 * <entry>even, odd</entry>
258 * <entry>GTK_STYLE_REGION_ROW</entry>
259 * <entry>#GtkTreeView</entry>
262 * <entry>column</entry>
263 * <entry>first, last, sorted</entry>
264 * <entry>GTK_STYLE_REGION_COLUMN</entry>
265 * <entry>#GtkTreeView</entry>
268 * <entry>column-header</entry>
270 * <entry>GTK_STYLE_REGION_COLUMN_HEADER</entry>
275 * <entry>even, odd, first, last</entry>
276 * <entry>GTK_STYLE_REGION_TAB</entry>
277 * <entry>#GtkNotebook</entry>
284 * <refsect2 id="gtkstylecontext-custom-styling">
285 * <title>Custom styling in UI libraries and applications</title>
287 * If you are developing a library with custom #GtkWidget<!-- -->s that
288 * render differently than standard components, you may need to add a
289 * #GtkStyleProvider yourself with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK
290 * priority, either a #GtkCssProvider or a custom object implementing the
291 * #GtkStyleProvider interface. This way theming engines may still attempt
292 * to style your UI elements in a different way if needed so.
295 * If you are using custom styling on an applications, you probably want then
296 * to make your style information prevail to the theme's, so you must use
297 * a #GtkStyleProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
298 * priority, keep in mind that the user settings in
299 * <filename><replaceable>XDG_CONFIG_HOME</replaceable>/gtk-3.0/gtk.css</filename> will
300 * still take precedence over your changes, as it uses the
301 * %GTK_STYLE_PROVIDER_PRIORITY_USER priority.
304 * If a custom theming engine is needed, you probably want to implement a
305 * #GtkStyleProvider yourself so it points to your #GtkThemingEngine
306 * implementation, as #GtkCssProvider uses gtk_theming_engine_load()
307 * which loads the theming engine module from the standard paths.
312 /* When these change we do a full restyling. Otherwise we try to figure out
313 * if we need to change things. */
314 #define GTK_STYLE_CONTEXT_RADICAL_CHANGE (GTK_CSS_CHANGE_NAME | GTK_CSS_CHANGE_CLASS | GTK_CSS_CHANGE_SOURCE)
315 /* When these change we don't clear the cache. This takes more memory but makes
316 * things go faster. */
317 #define GTK_STYLE_CONTEXT_CACHED_CHANGE (GTK_CSS_CHANGE_STATE)
319 typedef struct GtkStyleInfo GtkStyleInfo;
320 typedef struct GtkRegion GtkRegion;
321 typedef struct PropertyValue PropertyValue;
322 typedef struct StyleData StyleData;
327 GtkRegionFlags flags;
341 GArray *style_classes;
343 GtkJunctionSides junction_sides;
344 GtkStateFlags state_flags;
350 GtkCssComputedValues *store;
351 GArray *property_cache;
355 struct _GtkStyleContextPrivate
359 GtkStyleCascade *cascade;
361 GtkStyleContext *parent;
364 GtkWidgetPath *widget_path;
365 GHashTable *style_data;
368 GdkFrameClock *frame_clock;
369 guint frame_clock_update_id;
371 GtkCssChange relevant_changes;
372 GtkCssChange pending_changes;
374 const GtkBitmask *invalidating_context;
391 static guint signals[LAST_SIGNAL] = { 0 };
393 static void gtk_style_context_finalize (GObject *object);
395 static void frame_clock_target_iface_init (GdkFrameClockTargetInterface *target);
397 static void gtk_style_context_impl_set_property (GObject *object,
401 static void gtk_style_context_impl_get_property (GObject *object,
405 static StyleData *style_data_lookup (GtkStyleContext *context);
408 static void gtk_style_context_disconnect_update (GtkStyleContext *context);
409 static void gtk_style_context_connect_update (GtkStyleContext *context);
411 G_DEFINE_TYPE_WITH_CODE (GtkStyleContext, gtk_style_context, G_TYPE_OBJECT,
412 G_IMPLEMENT_INTERFACE (GDK_TYPE_FRAME_CLOCK_TARGET, frame_clock_target_iface_init))
415 gtk_style_context_real_changed (GtkStyleContext *context)
417 GtkStyleContextPrivate *priv = context->priv;
420 _gtk_widget_style_context_invalidated (priv->widget);
424 gtk_style_context_class_init (GtkStyleContextClass *klass)
426 GObjectClass *object_class = G_OBJECT_CLASS (klass);
428 object_class->finalize = gtk_style_context_finalize;
429 object_class->set_property = gtk_style_context_impl_set_property;
430 object_class->get_property = gtk_style_context_impl_get_property;
432 klass->changed = gtk_style_context_real_changed;
435 g_signal_new (I_("changed"),
436 G_TYPE_FROM_CLASS (object_class),
438 G_STRUCT_OFFSET (GtkStyleContextClass, changed),
440 g_cclosure_marshal_VOID__VOID,
443 g_object_class_install_property (object_class,
445 g_param_spec_object ("screen",
447 P_("The associated GdkScreen"),
449 GTK_PARAM_READWRITE));
450 g_object_class_install_property (object_class,
452 g_param_spec_enum ("direction",
454 P_("Text direction"),
455 GTK_TYPE_TEXT_DIRECTION,
457 GTK_PARAM_READWRITE));
459 * GtkStyleContext:parent:
461 * Sets or gets the style context's parent. See gtk_style_context_set_parent()
466 g_object_class_install_property (object_class,
468 g_param_spec_object ("parent",
470 P_("The parent style context"),
471 GTK_TYPE_STYLE_CONTEXT,
472 GTK_PARAM_READWRITE));
474 g_type_class_add_private (object_class, sizeof (GtkStyleContextPrivate));
478 gtk_style_context_set_clock (GdkFrameClockTarget *target,
479 GdkFrameClock *clock)
481 GtkStyleContext *context = GTK_STYLE_CONTEXT (target);
482 GtkStyleContextPrivate *priv = context->priv;
484 gtk_style_context_disconnect_update (context);
485 priv->frame_clock = clock;
487 gtk_style_context_connect_update (context);
491 frame_clock_target_iface_init (GdkFrameClockTargetInterface *iface)
493 iface->set_clock = gtk_style_context_set_clock;
497 style_data_new (void)
501 data = g_slice_new0 (StyleData);
508 clear_property_cache (StyleData *data)
512 if (!data->property_cache)
515 for (i = 0; i < data->property_cache->len; i++)
517 PropertyValue *node = &g_array_index (data->property_cache, PropertyValue, i);
519 g_param_spec_unref (node->pspec);
520 g_value_unset (&node->value);
523 g_array_free (data->property_cache, TRUE);
524 data->property_cache = NULL;
528 style_data_ref (StyleData *style_data)
530 style_data->ref_count++;
536 style_data_unref (StyleData *data)
540 if (data->ref_count > 0)
543 g_object_unref (data->store);
544 clear_property_cache (data);
546 g_slice_free (StyleData, data);
550 style_data_is_animating (StyleData *style_data)
552 return !_gtk_css_computed_values_is_static (style_data->store);
555 static GtkStyleInfo *
556 style_info_new (void)
560 info = g_slice_new0 (GtkStyleInfo);
561 info->style_classes = g_array_new (FALSE, FALSE, sizeof (GQuark));
562 info->regions = g_array_new (FALSE, FALSE, sizeof (GtkRegion));
568 style_info_set_data (GtkStyleInfo *info,
571 if (info->data == data)
575 style_data_ref (data);
578 style_data_unref (info->data);
584 style_info_free (GtkStyleInfo *info)
586 style_info_set_data (info, NULL);
587 g_array_free (info->style_classes, TRUE);
588 g_array_free (info->regions, TRUE);
589 g_slice_free (GtkStyleInfo, info);
592 static GtkStyleInfo *
593 style_info_pop (GtkStyleInfo *info)
595 GtkStyleInfo *next = info->next;
597 style_info_free (info);
602 static GtkStyleInfo *
603 style_info_copy (GtkStyleInfo *info)
607 copy = style_info_new ();
608 g_array_insert_vals (copy->style_classes, 0,
609 info->style_classes->data,
610 info->style_classes->len);
612 g_array_insert_vals (copy->regions, 0,
617 copy->junction_sides = info->junction_sides;
618 copy->state_flags = info->state_flags;
619 style_info_set_data (copy, info->data);
625 style_info_hash (gconstpointer elem)
627 const GtkStyleInfo *info;
632 for (i = 0; i < info->style_classes->len; i++)
634 hash += g_array_index (info->style_classes, GQuark, i);
638 for (i = 0; i < info->regions->len; i++)
642 region = &g_array_index (info->regions, GtkRegion, i);
643 hash += region->class_quark;
644 hash += region->flags;
648 return hash ^ info->state_flags;
652 style_info_equal (gconstpointer elem1,
655 const GtkStyleInfo *info1, *info2;
660 if (info1->state_flags != info2->state_flags)
663 if (info1->junction_sides != info2->junction_sides)
666 if (info1->style_classes->len != info2->style_classes->len)
669 if (memcmp (info1->style_classes->data,
670 info2->style_classes->data,
671 info1->style_classes->len * sizeof (GQuark)) != 0)
674 if (info1->regions->len != info2->regions->len)
677 if (memcmp (info1->regions->data,
678 info2->regions->data,
679 info1->regions->len * sizeof (GtkRegion)) != 0)
686 gtk_style_context_cascade_changed (GtkStyleCascade *cascade,
687 GtkStyleContext *context)
689 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_SOURCE);
693 gtk_style_context_set_cascade (GtkStyleContext *context,
694 GtkStyleCascade *cascade)
696 GtkStyleContextPrivate *priv;
698 priv = context->priv;
700 if (priv->cascade == cascade)
705 g_object_ref (cascade);
706 g_signal_connect (cascade,
707 "-gtk-private-changed",
708 G_CALLBACK (gtk_style_context_cascade_changed),
714 g_signal_handlers_disconnect_by_func (priv->cascade,
715 gtk_style_context_cascade_changed,
717 g_object_unref (priv->cascade);
720 priv->cascade = cascade;
723 gtk_style_context_cascade_changed (cascade, context);
727 gtk_style_context_init (GtkStyleContext *style_context)
729 GtkStyleContextPrivate *priv;
731 priv = style_context->priv = G_TYPE_INSTANCE_GET_PRIVATE (style_context,
732 GTK_TYPE_STYLE_CONTEXT,
733 GtkStyleContextPrivate);
735 priv->style_data = g_hash_table_new_full (style_info_hash,
737 (GDestroyNotify) style_info_free,
738 (GDestroyNotify) style_data_unref);
740 priv->screen = gdk_screen_get_default ();
741 priv->relevant_changes = GTK_CSS_CHANGE_ANY;
743 /* Create default info store */
744 priv->info = style_info_new ();
745 priv->info->state_flags = GTK_STATE_FLAG_DIR_LTR;
747 gtk_style_context_set_cascade (style_context,
748 _gtk_style_cascade_get_for_screen (priv->screen));
752 gtk_style_context_update (GdkFrameClock *clock,
753 GtkStyleContext *context)
755 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANIMATE);
757 /* A little blech to request one more than we need */
758 gdk_frame_clock_request_phase (clock, GDK_FRAME_CLOCK_PHASE_UPDATE);
762 gtk_style_context_is_animating (GtkStyleContext *context)
764 GtkStyleContextPrivate *priv = context->priv;
766 return priv->animating;
770 gtk_style_context_disconnect_update (GtkStyleContext *context)
772 GtkStyleContextPrivate *priv = context->priv;
774 if (priv->frame_clock && priv->frame_clock_update_id)
776 g_signal_handler_disconnect (priv->frame_clock,
777 priv->frame_clock_update_id);
778 priv->frame_clock_update_id = 0;
783 gtk_style_context_connect_update (GtkStyleContext *context)
785 GtkStyleContextPrivate *priv = context->priv;
787 if (priv->frame_clock && priv->frame_clock_update_id == 0)
789 priv->frame_clock_update_id = g_signal_connect (priv->frame_clock,
791 G_CALLBACK (gtk_style_context_update),
793 gdk_frame_clock_request_phase (priv->frame_clock, GDK_FRAME_CLOCK_PHASE_UPDATE);
798 gtk_style_context_stop_animating (GtkStyleContext *context)
800 GtkStyleContextPrivate *priv = context->priv;
802 if (!gtk_style_context_is_animating (context))
805 priv->animating = FALSE;
807 gtk_style_context_disconnect_update (context);
810 gtk_widget_remove_frame_clock_target (priv->widget,
811 GDK_FRAME_CLOCK_TARGET (context));
816 gtk_style_context_start_animating (GtkStyleContext *context)
818 GtkStyleContextPrivate *priv = context->priv;
820 if (gtk_style_context_is_animating (context))
823 priv->animating = TRUE;
825 gtk_style_context_connect_update (context);
828 gtk_widget_add_frame_clock_target (priv->widget,
829 GDK_FRAME_CLOCK_TARGET (context));
834 gtk_style_context_should_animate (GtkStyleContext *context)
836 GtkStyleContextPrivate *priv;
840 priv = context->priv;
842 if (priv->widget == NULL)
845 if (!gtk_widget_get_mapped (priv->widget))
848 data = style_data_lookup (context);
849 if (!style_data_is_animating (data))
852 g_object_get (gtk_widget_get_settings (context->priv->widget),
853 "gtk-enable-animations", &animate,
860 _gtk_style_context_update_animating (GtkStyleContext *context)
862 if (gtk_style_context_should_animate (context))
863 gtk_style_context_start_animating (context);
865 gtk_style_context_stop_animating (context);
869 gtk_style_context_finalize (GObject *object)
871 GtkStyleContextPrivate *priv;
872 GtkStyleContext *style_context;
874 style_context = GTK_STYLE_CONTEXT (object);
875 priv = style_context->priv;
877 gtk_style_context_stop_animating (style_context);
879 /* children hold a reference to us */
880 g_assert (priv->children == NULL);
882 gtk_style_context_set_parent (style_context, NULL);
884 gtk_style_context_set_cascade (style_context, NULL);
886 if (priv->widget_path)
887 gtk_widget_path_free (priv->widget_path);
889 g_hash_table_destroy (priv->style_data);
892 priv->info = style_info_pop (priv->info);
894 G_OBJECT_CLASS (gtk_style_context_parent_class)->finalize (object);
898 gtk_style_context_impl_set_property (GObject *object,
903 GtkStyleContext *style_context;
905 style_context = GTK_STYLE_CONTEXT (object);
910 gtk_style_context_set_screen (style_context,
911 g_value_get_object (value));
914 G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
915 gtk_style_context_set_direction (style_context,
916 g_value_get_enum (value));
917 G_GNUC_END_IGNORE_DEPRECATIONS;
920 gtk_style_context_set_parent (style_context,
921 g_value_get_object (value));
924 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
930 gtk_style_context_impl_get_property (GObject *object,
935 GtkStyleContext *style_context;
936 GtkStyleContextPrivate *priv;
938 style_context = GTK_STYLE_CONTEXT (object);
939 priv = style_context->priv;
944 g_value_set_object (value, priv->screen);
947 G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
948 g_value_set_enum (value, gtk_style_context_get_direction (style_context));
949 G_GNUC_END_IGNORE_DEPRECATIONS;
952 g_value_set_object (value, priv->parent);
955 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
960 static GtkWidgetPath *
961 create_query_path (GtkStyleContext *context,
964 GtkStyleContextPrivate *priv;
968 priv = context->priv;
969 path = priv->widget ? _gtk_widget_create_path (priv->widget) : gtk_widget_path_copy (priv->widget_path);
970 pos = gtk_widget_path_length (path) - 1;
972 /* Set widget regions */
973 for (i = 0; i < info->regions->len; i++)
977 region = &g_array_index (info->regions, GtkRegion, i);
978 gtk_widget_path_iter_add_region (path, pos,
979 g_quark_to_string (region->class_quark),
983 /* Set widget classes */
984 for (i = 0; i < info->style_classes->len; i++)
988 quark = g_array_index (info->style_classes, GQuark, i);
989 gtk_widget_path_iter_add_class (path, pos,
990 g_quark_to_string (quark));
997 build_properties (GtkStyleContext *context,
998 GtkCssComputedValues *values,
1000 const GtkBitmask *relevant_changes)
1002 GtkStyleContextPrivate *priv;
1003 GtkCssMatcher matcher;
1004 GtkWidgetPath *path;
1005 GtkCssLookup *lookup;
1007 priv = context->priv;
1009 path = create_query_path (context, info);
1010 lookup = _gtk_css_lookup_new (relevant_changes);
1012 if (_gtk_css_matcher_init (&matcher, path, info->state_flags))
1013 _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
1017 _gtk_css_lookup_resolve (lookup,
1018 GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
1020 priv->parent ? style_data_lookup (priv->parent)->store : NULL);
1022 _gtk_css_lookup_free (lookup);
1023 gtk_widget_path_free (path);
1027 style_data_lookup (GtkStyleContext *context)
1029 GtkStyleContextPrivate *priv;
1033 priv = context->priv;
1036 /* Current data in use is cached, just return it */
1040 g_assert (priv->widget != NULL || priv->widget_path != NULL);
1042 data = g_hash_table_lookup (priv->style_data, info);
1045 style_info_set_data (info, data);
1049 data = style_data_new ();
1050 data->store = _gtk_css_computed_values_new ();
1051 style_info_set_data (info, data);
1052 g_hash_table_insert (priv->style_data,
1053 style_info_copy (info),
1056 build_properties (context, data->store, info, NULL);
1062 style_data_lookup_for_state (GtkStyleContext *context,
1063 GtkStateFlags state)
1067 if (context->priv->info->state_flags == state)
1068 return style_data_lookup (context);
1070 gtk_style_context_save (context);
1071 gtk_style_context_set_state (context, state);
1072 data = style_data_lookup (context);
1073 gtk_style_context_restore (context);
1079 gtk_style_context_set_invalid (GtkStyleContext *context,
1082 GtkStyleContextPrivate *priv;
1084 priv = context->priv;
1086 if (priv->invalid == invalid)
1089 priv->invalid = invalid;
1094 gtk_style_context_set_invalid (priv->parent, TRUE);
1095 else if (GTK_IS_RESIZE_CONTAINER (priv->widget))
1096 _gtk_container_queue_restyle (GTK_CONTAINER (priv->widget));
1100 /* returns TRUE if someone called gtk_style_context_save() but hasn't
1101 * called gtk_style_context_restore() yet.
1102 * In those situations we don't invalidate the context when somebody
1103 * changes state/regions/classes.
1106 gtk_style_context_is_saved (GtkStyleContext *context)
1108 return context->priv->info->next != NULL;
1112 gtk_style_context_queue_invalidate_internal (GtkStyleContext *context,
1113 GtkCssChange change)
1115 GtkStyleContextPrivate *priv = context->priv;
1116 GtkStyleInfo *info = priv->info;
1118 if (gtk_style_context_is_saved (context))
1120 style_info_set_data (info, NULL);
1124 _gtk_style_context_queue_invalidate (context, change);
1125 /* XXX: We need to invalidate siblings here somehow */
1130 * gtk_style_context_new:
1132 * Creates a standalone #GtkStyleContext, this style context
1133 * won't be attached to any widget, so you may want
1134 * to call gtk_style_context_set_path() yourself.
1137 * This function is only useful when using the theming layer
1138 * separated from GTK+, if you are using #GtkStyleContext to
1139 * theme #GtkWidget<!-- -->s, use gtk_widget_get_style_context()
1140 * in order to get a style context ready to theme the widget.
1143 * Returns: A newly created #GtkStyleContext.
1146 gtk_style_context_new (void)
1148 return g_object_new (GTK_TYPE_STYLE_CONTEXT, NULL);
1152 _gtk_style_context_set_widget (GtkStyleContext *context,
1155 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1156 g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget));
1158 context->priv->widget = widget;
1160 _gtk_style_context_update_animating (context);
1162 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY_SELF);
1166 * gtk_style_context_add_provider:
1167 * @context: a #GtkStyleContext
1168 * @provider: a #GtkStyleProvider
1169 * @priority: the priority of the style provider. The lower
1170 * it is, the earlier it will be used in the style
1171 * construction. Typically this will be in the range
1172 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1173 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1175 * Adds a style provider to @context, to be used in style construction.
1176 * Note that a style provider added by this function only affects
1177 * the style of the widget to which @context belongs. If you want
1178 * to affect the style of all widgets, use
1179 * gtk_style_context_add_provider_for_screen().
1181 * <note><para>If both priorities are the same, A #GtkStyleProvider
1182 * added through this function takes precedence over another added
1183 * through gtk_style_context_add_provider_for_screen().</para></note>
1188 gtk_style_context_add_provider (GtkStyleContext *context,
1189 GtkStyleProvider *provider,
1192 GtkStyleContextPrivate *priv;
1194 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1195 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1197 priv = context->priv;
1199 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
1201 GtkStyleCascade *new_cascade;
1203 new_cascade = _gtk_style_cascade_new ();
1204 _gtk_style_cascade_set_parent (new_cascade, priv->cascade);
1205 _gtk_style_cascade_add_provider (new_cascade, provider, priority);
1206 gtk_style_context_set_cascade (context, new_cascade);
1207 g_object_unref (new_cascade);
1211 _gtk_style_cascade_add_provider (priv->cascade, provider, priority);
1216 * gtk_style_context_remove_provider:
1217 * @context: a #GtkStyleContext
1218 * @provider: a #GtkStyleProvider
1220 * Removes @provider from the style providers list in @context.
1225 gtk_style_context_remove_provider (GtkStyleContext *context,
1226 GtkStyleProvider *provider)
1228 GtkStyleContextPrivate *priv;
1230 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1231 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1233 priv = context->priv;
1235 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
1238 _gtk_style_cascade_remove_provider (priv->cascade, provider);
1242 * gtk_style_context_reset_widgets:
1243 * @screen: a #GdkScreen
1245 * This function recomputes the styles for all widgets under a particular
1246 * #GdkScreen. This is useful when some global parameter has changed that
1247 * affects the appearance of all widgets, because when a widget gets a new
1248 * style, it will both redraw and recompute any cached information about
1249 * its appearance. As an example, it is used when the color scheme changes
1250 * in the related #GtkSettings object.
1255 gtk_style_context_reset_widgets (GdkScreen *screen)
1257 GList *list, *toplevels;
1259 _gtk_icon_set_invalidate_caches ();
1261 toplevels = gtk_window_list_toplevels ();
1262 g_list_foreach (toplevels, (GFunc) g_object_ref, NULL);
1264 for (list = toplevels; list; list = list->next)
1266 if (gtk_widget_get_screen (list->data) == screen)
1267 gtk_widget_reset_style (list->data);
1269 g_object_unref (list->data);
1272 g_list_free (toplevels);
1276 * gtk_style_context_add_provider_for_screen:
1277 * @screen: a #GdkScreen
1278 * @provider: a #GtkStyleProvider
1279 * @priority: the priority of the style provider. The lower
1280 * it is, the earlier it will be used in the style
1281 * construction. Typically this will be in the range
1282 * between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and
1283 * %GTK_STYLE_PROVIDER_PRIORITY_USER
1285 * Adds a global style provider to @screen, which will be used
1286 * in style construction for all #GtkStyleContexts under @screen.
1288 * GTK+ uses this to make styling information from #GtkSettings
1291 * <note><para>If both priorities are the same, A #GtkStyleProvider
1292 * added through gtk_style_context_add_provider() takes precedence
1293 * over another added through this function.</para></note>
1298 gtk_style_context_add_provider_for_screen (GdkScreen *screen,
1299 GtkStyleProvider *provider,
1302 GtkStyleCascade *cascade;
1304 g_return_if_fail (GDK_IS_SCREEN (screen));
1305 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1306 g_return_if_fail (!GTK_IS_SETTINGS (provider) || _gtk_settings_get_screen (GTK_SETTINGS (provider)) == screen);
1308 cascade = _gtk_style_cascade_get_for_screen (screen);
1309 _gtk_style_cascade_add_provider (cascade, provider, priority);
1313 * gtk_style_context_remove_provider_for_screen:
1314 * @screen: a #GdkScreen
1315 * @provider: a #GtkStyleProvider
1317 * Removes @provider from the global style providers list in @screen.
1322 gtk_style_context_remove_provider_for_screen (GdkScreen *screen,
1323 GtkStyleProvider *provider)
1325 GtkStyleCascade *cascade;
1327 g_return_if_fail (GDK_IS_SCREEN (screen));
1328 g_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
1329 g_return_if_fail (!GTK_IS_SETTINGS (provider));
1331 cascade = _gtk_style_cascade_get_for_screen (screen);
1332 _gtk_style_cascade_remove_provider (cascade, provider);
1336 * gtk_style_context_get_section:
1337 * @context: a #GtkStyleContext
1338 * @property: style property name
1340 * Queries the location in the CSS where @property was defined for the
1341 * current @context. Note that the state to be queried is taken from
1342 * gtk_style_context_get_state().
1344 * If the location is not available, %NULL will be returned. The
1345 * location might not be available for various reasons, such as the
1346 * property being overridden, @property not naming a supported CSS
1347 * property or tracking of definitions being disabled for performance
1350 * Shorthand CSS properties cannot be queried for a location and will
1351 * always return %NULL.
1353 * Returns: %NULL or the section where value was defined
1356 gtk_style_context_get_section (GtkStyleContext *context,
1357 const gchar *property)
1359 GtkStyleContextPrivate *priv;
1360 GtkStyleProperty *prop;
1363 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1364 g_return_val_if_fail (property != NULL, NULL);
1366 priv = context->priv;
1367 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
1369 prop = _gtk_style_property_lookup (property);
1370 if (!GTK_IS_CSS_STYLE_PROPERTY (prop))
1373 data = style_data_lookup (context);
1374 return _gtk_css_computed_values_get_section (data->store, _gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (prop)));
1377 static GtkCssValue *
1378 gtk_style_context_query_func (guint id,
1381 return _gtk_css_computed_values_get_value (values, id);
1385 * gtk_style_context_get_property:
1386 * @context: a #GtkStyleContext
1387 * @property: style property name
1388 * @state: state to retrieve the property value for
1389 * @value: (out) (transfer full): return location for the style property value
1391 * Gets a style property from @context for the given state.
1393 * When @value is no longer needed, g_value_unset() must be called
1394 * to free any allocated memory.
1399 gtk_style_context_get_property (GtkStyleContext *context,
1400 const gchar *property,
1401 GtkStateFlags state,
1404 GtkStyleContextPrivate *priv;
1405 GtkStyleProperty *prop;
1408 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1409 g_return_if_fail (property != NULL);
1410 g_return_if_fail (value != NULL);
1412 priv = context->priv;
1413 g_return_if_fail (priv->widget != NULL || priv->widget_path != NULL);
1415 prop = _gtk_style_property_lookup (property);
1418 g_warning ("Style property \"%s\" is not registered", property);
1421 if (_gtk_style_property_get_value_type (prop) == G_TYPE_NONE)
1423 g_warning ("Style property \"%s\" is not gettable", property);
1427 data = style_data_lookup_for_state (context, state);
1428 _gtk_style_property_query (prop, value, gtk_style_context_query_func, data->store);
1432 * gtk_style_context_get_valist:
1433 * @context: a #GtkStyleContext
1434 * @state: state to retrieve the property values for
1435 * @args: va_list of property name/return location pairs, followed by %NULL
1437 * Retrieves several style property values from @context for a given state.
1442 gtk_style_context_get_valist (GtkStyleContext *context,
1443 GtkStateFlags state,
1446 const gchar *property_name;
1448 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1450 property_name = va_arg (args, const gchar *);
1452 while (property_name)
1454 gchar *error = NULL;
1455 GValue value = G_VALUE_INIT;
1457 gtk_style_context_get_property (context,
1462 G_VALUE_LCOPY (&value, args, 0, &error);
1463 g_value_unset (&value);
1467 g_warning ("Could not get style property \"%s\": %s", property_name, error);
1472 property_name = va_arg (args, const gchar *);
1477 * gtk_style_context_get:
1478 * @context: a #GtkStyleContext
1479 * @state: state to retrieve the property values for
1480 * @...: property name /return value pairs, followed by %NULL
1482 * Retrieves several style property values from @context for a
1488 gtk_style_context_get (GtkStyleContext *context,
1489 GtkStateFlags state,
1494 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1496 va_start (args, state);
1497 gtk_style_context_get_valist (context, state, args);
1502 * gtk_style_context_set_state:
1503 * @context: a #GtkStyleContext
1504 * @flags: state to represent
1506 * Sets the state to be used when rendering with any
1507 * of the gtk_render_*() functions.
1512 gtk_style_context_set_state (GtkStyleContext *context,
1513 GtkStateFlags flags)
1515 GtkStateFlags old_flags;
1516 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1518 old_flags = context->priv->info->state_flags;
1519 if (old_flags == flags)
1522 context->priv->info->state_flags = flags;
1524 if (((old_flags ^ flags) & (GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL)) &&
1525 !gtk_style_context_is_saved (context))
1526 g_object_notify (G_OBJECT (context), "direction");
1528 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_STATE);
1532 * gtk_style_context_get_state:
1533 * @context: a #GtkStyleContext
1535 * Returns the state used when rendering.
1537 * Returns: the state flags
1542 gtk_style_context_get_state (GtkStyleContext *context)
1544 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
1546 return context->priv->info->state_flags;
1550 * gtk_style_context_state_is_running:
1551 * @context: a #GtkStyleContext
1552 * @state: a widget state
1553 * @progress: (out): return location for the transition progress
1555 * Returns %TRUE if there is a transition animation running for the
1556 * current region (see gtk_style_context_push_animatable_region()).
1558 * If @progress is not %NULL, the animation progress will be returned
1559 * there, 0.0 means the state is closest to being unset, while 1.0 means
1560 * it's closest to being set. This means transition animation will
1561 * run from 0 to 1 when @state is being set and from 1 to 0 when
1564 * Returns: %TRUE if there is a running transition animation for @state.
1568 * Deprecated: 3.6: This function always returns %FALSE
1571 gtk_style_context_state_is_running (GtkStyleContext *context,
1575 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1581 * gtk_style_context_set_path:
1582 * @context: a #GtkStyleContext
1583 * @path: a #GtkWidgetPath
1585 * Sets the #GtkWidgetPath used for style matching. As a
1586 * consequence, the style will be regenerated to match
1587 * the new given path.
1589 * If you are using a #GtkStyleContext returned from
1590 * gtk_widget_get_style_context(), you do not need to call
1596 gtk_style_context_set_path (GtkStyleContext *context,
1597 GtkWidgetPath *path)
1599 GtkStyleContextPrivate *priv;
1601 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1602 g_return_if_fail (path != NULL);
1604 priv = context->priv;
1605 g_return_if_fail (priv->widget == NULL);
1607 if (priv->widget_path)
1609 gtk_widget_path_free (priv->widget_path);
1610 priv->widget_path = NULL;
1614 priv->widget_path = gtk_widget_path_copy (path);
1616 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY);
1620 * gtk_style_context_get_path:
1621 * @context: a #GtkStyleContext
1623 * Returns the widget path used for style matching.
1625 * Returns: (transfer none): A #GtkWidgetPath
1629 const GtkWidgetPath *
1630 gtk_style_context_get_path (GtkStyleContext *context)
1632 GtkStyleContextPrivate *priv;
1634 priv = context->priv;
1636 return gtk_widget_get_path (priv->widget);
1638 return priv->widget_path;
1642 * gtk_style_context_set_parent:
1643 * @context: a #GtkStyleContext
1644 * @parent: (allow-none): the new parent or %NULL
1646 * Sets the parent style context for @context. The parent style
1647 * context is used to implement
1648 * <ulink url="http://www.w3.org/TR/css3-cascade/#inheritance">inheritance</ulink>
1651 * If you are using a #GtkStyleContext returned from
1652 * gtk_widget_get_style_context(), the parent will be set for you.
1657 gtk_style_context_set_parent (GtkStyleContext *context,
1658 GtkStyleContext *parent)
1660 GtkStyleContextPrivate *priv;
1662 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1663 g_return_if_fail (parent == NULL || GTK_IS_STYLE_CONTEXT (parent));
1665 priv = context->priv;
1667 if (priv->parent == parent)
1672 parent->priv->children = g_slist_prepend (parent->priv->children, context);
1673 g_object_ref (parent);
1675 gtk_style_context_set_invalid (parent, TRUE);
1680 priv->parent->priv->children = g_slist_remove (priv->parent->priv->children, context);
1681 g_object_unref (priv->parent);
1684 priv->parent = parent;
1686 g_object_notify (G_OBJECT (context), "parent");
1687 _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_ANY_PARENT | GTK_CSS_CHANGE_ANY_SIBLING);
1691 * gtk_style_context_get_parent:
1692 * @context: a #GtkStyleContext
1694 * Gets the parent context set via gtk_style_context_set_parent().
1695 * See that function for details.
1697 * Returns: (transfer none): the parent context or %NULL
1702 gtk_style_context_get_parent (GtkStyleContext *context)
1704 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1706 return context->priv->parent;
1710 * gtk_style_context_save:
1711 * @context: a #GtkStyleContext
1713 * Saves the @context state, so all modifications done through
1714 * gtk_style_context_add_class(), gtk_style_context_remove_class(),
1715 * gtk_style_context_add_region(), gtk_style_context_remove_region()
1716 * or gtk_style_context_set_junction_sides() can be reverted in one
1717 * go through gtk_style_context_restore().
1722 gtk_style_context_save (GtkStyleContext *context)
1724 GtkStyleContextPrivate *priv;
1726 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1728 priv = context->priv;
1730 priv->info = style_info_copy (priv->info);
1731 /* Need to unset animations here because we can not know what style
1732 * class potential transitions came from once we save().
1734 if (priv->info->data && style_data_is_animating (priv->info->data))
1735 style_info_set_data (priv->info, NULL);
1739 * gtk_style_context_restore:
1740 * @context: a #GtkStyleContext
1742 * Restores @context state to a previous stage.
1743 * See gtk_style_context_save().
1748 gtk_style_context_restore (GtkStyleContext *context)
1750 GtkStyleContextPrivate *priv;
1752 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1754 priv = context->priv;
1756 priv->info = style_info_pop (priv->info);
1760 g_warning ("Unpaired gtk_style_context_restore() call");
1762 /* Create default region */
1763 priv->info = style_info_new ();
1768 style_class_find (GArray *array,
1773 gboolean found = FALSE;
1779 if (!array || array->len == 0)
1783 max = array->len - 1;
1789 mid = (min + max) / 2;
1790 item = g_array_index (array, GQuark, mid);
1792 if (class_quark == item)
1797 else if (class_quark > item)
1798 min = pos = mid + 1;
1805 while (!found && min <= max);
1814 region_find (GArray *array,
1819 gboolean found = FALSE;
1825 if (!array || array->len == 0)
1829 max = array->len - 1;
1835 mid = (min + max) / 2;
1836 region = &g_array_index (array, GtkRegion, mid);
1838 if (region->class_quark == class_quark)
1843 else if (region->class_quark > class_quark)
1844 min = pos = mid + 1;
1851 while (!found && min <= max);
1860 * gtk_style_context_add_class:
1861 * @context: a #GtkStyleContext
1862 * @class_name: class name to use in styling
1864 * Adds a style class to @context, so posterior calls to
1865 * gtk_style_context_get() or any of the gtk_render_*()
1866 * functions will make use of this new class for styling.
1868 * In the CSS file format, a #GtkEntry defining an "entry"
1869 * class, would be matched by:
1872 * GtkEntry.entry { ... }
1875 * While any widget defining an "entry" class would be
1884 gtk_style_context_add_class (GtkStyleContext *context,
1885 const gchar *class_name)
1887 GtkStyleContextPrivate *priv;
1892 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1893 g_return_if_fail (class_name != NULL);
1895 priv = context->priv;
1896 class_quark = g_quark_from_string (class_name);
1900 if (!style_class_find (info->style_classes, class_quark, &position))
1902 g_array_insert_val (info->style_classes, position, class_quark);
1904 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_CLASS);
1909 * gtk_style_context_remove_class:
1910 * @context: a #GtkStyleContext
1911 * @class_name: class name to remove
1913 * Removes @class_name from @context.
1918 gtk_style_context_remove_class (GtkStyleContext *context,
1919 const gchar *class_name)
1921 GtkStyleContextPrivate *priv;
1926 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
1927 g_return_if_fail (class_name != NULL);
1929 class_quark = g_quark_try_string (class_name);
1934 priv = context->priv;
1938 if (style_class_find (info->style_classes, class_quark, &position))
1940 g_array_remove_index (info->style_classes, position);
1942 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_CLASS);
1947 * gtk_style_context_has_class:
1948 * @context: a #GtkStyleContext
1949 * @class_name: a class name
1951 * Returns %TRUE if @context currently has defined the
1954 * Returns: %TRUE if @context has @class_name defined
1959 gtk_style_context_has_class (GtkStyleContext *context,
1960 const gchar *class_name)
1962 GtkStyleContextPrivate *priv;
1966 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
1967 g_return_val_if_fail (class_name != NULL, FALSE);
1969 class_quark = g_quark_try_string (class_name);
1974 priv = context->priv;
1978 if (style_class_find (info->style_classes, class_quark, NULL))
1985 * gtk_style_context_list_classes:
1986 * @context: a #GtkStyleContext
1988 * Returns the list of classes currently defined in @context.
1990 * Returns: (transfer container) (element-type utf8): a #GList of
1991 * strings with the currently defined classes. The contents
1992 * of the list are owned by GTK+, but you must free the list
1993 * itself with g_list_free() when you are done with it.
1998 gtk_style_context_list_classes (GtkStyleContext *context)
2000 GtkStyleContextPrivate *priv;
2002 GList *classes = NULL;
2005 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2007 priv = context->priv;
2011 for (i = 0; i < info->style_classes->len; i++)
2015 quark = g_array_index (info->style_classes, GQuark, i);
2016 classes = g_list_prepend (classes, (gchar *) g_quark_to_string (quark));
2023 * gtk_style_context_list_regions:
2024 * @context: a #GtkStyleContext
2026 * Returns the list of regions currently defined in @context.
2028 * Returns: (transfer container) (element-type utf8): a #GList of
2029 * strings with the currently defined regions. The contents
2030 * of the list are owned by GTK+, but you must free the list
2031 * itself with g_list_free() when you are done with it.
2036 gtk_style_context_list_regions (GtkStyleContext *context)
2038 GtkStyleContextPrivate *priv;
2040 GList *classes = NULL;
2043 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2045 priv = context->priv;
2049 for (i = 0; i < info->regions->len; i++)
2052 const gchar *class_name;
2054 region = &g_array_index (info->regions, GtkRegion, i);
2056 class_name = g_quark_to_string (region->class_quark);
2057 classes = g_list_prepend (classes, (gchar *) class_name);
2064 _gtk_style_context_check_region_name (const gchar *str)
2066 g_return_val_if_fail (str != NULL, FALSE);
2068 if (!g_ascii_islower (str[0]))
2074 !g_ascii_islower (*str))
2084 * gtk_style_context_add_region:
2085 * @context: a #GtkStyleContext
2086 * @region_name: region name to use in styling
2087 * @flags: flags that apply to the region
2089 * Adds a region to @context, so posterior calls to
2090 * gtk_style_context_get() or any of the gtk_render_*()
2091 * functions will make use of this new region for styling.
2093 * In the CSS file format, a #GtkTreeView defining a "row"
2094 * region, would be matched by:
2097 * GtkTreeView row { ... }
2100 * Pseudo-classes are used for matching @flags, so the two
2103 * GtkTreeView row:nth-child(even) { ... }
2104 * GtkTreeView row:nth-child(odd) { ... }
2107 * would apply to even and odd rows, respectively.
2109 * <note><para>Region names must only contain lowercase letters
2110 * and '-', starting always with a lowercase letter.</para></note>
2115 gtk_style_context_add_region (GtkStyleContext *context,
2116 const gchar *region_name,
2117 GtkRegionFlags flags)
2119 GtkStyleContextPrivate *priv;
2121 GQuark region_quark;
2124 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2125 g_return_if_fail (region_name != NULL);
2126 g_return_if_fail (_gtk_style_context_check_region_name (region_name));
2128 priv = context->priv;
2129 region_quark = g_quark_from_string (region_name);
2133 if (!region_find (info->regions, region_quark, &position))
2137 region.class_quark = region_quark;
2138 region.flags = flags;
2140 g_array_insert_val (info->regions, position, region);
2142 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_REGION);
2147 * gtk_style_context_remove_region:
2148 * @context: a #GtkStyleContext
2149 * @region_name: region name to unset
2151 * Removes a region from @context.
2156 gtk_style_context_remove_region (GtkStyleContext *context,
2157 const gchar *region_name)
2159 GtkStyleContextPrivate *priv;
2161 GQuark region_quark;
2164 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2165 g_return_if_fail (region_name != NULL);
2167 region_quark = g_quark_try_string (region_name);
2172 priv = context->priv;
2176 if (region_find (info->regions, region_quark, &position))
2178 g_array_remove_index (info->regions, position);
2180 gtk_style_context_queue_invalidate_internal (context, GTK_CSS_CHANGE_REGION);
2185 * gtk_style_context_has_region:
2186 * @context: a #GtkStyleContext
2187 * @region_name: a region name
2188 * @flags_return: (out) (allow-none): return location for region flags
2190 * Returns %TRUE if @context has the region defined.
2191 * If @flags_return is not %NULL, it is set to the flags
2192 * affecting the region.
2194 * Returns: %TRUE if region is defined
2199 gtk_style_context_has_region (GtkStyleContext *context,
2200 const gchar *region_name,
2201 GtkRegionFlags *flags_return)
2203 GtkStyleContextPrivate *priv;
2205 GQuark region_quark;
2208 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2209 g_return_val_if_fail (region_name != NULL, FALSE);
2214 region_quark = g_quark_try_string (region_name);
2219 priv = context->priv;
2223 if (region_find (info->regions, region_quark, &position))
2229 region = &g_array_index (info->regions, GtkRegion, position);
2230 *flags_return = region->flags;
2239 style_property_values_cmp (gconstpointer bsearch_node1,
2240 gconstpointer bsearch_node2)
2242 const PropertyValue *val1 = bsearch_node1;
2243 const PropertyValue *val2 = bsearch_node2;
2245 if (val1->widget_type != val2->widget_type)
2246 return val1->widget_type < val2->widget_type ? -1 : 1;
2248 if (val1->pspec != val2->pspec)
2249 return val1->pspec < val2->pspec ? -1 : 1;
2251 if (val1->state != val2->state)
2252 return val1->state < val2->state ? -1 : 1;
2258 _gtk_style_context_peek_property (GtkStyleContext *context,
2261 StyleData *data = style_data_lookup (context);
2263 return _gtk_css_computed_values_get_value (data->store, property_id);
2267 _gtk_style_context_peek_style_property (GtkStyleContext *context,
2269 GtkStateFlags state,
2272 GtkStyleContextPrivate *priv;
2273 PropertyValue *pcache, key = { 0 };
2277 priv = context->priv;
2279 data = style_data_lookup_for_state (context, state);
2281 key.widget_type = widget_type;
2285 /* need value cache array */
2286 if (!data->property_cache)
2287 data->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
2290 pcache = bsearch (&key,
2291 data->property_cache->data, data->property_cache->len,
2292 sizeof (PropertyValue), style_property_values_cmp);
2294 return &pcache->value;
2298 while (i < data->property_cache->len &&
2299 style_property_values_cmp (&key, &g_array_index (data->property_cache, PropertyValue, i)) >= 0)
2302 g_array_insert_val (data->property_cache, i, key);
2303 pcache = &g_array_index (data->property_cache, PropertyValue, i);
2305 /* cache miss, initialize value type, then set contents */
2306 g_param_spec_ref (pcache->pspec);
2307 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2309 if (priv->widget || priv->widget_path)
2311 GtkWidgetPath *widget_path = priv->widget ? _gtk_widget_create_path (priv->widget) : priv->widget_path;
2313 if (gtk_style_provider_get_style_property (GTK_STYLE_PROVIDER (priv->cascade),
2315 state, pspec, &pcache->value))
2317 G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
2319 /* Resolve symbolic colors to GdkColor/GdkRGBA */
2320 if (G_VALUE_TYPE (&pcache->value) == GTK_TYPE_SYMBOLIC_COLOR)
2322 GtkSymbolicColor *color;
2325 color = g_value_dup_boxed (&pcache->value);
2327 g_value_unset (&pcache->value);
2329 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2330 g_value_init (&pcache->value, GDK_TYPE_RGBA);
2332 g_value_init (&pcache->value, GDK_TYPE_COLOR);
2334 if (_gtk_style_context_resolve_color (context, _gtk_symbolic_color_get_css_value (color), &rgba, NULL))
2336 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
2337 g_value_set_boxed (&pcache->value, &rgba);
2342 rgb.red = rgba.red * 65535. + 0.5;
2343 rgb.green = rgba.green * 65535. + 0.5;
2344 rgb.blue = rgba.blue * 65535. + 0.5;
2346 g_value_set_boxed (&pcache->value, &rgb);
2350 g_param_value_set_default (pspec, &pcache->value);
2352 gtk_symbolic_color_unref (color);
2355 G_GNUC_END_IGNORE_DEPRECATIONS;
2358 gtk_widget_path_free (widget_path);
2360 return &pcache->value;
2364 gtk_widget_path_free (widget_path);
2367 /* not supplied by any provider, revert to default */
2368 g_param_value_set_default (pspec, &pcache->value);
2370 return &pcache->value;
2374 * gtk_style_context_get_style_property:
2375 * @context: a #GtkStyleContext
2376 * @property_name: the name of the widget style property
2377 * @value: Return location for the property value
2379 * Gets the value for a widget style property.
2381 * When @value is no longer needed, g_value_unset() must be called
2382 * to free any allocated memory.
2385 gtk_style_context_get_style_property (GtkStyleContext *context,
2386 const gchar *property_name,
2389 GtkStyleContextPrivate *priv;
2390 GtkWidgetClass *widget_class;
2391 GtkStateFlags state;
2393 const GValue *peek_value;
2396 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2397 g_return_if_fail (property_name != NULL);
2398 g_return_if_fail (value != NULL);
2400 priv = context->priv;
2404 widget_type = G_OBJECT_TYPE (priv->widget);
2408 if (!priv->widget_path)
2411 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2413 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2415 g_warning ("%s: can't get style properties for non-widget class `%s'",
2417 g_type_name (widget_type));
2422 widget_class = g_type_class_ref (widget_type);
2423 pspec = gtk_widget_class_find_style_property (widget_class, property_name);
2424 g_type_class_unref (widget_class);
2428 g_warning ("%s: widget class `%s' has no style property named `%s'",
2430 g_type_name (widget_type),
2435 state = gtk_style_context_get_state (context);
2436 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2439 if (G_VALUE_TYPE (value) == G_VALUE_TYPE (peek_value))
2440 g_value_copy (peek_value, value);
2441 else if (g_value_type_transformable (G_VALUE_TYPE (peek_value), G_VALUE_TYPE (value)))
2442 g_value_transform (peek_value, value);
2444 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
2446 G_VALUE_TYPE_NAME (peek_value),
2447 G_VALUE_TYPE_NAME (value));
2451 * gtk_style_context_get_style_valist:
2452 * @context: a #GtkStyleContext
2453 * @args: va_list of property name/return location pairs, followed by %NULL
2455 * Retrieves several widget style properties from @context according to the
2461 gtk_style_context_get_style_valist (GtkStyleContext *context,
2464 GtkStyleContextPrivate *priv;
2465 const gchar *prop_name;
2466 GtkStateFlags state;
2469 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2471 prop_name = va_arg (args, const gchar *);
2472 priv = context->priv;
2476 widget_type = G_OBJECT_TYPE (priv->widget);
2480 if (!priv->widget_path)
2483 widget_type = gtk_widget_path_get_object_type (priv->widget_path);
2485 if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
2487 g_warning ("%s: can't get style properties for non-widget class `%s'",
2489 g_type_name (widget_type));
2494 state = gtk_style_context_get_state (context);
2498 GtkWidgetClass *widget_class;
2500 const GValue *peek_value;
2503 widget_class = g_type_class_ref (widget_type);
2504 pspec = gtk_widget_class_find_style_property (widget_class, prop_name);
2505 g_type_class_unref (widget_class);
2509 g_warning ("%s: widget class `%s' has no style property named `%s'",
2511 g_type_name (widget_type),
2516 peek_value = _gtk_style_context_peek_style_property (context, widget_type,
2519 G_VALUE_LCOPY (peek_value, args, 0, &error);
2523 g_warning ("can't retrieve style property `%s' of type `%s': %s",
2525 G_VALUE_TYPE_NAME (peek_value),
2531 prop_name = va_arg (args, const gchar *);
2536 * gtk_style_context_get_style:
2537 * @context: a #GtkStyleContext
2538 * @...: property name /return value pairs, followed by %NULL
2540 * Retrieves several widget style properties from @context according to the
2546 gtk_style_context_get_style (GtkStyleContext *context,
2551 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2553 va_start (args, context);
2554 gtk_style_context_get_style_valist (context, args);
2560 * gtk_style_context_lookup_icon_set:
2561 * @context: a #GtkStyleContext
2562 * @stock_id: an icon name
2564 * Looks up @stock_id in the icon factories associated to @context and
2565 * the default icon factory, returning an icon set if found, otherwise
2568 * Returns: (transfer none): The looked up %GtkIconSet, or %NULL
2571 gtk_style_context_lookup_icon_set (GtkStyleContext *context,
2572 const gchar *stock_id)
2574 GtkStyleContextPrivate *priv;
2576 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2577 g_return_val_if_fail (stock_id != NULL, NULL);
2579 priv = context->priv;
2580 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
2582 return gtk_icon_factory_lookup_default (stock_id);
2586 * gtk_style_context_set_screen:
2587 * @context: a #GtkStyleContext
2588 * @screen: a #GdkScreen
2590 * Attaches @context to the given screen.
2592 * The screen is used to add style information from 'global' style
2593 * providers, such as the screens #GtkSettings instance.
2595 * If you are using a #GtkStyleContext returned from
2596 * gtk_widget_get_style_context(), you do not need to
2597 * call this yourself.
2602 gtk_style_context_set_screen (GtkStyleContext *context,
2605 GtkStyleContextPrivate *priv;
2607 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2608 g_return_if_fail (GDK_IS_SCREEN (screen));
2610 priv = context->priv;
2611 if (priv->screen == screen)
2614 if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
2616 gtk_style_context_set_cascade (context, _gtk_style_cascade_get_for_screen (screen));
2620 _gtk_style_cascade_set_parent (priv->cascade, _gtk_style_cascade_get_for_screen (screen));
2623 priv->screen = screen;
2625 g_object_notify (G_OBJECT (context), "screen");
2629 * gtk_style_context_get_screen:
2630 * @context: a #GtkStyleContext
2632 * Returns the #GdkScreen to which @context is attached.
2634 * Returns: (transfer none): a #GdkScreen.
2637 gtk_style_context_get_screen (GtkStyleContext *context)
2639 GtkStyleContextPrivate *priv;
2641 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
2643 priv = context->priv;
2644 return priv->screen;
2648 * gtk_style_context_set_direction:
2649 * @context: a #GtkStyleContext
2650 * @direction: the new direction.
2652 * Sets the reading direction for rendering purposes.
2654 * If you are using a #GtkStyleContext returned from
2655 * gtk_widget_get_style_context(), you do not need to
2656 * call this yourself.
2660 * Deprecated: 3.8: Use gtk_style_context_set_state() with
2661 * #GTK_STATE_FLAG_DIR_LTR and #GTK_STATE_FLAG_DIR_RTL
2665 gtk_style_context_set_direction (GtkStyleContext *context,
2666 GtkTextDirection direction)
2668 GtkStateFlags state;
2670 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2672 state = gtk_style_context_get_state (context);
2673 state &= ~(GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL);
2677 case GTK_TEXT_DIR_LTR:
2678 state |= GTK_STATE_FLAG_DIR_LTR;
2681 case GTK_TEXT_DIR_RTL:
2682 state |= GTK_STATE_FLAG_DIR_RTL;
2685 case GTK_TEXT_DIR_NONE:
2690 gtk_style_context_set_state (context, state);
2694 * gtk_style_context_get_direction:
2695 * @context: a #GtkStyleContext
2697 * Returns the widget direction used for rendering.
2699 * Returns: the widget direction
2703 * Deprecated: 3.8: Use gtk_style_context_get_state() and
2704 * check for #GTK_STATE_FLAG_DIR_LTR and
2705 * #GTK_STATE_FLAG_DIR_RTL instead.
2708 gtk_style_context_get_direction (GtkStyleContext *context)
2710 GtkStateFlags state;
2712 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), GTK_TEXT_DIR_LTR);
2714 state = gtk_style_context_get_state (context);
2716 if (state & GTK_STATE_FLAG_DIR_LTR)
2717 return GTK_TEXT_DIR_LTR;
2718 else if (state & GTK_STATE_FLAG_DIR_RTL)
2719 return GTK_TEXT_DIR_RTL;
2721 return GTK_TEXT_DIR_NONE;
2725 * gtk_style_context_set_junction_sides:
2726 * @context: a #GtkStyleContext
2727 * @sides: sides where rendered elements are visually connected to
2730 * Sets the sides where rendered elements (mostly through
2731 * gtk_render_frame()) will visually connect with other visual elements.
2733 * This is merely a hint that may or may not be honored
2734 * by theming engines.
2736 * Container widgets are expected to set junction hints as appropriate
2737 * for their children, so it should not normally be necessary to call
2738 * this function manually.
2743 gtk_style_context_set_junction_sides (GtkStyleContext *context,
2744 GtkJunctionSides sides)
2746 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2748 context->priv->info->junction_sides = sides;
2752 * gtk_style_context_get_junction_sides:
2753 * @context: a #GtkStyleContext
2755 * Returns the sides where rendered elements connect visually with others.
2757 * Returns: the junction sides
2762 gtk_style_context_get_junction_sides (GtkStyleContext *context)
2764 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
2766 return context->priv->info->junction_sides;
2770 _gtk_style_context_resolve_color (GtkStyleContext *context,
2773 GtkCssDependencies *dependencies)
2777 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2778 g_return_val_if_fail (color != NULL, FALSE);
2779 g_return_val_if_fail (result != NULL, FALSE);
2781 val = _gtk_css_color_value_resolve (color,
2782 GTK_STYLE_PROVIDER_PRIVATE (context->priv->cascade),
2783 _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR),
2784 GTK_CSS_DEPENDS_ON_COLOR,
2789 *result = *_gtk_css_rgba_value_get_rgba (val);
2790 _gtk_css_value_unref (val);
2795 * gtk_style_context_lookup_color:
2796 * @context: a #GtkStyleContext
2797 * @color_name: color name to lookup
2798 * @color: (out): Return location for the looked up color
2800 * Looks up and resolves a color name in the @context color map.
2802 * Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
2805 gtk_style_context_lookup_color (GtkStyleContext *context,
2806 const gchar *color_name,
2811 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
2812 g_return_val_if_fail (color_name != NULL, FALSE);
2813 g_return_val_if_fail (color != NULL, FALSE);
2815 value = _gtk_style_provider_private_get_color (GTK_STYLE_PROVIDER_PRIVATE (context->priv->cascade), color_name);
2819 return _gtk_style_context_resolve_color (context, value, color, NULL);
2823 * gtk_style_context_notify_state_change:
2824 * @context: a #GtkStyleContext
2825 * @window: a #GdkWindow
2826 * @region_id: (allow-none): animatable region to notify on, or %NULL.
2827 * See gtk_style_context_push_animatable_region()
2828 * @state: state to trigger transition for
2829 * @state_value: %TRUE if @state is the state we are changing to,
2830 * %FALSE if we are changing away from it
2832 * Notifies a state change on @context, so if the current style makes use
2833 * of transition animations, one will be started so all rendered elements
2834 * under @region_id are animated for state @state being set to value
2837 * The @window parameter is used in order to invalidate the rendered area
2838 * as the animation runs, so make sure it is the same window that is being
2839 * rendered on by the gtk_render_*() functions.
2841 * If @region_id is %NULL, all rendered elements using @context will be
2842 * affected by this state transition.
2844 * As a practical example, a #GtkButton notifying a state transition on
2845 * the prelight state:
2847 * gtk_style_context_notify_state_change (context,
2848 * gtk_widget_get_window (widget),
2850 * GTK_STATE_PRELIGHT,
2851 * button->in_button);
2854 * Can be handled in the CSS file like this:
2857 * background-color: #f00
2861 * background-color: #fff;
2862 * transition: 200ms linear
2866 * This combination will animate the button background from red to white
2867 * if a pointer enters the button, and back to red if the pointer leaves
2870 * Note that @state is used when finding the transition parameters, which
2871 * is why the style places the transition under the :hover pseudo-class.
2875 * Deprecated: 3.6: This function does nothing.
2878 gtk_style_context_notify_state_change (GtkStyleContext *context,
2882 gboolean state_value)
2884 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2885 g_return_if_fail (GDK_IS_WINDOW (window));
2886 g_return_if_fail (state > GTK_STATE_NORMAL && state <= GTK_STATE_FOCUSED);
2887 g_return_if_fail (context->priv->widget != NULL || context->priv->widget_path != NULL);
2891 * gtk_style_context_cancel_animations:
2892 * @context: a #GtkStyleContext
2893 * @region_id: (allow-none): animatable region to stop, or %NULL.
2894 * See gtk_style_context_push_animatable_region()
2896 * Stops all running animations for @region_id and all animatable
2897 * regions underneath.
2899 * A %NULL @region_id will stop all ongoing animations in @context,
2900 * when dealing with a #GtkStyleContext obtained through
2901 * gtk_widget_get_style_context(), this is normally done for you
2902 * in all circumstances you would expect all widget to be stopped,
2903 * so this should be only used in complex widgets with different
2904 * animatable regions.
2908 * Deprecated: 3.6: This function does nothing.
2911 gtk_style_context_cancel_animations (GtkStyleContext *context,
2914 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2918 * gtk_style_context_scroll_animations:
2919 * @context: a #GtkStyleContext
2920 * @window: a #GdkWindow used previously in
2921 * gtk_style_context_notify_state_change()
2922 * @dx: Amount to scroll in the X axis
2923 * @dy: Amount to scroll in the Y axis
2925 * This function is analogous to gdk_window_scroll(), and
2926 * should be called together with it so the invalidation
2927 * areas for any ongoing animation are scrolled together
2932 * Deprecated: 3.6: This function does nothing.
2935 gtk_style_context_scroll_animations (GtkStyleContext *context,
2940 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2941 g_return_if_fail (GDK_IS_WINDOW (window));
2945 * gtk_style_context_push_animatable_region:
2946 * @context: a #GtkStyleContext
2947 * @region_id: unique identifier for the animatable region
2949 * Pushes an animatable region, so all further gtk_render_*() calls between
2950 * this call and the following gtk_style_context_pop_animatable_region()
2951 * will potentially show transition animations for this region if
2952 * gtk_style_context_notify_state_change() is called for a given state,
2953 * and the current theme/style defines transition animations for state
2956 * The @region_id used must be unique in @context so the theming engine
2957 * can uniquely identify rendered elements subject to a state transition.
2961 * Deprecated: 3.6: This function does nothing.
2964 gtk_style_context_push_animatable_region (GtkStyleContext *context,
2967 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2968 g_return_if_fail (region_id != NULL);
2972 * gtk_style_context_pop_animatable_region:
2973 * @context: a #GtkStyleContext
2975 * Pops an animatable region from @context.
2976 * See gtk_style_context_push_animatable_region().
2980 * Deprecated: 3.6: This function does nothing.
2983 gtk_style_context_pop_animatable_region (GtkStyleContext *context)
2985 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
2989 gtk_style_context_clear_cache (GtkStyleContext *context)
2991 GtkStyleContextPrivate *priv;
2994 priv = context->priv;
2996 for (info = priv->info; info; info = info->next)
2998 style_info_set_data (info, NULL);
3000 g_hash_table_remove_all (priv->style_data);
3004 gtk_style_context_update_cache (GtkStyleContext *context,
3005 const GtkBitmask *parent_changes)
3007 GtkStyleContextPrivate *priv;
3008 GHashTableIter iter;
3009 gpointer key, value;
3011 if (_gtk_bitmask_is_empty (parent_changes))
3014 priv = context->priv;
3016 g_hash_table_iter_init (&iter, priv->style_data);
3017 while (g_hash_table_iter_next (&iter, &key, &value))
3019 GtkStyleInfo *info = key;
3020 StyleData *data = value;
3021 GtkBitmask *changes;
3023 changes = _gtk_css_computed_values_compute_dependencies (data->store, parent_changes);
3025 if (!_gtk_bitmask_is_empty (changes))
3026 build_properties (context, data->store, info, changes);
3028 _gtk_bitmask_free (changes);
3033 gtk_style_context_do_invalidate (GtkStyleContext *context,
3034 const GtkBitmask *changes)
3036 GtkStyleContextPrivate *priv;
3038 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3040 priv = context->priv;
3042 /* Avoid reentrancy */
3043 if (priv->invalidating_context)
3046 priv->invalidating_context = changes;
3048 g_signal_emit (context, signals[CHANGED], 0);
3050 priv->invalidating_context = NULL;
3054 gtk_style_context_update_animations (GtkStyleContext *context,
3057 GtkBitmask *differences;
3058 StyleData *style_data;
3060 style_data = style_data_lookup (context);
3062 differences = _gtk_css_computed_values_advance (style_data->store,
3065 if (_gtk_css_computed_values_is_static (style_data->store))
3066 _gtk_style_context_update_animating (context);
3072 gtk_style_context_needs_full_revalidate (GtkStyleContext *context,
3073 GtkCssChange change)
3075 GtkStyleContextPrivate *priv = context->priv;
3077 /* Try to avoid invalidating if we can */
3078 if (change & GTK_STYLE_CONTEXT_RADICAL_CHANGE)
3080 priv->relevant_changes = GTK_CSS_CHANGE_ANY;
3084 if (priv->relevant_changes == GTK_CSS_CHANGE_ANY)
3086 GtkWidgetPath *path;
3087 GtkCssMatcher matcher, superset;
3089 path = create_query_path (context, priv->info);
3090 if (_gtk_css_matcher_init (&matcher, path, priv->info->state_flags))
3092 _gtk_css_matcher_superset_init (&superset, &matcher, GTK_STYLE_CONTEXT_RADICAL_CHANGE & ~GTK_CSS_CHANGE_SOURCE);
3093 priv->relevant_changes = _gtk_style_provider_private_get_change (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
3097 priv->relevant_changes = 0;
3099 priv->relevant_changes &= ~GTK_STYLE_CONTEXT_RADICAL_CHANGE;
3101 gtk_widget_path_unref (path);
3105 if (priv->relevant_changes & change)
3112 gtk_style_context_should_create_transitions (GtkStyleContext *context)
3114 GtkStyleContextPrivate *priv;
3117 priv = context->priv;
3119 if (priv->widget == NULL)
3122 if (!gtk_widget_get_mapped (priv->widget))
3125 g_object_get (gtk_widget_get_settings (context->priv->widget),
3126 "gtk-enable-animations", &animate,
3133 _gtk_style_context_validate (GtkStyleContext *context,
3135 GtkCssChange change,
3136 const GtkBitmask *parent_changes)
3138 GtkStyleContextPrivate *priv;
3141 GtkBitmask *changes;
3144 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3146 priv = context->priv;
3148 change |= priv->pending_changes;
3150 /* If you run your application with
3151 * GTK_DEBUG=no-css-cache
3152 * every invalidation will purge the cache and completely query
3153 * everything anew form the cache. This is slow (in particular
3154 * when animating), but useful for figuring out bugs.
3156 * We achieve that by pretending that everything that could have
3157 * changed has and so we of course totally need to redo everything.
3159 * Note that this also completely revalidates child widgets all
3162 if (G_UNLIKELY (gtk_get_debug_flags () & GTK_DEBUG_NO_CSS_CACHE))
3163 change = GTK_CSS_CHANGE_ANY;
3165 if (!priv->invalid && change == 0 && _gtk_bitmask_is_empty (parent_changes))
3168 priv->pending_changes = 0;
3169 gtk_style_context_set_invalid (context, FALSE);
3173 current = style_data_ref (info->data);
3177 /* Try to avoid invalidating if we can */
3178 if (current == NULL ||
3179 gtk_style_context_needs_full_revalidate (context, change))
3183 if ((priv->relevant_changes & change) & ~GTK_STYLE_CONTEXT_CACHED_CHANGE)
3185 gtk_style_context_clear_cache (context);
3189 gtk_style_context_update_cache (context, parent_changes);
3190 style_info_set_data (info, NULL);
3193 data = style_data_lookup (context);
3195 _gtk_css_computed_values_create_animations (data->store,
3196 priv->parent ? style_data_lookup (priv->parent)->store : NULL,
3198 GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
3199 current && gtk_style_context_should_create_transitions (context) ? current->store : NULL);
3200 if (_gtk_css_computed_values_is_static (data->store))
3201 change &= ~GTK_CSS_CHANGE_ANIMATE;
3203 change |= GTK_CSS_CHANGE_ANIMATE;
3204 _gtk_style_context_update_animating (context);
3208 changes = _gtk_css_computed_values_get_difference (data->store, current->store);
3210 /* In the case where we keep the cache, we want unanimated values */
3211 _gtk_css_computed_values_cancel_animations (current->store);
3215 changes = _gtk_bitmask_new ();
3216 changes = _gtk_bitmask_invert_range (changes, 0, _gtk_css_style_property_get_n_properties ());
3221 changes = _gtk_css_computed_values_compute_dependencies (current->store, parent_changes);
3223 gtk_style_context_update_cache (context, parent_changes);
3227 style_data_unref (current);
3229 if (change & GTK_CSS_CHANGE_ANIMATE &&
3230 gtk_style_context_is_animating (context))
3232 GtkBitmask *animation_changes;
3234 animation_changes = gtk_style_context_update_animations (context, timestamp);
3235 changes = _gtk_bitmask_union (changes, animation_changes);
3236 _gtk_bitmask_free (animation_changes);
3239 if (!_gtk_bitmask_is_empty (changes) || (change & GTK_CSS_CHANGE_FORCE_INVALIDATE))
3240 gtk_style_context_do_invalidate (context, changes);
3242 change = _gtk_css_change_for_child (change);
3243 for (list = priv->children; list; list = list->next)
3245 _gtk_style_context_validate (list->data, timestamp, change, changes);
3248 _gtk_bitmask_free (changes);
3252 _gtk_style_context_queue_invalidate (GtkStyleContext *context,
3253 GtkCssChange change)
3255 GtkStyleContextPrivate *priv;
3257 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3258 g_return_if_fail (change != 0);
3260 priv = context->priv;
3262 if (priv->widget != NULL)
3264 priv->pending_changes |= change;
3265 gtk_style_context_set_invalid (context, TRUE);
3267 else if (priv->widget_path == NULL)
3269 gtk_style_context_invalidate (context);
3274 * gtk_style_context_invalidate:
3275 * @context: a #GtkStyleContext.
3277 * Invalidates @context style information, so it will be reconstructed
3280 * If you're using a #GtkStyleContext returned from
3281 * gtk_widget_get_style_context(), you do not need to
3282 * call this yourself.
3287 gtk_style_context_invalidate (GtkStyleContext *context)
3289 GtkBitmask *changes;
3291 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3293 gtk_style_context_clear_cache (context);
3295 changes = _gtk_bitmask_new ();
3296 changes = _gtk_bitmask_invert_range (changes,
3298 _gtk_css_style_property_get_n_properties ());
3299 gtk_style_context_do_invalidate (context, changes);
3300 _gtk_bitmask_free (changes);
3304 corner_value_is_right_angle (GtkCssValue *value)
3306 return _gtk_css_corner_value_get_x (value, 100) <= 0.0 &&
3307 _gtk_css_corner_value_get_y (value, 100) <= 0.0;
3311 * gtk_style_context_set_background:
3312 * @context: a #GtkStyleContext
3313 * @window: a #GdkWindow
3315 * Sets the background of @window to the background pattern or
3316 * color specified in @context for its current state.
3321 gtk_style_context_set_background (GtkStyleContext *context,
3324 const GdkRGBA *color;
3326 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3327 g_return_if_fail (GDK_IS_WINDOW (window));
3329 /* This is a sophisitcated optimization.
3330 * If we know the GDK window's background will be opaque, we mark
3331 * it as opaque. This is so GDK can do all the optimizations it does
3332 * for opaque windows and be fast.
3333 * This is mainly used when scrolling.
3335 * We could indeed just set black instead of the color we have.
3337 color = _gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BACKGROUND_COLOR));
3339 if (color->alpha >= 1.0 &&
3340 corner_value_is_right_angle (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_TOP_LEFT_RADIUS)) &&
3341 corner_value_is_right_angle (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_TOP_RIGHT_RADIUS)) &&
3342 corner_value_is_right_angle (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_BOTTOM_RIGHT_RADIUS)) &&
3343 corner_value_is_right_angle (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_BOTTOM_LEFT_RADIUS)))
3345 gdk_window_set_background_rgba (window, color);
3349 GdkRGBA transparent = { 0.0, 0.0, 0.0, 0.0 };
3350 gdk_window_set_background_rgba (window, &transparent);
3355 * gtk_style_context_get_color:
3356 * @context: a #GtkStyleContext
3357 * @state: state to retrieve the color for
3358 * @color: (out): return value for the foreground color
3360 * Gets the foreground color for a given state.
3365 gtk_style_context_get_color (GtkStyleContext *context,
3366 GtkStateFlags state,
3371 g_return_if_fail (color != NULL);
3372 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3374 gtk_style_context_get (context,
3384 * gtk_style_context_get_background_color:
3385 * @context: a #GtkStyleContext
3386 * @state: state to retrieve the color for
3387 * @color: (out): return value for the background color
3389 * Gets the background color for a given state.
3394 gtk_style_context_get_background_color (GtkStyleContext *context,
3395 GtkStateFlags state,
3400 g_return_if_fail (color != NULL);
3401 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3403 gtk_style_context_get (context,
3405 "background-color", &c,
3413 * gtk_style_context_get_border_color:
3414 * @context: a #GtkStyleContext
3415 * @state: state to retrieve the color for
3416 * @color: (out): return value for the border color
3418 * Gets the border color for a given state.
3423 gtk_style_context_get_border_color (GtkStyleContext *context,
3424 GtkStateFlags state,
3429 g_return_if_fail (color != NULL);
3430 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3432 gtk_style_context_get (context,
3442 * gtk_style_context_get_border:
3443 * @context: a #GtkStyleContext
3444 * @state: state to retrieve the border for
3445 * @border: (out): return value for the border settings
3447 * Gets the border for a given state as a #GtkBorder.
3448 * See %GTK_STYLE_PROPERTY_BORDER_WIDTH.
3453 gtk_style_context_get_border (GtkStyleContext *context,
3454 GtkStateFlags state,
3457 int top, left, bottom, right;
3459 g_return_if_fail (border != NULL);
3460 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3462 gtk_style_context_get (context,
3464 "border-top-width", &top,
3465 "border-left-width", &left,
3466 "border-bottom-width", &bottom,
3467 "border-right-width", &right,
3471 border->left = left;
3472 border->bottom = bottom;
3473 border->right = right;
3477 * gtk_style_context_get_padding:
3478 * @context: a #GtkStyleContext
3479 * @state: state to retrieve the padding for
3480 * @padding: (out): return value for the padding settings
3482 * Gets the padding for a given state as a #GtkBorder.
3483 * See %GTK_STYLE_PROPERTY_PADDING.
3488 gtk_style_context_get_padding (GtkStyleContext *context,
3489 GtkStateFlags state,
3492 int top, left, bottom, right;
3494 g_return_if_fail (padding != NULL);
3495 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3497 gtk_style_context_get (context,
3499 "padding-top", &top,
3500 "padding-left", &left,
3501 "padding-bottom", &bottom,
3502 "padding-right", &right,
3506 padding->left = left;
3507 padding->bottom = bottom;
3508 padding->right = right;
3512 * gtk_style_context_get_margin:
3513 * @context: a #GtkStyleContext
3514 * @state: state to retrieve the border for
3515 * @margin: (out): return value for the margin settings
3517 * Gets the margin for a given state as a #GtkBorder.
3518 * See %GTK_STYLE_PROPERTY_MARGIN.
3523 gtk_style_context_get_margin (GtkStyleContext *context,
3524 GtkStateFlags state,
3527 int top, left, bottom, right;
3529 g_return_if_fail (margin != NULL);
3530 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3532 gtk_style_context_get (context,
3535 "margin-left", &left,
3536 "margin-bottom", &bottom,
3537 "margin-right", &right,
3541 margin->left = left;
3542 margin->bottom = bottom;
3543 margin->right = right;
3547 * gtk_style_context_get_font:
3548 * @context: a #GtkStyleContext
3549 * @state: state to retrieve the font for
3551 * Returns the font description for a given state. The returned
3552 * object is const and will remain valid until the
3553 * #GtkStyleContext::changed signal happens.
3555 * Returns: (transfer none): the #PangoFontDescription for the given
3556 * state. This object is owned by GTK+ and should not be
3561 * Deprecated: 3.8: Use gtk_style_context_get() for "font" or
3562 * subproperties instead.
3564 const PangoFontDescription *
3565 gtk_style_context_get_font (GtkStyleContext *context,
3566 GtkStateFlags state)
3568 GtkStyleContextPrivate *priv;
3570 PangoFontDescription *description, *previous;
3572 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
3574 priv = context->priv;
3575 g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
3577 data = style_data_lookup_for_state (context, state);
3579 /* Yuck, fonts are created on-demand but we don't return a ref.
3580 * Do bad things to achieve this requirement */
3581 gtk_style_context_get (context, state, "font", &description, NULL);
3583 previous = g_object_get_data (G_OBJECT (data->store), "font-cache-for-get_font");
3587 pango_font_description_merge (previous, description, TRUE);
3588 pango_font_description_free (description);
3589 description = previous;
3593 g_object_set_data_full (G_OBJECT (data->store),
3594 "font-cache-for-get_font",
3596 (GDestroyNotify) pango_font_description_free);
3603 get_cursor_color (GtkStyleContext *context,
3607 GdkColor *style_color;
3609 gtk_style_context_get_style (context,
3610 primary ? "cursor-color" : "secondary-cursor-color",
3616 color->red = style_color->red / 65535.0;
3617 color->green = style_color->green / 65535.0;
3618 color->blue = style_color->blue / 65535.0;
3621 gdk_color_free (style_color);
3625 gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, color);
3631 gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &bg);
3633 color->red = (color->red + bg.red) * 0.5;
3634 color->green = (color->green + bg.green) * 0.5;
3635 color->blue = (color->blue + bg.blue) * 0.5;
3641 _gtk_style_context_get_cursor_color (GtkStyleContext *context,
3642 GdkRGBA *primary_color,
3643 GdkRGBA *secondary_color)
3646 get_cursor_color (context, TRUE, primary_color);
3648 if (secondary_color)
3649 get_cursor_color (context, FALSE, secondary_color);
3656 * @context: a #GtkStyleContext
3658 * @x: X origin of the rectangle
3659 * @y: Y origin of the rectangle
3660 * @width: rectangle width
3661 * @height: rectangle height
3663 * Renders a checkmark (as in a #GtkCheckButton).
3665 * The %GTK_STATE_FLAG_ACTIVE state determines whether the check is
3666 * on or off, and %GTK_STATE_FLAG_INCONSISTENT determines whether it
3667 * should be marked as undefined.
3670 * <title>Typical checkmark rendering</title>
3671 * <inlinegraphic fileref="checks.png" format="PNG"/>
3677 gtk_render_check (GtkStyleContext *context,
3684 GtkThemingEngineClass *engine_class;
3685 GtkThemingEngine *engine;
3687 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3688 g_return_if_fail (cr != NULL);
3690 if (width <= 0 || height <= 0)
3693 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3694 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3699 _gtk_theming_engine_set_context (engine, context);
3700 engine_class->render_check (engine, cr,
3701 x, y, width, height);
3707 * gtk_render_option:
3708 * @context: a #GtkStyleContext
3710 * @x: X origin of the rectangle
3711 * @y: Y origin of the rectangle
3712 * @width: rectangle width
3713 * @height: rectangle height
3715 * Renders an option mark (as in a #GtkRadioButton), the %GTK_STATE_FLAG_ACTIVE
3716 * state will determine whether the option is on or off, and
3717 * %GTK_STATE_FLAG_INCONSISTENT whether it should be marked as undefined.
3720 * <title>Typical option mark rendering</title>
3721 * <inlinegraphic fileref="options.png" format="PNG"/>
3727 gtk_render_option (GtkStyleContext *context,
3734 GtkThemingEngineClass *engine_class;
3735 GtkThemingEngine *engine;
3737 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3738 g_return_if_fail (cr != NULL);
3740 if (width <= 0 || height <= 0)
3743 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3744 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3748 _gtk_theming_engine_set_context (engine, context);
3749 engine_class->render_option (engine, cr,
3750 x, y, width, height);
3757 * @context: a #GtkStyleContext
3759 * @angle: arrow angle from 0 to 2 * %G_PI, being 0 the arrow pointing to the north
3760 * @x: X origin of the render area
3761 * @y: Y origin of the render area
3762 * @size: square side for render area
3764 * Renders an arrow pointing to @angle.
3767 * <title>Typical arrow rendering at 0, 1&solidus;2 π, π and 3&solidus;2 π</title>
3768 * <inlinegraphic fileref="arrows.png" format="PNG"/>
3774 gtk_render_arrow (GtkStyleContext *context,
3781 GtkThemingEngineClass *engine_class;
3782 GtkThemingEngine *engine;
3784 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3785 g_return_if_fail (cr != NULL);
3790 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3791 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3795 gtk_style_context_save (context);
3796 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ARROW);
3798 _gtk_theming_engine_set_context (engine, context);
3799 engine_class->render_arrow (engine, cr,
3802 gtk_style_context_restore (context);
3807 * gtk_render_background:
3808 * @context: a #GtkStyleContext
3810 * @x: X origin of the rectangle
3811 * @y: Y origin of the rectangle
3812 * @width: rectangle width
3813 * @height: rectangle height
3815 * Renders the background of an element.
3818 * <title>Typical background rendering, showing the effect of
3819 * <parameter>background-image</parameter>,
3820 * <parameter>border-width</parameter> and
3821 * <parameter>border-radius</parameter></title>
3822 * <inlinegraphic fileref="background.png" format="PNG"/>
3828 gtk_render_background (GtkStyleContext *context,
3835 GtkThemingEngineClass *engine_class;
3836 GtkThemingEngine *engine;
3838 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3839 g_return_if_fail (cr != NULL);
3841 if (width <= 0 || height <= 0)
3844 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3845 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3849 _gtk_theming_engine_set_context (engine, context);
3850 engine_class->render_background (engine, cr, x, y, width, height);
3857 * @context: a #GtkStyleContext
3859 * @x: X origin of the rectangle
3860 * @y: Y origin of the rectangle
3861 * @width: rectangle width
3862 * @height: rectangle height
3864 * Renders a frame around the rectangle defined by @x, @y, @width, @height.
3867 * <title>Examples of frame rendering, showing the effect of
3868 * <parameter>border-image</parameter>,
3869 * <parameter>border-color</parameter>,
3870 * <parameter>border-width</parameter>,
3871 * <parameter>border-radius</parameter> and
3873 * <inlinegraphic fileref="frames.png" format="PNG"/>
3879 gtk_render_frame (GtkStyleContext *context,
3886 GtkThemingEngineClass *engine_class;
3887 GtkThemingEngine *engine;
3889 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3890 g_return_if_fail (cr != NULL);
3892 if (width <= 0 || height <= 0)
3895 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3896 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3900 _gtk_theming_engine_set_context (engine, context);
3901 engine_class->render_frame (engine, cr, x, y, width, height);
3907 * gtk_render_expander:
3908 * @context: a #GtkStyleContext
3910 * @x: X origin of the rectangle
3911 * @y: Y origin of the rectangle
3912 * @width: rectangle width
3913 * @height: rectangle height
3915 * Renders an expander (as used in #GtkTreeView and #GtkExpander) in the area
3916 * defined by @x, @y, @width, @height. The state %GTK_STATE_FLAG_ACTIVE
3917 * determines whether the expander is collapsed or expanded.
3920 * <title>Typical expander rendering</title>
3921 * <inlinegraphic fileref="expanders.png" format="PNG"/>
3927 gtk_render_expander (GtkStyleContext *context,
3934 GtkThemingEngineClass *engine_class;
3935 GtkThemingEngine *engine;
3937 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3938 g_return_if_fail (cr != NULL);
3940 if (width <= 0 || height <= 0)
3943 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3944 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3948 _gtk_theming_engine_set_context (engine, context);
3949 engine_class->render_expander (engine, cr, x, y, width, height);
3956 * @context: a #GtkStyleContext
3958 * @x: X origin of the rectangle
3959 * @y: Y origin of the rectangle
3960 * @width: rectangle width
3961 * @height: rectangle height
3963 * Renders a focus indicator on the rectangle determined by @x, @y, @width, @height.
3965 * <title>Typical focus rendering</title>
3966 * <inlinegraphic fileref="focus.png" format="PNG"/>
3972 gtk_render_focus (GtkStyleContext *context,
3979 GtkThemingEngineClass *engine_class;
3980 GtkThemingEngine *engine;
3982 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
3983 g_return_if_fail (cr != NULL);
3985 if (width <= 0 || height <= 0)
3988 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
3989 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
3993 _gtk_theming_engine_set_context (engine, context);
3994 engine_class->render_focus (engine, cr, x, y, width, height);
4000 * gtk_render_layout:
4001 * @context: a #GtkStyleContext
4005 * @layout: the #PangoLayout to render
4007 * Renders @layout on the coordinates @x, @y
4012 gtk_render_layout (GtkStyleContext *context,
4016 PangoLayout *layout)
4018 GtkThemingEngineClass *engine_class;
4019 GtkThemingEngine *engine;
4020 PangoRectangle extents;
4022 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4023 g_return_if_fail (PANGO_IS_LAYOUT (layout));
4024 g_return_if_fail (cr != NULL);
4026 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4027 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4031 pango_layout_get_extents (layout, &extents, NULL);
4033 _gtk_theming_engine_set_context (engine, context);
4034 engine_class->render_layout (engine, cr, x, y, layout);
4041 * @context: a #GtkStyleContext
4043 * @x0: X coordinate for the origin of the line
4044 * @y0: Y coordinate for the origin of the line
4045 * @x1: X coordinate for the end of the line
4046 * @y1: Y coordinate for the end of the line
4048 * Renders a line from (x0, y0) to (x1, y1).
4053 gtk_render_line (GtkStyleContext *context,
4060 GtkThemingEngineClass *engine_class;
4061 GtkThemingEngine *engine;
4063 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4064 g_return_if_fail (cr != NULL);
4066 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4067 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4071 _gtk_theming_engine_set_context (engine, context);
4072 engine_class->render_line (engine, cr, x0, y0, x1, y1);
4078 * gtk_render_slider:
4079 * @context: a #GtkStyleContext
4081 * @x: X origin of the rectangle
4082 * @y: Y origin of the rectangle
4083 * @width: rectangle width
4084 * @height: rectangle height
4085 * @orientation: orientation of the slider
4087 * Renders a slider (as in #GtkScale) in the rectangle defined by @x, @y,
4088 * @width, @height. @orientation defines whether the slider is vertical
4092 * <title>Typical slider rendering</title>
4093 * <inlinegraphic fileref="sliders.png" format="PNG"/>
4099 gtk_render_slider (GtkStyleContext *context,
4105 GtkOrientation orientation)
4107 GtkThemingEngineClass *engine_class;
4108 GtkThemingEngine *engine;
4110 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4111 g_return_if_fail (cr != NULL);
4113 if (width <= 0 || height <= 0)
4116 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4117 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4121 _gtk_theming_engine_set_context (engine, context);
4122 engine_class->render_slider (engine, cr, x, y, width, height, orientation);
4128 * gtk_render_frame_gap:
4129 * @context: a #GtkStyleContext
4131 * @x: X origin of the rectangle
4132 * @y: Y origin of the rectangle
4133 * @width: rectangle width
4134 * @height: rectangle height
4135 * @gap_side: side where the gap is
4136 * @xy0_gap: initial coordinate (X or Y depending on @gap_side) for the gap
4137 * @xy1_gap: end coordinate (X or Y depending on @gap_side) for the gap
4139 * Renders a frame around the rectangle defined by (@x, @y, @width, @height),
4140 * leaving a gap on one side. @xy0_gap and @xy1_gap will mean X coordinates
4141 * for %GTK_POS_TOP and %GTK_POS_BOTTOM gap sides, and Y coordinates for
4142 * %GTK_POS_LEFT and %GTK_POS_RIGHT.
4145 * <title>Typical rendering of a frame with a gap</title>
4146 * <inlinegraphic fileref="frame-gap.png" format="PNG"/>
4152 gtk_render_frame_gap (GtkStyleContext *context,
4158 GtkPositionType gap_side,
4162 GtkThemingEngineClass *engine_class;
4163 GtkThemingEngine *engine;
4165 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4166 g_return_if_fail (cr != NULL);
4167 g_return_if_fail (xy0_gap <= xy1_gap);
4168 g_return_if_fail (xy0_gap >= 0);
4170 if (width <= 0 || height <= 0)
4173 if (gap_side == GTK_POS_LEFT ||
4174 gap_side == GTK_POS_RIGHT)
4175 g_return_if_fail (xy1_gap <= height);
4177 g_return_if_fail (xy1_gap <= width);
4179 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4180 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4184 _gtk_theming_engine_set_context (engine, context);
4185 engine_class->render_frame_gap (engine, cr,
4186 x, y, width, height, gap_side,
4193 * gtk_render_extension:
4194 * @context: a #GtkStyleContext
4196 * @x: X origin of the rectangle
4197 * @y: Y origin of the rectangle
4198 * @width: rectangle width
4199 * @height: rectangle height
4200 * @gap_side: side where the gap is
4202 * Renders a extension (as in a #GtkNotebook tab) in the rectangle
4203 * defined by @x, @y, @width, @height. The side where the extension
4204 * connects to is defined by @gap_side.
4207 * <title>Typical extension rendering</title>
4208 * <inlinegraphic fileref="extensions.png" format="PNG"/>
4214 gtk_render_extension (GtkStyleContext *context,
4220 GtkPositionType gap_side)
4222 GtkThemingEngineClass *engine_class;
4223 GtkThemingEngine *engine;
4225 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4226 g_return_if_fail (cr != NULL);
4228 if (width <= 0 || height <= 0)
4231 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4232 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4236 _gtk_theming_engine_set_context (engine, context);
4237 engine_class->render_extension (engine, cr, x, y, width, height, gap_side);
4243 * gtk_render_handle:
4244 * @context: a #GtkStyleContext
4246 * @x: X origin of the rectangle
4247 * @y: Y origin of the rectangle
4248 * @width: rectangle width
4249 * @height: rectangle height
4251 * Renders a handle (as in #GtkHandleBox, #GtkPaned and
4252 * #GtkWindow<!-- -->'s resize grip), in the rectangle
4253 * determined by @x, @y, @width, @height.
4256 * <title>Handles rendered for the paned and grip classes</title>
4257 * <inlinegraphic fileref="handles.png" format="PNG"/>
4263 gtk_render_handle (GtkStyleContext *context,
4270 GtkThemingEngineClass *engine_class;
4271 GtkThemingEngine *engine;
4273 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4274 g_return_if_fail (cr != NULL);
4276 if (width <= 0 || height <= 0)
4279 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4280 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4284 _gtk_theming_engine_set_context (engine, context);
4285 engine_class->render_handle (engine, cr, x, y, width, height);
4291 * gtk_render_activity:
4292 * @context: a #GtkStyleContext
4294 * @x: X origin of the rectangle
4295 * @y: Y origin of the rectangle
4296 * @width: rectangle width
4297 * @height: rectangle height
4299 * Renders an activity area (Such as in #GtkSpinner or the
4300 * fill line in #GtkRange), the state %GTK_STATE_FLAG_ACTIVE
4301 * determines whether there is activity going on.
4306 gtk_render_activity (GtkStyleContext *context,
4313 GtkThemingEngineClass *engine_class;
4314 GtkThemingEngine *engine;
4316 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4317 g_return_if_fail (cr != NULL);
4319 if (width <= 0 || height <= 0)
4322 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4323 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4327 _gtk_theming_engine_set_context (engine, context);
4328 engine_class->render_activity (engine, cr, x, y, width, height);
4334 * gtk_render_icon_pixbuf:
4335 * @context: a #GtkStyleContext
4336 * @source: the #GtkIconSource specifying the icon to render
4337 * @size: (type int): the size to render the icon at. A size of (GtkIconSize) -1
4338 * means render at the size of the source and don't scale.
4340 * Renders the icon specified by @source at the given @size, returning the result
4343 * Returns: (transfer full): a newly-created #GdkPixbuf containing the rendered icon
4348 gtk_render_icon_pixbuf (GtkStyleContext *context,
4349 const GtkIconSource *source,
4352 GtkThemingEngineClass *engine_class;
4353 GtkThemingEngine *engine;
4355 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
4356 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
4357 g_return_val_if_fail (source != NULL, NULL);
4359 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4360 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4362 _gtk_theming_engine_set_context (engine, context);
4363 return engine_class->render_icon_pixbuf (engine, source, size);
4368 * @context: a #GtkStyleContext
4370 * @pixbuf: a #GdkPixbuf containing the icon to draw
4371 * @x: X position for the @pixbuf
4372 * @y: Y position for the @pixbuf
4374 * Renders the icon in @pixbuf at the specified @x and @y coordinates.
4379 gtk_render_icon (GtkStyleContext *context,
4385 GtkThemingEngineClass *engine_class;
4386 GtkThemingEngine *engine;
4388 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4389 g_return_if_fail (cr != NULL);
4391 engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
4392 engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
4396 _gtk_theming_engine_set_context (engine, context);
4397 engine_class->render_icon (engine, cr, pixbuf, x, y);
4403 draw_insertion_cursor (GtkStyleContext *context,
4408 gboolean is_primary,
4409 PangoDirection direction,
4410 gboolean draw_arrow)
4413 GdkRGBA primary_color;
4414 GdkRGBA secondary_color;
4415 gfloat cursor_aspect_ratio;
4421 _gtk_style_context_get_cursor_color (context, &primary_color, &secondary_color);
4422 gdk_cairo_set_source_rgba (cr, is_primary ? &primary_color : &secondary_color);
4424 /* When changing the shape or size of the cursor here,
4425 * propagate the changes to gtktextview.c:text_window_invalidate_cursors().
4428 gtk_style_context_get_style (context,
4429 "cursor-aspect-ratio", &cursor_aspect_ratio,
4432 stem_width = height * cursor_aspect_ratio + 1;
4434 /* put (stem_width % 2) on the proper side of the cursor */
4435 if (direction == PANGO_DIRECTION_LTR)
4436 offset = stem_width / 2;
4438 offset = stem_width - stem_width / 2;
4440 cairo_rectangle (cr, x - offset, y, stem_width, height);
4448 arrow_width = stem_width + 1;
4450 if (direction == PANGO_DIRECTION_RTL)
4452 ax = x - offset - 1;
4453 ay = y + height - arrow_width * 2 - arrow_width + 1;
4455 cairo_move_to (cr, ax, ay + 1);
4456 cairo_line_to (cr, ax - arrow_width, ay + arrow_width);
4457 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4460 else if (direction == PANGO_DIRECTION_LTR)
4462 ax = x + stem_width - offset;
4463 ay = y + height - arrow_width * 2 - arrow_width + 1;
4465 cairo_move_to (cr, ax, ay + 1);
4466 cairo_line_to (cr, ax + arrow_width, ay + arrow_width);
4467 cairo_line_to (cr, ax, ay + 2 * arrow_width);
4471 g_assert_not_reached();
4478 * gtk_render_insertion_cursor:
4479 * @context: a #GtkStyleContext
4483 * @layout: the #PangoLayout of the text
4484 * @index: the index in the #PangoLayout
4485 * @direction: the #PangoDirection of the text
4487 * Draws a text caret on @cr at the specified index of @layout.
4492 gtk_render_insertion_cursor (GtkStyleContext *context,
4496 PangoLayout *layout,
4498 PangoDirection direction)
4500 GtkStyleContextPrivate *priv;
4501 gboolean split_cursor;
4502 PangoRectangle strong_pos, weak_pos;
4503 PangoRectangle *cursor1, *cursor2;
4504 PangoDirection keymap_direction;
4505 PangoDirection direction2;
4507 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
4508 g_return_if_fail (cr != NULL);
4509 g_return_if_fail (PANGO_IS_LAYOUT (layout));
4510 g_return_if_fail (index >= 0);
4512 priv = context->priv;
4514 g_object_get (gtk_settings_get_for_screen (priv->screen),
4515 "gtk-split-cursor", &split_cursor,
4518 keymap_direction = gdk_keymap_get_direction (gdk_keymap_get_for_display (gdk_screen_get_display (priv->screen)));
4520 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4522 direction2 = PANGO_DIRECTION_NEUTRAL;
4526 cursor1 = &strong_pos;
4528 if (strong_pos.x != weak_pos.x || strong_pos.y != weak_pos.y)
4530 direction2 = (direction == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
4531 cursor2 = &weak_pos;
4536 if (keymap_direction == direction)
4537 cursor1 = &strong_pos;
4539 cursor1 = &weak_pos;
4542 draw_insertion_cursor (context,
4544 x + PANGO_PIXELS (cursor1->x),
4545 y + PANGO_PIXELS (cursor1->y),
4546 PANGO_PIXELS (cursor1->height),
4549 direction2 != PANGO_DIRECTION_NEUTRAL);
4551 if (direction2 != PANGO_DIRECTION_NEUTRAL)
4553 draw_insertion_cursor (context,
4555 x + PANGO_PIXELS (cursor2->x),
4556 y + PANGO_PIXELS (cursor2->y),
4557 PANGO_PIXELS (cursor2->height),
4565 * gtk_draw_insertion_cursor:
4566 * @widget: a #GtkWidget
4567 * @cr: cairo context to draw to
4568 * @location: location where to draw the cursor (@location->width is ignored)
4569 * @is_primary: if the cursor should be the primary cursor color.
4570 * @direction: whether the cursor is left-to-right or
4571 * right-to-left. Should never be #GTK_TEXT_DIR_NONE
4572 * @draw_arrow: %TRUE to draw a directional arrow on the
4573 * cursor. Should be %FALSE unless the cursor is split.
4575 * Draws a text caret on @cr at @location. This is not a style function
4576 * but merely a convenience function for drawing the standard cursor shape.
4579 * Deprecated: 3.4: Use gtk_render_insertion_cursor() instead.
4582 gtk_draw_insertion_cursor (GtkWidget *widget,
4584 const GdkRectangle *location,
4585 gboolean is_primary,
4586 GtkTextDirection direction,
4587 gboolean draw_arrow)
4589 GtkStyleContext *context;
4591 g_return_if_fail (GTK_IS_WIDGET (widget));
4592 g_return_if_fail (cr != NULL);
4593 g_return_if_fail (location != NULL);
4594 g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
4596 context = gtk_widget_get_style_context (widget);
4598 draw_insertion_cursor (context, cr,
4599 location->x, location->y, location->height,
4601 (direction == GTK_TEXT_DIR_RTL) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR,
4606 * _gtk_style_context_get_changes:
4607 * @context: the context to query
4609 * Queries the context for the changes for the currently executing
4610 * GtkStyleContext::invalidate signal. If no signal is currently
4611 * emitted, this function returns %NULL.
4613 * FIXME 4.0: Make this part of the signal.
4615 * Returns: %NULL or the currently invalidating changes
4618 _gtk_style_context_get_changes (GtkStyleContext *context)
4620 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
4622 return context->priv->invalidating_context;
4625 static AtkAttributeSet *
4626 add_attribute (AtkAttributeSet *attributes,
4627 AtkTextAttribute attr,
4632 at = g_new (AtkAttribute, 1);
4633 at->name = g_strdup (atk_text_attribute_get_name (attr));
4634 at->value = g_strdup (value);
4636 return g_slist_prepend (attributes, at);
4640 * _gtk_style_context_get_attributes:
4641 * @attributes: a #AtkAttributeSet to add attributes to
4642 * @context: the #GtkStyleContext to get attributes from
4643 * @flags: the state to use with @context
4645 * Adds the foreground and background color from @context to
4646 * @attributes, after translating them to ATK attributes.
4648 * This is a convenience function that can be used in
4649 * implementing the #AtkText interface in widgets.
4651 * Returns: the modified #AtkAttributeSet
4654 _gtk_style_context_get_attributes (AtkAttributeSet *attributes,
4655 GtkStyleContext *context,
4656 GtkStateFlags flags)
4661 gtk_style_context_get_background_color (context, flags, &color);
4662 value = g_strdup_printf ("%u,%u,%u",
4663 (guint) ceil (color.red * 65536 - color.red),
4664 (guint) ceil (color.green * 65536 - color.green),
4665 (guint) ceil (color.blue * 65536 - color.blue));
4666 attributes = add_attribute (attributes, ATK_TEXT_ATTR_BG_COLOR, value);
4669 gtk_style_context_get_color (context, flags, &color);
4670 value = g_strdup_printf ("%u,%u,%u",
4671 (guint) ceil (color.red * 65536 - color.red),
4672 (guint) ceil (color.green * 65536 - color.green),
4673 (guint) ceil (color.blue * 65536 - color.blue));
4674 attributes = add_attribute (attributes, ATK_TEXT_ATTR_FG_COLOR, value);
4681 gtk_gradient_resolve_for_context (GtkGradient *gradient,
4682 GtkStyleContext *context)
4684 GtkStyleContextPrivate *priv = context->priv;
4685 GtkCssDependencies ignored = 0;
4687 g_return_val_if_fail (gradient != NULL, NULL);
4688 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
4690 return _gtk_gradient_resolve_full (gradient,
4691 GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
4692 style_data_lookup (context)->store,
4693 priv->parent ? style_data_lookup (priv->parent)->store : NULL,