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"
34 #include "gtkthemingengineprivate.h"
37 * SECTION:gtkthemingengine
38 * @Short_description: Theming renderers
39 * @Title: GtkThemingEngine
40 * @See_also: #GtkStyleContext
42 * #GtkThemingEngine is the object used for rendering themed content
43 * in GTK+ widgets. Even though GTK+ has a default implementation,
44 * it can be overridden in CSS files by enforcing a #GtkThemingEngine
45 * object to be loaded as a module.
47 * In order to implement a theming engine, a #GtkThemingEngine subclass
48 * must be created, alongside the CSS file that will reference it, the
49 * theming engine would be created as an .so library, and installed in
50 * $(gtk-modules-dir)/theming-engines/.
52 * #GtkThemingEngine<!-- -->s have limited access to the object they are
53 * rendering, the #GtkThemingEngine API has read-only accessors to the
54 * style information contained in the rendered object's #GtkStyleContext.
57 typedef struct GtkThemingEnginePrivate GtkThemingEnginePrivate;
72 struct GtkThemingEnginePrivate
74 GtkStyleContext *context;
78 #define GTK_THEMING_ENGINE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_THEMING_ENGINE, GtkThemingEnginePrivate))
80 static void gtk_theming_engine_finalize (GObject *object);
81 static void gtk_theming_engine_impl_set_property (GObject *object,
85 static void gtk_theming_engine_impl_get_property (GObject *object,
90 static void gtk_theming_engine_render_check (GtkThemingEngine *engine,
96 static void gtk_theming_engine_render_option (GtkThemingEngine *engine,
102 static void gtk_theming_engine_render_arrow (GtkThemingEngine *engine,
108 static void gtk_theming_engine_render_background (GtkThemingEngine *engine,
114 static void gtk_theming_engine_render_frame (GtkThemingEngine *engine,
120 static void gtk_theming_engine_render_expander (GtkThemingEngine *engine,
126 static void gtk_theming_engine_render_focus (GtkThemingEngine *engine,
132 static void gtk_theming_engine_render_layout (GtkThemingEngine *engine,
136 PangoLayout *layout);
137 static void gtk_theming_engine_render_line (GtkThemingEngine *engine,
143 static void gtk_theming_engine_render_slider (GtkThemingEngine *engine,
149 GtkOrientation orientation);
150 static void gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
156 GtkPositionType gap_side,
159 static void gtk_theming_engine_render_extension (GtkThemingEngine *engine,
165 GtkPositionType gap_side);
166 static void gtk_theming_engine_render_handle (GtkThemingEngine *engine,
172 static void gtk_theming_engine_render_activity (GtkThemingEngine *engine,
178 static GdkPixbuf * gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine *engine,
179 const GtkIconSource *source,
181 static void gtk_theming_engine_render_icon (GtkThemingEngine *engine,
187 G_DEFINE_TYPE (GtkThemingEngine, gtk_theming_engine, G_TYPE_OBJECT)
190 typedef struct GtkThemingModule GtkThemingModule;
191 typedef struct GtkThemingModuleClass GtkThemingModuleClass;
193 struct GtkThemingModule
195 GTypeModule parent_instance;
199 void (*init) (GTypeModule *module);
201 GtkThemingEngine * (*create_engine) (void);
204 struct GtkThemingModuleClass
206 GTypeModuleClass parent_class;
209 #define GTK_TYPE_THEMING_MODULE (gtk_theming_module_get_type ())
210 #define GTK_THEMING_MODULE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_THEMING_MODULE, GtkThemingModule))
211 #define GTK_IS_THEMING_MODULE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_THEMING_MODULE))
213 G_DEFINE_TYPE (GtkThemingModule, gtk_theming_module, G_TYPE_TYPE_MODULE);
216 gtk_theming_engine_class_init (GtkThemingEngineClass *klass)
218 GObjectClass *object_class = G_OBJECT_CLASS (klass);
220 object_class->finalize = gtk_theming_engine_finalize;
221 object_class->set_property = gtk_theming_engine_impl_set_property;
222 object_class->get_property = gtk_theming_engine_impl_get_property;
224 klass->render_icon = gtk_theming_engine_render_icon;
225 klass->render_check = gtk_theming_engine_render_check;
226 klass->render_option = gtk_theming_engine_render_option;
227 klass->render_arrow = gtk_theming_engine_render_arrow;
228 klass->render_background = gtk_theming_engine_render_background;
229 klass->render_frame = gtk_theming_engine_render_frame;
230 klass->render_expander = gtk_theming_engine_render_expander;
231 klass->render_focus = gtk_theming_engine_render_focus;
232 klass->render_layout = gtk_theming_engine_render_layout;
233 klass->render_line = gtk_theming_engine_render_line;
234 klass->render_slider = gtk_theming_engine_render_slider;
235 klass->render_frame_gap = gtk_theming_engine_render_frame_gap;
236 klass->render_extension = gtk_theming_engine_render_extension;
237 klass->render_handle = gtk_theming_engine_render_handle;
238 klass->render_activity = gtk_theming_engine_render_activity;
239 klass->render_icon_pixbuf = gtk_theming_engine_render_icon_pixbuf;
242 * GtkThemingEngine:name:
244 * The theming engine name, this name will be used when registering
245 * custom properties, for a theming engine named "Clearlooks" registering
246 * a "glossy" custom property, it could be referenced in the CSS file as
249 * -Clearlooks-glossy: true;
254 g_object_class_install_property (object_class,
256 g_param_spec_string ("name",
258 P_("Theming engine name"),
260 G_PARAM_CONSTRUCT_ONLY | GTK_PARAM_READWRITE));
262 g_type_class_add_private (object_class, sizeof (GtkThemingEnginePrivate));
266 gtk_theming_engine_init (GtkThemingEngine *engine)
268 engine->priv = GTK_THEMING_ENGINE_GET_PRIVATE (engine);
272 gtk_theming_engine_finalize (GObject *object)
274 GtkThemingEnginePrivate *priv;
276 priv = GTK_THEMING_ENGINE (object)->priv;
279 G_OBJECT_GET_CLASS (gtk_theming_engine_parent_class)->finalize (object);
283 gtk_theming_engine_impl_set_property (GObject *object,
288 GtkThemingEnginePrivate *priv;
290 priv = GTK_THEMING_ENGINE (object)->priv;
298 priv->name = g_value_dup_string (value);
301 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
307 gtk_theming_engine_impl_get_property (GObject *object,
312 GtkThemingEnginePrivate *priv;
314 priv = GTK_THEMING_ENGINE (object)->priv;
319 g_value_set_string (value, priv->name);
322 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
328 _gtk_theming_engine_set_context (GtkThemingEngine *engine,
329 GtkStyleContext *context)
331 GtkThemingEnginePrivate *priv;
333 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
334 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
337 priv->context = context;
341 * gtk_theming_engine_register_property: (skip)
342 * @name_space: namespace for the property name
343 * @parse_func: parsing function to use, or %NULL
344 * @pspec: the #GParamSpec for the new property
346 * Registers a property so it can be used in the CSS file format,
347 * on the CSS file the property will look like
348 * "-${@name_space}-${property_name}". being
349 * ${property_name} the given to @pspec. @name_space will usually
350 * be the theme engine name.
352 * For any type a @parse_func may be provided, being this function
353 * used for turning any property value (between ':' and ';') in
354 * CSS to the #GValue needed. For basic types there is already
355 * builtin parsing support, so %NULL may be provided for these
359 * Engines must ensure property registration happens exactly once,
360 * usually GTK+ deals with theming engines as singletons, so this
361 * should be guaranteed to happen once, but bear this in mind
362 * when creating #GtkThemeEngine<!-- -->s yourself.
366 * In order to make use of the custom registered properties in
367 * the CSS file, make sure the engine is loaded first by specifying
368 * the engine property, either in a previous rule or within the same
372 * engine: someengine;
373 * -SomeEngine-custom-property: 2;
381 gtk_theming_engine_register_property (const gchar *name_space,
382 GtkStylePropertyParser parse_func,
387 g_return_if_fail (name_space != NULL);
388 g_return_if_fail (strchr (name_space, ' ') == NULL);
389 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
391 /* FIXME: hack hack hack, replacing pspec->name to include namespace */
392 name = g_strdup_printf ("-%s-%s", name_space, pspec->name);
393 g_free (pspec->name);
396 gtk_style_properties_register_property (parse_func, pspec);
400 * gtk_theming_engine_get_property:
401 * @engine: a #GtkThemingEngine
402 * @property: the property name
403 * @state: state to retrieve the value for
404 * @value: (out) (transfer full): return location for the property value,
405 * you must free this memory using g_value_unset() once you are
408 * Gets a property value as retrieved from the style settings that apply
409 * to the currently rendered element.
414 gtk_theming_engine_get_property (GtkThemingEngine *engine,
415 const gchar *property,
419 GtkThemingEnginePrivate *priv;
421 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
422 g_return_if_fail (property != NULL);
423 g_return_if_fail (value != NULL);
426 gtk_style_context_get_property (priv->context, property, state, value);
430 * gtk_theming_engine_get_valist:
431 * @engine: a #GtkThemingEngine
432 * @state: state to retrieve values for
433 * @args: va_list of property name/return location pairs, followed by %NULL
435 * Retrieves several style property values that apply to the currently
441 gtk_theming_engine_get_valist (GtkThemingEngine *engine,
445 GtkThemingEnginePrivate *priv;
447 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
450 gtk_style_context_get_valist (priv->context, state, args);
454 * gtk_theming_engine_get:
455 * @engine: a #GtkThemingEngine
456 * @state: state to retrieve values for
457 * @...: property name /return value pairs, followed by %NULL
459 * Retrieves several style property values that apply to the currently
465 gtk_theming_engine_get (GtkThemingEngine *engine,
469 GtkThemingEnginePrivate *priv;
472 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
476 va_start (args, state);
477 gtk_style_context_get_valist (priv->context, state, args);
482 * gtk_theming_engine_get_style_property:
483 * @engine: a #GtkThemingEngine
484 * @property_name: the name of the widget style property
485 * @value: Return location for the property value, free with
486 * g_value_unset() after use.
488 * Gets the value for a widget style property.
493 gtk_theming_engine_get_style_property (GtkThemingEngine *engine,
494 const gchar *property_name,
497 GtkThemingEnginePrivate *priv;
499 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
500 g_return_if_fail (property_name != NULL);
503 gtk_style_context_get_style_property (priv->context, property_name, value);
507 * gtk_theming_engine_get_style_valist:
508 * @engine: a #GtkThemingEngine
509 * @args: va_list of property name/return location pairs, followed by %NULL
511 * Retrieves several widget style properties from @engine according to the
512 * currently rendered content's style.
517 gtk_theming_engine_get_style_valist (GtkThemingEngine *engine,
520 GtkThemingEnginePrivate *priv;
522 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
525 gtk_style_context_get_style_valist (priv->context, args);
529 * gtk_theming_engine_get_style:
530 * @engine: a #GtkThemingEngine
531 * @...: property name /return value pairs, followed by %NULL
533 * Retrieves several widget style properties from @engine according
534 * to the currently rendered content's style.
539 gtk_theming_engine_get_style (GtkThemingEngine *engine,
542 GtkThemingEnginePrivate *priv;
545 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
549 va_start (args, engine);
550 gtk_style_context_get_style_valist (priv->context, args);
555 * gtk_theming_engine_lookup_color:
556 * @engine: a #GtkThemingEngine
557 * @color_name: color name to lookup
558 * @color: (out): Return location for the looked up color
560 * Looks up and resolves a color name in the current style's color map.
562 * Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
565 gtk_theming_engine_lookup_color (GtkThemingEngine *engine,
566 const gchar *color_name,
569 GtkThemingEnginePrivate *priv;
571 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
572 g_return_val_if_fail (color_name != NULL, FALSE);
575 return gtk_style_context_lookup_color (priv->context, color_name, color);
579 * gtk_theming_engine_get_state:
580 * @engine: a #GtkThemingEngine
582 * returns the state used when rendering.
584 * Returns: the state flags
589 gtk_theming_engine_get_state (GtkThemingEngine *engine)
591 GtkThemingEnginePrivate *priv;
593 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), 0);
596 return gtk_style_context_get_state (priv->context);
600 * gtk_theming_engine_state_is_running:
601 * @engine: a #GtkThemingEngine
602 * @state: a widget state
603 * @progress: (out): return location for the transition progress
605 * Returns %TRUE if there is a transition animation running for the
606 * current region (see gtk_style_context_push_animatable_region()).
608 * If @progress is not %NULL, the animation progress will be returned
609 * there, 0.0 means the state is closest to being %FALSE, while 1.0 means
610 * it's closest to being %TRUE. This means transition animations will
611 * run from 0 to 1 when @state is being set to %TRUE and from 1 to 0 when
612 * it's being set to %FALSE.
614 * Returns: %TRUE if there is a running transition animation for @state.
619 gtk_theming_engine_state_is_running (GtkThemingEngine *engine,
623 GtkThemingEnginePrivate *priv;
625 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
628 return gtk_style_context_state_is_running (priv->context, state, progress);
632 * gtk_theming_engine_get_path:
633 * @engine: a #GtkThemingEngine
635 * Returns the widget path used for style matching.
637 * Returns: (transfer none): A #GtkWidgetPath
641 G_CONST_RETURN GtkWidgetPath *
642 gtk_theming_engine_get_path (GtkThemingEngine *engine)
644 GtkThemingEnginePrivate *priv;
646 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
649 return gtk_style_context_get_path (priv->context);
653 * gtk_theming_engine_has_class:
654 * @engine: a #GtkThemingEngine
655 * @style_class: class name to look up
657 * Returns %TRUE if the currently rendered contents have
658 * defined the given class name.
660 * Returns: %TRUE if @engine has @class_name defined
665 gtk_theming_engine_has_class (GtkThemingEngine *engine,
666 const gchar *style_class)
668 GtkThemingEnginePrivate *priv;
670 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
673 return gtk_style_context_has_class (priv->context, style_class);
677 * gtk_theming_engine_has_region:
678 * @engine: a #GtkThemingEngine
679 * @style_region: a region name
680 * @flags: (out) (allow-none): return location for region flags
682 * Returns %TRUE if the currently rendered contents have the
683 * region defined. If @flags_return is not %NULL, it is set
684 * to the flags affecting the region.
686 * Returns: %TRUE if region is defined
691 gtk_theming_engine_has_region (GtkThemingEngine *engine,
692 const gchar *style_region,
693 GtkRegionFlags *flags)
695 GtkThemingEnginePrivate *priv;
700 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
703 return gtk_style_context_has_region (priv->context, style_region, flags);
707 * gtk_theming_engine_get_direction:
708 * @engine: a #GtkThemingEngine
710 * Returns the widget direction used for rendering.
712 * Returns: the widget direction
717 gtk_theming_engine_get_direction (GtkThemingEngine *engine)
719 GtkThemingEnginePrivate *priv;
721 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), GTK_TEXT_DIR_LTR);
724 return gtk_style_context_get_direction (priv->context);
728 * gtk_theming_engine_get_junction_sides:
729 * @engine: a #GtkThemingEngine
731 * Returns the widget direction used for rendering.
733 * Returns: the widget direction
738 gtk_theming_engine_get_junction_sides (GtkThemingEngine *engine)
740 GtkThemingEnginePrivate *priv;
742 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), 0);
745 return gtk_style_context_get_junction_sides (priv->context);
749 * gtk_theming_engine_get_color:
750 * @engine: a #GtkThemingEngine
751 * @state: state to retrieve the color for
752 * @color: (out): return value for the foreground color
754 * Gets the foreground color for a given state.
759 gtk_theming_engine_get_color (GtkThemingEngine *engine,
763 GtkThemingEnginePrivate *priv;
765 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
768 gtk_style_context_get_color (priv->context, state, color);
772 * gtk_theming_engine_get_background_color:
773 * @engine: a #GtkThemingEngine
774 * @state: state to retrieve the color for
775 * @color: (out): return value for the background color
777 * Gets the background color for a given state.
782 gtk_theming_engine_get_background_color (GtkThemingEngine *engine,
786 GtkThemingEnginePrivate *priv;
788 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
791 gtk_style_context_get_background_color (priv->context, state, color);
795 * gtk_theming_engine_get_border_color:
796 * @engine: a #GtkThemingEngine
797 * @state: state to retrieve the color for
798 * @color: (out): return value for the border color
800 * Gets the border color for a given state.
805 gtk_theming_engine_get_border_color (GtkThemingEngine *engine,
809 GtkThemingEnginePrivate *priv;
811 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
814 gtk_style_context_get_border_color (priv->context, state, color);
818 * gtk_theming_engine_get_border:
819 * @engine: a #GtkthemingEngine
820 * @state: state to retrieve the border for
821 * @border: (out): return value for the border settings
823 * Gets the border for a given state as a #GtkBorder.
828 gtk_theming_engine_get_border (GtkThemingEngine *engine,
832 GtkThemingEnginePrivate *priv;
834 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
837 gtk_style_context_get_border (priv->context, state, border);
841 * gtk_theming_engine_get_padding:
842 * @engine: a #GtkthemingEngine
843 * @state: state to retrieve the padding for
844 * @padding: (out): return value for the padding settings
846 * Gets the padding for a given state as a #GtkBorder.
851 gtk_theming_engine_get_padding (GtkThemingEngine *engine,
855 GtkThemingEnginePrivate *priv;
857 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
860 gtk_style_context_get_padding (priv->context, state, padding);
864 * gtk_theming_engine_get_margin:
865 * @engine: a #GtkThemingEngine
866 * @state: state to retrieve the border for
867 * @margin: (out): return value for the margin settings
869 * Gets the margin for a given state as a #GtkBorder.
874 gtk_theming_engine_get_margin (GtkThemingEngine *engine,
878 GtkThemingEnginePrivate *priv;
880 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
883 gtk_style_context_get_margin (priv->context, state, margin);
887 * gtk_theming_engine_get_font:
888 * @engine: a #GtkThemingEngine
889 * @state: state to retrieve the font for
891 * Returns the font description for a given state.
893 * Returns: (transfer none): the #PangoFontDescription for the given
894 * state. This object is owned by GTK+ and should not be
899 const PangoFontDescription *
900 gtk_theming_engine_get_font (GtkThemingEngine *engine,
903 GtkThemingEnginePrivate *priv;
905 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
908 return gtk_style_context_get_font (priv->context, state);
911 /* GtkThemingModule */
914 gtk_theming_module_load (GTypeModule *type_module)
916 GtkThemingModule *theming_module;
918 gchar *name, *module_path;
920 theming_module = GTK_THEMING_MODULE (type_module);
921 name = theming_module->name;
922 module_path = _gtk_find_module (name, "theming-engines");
927 module = g_module_open (module_path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
928 g_free (module_path);
933 if (!g_module_symbol (module, "theme_init",
934 (gpointer *) &theming_module->init) ||
935 !g_module_symbol (module, "theme_exit",
936 (gpointer *) &theming_module->exit) ||
937 !g_module_symbol (module, "create_engine",
938 (gpointer *) &theming_module->create_engine))
940 g_module_close (module);
945 theming_module->module = module;
947 theming_module->init (G_TYPE_MODULE (theming_module));
953 gtk_theming_module_unload (GTypeModule *type_module)
955 GtkThemingModule *theming_module;
957 theming_module = GTK_THEMING_MODULE (type_module);
959 theming_module->exit ();
961 g_module_close (theming_module->module);
963 theming_module->module = NULL;
964 theming_module->init = NULL;
965 theming_module->exit = NULL;
966 theming_module->create_engine = NULL;
970 gtk_theming_module_class_init (GtkThemingModuleClass *klass)
972 GTypeModuleClass *module_class = G_TYPE_MODULE_CLASS (klass);
974 module_class->load = gtk_theming_module_load;
975 module_class->unload = gtk_theming_module_unload;
979 gtk_theming_module_init (GtkThemingModule *module)
984 * gtk_theming_engine_load:
985 * @name: Theme engine name to load
987 * Loads and initializes a theming engine module from the
988 * standard directories.
990 * Returns: (transfer none): A theming engine, or %NULL if
991 * the engine @name doesn't exist.
994 gtk_theming_engine_load (const gchar *name)
996 static GHashTable *engines = NULL;
997 static GtkThemingEngine *default_engine;
998 GtkThemingEngine *engine = NULL;
1003 engines = g_hash_table_new (g_str_hash, g_str_equal);
1005 engine = g_hash_table_lookup (engines, name);
1009 GtkThemingModule *module;
1011 module = g_object_new (GTK_TYPE_THEMING_MODULE, NULL);
1012 g_type_module_set_name (G_TYPE_MODULE (module), name);
1013 module->name = g_strdup (name);
1015 if (module && g_type_module_use (G_TYPE_MODULE (module)))
1017 engine = (module->create_engine) ();
1020 g_hash_table_insert (engines, module->name, engine);
1027 if (G_UNLIKELY (!default_engine))
1028 default_engine = g_object_new (GTK_TYPE_THEMING_ENGINE, NULL);
1030 engine = default_engine;
1037 * gtk_theming_engine_get_screen:
1038 * @engine: a #GtkThemingEngine
1040 * Returns the #GdkScreen to which @engine currently rendering to.
1042 * Returns: (transfer none): a #GdkScreen, or %NULL.
1045 gtk_theming_engine_get_screen (GtkThemingEngine *engine)
1047 GtkThemingEnginePrivate *priv;
1049 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
1051 priv = engine->priv;
1052 return gtk_style_context_get_screen (priv->context);
1055 /* Paint method implementations */
1057 gtk_theming_engine_render_check (GtkThemingEngine *engine,
1064 GdkRGBA fg_color, bg_color;
1065 GtkStateFlags flags;
1066 gint exterior_size, interior_size, thickness, pad;
1067 GtkBorderStyle border_style;
1071 flags = gtk_theming_engine_get_state (engine);
1074 gtk_theming_engine_get_color (engine, flags, &fg_color);
1075 gtk_theming_engine_get_background_color (engine, flags, &bg_color);
1076 gtk_theming_engine_get_border (engine, flags, &border);
1078 gtk_theming_engine_get (engine, flags,
1079 "border-style", &border_style,
1082 border_width = MIN (MIN (border.top, border.bottom),
1083 MIN (border.left, border.right));
1084 exterior_size = MIN (width, height);
1086 if (exterior_size % 2 == 0) /* Ensure odd */
1089 /* FIXME: thickness */
1091 pad = thickness + MAX (1, (exterior_size - 2 * thickness) / 9);
1092 interior_size = MAX (1, exterior_size - 2 * pad);
1094 if (interior_size < 7)
1097 pad = MAX (0, (exterior_size - interior_size) / 2);
1100 x -= (1 + exterior_size - (gint) width) / 2;
1101 y -= (1 + exterior_size - (gint) height) / 2;
1103 if (border_style == GTK_BORDER_STYLE_SOLID)
1105 GdkRGBA border_color;
1107 cairo_set_line_width (cr, border_width);
1108 gtk_theming_engine_get_border_color (engine, flags, &border_color);
1110 cairo_rectangle (cr, x + 0.5, y + 0.5, exterior_size - 1, exterior_size - 1);
1111 gdk_cairo_set_source_rgba (cr, &bg_color);
1112 cairo_fill_preserve (cr);
1114 gdk_cairo_set_source_rgba (cr, &border_color);
1118 gdk_cairo_set_source_rgba (cr, &fg_color);
1120 if (flags & GTK_STATE_FLAG_INCONSISTENT)
1122 int line_thickness = MAX (1, (3 + interior_size * 2) / 7);
1124 cairo_rectangle (cr,
1126 y + pad + (1 + interior_size - line_thickness) / 2,
1136 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress);
1138 if ((flags & GTK_STATE_FLAG_ACTIVE) || running)
1143 cairo_translate (cr,
1146 cairo_scale (cr, interior_size / 7., interior_size / 7.);
1148 cairo_rectangle (cr, 0, 0, 7 * progress, 7);
1151 cairo_move_to (cr, 7.0, 0.0);
1152 cairo_line_to (cr, 7.5, 1.0);
1153 cairo_curve_to (cr, 5.3, 2.0,
1156 cairo_curve_to (cr, 3.0, 5.7,
1159 cairo_line_to (cr, 0.2, 3.5);
1160 cairo_curve_to (cr, 1.1, 3.5,
1163 cairo_curve_to (cr, 1.0, 3.9,
1166 cairo_curve_to (cr, 3.5, 3.1,
1178 gtk_theming_engine_render_option (GtkThemingEngine *engine,
1185 GtkStateFlags flags;
1186 GdkRGBA fg_color, bg_color;
1187 gint exterior_size, interior_size, pad, thickness, border_width;
1188 GtkBorderStyle border_style;
1191 flags = gtk_theming_engine_get_state (engine);
1195 gtk_theming_engine_get_color (engine, flags, &fg_color);
1196 gtk_theming_engine_get_background_color (engine, flags, &bg_color);
1197 gtk_theming_engine_get_border (engine, flags, &border);
1199 gtk_theming_engine_get (engine, flags,
1200 "border-style", &border_style,
1203 exterior_size = MIN (width, height);
1204 border_width = MIN (MIN (border.top, border.bottom),
1205 MIN (border.left, border.right));
1207 if (exterior_size % 2 == 0) /* Ensure odd */
1210 x -= (1 + exterior_size - width) / 2;
1211 y -= (1 + exterior_size - height) / 2;
1213 if (border_style == GTK_BORDER_STYLE_SOLID)
1215 GdkRGBA border_color;
1217 cairo_set_line_width (cr, border_width);
1218 gtk_theming_engine_get_border_color (engine, flags, &border_color);
1220 cairo_new_sub_path (cr);
1222 x + exterior_size / 2.,
1223 y + exterior_size / 2.,
1224 (exterior_size - 1) / 2.,
1227 gdk_cairo_set_source_rgba (cr, &bg_color);
1228 cairo_fill_preserve (cr);
1230 gdk_cairo_set_source_rgba (cr, &border_color);
1234 gdk_cairo_set_source_rgba (cr, &fg_color);
1236 /* FIXME: thickness */
1239 if (flags & GTK_STATE_FLAG_INCONSISTENT)
1241 gint line_thickness;
1243 pad = thickness + MAX (1, (exterior_size - 2 * thickness) / 9);
1244 interior_size = MAX (1, exterior_size - 2 * pad);
1246 if (interior_size < 7)
1249 pad = MAX (0, (exterior_size - interior_size) / 2);
1252 line_thickness = MAX (1, (3 + interior_size * 2) / 7);
1254 cairo_rectangle (cr,
1256 y + pad + (interior_size - line_thickness) / 2.,
1261 if (flags & GTK_STATE_FLAG_ACTIVE)
1263 pad = thickness + MAX (1, 2 * (exterior_size - 2 * thickness) / 9);
1264 interior_size = MAX (1, exterior_size - 2 * pad);
1266 if (interior_size < 5)
1269 pad = MAX (0, (exterior_size - interior_size) / 2);
1272 cairo_new_sub_path (cr);
1274 x + pad + interior_size / 2.,
1275 y + pad + interior_size / 2.,
1285 add_path_arrow (cairo_t *cr,
1293 cairo_translate (cr, x + (size / 2), y + (size / 2));
1294 cairo_rotate (cr, angle);
1296 cairo_move_to (cr, 0, - (size / 4));
1297 cairo_line_to (cr, - (size / 2), (size / 4));
1298 cairo_line_to (cr, (size / 2), (size / 4));
1299 cairo_close_path (cr);
1305 gtk_theming_engine_render_arrow (GtkThemingEngine *engine,
1312 GtkStateFlags flags;
1317 flags = gtk_theming_engine_get_state (engine);
1318 gtk_theming_engine_get_color (engine, flags, &fg_color);
1320 if (flags & GTK_STATE_FLAG_INSENSITIVE)
1322 add_path_arrow (cr, angle, x + 1, y + 1, size);
1323 cairo_set_source_rgb (cr, 1, 1, 1);
1327 add_path_arrow (cr, angle, x, y, size);
1328 gdk_cairo_set_source_rgba (cr, &fg_color);
1335 add_path_line (cairo_t *cr,
1341 /* Adjust endpoints */
1355 cairo_move_to (cr, x1, y1);
1356 cairo_line_to (cr, x2, y2);
1360 color_shade (const GdkRGBA *color,
1362 GdkRGBA *color_return)
1364 GtkSymbolicColor *literal, *shade;
1366 literal = gtk_symbolic_color_new_literal (color);
1367 shade = gtk_symbolic_color_new_shade (literal, factor);
1368 gtk_symbolic_color_unref (literal);
1370 gtk_symbolic_color_resolve (shade, NULL, color_return);
1371 gtk_symbolic_color_unref (shade);
1375 _cairo_ellipsis (cairo_t *cr,
1376 double xc, double yc,
1377 double xradius, double yradius,
1378 double angle1, double angle2)
1380 if (xradius <= 0.0 || yradius <= 0.0)
1382 /* stolen from cairo sources */
1383 cairo_line_to (cr, xc, yc); /* might become a move_to */
1384 cairo_line_to (cr, xc, yc);
1389 cairo_translate (cr, xc, yc);
1390 cairo_scale (cr, xradius, yradius);
1391 cairo_arc (cr, 0, 0, 1.0, angle1, angle2);
1396 _cairo_round_rectangle_sides (cairo_t *cr,
1397 const GtkCssBorderRadius *border_radius,
1404 cairo_new_sub_path (cr);
1406 if (sides & SIDE_RIGHT)
1408 _cairo_ellipsis (cr,
1409 x + width - border_radius->top_right.horizontal,
1410 y + border_radius->top_right.vertical,
1411 border_radius->top_right.horizontal,
1412 border_radius->top_right.vertical,
1414 _cairo_ellipsis (cr,
1415 x + width - border_radius->bottom_right.horizontal,
1416 y + height - border_radius->bottom_right.vertical,
1417 border_radius->bottom_right.horizontal,
1418 border_radius->bottom_right.vertical,
1422 if (sides & SIDE_BOTTOM)
1424 _cairo_ellipsis (cr,
1425 x + width - border_radius->bottom_right.horizontal,
1426 y + height - border_radius->bottom_right.vertical,
1427 border_radius->bottom_right.horizontal,
1428 border_radius->bottom_right.vertical,
1429 G_PI / 4, G_PI / 2);
1430 _cairo_ellipsis (cr,
1431 x + border_radius->bottom_left.horizontal,
1432 y + height - border_radius->bottom_left.vertical,
1433 border_radius->bottom_left.horizontal,
1434 border_radius->bottom_left.vertical,
1435 G_PI / 2, 3 * (G_PI / 4));
1438 cairo_move_to (cr, x, y + height);
1440 if (sides & SIDE_LEFT)
1442 _cairo_ellipsis (cr,
1443 x + border_radius->bottom_left.horizontal,
1444 y + height - border_radius->bottom_left.vertical,
1445 border_radius->bottom_left.horizontal,
1446 border_radius->bottom_left.vertical,
1447 3 * (G_PI / 4), G_PI);
1448 _cairo_ellipsis (cr,
1449 x + border_radius->top_left.horizontal,
1450 y + border_radius->top_left.vertical,
1451 border_radius->top_left.horizontal,
1452 border_radius->top_left.vertical,
1453 G_PI, G_PI + G_PI / 4);
1456 cairo_move_to (cr, x, y);
1458 if (sides & SIDE_TOP)
1460 _cairo_ellipsis (cr,
1461 x + border_radius->top_left.horizontal,
1462 y + border_radius->top_left.vertical,
1463 border_radius->top_left.horizontal,
1464 border_radius->top_left.vertical,
1465 5 * (G_PI / 4), 3 * (G_PI / 2));
1466 _cairo_ellipsis (cr,
1467 x + width - border_radius->top_right.horizontal,
1468 y + border_radius->top_right.vertical,
1469 border_radius->top_right.horizontal,
1470 border_radius->top_right.vertical,
1471 3 * (G_PI / 2), - G_PI / 4);
1476 _cairo_uneven_frame (cairo_t *cr,
1477 const GtkCssBorderRadius *border_radius,
1484 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
1485 cairo_set_line_width (cr, 1);
1487 _cairo_round_rectangle_sides (cr, border_radius,
1492 _cairo_round_rectangle_sides (cr, border_radius,
1495 width - border->left - border->right,
1496 height - border->top - border->bottom,
1501 render_background_internal (GtkThemingEngine *engine,
1507 GtkJunctionSides junction)
1510 cairo_pattern_t *pattern;
1511 GtkStateFlags flags;
1513 gdouble progress, alpha = 1;
1515 GtkCssBorderCornerRadius *top_left_radius, *top_right_radius;
1516 GtkCssBorderCornerRadius *bottom_left_radius, *bottom_right_radius;
1517 GtkCssBorderRadius border_radius = { { 0, }, };
1519 GtkBorderStyle border_style;
1520 gdouble mat_w, mat_h;
1522 /* Use unmodified size for pattern scaling */
1526 flags = gtk_theming_engine_get_state (engine);
1528 gtk_theming_engine_get_background_color (engine, flags, &bg_color);
1529 gtk_theming_engine_get_border (engine, flags, &border);
1531 gtk_theming_engine_get (engine, flags,
1532 "background-image", &pattern,
1533 /* Can't use border-radius as it's an int for
1534 * backwards compat */
1535 "border-top-left-radius", &top_left_radius,
1536 "border-top-right-radius", &top_right_radius,
1537 "border-bottom-right-radius", &bottom_right_radius,
1538 "border-bottom-left-radius", &bottom_left_radius,
1539 "border-style", &border_style,
1542 if (top_left_radius)
1543 border_radius.top_left = *top_left_radius;
1544 g_free (top_left_radius);
1545 if (top_right_radius)
1546 border_radius.top_right = *top_right_radius;
1547 g_free (top_right_radius);
1548 if (bottom_right_radius)
1549 border_radius.bottom_right = *bottom_right_radius;
1550 g_free (bottom_right_radius);
1551 if (bottom_left_radius)
1552 border_radius.bottom_left = *bottom_left_radius;
1553 g_free (bottom_left_radius);
1555 border_width = MIN (MIN (border.top, border.bottom),
1556 MIN (border.left, border.right));
1558 if (border_width > 1 &&
1559 border_style == GTK_BORDER_STYLE_NONE)
1561 x += (gdouble) border_width / 2;
1562 y += (gdouble) border_width / 2;
1563 width -= border_width;
1564 height -= border_width;
1570 width -= border.left + border.right;
1571 height -= border.top + border.bottom;
1574 if (width <= 0 || height <= 0)
1578 cairo_set_line_width (cr, border_width);
1579 cairo_translate (cr, x, y);
1581 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
1583 if (gtk_theming_engine_has_class (engine, "background"))
1585 cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0); /* transparent */
1586 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
1592 cairo_pattern_t *other_pattern;
1593 GtkStateFlags other_flags;
1595 cairo_pattern_t *new_pattern = NULL;
1597 if (flags & GTK_STATE_FLAG_PRELIGHT)
1599 other_flags = flags & ~(GTK_STATE_FLAG_PRELIGHT);
1600 progress = 1 - progress;
1603 other_flags = flags | GTK_STATE_FLAG_PRELIGHT;
1605 gtk_theming_engine_get_background_color (engine, other_flags, &other_bg);
1606 gtk_theming_engine_get (engine, other_flags,
1607 "background-image", &other_pattern,
1610 if (pattern && other_pattern)
1612 cairo_pattern_type_t type, other_type;
1615 cairo_pattern_get_color_stop_count (pattern, &n0);
1616 cairo_pattern_get_color_stop_count (other_pattern, &n1);
1617 type = cairo_pattern_get_type (pattern);
1618 other_type = cairo_pattern_get_type (other_pattern);
1620 if (type == other_type && n0 == n1)
1622 gdouble offset0, red0, green0, blue0, alpha0;
1623 gdouble offset1, red1, green1, blue1, alpha1;
1624 gdouble x00, x01, y00, y01, x10, x11, y10, y11;
1625 gdouble r00, r01, r10, r11;
1628 if (type == CAIRO_PATTERN_TYPE_LINEAR)
1630 cairo_pattern_get_linear_points (pattern, &x00, &y00, &x01, &y01);
1631 cairo_pattern_get_linear_points (other_pattern, &x10, &y10, &x11, &y11);
1633 new_pattern = cairo_pattern_create_linear (x00 + (x10 - x00) * progress,
1634 y00 + (y10 - y00) * progress,
1635 x01 + (x11 - x01) * progress,
1636 y01 + (y11 - y01) * progress);
1640 cairo_pattern_get_radial_circles (pattern, &x00, &y00, &r00, &x01, &y01, &r01);
1641 cairo_pattern_get_radial_circles (other_pattern, &x10, &y10, &r10, &x11, &y11, &r11);
1643 new_pattern = cairo_pattern_create_radial (x00 + (x10 - x00) * progress,
1644 y00 + (y10 - y00) * progress,
1645 r00 + (r10 - r00) * progress,
1646 x01 + (x11 - x01) * progress,
1647 y01 + (y11 - y01) * progress,
1648 r01 + (r11 - r01) * progress);
1651 cairo_pattern_set_filter (new_pattern, CAIRO_FILTER_FAST);
1654 /* Blend both gradients into one */
1655 while (i < n0 && i < n1)
1657 cairo_pattern_get_color_stop_rgba (pattern, i,
1659 &red0, &green0, &blue0,
1661 cairo_pattern_get_color_stop_rgba (other_pattern, i,
1663 &red1, &green1, &blue1,
1666 cairo_pattern_add_color_stop_rgba (new_pattern,
1667 offset0 + ((offset1 - offset0) * progress),
1668 red0 + ((red1 - red0) * progress),
1669 green0 + ((green1 - green0) * progress),
1670 blue0 + ((blue1 - blue0) * progress),
1671 alpha0 + ((alpha1 - alpha0) * progress));
1677 /* Different pattern types, or different color
1678 * stop counts, alpha blend both patterns.
1680 _cairo_round_rectangle_sides (cr, &border_radius,
1681 0, 0, width, height,
1684 cairo_scale (cr, mat_w, mat_h);
1685 cairo_set_source (cr, other_pattern);
1686 cairo_scale (cr, 1.0 / mat_w, 1.0 / mat_h);
1687 cairo_fill_preserve (cr);
1689 /* Set alpha for posterior drawing
1690 * of the target pattern
1692 alpha = 1 - progress;
1695 else if (pattern || other_pattern)
1699 gdouble x0, y0, x1, y1, r0, r1;
1702 /* Blend a pattern with a color */
1707 progress = 1 - progress;
1715 if (cairo_pattern_get_type (p) == CAIRO_PATTERN_TYPE_LINEAR)
1717 cairo_pattern_get_linear_points (p, &x0, &y0, &x1, &y1);
1718 new_pattern = cairo_pattern_create_linear (x0, y0, x1, y1);
1722 cairo_pattern_get_radial_circles (p, &x0, &y0, &r0, &x1, &y1, &r1);
1723 new_pattern = cairo_pattern_create_radial (x0, y0, r0, x1, y1, r1);
1726 cairo_pattern_get_color_stop_count (p, &n);
1728 for (i = 0; i < n; i++)
1730 gdouble red1, green1, blue1, alpha1;
1733 cairo_pattern_get_color_stop_rgba (p, i,
1735 &red1, &green1, &blue1,
1737 cairo_pattern_add_color_stop_rgba (new_pattern, offset,
1738 c->red + ((red1 - c->red) * progress),
1739 c->green + ((green1 - c->green) * progress),
1740 c->blue + ((blue1 - c->blue) * progress),
1741 c->alpha + ((alpha1 - c->alpha) * progress));
1746 /* Merge just colors */
1747 new_pattern = cairo_pattern_create_rgba (CLAMP (bg_color.red + ((other_bg.red - bg_color.red) * progress), 0, 1),
1748 CLAMP (bg_color.green + ((other_bg.green - bg_color.green) * progress), 0, 1),
1749 CLAMP (bg_color.blue + ((other_bg.blue - bg_color.blue) * progress), 0, 1),
1750 CLAMP (bg_color.alpha + ((other_bg.alpha - bg_color.alpha) * progress), 0, 1));
1755 /* Replace pattern to use */
1756 cairo_pattern_destroy (pattern);
1757 pattern = new_pattern;
1761 cairo_pattern_destroy (other_pattern);
1764 _cairo_round_rectangle_sides (cr, &border_radius,
1765 0, 0, width, height,
1769 cairo_scale (cr, mat_w, mat_h);
1770 cairo_set_source (cr, pattern);
1771 cairo_scale (cr, 1.0 / mat_w, 1.0 / mat_h);
1774 gdk_cairo_set_source_rgba (cr, &bg_color);
1778 if (border_width > 1 &&
1779 border_style != GTK_BORDER_STYLE_NONE)
1781 /* stroke with the same source, so the background
1782 * has exactly the shape than the frame, this
1783 * is important so gtk_render_background() and
1784 * gtk_render_frame() fit perfectly with round
1787 cairo_fill_preserve (cr);
1796 _cairo_round_rectangle_sides (cr, &border_radius,
1797 0, 0, width, height,
1801 cairo_paint_with_alpha (cr, alpha);
1807 cairo_pattern_destroy (pattern);
1813 gtk_theming_engine_render_background (GtkThemingEngine *engine,
1820 GtkJunctionSides junction;
1822 junction = gtk_theming_engine_get_junction_sides (engine);
1824 render_background_internal (engine, cr,
1825 x, y, width, height,
1829 /* Renders the small triangle on corners so
1830 * frames with 0 radius have a 3D-like effect
1833 _cairo_corner_triangle (cairo_t *cr,
1840 cairo_move_to (cr, x + 0.5, y + size - 0.5);
1841 cairo_line_to (cr, x + size - 0.5, y + size - 0.5);
1842 cairo_line_to (cr, x + size - 0.5, y + 0.5);
1844 for (i = 1; i < size - 1; i++)
1846 cairo_move_to (cr, x + size - 0.5, y + i + 0.5);
1847 cairo_line_to (cr, x + (size - i) - 0.5, y + i + 0.5);
1852 gtk_themeing_engine_apply_junction_to_radius (GtkCssBorderRadius *border_radius,
1853 GtkJunctionSides junction)
1855 if (junction & GTK_JUNCTION_CORNER_TOPLEFT)
1856 border_radius->top_left.horizontal = border_radius->top_left.vertical = 0;
1857 if (junction & GTK_JUNCTION_CORNER_TOPRIGHT)
1858 border_radius->top_right.horizontal = border_radius->top_right.vertical = 0;
1859 if (junction & GTK_JUNCTION_CORNER_BOTTOMRIGHT)
1860 border_radius->bottom_right.horizontal = border_radius->bottom_right.vertical = 0;
1861 if (junction & GTK_JUNCTION_CORNER_BOTTOMLEFT)
1862 border_radius->bottom_left.horizontal = border_radius->bottom_left.vertical = 0;
1866 render_frame_internal (GtkThemingEngine *engine,
1873 GtkJunctionSides junction)
1875 GtkStateFlags state;
1877 GdkRGBA border_color;
1878 GtkBorderStyle border_style;
1880 GtkCssBorderCornerRadius *top_left_radius, *top_right_radius;
1881 GtkCssBorderCornerRadius *bottom_left_radius, *bottom_right_radius;
1882 GtkCssBorderRadius border_radius = { { 0, }, };
1883 gdouble progress, d1, d2, m;
1886 gboolean uniform_border;
1888 state = gtk_theming_engine_get_state (engine);
1890 gtk_theming_engine_get_border_color (engine, state, &border_color);
1891 gtk_theming_engine_get_border (engine, state, &border);
1893 gtk_theming_engine_get (engine, state,
1894 "border-style", &border_style,
1895 /* Can't use border-radius as it's an int for
1896 * backwards compat */
1897 "border-top-left-radius", &top_left_radius,
1898 "border-top-right-radius", &top_right_radius,
1899 "border-bottom-right-radius", &bottom_right_radius,
1900 "border-bottom-left-radius", &bottom_left_radius,
1903 if (top_left_radius)
1904 border_radius.top_left = *top_left_radius;
1905 g_free (top_left_radius);
1906 if (top_right_radius)
1907 border_radius.top_right = *top_right_radius;
1908 g_free (top_right_radius);
1909 if (bottom_right_radius)
1910 border_radius.bottom_right = *bottom_right_radius;
1911 g_free (bottom_right_radius);
1912 if (bottom_left_radius)
1913 border_radius.bottom_left = *bottom_left_radius;
1914 g_free (bottom_left_radius);
1916 gtk_themeing_engine_apply_junction_to_radius (&border_radius, junction);
1918 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
1919 border_width = MIN (MIN (border.top, border.bottom),
1920 MIN (border.left, border.right));
1921 uniform_border = (border.top == border.bottom &&
1922 border.top == border.left &&
1923 border.top == border.right);
1927 GtkStateFlags other_state;
1928 GdkRGBA other_color;
1930 if (state & GTK_STATE_FLAG_PRELIGHT)
1932 other_state = state & ~(GTK_STATE_FLAG_PRELIGHT);
1933 progress = 1 - progress;
1936 other_state = state | GTK_STATE_FLAG_PRELIGHT;
1938 gtk_theming_engine_get_border_color (engine, other_state, &other_color);
1940 border_color.red = CLAMP (border_color.red + ((other_color.red - border_color.red) * progress), 0, 1);
1941 border_color.green = CLAMP (border_color.green + ((other_color.green - border_color.green) * progress), 0, 1);
1942 border_color.blue = CLAMP (border_color.blue + ((other_color.blue - border_color.blue) * progress), 0, 1);
1943 border_color.alpha = CLAMP (border_color.alpha + ((other_color.alpha - border_color.alpha) * progress), 0, 1);
1948 color_shade (&border_color, 1.8, &lighter);
1950 switch (border_style)
1952 case GTK_BORDER_STYLE_NONE:
1954 case GTK_BORDER_STYLE_SOLID:
1955 cairo_set_line_width (cr, border_width);
1956 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
1958 gdk_cairo_set_source_rgba (cr, &border_color);
1962 if (border_width > 1)
1964 x += (gdouble) border_width / 2;
1965 y += (gdouble) border_width / 2;
1966 width -= border_width;
1967 height -= border_width;
1969 else if (border_width == 1)
1977 _cairo_round_rectangle_sides (cr, &border_radius,
1978 x, y, width, height,
1979 SIDE_ALL & ~(hidden_side));
1985 _cairo_uneven_frame (cr, &border_radius,
1986 x, y, width, height,
1993 case GTK_BORDER_STYLE_INSET:
1994 case GTK_BORDER_STYLE_OUTSET:
1995 cairo_set_line_width (cr, border_width);
1996 cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
1998 if (border_width > 1)
2000 d1 = (gdouble) border_width / 2;
2011 m = MIN (width, height);
2016 if (border_style == GTK_BORDER_STYLE_INSET)
2017 gdk_cairo_set_source_rgba (cr, &lighter);
2019 gdk_cairo_set_source_rgba (cr, &border_color);
2021 _cairo_round_rectangle_sides (cr, &border_radius,
2023 width - d2, height - d2,
2024 (SIDE_BOTTOM | SIDE_RIGHT) & ~(hidden_side));
2027 if (border_style == GTK_BORDER_STYLE_INSET)
2028 gdk_cairo_set_source_rgba (cr, &border_color);
2030 gdk_cairo_set_source_rgba (cr, &lighter);
2032 _cairo_round_rectangle_sides (cr, &border_radius,
2034 width - d2, height - d2,
2035 (SIDE_TOP | SIDE_LEFT) & ~(hidden_side));
2043 if (border_style == GTK_BORDER_STYLE_INSET)
2044 gdk_cairo_set_source_rgba (cr, &lighter);
2046 gdk_cairo_set_source_rgba (cr, &border_color);
2048 _cairo_uneven_frame (cr, &border_radius,
2049 x, y, width, height,
2054 cairo_move_to (cr, x, y);
2055 cairo_line_to (cr, x + width, y);
2057 x + width - border.right - border_radius.top_right.horizontal / 2,
2058 y + border.top + border_radius.top_right.vertical / 2);
2060 x + width - border.right - border_radius.bottom_right.horizontal / 2,
2061 y + height - border.bottom - border_radius.bottom_right.vertical / 2);
2063 x + border.left + border_radius.bottom_left.horizontal / 2,
2064 y + height - border.bottom - border_radius.bottom_left.vertical / 2);
2065 cairo_line_to (cr, x, y + height);
2066 cairo_close_path (cr);
2070 if (border_style == GTK_BORDER_STYLE_INSET)
2071 gdk_cairo_set_source_rgba (cr, &border_color);
2073 gdk_cairo_set_source_rgba (cr, &lighter);
2075 _cairo_uneven_frame (cr, &border_radius,
2076 x, y, width, height,
2082 if (border_width > 1)
2084 /* overprint top/right and bottom/left corner
2085 * triangles if there are square corners there,
2086 * to give the box a 3D-like appearance.
2090 if (border_style == GTK_BORDER_STYLE_INSET)
2091 gdk_cairo_set_source_rgba (cr, &lighter);
2093 gdk_cairo_set_source_rgba (cr, &border_color);
2095 cairo_set_line_width (cr, 1);
2097 if ((junction & GTK_JUNCTION_CORNER_TOPRIGHT) != 0)
2098 _cairo_corner_triangle (cr,
2099 x + width - border_width, y,
2102 if ((junction & GTK_JUNCTION_CORNER_BOTTOMLEFT) != 0)
2103 _cairo_corner_triangle (cr,
2104 x, y + height - border_width,
2118 gtk_theming_engine_render_frame (GtkThemingEngine *engine,
2125 GtkStateFlags flags;
2126 GtkBorderStyle border_style;
2127 GtkJunctionSides junction;
2128 GtkBorderImage *border_image;
2131 flags = gtk_theming_engine_get_state (engine);
2132 junction = gtk_theming_engine_get_junction_sides (engine);
2133 gtk_theming_engine_get_border (engine, flags, &border);
2135 gtk_theming_engine_get (engine, flags,
2136 "border-image", &border_image,
2137 "border-style", &border_style,
2140 if (border_image != NULL)
2142 _gtk_border_image_render (border_image, &border,
2143 cr, x, y, width, height);
2144 _gtk_border_image_unref (border_image);
2146 else if (border_style != GTK_BORDER_STYLE_NONE)
2147 render_frame_internal (engine, cr,
2148 x, y, width, height,
2153 gtk_theming_engine_render_expander (GtkThemingEngine *engine,
2160 GtkStateFlags flags;
2161 GdkRGBA outline_color, fg_color;
2162 double vertical_overshoot;
2165 double interp; /* interpolation factor for center position */
2166 double x_double_horz, y_double_horz;
2167 double x_double_vert, y_double_vert;
2168 double x_double, y_double;
2171 gboolean running, is_rtl;
2175 flags = gtk_theming_engine_get_state (engine);
2177 gtk_theming_engine_get_color (engine, flags, &fg_color);
2178 gtk_theming_engine_get_border_color (engine, flags, &outline_color);
2180 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress);
2181 is_rtl = (gtk_theming_engine_get_direction (engine) == GTK_TEXT_DIR_RTL);
2185 progress = (flags & GTK_STATE_FLAG_ACTIVE) ? 1 : 0;
2187 if (!gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_HORIZONTAL))
2190 angle = (G_PI) - ((G_PI / 2) * progress);
2192 angle = (G_PI / 2) * progress;
2197 angle = (G_PI / 2) + ((G_PI / 2) * progress);
2199 angle = (G_PI / 2) - ((G_PI / 2) * progress);
2204 /* Compute distance that the stroke extends beyonds the end
2205 * of the triangle we draw.
2207 vertical_overshoot = line_width / 2.0 * (1. / tan (G_PI / 8));
2209 /* For odd line widths, we end the vertical line of the triangle
2210 * at a half pixel, so we round differently.
2212 if (line_width % 2 == 1)
2213 vertical_overshoot = ceil (0.5 + vertical_overshoot) - 0.5;
2215 vertical_overshoot = ceil (vertical_overshoot);
2217 /* Adjust the size of the triangle we draw so that the entire stroke fits
2219 diameter = (gint) MAX (3, width - 2 * vertical_overshoot);
2221 /* If the line width is odd, we want the diameter to be even,
2222 * and vice versa, so force the sum to be odd. This relationship
2223 * makes the point of the triangle look right.
2225 diameter -= (1 - (diameter + line_width) % 2);
2227 radius = diameter / 2.;
2229 /* Adjust the center so that the stroke is properly aligned with
2230 * the pixel grid. The center adjustment is different for the
2231 * horizontal and vertical orientations. For intermediate positions
2232 * we interpolate between the two.
2234 x_double_vert = floor ((x + width / 2) - (radius + line_width) / 2.) + (radius + line_width) / 2.;
2235 y_double_vert = (y + height / 2) - 0.5;
2237 x_double_horz = (x + width / 2) - 0.5;
2238 y_double_horz = floor ((y + height / 2) - (radius + line_width) / 2.) + (radius + line_width) / 2.;
2240 x_double = x_double_vert * (1 - interp) + x_double_horz * interp;
2241 y_double = y_double_vert * (1 - interp) + y_double_horz * interp;
2243 cairo_translate (cr, x_double, y_double);
2244 cairo_rotate (cr, angle);
2246 cairo_move_to (cr, - radius / 2., - radius);
2247 cairo_line_to (cr, radius / 2., 0);
2248 cairo_line_to (cr, - radius / 2., radius);
2249 cairo_close_path (cr);
2251 cairo_set_line_width (cr, line_width);
2253 gdk_cairo_set_source_rgba (cr, &fg_color);
2255 cairo_fill_preserve (cr);
2257 gdk_cairo_set_source_rgba (cr, &outline_color);
2264 gtk_theming_engine_render_focus (GtkThemingEngine *engine,
2271 GtkStateFlags flags;
2277 flags = gtk_theming_engine_get_state (engine);
2279 gtk_theming_engine_get_color (engine, flags, &color);
2281 gtk_theming_engine_get_style (engine,
2282 "focus-line-width", &line_width,
2283 "focus-line-pattern", (gchar *) &dash_list,
2286 cairo_set_line_width (cr, (gdouble) line_width);
2290 gint n_dashes = strlen ((const gchar *) dash_list);
2291 gdouble *dashes = g_new (gdouble, n_dashes);
2292 gdouble total_length = 0;
2293 gdouble dash_offset;
2296 for (i = 0; i < n_dashes; i++)
2298 dashes[i] = dash_list[i];
2299 total_length += dash_list[i];
2302 /* The dash offset here aligns the pattern to integer pixels
2303 * by starting the dash at the right side of the left border
2304 * Negative dash offsets in cairo don't work
2305 * (https://bugs.freedesktop.org/show_bug.cgi?id=2729)
2307 dash_offset = - line_width / 2.;
2309 while (dash_offset < 0)
2310 dash_offset += total_length;
2312 cairo_set_dash (cr, dashes, n_dashes, dash_offset);
2316 cairo_rectangle (cr,
2317 x + line_width / 2.,
2318 y + line_width / 2.,
2320 height - line_width);
2322 gdk_cairo_set_source_rgba (cr, &color);
2331 gtk_theming_engine_render_line (GtkThemingEngine *engine,
2338 GdkRGBA bg_color, darker, lighter;
2339 GtkStateFlags flags;
2340 gint i, thickness, thickness_dark, thickness_light, len;
2341 cairo_matrix_t matrix;
2344 /* FIXME: thickness */
2346 thickness_dark = thickness / 2;
2347 thickness_light = thickness - thickness_dark;
2349 flags = gtk_theming_engine_get_state (engine);
2352 gtk_theming_engine_get_background_color (engine, flags, &bg_color);
2353 color_shade (&bg_color, 0.7, &darker);
2354 color_shade (&bg_color, 1.3, &lighter);
2356 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
2357 cairo_set_line_width (cr, 1);
2359 angle = atan2 (x1 - x0, y1 - y0);
2360 angle = (2 * G_PI) - angle;
2363 cairo_get_matrix (cr, &matrix);
2364 cairo_matrix_translate (&matrix, x0, y0);
2365 cairo_matrix_rotate (&matrix, angle);
2366 cairo_set_matrix (cr, &matrix);
2371 len = (gint) sqrt ((x1 * x1) + (y1 * y1));
2373 y0 = -thickness_dark;
2375 for (i = 0; i < thickness_dark; i++)
2377 gdk_cairo_set_source_rgba (cr, &lighter);
2378 add_path_line (cr, len - i - 1.5, y0, len - 0.5, y0);
2381 gdk_cairo_set_source_rgba (cr, &darker);
2382 add_path_line (cr, 0.5, y0, len - i - 1.5, y0);
2388 for (i = 0; i < thickness_light; i++)
2390 gdk_cairo_set_source_rgba (cr, &darker);
2391 add_path_line (cr, 0.5, y0, thickness_light - i + 0.5, y0);
2394 gdk_cairo_set_source_rgba (cr, &lighter);
2395 add_path_line (cr, thickness_light - i + 0.5, y0, len - 0.5, y0);
2405 prepare_context_for_layout (cairo_t *cr,
2408 PangoLayout *layout)
2410 const PangoMatrix *matrix;
2412 matrix = pango_context_get_matrix (pango_layout_get_context (layout));
2414 cairo_move_to (cr, x, y);
2418 cairo_matrix_t cairo_matrix;
2420 cairo_matrix_init (&cairo_matrix,
2421 matrix->xx, matrix->yx,
2422 matrix->xy, matrix->yy,
2423 matrix->x0, matrix->y0);
2425 cairo_transform (cr, &cairo_matrix);
2430 gtk_theming_engine_render_layout (GtkThemingEngine *engine,
2434 PangoLayout *layout)
2437 GtkShadow *text_shadow = NULL;
2438 GtkStateFlags flags;
2443 flags = gtk_theming_engine_get_state (engine);
2444 gtk_theming_engine_get_color (engine, flags, &fg_color);
2446 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
2450 GtkStateFlags other_flags;
2453 if (flags & GTK_STATE_FLAG_PRELIGHT)
2455 other_flags = flags & ~(GTK_STATE_FLAG_PRELIGHT);
2456 progress = 1 - progress;
2459 other_flags = flags | GTK_STATE_FLAG_PRELIGHT;
2461 gtk_theming_engine_get_color (engine, other_flags, &other_fg);
2463 fg_color.red = CLAMP (fg_color.red + ((other_fg.red - fg_color.red) * progress), 0, 1);
2464 fg_color.green = CLAMP (fg_color.green + ((other_fg.green - fg_color.green) * progress), 0, 1);
2465 fg_color.blue = CLAMP (fg_color.blue + ((other_fg.blue - fg_color.blue) * progress), 0, 1);
2466 fg_color.alpha = CLAMP (fg_color.alpha + ((other_fg.alpha - fg_color.alpha) * progress), 0, 1);
2469 gtk_theming_engine_get (engine, flags,
2470 "text-shadow", &text_shadow,
2473 prepare_context_for_layout (cr, x, y, layout);
2475 if (text_shadow != NULL)
2477 _gtk_text_shadow_paint_layout (text_shadow, cr, layout);
2478 _gtk_shadow_unref (text_shadow);
2481 gdk_cairo_set_source_rgba (cr, &fg_color);
2482 pango_cairo_show_layout (cr, layout);
2488 gtk_theming_engine_render_slider (GtkThemingEngine *engine,
2494 GtkOrientation orientation)
2496 const GtkWidgetPath *path;
2499 path = gtk_theming_engine_get_path (engine);
2501 gtk_theming_engine_render_background (engine, cr, x, y, width, height);
2502 gtk_theming_engine_render_frame (engine, cr, x, y, width, height);
2504 /* FIXME: thickness */
2507 if (gtk_widget_path_is_type (path, GTK_TYPE_SCALE))
2509 if (orientation == GTK_ORIENTATION_VERTICAL)
2510 gtk_theming_engine_render_line (engine, cr,
2512 y + (gint) height / 2,
2513 x + width - thickness - 1,
2514 y + (gint) height / 2);
2516 gtk_theming_engine_render_line (engine, cr,
2517 x + (gint) width / 2,
2519 x + (gint) width / 2,
2520 y + height - thickness - 1);
2525 gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
2531 GtkPositionType gap_side,
2535 GtkJunctionSides junction;
2536 GtkStateFlags state;
2538 GtkCssBorderCornerRadius *top_left_radius, *top_right_radius;
2539 GtkCssBorderCornerRadius *bottom_left_radius, *bottom_right_radius;
2540 GtkCssBorderRadius border_radius = { { 0, }, };
2541 gdouble x0, y0, x1, y1, xc, yc, wc, hc;
2544 xc = yc = wc = hc = 0;
2545 state = gtk_theming_engine_get_state (engine);
2546 junction = gtk_theming_engine_get_junction_sides (engine);
2548 gtk_theming_engine_get_border (engine, state, &border);
2549 gtk_theming_engine_get (engine, state,
2550 /* Can't use border-radius as it's an int for
2551 * backwards compat */
2552 "border-top-left-radius", &top_left_radius,
2553 "border-top-right-radius", &top_right_radius,
2554 "border-bottom-right-radius", &bottom_right_radius,
2555 "border-bottom-left-radius", &bottom_left_radius,
2558 if (top_left_radius)
2559 border_radius.top_left = *top_left_radius;
2560 g_free (top_left_radius);
2561 if (top_right_radius)
2562 border_radius.top_right = *top_right_radius;
2563 g_free (top_right_radius);
2564 if (bottom_right_radius)
2565 border_radius.bottom_right = *bottom_right_radius;
2566 g_free (bottom_right_radius);
2567 if (bottom_left_radius)
2568 border_radius.bottom_left = *bottom_left_radius;
2569 g_free (bottom_left_radius);
2571 border_width = MIN (MIN (border.top, border.bottom),
2572 MIN (border.left, border.right));
2579 xc = x + xy0_gap + border_width;
2581 wc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
2584 if (xy0_gap < border_radius.top_left.horizontal)
2585 junction |= GTK_JUNCTION_CORNER_TOPLEFT;
2587 if (xy1_gap > width - border_radius.top_right.horizontal)
2588 junction |= GTK_JUNCTION_CORNER_TOPRIGHT;
2590 case GTK_POS_BOTTOM:
2591 xc = x + xy0_gap + border_width;
2592 yc = y + height - border_width;
2593 wc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
2596 if (xy0_gap < border_radius.bottom_left.horizontal)
2597 junction |= GTK_JUNCTION_CORNER_BOTTOMLEFT;
2599 if (xy1_gap > width - border_radius.bottom_right.horizontal)
2600 junction |= GTK_JUNCTION_CORNER_BOTTOMRIGHT;
2605 yc = y + xy0_gap + border_width;
2607 hc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
2609 if (xy0_gap < border_radius.top_left.vertical)
2610 junction |= GTK_JUNCTION_CORNER_TOPLEFT;
2612 if (xy1_gap > height - border_radius.bottom_left.vertical)
2613 junction |= GTK_JUNCTION_CORNER_BOTTOMLEFT;
2617 xc = x + width - border_width;
2618 yc = y + xy0_gap + border_width;
2620 hc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
2622 if (xy0_gap < border_radius.top_right.vertical)
2623 junction |= GTK_JUNCTION_CORNER_TOPRIGHT;
2625 if (xy1_gap > height - border_radius.bottom_right.vertical)
2626 junction |= GTK_JUNCTION_CORNER_BOTTOMRIGHT;
2631 cairo_clip_extents (cr, &x0, &y0, &x1, &y1);
2632 cairo_rectangle (cr, x0, y0, x1 - x0, yc - y0);
2633 cairo_rectangle (cr, x0, yc, xc - x0, hc);
2634 cairo_rectangle (cr, xc + wc, yc, x1 - (xc + wc), hc);
2635 cairo_rectangle (cr, x0, yc + hc, x1 - x0, y1 - (yc + hc));
2638 render_frame_internal (engine, cr,
2639 x, y, width, height,
2646 gtk_theming_engine_render_extension (GtkThemingEngine *engine,
2652 GtkPositionType gap_side)
2654 GtkJunctionSides junction = 0;
2655 guint hidden_side = 0;
2662 junction = GTK_JUNCTION_LEFT;
2663 hidden_side = SIDE_LEFT;
2665 cairo_translate (cr, x + width, y);
2666 cairo_rotate (cr, G_PI / 2);
2669 junction = GTK_JUNCTION_RIGHT;
2670 hidden_side = SIDE_RIGHT;
2672 cairo_translate (cr, x, y + height);
2673 cairo_rotate (cr, - G_PI / 2);
2676 junction = GTK_JUNCTION_TOP;
2677 hidden_side = SIDE_TOP;
2679 cairo_translate (cr, x + width, y + height);
2680 cairo_rotate (cr, G_PI);
2682 case GTK_POS_BOTTOM:
2683 junction = GTK_JUNCTION_BOTTOM;
2684 hidden_side = SIDE_BOTTOM;
2686 cairo_translate (cr, x, y);
2690 if (gap_side == GTK_POS_TOP ||
2691 gap_side == GTK_POS_BOTTOM)
2692 render_background_internal (engine, cr,
2693 0, 0, width, height,
2694 GTK_JUNCTION_BOTTOM);
2696 render_background_internal (engine, cr,
2697 0, 0, height, width,
2698 GTK_JUNCTION_BOTTOM);
2703 render_frame_internal (engine, cr,
2704 x, y, width, height,
2705 hidden_side, junction);
2711 render_dot (cairo_t *cr,
2712 const GdkRGBA *lighter,
2713 const GdkRGBA *darker,
2718 size = CLAMP ((gint) size, 2, 3);
2722 gdk_cairo_set_source_rgba (cr, lighter);
2723 cairo_rectangle (cr, x, y, 1, 1);
2724 cairo_rectangle (cr, x + 1, y + 1, 1, 1);
2729 gdk_cairo_set_source_rgba (cr, lighter);
2730 cairo_rectangle (cr, x, y, 2, 1);
2731 cairo_rectangle (cr, x, y, 1, 2);
2734 gdk_cairo_set_source_rgba (cr, darker);
2735 cairo_rectangle (cr, x + 1, y + 1, 2, 1);
2736 cairo_rectangle (cr, x + 2, y, 1, 2);
2742 gtk_theming_engine_render_handle (GtkThemingEngine *engine,
2749 GtkStateFlags flags;
2750 GdkRGBA bg_color, lighter, darker;
2751 GtkJunctionSides sides;
2755 flags = gtk_theming_engine_get_state (engine);
2757 cairo_set_line_width (cr, 1.0);
2758 sides = gtk_theming_engine_get_junction_sides (engine);
2759 gtk_theming_engine_get_background_color (engine, flags, &bg_color);
2761 color_shade (&bg_color, 0.7, &darker);
2762 color_shade (&bg_color, 1.3, &lighter);
2764 render_background_internal (engine, cr, x, y, width, height, sides);
2766 if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_GRIP))
2768 /* reduce confusing values to a meaningful state */
2769 if ((sides & (GTK_JUNCTION_CORNER_TOPLEFT | GTK_JUNCTION_CORNER_BOTTOMRIGHT)) == (GTK_JUNCTION_CORNER_TOPLEFT | GTK_JUNCTION_CORNER_BOTTOMRIGHT))
2770 sides &= ~GTK_JUNCTION_CORNER_TOPLEFT;
2772 if ((sides & (GTK_JUNCTION_CORNER_TOPRIGHT | GTK_JUNCTION_CORNER_BOTTOMLEFT)) == (GTK_JUNCTION_CORNER_TOPRIGHT | GTK_JUNCTION_CORNER_BOTTOMLEFT))
2773 sides &= ~GTK_JUNCTION_CORNER_TOPRIGHT;
2776 sides = GTK_JUNCTION_CORNER_BOTTOMRIGHT;
2778 /* align drawing area to the connected side */
2779 if (sides == GTK_JUNCTION_LEFT)
2784 else if (sides == GTK_JUNCTION_CORNER_TOPLEFT)
2788 else if (height < width)
2791 else if (sides == GTK_JUNCTION_CORNER_BOTTOMLEFT)
2793 /* make it square, aligning to bottom left */
2796 y += (height - width);
2799 else if (height < width)
2802 else if (sides == GTK_JUNCTION_RIGHT)
2804 /* aligning to right */
2807 x += (width - height);
2811 else if (sides == GTK_JUNCTION_CORNER_TOPRIGHT)
2815 else if (height < width)
2817 x += (width - height);
2821 else if (sides == GTK_JUNCTION_CORNER_BOTTOMRIGHT)
2823 /* make it square, aligning to bottom right */
2826 y += (height - width);
2829 else if (height < width)
2831 x += (width - height);
2835 else if (sides == GTK_JUNCTION_TOP)
2840 else if (sides == GTK_JUNCTION_BOTTOM)
2842 /* align to bottom */
2845 y += (height - width);
2850 g_assert_not_reached ();
2852 if (sides == GTK_JUNCTION_LEFT ||
2853 sides == GTK_JUNCTION_RIGHT)
2859 while (xi < x + width)
2861 gdk_cairo_set_source_rgba (cr, &lighter);
2862 add_path_line (cr, x, y, x, y + height);
2866 gdk_cairo_set_source_rgba (cr, &darker);
2867 add_path_line (cr, xi, y, xi, y + height);
2872 else if (sides == GTK_JUNCTION_TOP ||
2873 sides == GTK_JUNCTION_BOTTOM)
2879 while (yi < y + height)
2881 gdk_cairo_set_source_rgba (cr, &lighter);
2882 add_path_line (cr, x, yi, x + width, yi);
2886 gdk_cairo_set_source_rgba (cr, &darker);
2887 add_path_line (cr, x, yi, x + width, yi);
2892 else if (sides == GTK_JUNCTION_CORNER_TOPLEFT)
2901 gdk_cairo_set_source_rgba (cr, &darker);
2902 add_path_line (cr, xi, y, x, yi);
2908 add_path_line (cr, xi, y, x, yi);
2914 gdk_cairo_set_source_rgba (cr, &lighter);
2915 add_path_line (cr, xi, y, x, yi);
2922 else if (sides == GTK_JUNCTION_CORNER_TOPRIGHT)
2929 while (xi < (x + width - 3))
2931 gdk_cairo_set_source_rgba (cr, &lighter);
2932 add_path_line (cr, xi, y, x + width, yi);
2938 gdk_cairo_set_source_rgba (cr, &darker);
2939 add_path_line (cr, xi, y, x + width, yi);
2945 add_path_line (cr, xi, y, x + width, yi);
2952 else if (sides == GTK_JUNCTION_CORNER_BOTTOMLEFT)
2961 gdk_cairo_set_source_rgba (cr, &darker);
2962 add_path_line (cr, x, yi, xi, y + height);
2968 add_path_line (cr, x, yi, xi, y + height);
2974 gdk_cairo_set_source_rgba (cr, &lighter);
2975 add_path_line (cr, x, yi, xi, y + height);
2982 else if (sides == GTK_JUNCTION_CORNER_BOTTOMRIGHT)
2989 while (xi < (x + width - 3))
2991 gdk_cairo_set_source_rgba (cr, &lighter);
2992 add_path_line (cr, xi, y + height, x + width, yi);
2998 gdk_cairo_set_source_rgba (cr, &darker);
2999 add_path_line (cr, xi, y + height, x + width, yi);
3005 add_path_line (cr, xi, y + height, x + width, yi);
3013 else if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_PANE_SEPARATOR))
3016 for (xx = x + width / 2 - 15; xx <= x + width / 2 + 15; xx += 5)
3017 render_dot (cr, &lighter, &darker, xx, y + height / 2 - 1, 3);
3019 for (yy = y + height / 2 - 15; yy <= y + height / 2 + 15; yy += 5)
3020 render_dot (cr, &lighter, &darker, x + width / 2 - 1, yy, 3);
3024 for (yy = y; yy < y + height; yy += 3)
3025 for (xx = x; xx < x + width; xx += 6)
3027 render_dot (cr, &lighter, &darker, xx, yy, 2);
3028 render_dot (cr, &lighter, &darker, xx + 3, yy + 1, 2);
3036 _gtk_theming_engine_paint_spinner (cairo_t *cr,
3041 guint num_steps, step;
3048 step = (guint) (progress * num_steps);
3054 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
3055 cairo_set_line_width (cr, 2.0);
3057 half = num_steps / 2;
3059 for (i = 0; i < num_steps; i++)
3061 gint inset = 0.7 * radius;
3063 /* transparency is a function of time and intial value */
3064 gdouble t = 1.0 - (gdouble) ((i + step) % num_steps) / num_steps;
3065 gdouble xscale = - sin (i * G_PI / half);
3066 gdouble yscale = - cos (i * G_PI / half);
3068 cairo_set_source_rgba (cr,
3075 (radius - inset) * xscale,
3076 (radius - inset) * yscale);
3088 render_spinner (GtkThemingEngine *engine,
3095 GtkStateFlags state;
3101 state = gtk_theming_engine_get_state (engine);
3103 if (!gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress))
3106 radius = MIN (width / 2, height / 2);
3108 gtk_theming_engine_get_color (engine, state, &color);
3109 gtk_theming_engine_get (engine, state,
3110 "icon-shadow", &shadow,
3114 cairo_translate (cr, x + width / 2, y + height / 2);
3118 _gtk_icon_shadow_paint_spinner (shadow, cr,
3121 _gtk_shadow_unref (shadow);
3124 _gtk_theming_engine_paint_spinner (cr,
3133 gtk_theming_engine_render_activity (GtkThemingEngine *engine,
3140 if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_SPINNER))
3142 render_spinner (engine, cr, x, y, width, height);
3146 gtk_theming_engine_render_background (engine, cr, x, y, width, height);
3147 gtk_theming_engine_render_frame (engine, cr, x, y, width, height);
3152 scale_or_ref (GdkPixbuf *src,
3156 if (width == gdk_pixbuf_get_width (src) &&
3157 height == gdk_pixbuf_get_height (src))
3158 return g_object_ref (src);
3160 return gdk_pixbuf_scale_simple (src,
3162 GDK_INTERP_BILINEAR);
3166 lookup_icon_size (GtkThemingEngine *engine,
3172 GtkSettings *settings;
3174 screen = gtk_theming_engine_get_screen (engine);
3175 settings = gtk_settings_get_for_screen (screen);
3177 return gtk_icon_size_lookup_for_settings (settings, size, width, height);
3181 colorshift_source (cairo_t *cr,
3184 cairo_pattern_t *source;
3189 source = cairo_pattern_reference (cairo_get_source (cr));
3191 cairo_set_source_rgb (cr, shift, shift, shift);
3192 cairo_set_operator (cr, CAIRO_OPERATOR_COLOR_DODGE);
3194 cairo_mask (cr, source);
3196 cairo_pattern_destroy (source);
3201 gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine *engine,
3202 const GtkIconSource *source,
3207 GdkPixbuf *base_pixbuf;
3208 GtkStateFlags state;
3212 cairo_surface_t *surface;
3214 base_pixbuf = gtk_icon_source_get_pixbuf (source);
3215 state = gtk_theming_engine_get_state (engine);
3217 g_return_val_if_fail (base_pixbuf != NULL, NULL);
3219 if (size != (GtkIconSize) -1 &&
3220 !lookup_icon_size (engine, size, &width, &height))
3222 g_warning (G_STRLOC ": invalid icon size '%d'", size);
3226 /* If the size was wildcarded, and we're allowed to scale, then scale; otherwise,
3229 if (size != (GtkIconSize) -1 &&
3230 gtk_icon_source_get_size_wildcarded (source))
3231 scaled = scale_or_ref (base_pixbuf, width, height);
3233 scaled = g_object_ref (base_pixbuf);
3235 /* If the state was wildcarded, then generate a state. */
3236 if (gtk_icon_source_get_state_wildcarded (source))
3238 if (state & GTK_STATE_FLAG_INSENSITIVE)
3240 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
3241 gdk_pixbuf_get_width (scaled),
3242 gdk_pixbuf_get_height (scaled));
3243 cr = cairo_create (surface);
3244 gdk_cairo_set_source_pixbuf (cr, scaled, 0, 0);
3245 cairo_paint_with_alpha (cr, 0.5);
3249 g_object_unref (scaled);
3250 stated = gdk_pixbuf_get_from_surface (surface, 0, 0,
3251 cairo_image_surface_get_width (surface),
3252 cairo_image_surface_get_height (surface));
3254 else if (state & GTK_STATE_FLAG_PRELIGHT)
3256 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
3257 gdk_pixbuf_get_width (scaled),
3258 gdk_pixbuf_get_height (scaled));
3260 cr = cairo_create (surface);
3261 gdk_cairo_set_source_pixbuf (cr, scaled, 0, 0);
3262 colorshift_source (cr, 0.10);
3266 g_object_unref (scaled);
3267 stated = gdk_pixbuf_get_from_surface (surface, 0, 0,
3268 cairo_image_surface_get_width (surface),
3269 cairo_image_surface_get_height (surface));
3281 gtk_theming_engine_render_icon (GtkThemingEngine *engine,
3287 GtkStateFlags state;
3288 GtkShadow *icon_shadow;
3290 state = gtk_theming_engine_get_state (engine);
3294 gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
3296 gtk_theming_engine_get (engine, state,
3297 "icon-shadow", &icon_shadow,
3300 if (icon_shadow != NULL)
3302 _gtk_icon_shadow_paint (icon_shadow, cr);
3303 _gtk_shadow_unref (icon_shadow);