1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
31 #include <gobject/gvaluecollector.h>
32 #include "gtkmarshalers.h"
35 #include "gtkspinbutton.h"
37 #include "gtkwidget.h"
38 #include "gtkthemes.h"
39 #include "gtkiconfactory.h"
40 #include "gtksettings.h" /* _gtk_settings_parse_convert() */
43 #include "gtkspinner.h"
44 #include "gtkborder.h"
49 * @Short_description: An object that hold style information for widgets
52 * A #GtkStyle object encapsulates the information that provides the look and
53 * feel for a widget. Each #GtkWidget has an associated #GTkStyle object that
54 * is used when rendering that widget. Also, a #GtkStyle holds information for
55 * the five possible widget states though not every widget supports all five
56 * states; see #GtkStateType.
58 * Usually the #GtkStyle for a widget is the same as the default style that is
59 * set by GTK+ and modified the theme engine.
61 * Usually applications should not need to use or modify the #GtkStyle of their
65 * In GTK+ 3.0, GtkStyle has been deprecated and replaced by #GtkStyleContext.
70 #define LIGHTNESS_MULT 1.3
71 #define DARKNESS_MULT 0.7
73 /* --- typedefs & structures --- */
80 #define GTK_STYLE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_STYLE, GtkStylePrivate))
82 typedef struct _GtkStylePrivate GtkStylePrivate;
84 struct _GtkStylePrivate {
86 GtkStyleContext *context;
87 gulong context_changed_id;
95 /* --- prototypes --- */
96 static void gtk_style_finalize (GObject *object);
97 static void gtk_style_constructed (GObject *object);
98 static void gtk_style_set_property (GObject *object,
102 static void gtk_style_get_property (GObject *object,
107 static void gtk_style_realize (GtkStyle *style,
109 static void gtk_style_real_realize (GtkStyle *style);
110 static void gtk_style_real_unrealize (GtkStyle *style);
111 static void gtk_style_real_copy (GtkStyle *style,
113 static void gtk_style_real_set_background (GtkStyle *style,
115 GtkStateType state_type);
116 static GtkStyle *gtk_style_real_clone (GtkStyle *style);
117 static void gtk_style_real_init_from_rc (GtkStyle *style,
118 GtkRcStyle *rc_style);
119 static GdkPixbuf *gtk_default_render_icon (GtkStyle *style,
120 const GtkIconSource *source,
121 GtkTextDirection direction,
125 const gchar *detail);
126 static void gtk_default_draw_hline (GtkStyle *style,
128 GtkStateType state_type,
134 static void gtk_default_draw_vline (GtkStyle *style,
136 GtkStateType state_type,
142 static void gtk_default_draw_shadow (GtkStyle *style,
144 GtkStateType state_type,
145 GtkShadowType shadow_type,
152 static void gtk_default_draw_arrow (GtkStyle *style,
154 GtkStateType state_type,
155 GtkShadowType shadow_type,
158 GtkArrowType arrow_type,
164 static void gtk_default_draw_diamond (GtkStyle *style,
166 GtkStateType state_type,
167 GtkShadowType shadow_type,
174 static void gtk_default_draw_box (GtkStyle *style,
176 GtkStateType state_type,
177 GtkShadowType shadow_type,
184 static void gtk_default_draw_flat_box (GtkStyle *style,
186 GtkStateType state_type,
187 GtkShadowType shadow_type,
194 static void gtk_default_draw_check (GtkStyle *style,
196 GtkStateType state_type,
197 GtkShadowType shadow_type,
204 static void gtk_default_draw_option (GtkStyle *style,
206 GtkStateType state_type,
207 GtkShadowType shadow_type,
214 static void gtk_default_draw_tab (GtkStyle *style,
216 GtkStateType state_type,
217 GtkShadowType shadow_type,
224 static void gtk_default_draw_shadow_gap (GtkStyle *style,
226 GtkStateType state_type,
227 GtkShadowType shadow_type,
234 GtkPositionType gap_side,
237 static void gtk_default_draw_box_gap (GtkStyle *style,
239 GtkStateType state_type,
240 GtkShadowType shadow_type,
247 GtkPositionType gap_side,
250 static void gtk_default_draw_extension (GtkStyle *style,
252 GtkStateType state_type,
253 GtkShadowType shadow_type,
260 GtkPositionType gap_side);
261 static void gtk_default_draw_focus (GtkStyle *style,
263 GtkStateType state_type,
270 static void gtk_default_draw_slider (GtkStyle *style,
272 GtkStateType state_type,
273 GtkShadowType shadow_type,
280 GtkOrientation orientation);
281 static void gtk_default_draw_handle (GtkStyle *style,
283 GtkStateType state_type,
284 GtkShadowType shadow_type,
291 GtkOrientation orientation);
292 static void gtk_default_draw_expander (GtkStyle *style,
294 GtkStateType state_type,
299 GtkExpanderStyle expander_style);
300 static void gtk_default_draw_layout (GtkStyle *style,
302 GtkStateType state_type,
308 PangoLayout *layout);
309 static void gtk_default_draw_resize_grip (GtkStyle *style,
311 GtkStateType state_type,
319 static void gtk_default_draw_spinner (GtkStyle *style,
321 GtkStateType state_type,
330 static void rgb_to_hls (gdouble *r,
333 static void hls_to_rgb (gdouble *h,
337 static void style_unrealize_cursors (GtkStyle *style);
339 static void transform_detail_string (const gchar *detail,
340 GtkStyleContext *context);
343 * Data for default check and radio buttons
346 static const GtkRequisition default_option_indicator_size = { 7, 13 };
347 static const GtkBorder default_option_indicator_spacing = { 7, 5, 2, 2 };
349 #define GTK_GRAY 0xdcdc, 0xdada, 0xd5d5
350 #define GTK_DARK_GRAY 0xc4c4, 0xc2c2, 0xbdbd
351 #define GTK_LIGHT_GRAY 0xeeee, 0xebeb, 0xe7e7
352 #define GTK_WHITE 0xffff, 0xffff, 0xffff
353 #define GTK_BLUE 0x4b4b, 0x6969, 0x8383
354 #define GTK_VERY_DARK_GRAY 0x9c9c, 0x9a9a, 0x9494
355 #define GTK_BLACK 0x0000, 0x0000, 0x0000
356 #define GTK_WEAK_GRAY 0x7530, 0x7530, 0x7530
358 /* --- variables --- */
359 static const GdkColor gtk_default_normal_fg = { 0, GTK_BLACK };
360 static const GdkColor gtk_default_active_fg = { 0, GTK_BLACK };
361 static const GdkColor gtk_default_prelight_fg = { 0, GTK_BLACK };
362 static const GdkColor gtk_default_selected_fg = { 0, GTK_WHITE };
363 static const GdkColor gtk_default_insensitive_fg = { 0, GTK_WEAK_GRAY };
365 static const GdkColor gtk_default_normal_bg = { 0, GTK_GRAY };
366 static const GdkColor gtk_default_active_bg = { 0, GTK_DARK_GRAY };
367 static const GdkColor gtk_default_prelight_bg = { 0, GTK_LIGHT_GRAY };
368 static const GdkColor gtk_default_selected_bg = { 0, GTK_BLUE };
369 static const GdkColor gtk_default_insensitive_bg = { 0, GTK_GRAY };
370 static const GdkColor gtk_default_selected_base = { 0, GTK_BLUE };
371 static const GdkColor gtk_default_active_base = { 0, GTK_VERY_DARK_GRAY };
373 /* --- signals --- */
374 static guint realize_signal = 0;
375 static guint unrealize_signal = 0;
377 G_DEFINE_TYPE (GtkStyle, gtk_style, G_TYPE_OBJECT)
379 /* --- functions --- */
382 * _gtk_style_init_for_settings:
383 * @style: a #GtkStyle
384 * @settings: a #GtkSettings
386 * Initializes the font description in @style according to the default
387 * font name of @settings. This is called for gtk_style_new() with
388 * the settings for the default screen (if any); if we are creating
389 * a style for a particular screen, we then call it again in a
390 * location where we know the correct settings.
391 * The reason for this is that gtk_rc_style_create_style() doesn't
392 * take the screen for an argument.
395 _gtk_style_init_for_settings (GtkStyle *style,
396 GtkSettings *settings)
398 const gchar *font_name = _gtk_rc_context_get_default_font_name (settings);
400 if (style->font_desc)
401 pango_font_description_free (style->font_desc);
403 style->font_desc = pango_font_description_from_string (font_name);
405 if (!pango_font_description_get_family (style->font_desc))
407 g_warning ("Default font does not have a family set");
408 pango_font_description_set_family (style->font_desc, "Sans");
410 if (pango_font_description_get_size (style->font_desc) <= 0)
412 g_warning ("Default font does not have a positive size");
413 pango_font_description_set_size (style->font_desc, 10 * PANGO_SCALE);
418 gtk_style_init (GtkStyle *style)
422 GtkSettings *settings = gtk_settings_get_default ();
425 _gtk_style_init_for_settings (style, settings);
427 style->font_desc = pango_font_description_from_string ("Sans 10");
429 style->attach_count = 0;
431 style->black.red = 0;
432 style->black.green = 0;
433 style->black.blue = 0;
435 style->white.red = 65535;
436 style->white.green = 65535;
437 style->white.blue = 65535;
439 style->fg[GTK_STATE_NORMAL] = gtk_default_normal_fg;
440 style->fg[GTK_STATE_ACTIVE] = gtk_default_active_fg;
441 style->fg[GTK_STATE_PRELIGHT] = gtk_default_prelight_fg;
442 style->fg[GTK_STATE_SELECTED] = gtk_default_selected_fg;
443 style->fg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
445 style->bg[GTK_STATE_NORMAL] = gtk_default_normal_bg;
446 style->bg[GTK_STATE_ACTIVE] = gtk_default_active_bg;
447 style->bg[GTK_STATE_PRELIGHT] = gtk_default_prelight_bg;
448 style->bg[GTK_STATE_SELECTED] = gtk_default_selected_bg;
449 style->bg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_bg;
451 for (i = 0; i < 4; i++)
453 style->text[i] = style->fg[i];
454 style->base[i] = style->white;
457 style->base[GTK_STATE_SELECTED] = gtk_default_selected_base;
458 style->text[GTK_STATE_SELECTED] = style->white;
459 style->base[GTK_STATE_ACTIVE] = gtk_default_active_base;
460 style->text[GTK_STATE_ACTIVE] = style->white;
461 style->base[GTK_STATE_INSENSITIVE] = gtk_default_prelight_bg;
462 style->text[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
464 style->rc_style = NULL;
466 style->xthickness = 2;
467 style->ythickness = 2;
469 style->property_cache = NULL;
473 gtk_style_class_init (GtkStyleClass *klass)
475 GObjectClass *object_class = G_OBJECT_CLASS (klass);
477 object_class->finalize = gtk_style_finalize;
478 object_class->set_property = gtk_style_set_property;
479 object_class->get_property = gtk_style_get_property;
480 object_class->constructed = gtk_style_constructed;
482 klass->clone = gtk_style_real_clone;
483 klass->copy = gtk_style_real_copy;
484 klass->init_from_rc = gtk_style_real_init_from_rc;
485 klass->realize = gtk_style_real_realize;
486 klass->unrealize = gtk_style_real_unrealize;
487 klass->set_background = gtk_style_real_set_background;
488 klass->render_icon = gtk_default_render_icon;
490 klass->draw_hline = gtk_default_draw_hline;
491 klass->draw_vline = gtk_default_draw_vline;
492 klass->draw_shadow = gtk_default_draw_shadow;
493 klass->draw_arrow = gtk_default_draw_arrow;
494 klass->draw_diamond = gtk_default_draw_diamond;
495 klass->draw_box = gtk_default_draw_box;
496 klass->draw_flat_box = gtk_default_draw_flat_box;
497 klass->draw_check = gtk_default_draw_check;
498 klass->draw_option = gtk_default_draw_option;
499 klass->draw_tab = gtk_default_draw_tab;
500 klass->draw_shadow_gap = gtk_default_draw_shadow_gap;
501 klass->draw_box_gap = gtk_default_draw_box_gap;
502 klass->draw_extension = gtk_default_draw_extension;
503 klass->draw_focus = gtk_default_draw_focus;
504 klass->draw_slider = gtk_default_draw_slider;
505 klass->draw_handle = gtk_default_draw_handle;
506 klass->draw_expander = gtk_default_draw_expander;
507 klass->draw_layout = gtk_default_draw_layout;
508 klass->draw_resize_grip = gtk_default_draw_resize_grip;
509 klass->draw_spinner = gtk_default_draw_spinner;
511 g_type_class_add_private (object_class, sizeof (GtkStylePrivate));
513 g_object_class_install_property (object_class,
515 g_param_spec_object ("context",
517 P_("GtkStyleContext to get style from"),
518 GTK_TYPE_STYLE_CONTEXT,
519 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
523 * @style: the object which received the signal
525 * Emitted when the style has been initialized for a particular
526 * visual. Connecting to this signal is probably seldom
527 * useful since most of the time applications and widgets only
528 * deal with styles that have been already realized.
532 realize_signal = g_signal_new (I_("realize"),
533 G_TYPE_FROM_CLASS (object_class),
535 G_STRUCT_OFFSET (GtkStyleClass, realize),
537 _gtk_marshal_VOID__VOID,
540 * GtkStyle::unrealize:
541 * @style: the object which received the signal
543 * Emitted when the aspects of the style specific to a particular visual
544 * is being cleaned up. A connection to this signal can be useful
545 * if a widget wants to cache objects as object data on #GtkStyle.
546 * This signal provides a convenient place to free such cached objects.
550 unrealize_signal = g_signal_new (I_("unrealize"),
551 G_TYPE_FROM_CLASS (object_class),
553 G_STRUCT_OFFSET (GtkStyleClass, unrealize),
555 _gtk_marshal_VOID__VOID,
560 clear_property_cache (GtkStyle *style)
562 if (style->property_cache)
566 for (i = 0; i < style->property_cache->len; i++)
568 PropertyValue *node = &g_array_index (style->property_cache, PropertyValue, i);
570 g_param_spec_unref (node->pspec);
571 g_value_unset (&node->value);
573 g_array_free (style->property_cache, TRUE);
574 style->property_cache = NULL;
579 gtk_style_finalize (GObject *object)
581 GtkStyle *style = GTK_STYLE (object);
582 GtkStylePrivate *priv = GTK_STYLE_GET_PRIVATE (style);
584 g_return_if_fail (style->attach_count == 0);
586 clear_property_cache (style);
588 /* All the styles in the list have the same
589 * style->styles pointer. If we delete the
590 * *first* style from the list, we need to update
591 * the style->styles pointers from all the styles.
592 * Otherwise we simply remove the node from
597 if (style->styles->data != style)
598 style->styles = g_slist_remove (style->styles, style);
601 GSList *tmp_list = style->styles->next;
605 GTK_STYLE (tmp_list->data)->styles = style->styles->next;
606 tmp_list = tmp_list->next;
608 g_slist_free_1 (style->styles);
612 g_slist_foreach (style->icon_factories, (GFunc) g_object_unref, NULL);
613 g_slist_free (style->icon_factories);
615 g_slist_foreach (priv->color_hashes, (GFunc) g_hash_table_unref, NULL);
616 g_slist_free (priv->color_hashes);
618 pango_font_description_free (style->font_desc);
620 if (style->private_font_desc)
621 pango_font_description_free (style->private_font_desc);
624 g_object_unref (style->rc_style);
628 if (priv->context_changed_id)
629 g_signal_handler_disconnect (priv->context, priv->context_changed_id);
631 g_object_unref (priv->context);
634 G_OBJECT_CLASS (gtk_style_parent_class)->finalize (object);
638 gtk_style_set_property (GObject *object,
643 GtkStylePrivate *priv;
645 priv = GTK_STYLE_GET_PRIVATE (object);
650 priv->context = g_value_dup_object (value);
653 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
659 gtk_style_get_property (GObject *object,
664 GtkStylePrivate *priv;
666 priv = GTK_STYLE_GET_PRIVATE (object);
671 g_value_set_object (value, priv->context);
674 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
680 set_color (GtkStyle *style,
681 GtkStyleContext *context,
686 GdkRGBA *color = NULL;
687 GdkColor *dest = { 0 }; /* Shut up gcc */
691 case GTK_STATE_ACTIVE:
692 flags = GTK_STATE_FLAG_ACTIVE;
694 case GTK_STATE_PRELIGHT:
695 flags = GTK_STATE_FLAG_PRELIGHT;
697 case GTK_STATE_SELECTED:
698 flags = GTK_STATE_FLAG_SELECTED;
700 case GTK_STATE_INSENSITIVE:
701 flags = GTK_STATE_FLAG_INSENSITIVE;
710 gtk_style_context_get (context, flags,
711 "background-color", &color,
713 dest = &style->bg[state];
716 gtk_style_context_get (context, flags,
719 dest = &style->fg[state];
722 gtk_style_context_get (context, flags,
725 dest = &style->text[state];
728 gtk_style_context_get (context, flags,
729 "background-color", &color,
731 dest = &style->base[state];
738 dest->red = CLAMP ((guint) (color->red * 65535), 0, 65535);
739 dest->green = CLAMP ((guint) (color->green * 65535), 0, 65535);
740 dest->blue = CLAMP ((guint) (color->blue * 65535), 0, 65535);
741 gdk_rgba_free (color);
746 gtk_style_update_from_context (GtkStyle *style)
748 GtkStylePrivate *priv;
752 priv = GTK_STYLE_GET_PRIVATE (style);
754 for (state = GTK_STATE_NORMAL; state <= GTK_STATE_INSENSITIVE; state++)
756 if (gtk_style_context_has_class (priv->context, "entry"))
758 gtk_style_context_save (priv->context);
759 gtk_style_context_remove_class (priv->context, "entry");
760 set_color (style, priv->context, state, GTK_RC_BG);
761 set_color (style, priv->context, state, GTK_RC_FG);
762 gtk_style_context_restore (priv->context);
764 set_color (style, priv->context, state, GTK_RC_BASE);
765 set_color (style, priv->context, state, GTK_RC_TEXT);
769 gtk_style_context_save (priv->context);
770 gtk_style_context_add_class (priv->context, "entry");
771 set_color (style, priv->context, state, GTK_RC_BASE);
772 set_color (style, priv->context, state, GTK_RC_TEXT);
773 gtk_style_context_restore (priv->context);
775 set_color (style, priv->context, state, GTK_RC_BG);
776 set_color (style, priv->context, state, GTK_RC_FG);
780 if (style->font_desc)
781 pango_font_description_free (style->font_desc);
783 gtk_style_context_get (priv->context, 0,
784 "font", &style->font_desc,
790 style->xthickness = padding->left;
791 style->ythickness = padding->top;
793 gtk_border_free (padding);
798 style_context_changed (GtkStyleContext *context,
801 gtk_style_update_from_context (GTK_STYLE (user_data));
805 gtk_style_constructed (GObject *object)
807 GtkStylePrivate *priv;
809 priv = GTK_STYLE_GET_PRIVATE (object);
813 gtk_style_update_from_context (GTK_STYLE (object));
815 priv->context_changed_id = g_signal_connect (priv->context, "changed",
816 G_CALLBACK (style_context_changed), object);
822 * @style: a #GtkStyle
824 * Creates a copy of the passed in #GtkStyle object.
826 * Returns: (transfer full): a copy of @style
828 * Deprecated:3.0: Use #GtkStyleContext instead
831 gtk_style_copy (GtkStyle *style)
835 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
837 new_style = GTK_STYLE_GET_CLASS (style)->clone (style);
838 GTK_STYLE_GET_CLASS (style)->copy (new_style, style);
844 gtk_style_duplicate (GtkStyle *style)
848 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
850 new_style = gtk_style_copy (style);
852 /* All the styles in the list have the same
853 * style->styles pointer. When we insert a new
854 * style, we append it to the list to avoid having
855 * to update the existing ones.
857 style->styles = g_slist_append (style->styles, new_style);
858 new_style->styles = style->styles;
865 * @returns: a new #GtkStyle.
867 * Creates a new #GtkStyle.
869 * Deprecated: 3.0: Use #GtkStyleContext
876 style = g_object_new (GTK_TYPE_STYLE, NULL);
882 gtk_style_has_context (GtkStyle *style)
884 GtkStylePrivate *priv;
886 priv = GTK_STYLE_GET_PRIVATE (style);
888 return priv->context != NULL;
893 * @style: a #GtkStyle.
894 * @window: a #GdkWindow.
896 * Attaches a style to a window; this process allocates the
897 * colors and creates the GC's for the style - it specializes
898 * it to a particular visual. The process may involve the creation
899 * of a new style if the style has already been attached to a
900 * window with a different style and visual.
902 * Since this function may return a new object, you have to use it
903 * in the following way:
904 * <literal>style = gtk_style_attach (style, window)</literal>
906 * Returns: Either @style, or a newly-created #GtkStyle.
907 * If the style is newly created, the style parameter
908 * will be unref'ed, and the new style will have
909 * a reference count belonging to the caller.
911 * Deprecated:3.0: Use gtk_widget_style_attach() instead
914 gtk_style_attach (GtkStyle *style,
918 GtkStyle *new_style = NULL;
921 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
922 g_return_val_if_fail (window != NULL, NULL);
924 visual = gdk_window_get_visual (window);
927 style->styles = g_slist_append (NULL, style);
929 styles = style->styles;
932 new_style = styles->data;
934 if (new_style->visual == visual)
938 styles = styles->next;
943 styles = style->styles;
947 new_style = styles->data;
949 if (new_style->attach_count == 0)
951 gtk_style_realize (new_style, visual);
956 styles = styles->next;
962 new_style = gtk_style_duplicate (style);
963 gtk_style_realize (new_style, visual);
966 /* A style gets a refcount from being attached */
967 if (new_style->attach_count == 0)
968 g_object_ref (new_style);
970 /* Another refcount belongs to the parent */
971 if (style != new_style)
973 g_object_unref (style);
974 g_object_ref (new_style);
977 new_style->attach_count++;
984 * @style: a #GtkStyle
986 * Detaches a style from a window. If the style is not attached
987 * to any windows anymore, it is unrealized. See gtk_style_attach().
989 * Deprecated:3.0: Use #GtkStyleContext instead
992 gtk_style_detach (GtkStyle *style)
994 g_return_if_fail (GTK_IS_STYLE (style));
996 if (style->attach_count == 0)
999 style->attach_count -= 1;
1000 if (style->attach_count == 0)
1002 g_signal_emit (style, unrealize_signal, 0);
1004 g_object_unref (style->visual);
1005 style->visual = NULL;
1007 if (style->private_font_desc)
1009 pango_font_description_free (style->private_font_desc);
1010 style->private_font_desc = NULL;
1013 g_object_unref (style);
1018 gtk_style_realize (GtkStyle *style,
1021 style->visual = g_object_ref (visual);
1023 g_signal_emit (style, realize_signal, 0);
1027 * gtk_style_lookup_icon_set:
1028 * @style: a #GtkStyle
1029 * @stock_id: an icon name
1031 * Looks up @stock_id in the icon factories associated with @style
1032 * and the default icon factory, returning an icon set if found,
1035 * Return value: icon set of @stock_id
1037 * Deprecated:3.0: Use gtk_style_context_lookup_icon_set() instead
1040 gtk_style_lookup_icon_set (GtkStyle *style,
1041 const char *stock_id)
1043 GtkStylePrivate *priv;
1045 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1046 g_return_val_if_fail (stock_id != NULL, NULL);
1048 priv = GTK_STYLE_GET_PRIVATE (style);
1051 return gtk_style_context_lookup_icon_set (priv->context, stock_id);
1053 return gtk_icon_factory_lookup_default (stock_id);
1057 * gtk_style_lookup_color:
1058 * @style: a #GtkStyle
1059 * @color_name: the name of the logical color to look up
1060 * @color: the #GdkColor to fill in
1062 * Looks up @color_name in the style's logical color mappings,
1063 * filling in @color and returning %TRUE if found, otherwise
1064 * returning %FALSE. Do not cache the found mapping, because
1065 * it depends on the #GtkStyle and might change when a theme
1068 * Return value: %TRUE if the mapping was found.
1072 * Deprecated:3.0: Use gtk_style_context_lookup_color() instead
1075 gtk_style_lookup_color (GtkStyle *style,
1076 const char *color_name,
1079 GtkStylePrivate *priv;
1083 g_return_val_if_fail (GTK_IS_STYLE (style), FALSE);
1084 g_return_val_if_fail (color_name != NULL, FALSE);
1085 g_return_val_if_fail (color != NULL, FALSE);
1087 priv = GTK_STYLE_GET_PRIVATE (style);
1092 result = gtk_style_context_lookup_color (priv->context, color_name, &rgba);
1096 color->red = (guint16) (rgba.red * 65535);
1097 color->green = (guint16) (rgba.green * 65535);
1098 color->blue = (guint16) (rgba.blue * 65535);
1106 * gtk_style_set_background:
1107 * @style: a #GtkStyle
1108 * @window: a #GdkWindow
1109 * @state_type: a state
1111 * Sets the background of @window to the background color or pixmap
1112 * specified by @style for the given state.
1114 * Deprecated:3.0: Use gtk_style_context_set_background() instead
1117 gtk_style_set_background (GtkStyle *style,
1119 GtkStateType state_type)
1121 g_return_if_fail (GTK_IS_STYLE (style));
1122 g_return_if_fail (window != NULL);
1124 GTK_STYLE_GET_CLASS (style)->set_background (style, window, state_type);
1127 /* Default functions */
1129 gtk_style_real_clone (GtkStyle *style)
1131 GtkStylePrivate *priv;
1133 priv = GTK_STYLE_GET_PRIVATE (style);
1135 return g_object_new (G_OBJECT_TYPE (style),
1136 "context", priv->context,
1141 gtk_style_real_copy (GtkStyle *style,
1144 GtkStylePrivate *priv = GTK_STYLE_GET_PRIVATE (style);
1145 GtkStylePrivate *src_priv = GTK_STYLE_GET_PRIVATE (src);
1148 for (i = 0; i < 5; i++)
1150 style->fg[i] = src->fg[i];
1151 style->bg[i] = src->bg[i];
1152 style->text[i] = src->text[i];
1153 style->base[i] = src->base[i];
1155 if (style->background[i])
1156 cairo_pattern_destroy (style->background[i]),
1157 style->background[i] = src->background[i];
1158 if (style->background[i])
1159 cairo_pattern_reference (style->background[i]);
1162 if (style->font_desc)
1163 pango_font_description_free (style->font_desc);
1165 style->font_desc = pango_font_description_copy (src->font_desc);
1167 style->font_desc = NULL;
1169 style->xthickness = src->xthickness;
1170 style->ythickness = src->ythickness;
1172 if (style->rc_style)
1173 g_object_unref (style->rc_style);
1174 style->rc_style = src->rc_style;
1176 g_object_ref (src->rc_style);
1178 g_slist_foreach (style->icon_factories, (GFunc) g_object_unref, NULL);
1179 g_slist_free (style->icon_factories);
1180 style->icon_factories = g_slist_copy (src->icon_factories);
1181 g_slist_foreach (style->icon_factories, (GFunc) g_object_ref, NULL);
1183 g_slist_foreach (priv->color_hashes, (GFunc) g_hash_table_unref, NULL);
1184 g_slist_free (priv->color_hashes);
1185 priv->color_hashes = g_slist_copy (src_priv->color_hashes);
1186 g_slist_foreach (priv->color_hashes, (GFunc) g_hash_table_ref, NULL);
1188 /* don't copy, just clear cache */
1189 clear_property_cache (style);
1193 gtk_style_real_init_from_rc (GtkStyle *style,
1194 GtkRcStyle *rc_style)
1196 GtkStylePrivate *priv = GTK_STYLE_GET_PRIVATE (style);
1199 /* cache _should_ be still empty */
1200 clear_property_cache (style);
1202 if (rc_style->font_desc)
1203 pango_font_description_merge (style->font_desc, rc_style->font_desc, TRUE);
1205 for (i = 0; i < 5; i++)
1207 if (rc_style->color_flags[i] & GTK_RC_FG)
1208 style->fg[i] = rc_style->fg[i];
1209 if (rc_style->color_flags[i] & GTK_RC_BG)
1210 style->bg[i] = rc_style->bg[i];
1211 if (rc_style->color_flags[i] & GTK_RC_TEXT)
1212 style->text[i] = rc_style->text[i];
1213 if (rc_style->color_flags[i] & GTK_RC_BASE)
1214 style->base[i] = rc_style->base[i];
1217 if (rc_style->xthickness >= 0)
1218 style->xthickness = rc_style->xthickness;
1219 if (rc_style->ythickness >= 0)
1220 style->ythickness = rc_style->ythickness;
1222 style->icon_factories = g_slist_copy (rc_style->icon_factories);
1223 g_slist_foreach (style->icon_factories, (GFunc) g_object_ref, NULL);
1225 priv->color_hashes = g_slist_copy (_gtk_rc_style_get_color_hashes (rc_style));
1226 g_slist_foreach (priv->color_hashes, (GFunc) g_hash_table_ref, NULL);
1230 style_property_values_cmp (gconstpointer bsearch_node1,
1231 gconstpointer bsearch_node2)
1233 const PropertyValue *val1 = bsearch_node1;
1234 const PropertyValue *val2 = bsearch_node2;
1236 if (val1->widget_type == val2->widget_type)
1237 return val1->pspec < val2->pspec ? -1 : val1->pspec == val2->pspec ? 0 : 1;
1239 return val1->widget_type < val2->widget_type ? -1 : 1;
1243 * gtk_style_get_style_property:
1244 * @style: a #GtkStyle
1245 * @widget_type: the #GType of a descendant of #GtkWidget
1246 * @property_name: the name of the style property to get
1247 * @value: a #GValue where the value of the property being
1248 * queried will be stored
1250 * Queries the value of a style property corresponding to a
1251 * widget class is in the given style.
1256 gtk_style_get_style_property (GtkStyle *style,
1258 const gchar *property_name,
1261 GtkWidgetClass *klass;
1263 GtkRcPropertyParser parser;
1264 const GValue *peek_value;
1266 klass = g_type_class_ref (widget_type);
1267 pspec = gtk_widget_class_find_style_property (klass, property_name);
1268 g_type_class_unref (klass);
1272 g_warning ("%s: widget class `%s' has no property named `%s'",
1274 g_type_name (widget_type),
1279 parser = g_param_spec_get_qdata (pspec,
1280 g_quark_from_static_string ("gtk-rc-property-parser"));
1282 peek_value = _gtk_style_peek_property_value (style, widget_type, pspec, parser);
1284 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
1285 g_value_copy (peek_value, value);
1286 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
1287 g_value_transform (peek_value, value);
1289 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
1291 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1292 G_VALUE_TYPE_NAME (value));
1296 * gtk_style_get_valist:
1297 * @style: a #GtkStyle
1298 * @widget_type: the #GType of a descendant of #GtkWidget
1299 * @first_property_name: the name of the first style property to get
1300 * @var_args: a <type>va_list</type> of pairs of property names and
1301 * locations to return the property values, starting with the
1302 * location for @first_property_name.
1304 * Non-vararg variant of gtk_style_get().
1305 * Used primarily by language bindings.
1310 gtk_style_get_valist (GtkStyle *style,
1312 const gchar *first_property_name,
1315 const char *property_name;
1316 GtkWidgetClass *klass;
1318 g_return_if_fail (GTK_IS_STYLE (style));
1320 klass = g_type_class_ref (widget_type);
1322 property_name = first_property_name;
1323 while (property_name)
1326 GtkRcPropertyParser parser;
1327 const GValue *peek_value;
1330 pspec = gtk_widget_class_find_style_property (klass, property_name);
1334 g_warning ("%s: widget class `%s' has no property named `%s'",
1336 g_type_name (widget_type),
1341 parser = g_param_spec_get_qdata (pspec,
1342 g_quark_from_static_string ("gtk-rc-property-parser"));
1344 peek_value = _gtk_style_peek_property_value (style, widget_type, pspec, parser);
1345 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
1348 g_warning ("%s: %s", G_STRLOC, error);
1353 property_name = va_arg (var_args, gchar*);
1356 g_type_class_unref (klass);
1361 * @style: a #GtkStyle
1362 * @widget_type: the #GType of a descendant of #GtkWidget
1363 * @first_property_name: the name of the first style property to get
1364 * @Varargs: pairs of property names and locations to
1365 * return the property values, starting with the location for
1366 * @first_property_name, terminated by %NULL.
1368 * Gets the values of a multiple style properties for @widget_type
1374 gtk_style_get (GtkStyle *style,
1376 const gchar *first_property_name,
1381 va_start (var_args, first_property_name);
1382 gtk_style_get_valist (style, widget_type, first_property_name, var_args);
1387 _gtk_style_peek_property_value (GtkStyle *style,
1390 GtkRcPropertyParser parser)
1392 PropertyValue *pcache, key = { 0, NULL, { 0, } };
1393 const GtkRcProperty *rcprop = NULL;
1396 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1397 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), NULL);
1398 g_return_val_if_fail (g_type_is_a (pspec->owner_type, GTK_TYPE_WIDGET), NULL);
1399 g_return_val_if_fail (g_type_is_a (widget_type, pspec->owner_type), NULL);
1401 key.widget_type = widget_type;
1404 /* need value cache array */
1405 if (!style->property_cache)
1406 style->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
1409 pcache = bsearch (&key,
1410 style->property_cache->data, style->property_cache->len,
1411 sizeof (PropertyValue), style_property_values_cmp);
1413 return &pcache->value;
1417 while (i < style->property_cache->len &&
1418 style_property_values_cmp (&key, &g_array_index (style->property_cache, PropertyValue, i)) >= 0)
1421 g_array_insert_val (style->property_cache, i, key);
1422 pcache = &g_array_index (style->property_cache, PropertyValue, i);
1424 /* cache miss, initialize value type, then set contents */
1425 g_param_spec_ref (pcache->pspec);
1426 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1428 /* value provided by rc style? */
1429 if (style->rc_style)
1431 GQuark prop_quark = g_quark_from_string (pspec->name);
1435 rcprop = _gtk_rc_style_lookup_rc_property (style->rc_style,
1436 g_type_qname (widget_type),
1440 widget_type = g_type_parent (widget_type);
1442 while (g_type_is_a (widget_type, pspec->owner_type));
1445 /* when supplied by rc style, we need to convert */
1446 if (rcprop && !_gtk_settings_parse_convert (parser, &rcprop->value,
1447 pspec, &pcache->value))
1449 gchar *contents = g_strdup_value_contents (&rcprop->value);
1451 g_message ("%s: failed to retrieve property `%s::%s' of type `%s' from rc file value \"%s\" of type `%s'",
1452 rcprop->origin ? rcprop->origin : "(for origin information, set GTK_DEBUG)",
1453 g_type_name (pspec->owner_type), pspec->name,
1454 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1456 G_VALUE_TYPE_NAME (&rcprop->value));
1458 rcprop = NULL; /* needs default */
1461 /* not supplied by rc style (or conversion failed), revert to default */
1463 g_param_value_set_default (pspec, &pcache->value);
1465 return &pcache->value;
1468 static cairo_pattern_t *
1469 load_background (GdkVisual *visual,
1471 const gchar *filename)
1473 if (filename == NULL)
1475 return cairo_pattern_create_rgb (bg_color->red / 65535.0,
1476 bg_color->green / 65535.0,
1477 bg_color->blue / 65535.0);
1479 if (strcmp (filename, "<parent>") == 0)
1484 cairo_surface_t *surface;
1485 cairo_pattern_t *pattern;
1487 GdkScreen *screen = gdk_visual_get_screen (visual);
1489 pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
1493 surface = gdk_window_create_similar_surface (gdk_screen_get_root_window (screen),
1494 CAIRO_CONTENT_COLOR,
1495 gdk_pixbuf_get_width (pixbuf),
1496 gdk_pixbuf_get_height (pixbuf));
1498 cr = cairo_create (surface);
1500 gdk_cairo_set_source_color (cr, bg_color);
1503 gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
1507 g_object_unref (pixbuf);
1509 pattern = cairo_pattern_create_for_surface (surface);
1511 cairo_surface_destroy (surface);
1518 gtk_style_real_realize (GtkStyle *style)
1522 for (i = 0; i < 5; i++)
1524 _gtk_style_shade (&style->bg[i], &style->light[i], LIGHTNESS_MULT);
1525 _gtk_style_shade (&style->bg[i], &style->dark[i], DARKNESS_MULT);
1527 style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
1528 style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
1529 style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
1531 style->text_aa[i].red = (style->text[i].red + style->base[i].red) / 2;
1532 style->text_aa[i].green = (style->text[i].green + style->base[i].green) / 2;
1533 style->text_aa[i].blue = (style->text[i].blue + style->base[i].blue) / 2;
1536 style->black.red = 0x0000;
1537 style->black.green = 0x0000;
1538 style->black.blue = 0x0000;
1540 style->white.red = 0xffff;
1541 style->white.green = 0xffff;
1542 style->white.blue = 0xffff;
1544 for (i = 0; i < 5; i++)
1546 const char *image_name;
1548 if (style->rc_style)
1549 image_name = style->rc_style->bg_pixmap_name[i];
1553 style->background[i] = load_background (style->visual,
1560 gtk_style_real_unrealize (GtkStyle *style)
1564 for (i = 0; i < 5; i++)
1566 if (style->background[i])
1568 cairo_pattern_destroy (style->background[i]);
1569 style->background[i] = NULL;
1574 style_unrealize_cursors (style);
1578 gtk_style_real_set_background (GtkStyle *style,
1580 GtkStateType state_type)
1582 gdk_window_set_background_pattern (window, style->background[state_type]);
1586 * gtk_style_render_icon:
1587 * @style: a #GtkStyle
1588 * @source: the #GtkIconSource specifying the icon to render
1589 * @direction: a text direction
1591 * @size: (type int): the size to render the icon at. A size of
1592 * (GtkIconSize)-1 means render at the size of the source and
1594 * @widget: (allow-none): the widget
1595 * @detail: (allow-none): a style detail
1597 * Renders the icon specified by @source at the given @size
1598 * according to the given parameters and returns the result in a
1601 * Return value: (transfer full): a newly-created #GdkPixbuf
1602 * containing the rendered icon
1604 * Deprecated:3.0: Use gtk_render_icon_pixbuf() instead
1607 gtk_style_render_icon (GtkStyle *style,
1608 const GtkIconSource *source,
1609 GtkTextDirection direction,
1613 const gchar *detail)
1617 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1618 g_return_val_if_fail (GTK_STYLE_GET_CLASS (style)->render_icon != NULL, NULL);
1620 pixbuf = GTK_STYLE_GET_CLASS (style)->render_icon (style, source, direction, state,
1621 size, widget, detail);
1623 g_return_val_if_fail (pixbuf != NULL, NULL);
1628 /* Default functions */
1631 * gtk_style_apply_default_background:
1637 * @area: (allow-none):
1643 * Deprecated:3.0: Use #GtkStyleContext instead
1646 gtk_style_apply_default_background (GtkStyle *style,
1649 GtkStateType state_type,
1657 if (style->background[state_type] == NULL)
1659 GdkWindow *parent = gdk_window_get_parent (window);
1660 int x_offset, y_offset;
1664 gdk_window_get_position (window, &x_offset, &y_offset);
1665 cairo_translate (cr, -x_offset, -y_offset);
1666 gtk_style_apply_default_background (style, cr,
1668 x + x_offset, y + y_offset,
1673 gdk_cairo_set_source_color (cr, &style->bg[state_type]);
1676 cairo_set_source (cr, style->background[state_type]);
1678 cairo_rectangle (cr, x, y, width, height);
1686 gtk_default_render_icon (GtkStyle *style,
1687 const GtkIconSource *source,
1688 GtkTextDirection direction,
1692 const gchar *detail)
1694 GtkStyleContext *context;
1695 GtkStylePrivate *priv;
1696 GtkStateFlags flags = 0;
1700 context = gtk_widget_get_style_context (widget);
1703 priv = GTK_STYLE_GET_PRIVATE (style);
1704 context = priv->context;
1710 gtk_style_context_save (context);
1713 transform_detail_string (detail, context);
1717 case GTK_STATE_PRELIGHT:
1718 flags |= GTK_STATE_FLAG_PRELIGHT;
1720 case GTK_STATE_INSENSITIVE:
1721 flags |= GTK_STATE_FLAG_INSENSITIVE;
1727 gtk_style_context_set_state (context, flags);
1729 pixbuf = gtk_render_icon_pixbuf (context, source, size);
1731 gtk_style_context_restore (context);
1737 _cairo_draw_line (cairo_t *cr,
1746 gdk_cairo_set_source_color (cr, color);
1747 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
1749 cairo_move_to (cr, x1 + 0.5, y1 + 0.5);
1750 cairo_line_to (cr, x2 + 0.5, y2 + 0.5);
1757 _cairo_draw_rectangle (cairo_t *cr,
1765 gdk_cairo_set_source_color (cr, color);
1769 cairo_rectangle (cr, x, y, width, height);
1774 cairo_rectangle (cr, x + 0.5, y + 0.5, width, height);
1780 _cairo_draw_point (cairo_t *cr,
1785 gdk_cairo_set_source_color (cr, color);
1786 cairo_rectangle (cr, x, y, 1, 1);
1791 transform_detail_string (const gchar *detail,
1792 GtkStyleContext *context)
1797 if (strcmp (detail, "arrow") == 0)
1798 gtk_style_context_add_class (context, "arrow");
1799 else if (strcmp (detail, "button") == 0)
1800 gtk_style_context_add_class (context, "button");
1801 else if (strcmp (detail, "buttondefault") == 0)
1803 gtk_style_context_add_class (context, "button");
1804 gtk_style_context_add_class (context, "default");
1806 else if (strcmp (detail, "calendar") == 0)
1807 gtk_style_context_add_class (context, "calendar");
1808 else if (strcmp (detail, "cellcheck") == 0)
1810 gtk_style_context_add_class (context, "cell");
1811 gtk_style_context_add_class (context, "check");
1813 else if (strcmp (detail, "cellradio") == 0)
1815 gtk_style_context_add_class (context, "cell");
1816 gtk_style_context_add_class (context, "radio");
1818 else if (strcmp (detail, "checkbutton") == 0)
1819 gtk_style_context_add_class (context, "check");
1820 else if (strcmp (detail, "check") == 0)
1822 gtk_style_context_add_class (context, "check");
1823 gtk_style_context_add_class (context, "menu");
1825 else if (strcmp (detail, "radiobutton") == 0)
1827 gtk_style_context_add_class (context, "radio");
1829 else if (strcmp (detail, "option") == 0)
1831 gtk_style_context_add_class (context, "radio");
1832 gtk_style_context_add_class (context, "menu");
1834 else if (strcmp (detail, "entry") == 0 ||
1835 strcmp (detail, "entry_bg") == 0)
1836 gtk_style_context_add_class (context, "entry");
1837 else if (strcmp (detail, "expander") == 0)
1838 gtk_style_context_add_class (context, "expander");
1839 else if (strcmp (detail, "tooltip") == 0)
1840 gtk_style_context_add_class (context, "tooltip");
1841 else if (strcmp (detail, "frame") == 0)
1842 gtk_style_context_add_class (context, "frame");
1843 else if (strcmp (detail, "scrolled_window") == 0)
1844 gtk_style_context_add_class (context, "scrolled-window");
1845 else if (strcmp (detail, "viewport") == 0 ||
1846 strcmp (detail, "viewportbin") == 0)
1847 gtk_style_context_add_class (context, "viewport");
1848 else if (strncmp (detail, "trough", 6) == 0)
1849 gtk_style_context_add_class (context, "trough");
1850 else if (strcmp (detail, "spinbutton") == 0)
1851 gtk_style_context_add_class (context, "spinbutton");
1852 else if (strcmp (detail, "spinbutton_up") == 0)
1854 gtk_style_context_add_class (context, "spinbutton");
1855 gtk_style_context_add_class (context, "button");
1856 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
1858 else if (strcmp (detail, "spinbutton_down") == 0)
1860 gtk_style_context_add_class (context, "spinbutton");
1861 gtk_style_context_add_class (context, "button");
1862 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
1864 else if ((detail[0] == 'h' || detail[0] == 'v') &&
1865 strncmp (&detail[1], "scrollbar_", 10) == 0)
1867 gtk_style_context_add_class (context, "button");
1868 gtk_style_context_add_class (context, "scrollbar");
1870 else if (strcmp (detail, "slider") == 0)
1872 gtk_style_context_add_class (context, "slider");
1873 gtk_style_context_add_class (context, "scrollbar");
1875 else if (strcmp (detail, "vscale") == 0 ||
1876 strcmp (detail, "hscale") == 0)
1878 gtk_style_context_add_class (context, "slider");
1879 gtk_style_context_add_class (context, "scale");
1881 else if (strcmp (detail, "menuitem") == 0)
1883 gtk_style_context_add_class (context, "menuitem");
1884 gtk_style_context_add_class (context, "menu");
1886 else if (strcmp (detail, "menu") == 0)
1888 gtk_style_context_add_class (context, "popup");
1889 gtk_style_context_add_class (context, "menu");
1891 else if (strcmp (detail, "accellabel") == 0)
1892 gtk_style_context_add_class (context, "accelerator");
1893 else if (strcmp (detail, "menubar") == 0)
1894 gtk_style_context_add_class (context, "menubar");
1895 else if (strcmp (detail, "base") == 0)
1896 gtk_style_context_add_class (context, "background");
1897 else if (strcmp (detail, "bar") == 0 ||
1898 strcmp (detail, "progressbar") == 0)
1899 gtk_style_context_add_class (context, "progressbar");
1900 else if (strcmp (detail, "toolbar") == 0)
1901 gtk_style_context_add_class (context, "toolbar");
1902 else if (strcmp (detail, "handlebox_bin") == 0)
1903 gtk_style_context_add_class (context, "dock");
1904 else if (strcmp (detail, "notebook") == 0)
1905 gtk_style_context_add_class (context, "notebook");
1906 else if (strcmp (detail, "tab") == 0)
1908 gtk_style_context_add_class (context, "notebook");
1909 gtk_style_context_add_region (context, GTK_STYLE_REGION_TAB, 0);
1911 else if (g_str_has_prefix (detail, "cell"))
1913 GtkRegionFlags row, col;
1914 gboolean ruled = FALSE;
1918 tokens = g_strsplit (detail, "_", -1);
1924 if (strcmp (tokens[i], "even") == 0)
1925 row |= GTK_REGION_EVEN;
1926 else if (strcmp (tokens[i], "odd") == 0)
1927 row |= GTK_REGION_ODD;
1928 else if (strcmp (tokens[i], "start") == 0)
1929 col |= GTK_REGION_FIRST;
1930 else if (strcmp (tokens[i], "end") == 0)
1931 col |= GTK_REGION_LAST;
1932 else if (strcmp (tokens[i], "ruled") == 0)
1934 else if (strcmp (tokens[i], "sorted") == 0)
1935 col |= GTK_REGION_SORTED;
1941 row &= ~(GTK_REGION_EVEN | GTK_REGION_ODD);
1943 gtk_style_context_add_class (context, "cell");
1944 gtk_style_context_add_region (context, "row", row);
1945 gtk_style_context_add_region (context, "column", col);
1947 g_strfreev (tokens);
1952 gtk_default_draw_hline (GtkStyle *style,
1954 GtkStateType state_type,
1956 const gchar *detail,
1961 GtkStyleContext *context;
1962 GtkStylePrivate *priv;
1965 context = gtk_widget_get_style_context (widget);
1968 priv = GTK_STYLE_GET_PRIVATE (style);
1969 context = priv->context;
1972 gtk_style_context_save (context);
1975 transform_detail_string (detail, context);
1979 gtk_render_line (context, cr,
1984 gtk_style_context_restore (context);
1989 gtk_default_draw_vline (GtkStyle *style,
1991 GtkStateType state_type,
1993 const gchar *detail,
1998 GtkStyleContext *context;
1999 GtkStylePrivate *priv;
2002 context = gtk_widget_get_style_context (widget);
2005 priv = GTK_STYLE_GET_PRIVATE (style);
2006 context = priv->context;
2009 gtk_style_context_save (context);
2012 transform_detail_string (detail, context);
2016 gtk_render_line (context, cr,
2020 gtk_style_context_restore (context);
2024 draw_thin_shadow (GtkStyle *style,
2032 GdkColor *gc1, *gc2;
2034 gc1 = &style->light[state];
2035 gc2 = &style->dark[state];
2037 _cairo_draw_line (cr, gc1,
2038 x, y + height - 1, x + width - 1, y + height - 1);
2039 _cairo_draw_line (cr, gc1,
2040 x + width - 1, y, x + width - 1, y + height - 1);
2042 _cairo_draw_line (cr, gc2,
2043 x, y, x + width - 2, y);
2044 _cairo_draw_line (cr, gc2,
2045 x, y, x, y + height - 2);
2049 draw_spinbutton_shadow (GtkStyle *style,
2052 GtkTextDirection direction,
2059 if (direction == GTK_TEXT_DIR_LTR)
2061 _cairo_draw_line (cr, &style->dark[state],
2062 x, y, x + width - 1, y);
2063 _cairo_draw_line (cr, &style->black,
2064 x, y + 1, x + width - 2, y + 1);
2065 _cairo_draw_line (cr, &style->black,
2066 x + width - 2, y + 2, x + width - 2, y + height - 3);
2067 _cairo_draw_line (cr, &style->light[state],
2068 x + width - 1, y + 1, x + width - 1, y + height - 2);
2069 _cairo_draw_line (cr, &style->light[state],
2070 x, y + height - 1, x + width - 1, y + height - 1);
2071 _cairo_draw_line (cr, &style->bg[state],
2072 x, y + height - 2, x + width - 2, y + height - 2);
2073 _cairo_draw_line (cr, &style->black,
2074 x, y + 2, x, y + height - 3);
2078 _cairo_draw_line (cr, &style->dark[state],
2079 x, y, x + width - 1, y);
2080 _cairo_draw_line (cr, &style->dark[state],
2081 x, y + 1, x, y + height - 1);
2082 _cairo_draw_line (cr, &style->black,
2083 x + 1, y + 1, x + width - 1, y + 1);
2084 _cairo_draw_line (cr, &style->black,
2085 x + 1, y + 2, x + 1, y + height - 2);
2086 _cairo_draw_line (cr, &style->black,
2087 x + width - 1, y + 2, x + width - 1, y + height - 3);
2088 _cairo_draw_line (cr, &style->light[state],
2089 x + 1, y + height - 1, x + width - 1, y + height - 1);
2090 _cairo_draw_line (cr, &style->bg[state],
2091 x + 2, y + height - 2, x + width - 1, y + height - 2);
2096 draw_menu_shadow (GtkStyle *style,
2104 if (style->ythickness > 0)
2106 if (style->ythickness > 1)
2108 _cairo_draw_line (cr, &style->dark[state],
2109 x + 1, y + height - 2,
2110 x + width - 2, y + height - 2);
2111 _cairo_draw_line (cr, &style->black,
2112 x, y + height - 1, x + width - 1, y + height - 1);
2116 _cairo_draw_line (cr, &style->dark[state],
2117 x + 1, y + height - 1, x + width - 1, y + height - 1);
2121 if (style->xthickness > 0)
2123 if (style->xthickness > 1)
2125 _cairo_draw_line (cr, &style->dark[state],
2126 x + width - 2, y + 1,
2127 x + width - 2, y + height - 2);
2129 _cairo_draw_line (cr, &style->black,
2130 x + width - 1, y, x + width - 1, y + height - 1);
2134 _cairo_draw_line (cr, &style->dark[state],
2135 x + width - 1, y + 1, x + width - 1, y + height - 1);
2139 /* Light around top and left */
2141 if (style->ythickness > 0)
2142 _cairo_draw_line (cr, &style->black,
2143 x, y, x + width - 2, y);
2144 if (style->xthickness > 0)
2145 _cairo_draw_line (cr, &style->black,
2146 x, y, x, y + height - 2);
2148 if (style->ythickness > 1)
2149 _cairo_draw_line (cr, &style->light[state],
2150 x + 1, y + 1, x + width - 3, y + 1);
2151 if (style->xthickness > 1)
2152 _cairo_draw_line (cr, &style->light[state],
2153 x + 1, y + 1, x + 1, y + height - 3);
2156 static GtkTextDirection
2157 get_direction (GtkWidget *widget)
2159 GtkTextDirection dir;
2162 dir = gtk_widget_get_direction (widget);
2164 dir = GTK_TEXT_DIR_LTR;
2171 gtk_default_draw_shadow (GtkStyle *style,
2173 GtkStateType state_type,
2174 GtkShadowType shadow_type,
2176 const gchar *detail,
2182 GtkStyleContext *context;
2183 GtkStylePrivate *priv;
2186 context = gtk_widget_get_style_context (widget);
2189 priv = GTK_STYLE_GET_PRIVATE (style);
2190 context = priv->context;
2193 gtk_style_context_save (context);
2196 transform_detail_string (detail, context);
2200 gtk_render_frame (context, cr,
2207 gtk_style_context_restore (context);
2211 draw_arrow (cairo_t *cr,
2213 GtkArrowType arrow_type,
2219 gdk_cairo_set_source_color (cr, color);
2222 if (arrow_type == GTK_ARROW_DOWN)
2224 cairo_move_to (cr, x, y);
2225 cairo_line_to (cr, x + width, y);
2226 cairo_line_to (cr, x + width / 2., y + height);
2228 else if (arrow_type == GTK_ARROW_UP)
2230 cairo_move_to (cr, x, y + height);
2231 cairo_line_to (cr, x + width / 2., y);
2232 cairo_line_to (cr, x + width, y + height);
2234 else if (arrow_type == GTK_ARROW_LEFT)
2236 cairo_move_to (cr, x + width, y);
2237 cairo_line_to (cr, x + width, y + height);
2238 cairo_line_to (cr, x, y + height / 2.);
2240 else if (arrow_type == GTK_ARROW_RIGHT)
2242 cairo_move_to (cr, x, y);
2243 cairo_line_to (cr, x + width, y + height / 2.);
2244 cairo_line_to (cr, x, y + height);
2247 cairo_close_path (cr);
2254 calculate_arrow_geometry (GtkArrowType arrow_type,
2266 case GTK_ARROW_DOWN:
2276 if (arrow_type == GTK_ARROW_DOWN)
2278 if (*height % 2 == 1 || h % 2 == 0)
2283 if (*height % 2 == 0 || h % 2 == 0)
2288 case GTK_ARROW_RIGHT:
2289 case GTK_ARROW_LEFT:
2299 if (arrow_type == GTK_ARROW_RIGHT)
2301 if (*width % 2 == 1 || w % 2 == 0)
2306 if (*width % 2 == 0 || w % 2 == 0)
2312 /* should not be reached */
2316 *x += (*width - w) / 2;
2317 *y += (*height - h) / 2;
2323 gtk_default_draw_arrow (GtkStyle *style,
2326 GtkShadowType shadow,
2328 const gchar *detail,
2329 GtkArrowType arrow_type,
2336 GtkStyleContext *context;
2337 GtkStylePrivate *priv;
2338 GtkStateFlags flags = 0;
2339 gdouble angle, size;
2341 if (arrow_type == GTK_ARROW_NONE)
2345 context = gtk_widget_get_style_context (widget);
2348 priv = GTK_STYLE_GET_PRIVATE (style);
2349 context = priv->context;
2352 gtk_style_context_save (context);
2355 transform_detail_string (detail, context);
2363 case GTK_ARROW_RIGHT:
2367 case GTK_ARROW_DOWN:
2371 case GTK_ARROW_LEFT:
2372 angle = 3 * (G_PI / 2);
2376 g_assert_not_reached ();
2381 case GTK_STATE_PRELIGHT:
2382 flags |= GTK_STATE_FLAG_PRELIGHT;
2384 case GTK_STATE_SELECTED:
2385 flags |= GTK_STATE_FLAG_SELECTED;
2387 case GTK_STATE_INSENSITIVE:
2388 flags |= GTK_STATE_FLAG_INSENSITIVE;
2390 case GTK_STATE_ACTIVE:
2391 flags |= GTK_STATE_FLAG_ACTIVE;
2397 gtk_style_context_set_state (context, flags);
2401 gtk_render_arrow (context,
2408 gtk_style_context_restore (context);
2412 gtk_default_draw_diamond (GtkStyle *style,
2414 GtkStateType state_type,
2415 GtkShadowType shadow_type,
2417 const gchar *detail,
2425 GdkColor *outer_nw = NULL;
2426 GdkColor *outer_ne = NULL;
2427 GdkColor *outer_sw = NULL;
2428 GdkColor *outer_se = NULL;
2429 GdkColor *middle_nw = NULL;
2430 GdkColor *middle_ne = NULL;
2431 GdkColor *middle_sw = NULL;
2432 GdkColor *middle_se = NULL;
2433 GdkColor *inner_nw = NULL;
2434 GdkColor *inner_ne = NULL;
2435 GdkColor *inner_sw = NULL;
2436 GdkColor *inner_se = NULL;
2438 half_width = width / 2;
2439 half_height = height / 2;
2441 switch (shadow_type)
2444 inner_sw = inner_se = &style->bg[state_type];
2445 middle_sw = middle_se = &style->light[state_type];
2446 outer_sw = outer_se = &style->light[state_type];
2447 inner_nw = inner_ne = &style->black;
2448 middle_nw = middle_ne = &style->dark[state_type];
2449 outer_nw = outer_ne = &style->dark[state_type];
2452 case GTK_SHADOW_OUT:
2453 inner_sw = inner_se = &style->dark[state_type];
2454 middle_sw = middle_se = &style->dark[state_type];
2455 outer_sw = outer_se = &style->black;
2456 inner_nw = inner_ne = &style->bg[state_type];
2457 middle_nw = middle_ne = &style->light[state_type];
2458 outer_nw = outer_ne = &style->light[state_type];
2461 case GTK_SHADOW_ETCHED_IN:
2462 inner_sw = inner_se = &style->bg[state_type];
2463 middle_sw = middle_se = &style->dark[state_type];
2464 outer_sw = outer_se = &style->light[state_type];
2465 inner_nw = inner_ne = &style->bg[state_type];
2466 middle_nw = middle_ne = &style->light[state_type];
2467 outer_nw = outer_ne = &style->dark[state_type];
2470 case GTK_SHADOW_ETCHED_OUT:
2471 inner_sw = inner_se = &style->bg[state_type];
2472 middle_sw = middle_se = &style->light[state_type];
2473 outer_sw = outer_se = &style->dark[state_type];
2474 inner_nw = inner_ne = &style->bg[state_type];
2475 middle_nw = middle_ne = &style->dark[state_type];
2476 outer_nw = outer_ne = &style->light[state_type];
2486 _cairo_draw_line (cr, inner_sw,
2487 x + 2, y + half_height,
2488 x + half_width, y + height - 2);
2489 _cairo_draw_line (cr, inner_se,
2490 x + half_width, y + height - 2,
2491 x + width - 2, y + half_height);
2492 _cairo_draw_line (cr, middle_sw,
2493 x + 1, y + half_height,
2494 x + half_width, y + height - 1);
2495 _cairo_draw_line (cr, middle_se,
2496 x + half_width, y + height - 1,
2497 x + width - 1, y + half_height);
2498 _cairo_draw_line (cr, outer_sw,
2500 x + half_width, y + height);
2501 _cairo_draw_line (cr, outer_se,
2502 x + half_width, y + height,
2503 x + width, y + half_height);
2505 _cairo_draw_line (cr, inner_nw,
2506 x + 2, y + half_height,
2507 x + half_width, y + 2);
2508 _cairo_draw_line (cr, inner_ne,
2509 x + half_width, y + 2,
2510 x + width - 2, y + half_height);
2511 _cairo_draw_line (cr, middle_nw,
2512 x + 1, y + half_height,
2513 x + half_width, y + 1);
2514 _cairo_draw_line (cr, middle_ne,
2515 x + half_width, y + 1,
2516 x + width - 1, y + half_height);
2517 _cairo_draw_line (cr, outer_nw,
2520 _cairo_draw_line (cr, outer_ne,
2522 x + width, y + half_height);
2527 option_menu_get_props (GtkWidget *widget,
2528 GtkRequisition *indicator_size,
2529 GtkBorder *indicator_spacing)
2531 GtkRequisition *tmp_size = NULL;
2532 GtkBorder *tmp_spacing = NULL;
2536 *indicator_size = *tmp_size;
2537 gtk_requisition_free (tmp_size);
2540 *indicator_size = default_option_indicator_size;
2544 *indicator_spacing = *tmp_spacing;
2545 gtk_border_free (tmp_spacing);
2548 *indicator_spacing = default_option_indicator_spacing;
2552 background_is_solid (GtkStyle *style,
2555 if (style->background[type] == NULL)
2558 return cairo_pattern_get_type (style->background[type]) == CAIRO_PATTERN_TYPE_SOLID;
2562 gtk_default_draw_box (GtkStyle *style,
2564 GtkStateType state_type,
2565 GtkShadowType shadow_type,
2567 const gchar *detail,
2573 GtkStyleContext *context;
2574 GtkStylePrivate *priv;
2575 GtkStateFlags flags = 0;
2578 context = gtk_widget_get_style_context (widget);
2581 priv = GTK_STYLE_GET_PRIVATE (style);
2582 context = priv->context;
2585 gtk_style_context_save (context);
2588 transform_detail_string (detail, context);
2592 case GTK_STATE_ACTIVE:
2593 flags |= GTK_STATE_FLAG_ACTIVE;
2595 case GTK_STATE_PRELIGHT:
2596 flags |= GTK_STATE_FLAG_PRELIGHT;
2598 case GTK_STATE_SELECTED:
2599 flags |= GTK_STATE_FLAG_SELECTED;
2601 case GTK_STATE_INSENSITIVE:
2602 flags |= GTK_STATE_FLAG_INSENSITIVE;
2608 if (shadow_type == GTK_SHADOW_IN)
2609 flags |= GTK_STATE_FLAG_ACTIVE;
2611 gtk_style_context_set_state (context, flags);
2615 if (gtk_style_context_has_class (context, GTK_STYLE_CLASS_PROGRESSBAR))
2616 gtk_render_activity (context, cr, x, y, width, height);
2619 gtk_render_background (context, cr, x, y, width, height);
2620 gtk_render_frame (context, cr, x, y, width, height);
2624 gtk_style_context_restore (context);
2628 get_darkened (const GdkColor *color,
2631 GdkColor src = *color;
2632 GdkColor shaded = *color;
2634 while (darken_count)
2636 _gtk_style_shade (&src, &shaded, 0.93);
2641 return gdk_color_copy (&shaded);
2645 gtk_default_draw_flat_box (GtkStyle *style,
2647 GtkStateType state_type,
2648 GtkShadowType shadow_type,
2650 const gchar *detail,
2656 GtkStyleContext *context;
2657 GtkStylePrivate *priv;
2658 GtkStateFlags flags = 0;
2661 context = gtk_widget_get_style_context (widget);
2664 priv = GTK_STYLE_GET_PRIVATE (style);
2665 context = priv->context;
2668 gtk_style_context_save (context);
2671 transform_detail_string (detail, context);
2675 case GTK_STATE_PRELIGHT:
2676 flags |= GTK_STATE_FLAG_PRELIGHT;
2678 case GTK_STATE_SELECTED:
2679 flags |= GTK_STATE_FLAG_SELECTED;
2681 case GTK_STATE_INSENSITIVE:
2682 flags |= GTK_STATE_FLAG_INSENSITIVE;
2684 case GTK_STATE_ACTIVE:
2685 flags |= GTK_STATE_FLAG_ACTIVE;
2687 case GTK_STATE_FOCUSED:
2688 flags |= GTK_STATE_FLAG_FOCUSED;
2694 gtk_style_context_set_state (context, flags);
2698 gtk_render_background (context, cr,
2705 gtk_style_context_restore (context);
2709 gtk_default_draw_check (GtkStyle *style,
2711 GtkStateType state_type,
2712 GtkShadowType shadow_type,
2714 const gchar *detail,
2720 GtkStyleContext *context;
2721 GtkStylePrivate *priv;
2722 GtkStateFlags flags = 0;
2725 context = gtk_widget_get_style_context (widget);
2728 priv = GTK_STYLE_GET_PRIVATE (style);
2729 context = priv->context;
2732 gtk_style_context_save (context);
2735 transform_detail_string (detail, context);
2739 case GTK_STATE_PRELIGHT:
2740 flags |= GTK_STATE_FLAG_PRELIGHT;
2742 case GTK_STATE_SELECTED:
2743 flags |= GTK_STATE_FLAG_SELECTED;
2745 case GTK_STATE_INSENSITIVE:
2746 flags |= GTK_STATE_FLAG_INSENSITIVE;
2752 if (shadow_type == GTK_SHADOW_IN)
2753 flags |= GTK_STATE_FLAG_ACTIVE;
2754 else if (shadow_type == GTK_SHADOW_ETCHED_IN)
2755 flags |= GTK_STATE_FLAG_INCONSISTENT;
2757 gtk_style_context_set_state (context, flags);
2761 gtk_render_check (context,
2766 gtk_style_context_restore (context);
2770 gtk_default_draw_option (GtkStyle *style,
2772 GtkStateType state_type,
2773 GtkShadowType shadow_type,
2775 const gchar *detail,
2781 GtkStyleContext *context;
2782 GtkStylePrivate *priv;
2783 GtkStateFlags flags = 0;
2786 context = gtk_widget_get_style_context (widget);
2789 priv = GTK_STYLE_GET_PRIVATE (style);
2790 context = priv->context;
2793 gtk_style_context_save (context);
2796 transform_detail_string (detail, context);
2800 case GTK_STATE_PRELIGHT:
2801 flags |= GTK_STATE_FLAG_PRELIGHT;
2803 case GTK_STATE_SELECTED:
2804 flags |= GTK_STATE_FLAG_SELECTED;
2806 case GTK_STATE_INSENSITIVE:
2807 flags |= GTK_STATE_FLAG_INSENSITIVE;
2813 if (shadow_type == GTK_SHADOW_IN)
2814 flags |= GTK_STATE_FLAG_ACTIVE;
2815 else if (shadow_type == GTK_SHADOW_ETCHED_IN)
2816 flags |= GTK_STATE_FLAG_INCONSISTENT;
2818 gtk_style_context_set_state (context, flags);
2821 gtk_render_option (context, cr,
2828 gtk_style_context_restore (context);
2832 gtk_default_draw_tab (GtkStyle *style,
2834 GtkStateType state_type,
2835 GtkShadowType shadow_type,
2837 const gchar *detail,
2843 #define ARROW_SPACE 4
2845 GtkRequisition indicator_size;
2846 GtkBorder indicator_spacing;
2849 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
2851 indicator_size.width += (indicator_size.width % 2) - 1;
2852 arrow_height = indicator_size.width / 2 + 1;
2854 x += (width - indicator_size.width) / 2;
2855 y += (height - (2 * arrow_height + ARROW_SPACE)) / 2;
2857 if (state_type == GTK_STATE_INSENSITIVE)
2859 draw_arrow (cr, &style->white,
2860 GTK_ARROW_UP, x + 1, y + 1,
2861 indicator_size.width, arrow_height);
2863 draw_arrow (cr, &style->white,
2864 GTK_ARROW_DOWN, x + 1, y + arrow_height + ARROW_SPACE + 1,
2865 indicator_size.width, arrow_height);
2868 draw_arrow (cr, &style->fg[state_type],
2870 indicator_size.width, arrow_height);
2873 draw_arrow (cr, &style->fg[state_type],
2874 GTK_ARROW_DOWN, x, y + arrow_height + ARROW_SPACE,
2875 indicator_size.width, arrow_height);
2879 gtk_default_draw_shadow_gap (GtkStyle *style,
2881 GtkStateType state_type,
2882 GtkShadowType shadow_type,
2884 const gchar *detail,
2889 GtkPositionType gap_side,
2893 GtkStyleContext *context;
2894 GtkStylePrivate *priv;
2895 GtkStateFlags flags = 0;
2898 context = gtk_widget_get_style_context (widget);
2901 priv = GTK_STYLE_GET_PRIVATE (style);
2902 context = priv->context;
2905 gtk_style_context_save (context);
2908 transform_detail_string (detail, context);
2912 case GTK_STATE_ACTIVE:
2913 flags |= GTK_STATE_FLAG_ACTIVE;
2915 case GTK_STATE_PRELIGHT:
2916 flags |= GTK_STATE_FLAG_PRELIGHT;
2918 case GTK_STATE_SELECTED:
2919 flags |= GTK_STATE_FLAG_SELECTED;
2921 case GTK_STATE_INSENSITIVE:
2922 flags |= GTK_STATE_FLAG_INSENSITIVE;
2928 gtk_style_context_set_state (context, flags);
2931 gtk_render_frame_gap (context, cr,
2938 (gdouble) gap_x + gap_width);
2941 gtk_style_context_restore (context);
2945 gtk_default_draw_box_gap (GtkStyle *style,
2947 GtkStateType state_type,
2948 GtkShadowType shadow_type,
2950 const gchar *detail,
2955 GtkPositionType gap_side,
2959 GtkStyleContext *context;
2960 GtkStylePrivate *priv;
2961 GtkStateFlags flags = 0;
2964 context = gtk_widget_get_style_context (widget);
2967 priv = GTK_STYLE_GET_PRIVATE (style);
2968 context = priv->context;
2971 gtk_style_context_save (context);
2974 transform_detail_string (detail, context);
2978 case GTK_STATE_ACTIVE:
2979 flags |= GTK_STATE_FLAG_ACTIVE;
2981 case GTK_STATE_PRELIGHT:
2982 flags |= GTK_STATE_FLAG_PRELIGHT;
2984 case GTK_STATE_SELECTED:
2985 flags |= GTK_STATE_FLAG_SELECTED;
2987 case GTK_STATE_INSENSITIVE:
2988 flags |= GTK_STATE_FLAG_INSENSITIVE;
2994 gtk_style_context_set_state (context, flags);
2997 gtk_render_background (context, cr,
3003 gtk_render_frame_gap (context, cr,
3010 (gdouble) gap_x + gap_width);
3013 gtk_style_context_restore (context);
3017 gtk_default_draw_extension (GtkStyle *style,
3019 GtkStateType state_type,
3020 GtkShadowType shadow_type,
3022 const gchar *detail,
3027 GtkPositionType gap_side)
3029 GtkStyleContext *context;
3030 GtkStylePrivate *priv;
3031 GtkStateFlags flags = 0;
3034 context = gtk_widget_get_style_context (widget);
3037 priv = GTK_STYLE_GET_PRIVATE (style);
3038 context = priv->context;
3041 gtk_style_context_save (context);
3044 transform_detail_string (detail, context);
3048 case GTK_STATE_ACTIVE:
3049 flags |= GTK_STATE_FLAG_ACTIVE;
3051 case GTK_STATE_PRELIGHT:
3052 flags |= GTK_STATE_FLAG_PRELIGHT;
3054 case GTK_STATE_SELECTED:
3055 flags |= GTK_STATE_FLAG_SELECTED;
3057 case GTK_STATE_INSENSITIVE:
3058 flags |= GTK_STATE_FLAG_INSENSITIVE;
3064 gtk_style_context_set_state (context, flags);
3068 gtk_render_extension (context, cr,
3076 gtk_style_context_restore (context);
3080 gtk_default_draw_focus (GtkStyle *style,
3082 GtkStateType state_type,
3084 const gchar *detail,
3090 GtkStyleContext *context;
3091 GtkStylePrivate *priv;
3094 context = gtk_widget_get_style_context (widget);
3097 priv = GTK_STYLE_GET_PRIVATE (style);
3098 context = priv->context;
3101 gtk_style_context_save (context);
3104 transform_detail_string (detail, context);
3108 gtk_render_focus (context, cr,
3115 gtk_style_context_restore (context);
3119 gtk_default_draw_slider (GtkStyle *style,
3121 GtkStateType state_type,
3122 GtkShadowType shadow_type,
3124 const gchar *detail,
3129 GtkOrientation orientation)
3131 GtkStyleContext *context;
3132 GtkStylePrivate *priv;
3133 GtkStateFlags flags = 0;
3136 context = gtk_widget_get_style_context (widget);
3139 priv = GTK_STYLE_GET_PRIVATE (style);
3140 context = priv->context;
3143 gtk_style_context_save (context);
3146 transform_detail_string (detail, context);
3150 case GTK_STATE_PRELIGHT:
3151 flags |= GTK_STATE_FLAG_PRELIGHT;
3153 case GTK_STATE_SELECTED:
3154 flags |= GTK_STATE_FLAG_SELECTED;
3156 case GTK_STATE_INSENSITIVE:
3157 flags |= GTK_STATE_FLAG_INSENSITIVE;
3163 gtk_style_context_set_state (context, flags);
3167 gtk_render_slider (context, cr, x, y, width, height, orientation);
3170 gtk_style_context_restore (context);
3174 draw_dot (cairo_t *cr,
3181 size = CLAMP (size, 2, 3);
3185 _cairo_draw_point (cr, light, x, y);
3186 _cairo_draw_point (cr, light, x+1, y+1);
3190 _cairo_draw_point (cr, light, x, y);
3191 _cairo_draw_point (cr, light, x+1, y);
3192 _cairo_draw_point (cr, light, x, y+1);
3193 _cairo_draw_point (cr, dark, x+1, y+2);
3194 _cairo_draw_point (cr, dark, x+2, y+1);
3195 _cairo_draw_point (cr, dark, x+2, y+2);
3200 gtk_default_draw_handle (GtkStyle *style,
3202 GtkStateType state_type,
3203 GtkShadowType shadow_type,
3205 const gchar *detail,
3210 GtkOrientation orientation)
3212 GtkStyleContext *context;
3213 GtkStylePrivate *priv;
3214 GtkStateFlags flags = 0;
3217 context = gtk_widget_get_style_context (widget);
3220 priv = GTK_STYLE_GET_PRIVATE (style);
3221 context = priv->context;
3224 gtk_style_context_save (context);
3227 transform_detail_string (detail, context);
3231 case GTK_STATE_PRELIGHT:
3232 flags |= GTK_STATE_FLAG_PRELIGHT;
3234 case GTK_STATE_SELECTED:
3235 flags |= GTK_STATE_FLAG_SELECTED;
3237 case GTK_STATE_INSENSITIVE:
3238 flags |= GTK_STATE_FLAG_INSENSITIVE;
3244 gtk_style_context_set_state (context, flags);
3248 gtk_render_handle (context, cr,
3255 gtk_style_context_restore (context);
3259 gtk_default_draw_expander (GtkStyle *style,
3261 GtkStateType state_type,
3263 const gchar *detail,
3266 GtkExpanderStyle expander_style)
3268 GtkStyleContext *context;
3269 GtkStylePrivate *priv;
3270 GtkStateFlags flags = 0;
3274 context = gtk_widget_get_style_context (widget);
3277 priv = GTK_STYLE_GET_PRIVATE (style);
3278 context = priv->context;
3281 gtk_style_context_save (context);
3284 transform_detail_string (detail, context);
3286 gtk_style_context_add_class (context, "expander");
3290 case GTK_STATE_PRELIGHT:
3291 flags |= GTK_STATE_FLAG_PRELIGHT;
3293 case GTK_STATE_SELECTED:
3294 flags |= GTK_STATE_FLAG_SELECTED;
3296 case GTK_STATE_INSENSITIVE:
3297 flags |= GTK_STATE_FLAG_INSENSITIVE;
3304 gtk_widget_class_find_style_property (GTK_WIDGET_GET_CLASS (widget),
3306 gtk_widget_style_get (widget, "expander-size", &size, NULL);
3310 if (expander_style == GTK_EXPANDER_EXPANDED)
3311 flags |= GTK_STATE_FLAG_ACTIVE;
3313 gtk_style_context_set_state (context, flags);
3317 gtk_render_expander (context, cr,
3318 (gdouble) x - (size / 2),
3319 (gdouble) y - (size / 2),
3324 gtk_style_context_restore (context);
3328 gtk_default_draw_layout (GtkStyle *style,
3330 GtkStateType state_type,
3333 const gchar *detail,
3336 PangoLayout *layout)
3338 GtkStyleContext *context;
3339 GtkStylePrivate *priv;
3340 GtkStateFlags flags = 0;
3343 context = gtk_widget_get_style_context (widget);
3346 priv = GTK_STYLE_GET_PRIVATE (style);
3347 context = priv->context;
3350 gtk_style_context_save (context);
3353 transform_detail_string (detail, context);
3357 case GTK_STATE_PRELIGHT:
3358 flags |= GTK_STATE_FLAG_PRELIGHT;
3360 case GTK_STATE_SELECTED:
3361 flags |= GTK_STATE_FLAG_SELECTED;
3363 case GTK_STATE_INSENSITIVE:
3364 flags |= GTK_STATE_FLAG_INSENSITIVE;
3370 gtk_style_context_set_state (context, flags);
3374 gtk_render_layout (context, cr,
3380 gtk_style_context_restore (context);
3384 gtk_default_draw_resize_grip (GtkStyle *style,
3386 GtkStateType state_type,
3388 const gchar *detail,
3395 GtkStyleContext *context;
3396 GtkStylePrivate *priv;
3397 GtkStateFlags flags = 0;
3398 GtkJunctionSides sides = 0;
3401 context = gtk_widget_get_style_context (widget);
3404 priv = GTK_STYLE_GET_PRIVATE (style);
3405 context = priv->context;
3408 gtk_style_context_save (context);
3411 transform_detail_string (detail, context);
3413 gtk_style_context_add_class (context, "grip");
3417 case GTK_STATE_PRELIGHT:
3418 flags |= GTK_STATE_FLAG_PRELIGHT;
3420 case GTK_STATE_SELECTED:
3421 flags |= GTK_STATE_FLAG_SELECTED;
3423 case GTK_STATE_INSENSITIVE:
3424 flags |= GTK_STATE_FLAG_INSENSITIVE;
3430 gtk_style_context_set_state (context, flags);
3434 case GDK_WINDOW_EDGE_NORTH_WEST:
3435 sides = GTK_JUNCTION_CORNER_TOPLEFT;
3437 case GDK_WINDOW_EDGE_NORTH:
3438 sides = GTK_JUNCTION_TOP;
3440 case GDK_WINDOW_EDGE_NORTH_EAST:
3441 sides = GTK_JUNCTION_CORNER_TOPRIGHT;
3443 case GDK_WINDOW_EDGE_WEST:
3444 sides = GTK_JUNCTION_LEFT;
3446 case GDK_WINDOW_EDGE_EAST:
3447 sides = GTK_JUNCTION_RIGHT;
3449 case GDK_WINDOW_EDGE_SOUTH_WEST:
3450 sides = GTK_JUNCTION_CORNER_BOTTOMLEFT;
3452 case GDK_WINDOW_EDGE_SOUTH:
3453 sides = GTK_JUNCTION_BOTTOM;
3455 case GDK_WINDOW_EDGE_SOUTH_EAST:
3456 sides = GTK_JUNCTION_CORNER_BOTTOMRIGHT;
3460 gtk_style_context_set_junction_sides (context, sides);
3464 gtk_render_handle (context, cr,
3471 gtk_style_context_restore (context);
3475 gtk_default_draw_spinner (GtkStyle *style,
3477 GtkStateType state_type,
3479 const gchar *detail,
3494 gtk_style_get (style, GTK_TYPE_SPINNER,
3495 "num-steps", &num_steps,
3497 real_step = step % num_steps;
3499 /* set a clip region for the expose event */
3500 cairo_rectangle (cr, x, y, width, height);
3503 cairo_translate (cr, x, y);
3505 /* draw clip region */
3506 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
3508 color = &style->fg[state_type];
3511 radius = MIN (width / 2, height / 2);
3512 half = num_steps / 2;
3514 for (i = 0; i < num_steps; i++)
3516 gint inset = 0.7 * radius;
3518 /* transparency is a function of time and intial value */
3519 gdouble t = (gdouble) ((i + num_steps - real_step)
3520 % num_steps) / num_steps;
3524 cairo_set_source_rgba (cr,
3525 color->red / 65535.,
3526 color->green / 65535.,
3527 color->blue / 65535.,
3530 cairo_set_line_width (cr, 2.0);
3532 dx + (radius - inset) * cos (i * G_PI / half),
3533 dy + (radius - inset) * sin (i * G_PI / half));
3535 dx + radius * cos (i * G_PI / half),
3536 dy + radius * sin (i * G_PI / half));
3544 _gtk_style_shade (const GdkColor *a,
3552 red = (gdouble) a->red / 65535.0;
3553 green = (gdouble) a->green / 65535.0;
3554 blue = (gdouble) a->blue / 65535.0;
3556 rgb_to_hls (&red, &green, &blue);
3561 else if (green < 0.0)
3567 else if (blue < 0.0)
3570 hls_to_rgb (&red, &green, &blue);
3572 b->red = red * 65535.0;
3573 b->green = green * 65535.0;
3574 b->blue = blue * 65535.0;
3578 rgb_to_hls (gdouble *r,
3619 l = (max + min) / 2;
3626 s = (max - min) / (max + min);
3628 s = (max - min) / (2 - max - min);
3632 h = (green - blue) / delta;
3633 else if (green == max)
3634 h = 2 + (blue - red) / delta;
3635 else if (blue == max)
3636 h = 4 + (red - green) / delta;
3649 hls_to_rgb (gdouble *h,
3662 if (lightness <= 0.5)
3663 m2 = lightness * (1 + saturation);
3665 m2 = lightness + saturation - lightness * saturation;
3666 m1 = 2 * lightness - m2;
3668 if (saturation == 0)
3683 r = m1 + (m2 - m1) * hue / 60;
3687 r = m1 + (m2 - m1) * (240 - hue) / 60;
3698 g = m1 + (m2 - m1) * hue / 60;
3702 g = m1 + (m2 - m1) * (240 - hue) / 60;
3713 b = m1 + (m2 - m1) * hue / 60;
3717 b = m1 + (m2 - m1) * (240 - hue) / 60;
3730 * @style: a #GtkStyle
3732 * @state_type: a state
3733 * @widget: (allow-none): the widget
3734 * @detail: (allow-none): a style detail
3735 * @x1: the starting x coordinate
3736 * @x2: the ending x coordinate
3737 * @y: the y coordinate
3739 * Draws a horizontal line from (@x1, @y) to (@x2, @y) in @cr
3740 * using the given style and state.
3742 * Deprecated:3.0: Use gtk_render_line() instead
3745 gtk_paint_hline (GtkStyle *style,
3747 GtkStateType state_type,
3749 const gchar *detail,
3754 g_return_if_fail (GTK_IS_STYLE (style));
3755 g_return_if_fail (cr != NULL);
3756 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
3760 GTK_STYLE_GET_CLASS (style)->draw_hline (style, cr, state_type,
3769 * @style: a #GtkStyle
3771 * @state_type: a state
3772 * @widget: (allow-none): the widget
3773 * @detail: (allow-none): a style detail
3774 * @y1_: the starting y coordinate
3775 * @y2_: the ending y coordinate
3776 * @x: the x coordinate
3778 * Draws a vertical line from (@x, @y1_) to (@x, @y2_) in @cr
3779 * using the given style and state.
3781 * Deprecated:3.0: Use gtk_render_line() instead
3784 gtk_paint_vline (GtkStyle *style,
3786 GtkStateType state_type,
3788 const gchar *detail,
3793 g_return_if_fail (GTK_IS_STYLE (style));
3794 g_return_if_fail (cr != NULL);
3795 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
3799 GTK_STYLE_GET_CLASS (style)->draw_vline (style, cr, state_type,
3808 * @style: a #GtkStyle
3810 * @state_type: a state
3811 * @shadow_type: type of shadow to draw
3812 * @widget: (allow-none): the widget
3813 * @detail: (allow-none): a style detail
3814 * @x: x origin of the rectangle
3815 * @y: y origin of the rectangle
3816 * @width: width of the rectangle
3817 * @height: width of the rectangle
3819 * Draws a shadow around the given rectangle in @cr
3820 * using the given style and state and shadow type.
3822 * Deprecated:3.0: Use gtk_render_frame() instead
3825 gtk_paint_shadow (GtkStyle *style,
3827 GtkStateType state_type,
3828 GtkShadowType shadow_type,
3830 const gchar *detail,
3836 g_return_if_fail (GTK_IS_STYLE (style));
3837 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
3838 g_return_if_fail (cr != NULL);
3839 g_return_if_fail (width >= 0);
3840 g_return_if_fail (height >= 0);
3844 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, cr, state_type, shadow_type,
3846 x, y, width, height);
3853 * @style: a #GtkStyle
3855 * @state_type: a state
3856 * @shadow_type: the type of shadow to draw
3857 * @widget: (allow-none): the widget
3858 * @detail: (allow-none): a style detail
3859 * @arrow_type: the type of arrow to draw
3860 * @fill: %TRUE if the arrow tip should be filled
3861 * @x: x origin of the rectangle to draw the arrow in
3862 * @y: y origin of the rectangle to draw the arrow in
3863 * @width: width of the rectangle to draw the arrow in
3864 * @height: height of the rectangle to draw the arrow in
3866 * Draws an arrow in the given rectangle on @cr using the given
3867 * parameters. @arrow_type determines the direction of the arrow.
3869 * Deprecated:3.0: Use gtk_render_arrow() instead
3872 gtk_paint_arrow (GtkStyle *style,
3874 GtkStateType state_type,
3875 GtkShadowType shadow_type,
3877 const gchar *detail,
3878 GtkArrowType arrow_type,
3885 g_return_if_fail (GTK_IS_STYLE (style));
3886 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
3887 g_return_if_fail (cr != NULL);
3888 g_return_if_fail (width >= 0);
3889 g_return_if_fail (height >= 0);
3893 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, cr, state_type, shadow_type,
3895 arrow_type, fill, x, y, width, height);
3901 * gtk_paint_diamond:
3902 * @style: a #GtkStyle
3904 * @state_type: a state
3905 * @shadow_type: the type of shadow to draw
3906 * @widget: (allow-none): the widget
3907 * @detail: (allow-none): a style detail
3908 * @x: x origin of the rectangle to draw the diamond in
3909 * @y: y origin of the rectangle to draw the diamond in
3910 * @width: width of the rectangle to draw the diamond in
3911 * @height: height of the rectangle to draw the diamond in
3913 * Draws a diamond in the given rectangle on @window using the given
3916 * Deprecated:3.0: Use cairo instead
3919 gtk_paint_diamond (GtkStyle *style,
3921 GtkStateType state_type,
3922 GtkShadowType shadow_type,
3924 const gchar *detail,
3930 g_return_if_fail (GTK_IS_STYLE (style));
3931 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
3932 g_return_if_fail (cr != NULL);
3933 g_return_if_fail (width >= 0);
3934 g_return_if_fail (height >= 0);
3938 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, cr, state_type, shadow_type,
3940 x, y, width, height);
3947 * @style: a #GtkStyle
3949 * @state_type: a state
3950 * @shadow_type: the type of shadow to draw
3951 * @widget: (allow-none): the widget
3952 * @detail: (allow-none): a style detail
3953 * @x: x origin of the box
3954 * @y: y origin of the box
3955 * @width: the width of the box
3956 * @height: the height of the box
3958 * Draws a box on @cr with the given parameters.
3960 * Deprecated:3.0: Use gtk_render_frame() and gtk_render_background() instead
3963 gtk_paint_box (GtkStyle *style,
3965 GtkStateType state_type,
3966 GtkShadowType shadow_type,
3968 const gchar *detail,
3974 g_return_if_fail (GTK_IS_STYLE (style));
3975 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
3976 g_return_if_fail (cr != NULL);
3980 GTK_STYLE_GET_CLASS (style)->draw_box (style, cr, state_type, shadow_type,
3982 x, y, width, height);
3988 * gtk_paint_flat_box:
3989 * @style: a #GtkStyle
3991 * @state_type: a state
3992 * @shadow_type: the type of shadow to draw
3993 * @area: (allow-none): clip rectangle, or %NULL if the
3994 * output should not be clipped
3995 * @widget: (allow-none): the widget
3996 * @detail: (allow-none): a style detail
3997 * @x: x origin of the box
3998 * @y: y origin of the box
3999 * @width: the width of the box
4000 * @height: the height of the box
4002 * Draws a flat box on @cr with the given parameters.
4004 * Deprecated:3.0: Use gtk_render_frame() and gtk_render_background() instead
4007 gtk_paint_flat_box (GtkStyle *style,
4009 GtkStateType state_type,
4010 GtkShadowType shadow_type,
4012 const gchar *detail,
4018 g_return_if_fail (GTK_IS_STYLE (style));
4019 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
4020 g_return_if_fail (cr != NULL);
4021 g_return_if_fail (width >= 0);
4022 g_return_if_fail (height >= 0);
4026 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, cr, state_type, shadow_type,
4028 x, y, width, height);
4035 * @style: a #GtkStyle
4037 * @state_type: a state
4038 * @shadow_type: the type of shadow to draw
4039 * @widget: (allow-none): the widget
4040 * @detail: (allow-none): a style detail
4041 * @x: x origin of the rectangle to draw the check in
4042 * @y: y origin of the rectangle to draw the check in
4043 * @width: the width of the rectangle to draw the check in
4044 * @height: the height of the rectangle to draw the check in
4046 * Draws a check button indicator in the given rectangle on @cr with
4047 * the given parameters.
4049 * Deprecated:3.0: Use gtk_render_check() instead
4052 gtk_paint_check (GtkStyle *style,
4054 GtkStateType state_type,
4055 GtkShadowType shadow_type,
4057 const gchar *detail,
4063 g_return_if_fail (GTK_IS_STYLE (style));
4064 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
4065 g_return_if_fail (cr != NULL);
4069 GTK_STYLE_GET_CLASS (style)->draw_check (style, cr, state_type, shadow_type,
4071 x, y, width, height);
4078 * @style: a #GtkStyle
4080 * @state_type: a state
4081 * @shadow_type: the type of shadow to draw
4082 * @widget: (allow-none): the widget
4083 * @detail: (allow-none): a style detail
4084 * @x: x origin of the rectangle to draw the option in
4085 * @y: y origin of the rectangle to draw the option in
4086 * @width: the width of the rectangle to draw the option in
4087 * @height: the height of the rectangle to draw the option in
4089 * Draws a radio button indicator in the given rectangle on @cr with
4090 * the given parameters.
4092 * Deprecated:3.0: Use gtk_render_option() instead
4095 gtk_paint_option (GtkStyle *style,
4097 GtkStateType state_type,
4098 GtkShadowType shadow_type,
4100 const gchar *detail,
4106 g_return_if_fail (GTK_IS_STYLE (style));
4107 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
4108 g_return_if_fail (cr != NULL);
4112 GTK_STYLE_GET_CLASS (style)->draw_option (style, cr, state_type, shadow_type,
4114 x, y, width, height);
4121 * @style: a #GtkStyle
4123 * @state_type: a state
4124 * @shadow_type: the type of shadow to draw
4125 * @widget: (allow-none): the widget
4126 * @detail: (allow-none): a style detail
4127 * @x: x origin of the rectangle to draw the tab in
4128 * @y: y origin of the rectangle to draw the tab in
4129 * @width: the width of the rectangle to draw the tab in
4130 * @height: the height of the rectangle to draw the tab in
4132 * Draws an option menu tab (i.e. the up and down pointing arrows)
4133 * in the given rectangle on @cr using the given parameters.
4135 * Deprecated:3.0: Use cairo instead
4138 gtk_paint_tab (GtkStyle *style,
4140 GtkStateType state_type,
4141 GtkShadowType shadow_type,
4143 const gchar *detail,
4149 g_return_if_fail (GTK_IS_STYLE (style));
4150 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
4151 g_return_if_fail (cr != NULL);
4155 GTK_STYLE_GET_CLASS (style)->draw_tab (style, cr, state_type, shadow_type,
4157 x, y, width, height);
4163 * gtk_paint_shadow_gap:
4164 * @style: a #GtkStyle
4166 * @state_type: a state
4167 * @shadow_type: type of shadow to draw
4168 * @widget: (allow-none): the widget
4169 * @detail: (allow-none): a style detail
4170 * @x: x origin of the rectangle
4171 * @y: y origin of the rectangle
4172 * @width: width of the rectangle
4173 * @height: width of the rectangle
4174 * @gap_side: side in which to leave the gap
4175 * @gap_x: starting position of the gap
4176 * @gap_width: width of the gap
4178 * Draws a shadow around the given rectangle in @cr
4179 * using the given style and state and shadow type, leaving a
4182 * Deprecated:3.0: Use gtk_render_frame_gap() instead
4185 gtk_paint_shadow_gap (GtkStyle *style,
4187 GtkStateType state_type,
4188 GtkShadowType shadow_type,
4190 const gchar *detail,
4195 GtkPositionType gap_side,
4199 g_return_if_fail (GTK_IS_STYLE (style));
4200 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
4201 g_return_if_fail (cr != NULL);
4202 g_return_if_fail (width >= 0);
4203 g_return_if_fail (height >= 0);
4207 GTK_STYLE_GET_CLASS (style)->draw_shadow_gap (style, cr, state_type, shadow_type,
4209 x, y, width, height, gap_side, gap_x, gap_width);
4215 * gtk_paint_box_gap:
4216 * @style: a #GtkStyle
4218 * @state_type: a state
4219 * @shadow_type: type of shadow to draw
4220 * @widget: (allow-none): the widget
4221 * @detail: (allow-none): a style detail
4222 * @x: x origin of the rectangle
4223 * @y: y origin of the rectangle
4224 * @width: width of the rectangle
4225 * @height: width of the rectangle
4226 * @gap_side: side in which to leave the gap
4227 * @gap_x: starting position of the gap
4228 * @gap_width: width of the gap
4230 * Draws a box in @cr using the given style and state and shadow type,
4231 * leaving a gap in one side.
4233 * Deprecated:3.0: Use gtk_render_frame_gap() instead
4236 gtk_paint_box_gap (GtkStyle *style,
4238 GtkStateType state_type,
4239 GtkShadowType shadow_type,
4241 const gchar *detail,
4246 GtkPositionType gap_side,
4250 g_return_if_fail (GTK_IS_STYLE (style));
4251 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
4252 g_return_if_fail (cr != NULL);
4253 g_return_if_fail (width >= 0);
4254 g_return_if_fail (height >= 0);
4258 GTK_STYLE_GET_CLASS (style)->draw_box_gap (style, cr, state_type, shadow_type,
4260 x, y, width, height, gap_side, gap_x, gap_width);
4266 * gtk_paint_extension:
4267 * @style: a #GtkStyle
4269 * @state_type: a state
4270 * @shadow_type: type of shadow to draw
4271 * @widget: (allow-none): the widget
4272 * @detail: (allow-none): a style detail
4273 * @x: x origin of the extension
4274 * @y: y origin of the extension
4275 * @width: width of the extension
4276 * @height: width of the extension
4277 * @gap_side: the side on to which the extension is attached
4279 * Draws an extension, i.e. a notebook tab.
4281 * Deprecated:3.0: Use gtk_render_extension() instead
4284 gtk_paint_extension (GtkStyle *style,
4286 GtkStateType state_type,
4287 GtkShadowType shadow_type,
4289 const gchar *detail,
4294 GtkPositionType gap_side)
4296 g_return_if_fail (GTK_IS_STYLE (style));
4297 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
4298 g_return_if_fail (cr != NULL);
4299 g_return_if_fail (width >= 0);
4300 g_return_if_fail (height >= 0);
4304 GTK_STYLE_GET_CLASS (style)->draw_extension (style, cr, state_type, shadow_type,
4306 x, y, width, height, gap_side);
4313 * @style: a #GtkStyle
4315 * @state_type: a state
4316 * @widget: (allow-none): the widget
4317 * @detail: (allow-none): a style detail
4318 * @x: the x origin of the rectangle around which to draw a focus indicator
4319 * @y: the y origin of the rectangle around which to draw a focus indicator
4320 * @width: the width of the rectangle around which to draw a focus indicator
4321 * @height: the height of the rectangle around which to draw a focus indicator
4323 * Draws a focus indicator around the given rectangle on @cr using the
4326 * Deprecated:3.0: Use gtk_render_focus() instead
4329 gtk_paint_focus (GtkStyle *style,
4331 GtkStateType state_type,
4333 const gchar *detail,
4339 g_return_if_fail (GTK_IS_STYLE (style));
4340 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
4341 g_return_if_fail (cr != NULL);
4342 g_return_if_fail (width >= 0);
4343 g_return_if_fail (height >= 0);
4347 GTK_STYLE_GET_CLASS (style)->draw_focus (style, cr, state_type,
4349 x, y, width, height);
4356 * @style: a #GtkStyle
4358 * @state_type: a state
4359 * @shadow_type: a shadow
4360 * @widget: (allow-none): the widget
4361 * @detail: (allow-none): a style detail
4362 * @x: the x origin of the rectangle in which to draw a slider
4363 * @y: the y origin of the rectangle in which to draw a slider
4364 * @width: the width of the rectangle in which to draw a slider
4365 * @height: the height of the rectangle in which to draw a slider
4366 * @orientation: the orientation to be used
4368 * Draws a slider in the given rectangle on @cr using the
4369 * given style and orientation.
4371 * Deprecated:3.0: Use gtk_render_slider() instead
4374 gtk_paint_slider (GtkStyle *style,
4376 GtkStateType state_type,
4377 GtkShadowType shadow_type,
4379 const gchar *detail,
4384 GtkOrientation orientation)
4386 g_return_if_fail (GTK_IS_STYLE (style));
4387 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
4388 g_return_if_fail (cr != NULL);
4389 g_return_if_fail (width >= 0);
4390 g_return_if_fail (height >= 0);
4394 GTK_STYLE_GET_CLASS (style)->draw_slider (style, cr, state_type, shadow_type,
4396 x, y, width, height, orientation);
4403 * @style: a #GtkStyle
4405 * @state_type: a state
4406 * @shadow_type: type of shadow to draw
4407 * @widget: (allow-none): the widget
4408 * @detail: (allow-none): a style detail
4409 * @x: x origin of the handle
4410 * @y: y origin of the handle
4411 * @width: with of the handle
4412 * @height: height of the handle
4413 * @orientation: the orientation of the handle
4415 * Draws a handle as used in #GtkHandleBox and #GtkPaned.
4417 * Deprecated:3.0: Use gtk_render_handle() instead
4420 gtk_paint_handle (GtkStyle *style,
4422 GtkStateType state_type,
4423 GtkShadowType shadow_type,
4425 const gchar *detail,
4430 GtkOrientation orientation)
4432 g_return_if_fail (GTK_IS_STYLE (style));
4433 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
4434 g_return_if_fail (cr != NULL);
4435 g_return_if_fail (width >= 0);
4436 g_return_if_fail (height >= 0);
4440 GTK_STYLE_GET_CLASS (style)->draw_handle (style, cr, state_type, shadow_type,
4442 x, y, width, height, orientation);
4448 * gtk_paint_expander:
4449 * @style: a #GtkStyle
4451 * @state_type: a state
4452 * @widget: (allow-none): the widget
4453 * @detail: (allow-none): a style detail
4454 * @x: the x position to draw the expander at
4455 * @y: the y position to draw the expander at
4456 * @expander_style: the style to draw the expander in; determines
4457 * whether the expander is collapsed, expanded, or in an
4458 * intermediate state.
4460 * Draws an expander as used in #GtkTreeView. @x and @y specify the
4461 * center the expander. The size of the expander is determined by the
4462 * "expander-size" style property of @widget. (If widget is not
4463 * specified or doesn't have an "expander-size" property, an
4464 * unspecified default size will be used, since the caller doesn't
4465 * have sufficient information to position the expander, this is
4466 * likely not useful.) The expander is expander_size pixels tall
4467 * in the collapsed position and expander_size pixels wide in the
4468 * expanded position.
4470 * Deprecated:3.0: Use gtk_render_expander() instead
4473 gtk_paint_expander (GtkStyle *style,
4475 GtkStateType state_type,
4477 const gchar *detail,
4480 GtkExpanderStyle expander_style)
4482 g_return_if_fail (GTK_IS_STYLE (style));
4483 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
4484 g_return_if_fail (cr != NULL);
4488 GTK_STYLE_GET_CLASS (style)->draw_expander (style, cr, state_type,
4490 x, y, expander_style);
4497 * @style: a #GtkStyle
4499 * @state_type: a state
4500 * @use_text: whether to use the text or foreground
4501 * graphics context of @style
4502 * @widget: (allow-none): the widget
4503 * @detail: (allow-none): a style detail
4506 * @layout: the layout to draw
4508 * Draws a layout on @cr using the given parameters.
4510 * Deprecated:3.0: Use gtk_render_layout() instead
4513 gtk_paint_layout (GtkStyle *style,
4515 GtkStateType state_type,
4518 const gchar *detail,
4521 PangoLayout *layout)
4523 g_return_if_fail (GTK_IS_STYLE (style));
4524 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
4525 g_return_if_fail (cr != NULL);
4529 GTK_STYLE_GET_CLASS (style)->draw_layout (style, cr, state_type, use_text,
4537 * gtk_paint_resize_grip:
4538 * @style: a #GtkStyle
4540 * @state_type: a state
4541 * @widget: (allow-none): the widget
4542 * @detail: (allow-none): a style detail
4543 * @edge: the edge in which to draw the resize grip
4544 * @x: the x origin of the rectangle in which to draw the resize grip
4545 * @y: the y origin of the rectangle in which to draw the resize grip
4546 * @width: the width of the rectangle in which to draw the resize grip
4547 * @height: the height of the rectangle in which to draw the resize grip
4549 * Draws a resize grip in the given rectangle on @cr using the given
4552 * Deprecated:3.0: Use gtk_render_handle() instead
4555 gtk_paint_resize_grip (GtkStyle *style,
4557 GtkStateType state_type,
4559 const gchar *detail,
4566 g_return_if_fail (GTK_IS_STYLE (style));
4567 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
4568 g_return_if_fail (cr != NULL);
4572 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, cr, state_type,
4574 edge, x, y, width, height);
4579 * gtk_paint_spinner:
4580 * @style: a #GtkStyle
4582 * @state_type: a state
4583 * @widget: (allow-none): the widget (may be %NULL)
4584 * @detail: (allow-none): a style detail (may be %NULL)
4585 * @step: the nth step, a value between 0 and #GtkSpinner:num-steps
4586 * @x: the x origin of the rectangle in which to draw the spinner
4587 * @y: the y origin of the rectangle in which to draw the spinner
4588 * @width: the width of the rectangle in which to draw the spinner
4589 * @height: the height of the rectangle in which to draw the spinner
4591 * Draws a spinner on @window using the given parameters.
4593 * Deprecated:3.0: Use gtk_render_activity() instead
4596 gtk_paint_spinner (GtkStyle *style,
4598 GtkStateType state_type,
4600 const gchar *detail,
4607 g_return_if_fail (GTK_IS_STYLE (style));
4608 g_return_if_fail (cr != NULL);
4609 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_spinner != NULL);
4613 GTK_STYLE_GET_CLASS (style)->draw_spinner (style, cr, state_type,
4615 step, x, y, width, height);
4620 typedef struct _CursorInfo CursorInfo;
4630 style_unrealize_cursors (GtkStyle *style)
4634 cursor_info = g_object_get_data (G_OBJECT (style), "gtk-style-cursor-info");
4637 g_free (cursor_info);
4638 g_object_set_data (G_OBJECT (style), I_("gtk-style-cursor-info"), NULL);
4642 static const GdkColor *
4643 get_insertion_cursor_color (GtkWidget *widget,
4644 gboolean is_primary)
4646 CursorInfo *cursor_info;
4648 GdkColor *cursor_color;
4650 style = gtk_widget_get_style (widget);
4652 cursor_info = g_object_get_data (G_OBJECT (style), "gtk-style-cursor-info");
4655 cursor_info = g_new0 (CursorInfo, 1);
4656 g_object_set_data (G_OBJECT (style), I_("gtk-style-cursor-info"), cursor_info);
4657 cursor_info->for_type = G_TYPE_INVALID;
4660 /* We have to keep track of the type because gtk_widget_style_get()
4661 * can return different results when called on the same property and
4662 * same style but for different widgets. :-(. That is,
4663 * GtkEntry::cursor-color = "red" in a style will modify the cursor
4664 * color for entries but not for text view.
4666 if (cursor_info->for_type != G_OBJECT_TYPE (widget))
4668 cursor_info->for_type = G_OBJECT_TYPE (widget);
4670 /* Cursors in text widgets are drawn only in NORMAL state,
4671 * so we can use text[GTK_STATE_NORMAL] as text color here */
4672 gtk_widget_style_get (widget, "cursor-color", &cursor_color, NULL);
4675 cursor_info->primary = *cursor_color;
4676 gdk_color_free (cursor_color);
4680 cursor_info->primary = style->text[GTK_STATE_NORMAL];
4683 gtk_widget_style_get (widget, "secondary-cursor-color", &cursor_color, NULL);
4686 cursor_info->secondary = *cursor_color;
4687 gdk_color_free (cursor_color);
4691 /* text_aa is the average of text and base colors,
4692 * in usual black-on-white case it's grey. */
4693 cursor_info->secondary = style->text_aa[GTK_STATE_NORMAL];
4698 return &cursor_info->primary;
4700 return &cursor_info->secondary;
4704 _gtk_widget_get_cursor_color (GtkWidget *widget,
4707 GdkColor *style_color;
4709 g_return_if_fail (GTK_IS_WIDGET (widget));
4710 g_return_if_fail (color != NULL);
4712 gtk_widget_style_get (widget, "cursor-color", &style_color, NULL);
4716 *color = *style_color;
4717 gdk_color_free (style_color);
4720 *color = gtk_widget_get_style (widget)->text[GTK_STATE_NORMAL];
4724 * gtk_draw_insertion_cursor:
4725 * @widget: a #GtkWidget
4726 * @cr: cairo context to draw to
4727 * @location: location where to draw the cursor (@location->width is ignored)
4728 * @is_primary: if the cursor should be the primary cursor color.
4729 * @direction: whether the cursor is left-to-right or
4730 * right-to-left. Should never be #GTK_TEXT_DIR_NONE
4731 * @draw_arrow: %TRUE to draw a directional arrow on the
4732 * cursor. Should be %FALSE unless the cursor is split.
4734 * Draws a text caret on @cr at @location. This is not a style function
4735 * but merely a convenience function for drawing the standard cursor shape.
4740 gtk_draw_insertion_cursor (GtkWidget *widget,
4742 const GdkRectangle *location,
4743 gboolean is_primary,
4744 GtkTextDirection direction,
4745 gboolean draw_arrow)
4750 gfloat cursor_aspect_ratio;
4753 g_return_if_fail (GTK_IS_WIDGET (widget));
4754 g_return_if_fail (cr != NULL);
4755 g_return_if_fail (location != NULL);
4756 g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
4758 gdk_cairo_set_source_color (cr, get_insertion_cursor_color (widget, is_primary));
4760 /* When changing the shape or size of the cursor here,
4761 * propagate the changes to gtktextview.c:text_window_invalidate_cursors().
4764 gtk_widget_style_get (widget, "cursor-aspect-ratio", &cursor_aspect_ratio, NULL);
4766 stem_width = location->height * cursor_aspect_ratio + 1;
4767 arrow_width = stem_width + 1;
4769 /* put (stem_width % 2) on the proper side of the cursor */
4770 if (direction == GTK_TEXT_DIR_LTR)
4771 offset = stem_width / 2;
4773 offset = stem_width - stem_width / 2;
4775 cairo_rectangle (cr,
4776 location->x - offset, location->y,
4777 stem_width, location->height);
4782 if (direction == GTK_TEXT_DIR_RTL)
4784 x = location->x - offset - 1;
4785 y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
4787 cairo_move_to (cr, x, y + 1);
4788 cairo_line_to (cr, x - arrow_width, y + arrow_width);
4789 cairo_line_to (cr, x, y + 2 * arrow_width);
4792 else if (direction == GTK_TEXT_DIR_LTR)
4794 x = location->x + stem_width - offset;
4795 y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
4797 cairo_move_to (cr, x, y + 1);
4798 cairo_line_to (cr, x + arrow_width, y + arrow_width);
4799 cairo_line_to (cr, x, y + 2 * arrow_width);