1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2010 Carlos Garnacho <carlosg@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
25 #include <gtk/gtkthemingengine.h>
26 #include <gtk/gtkstylecontext.h>
27 #include <gtk/gtkintl.h>
29 #include "gtkprivate.h"
30 #include "gtk9slice.h"
34 * SECTION:gtkthemingengine
35 * @Short_description: Theming renderers
36 * @Title: GtkThemingEngine
37 * @See_also: #GtkStyleContext
39 * #GtkThemingEngine is the object used for rendering themed content
40 * in GTK+ widgets. Even though GTK+ has a default implementation,
41 * it can be overridden in CSS files by enforcing a #GtkThemingEngine
42 * object to be loaded as a module.
44 * In order to implement a theming engine, a #GtkThemingEngine subclass
45 * must be created, alongside the CSS file that will reference it, the
46 * theming engine would be created as an .so library, and installed in
47 * $(gtk-modules-dir)/theming-engines/.
49 * #GtkThemingEngine<!-- -->s have limited access to the object they are
50 * rendering, the #GtkThemingEngine API has read-only accessors to the
51 * style information contained in the rendered object's #GtkStyleContext.
54 typedef struct GtkThemingEnginePrivate GtkThemingEnginePrivate;
69 struct GtkThemingEnginePrivate
71 GtkStyleContext *context;
75 #define GTK_THEMING_ENGINE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_THEMING_ENGINE, GtkThemingEnginePrivate))
77 static void gtk_theming_engine_finalize (GObject *object);
78 static void gtk_theming_engine_impl_set_property (GObject *object,
82 static void gtk_theming_engine_impl_get_property (GObject *object,
87 static void gtk_theming_engine_render_check (GtkThemingEngine *engine,
93 static void gtk_theming_engine_render_option (GtkThemingEngine *engine,
99 static void gtk_theming_engine_render_arrow (GtkThemingEngine *engine,
105 static void gtk_theming_engine_render_background (GtkThemingEngine *engine,
111 static void gtk_theming_engine_render_frame (GtkThemingEngine *engine,
117 static void gtk_theming_engine_render_expander (GtkThemingEngine *engine,
123 static void gtk_theming_engine_render_focus (GtkThemingEngine *engine,
129 static void gtk_theming_engine_render_layout (GtkThemingEngine *engine,
133 PangoLayout *layout);
134 static void gtk_theming_engine_render_line (GtkThemingEngine *engine,
140 static void gtk_theming_engine_render_slider (GtkThemingEngine *engine,
146 GtkOrientation orientation);
147 static void gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
153 GtkPositionType gap_side,
156 static void gtk_theming_engine_render_extension (GtkThemingEngine *engine,
162 GtkPositionType gap_side);
163 static void gtk_theming_engine_render_handle (GtkThemingEngine *engine,
169 static void gtk_theming_engine_render_activity (GtkThemingEngine *engine,
175 static GdkPixbuf * gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine *engine,
176 const GtkIconSource *source,
179 G_DEFINE_TYPE (GtkThemingEngine, gtk_theming_engine, G_TYPE_OBJECT)
182 typedef struct GtkThemingModule GtkThemingModule;
183 typedef struct GtkThemingModuleClass GtkThemingModuleClass;
185 struct GtkThemingModule
187 GTypeModule parent_instance;
191 void (*init) (GTypeModule *module);
193 GtkThemingEngine * (*create_engine) (void);
196 struct GtkThemingModuleClass
198 GTypeModuleClass parent_class;
201 #define GTK_TYPE_THEMING_MODULE (gtk_theming_module_get_type ())
202 #define GTK_THEMING_MODULE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_THEMING_MODULE, GtkThemingModule))
203 #define GTK_IS_THEMING_MODULE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_THEMING_MODULE))
205 G_DEFINE_TYPE (GtkThemingModule, gtk_theming_module, G_TYPE_TYPE_MODULE);
208 gtk_theming_engine_class_init (GtkThemingEngineClass *klass)
210 GObjectClass *object_class = G_OBJECT_CLASS (klass);
212 object_class->finalize = gtk_theming_engine_finalize;
213 object_class->set_property = gtk_theming_engine_impl_set_property;
214 object_class->get_property = gtk_theming_engine_impl_get_property;
216 klass->render_check = gtk_theming_engine_render_check;
217 klass->render_option = gtk_theming_engine_render_option;
218 klass->render_arrow = gtk_theming_engine_render_arrow;
219 klass->render_background = gtk_theming_engine_render_background;
220 klass->render_frame = gtk_theming_engine_render_frame;
221 klass->render_expander = gtk_theming_engine_render_expander;
222 klass->render_focus = gtk_theming_engine_render_focus;
223 klass->render_layout = gtk_theming_engine_render_layout;
224 klass->render_line = gtk_theming_engine_render_line;
225 klass->render_slider = gtk_theming_engine_render_slider;
226 klass->render_frame_gap = gtk_theming_engine_render_frame_gap;
227 klass->render_extension = gtk_theming_engine_render_extension;
228 klass->render_handle = gtk_theming_engine_render_handle;
229 klass->render_activity = gtk_theming_engine_render_activity;
230 klass->render_icon_pixbuf = gtk_theming_engine_render_icon_pixbuf;
233 * GtkThemingEngine:name:
235 * The theming engine name, this name will be used when registering
236 * custom properties, for a theming engine named "Clearlooks" registering
237 * a "glossy" custom property, it could be referenced in the CSS file as
240 * -Clearlooks-glossy: true;
245 g_object_class_install_property (object_class,
247 g_param_spec_string ("name",
249 P_("Theming engine name"),
251 G_PARAM_CONSTRUCT_ONLY | GTK_PARAM_READWRITE));
253 g_type_class_add_private (object_class, sizeof (GtkThemingEnginePrivate));
257 gtk_theming_engine_init (GtkThemingEngine *engine)
259 engine->priv = GTK_THEMING_ENGINE_GET_PRIVATE (engine);
263 gtk_theming_engine_finalize (GObject *object)
265 GtkThemingEnginePrivate *priv;
267 priv = GTK_THEMING_ENGINE (object)->priv;
270 G_OBJECT_GET_CLASS (gtk_theming_engine_parent_class)->finalize (object);
274 gtk_theming_engine_impl_set_property (GObject *object,
279 GtkThemingEnginePrivate *priv;
281 priv = GTK_THEMING_ENGINE (object)->priv;
289 priv->name = g_value_dup_string (value);
292 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
298 gtk_theming_engine_impl_get_property (GObject *object,
303 GtkThemingEnginePrivate *priv;
305 priv = GTK_THEMING_ENGINE (object)->priv;
310 g_value_set_string (value, priv->name);
313 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
319 _gtk_theming_engine_set_context (GtkThemingEngine *engine,
320 GtkStyleContext *context)
322 GtkThemingEnginePrivate *priv;
324 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
325 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
328 priv->context = context;
332 * gtk_theming_engine_register_property:
333 * @engine: a #GtkThemingEngine
334 * @name_space: namespace for the property name
335 * @parse_func: parsing function to use, or %NULL
336 * @pspec: the #GParamSpec for the new property
338 * Registers a property so it can be used in the CSS file format,
339 * on the CSS file the property will look like
340 * "-${@name_space}-${property_name}". being
341 * ${property_name} the given to @pspec. @name_space will usually
342 * be the theme engine name.
344 * For any type a @parse_func may be provided, being this function
345 * used for turning any property value (between ':' and ';') in
346 * CSS to the #GValue needed. For basic types there is already
347 * builtin parsing support, so %NULL may be provided for these
351 * Engines must ensure property registration happens exactly once,
352 * usually GTK+ deals with theming engines as singletons, so this
353 * should be guaranteed to happen once, but bear this in mind
354 * when creating #GtkThemeEngine<!-- -->s yourself.
358 * In order to make use of the custom registered properties in
359 * the CSS file, make sure the engine is loaded first by specifying
360 * the engine property, either in a previous rule or within the same
364 * engine: someengine;
365 * -SomeEngine-custom-property: 2;
373 gtk_theming_engine_register_property (const gchar *name_space,
374 GtkStylePropertyParser parse_func,
379 g_return_if_fail (name_space != NULL);
380 g_return_if_fail (strchr (name_space, ' ') == NULL);
381 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
383 /* FIXME: hack hack hack, replacing pspec->name to include namespace */
384 name = g_strdup_printf ("-%s-%s", name_space, pspec->name);
385 g_free (pspec->name);
388 gtk_style_properties_register_property (parse_func, pspec);
392 * gtk_theming_engine_get_property:
393 * @engine: a #GtkThemingEngine
394 * @property: the property name
395 * @state: state to retrieve the value for
396 * @value: (out) (transfer full): return location for the property value,
397 * you must free this memory using g_value_unset() once you are
400 * Gets a property value as retrieved from the style settings that apply
401 * to the currently rendered element.
406 gtk_theming_engine_get_property (GtkThemingEngine *engine,
407 const gchar *property,
411 GtkThemingEnginePrivate *priv;
413 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
414 g_return_if_fail (property != NULL);
415 g_return_if_fail (value != NULL);
418 gtk_style_context_get_property (priv->context, property, state, value);
422 * gtk_theming_engine_get_valist:
423 * @engine: a #GtkThemingEngine
424 * @state: state to retrieve values for
425 * @args: va_list of property name/return location pairs, followed by %NULL
427 * Retrieves several style property values that apply to the currently
433 gtk_theming_engine_get_valist (GtkThemingEngine *engine,
437 GtkThemingEnginePrivate *priv;
439 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
442 gtk_style_context_get_valist (priv->context, state, args);
446 * gtk_theming_engine_get:
447 * @engine: a #GtkThemingEngine
448 * @state: state to retrieve values for
449 * @...: property name /return value pairs, followed by %NULL
451 * Retrieves several style property values that apply to the currently
457 gtk_theming_engine_get (GtkThemingEngine *engine,
461 GtkThemingEnginePrivate *priv;
464 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
468 va_start (args, state);
469 gtk_style_context_get_valist (priv->context, state, args);
474 * gtk_theming_engine_get_style_property:
475 * @engine: a #GtkThemingEngine
476 * @property_name: the name of the widget style property
477 * @value: (out) (transfer full): Return location for the property value, free with
478 * g_value_unset() after use.
480 * Gets the value for a widget style property.
485 gtk_theming_engine_get_style_property (GtkThemingEngine *engine,
486 const gchar *property_name,
489 GtkThemingEnginePrivate *priv;
491 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
492 g_return_if_fail (property_name != NULL);
495 gtk_style_context_get_style_property (priv->context, property_name, value);
499 * gtk_theming_engine_get_style_valist:
500 * @engine: a #GtkThemingEngine
501 * @args: va_list of property name/return location pairs, followed by %NULL
503 * Retrieves several widget style properties from @engine according to the
504 * currently rendered content's style.
509 gtk_theming_engine_get_style_valist (GtkThemingEngine *engine,
512 GtkThemingEnginePrivate *priv;
514 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
517 gtk_style_context_get_style_valist (priv->context, args);
521 * gtk_theming_engine_get_style:
522 * @engine: a #GtkThemingEngine
523 * @...: property name /return value pairs, followed by %NULL
525 * Retrieves several widget style properties from @engine according
526 * to the currently rendered content's style.
531 gtk_theming_engine_get_style (GtkThemingEngine *engine,
534 GtkThemingEnginePrivate *priv;
537 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
541 va_start (args, engine);
542 gtk_style_context_get_style_valist (priv->context, args);
547 * gtk_theming_engine_get_state:
548 * @engine: a #GtkThemingEngine
550 * returns the state used when rendering.
552 * Returns: the state flags
557 gtk_theming_engine_get_state (GtkThemingEngine *engine)
559 GtkThemingEnginePrivate *priv;
561 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), 0);
564 return gtk_style_context_get_state (priv->context);
568 * gtk_theming_engine_state_is_running:
569 * @engine: a #GtkThemingEngine
570 * @state: a widget state
571 * @progress: (out): return location for the transition progress
573 * Returns %TRUE if there is a transition animation running for the
574 * current region (see gtk_style_context_push_animatable_region()).
576 * If @progress is not %NULL, the animation progress will be returned
577 * there, 0.0 means the state is closest to being %FALSE, while 1.0 means
578 * it's closest to being %TRUE. This means transition animations will
579 * run from 0 to 1 when @state is being set to %TRUE and from 1 to 0 when
580 * it's being set to %FALSE.
582 * Returns: %TRUE if there is a running transition animation for @state.
587 gtk_theming_engine_state_is_running (GtkThemingEngine *engine,
591 GtkThemingEnginePrivate *priv;
593 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
596 return gtk_style_context_state_is_running (priv->context, state, progress);
600 * gtk_theming_engine_get_path:
601 * @engine: a #GtkThemingEngine
603 * Returns the widget path used for style matching.
605 * Returns: (transfer none): A #GtkWidgetPath
609 G_CONST_RETURN GtkWidgetPath *
610 gtk_theming_engine_get_path (GtkThemingEngine *engine)
612 GtkThemingEnginePrivate *priv;
614 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
617 return gtk_style_context_get_path (priv->context);
621 * gtk_theming_engine_has_class:
622 * @engine: a #GtkThemingEngine
623 * @style_class: class name to look up
625 * Returns %TRUE if the currently rendered contents have
626 * defined the given class name.
628 * Returns: %TRUE if @engine has @class_name defined
633 gtk_theming_engine_has_class (GtkThemingEngine *engine,
634 const gchar *style_class)
636 GtkThemingEnginePrivate *priv;
638 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
641 return gtk_style_context_has_class (priv->context, style_class);
645 * gtk_theming_engine_has_region:
646 * @engine: a #GtkThemingEngine
647 * @style_region: a region name
648 * @flags: (out) (allow-none): return location for region flags
650 * Returns %TRUE if the currently rendered contents have the
651 * region defined. If @flags_return is not %NULL, it is set
652 * to the flags affecting the region.
654 * Returns: %TRUE if region is defined
659 gtk_theming_engine_has_region (GtkThemingEngine *engine,
660 const gchar *style_region,
661 GtkRegionFlags *flags)
663 GtkThemingEnginePrivate *priv;
668 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
671 return gtk_style_context_has_region (priv->context, style_region, flags);
675 * gtk_theming_engine_get_direction:
676 * @engine: a #GtkThemingEngine
678 * Returns the widget direction used for rendering.
680 * Returns: the widget direction
685 gtk_theming_engine_get_direction (GtkThemingEngine *engine)
687 GtkThemingEnginePrivate *priv;
689 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), GTK_TEXT_DIR_LTR);
692 return gtk_style_context_get_direction (priv->context);
696 * gtk_theming_engine_get_junction_sides:
697 * @engine: a #GtkThemingEngine
699 * Returns the widget direction used for rendering.
701 * Returns: the widget direction
706 gtk_theming_engine_get_junction_sides (GtkThemingEngine *engine)
708 GtkThemingEnginePrivate *priv;
710 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), 0);
713 return gtk_style_context_get_junction_sides (priv->context);
716 /* GtkThemingModule */
719 gtk_theming_module_load (GTypeModule *type_module)
721 GtkThemingModule *theming_module;
723 gchar *name, *module_path;
725 theming_module = GTK_THEMING_MODULE (type_module);
726 name = theming_module->name;
727 module_path = _gtk_find_module (name, "theming-engines");
731 g_warning (_("Unable to locate theme engine in module path: \"%s\","), name);
735 module = g_module_open (module_path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
736 g_free (module_path);
740 g_warning ("%s", g_module_error ());
744 if (!g_module_symbol (module, "theme_init",
745 (gpointer *) &theming_module->init) ||
746 !g_module_symbol (module, "theme_exit",
747 (gpointer *) &theming_module->exit) ||
748 !g_module_symbol (module, "create_engine",
749 (gpointer *) &theming_module->create_engine))
751 g_warning ("%s", g_module_error ());
752 g_module_close (module);
757 theming_module->module = module;
759 theming_module->init (G_TYPE_MODULE (theming_module));
765 gtk_theming_module_unload (GTypeModule *type_module)
767 GtkThemingModule *theming_module;
769 theming_module = GTK_THEMING_MODULE (type_module);
771 theming_module->exit ();
773 g_module_close (theming_module->module);
775 theming_module->module = NULL;
776 theming_module->init = NULL;
777 theming_module->exit = NULL;
778 theming_module->create_engine = NULL;
782 gtk_theming_module_class_init (GtkThemingModuleClass *klass)
784 GTypeModuleClass *module_class = G_TYPE_MODULE_CLASS (klass);
786 module_class->load = gtk_theming_module_load;
787 module_class->unload = gtk_theming_module_unload;
791 gtk_theming_module_init (GtkThemingModule *module)
796 * gtk_theming_engine_load:
797 * @name: Theme engine name to load
799 * Loads and initializes a theming engine module from the
800 * standard directories.
802 * Returns: (transfer none): A theming engine, or %NULL if
803 * the engine @name doesn't exist.
806 gtk_theming_engine_load (const gchar *name)
808 static GHashTable *engines = NULL;
809 static GtkThemingEngine *default_engine;
810 GtkThemingEngine *engine = NULL;
815 engines = g_hash_table_new (g_str_hash, g_str_equal);
817 engine = g_hash_table_lookup (engines, name);
821 GtkThemingModule *module;
823 module = g_object_new (GTK_TYPE_THEMING_MODULE, NULL);
824 g_type_module_set_name (G_TYPE_MODULE (module), name);
825 module->name = g_strdup (name);
827 if (module && g_type_module_use (G_TYPE_MODULE (module)))
829 engine = (module->create_engine) ();
832 g_hash_table_insert (engines, module->name, engine);
839 if (G_UNLIKELY (!default_engine))
840 default_engine = g_object_new (GTK_TYPE_THEMING_ENGINE, NULL);
842 engine = default_engine;
849 * gtk_theming_engine_get_screen:
850 * @engine: a #GtkThemingEngine
852 * Returns the #GdkScreen to which @engine currently rendering to.
854 * Returns: a #GdkScreen, or %NULL.
857 gtk_theming_engine_get_screen (GtkThemingEngine *engine)
859 GtkThemingEnginePrivate *priv;
861 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
864 return gtk_style_context_get_screen (priv->context);
867 /* Paint method implementations */
869 gtk_theming_engine_render_check (GtkThemingEngine *engine,
876 GdkRGBA *fg_color, *bg_color;
878 gint exterior_size, interior_size, thickness, pad;
880 flags = gtk_theming_engine_get_state (engine);
883 gtk_theming_engine_get (engine, flags,
885 "background-color", &bg_color,
888 exterior_size = MIN (width, height);
890 if (exterior_size % 2 == 0) /* Ensure odd */
893 /* FIXME: thickness */
895 pad = thickness + MAX (1, (exterior_size - 2 * thickness) / 9);
896 interior_size = MAX (1, exterior_size - 2 * pad);
898 if (interior_size < 7)
901 pad = MAX (0, (exterior_size - interior_size) / 2);
904 x -= (1 + exterior_size - (gint) width) / 2;
905 y -= (1 + exterior_size - (gint) height) / 2;
907 if (!gtk_theming_engine_has_class (engine, "menu"))
909 cairo_set_line_width (cr, 1.0);
911 cairo_rectangle (cr, x + 0.5, y + 0.5, exterior_size - 1, exterior_size - 1);
912 gdk_cairo_set_source_rgba (cr, bg_color);
913 cairo_fill_preserve (cr);
915 gdk_cairo_set_source_rgba (cr, fg_color);
919 gdk_cairo_set_source_rgba (cr, fg_color);
921 if (flags & GTK_STATE_FLAG_INCONSISTENT)
923 int line_thickness = MAX (1, (3 + interior_size * 2) / 7);
927 y + pad + (1 + interior_size - line_thickness) / 2,
937 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress);
939 if ((flags & GTK_STATE_FLAG_ACTIVE) || running)
947 cairo_scale (cr, interior_size / 7., interior_size / 7.);
949 cairo_rectangle (cr, 0, 0, 7 * progress, 7);
952 cairo_move_to (cr, 7.0, 0.0);
953 cairo_line_to (cr, 7.5, 1.0);
954 cairo_curve_to (cr, 5.3, 2.0,
957 cairo_curve_to (cr, 3.0, 5.7,
960 cairo_line_to (cr, 0.2, 3.5);
961 cairo_curve_to (cr, 1.1, 3.5,
964 cairo_curve_to (cr, 1.0, 3.9,
967 cairo_curve_to (cr, 3.5, 3.1,
977 gdk_rgba_free (fg_color);
978 gdk_rgba_free (bg_color);
982 gtk_theming_engine_render_option (GtkThemingEngine *engine,
990 GdkRGBA *fg_color, *bg_color;
991 gint exterior_size, interior_size, pad, thickness;
994 flags = gtk_theming_engine_get_state (engine);
995 radius = MIN (width, height) / 2 - 0.5;
999 gtk_theming_engine_get (engine, flags,
1001 "background-color", &bg_color,
1004 exterior_size = MIN (width, height);
1006 if (exterior_size % 2 == 0) /* Ensure odd */
1009 x -= (1 + exterior_size - width) / 2;
1010 y -= (1 + exterior_size - height) / 2;
1012 if (!gtk_theming_engine_has_class (engine, "menu"))
1014 cairo_set_line_width (cr, 1.);
1016 x + exterior_size / 2.,
1017 y + exterior_size / 2.,
1018 (exterior_size - 1) / 2.,
1021 gdk_cairo_set_source_rgba (cr, bg_color);
1022 cairo_fill_preserve (cr);
1024 gdk_cairo_set_source_rgba (cr, fg_color);
1028 gdk_cairo_set_source_rgba (cr, fg_color);
1030 /* FIXME: thickness */
1033 if (flags & GTK_STATE_FLAG_INCONSISTENT)
1035 gint line_thickness;
1037 pad = thickness + MAX (1, (exterior_size - 2 * thickness) / 9);
1038 interior_size = MAX (1, exterior_size - 2 * pad);
1040 if (interior_size < 7)
1043 pad = MAX (0, (exterior_size - interior_size) / 2);
1046 line_thickness = MAX (1, (3 + interior_size * 2) / 7);
1048 cairo_rectangle (cr,
1050 y + pad + (interior_size - line_thickness) / 2.,
1055 if (flags & GTK_STATE_FLAG_ACTIVE)
1057 pad = thickness + MAX (1, 2 * (exterior_size - 2 * thickness) / 9);
1058 interior_size = MAX (1, exterior_size - 2 * pad);
1060 if (interior_size < 5)
1063 pad = MAX (0, (exterior_size - interior_size) / 2);
1067 x + pad + interior_size / 2.,
1068 y + pad + interior_size / 2.,
1076 gdk_rgba_free (fg_color);
1077 gdk_rgba_free (bg_color);
1081 add_path_arrow (cairo_t *cr,
1089 cairo_translate (cr, x + (size / 2), y + (size / 2));
1090 cairo_rotate (cr, angle);
1092 cairo_move_to (cr, 0, - (size / 4));
1093 cairo_line_to (cr, - (size / 2), (size / 4));
1094 cairo_line_to (cr, (size / 2), (size / 4));
1095 cairo_close_path (cr);
1101 gtk_theming_engine_render_arrow (GtkThemingEngine *engine,
1108 GtkStateFlags flags;
1113 flags = gtk_theming_engine_get_state (engine);
1115 gtk_theming_engine_get (engine, flags,
1119 if (flags & GTK_STATE_FLAG_INSENSITIVE)
1121 add_path_arrow (cr, angle, x + 1, y + 1, size);
1122 cairo_set_source_rgb (cr, 1, 1, 1);
1126 add_path_arrow (cr, angle, x, y, size);
1127 gdk_cairo_set_source_rgba (cr, fg_color);
1132 gdk_rgba_free (fg_color);
1136 add_path_line (cairo_t *cr,
1142 /* Adjust endpoints */
1156 cairo_move_to (cr, x1, y1);
1157 cairo_line_to (cr, x2, y2);
1161 color_shade (const GdkRGBA *color,
1163 GdkRGBA *color_return)
1165 GtkSymbolicColor *literal, *shade;
1167 literal = gtk_symbolic_color_new_literal (color);
1168 shade = gtk_symbolic_color_new_shade (literal, factor);
1169 gtk_symbolic_color_unref (literal);
1171 gtk_symbolic_color_resolve (shade, NULL, color_return);
1172 gtk_symbolic_color_unref (shade);
1176 _cairo_round_rectangle_sides (cairo_t *cr,
1183 GtkJunctionSides junction)
1185 radius = CLAMP (radius, 0, MIN (width / 2, height / 2));
1187 if (sides & SIDE_RIGHT)
1190 (junction & GTK_JUNCTION_TOP) ||
1191 (junction & GTK_JUNCTION_RIGHT))
1192 cairo_move_to (cr, x + width, y);
1195 cairo_new_sub_path (cr);
1196 cairo_arc (cr, x + width - radius, y + radius, radius, - G_PI / 4, 0);
1200 (junction & GTK_JUNCTION_BOTTOM) ||
1201 (junction & GTK_JUNCTION_RIGHT))
1202 cairo_line_to (cr, x + width, y + height);
1204 cairo_arc (cr, x + width - radius, y + height - radius, radius, 0, G_PI / 4);
1207 if (sides & SIDE_BOTTOM)
1210 ! (junction & GTK_JUNCTION_RIGHT) &&
1211 ! (junction & GTK_JUNCTION_BOTTOM))
1213 if ((sides & SIDE_RIGHT) == 0)
1214 cairo_new_sub_path (cr);
1216 cairo_arc (cr, x + width - radius, y + height - radius, radius, G_PI / 4, G_PI / 2);
1218 else if ((sides & SIDE_RIGHT) == 0)
1219 cairo_move_to (cr, x + width, y + height);
1222 (junction & GTK_JUNCTION_BOTTOM) ||
1223 (junction & GTK_JUNCTION_LEFT))
1224 cairo_line_to (cr, x, y + height);
1226 cairo_arc (cr, x + radius, y + height - radius, radius, G_PI / 2, 3 * (G_PI / 4));
1229 cairo_move_to (cr, x, y + height);
1231 if (sides & SIDE_LEFT)
1234 ! (junction & GTK_JUNCTION_LEFT) &&
1235 ! (junction & GTK_JUNCTION_BOTTOM))
1237 if ((sides & SIDE_BOTTOM) == 0)
1238 cairo_new_sub_path (cr);
1240 cairo_arc (cr, x + radius, y + height - radius, radius, 3 * (G_PI / 4), G_PI);
1242 else if ((sides & SIDE_BOTTOM) == 0)
1243 cairo_move_to (cr, x, y + height);
1246 (junction & GTK_JUNCTION_TOP) ||
1247 (junction & GTK_JUNCTION_LEFT))
1248 cairo_line_to (cr, x, y);
1250 cairo_arc (cr, x + radius, y + radius, radius, G_PI, G_PI + G_PI / 4);
1253 if (sides & SIDE_TOP)
1256 ! (junction & GTK_JUNCTION_TOP) &&
1257 ! (junction & GTK_JUNCTION_LEFT))
1259 if ((sides & SIDE_LEFT) == 0)
1260 cairo_new_sub_path (cr);
1262 cairo_arc (cr, x + radius, y + radius, radius, 5 * (G_PI / 4), 3 * (G_PI / 2));
1264 else if ((sides & SIDE_LEFT) == 0)
1265 cairo_move_to (cr, x, y);
1268 (junction & GTK_JUNCTION_TOP) ||
1269 (junction & GTK_JUNCTION_RIGHT))
1270 cairo_line_to (cr, x + width, y);
1272 cairo_arc (cr, x + width - radius, y + radius, radius, 3 * (G_PI / 2), - G_PI / 4);
1277 gtk_theming_engine_render_background (GtkThemingEngine *engine,
1285 cairo_pattern_t *pattern;
1286 GtkStateFlags flags;
1288 gdouble progress, alpha = 1;
1289 GtkJunctionSides junction;
1290 gint radius, border_width;
1292 flags = gtk_theming_engine_get_state (engine);
1293 junction = gtk_theming_engine_get_junction_sides (engine);
1296 if (gtk_theming_engine_has_class (engine, "spinbutton") &&
1297 gtk_theming_engine_has_class (engine, "button"))
1305 gtk_theming_engine_get (engine, flags,
1306 "background-image", &pattern,
1307 "background-color", &bg_color,
1308 "border-width", &border_width,
1309 "border-radius", &radius,
1312 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
1314 if (border_width > 0)
1318 width -= 2 * border_width;
1319 height -= 2 * border_width;
1320 radius -= 2 * border_width;
1326 _cairo_round_rectangle_sides (cr, (gdouble) radius,
1327 x, y, width, height,
1328 SIDE_ALL, junction);
1331 if (gtk_theming_engine_has_class (engine, "background"))
1333 cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0); /* transparent */
1334 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
1338 cairo_translate (cr, x, y);
1339 cairo_scale (cr, width, height);
1343 cairo_pattern_t *other_pattern;
1344 GtkStateFlags other_flags;
1346 cairo_pattern_t *new_pattern = NULL;
1348 if (flags & GTK_STATE_FLAG_PRELIGHT)
1350 other_flags = flags & ~(GTK_STATE_FLAG_PRELIGHT);
1351 progress = 1 - progress;
1354 other_flags = flags | GTK_STATE_FLAG_PRELIGHT;
1356 gtk_theming_engine_get (engine, other_flags,
1357 "background-image", &other_pattern,
1358 "background-color", &other_bg,
1361 if (pattern && other_pattern)
1363 cairo_pattern_type_t type, other_type;
1366 cairo_pattern_get_color_stop_count (pattern, &n0);
1367 cairo_pattern_get_color_stop_count (other_pattern, &n1);
1368 type = cairo_pattern_get_type (pattern);
1369 other_type = cairo_pattern_get_type (other_pattern);
1371 if (type == other_type && n0 == n1)
1373 gdouble offset0, red0, green0, blue0, alpha0;
1374 gdouble offset1, red1, green1, blue1, alpha1;
1375 gdouble x00, x01, y00, y01, x10, x11, y10, y11;
1376 gdouble r00, r01, r10, r11;
1379 if (type == CAIRO_PATTERN_TYPE_LINEAR)
1381 cairo_pattern_get_linear_points (pattern, &x00, &y00, &x01, &y01);
1382 cairo_pattern_get_linear_points (other_pattern, &x10, &y10, &x11, &y11);
1384 new_pattern = cairo_pattern_create_linear (x00 + (x10 - x00) * progress,
1385 y00 + (y10 - y00) * progress,
1386 x01 + (x11 - x01) * progress,
1387 y01 + (y11 - y01) * progress);
1391 cairo_pattern_get_radial_circles (pattern, &x00, &y00, &r00, &x01, &y01, &r01);
1392 cairo_pattern_get_radial_circles (other_pattern, &x10, &y10, &r10, &x11, &y11, &r11);
1394 new_pattern = cairo_pattern_create_radial (x00 + (x10 - x00) * progress,
1395 y00 + (y10 - y00) * progress,
1396 r00 + (r10 - r00) * progress,
1397 x01 + (x11 - x01) * progress,
1398 y01 + (y11 - y01) * progress,
1399 r01 + (r11 - r01) * progress);
1402 cairo_pattern_set_filter (new_pattern, CAIRO_FILTER_FAST);
1405 /* Blend both gradients into one */
1406 while (i < n0 && i < n1)
1408 cairo_pattern_get_color_stop_rgba (pattern, i,
1410 &red0, &green0, &blue0,
1412 cairo_pattern_get_color_stop_rgba (other_pattern, i,
1414 &red1, &green1, &blue1,
1417 cairo_pattern_add_color_stop_rgba (new_pattern,
1418 offset0 + ((offset1 - offset0) * progress),
1419 red0 + ((red1 - red0) * progress),
1420 green0 + ((green1 - green0) * progress),
1421 blue0 + ((blue1 - blue0) * progress),
1422 alpha0 + ((alpha1 - alpha0) * progress));
1428 /* Different pattern types, or different color
1429 * stop counts, alpha blend both patterns.
1431 cairo_rectangle (cr, 0, 0, 1, 1);
1432 cairo_set_source (cr, other_pattern);
1433 cairo_fill_preserve (cr);
1435 /* Set alpha for posterior drawing
1436 * of the target pattern
1438 alpha = 1 - progress;
1441 else if (pattern || other_pattern)
1445 gdouble x0, y0, x1, y1, r0, r1;
1448 /* Blend a pattern with a color */
1453 progress = 1 - progress;
1461 if (cairo_pattern_get_type (p) == CAIRO_PATTERN_TYPE_LINEAR)
1463 cairo_pattern_get_linear_points (p, &x0, &y0, &x1, &y1);
1464 new_pattern = cairo_pattern_create_linear (x0, y0, x1, y1);
1468 cairo_pattern_get_radial_circles (p, &x0, &y0, &r0, &x1, &y1, &r1);
1469 new_pattern = cairo_pattern_create_radial (x0, y0, r0, x1, y1, r1);
1472 cairo_pattern_get_color_stop_count (p, &n);
1474 for (i = 0; i < n; i++)
1476 gdouble red1, green1, blue1, alpha1;
1479 cairo_pattern_get_color_stop_rgba (p, i,
1481 &red1, &green1, &blue1,
1483 cairo_pattern_add_color_stop_rgba (new_pattern, offset,
1484 c->red + ((red1 - c->red) * progress),
1485 c->green + ((green1 - c->green) * progress),
1486 c->blue + ((blue1 - c->blue) * progress),
1487 c->alpha + ((alpha1 - c->alpha) * progress));
1492 const GdkRGBA *color, *other_color;
1494 /* Merge just colors */
1496 other_color = other_bg;
1498 new_pattern = cairo_pattern_create_rgba (CLAMP (color->red + ((other_color->red - color->red) * progress), 0, 1),
1499 CLAMP (color->green + ((other_color->green - color->green) * progress), 0, 1),
1500 CLAMP (color->blue + ((other_color->blue - color->blue) * progress), 0, 1),
1501 CLAMP (color->alpha + ((other_color->alpha - color->alpha) * progress), 0, 1));
1506 /* Replace pattern to use */
1507 cairo_pattern_destroy (pattern);
1508 pattern = new_pattern;
1512 cairo_pattern_destroy (other_pattern);
1515 gdk_rgba_free (other_bg);
1518 cairo_rectangle (cr, 0, 0, 1, 1);
1522 cairo_set_source (cr, pattern);
1523 cairo_pattern_destroy (pattern);
1526 gdk_cairo_set_source_rgba (cr, bg_color);
1532 cairo_pattern_t *mask;
1534 mask = cairo_pattern_create_rgba (1, 1, 1, alpha);
1535 cairo_mask (cr, mask);
1536 cairo_pattern_destroy (mask);
1541 gdk_rgba_free (bg_color);
1545 render_frame_internal (GtkThemingEngine *engine,
1552 GtkJunctionSides junction)
1554 GtkStateFlags state;
1556 GdkRGBA *border_color;
1557 GtkBorderStyle border_style;
1558 gint border_width, radius;
1561 state = gtk_theming_engine_get_state (engine);
1562 gtk_theming_engine_get (engine, state,
1563 "border-color", &border_color,
1564 "border-style", &border_style,
1565 "border-width", &border_width,
1566 "border-radius", &radius,
1571 color_shade (border_color, 1.8, &lighter);
1573 switch (border_style)
1575 case GTK_BORDER_STYLE_NONE:
1577 case GTK_BORDER_STYLE_SOLID:
1578 cairo_set_line_width (cr, border_width);
1579 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
1581 if (border_width > 1)
1583 x += (gdouble) border_width / 2;
1584 y += (gdouble) border_width / 2;
1585 width -= border_width;
1586 height -= border_width;
1588 else if (border_width == 1)
1596 _cairo_round_rectangle_sides (cr, (gdouble) radius,
1597 x, y, width, height,
1598 SIDE_ALL & ~(hidden_side),
1600 gdk_cairo_set_source_rgba (cr, border_color);
1604 case GTK_BORDER_STYLE_INSET:
1605 case GTK_BORDER_STYLE_OUTSET:
1606 cairo_set_line_width (cr, border_width);
1607 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
1609 if (border_width > 1)
1611 d1 = (gdouble) border_width / 2;
1612 d2 = (gdouble) (border_width - (gint) d1) + 1;
1622 m = MIN (width, height);
1625 /* Only needed for square frames to have a 3D-like
1626 * feeling, for rounded ones, the arc will ensure
1627 * the stroke is painted to end at 45°.
1631 cairo_move_to (cr, x, y + height);
1632 cairo_line_to (cr, x + m, y + height - m);
1633 cairo_line_to (cr, x + width - m, y + m);
1634 cairo_line_to (cr, x + width, y);
1635 cairo_line_to (cr, x + width, y + height);
1636 cairo_close_path (cr);
1641 if (border_style == GTK_BORDER_STYLE_INSET)
1642 gdk_cairo_set_source_rgba (cr, &lighter);
1644 gdk_cairo_set_source_rgba (cr, border_color);
1646 _cairo_round_rectangle_sides (cr, (gdouble) radius,
1648 width - d2, height - d2,
1649 (SIDE_BOTTOM | SIDE_RIGHT) & ~(hidden_side),
1659 cairo_move_to (cr, x, y + height);
1660 cairo_line_to (cr, x + m, y + height - m);
1661 cairo_line_to (cr, x + width - m, y + m);
1662 cairo_line_to (cr, x + width, y);
1663 cairo_line_to (cr, x, y);
1664 cairo_close_path (cr);
1669 if (border_style == GTK_BORDER_STYLE_INSET)
1670 gdk_cairo_set_source_rgba (cr, border_color);
1672 gdk_cairo_set_source_rgba (cr, &lighter);
1674 _cairo_round_rectangle_sides (cr, (gdouble) radius,
1676 width - d2, height - d2,
1677 (SIDE_TOP | SIDE_LEFT) & ~(hidden_side),
1688 gdk_rgba_free (border_color);
1692 gtk_theming_engine_render_frame (GtkThemingEngine *engine,
1699 GtkStateFlags flags;
1701 GtkBorderStyle border_style;
1702 GtkJunctionSides junction;
1704 flags = gtk_theming_engine_get_state (engine);
1705 junction = gtk_theming_engine_get_junction_sides (engine);
1707 gtk_theming_engine_get (engine, flags,
1708 "border-image", &slice,
1709 "border-style", &border_style,
1714 gtk_9slice_render (slice, cr, x, y, width, height);
1715 gtk_9slice_unref (slice);
1717 else if (border_style != GTK_BORDER_STYLE_NONE)
1718 render_frame_internal (engine, cr,
1719 x, y, width, height,
1724 gtk_theming_engine_render_expander (GtkThemingEngine *engine,
1731 GtkStateFlags flags;
1732 GdkRGBA *bg_color, *fg_color;
1733 double vertical_overshoot;
1736 double interp; /* interpolation factor for center position */
1737 double x_double_horz, y_double_horz;
1738 double x_double_vert, y_double_vert;
1739 double x_double, y_double;
1744 flags = gtk_theming_engine_get_state (engine);
1746 gtk_theming_engine_get (engine, flags,
1748 "background-color", &bg_color,
1753 /* FIXME: LTR/RTL */
1754 if (flags & GTK_STATE_FLAG_ACTIVE)
1765 /* Compute distance that the stroke extends beyonds the end
1766 * of the triangle we draw.
1768 vertical_overshoot = line_width / 2.0 * (1. / tan (G_PI / 8));
1770 /* For odd line widths, we end the vertical line of the triangle
1771 * at a half pixel, so we round differently.
1773 if (line_width % 2 == 1)
1774 vertical_overshoot = ceil (0.5 + vertical_overshoot) - 0.5;
1776 vertical_overshoot = ceil (vertical_overshoot);
1778 /* Adjust the size of the triangle we draw so that the entire stroke fits
1780 diameter = (gint) MAX (3, width - 2 * vertical_overshoot);
1782 /* If the line width is odd, we want the diameter to be even,
1783 * and vice versa, so force the sum to be odd. This relationship
1784 * makes the point of the triangle look right.
1786 diameter -= (1 - (diameter + line_width) % 2);
1788 radius = diameter / 2.;
1790 /* Adjust the center so that the stroke is properly aligned with
1791 * the pixel grid. The center adjustment is different for the
1792 * horizontal and vertical orientations. For intermediate positions
1793 * we interpolate between the two.
1795 x_double_vert = floor ((x + width / 2) - (radius + line_width) / 2.) + (radius + line_width) / 2.;
1796 y_double_vert = (y + height / 2) - 0.5;
1798 x_double_horz = (x + width / 2) - 0.5;
1799 y_double_horz = floor ((y + height / 2) - (radius + line_width) / 2.) + (radius + line_width) / 2.;
1801 x_double = x_double_vert * (1 - interp) + x_double_horz * interp;
1802 y_double = y_double_vert * (1 - interp) + y_double_horz * interp;
1804 cairo_translate (cr, x_double, y_double);
1805 cairo_rotate (cr, angle);
1807 cairo_move_to (cr, - radius / 2., - radius);
1808 cairo_line_to (cr, radius / 2., 0);
1809 cairo_line_to (cr, - radius / 2., radius);
1810 cairo_close_path (cr);
1812 cairo_set_line_width (cr, line_width);
1814 gdk_cairo_set_source_rgba (cr, fg_color);
1816 cairo_fill_preserve (cr);
1818 gdk_cairo_set_source_rgba (cr, fg_color);
1823 gdk_rgba_free (fg_color);
1824 gdk_rgba_free (bg_color);
1828 gtk_theming_engine_render_focus (GtkThemingEngine *engine,
1835 GtkStateFlags flags;
1841 flags = gtk_theming_engine_get_state (engine);
1843 gtk_theming_engine_get (engine, flags,
1847 gtk_theming_engine_get_style (engine,
1848 "focus-line-width", &line_width,
1849 "focus-line-pattern", (gchar *) &dash_list,
1852 cairo_set_line_width (cr, (gdouble) line_width);
1856 gint n_dashes = strlen ((const gchar *) dash_list);
1857 gdouble *dashes = g_new (gdouble, n_dashes);
1858 gdouble total_length = 0;
1859 gdouble dash_offset;
1862 for (i = 0; i < n_dashes; i++)
1864 dashes[i] = dash_list[i];
1865 total_length += dash_list[i];
1868 /* The dash offset here aligns the pattern to integer pixels
1869 * by starting the dash at the right side of the left border
1870 * Negative dash offsets in cairo don't work
1871 * (https://bugs.freedesktop.org/show_bug.cgi?id=2729)
1873 dash_offset = - line_width / 2.;
1875 while (dash_offset < 0)
1876 dash_offset += total_length;
1878 cairo_set_dash (cr, dashes, n_dashes, dash_offset);
1882 cairo_rectangle (cr,
1883 x + line_width / 2.,
1884 y + line_width / 2.,
1886 height - line_width);
1888 gdk_cairo_set_source_rgba (cr, color);
1893 gdk_rgba_free (color);
1898 gtk_theming_engine_render_line (GtkThemingEngine *engine,
1905 GdkRGBA *bg_color, darker, lighter;
1906 GtkStateFlags flags;
1907 gint i, thickness, thickness_dark, thickness_light, len;
1908 cairo_matrix_t matrix;
1911 /* FIXME: thickness */
1913 thickness_dark = thickness / 2;
1914 thickness_light = thickness - thickness_dark;
1916 flags = gtk_theming_engine_get_state (engine);
1919 gtk_theming_engine_get (engine, flags,
1920 "background-color", &bg_color,
1922 color_shade (bg_color, 0.7, &darker);
1923 color_shade (bg_color, 1.3, &lighter);
1925 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
1926 cairo_set_line_width (cr, 1);
1928 angle = atan2 (x1 - x0, y1 - y0);
1929 angle = (2 * G_PI) - angle;
1932 cairo_get_matrix (cr, &matrix);
1933 cairo_matrix_translate (&matrix, x0, y0);
1934 cairo_matrix_rotate (&matrix, angle);
1935 cairo_set_matrix (cr, &matrix);
1940 len = (gint) sqrt ((x1 * x1) + (y1 * y1));
1942 y0 = -thickness_dark;
1944 for (i = 0; i < thickness_dark; i++)
1946 gdk_cairo_set_source_rgba (cr, &lighter);
1947 add_path_line (cr, len - i - 1.5, y0, len - 0.5, y0);
1950 gdk_cairo_set_source_rgba (cr, &darker);
1951 add_path_line (cr, 0.5, y0, len - i - 1.5, y0);
1957 for (i = 0; i < thickness_light; i++)
1959 gdk_cairo_set_source_rgba (cr, &darker);
1960 add_path_line (cr, 0.5, y0, thickness_light - i + 0.5, y0);
1963 gdk_cairo_set_source_rgba (cr, &lighter);
1964 add_path_line (cr, thickness_light - i + 0.5, y0, len - 0.5, y0);
1972 gdk_rgba_free (bg_color);
1976 gtk_theming_engine_render_layout (GtkThemingEngine *engine,
1980 PangoLayout *layout)
1982 const PangoMatrix *matrix;
1984 GtkStateFlags flags;
1988 flags = gtk_theming_engine_get_state (engine);
1990 gtk_theming_engine_get (engine, flags,
1994 screen = gtk_theming_engine_get_screen (engine);
1995 matrix = pango_context_get_matrix (pango_layout_get_context (layout));
1999 cairo_matrix_t cairo_matrix;
2000 PangoMatrix tmp_matrix;
2001 PangoRectangle rect;
2003 cairo_matrix_init (&cairo_matrix,
2004 matrix->xx, matrix->yx,
2005 matrix->xy, matrix->yy,
2006 matrix->x0, matrix->y0);
2008 pango_layout_get_extents (layout, NULL, &rect);
2009 pango_matrix_transform_rectangle (matrix, &rect);
2010 pango_extents_to_pixels (&rect, NULL);
2012 tmp_matrix = *matrix;
2013 cairo_matrix.x0 += x - rect.x;
2014 cairo_matrix.y0 += y - rect.y;
2016 cairo_set_matrix (cr, &cairo_matrix);
2019 cairo_translate (cr, x, y);
2021 if (flags & GTK_STATE_FLAG_INSENSITIVE)
2024 cairo_set_source_rgb (cr, 1, 1, 1);
2025 cairo_move_to (cr, 1, 1);
2026 _gtk_pango_fill_layout (cr, layout);
2030 gdk_cairo_set_source_rgba (cr, fg_color);
2031 pango_cairo_show_layout (cr, layout);
2035 gdk_rgba_free (fg_color);
2039 gtk_theming_engine_render_slider (GtkThemingEngine *engine,
2045 GtkOrientation orientation)
2047 const GtkWidgetPath *path;
2050 path = gtk_theming_engine_get_path (engine);
2052 gtk_theming_engine_render_background (engine, cr, x, y, width, height);
2053 gtk_theming_engine_render_frame (engine, cr, x, y, width, height);
2055 /* FIXME: thickness */
2058 if (gtk_widget_path_is_type (path, GTK_TYPE_SCALE))
2060 if (orientation == GTK_ORIENTATION_VERTICAL)
2061 gtk_theming_engine_render_line (engine, cr,
2063 y + (gint) height / 2,
2064 x + width - thickness - 1,
2065 y + (gint) height / 2);
2067 gtk_theming_engine_render_line (engine, cr,
2068 x + (gint) width / 2,
2070 x + (gint) width / 2,
2071 y + height - thickness - 1);
2076 gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
2082 GtkPositionType gap_side,
2086 GtkJunctionSides junction = 0;
2087 GtkStateFlags state;
2091 state = gtk_theming_engine_get_state (engine);
2092 gtk_theming_engine_get (engine, state,
2093 "border-width", &border_width,
2094 "background-color", &bg_color,
2102 junction = GTK_JUNCTION_TOP;
2104 case GTK_POS_BOTTOM:
2105 junction = GTK_JUNCTION_BOTTOM;
2108 junction = GTK_JUNCTION_LEFT;
2111 junction = GTK_JUNCTION_RIGHT;
2115 render_frame_internal (engine, cr,
2116 x, y, width, height,
2121 cairo_rectangle (cr,
2122 x + xy0_gap + border_width, y,
2123 xy1_gap - xy0_gap - 2 * border_width,
2126 case GTK_POS_BOTTOM:
2127 cairo_rectangle (cr,
2128 x + xy0_gap + border_width,
2129 y + height - border_width,
2130 xy1_gap - xy0_gap - 2 * border_width,
2134 cairo_rectangle (cr,
2135 x, y + xy0_gap + border_width, border_width,
2136 xy1_gap - xy0_gap - 2 * border_width);
2139 cairo_rectangle (cr,
2140 x + width - border_width,
2141 y + xy0_gap + border_width, border_width,
2142 xy1_gap - xy0_gap - 2 * border_width);
2146 gdk_cairo_set_source_rgba (cr, bg_color);
2152 gdk_rgba_free (bg_color);
2156 gtk_theming_engine_render_extension (GtkThemingEngine *engine,
2162 GtkPositionType gap_side)
2164 GtkJunctionSides junction = 0;
2165 GtkStateFlags state;
2166 guint hidden_side = 0;
2175 junction = GTK_JUNCTION_LEFT;
2176 hidden_side = SIDE_LEFT;
2179 junction = GTK_JUNCTION_RIGHT;
2180 hidden_side = SIDE_RIGHT;
2183 junction = GTK_JUNCTION_TOP;
2184 hidden_side = SIDE_TOP;
2186 case GTK_POS_BOTTOM:
2187 junction = GTK_JUNCTION_BOTTOM;
2188 hidden_side = SIDE_BOTTOM;
2192 state = gtk_theming_engine_get_state (engine);
2193 gtk_theming_engine_get (engine, state,
2194 "background-color", &bg_color,
2195 "border-radius", &radius,
2198 _cairo_round_rectangle_sides (cr, radius,
2199 x, y, width, height,
2200 SIDE_ALL, junction);
2201 gdk_cairo_set_source_rgba (cr, bg_color);
2204 render_frame_internal (engine, cr,
2205 x, y, width, height,
2206 hidden_side, junction);
2211 gdk_rgba_free (bg_color);
2215 render_dot (cairo_t *cr,
2216 const GdkRGBA *lighter,
2217 const GdkRGBA *darker,
2222 size = CLAMP ((gint) size, 2, 3);
2226 gdk_cairo_set_source_rgba (cr, lighter);
2227 cairo_rectangle (cr, x, y, 1, 1);
2228 cairo_rectangle (cr, x + 1, y + 1, 1, 1);
2233 gdk_cairo_set_source_rgba (cr, lighter);
2234 cairo_rectangle (cr, x, y, 2, 1);
2235 cairo_rectangle (cr, x, y, 1, 2);
2238 gdk_cairo_set_source_rgba (cr, darker);
2239 cairo_rectangle (cr, x + 1, y + 1, 2, 1);
2240 cairo_rectangle (cr, x + 2, y, 1, 2);
2246 gtk_theming_engine_render_handle (GtkThemingEngine *engine,
2253 GtkStateFlags flags;
2255 GdkRGBA lighter, darker;
2259 flags = gtk_theming_engine_get_state (engine);
2261 cairo_set_line_width (cr, 1);
2263 gtk_theming_engine_get (engine, flags,
2264 "background-color", &bg_color,
2266 color_shade (bg_color, 0.7, &darker);
2267 color_shade (bg_color, 1.3, &lighter);
2269 gdk_cairo_set_source_rgba (cr, bg_color);
2270 cairo_rectangle (cr, x, y, width, height);
2273 if (gtk_theming_engine_has_class (engine, "grip"))
2275 GtkJunctionSides sides;
2280 cairo_set_line_width (cr, 1.0);
2281 sides = gtk_theming_engine_get_junction_sides (engine);
2283 /* reduce confusing values to a meaningful state */
2284 if ((sides & (GTK_JUNCTION_LEFT | GTK_JUNCTION_RIGHT)) == (GTK_JUNCTION_LEFT | GTK_JUNCTION_RIGHT))
2285 sides &= ~GTK_JUNCTION_LEFT;
2287 if ((sides & (GTK_JUNCTION_TOP | GTK_JUNCTION_BOTTOM)) == (GTK_JUNCTION_TOP | GTK_JUNCTION_BOTTOM))
2288 sides &= ~GTK_JUNCTION_TOP;
2291 sides = (GTK_JUNCTION_BOTTOM | GTK_JUNCTION_RIGHT);
2293 /* align drawing area to the connected side */
2294 if (sides == GTK_JUNCTION_LEFT)
2299 else if (sides == (GTK_JUNCTION_LEFT | GTK_JUNCTION_TOP))
2303 else if (height < width)
2308 else if (sides == (GTK_JUNCTION_LEFT | GTK_JUNCTION_BOTTOM))
2310 /* make it square, aligning to bottom left */
2313 y += (height - width);
2316 else if (height < width)
2321 else if (sides == GTK_JUNCTION_RIGHT)
2323 /* aligning to right */
2326 x += (width - height);
2330 else if (sides == (GTK_JUNCTION_RIGHT | GTK_JUNCTION_TOP))
2334 else if (height < width)
2336 x += (width - height);
2342 else if (sides == (GTK_JUNCTION_RIGHT | GTK_JUNCTION_BOTTOM))
2344 /* make it square, aligning to bottom right */
2347 y += (height - width);
2350 else if (height < width)
2352 x += (width - height);
2358 else if (sides == GTK_JUNCTION_TOP)
2363 else if (sides == GTK_JUNCTION_BOTTOM)
2365 /* align to bottom */
2368 y += (height - width);
2373 g_assert_not_reached ();
2375 if (sides == GTK_JUNCTION_LEFT ||
2376 sides == GTK_JUNCTION_RIGHT)
2382 while (xi < x + width)
2384 gdk_cairo_set_source_rgba (cr, &lighter);
2385 add_path_line (cr, x, y, x, y + height);
2389 gdk_cairo_set_source_rgba (cr, &darker);
2390 add_path_line (cr, xi, y, xi, y + height);
2395 else if (sides == GTK_JUNCTION_TOP ||
2396 sides == GTK_JUNCTION_BOTTOM)
2402 while (yi < y + height)
2404 gdk_cairo_set_source_rgba (cr, &lighter);
2405 add_path_line (cr, x, yi, x + width, yi);
2409 gdk_cairo_set_source_rgba (cr, &darker);
2410 add_path_line (cr, x, yi, x + width, yi);
2415 else if (sides == (GTK_JUNCTION_TOP | GTK_JUNCTION_LEFT))
2424 gdk_cairo_set_source_rgba (cr, &darker);
2425 add_path_line (cr, xi, y, x, yi);
2431 add_path_line (cr, xi, y, x, yi);
2437 gdk_cairo_set_source_rgba (cr, &lighter);
2438 add_path_line (cr, xi, y, x, yi);
2445 else if (sides == (GTK_JUNCTION_TOP | GTK_JUNCTION_RIGHT))
2452 while (xi < (x + width - 3))
2454 gdk_cairo_set_source_rgba (cr, &lighter);
2455 add_path_line (cr, xi, y, x + width, yi);
2461 gdk_cairo_set_source_rgba (cr, &darker);
2462 add_path_line (cr, xi, y, x + width, yi);
2468 add_path_line (cr, xi, y, x + width, yi);
2475 else if (sides == (GTK_JUNCTION_BOTTOM | GTK_JUNCTION_LEFT))
2484 gdk_cairo_set_source_rgba (cr, &darker);
2485 add_path_line (cr, x, yi, xi, y + height);
2491 add_path_line (cr, x, yi, xi, y + height);
2497 gdk_cairo_set_source_rgba (cr, &lighter);
2498 add_path_line (cr, x, yi, xi, y + height);
2505 else if (sides == (GTK_JUNCTION_BOTTOM | GTK_JUNCTION_RIGHT))
2512 while (xi < (x + width - 3))
2514 gdk_cairo_set_source_rgba (cr, &lighter);
2515 add_path_line (cr, xi, y + height, x + width, yi);
2521 gdk_cairo_set_source_rgba (cr, &darker);
2522 add_path_line (cr, xi, y + height, x + width, yi);
2528 add_path_line (cr, xi, y + height, x + width, yi);
2538 else if (gtk_theming_engine_has_class (engine, "paned"))
2541 for (xx = x + width / 2 - 15; xx <= x + width / 2 + 15; xx += 5)
2542 render_dot (cr, &lighter, &darker, xx, y + height / 2 - 1, 3);
2544 for (yy = y + height / 2 - 15; yy <= y + height / 2 + 15; yy += 5)
2545 render_dot (cr, &lighter, &darker, x + width / 2 - 1, yy, 3);
2549 for (yy = y; yy < y + height; yy += 3)
2550 for (xx = x; xx < x + width; xx += 6)
2552 render_dot (cr, &lighter, &darker, xx, yy, 2);
2553 render_dot (cr, &lighter, &darker, xx + 3, yy + 1, 2);
2559 gdk_rgba_free (bg_color);
2563 gtk_theming_engine_render_activity (GtkThemingEngine *engine,
2570 if (gtk_theming_engine_has_class (engine, "spinner"))
2572 GtkStateFlags state;
2573 guint num_steps, step;
2581 gtk_theming_engine_get_style (engine,
2582 "num-steps", &num_steps,
2585 state = gtk_theming_engine_get_state (engine);
2586 gtk_theming_engine_get (engine, state,
2592 if (gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress))
2593 step = (guint) (progress * num_steps);
2599 cairo_translate (cr, x, y);
2601 /* draw clip region */
2602 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
2606 radius = MIN (width / 2, height / 2);
2607 half = num_steps / 2;
2609 for (i = 0; i < num_steps; i++)
2611 gint inset = 0.7 * radius;
2613 /* transparency is a function of time and intial value */
2614 gdouble t = (gdouble) ((i + num_steps - step)
2615 % num_steps) / num_steps;
2619 cairo_set_source_rgba (cr,
2625 cairo_set_line_width (cr, 2.0);
2627 dx + (radius - inset) * cos (i * G_PI / half),
2628 dy + (radius - inset) * sin (i * G_PI / half));
2630 dx + radius * cos (i * G_PI / half),
2631 dy + radius * sin (i * G_PI / half));
2639 gdk_rgba_free (color);
2643 gtk_theming_engine_render_background (engine, cr, x, y, width, height);
2644 gtk_theming_engine_render_frame (engine, cr, x, y, width, height);
2649 scale_or_ref (GdkPixbuf *src,
2653 if (width == gdk_pixbuf_get_width (src) &&
2654 height == gdk_pixbuf_get_height (src))
2655 return g_object_ref (src);
2657 return gdk_pixbuf_scale_simple (src,
2659 GDK_INTERP_BILINEAR);
2663 lookup_icon_size (GtkThemingEngine *engine,
2669 GtkSettings *settings;
2671 screen = gtk_theming_engine_get_screen (engine);
2672 settings = gtk_settings_get_for_screen (screen);
2674 return gtk_icon_size_lookup_for_settings (settings, size, width, height);
2678 gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine *engine,
2679 const GtkIconSource *source,
2684 GdkPixbuf *base_pixbuf;
2685 GtkStateFlags state;
2689 base_pixbuf = gtk_icon_source_get_pixbuf (source);
2690 state = gtk_theming_engine_get_state (engine);
2692 g_return_val_if_fail (base_pixbuf != NULL, NULL);
2694 if (size != (GtkIconSize) -1 &&
2695 !lookup_icon_size (engine, size, &width, &height))
2697 g_warning (G_STRLOC ": invalid icon size '%d'", size);
2701 /* If the size was wildcarded, and we're allowed to scale, then scale; otherwise,
2704 if (size != (GtkIconSize) -1 &&
2705 gtk_icon_source_get_size_wildcarded (source))
2706 scaled = scale_or_ref (base_pixbuf, width, height);
2708 scaled = g_object_ref (base_pixbuf);
2710 /* If the state was wildcarded, then generate a state. */
2711 if (gtk_icon_source_get_state_wildcarded (source))
2713 if (state & GTK_STATE_FLAG_INSENSITIVE)
2715 stated = gdk_pixbuf_copy (scaled);
2716 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
2718 g_object_unref (scaled);
2720 else if (state & GTK_STATE_FLAG_PRELIGHT)
2722 stated = gdk_pixbuf_copy (scaled);
2723 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
2725 g_object_unref (scaled);