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.
65 struct GtkThemingEnginePrivate
67 GtkStyleContext *context;
71 #define GTK_THEMING_ENGINE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_THEMING_ENGINE, GtkThemingEnginePrivate))
73 static void gtk_theming_engine_finalize (GObject *object);
74 static void gtk_theming_engine_impl_set_property (GObject *object,
78 static void gtk_theming_engine_impl_get_property (GObject *object,
83 static void gtk_theming_engine_render_check (GtkThemingEngine *engine,
89 static void gtk_theming_engine_render_option (GtkThemingEngine *engine,
95 static void gtk_theming_engine_render_arrow (GtkThemingEngine *engine,
101 static void gtk_theming_engine_render_background (GtkThemingEngine *engine,
107 static void gtk_theming_engine_render_frame (GtkThemingEngine *engine,
113 static void gtk_theming_engine_render_expander (GtkThemingEngine *engine,
119 static void gtk_theming_engine_render_focus (GtkThemingEngine *engine,
125 static void gtk_theming_engine_render_layout (GtkThemingEngine *engine,
129 PangoLayout *layout);
130 static void gtk_theming_engine_render_line (GtkThemingEngine *engine,
136 static void gtk_theming_engine_render_slider (GtkThemingEngine *engine,
142 GtkOrientation orientation);
143 static void gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
149 GtkPositionType gap_side,
152 static void gtk_theming_engine_render_extension (GtkThemingEngine *engine,
158 GtkPositionType gap_side);
159 static void gtk_theming_engine_render_handle (GtkThemingEngine *engine,
165 static void gtk_theming_engine_render_activity (GtkThemingEngine *engine,
171 static GdkPixbuf * gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine *engine,
172 const GtkIconSource *source,
174 static void gtk_theming_engine_render_icon (GtkThemingEngine *engine,
180 G_DEFINE_TYPE (GtkThemingEngine, gtk_theming_engine, G_TYPE_OBJECT)
183 typedef struct GtkThemingModule GtkThemingModule;
184 typedef struct GtkThemingModuleClass GtkThemingModuleClass;
186 struct GtkThemingModule
188 GTypeModule parent_instance;
192 void (*init) (GTypeModule *module);
194 GtkThemingEngine * (*create_engine) (void);
197 struct GtkThemingModuleClass
199 GTypeModuleClass parent_class;
202 #define GTK_TYPE_THEMING_MODULE (gtk_theming_module_get_type ())
203 #define GTK_THEMING_MODULE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_THEMING_MODULE, GtkThemingModule))
204 #define GTK_IS_THEMING_MODULE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_THEMING_MODULE))
206 G_DEFINE_TYPE (GtkThemingModule, gtk_theming_module, G_TYPE_TYPE_MODULE);
209 gtk_theming_engine_class_init (GtkThemingEngineClass *klass)
211 GObjectClass *object_class = G_OBJECT_CLASS (klass);
213 object_class->finalize = gtk_theming_engine_finalize;
214 object_class->set_property = gtk_theming_engine_impl_set_property;
215 object_class->get_property = gtk_theming_engine_impl_get_property;
217 klass->render_icon = gtk_theming_engine_render_icon;
218 klass->render_check = gtk_theming_engine_render_check;
219 klass->render_option = gtk_theming_engine_render_option;
220 klass->render_arrow = gtk_theming_engine_render_arrow;
221 klass->render_background = gtk_theming_engine_render_background;
222 klass->render_frame = gtk_theming_engine_render_frame;
223 klass->render_expander = gtk_theming_engine_render_expander;
224 klass->render_focus = gtk_theming_engine_render_focus;
225 klass->render_layout = gtk_theming_engine_render_layout;
226 klass->render_line = gtk_theming_engine_render_line;
227 klass->render_slider = gtk_theming_engine_render_slider;
228 klass->render_frame_gap = gtk_theming_engine_render_frame_gap;
229 klass->render_extension = gtk_theming_engine_render_extension;
230 klass->render_handle = gtk_theming_engine_render_handle;
231 klass->render_activity = gtk_theming_engine_render_activity;
232 klass->render_icon_pixbuf = gtk_theming_engine_render_icon_pixbuf;
235 * GtkThemingEngine:name:
237 * The theming engine name, this name will be used when registering
238 * custom properties, for a theming engine named "Clearlooks" registering
239 * a "glossy" custom property, it could be referenced in the CSS file as
242 * -Clearlooks-glossy: true;
247 g_object_class_install_property (object_class,
249 g_param_spec_string ("name",
251 P_("Theming engine name"),
253 G_PARAM_CONSTRUCT_ONLY | GTK_PARAM_READWRITE));
255 g_type_class_add_private (object_class, sizeof (GtkThemingEnginePrivate));
259 gtk_theming_engine_init (GtkThemingEngine *engine)
261 engine->priv = GTK_THEMING_ENGINE_GET_PRIVATE (engine);
265 gtk_theming_engine_finalize (GObject *object)
267 GtkThemingEnginePrivate *priv;
269 priv = GTK_THEMING_ENGINE (object)->priv;
272 G_OBJECT_GET_CLASS (gtk_theming_engine_parent_class)->finalize (object);
276 gtk_theming_engine_impl_set_property (GObject *object,
281 GtkThemingEnginePrivate *priv;
283 priv = GTK_THEMING_ENGINE (object)->priv;
291 priv->name = g_value_dup_string (value);
294 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
300 gtk_theming_engine_impl_get_property (GObject *object,
305 GtkThemingEnginePrivate *priv;
307 priv = GTK_THEMING_ENGINE (object)->priv;
312 g_value_set_string (value, priv->name);
315 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
321 _gtk_theming_engine_set_context (GtkThemingEngine *engine,
322 GtkStyleContext *context)
324 GtkThemingEnginePrivate *priv;
326 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
327 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
330 priv->context = context;
334 _gtk_theming_engine_peek_property (GtkThemingEngine *engine,
335 const char *property_name)
337 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
338 g_return_val_if_fail (property_name != NULL, NULL);
340 return _gtk_style_context_peek_property (engine->priv->context, property_name);
344 _gtk_theming_engine_get_number (GtkThemingEngine *engine,
345 const char *property_name,
346 double one_hundred_percent)
348 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), 0.0);
349 g_return_val_if_fail (property_name != NULL, 0.0);
351 return _gtk_style_context_get_number (engine->priv->context, property_name, one_hundred_percent);
355 * gtk_theming_engine_get_property:
356 * @engine: a #GtkThemingEngine
357 * @property: the property name
358 * @state: state to retrieve the value for
359 * @value: (out) (transfer full): return location for the property value,
360 * you must free this memory using g_value_unset() once you are
363 * Gets a property value as retrieved from the style settings that apply
364 * to the currently rendered element.
369 gtk_theming_engine_get_property (GtkThemingEngine *engine,
370 const gchar *property,
374 GtkThemingEnginePrivate *priv;
376 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
377 g_return_if_fail (property != NULL);
378 g_return_if_fail (value != NULL);
381 gtk_style_context_get_property (priv->context, property, state, value);
385 * gtk_theming_engine_get_valist:
386 * @engine: a #GtkThemingEngine
387 * @state: state to retrieve values for
388 * @args: va_list of property name/return location pairs, followed by %NULL
390 * Retrieves several style property values that apply to the currently
396 gtk_theming_engine_get_valist (GtkThemingEngine *engine,
400 GtkThemingEnginePrivate *priv;
402 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
405 gtk_style_context_get_valist (priv->context, state, args);
409 * gtk_theming_engine_get:
410 * @engine: a #GtkThemingEngine
411 * @state: state to retrieve values for
412 * @...: property name /return value pairs, followed by %NULL
414 * Retrieves several style property values that apply to the currently
420 gtk_theming_engine_get (GtkThemingEngine *engine,
424 GtkThemingEnginePrivate *priv;
427 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
431 va_start (args, state);
432 gtk_style_context_get_valist (priv->context, state, args);
437 * gtk_theming_engine_get_style_property:
438 * @engine: a #GtkThemingEngine
439 * @property_name: the name of the widget style property
440 * @value: Return location for the property value, free with
441 * g_value_unset() after use.
443 * Gets the value for a widget style property.
448 gtk_theming_engine_get_style_property (GtkThemingEngine *engine,
449 const gchar *property_name,
452 GtkThemingEnginePrivate *priv;
454 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
455 g_return_if_fail (property_name != NULL);
458 gtk_style_context_get_style_property (priv->context, property_name, value);
462 * gtk_theming_engine_get_style_valist:
463 * @engine: a #GtkThemingEngine
464 * @args: va_list of property name/return location pairs, followed by %NULL
466 * Retrieves several widget style properties from @engine according to the
467 * currently rendered content's style.
472 gtk_theming_engine_get_style_valist (GtkThemingEngine *engine,
475 GtkThemingEnginePrivate *priv;
477 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
480 gtk_style_context_get_style_valist (priv->context, args);
484 * gtk_theming_engine_get_style:
485 * @engine: a #GtkThemingEngine
486 * @...: property name /return value pairs, followed by %NULL
488 * Retrieves several widget style properties from @engine according
489 * to the currently rendered content's style.
494 gtk_theming_engine_get_style (GtkThemingEngine *engine,
497 GtkThemingEnginePrivate *priv;
500 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
504 va_start (args, engine);
505 gtk_style_context_get_style_valist (priv->context, args);
510 * gtk_theming_engine_lookup_color:
511 * @engine: a #GtkThemingEngine
512 * @color_name: color name to lookup
513 * @color: (out): Return location for the looked up color
515 * Looks up and resolves a color name in the current style's color map.
517 * Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
520 gtk_theming_engine_lookup_color (GtkThemingEngine *engine,
521 const gchar *color_name,
524 GtkThemingEnginePrivate *priv;
526 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
527 g_return_val_if_fail (color_name != NULL, FALSE);
530 return gtk_style_context_lookup_color (priv->context, color_name, color);
534 * gtk_theming_engine_get_state:
535 * @engine: a #GtkThemingEngine
537 * returns the state used when rendering.
539 * Returns: the state flags
544 gtk_theming_engine_get_state (GtkThemingEngine *engine)
546 GtkThemingEnginePrivate *priv;
548 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), 0);
551 return gtk_style_context_get_state (priv->context);
555 * gtk_theming_engine_state_is_running:
556 * @engine: a #GtkThemingEngine
557 * @state: a widget state
558 * @progress: (out): return location for the transition progress
560 * Returns %TRUE if there is a transition animation running for the
561 * current region (see gtk_style_context_push_animatable_region()).
563 * If @progress is not %NULL, the animation progress will be returned
564 * there, 0.0 means the state is closest to being %FALSE, while 1.0 means
565 * it's closest to being %TRUE. This means transition animations will
566 * run from 0 to 1 when @state is being set to %TRUE and from 1 to 0 when
567 * it's being set to %FALSE.
569 * Returns: %TRUE if there is a running transition animation for @state.
574 gtk_theming_engine_state_is_running (GtkThemingEngine *engine,
578 GtkThemingEnginePrivate *priv;
580 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
583 return gtk_style_context_state_is_running (priv->context, state, progress);
587 * gtk_theming_engine_get_path:
588 * @engine: a #GtkThemingEngine
590 * Returns the widget path used for style matching.
592 * Returns: (transfer none): A #GtkWidgetPath
596 const GtkWidgetPath *
597 gtk_theming_engine_get_path (GtkThemingEngine *engine)
599 GtkThemingEnginePrivate *priv;
601 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
604 return gtk_style_context_get_path (priv->context);
608 * gtk_theming_engine_has_class:
609 * @engine: a #GtkThemingEngine
610 * @style_class: class name to look up
612 * Returns %TRUE if the currently rendered contents have
613 * defined the given class name.
615 * Returns: %TRUE if @engine has @class_name defined
620 gtk_theming_engine_has_class (GtkThemingEngine *engine,
621 const gchar *style_class)
623 GtkThemingEnginePrivate *priv;
625 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
628 return gtk_style_context_has_class (priv->context, style_class);
632 * gtk_theming_engine_has_region:
633 * @engine: a #GtkThemingEngine
634 * @style_region: a region name
635 * @flags: (out) (allow-none): return location for region flags
637 * Returns %TRUE if the currently rendered contents have the
638 * region defined. If @flags_return is not %NULL, it is set
639 * to the flags affecting the region.
641 * Returns: %TRUE if region is defined
646 gtk_theming_engine_has_region (GtkThemingEngine *engine,
647 const gchar *style_region,
648 GtkRegionFlags *flags)
650 GtkThemingEnginePrivate *priv;
655 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
658 return gtk_style_context_has_region (priv->context, style_region, flags);
662 * gtk_theming_engine_get_direction:
663 * @engine: a #GtkThemingEngine
665 * Returns the widget direction used for rendering.
667 * Returns: the widget direction
672 gtk_theming_engine_get_direction (GtkThemingEngine *engine)
674 GtkThemingEnginePrivate *priv;
676 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), GTK_TEXT_DIR_LTR);
679 return gtk_style_context_get_direction (priv->context);
683 * gtk_theming_engine_get_junction_sides:
684 * @engine: a #GtkThemingEngine
686 * Returns the widget direction used for rendering.
688 * Returns: the widget direction
693 gtk_theming_engine_get_junction_sides (GtkThemingEngine *engine)
695 GtkThemingEnginePrivate *priv;
697 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), 0);
700 return gtk_style_context_get_junction_sides (priv->context);
704 * gtk_theming_engine_get_color:
705 * @engine: a #GtkThemingEngine
706 * @state: state to retrieve the color for
707 * @color: (out): return value for the foreground color
709 * Gets the foreground color for a given state.
714 gtk_theming_engine_get_color (GtkThemingEngine *engine,
718 GtkThemingEnginePrivate *priv;
720 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
723 gtk_style_context_get_color (priv->context, state, color);
727 * gtk_theming_engine_get_background_color:
728 * @engine: a #GtkThemingEngine
729 * @state: state to retrieve the color for
730 * @color: (out): return value for the background color
732 * Gets the background color for a given state.
737 gtk_theming_engine_get_background_color (GtkThemingEngine *engine,
741 GtkThemingEnginePrivate *priv;
743 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
746 gtk_style_context_get_background_color (priv->context, state, color);
750 * gtk_theming_engine_get_border_color:
751 * @engine: a #GtkThemingEngine
752 * @state: state to retrieve the color for
753 * @color: (out): return value for the border color
755 * Gets the border color for a given state.
760 gtk_theming_engine_get_border_color (GtkThemingEngine *engine,
764 GtkThemingEnginePrivate *priv;
766 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
769 gtk_style_context_get_border_color (priv->context, state, color);
773 * gtk_theming_engine_get_border:
774 * @engine: a #GtkthemingEngine
775 * @state: state to retrieve the border for
776 * @border: (out): return value for the border settings
778 * Gets the border for a given state as a #GtkBorder.
783 gtk_theming_engine_get_border (GtkThemingEngine *engine,
787 GtkThemingEnginePrivate *priv;
789 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
792 gtk_style_context_get_border (priv->context, state, border);
796 * gtk_theming_engine_get_padding:
797 * @engine: a #GtkthemingEngine
798 * @state: state to retrieve the padding for
799 * @padding: (out): return value for the padding settings
801 * Gets the padding for a given state as a #GtkBorder.
806 gtk_theming_engine_get_padding (GtkThemingEngine *engine,
810 GtkThemingEnginePrivate *priv;
812 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
815 gtk_style_context_get_padding (priv->context, state, padding);
819 * gtk_theming_engine_get_margin:
820 * @engine: a #GtkThemingEngine
821 * @state: state to retrieve the border for
822 * @margin: (out): return value for the margin settings
824 * Gets the margin for a given state as a #GtkBorder.
829 gtk_theming_engine_get_margin (GtkThemingEngine *engine,
833 GtkThemingEnginePrivate *priv;
835 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
838 gtk_style_context_get_margin (priv->context, state, margin);
842 * gtk_theming_engine_get_font:
843 * @engine: a #GtkThemingEngine
844 * @state: state to retrieve the font for
846 * Returns the font description for a given state.
848 * Returns: (transfer none): the #PangoFontDescription for the given
849 * state. This object is owned by GTK+ and should not be
854 const PangoFontDescription *
855 gtk_theming_engine_get_font (GtkThemingEngine *engine,
858 GtkThemingEnginePrivate *priv;
860 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
863 return gtk_style_context_get_font (priv->context, state);
866 /* GtkThemingModule */
869 gtk_theming_module_load (GTypeModule *type_module)
871 GtkThemingModule *theming_module;
873 gchar *name, *module_path;
875 theming_module = GTK_THEMING_MODULE (type_module);
876 name = theming_module->name;
877 module_path = _gtk_find_module (name, "theming-engines");
882 module = g_module_open (module_path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
883 g_free (module_path);
888 if (!g_module_symbol (module, "theme_init",
889 (gpointer *) &theming_module->init) ||
890 !g_module_symbol (module, "theme_exit",
891 (gpointer *) &theming_module->exit) ||
892 !g_module_symbol (module, "create_engine",
893 (gpointer *) &theming_module->create_engine))
895 g_module_close (module);
900 theming_module->module = module;
902 theming_module->init (G_TYPE_MODULE (theming_module));
908 gtk_theming_module_unload (GTypeModule *type_module)
910 GtkThemingModule *theming_module;
912 theming_module = GTK_THEMING_MODULE (type_module);
914 theming_module->exit ();
916 g_module_close (theming_module->module);
918 theming_module->module = NULL;
919 theming_module->init = NULL;
920 theming_module->exit = NULL;
921 theming_module->create_engine = NULL;
925 gtk_theming_module_class_init (GtkThemingModuleClass *klass)
927 GTypeModuleClass *module_class = G_TYPE_MODULE_CLASS (klass);
929 module_class->load = gtk_theming_module_load;
930 module_class->unload = gtk_theming_module_unload;
934 gtk_theming_module_init (GtkThemingModule *module)
939 * gtk_theming_engine_load:
940 * @name: Theme engine name to load
942 * Loads and initializes a theming engine module from the
943 * standard directories.
945 * Returns: (transfer none): A theming engine, or %NULL if
946 * the engine @name doesn't exist.
949 gtk_theming_engine_load (const gchar *name)
951 static GHashTable *engines = NULL;
952 static GtkThemingEngine *default_engine;
953 GtkThemingEngine *engine = NULL;
958 engines = g_hash_table_new (g_str_hash, g_str_equal);
960 engine = g_hash_table_lookup (engines, name);
964 GtkThemingModule *module;
966 module = g_object_new (GTK_TYPE_THEMING_MODULE, NULL);
967 g_type_module_set_name (G_TYPE_MODULE (module), name);
968 module->name = g_strdup (name);
970 if (module && g_type_module_use (G_TYPE_MODULE (module)))
972 engine = (module->create_engine) ();
975 g_hash_table_insert (engines, module->name, engine);
981 if (G_UNLIKELY (!default_engine))
982 default_engine = g_object_new (GTK_TYPE_THEMING_ENGINE, NULL);
984 engine = default_engine;
991 * gtk_theming_engine_get_screen:
992 * @engine: a #GtkThemingEngine
994 * Returns the #GdkScreen to which @engine currently rendering to.
996 * Returns: (transfer none): a #GdkScreen, or %NULL.
999 gtk_theming_engine_get_screen (GtkThemingEngine *engine)
1001 GtkThemingEnginePrivate *priv;
1003 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
1005 priv = engine->priv;
1006 return gtk_style_context_get_screen (priv->context);
1009 /* Paint method implementations */
1011 gtk_theming_engine_render_check (GtkThemingEngine *engine,
1018 GdkRGBA fg_color, bg_color;
1019 GtkStateFlags flags;
1020 gint exterior_size, interior_size, thickness, pad;
1021 GtkBorderStyle border_style;
1024 GtkThemingBackground bg;
1026 _gtk_theming_background_init (&bg, engine,
1029 gtk_theming_engine_get_junction_sides (engine));
1031 if (_gtk_theming_background_has_background_image (&bg))
1033 _gtk_theming_background_render (&bg, cr);
1037 flags = gtk_theming_engine_get_state (engine);
1040 gtk_theming_engine_get_color (engine, flags, &fg_color);
1041 gtk_theming_engine_get_background_color (engine, flags, &bg_color);
1042 gtk_theming_engine_get_border (engine, flags, &border);
1044 gtk_theming_engine_get (engine, flags,
1045 "border-style", &border_style,
1048 border_width = MIN (MIN (border.top, border.bottom),
1049 MIN (border.left, border.right));
1050 exterior_size = MIN (width, height);
1052 if (exterior_size % 2 == 0) /* Ensure odd */
1055 /* FIXME: thickness */
1057 pad = thickness + MAX (1, (exterior_size - 2 * thickness) / 9);
1058 interior_size = MAX (1, exterior_size - 2 * pad);
1060 if (interior_size < 7)
1063 pad = MAX (0, (exterior_size - interior_size) / 2);
1066 x -= (1 + exterior_size - (gint) width) / 2;
1067 y -= (1 + exterior_size - (gint) height) / 2;
1069 if (border_style == GTK_BORDER_STYLE_SOLID)
1071 GdkRGBA border_color;
1073 cairo_set_line_width (cr, border_width);
1074 gtk_theming_engine_get_border_color (engine, flags, &border_color);
1076 cairo_rectangle (cr, x + 0.5, y + 0.5, exterior_size - 1, exterior_size - 1);
1077 gdk_cairo_set_source_rgba (cr, &bg_color);
1078 cairo_fill_preserve (cr);
1080 gdk_cairo_set_source_rgba (cr, &border_color);
1084 gdk_cairo_set_source_rgba (cr, &fg_color);
1086 if (flags & GTK_STATE_FLAG_INCONSISTENT)
1088 int line_thickness = MAX (1, (3 + interior_size * 2) / 7);
1090 cairo_rectangle (cr,
1092 y + pad + (1 + interior_size - line_thickness) / 2,
1102 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress);
1104 if ((flags & GTK_STATE_FLAG_ACTIVE) || running)
1109 cairo_translate (cr,
1112 cairo_scale (cr, interior_size / 7., interior_size / 7.);
1114 cairo_rectangle (cr, 0, 0, 7 * progress, 7);
1117 cairo_move_to (cr, 7.0, 0.0);
1118 cairo_line_to (cr, 7.5, 1.0);
1119 cairo_curve_to (cr, 5.3, 2.0,
1122 cairo_curve_to (cr, 3.0, 5.7,
1125 cairo_line_to (cr, 0.2, 3.5);
1126 cairo_curve_to (cr, 1.1, 3.5,
1129 cairo_curve_to (cr, 1.0, 3.9,
1132 cairo_curve_to (cr, 3.5, 3.1,
1144 gtk_theming_engine_render_option (GtkThemingEngine *engine,
1151 GtkStateFlags flags;
1152 GdkRGBA fg_color, bg_color;
1153 gint exterior_size, interior_size, pad, thickness, border_width;
1154 GtkBorderStyle border_style;
1156 GtkThemingBackground bg;
1158 _gtk_theming_background_init (&bg, engine,
1161 gtk_theming_engine_get_junction_sides (engine));
1163 if (_gtk_theming_background_has_background_image (&bg))
1165 _gtk_theming_background_render (&bg, cr);
1169 flags = gtk_theming_engine_get_state (engine);
1173 gtk_theming_engine_get_color (engine, flags, &fg_color);
1174 gtk_theming_engine_get_background_color (engine, flags, &bg_color);
1175 gtk_theming_engine_get_border (engine, flags, &border);
1177 gtk_theming_engine_get (engine, flags,
1178 "border-style", &border_style,
1181 exterior_size = MIN (width, height);
1182 border_width = MIN (MIN (border.top, border.bottom),
1183 MIN (border.left, border.right));
1185 if (exterior_size % 2 == 0) /* Ensure odd */
1188 x -= (1 + exterior_size - width) / 2;
1189 y -= (1 + exterior_size - height) / 2;
1191 if (border_style == GTK_BORDER_STYLE_SOLID)
1193 GdkRGBA border_color;
1195 cairo_set_line_width (cr, border_width);
1196 gtk_theming_engine_get_border_color (engine, flags, &border_color);
1198 cairo_new_sub_path (cr);
1200 x + exterior_size / 2.,
1201 y + exterior_size / 2.,
1202 (exterior_size - 1) / 2.,
1205 gdk_cairo_set_source_rgba (cr, &bg_color);
1206 cairo_fill_preserve (cr);
1208 gdk_cairo_set_source_rgba (cr, &border_color);
1212 gdk_cairo_set_source_rgba (cr, &fg_color);
1214 /* FIXME: thickness */
1217 if (flags & GTK_STATE_FLAG_INCONSISTENT)
1219 gint line_thickness;
1221 pad = thickness + MAX (1, (exterior_size - 2 * thickness) / 9);
1222 interior_size = MAX (1, exterior_size - 2 * pad);
1224 if (interior_size < 7)
1227 pad = MAX (0, (exterior_size - interior_size) / 2);
1230 line_thickness = MAX (1, (3 + interior_size * 2) / 7);
1232 cairo_rectangle (cr,
1234 y + pad + (interior_size - line_thickness) / 2.,
1239 if (flags & GTK_STATE_FLAG_ACTIVE)
1241 pad = thickness + MAX (1, 2 * (exterior_size - 2 * thickness) / 9);
1242 interior_size = MAX (1, exterior_size - 2 * pad);
1244 if (interior_size < 5)
1247 pad = MAX (0, (exterior_size - interior_size) / 2);
1250 cairo_new_sub_path (cr);
1252 x + pad + interior_size / 2.,
1253 y + pad + interior_size / 2.,
1263 add_path_arrow (cairo_t *cr,
1271 cairo_translate (cr, x + (size / 2), y + (size / 2));
1272 cairo_rotate (cr, angle);
1274 cairo_move_to (cr, 0, - (size / 4));
1275 cairo_line_to (cr, - (size / 2), (size / 4));
1276 cairo_line_to (cr, (size / 2), (size / 4));
1277 cairo_close_path (cr);
1283 gtk_theming_engine_render_arrow (GtkThemingEngine *engine,
1290 GtkStateFlags flags;
1295 flags = gtk_theming_engine_get_state (engine);
1296 gtk_theming_engine_get_color (engine, flags, &fg_color);
1298 if (flags & GTK_STATE_FLAG_INSENSITIVE)
1300 add_path_arrow (cr, angle, x + 1, y + 1, size);
1301 cairo_set_source_rgb (cr, 1, 1, 1);
1305 add_path_arrow (cr, angle, x, y, size);
1306 gdk_cairo_set_source_rgba (cr, &fg_color);
1313 add_path_line (cairo_t *cr,
1319 /* Adjust endpoints */
1333 cairo_move_to (cr, x1, y1);
1334 cairo_line_to (cr, x2, y2);
1338 color_shade (const GdkRGBA *color,
1340 GdkRGBA *color_return)
1342 GtkSymbolicColor *literal, *shade;
1344 literal = gtk_symbolic_color_new_literal (color);
1345 shade = gtk_symbolic_color_new_shade (literal, factor);
1346 gtk_symbolic_color_unref (literal);
1348 gtk_symbolic_color_resolve (shade, NULL, color_return);
1349 gtk_symbolic_color_unref (shade);
1353 gtk_theming_engine_render_background (GtkThemingEngine *engine,
1360 GtkThemingBackground bg;
1362 _gtk_theming_background_init (&bg, engine,
1365 gtk_theming_engine_get_junction_sides (engine));
1367 _gtk_theming_background_render (&bg, cr);
1371 gtk_theming_engine_hide_border_sides (GtkBorder *border,
1374 if (hidden_side & (1 << GTK_CSS_TOP))
1376 if (hidden_side & (1 << GTK_CSS_RIGHT))
1378 if (hidden_side & (1 << GTK_CSS_BOTTOM))
1380 if (hidden_side & (1 << GTK_CSS_LEFT))
1385 render_frame_fill (cairo_t *cr,
1386 GtkRoundedBox *border_box,
1391 GtkRoundedBox padding_box;
1394 padding_box = *border_box;
1395 _gtk_rounded_box_shrink (&padding_box, border->top, border->right, border->bottom, border->left);
1397 if (hidden_side == 0 &&
1398 gdk_rgba_equal (&colors[0], &colors[1]) &&
1399 gdk_rgba_equal (&colors[0], &colors[2]) &&
1400 gdk_rgba_equal (&colors[0], &colors[3]))
1402 gdk_cairo_set_source_rgba (cr, &colors[0]);
1404 _gtk_rounded_box_path (border_box, cr);
1405 _gtk_rounded_box_path (&padding_box, cr);
1410 for (i = 0; i < 4; i++)
1412 if (hidden_side & (1 << i))
1415 for (j = 0; j < 4; j++)
1417 if (hidden_side & (1 << j))
1421 (gdk_rgba_equal (&colors[i], &colors[j])))
1423 /* We were already painted when i == j */
1428 _gtk_rounded_box_path_top (border_box, &padding_box, cr);
1430 _gtk_rounded_box_path_right (border_box, &padding_box, cr);
1432 _gtk_rounded_box_path_bottom (border_box, &padding_box, cr);
1434 _gtk_rounded_box_path_left (border_box, &padding_box, cr);
1437 /* We were already painted when i == j */
1441 gdk_cairo_set_source_rgba (cr, &colors[i]);
1449 set_stroke_style (cairo_t *cr,
1451 GtkBorderStyle style,
1457 cairo_set_line_width (cr, line_width);
1459 if (style == GTK_BORDER_STYLE_DOTTED)
1461 n = round (0.5 * length / line_width);
1464 segments[1] = n ? length / n : 2;
1465 cairo_set_dash (cr, segments, G_N_ELEMENTS (segments), 0);
1467 cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
1468 cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
1472 n = length / line_width;
1473 /* Optimize the common case of an integer-sized rectangle
1474 * Again, we care about focus rectangles.
1476 if (n == nearbyint (n))
1483 n = round ((1. / 3) * n);
1485 segments[0] = n ? (1. / 3) * length / n : 1;
1486 segments[1] = 2 * segments[1];
1488 cairo_set_dash (cr, segments, G_N_ELEMENTS (segments), 0);
1490 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
1491 cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
1496 get_border_side (GtkBorder *border,
1504 return border->right;
1505 case GTK_CSS_BOTTOM:
1506 return border->bottom;
1508 return border->left;
1510 g_assert_not_reached ();
1516 render_frame_stroke (cairo_t *cr,
1517 GtkRoundedBox *border_box,
1521 GtkBorderStyle stroke_style)
1523 gboolean different_colors, different_borders;
1524 GtkRoundedBox stroke_box;
1527 different_colors = !gdk_rgba_equal (&colors[0], &colors[1]) ||
1528 !gdk_rgba_equal (&colors[0], &colors[2]) ||
1529 !gdk_rgba_equal (&colors[0], &colors[3]);
1530 different_borders = border->top != border->right ||
1531 border->top != border->bottom ||
1532 border->top != border->left;
1534 stroke_box = *border_box;
1535 _gtk_rounded_box_shrink (&stroke_box,
1537 border->right / 2.0,
1538 border->bottom / 2.0,
1539 border->left / 2.0);
1541 if (!different_colors && !different_borders && hidden_side == 0)
1546 * Mostly expected to trigger for focus rectangles */
1547 for (i = 0; i < 4; i++)
1549 length += _gtk_rounded_box_guess_length (&stroke_box, i);
1550 _gtk_rounded_box_path_side (&stroke_box, cr, i);
1553 gdk_cairo_set_source_rgba (cr, &colors[0]);
1554 set_stroke_style (cr, border->top, stroke_style, length);
1559 GtkRoundedBox padding_box;
1561 padding_box = *border_box;
1562 _gtk_rounded_box_path (&padding_box, cr);
1563 _gtk_rounded_box_shrink (&padding_box,
1569 for (i = 0; i < 4; i++)
1571 if (hidden_side & (1 << i))
1577 _gtk_rounded_box_path_top (border_box, &padding_box, cr);
1579 _gtk_rounded_box_path_right (border_box, &padding_box, cr);
1581 _gtk_rounded_box_path_bottom (border_box, &padding_box, cr);
1583 _gtk_rounded_box_path_left (border_box, &padding_box, cr);
1586 _gtk_rounded_box_path_side (&stroke_box, cr, i);
1588 gdk_cairo_set_source_rgba (cr, &colors[i]);
1589 set_stroke_style (cr,
1590 get_border_side (border, i),
1592 _gtk_rounded_box_guess_length (&stroke_box, i));
1601 render_border (cairo_t *cr,
1602 GtkRoundedBox *border_box,
1606 GtkBorderStyle border_style[4])
1612 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
1614 for (i = 0; i < 4; i++)
1616 if (hidden_side & (1 << i))
1619 switch (border_style[i])
1621 case GTK_BORDER_STYLE_NONE:
1622 case GTK_BORDER_STYLE_HIDDEN:
1623 case GTK_BORDER_STYLE_SOLID:
1625 case GTK_BORDER_STYLE_INSET:
1626 if (i == 1 || i == 2)
1627 color_shade (&colors[i], 1.8, &colors[i]);
1629 case GTK_BORDER_STYLE_OUTSET:
1630 if (i == 0 || i == 3)
1631 color_shade (&colors[i], 1.8, &colors[i]);
1633 case GTK_BORDER_STYLE_DOTTED:
1634 case GTK_BORDER_STYLE_DASHED:
1636 guint dont_draw = hidden_side;
1638 for (j = 0; j < 4; j++)
1640 if (border_style[j] == border_style[i])
1641 hidden_side |= (1 << j);
1643 dont_draw |= (1 << j);
1646 render_frame_stroke (cr, border_box, border, colors, dont_draw, border_style[i]);
1649 case GTK_BORDER_STYLE_DOUBLE:
1651 GtkRoundedBox other_box;
1652 GtkBorder other_border;
1653 guint dont_draw = hidden_side;
1655 for (j = 0; j < 4; j++)
1657 if (border_style[j] == GTK_BORDER_STYLE_DOUBLE)
1658 hidden_side |= (1 << j);
1660 dont_draw |= (1 << j);
1662 other_border.top = (border->top + 2) / 3;
1663 other_border.right = (border->right + 2) / 3;
1664 other_border.bottom = (border->bottom + 2) / 3;
1665 other_border.left = (border->left + 2) / 3;
1667 render_frame_fill (cr, border_box, &other_border, colors, dont_draw);
1669 other_box = *border_box;
1670 _gtk_rounded_box_shrink (&other_box,
1671 border->top - other_border.top,
1672 border->right - other_border.right,
1673 border->bottom - other_border.bottom,
1674 border->left - other_border.left);
1675 render_frame_fill (cr, &other_box, &other_border, colors, dont_draw);
1677 case GTK_BORDER_STYLE_GROOVE:
1678 case GTK_BORDER_STYLE_RIDGE:
1680 GtkRoundedBox other_box;
1681 GdkRGBA other_colors[4];
1682 guint dont_draw = hidden_side;
1683 GtkBorder other_border;
1685 for (j = 0; j < 4; j++)
1687 other_colors[j] = colors[j];
1688 if ((j == 0 || j == 3) ^ (border_style[j] == GTK_BORDER_STYLE_RIDGE))
1689 color_shade (&other_colors[j], 1.8, &other_colors[j]);
1691 color_shade (&colors[j], 1.8, &colors[j]);
1692 if (border_style[j] == GTK_BORDER_STYLE_GROOVE ||
1693 border_style[j] == GTK_BORDER_STYLE_RIDGE)
1694 hidden_side |= (1 << j);
1696 dont_draw |= (1 << j);
1698 other_border.top = border->top / 2;
1699 other_border.right = border->right / 2;
1700 other_border.bottom = border->bottom / 2;
1701 other_border.left = border->left / 2;
1703 render_frame_fill (cr, border_box, &other_border, colors, dont_draw);
1705 other_box = *border_box;
1706 _gtk_rounded_box_shrink (&other_box,
1707 other_border.top, other_border.right,
1708 other_border.bottom, other_border.left);
1709 other_border.top = border->top - other_border.top;
1710 other_border.right = border->right - other_border.right;
1711 other_border.bottom = border->bottom - other_border.bottom;
1712 other_border.left = border->left - other_border.left;
1713 render_frame_fill (cr, &other_box, &other_border, other_colors, dont_draw);
1717 g_assert_not_reached ();
1722 render_frame_fill (cr, border_box, border, colors, hidden_side);
1728 render_frame_internal (GtkThemingEngine *engine,
1735 GtkJunctionSides junction)
1737 GtkBorderImage border_image;
1738 GtkStateFlags state;
1739 GtkBorderStyle border_style[4];
1740 GtkRoundedBox border_box;
1744 GdkRGBA *alloc_colors[4];
1748 state = gtk_theming_engine_get_state (engine);
1750 gtk_theming_engine_get_border (engine, state, &border);
1751 gtk_theming_engine_hide_border_sides (&border, hidden_side);
1753 if (_gtk_border_image_init (&border_image, engine))
1754 _gtk_border_image_render (&border_image, &border, cr, x, y, width, height);
1757 gtk_theming_engine_get (engine, state,
1758 "border-top-style", &border_style[0],
1759 "border-right-style", &border_style[1],
1760 "border-bottom-style", &border_style[2],
1761 "border-left-style", &border_style[3],
1762 "border-top-color", &alloc_colors[0],
1763 "border-right-color", &alloc_colors[1],
1764 "border-bottom-color", &alloc_colors[2],
1765 "border-left-color", &alloc_colors[3],
1768 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
1772 GtkStateFlags other_state;
1773 GdkRGBA *other_colors[4];
1775 if (state & GTK_STATE_FLAG_PRELIGHT)
1777 other_state = state & ~(GTK_STATE_FLAG_PRELIGHT);
1778 progress = 1 - progress;
1781 other_state = state | GTK_STATE_FLAG_PRELIGHT;
1783 gtk_theming_engine_get (engine, other_state,
1784 "border-top-color", &other_colors[0],
1785 "border-right-color", &other_colors[1],
1786 "border-bottom-color", &other_colors[2],
1787 "border-left-color", &other_colors[3],
1790 for (i = 0; i < 4; i++)
1792 colors[i].red = CLAMP (alloc_colors[i]->red + ((other_colors[i]->red - alloc_colors[i]->red) * progress), 0, 1);
1793 colors[i].green = CLAMP (alloc_colors[i]->green + ((other_colors[i]->green - alloc_colors[i]->green) * progress), 0, 1);
1794 colors[i].blue = CLAMP (alloc_colors[i]->blue + ((other_colors[i]->blue - alloc_colors[i]->blue) * progress), 0, 1);
1795 colors[i].alpha = CLAMP (alloc_colors[i]->alpha + ((other_colors[i]->alpha - alloc_colors[i]->alpha) * progress), 0, 1);
1796 gdk_rgba_free (other_colors[i]);
1797 gdk_rgba_free (alloc_colors[i]);
1802 for (i = 0; i < 4; i++)
1804 colors[i] = *alloc_colors[i];
1805 gdk_rgba_free (alloc_colors[i]);
1809 _gtk_rounded_box_init_rect (&border_box, x, y, width, height);
1810 _gtk_rounded_box_apply_border_radius (&border_box, engine, state, junction);
1812 render_border (cr, &border_box, &border, hidden_side, colors, border_style);
1815 border_style[0] = g_value_get_enum (_gtk_theming_engine_peek_property (engine, "outline-style"));
1816 if (border_style[0] != GTK_BORDER_STYLE_NONE)
1820 border_style[1] = border_style[2] = border_style[3] = border_style[0];
1821 border.top = g_value_get_int (_gtk_theming_engine_peek_property (engine, "outline-width"));
1822 border.left = border.right = border.bottom = border.top;
1823 colors[0] = *(GdkRGBA *) g_value_get_boxed (_gtk_theming_engine_peek_property (engine, "outline-color"));
1824 colors[3] = colors[2] = colors[1] = colors[0];
1825 offset = g_value_get_int (_gtk_theming_engine_peek_property (engine, "outline-offset"));
1827 /* reinit box here - outlines don't have a border radius */
1828 _gtk_rounded_box_init_rect (&border_box, x, y, width, height);
1829 _gtk_rounded_box_shrink (&border_box,
1830 - border.top - offset,
1831 - border.right - offset,
1832 - border.left - offset,
1833 - border.bottom - offset);
1835 render_border (cr, &border_box, &border, hidden_side, colors, border_style);
1840 gtk_theming_engine_render_frame (GtkThemingEngine *engine,
1847 GtkJunctionSides junction;
1849 junction = gtk_theming_engine_get_junction_sides (engine);
1851 render_frame_internal (engine, cr,
1852 x, y, width, height,
1857 gtk_theming_engine_render_expander (GtkThemingEngine *engine,
1864 GtkStateFlags flags;
1865 GdkRGBA outline_color, fg_color;
1866 double vertical_overshoot;
1869 double interp; /* interpolation factor for center position */
1870 double x_double_horz, y_double_horz;
1871 double x_double_vert, y_double_vert;
1872 double x_double, y_double;
1875 gboolean running, is_rtl;
1879 flags = gtk_theming_engine_get_state (engine);
1881 gtk_theming_engine_get_color (engine, flags, &fg_color);
1882 gtk_theming_engine_get_border_color (engine, flags, &outline_color);
1884 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress);
1885 is_rtl = (gtk_theming_engine_get_direction (engine) == GTK_TEXT_DIR_RTL);
1889 progress = (flags & GTK_STATE_FLAG_ACTIVE) ? 1 : 0;
1891 if (!gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_HORIZONTAL))
1894 angle = (G_PI) - ((G_PI / 2) * progress);
1896 angle = (G_PI / 2) * progress;
1901 angle = (G_PI / 2) + ((G_PI / 2) * progress);
1903 angle = (G_PI / 2) - ((G_PI / 2) * progress);
1908 /* Compute distance that the stroke extends beyonds the end
1909 * of the triangle we draw.
1911 vertical_overshoot = line_width / 2.0 * (1. / tan (G_PI / 8));
1913 /* For odd line widths, we end the vertical line of the triangle
1914 * at a half pixel, so we round differently.
1916 if (line_width % 2 == 1)
1917 vertical_overshoot = ceil (0.5 + vertical_overshoot) - 0.5;
1919 vertical_overshoot = ceil (vertical_overshoot);
1921 /* Adjust the size of the triangle we draw so that the entire stroke fits
1923 diameter = (gint) MAX (3, width - 2 * vertical_overshoot);
1925 /* If the line width is odd, we want the diameter to be even,
1926 * and vice versa, so force the sum to be odd. This relationship
1927 * makes the point of the triangle look right.
1929 diameter -= (1 - (diameter + line_width) % 2);
1931 radius = diameter / 2.;
1933 /* Adjust the center so that the stroke is properly aligned with
1934 * the pixel grid. The center adjustment is different for the
1935 * horizontal and vertical orientations. For intermediate positions
1936 * we interpolate between the two.
1938 x_double_vert = floor ((x + width / 2) - (radius + line_width) / 2.) + (radius + line_width) / 2.;
1939 y_double_vert = (y + height / 2) - 0.5;
1941 x_double_horz = (x + width / 2) - 0.5;
1942 y_double_horz = floor ((y + height / 2) - (radius + line_width) / 2.) + (radius + line_width) / 2.;
1944 x_double = x_double_vert * (1 - interp) + x_double_horz * interp;
1945 y_double = y_double_vert * (1 - interp) + y_double_horz * interp;
1947 cairo_translate (cr, x_double, y_double);
1948 cairo_rotate (cr, angle);
1950 cairo_move_to (cr, - radius / 2., - radius);
1951 cairo_line_to (cr, radius / 2., 0);
1952 cairo_line_to (cr, - radius / 2., radius);
1953 cairo_close_path (cr);
1955 cairo_set_line_width (cr, line_width);
1957 gdk_cairo_set_source_rgba (cr, &fg_color);
1959 cairo_fill_preserve (cr);
1961 gdk_cairo_set_source_rgba (cr, &outline_color);
1968 gtk_theming_engine_render_focus (GtkThemingEngine *engine,
1975 GtkStateFlags flags;
1981 flags = gtk_theming_engine_get_state (engine);
1983 gtk_theming_engine_get_color (engine, flags, &color);
1985 gtk_theming_engine_get_style (engine,
1986 "focus-line-width", &line_width,
1987 "focus-line-pattern", (gchar *) &dash_list,
1990 cairo_set_line_width (cr, (gdouble) line_width);
1994 gint n_dashes = strlen ((const gchar *) dash_list);
1995 gdouble *dashes = g_new (gdouble, n_dashes);
1996 gdouble total_length = 0;
1997 gdouble dash_offset;
2000 for (i = 0; i < n_dashes; i++)
2002 dashes[i] = dash_list[i];
2003 total_length += dash_list[i];
2006 /* The dash offset here aligns the pattern to integer pixels
2007 * by starting the dash at the right side of the left border
2008 * Negative dash offsets in cairo don't work
2009 * (https://bugs.freedesktop.org/show_bug.cgi?id=2729)
2011 dash_offset = - line_width / 2.;
2013 while (dash_offset < 0)
2014 dash_offset += total_length;
2016 cairo_set_dash (cr, dashes, n_dashes, dash_offset);
2020 cairo_rectangle (cr,
2021 x + line_width / 2.,
2022 y + line_width / 2.,
2024 height - line_width);
2026 gdk_cairo_set_source_rgba (cr, &color);
2035 gtk_theming_engine_render_line (GtkThemingEngine *engine,
2043 GtkStateFlags flags;
2045 flags = gtk_theming_engine_get_state (engine);
2048 gtk_theming_engine_get_color (engine, flags, &color);
2050 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
2051 cairo_set_line_width (cr, 1);
2053 cairo_move_to (cr, x0 + 0.5, y0 + 0.5);
2054 cairo_line_to (cr, x1 + 0.5, y1 + 0.5);
2056 gdk_cairo_set_source_rgba (cr, &color);
2063 prepare_context_for_layout (cairo_t *cr,
2066 PangoLayout *layout)
2068 const PangoMatrix *matrix;
2070 matrix = pango_context_get_matrix (pango_layout_get_context (layout));
2072 cairo_move_to (cr, x, y);
2076 cairo_matrix_t cairo_matrix;
2078 cairo_matrix_init (&cairo_matrix,
2079 matrix->xx, matrix->yx,
2080 matrix->xy, matrix->yy,
2081 matrix->x0, matrix->y0);
2083 cairo_transform (cr, &cairo_matrix);
2088 gtk_theming_engine_render_layout (GtkThemingEngine *engine,
2092 PangoLayout *layout)
2095 GtkShadow *text_shadow = NULL;
2096 GtkStateFlags flags;
2101 flags = gtk_theming_engine_get_state (engine);
2102 gtk_theming_engine_get_color (engine, flags, &fg_color);
2104 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
2108 GtkStateFlags other_flags;
2111 if (flags & GTK_STATE_FLAG_PRELIGHT)
2113 other_flags = flags & ~(GTK_STATE_FLAG_PRELIGHT);
2114 progress = 1 - progress;
2117 other_flags = flags | GTK_STATE_FLAG_PRELIGHT;
2119 gtk_theming_engine_get_color (engine, other_flags, &other_fg);
2121 fg_color.red = CLAMP (fg_color.red + ((other_fg.red - fg_color.red) * progress), 0, 1);
2122 fg_color.green = CLAMP (fg_color.green + ((other_fg.green - fg_color.green) * progress), 0, 1);
2123 fg_color.blue = CLAMP (fg_color.blue + ((other_fg.blue - fg_color.blue) * progress), 0, 1);
2124 fg_color.alpha = CLAMP (fg_color.alpha + ((other_fg.alpha - fg_color.alpha) * progress), 0, 1);
2127 gtk_theming_engine_get (engine, flags,
2128 "text-shadow", &text_shadow,
2131 prepare_context_for_layout (cr, x, y, layout);
2133 if (text_shadow != NULL)
2135 _gtk_text_shadow_paint_layout (text_shadow, cr, layout);
2136 _gtk_shadow_unref (text_shadow);
2139 gdk_cairo_set_source_rgba (cr, &fg_color);
2140 pango_cairo_show_layout (cr, layout);
2146 gtk_theming_engine_render_slider (GtkThemingEngine *engine,
2152 GtkOrientation orientation)
2154 const GtkWidgetPath *path;
2157 path = gtk_theming_engine_get_path (engine);
2159 gtk_theming_engine_render_background (engine, cr, x, y, width, height);
2160 gtk_theming_engine_render_frame (engine, cr, x, y, width, height);
2162 /* FIXME: thickness */
2165 if (gtk_widget_path_is_type (path, GTK_TYPE_SCALE))
2167 if (orientation == GTK_ORIENTATION_VERTICAL)
2168 gtk_theming_engine_render_line (engine, cr,
2170 y + (gint) height / 2,
2171 x + width - thickness - 1,
2172 y + (gint) height / 2);
2174 gtk_theming_engine_render_line (engine, cr,
2175 x + (gint) width / 2,
2177 x + (gint) width / 2,
2178 y + height - thickness - 1);
2183 gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
2189 GtkPositionType gap_side,
2193 GtkJunctionSides junction;
2194 GtkStateFlags state;
2196 GtkCssBorderCornerRadius *top_left_radius, *top_right_radius;
2197 GtkCssBorderCornerRadius *bottom_left_radius, *bottom_right_radius;
2198 gdouble x0, y0, x1, y1, xc, yc, wc, hc;
2201 xc = yc = wc = hc = 0;
2202 state = gtk_theming_engine_get_state (engine);
2203 junction = gtk_theming_engine_get_junction_sides (engine);
2205 gtk_theming_engine_get_border (engine, state, &border);
2206 gtk_theming_engine_get (engine, state,
2207 "border-top-left-radius", &top_left_radius,
2208 "border-top-right-radius", &top_right_radius,
2209 "border-bottom-right-radius", &bottom_right_radius,
2210 "border-bottom-left-radius", &bottom_left_radius,
2213 border_width = MIN (MIN (border.top, border.bottom),
2214 MIN (border.left, border.right));
2221 xc = x + xy0_gap + border_width;
2223 wc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
2226 if (xy0_gap < _gtk_css_number_get (&top_left_radius->horizontal, width))
2227 junction |= GTK_JUNCTION_CORNER_TOPLEFT;
2229 if (xy1_gap > width - _gtk_css_number_get (&top_right_radius->horizontal, width))
2230 junction |= GTK_JUNCTION_CORNER_TOPRIGHT;
2232 case GTK_POS_BOTTOM:
2233 xc = x + xy0_gap + border_width;
2234 yc = y + height - border_width;
2235 wc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
2238 if (xy0_gap < _gtk_css_number_get (&bottom_left_radius->horizontal, width))
2239 junction |= GTK_JUNCTION_CORNER_BOTTOMLEFT;
2241 if (xy1_gap > width - _gtk_css_number_get (&bottom_right_radius->horizontal, width))
2242 junction |= GTK_JUNCTION_CORNER_BOTTOMRIGHT;
2247 yc = y + xy0_gap + border_width;
2249 hc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
2251 if (xy0_gap < _gtk_css_number_get (&top_left_radius->vertical, height))
2252 junction |= GTK_JUNCTION_CORNER_TOPLEFT;
2254 if (xy1_gap > height - _gtk_css_number_get (&bottom_left_radius->vertical, height))
2255 junction |= GTK_JUNCTION_CORNER_BOTTOMLEFT;
2259 xc = x + width - border_width;
2260 yc = y + xy0_gap + border_width;
2262 hc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
2264 if (xy0_gap < _gtk_css_number_get (&top_right_radius->vertical, height))
2265 junction |= GTK_JUNCTION_CORNER_TOPRIGHT;
2267 if (xy1_gap > height - _gtk_css_number_get (&bottom_right_radius->vertical, height))
2268 junction |= GTK_JUNCTION_CORNER_BOTTOMRIGHT;
2273 cairo_clip_extents (cr, &x0, &y0, &x1, &y1);
2274 cairo_rectangle (cr, x0, y0, x1 - x0, yc - y0);
2275 cairo_rectangle (cr, x0, yc, xc - x0, hc);
2276 cairo_rectangle (cr, xc + wc, yc, x1 - (xc + wc), hc);
2277 cairo_rectangle (cr, x0, yc + hc, x1 - x0, y1 - (yc + hc));
2280 render_frame_internal (engine, cr,
2281 x, y, width, height,
2286 g_free (top_left_radius);
2287 g_free (top_right_radius);
2288 g_free (bottom_right_radius);
2289 g_free (bottom_left_radius);
2293 gtk_theming_engine_render_extension (GtkThemingEngine *engine,
2299 GtkPositionType gap_side)
2301 GtkThemingBackground bg;
2302 GtkJunctionSides junction = 0;
2303 guint hidden_side = 0;
2310 junction = GTK_JUNCTION_LEFT;
2311 hidden_side = (1 << GTK_CSS_LEFT);
2313 cairo_translate (cr, x + width, y);
2314 cairo_rotate (cr, G_PI / 2);
2317 junction = GTK_JUNCTION_RIGHT;
2318 hidden_side = (1 << GTK_CSS_RIGHT);
2320 cairo_translate (cr, x, y + height);
2321 cairo_rotate (cr, - G_PI / 2);
2324 junction = GTK_JUNCTION_TOP;
2325 hidden_side = (1 << GTK_CSS_TOP);
2327 cairo_translate (cr, x + width, y + height);
2328 cairo_rotate (cr, G_PI);
2330 case GTK_POS_BOTTOM:
2331 junction = GTK_JUNCTION_BOTTOM;
2332 hidden_side = (1 << GTK_CSS_BOTTOM);
2334 cairo_translate (cr, x, y);
2338 if (gap_side == GTK_POS_TOP ||
2339 gap_side == GTK_POS_BOTTOM)
2340 _gtk_theming_background_init (&bg, engine,
2343 GTK_JUNCTION_BOTTOM);
2345 _gtk_theming_background_init (&bg, engine,
2348 GTK_JUNCTION_BOTTOM);
2350 _gtk_theming_background_render (&bg, cr);
2356 render_frame_internal (engine, cr,
2357 x, y, width, height,
2358 hidden_side, junction);
2364 render_dot (cairo_t *cr,
2365 const GdkRGBA *lighter,
2366 const GdkRGBA *darker,
2371 size = CLAMP ((gint) size, 2, 3);
2375 gdk_cairo_set_source_rgba (cr, lighter);
2376 cairo_rectangle (cr, x, y, 1, 1);
2377 cairo_rectangle (cr, x + 1, y + 1, 1, 1);
2382 gdk_cairo_set_source_rgba (cr, lighter);
2383 cairo_rectangle (cr, x, y, 2, 1);
2384 cairo_rectangle (cr, x, y, 1, 2);
2387 gdk_cairo_set_source_rgba (cr, darker);
2388 cairo_rectangle (cr, x + 1, y + 1, 2, 1);
2389 cairo_rectangle (cr, x + 2, y, 1, 2);
2395 gtk_theming_engine_render_handle (GtkThemingEngine *engine,
2402 GtkStateFlags flags;
2403 GdkRGBA bg_color, lighter, darker;
2404 GtkJunctionSides sides;
2405 GtkThemingBackground bg;
2409 flags = gtk_theming_engine_get_state (engine);
2411 cairo_set_line_width (cr, 1.0);
2412 sides = gtk_theming_engine_get_junction_sides (engine);
2413 gtk_theming_engine_get_background_color (engine, flags, &bg_color);
2415 color_shade (&bg_color, 0.7, &darker);
2416 color_shade (&bg_color, 1.3, &lighter);
2418 _gtk_theming_background_init (&bg, engine, x, y, width, height, sides);
2419 _gtk_theming_background_render (&bg, cr);
2421 if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_GRIP))
2423 /* reduce confusing values to a meaningful state */
2424 if ((sides & (GTK_JUNCTION_CORNER_TOPLEFT | GTK_JUNCTION_CORNER_BOTTOMRIGHT)) == (GTK_JUNCTION_CORNER_TOPLEFT | GTK_JUNCTION_CORNER_BOTTOMRIGHT))
2425 sides &= ~GTK_JUNCTION_CORNER_TOPLEFT;
2427 if ((sides & (GTK_JUNCTION_CORNER_TOPRIGHT | GTK_JUNCTION_CORNER_BOTTOMLEFT)) == (GTK_JUNCTION_CORNER_TOPRIGHT | GTK_JUNCTION_CORNER_BOTTOMLEFT))
2428 sides &= ~GTK_JUNCTION_CORNER_TOPRIGHT;
2431 sides = GTK_JUNCTION_CORNER_BOTTOMRIGHT;
2433 /* align drawing area to the connected side */
2434 if (sides == GTK_JUNCTION_LEFT)
2439 else if (sides == GTK_JUNCTION_CORNER_TOPLEFT)
2443 else if (height < width)
2446 else if (sides == GTK_JUNCTION_CORNER_BOTTOMLEFT)
2448 /* make it square, aligning to bottom left */
2451 y += (height - width);
2454 else if (height < width)
2457 else if (sides == GTK_JUNCTION_RIGHT)
2459 /* aligning to right */
2462 x += (width - height);
2466 else if (sides == GTK_JUNCTION_CORNER_TOPRIGHT)
2470 else if (height < width)
2472 x += (width - height);
2476 else if (sides == GTK_JUNCTION_CORNER_BOTTOMRIGHT)
2478 /* make it square, aligning to bottom right */
2481 y += (height - width);
2484 else if (height < width)
2486 x += (width - height);
2490 else if (sides == GTK_JUNCTION_TOP)
2495 else if (sides == GTK_JUNCTION_BOTTOM)
2497 /* align to bottom */
2500 y += (height - width);
2505 g_assert_not_reached ();
2507 if (sides == GTK_JUNCTION_LEFT ||
2508 sides == GTK_JUNCTION_RIGHT)
2514 while (xi < x + width)
2516 gdk_cairo_set_source_rgba (cr, &lighter);
2517 add_path_line (cr, x, y, x, y + height);
2521 gdk_cairo_set_source_rgba (cr, &darker);
2522 add_path_line (cr, xi, y, xi, y + height);
2527 else if (sides == GTK_JUNCTION_TOP ||
2528 sides == GTK_JUNCTION_BOTTOM)
2534 while (yi < y + height)
2536 gdk_cairo_set_source_rgba (cr, &lighter);
2537 add_path_line (cr, x, yi, x + width, yi);
2541 gdk_cairo_set_source_rgba (cr, &darker);
2542 add_path_line (cr, x, yi, x + width, yi);
2547 else if (sides == GTK_JUNCTION_CORNER_TOPLEFT)
2556 gdk_cairo_set_source_rgba (cr, &darker);
2557 add_path_line (cr, xi, y, x, yi);
2563 add_path_line (cr, xi, y, x, yi);
2569 gdk_cairo_set_source_rgba (cr, &lighter);
2570 add_path_line (cr, xi, y, x, yi);
2577 else if (sides == GTK_JUNCTION_CORNER_TOPRIGHT)
2584 while (xi < (x + width - 3))
2586 gdk_cairo_set_source_rgba (cr, &lighter);
2587 add_path_line (cr, xi, y, x + width, yi);
2593 gdk_cairo_set_source_rgba (cr, &darker);
2594 add_path_line (cr, xi, y, x + width, yi);
2600 add_path_line (cr, xi, y, x + width, yi);
2607 else if (sides == GTK_JUNCTION_CORNER_BOTTOMLEFT)
2616 gdk_cairo_set_source_rgba (cr, &darker);
2617 add_path_line (cr, x, yi, xi, y + height);
2623 add_path_line (cr, x, yi, xi, y + height);
2629 gdk_cairo_set_source_rgba (cr, &lighter);
2630 add_path_line (cr, x, yi, xi, y + height);
2637 else if (sides == GTK_JUNCTION_CORNER_BOTTOMRIGHT)
2644 while (xi < (x + width - 3))
2646 gdk_cairo_set_source_rgba (cr, &lighter);
2647 add_path_line (cr, xi, y + height, x + width, yi);
2653 gdk_cairo_set_source_rgba (cr, &darker);
2654 add_path_line (cr, xi, y + height, x + width, yi);
2660 add_path_line (cr, xi, y + height, x + width, yi);
2668 else if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_PANE_SEPARATOR))
2671 for (xx = x + width / 2 - 15; xx <= x + width / 2 + 15; xx += 5)
2672 render_dot (cr, &lighter, &darker, xx, y + height / 2 - 1, 3);
2674 for (yy = y + height / 2 - 15; yy <= y + height / 2 + 15; yy += 5)
2675 render_dot (cr, &lighter, &darker, x + width / 2 - 1, yy, 3);
2679 for (yy = y; yy < y + height; yy += 3)
2680 for (xx = x; xx < x + width; xx += 6)
2682 render_dot (cr, &lighter, &darker, xx, yy, 2);
2683 render_dot (cr, &lighter, &darker, xx + 3, yy + 1, 2);
2691 _gtk_theming_engine_paint_spinner (cairo_t *cr,
2696 guint num_steps, step;
2703 step = (guint) (progress * num_steps);
2709 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
2710 cairo_set_line_width (cr, 2.0);
2712 half = num_steps / 2;
2714 for (i = 0; i < num_steps; i++)
2716 gint inset = 0.7 * radius;
2718 /* transparency is a function of time and intial value */
2719 gdouble t = 1.0 - (gdouble) ((i + step) % num_steps) / num_steps;
2720 gdouble xscale = - sin (i * G_PI / half);
2721 gdouble yscale = - cos (i * G_PI / half);
2723 cairo_set_source_rgba (cr,
2730 (radius - inset) * xscale,
2731 (radius - inset) * yscale);
2743 render_spinner (GtkThemingEngine *engine,
2750 GtkStateFlags state;
2756 state = gtk_theming_engine_get_state (engine);
2758 if (!gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress))
2761 radius = MIN (width / 2, height / 2);
2763 gtk_theming_engine_get_color (engine, state, &color);
2764 gtk_theming_engine_get (engine, state,
2765 "icon-shadow", &shadow,
2769 cairo_translate (cr, x + width / 2, y + height / 2);
2773 _gtk_icon_shadow_paint_spinner (shadow, cr,
2776 _gtk_shadow_unref (shadow);
2779 _gtk_theming_engine_paint_spinner (cr,
2788 gtk_theming_engine_render_activity (GtkThemingEngine *engine,
2795 if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_SPINNER))
2797 render_spinner (engine, cr, x, y, width, height);
2801 gtk_theming_engine_render_background (engine, cr, x, y, width, height);
2802 gtk_theming_engine_render_frame (engine, cr, x, y, width, height);
2807 scale_or_ref (GdkPixbuf *src,
2811 if (width == gdk_pixbuf_get_width (src) &&
2812 height == gdk_pixbuf_get_height (src))
2813 return g_object_ref (src);
2815 return gdk_pixbuf_scale_simple (src,
2817 GDK_INTERP_BILINEAR);
2821 lookup_icon_size (GtkThemingEngine *engine,
2827 GtkSettings *settings;
2829 screen = gtk_theming_engine_get_screen (engine);
2830 settings = gtk_settings_get_for_screen (screen);
2832 return gtk_icon_size_lookup_for_settings (settings, size, width, height);
2836 colorshift_source (cairo_t *cr,
2839 cairo_pattern_t *source;
2844 source = cairo_pattern_reference (cairo_get_source (cr));
2846 cairo_set_source_rgb (cr, shift, shift, shift);
2847 cairo_set_operator (cr, CAIRO_OPERATOR_COLOR_DODGE);
2849 cairo_mask (cr, source);
2851 cairo_pattern_destroy (source);
2856 gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine *engine,
2857 const GtkIconSource *source,
2862 GdkPixbuf *base_pixbuf;
2863 GtkStateFlags state;
2867 cairo_surface_t *surface;
2869 base_pixbuf = gtk_icon_source_get_pixbuf (source);
2870 state = gtk_theming_engine_get_state (engine);
2872 g_return_val_if_fail (base_pixbuf != NULL, NULL);
2874 if (size != (GtkIconSize) -1 &&
2875 !lookup_icon_size (engine, size, &width, &height))
2877 g_warning (G_STRLOC ": invalid icon size '%d'", size);
2881 /* If the size was wildcarded, and we're allowed to scale, then scale; otherwise,
2884 if (size != (GtkIconSize) -1 &&
2885 gtk_icon_source_get_size_wildcarded (source))
2886 scaled = scale_or_ref (base_pixbuf, width, height);
2888 scaled = g_object_ref (base_pixbuf);
2890 /* If the state was wildcarded, then generate a state. */
2891 if (gtk_icon_source_get_state_wildcarded (source))
2893 if (state & GTK_STATE_FLAG_INSENSITIVE)
2895 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
2896 gdk_pixbuf_get_width (scaled),
2897 gdk_pixbuf_get_height (scaled));
2898 cr = cairo_create (surface);
2899 gdk_cairo_set_source_pixbuf (cr, scaled, 0, 0);
2900 cairo_paint_with_alpha (cr, 0.5);
2904 g_object_unref (scaled);
2905 stated = gdk_pixbuf_get_from_surface (surface, 0, 0,
2906 cairo_image_surface_get_width (surface),
2907 cairo_image_surface_get_height (surface));
2908 cairo_surface_destroy (surface);
2910 else if (state & GTK_STATE_FLAG_PRELIGHT)
2912 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
2913 gdk_pixbuf_get_width (scaled),
2914 gdk_pixbuf_get_height (scaled));
2916 cr = cairo_create (surface);
2917 gdk_cairo_set_source_pixbuf (cr, scaled, 0, 0);
2918 colorshift_source (cr, 0.10);
2922 g_object_unref (scaled);
2923 stated = gdk_pixbuf_get_from_surface (surface, 0, 0,
2924 cairo_image_surface_get_width (surface),
2925 cairo_image_surface_get_height (surface));
2926 cairo_surface_destroy (surface);
2938 gtk_theming_engine_render_icon (GtkThemingEngine *engine,
2944 GtkStateFlags state;
2945 GtkShadow *icon_shadow;
2947 state = gtk_theming_engine_get_state (engine);
2951 gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
2953 gtk_theming_engine_get (engine, state,
2954 "icon-shadow", &icon_shadow,
2957 if (icon_shadow != NULL)
2959 _gtk_icon_shadow_paint (icon_shadow, cr);
2960 _gtk_shadow_unref (icon_shadow);