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 "gtk9slice.h"
33 * SECTION:gtkthemingengine
34 * @Short_description: Theming renderers
35 * @Title: GtkThemingEngine
36 * @See_also: #GtkStyleContext
38 * #GtkThemingEngine is the object used for rendering themed content
39 * in GTK+ widgets. Even though GTK+ has a default implementation,
40 * it can be overridden in CSS files by enforcing a #GtkThemingEngine
41 * object to be loaded as a module.
43 * In order to implement a theming engine, a #GtkThemingEngine subclass
44 * must be created, alongside the CSS file that will reference it, the
45 * theming engine would be created as an .so library, and installed in
46 * $(gtk-modules-dir)/theming-engines/.
49 typedef struct GtkThemingEnginePrivate GtkThemingEnginePrivate;
59 struct GtkThemingEnginePrivate
61 GtkStyleContext *context;
64 #define GTK_THEMING_ENGINE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_THEMING_ENGINE, GtkThemingEnginePrivate))
66 static void gtk_theming_engine_render_check (GtkThemingEngine *engine,
72 static void gtk_theming_engine_render_option (GtkThemingEngine *engine,
78 static void gtk_theming_engine_render_arrow (GtkThemingEngine *engine,
84 static void gtk_theming_engine_render_background (GtkThemingEngine *engine,
90 static void gtk_theming_engine_render_frame (GtkThemingEngine *engine,
96 static void gtk_theming_engine_render_expander (GtkThemingEngine *engine,
102 static void gtk_theming_engine_render_focus (GtkThemingEngine *engine,
108 static void gtk_theming_engine_render_layout (GtkThemingEngine *engine,
112 PangoLayout *layout);
113 static void gtk_theming_engine_render_line (GtkThemingEngine *engine,
119 static void gtk_theming_engine_render_slider (GtkThemingEngine *engine,
125 GtkOrientation orientation);
126 static void gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
132 GtkPositionType gap_side,
135 static void gtk_theming_engine_render_extension (GtkThemingEngine *engine,
141 GtkPositionType gap_side);
142 static void gtk_theming_engine_render_handle (GtkThemingEngine *engine,
149 G_DEFINE_TYPE (GtkThemingEngine, gtk_theming_engine, G_TYPE_OBJECT)
152 typedef struct GtkThemingModule GtkThemingModule;
153 typedef struct GtkThemingModuleClass GtkThemingModuleClass;
155 struct GtkThemingModule
157 GTypeModule parent_instance;
161 void (*init) (GTypeModule *module);
163 GtkThemingEngine * (*create_engine) (void);
166 struct GtkThemingModuleClass
168 GTypeModuleClass parent_class;
171 #define GTK_TYPE_THEMING_MODULE (gtk_theming_module_get_type ())
172 #define GTK_THEMING_MODULE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_THEMING_MODULE, GtkThemingModule))
173 #define GTK_IS_THEMING_MODULE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_THEMING_MODULE))
175 G_DEFINE_TYPE (GtkThemingModule, gtk_theming_module, G_TYPE_TYPE_MODULE);
178 gtk_theming_engine_class_init (GtkThemingEngineClass *klass)
180 GObjectClass *object_class = G_OBJECT_CLASS (klass);
182 klass->render_check = gtk_theming_engine_render_check;
183 klass->render_option = gtk_theming_engine_render_option;
184 klass->render_arrow = gtk_theming_engine_render_arrow;
185 klass->render_background = gtk_theming_engine_render_background;
186 klass->render_frame = gtk_theming_engine_render_frame;
187 klass->render_expander = gtk_theming_engine_render_expander;
188 klass->render_focus = gtk_theming_engine_render_focus;
189 klass->render_layout = gtk_theming_engine_render_layout;
190 klass->render_line = gtk_theming_engine_render_line;
191 klass->render_slider = gtk_theming_engine_render_slider;
192 klass->render_frame_gap = gtk_theming_engine_render_frame_gap;
193 klass->render_extension = gtk_theming_engine_render_extension;
194 klass->render_handle = gtk_theming_engine_render_handle;
196 g_type_class_add_private (object_class, sizeof (GtkThemingEnginePrivate));
200 gtk_theming_engine_init (GtkThemingEngine *engine)
202 engine->priv = GTK_THEMING_ENGINE_GET_PRIVATE (engine);
206 _gtk_theming_engine_set_context (GtkThemingEngine *engine,
207 GtkStyleContext *context)
209 GtkThemingEnginePrivate *priv;
211 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
212 g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
215 priv->context = context;
219 * gtk_theming_engine_register_property:
220 * @engine: a #GtkThemingEngine
221 * @property_name: property name to register
222 * @type: #GType the property will hold
223 * @default_value: default value for this property
224 * @parse_func: parsing function to use, or %NULL
226 * Registers a property so it can be used in the CSS file format,
227 * on the CSS file the property will look like
228 * "-${engine-object-name}-${@property_name}". being
229 * ${engine-object-name} the same than G_OBJECT_TYPE_NAME(engine)
232 * For any type a @parse_func may be provided, being this function
233 * used for turning any property value (between ':' and ';') in
234 * CSS to the #GValue needed. For basic types there is already
235 * builtin parsing support, so %NULL may be provided for these
239 * This function needs to be called only once during theming
240 * engine object initialization.
244 * In order to make use of the custom registered properties in
245 * the CSS file, make sure the engine is loaded first either in
246 * a previous rule or within the same one.
249 * engine: someengine;
250 * SomeEngine-custom-property: 2;
258 gtk_theming_engine_register_property (GtkThemingEngine *engine,
259 const gchar *property_name,
261 const GValue *default_value,
262 GtkStylePropertyParser parse_func)
266 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
267 g_return_if_fail (property_name != NULL);
268 g_return_if_fail (type != G_TYPE_INVALID);
269 g_return_if_fail (default_value != NULL && G_IS_VALUE (default_value));
271 name = g_strdup_printf ("-%s-%s", G_OBJECT_TYPE_NAME (engine), property_name);
272 gtk_style_set_register_property (name, type, default_value, parse_func);
277 * gtk_theming_engine_get_property:
278 * @engine: a #GtkThemingEngine
279 * @property: the property name
280 * @state: state to retrieve the value for
281 * @value: (out) (transfer full): return location for the property value,
282 * you must free this memory using g_value_unset() once you are
285 * Gets a property value as retrieved from the style settings that apply
286 * to the currently rendered element.
291 gtk_theming_engine_get_property (GtkThemingEngine *engine,
292 const gchar *property,
296 GtkThemingEnginePrivate *priv;
298 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
299 g_return_if_fail (property != NULL);
300 g_return_if_fail (value != NULL);
303 gtk_style_context_get_property (priv->context, property, state, value);
307 * gtk_theming_engine_get_valist:
308 * @engine: a #GtkThemingEngine
309 * @state: state to retrieve values for
310 * @args: va_list of property name/return location pairs, followed by %NULL
312 * Retrieves several style property values that apply to the currently
318 gtk_theming_engine_get_valist (GtkThemingEngine *engine,
322 GtkThemingEnginePrivate *priv;
324 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
327 gtk_style_context_get_valist (priv->context, state, args);
331 * gtk_theming_engine_get:
332 * @engine: a #GtkThemingEngine
333 * @state: state to retrieve values for
334 * @...: property name /return value pairs, followed by %NULL
336 * Retrieves several style property values that apply to the currently
342 gtk_theming_engine_get (GtkThemingEngine *engine,
346 GtkThemingEnginePrivate *priv;
349 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
353 va_start (args, state);
354 gtk_style_context_get_valist (priv->context, state, args);
359 * gtk_theming_engine_get_style_property:
360 * @engine: a #GtkThemingEngine
361 * @property_name: the name of the widget style property
362 * @value: (out) (transfer full): Return location for the property value, free with
363 * g_value_unset() after use.
365 * Gets the value for a widget style property.
370 gtk_theming_engine_get_style_property (GtkThemingEngine *engine,
371 const gchar *property_name,
374 GtkThemingEnginePrivate *priv;
376 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
377 g_return_if_fail (property_name != NULL);
380 gtk_style_context_get_style_property (priv->context, property_name, value);
384 * gtk_theming_engine_get_style_valist:
385 * @engine: a #GtkThemingEngine
386 * @args: va_list of property name/return location pairs, followed by %NULL
388 * Retrieves several widget style properties from @engine according to the
389 * currently rendered content's style.
394 gtk_theming_engine_get_style_valist (GtkThemingEngine *engine,
397 GtkThemingEnginePrivate *priv;
399 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
402 gtk_style_context_get_style_valist (priv->context, args);
406 * gtk_theming_engine_get_style:
407 * @engine: a #GtkThemingEngine
408 * @...: property name /return value pairs, followed by %NULL
410 * Retrieves several widget style properties from @engine according
411 * to the currently rendered content's style.
416 gtk_theming_engine_get_style (GtkThemingEngine *engine,
419 GtkThemingEnginePrivate *priv;
422 g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
426 va_start (args, engine);
427 gtk_style_context_get_style_valist (priv->context, args);
432 * gtk_theming_engine_get_state:
433 * @engine: a #GtkThemingEngine
435 * returns the state used when rendering.
437 * Returns: the state flags
442 gtk_theming_engine_get_state (GtkThemingEngine *engine)
444 GtkThemingEnginePrivate *priv;
446 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), 0);
449 return gtk_style_context_get_state (priv->context);
453 * gtk_theming_engine_state_is_running:
454 * @engine: a #GtkThemingEngine
455 * @state: a widget state
456 * @progress: (out): return location for the transition progress
458 * Returns %TRUE if there is a transition animation running for the
459 * current region (see gtk_style_context_push_animatable_region()).
461 * If @progress is not %NULL, the animation progress will be returned
462 * there, 0.0 means the state is closest to being %FALSE, while 1.0 means
463 * it's closest to being %TRUE. This means transition animations will
464 * run from 0 to 1 when @state is being set to %TRUE and from 1 to 0 when
465 * it's being set to %FALSE.
467 * Returns: %TRUE if there is a running transition animation for @state.
472 gtk_theming_engine_state_is_running (GtkThemingEngine *engine,
476 GtkThemingEnginePrivate *priv;
478 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
481 return gtk_style_context_state_is_running (priv->context, state, progress);
485 * gtk_theming_engine_get_path:
486 * @engine: a #GtkThemingEngine
488 * Returns the widget path used for style matching.
490 * Returns: (transfer none): A #GtkWidgetPath
494 G_CONST_RETURN GtkWidgetPath *
495 gtk_theming_engine_get_path (GtkThemingEngine *engine)
497 GtkThemingEnginePrivate *priv;
499 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
502 return gtk_style_context_get_path (priv->context);
506 * gtk_theming_engine_has_class:
507 * @engine: a #GtkThemingEngine
508 * @style_class: class name to look up
510 * Returns %TRUE if the currently rendered contents have
511 * defined the given class name.
513 * Returns: %TRUE if @engine has @class_name defined
518 gtk_theming_engine_has_class (GtkThemingEngine *engine,
519 const gchar *style_class)
521 GtkThemingEnginePrivate *priv;
523 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
526 return gtk_style_context_has_class (priv->context, style_class);
530 * gtk_theming_engine_has_region:
531 * @engine: a #GtkThemingEngine
532 * @style_region: a region name
533 * @flags: (out) (allow-none): return location for region flags
535 * Returns %TRUE if the currently rendered contents have the
536 * region defined. If @flags_return is not %NULL, it is set
537 * to the flags affecting the region.
539 * Returns: %TRUE if region is defined
544 gtk_theming_engine_has_region (GtkThemingEngine *engine,
545 const gchar *style_region,
546 GtkRegionFlags *flags)
548 GtkThemingEnginePrivate *priv;
553 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
556 return gtk_style_context_has_region (priv->context, style_region, flags);
560 * gtk_theming_engine_get_direction:
561 * @engine: a #GtkThemingEngine
563 * Returns the widget direction used for rendering.
565 * Returns: the widget direction
570 gtk_theming_engine_get_direction (GtkThemingEngine *engine)
572 GtkThemingEnginePrivate *priv;
574 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), GTK_TEXT_DIR_LTR);
577 return gtk_style_context_get_direction (priv->context);
581 * gtk_theming_engine_get_junction_sides:
582 * @engine: a #GtkThemingEngine
584 * Returns the widget direction used for rendering.
586 * Returns: the widget direction
591 gtk_theming_engine_get_junction_sides (GtkThemingEngine *engine)
593 GtkThemingEnginePrivate *priv;
595 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), 0);
598 return gtk_style_context_get_junction_sides (priv->context);
601 /* GtkThemingModule */
604 gtk_theming_module_load (GTypeModule *type_module)
606 GtkThemingModule *theming_module;
608 gchar *name, *module_path;
610 theming_module = GTK_THEMING_MODULE (type_module);
611 name = theming_module->name;
612 module_path = _gtk_find_module (name, "theming-engines");
616 g_warning (_("Unable to locate theme engine in module path: \"%s\","), name);
620 module = g_module_open (module_path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
621 g_free (module_path);
625 g_warning ("%s", g_module_error ());
629 if (!g_module_symbol (module, "theme_init",
630 (gpointer *) &theming_module->init) ||
631 !g_module_symbol (module, "theme_exit",
632 (gpointer *) &theming_module->exit) ||
633 !g_module_symbol (module, "create_engine",
634 (gpointer *) &theming_module->create_engine))
636 g_warning ("%s", g_module_error ());
637 g_module_close (module);
642 theming_module->module = module;
644 theming_module->init (theming_module);
650 gtk_theming_module_unload (GTypeModule *type_module)
652 GtkThemingModule *theming_module;
654 theming_module = GTK_THEMING_MODULE (type_module);
656 theming_module->exit ();
658 g_module_close (theming_module->module);
660 theming_module->module = NULL;
661 theming_module->init = NULL;
662 theming_module->exit = NULL;
663 theming_module->create_engine = NULL;
667 gtk_theming_module_class_init (GtkThemingModuleClass *klass)
669 GTypeModuleClass *module_class = G_TYPE_MODULE_CLASS (klass);
671 module_class->load = gtk_theming_module_load;
672 module_class->unload = gtk_theming_module_unload;
676 gtk_theming_module_init (GtkThemingModule *module)
681 * gtk_theming_engine_load:
682 * @name: Theme engine name to load
684 * Loads and initializes a theming engine module from the
685 * standard directories.
687 * Returns: (transfer none): A theming engine, or %NULL if
688 * the engine @name doesn't exist.
691 gtk_theming_engine_load (const gchar *name)
693 static GHashTable *engines = NULL;
694 static GtkThemingEngine *default_engine;
695 GtkThemingEngine *engine = NULL;
700 engines = g_hash_table_new (g_str_hash, g_str_equal);
702 engine = g_hash_table_lookup (engines, name);
706 GtkThemingModule *module;
708 module = g_object_new (GTK_TYPE_THEMING_MODULE, NULL);
709 g_type_module_set_name (G_TYPE_MODULE (module), name);
710 module->name = g_strdup (name);
712 if (module && g_type_module_use (G_TYPE_MODULE (module)))
714 engine = (module->create_engine) ();
717 g_hash_table_insert (engines, module->name, engine);
724 if (G_UNLIKELY (!default_engine))
725 default_engine = g_object_new (GTK_TYPE_THEMING_ENGINE, NULL);
727 engine = default_engine;
734 * gtk_theming_engine_get_screen:
735 * @engine: a #GtkThemingEngine
737 * Returns the #GdkScreen to which @engine currently rendering to.
739 * Returns: a #GdkScreen, or %NULL.
742 gtk_theming_engine_get_screen (GtkThemingEngine *engine)
744 GtkThemingEnginePrivate *priv;
746 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
749 return gtk_style_context_get_screen (priv->context);
752 /* Paint method implementations */
754 gtk_theming_engine_render_check (GtkThemingEngine *engine,
761 GdkRGBA *fg_color, *base_color, *text_color;
762 const GtkWidgetPath *path;
764 gint exterior_size, interior_size, thickness, pad;
766 flags = gtk_theming_engine_get_state (engine);
767 path = gtk_theming_engine_get_path (engine);
770 gtk_theming_engine_get (engine, flags,
771 "foreground-color", &fg_color,
772 "base-color", &base_color,
773 "text-color", &text_color,
776 exterior_size = MIN (width, height);
778 if (exterior_size % 2 == 0) /* Ensure odd */
781 /* FIXME: thickness */
783 pad = thickness + MAX (1, (exterior_size - 2 * thickness) / 9);
784 interior_size = MAX (1, exterior_size - 2 * pad);
786 if (interior_size < 7)
789 pad = MAX (0, (exterior_size - interior_size) / 2);
792 x -= (1 + exterior_size - (gint) width) / 2;
793 y -= (1 + exterior_size - (gint) height) / 2;
795 if (!gtk_theming_engine_has_class (engine, "menu"))
797 cairo_set_line_width (cr, 1.0);
799 cairo_rectangle (cr, x + 0.5, y + 0.5, exterior_size - 1, exterior_size - 1);
800 gdk_cairo_set_source_rgba (cr, base_color);
801 cairo_fill_preserve (cr);
803 if (gtk_theming_engine_has_class (engine, "cell"))
804 gdk_cairo_set_source_rgba (cr, text_color);
806 gdk_cairo_set_source_rgba (cr, fg_color);
811 if (gtk_theming_engine_has_class (engine, "menu"))
812 gdk_cairo_set_source_rgba (cr, fg_color);
814 gdk_cairo_set_source_rgba (cr, text_color);
816 if (flags & GTK_STATE_FLAG_INCONSISTENT)
818 int line_thickness = MAX (1, (3 + interior_size * 2) / 7);
822 y + pad + (1 + interior_size - line_thickness) / 2,
832 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_ACTIVE, &progress);
834 if ((flags & GTK_STATE_FLAG_ACTIVE) || running)
842 cairo_scale (cr, interior_size / 7., interior_size / 7.);
844 cairo_rectangle (cr, 0, 0, 7 * progress, 7);
847 cairo_move_to (cr, 7.0, 0.0);
848 cairo_line_to (cr, 7.5, 1.0);
849 cairo_curve_to (cr, 5.3, 2.0,
852 cairo_curve_to (cr, 3.0, 5.7,
855 cairo_line_to (cr, 0.2, 3.5);
856 cairo_curve_to (cr, 1.1, 3.5,
859 cairo_curve_to (cr, 1.0, 3.9,
862 cairo_curve_to (cr, 3.5, 3.1,
872 gdk_rgba_free (fg_color);
873 gdk_rgba_free (base_color);
874 gdk_rgba_free (text_color);
878 gtk_theming_engine_render_option (GtkThemingEngine *engine,
886 GdkRGBA *base_color, *fg_color, *text_color;
887 const GtkWidgetPath *path;
888 gint exterior_size, interior_size, pad, thickness;
891 flags = gtk_theming_engine_get_state (engine);
892 path = gtk_theming_engine_get_path (engine);
893 radius = MIN (width, height) / 2 - 0.5;
897 gtk_theming_engine_get (engine, flags,
898 "foreground-color", &fg_color,
899 "base-color", &base_color,
900 "text-color", &text_color,
903 exterior_size = MIN (width, height);
905 if (exterior_size % 2 == 0) /* Ensure odd */
908 x -= (1 + exterior_size - width) / 2;
909 y -= (1 + exterior_size - height) / 2;
911 if (!gtk_theming_engine_has_class (engine, "menu"))
913 gdk_cairo_set_source_rgba (cr, base_color);
916 x + exterior_size / 2.,
917 y + exterior_size / 2.,
918 (exterior_size - 1) / 2.,
921 cairo_fill_preserve (cr);
923 if (gtk_theming_engine_has_class (engine, "cell"))
924 gdk_cairo_set_source_rgba (cr, text_color);
926 gdk_cairo_set_source_rgba (cr, fg_color);
928 cairo_set_line_width (cr, 1.);
932 if (gtk_theming_engine_has_class (engine, "menu"))
933 gdk_cairo_set_source_rgba (cr, fg_color);
935 gdk_cairo_set_source_rgba (cr, text_color);
937 /* FIXME: thickness */
940 if (flags & GTK_STATE_FLAG_INCONSISTENT)
944 pad = thickness + MAX (1, (exterior_size - 2 * thickness) / 9);
945 interior_size = MAX (1, exterior_size - 2 * pad);
947 if (interior_size < 7)
950 pad = MAX (0, (exterior_size - interior_size) / 2);
953 line_thickness = MAX (1, (3 + interior_size * 2) / 7);
957 y + pad + (interior_size - line_thickness) / 2.,
962 if (flags & GTK_STATE_FLAG_ACTIVE)
964 pad = thickness + MAX (1, 2 * (exterior_size - 2 * thickness) / 9);
965 interior_size = MAX (1, exterior_size - 2 * pad);
967 if (interior_size < 5)
970 pad = MAX (0, (exterior_size - interior_size) / 2);
974 x + pad + interior_size / 2.,
975 y + pad + interior_size / 2.,
983 gdk_rgba_free (fg_color);
984 gdk_rgba_free (base_color);
985 gdk_rgba_free (text_color);
989 add_path_arrow (cairo_t *cr,
997 cairo_translate (cr, x + (size / 2), y + (size / 2));
998 cairo_rotate (cr, angle);
1000 cairo_move_to (cr, 0, - (size / 4));
1001 cairo_line_to (cr, - (size / 2), (size / 4));
1002 cairo_line_to (cr, (size / 2), (size / 4));
1003 cairo_close_path (cr);
1009 gtk_theming_engine_render_arrow (GtkThemingEngine *engine,
1016 GtkStateFlags flags;
1021 flags = gtk_theming_engine_get_state (engine);
1023 gtk_theming_engine_get (engine, flags,
1024 "foreground-color", &fg_color,
1027 if (flags & GTK_STATE_FLAG_INSENSITIVE)
1029 add_path_arrow (cr, angle, x + 1, y + 1, size);
1030 cairo_set_source_rgb (cr, 1, 1, 1);
1034 add_path_arrow (cr, angle, x, y, size);
1035 gdk_cairo_set_source_rgba (cr, fg_color);
1040 gdk_rgba_free (fg_color);
1044 add_path_line (cairo_t *cr,
1050 /* Adjust endpoints */
1064 cairo_move_to (cr, x1, y1);
1065 cairo_line_to (cr, x2, y2);
1069 add_path_rectangle_sides (cairo_t *cr,
1076 if (sides & SIDE_TOP)
1078 cairo_move_to (cr, x, y + 0.5);
1079 cairo_line_to (cr, x + width, y + 0.5);
1082 if (sides & SIDE_RIGHT)
1084 cairo_move_to (cr, x + width - 0.5, y);
1085 cairo_line_to (cr, x + width - 0.5, y + height);
1088 if (sides & SIDE_BOTTOM)
1090 cairo_move_to (cr, x, y + height - 0.5);
1091 cairo_line_to (cr, x + width, y + height - 0.5);
1094 if (sides & SIDE_LEFT)
1096 cairo_move_to (cr, x + 0.5, y + height);
1097 cairo_line_to (cr, x + 0.5, y);
1102 add_path_gap_side (cairo_t *cr,
1103 GtkPositionType gap_side,
1114 add_path_line (cr, x, y, x + xy0_gap, y);
1115 add_path_line (cr, x + xy1_gap, y, x + width, y);
1117 case GTK_POS_BOTTOM:
1118 add_path_line (cr, x, y + height, x + xy0_gap, y + height);
1119 add_path_line (cr, x + xy1_gap, y + height, x + width, y + height);
1122 add_path_line (cr, x, y, x, y + xy0_gap);
1123 add_path_line (cr, x, y + xy1_gap, x, y + height);
1126 add_path_line (cr, x + width, y, x + width, y + xy0_gap);
1127 add_path_line (cr, x + width, y + xy1_gap, x + width, y + height);
1133 color_shade (const GdkRGBA *color,
1135 GdkRGBA *color_return)
1137 color_return->red = CLAMP (color->red * factor, 0, 1);
1138 color_return->green = CLAMP (color->green * factor, 0, 1);
1139 color_return->blue = CLAMP (color->blue * factor, 0, 1);
1140 color_return->alpha = CLAMP (color->alpha * factor, 0, 1);
1144 _cairo_round_rectangle_sides (cairo_t *cr,
1151 GtkJunctionSides junction)
1153 radius = CLAMP (radius, 0, MIN (width / 2, height / 2));
1155 if (sides & SIDE_RIGHT)
1158 (junction & GTK_JUNCTION_TOP) ||
1159 (junction & GTK_JUNCTION_RIGHT))
1160 cairo_move_to (cr, x + width, y);
1163 cairo_new_sub_path (cr);
1164 cairo_arc (cr, x + width - radius, y + radius, radius, - G_PI / 4, 0);
1168 (junction & GTK_JUNCTION_BOTTOM) ||
1169 (junction & GTK_JUNCTION_RIGHT))
1170 cairo_line_to (cr, x + width, y + height);
1172 cairo_arc (cr, x + width - radius, y + height - radius, radius, 0, G_PI / 4);
1175 if (sides & SIDE_BOTTOM)
1178 ! (junction & GTK_JUNCTION_RIGHT) &&
1179 ! (junction & GTK_JUNCTION_BOTTOM))
1181 if ((sides & SIDE_RIGHT) == 0)
1182 cairo_new_sub_path (cr);
1184 cairo_arc (cr, x + width - radius, y + height - radius, radius, G_PI / 4, G_PI / 2);
1188 (junction & GTK_JUNCTION_BOTTOM) ||
1189 (junction & GTK_JUNCTION_LEFT))
1190 cairo_line_to (cr, x, y + height);
1192 cairo_arc (cr, x + radius, y + height - radius, radius, G_PI / 2, 3 * (G_PI / 4));
1195 cairo_move_to (cr, x, y + height);
1197 if (sides & SIDE_LEFT)
1200 ! (junction & GTK_JUNCTION_LEFT) &&
1201 ! (junction & GTK_JUNCTION_BOTTOM))
1203 if ((sides & SIDE_BOTTOM) == 0)
1204 cairo_new_sub_path (cr);
1206 cairo_arc (cr, x + radius, y + height - radius, radius, 3 * (G_PI / 4), G_PI);
1210 (junction & GTK_JUNCTION_TOP) ||
1211 (junction & GTK_JUNCTION_LEFT))
1212 cairo_line_to (cr, x, y);
1214 cairo_arc (cr, x + radius, y + radius, radius, G_PI, G_PI + G_PI / 4);
1217 if (sides & SIDE_TOP)
1220 ! (junction & GTK_JUNCTION_TOP) &&
1221 ! (junction & GTK_JUNCTION_LEFT))
1223 if ((sides & SIDE_TOP) == 0)
1224 cairo_new_sub_path (cr);
1226 cairo_arc (cr, x + radius, y + radius, radius, 5 * (G_PI / 4), 3 * (G_PI / 2));
1230 (junction & GTK_JUNCTION_TOP) ||
1231 (junction & GTK_JUNCTION_RIGHT))
1232 cairo_line_to (cr, x + width, y);
1234 cairo_arc (cr, x + width - radius, y + radius, radius, 3 * (G_PI / 2), - G_PI / 4);
1239 gtk_theming_engine_render_background (GtkThemingEngine *engine,
1246 GdkRGBA *bg_color, *base_color;
1247 cairo_pattern_t *pattern;
1248 GtkStateFlags flags;
1250 gdouble progress, alpha = 1;
1251 GtkJunctionSides junction;
1254 flags = gtk_theming_engine_get_state (engine);
1255 junction = gtk_theming_engine_get_junction_sides (engine);
1258 if (gtk_theming_engine_has_class (engine, "spinbutton") &&
1259 gtk_theming_engine_has_class (engine, "button"))
1267 gtk_theming_engine_get (engine, flags,
1268 "background-image", &pattern,
1269 "background-color", &bg_color,
1270 "base-color", &base_color,
1271 "border-radius", &radius,
1274 running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
1276 _cairo_round_rectangle_sides (cr, (gdouble) radius,
1277 x, y, width, height,
1278 SIDE_ALL, junction);
1281 cairo_translate (cr, x, y);
1282 cairo_scale (cr, width, height);
1286 cairo_pattern_t *other_pattern;
1287 GtkStateFlags other_flags;
1288 GdkRGBA *other_bg, *other_base;
1289 cairo_pattern_t *new_pattern = NULL;
1291 if (flags & GTK_STATE_FLAG_PRELIGHT)
1293 other_flags = flags & ~(GTK_STATE_FLAG_PRELIGHT);
1294 progress = 1 - progress;
1297 other_flags = flags | GTK_STATE_FLAG_PRELIGHT;
1299 gtk_theming_engine_get (engine, other_flags,
1300 "background-image", &other_pattern,
1301 "background-color", &other_bg,
1302 "base-color", &other_base,
1305 if (pattern && other_pattern)
1307 cairo_pattern_type_t type, other_type;
1310 cairo_pattern_get_color_stop_count (pattern, &n0);
1311 cairo_pattern_get_color_stop_count (other_pattern, &n1);
1312 type = cairo_pattern_get_type (pattern);
1313 other_type = cairo_pattern_get_type (other_pattern);
1315 if (type == other_type && n0 == n1)
1317 gdouble offset0, red0, green0, blue0, alpha0;
1318 gdouble offset1, red1, green1, blue1, alpha1;
1319 gdouble x00, x01, y00, y01, x10, x11, y10, y11;
1320 gdouble r00, r01, r10, r11;
1323 if (type == CAIRO_PATTERN_TYPE_LINEAR)
1325 cairo_pattern_get_linear_points (pattern, &x00, &y00, &x01, &y01);
1326 cairo_pattern_get_linear_points (other_pattern, &x10, &y10, &x11, &y11);
1328 new_pattern = cairo_pattern_create_linear (x00 + (x10 - x00) * progress,
1329 y00 + (y10 - y00) * progress,
1330 x01 + (x11 - x01) * progress,
1331 y01 + (y11 - y01) * progress);
1335 cairo_pattern_get_radial_circles (pattern, &x00, &y00, &r00, &x01, &y01, &r01);
1336 cairo_pattern_get_radial_circles (other_pattern, &x10, &y10, &r10, &x11, &y11, &r11);
1338 new_pattern = cairo_pattern_create_radial (x00 + (x10 - x00) * progress,
1339 y00 + (y10 - y00) * progress,
1340 r00 + (r10 - r00) * progress,
1341 x01 + (x11 - x01) * progress,
1342 y01 + (y11 - y01) * progress,
1343 r01 + (r11 - r01) * progress);
1346 cairo_pattern_set_filter (new_pattern, CAIRO_FILTER_FAST);
1349 /* Blend both gradients into one */
1350 while (i < n0 && i < n1)
1352 cairo_pattern_get_color_stop_rgba (pattern, i,
1354 &red0, &green0, &blue0,
1356 cairo_pattern_get_color_stop_rgba (other_pattern, i,
1358 &red1, &green1, &blue1,
1361 cairo_pattern_add_color_stop_rgba (new_pattern,
1362 offset0 + ((offset1 - offset0) * progress),
1363 red0 + ((red1 - red0) * progress),
1364 green0 + ((green1 - green0) * progress),
1365 blue0 + ((blue1 - blue0) * progress),
1366 alpha0 + ((alpha1 - alpha0) * progress));
1372 /* Different pattern types, or different color
1373 * stop counts, alpha blend both patterns.
1375 cairo_rectangle (cr, 0, 0, 1, 1);
1376 cairo_set_source (cr, other_pattern);
1377 cairo_fill_preserve (cr);
1379 /* Set alpha for posterior drawing
1380 * of the target pattern
1382 alpha = 1 - progress;
1385 else if (pattern || other_pattern)
1389 gdouble x0, y0, x1, y1, r0, r1;
1392 /* Blend a pattern with a color */
1396 c = gtk_theming_engine_has_class (engine, "entry") ? other_base : other_bg;
1397 progress = 1 - progress;
1402 c = gtk_theming_engine_has_class (engine, "entry") ? base_color : bg_color;
1405 if (cairo_pattern_get_type (p) == CAIRO_PATTERN_TYPE_LINEAR)
1407 cairo_pattern_get_linear_points (p, &x0, &y0, &x1, &y1);
1408 new_pattern = cairo_pattern_create_linear (x0, y0, x1, y1);
1412 cairo_pattern_get_radial_circles (p, &x0, &y0, &r0, &x1, &y1, &r1);
1413 new_pattern = cairo_pattern_create_radial (x0, y0, r0, x1, y1, r1);
1416 cairo_pattern_get_color_stop_count (p, &n);
1418 for (i = 0; i < n; i++)
1420 gdouble red1, green1, blue1, alpha1;
1423 cairo_pattern_get_color_stop_rgba (p, i,
1425 &red1, &green1, &blue1,
1427 cairo_pattern_add_color_stop_rgba (new_pattern, offset,
1428 c->red + ((red1 - c->red) * progress),
1429 c->green + ((green1 - c->green) * progress),
1430 c->blue + ((blue1 - c->blue) * progress),
1431 c->alpha + ((alpha1 - c->alpha) * progress));
1436 const GdkRGBA *color, *other_color;
1438 /* Merge just colors */
1439 if (gtk_theming_engine_has_class (engine, "entry"))
1442 other_color = other_base;
1447 other_color = other_bg;
1450 new_pattern = cairo_pattern_create_rgba (CLAMP (color->red + ((other_color->red - color->red) * progress), 0, 1),
1451 CLAMP (color->green + ((other_color->green - color->green) * progress), 0, 1),
1452 CLAMP (color->blue + ((other_color->blue - color->blue) * progress), 0, 1),
1453 CLAMP (color->alpha + ((other_color->alpha - color->alpha) * progress), 0, 1));
1458 /* Replace pattern to use */
1459 cairo_pattern_destroy (pattern);
1460 pattern = new_pattern;
1464 cairo_pattern_destroy (other_pattern);
1467 gdk_rgba_free (other_bg);
1470 gdk_rgba_free (other_base);
1473 cairo_rectangle (cr, 0, 0, 1, 1);
1477 cairo_set_source (cr, pattern);
1478 cairo_pattern_destroy (pattern);
1482 if (gtk_theming_engine_has_class (engine, "entry"))
1483 gdk_cairo_set_source_rgba (cr, base_color);
1485 gdk_cairo_set_source_rgba (cr, bg_color);
1488 if (gtk_theming_engine_has_class (engine, "tooltip"))
1490 cairo_fill_preserve (cr);
1492 cairo_set_source_rgb (cr, 0, 0, 0);
1501 cairo_pattern_t *mask;
1503 mask = cairo_pattern_create_rgba (1, 1, 1, alpha);
1504 cairo_mask (cr, mask);
1505 cairo_pattern_destroy (mask);
1511 gdk_rgba_free (base_color);
1512 gdk_rgba_free (bg_color);
1516 gtk_theming_engine_render_frame (GtkThemingEngine *engine,
1523 GtkStateFlags flags;
1524 GdkRGBA lighter, darker;
1525 GdkRGBA *border_color;
1527 GtkBorderStyle border_style;
1528 gint border_width, radius;
1529 GtkJunctionSides junction;
1531 flags = gtk_theming_engine_get_state (engine);
1532 junction = gtk_theming_engine_get_junction_sides (engine);
1534 gtk_theming_engine_get (engine, flags,
1535 "border-image", &slice,
1536 "border-color", &border_color,
1537 "border-style", &border_style,
1538 "border-width", &border_width,
1539 "border-radius", &radius,
1544 gtk_9slice_render (slice, cr, x, y, width, height);
1545 gtk_9slice_unref (slice);
1547 else if (border_style != GTK_BORDER_STYLE_NONE)
1551 color_shade (border_color, 0.7, &darker);
1552 color_shade (border_color, 1.3, &lighter);
1554 switch (border_style)
1556 case GTK_BORDER_STYLE_NONE:
1558 case GTK_BORDER_STYLE_SOLID:
1559 cairo_set_line_width (cr, border_width);
1561 if (border_width > 1)
1563 x += (gdouble) border_width / 2;
1564 y += (gdouble) border_width / 2;
1565 width -= border_width;
1566 height -= border_width;
1569 _cairo_round_rectangle_sides (cr, (gdouble) radius, x, y, width, height,
1570 SIDE_ALL, junction);
1571 gdk_cairo_set_source_rgba (cr, border_color);
1575 case GTK_BORDER_STYLE_INSET:
1576 case GTK_BORDER_STYLE_OUTSET:
1577 cairo_set_line_width (cr, border_width);
1578 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
1580 if (border_width > 1)
1584 d = border_width / 2;
1591 if (border_style == GTK_BORDER_STYLE_INSET)
1592 gdk_cairo_set_source_rgba (cr, border_color);
1594 gdk_cairo_set_source_rgba (cr, &darker);
1596 _cairo_round_rectangle_sides (cr, (gdouble) radius, x, y, width, height,
1597 SIDE_BOTTOM | SIDE_RIGHT, junction);
1600 if (border_style == GTK_BORDER_STYLE_INSET)
1601 gdk_cairo_set_source_rgba (cr, &darker);
1603 gdk_cairo_set_source_rgba (cr, border_color);
1605 _cairo_round_rectangle_sides (cr, (gdouble) radius, x, y, width, height,
1606 SIDE_TOP | SIDE_LEFT, junction);
1616 gdk_rgba_free (border_color);
1620 gtk_theming_engine_render_expander (GtkThemingEngine *engine,
1627 GtkStateFlags flags;
1628 GdkRGBA *bg_color, *fg_color, *base_color;
1629 double vertical_overshoot;
1632 double interp; /* interpolation factor for center position */
1633 double x_double_horz, y_double_horz;
1634 double x_double_vert, y_double_vert;
1635 double x_double, y_double;
1640 flags = gtk_theming_engine_get_state (engine);
1642 gtk_theming_engine_get (engine, flags,
1643 "foreground-color", &fg_color,
1644 "background-color", &bg_color,
1645 "base-color", &base_color,
1650 /* FIXME: LTR/RTL */
1651 if (flags & GTK_STATE_FLAG_ACTIVE)
1662 /* Compute distance that the stroke extends beyonds the end
1663 * of the triangle we draw.
1665 vertical_overshoot = line_width / 2.0 * (1. / tan (G_PI / 8));
1667 /* For odd line widths, we end the vertical line of the triangle
1668 * at a half pixel, so we round differently.
1670 if (line_width % 2 == 1)
1671 vertical_overshoot = ceil (0.5 + vertical_overshoot) - 0.5;
1673 vertical_overshoot = ceil (vertical_overshoot);
1675 /* Adjust the size of the triangle we draw so that the entire stroke fits
1677 diameter = (gint) MAX (3, width - 2 * vertical_overshoot);
1679 /* If the line width is odd, we want the diameter to be even,
1680 * and vice versa, so force the sum to be odd. This relationship
1681 * makes the point of the triangle look right.
1683 diameter -= (1 - (diameter + line_width) % 2);
1685 radius = diameter / 2.;
1687 /* Adjust the center so that the stroke is properly aligned with
1688 * the pixel grid. The center adjustment is different for the
1689 * horizontal and vertical orientations. For intermediate positions
1690 * we interpolate between the two.
1692 x_double_vert = floor ((x + width / 2) - (radius + line_width) / 2.) + (radius + line_width) / 2.;
1693 y_double_vert = (y + height / 2) - 0.5;
1695 x_double_horz = (x + width / 2) - 0.5;
1696 y_double_horz = floor ((y + height / 2) - (radius + line_width) / 2.) + (radius + line_width) / 2.;
1698 x_double = x_double_vert * (1 - interp) + x_double_horz * interp;
1699 y_double = y_double_vert * (1 - interp) + y_double_horz * interp;
1701 cairo_translate (cr, x_double, y_double);
1702 cairo_rotate (cr, angle);
1704 cairo_move_to (cr, - radius / 2., - radius);
1705 cairo_line_to (cr, radius / 2., 0);
1706 cairo_line_to (cr, - radius / 2., radius);
1707 cairo_close_path (cr);
1709 cairo_set_line_width (cr, line_width);
1711 if (flags & GTK_STATE_FLAG_PRELIGHT)
1712 gdk_cairo_set_source_rgba (cr, fg_color);
1714 gdk_cairo_set_source_rgba (cr, base_color);
1716 cairo_fill_preserve (cr);
1718 gdk_cairo_set_source_rgba (cr, fg_color);
1723 gdk_rgba_free (base_color);
1724 gdk_rgba_free (fg_color);
1725 gdk_rgba_free (bg_color);
1729 gtk_theming_engine_render_focus (GtkThemingEngine *engine,
1736 GtkStateFlags flags;
1742 flags = gtk_theming_engine_get_state (engine);
1744 gtk_theming_engine_get (engine, flags,
1745 "foreground-color", &color,
1748 gtk_theming_engine_get_style (engine,
1749 "focus-line-width", &line_width,
1750 "focus-line-pattern", (gchar *) &dash_list,
1753 cairo_set_line_width (cr, (gdouble) line_width);
1757 gint n_dashes = strlen ((const gchar *) dash_list);
1758 gdouble *dashes = g_new (gdouble, n_dashes);
1759 gdouble total_length = 0;
1760 gdouble dash_offset;
1763 for (i = 0; i < n_dashes; i++)
1765 dashes[i] = dash_list[i];
1766 total_length += dash_list[i];
1769 /* The dash offset here aligns the pattern to integer pixels
1770 * by starting the dash at the right side of the left border
1771 * Negative dash offsets in cairo don't work
1772 * (https://bugs.freedesktop.org/show_bug.cgi?id=2729)
1774 dash_offset = - line_width / 2.;
1776 while (dash_offset < 0)
1777 dash_offset += total_length;
1779 cairo_set_dash (cr, dashes, n_dashes, dash_offset);
1783 cairo_rectangle (cr,
1784 x + line_width / 2.,
1785 y + line_width / 2.,
1787 height - line_width);
1789 gdk_cairo_set_source_rgba (cr, color);
1794 gdk_rgba_free (color);
1799 gtk_theming_engine_render_line (GtkThemingEngine *engine,
1806 GdkRGBA *bg_color, darker, lighter;
1807 GtkStateFlags flags;
1808 gint i, thickness, thickness_dark, thickness_light, len;
1809 cairo_matrix_t matrix;
1812 /* FIXME: thickness */
1814 thickness_dark = thickness / 2;
1815 thickness_light = thickness - thickness_dark;
1817 flags = gtk_theming_engine_get_state (engine);
1820 gtk_theming_engine_get (engine, flags,
1821 "background-color", &bg_color,
1823 color_shade (bg_color, 0.7, &darker);
1824 color_shade (bg_color, 1.3, &lighter);
1826 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
1827 cairo_set_line_width (cr, 1);
1829 angle = atan2 (x1 - x0, y1 - y0);
1830 angle = (2 * G_PI) - angle;
1833 cairo_get_matrix (cr, &matrix);
1834 cairo_matrix_translate (&matrix, x0, y0);
1835 cairo_matrix_rotate (&matrix, angle);
1836 cairo_set_matrix (cr, &matrix);
1841 len = (gint) sqrt ((x1 * x1) + (y1 * y1));
1843 y0 = -thickness_dark;
1845 for (i = 0; i < thickness_dark; i++)
1847 gdk_cairo_set_source_rgba (cr, &lighter);
1848 add_path_line (cr, len - i - 1.5, y0, len - 0.5, y0);
1851 gdk_cairo_set_source_rgba (cr, &darker);
1852 add_path_line (cr, 0.5, y0, len - i - 1.5, y0);
1858 for (i = 0; i < thickness_light; i++)
1860 gdk_cairo_set_source_rgba (cr, &darker);
1861 add_path_line (cr, 0.5, y0, thickness_light - i + 0.5, y0);
1864 gdk_cairo_set_source_rgba (cr, &lighter);
1865 add_path_line (cr, thickness_light - i + 0.5, y0, len - 0.5, y0);
1873 gdk_rgba_free (bg_color);
1877 gtk_theming_engine_render_layout (GtkThemingEngine *engine,
1881 PangoLayout *layout)
1883 const PangoMatrix *matrix;
1885 GtkStateFlags flags;
1889 flags = gtk_theming_engine_get_state (engine);
1891 gtk_theming_engine_get (engine, flags,
1892 "foreground-color", &fg_color,
1895 screen = gtk_theming_engine_get_screen (engine);
1896 matrix = pango_context_get_matrix (pango_layout_get_context (layout));
1900 cairo_matrix_t cairo_matrix;
1901 PangoMatrix tmp_matrix;
1902 PangoRectangle rect;
1904 cairo_matrix_init (&cairo_matrix,
1905 matrix->xx, matrix->yx,
1906 matrix->xy, matrix->yy,
1907 matrix->x0, matrix->y0);
1909 pango_layout_get_extents (layout, NULL, &rect);
1910 pango_matrix_transform_rectangle (matrix, &rect);
1911 pango_extents_to_pixels (&rect, NULL);
1913 tmp_matrix = *matrix;
1914 cairo_matrix.x0 += x - rect.x;
1915 cairo_matrix.y0 += y - rect.y;
1917 cairo_set_matrix (cr, &cairo_matrix);
1920 cairo_translate (cr, x, y);
1922 if (flags & GTK_STATE_FLAG_INSENSITIVE)
1925 cairo_set_source_rgb (cr, 1, 1, 1);
1926 cairo_move_to (cr, 1, 1);
1927 _gtk_pango_fill_layout (cr, layout);
1931 gdk_cairo_set_source_rgba (cr, fg_color);
1932 pango_cairo_show_layout (cr, layout);
1936 gdk_rgba_free (fg_color);
1940 gtk_theming_engine_render_slider (GtkThemingEngine *engine,
1946 GtkOrientation orientation)
1948 const GtkWidgetPath *path;
1951 path = gtk_theming_engine_get_path (engine);
1953 gtk_theming_engine_render_background (engine, cr, x, y, width, height);
1954 gtk_theming_engine_render_frame (engine, cr, x, y, width, height);
1956 /* FIXME: thickness */
1959 if (gtk_widget_path_is_type (path, GTK_TYPE_SCALE))
1961 if (orientation == GTK_ORIENTATION_VERTICAL)
1962 gtk_theming_engine_render_line (engine, cr,
1964 y + (gint) height / 2,
1965 x + width - thickness - 1,
1966 y + (gint) height / 2);
1968 gtk_theming_engine_render_line (engine, cr,
1969 x + (gint) width / 2,
1971 x + (gint) width / 2,
1972 y + height - thickness - 1);
1977 gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
1983 GtkPositionType gap_side,
1987 GtkStateFlags flags;
1989 GdkRGBA lighter, darker;
1993 flags = gtk_theming_engine_get_state (engine);
1995 cairo_set_line_width (cr, 1);
1997 gtk_theming_engine_get (engine, flags,
1998 "background-color", &bg_color,
2000 color_shade (bg_color, 0.7, &darker);
2001 color_shade (bg_color, 1.3, &lighter);
2003 if (gtk_theming_engine_has_class (engine, "frame"))
2005 if (gap_side == GTK_POS_RIGHT)
2006 sides = SIDE_BOTTOM;
2007 else if (gap_side == GTK_POS_BOTTOM)
2010 sides = SIDE_BOTTOM | SIDE_RIGHT;
2012 gdk_cairo_set_source_rgba (cr, &lighter);
2013 add_path_rectangle_sides (cr, x , y, width , height, sides);
2016 gdk_cairo_set_source_rgba (cr, &darker);
2017 add_path_rectangle_sides (cr, x, y, width - 1, height - 1, sides);
2020 if (gap_side == GTK_POS_RIGHT ||
2021 gap_side == GTK_POS_BOTTOM)
2023 gdk_cairo_set_source_rgba (cr, &darker);
2024 add_path_gap_side (cr, gap_side,
2025 x + 1, y + 1, width - 4, height - 4,
2029 gdk_cairo_set_source_rgba (cr, &lighter);
2030 add_path_gap_side (cr, gap_side,
2031 x, y, width, height,
2036 if (gap_side == GTK_POS_LEFT)
2038 else if (gap_side == GTK_POS_TOP)
2041 sides = SIDE_TOP | SIDE_LEFT;
2043 gdk_cairo_set_source_rgba (cr, &lighter);
2044 add_path_rectangle_sides (cr, x + 1, y + 1, width - 2, height - 3, sides);
2047 gdk_cairo_set_source_rgba (cr, &darker);
2048 add_path_rectangle_sides (cr, x, y, width - 1, height - 1, sides);
2051 if (gap_side == GTK_POS_LEFT ||
2052 gap_side == GTK_POS_TOP)
2054 gdk_cairo_set_source_rgba (cr, &lighter);
2055 add_path_gap_side (cr, gap_side,
2056 x + 1, y + 1, width - 4, height - 4,
2060 gdk_cairo_set_source_rgba (cr, &darker);
2061 add_path_gap_side (cr, gap_side,
2062 x, y, width - 2, height - 2,
2069 if (gap_side == GTK_POS_RIGHT)
2070 sides = SIDE_BOTTOM;
2071 else if (gap_side == GTK_POS_BOTTOM)
2074 sides = SIDE_BOTTOM | SIDE_RIGHT;
2076 gdk_cairo_set_source_rgba (cr, &darker);
2077 add_path_rectangle_sides (cr, x + 1, y, width - 2, height, sides);
2078 add_path_rectangle_sides (cr, x, y + 1, width, height - 2, sides);
2081 cairo_set_source_rgb (cr, 0, 0, 0);
2082 add_path_rectangle_sides (cr, x, y, width, height, sides);
2085 if (gap_side == GTK_POS_RIGHT ||
2086 gap_side == GTK_POS_BOTTOM)
2088 gdk_cairo_set_source_rgba (cr, &darker);
2089 add_path_gap_side (cr, gap_side,
2090 x, y, width - 2, height - 2,
2094 cairo_set_source_rgb (cr, 0, 0, 0);
2095 add_path_gap_side (cr, gap_side,
2096 x, y, width - 1, height - 1,
2101 if (gap_side == GTK_POS_LEFT)
2103 else if (gap_side == GTK_POS_TOP)
2106 sides = SIDE_TOP | SIDE_LEFT;
2108 gdk_cairo_set_source_rgba (cr, &lighter);
2109 add_path_rectangle_sides (cr, x, y, width, height, sides);
2112 if (gap_side == GTK_POS_LEFT ||
2113 gap_side == GTK_POS_TOP)
2115 add_path_gap_side (cr, gap_side,
2116 x, y, width, height,
2124 gdk_rgba_free (bg_color);
2128 gtk_theming_engine_render_extension (GtkThemingEngine *engine,
2134 GtkPositionType gap_side)
2136 GtkStateFlags flags;
2138 GdkRGBA lighter, darker;
2141 flags = gtk_theming_engine_get_state (engine);
2143 cairo_set_line_width (cr, 1);
2145 gtk_theming_engine_get (engine, flags,
2146 "background-color", &bg_color,
2148 color_shade (bg_color, 0.7, &darker);
2149 color_shade (bg_color, 1.3, &lighter);
2154 gdk_cairo_set_source_rgba (cr, bg_color);
2155 cairo_rectangle (cr, x + 1, y, width - 2, height);
2158 gdk_cairo_set_source_rgba (cr, &lighter);
2159 add_path_line (cr, x, y, x, y + height - 2);
2162 gdk_cairo_set_source_rgba (cr, bg_color);
2163 add_path_line (cr, x + 1, y, x + 1, y + height - 2);
2166 gdk_cairo_set_source_rgba (cr, &darker);
2167 add_path_line (cr, x + 2, y + height - 2, x + width - 2, y + height - 2);
2168 add_path_line (cr, x + width - 2, y, x + width - 2, y + height - 2);
2171 cairo_set_source_rgb (cr, 0, 0, 0);
2172 add_path_line (cr, x + 1, y + height - 1, x + width - 2, y + height - 1);
2173 add_path_line (cr, x + width - 1, y, x + width - 1, y + height - 2);
2177 case GTK_POS_BOTTOM:
2178 gdk_cairo_set_source_rgba(cr, bg_color);
2179 cairo_rectangle (cr, x + 1, y, width - 2, height);
2182 gdk_cairo_set_source_rgba (cr, &lighter);
2183 add_path_line (cr, x + 1, y, x + width - 2, y);
2184 add_path_line (cr, x, y + 1, x, y + height - 1);
2187 gdk_cairo_set_source_rgba (cr, bg_color);
2188 add_path_line (cr, x + 1, y + 1, x + width - 2, y + 1);
2189 add_path_line (cr, x + 1, y + 1, x + 1, y + height - 1);
2192 gdk_cairo_set_source_rgba (cr, &darker);
2193 add_path_line (cr, x + width - 2, y + 2, x + width - 2, y + height - 1);
2196 cairo_set_source_rgb (cr, 0, 0, 0);
2197 add_path_line (cr, x + width - 1, y + 1, x + width - 1, y + height - 1);
2202 gdk_cairo_set_source_rgba (cr, bg_color);
2203 cairo_rectangle (cr, x, y + 1, width, height - 2);
2206 gdk_cairo_set_source_rgba (cr, &lighter);
2207 add_path_line (cr, x, y, x + width - 2, y);
2210 gdk_cairo_set_source_rgba (cr, bg_color);
2211 add_path_line (cr, x + 1, y + 1, x + width - 2, y + 1);
2214 gdk_cairo_set_source_rgba (cr, &darker);
2215 add_path_line (cr, x, y + height - 2, x + width - 2, y + height - 2);
2216 add_path_line (cr, x + width - 2, y + 2, x + width - 2, y + height - 2);
2219 cairo_set_source_rgb (cr, 0, 0, 0);
2220 add_path_line (cr, x, y + height - 1, x + width - 2, y + height - 1);
2221 add_path_line (cr, x + width - 1, y + 1, x + width - 1, y + height - 2);
2226 gdk_cairo_set_source_rgba (cr, bg_color);
2227 cairo_rectangle (cr, x, y + 1, width, height - 2);
2230 gdk_cairo_set_source_rgba (cr, &lighter);
2231 add_path_line (cr, x + 1, y, x + width - 1, y);
2232 add_path_line (cr, x, y + 1, x, y + height - 2);
2235 gdk_cairo_set_source_rgba (cr, bg_color);
2236 add_path_line (cr, x + 1, y + 1, x + width - 1, y + 1);
2237 add_path_line (cr, x + 1, y + 1, x + 1, y + height - 2);
2240 gdk_cairo_set_source_rgba (cr, &darker);
2241 add_path_line (cr, x + 2, y + height - 2, x + width - 1, y + height - 2);
2244 cairo_set_source_rgb (cr, 0, 0, 0);
2245 add_path_line (cr, x + 1, y + height - 1, x + width - 1, y + height - 1);
2253 gdk_rgba_free (bg_color);
2257 render_dot (cairo_t *cr,
2258 const GdkRGBA *lighter,
2259 const GdkRGBA *darker,
2264 size = CLAMP ((gint) size, 2, 3);
2268 gdk_cairo_set_source_rgba (cr, lighter);
2269 cairo_rectangle (cr, x, y, 1, 1);
2270 cairo_rectangle (cr, x + 1, y + 1, 1, 1);
2275 gdk_cairo_set_source_rgba (cr, lighter);
2276 cairo_rectangle (cr, x, y, 2, 1);
2277 cairo_rectangle (cr, x, y, 1, 2);
2280 gdk_cairo_set_source_rgba (cr, darker);
2281 cairo_rectangle (cr, x + 1, y + 1, 2, 1);
2282 cairo_rectangle (cr, x + 2, y, 1, 2);
2288 gtk_theming_engine_render_handle (GtkThemingEngine *engine,
2295 GtkStateFlags flags;
2297 GdkRGBA lighter, darker;
2301 flags = gtk_theming_engine_get_state (engine);
2303 cairo_set_line_width (cr, 1);
2305 gtk_theming_engine_get (engine, flags,
2306 "background-color", &bg_color,
2308 color_shade (bg_color, 0.7, &darker);
2309 color_shade (bg_color, 1.3, &lighter);
2311 gdk_cairo_set_source_rgba (cr, bg_color);
2312 cairo_rectangle (cr, x, y, width, height);
2315 if (gtk_theming_engine_has_class (engine, "paned"))
2318 for (xx = x + width / 2 - 15; xx <= x + width / 2 + 15; xx += 5)
2319 render_dot (cr, &lighter, &darker, xx, y + height / 2 - 1, 3);
2321 for (yy = y + height / 2 - 15; yy <= y + height / 2 + 15; yy += 5)
2322 render_dot (cr, &lighter, &darker, x + width / 2 - 1, yy, 3);
2326 for (yy = y; yy < y + height; yy += 3)
2327 for (xx = x; xx < x + width; xx += 6)
2329 render_dot (cr, &lighter, &darker, xx, yy, 2);
2330 render_dot (cr, &lighter, &darker, xx + 3, yy + 1, 2);
2336 gdk_rgba_free (bg_color);