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];
658 if (!color || !(color->alpha > 0.01))
662 dest->red = CLAMP ((guint) (color->red * 65535), 0, 65535);
663 dest->green = CLAMP ((guint) (color->green * 65535), 0, 65535);
664 dest->blue = CLAMP ((guint) (color->blue * 65535), 0, 65535);
665 gdk_rgba_free (color);
671 set_color (GtkStyle *style,
672 GtkStyleContext *context,
680 case GTK_STATE_ACTIVE:
681 flags = GTK_STATE_FLAG_ACTIVE;
683 case GTK_STATE_PRELIGHT:
684 flags = GTK_STATE_FLAG_PRELIGHT;
686 case GTK_STATE_SELECTED:
687 flags = GTK_STATE_FLAG_SELECTED;
689 case GTK_STATE_INSENSITIVE:
690 flags = GTK_STATE_FLAG_INSENSITIVE;
696 /* Try to fill in the values from the associated GtkStyleContext.
697 * Since fully-transparent black is a very common default (e.g. for
698 * background-color properties), and we must store the result in a GdkColor
699 * to retain API compatibility, in case the fetched color is fully transparent
700 * we give themes a fallback style class they can style, before using the
701 * hardcoded default values.
703 if (!set_color_from_context (style, state, context, flags, prop))
705 gtk_style_context_save (context);
706 gtk_style_context_add_class (context, "gtkstyle-fallback");
707 set_color_from_context (style, state, context, flags, prop);
708 gtk_style_context_restore (context);
713 gtk_style_update_from_context (GtkStyle *style)
715 GtkStylePrivate *priv;
720 priv = GTK_STYLE_GET_PRIVATE (style);
722 for (state = GTK_STATE_NORMAL; state <= GTK_STATE_INSENSITIVE; state++)
724 if (gtk_style_context_has_class (priv->context, "entry"))
726 gtk_style_context_save (priv->context);
727 gtk_style_context_remove_class (priv->context, "entry");
728 set_color (style, priv->context, state, GTK_RC_BG);
729 set_color (style, priv->context, state, GTK_RC_FG);
730 gtk_style_context_restore (priv->context);
732 set_color (style, priv->context, state, GTK_RC_BASE);
733 set_color (style, priv->context, state, GTK_RC_TEXT);
737 gtk_style_context_save (priv->context);
738 gtk_style_context_add_class (priv->context, "entry");
739 set_color (style, priv->context, state, GTK_RC_BASE);
740 set_color (style, priv->context, state, GTK_RC_TEXT);
741 gtk_style_context_restore (priv->context);
743 set_color (style, priv->context, state, GTK_RC_BG);
744 set_color (style, priv->context, state, GTK_RC_FG);
748 if (style->font_desc)
749 pango_font_description_free (style->font_desc);
751 gtk_style_context_get (priv->context, 0,
752 "font", &style->font_desc,
754 gtk_style_context_get_padding (priv->context, 0, &padding);
756 style->xthickness = padding.left;
757 style->ythickness = padding.top;
759 for (i = 0; i < 5; i++)
761 _gtk_style_shade (&style->bg[i], &style->light[i], LIGHTNESS_MULT);
762 _gtk_style_shade (&style->bg[i], &style->dark[i], DARKNESS_MULT);
764 style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
765 style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
766 style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
768 style->text_aa[i].red = (style->text[i].red + style->base[i].red) / 2;
769 style->text_aa[i].green = (style->text[i].green + style->base[i].green) / 2;
770 style->text_aa[i].blue = (style->text[i].blue + style->base[i].blue) / 2;
773 style->black.red = 0x0000;
774 style->black.green = 0x0000;
775 style->black.blue = 0x0000;
777 style->white.red = 0xffff;
778 style->white.green = 0xffff;
779 style->white.blue = 0xffff;
781 for (i = 0; i < 5; i++)
783 if (style->background[i])
784 cairo_pattern_destroy (style->background[i]);
786 style->background[i] = cairo_pattern_create_rgb (style->bg[i].red / 65535.0,
787 style->bg[i].green / 65535.0,
788 style->bg[i].blue / 65535.0);
793 style_context_changed (GtkStyleContext *context,
796 gtk_style_update_from_context (GTK_STYLE (user_data));
800 gtk_style_constructed (GObject *object)
802 GtkStylePrivate *priv;
804 priv = GTK_STYLE_GET_PRIVATE (object);
808 gtk_style_update_from_context (GTK_STYLE (object));
810 priv->context_changed_id = g_signal_connect (priv->context, "changed",
811 G_CALLBACK (style_context_changed), object);
817 * @style: a #GtkStyle
819 * Creates a copy of the passed in #GtkStyle object.
821 * Returns: (transfer full): a copy of @style
823 * Deprecated:3.0: Use #GtkStyleContext instead
826 gtk_style_copy (GtkStyle *style)
830 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
832 new_style = GTK_STYLE_GET_CLASS (style)->clone (style);
833 GTK_STYLE_GET_CLASS (style)->copy (new_style, style);
839 _gtk_style_new_for_path (GdkScreen *screen,
842 GtkStyleContext *context;
845 context = gtk_style_context_new ();
848 gtk_style_context_set_screen (context, screen);
850 gtk_style_context_set_path (context, path);
852 style = g_object_new (GTK_TYPE_STYLE,
856 g_object_unref (context);
864 * Creates a new #GtkStyle.
866 * Returns: a new #GtkStyle.
868 * Deprecated: 3.0: Use #GtkStyleContext
876 path = gtk_widget_path_new ();
877 gtk_widget_path_append_type (path, GTK_TYPE_WIDGET);
879 style = _gtk_style_new_for_path (gdk_screen_get_default (), path);
881 gtk_widget_path_free (path);
887 * gtk_style_has_context:
888 * @style: a #GtkStyle
890 * Returns whether @style has an associated #GtkStyleContext.
892 * Returns: %TRUE if @style has a #GtkStyleContext
897 gtk_style_has_context (GtkStyle *style)
899 GtkStylePrivate *priv;
901 priv = GTK_STYLE_GET_PRIVATE (style);
903 return priv->context != NULL;
907 * gtk_style_attach: (skip)
908 * @style: a #GtkStyle.
909 * @window: a #GdkWindow.
911 * Attaches a style to a window; this process allocates the
912 * colors and creates the GC's for the style - it specializes
913 * it to a particular visual. The process may involve the creation
914 * of a new style if the style has already been attached to a
915 * window with a different style and visual.
917 * Since this function may return a new object, you have to use it
918 * in the following way:
919 * <literal>style = gtk_style_attach (style, window)</literal>
921 * Returns: Either @style, or a newly-created #GtkStyle.
922 * If the style is newly created, the style parameter
923 * will be unref'ed, and the new style will have
924 * a reference count belonging to the caller.
926 * Deprecated:3.0: Use gtk_widget_style_attach() instead
929 gtk_style_attach (GtkStyle *style,
932 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
933 g_return_val_if_fail (window != NULL, NULL);
940 * @style: a #GtkStyle
942 * Detaches a style from a window. If the style is not attached
943 * to any windows anymore, it is unrealized. See gtk_style_attach().
945 * Deprecated:3.0: Use #GtkStyleContext instead
948 gtk_style_detach (GtkStyle *style)
950 g_return_if_fail (GTK_IS_STYLE (style));
954 * gtk_style_lookup_icon_set:
955 * @style: a #GtkStyle
956 * @stock_id: an icon name
958 * Looks up @stock_id in the icon factories associated with @style
959 * and the default icon factory, returning an icon set if found,
962 * Return value: (transfer none): icon set of @stock_id
964 * Deprecated:3.0: Use gtk_style_context_lookup_icon_set() instead
967 gtk_style_lookup_icon_set (GtkStyle *style,
968 const char *stock_id)
970 GtkStylePrivate *priv;
972 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
973 g_return_val_if_fail (stock_id != NULL, NULL);
975 priv = GTK_STYLE_GET_PRIVATE (style);
978 return gtk_style_context_lookup_icon_set (priv->context, stock_id);
980 return gtk_icon_factory_lookup_default (stock_id);
984 * gtk_style_lookup_color:
985 * @style: a #GtkStyle
986 * @color_name: the name of the logical color to look up
987 * @color: (out): the #GdkColor to fill in
989 * Looks up @color_name in the style's logical color mappings,
990 * filling in @color and returning %TRUE if found, otherwise
991 * returning %FALSE. Do not cache the found mapping, because
992 * it depends on the #GtkStyle and might change when a theme
995 * Return value: %TRUE if the mapping was found.
999 * Deprecated:3.0: Use gtk_style_context_lookup_color() instead
1002 gtk_style_lookup_color (GtkStyle *style,
1003 const char *color_name,
1006 GtkStylePrivate *priv;
1010 g_return_val_if_fail (GTK_IS_STYLE (style), FALSE);
1011 g_return_val_if_fail (color_name != NULL, FALSE);
1012 g_return_val_if_fail (color != NULL, FALSE);
1014 priv = GTK_STYLE_GET_PRIVATE (style);
1019 result = gtk_style_context_lookup_color (priv->context, color_name, &rgba);
1023 color->red = (guint16) (rgba.red * 65535);
1024 color->green = (guint16) (rgba.green * 65535);
1025 color->blue = (guint16) (rgba.blue * 65535);
1033 * gtk_style_set_background:
1034 * @style: a #GtkStyle
1035 * @window: a #GdkWindow
1036 * @state_type: a state
1038 * Sets the background of @window to the background color or pixmap
1039 * specified by @style for the given state.
1041 * Deprecated:3.0: Use gtk_style_context_set_background() instead
1044 gtk_style_set_background (GtkStyle *style,
1046 GtkStateType state_type)
1048 g_return_if_fail (GTK_IS_STYLE (style));
1049 g_return_if_fail (window != NULL);
1051 GTK_STYLE_GET_CLASS (style)->set_background (style, window, state_type);
1054 /* Default functions */
1056 gtk_style_real_clone (GtkStyle *style)
1058 GtkStylePrivate *priv;
1060 priv = GTK_STYLE_GET_PRIVATE (style);
1062 return g_object_new (G_OBJECT_TYPE (style),
1063 "context", priv->context,
1068 gtk_style_real_copy (GtkStyle *style,
1073 for (i = 0; i < 5; i++)
1075 style->fg[i] = src->fg[i];
1076 style->bg[i] = src->bg[i];
1077 style->text[i] = src->text[i];
1078 style->base[i] = src->base[i];
1080 if (style->background[i])
1081 cairo_pattern_destroy (style->background[i]),
1082 style->background[i] = src->background[i];
1083 if (style->background[i])
1084 cairo_pattern_reference (style->background[i]);
1087 if (style->font_desc)
1088 pango_font_description_free (style->font_desc);
1090 style->font_desc = pango_font_description_copy (src->font_desc);
1092 style->font_desc = NULL;
1094 style->xthickness = src->xthickness;
1095 style->ythickness = src->ythickness;
1097 if (style->rc_style)
1098 g_object_unref (style->rc_style);
1099 style->rc_style = src->rc_style;
1101 g_object_ref (src->rc_style);
1103 g_slist_foreach (style->icon_factories, (GFunc) g_object_unref, NULL);
1104 g_slist_free (style->icon_factories);
1105 style->icon_factories = g_slist_copy (src->icon_factories);
1106 g_slist_foreach (style->icon_factories, (GFunc) g_object_ref, NULL);
1110 gtk_style_real_init_from_rc (GtkStyle *style,
1111 GtkRcStyle *rc_style)
1116 * gtk_style_get_style_property:
1117 * @style: a #GtkStyle
1118 * @widget_type: the #GType of a descendant of #GtkWidget
1119 * @property_name: the name of the style property to get
1120 * @value: a #GValue where the value of the property being
1121 * queried will be stored
1123 * Queries the value of a style property corresponding to a
1124 * widget class is in the given style.
1129 gtk_style_get_style_property (GtkStyle *style,
1131 const gchar *property_name,
1134 GtkStylePrivate *priv;
1135 GtkWidgetClass *klass;
1137 const GValue *peek_value;
1139 klass = g_type_class_ref (widget_type);
1140 pspec = gtk_widget_class_find_style_property (klass, property_name);
1141 g_type_class_unref (klass);
1145 g_warning ("%s: widget class `%s' has no property named `%s'",
1147 g_type_name (widget_type),
1152 priv = GTK_STYLE_GET_PRIVATE (style);
1153 peek_value = _gtk_style_context_peek_style_property (priv->context,
1157 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
1158 g_value_copy (peek_value, value);
1159 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
1160 g_value_transform (peek_value, value);
1162 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
1164 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1165 G_VALUE_TYPE_NAME (value));
1169 * gtk_style_get_valist:
1170 * @style: a #GtkStyle
1171 * @widget_type: the #GType of a descendant of #GtkWidget
1172 * @first_property_name: the name of the first style property to get
1173 * @var_args: a <type>va_list</type> of pairs of property names and
1174 * locations to return the property values, starting with the
1175 * location for @first_property_name.
1177 * Non-vararg variant of gtk_style_get().
1178 * Used primarily by language bindings.
1183 gtk_style_get_valist (GtkStyle *style,
1185 const gchar *first_property_name,
1188 GtkStylePrivate *priv;
1189 const char *property_name;
1190 GtkWidgetClass *klass;
1192 g_return_if_fail (GTK_IS_STYLE (style));
1194 klass = g_type_class_ref (widget_type);
1196 priv = GTK_STYLE_GET_PRIVATE (style);
1197 property_name = first_property_name;
1198 while (property_name)
1201 const GValue *peek_value;
1204 pspec = gtk_widget_class_find_style_property (klass, property_name);
1208 g_warning ("%s: widget class `%s' has no property named `%s'",
1210 g_type_name (widget_type),
1215 peek_value = _gtk_style_context_peek_style_property (priv->context, widget_type,
1217 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
1220 g_warning ("%s: %s", G_STRLOC, error);
1225 property_name = va_arg (var_args, gchar*);
1228 g_type_class_unref (klass);
1233 * @style: a #GtkStyle
1234 * @widget_type: the #GType of a descendant of #GtkWidget
1235 * @first_property_name: the name of the first style property to get
1236 * @...: pairs of property names and locations to
1237 * return the property values, starting with the location for
1238 * @first_property_name, terminated by %NULL.
1240 * Gets the values of a multiple style properties for @widget_type
1246 gtk_style_get (GtkStyle *style,
1248 const gchar *first_property_name,
1253 va_start (var_args, first_property_name);
1254 gtk_style_get_valist (style, widget_type, first_property_name, var_args);
1259 gtk_style_real_realize (GtkStyle *style)
1264 gtk_style_real_unrealize (GtkStyle *style)
1269 gtk_style_real_set_background (GtkStyle *style,
1271 GtkStateType state_type)
1273 gdk_window_set_background_pattern (window, style->background[state_type]);
1277 * gtk_style_render_icon:
1278 * @style: a #GtkStyle
1279 * @source: the #GtkIconSource specifying the icon to render
1280 * @direction: a text direction
1282 * @size: (type int): the size to render the icon at. A size of
1283 * (GtkIconSize)-1 means render at the size of the source and
1285 * @widget: (allow-none): the widget
1286 * @detail: (allow-none): a style detail
1288 * Renders the icon specified by @source at the given @size
1289 * according to the given parameters and returns the result in a
1292 * Return value: (transfer full): a newly-created #GdkPixbuf
1293 * containing the rendered icon
1295 * Deprecated:3.0: Use gtk_render_icon_pixbuf() instead
1298 gtk_style_render_icon (GtkStyle *style,
1299 const GtkIconSource *source,
1300 GtkTextDirection direction,
1304 const gchar *detail)
1308 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1309 g_return_val_if_fail (GTK_STYLE_GET_CLASS (style)->render_icon != NULL, NULL);
1311 pixbuf = GTK_STYLE_GET_CLASS (style)->render_icon (style, source, direction, state,
1312 size, widget, detail);
1314 g_return_val_if_fail (pixbuf != NULL, NULL);
1319 /* Default functions */
1322 * gtk_style_apply_default_background:
1332 * Deprecated:3.0: Use #GtkStyleContext instead
1335 gtk_style_apply_default_background (GtkStyle *style,
1338 GtkStateType state_type,
1346 if (style->background[state_type] == NULL)
1348 GdkWindow *parent = gdk_window_get_parent (window);
1349 int x_offset, y_offset;
1353 gdk_window_get_position (window, &x_offset, &y_offset);
1354 cairo_translate (cr, -x_offset, -y_offset);
1355 gtk_style_apply_default_background (style, cr,
1357 x + x_offset, y + y_offset,
1362 gdk_cairo_set_source_color (cr, &style->bg[state_type]);
1365 cairo_set_source (cr, style->background[state_type]);
1367 cairo_rectangle (cr, x, y, width, height);
1375 gtk_default_render_icon (GtkStyle *style,
1376 const GtkIconSource *source,
1377 GtkTextDirection direction,
1381 const gchar *detail)
1383 GtkStyleContext *context;
1384 GtkStylePrivate *priv;
1385 GtkStateFlags flags = 0;
1389 context = gtk_widget_get_style_context (widget);
1392 priv = GTK_STYLE_GET_PRIVATE (style);
1393 context = priv->context;
1399 gtk_style_context_save (context);
1402 transform_detail_string (detail, context);
1406 case GTK_STATE_PRELIGHT:
1407 flags |= GTK_STATE_FLAG_PRELIGHT;
1409 case GTK_STATE_INSENSITIVE:
1410 flags |= GTK_STATE_FLAG_INSENSITIVE;
1416 gtk_style_context_set_state (context, flags);
1418 pixbuf = gtk_render_icon_pixbuf (context, source, size);
1420 gtk_style_context_restore (context);
1426 _cairo_draw_line (cairo_t *cr,
1435 gdk_cairo_set_source_color (cr, color);
1436 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
1438 cairo_move_to (cr, x1 + 0.5, y1 + 0.5);
1439 cairo_line_to (cr, x2 + 0.5, y2 + 0.5);
1446 transform_detail_string (const gchar *detail,
1447 GtkStyleContext *context)
1452 if (strcmp (detail, "arrow") == 0)
1453 gtk_style_context_add_class (context, "arrow");
1454 else if (strcmp (detail, "button") == 0)
1455 gtk_style_context_add_class (context, "button");
1456 else if (strcmp (detail, "buttondefault") == 0)
1458 gtk_style_context_add_class (context, "button");
1459 gtk_style_context_add_class (context, "default");
1461 else if (strcmp (detail, "calendar") == 0)
1462 gtk_style_context_add_class (context, "calendar");
1463 else if (strcmp (detail, "cellcheck") == 0)
1465 gtk_style_context_add_class (context, "cell");
1466 gtk_style_context_add_class (context, "check");
1468 else if (strcmp (detail, "cellradio") == 0)
1470 gtk_style_context_add_class (context, "cell");
1471 gtk_style_context_add_class (context, "radio");
1473 else if (strcmp (detail, "checkbutton") == 0)
1474 gtk_style_context_add_class (context, "check");
1475 else if (strcmp (detail, "check") == 0)
1477 gtk_style_context_add_class (context, "check");
1478 gtk_style_context_add_class (context, "menu");
1480 else if (strcmp (detail, "radiobutton") == 0)
1482 gtk_style_context_add_class (context, "radio");
1484 else if (strcmp (detail, "option") == 0)
1486 gtk_style_context_add_class (context, "radio");
1487 gtk_style_context_add_class (context, "menu");
1489 else if (strcmp (detail, "entry") == 0 ||
1490 strcmp (detail, "entry_bg") == 0)
1491 gtk_style_context_add_class (context, "entry");
1492 else if (strcmp (detail, "expander") == 0)
1493 gtk_style_context_add_class (context, "expander");
1494 else if (strcmp (detail, "tooltip") == 0)
1495 gtk_style_context_add_class (context, "tooltip");
1496 else if (strcmp (detail, "frame") == 0)
1497 gtk_style_context_add_class (context, "frame");
1498 else if (strcmp (detail, "scrolled_window") == 0)
1499 gtk_style_context_add_class (context, "scrolled-window");
1500 else if (strcmp (detail, "viewport") == 0 ||
1501 strcmp (detail, "viewportbin") == 0)
1502 gtk_style_context_add_class (context, "viewport");
1503 else if (strncmp (detail, "trough", 6) == 0)
1504 gtk_style_context_add_class (context, "trough");
1505 else if (strcmp (detail, "spinbutton") == 0)
1506 gtk_style_context_add_class (context, "spinbutton");
1507 else if (strcmp (detail, "spinbutton_up") == 0)
1509 gtk_style_context_add_class (context, "spinbutton");
1510 gtk_style_context_add_class (context, "button");
1511 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
1513 else if (strcmp (detail, "spinbutton_down") == 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_TOP);
1519 else if ((detail[0] == 'h' || detail[0] == 'v') &&
1520 strncmp (&detail[1], "scrollbar_", 10) == 0)
1522 gtk_style_context_add_class (context, "button");
1523 gtk_style_context_add_class (context, "scrollbar");
1525 else if (strcmp (detail, "slider") == 0)
1527 gtk_style_context_add_class (context, "slider");
1528 gtk_style_context_add_class (context, "scrollbar");
1530 else if (strcmp (detail, "vscale") == 0 ||
1531 strcmp (detail, "hscale") == 0)
1533 gtk_style_context_add_class (context, "slider");
1534 gtk_style_context_add_class (context, "scale");
1536 else if (strcmp (detail, "menuitem") == 0)
1538 gtk_style_context_add_class (context, "menuitem");
1539 gtk_style_context_add_class (context, "menu");
1541 else if (strcmp (detail, "menu") == 0)
1543 gtk_style_context_add_class (context, "popup");
1544 gtk_style_context_add_class (context, "menu");
1546 else if (strcmp (detail, "accellabel") == 0)
1547 gtk_style_context_add_class (context, "accelerator");
1548 else if (strcmp (detail, "menubar") == 0)
1549 gtk_style_context_add_class (context, "menubar");
1550 else if (strcmp (detail, "base") == 0)
1551 gtk_style_context_add_class (context, "background");
1552 else if (strcmp (detail, "bar") == 0 ||
1553 strcmp (detail, "progressbar") == 0)
1554 gtk_style_context_add_class (context, "progressbar");
1555 else if (strcmp (detail, "toolbar") == 0)
1556 gtk_style_context_add_class (context, "toolbar");
1557 else if (strcmp (detail, "handlebox_bin") == 0)
1558 gtk_style_context_add_class (context, "dock");
1559 else if (strcmp (detail, "notebook") == 0)
1560 gtk_style_context_add_class (context, "notebook");
1561 else if (strcmp (detail, "tab") == 0)
1563 gtk_style_context_add_class (context, "notebook");
1564 gtk_style_context_add_region (context, GTK_STYLE_REGION_TAB, 0);
1566 else if (g_str_has_prefix (detail, "cell"))
1568 GtkRegionFlags row, col;
1569 gboolean ruled = FALSE;
1573 tokens = g_strsplit (detail, "_", -1);
1579 if (strcmp (tokens[i], "even") == 0)
1580 row |= GTK_REGION_EVEN;
1581 else if (strcmp (tokens[i], "odd") == 0)
1582 row |= GTK_REGION_ODD;
1583 else if (strcmp (tokens[i], "start") == 0)
1584 col |= GTK_REGION_FIRST;
1585 else if (strcmp (tokens[i], "end") == 0)
1586 col |= GTK_REGION_LAST;
1587 else if (strcmp (tokens[i], "ruled") == 0)
1589 else if (strcmp (tokens[i], "sorted") == 0)
1590 col |= GTK_REGION_SORTED;
1596 row &= ~(GTK_REGION_EVEN | GTK_REGION_ODD);
1598 gtk_style_context_add_class (context, "cell");
1599 gtk_style_context_add_region (context, "row", row);
1600 gtk_style_context_add_region (context, "column", col);
1602 g_strfreev (tokens);
1607 gtk_default_draw_hline (GtkStyle *style,
1609 GtkStateType state_type,
1611 const gchar *detail,
1616 GtkStyleContext *context;
1617 GtkStylePrivate *priv;
1620 context = gtk_widget_get_style_context (widget);
1623 priv = GTK_STYLE_GET_PRIVATE (style);
1624 context = priv->context;
1627 gtk_style_context_save (context);
1630 transform_detail_string (detail, context);
1634 gtk_render_line (context, cr,
1639 gtk_style_context_restore (context);
1644 gtk_default_draw_vline (GtkStyle *style,
1646 GtkStateType state_type,
1648 const gchar *detail,
1653 GtkStyleContext *context;
1654 GtkStylePrivate *priv;
1657 context = gtk_widget_get_style_context (widget);
1660 priv = GTK_STYLE_GET_PRIVATE (style);
1661 context = priv->context;
1664 gtk_style_context_save (context);
1667 transform_detail_string (detail, context);
1671 gtk_render_line (context, cr,
1675 gtk_style_context_restore (context);
1679 gtk_default_draw_shadow (GtkStyle *style,
1681 GtkStateType state_type,
1682 GtkShadowType shadow_type,
1684 const gchar *detail,
1690 GtkStyleContext *context;
1691 GtkStylePrivate *priv;
1693 if (shadow_type == GTK_SHADOW_NONE)
1697 context = gtk_widget_get_style_context (widget);
1700 priv = GTK_STYLE_GET_PRIVATE (style);
1701 context = priv->context;
1704 gtk_style_context_save (context);
1707 transform_detail_string (detail, context);
1711 gtk_render_frame (context, cr,
1718 gtk_style_context_restore (context);
1722 draw_arrow (cairo_t *cr,
1724 GtkArrowType arrow_type,
1730 gdk_cairo_set_source_color (cr, color);
1733 if (arrow_type == GTK_ARROW_DOWN)
1735 cairo_move_to (cr, x, y);
1736 cairo_line_to (cr, x + width, y);
1737 cairo_line_to (cr, x + width / 2., y + height);
1739 else if (arrow_type == GTK_ARROW_UP)
1741 cairo_move_to (cr, x, y + height);
1742 cairo_line_to (cr, x + width / 2., y);
1743 cairo_line_to (cr, x + width, y + height);
1745 else if (arrow_type == GTK_ARROW_LEFT)
1747 cairo_move_to (cr, x + width, y);
1748 cairo_line_to (cr, x + width, y + height);
1749 cairo_line_to (cr, x, y + height / 2.);
1751 else if (arrow_type == GTK_ARROW_RIGHT)
1753 cairo_move_to (cr, x, y);
1754 cairo_line_to (cr, x + width, y + height / 2.);
1755 cairo_line_to (cr, x, y + height);
1758 cairo_close_path (cr);
1765 gtk_default_draw_arrow (GtkStyle *style,
1768 GtkShadowType shadow,
1770 const gchar *detail,
1771 GtkArrowType arrow_type,
1778 GtkStyleContext *context;
1779 GtkStylePrivate *priv;
1780 GtkStateFlags flags = 0;
1781 gdouble angle, size;
1783 if (arrow_type == GTK_ARROW_NONE)
1787 context = gtk_widget_get_style_context (widget);
1790 priv = GTK_STYLE_GET_PRIVATE (style);
1791 context = priv->context;
1794 gtk_style_context_save (context);
1797 transform_detail_string (detail, context);
1805 case GTK_ARROW_RIGHT:
1809 case GTK_ARROW_DOWN:
1813 case GTK_ARROW_LEFT:
1814 angle = 3 * (G_PI / 2);
1818 g_assert_not_reached ();
1823 case GTK_STATE_PRELIGHT:
1824 flags |= GTK_STATE_FLAG_PRELIGHT;
1826 case GTK_STATE_SELECTED:
1827 flags |= GTK_STATE_FLAG_SELECTED;
1829 case GTK_STATE_INSENSITIVE:
1830 flags |= GTK_STATE_FLAG_INSENSITIVE;
1832 case GTK_STATE_ACTIVE:
1833 flags |= GTK_STATE_FLAG_ACTIVE;
1839 gtk_style_context_set_state (context, flags);
1843 gtk_render_arrow (context,
1850 gtk_style_context_restore (context);
1854 gtk_default_draw_diamond (GtkStyle *style,
1856 GtkStateType state_type,
1857 GtkShadowType shadow_type,
1859 const gchar *detail,
1867 GdkColor *outer_nw = NULL;
1868 GdkColor *outer_ne = NULL;
1869 GdkColor *outer_sw = NULL;
1870 GdkColor *outer_se = NULL;
1871 GdkColor *middle_nw = NULL;
1872 GdkColor *middle_ne = NULL;
1873 GdkColor *middle_sw = NULL;
1874 GdkColor *middle_se = NULL;
1875 GdkColor *inner_nw = NULL;
1876 GdkColor *inner_ne = NULL;
1877 GdkColor *inner_sw = NULL;
1878 GdkColor *inner_se = NULL;
1880 half_width = width / 2;
1881 half_height = height / 2;
1883 switch (shadow_type)
1886 inner_sw = inner_se = &style->bg[state_type];
1887 middle_sw = middle_se = &style->light[state_type];
1888 outer_sw = outer_se = &style->light[state_type];
1889 inner_nw = inner_ne = &style->black;
1890 middle_nw = middle_ne = &style->dark[state_type];
1891 outer_nw = outer_ne = &style->dark[state_type];
1894 case GTK_SHADOW_OUT:
1895 inner_sw = inner_se = &style->dark[state_type];
1896 middle_sw = middle_se = &style->dark[state_type];
1897 outer_sw = outer_se = &style->black;
1898 inner_nw = inner_ne = &style->bg[state_type];
1899 middle_nw = middle_ne = &style->light[state_type];
1900 outer_nw = outer_ne = &style->light[state_type];
1903 case GTK_SHADOW_ETCHED_IN:
1904 inner_sw = inner_se = &style->bg[state_type];
1905 middle_sw = middle_se = &style->dark[state_type];
1906 outer_sw = outer_se = &style->light[state_type];
1907 inner_nw = inner_ne = &style->bg[state_type];
1908 middle_nw = middle_ne = &style->light[state_type];
1909 outer_nw = outer_ne = &style->dark[state_type];
1912 case GTK_SHADOW_ETCHED_OUT:
1913 inner_sw = inner_se = &style->bg[state_type];
1914 middle_sw = middle_se = &style->light[state_type];
1915 outer_sw = outer_se = &style->dark[state_type];
1916 inner_nw = inner_ne = &style->bg[state_type];
1917 middle_nw = middle_ne = &style->dark[state_type];
1918 outer_nw = outer_ne = &style->light[state_type];
1928 _cairo_draw_line (cr, inner_sw,
1929 x + 2, y + half_height,
1930 x + half_width, y + height - 2);
1931 _cairo_draw_line (cr, inner_se,
1932 x + half_width, y + height - 2,
1933 x + width - 2, y + half_height);
1934 _cairo_draw_line (cr, middle_sw,
1935 x + 1, y + half_height,
1936 x + half_width, y + height - 1);
1937 _cairo_draw_line (cr, middle_se,
1938 x + half_width, y + height - 1,
1939 x + width - 1, y + half_height);
1940 _cairo_draw_line (cr, outer_sw,
1942 x + half_width, y + height);
1943 _cairo_draw_line (cr, outer_se,
1944 x + half_width, y + height,
1945 x + width, y + half_height);
1947 _cairo_draw_line (cr, inner_nw,
1948 x + 2, y + half_height,
1949 x + half_width, y + 2);
1950 _cairo_draw_line (cr, inner_ne,
1951 x + half_width, y + 2,
1952 x + width - 2, y + half_height);
1953 _cairo_draw_line (cr, middle_nw,
1954 x + 1, y + half_height,
1955 x + half_width, y + 1);
1956 _cairo_draw_line (cr, middle_ne,
1957 x + half_width, y + 1,
1958 x + width - 1, y + half_height);
1959 _cairo_draw_line (cr, outer_nw,
1962 _cairo_draw_line (cr, outer_ne,
1964 x + width, y + half_height);
1969 option_menu_get_props (GtkWidget *widget,
1970 GtkRequisition *indicator_size,
1971 GtkBorder *indicator_spacing)
1973 GtkRequisition *tmp_size = NULL;
1974 GtkBorder *tmp_spacing = NULL;
1978 *indicator_size = *tmp_size;
1979 gtk_requisition_free (tmp_size);
1982 *indicator_size = default_option_indicator_size;
1986 *indicator_spacing = *tmp_spacing;
1987 gtk_border_free (tmp_spacing);
1990 *indicator_spacing = default_option_indicator_spacing;
1994 gtk_default_draw_box (GtkStyle *style,
1996 GtkStateType state_type,
1997 GtkShadowType shadow_type,
1999 const gchar *detail,
2005 GtkStyleContext *context;
2006 GtkStylePrivate *priv;
2007 GtkStateFlags flags = 0;
2010 context = gtk_widget_get_style_context (widget);
2013 priv = GTK_STYLE_GET_PRIVATE (style);
2014 context = priv->context;
2017 gtk_style_context_save (context);
2020 transform_detail_string (detail, context);
2024 case GTK_STATE_ACTIVE:
2025 flags |= GTK_STATE_FLAG_ACTIVE;
2027 case GTK_STATE_PRELIGHT:
2028 flags |= GTK_STATE_FLAG_PRELIGHT;
2030 case GTK_STATE_SELECTED:
2031 flags |= GTK_STATE_FLAG_SELECTED;
2033 case GTK_STATE_INSENSITIVE:
2034 flags |= GTK_STATE_FLAG_INSENSITIVE;
2040 if (shadow_type == GTK_SHADOW_IN)
2041 flags |= GTK_STATE_FLAG_ACTIVE;
2043 gtk_style_context_set_state (context, flags);
2047 if (gtk_style_context_has_class (context, GTK_STYLE_CLASS_PROGRESSBAR))
2048 gtk_render_activity (context, cr, x, y, width, height);
2051 gtk_render_background (context, cr, x, y, width, height);
2053 if (shadow_type != GTK_SHADOW_NONE)
2054 gtk_render_frame (context, cr, x, y, width, height);
2058 gtk_style_context_restore (context);
2062 gtk_default_draw_flat_box (GtkStyle *style,
2064 GtkStateType state_type,
2065 GtkShadowType shadow_type,
2067 const gchar *detail,
2073 GtkStyleContext *context;
2074 GtkStylePrivate *priv;
2075 GtkStateFlags flags = 0;
2078 context = gtk_widget_get_style_context (widget);
2081 priv = GTK_STYLE_GET_PRIVATE (style);
2082 context = priv->context;
2085 gtk_style_context_save (context);
2088 transform_detail_string (detail, context);
2092 case GTK_STATE_PRELIGHT:
2093 flags |= GTK_STATE_FLAG_PRELIGHT;
2095 case GTK_STATE_SELECTED:
2096 flags |= GTK_STATE_FLAG_SELECTED;
2098 case GTK_STATE_INSENSITIVE:
2099 flags |= GTK_STATE_FLAG_INSENSITIVE;
2101 case GTK_STATE_ACTIVE:
2102 flags |= GTK_STATE_FLAG_ACTIVE;
2104 case GTK_STATE_FOCUSED:
2105 flags |= GTK_STATE_FLAG_FOCUSED;
2111 gtk_style_context_set_state (context, flags);
2115 gtk_render_background (context, cr,
2122 gtk_style_context_restore (context);
2126 gtk_default_draw_check (GtkStyle *style,
2128 GtkStateType state_type,
2129 GtkShadowType shadow_type,
2131 const gchar *detail,
2137 GtkStyleContext *context;
2138 GtkStylePrivate *priv;
2139 GtkStateFlags flags = 0;
2142 context = gtk_widget_get_style_context (widget);
2145 priv = GTK_STYLE_GET_PRIVATE (style);
2146 context = priv->context;
2149 gtk_style_context_save (context);
2152 transform_detail_string (detail, context);
2156 case GTK_STATE_PRELIGHT:
2157 flags |= GTK_STATE_FLAG_PRELIGHT;
2159 case GTK_STATE_SELECTED:
2160 flags |= GTK_STATE_FLAG_SELECTED;
2162 case GTK_STATE_INSENSITIVE:
2163 flags |= GTK_STATE_FLAG_INSENSITIVE;
2169 if (shadow_type == GTK_SHADOW_IN)
2170 flags |= GTK_STATE_FLAG_ACTIVE;
2171 else if (shadow_type == GTK_SHADOW_ETCHED_IN)
2172 flags |= GTK_STATE_FLAG_INCONSISTENT;
2174 gtk_style_context_set_state (context, flags);
2178 gtk_render_check (context,
2183 gtk_style_context_restore (context);
2187 gtk_default_draw_option (GtkStyle *style,
2189 GtkStateType state_type,
2190 GtkShadowType shadow_type,
2192 const gchar *detail,
2198 GtkStyleContext *context;
2199 GtkStylePrivate *priv;
2200 GtkStateFlags flags = 0;
2203 context = gtk_widget_get_style_context (widget);
2206 priv = GTK_STYLE_GET_PRIVATE (style);
2207 context = priv->context;
2210 gtk_style_context_save (context);
2213 transform_detail_string (detail, context);
2217 case GTK_STATE_PRELIGHT:
2218 flags |= GTK_STATE_FLAG_PRELIGHT;
2220 case GTK_STATE_SELECTED:
2221 flags |= GTK_STATE_FLAG_SELECTED;
2223 case GTK_STATE_INSENSITIVE:
2224 flags |= GTK_STATE_FLAG_INSENSITIVE;
2230 if (shadow_type == GTK_SHADOW_IN)
2231 flags |= GTK_STATE_FLAG_ACTIVE;
2232 else if (shadow_type == GTK_SHADOW_ETCHED_IN)
2233 flags |= GTK_STATE_FLAG_INCONSISTENT;
2235 gtk_style_context_set_state (context, flags);
2238 gtk_render_option (context, cr,
2245 gtk_style_context_restore (context);
2249 gtk_default_draw_tab (GtkStyle *style,
2251 GtkStateType state_type,
2252 GtkShadowType shadow_type,
2254 const gchar *detail,
2260 #define ARROW_SPACE 4
2262 GtkRequisition indicator_size;
2263 GtkBorder indicator_spacing;
2266 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
2268 indicator_size.width += (indicator_size.width % 2) - 1;
2269 arrow_height = indicator_size.width / 2 + 1;
2271 x += (width - indicator_size.width) / 2;
2272 y += (height - (2 * arrow_height + ARROW_SPACE)) / 2;
2274 if (state_type == GTK_STATE_INSENSITIVE)
2276 draw_arrow (cr, &style->white,
2277 GTK_ARROW_UP, x + 1, y + 1,
2278 indicator_size.width, arrow_height);
2280 draw_arrow (cr, &style->white,
2281 GTK_ARROW_DOWN, x + 1, y + arrow_height + ARROW_SPACE + 1,
2282 indicator_size.width, arrow_height);
2285 draw_arrow (cr, &style->fg[state_type],
2287 indicator_size.width, arrow_height);
2290 draw_arrow (cr, &style->fg[state_type],
2291 GTK_ARROW_DOWN, x, y + arrow_height + ARROW_SPACE,
2292 indicator_size.width, arrow_height);
2296 gtk_default_draw_shadow_gap (GtkStyle *style,
2298 GtkStateType state_type,
2299 GtkShadowType shadow_type,
2301 const gchar *detail,
2306 GtkPositionType gap_side,
2310 GtkStyleContext *context;
2311 GtkStylePrivate *priv;
2312 GtkStateFlags flags = 0;
2314 if (shadow_type == GTK_SHADOW_NONE)
2318 context = gtk_widget_get_style_context (widget);
2321 priv = GTK_STYLE_GET_PRIVATE (style);
2322 context = priv->context;
2325 gtk_style_context_save (context);
2328 transform_detail_string (detail, context);
2332 case GTK_STATE_ACTIVE:
2333 flags |= GTK_STATE_FLAG_ACTIVE;
2335 case GTK_STATE_PRELIGHT:
2336 flags |= GTK_STATE_FLAG_PRELIGHT;
2338 case GTK_STATE_SELECTED:
2339 flags |= GTK_STATE_FLAG_SELECTED;
2341 case GTK_STATE_INSENSITIVE:
2342 flags |= GTK_STATE_FLAG_INSENSITIVE;
2348 gtk_style_context_set_state (context, flags);
2351 gtk_render_frame_gap (context, cr,
2358 (gdouble) gap_x + gap_width);
2361 gtk_style_context_restore (context);
2365 gtk_default_draw_box_gap (GtkStyle *style,
2367 GtkStateType state_type,
2368 GtkShadowType shadow_type,
2370 const gchar *detail,
2375 GtkPositionType gap_side,
2379 GtkStyleContext *context;
2380 GtkStylePrivate *priv;
2381 GtkStateFlags flags = 0;
2384 context = gtk_widget_get_style_context (widget);
2387 priv = GTK_STYLE_GET_PRIVATE (style);
2388 context = priv->context;
2391 gtk_style_context_save (context);
2394 transform_detail_string (detail, context);
2398 case GTK_STATE_ACTIVE:
2399 flags |= GTK_STATE_FLAG_ACTIVE;
2401 case GTK_STATE_PRELIGHT:
2402 flags |= GTK_STATE_FLAG_PRELIGHT;
2404 case GTK_STATE_SELECTED:
2405 flags |= GTK_STATE_FLAG_SELECTED;
2407 case GTK_STATE_INSENSITIVE:
2408 flags |= GTK_STATE_FLAG_INSENSITIVE;
2414 gtk_style_context_set_state (context, flags);
2417 gtk_render_background (context, cr,
2424 if (shadow_type != GTK_SHADOW_NONE)
2425 gtk_render_frame_gap (context, cr,
2432 (gdouble) gap_x + gap_width);
2435 gtk_style_context_restore (context);
2439 gtk_default_draw_extension (GtkStyle *style,
2441 GtkStateType state_type,
2442 GtkShadowType shadow_type,
2444 const gchar *detail,
2449 GtkPositionType gap_side)
2451 GtkStyleContext *context;
2452 GtkStylePrivate *priv;
2453 GtkStateFlags flags = 0;
2456 context = gtk_widget_get_style_context (widget);
2459 priv = GTK_STYLE_GET_PRIVATE (style);
2460 context = priv->context;
2463 gtk_style_context_save (context);
2466 transform_detail_string (detail, context);
2470 case GTK_STATE_ACTIVE:
2471 flags |= GTK_STATE_FLAG_ACTIVE;
2473 case GTK_STATE_PRELIGHT:
2474 flags |= GTK_STATE_FLAG_PRELIGHT;
2476 case GTK_STATE_SELECTED:
2477 flags |= GTK_STATE_FLAG_SELECTED;
2479 case GTK_STATE_INSENSITIVE:
2480 flags |= GTK_STATE_FLAG_INSENSITIVE;
2486 gtk_style_context_set_state (context, flags);
2490 gtk_render_extension (context, cr,
2498 gtk_style_context_restore (context);
2502 gtk_default_draw_focus (GtkStyle *style,
2504 GtkStateType state_type,
2506 const gchar *detail,
2512 GtkStyleContext *context;
2513 GtkStylePrivate *priv;
2516 context = gtk_widget_get_style_context (widget);
2519 priv = GTK_STYLE_GET_PRIVATE (style);
2520 context = priv->context;
2523 gtk_style_context_save (context);
2526 transform_detail_string (detail, context);
2530 gtk_render_focus (context, cr,
2537 gtk_style_context_restore (context);
2541 gtk_default_draw_slider (GtkStyle *style,
2543 GtkStateType state_type,
2544 GtkShadowType shadow_type,
2546 const gchar *detail,
2551 GtkOrientation orientation)
2553 GtkStyleContext *context;
2554 GtkStylePrivate *priv;
2555 GtkStateFlags flags = 0;
2558 context = gtk_widget_get_style_context (widget);
2561 priv = GTK_STYLE_GET_PRIVATE (style);
2562 context = priv->context;
2565 gtk_style_context_save (context);
2568 transform_detail_string (detail, context);
2572 case GTK_STATE_PRELIGHT:
2573 flags |= GTK_STATE_FLAG_PRELIGHT;
2575 case GTK_STATE_SELECTED:
2576 flags |= GTK_STATE_FLAG_SELECTED;
2578 case GTK_STATE_INSENSITIVE:
2579 flags |= GTK_STATE_FLAG_INSENSITIVE;
2585 gtk_style_context_set_state (context, flags);
2589 gtk_render_slider (context, cr, x, y, width, height, orientation);
2592 gtk_style_context_restore (context);
2596 gtk_default_draw_handle (GtkStyle *style,
2598 GtkStateType state_type,
2599 GtkShadowType shadow_type,
2601 const gchar *detail,
2606 GtkOrientation orientation)
2608 GtkStyleContext *context;
2609 GtkStylePrivate *priv;
2610 GtkStateFlags flags = 0;
2613 context = gtk_widget_get_style_context (widget);
2616 priv = GTK_STYLE_GET_PRIVATE (style);
2617 context = priv->context;
2620 gtk_style_context_save (context);
2623 transform_detail_string (detail, context);
2627 case GTK_STATE_PRELIGHT:
2628 flags |= GTK_STATE_FLAG_PRELIGHT;
2630 case GTK_STATE_SELECTED:
2631 flags |= GTK_STATE_FLAG_SELECTED;
2633 case GTK_STATE_INSENSITIVE:
2634 flags |= GTK_STATE_FLAG_INSENSITIVE;
2640 gtk_style_context_set_state (context, flags);
2644 gtk_render_handle (context, cr,
2651 gtk_style_context_restore (context);
2655 gtk_default_draw_expander (GtkStyle *style,
2657 GtkStateType state_type,
2659 const gchar *detail,
2662 GtkExpanderStyle expander_style)
2664 GtkStyleContext *context;
2665 GtkStylePrivate *priv;
2666 GtkStateFlags flags = 0;
2670 context = gtk_widget_get_style_context (widget);
2673 priv = GTK_STYLE_GET_PRIVATE (style);
2674 context = priv->context;
2677 gtk_style_context_save (context);
2680 transform_detail_string (detail, context);
2682 gtk_style_context_add_class (context, "expander");
2686 case GTK_STATE_PRELIGHT:
2687 flags |= GTK_STATE_FLAG_PRELIGHT;
2689 case GTK_STATE_SELECTED:
2690 flags |= GTK_STATE_FLAG_SELECTED;
2692 case GTK_STATE_INSENSITIVE:
2693 flags |= GTK_STATE_FLAG_INSENSITIVE;
2700 gtk_widget_class_find_style_property (GTK_WIDGET_GET_CLASS (widget),
2702 gtk_widget_style_get (widget, "expander-size", &size, NULL);
2706 if (expander_style == GTK_EXPANDER_EXPANDED)
2707 flags |= GTK_STATE_FLAG_ACTIVE;
2709 gtk_style_context_set_state (context, flags);
2713 gtk_render_expander (context, cr,
2714 (gdouble) x - (size / 2),
2715 (gdouble) y - (size / 2),
2720 gtk_style_context_restore (context);
2724 gtk_default_draw_layout (GtkStyle *style,
2726 GtkStateType state_type,
2729 const gchar *detail,
2732 PangoLayout *layout)
2734 GtkStyleContext *context;
2735 GtkStylePrivate *priv;
2736 GtkStateFlags flags = 0;
2739 context = gtk_widget_get_style_context (widget);
2742 priv = GTK_STYLE_GET_PRIVATE (style);
2743 context = priv->context;
2746 gtk_style_context_save (context);
2749 transform_detail_string (detail, context);
2753 case GTK_STATE_PRELIGHT:
2754 flags |= GTK_STATE_FLAG_PRELIGHT;
2756 case GTK_STATE_SELECTED:
2757 flags |= GTK_STATE_FLAG_SELECTED;
2759 case GTK_STATE_INSENSITIVE:
2760 flags |= GTK_STATE_FLAG_INSENSITIVE;
2766 gtk_style_context_set_state (context, flags);
2770 gtk_render_layout (context, cr,
2776 gtk_style_context_restore (context);
2780 gtk_default_draw_resize_grip (GtkStyle *style,
2782 GtkStateType state_type,
2784 const gchar *detail,
2791 GtkStyleContext *context;
2792 GtkStylePrivate *priv;
2793 GtkStateFlags flags = 0;
2794 GtkJunctionSides sides = 0;
2797 context = gtk_widget_get_style_context (widget);
2800 priv = GTK_STYLE_GET_PRIVATE (style);
2801 context = priv->context;
2804 gtk_style_context_save (context);
2807 transform_detail_string (detail, context);
2809 gtk_style_context_add_class (context, "grip");
2813 case GTK_STATE_PRELIGHT:
2814 flags |= GTK_STATE_FLAG_PRELIGHT;
2816 case GTK_STATE_SELECTED:
2817 flags |= GTK_STATE_FLAG_SELECTED;
2819 case GTK_STATE_INSENSITIVE:
2820 flags |= GTK_STATE_FLAG_INSENSITIVE;
2826 gtk_style_context_set_state (context, flags);
2830 case GDK_WINDOW_EDGE_NORTH_WEST:
2831 sides = GTK_JUNCTION_CORNER_TOPLEFT;
2833 case GDK_WINDOW_EDGE_NORTH:
2834 sides = GTK_JUNCTION_TOP;
2836 case GDK_WINDOW_EDGE_NORTH_EAST:
2837 sides = GTK_JUNCTION_CORNER_TOPRIGHT;
2839 case GDK_WINDOW_EDGE_WEST:
2840 sides = GTK_JUNCTION_LEFT;
2842 case GDK_WINDOW_EDGE_EAST:
2843 sides = GTK_JUNCTION_RIGHT;
2845 case GDK_WINDOW_EDGE_SOUTH_WEST:
2846 sides = GTK_JUNCTION_CORNER_BOTTOMLEFT;
2848 case GDK_WINDOW_EDGE_SOUTH:
2849 sides = GTK_JUNCTION_BOTTOM;
2851 case GDK_WINDOW_EDGE_SOUTH_EAST:
2852 sides = GTK_JUNCTION_CORNER_BOTTOMRIGHT;
2856 gtk_style_context_set_junction_sides (context, sides);
2860 gtk_render_handle (context, cr,
2867 gtk_style_context_restore (context);
2871 gtk_default_draw_spinner (GtkStyle *style,
2873 GtkStateType state_type,
2875 const gchar *detail,
2891 real_step = step % num_steps;
2893 /* set a clip region for the expose event */
2894 cairo_rectangle (cr, x, y, width, height);
2897 cairo_translate (cr, x, y);
2899 /* draw clip region */
2900 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
2902 color = &style->fg[state_type];
2905 radius = MIN (width / 2, height / 2);
2906 half = num_steps / 2;
2908 for (i = 0; i < num_steps; i++)
2910 gint inset = 0.7 * radius;
2912 /* transparency is a function of time and intial value */
2913 gdouble t = (gdouble) ((i + num_steps - real_step)
2914 % num_steps) / num_steps;
2918 cairo_set_source_rgba (cr,
2919 color->red / 65535.,
2920 color->green / 65535.,
2921 color->blue / 65535.,
2924 cairo_set_line_width (cr, 2.0);
2926 dx + (radius - inset) * cos (i * G_PI / half),
2927 dy + (radius - inset) * sin (i * G_PI / half));
2929 dx + radius * cos (i * G_PI / half),
2930 dy + radius * sin (i * G_PI / half));
2938 _gtk_style_shade (const GdkColor *a,
2946 red = (gdouble) a->red / 65535.0;
2947 green = (gdouble) a->green / 65535.0;
2948 blue = (gdouble) a->blue / 65535.0;
2950 rgb_to_hls (&red, &green, &blue);
2955 else if (green < 0.0)
2961 else if (blue < 0.0)
2964 hls_to_rgb (&red, &green, &blue);
2966 b->red = red * 65535.0;
2967 b->green = green * 65535.0;
2968 b->blue = blue * 65535.0;
2972 rgb_to_hls (gdouble *r,
3013 l = (max + min) / 2;
3020 s = (max - min) / (max + min);
3022 s = (max - min) / (2 - max - min);
3026 h = (green - blue) / delta;
3027 else if (green == max)
3028 h = 2 + (blue - red) / delta;
3029 else if (blue == max)
3030 h = 4 + (red - green) / delta;
3043 hls_to_rgb (gdouble *h,
3056 if (lightness <= 0.5)
3057 m2 = lightness * (1 + saturation);
3059 m2 = lightness + saturation - lightness * saturation;
3060 m1 = 2 * lightness - m2;
3062 if (saturation == 0)
3077 r = m1 + (m2 - m1) * hue / 60;
3081 r = m1 + (m2 - m1) * (240 - hue) / 60;
3092 g = m1 + (m2 - m1) * hue / 60;
3096 g = m1 + (m2 - m1) * (240 - hue) / 60;
3107 b = m1 + (m2 - m1) * hue / 60;
3111 b = m1 + (m2 - m1) * (240 - hue) / 60;
3124 * @style: a #GtkStyle
3126 * @state_type: a state
3127 * @widget: (allow-none): the widget
3128 * @detail: (allow-none): a style detail
3129 * @x1: the starting x coordinate
3130 * @x2: the ending x coordinate
3131 * @y: the y coordinate
3133 * Draws a horizontal line from (@x1, @y) to (@x2, @y) in @cr
3134 * using the given style and state.
3136 * Deprecated:3.0: Use gtk_render_line() instead
3139 gtk_paint_hline (GtkStyle *style,
3141 GtkStateType state_type,
3143 const gchar *detail,
3148 g_return_if_fail (GTK_IS_STYLE (style));
3149 g_return_if_fail (cr != NULL);
3150 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
3154 GTK_STYLE_GET_CLASS (style)->draw_hline (style, cr, state_type,
3163 * @style: a #GtkStyle
3165 * @state_type: a state
3166 * @widget: (allow-none): the widget
3167 * @detail: (allow-none): a style detail
3168 * @y1_: the starting y coordinate
3169 * @y2_: the ending y coordinate
3170 * @x: the x coordinate
3172 * Draws a vertical line from (@x, @y1_) to (@x, @y2_) in @cr
3173 * using the given style and state.
3175 * Deprecated:3.0: Use gtk_render_line() instead
3178 gtk_paint_vline (GtkStyle *style,
3180 GtkStateType state_type,
3182 const gchar *detail,
3187 g_return_if_fail (GTK_IS_STYLE (style));
3188 g_return_if_fail (cr != NULL);
3189 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
3193 GTK_STYLE_GET_CLASS (style)->draw_vline (style, cr, state_type,
3202 * @style: a #GtkStyle
3204 * @state_type: a state
3205 * @shadow_type: type of shadow to draw
3206 * @widget: (allow-none): the widget
3207 * @detail: (allow-none): a style detail
3208 * @x: x origin of the rectangle
3209 * @y: y origin of the rectangle
3210 * @width: width of the rectangle
3211 * @height: width of the rectangle
3213 * Draws a shadow around the given rectangle in @cr
3214 * using the given style and state and shadow type.
3216 * Deprecated:3.0: Use gtk_render_frame() instead
3219 gtk_paint_shadow (GtkStyle *style,
3221 GtkStateType state_type,
3222 GtkShadowType shadow_type,
3224 const gchar *detail,
3230 g_return_if_fail (GTK_IS_STYLE (style));
3231 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
3232 g_return_if_fail (cr != NULL);
3233 g_return_if_fail (width >= 0);
3234 g_return_if_fail (height >= 0);
3238 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, cr, state_type, shadow_type,
3240 x, y, width, height);
3247 * @style: a #GtkStyle
3249 * @state_type: a state
3250 * @shadow_type: the type of shadow to draw
3251 * @widget: (allow-none): the widget
3252 * @detail: (allow-none): a style detail
3253 * @arrow_type: the type of arrow to draw
3254 * @fill: %TRUE if the arrow tip should be filled
3255 * @x: x origin of the rectangle to draw the arrow in
3256 * @y: y origin of the rectangle to draw the arrow in
3257 * @width: width of the rectangle to draw the arrow in
3258 * @height: height of the rectangle to draw the arrow in
3260 * Draws an arrow in the given rectangle on @cr using the given
3261 * parameters. @arrow_type determines the direction of the arrow.
3263 * Deprecated:3.0: Use gtk_render_arrow() instead
3266 gtk_paint_arrow (GtkStyle *style,
3268 GtkStateType state_type,
3269 GtkShadowType shadow_type,
3271 const gchar *detail,
3272 GtkArrowType arrow_type,
3279 g_return_if_fail (GTK_IS_STYLE (style));
3280 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
3281 g_return_if_fail (cr != NULL);
3282 g_return_if_fail (width >= 0);
3283 g_return_if_fail (height >= 0);
3287 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, cr, state_type, shadow_type,
3289 arrow_type, fill, x, y, width, height);
3295 * gtk_paint_diamond:
3296 * @style: a #GtkStyle
3298 * @state_type: a state
3299 * @shadow_type: the type of shadow to draw
3300 * @widget: (allow-none): the widget
3301 * @detail: (allow-none): a style detail
3302 * @x: x origin of the rectangle to draw the diamond in
3303 * @y: y origin of the rectangle to draw the diamond in
3304 * @width: width of the rectangle to draw the diamond in
3305 * @height: height of the rectangle to draw the diamond in
3307 * Draws a diamond in the given rectangle on @window using the given
3310 * Deprecated:3.0: Use cairo instead
3313 gtk_paint_diamond (GtkStyle *style,
3315 GtkStateType state_type,
3316 GtkShadowType shadow_type,
3318 const gchar *detail,
3324 g_return_if_fail (GTK_IS_STYLE (style));
3325 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
3326 g_return_if_fail (cr != NULL);
3327 g_return_if_fail (width >= 0);
3328 g_return_if_fail (height >= 0);
3332 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, cr, state_type, shadow_type,
3334 x, y, width, height);
3341 * @style: a #GtkStyle
3343 * @state_type: a state
3344 * @shadow_type: the type of shadow to draw
3345 * @widget: (allow-none): the widget
3346 * @detail: (allow-none): a style detail
3347 * @x: x origin of the box
3348 * @y: y origin of the box
3349 * @width: the width of the box
3350 * @height: the height of the box
3352 * Draws a box on @cr with the given parameters.
3354 * Deprecated:3.0: Use gtk_render_frame() and gtk_render_background() instead
3357 gtk_paint_box (GtkStyle *style,
3359 GtkStateType state_type,
3360 GtkShadowType shadow_type,
3362 const gchar *detail,
3368 g_return_if_fail (GTK_IS_STYLE (style));
3369 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
3370 g_return_if_fail (cr != NULL);
3374 GTK_STYLE_GET_CLASS (style)->draw_box (style, cr, state_type, shadow_type,
3376 x, y, width, height);
3382 * gtk_paint_flat_box:
3383 * @style: a #GtkStyle
3385 * @state_type: a state
3386 * @shadow_type: the type of shadow to draw
3387 * @widget: (allow-none): the widget
3388 * @detail: (allow-none): a style detail
3389 * @x: x origin of the box
3390 * @y: y origin of the box
3391 * @width: the width of the box
3392 * @height: the height of the box
3394 * Draws a flat box on @cr with the given parameters.
3396 * Deprecated:3.0: Use gtk_render_frame() and gtk_render_background() instead
3399 gtk_paint_flat_box (GtkStyle *style,
3401 GtkStateType state_type,
3402 GtkShadowType shadow_type,
3404 const gchar *detail,
3410 g_return_if_fail (GTK_IS_STYLE (style));
3411 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
3412 g_return_if_fail (cr != NULL);
3413 g_return_if_fail (width >= 0);
3414 g_return_if_fail (height >= 0);
3418 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, cr, state_type, shadow_type,
3420 x, y, width, height);
3427 * @style: a #GtkStyle
3429 * @state_type: a state
3430 * @shadow_type: the type of shadow to draw
3431 * @widget: (allow-none): the widget
3432 * @detail: (allow-none): a style detail
3433 * @x: x origin of the rectangle to draw the check in
3434 * @y: y origin of the rectangle to draw the check in
3435 * @width: the width of the rectangle to draw the check in
3436 * @height: the height of the rectangle to draw the check in
3438 * Draws a check button indicator in the given rectangle on @cr with
3439 * the given parameters.
3441 * Deprecated:3.0: Use gtk_render_check() instead
3444 gtk_paint_check (GtkStyle *style,
3446 GtkStateType state_type,
3447 GtkShadowType shadow_type,
3449 const gchar *detail,
3455 g_return_if_fail (GTK_IS_STYLE (style));
3456 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
3457 g_return_if_fail (cr != NULL);
3461 GTK_STYLE_GET_CLASS (style)->draw_check (style, cr, state_type, shadow_type,
3463 x, y, width, height);
3470 * @style: a #GtkStyle
3472 * @state_type: a state
3473 * @shadow_type: the type of shadow to draw
3474 * @widget: (allow-none): the widget
3475 * @detail: (allow-none): a style detail
3476 * @x: x origin of the rectangle to draw the option in
3477 * @y: y origin of the rectangle to draw the option in
3478 * @width: the width of the rectangle to draw the option in
3479 * @height: the height of the rectangle to draw the option in
3481 * Draws a radio button indicator in the given rectangle on @cr with
3482 * the given parameters.
3484 * Deprecated:3.0: Use gtk_render_option() instead
3487 gtk_paint_option (GtkStyle *style,
3489 GtkStateType state_type,
3490 GtkShadowType shadow_type,
3492 const gchar *detail,
3498 g_return_if_fail (GTK_IS_STYLE (style));
3499 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
3500 g_return_if_fail (cr != NULL);
3504 GTK_STYLE_GET_CLASS (style)->draw_option (style, cr, state_type, shadow_type,
3506 x, y, width, height);
3513 * @style: a #GtkStyle
3515 * @state_type: a state
3516 * @shadow_type: the type of shadow to draw
3517 * @widget: (allow-none): the widget
3518 * @detail: (allow-none): a style detail
3519 * @x: x origin of the rectangle to draw the tab in
3520 * @y: y origin of the rectangle to draw the tab in
3521 * @width: the width of the rectangle to draw the tab in
3522 * @height: the height of the rectangle to draw the tab in
3524 * Draws an option menu tab (i.e. the up and down pointing arrows)
3525 * in the given rectangle on @cr using the given parameters.
3527 * Deprecated:3.0: Use cairo instead
3530 gtk_paint_tab (GtkStyle *style,
3532 GtkStateType state_type,
3533 GtkShadowType shadow_type,
3535 const gchar *detail,
3541 g_return_if_fail (GTK_IS_STYLE (style));
3542 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
3543 g_return_if_fail (cr != NULL);
3547 GTK_STYLE_GET_CLASS (style)->draw_tab (style, cr, state_type, shadow_type,
3549 x, y, width, height);
3555 * gtk_paint_shadow_gap:
3556 * @style: a #GtkStyle
3558 * @state_type: a state
3559 * @shadow_type: type of shadow to draw
3560 * @widget: (allow-none): the widget
3561 * @detail: (allow-none): a style detail
3562 * @x: x origin of the rectangle
3563 * @y: y origin of the rectangle
3564 * @width: width of the rectangle
3565 * @height: width of the rectangle
3566 * @gap_side: side in which to leave the gap
3567 * @gap_x: starting position of the gap
3568 * @gap_width: width of the gap
3570 * Draws a shadow around the given rectangle in @cr
3571 * using the given style and state and shadow type, leaving a
3574 * Deprecated:3.0: Use gtk_render_frame_gap() instead
3577 gtk_paint_shadow_gap (GtkStyle *style,
3579 GtkStateType state_type,
3580 GtkShadowType shadow_type,
3582 const gchar *detail,
3587 GtkPositionType gap_side,
3591 g_return_if_fail (GTK_IS_STYLE (style));
3592 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
3593 g_return_if_fail (cr != NULL);
3594 g_return_if_fail (width >= 0);
3595 g_return_if_fail (height >= 0);
3599 GTK_STYLE_GET_CLASS (style)->draw_shadow_gap (style, cr, state_type, shadow_type,
3601 x, y, width, height, gap_side, gap_x, gap_width);
3607 * gtk_paint_box_gap:
3608 * @style: a #GtkStyle
3610 * @state_type: a state
3611 * @shadow_type: type of shadow to draw
3612 * @widget: (allow-none): the widget
3613 * @detail: (allow-none): a style detail
3614 * @x: x origin of the rectangle
3615 * @y: y origin of the rectangle
3616 * @width: width of the rectangle
3617 * @height: width of the rectangle
3618 * @gap_side: side in which to leave the gap
3619 * @gap_x: starting position of the gap
3620 * @gap_width: width of the gap
3622 * Draws a box in @cr using the given style and state and shadow type,
3623 * leaving a gap in one side.
3625 * Deprecated:3.0: Use gtk_render_frame_gap() instead
3628 gtk_paint_box_gap (GtkStyle *style,
3630 GtkStateType state_type,
3631 GtkShadowType shadow_type,
3633 const gchar *detail,
3638 GtkPositionType gap_side,
3642 g_return_if_fail (GTK_IS_STYLE (style));
3643 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
3644 g_return_if_fail (cr != NULL);
3645 g_return_if_fail (width >= 0);
3646 g_return_if_fail (height >= 0);
3650 GTK_STYLE_GET_CLASS (style)->draw_box_gap (style, cr, state_type, shadow_type,
3652 x, y, width, height, gap_side, gap_x, gap_width);
3658 * gtk_paint_extension:
3659 * @style: a #GtkStyle
3661 * @state_type: a state
3662 * @shadow_type: type of shadow to draw
3663 * @widget: (allow-none): the widget
3664 * @detail: (allow-none): a style detail
3665 * @x: x origin of the extension
3666 * @y: y origin of the extension
3667 * @width: width of the extension
3668 * @height: width of the extension
3669 * @gap_side: the side on to which the extension is attached
3671 * Draws an extension, i.e. a notebook tab.
3673 * Deprecated:3.0: Use gtk_render_extension() instead
3676 gtk_paint_extension (GtkStyle *style,
3678 GtkStateType state_type,
3679 GtkShadowType shadow_type,
3681 const gchar *detail,
3686 GtkPositionType gap_side)
3688 g_return_if_fail (GTK_IS_STYLE (style));
3689 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
3690 g_return_if_fail (cr != NULL);
3691 g_return_if_fail (width >= 0);
3692 g_return_if_fail (height >= 0);
3696 GTK_STYLE_GET_CLASS (style)->draw_extension (style, cr, state_type, shadow_type,
3698 x, y, width, height, gap_side);
3705 * @style: a #GtkStyle
3707 * @state_type: a state
3708 * @widget: (allow-none): the widget
3709 * @detail: (allow-none): a style detail
3710 * @x: the x origin of the rectangle around which to draw a focus indicator
3711 * @y: the y origin of the rectangle around which to draw a focus indicator
3712 * @width: the width of the rectangle around which to draw a focus indicator
3713 * @height: the height of the rectangle around which to draw a focus indicator
3715 * Draws a focus indicator around the given rectangle on @cr using the
3718 * Deprecated:3.0: Use gtk_render_focus() instead
3721 gtk_paint_focus (GtkStyle *style,
3723 GtkStateType state_type,
3725 const gchar *detail,
3731 g_return_if_fail (GTK_IS_STYLE (style));
3732 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
3733 g_return_if_fail (cr != NULL);
3734 g_return_if_fail (width >= 0);
3735 g_return_if_fail (height >= 0);
3739 GTK_STYLE_GET_CLASS (style)->draw_focus (style, cr, state_type,
3741 x, y, width, height);
3748 * @style: a #GtkStyle
3750 * @state_type: a state
3751 * @shadow_type: a shadow
3752 * @widget: (allow-none): the widget
3753 * @detail: (allow-none): a style detail
3754 * @x: the x origin of the rectangle in which to draw a slider
3755 * @y: the y origin of the rectangle in which to draw a slider
3756 * @width: the width of the rectangle in which to draw a slider
3757 * @height: the height of the rectangle in which to draw a slider
3758 * @orientation: the orientation to be used
3760 * Draws a slider in the given rectangle on @cr using the
3761 * given style and orientation.
3763 * Deprecated:3.0: Use gtk_render_slider() instead
3766 gtk_paint_slider (GtkStyle *style,
3768 GtkStateType state_type,
3769 GtkShadowType shadow_type,
3771 const gchar *detail,
3776 GtkOrientation orientation)
3778 g_return_if_fail (GTK_IS_STYLE (style));
3779 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
3780 g_return_if_fail (cr != NULL);
3781 g_return_if_fail (width >= 0);
3782 g_return_if_fail (height >= 0);
3786 GTK_STYLE_GET_CLASS (style)->draw_slider (style, cr, state_type, shadow_type,
3788 x, y, width, height, orientation);
3795 * @style: a #GtkStyle
3797 * @state_type: a state
3798 * @shadow_type: type of shadow to draw
3799 * @widget: (allow-none): the widget
3800 * @detail: (allow-none): a style detail
3801 * @x: x origin of the handle
3802 * @y: y origin of the handle
3803 * @width: with of the handle
3804 * @height: height of the handle
3805 * @orientation: the orientation of the handle
3807 * Draws a handle as used in #GtkHandleBox and #GtkPaned.
3809 * Deprecated:3.0: Use gtk_render_handle() instead
3812 gtk_paint_handle (GtkStyle *style,
3814 GtkStateType state_type,
3815 GtkShadowType shadow_type,
3817 const gchar *detail,
3822 GtkOrientation orientation)
3824 g_return_if_fail (GTK_IS_STYLE (style));
3825 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
3826 g_return_if_fail (cr != NULL);
3827 g_return_if_fail (width >= 0);
3828 g_return_if_fail (height >= 0);
3832 GTK_STYLE_GET_CLASS (style)->draw_handle (style, cr, state_type, shadow_type,
3834 x, y, width, height, orientation);
3840 * gtk_paint_expander:
3841 * @style: a #GtkStyle
3843 * @state_type: a state
3844 * @widget: (allow-none): the widget
3845 * @detail: (allow-none): a style detail
3846 * @x: the x position to draw the expander at
3847 * @y: the y position to draw the expander at
3848 * @expander_style: the style to draw the expander in; determines
3849 * whether the expander is collapsed, expanded, or in an
3850 * intermediate state.
3852 * Draws an expander as used in #GtkTreeView. @x and @y specify the
3853 * center the expander. The size of the expander is determined by the
3854 * "expander-size" style property of @widget. (If widget is not
3855 * specified or doesn't have an "expander-size" property, an
3856 * unspecified default size will be used, since the caller doesn't
3857 * have sufficient information to position the expander, this is
3858 * likely not useful.) The expander is expander_size pixels tall
3859 * in the collapsed position and expander_size pixels wide in the
3860 * expanded position.
3862 * Deprecated:3.0: Use gtk_render_expander() instead
3865 gtk_paint_expander (GtkStyle *style,
3867 GtkStateType state_type,
3869 const gchar *detail,
3872 GtkExpanderStyle expander_style)
3874 g_return_if_fail (GTK_IS_STYLE (style));
3875 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
3876 g_return_if_fail (cr != NULL);
3880 GTK_STYLE_GET_CLASS (style)->draw_expander (style, cr, state_type,
3882 x, y, expander_style);
3889 * @style: a #GtkStyle
3891 * @state_type: a state
3892 * @use_text: whether to use the text or foreground
3893 * graphics context of @style
3894 * @widget: (allow-none): the widget
3895 * @detail: (allow-none): a style detail
3898 * @layout: the layout to draw
3900 * Draws a layout on @cr using the given parameters.
3902 * Deprecated:3.0: Use gtk_render_layout() instead
3905 gtk_paint_layout (GtkStyle *style,
3907 GtkStateType state_type,
3910 const gchar *detail,
3913 PangoLayout *layout)
3915 g_return_if_fail (GTK_IS_STYLE (style));
3916 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
3917 g_return_if_fail (cr != NULL);
3921 GTK_STYLE_GET_CLASS (style)->draw_layout (style, cr, state_type, use_text,
3929 * gtk_paint_resize_grip:
3930 * @style: a #GtkStyle
3932 * @state_type: a state
3933 * @widget: (allow-none): the widget
3934 * @detail: (allow-none): a style detail
3935 * @edge: the edge in which to draw the resize grip
3936 * @x: the x origin of the rectangle in which to draw the resize grip
3937 * @y: the y origin of the rectangle in which to draw the resize grip
3938 * @width: the width of the rectangle in which to draw the resize grip
3939 * @height: the height of the rectangle in which to draw the resize grip
3941 * Draws a resize grip in the given rectangle on @cr using the given
3944 * Deprecated:3.0: Use gtk_render_handle() instead
3947 gtk_paint_resize_grip (GtkStyle *style,
3949 GtkStateType state_type,
3951 const gchar *detail,
3958 g_return_if_fail (GTK_IS_STYLE (style));
3959 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
3960 g_return_if_fail (cr != NULL);
3964 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, cr, state_type,
3966 edge, x, y, width, height);
3971 * gtk_paint_spinner:
3972 * @style: a #GtkStyle
3974 * @state_type: a state
3975 * @widget: (allow-none): the widget (may be %NULL)
3976 * @detail: (allow-none): a style detail (may be %NULL)
3977 * @step: the nth step, a value between 0 and #GtkSpinner:num-steps
3978 * @x: the x origin of the rectangle in which to draw the spinner
3979 * @y: the y origin of the rectangle in which to draw the spinner
3980 * @width: the width of the rectangle in which to draw the spinner
3981 * @height: the height of the rectangle in which to draw the spinner
3983 * Draws a spinner on @window using the given parameters.
3985 * Deprecated:3.0: Use gtk_render_activity() instead
3988 gtk_paint_spinner (GtkStyle *style,
3990 GtkStateType state_type,
3992 const gchar *detail,
3999 g_return_if_fail (GTK_IS_STYLE (style));
4000 g_return_if_fail (cr != NULL);
4001 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_spinner != NULL);
4005 GTK_STYLE_GET_CLASS (style)->draw_spinner (style, cr, state_type,
4007 step, x, y, width, height);
4012 static GtkStyle *gtk_default_style = NULL;
4015 * gtk_widget_get_default_style:
4017 * Returns the default style used by all widgets initially.
4019 * Returns: (transfer none): the default style. This #GtkStyle
4020 * object is owned by GTK+ and should not be modified or freed.
4022 * Deprecated:3.0: Use #GtkStyleContext instead, and
4023 * gtk_css_provider_get_default() to obtain a #GtkStyleProvider
4024 * with the default widget style information.
4027 gtk_widget_get_default_style (void)
4029 if (!gtk_default_style)
4031 gtk_default_style = gtk_style_new ();
4032 g_object_ref (gtk_default_style);
4035 return gtk_default_style;
4039 * gtk_widget_style_attach:
4040 * @widget: a #GtkWidget
4042 * This function attaches the widget's #GtkStyle to the widget's
4043 * #GdkWindow. It is a replacement for
4046 * widget->style = gtk_style_attach (widget->style, widget->window);
4049 * and should only ever be called in a derived widget's "realize"
4050 * implementation which does not chain up to its parent class'
4051 * "realize" implementation, because one of the parent classes
4052 * (finally #GtkWidget) would attach the style itself.
4056 * Deprecated: 3.0. This step is unnecessary with #GtkStyleContext.
4059 gtk_widget_style_attach (GtkWidget *widget)
4061 g_return_if_fail (GTK_IS_WIDGET (widget));
4062 g_return_if_fail (gtk_widget_get_realized (widget));
4066 * gtk_widget_has_rc_style:
4067 * @widget: a #GtkWidget
4069 * Determines if the widget style has been looked up through the rc mechanism.
4071 * Returns: %TRUE if the widget has been looked up through the rc
4072 * mechanism, %FALSE otherwise.
4076 * Deprecated:3.0: Use #GtkStyleContext instead
4079 gtk_widget_has_rc_style (GtkWidget *widget)
4081 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4087 * gtk_widget_set_style:
4088 * @widget: a #GtkWidget
4089 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect
4090 * of a previous call to gtk_widget_set_style() and go back to
4093 * Used to set the #GtkStyle for a widget (@widget->style). Since
4094 * GTK 3, this function does nothing, the passed in style is ignored.
4096 * Deprecated:3.0: Use #GtkStyleContext instead
4099 gtk_widget_set_style (GtkWidget *widget,
4102 g_return_if_fail (GTK_IS_WIDGET (widget));
4106 * gtk_widget_ensure_style:
4107 * @widget: a #GtkWidget
4109 * Ensures that @widget has a style (@widget->style).
4111 * Not a very useful function; most of the time, if you
4112 * want the style, the widget is realized, and realized
4113 * widgets are guaranteed to have a style already.
4115 * Deprecated:3.0: Use #GtkStyleContext instead
4118 gtk_widget_ensure_style (GtkWidget *widget)
4121 g_return_if_fail (GTK_IS_WIDGET (widget));
4123 style = _gtk_widget_get_style (widget);
4124 if (style == gtk_widget_get_default_style ())
4126 g_object_unref (style);
4127 _gtk_widget_set_style (widget, NULL);
4129 g_signal_emit_by_name (widget, "style-set", 0, NULL);
4134 * gtk_widget_get_style:
4135 * @widget: a #GtkWidget
4137 * Simply an accessor function that returns @widget->style.
4139 * Return value: (transfer none): the widget's #GtkStyle
4141 * Deprecated:3.0: Use #GtkStyleContext instead
4144 gtk_widget_get_style (GtkWidget *widget)
4147 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4149 style = _gtk_widget_get_style (widget);
4153 style = g_object_new (GTK_TYPE_STYLE,
4154 "context", gtk_widget_get_style_context (widget),
4156 _gtk_widget_set_style (widget, style);
4163 * gtk_widget_modify_style:
4164 * @widget: a #GtkWidget
4165 * @style: the #GtkRcStyle holding the style modifications
4167 * Modifies style values on the widget.
4169 * Modifications made using this technique take precedence over
4170 * style values set via an RC file, however, they will be overridden
4171 * if a style is explicitely set on the widget using gtk_widget_set_style().
4172 * The #GtkRcStyle structure is designed so each field can either be
4173 * set or unset, so it is possible, using this function, to modify some
4174 * style values and leave the others unchanged.
4176 * Note that modifications made with this function are not cumulative
4177 * with previous calls to gtk_widget_modify_style() or with such
4178 * functions as gtk_widget_modify_fg(). If you wish to retain
4179 * previous values, you must first call gtk_widget_get_modifier_style(),
4180 * make your modifications to the returned style, then call
4181 * gtk_widget_modify_style() with that style. On the other hand,
4182 * if you first call gtk_widget_modify_style(), subsequent calls
4183 * to such functions gtk_widget_modify_fg() will have a cumulative
4184 * effect with the initial modifications.
4186 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
4189 gtk_widget_modify_style (GtkWidget *widget,
4192 g_return_if_fail (GTK_IS_WIDGET (widget));
4193 g_return_if_fail (GTK_IS_RC_STYLE (style));
4195 g_object_set_data_full (G_OBJECT (widget),
4197 gtk_rc_style_copy (style),
4198 (GDestroyNotify) g_object_unref);
4202 * gtk_widget_get_modifier_style:
4203 * @widget: a #GtkWidget
4205 * Returns the current modifier style for the widget. (As set by
4206 * gtk_widget_modify_style().) If no style has previously set, a new
4207 * #GtkRcStyle will be created with all values unset, and set as the
4208 * modifier style for the widget. If you make changes to this rc
4209 * style, you must call gtk_widget_modify_style(), passing in the
4210 * returned rc style, to make sure that your changes take effect.
4212 * Caution: passing the style back to gtk_widget_modify_style() will
4213 * normally end up destroying it, because gtk_widget_modify_style() copies
4214 * the passed-in style and sets the copy as the new modifier style,
4215 * thus dropping any reference to the old modifier style. Add a reference
4216 * to the modifier style if you want to keep it alive.
4218 * Return value: (transfer none): the modifier style for the widget.
4219 * This rc style is owned by the widget. If you want to keep a
4220 * pointer to value this around, you must add a refcount using
4223 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
4226 gtk_widget_get_modifier_style (GtkWidget *widget)
4228 GtkRcStyle *rc_style;
4230 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4232 rc_style = g_object_get_data (G_OBJECT (widget), "gtk-rc-style");
4236 rc_style = gtk_rc_style_new ();
4237 g_object_set_data_full (G_OBJECT (widget),
4240 (GDestroyNotify) g_object_unref);
4247 gtk_widget_modify_color_component (GtkWidget *widget,
4248 GtkRcFlags component,
4250 const GdkColor *color)
4252 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
4259 rc_style->fg[state] = *color;
4262 rc_style->bg[state] = *color;
4265 rc_style->text[state] = *color;
4268 rc_style->base[state] = *color;
4271 g_assert_not_reached();
4274 rc_style->color_flags[state] |= component;
4277 rc_style->color_flags[state] &= ~component;
4279 gtk_widget_modify_style (widget, rc_style);
4283 * gtk_widget_modify_fg:
4284 * @widget: a #GtkWidget
4285 * @state: the state for which to set the foreground color
4286 * @color: (allow-none): the color to assign (does not need to be allocated),
4287 * or %NULL to undo the effect of previous calls to
4288 * of gtk_widget_modify_fg().
4290 * Sets the foreground color for a widget in a particular state.
4292 * All other style values are left untouched.
4293 * See also gtk_widget_modify_style().
4295 * Deprecated:3.0: Use gtk_widget_override_color() instead
4298 gtk_widget_modify_fg (GtkWidget *widget,
4300 const GdkColor *color)
4302 GtkStateFlags flags;
4305 g_return_if_fail (GTK_IS_WIDGET (widget));
4306 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4310 case GTK_STATE_ACTIVE:
4311 flags = GTK_STATE_FLAG_ACTIVE;
4313 case GTK_STATE_PRELIGHT:
4314 flags = GTK_STATE_FLAG_PRELIGHT;
4316 case GTK_STATE_SELECTED:
4317 flags = GTK_STATE_FLAG_SELECTED;
4319 case GTK_STATE_INSENSITIVE:
4320 flags = GTK_STATE_FLAG_INSENSITIVE;
4322 case GTK_STATE_NORMAL:
4329 rgba.red = color->red / 65535.;
4330 rgba.green = color->green / 65535.;
4331 rgba.blue = color->blue / 65535.;
4334 gtk_widget_override_color (widget, flags, &rgba);
4337 gtk_widget_override_color (widget, flags, NULL);
4341 * gtk_widget_modify_bg:
4342 * @widget: a #GtkWidget
4343 * @state: the state for which to set the background color
4344 * @color: (allow-none): the color to assign (does not need
4345 * to be allocated), or %NULL to undo the effect of previous
4346 * calls to of gtk_widget_modify_bg().
4348 * Sets the background color for a widget in a particular state.
4350 * All other style values are left untouched.
4351 * See also gtk_widget_modify_style().
4354 * Note that "no window" widgets (which have the %GTK_NO_WINDOW
4355 * flag set) draw on their parent container's window and thus may
4356 * not draw any background themselves. This is the case for e.g.
4359 * To modify the background of such widgets, you have to set the
4360 * background color on their parent; if you want to set the background
4361 * of a rectangular area around a label, try placing the label in
4362 * a #GtkEventBox widget and setting the background color on that.
4365 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
4368 gtk_widget_modify_bg (GtkWidget *widget,
4370 const GdkColor *color)
4372 GtkStateFlags flags;
4375 g_return_if_fail (GTK_IS_WIDGET (widget));
4376 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4380 case GTK_STATE_ACTIVE:
4381 flags = GTK_STATE_FLAG_ACTIVE;
4383 case GTK_STATE_PRELIGHT:
4384 flags = GTK_STATE_FLAG_PRELIGHT;
4386 case GTK_STATE_SELECTED:
4387 flags = GTK_STATE_FLAG_SELECTED;
4389 case GTK_STATE_INSENSITIVE:
4390 flags = GTK_STATE_FLAG_INSENSITIVE;
4392 case GTK_STATE_NORMAL:
4399 rgba.red = color->red / 65535.;
4400 rgba.green = color->green / 65535.;
4401 rgba.blue = color->blue / 65535.;
4404 gtk_widget_override_background_color (widget, flags, &rgba);
4407 gtk_widget_override_background_color (widget, flags, NULL);
4411 * gtk_widget_modify_text:
4412 * @widget: a #GtkWidget
4413 * @state: the state for which to set the text color
4414 * @color: (allow-none): the color to assign (does not need to
4415 * be allocated), or %NULL to undo the effect of previous
4416 * calls to of gtk_widget_modify_text().
4418 * Sets the text color for a widget in a particular state.
4420 * All other style values are left untouched.
4421 * The text color is the foreground color used along with the
4422 * base color (see gtk_widget_modify_base()) for widgets such
4423 * as #GtkEntry and #GtkTextView.
4424 * See also gtk_widget_modify_style().
4426 * Deprecated:3.0: Use gtk_widget_override_color() instead
4429 gtk_widget_modify_text (GtkWidget *widget,
4431 const GdkColor *color)
4433 g_return_if_fail (GTK_IS_WIDGET (widget));
4434 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4436 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
4440 * gtk_widget_modify_base:
4441 * @widget: a #GtkWidget
4442 * @state: the state for which to set the base 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_base().
4447 * Sets the base color for a widget in a particular state.
4448 * All other style values are left untouched. The base color
4449 * is the background color used along with the text color
4450 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
4451 * and #GtkTextView. See also gtk_widget_modify_style().
4454 * Note that "no window" widgets (which have the %GTK_NO_WINDOW
4455 * flag set) draw on their parent container's window and thus may
4456 * not draw any background themselves. This is the case for e.g.
4459 * To modify the background of such widgets, you have to set the
4460 * base color on their parent; if you want to set the background
4461 * of a rectangular area around a label, try placing the label in
4462 * a #GtkEventBox widget and setting the base color on that.
4465 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
4468 gtk_widget_modify_base (GtkWidget *widget,
4470 const GdkColor *color)
4472 g_return_if_fail (GTK_IS_WIDGET (widget));
4473 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4475 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
4479 * gtk_widget_modify_cursor:
4480 * @widget: a #GtkWidget
4481 * @primary: the color to use for primary cursor (does not need to be
4482 * allocated), or %NULL to undo the effect of previous calls to
4483 * of gtk_widget_modify_cursor().
4484 * @secondary: the color to use for secondary cursor (does not need to be
4485 * allocated), or %NULL to undo the effect of previous calls to
4486 * of gtk_widget_modify_cursor().
4488 * Sets the cursor color to use in a widget, overriding the
4489 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
4492 * All other style values are left untouched.
4493 * See also gtk_widget_modify_style().
4497 * Deprecated: 3.0. Use gtk_widget_override_cursor() instead.
4500 gtk_widget_modify_cursor (GtkWidget *widget,
4501 const GdkColor *primary,
4502 const GdkColor *secondary)
4504 GdkRGBA primary_rgba, secondary_rgba;
4506 g_return_if_fail (GTK_IS_WIDGET (widget));
4508 primary_rgba.red = primary->red / 65535.;
4509 primary_rgba.green = primary->green / 65535.;
4510 primary_rgba.blue = primary->blue / 65535.;
4511 primary_rgba.alpha = 1;
4513 secondary_rgba.red = secondary->red / 65535.;
4514 secondary_rgba.green = secondary->green / 65535.;
4515 secondary_rgba.blue = secondary->blue / 65535.;
4516 secondary_rgba.alpha = 1;
4518 gtk_widget_override_cursor (widget, &primary_rgba, &secondary_rgba);
4522 * gtk_widget_modify_font:
4523 * @widget: a #GtkWidget
4524 * @font_desc: (allow-none): the font description to use, or %NULL
4525 * to undo the effect of previous calls to gtk_widget_modify_font()
4527 * Sets the font to use for a widget.
4529 * All other style values are left untouched.
4530 * See also gtk_widget_modify_style().
4532 * Deprecated:3.0: Use gtk_widget_override_font() instead
4535 gtk_widget_modify_font (GtkWidget *widget,
4536 PangoFontDescription *font_desc)
4538 g_return_if_fail (GTK_IS_WIDGET (widget));
4540 gtk_widget_override_font (widget, font_desc);
4544 * gtk_widget_reset_rc_styles:
4545 * @widget: a #GtkWidget.
4547 * Reset the styles of @widget and all descendents, so when
4548 * they are looked up again, they get the correct values
4549 * for the currently loaded RC file settings.
4551 * This function is not useful for applications.
4553 * Deprecated:3.0: Use #GtkStyleContext instead, and gtk_widget_reset_style()
4556 gtk_widget_reset_rc_styles (GtkWidget *widget)
4558 g_return_if_fail (GTK_IS_WIDGET (widget));
4560 gtk_widget_reset_style (widget);
4565 * @widget: a #GtkWidget
4566 * @path_length: (out) (allow-none): location to store length of the path,
4568 * @path: (out) (allow-none): location to store allocated path string,
4570 * @path_reversed: (out) (allow-none): location to store allocated reverse
4571 * path string, or %NULL
4573 * Obtains the full path to @widget. The path is simply the name of a
4574 * widget and all its parents in the container hierarchy, separated by
4575 * periods. The name of a widget comes from
4576 * gtk_widget_get_name(). Paths are used to apply styles to a widget
4577 * in gtkrc configuration files. Widget names are the type of the
4578 * widget by default (e.g. "GtkButton") or can be set to an
4579 * application-specific value with gtk_widget_set_name(). By setting
4580 * the name of a widget, you allow users or theme authors to apply
4581 * styles to that specific widget in their gtkrc
4582 * file. @path_reversed_p fills in the path in reverse order,
4583 * i.e. starting with @widget's name instead of starting with the name
4584 * of @widget's outermost ancestor.
4586 * Deprecated:3.0: Use gtk_widget_get_path() instead
4589 gtk_widget_path (GtkWidget *widget,
4592 gchar **path_reversed)
4594 static gchar *rev_path = NULL;
4595 static guint tmp_path_len = 0;
4598 #define INIT_PATH_SIZE (512)
4600 g_return_if_fail (GTK_IS_WIDGET (widget));
4605 const gchar *string;
4610 string = gtk_widget_get_name (widget);
4611 l = strlen (string);
4612 while (tmp_path_len <= len + l + 1)
4614 tmp_path_len += INIT_PATH_SIZE;
4615 rev_path = g_realloc (rev_path, tmp_path_len);
4623 widget = gtk_widget_get_parent (widget);
4626 rev_path[len++] = '.';
4628 rev_path[len++] = 0;
4633 *path_length = len - 1;
4635 *path_reversed = g_strdup (rev_path);
4638 *path = g_strdup (rev_path);
4639 g_strreverse (*path);
4644 * gtk_widget_class_path:
4645 * @widget: a #GtkWidget
4646 * @path_length: (out) (allow-none): location to store the length of the
4647 * class path, or %NULL
4648 * @path: (out) (allow-none): location to store the class path as an
4649 * allocated string, or %NULL
4650 * @path_reversed: (out) (allow-none): location to store the reverse
4651 * class path as an allocated string, or %NULL
4653 * Same as gtk_widget_path(), but always uses the name of a widget's type,
4654 * never uses a custom name set with gtk_widget_set_name().
4656 * Deprecated:3.0: Use gtk_widget_get_path() instead
4659 gtk_widget_class_path (GtkWidget *widget,
4662 gchar **path_reversed)
4664 static gchar *rev_path = NULL;
4665 static guint tmp_path_len = 0;
4668 g_return_if_fail (GTK_IS_WIDGET (widget));
4673 const gchar *string;
4678 string = g_type_name (G_OBJECT_TYPE (widget));
4679 l = strlen (string);
4680 while (tmp_path_len <= len + l + 1)
4682 tmp_path_len += INIT_PATH_SIZE;
4683 rev_path = g_realloc (rev_path, tmp_path_len);
4691 widget = gtk_widget_get_parent (widget);
4694 rev_path[len++] = '.';
4696 rev_path[len++] = 0;
4701 *path_length = len - 1;
4703 *path_reversed = g_strdup (rev_path);
4706 *path = g_strdup (rev_path);
4707 g_strreverse (*path);
4712 * gtk_widget_render_icon:
4713 * @widget: a #GtkWidget
4714 * @stock_id: a stock ID
4715 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
4716 * render at the size of the source and don't scale (if there are
4717 * multiple source sizes, GTK+ picks one of the available sizes).
4718 * @detail: (allow-none): render detail to pass to theme engine
4720 * A convenience function that uses the theme settings for @widget
4721 * to look up @stock_id and render it to a pixbuf. @stock_id should
4722 * be a stock icon ID such as #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size
4723 * should be a size such as #GTK_ICON_SIZE_MENU. @detail should be a
4724 * string that identifies the widget or code doing the rendering, so
4725 * that theme engines can special-case rendering for that widget or
4728 * The pixels in the returned #GdkPixbuf are shared with the rest of
4729 * the application and should not be modified. The pixbuf should be
4730 * freed after use with g_object_unref().
4732 * Return value: (transfer full): a new pixbuf, or %NULL if the
4733 * stock ID wasn't known
4735 * Deprecated: 3.0: Use gtk_widget_render_icon_pixbuf() instead.
4738 gtk_widget_render_icon (GtkWidget *widget,
4739 const gchar *stock_id,
4741 const gchar *detail)
4743 gtk_widget_ensure_style (widget);
4745 return gtk_widget_render_icon_pixbuf (widget, stock_id, size);