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/.
32 #include "gtkmarshalers.h"
33 #undef GTK_DISABLE_DEPRECATED
34 #include "gtkoptionmenu.h"
36 #include "gtkspinbutton.h"
38 #include "gtkwidget.h"
39 #include "gtkthemes.h"
40 #include "gtkiconfactory.h"
41 #include "gtksettings.h" /* _gtk_settings_parse_convert() */
45 #define LIGHTNESS_MULT 1.3
46 #define DARKNESS_MULT 0.7
48 /* --- typedefs & structures --- */
55 #define GTK_STYLE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_STYLE, GtkStylePrivate))
57 typedef struct _GtkStylePrivate GtkStylePrivate;
59 struct _GtkStylePrivate {
63 /* --- prototypes --- */
64 static void gtk_style_finalize (GObject *object);
65 static void gtk_style_realize (GtkStyle *style,
66 GdkColormap *colormap);
67 static void gtk_style_real_realize (GtkStyle *style);
68 static void gtk_style_real_unrealize (GtkStyle *style);
69 static void gtk_style_real_copy (GtkStyle *style,
71 static void gtk_style_real_set_background (GtkStyle *style,
73 GtkStateType state_type);
74 static GtkStyle *gtk_style_real_clone (GtkStyle *style);
75 static void gtk_style_real_init_from_rc (GtkStyle *style,
76 GtkRcStyle *rc_style);
77 static GdkPixbuf *gtk_default_render_icon (GtkStyle *style,
78 const GtkIconSource *source,
79 GtkTextDirection direction,
84 static void gtk_default_draw_hline (GtkStyle *style,
86 GtkStateType state_type,
93 static void gtk_default_draw_vline (GtkStyle *style,
95 GtkStateType state_type,
102 static void gtk_default_draw_shadow (GtkStyle *style,
104 GtkStateType state_type,
105 GtkShadowType shadow_type,
113 static void gtk_default_draw_polygon (GtkStyle *style,
115 GtkStateType state_type,
116 GtkShadowType shadow_type,
123 static void gtk_default_draw_arrow (GtkStyle *style,
125 GtkStateType state_type,
126 GtkShadowType shadow_type,
130 GtkArrowType arrow_type,
136 static void gtk_default_draw_diamond (GtkStyle *style,
138 GtkStateType state_type,
139 GtkShadowType shadow_type,
147 static void gtk_default_draw_string (GtkStyle *style,
149 GtkStateType state_type,
155 const gchar *string);
156 static void gtk_default_draw_box (GtkStyle *style,
158 GtkStateType state_type,
159 GtkShadowType shadow_type,
167 static void gtk_default_draw_flat_box (GtkStyle *style,
169 GtkStateType state_type,
170 GtkShadowType shadow_type,
178 static void gtk_default_draw_check (GtkStyle *style,
180 GtkStateType state_type,
181 GtkShadowType shadow_type,
189 static void gtk_default_draw_option (GtkStyle *style,
191 GtkStateType state_type,
192 GtkShadowType shadow_type,
200 static void gtk_default_draw_tab (GtkStyle *style,
202 GtkStateType state_type,
203 GtkShadowType shadow_type,
211 static void gtk_default_draw_shadow_gap (GtkStyle *style,
213 GtkStateType state_type,
214 GtkShadowType shadow_type,
222 GtkPositionType gap_side,
225 static void gtk_default_draw_box_gap (GtkStyle *style,
227 GtkStateType state_type,
228 GtkShadowType shadow_type,
236 GtkPositionType gap_side,
239 static void gtk_default_draw_extension (GtkStyle *style,
241 GtkStateType state_type,
242 GtkShadowType shadow_type,
250 GtkPositionType gap_side);
251 static void gtk_default_draw_focus (GtkStyle *style,
253 GtkStateType state_type,
261 static void gtk_default_draw_slider (GtkStyle *style,
263 GtkStateType state_type,
264 GtkShadowType shadow_type,
272 GtkOrientation orientation);
273 static void gtk_default_draw_handle (GtkStyle *style,
275 GtkStateType state_type,
276 GtkShadowType shadow_type,
284 GtkOrientation orientation);
285 static void gtk_default_draw_expander (GtkStyle *style,
287 GtkStateType state_type,
293 GtkExpanderStyle expander_style);
294 static void gtk_default_draw_layout (GtkStyle *style,
296 GtkStateType state_type,
303 PangoLayout *layout);
304 static void gtk_default_draw_resize_grip (GtkStyle *style,
306 GtkStateType state_type,
316 static void rgb_to_hls (gdouble *r,
319 static void hls_to_rgb (gdouble *h,
323 static void style_unrealize_cursor_gcs (GtkStyle *style);
325 static GdkFont *gtk_style_get_font_internal (GtkStyle *style);
328 * Data for default check and radio buttons
331 static const GtkRequisition default_option_indicator_size = { 7, 13 };
332 static const GtkBorder default_option_indicator_spacing = { 7, 5, 2, 2 };
334 #define GTK_GRAY 0xdcdc, 0xdada, 0xd5d5
335 #define GTK_DARK_GRAY 0xc4c4, 0xc2c2, 0xbdbd
336 #define GTK_LIGHT_GRAY 0xeeee, 0xebeb, 0xe7e7
337 #define GTK_WHITE 0xffff, 0xffff, 0xffff
338 #define GTK_BLUE 0x4b4b, 0x6969, 0x8383
339 #define GTK_VERY_DARK_GRAY 0x9c9c, 0x9a9a, 0x9494
340 #define GTK_BLACK 0x0000, 0x0000, 0x0000
341 #define GTK_WEAK_GRAY 0x7530, 0x7530, 0x7530
343 /* --- variables --- */
344 static const GdkColor gtk_default_normal_fg = { 0, GTK_BLACK };
345 static const GdkColor gtk_default_active_fg = { 0, GTK_BLACK };
346 static const GdkColor gtk_default_prelight_fg = { 0, GTK_BLACK };
347 static const GdkColor gtk_default_selected_fg = { 0, GTK_WHITE };
348 static const GdkColor gtk_default_insensitive_fg = { 0, GTK_WEAK_GRAY };
350 static const GdkColor gtk_default_normal_bg = { 0, GTK_GRAY };
351 static const GdkColor gtk_default_active_bg = { 0, GTK_DARK_GRAY };
352 static const GdkColor gtk_default_prelight_bg = { 0, GTK_LIGHT_GRAY };
353 static const GdkColor gtk_default_selected_bg = { 0, GTK_BLUE };
354 static const GdkColor gtk_default_insensitive_bg = { 0, GTK_GRAY };
355 static const GdkColor gtk_default_selected_base = { 0, GTK_BLUE };
356 static const GdkColor gtk_default_active_base = { 0, GTK_VERY_DARK_GRAY };
358 /* --- signals --- */
359 static guint realize_signal = 0;
360 static guint unrealize_signal = 0;
362 G_DEFINE_TYPE (GtkStyle, gtk_style, G_TYPE_OBJECT)
364 /* --- functions --- */
367 * _gtk_style_init_for_settings:
368 * @style: a #GtkStyle
369 * @settings: a #GtkSettings
371 * Initializes the font description in @style according to the default
372 * font name of @settings. This is called for gtk_style_new() with
373 * the settings for the default screen (if any); if we are creating
374 * a style for a particular screen, we then call it again in a
375 * location where we know the correct settings.
376 * The reason for this is that gtk_rc_style_create_style() doesn't
377 * take the screen for an argument.
380 _gtk_style_init_for_settings (GtkStyle *style,
381 GtkSettings *settings)
383 const gchar *font_name = _gtk_rc_context_get_default_font_name (settings);
385 if (style->font_desc)
386 pango_font_description_free (style->font_desc);
388 style->font_desc = pango_font_description_from_string (font_name);
390 if (!pango_font_description_get_family (style->font_desc))
392 g_warning ("Default font does not have a family set");
393 pango_font_description_set_family (style->font_desc, "Sans");
395 if (pango_font_description_get_size (style->font_desc) <= 0)
397 g_warning ("Default font does not have a positive size");
398 pango_font_description_set_size (style->font_desc, 10 * PANGO_SCALE);
403 gtk_style_init (GtkStyle *style)
407 GtkSettings *settings = gtk_settings_get_default ();
410 _gtk_style_init_for_settings (style, settings);
412 style->font_desc = pango_font_description_from_string ("Sans 10");
414 style->attach_count = 0;
415 style->colormap = NULL;
418 style->black.red = 0;
419 style->black.green = 0;
420 style->black.blue = 0;
422 style->white.red = 65535;
423 style->white.green = 65535;
424 style->white.blue = 65535;
426 style->black_gc = NULL;
427 style->white_gc = NULL;
429 style->fg[GTK_STATE_NORMAL] = gtk_default_normal_fg;
430 style->fg[GTK_STATE_ACTIVE] = gtk_default_active_fg;
431 style->fg[GTK_STATE_PRELIGHT] = gtk_default_prelight_fg;
432 style->fg[GTK_STATE_SELECTED] = gtk_default_selected_fg;
433 style->fg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
435 style->bg[GTK_STATE_NORMAL] = gtk_default_normal_bg;
436 style->bg[GTK_STATE_ACTIVE] = gtk_default_active_bg;
437 style->bg[GTK_STATE_PRELIGHT] = gtk_default_prelight_bg;
438 style->bg[GTK_STATE_SELECTED] = gtk_default_selected_bg;
439 style->bg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_bg;
441 for (i = 0; i < 4; i++)
443 style->text[i] = style->fg[i];
444 style->base[i] = style->white;
447 style->base[GTK_STATE_SELECTED] = gtk_default_selected_base;
448 style->text[GTK_STATE_SELECTED] = style->white;
449 style->base[GTK_STATE_ACTIVE] = gtk_default_active_base;
450 style->text[GTK_STATE_ACTIVE] = style->white;
451 style->base[GTK_STATE_INSENSITIVE] = gtk_default_prelight_bg;
452 style->text[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
454 for (i = 0; i < 5; i++)
455 style->bg_pixmap[i] = NULL;
457 style->rc_style = NULL;
459 for (i = 0; i < 5; i++)
461 style->fg_gc[i] = NULL;
462 style->bg_gc[i] = NULL;
463 style->light_gc[i] = NULL;
464 style->dark_gc[i] = NULL;
465 style->mid_gc[i] = NULL;
466 style->text_gc[i] = NULL;
467 style->base_gc[i] = NULL;
468 style->text_aa_gc[i] = NULL;
471 style->xthickness = 2;
472 style->ythickness = 2;
474 style->property_cache = NULL;
478 gtk_style_class_init (GtkStyleClass *klass)
480 GObjectClass *object_class = G_OBJECT_CLASS (klass);
482 object_class->finalize = gtk_style_finalize;
484 klass->clone = gtk_style_real_clone;
485 klass->copy = gtk_style_real_copy;
486 klass->init_from_rc = gtk_style_real_init_from_rc;
487 klass->realize = gtk_style_real_realize;
488 klass->unrealize = gtk_style_real_unrealize;
489 klass->set_background = gtk_style_real_set_background;
490 klass->render_icon = gtk_default_render_icon;
492 klass->draw_hline = gtk_default_draw_hline;
493 klass->draw_vline = gtk_default_draw_vline;
494 klass->draw_shadow = gtk_default_draw_shadow;
495 klass->draw_polygon = gtk_default_draw_polygon;
496 klass->draw_arrow = gtk_default_draw_arrow;
497 klass->draw_diamond = gtk_default_draw_diamond;
498 klass->draw_string = gtk_default_draw_string;
499 klass->draw_box = gtk_default_draw_box;
500 klass->draw_flat_box = gtk_default_draw_flat_box;
501 klass->draw_check = gtk_default_draw_check;
502 klass->draw_option = gtk_default_draw_option;
503 klass->draw_tab = gtk_default_draw_tab;
504 klass->draw_shadow_gap = gtk_default_draw_shadow_gap;
505 klass->draw_box_gap = gtk_default_draw_box_gap;
506 klass->draw_extension = gtk_default_draw_extension;
507 klass->draw_focus = gtk_default_draw_focus;
508 klass->draw_slider = gtk_default_draw_slider;
509 klass->draw_handle = gtk_default_draw_handle;
510 klass->draw_expander = gtk_default_draw_expander;
511 klass->draw_layout = gtk_default_draw_layout;
512 klass->draw_resize_grip = gtk_default_draw_resize_grip;
514 g_type_class_add_private (object_class, sizeof (GtkStylePrivate));
518 * @style: the object which received the signal
520 * Emitted when the style has been initialized for a particular
521 * colormap and depth. Connecting to this signal is probably seldom
522 * useful since most of the time applications and widgets only
523 * deal with styles that have been already realized.
527 realize_signal = g_signal_new (I_("realize"),
528 G_TYPE_FROM_CLASS (object_class),
530 G_STRUCT_OFFSET (GtkStyleClass, realize),
532 _gtk_marshal_VOID__VOID,
535 * GtkStyle::unrealize:
536 * @style: the object which received the signal
538 * Emitted when the aspects of the style specific to a particular colormap
539 * and depth are being cleaned up. A connection to this signal can be useful
540 * if a widget wants to cache objects like a #GdkGC as object data on #GtkStyle.
541 * This signal provides a convenient place to free such cached objects.
545 unrealize_signal = g_signal_new (I_("unrealize"),
546 G_TYPE_FROM_CLASS (object_class),
548 G_STRUCT_OFFSET (GtkStyleClass, unrealize),
550 _gtk_marshal_VOID__VOID,
555 clear_property_cache (GtkStyle *style)
557 if (style->property_cache)
561 for (i = 0; i < style->property_cache->len; i++)
563 PropertyValue *node = &g_array_index (style->property_cache, PropertyValue, i);
565 g_param_spec_unref (node->pspec);
566 g_value_unset (&node->value);
568 g_array_free (style->property_cache, TRUE);
569 style->property_cache = NULL;
574 gtk_style_finalize (GObject *object)
576 GtkStyle *style = GTK_STYLE (object);
577 GtkStylePrivate *priv = GTK_STYLE_GET_PRIVATE (style);
579 g_return_if_fail (style->attach_count == 0);
581 clear_property_cache (style);
583 /* All the styles in the list have the same
584 * style->styles pointer. If we delete the
585 * *first* style from the list, we need to update
586 * the style->styles pointers from all the styles.
587 * Otherwise we simply remove the node from
592 if (style->styles->data != style)
593 style->styles = g_slist_remove (style->styles, style);
596 GSList *tmp_list = style->styles->next;
600 GTK_STYLE (tmp_list->data)->styles = style->styles->next;
601 tmp_list = tmp_list->next;
603 g_slist_free_1 (style->styles);
607 g_slist_foreach (style->icon_factories, (GFunc) g_object_unref, NULL);
608 g_slist_free (style->icon_factories);
610 g_slist_foreach (priv->color_hashes, (GFunc) g_hash_table_unref, NULL);
611 g_slist_free (priv->color_hashes);
613 pango_font_description_free (style->font_desc);
615 if (style->private_font)
616 gdk_font_unref (style->private_font);
618 if (style->private_font_desc)
619 pango_font_description_free (style->private_font_desc);
622 g_object_unref (style->rc_style);
624 G_OBJECT_CLASS (gtk_style_parent_class)->finalize (object);
629 gtk_style_copy (GtkStyle *style)
633 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
635 new_style = GTK_STYLE_GET_CLASS (style)->clone (style);
636 GTK_STYLE_GET_CLASS (style)->copy (new_style, style);
642 gtk_style_duplicate (GtkStyle *style)
646 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
648 new_style = gtk_style_copy (style);
650 /* All the styles in the list have the same
651 * style->styles pointer. When we insert a new
652 * style, we append it to the list to avoid having
653 * to update the existing ones.
655 style->styles = g_slist_append (style->styles, new_style);
656 new_style->styles = style->styles;
663 * @returns: a new #GtkStyle.
665 * Creates a new #GtkStyle.
672 style = g_object_new (GTK_TYPE_STYLE, NULL);
679 * @style: a #GtkStyle.
680 * @window: a #GdkWindow.
682 * Attaches a style to a window; this process allocates the
683 * colors and creates the GC's for the style - it specializes
684 * it to a particular visual and colormap. The process may
685 * involve the creation of a new style if the style has already
686 * been attached to a window with a different style and colormap.
688 * Since this function may return a new object, you have to use it
689 * in the following way:
690 * <literal>style = gtk_style_attach (style, window)</literal>
692 * Returns: Either @style, or a newly-created #GtkStyle.
693 * If the style is newly created, the style parameter
694 * will be unref'ed, and the new style will have
695 * a reference count belonging to the caller.
698 gtk_style_attach (GtkStyle *style,
702 GtkStyle *new_style = NULL;
703 GdkColormap *colormap;
705 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
706 g_return_val_if_fail (window != NULL, NULL);
708 colormap = gdk_drawable_get_colormap (window);
711 style->styles = g_slist_append (NULL, style);
713 styles = style->styles;
716 new_style = styles->data;
718 if (new_style->colormap == colormap)
722 styles = styles->next;
727 styles = style->styles;
731 new_style = styles->data;
733 if (new_style->attach_count == 0)
735 gtk_style_realize (new_style, colormap);
740 styles = styles->next;
746 new_style = gtk_style_duplicate (style);
747 if (gdk_colormap_get_screen (style->colormap) != gdk_colormap_get_screen (colormap) &&
748 new_style->private_font)
750 gdk_font_unref (new_style->private_font);
751 new_style->private_font = NULL;
753 gtk_style_realize (new_style, colormap);
756 /* A style gets a refcount from being attached */
757 if (new_style->attach_count == 0)
758 g_object_ref (new_style);
760 /* Another refcount belongs to the parent */
761 if (style != new_style)
763 g_object_unref (style);
764 g_object_ref (new_style);
767 new_style->attach_count++;
774 * @style: a #GtkStyle
776 * Detaches a style from a window. If the style is not attached
777 * to any windows anymore, it is unrealized. See gtk_style_attach().
781 gtk_style_detach (GtkStyle *style)
783 g_return_if_fail (GTK_IS_STYLE (style));
784 g_return_if_fail (style->attach_count > 0);
786 style->attach_count -= 1;
787 if (style->attach_count == 0)
789 g_signal_emit (style, unrealize_signal, 0);
791 g_object_unref (style->colormap);
792 style->colormap = NULL;
794 if (style->private_font_desc)
796 if (style->private_font)
798 gdk_font_unref (style->private_font);
799 style->private_font = NULL;
802 pango_font_description_free (style->private_font_desc);
803 style->private_font_desc = NULL;
806 g_object_unref (style);
812 * @style: a #GtkStyle.
815 * Deprecated: 2.0: use g_object_ref() instead.
818 gtk_style_ref (GtkStyle *style)
820 return (GtkStyle *) g_object_ref (style);
825 * @style: a #GtkStyle.
827 * Deprecated: 2.0: use g_object_unref() instead.
830 gtk_style_unref (GtkStyle *style)
832 g_object_unref (style);
836 gtk_style_realize (GtkStyle *style,
837 GdkColormap *colormap)
839 style->colormap = g_object_ref (colormap);
840 style->depth = gdk_colormap_get_visual (colormap)->depth;
842 g_signal_emit (style, realize_signal, 0);
846 gtk_style_lookup_icon_set (GtkStyle *style,
847 const char *stock_id)
851 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
852 g_return_val_if_fail (stock_id != NULL, NULL);
854 iter = style->icon_factories;
857 GtkIconSet *icon_set = gtk_icon_factory_lookup (GTK_ICON_FACTORY (iter->data),
862 iter = g_slist_next (iter);
865 return gtk_icon_factory_lookup_default (stock_id);
869 * gtk_style_lookup_color:
870 * @style: a #GtkStyle
871 * @color_name: the name of the logical color to look up
872 * @color: the #GdkColor to fill in
874 * Looks up @color_name in the style's logical color mappings,
875 * filling in @color and returning %TRUE if found, otherwise
876 * returning %FALSE. Do not cache the found mapping, because
877 * it depends on the #GtkStyle and might change when a theme
880 * Return value: %TRUE if the mapping was found.
885 gtk_style_lookup_color (GtkStyle *style,
886 const char *color_name,
889 GtkStylePrivate *priv;
892 g_return_val_if_fail (GTK_IS_STYLE (style), FALSE);
893 g_return_val_if_fail (color_name != NULL, FALSE);
894 g_return_val_if_fail (color != NULL, FALSE);
896 priv = GTK_STYLE_GET_PRIVATE (style);
898 for (iter = priv->color_hashes; iter != NULL; iter = iter->next)
900 GHashTable *hash = iter->data;
901 GdkColor *mapping = g_hash_table_lookup (hash, color_name);
905 color->red = mapping->red;
906 color->green = mapping->green;
907 color->blue = mapping->blue;
917 * @style: a #GtkStyle
918 * @window: a #GdkWindow
919 * @state_type: a state
920 * @x1: the starting x coordinate
921 * @x2: the ending x coordinate
922 * @y: the y coordinate
924 * Draws a horizontal line from (@x1, @y) to (@x2, @y) in @window
925 * using the given style and state.
927 * Deprecated: 2.0: Use gtk_paint_hline() instead.
930 gtk_draw_hline (GtkStyle *style,
932 GtkStateType state_type,
937 g_return_if_fail (GTK_IS_STYLE (style));
938 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
940 GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, NULL, NULL, NULL, x1, x2, y);
946 * @style: a #GtkStyle
947 * @window: a #GdkWindow
948 * @state_type: a state
949 * @y1_: the starting y coordinate
950 * @y2_: the ending y coordinate
951 * @x: the x coordinate
953 * Draws a vertical line from (@x, @y1_) to (@x, @y2_) in @window
954 * using the given style and state.
956 * Deprecated: 2.0: Use gtk_paint_vline() instead.
959 gtk_draw_vline (GtkStyle *style,
961 GtkStateType state_type,
966 g_return_if_fail (GTK_IS_STYLE (style));
967 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
969 GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, NULL, NULL, NULL, y1_, y2_, x);
974 * @style: a #GtkStyle
975 * @window: a #GdkWindow
976 * @state_type: a state
977 * @shadow_type: type of shadow to draw
978 * @x: x origin of the rectangle
979 * @y: y origin of the rectangle
980 * @width: width of the rectangle
981 * @height: width of the rectangle
983 * Draws a shadow around the given rectangle in @window
984 * using the given style and state and shadow type.
986 * Deprecated: 2.0: Use gtk_paint_shadow() instead.
989 gtk_draw_shadow (GtkStyle *style,
991 GtkStateType state_type,
992 GtkShadowType shadow_type,
998 g_return_if_fail (GTK_IS_STYLE (style));
999 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
1001 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1006 * @style: a #GtkStyle
1007 * @window: a #GdkWindow
1008 * @state_type: a state
1009 * @shadow_type: type of shadow to draw
1010 * @points: an array of #GdkPoint<!-- -->s
1011 * @npoints: length of @points
1012 * @fill: %TRUE if the polygon should be filled
1014 * Draws a polygon on @window with the given parameters.
1016 * Deprecated: 2.0: Use gtk_paint_polygon() instead.
1019 gtk_draw_polygon (GtkStyle *style,
1021 GtkStateType state_type,
1022 GtkShadowType shadow_type,
1027 g_return_if_fail (GTK_IS_STYLE (style));
1028 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_polygon != NULL);
1030 GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, NULL, NULL, NULL, points, npoints, fill);
1035 * @style: a #GtkStyle
1036 * @window: a #GdkWindow
1037 * @state_type: a state
1038 * @shadow_type: the type of shadow to draw
1039 * @arrow_type: the type of arrow to draw
1040 * @fill: %TRUE if the arrow tip should be filled
1041 * @x: x origin of the rectangle to draw the arrow in
1042 * @y: y origin of the rectangle to draw the arrow in
1043 * @width: width of the rectangle to draw the arrow in
1044 * @height: height of the rectangle to draw the arrow in
1046 * Draws an arrow in the given rectangle on @window using the given
1047 * parameters. @arrow_type determines the direction of the arrow.
1049 * Deprecated: 2.0: Use gtk_paint_arrow() instead.
1052 gtk_draw_arrow (GtkStyle *style,
1054 GtkStateType state_type,
1055 GtkShadowType shadow_type,
1056 GtkArrowType arrow_type,
1063 g_return_if_fail (GTK_IS_STYLE (style));
1064 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
1066 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, NULL, NULL, NULL, arrow_type, fill, x, y, width, height);
1071 * @style: a #GtkStyle
1072 * @window: a #GdkWindow
1073 * @state_type: a state
1074 * @shadow_type: the type of shadow to draw
1075 * @x: x origin of the rectangle to draw the diamond in
1076 * @y: y origin of the rectangle to draw the diamond in
1077 * @width: width of the rectangle to draw the diamond in
1078 * @height: height of the rectangle to draw the diamond in
1080 * Draws a diamond in the given rectangle on @window using the given
1083 * Deprecated: 2.0: Use gtk_paint_diamond() instead.
1086 gtk_draw_diamond (GtkStyle *style,
1088 GtkStateType state_type,
1089 GtkShadowType shadow_type,
1095 g_return_if_fail (GTK_IS_STYLE (style));
1096 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
1098 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1103 * @style: a #GtkStyle
1104 * @window: a #GdkWindow
1105 * @state_type: a state
1108 * @string: the string to draw
1110 * Draws a text string on @window with the given parameters.
1112 * Deprecated: 2.0: Use gtk_paint_layout() instead.
1115 gtk_draw_string (GtkStyle *style,
1117 GtkStateType state_type,
1120 const gchar *string)
1122 g_return_if_fail (GTK_IS_STYLE (style));
1123 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
1125 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, NULL, NULL, NULL, x, y, string);
1130 * @style: a #GtkStyle
1131 * @window: a #GdkWindow
1132 * @state_type: a state
1133 * @shadow_type: the type of shadow to draw
1134 * @x: x origin of the box
1135 * @y: y origin of the box
1136 * @width: the width of the box
1137 * @height: the height of the box
1139 * Draws a box on @window with the given parameters.
1141 * Deprecated: 2.0: Use gtk_paint_box() instead.
1144 gtk_draw_box (GtkStyle *style,
1146 GtkStateType state_type,
1147 GtkShadowType shadow_type,
1153 g_return_if_fail (GTK_IS_STYLE (style));
1154 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
1156 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1160 * gtk_draw_flat_box:
1161 * @style: a #GtkStyle
1162 * @window: a #GdkWindow
1163 * @state_type: a state
1164 * @shadow_type: the type of shadow to draw
1165 * @x: x origin of the box
1166 * @y: y origin of the box
1167 * @width: the width of the box
1168 * @height: the height of the box
1170 * Draws a flat box on @window with the given parameters.
1172 * Deprecated: 2.0: Use gtk_paint_flat_box() instead.
1175 gtk_draw_flat_box (GtkStyle *style,
1177 GtkStateType state_type,
1178 GtkShadowType shadow_type,
1184 g_return_if_fail (GTK_IS_STYLE (style));
1185 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
1187 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1192 * @style: a #GtkStyle
1193 * @window: a #GdkWindow
1194 * @state_type: a state
1195 * @shadow_type: the type of shadow to draw
1196 * @x: x origin of the rectangle to draw the check in
1197 * @y: y origin of the rectangle to draw the check in
1198 * @width: the width of the rectangle to draw the check in
1199 * @height: the height of the rectangle to draw the check in
1201 * Draws a check button indicator in the given rectangle on @window with
1202 * the given parameters.
1204 * Deprecated: 2.0: Use gtk_paint_check() instead.
1207 gtk_draw_check (GtkStyle *style,
1209 GtkStateType state_type,
1210 GtkShadowType shadow_type,
1216 g_return_if_fail (GTK_IS_STYLE (style));
1217 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
1219 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1224 * @style: a #GtkStyle
1225 * @window: a #GdkWindow
1226 * @state_type: a state
1227 * @shadow_type: the type of shadow to draw
1228 * @x: x origin of the rectangle to draw the option in
1229 * @y: y origin of the rectangle to draw the option in
1230 * @width: the width of the rectangle to draw the option in
1231 * @height: the height of the rectangle to draw the option in
1233 * Draws a radio button indicator in the given rectangle on @window with
1234 * the given parameters.
1236 * Deprecated: 2.0: Use gtk_paint_option() instead.
1239 gtk_draw_option (GtkStyle *style,
1241 GtkStateType state_type,
1242 GtkShadowType shadow_type,
1248 g_return_if_fail (GTK_IS_STYLE (style));
1249 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
1251 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1256 * @style: a #GtkStyle
1257 * @window: a #GdkWindow
1258 * @state_type: a state
1259 * @shadow_type: the type of shadow to draw
1260 * @x: x origin of the rectangle to draw the tab in
1261 * @y: y origin of the rectangle to draw the tab in
1262 * @width: the width of the rectangle to draw the tab in
1263 * @height: the height of the rectangle to draw the tab in
1265 * Draws an option menu tab (i.e. the up and down pointing arrows)
1266 * in the given rectangle on @window using the given parameters.
1268 * Deprecated: 2.0: Use gtk_paint_tab() instead.
1271 gtk_draw_tab (GtkStyle *style,
1273 GtkStateType state_type,
1274 GtkShadowType shadow_type,
1280 g_return_if_fail (GTK_IS_STYLE (style));
1281 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
1283 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1287 * gtk_draw_shadow_gap:
1288 * @style: a #GtkStyle
1289 * @window: a #GdkWindow
1290 * @state_type: a state
1291 * @shadow_type: type of shadow to draw
1292 * @x: x origin of the rectangle
1293 * @y: y origin of the rectangle
1294 * @width: width of the rectangle
1295 * @height: width of the rectangle
1296 * @gap_side: side in which to leave the gap
1297 * @gap_x: starting position of the gap
1298 * @gap_width: width of the gap
1300 * Draws a shadow around the given rectangle in @window
1301 * using the given style and state and shadow type, leaving a
1304 * Deprecated: 2.0: Use gtk_paint_shadow_gap() instead.
1307 gtk_draw_shadow_gap (GtkStyle *style,
1309 GtkStateType state_type,
1310 GtkShadowType shadow_type,
1315 GtkPositionType gap_side,
1319 g_return_if_fail (GTK_IS_STYLE (style));
1320 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
1322 GTK_STYLE_GET_CLASS (style)->draw_shadow_gap (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, gap_side, gap_x, gap_width);
1327 * @style: a #GtkStyle
1328 * @window: a #GdkWindow
1329 * @state_type: a state
1330 * @shadow_type: type of shadow to draw
1331 * @x: x origin of the rectangle
1332 * @y: y origin of the rectangle
1333 * @width: width of the rectangle
1334 * @height: width of the rectangle
1335 * @gap_side: side in which to leave the gap
1336 * @gap_x: starting position of the gap
1337 * @gap_width: width of the gap
1339 * Draws a box in @window using the given style and state and shadow type,
1340 * leaving a gap in one side.
1342 * Deprecated: 2.0: Use gtk_paint_box_gap() instead.
1345 gtk_draw_box_gap (GtkStyle *style,
1347 GtkStateType state_type,
1348 GtkShadowType shadow_type,
1353 GtkPositionType gap_side,
1357 g_return_if_fail (GTK_IS_STYLE (style));
1358 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
1360 GTK_STYLE_GET_CLASS (style)->draw_box_gap (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, gap_side, gap_x, gap_width);
1364 * gtk_draw_extension:
1365 * @style: a #GtkStyle
1366 * @window: a #GdkWindow
1367 * @state_type: a state
1368 * @shadow_type: type of shadow to draw
1369 * @x: x origin of the extension
1370 * @y: y origin of the extension
1371 * @width: width of the extension
1372 * @height: width of the extension
1373 * @gap_side: the side on to which the extension is attached
1375 * Draws an extension, i.e. a notebook tab.
1377 * Deprecated: 2.0: Use gtk_paint_extension() instead.
1380 gtk_draw_extension (GtkStyle *style,
1382 GtkStateType state_type,
1383 GtkShadowType shadow_type,
1388 GtkPositionType gap_side)
1390 g_return_if_fail (GTK_IS_STYLE (style));
1391 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
1393 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, gap_side);
1398 * @style: a #GtkStyle
1399 * @window: a #GdkWindow
1400 * @x: the x origin of the rectangle around which to draw a focus indicator
1401 * @y: the y origin of the rectangle around which to draw a focus indicator
1402 * @width: the width of the rectangle around which to draw a focus indicator
1403 * @height: the height of the rectangle around which to draw a focus indicator
1405 * Draws a focus indicator around the given rectangle on @window using the
1408 * Deprecated: 2.0: Use gtk_paint_focus() instead.
1411 gtk_draw_focus (GtkStyle *style,
1418 g_return_if_fail (GTK_IS_STYLE (style));
1419 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
1421 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, GTK_STATE_NORMAL, NULL, NULL, NULL, x, y, width, height);
1425 gtk_draw_slider (GtkStyle *style,
1427 GtkStateType state_type,
1428 GtkShadowType shadow_type,
1433 GtkOrientation orientation)
1435 g_return_if_fail (GTK_IS_STYLE (style));
1436 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
1438 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
1443 * @style: a #GtkStyle
1444 * @window: a #GdkWindow
1445 * @state_type: a state
1446 * @shadow_type: type of shadow to draw
1447 * @x: x origin of the handle
1448 * @y: y origin of the handle
1449 * @width: with of the handle
1450 * @height: height of the handle
1451 * @orientation: the orientation of the handle
1453 * Draws a handle as used in #GtkHandleBox and #GtkPaned.
1455 * Deprecated: 2.0: Use gtk_paint_handle() instead.
1458 gtk_draw_handle (GtkStyle *style,
1460 GtkStateType state_type,
1461 GtkShadowType shadow_type,
1466 GtkOrientation orientation)
1468 g_return_if_fail (GTK_IS_STYLE (style));
1469 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
1471 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
1475 * gtk_draw_expander:
1476 * @style: a #GtkStyle
1477 * @window: a #GdkWindow
1478 * @state_type: a state
1479 * @x: the x position to draw the expander at
1480 * @y: the y position to draw the expander at
1481 * @expander_style: the style to draw the expander in
1483 * Draws an expander as used in #GtkTreeView.
1485 * Deprecated: 2.0: Use gtk_paint_expander() instead.
1488 gtk_draw_expander (GtkStyle *style,
1490 GtkStateType state_type,
1493 GtkExpanderStyle expander_style)
1495 g_return_if_fail (GTK_IS_STYLE (style));
1496 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
1498 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type,
1500 x, y, expander_style);
1504 gtk_draw_layout (GtkStyle *style,
1506 GtkStateType state_type,
1510 PangoLayout *layout)
1512 g_return_if_fail (GTK_IS_STYLE (style));
1513 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
1515 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, use_text,
1521 * gtk_draw_resize_grip:
1522 * @style: a #GtkStyle
1523 * @window: a #GdkWindow
1524 * @state_type: a state
1525 * @edge: the edge in which to draw the resize grip
1526 * @x: the x origin of the rectangle in which to draw the resize grip
1527 * @y: the y origin of the rectangle in which to draw the resize grip
1528 * @width: the width of the rectangle in which to draw the resize grip
1529 * @height: the height of the rectangle in which to draw the resize grip
1531 * Draws a resize grip in the given rectangle on @window using the given
1534 * Deprecated: 2.0: Use gtk_paint_resize_grip() instead.
1537 gtk_draw_resize_grip (GtkStyle *style,
1539 GtkStateType state_type,
1546 g_return_if_fail (GTK_IS_STYLE (style));
1547 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
1549 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, window, state_type,
1552 x, y, width, height);
1557 * gtk_style_set_background:
1558 * @style: a #GtkStyle
1559 * @window: a #GdkWindow
1560 * @state_type: a state
1562 * Sets the background of @window to the background color or pixmap
1563 * specified by @style for the given state.
1566 gtk_style_set_background (GtkStyle *style,
1568 GtkStateType state_type)
1570 g_return_if_fail (GTK_IS_STYLE (style));
1571 g_return_if_fail (window != NULL);
1573 GTK_STYLE_GET_CLASS (style)->set_background (style, window, state_type);
1576 /* Default functions */
1578 gtk_style_real_clone (GtkStyle *style)
1580 return g_object_new (G_OBJECT_TYPE (style), NULL);
1584 gtk_style_real_copy (GtkStyle *style,
1587 GtkStylePrivate *priv = GTK_STYLE_GET_PRIVATE (style);
1588 GtkStylePrivate *src_priv = GTK_STYLE_GET_PRIVATE (src);
1591 for (i = 0; i < 5; i++)
1593 style->fg[i] = src->fg[i];
1594 style->bg[i] = src->bg[i];
1595 style->text[i] = src->text[i];
1596 style->base[i] = src->base[i];
1598 if (style->bg_pixmap[i])
1599 g_object_unref (style->bg_pixmap[i]),
1600 style->bg_pixmap[i] = src->bg_pixmap[i];
1601 if (style->bg_pixmap[i])
1602 g_object_ref (style->bg_pixmap[i]);
1605 if (style->private_font)
1606 gdk_font_unref (style->private_font);
1607 style->private_font = src->private_font;
1608 if (style->private_font)
1609 gdk_font_ref (style->private_font);
1611 if (style->font_desc)
1612 pango_font_description_free (style->font_desc);
1614 style->font_desc = pango_font_description_copy (src->font_desc);
1616 style->font_desc = NULL;
1618 style->xthickness = src->xthickness;
1619 style->ythickness = src->ythickness;
1621 if (style->rc_style)
1622 g_object_unref (style->rc_style);
1623 style->rc_style = src->rc_style;
1625 g_object_ref (src->rc_style);
1627 g_slist_foreach (style->icon_factories, (GFunc) g_object_unref, NULL);
1628 g_slist_free (style->icon_factories);
1629 style->icon_factories = g_slist_copy (src->icon_factories);
1630 g_slist_foreach (style->icon_factories, (GFunc) g_object_ref, NULL);
1632 g_slist_foreach (priv->color_hashes, (GFunc) g_hash_table_unref, NULL);
1633 g_slist_free (priv->color_hashes);
1634 priv->color_hashes = g_slist_copy (src_priv->color_hashes);
1635 g_slist_foreach (priv->color_hashes, (GFunc) g_hash_table_ref, NULL);
1637 /* don't copy, just clear cache */
1638 clear_property_cache (style);
1642 gtk_style_real_init_from_rc (GtkStyle *style,
1643 GtkRcStyle *rc_style)
1645 GtkStylePrivate *priv = GTK_STYLE_GET_PRIVATE (style);
1648 /* cache _should_ be still empty */
1649 clear_property_cache (style);
1651 if (rc_style->font_desc)
1652 pango_font_description_merge (style->font_desc, rc_style->font_desc, TRUE);
1654 for (i = 0; i < 5; i++)
1656 if (rc_style->color_flags[i] & GTK_RC_FG)
1657 style->fg[i] = rc_style->fg[i];
1658 if (rc_style->color_flags[i] & GTK_RC_BG)
1659 style->bg[i] = rc_style->bg[i];
1660 if (rc_style->color_flags[i] & GTK_RC_TEXT)
1661 style->text[i] = rc_style->text[i];
1662 if (rc_style->color_flags[i] & GTK_RC_BASE)
1663 style->base[i] = rc_style->base[i];
1666 if (rc_style->xthickness >= 0)
1667 style->xthickness = rc_style->xthickness;
1668 if (rc_style->ythickness >= 0)
1669 style->ythickness = rc_style->ythickness;
1671 style->icon_factories = g_slist_copy (rc_style->icon_factories);
1672 g_slist_foreach (style->icon_factories, (GFunc) g_object_ref, NULL);
1674 priv->color_hashes = g_slist_copy (_gtk_rc_style_get_color_hashes (rc_style));
1675 g_slist_foreach (priv->color_hashes, (GFunc) g_hash_table_ref, NULL);
1679 style_property_values_cmp (gconstpointer bsearch_node1,
1680 gconstpointer bsearch_node2)
1682 const PropertyValue *val1 = bsearch_node1;
1683 const PropertyValue *val2 = bsearch_node2;
1685 if (val1->widget_type == val2->widget_type)
1686 return val1->pspec < val2->pspec ? -1 : val1->pspec == val2->pspec ? 0 : 1;
1688 return val1->widget_type < val2->widget_type ? -1 : 1;
1692 _gtk_style_peek_property_value (GtkStyle *style,
1695 GtkRcPropertyParser parser)
1697 PropertyValue *pcache, key = { 0, NULL, { 0, } };
1698 const GtkRcProperty *rcprop = NULL;
1701 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1702 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), NULL);
1703 g_return_val_if_fail (g_type_is_a (pspec->owner_type, GTK_TYPE_WIDGET), NULL);
1704 g_return_val_if_fail (g_type_is_a (widget_type, pspec->owner_type), NULL);
1706 key.widget_type = widget_type;
1709 /* need value cache array */
1710 if (!style->property_cache)
1711 style->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
1714 pcache = bsearch (&key,
1715 style->property_cache->data, style->property_cache->len,
1716 sizeof (PropertyValue), style_property_values_cmp);
1718 return &pcache->value;
1722 while (i < style->property_cache->len &&
1723 style_property_values_cmp (&key, &g_array_index (style->property_cache, PropertyValue, i)) >= 0)
1726 g_array_insert_val (style->property_cache, i, key);
1727 pcache = &g_array_index (style->property_cache, PropertyValue, i);
1729 /* cache miss, initialize value type, then set contents */
1730 g_param_spec_ref (pcache->pspec);
1731 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1733 /* value provided by rc style? */
1734 if (style->rc_style)
1736 GQuark prop_quark = g_quark_from_string (pspec->name);
1740 rcprop = _gtk_rc_style_lookup_rc_property (style->rc_style,
1741 g_type_qname (widget_type),
1745 widget_type = g_type_parent (widget_type);
1747 while (g_type_is_a (widget_type, pspec->owner_type));
1750 /* when supplied by rc style, we need to convert */
1751 if (rcprop && !_gtk_settings_parse_convert (parser, &rcprop->value,
1752 pspec, &pcache->value))
1754 gchar *contents = g_strdup_value_contents (&rcprop->value);
1756 g_message ("%s: failed to retrieve property `%s::%s' of type `%s' from rc file value \"%s\" of type `%s'",
1757 rcprop->origin ? rcprop->origin : "(for origin information, set GTK_DEBUG)",
1758 g_type_name (pspec->owner_type), pspec->name,
1759 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1761 G_VALUE_TYPE_NAME (&rcprop->value));
1763 rcprop = NULL; /* needs default */
1766 /* not supplied by rc style (or conversion failed), revert to default */
1768 g_param_value_set_default (pspec, &pcache->value);
1770 return &pcache->value;
1774 load_bg_image (GdkColormap *colormap,
1776 const gchar *filename)
1778 if (strcmp (filename, "<parent>") == 0)
1779 return (GdkPixmap*) GDK_PARENT_RELATIVE;
1782 return gdk_pixmap_colormap_create_from_xpm (NULL, colormap, NULL,
1789 gtk_style_real_realize (GtkStyle *style)
1791 GdkGCValues gc_values;
1792 GdkGCValuesMask gc_values_mask;
1796 for (i = 0; i < 5; i++)
1798 _gtk_style_shade (&style->bg[i], &style->light[i], LIGHTNESS_MULT);
1799 _gtk_style_shade (&style->bg[i], &style->dark[i], DARKNESS_MULT);
1801 style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
1802 style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
1803 style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
1805 style->text_aa[i].red = (style->text[i].red + style->base[i].red) / 2;
1806 style->text_aa[i].green = (style->text[i].green + style->base[i].green) / 2;
1807 style->text_aa[i].blue = (style->text[i].blue + style->base[i].blue) / 2;
1810 style->black.red = 0x0000;
1811 style->black.green = 0x0000;
1812 style->black.blue = 0x0000;
1813 gdk_colormap_alloc_color (style->colormap, &style->black, FALSE, TRUE);
1815 style->white.red = 0xffff;
1816 style->white.green = 0xffff;
1817 style->white.blue = 0xffff;
1818 gdk_colormap_alloc_color (style->colormap, &style->white, FALSE, TRUE);
1820 gc_values_mask = GDK_GC_FOREGROUND | GDK_GC_BACKGROUND;
1822 gc_values.foreground = style->black;
1823 gc_values.background = style->white;
1824 style->black_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1826 gc_values.foreground = style->white;
1827 gc_values.background = style->black;
1828 style->white_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1830 gc_values_mask = GDK_GC_FOREGROUND;
1832 for (i = 0; i < 5; i++)
1834 if (style->rc_style && style->rc_style->bg_pixmap_name[i])
1835 style->bg_pixmap[i] = load_bg_image (style->colormap,
1837 style->rc_style->bg_pixmap_name[i]);
1839 if (!gdk_colormap_alloc_color (style->colormap, &style->fg[i], FALSE, TRUE))
1840 g_warning ("unable to allocate color: ( %d %d %d )",
1841 style->fg[i].red, style->fg[i].green, style->fg[i].blue);
1842 if (!gdk_colormap_alloc_color (style->colormap, &style->bg[i], FALSE, TRUE))
1843 g_warning ("unable to allocate color: ( %d %d %d )",
1844 style->bg[i].red, style->bg[i].green, style->bg[i].blue);
1845 if (!gdk_colormap_alloc_color (style->colormap, &style->light[i], FALSE, TRUE))
1846 g_warning ("unable to allocate color: ( %d %d %d )",
1847 style->light[i].red, style->light[i].green, style->light[i].blue);
1848 if (!gdk_colormap_alloc_color (style->colormap, &style->dark[i], FALSE, TRUE))
1849 g_warning ("unable to allocate color: ( %d %d %d )",
1850 style->dark[i].red, style->dark[i].green, style->dark[i].blue);
1851 if (!gdk_colormap_alloc_color (style->colormap, &style->mid[i], FALSE, TRUE))
1852 g_warning ("unable to allocate color: ( %d %d %d )",
1853 style->mid[i].red, style->mid[i].green, style->mid[i].blue);
1854 if (!gdk_colormap_alloc_color (style->colormap, &style->text[i], FALSE, TRUE))
1855 g_warning ("unable to allocate color: ( %d %d %d )",
1856 style->text[i].red, style->text[i].green, style->text[i].blue);
1857 if (!gdk_colormap_alloc_color (style->colormap, &style->base[i], FALSE, TRUE))
1858 g_warning ("unable to allocate color: ( %d %d %d )",
1859 style->base[i].red, style->base[i].green, style->base[i].blue);
1860 if (!gdk_colormap_alloc_color (style->colormap, &style->text_aa[i], FALSE, TRUE))
1861 g_warning ("unable to allocate color: ( %d %d %d )",
1862 style->text_aa[i].red, style->text_aa[i].green, style->text_aa[i].blue);
1864 gc_values.foreground = style->fg[i];
1865 style->fg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1867 gc_values.foreground = style->bg[i];
1868 style->bg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1870 gc_values.foreground = style->light[i];
1871 style->light_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1873 gc_values.foreground = style->dark[i];
1874 style->dark_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1876 gc_values.foreground = style->mid[i];
1877 style->mid_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1879 gc_values.foreground = style->text[i];
1880 style->text_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1882 gc_values.foreground = style->base[i];
1883 style->base_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1885 gc_values.foreground = style->text_aa[i];
1886 style->text_aa_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1891 gtk_style_real_unrealize (GtkStyle *style)
1895 gtk_gc_release (style->black_gc);
1896 gtk_gc_release (style->white_gc);
1898 for (i = 0; i < 5; i++)
1900 gtk_gc_release (style->fg_gc[i]);
1901 gtk_gc_release (style->bg_gc[i]);
1902 gtk_gc_release (style->light_gc[i]);
1903 gtk_gc_release (style->dark_gc[i]);
1904 gtk_gc_release (style->mid_gc[i]);
1905 gtk_gc_release (style->text_gc[i]);
1906 gtk_gc_release (style->base_gc[i]);
1907 gtk_gc_release (style->text_aa_gc[i]);
1909 if (style->bg_pixmap[i] && style->bg_pixmap[i] != (GdkPixmap*) GDK_PARENT_RELATIVE)
1911 g_object_unref (style->bg_pixmap[i]);
1912 style->bg_pixmap[i] = NULL;
1917 gdk_colormap_free_colors (style->colormap, style->fg, 5);
1918 gdk_colormap_free_colors (style->colormap, style->bg, 5);
1919 gdk_colormap_free_colors (style->colormap, style->light, 5);
1920 gdk_colormap_free_colors (style->colormap, style->dark, 5);
1921 gdk_colormap_free_colors (style->colormap, style->mid, 5);
1922 gdk_colormap_free_colors (style->colormap, style->text, 5);
1923 gdk_colormap_free_colors (style->colormap, style->base, 5);
1924 gdk_colormap_free_colors (style->colormap, style->text_aa, 5);
1926 style_unrealize_cursor_gcs (style);
1930 gtk_style_real_set_background (GtkStyle *style,
1932 GtkStateType state_type)
1935 gint parent_relative;
1937 if (style->bg_pixmap[state_type])
1939 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1942 parent_relative = TRUE;
1946 pixmap = style->bg_pixmap[state_type];
1947 parent_relative = FALSE;
1950 gdk_window_set_back_pixmap (window, pixmap, parent_relative);
1953 gdk_window_set_background (window, &style->bg[state_type]);
1957 * gtk_style_render_icon:
1958 * @style: a #GtkStyle
1959 * @source: the #GtkIconSource specifying the icon to render
1960 * @direction: a text direction
1962 * @size: the size to render the icon at. A size of (GtkIconSize)-1
1963 * means render at the size of the source and don't scale.
1964 * @widget: the widget
1965 * @detail: a style detail
1966 * @returns: a newly-created #GdkPixbuf containing the rendered icon
1968 * Renders the icon specified by @source at the given @size
1969 * according to the given parameters and returns the result in a
1973 gtk_style_render_icon (GtkStyle *style,
1974 const GtkIconSource *source,
1975 GtkTextDirection direction,
1979 const gchar *detail)
1983 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1984 g_return_val_if_fail (GTK_STYLE_GET_CLASS (style)->render_icon != NULL, NULL);
1986 pixbuf = GTK_STYLE_GET_CLASS (style)->render_icon (style, source, direction, state,
1987 size, widget, detail);
1989 g_return_val_if_fail (pixbuf != NULL, NULL);
1994 /* Default functions */
1996 gtk_style_apply_default_background (GtkStyle *style,
1999 GtkStateType state_type,
2000 const GdkRectangle *area,
2006 GdkRectangle new_rect, old_rect;
2012 old_rect.width = width;
2013 old_rect.height = height;
2015 if (!gdk_rectangle_intersect (area, &old_rect, &new_rect))
2022 new_rect.width = width;
2023 new_rect.height = height;
2026 if (!style->bg_pixmap[state_type] ||
2027 GDK_IS_PIXMAP (window) ||
2028 (!set_bg && style->bg_pixmap[state_type] != (GdkPixmap*) GDK_PARENT_RELATIVE))
2030 GdkGC *gc = style->bg_gc[state_type];
2032 if (style->bg_pixmap[state_type])
2034 gdk_gc_set_fill (gc, GDK_TILED);
2035 gdk_gc_set_tile (gc, style->bg_pixmap[state_type]);
2038 gdk_draw_rectangle (window, gc, TRUE,
2039 new_rect.x, new_rect.y, new_rect.width, new_rect.height);
2040 if (style->bg_pixmap[state_type])
2041 gdk_gc_set_fill (gc, GDK_SOLID);
2047 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
2048 gdk_window_set_back_pixmap (window, NULL, TRUE);
2050 gdk_window_set_back_pixmap (window, style->bg_pixmap[state_type], FALSE);
2053 gdk_window_clear_area (window,
2054 new_rect.x, new_rect.y,
2055 new_rect.width, new_rect.height);
2060 scale_or_ref (GdkPixbuf *src,
2064 if (width == gdk_pixbuf_get_width (src) &&
2065 height == gdk_pixbuf_get_height (src))
2067 return g_object_ref (src);
2071 return gdk_pixbuf_scale_simple (src,
2073 GDK_INTERP_BILINEAR);
2078 gtk_default_render_icon (GtkStyle *style,
2079 const GtkIconSource *source,
2080 GtkTextDirection direction,
2084 const gchar *detail)
2090 GdkPixbuf *base_pixbuf;
2092 GtkSettings *settings;
2094 /* Oddly, style can be NULL in this function, because
2095 * GtkIconSet can be used without a style and if so
2096 * it uses this function.
2099 base_pixbuf = gtk_icon_source_get_pixbuf (source);
2101 g_return_val_if_fail (base_pixbuf != NULL, NULL);
2103 if (widget && gtk_widget_has_screen (widget))
2105 screen = gtk_widget_get_screen (widget);
2106 settings = gtk_settings_get_for_screen (screen);
2108 else if (style && style->colormap)
2110 screen = gdk_colormap_get_screen (style->colormap);
2111 settings = gtk_settings_get_for_screen (screen);
2115 settings = gtk_settings_get_default ();
2116 GTK_NOTE (MULTIHEAD,
2117 g_warning ("Using the default screen for gtk_default_render_icon()"));
2121 if (size != (GtkIconSize) -1 && !gtk_icon_size_lookup_for_settings (settings, size, &width, &height))
2123 g_warning (G_STRLOC ": invalid icon size '%d'", size);
2127 /* If the size was wildcarded, and we're allowed to scale, then scale; otherwise,
2130 if (size != (GtkIconSize)-1 && gtk_icon_source_get_size_wildcarded (source))
2131 scaled = scale_or_ref (base_pixbuf, width, height);
2133 scaled = g_object_ref (base_pixbuf);
2135 /* If the state was wildcarded, then generate a state. */
2136 if (gtk_icon_source_get_state_wildcarded (source))
2138 if (state == GTK_STATE_INSENSITIVE)
2140 stated = gdk_pixbuf_copy (scaled);
2142 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
2145 g_object_unref (scaled);
2147 else if (state == GTK_STATE_PRELIGHT)
2149 stated = gdk_pixbuf_copy (scaled);
2151 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
2154 g_object_unref (scaled);
2168 sanitize_size (GdkWindow *window,
2172 if ((*width == -1) && (*height == -1))
2173 gdk_drawable_get_size (window, width, height);
2174 else if (*width == -1)
2175 gdk_drawable_get_size (window, width, NULL);
2176 else if (*height == -1)
2177 gdk_drawable_get_size (window, NULL, height);
2181 gtk_default_draw_hline (GtkStyle *style,
2183 GtkStateType state_type,
2186 const gchar *detail,
2191 gint thickness_light;
2192 gint thickness_dark;
2195 thickness_light = style->ythickness / 2;
2196 thickness_dark = style->ythickness - thickness_light;
2200 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
2201 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
2204 if (detail && !strcmp (detail, "label"))
2206 if (state_type == GTK_STATE_INSENSITIVE)
2207 gdk_draw_line (window, style->white_gc, x1 + 1, y + 1, x2 + 1, y + 1);
2208 gdk_draw_line (window, style->fg_gc[state_type], x1, y, x2, y);
2212 for (i = 0; i < thickness_dark; i++)
2214 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x2 - i - 1, y + i);
2215 gdk_draw_line (window, style->light_gc[state_type], x2 - i, y + i, x2, y + i);
2218 y += thickness_dark;
2219 for (i = 0; i < thickness_light; i++)
2221 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x1 + thickness_light - i - 1, y + i);
2222 gdk_draw_line (window, style->light_gc[state_type], x1 + thickness_light - i, y + i, x2, y + i);
2228 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
2229 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
2235 gtk_default_draw_vline (GtkStyle *style,
2237 GtkStateType state_type,
2240 const gchar *detail,
2245 gint thickness_light;
2246 gint thickness_dark;
2249 thickness_light = style->xthickness / 2;
2250 thickness_dark = style->xthickness - thickness_light;
2254 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
2255 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
2257 for (i = 0; i < thickness_dark; i++)
2259 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y2 - i - 1);
2260 gdk_draw_line (window, style->light_gc[state_type], x + i, y2 - i, x + i, y2);
2263 x += thickness_dark;
2264 for (i = 0; i < thickness_light; i++)
2266 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y1 + thickness_light - i - 1);
2267 gdk_draw_line (window, style->light_gc[state_type], x + i, y1 + thickness_light - i, x + i, y2);
2271 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
2272 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
2277 draw_thin_shadow (GtkStyle *style,
2288 sanitize_size (window, &width, &height);
2290 gc1 = style->light_gc[state];
2291 gc2 = style->dark_gc[state];
2295 gdk_gc_set_clip_rectangle (gc1, area);
2296 gdk_gc_set_clip_rectangle (gc2, area);
2299 gdk_draw_line (window, gc1,
2300 x, y + height - 1, x + width - 1, y + height - 1);
2301 gdk_draw_line (window, gc1,
2302 x + width - 1, y, x + width - 1, y + height - 1);
2304 gdk_draw_line (window, gc2,
2305 x, y, x + width - 2, y);
2306 gdk_draw_line (window, gc2,
2307 x, y, x, y + height - 2);
2311 gdk_gc_set_clip_rectangle (gc1, NULL);
2312 gdk_gc_set_clip_rectangle (gc2, NULL);
2317 draw_spinbutton_shadow (GtkStyle *style,
2320 GtkTextDirection direction,
2327 sanitize_size (window, &width, &height);
2331 gdk_gc_set_clip_rectangle (style->black_gc, area);
2332 gdk_gc_set_clip_rectangle (style->bg_gc[state], area);
2333 gdk_gc_set_clip_rectangle (style->dark_gc[state], area);
2334 gdk_gc_set_clip_rectangle (style->light_gc[state], area);
2337 if (direction == GTK_TEXT_DIR_LTR)
2339 gdk_draw_line (window, style->dark_gc[state],
2340 x, y, x + width - 1, y);
2341 gdk_draw_line (window, style->black_gc,
2342 x, y + 1, x + width - 2, y + 1);
2343 gdk_draw_line (window, style->black_gc,
2344 x + width - 2, y + 2, x + width - 2, y + height - 3);
2345 gdk_draw_line (window, style->light_gc[state],
2346 x + width - 1, y + 1, x + width - 1, y + height - 2);
2347 gdk_draw_line (window, style->light_gc[state],
2348 x, y + height - 1, x + width - 1, y + height - 1);
2349 gdk_draw_line (window, style->bg_gc[state],
2350 x, y + height - 2, x + width - 2, y + height - 2);
2351 gdk_draw_line (window, style->black_gc,
2352 x, y + 2, x, y + height - 3);
2356 gdk_draw_line (window, style->dark_gc[state],
2357 x, y, x + width - 1, y);
2358 gdk_draw_line (window, style->dark_gc[state],
2359 x, y + 1, x, y + height - 1);
2360 gdk_draw_line (window, style->black_gc,
2361 x + 1, y + 1, x + width - 1, y + 1);
2362 gdk_draw_line (window, style->black_gc,
2363 x + 1, y + 2, x + 1, y + height - 2);
2364 gdk_draw_line (window, style->black_gc,
2365 x + width - 1, y + 2, x + width - 1, y + height - 3);
2366 gdk_draw_line (window, style->light_gc[state],
2367 x + 1, y + height - 1, x + width - 1, y + height - 1);
2368 gdk_draw_line (window, style->bg_gc[state],
2369 x + 2, y + height - 2, x + width - 1, y + height - 2);
2374 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2375 gdk_gc_set_clip_rectangle (style->bg_gc[state], NULL);
2376 gdk_gc_set_clip_rectangle (style->dark_gc[state], NULL);
2377 gdk_gc_set_clip_rectangle (style->light_gc[state], NULL);
2382 draw_menu_shadow (GtkStyle *style,
2391 if (style->ythickness > 0)
2393 if (style->ythickness > 1)
2395 gdk_draw_line (window, style->dark_gc[state],
2396 x + 1, y + height - 2, x + width - 2, y + height - 2);
2397 gdk_draw_line (window, style->black_gc,
2398 x, y + height - 1, x + width - 1, y + height - 1);
2402 gdk_draw_line (window, style->dark_gc[state],
2403 x + 1, y + height - 1, x + width - 1, y + height - 1);
2407 if (style->xthickness > 0)
2409 if (style->xthickness > 1)
2411 gdk_draw_line (window, style->dark_gc[state],
2412 x + width - 2, y + 1, x + width - 2, y + height - 2);
2414 gdk_draw_line (window, style->black_gc,
2415 x + width - 1, y, x + width - 1, y + height - 1);
2419 gdk_draw_line (window, style->dark_gc[state],
2420 x + width - 1, y + 1, x + width - 1, y + height - 1);
2424 /* Light around top and left */
2426 if (style->ythickness > 0)
2427 gdk_draw_line (window, style->black_gc,
2428 x, y, x + width - 2, y);
2429 if (style->xthickness > 0)
2430 gdk_draw_line (window, style->black_gc,
2431 x, y, x, y + height - 2);
2433 if (style->ythickness > 1)
2434 gdk_draw_line (window, style->light_gc[state],
2435 x + 1, y + 1, x + width - 3, y + 1);
2436 if (style->xthickness > 1)
2437 gdk_draw_line (window, style->light_gc[state],
2438 x + 1, y + 1, x + 1, y + height - 3);
2441 static GtkTextDirection
2442 get_direction (GtkWidget *widget)
2444 GtkTextDirection dir;
2447 dir = gtk_widget_get_direction (widget);
2449 dir = GTK_TEXT_DIR_LTR;
2456 gtk_default_draw_shadow (GtkStyle *style,
2458 GtkStateType state_type,
2459 GtkShadowType shadow_type,
2462 const gchar *detail,
2470 gint thickness_light;
2471 gint thickness_dark;
2474 if (shadow_type == GTK_SHADOW_IN)
2476 if (detail && strcmp (detail, "buttondefault") == 0)
2478 sanitize_size (window, &width, &height);
2480 gdk_draw_rectangle (window, style->black_gc, FALSE,
2481 x, y, width - 1, height - 1);
2485 if (detail && strcmp (detail, "trough") == 0)
2487 draw_thin_shadow (style, window, state_type, area,
2488 x, y, width, height);
2491 if (GTK_IS_SPIN_BUTTON (widget) &&
2492 detail && strcmp (detail, "spinbutton") == 0)
2494 draw_spinbutton_shadow (style, window, state_type,
2495 get_direction (widget), area, x, y, width, height);
2501 if (shadow_type == GTK_SHADOW_OUT && detail && strcmp (detail, "menu") == 0)
2503 draw_menu_shadow (style, window, state_type, area, x, y, width, height);
2507 sanitize_size (window, &width, &height);
2509 switch (shadow_type)
2511 case GTK_SHADOW_NONE:
2514 case GTK_SHADOW_ETCHED_IN:
2515 gc1 = style->light_gc[state_type];
2516 gc2 = style->dark_gc[state_type];
2518 case GTK_SHADOW_OUT:
2519 case GTK_SHADOW_ETCHED_OUT:
2520 gc1 = style->dark_gc[state_type];
2521 gc2 = style->light_gc[state_type];
2527 gdk_gc_set_clip_rectangle (gc1, area);
2528 gdk_gc_set_clip_rectangle (gc2, area);
2529 if (shadow_type == GTK_SHADOW_IN ||
2530 shadow_type == GTK_SHADOW_OUT)
2532 gdk_gc_set_clip_rectangle (style->black_gc, area);
2533 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2537 switch (shadow_type)
2539 case GTK_SHADOW_NONE:
2543 /* Light around right and bottom edge */
2545 if (style->ythickness > 0)
2546 gdk_draw_line (window, gc1,
2547 x, y + height - 1, x + width - 1, y + height - 1);
2548 if (style->xthickness > 0)
2549 gdk_draw_line (window, gc1,
2550 x + width - 1, y, x + width - 1, y + height - 1);
2552 if (style->ythickness > 1)
2553 gdk_draw_line (window, style->bg_gc[state_type],
2554 x + 1, y + height - 2, x + width - 2, y + height - 2);
2555 if (style->xthickness > 1)
2556 gdk_draw_line (window, style->bg_gc[state_type],
2557 x + width - 2, y + 1, x + width - 2, y + height - 2);
2559 /* Dark around left and top */
2561 if (style->ythickness > 1)
2562 gdk_draw_line (window, style->black_gc,
2563 x + 1, y + 1, x + width - 2, y + 1);
2564 if (style->xthickness > 1)
2565 gdk_draw_line (window, style->black_gc,
2566 x + 1, y + 1, x + 1, y + height - 2);
2568 if (style->ythickness > 0)
2569 gdk_draw_line (window, gc2,
2570 x, y, x + width - 1, y);
2571 if (style->xthickness > 0)
2572 gdk_draw_line (window, gc2,
2573 x, y, x, y + height - 1);
2576 case GTK_SHADOW_OUT:
2577 /* Dark around right and bottom edge */
2579 if (style->ythickness > 0)
2581 if (style->ythickness > 1)
2583 gdk_draw_line (window, gc1,
2584 x + 1, y + height - 2, x + width - 2, y + height - 2);
2585 gdk_draw_line (window, style->black_gc,
2586 x, y + height - 1, x + width - 1, y + height - 1);
2590 gdk_draw_line (window, gc1,
2591 x + 1, y + height - 1, x + width - 1, y + height - 1);
2595 if (style->xthickness > 0)
2597 if (style->xthickness > 1)
2599 gdk_draw_line (window, gc1,
2600 x + width - 2, y + 1, x + width - 2, y + height - 2);
2602 gdk_draw_line (window, style->black_gc,
2603 x + width - 1, y, x + width - 1, y + height - 1);
2607 gdk_draw_line (window, gc1,
2608 x + width - 1, y + 1, x + width - 1, y + height - 1);
2612 /* Light around top and left */
2614 if (style->ythickness > 0)
2615 gdk_draw_line (window, gc2,
2616 x, y, x + width - 2, y);
2617 if (style->xthickness > 0)
2618 gdk_draw_line (window, gc2,
2619 x, y, x, y + height - 2);
2621 if (style->ythickness > 1)
2622 gdk_draw_line (window, style->bg_gc[state_type],
2623 x + 1, y + 1, x + width - 3, y + 1);
2624 if (style->xthickness > 1)
2625 gdk_draw_line (window, style->bg_gc[state_type],
2626 x + 1, y + 1, x + 1, y + height - 3);
2629 case GTK_SHADOW_ETCHED_IN:
2630 case GTK_SHADOW_ETCHED_OUT:
2631 if (style->xthickness > 0)
2633 if (style->xthickness > 1)
2635 thickness_light = 1;
2638 for (i = 0; i < thickness_dark; i++)
2640 gdk_draw_line (window, gc1,
2644 y + height - i - 1);
2645 gdk_draw_line (window, gc2,
2649 y + height - i - 2);
2652 for (i = 0; i < thickness_light; i++)
2654 gdk_draw_line (window, gc1,
2655 x + thickness_dark + i,
2656 y + thickness_dark + i,
2657 x + thickness_dark + i,
2658 y + height - thickness_dark - i - 1);
2659 gdk_draw_line (window, gc2,
2660 x + width - thickness_light - i - 1,
2661 y + thickness_dark + i,
2662 x + width - thickness_light - i - 1,
2663 y + height - thickness_light - 1);
2668 gdk_draw_line (window,
2669 style->dark_gc[state_type],
2670 x, y, x, y + height);
2671 gdk_draw_line (window,
2672 style->dark_gc[state_type],
2673 x + width, y, x + width, y + height);
2677 if (style->ythickness > 0)
2679 if (style->ythickness > 1)
2681 thickness_light = 1;
2684 for (i = 0; i < thickness_dark; i++)
2686 gdk_draw_line (window, gc1,
2690 y + height - i - 1);
2692 gdk_draw_line (window, gc2,
2699 for (i = 0; i < thickness_light; i++)
2701 gdk_draw_line (window, gc1,
2702 x + thickness_dark + i,
2703 y + thickness_dark + i,
2704 x + width - thickness_dark - i - 2,
2705 y + thickness_dark + i);
2707 gdk_draw_line (window, gc2,
2708 x + thickness_dark + i,
2709 y + height - thickness_light - i - 1,
2710 x + width - thickness_light - 1,
2711 y + height - thickness_light - i - 1);
2716 gdk_draw_line (window,
2717 style->dark_gc[state_type],
2718 x, y, x + width, y);
2719 gdk_draw_line (window,
2720 style->dark_gc[state_type],
2721 x, y + height, x + width, y + height);
2728 if (shadow_type == GTK_SHADOW_IN &&
2729 GTK_IS_SPIN_BUTTON (widget) &&
2730 detail && strcmp (detail, "entry") == 0)
2732 if (get_direction (widget) == GTK_TEXT_DIR_LTR)
2734 gdk_draw_line (window,
2735 style->base_gc[state_type],
2736 x + width - 1, y + 2,
2737 x + width - 1, y + height - 3);
2738 gdk_draw_line (window,
2739 style->base_gc[state_type],
2740 x + width - 2, y + 2,
2741 x + width - 2, y + height - 3);
2742 gdk_draw_point (window,
2744 x + width - 1, y + 1);
2745 gdk_draw_point (window,
2746 style->bg_gc[state_type],
2747 x + width - 1, y + height - 2);
2751 gdk_draw_line (window,
2752 style->base_gc[state_type],
2755 gdk_draw_line (window,
2756 style->base_gc[state_type],
2758 x + 1, y + height - 3);
2759 gdk_draw_point (window,
2762 gdk_draw_line (window,
2763 style->bg_gc[state_type],
2765 x + 1, y + height - 2);
2766 gdk_draw_point (window,
2767 style->light_gc[state_type],
2775 gdk_gc_set_clip_rectangle (gc1, NULL);
2776 gdk_gc_set_clip_rectangle (gc2, NULL);
2777 if (shadow_type == GTK_SHADOW_IN ||
2778 shadow_type == GTK_SHADOW_OUT)
2780 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2781 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
2787 gtk_default_draw_polygon (GtkStyle *style,
2789 GtkStateType state_type,
2790 GtkShadowType shadow_type,
2793 const gchar *detail,
2798 static const gdouble pi_over_4 = G_PI_4;
2799 static const gdouble pi_3_over_4 = G_PI_4 * 3;
2809 switch (shadow_type)
2812 gc1 = style->bg_gc[state_type];
2813 gc2 = style->dark_gc[state_type];
2814 gc3 = style->light_gc[state_type];
2815 gc4 = style->black_gc;
2817 case GTK_SHADOW_ETCHED_IN:
2818 gc1 = style->light_gc[state_type];
2819 gc2 = style->dark_gc[state_type];
2820 gc3 = style->dark_gc[state_type];
2821 gc4 = style->light_gc[state_type];
2823 case GTK_SHADOW_OUT:
2824 gc1 = style->dark_gc[state_type];
2825 gc2 = style->light_gc[state_type];
2826 gc3 = style->black_gc;
2827 gc4 = style->bg_gc[state_type];
2829 case GTK_SHADOW_ETCHED_OUT:
2830 gc1 = style->dark_gc[state_type];
2831 gc2 = style->light_gc[state_type];
2832 gc3 = style->light_gc[state_type];
2833 gc4 = style->dark_gc[state_type];
2841 gdk_gc_set_clip_rectangle (gc1, area);
2842 gdk_gc_set_clip_rectangle (gc2, area);
2843 gdk_gc_set_clip_rectangle (gc3, area);
2844 gdk_gc_set_clip_rectangle (gc4, area);
2848 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, npoints);
2852 for (i = 0; i < npoints; i++)
2854 if ((points[i].x == points[i+1].x) &&
2855 (points[i].y == points[i+1].y))
2861 angle = atan2 (points[i+1].y - points[i].y,
2862 points[i+1].x - points[i].x);
2865 if ((angle > -pi_3_over_4) && (angle < pi_over_4))
2867 if (angle > -pi_over_4)
2878 gdk_draw_line (window, gc1,
2879 points[i].x-xadjust, points[i].y-yadjust,
2880 points[i+1].x-xadjust, points[i+1].y-yadjust);
2881 gdk_draw_line (window, gc3,
2882 points[i].x, points[i].y,
2883 points[i+1].x, points[i+1].y);
2887 if ((angle < -pi_3_over_4) || (angle > pi_3_over_4))
2898 gdk_draw_line (window, gc4,
2899 points[i].x+xadjust, points[i].y+yadjust,
2900 points[i+1].x+xadjust, points[i+1].y+yadjust);
2901 gdk_draw_line (window, gc2,
2902 points[i].x, points[i].y,
2903 points[i+1].x, points[i+1].y);
2909 gdk_gc_set_clip_rectangle (gc1, NULL);
2910 gdk_gc_set_clip_rectangle (gc2, NULL);
2911 gdk_gc_set_clip_rectangle (gc3, NULL);
2912 gdk_gc_set_clip_rectangle (gc4, NULL);
2917 draw_arrow (GdkWindow *window,
2920 GtkArrowType arrow_type,
2926 cairo_t *cr = gdk_cairo_create (window);
2927 gdk_cairo_set_source_color (cr, color);
2931 gdk_cairo_rectangle (cr, area);
2935 if (arrow_type == GTK_ARROW_DOWN)
2937 cairo_move_to (cr, x, y);
2938 cairo_line_to (cr, x + width, y);
2939 cairo_line_to (cr, x + width / 2., y + height);
2941 else if (arrow_type == GTK_ARROW_UP)
2943 cairo_move_to (cr, x, y + height);
2944 cairo_line_to (cr, x + width / 2., y);
2945 cairo_line_to (cr, x + width, y + height);
2947 else if (arrow_type == GTK_ARROW_LEFT)
2949 cairo_move_to (cr, x + width, y);
2950 cairo_line_to (cr, x + width, y + height);
2951 cairo_line_to (cr, x, y + height / 2.);
2953 else if (arrow_type == GTK_ARROW_RIGHT)
2955 cairo_move_to (cr, x, y);
2956 cairo_line_to (cr, x + width, y + height / 2.);
2957 cairo_line_to (cr, x, y + height);
2960 cairo_close_path (cr);
2967 calculate_arrow_geometry (GtkArrowType arrow_type,
2979 case GTK_ARROW_DOWN:
2989 if (arrow_type == GTK_ARROW_DOWN)
2991 if (*height % 2 == 1 || h % 2 == 0)
2996 if (*height % 2 == 0 || h % 2 == 0)
3001 case GTK_ARROW_RIGHT:
3002 case GTK_ARROW_LEFT:
3012 if (arrow_type == GTK_ARROW_RIGHT)
3014 if (*width % 2 == 1 || w % 2 == 0)
3019 if (*width % 2 == 0 || w % 2 == 0)
3025 /* should not be reached */
3029 *x += (*width - w) / 2;
3030 *y += (*height - h) / 2;
3036 gtk_default_draw_arrow (GtkStyle *style,
3039 GtkShadowType shadow,
3042 const gchar *detail,
3043 GtkArrowType arrow_type,
3050 sanitize_size (window, &width, &height);
3052 calculate_arrow_geometry (arrow_type, &x, &y, &width, &height);
3054 if (detail && strcmp (detail, "menu_scroll_arrow_up") == 0)
3057 if (state == GTK_STATE_INSENSITIVE)
3058 draw_arrow (window, &style->white, area, arrow_type,
3059 x + 1, y + 1, width, height);
3060 draw_arrow (window, &style->fg[state], area, arrow_type,
3061 x, y, width, height);
3065 gtk_default_draw_diamond (GtkStyle *style,
3067 GtkStateType state_type,
3068 GtkShadowType shadow_type,
3071 const gchar *detail,
3079 GdkGC *outer_nw = NULL;
3080 GdkGC *outer_ne = NULL;
3081 GdkGC *outer_sw = NULL;
3082 GdkGC *outer_se = NULL;
3083 GdkGC *middle_nw = NULL;
3084 GdkGC *middle_ne = NULL;
3085 GdkGC *middle_sw = NULL;
3086 GdkGC *middle_se = NULL;
3087 GdkGC *inner_nw = NULL;
3088 GdkGC *inner_ne = NULL;
3089 GdkGC *inner_sw = NULL;
3090 GdkGC *inner_se = NULL;
3092 sanitize_size (window, &width, &height);
3094 half_width = width / 2;
3095 half_height = height / 2;
3099 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
3100 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
3101 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
3102 gdk_gc_set_clip_rectangle (style->black_gc, area);
3105 switch (shadow_type)
3108 inner_sw = inner_se = style->bg_gc[state_type];
3109 middle_sw = middle_se = style->light_gc[state_type];
3110 outer_sw = outer_se = style->light_gc[state_type];
3111 inner_nw = inner_ne = style->black_gc;
3112 middle_nw = middle_ne = style->dark_gc[state_type];
3113 outer_nw = outer_ne = style->dark_gc[state_type];
3116 case GTK_SHADOW_OUT:
3117 inner_sw = inner_se = style->dark_gc[state_type];
3118 middle_sw = middle_se = style->dark_gc[state_type];
3119 outer_sw = outer_se = style->black_gc;
3120 inner_nw = inner_ne = style->bg_gc[state_type];
3121 middle_nw = middle_ne = style->light_gc[state_type];
3122 outer_nw = outer_ne = style->light_gc[state_type];
3125 case GTK_SHADOW_ETCHED_IN:
3126 inner_sw = inner_se = style->bg_gc[state_type];
3127 middle_sw = middle_se = style->dark_gc[state_type];
3128 outer_sw = outer_se = style->light_gc[state_type];
3129 inner_nw = inner_ne = style->bg_gc[state_type];
3130 middle_nw = middle_ne = style->light_gc[state_type];
3131 outer_nw = outer_ne = style->dark_gc[state_type];
3134 case GTK_SHADOW_ETCHED_OUT:
3135 inner_sw = inner_se = style->bg_gc[state_type];
3136 middle_sw = middle_se = style->light_gc[state_type];
3137 outer_sw = outer_se = style->dark_gc[state_type];
3138 inner_nw = inner_ne = style->bg_gc[state_type];
3139 middle_nw = middle_ne = style->dark_gc[state_type];
3140 outer_nw = outer_ne = style->light_gc[state_type];
3150 gdk_draw_line (window, inner_sw,
3151 x + 2, y + half_height,
3152 x + half_width, y + height - 2);
3153 gdk_draw_line (window, inner_se,
3154 x + half_width, y + height - 2,
3155 x + width - 2, y + half_height);
3156 gdk_draw_line (window, middle_sw,
3157 x + 1, y + half_height,
3158 x + half_width, y + height - 1);
3159 gdk_draw_line (window, middle_se,
3160 x + half_width, y + height - 1,
3161 x + width - 1, y + half_height);
3162 gdk_draw_line (window, outer_sw,
3164 x + half_width, y + height);
3165 gdk_draw_line (window, outer_se,
3166 x + half_width, y + height,
3167 x + width, y + half_height);
3169 gdk_draw_line (window, inner_nw,
3170 x + 2, y + half_height,
3171 x + half_width, y + 2);
3172 gdk_draw_line (window, inner_ne,
3173 x + half_width, y + 2,
3174 x + width - 2, y + half_height);
3175 gdk_draw_line (window, middle_nw,
3176 x + 1, y + half_height,
3177 x + half_width, y + 1);
3178 gdk_draw_line (window, middle_ne,
3179 x + half_width, y + 1,
3180 x + width - 1, y + half_height);
3181 gdk_draw_line (window, outer_nw,
3184 gdk_draw_line (window, outer_ne,
3186 x + width, y + half_height);
3191 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
3192 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
3193 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
3194 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
3199 gtk_default_draw_string (GtkStyle *style,
3201 GtkStateType state_type,
3204 const gchar *detail,
3207 const gchar *string)
3211 gdk_gc_set_clip_rectangle (style->white_gc, area);
3212 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], area);
3215 if (state_type == GTK_STATE_INSENSITIVE)
3216 gdk_draw_string (window,
3217 gtk_style_get_font_internal (style),
3218 style->white_gc, x + 1, y + 1, string);
3220 gdk_draw_string (window,
3221 gtk_style_get_font_internal (style),
3222 style->fg_gc[state_type], x, y, string);
3226 gdk_gc_set_clip_rectangle (style->white_gc, NULL);
3227 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], NULL);
3232 option_menu_get_props (GtkWidget *widget,
3233 GtkRequisition *indicator_size,
3234 GtkBorder *indicator_spacing)
3236 GtkRequisition *tmp_size = NULL;
3237 GtkBorder *tmp_spacing = NULL;
3239 if (GTK_IS_OPTION_MENU (widget))
3240 gtk_widget_style_get (widget,
3241 "indicator-size", &tmp_size,
3242 "indicator-spacing", &tmp_spacing,
3247 *indicator_size = *tmp_size;
3248 gtk_requisition_free (tmp_size);
3251 *indicator_size = default_option_indicator_size;
3255 *indicator_spacing = *tmp_spacing;
3256 gtk_border_free (tmp_spacing);
3259 *indicator_spacing = default_option_indicator_spacing;
3263 gtk_default_draw_box (GtkStyle *style,
3265 GtkStateType state_type,
3266 GtkShadowType shadow_type,
3269 const gchar *detail,
3275 gboolean is_spinbutton_box = FALSE;
3277 sanitize_size (window, &width, &height);
3279 if (GTK_IS_SPIN_BUTTON (widget) && detail)
3281 if (strcmp (detail, "spinbutton_up") == 0)
3287 if (get_direction (widget) == GTK_TEXT_DIR_RTL)
3292 is_spinbutton_box = TRUE;
3294 else if (strcmp (detail, "spinbutton_down") == 0)
3299 if (get_direction (widget) == GTK_TEXT_DIR_RTL)
3304 is_spinbutton_box = TRUE;
3308 if (!style->bg_pixmap[state_type] ||
3309 GDK_IS_PIXMAP (window))
3311 GdkGC *gc = style->bg_gc[state_type];
3313 if (state_type == GTK_STATE_SELECTED && detail && strcmp (detail, "paned") == 0)
3315 if (widget && !GTK_WIDGET_HAS_FOCUS (widget))
3316 gc = style->base_gc[GTK_STATE_ACTIVE];
3320 gdk_gc_set_clip_rectangle (gc, area);
3322 gdk_draw_rectangle (window, gc, TRUE,
3323 x, y, width, height);
3325 gdk_gc_set_clip_rectangle (gc, NULL);
3328 gtk_style_apply_default_background (style, window,
3329 widget && !GTK_WIDGET_NO_WINDOW (widget),
3330 state_type, area, x, y, width, height);
3332 if (is_spinbutton_box)
3337 lower_gc = style->dark_gc[state_type];
3338 if (shadow_type == GTK_SHADOW_OUT)
3339 upper_gc = style->light_gc[state_type];
3341 upper_gc = style->dark_gc[state_type];
3345 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
3346 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
3349 gdk_draw_line (window, upper_gc, x, y, x + width - 1, y);
3350 gdk_draw_line (window, lower_gc, x, y + height - 1, x + width - 1, y + height - 1);
3354 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
3355 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
3360 gtk_paint_shadow (style, window, state_type, shadow_type, area, widget, detail,
3361 x, y, width, height);
3363 if (detail && strcmp (detail, "optionmenu") == 0)
3365 GtkRequisition indicator_size;
3366 GtkBorder indicator_spacing;
3369 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
3371 sanitize_size (window, &width, &height);
3373 if (get_direction (widget) == GTK_TEXT_DIR_RTL)
3374 vline_x = x + indicator_size.width + indicator_spacing.left + indicator_spacing.right;
3376 vline_x = x + width - (indicator_size.width + indicator_spacing.left + indicator_spacing.right) - style->xthickness;
3378 gtk_paint_vline (style, window, state_type, area, widget,
3380 y + style->ythickness + 1,
3381 y + height - style->ythickness - 3,
3387 get_darkened_gc (GdkWindow *window,
3388 const GdkColor *color,
3391 GdkColor src = *color;
3392 GdkColor shaded = *color;
3395 gc = gdk_gc_new (window);
3397 while (darken_count)
3399 _gtk_style_shade (&src, &shaded, 0.93);
3404 gdk_gc_set_rgb_fg_color (gc, &shaded);
3410 gtk_default_draw_flat_box (GtkStyle *style,
3412 GtkStateType state_type,
3413 GtkShadowType shadow_type,
3416 const gchar *detail,
3423 GdkGC *freeme = NULL;
3425 sanitize_size (window, &width, &height);
3429 if (state_type == GTK_STATE_SELECTED)
3431 if (!strcmp ("text", detail))
3432 gc1 = style->bg_gc[GTK_STATE_SELECTED];
3433 else if (!strcmp ("cell_even", detail) ||
3434 !strcmp ("cell_odd", detail) ||
3435 !strcmp ("cell_even_ruled", detail) ||
3436 !strcmp ("cell_even_ruled_sorted", detail))
3438 /* This has to be really broken; alex made me do it. -jrb */
3439 if (widget && GTK_WIDGET_HAS_FOCUS (widget))
3440 gc1 = style->base_gc[state_type];
3442 gc1 = style->base_gc[GTK_STATE_ACTIVE];
3444 else if (!strcmp ("cell_odd_ruled", detail) ||
3445 !strcmp ("cell_odd_ruled_sorted", detail))
3447 if (widget && GTK_WIDGET_HAS_FOCUS (widget))
3448 freeme = get_darkened_gc (window, &style->base[state_type], 1);
3450 freeme = get_darkened_gc (window, &style->base[GTK_STATE_ACTIVE], 1);
3455 gc1 = style->bg_gc[state_type];
3460 if (!strcmp ("viewportbin", detail))
3461 gc1 = style->bg_gc[GTK_STATE_NORMAL];
3462 else if (!strcmp ("entry_bg", detail))
3463 gc1 = style->base_gc[state_type];
3465 /* For trees: even rows are base color, odd rows are a shade of
3466 * the base color, the sort column is a shade of the original color
3470 else if (!strcmp ("cell_even", detail) ||
3471 !strcmp ("cell_odd", detail) ||
3472 !strcmp ("cell_even_ruled", detail))
3474 GdkColor *color = NULL;
3476 gtk_widget_style_get (widget,
3477 "even-row-color", &color,
3482 freeme = get_darkened_gc (window, color, 0);
3485 gdk_color_free (color);
3488 gc1 = style->base_gc[state_type];
3490 else if (!strcmp ("cell_odd_ruled", detail))
3492 GdkColor *color = NULL;
3494 gtk_widget_style_get (widget,
3495 "odd-row-color", &color,
3500 freeme = get_darkened_gc (window, color, 0);
3503 gdk_color_free (color);
3507 gtk_widget_style_get (widget,
3508 "even-row-color", &color,
3513 freeme = get_darkened_gc (window, color, 1);
3514 gdk_color_free (color);
3517 freeme = get_darkened_gc (window, &style->base[state_type], 1);
3521 else if (!strcmp ("cell_even_sorted", detail) ||
3522 !strcmp ("cell_odd_sorted", detail) ||
3523 !strcmp ("cell_even_ruled_sorted", detail))
3525 GdkColor *color = NULL;
3527 if (!strcmp ("cell_odd_sorted", detail))
3528 gtk_widget_style_get (widget,
3529 "odd-row-color", &color,
3532 gtk_widget_style_get (widget,
3533 "even-row-color", &color,
3538 freeme = get_darkened_gc (window, color, 1);
3541 gdk_color_free (color);
3545 freeme = get_darkened_gc (window, &style->base[state_type], 1);
3549 else if (!strcmp ("cell_odd_ruled_sorted", detail))
3551 GdkColor *color = NULL;
3553 gtk_widget_style_get (widget,
3554 "odd-row-color", &color,
3559 freeme = get_darkened_gc (window, color, 1);
3562 gdk_color_free (color);
3566 gtk_widget_style_get (widget,
3567 "even-row-color", &color,
3572 freeme = get_darkened_gc (window, color, 2);
3573 gdk_color_free (color);
3576 freeme = get_darkened_gc (window, &style->base[state_type], 2);
3581 gc1 = style->bg_gc[state_type];
3585 gc1 = style->bg_gc[state_type];
3587 if (!style->bg_pixmap[state_type] || gc1 != style->bg_gc[state_type] ||
3588 GDK_IS_PIXMAP (window))
3591 gdk_gc_set_clip_rectangle (gc1, area);
3593 gdk_draw_rectangle (window, gc1, TRUE,
3594 x, y, width, height);
3596 if (detail && !strcmp ("tooltip", detail))
3597 gdk_draw_rectangle (window, style->black_gc, FALSE,
3598 x, y, width - 1, height - 1);
3601 gdk_gc_set_clip_rectangle (gc1, NULL);
3604 gtk_style_apply_default_background (style, window,
3605 widget && !GTK_WIDGET_NO_WINDOW (widget),
3606 state_type, area, x, y, width, height);
3610 g_object_unref (freeme);
3614 gtk_default_draw_check (GtkStyle *style,
3616 GtkStateType state_type,
3617 GtkShadowType shadow_type,
3620 const gchar *detail,
3626 cairo_t *cr = gdk_cairo_create (window);
3627 enum { BUTTON, MENU, CELL } type = BUTTON;
3634 if (strcmp (detail, "cellcheck") == 0)
3636 else if (strcmp (detail, "check") == 0)
3642 gdk_cairo_rectangle (cr, area);
3646 exterior_size = MIN (width, height);
3647 if (exterior_size % 2 == 0) /* Ensure odd */
3650 pad = style->xthickness + MAX (1, (exterior_size - 2 * style->xthickness) / 9);
3651 interior_size = MAX (1, exterior_size - 2 * pad);
3653 if (interior_size < 7)
3656 pad = MAX (0, (exterior_size - interior_size) / 2);
3659 x -= (1 + exterior_size - width) / 2;
3660 y -= (1 + exterior_size - height) / 2;
3667 gdk_cairo_set_source_color (cr, &style->fg[state_type]);
3669 gdk_cairo_set_source_color (cr, &style->text[state_type]);
3671 cairo_set_line_width (cr, 1.0);
3672 cairo_rectangle (cr, x + 0.5, y + 0.5, exterior_size - 1, exterior_size - 1);
3675 gdk_cairo_set_source_color (cr, &style->base[state_type]);
3676 cairo_rectangle (cr, x + 1, y + 1, exterior_size - 2, exterior_size - 2);
3688 gdk_cairo_set_source_color (cr, &style->text[state_type]);
3691 gdk_cairo_set_source_color (cr, &style->fg[state_type]);
3695 if (shadow_type == GTK_SHADOW_IN)
3697 cairo_translate (cr,
3700 cairo_scale (cr, interior_size / 7., interior_size / 7.);
3702 cairo_move_to (cr, 7.0, 0.0);
3703 cairo_line_to (cr, 7.5, 1.0);
3704 cairo_curve_to (cr, 5.3, 2.0,
3707 cairo_curve_to (cr, 3.0, 5.7,
3710 cairo_line_to (cr, 0.2, 3.5);
3711 cairo_curve_to (cr, 1.1, 3.5,
3714 cairo_curve_to (cr, 1.0, 3.9,
3717 cairo_curve_to (cr, 3.5, 3.1,
3723 else if (shadow_type == GTK_SHADOW_ETCHED_IN) /* inconsistent */
3725 int line_thickness = MAX (1, (3 + interior_size * 2) / 7);
3727 cairo_rectangle (cr,
3729 y + pad + (1 + interior_size - line_thickness) / 2,
3739 gtk_default_draw_option (GtkStyle *style,
3741 GtkStateType state_type,
3742 GtkShadowType shadow_type,
3745 const gchar *detail,
3751 cairo_t *cr = gdk_cairo_create (window);
3752 enum { BUTTON, MENU, CELL } type = BUTTON;
3757 if (strcmp (detail, "radio") == 0)
3759 else if (strcmp (detail, "option") == 0)
3765 gdk_cairo_rectangle (cr, area);
3769 exterior_size = MIN (width, height);
3770 if (exterior_size % 2 == 0) /* Ensure odd */
3773 x -= (1 + exterior_size - width) / 2;
3774 y -= (1 + exterior_size - height) / 2;
3780 gdk_cairo_set_source_color (cr, &style->base[state_type]);
3783 x + exterior_size / 2.,
3784 y + exterior_size / 2.,
3785 (exterior_size - 1) / 2.,
3788 cairo_fill_preserve (cr);
3791 gdk_cairo_set_source_color (cr, &style->fg[state_type]);
3793 gdk_cairo_set_source_color (cr, &style->text[state_type]);
3795 cairo_set_line_width (cr, 1.);
3806 gdk_cairo_set_source_color (cr, &style->text[state_type]);
3811 gdk_cairo_set_source_color (cr, &style->fg[state_type]);
3815 if (shadow_type == GTK_SHADOW_IN)
3817 int pad = style->xthickness + MAX (1, 2 * (exterior_size - 2 * style->xthickness) / 9);
3818 int interior_size = MAX (1, exterior_size - 2 * pad);
3820 if (interior_size < 5)
3823 pad = MAX (0, (exterior_size - interior_size) / 2);
3827 x + pad + interior_size / 2.,
3828 y + pad + interior_size / 2.,
3833 else if (shadow_type == GTK_SHADOW_ETCHED_IN) /* inconsistent */
3835 int pad = style->xthickness + MAX (1, (exterior_size - 2 * style->xthickness) / 9);
3836 int interior_size = MAX (1, exterior_size - 2 * pad);
3839 if (interior_size < 7)
3842 pad = MAX (0, (exterior_size - interior_size) / 2);
3845 line_thickness = MAX (1, (3 + interior_size * 2) / 7);
3847 cairo_rectangle (cr,
3849 y + pad + (interior_size - line_thickness) / 2.,
3859 gtk_default_draw_tab (GtkStyle *style,
3861 GtkStateType state_type,
3862 GtkShadowType shadow_type,
3865 const gchar *detail,
3871 #define ARROW_SPACE 4
3873 GtkRequisition indicator_size;
3874 GtkBorder indicator_spacing;
3877 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
3879 indicator_size.width += (indicator_size.width % 2) - 1;
3880 arrow_height = indicator_size.width / 2 + 1;
3882 x += (width - indicator_size.width) / 2;
3883 y += (height - (2 * arrow_height + ARROW_SPACE)) / 2;
3885 if (state_type == GTK_STATE_INSENSITIVE)
3887 draw_arrow (window, &style->white, area,
3888 GTK_ARROW_UP, x + 1, y + 1,
3889 indicator_size.width, arrow_height);
3891 draw_arrow (window, &style->white, area,
3892 GTK_ARROW_DOWN, x + 1, y + arrow_height + ARROW_SPACE + 1,
3893 indicator_size.width, arrow_height);
3896 draw_arrow (window, &style->fg[state_type], area,
3898 indicator_size.width, arrow_height);
3901 draw_arrow (window, &style->fg[state_type], area,
3902 GTK_ARROW_DOWN, x, y + arrow_height + ARROW_SPACE,
3903 indicator_size.width, arrow_height);
3907 gtk_default_draw_shadow_gap (GtkStyle *style,
3909 GtkStateType state_type,
3910 GtkShadowType shadow_type,
3913 const gchar *detail,
3918 GtkPositionType gap_side,
3927 sanitize_size (window, &width, &height);
3929 switch (shadow_type)
3931 case GTK_SHADOW_NONE:
3934 gc1 = style->dark_gc[state_type];
3935 gc2 = style->black_gc;
3936 gc3 = style->bg_gc[state_type];
3937 gc4 = style->light_gc[state_type];
3939 case GTK_SHADOW_ETCHED_IN:
3940 gc1 = style->dark_gc[state_type];
3941 gc2 = style->light_gc[state_type];
3942 gc3 = style->dark_gc[state_type];
3943 gc4 = style->light_gc[state_type];
3945 case GTK_SHADOW_OUT:
3946 gc1 = style->light_gc[state_type];
3947 gc2 = style->bg_gc[state_type];
3948 gc3 = style->dark_gc[state_type];
3949 gc4 = style->black_gc;
3951 case GTK_SHADOW_ETCHED_OUT:
3952 gc1 = style->light_gc[state_type];
3953 gc2 = style->dark_gc[state_type];
3954 gc3 = style->light_gc[state_type];
3955 gc4 = style->dark_gc[state_type];
3960 gdk_gc_set_clip_rectangle (gc1, area);
3961 gdk_gc_set_clip_rectangle (gc2, area);
3962 gdk_gc_set_clip_rectangle (gc3, area);
3963 gdk_gc_set_clip_rectangle (gc4, area);
3966 switch (shadow_type)
3968 case GTK_SHADOW_NONE:
3970 case GTK_SHADOW_OUT:
3971 case GTK_SHADOW_ETCHED_IN:
3972 case GTK_SHADOW_ETCHED_OUT:
3976 gdk_draw_line (window, gc1,
3977 x, y, x, y + height - 1);
3978 gdk_draw_line (window, gc2,
3979 x + 1, y, x + 1, y + height - 2);
3981 gdk_draw_line (window, gc3,
3982 x + 1, y + height - 2, x + width - 2, y + height - 2);
3983 gdk_draw_line (window, gc3,
3984 x + width - 2, y, x + width - 2, y + height - 2);
3985 gdk_draw_line (window, gc4,
3986 x, y + height - 1, x + width - 1, y + height - 1);
3987 gdk_draw_line (window, gc4,
3988 x + width - 1, y, x + width - 1, y + height - 1);
3991 gdk_draw_line (window, gc1,
3992 x, y, x + gap_x - 1, y);
3993 gdk_draw_line (window, gc2,
3994 x + 1, y + 1, x + gap_x - 1, y + 1);
3995 gdk_draw_line (window, gc2,
3996 x + gap_x, y, x + gap_x, y);
3998 if ((width - (gap_x + gap_width)) > 0)
4000 gdk_draw_line (window, gc1,
4001 x + gap_x + gap_width, y, x + width - 2, y);
4002 gdk_draw_line (window, gc2,
4003 x + gap_x + gap_width, y + 1, x + width - 3, y + 1);
4004 gdk_draw_line (window, gc2,
4005 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
4008 case GTK_POS_BOTTOM:
4009 gdk_draw_line (window, gc1,
4010 x, y, x + width - 1, y);
4011 gdk_draw_line (window, gc1,
4012 x, y, x, y + height - 1);
4013 gdk_draw_line (window, gc2,
4014 x + 1, y + 1, x + width - 2, y + 1);
4015 gdk_draw_line (window, gc2,
4016 x + 1, y + 1, x + 1, y + height - 1);
4018 gdk_draw_line (window, gc3,
4019 x + width - 2, y + 1, x + width - 2, y + height - 1);
4020 gdk_draw_line (window, gc4,
4021 x + width - 1, y, x + width - 1, y + height - 1);
4024 gdk_draw_line (window, gc4,
4025 x, y + height - 1, x + gap_x - 1, y + height - 1);
4026 gdk_draw_line (window, gc3,
4027 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
4028 gdk_draw_line (window, gc3,
4029 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
4031 if ((width - (gap_x + gap_width)) > 0)
4033 gdk_draw_line (window, gc4,
4034 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
4035 gdk_draw_line (window, gc3,
4036 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
4037 gdk_draw_line (window, gc3,
4038 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
4042 gdk_draw_line (window, gc1,
4043 x, y, x + width - 1, y);
4044 gdk_draw_line (window, gc2,
4045 x, y + 1, x + width - 2, y + 1);
4047 gdk_draw_line (window, gc3,
4048 x, y + height - 2, x + width - 2, y + height - 2);
4049 gdk_draw_line (window, gc3,
4050 x + width - 2, y + 1, x + width - 2, y + height - 2);
4051 gdk_draw_line (window, gc4,
4052 x, y + height - 1, x + width - 1, y + height - 1);
4053 gdk_draw_line (window, gc4,
4054 x + width - 1, y, x + width - 1, y + height - 1);
4057 gdk_draw_line (window, gc1,
4058 x, y, x, y + gap_x - 1);
4059 gdk_draw_line (window, gc2,
4060 x + 1, y + 1, x + 1, y + gap_x - 1);
4061 gdk_draw_line (window, gc2,
4062 x, y + gap_x, x, y + gap_x);
4064 if ((width - (gap_x + gap_width)) > 0)
4066 gdk_draw_line (window, gc1,
4067 x, y + gap_x + gap_width, x, y + height - 2);
4068 gdk_draw_line (window, gc2,
4069 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
4070 gdk_draw_line (window, gc2,
4071 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
4075 gdk_draw_line (window, gc1,
4076 x, y, x + width - 1, y);
4077 gdk_draw_line (window, gc1,
4078 x, y, x, y + height - 1);
4079 gdk_draw_line (window, gc2,
4080 x + 1, y + 1, x + width - 1, y + 1);
4081 gdk_draw_line (window, gc2,
4082 x + 1, y + 1, x + 1, y + height - 2);
4084 gdk_draw_line (window, gc3,
4085 x + 1, y + height - 2, x + width - 1, y + height - 2);
4086 gdk_draw_line (window, gc4,
4087 x, y + height - 1, x + width - 1, y + height - 1);
4090 gdk_draw_line (window, gc4,
4091 x + width - 1, y, x + width - 1, y + gap_x - 1);
4092 gdk_draw_line (window, gc3,
4093 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
4094 gdk_draw_line (window, gc3,
4095 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
4097 if ((width - (gap_x + gap_width)) > 0)
4099 gdk_draw_line (window, gc4,
4100 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
4101 gdk_draw_line (window, gc3,
4102 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
4103 gdk_draw_line (window, gc3,
4104 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
4112 gdk_gc_set_clip_rectangle (gc1, NULL);
4113 gdk_gc_set_clip_rectangle (gc2, NULL);
4114 gdk_gc_set_clip_rectangle (gc3, NULL);
4115 gdk_gc_set_clip_rectangle (gc4, NULL);
4120 gtk_default_draw_box_gap (GtkStyle *style,
4122 GtkStateType state_type,
4123 GtkShadowType shadow_type,
4126 const gchar *detail,
4131 GtkPositionType gap_side,
4140 gtk_style_apply_default_background (style, window,
4141 widget && !GTK_WIDGET_NO_WINDOW (widget),
4142 state_type, area, x, y, width, height);
4144 sanitize_size (window, &width, &height);
4146 switch (shadow_type)
4148 case GTK_SHADOW_NONE:
4151 gc1 = style->dark_gc[state_type];
4152 gc2 = style->black_gc;
4153 gc3 = style->bg_gc[state_type];
4154 gc4 = style->light_gc[state_type];
4156 case GTK_SHADOW_ETCHED_IN:
4157 gc1 = style->dark_gc[state_type];
4158 gc2 = style->light_gc[state_type];
4159 gc3 = style->dark_gc[state_type];
4160 gc4 = style->light_gc[state_type];
4162 case GTK_SHADOW_OUT:
4163 gc1 = style->light_gc[state_type];
4164 gc2 = style->bg_gc[state_type];
4165 gc3 = style->dark_gc[state_type];
4166 gc4 = style->black_gc;
4168 case GTK_SHADOW_ETCHED_OUT:
4169 gc1 = style->light_gc[state_type];
4170 gc2 = style->dark_gc[state_type];
4171 gc3 = style->light_gc[state_type];
4172 gc4 = style->dark_gc[state_type];
4178 gdk_gc_set_clip_rectangle (gc1, area);
4179 gdk_gc_set_clip_rectangle (gc2, area);
4180 gdk_gc_set_clip_rectangle (gc3, area);
4181 gdk_gc_set_clip_rectangle (gc4, area);
4184 switch (shadow_type)
4186 case GTK_SHADOW_NONE:
4188 case GTK_SHADOW_OUT:
4189 case GTK_SHADOW_ETCHED_IN:
4190 case GTK_SHADOW_ETCHED_OUT:
4194 gdk_draw_line (window, gc1,
4195 x, y, x, y + height - 1);
4196 gdk_draw_line (window, gc2,
4197 x + 1, y, x + 1, y + height - 2);
4199 gdk_draw_line (window, gc3,
4200 x + 1, y + height - 2, x + width - 2, y + height - 2);
4201 gdk_draw_line (window, gc3,
4202 x + width - 2, y, x + width - 2, y + height - 2);
4203 gdk_draw_line (window, gc4,
4204 x, y + height - 1, x + width - 1, y + height - 1);
4205 gdk_draw_line (window, gc4,
4206 x + width - 1, y, x + width - 1, y + height - 1);
4209 gdk_draw_line (window, gc1,
4210 x, y, x + gap_x - 1, y);
4211 gdk_draw_line (window, gc2,
4212 x + 1, y + 1, x + gap_x - 1, y + 1);
4213 gdk_draw_line (window, gc2,
4214 x + gap_x, y, x + gap_x, y);
4216 if ((width - (gap_x + gap_width)) > 0)
4218 gdk_draw_line (window, gc1,
4219 x + gap_x + gap_width, y, x + width - 2, y);
4220 gdk_draw_line (window, gc2,
4221 x + gap_x + gap_width, y + 1, x + width - 2, y + 1);
4222 gdk_draw_line (window, gc2,
4223 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
4226 case GTK_POS_BOTTOM:
4227 gdk_draw_line (window, gc1,
4228 x, y, x + width - 1, y);
4229 gdk_draw_line (window, gc1,
4230 x, y, x, y + height - 1);
4231 gdk_draw_line (window, gc2,
4232 x + 1, y + 1, x + width - 2, y + 1);
4233 gdk_draw_line (window, gc2,
4234 x + 1, y + 1, x + 1, y + height - 1);
4236 gdk_draw_line (window, gc3,
4237 x + width - 2, y + 1, x + width - 2, y + height - 1);
4238 gdk_draw_line (window, gc4,
4239 x + width - 1, y, x + width - 1, y + height - 1);
4242 gdk_draw_line (window, gc4,
4243 x, y + height - 1, x + gap_x - 1, y + height - 1);
4244 gdk_draw_line (window, gc3,
4245 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
4246 gdk_draw_line (window, gc3,
4247 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
4249 if ((width - (gap_x + gap_width)) > 0)
4251 gdk_draw_line (window, gc4,
4252 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
4253 gdk_draw_line (window, gc3,
4254 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
4255 gdk_draw_line (window, gc3,
4256 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
4260 gdk_draw_line (window, gc1,
4261 x, y, x + width - 1, y);
4262 gdk_draw_line (window, gc2,
4263 x, y + 1, x + width - 2, y + 1);
4265 gdk_draw_line (window, gc3,
4266 x, y + height - 2, x + width - 2, y + height - 2);
4267 gdk_draw_line (window, gc3,
4268 x + width - 2, y + 1, x + width - 2, y + height - 2);
4269 gdk_draw_line (window, gc4,
4270 x, y + height - 1, x + width - 1, y + height - 1);
4271 gdk_draw_line (window, gc4,
4272 x + width - 1, y, x + width - 1, y + height - 1);
4275 gdk_draw_line (window, gc1,
4276 x, y, x, y + gap_x - 1);
4277 gdk_draw_line (window, gc2,
4278 x + 1, y + 1, x + 1, y + gap_x - 1);
4279 gdk_draw_line (window, gc2,
4280 x, y + gap_x, x, y + gap_x);
4282 if ((height - (gap_x + gap_width)) > 0)
4284 gdk_draw_line (window, gc1,
4285 x, y + gap_x + gap_width, x, y + height - 2);
4286 gdk_draw_line (window, gc2,
4287 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
4288 gdk_draw_line (window, gc2,
4289 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
4293 gdk_draw_line (window, gc1,
4294 x, y, x + width - 1, y);
4295 gdk_draw_line (window, gc1,
4296 x, y, x, y + height - 1);
4297 gdk_draw_line (window, gc2,
4298 x + 1, y + 1, x + width - 1, y + 1);
4299 gdk_draw_line (window, gc2,
4300 x + 1, y + 1, x + 1, y + height - 2);
4302 gdk_draw_line (window, gc3,
4303 x + 1, y + height - 2, x + width - 1, y + height - 2);
4304 gdk_draw_line (window, gc4,
4305 x, y + height - 1, x + width - 1, y + height - 1);
4308 gdk_draw_line (window, gc4,
4309 x + width - 1, y, x + width - 1, y + gap_x - 1);
4310 gdk_draw_line (window, gc3,
4311 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
4312 gdk_draw_line (window, gc3,
4313 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
4315 if ((height - (gap_x + gap_width)) > 0)
4317 gdk_draw_line (window, gc4,
4318 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
4319 gdk_draw_line (window, gc3,
4320 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
4321 gdk_draw_line (window, gc3,
4322 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
4330 gdk_gc_set_clip_rectangle (gc1, NULL);
4331 gdk_gc_set_clip_rectangle (gc2, NULL);
4332 gdk_gc_set_clip_rectangle (gc3, NULL);
4333 gdk_gc_set_clip_rectangle (gc4, NULL);
4338 gtk_default_draw_extension (GtkStyle *style,
4340 GtkStateType state_type,
4341 GtkShadowType shadow_type,
4344 const gchar *detail,
4349 GtkPositionType gap_side)
4356 gtk_style_apply_default_background (style, window,
4357 widget && !GTK_WIDGET_NO_WINDOW (widget),
4358 GTK_STATE_NORMAL, area, x, y, width, height);
4360 sanitize_size (window, &width, &height);
4362 switch (shadow_type)
4364 case GTK_SHADOW_NONE:
4367 gc1 = style->dark_gc[state_type];
4368 gc2 = style->black_gc;
4369 gc3 = style->bg_gc[state_type];
4370 gc4 = style->light_gc[state_type];
4372 case GTK_SHADOW_ETCHED_IN:
4373 gc1 = style->dark_gc[state_type];
4374 gc2 = style->light_gc[state_type];
4375 gc3 = style->dark_gc[state_type];
4376 gc4 = style->light_gc[state_type];
4378 case GTK_SHADOW_OUT:
4379 gc1 = style->light_gc[state_type];
4380 gc2 = style->bg_gc[state_type];
4381 gc3 = style->dark_gc[state_type];
4382 gc4 = style->black_gc;
4384 case GTK_SHADOW_ETCHED_OUT:
4385 gc1 = style->light_gc[state_type];
4386 gc2 = style->dark_gc[state_type];
4387 gc3 = style->light_gc[state_type];
4388 gc4 = style->dark_gc[state_type];
4394 gdk_gc_set_clip_rectangle (gc1, area);
4395 gdk_gc_set_clip_rectangle (gc2, area);
4396 gdk_gc_set_clip_rectangle (gc3, area);
4397 gdk_gc_set_clip_rectangle (gc4, area);
4400 switch (shadow_type)
4402 case GTK_SHADOW_NONE:
4404 case GTK_SHADOW_OUT:
4405 case GTK_SHADOW_ETCHED_IN:
4406 case GTK_SHADOW_ETCHED_OUT:
4410 gtk_style_apply_default_background (style, window,
4411 widget && !GTK_WIDGET_NO_WINDOW (widget),
4413 x + style->xthickness,
4415 width - (2 * style->xthickness),
4416 height - (style->ythickness));
4417 gdk_draw_line (window, gc1,
4418 x, y, x, y + height - 2);
4419 gdk_draw_line (window, gc2,
4420 x + 1, y, x + 1, y + height - 2);
4422 gdk_draw_line (window, gc3,
4423 x + 2, y + height - 2, x + width - 2, y + height - 2);
4424 gdk_draw_line (window, gc3,
4425 x + width - 2, y, x + width - 2, y + height - 2);
4426 gdk_draw_line (window, gc4,
4427 x + 1, y + height - 1, x + width - 2, y + height - 1);
4428 gdk_draw_line (window, gc4,
4429 x + width - 1, y, x + width - 1, y + height - 2);
4431 case GTK_POS_BOTTOM:
4432 gtk_style_apply_default_background (style, window,
4433 widget && !GTK_WIDGET_NO_WINDOW (widget),
4435 x + style->xthickness,
4436 y + style->ythickness,
4437 width - (2 * style->xthickness),
4438 height - (style->ythickness));
4439 gdk_draw_line (window, gc1,
4440 x + 1, y, x + width - 2, y);
4441 gdk_draw_line (window, gc1,
4442 x, y + 1, x, y + height - 1);
4443 gdk_draw_line (window, gc2,
4444 x + 1, y + 1, x + width - 2, y + 1);
4445 gdk_draw_line (window, gc2,
4446 x + 1, y + 1, x + 1, y + height - 1);
4448 gdk_draw_line (window, gc3,
4449 x + width - 2, y + 2, x + width - 2, y + height - 1);
4450 gdk_draw_line (window, gc4,
4451 x + width - 1, y + 1, x + width - 1, y + height - 1);
4454 gtk_style_apply_default_background (style, window,
4455 widget && !GTK_WIDGET_NO_WINDOW (widget),
4458 y + style->ythickness,
4459 width - (style->xthickness),
4460 height - (2 * style->ythickness));
4461 gdk_draw_line (window, gc1,
4462 x, y, x + width - 2, y);
4463 gdk_draw_line (window, gc2,
4464 x + 1, y + 1, x + width - 2, y + 1);
4466 gdk_draw_line (window, gc3,
4467 x, y + height - 2, x + width - 2, y + height - 2);
4468 gdk_draw_line (window, gc3,
4469 x + width - 2, y + 2, x + width - 2, y + height - 2);
4470 gdk_draw_line (window, gc4,
4471 x, y + height - 1, x + width - 2, y + height - 1);
4472 gdk_draw_line (window, gc4,
4473 x + width - 1, y + 1, x + width - 1, y + height - 2);
4476 gtk_style_apply_default_background (style, window,
4477 widget && !GTK_WIDGET_NO_WINDOW (widget),
4479 x + style->xthickness,
4480 y + style->ythickness,
4481 width - (style->xthickness),
4482 height - (2 * style->ythickness));
4483 gdk_draw_line (window, gc1,
4484 x + 1, y, x + width - 1, y);
4485 gdk_draw_line (window, gc1,
4486 x, y + 1, x, y + height - 2);
4487 gdk_draw_line (window, gc2,
4488 x + 1, y + 1, x + width - 1, y + 1);
4489 gdk_draw_line (window, gc2,
4490 x + 1, y + 1, x + 1, y + height - 2);
4492 gdk_draw_line (window, gc3,
4493 x + 2, y + height - 2, x + width - 1, y + height - 2);
4494 gdk_draw_line (window, gc4,
4495 x + 1, y + height - 1, x + width - 1, y + height - 1);
4502 gdk_gc_set_clip_rectangle (gc1, NULL);
4503 gdk_gc_set_clip_rectangle (gc2, NULL);
4504 gdk_gc_set_clip_rectangle (gc3, NULL);
4505 gdk_gc_set_clip_rectangle (gc4, NULL);
4510 gtk_default_draw_focus (GtkStyle *style,
4512 GtkStateType state_type,
4515 const gchar *detail,
4522 gboolean free_dash_list = FALSE;
4523 gint line_width = 1;
4524 gint8 *dash_list = (gint8 *) "\1\1";
4528 gtk_widget_style_get (widget,
4529 "focus-line-width", &line_width,
4530 "focus-line-pattern", (gchar *)&dash_list,
4533 free_dash_list = TRUE;
4536 if (detail && !strcmp (detail, "add-mode"))
4541 dash_list = (gint8 *) "\4\4";
4542 free_dash_list = FALSE;
4545 sanitize_size (window, &width, &height);
4547 cr = gdk_cairo_create (window);
4549 if (detail && !strcmp (detail, "colorwheel_light"))
4550 cairo_set_source_rgb (cr, 0., 0., 0.);
4551 else if (detail && !strcmp (detail, "colorwheel_dark"))
4552 cairo_set_source_rgb (cr, 1., 1., 1.);
4554 gdk_cairo_set_source_color (cr, &style->fg[state_type]);
4556 cairo_set_line_width (cr, line_width);
4560 gint n_dashes = strlen ((const gchar *) dash_list);
4561 gdouble *dashes = g_new (gdouble, n_dashes);
4562 gdouble total_length = 0;
4563 gdouble dash_offset;
4566 for (i = 0; i < n_dashes; i++)
4568 dashes[i] = dash_list[i];
4569 total_length += dash_list[i];
4572 /* The dash offset here aligns the pattern to integer pixels
4573 * by starting the dash at the right side of the left border
4574 * Negative dash offsets in cairo don't work
4575 * (https://bugs.freedesktop.org/show_bug.cgi?id=2729)
4577 dash_offset = - line_width / 2.;
4578 while (dash_offset < 0)
4579 dash_offset += total_length;
4581 cairo_set_dash (cr, dashes, n_dashes, dash_offset);
4587 gdk_cairo_rectangle (cr, area);
4591 cairo_rectangle (cr,
4592 x + line_width / 2.,
4593 y + line_width / 2.,
4595 height - line_width);
4604 gtk_default_draw_slider (GtkStyle *style,
4606 GtkStateType state_type,
4607 GtkShadowType shadow_type,
4610 const gchar *detail,
4615 GtkOrientation orientation)
4617 sanitize_size (window, &width, &height);
4619 gtk_paint_box (style, window, state_type, shadow_type,
4620 area, widget, detail, x, y, width, height);
4623 (strcmp ("hscale", detail) == 0 ||
4624 strcmp ("vscale", detail) == 0))
4626 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4627 gtk_paint_vline (style, window, state_type, area, widget, detail,
4628 y + style->ythickness,
4629 y + height - style->ythickness - 1, x + width / 2);
4631 gtk_paint_hline (style, window, state_type, area, widget, detail,
4632 x + style->xthickness,
4633 x + width - style->xthickness - 1, y + height / 2);
4638 draw_dot (GdkWindow *window,
4645 size = CLAMP (size, 2, 3);
4649 gdk_draw_point (window, light_gc, x, y);
4650 gdk_draw_point (window, light_gc, x+1, y+1);
4654 gdk_draw_point (window, light_gc, x, y);
4655 gdk_draw_point (window, light_gc, x+1, y);
4656 gdk_draw_point (window, light_gc, x, y+1);
4657 gdk_draw_point (window, dark_gc, x+1, y+2);
4658 gdk_draw_point (window, dark_gc, x+2, y+1);
4659 gdk_draw_point (window, dark_gc, x+2, y+2);
4664 gtk_default_draw_handle (GtkStyle *style,
4666 GtkStateType state_type,
4667 GtkShadowType shadow_type,
4670 const gchar *detail,
4675 GtkOrientation orientation)
4678 gint xthick, ythick;
4679 GdkGC *light_gc, *dark_gc;
4680 GdkGC *free_me = NULL;
4685 sanitize_size (window, &width, &height);
4687 gtk_paint_box (style, window, state_type, shadow_type, area, widget,
4688 detail, x, y, width, height);
4691 if (detail && !strcmp (detail, "paned"))
4693 /* we want to ignore the shadow border in paned widgets */
4697 if (state_type == GTK_STATE_SELECTED && widget && !GTK_WIDGET_HAS_FOCUS (widget))
4699 GdkColor unfocused_light;
4701 _gtk_style_shade (&style->base[GTK_STATE_ACTIVE], &unfocused_light,
4704 light_gc = free_me = gdk_gc_new (window);
4705 gdk_gc_set_rgb_fg_color (light_gc, &unfocused_light);
4708 light_gc = style->light_gc[state_type];
4710 dark_gc = style->black_gc;
4714 xthick = style->xthickness;
4715 ythick = style->ythickness;
4717 light_gc = style->light_gc[state_type];
4718 dark_gc = style->dark_gc[state_type];
4721 rect.x = x + xthick;
4722 rect.y = y + ythick;
4723 rect.width = width - (xthick * 2);
4724 rect.height = height - (ythick * 2);
4727 intersect = gdk_rectangle_intersect (area, &rect, &dest);
4737 gdk_gc_set_clip_rectangle (light_gc, &dest);
4738 gdk_gc_set_clip_rectangle (dark_gc, &dest);
4740 if (detail && !strcmp (detail, "paned"))
4742 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4743 for (xx = x + width/2 - 15; xx <= x + width/2 + 15; xx += 5)
4744 draw_dot (window, light_gc, dark_gc, xx, y + height/2 - 1, 3);
4746 for (yy = y + height/2 - 15; yy <= y + height/2 + 15; yy += 5)
4747 draw_dot (window, light_gc, dark_gc, x + width/2 - 1, yy, 3);
4751 for (yy = y + ythick; yy < (y + height - ythick); yy += 3)
4752 for (xx = x + xthick; xx < (x + width - xthick); xx += 6)
4754 draw_dot (window, light_gc, dark_gc, xx, yy, 2);
4755 draw_dot (window, light_gc, dark_gc, xx + 3, yy + 1, 2);
4759 gdk_gc_set_clip_rectangle (light_gc, NULL);
4760 gdk_gc_set_clip_rectangle (dark_gc, NULL);
4764 g_object_unref (free_me);
4768 gtk_default_draw_expander (GtkStyle *style,
4770 GtkStateType state_type,
4773 const gchar *detail,
4776 GtkExpanderStyle expander_style)
4778 #define DEFAULT_EXPANDER_SIZE 12
4782 double vertical_overshoot;
4785 double interp; /* interpolation factor for center position */
4786 double x_double_horz, y_double_horz;
4787 double x_double_vert, y_double_vert;
4788 double x_double, y_double;
4791 cairo_t *cr = gdk_cairo_create (window);
4795 gdk_cairo_rectangle (cr, area);
4800 gtk_widget_class_find_style_property (GTK_WIDGET_GET_CLASS (widget),
4803 gtk_widget_style_get (widget,
4804 "expander-size", &expander_size,
4808 expander_size = DEFAULT_EXPANDER_SIZE;
4810 line_width = MAX (1, expander_size/9);
4812 switch (expander_style)
4814 case GTK_EXPANDER_COLLAPSED:
4815 degrees = (get_direction (widget) == GTK_TEXT_DIR_RTL) ? 180 : 0;
4818 case GTK_EXPANDER_SEMI_COLLAPSED:
4819 degrees = (get_direction (widget) == GTK_TEXT_DIR_RTL) ? 150 : 30;
4822 case GTK_EXPANDER_SEMI_EXPANDED:
4823 degrees = (get_direction (widget) == GTK_TEXT_DIR_RTL) ? 120 : 60;
4826 case GTK_EXPANDER_EXPANDED:
4831 g_assert_not_reached ();
4834 /* Compute distance that the stroke extends beyonds the end
4835 * of the triangle we draw.
4837 vertical_overshoot = line_width / 2.0 * (1. / tan (G_PI / 8));
4839 /* For odd line widths, we end the vertical line of the triangle
4840 * at a half pixel, so we round differently.
4842 if (line_width % 2 == 1)
4843 vertical_overshoot = ceil (0.5 + vertical_overshoot) - 0.5;
4845 vertical_overshoot = ceil (vertical_overshoot);
4847 /* Adjust the size of the triangle we draw so that the entire stroke fits
4849 diameter = MAX (3, expander_size - 2 * vertical_overshoot);
4851 /* If the line width is odd, we want the diameter to be even,
4852 * and vice versa, so force the sum to be odd. This relationship
4853 * makes the point of the triangle look right.
4855 diameter -= (1 - (diameter + line_width) % 2);
4857 radius = diameter / 2.;
4859 /* Adjust the center so that the stroke is properly aligned with
4860 * the pixel grid. The center adjustment is different for the
4861 * horizontal and vertical orientations. For intermediate positions
4862 * we interpolate between the two.
4864 x_double_vert = floor (x - (radius + line_width) / 2.) + (radius + line_width) / 2.;
4865 y_double_vert = y - 0.5;
4867 x_double_horz = x - 0.5;
4868 y_double_horz = floor (y - (radius + line_width) / 2.) + (radius + line_width) / 2.;
4870 x_double = x_double_vert * (1 - interp) + x_double_horz * interp;
4871 y_double = y_double_vert * (1 - interp) + y_double_horz * interp;
4873 cairo_translate (cr, x_double, y_double);
4874 cairo_rotate (cr, degrees * G_PI / 180);
4876 cairo_move_to (cr, - radius / 2., - radius);
4877 cairo_line_to (cr, radius / 2., 0);
4878 cairo_line_to (cr, - radius / 2., radius);
4879 cairo_close_path (cr);
4881 cairo_set_line_width (cr, line_width);
4883 if (state_type == GTK_STATE_PRELIGHT)
4884 gdk_cairo_set_source_color (cr,
4885 &style->fg[GTK_STATE_PRELIGHT]);
4886 else if (state_type == GTK_STATE_ACTIVE)
4887 gdk_cairo_set_source_color (cr,
4888 &style->light[GTK_STATE_ACTIVE]);
4890 gdk_cairo_set_source_color (cr,
4891 &style->base[GTK_STATE_NORMAL]);
4893 cairo_fill_preserve (cr);
4895 gdk_cairo_set_source_color (cr, &style->fg[state_type]);
4901 typedef struct _ByteRange ByteRange;
4910 range_new (guint start,
4913 ByteRange *br = g_new (ByteRange, 1);
4922 get_insensitive_layout (GdkDrawable *drawable,
4923 PangoLayout *layout)
4925 GSList *embossed_ranges = NULL;
4926 GSList *stippled_ranges = NULL;
4927 PangoLayoutIter *iter;
4928 GSList *tmp_list = NULL;
4929 PangoLayout *new_layout;
4930 PangoAttrList *attrs;
4931 GdkBitmap *stipple = NULL;
4933 iter = pango_layout_get_iter (layout);
4937 PangoLayoutRun *run;
4938 PangoAttribute *attr;
4939 gboolean need_stipple = FALSE;
4942 run = pango_layout_iter_get_run_readonly (iter);
4946 tmp_list = run->item->analysis.extra_attrs;
4948 while (tmp_list != NULL)
4950 attr = tmp_list->data;
4951 switch (attr->klass->type)
4953 case PANGO_ATTR_FOREGROUND:
4954 case PANGO_ATTR_BACKGROUND:
4955 need_stipple = TRUE;
4965 tmp_list = g_slist_next (tmp_list);
4968 br = range_new (run->item->offset, run->item->offset + run->item->length);
4971 stippled_ranges = g_slist_prepend (stippled_ranges, br);
4973 embossed_ranges = g_slist_prepend (embossed_ranges, br);
4976 while (pango_layout_iter_next_run (iter));
4978 pango_layout_iter_free (iter);
4980 new_layout = pango_layout_copy (layout);
4982 attrs = pango_layout_get_attributes (new_layout);
4986 /* Create attr list if there wasn't one */
4987 attrs = pango_attr_list_new ();
4988 pango_layout_set_attributes (new_layout, attrs);
4989 pango_attr_list_unref (attrs);
4992 tmp_list = embossed_ranges;
4993 while (tmp_list != NULL)
4995 PangoAttribute *attr;
4996 ByteRange *br = tmp_list->data;
4998 attr = gdk_pango_attr_embossed_new (TRUE);
5000 attr->start_index = br->start;
5001 attr->end_index = br->end;
5003 pango_attr_list_change (attrs, attr);
5007 tmp_list = g_slist_next (tmp_list);
5010 g_slist_free (embossed_ranges);
5012 tmp_list = stippled_ranges;
5013 while (tmp_list != NULL)
5015 PangoAttribute *attr;
5016 ByteRange *br = tmp_list->data;
5018 if (stipple == NULL)
5020 #define gray50_width 2
5021 #define gray50_height 2
5022 static const char gray50_bits[] = {
5026 stipple = gdk_bitmap_create_from_data (drawable,
5027 gray50_bits, gray50_width,
5031 attr = gdk_pango_attr_stipple_new (stipple);
5033 attr->start_index = br->start;
5034 attr->end_index = br->end;
5036 pango_attr_list_change (attrs, attr);
5040 tmp_list = g_slist_next (tmp_list);
5043 g_slist_free (stippled_ranges);
5046 g_object_unref (stipple);
5052 gtk_default_draw_layout (GtkStyle *style,
5054 GtkStateType state_type,
5058 const gchar *detail,
5061 PangoLayout *layout)
5065 gc = use_text ? style->text_gc[state_type] : style->fg_gc[state_type];
5068 gdk_gc_set_clip_rectangle (gc, area);
5070 if (state_type == GTK_STATE_INSENSITIVE)
5074 ins = get_insensitive_layout (window, layout);
5076 gdk_draw_layout (window, gc, x, y, ins);
5078 g_object_unref (ins);
5082 gdk_draw_layout (window, gc, x, y, layout);
5086 gdk_gc_set_clip_rectangle (gc, NULL);
5090 gtk_default_draw_resize_grip (GtkStyle *style,
5092 GtkStateType state_type,
5095 const gchar *detail,
5107 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
5108 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
5109 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
5115 case GDK_WINDOW_EDGE_NORTH_WEST:
5116 /* make it square */
5119 else if (height < width)
5123 case GDK_WINDOW_EDGE_NORTH:
5127 case GDK_WINDOW_EDGE_NORTH_EAST:
5128 /* make it square, aligning to top right */
5131 else if (height < width)
5133 x += (width - height);
5138 case GDK_WINDOW_EDGE_WEST:
5142 case GDK_WINDOW_EDGE_EAST:
5143 /* aligning to right */
5146 x += (width - height);
5150 case GDK_WINDOW_EDGE_SOUTH_WEST:
5151 /* make it square, aligning to bottom left */
5154 y += (height - width);
5157 else if (height < width)
5161 case GDK_WINDOW_EDGE_SOUTH:
5162 /* align to bottom */
5165 y += (height - width);
5169 case GDK_WINDOW_EDGE_SOUTH_EAST:
5170 /* make it square, aligning to bottom right */
5173 y += (height - width);
5176 else if (height < width)
5178 x += (width - height);
5184 g_assert_not_reached ();
5186 /* Clear background */
5188 for (i = 0; i < 4; i++)
5192 points[j].x = (i == 0 || i == 3) ? x : x + width;
5193 points[j].y = (i < 2) ? y : y + height;
5198 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE,
5199 points, skip < 0 ? 4 : 3);
5203 case GDK_WINDOW_EDGE_WEST:
5204 case GDK_WINDOW_EDGE_EAST:
5210 while (xi < x + width)
5212 gdk_draw_line (window,
5213 style->light_gc[state_type],
5218 gdk_draw_line (window,
5219 style->dark_gc[state_type],
5227 case GDK_WINDOW_EDGE_NORTH:
5228 case GDK_WINDOW_EDGE_SOUTH:
5234 while (yi < y + height)
5236 gdk_draw_line (window,
5237 style->light_gc[state_type],
5242 gdk_draw_line (window,
5243 style->dark_gc[state_type],
5251 case GDK_WINDOW_EDGE_NORTH_WEST:
5260 gdk_draw_line (window,
5261 style->dark_gc[state_type],
5268 gdk_draw_line (window,
5269 style->dark_gc[state_type],
5276 gdk_draw_line (window,
5277 style->light_gc[state_type],
5287 case GDK_WINDOW_EDGE_NORTH_EAST:
5294 while (xi < (x + width - 3))
5296 gdk_draw_line (window,
5297 style->light_gc[state_type],
5304 gdk_draw_line (window,
5305 style->dark_gc[state_type],
5312 gdk_draw_line (window,
5313 style->dark_gc[state_type],
5322 case GDK_WINDOW_EDGE_SOUTH_WEST:
5331 gdk_draw_line (window,
5332 style->dark_gc[state_type],
5339 gdk_draw_line (window,
5340 style->dark_gc[state_type],
5347 gdk_draw_line (window,
5348 style->light_gc[state_type],
5358 case GDK_WINDOW_EDGE_SOUTH_EAST:
5365 while (xi < (x + width - 3))
5367 gdk_draw_line (window,
5368 style->light_gc[state_type],
5375 gdk_draw_line (window,
5376 style->dark_gc[state_type],
5383 gdk_draw_line (window,
5384 style->dark_gc[state_type],
5394 g_assert_not_reached ();
5400 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
5401 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
5402 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
5407 _gtk_style_shade (const GdkColor *a,
5415 red = (gdouble) a->red / 65535.0;
5416 green = (gdouble) a->green / 65535.0;
5417 blue = (gdouble) a->blue / 65535.0;
5419 rgb_to_hls (&red, &green, &blue);
5424 else if (green < 0.0)
5430 else if (blue < 0.0)
5433 hls_to_rgb (&red, &green, &blue);
5435 b->red = red * 65535.0;
5436 b->green = green * 65535.0;
5437 b->blue = blue * 65535.0;
5441 rgb_to_hls (gdouble *r,
5482 l = (max + min) / 2;
5489 s = (max - min) / (max + min);
5491 s = (max - min) / (2 - max - min);
5495 h = (green - blue) / delta;
5496 else if (green == max)
5497 h = 2 + (blue - red) / delta;
5498 else if (blue == max)
5499 h = 4 + (red - green) / delta;
5512 hls_to_rgb (gdouble *h,
5525 if (lightness <= 0.5)
5526 m2 = lightness * (1 + saturation);
5528 m2 = lightness + saturation - lightness * saturation;
5529 m1 = 2 * lightness - m2;
5531 if (saturation == 0)
5546 r = m1 + (m2 - m1) * hue / 60;
5550 r = m1 + (m2 - m1) * (240 - hue) / 60;
5561 g = m1 + (m2 - m1) * hue / 60;
5565 g = m1 + (m2 - m1) * (240 - hue) / 60;
5576 b = m1 + (m2 - m1) * hue / 60;
5580 b = m1 + (m2 - m1) * (240 - hue) / 60;
5593 * @style: a #GtkStyle
5594 * @window: a #GdkWindow
5595 * @state_type: a state
5596 * @area: rectangle to which the output is clipped, or %NULL if the
5597 * output should not be clipped
5598 * @widget: the widget (may be %NULL)
5599 * @detail: a style detail (may be %NULL)
5600 * @x1: the starting x coordinate
5601 * @x2: the ending x coordinate
5602 * @y: the y coordinate
5604 * Draws a horizontal line from (@x1, @y) to (@x2, @y) in @window
5605 * using the given style and state.
5608 gtk_paint_hline (GtkStyle *style,
5610 GtkStateType state_type,
5611 const GdkRectangle *area,
5613 const gchar *detail,
5618 g_return_if_fail (GTK_IS_STYLE (style));
5619 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
5620 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
5622 GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type,
5623 (GdkRectangle *) area, widget, detail,
5629 * @style: a #GtkStyle
5630 * @window: a #GdkWindow
5631 * @state_type: a state
5632 * @area: rectangle to which the output is clipped, or %NULL if the
5633 * output should not be clipped
5634 * @widget: the widget (may be %NULL)
5635 * @detail: a style detail (may be %NULL)
5636 * @y1_: the starting y coordinate
5637 * @y2_: the ending y coordinate
5638 * @x: the x coordinate
5640 * Draws a vertical line from (@x, @y1_) to (@x, @y2_) in @window
5641 * using the given style and state.
5644 gtk_paint_vline (GtkStyle *style,
5646 GtkStateType state_type,
5647 const GdkRectangle *area,
5649 const gchar *detail,
5654 g_return_if_fail (GTK_IS_STYLE (style));
5655 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
5656 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
5658 GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type,
5659 (GdkRectangle *) area, widget, detail,
5665 * @style: a #GtkStyle
5666 * @window: a #GdkWindow
5667 * @state_type: a state
5668 * @shadow_type: type of shadow to draw
5669 * @area: clip rectangle or %NULL if the
5670 * output should not be clipped
5671 * @widget: the widget (may be %NULL)
5672 * @detail: a style detail (may be %NULL)
5673 * @x: x origin of the rectangle
5674 * @y: y origin of the rectangle
5675 * @width: width of the rectangle
5676 * @height: width of the rectangle
5678 * Draws a shadow around the given rectangle in @window
5679 * using the given style and state and shadow type.
5682 gtk_paint_shadow (GtkStyle *style,
5684 GtkStateType state_type,
5685 GtkShadowType shadow_type,
5686 const GdkRectangle *area,
5688 const gchar *detail,
5694 g_return_if_fail (GTK_IS_STYLE (style));
5695 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
5696 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
5698 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type,
5699 (GdkRectangle *) area, widget, detail,
5700 x, y, width, height);
5704 * gtk_paint_polygon:
5705 * @style: a #GtkStyle
5706 * @window: a #GdkWindow
5707 * @state_type: a state
5708 * @shadow_type: type of shadow to draw
5709 * @area: clip rectangle, or %NULL if the
5710 * output should not be clipped
5711 * @widget: the widget (may be %NULL)
5712 * @detail: a style detail (may be %NULL)
5713 * @points: an array of #GdkPoint<!-- -->s
5714 * @n_points: length of @points
5715 * @fill: %TRUE if the polygon should be filled
5717 * Draws a polygon on @window with the given parameters.
5720 gtk_paint_polygon (GtkStyle *style,
5722 GtkStateType state_type,
5723 GtkShadowType shadow_type,
5724 const GdkRectangle *area,
5726 const gchar *detail,
5727 const GdkPoint *points,
5731 g_return_if_fail (GTK_IS_STYLE (style));
5732 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_polygon != NULL);
5733 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
5735 GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type,
5736 (GdkRectangle *) area, widget, detail,
5737 (GdkPoint *) points, n_points, fill);
5742 * @style: a #GtkStyle
5743 * @window: a #GdkWindow
5744 * @state_type: a state
5745 * @shadow_type: the type of shadow to draw
5746 * @area: clip rectangle, or %NULL if the
5747 * output should not be clipped
5748 * @widget: the widget (may be %NULL)
5749 * @detail: a style detail (may be %NULL)
5750 * @arrow_type: the type of arrow to draw
5751 * @fill: %TRUE if the arrow tip should be filled
5752 * @x: x origin of the rectangle to draw the arrow in
5753 * @y: y origin of the rectangle to draw the arrow in
5754 * @width: width of the rectangle to draw the arrow in
5755 * @height: height of the rectangle to draw the arrow in
5757 * Draws an arrow in the given rectangle on @window using the given
5758 * parameters. @arrow_type determines the direction of the arrow.
5761 gtk_paint_arrow (GtkStyle *style,
5763 GtkStateType state_type,
5764 GtkShadowType shadow_type,
5765 const GdkRectangle *area,
5767 const gchar *detail,
5768 GtkArrowType arrow_type,
5775 g_return_if_fail (GTK_IS_STYLE (style));
5776 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
5777 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
5779 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type,
5780 (GdkRectangle *) area, widget, detail,
5781 arrow_type, fill, x, y, width, height);
5785 * gtk_paint_diamond:
5786 * @style: a #GtkStyle
5787 * @window: a #GdkWindow
5788 * @state_type: a state
5789 * @shadow_type: the type of shadow to draw
5790 * @area: clip rectangle, or %NULL if the
5791 * output should not be clipped
5792 * @widget: the widget (may be %NULL)
5793 * @detail: a style detail (may be %NULL)
5794 * @x: x origin of the rectangle to draw the diamond in
5795 * @y: y origin of the rectangle to draw the diamond in
5796 * @width: width of the rectangle to draw the diamond in
5797 * @height: height of the rectangle to draw the diamond in
5799 * Draws a diamond in the given rectangle on @window using the given
5803 gtk_paint_diamond (GtkStyle *style,
5805 GtkStateType state_type,
5806 GtkShadowType shadow_type,
5807 const GdkRectangle *area,
5809 const gchar *detail,
5815 g_return_if_fail (GTK_IS_STYLE (style));
5816 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
5817 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
5819 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type,
5820 (GdkRectangle *) area, widget, detail,
5821 x, y, width, height);
5826 * @style: a #GtkStyle
5827 * @window: a #GdkWindow
5828 * @state_type: a state
5829 * @area: clip rectangle, or %NULL if the
5830 * output should not be clipped
5831 * @widget: the widget (may be %NULL)
5832 * @detail: a style detail (may be %NULL)
5835 * @string: the string to draw
5837 * Draws a text string on @window with the given parameters.
5839 * Deprecated: 2.0: Use gtk_paint_layout() instead.
5842 gtk_paint_string (GtkStyle *style,
5844 GtkStateType state_type,
5845 const GdkRectangle *area,
5847 const gchar *detail,
5850 const gchar *string)
5852 g_return_if_fail (GTK_IS_STYLE (style));
5853 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
5854 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
5856 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type,
5857 (GdkRectangle *) area, widget, detail,
5863 * @style: a #GtkStyle
5864 * @window: a #GdkWindow
5865 * @state_type: a state
5866 * @shadow_type: the type of shadow to draw
5867 * @area: clip rectangle, or %NULL if the
5868 * output should not be clipped
5869 * @widget: the widget (may be %NULL)
5870 * @detail: a style detail (may be %NULL)
5871 * @x: x origin of the box
5872 * @y: y origin of the box
5873 * @width: the width of the box
5874 * @height: the height of the box
5876 * Draws a box on @window with the given parameters.
5879 gtk_paint_box (GtkStyle *style,
5881 GtkStateType state_type,
5882 GtkShadowType shadow_type,
5883 const GdkRectangle *area,
5885 const gchar *detail,
5891 g_return_if_fail (GTK_IS_STYLE (style));
5892 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
5893 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
5895 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type,
5896 (GdkRectangle *) area, widget, detail,
5897 x, y, width, height);
5901 * gtk_paint_flat_box:
5902 * @style: a #GtkStyle
5903 * @window: a #GdkWindow
5904 * @state_type: a state
5905 * @shadow_type: the type of shadow to draw
5906 * @area: clip rectangle, or %NULL if the
5907 * output should not be clipped
5908 * @widget: the widget (may be %NULL)
5909 * @detail: a style detail (may be %NULL)
5910 * @x: x origin of the box
5911 * @y: y origin of the box
5912 * @width: the width of the box
5913 * @height: the height of the box
5915 * Draws a flat box on @window with the given parameters.
5918 gtk_paint_flat_box (GtkStyle *style,
5920 GtkStateType state_type,
5921 GtkShadowType shadow_type,
5922 const GdkRectangle *area,
5924 const gchar *detail,
5930 g_return_if_fail (GTK_IS_STYLE (style));
5931 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
5932 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
5934 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type,
5935 (GdkRectangle *) area, widget, detail,
5936 x, y, width, height);
5941 * @style: a #GtkStyle
5942 * @window: a #GdkWindow
5943 * @state_type: a state
5944 * @shadow_type: the type of shadow to draw
5945 * @area: clip rectangle, or %NULL if the
5946 * output should not be clipped
5947 * @widget: the widget (may be %NULL)
5948 * @detail: a style detail (may be %NULL)
5949 * @x: x origin of the rectangle to draw the check in
5950 * @y: y origin of the rectangle to draw the check in
5951 * @width: the width of the rectangle to draw the check in
5952 * @height: the height of the rectangle to draw the check in
5954 * Draws a check button indicator in the given rectangle on @window with
5955 * the given parameters.
5958 gtk_paint_check (GtkStyle *style,
5960 GtkStateType state_type,
5961 GtkShadowType shadow_type,
5962 const GdkRectangle *area,
5964 const gchar *detail,
5970 g_return_if_fail (GTK_IS_STYLE (style));
5971 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
5972 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
5974 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type,
5975 (GdkRectangle *) area, widget, detail,
5976 x, y, width, height);
5981 * @style: a #GtkStyle
5982 * @window: a #GdkWindow
5983 * @state_type: a state
5984 * @shadow_type: the type of shadow to draw
5985 * @area: clip rectangle, or %NULL if the
5986 * output should not be clipped
5987 * @widget: the widget (may be %NULL)
5988 * @detail: a style detail (may be %NULL)
5989 * @x: x origin of the rectangle to draw the option in
5990 * @y: y origin of the rectangle to draw the option in
5991 * @width: the width of the rectangle to draw the option in
5992 * @height: the height of the rectangle to draw the option in
5994 * Draws a radio button indicator in the given rectangle on @window with
5995 * the given parameters.
5998 gtk_paint_option (GtkStyle *style,
6000 GtkStateType state_type,
6001 GtkShadowType shadow_type,
6002 const GdkRectangle *area,
6004 const gchar *detail,
6010 g_return_if_fail (GTK_IS_STYLE (style));
6011 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
6012 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
6014 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type,
6015 (GdkRectangle *) area, widget, detail,
6016 x, y, width, height);
6021 * @style: a #GtkStyle
6022 * @window: a #GdkWindow
6023 * @state_type: a state
6024 * @shadow_type: the type of shadow to draw
6025 * @area: clip rectangle, or %NULL if the
6026 * output should not be clipped
6027 * @widget: the widget (may be %NULL)
6028 * @detail: a style detail (may be %NULL)
6029 * @x: x origin of the rectangle to draw the tab in
6030 * @y: y origin of the rectangle to draw the tab in
6031 * @width: the width of the rectangle to draw the tab in
6032 * @height: the height of the rectangle to draw the tab in
6034 * Draws an option menu tab (i.e. the up and down pointing arrows)
6035 * in the given rectangle on @window using the given parameters.
6038 gtk_paint_tab (GtkStyle *style,
6040 GtkStateType state_type,
6041 GtkShadowType shadow_type,
6042 const GdkRectangle *area,
6044 const gchar *detail,
6050 g_return_if_fail (GTK_IS_STYLE (style));
6051 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
6052 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
6054 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type,
6055 (GdkRectangle *) area, widget, detail,
6056 x, y, width, height);
6060 * gtk_paint_shadow_gap:
6061 * @style: a #GtkStyle
6062 * @window: a #GdkWindow
6063 * @state_type: a state
6064 * @shadow_type: type of shadow to draw
6065 * @area: clip rectangle, or %NULL if the
6066 * output should not be clipped
6067 * @widget: the widget (may be %NULL)
6068 * @detail: a style detail (may be %NULL)
6069 * @x: x origin of the rectangle
6070 * @y: y origin of the rectangle
6071 * @width: width of the rectangle
6072 * @height: width of the rectangle
6073 * @gap_side: side in which to leave the gap
6074 * @gap_x: starting position of the gap
6075 * @gap_width: width of the gap
6077 * Draws a shadow around the given rectangle in @window
6078 * using the given style and state and shadow type, leaving a
6082 gtk_paint_shadow_gap (GtkStyle *style,
6084 GtkStateType state_type,
6085 GtkShadowType shadow_type,
6086 const GdkRectangle *area,
6088 const gchar *detail,
6093 GtkPositionType gap_side,
6097 g_return_if_fail (GTK_IS_STYLE (style));
6098 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
6099 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
6101 GTK_STYLE_GET_CLASS (style)->draw_shadow_gap (style, window, state_type, shadow_type,
6102 (GdkRectangle *) area, widget, detail,
6103 x, y, width, height, gap_side, gap_x, gap_width);
6108 * gtk_paint_box_gap:
6109 * @style: a #GtkStyle
6110 * @window: a #GdkWindow
6111 * @state_type: a state
6112 * @shadow_type: type of shadow to draw
6113 * @area: clip rectangle, or %NULL if the
6114 * output should not be clipped
6115 * @widget: the widget (may be %NULL)
6116 * @detail: a style detail (may be %NULL)
6117 * @x: x origin of the rectangle
6118 * @y: y origin of the rectangle
6119 * @width: width of the rectangle
6120 * @height: width of the rectangle
6121 * @gap_side: side in which to leave the gap
6122 * @gap_x: starting position of the gap
6123 * @gap_width: width of the gap
6125 * Draws a box in @window using the given style and state and shadow type,
6126 * leaving a gap in one side.
6129 gtk_paint_box_gap (GtkStyle *style,
6131 GtkStateType state_type,
6132 GtkShadowType shadow_type,
6133 const GdkRectangle *area,
6135 const gchar *detail,
6140 GtkPositionType gap_side,
6144 g_return_if_fail (GTK_IS_STYLE (style));
6145 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
6146 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
6148 GTK_STYLE_GET_CLASS (style)->draw_box_gap (style, window, state_type, shadow_type,
6149 (GdkRectangle *) area, widget, detail,
6150 x, y, width, height, gap_side, gap_x, gap_width);
6154 * gtk_paint_extension:
6155 * @style: a #GtkStyle
6156 * @window: a #GdkWindow
6157 * @state_type: a state
6158 * @shadow_type: type of shadow to draw
6159 * @area: clip rectangle, or %NULL if the
6160 * output should not be clipped
6161 * @widget: the widget (may be %NULL)
6162 * @detail: a style detail (may be %NULL)
6163 * @x: x origin of the extension
6164 * @y: y origin of the extension
6165 * @width: width of the extension
6166 * @height: width of the extension
6167 * @gap_side: the side on to which the extension is attached
6169 * Draws an extension, i.e. a notebook tab.
6172 gtk_paint_extension (GtkStyle *style,
6174 GtkStateType state_type,
6175 GtkShadowType shadow_type,
6176 const GdkRectangle *area,
6178 const gchar *detail,
6183 GtkPositionType gap_side)
6185 g_return_if_fail (GTK_IS_STYLE (style));
6186 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
6187 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
6189 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type,
6190 (GdkRectangle *) area, widget, detail,
6191 x, y, width, height, gap_side);
6196 * @style: a #GtkStyle
6197 * @window: a #GdkWindow
6198 * @state_type: a state
6199 * @area: clip rectangle, or %NULL if the
6200 * output should not be clipped
6201 * @widget: the widget (may be %NULL)
6202 * @detail: a style detail (may be %NULL)
6203 * @x: the x origin of the rectangle around which to draw a focus indicator
6204 * @y: the y origin of the rectangle around which to draw a focus indicator
6205 * @width: the width of the rectangle around which to draw a focus indicator
6206 * @height: the height of the rectangle around which to draw a focus indicator
6208 * Draws a focus indicator around the given rectangle on @window using the
6212 gtk_paint_focus (GtkStyle *style,
6214 GtkStateType state_type,
6215 const GdkRectangle *area,
6217 const gchar *detail,
6223 g_return_if_fail (GTK_IS_STYLE (style));
6224 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
6225 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
6227 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, state_type,
6228 (GdkRectangle *) area, widget, detail,
6229 x, y, width, height);
6234 * @style: a #GtkStyle
6235 * @window: a #GdkWindow
6236 * @state_type: a state
6237 * @shadow_type: a shadow
6238 * @area: clip rectangle, or %NULL if the
6239 * output should not be clipped
6240 * @widget: the widget (may be %NULL)
6241 * @detail: a style detail (may be %NULL)
6242 * @x: the x origin of the rectangle in which to draw a slider
6243 * @y: the y origin of the rectangle in which to draw a slider
6244 * @width: the width of the rectangle in which to draw a slider
6245 * @height: the height of the rectangle in which to draw a slider
6246 * @orientation: the orientation to be used
6248 * Draws a slider in the given rectangle on @window using the
6249 * given style and orientation.
6252 gtk_paint_slider (GtkStyle *style,
6254 GtkStateType state_type,
6255 GtkShadowType shadow_type,
6256 const GdkRectangle *area,
6258 const gchar *detail,
6263 GtkOrientation orientation)
6265 g_return_if_fail (GTK_IS_STYLE (style));
6266 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
6267 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
6269 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type,
6270 (GdkRectangle *) area, widget, detail,
6271 x, y, width, height, orientation);
6276 * @style: a #GtkStyle
6277 * @window: a #GdkWindow
6278 * @state_type: a state
6279 * @shadow_type: type of shadow to draw
6280 * @area: clip rectangle, or %NULL if the
6281 * output should not be clipped
6282 * @widget: the widget (may be %NULL)
6283 * @detail: a style detail (may be %NULL)
6284 * @x: x origin of the handle
6285 * @y: y origin of the handle
6286 * @width: with of the handle
6287 * @height: height of the handle
6288 * @orientation: the orientation of the handle
6290 * Draws a handle as used in #GtkHandleBox and #GtkPaned.
6293 gtk_paint_handle (GtkStyle *style,
6295 GtkStateType state_type,
6296 GtkShadowType shadow_type,
6297 const GdkRectangle *area,
6299 const gchar *detail,
6304 GtkOrientation orientation)
6306 g_return_if_fail (GTK_IS_STYLE (style));
6307 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
6308 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
6310 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type,
6311 (GdkRectangle *) area, widget, detail,
6312 x, y, width, height, orientation);
6316 * gtk_paint_expander:
6317 * @style: a #GtkStyle
6318 * @window: a #GdkWindow
6319 * @state_type: a state
6320 * @area: clip rectangle, or %NULL if the
6321 * output should not be clipped
6322 * @widget: the widget (may be %NULL)
6323 * @detail: a style detail (may be %NULL)
6324 * @x: the x position to draw the expander at
6325 * @y: the y position to draw the expander at
6326 * @expander_style: the style to draw the expander in; determines
6327 * whether the expander is collapsed, expanded, or in an
6328 * intermediate state.
6330 * Draws an expander as used in #GtkTreeView. @x and @y specify the
6331 * center the expander. The size of the expander is determined by the
6332 * "expander-size" style property of @widget. (If widget is not
6333 * specified or doesn't have an "expander-size" property, an
6334 * unspecified default size will be used, since the caller doesn't
6335 * have sufficient information to position the expander, this is
6336 * likely not useful.) The expander is expander_size pixels tall
6337 * in the collapsed position and expander_size pixels wide in the
6338 * expanded position.
6341 gtk_paint_expander (GtkStyle *style,
6343 GtkStateType state_type,
6344 const GdkRectangle *area,
6346 const gchar *detail,
6349 GtkExpanderStyle expander_style)
6351 g_return_if_fail (GTK_IS_STYLE (style));
6352 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
6353 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
6355 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type,
6356 (GdkRectangle *) area, widget, detail,
6357 x, y, expander_style);
6362 * @style: a #GtkStyle
6363 * @window: a #GdkWindow
6364 * @state_type: a state
6365 * @use_text: whether to use the text or foreground
6366 * graphics context of @style
6367 * @area: clip rectangle, or %NULL if the
6368 * output should not be clipped
6369 * @widget: the widget (may be %NULL)
6370 * @detail: a style detail (may be %NULL)
6373 * @layout: the layout to draw
6375 * Draws a layout on @window using the given parameters.
6378 gtk_paint_layout (GtkStyle *style,
6380 GtkStateType state_type,
6382 const GdkRectangle *area,
6384 const gchar *detail,
6387 PangoLayout *layout)
6389 g_return_if_fail (GTK_IS_STYLE (style));
6390 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
6391 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
6393 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, use_text,
6394 (GdkRectangle *) area, widget, detail,
6399 * gtk_paint_resize_grip:
6400 * @style: a #GtkStyle
6401 * @window: a #GdkWindow
6402 * @state_type: a state
6403 * @area: clip rectangle, or %NULL if the
6404 * output should not be clipped
6405 * @widget: the widget (may be %NULL)
6406 * @detail: a style detail (may be %NULL)
6407 * @edge: the edge in which to draw the resize grip
6408 * @x: the x origin of the rectangle in which to draw the resize grip
6409 * @y: the y origin of the rectangle in which to draw the resize grip
6410 * @width: the width of the rectangle in which to draw the resize grip
6411 * @height: the height of the rectangle in which to draw the resize grip
6413 * Draws a resize grip in the given rectangle on @window using the given
6417 gtk_paint_resize_grip (GtkStyle *style,
6419 GtkStateType state_type,
6420 const GdkRectangle *area,
6422 const gchar *detail,
6430 g_return_if_fail (GTK_IS_STYLE (style));
6431 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
6432 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
6434 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, window, state_type,
6435 (GdkRectangle *) area, widget, detail,
6436 edge, x, y, width, height);
6442 * Allocates a new #GtkBorder structure and initializes its elements to zero.
6444 * Returns: a new empty #GtkBorder. The newly allocated #GtkBorder should be
6445 * freed with gtk_border_free()
6450 gtk_border_new (void)
6452 return g_slice_new0 (GtkBorder);
6457 * @border_: a #GtkBorder.
6458 * @returns: a copy of @border_.
6460 * Copies a #GtkBorder structure.
6463 gtk_border_copy (const GtkBorder *border)
6465 g_return_val_if_fail (border != NULL, NULL);
6467 return g_slice_dup (GtkBorder, border);
6472 * @border_: a #GtkBorder.
6474 * Frees a #GtkBorder structure.
6477 gtk_border_free (GtkBorder *border)
6479 g_slice_free (GtkBorder, border);
6483 gtk_border_get_type (void)
6485 static GType our_type = 0;
6488 our_type = g_boxed_type_register_static (I_("GtkBorder"),
6489 (GBoxedCopyFunc) gtk_border_copy,
6490 (GBoxedFreeFunc) gtk_border_free);
6496 gtk_style_get_font_internal (GtkStyle *style)
6498 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
6500 if (style->private_font && style->private_font_desc)
6502 if (!style->font_desc ||
6503 !pango_font_description_equal (style->private_font_desc, style->font_desc))
6505 gdk_font_unref (style->private_font);
6506 style->private_font = NULL;
6508 if (style->private_font_desc)
6510 pango_font_description_free (style->private_font_desc);
6511 style->private_font_desc = NULL;
6516 if (!style->private_font)
6518 GdkDisplay *display;
6520 if (style->colormap)
6522 display = gdk_screen_get_display (gdk_colormap_get_screen (style->colormap));
6526 display = gdk_display_get_default ();
6527 GTK_NOTE (MULTIHEAD,
6528 g_warning ("gtk_style_get_font() should not be called on an unattached style"));
6531 if (style->font_desc)
6533 style->private_font = gdk_font_from_description_for_display (display, style->font_desc);
6534 style->private_font_desc = pango_font_description_copy (style->font_desc);
6537 if (!style->private_font)
6538 style->private_font = gdk_font_load_for_display (display, "fixed");
6540 if (!style->private_font)
6541 g_error ("Unable to load \"fixed\" font");
6544 return style->private_font;
6548 * gtk_style_get_font:
6549 * @style: a #GtkStyle
6551 * Gets the #GdkFont to use for the given style. This is
6552 * meant only as a replacement for direct access to @style->font
6553 * and should not be used in new code. New code should
6554 * use @style->font_desc instead.
6556 * Return value: the #GdkFont for the style. This font is owned
6557 * by the style; if you want to keep around a copy, you must
6558 * call gdk_font_ref().
6561 gtk_style_get_font (GtkStyle *style)
6563 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
6565 return gtk_style_get_font_internal (style);
6569 * gtk_style_set_font:
6570 * @style: a #GtkStyle.
6571 * @font: a #GdkFont, or %NULL to use the #GdkFont corresponding
6572 * to style->font_desc.
6574 * Sets the #GdkFont to use for a given style. This is
6575 * meant only as a replacement for direct access to style->font
6576 * and should not be used in new code. New code should
6577 * use style->font_desc instead.
6580 gtk_style_set_font (GtkStyle *style,
6585 g_return_if_fail (GTK_IS_STYLE (style));
6587 old_font = style->private_font;
6589 style->private_font = font;
6591 gdk_font_ref (font);
6594 gdk_font_unref (old_font);
6596 if (style->private_font_desc)
6598 pango_font_description_free (style->private_font_desc);
6599 style->private_font_desc = NULL;
6603 typedef struct _CursorInfo CursorInfo;
6609 GdkGC *secondary_gc;
6613 style_unrealize_cursor_gcs (GtkStyle *style)
6617 cursor_info = g_object_get_data (G_OBJECT (style), "gtk-style-cursor-info");
6620 if (cursor_info->primary_gc)
6621 gtk_gc_release (cursor_info->primary_gc);
6623 if (cursor_info->secondary_gc)
6624 gtk_gc_release (cursor_info->secondary_gc);
6626 g_free (cursor_info);
6627 g_object_set_data (G_OBJECT (style), I_("gtk-style-cursor-info"), NULL);
6632 make_cursor_gc (GtkWidget *widget,
6633 const gchar *property_name,
6634 const GdkColor *fallback)
6636 GdkGCValues gc_values;
6637 GdkGCValuesMask gc_values_mask;
6638 GdkColor *cursor_color;
6640 gtk_widget_style_get (widget, property_name, &cursor_color, NULL);
6642 gc_values_mask = GDK_GC_FOREGROUND;
6645 gc_values.foreground = *cursor_color;
6646 gdk_color_free (cursor_color);
6649 gc_values.foreground = *fallback;
6651 gdk_rgb_find_color (widget->style->colormap, &gc_values.foreground);
6652 return gtk_gc_get (widget->style->depth, widget->style->colormap, &gc_values, gc_values_mask);
6656 get_insertion_cursor_gc (GtkWidget *widget,
6657 gboolean is_primary)
6659 CursorInfo *cursor_info;
6661 cursor_info = g_object_get_data (G_OBJECT (widget->style), "gtk-style-cursor-info");
6664 cursor_info = g_new (CursorInfo, 1);
6665 g_object_set_data (G_OBJECT (widget->style), I_("gtk-style-cursor-info"), cursor_info);
6666 cursor_info->primary_gc = NULL;
6667 cursor_info->secondary_gc = NULL;
6668 cursor_info->for_type = G_TYPE_INVALID;
6671 /* We have to keep track of the type because gtk_widget_style_get()
6672 * can return different results when called on the same property and
6673 * same style but for different widgets. :-(. That is,
6674 * GtkEntry::cursor-color = "red" in a style will modify the cursor
6675 * color for entries but not for text view.
6677 if (cursor_info->for_type != G_OBJECT_TYPE (widget))
6679 cursor_info->for_type = G_OBJECT_TYPE (widget);
6680 if (cursor_info->primary_gc)
6682 gtk_gc_release (cursor_info->primary_gc);
6683 cursor_info->primary_gc = NULL;
6685 if (cursor_info->secondary_gc)
6687 gtk_gc_release (cursor_info->secondary_gc);
6688 cursor_info->secondary_gc = NULL;
6692 /* Cursors in text widgets are drawn only in NORMAL state,
6693 * so we can use text[GTK_STATE_NORMAL] as text color here */
6696 if (!cursor_info->primary_gc)
6697 cursor_info->primary_gc = make_cursor_gc (widget,
6699 &widget->style->text[GTK_STATE_NORMAL]);
6701 return cursor_info->primary_gc;
6705 if (!cursor_info->secondary_gc)
6706 cursor_info->secondary_gc = make_cursor_gc (widget,
6707 "secondary-cursor-color",
6708 /* text_aa is the average of text and base colors,
6709 * in usual black-on-white case it's grey. */
6710 &widget->style->text_aa[GTK_STATE_NORMAL]);
6712 return cursor_info->secondary_gc;
6717 _gtk_widget_get_cursor_gc (GtkWidget *widget)
6719 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6720 g_return_val_if_fail (GTK_WIDGET_REALIZED (widget), NULL);
6721 return get_insertion_cursor_gc (widget, TRUE);
6725 _gtk_widget_get_cursor_color (GtkWidget *widget,
6728 GdkColor *style_color;
6730 g_return_if_fail (GTK_IS_WIDGET (widget));
6731 g_return_if_fail (color != NULL);
6733 gtk_widget_style_get (widget, "cursor-color", &style_color, NULL);
6737 *color = *style_color;
6738 gdk_color_free (style_color);
6741 *color = widget->style->text[GTK_STATE_NORMAL];
6745 draw_insertion_cursor (GtkWidget *widget,
6746 GdkDrawable *drawable,
6748 const GdkRectangle *location,
6749 GtkTextDirection direction,
6750 gboolean draw_arrow)
6756 gfloat cursor_aspect_ratio;
6759 /* When changing the shape or size of the cursor here,
6760 * propagate the changes to gtktextview.c:text_window_invalidate_cursors().
6763 gtk_widget_style_get (widget, "cursor-aspect-ratio", &cursor_aspect_ratio, NULL);
6765 stem_width = location->height * cursor_aspect_ratio + 1;
6766 arrow_width = stem_width + 1;
6768 /* put (stem_width % 2) on the proper side of the cursor */
6769 if (direction == GTK_TEXT_DIR_LTR)
6770 offset = stem_width / 2;
6772 offset = stem_width - stem_width / 2;
6774 for (i = 0; i < stem_width; i++)
6775 gdk_draw_line (drawable, gc,
6776 location->x + i - offset, location->y,
6777 location->x + i - offset, location->y + location->height - 1);
6781 if (direction == GTK_TEXT_DIR_RTL)
6783 x = location->x - offset - 1;
6784 y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
6786 for (i = 0; i < arrow_width; i++)
6788 gdk_draw_line (drawable, gc,
6790 x, y + 2 * arrow_width - i - 1);
6794 else if (direction == GTK_TEXT_DIR_LTR)
6796 x = location->x + stem_width - offset;
6797 y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
6799 for (i = 0; i < arrow_width; i++)
6801 gdk_draw_line (drawable, gc,
6803 x, y + 2 * arrow_width - i - 1);
6811 * gtk_draw_insertion_cursor:
6812 * @widget: a #GtkWidget
6813 * @drawable: a #GdkDrawable
6814 * @area: rectangle to which the output is clipped, or %NULL if the
6815 * output should not be clipped
6816 * @location: location where to draw the cursor (@location->width is ignored)
6817 * @is_primary: if the cursor should be the primary cursor color.
6818 * @direction: whether the cursor is left-to-right or
6819 * right-to-left. Should never be #GTK_TEXT_DIR_NONE
6820 * @draw_arrow: %TRUE to draw a directional arrow on the
6821 * cursor. Should be %FALSE unless the cursor is split.
6823 * Draws a text caret on @drawable at @location. This is not a style function
6824 * but merely a convenience function for drawing the standard cursor shape.
6829 gtk_draw_insertion_cursor (GtkWidget *widget,
6830 GdkDrawable *drawable,
6831 const GdkRectangle *area,
6832 const GdkRectangle *location,
6833 gboolean is_primary,
6834 GtkTextDirection direction,
6835 gboolean draw_arrow)
6839 g_return_if_fail (GTK_IS_WIDGET (widget));
6840 g_return_if_fail (GDK_IS_DRAWABLE (drawable));
6841 g_return_if_fail (location != NULL);
6842 g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
6844 gc = get_insertion_cursor_gc (widget, is_primary);
6846 gdk_gc_set_clip_rectangle (gc, area);
6848 draw_insertion_cursor (widget, drawable, gc,
6849 location, direction, draw_arrow);
6852 gdk_gc_set_clip_rectangle (gc, NULL);
6855 #define __GTK_STYLE_C__
6856 #include "gtkaliasdef.c"