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, see <http://www.gnu.org/licenses/>.
19 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GTK+ Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
27 #define GDK_DISABLE_DEPRECATION_WARNINGS
32 #include <gobject/gvaluecollector.h>
33 #include "gtkmarshalers.h"
36 #include "gtkspinbutton.h"
38 #include "gtkstylecontextprivate.h"
39 #include "gtkwidget.h"
40 #include "gtkwidgetprivate.h"
41 #include "gtkiconfactory.h"
44 #include "gtkspinner.h"
45 #include "gtkborder.h"
46 #include "gtkwidgetpath.h"
50 * @Short_description: Deprecated object that holds style information
54 * A #GtkStyle object encapsulates the information that provides the look and
58 * In GTK+ 3.0, GtkStyle has been deprecated and replaced by #GtkStyleContext.
61 * Each #GtkWidget has an associated #GtkStyle object that is used when
62 * rendering that widget. Also, a #GtkStyle holds information for the five
63 * possible widget states though not every widget supports all five
64 * states; see #GtkStateType.
66 * Usually the #GtkStyle for a widget is the same as the default style that
67 * is set by GTK+ and modified the theme engine.
69 * Usually applications should not need to use or modify the #GtkStyle of
74 #define LIGHTNESS_MULT 1.3
75 #define DARKNESS_MULT 0.7
77 /* --- typedefs & structures --- */
84 #define GTK_STYLE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_STYLE, GtkStylePrivate))
86 typedef struct _GtkStylePrivate GtkStylePrivate;
88 struct _GtkStylePrivate {
89 GtkStyleContext *context;
90 gulong context_changed_id;
98 /* --- prototypes --- */
99 static void gtk_style_finalize (GObject *object);
100 static void gtk_style_constructed (GObject *object);
101 static void gtk_style_set_property (GObject *object,
105 static void gtk_style_get_property (GObject *object,
110 static void gtk_style_real_realize (GtkStyle *style);
111 static void gtk_style_real_unrealize (GtkStyle *style);
112 static void gtk_style_real_copy (GtkStyle *style,
114 static void gtk_style_real_set_background (GtkStyle *style,
116 GtkStateType state_type);
117 static GtkStyle *gtk_style_real_clone (GtkStyle *style);
118 static void gtk_style_real_init_from_rc (GtkStyle *style,
119 GtkRcStyle *rc_style);
120 static GdkPixbuf *gtk_default_render_icon (GtkStyle *style,
121 const GtkIconSource *source,
122 GtkTextDirection direction,
126 const gchar *detail);
127 static void gtk_default_draw_hline (GtkStyle *style,
129 GtkStateType state_type,
135 static void gtk_default_draw_vline (GtkStyle *style,
137 GtkStateType state_type,
143 static void gtk_default_draw_shadow (GtkStyle *style,
145 GtkStateType state_type,
146 GtkShadowType shadow_type,
153 static void gtk_default_draw_arrow (GtkStyle *style,
155 GtkStateType state_type,
156 GtkShadowType shadow_type,
159 GtkArrowType arrow_type,
165 static void gtk_default_draw_diamond (GtkStyle *style,
167 GtkStateType state_type,
168 GtkShadowType shadow_type,
175 static void gtk_default_draw_box (GtkStyle *style,
177 GtkStateType state_type,
178 GtkShadowType shadow_type,
185 static void gtk_default_draw_flat_box (GtkStyle *style,
187 GtkStateType state_type,
188 GtkShadowType shadow_type,
195 static void gtk_default_draw_check (GtkStyle *style,
197 GtkStateType state_type,
198 GtkShadowType shadow_type,
205 static void gtk_default_draw_option (GtkStyle *style,
207 GtkStateType state_type,
208 GtkShadowType shadow_type,
215 static void gtk_default_draw_tab (GtkStyle *style,
217 GtkStateType state_type,
218 GtkShadowType shadow_type,
225 static void gtk_default_draw_shadow_gap (GtkStyle *style,
227 GtkStateType state_type,
228 GtkShadowType shadow_type,
235 GtkPositionType gap_side,
238 static void gtk_default_draw_box_gap (GtkStyle *style,
240 GtkStateType state_type,
241 GtkShadowType shadow_type,
248 GtkPositionType gap_side,
251 static void gtk_default_draw_extension (GtkStyle *style,
253 GtkStateType state_type,
254 GtkShadowType shadow_type,
261 GtkPositionType gap_side);
262 static void gtk_default_draw_focus (GtkStyle *style,
264 GtkStateType state_type,
271 static void gtk_default_draw_slider (GtkStyle *style,
273 GtkStateType state_type,
274 GtkShadowType shadow_type,
281 GtkOrientation orientation);
282 static void gtk_default_draw_handle (GtkStyle *style,
284 GtkStateType state_type,
285 GtkShadowType shadow_type,
292 GtkOrientation orientation);
293 static void gtk_default_draw_expander (GtkStyle *style,
295 GtkStateType state_type,
300 GtkExpanderStyle expander_style);
301 static void gtk_default_draw_layout (GtkStyle *style,
303 GtkStateType state_type,
309 PangoLayout *layout);
310 static void gtk_default_draw_resize_grip (GtkStyle *style,
312 GtkStateType state_type,
320 static void gtk_default_draw_spinner (GtkStyle *style,
322 GtkStateType state_type,
331 static void rgb_to_hls (gdouble *r,
334 static void hls_to_rgb (gdouble *h,
338 static void transform_detail_string (const gchar *detail,
339 GtkStyleContext *context);
342 * Data for default check and radio buttons
345 static const GtkRequisition default_option_indicator_size = { 7, 13 };
346 static const GtkBorder default_option_indicator_spacing = { 7, 5, 2, 2 };
348 #define GTK_GRAY 0xdcdc, 0xdada, 0xd5d5
349 #define GTK_DARK_GRAY 0xc4c4, 0xc2c2, 0xbdbd
350 #define GTK_LIGHT_GRAY 0xeeee, 0xebeb, 0xe7e7
351 #define GTK_WHITE 0xffff, 0xffff, 0xffff
352 #define GTK_BLUE 0x4b4b, 0x6969, 0x8383
353 #define GTK_VERY_DARK_GRAY 0x9c9c, 0x9a9a, 0x9494
354 #define GTK_BLACK 0x0000, 0x0000, 0x0000
355 #define GTK_WEAK_GRAY 0x7530, 0x7530, 0x7530
357 /* --- variables --- */
358 static const GdkColor gtk_default_normal_fg = { 0, GTK_BLACK };
359 static const GdkColor gtk_default_active_fg = { 0, GTK_BLACK };
360 static const GdkColor gtk_default_prelight_fg = { 0, GTK_BLACK };
361 static const GdkColor gtk_default_selected_fg = { 0, GTK_WHITE };
362 static const GdkColor gtk_default_insensitive_fg = { 0, GTK_WEAK_GRAY };
364 static const GdkColor gtk_default_normal_bg = { 0, GTK_GRAY };
365 static const GdkColor gtk_default_active_bg = { 0, GTK_DARK_GRAY };
366 static const GdkColor gtk_default_prelight_bg = { 0, GTK_LIGHT_GRAY };
367 static const GdkColor gtk_default_selected_bg = { 0, GTK_BLUE };
368 static const GdkColor gtk_default_insensitive_bg = { 0, GTK_GRAY };
369 static const GdkColor gtk_default_selected_base = { 0, GTK_BLUE };
370 static const GdkColor gtk_default_active_base = { 0, GTK_VERY_DARK_GRAY };
372 /* --- signals --- */
373 static guint realize_signal = 0;
374 static guint unrealize_signal = 0;
376 G_DEFINE_TYPE (GtkStyle, gtk_style, G_TYPE_OBJECT)
378 /* --- functions --- */
381 gtk_style_init (GtkStyle *style)
385 style->font_desc = pango_font_description_from_string ("Sans 10");
387 style->attach_count = 0;
389 style->black.red = 0;
390 style->black.green = 0;
391 style->black.blue = 0;
393 style->white.red = 65535;
394 style->white.green = 65535;
395 style->white.blue = 65535;
397 style->fg[GTK_STATE_NORMAL] = gtk_default_normal_fg;
398 style->fg[GTK_STATE_ACTIVE] = gtk_default_active_fg;
399 style->fg[GTK_STATE_PRELIGHT] = gtk_default_prelight_fg;
400 style->fg[GTK_STATE_SELECTED] = gtk_default_selected_fg;
401 style->fg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
403 style->bg[GTK_STATE_NORMAL] = gtk_default_normal_bg;
404 style->bg[GTK_STATE_ACTIVE] = gtk_default_active_bg;
405 style->bg[GTK_STATE_PRELIGHT] = gtk_default_prelight_bg;
406 style->bg[GTK_STATE_SELECTED] = gtk_default_selected_bg;
407 style->bg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_bg;
409 for (i = 0; i < 4; i++)
411 style->text[i] = style->fg[i];
412 style->base[i] = style->white;
415 style->base[GTK_STATE_SELECTED] = gtk_default_selected_base;
416 style->text[GTK_STATE_SELECTED] = style->white;
417 style->base[GTK_STATE_ACTIVE] = gtk_default_active_base;
418 style->text[GTK_STATE_ACTIVE] = style->white;
419 style->base[GTK_STATE_INSENSITIVE] = gtk_default_prelight_bg;
420 style->text[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
422 style->rc_style = NULL;
424 style->xthickness = 2;
425 style->ythickness = 2;
427 style->property_cache = NULL;
431 gtk_style_class_init (GtkStyleClass *klass)
433 GObjectClass *object_class = G_OBJECT_CLASS (klass);
435 object_class->finalize = gtk_style_finalize;
436 object_class->set_property = gtk_style_set_property;
437 object_class->get_property = gtk_style_get_property;
438 object_class->constructed = gtk_style_constructed;
440 klass->clone = gtk_style_real_clone;
441 klass->copy = gtk_style_real_copy;
442 klass->init_from_rc = gtk_style_real_init_from_rc;
443 klass->realize = gtk_style_real_realize;
444 klass->unrealize = gtk_style_real_unrealize;
445 klass->set_background = gtk_style_real_set_background;
446 klass->render_icon = gtk_default_render_icon;
448 klass->draw_hline = gtk_default_draw_hline;
449 klass->draw_vline = gtk_default_draw_vline;
450 klass->draw_shadow = gtk_default_draw_shadow;
451 klass->draw_arrow = gtk_default_draw_arrow;
452 klass->draw_diamond = gtk_default_draw_diamond;
453 klass->draw_box = gtk_default_draw_box;
454 klass->draw_flat_box = gtk_default_draw_flat_box;
455 klass->draw_check = gtk_default_draw_check;
456 klass->draw_option = gtk_default_draw_option;
457 klass->draw_tab = gtk_default_draw_tab;
458 klass->draw_shadow_gap = gtk_default_draw_shadow_gap;
459 klass->draw_box_gap = gtk_default_draw_box_gap;
460 klass->draw_extension = gtk_default_draw_extension;
461 klass->draw_focus = gtk_default_draw_focus;
462 klass->draw_slider = gtk_default_draw_slider;
463 klass->draw_handle = gtk_default_draw_handle;
464 klass->draw_expander = gtk_default_draw_expander;
465 klass->draw_layout = gtk_default_draw_layout;
466 klass->draw_resize_grip = gtk_default_draw_resize_grip;
467 klass->draw_spinner = gtk_default_draw_spinner;
469 g_type_class_add_private (object_class, sizeof (GtkStylePrivate));
471 g_object_class_install_property (object_class,
473 g_param_spec_object ("context",
475 P_("GtkStyleContext to get style from"),
476 GTK_TYPE_STYLE_CONTEXT,
477 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
481 * @style: the object which received the signal
483 * Emitted when the style has been initialized for a particular
484 * visual. Connecting to this signal is probably seldom
485 * useful since most of the time applications and widgets only
486 * deal with styles that have been already realized.
490 realize_signal = g_signal_new (I_("realize"),
491 G_TYPE_FROM_CLASS (object_class),
493 G_STRUCT_OFFSET (GtkStyleClass, realize),
495 _gtk_marshal_VOID__VOID,
498 * GtkStyle::unrealize:
499 * @style: the object which received the signal
501 * Emitted when the aspects of the style specific to a particular visual
502 * is being cleaned up. A connection to this signal can be useful
503 * if a widget wants to cache objects as object data on #GtkStyle.
504 * This signal provides a convenient place to free such cached objects.
508 unrealize_signal = g_signal_new (I_("unrealize"),
509 G_TYPE_FROM_CLASS (object_class),
511 G_STRUCT_OFFSET (GtkStyleClass, unrealize),
513 _gtk_marshal_VOID__VOID,
518 gtk_style_finalize (GObject *object)
520 GtkStyle *style = GTK_STYLE (object);
521 GtkStylePrivate *priv = GTK_STYLE_GET_PRIVATE (style);
524 g_return_if_fail (style->attach_count == 0);
526 /* All the styles in the list have the same
527 * style->styles pointer. If we delete the
528 * *first* style from the list, we need to update
529 * the style->styles pointers from all the styles.
530 * Otherwise we simply remove the node from
535 if (style->styles->data != style)
536 style->styles = g_slist_remove (style->styles, style);
539 GSList *tmp_list = style->styles->next;
543 GTK_STYLE (tmp_list->data)->styles = style->styles->next;
544 tmp_list = tmp_list->next;
546 g_slist_free_1 (style->styles);
550 g_slist_foreach (style->icon_factories, (GFunc) g_object_unref, NULL);
551 g_slist_free (style->icon_factories);
553 pango_font_description_free (style->font_desc);
555 if (style->private_font_desc)
556 pango_font_description_free (style->private_font_desc);
559 g_object_unref (style->rc_style);
563 if (priv->context_changed_id)
564 g_signal_handler_disconnect (priv->context, priv->context_changed_id);
566 g_object_unref (priv->context);
569 for (i = 0; i < 5; i++)
571 if (style->background[i])
572 cairo_pattern_destroy (style->background[i]);
575 G_OBJECT_CLASS (gtk_style_parent_class)->finalize (object);
579 gtk_style_set_property (GObject *object,
584 GtkStylePrivate *priv;
586 priv = GTK_STYLE_GET_PRIVATE (object);
591 priv->context = g_value_dup_object (value);
594 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
600 gtk_style_get_property (GObject *object,
605 GtkStylePrivate *priv;
607 priv = GTK_STYLE_GET_PRIVATE (object);
612 g_value_set_object (value, priv->context);
615 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
621 set_color_from_context (GtkStyle *style,
623 GtkStyleContext *context,
627 GdkRGBA *color = NULL;
628 GdkColor *dest = { 0 }; /* Shut up gcc */
633 gtk_style_context_get (context, flags,
634 "background-color", &color,
636 dest = &style->bg[state];
639 gtk_style_context_get (context, flags,
642 dest = &style->fg[state];
645 gtk_style_context_get (context, flags,
648 dest = &style->text[state];
651 gtk_style_context_get (context, flags,
652 "background-color", &color,
654 dest = &style->base[state];
661 if (!(color->alpha > 0.01))
663 gdk_rgba_free (color);
668 dest->red = CLAMP ((guint) (color->red * 65535), 0, 65535);
669 dest->green = CLAMP ((guint) (color->green * 65535), 0, 65535);
670 dest->blue = CLAMP ((guint) (color->blue * 65535), 0, 65535);
671 gdk_rgba_free (color);
677 set_color (GtkStyle *style,
678 GtkStyleContext *context,
686 case GTK_STATE_ACTIVE:
687 flags = GTK_STATE_FLAG_ACTIVE;
689 case GTK_STATE_PRELIGHT:
690 flags = GTK_STATE_FLAG_PRELIGHT;
692 case GTK_STATE_SELECTED:
693 flags = GTK_STATE_FLAG_SELECTED;
695 case GTK_STATE_INSENSITIVE:
696 flags = GTK_STATE_FLAG_INSENSITIVE;
702 /* Try to fill in the values from the associated GtkStyleContext.
703 * Since fully-transparent black is a very common default (e.g. for
704 * background-color properties), and we must store the result in a GdkColor
705 * to retain API compatibility, in case the fetched color is fully transparent
706 * we give themes a fallback style class they can style, before using the
707 * hardcoded default values.
709 if (!set_color_from_context (style, state, context, flags, prop))
711 gtk_style_context_save (context);
712 gtk_style_context_add_class (context, "gtkstyle-fallback");
713 set_color_from_context (style, state, context, flags, prop);
714 gtk_style_context_restore (context);
719 gtk_style_update_from_context (GtkStyle *style)
721 GtkStylePrivate *priv;
726 priv = GTK_STYLE_GET_PRIVATE (style);
728 for (state = GTK_STATE_NORMAL; state <= GTK_STATE_INSENSITIVE; state++)
730 if (gtk_style_context_has_class (priv->context, "entry"))
732 gtk_style_context_save (priv->context);
733 gtk_style_context_remove_class (priv->context, "entry");
734 set_color (style, priv->context, state, GTK_RC_BG);
735 set_color (style, priv->context, state, GTK_RC_FG);
736 gtk_style_context_restore (priv->context);
738 set_color (style, priv->context, state, GTK_RC_BASE);
739 set_color (style, priv->context, state, GTK_RC_TEXT);
743 gtk_style_context_save (priv->context);
744 gtk_style_context_add_class (priv->context, "entry");
745 set_color (style, priv->context, state, GTK_RC_BASE);
746 set_color (style, priv->context, state, GTK_RC_TEXT);
747 gtk_style_context_restore (priv->context);
749 set_color (style, priv->context, state, GTK_RC_BG);
750 set_color (style, priv->context, state, GTK_RC_FG);
754 if (style->font_desc)
755 pango_font_description_free (style->font_desc);
757 gtk_style_context_get (priv->context, 0,
758 "font", &style->font_desc,
760 gtk_style_context_get_padding (priv->context, 0, &padding);
762 style->xthickness = padding.left;
763 style->ythickness = padding.top;
765 for (i = 0; i < 5; i++)
767 _gtk_style_shade (&style->bg[i], &style->light[i], LIGHTNESS_MULT);
768 _gtk_style_shade (&style->bg[i], &style->dark[i], DARKNESS_MULT);
770 style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
771 style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
772 style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
774 style->text_aa[i].red = (style->text[i].red + style->base[i].red) / 2;
775 style->text_aa[i].green = (style->text[i].green + style->base[i].green) / 2;
776 style->text_aa[i].blue = (style->text[i].blue + style->base[i].blue) / 2;
779 style->black.red = 0x0000;
780 style->black.green = 0x0000;
781 style->black.blue = 0x0000;
783 style->white.red = 0xffff;
784 style->white.green = 0xffff;
785 style->white.blue = 0xffff;
787 for (i = 0; i < 5; i++)
789 if (style->background[i])
790 cairo_pattern_destroy (style->background[i]);
792 style->background[i] = cairo_pattern_create_rgb (style->bg[i].red / 65535.0,
793 style->bg[i].green / 65535.0,
794 style->bg[i].blue / 65535.0);
799 style_context_changed (GtkStyleContext *context,
802 gtk_style_update_from_context (GTK_STYLE (user_data));
806 gtk_style_constructed (GObject *object)
808 GtkStylePrivate *priv;
810 priv = GTK_STYLE_GET_PRIVATE (object);
814 gtk_style_update_from_context (GTK_STYLE (object));
816 priv->context_changed_id = g_signal_connect (priv->context, "changed",
817 G_CALLBACK (style_context_changed), object);
823 * @style: a #GtkStyle
825 * Creates a copy of the passed in #GtkStyle object.
827 * Returns: (transfer full): a copy of @style
829 * Deprecated:3.0: Use #GtkStyleContext instead
832 gtk_style_copy (GtkStyle *style)
836 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
838 new_style = GTK_STYLE_GET_CLASS (style)->clone (style);
839 GTK_STYLE_GET_CLASS (style)->copy (new_style, style);
845 _gtk_style_new_for_path (GdkScreen *screen,
848 GtkStyleContext *context;
851 context = gtk_style_context_new ();
854 gtk_style_context_set_screen (context, screen);
856 gtk_style_context_set_path (context, path);
858 style = g_object_new (GTK_TYPE_STYLE,
862 g_object_unref (context);
870 * Creates a new #GtkStyle.
872 * Returns: a new #GtkStyle.
874 * Deprecated: 3.0: Use #GtkStyleContext
882 path = gtk_widget_path_new ();
883 gtk_widget_path_append_type (path, GTK_TYPE_WIDGET);
885 style = _gtk_style_new_for_path (gdk_screen_get_default (), path);
887 gtk_widget_path_free (path);
893 * gtk_style_has_context:
894 * @style: a #GtkStyle
896 * Returns whether @style has an associated #GtkStyleContext.
898 * Returns: %TRUE if @style has a #GtkStyleContext
903 gtk_style_has_context (GtkStyle *style)
905 GtkStylePrivate *priv;
907 priv = GTK_STYLE_GET_PRIVATE (style);
909 return priv->context != NULL;
913 * gtk_style_attach: (skip)
914 * @style: a #GtkStyle.
915 * @window: a #GdkWindow.
917 * Attaches a style to a window; this process allocates the
918 * colors and creates the GC's for the style - it specializes
919 * it to a particular visual. The process may involve the creation
920 * of a new style if the style has already been attached to a
921 * window with a different style and visual.
923 * Since this function may return a new object, you have to use it
924 * in the following way:
925 * <literal>style = gtk_style_attach (style, window)</literal>
927 * Returns: Either @style, or a newly-created #GtkStyle.
928 * If the style is newly created, the style parameter
929 * will be unref'ed, and the new style will have
930 * a reference count belonging to the caller.
932 * Deprecated:3.0: Use gtk_widget_style_attach() instead
935 gtk_style_attach (GtkStyle *style,
938 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
939 g_return_val_if_fail (window != NULL, NULL);
946 * @style: a #GtkStyle
948 * Detaches a style from a window. If the style is not attached
949 * to any windows anymore, it is unrealized. See gtk_style_attach().
951 * Deprecated:3.0: Use #GtkStyleContext instead
954 gtk_style_detach (GtkStyle *style)
956 g_return_if_fail (GTK_IS_STYLE (style));
960 * gtk_style_lookup_icon_set:
961 * @style: a #GtkStyle
962 * @stock_id: an icon name
964 * Looks up @stock_id in the icon factories associated with @style
965 * and the default icon factory, returning an icon set if found,
968 * Return value: (transfer none): icon set of @stock_id
970 * Deprecated:3.0: Use gtk_style_context_lookup_icon_set() instead
973 gtk_style_lookup_icon_set (GtkStyle *style,
974 const char *stock_id)
976 GtkStylePrivate *priv;
978 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
979 g_return_val_if_fail (stock_id != NULL, NULL);
981 priv = GTK_STYLE_GET_PRIVATE (style);
984 return gtk_style_context_lookup_icon_set (priv->context, stock_id);
986 return gtk_icon_factory_lookup_default (stock_id);
990 * gtk_style_lookup_color:
991 * @style: a #GtkStyle
992 * @color_name: the name of the logical color to look up
993 * @color: (out): the #GdkColor to fill in
995 * Looks up @color_name in the style's logical color mappings,
996 * filling in @color and returning %TRUE if found, otherwise
997 * returning %FALSE. Do not cache the found mapping, because
998 * it depends on the #GtkStyle and might change when a theme
1001 * Return value: %TRUE if the mapping was found.
1005 * Deprecated:3.0: Use gtk_style_context_lookup_color() instead
1008 gtk_style_lookup_color (GtkStyle *style,
1009 const char *color_name,
1012 GtkStylePrivate *priv;
1016 g_return_val_if_fail (GTK_IS_STYLE (style), FALSE);
1017 g_return_val_if_fail (color_name != NULL, FALSE);
1018 g_return_val_if_fail (color != NULL, FALSE);
1020 priv = GTK_STYLE_GET_PRIVATE (style);
1025 result = gtk_style_context_lookup_color (priv->context, color_name, &rgba);
1029 color->red = (guint16) (rgba.red * 65535);
1030 color->green = (guint16) (rgba.green * 65535);
1031 color->blue = (guint16) (rgba.blue * 65535);
1039 * gtk_style_set_background:
1040 * @style: a #GtkStyle
1041 * @window: a #GdkWindow
1042 * @state_type: a state
1044 * Sets the background of @window to the background color or pixmap
1045 * specified by @style for the given state.
1047 * Deprecated:3.0: Use gtk_style_context_set_background() instead
1050 gtk_style_set_background (GtkStyle *style,
1052 GtkStateType state_type)
1054 g_return_if_fail (GTK_IS_STYLE (style));
1055 g_return_if_fail (window != NULL);
1057 GTK_STYLE_GET_CLASS (style)->set_background (style, window, state_type);
1060 /* Default functions */
1062 gtk_style_real_clone (GtkStyle *style)
1064 GtkStylePrivate *priv;
1066 priv = GTK_STYLE_GET_PRIVATE (style);
1068 return g_object_new (G_OBJECT_TYPE (style),
1069 "context", priv->context,
1074 gtk_style_real_copy (GtkStyle *style,
1079 for (i = 0; i < 5; i++)
1081 style->fg[i] = src->fg[i];
1082 style->bg[i] = src->bg[i];
1083 style->text[i] = src->text[i];
1084 style->base[i] = src->base[i];
1086 if (style->background[i])
1087 cairo_pattern_destroy (style->background[i]),
1088 style->background[i] = src->background[i];
1089 if (style->background[i])
1090 cairo_pattern_reference (style->background[i]);
1093 if (style->font_desc)
1094 pango_font_description_free (style->font_desc);
1096 style->font_desc = pango_font_description_copy (src->font_desc);
1098 style->font_desc = NULL;
1100 style->xthickness = src->xthickness;
1101 style->ythickness = src->ythickness;
1103 if (style->rc_style)
1104 g_object_unref (style->rc_style);
1105 style->rc_style = src->rc_style;
1107 g_object_ref (src->rc_style);
1109 g_slist_foreach (style->icon_factories, (GFunc) g_object_unref, NULL);
1110 g_slist_free (style->icon_factories);
1111 style->icon_factories = g_slist_copy (src->icon_factories);
1112 g_slist_foreach (style->icon_factories, (GFunc) g_object_ref, NULL);
1116 gtk_style_real_init_from_rc (GtkStyle *style,
1117 GtkRcStyle *rc_style)
1122 * gtk_style_get_style_property:
1123 * @style: a #GtkStyle
1124 * @widget_type: the #GType of a descendant of #GtkWidget
1125 * @property_name: the name of the style property to get
1126 * @value: a #GValue where the value of the property being
1127 * queried will be stored
1129 * Queries the value of a style property corresponding to a
1130 * widget class is in the given style.
1135 gtk_style_get_style_property (GtkStyle *style,
1137 const gchar *property_name,
1140 GtkStylePrivate *priv;
1141 GtkWidgetClass *klass;
1143 const GValue *peek_value;
1145 klass = g_type_class_ref (widget_type);
1146 pspec = gtk_widget_class_find_style_property (klass, property_name);
1147 g_type_class_unref (klass);
1151 g_warning ("%s: widget class `%s' has no property named `%s'",
1153 g_type_name (widget_type),
1158 priv = GTK_STYLE_GET_PRIVATE (style);
1159 peek_value = _gtk_style_context_peek_style_property (priv->context,
1163 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
1164 g_value_copy (peek_value, value);
1165 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
1166 g_value_transform (peek_value, value);
1168 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
1170 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1171 G_VALUE_TYPE_NAME (value));
1175 * gtk_style_get_valist:
1176 * @style: a #GtkStyle
1177 * @widget_type: the #GType of a descendant of #GtkWidget
1178 * @first_property_name: the name of the first style property to get
1179 * @var_args: a <type>va_list</type> of pairs of property names and
1180 * locations to return the property values, starting with the
1181 * location for @first_property_name.
1183 * Non-vararg variant of gtk_style_get().
1184 * Used primarily by language bindings.
1189 gtk_style_get_valist (GtkStyle *style,
1191 const gchar *first_property_name,
1194 GtkStylePrivate *priv;
1195 const char *property_name;
1196 GtkWidgetClass *klass;
1198 g_return_if_fail (GTK_IS_STYLE (style));
1200 klass = g_type_class_ref (widget_type);
1202 priv = GTK_STYLE_GET_PRIVATE (style);
1203 property_name = first_property_name;
1204 while (property_name)
1207 const GValue *peek_value;
1210 pspec = gtk_widget_class_find_style_property (klass, property_name);
1214 g_warning ("%s: widget class `%s' has no property named `%s'",
1216 g_type_name (widget_type),
1221 peek_value = _gtk_style_context_peek_style_property (priv->context, widget_type,
1223 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
1226 g_warning ("%s: %s", G_STRLOC, error);
1231 property_name = va_arg (var_args, gchar*);
1234 g_type_class_unref (klass);
1239 * @style: a #GtkStyle
1240 * @widget_type: the #GType of a descendant of #GtkWidget
1241 * @first_property_name: the name of the first style property to get
1242 * @...: pairs of property names and locations to
1243 * return the property values, starting with the location for
1244 * @first_property_name, terminated by %NULL.
1246 * Gets the values of a multiple style properties for @widget_type
1252 gtk_style_get (GtkStyle *style,
1254 const gchar *first_property_name,
1259 va_start (var_args, first_property_name);
1260 gtk_style_get_valist (style, widget_type, first_property_name, var_args);
1265 gtk_style_real_realize (GtkStyle *style)
1270 gtk_style_real_unrealize (GtkStyle *style)
1275 gtk_style_real_set_background (GtkStyle *style,
1277 GtkStateType state_type)
1279 gdk_window_set_background_pattern (window, style->background[state_type]);
1283 * gtk_style_render_icon:
1284 * @style: a #GtkStyle
1285 * @source: the #GtkIconSource specifying the icon to render
1286 * @direction: a text direction
1288 * @size: (type int): the size to render the icon at. A size of
1289 * (GtkIconSize)-1 means render at the size of the source and
1291 * @widget: (allow-none): the widget
1292 * @detail: (allow-none): a style detail
1294 * Renders the icon specified by @source at the given @size
1295 * according to the given parameters and returns the result in a
1298 * Return value: (transfer full): a newly-created #GdkPixbuf
1299 * containing the rendered icon
1301 * Deprecated:3.0: Use gtk_render_icon_pixbuf() instead
1304 gtk_style_render_icon (GtkStyle *style,
1305 const GtkIconSource *source,
1306 GtkTextDirection direction,
1310 const gchar *detail)
1314 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1315 g_return_val_if_fail (GTK_STYLE_GET_CLASS (style)->render_icon != NULL, NULL);
1317 pixbuf = GTK_STYLE_GET_CLASS (style)->render_icon (style, source, direction, state,
1318 size, widget, detail);
1320 g_return_val_if_fail (pixbuf != NULL, NULL);
1325 /* Default functions */
1328 * gtk_style_apply_default_background:
1338 * Deprecated:3.0: Use #GtkStyleContext instead
1341 gtk_style_apply_default_background (GtkStyle *style,
1344 GtkStateType state_type,
1352 if (style->background[state_type] == NULL)
1354 GdkWindow *parent = gdk_window_get_parent (window);
1355 int x_offset, y_offset;
1359 gdk_window_get_position (window, &x_offset, &y_offset);
1360 cairo_translate (cr, -x_offset, -y_offset);
1361 gtk_style_apply_default_background (style, cr,
1363 x + x_offset, y + y_offset,
1368 gdk_cairo_set_source_color (cr, &style->bg[state_type]);
1371 cairo_set_source (cr, style->background[state_type]);
1373 cairo_rectangle (cr, x, y, width, height);
1381 gtk_default_render_icon (GtkStyle *style,
1382 const GtkIconSource *source,
1383 GtkTextDirection direction,
1387 const gchar *detail)
1389 GtkStyleContext *context;
1390 GtkStylePrivate *priv;
1391 GtkStateFlags flags = 0;
1395 context = gtk_widget_get_style_context (widget);
1398 priv = GTK_STYLE_GET_PRIVATE (style);
1399 context = priv->context;
1405 gtk_style_context_save (context);
1408 transform_detail_string (detail, context);
1412 case GTK_STATE_PRELIGHT:
1413 flags |= GTK_STATE_FLAG_PRELIGHT;
1415 case GTK_STATE_INSENSITIVE:
1416 flags |= GTK_STATE_FLAG_INSENSITIVE;
1422 gtk_style_context_set_state (context, flags);
1424 pixbuf = gtk_render_icon_pixbuf (context, source, size);
1426 gtk_style_context_restore (context);
1432 _cairo_draw_line (cairo_t *cr,
1441 gdk_cairo_set_source_color (cr, color);
1442 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
1444 cairo_move_to (cr, x1 + 0.5, y1 + 0.5);
1445 cairo_line_to (cr, x2 + 0.5, y2 + 0.5);
1452 transform_detail_string (const gchar *detail,
1453 GtkStyleContext *context)
1458 if (strcmp (detail, "arrow") == 0)
1459 gtk_style_context_add_class (context, "arrow");
1460 else if (strcmp (detail, "button") == 0)
1461 gtk_style_context_add_class (context, "button");
1462 else if (strcmp (detail, "buttondefault") == 0)
1464 gtk_style_context_add_class (context, "button");
1465 gtk_style_context_add_class (context, "default");
1467 else if (strcmp (detail, "calendar") == 0)
1468 gtk_style_context_add_class (context, "calendar");
1469 else if (strcmp (detail, "cellcheck") == 0)
1471 gtk_style_context_add_class (context, "cell");
1472 gtk_style_context_add_class (context, "check");
1474 else if (strcmp (detail, "cellradio") == 0)
1476 gtk_style_context_add_class (context, "cell");
1477 gtk_style_context_add_class (context, "radio");
1479 else if (strcmp (detail, "checkbutton") == 0)
1480 gtk_style_context_add_class (context, "check");
1481 else if (strcmp (detail, "check") == 0)
1483 gtk_style_context_add_class (context, "check");
1484 gtk_style_context_add_class (context, "menu");
1486 else if (strcmp (detail, "radiobutton") == 0)
1488 gtk_style_context_add_class (context, "radio");
1490 else if (strcmp (detail, "option") == 0)
1492 gtk_style_context_add_class (context, "radio");
1493 gtk_style_context_add_class (context, "menu");
1495 else if (strcmp (detail, "entry") == 0 ||
1496 strcmp (detail, "entry_bg") == 0)
1497 gtk_style_context_add_class (context, "entry");
1498 else if (strcmp (detail, "expander") == 0)
1499 gtk_style_context_add_class (context, "expander");
1500 else if (strcmp (detail, "tooltip") == 0)
1501 gtk_style_context_add_class (context, "tooltip");
1502 else if (strcmp (detail, "frame") == 0)
1503 gtk_style_context_add_class (context, "frame");
1504 else if (strcmp (detail, "scrolled_window") == 0)
1505 gtk_style_context_add_class (context, "scrolled-window");
1506 else if (strcmp (detail, "viewport") == 0 ||
1507 strcmp (detail, "viewportbin") == 0)
1508 gtk_style_context_add_class (context, "viewport");
1509 else if (strncmp (detail, "trough", 6) == 0)
1510 gtk_style_context_add_class (context, "trough");
1511 else if (strcmp (detail, "spinbutton") == 0)
1512 gtk_style_context_add_class (context, "spinbutton");
1513 else if (strcmp (detail, "spinbutton_up") == 0)
1515 gtk_style_context_add_class (context, "spinbutton");
1516 gtk_style_context_add_class (context, "button");
1517 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
1519 else if (strcmp (detail, "spinbutton_down") == 0)
1521 gtk_style_context_add_class (context, "spinbutton");
1522 gtk_style_context_add_class (context, "button");
1523 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
1525 else if ((detail[0] == 'h' || detail[0] == 'v') &&
1526 strncmp (&detail[1], "scrollbar_", 10) == 0)
1528 gtk_style_context_add_class (context, "button");
1529 gtk_style_context_add_class (context, "scrollbar");
1531 else if (strcmp (detail, "slider") == 0)
1533 gtk_style_context_add_class (context, "slider");
1534 gtk_style_context_add_class (context, "scrollbar");
1536 else if (strcmp (detail, "vscale") == 0 ||
1537 strcmp (detail, "hscale") == 0)
1539 gtk_style_context_add_class (context, "slider");
1540 gtk_style_context_add_class (context, "scale");
1542 else if (strcmp (detail, "menuitem") == 0)
1544 gtk_style_context_add_class (context, "menuitem");
1545 gtk_style_context_add_class (context, "menu");
1547 else if (strcmp (detail, "menu") == 0)
1549 gtk_style_context_add_class (context, "popup");
1550 gtk_style_context_add_class (context, "menu");
1552 else if (strcmp (detail, "accellabel") == 0)
1553 gtk_style_context_add_class (context, "accelerator");
1554 else if (strcmp (detail, "menubar") == 0)
1555 gtk_style_context_add_class (context, "menubar");
1556 else if (strcmp (detail, "base") == 0)
1557 gtk_style_context_add_class (context, "background");
1558 else if (strcmp (detail, "bar") == 0 ||
1559 strcmp (detail, "progressbar") == 0)
1560 gtk_style_context_add_class (context, "progressbar");
1561 else if (strcmp (detail, "toolbar") == 0)
1562 gtk_style_context_add_class (context, "toolbar");
1563 else if (strcmp (detail, "handlebox_bin") == 0)
1564 gtk_style_context_add_class (context, "dock");
1565 else if (strcmp (detail, "notebook") == 0)
1566 gtk_style_context_add_class (context, "notebook");
1567 else if (strcmp (detail, "tab") == 0)
1569 gtk_style_context_add_class (context, "notebook");
1570 gtk_style_context_add_region (context, GTK_STYLE_REGION_TAB, 0);
1572 else if (g_str_has_prefix (detail, "cell"))
1574 GtkRegionFlags row, col;
1575 gboolean ruled = FALSE;
1579 tokens = g_strsplit (detail, "_", -1);
1585 if (strcmp (tokens[i], "even") == 0)
1586 row |= GTK_REGION_EVEN;
1587 else if (strcmp (tokens[i], "odd") == 0)
1588 row |= GTK_REGION_ODD;
1589 else if (strcmp (tokens[i], "start") == 0)
1590 col |= GTK_REGION_FIRST;
1591 else if (strcmp (tokens[i], "end") == 0)
1592 col |= GTK_REGION_LAST;
1593 else if (strcmp (tokens[i], "ruled") == 0)
1595 else if (strcmp (tokens[i], "sorted") == 0)
1596 col |= GTK_REGION_SORTED;
1602 row &= ~(GTK_REGION_EVEN | GTK_REGION_ODD);
1604 gtk_style_context_add_class (context, "cell");
1605 gtk_style_context_add_region (context, "row", row);
1606 gtk_style_context_add_region (context, "column", col);
1608 g_strfreev (tokens);
1613 gtk_default_draw_hline (GtkStyle *style,
1615 GtkStateType state_type,
1617 const gchar *detail,
1622 GtkStyleContext *context;
1623 GtkStylePrivate *priv;
1626 context = gtk_widget_get_style_context (widget);
1629 priv = GTK_STYLE_GET_PRIVATE (style);
1630 context = priv->context;
1633 gtk_style_context_save (context);
1636 transform_detail_string (detail, context);
1640 gtk_render_line (context, cr,
1645 gtk_style_context_restore (context);
1650 gtk_default_draw_vline (GtkStyle *style,
1652 GtkStateType state_type,
1654 const gchar *detail,
1659 GtkStyleContext *context;
1660 GtkStylePrivate *priv;
1663 context = gtk_widget_get_style_context (widget);
1666 priv = GTK_STYLE_GET_PRIVATE (style);
1667 context = priv->context;
1670 gtk_style_context_save (context);
1673 transform_detail_string (detail, context);
1677 gtk_render_line (context, cr,
1681 gtk_style_context_restore (context);
1685 gtk_default_draw_shadow (GtkStyle *style,
1687 GtkStateType state_type,
1688 GtkShadowType shadow_type,
1690 const gchar *detail,
1696 GtkStyleContext *context;
1697 GtkStylePrivate *priv;
1699 if (shadow_type == GTK_SHADOW_NONE)
1703 context = gtk_widget_get_style_context (widget);
1706 priv = GTK_STYLE_GET_PRIVATE (style);
1707 context = priv->context;
1710 gtk_style_context_save (context);
1713 transform_detail_string (detail, context);
1717 gtk_render_frame (context, cr,
1724 gtk_style_context_restore (context);
1728 draw_arrow (cairo_t *cr,
1730 GtkArrowType arrow_type,
1736 gdk_cairo_set_source_color (cr, color);
1739 if (arrow_type == GTK_ARROW_DOWN)
1741 cairo_move_to (cr, x, y);
1742 cairo_line_to (cr, x + width, y);
1743 cairo_line_to (cr, x + width / 2., y + height);
1745 else if (arrow_type == GTK_ARROW_UP)
1747 cairo_move_to (cr, x, y + height);
1748 cairo_line_to (cr, x + width / 2., y);
1749 cairo_line_to (cr, x + width, y + height);
1751 else if (arrow_type == GTK_ARROW_LEFT)
1753 cairo_move_to (cr, x + width, y);
1754 cairo_line_to (cr, x + width, y + height);
1755 cairo_line_to (cr, x, y + height / 2.);
1757 else if (arrow_type == GTK_ARROW_RIGHT)
1759 cairo_move_to (cr, x, y);
1760 cairo_line_to (cr, x + width, y + height / 2.);
1761 cairo_line_to (cr, x, y + height);
1764 cairo_close_path (cr);
1771 gtk_default_draw_arrow (GtkStyle *style,
1774 GtkShadowType shadow,
1776 const gchar *detail,
1777 GtkArrowType arrow_type,
1784 GtkStyleContext *context;
1785 GtkStylePrivate *priv;
1786 GtkStateFlags flags = 0;
1787 gdouble angle, size;
1789 if (arrow_type == GTK_ARROW_NONE)
1793 context = gtk_widget_get_style_context (widget);
1796 priv = GTK_STYLE_GET_PRIVATE (style);
1797 context = priv->context;
1800 gtk_style_context_save (context);
1803 transform_detail_string (detail, context);
1811 case GTK_ARROW_RIGHT:
1815 case GTK_ARROW_DOWN:
1819 case GTK_ARROW_LEFT:
1820 angle = 3 * (G_PI / 2);
1824 g_assert_not_reached ();
1829 case GTK_STATE_PRELIGHT:
1830 flags |= GTK_STATE_FLAG_PRELIGHT;
1832 case GTK_STATE_SELECTED:
1833 flags |= GTK_STATE_FLAG_SELECTED;
1835 case GTK_STATE_INSENSITIVE:
1836 flags |= GTK_STATE_FLAG_INSENSITIVE;
1838 case GTK_STATE_ACTIVE:
1839 flags |= GTK_STATE_FLAG_ACTIVE;
1845 gtk_style_context_set_state (context, flags);
1849 gtk_render_arrow (context,
1856 gtk_style_context_restore (context);
1860 gtk_default_draw_diamond (GtkStyle *style,
1862 GtkStateType state_type,
1863 GtkShadowType shadow_type,
1865 const gchar *detail,
1873 GdkColor *outer_nw = NULL;
1874 GdkColor *outer_ne = NULL;
1875 GdkColor *outer_sw = NULL;
1876 GdkColor *outer_se = NULL;
1877 GdkColor *middle_nw = NULL;
1878 GdkColor *middle_ne = NULL;
1879 GdkColor *middle_sw = NULL;
1880 GdkColor *middle_se = NULL;
1881 GdkColor *inner_nw = NULL;
1882 GdkColor *inner_ne = NULL;
1883 GdkColor *inner_sw = NULL;
1884 GdkColor *inner_se = NULL;
1886 half_width = width / 2;
1887 half_height = height / 2;
1889 switch (shadow_type)
1892 inner_sw = inner_se = &style->bg[state_type];
1893 middle_sw = middle_se = &style->light[state_type];
1894 outer_sw = outer_se = &style->light[state_type];
1895 inner_nw = inner_ne = &style->black;
1896 middle_nw = middle_ne = &style->dark[state_type];
1897 outer_nw = outer_ne = &style->dark[state_type];
1900 case GTK_SHADOW_OUT:
1901 inner_sw = inner_se = &style->dark[state_type];
1902 middle_sw = middle_se = &style->dark[state_type];
1903 outer_sw = outer_se = &style->black;
1904 inner_nw = inner_ne = &style->bg[state_type];
1905 middle_nw = middle_ne = &style->light[state_type];
1906 outer_nw = outer_ne = &style->light[state_type];
1909 case GTK_SHADOW_ETCHED_IN:
1910 inner_sw = inner_se = &style->bg[state_type];
1911 middle_sw = middle_se = &style->dark[state_type];
1912 outer_sw = outer_se = &style->light[state_type];
1913 inner_nw = inner_ne = &style->bg[state_type];
1914 middle_nw = middle_ne = &style->light[state_type];
1915 outer_nw = outer_ne = &style->dark[state_type];
1918 case GTK_SHADOW_ETCHED_OUT:
1919 inner_sw = inner_se = &style->bg[state_type];
1920 middle_sw = middle_se = &style->light[state_type];
1921 outer_sw = outer_se = &style->dark[state_type];
1922 inner_nw = inner_ne = &style->bg[state_type];
1923 middle_nw = middle_ne = &style->dark[state_type];
1924 outer_nw = outer_ne = &style->light[state_type];
1934 _cairo_draw_line (cr, inner_sw,
1935 x + 2, y + half_height,
1936 x + half_width, y + height - 2);
1937 _cairo_draw_line (cr, inner_se,
1938 x + half_width, y + height - 2,
1939 x + width - 2, y + half_height);
1940 _cairo_draw_line (cr, middle_sw,
1941 x + 1, y + half_height,
1942 x + half_width, y + height - 1);
1943 _cairo_draw_line (cr, middle_se,
1944 x + half_width, y + height - 1,
1945 x + width - 1, y + half_height);
1946 _cairo_draw_line (cr, outer_sw,
1948 x + half_width, y + height);
1949 _cairo_draw_line (cr, outer_se,
1950 x + half_width, y + height,
1951 x + width, y + half_height);
1953 _cairo_draw_line (cr, inner_nw,
1954 x + 2, y + half_height,
1955 x + half_width, y + 2);
1956 _cairo_draw_line (cr, inner_ne,
1957 x + half_width, y + 2,
1958 x + width - 2, y + half_height);
1959 _cairo_draw_line (cr, middle_nw,
1960 x + 1, y + half_height,
1961 x + half_width, y + 1);
1962 _cairo_draw_line (cr, middle_ne,
1963 x + half_width, y + 1,
1964 x + width - 1, y + half_height);
1965 _cairo_draw_line (cr, outer_nw,
1968 _cairo_draw_line (cr, outer_ne,
1970 x + width, y + half_height);
1975 option_menu_get_props (GtkWidget *widget,
1976 GtkRequisition *indicator_size,
1977 GtkBorder *indicator_spacing)
1979 GtkRequisition *tmp_size = NULL;
1980 GtkBorder *tmp_spacing = NULL;
1984 *indicator_size = *tmp_size;
1985 gtk_requisition_free (tmp_size);
1988 *indicator_size = default_option_indicator_size;
1992 *indicator_spacing = *tmp_spacing;
1993 gtk_border_free (tmp_spacing);
1996 *indicator_spacing = default_option_indicator_spacing;
2000 gtk_default_draw_box (GtkStyle *style,
2002 GtkStateType state_type,
2003 GtkShadowType shadow_type,
2005 const gchar *detail,
2011 GtkStyleContext *context;
2012 GtkStylePrivate *priv;
2013 GtkStateFlags flags = 0;
2016 context = gtk_widget_get_style_context (widget);
2019 priv = GTK_STYLE_GET_PRIVATE (style);
2020 context = priv->context;
2023 gtk_style_context_save (context);
2026 transform_detail_string (detail, context);
2030 case GTK_STATE_ACTIVE:
2031 flags |= GTK_STATE_FLAG_ACTIVE;
2033 case GTK_STATE_PRELIGHT:
2034 flags |= GTK_STATE_FLAG_PRELIGHT;
2036 case GTK_STATE_SELECTED:
2037 flags |= GTK_STATE_FLAG_SELECTED;
2039 case GTK_STATE_INSENSITIVE:
2040 flags |= GTK_STATE_FLAG_INSENSITIVE;
2046 if (shadow_type == GTK_SHADOW_IN)
2047 flags |= GTK_STATE_FLAG_ACTIVE;
2049 gtk_style_context_set_state (context, flags);
2053 if (gtk_style_context_has_class (context, GTK_STYLE_CLASS_PROGRESSBAR))
2054 gtk_render_activity (context, cr, x, y, width, height);
2057 gtk_render_background (context, cr, x, y, width, height);
2059 if (shadow_type != GTK_SHADOW_NONE)
2060 gtk_render_frame (context, cr, x, y, width, height);
2064 gtk_style_context_restore (context);
2068 gtk_default_draw_flat_box (GtkStyle *style,
2070 GtkStateType state_type,
2071 GtkShadowType shadow_type,
2073 const gchar *detail,
2079 GtkStyleContext *context;
2080 GtkStylePrivate *priv;
2081 GtkStateFlags flags = 0;
2084 context = gtk_widget_get_style_context (widget);
2087 priv = GTK_STYLE_GET_PRIVATE (style);
2088 context = priv->context;
2091 gtk_style_context_save (context);
2094 transform_detail_string (detail, context);
2098 case GTK_STATE_PRELIGHT:
2099 flags |= GTK_STATE_FLAG_PRELIGHT;
2101 case GTK_STATE_SELECTED:
2102 flags |= GTK_STATE_FLAG_SELECTED;
2104 case GTK_STATE_INSENSITIVE:
2105 flags |= GTK_STATE_FLAG_INSENSITIVE;
2107 case GTK_STATE_ACTIVE:
2108 flags |= GTK_STATE_FLAG_ACTIVE;
2110 case GTK_STATE_FOCUSED:
2111 flags |= GTK_STATE_FLAG_FOCUSED;
2117 gtk_style_context_set_state (context, flags);
2121 gtk_render_background (context, cr,
2128 gtk_style_context_restore (context);
2132 gtk_default_draw_check (GtkStyle *style,
2134 GtkStateType state_type,
2135 GtkShadowType shadow_type,
2137 const gchar *detail,
2143 GtkStyleContext *context;
2144 GtkStylePrivate *priv;
2145 GtkStateFlags flags = 0;
2148 context = gtk_widget_get_style_context (widget);
2151 priv = GTK_STYLE_GET_PRIVATE (style);
2152 context = priv->context;
2155 gtk_style_context_save (context);
2158 transform_detail_string (detail, context);
2162 case GTK_STATE_PRELIGHT:
2163 flags |= GTK_STATE_FLAG_PRELIGHT;
2165 case GTK_STATE_SELECTED:
2166 flags |= GTK_STATE_FLAG_SELECTED;
2168 case GTK_STATE_INSENSITIVE:
2169 flags |= GTK_STATE_FLAG_INSENSITIVE;
2175 if (shadow_type == GTK_SHADOW_IN)
2176 flags |= GTK_STATE_FLAG_ACTIVE;
2177 else if (shadow_type == GTK_SHADOW_ETCHED_IN)
2178 flags |= GTK_STATE_FLAG_INCONSISTENT;
2180 gtk_style_context_set_state (context, flags);
2184 gtk_render_check (context,
2189 gtk_style_context_restore (context);
2193 gtk_default_draw_option (GtkStyle *style,
2195 GtkStateType state_type,
2196 GtkShadowType shadow_type,
2198 const gchar *detail,
2204 GtkStyleContext *context;
2205 GtkStylePrivate *priv;
2206 GtkStateFlags flags = 0;
2209 context = gtk_widget_get_style_context (widget);
2212 priv = GTK_STYLE_GET_PRIVATE (style);
2213 context = priv->context;
2216 gtk_style_context_save (context);
2219 transform_detail_string (detail, context);
2223 case GTK_STATE_PRELIGHT:
2224 flags |= GTK_STATE_FLAG_PRELIGHT;
2226 case GTK_STATE_SELECTED:
2227 flags |= GTK_STATE_FLAG_SELECTED;
2229 case GTK_STATE_INSENSITIVE:
2230 flags |= GTK_STATE_FLAG_INSENSITIVE;
2236 if (shadow_type == GTK_SHADOW_IN)
2237 flags |= GTK_STATE_FLAG_ACTIVE;
2238 else if (shadow_type == GTK_SHADOW_ETCHED_IN)
2239 flags |= GTK_STATE_FLAG_INCONSISTENT;
2241 gtk_style_context_set_state (context, flags);
2244 gtk_render_option (context, cr,
2251 gtk_style_context_restore (context);
2255 gtk_default_draw_tab (GtkStyle *style,
2257 GtkStateType state_type,
2258 GtkShadowType shadow_type,
2260 const gchar *detail,
2266 #define ARROW_SPACE 4
2268 GtkRequisition indicator_size;
2269 GtkBorder indicator_spacing;
2272 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
2274 indicator_size.width += (indicator_size.width % 2) - 1;
2275 arrow_height = indicator_size.width / 2 + 1;
2277 x += (width - indicator_size.width) / 2;
2278 y += (height - (2 * arrow_height + ARROW_SPACE)) / 2;
2280 if (state_type == GTK_STATE_INSENSITIVE)
2282 draw_arrow (cr, &style->white,
2283 GTK_ARROW_UP, x + 1, y + 1,
2284 indicator_size.width, arrow_height);
2286 draw_arrow (cr, &style->white,
2287 GTK_ARROW_DOWN, x + 1, y + arrow_height + ARROW_SPACE + 1,
2288 indicator_size.width, arrow_height);
2291 draw_arrow (cr, &style->fg[state_type],
2293 indicator_size.width, arrow_height);
2296 draw_arrow (cr, &style->fg[state_type],
2297 GTK_ARROW_DOWN, x, y + arrow_height + ARROW_SPACE,
2298 indicator_size.width, arrow_height);
2302 gtk_default_draw_shadow_gap (GtkStyle *style,
2304 GtkStateType state_type,
2305 GtkShadowType shadow_type,
2307 const gchar *detail,
2312 GtkPositionType gap_side,
2316 GtkStyleContext *context;
2317 GtkStylePrivate *priv;
2318 GtkStateFlags flags = 0;
2320 if (shadow_type == GTK_SHADOW_NONE)
2324 context = gtk_widget_get_style_context (widget);
2327 priv = GTK_STYLE_GET_PRIVATE (style);
2328 context = priv->context;
2331 gtk_style_context_save (context);
2334 transform_detail_string (detail, context);
2338 case GTK_STATE_ACTIVE:
2339 flags |= GTK_STATE_FLAG_ACTIVE;
2341 case GTK_STATE_PRELIGHT:
2342 flags |= GTK_STATE_FLAG_PRELIGHT;
2344 case GTK_STATE_SELECTED:
2345 flags |= GTK_STATE_FLAG_SELECTED;
2347 case GTK_STATE_INSENSITIVE:
2348 flags |= GTK_STATE_FLAG_INSENSITIVE;
2354 gtk_style_context_set_state (context, flags);
2357 gtk_render_frame_gap (context, cr,
2364 (gdouble) gap_x + gap_width);
2367 gtk_style_context_restore (context);
2371 gtk_default_draw_box_gap (GtkStyle *style,
2373 GtkStateType state_type,
2374 GtkShadowType shadow_type,
2376 const gchar *detail,
2381 GtkPositionType gap_side,
2385 GtkStyleContext *context;
2386 GtkStylePrivate *priv;
2387 GtkStateFlags flags = 0;
2390 context = gtk_widget_get_style_context (widget);
2393 priv = GTK_STYLE_GET_PRIVATE (style);
2394 context = priv->context;
2397 gtk_style_context_save (context);
2400 transform_detail_string (detail, context);
2404 case GTK_STATE_ACTIVE:
2405 flags |= GTK_STATE_FLAG_ACTIVE;
2407 case GTK_STATE_PRELIGHT:
2408 flags |= GTK_STATE_FLAG_PRELIGHT;
2410 case GTK_STATE_SELECTED:
2411 flags |= GTK_STATE_FLAG_SELECTED;
2413 case GTK_STATE_INSENSITIVE:
2414 flags |= GTK_STATE_FLAG_INSENSITIVE;
2420 gtk_style_context_set_state (context, flags);
2423 gtk_render_background (context, cr,
2430 if (shadow_type != GTK_SHADOW_NONE)
2431 gtk_render_frame_gap (context, cr,
2438 (gdouble) gap_x + gap_width);
2441 gtk_style_context_restore (context);
2445 gtk_default_draw_extension (GtkStyle *style,
2447 GtkStateType state_type,
2448 GtkShadowType shadow_type,
2450 const gchar *detail,
2455 GtkPositionType gap_side)
2457 GtkStyleContext *context;
2458 GtkStylePrivate *priv;
2459 GtkStateFlags flags = 0;
2462 context = gtk_widget_get_style_context (widget);
2465 priv = GTK_STYLE_GET_PRIVATE (style);
2466 context = priv->context;
2469 gtk_style_context_save (context);
2472 transform_detail_string (detail, context);
2476 case GTK_STATE_ACTIVE:
2477 flags |= GTK_STATE_FLAG_ACTIVE;
2479 case GTK_STATE_PRELIGHT:
2480 flags |= GTK_STATE_FLAG_PRELIGHT;
2482 case GTK_STATE_SELECTED:
2483 flags |= GTK_STATE_FLAG_SELECTED;
2485 case GTK_STATE_INSENSITIVE:
2486 flags |= GTK_STATE_FLAG_INSENSITIVE;
2492 gtk_style_context_set_state (context, flags);
2496 gtk_render_extension (context, cr,
2504 gtk_style_context_restore (context);
2508 gtk_default_draw_focus (GtkStyle *style,
2510 GtkStateType state_type,
2512 const gchar *detail,
2518 GtkStyleContext *context;
2519 GtkStylePrivate *priv;
2522 context = gtk_widget_get_style_context (widget);
2525 priv = GTK_STYLE_GET_PRIVATE (style);
2526 context = priv->context;
2529 gtk_style_context_save (context);
2532 transform_detail_string (detail, context);
2536 gtk_render_focus (context, cr,
2543 gtk_style_context_restore (context);
2547 gtk_default_draw_slider (GtkStyle *style,
2549 GtkStateType state_type,
2550 GtkShadowType shadow_type,
2552 const gchar *detail,
2557 GtkOrientation orientation)
2559 GtkStyleContext *context;
2560 GtkStylePrivate *priv;
2561 GtkStateFlags flags = 0;
2564 context = gtk_widget_get_style_context (widget);
2567 priv = GTK_STYLE_GET_PRIVATE (style);
2568 context = priv->context;
2571 gtk_style_context_save (context);
2574 transform_detail_string (detail, context);
2578 case GTK_STATE_PRELIGHT:
2579 flags |= GTK_STATE_FLAG_PRELIGHT;
2581 case GTK_STATE_SELECTED:
2582 flags |= GTK_STATE_FLAG_SELECTED;
2584 case GTK_STATE_INSENSITIVE:
2585 flags |= GTK_STATE_FLAG_INSENSITIVE;
2591 gtk_style_context_set_state (context, flags);
2595 gtk_render_slider (context, cr, x, y, width, height, orientation);
2598 gtk_style_context_restore (context);
2602 gtk_default_draw_handle (GtkStyle *style,
2604 GtkStateType state_type,
2605 GtkShadowType shadow_type,
2607 const gchar *detail,
2612 GtkOrientation orientation)
2614 GtkStyleContext *context;
2615 GtkStylePrivate *priv;
2616 GtkStateFlags flags = 0;
2619 context = gtk_widget_get_style_context (widget);
2622 priv = GTK_STYLE_GET_PRIVATE (style);
2623 context = priv->context;
2626 gtk_style_context_save (context);
2629 transform_detail_string (detail, context);
2633 case GTK_STATE_PRELIGHT:
2634 flags |= GTK_STATE_FLAG_PRELIGHT;
2636 case GTK_STATE_SELECTED:
2637 flags |= GTK_STATE_FLAG_SELECTED;
2639 case GTK_STATE_INSENSITIVE:
2640 flags |= GTK_STATE_FLAG_INSENSITIVE;
2646 gtk_style_context_set_state (context, flags);
2650 gtk_render_handle (context, cr,
2657 gtk_style_context_restore (context);
2661 gtk_default_draw_expander (GtkStyle *style,
2663 GtkStateType state_type,
2665 const gchar *detail,
2668 GtkExpanderStyle expander_style)
2670 GtkStyleContext *context;
2671 GtkStylePrivate *priv;
2672 GtkStateFlags flags = 0;
2676 context = gtk_widget_get_style_context (widget);
2679 priv = GTK_STYLE_GET_PRIVATE (style);
2680 context = priv->context;
2683 gtk_style_context_save (context);
2686 transform_detail_string (detail, context);
2688 gtk_style_context_add_class (context, "expander");
2692 case GTK_STATE_PRELIGHT:
2693 flags |= GTK_STATE_FLAG_PRELIGHT;
2695 case GTK_STATE_SELECTED:
2696 flags |= GTK_STATE_FLAG_SELECTED;
2698 case GTK_STATE_INSENSITIVE:
2699 flags |= GTK_STATE_FLAG_INSENSITIVE;
2706 gtk_widget_class_find_style_property (GTK_WIDGET_GET_CLASS (widget),
2708 gtk_widget_style_get (widget, "expander-size", &size, NULL);
2712 if (expander_style == GTK_EXPANDER_EXPANDED)
2713 flags |= GTK_STATE_FLAG_ACTIVE;
2715 gtk_style_context_set_state (context, flags);
2719 gtk_render_expander (context, cr,
2720 (gdouble) x - (size / 2),
2721 (gdouble) y - (size / 2),
2726 gtk_style_context_restore (context);
2730 gtk_default_draw_layout (GtkStyle *style,
2732 GtkStateType state_type,
2735 const gchar *detail,
2738 PangoLayout *layout)
2740 GtkStyleContext *context;
2741 GtkStylePrivate *priv;
2742 GtkStateFlags flags = 0;
2745 context = gtk_widget_get_style_context (widget);
2748 priv = GTK_STYLE_GET_PRIVATE (style);
2749 context = priv->context;
2752 gtk_style_context_save (context);
2755 transform_detail_string (detail, context);
2759 case GTK_STATE_PRELIGHT:
2760 flags |= GTK_STATE_FLAG_PRELIGHT;
2762 case GTK_STATE_SELECTED:
2763 flags |= GTK_STATE_FLAG_SELECTED;
2765 case GTK_STATE_INSENSITIVE:
2766 flags |= GTK_STATE_FLAG_INSENSITIVE;
2772 gtk_style_context_set_state (context, flags);
2776 gtk_render_layout (context, cr,
2782 gtk_style_context_restore (context);
2786 gtk_default_draw_resize_grip (GtkStyle *style,
2788 GtkStateType state_type,
2790 const gchar *detail,
2797 GtkStyleContext *context;
2798 GtkStylePrivate *priv;
2799 GtkStateFlags flags = 0;
2800 GtkJunctionSides sides = 0;
2803 context = gtk_widget_get_style_context (widget);
2806 priv = GTK_STYLE_GET_PRIVATE (style);
2807 context = priv->context;
2810 gtk_style_context_save (context);
2813 transform_detail_string (detail, context);
2815 gtk_style_context_add_class (context, "grip");
2819 case GTK_STATE_PRELIGHT:
2820 flags |= GTK_STATE_FLAG_PRELIGHT;
2822 case GTK_STATE_SELECTED:
2823 flags |= GTK_STATE_FLAG_SELECTED;
2825 case GTK_STATE_INSENSITIVE:
2826 flags |= GTK_STATE_FLAG_INSENSITIVE;
2832 gtk_style_context_set_state (context, flags);
2836 case GDK_WINDOW_EDGE_NORTH_WEST:
2837 sides = GTK_JUNCTION_CORNER_TOPLEFT;
2839 case GDK_WINDOW_EDGE_NORTH:
2840 sides = GTK_JUNCTION_TOP;
2842 case GDK_WINDOW_EDGE_NORTH_EAST:
2843 sides = GTK_JUNCTION_CORNER_TOPRIGHT;
2845 case GDK_WINDOW_EDGE_WEST:
2846 sides = GTK_JUNCTION_LEFT;
2848 case GDK_WINDOW_EDGE_EAST:
2849 sides = GTK_JUNCTION_RIGHT;
2851 case GDK_WINDOW_EDGE_SOUTH_WEST:
2852 sides = GTK_JUNCTION_CORNER_BOTTOMLEFT;
2854 case GDK_WINDOW_EDGE_SOUTH:
2855 sides = GTK_JUNCTION_BOTTOM;
2857 case GDK_WINDOW_EDGE_SOUTH_EAST:
2858 sides = GTK_JUNCTION_CORNER_BOTTOMRIGHT;
2862 gtk_style_context_set_junction_sides (context, sides);
2866 gtk_render_handle (context, cr,
2873 gtk_style_context_restore (context);
2877 gtk_default_draw_spinner (GtkStyle *style,
2879 GtkStateType state_type,
2881 const gchar *detail,
2897 real_step = step % num_steps;
2899 /* set a clip region for the expose event */
2900 cairo_rectangle (cr, x, y, width, height);
2903 cairo_translate (cr, x, y);
2905 /* draw clip region */
2906 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
2908 color = &style->fg[state_type];
2911 radius = MIN (width / 2, height / 2);
2912 half = num_steps / 2;
2914 for (i = 0; i < num_steps; i++)
2916 gint inset = 0.7 * radius;
2918 /* transparency is a function of time and intial value */
2919 gdouble t = (gdouble) ((i + num_steps - real_step)
2920 % num_steps) / num_steps;
2924 cairo_set_source_rgba (cr,
2925 color->red / 65535.,
2926 color->green / 65535.,
2927 color->blue / 65535.,
2930 cairo_set_line_width (cr, 2.0);
2932 dx + (radius - inset) * cos (i * G_PI / half),
2933 dy + (radius - inset) * sin (i * G_PI / half));
2935 dx + radius * cos (i * G_PI / half),
2936 dy + radius * sin (i * G_PI / half));
2944 _gtk_style_shade (const GdkColor *a,
2952 red = (gdouble) a->red / 65535.0;
2953 green = (gdouble) a->green / 65535.0;
2954 blue = (gdouble) a->blue / 65535.0;
2956 rgb_to_hls (&red, &green, &blue);
2961 else if (green < 0.0)
2967 else if (blue < 0.0)
2970 hls_to_rgb (&red, &green, &blue);
2972 b->red = red * 65535.0;
2973 b->green = green * 65535.0;
2974 b->blue = blue * 65535.0;
2978 rgb_to_hls (gdouble *r,
3019 l = (max + min) / 2;
3026 s = (max - min) / (max + min);
3028 s = (max - min) / (2 - max - min);
3032 h = (green - blue) / delta;
3033 else if (green == max)
3034 h = 2 + (blue - red) / delta;
3035 else if (blue == max)
3036 h = 4 + (red - green) / delta;
3049 hls_to_rgb (gdouble *h,
3062 if (lightness <= 0.5)
3063 m2 = lightness * (1 + saturation);
3065 m2 = lightness + saturation - lightness * saturation;
3066 m1 = 2 * lightness - m2;
3068 if (saturation == 0)
3083 r = m1 + (m2 - m1) * hue / 60;
3087 r = m1 + (m2 - m1) * (240 - hue) / 60;
3098 g = m1 + (m2 - m1) * hue / 60;
3102 g = m1 + (m2 - m1) * (240 - hue) / 60;
3113 b = m1 + (m2 - m1) * hue / 60;
3117 b = m1 + (m2 - m1) * (240 - hue) / 60;
3130 * @style: a #GtkStyle
3132 * @state_type: a state
3133 * @widget: (allow-none): the widget
3134 * @detail: (allow-none): a style detail
3135 * @x1: the starting x coordinate
3136 * @x2: the ending x coordinate
3137 * @y: the y coordinate
3139 * Draws a horizontal line from (@x1, @y) to (@x2, @y) in @cr
3140 * using the given style and state.
3142 * Deprecated:3.0: Use gtk_render_line() instead
3145 gtk_paint_hline (GtkStyle *style,
3147 GtkStateType state_type,
3149 const gchar *detail,
3154 g_return_if_fail (GTK_IS_STYLE (style));
3155 g_return_if_fail (cr != NULL);
3156 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
3160 GTK_STYLE_GET_CLASS (style)->draw_hline (style, cr, state_type,
3169 * @style: a #GtkStyle
3171 * @state_type: a state
3172 * @widget: (allow-none): the widget
3173 * @detail: (allow-none): a style detail
3174 * @y1_: the starting y coordinate
3175 * @y2_: the ending y coordinate
3176 * @x: the x coordinate
3178 * Draws a vertical line from (@x, @y1_) to (@x, @y2_) in @cr
3179 * using the given style and state.
3181 * Deprecated:3.0: Use gtk_render_line() instead
3184 gtk_paint_vline (GtkStyle *style,
3186 GtkStateType state_type,
3188 const gchar *detail,
3193 g_return_if_fail (GTK_IS_STYLE (style));
3194 g_return_if_fail (cr != NULL);
3195 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
3199 GTK_STYLE_GET_CLASS (style)->draw_vline (style, cr, state_type,
3208 * @style: a #GtkStyle
3210 * @state_type: a state
3211 * @shadow_type: type of shadow to draw
3212 * @widget: (allow-none): the widget
3213 * @detail: (allow-none): a style detail
3214 * @x: x origin of the rectangle
3215 * @y: y origin of the rectangle
3216 * @width: width of the rectangle
3217 * @height: width of the rectangle
3219 * Draws a shadow around the given rectangle in @cr
3220 * using the given style and state and shadow type.
3222 * Deprecated:3.0: Use gtk_render_frame() instead
3225 gtk_paint_shadow (GtkStyle *style,
3227 GtkStateType state_type,
3228 GtkShadowType shadow_type,
3230 const gchar *detail,
3236 g_return_if_fail (GTK_IS_STYLE (style));
3237 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
3238 g_return_if_fail (cr != NULL);
3239 g_return_if_fail (width >= 0);
3240 g_return_if_fail (height >= 0);
3244 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, cr, state_type, shadow_type,
3246 x, y, width, height);
3253 * @style: a #GtkStyle
3255 * @state_type: a state
3256 * @shadow_type: the type of shadow to draw
3257 * @widget: (allow-none): the widget
3258 * @detail: (allow-none): a style detail
3259 * @arrow_type: the type of arrow to draw
3260 * @fill: %TRUE if the arrow tip should be filled
3261 * @x: x origin of the rectangle to draw the arrow in
3262 * @y: y origin of the rectangle to draw the arrow in
3263 * @width: width of the rectangle to draw the arrow in
3264 * @height: height of the rectangle to draw the arrow in
3266 * Draws an arrow in the given rectangle on @cr using the given
3267 * parameters. @arrow_type determines the direction of the arrow.
3269 * Deprecated:3.0: Use gtk_render_arrow() instead
3272 gtk_paint_arrow (GtkStyle *style,
3274 GtkStateType state_type,
3275 GtkShadowType shadow_type,
3277 const gchar *detail,
3278 GtkArrowType arrow_type,
3285 g_return_if_fail (GTK_IS_STYLE (style));
3286 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
3287 g_return_if_fail (cr != NULL);
3288 g_return_if_fail (width >= 0);
3289 g_return_if_fail (height >= 0);
3293 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, cr, state_type, shadow_type,
3295 arrow_type, fill, x, y, width, height);
3301 * gtk_paint_diamond:
3302 * @style: a #GtkStyle
3304 * @state_type: a state
3305 * @shadow_type: the type of shadow to draw
3306 * @widget: (allow-none): the widget
3307 * @detail: (allow-none): a style detail
3308 * @x: x origin of the rectangle to draw the diamond in
3309 * @y: y origin of the rectangle to draw the diamond in
3310 * @width: width of the rectangle to draw the diamond in
3311 * @height: height of the rectangle to draw the diamond in
3313 * Draws a diamond in the given rectangle on @window using the given
3316 * Deprecated:3.0: Use cairo instead
3319 gtk_paint_diamond (GtkStyle *style,
3321 GtkStateType state_type,
3322 GtkShadowType shadow_type,
3324 const gchar *detail,
3330 g_return_if_fail (GTK_IS_STYLE (style));
3331 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
3332 g_return_if_fail (cr != NULL);
3333 g_return_if_fail (width >= 0);
3334 g_return_if_fail (height >= 0);
3338 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, cr, state_type, shadow_type,
3340 x, y, width, height);
3347 * @style: a #GtkStyle
3349 * @state_type: a state
3350 * @shadow_type: the type of shadow to draw
3351 * @widget: (allow-none): the widget
3352 * @detail: (allow-none): a style detail
3353 * @x: x origin of the box
3354 * @y: y origin of the box
3355 * @width: the width of the box
3356 * @height: the height of the box
3358 * Draws a box on @cr with the given parameters.
3360 * Deprecated:3.0: Use gtk_render_frame() and gtk_render_background() instead
3363 gtk_paint_box (GtkStyle *style,
3365 GtkStateType state_type,
3366 GtkShadowType shadow_type,
3368 const gchar *detail,
3374 g_return_if_fail (GTK_IS_STYLE (style));
3375 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
3376 g_return_if_fail (cr != NULL);
3380 GTK_STYLE_GET_CLASS (style)->draw_box (style, cr, state_type, shadow_type,
3382 x, y, width, height);
3388 * gtk_paint_flat_box:
3389 * @style: a #GtkStyle
3391 * @state_type: a state
3392 * @shadow_type: the type of shadow to draw
3393 * @widget: (allow-none): the widget
3394 * @detail: (allow-none): a style detail
3395 * @x: x origin of the box
3396 * @y: y origin of the box
3397 * @width: the width of the box
3398 * @height: the height of the box
3400 * Draws a flat box on @cr with the given parameters.
3402 * Deprecated:3.0: Use gtk_render_frame() and gtk_render_background() instead
3405 gtk_paint_flat_box (GtkStyle *style,
3407 GtkStateType state_type,
3408 GtkShadowType shadow_type,
3410 const gchar *detail,
3416 g_return_if_fail (GTK_IS_STYLE (style));
3417 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
3418 g_return_if_fail (cr != NULL);
3419 g_return_if_fail (width >= 0);
3420 g_return_if_fail (height >= 0);
3424 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, cr, state_type, shadow_type,
3426 x, y, width, height);
3433 * @style: a #GtkStyle
3435 * @state_type: a state
3436 * @shadow_type: the type of shadow to draw
3437 * @widget: (allow-none): the widget
3438 * @detail: (allow-none): a style detail
3439 * @x: x origin of the rectangle to draw the check in
3440 * @y: y origin of the rectangle to draw the check in
3441 * @width: the width of the rectangle to draw the check in
3442 * @height: the height of the rectangle to draw the check in
3444 * Draws a check button indicator in the given rectangle on @cr with
3445 * the given parameters.
3447 * Deprecated:3.0: Use gtk_render_check() instead
3450 gtk_paint_check (GtkStyle *style,
3452 GtkStateType state_type,
3453 GtkShadowType shadow_type,
3455 const gchar *detail,
3461 g_return_if_fail (GTK_IS_STYLE (style));
3462 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
3463 g_return_if_fail (cr != NULL);
3467 GTK_STYLE_GET_CLASS (style)->draw_check (style, cr, state_type, shadow_type,
3469 x, y, width, height);
3476 * @style: a #GtkStyle
3478 * @state_type: a state
3479 * @shadow_type: the type of shadow to draw
3480 * @widget: (allow-none): the widget
3481 * @detail: (allow-none): a style detail
3482 * @x: x origin of the rectangle to draw the option in
3483 * @y: y origin of the rectangle to draw the option in
3484 * @width: the width of the rectangle to draw the option in
3485 * @height: the height of the rectangle to draw the option in
3487 * Draws a radio button indicator in the given rectangle on @cr with
3488 * the given parameters.
3490 * Deprecated:3.0: Use gtk_render_option() instead
3493 gtk_paint_option (GtkStyle *style,
3495 GtkStateType state_type,
3496 GtkShadowType shadow_type,
3498 const gchar *detail,
3504 g_return_if_fail (GTK_IS_STYLE (style));
3505 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
3506 g_return_if_fail (cr != NULL);
3510 GTK_STYLE_GET_CLASS (style)->draw_option (style, cr, state_type, shadow_type,
3512 x, y, width, height);
3519 * @style: a #GtkStyle
3521 * @state_type: a state
3522 * @shadow_type: the type of shadow to draw
3523 * @widget: (allow-none): the widget
3524 * @detail: (allow-none): a style detail
3525 * @x: x origin of the rectangle to draw the tab in
3526 * @y: y origin of the rectangle to draw the tab in
3527 * @width: the width of the rectangle to draw the tab in
3528 * @height: the height of the rectangle to draw the tab in
3530 * Draws an option menu tab (i.e. the up and down pointing arrows)
3531 * in the given rectangle on @cr using the given parameters.
3533 * Deprecated:3.0: Use cairo instead
3536 gtk_paint_tab (GtkStyle *style,
3538 GtkStateType state_type,
3539 GtkShadowType shadow_type,
3541 const gchar *detail,
3547 g_return_if_fail (GTK_IS_STYLE (style));
3548 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
3549 g_return_if_fail (cr != NULL);
3553 GTK_STYLE_GET_CLASS (style)->draw_tab (style, cr, state_type, shadow_type,
3555 x, y, width, height);
3561 * gtk_paint_shadow_gap:
3562 * @style: a #GtkStyle
3564 * @state_type: a state
3565 * @shadow_type: type of shadow to draw
3566 * @widget: (allow-none): the widget
3567 * @detail: (allow-none): a style detail
3568 * @x: x origin of the rectangle
3569 * @y: y origin of the rectangle
3570 * @width: width of the rectangle
3571 * @height: width of the rectangle
3572 * @gap_side: side in which to leave the gap
3573 * @gap_x: starting position of the gap
3574 * @gap_width: width of the gap
3576 * Draws a shadow around the given rectangle in @cr
3577 * using the given style and state and shadow type, leaving a
3580 * Deprecated:3.0: Use gtk_render_frame_gap() instead
3583 gtk_paint_shadow_gap (GtkStyle *style,
3585 GtkStateType state_type,
3586 GtkShadowType shadow_type,
3588 const gchar *detail,
3593 GtkPositionType gap_side,
3597 g_return_if_fail (GTK_IS_STYLE (style));
3598 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
3599 g_return_if_fail (cr != NULL);
3600 g_return_if_fail (width >= 0);
3601 g_return_if_fail (height >= 0);
3605 GTK_STYLE_GET_CLASS (style)->draw_shadow_gap (style, cr, state_type, shadow_type,
3607 x, y, width, height, gap_side, gap_x, gap_width);
3613 * gtk_paint_box_gap:
3614 * @style: a #GtkStyle
3616 * @state_type: a state
3617 * @shadow_type: type of shadow to draw
3618 * @widget: (allow-none): the widget
3619 * @detail: (allow-none): a style detail
3620 * @x: x origin of the rectangle
3621 * @y: y origin of the rectangle
3622 * @width: width of the rectangle
3623 * @height: width of the rectangle
3624 * @gap_side: side in which to leave the gap
3625 * @gap_x: starting position of the gap
3626 * @gap_width: width of the gap
3628 * Draws a box in @cr using the given style and state and shadow type,
3629 * leaving a gap in one side.
3631 * Deprecated:3.0: Use gtk_render_frame_gap() instead
3634 gtk_paint_box_gap (GtkStyle *style,
3636 GtkStateType state_type,
3637 GtkShadowType shadow_type,
3639 const gchar *detail,
3644 GtkPositionType gap_side,
3648 g_return_if_fail (GTK_IS_STYLE (style));
3649 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
3650 g_return_if_fail (cr != NULL);
3651 g_return_if_fail (width >= 0);
3652 g_return_if_fail (height >= 0);
3656 GTK_STYLE_GET_CLASS (style)->draw_box_gap (style, cr, state_type, shadow_type,
3658 x, y, width, height, gap_side, gap_x, gap_width);
3664 * gtk_paint_extension:
3665 * @style: a #GtkStyle
3667 * @state_type: a state
3668 * @shadow_type: type of shadow to draw
3669 * @widget: (allow-none): the widget
3670 * @detail: (allow-none): a style detail
3671 * @x: x origin of the extension
3672 * @y: y origin of the extension
3673 * @width: width of the extension
3674 * @height: width of the extension
3675 * @gap_side: the side on to which the extension is attached
3677 * Draws an extension, i.e. a notebook tab.
3679 * Deprecated:3.0: Use gtk_render_extension() instead
3682 gtk_paint_extension (GtkStyle *style,
3684 GtkStateType state_type,
3685 GtkShadowType shadow_type,
3687 const gchar *detail,
3692 GtkPositionType gap_side)
3694 g_return_if_fail (GTK_IS_STYLE (style));
3695 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
3696 g_return_if_fail (cr != NULL);
3697 g_return_if_fail (width >= 0);
3698 g_return_if_fail (height >= 0);
3702 GTK_STYLE_GET_CLASS (style)->draw_extension (style, cr, state_type, shadow_type,
3704 x, y, width, height, gap_side);
3711 * @style: a #GtkStyle
3713 * @state_type: a state
3714 * @widget: (allow-none): the widget
3715 * @detail: (allow-none): a style detail
3716 * @x: the x origin of the rectangle around which to draw a focus indicator
3717 * @y: the y origin of the rectangle around which to draw a focus indicator
3718 * @width: the width of the rectangle around which to draw a focus indicator
3719 * @height: the height of the rectangle around which to draw a focus indicator
3721 * Draws a focus indicator around the given rectangle on @cr using the
3724 * Deprecated:3.0: Use gtk_render_focus() instead
3727 gtk_paint_focus (GtkStyle *style,
3729 GtkStateType state_type,
3731 const gchar *detail,
3737 g_return_if_fail (GTK_IS_STYLE (style));
3738 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
3739 g_return_if_fail (cr != NULL);
3740 g_return_if_fail (width >= 0);
3741 g_return_if_fail (height >= 0);
3745 GTK_STYLE_GET_CLASS (style)->draw_focus (style, cr, state_type,
3747 x, y, width, height);
3754 * @style: a #GtkStyle
3756 * @state_type: a state
3757 * @shadow_type: a shadow
3758 * @widget: (allow-none): the widget
3759 * @detail: (allow-none): a style detail
3760 * @x: the x origin of the rectangle in which to draw a slider
3761 * @y: the y origin of the rectangle in which to draw a slider
3762 * @width: the width of the rectangle in which to draw a slider
3763 * @height: the height of the rectangle in which to draw a slider
3764 * @orientation: the orientation to be used
3766 * Draws a slider in the given rectangle on @cr using the
3767 * given style and orientation.
3769 * Deprecated:3.0: Use gtk_render_slider() instead
3772 gtk_paint_slider (GtkStyle *style,
3774 GtkStateType state_type,
3775 GtkShadowType shadow_type,
3777 const gchar *detail,
3782 GtkOrientation orientation)
3784 g_return_if_fail (GTK_IS_STYLE (style));
3785 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
3786 g_return_if_fail (cr != NULL);
3787 g_return_if_fail (width >= 0);
3788 g_return_if_fail (height >= 0);
3792 GTK_STYLE_GET_CLASS (style)->draw_slider (style, cr, state_type, shadow_type,
3794 x, y, width, height, orientation);
3801 * @style: a #GtkStyle
3803 * @state_type: a state
3804 * @shadow_type: type of shadow to draw
3805 * @widget: (allow-none): the widget
3806 * @detail: (allow-none): a style detail
3807 * @x: x origin of the handle
3808 * @y: y origin of the handle
3809 * @width: with of the handle
3810 * @height: height of the handle
3811 * @orientation: the orientation of the handle
3813 * Draws a handle as used in #GtkHandleBox and #GtkPaned.
3815 * Deprecated:3.0: Use gtk_render_handle() instead
3818 gtk_paint_handle (GtkStyle *style,
3820 GtkStateType state_type,
3821 GtkShadowType shadow_type,
3823 const gchar *detail,
3828 GtkOrientation orientation)
3830 g_return_if_fail (GTK_IS_STYLE (style));
3831 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
3832 g_return_if_fail (cr != NULL);
3833 g_return_if_fail (width >= 0);
3834 g_return_if_fail (height >= 0);
3838 GTK_STYLE_GET_CLASS (style)->draw_handle (style, cr, state_type, shadow_type,
3840 x, y, width, height, orientation);
3846 * gtk_paint_expander:
3847 * @style: a #GtkStyle
3849 * @state_type: a state
3850 * @widget: (allow-none): the widget
3851 * @detail: (allow-none): a style detail
3852 * @x: the x position to draw the expander at
3853 * @y: the y position to draw the expander at
3854 * @expander_style: the style to draw the expander in; determines
3855 * whether the expander is collapsed, expanded, or in an
3856 * intermediate state.
3858 * Draws an expander as used in #GtkTreeView. @x and @y specify the
3859 * center the expander. The size of the expander is determined by the
3860 * "expander-size" style property of @widget. (If widget is not
3861 * specified or doesn't have an "expander-size" property, an
3862 * unspecified default size will be used, since the caller doesn't
3863 * have sufficient information to position the expander, this is
3864 * likely not useful.) The expander is expander_size pixels tall
3865 * in the collapsed position and expander_size pixels wide in the
3866 * expanded position.
3868 * Deprecated:3.0: Use gtk_render_expander() instead
3871 gtk_paint_expander (GtkStyle *style,
3873 GtkStateType state_type,
3875 const gchar *detail,
3878 GtkExpanderStyle expander_style)
3880 g_return_if_fail (GTK_IS_STYLE (style));
3881 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
3882 g_return_if_fail (cr != NULL);
3886 GTK_STYLE_GET_CLASS (style)->draw_expander (style, cr, state_type,
3888 x, y, expander_style);
3895 * @style: a #GtkStyle
3897 * @state_type: a state
3898 * @use_text: whether to use the text or foreground
3899 * graphics context of @style
3900 * @widget: (allow-none): the widget
3901 * @detail: (allow-none): a style detail
3904 * @layout: the layout to draw
3906 * Draws a layout on @cr using the given parameters.
3908 * Deprecated:3.0: Use gtk_render_layout() instead
3911 gtk_paint_layout (GtkStyle *style,
3913 GtkStateType state_type,
3916 const gchar *detail,
3919 PangoLayout *layout)
3921 g_return_if_fail (GTK_IS_STYLE (style));
3922 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
3923 g_return_if_fail (cr != NULL);
3927 GTK_STYLE_GET_CLASS (style)->draw_layout (style, cr, state_type, use_text,
3935 * gtk_paint_resize_grip:
3936 * @style: a #GtkStyle
3938 * @state_type: a state
3939 * @widget: (allow-none): the widget
3940 * @detail: (allow-none): a style detail
3941 * @edge: the edge in which to draw the resize grip
3942 * @x: the x origin of the rectangle in which to draw the resize grip
3943 * @y: the y origin of the rectangle in which to draw the resize grip
3944 * @width: the width of the rectangle in which to draw the resize grip
3945 * @height: the height of the rectangle in which to draw the resize grip
3947 * Draws a resize grip in the given rectangle on @cr using the given
3950 * Deprecated:3.0: Use gtk_render_handle() instead
3953 gtk_paint_resize_grip (GtkStyle *style,
3955 GtkStateType state_type,
3957 const gchar *detail,
3964 g_return_if_fail (GTK_IS_STYLE (style));
3965 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
3966 g_return_if_fail (cr != NULL);
3970 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, cr, state_type,
3972 edge, x, y, width, height);
3977 * gtk_paint_spinner:
3978 * @style: a #GtkStyle
3980 * @state_type: a state
3981 * @widget: (allow-none): the widget (may be %NULL)
3982 * @detail: (allow-none): a style detail (may be %NULL)
3983 * @step: the nth step, a value between 0 and #GtkSpinner:num-steps
3984 * @x: the x origin of the rectangle in which to draw the spinner
3985 * @y: the y origin of the rectangle in which to draw the spinner
3986 * @width: the width of the rectangle in which to draw the spinner
3987 * @height: the height of the rectangle in which to draw the spinner
3989 * Draws a spinner on @window using the given parameters.
3991 * Deprecated:3.0: Use gtk_render_activity() instead
3994 gtk_paint_spinner (GtkStyle *style,
3996 GtkStateType state_type,
3998 const gchar *detail,
4005 g_return_if_fail (GTK_IS_STYLE (style));
4006 g_return_if_fail (cr != NULL);
4007 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_spinner != NULL);
4011 GTK_STYLE_GET_CLASS (style)->draw_spinner (style, cr, state_type,
4013 step, x, y, width, height);
4019 gtk_widget_get_default_style_for_screen (GdkScreen *screen)
4021 GtkStyle *default_style;
4023 default_style = g_object_get_data (G_OBJECT (screen), "gtk-legacy-default-style");
4024 if (default_style == NULL)
4026 default_style = gtk_style_new ();
4027 g_object_set_data_full (G_OBJECT (screen),
4028 I_("gtk-legacy-default-style"),
4033 return default_style;
4037 * gtk_widget_get_default_style:
4039 * Returns the default style used by all widgets initially.
4041 * Returns: (transfer none): the default style. This #GtkStyle
4042 * object is owned by GTK+ and should not be modified or freed.
4044 * Deprecated:3.0: Use #GtkStyleContext instead, and
4045 * gtk_css_provider_get_default() to obtain a #GtkStyleProvider
4046 * with the default widget style information.
4049 gtk_widget_get_default_style (void)
4051 static GtkStyle *default_style = NULL;
4052 GtkStyle *style = NULL;
4053 GdkScreen *screen = gdk_screen_get_default ();
4056 style = gtk_widget_get_default_style_for_screen (screen);
4059 if (default_style == NULL)
4060 default_style = gtk_style_new ();
4061 style = default_style;
4068 * gtk_widget_style_attach:
4069 * @widget: a #GtkWidget
4071 * This function attaches the widget's #GtkStyle to the widget's
4072 * #GdkWindow. It is a replacement for
4075 * widget->style = gtk_style_attach (widget->style, widget->window);
4078 * and should only ever be called in a derived widget's "realize"
4079 * implementation which does not chain up to its parent class'
4080 * "realize" implementation, because one of the parent classes
4081 * (finally #GtkWidget) would attach the style itself.
4085 * Deprecated: 3.0. This step is unnecessary with #GtkStyleContext.
4088 gtk_widget_style_attach (GtkWidget *widget)
4090 g_return_if_fail (GTK_IS_WIDGET (widget));
4091 g_return_if_fail (gtk_widget_get_realized (widget));
4095 * gtk_widget_has_rc_style:
4096 * @widget: a #GtkWidget
4098 * Determines if the widget style has been looked up through the rc mechanism.
4100 * Returns: %TRUE if the widget has been looked up through the rc
4101 * mechanism, %FALSE otherwise.
4105 * Deprecated:3.0: Use #GtkStyleContext instead
4108 gtk_widget_has_rc_style (GtkWidget *widget)
4110 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4116 * gtk_widget_set_style:
4117 * @widget: a #GtkWidget
4118 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect
4119 * of a previous call to gtk_widget_set_style() and go back to
4122 * Used to set the #GtkStyle for a widget (@widget->style). Since
4123 * GTK 3, this function does nothing, the passed in style is ignored.
4125 * Deprecated:3.0: Use #GtkStyleContext instead
4128 gtk_widget_set_style (GtkWidget *widget,
4131 g_return_if_fail (GTK_IS_WIDGET (widget));
4135 * gtk_widget_ensure_style:
4136 * @widget: a #GtkWidget
4138 * Ensures that @widget has a style (@widget->style).
4140 * Not a very useful function; most of the time, if you
4141 * want the style, the widget is realized, and realized
4142 * widgets are guaranteed to have a style already.
4144 * Deprecated:3.0: Use #GtkStyleContext instead
4147 gtk_widget_ensure_style (GtkWidget *widget)
4150 g_return_if_fail (GTK_IS_WIDGET (widget));
4152 style = _gtk_widget_get_style (widget);
4153 if (style == gtk_widget_get_default_style ())
4155 g_object_unref (style);
4156 _gtk_widget_set_style (widget, NULL);
4158 g_signal_emit_by_name (widget, "style-set", 0, NULL);
4163 * gtk_widget_get_style:
4164 * @widget: a #GtkWidget
4166 * Simply an accessor function that returns @widget->style.
4168 * Return value: (transfer none): the widget's #GtkStyle
4170 * Deprecated:3.0: Use #GtkStyleContext instead
4173 gtk_widget_get_style (GtkWidget *widget)
4176 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4178 style = _gtk_widget_get_style (widget);
4182 style = g_object_new (GTK_TYPE_STYLE,
4183 "context", gtk_widget_get_style_context (widget),
4185 _gtk_widget_set_style (widget, style);
4192 * gtk_widget_modify_style:
4193 * @widget: a #GtkWidget
4194 * @style: the #GtkRcStyle holding the style modifications
4196 * Modifies style values on the widget.
4198 * Modifications made using this technique take precedence over
4199 * style values set via an RC file, however, they will be overridden
4200 * if a style is explicitely set on the widget using gtk_widget_set_style().
4201 * The #GtkRcStyle structure is designed so each field can either be
4202 * set or unset, so it is possible, using this function, to modify some
4203 * style values and leave the others unchanged.
4205 * Note that modifications made with this function are not cumulative
4206 * with previous calls to gtk_widget_modify_style() or with such
4207 * functions as gtk_widget_modify_fg(). If you wish to retain
4208 * previous values, you must first call gtk_widget_get_modifier_style(),
4209 * make your modifications to the returned style, then call
4210 * gtk_widget_modify_style() with that style. On the other hand,
4211 * if you first call gtk_widget_modify_style(), subsequent calls
4212 * to such functions gtk_widget_modify_fg() will have a cumulative
4213 * effect with the initial modifications.
4215 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
4218 gtk_widget_modify_style (GtkWidget *widget,
4221 g_return_if_fail (GTK_IS_WIDGET (widget));
4222 g_return_if_fail (GTK_IS_RC_STYLE (style));
4224 g_object_set_data_full (G_OBJECT (widget),
4226 gtk_rc_style_copy (style),
4227 (GDestroyNotify) g_object_unref);
4231 * gtk_widget_get_modifier_style:
4232 * @widget: a #GtkWidget
4234 * Returns the current modifier style for the widget. (As set by
4235 * gtk_widget_modify_style().) If no style has previously set, a new
4236 * #GtkRcStyle will be created with all values unset, and set as the
4237 * modifier style for the widget. If you make changes to this rc
4238 * style, you must call gtk_widget_modify_style(), passing in the
4239 * returned rc style, to make sure that your changes take effect.
4241 * Caution: passing the style back to gtk_widget_modify_style() will
4242 * normally end up destroying it, because gtk_widget_modify_style() copies
4243 * the passed-in style and sets the copy as the new modifier style,
4244 * thus dropping any reference to the old modifier style. Add a reference
4245 * to the modifier style if you want to keep it alive.
4247 * Return value: (transfer none): the modifier style for the widget.
4248 * This rc style is owned by the widget. If you want to keep a
4249 * pointer to value this around, you must add a refcount using
4252 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
4255 gtk_widget_get_modifier_style (GtkWidget *widget)
4257 GtkRcStyle *rc_style;
4259 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4261 rc_style = g_object_get_data (G_OBJECT (widget), "gtk-rc-style");
4265 rc_style = gtk_rc_style_new ();
4266 g_object_set_data_full (G_OBJECT (widget),
4269 (GDestroyNotify) g_object_unref);
4276 gtk_widget_modify_color_component (GtkWidget *widget,
4277 GtkRcFlags component,
4279 const GdkColor *color)
4281 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
4288 rc_style->fg[state] = *color;
4291 rc_style->bg[state] = *color;
4294 rc_style->text[state] = *color;
4297 rc_style->base[state] = *color;
4300 g_assert_not_reached();
4303 rc_style->color_flags[state] |= component;
4306 rc_style->color_flags[state] &= ~component;
4308 gtk_widget_modify_style (widget, rc_style);
4312 * gtk_widget_modify_fg:
4313 * @widget: a #GtkWidget
4314 * @state: the state for which to set the foreground color
4315 * @color: (allow-none): the color to assign (does not need to be allocated),
4316 * or %NULL to undo the effect of previous calls to
4317 * of gtk_widget_modify_fg().
4319 * Sets the foreground color for a widget in a particular state.
4321 * All other style values are left untouched.
4322 * See also gtk_widget_modify_style().
4324 * Deprecated:3.0: Use gtk_widget_override_color() instead
4327 gtk_widget_modify_fg (GtkWidget *widget,
4329 const GdkColor *color)
4331 GtkStateFlags flags;
4334 g_return_if_fail (GTK_IS_WIDGET (widget));
4335 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4339 case GTK_STATE_ACTIVE:
4340 flags = GTK_STATE_FLAG_ACTIVE;
4342 case GTK_STATE_PRELIGHT:
4343 flags = GTK_STATE_FLAG_PRELIGHT;
4345 case GTK_STATE_SELECTED:
4346 flags = GTK_STATE_FLAG_SELECTED;
4348 case GTK_STATE_INSENSITIVE:
4349 flags = GTK_STATE_FLAG_INSENSITIVE;
4351 case GTK_STATE_NORMAL:
4358 rgba.red = color->red / 65535.;
4359 rgba.green = color->green / 65535.;
4360 rgba.blue = color->blue / 65535.;
4363 gtk_widget_override_color (widget, flags, &rgba);
4366 gtk_widget_override_color (widget, flags, NULL);
4370 * gtk_widget_modify_bg:
4371 * @widget: a #GtkWidget
4372 * @state: the state for which to set the background color
4373 * @color: (allow-none): the color to assign (does not need
4374 * to be allocated), or %NULL to undo the effect of previous
4375 * calls to of gtk_widget_modify_bg().
4377 * Sets the background color for a widget in a particular state.
4379 * All other style values are left untouched.
4380 * See also gtk_widget_modify_style().
4383 * Note that "no window" widgets (which have the %GTK_NO_WINDOW
4384 * flag set) draw on their parent container's window and thus may
4385 * not draw any background themselves. This is the case for e.g.
4388 * To modify the background of such widgets, you have to set the
4389 * background color on their parent; if you want to set the background
4390 * of a rectangular area around a label, try placing the label in
4391 * a #GtkEventBox widget and setting the background color on that.
4394 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
4397 gtk_widget_modify_bg (GtkWidget *widget,
4399 const GdkColor *color)
4401 GtkStateFlags flags;
4404 g_return_if_fail (GTK_IS_WIDGET (widget));
4405 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4409 case GTK_STATE_ACTIVE:
4410 flags = GTK_STATE_FLAG_ACTIVE;
4412 case GTK_STATE_PRELIGHT:
4413 flags = GTK_STATE_FLAG_PRELIGHT;
4415 case GTK_STATE_SELECTED:
4416 flags = GTK_STATE_FLAG_SELECTED;
4418 case GTK_STATE_INSENSITIVE:
4419 flags = GTK_STATE_FLAG_INSENSITIVE;
4421 case GTK_STATE_NORMAL:
4428 rgba.red = color->red / 65535.;
4429 rgba.green = color->green / 65535.;
4430 rgba.blue = color->blue / 65535.;
4433 gtk_widget_override_background_color (widget, flags, &rgba);
4436 gtk_widget_override_background_color (widget, flags, NULL);
4440 * gtk_widget_modify_text:
4441 * @widget: a #GtkWidget
4442 * @state: the state for which to set the text color
4443 * @color: (allow-none): the color to assign (does not need to
4444 * be allocated), or %NULL to undo the effect of previous
4445 * calls to of gtk_widget_modify_text().
4447 * Sets the text color for a widget in a particular state.
4449 * All other style values are left untouched.
4450 * The text color is the foreground color used along with the
4451 * base color (see gtk_widget_modify_base()) for widgets such
4452 * as #GtkEntry and #GtkTextView.
4453 * See also gtk_widget_modify_style().
4455 * Deprecated:3.0: Use gtk_widget_override_color() instead
4458 gtk_widget_modify_text (GtkWidget *widget,
4460 const GdkColor *color)
4462 g_return_if_fail (GTK_IS_WIDGET (widget));
4463 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4465 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
4469 * gtk_widget_modify_base:
4470 * @widget: a #GtkWidget
4471 * @state: the state for which to set the base color
4472 * @color: (allow-none): the color to assign (does not need to
4473 * be allocated), or %NULL to undo the effect of previous
4474 * calls to of gtk_widget_modify_base().
4476 * Sets the base color for a widget in a particular state.
4477 * All other style values are left untouched. The base color
4478 * is the background color used along with the text color
4479 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
4480 * and #GtkTextView. See also gtk_widget_modify_style().
4483 * Note that "no window" widgets (which have the %GTK_NO_WINDOW
4484 * flag set) draw on their parent container's window and thus may
4485 * not draw any background themselves. This is the case for e.g.
4488 * To modify the background of such widgets, you have to set the
4489 * base color on their parent; if you want to set the background
4490 * of a rectangular area around a label, try placing the label in
4491 * a #GtkEventBox widget and setting the base color on that.
4494 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
4497 gtk_widget_modify_base (GtkWidget *widget,
4499 const GdkColor *color)
4501 g_return_if_fail (GTK_IS_WIDGET (widget));
4502 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4504 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
4508 * gtk_widget_modify_cursor:
4509 * @widget: a #GtkWidget
4510 * @primary: the color to use for primary cursor (does not need to be
4511 * allocated), or %NULL to undo the effect of previous calls to
4512 * of gtk_widget_modify_cursor().
4513 * @secondary: the color to use for secondary cursor (does not need to be
4514 * allocated), or %NULL to undo the effect of previous calls to
4515 * of gtk_widget_modify_cursor().
4517 * Sets the cursor color to use in a widget, overriding the
4518 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
4521 * All other style values are left untouched.
4522 * See also gtk_widget_modify_style().
4526 * Deprecated: 3.0. Use gtk_widget_override_cursor() instead.
4529 gtk_widget_modify_cursor (GtkWidget *widget,
4530 const GdkColor *primary,
4531 const GdkColor *secondary)
4533 GdkRGBA primary_rgba, secondary_rgba;
4535 g_return_if_fail (GTK_IS_WIDGET (widget));
4537 primary_rgba.red = primary->red / 65535.;
4538 primary_rgba.green = primary->green / 65535.;
4539 primary_rgba.blue = primary->blue / 65535.;
4540 primary_rgba.alpha = 1;
4542 secondary_rgba.red = secondary->red / 65535.;
4543 secondary_rgba.green = secondary->green / 65535.;
4544 secondary_rgba.blue = secondary->blue / 65535.;
4545 secondary_rgba.alpha = 1;
4547 gtk_widget_override_cursor (widget, &primary_rgba, &secondary_rgba);
4551 * gtk_widget_modify_font:
4552 * @widget: a #GtkWidget
4553 * @font_desc: (allow-none): the font description to use, or %NULL
4554 * to undo the effect of previous calls to gtk_widget_modify_font()
4556 * Sets the font to use for a widget.
4558 * All other style values are left untouched.
4559 * See also gtk_widget_modify_style().
4561 * Deprecated:3.0: Use gtk_widget_override_font() instead
4564 gtk_widget_modify_font (GtkWidget *widget,
4565 PangoFontDescription *font_desc)
4567 g_return_if_fail (GTK_IS_WIDGET (widget));
4569 gtk_widget_override_font (widget, font_desc);
4573 * gtk_widget_reset_rc_styles:
4574 * @widget: a #GtkWidget.
4576 * Reset the styles of @widget and all descendents, so when
4577 * they are looked up again, they get the correct values
4578 * for the currently loaded RC file settings.
4580 * This function is not useful for applications.
4582 * Deprecated:3.0: Use #GtkStyleContext instead, and gtk_widget_reset_style()
4585 gtk_widget_reset_rc_styles (GtkWidget *widget)
4587 g_return_if_fail (GTK_IS_WIDGET (widget));
4589 gtk_widget_reset_style (widget);
4594 * @widget: a #GtkWidget
4595 * @path_length: (out) (allow-none): location to store length of the path,
4597 * @path: (out) (allow-none): location to store allocated path string,
4599 * @path_reversed: (out) (allow-none): location to store allocated reverse
4600 * path string, or %NULL
4602 * Obtains the full path to @widget. The path is simply the name of a
4603 * widget and all its parents in the container hierarchy, separated by
4604 * periods. The name of a widget comes from
4605 * gtk_widget_get_name(). Paths are used to apply styles to a widget
4606 * in gtkrc configuration files. Widget names are the type of the
4607 * widget by default (e.g. "GtkButton") or can be set to an
4608 * application-specific value with gtk_widget_set_name(). By setting
4609 * the name of a widget, you allow users or theme authors to apply
4610 * styles to that specific widget in their gtkrc
4611 * file. @path_reversed_p fills in the path in reverse order,
4612 * i.e. starting with @widget's name instead of starting with the name
4613 * of @widget's outermost ancestor.
4615 * Deprecated:3.0: Use gtk_widget_get_path() instead
4618 gtk_widget_path (GtkWidget *widget,
4621 gchar **path_reversed)
4623 static gchar *rev_path = NULL;
4624 static guint tmp_path_len = 0;
4627 #define INIT_PATH_SIZE (512)
4629 g_return_if_fail (GTK_IS_WIDGET (widget));
4634 const gchar *string;
4639 string = gtk_widget_get_name (widget);
4640 l = strlen (string);
4641 while (tmp_path_len <= len + l + 1)
4643 tmp_path_len += INIT_PATH_SIZE;
4644 rev_path = g_realloc (rev_path, tmp_path_len);
4652 widget = gtk_widget_get_parent (widget);
4655 rev_path[len++] = '.';
4657 rev_path[len++] = 0;
4662 *path_length = len - 1;
4664 *path_reversed = g_strdup (rev_path);
4667 *path = g_strdup (rev_path);
4668 g_strreverse (*path);
4673 * gtk_widget_class_path:
4674 * @widget: a #GtkWidget
4675 * @path_length: (out) (allow-none): location to store the length of the
4676 * class path, or %NULL
4677 * @path: (out) (allow-none): location to store the class path as an
4678 * allocated string, or %NULL
4679 * @path_reversed: (out) (allow-none): location to store the reverse
4680 * class path as an allocated string, or %NULL
4682 * Same as gtk_widget_path(), but always uses the name of a widget's type,
4683 * never uses a custom name set with gtk_widget_set_name().
4685 * Deprecated:3.0: Use gtk_widget_get_path() instead
4688 gtk_widget_class_path (GtkWidget *widget,
4691 gchar **path_reversed)
4693 static gchar *rev_path = NULL;
4694 static guint tmp_path_len = 0;
4697 g_return_if_fail (GTK_IS_WIDGET (widget));
4702 const gchar *string;
4707 string = g_type_name (G_OBJECT_TYPE (widget));
4708 l = strlen (string);
4709 while (tmp_path_len <= len + l + 1)
4711 tmp_path_len += INIT_PATH_SIZE;
4712 rev_path = g_realloc (rev_path, tmp_path_len);
4720 widget = gtk_widget_get_parent (widget);
4723 rev_path[len++] = '.';
4725 rev_path[len++] = 0;
4730 *path_length = len - 1;
4732 *path_reversed = g_strdup (rev_path);
4735 *path = g_strdup (rev_path);
4736 g_strreverse (*path);
4741 * gtk_widget_render_icon:
4742 * @widget: a #GtkWidget
4743 * @stock_id: a stock ID
4744 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
4745 * render at the size of the source and don't scale (if there are
4746 * multiple source sizes, GTK+ picks one of the available sizes).
4747 * @detail: (allow-none): render detail to pass to theme engine
4749 * A convenience function that uses the theme settings for @widget
4750 * to look up @stock_id and render it to a pixbuf. @stock_id should
4751 * be a stock icon ID such as #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size
4752 * should be a size such as #GTK_ICON_SIZE_MENU. @detail should be a
4753 * string that identifies the widget or code doing the rendering, so
4754 * that theme engines can special-case rendering for that widget or
4757 * The pixels in the returned #GdkPixbuf are shared with the rest of
4758 * the application and should not be modified. The pixbuf should be
4759 * freed after use with g_object_unref().
4761 * Return value: (transfer full): a new pixbuf, or %NULL if the
4762 * stock ID wasn't known
4764 * Deprecated: 3.0: Use gtk_widget_render_icon_pixbuf() instead.
4767 gtk_widget_render_icon (GtkWidget *widget,
4768 const gchar *stock_id,
4770 const gchar *detail)
4772 gtk_widget_ensure_style (widget);
4774 return gtk_widget_render_icon_pixbuf (widget, stock_id, size);