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, *border_color;
878 gint exterior_size, interior_size, thickness, pad;
879 GtkBorderStyle border_style;
882 flags = gtk_theming_engine_get_state (engine);
885 gtk_theming_engine_get (engine, flags,
887 "background-color", &bg_color,
888 "border-color", &border_color,
889 "border-style", &border_style,
890 "border-width", &border_width,
893 exterior_size = MIN (width, height);
895 if (exterior_size % 2 == 0) /* Ensure odd */
898 /* FIXME: thickness */
900 pad = thickness + MAX (1, (exterior_size - 2 * thickness) / 9);
901 interior_size = MAX (1, exterior_size - 2 * pad);
903 if (interior_size < 7)
906 pad = MAX (0, (exterior_size - interior_size) / 2);
909 x -= (1 + exterior_size - (gint) width) / 2;
910 y -= (1 + exterior_size - (gint) height) / 2;
912 if (border_style == GTK_BORDER_STYLE_SOLID)
914 cairo_set_line_width (cr, border_width);
916 cairo_rectangle (cr, x + 0.5, y + 0.5, exterior_size - 1, exterior_size - 1);
917 gdk_cairo_set_source_rgba (cr, bg_color);
918 cairo_fill_preserve (cr);
921 gdk_cairo_set_source_rgba (cr, border_color);
923 gdk_cairo_set_source_rgba (cr, fg_color);
928 gdk_cairo_set_source_rgba (cr, fg_color);
930 if (flags & GTK_STATE_FLAG_INCONSISTENT)
932 int line_thickness = MAX (1, (3 + interior_size * 2) / 7);
936 y + pad + (1 + interior_size - line_thickness) / 2,
946 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress);
948 if ((flags & GTK_STATE_FLAG_ACTIVE) || running)
956 cairo_scale (cr, interior_size / 7., interior_size / 7.);
958 cairo_rectangle (cr, 0, 0, 7 * progress, 7);
961 cairo_move_to (cr, 7.0, 0.0);
962 cairo_line_to (cr, 7.5, 1.0);
963 cairo_curve_to (cr, 5.3, 2.0,
966 cairo_curve_to (cr, 3.0, 5.7,
969 cairo_line_to (cr, 0.2, 3.5);
970 cairo_curve_to (cr, 1.1, 3.5,
973 cairo_curve_to (cr, 1.0, 3.9,
976 cairo_curve_to (cr, 3.5, 3.1,
986 gdk_rgba_free (fg_color);
987 gdk_rgba_free (bg_color);
988 gdk_rgba_free (border_color);
992 gtk_theming_engine_render_option (GtkThemingEngine *engine,
1000 GdkRGBA *fg_color, *bg_color, *border_color;
1001 gint exterior_size, interior_size, pad, thickness, border_width;
1002 GtkBorderStyle border_style;
1005 flags = gtk_theming_engine_get_state (engine);
1006 radius = MIN (width, height) / 2 - 0.5;
1010 gtk_theming_engine_get (engine, flags,
1012 "background-color", &bg_color,
1013 "border-color", &border_color,
1014 "border-style", &border_style,
1015 "border-width", &border_width,
1018 exterior_size = MIN (width, height);
1020 if (exterior_size % 2 == 0) /* Ensure odd */
1023 x -= (1 + exterior_size - width) / 2;
1024 y -= (1 + exterior_size - height) / 2;
1026 if (border_style == GTK_BORDER_STYLE_SOLID)
1028 cairo_set_line_width (cr, border_width);
1030 x + exterior_size / 2.,
1031 y + exterior_size / 2.,
1032 (exterior_size - 1) / 2.,
1035 gdk_cairo_set_source_rgba (cr, bg_color);
1036 cairo_fill_preserve (cr);
1039 gdk_cairo_set_source_rgba (cr, border_color);
1041 gdk_cairo_set_source_rgba (cr, fg_color);
1046 gdk_cairo_set_source_rgba (cr, fg_color);
1048 /* FIXME: thickness */
1051 if (flags & GTK_STATE_FLAG_INCONSISTENT)
1053 gint line_thickness;
1055 pad = thickness + MAX (1, (exterior_size - 2 * thickness) / 9);
1056 interior_size = MAX (1, exterior_size - 2 * pad);
1058 if (interior_size < 7)
1061 pad = MAX (0, (exterior_size - interior_size) / 2);
1064 line_thickness = MAX (1, (3 + interior_size * 2) / 7);
1066 cairo_rectangle (cr,
1068 y + pad + (interior_size - line_thickness) / 2.,
1073 if (flags & GTK_STATE_FLAG_ACTIVE)
1075 pad = thickness + MAX (1, 2 * (exterior_size - 2 * thickness) / 9);
1076 interior_size = MAX (1, exterior_size - 2 * pad);
1078 if (interior_size < 5)
1081 pad = MAX (0, (exterior_size - interior_size) / 2);
1085 x + pad + interior_size / 2.,
1086 y + pad + interior_size / 2.,
1094 gdk_rgba_free (fg_color);
1095 gdk_rgba_free (bg_color);
1096 gdk_rgba_free (border_color);
1100 add_path_arrow (cairo_t *cr,
1108 cairo_translate (cr, x + (size / 2), y + (size / 2));
1109 cairo_rotate (cr, angle);
1111 cairo_move_to (cr, 0, - (size / 4));
1112 cairo_line_to (cr, - (size / 2), (size / 4));
1113 cairo_line_to (cr, (size / 2), (size / 4));
1114 cairo_close_path (cr);
1120 gtk_theming_engine_render_arrow (GtkThemingEngine *engine,
1127 GtkStateFlags flags;
1132 flags = gtk_theming_engine_get_state (engine);
1134 gtk_theming_engine_get (engine, flags,
1138 if (flags & GTK_STATE_FLAG_INSENSITIVE)
1140 add_path_arrow (cr, angle, x + 1, y + 1, size);
1141 cairo_set_source_rgb (cr, 1, 1, 1);
1145 add_path_arrow (cr, angle, x, y, size);
1146 gdk_cairo_set_source_rgba (cr, fg_color);
1151 gdk_rgba_free (fg_color);
1155 add_path_line (cairo_t *cr,
1161 /* Adjust endpoints */
1175 cairo_move_to (cr, x1, y1);
1176 cairo_line_to (cr, x2, y2);
1180 color_shade (const GdkRGBA *color,
1182 GdkRGBA *color_return)
1184 GtkSymbolicColor *literal, *shade;
1186 literal = gtk_symbolic_color_new_literal (color);
1187 shade = gtk_symbolic_color_new_shade (literal, factor);
1188 gtk_symbolic_color_unref (literal);
1190 gtk_symbolic_color_resolve (shade, NULL, color_return);
1191 gtk_symbolic_color_unref (shade);
1195 _cairo_round_rectangle_sides (cairo_t *cr,
1202 GtkJunctionSides junction)
1204 radius = CLAMP (radius, 0, MIN (width / 2, height / 2));
1206 if (sides & SIDE_RIGHT)
1209 (junction & GTK_JUNCTION_CORNER_TOPRIGHT))
1210 cairo_move_to (cr, x + width, y);
1213 cairo_new_sub_path (cr);
1214 cairo_arc (cr, x + width - radius, y + radius, radius, - G_PI / 4, 0);
1218 (junction & GTK_JUNCTION_CORNER_BOTTOMRIGHT))
1219 cairo_line_to (cr, x + width, y + height);
1221 cairo_arc (cr, x + width - radius, y + height - radius, radius, 0, G_PI / 4);
1224 if (sides & SIDE_BOTTOM)
1227 ! (junction & GTK_JUNCTION_CORNER_BOTTOMRIGHT))
1229 if ((sides & SIDE_RIGHT) == 0)
1230 cairo_new_sub_path (cr);
1232 cairo_arc (cr, x + width - radius, y + height - radius, radius, G_PI / 4, G_PI / 2);
1234 else if ((sides & SIDE_RIGHT) == 0)
1235 cairo_move_to (cr, x + width, y + height);
1238 (junction & GTK_JUNCTION_CORNER_BOTTOMLEFT))
1239 cairo_line_to (cr, x, y + height);
1241 cairo_arc (cr, x + radius, y + height - radius, radius, G_PI / 2, 3 * (G_PI / 4));
1244 cairo_move_to (cr, x, y + height);
1246 if (sides & SIDE_LEFT)
1249 ! (junction & GTK_JUNCTION_CORNER_BOTTOMLEFT))
1251 if ((sides & SIDE_BOTTOM) == 0)
1252 cairo_new_sub_path (cr);
1254 cairo_arc (cr, x + radius, y + height - radius, radius, 3 * (G_PI / 4), G_PI);
1256 else if ((sides & SIDE_BOTTOM) == 0)
1257 cairo_move_to (cr, x, y + height);
1260 (junction & GTK_JUNCTION_CORNER_TOPLEFT))
1261 cairo_line_to (cr, x, y);
1263 cairo_arc (cr, x + radius, y + radius, radius, G_PI, G_PI + G_PI / 4);
1266 if (sides & SIDE_TOP)
1269 ! (junction & GTK_JUNCTION_CORNER_TOPLEFT))
1271 if ((sides & SIDE_LEFT) == 0)
1272 cairo_new_sub_path (cr);
1274 cairo_arc (cr, x + radius, y + radius, radius, 5 * (G_PI / 4), 3 * (G_PI / 2));
1276 else if ((sides & SIDE_LEFT) == 0)
1277 cairo_move_to (cr, x, y);
1280 (junction & GTK_JUNCTION_CORNER_TOPRIGHT))
1281 cairo_line_to (cr, x + width, y);
1283 cairo_arc (cr, x + width - radius, y + radius, radius, 3 * (G_PI / 2), - G_PI / 4);
1288 gtk_theming_engine_render_background (GtkThemingEngine *engine,
1296 cairo_pattern_t *pattern;
1297 GtkStateFlags flags;
1299 gdouble progress, alpha = 1;
1300 GtkJunctionSides junction;
1301 gint radius, border_width;
1303 flags = gtk_theming_engine_get_state (engine);
1304 junction = gtk_theming_engine_get_junction_sides (engine);
1307 if (gtk_theming_engine_has_class (engine, "spinbutton") &&
1308 gtk_theming_engine_has_class (engine, "button"))
1316 gtk_theming_engine_get (engine, flags,
1317 "background-image", &pattern,
1318 "background-color", &bg_color,
1319 "border-width", &border_width,
1320 "border-radius", &radius,
1323 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
1325 if (border_width > 0)
1329 width -= 2 * border_width;
1330 height -= 2 * border_width;
1331 radius -= 2 * border_width;
1337 _cairo_round_rectangle_sides (cr, (gdouble) radius,
1338 x, y, width, height,
1339 SIDE_ALL, junction);
1342 if (gtk_theming_engine_has_class (engine, "background"))
1344 cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0); /* transparent */
1345 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
1349 cairo_translate (cr, x, y);
1350 cairo_scale (cr, width, height);
1354 cairo_pattern_t *other_pattern;
1355 GtkStateFlags other_flags;
1357 cairo_pattern_t *new_pattern = NULL;
1359 if (flags & GTK_STATE_FLAG_PRELIGHT)
1361 other_flags = flags & ~(GTK_STATE_FLAG_PRELIGHT);
1362 progress = 1 - progress;
1365 other_flags = flags | GTK_STATE_FLAG_PRELIGHT;
1367 gtk_theming_engine_get (engine, other_flags,
1368 "background-image", &other_pattern,
1369 "background-color", &other_bg,
1372 if (pattern && other_pattern)
1374 cairo_pattern_type_t type, other_type;
1377 cairo_pattern_get_color_stop_count (pattern, &n0);
1378 cairo_pattern_get_color_stop_count (other_pattern, &n1);
1379 type = cairo_pattern_get_type (pattern);
1380 other_type = cairo_pattern_get_type (other_pattern);
1382 if (type == other_type && n0 == n1)
1384 gdouble offset0, red0, green0, blue0, alpha0;
1385 gdouble offset1, red1, green1, blue1, alpha1;
1386 gdouble x00, x01, y00, y01, x10, x11, y10, y11;
1387 gdouble r00, r01, r10, r11;
1390 if (type == CAIRO_PATTERN_TYPE_LINEAR)
1392 cairo_pattern_get_linear_points (pattern, &x00, &y00, &x01, &y01);
1393 cairo_pattern_get_linear_points (other_pattern, &x10, &y10, &x11, &y11);
1395 new_pattern = cairo_pattern_create_linear (x00 + (x10 - x00) * progress,
1396 y00 + (y10 - y00) * progress,
1397 x01 + (x11 - x01) * progress,
1398 y01 + (y11 - y01) * progress);
1402 cairo_pattern_get_radial_circles (pattern, &x00, &y00, &r00, &x01, &y01, &r01);
1403 cairo_pattern_get_radial_circles (other_pattern, &x10, &y10, &r10, &x11, &y11, &r11);
1405 new_pattern = cairo_pattern_create_radial (x00 + (x10 - x00) * progress,
1406 y00 + (y10 - y00) * progress,
1407 r00 + (r10 - r00) * progress,
1408 x01 + (x11 - x01) * progress,
1409 y01 + (y11 - y01) * progress,
1410 r01 + (r11 - r01) * progress);
1413 cairo_pattern_set_filter (new_pattern, CAIRO_FILTER_FAST);
1416 /* Blend both gradients into one */
1417 while (i < n0 && i < n1)
1419 cairo_pattern_get_color_stop_rgba (pattern, i,
1421 &red0, &green0, &blue0,
1423 cairo_pattern_get_color_stop_rgba (other_pattern, i,
1425 &red1, &green1, &blue1,
1428 cairo_pattern_add_color_stop_rgba (new_pattern,
1429 offset0 + ((offset1 - offset0) * progress),
1430 red0 + ((red1 - red0) * progress),
1431 green0 + ((green1 - green0) * progress),
1432 blue0 + ((blue1 - blue0) * progress),
1433 alpha0 + ((alpha1 - alpha0) * progress));
1439 /* Different pattern types, or different color
1440 * stop counts, alpha blend both patterns.
1442 cairo_rectangle (cr, 0, 0, 1, 1);
1443 cairo_set_source (cr, other_pattern);
1444 cairo_fill_preserve (cr);
1446 /* Set alpha for posterior drawing
1447 * of the target pattern
1449 alpha = 1 - progress;
1452 else if (pattern || other_pattern)
1456 gdouble x0, y0, x1, y1, r0, r1;
1459 /* Blend a pattern with a color */
1464 progress = 1 - progress;
1472 if (cairo_pattern_get_type (p) == CAIRO_PATTERN_TYPE_LINEAR)
1474 cairo_pattern_get_linear_points (p, &x0, &y0, &x1, &y1);
1475 new_pattern = cairo_pattern_create_linear (x0, y0, x1, y1);
1479 cairo_pattern_get_radial_circles (p, &x0, &y0, &r0, &x1, &y1, &r1);
1480 new_pattern = cairo_pattern_create_radial (x0, y0, r0, x1, y1, r1);
1483 cairo_pattern_get_color_stop_count (p, &n);
1485 for (i = 0; i < n; i++)
1487 gdouble red1, green1, blue1, alpha1;
1490 cairo_pattern_get_color_stop_rgba (p, i,
1492 &red1, &green1, &blue1,
1494 cairo_pattern_add_color_stop_rgba (new_pattern, offset,
1495 c->red + ((red1 - c->red) * progress),
1496 c->green + ((green1 - c->green) * progress),
1497 c->blue + ((blue1 - c->blue) * progress),
1498 c->alpha + ((alpha1 - c->alpha) * progress));
1503 const GdkRGBA *color, *other_color;
1505 /* Merge just colors */
1507 other_color = other_bg;
1509 new_pattern = cairo_pattern_create_rgba (CLAMP (color->red + ((other_color->red - color->red) * progress), 0, 1),
1510 CLAMP (color->green + ((other_color->green - color->green) * progress), 0, 1),
1511 CLAMP (color->blue + ((other_color->blue - color->blue) * progress), 0, 1),
1512 CLAMP (color->alpha + ((other_color->alpha - color->alpha) * progress), 0, 1));
1517 /* Replace pattern to use */
1518 cairo_pattern_destroy (pattern);
1519 pattern = new_pattern;
1523 cairo_pattern_destroy (other_pattern);
1526 gdk_rgba_free (other_bg);
1529 cairo_rectangle (cr, 0, 0, 1, 1);
1533 cairo_set_source (cr, pattern);
1534 cairo_pattern_destroy (pattern);
1537 gdk_cairo_set_source_rgba (cr, bg_color);
1543 cairo_pattern_t *mask;
1545 mask = cairo_pattern_create_rgba (1, 1, 1, alpha);
1546 cairo_mask (cr, mask);
1547 cairo_pattern_destroy (mask);
1552 gdk_rgba_free (bg_color);
1556 render_frame_internal (GtkThemingEngine *engine,
1563 GtkJunctionSides junction)
1565 GtkStateFlags state;
1567 GdkRGBA *border_color;
1568 GtkBorderStyle border_style;
1569 gint border_width, radius;
1572 state = gtk_theming_engine_get_state (engine);
1573 gtk_theming_engine_get (engine, state,
1574 "border-color", &border_color,
1575 "border-style", &border_style,
1576 "border-width", &border_width,
1577 "border-radius", &radius,
1582 color_shade (border_color, 1.8, &lighter);
1584 switch (border_style)
1586 case GTK_BORDER_STYLE_NONE:
1588 case GTK_BORDER_STYLE_SOLID:
1589 cairo_set_line_width (cr, border_width);
1590 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
1592 if (border_width > 1)
1594 x += (gdouble) border_width / 2;
1595 y += (gdouble) border_width / 2;
1596 width -= border_width;
1597 height -= border_width;
1599 else if (border_width == 1)
1607 _cairo_round_rectangle_sides (cr, (gdouble) radius,
1608 x, y, width, height,
1609 SIDE_ALL & ~(hidden_side),
1611 gdk_cairo_set_source_rgba (cr, border_color);
1615 case GTK_BORDER_STYLE_INSET:
1616 case GTK_BORDER_STYLE_OUTSET:
1617 cairo_set_line_width (cr, border_width);
1618 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
1620 if (border_width > 1)
1622 d1 = (gdouble) border_width / 2;
1633 m = MIN (width, height);
1636 /* Only needed for square frames to have a 3D-like
1637 * feeling, for rounded ones, the arc will ensure
1638 * the stroke is painted to end at 45°.
1642 cairo_move_to (cr, x, y + height);
1643 cairo_line_to (cr, x + m, y + height - m);
1644 cairo_line_to (cr, x + width - m, y + m);
1645 cairo_line_to (cr, x + width, y);
1646 cairo_line_to (cr, x + width, y + height);
1647 cairo_close_path (cr);
1652 if (border_style == GTK_BORDER_STYLE_INSET)
1653 gdk_cairo_set_source_rgba (cr, &lighter);
1655 gdk_cairo_set_source_rgba (cr, border_color);
1657 _cairo_round_rectangle_sides (cr, (gdouble) radius,
1659 width - d2, height - d2,
1660 (SIDE_BOTTOM | SIDE_RIGHT) & ~(hidden_side),
1670 cairo_move_to (cr, x, y + height);
1671 cairo_line_to (cr, x + m, y + height - m);
1672 cairo_line_to (cr, x + width - m, y + m);
1673 cairo_line_to (cr, x + width, y);
1674 cairo_line_to (cr, x, y);
1675 cairo_close_path (cr);
1680 if (border_style == GTK_BORDER_STYLE_INSET)
1681 gdk_cairo_set_source_rgba (cr, border_color);
1683 gdk_cairo_set_source_rgba (cr, &lighter);
1685 _cairo_round_rectangle_sides (cr, (gdouble) radius,
1687 width - d2, height - d2,
1688 (SIDE_TOP | SIDE_LEFT) & ~(hidden_side),
1699 gdk_rgba_free (border_color);
1703 gtk_theming_engine_render_frame (GtkThemingEngine *engine,
1710 GtkStateFlags flags;
1712 GtkBorderStyle border_style;
1713 GtkJunctionSides junction;
1715 flags = gtk_theming_engine_get_state (engine);
1716 junction = gtk_theming_engine_get_junction_sides (engine);
1718 gtk_theming_engine_get (engine, flags,
1719 "border-image", &slice,
1720 "border-style", &border_style,
1725 gtk_9slice_render (slice, cr, x, y, width, height);
1726 gtk_9slice_unref (slice);
1728 else if (border_style != GTK_BORDER_STYLE_NONE)
1729 render_frame_internal (engine, cr,
1730 x, y, width, height,
1735 gtk_theming_engine_render_expander (GtkThemingEngine *engine,
1742 GtkStateFlags flags;
1743 GdkRGBA *outline_color, *fg_color;
1744 double vertical_overshoot;
1747 double interp; /* interpolation factor for center position */
1748 double x_double_horz, y_double_horz;
1749 double x_double_vert, y_double_vert;
1750 double x_double, y_double;
1755 flags = gtk_theming_engine_get_state (engine);
1757 gtk_theming_engine_get (engine, flags,
1760 gtk_theming_engine_get (engine, 0,
1761 "color", &outline_color,
1766 /* FIXME: LTR/RTL */
1767 if (flags & GTK_STATE_FLAG_ACTIVE)
1778 /* Compute distance that the stroke extends beyonds the end
1779 * of the triangle we draw.
1781 vertical_overshoot = line_width / 2.0 * (1. / tan (G_PI / 8));
1783 /* For odd line widths, we end the vertical line of the triangle
1784 * at a half pixel, so we round differently.
1786 if (line_width % 2 == 1)
1787 vertical_overshoot = ceil (0.5 + vertical_overshoot) - 0.5;
1789 vertical_overshoot = ceil (vertical_overshoot);
1791 /* Adjust the size of the triangle we draw so that the entire stroke fits
1793 diameter = (gint) MAX (3, width - 2 * vertical_overshoot);
1795 /* If the line width is odd, we want the diameter to be even,
1796 * and vice versa, so force the sum to be odd. This relationship
1797 * makes the point of the triangle look right.
1799 diameter -= (1 - (diameter + line_width) % 2);
1801 radius = diameter / 2.;
1803 /* Adjust the center so that the stroke is properly aligned with
1804 * the pixel grid. The center adjustment is different for the
1805 * horizontal and vertical orientations. For intermediate positions
1806 * we interpolate between the two.
1808 x_double_vert = floor ((x + width / 2) - (radius + line_width) / 2.) + (radius + line_width) / 2.;
1809 y_double_vert = (y + height / 2) - 0.5;
1811 x_double_horz = (x + width / 2) - 0.5;
1812 y_double_horz = floor ((y + height / 2) - (radius + line_width) / 2.) + (radius + line_width) / 2.;
1814 x_double = x_double_vert * (1 - interp) + x_double_horz * interp;
1815 y_double = y_double_vert * (1 - interp) + y_double_horz * interp;
1817 cairo_translate (cr, x_double, y_double);
1818 cairo_rotate (cr, angle);
1820 cairo_move_to (cr, - radius / 2., - radius);
1821 cairo_line_to (cr, radius / 2., 0);
1822 cairo_line_to (cr, - radius / 2., radius);
1823 cairo_close_path (cr);
1825 cairo_set_line_width (cr, line_width);
1827 gdk_cairo_set_source_rgba (cr, fg_color);
1829 cairo_fill_preserve (cr);
1831 gdk_cairo_set_source_rgba (cr, outline_color);
1836 gdk_rgba_free (fg_color);
1837 gdk_rgba_free (outline_color);
1841 gtk_theming_engine_render_focus (GtkThemingEngine *engine,
1848 GtkStateFlags flags;
1854 flags = gtk_theming_engine_get_state (engine);
1856 gtk_theming_engine_get (engine, flags,
1860 gtk_theming_engine_get_style (engine,
1861 "focus-line-width", &line_width,
1862 "focus-line-pattern", (gchar *) &dash_list,
1865 cairo_set_line_width (cr, (gdouble) line_width);
1869 gint n_dashes = strlen ((const gchar *) dash_list);
1870 gdouble *dashes = g_new (gdouble, n_dashes);
1871 gdouble total_length = 0;
1872 gdouble dash_offset;
1875 for (i = 0; i < n_dashes; i++)
1877 dashes[i] = dash_list[i];
1878 total_length += dash_list[i];
1881 /* The dash offset here aligns the pattern to integer pixels
1882 * by starting the dash at the right side of the left border
1883 * Negative dash offsets in cairo don't work
1884 * (https://bugs.freedesktop.org/show_bug.cgi?id=2729)
1886 dash_offset = - line_width / 2.;
1888 while (dash_offset < 0)
1889 dash_offset += total_length;
1891 cairo_set_dash (cr, dashes, n_dashes, dash_offset);
1895 cairo_rectangle (cr,
1896 x + line_width / 2.,
1897 y + line_width / 2.,
1899 height - line_width);
1901 gdk_cairo_set_source_rgba (cr, color);
1906 gdk_rgba_free (color);
1911 gtk_theming_engine_render_line (GtkThemingEngine *engine,
1918 GdkRGBA *bg_color, darker, lighter;
1919 GtkStateFlags flags;
1920 gint i, thickness, thickness_dark, thickness_light, len;
1921 cairo_matrix_t matrix;
1924 /* FIXME: thickness */
1926 thickness_dark = thickness / 2;
1927 thickness_light = thickness - thickness_dark;
1929 flags = gtk_theming_engine_get_state (engine);
1932 gtk_theming_engine_get (engine, flags,
1933 "background-color", &bg_color,
1935 color_shade (bg_color, 0.7, &darker);
1936 color_shade (bg_color, 1.3, &lighter);
1938 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
1939 cairo_set_line_width (cr, 1);
1941 angle = atan2 (x1 - x0, y1 - y0);
1942 angle = (2 * G_PI) - angle;
1945 cairo_get_matrix (cr, &matrix);
1946 cairo_matrix_translate (&matrix, x0, y0);
1947 cairo_matrix_rotate (&matrix, angle);
1948 cairo_set_matrix (cr, &matrix);
1953 len = (gint) sqrt ((x1 * x1) + (y1 * y1));
1955 y0 = -thickness_dark;
1957 for (i = 0; i < thickness_dark; i++)
1959 gdk_cairo_set_source_rgba (cr, &lighter);
1960 add_path_line (cr, len - i - 1.5, y0, len - 0.5, y0);
1963 gdk_cairo_set_source_rgba (cr, &darker);
1964 add_path_line (cr, 0.5, y0, len - i - 1.5, y0);
1970 for (i = 0; i < thickness_light; i++)
1972 gdk_cairo_set_source_rgba (cr, &darker);
1973 add_path_line (cr, 0.5, y0, thickness_light - i + 0.5, y0);
1976 gdk_cairo_set_source_rgba (cr, &lighter);
1977 add_path_line (cr, thickness_light - i + 0.5, y0, len - 0.5, y0);
1985 gdk_rgba_free (bg_color);
1989 gtk_theming_engine_render_layout (GtkThemingEngine *engine,
1993 PangoLayout *layout)
1995 const PangoMatrix *matrix;
1997 GtkStateFlags flags;
2001 flags = gtk_theming_engine_get_state (engine);
2003 gtk_theming_engine_get (engine, flags,
2007 screen = gtk_theming_engine_get_screen (engine);
2008 matrix = pango_context_get_matrix (pango_layout_get_context (layout));
2012 cairo_matrix_t cairo_matrix;
2013 PangoMatrix tmp_matrix;
2014 PangoRectangle rect;
2016 cairo_matrix_init (&cairo_matrix,
2017 matrix->xx, matrix->yx,
2018 matrix->xy, matrix->yy,
2019 matrix->x0, matrix->y0);
2021 pango_layout_get_extents (layout, NULL, &rect);
2022 pango_matrix_transform_rectangle (matrix, &rect);
2023 pango_extents_to_pixels (&rect, NULL);
2025 tmp_matrix = *matrix;
2026 cairo_matrix.x0 += x - rect.x;
2027 cairo_matrix.y0 += y - rect.y;
2029 cairo_set_matrix (cr, &cairo_matrix);
2032 cairo_translate (cr, x, y);
2034 if (flags & GTK_STATE_FLAG_INSENSITIVE)
2037 cairo_set_source_rgb (cr, 1, 1, 1);
2038 cairo_move_to (cr, 1, 1);
2039 _gtk_pango_fill_layout (cr, layout);
2043 gdk_cairo_set_source_rgba (cr, fg_color);
2044 pango_cairo_show_layout (cr, layout);
2048 gdk_rgba_free (fg_color);
2052 gtk_theming_engine_render_slider (GtkThemingEngine *engine,
2058 GtkOrientation orientation)
2060 const GtkWidgetPath *path;
2063 path = gtk_theming_engine_get_path (engine);
2065 gtk_theming_engine_render_background (engine, cr, x, y, width, height);
2066 gtk_theming_engine_render_frame (engine, cr, x, y, width, height);
2068 /* FIXME: thickness */
2071 if (gtk_widget_path_is_type (path, GTK_TYPE_SCALE))
2073 if (orientation == GTK_ORIENTATION_VERTICAL)
2074 gtk_theming_engine_render_line (engine, cr,
2076 y + (gint) height / 2,
2077 x + width - thickness - 1,
2078 y + (gint) height / 2);
2080 gtk_theming_engine_render_line (engine, cr,
2081 x + (gint) width / 2,
2083 x + (gint) width / 2,
2084 y + height - thickness - 1);
2089 gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
2095 GtkPositionType gap_side,
2099 GtkJunctionSides junction = 0;
2100 GtkStateFlags state;
2104 state = gtk_theming_engine_get_state (engine);
2105 gtk_theming_engine_get (engine, state,
2106 "border-width", &border_width,
2107 "background-color", &bg_color,
2115 junction = GTK_JUNCTION_TOP;
2117 case GTK_POS_BOTTOM:
2118 junction = GTK_JUNCTION_BOTTOM;
2121 junction = GTK_JUNCTION_LEFT;
2124 junction = GTK_JUNCTION_RIGHT;
2128 render_frame_internal (engine, cr,
2129 x, y, width, height,
2134 cairo_rectangle (cr,
2135 x + xy0_gap + border_width, y,
2136 xy1_gap - xy0_gap - 2 * border_width,
2139 case GTK_POS_BOTTOM:
2140 cairo_rectangle (cr,
2141 x + xy0_gap + border_width,
2142 y + height - border_width,
2143 xy1_gap - xy0_gap - 2 * border_width,
2147 cairo_rectangle (cr,
2148 x, y + xy0_gap + border_width, border_width,
2149 xy1_gap - xy0_gap - 2 * border_width);
2152 cairo_rectangle (cr,
2153 x + width - border_width,
2154 y + xy0_gap + border_width, border_width,
2155 xy1_gap - xy0_gap - 2 * border_width);
2159 gdk_cairo_set_source_rgba (cr, bg_color);
2165 gdk_rgba_free (bg_color);
2169 gtk_theming_engine_render_extension (GtkThemingEngine *engine,
2175 GtkPositionType gap_side)
2177 GtkJunctionSides junction = 0;
2178 GtkStateFlags state;
2179 guint hidden_side = 0;
2188 junction = GTK_JUNCTION_LEFT;
2189 hidden_side = SIDE_LEFT;
2192 junction = GTK_JUNCTION_RIGHT;
2193 hidden_side = SIDE_RIGHT;
2196 junction = GTK_JUNCTION_TOP;
2197 hidden_side = SIDE_TOP;
2199 case GTK_POS_BOTTOM:
2200 junction = GTK_JUNCTION_BOTTOM;
2201 hidden_side = SIDE_BOTTOM;
2205 state = gtk_theming_engine_get_state (engine);
2206 gtk_theming_engine_get (engine, state,
2207 "background-color", &bg_color,
2208 "border-radius", &radius,
2211 _cairo_round_rectangle_sides (cr, radius,
2212 x, y, width, height,
2213 SIDE_ALL, junction);
2214 gdk_cairo_set_source_rgba (cr, bg_color);
2217 render_frame_internal (engine, cr,
2218 x, y, width, height,
2219 hidden_side, junction);
2224 gdk_rgba_free (bg_color);
2228 render_dot (cairo_t *cr,
2229 const GdkRGBA *lighter,
2230 const GdkRGBA *darker,
2235 size = CLAMP ((gint) size, 2, 3);
2239 gdk_cairo_set_source_rgba (cr, lighter);
2240 cairo_rectangle (cr, x, y, 1, 1);
2241 cairo_rectangle (cr, x + 1, y + 1, 1, 1);
2246 gdk_cairo_set_source_rgba (cr, lighter);
2247 cairo_rectangle (cr, x, y, 2, 1);
2248 cairo_rectangle (cr, x, y, 1, 2);
2251 gdk_cairo_set_source_rgba (cr, darker);
2252 cairo_rectangle (cr, x + 1, y + 1, 2, 1);
2253 cairo_rectangle (cr, x + 2, y, 1, 2);
2259 gtk_theming_engine_render_handle (GtkThemingEngine *engine,
2266 GtkStateFlags flags;
2268 GdkRGBA lighter, darker;
2272 flags = gtk_theming_engine_get_state (engine);
2274 cairo_set_line_width (cr, 1);
2276 gtk_theming_engine_get (engine, flags,
2277 "background-color", &bg_color,
2279 color_shade (bg_color, 0.7, &darker);
2280 color_shade (bg_color, 1.3, &lighter);
2282 gdk_cairo_set_source_rgba (cr, bg_color);
2283 cairo_rectangle (cr, x, y, width, height);
2286 if (gtk_theming_engine_has_class (engine, "grip"))
2288 GtkJunctionSides sides;
2293 cairo_set_line_width (cr, 1.0);
2294 sides = gtk_theming_engine_get_junction_sides (engine);
2296 /* reduce confusing values to a meaningful state */
2297 if ((sides & (GTK_JUNCTION_CORNER_TOPLEFT | GTK_JUNCTION_CORNER_BOTTOMRIGHT)) == (GTK_JUNCTION_CORNER_TOPLEFT | GTK_JUNCTION_CORNER_BOTTOMRIGHT))
2298 sides &= ~GTK_JUNCTION_CORNER_TOPLEFT;
2300 if ((sides & (GTK_JUNCTION_CORNER_TOPRIGHT | GTK_JUNCTION_CORNER_BOTTOMLEFT)) == (GTK_JUNCTION_CORNER_TOPRIGHT | GTK_JUNCTION_CORNER_BOTTOMLEFT))
2301 sides &= ~GTK_JUNCTION_CORNER_TOPRIGHT;
2304 sides = GTK_JUNCTION_CORNER_BOTTOMRIGHT;
2306 /* align drawing area to the connected side */
2307 if (sides == GTK_JUNCTION_LEFT)
2312 else if (sides == GTK_JUNCTION_CORNER_TOPLEFT)
2316 else if (height < width)
2321 else if (sides == GTK_JUNCTION_CORNER_BOTTOMLEFT)
2323 /* make it square, aligning to bottom left */
2326 y += (height - width);
2329 else if (height < width)
2334 else if (sides == GTK_JUNCTION_RIGHT)
2336 /* aligning to right */
2339 x += (width - height);
2343 else if (sides == GTK_JUNCTION_CORNER_TOPRIGHT)
2347 else if (height < width)
2349 x += (width - height);
2355 else if (sides == GTK_JUNCTION_CORNER_BOTTOMRIGHT)
2357 /* make it square, aligning to bottom right */
2360 y += (height - width);
2363 else if (height < width)
2365 x += (width - height);
2371 else if (sides == GTK_JUNCTION_TOP)
2376 else if (sides == GTK_JUNCTION_BOTTOM)
2378 /* align to bottom */
2381 y += (height - width);
2386 g_assert_not_reached ();
2388 if (sides == GTK_JUNCTION_LEFT ||
2389 sides == GTK_JUNCTION_RIGHT)
2395 while (xi < x + width)
2397 gdk_cairo_set_source_rgba (cr, &lighter);
2398 add_path_line (cr, x, y, x, y + height);
2402 gdk_cairo_set_source_rgba (cr, &darker);
2403 add_path_line (cr, xi, y, xi, y + height);
2408 else if (sides == GTK_JUNCTION_TOP ||
2409 sides == GTK_JUNCTION_BOTTOM)
2415 while (yi < y + height)
2417 gdk_cairo_set_source_rgba (cr, &lighter);
2418 add_path_line (cr, x, yi, x + width, yi);
2422 gdk_cairo_set_source_rgba (cr, &darker);
2423 add_path_line (cr, x, yi, x + width, yi);
2428 else if (sides == GTK_JUNCTION_CORNER_TOPLEFT)
2437 gdk_cairo_set_source_rgba (cr, &darker);
2438 add_path_line (cr, xi, y, x, yi);
2444 add_path_line (cr, xi, y, x, yi);
2450 gdk_cairo_set_source_rgba (cr, &lighter);
2451 add_path_line (cr, xi, y, x, yi);
2458 else if (sides == GTK_JUNCTION_CORNER_TOPRIGHT)
2465 while (xi < (x + width - 3))
2467 gdk_cairo_set_source_rgba (cr, &lighter);
2468 add_path_line (cr, xi, y, x + width, yi);
2474 gdk_cairo_set_source_rgba (cr, &darker);
2475 add_path_line (cr, xi, y, x + width, yi);
2481 add_path_line (cr, xi, y, x + width, yi);
2488 else if (sides == GTK_JUNCTION_CORNER_BOTTOMLEFT)
2497 gdk_cairo_set_source_rgba (cr, &darker);
2498 add_path_line (cr, x, yi, xi, y + height);
2504 add_path_line (cr, x, yi, xi, y + height);
2510 gdk_cairo_set_source_rgba (cr, &lighter);
2511 add_path_line (cr, x, yi, xi, y + height);
2518 else if (sides == GTK_JUNCTION_CORNER_BOTTOMRIGHT)
2525 while (xi < (x + width - 3))
2527 gdk_cairo_set_source_rgba (cr, &lighter);
2528 add_path_line (cr, xi, y + height, x + width, yi);
2534 gdk_cairo_set_source_rgba (cr, &darker);
2535 add_path_line (cr, xi, y + height, x + width, yi);
2541 add_path_line (cr, xi, y + height, x + width, yi);
2551 else if (gtk_theming_engine_has_class (engine, "paned"))
2554 for (xx = x + width / 2 - 15; xx <= x + width / 2 + 15; xx += 5)
2555 render_dot (cr, &lighter, &darker, xx, y + height / 2 - 1, 3);
2557 for (yy = y + height / 2 - 15; yy <= y + height / 2 + 15; yy += 5)
2558 render_dot (cr, &lighter, &darker, x + width / 2 - 1, yy, 3);
2562 for (yy = y; yy < y + height; yy += 3)
2563 for (xx = x; xx < x + width; xx += 6)
2565 render_dot (cr, &lighter, &darker, xx, yy, 2);
2566 render_dot (cr, &lighter, &darker, xx + 3, yy + 1, 2);
2572 gdk_rgba_free (bg_color);
2576 gtk_theming_engine_render_activity (GtkThemingEngine *engine,
2583 if (gtk_theming_engine_has_class (engine, "spinner"))
2585 GtkStateFlags state;
2586 guint num_steps, step;
2594 gtk_theming_engine_get_style (engine,
2595 "num-steps", &num_steps,
2598 state = gtk_theming_engine_get_state (engine);
2599 gtk_theming_engine_get (engine, state,
2605 if (gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress))
2606 step = (guint) (progress * num_steps);
2612 cairo_translate (cr, x, y);
2614 /* draw clip region */
2615 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
2619 radius = MIN (width / 2, height / 2);
2620 half = num_steps / 2;
2622 for (i = 0; i < num_steps; i++)
2624 gint inset = 0.7 * radius;
2626 /* transparency is a function of time and intial value */
2627 gdouble t = (gdouble) ((i + num_steps - step)
2628 % num_steps) / num_steps;
2632 cairo_set_source_rgba (cr,
2638 cairo_set_line_width (cr, 2.0);
2640 dx + (radius - inset) * cos (i * G_PI / half),
2641 dy + (radius - inset) * sin (i * G_PI / half));
2643 dx + radius * cos (i * G_PI / half),
2644 dy + radius * sin (i * G_PI / half));
2652 gdk_rgba_free (color);
2656 gtk_theming_engine_render_background (engine, cr, x, y, width, height);
2657 gtk_theming_engine_render_frame (engine, cr, x, y, width, height);
2662 scale_or_ref (GdkPixbuf *src,
2666 if (width == gdk_pixbuf_get_width (src) &&
2667 height == gdk_pixbuf_get_height (src))
2668 return g_object_ref (src);
2670 return gdk_pixbuf_scale_simple (src,
2672 GDK_INTERP_BILINEAR);
2676 lookup_icon_size (GtkThemingEngine *engine,
2682 GtkSettings *settings;
2684 screen = gtk_theming_engine_get_screen (engine);
2685 settings = gtk_settings_get_for_screen (screen);
2687 return gtk_icon_size_lookup_for_settings (settings, size, width, height);
2691 gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine *engine,
2692 const GtkIconSource *source,
2697 GdkPixbuf *base_pixbuf;
2698 GtkStateFlags state;
2702 base_pixbuf = gtk_icon_source_get_pixbuf (source);
2703 state = gtk_theming_engine_get_state (engine);
2705 g_return_val_if_fail (base_pixbuf != NULL, NULL);
2707 if (size != (GtkIconSize) -1 &&
2708 !lookup_icon_size (engine, size, &width, &height))
2710 g_warning (G_STRLOC ": invalid icon size '%d'", size);
2714 /* If the size was wildcarded, and we're allowed to scale, then scale; otherwise,
2717 if (size != (GtkIconSize) -1 &&
2718 gtk_icon_source_get_size_wildcarded (source))
2719 scaled = scale_or_ref (base_pixbuf, width, height);
2721 scaled = g_object_ref (base_pixbuf);
2723 /* If the state was wildcarded, then generate a state. */
2724 if (gtk_icon_source_get_state_wildcarded (source))
2726 if (state & GTK_STATE_FLAG_INSENSITIVE)
2728 stated = gdk_pixbuf_copy (scaled);
2729 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
2731 g_object_unref (scaled);
2733 else if (state & GTK_STATE_FLAG_PRELIGHT)
2735 stated = gdk_pixbuf_copy (scaled);
2736 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
2738 g_object_unref (scaled);