1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2010 Carlos Garnacho <carlosg@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
25 #include <gtk/gtkthemingengine.h>
26 #include <gtk/gtkstylecontext.h>
27 #include <gtk/gtkintl.h>
29 #include "gtkprivate.h"
30 #include "gtkmodulesprivate.h"
31 #include "gtkborderimageprivate.h"
33 #include "gtkshadowprivate.h"
34 #include "gtkcsstypesprivate.h"
35 #include "gtkthemingengineprivate.h"
36 #include "gtkroundedboxprivate.h"
37 #include "gtkthemingbackgroundprivate.h"
40 * SECTION:gtkthemingengine
41 * @Short_description: Theming renderers
42 * @Title: GtkThemingEngine
43 * @See_also: #GtkStyleContext
45 * #GtkThemingEngine is the object used for rendering themed content
46 * in GTK+ widgets. Even though GTK+ has a default implementation,
47 * it can be overridden in CSS files by enforcing a #GtkThemingEngine
48 * object to be loaded as a module.
50 * In order to implement a theming engine, a #GtkThemingEngine subclass
51 * must be created, alongside the CSS file that will reference it, the
52 * theming engine would be created as an .so library, and installed in
53 * $(gtk-modules-dir)/theming-engines/.
55 * #GtkThemingEngine<!-- -->s have limited access to the object they are
56 * rendering, the #GtkThemingEngine API has read-only accessors to the
57 * style information contained in the rendered object's #GtkStyleContext.
73 struct GtkThemingEnginePrivate
75 GtkStyleContext *context;
79 #define GTK_THEMING_ENGINE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_THEMING_ENGINE, GtkThemingEnginePrivate))
81 static void gtk_theming_engine_finalize (GObject *object);
82 static void gtk_theming_engine_impl_set_property (GObject *object,
86 static void gtk_theming_engine_impl_get_property (GObject *object,
91 static void gtk_theming_engine_render_check (GtkThemingEngine *engine,
97 static void gtk_theming_engine_render_option (GtkThemingEngine *engine,
103 static void gtk_theming_engine_render_arrow (GtkThemingEngine *engine,
109 static void gtk_theming_engine_render_background (GtkThemingEngine *engine,
115 static void gtk_theming_engine_render_frame (GtkThemingEngine *engine,
121 static void gtk_theming_engine_render_expander (GtkThemingEngine *engine,
127 static void gtk_theming_engine_render_focus (GtkThemingEngine *engine,
133 static void gtk_theming_engine_render_layout (GtkThemingEngine *engine,
137 PangoLayout *layout);
138 static void gtk_theming_engine_render_line (GtkThemingEngine *engine,
144 static void gtk_theming_engine_render_slider (GtkThemingEngine *engine,
150 GtkOrientation orientation);
151 static void gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
157 GtkPositionType gap_side,
160 static void gtk_theming_engine_render_extension (GtkThemingEngine *engine,
166 GtkPositionType gap_side);
167 static void gtk_theming_engine_render_handle (GtkThemingEngine *engine,
173 static void gtk_theming_engine_render_activity (GtkThemingEngine *engine,
179 static GdkPixbuf * gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine *engine,
180 const GtkIconSource *source,
182 static void gtk_theming_engine_render_icon (GtkThemingEngine *engine,
188 G_DEFINE_TYPE (GtkThemingEngine, gtk_theming_engine, G_TYPE_OBJECT)
191 typedef struct GtkThemingModule GtkThemingModule;
192 typedef struct GtkThemingModuleClass GtkThemingModuleClass;
194 struct GtkThemingModule
196 GTypeModule parent_instance;
200 void (*init) (GTypeModule *module);
202 GtkThemingEngine * (*create_engine) (void);
205 struct GtkThemingModuleClass
207 GTypeModuleClass parent_class;
210 #define GTK_TYPE_THEMING_MODULE (gtk_theming_module_get_type ())
211 #define GTK_THEMING_MODULE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_THEMING_MODULE, GtkThemingModule))
212 #define GTK_IS_THEMING_MODULE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_THEMING_MODULE))
214 G_DEFINE_TYPE (GtkThemingModule, gtk_theming_module, G_TYPE_TYPE_MODULE);
217 gtk_theming_engine_class_init (GtkThemingEngineClass *klass)
219 GObjectClass *object_class = G_OBJECT_CLASS (klass);
221 object_class->finalize = gtk_theming_engine_finalize;
222 object_class->set_property = gtk_theming_engine_impl_set_property;
223 object_class->get_property = gtk_theming_engine_impl_get_property;
225 klass->render_icon = gtk_theming_engine_render_icon;
226 klass->render_check = gtk_theming_engine_render_check;
227 klass->render_option = gtk_theming_engine_render_option;
228 klass->render_arrow = gtk_theming_engine_render_arrow;
229 klass->render_background = gtk_theming_engine_render_background;
230 klass->render_frame = gtk_theming_engine_render_frame;
231 klass->render_expander = gtk_theming_engine_render_expander;
232 klass->render_focus = gtk_theming_engine_render_focus;
233 klass->render_layout = gtk_theming_engine_render_layout;
234 klass->render_line = gtk_theming_engine_render_line;
235 klass->render_slider = gtk_theming_engine_render_slider;
236 klass->render_frame_gap = gtk_theming_engine_render_frame_gap;
237 klass->render_extension = gtk_theming_engine_render_extension;
238 klass->render_handle = gtk_theming_engine_render_handle;
239 klass->render_activity = gtk_theming_engine_render_activity;
240 klass->render_icon_pixbuf = gtk_theming_engine_render_icon_pixbuf;
243 * GtkThemingEngine:name:
245 * The theming engine name, this name will be used when registering
246 * custom properties, for a theming engine named "Clearlooks" registering
247 * a "glossy" custom property, it could be referenced in the CSS file as
250 * -Clearlooks-glossy: true;
255 g_object_class_install_property (object_class,
257 g_param_spec_string ("name",
259 P_("Theming engine name"),
261 G_PARAM_CONSTRUCT_ONLY | GTK_PARAM_READWRITE));
263 g_type_class_add_private (object_class, sizeof (GtkThemingEnginePrivate));
267 gtk_theming_engine_init (GtkThemingEngine *engine)
269 engine->priv = GTK_THEMING_ENGINE_GET_PRIVATE (engine);
273 gtk_theming_engine_finalize (GObject *object)
275 GtkThemingEnginePrivate *priv;
277 priv = GTK_THEMING_ENGINE (object)->priv;
280 G_OBJECT_GET_CLASS (gtk_theming_engine_parent_class)->finalize (object);
284 gtk_theming_engine_impl_set_property (GObject *object,
289 GtkThemingEnginePrivate *priv;
291 priv = GTK_THEMING_ENGINE (object)->priv;
299 priv->name = g_value_dup_string (value);
302 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
308 gtk_theming_engine_impl_get_property (GObject *object,
313 GtkThemingEnginePrivate *priv;
315 priv = GTK_THEMING_ENGINE (object)->priv;
320 g_value_set_string (value, priv->name);
323 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
329 _gtk_theming_engine_set_context (GtkThemingEngine *engine,
330 GtkStyleContext *context)
332 GtkThemingEnginePrivate *priv;
334 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
335 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
338 priv->context = context;
342 _gtk_theming_engine_peek_property (GtkThemingEngine *engine,
343 const char *property_name)
345 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
346 g_return_val_if_fail (property_name != NULL, NULL);
348 return _gtk_style_context_peek_property (engine->priv->context, property_name);
352 * gtk_theming_engine_get_property:
353 * @engine: a #GtkThemingEngine
354 * @property: the property name
355 * @state: state to retrieve the value for
356 * @value: (out) (transfer full): return location for the property value,
357 * you must free this memory using g_value_unset() once you are
360 * Gets a property value as retrieved from the style settings that apply
361 * to the currently rendered element.
366 gtk_theming_engine_get_property (GtkThemingEngine *engine,
367 const gchar *property,
371 GtkThemingEnginePrivate *priv;
373 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
374 g_return_if_fail (property != NULL);
375 g_return_if_fail (value != NULL);
378 gtk_style_context_get_property (priv->context, property, state, value);
382 * gtk_theming_engine_get_valist:
383 * @engine: a #GtkThemingEngine
384 * @state: state to retrieve values for
385 * @args: va_list of property name/return location pairs, followed by %NULL
387 * Retrieves several style property values that apply to the currently
393 gtk_theming_engine_get_valist (GtkThemingEngine *engine,
397 GtkThemingEnginePrivate *priv;
399 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
402 gtk_style_context_get_valist (priv->context, state, args);
406 * gtk_theming_engine_get:
407 * @engine: a #GtkThemingEngine
408 * @state: state to retrieve values for
409 * @...: property name /return value pairs, followed by %NULL
411 * Retrieves several style property values that apply to the currently
417 gtk_theming_engine_get (GtkThemingEngine *engine,
421 GtkThemingEnginePrivate *priv;
424 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
428 va_start (args, state);
429 gtk_style_context_get_valist (priv->context, state, args);
434 * gtk_theming_engine_get_style_property:
435 * @engine: a #GtkThemingEngine
436 * @property_name: the name of the widget style property
437 * @value: Return location for the property value, free with
438 * g_value_unset() after use.
440 * Gets the value for a widget style property.
445 gtk_theming_engine_get_style_property (GtkThemingEngine *engine,
446 const gchar *property_name,
449 GtkThemingEnginePrivate *priv;
451 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
452 g_return_if_fail (property_name != NULL);
455 gtk_style_context_get_style_property (priv->context, property_name, value);
459 * gtk_theming_engine_get_style_valist:
460 * @engine: a #GtkThemingEngine
461 * @args: va_list of property name/return location pairs, followed by %NULL
463 * Retrieves several widget style properties from @engine according to the
464 * currently rendered content's style.
469 gtk_theming_engine_get_style_valist (GtkThemingEngine *engine,
472 GtkThemingEnginePrivate *priv;
474 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
477 gtk_style_context_get_style_valist (priv->context, args);
481 * gtk_theming_engine_get_style:
482 * @engine: a #GtkThemingEngine
483 * @...: property name /return value pairs, followed by %NULL
485 * Retrieves several widget style properties from @engine according
486 * to the currently rendered content's style.
491 gtk_theming_engine_get_style (GtkThemingEngine *engine,
494 GtkThemingEnginePrivate *priv;
497 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
501 va_start (args, engine);
502 gtk_style_context_get_style_valist (priv->context, args);
507 * gtk_theming_engine_lookup_color:
508 * @engine: a #GtkThemingEngine
509 * @color_name: color name to lookup
510 * @color: (out): Return location for the looked up color
512 * Looks up and resolves a color name in the current style's color map.
514 * Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
517 gtk_theming_engine_lookup_color (GtkThemingEngine *engine,
518 const gchar *color_name,
521 GtkThemingEnginePrivate *priv;
523 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
524 g_return_val_if_fail (color_name != NULL, FALSE);
527 return gtk_style_context_lookup_color (priv->context, color_name, color);
531 * gtk_theming_engine_get_state:
532 * @engine: a #GtkThemingEngine
534 * returns the state used when rendering.
536 * Returns: the state flags
541 gtk_theming_engine_get_state (GtkThemingEngine *engine)
543 GtkThemingEnginePrivate *priv;
545 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), 0);
548 return gtk_style_context_get_state (priv->context);
552 * gtk_theming_engine_state_is_running:
553 * @engine: a #GtkThemingEngine
554 * @state: a widget state
555 * @progress: (out): return location for the transition progress
557 * Returns %TRUE if there is a transition animation running for the
558 * current region (see gtk_style_context_push_animatable_region()).
560 * If @progress is not %NULL, the animation progress will be returned
561 * there, 0.0 means the state is closest to being %FALSE, while 1.0 means
562 * it's closest to being %TRUE. This means transition animations will
563 * run from 0 to 1 when @state is being set to %TRUE and from 1 to 0 when
564 * it's being set to %FALSE.
566 * Returns: %TRUE if there is a running transition animation for @state.
571 gtk_theming_engine_state_is_running (GtkThemingEngine *engine,
575 GtkThemingEnginePrivate *priv;
577 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
580 return gtk_style_context_state_is_running (priv->context, state, progress);
584 * gtk_theming_engine_get_path:
585 * @engine: a #GtkThemingEngine
587 * Returns the widget path used for style matching.
589 * Returns: (transfer none): A #GtkWidgetPath
593 const GtkWidgetPath *
594 gtk_theming_engine_get_path (GtkThemingEngine *engine)
596 GtkThemingEnginePrivate *priv;
598 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
601 return gtk_style_context_get_path (priv->context);
605 * gtk_theming_engine_has_class:
606 * @engine: a #GtkThemingEngine
607 * @style_class: class name to look up
609 * Returns %TRUE if the currently rendered contents have
610 * defined the given class name.
612 * Returns: %TRUE if @engine has @class_name defined
617 gtk_theming_engine_has_class (GtkThemingEngine *engine,
618 const gchar *style_class)
620 GtkThemingEnginePrivate *priv;
622 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
625 return gtk_style_context_has_class (priv->context, style_class);
629 * gtk_theming_engine_has_region:
630 * @engine: a #GtkThemingEngine
631 * @style_region: a region name
632 * @flags: (out) (allow-none): return location for region flags
634 * Returns %TRUE if the currently rendered contents have the
635 * region defined. If @flags_return is not %NULL, it is set
636 * to the flags affecting the region.
638 * Returns: %TRUE if region is defined
643 gtk_theming_engine_has_region (GtkThemingEngine *engine,
644 const gchar *style_region,
645 GtkRegionFlags *flags)
647 GtkThemingEnginePrivate *priv;
652 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
655 return gtk_style_context_has_region (priv->context, style_region, flags);
659 * gtk_theming_engine_get_direction:
660 * @engine: a #GtkThemingEngine
662 * Returns the widget direction used for rendering.
664 * Returns: the widget direction
669 gtk_theming_engine_get_direction (GtkThemingEngine *engine)
671 GtkThemingEnginePrivate *priv;
673 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), GTK_TEXT_DIR_LTR);
676 return gtk_style_context_get_direction (priv->context);
680 * gtk_theming_engine_get_junction_sides:
681 * @engine: a #GtkThemingEngine
683 * Returns the widget direction used for rendering.
685 * Returns: the widget direction
690 gtk_theming_engine_get_junction_sides (GtkThemingEngine *engine)
692 GtkThemingEnginePrivate *priv;
694 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), 0);
697 return gtk_style_context_get_junction_sides (priv->context);
701 * gtk_theming_engine_get_color:
702 * @engine: a #GtkThemingEngine
703 * @state: state to retrieve the color for
704 * @color: (out): return value for the foreground color
706 * Gets the foreground color for a given state.
711 gtk_theming_engine_get_color (GtkThemingEngine *engine,
715 GtkThemingEnginePrivate *priv;
717 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
720 gtk_style_context_get_color (priv->context, state, color);
724 * gtk_theming_engine_get_background_color:
725 * @engine: a #GtkThemingEngine
726 * @state: state to retrieve the color for
727 * @color: (out): return value for the background color
729 * Gets the background color for a given state.
734 gtk_theming_engine_get_background_color (GtkThemingEngine *engine,
738 GtkThemingEnginePrivate *priv;
740 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
743 gtk_style_context_get_background_color (priv->context, state, color);
747 * gtk_theming_engine_get_border_color:
748 * @engine: a #GtkThemingEngine
749 * @state: state to retrieve the color for
750 * @color: (out): return value for the border color
752 * Gets the border color for a given state.
757 gtk_theming_engine_get_border_color (GtkThemingEngine *engine,
761 GtkThemingEnginePrivate *priv;
763 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
766 gtk_style_context_get_border_color (priv->context, state, color);
770 * gtk_theming_engine_get_border:
771 * @engine: a #GtkthemingEngine
772 * @state: state to retrieve the border for
773 * @border: (out): return value for the border settings
775 * Gets the border for a given state as a #GtkBorder.
780 gtk_theming_engine_get_border (GtkThemingEngine *engine,
784 GtkThemingEnginePrivate *priv;
786 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
789 gtk_style_context_get_border (priv->context, state, border);
793 * gtk_theming_engine_get_padding:
794 * @engine: a #GtkthemingEngine
795 * @state: state to retrieve the padding for
796 * @padding: (out): return value for the padding settings
798 * Gets the padding for a given state as a #GtkBorder.
803 gtk_theming_engine_get_padding (GtkThemingEngine *engine,
807 GtkThemingEnginePrivate *priv;
809 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
812 gtk_style_context_get_padding (priv->context, state, padding);
816 * gtk_theming_engine_get_margin:
817 * @engine: a #GtkThemingEngine
818 * @state: state to retrieve the border for
819 * @margin: (out): return value for the margin settings
821 * Gets the margin for a given state as a #GtkBorder.
826 gtk_theming_engine_get_margin (GtkThemingEngine *engine,
830 GtkThemingEnginePrivate *priv;
832 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
835 gtk_style_context_get_margin (priv->context, state, margin);
839 * gtk_theming_engine_get_font:
840 * @engine: a #GtkThemingEngine
841 * @state: state to retrieve the font for
843 * Returns the font description for a given state.
845 * Returns: (transfer none): the #PangoFontDescription for the given
846 * state. This object is owned by GTK+ and should not be
851 const PangoFontDescription *
852 gtk_theming_engine_get_font (GtkThemingEngine *engine,
855 GtkThemingEnginePrivate *priv;
857 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
860 return gtk_style_context_get_font (priv->context, state);
863 /* GtkThemingModule */
866 gtk_theming_module_load (GTypeModule *type_module)
868 GtkThemingModule *theming_module;
870 gchar *name, *module_path;
872 theming_module = GTK_THEMING_MODULE (type_module);
873 name = theming_module->name;
874 module_path = _gtk_find_module (name, "theming-engines");
879 module = g_module_open (module_path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
880 g_free (module_path);
885 if (!g_module_symbol (module, "theme_init",
886 (gpointer *) &theming_module->init) ||
887 !g_module_symbol (module, "theme_exit",
888 (gpointer *) &theming_module->exit) ||
889 !g_module_symbol (module, "create_engine",
890 (gpointer *) &theming_module->create_engine))
892 g_module_close (module);
897 theming_module->module = module;
899 theming_module->init (G_TYPE_MODULE (theming_module));
905 gtk_theming_module_unload (GTypeModule *type_module)
907 GtkThemingModule *theming_module;
909 theming_module = GTK_THEMING_MODULE (type_module);
911 theming_module->exit ();
913 g_module_close (theming_module->module);
915 theming_module->module = NULL;
916 theming_module->init = NULL;
917 theming_module->exit = NULL;
918 theming_module->create_engine = NULL;
922 gtk_theming_module_class_init (GtkThemingModuleClass *klass)
924 GTypeModuleClass *module_class = G_TYPE_MODULE_CLASS (klass);
926 module_class->load = gtk_theming_module_load;
927 module_class->unload = gtk_theming_module_unload;
931 gtk_theming_module_init (GtkThemingModule *module)
936 * gtk_theming_engine_load:
937 * @name: Theme engine name to load
939 * Loads and initializes a theming engine module from the
940 * standard directories.
942 * Returns: (transfer none): A theming engine, or %NULL if
943 * the engine @name doesn't exist.
946 gtk_theming_engine_load (const gchar *name)
948 static GHashTable *engines = NULL;
949 static GtkThemingEngine *default_engine;
950 GtkThemingEngine *engine = NULL;
955 engines = g_hash_table_new (g_str_hash, g_str_equal);
957 engine = g_hash_table_lookup (engines, name);
961 GtkThemingModule *module;
963 module = g_object_new (GTK_TYPE_THEMING_MODULE, NULL);
964 g_type_module_set_name (G_TYPE_MODULE (module), name);
965 module->name = g_strdup (name);
967 if (module && g_type_module_use (G_TYPE_MODULE (module)))
969 engine = (module->create_engine) ();
972 g_hash_table_insert (engines, module->name, engine);
978 if (G_UNLIKELY (!default_engine))
979 default_engine = g_object_new (GTK_TYPE_THEMING_ENGINE, NULL);
981 engine = default_engine;
988 * gtk_theming_engine_get_screen:
989 * @engine: a #GtkThemingEngine
991 * Returns the #GdkScreen to which @engine currently rendering to.
993 * Returns: (transfer none): a #GdkScreen, or %NULL.
996 gtk_theming_engine_get_screen (GtkThemingEngine *engine)
998 GtkThemingEnginePrivate *priv;
1000 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
1002 priv = engine->priv;
1003 return gtk_style_context_get_screen (priv->context);
1006 /* Paint method implementations */
1008 gtk_theming_engine_render_check (GtkThemingEngine *engine,
1015 GdkRGBA fg_color, bg_color;
1016 GtkStateFlags flags;
1017 gint exterior_size, interior_size, thickness, pad;
1018 GtkBorderStyle border_style;
1021 GtkThemingBackground bg;
1023 _gtk_theming_background_init (&bg, engine,
1026 gtk_theming_engine_get_junction_sides (engine));
1028 if (_gtk_theming_background_has_background_image (&bg))
1030 _gtk_theming_background_render (&bg, cr);
1034 flags = gtk_theming_engine_get_state (engine);
1037 gtk_theming_engine_get_color (engine, flags, &fg_color);
1038 gtk_theming_engine_get_background_color (engine, flags, &bg_color);
1039 gtk_theming_engine_get_border (engine, flags, &border);
1041 gtk_theming_engine_get (engine, flags,
1042 "border-style", &border_style,
1045 border_width = MIN (MIN (border.top, border.bottom),
1046 MIN (border.left, border.right));
1047 exterior_size = MIN (width, height);
1049 if (exterior_size % 2 == 0) /* Ensure odd */
1052 /* FIXME: thickness */
1054 pad = thickness + MAX (1, (exterior_size - 2 * thickness) / 9);
1055 interior_size = MAX (1, exterior_size - 2 * pad);
1057 if (interior_size < 7)
1060 pad = MAX (0, (exterior_size - interior_size) / 2);
1063 x -= (1 + exterior_size - (gint) width) / 2;
1064 y -= (1 + exterior_size - (gint) height) / 2;
1066 if (border_style == GTK_BORDER_STYLE_SOLID)
1068 GdkRGBA border_color;
1070 cairo_set_line_width (cr, border_width);
1071 gtk_theming_engine_get_border_color (engine, flags, &border_color);
1073 cairo_rectangle (cr, x + 0.5, y + 0.5, exterior_size - 1, exterior_size - 1);
1074 gdk_cairo_set_source_rgba (cr, &bg_color);
1075 cairo_fill_preserve (cr);
1077 gdk_cairo_set_source_rgba (cr, &border_color);
1081 gdk_cairo_set_source_rgba (cr, &fg_color);
1083 if (flags & GTK_STATE_FLAG_INCONSISTENT)
1085 int line_thickness = MAX (1, (3 + interior_size * 2) / 7);
1087 cairo_rectangle (cr,
1089 y + pad + (1 + interior_size - line_thickness) / 2,
1099 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress);
1101 if ((flags & GTK_STATE_FLAG_ACTIVE) || running)
1106 cairo_translate (cr,
1109 cairo_scale (cr, interior_size / 7., interior_size / 7.);
1111 cairo_rectangle (cr, 0, 0, 7 * progress, 7);
1114 cairo_move_to (cr, 7.0, 0.0);
1115 cairo_line_to (cr, 7.5, 1.0);
1116 cairo_curve_to (cr, 5.3, 2.0,
1119 cairo_curve_to (cr, 3.0, 5.7,
1122 cairo_line_to (cr, 0.2, 3.5);
1123 cairo_curve_to (cr, 1.1, 3.5,
1126 cairo_curve_to (cr, 1.0, 3.9,
1129 cairo_curve_to (cr, 3.5, 3.1,
1141 gtk_theming_engine_render_option (GtkThemingEngine *engine,
1148 GtkStateFlags flags;
1149 GdkRGBA fg_color, bg_color;
1150 gint exterior_size, interior_size, pad, thickness, border_width;
1151 GtkBorderStyle border_style;
1153 GtkThemingBackground bg;
1155 _gtk_theming_background_init (&bg, engine,
1158 gtk_theming_engine_get_junction_sides (engine));
1160 if (_gtk_theming_background_has_background_image (&bg))
1162 _gtk_theming_background_render (&bg, cr);
1166 flags = gtk_theming_engine_get_state (engine);
1170 gtk_theming_engine_get_color (engine, flags, &fg_color);
1171 gtk_theming_engine_get_background_color (engine, flags, &bg_color);
1172 gtk_theming_engine_get_border (engine, flags, &border);
1174 gtk_theming_engine_get (engine, flags,
1175 "border-style", &border_style,
1178 exterior_size = MIN (width, height);
1179 border_width = MIN (MIN (border.top, border.bottom),
1180 MIN (border.left, border.right));
1182 if (exterior_size % 2 == 0) /* Ensure odd */
1185 x -= (1 + exterior_size - width) / 2;
1186 y -= (1 + exterior_size - height) / 2;
1188 if (border_style == GTK_BORDER_STYLE_SOLID)
1190 GdkRGBA border_color;
1192 cairo_set_line_width (cr, border_width);
1193 gtk_theming_engine_get_border_color (engine, flags, &border_color);
1195 cairo_new_sub_path (cr);
1197 x + exterior_size / 2.,
1198 y + exterior_size / 2.,
1199 (exterior_size - 1) / 2.,
1202 gdk_cairo_set_source_rgba (cr, &bg_color);
1203 cairo_fill_preserve (cr);
1205 gdk_cairo_set_source_rgba (cr, &border_color);
1209 gdk_cairo_set_source_rgba (cr, &fg_color);
1211 /* FIXME: thickness */
1214 if (flags & GTK_STATE_FLAG_INCONSISTENT)
1216 gint line_thickness;
1218 pad = thickness + MAX (1, (exterior_size - 2 * thickness) / 9);
1219 interior_size = MAX (1, exterior_size - 2 * pad);
1221 if (interior_size < 7)
1224 pad = MAX (0, (exterior_size - interior_size) / 2);
1227 line_thickness = MAX (1, (3 + interior_size * 2) / 7);
1229 cairo_rectangle (cr,
1231 y + pad + (interior_size - line_thickness) / 2.,
1236 if (flags & GTK_STATE_FLAG_ACTIVE)
1238 pad = thickness + MAX (1, 2 * (exterior_size - 2 * thickness) / 9);
1239 interior_size = MAX (1, exterior_size - 2 * pad);
1241 if (interior_size < 5)
1244 pad = MAX (0, (exterior_size - interior_size) / 2);
1247 cairo_new_sub_path (cr);
1249 x + pad + interior_size / 2.,
1250 y + pad + interior_size / 2.,
1260 add_path_arrow (cairo_t *cr,
1268 cairo_translate (cr, x + (size / 2), y + (size / 2));
1269 cairo_rotate (cr, angle);
1271 cairo_move_to (cr, 0, - (size / 4));
1272 cairo_line_to (cr, - (size / 2), (size / 4));
1273 cairo_line_to (cr, (size / 2), (size / 4));
1274 cairo_close_path (cr);
1280 gtk_theming_engine_render_arrow (GtkThemingEngine *engine,
1287 GtkStateFlags flags;
1292 flags = gtk_theming_engine_get_state (engine);
1293 gtk_theming_engine_get_color (engine, flags, &fg_color);
1295 if (flags & GTK_STATE_FLAG_INSENSITIVE)
1297 add_path_arrow (cr, angle, x + 1, y + 1, size);
1298 cairo_set_source_rgb (cr, 1, 1, 1);
1302 add_path_arrow (cr, angle, x, y, size);
1303 gdk_cairo_set_source_rgba (cr, &fg_color);
1310 add_path_line (cairo_t *cr,
1316 /* Adjust endpoints */
1330 cairo_move_to (cr, x1, y1);
1331 cairo_line_to (cr, x2, y2);
1335 color_shade (const GdkRGBA *color,
1337 GdkRGBA *color_return)
1339 GtkSymbolicColor *literal, *shade;
1341 literal = gtk_symbolic_color_new_literal (color);
1342 shade = gtk_symbolic_color_new_shade (literal, factor);
1343 gtk_symbolic_color_unref (literal);
1345 gtk_symbolic_color_resolve (shade, NULL, color_return);
1346 gtk_symbolic_color_unref (shade);
1350 gtk_theming_engine_render_background (GtkThemingEngine *engine,
1357 GtkThemingBackground bg;
1359 _gtk_theming_background_init (&bg, engine,
1362 gtk_theming_engine_get_junction_sides (engine));
1364 _gtk_theming_background_render (&bg, cr);
1368 gtk_theming_engine_hide_border_sides (GtkBorder *border,
1371 if (hidden_side & SIDE_TOP)
1373 if (hidden_side & SIDE_RIGHT)
1375 if (hidden_side & SIDE_BOTTOM)
1377 if (hidden_side & SIDE_LEFT)
1382 render_frame_internal (GtkThemingEngine *engine,
1389 GtkJunctionSides junction)
1391 GtkStateFlags state;
1392 GtkBorderStyle border_style[4];
1393 GtkRoundedBox border_box, padding_box;
1397 static const guint current_side[4] = { SIDE_TOP, SIDE_RIGHT, SIDE_BOTTOM, SIDE_LEFT };
1401 state = gtk_theming_engine_get_state (engine);
1403 gtk_theming_engine_get_border (engine, state, &border);
1404 gtk_theming_engine_hide_border_sides (&border, hidden_side);
1406 gtk_theming_engine_get (engine, state,
1407 "border-top-style", &border_style[0],
1408 "border-right-style", &border_style[1],
1409 "border-bottom-style", &border_style[2],
1410 "border-left-style", &border_style[3],
1411 "border-top-color", &colors[0],
1412 "border-right-color", &colors[1],
1413 "border-bottom-color", &colors[2],
1414 "border-left-color", &colors[3],
1417 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
1421 GtkStateFlags other_state;
1422 GdkRGBA *other_colors[4];
1424 if (state & GTK_STATE_FLAG_PRELIGHT)
1426 other_state = state & ~(GTK_STATE_FLAG_PRELIGHT);
1427 progress = 1 - progress;
1430 other_state = state | GTK_STATE_FLAG_PRELIGHT;
1432 gtk_theming_engine_get (engine, other_state,
1433 "border-top-color", &other_colors[0],
1434 "border-right-color", &other_colors[1],
1435 "border-bottom-color", &other_colors[2],
1436 "border-left-color", &other_colors[3],
1439 for (i = 0; i < 4; i++)
1441 colors[i]->red = CLAMP (colors[i]->red + ((other_colors[i]->red - colors[i]->red) * progress), 0, 1);
1442 colors[i]->green = CLAMP (colors[i]->green + ((other_colors[i]->green - colors[i]->green) * progress), 0, 1);
1443 colors[i]->blue = CLAMP (colors[i]->blue + ((other_colors[i]->blue - colors[i]->blue) * progress), 0, 1);
1444 colors[i]->alpha = CLAMP (colors[i]->alpha + ((other_colors[i]->alpha - colors[i]->alpha) * progress), 0, 1);
1445 gdk_rgba_free (other_colors[i]);
1449 if (border_style[0] == GTK_BORDER_STYLE_OUTSET)
1450 color_shade (colors[0], 1.8, colors[0]);
1451 if (border_style[1] == GTK_BORDER_STYLE_INSET)
1452 color_shade (colors[1], 1.8, colors[1]);
1453 if (border_style[2] == GTK_BORDER_STYLE_INSET)
1454 color_shade (colors[2], 1.8, colors[2]);
1455 if (border_style[3] == GTK_BORDER_STYLE_OUTSET)
1456 color_shade (colors[3], 1.8, colors[3]);
1460 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
1462 _gtk_rounded_box_init_rect (&border_box, x, y, width, height);
1463 _gtk_rounded_box_apply_border_radius (&border_box, engine, state, junction);
1464 padding_box = border_box;
1465 _gtk_rounded_box_shrink (&padding_box, border.top, border.right, border.bottom, border.left);
1467 if (gdk_rgba_equal (colors[0], colors[1]) &&
1468 gdk_rgba_equal (colors[0], colors[2]) &&
1469 gdk_rgba_equal (colors[0], colors[3]))
1471 gdk_cairo_set_source_rgba (cr, colors[0]);
1473 _gtk_rounded_box_path (&border_box, cr);
1474 _gtk_rounded_box_path (&padding_box, cr);
1479 for (i = 0; i < 4; i++)
1481 if (hidden_side & current_side[i])
1484 for (j = 0; j < 4; j++)
1486 if (hidden_side & current_side[j])
1490 (gdk_rgba_equal (colors[i], colors[j])))
1492 /* We were already painted when i == j */
1497 _gtk_rounded_box_path_top (&border_box, &padding_box, cr);
1499 _gtk_rounded_box_path_right (&border_box, &padding_box, cr);
1501 _gtk_rounded_box_path_bottom (&border_box, &padding_box, cr);
1503 _gtk_rounded_box_path_left (&border_box, &padding_box, cr);
1506 /* We were already painted when i == j */
1510 gdk_cairo_set_source_rgba (cr, colors[i]);
1518 for (i = 0; i < 4; i++)
1519 gdk_rgba_free (colors[i]);
1523 gtk_theming_engine_render_frame (GtkThemingEngine *engine,
1530 GtkStateFlags flags;
1531 GtkJunctionSides junction;
1532 GtkBorderImage border_image;
1535 flags = gtk_theming_engine_get_state (engine);
1536 junction = gtk_theming_engine_get_junction_sides (engine);
1537 gtk_theming_engine_get_border (engine, flags, &border);
1539 if (_gtk_border_image_init (&border_image, engine))
1540 _gtk_border_image_render (&border_image, &border,
1541 cr, x, y, width, height);
1543 render_frame_internal (engine, cr,
1544 x, y, width, height,
1549 gtk_theming_engine_render_expander (GtkThemingEngine *engine,
1556 GtkStateFlags flags;
1557 GdkRGBA outline_color, fg_color;
1558 double vertical_overshoot;
1561 double interp; /* interpolation factor for center position */
1562 double x_double_horz, y_double_horz;
1563 double x_double_vert, y_double_vert;
1564 double x_double, y_double;
1567 gboolean running, is_rtl;
1571 flags = gtk_theming_engine_get_state (engine);
1573 gtk_theming_engine_get_color (engine, flags, &fg_color);
1574 gtk_theming_engine_get_border_color (engine, flags, &outline_color);
1576 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress);
1577 is_rtl = (gtk_theming_engine_get_direction (engine) == GTK_TEXT_DIR_RTL);
1581 progress = (flags & GTK_STATE_FLAG_ACTIVE) ? 1 : 0;
1583 if (!gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_HORIZONTAL))
1586 angle = (G_PI) - ((G_PI / 2) * progress);
1588 angle = (G_PI / 2) * progress;
1593 angle = (G_PI / 2) + ((G_PI / 2) * progress);
1595 angle = (G_PI / 2) - ((G_PI / 2) * progress);
1600 /* Compute distance that the stroke extends beyonds the end
1601 * of the triangle we draw.
1603 vertical_overshoot = line_width / 2.0 * (1. / tan (G_PI / 8));
1605 /* For odd line widths, we end the vertical line of the triangle
1606 * at a half pixel, so we round differently.
1608 if (line_width % 2 == 1)
1609 vertical_overshoot = ceil (0.5 + vertical_overshoot) - 0.5;
1611 vertical_overshoot = ceil (vertical_overshoot);
1613 /* Adjust the size of the triangle we draw so that the entire stroke fits
1615 diameter = (gint) MAX (3, width - 2 * vertical_overshoot);
1617 /* If the line width is odd, we want the diameter to be even,
1618 * and vice versa, so force the sum to be odd. This relationship
1619 * makes the point of the triangle look right.
1621 diameter -= (1 - (diameter + line_width) % 2);
1623 radius = diameter / 2.;
1625 /* Adjust the center so that the stroke is properly aligned with
1626 * the pixel grid. The center adjustment is different for the
1627 * horizontal and vertical orientations. For intermediate positions
1628 * we interpolate between the two.
1630 x_double_vert = floor ((x + width / 2) - (radius + line_width) / 2.) + (radius + line_width) / 2.;
1631 y_double_vert = (y + height / 2) - 0.5;
1633 x_double_horz = (x + width / 2) - 0.5;
1634 y_double_horz = floor ((y + height / 2) - (radius + line_width) / 2.) + (radius + line_width) / 2.;
1636 x_double = x_double_vert * (1 - interp) + x_double_horz * interp;
1637 y_double = y_double_vert * (1 - interp) + y_double_horz * interp;
1639 cairo_translate (cr, x_double, y_double);
1640 cairo_rotate (cr, angle);
1642 cairo_move_to (cr, - radius / 2., - radius);
1643 cairo_line_to (cr, radius / 2., 0);
1644 cairo_line_to (cr, - radius / 2., radius);
1645 cairo_close_path (cr);
1647 cairo_set_line_width (cr, line_width);
1649 gdk_cairo_set_source_rgba (cr, &fg_color);
1651 cairo_fill_preserve (cr);
1653 gdk_cairo_set_source_rgba (cr, &outline_color);
1660 gtk_theming_engine_render_focus (GtkThemingEngine *engine,
1667 GtkStateFlags flags;
1673 flags = gtk_theming_engine_get_state (engine);
1675 gtk_theming_engine_get_color (engine, flags, &color);
1677 gtk_theming_engine_get_style (engine,
1678 "focus-line-width", &line_width,
1679 "focus-line-pattern", (gchar *) &dash_list,
1682 cairo_set_line_width (cr, (gdouble) line_width);
1686 gint n_dashes = strlen ((const gchar *) dash_list);
1687 gdouble *dashes = g_new (gdouble, n_dashes);
1688 gdouble total_length = 0;
1689 gdouble dash_offset;
1692 for (i = 0; i < n_dashes; i++)
1694 dashes[i] = dash_list[i];
1695 total_length += dash_list[i];
1698 /* The dash offset here aligns the pattern to integer pixels
1699 * by starting the dash at the right side of the left border
1700 * Negative dash offsets in cairo don't work
1701 * (https://bugs.freedesktop.org/show_bug.cgi?id=2729)
1703 dash_offset = - line_width / 2.;
1705 while (dash_offset < 0)
1706 dash_offset += total_length;
1708 cairo_set_dash (cr, dashes, n_dashes, dash_offset);
1712 cairo_rectangle (cr,
1713 x + line_width / 2.,
1714 y + line_width / 2.,
1716 height - line_width);
1718 gdk_cairo_set_source_rgba (cr, &color);
1727 gtk_theming_engine_render_line (GtkThemingEngine *engine,
1735 GtkStateFlags flags;
1737 flags = gtk_theming_engine_get_state (engine);
1740 gtk_theming_engine_get_color (engine, flags, &color);
1742 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
1743 cairo_set_line_width (cr, 1);
1745 cairo_move_to (cr, x0 + 0.5, y0 + 0.5);
1746 cairo_line_to (cr, x1 + 0.5, y1 + 0.5);
1748 gdk_cairo_set_source_rgba (cr, &color);
1755 prepare_context_for_layout (cairo_t *cr,
1758 PangoLayout *layout)
1760 const PangoMatrix *matrix;
1762 matrix = pango_context_get_matrix (pango_layout_get_context (layout));
1764 cairo_move_to (cr, x, y);
1768 cairo_matrix_t cairo_matrix;
1770 cairo_matrix_init (&cairo_matrix,
1771 matrix->xx, matrix->yx,
1772 matrix->xy, matrix->yy,
1773 matrix->x0, matrix->y0);
1775 cairo_transform (cr, &cairo_matrix);
1780 gtk_theming_engine_render_layout (GtkThemingEngine *engine,
1784 PangoLayout *layout)
1787 GtkShadow *text_shadow = NULL;
1788 GtkStateFlags flags;
1793 flags = gtk_theming_engine_get_state (engine);
1794 gtk_theming_engine_get_color (engine, flags, &fg_color);
1796 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
1800 GtkStateFlags other_flags;
1803 if (flags & GTK_STATE_FLAG_PRELIGHT)
1805 other_flags = flags & ~(GTK_STATE_FLAG_PRELIGHT);
1806 progress = 1 - progress;
1809 other_flags = flags | GTK_STATE_FLAG_PRELIGHT;
1811 gtk_theming_engine_get_color (engine, other_flags, &other_fg);
1813 fg_color.red = CLAMP (fg_color.red + ((other_fg.red - fg_color.red) * progress), 0, 1);
1814 fg_color.green = CLAMP (fg_color.green + ((other_fg.green - fg_color.green) * progress), 0, 1);
1815 fg_color.blue = CLAMP (fg_color.blue + ((other_fg.blue - fg_color.blue) * progress), 0, 1);
1816 fg_color.alpha = CLAMP (fg_color.alpha + ((other_fg.alpha - fg_color.alpha) * progress), 0, 1);
1819 gtk_theming_engine_get (engine, flags,
1820 "text-shadow", &text_shadow,
1823 prepare_context_for_layout (cr, x, y, layout);
1825 if (text_shadow != NULL)
1827 _gtk_text_shadow_paint_layout (text_shadow, cr, layout);
1828 _gtk_shadow_unref (text_shadow);
1831 gdk_cairo_set_source_rgba (cr, &fg_color);
1832 pango_cairo_show_layout (cr, layout);
1838 gtk_theming_engine_render_slider (GtkThemingEngine *engine,
1844 GtkOrientation orientation)
1846 const GtkWidgetPath *path;
1849 path = gtk_theming_engine_get_path (engine);
1851 gtk_theming_engine_render_background (engine, cr, x, y, width, height);
1852 gtk_theming_engine_render_frame (engine, cr, x, y, width, height);
1854 /* FIXME: thickness */
1857 if (gtk_widget_path_is_type (path, GTK_TYPE_SCALE))
1859 if (orientation == GTK_ORIENTATION_VERTICAL)
1860 gtk_theming_engine_render_line (engine, cr,
1862 y + (gint) height / 2,
1863 x + width - thickness - 1,
1864 y + (gint) height / 2);
1866 gtk_theming_engine_render_line (engine, cr,
1867 x + (gint) width / 2,
1869 x + (gint) width / 2,
1870 y + height - thickness - 1);
1875 gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
1881 GtkPositionType gap_side,
1885 GtkJunctionSides junction;
1886 GtkStateFlags state;
1888 GtkCssBorderCornerRadius *top_left_radius, *top_right_radius;
1889 GtkCssBorderCornerRadius *bottom_left_radius, *bottom_right_radius;
1890 gdouble x0, y0, x1, y1, xc, yc, wc, hc;
1891 GtkBorderImage border_image;
1894 xc = yc = wc = hc = 0;
1895 state = gtk_theming_engine_get_state (engine);
1896 junction = gtk_theming_engine_get_junction_sides (engine);
1898 gtk_theming_engine_get_border (engine, state, &border);
1899 gtk_theming_engine_get (engine, state,
1900 "border-top-left-radius", &top_left_radius,
1901 "border-top-right-radius", &top_right_radius,
1902 "border-bottom-right-radius", &bottom_right_radius,
1903 "border-bottom-left-radius", &bottom_left_radius,
1906 border_width = MIN (MIN (border.top, border.bottom),
1907 MIN (border.left, border.right));
1914 xc = x + xy0_gap + border_width;
1916 wc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
1919 if (xy0_gap < top_left_radius->horizontal)
1920 junction |= GTK_JUNCTION_CORNER_TOPLEFT;
1922 if (xy1_gap > width - top_right_radius->horizontal)
1923 junction |= GTK_JUNCTION_CORNER_TOPRIGHT;
1925 case GTK_POS_BOTTOM:
1926 xc = x + xy0_gap + border_width;
1927 yc = y + height - border_width;
1928 wc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
1931 if (xy0_gap < bottom_left_radius->horizontal)
1932 junction |= GTK_JUNCTION_CORNER_BOTTOMLEFT;
1934 if (xy1_gap > width - bottom_right_radius->horizontal)
1935 junction |= GTK_JUNCTION_CORNER_BOTTOMRIGHT;
1940 yc = y + xy0_gap + border_width;
1942 hc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
1944 if (xy0_gap < top_left_radius->vertical)
1945 junction |= GTK_JUNCTION_CORNER_TOPLEFT;
1947 if (xy1_gap > height - bottom_left_radius->vertical)
1948 junction |= GTK_JUNCTION_CORNER_BOTTOMLEFT;
1952 xc = x + width - border_width;
1953 yc = y + xy0_gap + border_width;
1955 hc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
1957 if (xy0_gap < top_right_radius->vertical)
1958 junction |= GTK_JUNCTION_CORNER_TOPRIGHT;
1960 if (xy1_gap > height - bottom_right_radius->vertical)
1961 junction |= GTK_JUNCTION_CORNER_BOTTOMRIGHT;
1966 cairo_clip_extents (cr, &x0, &y0, &x1, &y1);
1967 cairo_rectangle (cr, x0, y0, x1 - x0, yc - y0);
1968 cairo_rectangle (cr, x0, yc, xc - x0, hc);
1969 cairo_rectangle (cr, xc + wc, yc, x1 - (xc + wc), hc);
1970 cairo_rectangle (cr, x0, yc + hc, x1 - x0, y1 - (yc + hc));
1973 if (_gtk_border_image_init (&border_image, engine))
1974 _gtk_border_image_render (&border_image, &border,
1975 cr, x, y, width, height);
1977 render_frame_internal (engine, cr,
1978 x, y, width, height,
1983 g_free (top_left_radius);
1984 g_free (top_right_radius);
1985 g_free (bottom_right_radius);
1986 g_free (bottom_left_radius);
1990 gtk_theming_engine_render_extension (GtkThemingEngine *engine,
1996 GtkPositionType gap_side)
1998 GtkThemingBackground bg;
1999 GtkJunctionSides junction = 0;
2000 guint hidden_side = 0;
2007 junction = GTK_JUNCTION_LEFT;
2008 hidden_side = SIDE_LEFT;
2010 cairo_translate (cr, x + width, y);
2011 cairo_rotate (cr, G_PI / 2);
2014 junction = GTK_JUNCTION_RIGHT;
2015 hidden_side = SIDE_RIGHT;
2017 cairo_translate (cr, x, y + height);
2018 cairo_rotate (cr, - G_PI / 2);
2021 junction = GTK_JUNCTION_TOP;
2022 hidden_side = SIDE_TOP;
2024 cairo_translate (cr, x + width, y + height);
2025 cairo_rotate (cr, G_PI);
2027 case GTK_POS_BOTTOM:
2028 junction = GTK_JUNCTION_BOTTOM;
2029 hidden_side = SIDE_BOTTOM;
2031 cairo_translate (cr, x, y);
2035 if (gap_side == GTK_POS_TOP ||
2036 gap_side == GTK_POS_BOTTOM)
2037 _gtk_theming_background_init (&bg, engine,
2040 GTK_JUNCTION_BOTTOM);
2042 _gtk_theming_background_init (&bg, engine,
2045 GTK_JUNCTION_BOTTOM);
2047 _gtk_theming_background_render (&bg, cr);
2053 render_frame_internal (engine, cr,
2054 x, y, width, height,
2055 hidden_side, junction);
2061 render_dot (cairo_t *cr,
2062 const GdkRGBA *lighter,
2063 const GdkRGBA *darker,
2068 size = CLAMP ((gint) size, 2, 3);
2072 gdk_cairo_set_source_rgba (cr, lighter);
2073 cairo_rectangle (cr, x, y, 1, 1);
2074 cairo_rectangle (cr, x + 1, y + 1, 1, 1);
2079 gdk_cairo_set_source_rgba (cr, lighter);
2080 cairo_rectangle (cr, x, y, 2, 1);
2081 cairo_rectangle (cr, x, y, 1, 2);
2084 gdk_cairo_set_source_rgba (cr, darker);
2085 cairo_rectangle (cr, x + 1, y + 1, 2, 1);
2086 cairo_rectangle (cr, x + 2, y, 1, 2);
2092 gtk_theming_engine_render_handle (GtkThemingEngine *engine,
2099 GtkStateFlags flags;
2100 GdkRGBA bg_color, lighter, darker;
2101 GtkJunctionSides sides;
2102 GtkThemingBackground bg;
2106 flags = gtk_theming_engine_get_state (engine);
2108 cairo_set_line_width (cr, 1.0);
2109 sides = gtk_theming_engine_get_junction_sides (engine);
2110 gtk_theming_engine_get_background_color (engine, flags, &bg_color);
2112 color_shade (&bg_color, 0.7, &darker);
2113 color_shade (&bg_color, 1.3, &lighter);
2115 _gtk_theming_background_init (&bg, engine, x, y, width, height, sides);
2116 _gtk_theming_background_render (&bg, cr);
2118 if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_GRIP))
2120 /* reduce confusing values to a meaningful state */
2121 if ((sides & (GTK_JUNCTION_CORNER_TOPLEFT | GTK_JUNCTION_CORNER_BOTTOMRIGHT)) == (GTK_JUNCTION_CORNER_TOPLEFT | GTK_JUNCTION_CORNER_BOTTOMRIGHT))
2122 sides &= ~GTK_JUNCTION_CORNER_TOPLEFT;
2124 if ((sides & (GTK_JUNCTION_CORNER_TOPRIGHT | GTK_JUNCTION_CORNER_BOTTOMLEFT)) == (GTK_JUNCTION_CORNER_TOPRIGHT | GTK_JUNCTION_CORNER_BOTTOMLEFT))
2125 sides &= ~GTK_JUNCTION_CORNER_TOPRIGHT;
2128 sides = GTK_JUNCTION_CORNER_BOTTOMRIGHT;
2130 /* align drawing area to the connected side */
2131 if (sides == GTK_JUNCTION_LEFT)
2136 else if (sides == GTK_JUNCTION_CORNER_TOPLEFT)
2140 else if (height < width)
2143 else if (sides == GTK_JUNCTION_CORNER_BOTTOMLEFT)
2145 /* make it square, aligning to bottom left */
2148 y += (height - width);
2151 else if (height < width)
2154 else if (sides == GTK_JUNCTION_RIGHT)
2156 /* aligning to right */
2159 x += (width - height);
2163 else if (sides == GTK_JUNCTION_CORNER_TOPRIGHT)
2167 else if (height < width)
2169 x += (width - height);
2173 else if (sides == GTK_JUNCTION_CORNER_BOTTOMRIGHT)
2175 /* make it square, aligning to bottom right */
2178 y += (height - width);
2181 else if (height < width)
2183 x += (width - height);
2187 else if (sides == GTK_JUNCTION_TOP)
2192 else if (sides == GTK_JUNCTION_BOTTOM)
2194 /* align to bottom */
2197 y += (height - width);
2202 g_assert_not_reached ();
2204 if (sides == GTK_JUNCTION_LEFT ||
2205 sides == GTK_JUNCTION_RIGHT)
2211 while (xi < x + width)
2213 gdk_cairo_set_source_rgba (cr, &lighter);
2214 add_path_line (cr, x, y, x, y + height);
2218 gdk_cairo_set_source_rgba (cr, &darker);
2219 add_path_line (cr, xi, y, xi, y + height);
2224 else if (sides == GTK_JUNCTION_TOP ||
2225 sides == GTK_JUNCTION_BOTTOM)
2231 while (yi < y + height)
2233 gdk_cairo_set_source_rgba (cr, &lighter);
2234 add_path_line (cr, x, yi, x + width, yi);
2238 gdk_cairo_set_source_rgba (cr, &darker);
2239 add_path_line (cr, x, yi, x + width, yi);
2244 else if (sides == GTK_JUNCTION_CORNER_TOPLEFT)
2253 gdk_cairo_set_source_rgba (cr, &darker);
2254 add_path_line (cr, xi, y, x, yi);
2260 add_path_line (cr, xi, y, x, yi);
2266 gdk_cairo_set_source_rgba (cr, &lighter);
2267 add_path_line (cr, xi, y, x, yi);
2274 else if (sides == GTK_JUNCTION_CORNER_TOPRIGHT)
2281 while (xi < (x + width - 3))
2283 gdk_cairo_set_source_rgba (cr, &lighter);
2284 add_path_line (cr, xi, y, x + width, yi);
2290 gdk_cairo_set_source_rgba (cr, &darker);
2291 add_path_line (cr, xi, y, x + width, yi);
2297 add_path_line (cr, xi, y, x + width, yi);
2304 else if (sides == GTK_JUNCTION_CORNER_BOTTOMLEFT)
2313 gdk_cairo_set_source_rgba (cr, &darker);
2314 add_path_line (cr, x, yi, xi, y + height);
2320 add_path_line (cr, x, yi, xi, y + height);
2326 gdk_cairo_set_source_rgba (cr, &lighter);
2327 add_path_line (cr, x, yi, xi, y + height);
2334 else if (sides == GTK_JUNCTION_CORNER_BOTTOMRIGHT)
2341 while (xi < (x + width - 3))
2343 gdk_cairo_set_source_rgba (cr, &lighter);
2344 add_path_line (cr, xi, y + height, x + width, yi);
2350 gdk_cairo_set_source_rgba (cr, &darker);
2351 add_path_line (cr, xi, y + height, x + width, yi);
2357 add_path_line (cr, xi, y + height, x + width, yi);
2365 else if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_PANE_SEPARATOR))
2368 for (xx = x + width / 2 - 15; xx <= x + width / 2 + 15; xx += 5)
2369 render_dot (cr, &lighter, &darker, xx, y + height / 2 - 1, 3);
2371 for (yy = y + height / 2 - 15; yy <= y + height / 2 + 15; yy += 5)
2372 render_dot (cr, &lighter, &darker, x + width / 2 - 1, yy, 3);
2376 for (yy = y; yy < y + height; yy += 3)
2377 for (xx = x; xx < x + width; xx += 6)
2379 render_dot (cr, &lighter, &darker, xx, yy, 2);
2380 render_dot (cr, &lighter, &darker, xx + 3, yy + 1, 2);
2388 _gtk_theming_engine_paint_spinner (cairo_t *cr,
2393 guint num_steps, step;
2400 step = (guint) (progress * num_steps);
2406 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
2407 cairo_set_line_width (cr, 2.0);
2409 half = num_steps / 2;
2411 for (i = 0; i < num_steps; i++)
2413 gint inset = 0.7 * radius;
2415 /* transparency is a function of time and intial value */
2416 gdouble t = 1.0 - (gdouble) ((i + step) % num_steps) / num_steps;
2417 gdouble xscale = - sin (i * G_PI / half);
2418 gdouble yscale = - cos (i * G_PI / half);
2420 cairo_set_source_rgba (cr,
2427 (radius - inset) * xscale,
2428 (radius - inset) * yscale);
2440 render_spinner (GtkThemingEngine *engine,
2447 GtkStateFlags state;
2453 state = gtk_theming_engine_get_state (engine);
2455 if (!gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress))
2458 radius = MIN (width / 2, height / 2);
2460 gtk_theming_engine_get_color (engine, state, &color);
2461 gtk_theming_engine_get (engine, state,
2462 "icon-shadow", &shadow,
2466 cairo_translate (cr, x + width / 2, y + height / 2);
2470 _gtk_icon_shadow_paint_spinner (shadow, cr,
2473 _gtk_shadow_unref (shadow);
2476 _gtk_theming_engine_paint_spinner (cr,
2485 gtk_theming_engine_render_activity (GtkThemingEngine *engine,
2492 if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_SPINNER))
2494 render_spinner (engine, cr, x, y, width, height);
2498 gtk_theming_engine_render_background (engine, cr, x, y, width, height);
2499 gtk_theming_engine_render_frame (engine, cr, x, y, width, height);
2504 scale_or_ref (GdkPixbuf *src,
2508 if (width == gdk_pixbuf_get_width (src) &&
2509 height == gdk_pixbuf_get_height (src))
2510 return g_object_ref (src);
2512 return gdk_pixbuf_scale_simple (src,
2514 GDK_INTERP_BILINEAR);
2518 lookup_icon_size (GtkThemingEngine *engine,
2524 GtkSettings *settings;
2526 screen = gtk_theming_engine_get_screen (engine);
2527 settings = gtk_settings_get_for_screen (screen);
2529 return gtk_icon_size_lookup_for_settings (settings, size, width, height);
2533 colorshift_source (cairo_t *cr,
2536 cairo_pattern_t *source;
2541 source = cairo_pattern_reference (cairo_get_source (cr));
2543 cairo_set_source_rgb (cr, shift, shift, shift);
2544 cairo_set_operator (cr, CAIRO_OPERATOR_COLOR_DODGE);
2546 cairo_mask (cr, source);
2548 cairo_pattern_destroy (source);
2553 gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine *engine,
2554 const GtkIconSource *source,
2559 GdkPixbuf *base_pixbuf;
2560 GtkStateFlags state;
2564 cairo_surface_t *surface;
2566 base_pixbuf = gtk_icon_source_get_pixbuf (source);
2567 state = gtk_theming_engine_get_state (engine);
2569 g_return_val_if_fail (base_pixbuf != NULL, NULL);
2571 if (size != (GtkIconSize) -1 &&
2572 !lookup_icon_size (engine, size, &width, &height))
2574 g_warning (G_STRLOC ": invalid icon size '%d'", size);
2578 /* If the size was wildcarded, and we're allowed to scale, then scale; otherwise,
2581 if (size != (GtkIconSize) -1 &&
2582 gtk_icon_source_get_size_wildcarded (source))
2583 scaled = scale_or_ref (base_pixbuf, width, height);
2585 scaled = g_object_ref (base_pixbuf);
2587 /* If the state was wildcarded, then generate a state. */
2588 if (gtk_icon_source_get_state_wildcarded (source))
2590 if (state & GTK_STATE_FLAG_INSENSITIVE)
2592 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
2593 gdk_pixbuf_get_width (scaled),
2594 gdk_pixbuf_get_height (scaled));
2595 cr = cairo_create (surface);
2596 gdk_cairo_set_source_pixbuf (cr, scaled, 0, 0);
2597 cairo_paint_with_alpha (cr, 0.5);
2601 g_object_unref (scaled);
2602 stated = gdk_pixbuf_get_from_surface (surface, 0, 0,
2603 cairo_image_surface_get_width (surface),
2604 cairo_image_surface_get_height (surface));
2605 cairo_surface_destroy (surface);
2607 else if (state & GTK_STATE_FLAG_PRELIGHT)
2609 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
2610 gdk_pixbuf_get_width (scaled),
2611 gdk_pixbuf_get_height (scaled));
2613 cr = cairo_create (surface);
2614 gdk_cairo_set_source_pixbuf (cr, scaled, 0, 0);
2615 colorshift_source (cr, 0.10);
2619 g_object_unref (scaled);
2620 stated = gdk_pixbuf_get_from_surface (surface, 0, 0,
2621 cairo_image_surface_get_width (surface),
2622 cairo_image_surface_get_height (surface));
2623 cairo_surface_destroy (surface);
2635 gtk_theming_engine_render_icon (GtkThemingEngine *engine,
2641 GtkStateFlags state;
2642 GtkShadow *icon_shadow;
2644 state = gtk_theming_engine_get_state (engine);
2648 gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
2650 gtk_theming_engine_get (engine, state,
2651 "icon-shadow", &icon_shadow,
2654 if (icon_shadow != NULL)
2656 _gtk_icon_shadow_paint (icon_shadow, cr);
2657 _gtk_shadow_unref (icon_shadow);