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,
1493 /* Set the appropriate matrix for
1494 * patterns coming from the style context
1497 style_pattern_set_matrix (cairo_pattern_t *pattern,
1501 cairo_matrix_t matrix;
1504 if (cairo_pattern_get_type (pattern) == CAIRO_PATTERN_TYPE_SURFACE)
1506 cairo_surface_t *surface;
1508 cairo_pattern_get_surface (pattern, &surface);
1509 w = cairo_image_surface_get_width (surface);
1510 h = cairo_image_surface_get_height (surface);
1515 cairo_matrix_init_scale (&matrix, (gdouble) w / width, (gdouble) h / height);
1516 cairo_pattern_set_matrix (pattern, &matrix);
1520 render_background_internal (GtkThemingEngine *engine,
1526 GtkJunctionSides junction)
1529 cairo_pattern_t *pattern;
1530 GtkStateFlags flags;
1532 gdouble progress, alpha = 1;
1534 GtkCssBorderCornerRadius *top_left_radius, *top_right_radius;
1535 GtkCssBorderCornerRadius *bottom_left_radius, *bottom_right_radius;
1536 GtkCssBorderRadius border_radius = { { 0, }, };
1538 GtkBorderStyle border_style;
1539 gdouble mat_w, mat_h;
1540 cairo_matrix_t identity;
1542 /* Use unmodified size for pattern scaling */
1546 flags = gtk_theming_engine_get_state (engine);
1548 cairo_matrix_init_identity (&identity);
1550 gtk_theming_engine_get_background_color (engine, flags, &bg_color);
1551 gtk_theming_engine_get_border (engine, flags, &border);
1553 gtk_theming_engine_get (engine, flags,
1554 "background-image", &pattern,
1555 /* Can't use border-radius as it's an int for
1556 * backwards compat */
1557 "border-top-left-radius", &top_left_radius,
1558 "border-top-right-radius", &top_right_radius,
1559 "border-bottom-right-radius", &bottom_right_radius,
1560 "border-bottom-left-radius", &bottom_left_radius,
1561 "border-style", &border_style,
1564 if (top_left_radius)
1565 border_radius.top_left = *top_left_radius;
1566 g_free (top_left_radius);
1567 if (top_right_radius)
1568 border_radius.top_right = *top_right_radius;
1569 g_free (top_right_radius);
1570 if (bottom_right_radius)
1571 border_radius.bottom_right = *bottom_right_radius;
1572 g_free (bottom_right_radius);
1573 if (bottom_left_radius)
1574 border_radius.bottom_left = *bottom_left_radius;
1575 g_free (bottom_left_radius);
1577 border_width = MIN (MIN (border.top, border.bottom),
1578 MIN (border.left, border.right));
1580 if (border_width > 1 &&
1581 border_style == GTK_BORDER_STYLE_NONE)
1583 x += (gdouble) border_width / 2;
1584 y += (gdouble) border_width / 2;
1585 width -= border_width;
1586 height -= border_width;
1592 width -= border.left + border.right;
1593 height -= border.top + border.bottom;
1596 if (width <= 0 || height <= 0)
1600 cairo_set_line_width (cr, border_width);
1601 cairo_translate (cr, x, y);
1603 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
1605 if (gtk_theming_engine_has_class (engine, "background"))
1607 cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0); /* transparent */
1608 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
1614 cairo_pattern_t *other_pattern;
1615 GtkStateFlags other_flags;
1617 cairo_pattern_t *new_pattern = NULL;
1619 if (flags & GTK_STATE_FLAG_PRELIGHT)
1621 other_flags = flags & ~(GTK_STATE_FLAG_PRELIGHT);
1622 progress = 1 - progress;
1625 other_flags = flags | GTK_STATE_FLAG_PRELIGHT;
1627 gtk_theming_engine_get_background_color (engine, other_flags, &other_bg);
1628 gtk_theming_engine_get (engine, other_flags,
1629 "background-image", &other_pattern,
1632 if (pattern && other_pattern)
1634 cairo_pattern_type_t type, other_type;
1637 cairo_pattern_get_color_stop_count (pattern, &n0);
1638 cairo_pattern_get_color_stop_count (other_pattern, &n1);
1639 type = cairo_pattern_get_type (pattern);
1640 other_type = cairo_pattern_get_type (other_pattern);
1642 if (type == other_type && n0 == n1)
1644 gdouble offset0, red0, green0, blue0, alpha0;
1645 gdouble offset1, red1, green1, blue1, alpha1;
1646 gdouble x00, x01, y00, y01, x10, x11, y10, y11;
1647 gdouble r00, r01, r10, r11;
1650 if (type == CAIRO_PATTERN_TYPE_LINEAR)
1652 cairo_pattern_get_linear_points (pattern, &x00, &y00, &x01, &y01);
1653 cairo_pattern_get_linear_points (other_pattern, &x10, &y10, &x11, &y11);
1655 new_pattern = cairo_pattern_create_linear (x00 + (x10 - x00) * progress,
1656 y00 + (y10 - y00) * progress,
1657 x01 + (x11 - x01) * progress,
1658 y01 + (y11 - y01) * progress);
1662 cairo_pattern_get_radial_circles (pattern, &x00, &y00, &r00, &x01, &y01, &r01);
1663 cairo_pattern_get_radial_circles (other_pattern, &x10, &y10, &r10, &x11, &y11, &r11);
1665 new_pattern = cairo_pattern_create_radial (x00 + (x10 - x00) * progress,
1666 y00 + (y10 - y00) * progress,
1667 r00 + (r10 - r00) * progress,
1668 x01 + (x11 - x01) * progress,
1669 y01 + (y11 - y01) * progress,
1670 r01 + (r11 - r01) * progress);
1673 cairo_pattern_set_filter (new_pattern, CAIRO_FILTER_FAST);
1676 /* Blend both gradients into one */
1677 while (i < n0 && i < n1)
1679 cairo_pattern_get_color_stop_rgba (pattern, i,
1681 &red0, &green0, &blue0,
1683 cairo_pattern_get_color_stop_rgba (other_pattern, i,
1685 &red1, &green1, &blue1,
1688 cairo_pattern_add_color_stop_rgba (new_pattern,
1689 offset0 + ((offset1 - offset0) * progress),
1690 red0 + ((red1 - red0) * progress),
1691 green0 + ((green1 - green0) * progress),
1692 blue0 + ((blue1 - blue0) * progress),
1693 alpha0 + ((alpha1 - alpha0) * progress));
1699 /* Different pattern types, or different color
1700 * stop counts, alpha blend both patterns.
1702 _cairo_round_rectangle_sides (cr, &border_radius,
1703 0, 0, width, height,
1706 style_pattern_set_matrix (other_pattern, mat_w, mat_h);
1707 cairo_set_source (cr, other_pattern);
1708 cairo_fill_preserve (cr);
1710 cairo_pattern_set_matrix (other_pattern, &identity);
1712 /* Set alpha for posterior drawing
1713 * of the target pattern
1715 alpha = 1 - progress;
1718 else if (pattern || other_pattern)
1722 gdouble x0, y0, x1, y1, r0, r1;
1725 /* Blend a pattern with a color */
1730 progress = 1 - progress;
1738 if (cairo_pattern_get_type (p) == CAIRO_PATTERN_TYPE_LINEAR)
1740 cairo_pattern_get_linear_points (p, &x0, &y0, &x1, &y1);
1741 new_pattern = cairo_pattern_create_linear (x0, y0, x1, y1);
1745 cairo_pattern_get_radial_circles (p, &x0, &y0, &r0, &x1, &y1, &r1);
1746 new_pattern = cairo_pattern_create_radial (x0, y0, r0, x1, y1, r1);
1749 cairo_pattern_get_color_stop_count (p, &n);
1751 for (i = 0; i < n; i++)
1753 gdouble red1, green1, blue1, alpha1;
1756 cairo_pattern_get_color_stop_rgba (p, i,
1758 &red1, &green1, &blue1,
1760 cairo_pattern_add_color_stop_rgba (new_pattern, offset,
1761 c->red + ((red1 - c->red) * progress),
1762 c->green + ((green1 - c->green) * progress),
1763 c->blue + ((blue1 - c->blue) * progress),
1764 c->alpha + ((alpha1 - c->alpha) * progress));
1769 /* Merge just colors */
1770 new_pattern = cairo_pattern_create_rgba (CLAMP (bg_color.red + ((other_bg.red - bg_color.red) * progress), 0, 1),
1771 CLAMP (bg_color.green + ((other_bg.green - bg_color.green) * progress), 0, 1),
1772 CLAMP (bg_color.blue + ((other_bg.blue - bg_color.blue) * progress), 0, 1),
1773 CLAMP (bg_color.alpha + ((other_bg.alpha - bg_color.alpha) * progress), 0, 1));
1778 /* Replace pattern to use */
1779 cairo_pattern_destroy (pattern);
1780 pattern = new_pattern;
1784 cairo_pattern_destroy (other_pattern);
1787 _cairo_round_rectangle_sides (cr, &border_radius,
1788 0, 0, width, height,
1792 style_pattern_set_matrix (pattern, mat_w, mat_h);
1793 cairo_set_source (cr, pattern);
1796 gdk_cairo_set_source_rgba (cr, &bg_color);
1800 if (border_width > 1 &&
1801 border_style != GTK_BORDER_STYLE_NONE)
1803 /* stroke with the same source, so the background
1804 * has exactly the shape than the frame, this
1805 * is important so gtk_render_background() and
1806 * gtk_render_frame() fit perfectly with round
1809 cairo_fill_preserve (cr);
1818 _cairo_round_rectangle_sides (cr, &border_radius,
1819 0, 0, width, height,
1823 cairo_paint_with_alpha (cr, alpha);
1830 cairo_pattern_set_matrix (pattern, &identity);
1831 cairo_pattern_destroy (pattern);
1838 gtk_theming_engine_render_background (GtkThemingEngine *engine,
1845 GtkJunctionSides junction;
1847 junction = gtk_theming_engine_get_junction_sides (engine);
1849 render_background_internal (engine, cr,
1850 x, y, width, height,
1854 /* Renders the small triangle on corners so
1855 * frames with 0 radius have a 3D-like effect
1858 _cairo_corner_triangle (cairo_t *cr,
1865 cairo_move_to (cr, x + 0.5, y + size - 0.5);
1866 cairo_line_to (cr, x + size - 0.5, y + size - 0.5);
1867 cairo_line_to (cr, x + size - 0.5, y + 0.5);
1869 for (i = 1; i < size - 1; i++)
1871 cairo_move_to (cr, x + size - 0.5, y + i + 0.5);
1872 cairo_line_to (cr, x + (size - i) - 0.5, y + i + 0.5);
1877 gtk_themeing_engine_apply_junction_to_radius (GtkCssBorderRadius *border_radius,
1878 GtkJunctionSides junction)
1880 if (junction & GTK_JUNCTION_CORNER_TOPLEFT)
1881 border_radius->top_left.horizontal = border_radius->top_left.vertical = 0;
1882 if (junction & GTK_JUNCTION_CORNER_TOPRIGHT)
1883 border_radius->top_right.horizontal = border_radius->top_right.vertical = 0;
1884 if (junction & GTK_JUNCTION_CORNER_BOTTOMRIGHT)
1885 border_radius->bottom_right.horizontal = border_radius->bottom_right.vertical = 0;
1886 if (junction & GTK_JUNCTION_CORNER_BOTTOMLEFT)
1887 border_radius->bottom_left.horizontal = border_radius->bottom_left.vertical = 0;
1891 render_frame_internal (GtkThemingEngine *engine,
1898 GtkJunctionSides junction)
1900 GtkStateFlags state;
1902 GdkRGBA border_color;
1903 GtkBorderStyle border_style;
1905 GtkCssBorderCornerRadius *top_left_radius, *top_right_radius;
1906 GtkCssBorderCornerRadius *bottom_left_radius, *bottom_right_radius;
1907 GtkCssBorderRadius border_radius = { { 0, }, };
1908 gdouble progress, d1, d2, m;
1911 gboolean uniform_border;
1913 state = gtk_theming_engine_get_state (engine);
1915 gtk_theming_engine_get_border_color (engine, state, &border_color);
1916 gtk_theming_engine_get_border (engine, state, &border);
1918 gtk_theming_engine_get (engine, state,
1919 "border-style", &border_style,
1920 /* Can't use border-radius as it's an int for
1921 * backwards compat */
1922 "border-top-left-radius", &top_left_radius,
1923 "border-top-right-radius", &top_right_radius,
1924 "border-bottom-right-radius", &bottom_right_radius,
1925 "border-bottom-left-radius", &bottom_left_radius,
1928 if (top_left_radius)
1929 border_radius.top_left = *top_left_radius;
1930 g_free (top_left_radius);
1931 if (top_right_radius)
1932 border_radius.top_right = *top_right_radius;
1933 g_free (top_right_radius);
1934 if (bottom_right_radius)
1935 border_radius.bottom_right = *bottom_right_radius;
1936 g_free (bottom_right_radius);
1937 if (bottom_left_radius)
1938 border_radius.bottom_left = *bottom_left_radius;
1939 g_free (bottom_left_radius);
1941 gtk_themeing_engine_apply_junction_to_radius (&border_radius, junction);
1943 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
1944 border_width = MIN (MIN (border.top, border.bottom),
1945 MIN (border.left, border.right));
1946 uniform_border = (border.top == border.bottom &&
1947 border.top == border.left &&
1948 border.top == border.right);
1952 GtkStateFlags other_state;
1953 GdkRGBA other_color;
1955 if (state & GTK_STATE_FLAG_PRELIGHT)
1957 other_state = state & ~(GTK_STATE_FLAG_PRELIGHT);
1958 progress = 1 - progress;
1961 other_state = state | GTK_STATE_FLAG_PRELIGHT;
1963 gtk_theming_engine_get_border_color (engine, other_state, &other_color);
1965 border_color.red = CLAMP (border_color.red + ((other_color.red - border_color.red) * progress), 0, 1);
1966 border_color.green = CLAMP (border_color.green + ((other_color.green - border_color.green) * progress), 0, 1);
1967 border_color.blue = CLAMP (border_color.blue + ((other_color.blue - border_color.blue) * progress), 0, 1);
1968 border_color.alpha = CLAMP (border_color.alpha + ((other_color.alpha - border_color.alpha) * progress), 0, 1);
1973 color_shade (&border_color, 1.8, &lighter);
1975 switch (border_style)
1977 case GTK_BORDER_STYLE_NONE:
1979 case GTK_BORDER_STYLE_SOLID:
1980 cairo_set_line_width (cr, border_width);
1981 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
1983 gdk_cairo_set_source_rgba (cr, &border_color);
1987 if (border_width > 1)
1989 x += (gdouble) border_width / 2;
1990 y += (gdouble) border_width / 2;
1991 width -= border_width;
1992 height -= border_width;
1994 else if (border_width == 1)
2002 _cairo_round_rectangle_sides (cr, &border_radius,
2003 x, y, width, height,
2004 SIDE_ALL & ~(hidden_side));
2010 _cairo_uneven_frame (cr, &border_radius,
2011 x, y, width, height,
2018 case GTK_BORDER_STYLE_INSET:
2019 case GTK_BORDER_STYLE_OUTSET:
2020 cairo_set_line_width (cr, border_width);
2021 cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
2023 if (border_width > 1)
2025 d1 = (gdouble) border_width / 2;
2036 m = MIN (width, height);
2041 if (border_style == GTK_BORDER_STYLE_INSET)
2042 gdk_cairo_set_source_rgba (cr, &lighter);
2044 gdk_cairo_set_source_rgba (cr, &border_color);
2046 _cairo_round_rectangle_sides (cr, &border_radius,
2048 width - d2, height - d2,
2049 (SIDE_BOTTOM | SIDE_RIGHT) & ~(hidden_side));
2052 if (border_style == GTK_BORDER_STYLE_INSET)
2053 gdk_cairo_set_source_rgba (cr, &border_color);
2055 gdk_cairo_set_source_rgba (cr, &lighter);
2057 _cairo_round_rectangle_sides (cr, &border_radius,
2059 width - d2, height - d2,
2060 (SIDE_TOP | SIDE_LEFT) & ~(hidden_side));
2068 if (border_style == GTK_BORDER_STYLE_INSET)
2069 gdk_cairo_set_source_rgba (cr, &lighter);
2071 gdk_cairo_set_source_rgba (cr, &border_color);
2073 _cairo_uneven_frame (cr, &border_radius,
2074 x, y, width, height,
2079 cairo_move_to (cr, x, y);
2080 cairo_line_to (cr, x + width, y);
2082 x + width - border.right - border_radius.top_right.horizontal / 2,
2083 y + border.top + border_radius.top_right.vertical / 2);
2085 x + width - border.right - border_radius.bottom_right.horizontal / 2,
2086 y + height - border.bottom - border_radius.bottom_right.vertical / 2);
2088 x + border.left + border_radius.bottom_left.horizontal / 2,
2089 y + height - border.bottom - border_radius.bottom_left.vertical / 2);
2090 cairo_line_to (cr, x, y + height);
2091 cairo_close_path (cr);
2095 if (border_style == GTK_BORDER_STYLE_INSET)
2096 gdk_cairo_set_source_rgba (cr, &border_color);
2098 gdk_cairo_set_source_rgba (cr, &lighter);
2100 _cairo_uneven_frame (cr, &border_radius,
2101 x, y, width, height,
2107 if (border_width > 1)
2109 /* overprint top/right and bottom/left corner
2110 * triangles if there are square corners there,
2111 * to give the box a 3D-like appearance.
2115 if (border_style == GTK_BORDER_STYLE_INSET)
2116 gdk_cairo_set_source_rgba (cr, &lighter);
2118 gdk_cairo_set_source_rgba (cr, &border_color);
2120 cairo_set_line_width (cr, 1);
2122 if ((junction & GTK_JUNCTION_CORNER_TOPRIGHT) != 0)
2123 _cairo_corner_triangle (cr,
2124 x + width - border_width, y,
2127 if ((junction & GTK_JUNCTION_CORNER_BOTTOMLEFT) != 0)
2128 _cairo_corner_triangle (cr,
2129 x, y + height - border_width,
2143 gtk_theming_engine_render_frame (GtkThemingEngine *engine,
2150 GtkStateFlags flags;
2151 GtkBorderStyle border_style;
2152 GtkJunctionSides junction;
2153 GtkBorderImage *border_image;
2156 flags = gtk_theming_engine_get_state (engine);
2157 junction = gtk_theming_engine_get_junction_sides (engine);
2158 gtk_theming_engine_get_border (engine, flags, &border);
2160 gtk_theming_engine_get (engine, flags,
2161 "border-image", &border_image,
2162 "border-style", &border_style,
2165 if (border_image != NULL)
2167 _gtk_border_image_render (border_image, &border,
2168 cr, x, y, width, height);
2169 _gtk_border_image_unref (border_image);
2171 else if (border_style != GTK_BORDER_STYLE_NONE)
2172 render_frame_internal (engine, cr,
2173 x, y, width, height,
2178 gtk_theming_engine_render_expander (GtkThemingEngine *engine,
2185 GtkStateFlags flags;
2186 GdkRGBA outline_color, fg_color;
2187 double vertical_overshoot;
2190 double interp; /* interpolation factor for center position */
2191 double x_double_horz, y_double_horz;
2192 double x_double_vert, y_double_vert;
2193 double x_double, y_double;
2196 gboolean running, is_rtl;
2200 flags = gtk_theming_engine_get_state (engine);
2202 gtk_theming_engine_get_color (engine, flags, &fg_color);
2203 gtk_theming_engine_get_border_color (engine, flags, &outline_color);
2205 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress);
2206 is_rtl = (gtk_theming_engine_get_direction (engine) == GTK_TEXT_DIR_RTL);
2210 progress = (flags & GTK_STATE_FLAG_ACTIVE) ? 1 : 0;
2212 if (!gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_HORIZONTAL))
2215 angle = (G_PI) - ((G_PI / 2) * progress);
2217 angle = (G_PI / 2) * progress;
2222 angle = (G_PI / 2) + ((G_PI / 2) * progress);
2224 angle = (G_PI / 2) - ((G_PI / 2) * progress);
2229 /* Compute distance that the stroke extends beyonds the end
2230 * of the triangle we draw.
2232 vertical_overshoot = line_width / 2.0 * (1. / tan (G_PI / 8));
2234 /* For odd line widths, we end the vertical line of the triangle
2235 * at a half pixel, so we round differently.
2237 if (line_width % 2 == 1)
2238 vertical_overshoot = ceil (0.5 + vertical_overshoot) - 0.5;
2240 vertical_overshoot = ceil (vertical_overshoot);
2242 /* Adjust the size of the triangle we draw so that the entire stroke fits
2244 diameter = (gint) MAX (3, width - 2 * vertical_overshoot);
2246 /* If the line width is odd, we want the diameter to be even,
2247 * and vice versa, so force the sum to be odd. This relationship
2248 * makes the point of the triangle look right.
2250 diameter -= (1 - (diameter + line_width) % 2);
2252 radius = diameter / 2.;
2254 /* Adjust the center so that the stroke is properly aligned with
2255 * the pixel grid. The center adjustment is different for the
2256 * horizontal and vertical orientations. For intermediate positions
2257 * we interpolate between the two.
2259 x_double_vert = floor ((x + width / 2) - (radius + line_width) / 2.) + (radius + line_width) / 2.;
2260 y_double_vert = (y + height / 2) - 0.5;
2262 x_double_horz = (x + width / 2) - 0.5;
2263 y_double_horz = floor ((y + height / 2) - (radius + line_width) / 2.) + (radius + line_width) / 2.;
2265 x_double = x_double_vert * (1 - interp) + x_double_horz * interp;
2266 y_double = y_double_vert * (1 - interp) + y_double_horz * interp;
2268 cairo_translate (cr, x_double, y_double);
2269 cairo_rotate (cr, angle);
2271 cairo_move_to (cr, - radius / 2., - radius);
2272 cairo_line_to (cr, radius / 2., 0);
2273 cairo_line_to (cr, - radius / 2., radius);
2274 cairo_close_path (cr);
2276 cairo_set_line_width (cr, line_width);
2278 gdk_cairo_set_source_rgba (cr, &fg_color);
2280 cairo_fill_preserve (cr);
2282 gdk_cairo_set_source_rgba (cr, &outline_color);
2289 gtk_theming_engine_render_focus (GtkThemingEngine *engine,
2296 GtkStateFlags flags;
2302 flags = gtk_theming_engine_get_state (engine);
2304 gtk_theming_engine_get_color (engine, flags, &color);
2306 gtk_theming_engine_get_style (engine,
2307 "focus-line-width", &line_width,
2308 "focus-line-pattern", (gchar *) &dash_list,
2311 cairo_set_line_width (cr, (gdouble) line_width);
2315 gint n_dashes = strlen ((const gchar *) dash_list);
2316 gdouble *dashes = g_new (gdouble, n_dashes);
2317 gdouble total_length = 0;
2318 gdouble dash_offset;
2321 for (i = 0; i < n_dashes; i++)
2323 dashes[i] = dash_list[i];
2324 total_length += dash_list[i];
2327 /* The dash offset here aligns the pattern to integer pixels
2328 * by starting the dash at the right side of the left border
2329 * Negative dash offsets in cairo don't work
2330 * (https://bugs.freedesktop.org/show_bug.cgi?id=2729)
2332 dash_offset = - line_width / 2.;
2334 while (dash_offset < 0)
2335 dash_offset += total_length;
2337 cairo_set_dash (cr, dashes, n_dashes, dash_offset);
2341 cairo_rectangle (cr,
2342 x + line_width / 2.,
2343 y + line_width / 2.,
2345 height - line_width);
2347 gdk_cairo_set_source_rgba (cr, &color);
2356 gtk_theming_engine_render_line (GtkThemingEngine *engine,
2363 GdkRGBA bg_color, darker, lighter;
2364 GtkStateFlags flags;
2365 gint i, thickness, thickness_dark, thickness_light, len;
2366 cairo_matrix_t matrix;
2369 /* FIXME: thickness */
2371 thickness_dark = thickness / 2;
2372 thickness_light = thickness - thickness_dark;
2374 flags = gtk_theming_engine_get_state (engine);
2377 gtk_theming_engine_get_background_color (engine, flags, &bg_color);
2378 color_shade (&bg_color, 0.7, &darker);
2379 color_shade (&bg_color, 1.3, &lighter);
2381 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
2382 cairo_set_line_width (cr, 1);
2384 angle = atan2 (x1 - x0, y1 - y0);
2385 angle = (2 * G_PI) - angle;
2388 cairo_get_matrix (cr, &matrix);
2389 cairo_matrix_translate (&matrix, x0, y0);
2390 cairo_matrix_rotate (&matrix, angle);
2391 cairo_set_matrix (cr, &matrix);
2396 len = (gint) sqrt ((x1 * x1) + (y1 * y1));
2398 y0 = -thickness_dark;
2400 for (i = 0; i < thickness_dark; i++)
2402 gdk_cairo_set_source_rgba (cr, &lighter);
2403 add_path_line (cr, len - i - 1.5, y0, len - 0.5, y0);
2406 gdk_cairo_set_source_rgba (cr, &darker);
2407 add_path_line (cr, 0.5, y0, len - i - 1.5, y0);
2413 for (i = 0; i < thickness_light; i++)
2415 gdk_cairo_set_source_rgba (cr, &darker);
2416 add_path_line (cr, 0.5, y0, thickness_light - i + 0.5, y0);
2419 gdk_cairo_set_source_rgba (cr, &lighter);
2420 add_path_line (cr, thickness_light - i + 0.5, y0, len - 0.5, y0);
2430 prepare_context_for_layout (cairo_t *cr,
2433 PangoLayout *layout)
2435 const PangoMatrix *matrix;
2437 matrix = pango_context_get_matrix (pango_layout_get_context (layout));
2439 cairo_move_to (cr, x, y);
2443 cairo_matrix_t cairo_matrix;
2445 cairo_matrix_init (&cairo_matrix,
2446 matrix->xx, matrix->yx,
2447 matrix->xy, matrix->yy,
2448 matrix->x0, matrix->y0);
2450 cairo_transform (cr, &cairo_matrix);
2455 gtk_theming_engine_render_layout (GtkThemingEngine *engine,
2459 PangoLayout *layout)
2462 GtkShadow *text_shadow = NULL;
2463 GtkStateFlags flags;
2468 flags = gtk_theming_engine_get_state (engine);
2469 gtk_theming_engine_get_color (engine, flags, &fg_color);
2471 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
2475 GtkStateFlags other_flags;
2478 if (flags & GTK_STATE_FLAG_PRELIGHT)
2480 other_flags = flags & ~(GTK_STATE_FLAG_PRELIGHT);
2481 progress = 1 - progress;
2484 other_flags = flags | GTK_STATE_FLAG_PRELIGHT;
2486 gtk_theming_engine_get_color (engine, other_flags, &other_fg);
2488 fg_color.red = CLAMP (fg_color.red + ((other_fg.red - fg_color.red) * progress), 0, 1);
2489 fg_color.green = CLAMP (fg_color.green + ((other_fg.green - fg_color.green) * progress), 0, 1);
2490 fg_color.blue = CLAMP (fg_color.blue + ((other_fg.blue - fg_color.blue) * progress), 0, 1);
2491 fg_color.alpha = CLAMP (fg_color.alpha + ((other_fg.alpha - fg_color.alpha) * progress), 0, 1);
2494 gtk_theming_engine_get (engine, flags,
2495 "text-shadow", &text_shadow,
2498 prepare_context_for_layout (cr, x, y, layout);
2500 if (text_shadow != NULL)
2502 _gtk_text_shadow_paint_layout (text_shadow, cr, layout);
2503 _gtk_shadow_unref (text_shadow);
2506 gdk_cairo_set_source_rgba (cr, &fg_color);
2507 pango_cairo_show_layout (cr, layout);
2513 gtk_theming_engine_render_slider (GtkThemingEngine *engine,
2519 GtkOrientation orientation)
2521 const GtkWidgetPath *path;
2524 path = gtk_theming_engine_get_path (engine);
2526 gtk_theming_engine_render_background (engine, cr, x, y, width, height);
2527 gtk_theming_engine_render_frame (engine, cr, x, y, width, height);
2529 /* FIXME: thickness */
2532 if (gtk_widget_path_is_type (path, GTK_TYPE_SCALE))
2534 if (orientation == GTK_ORIENTATION_VERTICAL)
2535 gtk_theming_engine_render_line (engine, cr,
2537 y + (gint) height / 2,
2538 x + width - thickness - 1,
2539 y + (gint) height / 2);
2541 gtk_theming_engine_render_line (engine, cr,
2542 x + (gint) width / 2,
2544 x + (gint) width / 2,
2545 y + height - thickness - 1);
2550 gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
2556 GtkPositionType gap_side,
2560 GtkJunctionSides junction;
2561 GtkStateFlags state;
2563 GtkCssBorderCornerRadius *top_left_radius, *top_right_radius;
2564 GtkCssBorderCornerRadius *bottom_left_radius, *bottom_right_radius;
2565 GtkCssBorderRadius border_radius = { { 0, }, };
2566 gdouble x0, y0, x1, y1, xc, yc, wc, hc;
2569 xc = yc = wc = hc = 0;
2570 state = gtk_theming_engine_get_state (engine);
2571 junction = gtk_theming_engine_get_junction_sides (engine);
2573 gtk_theming_engine_get_border (engine, state, &border);
2574 gtk_theming_engine_get (engine, state,
2575 /* Can't use border-radius as it's an int for
2576 * backwards compat */
2577 "border-top-left-radius", &top_left_radius,
2578 "border-top-right-radius", &top_right_radius,
2579 "border-bottom-right-radius", &bottom_right_radius,
2580 "border-bottom-left-radius", &bottom_left_radius,
2583 if (top_left_radius)
2584 border_radius.top_left = *top_left_radius;
2585 g_free (top_left_radius);
2586 if (top_right_radius)
2587 border_radius.top_right = *top_right_radius;
2588 g_free (top_right_radius);
2589 if (bottom_right_radius)
2590 border_radius.bottom_right = *bottom_right_radius;
2591 g_free (bottom_right_radius);
2592 if (bottom_left_radius)
2593 border_radius.bottom_left = *bottom_left_radius;
2594 g_free (bottom_left_radius);
2596 border_width = MIN (MIN (border.top, border.bottom),
2597 MIN (border.left, border.right));
2604 xc = x + xy0_gap + border_width;
2606 wc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
2609 if (xy0_gap < border_radius.top_left.horizontal)
2610 junction |= GTK_JUNCTION_CORNER_TOPLEFT;
2612 if (xy1_gap > width - border_radius.top_right.horizontal)
2613 junction |= GTK_JUNCTION_CORNER_TOPRIGHT;
2615 case GTK_POS_BOTTOM:
2616 xc = x + xy0_gap + border_width;
2617 yc = y + height - border_width;
2618 wc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
2621 if (xy0_gap < border_radius.bottom_left.horizontal)
2622 junction |= GTK_JUNCTION_CORNER_BOTTOMLEFT;
2624 if (xy1_gap > width - border_radius.bottom_right.horizontal)
2625 junction |= GTK_JUNCTION_CORNER_BOTTOMRIGHT;
2630 yc = y + xy0_gap + border_width;
2632 hc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
2634 if (xy0_gap < border_radius.top_left.vertical)
2635 junction |= GTK_JUNCTION_CORNER_TOPLEFT;
2637 if (xy1_gap > height - border_radius.bottom_left.vertical)
2638 junction |= GTK_JUNCTION_CORNER_BOTTOMLEFT;
2642 xc = x + width - border_width;
2643 yc = y + xy0_gap + border_width;
2645 hc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
2647 if (xy0_gap < border_radius.top_right.vertical)
2648 junction |= GTK_JUNCTION_CORNER_TOPRIGHT;
2650 if (xy1_gap > height - border_radius.bottom_right.vertical)
2651 junction |= GTK_JUNCTION_CORNER_BOTTOMRIGHT;
2656 cairo_clip_extents (cr, &x0, &y0, &x1, &y1);
2657 cairo_rectangle (cr, x0, y0, x1 - x0, yc - y0);
2658 cairo_rectangle (cr, x0, yc, xc - x0, hc);
2659 cairo_rectangle (cr, xc + wc, yc, x1 - (xc + wc), hc);
2660 cairo_rectangle (cr, x0, yc + hc, x1 - x0, y1 - (yc + hc));
2663 render_frame_internal (engine, cr,
2664 x, y, width, height,
2671 gtk_theming_engine_render_extension (GtkThemingEngine *engine,
2677 GtkPositionType gap_side)
2679 GtkJunctionSides junction = 0;
2680 guint hidden_side = 0;
2687 junction = GTK_JUNCTION_LEFT;
2688 hidden_side = SIDE_LEFT;
2690 cairo_translate (cr, x + width, y);
2691 cairo_rotate (cr, G_PI / 2);
2694 junction = GTK_JUNCTION_RIGHT;
2695 hidden_side = SIDE_RIGHT;
2697 cairo_translate (cr, x, y + height);
2698 cairo_rotate (cr, - G_PI / 2);
2701 junction = GTK_JUNCTION_TOP;
2702 hidden_side = SIDE_TOP;
2704 cairo_translate (cr, x + width, y + height);
2705 cairo_rotate (cr, G_PI);
2707 case GTK_POS_BOTTOM:
2708 junction = GTK_JUNCTION_BOTTOM;
2709 hidden_side = SIDE_BOTTOM;
2711 cairo_translate (cr, x, y);
2715 if (gap_side == GTK_POS_TOP ||
2716 gap_side == GTK_POS_BOTTOM)
2717 render_background_internal (engine, cr,
2718 0, 0, width, height,
2719 GTK_JUNCTION_BOTTOM);
2721 render_background_internal (engine, cr,
2722 0, 0, height, width,
2723 GTK_JUNCTION_BOTTOM);
2728 render_frame_internal (engine, cr,
2729 x, y, width, height,
2730 hidden_side, junction);
2736 render_dot (cairo_t *cr,
2737 const GdkRGBA *lighter,
2738 const GdkRGBA *darker,
2743 size = CLAMP ((gint) size, 2, 3);
2747 gdk_cairo_set_source_rgba (cr, lighter);
2748 cairo_rectangle (cr, x, y, 1, 1);
2749 cairo_rectangle (cr, x + 1, y + 1, 1, 1);
2754 gdk_cairo_set_source_rgba (cr, lighter);
2755 cairo_rectangle (cr, x, y, 2, 1);
2756 cairo_rectangle (cr, x, y, 1, 2);
2759 gdk_cairo_set_source_rgba (cr, darker);
2760 cairo_rectangle (cr, x + 1, y + 1, 2, 1);
2761 cairo_rectangle (cr, x + 2, y, 1, 2);
2767 gtk_theming_engine_render_handle (GtkThemingEngine *engine,
2774 GtkStateFlags flags;
2775 GdkRGBA bg_color, lighter, darker;
2776 GtkJunctionSides sides;
2780 flags = gtk_theming_engine_get_state (engine);
2782 cairo_set_line_width (cr, 1.0);
2783 sides = gtk_theming_engine_get_junction_sides (engine);
2784 gtk_theming_engine_get_background_color (engine, flags, &bg_color);
2786 color_shade (&bg_color, 0.7, &darker);
2787 color_shade (&bg_color, 1.3, &lighter);
2789 render_background_internal (engine, cr, x, y, width, height, sides);
2791 if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_GRIP))
2793 /* reduce confusing values to a meaningful state */
2794 if ((sides & (GTK_JUNCTION_CORNER_TOPLEFT | GTK_JUNCTION_CORNER_BOTTOMRIGHT)) == (GTK_JUNCTION_CORNER_TOPLEFT | GTK_JUNCTION_CORNER_BOTTOMRIGHT))
2795 sides &= ~GTK_JUNCTION_CORNER_TOPLEFT;
2797 if ((sides & (GTK_JUNCTION_CORNER_TOPRIGHT | GTK_JUNCTION_CORNER_BOTTOMLEFT)) == (GTK_JUNCTION_CORNER_TOPRIGHT | GTK_JUNCTION_CORNER_BOTTOMLEFT))
2798 sides &= ~GTK_JUNCTION_CORNER_TOPRIGHT;
2801 sides = GTK_JUNCTION_CORNER_BOTTOMRIGHT;
2803 /* align drawing area to the connected side */
2804 if (sides == GTK_JUNCTION_LEFT)
2809 else if (sides == GTK_JUNCTION_CORNER_TOPLEFT)
2813 else if (height < width)
2816 else if (sides == GTK_JUNCTION_CORNER_BOTTOMLEFT)
2818 /* make it square, aligning to bottom left */
2821 y += (height - width);
2824 else if (height < width)
2827 else if (sides == GTK_JUNCTION_RIGHT)
2829 /* aligning to right */
2832 x += (width - height);
2836 else if (sides == GTK_JUNCTION_CORNER_TOPRIGHT)
2840 else if (height < width)
2842 x += (width - height);
2846 else if (sides == GTK_JUNCTION_CORNER_BOTTOMRIGHT)
2848 /* make it square, aligning to bottom right */
2851 y += (height - width);
2854 else if (height < width)
2856 x += (width - height);
2860 else if (sides == GTK_JUNCTION_TOP)
2865 else if (sides == GTK_JUNCTION_BOTTOM)
2867 /* align to bottom */
2870 y += (height - width);
2875 g_assert_not_reached ();
2877 if (sides == GTK_JUNCTION_LEFT ||
2878 sides == GTK_JUNCTION_RIGHT)
2884 while (xi < x + width)
2886 gdk_cairo_set_source_rgba (cr, &lighter);
2887 add_path_line (cr, x, y, x, y + height);
2891 gdk_cairo_set_source_rgba (cr, &darker);
2892 add_path_line (cr, xi, y, xi, y + height);
2897 else if (sides == GTK_JUNCTION_TOP ||
2898 sides == GTK_JUNCTION_BOTTOM)
2904 while (yi < y + height)
2906 gdk_cairo_set_source_rgba (cr, &lighter);
2907 add_path_line (cr, x, yi, x + width, yi);
2911 gdk_cairo_set_source_rgba (cr, &darker);
2912 add_path_line (cr, x, yi, x + width, yi);
2917 else if (sides == GTK_JUNCTION_CORNER_TOPLEFT)
2926 gdk_cairo_set_source_rgba (cr, &darker);
2927 add_path_line (cr, xi, y, x, yi);
2933 add_path_line (cr, xi, y, x, yi);
2939 gdk_cairo_set_source_rgba (cr, &lighter);
2940 add_path_line (cr, xi, y, x, yi);
2947 else if (sides == GTK_JUNCTION_CORNER_TOPRIGHT)
2954 while (xi < (x + width - 3))
2956 gdk_cairo_set_source_rgba (cr, &lighter);
2957 add_path_line (cr, xi, y, x + width, yi);
2963 gdk_cairo_set_source_rgba (cr, &darker);
2964 add_path_line (cr, xi, y, x + width, yi);
2970 add_path_line (cr, xi, y, x + width, yi);
2977 else if (sides == GTK_JUNCTION_CORNER_BOTTOMLEFT)
2986 gdk_cairo_set_source_rgba (cr, &darker);
2987 add_path_line (cr, x, yi, xi, y + height);
2993 add_path_line (cr, x, yi, xi, y + height);
2999 gdk_cairo_set_source_rgba (cr, &lighter);
3000 add_path_line (cr, x, yi, xi, y + height);
3007 else if (sides == GTK_JUNCTION_CORNER_BOTTOMRIGHT)
3014 while (xi < (x + width - 3))
3016 gdk_cairo_set_source_rgba (cr, &lighter);
3017 add_path_line (cr, xi, y + height, x + width, yi);
3023 gdk_cairo_set_source_rgba (cr, &darker);
3024 add_path_line (cr, xi, y + height, x + width, yi);
3030 add_path_line (cr, xi, y + height, x + width, yi);
3038 else if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_PANE_SEPARATOR))
3041 for (xx = x + width / 2 - 15; xx <= x + width / 2 + 15; xx += 5)
3042 render_dot (cr, &lighter, &darker, xx, y + height / 2 - 1, 3);
3044 for (yy = y + height / 2 - 15; yy <= y + height / 2 + 15; yy += 5)
3045 render_dot (cr, &lighter, &darker, x + width / 2 - 1, yy, 3);
3049 for (yy = y; yy < y + height; yy += 3)
3050 for (xx = x; xx < x + width; xx += 6)
3052 render_dot (cr, &lighter, &darker, xx, yy, 2);
3053 render_dot (cr, &lighter, &darker, xx + 3, yy + 1, 2);
3061 gtk_theming_engine_render_activity (GtkThemingEngine *engine,
3068 if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_SPINNER))
3070 GtkStateFlags state;
3071 guint num_steps, step;
3080 state = gtk_theming_engine_get_state (engine);
3081 gtk_theming_engine_get_color (engine, state, &color);
3083 if (gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress))
3084 step = (guint) (progress * num_steps);
3090 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
3091 cairo_set_line_width (cr, 2.0);
3092 cairo_translate (cr, x + width / 2, y + height / 2);
3094 radius = MIN (width / 2, height / 2);
3095 half = num_steps / 2;
3097 for (i = 0; i < num_steps; i++)
3099 gint inset = 0.7 * radius;
3101 /* transparency is a function of time and intial value */
3102 gdouble t = 1.0 - (gdouble) ((i + step) % num_steps) / num_steps;
3103 gdouble xscale = - sin (i * G_PI / half);
3104 gdouble yscale = - cos (i * G_PI / half);
3106 cairo_set_source_rgba (cr,
3113 (radius - inset) * xscale,
3114 (radius - inset) * yscale);
3125 gtk_theming_engine_render_background (engine, cr, x, y, width, height);
3126 gtk_theming_engine_render_frame (engine, cr, x, y, width, height);
3131 scale_or_ref (GdkPixbuf *src,
3135 if (width == gdk_pixbuf_get_width (src) &&
3136 height == gdk_pixbuf_get_height (src))
3137 return g_object_ref (src);
3139 return gdk_pixbuf_scale_simple (src,
3141 GDK_INTERP_BILINEAR);
3145 lookup_icon_size (GtkThemingEngine *engine,
3151 GtkSettings *settings;
3153 screen = gtk_theming_engine_get_screen (engine);
3154 settings = gtk_settings_get_for_screen (screen);
3156 return gtk_icon_size_lookup_for_settings (settings, size, width, height);
3159 /* Kudos to the gnome-panel guys. */
3161 colorshift_pixbuf (GdkPixbuf *src,
3166 gint width, height, has_alpha, src_rowstride, dest_rowstride;
3167 guchar *target_pixels;
3168 guchar *original_pixels;
3174 has_alpha = gdk_pixbuf_get_has_alpha (src);
3175 width = gdk_pixbuf_get_width (src);
3176 height = gdk_pixbuf_get_height (src);
3177 src_rowstride = gdk_pixbuf_get_rowstride (src);
3178 dest_rowstride = gdk_pixbuf_get_rowstride (dest);
3179 original_pixels = gdk_pixbuf_get_pixels (src);
3180 target_pixels = gdk_pixbuf_get_pixels (dest);
3182 for (i = 0; i < height; i++)
3184 pix_dest = target_pixels + i * dest_rowstride;
3185 pix_src = original_pixels + i * src_rowstride;
3187 for (j = 0; j < width; j++)
3194 *(pix_dest++) = CLAMP (val, 0, 255);
3197 *(pix_dest++) = CLAMP (val, 0, 255);
3200 *(pix_dest++) = CLAMP (val, 0, 255);
3203 *(pix_dest++) = *(pix_src++);
3209 gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine *engine,
3210 const GtkIconSource *source,
3215 GdkPixbuf *base_pixbuf;
3216 GtkStateFlags state;
3220 base_pixbuf = gtk_icon_source_get_pixbuf (source);
3221 state = gtk_theming_engine_get_state (engine);
3223 g_return_val_if_fail (base_pixbuf != NULL, NULL);
3225 if (size != (GtkIconSize) -1 &&
3226 !lookup_icon_size (engine, size, &width, &height))
3228 g_warning (G_STRLOC ": invalid icon size '%d'", size);
3232 /* If the size was wildcarded, and we're allowed to scale, then scale; otherwise,
3235 if (size != (GtkIconSize) -1 &&
3236 gtk_icon_source_get_size_wildcarded (source))
3237 scaled = scale_or_ref (base_pixbuf, width, height);
3239 scaled = g_object_ref (base_pixbuf);
3241 /* If the state was wildcarded, then generate a state. */
3242 if (gtk_icon_source_get_state_wildcarded (source))
3244 if (state & GTK_STATE_FLAG_INSENSITIVE)
3246 stated = gdk_pixbuf_copy (scaled);
3247 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
3249 g_object_unref (scaled);
3251 else if (state & GTK_STATE_FLAG_PRELIGHT)
3253 stated = gdk_pixbuf_copy (scaled);
3254 colorshift_pixbuf (scaled, stated, 30);
3255 g_object_unref (scaled);