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"
34 #include "gtkspinbutton.h"
36 #include "gtkwidget.h"
37 #include "gtkthemes.h"
38 #include "gtkiconfactory.h"
39 #include "gtksettings.h" /* _gtk_settings_parse_convert() */
42 #define LIGHTNESS_MULT 1.3
43 #define DARKNESS_MULT 0.7
45 /* --- typedefs & structures --- */
52 /* --- prototypes --- */
53 static void gtk_style_init (GtkStyle *style);
54 static void gtk_style_class_init (GtkStyleClass *klass);
55 static void gtk_style_finalize (GObject *object);
56 static void gtk_style_realize (GtkStyle *style,
57 GdkColormap *colormap);
58 static void gtk_style_real_realize (GtkStyle *style);
59 static void gtk_style_real_unrealize (GtkStyle *style);
60 static void gtk_style_real_copy (GtkStyle *style,
62 static void gtk_style_real_set_background (GtkStyle *style,
64 GtkStateType state_type);
65 static GtkStyle *gtk_style_real_clone (GtkStyle *style);
66 static void gtk_style_real_init_from_rc (GtkStyle *style,
67 GtkRcStyle *rc_style);
68 static GdkPixbuf *gtk_default_render_icon (GtkStyle *style,
69 const GtkIconSource *source,
70 GtkTextDirection direction,
75 static void gtk_default_draw_hline (GtkStyle *style,
77 GtkStateType state_type,
84 static void gtk_default_draw_vline (GtkStyle *style,
86 GtkStateType state_type,
93 static void gtk_default_draw_shadow (GtkStyle *style,
95 GtkStateType state_type,
96 GtkShadowType shadow_type,
104 static void gtk_default_draw_polygon (GtkStyle *style,
106 GtkStateType state_type,
107 GtkShadowType shadow_type,
114 static void gtk_default_draw_arrow (GtkStyle *style,
116 GtkStateType state_type,
117 GtkShadowType shadow_type,
121 GtkArrowType arrow_type,
127 static void gtk_default_draw_diamond (GtkStyle *style,
129 GtkStateType state_type,
130 GtkShadowType shadow_type,
138 static void gtk_default_draw_string (GtkStyle *style,
140 GtkStateType state_type,
146 const gchar *string);
147 static void gtk_default_draw_box (GtkStyle *style,
149 GtkStateType state_type,
150 GtkShadowType shadow_type,
158 static void gtk_default_draw_flat_box (GtkStyle *style,
160 GtkStateType state_type,
161 GtkShadowType shadow_type,
169 static void gtk_default_draw_check (GtkStyle *style,
171 GtkStateType state_type,
172 GtkShadowType shadow_type,
180 static void gtk_default_draw_option (GtkStyle *style,
182 GtkStateType state_type,
183 GtkShadowType shadow_type,
191 static void gtk_default_draw_tab (GtkStyle *style,
193 GtkStateType state_type,
194 GtkShadowType shadow_type,
202 static void gtk_default_draw_shadow_gap (GtkStyle *style,
204 GtkStateType state_type,
205 GtkShadowType shadow_type,
213 GtkPositionType gap_side,
216 static void gtk_default_draw_box_gap (GtkStyle *style,
218 GtkStateType state_type,
219 GtkShadowType shadow_type,
227 GtkPositionType gap_side,
230 static void gtk_default_draw_extension (GtkStyle *style,
232 GtkStateType state_type,
233 GtkShadowType shadow_type,
241 GtkPositionType gap_side);
242 static void gtk_default_draw_focus (GtkStyle *style,
244 GtkStateType state_type,
252 static void gtk_default_draw_slider (GtkStyle *style,
254 GtkStateType state_type,
255 GtkShadowType shadow_type,
263 GtkOrientation orientation);
264 static void gtk_default_draw_handle (GtkStyle *style,
266 GtkStateType state_type,
267 GtkShadowType shadow_type,
275 GtkOrientation orientation);
276 static void gtk_default_draw_expander (GtkStyle *style,
278 GtkStateType state_type,
284 GtkExpanderStyle expander_style);
285 static void gtk_default_draw_layout (GtkStyle *style,
287 GtkStateType state_type,
294 PangoLayout *layout);
295 static void gtk_default_draw_resize_grip (GtkStyle *style,
297 GtkStateType state_type,
307 static void gtk_style_shade (GdkColor *a,
310 static void rgb_to_hls (gdouble *r,
313 static void hls_to_rgb (gdouble *h,
317 static void style_unrealize_cursor_gcs (GtkStyle *style);
319 static GdkFont *gtk_style_get_font_internal (GtkStyle *style);
322 * Data for default check and radio buttons
325 static const GtkRequisition default_option_indicator_size = { 7, 13 };
326 static const GtkBorder default_option_indicator_spacing = { 7, 5, 2, 2 };
328 #define GTK_GRAY 0xdcdc, 0xdada, 0xd5d5
329 #define GTK_DARK_GRAY 0xc4c4, 0xc2c2, 0xbdbd
330 #define GTK_LIGHT_GRAY 0xeeee, 0xebeb, 0xe7e7
331 #define GTK_WHITE 0xffff, 0xffff, 0xffff
332 #define GTK_BLUE 0x4b4b, 0x6969, 0x8383
333 #define GTK_VERY_DARK_GRAY 0x9c9c, 0x9a9a, 0x9494
334 #define GTK_BLACK 0x0000, 0x0000, 0x0000
335 #define GTK_WEAK_GRAY 0x7530, 0x7530, 0x7530
337 /* --- variables --- */
338 static const GdkColor gtk_default_normal_fg = { 0, GTK_BLACK };
339 static const GdkColor gtk_default_active_fg = { 0, GTK_BLACK };
340 static const GdkColor gtk_default_prelight_fg = { 0, GTK_BLACK };
341 static const GdkColor gtk_default_selected_fg = { 0, GTK_WHITE };
342 static const GdkColor gtk_default_insensitive_fg = { 0, GTK_WEAK_GRAY };
344 static const GdkColor gtk_default_normal_bg = { 0, GTK_GRAY };
345 static const GdkColor gtk_default_active_bg = { 0, GTK_DARK_GRAY };
346 static const GdkColor gtk_default_prelight_bg = { 0, GTK_LIGHT_GRAY };
347 static const GdkColor gtk_default_selected_bg = { 0, GTK_BLUE };
348 static const GdkColor gtk_default_insensitive_bg = { 0, GTK_GRAY };
349 static const GdkColor gtk_default_selected_base = { 0, GTK_BLUE };
350 static const GdkColor gtk_default_active_base = { 0, GTK_VERY_DARK_GRAY };
352 static gpointer parent_class = NULL;
354 /* --- signals --- */
355 static guint realize_signal = 0;
356 static guint unrealize_signal = 0;
358 /* --- functions --- */
360 gtk_style_get_type (void)
362 static GType style_type = 0;
366 static const GTypeInfo style_info =
368 sizeof (GtkStyleClass),
369 (GBaseInitFunc) NULL,
370 (GBaseFinalizeFunc) NULL,
371 (GClassInitFunc) gtk_style_class_init,
372 NULL, /* class_finalize */
373 NULL, /* class_data */
376 (GInstanceInitFunc) gtk_style_init,
379 style_type = g_type_register_static (G_TYPE_OBJECT, "GtkStyle",
387 * _gtk_style_init_for_settings:
388 * @style: a #GtkStyle
389 * @settings: a #GtkSettings
391 * Initializes the font description in @style according to the default
392 * font name of @settings. This is called for gtk_style_new() with
393 * the settings for the default screen (if any); if we are creating
394 * a style for a particular screen, we then call it again in a
395 * location where we know the correct settings.
396 * The reason for this is that gtk_rc_style_create_style() doesn't
397 * take the screen for an argument.
400 _gtk_style_init_for_settings (GtkStyle *style,
401 GtkSettings *settings)
403 const gchar *font_name = _gtk_rc_context_get_default_font_name (settings);
405 if (style->font_desc)
406 pango_font_description_free (style->font_desc);
408 style->font_desc = pango_font_description_from_string (font_name);
410 if (!pango_font_description_get_family (style->font_desc))
412 g_warning ("Default font does not have a family set");
413 pango_font_description_set_family (style->font_desc, "Sans");
415 if (pango_font_description_get_size (style->font_desc) <= 0)
417 g_warning ("Default font does not have a positive size");
418 pango_font_description_set_size (style->font_desc, 10 * PANGO_SCALE);
423 gtk_style_init (GtkStyle *style)
427 GtkSettings *settings = gtk_settings_get_default ();
430 _gtk_style_init_for_settings (style, settings);
432 style->font_desc = pango_font_description_from_string ("Sans 10");
434 style->attach_count = 0;
435 style->colormap = NULL;
438 style->black.red = 0;
439 style->black.green = 0;
440 style->black.blue = 0;
442 style->white.red = 65535;
443 style->white.green = 65535;
444 style->white.blue = 65535;
446 style->black_gc = NULL;
447 style->white_gc = NULL;
449 style->fg[GTK_STATE_NORMAL] = gtk_default_normal_fg;
450 style->fg[GTK_STATE_ACTIVE] = gtk_default_active_fg;
451 style->fg[GTK_STATE_PRELIGHT] = gtk_default_prelight_fg;
452 style->fg[GTK_STATE_SELECTED] = gtk_default_selected_fg;
453 style->fg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
455 style->bg[GTK_STATE_NORMAL] = gtk_default_normal_bg;
456 style->bg[GTK_STATE_ACTIVE] = gtk_default_active_bg;
457 style->bg[GTK_STATE_PRELIGHT] = gtk_default_prelight_bg;
458 style->bg[GTK_STATE_SELECTED] = gtk_default_selected_bg;
459 style->bg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_bg;
461 for (i = 0; i < 4; i++)
463 style->text[i] = style->fg[i];
464 style->base[i] = style->white;
467 style->base[GTK_STATE_SELECTED] = gtk_default_selected_base;
468 style->text[GTK_STATE_SELECTED] = style->white;
469 style->base[GTK_STATE_ACTIVE] = gtk_default_active_base;
470 style->text[GTK_STATE_ACTIVE] = style->white;
471 style->base[GTK_STATE_INSENSITIVE] = gtk_default_prelight_bg;
472 style->text[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
474 for (i = 0; i < 5; i++)
475 style->bg_pixmap[i] = NULL;
477 style->rc_style = NULL;
479 for (i = 0; i < 5; i++)
481 style->fg_gc[i] = NULL;
482 style->bg_gc[i] = NULL;
483 style->light_gc[i] = NULL;
484 style->dark_gc[i] = NULL;
485 style->mid_gc[i] = NULL;
486 style->text_gc[i] = NULL;
487 style->base_gc[i] = NULL;
488 style->text_aa_gc[i] = NULL;
491 style->xthickness = 2;
492 style->ythickness = 2;
494 style->property_cache = NULL;
498 gtk_style_class_init (GtkStyleClass *klass)
500 GObjectClass *object_class = G_OBJECT_CLASS (klass);
502 parent_class = g_type_class_peek_parent (klass);
504 object_class->finalize = gtk_style_finalize;
506 klass->clone = gtk_style_real_clone;
507 klass->copy = gtk_style_real_copy;
508 klass->init_from_rc = gtk_style_real_init_from_rc;
509 klass->realize = gtk_style_real_realize;
510 klass->unrealize = gtk_style_real_unrealize;
511 klass->set_background = gtk_style_real_set_background;
512 klass->render_icon = gtk_default_render_icon;
514 klass->draw_hline = gtk_default_draw_hline;
515 klass->draw_vline = gtk_default_draw_vline;
516 klass->draw_shadow = gtk_default_draw_shadow;
517 klass->draw_polygon = gtk_default_draw_polygon;
518 klass->draw_arrow = gtk_default_draw_arrow;
519 klass->draw_diamond = gtk_default_draw_diamond;
520 klass->draw_string = gtk_default_draw_string;
521 klass->draw_box = gtk_default_draw_box;
522 klass->draw_flat_box = gtk_default_draw_flat_box;
523 klass->draw_check = gtk_default_draw_check;
524 klass->draw_option = gtk_default_draw_option;
525 klass->draw_tab = gtk_default_draw_tab;
526 klass->draw_shadow_gap = gtk_default_draw_shadow_gap;
527 klass->draw_box_gap = gtk_default_draw_box_gap;
528 klass->draw_extension = gtk_default_draw_extension;
529 klass->draw_focus = gtk_default_draw_focus;
530 klass->draw_slider = gtk_default_draw_slider;
531 klass->draw_handle = gtk_default_draw_handle;
532 klass->draw_expander = gtk_default_draw_expander;
533 klass->draw_layout = gtk_default_draw_layout;
534 klass->draw_resize_grip = gtk_default_draw_resize_grip;
539 * @style: the object which received the signal
541 * Emitted when the style has been initialized for a particular
542 * colormap and depth. Connecting to this signal is probably seldom
543 * useful since most of the time applications and widgets only
544 * deal with styles that have been already realized.
548 realize_signal = g_signal_new ("realize",
549 G_TYPE_FROM_CLASS (object_class),
551 G_STRUCT_OFFSET (GtkStyleClass, realize),
553 _gtk_marshal_VOID__VOID,
556 * GtkStyle::unrealize:
557 * @style: the object which received the signal
559 * Emitted when the aspects of the style specific to a particular colormap
560 * and depth are being cleaned up. A connection to this signal can be useful
561 * if a widget wants to cache objects like a #GdkGC as object data on #GtkStyle.
562 * This signal provides a convenient place to free such cached objects.
566 unrealize_signal = g_signal_new ("unrealize",
567 G_TYPE_FROM_CLASS (object_class),
569 G_STRUCT_OFFSET (GtkStyleClass, unrealize),
571 _gtk_marshal_VOID__VOID,
576 clear_property_cache (GtkStyle *style)
578 if (style->property_cache)
582 for (i = 0; i < style->property_cache->len; i++)
584 PropertyValue *node = &g_array_index (style->property_cache, PropertyValue, i);
586 g_param_spec_unref (node->pspec);
587 g_value_unset (&node->value);
589 g_array_free (style->property_cache, TRUE);
590 style->property_cache = NULL;
595 gtk_style_finalize (GObject *object)
597 GtkStyle *style = GTK_STYLE (object);
599 g_return_if_fail (style->attach_count == 0);
601 clear_property_cache (style);
603 /* All the styles in the list have the same
604 * style->styles pointer. If we delete the
605 * *first* style from the list, we need to update
606 * the style->styles pointers from all the styles.
607 * Otherwise we simply remove the node from
612 if (style->styles->data != style)
613 g_slist_remove (style->styles, style);
616 GSList *tmp_list = style->styles->next;
620 GTK_STYLE (tmp_list->data)->styles = style->styles->next;
621 tmp_list = tmp_list->next;
623 g_slist_free_1 (style->styles);
627 if (style->icon_factories)
629 GSList *tmp_list = style->icon_factories;
633 g_object_unref (tmp_list->data);
634 tmp_list = tmp_list->next;
637 g_slist_free (style->icon_factories);
640 pango_font_description_free (style->font_desc);
642 if (style->private_font)
643 gdk_font_unref (style->private_font);
645 if (style->private_font_desc)
646 pango_font_description_free (style->private_font_desc);
649 gtk_rc_style_unref (style->rc_style);
651 G_OBJECT_CLASS (parent_class)->finalize (object);
656 gtk_style_copy (GtkStyle *style)
660 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
662 new_style = GTK_STYLE_GET_CLASS (style)->clone (style);
663 GTK_STYLE_GET_CLASS (style)->copy (new_style, style);
669 gtk_style_duplicate (GtkStyle *style)
673 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
675 new_style = gtk_style_copy (style);
677 /* All the styles in the list have the same
678 * style->styles pointer. When we insert a new
679 * style, we append it to the list to avoid having
680 * to update the existing ones.
682 style->styles = g_slist_append (style->styles, new_style);
683 new_style->styles = style->styles;
690 * @returns: a new #GtkStyle.
692 * Creates a new #GtkStyle.
699 style = g_object_new (GTK_TYPE_STYLE, NULL);
706 * @style: a #GtkStyle.
707 * @window: a #GdkWindow.
708 * @returns: Either @style, or a newly-created #GtkStyle.
709 * If the style is newly created, the style parameter
710 * will be dereferenced, and the new style will have
711 * a reference count belonging to the caller.
713 * Attaches a style to a window; this process allocates the
714 * colors and creates the GC's for the style - it specializes
715 * it to a particular visual and colormap. The process may
716 * involve the creation of a new style if the style has already
717 * been attached to a window with a different style and colormap.
720 gtk_style_attach (GtkStyle *style,
724 GtkStyle *new_style = NULL;
725 GdkColormap *colormap;
727 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
728 g_return_val_if_fail (window != NULL, NULL);
730 colormap = gdk_drawable_get_colormap (window);
733 style->styles = g_slist_append (NULL, style);
735 styles = style->styles;
738 new_style = styles->data;
740 if (new_style->colormap == colormap)
744 styles = styles->next;
749 styles = style->styles;
753 new_style = styles->data;
755 if (new_style->attach_count == 0)
757 gtk_style_realize (new_style, colormap);
762 styles = styles->next;
768 new_style = gtk_style_duplicate (style);
769 if (gdk_colormap_get_screen (style->colormap) != gdk_colormap_get_screen (colormap) &&
770 new_style->private_font)
772 gdk_font_unref (new_style->private_font);
773 new_style->private_font = NULL;
775 gtk_style_realize (new_style, colormap);
778 /* A style gets a refcount from being attached */
779 if (new_style->attach_count == 0)
780 g_object_ref (new_style);
782 /* Another refcount belongs to the parent */
783 if (style != new_style)
785 g_object_unref (style);
786 g_object_ref (new_style);
789 new_style->attach_count++;
795 gtk_style_detach (GtkStyle *style)
797 g_return_if_fail (GTK_IS_STYLE (style));
799 style->attach_count -= 1;
800 if (style->attach_count == 0)
802 g_signal_emit (style, unrealize_signal, 0);
804 g_object_unref (style->colormap);
805 style->colormap = NULL;
807 if (style->private_font_desc)
809 if (style->private_font)
811 gdk_font_unref (style->private_font);
812 style->private_font = NULL;
815 pango_font_description_free (style->private_font_desc);
816 style->private_font_desc = NULL;
819 g_object_unref (style);
825 * @style: a #GtkStyle.
828 * Deprecated equivalent of g_object_ref().
831 gtk_style_ref (GtkStyle *style)
833 return (GtkStyle *) g_object_ref (style);
838 * @style: a #GtkStyle.
840 * Deprecated equivalent of g_object_unref().
843 gtk_style_unref (GtkStyle *style)
845 g_object_unref (style);
849 gtk_style_realize (GtkStyle *style,
850 GdkColormap *colormap)
852 g_return_if_fail (GTK_IS_STYLE (style));
853 g_return_if_fail (GDK_IS_COLORMAP (colormap));
855 style->colormap = g_object_ref (colormap);
856 style->depth = gdk_colormap_get_visual (colormap)->depth;
858 g_signal_emit (style, realize_signal, 0);
862 gtk_style_lookup_icon_set (GtkStyle *style,
863 const char *stock_id)
867 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
868 g_return_val_if_fail (stock_id != NULL, NULL);
870 iter = style->icon_factories;
873 GtkIconSet *icon_set = gtk_icon_factory_lookup (GTK_ICON_FACTORY (iter->data),
878 iter = g_slist_next (iter);
881 return gtk_icon_factory_lookup_default (stock_id);
886 * @style: a #GtkStyle
887 * @window: a #GdkWindow
888 * @state_type: a state
889 * @x1: the starting x coordinate
890 * @x2: the ending x coordinate
891 * @y: the y coordinate
893 * Draws a horizontal line from (@x1, @y) to (@x2, @y) in @window
894 * using the given style and state.
896 * Deprecated: Use gtk_paint_hline() instead.
899 gtk_draw_hline (GtkStyle *style,
901 GtkStateType state_type,
906 g_return_if_fail (GTK_IS_STYLE (style));
907 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
909 GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, NULL, NULL, NULL, x1, x2, y);
915 * @style: a #GtkStyle
916 * @window: a #GdkWindow
917 * @state_type: a state
918 * @y1_: the starting y coordinate
919 * @y2_: the ending y coordinate
920 * @x: the x coordinate
922 * Draws a vertical line from (@x, @y1_) to (@x, @y2_) in @window
923 * using the given style and state.
925 * Deprecated: Use gtk_paint_vline() instead.
928 gtk_draw_vline (GtkStyle *style,
930 GtkStateType state_type,
935 g_return_if_fail (GTK_IS_STYLE (style));
936 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
938 GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, NULL, NULL, NULL, y1_, y2_, x);
943 * @style: a #GtkStyle
944 * @window: a #GdkWindow
945 * @state_type: a state
946 * @shadow_type: type of shadow to draw
947 * @x: x origin of the rectangle
948 * @y: y origin of the rectangle
949 * @width: width of the rectangle
950 * @height: width of the rectangle
952 * Draws a shadow around the given rectangle in @window
953 * using the given style and state and shadow type.
955 * Deprecated: Use gtk_paint_shadow() instead.
958 gtk_draw_shadow (GtkStyle *style,
960 GtkStateType state_type,
961 GtkShadowType shadow_type,
967 g_return_if_fail (GTK_IS_STYLE (style));
968 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
970 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
975 * @style: a #GtkStyle
976 * @window: a #GdkWindow
977 * @state_type: a state
978 * @shadow_type: type of shadow to draw
979 * @points: an array of #GdkPoint<!-- -->s
980 * @npoints: length of @points
981 * @fill: %TRUE if the polygon should be filled
983 * Draws a polygon on @window with the given parameters.
985 * Deprecated: Use gtk_paint_polygon() instead.
988 gtk_draw_polygon (GtkStyle *style,
990 GtkStateType state_type,
991 GtkShadowType shadow_type,
996 g_return_if_fail (GTK_IS_STYLE (style));
997 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_polygon != NULL);
999 GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, NULL, NULL, NULL, points, npoints, fill);
1004 * @style: a #GtkStyle
1005 * @window: a #GdkWindow
1006 * @state_type: a state
1007 * @shadow_type: the type of shadow to draw
1008 * @arrow_type: the type of arrow to draw
1009 * @fill: %TRUE if the arrow tip should be filled
1010 * @x: x origin of the rectangle to draw the arrow in
1011 * @y: y origin of the rectangle to draw the arrow in
1012 * @width: width of the rectangle to draw the arrow in
1013 * @height: height of the rectangle to draw the arrow in
1015 * Draws an arrow in the given rectangle on @window using the given
1016 * parameters. @arrow_type determines the direction of the arrow.
1018 * Deprecated: Use gtk_paint_arrow() instead.
1021 gtk_draw_arrow (GtkStyle *style,
1023 GtkStateType state_type,
1024 GtkShadowType shadow_type,
1025 GtkArrowType arrow_type,
1032 g_return_if_fail (GTK_IS_STYLE (style));
1033 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
1035 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, NULL, NULL, NULL, arrow_type, fill, x, y, width, height);
1040 * @style: a #GtkStyle
1041 * @window: a #GdkWindow
1042 * @state_type: a state
1043 * @shadow_type: the type of shadow to draw
1044 * @x: x origin of the rectangle to draw the diamond in
1045 * @y: y origin of the rectangle to draw the diamond in
1046 * @width: width of the rectangle to draw the diamond in
1047 * @height: height of the rectangle to draw the diamond in
1049 * Draws a diamond in the given rectangle on @window using the given
1052 * Deprecated: Use gtk_paint_diamond() instead.
1055 gtk_draw_diamond (GtkStyle *style,
1057 GtkStateType state_type,
1058 GtkShadowType shadow_type,
1064 g_return_if_fail (GTK_IS_STYLE (style));
1065 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
1067 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1072 * @style: a #GtkStyle
1073 * @window: a #GdkWindow
1074 * @state_type: a state
1077 * @string: the string to draw
1079 * Draws a text string on @window with the given parameters.
1081 * Deprecated: Use gtk_paint_layout() instead.
1084 gtk_draw_string (GtkStyle *style,
1086 GtkStateType state_type,
1089 const gchar *string)
1091 g_return_if_fail (GTK_IS_STYLE (style));
1092 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
1094 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, NULL, NULL, NULL, x, y, string);
1099 * @style: a #GtkStyle
1100 * @window: a #GdkWindow
1101 * @state_type: a state
1102 * @shadow_type: the type of shadow to draw
1103 * @x: x origin of the box
1104 * @y: y origin of the box
1105 * @width: the width of the box
1106 * @height: the height of the box
1108 * Draws a box on @window with the given parameters.
1110 * Deprecated: Use gtk_paint_box() instead.
1113 gtk_draw_box (GtkStyle *style,
1115 GtkStateType state_type,
1116 GtkShadowType shadow_type,
1122 g_return_if_fail (GTK_IS_STYLE (style));
1123 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
1125 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1129 * gtk_draw_flat_box:
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 flat box on @window with the given parameters.
1141 * Deprecated: Use gtk_paint_flat_box() instead.
1144 gtk_draw_flat_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_flat_box != NULL);
1156 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
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 rectangle to draw the check in
1166 * @y: y origin of the rectangle to draw the check in
1167 * @width: the width of the rectangle to draw the check in
1168 * @height: the height of the rectangle to draw the check in
1170 * Draws a check button indicator in the given rectangle on @window with
1171 * the given parameters.
1173 * Deprecated: Use gtk_paint_check() instead.
1176 gtk_draw_check (GtkStyle *style,
1178 GtkStateType state_type,
1179 GtkShadowType shadow_type,
1185 g_return_if_fail (GTK_IS_STYLE (style));
1186 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
1188 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1193 * @style: a #GtkStyle
1194 * @window: a #GdkWindow
1195 * @state_type: a state
1196 * @shadow_type: the type of shadow to draw
1197 * @x: x origin of the rectangle to draw the option in
1198 * @y: y origin of the rectangle to draw the option in
1199 * @width: the width of the rectangle to draw the option in
1200 * @height: the height of the rectangle to draw the option in
1202 * Draws a radio button indicator in the given rectangle on @window with
1203 * the given parameters.
1205 * Deprecated: Use gtk_paint_option() instead.
1208 gtk_draw_option (GtkStyle *style,
1210 GtkStateType state_type,
1211 GtkShadowType shadow_type,
1217 g_return_if_fail (GTK_IS_STYLE (style));
1218 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
1220 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1225 * @style: a #GtkStyle
1226 * @window: a #GdkWindow
1227 * @state_type: a state
1228 * @shadow_type: the type of shadow to draw
1229 * @x: x origin of the rectangle to draw the tab in
1230 * @y: y origin of the rectangle to draw the tab in
1231 * @width: the width of the rectangle to draw the tab in
1232 * @height: the height of the rectangle to draw the tab in
1234 * Draws an option menu tab (i.e. the up and down pointing arrows)
1235 * in the given rectangle on @window using the given parameters.
1237 * Deprecated: Use gtk_paint_tab() instead.
1240 gtk_draw_tab (GtkStyle *style,
1242 GtkStateType state_type,
1243 GtkShadowType shadow_type,
1249 g_return_if_fail (GTK_IS_STYLE (style));
1250 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
1252 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1256 * gtk_draw_shadow_gap:
1257 * @style: a #GtkStyle
1258 * @window: a #GdkWindow
1259 * @state_type: a state
1260 * @shadow_type: type of shadow to draw
1261 * @x: x origin of the rectangle
1262 * @y: y origin of the rectangle
1263 * @width: width of the rectangle
1264 * @height: width of the rectangle
1265 * @gap_side: side in which to leave the gap
1266 * @gap_x: starting position of the gap
1267 * @gap_width: width of the gap
1269 * Draws a shadow around the given rectangle in @window
1270 * using the given style and state and shadow type, leaving a
1273 * Deprecated: Use gtk_paint_shadow_gap() instead.
1276 gtk_draw_shadow_gap (GtkStyle *style,
1278 GtkStateType state_type,
1279 GtkShadowType shadow_type,
1284 GtkPositionType gap_side,
1288 g_return_if_fail (GTK_IS_STYLE (style));
1289 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
1291 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);
1296 * @style: a #GtkStyle
1297 * @window: a #GdkWindow
1298 * @state_type: a state
1299 * @shadow_type: type of shadow to draw
1300 * @x: x origin of the rectangle
1301 * @y: y origin of the rectangle
1302 * @width: width of the rectangle
1303 * @height: width of the rectangle
1304 * @gap_side: side in which to leave the gap
1305 * @gap_x: starting position of the gap
1306 * @gap_width: width of the gap
1308 * Draws a box in @window using the given style and state and shadow type,
1309 * leaving a gap in one side.
1311 * Deprecated: Use gtk_paint_box_gap() instead.
1314 gtk_draw_box_gap (GtkStyle *style,
1316 GtkStateType state_type,
1317 GtkShadowType shadow_type,
1322 GtkPositionType gap_side,
1326 g_return_if_fail (GTK_IS_STYLE (style));
1327 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
1329 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);
1333 * gtk_draw_extension:
1334 * @style: a #GtkStyle
1335 * @window: a #GdkWindow
1336 * @state_type: a state
1337 * @shadow_type: type of shadow to draw
1338 * @x: x origin of the extension
1339 * @y: y origin of the extension
1340 * @width: width of the extension
1341 * @height: width of the extension
1342 * @gap_side: the side on to which the extension is attached
1344 * Draws an extension, i.e. a notebook tab.
1346 * Deprecated: Use gtk_paint_extension() instead.
1349 gtk_draw_extension (GtkStyle *style,
1351 GtkStateType state_type,
1352 GtkShadowType shadow_type,
1357 GtkPositionType gap_side)
1359 g_return_if_fail (GTK_IS_STYLE (style));
1360 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
1362 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, gap_side);
1367 * @style: a #GtkStyle
1368 * @window: a #GdkWindow
1369 * @x: the x origin of the rectangle around which to draw a focus indicator
1370 * @y: the y origin of the rectangle around which to draw a focus indicator
1371 * @width: the width of the rectangle around which to draw a focus indicator
1372 * @height: the height of the rectangle around which to draw a focus indicator
1374 * Draws a focus indicator around the given rectangle on @window using the
1377 * Deprecated: Use gtk_paint_focus() instead.
1380 gtk_draw_focus (GtkStyle *style,
1387 g_return_if_fail (GTK_IS_STYLE (style));
1388 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
1390 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, GTK_STATE_NORMAL, NULL, NULL, NULL, x, y, width, height);
1394 gtk_draw_slider (GtkStyle *style,
1396 GtkStateType state_type,
1397 GtkShadowType shadow_type,
1402 GtkOrientation orientation)
1404 g_return_if_fail (GTK_IS_STYLE (style));
1405 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
1407 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
1412 * @style: a #GtkStyle
1413 * @window: a #GdkWindow
1414 * @state_type: a state
1415 * @shadow_type: type of shadow to draw
1416 * @x: x origin of the handle
1417 * @y: y origin of the handle
1418 * @width: with of the handle
1419 * @height: height of the handle
1420 * @orientation: the orientation of the handle
1422 * Draws a handle as used in #GtkHandleBox and #GtkPaned.
1424 * Deprecated: Use gtk_paint_handle() instead.
1427 gtk_draw_handle (GtkStyle *style,
1429 GtkStateType state_type,
1430 GtkShadowType shadow_type,
1435 GtkOrientation orientation)
1437 g_return_if_fail (GTK_IS_STYLE (style));
1438 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
1440 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
1444 * gtk_draw_expander:
1445 * @style: a #GtkStyle
1446 * @window: a #GdkWindow
1447 * @state_type: a state
1448 * @x: the x position to draw the expander at
1449 * @y: the y position to draw the expander at
1450 * @expander_style: the style to draw the expander in
1452 * Draws an expander as used in #GtkTreeView.
1454 * Deprecated: Use gtk_paint_expander() instead.
1457 gtk_draw_expander (GtkStyle *style,
1459 GtkStateType state_type,
1462 GtkExpanderStyle expander_style)
1464 g_return_if_fail (GTK_IS_STYLE (style));
1465 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
1467 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type,
1469 x, y, expander_style);
1473 gtk_draw_layout (GtkStyle *style,
1475 GtkStateType state_type,
1479 PangoLayout *layout)
1481 g_return_if_fail (GTK_IS_STYLE (style));
1482 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
1484 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, use_text,
1490 * gtk_draw_resize_grip:
1491 * @style: a #GtkStyle
1492 * @window: a #GdkWindow
1493 * @state_type: a state
1494 * @edge: the edge in which to draw the resize grip
1495 * @x: the x origin of the rectangle in which to draw the resize grip
1496 * @y: the y origin of the rectangle in which to draw the resize grip
1497 * @width: the width of the rectangle in which to draw the resize grip
1498 * @height: the height of the rectangle in which to draw the resize grip
1500 * Draws a resize grip in the given rectangle on @window using the given
1503 * Deprecated: Use gtk_paint_resize_grip() instead.
1506 gtk_draw_resize_grip (GtkStyle *style,
1508 GtkStateType state_type,
1515 g_return_if_fail (GTK_IS_STYLE (style));
1516 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
1518 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, window, state_type,
1521 x, y, width, height);
1526 * gtk_style_set_background:
1527 * @style: a #GtkStyle
1528 * @window: a #GdkWindow
1529 * @state_type: a state
1531 * Sets the background of @window to the background color or pixmap
1532 * specified by @style for the given state.
1535 gtk_style_set_background (GtkStyle *style,
1537 GtkStateType state_type)
1539 g_return_if_fail (GTK_IS_STYLE (style));
1540 g_return_if_fail (window != NULL);
1542 GTK_STYLE_GET_CLASS (style)->set_background (style, window, state_type);
1545 /* Default functions */
1547 gtk_style_real_clone (GtkStyle *style)
1549 return g_object_new (G_OBJECT_TYPE (style), NULL);
1553 gtk_style_real_copy (GtkStyle *style,
1558 for (i = 0; i < 5; i++)
1560 style->fg[i] = src->fg[i];
1561 style->bg[i] = src->bg[i];
1562 style->text[i] = src->text[i];
1563 style->base[i] = src->base[i];
1565 if (style->bg_pixmap[i])
1566 g_object_unref (style->bg_pixmap[i]),
1567 style->bg_pixmap[i] = src->bg_pixmap[i];
1568 if (style->bg_pixmap[i])
1569 g_object_ref (style->bg_pixmap[i]);
1572 if (style->private_font)
1573 gdk_font_unref (style->private_font);
1574 style->private_font = src->private_font;
1575 if (style->private_font)
1576 gdk_font_ref (style->private_font);
1578 if (style->font_desc)
1579 pango_font_description_free (style->font_desc);
1581 style->font_desc = pango_font_description_copy (src->font_desc);
1583 style->font_desc = NULL;
1585 style->xthickness = src->xthickness;
1586 style->ythickness = src->ythickness;
1588 if (style->rc_style)
1589 gtk_rc_style_unref (style->rc_style);
1590 style->rc_style = src->rc_style;
1592 gtk_rc_style_ref (src->rc_style);
1594 /* don't copy, just clear cache */
1595 clear_property_cache (style);
1599 gtk_style_real_init_from_rc (GtkStyle *style,
1600 GtkRcStyle *rc_style)
1604 /* cache _should_ be still empty */
1605 clear_property_cache (style);
1607 if (rc_style->font_desc)
1608 pango_font_description_merge (style->font_desc, rc_style->font_desc, TRUE);
1610 for (i = 0; i < 5; i++)
1612 if (rc_style->color_flags[i] & GTK_RC_FG)
1613 style->fg[i] = rc_style->fg[i];
1614 if (rc_style->color_flags[i] & GTK_RC_BG)
1615 style->bg[i] = rc_style->bg[i];
1616 if (rc_style->color_flags[i] & GTK_RC_TEXT)
1617 style->text[i] = rc_style->text[i];
1618 if (rc_style->color_flags[i] & GTK_RC_BASE)
1619 style->base[i] = rc_style->base[i];
1622 if (rc_style->xthickness >= 0)
1623 style->xthickness = rc_style->xthickness;
1624 if (rc_style->ythickness >= 0)
1625 style->ythickness = rc_style->ythickness;
1627 if (rc_style->icon_factories)
1631 style->icon_factories = g_slist_copy (rc_style->icon_factories);
1633 iter = style->icon_factories;
1634 while (iter != NULL)
1636 g_object_ref (iter->data);
1637 iter = g_slist_next (iter);
1643 style_property_values_cmp (gconstpointer bsearch_node1,
1644 gconstpointer bsearch_node2)
1646 const PropertyValue *val1 = bsearch_node1;
1647 const PropertyValue *val2 = bsearch_node2;
1649 if (val1->widget_type == val2->widget_type)
1650 return val1->pspec < val2->pspec ? -1 : val1->pspec == val2->pspec ? 0 : 1;
1652 return val1->widget_type < val2->widget_type ? -1 : 1;
1656 _gtk_style_peek_property_value (GtkStyle *style,
1659 GtkRcPropertyParser parser)
1661 PropertyValue *pcache, key = { 0, NULL, { 0, } };
1662 const GtkRcProperty *rcprop = NULL;
1665 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1666 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), NULL);
1667 g_return_val_if_fail (g_type_is_a (pspec->owner_type, GTK_TYPE_WIDGET), NULL);
1668 g_return_val_if_fail (g_type_is_a (widget_type, pspec->owner_type), NULL);
1670 key.widget_type = widget_type;
1673 /* need value cache array */
1674 if (!style->property_cache)
1675 style->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
1678 pcache = bsearch (&key,
1679 style->property_cache->data, style->property_cache->len,
1680 sizeof (PropertyValue), style_property_values_cmp);
1682 return &pcache->value;
1686 while (i < style->property_cache->len &&
1687 style_property_values_cmp (&key, &g_array_index (style->property_cache, PropertyValue, i)) >= 0)
1690 g_array_insert_val (style->property_cache, i, key);
1691 pcache = &g_array_index (style->property_cache, PropertyValue, i);
1693 /* cache miss, initialize value type, then set contents */
1694 g_param_spec_ref (pcache->pspec);
1695 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1697 /* value provided by rc style? */
1698 if (style->rc_style)
1700 GQuark prop_quark = g_quark_from_string (pspec->name);
1704 rcprop = _gtk_rc_style_lookup_rc_property (style->rc_style,
1705 g_type_qname (widget_type),
1709 widget_type = g_type_parent (widget_type);
1711 while (g_type_is_a (widget_type, pspec->owner_type));
1714 /* when supplied by rc style, we need to convert */
1715 if (rcprop && !_gtk_settings_parse_convert (parser, &rcprop->value,
1716 pspec, &pcache->value))
1718 gchar *contents = g_strdup_value_contents (&rcprop->value);
1720 g_message ("%s: failed to retrieve property `%s::%s' of type `%s' from rc file value \"%s\" of type `%s'",
1722 g_type_name (pspec->owner_type), pspec->name,
1723 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1725 G_VALUE_TYPE_NAME (&rcprop->value));
1727 rcprop = NULL; /* needs default */
1730 /* not supplied by rc style (or conversion failed), revert to default */
1732 g_param_value_set_default (pspec, &pcache->value);
1734 return &pcache->value;
1738 load_bg_image (GdkColormap *colormap,
1740 const gchar *filename)
1742 if (strcmp (filename, "<parent>") == 0)
1743 return (GdkPixmap*) GDK_PARENT_RELATIVE;
1746 return gdk_pixmap_colormap_create_from_xpm (NULL, colormap, NULL,
1753 gtk_style_real_realize (GtkStyle *style)
1755 GdkGCValues gc_values;
1756 GdkGCValuesMask gc_values_mask;
1760 for (i = 0; i < 5; i++)
1762 gtk_style_shade (&style->bg[i], &style->light[i], LIGHTNESS_MULT);
1763 gtk_style_shade (&style->bg[i], &style->dark[i], DARKNESS_MULT);
1765 style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
1766 style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
1767 style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
1769 style->text_aa[i].red = (style->text[i].red + style->base[i].red) / 2;
1770 style->text_aa[i].green = (style->text[i].green + style->base[i].green) / 2;
1771 style->text_aa[i].blue = (style->text[i].blue + style->base[i].blue) / 2;
1774 style->black.red = 0x0000;
1775 style->black.green = 0x0000;
1776 style->black.blue = 0x0000;
1777 gdk_colormap_alloc_color (style->colormap, &style->black, FALSE, TRUE);
1779 style->white.red = 0xffff;
1780 style->white.green = 0xffff;
1781 style->white.blue = 0xffff;
1782 gdk_colormap_alloc_color (style->colormap, &style->white, FALSE, TRUE);
1784 gc_values_mask = GDK_GC_FOREGROUND | GDK_GC_BACKGROUND;
1786 gc_values.foreground = style->black;
1787 gc_values.background = style->white;
1788 style->black_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1790 gc_values.foreground = style->white;
1791 gc_values.background = style->black;
1792 style->white_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1794 gc_values_mask = GDK_GC_FOREGROUND;
1796 for (i = 0; i < 5; i++)
1798 if (style->rc_style && style->rc_style->bg_pixmap_name[i])
1799 style->bg_pixmap[i] = load_bg_image (style->colormap,
1801 style->rc_style->bg_pixmap_name[i]);
1803 if (!gdk_colormap_alloc_color (style->colormap, &style->fg[i], FALSE, TRUE))
1804 g_warning ("unable to allocate color: ( %d %d %d )",
1805 style->fg[i].red, style->fg[i].green, style->fg[i].blue);
1806 if (!gdk_colormap_alloc_color (style->colormap, &style->bg[i], FALSE, TRUE))
1807 g_warning ("unable to allocate color: ( %d %d %d )",
1808 style->bg[i].red, style->bg[i].green, style->bg[i].blue);
1809 if (!gdk_colormap_alloc_color (style->colormap, &style->light[i], FALSE, TRUE))
1810 g_warning ("unable to allocate color: ( %d %d %d )",
1811 style->light[i].red, style->light[i].green, style->light[i].blue);
1812 if (!gdk_colormap_alloc_color (style->colormap, &style->dark[i], FALSE, TRUE))
1813 g_warning ("unable to allocate color: ( %d %d %d )",
1814 style->dark[i].red, style->dark[i].green, style->dark[i].blue);
1815 if (!gdk_colormap_alloc_color (style->colormap, &style->mid[i], FALSE, TRUE))
1816 g_warning ("unable to allocate color: ( %d %d %d )",
1817 style->mid[i].red, style->mid[i].green, style->mid[i].blue);
1818 if (!gdk_colormap_alloc_color (style->colormap, &style->text[i], FALSE, TRUE))
1819 g_warning ("unable to allocate color: ( %d %d %d )",
1820 style->text[i].red, style->text[i].green, style->text[i].blue);
1821 if (!gdk_colormap_alloc_color (style->colormap, &style->base[i], FALSE, TRUE))
1822 g_warning ("unable to allocate color: ( %d %d %d )",
1823 style->base[i].red, style->base[i].green, style->base[i].blue);
1824 if (!gdk_colormap_alloc_color (style->colormap, &style->text_aa[i], FALSE, TRUE))
1825 g_warning ("unable to allocate color: ( %d %d %d )",
1826 style->text_aa[i].red, style->text_aa[i].green, style->text_aa[i].blue);
1828 gc_values.foreground = style->fg[i];
1829 style->fg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1831 gc_values.foreground = style->bg[i];
1832 style->bg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1834 gc_values.foreground = style->light[i];
1835 style->light_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1837 gc_values.foreground = style->dark[i];
1838 style->dark_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1840 gc_values.foreground = style->mid[i];
1841 style->mid_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1843 gc_values.foreground = style->text[i];
1844 style->text_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1846 gc_values.foreground = style->base[i];
1847 style->base_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1849 gc_values.foreground = style->text_aa[i];
1850 style->text_aa_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1855 gtk_style_real_unrealize (GtkStyle *style)
1859 gtk_gc_release (style->black_gc);
1860 gtk_gc_release (style->white_gc);
1862 for (i = 0; i < 5; i++)
1864 gtk_gc_release (style->fg_gc[i]);
1865 gtk_gc_release (style->bg_gc[i]);
1866 gtk_gc_release (style->light_gc[i]);
1867 gtk_gc_release (style->dark_gc[i]);
1868 gtk_gc_release (style->mid_gc[i]);
1869 gtk_gc_release (style->text_gc[i]);
1870 gtk_gc_release (style->base_gc[i]);
1871 gtk_gc_release (style->text_aa_gc[i]);
1873 if (style->bg_pixmap[i] && style->bg_pixmap[i] != (GdkPixmap*) GDK_PARENT_RELATIVE)
1875 g_object_unref (style->bg_pixmap[i]);
1876 style->bg_pixmap[i] = NULL;
1881 gdk_colormap_free_colors (style->colormap, style->fg, 5);
1882 gdk_colormap_free_colors (style->colormap, style->bg, 5);
1883 gdk_colormap_free_colors (style->colormap, style->light, 5);
1884 gdk_colormap_free_colors (style->colormap, style->dark, 5);
1885 gdk_colormap_free_colors (style->colormap, style->mid, 5);
1886 gdk_colormap_free_colors (style->colormap, style->text, 5);
1887 gdk_colormap_free_colors (style->colormap, style->base, 5);
1888 gdk_colormap_free_colors (style->colormap, style->text_aa, 5);
1890 style_unrealize_cursor_gcs (style);
1894 gtk_style_real_set_background (GtkStyle *style,
1896 GtkStateType state_type)
1899 gint parent_relative;
1901 if (style->bg_pixmap[state_type])
1903 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1906 parent_relative = TRUE;
1910 pixmap = style->bg_pixmap[state_type];
1911 parent_relative = FALSE;
1914 gdk_window_set_back_pixmap (window, pixmap, parent_relative);
1917 gdk_window_set_background (window, &style->bg[state_type]);
1921 * gtk_style_render_icon:
1922 * @style: a #GtkStyle
1923 * @source: the #GtkIconSource specifying the icon to render
1924 * @direction: a text direction
1926 * @size: the size to render the icon at. A size of (GtkIconSize)-1
1927 * means render at the size of the source and don't scale.
1928 * @widget: the widget
1929 * @detail: a style detail
1930 * @returns: a newly-created #GdkPixbuf containing the rendered icon
1932 * Renders the icon specified by @source at the given @size
1933 * according to the given parameters and returns the result in a
1937 gtk_style_render_icon (GtkStyle *style,
1938 const GtkIconSource *source,
1939 GtkTextDirection direction,
1943 const gchar *detail)
1947 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1948 g_return_val_if_fail (GTK_STYLE_GET_CLASS (style)->render_icon != NULL, NULL);
1950 pixbuf = GTK_STYLE_GET_CLASS (style)->render_icon (style, source, direction, state,
1951 size, widget, detail);
1953 g_return_val_if_fail (pixbuf != NULL, NULL);
1958 /* Default functions */
1960 gtk_style_apply_default_background (GtkStyle *style,
1963 GtkStateType state_type,
1970 GdkRectangle new_rect, old_rect;
1976 old_rect.width = width;
1977 old_rect.height = height;
1979 if (!gdk_rectangle_intersect (area, &old_rect, &new_rect))
1986 new_rect.width = width;
1987 new_rect.height = height;
1990 if (!style->bg_pixmap[state_type] ||
1991 GDK_IS_PIXMAP (window) ||
1992 (!set_bg && style->bg_pixmap[state_type] != (GdkPixmap*) GDK_PARENT_RELATIVE))
1994 GdkGC *gc = style->bg_gc[state_type];
1996 if (style->bg_pixmap[state_type])
1998 gdk_gc_set_fill (gc, GDK_TILED);
1999 gdk_gc_set_tile (gc, style->bg_pixmap[state_type]);
2002 gdk_draw_rectangle (window, gc, TRUE,
2003 new_rect.x, new_rect.y, new_rect.width, new_rect.height);
2004 if (style->bg_pixmap[state_type])
2005 gdk_gc_set_fill (gc, GDK_SOLID);
2011 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
2012 gdk_window_set_back_pixmap (window, NULL, TRUE);
2014 gdk_window_set_back_pixmap (window, style->bg_pixmap[state_type], FALSE);
2017 gdk_window_clear_area (window,
2018 new_rect.x, new_rect.y,
2019 new_rect.width, new_rect.height);
2024 scale_or_ref (GdkPixbuf *src,
2028 if (width == gdk_pixbuf_get_width (src) &&
2029 height == gdk_pixbuf_get_height (src))
2031 return g_object_ref (src);
2035 return gdk_pixbuf_scale_simple (src,
2037 GDK_INTERP_BILINEAR);
2042 gtk_default_render_icon (GtkStyle *style,
2043 const GtkIconSource *source,
2044 GtkTextDirection direction,
2048 const gchar *detail)
2054 GdkPixbuf *base_pixbuf;
2056 GtkSettings *settings;
2058 /* Oddly, style can be NULL in this function, because
2059 * GtkIconSet can be used without a style and if so
2060 * it uses this function.
2063 base_pixbuf = gtk_icon_source_get_pixbuf (source);
2065 g_return_val_if_fail (base_pixbuf != NULL, NULL);
2067 if (widget && gtk_widget_has_screen (widget))
2069 screen = gtk_widget_get_screen (widget);
2070 settings = gtk_settings_get_for_screen (screen);
2072 else if (style && style->colormap)
2074 screen = gdk_colormap_get_screen (style->colormap);
2075 settings = gtk_settings_get_for_screen (screen);
2079 settings = gtk_settings_get_default ();
2080 GTK_NOTE (MULTIHEAD,
2081 g_warning ("Using the default screen for gtk_default_render_icon()"));
2085 if (size != (GtkIconSize) -1 && !gtk_icon_size_lookup_for_settings (settings, size, &width, &height))
2087 g_warning (G_STRLOC ": invalid icon size '%d'", size);
2091 /* If the size was wildcarded, and we're allowed to scale, then scale; otherwise,
2094 if (size != (GtkIconSize)-1 && gtk_icon_source_get_size_wildcarded (source))
2095 scaled = scale_or_ref (base_pixbuf, width, height);
2097 scaled = g_object_ref (base_pixbuf);
2099 /* If the state was wildcarded, then generate a state. */
2100 if (gtk_icon_source_get_state_wildcarded (source))
2102 if (state == GTK_STATE_INSENSITIVE)
2104 stated = gdk_pixbuf_copy (scaled);
2106 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
2109 g_object_unref (scaled);
2111 else if (state == GTK_STATE_PRELIGHT)
2113 stated = gdk_pixbuf_copy (scaled);
2115 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
2118 g_object_unref (scaled);
2132 sanitize_size (GdkWindow *window,
2136 if ((*width == -1) && (*height == -1))
2137 gdk_drawable_get_size (window, width, height);
2138 else if (*width == -1)
2139 gdk_drawable_get_size (window, width, NULL);
2140 else if (*height == -1)
2141 gdk_drawable_get_size (window, NULL, height);
2145 gtk_default_draw_hline (GtkStyle *style,
2147 GtkStateType state_type,
2150 const gchar *detail,
2155 gint thickness_light;
2156 gint thickness_dark;
2159 g_return_if_fail (GTK_IS_STYLE (style));
2160 g_return_if_fail (window != NULL);
2162 thickness_light = style->ythickness / 2;
2163 thickness_dark = style->ythickness - thickness_light;
2167 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
2168 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
2171 if (detail && !strcmp (detail, "label"))
2173 if (state_type == GTK_STATE_INSENSITIVE)
2174 gdk_draw_line (window, style->white_gc, x1 + 1, y + 1, x2 + 1, y + 1);
2175 gdk_draw_line (window, style->fg_gc[state_type], x1, y, x2, y);
2179 for (i = 0; i < thickness_dark; i++)
2181 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x2 - i - 1, y + i);
2182 gdk_draw_line (window, style->light_gc[state_type], x2 - i, y + i, x2, y + i);
2185 y += thickness_dark;
2186 for (i = 0; i < thickness_light; i++)
2188 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x1 + thickness_light - i - 1, y + i);
2189 gdk_draw_line (window, style->light_gc[state_type], x1 + thickness_light - i, y + i, x2, y + i);
2195 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
2196 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
2202 gtk_default_draw_vline (GtkStyle *style,
2204 GtkStateType state_type,
2207 const gchar *detail,
2212 gint thickness_light;
2213 gint thickness_dark;
2216 g_return_if_fail (GTK_IS_STYLE (style));
2217 g_return_if_fail (window != NULL);
2219 thickness_light = style->xthickness / 2;
2220 thickness_dark = style->xthickness - thickness_light;
2224 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
2225 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
2227 for (i = 0; i < thickness_dark; i++)
2229 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y2 - i - 1);
2230 gdk_draw_line (window, style->light_gc[state_type], x + i, y2 - i, x + i, y2);
2233 x += thickness_dark;
2234 for (i = 0; i < thickness_light; i++)
2236 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y1 + thickness_light - i - 1);
2237 gdk_draw_line (window, style->light_gc[state_type], x + i, y1 + thickness_light - i, x + i, y2);
2241 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
2242 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
2247 draw_thin_shadow (GtkStyle *style,
2258 sanitize_size (window, &width, &height);
2260 gc1 = style->light_gc[state];
2261 gc2 = style->dark_gc[state];
2265 gdk_gc_set_clip_rectangle (gc1, area);
2266 gdk_gc_set_clip_rectangle (gc2, area);
2269 gdk_draw_line (window, gc1,
2270 x, y + height - 1, x + width - 1, y + height - 1);
2271 gdk_draw_line (window, gc1,
2272 x + width - 1, y, x + width - 1, y + height - 1);
2274 gdk_draw_line (window, gc2,
2275 x, y, x + width - 2, y);
2276 gdk_draw_line (window, gc2,
2277 x, y, x, y + height - 2);
2281 gdk_gc_set_clip_rectangle (gc1, NULL);
2282 gdk_gc_set_clip_rectangle (gc2, NULL);
2287 draw_spinbutton_shadow (GtkStyle *style,
2290 GtkTextDirection direction,
2297 sanitize_size (window, &width, &height);
2301 gdk_gc_set_clip_rectangle (style->black_gc, area);
2302 gdk_gc_set_clip_rectangle (style->bg_gc[state], area);
2303 gdk_gc_set_clip_rectangle (style->dark_gc[state], area);
2304 gdk_gc_set_clip_rectangle (style->light_gc[state], area);
2307 if (direction == GTK_TEXT_DIR_LTR)
2309 gdk_draw_line (window, style->dark_gc[state],
2310 x, y, x + width - 1, y);
2311 gdk_draw_line (window, style->black_gc,
2312 x, y + 1, x + width - 2, y + 1);
2313 gdk_draw_line (window, style->black_gc,
2314 x + width - 2, y + 2, x + width - 2, y + height - 3);
2315 gdk_draw_line (window, style->light_gc[state],
2316 x + width - 1, y + 1, x + width - 1, y + height - 2);
2317 gdk_draw_line (window, style->light_gc[state],
2318 x, y + height - 1, x + width - 1, y + height - 1);
2319 gdk_draw_line (window, style->bg_gc[state],
2320 x, y + height - 2, x + width - 2, y + height - 2);
2321 gdk_draw_line (window, style->black_gc,
2322 x, y + 2, x, y + height - 3);
2326 gdk_draw_line (window, style->dark_gc[state],
2327 x, y, x + width - 1, y);
2328 gdk_draw_line (window, style->dark_gc[state],
2329 x, y + 1, x, y + height - 1);
2330 gdk_draw_line (window, style->black_gc,
2331 x + 1, y + 1, x + width - 1, y + 1);
2332 gdk_draw_line (window, style->black_gc,
2333 x + 1, y + 2, x + 1, y + height - 2);
2334 gdk_draw_line (window, style->black_gc,
2335 x + width - 1, y + 2, x + width - 1, y + height - 3);
2336 gdk_draw_line (window, style->light_gc[state],
2337 x + 1, y + height - 1, x + width - 1, y + height - 1);
2338 gdk_draw_line (window, style->bg_gc[state],
2339 x + 2, y + height - 2, x + width - 1, y + height - 2);
2344 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2345 gdk_gc_set_clip_rectangle (style->bg_gc[state], NULL);
2346 gdk_gc_set_clip_rectangle (style->dark_gc[state], NULL);
2347 gdk_gc_set_clip_rectangle (style->light_gc[state], NULL);
2352 draw_menu_shadow (GtkStyle *style,
2361 if (style->ythickness > 0)
2363 if (style->ythickness > 1)
2365 gdk_draw_line (window, style->dark_gc[state],
2366 x + 1, y + height - 2, x + width - 2, y + height - 2);
2367 gdk_draw_line (window, style->black_gc,
2368 x, y + height - 1, x + width - 1, y + height - 1);
2372 gdk_draw_line (window, style->dark_gc[state],
2373 x + 1, y + height - 1, x + width - 1, y + height - 1);
2377 if (style->xthickness > 0)
2379 if (style->xthickness > 1)
2381 gdk_draw_line (window, style->dark_gc[state],
2382 x + width - 2, y + 1, x + width - 2, y + height - 2);
2384 gdk_draw_line (window, style->black_gc,
2385 x + width - 1, y, x + width - 1, y + height - 1);
2389 gdk_draw_line (window, style->dark_gc[state],
2390 x + width - 1, y + 1, x + width - 1, y + height - 1);
2394 /* Light around top and left */
2396 if (style->ythickness > 0)
2397 gdk_draw_line (window, style->black_gc,
2398 x, y, x + width - 2, y);
2399 if (style->xthickness > 0)
2400 gdk_draw_line (window, style->black_gc,
2401 x, y, x, y + height - 2);
2403 if (style->ythickness > 1)
2404 gdk_draw_line (window, style->light_gc[state],
2405 x + 1, y + 1, x + width - 3, y + 1);
2406 if (style->xthickness > 1)
2407 gdk_draw_line (window, style->light_gc[state],
2408 x + 1, y + 1, x + 1, y + height - 3);
2411 static GtkTextDirection
2412 get_direction (GtkWidget *widget)
2414 GtkTextDirection dir;
2417 dir = gtk_widget_get_direction (widget);
2419 dir = GTK_TEXT_DIR_LTR;
2426 gtk_default_draw_shadow (GtkStyle *style,
2428 GtkStateType state_type,
2429 GtkShadowType shadow_type,
2432 const gchar *detail,
2440 gint thickness_light;
2441 gint thickness_dark;
2444 g_return_if_fail (GTK_IS_STYLE (style));
2445 g_return_if_fail (window != NULL);
2447 if (shadow_type == GTK_SHADOW_IN)
2449 if (detail && (strcmp (detail, "buttondefault") == 0))
2451 sanitize_size (window, &width, &height);
2453 gdk_draw_rectangle (window, style->black_gc, FALSE,
2454 x, y, width - 1, height - 1);
2458 if (detail && strcmp (detail, "trough") == 0)
2460 draw_thin_shadow (style, window, state_type, area,
2461 x, y, width, height);
2464 if (widget && GTK_IS_SPIN_BUTTON (widget) &&
2465 detail && strcmp (detail, "spinbutton") == 0)
2467 draw_spinbutton_shadow (style, window, state_type,
2468 get_direction (widget), area, x, y, width, height);
2474 if (shadow_type == GTK_SHADOW_OUT && detail && strcmp (detail, "menu") == 0)
2476 draw_menu_shadow (style, window, state_type, area, x, y, width, height);
2480 sanitize_size (window, &width, &height);
2482 switch (shadow_type)
2484 case GTK_SHADOW_NONE:
2487 case GTK_SHADOW_ETCHED_IN:
2488 gc1 = style->light_gc[state_type];
2489 gc2 = style->dark_gc[state_type];
2491 case GTK_SHADOW_OUT:
2492 case GTK_SHADOW_ETCHED_OUT:
2493 gc1 = style->dark_gc[state_type];
2494 gc2 = style->light_gc[state_type];
2500 gdk_gc_set_clip_rectangle (gc1, area);
2501 gdk_gc_set_clip_rectangle (gc2, area);
2502 if (shadow_type == GTK_SHADOW_IN ||
2503 shadow_type == GTK_SHADOW_OUT)
2505 gdk_gc_set_clip_rectangle (style->black_gc, area);
2506 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2510 switch (shadow_type)
2512 case GTK_SHADOW_NONE:
2516 /* Light around right and bottom edge */
2518 if (style->ythickness > 0)
2519 gdk_draw_line (window, gc1,
2520 x, y + height - 1, x + width - 1, y + height - 1);
2521 if (style->xthickness > 0)
2522 gdk_draw_line (window, gc1,
2523 x + width - 1, y, x + width - 1, y + height - 1);
2525 if (style->ythickness > 1)
2526 gdk_draw_line (window, style->bg_gc[state_type],
2527 x + 1, y + height - 2, x + width - 2, y + height - 2);
2528 if (style->xthickness > 1)
2529 gdk_draw_line (window, style->bg_gc[state_type],
2530 x + width - 2, y + 1, x + width - 2, y + height - 2);
2532 /* Dark around left and top */
2534 if (style->ythickness > 1)
2535 gdk_draw_line (window, style->black_gc,
2536 x + 1, y + 1, x + width - 2, y + 1);
2537 if (style->xthickness > 1)
2538 gdk_draw_line (window, style->black_gc,
2539 x + 1, y + 1, x + 1, y + height - 2);
2541 if (style->ythickness > 0)
2542 gdk_draw_line (window, gc2,
2543 x, y, x + width - 1, y);
2544 if (style->xthickness > 0)
2545 gdk_draw_line (window, gc2,
2546 x, y, x, y + height - 1);
2549 case GTK_SHADOW_OUT:
2550 /* Dark around right and bottom edge */
2552 if (style->ythickness > 0)
2554 if (style->ythickness > 1)
2556 gdk_draw_line (window, gc1,
2557 x + 1, y + height - 2, x + width - 2, y + height - 2);
2558 gdk_draw_line (window, style->black_gc,
2559 x, y + height - 1, x + width - 1, y + height - 1);
2563 gdk_draw_line (window, gc1,
2564 x + 1, y + height - 1, x + width - 1, y + height - 1);
2568 if (style->xthickness > 0)
2570 if (style->xthickness > 1)
2572 gdk_draw_line (window, gc1,
2573 x + width - 2, y + 1, x + width - 2, y + height - 2);
2575 gdk_draw_line (window, style->black_gc,
2576 x + width - 1, y, x + width - 1, y + height - 1);
2580 gdk_draw_line (window, gc1,
2581 x + width - 1, y + 1, x + width - 1, y + height - 1);
2585 /* Light around top and left */
2587 if (style->ythickness > 0)
2588 gdk_draw_line (window, gc2,
2589 x, y, x + width - 2, y);
2590 if (style->xthickness > 0)
2591 gdk_draw_line (window, gc2,
2592 x, y, x, y + height - 2);
2594 if (style->ythickness > 1)
2595 gdk_draw_line (window, style->bg_gc[state_type],
2596 x + 1, y + 1, x + width - 3, y + 1);
2597 if (style->xthickness > 1)
2598 gdk_draw_line (window, style->bg_gc[state_type],
2599 x + 1, y + 1, x + 1, y + height - 3);
2602 case GTK_SHADOW_ETCHED_IN:
2603 case GTK_SHADOW_ETCHED_OUT:
2604 if (style->xthickness > 0)
2606 if (style->xthickness > 1)
2608 thickness_light = 1;
2611 for (i = 0; i < thickness_dark; i++)
2613 gdk_draw_line (window, gc1,
2617 y + height - i - 1);
2618 gdk_draw_line (window, gc2,
2622 y + height - i - 2);
2625 for (i = 0; i < thickness_light; i++)
2627 gdk_draw_line (window, gc1,
2628 x + thickness_dark + i,
2629 y + thickness_dark + i,
2630 x + thickness_dark + i,
2631 y + height - thickness_dark - i - 1);
2632 gdk_draw_line (window, gc2,
2633 x + width - thickness_light - i - 1,
2634 y + thickness_dark + i,
2635 x + width - thickness_light - i - 1,
2636 y + height - thickness_light - 1);
2641 gdk_draw_line (window,
2642 style->dark_gc[state_type],
2643 x, y, x, y + height);
2644 gdk_draw_line (window,
2645 style->dark_gc[state_type],
2646 x + width, y, x + width, y + height);
2650 if (style->ythickness > 0)
2652 if (style->ythickness > 1)
2654 thickness_light = 1;
2657 for (i = 0; i < thickness_dark; i++)
2659 gdk_draw_line (window, gc1,
2663 y + height - i - 1);
2665 gdk_draw_line (window, gc2,
2672 for (i = 0; i < thickness_light; i++)
2674 gdk_draw_line (window, gc1,
2675 x + thickness_dark + i,
2676 y + thickness_dark + i,
2677 x + width - thickness_dark - i - 2,
2678 y + thickness_dark + i);
2680 gdk_draw_line (window, gc2,
2681 x + thickness_dark + i,
2682 y + height - thickness_light - i - 1,
2683 x + width - thickness_light - 1,
2684 y + height - thickness_light - i - 1);
2689 gdk_draw_line (window,
2690 style->dark_gc[state_type],
2691 x, y, x + width, y);
2692 gdk_draw_line (window,
2693 style->dark_gc[state_type],
2694 x, y + height, x + width, y + height);
2701 if (shadow_type == GTK_SHADOW_IN &&
2702 widget && GTK_IS_SPIN_BUTTON (widget) &&
2703 detail && strcmp (detail, "entry") == 0)
2705 if (get_direction (widget) == GTK_TEXT_DIR_LTR)
2707 gdk_draw_line (window,
2708 style->base_gc[state_type],
2709 x + width - 1, y + 2,
2710 x + width - 1, y + height - 3);
2711 gdk_draw_line (window,
2712 style->base_gc[state_type],
2713 x + width - 2, y + 2,
2714 x + width - 2, y + height - 3);
2715 gdk_draw_point (window,
2717 x + width - 1, y + 1);
2718 gdk_draw_point (window,
2719 style->bg_gc[state_type],
2720 x + width - 1, y + height - 2);
2724 gdk_draw_line (window,
2725 style->base_gc[state_type],
2728 gdk_draw_line (window,
2729 style->base_gc[state_type],
2731 x + 1, y + height - 3);
2732 gdk_draw_point (window,
2735 gdk_draw_line (window,
2736 style->bg_gc[state_type],
2738 x + 1, y + height - 2);
2739 gdk_draw_point (window,
2740 style->light_gc[state_type],
2748 gdk_gc_set_clip_rectangle (gc1, NULL);
2749 gdk_gc_set_clip_rectangle (gc2, NULL);
2750 if (shadow_type == GTK_SHADOW_IN ||
2751 shadow_type == GTK_SHADOW_OUT)
2753 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2754 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
2760 gtk_default_draw_polygon (GtkStyle *style,
2762 GtkStateType state_type,
2763 GtkShadowType shadow_type,
2766 const gchar *detail,
2771 static const gdouble pi_over_4 = G_PI_4;
2772 static const gdouble pi_3_over_4 = G_PI_4 * 3;
2782 g_return_if_fail (GTK_IS_STYLE (style));
2783 g_return_if_fail (window != NULL);
2784 g_return_if_fail (points != NULL);
2786 switch (shadow_type)
2789 gc1 = style->bg_gc[state_type];
2790 gc2 = style->dark_gc[state_type];
2791 gc3 = style->light_gc[state_type];
2792 gc4 = style->black_gc;
2794 case GTK_SHADOW_ETCHED_IN:
2795 gc1 = style->light_gc[state_type];
2796 gc2 = style->dark_gc[state_type];
2797 gc3 = style->dark_gc[state_type];
2798 gc4 = style->light_gc[state_type];
2800 case GTK_SHADOW_OUT:
2801 gc1 = style->dark_gc[state_type];
2802 gc2 = style->light_gc[state_type];
2803 gc3 = style->black_gc;
2804 gc4 = style->bg_gc[state_type];
2806 case GTK_SHADOW_ETCHED_OUT:
2807 gc1 = style->dark_gc[state_type];
2808 gc2 = style->light_gc[state_type];
2809 gc3 = style->light_gc[state_type];
2810 gc4 = style->dark_gc[state_type];
2818 gdk_gc_set_clip_rectangle (gc1, area);
2819 gdk_gc_set_clip_rectangle (gc2, area);
2820 gdk_gc_set_clip_rectangle (gc3, area);
2821 gdk_gc_set_clip_rectangle (gc4, area);
2825 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, npoints);
2829 for (i = 0; i < npoints; i++)
2831 if ((points[i].x == points[i+1].x) &&
2832 (points[i].y == points[i+1].y))
2838 angle = atan2 (points[i+1].y - points[i].y,
2839 points[i+1].x - points[i].x);
2842 if ((angle > -pi_3_over_4) && (angle < pi_over_4))
2844 if (angle > -pi_over_4)
2855 gdk_draw_line (window, gc1,
2856 points[i].x-xadjust, points[i].y-yadjust,
2857 points[i+1].x-xadjust, points[i+1].y-yadjust);
2858 gdk_draw_line (window, gc3,
2859 points[i].x, points[i].y,
2860 points[i+1].x, points[i+1].y);
2864 if ((angle < -pi_3_over_4) || (angle > pi_3_over_4))
2875 gdk_draw_line (window, gc4,
2876 points[i].x+xadjust, points[i].y+yadjust,
2877 points[i+1].x+xadjust, points[i+1].y+yadjust);
2878 gdk_draw_line (window, gc2,
2879 points[i].x, points[i].y,
2880 points[i+1].x, points[i+1].y);
2886 gdk_gc_set_clip_rectangle (gc1, NULL);
2887 gdk_gc_set_clip_rectangle (gc2, NULL);
2888 gdk_gc_set_clip_rectangle (gc3, NULL);
2889 gdk_gc_set_clip_rectangle (gc4, NULL);
2894 draw_arrow (GdkWindow *window,
2897 GtkArrowType arrow_type,
2903 cairo_t *cr = gdk_drawable_create_cairo_context (window);
2904 gdk_cairo_set_source_color (cr, color);
2909 cairo_rectangle (cr, area->x, area->y, area->width, area->height);
2911 cairo_new_path (cr);
2914 if (arrow_type == GTK_ARROW_DOWN)
2916 cairo_move_to (cr, x, y);
2917 cairo_line_to (cr, x + width, y);
2918 cairo_line_to (cr, x + width / 2., y + height);
2920 else if (arrow_type == GTK_ARROW_UP)
2922 cairo_move_to (cr, x, y + height);
2923 cairo_line_to (cr, x + width / 2., y);
2924 cairo_line_to (cr, x + width, y + height);
2926 else if (arrow_type == GTK_ARROW_LEFT)
2928 cairo_move_to (cr, x + width, y);
2929 cairo_line_to (cr, x + width, y + height);
2930 cairo_line_to (cr, x, y + height / 2.);
2932 else if (arrow_type == GTK_ARROW_RIGHT)
2934 cairo_move_to (cr, x, y);
2935 cairo_line_to (cr, x + width, y + height / 2.);
2936 cairo_line_to (cr, x, y + height);
2939 cairo_close_path (cr);
2949 calculate_arrow_geometry (GtkArrowType arrow_type,
2961 case GTK_ARROW_DOWN:
2971 if (arrow_type == GTK_ARROW_DOWN)
2973 if (*height % 2 == 1 || h % 2 == 0)
2978 if (*height % 2 == 0 || h % 2 == 0)
2983 case GTK_ARROW_RIGHT:
2984 case GTK_ARROW_LEFT:
2994 if (arrow_type == GTK_ARROW_RIGHT)
2996 if (*width % 2 == 1 || w % 2 == 0)
3001 if (*width % 2 == 0 || w % 2 == 0)
3007 /* should not be reached */
3011 *x += (*width - w) / 2;
3012 *y += (*height - h) / 2;
3018 gtk_default_draw_arrow (GtkStyle *style,
3021 GtkShadowType shadow,
3024 const gchar *detail,
3025 GtkArrowType arrow_type,
3032 gint original_width, original_x;
3034 sanitize_size (window, &width, &height);
3036 original_width = width;
3039 calculate_arrow_geometry (arrow_type, &x, &y, &width, &height);
3041 if (detail && strcmp (detail, "menu_scroll_arrow_up") == 0)
3044 if (state == GTK_STATE_INSENSITIVE)
3045 draw_arrow (window, &style->white, area, arrow_type,
3046 x + 1, y + 1, width, height);
3047 draw_arrow (window, &style->fg[state], area, arrow_type,
3048 x, y, width, height);
3052 gtk_default_draw_diamond (GtkStyle *style,
3054 GtkStateType state_type,
3055 GtkShadowType shadow_type,
3058 const gchar *detail,
3066 GdkGC *outer_nw = NULL;
3067 GdkGC *outer_ne = NULL;
3068 GdkGC *outer_sw = NULL;
3069 GdkGC *outer_se = NULL;
3070 GdkGC *middle_nw = NULL;
3071 GdkGC *middle_ne = NULL;
3072 GdkGC *middle_sw = NULL;
3073 GdkGC *middle_se = NULL;
3074 GdkGC *inner_nw = NULL;
3075 GdkGC *inner_ne = NULL;
3076 GdkGC *inner_sw = NULL;
3077 GdkGC *inner_se = NULL;
3079 g_return_if_fail (GTK_IS_STYLE (style));
3080 g_return_if_fail (window != NULL);
3082 sanitize_size (window, &width, &height);
3084 half_width = width / 2;
3085 half_height = height / 2;
3089 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
3090 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
3091 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
3092 gdk_gc_set_clip_rectangle (style->black_gc, area);
3095 switch (shadow_type)
3098 inner_sw = inner_se = style->bg_gc[state_type];
3099 middle_sw = middle_se = style->light_gc[state_type];
3100 outer_sw = outer_se = style->light_gc[state_type];
3101 inner_nw = inner_ne = style->black_gc;
3102 middle_nw = middle_ne = style->dark_gc[state_type];
3103 outer_nw = outer_ne = style->dark_gc[state_type];
3106 case GTK_SHADOW_OUT:
3107 inner_sw = inner_se = style->dark_gc[state_type];
3108 middle_sw = middle_se = style->dark_gc[state_type];
3109 outer_sw = outer_se = style->black_gc;
3110 inner_nw = inner_ne = style->bg_gc[state_type];
3111 middle_nw = middle_ne = style->light_gc[state_type];
3112 outer_nw = outer_ne = style->light_gc[state_type];
3115 case GTK_SHADOW_ETCHED_IN:
3116 inner_sw = inner_se = style->bg_gc[state_type];
3117 middle_sw = middle_se = style->dark_gc[state_type];
3118 outer_sw = outer_se = style->light_gc[state_type];
3119 inner_nw = inner_ne = style->bg_gc[state_type];
3120 middle_nw = middle_ne = style->light_gc[state_type];
3121 outer_nw = outer_ne = style->dark_gc[state_type];
3124 case GTK_SHADOW_ETCHED_OUT:
3125 inner_sw = inner_se = style->bg_gc[state_type];
3126 middle_sw = middle_se = style->light_gc[state_type];
3127 outer_sw = outer_se = style->dark_gc[state_type];
3128 inner_nw = inner_ne = style->bg_gc[state_type];
3129 middle_nw = middle_ne = style->dark_gc[state_type];
3130 outer_nw = outer_ne = style->light_gc[state_type];
3140 gdk_draw_line (window, inner_sw,
3141 x + 2, y + half_height,
3142 x + half_width, y + height - 2);
3143 gdk_draw_line (window, inner_se,
3144 x + half_width, y + height - 2,
3145 x + width - 2, y + half_height);
3146 gdk_draw_line (window, middle_sw,
3147 x + 1, y + half_height,
3148 x + half_width, y + height - 1);
3149 gdk_draw_line (window, middle_se,
3150 x + half_width, y + height - 1,
3151 x + width - 1, y + half_height);
3152 gdk_draw_line (window, outer_sw,
3154 x + half_width, y + height);
3155 gdk_draw_line (window, outer_se,
3156 x + half_width, y + height,
3157 x + width, y + half_height);
3159 gdk_draw_line (window, inner_nw,
3160 x + 2, y + half_height,
3161 x + half_width, y + 2);
3162 gdk_draw_line (window, inner_ne,
3163 x + half_width, y + 2,
3164 x + width - 2, y + half_height);
3165 gdk_draw_line (window, middle_nw,
3166 x + 1, y + half_height,
3167 x + half_width, y + 1);
3168 gdk_draw_line (window, middle_ne,
3169 x + half_width, y + 1,
3170 x + width - 1, y + half_height);
3171 gdk_draw_line (window, outer_nw,
3174 gdk_draw_line (window, outer_ne,
3176 x + width, y + half_height);
3181 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
3182 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
3183 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
3184 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
3189 gtk_default_draw_string (GtkStyle *style,
3191 GtkStateType state_type,
3194 const gchar *detail,
3197 const gchar *string)
3199 GdkDisplay *display;
3201 g_return_if_fail (GTK_IS_STYLE (style));
3202 g_return_if_fail (window != NULL);
3204 display = gdk_drawable_get_display (window);
3208 gdk_gc_set_clip_rectangle (style->white_gc, area);
3209 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], area);
3212 if (state_type == GTK_STATE_INSENSITIVE)
3213 gdk_draw_string (window,
3214 gtk_style_get_font_internal (style),
3215 style->white_gc, x + 1, y + 1, string);
3217 gdk_draw_string (window,
3218 gtk_style_get_font_internal (style),
3219 style->fg_gc[state_type], x, y, string);
3223 gdk_gc_set_clip_rectangle (style->white_gc, NULL);
3224 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], NULL);
3229 option_menu_get_props (GtkWidget *widget,
3230 GtkRequisition *indicator_size,
3231 GtkBorder *indicator_spacing)
3233 GtkRequisition *tmp_size = NULL;
3234 GtkBorder *tmp_spacing = NULL;
3237 gtk_widget_style_get (widget,
3238 "indicator-size", &tmp_size,
3239 "indicator-spacing", &tmp_spacing,
3244 *indicator_size = *tmp_size;
3248 *indicator_size = default_option_indicator_size;
3252 *indicator_spacing = *tmp_spacing;
3253 g_free (tmp_spacing);
3256 *indicator_spacing = default_option_indicator_spacing;
3260 gtk_default_draw_box (GtkStyle *style,
3262 GtkStateType state_type,
3263 GtkShadowType shadow_type,
3266 const gchar *detail,
3272 gboolean is_spinbutton_box = FALSE;
3274 g_return_if_fail (GTK_IS_STYLE (style));
3275 g_return_if_fail (window != NULL);
3277 sanitize_size (window, &width, &height);
3279 if (widget && 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,
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 g_return_if_fail (GTK_IS_STYLE (style));
3426 g_return_if_fail (window != NULL);
3428 sanitize_size (window, &width, &height);
3432 if (state_type == GTK_STATE_SELECTED)
3434 if (!strcmp ("text", detail))
3435 gc1 = style->bg_gc[GTK_STATE_SELECTED];
3436 else if (!strncmp ("cell_even", detail, strlen ("cell_even")) ||
3437 !strncmp ("cell_odd", detail, strlen ("cell_odd")))
3439 /* This has to be really broken; alex made me do it. -jrb */
3440 if (GTK_WIDGET_HAS_FOCUS (widget))
3441 gc1 = style->base_gc[state_type];
3443 gc1 = style->base_gc[GTK_STATE_ACTIVE];
3447 gc1 = style->bg_gc[state_type];
3452 if (!strcmp ("viewportbin", detail))
3453 gc1 = style->bg_gc[GTK_STATE_NORMAL];
3454 else if (!strcmp ("entry_bg", detail))
3455 gc1 = style->base_gc[state_type];
3457 /* For trees: even rows are base color, odd rows are a shade of
3458 * the base color, the sort column is a shade of the original color
3462 else if (!strcmp ("cell_even", detail) ||
3463 !strcmp ("cell_odd", detail) ||
3464 !strcmp ("cell_even_ruled", detail))
3466 GdkColor *color = NULL;
3468 gtk_widget_style_get (widget,
3469 "even-row-color", &color,
3474 freeme = get_darkened_gc (window, color, 0);
3477 gdk_color_free (color);
3480 gc1 = style->base_gc[state_type];
3482 else if (!strcmp ("cell_odd_ruled", detail))
3486 gtk_widget_style_get (widget,
3487 "odd-row-color", &color,
3492 freeme = get_darkened_gc (window, color, 0);
3495 gdk_color_free (color);
3499 gtk_widget_style_get (widget,
3500 "even-row-color", &color,
3505 freeme = get_darkened_gc (window, color, 1);
3506 gdk_color_free (color);
3509 freeme = get_darkened_gc (window, &style->base[state_type], 1);
3513 else if (!strcmp ("cell_even_sorted", detail) ||
3514 !strcmp ("cell_odd_sorted", detail) ||
3515 !strcmp ("cell_even_ruled_sorted", detail))
3517 GdkColor *color = NULL;
3519 if (!strcmp ("cell_odd_sorted", detail))
3520 gtk_widget_style_get (widget,
3521 "odd-row-color", &color,
3524 gtk_widget_style_get (widget,
3525 "even-row-color", &color,
3530 freeme = get_darkened_gc (window, color, 1);
3533 gdk_color_free (color);
3537 freeme = get_darkened_gc (window, &style->base[state_type], 1);
3541 else if (!strcmp ("cell_odd_ruled_sorted", detail))
3543 GdkColor *color = NULL;
3545 gtk_widget_style_get (widget,
3546 "odd-row-color", &color,
3551 freeme = get_darkened_gc (window, color, 1);
3554 gdk_color_free (color);
3558 gtk_widget_style_get (widget,
3559 "even-row-color", &color,
3564 freeme = get_darkened_gc (window, color, 2);
3565 gdk_color_free (color);
3568 freeme = get_darkened_gc (window, &style->base[state_type], 2);
3573 gc1 = style->bg_gc[state_type];
3577 gc1 = style->bg_gc[state_type];
3579 if (!style->bg_pixmap[state_type] || gc1 != style->bg_gc[state_type] ||
3580 GDK_IS_PIXMAP (window))
3583 gdk_gc_set_clip_rectangle (gc1, area);
3585 gdk_draw_rectangle (window, gc1, TRUE,
3586 x, y, width, height);
3588 if (detail && !strcmp ("tooltip", detail))
3589 gdk_draw_rectangle (window, style->black_gc, FALSE,
3590 x, y, width - 1, height - 1);
3593 gdk_gc_set_clip_rectangle (gc1, NULL);
3596 gtk_style_apply_default_background (style, window,
3597 widget && !GTK_WIDGET_NO_WINDOW (widget),
3598 state_type, area, x, y, width, height);
3602 g_object_unref (freeme);
3606 gtk_default_draw_check (GtkStyle *style,
3608 GtkStateType state_type,
3609 GtkShadowType shadow_type,
3612 const gchar *detail,
3618 cairo_t *cr = gdk_drawable_create_cairo_context (window);
3619 enum { BUTTON, MENU, CELL } type = BUTTON;
3626 if (strcmp (detail, "cellcheck") == 0)
3628 else if (strcmp (detail, "check") == 0)
3635 cairo_rectangle (cr, area->x, area->y, area->width, area->height);
3637 cairo_new_path (cr);
3640 exterior_size = MIN (width, height);
3641 if (exterior_size % 2 == 0) /* Ensure odd */
3642 exterior_size -= -1;
3644 pad = style->xthickness + MAX (1, (exterior_size - 2 * style->xthickness) / 9);
3645 interior_size = MAX (1, exterior_size - 2 * pad);
3647 if (interior_size < 7)
3650 pad = MAX (0, (exterior_size - interior_size) / 2);
3653 x -= (1 + exterior_size - width) / 2;
3654 y -= (1 + exterior_size - height) / 2;
3661 gdk_cairo_set_source_color (cr, &style->fg[state_type]);
3663 gdk_cairo_set_source_color (cr, &style->text[state_type]);
3665 cairo_set_line_width (cr, 1.0);
3666 cairo_rectangle (cr, x + 0.5, y + 0.5, exterior_size - 1, exterior_size - 1);
3669 gdk_cairo_set_source_color (cr, &style->base[state_type]);
3670 cairo_rectangle (cr, x + 1, y + 1, exterior_size - 2, exterior_size - 2);
3682 gdk_cairo_set_source_color (cr, &style->text[state_type]);
3685 gdk_cairo_set_source_color (cr, &style->fg[state_type]);
3689 if (shadow_type == GTK_SHADOW_IN)
3691 cairo_translate (cr,
3694 cairo_scale (cr, interior_size / 7., interior_size / 7.);
3696 cairo_move_to (cr, 7.0, 0.0);
3697 cairo_line_to (cr, 7.5, 1.0);
3698 cairo_curve_to (cr, 5.3, 2.0,
3701 cairo_curve_to (cr, 3.0, 5.7,
3704 cairo_line_to (cr, 0.2, 3.5);
3705 cairo_curve_to (cr, 1.1, 3.5,
3708 cairo_curve_to (cr, 1.0, 3.9,
3711 cairo_curve_to (cr, 3.5, 3.1,
3717 else if (shadow_type == GTK_SHADOW_ETCHED_IN) /* inconsistent */
3719 int line_thickness = MAX (1, (3 + interior_size * 2) / 7);
3721 cairo_rectangle (cr,
3723 y + pad + (1 + interior_size - line_thickness) / 2,
3736 gtk_default_draw_option (GtkStyle *style,
3738 GtkStateType state_type,
3739 GtkShadowType shadow_type,
3742 const gchar *detail,
3748 cairo_t *cr = gdk_drawable_create_cairo_context (window);
3749 enum { BUTTON, MENU, CELL } type = BUTTON;
3754 if (strcmp (detail, "radio") == 0)
3756 else if (strcmp (detail, "option") == 0)
3763 cairo_rectangle (cr, area->x, area->y, area->width, area->height);
3765 cairo_new_path (cr);
3768 exterior_size = MIN (width, height);
3769 if (exterior_size % 2 == 0) /* Ensure odd */
3770 exterior_size -= -1;
3772 x -= (1 + exterior_size - width) / 2;
3773 y -= (1 + exterior_size - height) / 2;
3779 gdk_cairo_set_source_color (cr, &style->base[state_type]);
3782 x + exterior_size / 2.,
3783 y + exterior_size / 2.,
3784 (exterior_size - 1) / 2.,
3792 gdk_cairo_set_source_color (cr, &style->fg[state_type]);
3794 gdk_cairo_set_source_color (cr, &style->text[state_type]);
3796 cairo_set_line_width (cr, 1.);
3807 gdk_cairo_set_source_color (cr, &style->text[state_type]);
3812 gdk_cairo_set_source_color (cr, &style->fg[state_type]);
3816 if (shadow_type == GTK_SHADOW_IN)
3818 int pad = style->xthickness + MAX (1, 2 * (exterior_size - 2 * style->xthickness) / 9);
3819 int interior_size = MAX (1, exterior_size - 2 * pad);
3821 if (interior_size < 5)
3824 pad = MAX (0, (exterior_size - interior_size) / 2);
3828 x + pad + interior_size / 2.,
3829 y + pad + interior_size / 2.,
3834 else if (shadow_type == GTK_SHADOW_ETCHED_IN) /* inconsistent */
3836 int pad = style->xthickness + MAX (1, (exterior_size - 2 * style->xthickness) / 9);
3837 int interior_size = MAX (1, exterior_size - 2 * pad);
3840 if (interior_size < 7)
3843 pad = MAX (0, (exterior_size - interior_size) / 2);
3846 line_thickness = MAX (1, (3 + interior_size * 2) / 7);
3848 cairo_rectangle (cr,
3850 y + pad + (interior_size - line_thickness) / 2.,
3863 gtk_default_draw_tab (GtkStyle *style,
3865 GtkStateType state_type,
3866 GtkShadowType shadow_type,
3869 const gchar *detail,
3875 #define ARROW_SPACE 4
3877 GtkRequisition indicator_size;
3878 GtkBorder indicator_spacing;
3881 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
3883 indicator_size.width += (indicator_size.width % 2) - 1;
3884 arrow_height = indicator_size.width / 2 + 1;
3886 x += (width - indicator_size.width) / 2;
3887 y += (height - (2 * arrow_height + ARROW_SPACE)) / 2;
3889 if (state_type == GTK_STATE_INSENSITIVE)
3891 draw_arrow (window, &style->white, area,
3892 GTK_ARROW_UP, x + 1, y + 1,
3893 indicator_size.width, arrow_height);
3895 draw_arrow (window, &style->white, area,
3896 GTK_ARROW_DOWN, x + 1, y + arrow_height + ARROW_SPACE + 1,
3897 indicator_size.width, arrow_height);
3900 draw_arrow (window, &style->fg[state_type], area,
3902 indicator_size.width, arrow_height);
3905 draw_arrow (window, &style->fg[state_type], area,
3906 GTK_ARROW_DOWN, x, y + arrow_height + ARROW_SPACE,
3907 indicator_size.width, arrow_height);
3911 gtk_default_draw_shadow_gap (GtkStyle *style,
3913 GtkStateType state_type,
3914 GtkShadowType shadow_type,
3917 const gchar *detail,
3922 GtkPositionType gap_side,
3931 g_return_if_fail (GTK_IS_STYLE (style));
3932 g_return_if_fail (window != NULL);
3934 sanitize_size (window, &width, &height);
3936 switch (shadow_type)
3938 case GTK_SHADOW_NONE:
3941 gc1 = style->dark_gc[state_type];
3942 gc2 = style->black_gc;
3943 gc3 = style->bg_gc[state_type];
3944 gc4 = style->light_gc[state_type];
3946 case GTK_SHADOW_ETCHED_IN:
3947 gc1 = style->dark_gc[state_type];
3948 gc2 = style->light_gc[state_type];
3949 gc3 = style->dark_gc[state_type];
3950 gc4 = style->light_gc[state_type];
3952 case GTK_SHADOW_OUT:
3953 gc1 = style->light_gc[state_type];
3954 gc2 = style->bg_gc[state_type];
3955 gc3 = style->dark_gc[state_type];
3956 gc4 = style->black_gc;
3958 case GTK_SHADOW_ETCHED_OUT:
3959 gc1 = style->light_gc[state_type];
3960 gc2 = style->dark_gc[state_type];
3961 gc3 = style->light_gc[state_type];
3962 gc4 = style->dark_gc[state_type];
3967 gdk_gc_set_clip_rectangle (gc1, area);
3968 gdk_gc_set_clip_rectangle (gc2, area);
3969 gdk_gc_set_clip_rectangle (gc3, area);
3970 gdk_gc_set_clip_rectangle (gc4, area);
3973 switch (shadow_type)
3975 case GTK_SHADOW_NONE:
3977 case GTK_SHADOW_OUT:
3978 case GTK_SHADOW_ETCHED_IN:
3979 case GTK_SHADOW_ETCHED_OUT:
3983 gdk_draw_line (window, gc1,
3984 x, y, x, y + height - 1);
3985 gdk_draw_line (window, gc2,
3986 x + 1, y, x + 1, y + height - 2);
3988 gdk_draw_line (window, gc3,
3989 x + 1, y + height - 2, x + width - 2, y + height - 2);
3990 gdk_draw_line (window, gc3,
3991 x + width - 2, y, x + width - 2, y + height - 2);
3992 gdk_draw_line (window, gc4,
3993 x, y + height - 1, x + width - 1, y + height - 1);
3994 gdk_draw_line (window, gc4,
3995 x + width - 1, y, x + width - 1, y + height - 1);
3998 gdk_draw_line (window, gc1,
3999 x, y, x + gap_x - 1, y);
4000 gdk_draw_line (window, gc2,
4001 x + 1, y + 1, x + gap_x - 1, y + 1);
4002 gdk_draw_line (window, gc2,
4003 x + gap_x, y, x + gap_x, y);
4005 if ((width - (gap_x + gap_width)) > 0)
4007 gdk_draw_line (window, gc1,
4008 x + gap_x + gap_width, y, x + width - 2, y);
4009 gdk_draw_line (window, gc2,
4010 x + gap_x + gap_width, y + 1, x + width - 3, y + 1);
4011 gdk_draw_line (window, gc2,
4012 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
4015 case GTK_POS_BOTTOM:
4016 gdk_draw_line (window, gc1,
4017 x, y, x + width - 1, y);
4018 gdk_draw_line (window, gc1,
4019 x, y, x, y + height - 1);
4020 gdk_draw_line (window, gc2,
4021 x + 1, y + 1, x + width - 2, y + 1);
4022 gdk_draw_line (window, gc2,
4023 x + 1, y + 1, x + 1, y + height - 1);
4025 gdk_draw_line (window, gc3,
4026 x + width - 2, y + 1, x + width - 2, y + height - 1);
4027 gdk_draw_line (window, gc4,
4028 x + width - 1, y, x + width - 1, y + height - 1);
4031 gdk_draw_line (window, gc4,
4032 x, y + height - 1, x + gap_x - 1, y + height - 1);
4033 gdk_draw_line (window, gc3,
4034 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
4035 gdk_draw_line (window, gc3,
4036 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
4038 if ((width - (gap_x + gap_width)) > 0)
4040 gdk_draw_line (window, gc4,
4041 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
4042 gdk_draw_line (window, gc3,
4043 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
4044 gdk_draw_line (window, gc3,
4045 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
4049 gdk_draw_line (window, gc1,
4050 x, y, x + width - 1, y);
4051 gdk_draw_line (window, gc2,
4052 x, y + 1, x + width - 2, y + 1);
4054 gdk_draw_line (window, gc3,
4055 x, y + height - 2, x + width - 2, y + height - 2);
4056 gdk_draw_line (window, gc3,
4057 x + width - 2, y + 1, x + width - 2, y + height - 2);
4058 gdk_draw_line (window, gc4,
4059 x, y + height - 1, x + width - 1, y + height - 1);
4060 gdk_draw_line (window, gc4,
4061 x + width - 1, y, x + width - 1, y + height - 1);
4064 gdk_draw_line (window, gc1,
4065 x, y, x, y + gap_x - 1);
4066 gdk_draw_line (window, gc2,
4067 x + 1, y + 1, x + 1, y + gap_x - 1);
4068 gdk_draw_line (window, gc2,
4069 x, y + gap_x, x, y + gap_x);
4071 if ((width - (gap_x + gap_width)) > 0)
4073 gdk_draw_line (window, gc1,
4074 x, y + gap_x + gap_width, x, y + height - 2);
4075 gdk_draw_line (window, gc2,
4076 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
4077 gdk_draw_line (window, gc2,
4078 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
4082 gdk_draw_line (window, gc1,
4083 x, y, x + width - 1, y);
4084 gdk_draw_line (window, gc1,
4085 x, y, x, y + height - 1);
4086 gdk_draw_line (window, gc2,
4087 x + 1, y + 1, x + width - 1, y + 1);
4088 gdk_draw_line (window, gc2,
4089 x + 1, y + 1, x + 1, y + height - 2);
4091 gdk_draw_line (window, gc3,
4092 x + 1, y + height - 2, x + width - 1, y + height - 2);
4093 gdk_draw_line (window, gc4,
4094 x, y + height - 1, x + width - 1, y + height - 1);
4097 gdk_draw_line (window, gc4,
4098 x + width - 1, y, x + width - 1, y + gap_x - 1);
4099 gdk_draw_line (window, gc3,
4100 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
4101 gdk_draw_line (window, gc3,
4102 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
4104 if ((width - (gap_x + gap_width)) > 0)
4106 gdk_draw_line (window, gc4,
4107 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
4108 gdk_draw_line (window, gc3,
4109 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
4110 gdk_draw_line (window, gc3,
4111 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
4119 gdk_gc_set_clip_rectangle (gc1, NULL);
4120 gdk_gc_set_clip_rectangle (gc2, NULL);
4121 gdk_gc_set_clip_rectangle (gc3, NULL);
4122 gdk_gc_set_clip_rectangle (gc4, NULL);
4127 gtk_default_draw_box_gap (GtkStyle *style,
4129 GtkStateType state_type,
4130 GtkShadowType shadow_type,
4133 const gchar *detail,
4138 GtkPositionType gap_side,
4147 g_return_if_fail (GTK_IS_STYLE (style));
4148 g_return_if_fail (window != NULL);
4150 gtk_style_apply_default_background (style, window,
4151 widget && !GTK_WIDGET_NO_WINDOW (widget),
4152 state_type, area, x, y, width, height);
4154 sanitize_size (window, &width, &height);
4156 switch (shadow_type)
4158 case GTK_SHADOW_NONE:
4161 gc1 = style->dark_gc[state_type];
4162 gc2 = style->black_gc;
4163 gc3 = style->bg_gc[state_type];
4164 gc4 = style->light_gc[state_type];
4166 case GTK_SHADOW_ETCHED_IN:
4167 gc1 = style->dark_gc[state_type];
4168 gc2 = style->light_gc[state_type];
4169 gc3 = style->dark_gc[state_type];
4170 gc4 = style->light_gc[state_type];
4172 case GTK_SHADOW_OUT:
4173 gc1 = style->light_gc[state_type];
4174 gc2 = style->bg_gc[state_type];
4175 gc3 = style->dark_gc[state_type];
4176 gc4 = style->black_gc;
4178 case GTK_SHADOW_ETCHED_OUT:
4179 gc1 = style->light_gc[state_type];
4180 gc2 = style->dark_gc[state_type];
4181 gc3 = style->light_gc[state_type];
4182 gc4 = style->dark_gc[state_type];
4188 gdk_gc_set_clip_rectangle (gc1, area);
4189 gdk_gc_set_clip_rectangle (gc2, area);
4190 gdk_gc_set_clip_rectangle (gc3, area);
4191 gdk_gc_set_clip_rectangle (gc4, area);
4194 switch (shadow_type)
4196 case GTK_SHADOW_NONE:
4198 case GTK_SHADOW_OUT:
4199 case GTK_SHADOW_ETCHED_IN:
4200 case GTK_SHADOW_ETCHED_OUT:
4204 gdk_draw_line (window, gc1,
4205 x, y, x, y + height - 1);
4206 gdk_draw_line (window, gc2,
4207 x + 1, y, x + 1, y + height - 2);
4209 gdk_draw_line (window, gc3,
4210 x + 1, y + height - 2, x + width - 2, y + height - 2);
4211 gdk_draw_line (window, gc3,
4212 x + width - 2, y, x + width - 2, y + height - 2);
4213 gdk_draw_line (window, gc4,
4214 x, y + height - 1, x + width - 1, y + height - 1);
4215 gdk_draw_line (window, gc4,
4216 x + width - 1, y, x + width - 1, y + height - 1);
4219 gdk_draw_line (window, gc1,
4220 x, y, x + gap_x - 1, y);
4221 gdk_draw_line (window, gc2,
4222 x + 1, y + 1, x + gap_x - 1, y + 1);
4223 gdk_draw_line (window, gc2,
4224 x + gap_x, y, x + gap_x, y);
4226 if ((width - (gap_x + gap_width)) > 0)
4228 gdk_draw_line (window, gc1,
4229 x + gap_x + gap_width, y, x + width - 2, y);
4230 gdk_draw_line (window, gc2,
4231 x + gap_x + gap_width, y + 1, x + width - 2, y + 1);
4232 gdk_draw_line (window, gc2,
4233 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
4236 case GTK_POS_BOTTOM:
4237 gdk_draw_line (window, gc1,
4238 x, y, x + width - 1, y);
4239 gdk_draw_line (window, gc1,
4240 x, y, x, y + height - 1);
4241 gdk_draw_line (window, gc2,
4242 x + 1, y + 1, x + width - 2, y + 1);
4243 gdk_draw_line (window, gc2,
4244 x + 1, y + 1, x + 1, y + height - 1);
4246 gdk_draw_line (window, gc3,
4247 x + width - 2, y + 1, x + width - 2, y + height - 1);
4248 gdk_draw_line (window, gc4,
4249 x + width - 1, y, x + width - 1, y + height - 1);
4252 gdk_draw_line (window, gc4,
4253 x, y + height - 1, x + gap_x - 1, y + height - 1);
4254 gdk_draw_line (window, gc3,
4255 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
4256 gdk_draw_line (window, gc3,
4257 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
4259 if ((width - (gap_x + gap_width)) > 0)
4261 gdk_draw_line (window, gc4,
4262 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
4263 gdk_draw_line (window, gc3,
4264 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
4265 gdk_draw_line (window, gc3,
4266 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
4270 gdk_draw_line (window, gc1,
4271 x, y, x + width - 1, y);
4272 gdk_draw_line (window, gc2,
4273 x, y + 1, x + width - 2, y + 1);
4275 gdk_draw_line (window, gc3,
4276 x, y + height - 2, x + width - 2, y + height - 2);
4277 gdk_draw_line (window, gc3,
4278 x + width - 2, y + 1, x + width - 2, y + height - 2);
4279 gdk_draw_line (window, gc4,
4280 x, y + height - 1, x + width - 1, y + height - 1);
4281 gdk_draw_line (window, gc4,
4282 x + width - 1, y, x + width - 1, y + height - 1);
4285 gdk_draw_line (window, gc1,
4286 x, y, x, y + gap_x - 1);
4287 gdk_draw_line (window, gc2,
4288 x + 1, y + 1, x + 1, y + gap_x - 1);
4289 gdk_draw_line (window, gc2,
4290 x, y + gap_x, x, y + gap_x);
4292 if ((width - (gap_x + gap_width)) > 0)
4294 gdk_draw_line (window, gc1,
4295 x, y + gap_x + gap_width, x, y + height - 2);
4296 gdk_draw_line (window, gc2,
4297 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
4298 gdk_draw_line (window, gc2,
4299 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
4303 gdk_draw_line (window, gc1,
4304 x, y, x + width - 1, y);
4305 gdk_draw_line (window, gc1,
4306 x, y, x, y + height - 1);
4307 gdk_draw_line (window, gc2,
4308 x + 1, y + 1, x + width - 1, y + 1);
4309 gdk_draw_line (window, gc2,
4310 x + 1, y + 1, x + 1, y + height - 2);
4312 gdk_draw_line (window, gc3,
4313 x + 1, y + height - 2, x + width - 1, y + height - 2);
4314 gdk_draw_line (window, gc4,
4315 x, y + height - 1, x + width - 1, y + height - 1);
4318 gdk_draw_line (window, gc4,
4319 x + width - 1, y, x + width - 1, y + gap_x - 1);
4320 gdk_draw_line (window, gc3,
4321 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
4322 gdk_draw_line (window, gc3,
4323 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
4325 if ((width - (gap_x + gap_width)) > 0)
4327 gdk_draw_line (window, gc4,
4328 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
4329 gdk_draw_line (window, gc3,
4330 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
4331 gdk_draw_line (window, gc3,
4332 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
4340 gdk_gc_set_clip_rectangle (gc1, NULL);
4341 gdk_gc_set_clip_rectangle (gc2, NULL);
4342 gdk_gc_set_clip_rectangle (gc3, NULL);
4343 gdk_gc_set_clip_rectangle (gc4, NULL);
4348 gtk_default_draw_extension (GtkStyle *style,
4350 GtkStateType state_type,
4351 GtkShadowType shadow_type,
4354 const gchar *detail,
4359 GtkPositionType gap_side)
4366 g_return_if_fail (GTK_IS_STYLE (style));
4367 g_return_if_fail (window != NULL);
4369 gtk_style_apply_default_background (style, window,
4370 widget && !GTK_WIDGET_NO_WINDOW (widget),
4371 GTK_STATE_NORMAL, area, x, y, width, height);
4373 sanitize_size (window, &width, &height);
4375 switch (shadow_type)
4377 case GTK_SHADOW_NONE:
4380 gc1 = style->dark_gc[state_type];
4381 gc2 = style->black_gc;
4382 gc3 = style->bg_gc[state_type];
4383 gc4 = style->light_gc[state_type];
4385 case GTK_SHADOW_ETCHED_IN:
4386 gc1 = style->dark_gc[state_type];
4387 gc2 = style->light_gc[state_type];
4388 gc3 = style->dark_gc[state_type];
4389 gc4 = style->light_gc[state_type];
4391 case GTK_SHADOW_OUT:
4392 gc1 = style->light_gc[state_type];
4393 gc2 = style->bg_gc[state_type];
4394 gc3 = style->dark_gc[state_type];
4395 gc4 = style->black_gc;
4397 case GTK_SHADOW_ETCHED_OUT:
4398 gc1 = style->light_gc[state_type];
4399 gc2 = style->dark_gc[state_type];
4400 gc3 = style->light_gc[state_type];
4401 gc4 = style->dark_gc[state_type];
4407 gdk_gc_set_clip_rectangle (gc1, area);
4408 gdk_gc_set_clip_rectangle (gc2, area);
4409 gdk_gc_set_clip_rectangle (gc3, area);
4410 gdk_gc_set_clip_rectangle (gc4, area);
4413 switch (shadow_type)
4415 case GTK_SHADOW_NONE:
4417 case GTK_SHADOW_OUT:
4418 case GTK_SHADOW_ETCHED_IN:
4419 case GTK_SHADOW_ETCHED_OUT:
4423 gtk_style_apply_default_background (style, window,
4424 widget && !GTK_WIDGET_NO_WINDOW (widget),
4426 x + style->xthickness,
4428 width - (2 * style->xthickness),
4429 height - (style->ythickness));
4430 gdk_draw_line (window, gc1,
4431 x, y, x, y + height - 2);
4432 gdk_draw_line (window, gc2,
4433 x + 1, y, x + 1, y + height - 2);
4435 gdk_draw_line (window, gc3,
4436 x + 2, y + height - 2, x + width - 2, y + height - 2);
4437 gdk_draw_line (window, gc3,
4438 x + width - 2, y, x + width - 2, y + height - 2);
4439 gdk_draw_line (window, gc4,
4440 x + 1, y + height - 1, x + width - 2, y + height - 1);
4441 gdk_draw_line (window, gc4,
4442 x + width - 1, y, x + width - 1, y + height - 2);
4444 case GTK_POS_BOTTOM:
4445 gtk_style_apply_default_background (style, window,
4446 widget && !GTK_WIDGET_NO_WINDOW (widget),
4448 x + style->xthickness,
4449 y + style->ythickness,
4450 width - (2 * style->xthickness),
4451 height - (style->ythickness));
4452 gdk_draw_line (window, gc1,
4453 x + 1, y, x + width - 2, y);
4454 gdk_draw_line (window, gc1,
4455 x, y + 1, x, y + height - 1);
4456 gdk_draw_line (window, gc2,
4457 x + 1, y + 1, x + width - 2, y + 1);
4458 gdk_draw_line (window, gc2,
4459 x + 1, y + 1, x + 1, y + height - 1);
4461 gdk_draw_line (window, gc3,
4462 x + width - 2, y + 2, x + width - 2, y + height - 1);
4463 gdk_draw_line (window, gc4,
4464 x + width - 1, y + 1, x + width - 1, y + height - 1);
4467 gtk_style_apply_default_background (style, window,
4468 widget && !GTK_WIDGET_NO_WINDOW (widget),
4471 y + style->ythickness,
4472 width - (style->xthickness),
4473 height - (2 * style->ythickness));
4474 gdk_draw_line (window, gc1,
4475 x, y, x + width - 2, y);
4476 gdk_draw_line (window, gc2,
4477 x + 1, y + 1, x + width - 2, y + 1);
4479 gdk_draw_line (window, gc3,
4480 x, y + height - 2, x + width - 2, y + height - 2);
4481 gdk_draw_line (window, gc3,
4482 x + width - 2, y + 2, x + width - 2, y + height - 2);
4483 gdk_draw_line (window, gc4,
4484 x, y + height - 1, x + width - 2, y + height - 1);
4485 gdk_draw_line (window, gc4,
4486 x + width - 1, y + 1, x + width - 1, y + height - 2);
4489 gtk_style_apply_default_background (style, window,
4490 widget && !GTK_WIDGET_NO_WINDOW (widget),
4492 x + style->xthickness,
4493 y + style->ythickness,
4494 width - (style->xthickness),
4495 height - (2 * style->ythickness));
4496 gdk_draw_line (window, gc1,
4497 x + 1, y, x + width - 1, y);
4498 gdk_draw_line (window, gc1,
4499 x, y + 1, x, y + height - 2);
4500 gdk_draw_line (window, gc2,
4501 x + 1, y + 1, x + width - 1, y + 1);
4502 gdk_draw_line (window, gc2,
4503 x + 1, y + 1, x + 1, y + height - 2);
4505 gdk_draw_line (window, gc3,
4506 x + 2, y + height - 2, x + width - 1, y + height - 2);
4507 gdk_draw_line (window, gc4,
4508 x + 1, y + height - 1, x + width - 1, y + height - 1);
4515 gdk_gc_set_clip_rectangle (gc1, NULL);
4516 gdk_gc_set_clip_rectangle (gc2, NULL);
4517 gdk_gc_set_clip_rectangle (gc3, NULL);
4518 gdk_gc_set_clip_rectangle (gc4, NULL);
4523 gtk_default_draw_focus (GtkStyle *style,
4525 GtkStateType state_type,
4528 const gchar *detail,
4535 gboolean free_dash_list = FALSE;
4536 gint line_width = 1;
4537 gint8 *dash_list = "\1\1";
4541 gtk_widget_style_get (widget,
4542 "focus-line-width", &line_width,
4543 "focus-line-pattern", (gchar *)&dash_list,
4546 free_dash_list = TRUE;
4549 if (detail && !strcmp (detail, "add-mode"))
4555 free_dash_list = FALSE;
4558 sanitize_size (window, &width, &height);
4560 cr = gdk_drawable_create_cairo_context (window);
4562 if (detail && !strcmp (detail, "colorwheel_light"))
4563 cairo_set_source_rgb (cr, 0., 0., 0.);
4564 else if (detail && !strcmp (detail, "colorwheel_dark"))
4565 cairo_set_source_rgb (cr, 1., 1., 1.);
4567 gdk_cairo_set_source_color (cr, &style->fg[state_type]);
4569 cairo_set_line_width (cr, line_width);
4573 gint n_dashes = strlen (dash_list);
4574 gdouble *dashes = g_new (gdouble, n_dashes);
4575 gdouble total_length = 0;
4576 gdouble dash_offset;
4579 for (i = 0; i < n_dashes; i++)
4581 dashes[i] = dash_list[i];
4582 total_length += dash_list[i];
4585 /* The dash offset here aligns the pattern to integer pixels
4586 * by starting the dash at the right side of the left border
4587 * Negative dash offsets in cairo don't work
4588 * (https://bugs.freedesktop.org/show_bug.cgi?id=2729)
4590 dash_offset = - line_width / 2.;
4591 while (dash_offset < 0)
4592 dash_offset += total_length;
4594 cairo_set_dash (cr, dashes, n_dashes, dash_offset);
4600 cairo_rectangle (cr,
4601 area->x, area->y, area->width, area->height);
4603 cairo_new_path (cr);
4606 cairo_rectangle (cr,
4607 x + line_width / 2.,
4608 y + line_width / 2.,
4610 height - line_width);
4619 gtk_default_draw_slider (GtkStyle *style,
4621 GtkStateType state_type,
4622 GtkShadowType shadow_type,
4625 const gchar *detail,
4630 GtkOrientation orientation)
4632 g_return_if_fail (GTK_IS_STYLE (style));
4633 g_return_if_fail (window != NULL);
4635 sanitize_size (window, &width, &height);
4637 gtk_paint_box (style, window, state_type, shadow_type,
4638 area, widget, detail, x, y, width, height);
4641 (strcmp ("hscale", detail) == 0 ||
4642 strcmp ("vscale", detail) == 0))
4644 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4645 gtk_paint_vline (style, window, state_type, area, widget, detail,
4646 y + style->ythickness,
4647 y + height - style->ythickness - 1, x + width / 2);
4649 gtk_paint_hline (style, window, state_type, area, widget, detail,
4650 x + style->xthickness,
4651 x + width - style->xthickness - 1, y + height / 2);
4656 draw_dot (GdkWindow *window,
4664 size = CLAMP (size, 2, 3);
4668 gdk_draw_point (window, light_gc, x, y);
4669 gdk_draw_point (window, light_gc, x+1, y+1);
4673 gdk_draw_point (window, light_gc, x, y);
4674 gdk_draw_point (window, light_gc, x+1, y);
4675 gdk_draw_point (window, light_gc, x, y+1);
4676 gdk_draw_point (window, dark_gc, x+1, y+2);
4677 gdk_draw_point (window, dark_gc, x+2, y+1);
4678 gdk_draw_point (window, dark_gc, x+2, y+2);
4683 gtk_default_draw_handle (GtkStyle *style,
4685 GtkStateType state_type,
4686 GtkShadowType shadow_type,
4689 const gchar *detail,
4694 GtkOrientation orientation)
4697 gint xthick, ythick;
4698 GdkGC *light_gc, *dark_gc;
4699 GdkGC *free_me = NULL;
4704 g_return_if_fail (GTK_IS_STYLE (style));
4705 g_return_if_fail (window != NULL);
4707 sanitize_size (window, &width, &height);
4709 gtk_paint_box (style, window, state_type, shadow_type, area, widget,
4710 detail, x, y, width, height);
4713 if (detail && !strcmp (detail, "paned"))
4715 /* we want to ignore the shadow border in paned widgets */
4719 if (state_type == GTK_STATE_SELECTED && widget && !GTK_WIDGET_HAS_FOCUS (widget))
4721 GdkColor unfocused_light;
4723 gtk_style_shade (&style->base[GTK_STATE_ACTIVE], &unfocused_light,
4726 light_gc = free_me = gdk_gc_new (window);
4727 gdk_gc_set_rgb_fg_color (light_gc, &unfocused_light);
4730 light_gc = style->light_gc[state_type];
4732 dark_gc = style->black_gc;
4736 xthick = style->xthickness;
4737 ythick = style->ythickness;
4739 light_gc = style->light_gc[state_type];
4740 dark_gc = style->dark_gc[state_type];
4743 rect.x = x + xthick;
4744 rect.y = y + ythick;
4745 rect.width = width - (xthick * 2);
4746 rect.height = height - (ythick * 2);
4749 intersect = gdk_rectangle_intersect (area, &rect, &dest);
4759 gdk_gc_set_clip_rectangle (light_gc, &dest);
4760 gdk_gc_set_clip_rectangle (dark_gc, &dest);
4762 if (detail && !strcmp (detail, "paned"))
4764 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4765 for (xx = x + width/2 - 15; xx <= x + width/2 + 15; xx += 5)
4766 draw_dot (window, light_gc, dark_gc, xx, y + height/2 - 1, 3);
4768 for (yy = y + height/2 - 15; yy <= y + height/2 + 15; yy += 5)
4769 draw_dot (window, light_gc, dark_gc, x + width/2 - 1, yy, 3);
4773 for (yy = y + ythick; yy < (y + height - ythick); yy += 3)
4774 for (xx = x + xthick; xx < (x + width - xthick); xx += 6)
4776 draw_dot (window, light_gc, dark_gc, xx, yy, 2);
4777 draw_dot (window, light_gc, dark_gc, xx + 3, yy + 1, 2);
4781 gdk_gc_set_clip_rectangle (light_gc, NULL);
4782 gdk_gc_set_clip_rectangle (dark_gc, NULL);
4786 g_object_unref (free_me);
4790 gtk_default_draw_expander (GtkStyle *style,
4792 GtkStateType state_type,
4795 const gchar *detail,
4798 GtkExpanderStyle expander_style)
4800 #define DEFAULT_EXPANDER_SIZE 12
4804 double vertical_overshoot;
4807 double x_double, y_double;
4810 cairo_t *cr = gdk_drawable_create_cairo_context (window);
4815 cairo_rectangle (cr, area->x, area->y, area->width, area->height);
4817 cairo_new_path (cr);
4821 gtk_widget_class_find_style_property (GTK_WIDGET_GET_CLASS (widget),
4824 gtk_widget_style_get (widget,
4825 "expander-size", &expander_size,
4829 expander_size = DEFAULT_EXPANDER_SIZE;
4831 line_width = MAX (1, expander_size/9);
4833 switch (expander_style)
4835 case GTK_EXPANDER_COLLAPSED:
4836 degrees = (get_direction (widget) == GTK_TEXT_DIR_RTL) ? 180 : 0;
4838 case GTK_EXPANDER_SEMI_COLLAPSED:
4839 degrees = (get_direction (widget) == GTK_TEXT_DIR_RTL) ? 150 : 30;
4841 case GTK_EXPANDER_SEMI_EXPANDED:
4842 degrees = (get_direction (widget) == GTK_TEXT_DIR_RTL) ? 120 : 60;
4844 case GTK_EXPANDER_EXPANDED:
4848 g_assert_not_reached ();
4851 /* Compute distance that the stroke extends beyonds the end
4852 * of the triangle we draw.
4854 vertical_overshoot = line_width / 2.0 * (1. / tan (G_PI / 8));
4856 /* For odd line widths, we end the vertical line of the triangle
4857 * at a half pixel, so we round differently.
4859 if (line_width % 2 == 1)
4860 vertical_overshoot = ceil (0.5 + vertical_overshoot) - 0.5;
4862 vertical_overshoot = ceil (vertical_overshoot);
4864 /* Adjust the size of the triangle we draw so that the entire stroke fits
4866 diameter = MAX (3, expander_size - 2 * vertical_overshoot);
4868 /* If the line width is odd, we want the diameter to be even,
4869 * and vice versa, so force the sum to be odd
4871 diameter -= (1 - (diameter + line_width) % 2);
4873 radius = diameter / 2.;
4875 /* Adjust the center so that the stroke is properly aligned with
4878 x_double = floor (x - (radius + line_width) / 2.) + (radius + line_width) / 2.;
4881 cairo_translate (cr, x_double, y_double);
4882 cairo_rotate (cr, degrees * M_PI / 180);
4884 cairo_move_to (cr, - radius / 2., - radius);
4885 cairo_line_to (cr, radius / 2., 0);
4886 cairo_line_to (cr, - radius / 2., radius);
4887 cairo_close_path (cr);
4889 cairo_set_line_width (cr, line_width);
4892 if (state_type == GTK_STATE_PRELIGHT)
4893 gdk_cairo_set_source_color (cr,
4894 &style->fg[GTK_STATE_PRELIGHT]);
4895 else if (state_type == GTK_STATE_ACTIVE)
4896 gdk_cairo_set_source_color (cr,
4897 &style->light[GTK_STATE_ACTIVE]);
4899 gdk_cairo_set_source_color (cr,
4900 &style->base[GTK_STATE_NORMAL]);
4905 gdk_cairo_set_source_color (cr, &style->fg[state_type]);
4914 typedef struct _ByteRange ByteRange;
4923 range_new (guint start,
4926 ByteRange *br = g_new (ByteRange, 1);
4935 get_insensitive_layout (GdkDrawable *drawable,
4936 PangoLayout *layout)
4938 GSList *embossed_ranges = NULL;
4939 GSList *stippled_ranges = NULL;
4940 PangoLayoutIter *iter;
4941 GSList *tmp_list = NULL;
4942 PangoLayout *new_layout;
4943 PangoAttrList *attrs;
4944 GdkBitmap *stipple = NULL;
4946 iter = pango_layout_get_iter (layout);
4950 PangoLayoutRun *run;
4951 PangoAttribute *attr;
4952 gboolean need_stipple = FALSE;
4955 run = pango_layout_iter_get_run (iter);
4959 tmp_list = run->item->analysis.extra_attrs;
4961 while (tmp_list != NULL)
4963 attr = tmp_list->data;
4964 switch (attr->klass->type)
4966 case PANGO_ATTR_FOREGROUND:
4967 case PANGO_ATTR_BACKGROUND:
4968 need_stipple = TRUE;
4978 tmp_list = g_slist_next (tmp_list);
4981 br = range_new (run->item->offset, run->item->offset + run->item->length);
4984 stippled_ranges = g_slist_prepend (stippled_ranges, br);
4986 embossed_ranges = g_slist_prepend (embossed_ranges, br);
4989 while (pango_layout_iter_next_run (iter));
4991 pango_layout_iter_free (iter);
4993 new_layout = pango_layout_copy (layout);
4995 attrs = pango_layout_get_attributes (new_layout);
4999 /* Create attr list if there wasn't one */
5000 attrs = pango_attr_list_new ();
5001 pango_layout_set_attributes (new_layout, attrs);
5002 pango_attr_list_unref (attrs);
5005 tmp_list = embossed_ranges;
5006 while (tmp_list != NULL)
5008 PangoAttribute *attr;
5009 ByteRange *br = tmp_list->data;
5011 attr = gdk_pango_attr_embossed_new (TRUE);
5013 attr->start_index = br->start;
5014 attr->end_index = br->end;
5016 pango_attr_list_change (attrs, attr);
5020 tmp_list = g_slist_next (tmp_list);
5023 g_slist_free (embossed_ranges);
5025 tmp_list = stippled_ranges;
5026 while (tmp_list != NULL)
5028 PangoAttribute *attr;
5029 ByteRange *br = tmp_list->data;
5031 if (stipple == NULL)
5033 #define gray50_width 2
5034 #define gray50_height 2
5035 static const char gray50_bits[] = {
5039 stipple = gdk_bitmap_create_from_data (drawable,
5040 gray50_bits, gray50_width,
5044 attr = gdk_pango_attr_stipple_new (stipple);
5046 attr->start_index = br->start;
5047 attr->end_index = br->end;
5049 pango_attr_list_change (attrs, attr);
5053 tmp_list = g_slist_next (tmp_list);
5056 g_slist_free (stippled_ranges);
5059 g_object_unref (stipple);
5065 gtk_default_draw_layout (GtkStyle *style,
5067 GtkStateType state_type,
5071 const gchar *detail,
5074 PangoLayout *layout)
5078 g_return_if_fail (GTK_IS_STYLE (style));
5079 g_return_if_fail (window != NULL);
5081 gc = use_text ? style->text_gc[state_type] : style->fg_gc[state_type];
5084 gdk_gc_set_clip_rectangle (gc, area);
5086 if (state_type == GTK_STATE_INSENSITIVE)
5090 ins = get_insensitive_layout (window, layout);
5092 gdk_draw_layout (window, gc, x, y, ins);
5094 g_object_unref (ins);
5098 gdk_draw_layout (window, gc, x, y, layout);
5102 gdk_gc_set_clip_rectangle (gc, NULL);
5106 gtk_default_draw_resize_grip (GtkStyle *style,
5108 GtkStateType state_type,
5111 const gchar *detail,
5121 g_return_if_fail (GTK_IS_STYLE (style));
5122 g_return_if_fail (window != NULL);
5126 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
5127 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
5128 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
5134 case GDK_WINDOW_EDGE_NORTH_WEST:
5135 /* make it square */
5138 else if (height < width)
5142 case GDK_WINDOW_EDGE_NORTH:
5146 case GDK_WINDOW_EDGE_NORTH_EAST:
5147 /* make it square, aligning to top right */
5150 else if (height < width)
5152 x += (width - height);
5157 case GDK_WINDOW_EDGE_WEST:
5161 case GDK_WINDOW_EDGE_EAST:
5162 /* aligning to right */
5165 x += (width - height);
5169 case GDK_WINDOW_EDGE_SOUTH_WEST:
5170 /* make it square, aligning to bottom left */
5173 y += (height - width);
5176 else if (height < width)
5180 case GDK_WINDOW_EDGE_SOUTH:
5181 /* align to bottom */
5184 y += (height - width);
5188 case GDK_WINDOW_EDGE_SOUTH_EAST:
5189 /* make it square, aligning to bottom right */
5192 y += (height - width);
5195 else if (height < width)
5197 x += (width - height);
5203 g_assert_not_reached ();
5205 /* Clear background */
5207 for (i = 0; i < 4; i++)
5211 points[j].x = (i == 0 || i == 3) ? x : x + width;
5212 points[j].y = (i < 2) ? y : y + height;
5217 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE,
5218 points, skip < 0 ? 4 : 3);
5222 case GDK_WINDOW_EDGE_WEST:
5223 case GDK_WINDOW_EDGE_EAST:
5229 while (xi < x + width)
5231 gdk_draw_line (window,
5232 style->light_gc[state_type],
5237 gdk_draw_line (window,
5238 style->dark_gc[state_type],
5246 case GDK_WINDOW_EDGE_NORTH:
5247 case GDK_WINDOW_EDGE_SOUTH:
5253 while (yi < y + height)
5255 gdk_draw_line (window,
5256 style->light_gc[state_type],
5261 gdk_draw_line (window,
5262 style->dark_gc[state_type],
5270 case GDK_WINDOW_EDGE_NORTH_WEST:
5279 gdk_draw_line (window,
5280 style->dark_gc[state_type],
5287 gdk_draw_line (window,
5288 style->dark_gc[state_type],
5295 gdk_draw_line (window,
5296 style->light_gc[state_type],
5306 case GDK_WINDOW_EDGE_NORTH_EAST:
5313 while (xi < (x + width - 3))
5315 gdk_draw_line (window,
5316 style->light_gc[state_type],
5323 gdk_draw_line (window,
5324 style->dark_gc[state_type],
5331 gdk_draw_line (window,
5332 style->dark_gc[state_type],
5341 case GDK_WINDOW_EDGE_SOUTH_WEST:
5350 gdk_draw_line (window,
5351 style->dark_gc[state_type],
5358 gdk_draw_line (window,
5359 style->dark_gc[state_type],
5366 gdk_draw_line (window,
5367 style->light_gc[state_type],
5377 case GDK_WINDOW_EDGE_SOUTH_EAST:
5384 while (xi < (x + width - 3))
5386 gdk_draw_line (window,
5387 style->light_gc[state_type],
5394 gdk_draw_line (window,
5395 style->dark_gc[state_type],
5402 gdk_draw_line (window,
5403 style->dark_gc[state_type],
5413 g_assert_not_reached ();
5419 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
5420 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
5421 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
5426 gtk_style_shade (GdkColor *a,
5434 red = (gdouble) a->red / 65535.0;
5435 green = (gdouble) a->green / 65535.0;
5436 blue = (gdouble) a->blue / 65535.0;
5438 rgb_to_hls (&red, &green, &blue);
5443 else if (green < 0.0)
5449 else if (blue < 0.0)
5452 hls_to_rgb (&red, &green, &blue);
5454 b->red = red * 65535.0;
5455 b->green = green * 65535.0;
5456 b->blue = blue * 65535.0;
5460 rgb_to_hls (gdouble *r,
5501 l = (max + min) / 2;
5508 s = (max - min) / (max + min);
5510 s = (max - min) / (2 - max - min);
5514 h = (green - blue) / delta;
5515 else if (green == max)
5516 h = 2 + (blue - red) / delta;
5517 else if (blue == max)
5518 h = 4 + (red - green) / delta;
5531 hls_to_rgb (gdouble *h,
5544 if (lightness <= 0.5)
5545 m2 = lightness * (1 + saturation);
5547 m2 = lightness + saturation - lightness * saturation;
5548 m1 = 2 * lightness - m2;
5550 if (saturation == 0)
5565 r = m1 + (m2 - m1) * hue / 60;
5569 r = m1 + (m2 - m1) * (240 - hue) / 60;
5580 g = m1 + (m2 - m1) * hue / 60;
5584 g = m1 + (m2 - m1) * (240 - hue) / 60;
5595 b = m1 + (m2 - m1) * hue / 60;
5599 b = m1 + (m2 - m1) * (240 - hue) / 60;
5612 * @style: a #GtkStyle
5613 * @window: a #GdkWindow
5614 * @state_type: a state
5615 * @area: rectangle to which the output is clipped, or %NULL if the
5616 * output should not be clipped
5617 * @widget: the widget (may be %NULL)
5618 * @detail: a style detail (may be %NULL)
5619 * @x1: the starting x coordinate
5620 * @x2: the ending x coordinate
5621 * @y: the y coordinate
5623 * Draws a horizontal line from (@x1, @y) to (@x2, @y) in @window
5624 * using the given style and state.
5627 gtk_paint_hline (GtkStyle *style,
5629 GtkStateType state_type,
5632 const gchar *detail,
5637 g_return_if_fail (GTK_IS_STYLE (style));
5638 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
5639 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
5641 GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, area, widget, detail, x1, x2, y);
5646 * @style: a #GtkStyle
5647 * @window: a #GdkWindow
5648 * @state_type: a state
5649 * @area: rectangle to which the output is clipped, or %NULL if the
5650 * output should not be clipped
5651 * @widget: the widget (may be %NULL)
5652 * @detail: a style detail (may be %NULL)
5653 * @y1_: the starting y coordinate
5654 * @y2_: the ending y coordinate
5655 * @x: the x coordinate
5657 * Draws a vertical line from (@x, @y1_) to (@x, @y2_) in @window
5658 * using the given style and state.
5661 gtk_paint_vline (GtkStyle *style,
5663 GtkStateType state_type,
5666 const gchar *detail,
5671 g_return_if_fail (GTK_IS_STYLE (style));
5672 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
5673 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
5675 GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, area, widget, detail, y1_, y2_, x);
5680 * @style: a #GtkStyle
5681 * @window: a #GdkWindow
5682 * @state_type: a state
5683 * @shadow_type: type of shadow to draw
5684 * @area: clip rectangle or %NULL if the
5685 * output should not be clipped
5686 * @widget: the widget (may be %NULL)
5687 * @detail: a style detail (may be %NULL)
5688 * @x: x origin of the rectangle
5689 * @y: y origin of the rectangle
5690 * @width: width of the rectangle
5691 * @height: width of the rectangle
5693 * Draws a shadow around the given rectangle in @window
5694 * using the given style and state and shadow type.
5697 gtk_paint_shadow (GtkStyle *style,
5699 GtkStateType state_type,
5700 GtkShadowType shadow_type,
5703 const gchar *detail,
5709 g_return_if_fail (GTK_IS_STYLE (style));
5710 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
5711 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
5713 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5717 * gtk_paint_polygon:
5718 * @style: a #GtkStyle
5719 * @window: a #GdkWindow
5720 * @state_type: a state
5721 * @shadow_type: type of shadow to draw
5722 * @area: clip rectangle, or %NULL if the
5723 * output should not be clipped
5724 * @widget: the widget (may be %NULL)
5725 * @detail: a style detail (may be %NULL)
5726 * @points: an array of #GdkPoint<!-- -->s
5727 * @npoints: length of @points
5728 * @fill: %TRUE if the polygon should be filled
5730 * Draws a polygon on @window with the given parameters.
5733 gtk_paint_polygon (GtkStyle *style,
5735 GtkStateType state_type,
5736 GtkShadowType shadow_type,
5739 const gchar *detail,
5744 g_return_if_fail (GTK_IS_STYLE (style));
5745 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_polygon != NULL);
5746 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
5748 GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, area, widget, detail, points, npoints, fill);
5753 * @style: a #GtkStyle
5754 * @window: a #GdkWindow
5755 * @state_type: a state
5756 * @shadow_type: the type of shadow to draw
5757 * @area: clip rectangle, or %NULL if the
5758 * output should not be clipped
5759 * @widget: the widget (may be %NULL)
5760 * @detail: a style detail (may be %NULL)
5761 * @arrow_type: the type of arrow to draw
5762 * @fill: %TRUE if the arrow tip should be filled
5763 * @x: x origin of the rectangle to draw the arrow in
5764 * @y: y origin of the rectangle to draw the arrow in
5765 * @width: width of the rectangle to draw the arrow in
5766 * @height: height of the rectangle to draw the arrow in
5768 * Draws an arrow in the given rectangle on @window using the given
5769 * parameters. @arrow_type determines the direction of the arrow.
5772 gtk_paint_arrow (GtkStyle *style,
5774 GtkStateType state_type,
5775 GtkShadowType shadow_type,
5778 const gchar *detail,
5779 GtkArrowType arrow_type,
5786 g_return_if_fail (GTK_IS_STYLE (style));
5787 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
5788 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
5790 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, area, widget, detail, arrow_type, fill, x, y, width, height);
5794 * gtk_paint_diamond:
5795 * @style: a #GtkStyle
5796 * @window: a #GdkWindow
5797 * @state_type: a state
5798 * @shadow_type: the type of shadow to draw
5799 * @area: clip rectangle, or %NULL if the
5800 * output should not be clipped
5801 * @widget: the widget (may be %NULL)
5802 * @detail: a style detail (may be %NULL)
5803 * @x: x origin of the rectangle to draw the diamond in
5804 * @y: y origin of the rectangle to draw the diamond in
5805 * @width: width of the rectangle to draw the diamond in
5806 * @height: height of the rectangle to draw the diamond in
5808 * Draws a diamond in the given rectangle on @window using the given
5812 gtk_paint_diamond (GtkStyle *style,
5814 GtkStateType state_type,
5815 GtkShadowType shadow_type,
5818 const gchar *detail,
5824 g_return_if_fail (GTK_IS_STYLE (style));
5825 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
5826 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
5828 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5833 * @style: a #GtkStyle
5834 * @window: a #GdkWindow
5835 * @state_type: a state
5836 * @area: clip rectangle, or %NULL if the
5837 * output should not be clipped
5838 * @widget: the widget (may be %NULL)
5839 * @detail: a style detail (may be %NULL)
5842 * @string: the string to draw
5844 * Draws a text string on @window with the given parameters.
5846 * Deprecated: Use gtk_paint_layout() instead.
5849 gtk_paint_string (GtkStyle *style,
5851 GtkStateType state_type,
5854 const gchar *detail,
5857 const gchar *string)
5859 g_return_if_fail (GTK_IS_STYLE (style));
5860 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
5861 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
5863 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, area, widget, detail, x, y, string);
5868 * @style: a #GtkStyle
5869 * @window: a #GdkWindow
5870 * @state_type: a state
5871 * @shadow_type: the type of shadow to draw
5872 * @area: clip rectangle, or %NULL if the
5873 * output should not be clipped
5874 * @widget: the widget (may be %NULL)
5875 * @detail: a style detail (may be %NULL)
5876 * @x: x origin of the box
5877 * @y: y origin of the box
5878 * @width: the width of the box
5879 * @height: the height of the box
5881 * Draws a box on @window with the given parameters.
5884 gtk_paint_box (GtkStyle *style,
5886 GtkStateType state_type,
5887 GtkShadowType shadow_type,
5890 const gchar *detail,
5896 g_return_if_fail (GTK_IS_STYLE (style));
5897 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
5898 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
5900 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5904 * gtk_paint_flat_box:
5905 * @style: a #GtkStyle
5906 * @window: a #GdkWindow
5907 * @state_type: a state
5908 * @shadow_type: the type of shadow to draw
5909 * @area: clip rectangle, or %NULL if the
5910 * output should not be clipped
5911 * @widget: the widget (may be %NULL)
5912 * @detail: a style detail (may be %NULL)
5913 * @x: x origin of the box
5914 * @y: y origin of the box
5915 * @width: the width of the box
5916 * @height: the height of the box
5918 * Draws a flat box on @window with the given parameters.
5921 gtk_paint_flat_box (GtkStyle *style,
5923 GtkStateType state_type,
5924 GtkShadowType shadow_type,
5927 const gchar *detail,
5933 g_return_if_fail (GTK_IS_STYLE (style));
5934 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
5935 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
5937 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5942 * @style: a #GtkStyle
5943 * @window: a #GdkWindow
5944 * @state_type: a state
5945 * @shadow_type: the type of shadow to draw
5946 * @area: clip rectangle, or %NULL if the
5947 * output should not be clipped
5948 * @widget: the widget (may be %NULL)
5949 * @detail: a style detail (may be %NULL)
5950 * @x: x origin of the rectangle to draw the check in
5951 * @y: y origin of the rectangle to draw the check in
5952 * @width: the width of the rectangle to draw the check in
5953 * @height: the height of the rectangle to draw the check in
5955 * Draws a check button indicator in the given rectangle on @window with
5956 * the given parameters.
5959 gtk_paint_check (GtkStyle *style,
5961 GtkStateType state_type,
5962 GtkShadowType shadow_type,
5965 const gchar *detail,
5971 g_return_if_fail (GTK_IS_STYLE (style));
5972 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
5973 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
5975 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5980 * @style: a #GtkStyle
5981 * @window: a #GdkWindow
5982 * @state_type: a state
5983 * @shadow_type: the type of shadow to draw
5984 * @area: clip rectangle, or %NULL if the
5985 * output should not be clipped
5986 * @widget: the widget (may be %NULL)
5987 * @detail: a style detail (may be %NULL)
5988 * @x: x origin of the rectangle to draw the option in
5989 * @y: y origin of the rectangle to draw the option in
5990 * @width: the width of the rectangle to draw the option in
5991 * @height: the height of the rectangle to draw the option in
5993 * Draws a radio button indicator in the given rectangle on @window with
5994 * the given parameters.
5997 gtk_paint_option (GtkStyle *style,
5999 GtkStateType state_type,
6000 GtkShadowType shadow_type,
6003 const gchar *detail,
6009 g_return_if_fail (GTK_IS_STYLE (style));
6010 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
6011 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
6013 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
6018 * @style: a #GtkStyle
6019 * @window: a #GdkWindow
6020 * @state_type: a state
6021 * @shadow_type: the type of shadow to draw
6022 * @area: clip rectangle, or %NULL if the
6023 * output should not be clipped
6024 * @widget: the widget (may be %NULL)
6025 * @detail: a style detail (may be %NULL)
6026 * @x: x origin of the rectangle to draw the tab in
6027 * @y: y origin of the rectangle to draw the tab in
6028 * @width: the width of the rectangle to draw the tab in
6029 * @height: the height of the rectangle to draw the tab in
6031 * Draws an option menu tab (i.e. the up and down pointing arrows)
6032 * in the given rectangle on @window using the given parameters.
6035 gtk_paint_tab (GtkStyle *style,
6037 GtkStateType state_type,
6038 GtkShadowType shadow_type,
6041 const gchar *detail,
6047 g_return_if_fail (GTK_IS_STYLE (style));
6048 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
6049 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
6051 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
6055 * gtk_paint_shadow_gap:
6056 * @style: a #GtkStyle
6057 * @window: a #GdkWindow
6058 * @state_type: a state
6059 * @shadow_type: type of shadow to draw
6060 * @area: clip rectangle, or %NULL if the
6061 * output should not be clipped
6062 * @widget: the widget (may be %NULL)
6063 * @detail: a style detail (may be %NULL)
6064 * @x: x origin of the rectangle
6065 * @y: y origin of the rectangle
6066 * @width: width of the rectangle
6067 * @height: width of the rectangle
6068 * @gap_side: side in which to leave the gap
6069 * @gap_x: starting position of the gap
6070 * @gap_width: width of the gap
6072 * Draws a shadow around the given rectangle in @window
6073 * using the given style and state and shadow type, leaving a
6077 gtk_paint_shadow_gap (GtkStyle *style,
6079 GtkStateType state_type,
6080 GtkShadowType shadow_type,
6088 GtkPositionType gap_side,
6092 g_return_if_fail (GTK_IS_STYLE (style));
6093 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
6094 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
6096 GTK_STYLE_GET_CLASS (style)->draw_shadow_gap (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, gap_side, gap_x, gap_width);
6101 * gtk_paint_box_gap:
6102 * @style: a #GtkStyle
6103 * @window: a #GdkWindow
6104 * @state_type: a state
6105 * @shadow_type: type of shadow to draw
6106 * @area: clip rectangle, or %NULL if the
6107 * output should not be clipped
6108 * @widget: the widget (may be %NULL)
6109 * @detail: a style detail (may be %NULL)
6110 * @x: x origin of the rectangle
6111 * @y: y origin of the rectangle
6112 * @width: width of the rectangle
6113 * @height: width of the rectangle
6114 * @gap_side: side in which to leave the gap
6115 * @gap_x: starting position of the gap
6116 * @gap_width: width of the gap
6118 * Draws a box in @window using the given style and state and shadow type,
6119 * leaving a gap in one side.
6122 gtk_paint_box_gap (GtkStyle *style,
6124 GtkStateType state_type,
6125 GtkShadowType shadow_type,
6133 GtkPositionType gap_side,
6137 g_return_if_fail (GTK_IS_STYLE (style));
6138 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
6139 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
6141 GTK_STYLE_GET_CLASS (style)->draw_box_gap (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, gap_side, gap_x, gap_width);
6145 * gtk_paint_extension:
6146 * @style: a #GtkStyle
6147 * @window: a #GdkWindow
6148 * @state_type: a state
6149 * @shadow_type: type of shadow to draw
6150 * @area: clip rectangle, or %NULL if the
6151 * output should not be clipped
6152 * @widget: the widget (may be %NULL)
6153 * @detail: a style detail (may be %NULL)
6154 * @x: x origin of the extension
6155 * @y: y origin of the extension
6156 * @width: width of the extension
6157 * @height: width of the extension
6158 * @gap_side: the side on to which the extension is attached
6160 * Draws an extension, i.e. a notebook tab.
6163 gtk_paint_extension (GtkStyle *style,
6165 GtkStateType state_type,
6166 GtkShadowType shadow_type,
6174 GtkPositionType gap_side)
6176 g_return_if_fail (GTK_IS_STYLE (style));
6177 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
6178 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
6180 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, gap_side);
6185 * @style: a #GtkStyle
6186 * @window: a #GdkWindow
6187 * @state_type: a state
6188 * @area: clip rectangle, or %NULL if the
6189 * output should not be clipped
6190 * @widget: the widget (may be %NULL)
6191 * @detail: a style detail (may be %NULL)
6192 * @x: the x origin of the rectangle around which to draw a focus indicator
6193 * @y: the y origin of the rectangle around which to draw a focus indicator
6194 * @width: the width of the rectangle around which to draw a focus indicator
6195 * @height: the height of the rectangle around which to draw a focus indicator
6197 * Draws a focus indicator around the given rectangle on @window using the
6201 gtk_paint_focus (GtkStyle *style,
6203 GtkStateType state_type,
6206 const gchar *detail,
6212 g_return_if_fail (GTK_IS_STYLE (style));
6213 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
6214 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
6216 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, state_type, area, widget, detail, x, y, width, height);
6220 gtk_paint_slider (GtkStyle *style,
6222 GtkStateType state_type,
6223 GtkShadowType shadow_type,
6226 const gchar *detail,
6231 GtkOrientation orientation)
6233 g_return_if_fail (GTK_IS_STYLE (style));
6234 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
6235 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
6237 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
6242 * @style: a #GtkStyle
6243 * @window: a #GdkWindow
6244 * @state_type: a state
6245 * @shadow_type: type of shadow to draw
6246 * @area: clip rectangle, or %NULL if the
6247 * output should not be clipped
6248 * @widget: the widget (may be %NULL)
6249 * @detail: a style detail (may be %NULL)
6250 * @x: x origin of the handle
6251 * @y: y origin of the handle
6252 * @width: with of the handle
6253 * @height: height of the handle
6254 * @orientation: the orientation of the handle
6256 * Draws a handle as used in #GtkHandleBox and #GtkPaned.
6259 gtk_paint_handle (GtkStyle *style,
6261 GtkStateType state_type,
6262 GtkShadowType shadow_type,
6265 const gchar *detail,
6270 GtkOrientation orientation)
6272 g_return_if_fail (GTK_IS_STYLE (style));
6273 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
6274 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
6276 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
6280 * gtk_paint_expander:
6281 * @style: a #GtkStyle
6282 * @window: a #GdkWindow
6283 * @state_type: a state
6284 * @area: clip rectangle, or %NULL if the
6285 * output should not be clipped
6286 * @widget: the widget (may be %NULL)
6287 * @detail: a style detail (may be %NULL)
6288 * @x: the x position to draw the expander at
6289 * @y: the y position to draw the expander at
6290 * @expander_style: the style to draw the expander in; determines
6291 * whether the expander is collapsed, expanded, or in an
6292 * intermediate state.
6294 * Draws an expander as used in #GtkTreeView. @x and @y specify the
6295 * center the expander. The size of the expander is determined by the
6296 * "expander-size" style property of @widget. (If widget is not
6297 * specified or doesn't have an "expander-size" property, an
6298 * unspecified default size will be used, since the caller doesn't
6299 * have sufficient information to position the expander, this is
6300 * likely not useful.) The expander is expander_size pixels tall
6301 * in the collapsed position and expander_size pixels wide in the
6302 * expanded position.
6305 gtk_paint_expander (GtkStyle *style,
6307 GtkStateType state_type,
6310 const gchar *detail,
6313 GtkExpanderStyle expander_style)
6315 g_return_if_fail (GTK_IS_STYLE (style));
6316 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
6317 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
6319 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type, area,
6320 widget, detail, x, y, expander_style);
6324 gtk_paint_layout (GtkStyle *style,
6326 GtkStateType state_type,
6330 const gchar *detail,
6333 PangoLayout *layout)
6335 g_return_if_fail (GTK_IS_STYLE (style));
6336 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
6337 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
6339 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, use_text, area,
6340 widget, detail, x, y, layout);
6344 * gtk_paint_resize_grip:
6345 * @style: a #GtkStyle
6346 * @window: a #GdkWindow
6347 * @state_type: a state
6348 * @area: clip rectangle, or %NULL if the
6349 * output should not be clipped
6350 * @widget: the widget (may be %NULL)
6351 * @detail: a style detail (may be %NULL)
6352 * @edge: the edge in which to draw the resize grip
6353 * @x: the x origin of the rectangle in which to draw the resize grip
6354 * @y: the y origin of the rectangle in which to draw the resize grip
6355 * @width: the width of the rectangle in which to draw the resize grip
6356 * @height: the height of the rectangle in which to draw the resize grip
6358 * Draws a resize grip in the given rectangle on @window using the given
6362 gtk_paint_resize_grip (GtkStyle *style,
6364 GtkStateType state_type,
6367 const gchar *detail,
6375 g_return_if_fail (GTK_IS_STYLE (style));
6376 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
6377 g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
6379 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, window, state_type,
6380 area, widget, detail,
6381 edge, x, y, width, height);
6386 * @border_: a #GtkBorder.
6387 * @returns: a copy of @border_.
6389 * Copies a #GtkBorder structure.
6392 gtk_border_copy (const GtkBorder *border)
6394 return (GtkBorder *)g_memdup (border, sizeof (GtkBorder));
6399 * @border_: a #GtkBorder.
6401 * Frees a #GtkBorder structure.
6404 gtk_border_free (GtkBorder *border)
6410 gtk_border_get_type (void)
6412 static GType our_type = 0;
6415 our_type = g_boxed_type_register_static ("GtkBorder",
6416 (GBoxedCopyFunc) gtk_border_copy,
6417 (GBoxedFreeFunc) gtk_border_free);
6423 gtk_style_get_font_internal (GtkStyle *style)
6425 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
6427 if (style->private_font && style->private_font_desc)
6429 if (!style->font_desc ||
6430 !pango_font_description_equal (style->private_font_desc, style->font_desc))
6432 gdk_font_unref (style->private_font);
6433 style->private_font = NULL;
6435 if (style->private_font_desc)
6437 pango_font_description_free (style->private_font_desc);
6438 style->private_font_desc = NULL;
6443 if (!style->private_font)
6445 GdkDisplay *display;
6447 if (style->colormap)
6449 display = gdk_screen_get_display (gdk_colormap_get_screen (style->colormap));
6453 display = gdk_display_get_default ();
6454 GTK_NOTE (MULTIHEAD,
6455 g_warning ("gtk_style_get_font() should not be called on an unattached style"));
6458 if (style->font_desc)
6460 style->private_font = gdk_font_from_description_for_display (display, style->font_desc);
6461 style->private_font_desc = pango_font_description_copy (style->font_desc);
6464 if (!style->private_font)
6465 style->private_font = gdk_font_load_for_display (display, "fixed");
6467 if (!style->private_font)
6468 g_error ("Unable to load \"fixed\" font");
6471 return style->private_font;
6475 * gtk_style_get_font:
6476 * @style: a #GtkStyle
6478 * Gets the #GdkFont to use for the given style. This is
6479 * meant only as a replacement for direct access to @style->font
6480 * and should not be used in new code. New code should
6481 * use @style->font_desc instead.
6483 * Return value: the #GdkFont for the style. This font is owned
6484 * by the style; if you want to keep around a copy, you must
6485 * call gdk_font_ref().
6488 gtk_style_get_font (GtkStyle *style)
6490 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
6492 return gtk_style_get_font_internal (style);
6496 * gtk_style_set_font:
6497 * @style: a #GtkStyle.
6498 * @font: a #GdkFont, or %NULL to use the #GdkFont corresponding
6499 * to style->font_desc.
6501 * Sets the #GdkFont to use for a given style. This is
6502 * meant only as a replacement for direct access to style->font
6503 * and should not be used in new code. New code should
6504 * use style->font_desc instead.
6507 gtk_style_set_font (GtkStyle *style,
6512 g_return_if_fail (GTK_IS_STYLE (style));
6514 old_font = style->private_font;
6516 style->private_font = font;
6518 gdk_font_ref (font);
6521 gdk_font_unref (old_font);
6523 if (style->private_font_desc)
6525 pango_font_description_free (style->private_font_desc);
6526 style->private_font_desc = NULL;
6530 typedef struct _CursorInfo CursorInfo;
6536 GdkGC *secondary_gc;
6540 style_unrealize_cursor_gcs (GtkStyle *style)
6544 cursor_info = g_object_get_data (G_OBJECT (style), "gtk-style-cursor-info");
6547 if (cursor_info->primary_gc)
6548 gtk_gc_release (cursor_info->primary_gc);
6550 if (cursor_info->secondary_gc)
6551 gtk_gc_release (cursor_info->secondary_gc);
6553 g_free (cursor_info);
6554 g_object_set_data (G_OBJECT (style), "gtk-style-cursor-info", NULL);
6559 make_cursor_gc (GtkWidget *widget,
6560 const gchar *property_name,
6561 const GdkColor *fallback)
6563 GdkGCValues gc_values;
6564 GdkGCValuesMask gc_values_mask;
6565 GdkColor *cursor_color;
6567 gtk_widget_style_get (widget, property_name, &cursor_color, NULL);
6569 gc_values_mask = GDK_GC_FOREGROUND;
6572 gc_values.foreground = *cursor_color;
6573 gdk_color_free (cursor_color);
6576 gc_values.foreground = *fallback;
6578 gdk_rgb_find_color (widget->style->colormap, &gc_values.foreground);
6579 return gtk_gc_get (widget->style->depth, widget->style->colormap, &gc_values, gc_values_mask);
6583 get_insertion_cursor_gc (GtkWidget *widget,
6584 gboolean is_primary)
6586 CursorInfo *cursor_info;
6588 cursor_info = g_object_get_data (G_OBJECT (widget->style), "gtk-style-cursor-info");
6591 cursor_info = g_new (CursorInfo, 1);
6592 g_object_set_data (G_OBJECT (widget->style), "gtk-style-cursor-info", cursor_info);
6593 cursor_info->primary_gc = NULL;
6594 cursor_info->secondary_gc = NULL;
6595 cursor_info->for_type = G_TYPE_INVALID;
6598 /* We have to keep track of the type because gtk_widget_style_get()
6599 * can return different results when called on the same property and
6600 * same style but for different widgets. :-(. That is,
6601 * GtkEntry::cursor-color = "red" in a style will modify the cursor
6602 * color for entries but not for text view.
6604 if (cursor_info->for_type != G_OBJECT_TYPE (widget))
6606 cursor_info->for_type = G_OBJECT_TYPE (widget);
6607 if (cursor_info->primary_gc)
6609 gtk_gc_release (cursor_info->primary_gc);
6610 cursor_info->primary_gc = NULL;
6612 if (cursor_info->secondary_gc)
6614 gtk_gc_release (cursor_info->secondary_gc);
6615 cursor_info->secondary_gc = NULL;
6621 if (!cursor_info->primary_gc)
6622 cursor_info->primary_gc = make_cursor_gc (widget,
6624 &widget->style->black);
6626 return cursor_info->primary_gc;
6630 static const GdkColor gray = { 0, 0x8888, 0x8888, 0x8888 };
6632 if (!cursor_info->secondary_gc)
6633 cursor_info->secondary_gc = make_cursor_gc (widget,
6634 "secondary-cursor-color",
6637 return cursor_info->secondary_gc;
6642 draw_insertion_cursor (GtkWidget *widget,
6643 GdkDrawable *drawable,
6645 GdkRectangle *location,
6646 GtkTextDirection direction,
6647 gboolean draw_arrow)
6653 gfloat cursor_aspect_ratio;
6656 g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
6658 gtk_widget_style_get (widget, "cursor-aspect-ratio", &cursor_aspect_ratio, NULL);
6660 stem_width = location->height * cursor_aspect_ratio + 1;
6661 arrow_width = stem_width + 1;
6663 /* put (stem_width % 2) on the proper side of the cursor */
6664 if (direction == GTK_TEXT_DIR_LTR)
6665 offset = stem_width / 2;
6667 offset = stem_width - stem_width / 2;
6669 for (i = 0; i < stem_width; i++)
6670 gdk_draw_line (drawable, gc,
6671 location->x + i - offset, location->y,
6672 location->x + i - offset, location->y + location->height - 1);
6676 if (direction == GTK_TEXT_DIR_RTL)
6678 x = location->x - offset - 1;
6679 y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
6681 for (i = 0; i < arrow_width; i++)
6683 gdk_draw_line (drawable, gc,
6685 x, y + 2 * arrow_width - i - 1);
6689 else if (direction == GTK_TEXT_DIR_LTR)
6691 x = location->x + stem_width - offset;
6692 y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
6694 for (i = 0; i < arrow_width; i++)
6696 gdk_draw_line (drawable, gc,
6698 x, y + 2 * arrow_width - i - 1);
6706 * gtk_draw_insertion_cursor:
6707 * @widget: a #GtkWidget
6708 * @drawable: a #GdkDrawable
6709 * @area: rectangle to which the output is clipped, or %NULL if the
6710 * output should not be clipped
6711 * @location: location where to draw the cursor (@location->width is ignored)
6712 * @is_primary: if the cursor should be the primary cursor color.
6713 * @direction: whether the cursor is left-to-right or
6714 * right-to-left. Should never be #GTK_TEXT_DIR_NONE
6715 * @draw_arrow: %TRUE to draw a directional arrow on the
6716 * cursor. Should be %FALSE unless the cursor is split.
6718 * Draws a text caret on @drawable at @location. This is not a style function
6719 * but merely a convenience function for drawing the standard cursor shape.
6724 gtk_draw_insertion_cursor (GtkWidget *widget,
6725 GdkDrawable *drawable,
6727 GdkRectangle *location,
6728 gboolean is_primary,
6729 GtkTextDirection direction,
6730 gboolean draw_arrow)
6734 g_return_if_fail (GTK_IS_WIDGET (widget));
6735 g_return_if_fail (GDK_IS_DRAWABLE (drawable));
6736 g_return_if_fail (location != NULL);
6737 g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
6739 gc = get_insertion_cursor_gc (widget, is_primary);
6741 gdk_gc_set_clip_rectangle (gc, area);
6743 draw_insertion_cursor (widget, drawable, gc,
6744 location, direction, draw_arrow);
6747 gdk_gc_set_clip_rectangle (gc, NULL);
6750 #define __GTK_STYLE_C__
6751 #include "gtkaliasdef.c"