1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
31 #include <gobject/gvaluecollector.h>
32 #include "gtkmarshalers.h"
35 #include "gtkspinbutton.h"
37 #include "gtkwidget.h"
38 #include "gtkthemes.h"
39 #include "gtkiconfactory.h"
40 #include "gtksettings.h" /* _gtk_settings_parse_convert() */
43 #include "gtkspinner.h"
48 * @Short_description: An object that hold style information for widgets
51 * A #GtkStyle object encapsulates the information that provides the look and
52 * feel for a widget. Each #GtkWidget has an associated #GTkStyle object that
53 * is used when rendering that widget. Also, a #GtkStyle holds information for
54 * the five possible widget states though not every widget supports all five
55 * states; see #GtkStateType.
57 * Usually the #GtkStyle for a widget is the same as the default style that is
58 * set by GTK+ and modified the theme engine.
60 * Usually applications should not need to use or modify the #GtkStyle of their
65 #define LIGHTNESS_MULT 1.3
66 #define DARKNESS_MULT 0.7
68 /* --- typedefs & structures --- */
75 #define GTK_STYLE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_STYLE, GtkStylePrivate))
77 typedef struct _GtkStylePrivate GtkStylePrivate;
79 struct _GtkStylePrivate {
81 GtkStyleContext *context;
82 gulong context_changed_id;
90 /* --- prototypes --- */
91 static void gtk_style_finalize (GObject *object);
92 static void gtk_style_constructed (GObject *object);
93 static void gtk_style_set_property (GObject *object,
98 static void gtk_style_realize (GtkStyle *style,
100 static void gtk_style_real_realize (GtkStyle *style);
101 static void gtk_style_real_unrealize (GtkStyle *style);
102 static void gtk_style_real_copy (GtkStyle *style,
104 static void gtk_style_real_set_background (GtkStyle *style,
106 GtkStateType state_type);
107 static GtkStyle *gtk_style_real_clone (GtkStyle *style);
108 static void gtk_style_real_init_from_rc (GtkStyle *style,
109 GtkRcStyle *rc_style);
110 static GdkPixbuf *gtk_default_render_icon (GtkStyle *style,
111 const GtkIconSource *source,
112 GtkTextDirection direction,
116 const gchar *detail);
117 static void gtk_default_draw_hline (GtkStyle *style,
119 GtkStateType state_type,
125 static void gtk_default_draw_vline (GtkStyle *style,
127 GtkStateType state_type,
133 static void gtk_default_draw_shadow (GtkStyle *style,
135 GtkStateType state_type,
136 GtkShadowType shadow_type,
143 static void gtk_default_draw_arrow (GtkStyle *style,
145 GtkStateType state_type,
146 GtkShadowType shadow_type,
149 GtkArrowType arrow_type,
155 static void gtk_default_draw_diamond (GtkStyle *style,
157 GtkStateType state_type,
158 GtkShadowType shadow_type,
165 static void gtk_default_draw_box (GtkStyle *style,
167 GtkStateType state_type,
168 GtkShadowType shadow_type,
175 static void gtk_default_draw_flat_box (GtkStyle *style,
177 GtkStateType state_type,
178 GtkShadowType shadow_type,
185 static void gtk_default_draw_check (GtkStyle *style,
187 GtkStateType state_type,
188 GtkShadowType shadow_type,
195 static void gtk_default_draw_option (GtkStyle *style,
197 GtkStateType state_type,
198 GtkShadowType shadow_type,
205 static void gtk_default_draw_tab (GtkStyle *style,
207 GtkStateType state_type,
208 GtkShadowType shadow_type,
215 static void gtk_default_draw_shadow_gap (GtkStyle *style,
217 GtkStateType state_type,
218 GtkShadowType shadow_type,
225 GtkPositionType gap_side,
228 static void gtk_default_draw_box_gap (GtkStyle *style,
230 GtkStateType state_type,
231 GtkShadowType shadow_type,
238 GtkPositionType gap_side,
241 static void gtk_default_draw_extension (GtkStyle *style,
243 GtkStateType state_type,
244 GtkShadowType shadow_type,
251 GtkPositionType gap_side);
252 static void gtk_default_draw_focus (GtkStyle *style,
254 GtkStateType state_type,
261 static void gtk_default_draw_slider (GtkStyle *style,
263 GtkStateType state_type,
264 GtkShadowType shadow_type,
271 GtkOrientation orientation);
272 static void gtk_default_draw_handle (GtkStyle *style,
274 GtkStateType state_type,
275 GtkShadowType shadow_type,
282 GtkOrientation orientation);
283 static void gtk_default_draw_expander (GtkStyle *style,
285 GtkStateType state_type,
290 GtkExpanderStyle expander_style);
291 static void gtk_default_draw_layout (GtkStyle *style,
293 GtkStateType state_type,
299 PangoLayout *layout);
300 static void gtk_default_draw_resize_grip (GtkStyle *style,
302 GtkStateType state_type,
310 static void gtk_default_draw_spinner (GtkStyle *style,
312 GtkStateType state_type,
321 static void rgb_to_hls (gdouble *r,
324 static void hls_to_rgb (gdouble *h,
328 static void style_unrealize_cursors (GtkStyle *style);
330 static void transform_detail_string (const gchar *detail,
331 GtkStyleContext *context);
334 * Data for default check and radio buttons
337 static const GtkRequisition default_option_indicator_size = { 7, 13 };
338 static const GtkBorder default_option_indicator_spacing = { 7, 5, 2, 2 };
340 #define GTK_GRAY 0xdcdc, 0xdada, 0xd5d5
341 #define GTK_DARK_GRAY 0xc4c4, 0xc2c2, 0xbdbd
342 #define GTK_LIGHT_GRAY 0xeeee, 0xebeb, 0xe7e7
343 #define GTK_WHITE 0xffff, 0xffff, 0xffff
344 #define GTK_BLUE 0x4b4b, 0x6969, 0x8383
345 #define GTK_VERY_DARK_GRAY 0x9c9c, 0x9a9a, 0x9494
346 #define GTK_BLACK 0x0000, 0x0000, 0x0000
347 #define GTK_WEAK_GRAY 0x7530, 0x7530, 0x7530
349 /* --- variables --- */
350 static const GdkColor gtk_default_normal_fg = { 0, GTK_BLACK };
351 static const GdkColor gtk_default_active_fg = { 0, GTK_BLACK };
352 static const GdkColor gtk_default_prelight_fg = { 0, GTK_BLACK };
353 static const GdkColor gtk_default_selected_fg = { 0, GTK_WHITE };
354 static const GdkColor gtk_default_insensitive_fg = { 0, GTK_WEAK_GRAY };
356 static const GdkColor gtk_default_normal_bg = { 0, GTK_GRAY };
357 static const GdkColor gtk_default_active_bg = { 0, GTK_DARK_GRAY };
358 static const GdkColor gtk_default_prelight_bg = { 0, GTK_LIGHT_GRAY };
359 static const GdkColor gtk_default_selected_bg = { 0, GTK_BLUE };
360 static const GdkColor gtk_default_insensitive_bg = { 0, GTK_GRAY };
361 static const GdkColor gtk_default_selected_base = { 0, GTK_BLUE };
362 static const GdkColor gtk_default_active_base = { 0, GTK_VERY_DARK_GRAY };
364 /* --- signals --- */
365 static guint realize_signal = 0;
366 static guint unrealize_signal = 0;
368 G_DEFINE_TYPE (GtkStyle, gtk_style, G_TYPE_OBJECT)
370 /* --- functions --- */
373 * _gtk_style_init_for_settings:
374 * @style: a #GtkStyle
375 * @settings: a #GtkSettings
377 * Initializes the font description in @style according to the default
378 * font name of @settings. This is called for gtk_style_new() with
379 * the settings for the default screen (if any); if we are creating
380 * a style for a particular screen, we then call it again in a
381 * location where we know the correct settings.
382 * The reason for this is that gtk_rc_style_create_style() doesn't
383 * take the screen for an argument.
386 _gtk_style_init_for_settings (GtkStyle *style,
387 GtkSettings *settings)
389 const gchar *font_name = _gtk_rc_context_get_default_font_name (settings);
391 if (style->font_desc)
392 pango_font_description_free (style->font_desc);
394 style->font_desc = pango_font_description_from_string (font_name);
396 if (!pango_font_description_get_family (style->font_desc))
398 g_warning ("Default font does not have a family set");
399 pango_font_description_set_family (style->font_desc, "Sans");
401 if (pango_font_description_get_size (style->font_desc) <= 0)
403 g_warning ("Default font does not have a positive size");
404 pango_font_description_set_size (style->font_desc, 10 * PANGO_SCALE);
409 gtk_style_init (GtkStyle *style)
413 GtkSettings *settings = gtk_settings_get_default ();
416 _gtk_style_init_for_settings (style, settings);
418 style->font_desc = pango_font_description_from_string ("Sans 10");
420 style->attach_count = 0;
422 style->black.red = 0;
423 style->black.green = 0;
424 style->black.blue = 0;
426 style->white.red = 65535;
427 style->white.green = 65535;
428 style->white.blue = 65535;
430 style->fg[GTK_STATE_NORMAL] = gtk_default_normal_fg;
431 style->fg[GTK_STATE_ACTIVE] = gtk_default_active_fg;
432 style->fg[GTK_STATE_PRELIGHT] = gtk_default_prelight_fg;
433 style->fg[GTK_STATE_SELECTED] = gtk_default_selected_fg;
434 style->fg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
436 style->bg[GTK_STATE_NORMAL] = gtk_default_normal_bg;
437 style->bg[GTK_STATE_ACTIVE] = gtk_default_active_bg;
438 style->bg[GTK_STATE_PRELIGHT] = gtk_default_prelight_bg;
439 style->bg[GTK_STATE_SELECTED] = gtk_default_selected_bg;
440 style->bg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_bg;
442 for (i = 0; i < 4; i++)
444 style->text[i] = style->fg[i];
445 style->base[i] = style->white;
448 style->base[GTK_STATE_SELECTED] = gtk_default_selected_base;
449 style->text[GTK_STATE_SELECTED] = style->white;
450 style->base[GTK_STATE_ACTIVE] = gtk_default_active_base;
451 style->text[GTK_STATE_ACTIVE] = style->white;
452 style->base[GTK_STATE_INSENSITIVE] = gtk_default_prelight_bg;
453 style->text[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
455 style->rc_style = NULL;
457 style->xthickness = 2;
458 style->ythickness = 2;
460 style->property_cache = NULL;
464 gtk_style_class_init (GtkStyleClass *klass)
466 GObjectClass *object_class = G_OBJECT_CLASS (klass);
468 object_class->finalize = gtk_style_finalize;
469 object_class->set_property = gtk_style_set_property;
470 object_class->constructed = gtk_style_constructed;
472 klass->clone = gtk_style_real_clone;
473 klass->copy = gtk_style_real_copy;
474 klass->init_from_rc = gtk_style_real_init_from_rc;
475 klass->realize = gtk_style_real_realize;
476 klass->unrealize = gtk_style_real_unrealize;
477 klass->set_background = gtk_style_real_set_background;
478 klass->render_icon = gtk_default_render_icon;
480 klass->draw_hline = gtk_default_draw_hline;
481 klass->draw_vline = gtk_default_draw_vline;
482 klass->draw_shadow = gtk_default_draw_shadow;
483 klass->draw_arrow = gtk_default_draw_arrow;
484 klass->draw_diamond = gtk_default_draw_diamond;
485 klass->draw_box = gtk_default_draw_box;
486 klass->draw_flat_box = gtk_default_draw_flat_box;
487 klass->draw_check = gtk_default_draw_check;
488 klass->draw_option = gtk_default_draw_option;
489 klass->draw_tab = gtk_default_draw_tab;
490 klass->draw_shadow_gap = gtk_default_draw_shadow_gap;
491 klass->draw_box_gap = gtk_default_draw_box_gap;
492 klass->draw_extension = gtk_default_draw_extension;
493 klass->draw_focus = gtk_default_draw_focus;
494 klass->draw_slider = gtk_default_draw_slider;
495 klass->draw_handle = gtk_default_draw_handle;
496 klass->draw_expander = gtk_default_draw_expander;
497 klass->draw_layout = gtk_default_draw_layout;
498 klass->draw_resize_grip = gtk_default_draw_resize_grip;
499 klass->draw_spinner = gtk_default_draw_spinner;
501 g_type_class_add_private (object_class, sizeof (GtkStylePrivate));
503 g_object_class_install_property (object_class,
505 g_param_spec_object ("context",
507 P_("GtkStyleContext to get style from"),
508 GTK_TYPE_STYLE_CONTEXT,
509 G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
513 * @style: the object which received the signal
515 * Emitted when the style has been initialized for a particular
516 * visual. Connecting to this signal is probably seldom
517 * useful since most of the time applications and widgets only
518 * deal with styles that have been already realized.
522 realize_signal = g_signal_new (I_("realize"),
523 G_TYPE_FROM_CLASS (object_class),
525 G_STRUCT_OFFSET (GtkStyleClass, realize),
527 _gtk_marshal_VOID__VOID,
530 * GtkStyle::unrealize:
531 * @style: the object which received the signal
533 * Emitted when the aspects of the style specific to a particular visual
534 * is being cleaned up. A connection to this signal can be useful
535 * if a widget wants to cache objects as object data on #GtkStyle.
536 * This signal provides a convenient place to free such cached objects.
540 unrealize_signal = g_signal_new (I_("unrealize"),
541 G_TYPE_FROM_CLASS (object_class),
543 G_STRUCT_OFFSET (GtkStyleClass, unrealize),
545 _gtk_marshal_VOID__VOID,
550 clear_property_cache (GtkStyle *style)
552 if (style->property_cache)
556 for (i = 0; i < style->property_cache->len; i++)
558 PropertyValue *node = &g_array_index (style->property_cache, PropertyValue, i);
560 g_param_spec_unref (node->pspec);
561 g_value_unset (&node->value);
563 g_array_free (style->property_cache, TRUE);
564 style->property_cache = NULL;
569 gtk_style_finalize (GObject *object)
571 GtkStyle *style = GTK_STYLE (object);
572 GtkStylePrivate *priv = GTK_STYLE_GET_PRIVATE (style);
574 g_return_if_fail (style->attach_count == 0);
576 clear_property_cache (style);
578 /* All the styles in the list have the same
579 * style->styles pointer. If we delete the
580 * *first* style from the list, we need to update
581 * the style->styles pointers from all the styles.
582 * Otherwise we simply remove the node from
587 if (style->styles->data != style)
588 style->styles = g_slist_remove (style->styles, style);
591 GSList *tmp_list = style->styles->next;
595 GTK_STYLE (tmp_list->data)->styles = style->styles->next;
596 tmp_list = tmp_list->next;
598 g_slist_free_1 (style->styles);
602 g_slist_foreach (style->icon_factories, (GFunc) g_object_unref, NULL);
603 g_slist_free (style->icon_factories);
605 g_slist_foreach (priv->color_hashes, (GFunc) g_hash_table_unref, NULL);
606 g_slist_free (priv->color_hashes);
608 pango_font_description_free (style->font_desc);
610 if (style->private_font_desc)
611 pango_font_description_free (style->private_font_desc);
614 g_object_unref (style->rc_style);
618 if (priv->context_changed_id)
619 g_signal_handler_disconnect (priv->context, priv->context_changed_id);
621 g_object_unref (priv->context);
624 G_OBJECT_CLASS (gtk_style_parent_class)->finalize (object);
628 gtk_style_set_property (GObject *object,
633 GtkStylePrivate *priv;
635 priv = GTK_STYLE_GET_PRIVATE (object);
640 priv->context = g_value_dup_object (value);
643 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
649 set_color (GtkStyle *style,
650 GtkStyleContext *context,
655 GdkRGBA *color = NULL;
656 GdkColor *dest = { 0 }; /* Shut up gcc */
660 case GTK_STATE_ACTIVE:
661 flags = GTK_STATE_FLAG_ACTIVE;
663 case GTK_STATE_PRELIGHT:
664 flags = GTK_STATE_FLAG_PRELIGHT;
666 case GTK_STATE_SELECTED:
667 flags = GTK_STATE_FLAG_SELECTED;
669 case GTK_STATE_INSENSITIVE:
670 flags = GTK_STATE_FLAG_INSENSITIVE;
679 gtk_style_context_get (context, flags,
680 "background-color", &color,
682 dest = &style->bg[state];
685 gtk_style_context_get (context, flags,
688 dest = &style->fg[state];
691 gtk_style_context_get (context, flags,
694 dest = &style->text[state];
697 gtk_style_context_get (context, flags,
698 "background-color", &color,
700 dest = &style->base[state];
707 dest->red = CLAMP ((guint) (color->red * 65535), 0, 65535);
708 dest->green = CLAMP ((guint) (color->green * 65535), 0, 65535);
709 dest->blue = CLAMP ((guint) (color->blue * 65535), 0, 65535);
710 gdk_rgba_free (color);
715 gtk_style_update_from_context (GtkStyle *style)
717 GtkStylePrivate *priv;
721 priv = GTK_STYLE_GET_PRIVATE (style);
723 for (state = GTK_STATE_NORMAL; state <= GTK_STATE_INSENSITIVE; state++)
725 if (gtk_style_context_has_class (priv->context, "entry"))
727 gtk_style_context_save (priv->context);
728 gtk_style_context_remove_class (priv->context, "entry");
729 set_color (style, priv->context, state, GTK_RC_BG);
730 set_color (style, priv->context, state, GTK_RC_FG);
731 gtk_style_context_restore (priv->context);
733 set_color (style, priv->context, state, GTK_RC_BASE);
734 set_color (style, priv->context, state, GTK_RC_TEXT);
738 gtk_style_context_save (priv->context);
739 gtk_style_context_add_class (priv->context, "entry");
740 set_color (style, priv->context, state, GTK_RC_BASE);
741 set_color (style, priv->context, state, GTK_RC_TEXT);
742 gtk_style_context_restore (priv->context);
744 set_color (style, priv->context, state, GTK_RC_BG);
745 set_color (style, priv->context, state, GTK_RC_FG);
749 if (style->font_desc)
750 pango_font_description_free (style->font_desc);
752 gtk_style_context_get (priv->context, state,
753 "font", &style->font_desc,
759 style->xthickness = padding->left;
760 style->ythickness = padding->top;
762 gtk_border_free (padding);
767 style_context_changed (GtkStyleContext *context,
770 gtk_style_update_from_context (GTK_STYLE (user_data));
774 gtk_style_constructed (GObject *object)
776 GtkStylePrivate *priv;
778 priv = GTK_STYLE_GET_PRIVATE (object);
782 gtk_style_update_from_context (GTK_STYLE (object));
784 priv->context_changed_id = g_signal_connect (priv->context, "changed",
785 G_CALLBACK (style_context_changed), object);
791 * @style: a #GtkStyle
793 * Creates a copy of the passed in #GtkStyle object.
795 * Returns: (transfer full): a copy of @style
797 * Deprecated:3.0: Use #GtkStyleContext instead
800 gtk_style_copy (GtkStyle *style)
804 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
806 new_style = GTK_STYLE_GET_CLASS (style)->clone (style);
807 GTK_STYLE_GET_CLASS (style)->copy (new_style, style);
813 gtk_style_duplicate (GtkStyle *style)
817 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
819 new_style = gtk_style_copy (style);
821 /* All the styles in the list have the same
822 * style->styles pointer. When we insert a new
823 * style, we append it to the list to avoid having
824 * to update the existing ones.
826 style->styles = g_slist_append (style->styles, new_style);
827 new_style->styles = style->styles;
834 * @returns: a new #GtkStyle.
836 * Creates a new #GtkStyle.
838 * Deprecated: 3.0: Use #GtkStyleContext
845 style = g_object_new (GTK_TYPE_STYLE, NULL);
851 gtk_style_has_context (GtkStyle *style)
853 GtkStylePrivate *priv;
855 priv = GTK_STYLE_GET_PRIVATE (style);
857 return priv->context != NULL;
862 * @style: a #GtkStyle.
863 * @window: a #GdkWindow.
865 * Attaches a style to a window; this process allocates the
866 * colors and creates the GC's for the style - it specializes
867 * it to a particular visual. The process may involve the creation
868 * of a new style if the style has already been attached to a
869 * window with a different style and visual.
871 * Since this function may return a new object, you have to use it
872 * in the following way:
873 * <literal>style = gtk_style_attach (style, window)</literal>
875 * Returns: Either @style, or a newly-created #GtkStyle.
876 * If the style is newly created, the style parameter
877 * will be unref'ed, and the new style will have
878 * a reference count belonging to the caller.
880 * Deprecated:3.0: Use gtk_widget_style_attach() instead
883 gtk_style_attach (GtkStyle *style,
887 GtkStyle *new_style = NULL;
890 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
891 g_return_val_if_fail (window != NULL, NULL);
893 visual = gdk_window_get_visual (window);
896 style->styles = g_slist_append (NULL, style);
898 styles = style->styles;
901 new_style = styles->data;
903 if (new_style->visual == visual)
907 styles = styles->next;
912 styles = style->styles;
916 new_style = styles->data;
918 if (new_style->attach_count == 0)
920 gtk_style_realize (new_style, visual);
925 styles = styles->next;
931 new_style = gtk_style_duplicate (style);
932 gtk_style_realize (new_style, visual);
935 /* A style gets a refcount from being attached */
936 if (new_style->attach_count == 0)
937 g_object_ref (new_style);
939 /* Another refcount belongs to the parent */
940 if (style != new_style)
942 g_object_unref (style);
943 g_object_ref (new_style);
946 new_style->attach_count++;
953 * @style: a #GtkStyle
955 * Detaches a style from a window. If the style is not attached
956 * to any windows anymore, it is unrealized. See gtk_style_attach().
958 * Deprecated:3.0: Use #GtkStyleContext instead
961 gtk_style_detach (GtkStyle *style)
963 g_return_if_fail (GTK_IS_STYLE (style));
965 if (style->attach_count == 0)
968 style->attach_count -= 1;
969 if (style->attach_count == 0)
971 g_signal_emit (style, unrealize_signal, 0);
973 g_object_unref (style->visual);
974 style->visual = NULL;
976 if (style->private_font_desc)
978 pango_font_description_free (style->private_font_desc);
979 style->private_font_desc = NULL;
982 g_object_unref (style);
987 gtk_style_realize (GtkStyle *style,
990 style->visual = g_object_ref (visual);
992 g_signal_emit (style, realize_signal, 0);
996 * gtk_style_lookup_icon_set:
997 * @style: a #GtkStyle
998 * @stock_id: an icon name
1000 * Looks up @stock_id in the icon factories associated with @style
1001 * and the default icon factory, returning an icon set if found,
1004 * Return value: icon set of @stock_id
1006 * Deprecated:3.0: Use gtk_style_context_lookup_icon_set() instead
1009 gtk_style_lookup_icon_set (GtkStyle *style,
1010 const char *stock_id)
1012 GtkStylePrivate *priv;
1014 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1015 g_return_val_if_fail (stock_id != NULL, NULL);
1017 priv = GTK_STYLE_GET_PRIVATE (style);
1020 return gtk_style_context_lookup_icon_set (priv->context, stock_id);
1022 return gtk_icon_factory_lookup_default (stock_id);
1026 * gtk_style_lookup_color:
1027 * @style: a #GtkStyle
1028 * @color_name: the name of the logical color to look up
1029 * @color: the #GdkColor to fill in
1031 * Looks up @color_name in the style's logical color mappings,
1032 * filling in @color and returning %TRUE if found, otherwise
1033 * returning %FALSE. Do not cache the found mapping, because
1034 * it depends on the #GtkStyle and might change when a theme
1037 * Return value: %TRUE if the mapping was found.
1041 * Deprecated:3.0: Use gtk_style_context_lookup_color() instead
1044 gtk_style_lookup_color (GtkStyle *style,
1045 const char *color_name,
1048 GtkStylePrivate *priv;
1052 g_return_val_if_fail (GTK_IS_STYLE (style), FALSE);
1053 g_return_val_if_fail (color_name != NULL, FALSE);
1054 g_return_val_if_fail (color != NULL, FALSE);
1056 priv = GTK_STYLE_GET_PRIVATE (style);
1061 result = gtk_style_context_lookup_color (priv->context, color_name, &rgba);
1065 color->red = (guint16) (rgba.red * 65535);
1066 color->green = (guint16) (rgba.green * 65535);
1067 color->blue = (guint16) (rgba.blue * 65535);
1075 * gtk_style_set_background:
1076 * @style: a #GtkStyle
1077 * @window: a #GdkWindow
1078 * @state_type: a state
1080 * Sets the background of @window to the background color or pixmap
1081 * specified by @style for the given state.
1083 * Deprecated:3.0: Use gtk_style_context_set_background() instead
1086 gtk_style_set_background (GtkStyle *style,
1088 GtkStateType state_type)
1090 g_return_if_fail (GTK_IS_STYLE (style));
1091 g_return_if_fail (window != NULL);
1093 GTK_STYLE_GET_CLASS (style)->set_background (style, window, state_type);
1096 /* Default functions */
1098 gtk_style_real_clone (GtkStyle *style)
1100 GtkStylePrivate *priv;
1102 priv = GTK_STYLE_GET_PRIVATE (style);
1104 return g_object_new (G_OBJECT_TYPE (style),
1105 "context", priv->context,
1110 gtk_style_real_copy (GtkStyle *style,
1113 GtkStylePrivate *priv = GTK_STYLE_GET_PRIVATE (style);
1114 GtkStylePrivate *src_priv = GTK_STYLE_GET_PRIVATE (src);
1117 for (i = 0; i < 5; i++)
1119 style->fg[i] = src->fg[i];
1120 style->bg[i] = src->bg[i];
1121 style->text[i] = src->text[i];
1122 style->base[i] = src->base[i];
1124 if (style->background[i])
1125 cairo_pattern_destroy (style->background[i]),
1126 style->background[i] = src->background[i];
1127 if (style->background[i])
1128 cairo_pattern_reference (style->background[i]);
1131 if (style->font_desc)
1132 pango_font_description_free (style->font_desc);
1134 style->font_desc = pango_font_description_copy (src->font_desc);
1136 style->font_desc = NULL;
1138 style->xthickness = src->xthickness;
1139 style->ythickness = src->ythickness;
1141 if (style->rc_style)
1142 g_object_unref (style->rc_style);
1143 style->rc_style = src->rc_style;
1145 g_object_ref (src->rc_style);
1147 g_slist_foreach (style->icon_factories, (GFunc) g_object_unref, NULL);
1148 g_slist_free (style->icon_factories);
1149 style->icon_factories = g_slist_copy (src->icon_factories);
1150 g_slist_foreach (style->icon_factories, (GFunc) g_object_ref, NULL);
1152 g_slist_foreach (priv->color_hashes, (GFunc) g_hash_table_unref, NULL);
1153 g_slist_free (priv->color_hashes);
1154 priv->color_hashes = g_slist_copy (src_priv->color_hashes);
1155 g_slist_foreach (priv->color_hashes, (GFunc) g_hash_table_ref, NULL);
1157 /* don't copy, just clear cache */
1158 clear_property_cache (style);
1162 gtk_style_real_init_from_rc (GtkStyle *style,
1163 GtkRcStyle *rc_style)
1165 GtkStylePrivate *priv = GTK_STYLE_GET_PRIVATE (style);
1168 /* cache _should_ be still empty */
1169 clear_property_cache (style);
1171 if (rc_style->font_desc)
1172 pango_font_description_merge (style->font_desc, rc_style->font_desc, TRUE);
1174 for (i = 0; i < 5; i++)
1176 if (rc_style->color_flags[i] & GTK_RC_FG)
1177 style->fg[i] = rc_style->fg[i];
1178 if (rc_style->color_flags[i] & GTK_RC_BG)
1179 style->bg[i] = rc_style->bg[i];
1180 if (rc_style->color_flags[i] & GTK_RC_TEXT)
1181 style->text[i] = rc_style->text[i];
1182 if (rc_style->color_flags[i] & GTK_RC_BASE)
1183 style->base[i] = rc_style->base[i];
1186 if (rc_style->xthickness >= 0)
1187 style->xthickness = rc_style->xthickness;
1188 if (rc_style->ythickness >= 0)
1189 style->ythickness = rc_style->ythickness;
1191 style->icon_factories = g_slist_copy (rc_style->icon_factories);
1192 g_slist_foreach (style->icon_factories, (GFunc) g_object_ref, NULL);
1194 priv->color_hashes = g_slist_copy (_gtk_rc_style_get_color_hashes (rc_style));
1195 g_slist_foreach (priv->color_hashes, (GFunc) g_hash_table_ref, NULL);
1199 style_property_values_cmp (gconstpointer bsearch_node1,
1200 gconstpointer bsearch_node2)
1202 const PropertyValue *val1 = bsearch_node1;
1203 const PropertyValue *val2 = bsearch_node2;
1205 if (val1->widget_type == val2->widget_type)
1206 return val1->pspec < val2->pspec ? -1 : val1->pspec == val2->pspec ? 0 : 1;
1208 return val1->widget_type < val2->widget_type ? -1 : 1;
1212 * gtk_style_get_style_property:
1213 * @style: a #GtkStyle
1214 * @widget_type: the #GType of a descendant of #GtkWidget
1215 * @property_name: the name of the style property to get
1216 * @value: a #GValue where the value of the property being
1217 * queried will be stored
1219 * Queries the value of a style property corresponding to a
1220 * widget class is in the given style.
1225 gtk_style_get_style_property (GtkStyle *style,
1227 const gchar *property_name,
1230 GtkWidgetClass *klass;
1232 GtkRcPropertyParser parser;
1233 const GValue *peek_value;
1235 klass = g_type_class_ref (widget_type);
1236 pspec = gtk_widget_class_find_style_property (klass, property_name);
1237 g_type_class_unref (klass);
1241 g_warning ("%s: widget class `%s' has no property named `%s'",
1243 g_type_name (widget_type),
1248 parser = g_param_spec_get_qdata (pspec,
1249 g_quark_from_static_string ("gtk-rc-property-parser"));
1251 peek_value = _gtk_style_peek_property_value (style, widget_type, pspec, parser);
1253 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
1254 g_value_copy (peek_value, value);
1255 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
1256 g_value_transform (peek_value, value);
1258 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
1260 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1261 G_VALUE_TYPE_NAME (value));
1265 * gtk_style_get_valist:
1266 * @style: a #GtkStyle
1267 * @widget_type: the #GType of a descendant of #GtkWidget
1268 * @first_property_name: the name of the first style property to get
1269 * @var_args: a <type>va_list</type> of pairs of property names and
1270 * locations to return the property values, starting with the
1271 * location for @first_property_name.
1273 * Non-vararg variant of gtk_style_get().
1274 * Used primarily by language bindings.
1279 gtk_style_get_valist (GtkStyle *style,
1281 const gchar *first_property_name,
1284 const char *property_name;
1285 GtkWidgetClass *klass;
1287 g_return_if_fail (GTK_IS_STYLE (style));
1289 klass = g_type_class_ref (widget_type);
1291 property_name = first_property_name;
1292 while (property_name)
1295 GtkRcPropertyParser parser;
1296 const GValue *peek_value;
1299 pspec = gtk_widget_class_find_style_property (klass, property_name);
1303 g_warning ("%s: widget class `%s' has no property named `%s'",
1305 g_type_name (widget_type),
1310 parser = g_param_spec_get_qdata (pspec,
1311 g_quark_from_static_string ("gtk-rc-property-parser"));
1313 peek_value = _gtk_style_peek_property_value (style, widget_type, pspec, parser);
1314 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
1317 g_warning ("%s: %s", G_STRLOC, error);
1322 property_name = va_arg (var_args, gchar*);
1325 g_type_class_unref (klass);
1330 * @style: a #GtkStyle
1331 * @widget_type: the #GType of a descendant of #GtkWidget
1332 * @first_property_name: the name of the first style property to get
1333 * @Varargs: pairs of property names and locations to
1334 * return the property values, starting with the location for
1335 * @first_property_name, terminated by %NULL.
1337 * Gets the values of a multiple style properties for @widget_type
1343 gtk_style_get (GtkStyle *style,
1345 const gchar *first_property_name,
1350 va_start (var_args, first_property_name);
1351 gtk_style_get_valist (style, widget_type, first_property_name, var_args);
1356 _gtk_style_peek_property_value (GtkStyle *style,
1359 GtkRcPropertyParser parser)
1361 PropertyValue *pcache, key = { 0, NULL, { 0, } };
1362 const GtkRcProperty *rcprop = NULL;
1365 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1366 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), NULL);
1367 g_return_val_if_fail (g_type_is_a (pspec->owner_type, GTK_TYPE_WIDGET), NULL);
1368 g_return_val_if_fail (g_type_is_a (widget_type, pspec->owner_type), NULL);
1370 key.widget_type = widget_type;
1373 /* need value cache array */
1374 if (!style->property_cache)
1375 style->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
1378 pcache = bsearch (&key,
1379 style->property_cache->data, style->property_cache->len,
1380 sizeof (PropertyValue), style_property_values_cmp);
1382 return &pcache->value;
1386 while (i < style->property_cache->len &&
1387 style_property_values_cmp (&key, &g_array_index (style->property_cache, PropertyValue, i)) >= 0)
1390 g_array_insert_val (style->property_cache, i, key);
1391 pcache = &g_array_index (style->property_cache, PropertyValue, i);
1393 /* cache miss, initialize value type, then set contents */
1394 g_param_spec_ref (pcache->pspec);
1395 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1397 /* value provided by rc style? */
1398 if (style->rc_style)
1400 GQuark prop_quark = g_quark_from_string (pspec->name);
1404 rcprop = _gtk_rc_style_lookup_rc_property (style->rc_style,
1405 g_type_qname (widget_type),
1409 widget_type = g_type_parent (widget_type);
1411 while (g_type_is_a (widget_type, pspec->owner_type));
1414 /* when supplied by rc style, we need to convert */
1415 if (rcprop && !_gtk_settings_parse_convert (parser, &rcprop->value,
1416 pspec, &pcache->value))
1418 gchar *contents = g_strdup_value_contents (&rcprop->value);
1420 g_message ("%s: failed to retrieve property `%s::%s' of type `%s' from rc file value \"%s\" of type `%s'",
1421 rcprop->origin ? rcprop->origin : "(for origin information, set GTK_DEBUG)",
1422 g_type_name (pspec->owner_type), pspec->name,
1423 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1425 G_VALUE_TYPE_NAME (&rcprop->value));
1427 rcprop = NULL; /* needs default */
1430 /* not supplied by rc style (or conversion failed), revert to default */
1432 g_param_value_set_default (pspec, &pcache->value);
1434 return &pcache->value;
1437 static cairo_pattern_t *
1438 load_background (GdkVisual *visual,
1440 const gchar *filename)
1442 if (filename == NULL)
1444 return cairo_pattern_create_rgb (bg_color->red / 65535.0,
1445 bg_color->green / 65535.0,
1446 bg_color->blue / 65535.0);
1448 if (strcmp (filename, "<parent>") == 0)
1453 cairo_surface_t *surface;
1454 cairo_pattern_t *pattern;
1456 GdkScreen *screen = gdk_visual_get_screen (visual);
1458 pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
1462 surface = gdk_window_create_similar_surface (gdk_screen_get_root_window (screen),
1463 CAIRO_CONTENT_COLOR,
1464 gdk_pixbuf_get_width (pixbuf),
1465 gdk_pixbuf_get_height (pixbuf));
1467 cr = cairo_create (surface);
1469 gdk_cairo_set_source_color (cr, bg_color);
1472 gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
1476 g_object_unref (pixbuf);
1478 pattern = cairo_pattern_create_for_surface (surface);
1480 cairo_surface_destroy (surface);
1487 gtk_style_real_realize (GtkStyle *style)
1491 for (i = 0; i < 5; i++)
1493 _gtk_style_shade (&style->bg[i], &style->light[i], LIGHTNESS_MULT);
1494 _gtk_style_shade (&style->bg[i], &style->dark[i], DARKNESS_MULT);
1496 style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
1497 style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
1498 style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
1500 style->text_aa[i].red = (style->text[i].red + style->base[i].red) / 2;
1501 style->text_aa[i].green = (style->text[i].green + style->base[i].green) / 2;
1502 style->text_aa[i].blue = (style->text[i].blue + style->base[i].blue) / 2;
1505 style->black.red = 0x0000;
1506 style->black.green = 0x0000;
1507 style->black.blue = 0x0000;
1509 style->white.red = 0xffff;
1510 style->white.green = 0xffff;
1511 style->white.blue = 0xffff;
1513 for (i = 0; i < 5; i++)
1515 const char *image_name;
1517 if (style->rc_style)
1518 image_name = style->rc_style->bg_pixmap_name[i];
1522 style->background[i] = load_background (style->visual,
1529 gtk_style_real_unrealize (GtkStyle *style)
1533 for (i = 0; i < 5; i++)
1535 if (style->background[i])
1537 cairo_pattern_destroy (style->background[i]);
1538 style->background[i] = NULL;
1543 style_unrealize_cursors (style);
1547 gtk_style_real_set_background (GtkStyle *style,
1549 GtkStateType state_type)
1551 gdk_window_set_background_pattern (window, style->background[state_type]);
1555 * gtk_style_render_icon:
1556 * @style: a #GtkStyle
1557 * @source: the #GtkIconSource specifying the icon to render
1558 * @direction: a text direction
1560 * @size: (type int): the size to render the icon at. A size of
1561 * (GtkIconSize)-1 means render at the size of the source and
1563 * @widget: (allow-none): the widget
1564 * @detail: (allow-none): a style detail
1566 * Renders the icon specified by @source at the given @size
1567 * according to the given parameters and returns the result in a
1570 * Return value: (transfer full): a newly-created #GdkPixbuf
1571 * containing the rendered icon
1573 * Deprecated:3.0: Use gtk_render_icon_pixbuf() instead
1576 gtk_style_render_icon (GtkStyle *style,
1577 const GtkIconSource *source,
1578 GtkTextDirection direction,
1582 const gchar *detail)
1586 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1587 g_return_val_if_fail (GTK_STYLE_GET_CLASS (style)->render_icon != NULL, NULL);
1589 pixbuf = GTK_STYLE_GET_CLASS (style)->render_icon (style, source, direction, state,
1590 size, widget, detail);
1592 g_return_val_if_fail (pixbuf != NULL, NULL);
1597 /* Default functions */
1600 * gtk_style_apply_default_background:
1606 * @area: (allow-none):
1612 * Deprecated:3.0: Use #GtkStyleContext instead
1615 gtk_style_apply_default_background (GtkStyle *style,
1618 GtkStateType state_type,
1626 if (style->background[state_type] == NULL)
1628 GdkWindow *parent = gdk_window_get_parent (window);
1629 int x_offset, y_offset;
1633 gdk_window_get_position (window, &x_offset, &y_offset);
1634 cairo_translate (cr, -x_offset, -y_offset);
1635 gtk_style_apply_default_background (style, cr,
1637 x + x_offset, y + y_offset,
1642 gdk_cairo_set_source_color (cr, &style->bg[state_type]);
1645 cairo_set_source (cr, style->background[state_type]);
1647 cairo_rectangle (cr, x, y, width, height);
1655 gtk_default_render_icon (GtkStyle *style,
1656 const GtkIconSource *source,
1657 GtkTextDirection direction,
1661 const gchar *detail)
1663 GtkStyleContext *context;
1664 GtkStylePrivate *priv;
1668 context = gtk_widget_get_style_context (widget);
1671 priv = GTK_STYLE_GET_PRIVATE (style);
1672 context = priv->context;
1678 gtk_style_context_save (context);
1681 transform_detail_string (detail, context);
1683 pixbuf = gtk_render_icon_pixbuf (context, source, size);
1685 gtk_style_context_restore (context);
1691 _cairo_draw_line (cairo_t *cr,
1700 gdk_cairo_set_source_color (cr, color);
1701 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
1703 cairo_move_to (cr, x1 + 0.5, y1 + 0.5);
1704 cairo_line_to (cr, x2 + 0.5, y2 + 0.5);
1711 _cairo_draw_rectangle (cairo_t *cr,
1719 gdk_cairo_set_source_color (cr, color);
1723 cairo_rectangle (cr, x, y, width, height);
1728 cairo_rectangle (cr, x + 0.5, y + 0.5, width, height);
1734 _cairo_draw_point (cairo_t *cr,
1739 gdk_cairo_set_source_color (cr, color);
1740 cairo_rectangle (cr, x, y, 1, 1);
1745 transform_detail_string (const gchar *detail,
1746 GtkStyleContext *context)
1751 if (strcmp (detail, "arrow") == 0)
1752 gtk_style_context_add_class (context, "arrow");
1753 else if (strcmp (detail, "button") == 0)
1754 gtk_style_context_add_class (context, "button");
1755 else if (strcmp (detail, "buttondefault") == 0)
1757 gtk_style_context_add_class (context, "button");
1758 gtk_style_context_add_class (context, "default");
1760 else if (strcmp (detail, "calendar") == 0)
1761 gtk_style_context_add_class (context, "calendar");
1762 else if (strcmp (detail, "cellcheck") == 0)
1764 gtk_style_context_add_class (context, "cell");
1765 gtk_style_context_add_class (context, "check");
1767 else if (strcmp (detail, "cellradio") == 0)
1769 gtk_style_context_add_class (context, "cell");
1770 gtk_style_context_add_class (context, "radio");
1772 else if (strcmp (detail, "checkbutton") == 0)
1773 gtk_style_context_add_class (context, "check");
1774 else if (strcmp (detail, "check") == 0)
1776 gtk_style_context_add_class (context, "check");
1777 gtk_style_context_add_class (context, "menu");
1779 else if (strcmp (detail, "radiobutton") == 0)
1781 gtk_style_context_add_class (context, "radio");
1783 else if (strcmp (detail, "option") == 0)
1785 gtk_style_context_add_class (context, "radio");
1786 gtk_style_context_add_class (context, "menu");
1788 else if (strcmp (detail, "entry") == 0 ||
1789 strcmp (detail, "entry_bg") == 0)
1790 gtk_style_context_add_class (context, "entry");
1791 else if (strcmp (detail, "expander") == 0)
1792 gtk_style_context_add_class (context, "expander");
1793 else if (strcmp (detail, "tooltip") == 0)
1794 gtk_style_context_add_class (context, "tooltip");
1795 else if (strcmp (detail, "frame") == 0)
1796 gtk_style_context_add_class (context, "frame");
1797 else if (strcmp (detail, "scrolled_window") == 0)
1798 gtk_style_context_add_class (context, "scrolled-window");
1799 else if (strcmp (detail, "viewport") == 0 ||
1800 strcmp (detail, "viewportbin") == 0)
1801 gtk_style_context_add_class (context, "viewport");
1802 else if (strncmp (detail, "trough", 6) == 0)
1804 gtk_style_context_add_class (context, "scrollbar");
1805 gtk_style_context_add_class (context, "trough");
1807 else if (strcmp (detail, "spinbutton") == 0)
1808 gtk_style_context_add_class (context, "spinbutton");
1809 else if (strcmp (detail, "spinbutton_up") == 0)
1811 gtk_style_context_add_class (context, "spinbutton");
1812 gtk_style_context_add_class (context, "button");
1813 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
1815 else if (strcmp (detail, "spinbutton_down") == 0)
1817 gtk_style_context_add_class (context, "spinbutton");
1818 gtk_style_context_add_class (context, "button");
1819 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
1821 else if ((detail[0] == 'h' || detail[0] == 'v') &&
1822 strncmp (&detail[1], "scrollbar_", 10) == 0)
1824 gtk_style_context_add_class (context, "button");
1825 gtk_style_context_add_class (context, "scrollbar");
1827 else if (strcmp (detail, "slider") == 0)
1829 gtk_style_context_add_class (context, "slider");
1830 gtk_style_context_add_class (context, "scrollbar");
1832 else if (strcmp (detail, "vscale") == 0 ||
1833 strcmp (detail, "hscale") == 0)
1835 gtk_style_context_add_class (context, "slider");
1836 gtk_style_context_add_class (context, "scale");
1838 else if (strcmp (detail, "menuitem") == 0)
1840 gtk_style_context_add_class (context, "menuitem");
1841 gtk_style_context_add_class (context, "menu");
1843 else if (strcmp (detail, "menu") == 0)
1845 gtk_style_context_add_class (context, "popup");
1846 gtk_style_context_add_class (context, "menu");
1848 else if (strcmp (detail, "accellabel") == 0)
1849 gtk_style_context_add_class (context, "accelerator");
1850 else if (strcmp (detail, "menubar") == 0)
1851 gtk_style_context_add_class (context, "menubar");
1852 else if (strcmp (detail, "base") == 0)
1853 gtk_style_context_add_class (context, "background");
1854 else if (strcmp (detail, "bar") == 0 ||
1855 strcmp (detail, "progressbar") == 0)
1856 gtk_style_context_add_class (context, "progressbar");
1857 else if (strcmp (detail, "toolbar") == 0)
1858 gtk_style_context_add_class (context, "toolbar");
1859 else if (strcmp (detail, "handlebox_bin") == 0)
1860 gtk_style_context_add_class (context, "dock");
1861 else if (strcmp (detail, "notebook") == 0)
1862 gtk_style_context_add_class (context, "notebook");
1863 else if (strcmp (detail, "tab") == 0)
1865 gtk_style_context_add_class (context, "notebook");
1866 gtk_style_context_add_region (context, GTK_STYLE_REGION_TAB, 0);
1868 else if (g_str_has_prefix (detail, "cell"))
1870 GtkRegionFlags row, col;
1871 gboolean ruled = FALSE;
1875 tokens = g_strsplit (detail, "_", -1);
1881 if (strcmp (tokens[i], "even") == 0)
1882 row |= GTK_REGION_EVEN;
1883 else if (strcmp (tokens[i], "odd") == 0)
1884 row |= GTK_REGION_ODD;
1885 else if (strcmp (tokens[i], "start") == 0)
1886 col |= GTK_REGION_FIRST;
1887 else if (strcmp (tokens[i], "end") == 0)
1888 col |= GTK_REGION_LAST;
1889 else if (strcmp (tokens[i], "ruled") == 0)
1891 else if (strcmp (tokens[i], "sorted") == 0)
1892 col |= GTK_REGION_SORTED;
1898 row &= ~(GTK_REGION_EVEN | GTK_REGION_ODD);
1900 gtk_style_context_add_class (context, "cell");
1901 gtk_style_context_add_region (context, "row", row);
1902 gtk_style_context_add_region (context, "column", col);
1904 g_strfreev (tokens);
1909 gtk_default_draw_hline (GtkStyle *style,
1911 GtkStateType state_type,
1913 const gchar *detail,
1918 GtkStyleContext *context;
1919 GtkStylePrivate *priv;
1922 context = gtk_widget_get_style_context (widget);
1925 priv = GTK_STYLE_GET_PRIVATE (style);
1926 context = priv->context;
1929 gtk_style_context_save (context);
1932 transform_detail_string (detail, context);
1936 gtk_render_line (context, cr,
1941 gtk_style_context_restore (context);
1946 gtk_default_draw_vline (GtkStyle *style,
1948 GtkStateType state_type,
1950 const gchar *detail,
1955 GtkStyleContext *context;
1956 GtkStylePrivate *priv;
1959 context = gtk_widget_get_style_context (widget);
1962 priv = GTK_STYLE_GET_PRIVATE (style);
1963 context = priv->context;
1966 gtk_style_context_save (context);
1969 transform_detail_string (detail, context);
1973 gtk_render_line (context, cr,
1977 gtk_style_context_restore (context);
1981 draw_thin_shadow (GtkStyle *style,
1989 GdkColor *gc1, *gc2;
1991 gc1 = &style->light[state];
1992 gc2 = &style->dark[state];
1994 _cairo_draw_line (cr, gc1,
1995 x, y + height - 1, x + width - 1, y + height - 1);
1996 _cairo_draw_line (cr, gc1,
1997 x + width - 1, y, x + width - 1, y + height - 1);
1999 _cairo_draw_line (cr, gc2,
2000 x, y, x + width - 2, y);
2001 _cairo_draw_line (cr, gc2,
2002 x, y, x, y + height - 2);
2006 draw_spinbutton_shadow (GtkStyle *style,
2009 GtkTextDirection direction,
2016 if (direction == GTK_TEXT_DIR_LTR)
2018 _cairo_draw_line (cr, &style->dark[state],
2019 x, y, x + width - 1, y);
2020 _cairo_draw_line (cr, &style->black,
2021 x, y + 1, x + width - 2, y + 1);
2022 _cairo_draw_line (cr, &style->black,
2023 x + width - 2, y + 2, x + width - 2, y + height - 3);
2024 _cairo_draw_line (cr, &style->light[state],
2025 x + width - 1, y + 1, x + width - 1, y + height - 2);
2026 _cairo_draw_line (cr, &style->light[state],
2027 x, y + height - 1, x + width - 1, y + height - 1);
2028 _cairo_draw_line (cr, &style->bg[state],
2029 x, y + height - 2, x + width - 2, y + height - 2);
2030 _cairo_draw_line (cr, &style->black,
2031 x, y + 2, x, y + height - 3);
2035 _cairo_draw_line (cr, &style->dark[state],
2036 x, y, x + width - 1, y);
2037 _cairo_draw_line (cr, &style->dark[state],
2038 x, y + 1, x, y + height - 1);
2039 _cairo_draw_line (cr, &style->black,
2040 x + 1, y + 1, x + width - 1, y + 1);
2041 _cairo_draw_line (cr, &style->black,
2042 x + 1, y + 2, x + 1, y + height - 2);
2043 _cairo_draw_line (cr, &style->black,
2044 x + width - 1, y + 2, x + width - 1, y + height - 3);
2045 _cairo_draw_line (cr, &style->light[state],
2046 x + 1, y + height - 1, x + width - 1, y + height - 1);
2047 _cairo_draw_line (cr, &style->bg[state],
2048 x + 2, y + height - 2, x + width - 1, y + height - 2);
2053 draw_menu_shadow (GtkStyle *style,
2061 if (style->ythickness > 0)
2063 if (style->ythickness > 1)
2065 _cairo_draw_line (cr, &style->dark[state],
2066 x + 1, y + height - 2,
2067 x + width - 2, y + height - 2);
2068 _cairo_draw_line (cr, &style->black,
2069 x, y + height - 1, x + width - 1, y + height - 1);
2073 _cairo_draw_line (cr, &style->dark[state],
2074 x + 1, y + height - 1, x + width - 1, y + height - 1);
2078 if (style->xthickness > 0)
2080 if (style->xthickness > 1)
2082 _cairo_draw_line (cr, &style->dark[state],
2083 x + width - 2, y + 1,
2084 x + width - 2, y + height - 2);
2086 _cairo_draw_line (cr, &style->black,
2087 x + width - 1, y, x + width - 1, y + height - 1);
2091 _cairo_draw_line (cr, &style->dark[state],
2092 x + width - 1, y + 1, x + width - 1, y + height - 1);
2096 /* Light around top and left */
2098 if (style->ythickness > 0)
2099 _cairo_draw_line (cr, &style->black,
2100 x, y, x + width - 2, y);
2101 if (style->xthickness > 0)
2102 _cairo_draw_line (cr, &style->black,
2103 x, y, x, y + height - 2);
2105 if (style->ythickness > 1)
2106 _cairo_draw_line (cr, &style->light[state],
2107 x + 1, y + 1, x + width - 3, y + 1);
2108 if (style->xthickness > 1)
2109 _cairo_draw_line (cr, &style->light[state],
2110 x + 1, y + 1, x + 1, y + height - 3);
2113 static GtkTextDirection
2114 get_direction (GtkWidget *widget)
2116 GtkTextDirection dir;
2119 dir = gtk_widget_get_direction (widget);
2121 dir = GTK_TEXT_DIR_LTR;
2128 gtk_default_draw_shadow (GtkStyle *style,
2130 GtkStateType state_type,
2131 GtkShadowType shadow_type,
2133 const gchar *detail,
2139 GtkStyleContext *context;
2140 GtkStylePrivate *priv;
2143 context = gtk_widget_get_style_context (widget);
2146 priv = GTK_STYLE_GET_PRIVATE (style);
2147 context = priv->context;
2150 gtk_style_context_save (context);
2153 transform_detail_string (detail, context);
2157 gtk_render_frame (context, cr,
2164 gtk_style_context_restore (context);
2168 draw_arrow (cairo_t *cr,
2170 GtkArrowType arrow_type,
2176 gdk_cairo_set_source_color (cr, color);
2179 if (arrow_type == GTK_ARROW_DOWN)
2181 cairo_move_to (cr, x, y);
2182 cairo_line_to (cr, x + width, y);
2183 cairo_line_to (cr, x + width / 2., y + height);
2185 else if (arrow_type == GTK_ARROW_UP)
2187 cairo_move_to (cr, x, y + height);
2188 cairo_line_to (cr, x + width / 2., y);
2189 cairo_line_to (cr, x + width, y + height);
2191 else if (arrow_type == GTK_ARROW_LEFT)
2193 cairo_move_to (cr, x + width, y);
2194 cairo_line_to (cr, x + width, y + height);
2195 cairo_line_to (cr, x, y + height / 2.);
2197 else if (arrow_type == GTK_ARROW_RIGHT)
2199 cairo_move_to (cr, x, y);
2200 cairo_line_to (cr, x + width, y + height / 2.);
2201 cairo_line_to (cr, x, y + height);
2204 cairo_close_path (cr);
2211 calculate_arrow_geometry (GtkArrowType arrow_type,
2223 case GTK_ARROW_DOWN:
2233 if (arrow_type == GTK_ARROW_DOWN)
2235 if (*height % 2 == 1 || h % 2 == 0)
2240 if (*height % 2 == 0 || h % 2 == 0)
2245 case GTK_ARROW_RIGHT:
2246 case GTK_ARROW_LEFT:
2256 if (arrow_type == GTK_ARROW_RIGHT)
2258 if (*width % 2 == 1 || w % 2 == 0)
2263 if (*width % 2 == 0 || w % 2 == 0)
2269 /* should not be reached */
2273 *x += (*width - w) / 2;
2274 *y += (*height - h) / 2;
2280 gtk_default_draw_arrow (GtkStyle *style,
2283 GtkShadowType shadow,
2285 const gchar *detail,
2286 GtkArrowType arrow_type,
2293 GtkStyleContext *context;
2294 GtkStylePrivate *priv;
2295 GtkStateFlags flags = 0;
2296 gdouble angle, size;
2298 if (arrow_type == GTK_ARROW_NONE)
2302 context = gtk_widget_get_style_context (widget);
2305 priv = GTK_STYLE_GET_PRIVATE (style);
2306 context = priv->context;
2309 gtk_style_context_save (context);
2312 transform_detail_string (detail, context);
2320 case GTK_ARROW_RIGHT:
2324 case GTK_ARROW_DOWN:
2328 case GTK_ARROW_LEFT:
2329 angle = 3 * (G_PI / 2);
2333 g_assert_not_reached ();
2338 case GTK_STATE_PRELIGHT:
2339 flags |= GTK_STATE_FLAG_PRELIGHT;
2341 case GTK_STATE_SELECTED:
2342 flags |= GTK_STATE_FLAG_SELECTED;
2344 case GTK_STATE_INSENSITIVE:
2345 flags |= GTK_STATE_FLAG_INSENSITIVE;
2347 case GTK_STATE_ACTIVE:
2348 flags |= GTK_STATE_FLAG_ACTIVE;
2354 gtk_style_context_set_state (context, flags);
2358 gtk_render_arrow (context,
2365 gtk_style_context_restore (context);
2369 gtk_default_draw_diamond (GtkStyle *style,
2371 GtkStateType state_type,
2372 GtkShadowType shadow_type,
2374 const gchar *detail,
2382 GdkColor *outer_nw = NULL;
2383 GdkColor *outer_ne = NULL;
2384 GdkColor *outer_sw = NULL;
2385 GdkColor *outer_se = NULL;
2386 GdkColor *middle_nw = NULL;
2387 GdkColor *middle_ne = NULL;
2388 GdkColor *middle_sw = NULL;
2389 GdkColor *middle_se = NULL;
2390 GdkColor *inner_nw = NULL;
2391 GdkColor *inner_ne = NULL;
2392 GdkColor *inner_sw = NULL;
2393 GdkColor *inner_se = NULL;
2395 half_width = width / 2;
2396 half_height = height / 2;
2398 switch (shadow_type)
2401 inner_sw = inner_se = &style->bg[state_type];
2402 middle_sw = middle_se = &style->light[state_type];
2403 outer_sw = outer_se = &style->light[state_type];
2404 inner_nw = inner_ne = &style->black;
2405 middle_nw = middle_ne = &style->dark[state_type];
2406 outer_nw = outer_ne = &style->dark[state_type];
2409 case GTK_SHADOW_OUT:
2410 inner_sw = inner_se = &style->dark[state_type];
2411 middle_sw = middle_se = &style->dark[state_type];
2412 outer_sw = outer_se = &style->black;
2413 inner_nw = inner_ne = &style->bg[state_type];
2414 middle_nw = middle_ne = &style->light[state_type];
2415 outer_nw = outer_ne = &style->light[state_type];
2418 case GTK_SHADOW_ETCHED_IN:
2419 inner_sw = inner_se = &style->bg[state_type];
2420 middle_sw = middle_se = &style->dark[state_type];
2421 outer_sw = outer_se = &style->light[state_type];
2422 inner_nw = inner_ne = &style->bg[state_type];
2423 middle_nw = middle_ne = &style->light[state_type];
2424 outer_nw = outer_ne = &style->dark[state_type];
2427 case GTK_SHADOW_ETCHED_OUT:
2428 inner_sw = inner_se = &style->bg[state_type];
2429 middle_sw = middle_se = &style->light[state_type];
2430 outer_sw = outer_se = &style->dark[state_type];
2431 inner_nw = inner_ne = &style->bg[state_type];
2432 middle_nw = middle_ne = &style->dark[state_type];
2433 outer_nw = outer_ne = &style->light[state_type];
2443 _cairo_draw_line (cr, inner_sw,
2444 x + 2, y + half_height,
2445 x + half_width, y + height - 2);
2446 _cairo_draw_line (cr, inner_se,
2447 x + half_width, y + height - 2,
2448 x + width - 2, y + half_height);
2449 _cairo_draw_line (cr, middle_sw,
2450 x + 1, y + half_height,
2451 x + half_width, y + height - 1);
2452 _cairo_draw_line (cr, middle_se,
2453 x + half_width, y + height - 1,
2454 x + width - 1, y + half_height);
2455 _cairo_draw_line (cr, outer_sw,
2457 x + half_width, y + height);
2458 _cairo_draw_line (cr, outer_se,
2459 x + half_width, y + height,
2460 x + width, y + half_height);
2462 _cairo_draw_line (cr, inner_nw,
2463 x + 2, y + half_height,
2464 x + half_width, y + 2);
2465 _cairo_draw_line (cr, inner_ne,
2466 x + half_width, y + 2,
2467 x + width - 2, y + half_height);
2468 _cairo_draw_line (cr, middle_nw,
2469 x + 1, y + half_height,
2470 x + half_width, y + 1);
2471 _cairo_draw_line (cr, middle_ne,
2472 x + half_width, y + 1,
2473 x + width - 1, y + half_height);
2474 _cairo_draw_line (cr, outer_nw,
2477 _cairo_draw_line (cr, outer_ne,
2479 x + width, y + half_height);
2484 option_menu_get_props (GtkWidget *widget,
2485 GtkRequisition *indicator_size,
2486 GtkBorder *indicator_spacing)
2488 GtkRequisition *tmp_size = NULL;
2489 GtkBorder *tmp_spacing = NULL;
2493 *indicator_size = *tmp_size;
2494 gtk_requisition_free (tmp_size);
2497 *indicator_size = default_option_indicator_size;
2501 *indicator_spacing = *tmp_spacing;
2502 gtk_border_free (tmp_spacing);
2505 *indicator_spacing = default_option_indicator_spacing;
2509 background_is_solid (GtkStyle *style,
2512 if (style->background[type] == NULL)
2515 return cairo_pattern_get_type (style->background[type]) == CAIRO_PATTERN_TYPE_SOLID;
2519 gtk_default_draw_box (GtkStyle *style,
2521 GtkStateType state_type,
2522 GtkShadowType shadow_type,
2524 const gchar *detail,
2530 GtkStyleContext *context;
2531 GtkStylePrivate *priv;
2532 GtkStateFlags flags = 0;
2535 context = gtk_widget_get_style_context (widget);
2538 priv = GTK_STYLE_GET_PRIVATE (style);
2539 context = priv->context;
2542 gtk_style_context_save (context);
2545 transform_detail_string (detail, context);
2549 case GTK_STATE_ACTIVE:
2550 flags |= GTK_STATE_FLAG_ACTIVE;
2552 case GTK_STATE_PRELIGHT:
2553 flags |= GTK_STATE_FLAG_PRELIGHT;
2555 case GTK_STATE_SELECTED:
2556 flags |= GTK_STATE_FLAG_SELECTED;
2558 case GTK_STATE_INSENSITIVE:
2559 flags |= GTK_STATE_FLAG_INSENSITIVE;
2565 if (shadow_type == GTK_SHADOW_IN)
2566 flags |= GTK_STATE_FLAG_ACTIVE;
2568 gtk_style_context_set_state (context, flags);
2572 if (gtk_style_context_has_class (context, GTK_STYLE_CLASS_PROGRESSBAR))
2573 gtk_render_activity (context, cr, x, y, width, height);
2576 gtk_render_background (context, cr, x, y, width, height);
2577 gtk_render_frame (context, cr, x, y, width, height);
2581 gtk_style_context_restore (context);
2585 get_darkened (const GdkColor *color,
2588 GdkColor src = *color;
2589 GdkColor shaded = *color;
2591 while (darken_count)
2593 _gtk_style_shade (&src, &shaded, 0.93);
2598 return gdk_color_copy (&shaded);
2602 gtk_default_draw_flat_box (GtkStyle *style,
2604 GtkStateType state_type,
2605 GtkShadowType shadow_type,
2607 const gchar *detail,
2613 GtkStyleContext *context;
2614 GtkStylePrivate *priv;
2615 GtkStateFlags flags = 0;
2618 context = gtk_widget_get_style_context (widget);
2621 priv = GTK_STYLE_GET_PRIVATE (style);
2622 context = priv->context;
2625 gtk_style_context_save (context);
2628 transform_detail_string (detail, context);
2632 case GTK_STATE_PRELIGHT:
2633 flags |= GTK_STATE_FLAG_PRELIGHT;
2635 case GTK_STATE_SELECTED:
2636 flags |= GTK_STATE_FLAG_SELECTED;
2638 case GTK_STATE_INSENSITIVE:
2639 flags |= GTK_STATE_FLAG_INSENSITIVE;
2641 case GTK_STATE_ACTIVE:
2642 flags |= GTK_STATE_FLAG_ACTIVE;
2644 case GTK_STATE_FOCUSED:
2645 flags |= GTK_STATE_FLAG_FOCUSED;
2651 gtk_style_context_set_state (context, flags);
2655 gtk_render_background (context, cr,
2662 gtk_style_context_restore (context);
2666 gtk_default_draw_check (GtkStyle *style,
2668 GtkStateType state_type,
2669 GtkShadowType shadow_type,
2671 const gchar *detail,
2677 GtkStyleContext *context;
2678 GtkStylePrivate *priv;
2679 GtkStateFlags flags = 0;
2682 context = gtk_widget_get_style_context (widget);
2685 priv = GTK_STYLE_GET_PRIVATE (style);
2686 context = priv->context;
2689 gtk_style_context_save (context);
2692 transform_detail_string (detail, context);
2696 case GTK_STATE_PRELIGHT:
2697 flags |= GTK_STATE_FLAG_PRELIGHT;
2699 case GTK_STATE_SELECTED:
2700 flags |= GTK_STATE_FLAG_SELECTED;
2702 case GTK_STATE_INSENSITIVE:
2703 flags |= GTK_STATE_FLAG_INSENSITIVE;
2709 if (shadow_type == GTK_SHADOW_IN)
2710 flags |= GTK_STATE_FLAG_ACTIVE;
2711 else if (shadow_type == GTK_SHADOW_ETCHED_IN)
2712 flags |= GTK_STATE_FLAG_INCONSISTENT;
2714 gtk_style_context_set_state (context, flags);
2718 gtk_render_check (context,
2723 gtk_style_context_restore (context);
2727 gtk_default_draw_option (GtkStyle *style,
2729 GtkStateType state_type,
2730 GtkShadowType shadow_type,
2732 const gchar *detail,
2738 GtkStyleContext *context;
2739 GtkStylePrivate *priv;
2740 GtkStateFlags flags = 0;
2743 context = gtk_widget_get_style_context (widget);
2746 priv = GTK_STYLE_GET_PRIVATE (style);
2747 context = priv->context;
2750 gtk_style_context_save (context);
2753 transform_detail_string (detail, context);
2757 case GTK_STATE_PRELIGHT:
2758 flags |= GTK_STATE_FLAG_PRELIGHT;
2760 case GTK_STATE_SELECTED:
2761 flags |= GTK_STATE_FLAG_SELECTED;
2763 case GTK_STATE_INSENSITIVE:
2764 flags |= GTK_STATE_FLAG_INSENSITIVE;
2770 if (shadow_type == GTK_SHADOW_IN)
2771 flags |= GTK_STATE_FLAG_ACTIVE;
2772 else if (shadow_type == GTK_SHADOW_ETCHED_IN)
2773 flags |= GTK_STATE_FLAG_INCONSISTENT;
2775 gtk_style_context_set_state (context, flags);
2778 gtk_render_option (context, cr,
2785 gtk_style_context_restore (context);
2789 gtk_default_draw_tab (GtkStyle *style,
2791 GtkStateType state_type,
2792 GtkShadowType shadow_type,
2794 const gchar *detail,
2800 #define ARROW_SPACE 4
2802 GtkRequisition indicator_size;
2803 GtkBorder indicator_spacing;
2806 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
2808 indicator_size.width += (indicator_size.width % 2) - 1;
2809 arrow_height = indicator_size.width / 2 + 1;
2811 x += (width - indicator_size.width) / 2;
2812 y += (height - (2 * arrow_height + ARROW_SPACE)) / 2;
2814 if (state_type == GTK_STATE_INSENSITIVE)
2816 draw_arrow (cr, &style->white,
2817 GTK_ARROW_UP, x + 1, y + 1,
2818 indicator_size.width, arrow_height);
2820 draw_arrow (cr, &style->white,
2821 GTK_ARROW_DOWN, x + 1, y + arrow_height + ARROW_SPACE + 1,
2822 indicator_size.width, arrow_height);
2825 draw_arrow (cr, &style->fg[state_type],
2827 indicator_size.width, arrow_height);
2830 draw_arrow (cr, &style->fg[state_type],
2831 GTK_ARROW_DOWN, x, y + arrow_height + ARROW_SPACE,
2832 indicator_size.width, arrow_height);
2836 gtk_default_draw_shadow_gap (GtkStyle *style,
2838 GtkStateType state_type,
2839 GtkShadowType shadow_type,
2841 const gchar *detail,
2846 GtkPositionType gap_side,
2850 GtkStyleContext *context;
2851 GtkStylePrivate *priv;
2852 GtkStateFlags flags = 0;
2855 context = gtk_widget_get_style_context (widget);
2858 priv = GTK_STYLE_GET_PRIVATE (style);
2859 context = priv->context;
2862 gtk_style_context_save (context);
2865 transform_detail_string (detail, context);
2869 case GTK_STATE_ACTIVE:
2870 flags |= GTK_STATE_ACTIVE;
2872 case GTK_STATE_PRELIGHT:
2873 flags |= GTK_STATE_FLAG_PRELIGHT;
2875 case GTK_STATE_SELECTED:
2876 flags |= GTK_STATE_FLAG_SELECTED;
2878 case GTK_STATE_INSENSITIVE:
2879 flags |= GTK_STATE_FLAG_INSENSITIVE;
2885 gtk_style_context_set_state (context, flags);
2888 gtk_render_frame_gap (context, cr,
2895 (gdouble) gap_x + gap_width);
2898 gtk_style_context_restore (context);
2902 gtk_default_draw_box_gap (GtkStyle *style,
2904 GtkStateType state_type,
2905 GtkShadowType shadow_type,
2907 const gchar *detail,
2912 GtkPositionType gap_side,
2916 GtkStyleContext *context;
2917 GtkStylePrivate *priv;
2918 GtkStateFlags flags = 0;
2921 context = gtk_widget_get_style_context (widget);
2924 priv = GTK_STYLE_GET_PRIVATE (style);
2925 context = priv->context;
2928 gtk_style_context_save (context);
2931 transform_detail_string (detail, context);
2935 case GTK_STATE_ACTIVE:
2936 flags |= GTK_STATE_ACTIVE;
2938 case GTK_STATE_PRELIGHT:
2939 flags |= GTK_STATE_FLAG_PRELIGHT;
2941 case GTK_STATE_SELECTED:
2942 flags |= GTK_STATE_FLAG_SELECTED;
2944 case GTK_STATE_INSENSITIVE:
2945 flags |= GTK_STATE_FLAG_INSENSITIVE;
2951 gtk_style_context_set_state (context, flags);
2954 gtk_render_background (context, cr,
2960 gtk_render_frame_gap (context, cr,
2967 (gdouble) gap_x + gap_width);
2970 gtk_style_context_restore (context);
2974 gtk_default_draw_extension (GtkStyle *style,
2976 GtkStateType state_type,
2977 GtkShadowType shadow_type,
2979 const gchar *detail,
2984 GtkPositionType gap_side)
2986 GtkStyleContext *context;
2987 GtkStylePrivate *priv;
2988 GtkStateFlags flags = 0;
2991 context = gtk_widget_get_style_context (widget);
2994 priv = GTK_STYLE_GET_PRIVATE (style);
2995 context = priv->context;
2998 gtk_style_context_save (context);
3001 transform_detail_string (detail, context);
3005 case GTK_STATE_ACTIVE:
3006 flags |= GTK_STATE_ACTIVE;
3008 case GTK_STATE_PRELIGHT:
3009 flags |= GTK_STATE_FLAG_PRELIGHT;
3011 case GTK_STATE_SELECTED:
3012 flags |= GTK_STATE_FLAG_SELECTED;
3014 case GTK_STATE_INSENSITIVE:
3015 flags |= GTK_STATE_FLAG_INSENSITIVE;
3021 gtk_style_context_set_state (context, flags);
3025 gtk_render_extension (context, cr,
3033 gtk_style_context_restore (context);
3037 gtk_default_draw_focus (GtkStyle *style,
3039 GtkStateType state_type,
3041 const gchar *detail,
3047 GtkStyleContext *context;
3048 GtkStylePrivate *priv;
3051 context = gtk_widget_get_style_context (widget);
3054 priv = GTK_STYLE_GET_PRIVATE (style);
3055 context = priv->context;
3058 gtk_style_context_save (context);
3061 transform_detail_string (detail, context);
3065 gtk_render_focus (context, cr,
3072 gtk_style_context_restore (context);
3076 gtk_default_draw_slider (GtkStyle *style,
3078 GtkStateType state_type,
3079 GtkShadowType shadow_type,
3081 const gchar *detail,
3086 GtkOrientation orientation)
3088 GtkStyleContext *context;
3089 GtkStylePrivate *priv;
3090 GtkStateFlags flags = 0;
3093 context = gtk_widget_get_style_context (widget);
3096 priv = GTK_STYLE_GET_PRIVATE (style);
3097 context = priv->context;
3100 gtk_style_context_save (context);
3103 transform_detail_string (detail, context);
3107 case GTK_STATE_PRELIGHT:
3108 flags |= GTK_STATE_FLAG_PRELIGHT;
3110 case GTK_STATE_SELECTED:
3111 flags |= GTK_STATE_FLAG_SELECTED;
3113 case GTK_STATE_INSENSITIVE:
3114 flags |= GTK_STATE_FLAG_INSENSITIVE;
3120 gtk_style_context_set_state (context, flags);
3124 gtk_render_slider (context, cr, x, y, width, height, orientation);
3127 gtk_style_context_restore (context);
3131 draw_dot (cairo_t *cr,
3138 size = CLAMP (size, 2, 3);
3142 _cairo_draw_point (cr, light, x, y);
3143 _cairo_draw_point (cr, light, x+1, y+1);
3147 _cairo_draw_point (cr, light, x, y);
3148 _cairo_draw_point (cr, light, x+1, y);
3149 _cairo_draw_point (cr, light, x, y+1);
3150 _cairo_draw_point (cr, dark, x+1, y+2);
3151 _cairo_draw_point (cr, dark, x+2, y+1);
3152 _cairo_draw_point (cr, dark, x+2, y+2);
3157 gtk_default_draw_handle (GtkStyle *style,
3159 GtkStateType state_type,
3160 GtkShadowType shadow_type,
3162 const gchar *detail,
3167 GtkOrientation orientation)
3169 GtkStyleContext *context;
3170 GtkStylePrivate *priv;
3171 GtkStateFlags flags = 0;
3174 context = gtk_widget_get_style_context (widget);
3177 priv = GTK_STYLE_GET_PRIVATE (style);
3178 context = priv->context;
3181 gtk_style_context_save (context);
3184 transform_detail_string (detail, context);
3188 case GTK_STATE_PRELIGHT:
3189 flags |= GTK_STATE_FLAG_PRELIGHT;
3191 case GTK_STATE_SELECTED:
3192 flags |= GTK_STATE_FLAG_SELECTED;
3194 case GTK_STATE_INSENSITIVE:
3195 flags |= GTK_STATE_FLAG_INSENSITIVE;
3201 gtk_style_context_set_state (context, flags);
3205 gtk_render_handle (context, cr,
3212 gtk_style_context_restore (context);
3216 gtk_default_draw_expander (GtkStyle *style,
3218 GtkStateType state_type,
3220 const gchar *detail,
3223 GtkExpanderStyle expander_style)
3225 GtkStyleContext *context;
3226 GtkStylePrivate *priv;
3227 GtkStateFlags flags = 0;
3231 context = gtk_widget_get_style_context (widget);
3234 priv = GTK_STYLE_GET_PRIVATE (style);
3235 context = priv->context;
3238 gtk_style_context_save (context);
3241 transform_detail_string (detail, context);
3243 gtk_style_context_add_class (context, "expander");
3247 case GTK_STATE_PRELIGHT:
3248 flags |= GTK_STATE_FLAG_PRELIGHT;
3250 case GTK_STATE_SELECTED:
3251 flags |= GTK_STATE_FLAG_SELECTED;
3253 case GTK_STATE_INSENSITIVE:
3254 flags |= GTK_STATE_FLAG_INSENSITIVE;
3261 gtk_widget_class_find_style_property (GTK_WIDGET_GET_CLASS (widget),
3263 gtk_widget_style_get (widget, "expander-size", &size, NULL);
3267 if (expander_style == GTK_EXPANDER_EXPANDED)
3268 flags |= GTK_STATE_FLAG_ACTIVE;
3270 gtk_style_context_set_state (context, flags);
3274 gtk_render_expander (context, cr,
3275 (gdouble) x - (size / 2),
3276 (gdouble) y - (size / 2),
3281 gtk_style_context_restore (context);
3285 gtk_default_draw_layout (GtkStyle *style,
3287 GtkStateType state_type,
3290 const gchar *detail,
3293 PangoLayout *layout)
3295 GtkStyleContext *context;
3296 GtkStylePrivate *priv;
3297 GtkStateFlags flags = 0;
3300 context = gtk_widget_get_style_context (widget);
3303 priv = GTK_STYLE_GET_PRIVATE (style);
3304 context = priv->context;
3307 gtk_style_context_save (context);
3310 transform_detail_string (detail, context);
3314 case GTK_STATE_PRELIGHT:
3315 flags |= GTK_STATE_FLAG_PRELIGHT;
3317 case GTK_STATE_SELECTED:
3318 flags |= GTK_STATE_FLAG_SELECTED;
3320 case GTK_STATE_INSENSITIVE:
3321 flags |= GTK_STATE_FLAG_INSENSITIVE;
3327 gtk_style_context_set_state (context, flags);
3331 gtk_render_layout (context, cr,
3337 gtk_style_context_restore (context);
3341 gtk_default_draw_resize_grip (GtkStyle *style,
3343 GtkStateType state_type,
3345 const gchar *detail,
3352 GtkStyleContext *context;
3353 GtkStylePrivate *priv;
3354 GtkStateFlags flags = 0;
3355 GtkJunctionSides sides = 0;
3358 context = gtk_widget_get_style_context (widget);
3361 priv = GTK_STYLE_GET_PRIVATE (style);
3362 context = priv->context;
3365 gtk_style_context_save (context);
3368 transform_detail_string (detail, context);
3370 gtk_style_context_add_class (context, "grip");
3374 case GTK_STATE_PRELIGHT:
3375 flags |= GTK_STATE_FLAG_PRELIGHT;
3377 case GTK_STATE_SELECTED:
3378 flags |= GTK_STATE_FLAG_SELECTED;
3380 case GTK_STATE_INSENSITIVE:
3381 flags |= GTK_STATE_FLAG_INSENSITIVE;
3387 gtk_style_context_set_state (context, flags);
3391 case GDK_WINDOW_EDGE_NORTH_WEST:
3392 sides = GTK_JUNCTION_CORNER_TOPLEFT;
3394 case GDK_WINDOW_EDGE_NORTH:
3395 sides = GTK_JUNCTION_TOP;
3397 case GDK_WINDOW_EDGE_NORTH_EAST:
3398 sides = GTK_JUNCTION_CORNER_TOPRIGHT;
3400 case GDK_WINDOW_EDGE_WEST:
3401 sides = GTK_JUNCTION_LEFT;
3403 case GDK_WINDOW_EDGE_EAST:
3404 sides = GTK_JUNCTION_RIGHT;
3406 case GDK_WINDOW_EDGE_SOUTH_WEST:
3407 sides = GTK_JUNCTION_CORNER_BOTTOMLEFT;
3409 case GDK_WINDOW_EDGE_SOUTH:
3410 sides = GTK_JUNCTION_BOTTOM;
3412 case GDK_WINDOW_EDGE_SOUTH_EAST:
3413 sides = GTK_JUNCTION_CORNER_BOTTOMRIGHT;
3417 gtk_style_context_set_junction_sides (context, sides);
3421 gtk_render_handle (context, cr,
3428 gtk_style_context_restore (context);
3432 gtk_default_draw_spinner (GtkStyle *style,
3434 GtkStateType state_type,
3436 const gchar *detail,
3451 gtk_style_get (style, GTK_TYPE_SPINNER,
3452 "num-steps", &num_steps,
3454 real_step = step % num_steps;
3456 /* set a clip region for the expose event */
3457 cairo_rectangle (cr, x, y, width, height);
3460 cairo_translate (cr, x, y);
3462 /* draw clip region */
3463 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
3465 color = &style->fg[state_type];
3468 radius = MIN (width / 2, height / 2);
3469 half = num_steps / 2;
3471 for (i = 0; i < num_steps; i++)
3473 gint inset = 0.7 * radius;
3475 /* transparency is a function of time and intial value */
3476 gdouble t = (gdouble) ((i + num_steps - real_step)
3477 % num_steps) / num_steps;
3481 cairo_set_source_rgba (cr,
3482 color->red / 65535.,
3483 color->green / 65535.,
3484 color->blue / 65535.,
3487 cairo_set_line_width (cr, 2.0);
3489 dx + (radius - inset) * cos (i * G_PI / half),
3490 dy + (radius - inset) * sin (i * G_PI / half));
3492 dx + radius * cos (i * G_PI / half),
3493 dy + radius * sin (i * G_PI / half));
3501 _gtk_style_shade (const GdkColor *a,
3509 red = (gdouble) a->red / 65535.0;
3510 green = (gdouble) a->green / 65535.0;
3511 blue = (gdouble) a->blue / 65535.0;
3513 rgb_to_hls (&red, &green, &blue);
3518 else if (green < 0.0)
3524 else if (blue < 0.0)
3527 hls_to_rgb (&red, &green, &blue);
3529 b->red = red * 65535.0;
3530 b->green = green * 65535.0;
3531 b->blue = blue * 65535.0;
3535 rgb_to_hls (gdouble *r,
3576 l = (max + min) / 2;
3583 s = (max - min) / (max + min);
3585 s = (max - min) / (2 - max - min);
3589 h = (green - blue) / delta;
3590 else if (green == max)
3591 h = 2 + (blue - red) / delta;
3592 else if (blue == max)
3593 h = 4 + (red - green) / delta;
3606 hls_to_rgb (gdouble *h,
3619 if (lightness <= 0.5)
3620 m2 = lightness * (1 + saturation);
3622 m2 = lightness + saturation - lightness * saturation;
3623 m1 = 2 * lightness - m2;
3625 if (saturation == 0)
3640 r = m1 + (m2 - m1) * hue / 60;
3644 r = m1 + (m2 - m1) * (240 - hue) / 60;
3655 g = m1 + (m2 - m1) * hue / 60;
3659 g = m1 + (m2 - m1) * (240 - hue) / 60;
3670 b = m1 + (m2 - m1) * hue / 60;
3674 b = m1 + (m2 - m1) * (240 - hue) / 60;
3687 * @style: a #GtkStyle
3689 * @state_type: a state
3690 * @widget: (allow-none): the widget
3691 * @detail: (allow-none): a style detail
3692 * @x1: the starting x coordinate
3693 * @x2: the ending x coordinate
3694 * @y: the y coordinate
3696 * Draws a horizontal line from (@x1, @y) to (@x2, @y) in @cr
3697 * using the given style and state.
3699 * Deprecated:3.0: Use gtk_render_line() instead
3702 gtk_paint_hline (GtkStyle *style,
3704 GtkStateType state_type,
3706 const gchar *detail,
3711 g_return_if_fail (GTK_IS_STYLE (style));
3712 g_return_if_fail (cr != NULL);
3713 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
3717 GTK_STYLE_GET_CLASS (style)->draw_hline (style, cr, state_type,
3726 * @style: a #GtkStyle
3728 * @state_type: a state
3729 * @widget: (allow-none): the widget
3730 * @detail: (allow-none): a style detail
3731 * @y1_: the starting y coordinate
3732 * @y2_: the ending y coordinate
3733 * @x: the x coordinate
3735 * Draws a vertical line from (@x, @y1_) to (@x, @y2_) in @cr
3736 * using the given style and state.
3738 * Deprecated:3.0: Use gtk_render_line() instead
3741 gtk_paint_vline (GtkStyle *style,
3743 GtkStateType state_type,
3745 const gchar *detail,
3750 g_return_if_fail (GTK_IS_STYLE (style));
3751 g_return_if_fail (cr != NULL);
3752 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
3756 GTK_STYLE_GET_CLASS (style)->draw_vline (style, cr, state_type,
3765 * @style: a #GtkStyle
3767 * @state_type: a state
3768 * @shadow_type: type of shadow to draw
3769 * @widget: (allow-none): the widget
3770 * @detail: (allow-none): a style detail
3771 * @x: x origin of the rectangle
3772 * @y: y origin of the rectangle
3773 * @width: width of the rectangle
3774 * @height: width of the rectangle
3776 * Draws a shadow around the given rectangle in @cr
3777 * using the given style and state and shadow type.
3779 * Deprecated:3.0: Use gtk_render_frame() instead
3782 gtk_paint_shadow (GtkStyle *style,
3784 GtkStateType state_type,
3785 GtkShadowType shadow_type,
3787 const gchar *detail,
3793 g_return_if_fail (GTK_IS_STYLE (style));
3794 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
3795 g_return_if_fail (cr != NULL);
3796 g_return_if_fail (width >= 0);
3797 g_return_if_fail (height >= 0);
3801 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, cr, state_type, shadow_type,
3803 x, y, width, height);
3810 * @style: a #GtkStyle
3812 * @state_type: a state
3813 * @shadow_type: the type of shadow to draw
3814 * @widget: (allow-none): the widget
3815 * @detail: (allow-none): a style detail
3816 * @arrow_type: the type of arrow to draw
3817 * @fill: %TRUE if the arrow tip should be filled
3818 * @x: x origin of the rectangle to draw the arrow in
3819 * @y: y origin of the rectangle to draw the arrow in
3820 * @width: width of the rectangle to draw the arrow in
3821 * @height: height of the rectangle to draw the arrow in
3823 * Draws an arrow in the given rectangle on @cr using the given
3824 * parameters. @arrow_type determines the direction of the arrow.
3826 * Deprecated:3.0: Use gtk_render_arrow() instead
3829 gtk_paint_arrow (GtkStyle *style,
3831 GtkStateType state_type,
3832 GtkShadowType shadow_type,
3834 const gchar *detail,
3835 GtkArrowType arrow_type,
3842 g_return_if_fail (GTK_IS_STYLE (style));
3843 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
3844 g_return_if_fail (cr != NULL);
3845 g_return_if_fail (width >= 0);
3846 g_return_if_fail (height >= 0);
3850 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, cr, state_type, shadow_type,
3852 arrow_type, fill, x, y, width, height);
3858 * gtk_paint_diamond:
3859 * @style: a #GtkStyle
3861 * @state_type: a state
3862 * @shadow_type: the type of shadow to draw
3863 * @widget: (allow-none): the widget
3864 * @detail: (allow-none): a style detail
3865 * @x: x origin of the rectangle to draw the diamond in
3866 * @y: y origin of the rectangle to draw the diamond in
3867 * @width: width of the rectangle to draw the diamond in
3868 * @height: height of the rectangle to draw the diamond in
3870 * Draws a diamond in the given rectangle on @window using the given
3873 * Deprecated:3.0: Use cairo instead
3876 gtk_paint_diamond (GtkStyle *style,
3878 GtkStateType state_type,
3879 GtkShadowType shadow_type,
3881 const gchar *detail,
3887 g_return_if_fail (GTK_IS_STYLE (style));
3888 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
3889 g_return_if_fail (cr != NULL);
3890 g_return_if_fail (width >= 0);
3891 g_return_if_fail (height >= 0);
3895 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, cr, state_type, shadow_type,
3897 x, y, width, height);
3904 * @style: a #GtkStyle
3906 * @state_type: a state
3907 * @shadow_type: the type of shadow to draw
3908 * @widget: (allow-none): the widget
3909 * @detail: (allow-none): a style detail
3910 * @x: x origin of the box
3911 * @y: y origin of the box
3912 * @width: the width of the box
3913 * @height: the height of the box
3915 * Draws a box on @cr with the given parameters.
3917 * Deprecated:3.0: Use gtk_render_frame() and gtk_render_background() instead
3920 gtk_paint_box (GtkStyle *style,
3922 GtkStateType state_type,
3923 GtkShadowType shadow_type,
3925 const gchar *detail,
3931 g_return_if_fail (GTK_IS_STYLE (style));
3932 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
3933 g_return_if_fail (cr != NULL);
3937 GTK_STYLE_GET_CLASS (style)->draw_box (style, cr, state_type, shadow_type,
3939 x, y, width, height);
3945 * gtk_paint_flat_box:
3946 * @style: a #GtkStyle
3948 * @state_type: a state
3949 * @shadow_type: the type of shadow to draw
3950 * @area: (allow-none): clip rectangle, or %NULL if the
3951 * output should not be clipped
3952 * @widget: (allow-none): the widget
3953 * @detail: (allow-none): a style detail
3954 * @x: x origin of the box
3955 * @y: y origin of the box
3956 * @width: the width of the box
3957 * @height: the height of the box
3959 * Draws a flat box on @cr with the given parameters.
3961 * Deprecated:3.0: Use gtk_render_frame() and gtk_render_background() instead
3964 gtk_paint_flat_box (GtkStyle *style,
3966 GtkStateType state_type,
3967 GtkShadowType shadow_type,
3969 const gchar *detail,
3975 g_return_if_fail (GTK_IS_STYLE (style));
3976 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
3977 g_return_if_fail (cr != NULL);
3978 g_return_if_fail (width >= 0);
3979 g_return_if_fail (height >= 0);
3983 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, cr, state_type, shadow_type,
3985 x, y, width, height);
3992 * @style: a #GtkStyle
3994 * @state_type: a state
3995 * @shadow_type: the type of shadow to draw
3996 * @widget: (allow-none): the widget
3997 * @detail: (allow-none): a style detail
3998 * @x: x origin of the rectangle to draw the check in
3999 * @y: y origin of the rectangle to draw the check in
4000 * @width: the width of the rectangle to draw the check in
4001 * @height: the height of the rectangle to draw the check in
4003 * Draws a check button indicator in the given rectangle on @cr with
4004 * the given parameters.
4006 * Deprecated:3.0: Use gtk_render_check() instead
4009 gtk_paint_check (GtkStyle *style,
4011 GtkStateType state_type,
4012 GtkShadowType shadow_type,
4014 const gchar *detail,
4020 g_return_if_fail (GTK_IS_STYLE (style));
4021 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
4022 g_return_if_fail (cr != NULL);
4026 GTK_STYLE_GET_CLASS (style)->draw_check (style, cr, state_type, shadow_type,
4028 x, y, width, height);
4035 * @style: a #GtkStyle
4037 * @state_type: a state
4038 * @shadow_type: the type of shadow to draw
4039 * @widget: (allow-none): the widget
4040 * @detail: (allow-none): a style detail
4041 * @x: x origin of the rectangle to draw the option in
4042 * @y: y origin of the rectangle to draw the option in
4043 * @width: the width of the rectangle to draw the option in
4044 * @height: the height of the rectangle to draw the option in
4046 * Draws a radio button indicator in the given rectangle on @cr with
4047 * the given parameters.
4049 * Deprecated:3.0: Use gtk_render_option() instead
4052 gtk_paint_option (GtkStyle *style,
4054 GtkStateType state_type,
4055 GtkShadowType shadow_type,
4057 const gchar *detail,
4063 g_return_if_fail (GTK_IS_STYLE (style));
4064 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
4065 g_return_if_fail (cr != NULL);
4069 GTK_STYLE_GET_CLASS (style)->draw_option (style, cr, state_type, shadow_type,
4071 x, y, width, height);
4078 * @style: a #GtkStyle
4080 * @state_type: a state
4081 * @shadow_type: the type of shadow to draw
4082 * @widget: (allow-none): the widget
4083 * @detail: (allow-none): a style detail
4084 * @x: x origin of the rectangle to draw the tab in
4085 * @y: y origin of the rectangle to draw the tab in
4086 * @width: the width of the rectangle to draw the tab in
4087 * @height: the height of the rectangle to draw the tab in
4089 * Draws an option menu tab (i.e. the up and down pointing arrows)
4090 * in the given rectangle on @cr using the given parameters.
4092 * Deprecated:3.0: Use cairo instead
4095 gtk_paint_tab (GtkStyle *style,
4097 GtkStateType state_type,
4098 GtkShadowType shadow_type,
4100 const gchar *detail,
4106 g_return_if_fail (GTK_IS_STYLE (style));
4107 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
4108 g_return_if_fail (cr != NULL);
4112 GTK_STYLE_GET_CLASS (style)->draw_tab (style, cr, state_type, shadow_type,
4114 x, y, width, height);
4120 * gtk_paint_shadow_gap:
4121 * @style: a #GtkStyle
4123 * @state_type: a state
4124 * @shadow_type: type of shadow to draw
4125 * @widget: (allow-none): the widget
4126 * @detail: (allow-none): a style detail
4127 * @x: x origin of the rectangle
4128 * @y: y origin of the rectangle
4129 * @width: width of the rectangle
4130 * @height: width of the rectangle
4131 * @gap_side: side in which to leave the gap
4132 * @gap_x: starting position of the gap
4133 * @gap_width: width of the gap
4135 * Draws a shadow around the given rectangle in @cr
4136 * using the given style and state and shadow type, leaving a
4139 * Deprecated:3.0: Use gtk_render_frame_gap() instead
4142 gtk_paint_shadow_gap (GtkStyle *style,
4144 GtkStateType state_type,
4145 GtkShadowType shadow_type,
4147 const gchar *detail,
4152 GtkPositionType gap_side,
4156 g_return_if_fail (GTK_IS_STYLE (style));
4157 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
4158 g_return_if_fail (cr != NULL);
4159 g_return_if_fail (width >= 0);
4160 g_return_if_fail (height >= 0);
4164 GTK_STYLE_GET_CLASS (style)->draw_shadow_gap (style, cr, state_type, shadow_type,
4166 x, y, width, height, gap_side, gap_x, gap_width);
4172 * gtk_paint_box_gap:
4173 * @style: a #GtkStyle
4175 * @state_type: a state
4176 * @shadow_type: type of shadow to draw
4177 * @widget: (allow-none): the widget
4178 * @detail: (allow-none): a style detail
4179 * @x: x origin of the rectangle
4180 * @y: y origin of the rectangle
4181 * @width: width of the rectangle
4182 * @height: width of the rectangle
4183 * @gap_side: side in which to leave the gap
4184 * @gap_x: starting position of the gap
4185 * @gap_width: width of the gap
4187 * Draws a box in @cr using the given style and state and shadow type,
4188 * leaving a gap in one side.
4190 * Deprecated:3.0: Use gtk_render_frame_gap() instead
4193 gtk_paint_box_gap (GtkStyle *style,
4195 GtkStateType state_type,
4196 GtkShadowType shadow_type,
4198 const gchar *detail,
4203 GtkPositionType gap_side,
4207 g_return_if_fail (GTK_IS_STYLE (style));
4208 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
4209 g_return_if_fail (cr != NULL);
4210 g_return_if_fail (width >= 0);
4211 g_return_if_fail (height >= 0);
4215 GTK_STYLE_GET_CLASS (style)->draw_box_gap (style, cr, state_type, shadow_type,
4217 x, y, width, height, gap_side, gap_x, gap_width);
4223 * gtk_paint_extension:
4224 * @style: a #GtkStyle
4226 * @state_type: a state
4227 * @shadow_type: type of shadow to draw
4228 * @widget: (allow-none): the widget
4229 * @detail: (allow-none): a style detail
4230 * @x: x origin of the extension
4231 * @y: y origin of the extension
4232 * @width: width of the extension
4233 * @height: width of the extension
4234 * @gap_side: the side on to which the extension is attached
4236 * Draws an extension, i.e. a notebook tab.
4238 * Deprecated:3.0: Use gtk_render_extension() instead
4241 gtk_paint_extension (GtkStyle *style,
4243 GtkStateType state_type,
4244 GtkShadowType shadow_type,
4246 const gchar *detail,
4251 GtkPositionType gap_side)
4253 g_return_if_fail (GTK_IS_STYLE (style));
4254 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
4255 g_return_if_fail (cr != NULL);
4256 g_return_if_fail (width >= 0);
4257 g_return_if_fail (height >= 0);
4261 GTK_STYLE_GET_CLASS (style)->draw_extension (style, cr, state_type, shadow_type,
4263 x, y, width, height, gap_side);
4270 * @style: a #GtkStyle
4272 * @state_type: a state
4273 * @widget: (allow-none): the widget
4274 * @detail: (allow-none): a style detail
4275 * @x: the x origin of the rectangle around which to draw a focus indicator
4276 * @y: the y origin of the rectangle around which to draw a focus indicator
4277 * @width: the width of the rectangle around which to draw a focus indicator
4278 * @height: the height of the rectangle around which to draw a focus indicator
4280 * Draws a focus indicator around the given rectangle on @cr using the
4283 * Deprecated:3.0: Use gtk_render_focus() instead
4286 gtk_paint_focus (GtkStyle *style,
4288 GtkStateType state_type,
4290 const gchar *detail,
4296 g_return_if_fail (GTK_IS_STYLE (style));
4297 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
4298 g_return_if_fail (cr != NULL);
4299 g_return_if_fail (width >= 0);
4300 g_return_if_fail (height >= 0);
4304 GTK_STYLE_GET_CLASS (style)->draw_focus (style, cr, state_type,
4306 x, y, width, height);
4313 * @style: a #GtkStyle
4315 * @state_type: a state
4316 * @shadow_type: a shadow
4317 * @widget: (allow-none): the widget
4318 * @detail: (allow-none): a style detail
4319 * @x: the x origin of the rectangle in which to draw a slider
4320 * @y: the y origin of the rectangle in which to draw a slider
4321 * @width: the width of the rectangle in which to draw a slider
4322 * @height: the height of the rectangle in which to draw a slider
4323 * @orientation: the orientation to be used
4325 * Draws a slider in the given rectangle on @cr using the
4326 * given style and orientation.
4328 * Deprecated:3.0: Use gtk_render_slider() instead
4331 gtk_paint_slider (GtkStyle *style,
4333 GtkStateType state_type,
4334 GtkShadowType shadow_type,
4336 const gchar *detail,
4341 GtkOrientation orientation)
4343 g_return_if_fail (GTK_IS_STYLE (style));
4344 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
4345 g_return_if_fail (cr != NULL);
4346 g_return_if_fail (width >= 0);
4347 g_return_if_fail (height >= 0);
4351 GTK_STYLE_GET_CLASS (style)->draw_slider (style, cr, state_type, shadow_type,
4353 x, y, width, height, orientation);
4360 * @style: a #GtkStyle
4362 * @state_type: a state
4363 * @shadow_type: type of shadow to draw
4364 * @widget: (allow-none): the widget
4365 * @detail: (allow-none): a style detail
4366 * @x: x origin of the handle
4367 * @y: y origin of the handle
4368 * @width: with of the handle
4369 * @height: height of the handle
4370 * @orientation: the orientation of the handle
4372 * Draws a handle as used in #GtkHandleBox and #GtkPaned.
4374 * Deprecated:3.0: Use gtk_render_handle() instead
4377 gtk_paint_handle (GtkStyle *style,
4379 GtkStateType state_type,
4380 GtkShadowType shadow_type,
4382 const gchar *detail,
4387 GtkOrientation orientation)
4389 g_return_if_fail (GTK_IS_STYLE (style));
4390 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
4391 g_return_if_fail (cr != NULL);
4392 g_return_if_fail (width >= 0);
4393 g_return_if_fail (height >= 0);
4397 GTK_STYLE_GET_CLASS (style)->draw_handle (style, cr, state_type, shadow_type,
4399 x, y, width, height, orientation);
4405 * gtk_paint_expander:
4406 * @style: a #GtkStyle
4408 * @state_type: a state
4409 * @widget: (allow-none): the widget
4410 * @detail: (allow-none): a style detail
4411 * @x: the x position to draw the expander at
4412 * @y: the y position to draw the expander at
4413 * @expander_style: the style to draw the expander in; determines
4414 * whether the expander is collapsed, expanded, or in an
4415 * intermediate state.
4417 * Draws an expander as used in #GtkTreeView. @x and @y specify the
4418 * center the expander. The size of the expander is determined by the
4419 * "expander-size" style property of @widget. (If widget is not
4420 * specified or doesn't have an "expander-size" property, an
4421 * unspecified default size will be used, since the caller doesn't
4422 * have sufficient information to position the expander, this is
4423 * likely not useful.) The expander is expander_size pixels tall
4424 * in the collapsed position and expander_size pixels wide in the
4425 * expanded position.
4427 * Deprecated:3.0: Use gtk_render_expander() instead
4430 gtk_paint_expander (GtkStyle *style,
4432 GtkStateType state_type,
4434 const gchar *detail,
4437 GtkExpanderStyle expander_style)
4439 g_return_if_fail (GTK_IS_STYLE (style));
4440 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
4441 g_return_if_fail (cr != NULL);
4445 GTK_STYLE_GET_CLASS (style)->draw_expander (style, cr, state_type,
4447 x, y, expander_style);
4454 * @style: a #GtkStyle
4456 * @state_type: a state
4457 * @use_text: whether to use the text or foreground
4458 * graphics context of @style
4459 * @widget: (allow-none): the widget
4460 * @detail: (allow-none): a style detail
4463 * @layout: the layout to draw
4465 * Draws a layout on @cr using the given parameters.
4467 * Deprecated:3.0: Use gtk_render_layout() instead
4470 gtk_paint_layout (GtkStyle *style,
4472 GtkStateType state_type,
4475 const gchar *detail,
4478 PangoLayout *layout)
4480 g_return_if_fail (GTK_IS_STYLE (style));
4481 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
4482 g_return_if_fail (cr != NULL);
4486 GTK_STYLE_GET_CLASS (style)->draw_layout (style, cr, state_type, use_text,
4494 * gtk_paint_resize_grip:
4495 * @style: a #GtkStyle
4497 * @state_type: a state
4498 * @widget: (allow-none): the widget
4499 * @detail: (allow-none): a style detail
4500 * @edge: the edge in which to draw the resize grip
4501 * @x: the x origin of the rectangle in which to draw the resize grip
4502 * @y: the y origin of the rectangle in which to draw the resize grip
4503 * @width: the width of the rectangle in which to draw the resize grip
4504 * @height: the height of the rectangle in which to draw the resize grip
4506 * Draws a resize grip in the given rectangle on @cr using the given
4509 * Deprecated:3.0: Use gtk_render_handle() instead
4512 gtk_paint_resize_grip (GtkStyle *style,
4514 GtkStateType state_type,
4516 const gchar *detail,
4523 g_return_if_fail (GTK_IS_STYLE (style));
4524 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
4525 g_return_if_fail (cr != NULL);
4529 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, cr, state_type,
4531 edge, x, y, width, height);
4536 * gtk_paint_spinner:
4537 * @style: a #GtkStyle
4539 * @state_type: a state
4540 * @widget: (allow-none): the widget (may be %NULL)
4541 * @detail: (allow-none): a style detail (may be %NULL)
4542 * @step: the nth step, a value between 0 and #GtkSpinner:num-steps
4543 * @x: the x origin of the rectangle in which to draw the spinner
4544 * @y: the y origin of the rectangle in which to draw the spinner
4545 * @width: the width of the rectangle in which to draw the spinner
4546 * @height: the height of the rectangle in which to draw the spinner
4548 * Draws a spinner on @window using the given parameters.
4550 * Deprecated:3.0: Use gtk_render_activity() instead
4553 gtk_paint_spinner (GtkStyle *style,
4555 GtkStateType state_type,
4557 const gchar *detail,
4564 g_return_if_fail (GTK_IS_STYLE (style));
4565 g_return_if_fail (cr != NULL);
4566 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_spinner != NULL);
4570 GTK_STYLE_GET_CLASS (style)->draw_spinner (style, cr, state_type,
4572 step, x, y, width, height);
4580 * Allocates a new #GtkBorder structure and initializes its elements to zero.
4582 * Returns: a new empty #GtkBorder. The newly allocated #GtkBorder should be
4583 * freed with gtk_border_free()
4588 gtk_border_new (void)
4590 return g_slice_new0 (GtkBorder);
4595 * @border_: a #GtkBorder.
4596 * @returns: a copy of @border_.
4598 * Copies a #GtkBorder structure.
4601 gtk_border_copy (const GtkBorder *border)
4603 g_return_val_if_fail (border != NULL, NULL);
4605 return g_slice_dup (GtkBorder, border);
4610 * @border_: a #GtkBorder.
4612 * Frees a #GtkBorder structure.
4615 gtk_border_free (GtkBorder *border)
4617 g_slice_free (GtkBorder, border);
4620 G_DEFINE_BOXED_TYPE (GtkBorder, gtk_border,
4624 typedef struct _CursorInfo CursorInfo;
4634 style_unrealize_cursors (GtkStyle *style)
4638 cursor_info = g_object_get_data (G_OBJECT (style), "gtk-style-cursor-info");
4641 g_free (cursor_info);
4642 g_object_set_data (G_OBJECT (style), I_("gtk-style-cursor-info"), NULL);
4646 static const GdkColor *
4647 get_insertion_cursor_color (GtkWidget *widget,
4648 gboolean is_primary)
4650 CursorInfo *cursor_info;
4652 GdkColor *cursor_color;
4654 style = gtk_widget_get_style (widget);
4656 cursor_info = g_object_get_data (G_OBJECT (style), "gtk-style-cursor-info");
4659 cursor_info = g_new0 (CursorInfo, 1);
4660 g_object_set_data (G_OBJECT (style), I_("gtk-style-cursor-info"), cursor_info);
4661 cursor_info->for_type = G_TYPE_INVALID;
4664 /* We have to keep track of the type because gtk_widget_style_get()
4665 * can return different results when called on the same property and
4666 * same style but for different widgets. :-(. That is,
4667 * GtkEntry::cursor-color = "red" in a style will modify the cursor
4668 * color for entries but not for text view.
4670 if (cursor_info->for_type != G_OBJECT_TYPE (widget))
4672 cursor_info->for_type = G_OBJECT_TYPE (widget);
4674 /* Cursors in text widgets are drawn only in NORMAL state,
4675 * so we can use text[GTK_STATE_NORMAL] as text color here */
4676 gtk_widget_style_get (widget, "cursor-color", &cursor_color, NULL);
4679 cursor_info->primary = *cursor_color;
4680 gdk_color_free (cursor_color);
4684 cursor_info->primary = style->text[GTK_STATE_NORMAL];
4687 gtk_widget_style_get (widget, "secondary-cursor-color", &cursor_color, NULL);
4690 cursor_info->secondary = *cursor_color;
4691 gdk_color_free (cursor_color);
4695 /* text_aa is the average of text and base colors,
4696 * in usual black-on-white case it's grey. */
4697 cursor_info->secondary = style->text_aa[GTK_STATE_NORMAL];
4702 return &cursor_info->primary;
4704 return &cursor_info->secondary;
4708 _gtk_widget_get_cursor_color (GtkWidget *widget,
4711 GdkColor *style_color;
4713 g_return_if_fail (GTK_IS_WIDGET (widget));
4714 g_return_if_fail (color != NULL);
4716 gtk_widget_style_get (widget, "cursor-color", &style_color, NULL);
4720 *color = *style_color;
4721 gdk_color_free (style_color);
4724 *color = gtk_widget_get_style (widget)->text[GTK_STATE_NORMAL];
4728 * gtk_draw_insertion_cursor:
4729 * @widget: a #GtkWidget
4730 * @cr: cairo context to draw to
4731 * @location: location where to draw the cursor (@location->width is ignored)
4732 * @is_primary: if the cursor should be the primary cursor color.
4733 * @direction: whether the cursor is left-to-right or
4734 * right-to-left. Should never be #GTK_TEXT_DIR_NONE
4735 * @draw_arrow: %TRUE to draw a directional arrow on the
4736 * cursor. Should be %FALSE unless the cursor is split.
4738 * Draws a text caret on @cr at @location. This is not a style function
4739 * but merely a convenience function for drawing the standard cursor shape.
4744 gtk_draw_insertion_cursor (GtkWidget *widget,
4746 const GdkRectangle *location,
4747 gboolean is_primary,
4748 GtkTextDirection direction,
4749 gboolean draw_arrow)
4754 gfloat cursor_aspect_ratio;
4757 g_return_if_fail (GTK_IS_WIDGET (widget));
4758 g_return_if_fail (cr != NULL);
4759 g_return_if_fail (location != NULL);
4760 g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
4762 gdk_cairo_set_source_color (cr, get_insertion_cursor_color (widget, is_primary));
4764 /* When changing the shape or size of the cursor here,
4765 * propagate the changes to gtktextview.c:text_window_invalidate_cursors().
4768 gtk_widget_style_get (widget, "cursor-aspect-ratio", &cursor_aspect_ratio, NULL);
4770 stem_width = location->height * cursor_aspect_ratio + 1;
4771 arrow_width = stem_width + 1;
4773 /* put (stem_width % 2) on the proper side of the cursor */
4774 if (direction == GTK_TEXT_DIR_LTR)
4775 offset = stem_width / 2;
4777 offset = stem_width - stem_width / 2;
4779 cairo_rectangle (cr,
4780 location->x - offset, location->y,
4781 stem_width, location->height);
4786 if (direction == GTK_TEXT_DIR_RTL)
4788 x = location->x - offset - 1;
4789 y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
4791 cairo_move_to (cr, x, y + 1);
4792 cairo_line_to (cr, x - arrow_width, y + arrow_width);
4793 cairo_line_to (cr, x, y + 2 * arrow_width);
4796 else if (direction == GTK_TEXT_DIR_LTR)
4798 x = location->x + stem_width - offset;
4799 y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
4801 cairo_move_to (cr, x, y + 1);
4802 cairo_line_to (cr, x + arrow_width, y + arrow_width);
4803 cairo_line_to (cr, x, y + 2 * arrow_width);