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 "gtk9slice.h"
34 * SECTION:gtkthemingengine
35 * @Short_description: Theming renderers
36 * @Title: GtkThemingEngine
37 * @See_also: #GtkStyleContext
39 * #GtkThemingEngine is the object used for rendering themed content
40 * in GTK+ widgets. Even though GTK+ has a default implementation,
41 * it can be overridden in CSS files by enforcing a #GtkThemingEngine
42 * object to be loaded as a module.
44 * In order to implement a theming engine, a #GtkThemingEngine subclass
45 * must be created, alongside the CSS file that will reference it, the
46 * theming engine would be created as an .so library, and installed in
47 * $(gtk-modules-dir)/theming-engines/.
49 * #GtkThemingEngine<!-- -->s have limited access to the object they are
50 * rendering, the #GtkThemingEngine API has read-only accessors to the
51 * style information contained in the rendered object's #GtkStyleContext.
54 typedef struct GtkThemingEnginePrivate GtkThemingEnginePrivate;
69 struct GtkThemingEnginePrivate
71 GtkStyleContext *context;
75 #define GTK_THEMING_ENGINE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_THEMING_ENGINE, GtkThemingEnginePrivate))
77 static void gtk_theming_engine_finalize (GObject *object);
78 static void gtk_theming_engine_impl_set_property (GObject *object,
82 static void gtk_theming_engine_impl_get_property (GObject *object,
87 static void gtk_theming_engine_render_check (GtkThemingEngine *engine,
93 static void gtk_theming_engine_render_option (GtkThemingEngine *engine,
99 static void gtk_theming_engine_render_arrow (GtkThemingEngine *engine,
105 static void gtk_theming_engine_render_background (GtkThemingEngine *engine,
111 static void gtk_theming_engine_render_frame (GtkThemingEngine *engine,
117 static void gtk_theming_engine_render_expander (GtkThemingEngine *engine,
123 static void gtk_theming_engine_render_focus (GtkThemingEngine *engine,
129 static void gtk_theming_engine_render_layout (GtkThemingEngine *engine,
133 PangoLayout *layout);
134 static void gtk_theming_engine_render_line (GtkThemingEngine *engine,
140 static void gtk_theming_engine_render_slider (GtkThemingEngine *engine,
146 GtkOrientation orientation);
147 static void gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
153 GtkPositionType gap_side,
156 static void gtk_theming_engine_render_extension (GtkThemingEngine *engine,
162 GtkPositionType gap_side);
163 static void gtk_theming_engine_render_handle (GtkThemingEngine *engine,
169 static void gtk_theming_engine_render_activity (GtkThemingEngine *engine,
175 static GdkPixbuf * gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine *engine,
176 const GtkIconSource *source,
179 G_DEFINE_TYPE (GtkThemingEngine, gtk_theming_engine, G_TYPE_OBJECT)
182 typedef struct GtkThemingModule GtkThemingModule;
183 typedef struct GtkThemingModuleClass GtkThemingModuleClass;
185 struct GtkThemingModule
187 GTypeModule parent_instance;
191 void (*init) (GTypeModule *module);
193 GtkThemingEngine * (*create_engine) (void);
196 struct GtkThemingModuleClass
198 GTypeModuleClass parent_class;
201 #define GTK_TYPE_THEMING_MODULE (gtk_theming_module_get_type ())
202 #define GTK_THEMING_MODULE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_THEMING_MODULE, GtkThemingModule))
203 #define GTK_IS_THEMING_MODULE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_THEMING_MODULE))
205 G_DEFINE_TYPE (GtkThemingModule, gtk_theming_module, G_TYPE_TYPE_MODULE);
208 gtk_theming_engine_class_init (GtkThemingEngineClass *klass)
210 GObjectClass *object_class = G_OBJECT_CLASS (klass);
212 object_class->finalize = gtk_theming_engine_finalize;
213 object_class->set_property = gtk_theming_engine_impl_set_property;
214 object_class->get_property = gtk_theming_engine_impl_get_property;
216 klass->render_check = gtk_theming_engine_render_check;
217 klass->render_option = gtk_theming_engine_render_option;
218 klass->render_arrow = gtk_theming_engine_render_arrow;
219 klass->render_background = gtk_theming_engine_render_background;
220 klass->render_frame = gtk_theming_engine_render_frame;
221 klass->render_expander = gtk_theming_engine_render_expander;
222 klass->render_focus = gtk_theming_engine_render_focus;
223 klass->render_layout = gtk_theming_engine_render_layout;
224 klass->render_line = gtk_theming_engine_render_line;
225 klass->render_slider = gtk_theming_engine_render_slider;
226 klass->render_frame_gap = gtk_theming_engine_render_frame_gap;
227 klass->render_extension = gtk_theming_engine_render_extension;
228 klass->render_handle = gtk_theming_engine_render_handle;
229 klass->render_activity = gtk_theming_engine_render_activity;
230 klass->render_icon_pixbuf = gtk_theming_engine_render_icon_pixbuf;
233 * GtkThemingEngine:name:
235 * The theming engine name, this name will be used when registering
236 * custom properties, for a theming engine named "Clearlooks" registering
237 * a "glossy" custom property, it could be referenced in the CSS file as
240 * -Clearlooks-glossy: true;
245 g_object_class_install_property (object_class,
247 g_param_spec_string ("name",
249 P_("Theming engine name"),
251 G_PARAM_CONSTRUCT_ONLY | GTK_PARAM_READWRITE));
253 g_type_class_add_private (object_class, sizeof (GtkThemingEnginePrivate));
257 gtk_theming_engine_init (GtkThemingEngine *engine)
259 engine->priv = GTK_THEMING_ENGINE_GET_PRIVATE (engine);
263 gtk_theming_engine_finalize (GObject *object)
265 GtkThemingEnginePrivate *priv;
267 priv = GTK_THEMING_ENGINE (object)->priv;
270 G_OBJECT_GET_CLASS (gtk_theming_engine_parent_class)->finalize (object);
274 gtk_theming_engine_impl_set_property (GObject *object,
279 GtkThemingEnginePrivate *priv;
281 priv = GTK_THEMING_ENGINE (object)->priv;
289 priv->name = g_value_dup_string (value);
292 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
298 gtk_theming_engine_impl_get_property (GObject *object,
303 GtkThemingEnginePrivate *priv;
305 priv = GTK_THEMING_ENGINE (object)->priv;
310 g_value_set_string (value, priv->name);
313 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
319 _gtk_theming_engine_set_context (GtkThemingEngine *engine,
320 GtkStyleContext *context)
322 GtkThemingEnginePrivate *priv;
324 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
325 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
328 priv->context = context;
332 * gtk_theming_engine_register_property: (skip)
333 * @name_space: namespace for the property name
334 * @parse_func: parsing function to use, or %NULL
335 * @pspec: the #GParamSpec for the new property
337 * Registers a property so it can be used in the CSS file format,
338 * on the CSS file the property will look like
339 * "-${@name_space}-${property_name}". being
340 * ${property_name} the given to @pspec. @name_space will usually
341 * be the theme engine name.
343 * For any type a @parse_func may be provided, being this function
344 * used for turning any property value (between ':' and ';') in
345 * CSS to the #GValue needed. For basic types there is already
346 * builtin parsing support, so %NULL may be provided for these
350 * Engines must ensure property registration happens exactly once,
351 * usually GTK+ deals with theming engines as singletons, so this
352 * should be guaranteed to happen once, but bear this in mind
353 * when creating #GtkThemeEngine<!-- -->s yourself.
357 * In order to make use of the custom registered properties in
358 * the CSS file, make sure the engine is loaded first by specifying
359 * the engine property, either in a previous rule or within the same
363 * engine: someengine;
364 * -SomeEngine-custom-property: 2;
372 gtk_theming_engine_register_property (const gchar *name_space,
373 GtkStylePropertyParser parse_func,
378 g_return_if_fail (name_space != NULL);
379 g_return_if_fail (strchr (name_space, ' ') == NULL);
380 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
382 /* FIXME: hack hack hack, replacing pspec->name to include namespace */
383 name = g_strdup_printf ("-%s-%s", name_space, pspec->name);
384 g_free (pspec->name);
387 gtk_style_properties_register_property (parse_func, pspec);
391 * gtk_theming_engine_get_property:
392 * @engine: a #GtkThemingEngine
393 * @property: the property name
394 * @state: state to retrieve the value for
395 * @value: (out) (transfer full): return location for the property value,
396 * you must free this memory using g_value_unset() once you are
399 * Gets a property value as retrieved from the style settings that apply
400 * to the currently rendered element.
405 gtk_theming_engine_get_property (GtkThemingEngine *engine,
406 const gchar *property,
410 GtkThemingEnginePrivate *priv;
412 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
413 g_return_if_fail (property != NULL);
414 g_return_if_fail (value != NULL);
417 gtk_style_context_get_property (priv->context, property, state, value);
421 * gtk_theming_engine_get_valist:
422 * @engine: a #GtkThemingEngine
423 * @state: state to retrieve values for
424 * @args: va_list of property name/return location pairs, followed by %NULL
426 * Retrieves several style property values that apply to the currently
432 gtk_theming_engine_get_valist (GtkThemingEngine *engine,
436 GtkThemingEnginePrivate *priv;
438 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
441 gtk_style_context_get_valist (priv->context, state, args);
445 * gtk_theming_engine_get:
446 * @engine: a #GtkThemingEngine
447 * @state: state to retrieve values for
448 * @...: property name /return value pairs, followed by %NULL
450 * Retrieves several style property values that apply to the currently
456 gtk_theming_engine_get (GtkThemingEngine *engine,
460 GtkThemingEnginePrivate *priv;
463 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
467 va_start (args, state);
468 gtk_style_context_get_valist (priv->context, state, args);
473 * gtk_theming_engine_get_style_property:
474 * @engine: a #GtkThemingEngine
475 * @property_name: the name of the widget style property
476 * @value: Return location for the property value, free with
477 * g_value_unset() after use.
479 * Gets the value for a widget style property.
484 gtk_theming_engine_get_style_property (GtkThemingEngine *engine,
485 const gchar *property_name,
488 GtkThemingEnginePrivate *priv;
490 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
491 g_return_if_fail (property_name != NULL);
494 gtk_style_context_get_style_property (priv->context, property_name, value);
498 * gtk_theming_engine_get_style_valist:
499 * @engine: a #GtkThemingEngine
500 * @args: va_list of property name/return location pairs, followed by %NULL
502 * Retrieves several widget style properties from @engine according to the
503 * currently rendered content's style.
508 gtk_theming_engine_get_style_valist (GtkThemingEngine *engine,
511 GtkThemingEnginePrivate *priv;
513 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
516 gtk_style_context_get_style_valist (priv->context, args);
520 * gtk_theming_engine_get_style:
521 * @engine: a #GtkThemingEngine
522 * @...: property name /return value pairs, followed by %NULL
524 * Retrieves several widget style properties from @engine according
525 * to the currently rendered content's style.
530 gtk_theming_engine_get_style (GtkThemingEngine *engine,
533 GtkThemingEnginePrivate *priv;
536 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
540 va_start (args, engine);
541 gtk_style_context_get_style_valist (priv->context, args);
546 * gtk_theming_engine_lookup_color:
547 * @engine: a #GtkThemingEngine
548 * @color_name: color name to lookup
549 * @color: (out): Return location for the looked up color
551 * Looks up and resolves a color name in the current style's color map.
553 * Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
556 gtk_theming_engine_lookup_color (GtkThemingEngine *engine,
557 const gchar *color_name,
560 GtkThemingEnginePrivate *priv;
562 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
563 g_return_val_if_fail (color_name != NULL, FALSE);
566 return gtk_style_context_lookup_color (priv->context, color_name, color);
570 * gtk_theming_engine_get_state:
571 * @engine: a #GtkThemingEngine
573 * returns the state used when rendering.
575 * Returns: the state flags
580 gtk_theming_engine_get_state (GtkThemingEngine *engine)
582 GtkThemingEnginePrivate *priv;
584 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), 0);
587 return gtk_style_context_get_state (priv->context);
591 * gtk_theming_engine_state_is_running:
592 * @engine: a #GtkThemingEngine
593 * @state: a widget state
594 * @progress: (out): return location for the transition progress
596 * Returns %TRUE if there is a transition animation running for the
597 * current region (see gtk_style_context_push_animatable_region()).
599 * If @progress is not %NULL, the animation progress will be returned
600 * there, 0.0 means the state is closest to being %FALSE, while 1.0 means
601 * it's closest to being %TRUE. This means transition animations will
602 * run from 0 to 1 when @state is being set to %TRUE and from 1 to 0 when
603 * it's being set to %FALSE.
605 * Returns: %TRUE if there is a running transition animation for @state.
610 gtk_theming_engine_state_is_running (GtkThemingEngine *engine,
614 GtkThemingEnginePrivate *priv;
616 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
619 return gtk_style_context_state_is_running (priv->context, state, progress);
623 * gtk_theming_engine_get_path:
624 * @engine: a #GtkThemingEngine
626 * Returns the widget path used for style matching.
628 * Returns: (transfer none): A #GtkWidgetPath
632 G_CONST_RETURN GtkWidgetPath *
633 gtk_theming_engine_get_path (GtkThemingEngine *engine)
635 GtkThemingEnginePrivate *priv;
637 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
640 return gtk_style_context_get_path (priv->context);
644 * gtk_theming_engine_has_class:
645 * @engine: a #GtkThemingEngine
646 * @style_class: class name to look up
648 * Returns %TRUE if the currently rendered contents have
649 * defined the given class name.
651 * Returns: %TRUE if @engine has @class_name defined
656 gtk_theming_engine_has_class (GtkThemingEngine *engine,
657 const gchar *style_class)
659 GtkThemingEnginePrivate *priv;
661 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
664 return gtk_style_context_has_class (priv->context, style_class);
668 * gtk_theming_engine_has_region:
669 * @engine: a #GtkThemingEngine
670 * @style_region: a region name
671 * @flags: (out) (allow-none): return location for region flags
673 * Returns %TRUE if the currently rendered contents have the
674 * region defined. If @flags_return is not %NULL, it is set
675 * to the flags affecting the region.
677 * Returns: %TRUE if region is defined
682 gtk_theming_engine_has_region (GtkThemingEngine *engine,
683 const gchar *style_region,
684 GtkRegionFlags *flags)
686 GtkThemingEnginePrivate *priv;
691 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
694 return gtk_style_context_has_region (priv->context, style_region, flags);
698 * gtk_theming_engine_get_direction:
699 * @engine: a #GtkThemingEngine
701 * Returns the widget direction used for rendering.
703 * Returns: the widget direction
708 gtk_theming_engine_get_direction (GtkThemingEngine *engine)
710 GtkThemingEnginePrivate *priv;
712 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), GTK_TEXT_DIR_LTR);
715 return gtk_style_context_get_direction (priv->context);
719 * gtk_theming_engine_get_junction_sides:
720 * @engine: a #GtkThemingEngine
722 * Returns the widget direction used for rendering.
724 * Returns: the widget direction
729 gtk_theming_engine_get_junction_sides (GtkThemingEngine *engine)
731 GtkThemingEnginePrivate *priv;
733 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), 0);
736 return gtk_style_context_get_junction_sides (priv->context);
740 * gtk_theming_engine_get_color:
741 * @engine: a #GtkThemingEngine
742 * @state: state to retrieve the color for
743 * @color: (out): return value for the foreground color
745 * Gets the foreground color for a given state.
750 gtk_theming_engine_get_color (GtkThemingEngine *engine,
754 GtkThemingEnginePrivate *priv;
756 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
759 gtk_style_context_get_color (priv->context, state, color);
763 * gtk_theming_engine_get_background_color:
764 * @engine: a #GtkThemingEngine
765 * @state: state to retrieve the color for
766 * @color: (out): return value for the background color
768 * Gets the background color for a given state.
773 gtk_theming_engine_get_background_color (GtkThemingEngine *engine,
777 GtkThemingEnginePrivate *priv;
779 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
782 gtk_style_context_get_background_color (priv->context, state, color);
786 * gtk_theming_engine_get_border_color:
787 * @engine: a #GtkThemingEngine
788 * @state: state to retrieve the color for
789 * @color: (out): return value for the border color
791 * Gets the border color for a given state.
796 gtk_theming_engine_get_border_color (GtkThemingEngine *engine,
800 GtkThemingEnginePrivate *priv;
802 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
805 gtk_style_context_get_border_color (priv->context, state, color);
809 * gtk_theming_engine_get_border:
810 * @engine: a #GtkthemingEngine
811 * @state: state to retrieve the border for
812 * @border: (out): return value for the border settings
814 * Gets the border for a given state as a #GtkBorder.
819 gtk_theming_engine_get_border (GtkThemingEngine *engine,
823 GtkThemingEnginePrivate *priv;
825 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
828 gtk_style_context_get_border (priv->context, state, border);
832 * gtk_theming_engine_get_padding:
833 * @engine: a #GtkthemingEngine
834 * @state: state to retrieve the padding for
835 * @padding: (out): return value for the padding settings
837 * Gets the padding for a given state as a #GtkBorder.
842 gtk_theming_engine_get_padding (GtkThemingEngine *engine,
846 GtkThemingEnginePrivate *priv;
848 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
851 gtk_style_context_get_padding (priv->context, state, padding);
855 * gtk_theming_engine_get_margin:
856 * @engine: a #GtkThemingEngine
857 * @state: state to retrieve the border for
858 * @margin: (out): return value for the margin settings
860 * Gets the margin for a given state as a #GtkBorder.
865 gtk_theming_engine_get_margin (GtkThemingEngine *engine,
869 GtkThemingEnginePrivate *priv;
871 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
874 gtk_style_context_get_margin (priv->context, state, margin);
878 * gtk_theming_engine_get_font:
879 * @engine: a #GtkThemingEngine
880 * @state: state to retrieve the font for
882 * Returns the font description for a given state.
884 * Returns: (transfer none): the #PangoFontDescription for the given
885 * state. This object is owned by GTK+ and should not be
890 const PangoFontDescription *
891 gtk_theming_engine_get_font (GtkThemingEngine *engine,
894 GtkThemingEnginePrivate *priv;
896 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
899 return gtk_style_context_get_font (priv->context, state);
902 /* GtkThemingModule */
905 gtk_theming_module_load (GTypeModule *type_module)
907 GtkThemingModule *theming_module;
909 gchar *name, *module_path;
911 theming_module = GTK_THEMING_MODULE (type_module);
912 name = theming_module->name;
913 module_path = _gtk_find_module (name, "theming-engines");
918 module = g_module_open (module_path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
919 g_free (module_path);
924 if (!g_module_symbol (module, "theme_init",
925 (gpointer *) &theming_module->init) ||
926 !g_module_symbol (module, "theme_exit",
927 (gpointer *) &theming_module->exit) ||
928 !g_module_symbol (module, "create_engine",
929 (gpointer *) &theming_module->create_engine))
931 g_module_close (module);
936 theming_module->module = module;
938 theming_module->init (G_TYPE_MODULE (theming_module));
944 gtk_theming_module_unload (GTypeModule *type_module)
946 GtkThemingModule *theming_module;
948 theming_module = GTK_THEMING_MODULE (type_module);
950 theming_module->exit ();
952 g_module_close (theming_module->module);
954 theming_module->module = NULL;
955 theming_module->init = NULL;
956 theming_module->exit = NULL;
957 theming_module->create_engine = NULL;
961 gtk_theming_module_class_init (GtkThemingModuleClass *klass)
963 GTypeModuleClass *module_class = G_TYPE_MODULE_CLASS (klass);
965 module_class->load = gtk_theming_module_load;
966 module_class->unload = gtk_theming_module_unload;
970 gtk_theming_module_init (GtkThemingModule *module)
975 * gtk_theming_engine_load:
976 * @name: Theme engine name to load
978 * Loads and initializes a theming engine module from the
979 * standard directories.
981 * Returns: (transfer none): A theming engine, or %NULL if
982 * the engine @name doesn't exist.
985 gtk_theming_engine_load (const gchar *name)
987 static GHashTable *engines = NULL;
988 static GtkThemingEngine *default_engine;
989 GtkThemingEngine *engine = NULL;
994 engines = g_hash_table_new (g_str_hash, g_str_equal);
996 engine = g_hash_table_lookup (engines, name);
1000 GtkThemingModule *module;
1002 module = g_object_new (GTK_TYPE_THEMING_MODULE, NULL);
1003 g_type_module_set_name (G_TYPE_MODULE (module), name);
1004 module->name = g_strdup (name);
1006 if (module && g_type_module_use (G_TYPE_MODULE (module)))
1008 engine = (module->create_engine) ();
1011 g_hash_table_insert (engines, module->name, engine);
1018 if (G_UNLIKELY (!default_engine))
1019 default_engine = g_object_new (GTK_TYPE_THEMING_ENGINE, NULL);
1021 engine = default_engine;
1028 * gtk_theming_engine_get_screen:
1029 * @engine: a #GtkThemingEngine
1031 * Returns the #GdkScreen to which @engine currently rendering to.
1033 * Returns: (transfer none): a #GdkScreen, or %NULL.
1036 gtk_theming_engine_get_screen (GtkThemingEngine *engine)
1038 GtkThemingEnginePrivate *priv;
1040 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
1042 priv = engine->priv;
1043 return gtk_style_context_get_screen (priv->context);
1046 /* Paint method implementations */
1048 gtk_theming_engine_render_check (GtkThemingEngine *engine,
1055 GdkRGBA *fg_color, *bg_color, *border_color;
1056 GtkStateFlags flags;
1057 gint exterior_size, interior_size, thickness, pad;
1058 GtkBorderStyle border_style;
1062 flags = gtk_theming_engine_get_state (engine);
1065 gtk_theming_engine_get (engine, flags,
1067 "background-color", &bg_color,
1068 "border-color", &border_color,
1069 "border-style", &border_style,
1070 "border-width", &border,
1073 border_width = MIN (MIN (border->top, border->bottom),
1074 MIN (border->left, border->right));
1075 exterior_size = MIN (width, height);
1077 if (exterior_size % 2 == 0) /* Ensure odd */
1080 /* FIXME: thickness */
1082 pad = thickness + MAX (1, (exterior_size - 2 * thickness) / 9);
1083 interior_size = MAX (1, exterior_size - 2 * pad);
1085 if (interior_size < 7)
1088 pad = MAX (0, (exterior_size - interior_size) / 2);
1091 x -= (1 + exterior_size - (gint) width) / 2;
1092 y -= (1 + exterior_size - (gint) height) / 2;
1094 if (border_style == GTK_BORDER_STYLE_SOLID)
1096 cairo_set_line_width (cr, border_width);
1098 cairo_rectangle (cr, x + 0.5, y + 0.5, exterior_size - 1, exterior_size - 1);
1099 gdk_cairo_set_source_rgba (cr, bg_color);
1100 cairo_fill_preserve (cr);
1103 gdk_cairo_set_source_rgba (cr, border_color);
1105 gdk_cairo_set_source_rgba (cr, fg_color);
1110 gdk_cairo_set_source_rgba (cr, fg_color);
1112 if (flags & GTK_STATE_FLAG_INCONSISTENT)
1114 int line_thickness = MAX (1, (3 + interior_size * 2) / 7);
1116 cairo_rectangle (cr,
1118 y + pad + (1 + interior_size - line_thickness) / 2,
1128 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress);
1130 if ((flags & GTK_STATE_FLAG_ACTIVE) || running)
1135 cairo_translate (cr,
1138 cairo_scale (cr, interior_size / 7., interior_size / 7.);
1140 cairo_rectangle (cr, 0, 0, 7 * progress, 7);
1143 cairo_move_to (cr, 7.0, 0.0);
1144 cairo_line_to (cr, 7.5, 1.0);
1145 cairo_curve_to (cr, 5.3, 2.0,
1148 cairo_curve_to (cr, 3.0, 5.7,
1151 cairo_line_to (cr, 0.2, 3.5);
1152 cairo_curve_to (cr, 1.1, 3.5,
1155 cairo_curve_to (cr, 1.0, 3.9,
1158 cairo_curve_to (cr, 3.5, 3.1,
1168 gdk_rgba_free (fg_color);
1169 gdk_rgba_free (bg_color);
1170 gdk_rgba_free (border_color);
1171 gtk_border_free (border);
1175 gtk_theming_engine_render_option (GtkThemingEngine *engine,
1182 GtkStateFlags flags;
1183 GdkRGBA *fg_color, *bg_color, *border_color;
1184 gint exterior_size, interior_size, pad, thickness, border_width;
1185 GtkBorderStyle border_style;
1188 flags = gtk_theming_engine_get_state (engine);
1192 gtk_theming_engine_get (engine, flags,
1194 "background-color", &bg_color,
1195 "border-color", &border_color,
1196 "border-style", &border_style,
1197 "border-width", &border,
1200 exterior_size = MIN (width, height);
1201 border_width = MIN (MIN (border->top, border->bottom),
1202 MIN (border->left, border->right));
1204 if (exterior_size % 2 == 0) /* Ensure odd */
1207 x -= (1 + exterior_size - width) / 2;
1208 y -= (1 + exterior_size - height) / 2;
1210 if (border_style == GTK_BORDER_STYLE_SOLID)
1212 cairo_set_line_width (cr, border_width);
1214 cairo_new_sub_path (cr);
1216 x + exterior_size / 2.,
1217 y + exterior_size / 2.,
1218 (exterior_size - 1) / 2.,
1221 gdk_cairo_set_source_rgba (cr, bg_color);
1222 cairo_fill_preserve (cr);
1225 gdk_cairo_set_source_rgba (cr, border_color);
1227 gdk_cairo_set_source_rgba (cr, fg_color);
1232 gdk_cairo_set_source_rgba (cr, fg_color);
1234 /* FIXME: thickness */
1237 if (flags & GTK_STATE_FLAG_INCONSISTENT)
1239 gint line_thickness;
1241 pad = thickness + MAX (1, (exterior_size - 2 * thickness) / 9);
1242 interior_size = MAX (1, exterior_size - 2 * pad);
1244 if (interior_size < 7)
1247 pad = MAX (0, (exterior_size - interior_size) / 2);
1250 line_thickness = MAX (1, (3 + interior_size * 2) / 7);
1252 cairo_rectangle (cr,
1254 y + pad + (interior_size - line_thickness) / 2.,
1259 if (flags & GTK_STATE_FLAG_ACTIVE)
1261 pad = thickness + MAX (1, 2 * (exterior_size - 2 * thickness) / 9);
1262 interior_size = MAX (1, exterior_size - 2 * pad);
1264 if (interior_size < 5)
1267 pad = MAX (0, (exterior_size - interior_size) / 2);
1270 cairo_new_sub_path (cr);
1272 x + pad + interior_size / 2.,
1273 y + pad + interior_size / 2.,
1281 gdk_rgba_free (fg_color);
1282 gdk_rgba_free (bg_color);
1283 gdk_rgba_free (border_color);
1284 gtk_border_free (border);
1288 add_path_arrow (cairo_t *cr,
1296 cairo_translate (cr, x + (size / 2), y + (size / 2));
1297 cairo_rotate (cr, angle);
1299 cairo_move_to (cr, 0, - (size / 4));
1300 cairo_line_to (cr, - (size / 2), (size / 4));
1301 cairo_line_to (cr, (size / 2), (size / 4));
1302 cairo_close_path (cr);
1308 gtk_theming_engine_render_arrow (GtkThemingEngine *engine,
1315 GtkStateFlags flags;
1320 flags = gtk_theming_engine_get_state (engine);
1322 gtk_theming_engine_get (engine, flags,
1326 if (flags & GTK_STATE_FLAG_INSENSITIVE)
1328 add_path_arrow (cr, angle, x + 1, y + 1, size);
1329 cairo_set_source_rgb (cr, 1, 1, 1);
1333 add_path_arrow (cr, angle, x, y, size);
1334 gdk_cairo_set_source_rgba (cr, fg_color);
1339 gdk_rgba_free (fg_color);
1343 add_path_line (cairo_t *cr,
1349 /* Adjust endpoints */
1363 cairo_move_to (cr, x1, y1);
1364 cairo_line_to (cr, x2, y2);
1368 color_shade (const GdkRGBA *color,
1370 GdkRGBA *color_return)
1372 GtkSymbolicColor *literal, *shade;
1374 literal = gtk_symbolic_color_new_literal (color);
1375 shade = gtk_symbolic_color_new_shade (literal, factor);
1376 gtk_symbolic_color_unref (literal);
1378 gtk_symbolic_color_resolve (shade, NULL, color_return);
1379 gtk_symbolic_color_unref (shade);
1383 _cairo_round_rectangle_sides (cairo_t *cr,
1390 GtkJunctionSides junction)
1392 radius = CLAMP (radius, 0, MIN (width / 2, height / 2));
1394 if (sides & SIDE_RIGHT)
1397 (junction & GTK_JUNCTION_CORNER_TOPRIGHT))
1398 cairo_move_to (cr, x + width, y);
1401 cairo_new_sub_path (cr);
1402 cairo_arc (cr, x + width - radius, y + radius, radius, - G_PI / 4, 0);
1406 (junction & GTK_JUNCTION_CORNER_BOTTOMRIGHT))
1407 cairo_line_to (cr, x + width, y + height);
1409 cairo_arc (cr, x + width - radius, y + height - radius, radius, 0, G_PI / 4);
1412 if (sides & SIDE_BOTTOM)
1415 ! (junction & GTK_JUNCTION_CORNER_BOTTOMRIGHT))
1417 if ((sides & SIDE_RIGHT) == 0)
1418 cairo_new_sub_path (cr);
1420 cairo_arc (cr, x + width - radius, y + height - radius, radius, G_PI / 4, G_PI / 2);
1422 else if ((sides & SIDE_RIGHT) == 0)
1423 cairo_move_to (cr, x + width, y + height);
1426 (junction & GTK_JUNCTION_CORNER_BOTTOMLEFT))
1427 cairo_line_to (cr, x, y + height);
1429 cairo_arc (cr, x + radius, y + height - radius, radius, G_PI / 2, 3 * (G_PI / 4));
1432 cairo_move_to (cr, x, y + height);
1434 if (sides & SIDE_LEFT)
1437 ! (junction & GTK_JUNCTION_CORNER_BOTTOMLEFT))
1439 if ((sides & SIDE_BOTTOM) == 0)
1440 cairo_new_sub_path (cr);
1442 cairo_arc (cr, x + radius, y + height - radius, radius, 3 * (G_PI / 4), G_PI);
1444 else if ((sides & SIDE_BOTTOM) == 0)
1445 cairo_move_to (cr, x, y + height);
1448 (junction & GTK_JUNCTION_CORNER_TOPLEFT))
1449 cairo_line_to (cr, x, y);
1451 cairo_arc (cr, x + radius, y + radius, radius, G_PI, G_PI + G_PI / 4);
1454 if (sides & SIDE_TOP)
1457 ! (junction & GTK_JUNCTION_CORNER_TOPLEFT))
1459 if ((sides & SIDE_LEFT) == 0)
1460 cairo_new_sub_path (cr);
1462 cairo_arc (cr, x + radius, y + radius, radius, 5 * (G_PI / 4), 3 * (G_PI / 2));
1464 else if ((sides & SIDE_LEFT) == 0)
1465 cairo_move_to (cr, x, y);
1468 (junction & GTK_JUNCTION_CORNER_TOPRIGHT))
1469 cairo_line_to (cr, x + width, y);
1471 cairo_arc (cr, x + width - radius, y + radius, radius, 3 * (G_PI / 2), - G_PI / 4);
1476 render_background_internal (GtkThemingEngine *engine,
1482 GtkJunctionSides junction)
1485 cairo_pattern_t *pattern;
1486 GtkStateFlags flags;
1488 gdouble progress, alpha = 1;
1491 flags = gtk_theming_engine_get_state (engine);
1494 gtk_theming_engine_get (engine, flags,
1495 "background-image", &pattern,
1496 "background-color", &bg_color,
1497 "border-radius", &radius,
1500 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
1501 _cairo_round_rectangle_sides (cr, (gdouble) radius,
1502 x, y, width, height,
1503 SIDE_ALL, junction);
1506 if (gtk_theming_engine_has_class (engine, "background"))
1508 cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0); /* transparent */
1509 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
1513 cairo_translate (cr, x, y);
1514 cairo_scale (cr, width, height);
1518 cairo_pattern_t *other_pattern;
1519 GtkStateFlags other_flags;
1521 cairo_pattern_t *new_pattern = NULL;
1523 if (flags & GTK_STATE_FLAG_PRELIGHT)
1525 other_flags = flags & ~(GTK_STATE_FLAG_PRELIGHT);
1526 progress = 1 - progress;
1529 other_flags = flags | GTK_STATE_FLAG_PRELIGHT;
1531 gtk_theming_engine_get (engine, other_flags,
1532 "background-image", &other_pattern,
1533 "background-color", &other_bg,
1536 if (pattern && other_pattern)
1538 cairo_pattern_type_t type, other_type;
1541 cairo_pattern_get_color_stop_count (pattern, &n0);
1542 cairo_pattern_get_color_stop_count (other_pattern, &n1);
1543 type = cairo_pattern_get_type (pattern);
1544 other_type = cairo_pattern_get_type (other_pattern);
1546 if (type == other_type && n0 == n1)
1548 gdouble offset0, red0, green0, blue0, alpha0;
1549 gdouble offset1, red1, green1, blue1, alpha1;
1550 gdouble x00, x01, y00, y01, x10, x11, y10, y11;
1551 gdouble r00, r01, r10, r11;
1554 if (type == CAIRO_PATTERN_TYPE_LINEAR)
1556 cairo_pattern_get_linear_points (pattern, &x00, &y00, &x01, &y01);
1557 cairo_pattern_get_linear_points (other_pattern, &x10, &y10, &x11, &y11);
1559 new_pattern = cairo_pattern_create_linear (x00 + (x10 - x00) * progress,
1560 y00 + (y10 - y00) * progress,
1561 x01 + (x11 - x01) * progress,
1562 y01 + (y11 - y01) * progress);
1566 cairo_pattern_get_radial_circles (pattern, &x00, &y00, &r00, &x01, &y01, &r01);
1567 cairo_pattern_get_radial_circles (other_pattern, &x10, &y10, &r10, &x11, &y11, &r11);
1569 new_pattern = cairo_pattern_create_radial (x00 + (x10 - x00) * progress,
1570 y00 + (y10 - y00) * progress,
1571 r00 + (r10 - r00) * progress,
1572 x01 + (x11 - x01) * progress,
1573 y01 + (y11 - y01) * progress,
1574 r01 + (r11 - r01) * progress);
1577 cairo_pattern_set_filter (new_pattern, CAIRO_FILTER_FAST);
1580 /* Blend both gradients into one */
1581 while (i < n0 && i < n1)
1583 cairo_pattern_get_color_stop_rgba (pattern, i,
1585 &red0, &green0, &blue0,
1587 cairo_pattern_get_color_stop_rgba (other_pattern, i,
1589 &red1, &green1, &blue1,
1592 cairo_pattern_add_color_stop_rgba (new_pattern,
1593 offset0 + ((offset1 - offset0) * progress),
1594 red0 + ((red1 - red0) * progress),
1595 green0 + ((green1 - green0) * progress),
1596 blue0 + ((blue1 - blue0) * progress),
1597 alpha0 + ((alpha1 - alpha0) * progress));
1603 /* Different pattern types, or different color
1604 * stop counts, alpha blend both patterns.
1606 cairo_rectangle (cr, 0, 0, 1, 1);
1607 cairo_set_source (cr, other_pattern);
1608 cairo_fill_preserve (cr);
1610 /* Set alpha for posterior drawing
1611 * of the target pattern
1613 alpha = 1 - progress;
1616 else if (pattern || other_pattern)
1620 gdouble x0, y0, x1, y1, r0, r1;
1623 /* Blend a pattern with a color */
1628 progress = 1 - progress;
1636 if (cairo_pattern_get_type (p) == CAIRO_PATTERN_TYPE_LINEAR)
1638 cairo_pattern_get_linear_points (p, &x0, &y0, &x1, &y1);
1639 new_pattern = cairo_pattern_create_linear (x0, y0, x1, y1);
1643 cairo_pattern_get_radial_circles (p, &x0, &y0, &r0, &x1, &y1, &r1);
1644 new_pattern = cairo_pattern_create_radial (x0, y0, r0, x1, y1, r1);
1647 cairo_pattern_get_color_stop_count (p, &n);
1649 for (i = 0; i < n; i++)
1651 gdouble red1, green1, blue1, alpha1;
1654 cairo_pattern_get_color_stop_rgba (p, i,
1656 &red1, &green1, &blue1,
1658 cairo_pattern_add_color_stop_rgba (new_pattern, offset,
1659 c->red + ((red1 - c->red) * progress),
1660 c->green + ((green1 - c->green) * progress),
1661 c->blue + ((blue1 - c->blue) * progress),
1662 c->alpha + ((alpha1 - c->alpha) * progress));
1667 const GdkRGBA *color, *other_color;
1669 /* Merge just colors */
1671 other_color = other_bg;
1673 new_pattern = cairo_pattern_create_rgba (CLAMP (color->red + ((other_color->red - color->red) * progress), 0, 1),
1674 CLAMP (color->green + ((other_color->green - color->green) * progress), 0, 1),
1675 CLAMP (color->blue + ((other_color->blue - color->blue) * progress), 0, 1),
1676 CLAMP (color->alpha + ((other_color->alpha - color->alpha) * progress), 0, 1));
1681 /* Replace pattern to use */
1682 cairo_pattern_destroy (pattern);
1683 pattern = new_pattern;
1687 cairo_pattern_destroy (other_pattern);
1690 gdk_rgba_free (other_bg);
1693 cairo_rectangle (cr, 0, 0, 1, 1);
1697 cairo_set_source (cr, pattern);
1698 cairo_pattern_destroy (pattern);
1701 gdk_cairo_set_source_rgba (cr, bg_color);
1707 cairo_pattern_t *mask;
1709 mask = cairo_pattern_create_rgba (1, 1, 1, alpha);
1710 cairo_mask (cr, mask);
1711 cairo_pattern_destroy (mask);
1716 gdk_rgba_free (bg_color);
1720 gtk_theming_engine_render_background (GtkThemingEngine *engine,
1727 GtkJunctionSides junction;
1728 GtkStateFlags flags;
1731 junction = gtk_theming_engine_get_junction_sides (engine);
1733 flags = gtk_theming_engine_get_state (engine);
1734 gtk_theming_engine_get (engine, flags,
1735 "border-width", &border,
1740 width -= border->left + border->right;
1741 height -= border->top + border->bottom;
1743 render_background_internal (engine, cr,
1744 x, y, width, height,
1747 gtk_border_free (border);
1750 /* Renders the small triangle on corners so
1751 * frames with 0 radius have a 3D-like effect
1754 _cairo_corner_triangle (cairo_t *cr,
1761 cairo_move_to (cr, x + 0.5, y + size - 0.5);
1762 cairo_line_to (cr, x + size - 0.5, y + size - 0.5);
1763 cairo_line_to (cr, x + size - 0.5, y + 0.5);
1765 for (i = 1; i < size - 1; i++)
1767 cairo_move_to (cr, x + size - 0.5, y + i + 0.5);
1768 cairo_line_to (cr, x + (size - i) - 0.5, y + i + 0.5);
1773 render_frame_internal (GtkThemingEngine *engine,
1780 GtkJunctionSides junction)
1782 GtkStateFlags state;
1784 GdkRGBA *border_color;
1785 GtkBorderStyle border_style;
1786 gint border_width, radius;
1787 gdouble progress, d1, d2, m;
1791 state = gtk_theming_engine_get_state (engine);
1792 gtk_theming_engine_get (engine, state,
1793 "border-color", &border_color,
1794 "border-style", &border_style,
1795 "border-width", &border,
1796 "border-radius", &radius,
1799 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
1800 border_width = MIN (MIN (border->top, border->bottom),
1801 MIN (border->left, border->right));
1805 GtkStateFlags other_state;
1806 GdkRGBA *other_color;
1808 if (state & GTK_STATE_FLAG_PRELIGHT)
1810 other_state = state & ~(GTK_STATE_FLAG_PRELIGHT);
1811 progress = 1 - progress;
1814 other_state = state | GTK_STATE_FLAG_PRELIGHT;
1816 gtk_theming_engine_get (engine, other_state,
1817 "border-color", &other_color,
1820 border_color->red = CLAMP (border_color->red + ((other_color->red - border_color->red) * progress), 0, 1);
1821 border_color->green = CLAMP (border_color->green + ((other_color->green - border_color->green) * progress), 0, 1);
1822 border_color->blue = CLAMP (border_color->blue + ((other_color->blue - border_color->blue) * progress), 0, 1);
1823 border_color->alpha = CLAMP (border_color->alpha + ((other_color->alpha - border_color->alpha) * progress), 0, 1);
1825 gdk_rgba_free (other_color);
1830 color_shade (border_color, 1.8, &lighter);
1832 switch (border_style)
1834 case GTK_BORDER_STYLE_NONE:
1836 case GTK_BORDER_STYLE_SOLID:
1837 cairo_set_line_width (cr, border_width);
1838 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
1840 if (border_width > 1)
1842 x += (gdouble) border_width / 2;
1843 y += (gdouble) border_width / 2;
1844 width -= border_width;
1845 height -= border_width;
1847 else if (border_width == 1)
1855 _cairo_round_rectangle_sides (cr, (gdouble) radius,
1856 x, y, width, height,
1857 SIDE_ALL & ~(hidden_side),
1859 gdk_cairo_set_source_rgba (cr, border_color);
1863 case GTK_BORDER_STYLE_INSET:
1864 case GTK_BORDER_STYLE_OUTSET:
1865 cairo_set_line_width (cr, border_width);
1868 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
1870 cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
1872 if (border_width > 1)
1874 d1 = (gdouble) border_width / 2;
1885 m = MIN (width, height);
1888 if (border_style == GTK_BORDER_STYLE_INSET)
1889 gdk_cairo_set_source_rgba (cr, &lighter);
1891 gdk_cairo_set_source_rgba (cr, border_color);
1893 _cairo_round_rectangle_sides (cr, (gdouble) radius,
1895 width - d2, height - d2,
1896 (SIDE_BOTTOM | SIDE_RIGHT) & ~(hidden_side),
1900 if (border_style == GTK_BORDER_STYLE_INSET)
1901 gdk_cairo_set_source_rgba (cr, border_color);
1903 gdk_cairo_set_source_rgba (cr, &lighter);
1905 _cairo_round_rectangle_sides (cr, (gdouble) radius,
1907 width - d2, height - d2,
1908 (SIDE_TOP | SIDE_LEFT) & ~(hidden_side),
1912 if (border_width > 1)
1914 /* overprint top/right and bottom/left corner
1915 * triangles if there are square corners there,
1916 * to give the box a 3D-like appearance.
1920 if (border_style == GTK_BORDER_STYLE_INSET)
1921 gdk_cairo_set_source_rgba (cr, &lighter);
1923 gdk_cairo_set_source_rgba (cr, border_color);
1925 cairo_set_line_width (cr, 1);
1928 (junction & GTK_JUNCTION_CORNER_TOPRIGHT) != 0)
1929 _cairo_corner_triangle (cr,
1930 x + width - border_width, y,
1934 (junction & GTK_JUNCTION_CORNER_BOTTOMLEFT) != 0)
1935 _cairo_corner_triangle (cr,
1936 x, y + height - border_width,
1949 gdk_rgba_free (border_color);
1951 gtk_border_free (border);
1955 gtk_theming_engine_render_frame (GtkThemingEngine *engine,
1962 GtkStateFlags flags;
1964 GtkBorderStyle border_style;
1965 GtkJunctionSides junction;
1967 flags = gtk_theming_engine_get_state (engine);
1968 junction = gtk_theming_engine_get_junction_sides (engine);
1970 gtk_theming_engine_get (engine, flags,
1971 "border-image", &slice,
1972 "border-style", &border_style,
1977 _gtk_9slice_render (slice, cr, x, y, width, height);
1978 _gtk_9slice_unref (slice);
1980 else if (border_style != GTK_BORDER_STYLE_NONE)
1981 render_frame_internal (engine, cr,
1982 x, y, width, height,
1987 gtk_theming_engine_render_expander (GtkThemingEngine *engine,
1994 GtkStateFlags flags;
1995 GdkRGBA *outline_color, *fg_color;
1996 double vertical_overshoot;
1999 double interp; /* interpolation factor for center position */
2000 double x_double_horz, y_double_horz;
2001 double x_double_vert, y_double_vert;
2002 double x_double, y_double;
2005 gboolean running, is_rtl;
2009 flags = gtk_theming_engine_get_state (engine);
2011 gtk_theming_engine_get (engine, flags,
2014 gtk_theming_engine_get (engine, flags,
2015 "border-color", &outline_color,
2018 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress);
2019 is_rtl = (gtk_theming_engine_get_direction (engine) == GTK_TEXT_DIR_RTL);
2023 progress = (flags & GTK_STATE_FLAG_ACTIVE) ? 1 : 0;
2025 if (!gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_HORIZONTAL))
2028 angle = (G_PI) - ((G_PI / 2) * progress);
2030 angle = (G_PI / 2) * progress;
2035 angle = (G_PI / 2) + ((G_PI / 2) * progress);
2037 angle = (G_PI / 2) - ((G_PI / 2) * progress);
2042 /* Compute distance that the stroke extends beyonds the end
2043 * of the triangle we draw.
2045 vertical_overshoot = line_width / 2.0 * (1. / tan (G_PI / 8));
2047 /* For odd line widths, we end the vertical line of the triangle
2048 * at a half pixel, so we round differently.
2050 if (line_width % 2 == 1)
2051 vertical_overshoot = ceil (0.5 + vertical_overshoot) - 0.5;
2053 vertical_overshoot = ceil (vertical_overshoot);
2055 /* Adjust the size of the triangle we draw so that the entire stroke fits
2057 diameter = (gint) MAX (3, width - 2 * vertical_overshoot);
2059 /* If the line width is odd, we want the diameter to be even,
2060 * and vice versa, so force the sum to be odd. This relationship
2061 * makes the point of the triangle look right.
2063 diameter -= (1 - (diameter + line_width) % 2);
2065 radius = diameter / 2.;
2067 /* Adjust the center so that the stroke is properly aligned with
2068 * the pixel grid. The center adjustment is different for the
2069 * horizontal and vertical orientations. For intermediate positions
2070 * we interpolate between the two.
2072 x_double_vert = floor ((x + width / 2) - (radius + line_width) / 2.) + (radius + line_width) / 2.;
2073 y_double_vert = (y + height / 2) - 0.5;
2075 x_double_horz = (x + width / 2) - 0.5;
2076 y_double_horz = floor ((y + height / 2) - (radius + line_width) / 2.) + (radius + line_width) / 2.;
2078 x_double = x_double_vert * (1 - interp) + x_double_horz * interp;
2079 y_double = y_double_vert * (1 - interp) + y_double_horz * interp;
2081 cairo_translate (cr, x_double, y_double);
2082 cairo_rotate (cr, angle);
2084 cairo_move_to (cr, - radius / 2., - radius);
2085 cairo_line_to (cr, radius / 2., 0);
2086 cairo_line_to (cr, - radius / 2., radius);
2087 cairo_close_path (cr);
2089 cairo_set_line_width (cr, line_width);
2091 gdk_cairo_set_source_rgba (cr, fg_color);
2093 cairo_fill_preserve (cr);
2095 gdk_cairo_set_source_rgba (cr, outline_color);
2100 gdk_rgba_free (fg_color);
2101 gdk_rgba_free (outline_color);
2105 gtk_theming_engine_render_focus (GtkThemingEngine *engine,
2112 GtkStateFlags flags;
2118 flags = gtk_theming_engine_get_state (engine);
2120 gtk_theming_engine_get (engine, flags,
2124 gtk_theming_engine_get_style (engine,
2125 "focus-line-width", &line_width,
2126 "focus-line-pattern", (gchar *) &dash_list,
2129 cairo_set_line_width (cr, (gdouble) line_width);
2133 gint n_dashes = strlen ((const gchar *) dash_list);
2134 gdouble *dashes = g_new (gdouble, n_dashes);
2135 gdouble total_length = 0;
2136 gdouble dash_offset;
2139 for (i = 0; i < n_dashes; i++)
2141 dashes[i] = dash_list[i];
2142 total_length += dash_list[i];
2145 /* The dash offset here aligns the pattern to integer pixels
2146 * by starting the dash at the right side of the left border
2147 * Negative dash offsets in cairo don't work
2148 * (https://bugs.freedesktop.org/show_bug.cgi?id=2729)
2150 dash_offset = - line_width / 2.;
2152 while (dash_offset < 0)
2153 dash_offset += total_length;
2155 cairo_set_dash (cr, dashes, n_dashes, dash_offset);
2159 cairo_rectangle (cr,
2160 x + line_width / 2.,
2161 y + line_width / 2.,
2163 height - line_width);
2165 gdk_cairo_set_source_rgba (cr, color);
2170 gdk_rgba_free (color);
2175 gtk_theming_engine_render_line (GtkThemingEngine *engine,
2182 GdkRGBA *bg_color, darker, lighter;
2183 GtkStateFlags flags;
2184 gint i, thickness, thickness_dark, thickness_light, len;
2185 cairo_matrix_t matrix;
2188 /* FIXME: thickness */
2190 thickness_dark = thickness / 2;
2191 thickness_light = thickness - thickness_dark;
2193 flags = gtk_theming_engine_get_state (engine);
2196 gtk_theming_engine_get (engine, flags,
2197 "background-color", &bg_color,
2199 color_shade (bg_color, 0.7, &darker);
2200 color_shade (bg_color, 1.3, &lighter);
2202 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
2203 cairo_set_line_width (cr, 1);
2205 angle = atan2 (x1 - x0, y1 - y0);
2206 angle = (2 * G_PI) - angle;
2209 cairo_get_matrix (cr, &matrix);
2210 cairo_matrix_translate (&matrix, x0, y0);
2211 cairo_matrix_rotate (&matrix, angle);
2212 cairo_set_matrix (cr, &matrix);
2217 len = (gint) sqrt ((x1 * x1) + (y1 * y1));
2219 y0 = -thickness_dark;
2221 for (i = 0; i < thickness_dark; i++)
2223 gdk_cairo_set_source_rgba (cr, &lighter);
2224 add_path_line (cr, len - i - 1.5, y0, len - 0.5, y0);
2227 gdk_cairo_set_source_rgba (cr, &darker);
2228 add_path_line (cr, 0.5, y0, len - i - 1.5, y0);
2234 for (i = 0; i < thickness_light; i++)
2236 gdk_cairo_set_source_rgba (cr, &darker);
2237 add_path_line (cr, 0.5, y0, thickness_light - i + 0.5, y0);
2240 gdk_cairo_set_source_rgba (cr, &lighter);
2241 add_path_line (cr, thickness_light - i + 0.5, y0, len - 0.5, y0);
2249 gdk_rgba_free (bg_color);
2253 gtk_theming_engine_render_layout (GtkThemingEngine *engine,
2257 PangoLayout *layout)
2259 const PangoMatrix *matrix;
2261 GtkStateFlags flags;
2266 flags = gtk_theming_engine_get_state (engine);
2268 gtk_theming_engine_get (engine, flags,
2272 matrix = pango_context_get_matrix (pango_layout_get_context (layout));
2274 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
2278 GtkStateFlags other_flags;
2281 if (flags & GTK_STATE_FLAG_PRELIGHT)
2283 other_flags = flags & ~(GTK_STATE_FLAG_PRELIGHT);
2284 progress = 1 - progress;
2287 other_flags = flags | GTK_STATE_FLAG_PRELIGHT;
2289 gtk_theming_engine_get (engine, other_flags,
2293 if (fg_color && other_fg)
2295 fg_color->red = CLAMP (fg_color->red + ((other_fg->red - fg_color->red) * progress), 0, 1);
2296 fg_color->green = CLAMP (fg_color->green + ((other_fg->green - fg_color->green) * progress), 0, 1);
2297 fg_color->blue = CLAMP (fg_color->blue + ((other_fg->blue - fg_color->blue) * progress), 0, 1);
2298 fg_color->alpha = CLAMP (fg_color->alpha + ((other_fg->alpha - fg_color->alpha) * progress), 0, 1);
2302 gdk_rgba_free (other_fg);
2307 cairo_matrix_t cairo_matrix;
2308 PangoRectangle rect;
2310 cairo_matrix_init (&cairo_matrix,
2311 matrix->xx, matrix->yx,
2312 matrix->xy, matrix->yy,
2313 matrix->x0, matrix->y0);
2315 pango_layout_get_extents (layout, NULL, &rect);
2316 pango_matrix_transform_rectangle (matrix, &rect);
2317 pango_extents_to_pixels (&rect, NULL);
2319 cairo_matrix.x0 += x - rect.x;
2320 cairo_matrix.y0 += y - rect.y;
2322 cairo_set_matrix (cr, &cairo_matrix);
2325 cairo_move_to (cr, x, y);
2327 if (flags & GTK_STATE_FLAG_INSENSITIVE)
2330 cairo_set_source_rgb (cr, 1, 1, 1);
2331 cairo_move_to (cr, x + 1, y + 1);
2332 _gtk_pango_fill_layout (cr, layout);
2336 gdk_cairo_set_source_rgba (cr, fg_color);
2337 pango_cairo_show_layout (cr, layout);
2341 gdk_rgba_free (fg_color);
2345 gtk_theming_engine_render_slider (GtkThemingEngine *engine,
2351 GtkOrientation orientation)
2353 const GtkWidgetPath *path;
2356 path = gtk_theming_engine_get_path (engine);
2358 gtk_theming_engine_render_background (engine, cr, x, y, width, height);
2359 gtk_theming_engine_render_frame (engine, cr, x, y, width, height);
2361 /* FIXME: thickness */
2364 if (gtk_widget_path_is_type (path, GTK_TYPE_SCALE))
2366 if (orientation == GTK_ORIENTATION_VERTICAL)
2367 gtk_theming_engine_render_line (engine, cr,
2369 y + (gint) height / 2,
2370 x + width - thickness - 1,
2371 y + (gint) height / 2);
2373 gtk_theming_engine_render_line (engine, cr,
2374 x + (gint) width / 2,
2376 x + (gint) width / 2,
2377 y + height - thickness - 1);
2382 gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
2388 GtkPositionType gap_side,
2392 GtkJunctionSides junction;
2393 GtkStateFlags state;
2394 gint border_width, radius;
2395 gdouble x0, y0, x1, y1, xc, yc, wc, hc;
2398 xc = yc = wc = hc = 0;
2399 state = gtk_theming_engine_get_state (engine);
2400 junction = gtk_theming_engine_get_junction_sides (engine);
2401 gtk_theming_engine_get (engine, state,
2402 "border-width", &border,
2403 "border-radius", &radius,
2406 border_width = MIN (MIN (border->top, border->bottom),
2407 MIN (border->left, border->right));
2414 xc = x + xy0_gap + border_width;
2416 wc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
2419 if (xy0_gap < radius)
2420 junction |= GTK_JUNCTION_CORNER_TOPLEFT;
2422 if (xy1_gap > width - radius)
2423 junction |= GTK_JUNCTION_CORNER_TOPRIGHT;
2425 case GTK_POS_BOTTOM:
2426 xc = x + xy0_gap + border_width;
2427 yc = y + height - border_width;
2428 wc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
2431 if (xy0_gap < radius)
2432 junction |= GTK_JUNCTION_CORNER_BOTTOMLEFT;
2434 if (xy1_gap > width - radius)
2435 junction |= GTK_JUNCTION_CORNER_BOTTOMRIGHT;
2440 yc = y + xy0_gap + border_width;
2442 hc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
2444 if (xy0_gap < radius)
2445 junction |= GTK_JUNCTION_CORNER_TOPLEFT;
2447 if (xy1_gap > height - radius)
2448 junction |= GTK_JUNCTION_CORNER_BOTTOMLEFT;
2452 xc = x + width - border_width;
2453 yc = y + xy0_gap + border_width;
2455 hc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
2457 if (xy0_gap < radius)
2458 junction |= GTK_JUNCTION_CORNER_TOPRIGHT;
2460 if (xy1_gap > height - radius)
2461 junction |= GTK_JUNCTION_CORNER_BOTTOMRIGHT;
2466 cairo_clip_extents (cr, &x0, &y0, &x1, &y1);
2467 cairo_rectangle (cr, x0, y0, x1 - x0, yc - y0);
2468 cairo_rectangle (cr, x0, yc, xc - x0, hc);
2469 cairo_rectangle (cr, xc + wc, yc, x1 - (xc + wc), hc);
2470 cairo_rectangle (cr, x0, yc + hc, x1 - x0, y1 - (yc + hc));
2473 render_frame_internal (engine, cr,
2474 x, y, width, height,
2479 gtk_border_free (border);
2483 gtk_theming_engine_render_extension (GtkThemingEngine *engine,
2489 GtkPositionType gap_side)
2491 GtkJunctionSides junction = 0;
2492 guint hidden_side = 0;
2499 junction = GTK_JUNCTION_LEFT;
2500 hidden_side = SIDE_LEFT;
2502 cairo_translate (cr, x + width, y);
2503 cairo_rotate (cr, G_PI / 2);
2506 junction = GTK_JUNCTION_RIGHT;
2507 hidden_side = SIDE_RIGHT;
2509 cairo_translate (cr, x, y + height);
2510 cairo_rotate (cr, - G_PI / 2);
2513 junction = GTK_JUNCTION_TOP;
2514 hidden_side = SIDE_TOP;
2516 cairo_translate (cr, x + width, y + height);
2517 cairo_rotate (cr, G_PI);
2519 case GTK_POS_BOTTOM:
2520 junction = GTK_JUNCTION_BOTTOM;
2521 hidden_side = SIDE_BOTTOM;
2523 cairo_translate (cr, x, y);
2527 if (gap_side == GTK_POS_TOP ||
2528 gap_side == GTK_POS_BOTTOM)
2529 render_background_internal (engine, cr,
2530 0, 0, width, height,
2531 GTK_JUNCTION_BOTTOM);
2533 render_background_internal (engine, cr,
2534 0, 0, height, width,
2535 GTK_JUNCTION_BOTTOM);
2540 render_frame_internal (engine, cr,
2541 x, y, width, height,
2542 hidden_side, junction);
2548 render_dot (cairo_t *cr,
2549 const GdkRGBA *lighter,
2550 const GdkRGBA *darker,
2555 size = CLAMP ((gint) size, 2, 3);
2559 gdk_cairo_set_source_rgba (cr, lighter);
2560 cairo_rectangle (cr, x, y, 1, 1);
2561 cairo_rectangle (cr, x + 1, y + 1, 1, 1);
2566 gdk_cairo_set_source_rgba (cr, lighter);
2567 cairo_rectangle (cr, x, y, 2, 1);
2568 cairo_rectangle (cr, x, y, 1, 2);
2571 gdk_cairo_set_source_rgba (cr, darker);
2572 cairo_rectangle (cr, x + 1, y + 1, 2, 1);
2573 cairo_rectangle (cr, x + 2, y, 1, 2);
2579 gtk_theming_engine_render_handle (GtkThemingEngine *engine,
2586 GtkStateFlags flags;
2588 GdkRGBA lighter, darker;
2592 flags = gtk_theming_engine_get_state (engine);
2594 cairo_set_line_width (cr, 1);
2596 gtk_theming_engine_get (engine, flags,
2597 "background-color", &bg_color,
2599 color_shade (bg_color, 0.7, &darker);
2600 color_shade (bg_color, 1.3, &lighter);
2602 gdk_cairo_set_source_rgba (cr, bg_color);
2603 cairo_rectangle (cr, x, y, width, height);
2606 if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_GRIP))
2608 GtkJunctionSides sides;
2612 cairo_set_line_width (cr, 1.0);
2613 sides = gtk_theming_engine_get_junction_sides (engine);
2615 /* reduce confusing values to a meaningful state */
2616 if ((sides & (GTK_JUNCTION_CORNER_TOPLEFT | GTK_JUNCTION_CORNER_BOTTOMRIGHT)) == (GTK_JUNCTION_CORNER_TOPLEFT | GTK_JUNCTION_CORNER_BOTTOMRIGHT))
2617 sides &= ~GTK_JUNCTION_CORNER_TOPLEFT;
2619 if ((sides & (GTK_JUNCTION_CORNER_TOPRIGHT | GTK_JUNCTION_CORNER_BOTTOMLEFT)) == (GTK_JUNCTION_CORNER_TOPRIGHT | GTK_JUNCTION_CORNER_BOTTOMLEFT))
2620 sides &= ~GTK_JUNCTION_CORNER_TOPRIGHT;
2623 sides = GTK_JUNCTION_CORNER_BOTTOMRIGHT;
2625 /* align drawing area to the connected side */
2626 if (sides == GTK_JUNCTION_LEFT)
2631 else if (sides == GTK_JUNCTION_CORNER_TOPLEFT)
2635 else if (height < width)
2638 else if (sides == GTK_JUNCTION_CORNER_BOTTOMLEFT)
2640 /* make it square, aligning to bottom left */
2643 y += (height - width);
2646 else if (height < width)
2649 else if (sides == GTK_JUNCTION_RIGHT)
2651 /* aligning to right */
2654 x += (width - height);
2658 else if (sides == GTK_JUNCTION_CORNER_TOPRIGHT)
2662 else if (height < width)
2664 x += (width - height);
2668 else if (sides == GTK_JUNCTION_CORNER_BOTTOMRIGHT)
2670 /* make it square, aligning to bottom right */
2673 y += (height - width);
2676 else if (height < width)
2678 x += (width - height);
2682 else if (sides == GTK_JUNCTION_TOP)
2687 else if (sides == GTK_JUNCTION_BOTTOM)
2689 /* align to bottom */
2692 y += (height - width);
2697 g_assert_not_reached ();
2699 if (sides == GTK_JUNCTION_LEFT ||
2700 sides == GTK_JUNCTION_RIGHT)
2706 while (xi < x + width)
2708 gdk_cairo_set_source_rgba (cr, &lighter);
2709 add_path_line (cr, x, y, x, y + height);
2713 gdk_cairo_set_source_rgba (cr, &darker);
2714 add_path_line (cr, xi, y, xi, y + height);
2719 else if (sides == GTK_JUNCTION_TOP ||
2720 sides == GTK_JUNCTION_BOTTOM)
2726 while (yi < y + height)
2728 gdk_cairo_set_source_rgba (cr, &lighter);
2729 add_path_line (cr, x, yi, x + width, yi);
2733 gdk_cairo_set_source_rgba (cr, &darker);
2734 add_path_line (cr, x, yi, x + width, yi);
2739 else if (sides == GTK_JUNCTION_CORNER_TOPLEFT)
2748 gdk_cairo_set_source_rgba (cr, &darker);
2749 add_path_line (cr, xi, y, x, yi);
2755 add_path_line (cr, xi, y, x, yi);
2761 gdk_cairo_set_source_rgba (cr, &lighter);
2762 add_path_line (cr, xi, y, x, yi);
2769 else if (sides == GTK_JUNCTION_CORNER_TOPRIGHT)
2776 while (xi < (x + width - 3))
2778 gdk_cairo_set_source_rgba (cr, &lighter);
2779 add_path_line (cr, xi, y, x + width, yi);
2785 gdk_cairo_set_source_rgba (cr, &darker);
2786 add_path_line (cr, xi, y, x + width, yi);
2792 add_path_line (cr, xi, y, x + width, yi);
2799 else if (sides == GTK_JUNCTION_CORNER_BOTTOMLEFT)
2808 gdk_cairo_set_source_rgba (cr, &darker);
2809 add_path_line (cr, x, yi, xi, y + height);
2815 add_path_line (cr, x, yi, xi, y + height);
2821 gdk_cairo_set_source_rgba (cr, &lighter);
2822 add_path_line (cr, x, yi, xi, y + height);
2829 else if (sides == GTK_JUNCTION_CORNER_BOTTOMRIGHT)
2836 while (xi < (x + width - 3))
2838 gdk_cairo_set_source_rgba (cr, &lighter);
2839 add_path_line (cr, xi, y + height, x + width, yi);
2845 gdk_cairo_set_source_rgba (cr, &darker);
2846 add_path_line (cr, xi, y + height, x + width, yi);
2852 add_path_line (cr, xi, y + height, x + width, yi);
2862 else if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_PANE_SEPARATOR))
2865 for (xx = x + width / 2 - 15; xx <= x + width / 2 + 15; xx += 5)
2866 render_dot (cr, &lighter, &darker, xx, y + height / 2 - 1, 3);
2868 for (yy = y + height / 2 - 15; yy <= y + height / 2 + 15; yy += 5)
2869 render_dot (cr, &lighter, &darker, x + width / 2 - 1, yy, 3);
2873 for (yy = y; yy < y + height; yy += 3)
2874 for (xx = x; xx < x + width; xx += 6)
2876 render_dot (cr, &lighter, &darker, xx, yy, 2);
2877 render_dot (cr, &lighter, &darker, xx + 3, yy + 1, 2);
2883 gdk_rgba_free (bg_color);
2887 gtk_theming_engine_render_activity (GtkThemingEngine *engine,
2894 if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_SPINNER))
2896 GtkStateFlags state;
2897 guint num_steps, step;
2907 state = gtk_theming_engine_get_state (engine);
2908 gtk_theming_engine_get (engine, state,
2912 if (gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress))
2913 step = (guint) (progress * num_steps);
2919 cairo_translate (cr, x, y);
2921 /* draw clip region */
2922 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
2926 radius = MIN (width / 2, height / 2);
2927 half = num_steps / 2;
2929 for (i = 0; i < num_steps; i++)
2931 gint inset = 0.7 * radius;
2933 /* transparency is a function of time and intial value */
2934 gdouble t = (gdouble) ((i + num_steps - step)
2935 % num_steps) / num_steps;
2939 cairo_set_source_rgba (cr,
2945 cairo_set_line_width (cr, 2.0);
2947 dx + (radius - inset) * cos (i * G_PI / half),
2948 dy + (radius - inset) * sin (i * G_PI / half));
2950 dx + radius * cos (i * G_PI / half),
2951 dy + radius * sin (i * G_PI / half));
2959 gdk_rgba_free (color);
2963 gtk_theming_engine_render_background (engine, cr, x, y, width, height);
2964 gtk_theming_engine_render_frame (engine, cr, x, y, width, height);
2969 scale_or_ref (GdkPixbuf *src,
2973 if (width == gdk_pixbuf_get_width (src) &&
2974 height == gdk_pixbuf_get_height (src))
2975 return g_object_ref (src);
2977 return gdk_pixbuf_scale_simple (src,
2979 GDK_INTERP_BILINEAR);
2983 lookup_icon_size (GtkThemingEngine *engine,
2989 GtkSettings *settings;
2991 screen = gtk_theming_engine_get_screen (engine);
2992 settings = gtk_settings_get_for_screen (screen);
2994 return gtk_icon_size_lookup_for_settings (settings, size, width, height);
2997 /* Kudos to the gnome-panel guys. */
2999 colorshift_pixbuf (GdkPixbuf *src,
3004 gint width, height, has_alpha, src_rowstride, dest_rowstride;
3005 guchar *target_pixels;
3006 guchar *original_pixels;
3012 has_alpha = gdk_pixbuf_get_has_alpha (src);
3013 width = gdk_pixbuf_get_width (src);
3014 height = gdk_pixbuf_get_height (src);
3015 src_rowstride = gdk_pixbuf_get_rowstride (src);
3016 dest_rowstride = gdk_pixbuf_get_rowstride (dest);
3017 original_pixels = gdk_pixbuf_get_pixels (src);
3018 target_pixels = gdk_pixbuf_get_pixels (dest);
3020 for (i = 0; i < height; i++)
3022 pix_dest = target_pixels + i * dest_rowstride;
3023 pix_src = original_pixels + i * src_rowstride;
3025 for (j = 0; j < width; j++)
3032 *(pix_dest++) = CLAMP (val, 0, 255);
3035 *(pix_dest++) = CLAMP (val, 0, 255);
3038 *(pix_dest++) = CLAMP (val, 0, 255);
3041 *(pix_dest++) = *(pix_src++);
3047 gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine *engine,
3048 const GtkIconSource *source,
3053 GdkPixbuf *base_pixbuf;
3054 GtkStateFlags state;
3058 base_pixbuf = gtk_icon_source_get_pixbuf (source);
3059 state = gtk_theming_engine_get_state (engine);
3061 g_return_val_if_fail (base_pixbuf != NULL, NULL);
3063 if (size != (GtkIconSize) -1 &&
3064 !lookup_icon_size (engine, size, &width, &height))
3066 g_warning (G_STRLOC ": invalid icon size '%d'", size);
3070 /* If the size was wildcarded, and we're allowed to scale, then scale; otherwise,
3073 if (size != (GtkIconSize) -1 &&
3074 gtk_icon_source_get_size_wildcarded (source))
3075 scaled = scale_or_ref (base_pixbuf, width, height);
3077 scaled = g_object_ref (base_pixbuf);
3079 /* If the state was wildcarded, then generate a state. */
3080 if (gtk_icon_source_get_state_wildcarded (source))
3082 if (state & GTK_STATE_FLAG_INSENSITIVE)
3084 stated = gdk_pixbuf_copy (scaled);
3085 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
3087 g_object_unref (scaled);
3089 else if (state & GTK_STATE_FLAG_PRELIGHT)
3091 stated = gdk_pixbuf_copy (scaled);
3092 colorshift_pixbuf (scaled, stated, 30);
3093 g_object_unref (scaled);