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;
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-style", &border_style,
1408 "border-top-color", &colors[0],
1409 "border-right-color", &colors[1],
1410 "border-bottom-color", &colors[2],
1411 "border-left-color", &colors[3],
1414 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
1418 GtkStateFlags other_state;
1419 GdkRGBA *other_colors[4];
1421 if (state & GTK_STATE_FLAG_PRELIGHT)
1423 other_state = state & ~(GTK_STATE_FLAG_PRELIGHT);
1424 progress = 1 - progress;
1427 other_state = state | GTK_STATE_FLAG_PRELIGHT;
1429 gtk_theming_engine_get (engine, other_state,
1430 "border-top-color", &other_colors[0],
1431 "border-right-color", &other_colors[1],
1432 "border-bottom-color", &other_colors[2],
1433 "border-left-color", &other_colors[3],
1436 for (i = 0; i < 4; i++)
1438 colors[i]->red = CLAMP (colors[i]->red + ((other_colors[i]->red - colors[i]->red) * progress), 0, 1);
1439 colors[i]->green = CLAMP (colors[i]->green + ((other_colors[i]->green - colors[i]->green) * progress), 0, 1);
1440 colors[i]->blue = CLAMP (colors[i]->blue + ((other_colors[i]->blue - colors[i]->blue) * progress), 0, 1);
1441 colors[i]->alpha = CLAMP (colors[i]->alpha + ((other_colors[i]->alpha - colors[i]->alpha) * progress), 0, 1);
1442 gdk_rgba_free (other_colors[i]);
1446 switch (border_style)
1449 g_assert_not_reached ();
1450 case GTK_BORDER_STYLE_NONE:
1451 case GTK_BORDER_STYLE_SOLID:
1453 case GTK_BORDER_STYLE_INSET:
1454 color_shade (colors[1], 1.8, colors[1]);
1455 color_shade (colors[2], 1.8, colors[2]);
1457 case GTK_BORDER_STYLE_OUTSET:
1458 color_shade (colors[0], 1.8, colors[0]);
1459 color_shade (colors[3], 1.8, colors[3]);
1465 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
1467 _gtk_rounded_box_init_rect (&border_box, x, y, width, height);
1468 _gtk_rounded_box_apply_border_radius (&border_box, engine, state, junction);
1469 padding_box = border_box;
1470 _gtk_rounded_box_shrink (&padding_box, border.top, border.right, border.bottom, border.left);
1472 switch (border_style)
1474 case GTK_BORDER_STYLE_NONE:
1476 case GTK_BORDER_STYLE_SOLID:
1477 case GTK_BORDER_STYLE_INSET:
1478 case GTK_BORDER_STYLE_OUTSET:
1480 if (gdk_rgba_equal (colors[0], colors[1]) &&
1481 gdk_rgba_equal (colors[0], colors[2]) &&
1482 gdk_rgba_equal (colors[0], colors[3]))
1484 gdk_cairo_set_source_rgba (cr, colors[0]);
1486 _gtk_rounded_box_path (&border_box, cr);
1487 _gtk_rounded_box_path (&padding_box, cr);
1492 for (i = 0; i < 4; i++)
1494 if (hidden_side & current_side[i])
1497 for (j = 0; j < 4; j++)
1499 if (hidden_side & current_side[j])
1503 gdk_rgba_equal (colors[i], colors[j]))
1505 /* We were already painted when i == j */
1510 _gtk_rounded_box_path_top (&border_box, &padding_box, cr);
1512 _gtk_rounded_box_path_right (&border_box, &padding_box, cr);
1514 _gtk_rounded_box_path_bottom (&border_box, &padding_box, cr);
1516 _gtk_rounded_box_path_left (&border_box, &padding_box, cr);
1519 /* We were already painted when i == j */
1523 gdk_cairo_set_source_rgba (cr, colors[i]);
1533 for (i = 0; i < 4; i++)
1534 gdk_rgba_free (colors[i]);
1538 gtk_theming_engine_render_frame (GtkThemingEngine *engine,
1545 GtkStateFlags flags;
1546 GtkBorderStyle border_style;
1547 GtkJunctionSides junction;
1548 GtkBorderImage border_image;
1551 flags = gtk_theming_engine_get_state (engine);
1552 junction = gtk_theming_engine_get_junction_sides (engine);
1553 gtk_theming_engine_get_border (engine, flags, &border);
1555 gtk_theming_engine_get (engine, flags,
1556 "border-style", &border_style,
1559 if (_gtk_border_image_init (&border_image, engine))
1560 _gtk_border_image_render (&border_image, &border,
1561 cr, x, y, width, height);
1562 else if (border_style != GTK_BORDER_STYLE_NONE)
1563 render_frame_internal (engine, cr,
1564 x, y, width, height,
1569 gtk_theming_engine_render_expander (GtkThemingEngine *engine,
1576 GtkStateFlags flags;
1577 GdkRGBA outline_color, fg_color;
1578 double vertical_overshoot;
1581 double interp; /* interpolation factor for center position */
1582 double x_double_horz, y_double_horz;
1583 double x_double_vert, y_double_vert;
1584 double x_double, y_double;
1587 gboolean running, is_rtl;
1591 flags = gtk_theming_engine_get_state (engine);
1593 gtk_theming_engine_get_color (engine, flags, &fg_color);
1594 gtk_theming_engine_get_border_color (engine, flags, &outline_color);
1596 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress);
1597 is_rtl = (gtk_theming_engine_get_direction (engine) == GTK_TEXT_DIR_RTL);
1601 progress = (flags & GTK_STATE_FLAG_ACTIVE) ? 1 : 0;
1603 if (!gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_HORIZONTAL))
1606 angle = (G_PI) - ((G_PI / 2) * progress);
1608 angle = (G_PI / 2) * progress;
1613 angle = (G_PI / 2) + ((G_PI / 2) * progress);
1615 angle = (G_PI / 2) - ((G_PI / 2) * progress);
1620 /* Compute distance that the stroke extends beyonds the end
1621 * of the triangle we draw.
1623 vertical_overshoot = line_width / 2.0 * (1. / tan (G_PI / 8));
1625 /* For odd line widths, we end the vertical line of the triangle
1626 * at a half pixel, so we round differently.
1628 if (line_width % 2 == 1)
1629 vertical_overshoot = ceil (0.5 + vertical_overshoot) - 0.5;
1631 vertical_overshoot = ceil (vertical_overshoot);
1633 /* Adjust the size of the triangle we draw so that the entire stroke fits
1635 diameter = (gint) MAX (3, width - 2 * vertical_overshoot);
1637 /* If the line width is odd, we want the diameter to be even,
1638 * and vice versa, so force the sum to be odd. This relationship
1639 * makes the point of the triangle look right.
1641 diameter -= (1 - (diameter + line_width) % 2);
1643 radius = diameter / 2.;
1645 /* Adjust the center so that the stroke is properly aligned with
1646 * the pixel grid. The center adjustment is different for the
1647 * horizontal and vertical orientations. For intermediate positions
1648 * we interpolate between the two.
1650 x_double_vert = floor ((x + width / 2) - (radius + line_width) / 2.) + (radius + line_width) / 2.;
1651 y_double_vert = (y + height / 2) - 0.5;
1653 x_double_horz = (x + width / 2) - 0.5;
1654 y_double_horz = floor ((y + height / 2) - (radius + line_width) / 2.) + (radius + line_width) / 2.;
1656 x_double = x_double_vert * (1 - interp) + x_double_horz * interp;
1657 y_double = y_double_vert * (1 - interp) + y_double_horz * interp;
1659 cairo_translate (cr, x_double, y_double);
1660 cairo_rotate (cr, angle);
1662 cairo_move_to (cr, - radius / 2., - radius);
1663 cairo_line_to (cr, radius / 2., 0);
1664 cairo_line_to (cr, - radius / 2., radius);
1665 cairo_close_path (cr);
1667 cairo_set_line_width (cr, line_width);
1669 gdk_cairo_set_source_rgba (cr, &fg_color);
1671 cairo_fill_preserve (cr);
1673 gdk_cairo_set_source_rgba (cr, &outline_color);
1680 gtk_theming_engine_render_focus (GtkThemingEngine *engine,
1687 GtkStateFlags flags;
1693 flags = gtk_theming_engine_get_state (engine);
1695 gtk_theming_engine_get_color (engine, flags, &color);
1697 gtk_theming_engine_get_style (engine,
1698 "focus-line-width", &line_width,
1699 "focus-line-pattern", (gchar *) &dash_list,
1702 cairo_set_line_width (cr, (gdouble) line_width);
1706 gint n_dashes = strlen ((const gchar *) dash_list);
1707 gdouble *dashes = g_new (gdouble, n_dashes);
1708 gdouble total_length = 0;
1709 gdouble dash_offset;
1712 for (i = 0; i < n_dashes; i++)
1714 dashes[i] = dash_list[i];
1715 total_length += dash_list[i];
1718 /* The dash offset here aligns the pattern to integer pixels
1719 * by starting the dash at the right side of the left border
1720 * Negative dash offsets in cairo don't work
1721 * (https://bugs.freedesktop.org/show_bug.cgi?id=2729)
1723 dash_offset = - line_width / 2.;
1725 while (dash_offset < 0)
1726 dash_offset += total_length;
1728 cairo_set_dash (cr, dashes, n_dashes, dash_offset);
1732 cairo_rectangle (cr,
1733 x + line_width / 2.,
1734 y + line_width / 2.,
1736 height - line_width);
1738 gdk_cairo_set_source_rgba (cr, &color);
1747 gtk_theming_engine_render_line (GtkThemingEngine *engine,
1755 GtkStateFlags flags;
1757 flags = gtk_theming_engine_get_state (engine);
1760 gtk_theming_engine_get_color (engine, flags, &color);
1762 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
1763 cairo_set_line_width (cr, 1);
1765 cairo_move_to (cr, x0 + 0.5, y0 + 0.5);
1766 cairo_line_to (cr, x1 + 0.5, y1 + 0.5);
1768 gdk_cairo_set_source_rgba (cr, &color);
1775 prepare_context_for_layout (cairo_t *cr,
1778 PangoLayout *layout)
1780 const PangoMatrix *matrix;
1782 matrix = pango_context_get_matrix (pango_layout_get_context (layout));
1784 cairo_move_to (cr, x, y);
1788 cairo_matrix_t cairo_matrix;
1790 cairo_matrix_init (&cairo_matrix,
1791 matrix->xx, matrix->yx,
1792 matrix->xy, matrix->yy,
1793 matrix->x0, matrix->y0);
1795 cairo_transform (cr, &cairo_matrix);
1800 gtk_theming_engine_render_layout (GtkThemingEngine *engine,
1804 PangoLayout *layout)
1807 GtkShadow *text_shadow = NULL;
1808 GtkStateFlags flags;
1813 flags = gtk_theming_engine_get_state (engine);
1814 gtk_theming_engine_get_color (engine, flags, &fg_color);
1816 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
1820 GtkStateFlags other_flags;
1823 if (flags & GTK_STATE_FLAG_PRELIGHT)
1825 other_flags = flags & ~(GTK_STATE_FLAG_PRELIGHT);
1826 progress = 1 - progress;
1829 other_flags = flags | GTK_STATE_FLAG_PRELIGHT;
1831 gtk_theming_engine_get_color (engine, other_flags, &other_fg);
1833 fg_color.red = CLAMP (fg_color.red + ((other_fg.red - fg_color.red) * progress), 0, 1);
1834 fg_color.green = CLAMP (fg_color.green + ((other_fg.green - fg_color.green) * progress), 0, 1);
1835 fg_color.blue = CLAMP (fg_color.blue + ((other_fg.blue - fg_color.blue) * progress), 0, 1);
1836 fg_color.alpha = CLAMP (fg_color.alpha + ((other_fg.alpha - fg_color.alpha) * progress), 0, 1);
1839 gtk_theming_engine_get (engine, flags,
1840 "text-shadow", &text_shadow,
1843 prepare_context_for_layout (cr, x, y, layout);
1845 if (text_shadow != NULL)
1847 _gtk_text_shadow_paint_layout (text_shadow, cr, layout);
1848 _gtk_shadow_unref (text_shadow);
1851 gdk_cairo_set_source_rgba (cr, &fg_color);
1852 pango_cairo_show_layout (cr, layout);
1858 gtk_theming_engine_render_slider (GtkThemingEngine *engine,
1864 GtkOrientation orientation)
1866 const GtkWidgetPath *path;
1869 path = gtk_theming_engine_get_path (engine);
1871 gtk_theming_engine_render_background (engine, cr, x, y, width, height);
1872 gtk_theming_engine_render_frame (engine, cr, x, y, width, height);
1874 /* FIXME: thickness */
1877 if (gtk_widget_path_is_type (path, GTK_TYPE_SCALE))
1879 if (orientation == GTK_ORIENTATION_VERTICAL)
1880 gtk_theming_engine_render_line (engine, cr,
1882 y + (gint) height / 2,
1883 x + width - thickness - 1,
1884 y + (gint) height / 2);
1886 gtk_theming_engine_render_line (engine, cr,
1887 x + (gint) width / 2,
1889 x + (gint) width / 2,
1890 y + height - thickness - 1);
1895 gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
1901 GtkPositionType gap_side,
1905 GtkJunctionSides junction;
1906 GtkStateFlags state;
1908 GtkCssBorderCornerRadius *top_left_radius, *top_right_radius;
1909 GtkCssBorderCornerRadius *bottom_left_radius, *bottom_right_radius;
1910 gdouble x0, y0, x1, y1, xc, yc, wc, hc;
1911 GtkBorderImage border_image;
1914 xc = yc = wc = hc = 0;
1915 state = gtk_theming_engine_get_state (engine);
1916 junction = gtk_theming_engine_get_junction_sides (engine);
1918 gtk_theming_engine_get_border (engine, state, &border);
1919 gtk_theming_engine_get (engine, state,
1920 "border-top-left-radius", &top_left_radius,
1921 "border-top-right-radius", &top_right_radius,
1922 "border-bottom-right-radius", &bottom_right_radius,
1923 "border-bottom-left-radius", &bottom_left_radius,
1926 border_width = MIN (MIN (border.top, border.bottom),
1927 MIN (border.left, border.right));
1934 xc = x + xy0_gap + border_width;
1936 wc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
1939 if (xy0_gap < top_left_radius->horizontal)
1940 junction |= GTK_JUNCTION_CORNER_TOPLEFT;
1942 if (xy1_gap > width - top_right_radius->horizontal)
1943 junction |= GTK_JUNCTION_CORNER_TOPRIGHT;
1945 case GTK_POS_BOTTOM:
1946 xc = x + xy0_gap + border_width;
1947 yc = y + height - border_width;
1948 wc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
1951 if (xy0_gap < bottom_left_radius->horizontal)
1952 junction |= GTK_JUNCTION_CORNER_BOTTOMLEFT;
1954 if (xy1_gap > width - bottom_right_radius->horizontal)
1955 junction |= GTK_JUNCTION_CORNER_BOTTOMRIGHT;
1960 yc = y + xy0_gap + border_width;
1962 hc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
1964 if (xy0_gap < top_left_radius->vertical)
1965 junction |= GTK_JUNCTION_CORNER_TOPLEFT;
1967 if (xy1_gap > height - bottom_left_radius->vertical)
1968 junction |= GTK_JUNCTION_CORNER_BOTTOMLEFT;
1972 xc = x + width - border_width;
1973 yc = y + xy0_gap + border_width;
1975 hc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
1977 if (xy0_gap < top_right_radius->vertical)
1978 junction |= GTK_JUNCTION_CORNER_TOPRIGHT;
1980 if (xy1_gap > height - bottom_right_radius->vertical)
1981 junction |= GTK_JUNCTION_CORNER_BOTTOMRIGHT;
1986 cairo_clip_extents (cr, &x0, &y0, &x1, &y1);
1987 cairo_rectangle (cr, x0, y0, x1 - x0, yc - y0);
1988 cairo_rectangle (cr, x0, yc, xc - x0, hc);
1989 cairo_rectangle (cr, xc + wc, yc, x1 - (xc + wc), hc);
1990 cairo_rectangle (cr, x0, yc + hc, x1 - x0, y1 - (yc + hc));
1993 if (_gtk_border_image_init (&border_image, engine))
1994 _gtk_border_image_render (&border_image, &border,
1995 cr, x, y, width, height);
1997 render_frame_internal (engine, cr,
1998 x, y, width, height,
2003 g_free (top_left_radius);
2004 g_free (top_right_radius);
2005 g_free (bottom_right_radius);
2006 g_free (bottom_left_radius);
2010 gtk_theming_engine_render_extension (GtkThemingEngine *engine,
2016 GtkPositionType gap_side)
2018 GtkThemingBackground bg;
2019 GtkJunctionSides junction = 0;
2020 guint hidden_side = 0;
2027 junction = GTK_JUNCTION_LEFT;
2028 hidden_side = SIDE_LEFT;
2030 cairo_translate (cr, x + width, y);
2031 cairo_rotate (cr, G_PI / 2);
2034 junction = GTK_JUNCTION_RIGHT;
2035 hidden_side = SIDE_RIGHT;
2037 cairo_translate (cr, x, y + height);
2038 cairo_rotate (cr, - G_PI / 2);
2041 junction = GTK_JUNCTION_TOP;
2042 hidden_side = SIDE_TOP;
2044 cairo_translate (cr, x + width, y + height);
2045 cairo_rotate (cr, G_PI);
2047 case GTK_POS_BOTTOM:
2048 junction = GTK_JUNCTION_BOTTOM;
2049 hidden_side = SIDE_BOTTOM;
2051 cairo_translate (cr, x, y);
2055 if (gap_side == GTK_POS_TOP ||
2056 gap_side == GTK_POS_BOTTOM)
2057 _gtk_theming_background_init (&bg, engine,
2060 GTK_JUNCTION_BOTTOM);
2062 _gtk_theming_background_init (&bg, engine,
2065 GTK_JUNCTION_BOTTOM);
2067 _gtk_theming_background_render (&bg, cr);
2073 render_frame_internal (engine, cr,
2074 x, y, width, height,
2075 hidden_side, junction);
2081 render_dot (cairo_t *cr,
2082 const GdkRGBA *lighter,
2083 const GdkRGBA *darker,
2088 size = CLAMP ((gint) size, 2, 3);
2092 gdk_cairo_set_source_rgba (cr, lighter);
2093 cairo_rectangle (cr, x, y, 1, 1);
2094 cairo_rectangle (cr, x + 1, y + 1, 1, 1);
2099 gdk_cairo_set_source_rgba (cr, lighter);
2100 cairo_rectangle (cr, x, y, 2, 1);
2101 cairo_rectangle (cr, x, y, 1, 2);
2104 gdk_cairo_set_source_rgba (cr, darker);
2105 cairo_rectangle (cr, x + 1, y + 1, 2, 1);
2106 cairo_rectangle (cr, x + 2, y, 1, 2);
2112 gtk_theming_engine_render_handle (GtkThemingEngine *engine,
2119 GtkStateFlags flags;
2120 GdkRGBA bg_color, lighter, darker;
2121 GtkJunctionSides sides;
2122 GtkThemingBackground bg;
2126 flags = gtk_theming_engine_get_state (engine);
2128 cairo_set_line_width (cr, 1.0);
2129 sides = gtk_theming_engine_get_junction_sides (engine);
2130 gtk_theming_engine_get_background_color (engine, flags, &bg_color);
2132 color_shade (&bg_color, 0.7, &darker);
2133 color_shade (&bg_color, 1.3, &lighter);
2135 _gtk_theming_background_init (&bg, engine, x, y, width, height, sides);
2136 _gtk_theming_background_render (&bg, cr);
2138 if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_GRIP))
2140 /* reduce confusing values to a meaningful state */
2141 if ((sides & (GTK_JUNCTION_CORNER_TOPLEFT | GTK_JUNCTION_CORNER_BOTTOMRIGHT)) == (GTK_JUNCTION_CORNER_TOPLEFT | GTK_JUNCTION_CORNER_BOTTOMRIGHT))
2142 sides &= ~GTK_JUNCTION_CORNER_TOPLEFT;
2144 if ((sides & (GTK_JUNCTION_CORNER_TOPRIGHT | GTK_JUNCTION_CORNER_BOTTOMLEFT)) == (GTK_JUNCTION_CORNER_TOPRIGHT | GTK_JUNCTION_CORNER_BOTTOMLEFT))
2145 sides &= ~GTK_JUNCTION_CORNER_TOPRIGHT;
2148 sides = GTK_JUNCTION_CORNER_BOTTOMRIGHT;
2150 /* align drawing area to the connected side */
2151 if (sides == GTK_JUNCTION_LEFT)
2156 else if (sides == GTK_JUNCTION_CORNER_TOPLEFT)
2160 else if (height < width)
2163 else if (sides == GTK_JUNCTION_CORNER_BOTTOMLEFT)
2165 /* make it square, aligning to bottom left */
2168 y += (height - width);
2171 else if (height < width)
2174 else if (sides == GTK_JUNCTION_RIGHT)
2176 /* aligning to right */
2179 x += (width - height);
2183 else if (sides == GTK_JUNCTION_CORNER_TOPRIGHT)
2187 else if (height < width)
2189 x += (width - height);
2193 else if (sides == GTK_JUNCTION_CORNER_BOTTOMRIGHT)
2195 /* make it square, aligning to bottom right */
2198 y += (height - width);
2201 else if (height < width)
2203 x += (width - height);
2207 else if (sides == GTK_JUNCTION_TOP)
2212 else if (sides == GTK_JUNCTION_BOTTOM)
2214 /* align to bottom */
2217 y += (height - width);
2222 g_assert_not_reached ();
2224 if (sides == GTK_JUNCTION_LEFT ||
2225 sides == GTK_JUNCTION_RIGHT)
2231 while (xi < x + width)
2233 gdk_cairo_set_source_rgba (cr, &lighter);
2234 add_path_line (cr, x, y, x, y + height);
2238 gdk_cairo_set_source_rgba (cr, &darker);
2239 add_path_line (cr, xi, y, xi, y + height);
2244 else if (sides == GTK_JUNCTION_TOP ||
2245 sides == GTK_JUNCTION_BOTTOM)
2251 while (yi < y + height)
2253 gdk_cairo_set_source_rgba (cr, &lighter);
2254 add_path_line (cr, x, yi, x + width, yi);
2258 gdk_cairo_set_source_rgba (cr, &darker);
2259 add_path_line (cr, x, yi, x + width, yi);
2264 else if (sides == GTK_JUNCTION_CORNER_TOPLEFT)
2273 gdk_cairo_set_source_rgba (cr, &darker);
2274 add_path_line (cr, xi, y, x, yi);
2280 add_path_line (cr, xi, y, x, yi);
2286 gdk_cairo_set_source_rgba (cr, &lighter);
2287 add_path_line (cr, xi, y, x, yi);
2294 else if (sides == GTK_JUNCTION_CORNER_TOPRIGHT)
2301 while (xi < (x + width - 3))
2303 gdk_cairo_set_source_rgba (cr, &lighter);
2304 add_path_line (cr, xi, y, x + width, yi);
2310 gdk_cairo_set_source_rgba (cr, &darker);
2311 add_path_line (cr, xi, y, x + width, yi);
2317 add_path_line (cr, xi, y, x + width, yi);
2324 else if (sides == GTK_JUNCTION_CORNER_BOTTOMLEFT)
2333 gdk_cairo_set_source_rgba (cr, &darker);
2334 add_path_line (cr, x, yi, xi, y + height);
2340 add_path_line (cr, x, yi, xi, y + height);
2346 gdk_cairo_set_source_rgba (cr, &lighter);
2347 add_path_line (cr, x, yi, xi, y + height);
2354 else if (sides == GTK_JUNCTION_CORNER_BOTTOMRIGHT)
2361 while (xi < (x + width - 3))
2363 gdk_cairo_set_source_rgba (cr, &lighter);
2364 add_path_line (cr, xi, y + height, x + width, yi);
2370 gdk_cairo_set_source_rgba (cr, &darker);
2371 add_path_line (cr, xi, y + height, x + width, yi);
2377 add_path_line (cr, xi, y + height, x + width, yi);
2385 else if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_PANE_SEPARATOR))
2388 for (xx = x + width / 2 - 15; xx <= x + width / 2 + 15; xx += 5)
2389 render_dot (cr, &lighter, &darker, xx, y + height / 2 - 1, 3);
2391 for (yy = y + height / 2 - 15; yy <= y + height / 2 + 15; yy += 5)
2392 render_dot (cr, &lighter, &darker, x + width / 2 - 1, yy, 3);
2396 for (yy = y; yy < y + height; yy += 3)
2397 for (xx = x; xx < x + width; xx += 6)
2399 render_dot (cr, &lighter, &darker, xx, yy, 2);
2400 render_dot (cr, &lighter, &darker, xx + 3, yy + 1, 2);
2408 _gtk_theming_engine_paint_spinner (cairo_t *cr,
2413 guint num_steps, step;
2420 step = (guint) (progress * num_steps);
2426 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
2427 cairo_set_line_width (cr, 2.0);
2429 half = num_steps / 2;
2431 for (i = 0; i < num_steps; i++)
2433 gint inset = 0.7 * radius;
2435 /* transparency is a function of time and intial value */
2436 gdouble t = 1.0 - (gdouble) ((i + step) % num_steps) / num_steps;
2437 gdouble xscale = - sin (i * G_PI / half);
2438 gdouble yscale = - cos (i * G_PI / half);
2440 cairo_set_source_rgba (cr,
2447 (radius - inset) * xscale,
2448 (radius - inset) * yscale);
2460 render_spinner (GtkThemingEngine *engine,
2467 GtkStateFlags state;
2473 state = gtk_theming_engine_get_state (engine);
2475 if (!gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress))
2478 radius = MIN (width / 2, height / 2);
2480 gtk_theming_engine_get_color (engine, state, &color);
2481 gtk_theming_engine_get (engine, state,
2482 "icon-shadow", &shadow,
2486 cairo_translate (cr, x + width / 2, y + height / 2);
2490 _gtk_icon_shadow_paint_spinner (shadow, cr,
2493 _gtk_shadow_unref (shadow);
2496 _gtk_theming_engine_paint_spinner (cr,
2505 gtk_theming_engine_render_activity (GtkThemingEngine *engine,
2512 if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_SPINNER))
2514 render_spinner (engine, cr, x, y, width, height);
2518 gtk_theming_engine_render_background (engine, cr, x, y, width, height);
2519 gtk_theming_engine_render_frame (engine, cr, x, y, width, height);
2524 scale_or_ref (GdkPixbuf *src,
2528 if (width == gdk_pixbuf_get_width (src) &&
2529 height == gdk_pixbuf_get_height (src))
2530 return g_object_ref (src);
2532 return gdk_pixbuf_scale_simple (src,
2534 GDK_INTERP_BILINEAR);
2538 lookup_icon_size (GtkThemingEngine *engine,
2544 GtkSettings *settings;
2546 screen = gtk_theming_engine_get_screen (engine);
2547 settings = gtk_settings_get_for_screen (screen);
2549 return gtk_icon_size_lookup_for_settings (settings, size, width, height);
2553 colorshift_source (cairo_t *cr,
2556 cairo_pattern_t *source;
2561 source = cairo_pattern_reference (cairo_get_source (cr));
2563 cairo_set_source_rgb (cr, shift, shift, shift);
2564 cairo_set_operator (cr, CAIRO_OPERATOR_COLOR_DODGE);
2566 cairo_mask (cr, source);
2568 cairo_pattern_destroy (source);
2573 gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine *engine,
2574 const GtkIconSource *source,
2579 GdkPixbuf *base_pixbuf;
2580 GtkStateFlags state;
2584 cairo_surface_t *surface;
2586 base_pixbuf = gtk_icon_source_get_pixbuf (source);
2587 state = gtk_theming_engine_get_state (engine);
2589 g_return_val_if_fail (base_pixbuf != NULL, NULL);
2591 if (size != (GtkIconSize) -1 &&
2592 !lookup_icon_size (engine, size, &width, &height))
2594 g_warning (G_STRLOC ": invalid icon size '%d'", size);
2598 /* If the size was wildcarded, and we're allowed to scale, then scale; otherwise,
2601 if (size != (GtkIconSize) -1 &&
2602 gtk_icon_source_get_size_wildcarded (source))
2603 scaled = scale_or_ref (base_pixbuf, width, height);
2605 scaled = g_object_ref (base_pixbuf);
2607 /* If the state was wildcarded, then generate a state. */
2608 if (gtk_icon_source_get_state_wildcarded (source))
2610 if (state & GTK_STATE_FLAG_INSENSITIVE)
2612 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
2613 gdk_pixbuf_get_width (scaled),
2614 gdk_pixbuf_get_height (scaled));
2615 cr = cairo_create (surface);
2616 gdk_cairo_set_source_pixbuf (cr, scaled, 0, 0);
2617 cairo_paint_with_alpha (cr, 0.5);
2621 g_object_unref (scaled);
2622 stated = gdk_pixbuf_get_from_surface (surface, 0, 0,
2623 cairo_image_surface_get_width (surface),
2624 cairo_image_surface_get_height (surface));
2625 cairo_surface_destroy (surface);
2627 else if (state & GTK_STATE_FLAG_PRELIGHT)
2629 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
2630 gdk_pixbuf_get_width (scaled),
2631 gdk_pixbuf_get_height (scaled));
2633 cr = cairo_create (surface);
2634 gdk_cairo_set_source_pixbuf (cr, scaled, 0, 0);
2635 colorshift_source (cr, 0.10);
2639 g_object_unref (scaled);
2640 stated = gdk_pixbuf_get_from_surface (surface, 0, 0,
2641 cairo_image_surface_get_width (surface),
2642 cairo_image_surface_get_height (surface));
2643 cairo_surface_destroy (surface);
2655 gtk_theming_engine_render_icon (GtkThemingEngine *engine,
2661 GtkStateFlags state;
2662 GtkShadow *icon_shadow;
2664 state = gtk_theming_engine_get_state (engine);
2668 gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
2670 gtk_theming_engine_get (engine, state,
2671 "icon-shadow", &icon_shadow,
2674 if (icon_shadow != NULL)
2676 _gtk_icon_shadow_paint (icon_shadow, cr);
2677 _gtk_shadow_unref (icon_shadow);