1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2010 Carlos Garnacho <carlosg@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
25 #include <gtk/gtkthemingengine.h>
26 #include <gtk/gtkstylecontext.h>
27 #include <gtk/gtkintl.h>
29 #include "gtkprivate.h"
30 #include "gtkmodulesprivate.h"
31 #include "gtkborderimageprivate.h"
33 #include "gtkshadowprivate.h"
34 #include "gtkcsstypesprivate.h"
35 #include "gtkthemingengineprivate.h"
36 #include "gtkroundedboxprivate.h"
37 #include "gtkthemingbackgroundprivate.h"
40 * SECTION:gtkthemingengine
41 * @Short_description: Theming renderers
42 * @Title: GtkThemingEngine
43 * @See_also: #GtkStyleContext
45 * #GtkThemingEngine is the object used for rendering themed content
46 * in GTK+ widgets. Even though GTK+ has a default implementation,
47 * it can be overridden in CSS files by enforcing a #GtkThemingEngine
48 * object to be loaded as a module.
50 * In order to implement a theming engine, a #GtkThemingEngine subclass
51 * must be created, alongside the CSS file that will reference it, the
52 * theming engine would be created as an .so library, and installed in
53 * $(gtk-modules-dir)/theming-engines/.
55 * #GtkThemingEngine<!-- -->s have limited access to the object they are
56 * rendering, the #GtkThemingEngine API has read-only accessors to the
57 * style information contained in the rendered object's #GtkStyleContext.
73 struct GtkThemingEnginePrivate
75 GtkStyleContext *context;
79 #define GTK_THEMING_ENGINE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_THEMING_ENGINE, GtkThemingEnginePrivate))
81 static void gtk_theming_engine_finalize (GObject *object);
82 static void gtk_theming_engine_impl_set_property (GObject *object,
86 static void gtk_theming_engine_impl_get_property (GObject *object,
91 static void gtk_theming_engine_render_check (GtkThemingEngine *engine,
97 static void gtk_theming_engine_render_option (GtkThemingEngine *engine,
103 static void gtk_theming_engine_render_arrow (GtkThemingEngine *engine,
109 static void gtk_theming_engine_render_background (GtkThemingEngine *engine,
115 static void gtk_theming_engine_render_frame (GtkThemingEngine *engine,
121 static void gtk_theming_engine_render_expander (GtkThemingEngine *engine,
127 static void gtk_theming_engine_render_focus (GtkThemingEngine *engine,
133 static void gtk_theming_engine_render_layout (GtkThemingEngine *engine,
137 PangoLayout *layout);
138 static void gtk_theming_engine_render_line (GtkThemingEngine *engine,
144 static void gtk_theming_engine_render_slider (GtkThemingEngine *engine,
150 GtkOrientation orientation);
151 static void gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
157 GtkPositionType gap_side,
160 static void gtk_theming_engine_render_extension (GtkThemingEngine *engine,
166 GtkPositionType gap_side);
167 static void gtk_theming_engine_render_handle (GtkThemingEngine *engine,
173 static void gtk_theming_engine_render_activity (GtkThemingEngine *engine,
179 static GdkPixbuf * gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine *engine,
180 const GtkIconSource *source,
182 static void gtk_theming_engine_render_icon (GtkThemingEngine *engine,
188 G_DEFINE_TYPE (GtkThemingEngine, gtk_theming_engine, G_TYPE_OBJECT)
191 typedef struct GtkThemingModule GtkThemingModule;
192 typedef struct GtkThemingModuleClass GtkThemingModuleClass;
194 struct GtkThemingModule
196 GTypeModule parent_instance;
200 void (*init) (GTypeModule *module);
202 GtkThemingEngine * (*create_engine) (void);
205 struct GtkThemingModuleClass
207 GTypeModuleClass parent_class;
210 #define GTK_TYPE_THEMING_MODULE (gtk_theming_module_get_type ())
211 #define GTK_THEMING_MODULE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_THEMING_MODULE, GtkThemingModule))
212 #define GTK_IS_THEMING_MODULE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_THEMING_MODULE))
214 G_DEFINE_TYPE (GtkThemingModule, gtk_theming_module, G_TYPE_TYPE_MODULE);
217 gtk_theming_engine_class_init (GtkThemingEngineClass *klass)
219 GObjectClass *object_class = G_OBJECT_CLASS (klass);
221 object_class->finalize = gtk_theming_engine_finalize;
222 object_class->set_property = gtk_theming_engine_impl_set_property;
223 object_class->get_property = gtk_theming_engine_impl_get_property;
225 klass->render_icon = gtk_theming_engine_render_icon;
226 klass->render_check = gtk_theming_engine_render_check;
227 klass->render_option = gtk_theming_engine_render_option;
228 klass->render_arrow = gtk_theming_engine_render_arrow;
229 klass->render_background = gtk_theming_engine_render_background;
230 klass->render_frame = gtk_theming_engine_render_frame;
231 klass->render_expander = gtk_theming_engine_render_expander;
232 klass->render_focus = gtk_theming_engine_render_focus;
233 klass->render_layout = gtk_theming_engine_render_layout;
234 klass->render_line = gtk_theming_engine_render_line;
235 klass->render_slider = gtk_theming_engine_render_slider;
236 klass->render_frame_gap = gtk_theming_engine_render_frame_gap;
237 klass->render_extension = gtk_theming_engine_render_extension;
238 klass->render_handle = gtk_theming_engine_render_handle;
239 klass->render_activity = gtk_theming_engine_render_activity;
240 klass->render_icon_pixbuf = gtk_theming_engine_render_icon_pixbuf;
243 * GtkThemingEngine:name:
245 * The theming engine name, this name will be used when registering
246 * custom properties, for a theming engine named "Clearlooks" registering
247 * a "glossy" custom property, it could be referenced in the CSS file as
250 * -Clearlooks-glossy: true;
255 g_object_class_install_property (object_class,
257 g_param_spec_string ("name",
259 P_("Theming engine name"),
261 G_PARAM_CONSTRUCT_ONLY | GTK_PARAM_READWRITE));
263 g_type_class_add_private (object_class, sizeof (GtkThemingEnginePrivate));
267 gtk_theming_engine_init (GtkThemingEngine *engine)
269 engine->priv = GTK_THEMING_ENGINE_GET_PRIVATE (engine);
273 gtk_theming_engine_finalize (GObject *object)
275 GtkThemingEnginePrivate *priv;
277 priv = GTK_THEMING_ENGINE (object)->priv;
280 G_OBJECT_GET_CLASS (gtk_theming_engine_parent_class)->finalize (object);
284 gtk_theming_engine_impl_set_property (GObject *object,
289 GtkThemingEnginePrivate *priv;
291 priv = GTK_THEMING_ENGINE (object)->priv;
299 priv->name = g_value_dup_string (value);
302 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
308 gtk_theming_engine_impl_get_property (GObject *object,
313 GtkThemingEnginePrivate *priv;
315 priv = GTK_THEMING_ENGINE (object)->priv;
320 g_value_set_string (value, priv->name);
323 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
329 _gtk_theming_engine_set_context (GtkThemingEngine *engine,
330 GtkStyleContext *context)
332 GtkThemingEnginePrivate *priv;
334 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
335 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
338 priv->context = context;
342 * gtk_theming_engine_register_property: (skip)
343 * @name_space: namespace for the property name
344 * @parse_func: parsing function to use, or %NULL
345 * @pspec: the #GParamSpec for the new property
347 * Registers a property so it can be used in the CSS file format,
348 * on the CSS file the property will look like
349 * "-${@name_space}-${property_name}". being
350 * ${property_name} the given to @pspec. @name_space will usually
351 * be the theme engine name.
353 * For any type a @parse_func may be provided, being this function
354 * used for turning any property value (between ':' and ';') in
355 * CSS to the #GValue needed. For basic types there is already
356 * builtin parsing support, so %NULL may be provided for these
360 * Engines must ensure property registration happens exactly once,
361 * usually GTK+ deals with theming engines as singletons, so this
362 * should be guaranteed to happen once, but bear this in mind
363 * when creating #GtkThemeEngine<!-- -->s yourself.
367 * In order to make use of the custom registered properties in
368 * the CSS file, make sure the engine is loaded first by specifying
369 * the engine property, either in a previous rule or within the same
373 * engine: someengine;
374 * -SomeEngine-custom-property: 2;
382 gtk_theming_engine_register_property (const gchar *name_space,
383 GtkStylePropertyParser parse_func,
388 g_return_if_fail (name_space != NULL);
389 g_return_if_fail (strchr (name_space, ' ') == NULL);
390 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
392 /* FIXME: hack hack hack, replacing pspec->name to include namespace */
393 name = g_strdup_printf ("-%s-%s", name_space, pspec->name);
394 pspec->name = (char *)g_intern_string (name);
397 gtk_style_properties_register_property (parse_func, pspec);
401 * gtk_theming_engine_get_property:
402 * @engine: a #GtkThemingEngine
403 * @property: the property name
404 * @state: state to retrieve the value for
405 * @value: (out) (transfer full): return location for the property value,
406 * you must free this memory using g_value_unset() once you are
409 * Gets a property value as retrieved from the style settings that apply
410 * to the currently rendered element.
415 gtk_theming_engine_get_property (GtkThemingEngine *engine,
416 const gchar *property,
420 GtkThemingEnginePrivate *priv;
422 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
423 g_return_if_fail (property != NULL);
424 g_return_if_fail (value != NULL);
427 gtk_style_context_get_property (priv->context, property, state, value);
431 * gtk_theming_engine_get_valist:
432 * @engine: a #GtkThemingEngine
433 * @state: state to retrieve values for
434 * @args: va_list of property name/return location pairs, followed by %NULL
436 * Retrieves several style property values that apply to the currently
442 gtk_theming_engine_get_valist (GtkThemingEngine *engine,
446 GtkThemingEnginePrivate *priv;
448 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
451 gtk_style_context_get_valist (priv->context, state, args);
455 _gtk_theming_engine_get (GtkThemingEngine *engine,
457 GtkStylePropertyContext *property_context,
460 GtkThemingEnginePrivate *priv;
463 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
467 va_start (args, property_context);
468 _gtk_style_context_get_valist (priv->context, state, property_context, args);
474 * gtk_theming_engine_get:
475 * @engine: a #GtkThemingEngine
476 * @state: state to retrieve values for
477 * @...: property name /return value pairs, followed by %NULL
479 * Retrieves several style property values that apply to the currently
485 gtk_theming_engine_get (GtkThemingEngine *engine,
489 GtkThemingEnginePrivate *priv;
492 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
496 va_start (args, state);
497 gtk_style_context_get_valist (priv->context, state, args);
502 * gtk_theming_engine_get_style_property:
503 * @engine: a #GtkThemingEngine
504 * @property_name: the name of the widget style property
505 * @value: Return location for the property value, free with
506 * g_value_unset() after use.
508 * Gets the value for a widget style property.
513 gtk_theming_engine_get_style_property (GtkThemingEngine *engine,
514 const gchar *property_name,
517 GtkThemingEnginePrivate *priv;
519 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
520 g_return_if_fail (property_name != NULL);
523 gtk_style_context_get_style_property (priv->context, property_name, value);
527 * gtk_theming_engine_get_style_valist:
528 * @engine: a #GtkThemingEngine
529 * @args: va_list of property name/return location pairs, followed by %NULL
531 * Retrieves several widget style properties from @engine according to the
532 * currently rendered content's style.
537 gtk_theming_engine_get_style_valist (GtkThemingEngine *engine,
540 GtkThemingEnginePrivate *priv;
542 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
545 gtk_style_context_get_style_valist (priv->context, args);
549 * gtk_theming_engine_get_style:
550 * @engine: a #GtkThemingEngine
551 * @...: property name /return value pairs, followed by %NULL
553 * Retrieves several widget style properties from @engine according
554 * to the currently rendered content's style.
559 gtk_theming_engine_get_style (GtkThemingEngine *engine,
562 GtkThemingEnginePrivate *priv;
565 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
569 va_start (args, engine);
570 gtk_style_context_get_style_valist (priv->context, args);
575 * gtk_theming_engine_lookup_color:
576 * @engine: a #GtkThemingEngine
577 * @color_name: color name to lookup
578 * @color: (out): Return location for the looked up color
580 * Looks up and resolves a color name in the current style's color map.
582 * Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
585 gtk_theming_engine_lookup_color (GtkThemingEngine *engine,
586 const gchar *color_name,
589 GtkThemingEnginePrivate *priv;
591 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
592 g_return_val_if_fail (color_name != NULL, FALSE);
595 return gtk_style_context_lookup_color (priv->context, color_name, color);
599 * gtk_theming_engine_get_state:
600 * @engine: a #GtkThemingEngine
602 * returns the state used when rendering.
604 * Returns: the state flags
609 gtk_theming_engine_get_state (GtkThemingEngine *engine)
611 GtkThemingEnginePrivate *priv;
613 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), 0);
616 return gtk_style_context_get_state (priv->context);
620 * gtk_theming_engine_state_is_running:
621 * @engine: a #GtkThemingEngine
622 * @state: a widget state
623 * @progress: (out): return location for the transition progress
625 * Returns %TRUE if there is a transition animation running for the
626 * current region (see gtk_style_context_push_animatable_region()).
628 * If @progress is not %NULL, the animation progress will be returned
629 * there, 0.0 means the state is closest to being %FALSE, while 1.0 means
630 * it's closest to being %TRUE. This means transition animations will
631 * run from 0 to 1 when @state is being set to %TRUE and from 1 to 0 when
632 * it's being set to %FALSE.
634 * Returns: %TRUE if there is a running transition animation for @state.
639 gtk_theming_engine_state_is_running (GtkThemingEngine *engine,
643 GtkThemingEnginePrivate *priv;
645 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
648 return gtk_style_context_state_is_running (priv->context, state, progress);
652 * gtk_theming_engine_get_path:
653 * @engine: a #GtkThemingEngine
655 * Returns the widget path used for style matching.
657 * Returns: (transfer none): A #GtkWidgetPath
661 const GtkWidgetPath *
662 gtk_theming_engine_get_path (GtkThemingEngine *engine)
664 GtkThemingEnginePrivate *priv;
666 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
669 return gtk_style_context_get_path (priv->context);
673 * gtk_theming_engine_has_class:
674 * @engine: a #GtkThemingEngine
675 * @style_class: class name to look up
677 * Returns %TRUE if the currently rendered contents have
678 * defined the given class name.
680 * Returns: %TRUE if @engine has @class_name defined
685 gtk_theming_engine_has_class (GtkThemingEngine *engine,
686 const gchar *style_class)
688 GtkThemingEnginePrivate *priv;
690 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
693 return gtk_style_context_has_class (priv->context, style_class);
697 * gtk_theming_engine_has_region:
698 * @engine: a #GtkThemingEngine
699 * @style_region: a region name
700 * @flags: (out) (allow-none): return location for region flags
702 * Returns %TRUE if the currently rendered contents have the
703 * region defined. If @flags_return is not %NULL, it is set
704 * to the flags affecting the region.
706 * Returns: %TRUE if region is defined
711 gtk_theming_engine_has_region (GtkThemingEngine *engine,
712 const gchar *style_region,
713 GtkRegionFlags *flags)
715 GtkThemingEnginePrivate *priv;
720 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
723 return gtk_style_context_has_region (priv->context, style_region, flags);
727 * gtk_theming_engine_get_direction:
728 * @engine: a #GtkThemingEngine
730 * Returns the widget direction used for rendering.
732 * Returns: the widget direction
737 gtk_theming_engine_get_direction (GtkThemingEngine *engine)
739 GtkThemingEnginePrivate *priv;
741 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), GTK_TEXT_DIR_LTR);
744 return gtk_style_context_get_direction (priv->context);
748 * gtk_theming_engine_get_junction_sides:
749 * @engine: a #GtkThemingEngine
751 * Returns the widget direction used for rendering.
753 * Returns: the widget direction
758 gtk_theming_engine_get_junction_sides (GtkThemingEngine *engine)
760 GtkThemingEnginePrivate *priv;
762 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), 0);
765 return gtk_style_context_get_junction_sides (priv->context);
769 * gtk_theming_engine_get_color:
770 * @engine: a #GtkThemingEngine
771 * @state: state to retrieve the color for
772 * @color: (out): return value for the foreground color
774 * Gets the foreground color for a given state.
779 gtk_theming_engine_get_color (GtkThemingEngine *engine,
783 GtkThemingEnginePrivate *priv;
785 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
788 gtk_style_context_get_color (priv->context, state, color);
792 * gtk_theming_engine_get_background_color:
793 * @engine: a #GtkThemingEngine
794 * @state: state to retrieve the color for
795 * @color: (out): return value for the background color
797 * Gets the background color for a given state.
802 gtk_theming_engine_get_background_color (GtkThemingEngine *engine,
806 GtkThemingEnginePrivate *priv;
808 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
811 gtk_style_context_get_background_color (priv->context, state, color);
815 * gtk_theming_engine_get_border_color:
816 * @engine: a #GtkThemingEngine
817 * @state: state to retrieve the color for
818 * @color: (out): return value for the border color
820 * Gets the border color for a given state.
825 gtk_theming_engine_get_border_color (GtkThemingEngine *engine,
829 GtkThemingEnginePrivate *priv;
831 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
834 gtk_style_context_get_border_color (priv->context, state, color);
838 * gtk_theming_engine_get_border:
839 * @engine: a #GtkthemingEngine
840 * @state: state to retrieve the border for
841 * @border: (out): return value for the border settings
843 * Gets the border for a given state as a #GtkBorder.
848 gtk_theming_engine_get_border (GtkThemingEngine *engine,
852 GtkThemingEnginePrivate *priv;
854 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
857 gtk_style_context_get_border (priv->context, state, border);
861 * gtk_theming_engine_get_padding:
862 * @engine: a #GtkthemingEngine
863 * @state: state to retrieve the padding for
864 * @padding: (out): return value for the padding settings
866 * Gets the padding for a given state as a #GtkBorder.
871 gtk_theming_engine_get_padding (GtkThemingEngine *engine,
875 GtkThemingEnginePrivate *priv;
877 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
880 gtk_style_context_get_padding (priv->context, state, padding);
884 * gtk_theming_engine_get_margin:
885 * @engine: a #GtkThemingEngine
886 * @state: state to retrieve the border for
887 * @margin: (out): return value for the margin settings
889 * Gets the margin for a given state as a #GtkBorder.
894 gtk_theming_engine_get_margin (GtkThemingEngine *engine,
898 GtkThemingEnginePrivate *priv;
900 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
903 gtk_style_context_get_margin (priv->context, state, margin);
907 * gtk_theming_engine_get_font:
908 * @engine: a #GtkThemingEngine
909 * @state: state to retrieve the font for
911 * Returns the font description for a given state.
913 * Returns: (transfer none): the #PangoFontDescription for the given
914 * state. This object is owned by GTK+ and should not be
919 const PangoFontDescription *
920 gtk_theming_engine_get_font (GtkThemingEngine *engine,
923 GtkThemingEnginePrivate *priv;
925 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
928 return gtk_style_context_get_font (priv->context, state);
931 /* GtkThemingModule */
934 gtk_theming_module_load (GTypeModule *type_module)
936 GtkThemingModule *theming_module;
938 gchar *name, *module_path;
940 theming_module = GTK_THEMING_MODULE (type_module);
941 name = theming_module->name;
942 module_path = _gtk_find_module (name, "theming-engines");
947 module = g_module_open (module_path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
948 g_free (module_path);
953 if (!g_module_symbol (module, "theme_init",
954 (gpointer *) &theming_module->init) ||
955 !g_module_symbol (module, "theme_exit",
956 (gpointer *) &theming_module->exit) ||
957 !g_module_symbol (module, "create_engine",
958 (gpointer *) &theming_module->create_engine))
960 g_module_close (module);
965 theming_module->module = module;
967 theming_module->init (G_TYPE_MODULE (theming_module));
973 gtk_theming_module_unload (GTypeModule *type_module)
975 GtkThemingModule *theming_module;
977 theming_module = GTK_THEMING_MODULE (type_module);
979 theming_module->exit ();
981 g_module_close (theming_module->module);
983 theming_module->module = NULL;
984 theming_module->init = NULL;
985 theming_module->exit = NULL;
986 theming_module->create_engine = NULL;
990 gtk_theming_module_class_init (GtkThemingModuleClass *klass)
992 GTypeModuleClass *module_class = G_TYPE_MODULE_CLASS (klass);
994 module_class->load = gtk_theming_module_load;
995 module_class->unload = gtk_theming_module_unload;
999 gtk_theming_module_init (GtkThemingModule *module)
1004 * gtk_theming_engine_load:
1005 * @name: Theme engine name to load
1007 * Loads and initializes a theming engine module from the
1008 * standard directories.
1010 * Returns: (transfer none): A theming engine, or %NULL if
1011 * the engine @name doesn't exist.
1014 gtk_theming_engine_load (const gchar *name)
1016 static GHashTable *engines = NULL;
1017 static GtkThemingEngine *default_engine;
1018 GtkThemingEngine *engine = NULL;
1023 engines = g_hash_table_new (g_str_hash, g_str_equal);
1025 engine = g_hash_table_lookup (engines, name);
1029 GtkThemingModule *module;
1031 module = g_object_new (GTK_TYPE_THEMING_MODULE, NULL);
1032 g_type_module_set_name (G_TYPE_MODULE (module), name);
1033 module->name = g_strdup (name);
1035 if (module && g_type_module_use (G_TYPE_MODULE (module)))
1037 engine = (module->create_engine) ();
1040 g_hash_table_insert (engines, module->name, engine);
1046 if (G_UNLIKELY (!default_engine))
1047 default_engine = g_object_new (GTK_TYPE_THEMING_ENGINE, NULL);
1049 engine = default_engine;
1056 * gtk_theming_engine_get_screen:
1057 * @engine: a #GtkThemingEngine
1059 * Returns the #GdkScreen to which @engine currently rendering to.
1061 * Returns: (transfer none): a #GdkScreen, or %NULL.
1064 gtk_theming_engine_get_screen (GtkThemingEngine *engine)
1066 GtkThemingEnginePrivate *priv;
1068 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
1070 priv = engine->priv;
1071 return gtk_style_context_get_screen (priv->context);
1074 /* Paint method implementations */
1076 gtk_theming_engine_render_check (GtkThemingEngine *engine,
1083 GdkRGBA fg_color, bg_color;
1084 GtkStateFlags flags;
1085 gint exterior_size, interior_size, thickness, pad;
1086 GtkBorderStyle border_style;
1089 GtkThemingBackground bg;
1091 _gtk_theming_background_init (&bg, engine,
1094 gtk_theming_engine_get_junction_sides (engine));
1096 if (_gtk_theming_background_has_background_image (&bg))
1098 _gtk_theming_background_render (&bg, cr);
1102 flags = gtk_theming_engine_get_state (engine);
1105 gtk_theming_engine_get_color (engine, flags, &fg_color);
1106 gtk_theming_engine_get_background_color (engine, flags, &bg_color);
1107 gtk_theming_engine_get_border (engine, flags, &border);
1109 gtk_theming_engine_get (engine, flags,
1110 "border-style", &border_style,
1113 border_width = MIN (MIN (border.top, border.bottom),
1114 MIN (border.left, border.right));
1115 exterior_size = MIN (width, height);
1117 if (exterior_size % 2 == 0) /* Ensure odd */
1120 /* FIXME: thickness */
1122 pad = thickness + MAX (1, (exterior_size - 2 * thickness) / 9);
1123 interior_size = MAX (1, exterior_size - 2 * pad);
1125 if (interior_size < 7)
1128 pad = MAX (0, (exterior_size - interior_size) / 2);
1131 x -= (1 + exterior_size - (gint) width) / 2;
1132 y -= (1 + exterior_size - (gint) height) / 2;
1134 if (border_style == GTK_BORDER_STYLE_SOLID)
1136 GdkRGBA border_color;
1138 cairo_set_line_width (cr, border_width);
1139 gtk_theming_engine_get_border_color (engine, flags, &border_color);
1141 cairo_rectangle (cr, x + 0.5, y + 0.5, exterior_size - 1, exterior_size - 1);
1142 gdk_cairo_set_source_rgba (cr, &bg_color);
1143 cairo_fill_preserve (cr);
1145 gdk_cairo_set_source_rgba (cr, &border_color);
1149 gdk_cairo_set_source_rgba (cr, &fg_color);
1151 if (flags & GTK_STATE_FLAG_INCONSISTENT)
1153 int line_thickness = MAX (1, (3 + interior_size * 2) / 7);
1155 cairo_rectangle (cr,
1157 y + pad + (1 + interior_size - line_thickness) / 2,
1167 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress);
1169 if ((flags & GTK_STATE_FLAG_ACTIVE) || running)
1174 cairo_translate (cr,
1177 cairo_scale (cr, interior_size / 7., interior_size / 7.);
1179 cairo_rectangle (cr, 0, 0, 7 * progress, 7);
1182 cairo_move_to (cr, 7.0, 0.0);
1183 cairo_line_to (cr, 7.5, 1.0);
1184 cairo_curve_to (cr, 5.3, 2.0,
1187 cairo_curve_to (cr, 3.0, 5.7,
1190 cairo_line_to (cr, 0.2, 3.5);
1191 cairo_curve_to (cr, 1.1, 3.5,
1194 cairo_curve_to (cr, 1.0, 3.9,
1197 cairo_curve_to (cr, 3.5, 3.1,
1209 gtk_theming_engine_render_option (GtkThemingEngine *engine,
1216 GtkStateFlags flags;
1217 GdkRGBA fg_color, bg_color;
1218 gint exterior_size, interior_size, pad, thickness, border_width;
1219 GtkBorderStyle border_style;
1221 GtkThemingBackground bg;
1223 _gtk_theming_background_init (&bg, engine,
1226 gtk_theming_engine_get_junction_sides (engine));
1228 if (_gtk_theming_background_has_background_image (&bg))
1230 _gtk_theming_background_render (&bg, cr);
1234 flags = gtk_theming_engine_get_state (engine);
1238 gtk_theming_engine_get_color (engine, flags, &fg_color);
1239 gtk_theming_engine_get_background_color (engine, flags, &bg_color);
1240 gtk_theming_engine_get_border (engine, flags, &border);
1242 gtk_theming_engine_get (engine, flags,
1243 "border-style", &border_style,
1246 exterior_size = MIN (width, height);
1247 border_width = MIN (MIN (border.top, border.bottom),
1248 MIN (border.left, border.right));
1250 if (exterior_size % 2 == 0) /* Ensure odd */
1253 x -= (1 + exterior_size - width) / 2;
1254 y -= (1 + exterior_size - height) / 2;
1256 if (border_style == GTK_BORDER_STYLE_SOLID)
1258 GdkRGBA border_color;
1260 cairo_set_line_width (cr, border_width);
1261 gtk_theming_engine_get_border_color (engine, flags, &border_color);
1263 cairo_new_sub_path (cr);
1265 x + exterior_size / 2.,
1266 y + exterior_size / 2.,
1267 (exterior_size - 1) / 2.,
1270 gdk_cairo_set_source_rgba (cr, &bg_color);
1271 cairo_fill_preserve (cr);
1273 gdk_cairo_set_source_rgba (cr, &border_color);
1277 gdk_cairo_set_source_rgba (cr, &fg_color);
1279 /* FIXME: thickness */
1282 if (flags & GTK_STATE_FLAG_INCONSISTENT)
1284 gint line_thickness;
1286 pad = thickness + MAX (1, (exterior_size - 2 * thickness) / 9);
1287 interior_size = MAX (1, exterior_size - 2 * pad);
1289 if (interior_size < 7)
1292 pad = MAX (0, (exterior_size - interior_size) / 2);
1295 line_thickness = MAX (1, (3 + interior_size * 2) / 7);
1297 cairo_rectangle (cr,
1299 y + pad + (interior_size - line_thickness) / 2.,
1304 if (flags & GTK_STATE_FLAG_ACTIVE)
1306 pad = thickness + MAX (1, 2 * (exterior_size - 2 * thickness) / 9);
1307 interior_size = MAX (1, exterior_size - 2 * pad);
1309 if (interior_size < 5)
1312 pad = MAX (0, (exterior_size - interior_size) / 2);
1315 cairo_new_sub_path (cr);
1317 x + pad + interior_size / 2.,
1318 y + pad + interior_size / 2.,
1328 add_path_arrow (cairo_t *cr,
1336 cairo_translate (cr, x + (size / 2), y + (size / 2));
1337 cairo_rotate (cr, angle);
1339 cairo_move_to (cr, 0, - (size / 4));
1340 cairo_line_to (cr, - (size / 2), (size / 4));
1341 cairo_line_to (cr, (size / 2), (size / 4));
1342 cairo_close_path (cr);
1348 gtk_theming_engine_render_arrow (GtkThemingEngine *engine,
1355 GtkStateFlags flags;
1360 flags = gtk_theming_engine_get_state (engine);
1361 gtk_theming_engine_get_color (engine, flags, &fg_color);
1363 if (flags & GTK_STATE_FLAG_INSENSITIVE)
1365 add_path_arrow (cr, angle, x + 1, y + 1, size);
1366 cairo_set_source_rgb (cr, 1, 1, 1);
1370 add_path_arrow (cr, angle, x, y, size);
1371 gdk_cairo_set_source_rgba (cr, &fg_color);
1378 add_path_line (cairo_t *cr,
1384 /* Adjust endpoints */
1398 cairo_move_to (cr, x1, y1);
1399 cairo_line_to (cr, x2, y2);
1403 color_shade (const GdkRGBA *color,
1405 GdkRGBA *color_return)
1407 GtkSymbolicColor *literal, *shade;
1409 literal = gtk_symbolic_color_new_literal (color);
1410 shade = gtk_symbolic_color_new_shade (literal, factor);
1411 gtk_symbolic_color_unref (literal);
1413 gtk_symbolic_color_resolve (shade, NULL, color_return);
1414 gtk_symbolic_color_unref (shade);
1418 gtk_theming_engine_render_background (GtkThemingEngine *engine,
1425 GtkThemingBackground bg;
1427 _gtk_theming_background_init (&bg, engine,
1430 gtk_theming_engine_get_junction_sides (engine));
1432 _gtk_theming_background_render (&bg, cr);
1436 gtk_theming_engine_hide_border_sides (GtkBorder *border,
1439 if (hidden_side & SIDE_TOP)
1441 if (hidden_side & SIDE_RIGHT)
1443 if (hidden_side & SIDE_BOTTOM)
1445 if (hidden_side & SIDE_LEFT)
1450 render_frame_internal (GtkThemingEngine *engine,
1457 GtkJunctionSides junction)
1459 GtkStateFlags state;
1460 GtkBorderStyle border_style;
1461 GtkRoundedBox border_box, padding_box;
1465 static const guint current_side[4] = { SIDE_TOP, SIDE_RIGHT, SIDE_BOTTOM, SIDE_LEFT };
1469 state = gtk_theming_engine_get_state (engine);
1471 gtk_theming_engine_get_border (engine, state, &border);
1472 gtk_theming_engine_hide_border_sides (&border, hidden_side);
1474 gtk_theming_engine_get (engine, state,
1475 "border-style", &border_style,
1476 "border-top-color", &colors[0],
1477 "border-right-color", &colors[1],
1478 "border-bottom-color", &colors[2],
1479 "border-left-color", &colors[3],
1482 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
1486 GtkStateFlags other_state;
1487 GdkRGBA *other_colors[4];
1489 if (state & GTK_STATE_FLAG_PRELIGHT)
1491 other_state = state & ~(GTK_STATE_FLAG_PRELIGHT);
1492 progress = 1 - progress;
1495 other_state = state | GTK_STATE_FLAG_PRELIGHT;
1497 gtk_theming_engine_get (engine, other_state,
1498 "border-top-color", &other_colors[0],
1499 "border-right-color", &other_colors[1],
1500 "border-bottom-color", &other_colors[2],
1501 "border-left-color", &other_colors[3],
1504 for (i = 0; i < 4; i++)
1506 colors[i]->red = CLAMP (colors[i]->red + ((other_colors[i]->red - colors[i]->red) * progress), 0, 1);
1507 colors[i]->green = CLAMP (colors[i]->green + ((other_colors[i]->green - colors[i]->green) * progress), 0, 1);
1508 colors[i]->blue = CLAMP (colors[i]->blue + ((other_colors[i]->blue - colors[i]->blue) * progress), 0, 1);
1509 colors[i]->alpha = CLAMP (colors[i]->alpha + ((other_colors[i]->alpha - colors[i]->alpha) * progress), 0, 1);
1510 gdk_rgba_free (other_colors[i]);
1514 switch (border_style)
1517 g_assert_not_reached ();
1518 case GTK_BORDER_STYLE_NONE:
1519 case GTK_BORDER_STYLE_SOLID:
1521 case GTK_BORDER_STYLE_INSET:
1522 color_shade (colors[1], 1.8, colors[1]);
1523 color_shade (colors[2], 1.8, colors[2]);
1525 case GTK_BORDER_STYLE_OUTSET:
1526 color_shade (colors[0], 1.8, colors[0]);
1527 color_shade (colors[3], 1.8, colors[3]);
1533 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
1535 _gtk_rounded_box_init_rect (&border_box, x, y, width, height);
1536 _gtk_rounded_box_apply_border_radius (&border_box, engine, state, junction);
1537 padding_box = border_box;
1538 _gtk_rounded_box_shrink (&padding_box, border.top, border.right, border.bottom, border.left);
1540 switch (border_style)
1542 case GTK_BORDER_STYLE_NONE:
1544 case GTK_BORDER_STYLE_SOLID:
1545 case GTK_BORDER_STYLE_INSET:
1546 case GTK_BORDER_STYLE_OUTSET:
1548 if (gdk_rgba_equal (colors[0], colors[1]) &&
1549 gdk_rgba_equal (colors[0], colors[2]) &&
1550 gdk_rgba_equal (colors[0], colors[3]))
1552 gdk_cairo_set_source_rgba (cr, colors[0]);
1554 _gtk_rounded_box_path (&border_box, cr);
1555 _gtk_rounded_box_path (&padding_box, cr);
1560 for (i = 0; i < 4; i++)
1562 if (hidden_side & current_side[i])
1565 for (j = 0; j < 4; j++)
1567 if (hidden_side & current_side[j])
1571 gdk_rgba_equal (colors[i], colors[j]))
1573 /* We were already painted when i == j */
1578 _gtk_rounded_box_path_top (&border_box, &padding_box, cr);
1580 _gtk_rounded_box_path_right (&border_box, &padding_box, cr);
1582 _gtk_rounded_box_path_bottom (&border_box, &padding_box, cr);
1584 _gtk_rounded_box_path_left (&border_box, &padding_box, cr);
1587 /* We were already painted when i == j */
1591 gdk_cairo_set_source_rgba (cr, colors[i]);
1601 for (i = 0; i < 4; i++)
1602 gdk_rgba_free (colors[i]);
1606 gtk_theming_engine_render_frame (GtkThemingEngine *engine,
1613 GtkStateFlags flags;
1614 GtkBorderStyle border_style;
1615 GtkJunctionSides junction;
1616 GtkBorderImage *border_image;
1618 GtkStylePropertyContext context;
1620 flags = gtk_theming_engine_get_state (engine);
1621 junction = gtk_theming_engine_get_junction_sides (engine);
1622 gtk_theming_engine_get_border (engine, flags, &border);
1624 context.width = width;
1625 context.height = height;
1627 _gtk_theming_engine_get (engine, flags, &context,
1628 "border-image", &border_image,
1629 "border-style", &border_style,
1632 if (border_image != NULL)
1634 _gtk_border_image_render (border_image, &border,
1635 cr, x, y, width, height);
1636 _gtk_border_image_unref (border_image);
1638 else if (border_style != GTK_BORDER_STYLE_NONE)
1639 render_frame_internal (engine, cr,
1640 x, y, width, height,
1645 gtk_theming_engine_render_expander (GtkThemingEngine *engine,
1652 GtkStateFlags flags;
1653 GdkRGBA outline_color, fg_color;
1654 double vertical_overshoot;
1657 double interp; /* interpolation factor for center position */
1658 double x_double_horz, y_double_horz;
1659 double x_double_vert, y_double_vert;
1660 double x_double, y_double;
1663 gboolean running, is_rtl;
1667 flags = gtk_theming_engine_get_state (engine);
1669 gtk_theming_engine_get_color (engine, flags, &fg_color);
1670 gtk_theming_engine_get_border_color (engine, flags, &outline_color);
1672 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress);
1673 is_rtl = (gtk_theming_engine_get_direction (engine) == GTK_TEXT_DIR_RTL);
1677 progress = (flags & GTK_STATE_FLAG_ACTIVE) ? 1 : 0;
1679 if (!gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_HORIZONTAL))
1682 angle = (G_PI) - ((G_PI / 2) * progress);
1684 angle = (G_PI / 2) * progress;
1689 angle = (G_PI / 2) + ((G_PI / 2) * progress);
1691 angle = (G_PI / 2) - ((G_PI / 2) * progress);
1696 /* Compute distance that the stroke extends beyonds the end
1697 * of the triangle we draw.
1699 vertical_overshoot = line_width / 2.0 * (1. / tan (G_PI / 8));
1701 /* For odd line widths, we end the vertical line of the triangle
1702 * at a half pixel, so we round differently.
1704 if (line_width % 2 == 1)
1705 vertical_overshoot = ceil (0.5 + vertical_overshoot) - 0.5;
1707 vertical_overshoot = ceil (vertical_overshoot);
1709 /* Adjust the size of the triangle we draw so that the entire stroke fits
1711 diameter = (gint) MAX (3, width - 2 * vertical_overshoot);
1713 /* If the line width is odd, we want the diameter to be even,
1714 * and vice versa, so force the sum to be odd. This relationship
1715 * makes the point of the triangle look right.
1717 diameter -= (1 - (diameter + line_width) % 2);
1719 radius = diameter / 2.;
1721 /* Adjust the center so that the stroke is properly aligned with
1722 * the pixel grid. The center adjustment is different for the
1723 * horizontal and vertical orientations. For intermediate positions
1724 * we interpolate between the two.
1726 x_double_vert = floor ((x + width / 2) - (radius + line_width) / 2.) + (radius + line_width) / 2.;
1727 y_double_vert = (y + height / 2) - 0.5;
1729 x_double_horz = (x + width / 2) - 0.5;
1730 y_double_horz = floor ((y + height / 2) - (radius + line_width) / 2.) + (radius + line_width) / 2.;
1732 x_double = x_double_vert * (1 - interp) + x_double_horz * interp;
1733 y_double = y_double_vert * (1 - interp) + y_double_horz * interp;
1735 cairo_translate (cr, x_double, y_double);
1736 cairo_rotate (cr, angle);
1738 cairo_move_to (cr, - radius / 2., - radius);
1739 cairo_line_to (cr, radius / 2., 0);
1740 cairo_line_to (cr, - radius / 2., radius);
1741 cairo_close_path (cr);
1743 cairo_set_line_width (cr, line_width);
1745 gdk_cairo_set_source_rgba (cr, &fg_color);
1747 cairo_fill_preserve (cr);
1749 gdk_cairo_set_source_rgba (cr, &outline_color);
1756 gtk_theming_engine_render_focus (GtkThemingEngine *engine,
1763 GtkStateFlags flags;
1769 flags = gtk_theming_engine_get_state (engine);
1771 gtk_theming_engine_get_color (engine, flags, &color);
1773 gtk_theming_engine_get_style (engine,
1774 "focus-line-width", &line_width,
1775 "focus-line-pattern", (gchar *) &dash_list,
1778 cairo_set_line_width (cr, (gdouble) line_width);
1782 gint n_dashes = strlen ((const gchar *) dash_list);
1783 gdouble *dashes = g_new (gdouble, n_dashes);
1784 gdouble total_length = 0;
1785 gdouble dash_offset;
1788 for (i = 0; i < n_dashes; i++)
1790 dashes[i] = dash_list[i];
1791 total_length += dash_list[i];
1794 /* The dash offset here aligns the pattern to integer pixels
1795 * by starting the dash at the right side of the left border
1796 * Negative dash offsets in cairo don't work
1797 * (https://bugs.freedesktop.org/show_bug.cgi?id=2729)
1799 dash_offset = - line_width / 2.;
1801 while (dash_offset < 0)
1802 dash_offset += total_length;
1804 cairo_set_dash (cr, dashes, n_dashes, dash_offset);
1808 cairo_rectangle (cr,
1809 x + line_width / 2.,
1810 y + line_width / 2.,
1812 height - line_width);
1814 gdk_cairo_set_source_rgba (cr, &color);
1823 gtk_theming_engine_render_line (GtkThemingEngine *engine,
1831 GtkStateFlags flags;
1833 flags = gtk_theming_engine_get_state (engine);
1836 gtk_theming_engine_get_color (engine, flags, &color);
1838 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
1839 cairo_set_line_width (cr, 1);
1841 cairo_move_to (cr, x0 + 0.5, y0 + 0.5);
1842 cairo_line_to (cr, x1 + 0.5, y1 + 0.5);
1844 gdk_cairo_set_source_rgba (cr, &color);
1851 prepare_context_for_layout (cairo_t *cr,
1854 PangoLayout *layout)
1856 const PangoMatrix *matrix;
1858 matrix = pango_context_get_matrix (pango_layout_get_context (layout));
1860 cairo_move_to (cr, x, y);
1864 cairo_matrix_t cairo_matrix;
1866 cairo_matrix_init (&cairo_matrix,
1867 matrix->xx, matrix->yx,
1868 matrix->xy, matrix->yy,
1869 matrix->x0, matrix->y0);
1871 cairo_transform (cr, &cairo_matrix);
1876 gtk_theming_engine_render_layout (GtkThemingEngine *engine,
1880 PangoLayout *layout)
1883 GtkShadow *text_shadow = NULL;
1884 GtkStateFlags flags;
1889 flags = gtk_theming_engine_get_state (engine);
1890 gtk_theming_engine_get_color (engine, flags, &fg_color);
1892 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
1896 GtkStateFlags other_flags;
1899 if (flags & GTK_STATE_FLAG_PRELIGHT)
1901 other_flags = flags & ~(GTK_STATE_FLAG_PRELIGHT);
1902 progress = 1 - progress;
1905 other_flags = flags | GTK_STATE_FLAG_PRELIGHT;
1907 gtk_theming_engine_get_color (engine, other_flags, &other_fg);
1909 fg_color.red = CLAMP (fg_color.red + ((other_fg.red - fg_color.red) * progress), 0, 1);
1910 fg_color.green = CLAMP (fg_color.green + ((other_fg.green - fg_color.green) * progress), 0, 1);
1911 fg_color.blue = CLAMP (fg_color.blue + ((other_fg.blue - fg_color.blue) * progress), 0, 1);
1912 fg_color.alpha = CLAMP (fg_color.alpha + ((other_fg.alpha - fg_color.alpha) * progress), 0, 1);
1915 gtk_theming_engine_get (engine, flags,
1916 "text-shadow", &text_shadow,
1919 prepare_context_for_layout (cr, x, y, layout);
1921 if (text_shadow != NULL)
1923 _gtk_text_shadow_paint_layout (text_shadow, cr, layout);
1924 _gtk_shadow_unref (text_shadow);
1927 gdk_cairo_set_source_rgba (cr, &fg_color);
1928 pango_cairo_show_layout (cr, layout);
1934 gtk_theming_engine_render_slider (GtkThemingEngine *engine,
1940 GtkOrientation orientation)
1942 const GtkWidgetPath *path;
1945 path = gtk_theming_engine_get_path (engine);
1947 gtk_theming_engine_render_background (engine, cr, x, y, width, height);
1948 gtk_theming_engine_render_frame (engine, cr, x, y, width, height);
1950 /* FIXME: thickness */
1953 if (gtk_widget_path_is_type (path, GTK_TYPE_SCALE))
1955 if (orientation == GTK_ORIENTATION_VERTICAL)
1956 gtk_theming_engine_render_line (engine, cr,
1958 y + (gint) height / 2,
1959 x + width - thickness - 1,
1960 y + (gint) height / 2);
1962 gtk_theming_engine_render_line (engine, cr,
1963 x + (gint) width / 2,
1965 x + (gint) width / 2,
1966 y + height - thickness - 1);
1971 gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
1977 GtkPositionType gap_side,
1981 GtkJunctionSides junction;
1982 GtkStateFlags state;
1984 GtkCssBorderCornerRadius *top_left_radius, *top_right_radius;
1985 GtkCssBorderCornerRadius *bottom_left_radius, *bottom_right_radius;
1986 GtkCssBorderRadius border_radius = { { 0, }, };
1987 gdouble x0, y0, x1, y1, xc, yc, wc, hc;
1988 GtkStylePropertyContext context;
1989 GtkBorderImage *border_image;
1992 xc = yc = wc = hc = 0;
1993 state = gtk_theming_engine_get_state (engine);
1994 junction = gtk_theming_engine_get_junction_sides (engine);
1996 context.width = width;
1997 context.height = height;
1999 gtk_theming_engine_get_border (engine, state, &border);
2000 _gtk_theming_engine_get (engine, state, &context,
2001 "border-image", &border_image,
2002 /* Can't use border-radius as it's an int for
2003 * backwards compat */
2004 "border-top-left-radius", &top_left_radius,
2005 "border-top-right-radius", &top_right_radius,
2006 "border-bottom-right-radius", &bottom_right_radius,
2007 "border-bottom-left-radius", &bottom_left_radius,
2010 if (top_left_radius)
2011 border_radius.top_left = *top_left_radius;
2012 g_free (top_left_radius);
2013 if (top_right_radius)
2014 border_radius.top_right = *top_right_radius;
2015 g_free (top_right_radius);
2016 if (bottom_right_radius)
2017 border_radius.bottom_right = *bottom_right_radius;
2018 g_free (bottom_right_radius);
2019 if (bottom_left_radius)
2020 border_radius.bottom_left = *bottom_left_radius;
2021 g_free (bottom_left_radius);
2023 border_width = MIN (MIN (border.top, border.bottom),
2024 MIN (border.left, border.right));
2031 xc = x + xy0_gap + border_width;
2033 wc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
2036 if (xy0_gap < border_radius.top_left.horizontal)
2037 junction |= GTK_JUNCTION_CORNER_TOPLEFT;
2039 if (xy1_gap > width - border_radius.top_right.horizontal)
2040 junction |= GTK_JUNCTION_CORNER_TOPRIGHT;
2042 case GTK_POS_BOTTOM:
2043 xc = x + xy0_gap + border_width;
2044 yc = y + height - border_width;
2045 wc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
2048 if (xy0_gap < border_radius.bottom_left.horizontal)
2049 junction |= GTK_JUNCTION_CORNER_BOTTOMLEFT;
2051 if (xy1_gap > width - border_radius.bottom_right.horizontal)
2052 junction |= GTK_JUNCTION_CORNER_BOTTOMRIGHT;
2057 yc = y + xy0_gap + border_width;
2059 hc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
2061 if (xy0_gap < border_radius.top_left.vertical)
2062 junction |= GTK_JUNCTION_CORNER_TOPLEFT;
2064 if (xy1_gap > height - border_radius.bottom_left.vertical)
2065 junction |= GTK_JUNCTION_CORNER_BOTTOMLEFT;
2069 xc = x + width - border_width;
2070 yc = y + xy0_gap + border_width;
2072 hc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
2074 if (xy0_gap < border_radius.top_right.vertical)
2075 junction |= GTK_JUNCTION_CORNER_TOPRIGHT;
2077 if (xy1_gap > height - border_radius.bottom_right.vertical)
2078 junction |= GTK_JUNCTION_CORNER_BOTTOMRIGHT;
2083 cairo_clip_extents (cr, &x0, &y0, &x1, &y1);
2084 cairo_rectangle (cr, x0, y0, x1 - x0, yc - y0);
2085 cairo_rectangle (cr, x0, yc, xc - x0, hc);
2086 cairo_rectangle (cr, xc + wc, yc, x1 - (xc + wc), hc);
2087 cairo_rectangle (cr, x0, yc + hc, x1 - x0, y1 - (yc + hc));
2090 if (border_image != NULL)
2092 _gtk_border_image_render (border_image, &border,
2093 cr, x, y, width, height);
2094 _gtk_border_image_unref (border_image);
2097 render_frame_internal (engine, cr,
2098 x, y, width, height,
2105 gtk_theming_engine_render_extension (GtkThemingEngine *engine,
2111 GtkPositionType gap_side)
2113 GtkThemingBackground bg;
2114 GtkJunctionSides junction = 0;
2115 guint hidden_side = 0;
2122 junction = GTK_JUNCTION_LEFT;
2123 hidden_side = SIDE_LEFT;
2125 cairo_translate (cr, x + width, y);
2126 cairo_rotate (cr, G_PI / 2);
2129 junction = GTK_JUNCTION_RIGHT;
2130 hidden_side = SIDE_RIGHT;
2132 cairo_translate (cr, x, y + height);
2133 cairo_rotate (cr, - G_PI / 2);
2136 junction = GTK_JUNCTION_TOP;
2137 hidden_side = SIDE_TOP;
2139 cairo_translate (cr, x + width, y + height);
2140 cairo_rotate (cr, G_PI);
2142 case GTK_POS_BOTTOM:
2143 junction = GTK_JUNCTION_BOTTOM;
2144 hidden_side = SIDE_BOTTOM;
2146 cairo_translate (cr, x, y);
2150 if (gap_side == GTK_POS_TOP ||
2151 gap_side == GTK_POS_BOTTOM)
2152 _gtk_theming_background_init (&bg, engine,
2155 GTK_JUNCTION_BOTTOM);
2157 _gtk_theming_background_init (&bg, engine,
2160 GTK_JUNCTION_BOTTOM);
2162 _gtk_theming_background_render (&bg, cr);
2168 render_frame_internal (engine, cr,
2169 x, y, width, height,
2170 hidden_side, junction);
2176 render_dot (cairo_t *cr,
2177 const GdkRGBA *lighter,
2178 const GdkRGBA *darker,
2183 size = CLAMP ((gint) size, 2, 3);
2187 gdk_cairo_set_source_rgba (cr, lighter);
2188 cairo_rectangle (cr, x, y, 1, 1);
2189 cairo_rectangle (cr, x + 1, y + 1, 1, 1);
2194 gdk_cairo_set_source_rgba (cr, lighter);
2195 cairo_rectangle (cr, x, y, 2, 1);
2196 cairo_rectangle (cr, x, y, 1, 2);
2199 gdk_cairo_set_source_rgba (cr, darker);
2200 cairo_rectangle (cr, x + 1, y + 1, 2, 1);
2201 cairo_rectangle (cr, x + 2, y, 1, 2);
2207 gtk_theming_engine_render_handle (GtkThemingEngine *engine,
2214 GtkStateFlags flags;
2215 GdkRGBA bg_color, lighter, darker;
2216 GtkJunctionSides sides;
2217 GtkThemingBackground bg;
2221 flags = gtk_theming_engine_get_state (engine);
2223 cairo_set_line_width (cr, 1.0);
2224 sides = gtk_theming_engine_get_junction_sides (engine);
2225 gtk_theming_engine_get_background_color (engine, flags, &bg_color);
2227 color_shade (&bg_color, 0.7, &darker);
2228 color_shade (&bg_color, 1.3, &lighter);
2230 _gtk_theming_background_init (&bg, engine, x, y, width, height, sides);
2231 _gtk_theming_background_render (&bg, cr);
2233 if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_GRIP))
2235 /* reduce confusing values to a meaningful state */
2236 if ((sides & (GTK_JUNCTION_CORNER_TOPLEFT | GTK_JUNCTION_CORNER_BOTTOMRIGHT)) == (GTK_JUNCTION_CORNER_TOPLEFT | GTK_JUNCTION_CORNER_BOTTOMRIGHT))
2237 sides &= ~GTK_JUNCTION_CORNER_TOPLEFT;
2239 if ((sides & (GTK_JUNCTION_CORNER_TOPRIGHT | GTK_JUNCTION_CORNER_BOTTOMLEFT)) == (GTK_JUNCTION_CORNER_TOPRIGHT | GTK_JUNCTION_CORNER_BOTTOMLEFT))
2240 sides &= ~GTK_JUNCTION_CORNER_TOPRIGHT;
2243 sides = GTK_JUNCTION_CORNER_BOTTOMRIGHT;
2245 /* align drawing area to the connected side */
2246 if (sides == GTK_JUNCTION_LEFT)
2251 else if (sides == GTK_JUNCTION_CORNER_TOPLEFT)
2255 else if (height < width)
2258 else if (sides == GTK_JUNCTION_CORNER_BOTTOMLEFT)
2260 /* make it square, aligning to bottom left */
2263 y += (height - width);
2266 else if (height < width)
2269 else if (sides == GTK_JUNCTION_RIGHT)
2271 /* aligning to right */
2274 x += (width - height);
2278 else if (sides == GTK_JUNCTION_CORNER_TOPRIGHT)
2282 else if (height < width)
2284 x += (width - height);
2288 else if (sides == GTK_JUNCTION_CORNER_BOTTOMRIGHT)
2290 /* make it square, aligning to bottom right */
2293 y += (height - width);
2296 else if (height < width)
2298 x += (width - height);
2302 else if (sides == GTK_JUNCTION_TOP)
2307 else if (sides == GTK_JUNCTION_BOTTOM)
2309 /* align to bottom */
2312 y += (height - width);
2317 g_assert_not_reached ();
2319 if (sides == GTK_JUNCTION_LEFT ||
2320 sides == GTK_JUNCTION_RIGHT)
2326 while (xi < x + width)
2328 gdk_cairo_set_source_rgba (cr, &lighter);
2329 add_path_line (cr, x, y, x, y + height);
2333 gdk_cairo_set_source_rgba (cr, &darker);
2334 add_path_line (cr, xi, y, xi, y + height);
2339 else if (sides == GTK_JUNCTION_TOP ||
2340 sides == GTK_JUNCTION_BOTTOM)
2346 while (yi < y + height)
2348 gdk_cairo_set_source_rgba (cr, &lighter);
2349 add_path_line (cr, x, yi, x + width, yi);
2353 gdk_cairo_set_source_rgba (cr, &darker);
2354 add_path_line (cr, x, yi, x + width, yi);
2359 else if (sides == GTK_JUNCTION_CORNER_TOPLEFT)
2368 gdk_cairo_set_source_rgba (cr, &darker);
2369 add_path_line (cr, xi, y, x, yi);
2375 add_path_line (cr, xi, y, x, yi);
2381 gdk_cairo_set_source_rgba (cr, &lighter);
2382 add_path_line (cr, xi, y, x, yi);
2389 else if (sides == GTK_JUNCTION_CORNER_TOPRIGHT)
2396 while (xi < (x + width - 3))
2398 gdk_cairo_set_source_rgba (cr, &lighter);
2399 add_path_line (cr, xi, y, x + width, yi);
2405 gdk_cairo_set_source_rgba (cr, &darker);
2406 add_path_line (cr, xi, y, x + width, yi);
2412 add_path_line (cr, xi, y, x + width, yi);
2419 else if (sides == GTK_JUNCTION_CORNER_BOTTOMLEFT)
2428 gdk_cairo_set_source_rgba (cr, &darker);
2429 add_path_line (cr, x, yi, xi, y + height);
2435 add_path_line (cr, x, yi, xi, y + height);
2441 gdk_cairo_set_source_rgba (cr, &lighter);
2442 add_path_line (cr, x, yi, xi, y + height);
2449 else if (sides == GTK_JUNCTION_CORNER_BOTTOMRIGHT)
2456 while (xi < (x + width - 3))
2458 gdk_cairo_set_source_rgba (cr, &lighter);
2459 add_path_line (cr, xi, y + height, x + width, yi);
2465 gdk_cairo_set_source_rgba (cr, &darker);
2466 add_path_line (cr, xi, y + height, x + width, yi);
2472 add_path_line (cr, xi, y + height, x + width, yi);
2480 else if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_PANE_SEPARATOR))
2483 for (xx = x + width / 2 - 15; xx <= x + width / 2 + 15; xx += 5)
2484 render_dot (cr, &lighter, &darker, xx, y + height / 2 - 1, 3);
2486 for (yy = y + height / 2 - 15; yy <= y + height / 2 + 15; yy += 5)
2487 render_dot (cr, &lighter, &darker, x + width / 2 - 1, yy, 3);
2491 for (yy = y; yy < y + height; yy += 3)
2492 for (xx = x; xx < x + width; xx += 6)
2494 render_dot (cr, &lighter, &darker, xx, yy, 2);
2495 render_dot (cr, &lighter, &darker, xx + 3, yy + 1, 2);
2503 _gtk_theming_engine_paint_spinner (cairo_t *cr,
2508 guint num_steps, step;
2515 step = (guint) (progress * num_steps);
2521 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
2522 cairo_set_line_width (cr, 2.0);
2524 half = num_steps / 2;
2526 for (i = 0; i < num_steps; i++)
2528 gint inset = 0.7 * radius;
2530 /* transparency is a function of time and intial value */
2531 gdouble t = 1.0 - (gdouble) ((i + step) % num_steps) / num_steps;
2532 gdouble xscale = - sin (i * G_PI / half);
2533 gdouble yscale = - cos (i * G_PI / half);
2535 cairo_set_source_rgba (cr,
2542 (radius - inset) * xscale,
2543 (radius - inset) * yscale);
2555 render_spinner (GtkThemingEngine *engine,
2562 GtkStateFlags state;
2568 state = gtk_theming_engine_get_state (engine);
2570 if (!gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress))
2573 radius = MIN (width / 2, height / 2);
2575 gtk_theming_engine_get_color (engine, state, &color);
2576 gtk_theming_engine_get (engine, state,
2577 "icon-shadow", &shadow,
2581 cairo_translate (cr, x + width / 2, y + height / 2);
2585 _gtk_icon_shadow_paint_spinner (shadow, cr,
2588 _gtk_shadow_unref (shadow);
2591 _gtk_theming_engine_paint_spinner (cr,
2600 gtk_theming_engine_render_activity (GtkThemingEngine *engine,
2607 if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_SPINNER))
2609 render_spinner (engine, cr, x, y, width, height);
2613 gtk_theming_engine_render_background (engine, cr, x, y, width, height);
2614 gtk_theming_engine_render_frame (engine, cr, x, y, width, height);
2619 scale_or_ref (GdkPixbuf *src,
2623 if (width == gdk_pixbuf_get_width (src) &&
2624 height == gdk_pixbuf_get_height (src))
2625 return g_object_ref (src);
2627 return gdk_pixbuf_scale_simple (src,
2629 GDK_INTERP_BILINEAR);
2633 lookup_icon_size (GtkThemingEngine *engine,
2639 GtkSettings *settings;
2641 screen = gtk_theming_engine_get_screen (engine);
2642 settings = gtk_settings_get_for_screen (screen);
2644 return gtk_icon_size_lookup_for_settings (settings, size, width, height);
2648 colorshift_source (cairo_t *cr,
2651 cairo_pattern_t *source;
2656 source = cairo_pattern_reference (cairo_get_source (cr));
2658 cairo_set_source_rgb (cr, shift, shift, shift);
2659 cairo_set_operator (cr, CAIRO_OPERATOR_COLOR_DODGE);
2661 cairo_mask (cr, source);
2663 cairo_pattern_destroy (source);
2668 gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine *engine,
2669 const GtkIconSource *source,
2674 GdkPixbuf *base_pixbuf;
2675 GtkStateFlags state;
2679 cairo_surface_t *surface;
2681 base_pixbuf = gtk_icon_source_get_pixbuf (source);
2682 state = gtk_theming_engine_get_state (engine);
2684 g_return_val_if_fail (base_pixbuf != NULL, NULL);
2686 if (size != (GtkIconSize) -1 &&
2687 !lookup_icon_size (engine, size, &width, &height))
2689 g_warning (G_STRLOC ": invalid icon size '%d'", size);
2693 /* If the size was wildcarded, and we're allowed to scale, then scale; otherwise,
2696 if (size != (GtkIconSize) -1 &&
2697 gtk_icon_source_get_size_wildcarded (source))
2698 scaled = scale_or_ref (base_pixbuf, width, height);
2700 scaled = g_object_ref (base_pixbuf);
2702 /* If the state was wildcarded, then generate a state. */
2703 if (gtk_icon_source_get_state_wildcarded (source))
2705 if (state & GTK_STATE_FLAG_INSENSITIVE)
2707 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
2708 gdk_pixbuf_get_width (scaled),
2709 gdk_pixbuf_get_height (scaled));
2710 cr = cairo_create (surface);
2711 gdk_cairo_set_source_pixbuf (cr, scaled, 0, 0);
2712 cairo_paint_with_alpha (cr, 0.5);
2716 g_object_unref (scaled);
2717 stated = gdk_pixbuf_get_from_surface (surface, 0, 0,
2718 cairo_image_surface_get_width (surface),
2719 cairo_image_surface_get_height (surface));
2720 cairo_surface_destroy (surface);
2722 else if (state & GTK_STATE_FLAG_PRELIGHT)
2724 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
2725 gdk_pixbuf_get_width (scaled),
2726 gdk_pixbuf_get_height (scaled));
2728 cr = cairo_create (surface);
2729 gdk_cairo_set_source_pixbuf (cr, scaled, 0, 0);
2730 colorshift_source (cr, 0.10);
2734 g_object_unref (scaled);
2735 stated = gdk_pixbuf_get_from_surface (surface, 0, 0,
2736 cairo_image_surface_get_width (surface),
2737 cairo_image_surface_get_height (surface));
2738 cairo_surface_destroy (surface);
2750 gtk_theming_engine_render_icon (GtkThemingEngine *engine,
2756 GtkStateFlags state;
2757 GtkShadow *icon_shadow;
2759 state = gtk_theming_engine_get_state (engine);
2763 gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
2765 gtk_theming_engine_get (engine, state,
2766 "icon-shadow", &icon_shadow,
2769 if (icon_shadow != NULL)
2771 _gtk_icon_shadow_paint (icon_shadow, cr);
2772 _gtk_shadow_unref (icon_shadow);