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 "gtkborderimageprivate.h"
32 #include "gtkshadowprivate.h"
33 #include "gtkcsstypesprivate.h"
36 * SECTION:gtkthemingengine
37 * @Short_description: Theming renderers
38 * @Title: GtkThemingEngine
39 * @See_also: #GtkStyleContext
41 * #GtkThemingEngine is the object used for rendering themed content
42 * in GTK+ widgets. Even though GTK+ has a default implementation,
43 * it can be overridden in CSS files by enforcing a #GtkThemingEngine
44 * object to be loaded as a module.
46 * In order to implement a theming engine, a #GtkThemingEngine subclass
47 * must be created, alongside the CSS file that will reference it, the
48 * theming engine would be created as an .so library, and installed in
49 * $(gtk-modules-dir)/theming-engines/.
51 * #GtkThemingEngine<!-- -->s have limited access to the object they are
52 * rendering, the #GtkThemingEngine API has read-only accessors to the
53 * style information contained in the rendered object's #GtkStyleContext.
56 typedef struct GtkThemingEnginePrivate GtkThemingEnginePrivate;
71 struct GtkThemingEnginePrivate
73 GtkStyleContext *context;
77 #define GTK_THEMING_ENGINE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_THEMING_ENGINE, GtkThemingEnginePrivate))
79 static void gtk_theming_engine_finalize (GObject *object);
80 static void gtk_theming_engine_impl_set_property (GObject *object,
84 static void gtk_theming_engine_impl_get_property (GObject *object,
89 static void gtk_theming_engine_render_check (GtkThemingEngine *engine,
95 static void gtk_theming_engine_render_option (GtkThemingEngine *engine,
101 static void gtk_theming_engine_render_arrow (GtkThemingEngine *engine,
107 static void gtk_theming_engine_render_background (GtkThemingEngine *engine,
113 static void gtk_theming_engine_render_frame (GtkThemingEngine *engine,
119 static void gtk_theming_engine_render_expander (GtkThemingEngine *engine,
125 static void gtk_theming_engine_render_focus (GtkThemingEngine *engine,
131 static void gtk_theming_engine_render_layout (GtkThemingEngine *engine,
135 PangoLayout *layout);
136 static void gtk_theming_engine_render_line (GtkThemingEngine *engine,
142 static void gtk_theming_engine_render_slider (GtkThemingEngine *engine,
148 GtkOrientation orientation);
149 static void gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
155 GtkPositionType gap_side,
158 static void gtk_theming_engine_render_extension (GtkThemingEngine *engine,
164 GtkPositionType gap_side);
165 static void gtk_theming_engine_render_handle (GtkThemingEngine *engine,
171 static void gtk_theming_engine_render_activity (GtkThemingEngine *engine,
177 static GdkPixbuf * gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine *engine,
178 const GtkIconSource *source,
181 G_DEFINE_TYPE (GtkThemingEngine, gtk_theming_engine, G_TYPE_OBJECT)
184 typedef struct GtkThemingModule GtkThemingModule;
185 typedef struct GtkThemingModuleClass GtkThemingModuleClass;
187 struct GtkThemingModule
189 GTypeModule parent_instance;
193 void (*init) (GTypeModule *module);
195 GtkThemingEngine * (*create_engine) (void);
198 struct GtkThemingModuleClass
200 GTypeModuleClass parent_class;
203 #define GTK_TYPE_THEMING_MODULE (gtk_theming_module_get_type ())
204 #define GTK_THEMING_MODULE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_THEMING_MODULE, GtkThemingModule))
205 #define GTK_IS_THEMING_MODULE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_THEMING_MODULE))
207 G_DEFINE_TYPE (GtkThemingModule, gtk_theming_module, G_TYPE_TYPE_MODULE);
210 gtk_theming_engine_class_init (GtkThemingEngineClass *klass)
212 GObjectClass *object_class = G_OBJECT_CLASS (klass);
214 object_class->finalize = gtk_theming_engine_finalize;
215 object_class->set_property = gtk_theming_engine_impl_set_property;
216 object_class->get_property = gtk_theming_engine_impl_get_property;
218 klass->render_check = gtk_theming_engine_render_check;
219 klass->render_option = gtk_theming_engine_render_option;
220 klass->render_arrow = gtk_theming_engine_render_arrow;
221 klass->render_background = gtk_theming_engine_render_background;
222 klass->render_frame = gtk_theming_engine_render_frame;
223 klass->render_expander = gtk_theming_engine_render_expander;
224 klass->render_focus = gtk_theming_engine_render_focus;
225 klass->render_layout = gtk_theming_engine_render_layout;
226 klass->render_line = gtk_theming_engine_render_line;
227 klass->render_slider = gtk_theming_engine_render_slider;
228 klass->render_frame_gap = gtk_theming_engine_render_frame_gap;
229 klass->render_extension = gtk_theming_engine_render_extension;
230 klass->render_handle = gtk_theming_engine_render_handle;
231 klass->render_activity = gtk_theming_engine_render_activity;
232 klass->render_icon_pixbuf = gtk_theming_engine_render_icon_pixbuf;
235 * GtkThemingEngine:name:
237 * The theming engine name, this name will be used when registering
238 * custom properties, for a theming engine named "Clearlooks" registering
239 * a "glossy" custom property, it could be referenced in the CSS file as
242 * -Clearlooks-glossy: true;
247 g_object_class_install_property (object_class,
249 g_param_spec_string ("name",
251 P_("Theming engine name"),
253 G_PARAM_CONSTRUCT_ONLY | GTK_PARAM_READWRITE));
255 g_type_class_add_private (object_class, sizeof (GtkThemingEnginePrivate));
259 gtk_theming_engine_init (GtkThemingEngine *engine)
261 engine->priv = GTK_THEMING_ENGINE_GET_PRIVATE (engine);
265 gtk_theming_engine_finalize (GObject *object)
267 GtkThemingEnginePrivate *priv;
269 priv = GTK_THEMING_ENGINE (object)->priv;
272 G_OBJECT_GET_CLASS (gtk_theming_engine_parent_class)->finalize (object);
276 gtk_theming_engine_impl_set_property (GObject *object,
281 GtkThemingEnginePrivate *priv;
283 priv = GTK_THEMING_ENGINE (object)->priv;
291 priv->name = g_value_dup_string (value);
294 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
300 gtk_theming_engine_impl_get_property (GObject *object,
305 GtkThemingEnginePrivate *priv;
307 priv = GTK_THEMING_ENGINE (object)->priv;
312 g_value_set_string (value, priv->name);
315 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
321 _gtk_theming_engine_set_context (GtkThemingEngine *engine,
322 GtkStyleContext *context)
324 GtkThemingEnginePrivate *priv;
326 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
327 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
330 priv->context = context;
334 * gtk_theming_engine_register_property: (skip)
335 * @name_space: namespace for the property name
336 * @parse_func: parsing function to use, or %NULL
337 * @pspec: the #GParamSpec for the new property
339 * Registers a property so it can be used in the CSS file format,
340 * on the CSS file the property will look like
341 * "-${@name_space}-${property_name}". being
342 * ${property_name} the given to @pspec. @name_space will usually
343 * be the theme engine name.
345 * For any type a @parse_func may be provided, being this function
346 * used for turning any property value (between ':' and ';') in
347 * CSS to the #GValue needed. For basic types there is already
348 * builtin parsing support, so %NULL may be provided for these
352 * Engines must ensure property registration happens exactly once,
353 * usually GTK+ deals with theming engines as singletons, so this
354 * should be guaranteed to happen once, but bear this in mind
355 * when creating #GtkThemeEngine<!-- -->s yourself.
359 * In order to make use of the custom registered properties in
360 * the CSS file, make sure the engine is loaded first by specifying
361 * the engine property, either in a previous rule or within the same
365 * engine: someengine;
366 * -SomeEngine-custom-property: 2;
374 gtk_theming_engine_register_property (const gchar *name_space,
375 GtkStylePropertyParser parse_func,
380 g_return_if_fail (name_space != NULL);
381 g_return_if_fail (strchr (name_space, ' ') == NULL);
382 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
384 /* FIXME: hack hack hack, replacing pspec->name to include namespace */
385 name = g_strdup_printf ("-%s-%s", name_space, pspec->name);
386 g_free (pspec->name);
389 gtk_style_properties_register_property (parse_func, pspec);
393 * gtk_theming_engine_get_property:
394 * @engine: a #GtkThemingEngine
395 * @property: the property name
396 * @state: state to retrieve the value for
397 * @value: (out) (transfer full): return location for the property value,
398 * you must free this memory using g_value_unset() once you are
401 * Gets a property value as retrieved from the style settings that apply
402 * to the currently rendered element.
407 gtk_theming_engine_get_property (GtkThemingEngine *engine,
408 const gchar *property,
412 GtkThemingEnginePrivate *priv;
414 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
415 g_return_if_fail (property != NULL);
416 g_return_if_fail (value != NULL);
419 gtk_style_context_get_property (priv->context, property, state, value);
423 * gtk_theming_engine_get_valist:
424 * @engine: a #GtkThemingEngine
425 * @state: state to retrieve values for
426 * @args: va_list of property name/return location pairs, followed by %NULL
428 * Retrieves several style property values that apply to the currently
434 gtk_theming_engine_get_valist (GtkThemingEngine *engine,
438 GtkThemingEnginePrivate *priv;
440 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
443 gtk_style_context_get_valist (priv->context, state, args);
447 * gtk_theming_engine_get:
448 * @engine: a #GtkThemingEngine
449 * @state: state to retrieve values for
450 * @...: property name /return value pairs, followed by %NULL
452 * Retrieves several style property values that apply to the currently
458 gtk_theming_engine_get (GtkThemingEngine *engine,
462 GtkThemingEnginePrivate *priv;
465 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
469 va_start (args, state);
470 gtk_style_context_get_valist (priv->context, state, args);
475 * gtk_theming_engine_get_style_property:
476 * @engine: a #GtkThemingEngine
477 * @property_name: the name of the widget style property
478 * @value: Return location for the property value, free with
479 * g_value_unset() after use.
481 * Gets the value for a widget style property.
486 gtk_theming_engine_get_style_property (GtkThemingEngine *engine,
487 const gchar *property_name,
490 GtkThemingEnginePrivate *priv;
492 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
493 g_return_if_fail (property_name != NULL);
496 gtk_style_context_get_style_property (priv->context, property_name, value);
500 * gtk_theming_engine_get_style_valist:
501 * @engine: a #GtkThemingEngine
502 * @args: va_list of property name/return location pairs, followed by %NULL
504 * Retrieves several widget style properties from @engine according to the
505 * currently rendered content's style.
510 gtk_theming_engine_get_style_valist (GtkThemingEngine *engine,
513 GtkThemingEnginePrivate *priv;
515 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
518 gtk_style_context_get_style_valist (priv->context, args);
522 * gtk_theming_engine_get_style:
523 * @engine: a #GtkThemingEngine
524 * @...: property name /return value pairs, followed by %NULL
526 * Retrieves several widget style properties from @engine according
527 * to the currently rendered content's style.
532 gtk_theming_engine_get_style (GtkThemingEngine *engine,
535 GtkThemingEnginePrivate *priv;
538 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
542 va_start (args, engine);
543 gtk_style_context_get_style_valist (priv->context, args);
548 * gtk_theming_engine_lookup_color:
549 * @engine: a #GtkThemingEngine
550 * @color_name: color name to lookup
551 * @color: (out): Return location for the looked up color
553 * Looks up and resolves a color name in the current style's color map.
555 * Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
558 gtk_theming_engine_lookup_color (GtkThemingEngine *engine,
559 const gchar *color_name,
562 GtkThemingEnginePrivate *priv;
564 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
565 g_return_val_if_fail (color_name != NULL, FALSE);
568 return gtk_style_context_lookup_color (priv->context, color_name, color);
572 * gtk_theming_engine_get_state:
573 * @engine: a #GtkThemingEngine
575 * returns the state used when rendering.
577 * Returns: the state flags
582 gtk_theming_engine_get_state (GtkThemingEngine *engine)
584 GtkThemingEnginePrivate *priv;
586 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), 0);
589 return gtk_style_context_get_state (priv->context);
593 * gtk_theming_engine_state_is_running:
594 * @engine: a #GtkThemingEngine
595 * @state: a widget state
596 * @progress: (out): return location for the transition progress
598 * Returns %TRUE if there is a transition animation running for the
599 * current region (see gtk_style_context_push_animatable_region()).
601 * If @progress is not %NULL, the animation progress will be returned
602 * there, 0.0 means the state is closest to being %FALSE, while 1.0 means
603 * it's closest to being %TRUE. This means transition animations will
604 * run from 0 to 1 when @state is being set to %TRUE and from 1 to 0 when
605 * it's being set to %FALSE.
607 * Returns: %TRUE if there is a running transition animation for @state.
612 gtk_theming_engine_state_is_running (GtkThemingEngine *engine,
616 GtkThemingEnginePrivate *priv;
618 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
621 return gtk_style_context_state_is_running (priv->context, state, progress);
625 * gtk_theming_engine_get_path:
626 * @engine: a #GtkThemingEngine
628 * Returns the widget path used for style matching.
630 * Returns: (transfer none): A #GtkWidgetPath
634 G_CONST_RETURN GtkWidgetPath *
635 gtk_theming_engine_get_path (GtkThemingEngine *engine)
637 GtkThemingEnginePrivate *priv;
639 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
642 return gtk_style_context_get_path (priv->context);
646 * gtk_theming_engine_has_class:
647 * @engine: a #GtkThemingEngine
648 * @style_class: class name to look up
650 * Returns %TRUE if the currently rendered contents have
651 * defined the given class name.
653 * Returns: %TRUE if @engine has @class_name defined
658 gtk_theming_engine_has_class (GtkThemingEngine *engine,
659 const gchar *style_class)
661 GtkThemingEnginePrivate *priv;
663 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
666 return gtk_style_context_has_class (priv->context, style_class);
670 * gtk_theming_engine_has_region:
671 * @engine: a #GtkThemingEngine
672 * @style_region: a region name
673 * @flags: (out) (allow-none): return location for region flags
675 * Returns %TRUE if the currently rendered contents have the
676 * region defined. If @flags_return is not %NULL, it is set
677 * to the flags affecting the region.
679 * Returns: %TRUE if region is defined
684 gtk_theming_engine_has_region (GtkThemingEngine *engine,
685 const gchar *style_region,
686 GtkRegionFlags *flags)
688 GtkThemingEnginePrivate *priv;
693 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
696 return gtk_style_context_has_region (priv->context, style_region, flags);
700 * gtk_theming_engine_get_direction:
701 * @engine: a #GtkThemingEngine
703 * Returns the widget direction used for rendering.
705 * Returns: the widget direction
710 gtk_theming_engine_get_direction (GtkThemingEngine *engine)
712 GtkThemingEnginePrivate *priv;
714 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), GTK_TEXT_DIR_LTR);
717 return gtk_style_context_get_direction (priv->context);
721 * gtk_theming_engine_get_junction_sides:
722 * @engine: a #GtkThemingEngine
724 * Returns the widget direction used for rendering.
726 * Returns: the widget direction
731 gtk_theming_engine_get_junction_sides (GtkThemingEngine *engine)
733 GtkThemingEnginePrivate *priv;
735 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), 0);
738 return gtk_style_context_get_junction_sides (priv->context);
742 * gtk_theming_engine_get_color:
743 * @engine: a #GtkThemingEngine
744 * @state: state to retrieve the color for
745 * @color: (out): return value for the foreground color
747 * Gets the foreground color for a given state.
752 gtk_theming_engine_get_color (GtkThemingEngine *engine,
756 GtkThemingEnginePrivate *priv;
758 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
761 gtk_style_context_get_color (priv->context, state, color);
765 * gtk_theming_engine_get_background_color:
766 * @engine: a #GtkThemingEngine
767 * @state: state to retrieve the color for
768 * @color: (out): return value for the background color
770 * Gets the background color for a given state.
775 gtk_theming_engine_get_background_color (GtkThemingEngine *engine,
779 GtkThemingEnginePrivate *priv;
781 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
784 gtk_style_context_get_background_color (priv->context, state, color);
788 * gtk_theming_engine_get_border_color:
789 * @engine: a #GtkThemingEngine
790 * @state: state to retrieve the color for
791 * @color: (out): return value for the border color
793 * Gets the border color for a given state.
798 gtk_theming_engine_get_border_color (GtkThemingEngine *engine,
802 GtkThemingEnginePrivate *priv;
804 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
807 gtk_style_context_get_border_color (priv->context, state, color);
811 * gtk_theming_engine_get_border:
812 * @engine: a #GtkthemingEngine
813 * @state: state to retrieve the border for
814 * @border: (out): return value for the border settings
816 * Gets the border for a given state as a #GtkBorder.
821 gtk_theming_engine_get_border (GtkThemingEngine *engine,
825 GtkThemingEnginePrivate *priv;
827 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
830 gtk_style_context_get_border (priv->context, state, border);
834 * gtk_theming_engine_get_padding:
835 * @engine: a #GtkthemingEngine
836 * @state: state to retrieve the padding for
837 * @padding: (out): return value for the padding settings
839 * Gets the padding for a given state as a #GtkBorder.
844 gtk_theming_engine_get_padding (GtkThemingEngine *engine,
848 GtkThemingEnginePrivate *priv;
850 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
853 gtk_style_context_get_padding (priv->context, state, padding);
857 * gtk_theming_engine_get_margin:
858 * @engine: a #GtkThemingEngine
859 * @state: state to retrieve the border for
860 * @margin: (out): return value for the margin settings
862 * Gets the margin for a given state as a #GtkBorder.
867 gtk_theming_engine_get_margin (GtkThemingEngine *engine,
871 GtkThemingEnginePrivate *priv;
873 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
876 gtk_style_context_get_margin (priv->context, state, margin);
880 * gtk_theming_engine_get_font:
881 * @engine: a #GtkThemingEngine
882 * @state: state to retrieve the font for
884 * Returns the font description for a given state.
886 * Returns: (transfer none): the #PangoFontDescription for the given
887 * state. This object is owned by GTK+ and should not be
892 const PangoFontDescription *
893 gtk_theming_engine_get_font (GtkThemingEngine *engine,
896 GtkThemingEnginePrivate *priv;
898 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
901 return gtk_style_context_get_font (priv->context, state);
904 /* GtkThemingModule */
907 gtk_theming_module_load (GTypeModule *type_module)
909 GtkThemingModule *theming_module;
911 gchar *name, *module_path;
913 theming_module = GTK_THEMING_MODULE (type_module);
914 name = theming_module->name;
915 module_path = _gtk_find_module (name, "theming-engines");
920 module = g_module_open (module_path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
921 g_free (module_path);
926 if (!g_module_symbol (module, "theme_init",
927 (gpointer *) &theming_module->init) ||
928 !g_module_symbol (module, "theme_exit",
929 (gpointer *) &theming_module->exit) ||
930 !g_module_symbol (module, "create_engine",
931 (gpointer *) &theming_module->create_engine))
933 g_module_close (module);
938 theming_module->module = module;
940 theming_module->init (G_TYPE_MODULE (theming_module));
946 gtk_theming_module_unload (GTypeModule *type_module)
948 GtkThemingModule *theming_module;
950 theming_module = GTK_THEMING_MODULE (type_module);
952 theming_module->exit ();
954 g_module_close (theming_module->module);
956 theming_module->module = NULL;
957 theming_module->init = NULL;
958 theming_module->exit = NULL;
959 theming_module->create_engine = NULL;
963 gtk_theming_module_class_init (GtkThemingModuleClass *klass)
965 GTypeModuleClass *module_class = G_TYPE_MODULE_CLASS (klass);
967 module_class->load = gtk_theming_module_load;
968 module_class->unload = gtk_theming_module_unload;
972 gtk_theming_module_init (GtkThemingModule *module)
977 * gtk_theming_engine_load:
978 * @name: Theme engine name to load
980 * Loads and initializes a theming engine module from the
981 * standard directories.
983 * Returns: (transfer none): A theming engine, or %NULL if
984 * the engine @name doesn't exist.
987 gtk_theming_engine_load (const gchar *name)
989 static GHashTable *engines = NULL;
990 static GtkThemingEngine *default_engine;
991 GtkThemingEngine *engine = NULL;
996 engines = g_hash_table_new (g_str_hash, g_str_equal);
998 engine = g_hash_table_lookup (engines, name);
1002 GtkThemingModule *module;
1004 module = g_object_new (GTK_TYPE_THEMING_MODULE, NULL);
1005 g_type_module_set_name (G_TYPE_MODULE (module), name);
1006 module->name = g_strdup (name);
1008 if (module && g_type_module_use (G_TYPE_MODULE (module)))
1010 engine = (module->create_engine) ();
1013 g_hash_table_insert (engines, module->name, engine);
1020 if (G_UNLIKELY (!default_engine))
1021 default_engine = g_object_new (GTK_TYPE_THEMING_ENGINE, NULL);
1023 engine = default_engine;
1030 * gtk_theming_engine_get_screen:
1031 * @engine: a #GtkThemingEngine
1033 * Returns the #GdkScreen to which @engine currently rendering to.
1035 * Returns: (transfer none): a #GdkScreen, or %NULL.
1038 gtk_theming_engine_get_screen (GtkThemingEngine *engine)
1040 GtkThemingEnginePrivate *priv;
1042 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
1044 priv = engine->priv;
1045 return gtk_style_context_get_screen (priv->context);
1048 /* Paint method implementations */
1050 gtk_theming_engine_render_check (GtkThemingEngine *engine,
1057 GdkRGBA fg_color, bg_color;
1058 GtkStateFlags flags;
1059 gint exterior_size, interior_size, thickness, pad;
1060 GtkBorderStyle border_style;
1064 flags = gtk_theming_engine_get_state (engine);
1067 gtk_theming_engine_get_color (engine, flags, &fg_color);
1068 gtk_theming_engine_get_background_color (engine, flags, &bg_color);
1069 gtk_theming_engine_get_border (engine, flags, &border);
1071 gtk_theming_engine_get (engine, flags,
1072 "border-style", &border_style,
1075 border_width = MIN (MIN (border.top, border.bottom),
1076 MIN (border.left, border.right));
1077 exterior_size = MIN (width, height);
1079 if (exterior_size % 2 == 0) /* Ensure odd */
1082 /* FIXME: thickness */
1084 pad = thickness + MAX (1, (exterior_size - 2 * thickness) / 9);
1085 interior_size = MAX (1, exterior_size - 2 * pad);
1087 if (interior_size < 7)
1090 pad = MAX (0, (exterior_size - interior_size) / 2);
1093 x -= (1 + exterior_size - (gint) width) / 2;
1094 y -= (1 + exterior_size - (gint) height) / 2;
1096 if (border_style == GTK_BORDER_STYLE_SOLID)
1098 GdkRGBA border_color;
1100 cairo_set_line_width (cr, border_width);
1101 gtk_theming_engine_get_border_color (engine, flags, &border_color);
1103 cairo_rectangle (cr, x + 0.5, y + 0.5, exterior_size - 1, exterior_size - 1);
1104 gdk_cairo_set_source_rgba (cr, &bg_color);
1105 cairo_fill_preserve (cr);
1107 gdk_cairo_set_source_rgba (cr, &border_color);
1111 gdk_cairo_set_source_rgba (cr, &fg_color);
1113 if (flags & GTK_STATE_FLAG_INCONSISTENT)
1115 int line_thickness = MAX (1, (3 + interior_size * 2) / 7);
1117 cairo_rectangle (cr,
1119 y + pad + (1 + interior_size - line_thickness) / 2,
1129 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress);
1131 if ((flags & GTK_STATE_FLAG_ACTIVE) || running)
1136 cairo_translate (cr,
1139 cairo_scale (cr, interior_size / 7., interior_size / 7.);
1141 cairo_rectangle (cr, 0, 0, 7 * progress, 7);
1144 cairo_move_to (cr, 7.0, 0.0);
1145 cairo_line_to (cr, 7.5, 1.0);
1146 cairo_curve_to (cr, 5.3, 2.0,
1149 cairo_curve_to (cr, 3.0, 5.7,
1152 cairo_line_to (cr, 0.2, 3.5);
1153 cairo_curve_to (cr, 1.1, 3.5,
1156 cairo_curve_to (cr, 1.0, 3.9,
1159 cairo_curve_to (cr, 3.5, 3.1,
1171 gtk_theming_engine_render_option (GtkThemingEngine *engine,
1178 GtkStateFlags flags;
1179 GdkRGBA fg_color, bg_color;
1180 gint exterior_size, interior_size, pad, thickness, border_width;
1181 GtkBorderStyle border_style;
1184 flags = gtk_theming_engine_get_state (engine);
1188 gtk_theming_engine_get_color (engine, flags, &fg_color);
1189 gtk_theming_engine_get_background_color (engine, flags, &bg_color);
1190 gtk_theming_engine_get_border (engine, flags, &border);
1192 gtk_theming_engine_get (engine, flags,
1193 "border-style", &border_style,
1196 exterior_size = MIN (width, height);
1197 border_width = MIN (MIN (border.top, border.bottom),
1198 MIN (border.left, border.right));
1200 if (exterior_size % 2 == 0) /* Ensure odd */
1203 x -= (1 + exterior_size - width) / 2;
1204 y -= (1 + exterior_size - height) / 2;
1206 if (border_style == GTK_BORDER_STYLE_SOLID)
1208 GdkRGBA border_color;
1210 cairo_set_line_width (cr, border_width);
1211 gtk_theming_engine_get_border_color (engine, flags, &border_color);
1213 cairo_new_sub_path (cr);
1215 x + exterior_size / 2.,
1216 y + exterior_size / 2.,
1217 (exterior_size - 1) / 2.,
1220 gdk_cairo_set_source_rgba (cr, &bg_color);
1221 cairo_fill_preserve (cr);
1223 gdk_cairo_set_source_rgba (cr, &border_color);
1227 gdk_cairo_set_source_rgba (cr, &fg_color);
1229 /* FIXME: thickness */
1232 if (flags & GTK_STATE_FLAG_INCONSISTENT)
1234 gint line_thickness;
1236 pad = thickness + MAX (1, (exterior_size - 2 * thickness) / 9);
1237 interior_size = MAX (1, exterior_size - 2 * pad);
1239 if (interior_size < 7)
1242 pad = MAX (0, (exterior_size - interior_size) / 2);
1245 line_thickness = MAX (1, (3 + interior_size * 2) / 7);
1247 cairo_rectangle (cr,
1249 y + pad + (interior_size - line_thickness) / 2.,
1254 if (flags & GTK_STATE_FLAG_ACTIVE)
1256 pad = thickness + MAX (1, 2 * (exterior_size - 2 * thickness) / 9);
1257 interior_size = MAX (1, exterior_size - 2 * pad);
1259 if (interior_size < 5)
1262 pad = MAX (0, (exterior_size - interior_size) / 2);
1265 cairo_new_sub_path (cr);
1267 x + pad + interior_size / 2.,
1268 y + pad + interior_size / 2.,
1278 add_path_arrow (cairo_t *cr,
1286 cairo_translate (cr, x + (size / 2), y + (size / 2));
1287 cairo_rotate (cr, angle);
1289 cairo_move_to (cr, 0, - (size / 4));
1290 cairo_line_to (cr, - (size / 2), (size / 4));
1291 cairo_line_to (cr, (size / 2), (size / 4));
1292 cairo_close_path (cr);
1298 gtk_theming_engine_render_arrow (GtkThemingEngine *engine,
1305 GtkStateFlags flags;
1310 flags = gtk_theming_engine_get_state (engine);
1311 gtk_theming_engine_get_color (engine, flags, &fg_color);
1313 if (flags & GTK_STATE_FLAG_INSENSITIVE)
1315 add_path_arrow (cr, angle, x + 1, y + 1, size);
1316 cairo_set_source_rgb (cr, 1, 1, 1);
1320 add_path_arrow (cr, angle, x, y, size);
1321 gdk_cairo_set_source_rgba (cr, &fg_color);
1328 add_path_line (cairo_t *cr,
1334 /* Adjust endpoints */
1348 cairo_move_to (cr, x1, y1);
1349 cairo_line_to (cr, x2, y2);
1353 color_shade (const GdkRGBA *color,
1355 GdkRGBA *color_return)
1357 GtkSymbolicColor *literal, *shade;
1359 literal = gtk_symbolic_color_new_literal (color);
1360 shade = gtk_symbolic_color_new_shade (literal, factor);
1361 gtk_symbolic_color_unref (literal);
1363 gtk_symbolic_color_resolve (shade, NULL, color_return);
1364 gtk_symbolic_color_unref (shade);
1368 _cairo_ellipsis (cairo_t *cr,
1369 double xc, double yc,
1370 double xradius, double yradius,
1371 double angle1, double angle2)
1373 if (xradius <= 0.0 || yradius <= 0.0)
1375 /* stolen from cairo sources */
1376 cairo_line_to (cr, xc, yc); /* might become a move_to */
1377 cairo_line_to (cr, xc, yc);
1382 cairo_translate (cr, xc, yc);
1383 cairo_scale (cr, xradius, yradius);
1384 cairo_arc (cr, 0, 0, 1.0, angle1, angle2);
1389 _cairo_round_rectangle_sides (cairo_t *cr,
1390 const GtkCssBorderRadius *border_radius,
1397 cairo_new_sub_path (cr);
1399 if (sides & SIDE_RIGHT)
1401 _cairo_ellipsis (cr,
1402 x + width - border_radius->top_right.horizontal,
1403 y + border_radius->top_right.vertical,
1404 border_radius->top_right.horizontal,
1405 border_radius->top_right.vertical,
1407 _cairo_ellipsis (cr,
1408 x + width - border_radius->bottom_right.horizontal,
1409 y + height - border_radius->bottom_right.vertical,
1410 border_radius->bottom_right.horizontal,
1411 border_radius->bottom_right.vertical,
1415 if (sides & SIDE_BOTTOM)
1417 _cairo_ellipsis (cr,
1418 x + width - border_radius->bottom_right.horizontal,
1419 y + height - border_radius->bottom_right.vertical,
1420 border_radius->bottom_right.horizontal,
1421 border_radius->bottom_right.vertical,
1422 G_PI / 4, G_PI / 2);
1423 _cairo_ellipsis (cr,
1424 x + border_radius->bottom_left.horizontal,
1425 y + height - border_radius->bottom_left.vertical,
1426 border_radius->bottom_left.horizontal,
1427 border_radius->bottom_left.vertical,
1428 G_PI / 2, 3 * (G_PI / 4));
1431 cairo_move_to (cr, x, y + height);
1433 if (sides & SIDE_LEFT)
1435 _cairo_ellipsis (cr,
1436 x + border_radius->bottom_left.horizontal,
1437 y + height - border_radius->bottom_left.vertical,
1438 border_radius->bottom_left.horizontal,
1439 border_radius->bottom_left.vertical,
1440 3 * (G_PI / 4), G_PI);
1441 _cairo_ellipsis (cr,
1442 x + border_radius->top_left.horizontal,
1443 y + border_radius->top_left.vertical,
1444 border_radius->top_left.horizontal,
1445 border_radius->top_left.vertical,
1446 G_PI, G_PI + G_PI / 4);
1449 cairo_move_to (cr, x, y);
1451 if (sides & SIDE_TOP)
1453 _cairo_ellipsis (cr,
1454 x + border_radius->top_left.horizontal,
1455 y + border_radius->top_left.vertical,
1456 border_radius->top_left.horizontal,
1457 border_radius->top_left.vertical,
1458 5 * (G_PI / 4), 3 * (G_PI / 2));
1459 _cairo_ellipsis (cr,
1460 x + width - border_radius->top_right.horizontal,
1461 y + border_radius->top_right.vertical,
1462 border_radius->top_right.horizontal,
1463 border_radius->top_right.vertical,
1464 3 * (G_PI / 2), - G_PI / 4);
1469 _cairo_uneven_frame (cairo_t *cr,
1470 const GtkCssBorderRadius *border_radius,
1477 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
1478 cairo_set_line_width (cr, 1);
1480 _cairo_round_rectangle_sides (cr, border_radius,
1485 _cairo_round_rectangle_sides (cr, border_radius,
1488 width - border->left - border->right,
1489 height - border->top - border->bottom,
1494 render_background_internal (GtkThemingEngine *engine,
1500 GtkJunctionSides junction)
1503 cairo_pattern_t *pattern;
1504 GtkStateFlags flags;
1506 gdouble progress, alpha = 1;
1508 GtkCssBorderCornerRadius *top_left_radius, *top_right_radius;
1509 GtkCssBorderCornerRadius *bottom_left_radius, *bottom_right_radius;
1510 GtkCssBorderRadius border_radius = { { 0, }, };
1512 GtkBorderStyle border_style;
1513 gdouble mat_w, mat_h;
1515 /* Use unmodified size for pattern scaling */
1519 flags = gtk_theming_engine_get_state (engine);
1521 gtk_theming_engine_get_background_color (engine, flags, &bg_color);
1522 gtk_theming_engine_get_border (engine, flags, &border);
1524 gtk_theming_engine_get (engine, flags,
1525 "background-image", &pattern,
1526 /* Can't use border-radius as it's an int for
1527 * backwards compat */
1528 "border-top-left-radius", &top_left_radius,
1529 "border-top-right-radius", &top_right_radius,
1530 "border-bottom-right-radius", &bottom_right_radius,
1531 "border-bottom-left-radius", &bottom_left_radius,
1532 "border-style", &border_style,
1535 if (top_left_radius)
1536 border_radius.top_left = *top_left_radius;
1537 g_free (top_left_radius);
1538 if (top_right_radius)
1539 border_radius.top_right = *top_right_radius;
1540 g_free (top_right_radius);
1541 if (bottom_right_radius)
1542 border_radius.bottom_right = *bottom_right_radius;
1543 g_free (bottom_right_radius);
1544 if (bottom_left_radius)
1545 border_radius.bottom_left = *bottom_left_radius;
1546 g_free (bottom_left_radius);
1548 border_width = MIN (MIN (border.top, border.bottom),
1549 MIN (border.left, border.right));
1551 if (border_width > 1 &&
1552 border_style == GTK_BORDER_STYLE_NONE)
1554 x += (gdouble) border_width / 2;
1555 y += (gdouble) border_width / 2;
1556 width -= border_width;
1557 height -= border_width;
1563 width -= border.left + border.right;
1564 height -= border.top + border.bottom;
1567 if (width <= 0 || height <= 0)
1571 cairo_set_line_width (cr, border_width);
1572 cairo_translate (cr, x, y);
1574 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
1576 if (gtk_theming_engine_has_class (engine, "background"))
1578 cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0); /* transparent */
1579 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
1585 cairo_pattern_t *other_pattern;
1586 GtkStateFlags other_flags;
1588 cairo_pattern_t *new_pattern = NULL;
1590 if (flags & GTK_STATE_FLAG_PRELIGHT)
1592 other_flags = flags & ~(GTK_STATE_FLAG_PRELIGHT);
1593 progress = 1 - progress;
1596 other_flags = flags | GTK_STATE_FLAG_PRELIGHT;
1598 gtk_theming_engine_get_background_color (engine, other_flags, &other_bg);
1599 gtk_theming_engine_get (engine, other_flags,
1600 "background-image", &other_pattern,
1603 if (pattern && other_pattern)
1605 cairo_pattern_type_t type, other_type;
1608 cairo_pattern_get_color_stop_count (pattern, &n0);
1609 cairo_pattern_get_color_stop_count (other_pattern, &n1);
1610 type = cairo_pattern_get_type (pattern);
1611 other_type = cairo_pattern_get_type (other_pattern);
1613 if (type == other_type && n0 == n1)
1615 gdouble offset0, red0, green0, blue0, alpha0;
1616 gdouble offset1, red1, green1, blue1, alpha1;
1617 gdouble x00, x01, y00, y01, x10, x11, y10, y11;
1618 gdouble r00, r01, r10, r11;
1621 if (type == CAIRO_PATTERN_TYPE_LINEAR)
1623 cairo_pattern_get_linear_points (pattern, &x00, &y00, &x01, &y01);
1624 cairo_pattern_get_linear_points (other_pattern, &x10, &y10, &x11, &y11);
1626 new_pattern = cairo_pattern_create_linear (x00 + (x10 - x00) * progress,
1627 y00 + (y10 - y00) * progress,
1628 x01 + (x11 - x01) * progress,
1629 y01 + (y11 - y01) * progress);
1633 cairo_pattern_get_radial_circles (pattern, &x00, &y00, &r00, &x01, &y01, &r01);
1634 cairo_pattern_get_radial_circles (other_pattern, &x10, &y10, &r10, &x11, &y11, &r11);
1636 new_pattern = cairo_pattern_create_radial (x00 + (x10 - x00) * progress,
1637 y00 + (y10 - y00) * progress,
1638 r00 + (r10 - r00) * progress,
1639 x01 + (x11 - x01) * progress,
1640 y01 + (y11 - y01) * progress,
1641 r01 + (r11 - r01) * progress);
1644 cairo_pattern_set_filter (new_pattern, CAIRO_FILTER_FAST);
1647 /* Blend both gradients into one */
1648 while (i < n0 && i < n1)
1650 cairo_pattern_get_color_stop_rgba (pattern, i,
1652 &red0, &green0, &blue0,
1654 cairo_pattern_get_color_stop_rgba (other_pattern, i,
1656 &red1, &green1, &blue1,
1659 cairo_pattern_add_color_stop_rgba (new_pattern,
1660 offset0 + ((offset1 - offset0) * progress),
1661 red0 + ((red1 - red0) * progress),
1662 green0 + ((green1 - green0) * progress),
1663 blue0 + ((blue1 - blue0) * progress),
1664 alpha0 + ((alpha1 - alpha0) * progress));
1670 /* Different pattern types, or different color
1671 * stop counts, alpha blend both patterns.
1673 _cairo_round_rectangle_sides (cr, &border_radius,
1674 0, 0, width, height,
1677 cairo_scale (cr, mat_w, mat_h);
1678 cairo_set_source (cr, other_pattern);
1679 cairo_scale (cr, 1.0 / mat_w, 1.0 / mat_h);
1680 cairo_fill_preserve (cr);
1682 /* Set alpha for posterior drawing
1683 * of the target pattern
1685 alpha = 1 - progress;
1688 else if (pattern || other_pattern)
1692 gdouble x0, y0, x1, y1, r0, r1;
1695 /* Blend a pattern with a color */
1700 progress = 1 - progress;
1708 if (cairo_pattern_get_type (p) == CAIRO_PATTERN_TYPE_LINEAR)
1710 cairo_pattern_get_linear_points (p, &x0, &y0, &x1, &y1);
1711 new_pattern = cairo_pattern_create_linear (x0, y0, x1, y1);
1715 cairo_pattern_get_radial_circles (p, &x0, &y0, &r0, &x1, &y1, &r1);
1716 new_pattern = cairo_pattern_create_radial (x0, y0, r0, x1, y1, r1);
1719 cairo_pattern_get_color_stop_count (p, &n);
1721 for (i = 0; i < n; i++)
1723 gdouble red1, green1, blue1, alpha1;
1726 cairo_pattern_get_color_stop_rgba (p, i,
1728 &red1, &green1, &blue1,
1730 cairo_pattern_add_color_stop_rgba (new_pattern, offset,
1731 c->red + ((red1 - c->red) * progress),
1732 c->green + ((green1 - c->green) * progress),
1733 c->blue + ((blue1 - c->blue) * progress),
1734 c->alpha + ((alpha1 - c->alpha) * progress));
1739 /* Merge just colors */
1740 new_pattern = cairo_pattern_create_rgba (CLAMP (bg_color.red + ((other_bg.red - bg_color.red) * progress), 0, 1),
1741 CLAMP (bg_color.green + ((other_bg.green - bg_color.green) * progress), 0, 1),
1742 CLAMP (bg_color.blue + ((other_bg.blue - bg_color.blue) * progress), 0, 1),
1743 CLAMP (bg_color.alpha + ((other_bg.alpha - bg_color.alpha) * progress), 0, 1));
1748 /* Replace pattern to use */
1749 cairo_pattern_destroy (pattern);
1750 pattern = new_pattern;
1754 cairo_pattern_destroy (other_pattern);
1757 _cairo_round_rectangle_sides (cr, &border_radius,
1758 0, 0, width, height,
1762 cairo_scale (cr, mat_w, mat_h);
1763 cairo_set_source (cr, pattern);
1764 cairo_scale (cr, 1.0 / mat_w, 1.0 / mat_h);
1767 gdk_cairo_set_source_rgba (cr, &bg_color);
1771 if (border_width > 1 &&
1772 border_style != GTK_BORDER_STYLE_NONE)
1774 /* stroke with the same source, so the background
1775 * has exactly the shape than the frame, this
1776 * is important so gtk_render_background() and
1777 * gtk_render_frame() fit perfectly with round
1780 cairo_fill_preserve (cr);
1789 _cairo_round_rectangle_sides (cr, &border_radius,
1790 0, 0, width, height,
1794 cairo_paint_with_alpha (cr, alpha);
1800 cairo_pattern_destroy (pattern);
1806 gtk_theming_engine_render_background (GtkThemingEngine *engine,
1813 GtkJunctionSides junction;
1815 junction = gtk_theming_engine_get_junction_sides (engine);
1817 render_background_internal (engine, cr,
1818 x, y, width, height,
1822 /* Renders the small triangle on corners so
1823 * frames with 0 radius have a 3D-like effect
1826 _cairo_corner_triangle (cairo_t *cr,
1833 cairo_move_to (cr, x + 0.5, y + size - 0.5);
1834 cairo_line_to (cr, x + size - 0.5, y + size - 0.5);
1835 cairo_line_to (cr, x + size - 0.5, y + 0.5);
1837 for (i = 1; i < size - 1; i++)
1839 cairo_move_to (cr, x + size - 0.5, y + i + 0.5);
1840 cairo_line_to (cr, x + (size - i) - 0.5, y + i + 0.5);
1845 gtk_themeing_engine_apply_junction_to_radius (GtkCssBorderRadius *border_radius,
1846 GtkJunctionSides junction)
1848 if (junction & GTK_JUNCTION_CORNER_TOPLEFT)
1849 border_radius->top_left.horizontal = border_radius->top_left.vertical = 0;
1850 if (junction & GTK_JUNCTION_CORNER_TOPRIGHT)
1851 border_radius->top_right.horizontal = border_radius->top_right.vertical = 0;
1852 if (junction & GTK_JUNCTION_CORNER_BOTTOMRIGHT)
1853 border_radius->bottom_right.horizontal = border_radius->bottom_right.vertical = 0;
1854 if (junction & GTK_JUNCTION_CORNER_BOTTOMLEFT)
1855 border_radius->bottom_left.horizontal = border_radius->bottom_left.vertical = 0;
1859 render_frame_internal (GtkThemingEngine *engine,
1866 GtkJunctionSides junction)
1868 GtkStateFlags state;
1870 GdkRGBA border_color;
1871 GtkBorderStyle border_style;
1873 GtkCssBorderCornerRadius *top_left_radius, *top_right_radius;
1874 GtkCssBorderCornerRadius *bottom_left_radius, *bottom_right_radius;
1875 GtkCssBorderRadius border_radius = { { 0, }, };
1876 gdouble progress, d1, d2, m;
1879 gboolean uniform_border;
1881 state = gtk_theming_engine_get_state (engine);
1883 gtk_theming_engine_get_border_color (engine, state, &border_color);
1884 gtk_theming_engine_get_border (engine, state, &border);
1886 gtk_theming_engine_get (engine, state,
1887 "border-style", &border_style,
1888 /* Can't use border-radius as it's an int for
1889 * backwards compat */
1890 "border-top-left-radius", &top_left_radius,
1891 "border-top-right-radius", &top_right_radius,
1892 "border-bottom-right-radius", &bottom_right_radius,
1893 "border-bottom-left-radius", &bottom_left_radius,
1896 if (top_left_radius)
1897 border_radius.top_left = *top_left_radius;
1898 g_free (top_left_radius);
1899 if (top_right_radius)
1900 border_radius.top_right = *top_right_radius;
1901 g_free (top_right_radius);
1902 if (bottom_right_radius)
1903 border_radius.bottom_right = *bottom_right_radius;
1904 g_free (bottom_right_radius);
1905 if (bottom_left_radius)
1906 border_radius.bottom_left = *bottom_left_radius;
1907 g_free (bottom_left_radius);
1909 gtk_themeing_engine_apply_junction_to_radius (&border_radius, junction);
1911 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
1912 border_width = MIN (MIN (border.top, border.bottom),
1913 MIN (border.left, border.right));
1914 uniform_border = (border.top == border.bottom &&
1915 border.top == border.left &&
1916 border.top == border.right);
1920 GtkStateFlags other_state;
1921 GdkRGBA other_color;
1923 if (state & GTK_STATE_FLAG_PRELIGHT)
1925 other_state = state & ~(GTK_STATE_FLAG_PRELIGHT);
1926 progress = 1 - progress;
1929 other_state = state | GTK_STATE_FLAG_PRELIGHT;
1931 gtk_theming_engine_get_border_color (engine, other_state, &other_color);
1933 border_color.red = CLAMP (border_color.red + ((other_color.red - border_color.red) * progress), 0, 1);
1934 border_color.green = CLAMP (border_color.green + ((other_color.green - border_color.green) * progress), 0, 1);
1935 border_color.blue = CLAMP (border_color.blue + ((other_color.blue - border_color.blue) * progress), 0, 1);
1936 border_color.alpha = CLAMP (border_color.alpha + ((other_color.alpha - border_color.alpha) * progress), 0, 1);
1941 color_shade (&border_color, 1.8, &lighter);
1943 switch (border_style)
1945 case GTK_BORDER_STYLE_NONE:
1947 case GTK_BORDER_STYLE_SOLID:
1948 cairo_set_line_width (cr, border_width);
1949 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
1951 gdk_cairo_set_source_rgba (cr, &border_color);
1955 if (border_width > 1)
1957 x += (gdouble) border_width / 2;
1958 y += (gdouble) border_width / 2;
1959 width -= border_width;
1960 height -= border_width;
1962 else if (border_width == 1)
1970 _cairo_round_rectangle_sides (cr, &border_radius,
1971 x, y, width, height,
1972 SIDE_ALL & ~(hidden_side));
1978 _cairo_uneven_frame (cr, &border_radius,
1979 x, y, width, height,
1986 case GTK_BORDER_STYLE_INSET:
1987 case GTK_BORDER_STYLE_OUTSET:
1988 cairo_set_line_width (cr, border_width);
1989 cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
1991 if (border_width > 1)
1993 d1 = (gdouble) border_width / 2;
2004 m = MIN (width, height);
2009 if (border_style == GTK_BORDER_STYLE_INSET)
2010 gdk_cairo_set_source_rgba (cr, &lighter);
2012 gdk_cairo_set_source_rgba (cr, &border_color);
2014 _cairo_round_rectangle_sides (cr, &border_radius,
2016 width - d2, height - d2,
2017 (SIDE_BOTTOM | SIDE_RIGHT) & ~(hidden_side));
2020 if (border_style == GTK_BORDER_STYLE_INSET)
2021 gdk_cairo_set_source_rgba (cr, &border_color);
2023 gdk_cairo_set_source_rgba (cr, &lighter);
2025 _cairo_round_rectangle_sides (cr, &border_radius,
2027 width - d2, height - d2,
2028 (SIDE_TOP | SIDE_LEFT) & ~(hidden_side));
2036 if (border_style == GTK_BORDER_STYLE_INSET)
2037 gdk_cairo_set_source_rgba (cr, &lighter);
2039 gdk_cairo_set_source_rgba (cr, &border_color);
2041 _cairo_uneven_frame (cr, &border_radius,
2042 x, y, width, height,
2047 cairo_move_to (cr, x, y);
2048 cairo_line_to (cr, x + width, y);
2050 x + width - border.right - border_radius.top_right.horizontal / 2,
2051 y + border.top + border_radius.top_right.vertical / 2);
2053 x + width - border.right - border_radius.bottom_right.horizontal / 2,
2054 y + height - border.bottom - border_radius.bottom_right.vertical / 2);
2056 x + border.left + border_radius.bottom_left.horizontal / 2,
2057 y + height - border.bottom - border_radius.bottom_left.vertical / 2);
2058 cairo_line_to (cr, x, y + height);
2059 cairo_close_path (cr);
2063 if (border_style == GTK_BORDER_STYLE_INSET)
2064 gdk_cairo_set_source_rgba (cr, &border_color);
2066 gdk_cairo_set_source_rgba (cr, &lighter);
2068 _cairo_uneven_frame (cr, &border_radius,
2069 x, y, width, height,
2075 if (border_width > 1)
2077 /* overprint top/right and bottom/left corner
2078 * triangles if there are square corners there,
2079 * to give the box a 3D-like appearance.
2083 if (border_style == GTK_BORDER_STYLE_INSET)
2084 gdk_cairo_set_source_rgba (cr, &lighter);
2086 gdk_cairo_set_source_rgba (cr, &border_color);
2088 cairo_set_line_width (cr, 1);
2090 if ((junction & GTK_JUNCTION_CORNER_TOPRIGHT) != 0)
2091 _cairo_corner_triangle (cr,
2092 x + width - border_width, y,
2095 if ((junction & GTK_JUNCTION_CORNER_BOTTOMLEFT) != 0)
2096 _cairo_corner_triangle (cr,
2097 x, y + height - border_width,
2111 gtk_theming_engine_render_frame (GtkThemingEngine *engine,
2118 GtkStateFlags flags;
2119 GtkBorderStyle border_style;
2120 GtkJunctionSides junction;
2121 GtkBorderImage *border_image;
2124 flags = gtk_theming_engine_get_state (engine);
2125 junction = gtk_theming_engine_get_junction_sides (engine);
2126 gtk_theming_engine_get_border (engine, flags, &border);
2128 gtk_theming_engine_get (engine, flags,
2129 "border-image", &border_image,
2130 "border-style", &border_style,
2133 if (border_image != NULL)
2135 _gtk_border_image_render (border_image, &border,
2136 cr, x, y, width, height);
2137 _gtk_border_image_unref (border_image);
2139 else if (border_style != GTK_BORDER_STYLE_NONE)
2140 render_frame_internal (engine, cr,
2141 x, y, width, height,
2146 gtk_theming_engine_render_expander (GtkThemingEngine *engine,
2153 GtkStateFlags flags;
2154 GdkRGBA outline_color, fg_color;
2155 double vertical_overshoot;
2158 double interp; /* interpolation factor for center position */
2159 double x_double_horz, y_double_horz;
2160 double x_double_vert, y_double_vert;
2161 double x_double, y_double;
2164 gboolean running, is_rtl;
2168 flags = gtk_theming_engine_get_state (engine);
2170 gtk_theming_engine_get_color (engine, flags, &fg_color);
2171 gtk_theming_engine_get_border_color (engine, flags, &outline_color);
2173 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress);
2174 is_rtl = (gtk_theming_engine_get_direction (engine) == GTK_TEXT_DIR_RTL);
2178 progress = (flags & GTK_STATE_FLAG_ACTIVE) ? 1 : 0;
2180 if (!gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_HORIZONTAL))
2183 angle = (G_PI) - ((G_PI / 2) * progress);
2185 angle = (G_PI / 2) * progress;
2190 angle = (G_PI / 2) + ((G_PI / 2) * progress);
2192 angle = (G_PI / 2) - ((G_PI / 2) * progress);
2197 /* Compute distance that the stroke extends beyonds the end
2198 * of the triangle we draw.
2200 vertical_overshoot = line_width / 2.0 * (1. / tan (G_PI / 8));
2202 /* For odd line widths, we end the vertical line of the triangle
2203 * at a half pixel, so we round differently.
2205 if (line_width % 2 == 1)
2206 vertical_overshoot = ceil (0.5 + vertical_overshoot) - 0.5;
2208 vertical_overshoot = ceil (vertical_overshoot);
2210 /* Adjust the size of the triangle we draw so that the entire stroke fits
2212 diameter = (gint) MAX (3, width - 2 * vertical_overshoot);
2214 /* If the line width is odd, we want the diameter to be even,
2215 * and vice versa, so force the sum to be odd. This relationship
2216 * makes the point of the triangle look right.
2218 diameter -= (1 - (diameter + line_width) % 2);
2220 radius = diameter / 2.;
2222 /* Adjust the center so that the stroke is properly aligned with
2223 * the pixel grid. The center adjustment is different for the
2224 * horizontal and vertical orientations. For intermediate positions
2225 * we interpolate between the two.
2227 x_double_vert = floor ((x + width / 2) - (radius + line_width) / 2.) + (radius + line_width) / 2.;
2228 y_double_vert = (y + height / 2) - 0.5;
2230 x_double_horz = (x + width / 2) - 0.5;
2231 y_double_horz = floor ((y + height / 2) - (radius + line_width) / 2.) + (radius + line_width) / 2.;
2233 x_double = x_double_vert * (1 - interp) + x_double_horz * interp;
2234 y_double = y_double_vert * (1 - interp) + y_double_horz * interp;
2236 cairo_translate (cr, x_double, y_double);
2237 cairo_rotate (cr, angle);
2239 cairo_move_to (cr, - radius / 2., - radius);
2240 cairo_line_to (cr, radius / 2., 0);
2241 cairo_line_to (cr, - radius / 2., radius);
2242 cairo_close_path (cr);
2244 cairo_set_line_width (cr, line_width);
2246 gdk_cairo_set_source_rgba (cr, &fg_color);
2248 cairo_fill_preserve (cr);
2250 gdk_cairo_set_source_rgba (cr, &outline_color);
2257 gtk_theming_engine_render_focus (GtkThemingEngine *engine,
2264 GtkStateFlags flags;
2270 flags = gtk_theming_engine_get_state (engine);
2272 gtk_theming_engine_get_color (engine, flags, &color);
2274 gtk_theming_engine_get_style (engine,
2275 "focus-line-width", &line_width,
2276 "focus-line-pattern", (gchar *) &dash_list,
2279 cairo_set_line_width (cr, (gdouble) line_width);
2283 gint n_dashes = strlen ((const gchar *) dash_list);
2284 gdouble *dashes = g_new (gdouble, n_dashes);
2285 gdouble total_length = 0;
2286 gdouble dash_offset;
2289 for (i = 0; i < n_dashes; i++)
2291 dashes[i] = dash_list[i];
2292 total_length += dash_list[i];
2295 /* The dash offset here aligns the pattern to integer pixels
2296 * by starting the dash at the right side of the left border
2297 * Negative dash offsets in cairo don't work
2298 * (https://bugs.freedesktop.org/show_bug.cgi?id=2729)
2300 dash_offset = - line_width / 2.;
2302 while (dash_offset < 0)
2303 dash_offset += total_length;
2305 cairo_set_dash (cr, dashes, n_dashes, dash_offset);
2309 cairo_rectangle (cr,
2310 x + line_width / 2.,
2311 y + line_width / 2.,
2313 height - line_width);
2315 gdk_cairo_set_source_rgba (cr, &color);
2324 gtk_theming_engine_render_line (GtkThemingEngine *engine,
2331 GdkRGBA bg_color, darker, lighter;
2332 GtkStateFlags flags;
2333 gint i, thickness, thickness_dark, thickness_light, len;
2334 cairo_matrix_t matrix;
2337 /* FIXME: thickness */
2339 thickness_dark = thickness / 2;
2340 thickness_light = thickness - thickness_dark;
2342 flags = gtk_theming_engine_get_state (engine);
2345 gtk_theming_engine_get_background_color (engine, flags, &bg_color);
2346 color_shade (&bg_color, 0.7, &darker);
2347 color_shade (&bg_color, 1.3, &lighter);
2349 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
2350 cairo_set_line_width (cr, 1);
2352 angle = atan2 (x1 - x0, y1 - y0);
2353 angle = (2 * G_PI) - angle;
2356 cairo_get_matrix (cr, &matrix);
2357 cairo_matrix_translate (&matrix, x0, y0);
2358 cairo_matrix_rotate (&matrix, angle);
2359 cairo_set_matrix (cr, &matrix);
2364 len = (gint) sqrt ((x1 * x1) + (y1 * y1));
2366 y0 = -thickness_dark;
2368 for (i = 0; i < thickness_dark; i++)
2370 gdk_cairo_set_source_rgba (cr, &lighter);
2371 add_path_line (cr, len - i - 1.5, y0, len - 0.5, y0);
2374 gdk_cairo_set_source_rgba (cr, &darker);
2375 add_path_line (cr, 0.5, y0, len - i - 1.5, y0);
2381 for (i = 0; i < thickness_light; i++)
2383 gdk_cairo_set_source_rgba (cr, &darker);
2384 add_path_line (cr, 0.5, y0, thickness_light - i + 0.5, y0);
2387 gdk_cairo_set_source_rgba (cr, &lighter);
2388 add_path_line (cr, thickness_light - i + 0.5, y0, len - 0.5, y0);
2398 prepare_context_for_layout (cairo_t *cr,
2401 PangoLayout *layout)
2403 const PangoMatrix *matrix;
2405 matrix = pango_context_get_matrix (pango_layout_get_context (layout));
2407 cairo_move_to (cr, x, y);
2411 cairo_matrix_t cairo_matrix;
2413 cairo_matrix_init (&cairo_matrix,
2414 matrix->xx, matrix->yx,
2415 matrix->xy, matrix->yy,
2416 matrix->x0, matrix->y0);
2418 cairo_transform (cr, &cairo_matrix);
2423 gtk_theming_engine_render_layout (GtkThemingEngine *engine,
2427 PangoLayout *layout)
2430 GtkShadow *text_shadow = NULL;
2431 GtkStateFlags flags;
2436 flags = gtk_theming_engine_get_state (engine);
2437 gtk_theming_engine_get_color (engine, flags, &fg_color);
2439 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
2443 GtkStateFlags other_flags;
2446 if (flags & GTK_STATE_FLAG_PRELIGHT)
2448 other_flags = flags & ~(GTK_STATE_FLAG_PRELIGHT);
2449 progress = 1 - progress;
2452 other_flags = flags | GTK_STATE_FLAG_PRELIGHT;
2454 gtk_theming_engine_get_color (engine, other_flags, &other_fg);
2456 fg_color.red = CLAMP (fg_color.red + ((other_fg.red - fg_color.red) * progress), 0, 1);
2457 fg_color.green = CLAMP (fg_color.green + ((other_fg.green - fg_color.green) * progress), 0, 1);
2458 fg_color.blue = CLAMP (fg_color.blue + ((other_fg.blue - fg_color.blue) * progress), 0, 1);
2459 fg_color.alpha = CLAMP (fg_color.alpha + ((other_fg.alpha - fg_color.alpha) * progress), 0, 1);
2462 gtk_theming_engine_get (engine, flags,
2463 "text-shadow", &text_shadow,
2466 prepare_context_for_layout (cr, x, y, layout);
2468 if (text_shadow != NULL)
2470 _gtk_text_shadow_paint_layout (text_shadow, cr, layout);
2471 _gtk_shadow_unref (text_shadow);
2474 gdk_cairo_set_source_rgba (cr, &fg_color);
2475 pango_cairo_show_layout (cr, layout);
2481 gtk_theming_engine_render_slider (GtkThemingEngine *engine,
2487 GtkOrientation orientation)
2489 const GtkWidgetPath *path;
2492 path = gtk_theming_engine_get_path (engine);
2494 gtk_theming_engine_render_background (engine, cr, x, y, width, height);
2495 gtk_theming_engine_render_frame (engine, cr, x, y, width, height);
2497 /* FIXME: thickness */
2500 if (gtk_widget_path_is_type (path, GTK_TYPE_SCALE))
2502 if (orientation == GTK_ORIENTATION_VERTICAL)
2503 gtk_theming_engine_render_line (engine, cr,
2505 y + (gint) height / 2,
2506 x + width - thickness - 1,
2507 y + (gint) height / 2);
2509 gtk_theming_engine_render_line (engine, cr,
2510 x + (gint) width / 2,
2512 x + (gint) width / 2,
2513 y + height - thickness - 1);
2518 gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
2524 GtkPositionType gap_side,
2528 GtkJunctionSides junction;
2529 GtkStateFlags state;
2531 GtkCssBorderCornerRadius *top_left_radius, *top_right_radius;
2532 GtkCssBorderCornerRadius *bottom_left_radius, *bottom_right_radius;
2533 GtkCssBorderRadius border_radius = { { 0, }, };
2534 gdouble x0, y0, x1, y1, xc, yc, wc, hc;
2537 xc = yc = wc = hc = 0;
2538 state = gtk_theming_engine_get_state (engine);
2539 junction = gtk_theming_engine_get_junction_sides (engine);
2541 gtk_theming_engine_get_border (engine, state, &border);
2542 gtk_theming_engine_get (engine, state,
2543 /* Can't use border-radius as it's an int for
2544 * backwards compat */
2545 "border-top-left-radius", &top_left_radius,
2546 "border-top-right-radius", &top_right_radius,
2547 "border-bottom-right-radius", &bottom_right_radius,
2548 "border-bottom-left-radius", &bottom_left_radius,
2551 if (top_left_radius)
2552 border_radius.top_left = *top_left_radius;
2553 g_free (top_left_radius);
2554 if (top_right_radius)
2555 border_radius.top_right = *top_right_radius;
2556 g_free (top_right_radius);
2557 if (bottom_right_radius)
2558 border_radius.bottom_right = *bottom_right_radius;
2559 g_free (bottom_right_radius);
2560 if (bottom_left_radius)
2561 border_radius.bottom_left = *bottom_left_radius;
2562 g_free (bottom_left_radius);
2564 border_width = MIN (MIN (border.top, border.bottom),
2565 MIN (border.left, border.right));
2572 xc = x + xy0_gap + border_width;
2574 wc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
2577 if (xy0_gap < border_radius.top_left.horizontal)
2578 junction |= GTK_JUNCTION_CORNER_TOPLEFT;
2580 if (xy1_gap > width - border_radius.top_right.horizontal)
2581 junction |= GTK_JUNCTION_CORNER_TOPRIGHT;
2583 case GTK_POS_BOTTOM:
2584 xc = x + xy0_gap + border_width;
2585 yc = y + height - border_width;
2586 wc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
2589 if (xy0_gap < border_radius.bottom_left.horizontal)
2590 junction |= GTK_JUNCTION_CORNER_BOTTOMLEFT;
2592 if (xy1_gap > width - border_radius.bottom_right.horizontal)
2593 junction |= GTK_JUNCTION_CORNER_BOTTOMRIGHT;
2598 yc = y + xy0_gap + border_width;
2600 hc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
2602 if (xy0_gap < border_radius.top_left.vertical)
2603 junction |= GTK_JUNCTION_CORNER_TOPLEFT;
2605 if (xy1_gap > height - border_radius.bottom_left.vertical)
2606 junction |= GTK_JUNCTION_CORNER_BOTTOMLEFT;
2610 xc = x + width - border_width;
2611 yc = y + xy0_gap + border_width;
2613 hc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
2615 if (xy0_gap < border_radius.top_right.vertical)
2616 junction |= GTK_JUNCTION_CORNER_TOPRIGHT;
2618 if (xy1_gap > height - border_radius.bottom_right.vertical)
2619 junction |= GTK_JUNCTION_CORNER_BOTTOMRIGHT;
2624 cairo_clip_extents (cr, &x0, &y0, &x1, &y1);
2625 cairo_rectangle (cr, x0, y0, x1 - x0, yc - y0);
2626 cairo_rectangle (cr, x0, yc, xc - x0, hc);
2627 cairo_rectangle (cr, xc + wc, yc, x1 - (xc + wc), hc);
2628 cairo_rectangle (cr, x0, yc + hc, x1 - x0, y1 - (yc + hc));
2631 render_frame_internal (engine, cr,
2632 x, y, width, height,
2639 gtk_theming_engine_render_extension (GtkThemingEngine *engine,
2645 GtkPositionType gap_side)
2647 GtkJunctionSides junction = 0;
2648 guint hidden_side = 0;
2655 junction = GTK_JUNCTION_LEFT;
2656 hidden_side = SIDE_LEFT;
2658 cairo_translate (cr, x + width, y);
2659 cairo_rotate (cr, G_PI / 2);
2662 junction = GTK_JUNCTION_RIGHT;
2663 hidden_side = SIDE_RIGHT;
2665 cairo_translate (cr, x, y + height);
2666 cairo_rotate (cr, - G_PI / 2);
2669 junction = GTK_JUNCTION_TOP;
2670 hidden_side = SIDE_TOP;
2672 cairo_translate (cr, x + width, y + height);
2673 cairo_rotate (cr, G_PI);
2675 case GTK_POS_BOTTOM:
2676 junction = GTK_JUNCTION_BOTTOM;
2677 hidden_side = SIDE_BOTTOM;
2679 cairo_translate (cr, x, y);
2683 if (gap_side == GTK_POS_TOP ||
2684 gap_side == GTK_POS_BOTTOM)
2685 render_background_internal (engine, cr,
2686 0, 0, width, height,
2687 GTK_JUNCTION_BOTTOM);
2689 render_background_internal (engine, cr,
2690 0, 0, height, width,
2691 GTK_JUNCTION_BOTTOM);
2696 render_frame_internal (engine, cr,
2697 x, y, width, height,
2698 hidden_side, junction);
2704 render_dot (cairo_t *cr,
2705 const GdkRGBA *lighter,
2706 const GdkRGBA *darker,
2711 size = CLAMP ((gint) size, 2, 3);
2715 gdk_cairo_set_source_rgba (cr, lighter);
2716 cairo_rectangle (cr, x, y, 1, 1);
2717 cairo_rectangle (cr, x + 1, y + 1, 1, 1);
2722 gdk_cairo_set_source_rgba (cr, lighter);
2723 cairo_rectangle (cr, x, y, 2, 1);
2724 cairo_rectangle (cr, x, y, 1, 2);
2727 gdk_cairo_set_source_rgba (cr, darker);
2728 cairo_rectangle (cr, x + 1, y + 1, 2, 1);
2729 cairo_rectangle (cr, x + 2, y, 1, 2);
2735 gtk_theming_engine_render_handle (GtkThemingEngine *engine,
2742 GtkStateFlags flags;
2743 GdkRGBA bg_color, lighter, darker;
2744 GtkJunctionSides sides;
2748 flags = gtk_theming_engine_get_state (engine);
2750 cairo_set_line_width (cr, 1.0);
2751 sides = gtk_theming_engine_get_junction_sides (engine);
2752 gtk_theming_engine_get_background_color (engine, flags, &bg_color);
2754 color_shade (&bg_color, 0.7, &darker);
2755 color_shade (&bg_color, 1.3, &lighter);
2757 render_background_internal (engine, cr, x, y, width, height, sides);
2759 if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_GRIP))
2761 /* reduce confusing values to a meaningful state */
2762 if ((sides & (GTK_JUNCTION_CORNER_TOPLEFT | GTK_JUNCTION_CORNER_BOTTOMRIGHT)) == (GTK_JUNCTION_CORNER_TOPLEFT | GTK_JUNCTION_CORNER_BOTTOMRIGHT))
2763 sides &= ~GTK_JUNCTION_CORNER_TOPLEFT;
2765 if ((sides & (GTK_JUNCTION_CORNER_TOPRIGHT | GTK_JUNCTION_CORNER_BOTTOMLEFT)) == (GTK_JUNCTION_CORNER_TOPRIGHT | GTK_JUNCTION_CORNER_BOTTOMLEFT))
2766 sides &= ~GTK_JUNCTION_CORNER_TOPRIGHT;
2769 sides = GTK_JUNCTION_CORNER_BOTTOMRIGHT;
2771 /* align drawing area to the connected side */
2772 if (sides == GTK_JUNCTION_LEFT)
2777 else if (sides == GTK_JUNCTION_CORNER_TOPLEFT)
2781 else if (height < width)
2784 else if (sides == GTK_JUNCTION_CORNER_BOTTOMLEFT)
2786 /* make it square, aligning to bottom left */
2789 y += (height - width);
2792 else if (height < width)
2795 else if (sides == GTK_JUNCTION_RIGHT)
2797 /* aligning to right */
2800 x += (width - height);
2804 else if (sides == GTK_JUNCTION_CORNER_TOPRIGHT)
2808 else if (height < width)
2810 x += (width - height);
2814 else if (sides == GTK_JUNCTION_CORNER_BOTTOMRIGHT)
2816 /* make it square, aligning to bottom right */
2819 y += (height - width);
2822 else if (height < width)
2824 x += (width - height);
2828 else if (sides == GTK_JUNCTION_TOP)
2833 else if (sides == GTK_JUNCTION_BOTTOM)
2835 /* align to bottom */
2838 y += (height - width);
2843 g_assert_not_reached ();
2845 if (sides == GTK_JUNCTION_LEFT ||
2846 sides == GTK_JUNCTION_RIGHT)
2852 while (xi < x + width)
2854 gdk_cairo_set_source_rgba (cr, &lighter);
2855 add_path_line (cr, x, y, x, y + height);
2859 gdk_cairo_set_source_rgba (cr, &darker);
2860 add_path_line (cr, xi, y, xi, y + height);
2865 else if (sides == GTK_JUNCTION_TOP ||
2866 sides == GTK_JUNCTION_BOTTOM)
2872 while (yi < y + height)
2874 gdk_cairo_set_source_rgba (cr, &lighter);
2875 add_path_line (cr, x, yi, x + width, yi);
2879 gdk_cairo_set_source_rgba (cr, &darker);
2880 add_path_line (cr, x, yi, x + width, yi);
2885 else if (sides == GTK_JUNCTION_CORNER_TOPLEFT)
2894 gdk_cairo_set_source_rgba (cr, &darker);
2895 add_path_line (cr, xi, y, x, yi);
2901 add_path_line (cr, xi, y, x, yi);
2907 gdk_cairo_set_source_rgba (cr, &lighter);
2908 add_path_line (cr, xi, y, x, yi);
2915 else if (sides == GTK_JUNCTION_CORNER_TOPRIGHT)
2922 while (xi < (x + width - 3))
2924 gdk_cairo_set_source_rgba (cr, &lighter);
2925 add_path_line (cr, xi, y, x + width, yi);
2931 gdk_cairo_set_source_rgba (cr, &darker);
2932 add_path_line (cr, xi, y, x + width, yi);
2938 add_path_line (cr, xi, y, x + width, yi);
2945 else if (sides == GTK_JUNCTION_CORNER_BOTTOMLEFT)
2954 gdk_cairo_set_source_rgba (cr, &darker);
2955 add_path_line (cr, x, yi, xi, y + height);
2961 add_path_line (cr, x, yi, xi, y + height);
2967 gdk_cairo_set_source_rgba (cr, &lighter);
2968 add_path_line (cr, x, yi, xi, y + height);
2975 else if (sides == GTK_JUNCTION_CORNER_BOTTOMRIGHT)
2982 while (xi < (x + width - 3))
2984 gdk_cairo_set_source_rgba (cr, &lighter);
2985 add_path_line (cr, xi, y + height, x + width, yi);
2991 gdk_cairo_set_source_rgba (cr, &darker);
2992 add_path_line (cr, xi, y + height, x + width, yi);
2998 add_path_line (cr, xi, y + height, x + width, yi);
3006 else if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_PANE_SEPARATOR))
3009 for (xx = x + width / 2 - 15; xx <= x + width / 2 + 15; xx += 5)
3010 render_dot (cr, &lighter, &darker, xx, y + height / 2 - 1, 3);
3012 for (yy = y + height / 2 - 15; yy <= y + height / 2 + 15; yy += 5)
3013 render_dot (cr, &lighter, &darker, x + width / 2 - 1, yy, 3);
3017 for (yy = y; yy < y + height; yy += 3)
3018 for (xx = x; xx < x + width; xx += 6)
3020 render_dot (cr, &lighter, &darker, xx, yy, 2);
3021 render_dot (cr, &lighter, &darker, xx + 3, yy + 1, 2);
3029 gtk_theming_engine_render_activity (GtkThemingEngine *engine,
3036 if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_SPINNER))
3038 GtkStateFlags state;
3039 guint num_steps, step;
3048 state = gtk_theming_engine_get_state (engine);
3049 gtk_theming_engine_get_color (engine, state, &color);
3051 if (gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress))
3052 step = (guint) (progress * num_steps);
3058 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
3059 cairo_set_line_width (cr, 2.0);
3060 cairo_translate (cr, x + width / 2, y + height / 2);
3062 radius = MIN (width / 2, height / 2);
3063 half = num_steps / 2;
3065 for (i = 0; i < num_steps; i++)
3067 gint inset = 0.7 * radius;
3069 /* transparency is a function of time and intial value */
3070 gdouble t = 1.0 - (gdouble) ((i + step) % num_steps) / num_steps;
3071 gdouble xscale = - sin (i * G_PI / half);
3072 gdouble yscale = - cos (i * G_PI / half);
3074 cairo_set_source_rgba (cr,
3081 (radius - inset) * xscale,
3082 (radius - inset) * yscale);
3093 gtk_theming_engine_render_background (engine, cr, x, y, width, height);
3094 gtk_theming_engine_render_frame (engine, cr, x, y, width, height);
3099 scale_or_ref (GdkPixbuf *src,
3103 if (width == gdk_pixbuf_get_width (src) &&
3104 height == gdk_pixbuf_get_height (src))
3105 return g_object_ref (src);
3107 return gdk_pixbuf_scale_simple (src,
3109 GDK_INTERP_BILINEAR);
3113 lookup_icon_size (GtkThemingEngine *engine,
3119 GtkSettings *settings;
3121 screen = gtk_theming_engine_get_screen (engine);
3122 settings = gtk_settings_get_for_screen (screen);
3124 return gtk_icon_size_lookup_for_settings (settings, size, width, height);
3127 /* Kudos to the gnome-panel guys. */
3129 colorshift_pixbuf (GdkPixbuf *src,
3134 gint width, height, has_alpha, src_rowstride, dest_rowstride;
3135 guchar *target_pixels;
3136 guchar *original_pixels;
3142 has_alpha = gdk_pixbuf_get_has_alpha (src);
3143 width = gdk_pixbuf_get_width (src);
3144 height = gdk_pixbuf_get_height (src);
3145 src_rowstride = gdk_pixbuf_get_rowstride (src);
3146 dest_rowstride = gdk_pixbuf_get_rowstride (dest);
3147 original_pixels = gdk_pixbuf_get_pixels (src);
3148 target_pixels = gdk_pixbuf_get_pixels (dest);
3150 for (i = 0; i < height; i++)
3152 pix_dest = target_pixels + i * dest_rowstride;
3153 pix_src = original_pixels + i * src_rowstride;
3155 for (j = 0; j < width; j++)
3162 *(pix_dest++) = CLAMP (val, 0, 255);
3165 *(pix_dest++) = CLAMP (val, 0, 255);
3168 *(pix_dest++) = CLAMP (val, 0, 255);
3171 *(pix_dest++) = *(pix_src++);
3177 gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine *engine,
3178 const GtkIconSource *source,
3183 GdkPixbuf *base_pixbuf;
3184 GtkStateFlags state;
3188 base_pixbuf = gtk_icon_source_get_pixbuf (source);
3189 state = gtk_theming_engine_get_state (engine);
3191 g_return_val_if_fail (base_pixbuf != NULL, NULL);
3193 if (size != (GtkIconSize) -1 &&
3194 !lookup_icon_size (engine, size, &width, &height))
3196 g_warning (G_STRLOC ": invalid icon size '%d'", size);
3200 /* If the size was wildcarded, and we're allowed to scale, then scale; otherwise,
3203 if (size != (GtkIconSize) -1 &&
3204 gtk_icon_source_get_size_wildcarded (source))
3205 scaled = scale_or_ref (base_pixbuf, width, height);
3207 scaled = g_object_ref (base_pixbuf);
3209 /* If the state was wildcarded, then generate a state. */
3210 if (gtk_icon_source_get_state_wildcarded (source))
3212 if (state & GTK_STATE_FLAG_INSENSITIVE)
3214 stated = gdk_pixbuf_copy (scaled);
3215 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
3217 g_object_unref (scaled);
3219 else if (state & GTK_STATE_FLAG_PRELIGHT)
3221 stated = gdk_pixbuf_copy (scaled);
3222 colorshift_pixbuf (scaled, stated, 30);
3223 g_object_unref (scaled);