1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
29 #define GDK_DISABLE_DEPRECATION_WARNINGS
34 #include <gobject/gvaluecollector.h>
35 #include "gtkmarshalers.h"
38 #include "gtkspinbutton.h"
40 #include "gtkstylecontextprivate.h"
41 #include "gtkwidget.h"
42 #include "gtkwidgetprivate.h"
43 #include "gtkiconfactory.h"
46 #include "gtkspinner.h"
47 #include "gtkborder.h"
51 * @Short_description: Deprecated object that holds style information
55 * A #GtkStyle object encapsulates the information that provides the look and
59 * In GTK+ 3.0, GtkStyle has been deprecated and replaced by #GtkStyleContext.
62 * Each #GtkWidget has an associated #GtkStyle object that is used when
63 * rendering that widget. Also, a #GtkStyle holds information for the five
64 * possible widget states though not every widget supports all five
65 * states; see #GtkStateType.
67 * Usually the #GtkStyle for a widget is the same as the default style that
68 * is set by GTK+ and modified the theme engine.
70 * Usually applications should not need to use or modify the #GtkStyle of
75 #define LIGHTNESS_MULT 1.3
76 #define DARKNESS_MULT 0.7
78 /* --- typedefs & structures --- */
85 #define GTK_STYLE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_STYLE, GtkStylePrivate))
87 typedef struct _GtkStylePrivate GtkStylePrivate;
89 struct _GtkStylePrivate {
90 GtkStyleContext *context;
91 gulong context_changed_id;
99 /* --- prototypes --- */
100 static void gtk_style_finalize (GObject *object);
101 static void gtk_style_constructed (GObject *object);
102 static void gtk_style_set_property (GObject *object,
106 static void gtk_style_get_property (GObject *object,
111 static void gtk_style_real_realize (GtkStyle *style);
112 static void gtk_style_real_unrealize (GtkStyle *style);
113 static void gtk_style_real_copy (GtkStyle *style,
115 static void gtk_style_real_set_background (GtkStyle *style,
117 GtkStateType state_type);
118 static GtkStyle *gtk_style_real_clone (GtkStyle *style);
119 static void gtk_style_real_init_from_rc (GtkStyle *style,
120 GtkRcStyle *rc_style);
121 static GdkPixbuf *gtk_default_render_icon (GtkStyle *style,
122 const GtkIconSource *source,
123 GtkTextDirection direction,
127 const gchar *detail);
128 static void gtk_default_draw_hline (GtkStyle *style,
130 GtkStateType state_type,
136 static void gtk_default_draw_vline (GtkStyle *style,
138 GtkStateType state_type,
144 static void gtk_default_draw_shadow (GtkStyle *style,
146 GtkStateType state_type,
147 GtkShadowType shadow_type,
154 static void gtk_default_draw_arrow (GtkStyle *style,
156 GtkStateType state_type,
157 GtkShadowType shadow_type,
160 GtkArrowType arrow_type,
166 static void gtk_default_draw_diamond (GtkStyle *style,
168 GtkStateType state_type,
169 GtkShadowType shadow_type,
176 static void gtk_default_draw_box (GtkStyle *style,
178 GtkStateType state_type,
179 GtkShadowType shadow_type,
186 static void gtk_default_draw_flat_box (GtkStyle *style,
188 GtkStateType state_type,
189 GtkShadowType shadow_type,
196 static void gtk_default_draw_check (GtkStyle *style,
198 GtkStateType state_type,
199 GtkShadowType shadow_type,
206 static void gtk_default_draw_option (GtkStyle *style,
208 GtkStateType state_type,
209 GtkShadowType shadow_type,
216 static void gtk_default_draw_tab (GtkStyle *style,
218 GtkStateType state_type,
219 GtkShadowType shadow_type,
226 static void gtk_default_draw_shadow_gap (GtkStyle *style,
228 GtkStateType state_type,
229 GtkShadowType shadow_type,
236 GtkPositionType gap_side,
239 static void gtk_default_draw_box_gap (GtkStyle *style,
241 GtkStateType state_type,
242 GtkShadowType shadow_type,
249 GtkPositionType gap_side,
252 static void gtk_default_draw_extension (GtkStyle *style,
254 GtkStateType state_type,
255 GtkShadowType shadow_type,
262 GtkPositionType gap_side);
263 static void gtk_default_draw_focus (GtkStyle *style,
265 GtkStateType state_type,
272 static void gtk_default_draw_slider (GtkStyle *style,
274 GtkStateType state_type,
275 GtkShadowType shadow_type,
282 GtkOrientation orientation);
283 static void gtk_default_draw_handle (GtkStyle *style,
285 GtkStateType state_type,
286 GtkShadowType shadow_type,
293 GtkOrientation orientation);
294 static void gtk_default_draw_expander (GtkStyle *style,
296 GtkStateType state_type,
301 GtkExpanderStyle expander_style);
302 static void gtk_default_draw_layout (GtkStyle *style,
304 GtkStateType state_type,
310 PangoLayout *layout);
311 static void gtk_default_draw_resize_grip (GtkStyle *style,
313 GtkStateType state_type,
321 static void gtk_default_draw_spinner (GtkStyle *style,
323 GtkStateType state_type,
332 static void rgb_to_hls (gdouble *r,
335 static void hls_to_rgb (gdouble *h,
339 static void transform_detail_string (const gchar *detail,
340 GtkStyleContext *context);
343 * Data for default check and radio buttons
346 static const GtkRequisition default_option_indicator_size = { 7, 13 };
347 static const GtkBorder default_option_indicator_spacing = { 7, 5, 2, 2 };
349 #define GTK_GRAY 0xdcdc, 0xdada, 0xd5d5
350 #define GTK_DARK_GRAY 0xc4c4, 0xc2c2, 0xbdbd
351 #define GTK_LIGHT_GRAY 0xeeee, 0xebeb, 0xe7e7
352 #define GTK_WHITE 0xffff, 0xffff, 0xffff
353 #define GTK_BLUE 0x4b4b, 0x6969, 0x8383
354 #define GTK_VERY_DARK_GRAY 0x9c9c, 0x9a9a, 0x9494
355 #define GTK_BLACK 0x0000, 0x0000, 0x0000
356 #define GTK_WEAK_GRAY 0x7530, 0x7530, 0x7530
358 /* --- variables --- */
359 static const GdkColor gtk_default_normal_fg = { 0, GTK_BLACK };
360 static const GdkColor gtk_default_active_fg = { 0, GTK_BLACK };
361 static const GdkColor gtk_default_prelight_fg = { 0, GTK_BLACK };
362 static const GdkColor gtk_default_selected_fg = { 0, GTK_WHITE };
363 static const GdkColor gtk_default_insensitive_fg = { 0, GTK_WEAK_GRAY };
365 static const GdkColor gtk_default_normal_bg = { 0, GTK_GRAY };
366 static const GdkColor gtk_default_active_bg = { 0, GTK_DARK_GRAY };
367 static const GdkColor gtk_default_prelight_bg = { 0, GTK_LIGHT_GRAY };
368 static const GdkColor gtk_default_selected_bg = { 0, GTK_BLUE };
369 static const GdkColor gtk_default_insensitive_bg = { 0, GTK_GRAY };
370 static const GdkColor gtk_default_selected_base = { 0, GTK_BLUE };
371 static const GdkColor gtk_default_active_base = { 0, GTK_VERY_DARK_GRAY };
373 /* --- signals --- */
374 static guint realize_signal = 0;
375 static guint unrealize_signal = 0;
377 G_DEFINE_TYPE (GtkStyle, gtk_style, G_TYPE_OBJECT)
379 /* --- functions --- */
382 gtk_style_init (GtkStyle *style)
386 style->font_desc = pango_font_description_from_string ("Sans 10");
388 style->attach_count = 0;
390 style->black.red = 0;
391 style->black.green = 0;
392 style->black.blue = 0;
394 style->white.red = 65535;
395 style->white.green = 65535;
396 style->white.blue = 65535;
398 style->fg[GTK_STATE_NORMAL] = gtk_default_normal_fg;
399 style->fg[GTK_STATE_ACTIVE] = gtk_default_active_fg;
400 style->fg[GTK_STATE_PRELIGHT] = gtk_default_prelight_fg;
401 style->fg[GTK_STATE_SELECTED] = gtk_default_selected_fg;
402 style->fg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
404 style->bg[GTK_STATE_NORMAL] = gtk_default_normal_bg;
405 style->bg[GTK_STATE_ACTIVE] = gtk_default_active_bg;
406 style->bg[GTK_STATE_PRELIGHT] = gtk_default_prelight_bg;
407 style->bg[GTK_STATE_SELECTED] = gtk_default_selected_bg;
408 style->bg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_bg;
410 for (i = 0; i < 4; i++)
412 style->text[i] = style->fg[i];
413 style->base[i] = style->white;
416 style->base[GTK_STATE_SELECTED] = gtk_default_selected_base;
417 style->text[GTK_STATE_SELECTED] = style->white;
418 style->base[GTK_STATE_ACTIVE] = gtk_default_active_base;
419 style->text[GTK_STATE_ACTIVE] = style->white;
420 style->base[GTK_STATE_INSENSITIVE] = gtk_default_prelight_bg;
421 style->text[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
423 style->rc_style = NULL;
425 style->xthickness = 2;
426 style->ythickness = 2;
428 style->property_cache = NULL;
432 gtk_style_class_init (GtkStyleClass *klass)
434 GObjectClass *object_class = G_OBJECT_CLASS (klass);
436 object_class->finalize = gtk_style_finalize;
437 object_class->set_property = gtk_style_set_property;
438 object_class->get_property = gtk_style_get_property;
439 object_class->constructed = gtk_style_constructed;
441 klass->clone = gtk_style_real_clone;
442 klass->copy = gtk_style_real_copy;
443 klass->init_from_rc = gtk_style_real_init_from_rc;
444 klass->realize = gtk_style_real_realize;
445 klass->unrealize = gtk_style_real_unrealize;
446 klass->set_background = gtk_style_real_set_background;
447 klass->render_icon = gtk_default_render_icon;
449 klass->draw_hline = gtk_default_draw_hline;
450 klass->draw_vline = gtk_default_draw_vline;
451 klass->draw_shadow = gtk_default_draw_shadow;
452 klass->draw_arrow = gtk_default_draw_arrow;
453 klass->draw_diamond = gtk_default_draw_diamond;
454 klass->draw_box = gtk_default_draw_box;
455 klass->draw_flat_box = gtk_default_draw_flat_box;
456 klass->draw_check = gtk_default_draw_check;
457 klass->draw_option = gtk_default_draw_option;
458 klass->draw_tab = gtk_default_draw_tab;
459 klass->draw_shadow_gap = gtk_default_draw_shadow_gap;
460 klass->draw_box_gap = gtk_default_draw_box_gap;
461 klass->draw_extension = gtk_default_draw_extension;
462 klass->draw_focus = gtk_default_draw_focus;
463 klass->draw_slider = gtk_default_draw_slider;
464 klass->draw_handle = gtk_default_draw_handle;
465 klass->draw_expander = gtk_default_draw_expander;
466 klass->draw_layout = gtk_default_draw_layout;
467 klass->draw_resize_grip = gtk_default_draw_resize_grip;
468 klass->draw_spinner = gtk_default_draw_spinner;
470 g_type_class_add_private (object_class, sizeof (GtkStylePrivate));
472 g_object_class_install_property (object_class,
474 g_param_spec_object ("context",
476 P_("GtkStyleContext to get style from"),
477 GTK_TYPE_STYLE_CONTEXT,
478 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
482 * @style: the object which received the signal
484 * Emitted when the style has been initialized for a particular
485 * visual. Connecting to this signal is probably seldom
486 * useful since most of the time applications and widgets only
487 * deal with styles that have been already realized.
491 realize_signal = g_signal_new (I_("realize"),
492 G_TYPE_FROM_CLASS (object_class),
494 G_STRUCT_OFFSET (GtkStyleClass, realize),
496 _gtk_marshal_VOID__VOID,
499 * GtkStyle::unrealize:
500 * @style: the object which received the signal
502 * Emitted when the aspects of the style specific to a particular visual
503 * is being cleaned up. A connection to this signal can be useful
504 * if a widget wants to cache objects as object data on #GtkStyle.
505 * This signal provides a convenient place to free such cached objects.
509 unrealize_signal = g_signal_new (I_("unrealize"),
510 G_TYPE_FROM_CLASS (object_class),
512 G_STRUCT_OFFSET (GtkStyleClass, unrealize),
514 _gtk_marshal_VOID__VOID,
519 gtk_style_finalize (GObject *object)
521 GtkStyle *style = GTK_STYLE (object);
522 GtkStylePrivate *priv = GTK_STYLE_GET_PRIVATE (style);
525 g_return_if_fail (style->attach_count == 0);
527 /* All the styles in the list have the same
528 * style->styles pointer. If we delete the
529 * *first* style from the list, we need to update
530 * the style->styles pointers from all the styles.
531 * Otherwise we simply remove the node from
536 if (style->styles->data != style)
537 style->styles = g_slist_remove (style->styles, style);
540 GSList *tmp_list = style->styles->next;
544 GTK_STYLE (tmp_list->data)->styles = style->styles->next;
545 tmp_list = tmp_list->next;
547 g_slist_free_1 (style->styles);
551 g_slist_foreach (style->icon_factories, (GFunc) g_object_unref, NULL);
552 g_slist_free (style->icon_factories);
554 pango_font_description_free (style->font_desc);
556 if (style->private_font_desc)
557 pango_font_description_free (style->private_font_desc);
560 g_object_unref (style->rc_style);
564 if (priv->context_changed_id)
565 g_signal_handler_disconnect (priv->context, priv->context_changed_id);
567 g_object_unref (priv->context);
570 for (i = 0; i < 5; i++)
572 if (style->background[i])
573 cairo_pattern_destroy (style->background[i]);
576 G_OBJECT_CLASS (gtk_style_parent_class)->finalize (object);
580 gtk_style_set_property (GObject *object,
585 GtkStylePrivate *priv;
587 priv = GTK_STYLE_GET_PRIVATE (object);
592 priv->context = g_value_dup_object (value);
595 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
601 gtk_style_get_property (GObject *object,
606 GtkStylePrivate *priv;
608 priv = GTK_STYLE_GET_PRIVATE (object);
613 g_value_set_object (value, priv->context);
616 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
622 set_color (GtkStyle *style,
623 GtkStyleContext *context,
628 GdkRGBA *color = NULL;
629 GdkColor *dest = { 0 }; /* Shut up gcc */
633 case GTK_STATE_ACTIVE:
634 flags = GTK_STATE_FLAG_ACTIVE;
636 case GTK_STATE_PRELIGHT:
637 flags = GTK_STATE_FLAG_PRELIGHT;
639 case GTK_STATE_SELECTED:
640 flags = GTK_STATE_FLAG_SELECTED;
642 case GTK_STATE_INSENSITIVE:
643 flags = GTK_STATE_FLAG_INSENSITIVE;
652 gtk_style_context_get (context, flags,
653 "background-color", &color,
655 dest = &style->bg[state];
658 gtk_style_context_get (context, flags,
661 dest = &style->fg[state];
664 gtk_style_context_get (context, flags,
667 dest = &style->text[state];
670 gtk_style_context_get (context, flags,
671 "background-color", &color,
673 dest = &style->base[state];
680 dest->red = CLAMP ((guint) (color->red * 65535), 0, 65535);
681 dest->green = CLAMP ((guint) (color->green * 65535), 0, 65535);
682 dest->blue = CLAMP ((guint) (color->blue * 65535), 0, 65535);
683 gdk_rgba_free (color);
688 gtk_style_update_from_context (GtkStyle *style)
690 GtkStylePrivate *priv;
695 priv = GTK_STYLE_GET_PRIVATE (style);
697 for (state = GTK_STATE_NORMAL; state <= GTK_STATE_INSENSITIVE; state++)
699 if (gtk_style_context_has_class (priv->context, "entry"))
701 gtk_style_context_save (priv->context);
702 gtk_style_context_remove_class (priv->context, "entry");
703 set_color (style, priv->context, state, GTK_RC_BG);
704 set_color (style, priv->context, state, GTK_RC_FG);
705 gtk_style_context_restore (priv->context);
707 set_color (style, priv->context, state, GTK_RC_BASE);
708 set_color (style, priv->context, state, GTK_RC_TEXT);
712 gtk_style_context_save (priv->context);
713 gtk_style_context_add_class (priv->context, "entry");
714 set_color (style, priv->context, state, GTK_RC_BASE);
715 set_color (style, priv->context, state, GTK_RC_TEXT);
716 gtk_style_context_restore (priv->context);
718 set_color (style, priv->context, state, GTK_RC_BG);
719 set_color (style, priv->context, state, GTK_RC_FG);
723 if (style->font_desc)
724 pango_font_description_free (style->font_desc);
726 gtk_style_context_get (priv->context, 0,
727 "font", &style->font_desc,
729 gtk_style_context_get_padding (priv->context, 0, &padding);
731 style->xthickness = padding.left;
732 style->ythickness = padding.top;
734 for (i = 0; i < 5; i++)
736 _gtk_style_shade (&style->bg[i], &style->light[i], LIGHTNESS_MULT);
737 _gtk_style_shade (&style->bg[i], &style->dark[i], DARKNESS_MULT);
739 style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
740 style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
741 style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
743 style->text_aa[i].red = (style->text[i].red + style->base[i].red) / 2;
744 style->text_aa[i].green = (style->text[i].green + style->base[i].green) / 2;
745 style->text_aa[i].blue = (style->text[i].blue + style->base[i].blue) / 2;
748 style->black.red = 0x0000;
749 style->black.green = 0x0000;
750 style->black.blue = 0x0000;
752 style->white.red = 0xffff;
753 style->white.green = 0xffff;
754 style->white.blue = 0xffff;
756 for (i = 0; i < 5; i++)
758 if (style->background[i])
759 cairo_pattern_destroy (style->background[i]);
761 style->background[i] = cairo_pattern_create_rgb (style->bg[i].red / 65535.0,
762 style->bg[i].green / 65535.0,
763 style->bg[i].blue / 65535.0);
768 style_context_changed (GtkStyleContext *context,
771 gtk_style_update_from_context (GTK_STYLE (user_data));
775 gtk_style_constructed (GObject *object)
777 GtkStylePrivate *priv;
779 priv = GTK_STYLE_GET_PRIVATE (object);
783 gtk_style_update_from_context (GTK_STYLE (object));
785 priv->context_changed_id = g_signal_connect (priv->context, "changed",
786 G_CALLBACK (style_context_changed), object);
792 * @style: a #GtkStyle
794 * Creates a copy of the passed in #GtkStyle object.
796 * Returns: (transfer full): a copy of @style
798 * Deprecated:3.0: Use #GtkStyleContext instead
801 gtk_style_copy (GtkStyle *style)
805 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
807 new_style = GTK_STYLE_GET_CLASS (style)->clone (style);
808 GTK_STYLE_GET_CLASS (style)->copy (new_style, style);
814 _gtk_style_new_for_path (GdkScreen *screen,
817 GtkStyleContext *context;
820 context = gtk_style_context_new ();
823 gtk_style_context_set_screen (context, screen);
825 gtk_style_context_set_path (context, path);
827 style = g_object_new (GTK_TYPE_STYLE,
831 g_object_unref (context);
839 * Creates a new #GtkStyle.
841 * Returns: a new #GtkStyle.
843 * Deprecated: 3.0: Use #GtkStyleContext
851 path = gtk_widget_path_new ();
852 gtk_widget_path_append_type (path, GTK_TYPE_WIDGET);
854 style = _gtk_style_new_for_path (gdk_screen_get_default (), path);
856 gtk_widget_path_free (path);
862 * gtk_style_has_context:
863 * @style: a #GtkStyle
865 * Returns whether @style has an associated #GtkStyleContext.
867 * Returns: %TRUE if @style has a #GtkStyleContext
872 gtk_style_has_context (GtkStyle *style)
874 GtkStylePrivate *priv;
876 priv = GTK_STYLE_GET_PRIVATE (style);
878 return priv->context != NULL;
882 * gtk_style_attach: (skip)
883 * @style: a #GtkStyle.
884 * @window: a #GdkWindow.
886 * Attaches a style to a window; this process allocates the
887 * colors and creates the GC's for the style - it specializes
888 * it to a particular visual. The process may involve the creation
889 * of a new style if the style has already been attached to a
890 * window with a different style and visual.
892 * Since this function may return a new object, you have to use it
893 * in the following way:
894 * <literal>style = gtk_style_attach (style, window)</literal>
896 * Returns: Either @style, or a newly-created #GtkStyle.
897 * If the style is newly created, the style parameter
898 * will be unref'ed, and the new style will have
899 * a reference count belonging to the caller.
901 * Deprecated:3.0: Use gtk_widget_style_attach() instead
904 gtk_style_attach (GtkStyle *style,
907 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
908 g_return_val_if_fail (window != NULL, NULL);
915 * @style: a #GtkStyle
917 * Detaches a style from a window. If the style is not attached
918 * to any windows anymore, it is unrealized. See gtk_style_attach().
920 * Deprecated:3.0: Use #GtkStyleContext instead
923 gtk_style_detach (GtkStyle *style)
925 g_return_if_fail (GTK_IS_STYLE (style));
929 * gtk_style_lookup_icon_set:
930 * @style: a #GtkStyle
931 * @stock_id: an icon name
933 * Looks up @stock_id in the icon factories associated with @style
934 * and the default icon factory, returning an icon set if found,
937 * Return value: (transfer none): icon set of @stock_id
939 * Deprecated:3.0: Use gtk_style_context_lookup_icon_set() instead
942 gtk_style_lookup_icon_set (GtkStyle *style,
943 const char *stock_id)
945 GtkStylePrivate *priv;
947 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
948 g_return_val_if_fail (stock_id != NULL, NULL);
950 priv = GTK_STYLE_GET_PRIVATE (style);
953 return gtk_style_context_lookup_icon_set (priv->context, stock_id);
955 return gtk_icon_factory_lookup_default (stock_id);
959 * gtk_style_lookup_color:
960 * @style: a #GtkStyle
961 * @color_name: the name of the logical color to look up
962 * @color: (out): the #GdkColor to fill in
964 * Looks up @color_name in the style's logical color mappings,
965 * filling in @color and returning %TRUE if found, otherwise
966 * returning %FALSE. Do not cache the found mapping, because
967 * it depends on the #GtkStyle and might change when a theme
970 * Return value: %TRUE if the mapping was found.
974 * Deprecated:3.0: Use gtk_style_context_lookup_color() instead
977 gtk_style_lookup_color (GtkStyle *style,
978 const char *color_name,
981 GtkStylePrivate *priv;
985 g_return_val_if_fail (GTK_IS_STYLE (style), FALSE);
986 g_return_val_if_fail (color_name != NULL, FALSE);
987 g_return_val_if_fail (color != NULL, FALSE);
989 priv = GTK_STYLE_GET_PRIVATE (style);
994 result = gtk_style_context_lookup_color (priv->context, color_name, &rgba);
998 color->red = (guint16) (rgba.red * 65535);
999 color->green = (guint16) (rgba.green * 65535);
1000 color->blue = (guint16) (rgba.blue * 65535);
1008 * gtk_style_set_background:
1009 * @style: a #GtkStyle
1010 * @window: a #GdkWindow
1011 * @state_type: a state
1013 * Sets the background of @window to the background color or pixmap
1014 * specified by @style for the given state.
1016 * Deprecated:3.0: Use gtk_style_context_set_background() instead
1019 gtk_style_set_background (GtkStyle *style,
1021 GtkStateType state_type)
1023 g_return_if_fail (GTK_IS_STYLE (style));
1024 g_return_if_fail (window != NULL);
1026 GTK_STYLE_GET_CLASS (style)->set_background (style, window, state_type);
1029 /* Default functions */
1031 gtk_style_real_clone (GtkStyle *style)
1033 GtkStylePrivate *priv;
1035 priv = GTK_STYLE_GET_PRIVATE (style);
1037 return g_object_new (G_OBJECT_TYPE (style),
1038 "context", priv->context,
1043 gtk_style_real_copy (GtkStyle *style,
1048 for (i = 0; i < 5; i++)
1050 style->fg[i] = src->fg[i];
1051 style->bg[i] = src->bg[i];
1052 style->text[i] = src->text[i];
1053 style->base[i] = src->base[i];
1055 if (style->background[i])
1056 cairo_pattern_destroy (style->background[i]),
1057 style->background[i] = src->background[i];
1058 if (style->background[i])
1059 cairo_pattern_reference (style->background[i]);
1062 if (style->font_desc)
1063 pango_font_description_free (style->font_desc);
1065 style->font_desc = pango_font_description_copy (src->font_desc);
1067 style->font_desc = NULL;
1069 style->xthickness = src->xthickness;
1070 style->ythickness = src->ythickness;
1072 if (style->rc_style)
1073 g_object_unref (style->rc_style);
1074 style->rc_style = src->rc_style;
1076 g_object_ref (src->rc_style);
1078 g_slist_foreach (style->icon_factories, (GFunc) g_object_unref, NULL);
1079 g_slist_free (style->icon_factories);
1080 style->icon_factories = g_slist_copy (src->icon_factories);
1081 g_slist_foreach (style->icon_factories, (GFunc) g_object_ref, NULL);
1085 gtk_style_real_init_from_rc (GtkStyle *style,
1086 GtkRcStyle *rc_style)
1091 * gtk_style_get_style_property:
1092 * @style: a #GtkStyle
1093 * @widget_type: the #GType of a descendant of #GtkWidget
1094 * @property_name: the name of the style property to get
1095 * @value: a #GValue where the value of the property being
1096 * queried will be stored
1098 * Queries the value of a style property corresponding to a
1099 * widget class is in the given style.
1104 gtk_style_get_style_property (GtkStyle *style,
1106 const gchar *property_name,
1109 GtkStylePrivate *priv;
1110 GtkWidgetClass *klass;
1112 const GValue *peek_value;
1114 klass = g_type_class_ref (widget_type);
1115 pspec = gtk_widget_class_find_style_property (klass, property_name);
1116 g_type_class_unref (klass);
1120 g_warning ("%s: widget class `%s' has no property named `%s'",
1122 g_type_name (widget_type),
1127 priv = GTK_STYLE_GET_PRIVATE (style);
1128 peek_value = _gtk_style_context_peek_style_property (priv->context,
1132 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
1133 g_value_copy (peek_value, value);
1134 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
1135 g_value_transform (peek_value, value);
1137 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
1139 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1140 G_VALUE_TYPE_NAME (value));
1144 * gtk_style_get_valist:
1145 * @style: a #GtkStyle
1146 * @widget_type: the #GType of a descendant of #GtkWidget
1147 * @first_property_name: the name of the first style property to get
1148 * @var_args: a <type>va_list</type> of pairs of property names and
1149 * locations to return the property values, starting with the
1150 * location for @first_property_name.
1152 * Non-vararg variant of gtk_style_get().
1153 * Used primarily by language bindings.
1158 gtk_style_get_valist (GtkStyle *style,
1160 const gchar *first_property_name,
1163 GtkStylePrivate *priv;
1164 const char *property_name;
1165 GtkWidgetClass *klass;
1167 g_return_if_fail (GTK_IS_STYLE (style));
1169 klass = g_type_class_ref (widget_type);
1171 priv = GTK_STYLE_GET_PRIVATE (style);
1172 property_name = first_property_name;
1173 while (property_name)
1176 const GValue *peek_value;
1179 pspec = gtk_widget_class_find_style_property (klass, property_name);
1183 g_warning ("%s: widget class `%s' has no property named `%s'",
1185 g_type_name (widget_type),
1190 peek_value = _gtk_style_context_peek_style_property (priv->context, widget_type,
1192 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
1195 g_warning ("%s: %s", G_STRLOC, error);
1200 property_name = va_arg (var_args, gchar*);
1203 g_type_class_unref (klass);
1208 * @style: a #GtkStyle
1209 * @widget_type: the #GType of a descendant of #GtkWidget
1210 * @first_property_name: the name of the first style property to get
1211 * @...: pairs of property names and locations to
1212 * return the property values, starting with the location for
1213 * @first_property_name, terminated by %NULL.
1215 * Gets the values of a multiple style properties for @widget_type
1221 gtk_style_get (GtkStyle *style,
1223 const gchar *first_property_name,
1228 va_start (var_args, first_property_name);
1229 gtk_style_get_valist (style, widget_type, first_property_name, var_args);
1234 gtk_style_real_realize (GtkStyle *style)
1239 gtk_style_real_unrealize (GtkStyle *style)
1244 gtk_style_real_set_background (GtkStyle *style,
1246 GtkStateType state_type)
1248 gdk_window_set_background_pattern (window, style->background[state_type]);
1252 * gtk_style_render_icon:
1253 * @style: a #GtkStyle
1254 * @source: the #GtkIconSource specifying the icon to render
1255 * @direction: a text direction
1257 * @size: (type int): the size to render the icon at. A size of
1258 * (GtkIconSize)-1 means render at the size of the source and
1260 * @widget: (allow-none): the widget
1261 * @detail: (allow-none): a style detail
1263 * Renders the icon specified by @source at the given @size
1264 * according to the given parameters and returns the result in a
1267 * Return value: (transfer full): a newly-created #GdkPixbuf
1268 * containing the rendered icon
1270 * Deprecated:3.0: Use gtk_render_icon_pixbuf() instead
1273 gtk_style_render_icon (GtkStyle *style,
1274 const GtkIconSource *source,
1275 GtkTextDirection direction,
1279 const gchar *detail)
1283 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1284 g_return_val_if_fail (GTK_STYLE_GET_CLASS (style)->render_icon != NULL, NULL);
1286 pixbuf = GTK_STYLE_GET_CLASS (style)->render_icon (style, source, direction, state,
1287 size, widget, detail);
1289 g_return_val_if_fail (pixbuf != NULL, NULL);
1294 /* Default functions */
1297 * gtk_style_apply_default_background:
1307 * Deprecated:3.0: Use #GtkStyleContext instead
1310 gtk_style_apply_default_background (GtkStyle *style,
1313 GtkStateType state_type,
1321 if (style->background[state_type] == NULL)
1323 GdkWindow *parent = gdk_window_get_parent (window);
1324 int x_offset, y_offset;
1328 gdk_window_get_position (window, &x_offset, &y_offset);
1329 cairo_translate (cr, -x_offset, -y_offset);
1330 gtk_style_apply_default_background (style, cr,
1332 x + x_offset, y + y_offset,
1337 gdk_cairo_set_source_color (cr, &style->bg[state_type]);
1340 cairo_set_source (cr, style->background[state_type]);
1342 cairo_rectangle (cr, x, y, width, height);
1350 gtk_default_render_icon (GtkStyle *style,
1351 const GtkIconSource *source,
1352 GtkTextDirection direction,
1356 const gchar *detail)
1358 GtkStyleContext *context;
1359 GtkStylePrivate *priv;
1360 GtkStateFlags flags = 0;
1364 context = gtk_widget_get_style_context (widget);
1367 priv = GTK_STYLE_GET_PRIVATE (style);
1368 context = priv->context;
1374 gtk_style_context_save (context);
1377 transform_detail_string (detail, context);
1381 case GTK_STATE_PRELIGHT:
1382 flags |= GTK_STATE_FLAG_PRELIGHT;
1384 case GTK_STATE_INSENSITIVE:
1385 flags |= GTK_STATE_FLAG_INSENSITIVE;
1391 gtk_style_context_set_state (context, flags);
1393 pixbuf = gtk_render_icon_pixbuf (context, source, size);
1395 gtk_style_context_restore (context);
1401 _cairo_draw_line (cairo_t *cr,
1410 gdk_cairo_set_source_color (cr, color);
1411 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
1413 cairo_move_to (cr, x1 + 0.5, y1 + 0.5);
1414 cairo_line_to (cr, x2 + 0.5, y2 + 0.5);
1421 transform_detail_string (const gchar *detail,
1422 GtkStyleContext *context)
1427 if (strcmp (detail, "arrow") == 0)
1428 gtk_style_context_add_class (context, "arrow");
1429 else if (strcmp (detail, "button") == 0)
1430 gtk_style_context_add_class (context, "button");
1431 else if (strcmp (detail, "buttondefault") == 0)
1433 gtk_style_context_add_class (context, "button");
1434 gtk_style_context_add_class (context, "default");
1436 else if (strcmp (detail, "calendar") == 0)
1437 gtk_style_context_add_class (context, "calendar");
1438 else if (strcmp (detail, "cellcheck") == 0)
1440 gtk_style_context_add_class (context, "cell");
1441 gtk_style_context_add_class (context, "check");
1443 else if (strcmp (detail, "cellradio") == 0)
1445 gtk_style_context_add_class (context, "cell");
1446 gtk_style_context_add_class (context, "radio");
1448 else if (strcmp (detail, "checkbutton") == 0)
1449 gtk_style_context_add_class (context, "check");
1450 else if (strcmp (detail, "check") == 0)
1452 gtk_style_context_add_class (context, "check");
1453 gtk_style_context_add_class (context, "menu");
1455 else if (strcmp (detail, "radiobutton") == 0)
1457 gtk_style_context_add_class (context, "radio");
1459 else if (strcmp (detail, "option") == 0)
1461 gtk_style_context_add_class (context, "radio");
1462 gtk_style_context_add_class (context, "menu");
1464 else if (strcmp (detail, "entry") == 0 ||
1465 strcmp (detail, "entry_bg") == 0)
1466 gtk_style_context_add_class (context, "entry");
1467 else if (strcmp (detail, "expander") == 0)
1468 gtk_style_context_add_class (context, "expander");
1469 else if (strcmp (detail, "tooltip") == 0)
1470 gtk_style_context_add_class (context, "tooltip");
1471 else if (strcmp (detail, "frame") == 0)
1472 gtk_style_context_add_class (context, "frame");
1473 else if (strcmp (detail, "scrolled_window") == 0)
1474 gtk_style_context_add_class (context, "scrolled-window");
1475 else if (strcmp (detail, "viewport") == 0 ||
1476 strcmp (detail, "viewportbin") == 0)
1477 gtk_style_context_add_class (context, "viewport");
1478 else if (strncmp (detail, "trough", 6) == 0)
1479 gtk_style_context_add_class (context, "trough");
1480 else if (strcmp (detail, "spinbutton") == 0)
1481 gtk_style_context_add_class (context, "spinbutton");
1482 else if (strcmp (detail, "spinbutton_up") == 0)
1484 gtk_style_context_add_class (context, "spinbutton");
1485 gtk_style_context_add_class (context, "button");
1486 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
1488 else if (strcmp (detail, "spinbutton_down") == 0)
1490 gtk_style_context_add_class (context, "spinbutton");
1491 gtk_style_context_add_class (context, "button");
1492 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
1494 else if ((detail[0] == 'h' || detail[0] == 'v') &&
1495 strncmp (&detail[1], "scrollbar_", 10) == 0)
1497 gtk_style_context_add_class (context, "button");
1498 gtk_style_context_add_class (context, "scrollbar");
1500 else if (strcmp (detail, "slider") == 0)
1502 gtk_style_context_add_class (context, "slider");
1503 gtk_style_context_add_class (context, "scrollbar");
1505 else if (strcmp (detail, "vscale") == 0 ||
1506 strcmp (detail, "hscale") == 0)
1508 gtk_style_context_add_class (context, "slider");
1509 gtk_style_context_add_class (context, "scale");
1511 else if (strcmp (detail, "menuitem") == 0)
1513 gtk_style_context_add_class (context, "menuitem");
1514 gtk_style_context_add_class (context, "menu");
1516 else if (strcmp (detail, "menu") == 0)
1518 gtk_style_context_add_class (context, "popup");
1519 gtk_style_context_add_class (context, "menu");
1521 else if (strcmp (detail, "accellabel") == 0)
1522 gtk_style_context_add_class (context, "accelerator");
1523 else if (strcmp (detail, "menubar") == 0)
1524 gtk_style_context_add_class (context, "menubar");
1525 else if (strcmp (detail, "base") == 0)
1526 gtk_style_context_add_class (context, "background");
1527 else if (strcmp (detail, "bar") == 0 ||
1528 strcmp (detail, "progressbar") == 0)
1529 gtk_style_context_add_class (context, "progressbar");
1530 else if (strcmp (detail, "toolbar") == 0)
1531 gtk_style_context_add_class (context, "toolbar");
1532 else if (strcmp (detail, "handlebox_bin") == 0)
1533 gtk_style_context_add_class (context, "dock");
1534 else if (strcmp (detail, "notebook") == 0)
1535 gtk_style_context_add_class (context, "notebook");
1536 else if (strcmp (detail, "tab") == 0)
1538 gtk_style_context_add_class (context, "notebook");
1539 gtk_style_context_add_region (context, GTK_STYLE_REGION_TAB, 0);
1541 else if (g_str_has_prefix (detail, "cell"))
1543 GtkRegionFlags row, col;
1544 gboolean ruled = FALSE;
1548 tokens = g_strsplit (detail, "_", -1);
1554 if (strcmp (tokens[i], "even") == 0)
1555 row |= GTK_REGION_EVEN;
1556 else if (strcmp (tokens[i], "odd") == 0)
1557 row |= GTK_REGION_ODD;
1558 else if (strcmp (tokens[i], "start") == 0)
1559 col |= GTK_REGION_FIRST;
1560 else if (strcmp (tokens[i], "end") == 0)
1561 col |= GTK_REGION_LAST;
1562 else if (strcmp (tokens[i], "ruled") == 0)
1564 else if (strcmp (tokens[i], "sorted") == 0)
1565 col |= GTK_REGION_SORTED;
1571 row &= ~(GTK_REGION_EVEN | GTK_REGION_ODD);
1573 gtk_style_context_add_class (context, "cell");
1574 gtk_style_context_add_region (context, "row", row);
1575 gtk_style_context_add_region (context, "column", col);
1577 g_strfreev (tokens);
1582 gtk_default_draw_hline (GtkStyle *style,
1584 GtkStateType state_type,
1586 const gchar *detail,
1591 GtkStyleContext *context;
1592 GtkStylePrivate *priv;
1595 context = gtk_widget_get_style_context (widget);
1598 priv = GTK_STYLE_GET_PRIVATE (style);
1599 context = priv->context;
1602 gtk_style_context_save (context);
1605 transform_detail_string (detail, context);
1609 gtk_render_line (context, cr,
1614 gtk_style_context_restore (context);
1619 gtk_default_draw_vline (GtkStyle *style,
1621 GtkStateType state_type,
1623 const gchar *detail,
1628 GtkStyleContext *context;
1629 GtkStylePrivate *priv;
1632 context = gtk_widget_get_style_context (widget);
1635 priv = GTK_STYLE_GET_PRIVATE (style);
1636 context = priv->context;
1639 gtk_style_context_save (context);
1642 transform_detail_string (detail, context);
1646 gtk_render_line (context, cr,
1650 gtk_style_context_restore (context);
1654 gtk_default_draw_shadow (GtkStyle *style,
1656 GtkStateType state_type,
1657 GtkShadowType shadow_type,
1659 const gchar *detail,
1665 GtkStyleContext *context;
1666 GtkStylePrivate *priv;
1668 if (shadow_type == GTK_SHADOW_NONE)
1672 context = gtk_widget_get_style_context (widget);
1675 priv = GTK_STYLE_GET_PRIVATE (style);
1676 context = priv->context;
1679 gtk_style_context_save (context);
1682 transform_detail_string (detail, context);
1686 gtk_render_frame (context, cr,
1693 gtk_style_context_restore (context);
1697 draw_arrow (cairo_t *cr,
1699 GtkArrowType arrow_type,
1705 gdk_cairo_set_source_color (cr, color);
1708 if (arrow_type == GTK_ARROW_DOWN)
1710 cairo_move_to (cr, x, y);
1711 cairo_line_to (cr, x + width, y);
1712 cairo_line_to (cr, x + width / 2., y + height);
1714 else if (arrow_type == GTK_ARROW_UP)
1716 cairo_move_to (cr, x, y + height);
1717 cairo_line_to (cr, x + width / 2., y);
1718 cairo_line_to (cr, x + width, y + height);
1720 else if (arrow_type == GTK_ARROW_LEFT)
1722 cairo_move_to (cr, x + width, y);
1723 cairo_line_to (cr, x + width, y + height);
1724 cairo_line_to (cr, x, y + height / 2.);
1726 else if (arrow_type == GTK_ARROW_RIGHT)
1728 cairo_move_to (cr, x, y);
1729 cairo_line_to (cr, x + width, y + height / 2.);
1730 cairo_line_to (cr, x, y + height);
1733 cairo_close_path (cr);
1740 gtk_default_draw_arrow (GtkStyle *style,
1743 GtkShadowType shadow,
1745 const gchar *detail,
1746 GtkArrowType arrow_type,
1753 GtkStyleContext *context;
1754 GtkStylePrivate *priv;
1755 GtkStateFlags flags = 0;
1756 gdouble angle, size;
1758 if (arrow_type == GTK_ARROW_NONE)
1762 context = gtk_widget_get_style_context (widget);
1765 priv = GTK_STYLE_GET_PRIVATE (style);
1766 context = priv->context;
1769 gtk_style_context_save (context);
1772 transform_detail_string (detail, context);
1780 case GTK_ARROW_RIGHT:
1784 case GTK_ARROW_DOWN:
1788 case GTK_ARROW_LEFT:
1789 angle = 3 * (G_PI / 2);
1793 g_assert_not_reached ();
1798 case GTK_STATE_PRELIGHT:
1799 flags |= GTK_STATE_FLAG_PRELIGHT;
1801 case GTK_STATE_SELECTED:
1802 flags |= GTK_STATE_FLAG_SELECTED;
1804 case GTK_STATE_INSENSITIVE:
1805 flags |= GTK_STATE_FLAG_INSENSITIVE;
1807 case GTK_STATE_ACTIVE:
1808 flags |= GTK_STATE_FLAG_ACTIVE;
1814 gtk_style_context_set_state (context, flags);
1818 gtk_render_arrow (context,
1825 gtk_style_context_restore (context);
1829 gtk_default_draw_diamond (GtkStyle *style,
1831 GtkStateType state_type,
1832 GtkShadowType shadow_type,
1834 const gchar *detail,
1842 GdkColor *outer_nw = NULL;
1843 GdkColor *outer_ne = NULL;
1844 GdkColor *outer_sw = NULL;
1845 GdkColor *outer_se = NULL;
1846 GdkColor *middle_nw = NULL;
1847 GdkColor *middle_ne = NULL;
1848 GdkColor *middle_sw = NULL;
1849 GdkColor *middle_se = NULL;
1850 GdkColor *inner_nw = NULL;
1851 GdkColor *inner_ne = NULL;
1852 GdkColor *inner_sw = NULL;
1853 GdkColor *inner_se = NULL;
1855 half_width = width / 2;
1856 half_height = height / 2;
1858 switch (shadow_type)
1861 inner_sw = inner_se = &style->bg[state_type];
1862 middle_sw = middle_se = &style->light[state_type];
1863 outer_sw = outer_se = &style->light[state_type];
1864 inner_nw = inner_ne = &style->black;
1865 middle_nw = middle_ne = &style->dark[state_type];
1866 outer_nw = outer_ne = &style->dark[state_type];
1869 case GTK_SHADOW_OUT:
1870 inner_sw = inner_se = &style->dark[state_type];
1871 middle_sw = middle_se = &style->dark[state_type];
1872 outer_sw = outer_se = &style->black;
1873 inner_nw = inner_ne = &style->bg[state_type];
1874 middle_nw = middle_ne = &style->light[state_type];
1875 outer_nw = outer_ne = &style->light[state_type];
1878 case GTK_SHADOW_ETCHED_IN:
1879 inner_sw = inner_se = &style->bg[state_type];
1880 middle_sw = middle_se = &style->dark[state_type];
1881 outer_sw = outer_se = &style->light[state_type];
1882 inner_nw = inner_ne = &style->bg[state_type];
1883 middle_nw = middle_ne = &style->light[state_type];
1884 outer_nw = outer_ne = &style->dark[state_type];
1887 case GTK_SHADOW_ETCHED_OUT:
1888 inner_sw = inner_se = &style->bg[state_type];
1889 middle_sw = middle_se = &style->light[state_type];
1890 outer_sw = outer_se = &style->dark[state_type];
1891 inner_nw = inner_ne = &style->bg[state_type];
1892 middle_nw = middle_ne = &style->dark[state_type];
1893 outer_nw = outer_ne = &style->light[state_type];
1903 _cairo_draw_line (cr, inner_sw,
1904 x + 2, y + half_height,
1905 x + half_width, y + height - 2);
1906 _cairo_draw_line (cr, inner_se,
1907 x + half_width, y + height - 2,
1908 x + width - 2, y + half_height);
1909 _cairo_draw_line (cr, middle_sw,
1910 x + 1, y + half_height,
1911 x + half_width, y + height - 1);
1912 _cairo_draw_line (cr, middle_se,
1913 x + half_width, y + height - 1,
1914 x + width - 1, y + half_height);
1915 _cairo_draw_line (cr, outer_sw,
1917 x + half_width, y + height);
1918 _cairo_draw_line (cr, outer_se,
1919 x + half_width, y + height,
1920 x + width, y + half_height);
1922 _cairo_draw_line (cr, inner_nw,
1923 x + 2, y + half_height,
1924 x + half_width, y + 2);
1925 _cairo_draw_line (cr, inner_ne,
1926 x + half_width, y + 2,
1927 x + width - 2, y + half_height);
1928 _cairo_draw_line (cr, middle_nw,
1929 x + 1, y + half_height,
1930 x + half_width, y + 1);
1931 _cairo_draw_line (cr, middle_ne,
1932 x + half_width, y + 1,
1933 x + width - 1, y + half_height);
1934 _cairo_draw_line (cr, outer_nw,
1937 _cairo_draw_line (cr, outer_ne,
1939 x + width, y + half_height);
1944 option_menu_get_props (GtkWidget *widget,
1945 GtkRequisition *indicator_size,
1946 GtkBorder *indicator_spacing)
1948 GtkRequisition *tmp_size = NULL;
1949 GtkBorder *tmp_spacing = NULL;
1953 *indicator_size = *tmp_size;
1954 gtk_requisition_free (tmp_size);
1957 *indicator_size = default_option_indicator_size;
1961 *indicator_spacing = *tmp_spacing;
1962 gtk_border_free (tmp_spacing);
1965 *indicator_spacing = default_option_indicator_spacing;
1969 gtk_default_draw_box (GtkStyle *style,
1971 GtkStateType state_type,
1972 GtkShadowType shadow_type,
1974 const gchar *detail,
1980 GtkStyleContext *context;
1981 GtkStylePrivate *priv;
1982 GtkStateFlags flags = 0;
1985 context = gtk_widget_get_style_context (widget);
1988 priv = GTK_STYLE_GET_PRIVATE (style);
1989 context = priv->context;
1992 gtk_style_context_save (context);
1995 transform_detail_string (detail, context);
1999 case GTK_STATE_ACTIVE:
2000 flags |= GTK_STATE_FLAG_ACTIVE;
2002 case GTK_STATE_PRELIGHT:
2003 flags |= GTK_STATE_FLAG_PRELIGHT;
2005 case GTK_STATE_SELECTED:
2006 flags |= GTK_STATE_FLAG_SELECTED;
2008 case GTK_STATE_INSENSITIVE:
2009 flags |= GTK_STATE_FLAG_INSENSITIVE;
2015 if (shadow_type == GTK_SHADOW_IN)
2016 flags |= GTK_STATE_FLAG_ACTIVE;
2018 gtk_style_context_set_state (context, flags);
2022 if (gtk_style_context_has_class (context, GTK_STYLE_CLASS_PROGRESSBAR))
2023 gtk_render_activity (context, cr, x, y, width, height);
2026 gtk_render_background (context, cr, x, y, width, height);
2028 if (shadow_type != GTK_SHADOW_NONE)
2029 gtk_render_frame (context, cr, x, y, width, height);
2033 gtk_style_context_restore (context);
2037 gtk_default_draw_flat_box (GtkStyle *style,
2039 GtkStateType state_type,
2040 GtkShadowType shadow_type,
2042 const gchar *detail,
2048 GtkStyleContext *context;
2049 GtkStylePrivate *priv;
2050 GtkStateFlags flags = 0;
2053 context = gtk_widget_get_style_context (widget);
2056 priv = GTK_STYLE_GET_PRIVATE (style);
2057 context = priv->context;
2060 gtk_style_context_save (context);
2063 transform_detail_string (detail, context);
2067 case GTK_STATE_PRELIGHT:
2068 flags |= GTK_STATE_FLAG_PRELIGHT;
2070 case GTK_STATE_SELECTED:
2071 flags |= GTK_STATE_FLAG_SELECTED;
2073 case GTK_STATE_INSENSITIVE:
2074 flags |= GTK_STATE_FLAG_INSENSITIVE;
2076 case GTK_STATE_ACTIVE:
2077 flags |= GTK_STATE_FLAG_ACTIVE;
2079 case GTK_STATE_FOCUSED:
2080 flags |= GTK_STATE_FLAG_FOCUSED;
2086 gtk_style_context_set_state (context, flags);
2090 gtk_render_background (context, cr,
2097 gtk_style_context_restore (context);
2101 gtk_default_draw_check (GtkStyle *style,
2103 GtkStateType state_type,
2104 GtkShadowType shadow_type,
2106 const gchar *detail,
2112 GtkStyleContext *context;
2113 GtkStylePrivate *priv;
2114 GtkStateFlags flags = 0;
2117 context = gtk_widget_get_style_context (widget);
2120 priv = GTK_STYLE_GET_PRIVATE (style);
2121 context = priv->context;
2124 gtk_style_context_save (context);
2127 transform_detail_string (detail, context);
2131 case GTK_STATE_PRELIGHT:
2132 flags |= GTK_STATE_FLAG_PRELIGHT;
2134 case GTK_STATE_SELECTED:
2135 flags |= GTK_STATE_FLAG_SELECTED;
2137 case GTK_STATE_INSENSITIVE:
2138 flags |= GTK_STATE_FLAG_INSENSITIVE;
2144 if (shadow_type == GTK_SHADOW_IN)
2145 flags |= GTK_STATE_FLAG_ACTIVE;
2146 else if (shadow_type == GTK_SHADOW_ETCHED_IN)
2147 flags |= GTK_STATE_FLAG_INCONSISTENT;
2149 gtk_style_context_set_state (context, flags);
2153 gtk_render_check (context,
2158 gtk_style_context_restore (context);
2162 gtk_default_draw_option (GtkStyle *style,
2164 GtkStateType state_type,
2165 GtkShadowType shadow_type,
2167 const gchar *detail,
2173 GtkStyleContext *context;
2174 GtkStylePrivate *priv;
2175 GtkStateFlags flags = 0;
2178 context = gtk_widget_get_style_context (widget);
2181 priv = GTK_STYLE_GET_PRIVATE (style);
2182 context = priv->context;
2185 gtk_style_context_save (context);
2188 transform_detail_string (detail, context);
2192 case GTK_STATE_PRELIGHT:
2193 flags |= GTK_STATE_FLAG_PRELIGHT;
2195 case GTK_STATE_SELECTED:
2196 flags |= GTK_STATE_FLAG_SELECTED;
2198 case GTK_STATE_INSENSITIVE:
2199 flags |= GTK_STATE_FLAG_INSENSITIVE;
2205 if (shadow_type == GTK_SHADOW_IN)
2206 flags |= GTK_STATE_FLAG_ACTIVE;
2207 else if (shadow_type == GTK_SHADOW_ETCHED_IN)
2208 flags |= GTK_STATE_FLAG_INCONSISTENT;
2210 gtk_style_context_set_state (context, flags);
2213 gtk_render_option (context, cr,
2220 gtk_style_context_restore (context);
2224 gtk_default_draw_tab (GtkStyle *style,
2226 GtkStateType state_type,
2227 GtkShadowType shadow_type,
2229 const gchar *detail,
2235 #define ARROW_SPACE 4
2237 GtkRequisition indicator_size;
2238 GtkBorder indicator_spacing;
2241 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
2243 indicator_size.width += (indicator_size.width % 2) - 1;
2244 arrow_height = indicator_size.width / 2 + 1;
2246 x += (width - indicator_size.width) / 2;
2247 y += (height - (2 * arrow_height + ARROW_SPACE)) / 2;
2249 if (state_type == GTK_STATE_INSENSITIVE)
2251 draw_arrow (cr, &style->white,
2252 GTK_ARROW_UP, x + 1, y + 1,
2253 indicator_size.width, arrow_height);
2255 draw_arrow (cr, &style->white,
2256 GTK_ARROW_DOWN, x + 1, y + arrow_height + ARROW_SPACE + 1,
2257 indicator_size.width, arrow_height);
2260 draw_arrow (cr, &style->fg[state_type],
2262 indicator_size.width, arrow_height);
2265 draw_arrow (cr, &style->fg[state_type],
2266 GTK_ARROW_DOWN, x, y + arrow_height + ARROW_SPACE,
2267 indicator_size.width, arrow_height);
2271 gtk_default_draw_shadow_gap (GtkStyle *style,
2273 GtkStateType state_type,
2274 GtkShadowType shadow_type,
2276 const gchar *detail,
2281 GtkPositionType gap_side,
2285 GtkStyleContext *context;
2286 GtkStylePrivate *priv;
2287 GtkStateFlags flags = 0;
2289 if (shadow_type == GTK_SHADOW_NONE)
2293 context = gtk_widget_get_style_context (widget);
2296 priv = GTK_STYLE_GET_PRIVATE (style);
2297 context = priv->context;
2300 gtk_style_context_save (context);
2303 transform_detail_string (detail, context);
2307 case GTK_STATE_ACTIVE:
2308 flags |= GTK_STATE_FLAG_ACTIVE;
2310 case GTK_STATE_PRELIGHT:
2311 flags |= GTK_STATE_FLAG_PRELIGHT;
2313 case GTK_STATE_SELECTED:
2314 flags |= GTK_STATE_FLAG_SELECTED;
2316 case GTK_STATE_INSENSITIVE:
2317 flags |= GTK_STATE_FLAG_INSENSITIVE;
2323 gtk_style_context_set_state (context, flags);
2326 gtk_render_frame_gap (context, cr,
2333 (gdouble) gap_x + gap_width);
2336 gtk_style_context_restore (context);
2340 gtk_default_draw_box_gap (GtkStyle *style,
2342 GtkStateType state_type,
2343 GtkShadowType shadow_type,
2345 const gchar *detail,
2350 GtkPositionType gap_side,
2354 GtkStyleContext *context;
2355 GtkStylePrivate *priv;
2356 GtkStateFlags flags = 0;
2359 context = gtk_widget_get_style_context (widget);
2362 priv = GTK_STYLE_GET_PRIVATE (style);
2363 context = priv->context;
2366 gtk_style_context_save (context);
2369 transform_detail_string (detail, context);
2373 case GTK_STATE_ACTIVE:
2374 flags |= GTK_STATE_FLAG_ACTIVE;
2376 case GTK_STATE_PRELIGHT:
2377 flags |= GTK_STATE_FLAG_PRELIGHT;
2379 case GTK_STATE_SELECTED:
2380 flags |= GTK_STATE_FLAG_SELECTED;
2382 case GTK_STATE_INSENSITIVE:
2383 flags |= GTK_STATE_FLAG_INSENSITIVE;
2389 gtk_style_context_set_state (context, flags);
2392 gtk_render_background (context, cr,
2399 if (shadow_type != GTK_SHADOW_NONE)
2400 gtk_render_frame_gap (context, cr,
2407 (gdouble) gap_x + gap_width);
2410 gtk_style_context_restore (context);
2414 gtk_default_draw_extension (GtkStyle *style,
2416 GtkStateType state_type,
2417 GtkShadowType shadow_type,
2419 const gchar *detail,
2424 GtkPositionType gap_side)
2426 GtkStyleContext *context;
2427 GtkStylePrivate *priv;
2428 GtkStateFlags flags = 0;
2431 context = gtk_widget_get_style_context (widget);
2434 priv = GTK_STYLE_GET_PRIVATE (style);
2435 context = priv->context;
2438 gtk_style_context_save (context);
2441 transform_detail_string (detail, context);
2445 case GTK_STATE_ACTIVE:
2446 flags |= GTK_STATE_FLAG_ACTIVE;
2448 case GTK_STATE_PRELIGHT:
2449 flags |= GTK_STATE_FLAG_PRELIGHT;
2451 case GTK_STATE_SELECTED:
2452 flags |= GTK_STATE_FLAG_SELECTED;
2454 case GTK_STATE_INSENSITIVE:
2455 flags |= GTK_STATE_FLAG_INSENSITIVE;
2461 gtk_style_context_set_state (context, flags);
2465 gtk_render_extension (context, cr,
2473 gtk_style_context_restore (context);
2477 gtk_default_draw_focus (GtkStyle *style,
2479 GtkStateType state_type,
2481 const gchar *detail,
2487 GtkStyleContext *context;
2488 GtkStylePrivate *priv;
2491 context = gtk_widget_get_style_context (widget);
2494 priv = GTK_STYLE_GET_PRIVATE (style);
2495 context = priv->context;
2498 gtk_style_context_save (context);
2501 transform_detail_string (detail, context);
2505 gtk_render_focus (context, cr,
2512 gtk_style_context_restore (context);
2516 gtk_default_draw_slider (GtkStyle *style,
2518 GtkStateType state_type,
2519 GtkShadowType shadow_type,
2521 const gchar *detail,
2526 GtkOrientation orientation)
2528 GtkStyleContext *context;
2529 GtkStylePrivate *priv;
2530 GtkStateFlags flags = 0;
2533 context = gtk_widget_get_style_context (widget);
2536 priv = GTK_STYLE_GET_PRIVATE (style);
2537 context = priv->context;
2540 gtk_style_context_save (context);
2543 transform_detail_string (detail, context);
2547 case GTK_STATE_PRELIGHT:
2548 flags |= GTK_STATE_FLAG_PRELIGHT;
2550 case GTK_STATE_SELECTED:
2551 flags |= GTK_STATE_FLAG_SELECTED;
2553 case GTK_STATE_INSENSITIVE:
2554 flags |= GTK_STATE_FLAG_INSENSITIVE;
2560 gtk_style_context_set_state (context, flags);
2564 gtk_render_slider (context, cr, x, y, width, height, orientation);
2567 gtk_style_context_restore (context);
2571 gtk_default_draw_handle (GtkStyle *style,
2573 GtkStateType state_type,
2574 GtkShadowType shadow_type,
2576 const gchar *detail,
2581 GtkOrientation orientation)
2583 GtkStyleContext *context;
2584 GtkStylePrivate *priv;
2585 GtkStateFlags flags = 0;
2588 context = gtk_widget_get_style_context (widget);
2591 priv = GTK_STYLE_GET_PRIVATE (style);
2592 context = priv->context;
2595 gtk_style_context_save (context);
2598 transform_detail_string (detail, context);
2602 case GTK_STATE_PRELIGHT:
2603 flags |= GTK_STATE_FLAG_PRELIGHT;
2605 case GTK_STATE_SELECTED:
2606 flags |= GTK_STATE_FLAG_SELECTED;
2608 case GTK_STATE_INSENSITIVE:
2609 flags |= GTK_STATE_FLAG_INSENSITIVE;
2615 gtk_style_context_set_state (context, flags);
2619 gtk_render_handle (context, cr,
2626 gtk_style_context_restore (context);
2630 gtk_default_draw_expander (GtkStyle *style,
2632 GtkStateType state_type,
2634 const gchar *detail,
2637 GtkExpanderStyle expander_style)
2639 GtkStyleContext *context;
2640 GtkStylePrivate *priv;
2641 GtkStateFlags flags = 0;
2645 context = gtk_widget_get_style_context (widget);
2648 priv = GTK_STYLE_GET_PRIVATE (style);
2649 context = priv->context;
2652 gtk_style_context_save (context);
2655 transform_detail_string (detail, context);
2657 gtk_style_context_add_class (context, "expander");
2661 case GTK_STATE_PRELIGHT:
2662 flags |= GTK_STATE_FLAG_PRELIGHT;
2664 case GTK_STATE_SELECTED:
2665 flags |= GTK_STATE_FLAG_SELECTED;
2667 case GTK_STATE_INSENSITIVE:
2668 flags |= GTK_STATE_FLAG_INSENSITIVE;
2675 gtk_widget_class_find_style_property (GTK_WIDGET_GET_CLASS (widget),
2677 gtk_widget_style_get (widget, "expander-size", &size, NULL);
2681 if (expander_style == GTK_EXPANDER_EXPANDED)
2682 flags |= GTK_STATE_FLAG_ACTIVE;
2684 gtk_style_context_set_state (context, flags);
2688 gtk_render_expander (context, cr,
2689 (gdouble) x - (size / 2),
2690 (gdouble) y - (size / 2),
2695 gtk_style_context_restore (context);
2699 gtk_default_draw_layout (GtkStyle *style,
2701 GtkStateType state_type,
2704 const gchar *detail,
2707 PangoLayout *layout)
2709 GtkStyleContext *context;
2710 GtkStylePrivate *priv;
2711 GtkStateFlags flags = 0;
2714 context = gtk_widget_get_style_context (widget);
2717 priv = GTK_STYLE_GET_PRIVATE (style);
2718 context = priv->context;
2721 gtk_style_context_save (context);
2724 transform_detail_string (detail, context);
2728 case GTK_STATE_PRELIGHT:
2729 flags |= GTK_STATE_FLAG_PRELIGHT;
2731 case GTK_STATE_SELECTED:
2732 flags |= GTK_STATE_FLAG_SELECTED;
2734 case GTK_STATE_INSENSITIVE:
2735 flags |= GTK_STATE_FLAG_INSENSITIVE;
2741 gtk_style_context_set_state (context, flags);
2745 gtk_render_layout (context, cr,
2751 gtk_style_context_restore (context);
2755 gtk_default_draw_resize_grip (GtkStyle *style,
2757 GtkStateType state_type,
2759 const gchar *detail,
2766 GtkStyleContext *context;
2767 GtkStylePrivate *priv;
2768 GtkStateFlags flags = 0;
2769 GtkJunctionSides sides = 0;
2772 context = gtk_widget_get_style_context (widget);
2775 priv = GTK_STYLE_GET_PRIVATE (style);
2776 context = priv->context;
2779 gtk_style_context_save (context);
2782 transform_detail_string (detail, context);
2784 gtk_style_context_add_class (context, "grip");
2788 case GTK_STATE_PRELIGHT:
2789 flags |= GTK_STATE_FLAG_PRELIGHT;
2791 case GTK_STATE_SELECTED:
2792 flags |= GTK_STATE_FLAG_SELECTED;
2794 case GTK_STATE_INSENSITIVE:
2795 flags |= GTK_STATE_FLAG_INSENSITIVE;
2801 gtk_style_context_set_state (context, flags);
2805 case GDK_WINDOW_EDGE_NORTH_WEST:
2806 sides = GTK_JUNCTION_CORNER_TOPLEFT;
2808 case GDK_WINDOW_EDGE_NORTH:
2809 sides = GTK_JUNCTION_TOP;
2811 case GDK_WINDOW_EDGE_NORTH_EAST:
2812 sides = GTK_JUNCTION_CORNER_TOPRIGHT;
2814 case GDK_WINDOW_EDGE_WEST:
2815 sides = GTK_JUNCTION_LEFT;
2817 case GDK_WINDOW_EDGE_EAST:
2818 sides = GTK_JUNCTION_RIGHT;
2820 case GDK_WINDOW_EDGE_SOUTH_WEST:
2821 sides = GTK_JUNCTION_CORNER_BOTTOMLEFT;
2823 case GDK_WINDOW_EDGE_SOUTH:
2824 sides = GTK_JUNCTION_BOTTOM;
2826 case GDK_WINDOW_EDGE_SOUTH_EAST:
2827 sides = GTK_JUNCTION_CORNER_BOTTOMRIGHT;
2831 gtk_style_context_set_junction_sides (context, sides);
2835 gtk_render_handle (context, cr,
2842 gtk_style_context_restore (context);
2846 gtk_default_draw_spinner (GtkStyle *style,
2848 GtkStateType state_type,
2850 const gchar *detail,
2866 real_step = step % num_steps;
2868 /* set a clip region for the expose event */
2869 cairo_rectangle (cr, x, y, width, height);
2872 cairo_translate (cr, x, y);
2874 /* draw clip region */
2875 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
2877 color = &style->fg[state_type];
2880 radius = MIN (width / 2, height / 2);
2881 half = num_steps / 2;
2883 for (i = 0; i < num_steps; i++)
2885 gint inset = 0.7 * radius;
2887 /* transparency is a function of time and intial value */
2888 gdouble t = (gdouble) ((i + num_steps - real_step)
2889 % num_steps) / num_steps;
2893 cairo_set_source_rgba (cr,
2894 color->red / 65535.,
2895 color->green / 65535.,
2896 color->blue / 65535.,
2899 cairo_set_line_width (cr, 2.0);
2901 dx + (radius - inset) * cos (i * G_PI / half),
2902 dy + (radius - inset) * sin (i * G_PI / half));
2904 dx + radius * cos (i * G_PI / half),
2905 dy + radius * sin (i * G_PI / half));
2913 _gtk_style_shade (const GdkColor *a,
2921 red = (gdouble) a->red / 65535.0;
2922 green = (gdouble) a->green / 65535.0;
2923 blue = (gdouble) a->blue / 65535.0;
2925 rgb_to_hls (&red, &green, &blue);
2930 else if (green < 0.0)
2936 else if (blue < 0.0)
2939 hls_to_rgb (&red, &green, &blue);
2941 b->red = red * 65535.0;
2942 b->green = green * 65535.0;
2943 b->blue = blue * 65535.0;
2947 rgb_to_hls (gdouble *r,
2988 l = (max + min) / 2;
2995 s = (max - min) / (max + min);
2997 s = (max - min) / (2 - max - min);
3001 h = (green - blue) / delta;
3002 else if (green == max)
3003 h = 2 + (blue - red) / delta;
3004 else if (blue == max)
3005 h = 4 + (red - green) / delta;
3018 hls_to_rgb (gdouble *h,
3031 if (lightness <= 0.5)
3032 m2 = lightness * (1 + saturation);
3034 m2 = lightness + saturation - lightness * saturation;
3035 m1 = 2 * lightness - m2;
3037 if (saturation == 0)
3052 r = m1 + (m2 - m1) * hue / 60;
3056 r = m1 + (m2 - m1) * (240 - hue) / 60;
3067 g = m1 + (m2 - m1) * hue / 60;
3071 g = m1 + (m2 - m1) * (240 - hue) / 60;
3082 b = m1 + (m2 - m1) * hue / 60;
3086 b = m1 + (m2 - m1) * (240 - hue) / 60;
3099 * @style: a #GtkStyle
3101 * @state_type: a state
3102 * @widget: (allow-none): the widget
3103 * @detail: (allow-none): a style detail
3104 * @x1: the starting x coordinate
3105 * @x2: the ending x coordinate
3106 * @y: the y coordinate
3108 * Draws a horizontal line from (@x1, @y) to (@x2, @y) in @cr
3109 * using the given style and state.
3111 * Deprecated:3.0: Use gtk_render_line() instead
3114 gtk_paint_hline (GtkStyle *style,
3116 GtkStateType state_type,
3118 const gchar *detail,
3123 g_return_if_fail (GTK_IS_STYLE (style));
3124 g_return_if_fail (cr != NULL);
3125 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
3129 GTK_STYLE_GET_CLASS (style)->draw_hline (style, cr, state_type,
3138 * @style: a #GtkStyle
3140 * @state_type: a state
3141 * @widget: (allow-none): the widget
3142 * @detail: (allow-none): a style detail
3143 * @y1_: the starting y coordinate
3144 * @y2_: the ending y coordinate
3145 * @x: the x coordinate
3147 * Draws a vertical line from (@x, @y1_) to (@x, @y2_) in @cr
3148 * using the given style and state.
3150 * Deprecated:3.0: Use gtk_render_line() instead
3153 gtk_paint_vline (GtkStyle *style,
3155 GtkStateType state_type,
3157 const gchar *detail,
3162 g_return_if_fail (GTK_IS_STYLE (style));
3163 g_return_if_fail (cr != NULL);
3164 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
3168 GTK_STYLE_GET_CLASS (style)->draw_vline (style, cr, state_type,
3177 * @style: a #GtkStyle
3179 * @state_type: a state
3180 * @shadow_type: type of shadow to draw
3181 * @widget: (allow-none): the widget
3182 * @detail: (allow-none): a style detail
3183 * @x: x origin of the rectangle
3184 * @y: y origin of the rectangle
3185 * @width: width of the rectangle
3186 * @height: width of the rectangle
3188 * Draws a shadow around the given rectangle in @cr
3189 * using the given style and state and shadow type.
3191 * Deprecated:3.0: Use gtk_render_frame() instead
3194 gtk_paint_shadow (GtkStyle *style,
3196 GtkStateType state_type,
3197 GtkShadowType shadow_type,
3199 const gchar *detail,
3205 g_return_if_fail (GTK_IS_STYLE (style));
3206 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
3207 g_return_if_fail (cr != NULL);
3208 g_return_if_fail (width >= 0);
3209 g_return_if_fail (height >= 0);
3213 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, cr, state_type, shadow_type,
3215 x, y, width, height);
3222 * @style: a #GtkStyle
3224 * @state_type: a state
3225 * @shadow_type: the type of shadow to draw
3226 * @widget: (allow-none): the widget
3227 * @detail: (allow-none): a style detail
3228 * @arrow_type: the type of arrow to draw
3229 * @fill: %TRUE if the arrow tip should be filled
3230 * @x: x origin of the rectangle to draw the arrow in
3231 * @y: y origin of the rectangle to draw the arrow in
3232 * @width: width of the rectangle to draw the arrow in
3233 * @height: height of the rectangle to draw the arrow in
3235 * Draws an arrow in the given rectangle on @cr using the given
3236 * parameters. @arrow_type determines the direction of the arrow.
3238 * Deprecated:3.0: Use gtk_render_arrow() instead
3241 gtk_paint_arrow (GtkStyle *style,
3243 GtkStateType state_type,
3244 GtkShadowType shadow_type,
3246 const gchar *detail,
3247 GtkArrowType arrow_type,
3254 g_return_if_fail (GTK_IS_STYLE (style));
3255 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
3256 g_return_if_fail (cr != NULL);
3257 g_return_if_fail (width >= 0);
3258 g_return_if_fail (height >= 0);
3262 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, cr, state_type, shadow_type,
3264 arrow_type, fill, x, y, width, height);
3270 * gtk_paint_diamond:
3271 * @style: a #GtkStyle
3273 * @state_type: a state
3274 * @shadow_type: the type of shadow to draw
3275 * @widget: (allow-none): the widget
3276 * @detail: (allow-none): a style detail
3277 * @x: x origin of the rectangle to draw the diamond in
3278 * @y: y origin of the rectangle to draw the diamond in
3279 * @width: width of the rectangle to draw the diamond in
3280 * @height: height of the rectangle to draw the diamond in
3282 * Draws a diamond in the given rectangle on @window using the given
3285 * Deprecated:3.0: Use cairo instead
3288 gtk_paint_diamond (GtkStyle *style,
3290 GtkStateType state_type,
3291 GtkShadowType shadow_type,
3293 const gchar *detail,
3299 g_return_if_fail (GTK_IS_STYLE (style));
3300 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
3301 g_return_if_fail (cr != NULL);
3302 g_return_if_fail (width >= 0);
3303 g_return_if_fail (height >= 0);
3307 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, cr, state_type, shadow_type,
3309 x, y, width, height);
3316 * @style: a #GtkStyle
3318 * @state_type: a state
3319 * @shadow_type: the type of shadow to draw
3320 * @widget: (allow-none): the widget
3321 * @detail: (allow-none): a style detail
3322 * @x: x origin of the box
3323 * @y: y origin of the box
3324 * @width: the width of the box
3325 * @height: the height of the box
3327 * Draws a box on @cr with the given parameters.
3329 * Deprecated:3.0: Use gtk_render_frame() and gtk_render_background() instead
3332 gtk_paint_box (GtkStyle *style,
3334 GtkStateType state_type,
3335 GtkShadowType shadow_type,
3337 const gchar *detail,
3343 g_return_if_fail (GTK_IS_STYLE (style));
3344 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
3345 g_return_if_fail (cr != NULL);
3349 GTK_STYLE_GET_CLASS (style)->draw_box (style, cr, state_type, shadow_type,
3351 x, y, width, height);
3357 * gtk_paint_flat_box:
3358 * @style: a #GtkStyle
3360 * @state_type: a state
3361 * @shadow_type: the type of shadow to draw
3362 * @widget: (allow-none): the widget
3363 * @detail: (allow-none): a style detail
3364 * @x: x origin of the box
3365 * @y: y origin of the box
3366 * @width: the width of the box
3367 * @height: the height of the box
3369 * Draws a flat box on @cr with the given parameters.
3371 * Deprecated:3.0: Use gtk_render_frame() and gtk_render_background() instead
3374 gtk_paint_flat_box (GtkStyle *style,
3376 GtkStateType state_type,
3377 GtkShadowType shadow_type,
3379 const gchar *detail,
3385 g_return_if_fail (GTK_IS_STYLE (style));
3386 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
3387 g_return_if_fail (cr != NULL);
3388 g_return_if_fail (width >= 0);
3389 g_return_if_fail (height >= 0);
3393 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, cr, state_type, shadow_type,
3395 x, y, width, height);
3402 * @style: a #GtkStyle
3404 * @state_type: a state
3405 * @shadow_type: the type of shadow to draw
3406 * @widget: (allow-none): the widget
3407 * @detail: (allow-none): a style detail
3408 * @x: x origin of the rectangle to draw the check in
3409 * @y: y origin of the rectangle to draw the check in
3410 * @width: the width of the rectangle to draw the check in
3411 * @height: the height of the rectangle to draw the check in
3413 * Draws a check button indicator in the given rectangle on @cr with
3414 * the given parameters.
3416 * Deprecated:3.0: Use gtk_render_check() instead
3419 gtk_paint_check (GtkStyle *style,
3421 GtkStateType state_type,
3422 GtkShadowType shadow_type,
3424 const gchar *detail,
3430 g_return_if_fail (GTK_IS_STYLE (style));
3431 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
3432 g_return_if_fail (cr != NULL);
3436 GTK_STYLE_GET_CLASS (style)->draw_check (style, cr, state_type, shadow_type,
3438 x, y, width, height);
3445 * @style: a #GtkStyle
3447 * @state_type: a state
3448 * @shadow_type: the type of shadow to draw
3449 * @widget: (allow-none): the widget
3450 * @detail: (allow-none): a style detail
3451 * @x: x origin of the rectangle to draw the option in
3452 * @y: y origin of the rectangle to draw the option in
3453 * @width: the width of the rectangle to draw the option in
3454 * @height: the height of the rectangle to draw the option in
3456 * Draws a radio button indicator in the given rectangle on @cr with
3457 * the given parameters.
3459 * Deprecated:3.0: Use gtk_render_option() instead
3462 gtk_paint_option (GtkStyle *style,
3464 GtkStateType state_type,
3465 GtkShadowType shadow_type,
3467 const gchar *detail,
3473 g_return_if_fail (GTK_IS_STYLE (style));
3474 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
3475 g_return_if_fail (cr != NULL);
3479 GTK_STYLE_GET_CLASS (style)->draw_option (style, cr, state_type, shadow_type,
3481 x, y, width, height);
3488 * @style: a #GtkStyle
3490 * @state_type: a state
3491 * @shadow_type: the type of shadow to draw
3492 * @widget: (allow-none): the widget
3493 * @detail: (allow-none): a style detail
3494 * @x: x origin of the rectangle to draw the tab in
3495 * @y: y origin of the rectangle to draw the tab in
3496 * @width: the width of the rectangle to draw the tab in
3497 * @height: the height of the rectangle to draw the tab in
3499 * Draws an option menu tab (i.e. the up and down pointing arrows)
3500 * in the given rectangle on @cr using the given parameters.
3502 * Deprecated:3.0: Use cairo instead
3505 gtk_paint_tab (GtkStyle *style,
3507 GtkStateType state_type,
3508 GtkShadowType shadow_type,
3510 const gchar *detail,
3516 g_return_if_fail (GTK_IS_STYLE (style));
3517 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
3518 g_return_if_fail (cr != NULL);
3522 GTK_STYLE_GET_CLASS (style)->draw_tab (style, cr, state_type, shadow_type,
3524 x, y, width, height);
3530 * gtk_paint_shadow_gap:
3531 * @style: a #GtkStyle
3533 * @state_type: a state
3534 * @shadow_type: type of shadow to draw
3535 * @widget: (allow-none): the widget
3536 * @detail: (allow-none): a style detail
3537 * @x: x origin of the rectangle
3538 * @y: y origin of the rectangle
3539 * @width: width of the rectangle
3540 * @height: width of the rectangle
3541 * @gap_side: side in which to leave the gap
3542 * @gap_x: starting position of the gap
3543 * @gap_width: width of the gap
3545 * Draws a shadow around the given rectangle in @cr
3546 * using the given style and state and shadow type, leaving a
3549 * Deprecated:3.0: Use gtk_render_frame_gap() instead
3552 gtk_paint_shadow_gap (GtkStyle *style,
3554 GtkStateType state_type,
3555 GtkShadowType shadow_type,
3557 const gchar *detail,
3562 GtkPositionType gap_side,
3566 g_return_if_fail (GTK_IS_STYLE (style));
3567 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
3568 g_return_if_fail (cr != NULL);
3569 g_return_if_fail (width >= 0);
3570 g_return_if_fail (height >= 0);
3574 GTK_STYLE_GET_CLASS (style)->draw_shadow_gap (style, cr, state_type, shadow_type,
3576 x, y, width, height, gap_side, gap_x, gap_width);
3582 * gtk_paint_box_gap:
3583 * @style: a #GtkStyle
3585 * @state_type: a state
3586 * @shadow_type: type of shadow to draw
3587 * @widget: (allow-none): the widget
3588 * @detail: (allow-none): a style detail
3589 * @x: x origin of the rectangle
3590 * @y: y origin of the rectangle
3591 * @width: width of the rectangle
3592 * @height: width of the rectangle
3593 * @gap_side: side in which to leave the gap
3594 * @gap_x: starting position of the gap
3595 * @gap_width: width of the gap
3597 * Draws a box in @cr using the given style and state and shadow type,
3598 * leaving a gap in one side.
3600 * Deprecated:3.0: Use gtk_render_frame_gap() instead
3603 gtk_paint_box_gap (GtkStyle *style,
3605 GtkStateType state_type,
3606 GtkShadowType shadow_type,
3608 const gchar *detail,
3613 GtkPositionType gap_side,
3617 g_return_if_fail (GTK_IS_STYLE (style));
3618 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
3619 g_return_if_fail (cr != NULL);
3620 g_return_if_fail (width >= 0);
3621 g_return_if_fail (height >= 0);
3625 GTK_STYLE_GET_CLASS (style)->draw_box_gap (style, cr, state_type, shadow_type,
3627 x, y, width, height, gap_side, gap_x, gap_width);
3633 * gtk_paint_extension:
3634 * @style: a #GtkStyle
3636 * @state_type: a state
3637 * @shadow_type: type of shadow to draw
3638 * @widget: (allow-none): the widget
3639 * @detail: (allow-none): a style detail
3640 * @x: x origin of the extension
3641 * @y: y origin of the extension
3642 * @width: width of the extension
3643 * @height: width of the extension
3644 * @gap_side: the side on to which the extension is attached
3646 * Draws an extension, i.e. a notebook tab.
3648 * Deprecated:3.0: Use gtk_render_extension() instead
3651 gtk_paint_extension (GtkStyle *style,
3653 GtkStateType state_type,
3654 GtkShadowType shadow_type,
3656 const gchar *detail,
3661 GtkPositionType gap_side)
3663 g_return_if_fail (GTK_IS_STYLE (style));
3664 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
3665 g_return_if_fail (cr != NULL);
3666 g_return_if_fail (width >= 0);
3667 g_return_if_fail (height >= 0);
3671 GTK_STYLE_GET_CLASS (style)->draw_extension (style, cr, state_type, shadow_type,
3673 x, y, width, height, gap_side);
3680 * @style: a #GtkStyle
3682 * @state_type: a state
3683 * @widget: (allow-none): the widget
3684 * @detail: (allow-none): a style detail
3685 * @x: the x origin of the rectangle around which to draw a focus indicator
3686 * @y: the y origin of the rectangle around which to draw a focus indicator
3687 * @width: the width of the rectangle around which to draw a focus indicator
3688 * @height: the height of the rectangle around which to draw a focus indicator
3690 * Draws a focus indicator around the given rectangle on @cr using the
3693 * Deprecated:3.0: Use gtk_render_focus() instead
3696 gtk_paint_focus (GtkStyle *style,
3698 GtkStateType state_type,
3700 const gchar *detail,
3706 g_return_if_fail (GTK_IS_STYLE (style));
3707 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
3708 g_return_if_fail (cr != NULL);
3709 g_return_if_fail (width >= 0);
3710 g_return_if_fail (height >= 0);
3714 GTK_STYLE_GET_CLASS (style)->draw_focus (style, cr, state_type,
3716 x, y, width, height);
3723 * @style: a #GtkStyle
3725 * @state_type: a state
3726 * @shadow_type: a shadow
3727 * @widget: (allow-none): the widget
3728 * @detail: (allow-none): a style detail
3729 * @x: the x origin of the rectangle in which to draw a slider
3730 * @y: the y origin of the rectangle in which to draw a slider
3731 * @width: the width of the rectangle in which to draw a slider
3732 * @height: the height of the rectangle in which to draw a slider
3733 * @orientation: the orientation to be used
3735 * Draws a slider in the given rectangle on @cr using the
3736 * given style and orientation.
3738 * Deprecated:3.0: Use gtk_render_slider() instead
3741 gtk_paint_slider (GtkStyle *style,
3743 GtkStateType state_type,
3744 GtkShadowType shadow_type,
3746 const gchar *detail,
3751 GtkOrientation orientation)
3753 g_return_if_fail (GTK_IS_STYLE (style));
3754 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
3755 g_return_if_fail (cr != NULL);
3756 g_return_if_fail (width >= 0);
3757 g_return_if_fail (height >= 0);
3761 GTK_STYLE_GET_CLASS (style)->draw_slider (style, cr, state_type, shadow_type,
3763 x, y, width, height, orientation);
3770 * @style: a #GtkStyle
3772 * @state_type: a state
3773 * @shadow_type: type of shadow to draw
3774 * @widget: (allow-none): the widget
3775 * @detail: (allow-none): a style detail
3776 * @x: x origin of the handle
3777 * @y: y origin of the handle
3778 * @width: with of the handle
3779 * @height: height of the handle
3780 * @orientation: the orientation of the handle
3782 * Draws a handle as used in #GtkHandleBox and #GtkPaned.
3784 * Deprecated:3.0: Use gtk_render_handle() instead
3787 gtk_paint_handle (GtkStyle *style,
3789 GtkStateType state_type,
3790 GtkShadowType shadow_type,
3792 const gchar *detail,
3797 GtkOrientation orientation)
3799 g_return_if_fail (GTK_IS_STYLE (style));
3800 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
3801 g_return_if_fail (cr != NULL);
3802 g_return_if_fail (width >= 0);
3803 g_return_if_fail (height >= 0);
3807 GTK_STYLE_GET_CLASS (style)->draw_handle (style, cr, state_type, shadow_type,
3809 x, y, width, height, orientation);
3815 * gtk_paint_expander:
3816 * @style: a #GtkStyle
3818 * @state_type: a state
3819 * @widget: (allow-none): the widget
3820 * @detail: (allow-none): a style detail
3821 * @x: the x position to draw the expander at
3822 * @y: the y position to draw the expander at
3823 * @expander_style: the style to draw the expander in; determines
3824 * whether the expander is collapsed, expanded, or in an
3825 * intermediate state.
3827 * Draws an expander as used in #GtkTreeView. @x and @y specify the
3828 * center the expander. The size of the expander is determined by the
3829 * "expander-size" style property of @widget. (If widget is not
3830 * specified or doesn't have an "expander-size" property, an
3831 * unspecified default size will be used, since the caller doesn't
3832 * have sufficient information to position the expander, this is
3833 * likely not useful.) The expander is expander_size pixels tall
3834 * in the collapsed position and expander_size pixels wide in the
3835 * expanded position.
3837 * Deprecated:3.0: Use gtk_render_expander() instead
3840 gtk_paint_expander (GtkStyle *style,
3842 GtkStateType state_type,
3844 const gchar *detail,
3847 GtkExpanderStyle expander_style)
3849 g_return_if_fail (GTK_IS_STYLE (style));
3850 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
3851 g_return_if_fail (cr != NULL);
3855 GTK_STYLE_GET_CLASS (style)->draw_expander (style, cr, state_type,
3857 x, y, expander_style);
3864 * @style: a #GtkStyle
3866 * @state_type: a state
3867 * @use_text: whether to use the text or foreground
3868 * graphics context of @style
3869 * @widget: (allow-none): the widget
3870 * @detail: (allow-none): a style detail
3873 * @layout: the layout to draw
3875 * Draws a layout on @cr using the given parameters.
3877 * Deprecated:3.0: Use gtk_render_layout() instead
3880 gtk_paint_layout (GtkStyle *style,
3882 GtkStateType state_type,
3885 const gchar *detail,
3888 PangoLayout *layout)
3890 g_return_if_fail (GTK_IS_STYLE (style));
3891 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
3892 g_return_if_fail (cr != NULL);
3896 GTK_STYLE_GET_CLASS (style)->draw_layout (style, cr, state_type, use_text,
3904 * gtk_paint_resize_grip:
3905 * @style: a #GtkStyle
3907 * @state_type: a state
3908 * @widget: (allow-none): the widget
3909 * @detail: (allow-none): a style detail
3910 * @edge: the edge in which to draw the resize grip
3911 * @x: the x origin of the rectangle in which to draw the resize grip
3912 * @y: the y origin of the rectangle in which to draw the resize grip
3913 * @width: the width of the rectangle in which to draw the resize grip
3914 * @height: the height of the rectangle in which to draw the resize grip
3916 * Draws a resize grip in the given rectangle on @cr using the given
3919 * Deprecated:3.0: Use gtk_render_handle() instead
3922 gtk_paint_resize_grip (GtkStyle *style,
3924 GtkStateType state_type,
3926 const gchar *detail,
3933 g_return_if_fail (GTK_IS_STYLE (style));
3934 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
3935 g_return_if_fail (cr != NULL);
3939 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, cr, state_type,
3941 edge, x, y, width, height);
3946 * gtk_paint_spinner:
3947 * @style: a #GtkStyle
3949 * @state_type: a state
3950 * @widget: (allow-none): the widget (may be %NULL)
3951 * @detail: (allow-none): a style detail (may be %NULL)
3952 * @step: the nth step, a value between 0 and #GtkSpinner:num-steps
3953 * @x: the x origin of the rectangle in which to draw the spinner
3954 * @y: the y origin of the rectangle in which to draw the spinner
3955 * @width: the width of the rectangle in which to draw the spinner
3956 * @height: the height of the rectangle in which to draw the spinner
3958 * Draws a spinner on @window using the given parameters.
3960 * Deprecated:3.0: Use gtk_render_activity() instead
3963 gtk_paint_spinner (GtkStyle *style,
3965 GtkStateType state_type,
3967 const gchar *detail,
3974 g_return_if_fail (GTK_IS_STYLE (style));
3975 g_return_if_fail (cr != NULL);
3976 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_spinner != NULL);
3980 GTK_STYLE_GET_CLASS (style)->draw_spinner (style, cr, state_type,
3982 step, x, y, width, height);
3987 static GtkStyle *gtk_default_style = NULL;
3990 * gtk_widget_get_default_style:
3992 * Returns the default style used by all widgets initially.
3994 * Returns: (transfer none): the default style. This #GtkStyle
3995 * object is owned by GTK+ and should not be modified or freed.
3997 * Deprecated:3.0: Use #GtkStyleContext instead, and
3998 * gtk_css_provider_get_default() to obtain a #GtkStyleProvider
3999 * with the default widget style information.
4002 gtk_widget_get_default_style (void)
4004 if (!gtk_default_style)
4006 gtk_default_style = gtk_style_new ();
4007 g_object_ref (gtk_default_style);
4010 return gtk_default_style;
4014 * gtk_widget_style_attach:
4015 * @widget: a #GtkWidget
4017 * This function attaches the widget's #GtkStyle to the widget's
4018 * #GdkWindow. It is a replacement for
4021 * widget->style = gtk_style_attach (widget->style, widget->window);
4024 * and should only ever be called in a derived widget's "realize"
4025 * implementation which does not chain up to its parent class'
4026 * "realize" implementation, because one of the parent classes
4027 * (finally #GtkWidget) would attach the style itself.
4031 * Deprecated: 3.0. This step is unnecessary with #GtkStyleContext.
4034 gtk_widget_style_attach (GtkWidget *widget)
4036 g_return_if_fail (GTK_IS_WIDGET (widget));
4037 g_return_if_fail (gtk_widget_get_realized (widget));
4041 * gtk_widget_has_rc_style:
4042 * @widget: a #GtkWidget
4044 * Determines if the widget style has been looked up through the rc mechanism.
4046 * Returns: %TRUE if the widget has been looked up through the rc
4047 * mechanism, %FALSE otherwise.
4051 * Deprecated:3.0: Use #GtkStyleContext instead
4054 gtk_widget_has_rc_style (GtkWidget *widget)
4056 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4062 * gtk_widget_set_style:
4063 * @widget: a #GtkWidget
4064 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect
4065 * of a previous call to gtk_widget_set_style() and go back to
4068 * Used to set the #GtkStyle for a widget (@widget->style). Since
4069 * GTK 3, this function does nothing, the passed in style is ignored.
4071 * Deprecated:3.0: Use #GtkStyleContext instead
4074 gtk_widget_set_style (GtkWidget *widget,
4077 g_return_if_fail (GTK_IS_WIDGET (widget));
4081 * gtk_widget_ensure_style:
4082 * @widget: a #GtkWidget
4084 * Ensures that @widget has a style (@widget->style).
4086 * Not a very useful function; most of the time, if you
4087 * want the style, the widget is realized, and realized
4088 * widgets are guaranteed to have a style already.
4090 * Deprecated:3.0: Use #GtkStyleContext instead
4093 gtk_widget_ensure_style (GtkWidget *widget)
4096 g_return_if_fail (GTK_IS_WIDGET (widget));
4098 style = _gtk_widget_get_style (widget);
4099 if (style == gtk_widget_get_default_style ())
4101 g_object_unref (style);
4102 _gtk_widget_set_style (widget, NULL);
4104 g_signal_emit_by_name (widget, "style-set", 0, NULL);
4109 * gtk_widget_get_style:
4110 * @widget: a #GtkWidget
4112 * Simply an accessor function that returns @widget->style.
4114 * Return value: (transfer none): the widget's #GtkStyle
4116 * Deprecated:3.0: Use #GtkStyleContext instead
4119 gtk_widget_get_style (GtkWidget *widget)
4122 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4124 style = _gtk_widget_get_style (widget);
4128 style = g_object_new (GTK_TYPE_STYLE,
4129 "context", gtk_widget_get_style_context (widget),
4131 _gtk_widget_set_style (widget, style);
4138 * gtk_widget_modify_style:
4139 * @widget: a #GtkWidget
4140 * @style: the #GtkRcStyle holding the style modifications
4142 * Modifies style values on the widget.
4144 * Modifications made using this technique take precedence over
4145 * style values set via an RC file, however, they will be overridden
4146 * if a style is explicitely set on the widget using gtk_widget_set_style().
4147 * The #GtkRcStyle structure is designed so each field can either be
4148 * set or unset, so it is possible, using this function, to modify some
4149 * style values and leave the others unchanged.
4151 * Note that modifications made with this function are not cumulative
4152 * with previous calls to gtk_widget_modify_style() or with such
4153 * functions as gtk_widget_modify_fg(). If you wish to retain
4154 * previous values, you must first call gtk_widget_get_modifier_style(),
4155 * make your modifications to the returned style, then call
4156 * gtk_widget_modify_style() with that style. On the other hand,
4157 * if you first call gtk_widget_modify_style(), subsequent calls
4158 * to such functions gtk_widget_modify_fg() will have a cumulative
4159 * effect with the initial modifications.
4161 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
4164 gtk_widget_modify_style (GtkWidget *widget,
4167 g_return_if_fail (GTK_IS_WIDGET (widget));
4168 g_return_if_fail (GTK_IS_RC_STYLE (style));
4170 g_object_set_data_full (G_OBJECT (widget),
4172 gtk_rc_style_copy (style),
4173 (GDestroyNotify) g_object_unref);
4177 * gtk_widget_get_modifier_style:
4178 * @widget: a #GtkWidget
4180 * Returns the current modifier style for the widget. (As set by
4181 * gtk_widget_modify_style().) If no style has previously set, a new
4182 * #GtkRcStyle will be created with all values unset, and set as the
4183 * modifier style for the widget. If you make changes to this rc
4184 * style, you must call gtk_widget_modify_style(), passing in the
4185 * returned rc style, to make sure that your changes take effect.
4187 * Caution: passing the style back to gtk_widget_modify_style() will
4188 * normally end up destroying it, because gtk_widget_modify_style() copies
4189 * the passed-in style and sets the copy as the new modifier style,
4190 * thus dropping any reference to the old modifier style. Add a reference
4191 * to the modifier style if you want to keep it alive.
4193 * Return value: (transfer none): the modifier style for the widget.
4194 * This rc style is owned by the widget. If you want to keep a
4195 * pointer to value this around, you must add a refcount using
4198 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
4201 gtk_widget_get_modifier_style (GtkWidget *widget)
4203 GtkRcStyle *rc_style;
4205 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4207 rc_style = g_object_get_data (G_OBJECT (widget), "gtk-rc-style");
4211 rc_style = gtk_rc_style_new ();
4212 g_object_set_data_full (G_OBJECT (widget),
4215 (GDestroyNotify) g_object_unref);
4222 gtk_widget_modify_color_component (GtkWidget *widget,
4223 GtkRcFlags component,
4225 const GdkColor *color)
4227 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
4234 rc_style->fg[state] = *color;
4237 rc_style->bg[state] = *color;
4240 rc_style->text[state] = *color;
4243 rc_style->base[state] = *color;
4246 g_assert_not_reached();
4249 rc_style->color_flags[state] |= component;
4252 rc_style->color_flags[state] &= ~component;
4254 gtk_widget_modify_style (widget, rc_style);
4258 * gtk_widget_modify_fg:
4259 * @widget: a #GtkWidget
4260 * @state: the state for which to set the foreground color
4261 * @color: (allow-none): the color to assign (does not need to be allocated),
4262 * or %NULL to undo the effect of previous calls to
4263 * of gtk_widget_modify_fg().
4265 * Sets the foreground color for a widget in a particular state.
4267 * All other style values are left untouched.
4268 * See also gtk_widget_modify_style().
4270 * Deprecated:3.0: Use gtk_widget_override_color() instead
4273 gtk_widget_modify_fg (GtkWidget *widget,
4275 const GdkColor *color)
4277 GtkStateFlags flags;
4280 g_return_if_fail (GTK_IS_WIDGET (widget));
4281 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4285 case GTK_STATE_ACTIVE:
4286 flags = GTK_STATE_FLAG_ACTIVE;
4288 case GTK_STATE_PRELIGHT:
4289 flags = GTK_STATE_FLAG_PRELIGHT;
4291 case GTK_STATE_SELECTED:
4292 flags = GTK_STATE_FLAG_SELECTED;
4294 case GTK_STATE_INSENSITIVE:
4295 flags = GTK_STATE_FLAG_INSENSITIVE;
4297 case GTK_STATE_NORMAL:
4304 rgba.red = color->red / 65535.;
4305 rgba.green = color->green / 65535.;
4306 rgba.blue = color->blue / 65535.;
4309 gtk_widget_override_color (widget, flags, &rgba);
4312 gtk_widget_override_color (widget, flags, NULL);
4316 * gtk_widget_modify_bg:
4317 * @widget: a #GtkWidget
4318 * @state: the state for which to set the background color
4319 * @color: (allow-none): the color to assign (does not need
4320 * to be allocated), or %NULL to undo the effect of previous
4321 * calls to of gtk_widget_modify_bg().
4323 * Sets the background color for a widget in a particular state.
4325 * All other style values are left untouched.
4326 * See also gtk_widget_modify_style().
4329 * Note that "no window" widgets (which have the %GTK_NO_WINDOW
4330 * flag set) draw on their parent container's window and thus may
4331 * not draw any background themselves. This is the case for e.g.
4334 * To modify the background of such widgets, you have to set the
4335 * background color on their parent; if you want to set the background
4336 * of a rectangular area around a label, try placing the label in
4337 * a #GtkEventBox widget and setting the background color on that.
4340 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
4343 gtk_widget_modify_bg (GtkWidget *widget,
4345 const GdkColor *color)
4347 GtkStateFlags flags;
4350 g_return_if_fail (GTK_IS_WIDGET (widget));
4351 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4355 case GTK_STATE_ACTIVE:
4356 flags = GTK_STATE_FLAG_ACTIVE;
4358 case GTK_STATE_PRELIGHT:
4359 flags = GTK_STATE_FLAG_PRELIGHT;
4361 case GTK_STATE_SELECTED:
4362 flags = GTK_STATE_FLAG_SELECTED;
4364 case GTK_STATE_INSENSITIVE:
4365 flags = GTK_STATE_FLAG_INSENSITIVE;
4367 case GTK_STATE_NORMAL:
4374 rgba.red = color->red / 65535.;
4375 rgba.green = color->green / 65535.;
4376 rgba.blue = color->blue / 65535.;
4379 gtk_widget_override_background_color (widget, flags, &rgba);
4382 gtk_widget_override_background_color (widget, flags, NULL);
4386 * gtk_widget_modify_text:
4387 * @widget: a #GtkWidget
4388 * @state: the state for which to set the text color
4389 * @color: (allow-none): the color to assign (does not need to
4390 * be allocated), or %NULL to undo the effect of previous
4391 * calls to of gtk_widget_modify_text().
4393 * Sets the text color for a widget in a particular state.
4395 * All other style values are left untouched.
4396 * The text color is the foreground color used along with the
4397 * base color (see gtk_widget_modify_base()) for widgets such
4398 * as #GtkEntry and #GtkTextView.
4399 * See also gtk_widget_modify_style().
4401 * Deprecated:3.0: Use gtk_widget_override_color() instead
4404 gtk_widget_modify_text (GtkWidget *widget,
4406 const GdkColor *color)
4408 g_return_if_fail (GTK_IS_WIDGET (widget));
4409 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4411 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
4415 * gtk_widget_modify_base:
4416 * @widget: a #GtkWidget
4417 * @state: the state for which to set the base color
4418 * @color: (allow-none): the color to assign (does not need to
4419 * be allocated), or %NULL to undo the effect of previous
4420 * calls to of gtk_widget_modify_base().
4422 * Sets the base color for a widget in a particular state.
4423 * All other style values are left untouched. The base color
4424 * is the background color used along with the text color
4425 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
4426 * and #GtkTextView. See also gtk_widget_modify_style().
4429 * Note that "no window" widgets (which have the %GTK_NO_WINDOW
4430 * flag set) draw on their parent container's window and thus may
4431 * not draw any background themselves. This is the case for e.g.
4434 * To modify the background of such widgets, you have to set the
4435 * base color on their parent; if you want to set the background
4436 * of a rectangular area around a label, try placing the label in
4437 * a #GtkEventBox widget and setting the base color on that.
4440 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
4443 gtk_widget_modify_base (GtkWidget *widget,
4445 const GdkColor *color)
4447 g_return_if_fail (GTK_IS_WIDGET (widget));
4448 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4450 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
4454 * gtk_widget_modify_cursor:
4455 * @widget: a #GtkWidget
4456 * @primary: the color to use for primary cursor (does not need to be
4457 * allocated), or %NULL to undo the effect of previous calls to
4458 * of gtk_widget_modify_cursor().
4459 * @secondary: the color to use for secondary cursor (does not need to be
4460 * allocated), or %NULL to undo the effect of previous calls to
4461 * of gtk_widget_modify_cursor().
4463 * Sets the cursor color to use in a widget, overriding the
4464 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
4467 * All other style values are left untouched.
4468 * See also gtk_widget_modify_style().
4472 * Deprecated: 3.0. Use gtk_widget_override_cursor() instead.
4475 gtk_widget_modify_cursor (GtkWidget *widget,
4476 const GdkColor *primary,
4477 const GdkColor *secondary)
4479 GdkRGBA primary_rgba, secondary_rgba;
4481 g_return_if_fail (GTK_IS_WIDGET (widget));
4483 primary_rgba.red = primary->red / 65535.;
4484 primary_rgba.green = primary->green / 65535.;
4485 primary_rgba.blue = primary->blue / 65535.;
4486 primary_rgba.alpha = 1;
4488 secondary_rgba.red = secondary->red / 65535.;
4489 secondary_rgba.green = secondary->green / 65535.;
4490 secondary_rgba.blue = secondary->blue / 65535.;
4491 secondary_rgba.alpha = 1;
4493 gtk_widget_override_cursor (widget, &primary_rgba, &secondary_rgba);
4497 * gtk_widget_modify_font:
4498 * @widget: a #GtkWidget
4499 * @font_desc: (allow-none): the font description to use, or %NULL
4500 * to undo the effect of previous calls to gtk_widget_modify_font()
4502 * Sets the font to use for a widget.
4504 * All other style values are left untouched.
4505 * See also gtk_widget_modify_style().
4507 * Deprecated:3.0: Use gtk_widget_override_font() instead
4510 gtk_widget_modify_font (GtkWidget *widget,
4511 PangoFontDescription *font_desc)
4513 g_return_if_fail (GTK_IS_WIDGET (widget));
4515 gtk_widget_override_font (widget, font_desc);
4519 * gtk_widget_reset_rc_styles:
4520 * @widget: a #GtkWidget.
4522 * Reset the styles of @widget and all descendents, so when
4523 * they are looked up again, they get the correct values
4524 * for the currently loaded RC file settings.
4526 * This function is not useful for applications.
4528 * Deprecated:3.0: Use #GtkStyleContext instead, and gtk_widget_reset_style()
4531 gtk_widget_reset_rc_styles (GtkWidget *widget)
4533 g_return_if_fail (GTK_IS_WIDGET (widget));
4535 gtk_widget_reset_style (widget);
4540 * @widget: a #GtkWidget
4541 * @path_length: (out) (allow-none): location to store length of the path,
4543 * @path: (out) (allow-none): location to store allocated path string,
4545 * @path_reversed: (out) (allow-none): location to store allocated reverse
4546 * path string, or %NULL
4548 * Obtains the full path to @widget. The path is simply the name of a
4549 * widget and all its parents in the container hierarchy, separated by
4550 * periods. The name of a widget comes from
4551 * gtk_widget_get_name(). Paths are used to apply styles to a widget
4552 * in gtkrc configuration files. Widget names are the type of the
4553 * widget by default (e.g. "GtkButton") or can be set to an
4554 * application-specific value with gtk_widget_set_name(). By setting
4555 * the name of a widget, you allow users or theme authors to apply
4556 * styles to that specific widget in their gtkrc
4557 * file. @path_reversed_p fills in the path in reverse order,
4558 * i.e. starting with @widget's name instead of starting with the name
4559 * of @widget's outermost ancestor.
4561 * Deprecated:3.0: Use gtk_widget_get_path() instead
4564 gtk_widget_path (GtkWidget *widget,
4567 gchar **path_reversed)
4569 static gchar *rev_path = NULL;
4570 static guint tmp_path_len = 0;
4573 #define INIT_PATH_SIZE (512)
4575 g_return_if_fail (GTK_IS_WIDGET (widget));
4580 const gchar *string;
4585 string = gtk_widget_get_name (widget);
4586 l = strlen (string);
4587 while (tmp_path_len <= len + l + 1)
4589 tmp_path_len += INIT_PATH_SIZE;
4590 rev_path = g_realloc (rev_path, tmp_path_len);
4598 widget = gtk_widget_get_parent (widget);
4601 rev_path[len++] = '.';
4603 rev_path[len++] = 0;
4608 *path_length = len - 1;
4610 *path_reversed = g_strdup (rev_path);
4613 *path = g_strdup (rev_path);
4614 g_strreverse (*path);
4619 * gtk_widget_class_path:
4620 * @widget: a #GtkWidget
4621 * @path_length: (out) (allow-none): location to store the length of the
4622 * class path, or %NULL
4623 * @path: (out) (allow-none): location to store the class path as an
4624 * allocated string, or %NULL
4625 * @path_reversed: (out) (allow-none): location to store the reverse
4626 * class path as an allocated string, or %NULL
4628 * Same as gtk_widget_path(), but always uses the name of a widget's type,
4629 * never uses a custom name set with gtk_widget_set_name().
4631 * Deprecated:3.0: Use gtk_widget_get_path() instead
4634 gtk_widget_class_path (GtkWidget *widget,
4637 gchar **path_reversed)
4639 static gchar *rev_path = NULL;
4640 static guint tmp_path_len = 0;
4643 g_return_if_fail (GTK_IS_WIDGET (widget));
4648 const gchar *string;
4653 string = g_type_name (G_OBJECT_TYPE (widget));
4654 l = strlen (string);
4655 while (tmp_path_len <= len + l + 1)
4657 tmp_path_len += INIT_PATH_SIZE;
4658 rev_path = g_realloc (rev_path, tmp_path_len);
4666 widget = gtk_widget_get_parent (widget);
4669 rev_path[len++] = '.';
4671 rev_path[len++] = 0;
4676 *path_length = len - 1;
4678 *path_reversed = g_strdup (rev_path);
4681 *path = g_strdup (rev_path);
4682 g_strreverse (*path);
4687 * gtk_widget_render_icon:
4688 * @widget: a #GtkWidget
4689 * @stock_id: a stock ID
4690 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
4691 * render at the size of the source and don't scale (if there are
4692 * multiple source sizes, GTK+ picks one of the available sizes).
4693 * @detail: (allow-none): render detail to pass to theme engine
4695 * A convenience function that uses the theme settings for @widget
4696 * to look up @stock_id and render it to a pixbuf. @stock_id should
4697 * be a stock icon ID such as #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size
4698 * should be a size such as #GTK_ICON_SIZE_MENU. @detail should be a
4699 * string that identifies the widget or code doing the rendering, so
4700 * that theme engines can special-case rendering for that widget or
4703 * The pixels in the returned #GdkPixbuf are shared with the rest of
4704 * the application and should not be modified. The pixbuf should be
4705 * freed after use with g_object_unref().
4707 * Return value: (transfer full): a new pixbuf, or %NULL if the
4708 * stock ID wasn't known
4710 * Deprecated: 3.0: Use gtk_widget_render_icon_pixbuf() instead.
4713 gtk_widget_render_icon (GtkWidget *widget,
4714 const gchar *stock_id,
4716 const gchar *detail)
4718 gtk_widget_ensure_style (widget);
4720 return gtk_widget_render_icon_pixbuf (widget, stock_id, size);