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 "gtkspinbutton.h"
34 #include "gtkwidget.h"
35 #include "gtkthemes.h"
36 #include "gtkiconfactory.h"
37 #include "gtksettings.h" /* _gtk_settings_parse_convert() */
39 #define LIGHTNESS_MULT 1.3
40 #define DARKNESS_MULT 0.7
42 /* --- typedefs & structures --- */
50 /* --- prototypes --- */
51 static void gtk_style_init (GtkStyle *style);
52 static void gtk_style_class_init (GtkStyleClass *klass);
53 static void gtk_style_finalize (GObject *object);
54 static void gtk_style_realize (GtkStyle *style,
55 GdkColormap *colormap);
56 static void gtk_style_real_realize (GtkStyle *style);
57 static void gtk_style_real_unrealize (GtkStyle *style);
58 static void gtk_style_real_copy (GtkStyle *style,
60 static void gtk_style_real_set_background (GtkStyle *style,
62 GtkStateType state_type);
63 static GtkStyle *gtk_style_real_clone (GtkStyle *style);
64 static void gtk_style_real_init_from_rc (GtkStyle *style,
65 GtkRcStyle *rc_style);
66 static GdkPixbuf *gtk_default_render_icon (GtkStyle *style,
67 const GtkIconSource *source,
68 GtkTextDirection direction,
73 static void gtk_default_draw_hline (GtkStyle *style,
75 GtkStateType state_type,
82 static void gtk_default_draw_vline (GtkStyle *style,
84 GtkStateType state_type,
91 static void gtk_default_draw_shadow (GtkStyle *style,
93 GtkStateType state_type,
94 GtkShadowType shadow_type,
102 static void gtk_default_draw_polygon (GtkStyle *style,
104 GtkStateType state_type,
105 GtkShadowType shadow_type,
112 static void gtk_default_draw_arrow (GtkStyle *style,
114 GtkStateType state_type,
115 GtkShadowType shadow_type,
119 GtkArrowType arrow_type,
125 static void gtk_default_draw_diamond (GtkStyle *style,
127 GtkStateType state_type,
128 GtkShadowType shadow_type,
136 static void gtk_default_draw_string (GtkStyle *style,
138 GtkStateType state_type,
144 const gchar *string);
145 static void gtk_default_draw_box (GtkStyle *style,
147 GtkStateType state_type,
148 GtkShadowType shadow_type,
156 static void gtk_default_draw_flat_box (GtkStyle *style,
158 GtkStateType state_type,
159 GtkShadowType shadow_type,
167 static void gtk_default_draw_check (GtkStyle *style,
169 GtkStateType state_type,
170 GtkShadowType shadow_type,
178 static void gtk_default_draw_option (GtkStyle *style,
180 GtkStateType state_type,
181 GtkShadowType shadow_type,
189 static void gtk_default_draw_tab (GtkStyle *style,
191 GtkStateType state_type,
192 GtkShadowType shadow_type,
200 static void gtk_default_draw_shadow_gap (GtkStyle *style,
202 GtkStateType state_type,
203 GtkShadowType shadow_type,
211 GtkPositionType gap_side,
214 static void gtk_default_draw_box_gap (GtkStyle *style,
216 GtkStateType state_type,
217 GtkShadowType shadow_type,
225 GtkPositionType gap_side,
228 static void gtk_default_draw_extension (GtkStyle *style,
230 GtkStateType state_type,
231 GtkShadowType shadow_type,
239 GtkPositionType gap_side);
240 static void gtk_default_draw_focus (GtkStyle *style,
242 GtkStateType state_type,
250 static void gtk_default_draw_slider (GtkStyle *style,
252 GtkStateType state_type,
253 GtkShadowType shadow_type,
261 GtkOrientation orientation);
262 static void gtk_default_draw_handle (GtkStyle *style,
264 GtkStateType state_type,
265 GtkShadowType shadow_type,
273 GtkOrientation orientation);
274 static void gtk_default_draw_expander (GtkStyle *style,
276 GtkStateType state_type,
282 GtkExpanderStyle expander_style);
283 static void gtk_default_draw_layout (GtkStyle *style,
285 GtkStateType state_type,
292 PangoLayout *layout);
293 static void gtk_default_draw_resize_grip (GtkStyle *style,
295 GtkStateType state_type,
305 static void gtk_style_shade (GdkColor *a,
308 static void rgb_to_hls (gdouble *r,
311 static void hls_to_rgb (gdouble *h,
317 * Data for default check and radio buttons
320 static GtkRequisition default_option_indicator_size = { 7, 13 };
321 static GtkBorder default_option_indicator_spacing = { 7, 5, 2, 2 };
323 #define INDICATOR_PART_SIZE 13
341 static char check_aa_bits[] = {
342 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x58,0x00,0xa0,
343 0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
344 static char check_base_bits[] = {
345 0x00,0x00,0x00,0x00,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,
346 0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0x00,0x00,0x00,0x00};
347 static char check_black_bits[] = {
348 0x00,0x00,0xfe,0x0f,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
349 0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x00,0x00};
350 static char check_dark_bits[] = {
351 0xff,0x1f,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
352 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00};
353 static char check_light_bits[] = {
354 0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,
355 0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0xfe,0x1f};
356 static char check_mid_bits[] = {
357 0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,
358 0x08,0x00,0x08,0x00,0x08,0x00,0x08,0xfc,0x0f,0x00,0x00};
359 static char check_text_bits[] = {
360 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x03,0x80,0x01,0x80,0x00,0xd8,
361 0x00,0x60,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
362 static char radio_base_bits[] = {
363 0x00,0x00,0x00,0x00,0xf0,0x01,0xf8,0x03,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,
364 0x07,0xfc,0x07,0xf8,0x03,0xf0,0x01,0x00,0x00,0x00,0x00};
365 static char radio_black_bits[] = {
366 0x00,0x00,0xf0,0x01,0x08,0x02,0x04,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
367 0x00,0x02,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
368 static char radio_dark_bits[] = {
369 0xf0,0x01,0x08,0x02,0x04,0x04,0x02,0x04,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
370 0x00,0x01,0x00,0x02,0x00,0x0c,0x00,0x00,0x00,0x00,0x00};
371 static char radio_light_bits[] = {
372 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x10,0x00,0x10,0x00,0x10,0x00,
373 0x10,0x00,0x10,0x00,0x08,0x00,0x04,0x08,0x02,0xf0,0x01};
374 static char radio_mid_bits[] = {
375 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,
376 0x08,0x00,0x08,0x00,0x04,0x00,0x02,0xf0,0x01,0x00,0x00};
377 static char radio_text_bits[] = {
378 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x00,0xf0,0x01,0xf0,0x01,0xf0,
379 0x01,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
384 } indicator_parts[] = {
385 { check_aa_bits, NULL },
386 { check_base_bits, NULL },
387 { check_black_bits, NULL },
388 { check_dark_bits, NULL },
389 { check_light_bits, NULL },
390 { check_mid_bits, NULL },
391 { check_text_bits, NULL },
392 { radio_base_bits, NULL },
393 { radio_black_bits, NULL },
394 { radio_dark_bits, NULL },
395 { radio_light_bits, NULL },
396 { radio_mid_bits, NULL },
397 { radio_text_bits, NULL }
400 /* --- variables --- */
401 static GdkColor gtk_default_normal_fg = { 0, 0, 0, 0 };
402 static GdkColor gtk_default_active_fg = { 0, 0, 0, 0 };
403 static GdkColor gtk_default_prelight_fg = { 0, 0, 0, 0 };
404 static GdkColor gtk_default_selected_fg = { 0, 0xffff, 0xffff, 0xffff };
405 static GdkColor gtk_default_insensitive_fg = { 0, 0x7530, 0x7530, 0x7530 };
407 static GdkColor gtk_default_normal_bg = { 0, 0xd6d6, 0xd6d6, 0xd6d6 };
408 static GdkColor gtk_default_active_bg = { 0, 0xc350, 0xc350, 0xc350 };
409 static GdkColor gtk_default_prelight_bg = { 0, 0xea60, 0xea60, 0xea60 };
410 static GdkColor gtk_default_selected_bg = { 0, 0, 0, 0x9c40 };
411 static GdkColor gtk_default_insensitive_bg = { 0, 0xd6d6, 0xd6d6, 0xd6d6 };
412 static GdkColor gtk_default_selected_base = { 0, 0xa4a4, 0xdfdf, 0xffff };
413 static GdkColor gtk_default_active_base = { 0, 0xbcbc, 0xd2d2, 0xeeee };
415 static gpointer parent_class = NULL;
418 /* --- functions --- */
420 gtk_style_get_type (void)
422 static GType style_type = 0;
426 static const GTypeInfo style_info =
428 sizeof (GtkStyleClass),
429 (GBaseInitFunc) NULL,
430 (GBaseFinalizeFunc) NULL,
431 (GClassInitFunc) gtk_style_class_init,
432 NULL, /* class_finalize */
433 NULL, /* class_data */
436 (GInstanceInitFunc) gtk_style_init,
439 style_type = g_type_register_static (G_TYPE_OBJECT,
448 gtk_style_init (GtkStyle *style)
452 style->font_desc = pango_font_description_from_string ("Sans 10");
454 style->attach_count = 0;
455 style->colormap = NULL;
458 style->black.red = 0;
459 style->black.green = 0;
460 style->black.blue = 0;
462 style->white.red = 65535;
463 style->white.green = 65535;
464 style->white.blue = 65535;
466 style->black_gc = NULL;
467 style->white_gc = NULL;
469 style->fg[GTK_STATE_NORMAL] = gtk_default_normal_fg;
470 style->fg[GTK_STATE_ACTIVE] = gtk_default_active_fg;
471 style->fg[GTK_STATE_PRELIGHT] = gtk_default_prelight_fg;
472 style->fg[GTK_STATE_SELECTED] = gtk_default_selected_fg;
473 style->fg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
475 style->bg[GTK_STATE_NORMAL] = gtk_default_normal_bg;
476 style->bg[GTK_STATE_ACTIVE] = gtk_default_active_bg;
477 style->bg[GTK_STATE_PRELIGHT] = gtk_default_prelight_bg;
478 style->bg[GTK_STATE_SELECTED] = gtk_default_selected_bg;
479 style->bg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_bg;
481 for (i = 0; i < 4; i++)
483 style->text[i] = style->fg[i];
484 style->base[i] = style->white;
487 style->base[GTK_STATE_SELECTED] = gtk_default_selected_base;
488 style->text[GTK_STATE_SELECTED] = style->black;
489 style->base[GTK_STATE_ACTIVE] = gtk_default_active_base;
490 style->text[GTK_STATE_ACTIVE] = style->black;
491 style->base[GTK_STATE_INSENSITIVE] = gtk_default_prelight_bg;
492 style->text[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
494 for (i = 0; i < 5; i++)
495 style->bg_pixmap[i] = NULL;
497 style->rc_style = NULL;
499 for (i = 0; i < 5; i++)
501 style->fg_gc[i] = NULL;
502 style->bg_gc[i] = NULL;
503 style->light_gc[i] = NULL;
504 style->dark_gc[i] = NULL;
505 style->mid_gc[i] = NULL;
506 style->text_gc[i] = NULL;
507 style->base_gc[i] = NULL;
508 style->text_aa_gc[i] = NULL;
511 style->xthickness = 2;
512 style->ythickness = 2;
514 style->property_cache = NULL;
518 gtk_style_class_init (GtkStyleClass *klass)
520 GObjectClass *object_class = G_OBJECT_CLASS (klass);
522 parent_class = g_type_class_peek_parent (klass);
524 object_class->finalize = gtk_style_finalize;
526 klass->clone = gtk_style_real_clone;
527 klass->copy = gtk_style_real_copy;
528 klass->init_from_rc = gtk_style_real_init_from_rc;
529 klass->realize = gtk_style_real_realize;
530 klass->unrealize = gtk_style_real_unrealize;
531 klass->set_background = gtk_style_real_set_background;
532 klass->render_icon = gtk_default_render_icon;
534 klass->draw_hline = gtk_default_draw_hline;
535 klass->draw_vline = gtk_default_draw_vline;
536 klass->draw_shadow = gtk_default_draw_shadow;
537 klass->draw_polygon = gtk_default_draw_polygon;
538 klass->draw_arrow = gtk_default_draw_arrow;
539 klass->draw_diamond = gtk_default_draw_diamond;
540 klass->draw_string = gtk_default_draw_string;
541 klass->draw_box = gtk_default_draw_box;
542 klass->draw_flat_box = gtk_default_draw_flat_box;
543 klass->draw_check = gtk_default_draw_check;
544 klass->draw_option = gtk_default_draw_option;
545 klass->draw_tab = gtk_default_draw_tab;
546 klass->draw_shadow_gap = gtk_default_draw_shadow_gap;
547 klass->draw_box_gap = gtk_default_draw_box_gap;
548 klass->draw_extension = gtk_default_draw_extension;
549 klass->draw_focus = gtk_default_draw_focus;
550 klass->draw_slider = gtk_default_draw_slider;
551 klass->draw_handle = gtk_default_draw_handle;
552 klass->draw_expander = gtk_default_draw_expander;
553 klass->draw_layout = gtk_default_draw_layout;
554 klass->draw_resize_grip = gtk_default_draw_resize_grip;
558 clear_property_cache (GtkStyle *style)
560 if (style->property_cache)
564 for (i = 0; i < style->property_cache->len; i++)
566 PropertyValue *node = &g_array_index (style->property_cache, PropertyValue, i);
568 g_param_spec_unref (node->pspec);
569 g_value_unset (&node->value);
571 g_array_free (style->property_cache, TRUE);
572 style->property_cache = NULL;
577 gtk_style_finalize (GObject *object)
579 GtkStyle *style = GTK_STYLE (object);
581 g_return_if_fail (style->attach_count == 0);
583 clear_property_cache (style);
587 if (style->styles->data != style)
588 g_slist_remove (style->styles, style);
591 GSList *tmp_list = style->styles->next;
595 GTK_STYLE (tmp_list->data)->styles = style->styles->next;
596 tmp_list = tmp_list->next;
598 g_slist_free_1 (style->styles);
602 pango_font_description_free (style->font_desc);
604 if (style->private_font)
605 gdk_font_unref (style->private_font);
607 if (style->private_font_desc)
608 pango_font_description_free (style->private_font_desc);
611 gtk_rc_style_unref (style->rc_style);
613 G_OBJECT_CLASS (parent_class)->finalize (object);
618 gtk_style_copy (GtkStyle *style)
622 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
624 new_style = GTK_STYLE_GET_CLASS (style)->clone (style);
625 GTK_STYLE_GET_CLASS (style)->copy (new_style, style);
631 gtk_style_duplicate (GtkStyle *style)
635 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
637 new_style = gtk_style_copy (style);
639 style->styles = g_slist_append (style->styles, new_style);
640 new_style->styles = style->styles;
647 * @returns: a new #GtkStyle.
649 * Creates a new #GtkStyle.
656 style = g_object_new (GTK_TYPE_STYLE, NULL);
663 * @style: a #GtkStyle.
664 * @window: a #GtkWindow.
665 * @returns: Either @style, or a newly-created #GtkStyle.
666 * If the style is newly created, the style parameter
667 * will be dereferenced, and the new style will have
668 * a reference count belonging to the caller.
670 * Attaches a style to a window; this process allocates the
671 * colors and creates the GC's for the style - it specializes
672 * it to a particular visual and colormap. The process may
673 * involve the creation of a new style if the style has already
674 * been attached to a window with a different style and colormap.
677 * FIXME: The sequence -
678 * create a style => s1
679 * attach s1 to v1, c1 => s1
680 * attach s1 to v2, c2 => s2
681 * detach s1 from v1, c1
682 * attach s1 to v2, c2 => s3
683 * results in two separate, unlinked styles s2 and s3 which
684 * are identical and could be shared. To fix this, we would
685 * want to never remove a style from the list of linked
686 * styles as long as as it has a reference count. However, the
687 * disadvantage of doing it this way means that we would need two
688 * passes through the linked list when attaching (one to check for
689 * matching styles, one to look for empty unattached styles - but
690 * it will almost never be longer than 2 elements.
693 gtk_style_attach (GtkStyle *style,
697 GtkStyle *new_style = NULL;
698 GdkColormap *colormap;
700 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
701 g_return_val_if_fail (window != NULL, NULL);
703 colormap = gdk_window_get_colormap (window);
706 style->styles = g_slist_append (NULL, style);
708 styles = style->styles;
711 new_style = styles->data;
713 if (new_style->attach_count == 0)
715 gtk_style_realize (new_style, colormap);
718 else if (new_style->colormap == colormap)
722 styles = styles->next;
727 new_style = gtk_style_duplicate (style);
728 gtk_style_realize (new_style, colormap);
731 /* A style gets a refcount from being attached */
732 if (new_style->attach_count == 0)
733 g_object_ref (new_style);
735 /* Another refcount belongs to the parent */
736 if (style != new_style)
738 g_object_unref (style);
739 g_object_ref (new_style);
742 new_style->attach_count++;
748 gtk_style_detach (GtkStyle *style)
750 g_return_if_fail (GTK_IS_STYLE (style));
752 style->attach_count -= 1;
753 if (style->attach_count == 0)
755 GTK_STYLE_GET_CLASS (style)->unrealize (style);
757 gdk_colormap_unref (style->colormap);
758 style->colormap = NULL;
760 g_object_unref (style);
766 * @style: a #GtkStyle.
769 * Deprecated equivalent of g_object_ref().
772 gtk_style_ref (GtkStyle *style)
774 return (GtkStyle *) g_object_ref (G_OBJECT (style));
779 * @style: a #GtkStyle.
781 * Deprecated equivalent of g_object_unref().
784 gtk_style_unref (GtkStyle *style)
786 g_object_unref (G_OBJECT (style));
790 gtk_style_realize (GtkStyle *style,
791 GdkColormap *colormap)
793 g_return_if_fail (GTK_IS_STYLE (style));
794 g_return_if_fail (GDK_IS_COLORMAP (colormap));
796 style->colormap = gdk_colormap_ref (colormap);
797 style->depth = gdk_colormap_get_visual (colormap)->depth;
799 GTK_STYLE_GET_CLASS (style)->realize (style);
803 gtk_style_lookup_icon_set (GtkStyle *style,
804 const char *stock_id)
808 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
809 g_return_val_if_fail (stock_id != NULL, NULL);
811 iter = style->icon_factories;
814 GtkIconSet *icon_set = gtk_icon_factory_lookup (GTK_ICON_FACTORY (iter->data),
819 iter = g_slist_next (iter);
822 return gtk_icon_factory_lookup_default (stock_id);
827 * @style: a #GtkStyle
828 * @window: a #GdkWindow
829 * @state_type: a state
830 * @x1: the starting x coordinate
831 * @x2: the ending x coordinate
832 * @y: the y coordinate
834 * Draws a horizontal line from (@x1, @y) to (@x2, @y) in @window
835 * using the given style and state.
837 * This function is deprecated, use gtk_paint_hline() instead.
840 gtk_draw_hline (GtkStyle *style,
842 GtkStateType state_type,
847 g_return_if_fail (GTK_IS_STYLE (style));
848 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
850 GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, NULL, NULL, NULL, x1, x2, y);
856 * @style: a #GtkStyle
857 * @window: a #GdkWindow
858 * @state_type: a state
859 * @y1: the starting y coordinate
860 * @y2: the ending y coordinate
861 * @x: the x coordinate
863 * Draws a vertical line from (@x, @y1) to (@x, @y2) in @window
864 * using the given style and state.
866 * This function is deprecated, use gtk_paint_vline() instead.
869 gtk_draw_vline (GtkStyle *style,
871 GtkStateType state_type,
876 g_return_if_fail (GTK_IS_STYLE (style));
877 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
879 GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, NULL, NULL, NULL, y1, y2, x);
884 * @style: a #GtkStyle
885 * @window: a #GdkWindow
886 * @state_type: a state
887 * @shadow_type: type of shadow to draw
888 * @x: x origin of the rectangle
889 * @y: y origin of the rectangle
890 * @width: width of the rectangle
891 * @height: width of the rectangle
893 * Draws a shadow around the given rectangle in @window
894 * using the given style and state and shadow type.
896 * This function is deprecated, use gtk_paint_shadow() instead.
899 gtk_draw_shadow (GtkStyle *style,
901 GtkStateType state_type,
902 GtkShadowType shadow_type,
908 g_return_if_fail (GTK_IS_STYLE (style));
909 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
911 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
916 * @style: a #GtkStyle
917 * @window: a #GdkWindow
918 * @state_type: a state
919 * @shadow_type: type of shadow to draw
920 * @points: an array of #GdkPoint<!>s
921 * @npoints: length of @points
922 * @fill: %TRUE if the polygon should be filled
924 * Draws a polygon on @window with the given parameters.
926 * This function is deprecated, use gtk_paint_polygon() instead.
929 gtk_draw_polygon (GtkStyle *style,
931 GtkStateType state_type,
932 GtkShadowType shadow_type,
937 g_return_if_fail (GTK_IS_STYLE (style));
938 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_polygon != NULL);
940 GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, NULL, NULL, NULL, points, npoints, fill);
945 * @style: a #GtkStyle
946 * @window: a #GdkWindow
947 * @state_type: a state
948 * @shadow_type: the type of shadow to draw
949 * @arrow_type: the type of arrow to draw
950 * @fill: %TRUE if the arrow tip should be filled
951 * @x: x origin of the rectangle to draw the arrow in
952 * @y: y origin of the rectangle to draw the arrow in
953 * @width: width of the rectangle to draw the arrow in
954 * @height: height of the rectangle to draw the arrow in
956 * Draws an arrow in the given rectangle on @window using the given
957 * parameters. @arrow_type determines the direction of the arrow.
959 * This function is deprecated, use gtk_paint_arrow() instead.
962 gtk_draw_arrow (GtkStyle *style,
964 GtkStateType state_type,
965 GtkShadowType shadow_type,
966 GtkArrowType arrow_type,
973 g_return_if_fail (GTK_IS_STYLE (style));
974 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
976 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, NULL, NULL, NULL, arrow_type, fill, x, y, width, height);
981 * @style: a #GtkStyle
982 * @window: a #GdkWindow
983 * @state_type: a state
984 * @shadow_type: the type of shadow to draw
985 * @x: x origin of the rectangle to draw the diamond in
986 * @y: y origin of the rectangle to draw the diamond in
987 * @width: width of the rectangle to draw the diamond in
988 * @height: height of the rectangle to draw the diamond in
990 * Draws a diamond in the given rectangle on @window using the given parameters.
992 * This function is deprecated, use gtk_paint_diamond() instead.
995 gtk_draw_diamond (GtkStyle *style,
997 GtkStateType state_type,
998 GtkShadowType shadow_type,
1004 g_return_if_fail (GTK_IS_STYLE (style));
1005 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
1007 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1012 * @style: a #GtkStyle
1013 * @window: a #GdkWindow
1014 * @state_type: a state
1017 * @string: the string to draw
1019 * Draws a text string on @window with the given parameters.
1021 * This function is deprecated, use gtk_paint_layout() instead.
1024 gtk_draw_string (GtkStyle *style,
1026 GtkStateType state_type,
1029 const gchar *string)
1031 g_return_if_fail (GTK_IS_STYLE (style));
1032 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
1034 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, NULL, NULL, NULL, x, y, string);
1039 * @style: a #GtkStyle
1040 * @window: a #GdkWindow
1041 * @state_type: a state
1042 * @shadow_type: the type of shadow to draw
1043 * @x: x origin of the box
1044 * @y: y origin of the box
1045 * @width: the width of the box
1046 * @height: the height of the box
1048 * Draws a box on @window with the given parameters.
1050 * This function is deprecated, use gtk_paint_box() instead.
1053 gtk_draw_box (GtkStyle *style,
1055 GtkStateType state_type,
1056 GtkShadowType shadow_type,
1062 g_return_if_fail (GTK_IS_STYLE (style));
1063 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
1065 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1069 * gtk_draw_flat_box:
1070 * @style: a #GtkStyle
1071 * @window: a #GdkWindow
1072 * @state_type: a state
1073 * @shadow_type: the type of shadow to draw
1074 * @x: x origin of the box
1075 * @y: y origin of the box
1076 * @width: the width of the box
1077 * @height: the height of the box
1079 * Draws a flat box on @window with the given parameters.
1081 * This function is deprecated, use gtk_paint_flat_box() instead.
1084 gtk_draw_flat_box (GtkStyle *style,
1086 GtkStateType state_type,
1087 GtkShadowType shadow_type,
1093 g_return_if_fail (GTK_IS_STYLE (style));
1094 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
1096 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1101 * @style: a #GtkStyle
1102 * @window: a #GdkWindow
1103 * @state_type: a state
1104 * @shadow_type: the type of shadow to draw
1105 * @x: x origin of the rectangle to draw the check in
1106 * @y: y origin of the rectangle to draw the check in
1107 * @width: the width of the rectangle to draw the check in
1108 * @height: the height of the rectangle to draw the check in
1110 * Draws a check button indicator in the given rectangle on @window with
1111 * the given parameters.
1113 * This function is deprecated, use gtk_paint_check() instead.
1116 gtk_draw_check (GtkStyle *style,
1118 GtkStateType state_type,
1119 GtkShadowType shadow_type,
1125 g_return_if_fail (GTK_IS_STYLE (style));
1126 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
1128 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1133 * @style: a #GtkStyle
1134 * @window: a #GdkWindow
1135 * @state_type: a state
1136 * @shadow_type: the type of shadow to draw
1137 * @x: x origin of the rectangle to draw the option in
1138 * @y: y origin of the rectangle to draw the option in
1139 * @width: the width of the rectangle to draw the option in
1140 * @height: the height of the rectangle to draw the option in
1142 * Draws a radio button indicator in the given rectangle on @window with
1143 * the given parameters.
1145 * This function is deprecated, use gtk_paint_option() instead.
1148 gtk_draw_option (GtkStyle *style,
1150 GtkStateType state_type,
1151 GtkShadowType shadow_type,
1157 g_return_if_fail (GTK_IS_STYLE (style));
1158 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
1160 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1165 * @style: a #GtkStyle
1166 * @window: a #GdkWindow
1167 * @state_type: a state
1168 * @shadow_type: the type of shadow to draw
1169 * @x: x origin of the rectangle to draw the tab in
1170 * @y: y origin of the rectangle to draw the tab in
1171 * @width: the width of the rectangle to draw the tab in
1172 * @height: the height of the rectangle to draw the tab in
1174 * Draws an option menu tab (i.e. the up and down pointing arrows)
1175 * in the given rectangle on @window using the given parameters.
1177 * This function is deprecated, use gtk_paint_tab() instead.
1180 gtk_draw_tab (GtkStyle *style,
1182 GtkStateType state_type,
1183 GtkShadowType shadow_type,
1189 g_return_if_fail (GTK_IS_STYLE (style));
1190 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
1192 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1196 gtk_draw_shadow_gap (GtkStyle *style,
1198 GtkStateType state_type,
1199 GtkShadowType shadow_type,
1204 GtkPositionType gap_side,
1208 g_return_if_fail (GTK_IS_STYLE (style));
1209 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
1211 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);
1215 gtk_draw_box_gap (GtkStyle *style,
1217 GtkStateType state_type,
1218 GtkShadowType shadow_type,
1223 GtkPositionType gap_side,
1227 g_return_if_fail (GTK_IS_STYLE (style));
1228 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
1230 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);
1234 gtk_draw_extension (GtkStyle *style,
1236 GtkStateType state_type,
1237 GtkShadowType shadow_type,
1242 GtkPositionType gap_side)
1244 g_return_if_fail (GTK_IS_STYLE (style));
1245 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
1247 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, gap_side);
1252 * @style: a #GtkStyle
1253 * @window: a #GdkWindow
1254 * @x: the x origin of the rectangle around which to draw a focus indicator
1255 * @y: the y origin of the rectangle around which to draw a focus indicator
1256 * @width: the width of the rectangle around which to draw a focus indicator
1257 * @height: the height of the rectangle around which to draw a focus indicator
1259 * Draws a focus indicator around the given rectangle on @window using the
1262 * This function is deprecated, use gtk_paint_focus() instead.
1265 gtk_draw_focus (GtkStyle *style,
1272 g_return_if_fail (GTK_IS_STYLE (style));
1273 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
1275 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, GTK_STATE_NORMAL, NULL, NULL, NULL, x, y, width, height);
1279 gtk_draw_slider (GtkStyle *style,
1281 GtkStateType state_type,
1282 GtkShadowType shadow_type,
1287 GtkOrientation orientation)
1289 g_return_if_fail (GTK_IS_STYLE (style));
1290 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
1292 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
1296 gtk_draw_handle (GtkStyle *style,
1298 GtkStateType state_type,
1299 GtkShadowType shadow_type,
1304 GtkOrientation orientation)
1306 g_return_if_fail (GTK_IS_STYLE (style));
1307 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
1309 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
1313 gtk_draw_expander (GtkStyle *style,
1315 GtkStateType state_type,
1318 GtkExpanderStyle expander_style)
1320 g_return_if_fail (GTK_IS_STYLE (style));
1321 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
1323 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type,
1325 x, y, expander_style);
1329 gtk_draw_layout (GtkStyle *style,
1331 GtkStateType state_type,
1335 PangoLayout *layout)
1337 g_return_if_fail (GTK_IS_STYLE (style));
1338 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
1340 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, use_text,
1346 * gtk_draw_resize_grip:
1347 * @style: a #GtkStyle
1348 * @window: a #GdkWindow
1349 * @state_type: a state
1350 * @edge: the edge in which to draw the resize grip, currently only
1351 * %GTK_WINDOW_EDGE_SOUTH_EAST is implemented
1352 * @x: the x origin of the rectangle in which to draw the resize grip
1353 * @y: the y origin of the rectangle in which to draw the resize grip
1354 * @width: the width of the rectangle in which to draw the resize grip
1355 * @height: the height of the rectangle in which to draw the resize grip
1357 * Draws a resize grip in the given rectangle on @window using the given
1360 * This function is deprecated, use gtk_paint_resize_grip() instead.
1363 gtk_draw_resize_grip (GtkStyle *style,
1365 GtkStateType state_type,
1372 g_return_if_fail (GTK_IS_STYLE (style));
1373 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
1375 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, window, state_type,
1378 x, y, width, height);
1383 * gtk_style_set_background:
1384 * @style: a #GtkStyle
1385 * @window: a #GdkWindow
1386 * @state_type: a state
1388 * Sets the background of @window to the background color or pixmap
1389 * specified by @style for the given state.
1392 gtk_style_set_background (GtkStyle *style,
1394 GtkStateType state_type)
1396 g_return_if_fail (GTK_IS_STYLE (style));
1397 g_return_if_fail (window != NULL);
1399 GTK_STYLE_GET_CLASS (style)->set_background (style, window, state_type);
1402 /* Default functions */
1404 gtk_style_real_clone (GtkStyle *style)
1406 return GTK_STYLE (g_object_new (G_OBJECT_TYPE (style), NULL));
1410 gtk_style_real_copy (GtkStyle *style,
1415 for (i = 0; i < 5; i++)
1417 style->fg[i] = src->fg[i];
1418 style->bg[i] = src->bg[i];
1419 style->text[i] = src->text[i];
1420 style->base[i] = src->base[i];
1422 style->bg_pixmap[i] = src->bg_pixmap[i];
1425 if (style->private_font)
1426 gdk_font_unref (style->private_font);
1427 style->private_font = src->private_font;
1428 if (style->private_font)
1429 gdk_font_ref (style->private_font);
1431 if (style->font_desc)
1432 pango_font_description_free (style->font_desc);
1434 style->font_desc = pango_font_description_copy (src->font_desc);
1436 style->font_desc = NULL;
1438 style->xthickness = src->xthickness;
1439 style->ythickness = src->ythickness;
1441 if (style->rc_style)
1442 gtk_rc_style_unref (style->rc_style);
1443 style->rc_style = src->rc_style;
1445 gtk_rc_style_ref (src->rc_style);
1447 /* don't copy, just clear cache */
1448 clear_property_cache (style);
1452 gtk_style_real_init_from_rc (GtkStyle *style,
1453 GtkRcStyle *rc_style)
1457 /* cache _should_ be still empty */
1458 clear_property_cache (style);
1460 if (rc_style->font_desc)
1461 pango_font_description_merge (style->font_desc, rc_style->font_desc, TRUE);
1463 for (i = 0; i < 5; i++)
1465 if (rc_style->color_flags[i] & GTK_RC_FG)
1466 style->fg[i] = rc_style->fg[i];
1467 if (rc_style->color_flags[i] & GTK_RC_BG)
1468 style->bg[i] = rc_style->bg[i];
1469 if (rc_style->color_flags[i] & GTK_RC_TEXT)
1470 style->text[i] = rc_style->text[i];
1471 if (rc_style->color_flags[i] & GTK_RC_BASE)
1472 style->base[i] = rc_style->base[i];
1475 if (rc_style->xthickness >= 0)
1476 style->xthickness = rc_style->xthickness;
1477 if (rc_style->ythickness >= 0)
1478 style->ythickness = rc_style->ythickness;
1480 if (rc_style->icon_factories)
1484 style->icon_factories = g_slist_copy (rc_style->icon_factories);
1486 iter = style->icon_factories;
1487 while (iter != NULL)
1489 g_object_ref (G_OBJECT (iter->data));
1491 iter = g_slist_next (iter);
1497 style_property_values_cmp (gconstpointer bsearch_node1,
1498 gconstpointer bsearch_node2)
1500 const PropertyValue *val1 = bsearch_node1;
1501 const PropertyValue *val2 = bsearch_node2;
1503 if (val1->widget_type == val2->widget_type)
1504 return val1->pspec < val2->pspec ? -1 : val1->pspec == val2->pspec ? 0 : 1;
1506 return val1->widget_type < val2->widget_type ? -1 : 1;
1510 _gtk_style_peek_property_value (GtkStyle *style,
1513 GtkRcPropertyParser parser)
1515 PropertyValue *pcache, key = { 0, NULL, { 0, } };
1516 const GtkRcProperty *rcprop = NULL;
1519 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1520 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), NULL);
1521 g_return_val_if_fail (g_type_is_a (pspec->owner_type, GTK_TYPE_WIDGET), NULL);
1522 g_return_val_if_fail (g_type_is_a (widget_type, pspec->owner_type), NULL);
1524 key.widget_type = widget_type;
1527 /* need value cache array */
1528 if (!style->property_cache)
1529 style->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
1532 pcache = bsearch (&key,
1533 style->property_cache->data, style->property_cache->len,
1534 sizeof (PropertyValue), style_property_values_cmp);
1536 return &pcache->value;
1540 while (i < style->property_cache->len &&
1541 style_property_values_cmp (&key, &g_array_index (style->property_cache, PropertyValue, i)) >= 0)
1544 g_array_insert_val (style->property_cache, i, key);
1545 pcache = &g_array_index (style->property_cache, PropertyValue, i);
1547 /* cache miss, initialize value type, then set contents */
1548 g_param_spec_ref (pcache->pspec);
1549 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1551 /* value provided by rc style? */
1552 if (style->rc_style)
1554 GQuark prop_quark = g_quark_from_string (pspec->name);
1558 rcprop = _gtk_rc_style_lookup_rc_property (style->rc_style,
1559 g_type_qname (widget_type),
1563 widget_type = g_type_parent (widget_type);
1565 while (g_type_is_a (widget_type, pspec->owner_type));
1568 /* when supplied by rc style, we need to convert */
1569 if (rcprop && !_gtk_settings_parse_convert (parser, &rcprop->value,
1570 pspec, &pcache->value))
1572 gchar *contents = g_strdup_value_contents (&rcprop->value);
1574 g_message ("%s: failed to retrieve property `%s::%s' of type `%s' from rc file value \"%s\" of type `%s'",
1576 g_type_name (pspec->owner_type), pspec->name,
1577 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1579 G_VALUE_TYPE_NAME (&rcprop->value));
1581 rcprop = NULL; /* needs default */
1584 /* not supplied by rc style (or conversion failed), revert to default */
1586 g_param_value_set_default (pspec, &pcache->value);
1588 return &pcache->value;
1592 load_bg_image (GdkColormap *colormap,
1594 const gchar *filename)
1596 if (strcmp (filename, "<parent>") == 0)
1597 return (GdkPixmap*) GDK_PARENT_RELATIVE;
1600 return gdk_pixmap_colormap_create_from_xpm (NULL, colormap, NULL,
1607 gtk_style_real_realize (GtkStyle *style)
1609 GdkGCValues gc_values;
1610 GdkGCValuesMask gc_values_mask;
1614 for (i = 0; i < 5; i++)
1616 gtk_style_shade (&style->bg[i], &style->light[i], LIGHTNESS_MULT);
1617 gtk_style_shade (&style->bg[i], &style->dark[i], DARKNESS_MULT);
1619 style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
1620 style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
1621 style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
1623 style->text_aa[i].red = (style->text[i].red + style->base[i].red) / 2;
1624 style->text_aa[i].green = (style->text[i].green + style->base[i].green) / 2;
1625 style->text_aa[i].blue = (style->text[i].blue + style->base[i].blue) / 2;
1628 gdk_color_black (style->colormap, &style->black);
1629 gdk_color_white (style->colormap, &style->white);
1631 gc_values_mask = GDK_GC_FOREGROUND;
1633 gc_values.foreground = style->black;
1634 style->black_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1636 gc_values.foreground = style->white;
1637 style->white_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1639 for (i = 0; i < 5; i++)
1641 if (style->rc_style && style->rc_style->bg_pixmap_name[i])
1642 style->bg_pixmap[i] = load_bg_image (style->colormap,
1644 style->rc_style->bg_pixmap_name[i]);
1646 if (!gdk_color_alloc (style->colormap, &style->fg[i]))
1647 g_warning ("unable to allocate color: ( %d %d %d )",
1648 style->fg[i].red, style->fg[i].green, style->fg[i].blue);
1649 if (!gdk_color_alloc (style->colormap, &style->bg[i]))
1650 g_warning ("unable to allocate color: ( %d %d %d )",
1651 style->bg[i].red, style->bg[i].green, style->bg[i].blue);
1652 if (!gdk_color_alloc (style->colormap, &style->light[i]))
1653 g_warning ("unable to allocate color: ( %d %d %d )",
1654 style->light[i].red, style->light[i].green, style->light[i].blue);
1655 if (!gdk_color_alloc (style->colormap, &style->dark[i]))
1656 g_warning ("unable to allocate color: ( %d %d %d )",
1657 style->dark[i].red, style->dark[i].green, style->dark[i].blue);
1658 if (!gdk_color_alloc (style->colormap, &style->mid[i]))
1659 g_warning ("unable to allocate color: ( %d %d %d )",
1660 style->mid[i].red, style->mid[i].green, style->mid[i].blue);
1661 if (!gdk_color_alloc (style->colormap, &style->text[i]))
1662 g_warning ("unable to allocate color: ( %d %d %d )",
1663 style->text[i].red, style->text[i].green, style->text[i].blue);
1664 if (!gdk_color_alloc (style->colormap, &style->base[i]))
1665 g_warning ("unable to allocate color: ( %d %d %d )",
1666 style->base[i].red, style->base[i].green, style->base[i].blue);
1667 if (!gdk_color_alloc (style->colormap, &style->text_aa[i]))
1668 g_warning ("unable to allocate color: ( %d %d %d )",
1669 style->text_aa[i].red, style->text_aa[i].green, style->text_aa[i].blue);
1671 gc_values.foreground = style->fg[i];
1672 style->fg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1674 gc_values.foreground = style->bg[i];
1675 style->bg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1677 gc_values.foreground = style->light[i];
1678 style->light_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1680 gc_values.foreground = style->dark[i];
1681 style->dark_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1683 gc_values.foreground = style->mid[i];
1684 style->mid_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1686 gc_values.foreground = style->text[i];
1687 style->text_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1689 gc_values.foreground = style->base[i];
1690 style->base_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1692 gc_values.foreground = style->text_aa[i];
1693 style->text_aa_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1698 gtk_style_real_unrealize (GtkStyle *style)
1702 gtk_gc_release (style->black_gc);
1703 gtk_gc_release (style->white_gc);
1705 for (i = 0; i < 5; i++)
1707 gtk_gc_release (style->fg_gc[i]);
1708 gtk_gc_release (style->bg_gc[i]);
1709 gtk_gc_release (style->light_gc[i]);
1710 gtk_gc_release (style->dark_gc[i]);
1711 gtk_gc_release (style->mid_gc[i]);
1712 gtk_gc_release (style->text_gc[i]);
1713 gtk_gc_release (style->base_gc[i]);
1714 gtk_gc_release (style->text_aa_gc[i]);
1716 if (style->bg_pixmap[i] && style->bg_pixmap[i] != (GdkPixmap*) GDK_PARENT_RELATIVE)
1717 gdk_pixmap_unref (style->bg_pixmap[i]);
1720 gdk_colormap_free_colors (style->colormap, style->fg, 5);
1721 gdk_colormap_free_colors (style->colormap, style->bg, 5);
1722 gdk_colormap_free_colors (style->colormap, style->light, 5);
1723 gdk_colormap_free_colors (style->colormap, style->dark, 5);
1724 gdk_colormap_free_colors (style->colormap, style->mid, 5);
1725 gdk_colormap_free_colors (style->colormap, style->text, 5);
1726 gdk_colormap_free_colors (style->colormap, style->base, 5);
1727 gdk_colormap_free_colors (style->colormap, style->text_aa, 5);
1731 gtk_style_real_set_background (GtkStyle *style,
1733 GtkStateType state_type)
1736 gint parent_relative;
1738 if (style->bg_pixmap[state_type])
1740 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1743 parent_relative = TRUE;
1747 pixmap = style->bg_pixmap[state_type];
1748 parent_relative = FALSE;
1751 gdk_window_set_back_pixmap (window, pixmap, parent_relative);
1754 gdk_window_set_background (window, &style->bg[state_type]);
1758 * gtk_style_render_icon:
1759 * @style: a #GtkStyle
1760 * @source: the #GtkIconSource specifying the icon to render
1761 * @direction: a text direction
1763 * @size: the size to render the icon at. A size of (GtkIconSize)-1
1764 * means render at the size of the source and don't scale.
1765 * @widget: the widget
1766 * @detail: a style detail
1767 * @returns: a newly-created #GdkPixbuf containing the rendered icon
1769 * Renders the icon specified by @source at the given @size
1770 * according to the given parameters and returns the result in a
1774 gtk_style_render_icon (GtkStyle *style,
1775 const GtkIconSource *source,
1776 GtkTextDirection direction,
1780 const gchar *detail)
1784 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1785 g_return_val_if_fail (GTK_STYLE_GET_CLASS (style)->render_icon != NULL, NULL);
1787 pixbuf = GTK_STYLE_GET_CLASS (style)->render_icon (style, source, direction, state,
1788 size, widget, detail);
1790 g_return_val_if_fail (pixbuf != NULL, NULL);
1795 /* Default functions */
1797 gtk_style_apply_default_background (GtkStyle *style,
1800 GtkStateType state_type,
1807 GdkRectangle new_rect, old_rect;
1813 old_rect.width = width;
1814 old_rect.height = height;
1816 if (!gdk_rectangle_intersect (area, &old_rect, &new_rect))
1823 new_rect.width = width;
1824 new_rect.height = height;
1827 if (!style->bg_pixmap[state_type] ||
1828 GDK_IS_PIXMAP (window) ||
1829 (!set_bg && style->bg_pixmap[state_type] != (GdkPixmap*) GDK_PARENT_RELATIVE))
1831 GdkGC *gc = style->bg_gc[state_type];
1833 if (style->bg_pixmap[state_type])
1835 gdk_gc_set_fill (gc, GDK_TILED);
1836 gdk_gc_set_tile (gc, style->bg_pixmap[state_type]);
1839 gdk_draw_rectangle (window, gc, TRUE,
1840 new_rect.x, new_rect.y, new_rect.width, new_rect.height);
1841 if (style->bg_pixmap[state_type])
1842 gdk_gc_set_fill (gc, GDK_SOLID);
1848 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1849 gdk_window_set_back_pixmap (window, NULL, TRUE);
1851 gdk_window_set_back_pixmap (window, style->bg_pixmap[state_type], FALSE);
1854 gdk_window_clear_area (window,
1855 new_rect.x, new_rect.y,
1856 new_rect.width, new_rect.height);
1861 scale_or_ref (GdkPixbuf *src,
1865 if (width == gdk_pixbuf_get_width (src) &&
1866 height == gdk_pixbuf_get_height (src))
1868 gdk_pixbuf_ref (src);
1873 return gdk_pixbuf_scale_simple (src,
1875 GDK_INTERP_BILINEAR);
1880 gtk_default_render_icon (GtkStyle *style,
1881 const GtkIconSource *source,
1882 GtkTextDirection direction,
1886 const gchar *detail)
1892 GdkPixbuf *base_pixbuf;
1894 /* Oddly, style can be NULL in this function, because
1895 * GtkIconSet can be used without a style and if so
1896 * it uses this function.
1899 base_pixbuf = gtk_icon_source_get_pixbuf (source);
1901 g_return_val_if_fail (base_pixbuf != NULL, NULL);
1903 if (size != (GtkIconSize) -1 && !gtk_icon_size_lookup (size, &width, &height))
1905 g_warning (G_STRLOC ": invalid icon size `%d'", size);
1909 /* If the size was wildcarded, and we're allowed to scale, then scale; otherwise,
1912 if (size != (GtkIconSize)-1 && gtk_icon_source_get_size_wildcarded (source))
1913 scaled = scale_or_ref (base_pixbuf, width, height);
1915 scaled = GDK_PIXBUF (g_object_ref (G_OBJECT (base_pixbuf)));
1917 /* If the state was wildcarded, then generate a state. */
1918 if (gtk_icon_source_get_state_wildcarded (source))
1920 if (state == GTK_STATE_INSENSITIVE)
1922 stated = gdk_pixbuf_copy (scaled);
1924 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
1927 gdk_pixbuf_unref (scaled);
1929 else if (state == GTK_STATE_PRELIGHT)
1931 stated = gdk_pixbuf_copy (scaled);
1933 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
1936 gdk_pixbuf_unref (scaled);
1950 sanitize_size (GdkWindow *window,
1954 if ((*width == -1) && (*height == -1))
1955 gdk_window_get_size (window, width, height);
1956 else if (*width == -1)
1957 gdk_window_get_size (window, width, NULL);
1958 else if (*height == -1)
1959 gdk_window_get_size (window, NULL, height);
1963 draw_part (GdkDrawable *drawable,
1971 gdk_gc_set_clip_rectangle (gc, area);
1973 if (!indicator_parts[part].bmap)
1974 indicator_parts[part].bmap = gdk_bitmap_create_from_data (drawable,
1975 indicator_parts[part].bits,
1976 INDICATOR_PART_SIZE, INDICATOR_PART_SIZE);
1978 gdk_gc_set_ts_origin (gc, x, y);
1979 gdk_gc_set_stipple (gc, indicator_parts[part].bmap);
1980 gdk_gc_set_fill (gc, GDK_STIPPLED);
1982 gdk_draw_rectangle (drawable, gc, TRUE, x, y, INDICATOR_PART_SIZE, INDICATOR_PART_SIZE);
1984 gdk_gc_set_fill (gc, GDK_SOLID);
1987 gdk_gc_set_clip_rectangle (gc, NULL);
1991 gtk_default_draw_hline (GtkStyle *style,
1993 GtkStateType state_type,
1996 const gchar *detail,
2001 gint thickness_light;
2002 gint thickness_dark;
2005 g_return_if_fail (GTK_IS_STYLE (style));
2006 g_return_if_fail (window != NULL);
2008 thickness_light = style->ythickness / 2;
2009 thickness_dark = style->ythickness - thickness_light;
2013 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
2014 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
2017 if (detail && !strcmp (detail, "label"))
2019 if (state_type == GTK_STATE_INSENSITIVE)
2020 gdk_draw_line (window, style->white_gc, x1 + 1, y + 1, x2 + 1, y + 1);
2021 gdk_draw_line (window, style->fg_gc[state_type], x1, y, x2, y);
2025 for (i = 0; i < thickness_dark; i++)
2027 gdk_draw_line (window, style->light_gc[state_type], x2 - i - 1, y + i, x2, y + i);
2028 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x2 - i - 1, y + i);
2031 y += thickness_dark;
2032 for (i = 0; i < thickness_light; i++)
2034 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x1 + thickness_light - i - 1, y + i);
2035 gdk_draw_line (window, style->light_gc[state_type], x1 + thickness_light - i - 1, y + i, x2, y + i);
2041 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
2042 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
2048 gtk_default_draw_vline (GtkStyle *style,
2050 GtkStateType state_type,
2053 const gchar *detail,
2058 gint thickness_light;
2059 gint thickness_dark;
2062 g_return_if_fail (GTK_IS_STYLE (style));
2063 g_return_if_fail (window != NULL);
2065 thickness_light = style->xthickness / 2;
2066 thickness_dark = style->xthickness - thickness_light;
2070 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
2071 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
2073 for (i = 0; i < thickness_dark; i++)
2075 gdk_draw_line (window, style->light_gc[state_type], x + i, y2 - i - 1, x + i, y2);
2076 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y2 - i - 1);
2079 x += thickness_dark;
2080 for (i = 0; i < thickness_light; i++)
2082 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y1 + thickness_light - i);
2083 gdk_draw_line (window, style->light_gc[state_type], x + i, y1 + thickness_light - i, x + i, y2);
2087 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
2088 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
2094 draw_thin_shadow (GtkStyle *style,
2105 sanitize_size (window, &width, &height);
2107 gc1 = style->light_gc[state];
2108 gc2 = style->dark_gc[state];
2112 gdk_gc_set_clip_rectangle (gc1, area);
2113 gdk_gc_set_clip_rectangle (gc2, area);
2116 gdk_draw_line (window, gc1,
2117 x, y + height - 1, x + width - 1, y + height - 1);
2118 gdk_draw_line (window, gc1,
2119 x + width - 1, y, x + width - 1, y + height - 1);
2121 gdk_draw_line (window, gc2,
2122 x, y, x + width - 1, y);
2123 gdk_draw_line (window, gc2,
2124 x, y, x, y + height - 1);
2128 gdk_gc_set_clip_rectangle (gc1, NULL);
2129 gdk_gc_set_clip_rectangle (gc2, NULL);
2134 draw_spin_entry_shadow (GtkStyle *style,
2143 gint window_width, window_height;
2144 gboolean focus_inset;
2146 gdk_window_get_size (window, &window_width, &window_height);
2149 width = window_width;
2151 height = window_height;
2153 focus_inset = (width < window_width && height < window_height);
2157 gdk_gc_set_clip_rectangle (style->light_gc[state], area);
2158 gdk_gc_set_clip_rectangle (style->dark_gc[state], area);
2159 gdk_gc_set_clip_rectangle (style->black_gc, area);
2160 gdk_gc_set_clip_rectangle (style->bg_gc[state], area);
2161 gdk_gc_set_clip_rectangle (style->base_gc[state], area);
2164 gdk_draw_line (window, style->light_gc[state],
2165 x, y + height - 1, x + width - 1, y + height - 1);
2167 gdk_draw_line (window,
2168 style->base_gc[state],
2169 x + width - 1, y + 1, x + width - 1, y + height - 3);
2173 gdk_draw_line (window, style->bg_gc[state],
2174 x + 1, y + height - 2, x + width - 1, y + height - 2);
2175 gdk_draw_line (window,
2176 style->base_gc[state],
2177 x + width - 2, y + 1, x + width - 2, y + height - 3);
2179 gdk_draw_line (window, style->black_gc,
2180 x + 1, y + 1, x + width - 1, y + 1);
2181 gdk_draw_line (window, style->black_gc,
2182 x + 1, y + 1, x + 1, y + height - 2);
2185 gdk_draw_line (window, style->dark_gc[state],
2186 x, y, x + width - 1, y);
2187 gdk_draw_line (window, style->dark_gc[state],
2188 x, y, x, y + height - 1);
2192 gdk_gc_set_clip_rectangle (style->light_gc[state], NULL);
2193 gdk_gc_set_clip_rectangle (style->dark_gc[state], NULL);
2194 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2195 gdk_gc_set_clip_rectangle (style->bg_gc[state], NULL);
2196 gdk_gc_set_clip_rectangle (style->base_gc[state], NULL);
2201 draw_spinbutton_shadow (GtkStyle *style,
2210 gint y_middle = y + height / 2;
2212 sanitize_size (window, &width, &height);
2216 gdk_gc_set_clip_rectangle (style->black_gc, area);
2217 gdk_gc_set_clip_rectangle (style->bg_gc[state], area);
2218 gdk_gc_set_clip_rectangle (style->dark_gc[state], area);
2219 gdk_gc_set_clip_rectangle (style->light_gc[state], area);
2222 gdk_draw_line (window, style->black_gc,
2223 x, y + 2, x, y + height - 3);
2224 gdk_draw_line (window, style->black_gc,
2225 x, y + 1, x + width - 2, y + 1);
2226 gdk_draw_line (window, style->black_gc,
2227 x + width - 2, y + 2, x + width - 2, y + height - 3);
2229 gdk_draw_line (window, style->bg_gc[state],
2230 x, y + height - 2, x + width - 2, y + height - 2);
2232 gdk_draw_line (window, style->dark_gc[state],
2233 x, y, x + width - 1, y);
2234 gdk_draw_line (window, style->dark_gc[state],
2235 x + 1, y_middle - 1, x + width - 3, y_middle - 1);
2236 gdk_draw_line (window, style->dark_gc[state],
2237 x + 1, y + height - 3, x + width - 3, y + height - 3);
2239 gdk_draw_line (window, style->light_gc[state],
2240 x + 1, y + 2, x + width - 3, y + 2);
2241 gdk_draw_line (window, style->light_gc[state],
2242 x + 1, y_middle, x + width - 3, y_middle);
2243 gdk_draw_line (window, style->light_gc[state],
2244 x + width - 1, y + 1, x + width - 1, y + height - 1);
2245 gdk_draw_line (window, style->light_gc[state],
2246 x, y + height - 1, x + width - 2, y + height - 1);
2250 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2251 gdk_gc_set_clip_rectangle (style->bg_gc[state], NULL);
2252 gdk_gc_set_clip_rectangle (style->dark_gc[state], NULL);
2253 gdk_gc_set_clip_rectangle (style->light_gc[state], NULL);
2258 gtk_default_draw_shadow (GtkStyle *style,
2260 GtkStateType state_type,
2261 GtkShadowType shadow_type,
2264 const gchar *detail,
2272 gint thickness_light;
2273 gint thickness_dark;
2276 g_return_if_fail (GTK_IS_STYLE (style));
2277 g_return_if_fail (window != NULL);
2279 if (shadow_type == GTK_SHADOW_IN)
2281 if (detail && (strcmp (detail, "buttondefault") == 0))
2283 sanitize_size (window, &width, &height);
2285 gdk_draw_rectangle (window, style->black_gc, FALSE,
2286 x, y, width - 1, height - 1);
2290 if (detail && strcmp (detail, "trough") == 0)
2292 draw_thin_shadow (style, window, state_type, area,
2293 x, y, width, height);
2296 else if (widget && GTK_IS_SPIN_BUTTON (widget) &&
2297 detail && strcmp (detail, "entry") == 0)
2299 draw_spin_entry_shadow (style, window, state_type, area,
2300 x, y, width, height);
2303 else if (widget && GTK_IS_SPIN_BUTTON (widget) &&
2304 detail && strcmp (detail, "spinbutton") == 0)
2306 draw_spinbutton_shadow (style, window, state_type,
2307 area, x, y, width, height);
2312 sanitize_size (window, &width, &height);
2314 switch (shadow_type)
2316 case GTK_SHADOW_NONE:
2319 case GTK_SHADOW_ETCHED_IN:
2320 gc1 = style->light_gc[state_type];
2321 gc2 = style->dark_gc[state_type];
2323 case GTK_SHADOW_OUT:
2324 case GTK_SHADOW_ETCHED_OUT:
2325 gc1 = style->dark_gc[state_type];
2326 gc2 = style->light_gc[state_type];
2332 gdk_gc_set_clip_rectangle (gc1, area);
2333 gdk_gc_set_clip_rectangle (gc2, area);
2334 if (shadow_type == GTK_SHADOW_IN ||
2335 shadow_type == GTK_SHADOW_OUT)
2337 gdk_gc_set_clip_rectangle (style->black_gc, area);
2338 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2342 switch (shadow_type)
2344 case GTK_SHADOW_NONE:
2348 /* Light around right and bottom edge */
2350 if (style->ythickness > 0)
2351 gdk_draw_line (window, gc1,
2352 x, y + height - 1, x + width - 1, y + height - 1);
2353 if (style->xthickness > 0)
2354 gdk_draw_line (window, gc1,
2355 x + width - 1, y, x + width - 1, y + height - 1);
2357 if (style->ythickness > 1)
2358 gdk_draw_line (window, style->bg_gc[state_type],
2359 x + 1, y + height - 2, x + width - 2, y + height - 2);
2360 if (style->xthickness > 1)
2361 gdk_draw_line (window, style->bg_gc[state_type],
2362 x + width - 2, y + 1, x + width - 2, y + height - 2);
2364 /* Dark around left and top */
2366 if (style->ythickness > 1)
2367 gdk_draw_line (window, style->black_gc,
2368 x + 1, y + 1, x + width - 2, y + 1);
2369 if (style->xthickness > 1)
2370 gdk_draw_line (window, style->black_gc,
2371 x + 1, y + 1, x + 1, y + height - 2);
2373 if (style->ythickness > 0)
2374 gdk_draw_line (window, gc2,
2375 x, y, x + width - 1, y);
2376 if (style->xthickness > 0)
2377 gdk_draw_line (window, gc2,
2378 x, y, x, y + height - 1);
2381 case GTK_SHADOW_OUT:
2382 /* Dark around right and bottom edge */
2384 if (style->ythickness > 0)
2386 if (style->ythickness > 1)
2388 gdk_draw_line (window, gc1,
2389 x + 1, y + height - 2, x + width - 2, y + height - 2);
2390 gdk_draw_line (window, style->black_gc,
2391 x, y + height - 1, x + width - 1, y + height - 1);
2395 gdk_draw_line (window, gc1,
2396 x + 1, y + height - 1, x + width - 1, y + height - 1);
2400 if (style->xthickness > 0)
2402 if (style->xthickness > 1)
2404 gdk_draw_line (window, gc1,
2405 x + width - 2, y + 1, x + width - 2, y + height - 2);
2407 gdk_draw_line (window, style->black_gc,
2408 x + width - 1, y, x + width - 1, y + height - 1);
2412 gdk_draw_line (window, gc1,
2413 x + width - 1, y + 1, x + width - 1, y + height - 1);
2417 /* Light around top and left */
2419 if (style->ythickness > 0)
2420 gdk_draw_line (window, gc2,
2421 x, y, x + width - 1, y);
2422 if (style->xthickness > 0)
2423 gdk_draw_line (window, gc2,
2424 x, y, x, y + height - 1);
2426 if (style->ythickness > 1)
2427 gdk_draw_line (window, style->bg_gc[state_type],
2428 x + 1, y + 1, x + width - 2, y + 1);
2429 if (style->xthickness > 1)
2430 gdk_draw_line (window, style->bg_gc[state_type],
2431 x + 1, y + 1, x + 1, y + height - 2);
2434 case GTK_SHADOW_ETCHED_IN:
2435 case GTK_SHADOW_ETCHED_OUT:
2436 if (style->xthickness > 0)
2438 if (style->xthickness > 1)
2440 thickness_light = 1;
2443 for (i = 0; i < thickness_dark; i++)
2445 gdk_draw_line (window, gc1,
2449 y + height - i - 1);
2450 gdk_draw_line (window, gc2,
2454 y + height - i - 2);
2457 for (i = 0; i < thickness_light; i++)
2459 gdk_draw_line (window, gc1,
2460 x + thickness_dark + i,
2461 y + thickness_dark + i,
2462 x + thickness_dark + i,
2463 y + height - thickness_dark - i - 1);
2464 gdk_draw_line (window, gc2,
2465 x + width - thickness_light - i - 1,
2466 y + thickness_dark + i,
2467 x + width - thickness_light - i - 1,
2468 y + height - thickness_light - 1);
2473 gdk_draw_line (window,
2474 style->dark_gc[state_type],
2475 x, y, x, y + height);
2476 gdk_draw_line (window,
2477 style->dark_gc[state_type],
2478 x + width, y, x + width, y + height);
2482 if (style->ythickness > 0)
2484 if (style->ythickness > 1)
2486 thickness_light = 1;
2489 for (i = 0; i < thickness_dark; i++)
2491 gdk_draw_line (window, gc1,
2495 y + height - i - 1);
2497 gdk_draw_line (window, gc2,
2504 for (i = 0; i < thickness_light; i++)
2506 gdk_draw_line (window, gc1,
2507 x + thickness_dark + i,
2508 y + thickness_dark + i,
2509 x + width - thickness_dark - i - 1,
2510 y + thickness_dark + i);
2512 gdk_draw_line (window, gc2,
2513 x + thickness_dark + i,
2514 y + height - thickness_light - i - 1,
2515 x + width - thickness_light - 1,
2516 y + height - thickness_light - i - 1);
2521 gdk_draw_line (window,
2522 style->dark_gc[state_type],
2523 x, y, x + width, y);
2524 gdk_draw_line (window,
2525 style->dark_gc[state_type],
2526 x, y + height, x + width, y + height);
2534 gdk_gc_set_clip_rectangle (gc1, NULL);
2535 gdk_gc_set_clip_rectangle (gc2, NULL);
2536 if (shadow_type == GTK_SHADOW_IN ||
2537 shadow_type == GTK_SHADOW_OUT)
2539 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2540 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
2546 gtk_default_draw_polygon (GtkStyle *style,
2548 GtkStateType state_type,
2549 GtkShadowType shadow_type,
2552 const gchar *detail,
2557 static const gdouble pi_over_4 = G_PI_4;
2558 static const gdouble pi_3_over_4 = G_PI_4 * 3;
2568 g_return_if_fail (GTK_IS_STYLE (style));
2569 g_return_if_fail (window != NULL);
2570 g_return_if_fail (points != NULL);
2572 switch (shadow_type)
2575 gc1 = style->bg_gc[state_type];
2576 gc2 = style->dark_gc[state_type];
2577 gc3 = style->light_gc[state_type];
2578 gc4 = style->black_gc;
2580 case GTK_SHADOW_ETCHED_IN:
2581 gc1 = style->light_gc[state_type];
2582 gc2 = style->dark_gc[state_type];
2583 gc3 = style->dark_gc[state_type];
2584 gc4 = style->light_gc[state_type];
2586 case GTK_SHADOW_OUT:
2587 gc1 = style->dark_gc[state_type];
2588 gc2 = style->light_gc[state_type];
2589 gc3 = style->black_gc;
2590 gc4 = style->bg_gc[state_type];
2592 case GTK_SHADOW_ETCHED_OUT:
2593 gc1 = style->dark_gc[state_type];
2594 gc2 = style->light_gc[state_type];
2595 gc3 = style->light_gc[state_type];
2596 gc4 = style->dark_gc[state_type];
2604 gdk_gc_set_clip_rectangle (gc1, area);
2605 gdk_gc_set_clip_rectangle (gc2, area);
2606 gdk_gc_set_clip_rectangle (gc3, area);
2607 gdk_gc_set_clip_rectangle (gc4, area);
2611 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, npoints);
2615 for (i = 0; i < npoints; i++)
2617 if ((points[i].x == points[i+1].x) &&
2618 (points[i].y == points[i+1].y))
2624 angle = atan2 (points[i+1].y - points[i].y,
2625 points[i+1].x - points[i].x);
2628 if ((angle > -pi_3_over_4) && (angle < pi_over_4))
2630 if (angle > -pi_over_4)
2641 gdk_draw_line (window, gc1,
2642 points[i].x-xadjust, points[i].y-yadjust,
2643 points[i+1].x-xadjust, points[i+1].y-yadjust);
2644 gdk_draw_line (window, gc3,
2645 points[i].x, points[i].y,
2646 points[i+1].x, points[i+1].y);
2650 if ((angle < -pi_3_over_4) || (angle > pi_3_over_4))
2661 gdk_draw_line (window, gc4,
2662 points[i].x+xadjust, points[i].y+yadjust,
2663 points[i+1].x+xadjust, points[i+1].y+yadjust);
2664 gdk_draw_line (window, gc2,
2665 points[i].x, points[i].y,
2666 points[i+1].x, points[i+1].y);
2672 gdk_gc_set_clip_rectangle (gc1, NULL);
2673 gdk_gc_set_clip_rectangle (gc2, NULL);
2674 gdk_gc_set_clip_rectangle (gc3, NULL);
2675 gdk_gc_set_clip_rectangle (gc4, NULL);
2680 draw_varrow (GdkWindow *window,
2682 GtkShadowType shadow_type,
2684 GtkArrowType arrow_type,
2691 gint y_start, y_increment;
2695 gdk_gc_set_clip_rectangle (gc, area);
2697 width = width + width % 2 - 1; /* Force odd */
2699 steps = 1 + width / 2;
2701 extra = height - steps;
2703 if (arrow_type == GTK_ARROW_DOWN)
2710 y_start = y + height - 1;
2714 for (i = 0; i < extra; i++)
2716 gdk_draw_line (window, gc,
2717 x, y_start + i * y_increment,
2718 x + width - 1, y_start + i * y_increment);
2720 for (; i < height; i++)
2722 gdk_draw_line (window, gc,
2723 x + (i - extra), y_start + i * y_increment,
2724 x + width - (i - extra) - 1, y_start + i * y_increment);
2729 gdk_gc_set_clip_rectangle (gc, NULL);
2733 draw_harrow (GdkWindow *window,
2735 GtkShadowType shadow_type,
2737 GtkArrowType arrow_type,
2744 gint x_start, x_increment;
2748 gdk_gc_set_clip_rectangle (gc, area);
2750 height = height + height % 2 - 1; /* Force odd */
2752 steps = 1 + height / 2;
2754 extra = width - steps;
2756 if (arrow_type == GTK_ARROW_RIGHT)
2763 x_start = x + width - 1;
2767 for (i = 0; i < extra; i++)
2769 gdk_draw_line (window, gc,
2770 x_start + i * x_increment, y,
2771 x_start + i * x_increment, y + height - 1);
2773 for (; i < width; i++)
2775 gdk_draw_line (window, gc,
2776 x_start + i * x_increment, y + (i - extra),
2777 x_start + i * x_increment, y + height - (i - extra) - 1);
2782 gdk_gc_set_clip_rectangle (gc, NULL);
2786 gtk_default_draw_arrow (GtkStyle *style,
2789 GtkShadowType shadow,
2792 const gchar *detail,
2793 GtkArrowType arrow_type,
2800 sanitize_size (window, &width, &height);
2802 if (detail && strcmp (detail, "spinbutton") == 0)
2805 int my_height = height;
2806 int my_width = width;
2809 if (my_height > my_width)
2811 vpad_add = (my_height - my_width) / 2;
2812 my_height = my_width;
2815 hpad = my_width / 4;
2820 vpad = 2 * hpad - 1;
2827 draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
2828 x, y, my_width - hpad, my_height - vpad);
2830 else if (detail && strcmp (detail, "vscrollbar") == 0)
2832 gtk_paint_box (style, window, state, shadow, area,
2833 widget, detail, x, y, width, height);
2835 x += (width - 7) / 2;
2836 y += (height - 5) / 2;
2838 draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
2841 else if (detail && strcmp (detail, "hscrollbar") == 0)
2843 gtk_paint_box (style, window, state, shadow, area,
2844 widget, detail, x, y, width, height);
2846 y += (height - 7) / 2;
2847 x += (width - 5) / 2;
2849 draw_harrow (window, style->fg_gc[state], shadow, area, arrow_type,
2854 if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
2856 x += (width - 7) / 2;
2857 y += (height - 5) / 2;
2859 draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
2864 x += (width - 5) / 2;
2865 y += (height - 7) / 2;
2867 draw_harrow (window, style->fg_gc[state], shadow, area, arrow_type,
2874 gtk_default_draw_diamond (GtkStyle *style,
2876 GtkStateType state_type,
2877 GtkShadowType shadow_type,
2880 const gchar *detail,
2888 GdkGC *outer_nw = NULL;
2889 GdkGC *outer_ne = NULL;
2890 GdkGC *outer_sw = NULL;
2891 GdkGC *outer_se = NULL;
2892 GdkGC *middle_nw = NULL;
2893 GdkGC *middle_ne = NULL;
2894 GdkGC *middle_sw = NULL;
2895 GdkGC *middle_se = NULL;
2896 GdkGC *inner_nw = NULL;
2897 GdkGC *inner_ne = NULL;
2898 GdkGC *inner_sw = NULL;
2899 GdkGC *inner_se = NULL;
2901 g_return_if_fail (GTK_IS_STYLE (style));
2902 g_return_if_fail (window != NULL);
2904 sanitize_size (window, &width, &height);
2906 half_width = width / 2;
2907 half_height = height / 2;
2911 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
2912 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2913 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
2914 gdk_gc_set_clip_rectangle (style->black_gc, area);
2917 switch (shadow_type)
2920 inner_sw = inner_se = style->bg_gc[state_type];
2921 middle_sw = middle_se = style->light_gc[state_type];
2922 outer_sw = outer_se = style->light_gc[state_type];
2923 inner_nw = inner_ne = style->black_gc;
2924 middle_nw = middle_ne = style->dark_gc[state_type];
2925 outer_nw = outer_ne = style->dark_gc[state_type];
2928 case GTK_SHADOW_OUT:
2929 inner_sw = inner_se = style->dark_gc[state_type];
2930 middle_sw = middle_se = style->dark_gc[state_type];
2931 outer_sw = outer_se = style->black_gc;
2932 inner_nw = inner_ne = style->bg_gc[state_type];
2933 middle_nw = middle_ne = style->light_gc[state_type];
2934 outer_nw = outer_ne = style->light_gc[state_type];
2937 case GTK_SHADOW_ETCHED_IN:
2938 inner_sw = inner_se = style->bg_gc[state_type];
2939 middle_sw = middle_se = style->dark_gc[state_type];
2940 outer_sw = outer_se = style->light_gc[state_type];
2941 inner_nw = inner_ne = style->bg_gc[state_type];
2942 middle_nw = middle_ne = style->light_gc[state_type];
2943 outer_nw = outer_ne = style->dark_gc[state_type];
2946 case GTK_SHADOW_ETCHED_OUT:
2947 inner_sw = inner_se = style->bg_gc[state_type];
2948 middle_sw = middle_se = style->light_gc[state_type];
2949 outer_sw = outer_se = style->dark_gc[state_type];
2950 inner_nw = inner_ne = style->bg_gc[state_type];
2951 middle_nw = middle_ne = style->dark_gc[state_type];
2952 outer_nw = outer_ne = style->light_gc[state_type];
2962 gdk_draw_line (window, inner_sw,
2963 x + 2, y + half_height,
2964 x + half_width, y + height - 2);
2965 gdk_draw_line (window, inner_se,
2966 x + half_width, y + height - 2,
2967 x + width - 2, y + half_height);
2968 gdk_draw_line (window, middle_sw,
2969 x + 1, y + half_height,
2970 x + half_width, y + height - 1);
2971 gdk_draw_line (window, middle_se,
2972 x + half_width, y + height - 1,
2973 x + width - 1, y + half_height);
2974 gdk_draw_line (window, outer_sw,
2976 x + half_width, y + height);
2977 gdk_draw_line (window, outer_se,
2978 x + half_width, y + height,
2979 x + width, y + half_height);
2981 gdk_draw_line (window, inner_nw,
2982 x + 2, y + half_height,
2983 x + half_width, y + 2);
2984 gdk_draw_line (window, inner_ne,
2985 x + half_width, y + 2,
2986 x + width - 2, y + half_height);
2987 gdk_draw_line (window, middle_nw,
2988 x + 1, y + half_height,
2989 x + half_width, y + 1);
2990 gdk_draw_line (window, middle_ne,
2991 x + half_width, y + 1,
2992 x + width - 1, y + half_height);
2993 gdk_draw_line (window, outer_nw,
2996 gdk_draw_line (window, outer_ne,
2998 x + width, y + half_height);
3003 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
3004 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
3005 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
3006 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
3011 gtk_default_draw_string (GtkStyle *style,
3013 GtkStateType state_type,
3016 const gchar *detail,
3019 const gchar *string)
3021 g_return_if_fail (GTK_IS_STYLE (style));
3022 g_return_if_fail (window != NULL);
3026 gdk_gc_set_clip_rectangle (style->white_gc, area);
3027 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], area);
3030 if (state_type == GTK_STATE_INSENSITIVE)
3031 gdk_draw_string (window, gtk_style_get_font (style), style->white_gc, x + 1, y + 1, string);
3033 gdk_draw_string (window, gtk_style_get_font (style), style->fg_gc[state_type], x, y, string);
3037 gdk_gc_set_clip_rectangle (style->white_gc, NULL);
3038 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], NULL);
3043 option_menu_get_props (GtkWidget *widget,
3044 GtkRequisition *indicator_size,
3045 GtkBorder *indicator_spacing)
3047 GtkRequisition *tmp_size = NULL;
3048 GtkBorder *tmp_spacing = NULL;
3051 gtk_widget_style_get (widget,
3052 "indicator_size", &tmp_size,
3053 "indicator_spacing", &tmp_spacing,
3058 *indicator_size = *tmp_size;
3062 *indicator_size = default_option_indicator_size;
3066 *indicator_spacing = *tmp_spacing;
3067 g_free (tmp_spacing);
3070 *indicator_spacing = default_option_indicator_spacing;
3074 gtk_default_draw_box (GtkStyle *style,
3076 GtkStateType state_type,
3077 GtkShadowType shadow_type,
3080 const gchar *detail,
3086 g_return_if_fail (GTK_IS_STYLE (style));
3087 g_return_if_fail (window != NULL);
3089 sanitize_size (window, &width, &height);
3091 if (!style->bg_pixmap[state_type] ||
3092 GDK_IS_PIXMAP (window))
3095 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
3097 gdk_draw_rectangle (window, style->bg_gc[state_type], TRUE,
3098 x, y, width, height);
3100 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
3103 gtk_style_apply_default_background (style, window,
3104 widget && !GTK_WIDGET_NO_WINDOW (widget),
3105 state_type, area, x, y, width, height);
3107 gtk_paint_shadow (style, window, state_type, shadow_type, area, widget, detail,
3108 x, y, width, height);
3110 if (detail && strcmp (detail, "optionmenu") == 0)
3112 GtkRequisition indicator_size;
3113 GtkBorder indicator_spacing;
3115 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
3117 sanitize_size (window, &width, &height);
3119 gtk_paint_vline (style, window, state_type, area, widget,
3121 y + style->ythickness + 1,
3122 y + height - style->ythickness - 3,
3123 x + width - (indicator_size.width + indicator_spacing.left + indicator_spacing.right) - style->xthickness);
3128 get_darkened_gc (GdkWindow *window,
3132 GdkColor src = *color;
3136 gc = gdk_gc_new (window);
3138 while (darken_count)
3140 gtk_style_shade (&src, &shaded, 0.93);
3145 gdk_gc_set_rgb_fg_color (gc, &shaded);
3151 gtk_default_draw_flat_box (GtkStyle *style,
3153 GtkStateType state_type,
3154 GtkShadowType shadow_type,
3157 const gchar *detail,
3164 GdkGC *freeme = NULL;
3166 g_return_if_fail (GTK_IS_STYLE (style));
3167 g_return_if_fail (window != NULL);
3169 sanitize_size (window, &width, &height);
3173 if (state_type == GTK_STATE_SELECTED)
3175 if (!strcmp ("text", detail))
3176 gc1 = style->bg_gc[GTK_STATE_SELECTED];
3177 else if (!strncmp ("cell_even", detail, strlen ("cell_even")) ||
3178 !strncmp ("cell_odd", detail, strlen ("cell_odd")))
3180 /* This has to be really broken; alex made me do it. -jrb */
3181 if (GTK_WIDGET_HAS_FOCUS (widget))
3182 gc1 = style->base_gc[state_type];
3184 gc1 = style->base_gc[GTK_STATE_ACTIVE];
3188 gc1 = style->bg_gc[state_type];
3193 if (!strcmp ("viewportbin", detail))
3194 gc1 = style->bg_gc[GTK_STATE_NORMAL];
3195 else if (!strcmp ("entry_bg", detail))
3196 gc1 = style->base_gc[state_type];
3198 /* For trees: even rows are base color, odd rows are a shade of
3199 * the base color, the sort column is a shade of the original color
3203 /* FIXME when we have style properties, clean this up.
3206 else if (!strcmp ("cell_even", detail) ||
3207 !strcmp ("cell_odd", detail) ||
3208 !strcmp ("cell_even_ruled", detail))
3210 gc1 = style->base_gc[state_type];
3212 else if (!strcmp ("cell_even_sorted", detail) ||
3213 !strcmp ("cell_odd_sorted", detail) ||
3214 !strcmp ("cell_odd_ruled", detail) ||
3215 !strcmp ("cell_even_ruled_sorted", detail))
3217 freeme = get_darkened_gc (window, &style->base[state_type], 1);
3220 else if (!strcmp ("cell_odd_ruled_sorted", detail))
3222 freeme = get_darkened_gc (window, &style->base[state_type], 2);
3226 gc1 = style->bg_gc[state_type];
3230 gc1 = style->bg_gc[state_type];
3232 if (!style->bg_pixmap[state_type] || gc1 != style->bg_gc[state_type] ||
3233 GDK_IS_PIXMAP (window))
3236 gdk_gc_set_clip_rectangle (gc1, area);
3238 gdk_draw_rectangle (window, gc1, TRUE,
3239 x, y, width, height);
3241 if (detail && !strcmp ("tooltip", detail))
3242 gdk_draw_rectangle (window, style->black_gc, FALSE,
3243 x, y, width - 1, height - 1);
3246 gdk_gc_set_clip_rectangle (gc1, NULL);
3249 gtk_style_apply_default_background (style, window,
3250 widget && !GTK_WIDGET_NO_WINDOW (widget),
3251 state_type, area, x, y, width, height);
3255 g_object_unref (G_OBJECT (freeme));
3259 gtk_default_draw_check (GtkStyle *style,
3261 GtkStateType state_type,
3262 GtkShadowType shadow_type,
3265 const gchar *detail,
3271 if (detail && strcmp (detail, "cellcheck") == 0)
3273 gdk_draw_rectangle (window,
3274 widget->style->base_gc[state_type],
3278 gdk_draw_rectangle (window,
3279 widget->style->text_gc[state_type],
3284 x -= (1 + INDICATOR_PART_SIZE - width) / 2;
3285 y -= (((1 + INDICATOR_PART_SIZE - height) / 2) - 1);
3286 if (shadow_type == GTK_SHADOW_IN)
3288 draw_part (window, style->text_gc[state_type], area, x, y, CHECK_TEXT);
3289 draw_part (window, style->text_aa_gc[state_type], area, x, y, CHECK_AA);
3294 x -= (1 + INDICATOR_PART_SIZE - width) / 2;
3295 y -= (1 + INDICATOR_PART_SIZE - height) / 2;
3297 if (strcmp (detail, "check") == 0) /* Menu item */
3299 if (shadow_type == GTK_SHADOW_IN)
3301 draw_part (window, style->black_gc, area, x, y, CHECK_TEXT);
3302 draw_part (window, style->dark_gc[state_type], area, x, y, CHECK_AA);
3307 draw_part (window, style->black_gc, area, x, y, CHECK_BLACK);
3308 draw_part (window, style->dark_gc[state_type], area, x, y, CHECK_DARK);
3309 draw_part (window, style->mid_gc[state_type], area, x, y, CHECK_MID);
3310 draw_part (window, style->light_gc[state_type], area, x, y, CHECK_LIGHT);
3311 draw_part (window, style->base_gc[state_type], area, x, y, CHECK_BASE);
3313 if (shadow_type == GTK_SHADOW_IN)
3315 draw_part (window, style->text_gc[state_type], area, x, y, CHECK_TEXT);
3316 draw_part (window, style->text_aa_gc[state_type], area, x, y, CHECK_AA);
3324 gtk_default_draw_option (GtkStyle *style,
3326 GtkStateType state_type,
3327 GtkShadowType shadow_type,
3330 const gchar *detail,
3336 if (detail && strcmp (detail, "cellradio") == 0)
3338 gdk_draw_arc (window,
3339 widget->style->fg_gc[state_type],
3346 if (shadow_type == GTK_SHADOW_IN)
3348 gdk_draw_arc (window,
3349 widget->style->fg_gc[state_type],
3360 x -= (1 + INDICATOR_PART_SIZE - width) / 2;
3361 y -= (1 + INDICATOR_PART_SIZE - height) / 2;
3363 if (strcmp (detail, "option") == 0) /* Menu item */
3365 if (shadow_type == GTK_SHADOW_IN)
3366 draw_part (window, style->fg_gc[state_type], area, x, y, RADIO_TEXT);
3370 draw_part (window, style->black_gc, area, x, y, RADIO_BLACK);
3371 draw_part (window, style->dark_gc[state_type], area, x, y, RADIO_DARK);
3372 draw_part (window, style->mid_gc[state_type], area, x, y, RADIO_MID);
3373 draw_part (window, style->light_gc[state_type], area, x, y, RADIO_LIGHT);
3374 draw_part (window, style->base_gc[state_type], area, x, y, RADIO_BASE);
3376 if (shadow_type == GTK_SHADOW_IN)
3377 draw_part (window, style->text_gc[state_type], area, x, y, RADIO_TEXT);
3383 gtk_default_draw_tab (GtkStyle *style,
3385 GtkStateType state_type,
3386 GtkShadowType shadow_type,
3389 const gchar *detail,
3395 GtkRequisition indicator_size;
3396 GtkBorder indicator_spacing;
3398 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
3400 x += (width - indicator_size.width) / 2;
3401 y += (height - indicator_size.height) / 2 - 1;
3403 draw_varrow (window, style->black_gc, shadow_type, area, GTK_ARROW_UP,
3404 x, y, indicator_size.width, 5);
3405 draw_varrow (window, style->black_gc, shadow_type, area, GTK_ARROW_DOWN,
3406 x, y + 8, indicator_size.width, 5);
3410 gtk_default_draw_shadow_gap (GtkStyle *style,
3412 GtkStateType state_type,
3413 GtkShadowType shadow_type,
3416 const gchar *detail,
3421 GtkPositionType gap_side,
3430 g_return_if_fail (GTK_IS_STYLE (style));
3431 g_return_if_fail (window != NULL);
3433 sanitize_size (window, &width, &height);
3435 switch (shadow_type)
3437 case GTK_SHADOW_NONE:
3440 gc1 = style->dark_gc[state_type];
3441 gc2 = style->black_gc;
3442 gc3 = style->bg_gc[state_type];
3443 gc4 = style->light_gc[state_type];
3445 case GTK_SHADOW_ETCHED_IN:
3446 gc1 = style->dark_gc[state_type];
3447 gc2 = style->light_gc[state_type];
3448 gc3 = style->dark_gc[state_type];
3449 gc4 = style->light_gc[state_type];
3451 case GTK_SHADOW_OUT:
3452 gc1 = style->light_gc[state_type];
3453 gc2 = style->bg_gc[state_type];
3454 gc3 = style->dark_gc[state_type];
3455 gc4 = style->black_gc;
3457 case GTK_SHADOW_ETCHED_OUT:
3458 gc1 = style->light_gc[state_type];
3459 gc2 = style->dark_gc[state_type];
3460 gc3 = style->light_gc[state_type];
3461 gc4 = style->dark_gc[state_type];
3466 gdk_gc_set_clip_rectangle (gc1, area);
3467 gdk_gc_set_clip_rectangle (gc2, area);
3468 gdk_gc_set_clip_rectangle (gc3, area);
3469 gdk_gc_set_clip_rectangle (gc4, area);
3472 switch (shadow_type)
3474 case GTK_SHADOW_NONE:
3476 case GTK_SHADOW_OUT:
3477 case GTK_SHADOW_ETCHED_IN:
3478 case GTK_SHADOW_ETCHED_OUT:
3482 gdk_draw_line (window, gc1,
3483 x, y, x, y + height - 1);
3484 gdk_draw_line (window, gc2,
3485 x + 1, y, x + 1, y + height - 2);
3487 gdk_draw_line (window, gc3,
3488 x + 1, y + height - 2, x + width - 2, y + height - 2);
3489 gdk_draw_line (window, gc3,
3490 x + width - 2, y, x + width - 2, y + height - 2);
3491 gdk_draw_line (window, gc4,
3492 x, y + height - 1, x + width - 1, y + height - 1);
3493 gdk_draw_line (window, gc4,
3494 x + width - 1, y, x + width - 1, y + height - 1);
3497 gdk_draw_line (window, gc1,
3498 x, y, x + gap_x - 1, y);
3499 gdk_draw_line (window, gc2,
3500 x + 1, y + 1, x + gap_x - 1, y + 1);
3501 gdk_draw_line (window, gc2,
3502 x + gap_x, y, x + gap_x, y);
3504 if ((width - (gap_x + gap_width)) > 0)
3506 gdk_draw_line (window, gc1,
3507 x + gap_x + gap_width, y, x + width - 2, y);
3508 gdk_draw_line (window, gc2,
3509 x + gap_x + gap_width, y + 1, x + width - 3, y + 1);
3510 gdk_draw_line (window, gc2,
3511 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
3514 case GTK_POS_BOTTOM:
3515 gdk_draw_line (window, gc1,
3516 x, y, x + width - 1, y);
3517 gdk_draw_line (window, gc1,
3518 x, y, x, y + height - 1);
3519 gdk_draw_line (window, gc2,
3520 x + 1, y + 1, x + width - 2, y + 1);
3521 gdk_draw_line (window, gc2,
3522 x + 1, y + 1, x + 1, y + height - 1);
3524 gdk_draw_line (window, gc3,
3525 x + width - 2, y + 1, x + width - 2, y + height - 1);
3526 gdk_draw_line (window, gc4,
3527 x + width - 1, y, x + width - 1, y + height - 1);
3530 gdk_draw_line (window, gc4,
3531 x, y + height - 1, x + gap_x - 1, y + height - 1);
3532 gdk_draw_line (window, gc3,
3533 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
3534 gdk_draw_line (window, gc3,
3535 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
3537 if ((width - (gap_x + gap_width)) > 0)
3539 gdk_draw_line (window, gc4,
3540 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
3541 gdk_draw_line (window, gc3,
3542 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
3543 gdk_draw_line (window, gc3,
3544 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
3548 gdk_draw_line (window, gc1,
3549 x, y, x + width - 1, y);
3550 gdk_draw_line (window, gc2,
3551 x, y + 1, x + width - 2, y + 1);
3553 gdk_draw_line (window, gc3,
3554 x, y + height - 2, x + width - 2, y + height - 2);
3555 gdk_draw_line (window, gc3,
3556 x + width - 2, y + 1, x + width - 2, y + height - 2);
3557 gdk_draw_line (window, gc4,
3558 x, y + height - 1, x + width - 1, y + height - 1);
3559 gdk_draw_line (window, gc4,
3560 x + width - 1, y, x + width - 1, y + height - 1);
3563 gdk_draw_line (window, gc1,
3564 x, y, x, y + gap_x - 1);
3565 gdk_draw_line (window, gc2,
3566 x + 1, y + 1, x + 1, y + gap_x - 1);
3567 gdk_draw_line (window, gc2,
3568 x, y + gap_x, x, y + gap_x);
3570 if ((width - (gap_x + gap_width)) > 0)
3572 gdk_draw_line (window, gc1,
3573 x, y + gap_x + gap_width, x, y + height - 2);
3574 gdk_draw_line (window, gc2,
3575 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
3576 gdk_draw_line (window, gc2,
3577 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
3581 gdk_draw_line (window, gc1,
3582 x, y, x + width - 1, y);
3583 gdk_draw_line (window, gc1,
3584 x, y, x, y + height - 1);
3585 gdk_draw_line (window, gc2,
3586 x + 1, y + 1, x + width - 1, y + 1);
3587 gdk_draw_line (window, gc2,
3588 x + 1, y + 1, x + 1, y + height - 2);
3590 gdk_draw_line (window, gc3,
3591 x + 1, y + height - 2, x + width - 1, y + height - 2);
3592 gdk_draw_line (window, gc4,
3593 x, y + height - 1, x + width - 1, y + height - 1);
3596 gdk_draw_line (window, gc4,
3597 x + width - 1, y, x + width - 1, y + gap_x - 1);
3598 gdk_draw_line (window, gc3,
3599 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
3600 gdk_draw_line (window, gc3,
3601 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
3603 if ((width - (gap_x + gap_width)) > 0)
3605 gdk_draw_line (window, gc4,
3606 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
3607 gdk_draw_line (window, gc3,
3608 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
3609 gdk_draw_line (window, gc3,
3610 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
3618 gdk_gc_set_clip_rectangle (gc1, NULL);
3619 gdk_gc_set_clip_rectangle (gc2, NULL);
3620 gdk_gc_set_clip_rectangle (gc3, NULL);
3621 gdk_gc_set_clip_rectangle (gc4, NULL);
3626 gtk_default_draw_box_gap (GtkStyle *style,
3628 GtkStateType state_type,
3629 GtkShadowType shadow_type,
3632 const gchar *detail,
3637 GtkPositionType gap_side,
3646 g_return_if_fail (GTK_IS_STYLE (style));
3647 g_return_if_fail (window != NULL);
3649 gtk_style_apply_default_background (style, window,
3650 widget && !GTK_WIDGET_NO_WINDOW (widget),
3651 state_type, area, x, y, width, height);
3653 sanitize_size (window, &width, &height);
3655 switch (shadow_type)
3657 case GTK_SHADOW_NONE:
3660 gc1 = style->dark_gc[state_type];
3661 gc2 = style->black_gc;
3662 gc3 = style->bg_gc[state_type];
3663 gc4 = style->light_gc[state_type];
3665 case GTK_SHADOW_ETCHED_IN:
3666 gc1 = style->dark_gc[state_type];
3667 gc2 = style->light_gc[state_type];
3668 gc3 = style->dark_gc[state_type];
3669 gc4 = style->light_gc[state_type];
3671 case GTK_SHADOW_OUT:
3672 gc1 = style->light_gc[state_type];
3673 gc2 = style->bg_gc[state_type];
3674 gc3 = style->dark_gc[state_type];
3675 gc4 = style->black_gc;
3677 case GTK_SHADOW_ETCHED_OUT:
3678 gc1 = style->light_gc[state_type];
3679 gc2 = style->dark_gc[state_type];
3680 gc3 = style->light_gc[state_type];
3681 gc4 = style->dark_gc[state_type];
3687 gdk_gc_set_clip_rectangle (gc1, area);
3688 gdk_gc_set_clip_rectangle (gc2, area);
3689 gdk_gc_set_clip_rectangle (gc3, area);
3690 gdk_gc_set_clip_rectangle (gc4, area);
3693 switch (shadow_type)
3695 case GTK_SHADOW_NONE:
3697 case GTK_SHADOW_OUT:
3698 case GTK_SHADOW_ETCHED_IN:
3699 case GTK_SHADOW_ETCHED_OUT:
3703 gdk_draw_line (window, gc1,
3704 x, y, x, y + height - 1);
3705 gdk_draw_line (window, gc2,
3706 x + 1, y, x + 1, y + height - 2);
3708 gdk_draw_line (window, gc3,
3709 x + 1, y + height - 2, x + width - 2, y + height - 2);
3710 gdk_draw_line (window, gc3,
3711 x + width - 2, y, x + width - 2, y + height - 2);
3712 gdk_draw_line (window, gc4,
3713 x, y + height - 1, x + width - 1, y + height - 1);
3714 gdk_draw_line (window, gc4,
3715 x + width - 1, y, x + width - 1, y + height - 1);
3718 gdk_draw_line (window, gc1,
3719 x, y, x + gap_x - 1, y);
3720 gdk_draw_line (window, gc2,
3721 x + 1, y + 1, x + gap_x - 1, y + 1);
3722 gdk_draw_line (window, gc2,
3723 x + gap_x, y, x + gap_x, y);
3725 if ((width - (gap_x + gap_width)) > 0)
3727 gdk_draw_line (window, gc1,
3728 x + gap_x + gap_width, y, x + width - 2, y);
3729 gdk_draw_line (window, gc2,
3730 x + gap_x + gap_width, y + 1, x + width - 2, y + 1);
3731 gdk_draw_line (window, gc2,
3732 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
3735 case GTK_POS_BOTTOM:
3736 gdk_draw_line (window, gc1,
3737 x, y, x + width - 1, y);
3738 gdk_draw_line (window, gc1,
3739 x, y, x, y + height - 1);
3740 gdk_draw_line (window, gc2,
3741 x + 1, y + 1, x + width - 2, y + 1);
3742 gdk_draw_line (window, gc2,
3743 x + 1, y + 1, x + 1, y + height - 1);
3745 gdk_draw_line (window, gc3,
3746 x + width - 2, y + 1, x + width - 2, y + height - 1);
3747 gdk_draw_line (window, gc4,
3748 x + width - 1, y, x + width - 1, y + height - 1);
3751 gdk_draw_line (window, gc4,
3752 x, y + height - 1, x + gap_x - 1, y + height - 1);
3753 gdk_draw_line (window, gc3,
3754 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
3755 gdk_draw_line (window, gc3,
3756 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
3758 if ((width - (gap_x + gap_width)) > 0)
3760 gdk_draw_line (window, gc4,
3761 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
3762 gdk_draw_line (window, gc3,
3763 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
3764 gdk_draw_line (window, gc3,
3765 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
3769 gdk_draw_line (window, gc1,
3770 x, y, x + width - 1, y);
3771 gdk_draw_line (window, gc2,
3772 x, y + 1, x + width - 2, y + 1);
3774 gdk_draw_line (window, gc3,
3775 x, y + height - 2, x + width - 2, y + height - 2);
3776 gdk_draw_line (window, gc3,
3777 x + width - 2, y + 1, x + width - 2, y + height - 2);
3778 gdk_draw_line (window, gc4,
3779 x, y + height - 1, x + width - 1, y + height - 1);
3780 gdk_draw_line (window, gc4,
3781 x + width - 1, y, x + width - 1, y + height - 1);
3784 gdk_draw_line (window, gc1,
3785 x, y, x, y + gap_x - 1);
3786 gdk_draw_line (window, gc2,
3787 x + 1, y + 1, x + 1, y + gap_x - 1);
3788 gdk_draw_line (window, gc2,
3789 x, y + gap_x, x, y + gap_x);
3791 if ((width - (gap_x + gap_width)) > 0)
3793 gdk_draw_line (window, gc1,
3794 x, y + gap_x + gap_width, x, y + height - 2);
3795 gdk_draw_line (window, gc2,
3796 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
3797 gdk_draw_line (window, gc2,
3798 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
3802 gdk_draw_line (window, gc1,
3803 x, y, x + width - 1, y);
3804 gdk_draw_line (window, gc1,
3805 x, y, x, y + height - 1);
3806 gdk_draw_line (window, gc2,
3807 x + 1, y + 1, x + width - 1, y + 1);
3808 gdk_draw_line (window, gc2,
3809 x + 1, y + 1, x + 1, y + height - 2);
3811 gdk_draw_line (window, gc3,
3812 x + 1, y + height - 2, x + width - 1, y + height - 2);
3813 gdk_draw_line (window, gc4,
3814 x, y + height - 1, x + width - 1, y + height - 1);
3817 gdk_draw_line (window, gc4,
3818 x + width - 1, y, x + width - 1, y + gap_x - 1);
3819 gdk_draw_line (window, gc3,
3820 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
3821 gdk_draw_line (window, gc3,
3822 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
3824 if ((width - (gap_x + gap_width)) > 0)
3826 gdk_draw_line (window, gc4,
3827 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
3828 gdk_draw_line (window, gc3,
3829 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
3830 gdk_draw_line (window, gc3,
3831 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
3839 gdk_gc_set_clip_rectangle (gc1, NULL);
3840 gdk_gc_set_clip_rectangle (gc2, NULL);
3841 gdk_gc_set_clip_rectangle (gc3, NULL);
3842 gdk_gc_set_clip_rectangle (gc4, NULL);
3847 gtk_default_draw_extension (GtkStyle *style,
3849 GtkStateType state_type,
3850 GtkShadowType shadow_type,
3853 const gchar *detail,
3858 GtkPositionType gap_side)
3865 g_return_if_fail (GTK_IS_STYLE (style));
3866 g_return_if_fail (window != NULL);
3868 gtk_style_apply_default_background (style, window,
3869 widget && !GTK_WIDGET_NO_WINDOW (widget),
3870 GTK_STATE_NORMAL, area, x, y, width, height);
3872 sanitize_size (window, &width, &height);
3874 switch (shadow_type)
3876 case GTK_SHADOW_NONE:
3879 gc1 = style->dark_gc[state_type];
3880 gc2 = style->black_gc;
3881 gc3 = style->bg_gc[state_type];
3882 gc4 = style->light_gc[state_type];
3884 case GTK_SHADOW_ETCHED_IN:
3885 gc1 = style->dark_gc[state_type];
3886 gc2 = style->light_gc[state_type];
3887 gc3 = style->dark_gc[state_type];
3888 gc4 = style->light_gc[state_type];
3890 case GTK_SHADOW_OUT:
3891 gc1 = style->light_gc[state_type];
3892 gc2 = style->bg_gc[state_type];
3893 gc3 = style->dark_gc[state_type];
3894 gc4 = style->black_gc;
3896 case GTK_SHADOW_ETCHED_OUT:
3897 gc1 = style->light_gc[state_type];
3898 gc2 = style->dark_gc[state_type];
3899 gc3 = style->light_gc[state_type];
3900 gc4 = style->dark_gc[state_type];
3906 gdk_gc_set_clip_rectangle (gc1, area);
3907 gdk_gc_set_clip_rectangle (gc2, area);
3908 gdk_gc_set_clip_rectangle (gc3, area);
3909 gdk_gc_set_clip_rectangle (gc4, area);
3912 switch (shadow_type)
3914 case GTK_SHADOW_NONE:
3916 case GTK_SHADOW_OUT:
3917 case GTK_SHADOW_ETCHED_IN:
3918 case GTK_SHADOW_ETCHED_OUT:
3922 gtk_style_apply_default_background (style, window,
3923 widget && !GTK_WIDGET_NO_WINDOW (widget),
3925 x + style->xthickness,
3927 width - (2 * style->xthickness),
3928 height - (style->ythickness));
3929 gdk_draw_line (window, gc1,
3930 x, y, x, y + height - 2);
3931 gdk_draw_line (window, gc2,
3932 x + 1, y, x + 1, y + height - 2);
3934 gdk_draw_line (window, gc3,
3935 x + 2, y + height - 2, x + width - 2, y + height - 2);
3936 gdk_draw_line (window, gc3,
3937 x + width - 2, y, x + width - 2, y + height - 2);
3938 gdk_draw_line (window, gc4,
3939 x + 1, y + height - 1, x + width - 2, y + height - 1);
3940 gdk_draw_line (window, gc4,
3941 x + width - 1, y, x + width - 1, y + height - 2);
3943 case GTK_POS_BOTTOM:
3944 gtk_style_apply_default_background (style, window,
3945 widget && !GTK_WIDGET_NO_WINDOW (widget),
3947 x + style->xthickness,
3948 y + style->ythickness,
3949 width - (2 * style->xthickness),
3950 height - (style->ythickness));
3951 gdk_draw_line (window, gc1,
3952 x + 1, y, x + width - 2, y);
3953 gdk_draw_line (window, gc1,
3954 x, y + 1, x, y + height - 1);
3955 gdk_draw_line (window, gc2,
3956 x + 1, y + 1, x + width - 2, y + 1);
3957 gdk_draw_line (window, gc2,
3958 x + 1, y + 1, x + 1, y + height - 1);
3960 gdk_draw_line (window, gc3,
3961 x + width - 2, y + 2, x + width - 2, y + height - 1);
3962 gdk_draw_line (window, gc4,
3963 x + width - 1, y + 1, x + width - 1, y + height - 1);
3966 gtk_style_apply_default_background (style, window,
3967 widget && !GTK_WIDGET_NO_WINDOW (widget),
3970 y + style->ythickness,
3971 width - (style->xthickness),
3972 height - (2 * style->ythickness));
3973 gdk_draw_line (window, gc1,
3974 x, y, x + width - 2, y);
3975 gdk_draw_line (window, gc2,
3976 x + 1, y + 1, x + width - 2, y + 1);
3978 gdk_draw_line (window, gc3,
3979 x, y + height - 2, x + width - 2, y + height - 2);
3980 gdk_draw_line (window, gc3,
3981 x + width - 2, y + 2, x + width - 2, y + height - 2);
3982 gdk_draw_line (window, gc4,
3983 x, y + height - 1, x + width - 2, y + height - 1);
3984 gdk_draw_line (window, gc4,
3985 x + width - 1, y + 1, x + width - 1, y + height - 2);
3988 gtk_style_apply_default_background (style, window,
3989 widget && !GTK_WIDGET_NO_WINDOW (widget),
3991 x + style->xthickness,
3992 y + style->ythickness,
3993 width - (style->xthickness),
3994 height - (2 * style->ythickness));
3995 gdk_draw_line (window, gc1,
3996 x + 1, y, x + width - 1, y);
3997 gdk_draw_line (window, gc1,
3998 x, y + 1, x, y + height - 2);
3999 gdk_draw_line (window, gc2,
4000 x + 1, y + 1, x + width - 1, y + 1);
4001 gdk_draw_line (window, gc2,
4002 x + 1, y + 1, x + 1, y + height - 2);
4004 gdk_draw_line (window, gc3,
4005 x + 2, y + height - 2, x + width - 1, y + height - 2);
4006 gdk_draw_line (window, gc4,
4007 x + 1, y + height - 1, x + width - 1, y + height - 1);
4014 gdk_gc_set_clip_rectangle (gc1, NULL);
4015 gdk_gc_set_clip_rectangle (gc2, NULL);
4016 gdk_gc_set_clip_rectangle (gc3, NULL);
4017 gdk_gc_set_clip_rectangle (gc4, NULL);
4022 gtk_default_draw_focus (GtkStyle *style,
4024 GtkStateType state_type,
4027 const gchar *detail,
4035 gboolean free_dash_list = FALSE;
4036 gint line_width = 1;
4037 gchar *dash_list = "\1\1";
4040 gc = style->fg_gc[state_type];
4044 gtk_widget_style_get (widget,
4045 "focus-line-width", &line_width,
4046 "focus-line-pattern", (gchar *)&dash_list,
4049 free_dash_list = TRUE;
4052 sanitize_size (window, &width, &height);
4055 gdk_gc_set_clip_rectangle (gc, area);
4057 gdk_gc_set_line_attributes (gc, line_width,
4058 dash_list[0] ? GDK_LINE_ON_OFF_DASH : GDK_LINE_SOLID,
4059 GDK_CAP_BUTT, GDK_JOIN_MITER);
4062 if (detail && !strcmp (detail, "add-mode"))
4068 free_dash_list = FALSE;
4071 points[0].x = x + line_width / 2;
4072 points[0].y = y + line_width / 2;
4073 points[1].x = x + width - line_width + line_width / 2;
4074 points[1].y = y + line_width / 2;
4075 points[2].x = x + width - line_width + line_width / 2;
4076 points[2].y = y + height - line_width + line_width / 2;
4077 points[3].x = x + line_width / 2;
4078 points[3].y = y + height - line_width + line_width / 2;
4079 points[4] = points[0];
4083 gdk_draw_lines (window, gc, points, 5);
4087 /* We go through all the pain below because the X rasterization
4088 * rules don't really work right for dashed lines if you
4089 * want continuity in segments that go between top/right
4090 * and left/bottom. For instance, a top left corner
4091 * with a 1-1 dash is drawn as:
4098 * This is because pixels on the top and left boundaries
4099 * of polygons are drawn, but not on the bottom and right.
4100 * So, if you have a line going up that turns the corner
4101 * and goes right, there is a one pixel shift in the pattern.
4103 * So, to fix this, we drawn the top and right in one call,
4104 * then the left and bottom in another call, fixing up
4105 * the dash offset for the second call ourselves to get
4106 * continuity at the upper left.
4108 * It's not perfect since we really should have a join at
4109 * the upper left and lower right instead of two intersecting
4110 * lines but that's only really apparent for no-dashes,
4111 * which (for this reason) are done as one polygon and
4112 * don't to through this code path.
4115 dash_len = strlen (dash_list);
4118 gdk_gc_set_dashes (gc, 0, dash_list, dash_len);
4120 gdk_draw_lines (window, gc, points, 3);
4122 /* We draw this line one farther over than it is "supposed" to
4123 * because of another rasterization problem ... if two 1 pixel
4124 * unjoined lines meet at the lower right, there will be a missing
4131 gint dash_pixels = 0;
4134 /* Adjust the dash offset for the bottom and left so we
4135 * match up at the upper left.
4137 for (i = 0; i < dash_len; i++)
4138 dash_pixels += dash_list[i];
4140 if (dash_len % 2 == 1)
4143 gdk_gc_set_dashes (gc, dash_pixels - (width + height - 2 * line_width) % dash_pixels, dash_list, dash_len);
4146 gdk_draw_lines (window, gc, points + 2, 3);
4149 gdk_gc_set_line_attributes (gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
4152 gdk_gc_set_clip_rectangle (gc, NULL);
4159 gtk_default_draw_slider (GtkStyle *style,
4161 GtkStateType state_type,
4162 GtkShadowType shadow_type,
4165 const gchar *detail,
4170 GtkOrientation orientation)
4172 g_return_if_fail (GTK_IS_STYLE (style));
4173 g_return_if_fail (window != NULL);
4175 sanitize_size (window, &width, &height);
4177 gtk_paint_box (style, window, state_type, shadow_type,
4178 area, widget, detail, x, y, width, height);
4181 (strcmp ("hscale", detail) == 0 ||
4182 strcmp ("vscale", detail) == 0))
4184 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4185 gtk_paint_vline (style, window, state_type, area, widget, detail,
4186 y + style->ythickness,
4187 y + height - style->ythickness - 1, x + width / 2);
4189 gtk_paint_hline (style, window, state_type, area, widget, detail,
4190 x + style->xthickness,
4191 x + width - style->xthickness - 1, y + height / 2);
4196 draw_dot (GdkWindow *window,
4204 size = CLAMP (size, 2, 3);
4208 gdk_draw_point (window, light_gc, x, y);
4209 gdk_draw_point (window, light_gc, x+1, y+1);
4211 else if (size == 3);
4213 gdk_draw_point (window, light_gc, x, y);
4214 gdk_draw_point (window, light_gc, x+1, y);
4215 gdk_draw_point (window, light_gc, x, y+1);
4216 gdk_draw_point (window, dark_gc, x+1, y+2);
4217 gdk_draw_point (window, dark_gc, x+2, y+1);
4218 gdk_draw_point (window, dark_gc, x+2, y+2);
4223 gtk_default_draw_handle (GtkStyle *style,
4225 GtkStateType state_type,
4226 GtkShadowType shadow_type,
4229 const gchar *detail,
4234 GtkOrientation orientation)
4237 gint xthick, ythick;
4238 GdkGC *light_gc, *dark_gc;
4243 g_return_if_fail (GTK_IS_STYLE (style));
4244 g_return_if_fail (window != NULL);
4246 sanitize_size (window, &width, &height);
4248 gtk_paint_box (style, window, state_type, shadow_type, area, widget,
4249 detail, x, y, width, height);
4252 if (!strcmp (detail, "paned"))
4254 /* we want to ignore the shadow border in paned widgets */
4258 light_gc = style->light_gc[state_type];
4259 dark_gc = style->black_gc;
4263 xthick = style->xthickness;
4264 ythick = style->ythickness;
4266 light_gc = style->light_gc[state_type];
4267 dark_gc = style->dark_gc[state_type];
4270 rect.x = x + xthick;
4271 rect.y = y + ythick;
4272 rect.width = width - (xthick * 2);
4273 rect.height = height - (ythick * 2);
4276 intersect = gdk_rectangle_intersect (area, &rect, &dest);
4286 gdk_gc_set_clip_rectangle (light_gc, &dest);
4287 gdk_gc_set_clip_rectangle (dark_gc, &dest);
4289 if (!strcmp (detail, "paned"))
4291 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4292 for (xx = x + width/2 - 15; xx <= x + width/2 + 15; xx += 5)
4293 draw_dot (window, light_gc, dark_gc, xx, y + height/2 - 1, 3);
4295 for (yy = y + height/2 - 15; yy <= y + height/2 + 15; yy += 5)
4296 draw_dot (window, light_gc, dark_gc, x + width/2 - 1, yy, 3);
4300 for (yy = y + ythick; yy < (y + height - ythick); yy += 3)
4301 for (xx = x + xthick; xx < (x + width - xthick); xx += 6)
4303 draw_dot (window, light_gc, dark_gc, xx, yy, 2);
4304 draw_dot (window, light_gc, dark_gc, xx + 3, yy + 1, 2);
4308 gdk_gc_set_clip_rectangle (light_gc, NULL);
4309 gdk_gc_set_clip_rectangle (dark_gc, NULL);
4313 create_expander_affine (gdouble affine[6],
4323 width = expander_size / 4.0;
4324 height = expander_size / 2.0;
4326 s = sin (degrees * G_PI / 180.0);
4327 c = cos (degrees * G_PI / 180.0);
4333 affine[4] = -width * c - height * -s + x;
4334 affine[5] = -width * s - height * c + y;
4338 apply_affine_on_point (double affine[6], GdkPoint *point)
4342 x = point->x * affine[0] + point->y * affine[2] + affine[4];
4343 y = point->x * affine[1] + point->y * affine[3] + affine[5];
4350 gtk_style_draw_polygon_with_gc (GdkWindow *window, GdkGC *gc, gint line_width,
4351 gboolean do_fill, GdkPoint *points, gint n_points)
4353 gdk_gc_set_line_attributes (gc, line_width,
4355 GDK_CAP_BUTT, GDK_JOIN_MITER);
4357 gdk_draw_polygon (window, gc, do_fill, points, n_points);
4358 gdk_gc_set_line_attributes (gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
4362 gtk_default_draw_expander (GtkStyle *style,
4364 GtkStateType state_type,
4367 const gchar *detail,
4370 GtkExpanderStyle expander_style)
4379 gtk_widget_style_get (widget,
4380 "expander_size", &expander_size,
4382 line_width = MAX (1, expander_size/7);
4386 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], area);
4387 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], area);
4390 expander_size -= (line_width * 2 - 2);
4391 points[0].x = line_width / 2;
4392 points[0].y = line_width / 2;
4393 points[1].x = expander_size / 2 + line_width / 2;
4394 points[1].y = expander_size / 2 + line_width / 2;
4395 points[2].x = line_width / 2;
4396 points[2].y = expander_size + line_width / 2;
4398 switch (expander_style)
4400 case GTK_EXPANDER_COLLAPSED:
4401 degrees = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ? 180 : 0;
4403 case GTK_EXPANDER_SEMI_COLLAPSED:
4404 degrees = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ? 150 : 30;
4406 case GTK_EXPANDER_SEMI_EXPANDED:
4407 degrees = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ? 120 : 60;
4409 case GTK_EXPANDER_EXPANDED:
4413 g_assert_not_reached ();
4416 create_expander_affine (affine, degrees, expander_size, x, y);
4418 for (i = 0; i < 3; i++)
4419 apply_affine_on_point (affine, &points[i]);
4421 if (state_type == GTK_STATE_PRELIGHT)
4423 gtk_style_draw_polygon_with_gc (window, style->fg_gc[GTK_STATE_NORMAL],
4424 1, TRUE, points, 3);
4426 else if (state_type == GTK_STATE_ACTIVE)
4428 gtk_style_draw_polygon_with_gc (window, style->light_gc[GTK_STATE_ACTIVE],
4429 1, TRUE, points, 3);
4430 gtk_style_draw_polygon_with_gc (window, style->fg_gc[GTK_STATE_NORMAL],
4431 line_width, FALSE, points, 3);
4435 gtk_style_draw_polygon_with_gc (window, style->base_gc[GTK_STATE_NORMAL],
4436 1, TRUE, points, 3);
4437 gtk_style_draw_polygon_with_gc (window, style->fg_gc[GTK_STATE_NORMAL],
4438 line_width, FALSE, points, 3);
4442 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], NULL);
4443 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], NULL);
4447 typedef struct _ByteRange ByteRange;
4456 range_new (guint start,
4459 ByteRange *br = g_new (ByteRange, 1);
4468 get_insensitive_layout (PangoLayout *layout)
4470 GSList *embossed_ranges = NULL;
4471 GSList *stippled_ranges = NULL;
4472 PangoLayoutIter *iter;
4473 GSList *tmp_list = NULL;
4474 PangoLayout *new_layout;
4475 PangoAttrList *attrs;
4476 GdkBitmap *stipple = NULL;
4478 iter = pango_layout_get_iter (layout);
4482 PangoLayoutRun *run;
4483 PangoAttribute *attr;
4484 gboolean need_stipple = FALSE;
4487 run = pango_layout_iter_get_run (iter);
4491 tmp_list = run->item->analysis.extra_attrs;
4493 while (tmp_list != NULL)
4495 attr = tmp_list->data;
4496 switch (attr->klass->type)
4498 case PANGO_ATTR_FOREGROUND:
4499 case PANGO_ATTR_BACKGROUND:
4500 need_stipple = TRUE;
4510 tmp_list = g_slist_next (tmp_list);
4513 br = range_new (run->item->offset, run->item->offset + run->item->length);
4516 stippled_ranges = g_slist_prepend (stippled_ranges, br);
4518 embossed_ranges = g_slist_prepend (embossed_ranges, br);
4521 while (pango_layout_iter_next_run (iter));
4523 pango_layout_iter_free (iter);
4525 new_layout = pango_layout_copy (layout);
4527 attrs = pango_layout_get_attributes (new_layout);
4531 /* Create attr list if there wasn't one */
4532 attrs = pango_attr_list_new ();
4533 pango_layout_set_attributes (new_layout, attrs);
4534 pango_attr_list_unref (attrs);
4537 tmp_list = embossed_ranges;
4538 while (tmp_list != NULL)
4540 PangoAttribute *attr;
4541 ByteRange *br = tmp_list->data;
4543 attr = gdk_pango_attr_embossed_new (TRUE);
4545 attr->start_index = br->start;
4546 attr->end_index = br->end;
4548 pango_attr_list_change (attrs, attr);
4552 tmp_list = g_slist_next (tmp_list);
4555 g_slist_free (embossed_ranges);
4557 tmp_list = stippled_ranges;
4558 while (tmp_list != NULL)
4560 PangoAttribute *attr;
4561 ByteRange *br = tmp_list->data;
4563 if (stipple == NULL)
4565 #define gray50_width 2
4566 #define gray50_height 2
4567 static char gray50_bits[] = {
4571 stipple = gdk_bitmap_create_from_data (NULL,
4572 gray50_bits, gray50_width,
4576 attr = gdk_pango_attr_stipple_new (stipple);
4578 attr->start_index = br->start;
4579 attr->end_index = br->end;
4581 pango_attr_list_change (attrs, attr);
4585 tmp_list = g_slist_next (tmp_list);
4588 g_slist_free (stippled_ranges);
4591 g_object_unref (G_OBJECT (stipple));
4597 gtk_default_draw_layout (GtkStyle *style,
4599 GtkStateType state_type,
4603 const gchar *detail,
4606 PangoLayout *layout)
4610 g_return_if_fail (GTK_IS_STYLE (style));
4611 g_return_if_fail (window != NULL);
4613 gc = use_text ? style->text_gc[state_type] : style->fg_gc[state_type];
4616 gdk_gc_set_clip_rectangle (gc, area);
4618 if (state_type == GTK_STATE_INSENSITIVE)
4622 ins = get_insensitive_layout (layout);
4624 gdk_draw_layout (window, gc, x, y, ins);
4626 g_object_unref (G_OBJECT (ins));
4630 gdk_draw_layout (window, gc, x, y, layout);
4634 gdk_gc_set_clip_rectangle (gc, NULL);
4638 gtk_default_draw_resize_grip (GtkStyle *style,
4640 GtkStateType state_type,
4643 const gchar *detail,
4650 g_return_if_fail (GTK_IS_STYLE (style));
4651 g_return_if_fail (window != NULL);
4655 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
4656 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
4657 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
4660 /* make it square, aligning to bottom right */
4663 y += (height - width);
4666 else if (height < width)
4668 x += (width - height);
4672 /* Clear background */
4673 gdk_draw_rectangle (window,
4674 style->bg_gc[state_type],
4676 x, y, width, height);
4680 case GDK_WINDOW_EDGE_SOUTH_EAST:
4687 while (xi < (x + width - 3))
4689 gdk_draw_line (window,
4690 style->light_gc[state_type],
4697 gdk_draw_line (window,
4698 style->dark_gc[state_type],
4705 gdk_draw_line (window,
4706 style->dark_gc[state_type],
4716 g_assert_not_reached ();
4722 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
4723 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
4724 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
4729 gtk_style_shade (GdkColor *a,
4737 red = (gdouble) a->red / 65535.0;
4738 green = (gdouble) a->green / 65535.0;
4739 blue = (gdouble) a->blue / 65535.0;
4741 rgb_to_hls (&red, &green, &blue);
4746 else if (green < 0.0)
4752 else if (blue < 0.0)
4755 hls_to_rgb (&red, &green, &blue);
4757 b->red = red * 65535.0;
4758 b->green = green * 65535.0;
4759 b->blue = blue * 65535.0;
4763 rgb_to_hls (gdouble *r,
4804 l = (max + min) / 2;
4811 s = (max - min) / (max + min);
4813 s = (max - min) / (2 - max - min);
4817 h = (green - blue) / delta;
4818 else if (green == max)
4819 h = 2 + (blue - red) / delta;
4820 else if (blue == max)
4821 h = 4 + (red - green) / delta;
4834 hls_to_rgb (gdouble *h,
4847 if (lightness <= 0.5)
4848 m2 = lightness * (1 + saturation);
4850 m2 = lightness + saturation - lightness * saturation;
4851 m1 = 2 * lightness - m2;
4853 if (saturation == 0)
4868 r = m1 + (m2 - m1) * hue / 60;
4872 r = m1 + (m2 - m1) * (240 - hue) / 60;
4883 g = m1 + (m2 - m1) * hue / 60;
4887 g = m1 + (m2 - m1) * (240 - hue) / 60;
4898 b = m1 + (m2 - m1) * hue / 60;
4902 b = m1 + (m2 - m1) * (240 - hue) / 60;
4915 * @style: a #GtkStyle
4916 * @window: a #GdkWindow
4917 * @state_type: a state
4918 * @area: rectangle to which the output is clipped
4921 * @x1: the starting x coordinate
4922 * @x2: the ending x coordinate
4923 * @y: the y coordinate
4925 * Draws a horizontal line from (@x1, @y) to (@x2, @y) in @window
4926 * using the given style and state.
4929 gtk_paint_hline (GtkStyle *style,
4931 GtkStateType state_type,
4934 const gchar *detail,
4939 g_return_if_fail (GTK_IS_STYLE (style));
4940 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
4942 GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, area, widget, detail, x1, x2, y);
4947 * @style: a #GtkStyle
4948 * @window: a #GdkWindow
4949 * @state_type: a state
4950 * @area: rectangle to which the output is clipped
4953 * @y1: the starting y coordinate
4954 * @y2: the ending y coordinate
4955 * @x: the x coordinate
4957 * Draws a vertical line from (@x, @y1) to (@x, @y1) in @window
4958 * using the given style and state.
4961 gtk_paint_vline (GtkStyle *style,
4963 GtkStateType state_type,
4966 const gchar *detail,
4971 g_return_if_fail (GTK_IS_STYLE (style));
4972 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
4974 GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, area, widget, detail, y1, y2, x);
4978 gtk_paint_shadow (GtkStyle *style,
4980 GtkStateType state_type,
4981 GtkShadowType shadow_type,
4984 const gchar *detail,
4990 g_return_if_fail (GTK_IS_STYLE (style));
4991 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
4993 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4997 gtk_paint_polygon (GtkStyle *style,
4999 GtkStateType state_type,
5000 GtkShadowType shadow_type,
5003 const gchar *detail,
5008 g_return_if_fail (GTK_IS_STYLE (style));
5009 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
5011 GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, area, widget, detail, points, npoints, fill);
5015 gtk_paint_arrow (GtkStyle *style,
5017 GtkStateType state_type,
5018 GtkShadowType shadow_type,
5021 const gchar *detail,
5022 GtkArrowType arrow_type,
5029 g_return_if_fail (GTK_IS_STYLE (style));
5030 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
5032 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, area, widget, detail, arrow_type, fill, x, y, width, height);
5036 gtk_paint_diamond (GtkStyle *style,
5038 GtkStateType state_type,
5039 GtkShadowType shadow_type,
5042 const gchar *detail,
5048 g_return_if_fail (GTK_IS_STYLE (style));
5049 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
5051 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5056 * @style: a #GtkStyle
5057 * @window: a #GdkWindow
5058 * @state_type: a state
5059 * @area: clip rectangle
5060 * @widget: the widget
5061 * @detail: a style detail
5064 * @string: the string to draw
5066 * Draws a text string on @window with the given parameters.
5068 * This function is deprecated, use gtk_paint_layout() instead.
5071 gtk_paint_string (GtkStyle *style,
5073 GtkStateType state_type,
5076 const gchar *detail,
5079 const gchar *string)
5081 g_return_if_fail (GTK_IS_STYLE (style));
5082 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
5084 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, area, widget, detail, x, y, string);
5088 gtk_paint_box (GtkStyle *style,
5090 GtkStateType state_type,
5091 GtkShadowType shadow_type,
5094 const gchar *detail,
5100 g_return_if_fail (GTK_IS_STYLE (style));
5101 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
5103 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5107 gtk_paint_flat_box (GtkStyle *style,
5109 GtkStateType state_type,
5110 GtkShadowType shadow_type,
5113 const gchar *detail,
5119 g_return_if_fail (GTK_IS_STYLE (style));
5120 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
5122 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5126 gtk_paint_check (GtkStyle *style,
5128 GtkStateType state_type,
5129 GtkShadowType shadow_type,
5132 const gchar *detail,
5138 g_return_if_fail (GTK_IS_STYLE (style));
5139 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
5141 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5145 gtk_paint_option (GtkStyle *style,
5147 GtkStateType state_type,
5148 GtkShadowType shadow_type,
5151 const gchar *detail,
5157 g_return_if_fail (GTK_IS_STYLE (style));
5158 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
5160 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5164 gtk_paint_tab (GtkStyle *style,
5166 GtkStateType state_type,
5167 GtkShadowType shadow_type,
5170 const gchar *detail,
5176 g_return_if_fail (GTK_IS_STYLE (style));
5177 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
5179 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5183 gtk_paint_shadow_gap (GtkStyle *style,
5185 GtkStateType state_type,
5186 GtkShadowType shadow_type,
5194 GtkPositionType gap_side,
5198 g_return_if_fail (GTK_IS_STYLE (style));
5199 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
5201 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);
5206 gtk_paint_box_gap (GtkStyle *style,
5208 GtkStateType state_type,
5209 GtkShadowType shadow_type,
5217 GtkPositionType gap_side,
5221 g_return_if_fail (GTK_IS_STYLE (style));
5222 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
5224 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);
5228 gtk_paint_extension (GtkStyle *style,
5230 GtkStateType state_type,
5231 GtkShadowType shadow_type,
5239 GtkPositionType gap_side)
5241 g_return_if_fail (GTK_IS_STYLE (style));
5242 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
5244 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, gap_side);
5248 gtk_paint_focus (GtkStyle *style,
5250 GtkStateType state_type,
5253 const gchar *detail,
5259 g_return_if_fail (GTK_IS_STYLE (style));
5260 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
5262 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, state_type, area, widget, detail, x, y, width, height);
5266 gtk_paint_slider (GtkStyle *style,
5268 GtkStateType state_type,
5269 GtkShadowType shadow_type,
5272 const gchar *detail,
5277 GtkOrientation orientation)
5279 g_return_if_fail (GTK_IS_STYLE (style));
5280 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
5282 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
5286 gtk_paint_handle (GtkStyle *style,
5288 GtkStateType state_type,
5289 GtkShadowType shadow_type,
5292 const gchar *detail,
5297 GtkOrientation orientation)
5299 g_return_if_fail (GTK_IS_STYLE (style));
5300 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
5302 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
5306 gtk_paint_expander (GtkStyle *style,
5308 GtkStateType state_type,
5311 const gchar *detail,
5314 GtkExpanderStyle expander_style)
5316 g_return_if_fail (GTK_IS_STYLE (style));
5317 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
5319 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type, area,
5320 widget, detail, x, y, expander_style);
5324 gtk_paint_layout (GtkStyle *style,
5326 GtkStateType state_type,
5330 const gchar *detail,
5333 PangoLayout *layout)
5335 g_return_if_fail (GTK_IS_STYLE (style));
5336 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
5338 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, use_text, area,
5339 widget, detail, x, y, layout);
5343 gtk_paint_resize_grip (GtkStyle *style,
5345 GtkStateType state_type,
5348 const gchar *detail,
5356 g_return_if_fail (GTK_IS_STYLE (style));
5357 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
5359 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, window, state_type,
5360 area, widget, detail,
5361 edge, x, y, width, height);
5366 * @border: a #GtkBorder.
5367 * @returns: a copy of @border.
5369 * Copies a #GtkBorder structure.
5372 gtk_border_copy (const GtkBorder *border)
5374 return (GtkBorder *)g_memdup (border, sizeof (GtkBorder));
5379 * @border: a #GtkBorder.
5381 * Frees a #GtkBorder structure.
5384 gtk_border_free (GtkBorder *border)
5390 * gtk_style_get_font:
5391 * @style: a #GtkStyle
5393 * Gets the #GdkFont to use for the given style. This is
5394 * meant only as a replacement for direct access to @style->font
5395 * and should not be used in new code. New code should
5396 * use @style->font_desc instead.
5398 * Return value: the #GdkFont for the style. This font is owned
5399 * by the style; if you want to keep around a copy, you must
5400 * call gdk_font_ref().
5403 gtk_style_get_font (GtkStyle *style)
5405 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
5407 if (style->private_font && style->private_font_desc)
5409 if (!style->font_desc ||
5410 !pango_font_description_equal (style->private_font_desc, style->font_desc))
5412 gdk_font_unref (style->private_font);
5413 style->private_font = NULL;
5415 if (style->private_font_desc)
5417 pango_font_description_free (style->private_font_desc);
5418 style->private_font_desc = NULL;
5423 if (!style->private_font)
5425 if (style->font_desc)
5427 style->private_font = gdk_font_from_description (style->font_desc);
5428 style->private_font_desc = pango_font_description_copy (style->font_desc);
5431 if (!style->private_font)
5432 style->private_font = gdk_font_load ("fixed");
5434 if (!style->private_font)
5435 g_error ("Unable to load \"fixed\" font");
5438 return style->private_font;
5442 * gtk_style_set_font:
5443 * @style: a #GtkStyle.
5444 * @font: a #GdkFont, or %NULL to use the #GdkFont corresponding
5445 * to style->font_desc.
5447 * Sets the #GdkFont to use for a given style. This is
5448 * meant only as a replacement for direct access to style->font
5449 * and should not be used in new code. New code should
5450 * use style->font_desc instead.
5453 gtk_style_set_font (GtkStyle *style,
5458 g_return_if_fail (GTK_IS_STYLE (style));
5460 old_font = style->private_font;
5462 style->private_font = font;
5464 gdk_font_ref (font);
5467 gdk_font_unref (old_font);
5469 if (style->private_font_desc)
5471 pango_font_description_free (style->private_font_desc);
5472 style->private_font_desc = NULL;
5477 * _gtk_draw_insertion_cursor:
5478 * @drawable: a #GdkDrawable
5480 * @location: location where to draw the cursor (@location->width is ignored)
5481 * @dir: text direction for the cursor, used to decide whether to draw a
5482 * directional arrow on the cursor and in what direction. Unless both
5483 * strong and weak cursors are displayed, this should be %GTK_TEXT_DIR_NONE.
5485 * Draws a text caret on @drawable at @location. This is not a style function
5486 * but merely a convenience function for drawing the standard cursor shape.
5489 _gtk_draw_insertion_cursor (GdkDrawable *drawable,
5491 GdkRectangle *location,
5492 GtkTextDirection dir)
5494 gint stem_width = location->height / 30 + 1;
5495 gint arrow_width = stem_width + 1;
5499 for (i = 0; i < stem_width; i++)
5500 gdk_draw_line (drawable, gc,
5501 location->x + i - stem_width / 2, location->y,
5502 location->x + i - stem_width / 2, location->y + location->height);
5504 if (dir == GTK_TEXT_DIR_RTL)
5506 x = location->x - stem_width / 2 - 1;
5507 y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
5509 for (i = 0; i < arrow_width; i++)
5511 gdk_draw_line (drawable, gc,
5513 x, y + 2 * arrow_width - i - 1);
5517 else if (dir == GTK_TEXT_DIR_LTR)
5519 x = location->x + stem_width - stem_width / 2;
5520 y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
5522 for (i = 0; i < arrow_width; i++)
5524 gdk_draw_line (drawable, gc,
5526 x, y + 2 * arrow_width - i - 1);