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, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
25 #include <gtk/gtkthemingengine.h>
26 #include <gtk/gtkstylecontext.h>
27 #include <gtk/gtkintl.h>
29 #include "gtkprivate.h"
30 #include "gtkmodulesprivate.h"
31 #include "gtkborderimageprivate.h"
33 #include "gtkshadowprivate.h"
34 #include "gtkcsstypesprivate.h"
35 #include "gtkthemingengineprivate.h"
36 #include "gtkroundedboxprivate.h"
39 * SECTION:gtkthemingengine
40 * @Short_description: Theming renderers
41 * @Title: GtkThemingEngine
42 * @See_also: #GtkStyleContext
44 * #GtkThemingEngine is the object used for rendering themed content
45 * in GTK+ widgets. Even though GTK+ has a default implementation,
46 * it can be overridden in CSS files by enforcing a #GtkThemingEngine
47 * object to be loaded as a module.
49 * In order to implement a theming engine, a #GtkThemingEngine subclass
50 * must be created, alongside the CSS file that will reference it, the
51 * theming engine would be created as an .so library, and installed in
52 * $(gtk-modules-dir)/theming-engines/.
54 * #GtkThemingEngine<!-- -->s have limited access to the object they are
55 * rendering, the #GtkThemingEngine API has read-only accessors to the
56 * style information contained in the rendered object's #GtkStyleContext.
72 struct GtkThemingEnginePrivate
74 GtkStyleContext *context;
78 #define GTK_THEMING_ENGINE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_THEMING_ENGINE, GtkThemingEnginePrivate))
80 static void gtk_theming_engine_finalize (GObject *object);
81 static void gtk_theming_engine_impl_set_property (GObject *object,
85 static void gtk_theming_engine_impl_get_property (GObject *object,
90 static void gtk_theming_engine_render_check (GtkThemingEngine *engine,
96 static void gtk_theming_engine_render_option (GtkThemingEngine *engine,
102 static void gtk_theming_engine_render_arrow (GtkThemingEngine *engine,
108 static void gtk_theming_engine_render_background (GtkThemingEngine *engine,
114 static void gtk_theming_engine_render_frame (GtkThemingEngine *engine,
120 static void gtk_theming_engine_render_expander (GtkThemingEngine *engine,
126 static void gtk_theming_engine_render_focus (GtkThemingEngine *engine,
132 static void gtk_theming_engine_render_layout (GtkThemingEngine *engine,
136 PangoLayout *layout);
137 static void gtk_theming_engine_render_line (GtkThemingEngine *engine,
143 static void gtk_theming_engine_render_slider (GtkThemingEngine *engine,
149 GtkOrientation orientation);
150 static void gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
156 GtkPositionType gap_side,
159 static void gtk_theming_engine_render_extension (GtkThemingEngine *engine,
165 GtkPositionType gap_side);
166 static void gtk_theming_engine_render_handle (GtkThemingEngine *engine,
172 static void gtk_theming_engine_render_activity (GtkThemingEngine *engine,
178 static GdkPixbuf * gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine *engine,
179 const GtkIconSource *source,
181 static void gtk_theming_engine_render_icon (GtkThemingEngine *engine,
186 static void render_background_internal (GtkThemingEngine *engine,
192 GtkJunctionSides junction,
193 cairo_pattern_t *optional_background);
195 G_DEFINE_TYPE (GtkThemingEngine, gtk_theming_engine, G_TYPE_OBJECT)
198 typedef struct GtkThemingModule GtkThemingModule;
199 typedef struct GtkThemingModuleClass GtkThemingModuleClass;
201 struct GtkThemingModule
203 GTypeModule parent_instance;
207 void (*init) (GTypeModule *module);
209 GtkThemingEngine * (*create_engine) (void);
212 struct GtkThemingModuleClass
214 GTypeModuleClass parent_class;
217 #define GTK_TYPE_THEMING_MODULE (gtk_theming_module_get_type ())
218 #define GTK_THEMING_MODULE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_THEMING_MODULE, GtkThemingModule))
219 #define GTK_IS_THEMING_MODULE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_THEMING_MODULE))
221 G_DEFINE_TYPE (GtkThemingModule, gtk_theming_module, G_TYPE_TYPE_MODULE);
224 gtk_theming_engine_class_init (GtkThemingEngineClass *klass)
226 GObjectClass *object_class = G_OBJECT_CLASS (klass);
228 object_class->finalize = gtk_theming_engine_finalize;
229 object_class->set_property = gtk_theming_engine_impl_set_property;
230 object_class->get_property = gtk_theming_engine_impl_get_property;
232 klass->render_icon = gtk_theming_engine_render_icon;
233 klass->render_check = gtk_theming_engine_render_check;
234 klass->render_option = gtk_theming_engine_render_option;
235 klass->render_arrow = gtk_theming_engine_render_arrow;
236 klass->render_background = gtk_theming_engine_render_background;
237 klass->render_frame = gtk_theming_engine_render_frame;
238 klass->render_expander = gtk_theming_engine_render_expander;
239 klass->render_focus = gtk_theming_engine_render_focus;
240 klass->render_layout = gtk_theming_engine_render_layout;
241 klass->render_line = gtk_theming_engine_render_line;
242 klass->render_slider = gtk_theming_engine_render_slider;
243 klass->render_frame_gap = gtk_theming_engine_render_frame_gap;
244 klass->render_extension = gtk_theming_engine_render_extension;
245 klass->render_handle = gtk_theming_engine_render_handle;
246 klass->render_activity = gtk_theming_engine_render_activity;
247 klass->render_icon_pixbuf = gtk_theming_engine_render_icon_pixbuf;
250 * GtkThemingEngine:name:
252 * The theming engine name, this name will be used when registering
253 * custom properties, for a theming engine named "Clearlooks" registering
254 * a "glossy" custom property, it could be referenced in the CSS file as
257 * -Clearlooks-glossy: true;
262 g_object_class_install_property (object_class,
264 g_param_spec_string ("name",
266 P_("Theming engine name"),
268 G_PARAM_CONSTRUCT_ONLY | GTK_PARAM_READWRITE));
270 g_type_class_add_private (object_class, sizeof (GtkThemingEnginePrivate));
274 gtk_theming_engine_init (GtkThemingEngine *engine)
276 engine->priv = GTK_THEMING_ENGINE_GET_PRIVATE (engine);
280 gtk_theming_engine_finalize (GObject *object)
282 GtkThemingEnginePrivate *priv;
284 priv = GTK_THEMING_ENGINE (object)->priv;
287 G_OBJECT_GET_CLASS (gtk_theming_engine_parent_class)->finalize (object);
291 gtk_theming_engine_impl_set_property (GObject *object,
296 GtkThemingEnginePrivate *priv;
298 priv = GTK_THEMING_ENGINE (object)->priv;
306 priv->name = g_value_dup_string (value);
309 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
315 gtk_theming_engine_impl_get_property (GObject *object,
320 GtkThemingEnginePrivate *priv;
322 priv = GTK_THEMING_ENGINE (object)->priv;
327 g_value_set_string (value, priv->name);
330 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
336 _gtk_theming_engine_set_context (GtkThemingEngine *engine,
337 GtkStyleContext *context)
339 GtkThemingEnginePrivate *priv;
341 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
342 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
345 priv->context = context;
349 * gtk_theming_engine_register_property: (skip)
350 * @name_space: namespace for the property name
351 * @parse_func: parsing function to use, or %NULL
352 * @pspec: the #GParamSpec for the new property
354 * Registers a property so it can be used in the CSS file format,
355 * on the CSS file the property will look like
356 * "-${@name_space}-${property_name}". being
357 * ${property_name} the given to @pspec. @name_space will usually
358 * be the theme engine name.
360 * For any type a @parse_func may be provided, being this function
361 * used for turning any property value (between ':' and ';') in
362 * CSS to the #GValue needed. For basic types there is already
363 * builtin parsing support, so %NULL may be provided for these
367 * Engines must ensure property registration happens exactly once,
368 * usually GTK+ deals with theming engines as singletons, so this
369 * should be guaranteed to happen once, but bear this in mind
370 * when creating #GtkThemeEngine<!-- -->s yourself.
374 * In order to make use of the custom registered properties in
375 * the CSS file, make sure the engine is loaded first by specifying
376 * the engine property, either in a previous rule or within the same
380 * engine: someengine;
381 * -SomeEngine-custom-property: 2;
389 gtk_theming_engine_register_property (const gchar *name_space,
390 GtkStylePropertyParser parse_func,
395 g_return_if_fail (name_space != NULL);
396 g_return_if_fail (strchr (name_space, ' ') == NULL);
397 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
399 /* FIXME: hack hack hack, replacing pspec->name to include namespace */
400 name = g_strdup_printf ("-%s-%s", name_space, pspec->name);
401 pspec->name = (char *)g_intern_string (name);
404 gtk_style_properties_register_property (parse_func, pspec);
408 * gtk_theming_engine_get_property:
409 * @engine: a #GtkThemingEngine
410 * @property: the property name
411 * @state: state to retrieve the value for
412 * @value: (out) (transfer full): return location for the property value,
413 * you must free this memory using g_value_unset() once you are
416 * Gets a property value as retrieved from the style settings that apply
417 * to the currently rendered element.
422 gtk_theming_engine_get_property (GtkThemingEngine *engine,
423 const gchar *property,
427 GtkThemingEnginePrivate *priv;
429 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
430 g_return_if_fail (property != NULL);
431 g_return_if_fail (value != NULL);
434 gtk_style_context_get_property (priv->context, property, state, value);
438 * gtk_theming_engine_get_valist:
439 * @engine: a #GtkThemingEngine
440 * @state: state to retrieve values for
441 * @args: va_list of property name/return location pairs, followed by %NULL
443 * Retrieves several style property values that apply to the currently
449 gtk_theming_engine_get_valist (GtkThemingEngine *engine,
453 GtkThemingEnginePrivate *priv;
455 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
458 gtk_style_context_get_valist (priv->context, state, args);
462 _gtk_theming_engine_get (GtkThemingEngine *engine,
464 GtkStylePropertyContext *property_context,
467 GtkThemingEnginePrivate *priv;
470 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
474 va_start (args, property_context);
475 _gtk_style_context_get_valist (priv->context, state, property_context, args);
481 * gtk_theming_engine_get:
482 * @engine: a #GtkThemingEngine
483 * @state: state to retrieve values for
484 * @...: property name /return value pairs, followed by %NULL
486 * Retrieves several style property values that apply to the currently
492 gtk_theming_engine_get (GtkThemingEngine *engine,
496 GtkThemingEnginePrivate *priv;
499 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
503 va_start (args, state);
504 gtk_style_context_get_valist (priv->context, state, args);
509 * gtk_theming_engine_get_style_property:
510 * @engine: a #GtkThemingEngine
511 * @property_name: the name of the widget style property
512 * @value: Return location for the property value, free with
513 * g_value_unset() after use.
515 * Gets the value for a widget style property.
520 gtk_theming_engine_get_style_property (GtkThemingEngine *engine,
521 const gchar *property_name,
524 GtkThemingEnginePrivate *priv;
526 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
527 g_return_if_fail (property_name != NULL);
530 gtk_style_context_get_style_property (priv->context, property_name, value);
534 * gtk_theming_engine_get_style_valist:
535 * @engine: a #GtkThemingEngine
536 * @args: va_list of property name/return location pairs, followed by %NULL
538 * Retrieves several widget style properties from @engine according to the
539 * currently rendered content's style.
544 gtk_theming_engine_get_style_valist (GtkThemingEngine *engine,
547 GtkThemingEnginePrivate *priv;
549 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
552 gtk_style_context_get_style_valist (priv->context, args);
556 * gtk_theming_engine_get_style:
557 * @engine: a #GtkThemingEngine
558 * @...: property name /return value pairs, followed by %NULL
560 * Retrieves several widget style properties from @engine according
561 * to the currently rendered content's style.
566 gtk_theming_engine_get_style (GtkThemingEngine *engine,
569 GtkThemingEnginePrivate *priv;
572 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
576 va_start (args, engine);
577 gtk_style_context_get_style_valist (priv->context, args);
582 * gtk_theming_engine_lookup_color:
583 * @engine: a #GtkThemingEngine
584 * @color_name: color name to lookup
585 * @color: (out): Return location for the looked up color
587 * Looks up and resolves a color name in the current style's color map.
589 * Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
592 gtk_theming_engine_lookup_color (GtkThemingEngine *engine,
593 const gchar *color_name,
596 GtkThemingEnginePrivate *priv;
598 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
599 g_return_val_if_fail (color_name != NULL, FALSE);
602 return gtk_style_context_lookup_color (priv->context, color_name, color);
606 * gtk_theming_engine_get_state:
607 * @engine: a #GtkThemingEngine
609 * returns the state used when rendering.
611 * Returns: the state flags
616 gtk_theming_engine_get_state (GtkThemingEngine *engine)
618 GtkThemingEnginePrivate *priv;
620 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), 0);
623 return gtk_style_context_get_state (priv->context);
627 * gtk_theming_engine_state_is_running:
628 * @engine: a #GtkThemingEngine
629 * @state: a widget state
630 * @progress: (out): return location for the transition progress
632 * Returns %TRUE if there is a transition animation running for the
633 * current region (see gtk_style_context_push_animatable_region()).
635 * If @progress is not %NULL, the animation progress will be returned
636 * there, 0.0 means the state is closest to being %FALSE, while 1.0 means
637 * it's closest to being %TRUE. This means transition animations will
638 * run from 0 to 1 when @state is being set to %TRUE and from 1 to 0 when
639 * it's being set to %FALSE.
641 * Returns: %TRUE if there is a running transition animation for @state.
646 gtk_theming_engine_state_is_running (GtkThemingEngine *engine,
650 GtkThemingEnginePrivate *priv;
652 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
655 return gtk_style_context_state_is_running (priv->context, state, progress);
659 * gtk_theming_engine_get_path:
660 * @engine: a #GtkThemingEngine
662 * Returns the widget path used for style matching.
664 * Returns: (transfer none): A #GtkWidgetPath
668 const GtkWidgetPath *
669 gtk_theming_engine_get_path (GtkThemingEngine *engine)
671 GtkThemingEnginePrivate *priv;
673 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
676 return gtk_style_context_get_path (priv->context);
680 * gtk_theming_engine_has_class:
681 * @engine: a #GtkThemingEngine
682 * @style_class: class name to look up
684 * Returns %TRUE if the currently rendered contents have
685 * defined the given class name.
687 * Returns: %TRUE if @engine has @class_name defined
692 gtk_theming_engine_has_class (GtkThemingEngine *engine,
693 const gchar *style_class)
695 GtkThemingEnginePrivate *priv;
697 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
700 return gtk_style_context_has_class (priv->context, style_class);
704 * gtk_theming_engine_has_region:
705 * @engine: a #GtkThemingEngine
706 * @style_region: a region name
707 * @flags: (out) (allow-none): return location for region flags
709 * Returns %TRUE if the currently rendered contents have the
710 * region defined. If @flags_return is not %NULL, it is set
711 * to the flags affecting the region.
713 * Returns: %TRUE if region is defined
718 gtk_theming_engine_has_region (GtkThemingEngine *engine,
719 const gchar *style_region,
720 GtkRegionFlags *flags)
722 GtkThemingEnginePrivate *priv;
727 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
730 return gtk_style_context_has_region (priv->context, style_region, flags);
734 * gtk_theming_engine_get_direction:
735 * @engine: a #GtkThemingEngine
737 * Returns the widget direction used for rendering.
739 * Returns: the widget direction
744 gtk_theming_engine_get_direction (GtkThemingEngine *engine)
746 GtkThemingEnginePrivate *priv;
748 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), GTK_TEXT_DIR_LTR);
751 return gtk_style_context_get_direction (priv->context);
755 * gtk_theming_engine_get_junction_sides:
756 * @engine: a #GtkThemingEngine
758 * Returns the widget direction used for rendering.
760 * Returns: the widget direction
765 gtk_theming_engine_get_junction_sides (GtkThemingEngine *engine)
767 GtkThemingEnginePrivate *priv;
769 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), 0);
772 return gtk_style_context_get_junction_sides (priv->context);
776 * gtk_theming_engine_get_color:
777 * @engine: a #GtkThemingEngine
778 * @state: state to retrieve the color for
779 * @color: (out): return value for the foreground color
781 * Gets the foreground color for a given state.
786 gtk_theming_engine_get_color (GtkThemingEngine *engine,
790 GtkThemingEnginePrivate *priv;
792 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
795 gtk_style_context_get_color (priv->context, state, color);
799 * gtk_theming_engine_get_background_color:
800 * @engine: a #GtkThemingEngine
801 * @state: state to retrieve the color for
802 * @color: (out): return value for the background color
804 * Gets the background color for a given state.
809 gtk_theming_engine_get_background_color (GtkThemingEngine *engine,
813 GtkThemingEnginePrivate *priv;
815 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
818 gtk_style_context_get_background_color (priv->context, state, color);
822 * gtk_theming_engine_get_border_color:
823 * @engine: a #GtkThemingEngine
824 * @state: state to retrieve the color for
825 * @color: (out): return value for the border color
827 * Gets the border color for a given state.
832 gtk_theming_engine_get_border_color (GtkThemingEngine *engine,
836 GtkThemingEnginePrivate *priv;
838 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
841 gtk_style_context_get_border_color (priv->context, state, color);
845 * gtk_theming_engine_get_border:
846 * @engine: a #GtkthemingEngine
847 * @state: state to retrieve the border for
848 * @border: (out): return value for the border settings
850 * Gets the border for a given state as a #GtkBorder.
855 gtk_theming_engine_get_border (GtkThemingEngine *engine,
859 GtkThemingEnginePrivate *priv;
861 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
864 gtk_style_context_get_border (priv->context, state, border);
868 * gtk_theming_engine_get_padding:
869 * @engine: a #GtkthemingEngine
870 * @state: state to retrieve the padding for
871 * @padding: (out): return value for the padding settings
873 * Gets the padding for a given state as a #GtkBorder.
878 gtk_theming_engine_get_padding (GtkThemingEngine *engine,
882 GtkThemingEnginePrivate *priv;
884 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
887 gtk_style_context_get_padding (priv->context, state, padding);
891 * gtk_theming_engine_get_margin:
892 * @engine: a #GtkThemingEngine
893 * @state: state to retrieve the border for
894 * @margin: (out): return value for the margin settings
896 * Gets the margin for a given state as a #GtkBorder.
901 gtk_theming_engine_get_margin (GtkThemingEngine *engine,
905 GtkThemingEnginePrivate *priv;
907 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
910 gtk_style_context_get_margin (priv->context, state, margin);
914 * gtk_theming_engine_get_font:
915 * @engine: a #GtkThemingEngine
916 * @state: state to retrieve the font for
918 * Returns the font description for a given state.
920 * Returns: (transfer none): the #PangoFontDescription for the given
921 * state. This object is owned by GTK+ and should not be
926 const PangoFontDescription *
927 gtk_theming_engine_get_font (GtkThemingEngine *engine,
930 GtkThemingEnginePrivate *priv;
932 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
935 return gtk_style_context_get_font (priv->context, state);
938 /* GtkThemingModule */
941 gtk_theming_module_load (GTypeModule *type_module)
943 GtkThemingModule *theming_module;
945 gchar *name, *module_path;
947 theming_module = GTK_THEMING_MODULE (type_module);
948 name = theming_module->name;
949 module_path = _gtk_find_module (name, "theming-engines");
954 module = g_module_open (module_path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
955 g_free (module_path);
960 if (!g_module_symbol (module, "theme_init",
961 (gpointer *) &theming_module->init) ||
962 !g_module_symbol (module, "theme_exit",
963 (gpointer *) &theming_module->exit) ||
964 !g_module_symbol (module, "create_engine",
965 (gpointer *) &theming_module->create_engine))
967 g_module_close (module);
972 theming_module->module = module;
974 theming_module->init (G_TYPE_MODULE (theming_module));
980 gtk_theming_module_unload (GTypeModule *type_module)
982 GtkThemingModule *theming_module;
984 theming_module = GTK_THEMING_MODULE (type_module);
986 theming_module->exit ();
988 g_module_close (theming_module->module);
990 theming_module->module = NULL;
991 theming_module->init = NULL;
992 theming_module->exit = NULL;
993 theming_module->create_engine = NULL;
997 gtk_theming_module_class_init (GtkThemingModuleClass *klass)
999 GTypeModuleClass *module_class = G_TYPE_MODULE_CLASS (klass);
1001 module_class->load = gtk_theming_module_load;
1002 module_class->unload = gtk_theming_module_unload;
1006 gtk_theming_module_init (GtkThemingModule *module)
1011 * gtk_theming_engine_load:
1012 * @name: Theme engine name to load
1014 * Loads and initializes a theming engine module from the
1015 * standard directories.
1017 * Returns: (transfer none): A theming engine, or %NULL if
1018 * the engine @name doesn't exist.
1021 gtk_theming_engine_load (const gchar *name)
1023 static GHashTable *engines = NULL;
1024 static GtkThemingEngine *default_engine;
1025 GtkThemingEngine *engine = NULL;
1030 engines = g_hash_table_new (g_str_hash, g_str_equal);
1032 engine = g_hash_table_lookup (engines, name);
1036 GtkThemingModule *module;
1038 module = g_object_new (GTK_TYPE_THEMING_MODULE, NULL);
1039 g_type_module_set_name (G_TYPE_MODULE (module), name);
1040 module->name = g_strdup (name);
1042 if (module && g_type_module_use (G_TYPE_MODULE (module)))
1044 engine = (module->create_engine) ();
1047 g_hash_table_insert (engines, module->name, engine);
1053 if (G_UNLIKELY (!default_engine))
1054 default_engine = g_object_new (GTK_TYPE_THEMING_ENGINE, NULL);
1056 engine = default_engine;
1063 * gtk_theming_engine_get_screen:
1064 * @engine: a #GtkThemingEngine
1066 * Returns the #GdkScreen to which @engine currently rendering to.
1068 * Returns: (transfer none): a #GdkScreen, or %NULL.
1071 gtk_theming_engine_get_screen (GtkThemingEngine *engine)
1073 GtkThemingEnginePrivate *priv;
1075 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
1077 priv = engine->priv;
1078 return gtk_style_context_get_screen (priv->context);
1081 /* Paint method implementations */
1083 gtk_theming_engine_render_check (GtkThemingEngine *engine,
1090 GdkRGBA fg_color, bg_color;
1091 GtkStateFlags flags;
1092 gint exterior_size, interior_size, thickness, pad;
1093 GtkBorderStyle border_style;
1096 GtkStylePropertyContext context;
1097 cairo_pattern_t *pattern;
1099 flags = gtk_theming_engine_get_state (engine);
1102 gtk_theming_engine_get_color (engine, flags, &fg_color);
1103 gtk_theming_engine_get_background_color (engine, flags, &bg_color);
1104 gtk_theming_engine_get_border (engine, flags, &border);
1106 context.width = width;
1107 context.height = height;
1109 _gtk_theming_engine_get (engine, flags, &context,
1110 "background-image", &pattern,
1111 "border-style", &border_style,
1114 if (pattern != NULL)
1116 render_background_internal (engine, cr, x, y, width, height,
1117 gtk_theming_engine_get_junction_sides (engine), pattern);
1119 cairo_pattern_destroy (pattern);
1123 border_width = MIN (MIN (border.top, border.bottom),
1124 MIN (border.left, border.right));
1125 exterior_size = MIN (width, height);
1127 if (exterior_size % 2 == 0) /* Ensure odd */
1130 /* FIXME: thickness */
1132 pad = thickness + MAX (1, (exterior_size - 2 * thickness) / 9);
1133 interior_size = MAX (1, exterior_size - 2 * pad);
1135 if (interior_size < 7)
1138 pad = MAX (0, (exterior_size - interior_size) / 2);
1141 x -= (1 + exterior_size - (gint) width) / 2;
1142 y -= (1 + exterior_size - (gint) height) / 2;
1144 if (border_style == GTK_BORDER_STYLE_SOLID)
1146 GdkRGBA border_color;
1148 cairo_set_line_width (cr, border_width);
1149 gtk_theming_engine_get_border_color (engine, flags, &border_color);
1151 cairo_rectangle (cr, x + 0.5, y + 0.5, exterior_size - 1, exterior_size - 1);
1152 gdk_cairo_set_source_rgba (cr, &bg_color);
1153 cairo_fill_preserve (cr);
1155 gdk_cairo_set_source_rgba (cr, &border_color);
1159 gdk_cairo_set_source_rgba (cr, &fg_color);
1161 if (flags & GTK_STATE_FLAG_INCONSISTENT)
1163 int line_thickness = MAX (1, (3 + interior_size * 2) / 7);
1165 cairo_rectangle (cr,
1167 y + pad + (1 + interior_size - line_thickness) / 2,
1177 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress);
1179 if ((flags & GTK_STATE_FLAG_ACTIVE) || running)
1184 cairo_translate (cr,
1187 cairo_scale (cr, interior_size / 7., interior_size / 7.);
1189 cairo_rectangle (cr, 0, 0, 7 * progress, 7);
1192 cairo_move_to (cr, 7.0, 0.0);
1193 cairo_line_to (cr, 7.5, 1.0);
1194 cairo_curve_to (cr, 5.3, 2.0,
1197 cairo_curve_to (cr, 3.0, 5.7,
1200 cairo_line_to (cr, 0.2, 3.5);
1201 cairo_curve_to (cr, 1.1, 3.5,
1204 cairo_curve_to (cr, 1.0, 3.9,
1207 cairo_curve_to (cr, 3.5, 3.1,
1219 gtk_theming_engine_render_option (GtkThemingEngine *engine,
1226 GtkStateFlags flags;
1227 GdkRGBA fg_color, bg_color;
1228 gint exterior_size, interior_size, pad, thickness, border_width;
1229 GtkBorderStyle border_style;
1231 GtkStylePropertyContext context;
1232 cairo_pattern_t *pattern;
1234 flags = gtk_theming_engine_get_state (engine);
1238 gtk_theming_engine_get_color (engine, flags, &fg_color);
1239 gtk_theming_engine_get_background_color (engine, flags, &bg_color);
1240 gtk_theming_engine_get_border (engine, flags, &border);
1242 context.width = width;
1243 context.height = height;
1245 _gtk_theming_engine_get (engine, flags, &context,
1246 "background-image", &pattern,
1247 "border-style", &border_style,
1250 if (pattern != NULL)
1252 render_background_internal (engine, cr, x, y, width, height,
1253 gtk_theming_engine_get_junction_sides (engine), pattern);
1255 cairo_pattern_destroy (pattern);
1259 exterior_size = MIN (width, height);
1260 border_width = MIN (MIN (border.top, border.bottom),
1261 MIN (border.left, border.right));
1263 if (exterior_size % 2 == 0) /* Ensure odd */
1266 x -= (1 + exterior_size - width) / 2;
1267 y -= (1 + exterior_size - height) / 2;
1269 if (border_style == GTK_BORDER_STYLE_SOLID)
1271 GdkRGBA border_color;
1273 cairo_set_line_width (cr, border_width);
1274 gtk_theming_engine_get_border_color (engine, flags, &border_color);
1276 cairo_new_sub_path (cr);
1278 x + exterior_size / 2.,
1279 y + exterior_size / 2.,
1280 (exterior_size - 1) / 2.,
1283 gdk_cairo_set_source_rgba (cr, &bg_color);
1284 cairo_fill_preserve (cr);
1286 gdk_cairo_set_source_rgba (cr, &border_color);
1290 gdk_cairo_set_source_rgba (cr, &fg_color);
1292 /* FIXME: thickness */
1295 if (flags & GTK_STATE_FLAG_INCONSISTENT)
1297 gint line_thickness;
1299 pad = thickness + MAX (1, (exterior_size - 2 * thickness) / 9);
1300 interior_size = MAX (1, exterior_size - 2 * pad);
1302 if (interior_size < 7)
1305 pad = MAX (0, (exterior_size - interior_size) / 2);
1308 line_thickness = MAX (1, (3 + interior_size * 2) / 7);
1310 cairo_rectangle (cr,
1312 y + pad + (interior_size - line_thickness) / 2.,
1317 if (flags & GTK_STATE_FLAG_ACTIVE)
1319 pad = thickness + MAX (1, 2 * (exterior_size - 2 * thickness) / 9);
1320 interior_size = MAX (1, exterior_size - 2 * pad);
1322 if (interior_size < 5)
1325 pad = MAX (0, (exterior_size - interior_size) / 2);
1328 cairo_new_sub_path (cr);
1330 x + pad + interior_size / 2.,
1331 y + pad + interior_size / 2.,
1341 add_path_arrow (cairo_t *cr,
1349 cairo_translate (cr, x + (size / 2), y + (size / 2));
1350 cairo_rotate (cr, angle);
1352 cairo_move_to (cr, 0, - (size / 4));
1353 cairo_line_to (cr, - (size / 2), (size / 4));
1354 cairo_line_to (cr, (size / 2), (size / 4));
1355 cairo_close_path (cr);
1361 gtk_theming_engine_render_arrow (GtkThemingEngine *engine,
1368 GtkStateFlags flags;
1373 flags = gtk_theming_engine_get_state (engine);
1374 gtk_theming_engine_get_color (engine, flags, &fg_color);
1376 if (flags & GTK_STATE_FLAG_INSENSITIVE)
1378 add_path_arrow (cr, angle, x + 1, y + 1, size);
1379 cairo_set_source_rgb (cr, 1, 1, 1);
1383 add_path_arrow (cr, angle, x, y, size);
1384 gdk_cairo_set_source_rgba (cr, &fg_color);
1391 add_path_line (cairo_t *cr,
1397 /* Adjust endpoints */
1411 cairo_move_to (cr, x1, y1);
1412 cairo_line_to (cr, x2, y2);
1416 color_shade (const GdkRGBA *color,
1418 GdkRGBA *color_return)
1420 GtkSymbolicColor *literal, *shade;
1422 literal = gtk_symbolic_color_new_literal (color);
1423 shade = gtk_symbolic_color_new_shade (literal, factor);
1424 gtk_symbolic_color_unref (literal);
1426 gtk_symbolic_color_resolve (shade, NULL, color_return);
1427 gtk_symbolic_color_unref (shade);
1430 /* optional_background is the background-image, in case it was
1431 already availible we avoid getting it (and thus possibly
1432 rendering it) twice */
1434 render_background_internal (GtkThemingEngine *engine,
1440 GtkJunctionSides junction,
1441 cairo_pattern_t *optional_background)
1444 cairo_pattern_t *pattern;
1445 GtkCssBackgroundRepeat *repeat;
1446 GtkStateFlags flags;
1449 GtkRoundedBox padding_box;
1450 GtkRoundedBox clip_box;
1451 GtkShadow *box_shadow;
1452 GtkBorder border, padding;
1453 GtkStylePropertyContext context;
1454 GtkCssArea clip, origin;
1455 gdouble bg_width, bg_height, bg_x, bg_y;
1457 flags = gtk_theming_engine_get_state (engine);
1459 gtk_theming_engine_get_background_color (engine, flags, &bg_color);
1461 gtk_theming_engine_get (engine, flags,
1462 "background-origin", &origin,
1463 "background-clip", &clip,
1464 "background-repeat", &repeat,
1465 "box-shadow", &box_shadow,
1468 gtk_theming_engine_get_border (engine, flags, &border);
1469 gtk_theming_engine_get_padding (engine, flags, &padding);
1471 /* The default size of the background image depends on the
1472 background-origin value as this affects the top left
1473 and the bottom right corners. */
1475 case GTK_CSS_AREA_BORDER_BOX:
1481 case GTK_CSS_AREA_PADDING_BOX:
1485 bg_width = width - border.left - border.left;
1486 bg_height = height - border.top - border.bottom;
1488 case GTK_CSS_AREA_CONTENT_BOX:
1489 bg_x = border.left + padding.left;
1490 bg_y = border.top + padding.top;
1491 bg_width = width - border.left - border.right - padding.left - padding.right;
1492 bg_height = height - border.top - border.bottom - padding.top - padding.bottom;
1496 context.width = bg_width;
1497 context.height = bg_height;
1499 if (optional_background)
1500 pattern = cairo_pattern_reference (optional_background);
1502 _gtk_theming_engine_get (engine, flags, &context,
1503 "background-image", &pattern,
1508 cairo_translate (cr, x, y);
1510 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
1512 if (gtk_theming_engine_has_class (engine, "background"))
1514 cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0); /* transparent */
1515 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
1521 cairo_pattern_t *other_pattern;
1522 GtkStateFlags other_flags;
1524 cairo_pattern_t *new_pattern = NULL;
1526 if (flags & GTK_STATE_FLAG_PRELIGHT)
1528 other_flags = flags & ~(GTK_STATE_FLAG_PRELIGHT);
1529 progress = 1 - progress;
1532 other_flags = flags | GTK_STATE_FLAG_PRELIGHT;
1534 gtk_theming_engine_get_background_color (engine, other_flags, &other_bg);
1535 _gtk_theming_engine_get (engine, other_flags, &context,
1536 "background-image", &other_pattern,
1539 if (pattern && other_pattern)
1541 cairo_pattern_type_t type, other_type;
1544 cairo_pattern_get_color_stop_count (pattern, &n0);
1545 cairo_pattern_get_color_stop_count (other_pattern, &n1);
1546 type = cairo_pattern_get_type (pattern);
1547 other_type = cairo_pattern_get_type (other_pattern);
1549 if (type == other_type && n0 == n1)
1551 gdouble offset0, red0, green0, blue0, alpha0;
1552 gdouble offset1, red1, green1, blue1, alpha1;
1553 gdouble x00, x01, y00, y01, x10, x11, y10, y11;
1554 gdouble r00, r01, r10, r11;
1557 if (type == CAIRO_PATTERN_TYPE_LINEAR)
1559 cairo_pattern_get_linear_points (pattern, &x00, &y00, &x01, &y01);
1560 cairo_pattern_get_linear_points (other_pattern, &x10, &y10, &x11, &y11);
1562 new_pattern = cairo_pattern_create_linear (x00 + (x10 - x00) * progress,
1563 y00 + (y10 - y00) * progress,
1564 x01 + (x11 - x01) * progress,
1565 y01 + (y11 - y01) * progress);
1569 cairo_pattern_get_radial_circles (pattern, &x00, &y00, &r00, &x01, &y01, &r01);
1570 cairo_pattern_get_radial_circles (other_pattern, &x10, &y10, &r10, &x11, &y11, &r11);
1572 new_pattern = cairo_pattern_create_radial (x00 + (x10 - x00) * progress,
1573 y00 + (y10 - y00) * progress,
1574 r00 + (r10 - r00) * progress,
1575 x01 + (x11 - x01) * progress,
1576 y01 + (y11 - y01) * progress,
1577 r01 + (r11 - r01) * progress);
1580 cairo_pattern_set_filter (new_pattern, CAIRO_FILTER_FAST);
1583 /* Blend both gradients into one */
1584 while (i < n0 && i < n1)
1586 cairo_pattern_get_color_stop_rgba (pattern, i,
1588 &red0, &green0, &blue0,
1590 cairo_pattern_get_color_stop_rgba (other_pattern, i,
1592 &red1, &green1, &blue1,
1595 cairo_pattern_add_color_stop_rgba (new_pattern,
1596 offset0 + ((offset1 - offset0) * progress),
1597 red0 + ((red1 - red0) * progress),
1598 green0 + ((green1 - green0) * progress),
1599 blue0 + ((blue1 - blue0) * progress),
1600 alpha0 + ((alpha1 - alpha0) * progress));
1608 cairo_rectangle (cr, 0, 0, width, height);
1611 cairo_push_group (cr);
1613 cairo_scale (cr, width, height);
1614 cairo_set_source (cr, other_pattern);
1615 cairo_paint_with_alpha (cr, progress);
1616 cairo_set_source (cr, pattern);
1617 cairo_paint_with_alpha (cr, 1.0 - progress);
1619 new_pattern = cairo_pop_group (cr);
1624 else if (pattern || other_pattern)
1628 gdouble x0, y0, x1, y1, r0, r1;
1631 /* Blend a pattern with a color */
1636 progress = 1 - progress;
1644 if (cairo_pattern_get_type (p) == CAIRO_PATTERN_TYPE_LINEAR)
1646 cairo_pattern_get_linear_points (p, &x0, &y0, &x1, &y1);
1647 new_pattern = cairo_pattern_create_linear (x0, y0, x1, y1);
1651 cairo_pattern_get_radial_circles (p, &x0, &y0, &r0, &x1, &y1, &r1);
1652 new_pattern = cairo_pattern_create_radial (x0, y0, r0, x1, y1, r1);
1655 cairo_pattern_get_color_stop_count (p, &n);
1657 for (i = 0; i < n; i++)
1659 gdouble red1, green1, blue1, alpha1;
1662 cairo_pattern_get_color_stop_rgba (p, i,
1664 &red1, &green1, &blue1,
1666 cairo_pattern_add_color_stop_rgba (new_pattern, offset,
1667 c->red + ((red1 - c->red) * progress),
1668 c->green + ((green1 - c->green) * progress),
1669 c->blue + ((blue1 - c->blue) * progress),
1670 c->alpha + ((alpha1 - c->alpha) * progress));
1675 /* Merge just colors */
1676 new_pattern = cairo_pattern_create_rgba (CLAMP (bg_color.red + ((other_bg.red - bg_color.red) * progress), 0, 1),
1677 CLAMP (bg_color.green + ((other_bg.green - bg_color.green) * progress), 0, 1),
1678 CLAMP (bg_color.blue + ((other_bg.blue - bg_color.blue) * progress), 0, 1),
1679 CLAMP (bg_color.alpha + ((other_bg.alpha - bg_color.alpha) * progress), 0, 1));
1684 /* Replace pattern to use */
1685 cairo_pattern_destroy (pattern);
1686 pattern = new_pattern;
1690 cairo_pattern_destroy (other_pattern);
1693 /* In the CSS box model, by default the background positioning area is
1694 * the padding-box, i.e. all the border-box minus the borders themselves,
1695 * which determines also its default size, see
1696 * http://dev.w3.org/csswg/css3-background/#background-origin
1698 * In the future we might want to support different origins or clips, but
1699 * right now we just shrink to the default.
1701 _gtk_rounded_box_init_rect (&padding_box, 0, 0, width, height);
1702 _gtk_rounded_box_apply_border_radius (&padding_box, engine, flags, junction);
1703 clip_box = padding_box;
1704 _gtk_rounded_box_shrink (&padding_box,
1705 border.top, border.right,
1706 border.bottom, border.left);
1707 if (clip == GTK_CSS_AREA_PADDING_BOX)
1709 _gtk_rounded_box_shrink (&clip_box,
1710 border.top, border.right,
1711 border.bottom, border.left);
1713 else if (clip == GTK_CSS_AREA_CONTENT_BOX)
1715 _gtk_rounded_box_shrink (&clip_box,
1716 border.top + padding.top,
1717 border.right + padding.right,
1718 border.bottom + padding.bottom,
1719 border.left + padding.left);
1722 _gtk_rounded_box_path (&clip_box, cr);
1726 cairo_surface_t *surface;
1727 int scale_width, scale_height;
1729 if (cairo_pattern_get_surface (pattern, &surface) != CAIRO_STATUS_SUCCESS)
1732 if (surface && repeat &&
1733 repeat->repeat != GTK_CSS_BACKGROUND_REPEAT_STYLE_NONE)
1735 scale_width = cairo_image_surface_get_width (surface);
1736 scale_height = cairo_image_surface_get_height (surface);
1737 if (repeat->repeat == GTK_CSS_BACKGROUND_REPEAT_STYLE_REPEAT)
1738 cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
1739 else if (repeat->repeat == GTK_CSS_BACKGROUND_REPEAT_STYLE_NO_REPEAT)
1740 cairo_pattern_set_extend (pattern, CAIRO_EXTEND_NONE);
1744 cairo_pattern_set_extend (pattern, CAIRO_EXTEND_PAD);
1745 scale_width = bg_width;
1746 scale_height = bg_height;
1749 cairo_translate (cr, bg_x, bg_y);
1750 cairo_scale (cr, scale_width, scale_height);
1751 cairo_set_source (cr, pattern);
1752 cairo_scale (cr, 1.0 / scale_width, 1.0 / scale_height);
1753 cairo_translate (cr, -bg_x, -bg_y);
1756 gdk_cairo_set_source_rgba (cr, &bg_color);
1761 cairo_pattern_destroy (pattern);
1766 if (box_shadow != NULL)
1768 _gtk_box_shadow_render (box_shadow, cr, &padding_box);
1769 _gtk_shadow_unref (box_shadow);
1776 gtk_theming_engine_render_background (GtkThemingEngine *engine,
1783 GtkJunctionSides junction;
1785 junction = gtk_theming_engine_get_junction_sides (engine);
1787 render_background_internal (engine, cr,
1788 x, y, width, height,
1793 gtk_theming_engine_hide_border_sides (GtkBorder *border,
1796 if (hidden_side & SIDE_TOP)
1798 if (hidden_side & SIDE_RIGHT)
1800 if (hidden_side & SIDE_BOTTOM)
1802 if (hidden_side & SIDE_LEFT)
1807 render_frame_internal (GtkThemingEngine *engine,
1814 GtkJunctionSides junction)
1816 GtkStateFlags state;
1817 GtkBorderStyle border_style;
1818 GtkRoundedBox border_box, padding_box;
1822 static const guint current_side[4] = { SIDE_TOP, SIDE_RIGHT, SIDE_BOTTOM, SIDE_LEFT };
1826 state = gtk_theming_engine_get_state (engine);
1828 gtk_theming_engine_get_border (engine, state, &border);
1829 gtk_theming_engine_hide_border_sides (&border, hidden_side);
1831 gtk_theming_engine_get (engine, state,
1832 "border-style", &border_style,
1833 "border-top-color", &colors[0],
1834 "border-right-color", &colors[1],
1835 "border-bottom-color", &colors[2],
1836 "border-left-color", &colors[3],
1839 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
1843 GtkStateFlags other_state;
1844 GdkRGBA *other_colors[4];
1846 if (state & GTK_STATE_FLAG_PRELIGHT)
1848 other_state = state & ~(GTK_STATE_FLAG_PRELIGHT);
1849 progress = 1 - progress;
1852 other_state = state | GTK_STATE_FLAG_PRELIGHT;
1854 gtk_theming_engine_get (engine, other_state,
1855 "border-top-color", &other_colors[0],
1856 "border-right-color", &other_colors[1],
1857 "border-bottom-color", &other_colors[2],
1858 "border-left-color", &other_colors[3],
1861 for (i = 0; i < 4; i++)
1863 colors[i]->red = CLAMP (colors[i]->red + ((other_colors[i]->red - colors[i]->red) * progress), 0, 1);
1864 colors[i]->green = CLAMP (colors[i]->green + ((other_colors[i]->green - colors[i]->green) * progress), 0, 1);
1865 colors[i]->blue = CLAMP (colors[i]->blue + ((other_colors[i]->blue - colors[i]->blue) * progress), 0, 1);
1866 colors[i]->alpha = CLAMP (colors[i]->alpha + ((other_colors[i]->alpha - colors[i]->alpha) * progress), 0, 1);
1867 gdk_rgba_free (other_colors[i]);
1871 switch (border_style)
1874 g_assert_not_reached ();
1875 case GTK_BORDER_STYLE_NONE:
1876 case GTK_BORDER_STYLE_SOLID:
1878 case GTK_BORDER_STYLE_INSET:
1879 color_shade (colors[1], 1.8, colors[1]);
1880 color_shade (colors[2], 1.8, colors[2]);
1882 case GTK_BORDER_STYLE_OUTSET:
1883 color_shade (colors[0], 1.8, colors[0]);
1884 color_shade (colors[3], 1.8, colors[3]);
1890 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
1892 _gtk_rounded_box_init_rect (&border_box, x, y, width, height);
1893 _gtk_rounded_box_apply_border_radius (&border_box, engine, state, junction);
1894 padding_box = border_box;
1895 _gtk_rounded_box_shrink (&padding_box, border.top, border.right, border.bottom, border.left);
1897 switch (border_style)
1899 case GTK_BORDER_STYLE_NONE:
1901 case GTK_BORDER_STYLE_SOLID:
1902 case GTK_BORDER_STYLE_INSET:
1903 case GTK_BORDER_STYLE_OUTSET:
1905 if (gdk_rgba_equal (colors[0], colors[1]) &&
1906 gdk_rgba_equal (colors[0], colors[2]) &&
1907 gdk_rgba_equal (colors[0], colors[3]))
1909 gdk_cairo_set_source_rgba (cr, colors[0]);
1911 _gtk_rounded_box_path (&border_box, cr);
1912 _gtk_rounded_box_path (&padding_box, cr);
1917 for (i = 0; i < 4; i++)
1919 if (hidden_side & current_side[i])
1922 for (j = 0; j < 4; j++)
1924 if (hidden_side & current_side[j])
1928 gdk_rgba_equal (colors[i], colors[j]))
1930 /* We were already painted when i == j */
1935 _gtk_rounded_box_path_top (&border_box, &padding_box, cr);
1937 _gtk_rounded_box_path_right (&border_box, &padding_box, cr);
1939 _gtk_rounded_box_path_bottom (&border_box, &padding_box, cr);
1941 _gtk_rounded_box_path_left (&border_box, &padding_box, cr);
1944 /* We were already painted when i == j */
1948 gdk_cairo_set_source_rgba (cr, colors[i]);
1958 for (i = 0; i < 4; i++)
1959 gdk_rgba_free (colors[i]);
1963 gtk_theming_engine_render_frame (GtkThemingEngine *engine,
1970 GtkStateFlags flags;
1971 GtkBorderStyle border_style;
1972 GtkJunctionSides junction;
1973 GtkBorderImage *border_image;
1975 GtkStylePropertyContext context;
1977 flags = gtk_theming_engine_get_state (engine);
1978 junction = gtk_theming_engine_get_junction_sides (engine);
1979 gtk_theming_engine_get_border (engine, flags, &border);
1981 context.width = width;
1982 context.height = height;
1984 _gtk_theming_engine_get (engine, flags, &context,
1985 "border-image", &border_image,
1986 "border-style", &border_style,
1989 if (border_image != NULL)
1991 _gtk_border_image_render (border_image, &border,
1992 cr, x, y, width, height);
1993 _gtk_border_image_unref (border_image);
1995 else if (border_style != GTK_BORDER_STYLE_NONE)
1996 render_frame_internal (engine, cr,
1997 x, y, width, height,
2002 gtk_theming_engine_render_expander (GtkThemingEngine *engine,
2009 GtkStateFlags flags;
2010 GdkRGBA outline_color, fg_color;
2011 double vertical_overshoot;
2014 double interp; /* interpolation factor for center position */
2015 double x_double_horz, y_double_horz;
2016 double x_double_vert, y_double_vert;
2017 double x_double, y_double;
2020 gboolean running, is_rtl;
2024 flags = gtk_theming_engine_get_state (engine);
2026 gtk_theming_engine_get_color (engine, flags, &fg_color);
2027 gtk_theming_engine_get_border_color (engine, flags, &outline_color);
2029 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress);
2030 is_rtl = (gtk_theming_engine_get_direction (engine) == GTK_TEXT_DIR_RTL);
2034 progress = (flags & GTK_STATE_FLAG_ACTIVE) ? 1 : 0;
2036 if (!gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_HORIZONTAL))
2039 angle = (G_PI) - ((G_PI / 2) * progress);
2041 angle = (G_PI / 2) * progress;
2046 angle = (G_PI / 2) + ((G_PI / 2) * progress);
2048 angle = (G_PI / 2) - ((G_PI / 2) * progress);
2053 /* Compute distance that the stroke extends beyonds the end
2054 * of the triangle we draw.
2056 vertical_overshoot = line_width / 2.0 * (1. / tan (G_PI / 8));
2058 /* For odd line widths, we end the vertical line of the triangle
2059 * at a half pixel, so we round differently.
2061 if (line_width % 2 == 1)
2062 vertical_overshoot = ceil (0.5 + vertical_overshoot) - 0.5;
2064 vertical_overshoot = ceil (vertical_overshoot);
2066 /* Adjust the size of the triangle we draw so that the entire stroke fits
2068 diameter = (gint) MAX (3, width - 2 * vertical_overshoot);
2070 /* If the line width is odd, we want the diameter to be even,
2071 * and vice versa, so force the sum to be odd. This relationship
2072 * makes the point of the triangle look right.
2074 diameter -= (1 - (diameter + line_width) % 2);
2076 radius = diameter / 2.;
2078 /* Adjust the center so that the stroke is properly aligned with
2079 * the pixel grid. The center adjustment is different for the
2080 * horizontal and vertical orientations. For intermediate positions
2081 * we interpolate between the two.
2083 x_double_vert = floor ((x + width / 2) - (radius + line_width) / 2.) + (radius + line_width) / 2.;
2084 y_double_vert = (y + height / 2) - 0.5;
2086 x_double_horz = (x + width / 2) - 0.5;
2087 y_double_horz = floor ((y + height / 2) - (radius + line_width) / 2.) + (radius + line_width) / 2.;
2089 x_double = x_double_vert * (1 - interp) + x_double_horz * interp;
2090 y_double = y_double_vert * (1 - interp) + y_double_horz * interp;
2092 cairo_translate (cr, x_double, y_double);
2093 cairo_rotate (cr, angle);
2095 cairo_move_to (cr, - radius / 2., - radius);
2096 cairo_line_to (cr, radius / 2., 0);
2097 cairo_line_to (cr, - radius / 2., radius);
2098 cairo_close_path (cr);
2100 cairo_set_line_width (cr, line_width);
2102 gdk_cairo_set_source_rgba (cr, &fg_color);
2104 cairo_fill_preserve (cr);
2106 gdk_cairo_set_source_rgba (cr, &outline_color);
2113 gtk_theming_engine_render_focus (GtkThemingEngine *engine,
2120 GtkStateFlags flags;
2126 flags = gtk_theming_engine_get_state (engine);
2128 gtk_theming_engine_get_color (engine, flags, &color);
2130 gtk_theming_engine_get_style (engine,
2131 "focus-line-width", &line_width,
2132 "focus-line-pattern", (gchar *) &dash_list,
2135 cairo_set_line_width (cr, (gdouble) line_width);
2139 gint n_dashes = strlen ((const gchar *) dash_list);
2140 gdouble *dashes = g_new (gdouble, n_dashes);
2141 gdouble total_length = 0;
2142 gdouble dash_offset;
2145 for (i = 0; i < n_dashes; i++)
2147 dashes[i] = dash_list[i];
2148 total_length += dash_list[i];
2151 /* The dash offset here aligns the pattern to integer pixels
2152 * by starting the dash at the right side of the left border
2153 * Negative dash offsets in cairo don't work
2154 * (https://bugs.freedesktop.org/show_bug.cgi?id=2729)
2156 dash_offset = - line_width / 2.;
2158 while (dash_offset < 0)
2159 dash_offset += total_length;
2161 cairo_set_dash (cr, dashes, n_dashes, dash_offset);
2165 cairo_rectangle (cr,
2166 x + line_width / 2.,
2167 y + line_width / 2.,
2169 height - line_width);
2171 gdk_cairo_set_source_rgba (cr, &color);
2180 gtk_theming_engine_render_line (GtkThemingEngine *engine,
2188 GtkStateFlags flags;
2190 flags = gtk_theming_engine_get_state (engine);
2193 gtk_theming_engine_get_color (engine, flags, &color);
2195 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
2196 cairo_set_line_width (cr, 1);
2198 cairo_move_to (cr, x0 + 0.5, y0 + 0.5);
2199 cairo_line_to (cr, x1 + 0.5, y1 + 0.5);
2201 gdk_cairo_set_source_rgba (cr, &color);
2208 prepare_context_for_layout (cairo_t *cr,
2211 PangoLayout *layout)
2213 const PangoMatrix *matrix;
2215 matrix = pango_context_get_matrix (pango_layout_get_context (layout));
2217 cairo_move_to (cr, x, y);
2221 cairo_matrix_t cairo_matrix;
2223 cairo_matrix_init (&cairo_matrix,
2224 matrix->xx, matrix->yx,
2225 matrix->xy, matrix->yy,
2226 matrix->x0, matrix->y0);
2228 cairo_transform (cr, &cairo_matrix);
2233 gtk_theming_engine_render_layout (GtkThemingEngine *engine,
2237 PangoLayout *layout)
2240 GtkShadow *text_shadow = NULL;
2241 GtkStateFlags flags;
2246 flags = gtk_theming_engine_get_state (engine);
2247 gtk_theming_engine_get_color (engine, flags, &fg_color);
2249 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
2253 GtkStateFlags other_flags;
2256 if (flags & GTK_STATE_FLAG_PRELIGHT)
2258 other_flags = flags & ~(GTK_STATE_FLAG_PRELIGHT);
2259 progress = 1 - progress;
2262 other_flags = flags | GTK_STATE_FLAG_PRELIGHT;
2264 gtk_theming_engine_get_color (engine, other_flags, &other_fg);
2266 fg_color.red = CLAMP (fg_color.red + ((other_fg.red - fg_color.red) * progress), 0, 1);
2267 fg_color.green = CLAMP (fg_color.green + ((other_fg.green - fg_color.green) * progress), 0, 1);
2268 fg_color.blue = CLAMP (fg_color.blue + ((other_fg.blue - fg_color.blue) * progress), 0, 1);
2269 fg_color.alpha = CLAMP (fg_color.alpha + ((other_fg.alpha - fg_color.alpha) * progress), 0, 1);
2272 gtk_theming_engine_get (engine, flags,
2273 "text-shadow", &text_shadow,
2276 prepare_context_for_layout (cr, x, y, layout);
2278 if (text_shadow != NULL)
2280 _gtk_text_shadow_paint_layout (text_shadow, cr, layout);
2281 _gtk_shadow_unref (text_shadow);
2284 gdk_cairo_set_source_rgba (cr, &fg_color);
2285 pango_cairo_show_layout (cr, layout);
2291 gtk_theming_engine_render_slider (GtkThemingEngine *engine,
2297 GtkOrientation orientation)
2299 const GtkWidgetPath *path;
2302 path = gtk_theming_engine_get_path (engine);
2304 gtk_theming_engine_render_background (engine, cr, x, y, width, height);
2305 gtk_theming_engine_render_frame (engine, cr, x, y, width, height);
2307 /* FIXME: thickness */
2310 if (gtk_widget_path_is_type (path, GTK_TYPE_SCALE))
2312 if (orientation == GTK_ORIENTATION_VERTICAL)
2313 gtk_theming_engine_render_line (engine, cr,
2315 y + (gint) height / 2,
2316 x + width - thickness - 1,
2317 y + (gint) height / 2);
2319 gtk_theming_engine_render_line (engine, cr,
2320 x + (gint) width / 2,
2322 x + (gint) width / 2,
2323 y + height - thickness - 1);
2328 gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
2334 GtkPositionType gap_side,
2338 GtkJunctionSides junction;
2339 GtkStateFlags state;
2341 GtkCssBorderCornerRadius *top_left_radius, *top_right_radius;
2342 GtkCssBorderCornerRadius *bottom_left_radius, *bottom_right_radius;
2343 GtkCssBorderRadius border_radius = { { 0, }, };
2344 gdouble x0, y0, x1, y1, xc, yc, wc, hc;
2347 xc = yc = wc = hc = 0;
2348 state = gtk_theming_engine_get_state (engine);
2349 junction = gtk_theming_engine_get_junction_sides (engine);
2351 gtk_theming_engine_get_border (engine, state, &border);
2352 gtk_theming_engine_get (engine, state,
2353 /* Can't use border-radius as it's an int for
2354 * backwards compat */
2355 "border-top-left-radius", &top_left_radius,
2356 "border-top-right-radius", &top_right_radius,
2357 "border-bottom-right-radius", &bottom_right_radius,
2358 "border-bottom-left-radius", &bottom_left_radius,
2361 if (top_left_radius)
2362 border_radius.top_left = *top_left_radius;
2363 g_free (top_left_radius);
2364 if (top_right_radius)
2365 border_radius.top_right = *top_right_radius;
2366 g_free (top_right_radius);
2367 if (bottom_right_radius)
2368 border_radius.bottom_right = *bottom_right_radius;
2369 g_free (bottom_right_radius);
2370 if (bottom_left_radius)
2371 border_radius.bottom_left = *bottom_left_radius;
2372 g_free (bottom_left_radius);
2374 border_width = MIN (MIN (border.top, border.bottom),
2375 MIN (border.left, border.right));
2382 xc = x + xy0_gap + border_width;
2384 wc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
2387 if (xy0_gap < border_radius.top_left.horizontal)
2388 junction |= GTK_JUNCTION_CORNER_TOPLEFT;
2390 if (xy1_gap > width - border_radius.top_right.horizontal)
2391 junction |= GTK_JUNCTION_CORNER_TOPRIGHT;
2393 case GTK_POS_BOTTOM:
2394 xc = x + xy0_gap + border_width;
2395 yc = y + height - border_width;
2396 wc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
2399 if (xy0_gap < border_radius.bottom_left.horizontal)
2400 junction |= GTK_JUNCTION_CORNER_BOTTOMLEFT;
2402 if (xy1_gap > width - border_radius.bottom_right.horizontal)
2403 junction |= GTK_JUNCTION_CORNER_BOTTOMRIGHT;
2408 yc = y + xy0_gap + border_width;
2410 hc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
2412 if (xy0_gap < border_radius.top_left.vertical)
2413 junction |= GTK_JUNCTION_CORNER_TOPLEFT;
2415 if (xy1_gap > height - border_radius.bottom_left.vertical)
2416 junction |= GTK_JUNCTION_CORNER_BOTTOMLEFT;
2420 xc = x + width - border_width;
2421 yc = y + xy0_gap + border_width;
2423 hc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
2425 if (xy0_gap < border_radius.top_right.vertical)
2426 junction |= GTK_JUNCTION_CORNER_TOPRIGHT;
2428 if (xy1_gap > height - border_radius.bottom_right.vertical)
2429 junction |= GTK_JUNCTION_CORNER_BOTTOMRIGHT;
2434 cairo_clip_extents (cr, &x0, &y0, &x1, &y1);
2435 cairo_rectangle (cr, x0, y0, x1 - x0, yc - y0);
2436 cairo_rectangle (cr, x0, yc, xc - x0, hc);
2437 cairo_rectangle (cr, xc + wc, yc, x1 - (xc + wc), hc);
2438 cairo_rectangle (cr, x0, yc + hc, x1 - x0, y1 - (yc + hc));
2441 render_frame_internal (engine, cr,
2442 x, y, width, height,
2449 gtk_theming_engine_render_extension (GtkThemingEngine *engine,
2455 GtkPositionType gap_side)
2457 GtkJunctionSides junction = 0;
2458 guint hidden_side = 0;
2465 junction = GTK_JUNCTION_LEFT;
2466 hidden_side = SIDE_LEFT;
2468 cairo_translate (cr, x + width, y);
2469 cairo_rotate (cr, G_PI / 2);
2472 junction = GTK_JUNCTION_RIGHT;
2473 hidden_side = SIDE_RIGHT;
2475 cairo_translate (cr, x, y + height);
2476 cairo_rotate (cr, - G_PI / 2);
2479 junction = GTK_JUNCTION_TOP;
2480 hidden_side = SIDE_TOP;
2482 cairo_translate (cr, x + width, y + height);
2483 cairo_rotate (cr, G_PI);
2485 case GTK_POS_BOTTOM:
2486 junction = GTK_JUNCTION_BOTTOM;
2487 hidden_side = SIDE_BOTTOM;
2489 cairo_translate (cr, x, y);
2493 if (gap_side == GTK_POS_TOP ||
2494 gap_side == GTK_POS_BOTTOM)
2495 render_background_internal (engine, cr,
2496 0, 0, width, height,
2497 GTK_JUNCTION_BOTTOM, NULL);
2499 render_background_internal (engine, cr,
2500 0, 0, height, width,
2501 GTK_JUNCTION_BOTTOM, NULL);
2506 render_frame_internal (engine, cr,
2507 x, y, width, height,
2508 hidden_side, junction);
2514 render_dot (cairo_t *cr,
2515 const GdkRGBA *lighter,
2516 const GdkRGBA *darker,
2521 size = CLAMP ((gint) size, 2, 3);
2525 gdk_cairo_set_source_rgba (cr, lighter);
2526 cairo_rectangle (cr, x, y, 1, 1);
2527 cairo_rectangle (cr, x + 1, y + 1, 1, 1);
2532 gdk_cairo_set_source_rgba (cr, lighter);
2533 cairo_rectangle (cr, x, y, 2, 1);
2534 cairo_rectangle (cr, x, y, 1, 2);
2537 gdk_cairo_set_source_rgba (cr, darker);
2538 cairo_rectangle (cr, x + 1, y + 1, 2, 1);
2539 cairo_rectangle (cr, x + 2, y, 1, 2);
2545 gtk_theming_engine_render_handle (GtkThemingEngine *engine,
2552 GtkStateFlags flags;
2553 GdkRGBA bg_color, lighter, darker;
2554 GtkJunctionSides sides;
2558 flags = gtk_theming_engine_get_state (engine);
2560 cairo_set_line_width (cr, 1.0);
2561 sides = gtk_theming_engine_get_junction_sides (engine);
2562 gtk_theming_engine_get_background_color (engine, flags, &bg_color);
2564 color_shade (&bg_color, 0.7, &darker);
2565 color_shade (&bg_color, 1.3, &lighter);
2567 render_background_internal (engine, cr, x, y, width, height, sides, NULL);
2569 if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_GRIP))
2571 /* reduce confusing values to a meaningful state */
2572 if ((sides & (GTK_JUNCTION_CORNER_TOPLEFT | GTK_JUNCTION_CORNER_BOTTOMRIGHT)) == (GTK_JUNCTION_CORNER_TOPLEFT | GTK_JUNCTION_CORNER_BOTTOMRIGHT))
2573 sides &= ~GTK_JUNCTION_CORNER_TOPLEFT;
2575 if ((sides & (GTK_JUNCTION_CORNER_TOPRIGHT | GTK_JUNCTION_CORNER_BOTTOMLEFT)) == (GTK_JUNCTION_CORNER_TOPRIGHT | GTK_JUNCTION_CORNER_BOTTOMLEFT))
2576 sides &= ~GTK_JUNCTION_CORNER_TOPRIGHT;
2579 sides = GTK_JUNCTION_CORNER_BOTTOMRIGHT;
2581 /* align drawing area to the connected side */
2582 if (sides == GTK_JUNCTION_LEFT)
2587 else if (sides == GTK_JUNCTION_CORNER_TOPLEFT)
2591 else if (height < width)
2594 else if (sides == GTK_JUNCTION_CORNER_BOTTOMLEFT)
2596 /* make it square, aligning to bottom left */
2599 y += (height - width);
2602 else if (height < width)
2605 else if (sides == GTK_JUNCTION_RIGHT)
2607 /* aligning to right */
2610 x += (width - height);
2614 else if (sides == GTK_JUNCTION_CORNER_TOPRIGHT)
2618 else if (height < width)
2620 x += (width - height);
2624 else if (sides == GTK_JUNCTION_CORNER_BOTTOMRIGHT)
2626 /* make it square, aligning to bottom right */
2629 y += (height - width);
2632 else if (height < width)
2634 x += (width - height);
2638 else if (sides == GTK_JUNCTION_TOP)
2643 else if (sides == GTK_JUNCTION_BOTTOM)
2645 /* align to bottom */
2648 y += (height - width);
2653 g_assert_not_reached ();
2655 if (sides == GTK_JUNCTION_LEFT ||
2656 sides == GTK_JUNCTION_RIGHT)
2662 while (xi < x + width)
2664 gdk_cairo_set_source_rgba (cr, &lighter);
2665 add_path_line (cr, x, y, x, y + height);
2669 gdk_cairo_set_source_rgba (cr, &darker);
2670 add_path_line (cr, xi, y, xi, y + height);
2675 else if (sides == GTK_JUNCTION_TOP ||
2676 sides == GTK_JUNCTION_BOTTOM)
2682 while (yi < y + height)
2684 gdk_cairo_set_source_rgba (cr, &lighter);
2685 add_path_line (cr, x, yi, x + width, yi);
2689 gdk_cairo_set_source_rgba (cr, &darker);
2690 add_path_line (cr, x, yi, x + width, yi);
2695 else if (sides == GTK_JUNCTION_CORNER_TOPLEFT)
2704 gdk_cairo_set_source_rgba (cr, &darker);
2705 add_path_line (cr, xi, y, x, yi);
2711 add_path_line (cr, xi, y, x, yi);
2717 gdk_cairo_set_source_rgba (cr, &lighter);
2718 add_path_line (cr, xi, y, x, yi);
2725 else if (sides == GTK_JUNCTION_CORNER_TOPRIGHT)
2732 while (xi < (x + width - 3))
2734 gdk_cairo_set_source_rgba (cr, &lighter);
2735 add_path_line (cr, xi, y, x + width, yi);
2741 gdk_cairo_set_source_rgba (cr, &darker);
2742 add_path_line (cr, xi, y, x + width, yi);
2748 add_path_line (cr, xi, y, x + width, yi);
2755 else if (sides == GTK_JUNCTION_CORNER_BOTTOMLEFT)
2764 gdk_cairo_set_source_rgba (cr, &darker);
2765 add_path_line (cr, x, yi, xi, y + height);
2771 add_path_line (cr, x, yi, xi, y + height);
2777 gdk_cairo_set_source_rgba (cr, &lighter);
2778 add_path_line (cr, x, yi, xi, y + height);
2785 else if (sides == GTK_JUNCTION_CORNER_BOTTOMRIGHT)
2792 while (xi < (x + width - 3))
2794 gdk_cairo_set_source_rgba (cr, &lighter);
2795 add_path_line (cr, xi, y + height, x + width, yi);
2801 gdk_cairo_set_source_rgba (cr, &darker);
2802 add_path_line (cr, xi, y + height, x + width, yi);
2808 add_path_line (cr, xi, y + height, x + width, yi);
2816 else if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_PANE_SEPARATOR))
2819 for (xx = x + width / 2 - 15; xx <= x + width / 2 + 15; xx += 5)
2820 render_dot (cr, &lighter, &darker, xx, y + height / 2 - 1, 3);
2822 for (yy = y + height / 2 - 15; yy <= y + height / 2 + 15; yy += 5)
2823 render_dot (cr, &lighter, &darker, x + width / 2 - 1, yy, 3);
2827 for (yy = y; yy < y + height; yy += 3)
2828 for (xx = x; xx < x + width; xx += 6)
2830 render_dot (cr, &lighter, &darker, xx, yy, 2);
2831 render_dot (cr, &lighter, &darker, xx + 3, yy + 1, 2);
2839 _gtk_theming_engine_paint_spinner (cairo_t *cr,
2844 guint num_steps, step;
2851 step = (guint) (progress * num_steps);
2857 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
2858 cairo_set_line_width (cr, 2.0);
2860 half = num_steps / 2;
2862 for (i = 0; i < num_steps; i++)
2864 gint inset = 0.7 * radius;
2866 /* transparency is a function of time and intial value */
2867 gdouble t = 1.0 - (gdouble) ((i + step) % num_steps) / num_steps;
2868 gdouble xscale = - sin (i * G_PI / half);
2869 gdouble yscale = - cos (i * G_PI / half);
2871 cairo_set_source_rgba (cr,
2878 (radius - inset) * xscale,
2879 (radius - inset) * yscale);
2891 render_spinner (GtkThemingEngine *engine,
2898 GtkStateFlags state;
2904 state = gtk_theming_engine_get_state (engine);
2906 if (!gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress))
2909 radius = MIN (width / 2, height / 2);
2911 gtk_theming_engine_get_color (engine, state, &color);
2912 gtk_theming_engine_get (engine, state,
2913 "icon-shadow", &shadow,
2917 cairo_translate (cr, x + width / 2, y + height / 2);
2921 _gtk_icon_shadow_paint_spinner (shadow, cr,
2924 _gtk_shadow_unref (shadow);
2927 _gtk_theming_engine_paint_spinner (cr,
2936 gtk_theming_engine_render_activity (GtkThemingEngine *engine,
2943 if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_SPINNER))
2945 render_spinner (engine, cr, x, y, width, height);
2949 gtk_theming_engine_render_background (engine, cr, x, y, width, height);
2950 gtk_theming_engine_render_frame (engine, cr, x, y, width, height);
2955 scale_or_ref (GdkPixbuf *src,
2959 if (width == gdk_pixbuf_get_width (src) &&
2960 height == gdk_pixbuf_get_height (src))
2961 return g_object_ref (src);
2963 return gdk_pixbuf_scale_simple (src,
2965 GDK_INTERP_BILINEAR);
2969 lookup_icon_size (GtkThemingEngine *engine,
2975 GtkSettings *settings;
2977 screen = gtk_theming_engine_get_screen (engine);
2978 settings = gtk_settings_get_for_screen (screen);
2980 return gtk_icon_size_lookup_for_settings (settings, size, width, height);
2984 colorshift_source (cairo_t *cr,
2987 cairo_pattern_t *source;
2992 source = cairo_pattern_reference (cairo_get_source (cr));
2994 cairo_set_source_rgb (cr, shift, shift, shift);
2995 cairo_set_operator (cr, CAIRO_OPERATOR_COLOR_DODGE);
2997 cairo_mask (cr, source);
2999 cairo_pattern_destroy (source);
3004 gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine *engine,
3005 const GtkIconSource *source,
3010 GdkPixbuf *base_pixbuf;
3011 GtkStateFlags state;
3015 cairo_surface_t *surface;
3017 base_pixbuf = gtk_icon_source_get_pixbuf (source);
3018 state = gtk_theming_engine_get_state (engine);
3020 g_return_val_if_fail (base_pixbuf != NULL, NULL);
3022 if (size != (GtkIconSize) -1 &&
3023 !lookup_icon_size (engine, size, &width, &height))
3025 g_warning (G_STRLOC ": invalid icon size '%d'", size);
3029 /* If the size was wildcarded, and we're allowed to scale, then scale; otherwise,
3032 if (size != (GtkIconSize) -1 &&
3033 gtk_icon_source_get_size_wildcarded (source))
3034 scaled = scale_or_ref (base_pixbuf, width, height);
3036 scaled = g_object_ref (base_pixbuf);
3038 /* If the state was wildcarded, then generate a state. */
3039 if (gtk_icon_source_get_state_wildcarded (source))
3041 if (state & GTK_STATE_FLAG_INSENSITIVE)
3043 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
3044 gdk_pixbuf_get_width (scaled),
3045 gdk_pixbuf_get_height (scaled));
3046 cr = cairo_create (surface);
3047 gdk_cairo_set_source_pixbuf (cr, scaled, 0, 0);
3048 cairo_paint_with_alpha (cr, 0.5);
3052 g_object_unref (scaled);
3053 stated = gdk_pixbuf_get_from_surface (surface, 0, 0,
3054 cairo_image_surface_get_width (surface),
3055 cairo_image_surface_get_height (surface));
3056 cairo_surface_destroy (surface);
3058 else if (state & GTK_STATE_FLAG_PRELIGHT)
3060 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
3061 gdk_pixbuf_get_width (scaled),
3062 gdk_pixbuf_get_height (scaled));
3064 cr = cairo_create (surface);
3065 gdk_cairo_set_source_pixbuf (cr, scaled, 0, 0);
3066 colorshift_source (cr, 0.10);
3070 g_object_unref (scaled);
3071 stated = gdk_pixbuf_get_from_surface (surface, 0, 0,
3072 cairo_image_surface_get_width (surface),
3073 cairo_image_surface_get_height (surface));
3074 cairo_surface_destroy (surface);
3086 gtk_theming_engine_render_icon (GtkThemingEngine *engine,
3092 GtkStateFlags state;
3093 GtkShadow *icon_shadow;
3095 state = gtk_theming_engine_get_state (engine);
3099 gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
3101 gtk_theming_engine_get (engine, state,
3102 "icon-shadow", &icon_shadow,
3105 if (icon_shadow != NULL)
3107 _gtk_icon_shadow_paint (icon_shadow, cr);
3108 _gtk_shadow_unref (icon_shadow);