1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GTK+ Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
27 #define GDK_DISABLE_DEPRECATION_WARNINGS
32 #include <gobject/gvaluecollector.h>
33 #include "gtkmarshalers.h"
36 #include "gtkspinbutton.h"
38 #include "gtkstylecontextprivate.h"
39 #include "gtkwidget.h"
40 #include "gtkwidgetprivate.h"
41 #include "gtkiconfactory.h"
44 #include "gtkspinner.h"
45 #include "gtkborder.h"
49 * @Short_description: Deprecated object that holds style information
53 * A #GtkStyle object encapsulates the information that provides the look and
57 * In GTK+ 3.0, GtkStyle has been deprecated and replaced by #GtkStyleContext.
60 * Each #GtkWidget has an associated #GtkStyle object that is used when
61 * rendering that widget. Also, a #GtkStyle holds information for the five
62 * possible widget states though not every widget supports all five
63 * states; see #GtkStateType.
65 * Usually the #GtkStyle for a widget is the same as the default style that
66 * is set by GTK+ and modified the theme engine.
68 * Usually applications should not need to use or modify the #GtkStyle of
73 #define LIGHTNESS_MULT 1.3
74 #define DARKNESS_MULT 0.7
76 /* --- typedefs & structures --- */
83 #define GTK_STYLE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_STYLE, GtkStylePrivate))
85 typedef struct _GtkStylePrivate GtkStylePrivate;
87 struct _GtkStylePrivate {
88 GtkStyleContext *context;
89 gulong context_changed_id;
97 /* --- prototypes --- */
98 static void gtk_style_finalize (GObject *object);
99 static void gtk_style_constructed (GObject *object);
100 static void gtk_style_set_property (GObject *object,
104 static void gtk_style_get_property (GObject *object,
109 static void gtk_style_real_realize (GtkStyle *style);
110 static void gtk_style_real_unrealize (GtkStyle *style);
111 static void gtk_style_real_copy (GtkStyle *style,
113 static void gtk_style_real_set_background (GtkStyle *style,
115 GtkStateType state_type);
116 static GtkStyle *gtk_style_real_clone (GtkStyle *style);
117 static void gtk_style_real_init_from_rc (GtkStyle *style,
118 GtkRcStyle *rc_style);
119 static GdkPixbuf *gtk_default_render_icon (GtkStyle *style,
120 const GtkIconSource *source,
121 GtkTextDirection direction,
125 const gchar *detail);
126 static void gtk_default_draw_hline (GtkStyle *style,
128 GtkStateType state_type,
134 static void gtk_default_draw_vline (GtkStyle *style,
136 GtkStateType state_type,
142 static void gtk_default_draw_shadow (GtkStyle *style,
144 GtkStateType state_type,
145 GtkShadowType shadow_type,
152 static void gtk_default_draw_arrow (GtkStyle *style,
154 GtkStateType state_type,
155 GtkShadowType shadow_type,
158 GtkArrowType arrow_type,
164 static void gtk_default_draw_diamond (GtkStyle *style,
166 GtkStateType state_type,
167 GtkShadowType shadow_type,
174 static void gtk_default_draw_box (GtkStyle *style,
176 GtkStateType state_type,
177 GtkShadowType shadow_type,
184 static void gtk_default_draw_flat_box (GtkStyle *style,
186 GtkStateType state_type,
187 GtkShadowType shadow_type,
194 static void gtk_default_draw_check (GtkStyle *style,
196 GtkStateType state_type,
197 GtkShadowType shadow_type,
204 static void gtk_default_draw_option (GtkStyle *style,
206 GtkStateType state_type,
207 GtkShadowType shadow_type,
214 static void gtk_default_draw_tab (GtkStyle *style,
216 GtkStateType state_type,
217 GtkShadowType shadow_type,
224 static void gtk_default_draw_shadow_gap (GtkStyle *style,
226 GtkStateType state_type,
227 GtkShadowType shadow_type,
234 GtkPositionType gap_side,
237 static void gtk_default_draw_box_gap (GtkStyle *style,
239 GtkStateType state_type,
240 GtkShadowType shadow_type,
247 GtkPositionType gap_side,
250 static void gtk_default_draw_extension (GtkStyle *style,
252 GtkStateType state_type,
253 GtkShadowType shadow_type,
260 GtkPositionType gap_side);
261 static void gtk_default_draw_focus (GtkStyle *style,
263 GtkStateType state_type,
270 static void gtk_default_draw_slider (GtkStyle *style,
272 GtkStateType state_type,
273 GtkShadowType shadow_type,
280 GtkOrientation orientation);
281 static void gtk_default_draw_handle (GtkStyle *style,
283 GtkStateType state_type,
284 GtkShadowType shadow_type,
291 GtkOrientation orientation);
292 static void gtk_default_draw_expander (GtkStyle *style,
294 GtkStateType state_type,
299 GtkExpanderStyle expander_style);
300 static void gtk_default_draw_layout (GtkStyle *style,
302 GtkStateType state_type,
308 PangoLayout *layout);
309 static void gtk_default_draw_resize_grip (GtkStyle *style,
311 GtkStateType state_type,
319 static void gtk_default_draw_spinner (GtkStyle *style,
321 GtkStateType state_type,
330 static void rgb_to_hls (gdouble *r,
333 static void hls_to_rgb (gdouble *h,
337 static void transform_detail_string (const gchar *detail,
338 GtkStyleContext *context);
341 * Data for default check and radio buttons
344 static const GtkRequisition default_option_indicator_size = { 7, 13 };
345 static const GtkBorder default_option_indicator_spacing = { 7, 5, 2, 2 };
347 #define GTK_GRAY 0xdcdc, 0xdada, 0xd5d5
348 #define GTK_DARK_GRAY 0xc4c4, 0xc2c2, 0xbdbd
349 #define GTK_LIGHT_GRAY 0xeeee, 0xebeb, 0xe7e7
350 #define GTK_WHITE 0xffff, 0xffff, 0xffff
351 #define GTK_BLUE 0x4b4b, 0x6969, 0x8383
352 #define GTK_VERY_DARK_GRAY 0x9c9c, 0x9a9a, 0x9494
353 #define GTK_BLACK 0x0000, 0x0000, 0x0000
354 #define GTK_WEAK_GRAY 0x7530, 0x7530, 0x7530
356 /* --- variables --- */
357 static const GdkColor gtk_default_normal_fg = { 0, GTK_BLACK };
358 static const GdkColor gtk_default_active_fg = { 0, GTK_BLACK };
359 static const GdkColor gtk_default_prelight_fg = { 0, GTK_BLACK };
360 static const GdkColor gtk_default_selected_fg = { 0, GTK_WHITE };
361 static const GdkColor gtk_default_insensitive_fg = { 0, GTK_WEAK_GRAY };
363 static const GdkColor gtk_default_normal_bg = { 0, GTK_GRAY };
364 static const GdkColor gtk_default_active_bg = { 0, GTK_DARK_GRAY };
365 static const GdkColor gtk_default_prelight_bg = { 0, GTK_LIGHT_GRAY };
366 static const GdkColor gtk_default_selected_bg = { 0, GTK_BLUE };
367 static const GdkColor gtk_default_insensitive_bg = { 0, GTK_GRAY };
368 static const GdkColor gtk_default_selected_base = { 0, GTK_BLUE };
369 static const GdkColor gtk_default_active_base = { 0, GTK_VERY_DARK_GRAY };
371 /* --- signals --- */
372 static guint realize_signal = 0;
373 static guint unrealize_signal = 0;
375 G_DEFINE_TYPE (GtkStyle, gtk_style, G_TYPE_OBJECT)
377 /* --- functions --- */
380 gtk_style_init (GtkStyle *style)
384 style->font_desc = pango_font_description_from_string ("Sans 10");
386 style->attach_count = 0;
388 style->black.red = 0;
389 style->black.green = 0;
390 style->black.blue = 0;
392 style->white.red = 65535;
393 style->white.green = 65535;
394 style->white.blue = 65535;
396 style->fg[GTK_STATE_NORMAL] = gtk_default_normal_fg;
397 style->fg[GTK_STATE_ACTIVE] = gtk_default_active_fg;
398 style->fg[GTK_STATE_PRELIGHT] = gtk_default_prelight_fg;
399 style->fg[GTK_STATE_SELECTED] = gtk_default_selected_fg;
400 style->fg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
402 style->bg[GTK_STATE_NORMAL] = gtk_default_normal_bg;
403 style->bg[GTK_STATE_ACTIVE] = gtk_default_active_bg;
404 style->bg[GTK_STATE_PRELIGHT] = gtk_default_prelight_bg;
405 style->bg[GTK_STATE_SELECTED] = gtk_default_selected_bg;
406 style->bg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_bg;
408 for (i = 0; i < 4; i++)
410 style->text[i] = style->fg[i];
411 style->base[i] = style->white;
414 style->base[GTK_STATE_SELECTED] = gtk_default_selected_base;
415 style->text[GTK_STATE_SELECTED] = style->white;
416 style->base[GTK_STATE_ACTIVE] = gtk_default_active_base;
417 style->text[GTK_STATE_ACTIVE] = style->white;
418 style->base[GTK_STATE_INSENSITIVE] = gtk_default_prelight_bg;
419 style->text[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
421 style->rc_style = NULL;
423 style->xthickness = 2;
424 style->ythickness = 2;
426 style->property_cache = NULL;
430 gtk_style_class_init (GtkStyleClass *klass)
432 GObjectClass *object_class = G_OBJECT_CLASS (klass);
434 object_class->finalize = gtk_style_finalize;
435 object_class->set_property = gtk_style_set_property;
436 object_class->get_property = gtk_style_get_property;
437 object_class->constructed = gtk_style_constructed;
439 klass->clone = gtk_style_real_clone;
440 klass->copy = gtk_style_real_copy;
441 klass->init_from_rc = gtk_style_real_init_from_rc;
442 klass->realize = gtk_style_real_realize;
443 klass->unrealize = gtk_style_real_unrealize;
444 klass->set_background = gtk_style_real_set_background;
445 klass->render_icon = gtk_default_render_icon;
447 klass->draw_hline = gtk_default_draw_hline;
448 klass->draw_vline = gtk_default_draw_vline;
449 klass->draw_shadow = gtk_default_draw_shadow;
450 klass->draw_arrow = gtk_default_draw_arrow;
451 klass->draw_diamond = gtk_default_draw_diamond;
452 klass->draw_box = gtk_default_draw_box;
453 klass->draw_flat_box = gtk_default_draw_flat_box;
454 klass->draw_check = gtk_default_draw_check;
455 klass->draw_option = gtk_default_draw_option;
456 klass->draw_tab = gtk_default_draw_tab;
457 klass->draw_shadow_gap = gtk_default_draw_shadow_gap;
458 klass->draw_box_gap = gtk_default_draw_box_gap;
459 klass->draw_extension = gtk_default_draw_extension;
460 klass->draw_focus = gtk_default_draw_focus;
461 klass->draw_slider = gtk_default_draw_slider;
462 klass->draw_handle = gtk_default_draw_handle;
463 klass->draw_expander = gtk_default_draw_expander;
464 klass->draw_layout = gtk_default_draw_layout;
465 klass->draw_resize_grip = gtk_default_draw_resize_grip;
466 klass->draw_spinner = gtk_default_draw_spinner;
468 g_type_class_add_private (object_class, sizeof (GtkStylePrivate));
470 g_object_class_install_property (object_class,
472 g_param_spec_object ("context",
474 P_("GtkStyleContext to get style from"),
475 GTK_TYPE_STYLE_CONTEXT,
476 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
480 * @style: the object which received the signal
482 * Emitted when the style has been initialized for a particular
483 * visual. Connecting to this signal is probably seldom
484 * useful since most of the time applications and widgets only
485 * deal with styles that have been already realized.
489 realize_signal = g_signal_new (I_("realize"),
490 G_TYPE_FROM_CLASS (object_class),
492 G_STRUCT_OFFSET (GtkStyleClass, realize),
494 _gtk_marshal_VOID__VOID,
497 * GtkStyle::unrealize:
498 * @style: the object which received the signal
500 * Emitted when the aspects of the style specific to a particular visual
501 * is being cleaned up. A connection to this signal can be useful
502 * if a widget wants to cache objects as object data on #GtkStyle.
503 * This signal provides a convenient place to free such cached objects.
507 unrealize_signal = g_signal_new (I_("unrealize"),
508 G_TYPE_FROM_CLASS (object_class),
510 G_STRUCT_OFFSET (GtkStyleClass, unrealize),
512 _gtk_marshal_VOID__VOID,
517 gtk_style_finalize (GObject *object)
519 GtkStyle *style = GTK_STYLE (object);
520 GtkStylePrivate *priv = GTK_STYLE_GET_PRIVATE (style);
523 g_return_if_fail (style->attach_count == 0);
525 /* All the styles in the list have the same
526 * style->styles pointer. If we delete the
527 * *first* style from the list, we need to update
528 * the style->styles pointers from all the styles.
529 * Otherwise we simply remove the node from
534 if (style->styles->data != style)
535 style->styles = g_slist_remove (style->styles, style);
538 GSList *tmp_list = style->styles->next;
542 GTK_STYLE (tmp_list->data)->styles = style->styles->next;
543 tmp_list = tmp_list->next;
545 g_slist_free_1 (style->styles);
549 g_slist_foreach (style->icon_factories, (GFunc) g_object_unref, NULL);
550 g_slist_free (style->icon_factories);
552 pango_font_description_free (style->font_desc);
554 if (style->private_font_desc)
555 pango_font_description_free (style->private_font_desc);
558 g_object_unref (style->rc_style);
562 if (priv->context_changed_id)
563 g_signal_handler_disconnect (priv->context, priv->context_changed_id);
565 g_object_unref (priv->context);
568 for (i = 0; i < 5; i++)
570 if (style->background[i])
571 cairo_pattern_destroy (style->background[i]);
574 G_OBJECT_CLASS (gtk_style_parent_class)->finalize (object);
578 gtk_style_set_property (GObject *object,
583 GtkStylePrivate *priv;
585 priv = GTK_STYLE_GET_PRIVATE (object);
590 priv->context = g_value_dup_object (value);
593 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
599 gtk_style_get_property (GObject *object,
604 GtkStylePrivate *priv;
606 priv = GTK_STYLE_GET_PRIVATE (object);
611 g_value_set_object (value, priv->context);
614 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
620 set_color (GtkStyle *style,
621 GtkStyleContext *context,
626 GdkRGBA *color = NULL;
627 GdkColor *dest = { 0 }; /* Shut up gcc */
631 case GTK_STATE_ACTIVE:
632 flags = GTK_STATE_FLAG_ACTIVE;
634 case GTK_STATE_PRELIGHT:
635 flags = GTK_STATE_FLAG_PRELIGHT;
637 case GTK_STATE_SELECTED:
638 flags = GTK_STATE_FLAG_SELECTED;
640 case GTK_STATE_INSENSITIVE:
641 flags = GTK_STATE_FLAG_INSENSITIVE;
650 gtk_style_context_get (context, flags,
651 "background-color", &color,
653 dest = &style->bg[state];
656 gtk_style_context_get (context, flags,
659 dest = &style->fg[state];
662 gtk_style_context_get (context, flags,
665 dest = &style->text[state];
668 gtk_style_context_get (context, flags,
669 "background-color", &color,
671 dest = &style->base[state];
678 dest->red = CLAMP ((guint) (color->red * 65535), 0, 65535);
679 dest->green = CLAMP ((guint) (color->green * 65535), 0, 65535);
680 dest->blue = CLAMP ((guint) (color->blue * 65535), 0, 65535);
681 gdk_rgba_free (color);
686 gtk_style_update_from_context (GtkStyle *style)
688 GtkStylePrivate *priv;
693 priv = GTK_STYLE_GET_PRIVATE (style);
695 for (state = GTK_STATE_NORMAL; state <= GTK_STATE_INSENSITIVE; state++)
697 if (gtk_style_context_has_class (priv->context, "entry"))
699 gtk_style_context_save (priv->context);
700 gtk_style_context_remove_class (priv->context, "entry");
701 set_color (style, priv->context, state, GTK_RC_BG);
702 set_color (style, priv->context, state, GTK_RC_FG);
703 gtk_style_context_restore (priv->context);
705 set_color (style, priv->context, state, GTK_RC_BASE);
706 set_color (style, priv->context, state, GTK_RC_TEXT);
710 gtk_style_context_save (priv->context);
711 gtk_style_context_add_class (priv->context, "entry");
712 set_color (style, priv->context, state, GTK_RC_BASE);
713 set_color (style, priv->context, state, GTK_RC_TEXT);
714 gtk_style_context_restore (priv->context);
716 set_color (style, priv->context, state, GTK_RC_BG);
717 set_color (style, priv->context, state, GTK_RC_FG);
721 if (style->font_desc)
722 pango_font_description_free (style->font_desc);
724 gtk_style_context_get (priv->context, 0,
725 "font", &style->font_desc,
727 gtk_style_context_get_padding (priv->context, 0, &padding);
729 style->xthickness = padding.left;
730 style->ythickness = padding.top;
732 for (i = 0; i < 5; i++)
734 _gtk_style_shade (&style->bg[i], &style->light[i], LIGHTNESS_MULT);
735 _gtk_style_shade (&style->bg[i], &style->dark[i], DARKNESS_MULT);
737 style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
738 style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
739 style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
741 style->text_aa[i].red = (style->text[i].red + style->base[i].red) / 2;
742 style->text_aa[i].green = (style->text[i].green + style->base[i].green) / 2;
743 style->text_aa[i].blue = (style->text[i].blue + style->base[i].blue) / 2;
746 style->black.red = 0x0000;
747 style->black.green = 0x0000;
748 style->black.blue = 0x0000;
750 style->white.red = 0xffff;
751 style->white.green = 0xffff;
752 style->white.blue = 0xffff;
754 for (i = 0; i < 5; i++)
756 if (style->background[i])
757 cairo_pattern_destroy (style->background[i]);
759 style->background[i] = cairo_pattern_create_rgb (style->bg[i].red / 65535.0,
760 style->bg[i].green / 65535.0,
761 style->bg[i].blue / 65535.0);
766 style_context_changed (GtkStyleContext *context,
769 gtk_style_update_from_context (GTK_STYLE (user_data));
773 gtk_style_constructed (GObject *object)
775 GtkStylePrivate *priv;
777 priv = GTK_STYLE_GET_PRIVATE (object);
781 gtk_style_update_from_context (GTK_STYLE (object));
783 priv->context_changed_id = g_signal_connect (priv->context, "changed",
784 G_CALLBACK (style_context_changed), object);
790 * @style: a #GtkStyle
792 * Creates a copy of the passed in #GtkStyle object.
794 * Returns: (transfer full): a copy of @style
796 * Deprecated:3.0: Use #GtkStyleContext instead
799 gtk_style_copy (GtkStyle *style)
803 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
805 new_style = GTK_STYLE_GET_CLASS (style)->clone (style);
806 GTK_STYLE_GET_CLASS (style)->copy (new_style, style);
812 _gtk_style_new_for_path (GdkScreen *screen,
815 GtkStyleContext *context;
818 context = gtk_style_context_new ();
821 gtk_style_context_set_screen (context, screen);
823 gtk_style_context_set_path (context, path);
825 style = g_object_new (GTK_TYPE_STYLE,
829 g_object_unref (context);
837 * Creates a new #GtkStyle.
839 * Returns: a new #GtkStyle.
841 * Deprecated: 3.0: Use #GtkStyleContext
849 path = gtk_widget_path_new ();
850 gtk_widget_path_append_type (path, GTK_TYPE_WIDGET);
852 style = _gtk_style_new_for_path (gdk_screen_get_default (), path);
854 gtk_widget_path_free (path);
860 * gtk_style_has_context:
861 * @style: a #GtkStyle
863 * Returns whether @style has an associated #GtkStyleContext.
865 * Returns: %TRUE if @style has a #GtkStyleContext
870 gtk_style_has_context (GtkStyle *style)
872 GtkStylePrivate *priv;
874 priv = GTK_STYLE_GET_PRIVATE (style);
876 return priv->context != NULL;
880 * gtk_style_attach: (skip)
881 * @style: a #GtkStyle.
882 * @window: a #GdkWindow.
884 * Attaches a style to a window; this process allocates the
885 * colors and creates the GC's for the style - it specializes
886 * it to a particular visual. The process may involve the creation
887 * of a new style if the style has already been attached to a
888 * window with a different style and visual.
890 * Since this function may return a new object, you have to use it
891 * in the following way:
892 * <literal>style = gtk_style_attach (style, window)</literal>
894 * Returns: Either @style, or a newly-created #GtkStyle.
895 * If the style is newly created, the style parameter
896 * will be unref'ed, and the new style will have
897 * a reference count belonging to the caller.
899 * Deprecated:3.0: Use gtk_widget_style_attach() instead
902 gtk_style_attach (GtkStyle *style,
905 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
906 g_return_val_if_fail (window != NULL, NULL);
913 * @style: a #GtkStyle
915 * Detaches a style from a window. If the style is not attached
916 * to any windows anymore, it is unrealized. See gtk_style_attach().
918 * Deprecated:3.0: Use #GtkStyleContext instead
921 gtk_style_detach (GtkStyle *style)
923 g_return_if_fail (GTK_IS_STYLE (style));
927 * gtk_style_lookup_icon_set:
928 * @style: a #GtkStyle
929 * @stock_id: an icon name
931 * Looks up @stock_id in the icon factories associated with @style
932 * and the default icon factory, returning an icon set if found,
935 * Return value: (transfer none): icon set of @stock_id
937 * Deprecated:3.0: Use gtk_style_context_lookup_icon_set() instead
940 gtk_style_lookup_icon_set (GtkStyle *style,
941 const char *stock_id)
943 GtkStylePrivate *priv;
945 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
946 g_return_val_if_fail (stock_id != NULL, NULL);
948 priv = GTK_STYLE_GET_PRIVATE (style);
951 return gtk_style_context_lookup_icon_set (priv->context, stock_id);
953 return gtk_icon_factory_lookup_default (stock_id);
957 * gtk_style_lookup_color:
958 * @style: a #GtkStyle
959 * @color_name: the name of the logical color to look up
960 * @color: (out): the #GdkColor to fill in
962 * Looks up @color_name in the style's logical color mappings,
963 * filling in @color and returning %TRUE if found, otherwise
964 * returning %FALSE. Do not cache the found mapping, because
965 * it depends on the #GtkStyle and might change when a theme
968 * Return value: %TRUE if the mapping was found.
972 * Deprecated:3.0: Use gtk_style_context_lookup_color() instead
975 gtk_style_lookup_color (GtkStyle *style,
976 const char *color_name,
979 GtkStylePrivate *priv;
983 g_return_val_if_fail (GTK_IS_STYLE (style), FALSE);
984 g_return_val_if_fail (color_name != NULL, FALSE);
985 g_return_val_if_fail (color != NULL, FALSE);
987 priv = GTK_STYLE_GET_PRIVATE (style);
992 result = gtk_style_context_lookup_color (priv->context, color_name, &rgba);
996 color->red = (guint16) (rgba.red * 65535);
997 color->green = (guint16) (rgba.green * 65535);
998 color->blue = (guint16) (rgba.blue * 65535);
1006 * gtk_style_set_background:
1007 * @style: a #GtkStyle
1008 * @window: a #GdkWindow
1009 * @state_type: a state
1011 * Sets the background of @window to the background color or pixmap
1012 * specified by @style for the given state.
1014 * Deprecated:3.0: Use gtk_style_context_set_background() instead
1017 gtk_style_set_background (GtkStyle *style,
1019 GtkStateType state_type)
1021 g_return_if_fail (GTK_IS_STYLE (style));
1022 g_return_if_fail (window != NULL);
1024 GTK_STYLE_GET_CLASS (style)->set_background (style, window, state_type);
1027 /* Default functions */
1029 gtk_style_real_clone (GtkStyle *style)
1031 GtkStylePrivate *priv;
1033 priv = GTK_STYLE_GET_PRIVATE (style);
1035 return g_object_new (G_OBJECT_TYPE (style),
1036 "context", priv->context,
1041 gtk_style_real_copy (GtkStyle *style,
1046 for (i = 0; i < 5; i++)
1048 style->fg[i] = src->fg[i];
1049 style->bg[i] = src->bg[i];
1050 style->text[i] = src->text[i];
1051 style->base[i] = src->base[i];
1053 if (style->background[i])
1054 cairo_pattern_destroy (style->background[i]),
1055 style->background[i] = src->background[i];
1056 if (style->background[i])
1057 cairo_pattern_reference (style->background[i]);
1060 if (style->font_desc)
1061 pango_font_description_free (style->font_desc);
1063 style->font_desc = pango_font_description_copy (src->font_desc);
1065 style->font_desc = NULL;
1067 style->xthickness = src->xthickness;
1068 style->ythickness = src->ythickness;
1070 if (style->rc_style)
1071 g_object_unref (style->rc_style);
1072 style->rc_style = src->rc_style;
1074 g_object_ref (src->rc_style);
1076 g_slist_foreach (style->icon_factories, (GFunc) g_object_unref, NULL);
1077 g_slist_free (style->icon_factories);
1078 style->icon_factories = g_slist_copy (src->icon_factories);
1079 g_slist_foreach (style->icon_factories, (GFunc) g_object_ref, NULL);
1083 gtk_style_real_init_from_rc (GtkStyle *style,
1084 GtkRcStyle *rc_style)
1089 * gtk_style_get_style_property:
1090 * @style: a #GtkStyle
1091 * @widget_type: the #GType of a descendant of #GtkWidget
1092 * @property_name: the name of the style property to get
1093 * @value: a #GValue where the value of the property being
1094 * queried will be stored
1096 * Queries the value of a style property corresponding to a
1097 * widget class is in the given style.
1102 gtk_style_get_style_property (GtkStyle *style,
1104 const gchar *property_name,
1107 GtkStylePrivate *priv;
1108 GtkWidgetClass *klass;
1110 const GValue *peek_value;
1112 klass = g_type_class_ref (widget_type);
1113 pspec = gtk_widget_class_find_style_property (klass, property_name);
1114 g_type_class_unref (klass);
1118 g_warning ("%s: widget class `%s' has no property named `%s'",
1120 g_type_name (widget_type),
1125 priv = GTK_STYLE_GET_PRIVATE (style);
1126 peek_value = _gtk_style_context_peek_style_property (priv->context,
1130 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
1131 g_value_copy (peek_value, value);
1132 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
1133 g_value_transform (peek_value, value);
1135 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
1137 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1138 G_VALUE_TYPE_NAME (value));
1142 * gtk_style_get_valist:
1143 * @style: a #GtkStyle
1144 * @widget_type: the #GType of a descendant of #GtkWidget
1145 * @first_property_name: the name of the first style property to get
1146 * @var_args: a <type>va_list</type> of pairs of property names and
1147 * locations to return the property values, starting with the
1148 * location for @first_property_name.
1150 * Non-vararg variant of gtk_style_get().
1151 * Used primarily by language bindings.
1156 gtk_style_get_valist (GtkStyle *style,
1158 const gchar *first_property_name,
1161 GtkStylePrivate *priv;
1162 const char *property_name;
1163 GtkWidgetClass *klass;
1165 g_return_if_fail (GTK_IS_STYLE (style));
1167 klass = g_type_class_ref (widget_type);
1169 priv = GTK_STYLE_GET_PRIVATE (style);
1170 property_name = first_property_name;
1171 while (property_name)
1174 const GValue *peek_value;
1177 pspec = gtk_widget_class_find_style_property (klass, property_name);
1181 g_warning ("%s: widget class `%s' has no property named `%s'",
1183 g_type_name (widget_type),
1188 peek_value = _gtk_style_context_peek_style_property (priv->context, widget_type,
1190 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
1193 g_warning ("%s: %s", G_STRLOC, error);
1198 property_name = va_arg (var_args, gchar*);
1201 g_type_class_unref (klass);
1206 * @style: a #GtkStyle
1207 * @widget_type: the #GType of a descendant of #GtkWidget
1208 * @first_property_name: the name of the first style property to get
1209 * @...: pairs of property names and locations to
1210 * return the property values, starting with the location for
1211 * @first_property_name, terminated by %NULL.
1213 * Gets the values of a multiple style properties for @widget_type
1219 gtk_style_get (GtkStyle *style,
1221 const gchar *first_property_name,
1226 va_start (var_args, first_property_name);
1227 gtk_style_get_valist (style, widget_type, first_property_name, var_args);
1232 gtk_style_real_realize (GtkStyle *style)
1237 gtk_style_real_unrealize (GtkStyle *style)
1242 gtk_style_real_set_background (GtkStyle *style,
1244 GtkStateType state_type)
1246 gdk_window_set_background_pattern (window, style->background[state_type]);
1250 * gtk_style_render_icon:
1251 * @style: a #GtkStyle
1252 * @source: the #GtkIconSource specifying the icon to render
1253 * @direction: a text direction
1255 * @size: (type int): the size to render the icon at. A size of
1256 * (GtkIconSize)-1 means render at the size of the source and
1258 * @widget: (allow-none): the widget
1259 * @detail: (allow-none): a style detail
1261 * Renders the icon specified by @source at the given @size
1262 * according to the given parameters and returns the result in a
1265 * Return value: (transfer full): a newly-created #GdkPixbuf
1266 * containing the rendered icon
1268 * Deprecated:3.0: Use gtk_render_icon_pixbuf() instead
1271 gtk_style_render_icon (GtkStyle *style,
1272 const GtkIconSource *source,
1273 GtkTextDirection direction,
1277 const gchar *detail)
1281 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1282 g_return_val_if_fail (GTK_STYLE_GET_CLASS (style)->render_icon != NULL, NULL);
1284 pixbuf = GTK_STYLE_GET_CLASS (style)->render_icon (style, source, direction, state,
1285 size, widget, detail);
1287 g_return_val_if_fail (pixbuf != NULL, NULL);
1292 /* Default functions */
1295 * gtk_style_apply_default_background:
1305 * Deprecated:3.0: Use #GtkStyleContext instead
1308 gtk_style_apply_default_background (GtkStyle *style,
1311 GtkStateType state_type,
1319 if (style->background[state_type] == NULL)
1321 GdkWindow *parent = gdk_window_get_parent (window);
1322 int x_offset, y_offset;
1326 gdk_window_get_position (window, &x_offset, &y_offset);
1327 cairo_translate (cr, -x_offset, -y_offset);
1328 gtk_style_apply_default_background (style, cr,
1330 x + x_offset, y + y_offset,
1335 gdk_cairo_set_source_color (cr, &style->bg[state_type]);
1338 cairo_set_source (cr, style->background[state_type]);
1340 cairo_rectangle (cr, x, y, width, height);
1348 gtk_default_render_icon (GtkStyle *style,
1349 const GtkIconSource *source,
1350 GtkTextDirection direction,
1354 const gchar *detail)
1356 GtkStyleContext *context;
1357 GtkStylePrivate *priv;
1358 GtkStateFlags flags = 0;
1362 context = gtk_widget_get_style_context (widget);
1365 priv = GTK_STYLE_GET_PRIVATE (style);
1366 context = priv->context;
1372 gtk_style_context_save (context);
1375 transform_detail_string (detail, context);
1379 case GTK_STATE_PRELIGHT:
1380 flags |= GTK_STATE_FLAG_PRELIGHT;
1382 case GTK_STATE_INSENSITIVE:
1383 flags |= GTK_STATE_FLAG_INSENSITIVE;
1389 gtk_style_context_set_state (context, flags);
1391 pixbuf = gtk_render_icon_pixbuf (context, source, size);
1393 gtk_style_context_restore (context);
1399 _cairo_draw_line (cairo_t *cr,
1408 gdk_cairo_set_source_color (cr, color);
1409 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
1411 cairo_move_to (cr, x1 + 0.5, y1 + 0.5);
1412 cairo_line_to (cr, x2 + 0.5, y2 + 0.5);
1419 transform_detail_string (const gchar *detail,
1420 GtkStyleContext *context)
1425 if (strcmp (detail, "arrow") == 0)
1426 gtk_style_context_add_class (context, "arrow");
1427 else if (strcmp (detail, "button") == 0)
1428 gtk_style_context_add_class (context, "button");
1429 else if (strcmp (detail, "buttondefault") == 0)
1431 gtk_style_context_add_class (context, "button");
1432 gtk_style_context_add_class (context, "default");
1434 else if (strcmp (detail, "calendar") == 0)
1435 gtk_style_context_add_class (context, "calendar");
1436 else if (strcmp (detail, "cellcheck") == 0)
1438 gtk_style_context_add_class (context, "cell");
1439 gtk_style_context_add_class (context, "check");
1441 else if (strcmp (detail, "cellradio") == 0)
1443 gtk_style_context_add_class (context, "cell");
1444 gtk_style_context_add_class (context, "radio");
1446 else if (strcmp (detail, "checkbutton") == 0)
1447 gtk_style_context_add_class (context, "check");
1448 else if (strcmp (detail, "check") == 0)
1450 gtk_style_context_add_class (context, "check");
1451 gtk_style_context_add_class (context, "menu");
1453 else if (strcmp (detail, "radiobutton") == 0)
1455 gtk_style_context_add_class (context, "radio");
1457 else if (strcmp (detail, "option") == 0)
1459 gtk_style_context_add_class (context, "radio");
1460 gtk_style_context_add_class (context, "menu");
1462 else if (strcmp (detail, "entry") == 0 ||
1463 strcmp (detail, "entry_bg") == 0)
1464 gtk_style_context_add_class (context, "entry");
1465 else if (strcmp (detail, "expander") == 0)
1466 gtk_style_context_add_class (context, "expander");
1467 else if (strcmp (detail, "tooltip") == 0)
1468 gtk_style_context_add_class (context, "tooltip");
1469 else if (strcmp (detail, "frame") == 0)
1470 gtk_style_context_add_class (context, "frame");
1471 else if (strcmp (detail, "scrolled_window") == 0)
1472 gtk_style_context_add_class (context, "scrolled-window");
1473 else if (strcmp (detail, "viewport") == 0 ||
1474 strcmp (detail, "viewportbin") == 0)
1475 gtk_style_context_add_class (context, "viewport");
1476 else if (strncmp (detail, "trough", 6) == 0)
1477 gtk_style_context_add_class (context, "trough");
1478 else if (strcmp (detail, "spinbutton") == 0)
1479 gtk_style_context_add_class (context, "spinbutton");
1480 else if (strcmp (detail, "spinbutton_up") == 0)
1482 gtk_style_context_add_class (context, "spinbutton");
1483 gtk_style_context_add_class (context, "button");
1484 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
1486 else if (strcmp (detail, "spinbutton_down") == 0)
1488 gtk_style_context_add_class (context, "spinbutton");
1489 gtk_style_context_add_class (context, "button");
1490 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
1492 else if ((detail[0] == 'h' || detail[0] == 'v') &&
1493 strncmp (&detail[1], "scrollbar_", 10) == 0)
1495 gtk_style_context_add_class (context, "button");
1496 gtk_style_context_add_class (context, "scrollbar");
1498 else if (strcmp (detail, "slider") == 0)
1500 gtk_style_context_add_class (context, "slider");
1501 gtk_style_context_add_class (context, "scrollbar");
1503 else if (strcmp (detail, "vscale") == 0 ||
1504 strcmp (detail, "hscale") == 0)
1506 gtk_style_context_add_class (context, "slider");
1507 gtk_style_context_add_class (context, "scale");
1509 else if (strcmp (detail, "menuitem") == 0)
1511 gtk_style_context_add_class (context, "menuitem");
1512 gtk_style_context_add_class (context, "menu");
1514 else if (strcmp (detail, "menu") == 0)
1516 gtk_style_context_add_class (context, "popup");
1517 gtk_style_context_add_class (context, "menu");
1519 else if (strcmp (detail, "accellabel") == 0)
1520 gtk_style_context_add_class (context, "accelerator");
1521 else if (strcmp (detail, "menubar") == 0)
1522 gtk_style_context_add_class (context, "menubar");
1523 else if (strcmp (detail, "base") == 0)
1524 gtk_style_context_add_class (context, "background");
1525 else if (strcmp (detail, "bar") == 0 ||
1526 strcmp (detail, "progressbar") == 0)
1527 gtk_style_context_add_class (context, "progressbar");
1528 else if (strcmp (detail, "toolbar") == 0)
1529 gtk_style_context_add_class (context, "toolbar");
1530 else if (strcmp (detail, "handlebox_bin") == 0)
1531 gtk_style_context_add_class (context, "dock");
1532 else if (strcmp (detail, "notebook") == 0)
1533 gtk_style_context_add_class (context, "notebook");
1534 else if (strcmp (detail, "tab") == 0)
1536 gtk_style_context_add_class (context, "notebook");
1537 gtk_style_context_add_region (context, GTK_STYLE_REGION_TAB, 0);
1539 else if (g_str_has_prefix (detail, "cell"))
1541 GtkRegionFlags row, col;
1542 gboolean ruled = FALSE;
1546 tokens = g_strsplit (detail, "_", -1);
1552 if (strcmp (tokens[i], "even") == 0)
1553 row |= GTK_REGION_EVEN;
1554 else if (strcmp (tokens[i], "odd") == 0)
1555 row |= GTK_REGION_ODD;
1556 else if (strcmp (tokens[i], "start") == 0)
1557 col |= GTK_REGION_FIRST;
1558 else if (strcmp (tokens[i], "end") == 0)
1559 col |= GTK_REGION_LAST;
1560 else if (strcmp (tokens[i], "ruled") == 0)
1562 else if (strcmp (tokens[i], "sorted") == 0)
1563 col |= GTK_REGION_SORTED;
1569 row &= ~(GTK_REGION_EVEN | GTK_REGION_ODD);
1571 gtk_style_context_add_class (context, "cell");
1572 gtk_style_context_add_region (context, "row", row);
1573 gtk_style_context_add_region (context, "column", col);
1575 g_strfreev (tokens);
1580 gtk_default_draw_hline (GtkStyle *style,
1582 GtkStateType state_type,
1584 const gchar *detail,
1589 GtkStyleContext *context;
1590 GtkStylePrivate *priv;
1593 context = gtk_widget_get_style_context (widget);
1596 priv = GTK_STYLE_GET_PRIVATE (style);
1597 context = priv->context;
1600 gtk_style_context_save (context);
1603 transform_detail_string (detail, context);
1607 gtk_render_line (context, cr,
1612 gtk_style_context_restore (context);
1617 gtk_default_draw_vline (GtkStyle *style,
1619 GtkStateType state_type,
1621 const gchar *detail,
1626 GtkStyleContext *context;
1627 GtkStylePrivate *priv;
1630 context = gtk_widget_get_style_context (widget);
1633 priv = GTK_STYLE_GET_PRIVATE (style);
1634 context = priv->context;
1637 gtk_style_context_save (context);
1640 transform_detail_string (detail, context);
1644 gtk_render_line (context, cr,
1648 gtk_style_context_restore (context);
1652 gtk_default_draw_shadow (GtkStyle *style,
1654 GtkStateType state_type,
1655 GtkShadowType shadow_type,
1657 const gchar *detail,
1663 GtkStyleContext *context;
1664 GtkStylePrivate *priv;
1666 if (shadow_type == GTK_SHADOW_NONE)
1670 context = gtk_widget_get_style_context (widget);
1673 priv = GTK_STYLE_GET_PRIVATE (style);
1674 context = priv->context;
1677 gtk_style_context_save (context);
1680 transform_detail_string (detail, context);
1684 gtk_render_frame (context, cr,
1691 gtk_style_context_restore (context);
1695 draw_arrow (cairo_t *cr,
1697 GtkArrowType arrow_type,
1703 gdk_cairo_set_source_color (cr, color);
1706 if (arrow_type == GTK_ARROW_DOWN)
1708 cairo_move_to (cr, x, y);
1709 cairo_line_to (cr, x + width, y);
1710 cairo_line_to (cr, x + width / 2., y + height);
1712 else if (arrow_type == GTK_ARROW_UP)
1714 cairo_move_to (cr, x, y + height);
1715 cairo_line_to (cr, x + width / 2., y);
1716 cairo_line_to (cr, x + width, y + height);
1718 else if (arrow_type == GTK_ARROW_LEFT)
1720 cairo_move_to (cr, x + width, y);
1721 cairo_line_to (cr, x + width, y + height);
1722 cairo_line_to (cr, x, y + height / 2.);
1724 else if (arrow_type == GTK_ARROW_RIGHT)
1726 cairo_move_to (cr, x, y);
1727 cairo_line_to (cr, x + width, y + height / 2.);
1728 cairo_line_to (cr, x, y + height);
1731 cairo_close_path (cr);
1738 gtk_default_draw_arrow (GtkStyle *style,
1741 GtkShadowType shadow,
1743 const gchar *detail,
1744 GtkArrowType arrow_type,
1751 GtkStyleContext *context;
1752 GtkStylePrivate *priv;
1753 GtkStateFlags flags = 0;
1754 gdouble angle, size;
1756 if (arrow_type == GTK_ARROW_NONE)
1760 context = gtk_widget_get_style_context (widget);
1763 priv = GTK_STYLE_GET_PRIVATE (style);
1764 context = priv->context;
1767 gtk_style_context_save (context);
1770 transform_detail_string (detail, context);
1778 case GTK_ARROW_RIGHT:
1782 case GTK_ARROW_DOWN:
1786 case GTK_ARROW_LEFT:
1787 angle = 3 * (G_PI / 2);
1791 g_assert_not_reached ();
1796 case GTK_STATE_PRELIGHT:
1797 flags |= GTK_STATE_FLAG_PRELIGHT;
1799 case GTK_STATE_SELECTED:
1800 flags |= GTK_STATE_FLAG_SELECTED;
1802 case GTK_STATE_INSENSITIVE:
1803 flags |= GTK_STATE_FLAG_INSENSITIVE;
1805 case GTK_STATE_ACTIVE:
1806 flags |= GTK_STATE_FLAG_ACTIVE;
1812 gtk_style_context_set_state (context, flags);
1816 gtk_render_arrow (context,
1823 gtk_style_context_restore (context);
1827 gtk_default_draw_diamond (GtkStyle *style,
1829 GtkStateType state_type,
1830 GtkShadowType shadow_type,
1832 const gchar *detail,
1840 GdkColor *outer_nw = NULL;
1841 GdkColor *outer_ne = NULL;
1842 GdkColor *outer_sw = NULL;
1843 GdkColor *outer_se = NULL;
1844 GdkColor *middle_nw = NULL;
1845 GdkColor *middle_ne = NULL;
1846 GdkColor *middle_sw = NULL;
1847 GdkColor *middle_se = NULL;
1848 GdkColor *inner_nw = NULL;
1849 GdkColor *inner_ne = NULL;
1850 GdkColor *inner_sw = NULL;
1851 GdkColor *inner_se = NULL;
1853 half_width = width / 2;
1854 half_height = height / 2;
1856 switch (shadow_type)
1859 inner_sw = inner_se = &style->bg[state_type];
1860 middle_sw = middle_se = &style->light[state_type];
1861 outer_sw = outer_se = &style->light[state_type];
1862 inner_nw = inner_ne = &style->black;
1863 middle_nw = middle_ne = &style->dark[state_type];
1864 outer_nw = outer_ne = &style->dark[state_type];
1867 case GTK_SHADOW_OUT:
1868 inner_sw = inner_se = &style->dark[state_type];
1869 middle_sw = middle_se = &style->dark[state_type];
1870 outer_sw = outer_se = &style->black;
1871 inner_nw = inner_ne = &style->bg[state_type];
1872 middle_nw = middle_ne = &style->light[state_type];
1873 outer_nw = outer_ne = &style->light[state_type];
1876 case GTK_SHADOW_ETCHED_IN:
1877 inner_sw = inner_se = &style->bg[state_type];
1878 middle_sw = middle_se = &style->dark[state_type];
1879 outer_sw = outer_se = &style->light[state_type];
1880 inner_nw = inner_ne = &style->bg[state_type];
1881 middle_nw = middle_ne = &style->light[state_type];
1882 outer_nw = outer_ne = &style->dark[state_type];
1885 case GTK_SHADOW_ETCHED_OUT:
1886 inner_sw = inner_se = &style->bg[state_type];
1887 middle_sw = middle_se = &style->light[state_type];
1888 outer_sw = outer_se = &style->dark[state_type];
1889 inner_nw = inner_ne = &style->bg[state_type];
1890 middle_nw = middle_ne = &style->dark[state_type];
1891 outer_nw = outer_ne = &style->light[state_type];
1901 _cairo_draw_line (cr, inner_sw,
1902 x + 2, y + half_height,
1903 x + half_width, y + height - 2);
1904 _cairo_draw_line (cr, inner_se,
1905 x + half_width, y + height - 2,
1906 x + width - 2, y + half_height);
1907 _cairo_draw_line (cr, middle_sw,
1908 x + 1, y + half_height,
1909 x + half_width, y + height - 1);
1910 _cairo_draw_line (cr, middle_se,
1911 x + half_width, y + height - 1,
1912 x + width - 1, y + half_height);
1913 _cairo_draw_line (cr, outer_sw,
1915 x + half_width, y + height);
1916 _cairo_draw_line (cr, outer_se,
1917 x + half_width, y + height,
1918 x + width, y + half_height);
1920 _cairo_draw_line (cr, inner_nw,
1921 x + 2, y + half_height,
1922 x + half_width, y + 2);
1923 _cairo_draw_line (cr, inner_ne,
1924 x + half_width, y + 2,
1925 x + width - 2, y + half_height);
1926 _cairo_draw_line (cr, middle_nw,
1927 x + 1, y + half_height,
1928 x + half_width, y + 1);
1929 _cairo_draw_line (cr, middle_ne,
1930 x + half_width, y + 1,
1931 x + width - 1, y + half_height);
1932 _cairo_draw_line (cr, outer_nw,
1935 _cairo_draw_line (cr, outer_ne,
1937 x + width, y + half_height);
1942 option_menu_get_props (GtkWidget *widget,
1943 GtkRequisition *indicator_size,
1944 GtkBorder *indicator_spacing)
1946 GtkRequisition *tmp_size = NULL;
1947 GtkBorder *tmp_spacing = NULL;
1951 *indicator_size = *tmp_size;
1952 gtk_requisition_free (tmp_size);
1955 *indicator_size = default_option_indicator_size;
1959 *indicator_spacing = *tmp_spacing;
1960 gtk_border_free (tmp_spacing);
1963 *indicator_spacing = default_option_indicator_spacing;
1967 gtk_default_draw_box (GtkStyle *style,
1969 GtkStateType state_type,
1970 GtkShadowType shadow_type,
1972 const gchar *detail,
1978 GtkStyleContext *context;
1979 GtkStylePrivate *priv;
1980 GtkStateFlags flags = 0;
1983 context = gtk_widget_get_style_context (widget);
1986 priv = GTK_STYLE_GET_PRIVATE (style);
1987 context = priv->context;
1990 gtk_style_context_save (context);
1993 transform_detail_string (detail, context);
1997 case GTK_STATE_ACTIVE:
1998 flags |= GTK_STATE_FLAG_ACTIVE;
2000 case GTK_STATE_PRELIGHT:
2001 flags |= GTK_STATE_FLAG_PRELIGHT;
2003 case GTK_STATE_SELECTED:
2004 flags |= GTK_STATE_FLAG_SELECTED;
2006 case GTK_STATE_INSENSITIVE:
2007 flags |= GTK_STATE_FLAG_INSENSITIVE;
2013 if (shadow_type == GTK_SHADOW_IN)
2014 flags |= GTK_STATE_FLAG_ACTIVE;
2016 gtk_style_context_set_state (context, flags);
2020 if (gtk_style_context_has_class (context, GTK_STYLE_CLASS_PROGRESSBAR))
2021 gtk_render_activity (context, cr, x, y, width, height);
2024 gtk_render_background (context, cr, x, y, width, height);
2026 if (shadow_type != GTK_SHADOW_NONE)
2027 gtk_render_frame (context, cr, x, y, width, height);
2031 gtk_style_context_restore (context);
2035 gtk_default_draw_flat_box (GtkStyle *style,
2037 GtkStateType state_type,
2038 GtkShadowType shadow_type,
2040 const gchar *detail,
2046 GtkStyleContext *context;
2047 GtkStylePrivate *priv;
2048 GtkStateFlags flags = 0;
2051 context = gtk_widget_get_style_context (widget);
2054 priv = GTK_STYLE_GET_PRIVATE (style);
2055 context = priv->context;
2058 gtk_style_context_save (context);
2061 transform_detail_string (detail, context);
2065 case GTK_STATE_PRELIGHT:
2066 flags |= GTK_STATE_FLAG_PRELIGHT;
2068 case GTK_STATE_SELECTED:
2069 flags |= GTK_STATE_FLAG_SELECTED;
2071 case GTK_STATE_INSENSITIVE:
2072 flags |= GTK_STATE_FLAG_INSENSITIVE;
2074 case GTK_STATE_ACTIVE:
2075 flags |= GTK_STATE_FLAG_ACTIVE;
2077 case GTK_STATE_FOCUSED:
2078 flags |= GTK_STATE_FLAG_FOCUSED;
2084 gtk_style_context_set_state (context, flags);
2088 gtk_render_background (context, cr,
2095 gtk_style_context_restore (context);
2099 gtk_default_draw_check (GtkStyle *style,
2101 GtkStateType state_type,
2102 GtkShadowType shadow_type,
2104 const gchar *detail,
2110 GtkStyleContext *context;
2111 GtkStylePrivate *priv;
2112 GtkStateFlags flags = 0;
2115 context = gtk_widget_get_style_context (widget);
2118 priv = GTK_STYLE_GET_PRIVATE (style);
2119 context = priv->context;
2122 gtk_style_context_save (context);
2125 transform_detail_string (detail, context);
2129 case GTK_STATE_PRELIGHT:
2130 flags |= GTK_STATE_FLAG_PRELIGHT;
2132 case GTK_STATE_SELECTED:
2133 flags |= GTK_STATE_FLAG_SELECTED;
2135 case GTK_STATE_INSENSITIVE:
2136 flags |= GTK_STATE_FLAG_INSENSITIVE;
2142 if (shadow_type == GTK_SHADOW_IN)
2143 flags |= GTK_STATE_FLAG_ACTIVE;
2144 else if (shadow_type == GTK_SHADOW_ETCHED_IN)
2145 flags |= GTK_STATE_FLAG_INCONSISTENT;
2147 gtk_style_context_set_state (context, flags);
2151 gtk_render_check (context,
2156 gtk_style_context_restore (context);
2160 gtk_default_draw_option (GtkStyle *style,
2162 GtkStateType state_type,
2163 GtkShadowType shadow_type,
2165 const gchar *detail,
2171 GtkStyleContext *context;
2172 GtkStylePrivate *priv;
2173 GtkStateFlags flags = 0;
2176 context = gtk_widget_get_style_context (widget);
2179 priv = GTK_STYLE_GET_PRIVATE (style);
2180 context = priv->context;
2183 gtk_style_context_save (context);
2186 transform_detail_string (detail, context);
2190 case GTK_STATE_PRELIGHT:
2191 flags |= GTK_STATE_FLAG_PRELIGHT;
2193 case GTK_STATE_SELECTED:
2194 flags |= GTK_STATE_FLAG_SELECTED;
2196 case GTK_STATE_INSENSITIVE:
2197 flags |= GTK_STATE_FLAG_INSENSITIVE;
2203 if (shadow_type == GTK_SHADOW_IN)
2204 flags |= GTK_STATE_FLAG_ACTIVE;
2205 else if (shadow_type == GTK_SHADOW_ETCHED_IN)
2206 flags |= GTK_STATE_FLAG_INCONSISTENT;
2208 gtk_style_context_set_state (context, flags);
2211 gtk_render_option (context, cr,
2218 gtk_style_context_restore (context);
2222 gtk_default_draw_tab (GtkStyle *style,
2224 GtkStateType state_type,
2225 GtkShadowType shadow_type,
2227 const gchar *detail,
2233 #define ARROW_SPACE 4
2235 GtkRequisition indicator_size;
2236 GtkBorder indicator_spacing;
2239 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
2241 indicator_size.width += (indicator_size.width % 2) - 1;
2242 arrow_height = indicator_size.width / 2 + 1;
2244 x += (width - indicator_size.width) / 2;
2245 y += (height - (2 * arrow_height + ARROW_SPACE)) / 2;
2247 if (state_type == GTK_STATE_INSENSITIVE)
2249 draw_arrow (cr, &style->white,
2250 GTK_ARROW_UP, x + 1, y + 1,
2251 indicator_size.width, arrow_height);
2253 draw_arrow (cr, &style->white,
2254 GTK_ARROW_DOWN, x + 1, y + arrow_height + ARROW_SPACE + 1,
2255 indicator_size.width, arrow_height);
2258 draw_arrow (cr, &style->fg[state_type],
2260 indicator_size.width, arrow_height);
2263 draw_arrow (cr, &style->fg[state_type],
2264 GTK_ARROW_DOWN, x, y + arrow_height + ARROW_SPACE,
2265 indicator_size.width, arrow_height);
2269 gtk_default_draw_shadow_gap (GtkStyle *style,
2271 GtkStateType state_type,
2272 GtkShadowType shadow_type,
2274 const gchar *detail,
2279 GtkPositionType gap_side,
2283 GtkStyleContext *context;
2284 GtkStylePrivate *priv;
2285 GtkStateFlags flags = 0;
2287 if (shadow_type == GTK_SHADOW_NONE)
2291 context = gtk_widget_get_style_context (widget);
2294 priv = GTK_STYLE_GET_PRIVATE (style);
2295 context = priv->context;
2298 gtk_style_context_save (context);
2301 transform_detail_string (detail, context);
2305 case GTK_STATE_ACTIVE:
2306 flags |= GTK_STATE_FLAG_ACTIVE;
2308 case GTK_STATE_PRELIGHT:
2309 flags |= GTK_STATE_FLAG_PRELIGHT;
2311 case GTK_STATE_SELECTED:
2312 flags |= GTK_STATE_FLAG_SELECTED;
2314 case GTK_STATE_INSENSITIVE:
2315 flags |= GTK_STATE_FLAG_INSENSITIVE;
2321 gtk_style_context_set_state (context, flags);
2324 gtk_render_frame_gap (context, cr,
2331 (gdouble) gap_x + gap_width);
2334 gtk_style_context_restore (context);
2338 gtk_default_draw_box_gap (GtkStyle *style,
2340 GtkStateType state_type,
2341 GtkShadowType shadow_type,
2343 const gchar *detail,
2348 GtkPositionType gap_side,
2352 GtkStyleContext *context;
2353 GtkStylePrivate *priv;
2354 GtkStateFlags flags = 0;
2357 context = gtk_widget_get_style_context (widget);
2360 priv = GTK_STYLE_GET_PRIVATE (style);
2361 context = priv->context;
2364 gtk_style_context_save (context);
2367 transform_detail_string (detail, context);
2371 case GTK_STATE_ACTIVE:
2372 flags |= GTK_STATE_FLAG_ACTIVE;
2374 case GTK_STATE_PRELIGHT:
2375 flags |= GTK_STATE_FLAG_PRELIGHT;
2377 case GTK_STATE_SELECTED:
2378 flags |= GTK_STATE_FLAG_SELECTED;
2380 case GTK_STATE_INSENSITIVE:
2381 flags |= GTK_STATE_FLAG_INSENSITIVE;
2387 gtk_style_context_set_state (context, flags);
2390 gtk_render_background (context, cr,
2397 if (shadow_type != GTK_SHADOW_NONE)
2398 gtk_render_frame_gap (context, cr,
2405 (gdouble) gap_x + gap_width);
2408 gtk_style_context_restore (context);
2412 gtk_default_draw_extension (GtkStyle *style,
2414 GtkStateType state_type,
2415 GtkShadowType shadow_type,
2417 const gchar *detail,
2422 GtkPositionType gap_side)
2424 GtkStyleContext *context;
2425 GtkStylePrivate *priv;
2426 GtkStateFlags flags = 0;
2429 context = gtk_widget_get_style_context (widget);
2432 priv = GTK_STYLE_GET_PRIVATE (style);
2433 context = priv->context;
2436 gtk_style_context_save (context);
2439 transform_detail_string (detail, context);
2443 case GTK_STATE_ACTIVE:
2444 flags |= GTK_STATE_FLAG_ACTIVE;
2446 case GTK_STATE_PRELIGHT:
2447 flags |= GTK_STATE_FLAG_PRELIGHT;
2449 case GTK_STATE_SELECTED:
2450 flags |= GTK_STATE_FLAG_SELECTED;
2452 case GTK_STATE_INSENSITIVE:
2453 flags |= GTK_STATE_FLAG_INSENSITIVE;
2459 gtk_style_context_set_state (context, flags);
2463 gtk_render_extension (context, cr,
2471 gtk_style_context_restore (context);
2475 gtk_default_draw_focus (GtkStyle *style,
2477 GtkStateType state_type,
2479 const gchar *detail,
2485 GtkStyleContext *context;
2486 GtkStylePrivate *priv;
2489 context = gtk_widget_get_style_context (widget);
2492 priv = GTK_STYLE_GET_PRIVATE (style);
2493 context = priv->context;
2496 gtk_style_context_save (context);
2499 transform_detail_string (detail, context);
2503 gtk_render_focus (context, cr,
2510 gtk_style_context_restore (context);
2514 gtk_default_draw_slider (GtkStyle *style,
2516 GtkStateType state_type,
2517 GtkShadowType shadow_type,
2519 const gchar *detail,
2524 GtkOrientation orientation)
2526 GtkStyleContext *context;
2527 GtkStylePrivate *priv;
2528 GtkStateFlags flags = 0;
2531 context = gtk_widget_get_style_context (widget);
2534 priv = GTK_STYLE_GET_PRIVATE (style);
2535 context = priv->context;
2538 gtk_style_context_save (context);
2541 transform_detail_string (detail, context);
2545 case GTK_STATE_PRELIGHT:
2546 flags |= GTK_STATE_FLAG_PRELIGHT;
2548 case GTK_STATE_SELECTED:
2549 flags |= GTK_STATE_FLAG_SELECTED;
2551 case GTK_STATE_INSENSITIVE:
2552 flags |= GTK_STATE_FLAG_INSENSITIVE;
2558 gtk_style_context_set_state (context, flags);
2562 gtk_render_slider (context, cr, x, y, width, height, orientation);
2565 gtk_style_context_restore (context);
2569 gtk_default_draw_handle (GtkStyle *style,
2571 GtkStateType state_type,
2572 GtkShadowType shadow_type,
2574 const gchar *detail,
2579 GtkOrientation orientation)
2581 GtkStyleContext *context;
2582 GtkStylePrivate *priv;
2583 GtkStateFlags flags = 0;
2586 context = gtk_widget_get_style_context (widget);
2589 priv = GTK_STYLE_GET_PRIVATE (style);
2590 context = priv->context;
2593 gtk_style_context_save (context);
2596 transform_detail_string (detail, context);
2600 case GTK_STATE_PRELIGHT:
2601 flags |= GTK_STATE_FLAG_PRELIGHT;
2603 case GTK_STATE_SELECTED:
2604 flags |= GTK_STATE_FLAG_SELECTED;
2606 case GTK_STATE_INSENSITIVE:
2607 flags |= GTK_STATE_FLAG_INSENSITIVE;
2613 gtk_style_context_set_state (context, flags);
2617 gtk_render_handle (context, cr,
2624 gtk_style_context_restore (context);
2628 gtk_default_draw_expander (GtkStyle *style,
2630 GtkStateType state_type,
2632 const gchar *detail,
2635 GtkExpanderStyle expander_style)
2637 GtkStyleContext *context;
2638 GtkStylePrivate *priv;
2639 GtkStateFlags flags = 0;
2643 context = gtk_widget_get_style_context (widget);
2646 priv = GTK_STYLE_GET_PRIVATE (style);
2647 context = priv->context;
2650 gtk_style_context_save (context);
2653 transform_detail_string (detail, context);
2655 gtk_style_context_add_class (context, "expander");
2659 case GTK_STATE_PRELIGHT:
2660 flags |= GTK_STATE_FLAG_PRELIGHT;
2662 case GTK_STATE_SELECTED:
2663 flags |= GTK_STATE_FLAG_SELECTED;
2665 case GTK_STATE_INSENSITIVE:
2666 flags |= GTK_STATE_FLAG_INSENSITIVE;
2673 gtk_widget_class_find_style_property (GTK_WIDGET_GET_CLASS (widget),
2675 gtk_widget_style_get (widget, "expander-size", &size, NULL);
2679 if (expander_style == GTK_EXPANDER_EXPANDED)
2680 flags |= GTK_STATE_FLAG_ACTIVE;
2682 gtk_style_context_set_state (context, flags);
2686 gtk_render_expander (context, cr,
2687 (gdouble) x - (size / 2),
2688 (gdouble) y - (size / 2),
2693 gtk_style_context_restore (context);
2697 gtk_default_draw_layout (GtkStyle *style,
2699 GtkStateType state_type,
2702 const gchar *detail,
2705 PangoLayout *layout)
2707 GtkStyleContext *context;
2708 GtkStylePrivate *priv;
2709 GtkStateFlags flags = 0;
2712 context = gtk_widget_get_style_context (widget);
2715 priv = GTK_STYLE_GET_PRIVATE (style);
2716 context = priv->context;
2719 gtk_style_context_save (context);
2722 transform_detail_string (detail, context);
2726 case GTK_STATE_PRELIGHT:
2727 flags |= GTK_STATE_FLAG_PRELIGHT;
2729 case GTK_STATE_SELECTED:
2730 flags |= GTK_STATE_FLAG_SELECTED;
2732 case GTK_STATE_INSENSITIVE:
2733 flags |= GTK_STATE_FLAG_INSENSITIVE;
2739 gtk_style_context_set_state (context, flags);
2743 gtk_render_layout (context, cr,
2749 gtk_style_context_restore (context);
2753 gtk_default_draw_resize_grip (GtkStyle *style,
2755 GtkStateType state_type,
2757 const gchar *detail,
2764 GtkStyleContext *context;
2765 GtkStylePrivate *priv;
2766 GtkStateFlags flags = 0;
2767 GtkJunctionSides sides = 0;
2770 context = gtk_widget_get_style_context (widget);
2773 priv = GTK_STYLE_GET_PRIVATE (style);
2774 context = priv->context;
2777 gtk_style_context_save (context);
2780 transform_detail_string (detail, context);
2782 gtk_style_context_add_class (context, "grip");
2786 case GTK_STATE_PRELIGHT:
2787 flags |= GTK_STATE_FLAG_PRELIGHT;
2789 case GTK_STATE_SELECTED:
2790 flags |= GTK_STATE_FLAG_SELECTED;
2792 case GTK_STATE_INSENSITIVE:
2793 flags |= GTK_STATE_FLAG_INSENSITIVE;
2799 gtk_style_context_set_state (context, flags);
2803 case GDK_WINDOW_EDGE_NORTH_WEST:
2804 sides = GTK_JUNCTION_CORNER_TOPLEFT;
2806 case GDK_WINDOW_EDGE_NORTH:
2807 sides = GTK_JUNCTION_TOP;
2809 case GDK_WINDOW_EDGE_NORTH_EAST:
2810 sides = GTK_JUNCTION_CORNER_TOPRIGHT;
2812 case GDK_WINDOW_EDGE_WEST:
2813 sides = GTK_JUNCTION_LEFT;
2815 case GDK_WINDOW_EDGE_EAST:
2816 sides = GTK_JUNCTION_RIGHT;
2818 case GDK_WINDOW_EDGE_SOUTH_WEST:
2819 sides = GTK_JUNCTION_CORNER_BOTTOMLEFT;
2821 case GDK_WINDOW_EDGE_SOUTH:
2822 sides = GTK_JUNCTION_BOTTOM;
2824 case GDK_WINDOW_EDGE_SOUTH_EAST:
2825 sides = GTK_JUNCTION_CORNER_BOTTOMRIGHT;
2829 gtk_style_context_set_junction_sides (context, sides);
2833 gtk_render_handle (context, cr,
2840 gtk_style_context_restore (context);
2844 gtk_default_draw_spinner (GtkStyle *style,
2846 GtkStateType state_type,
2848 const gchar *detail,
2864 real_step = step % num_steps;
2866 /* set a clip region for the expose event */
2867 cairo_rectangle (cr, x, y, width, height);
2870 cairo_translate (cr, x, y);
2872 /* draw clip region */
2873 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
2875 color = &style->fg[state_type];
2878 radius = MIN (width / 2, height / 2);
2879 half = num_steps / 2;
2881 for (i = 0; i < num_steps; i++)
2883 gint inset = 0.7 * radius;
2885 /* transparency is a function of time and intial value */
2886 gdouble t = (gdouble) ((i + num_steps - real_step)
2887 % num_steps) / num_steps;
2891 cairo_set_source_rgba (cr,
2892 color->red / 65535.,
2893 color->green / 65535.,
2894 color->blue / 65535.,
2897 cairo_set_line_width (cr, 2.0);
2899 dx + (radius - inset) * cos (i * G_PI / half),
2900 dy + (radius - inset) * sin (i * G_PI / half));
2902 dx + radius * cos (i * G_PI / half),
2903 dy + radius * sin (i * G_PI / half));
2911 _gtk_style_shade (const GdkColor *a,
2919 red = (gdouble) a->red / 65535.0;
2920 green = (gdouble) a->green / 65535.0;
2921 blue = (gdouble) a->blue / 65535.0;
2923 rgb_to_hls (&red, &green, &blue);
2928 else if (green < 0.0)
2934 else if (blue < 0.0)
2937 hls_to_rgb (&red, &green, &blue);
2939 b->red = red * 65535.0;
2940 b->green = green * 65535.0;
2941 b->blue = blue * 65535.0;
2945 rgb_to_hls (gdouble *r,
2986 l = (max + min) / 2;
2993 s = (max - min) / (max + min);
2995 s = (max - min) / (2 - max - min);
2999 h = (green - blue) / delta;
3000 else if (green == max)
3001 h = 2 + (blue - red) / delta;
3002 else if (blue == max)
3003 h = 4 + (red - green) / delta;
3016 hls_to_rgb (gdouble *h,
3029 if (lightness <= 0.5)
3030 m2 = lightness * (1 + saturation);
3032 m2 = lightness + saturation - lightness * saturation;
3033 m1 = 2 * lightness - m2;
3035 if (saturation == 0)
3050 r = m1 + (m2 - m1) * hue / 60;
3054 r = m1 + (m2 - m1) * (240 - hue) / 60;
3065 g = m1 + (m2 - m1) * hue / 60;
3069 g = m1 + (m2 - m1) * (240 - hue) / 60;
3080 b = m1 + (m2 - m1) * hue / 60;
3084 b = m1 + (m2 - m1) * (240 - hue) / 60;
3097 * @style: a #GtkStyle
3099 * @state_type: a state
3100 * @widget: (allow-none): the widget
3101 * @detail: (allow-none): a style detail
3102 * @x1: the starting x coordinate
3103 * @x2: the ending x coordinate
3104 * @y: the y coordinate
3106 * Draws a horizontal line from (@x1, @y) to (@x2, @y) in @cr
3107 * using the given style and state.
3109 * Deprecated:3.0: Use gtk_render_line() instead
3112 gtk_paint_hline (GtkStyle *style,
3114 GtkStateType state_type,
3116 const gchar *detail,
3121 g_return_if_fail (GTK_IS_STYLE (style));
3122 g_return_if_fail (cr != NULL);
3123 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
3127 GTK_STYLE_GET_CLASS (style)->draw_hline (style, cr, state_type,
3136 * @style: a #GtkStyle
3138 * @state_type: a state
3139 * @widget: (allow-none): the widget
3140 * @detail: (allow-none): a style detail
3141 * @y1_: the starting y coordinate
3142 * @y2_: the ending y coordinate
3143 * @x: the x coordinate
3145 * Draws a vertical line from (@x, @y1_) to (@x, @y2_) in @cr
3146 * using the given style and state.
3148 * Deprecated:3.0: Use gtk_render_line() instead
3151 gtk_paint_vline (GtkStyle *style,
3153 GtkStateType state_type,
3155 const gchar *detail,
3160 g_return_if_fail (GTK_IS_STYLE (style));
3161 g_return_if_fail (cr != NULL);
3162 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
3166 GTK_STYLE_GET_CLASS (style)->draw_vline (style, cr, state_type,
3175 * @style: a #GtkStyle
3177 * @state_type: a state
3178 * @shadow_type: type of shadow to draw
3179 * @widget: (allow-none): the widget
3180 * @detail: (allow-none): a style detail
3181 * @x: x origin of the rectangle
3182 * @y: y origin of the rectangle
3183 * @width: width of the rectangle
3184 * @height: width of the rectangle
3186 * Draws a shadow around the given rectangle in @cr
3187 * using the given style and state and shadow type.
3189 * Deprecated:3.0: Use gtk_render_frame() instead
3192 gtk_paint_shadow (GtkStyle *style,
3194 GtkStateType state_type,
3195 GtkShadowType shadow_type,
3197 const gchar *detail,
3203 g_return_if_fail (GTK_IS_STYLE (style));
3204 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
3205 g_return_if_fail (cr != NULL);
3206 g_return_if_fail (width >= 0);
3207 g_return_if_fail (height >= 0);
3211 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, cr, state_type, shadow_type,
3213 x, y, width, height);
3220 * @style: a #GtkStyle
3222 * @state_type: a state
3223 * @shadow_type: the type of shadow to draw
3224 * @widget: (allow-none): the widget
3225 * @detail: (allow-none): a style detail
3226 * @arrow_type: the type of arrow to draw
3227 * @fill: %TRUE if the arrow tip should be filled
3228 * @x: x origin of the rectangle to draw the arrow in
3229 * @y: y origin of the rectangle to draw the arrow in
3230 * @width: width of the rectangle to draw the arrow in
3231 * @height: height of the rectangle to draw the arrow in
3233 * Draws an arrow in the given rectangle on @cr using the given
3234 * parameters. @arrow_type determines the direction of the arrow.
3236 * Deprecated:3.0: Use gtk_render_arrow() instead
3239 gtk_paint_arrow (GtkStyle *style,
3241 GtkStateType state_type,
3242 GtkShadowType shadow_type,
3244 const gchar *detail,
3245 GtkArrowType arrow_type,
3252 g_return_if_fail (GTK_IS_STYLE (style));
3253 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
3254 g_return_if_fail (cr != NULL);
3255 g_return_if_fail (width >= 0);
3256 g_return_if_fail (height >= 0);
3260 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, cr, state_type, shadow_type,
3262 arrow_type, fill, x, y, width, height);
3268 * gtk_paint_diamond:
3269 * @style: a #GtkStyle
3271 * @state_type: a state
3272 * @shadow_type: the type of shadow to draw
3273 * @widget: (allow-none): the widget
3274 * @detail: (allow-none): a style detail
3275 * @x: x origin of the rectangle to draw the diamond in
3276 * @y: y origin of the rectangle to draw the diamond in
3277 * @width: width of the rectangle to draw the diamond in
3278 * @height: height of the rectangle to draw the diamond in
3280 * Draws a diamond in the given rectangle on @window using the given
3283 * Deprecated:3.0: Use cairo instead
3286 gtk_paint_diamond (GtkStyle *style,
3288 GtkStateType state_type,
3289 GtkShadowType shadow_type,
3291 const gchar *detail,
3297 g_return_if_fail (GTK_IS_STYLE (style));
3298 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
3299 g_return_if_fail (cr != NULL);
3300 g_return_if_fail (width >= 0);
3301 g_return_if_fail (height >= 0);
3305 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, cr, state_type, shadow_type,
3307 x, y, width, height);
3314 * @style: a #GtkStyle
3316 * @state_type: a state
3317 * @shadow_type: the type of shadow to draw
3318 * @widget: (allow-none): the widget
3319 * @detail: (allow-none): a style detail
3320 * @x: x origin of the box
3321 * @y: y origin of the box
3322 * @width: the width of the box
3323 * @height: the height of the box
3325 * Draws a box on @cr with the given parameters.
3327 * Deprecated:3.0: Use gtk_render_frame() and gtk_render_background() instead
3330 gtk_paint_box (GtkStyle *style,
3332 GtkStateType state_type,
3333 GtkShadowType shadow_type,
3335 const gchar *detail,
3341 g_return_if_fail (GTK_IS_STYLE (style));
3342 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
3343 g_return_if_fail (cr != NULL);
3347 GTK_STYLE_GET_CLASS (style)->draw_box (style, cr, state_type, shadow_type,
3349 x, y, width, height);
3355 * gtk_paint_flat_box:
3356 * @style: a #GtkStyle
3358 * @state_type: a state
3359 * @shadow_type: the type of shadow to draw
3360 * @widget: (allow-none): the widget
3361 * @detail: (allow-none): a style detail
3362 * @x: x origin of the box
3363 * @y: y origin of the box
3364 * @width: the width of the box
3365 * @height: the height of the box
3367 * Draws a flat box on @cr with the given parameters.
3369 * Deprecated:3.0: Use gtk_render_frame() and gtk_render_background() instead
3372 gtk_paint_flat_box (GtkStyle *style,
3374 GtkStateType state_type,
3375 GtkShadowType shadow_type,
3377 const gchar *detail,
3383 g_return_if_fail (GTK_IS_STYLE (style));
3384 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
3385 g_return_if_fail (cr != NULL);
3386 g_return_if_fail (width >= 0);
3387 g_return_if_fail (height >= 0);
3391 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, cr, state_type, shadow_type,
3393 x, y, width, height);
3400 * @style: a #GtkStyle
3402 * @state_type: a state
3403 * @shadow_type: the type of shadow to draw
3404 * @widget: (allow-none): the widget
3405 * @detail: (allow-none): a style detail
3406 * @x: x origin of the rectangle to draw the check in
3407 * @y: y origin of the rectangle to draw the check in
3408 * @width: the width of the rectangle to draw the check in
3409 * @height: the height of the rectangle to draw the check in
3411 * Draws a check button indicator in the given rectangle on @cr with
3412 * the given parameters.
3414 * Deprecated:3.0: Use gtk_render_check() instead
3417 gtk_paint_check (GtkStyle *style,
3419 GtkStateType state_type,
3420 GtkShadowType shadow_type,
3422 const gchar *detail,
3428 g_return_if_fail (GTK_IS_STYLE (style));
3429 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
3430 g_return_if_fail (cr != NULL);
3434 GTK_STYLE_GET_CLASS (style)->draw_check (style, cr, state_type, shadow_type,
3436 x, y, width, height);
3443 * @style: a #GtkStyle
3445 * @state_type: a state
3446 * @shadow_type: the type of shadow to draw
3447 * @widget: (allow-none): the widget
3448 * @detail: (allow-none): a style detail
3449 * @x: x origin of the rectangle to draw the option in
3450 * @y: y origin of the rectangle to draw the option in
3451 * @width: the width of the rectangle to draw the option in
3452 * @height: the height of the rectangle to draw the option in
3454 * Draws a radio button indicator in the given rectangle on @cr with
3455 * the given parameters.
3457 * Deprecated:3.0: Use gtk_render_option() instead
3460 gtk_paint_option (GtkStyle *style,
3462 GtkStateType state_type,
3463 GtkShadowType shadow_type,
3465 const gchar *detail,
3471 g_return_if_fail (GTK_IS_STYLE (style));
3472 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
3473 g_return_if_fail (cr != NULL);
3477 GTK_STYLE_GET_CLASS (style)->draw_option (style, cr, state_type, shadow_type,
3479 x, y, width, height);
3486 * @style: a #GtkStyle
3488 * @state_type: a state
3489 * @shadow_type: the type of shadow to draw
3490 * @widget: (allow-none): the widget
3491 * @detail: (allow-none): a style detail
3492 * @x: x origin of the rectangle to draw the tab in
3493 * @y: y origin of the rectangle to draw the tab in
3494 * @width: the width of the rectangle to draw the tab in
3495 * @height: the height of the rectangle to draw the tab in
3497 * Draws an option menu tab (i.e. the up and down pointing arrows)
3498 * in the given rectangle on @cr using the given parameters.
3500 * Deprecated:3.0: Use cairo instead
3503 gtk_paint_tab (GtkStyle *style,
3505 GtkStateType state_type,
3506 GtkShadowType shadow_type,
3508 const gchar *detail,
3514 g_return_if_fail (GTK_IS_STYLE (style));
3515 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
3516 g_return_if_fail (cr != NULL);
3520 GTK_STYLE_GET_CLASS (style)->draw_tab (style, cr, state_type, shadow_type,
3522 x, y, width, height);
3528 * gtk_paint_shadow_gap:
3529 * @style: a #GtkStyle
3531 * @state_type: a state
3532 * @shadow_type: type of shadow to draw
3533 * @widget: (allow-none): the widget
3534 * @detail: (allow-none): a style detail
3535 * @x: x origin of the rectangle
3536 * @y: y origin of the rectangle
3537 * @width: width of the rectangle
3538 * @height: width of the rectangle
3539 * @gap_side: side in which to leave the gap
3540 * @gap_x: starting position of the gap
3541 * @gap_width: width of the gap
3543 * Draws a shadow around the given rectangle in @cr
3544 * using the given style and state and shadow type, leaving a
3547 * Deprecated:3.0: Use gtk_render_frame_gap() instead
3550 gtk_paint_shadow_gap (GtkStyle *style,
3552 GtkStateType state_type,
3553 GtkShadowType shadow_type,
3555 const gchar *detail,
3560 GtkPositionType gap_side,
3564 g_return_if_fail (GTK_IS_STYLE (style));
3565 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
3566 g_return_if_fail (cr != NULL);
3567 g_return_if_fail (width >= 0);
3568 g_return_if_fail (height >= 0);
3572 GTK_STYLE_GET_CLASS (style)->draw_shadow_gap (style, cr, state_type, shadow_type,
3574 x, y, width, height, gap_side, gap_x, gap_width);
3580 * gtk_paint_box_gap:
3581 * @style: a #GtkStyle
3583 * @state_type: a state
3584 * @shadow_type: type of shadow to draw
3585 * @widget: (allow-none): the widget
3586 * @detail: (allow-none): a style detail
3587 * @x: x origin of the rectangle
3588 * @y: y origin of the rectangle
3589 * @width: width of the rectangle
3590 * @height: width of the rectangle
3591 * @gap_side: side in which to leave the gap
3592 * @gap_x: starting position of the gap
3593 * @gap_width: width of the gap
3595 * Draws a box in @cr using the given style and state and shadow type,
3596 * leaving a gap in one side.
3598 * Deprecated:3.0: Use gtk_render_frame_gap() instead
3601 gtk_paint_box_gap (GtkStyle *style,
3603 GtkStateType state_type,
3604 GtkShadowType shadow_type,
3606 const gchar *detail,
3611 GtkPositionType gap_side,
3615 g_return_if_fail (GTK_IS_STYLE (style));
3616 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
3617 g_return_if_fail (cr != NULL);
3618 g_return_if_fail (width >= 0);
3619 g_return_if_fail (height >= 0);
3623 GTK_STYLE_GET_CLASS (style)->draw_box_gap (style, cr, state_type, shadow_type,
3625 x, y, width, height, gap_side, gap_x, gap_width);
3631 * gtk_paint_extension:
3632 * @style: a #GtkStyle
3634 * @state_type: a state
3635 * @shadow_type: type of shadow to draw
3636 * @widget: (allow-none): the widget
3637 * @detail: (allow-none): a style detail
3638 * @x: x origin of the extension
3639 * @y: y origin of the extension
3640 * @width: width of the extension
3641 * @height: width of the extension
3642 * @gap_side: the side on to which the extension is attached
3644 * Draws an extension, i.e. a notebook tab.
3646 * Deprecated:3.0: Use gtk_render_extension() instead
3649 gtk_paint_extension (GtkStyle *style,
3651 GtkStateType state_type,
3652 GtkShadowType shadow_type,
3654 const gchar *detail,
3659 GtkPositionType gap_side)
3661 g_return_if_fail (GTK_IS_STYLE (style));
3662 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
3663 g_return_if_fail (cr != NULL);
3664 g_return_if_fail (width >= 0);
3665 g_return_if_fail (height >= 0);
3669 GTK_STYLE_GET_CLASS (style)->draw_extension (style, cr, state_type, shadow_type,
3671 x, y, width, height, gap_side);
3678 * @style: a #GtkStyle
3680 * @state_type: a state
3681 * @widget: (allow-none): the widget
3682 * @detail: (allow-none): a style detail
3683 * @x: the x origin of the rectangle around which to draw a focus indicator
3684 * @y: the y origin of the rectangle around which to draw a focus indicator
3685 * @width: the width of the rectangle around which to draw a focus indicator
3686 * @height: the height of the rectangle around which to draw a focus indicator
3688 * Draws a focus indicator around the given rectangle on @cr using the
3691 * Deprecated:3.0: Use gtk_render_focus() instead
3694 gtk_paint_focus (GtkStyle *style,
3696 GtkStateType state_type,
3698 const gchar *detail,
3704 g_return_if_fail (GTK_IS_STYLE (style));
3705 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
3706 g_return_if_fail (cr != NULL);
3707 g_return_if_fail (width >= 0);
3708 g_return_if_fail (height >= 0);
3712 GTK_STYLE_GET_CLASS (style)->draw_focus (style, cr, state_type,
3714 x, y, width, height);
3721 * @style: a #GtkStyle
3723 * @state_type: a state
3724 * @shadow_type: a shadow
3725 * @widget: (allow-none): the widget
3726 * @detail: (allow-none): a style detail
3727 * @x: the x origin of the rectangle in which to draw a slider
3728 * @y: the y origin of the rectangle in which to draw a slider
3729 * @width: the width of the rectangle in which to draw a slider
3730 * @height: the height of the rectangle in which to draw a slider
3731 * @orientation: the orientation to be used
3733 * Draws a slider in the given rectangle on @cr using the
3734 * given style and orientation.
3736 * Deprecated:3.0: Use gtk_render_slider() instead
3739 gtk_paint_slider (GtkStyle *style,
3741 GtkStateType state_type,
3742 GtkShadowType shadow_type,
3744 const gchar *detail,
3749 GtkOrientation orientation)
3751 g_return_if_fail (GTK_IS_STYLE (style));
3752 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
3753 g_return_if_fail (cr != NULL);
3754 g_return_if_fail (width >= 0);
3755 g_return_if_fail (height >= 0);
3759 GTK_STYLE_GET_CLASS (style)->draw_slider (style, cr, state_type, shadow_type,
3761 x, y, width, height, orientation);
3768 * @style: a #GtkStyle
3770 * @state_type: a state
3771 * @shadow_type: type of shadow to draw
3772 * @widget: (allow-none): the widget
3773 * @detail: (allow-none): a style detail
3774 * @x: x origin of the handle
3775 * @y: y origin of the handle
3776 * @width: with of the handle
3777 * @height: height of the handle
3778 * @orientation: the orientation of the handle
3780 * Draws a handle as used in #GtkHandleBox and #GtkPaned.
3782 * Deprecated:3.0: Use gtk_render_handle() instead
3785 gtk_paint_handle (GtkStyle *style,
3787 GtkStateType state_type,
3788 GtkShadowType shadow_type,
3790 const gchar *detail,
3795 GtkOrientation orientation)
3797 g_return_if_fail (GTK_IS_STYLE (style));
3798 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
3799 g_return_if_fail (cr != NULL);
3800 g_return_if_fail (width >= 0);
3801 g_return_if_fail (height >= 0);
3805 GTK_STYLE_GET_CLASS (style)->draw_handle (style, cr, state_type, shadow_type,
3807 x, y, width, height, orientation);
3813 * gtk_paint_expander:
3814 * @style: a #GtkStyle
3816 * @state_type: a state
3817 * @widget: (allow-none): the widget
3818 * @detail: (allow-none): a style detail
3819 * @x: the x position to draw the expander at
3820 * @y: the y position to draw the expander at
3821 * @expander_style: the style to draw the expander in; determines
3822 * whether the expander is collapsed, expanded, or in an
3823 * intermediate state.
3825 * Draws an expander as used in #GtkTreeView. @x and @y specify the
3826 * center the expander. The size of the expander is determined by the
3827 * "expander-size" style property of @widget. (If widget is not
3828 * specified or doesn't have an "expander-size" property, an
3829 * unspecified default size will be used, since the caller doesn't
3830 * have sufficient information to position the expander, this is
3831 * likely not useful.) The expander is expander_size pixels tall
3832 * in the collapsed position and expander_size pixels wide in the
3833 * expanded position.
3835 * Deprecated:3.0: Use gtk_render_expander() instead
3838 gtk_paint_expander (GtkStyle *style,
3840 GtkStateType state_type,
3842 const gchar *detail,
3845 GtkExpanderStyle expander_style)
3847 g_return_if_fail (GTK_IS_STYLE (style));
3848 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
3849 g_return_if_fail (cr != NULL);
3853 GTK_STYLE_GET_CLASS (style)->draw_expander (style, cr, state_type,
3855 x, y, expander_style);
3862 * @style: a #GtkStyle
3864 * @state_type: a state
3865 * @use_text: whether to use the text or foreground
3866 * graphics context of @style
3867 * @widget: (allow-none): the widget
3868 * @detail: (allow-none): a style detail
3871 * @layout: the layout to draw
3873 * Draws a layout on @cr using the given parameters.
3875 * Deprecated:3.0: Use gtk_render_layout() instead
3878 gtk_paint_layout (GtkStyle *style,
3880 GtkStateType state_type,
3883 const gchar *detail,
3886 PangoLayout *layout)
3888 g_return_if_fail (GTK_IS_STYLE (style));
3889 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
3890 g_return_if_fail (cr != NULL);
3894 GTK_STYLE_GET_CLASS (style)->draw_layout (style, cr, state_type, use_text,
3902 * gtk_paint_resize_grip:
3903 * @style: a #GtkStyle
3905 * @state_type: a state
3906 * @widget: (allow-none): the widget
3907 * @detail: (allow-none): a style detail
3908 * @edge: the edge in which to draw the resize grip
3909 * @x: the x origin of the rectangle in which to draw the resize grip
3910 * @y: the y origin of the rectangle in which to draw the resize grip
3911 * @width: the width of the rectangle in which to draw the resize grip
3912 * @height: the height of the rectangle in which to draw the resize grip
3914 * Draws a resize grip in the given rectangle on @cr using the given
3917 * Deprecated:3.0: Use gtk_render_handle() instead
3920 gtk_paint_resize_grip (GtkStyle *style,
3922 GtkStateType state_type,
3924 const gchar *detail,
3931 g_return_if_fail (GTK_IS_STYLE (style));
3932 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
3933 g_return_if_fail (cr != NULL);
3937 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, cr, state_type,
3939 edge, x, y, width, height);
3944 * gtk_paint_spinner:
3945 * @style: a #GtkStyle
3947 * @state_type: a state
3948 * @widget: (allow-none): the widget (may be %NULL)
3949 * @detail: (allow-none): a style detail (may be %NULL)
3950 * @step: the nth step, a value between 0 and #GtkSpinner:num-steps
3951 * @x: the x origin of the rectangle in which to draw the spinner
3952 * @y: the y origin of the rectangle in which to draw the spinner
3953 * @width: the width of the rectangle in which to draw the spinner
3954 * @height: the height of the rectangle in which to draw the spinner
3956 * Draws a spinner on @window using the given parameters.
3958 * Deprecated:3.0: Use gtk_render_activity() instead
3961 gtk_paint_spinner (GtkStyle *style,
3963 GtkStateType state_type,
3965 const gchar *detail,
3972 g_return_if_fail (GTK_IS_STYLE (style));
3973 g_return_if_fail (cr != NULL);
3974 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_spinner != NULL);
3978 GTK_STYLE_GET_CLASS (style)->draw_spinner (style, cr, state_type,
3980 step, x, y, width, height);
3985 static GtkStyle *gtk_default_style = NULL;
3988 * gtk_widget_get_default_style:
3990 * Returns the default style used by all widgets initially.
3992 * Returns: (transfer none): the default style. This #GtkStyle
3993 * object is owned by GTK+ and should not be modified or freed.
3995 * Deprecated:3.0: Use #GtkStyleContext instead, and
3996 * gtk_css_provider_get_default() to obtain a #GtkStyleProvider
3997 * with the default widget style information.
4000 gtk_widget_get_default_style (void)
4002 if (!gtk_default_style)
4004 gtk_default_style = gtk_style_new ();
4005 g_object_ref (gtk_default_style);
4008 return gtk_default_style;
4012 * gtk_widget_style_attach:
4013 * @widget: a #GtkWidget
4015 * This function attaches the widget's #GtkStyle to the widget's
4016 * #GdkWindow. It is a replacement for
4019 * widget->style = gtk_style_attach (widget->style, widget->window);
4022 * and should only ever be called in a derived widget's "realize"
4023 * implementation which does not chain up to its parent class'
4024 * "realize" implementation, because one of the parent classes
4025 * (finally #GtkWidget) would attach the style itself.
4029 * Deprecated: 3.0. This step is unnecessary with #GtkStyleContext.
4032 gtk_widget_style_attach (GtkWidget *widget)
4034 g_return_if_fail (GTK_IS_WIDGET (widget));
4035 g_return_if_fail (gtk_widget_get_realized (widget));
4039 * gtk_widget_has_rc_style:
4040 * @widget: a #GtkWidget
4042 * Determines if the widget style has been looked up through the rc mechanism.
4044 * Returns: %TRUE if the widget has been looked up through the rc
4045 * mechanism, %FALSE otherwise.
4049 * Deprecated:3.0: Use #GtkStyleContext instead
4052 gtk_widget_has_rc_style (GtkWidget *widget)
4054 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4060 * gtk_widget_set_style:
4061 * @widget: a #GtkWidget
4062 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect
4063 * of a previous call to gtk_widget_set_style() and go back to
4066 * Used to set the #GtkStyle for a widget (@widget->style). Since
4067 * GTK 3, this function does nothing, the passed in style is ignored.
4069 * Deprecated:3.0: Use #GtkStyleContext instead
4072 gtk_widget_set_style (GtkWidget *widget,
4075 g_return_if_fail (GTK_IS_WIDGET (widget));
4079 * gtk_widget_ensure_style:
4080 * @widget: a #GtkWidget
4082 * Ensures that @widget has a style (@widget->style).
4084 * Not a very useful function; most of the time, if you
4085 * want the style, the widget is realized, and realized
4086 * widgets are guaranteed to have a style already.
4088 * Deprecated:3.0: Use #GtkStyleContext instead
4091 gtk_widget_ensure_style (GtkWidget *widget)
4094 g_return_if_fail (GTK_IS_WIDGET (widget));
4096 style = _gtk_widget_get_style (widget);
4097 if (style == gtk_widget_get_default_style ())
4099 g_object_unref (style);
4100 _gtk_widget_set_style (widget, NULL);
4102 g_signal_emit_by_name (widget, "style-set", 0, NULL);
4107 * gtk_widget_get_style:
4108 * @widget: a #GtkWidget
4110 * Simply an accessor function that returns @widget->style.
4112 * Return value: (transfer none): the widget's #GtkStyle
4114 * Deprecated:3.0: Use #GtkStyleContext instead
4117 gtk_widget_get_style (GtkWidget *widget)
4120 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4122 style = _gtk_widget_get_style (widget);
4126 style = g_object_new (GTK_TYPE_STYLE,
4127 "context", gtk_widget_get_style_context (widget),
4129 _gtk_widget_set_style (widget, style);
4136 * gtk_widget_modify_style:
4137 * @widget: a #GtkWidget
4138 * @style: the #GtkRcStyle holding the style modifications
4140 * Modifies style values on the widget.
4142 * Modifications made using this technique take precedence over
4143 * style values set via an RC file, however, they will be overridden
4144 * if a style is explicitely set on the widget using gtk_widget_set_style().
4145 * The #GtkRcStyle structure is designed so each field can either be
4146 * set or unset, so it is possible, using this function, to modify some
4147 * style values and leave the others unchanged.
4149 * Note that modifications made with this function are not cumulative
4150 * with previous calls to gtk_widget_modify_style() or with such
4151 * functions as gtk_widget_modify_fg(). If you wish to retain
4152 * previous values, you must first call gtk_widget_get_modifier_style(),
4153 * make your modifications to the returned style, then call
4154 * gtk_widget_modify_style() with that style. On the other hand,
4155 * if you first call gtk_widget_modify_style(), subsequent calls
4156 * to such functions gtk_widget_modify_fg() will have a cumulative
4157 * effect with the initial modifications.
4159 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
4162 gtk_widget_modify_style (GtkWidget *widget,
4165 g_return_if_fail (GTK_IS_WIDGET (widget));
4166 g_return_if_fail (GTK_IS_RC_STYLE (style));
4168 g_object_set_data_full (G_OBJECT (widget),
4170 gtk_rc_style_copy (style),
4171 (GDestroyNotify) g_object_unref);
4175 * gtk_widget_get_modifier_style:
4176 * @widget: a #GtkWidget
4178 * Returns the current modifier style for the widget. (As set by
4179 * gtk_widget_modify_style().) If no style has previously set, a new
4180 * #GtkRcStyle will be created with all values unset, and set as the
4181 * modifier style for the widget. If you make changes to this rc
4182 * style, you must call gtk_widget_modify_style(), passing in the
4183 * returned rc style, to make sure that your changes take effect.
4185 * Caution: passing the style back to gtk_widget_modify_style() will
4186 * normally end up destroying it, because gtk_widget_modify_style() copies
4187 * the passed-in style and sets the copy as the new modifier style,
4188 * thus dropping any reference to the old modifier style. Add a reference
4189 * to the modifier style if you want to keep it alive.
4191 * Return value: (transfer none): the modifier style for the widget.
4192 * This rc style is owned by the widget. If you want to keep a
4193 * pointer to value this around, you must add a refcount using
4196 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
4199 gtk_widget_get_modifier_style (GtkWidget *widget)
4201 GtkRcStyle *rc_style;
4203 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4205 rc_style = g_object_get_data (G_OBJECT (widget), "gtk-rc-style");
4209 rc_style = gtk_rc_style_new ();
4210 g_object_set_data_full (G_OBJECT (widget),
4213 (GDestroyNotify) g_object_unref);
4220 gtk_widget_modify_color_component (GtkWidget *widget,
4221 GtkRcFlags component,
4223 const GdkColor *color)
4225 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
4232 rc_style->fg[state] = *color;
4235 rc_style->bg[state] = *color;
4238 rc_style->text[state] = *color;
4241 rc_style->base[state] = *color;
4244 g_assert_not_reached();
4247 rc_style->color_flags[state] |= component;
4250 rc_style->color_flags[state] &= ~component;
4252 gtk_widget_modify_style (widget, rc_style);
4256 * gtk_widget_modify_fg:
4257 * @widget: a #GtkWidget
4258 * @state: the state for which to set the foreground color
4259 * @color: (allow-none): the color to assign (does not need to be allocated),
4260 * or %NULL to undo the effect of previous calls to
4261 * of gtk_widget_modify_fg().
4263 * Sets the foreground color for a widget in a particular state.
4265 * All other style values are left untouched.
4266 * See also gtk_widget_modify_style().
4268 * Deprecated:3.0: Use gtk_widget_override_color() instead
4271 gtk_widget_modify_fg (GtkWidget *widget,
4273 const GdkColor *color)
4275 GtkStateFlags flags;
4278 g_return_if_fail (GTK_IS_WIDGET (widget));
4279 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4283 case GTK_STATE_ACTIVE:
4284 flags = GTK_STATE_FLAG_ACTIVE;
4286 case GTK_STATE_PRELIGHT:
4287 flags = GTK_STATE_FLAG_PRELIGHT;
4289 case GTK_STATE_SELECTED:
4290 flags = GTK_STATE_FLAG_SELECTED;
4292 case GTK_STATE_INSENSITIVE:
4293 flags = GTK_STATE_FLAG_INSENSITIVE;
4295 case GTK_STATE_NORMAL:
4302 rgba.red = color->red / 65535.;
4303 rgba.green = color->green / 65535.;
4304 rgba.blue = color->blue / 65535.;
4307 gtk_widget_override_color (widget, flags, &rgba);
4310 gtk_widget_override_color (widget, flags, NULL);
4314 * gtk_widget_modify_bg:
4315 * @widget: a #GtkWidget
4316 * @state: the state for which to set the background color
4317 * @color: (allow-none): the color to assign (does not need
4318 * to be allocated), or %NULL to undo the effect of previous
4319 * calls to of gtk_widget_modify_bg().
4321 * Sets the background color for a widget in a particular state.
4323 * All other style values are left untouched.
4324 * See also gtk_widget_modify_style().
4327 * Note that "no window" widgets (which have the %GTK_NO_WINDOW
4328 * flag set) draw on their parent container's window and thus may
4329 * not draw any background themselves. This is the case for e.g.
4332 * To modify the background of such widgets, you have to set the
4333 * background color on their parent; if you want to set the background
4334 * of a rectangular area around a label, try placing the label in
4335 * a #GtkEventBox widget and setting the background color on that.
4338 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
4341 gtk_widget_modify_bg (GtkWidget *widget,
4343 const GdkColor *color)
4345 GtkStateFlags flags;
4348 g_return_if_fail (GTK_IS_WIDGET (widget));
4349 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4353 case GTK_STATE_ACTIVE:
4354 flags = GTK_STATE_FLAG_ACTIVE;
4356 case GTK_STATE_PRELIGHT:
4357 flags = GTK_STATE_FLAG_PRELIGHT;
4359 case GTK_STATE_SELECTED:
4360 flags = GTK_STATE_FLAG_SELECTED;
4362 case GTK_STATE_INSENSITIVE:
4363 flags = GTK_STATE_FLAG_INSENSITIVE;
4365 case GTK_STATE_NORMAL:
4372 rgba.red = color->red / 65535.;
4373 rgba.green = color->green / 65535.;
4374 rgba.blue = color->blue / 65535.;
4377 gtk_widget_override_background_color (widget, flags, &rgba);
4380 gtk_widget_override_background_color (widget, flags, NULL);
4384 * gtk_widget_modify_text:
4385 * @widget: a #GtkWidget
4386 * @state: the state for which to set the text color
4387 * @color: (allow-none): the color to assign (does not need to
4388 * be allocated), or %NULL to undo the effect of previous
4389 * calls to of gtk_widget_modify_text().
4391 * Sets the text color for a widget in a particular state.
4393 * All other style values are left untouched.
4394 * The text color is the foreground color used along with the
4395 * base color (see gtk_widget_modify_base()) for widgets such
4396 * as #GtkEntry and #GtkTextView.
4397 * See also gtk_widget_modify_style().
4399 * Deprecated:3.0: Use gtk_widget_override_color() instead
4402 gtk_widget_modify_text (GtkWidget *widget,
4404 const GdkColor *color)
4406 g_return_if_fail (GTK_IS_WIDGET (widget));
4407 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4409 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
4413 * gtk_widget_modify_base:
4414 * @widget: a #GtkWidget
4415 * @state: the state for which to set the base color
4416 * @color: (allow-none): the color to assign (does not need to
4417 * be allocated), or %NULL to undo the effect of previous
4418 * calls to of gtk_widget_modify_base().
4420 * Sets the base color for a widget in a particular state.
4421 * All other style values are left untouched. The base color
4422 * is the background color used along with the text color
4423 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
4424 * and #GtkTextView. See also gtk_widget_modify_style().
4427 * Note that "no window" widgets (which have the %GTK_NO_WINDOW
4428 * flag set) draw on their parent container's window and thus may
4429 * not draw any background themselves. This is the case for e.g.
4432 * To modify the background of such widgets, you have to set the
4433 * base color on their parent; if you want to set the background
4434 * of a rectangular area around a label, try placing the label in
4435 * a #GtkEventBox widget and setting the base color on that.
4438 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
4441 gtk_widget_modify_base (GtkWidget *widget,
4443 const GdkColor *color)
4445 g_return_if_fail (GTK_IS_WIDGET (widget));
4446 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4448 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
4452 * gtk_widget_modify_cursor:
4453 * @widget: a #GtkWidget
4454 * @primary: the color to use for primary cursor (does not need to be
4455 * allocated), or %NULL to undo the effect of previous calls to
4456 * of gtk_widget_modify_cursor().
4457 * @secondary: the color to use for secondary cursor (does not need to be
4458 * allocated), or %NULL to undo the effect of previous calls to
4459 * of gtk_widget_modify_cursor().
4461 * Sets the cursor color to use in a widget, overriding the
4462 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
4465 * All other style values are left untouched.
4466 * See also gtk_widget_modify_style().
4470 * Deprecated: 3.0. Use gtk_widget_override_cursor() instead.
4473 gtk_widget_modify_cursor (GtkWidget *widget,
4474 const GdkColor *primary,
4475 const GdkColor *secondary)
4477 GdkRGBA primary_rgba, secondary_rgba;
4479 g_return_if_fail (GTK_IS_WIDGET (widget));
4481 primary_rgba.red = primary->red / 65535.;
4482 primary_rgba.green = primary->green / 65535.;
4483 primary_rgba.blue = primary->blue / 65535.;
4484 primary_rgba.alpha = 1;
4486 secondary_rgba.red = secondary->red / 65535.;
4487 secondary_rgba.green = secondary->green / 65535.;
4488 secondary_rgba.blue = secondary->blue / 65535.;
4489 secondary_rgba.alpha = 1;
4491 gtk_widget_override_cursor (widget, &primary_rgba, &secondary_rgba);
4495 * gtk_widget_modify_font:
4496 * @widget: a #GtkWidget
4497 * @font_desc: (allow-none): the font description to use, or %NULL
4498 * to undo the effect of previous calls to gtk_widget_modify_font()
4500 * Sets the font to use for a widget.
4502 * All other style values are left untouched.
4503 * See also gtk_widget_modify_style().
4505 * Deprecated:3.0: Use gtk_widget_override_font() instead
4508 gtk_widget_modify_font (GtkWidget *widget,
4509 PangoFontDescription *font_desc)
4511 g_return_if_fail (GTK_IS_WIDGET (widget));
4513 gtk_widget_override_font (widget, font_desc);
4517 * gtk_widget_reset_rc_styles:
4518 * @widget: a #GtkWidget.
4520 * Reset the styles of @widget and all descendents, so when
4521 * they are looked up again, they get the correct values
4522 * for the currently loaded RC file settings.
4524 * This function is not useful for applications.
4526 * Deprecated:3.0: Use #GtkStyleContext instead, and gtk_widget_reset_style()
4529 gtk_widget_reset_rc_styles (GtkWidget *widget)
4531 g_return_if_fail (GTK_IS_WIDGET (widget));
4533 gtk_widget_reset_style (widget);
4538 * @widget: a #GtkWidget
4539 * @path_length: (out) (allow-none): location to store length of the path,
4541 * @path: (out) (allow-none): location to store allocated path string,
4543 * @path_reversed: (out) (allow-none): location to store allocated reverse
4544 * path string, or %NULL
4546 * Obtains the full path to @widget. The path is simply the name of a
4547 * widget and all its parents in the container hierarchy, separated by
4548 * periods. The name of a widget comes from
4549 * gtk_widget_get_name(). Paths are used to apply styles to a widget
4550 * in gtkrc configuration files. Widget names are the type of the
4551 * widget by default (e.g. "GtkButton") or can be set to an
4552 * application-specific value with gtk_widget_set_name(). By setting
4553 * the name of a widget, you allow users or theme authors to apply
4554 * styles to that specific widget in their gtkrc
4555 * file. @path_reversed_p fills in the path in reverse order,
4556 * i.e. starting with @widget's name instead of starting with the name
4557 * of @widget's outermost ancestor.
4559 * Deprecated:3.0: Use gtk_widget_get_path() instead
4562 gtk_widget_path (GtkWidget *widget,
4565 gchar **path_reversed)
4567 static gchar *rev_path = NULL;
4568 static guint tmp_path_len = 0;
4571 #define INIT_PATH_SIZE (512)
4573 g_return_if_fail (GTK_IS_WIDGET (widget));
4578 const gchar *string;
4583 string = gtk_widget_get_name (widget);
4584 l = strlen (string);
4585 while (tmp_path_len <= len + l + 1)
4587 tmp_path_len += INIT_PATH_SIZE;
4588 rev_path = g_realloc (rev_path, tmp_path_len);
4596 widget = gtk_widget_get_parent (widget);
4599 rev_path[len++] = '.';
4601 rev_path[len++] = 0;
4606 *path_length = len - 1;
4608 *path_reversed = g_strdup (rev_path);
4611 *path = g_strdup (rev_path);
4612 g_strreverse (*path);
4617 * gtk_widget_class_path:
4618 * @widget: a #GtkWidget
4619 * @path_length: (out) (allow-none): location to store the length of the
4620 * class path, or %NULL
4621 * @path: (out) (allow-none): location to store the class path as an
4622 * allocated string, or %NULL
4623 * @path_reversed: (out) (allow-none): location to store the reverse
4624 * class path as an allocated string, or %NULL
4626 * Same as gtk_widget_path(), but always uses the name of a widget's type,
4627 * never uses a custom name set with gtk_widget_set_name().
4629 * Deprecated:3.0: Use gtk_widget_get_path() instead
4632 gtk_widget_class_path (GtkWidget *widget,
4635 gchar **path_reversed)
4637 static gchar *rev_path = NULL;
4638 static guint tmp_path_len = 0;
4641 g_return_if_fail (GTK_IS_WIDGET (widget));
4646 const gchar *string;
4651 string = g_type_name (G_OBJECT_TYPE (widget));
4652 l = strlen (string);
4653 while (tmp_path_len <= len + l + 1)
4655 tmp_path_len += INIT_PATH_SIZE;
4656 rev_path = g_realloc (rev_path, tmp_path_len);
4664 widget = gtk_widget_get_parent (widget);
4667 rev_path[len++] = '.';
4669 rev_path[len++] = 0;
4674 *path_length = len - 1;
4676 *path_reversed = g_strdup (rev_path);
4679 *path = g_strdup (rev_path);
4680 g_strreverse (*path);
4685 * gtk_widget_render_icon:
4686 * @widget: a #GtkWidget
4687 * @stock_id: a stock ID
4688 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
4689 * render at the size of the source and don't scale (if there are
4690 * multiple source sizes, GTK+ picks one of the available sizes).
4691 * @detail: (allow-none): render detail to pass to theme engine
4693 * A convenience function that uses the theme settings for @widget
4694 * to look up @stock_id and render it to a pixbuf. @stock_id should
4695 * be a stock icon ID such as #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size
4696 * should be a size such as #GTK_ICON_SIZE_MENU. @detail should be a
4697 * string that identifies the widget or code doing the rendering, so
4698 * that theme engines can special-case rendering for that widget or
4701 * The pixels in the returned #GdkPixbuf are shared with the rest of
4702 * the application and should not be modified. The pixbuf should be
4703 * freed after use with g_object_unref().
4705 * Return value: (transfer full): a new pixbuf, or %NULL if the
4706 * stock ID wasn't known
4708 * Deprecated: 3.0: Use gtk_widget_render_icon_pixbuf() instead.
4711 gtk_widget_render_icon (GtkWidget *widget,
4712 const gchar *stock_id,
4714 const gchar *detail)
4716 gtk_widget_ensure_style (widget);
4718 return gtk_widget_render_icon_pixbuf (widget, stock_id, size);