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 "gtkwidget.h"
33 #include "gtkthemes.h"
34 #include "gtkiconfactory.h"
36 #define LIGHTNESS_MULT 1.3
37 #define DARKNESS_MULT 0.7
39 /* actually glib should do that for us */
41 #define M_PI 3.14159265358979323846
44 #define M_PI_4 0.78539816339744830962
47 static void gtk_style_realize (GtkStyle *style,
48 GdkColormap *colormap);
50 static void gtk_style_real_realize (GtkStyle *style);
51 static void gtk_style_real_unrealize (GtkStyle *style);
52 static void gtk_style_real_copy (GtkStyle *style,
54 static void gtk_style_real_set_background (GtkStyle *style,
56 GtkStateType state_type);
57 static GtkStyle *gtk_style_real_clone (GtkStyle *style);
58 static void gtk_style_real_init_from_rc (GtkStyle *style,
59 GtkRcStyle *rc_style);
62 static GdkPixbuf *gtk_default_render_icon (GtkStyle *style,
63 const GtkIconSource *source,
64 GtkTextDirection direction,
70 static void gtk_default_draw_hline (GtkStyle *style,
72 GtkStateType state_type,
79 static void gtk_default_draw_vline (GtkStyle *style,
81 GtkStateType state_type,
88 static void gtk_default_draw_shadow (GtkStyle *style,
90 GtkStateType state_type,
91 GtkShadowType shadow_type,
99 static void gtk_default_draw_shadow (GtkStyle *style,
101 GtkStateType state_type,
102 GtkShadowType shadow_type,
110 static void gtk_default_draw_polygon (GtkStyle *style,
112 GtkStateType state_type,
113 GtkShadowType shadow_type,
120 static void gtk_default_draw_arrow (GtkStyle *style,
122 GtkStateType state_type,
123 GtkShadowType shadow_type,
127 GtkArrowType arrow_type,
133 static void gtk_default_draw_diamond (GtkStyle *style,
135 GtkStateType state_type,
136 GtkShadowType shadow_type,
144 static void gtk_default_draw_string (GtkStyle *style,
146 GtkStateType state_type,
152 const gchar *string);
153 static void gtk_default_draw_box (GtkStyle *style,
155 GtkStateType state_type,
156 GtkShadowType shadow_type,
164 static void gtk_default_draw_flat_box (GtkStyle *style,
166 GtkStateType state_type,
167 GtkShadowType shadow_type,
175 static void gtk_default_draw_check (GtkStyle *style,
177 GtkStateType state_type,
178 GtkShadowType shadow_type,
186 static void gtk_default_draw_option (GtkStyle *style,
188 GtkStateType state_type,
189 GtkShadowType shadow_type,
197 static void gtk_default_draw_tab (GtkStyle *style,
199 GtkStateType state_type,
200 GtkShadowType shadow_type,
208 static void gtk_default_draw_shadow_gap (GtkStyle *style,
210 GtkStateType state_type,
211 GtkShadowType shadow_type,
219 GtkPositionType gap_side,
222 static void gtk_default_draw_box_gap (GtkStyle *style,
224 GtkStateType state_type,
225 GtkShadowType shadow_type,
233 GtkPositionType gap_side,
236 static void gtk_default_draw_extension (GtkStyle *style,
238 GtkStateType state_type,
239 GtkShadowType shadow_type,
247 GtkPositionType gap_side);
248 static void gtk_default_draw_focus (GtkStyle *style,
257 static void gtk_default_draw_slider (GtkStyle *style,
259 GtkStateType state_type,
260 GtkShadowType shadow_type,
268 GtkOrientation orientation);
269 static void gtk_default_draw_handle (GtkStyle *style,
271 GtkStateType state_type,
272 GtkShadowType shadow_type,
280 GtkOrientation orientation);
281 static void gtk_default_draw_expander (GtkStyle *style,
283 GtkStateType state_type,
290 static void gtk_default_draw_layout (GtkStyle *style,
292 GtkStateType state_type,
298 PangoLayout *layout);
300 static void gtk_style_shade (GdkColor *a, GdkColor *b, gdouble k);
301 static void rgb_to_hls (gdouble *r, gdouble *g, gdouble *b);
302 static void hls_to_rgb (gdouble *h, gdouble *l, gdouble *s);
304 GdkFont *default_font = NULL;
306 static GdkColor gtk_default_normal_fg = { 0, 0, 0, 0 };
307 static GdkColor gtk_default_active_fg = { 0, 0, 0, 0 };
308 static GdkColor gtk_default_prelight_fg = { 0, 0, 0, 0 };
309 static GdkColor gtk_default_selected_fg = { 0, 0xffff, 0xffff, 0xffff };
310 static GdkColor gtk_default_insensitive_fg = { 0, 0x7530, 0x7530, 0x7530 };
312 static GdkColor gtk_default_normal_bg = { 0, 0xd6d6, 0xd6d6, 0xd6d6 };
313 static GdkColor gtk_default_active_bg = { 0, 0xc350, 0xc350, 0xc350 };
314 static GdkColor gtk_default_prelight_bg = { 0, 0xea60, 0xea60, 0xea60 };
315 static GdkColor gtk_default_selected_bg = { 0, 0, 0, 0x9c40 };
316 static GdkColor gtk_default_insensitive_bg = { 0, 0xd6d6, 0xd6d6, 0xd6d6 };
318 static gpointer parent_class = NULL;
320 static void gtk_style_init (GtkStyle *style);
321 static void gtk_style_class_init (GtkStyleClass *klass);
322 static void gtk_style_finalize (GObject *object);
325 gtk_style_get_type (void)
327 static GType object_type = 0;
331 static const GTypeInfo object_info =
333 sizeof (GtkStyleClass),
334 (GBaseInitFunc) NULL,
335 (GBaseFinalizeFunc) NULL,
336 (GClassInitFunc) gtk_style_class_init,
337 NULL, /* class_finalize */
338 NULL, /* class_data */
341 (GInstanceInitFunc) gtk_style_init,
344 object_type = g_type_register_static (G_TYPE_OBJECT,
353 gtk_style_init (GtkStyle *style)
357 style->font_desc = pango_font_description_from_string ("Sans 10");
361 default_font = gdk_font_from_description (style->font_desc);
364 default_font = gdk_font_load ("fixed");
367 g_error ("Unable to load \"fixed\" font!");
370 style->font = default_font;
371 gdk_font_ref (style->font);
373 style->attach_count = 0;
374 style->colormap = NULL;
377 style->black.red = 0;
378 style->black.green = 0;
379 style->black.blue = 0;
381 style->white.red = 65535;
382 style->white.green = 65535;
383 style->white.blue = 65535;
385 style->black_gc = NULL;
386 style->white_gc = NULL;
388 style->fg[GTK_STATE_NORMAL] = gtk_default_normal_fg;
389 style->fg[GTK_STATE_ACTIVE] = gtk_default_active_fg;
390 style->fg[GTK_STATE_PRELIGHT] = gtk_default_prelight_fg;
391 style->fg[GTK_STATE_SELECTED] = gtk_default_selected_fg;
392 style->fg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
394 style->bg[GTK_STATE_NORMAL] = gtk_default_normal_bg;
395 style->bg[GTK_STATE_ACTIVE] = gtk_default_active_bg;
396 style->bg[GTK_STATE_PRELIGHT] = gtk_default_prelight_bg;
397 style->bg[GTK_STATE_SELECTED] = gtk_default_selected_bg;
398 style->bg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_bg;
400 for (i = 0; i < 4; i++)
402 style->text[i] = style->fg[i];
403 style->base[i] = style->white;
406 style->base[GTK_STATE_INSENSITIVE] = gtk_default_prelight_bg;
407 style->text[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
409 for (i = 0; i < 5; i++)
410 style->bg_pixmap[i] = NULL;
412 style->rc_style = NULL;
414 for (i = 0; i < 5; i++)
416 style->fg_gc[i] = NULL;
417 style->bg_gc[i] = NULL;
418 style->light_gc[i] = NULL;
419 style->dark_gc[i] = NULL;
420 style->mid_gc[i] = NULL;
421 style->text_gc[i] = NULL;
422 style->base_gc[i] = NULL;
425 style->xthickness = 2;
426 style->ythickness = 2;
430 gtk_style_class_init (GtkStyleClass *klass)
432 GObjectClass *object_class = G_OBJECT_CLASS (klass);
434 parent_class = g_type_class_peek_parent (klass);
436 object_class->finalize = gtk_style_finalize;
438 klass->clone = gtk_style_real_clone;
439 klass->copy = gtk_style_real_copy;
440 klass->init_from_rc = gtk_style_real_init_from_rc;
441 klass->realize = gtk_style_real_realize;
442 klass->unrealize = gtk_style_real_unrealize;
443 klass->set_background = gtk_style_real_set_background;
444 klass->render_icon = gtk_default_render_icon;
446 klass->draw_hline = gtk_default_draw_hline;
447 klass->draw_vline = gtk_default_draw_vline;
448 klass->draw_shadow = gtk_default_draw_shadow;
449 klass->draw_polygon = gtk_default_draw_polygon;
450 klass->draw_arrow = gtk_default_draw_arrow;
451 klass->draw_diamond = gtk_default_draw_diamond;
452 klass->draw_string = gtk_default_draw_string;
453 klass->draw_box = gtk_default_draw_box;
454 klass->draw_flat_box = gtk_default_draw_flat_box;
455 klass->draw_check = gtk_default_draw_check;
456 klass->draw_option = gtk_default_draw_option;
457 klass->draw_tab = gtk_default_draw_tab;
458 klass->draw_shadow_gap = gtk_default_draw_shadow_gap;
459 klass->draw_box_gap = gtk_default_draw_box_gap;
460 klass->draw_extension = gtk_default_draw_extension;
461 klass->draw_focus = gtk_default_draw_focus;
462 klass->draw_slider = gtk_default_draw_slider;
463 klass->draw_handle = gtk_default_draw_handle;
464 klass->draw_expander = gtk_default_draw_expander;
465 klass->draw_layout = gtk_default_draw_layout;
469 gtk_style_finalize (GObject *object)
471 GtkStyle *style = GTK_STYLE (object);
473 g_return_if_fail (style->attach_count == 0);
477 if (style->styles->data != style)
478 g_slist_remove (style->styles, style);
481 GSList *tmp_list = style->styles->next;
485 ((GtkStyle*) tmp_list->data)->styles = style->styles->next;
486 tmp_list = tmp_list->next;
488 g_slist_free_1 (style->styles);
492 gdk_font_unref (style->font);
493 pango_font_description_free (style->font_desc);
496 gtk_rc_style_unref (style->rc_style);
498 G_OBJECT_CLASS (parent_class)->finalize (object);
503 gtk_style_copy (GtkStyle *style)
507 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
509 new_style = GTK_STYLE_GET_CLASS (style)->clone (style);
510 GTK_STYLE_GET_CLASS (style)->copy (new_style, style);
516 gtk_style_duplicate (GtkStyle *style)
520 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
522 new_style = gtk_style_copy (style);
524 style->styles = g_slist_append (style->styles, new_style);
525 new_style->styles = style->styles;
535 style = g_object_new (GTK_TYPE_STYLE, NULL);
540 /*************************************************************
542 * Attach a style to a window; this process allocates the
543 * colors and creates the GC's for the style - it specializes
544 * it to a particular visual and colormap. The process
545 * may involve the creation of a new style if the style
546 * has already been attached to a window with a different
547 * style and colormap.
552 * Either the style parameter, or a newly created style.
553 * If the style is newly created, the style parameter
554 * will be dereferenced, and the new style will have
555 * a reference count belonging to the caller.
557 * FIXME: The sequence -
558 * create a style => s1
559 * attach s1 to v1, c1 => s1
560 * attach s1 to v2, c2 => s2
561 * detach s1 from v1, c1
562 * attach s1 to v2, c2 => s3
563 * results in two separate, unlinked styles s2 and s3 which
564 * are identical and could be shared. To fix this, we would
565 * want to never remove a style from the list of linked
566 * styles as long as as it has a reference count. However, the
567 * disadvantage of doing it this way means that we would need two
568 * passes through the linked list when attaching (one to check for
569 * matching styles, one to look for empty unattached styles - but
570 * it will almost never be longer than 2 elements.
571 *************************************************************/
574 gtk_style_attach (GtkStyle *style,
578 GtkStyle *new_style = NULL;
579 GdkColormap *colormap;
581 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
582 g_return_val_if_fail (window != NULL, NULL);
584 colormap = gdk_window_get_colormap (window);
587 style->styles = g_slist_append (NULL, style);
589 styles = style->styles;
592 new_style = styles->data;
594 if (new_style->attach_count == 0)
596 gtk_style_realize (new_style, colormap);
599 else if (new_style->colormap == colormap)
603 styles = styles->next;
608 new_style = gtk_style_duplicate (style);
609 gtk_style_realize (new_style, colormap);
612 /* A style gets a refcount from being attached */
613 if (new_style->attach_count == 0)
614 gtk_style_ref (new_style);
616 /* Another refcount belongs to the parent */
617 if (style != new_style)
619 gtk_style_unref (style);
620 gtk_style_ref (new_style);
623 new_style->attach_count++;
629 gtk_style_detach (GtkStyle *style)
631 g_return_if_fail (GTK_IS_STYLE (style));
633 style->attach_count -= 1;
634 if (style->attach_count == 0)
636 GTK_STYLE_GET_CLASS (style)->unrealize (style);
638 gdk_colormap_unref (style->colormap);
639 style->colormap = NULL;
641 gtk_style_unref (style);
646 gtk_style_ref (GtkStyle *style)
648 return (GtkStyle *) g_object_ref (G_OBJECT (style));
652 gtk_style_unref (GtkStyle *style)
654 g_object_unref (G_OBJECT (style));
658 gtk_style_realize (GtkStyle *style,
659 GdkColormap *colormap)
661 g_return_if_fail (GTK_IS_STYLE (style));
663 style->colormap = gdk_colormap_ref (colormap);
664 style->depth = gdk_colormap_get_visual (colormap)->depth;
666 GTK_STYLE_GET_CLASS (style)->realize (style);
670 gtk_style_lookup_icon_set (GtkStyle *style,
671 const char *stock_id)
675 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
676 g_return_val_if_fail (stock_id != NULL, NULL);
678 iter = style->icon_factories;
681 GtkIconSet *icon_set =
682 gtk_icon_factory_lookup (GTK_ICON_FACTORY (iter->data),
688 iter = g_slist_next (iter);
691 return gtk_icon_factory_lookup_default (stock_id);
695 gtk_draw_hline (GtkStyle *style,
697 GtkStateType state_type,
702 g_return_if_fail (GTK_IS_STYLE (style));
703 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
705 GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, NULL, NULL, NULL, x1, x2, y);
710 gtk_draw_vline (GtkStyle *style,
712 GtkStateType state_type,
717 g_return_if_fail (GTK_IS_STYLE (style));
718 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
720 GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, NULL, NULL, NULL, y1, y2, x);
725 gtk_draw_shadow (GtkStyle *style,
727 GtkStateType state_type,
728 GtkShadowType shadow_type,
734 g_return_if_fail (GTK_IS_STYLE (style));
735 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
737 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
741 gtk_draw_polygon (GtkStyle *style,
743 GtkStateType state_type,
744 GtkShadowType shadow_type,
749 g_return_if_fail (GTK_IS_STYLE (style));
750 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_polygon != NULL);
752 GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, NULL, NULL, NULL, points, npoints, fill);
756 gtk_draw_arrow (GtkStyle *style,
758 GtkStateType state_type,
759 GtkShadowType shadow_type,
760 GtkArrowType arrow_type,
767 g_return_if_fail (GTK_IS_STYLE (style));
768 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
770 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, NULL, NULL, NULL, arrow_type, fill, x, y, width, height);
775 gtk_draw_diamond (GtkStyle *style,
777 GtkStateType state_type,
778 GtkShadowType shadow_type,
784 g_return_if_fail (GTK_IS_STYLE (style));
785 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
787 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
792 gtk_draw_string (GtkStyle *style,
794 GtkStateType state_type,
799 g_return_if_fail (GTK_IS_STYLE (style));
800 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
802 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, NULL, NULL, NULL, x, y, string);
806 gtk_draw_box (GtkStyle *style,
808 GtkStateType state_type,
809 GtkShadowType shadow_type,
815 g_return_if_fail (GTK_IS_STYLE (style));
816 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
818 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
822 gtk_draw_flat_box (GtkStyle *style,
824 GtkStateType state_type,
825 GtkShadowType shadow_type,
831 g_return_if_fail (GTK_IS_STYLE (style));
832 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
834 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
838 gtk_draw_check (GtkStyle *style,
840 GtkStateType state_type,
841 GtkShadowType shadow_type,
847 g_return_if_fail (GTK_IS_STYLE (style));
848 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
850 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
854 gtk_draw_option (GtkStyle *style,
856 GtkStateType state_type,
857 GtkShadowType shadow_type,
863 g_return_if_fail (GTK_IS_STYLE (style));
864 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
866 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
870 gtk_draw_tab (GtkStyle *style,
872 GtkStateType state_type,
873 GtkShadowType shadow_type,
879 g_return_if_fail (GTK_IS_STYLE (style));
880 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
882 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
886 gtk_draw_shadow_gap (GtkStyle *style,
888 GtkStateType state_type,
889 GtkShadowType shadow_type,
894 GtkPositionType gap_side,
898 g_return_if_fail (GTK_IS_STYLE (style));
899 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
901 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);
905 gtk_draw_box_gap (GtkStyle *style,
907 GtkStateType state_type,
908 GtkShadowType shadow_type,
913 GtkPositionType gap_side,
917 g_return_if_fail (GTK_IS_STYLE (style));
918 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
920 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);
924 gtk_draw_extension (GtkStyle *style,
926 GtkStateType state_type,
927 GtkShadowType shadow_type,
932 GtkPositionType gap_side)
934 g_return_if_fail (GTK_IS_STYLE (style));
935 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
937 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, gap_side);
941 gtk_draw_focus (GtkStyle *style,
948 g_return_if_fail (GTK_IS_STYLE (style));
949 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
951 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, NULL, NULL, NULL, x, y, width, height);
955 gtk_draw_slider (GtkStyle *style,
957 GtkStateType state_type,
958 GtkShadowType shadow_type,
963 GtkOrientation orientation)
965 g_return_if_fail (GTK_IS_STYLE (style));
966 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
968 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
972 gtk_draw_handle (GtkStyle *style,
974 GtkStateType state_type,
975 GtkShadowType shadow_type,
980 GtkOrientation orientation)
982 g_return_if_fail (GTK_IS_STYLE (style));
983 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
985 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
989 gtk_draw_expander (GtkStyle *style,
991 GtkStateType state_type,
996 g_return_if_fail (GTK_IS_STYLE (style));
997 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
999 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type,
1005 gtk_draw_layout (GtkStyle *style,
1007 GtkStateType state_type,
1010 PangoLayout *layout)
1012 g_return_if_fail (GTK_IS_STYLE (style));
1013 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
1015 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type,
1021 gtk_style_set_background (GtkStyle *style,
1023 GtkStateType state_type)
1025 g_return_if_fail (GTK_IS_STYLE (style));
1026 g_return_if_fail (window != NULL);
1028 GTK_STYLE_GET_CLASS (style)->set_background (style, window, state_type);
1031 /* Default functions */
1033 gtk_style_real_clone (GtkStyle *style)
1035 return GTK_STYLE (g_object_new (G_OBJECT_TYPE (style), NULL));
1039 gtk_style_real_copy (GtkStyle *style,
1044 for (i = 0; i < 5; i++)
1046 style->fg[i] = src->fg[i];
1047 style->bg[i] = src->bg[i];
1048 style->text[i] = src->text[i];
1049 style->base[i] = src->base[i];
1051 style->bg_pixmap[i] = src->bg_pixmap[i];
1055 gdk_font_unref (style->font);
1056 style->font = src->font;
1058 gdk_font_ref (style->font);
1060 if (style->font_desc)
1061 pango_font_description_free (style->font_desc);
1063 style->font_desc = pango_font_description_copy (src->font_desc);
1065 style->font_desc = NULL;
1067 style->xthickness = src->xthickness;
1068 style->ythickness = src->ythickness;
1070 if (style->rc_style)
1071 gtk_rc_style_unref (style->rc_style);
1072 style->rc_style = src->rc_style;
1074 gtk_rc_style_ref (src->rc_style);
1078 gtk_style_real_init_from_rc (GtkStyle *style,
1079 GtkRcStyle *rc_style)
1084 if (rc_style->font_desc)
1086 pango_font_description_free (style->font_desc);
1087 style->font_desc = pango_font_description_copy (rc_style->font_desc);
1089 old_font = style->font;
1090 style->font = gdk_font_from_description (style->font_desc);
1092 gdk_font_unref (old_font);
1094 style->font = old_font;
1097 for (i = 0; i < 5; i++)
1099 if (rc_style->color_flags[i] & GTK_RC_FG)
1100 style->fg[i] = rc_style->fg[i];
1101 if (rc_style->color_flags[i] & GTK_RC_BG)
1102 style->bg[i] = rc_style->bg[i];
1103 if (rc_style->color_flags[i] & GTK_RC_TEXT)
1104 style->text[i] = rc_style->text[i];
1105 if (rc_style->color_flags[i] & GTK_RC_BASE)
1106 style->base[i] = rc_style->base[i];
1109 if (rc_style->xthickness >= 0)
1110 style->xthickness = rc_style->xthickness;
1111 if (rc_style->ythickness >= 0)
1112 style->ythickness = rc_style->ythickness;
1115 if (rc_style->icon_factories)
1119 style->icon_factories = g_slist_copy (rc_style->icon_factories);
1121 iter = style->icon_factories;
1122 while (iter != NULL)
1124 g_object_ref (G_OBJECT (iter->data));
1126 iter = g_slist_next (iter);
1132 gtk_style_real_realize (GtkStyle *style)
1134 GdkGCValues gc_values;
1135 GdkGCValuesMask gc_values_mask;
1139 for (i = 0; i < 5; i++)
1141 gtk_style_shade (&style->bg[i], &style->light[i], LIGHTNESS_MULT);
1142 gtk_style_shade (&style->bg[i], &style->dark[i], DARKNESS_MULT);
1144 style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
1145 style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
1146 style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
1149 gdk_color_black (style->colormap, &style->black);
1150 gdk_color_white (style->colormap, &style->white);
1152 gc_values_mask = GDK_GC_FOREGROUND | GDK_GC_FONT;
1153 if (style->font->type == GDK_FONT_FONT)
1155 gc_values.font = style->font;
1157 else if (style->font->type == GDK_FONT_FONTSET)
1159 gc_values.font = default_font;
1162 gc_values.foreground = style->black;
1163 style->black_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1165 gc_values.foreground = style->white;
1166 style->white_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1168 for (i = 0; i < 5; i++)
1170 if (style->rc_style && style->rc_style->bg_pixmap_name[i])
1171 style->bg_pixmap[i] = gtk_rc_load_image (style->colormap,
1173 style->rc_style->bg_pixmap_name[i]);
1175 if (!gdk_color_alloc (style->colormap, &style->fg[i]))
1176 g_warning ("unable to allocate color: ( %d %d %d )",
1177 style->fg[i].red, style->fg[i].green, style->fg[i].blue);
1178 if (!gdk_color_alloc (style->colormap, &style->bg[i]))
1179 g_warning ("unable to allocate color: ( %d %d %d )",
1180 style->bg[i].red, style->bg[i].green, style->bg[i].blue);
1181 if (!gdk_color_alloc (style->colormap, &style->light[i]))
1182 g_warning ("unable to allocate color: ( %d %d %d )",
1183 style->light[i].red, style->light[i].green, style->light[i].blue);
1184 if (!gdk_color_alloc (style->colormap, &style->dark[i]))
1185 g_warning ("unable to allocate color: ( %d %d %d )",
1186 style->dark[i].red, style->dark[i].green, style->dark[i].blue);
1187 if (!gdk_color_alloc (style->colormap, &style->mid[i]))
1188 g_warning ("unable to allocate color: ( %d %d %d )",
1189 style->mid[i].red, style->mid[i].green, style->mid[i].blue);
1190 if (!gdk_color_alloc (style->colormap, &style->text[i]))
1191 g_warning ("unable to allocate color: ( %d %d %d )",
1192 style->text[i].red, style->text[i].green, style->text[i].blue);
1193 if (!gdk_color_alloc (style->colormap, &style->base[i]))
1194 g_warning ("unable to allocate color: ( %d %d %d )",
1195 style->base[i].red, style->base[i].green, style->base[i].blue);
1197 gc_values.foreground = style->fg[i];
1198 style->fg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1200 gc_values.foreground = style->bg[i];
1201 style->bg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1203 gc_values.foreground = style->light[i];
1204 style->light_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1206 gc_values.foreground = style->dark[i];
1207 style->dark_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1209 gc_values.foreground = style->mid[i];
1210 style->mid_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1212 gc_values.foreground = style->text[i];
1213 style->text_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1215 gc_values.foreground = style->base[i];
1216 style->base_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1221 gtk_style_real_unrealize (GtkStyle *style)
1225 gtk_gc_release (style->black_gc);
1226 gtk_gc_release (style->white_gc);
1228 for (i = 0; i < 5; i++)
1230 gtk_gc_release (style->fg_gc[i]);
1231 gtk_gc_release (style->bg_gc[i]);
1232 gtk_gc_release (style->light_gc[i]);
1233 gtk_gc_release (style->dark_gc[i]);
1234 gtk_gc_release (style->mid_gc[i]);
1235 gtk_gc_release (style->text_gc[i]);
1236 gtk_gc_release (style->base_gc[i]);
1238 if (style->bg_pixmap[i] && style->bg_pixmap[i] != (GdkPixmap*) GDK_PARENT_RELATIVE)
1239 gdk_pixmap_unref (style->bg_pixmap[i]);
1242 gdk_colormap_free_colors (style->colormap, style->fg, 5);
1243 gdk_colormap_free_colors (style->colormap, style->bg, 5);
1244 gdk_colormap_free_colors (style->colormap, style->light, 5);
1245 gdk_colormap_free_colors (style->colormap, style->dark, 5);
1246 gdk_colormap_free_colors (style->colormap, style->mid, 5);
1247 gdk_colormap_free_colors (style->colormap, style->text, 5);
1248 gdk_colormap_free_colors (style->colormap, style->base, 5);
1252 gtk_style_real_set_background (GtkStyle *style,
1254 GtkStateType state_type)
1257 gint parent_relative;
1259 if (style->bg_pixmap[state_type])
1261 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1264 parent_relative = TRUE;
1268 pixmap = style->bg_pixmap[state_type];
1269 parent_relative = FALSE;
1272 gdk_window_set_back_pixmap (window, pixmap, parent_relative);
1275 gdk_window_set_background (window, &style->bg[state_type]);
1279 gtk_style_render_icon (GtkStyle *style,
1280 const GtkIconSource *source,
1281 GtkTextDirection direction,
1285 const gchar *detail)
1289 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1290 g_return_val_if_fail (GTK_STYLE_GET_CLASS (style)->render_icon != NULL, NULL);
1292 pixbuf = GTK_STYLE_GET_CLASS (style)->render_icon (style, source, direction, state,
1293 size, widget, detail);
1295 g_return_val_if_fail (pixbuf != NULL, NULL);
1300 /* Default functions */
1302 gtk_style_apply_default_background (GtkStyle *style,
1305 GtkStateType state_type,
1312 GdkRectangle new_rect, old_rect;
1318 old_rect.width = width;
1319 old_rect.height = height;
1321 if (!gdk_rectangle_intersect (area, &old_rect, &new_rect))
1328 new_rect.width = width;
1329 new_rect.height = height;
1332 if (!style->bg_pixmap[state_type] ||
1333 GDK_IS_PIXMAP (window) ||
1334 (!set_bg && style->bg_pixmap[state_type] != (GdkPixmap*) GDK_PARENT_RELATIVE))
1336 GdkGC *gc = style->bg_gc[state_type];
1338 if (style->bg_pixmap[state_type])
1340 gdk_gc_set_fill (gc, GDK_TILED);
1341 gdk_gc_set_tile (gc, style->bg_pixmap[state_type]);
1344 gdk_draw_rectangle (window, gc, TRUE,
1345 new_rect.x, new_rect.y, new_rect.width, new_rect.height);
1346 if (style->bg_pixmap[state_type])
1347 gdk_gc_set_fill (gc, GDK_SOLID);
1353 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1354 gdk_window_set_back_pixmap (window, NULL, TRUE);
1356 gdk_window_set_back_pixmap (window, style->bg_pixmap[state_type], FALSE);
1359 gdk_window_clear_area (window,
1360 new_rect.x, new_rect.y,
1361 new_rect.width, new_rect.height);
1366 scale_or_ref (GdkPixbuf *src,
1370 if (width == gdk_pixbuf_get_width (src) &&
1371 height == gdk_pixbuf_get_height (src))
1373 gdk_pixbuf_ref (src);
1378 return gdk_pixbuf_scale_simple (src,
1380 GDK_INTERP_BILINEAR);
1385 gtk_default_render_icon (GtkStyle *style,
1386 const GtkIconSource *source,
1387 GtkTextDirection direction,
1391 const gchar *detail)
1398 /* Oddly, style can be NULL in this function, because
1399 * GtkIconSet can be used without a style and if so
1400 * it uses this function.
1403 g_return_val_if_fail (source->pixbuf != NULL, NULL);
1405 if (!gtk_icon_size_lookup (size, &width, &height))
1407 g_warning ("Bad icon size '%s' passed to render_icon", size);
1411 /* If the size was wildcarded, then scale; otherwise, leave it
1414 if (source->any_size)
1415 scaled = scale_or_ref (source->pixbuf, width, height);
1417 scaled = GDK_PIXBUF (g_object_ref (G_OBJECT (source->pixbuf)));
1419 /* If the state was wildcarded, then generate a state. */
1420 if (source->any_state)
1422 if (state == GTK_STATE_INSENSITIVE)
1424 stated = gdk_pixbuf_copy (scaled);
1426 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
1429 gdk_pixbuf_unref (scaled);
1431 else if (state == GTK_STATE_PRELIGHT)
1433 stated = gdk_pixbuf_copy (scaled);
1435 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
1438 gdk_pixbuf_unref (scaled);
1452 gtk_default_draw_hline (GtkStyle *style,
1454 GtkStateType state_type,
1457 const gchar *detail,
1462 gint thickness_light;
1463 gint thickness_dark;
1466 g_return_if_fail (GTK_IS_STYLE (style));
1467 g_return_if_fail (window != NULL);
1469 thickness_light = style->ythickness / 2;
1470 thickness_dark = style->ythickness - thickness_light;
1474 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
1475 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
1478 if (detail && !strcmp (detail, "label"))
1480 if (state_type == GTK_STATE_INSENSITIVE)
1481 gdk_draw_line (window, style->white_gc, x1 + 1, y + 1, x2 + 1, y + 1);
1482 gdk_draw_line (window, style->fg_gc[state_type], x1, y, x2, y);
1486 for (i = 0; i < thickness_dark; i++)
1488 gdk_draw_line (window, style->light_gc[state_type], x2 - i - 1, y + i, x2, y + i);
1489 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x2 - i - 1, y + i);
1492 y += thickness_dark;
1493 for (i = 0; i < thickness_light; i++)
1495 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x1 + thickness_light - i - 1, y + i);
1496 gdk_draw_line (window, style->light_gc[state_type], x1 + thickness_light - i - 1, y + i, x2, y + i);
1502 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
1503 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
1509 gtk_default_draw_vline (GtkStyle *style,
1511 GtkStateType state_type,
1514 const gchar *detail,
1519 gint thickness_light;
1520 gint thickness_dark;
1523 g_return_if_fail (GTK_IS_STYLE (style));
1524 g_return_if_fail (window != NULL);
1526 thickness_light = style->xthickness / 2;
1527 thickness_dark = style->xthickness - thickness_light;
1531 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
1532 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
1534 for (i = 0; i < thickness_dark; i++)
1536 gdk_draw_line (window, style->light_gc[state_type], x + i, y2 - i - 1, x + i, y2);
1537 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y2 - i - 1);
1540 x += thickness_dark;
1541 for (i = 0; i < thickness_light; i++)
1543 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y1 + thickness_light - i);
1544 gdk_draw_line (window, style->light_gc[state_type], x + i, y1 + thickness_light - i, x + i, y2);
1548 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
1549 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
1555 gtk_default_draw_shadow (GtkStyle *style,
1557 GtkStateType state_type,
1558 GtkShadowType shadow_type,
1561 const gchar *detail,
1569 gint thickness_light;
1570 gint thickness_dark;
1573 g_return_if_fail (GTK_IS_STYLE (style));
1574 g_return_if_fail (window != NULL);
1576 if ((width == -1) && (height == -1))
1577 gdk_window_get_size (window, &width, &height);
1578 else if (width == -1)
1579 gdk_window_get_size (window, &width, NULL);
1580 else if (height == -1)
1581 gdk_window_get_size (window, NULL, &height);
1583 switch (shadow_type)
1585 case GTK_SHADOW_NONE:
1588 case GTK_SHADOW_ETCHED_IN:
1589 gc1 = style->light_gc[state_type];
1590 gc2 = style->dark_gc[state_type];
1592 case GTK_SHADOW_OUT:
1593 case GTK_SHADOW_ETCHED_OUT:
1594 gc1 = style->dark_gc[state_type];
1595 gc2 = style->light_gc[state_type];
1601 gdk_gc_set_clip_rectangle (gc1, area);
1602 gdk_gc_set_clip_rectangle (gc2, area);
1603 if (shadow_type == GTK_SHADOW_IN ||
1604 shadow_type == GTK_SHADOW_OUT)
1606 gdk_gc_set_clip_rectangle (style->black_gc, area);
1607 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
1611 switch (shadow_type)
1613 case GTK_SHADOW_NONE:
1617 gdk_draw_line (window, gc1,
1618 x, y + height - 1, x + width - 1, y + height - 1);
1619 gdk_draw_line (window, gc1,
1620 x + width - 1, y, x + width - 1, y + height - 1);
1622 gdk_draw_line (window, style->bg_gc[state_type],
1623 x + 1, y + height - 2, x + width - 2, y + height - 2);
1624 gdk_draw_line (window, style->bg_gc[state_type],
1625 x + width - 2, y + 1, x + width - 2, y + height - 2);
1627 gdk_draw_line (window, style->black_gc,
1628 x + 1, y + 1, x + width - 2, y + 1);
1629 gdk_draw_line (window, style->black_gc,
1630 x + 1, y + 1, x + 1, y + height - 2);
1632 gdk_draw_line (window, gc2,
1633 x, y, x + width - 1, y);
1634 gdk_draw_line (window, gc2,
1635 x, y, x, y + height - 1);
1638 case GTK_SHADOW_OUT:
1639 gdk_draw_line (window, gc1,
1640 x + 1, y + height - 2, x + width - 2, y + height - 2);
1641 gdk_draw_line (window, gc1,
1642 x + width - 2, y + 1, x + width - 2, y + height - 2);
1644 gdk_draw_line (window, gc2,
1645 x, y, x + width - 1, y);
1646 gdk_draw_line (window, gc2,
1647 x, y, x, y + height - 1);
1649 gdk_draw_line (window, style->bg_gc[state_type],
1650 x + 1, y + 1, x + width - 2, y + 1);
1651 gdk_draw_line (window, style->bg_gc[state_type],
1652 x + 1, y + 1, x + 1, y + height - 2);
1654 gdk_draw_line (window, style->black_gc,
1655 x, y + height - 1, x + width - 1, y + height - 1);
1656 gdk_draw_line (window, style->black_gc,
1657 x + width - 1, y, x + width - 1, y + height - 1);
1660 case GTK_SHADOW_ETCHED_IN:
1661 case GTK_SHADOW_ETCHED_OUT:
1662 thickness_light = 1;
1665 for (i = 0; i < thickness_dark; i++)
1667 gdk_draw_line (window, gc1,
1671 y + height - i - 1);
1672 gdk_draw_line (window, gc1,
1676 y + height - i - 1);
1678 gdk_draw_line (window, gc2,
1683 gdk_draw_line (window, gc2,
1687 y + height - i - 2);
1690 for (i = 0; i < thickness_light; i++)
1692 gdk_draw_line (window, gc1,
1693 x + thickness_dark + i,
1694 y + thickness_dark + i,
1695 x + width - thickness_dark - i - 1,
1696 y + thickness_dark + i);
1697 gdk_draw_line (window, gc1,
1698 x + thickness_dark + i,
1699 y + thickness_dark + i,
1700 x + thickness_dark + i,
1701 y + height - thickness_dark - i - 1);
1703 gdk_draw_line (window, gc2,
1704 x + thickness_dark + i,
1705 y + height - thickness_light - i - 1,
1706 x + width - thickness_light - 1,
1707 y + height - thickness_light - i - 1);
1708 gdk_draw_line (window, gc2,
1709 x + width - thickness_light - i - 1,
1710 y + thickness_dark + i,
1711 x + width - thickness_light - i - 1,
1712 y + height - thickness_light - 1);
1718 gdk_gc_set_clip_rectangle (gc1, NULL);
1719 gdk_gc_set_clip_rectangle (gc2, NULL);
1720 if (shadow_type == GTK_SHADOW_IN ||
1721 shadow_type == GTK_SHADOW_OUT)
1723 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
1724 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
1730 gtk_default_draw_polygon (GtkStyle *style,
1732 GtkStateType state_type,
1733 GtkShadowType shadow_type,
1736 const gchar *detail,
1741 static const gdouble pi_over_4 = M_PI_4;
1742 static const gdouble pi_3_over_4 = M_PI_4 * 3;
1752 g_return_if_fail (GTK_IS_STYLE (style));
1753 g_return_if_fail (window != NULL);
1754 g_return_if_fail (points != NULL);
1756 switch (shadow_type)
1759 gc1 = style->bg_gc[state_type];
1760 gc2 = style->dark_gc[state_type];
1761 gc3 = style->light_gc[state_type];
1762 gc4 = style->black_gc;
1764 case GTK_SHADOW_ETCHED_IN:
1765 gc1 = style->light_gc[state_type];
1766 gc2 = style->dark_gc[state_type];
1767 gc3 = style->dark_gc[state_type];
1768 gc4 = style->light_gc[state_type];
1770 case GTK_SHADOW_OUT:
1771 gc1 = style->dark_gc[state_type];
1772 gc2 = style->light_gc[state_type];
1773 gc3 = style->black_gc;
1774 gc4 = style->bg_gc[state_type];
1776 case GTK_SHADOW_ETCHED_OUT:
1777 gc1 = style->dark_gc[state_type];
1778 gc2 = style->light_gc[state_type];
1779 gc3 = style->light_gc[state_type];
1780 gc4 = style->dark_gc[state_type];
1788 gdk_gc_set_clip_rectangle (gc1, area);
1789 gdk_gc_set_clip_rectangle (gc2, area);
1790 gdk_gc_set_clip_rectangle (gc3, area);
1791 gdk_gc_set_clip_rectangle (gc4, area);
1795 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, npoints);
1799 for (i = 0; i < npoints; i++)
1801 if ((points[i].x == points[i+1].x) &&
1802 (points[i].y == points[i+1].y))
1808 angle = atan2 (points[i+1].y - points[i].y,
1809 points[i+1].x - points[i].x);
1812 if ((angle > -pi_3_over_4) && (angle < pi_over_4))
1814 if (angle > -pi_over_4)
1825 gdk_draw_line (window, gc1,
1826 points[i].x-xadjust, points[i].y-yadjust,
1827 points[i+1].x-xadjust, points[i+1].y-yadjust);
1828 gdk_draw_line (window, gc3,
1829 points[i].x, points[i].y,
1830 points[i+1].x, points[i+1].y);
1834 if ((angle < -pi_3_over_4) || (angle > pi_3_over_4))
1845 gdk_draw_line (window, gc4,
1846 points[i].x+xadjust, points[i].y+yadjust,
1847 points[i+1].x+xadjust, points[i+1].y+yadjust);
1848 gdk_draw_line (window, gc2,
1849 points[i].x, points[i].y,
1850 points[i+1].x, points[i+1].y);
1856 gdk_gc_set_clip_rectangle (gc1, NULL);
1857 gdk_gc_set_clip_rectangle (gc2, NULL);
1858 gdk_gc_set_clip_rectangle (gc3, NULL);
1859 gdk_gc_set_clip_rectangle (gc4, NULL);
1864 gtk_default_draw_arrow (GtkStyle *style,
1866 GtkStateType state_type,
1867 GtkShadowType shadow_type,
1870 const gchar *detail,
1871 GtkArrowType arrow_type,
1886 g_return_if_fail (GTK_IS_STYLE (style));
1887 g_return_if_fail (window != NULL);
1889 switch (shadow_type)
1892 gc1 = style->bg_gc[state_type];
1893 gc2 = style->dark_gc[state_type];
1894 gc3 = style->light_gc[state_type];
1895 gc4 = style->black_gc;
1897 case GTK_SHADOW_OUT:
1898 gc1 = style->dark_gc[state_type];
1899 gc2 = style->light_gc[state_type];
1900 gc3 = style->black_gc;
1901 gc4 = style->bg_gc[state_type];
1903 case GTK_SHADOW_ETCHED_IN:
1904 gc1 = style->light_gc[state_type];
1905 gc2 = style->dark_gc[state_type];
1909 case GTK_SHADOW_ETCHED_OUT:
1910 gc1 = style->dark_gc[state_type];
1911 gc2 = style->light_gc[state_type];
1919 if ((width == -1) && (height == -1))
1920 gdk_window_get_size (window, &width, &height);
1921 else if (width == -1)
1922 gdk_window_get_size (window, &width, NULL);
1923 else if (height == -1)
1924 gdk_window_get_size (window, NULL, &height);
1926 half_width = width / 2;
1927 half_height = height / 2;
1931 gdk_gc_set_clip_rectangle (gc1, area);
1932 gdk_gc_set_clip_rectangle (gc2, area);
1935 gdk_gc_set_clip_rectangle (gc3, area);
1936 gdk_gc_set_clip_rectangle (gc4, area);
1945 points[0].x = x + half_width;
1948 points[1].y = y + height - 1;
1949 points[2].x = x + width - 1;
1950 points[2].y = y + height - 1;
1952 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
1955 switch (shadow_type)
1958 case GTK_SHADOW_OUT:
1960 gdk_draw_line (window, gc1,
1961 x + 1, y + height - 2,
1962 x + width - 2, y + height - 2);
1963 gdk_draw_line (window, gc3,
1964 x + 0, y + height - 1,
1965 x + width - 1, y + height - 1);
1967 gdk_draw_line (window, gc1,
1968 x + width - 2, y + height - 1,
1969 x + half_width, y + 1);
1970 gdk_draw_line (window, gc3,
1971 x + width - 1, y + height - 1,
1974 gdk_draw_line (window, gc4,
1975 x + half_width, y + 1,
1976 x + 1, y + height - 1);
1977 gdk_draw_line (window, gc2,
1982 case GTK_SHADOW_ETCHED_IN:
1983 case GTK_SHADOW_ETCHED_OUT:
1984 gdk_draw_line (window, gc1,
1985 x + half_width, y + 1,
1986 x + 1, y + height - 1);
1987 gdk_draw_line (window, gc1,
1988 x + 1, y + height - 1,
1989 x + width - 1, y + height - 1);
1990 gdk_draw_line (window, gc1,
1991 x + width - 1, y + height - 1,
1992 x + half_width + 1, y + 1);
1994 points[0].x = x + half_width;
1997 points[1].y = y + height - 2;
1998 points[2].x = x + width - 2;
1999 points[2].y = y + height - 2;
2001 gdk_draw_polygon (window, gc2, FALSE, points, 3);
2009 case GTK_ARROW_DOWN:
2012 points[0].x = x + width - 1;
2016 points[2].x = x + half_width;
2017 points[2].y = y + height - 1;
2019 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
2021 switch (shadow_type)
2024 case GTK_SHADOW_OUT:
2025 gdk_draw_line (window, gc4,
2027 y + 1, x + 1, y + 1);
2028 gdk_draw_line (window, gc2,
2032 gdk_draw_line (window, gc4,
2034 x + half_width, y + height - 2);
2035 gdk_draw_line (window, gc2,
2037 x + half_width, y + height - 1);
2039 gdk_draw_line (window, gc1,
2040 x + half_width, y + height - 2,
2042 gdk_draw_line (window, gc3,
2043 x + half_width, y + height - 1,
2047 case GTK_SHADOW_ETCHED_IN:
2048 case GTK_SHADOW_ETCHED_OUT:
2049 gdk_draw_line (window, gc1,
2050 x + width - 1, y + 1,
2052 gdk_draw_line (window, gc1,
2054 x + half_width + 1, y + height - 1);
2055 gdk_draw_line (window, gc1,
2056 x + half_width + 1, y + height - 2,
2059 points[0].x = x + width - 2;
2063 points[2].x = x + half_width;
2064 points[2].y = y + height - 2;
2066 gdk_draw_polygon (window, gc2, FALSE, points, 3);
2073 case GTK_ARROW_LEFT:
2077 points[0].y = y + half_height;
2078 points[1].x = x + width - 1;
2079 points[1].y = y + height - 1;
2080 points[2].x = x + width - 1;
2083 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
2086 switch (shadow_type)
2089 case GTK_SHADOW_OUT:
2090 gdk_draw_line (window, gc1,
2091 x + 1, y + half_height,
2092 x + width - 1, y + height - 1);
2093 gdk_draw_line (window, gc3,
2095 x + width - 1, y + height - 1);
2097 gdk_draw_line (window, gc1,
2098 x + width - 2, y + height - 1,
2099 x + width - 2, y + 1);
2100 gdk_draw_line (window, gc3,
2101 x + width - 1, y + height - 1,
2104 gdk_draw_line (window, gc4,
2105 x + width - 1, y + 1,
2106 x + 1, y + half_height);
2107 gdk_draw_line (window, gc2,
2109 x, y + half_height);
2112 case GTK_SHADOW_ETCHED_IN:
2113 case GTK_SHADOW_ETCHED_OUT:
2114 gdk_draw_line (window, gc1,
2115 x + width - 1, y + 1,
2116 x + 1, y + half_height);
2117 gdk_draw_line (window, gc1,
2118 x + 1, y + half_height + 1,
2119 x + width - 1, y + height - 1);
2120 gdk_draw_line (window, gc1,
2121 x + width - 1, y + height - 1,
2122 x + width - 1, y + 1);
2124 points[0].x = x + width - 2;
2127 points[1].y = y + half_height;
2128 points[2].x = x + width - 2;
2129 points[2].y = y + height - 2;
2131 gdk_draw_polygon (window, gc2, FALSE, points, 3);
2138 case GTK_ARROW_RIGHT:
2141 points[0].x = x + width - 1;
2142 points[0].y = y + half_height;
2146 points[2].y = y + height - 1;
2148 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
2151 switch (shadow_type)
2154 case GTK_SHADOW_OUT:
2155 gdk_draw_line (window, gc4,
2156 x + width - 1, y + half_height,
2158 gdk_draw_line (window, gc2,
2159 x + width - 1, y + half_height,
2161 gdk_draw_line (window, gc4,
2163 x + 1, y + height - 2);
2164 gdk_draw_line (window, gc2,
2168 gdk_draw_line (window, gc1,
2169 x + 1, y + height - 2,
2170 x + width - 1, y + half_height);
2171 gdk_draw_line (window, gc3,
2173 x + width - 1, y + half_height);
2176 case GTK_SHADOW_ETCHED_IN:
2177 case GTK_SHADOW_ETCHED_OUT:
2178 gdk_draw_line (window, gc1,
2179 x + width - 1, y + half_height + 1,
2181 gdk_draw_line (window, gc1,
2183 x + 1, y + height - 1);
2184 gdk_draw_line (window, gc1,
2185 x + 1, y + height - 1,
2186 x + width - 1, y + half_height + 1);
2188 points[0].x = x + width - 2;
2189 points[0].y = y + half_height;
2193 points[2].y = y + height - 1;
2195 gdk_draw_polygon (window, gc2, FALSE, points, 3);
2206 gdk_gc_set_clip_rectangle (gc1, NULL);
2207 gdk_gc_set_clip_rectangle (gc2, NULL);
2210 gdk_gc_set_clip_rectangle (gc3, NULL);
2211 gdk_gc_set_clip_rectangle (gc4, NULL);
2217 gtk_default_draw_diamond (GtkStyle *style,
2219 GtkStateType state_type,
2220 GtkShadowType shadow_type,
2223 const gchar *detail,
2232 g_return_if_fail (GTK_IS_STYLE (style));
2233 g_return_if_fail (window != NULL);
2235 if ((width == -1) && (height == -1))
2236 gdk_window_get_size (window, &width, &height);
2237 else if (width == -1)
2238 gdk_window_get_size (window, &width, NULL);
2239 else if (height == -1)
2240 gdk_window_get_size (window, NULL, &height);
2242 half_width = width / 2;
2243 half_height = height / 2;
2247 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
2248 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2249 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
2250 gdk_gc_set_clip_rectangle (style->black_gc, area);
2252 switch (shadow_type)
2255 gdk_draw_line (window, style->bg_gc[state_type],
2256 x + 2, y + half_height,
2257 x + half_width, y + height - 2);
2258 gdk_draw_line (window, style->bg_gc[state_type],
2259 x + half_width, y + height - 2,
2260 x + width - 2, y + half_height);
2261 gdk_draw_line (window, style->light_gc[state_type],
2262 x + 1, y + half_height,
2263 x + half_width, y + height - 1);
2264 gdk_draw_line (window, style->light_gc[state_type],
2265 x + half_width, y + height - 1,
2266 x + width - 1, y + half_height);
2267 gdk_draw_line (window, style->light_gc[state_type],
2269 x + half_width, y + height);
2270 gdk_draw_line (window, style->light_gc[state_type],
2271 x + half_width, y + height,
2272 x + width, y + half_height);
2274 gdk_draw_line (window, style->black_gc,
2275 x + 2, y + half_height,
2276 x + half_width, y + 2);
2277 gdk_draw_line (window, style->black_gc,
2278 x + half_width, y + 2,
2279 x + width - 2, y + half_height);
2280 gdk_draw_line (window, style->dark_gc[state_type],
2281 x + 1, y + half_height,
2282 x + half_width, y + 1);
2283 gdk_draw_line (window, style->dark_gc[state_type],
2284 x + half_width, y + 1,
2285 x + width - 1, y + half_height);
2286 gdk_draw_line (window, style->dark_gc[state_type],
2289 gdk_draw_line (window, style->dark_gc[state_type],
2291 x + width, y + half_height);
2293 case GTK_SHADOW_OUT:
2294 gdk_draw_line (window, style->dark_gc[state_type],
2295 x + 2, y + half_height,
2296 x + half_width, y + height - 2);
2297 gdk_draw_line (window, style->dark_gc[state_type],
2298 x + half_width, y + height - 2,
2299 x + width - 2, y + half_height);
2300 gdk_draw_line (window, style->dark_gc[state_type],
2301 x + 1, y + half_height,
2302 x + half_width, y + height - 1);
2303 gdk_draw_line (window, style->dark_gc[state_type],
2304 x + half_width, y + height - 1,
2305 x + width - 1, y + half_height);
2306 gdk_draw_line (window, style->black_gc,
2308 x + half_width, y + height);
2309 gdk_draw_line (window, style->black_gc,
2310 x + half_width, y + height,
2311 x + width, y + half_height);
2313 gdk_draw_line (window, style->bg_gc[state_type],
2314 x + 2, y + half_height,
2315 x + half_width, y + 2);
2316 gdk_draw_line (window, style->bg_gc[state_type],
2317 x + half_width, y + 2,
2318 x + width - 2, y + half_height);
2319 gdk_draw_line (window, style->light_gc[state_type],
2320 x + 1, y + half_height,
2321 x + half_width, y + 1);
2322 gdk_draw_line (window, style->light_gc[state_type],
2323 x + half_width, y + 1,
2324 x + width - 1, y + half_height);
2325 gdk_draw_line (window, style->light_gc[state_type],
2328 gdk_draw_line (window, style->light_gc[state_type],
2330 x + width, y + half_height);
2337 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
2338 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
2339 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
2340 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2345 gtk_default_draw_string (GtkStyle *style,
2347 GtkStateType state_type,
2350 const gchar *detail,
2353 const gchar *string)
2355 g_return_if_fail (GTK_IS_STYLE (style));
2356 g_return_if_fail (window != NULL);
2360 gdk_gc_set_clip_rectangle (style->white_gc, area);
2361 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], area);
2364 if (state_type == GTK_STATE_INSENSITIVE)
2365 gdk_draw_string (window, style->font, style->white_gc, x + 1, y + 1, string);
2367 gdk_draw_string (window, style->font, style->fg_gc[state_type], x, y, string);
2371 gdk_gc_set_clip_rectangle (style->white_gc, NULL);
2372 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], NULL);
2377 gtk_default_draw_box (GtkStyle *style,
2379 GtkStateType state_type,
2380 GtkShadowType shadow_type,
2383 const gchar *detail,
2389 g_return_if_fail (GTK_IS_STYLE (style));
2390 g_return_if_fail (window != NULL);
2392 if (width == -1 && height == -1)
2393 gdk_window_get_size (window, &width, &height);
2394 else if (width == -1)
2395 gdk_window_get_size (window, &width, NULL);
2396 else if (height == -1)
2397 gdk_window_get_size (window, NULL, &height);
2399 if (!style->bg_pixmap[state_type] ||
2400 GDK_IS_PIXMAP (window))
2403 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2405 gdk_draw_rectangle (window, style->bg_gc[state_type], TRUE,
2406 x, y, width, height);
2408 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
2411 gtk_style_apply_default_background (style, window,
2412 widget && !GTK_WIDGET_NO_WINDOW (widget),
2413 state_type, area, x, y, width, height);
2415 gtk_paint_shadow (style, window, state_type, shadow_type, area, widget, detail,
2416 x, y, width, height);
2420 get_darkened_gc (GdkWindow *window,
2424 GdkColor src = *color;
2428 gc = gdk_gc_new (window);
2430 while (darken_count)
2432 gtk_style_shade (&src, &shaded, 1.3);
2437 gdk_gc_set_rgb_fg_color (gc, &shaded);
2443 gtk_default_draw_flat_box (GtkStyle *style,
2445 GtkStateType state_type,
2446 GtkShadowType shadow_type,
2449 const gchar *detail,
2456 GdkGC *freeme = NULL;
2458 g_return_if_fail (GTK_IS_STYLE (style));
2459 g_return_if_fail (window != NULL);
2461 if (width == -1 && height == -1)
2462 gdk_window_get_size (window, &width, &height);
2463 else if (width == -1)
2464 gdk_window_get_size (window, &width, NULL);
2465 else if (height == -1)
2466 gdk_window_get_size (window, NULL, &height);
2470 if (state_type == GTK_STATE_SELECTED)
2472 if (!strcmp ("text", detail))
2473 gc1 = style->bg_gc[GTK_STATE_SELECTED];
2474 else if (!strcmp ("cell_even_sorted", detail) ||
2475 !strcmp ("cell_odd_sorted", detail) ||
2476 !strcmp ("cell_even_ruled_sorted", detail) ||
2477 !strcmp ("cell_odd_ruled_sorted", detail))
2479 freeme = get_darkened_gc (window, &style->bg[state_type], 1);
2484 gc1 = style->bg_gc[state_type];
2489 if (!strcmp ("viewportbin", detail))
2490 gc1 = style->bg_gc[GTK_STATE_NORMAL];
2491 else if (!strcmp ("entry_bg", detail))
2492 gc1 = style->base_gc[state_type];
2494 /* For trees: even rows are base color, odd rows are a shade of
2495 * the base color, the sort column is a shade of the original color
2499 /* FIXME when we have style properties, clean this up.
2502 else if (!strcmp ("cell_even", detail) ||
2503 !strcmp ("cell_odd", detail) ||
2504 !strcmp ("cell_even_ruled", detail))
2506 gc1 = style->base_gc[state_type];
2508 else if (!strcmp ("cell_even_sorted", detail) ||
2509 !strcmp ("cell_odd_sorted", detail) ||
2510 !strcmp ("cell_odd_ruled", detail) ||
2511 !strcmp ("cell_even_ruled_sorted", detail))
2513 freeme = get_darkened_gc (window, &style->base[state_type], 1);
2516 else if (!strcmp ("cell_odd_ruled_sorted", detail))
2518 freeme = get_darkened_gc (window, &style->base[state_type], 2);
2522 gc1 = style->bg_gc[state_type];
2526 gc1 = style->bg_gc[state_type];
2528 if (!style->bg_pixmap[state_type] || gc1 != style->bg_gc[state_type] ||
2529 GDK_IS_PIXMAP (window))
2532 gdk_gc_set_clip_rectangle (gc1, area);
2534 gdk_draw_rectangle (window, gc1, TRUE,
2535 x, y, width, height);
2537 if (detail && !strcmp ("tooltip", detail))
2538 gdk_draw_rectangle (window, style->black_gc, FALSE,
2539 x, y, width - 1, height - 1);
2542 gdk_gc_set_clip_rectangle (gc1, NULL);
2545 gtk_style_apply_default_background (style, window,
2546 widget && !GTK_WIDGET_NO_WINDOW (widget),
2547 state_type, area, x, y, width, height);
2551 g_object_unref (G_OBJECT (freeme));
2555 gtk_default_draw_check (GtkStyle *style,
2557 GtkStateType state_type,
2558 GtkShadowType shadow_type,
2561 const gchar *detail,
2567 if (detail && strcmp (detail, "cellcheck") == 0)
2569 gdk_draw_rectangle (window,
2570 widget->style->fg_gc[state_type],
2575 if (shadow_type == GTK_SHADOW_IN)
2577 gdk_draw_line (window,
2578 widget->style->fg_gc[state_type],
2582 gdk_draw_line (window,
2583 widget->style->fg_gc[state_type],
2592 gtk_paint_box (style, window, state_type, shadow_type, area, widget, detail,
2593 x, y, width, height);
2598 gtk_default_draw_option (GtkStyle *style,
2600 GtkStateType state_type,
2601 GtkShadowType shadow_type,
2604 const gchar *detail,
2610 if (detail && strcmp (detail, "cellradio") == 0)
2612 gdk_draw_arc (window,
2613 widget->style->fg_gc[state_type],
2620 if (shadow_type == GTK_SHADOW_IN)
2622 gdk_draw_arc (window,
2623 widget->style->fg_gc[state_type],
2634 gtk_paint_diamond (style, window, state_type, shadow_type, area, widget,
2635 detail, x, y, width, height);
2640 gtk_default_draw_tab (GtkStyle *style,
2642 GtkStateType state_type,
2643 GtkShadowType shadow_type,
2646 const gchar *detail,
2652 g_return_if_fail (GTK_IS_STYLE (style));
2653 g_return_if_fail (window != NULL);
2655 gtk_paint_box (style, window, state_type, shadow_type, area, widget, detail,
2656 x, y, width, height);
2660 gtk_default_draw_shadow_gap (GtkStyle *style,
2662 GtkStateType state_type,
2663 GtkShadowType shadow_type,
2666 const gchar *detail,
2671 GtkPositionType gap_side,
2680 g_return_if_fail (GTK_IS_STYLE (style));
2681 g_return_if_fail (window != NULL);
2683 if (width == -1 && height == -1)
2684 gdk_window_get_size (window, &width, &height);
2685 else if (width == -1)
2686 gdk_window_get_size (window, &width, NULL);
2687 else if (height == -1)
2688 gdk_window_get_size (window, NULL, &height);
2690 switch (shadow_type)
2692 case GTK_SHADOW_NONE:
2695 gc1 = style->dark_gc[state_type];
2696 gc2 = style->black_gc;
2697 gc3 = style->bg_gc[state_type];
2698 gc4 = style->light_gc[state_type];
2700 case GTK_SHADOW_ETCHED_IN:
2701 gc1 = style->dark_gc[state_type];
2702 gc2 = style->light_gc[state_type];
2703 gc3 = style->dark_gc[state_type];
2704 gc4 = style->light_gc[state_type];
2706 case GTK_SHADOW_OUT:
2707 gc1 = style->light_gc[state_type];
2708 gc2 = style->bg_gc[state_type];
2709 gc3 = style->dark_gc[state_type];
2710 gc4 = style->black_gc;
2712 case GTK_SHADOW_ETCHED_OUT:
2713 gc1 = style->light_gc[state_type];
2714 gc2 = style->dark_gc[state_type];
2715 gc3 = style->light_gc[state_type];
2716 gc4 = style->dark_gc[state_type];
2721 gdk_gc_set_clip_rectangle (gc1, area);
2722 gdk_gc_set_clip_rectangle (gc2, area);
2723 gdk_gc_set_clip_rectangle (gc3, area);
2724 gdk_gc_set_clip_rectangle (gc4, area);
2727 switch (shadow_type)
2729 case GTK_SHADOW_NONE:
2731 case GTK_SHADOW_OUT:
2732 case GTK_SHADOW_ETCHED_IN:
2733 case GTK_SHADOW_ETCHED_OUT:
2737 gdk_draw_line (window, gc1,
2738 x, y, x, y + height - 1);
2739 gdk_draw_line (window, gc2,
2740 x + 1, y, x + 1, y + height - 2);
2742 gdk_draw_line (window, gc3,
2743 x + 1, y + height - 2, x + width - 2, y + height - 2);
2744 gdk_draw_line (window, gc3,
2745 x + width - 2, y, x + width - 2, y + height - 2);
2746 gdk_draw_line (window, gc4,
2747 x, y + height - 1, x + width - 1, y + height - 1);
2748 gdk_draw_line (window, gc4,
2749 x + width - 1, y, x + width - 1, y + height - 1);
2752 gdk_draw_line (window, gc1,
2753 x, y, x + gap_x - 1, y);
2754 gdk_draw_line (window, gc2,
2755 x + 1, y + 1, x + gap_x - 1, y + 1);
2756 gdk_draw_line (window, gc2,
2757 x + gap_x, y, x + gap_x, y);
2759 if ((width - (gap_x + gap_width)) > 0)
2761 gdk_draw_line (window, gc1,
2762 x + gap_x + gap_width, y, x + width - 2, y);
2763 gdk_draw_line (window, gc2,
2764 x + gap_x + gap_width, y + 1, x + width - 2, y + 1);
2765 gdk_draw_line (window, gc2,
2766 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
2769 case GTK_POS_BOTTOM:
2770 gdk_draw_line (window, gc1,
2771 x, y, x + width - 1, y);
2772 gdk_draw_line (window, gc1,
2773 x, y, x, y + height - 1);
2774 gdk_draw_line (window, gc2,
2775 x + 1, y + 1, x + width - 2, y + 1);
2776 gdk_draw_line (window, gc2,
2777 x + 1, y + 1, x + 1, y + height - 1);
2779 gdk_draw_line (window, gc3,
2780 x + width - 2, y + 1, x + width - 2, y + height - 1);
2781 gdk_draw_line (window, gc4,
2782 x + width - 1, y, x + width - 1, y + height - 1);
2785 gdk_draw_line (window, gc4,
2786 x, y + height - 1, x + gap_x - 1, y + height - 1);
2787 gdk_draw_line (window, gc3,
2788 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
2789 gdk_draw_line (window, gc3,
2790 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
2792 if ((width - (gap_x + gap_width)) > 0)
2794 gdk_draw_line (window, gc4,
2795 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
2796 gdk_draw_line (window, gc3,
2797 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
2798 gdk_draw_line (window, gc3,
2799 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
2803 gdk_draw_line (window, gc1,
2804 x, y, x + width - 1, y);
2805 gdk_draw_line (window, gc2,
2806 x, y + 1, x + width - 2, y + 1);
2808 gdk_draw_line (window, gc3,
2809 x, y + height - 2, x + width - 2, y + height - 2);
2810 gdk_draw_line (window, gc3,
2811 x + width - 2, y + 1, x + width - 2, y + height - 2);
2812 gdk_draw_line (window, gc4,
2813 x, y + height - 1, x + width - 1, y + height - 1);
2814 gdk_draw_line (window, gc4,
2815 x + width - 1, y, x + width - 1, y + height - 1);
2818 gdk_draw_line (window, gc1,
2819 x, y, x, y + gap_x - 1);
2820 gdk_draw_line (window, gc2,
2821 x + 1, y + 1, x + 1, y + gap_x - 1);
2822 gdk_draw_line (window, gc2,
2823 x, y + gap_x, x, y + gap_x);
2825 if ((width - (gap_x + gap_width)) > 0)
2827 gdk_draw_line (window, gc1,
2828 x, y + gap_x + gap_width, x, y + height - 2);
2829 gdk_draw_line (window, gc2,
2830 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
2831 gdk_draw_line (window, gc2,
2832 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
2836 gdk_draw_line (window, gc1,
2837 x, y, x + width - 1, y);
2838 gdk_draw_line (window, gc1,
2839 x, y, x, y + height - 1);
2840 gdk_draw_line (window, gc2,
2841 x + 1, y + 1, x + width - 1, y + 1);
2842 gdk_draw_line (window, gc2,
2843 x + 1, y + 1, x + 1, y + height - 2);
2845 gdk_draw_line (window, gc3,
2846 x + 1, y + height - 2, x + width - 1, y + height - 2);
2847 gdk_draw_line (window, gc4,
2848 x, y + height - 1, x + width - 1, y + height - 1);
2851 gdk_draw_line (window, gc4,
2852 x + width - 1, y, x + width - 1, y + gap_x - 1);
2853 gdk_draw_line (window, gc3,
2854 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
2855 gdk_draw_line (window, gc3,
2856 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
2858 if ((width - (gap_x + gap_width)) > 0)
2860 gdk_draw_line (window, gc4,
2861 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
2862 gdk_draw_line (window, gc3,
2863 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
2864 gdk_draw_line (window, gc3,
2865 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
2873 gdk_gc_set_clip_rectangle (gc1, NULL);
2874 gdk_gc_set_clip_rectangle (gc2, NULL);
2875 gdk_gc_set_clip_rectangle (gc3, NULL);
2876 gdk_gc_set_clip_rectangle (gc4, NULL);
2881 gtk_default_draw_box_gap (GtkStyle *style,
2883 GtkStateType state_type,
2884 GtkShadowType shadow_type,
2887 const gchar *detail,
2892 GtkPositionType gap_side,
2901 g_return_if_fail (GTK_IS_STYLE (style));
2902 g_return_if_fail (window != NULL);
2904 gtk_style_apply_default_background (style, window,
2905 widget && !GTK_WIDGET_NO_WINDOW (widget),
2906 state_type, area, x, y, width, height);
2908 if (width == -1 && height == -1)
2909 gdk_window_get_size (window, &width, &height);
2910 else if (width == -1)
2911 gdk_window_get_size (window, &width, NULL);
2912 else if (height == -1)
2913 gdk_window_get_size (window, NULL, &height);
2915 switch (shadow_type)
2917 case GTK_SHADOW_NONE:
2920 gc1 = style->dark_gc[state_type];
2921 gc2 = style->black_gc;
2922 gc3 = style->bg_gc[state_type];
2923 gc4 = style->light_gc[state_type];
2925 case GTK_SHADOW_ETCHED_IN:
2926 gc1 = style->dark_gc[state_type];
2927 gc2 = style->light_gc[state_type];
2928 gc3 = style->dark_gc[state_type];
2929 gc4 = style->light_gc[state_type];
2931 case GTK_SHADOW_OUT:
2932 gc1 = style->light_gc[state_type];
2933 gc2 = style->bg_gc[state_type];
2934 gc3 = style->dark_gc[state_type];
2935 gc4 = style->black_gc;
2937 case GTK_SHADOW_ETCHED_OUT:
2938 gc1 = style->light_gc[state_type];
2939 gc2 = style->dark_gc[state_type];
2940 gc3 = style->light_gc[state_type];
2941 gc4 = style->dark_gc[state_type];
2947 gdk_gc_set_clip_rectangle (gc1, area);
2948 gdk_gc_set_clip_rectangle (gc2, area);
2949 gdk_gc_set_clip_rectangle (gc3, area);
2950 gdk_gc_set_clip_rectangle (gc4, area);
2953 switch (shadow_type)
2955 case GTK_SHADOW_NONE:
2957 case GTK_SHADOW_OUT:
2958 case GTK_SHADOW_ETCHED_IN:
2959 case GTK_SHADOW_ETCHED_OUT:
2963 gdk_draw_line (window, gc1,
2964 x, y, x, y + height - 1);
2965 gdk_draw_line (window, gc2,
2966 x + 1, y, x + 1, y + height - 2);
2968 gdk_draw_line (window, gc3,
2969 x + 1, y + height - 2, x + width - 2, y + height - 2);
2970 gdk_draw_line (window, gc3,
2971 x + width - 2, y, x + width - 2, y + height - 2);
2972 gdk_draw_line (window, gc4,
2973 x, y + height - 1, x + width - 1, y + height - 1);
2974 gdk_draw_line (window, gc4,
2975 x + width - 1, y, x + width - 1, y + height - 1);
2978 gdk_draw_line (window, gc1,
2979 x, y, x + gap_x - 1, y);
2980 gdk_draw_line (window, gc2,
2981 x + 1, y + 1, x + gap_x - 1, y + 1);
2982 gdk_draw_line (window, gc2,
2983 x + gap_x, y, x + gap_x, y);
2985 if ((width - (gap_x + gap_width)) > 0)
2987 gdk_draw_line (window, gc1,
2988 x + gap_x + gap_width, y, x + width - 2, y);
2989 gdk_draw_line (window, gc2,
2990 x + gap_x + gap_width, y + 1, x + width - 2, y + 1);
2991 gdk_draw_line (window, gc2,
2992 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
2995 case GTK_POS_BOTTOM:
2996 gdk_draw_line (window, gc1,
2997 x, y, x + width - 1, y);
2998 gdk_draw_line (window, gc1,
2999 x, y, x, y + height - 1);
3000 gdk_draw_line (window, gc2,
3001 x + 1, y + 1, x + width - 2, y + 1);
3002 gdk_draw_line (window, gc2,
3003 x + 1, y + 1, x + 1, y + height - 1);
3005 gdk_draw_line (window, gc3,
3006 x + width - 2, y + 1, x + width - 2, y + height - 1);
3007 gdk_draw_line (window, gc4,
3008 x + width - 1, y, x + width - 1, y + height - 1);
3011 gdk_draw_line (window, gc4,
3012 x, y + height - 1, x + gap_x - 1, y + height - 1);
3013 gdk_draw_line (window, gc3,
3014 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
3015 gdk_draw_line (window, gc3,
3016 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
3018 if ((width - (gap_x + gap_width)) > 0)
3020 gdk_draw_line (window, gc4,
3021 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
3022 gdk_draw_line (window, gc3,
3023 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
3024 gdk_draw_line (window, gc3,
3025 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
3029 gdk_draw_line (window, gc1,
3030 x, y, x + width - 1, y);
3031 gdk_draw_line (window, gc2,
3032 x, y + 1, x + width - 2, y + 1);
3034 gdk_draw_line (window, gc3,
3035 x, y + height - 2, x + width - 2, y + height - 2);
3036 gdk_draw_line (window, gc3,
3037 x + width - 2, y + 1, x + width - 2, y + height - 2);
3038 gdk_draw_line (window, gc4,
3039 x, y + height - 1, x + width - 1, y + height - 1);
3040 gdk_draw_line (window, gc4,
3041 x + width - 1, y, x + width - 1, y + height - 1);
3044 gdk_draw_line (window, gc1,
3045 x, y, x, y + gap_x - 1);
3046 gdk_draw_line (window, gc2,
3047 x + 1, y + 1, x + 1, y + gap_x - 1);
3048 gdk_draw_line (window, gc2,
3049 x, y + gap_x, x, y + gap_x);
3051 if ((width - (gap_x + gap_width)) > 0)
3053 gdk_draw_line (window, gc1,
3054 x, y + gap_x + gap_width, x, y + height - 2);
3055 gdk_draw_line (window, gc2,
3056 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
3057 gdk_draw_line (window, gc2,
3058 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
3062 gdk_draw_line (window, gc1,
3063 x, y, x + width - 1, y);
3064 gdk_draw_line (window, gc1,
3065 x, y, x, y + height - 1);
3066 gdk_draw_line (window, gc2,
3067 x + 1, y + 1, x + width - 1, y + 1);
3068 gdk_draw_line (window, gc2,
3069 x + 1, y + 1, x + 1, y + height - 2);
3071 gdk_draw_line (window, gc3,
3072 x + 1, y + height - 2, x + width - 1, y + height - 2);
3073 gdk_draw_line (window, gc4,
3074 x, y + height - 1, x + width - 1, y + height - 1);
3077 gdk_draw_line (window, gc4,
3078 x + width - 1, y, x + width - 1, y + gap_x - 1);
3079 gdk_draw_line (window, gc3,
3080 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
3081 gdk_draw_line (window, gc3,
3082 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
3084 if ((width - (gap_x + gap_width)) > 0)
3086 gdk_draw_line (window, gc4,
3087 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
3088 gdk_draw_line (window, gc3,
3089 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
3090 gdk_draw_line (window, gc3,
3091 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
3099 gdk_gc_set_clip_rectangle (gc1, NULL);
3100 gdk_gc_set_clip_rectangle (gc2, NULL);
3101 gdk_gc_set_clip_rectangle (gc3, NULL);
3102 gdk_gc_set_clip_rectangle (gc4, NULL);
3107 gtk_default_draw_extension (GtkStyle *style,
3109 GtkStateType state_type,
3110 GtkShadowType shadow_type,
3113 const gchar *detail,
3118 GtkPositionType gap_side)
3125 g_return_if_fail (GTK_IS_STYLE (style));
3126 g_return_if_fail (window != NULL);
3128 gtk_style_apply_default_background (style, window,
3129 widget && !GTK_WIDGET_NO_WINDOW (widget),
3130 GTK_STATE_NORMAL, area, x, y, width, height);
3132 if (width == -1 && height == -1)
3133 gdk_window_get_size (window, &width, &height);
3134 else if (width == -1)
3135 gdk_window_get_size (window, &width, NULL);
3136 else if (height == -1)
3137 gdk_window_get_size (window, NULL, &height);
3139 switch (shadow_type)
3141 case GTK_SHADOW_NONE:
3144 gc1 = style->dark_gc[state_type];
3145 gc2 = style->black_gc;
3146 gc3 = style->bg_gc[state_type];
3147 gc4 = style->light_gc[state_type];
3149 case GTK_SHADOW_ETCHED_IN:
3150 gc1 = style->dark_gc[state_type];
3151 gc2 = style->light_gc[state_type];
3152 gc3 = style->dark_gc[state_type];
3153 gc4 = style->light_gc[state_type];
3155 case GTK_SHADOW_OUT:
3156 gc1 = style->light_gc[state_type];
3157 gc2 = style->bg_gc[state_type];
3158 gc3 = style->dark_gc[state_type];
3159 gc4 = style->black_gc;
3161 case GTK_SHADOW_ETCHED_OUT:
3162 gc1 = style->light_gc[state_type];
3163 gc2 = style->dark_gc[state_type];
3164 gc3 = style->light_gc[state_type];
3165 gc4 = style->dark_gc[state_type];
3171 gdk_gc_set_clip_rectangle (gc1, area);
3172 gdk_gc_set_clip_rectangle (gc2, area);
3173 gdk_gc_set_clip_rectangle (gc3, area);
3174 gdk_gc_set_clip_rectangle (gc4, area);
3177 switch (shadow_type)
3179 case GTK_SHADOW_NONE:
3181 case GTK_SHADOW_OUT:
3182 case GTK_SHADOW_ETCHED_IN:
3183 case GTK_SHADOW_ETCHED_OUT:
3187 gtk_style_apply_default_background (style, window,
3188 widget && !GTK_WIDGET_NO_WINDOW (widget),
3190 x + style->xthickness,
3192 width - (2 * style->xthickness),
3193 height - (style->ythickness));
3194 gdk_draw_line (window, gc1,
3195 x, y, x, y + height - 2);
3196 gdk_draw_line (window, gc2,
3197 x + 1, y, x + 1, y + height - 2);
3199 gdk_draw_line (window, gc3,
3200 x + 2, y + height - 2, x + width - 2, y + height - 2);
3201 gdk_draw_line (window, gc3,
3202 x + width - 2, y, x + width - 2, y + height - 2);
3203 gdk_draw_line (window, gc4,
3204 x + 1, y + height - 1, x + width - 2, y + height - 1);
3205 gdk_draw_line (window, gc4,
3206 x + width - 1, y, x + width - 1, y + height - 2);
3208 case GTK_POS_BOTTOM:
3209 gtk_style_apply_default_background (style, window,
3210 widget && !GTK_WIDGET_NO_WINDOW (widget),
3212 x + style->xthickness,
3213 y + style->ythickness,
3214 width - (2 * style->xthickness),
3215 height - (style->ythickness));
3216 gdk_draw_line (window, gc1,
3217 x + 1, y, x + width - 2, y);
3218 gdk_draw_line (window, gc1,
3219 x, y + 1, x, y + height - 1);
3220 gdk_draw_line (window, gc2,
3221 x + 1, y + 1, x + width - 2, y + 1);
3222 gdk_draw_line (window, gc2,
3223 x + 1, y + 1, x + 1, y + height - 1);
3225 gdk_draw_line (window, gc3,
3226 x + width - 2, y + 2, x + width - 2, y + height - 1);
3227 gdk_draw_line (window, gc4,
3228 x + width - 1, y + 1, x + width - 1, y + height - 1);
3231 gtk_style_apply_default_background (style, window,
3232 widget && !GTK_WIDGET_NO_WINDOW (widget),
3235 y + style->ythickness,
3236 width - (style->xthickness),
3237 height - (2 * style->ythickness));
3238 gdk_draw_line (window, gc1,
3239 x, y, x + width - 2, y);
3240 gdk_draw_line (window, gc2,
3241 x + 1, y + 1, x + width - 2, y + 1);
3243 gdk_draw_line (window, gc3,
3244 x, y + height - 2, x + width - 2, y + height - 2);
3245 gdk_draw_line (window, gc3,
3246 x + width - 2, y + 2, x + width - 2, y + height - 2);
3247 gdk_draw_line (window, gc4,
3248 x, y + height - 1, x + width - 2, y + height - 1);
3249 gdk_draw_line (window, gc4,
3250 x + width - 1, y + 1, x + width - 1, y + height - 2);
3253 gtk_style_apply_default_background (style, window,
3254 widget && !GTK_WIDGET_NO_WINDOW (widget),
3256 x + style->xthickness,
3257 y + style->ythickness,
3258 width - (style->xthickness),
3259 height - (2 * style->ythickness));
3260 gdk_draw_line (window, gc1,
3261 x + 1, y, x + width - 1, y);
3262 gdk_draw_line (window, gc1,
3263 x, y + 1, x, y + height - 2);
3264 gdk_draw_line (window, gc2,
3265 x + 1, y + 1, x + width - 1, y + 1);
3266 gdk_draw_line (window, gc2,
3267 x + 1, y + 1, x + 1, y + height - 2);
3269 gdk_draw_line (window, gc3,
3270 x + 2, y + height - 2, x + width - 1, y + height - 2);
3271 gdk_draw_line (window, gc4,
3272 x + 1, y + height - 1, x + width - 1, y + height - 1);
3279 gdk_gc_set_clip_rectangle (gc1, NULL);
3280 gdk_gc_set_clip_rectangle (gc2, NULL);
3281 gdk_gc_set_clip_rectangle (gc3, NULL);
3282 gdk_gc_set_clip_rectangle (gc4, NULL);
3287 gtk_default_draw_focus (GtkStyle *style,
3291 const gchar *detail,
3297 g_return_if_fail (GTK_IS_STYLE (style));
3298 g_return_if_fail (window != NULL);
3300 if (width == -1 && height == -1)
3302 gdk_window_get_size (window, &width, &height);
3306 else if (width == -1)
3308 gdk_window_get_size (window, &width, NULL);
3311 else if (height == -1)
3313 gdk_window_get_size (window, NULL, &height);
3318 gdk_gc_set_clip_rectangle (style->black_gc, area);
3320 if (detail && !strcmp (detail, "add-mode"))
3322 gdk_gc_set_line_attributes (style->black_gc, 1, GDK_LINE_ON_OFF_DASH, 0, 0);
3323 gdk_gc_set_dashes (style->black_gc, 0, "\4\4", 2);
3325 gdk_draw_rectangle (window,
3326 style->black_gc, FALSE,
3327 x, y, width, height);
3329 gdk_gc_set_line_attributes (style->black_gc, 1, GDK_LINE_SOLID, 0, 0);
3333 gdk_draw_rectangle (window,
3334 style->black_gc, FALSE,
3335 x, y, width, height);
3339 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
3343 gtk_default_draw_slider (GtkStyle *style,
3345 GtkStateType state_type,
3346 GtkShadowType shadow_type,
3349 const gchar *detail,
3354 GtkOrientation orientation)
3356 g_return_if_fail (GTK_IS_STYLE (style));
3357 g_return_if_fail (window != NULL);
3359 if (width == -1 && height == -1)
3360 gdk_window_get_size (window, &width, &height);
3361 else if (width == -1)
3362 gdk_window_get_size (window, &width, NULL);
3363 else if (height == -1)
3364 gdk_window_get_size (window, NULL, &height);
3366 gtk_paint_box (style, window, state_type, shadow_type,
3367 area, widget, detail, x, y, width, height);
3369 if (orientation == GTK_ORIENTATION_HORIZONTAL)
3370 gtk_paint_vline (style, window, state_type, area, widget, detail,
3372 height - style->ythickness - 1, width / 2);
3374 gtk_paint_hline (style, window, state_type, area, widget, detail,
3376 width - style->xthickness - 1, height / 2);
3380 draw_dot (GdkWindow *window,
3388 size = CLAMP (size, 2, 3);
3392 gdk_draw_point (window, light_gc, x, y);
3393 gdk_draw_point (window, light_gc, x+1, y+1);
3395 else if (size == 3);
3397 gdk_draw_point (window, light_gc, x, y);
3398 gdk_draw_point (window, light_gc, x+1, y);
3399 gdk_draw_point (window, light_gc, x, y+1);
3400 gdk_draw_point (window, dark_gc, x+1, y+2);
3401 gdk_draw_point (window, dark_gc, x+2, y+1);
3402 gdk_draw_point (window, dark_gc, x+2, y+2);
3407 gtk_default_draw_handle (GtkStyle *style,
3409 GtkStateType state_type,
3410 GtkShadowType shadow_type,
3413 const gchar *detail,
3418 GtkOrientation orientation)
3421 gint xthick, ythick;
3422 GdkGC *light_gc, *dark_gc;
3427 g_return_if_fail (GTK_IS_STYLE (style));
3428 g_return_if_fail (window != NULL);
3430 if (width == -1 && height == -1)
3431 gdk_window_get_size (window, &width, &height);
3432 else if (width == -1)
3433 gdk_window_get_size (window, &width, NULL);
3434 else if (height == -1)
3435 gdk_window_get_size (window, NULL, &height);
3437 gtk_paint_box (style, window, state_type, shadow_type, area, widget,
3438 detail, x, y, width, height);
3441 if (!strcmp (detail, "paned"))
3443 /* we want to ignore the shadow border in paned widgets */
3447 light_gc = style->light_gc[state_type];
3448 dark_gc = style->black_gc;
3452 xthick = style->xthickness;
3453 ythick = style->ythickness;
3455 light_gc = style->light_gc[state_type];
3456 dark_gc = style->dark_gc[state_type];
3459 rect.x = x + xthick;
3460 rect.y = y + ythick;
3461 rect.width = width - (xthick * 2);
3462 rect.height = height - (ythick * 2);
3465 intersect = gdk_rectangle_intersect (area, &rect, &dest);
3475 gdk_gc_set_clip_rectangle (light_gc, &dest);
3476 gdk_gc_set_clip_rectangle (dark_gc, &dest);
3478 if (!strcmp (detail, "paned"))
3483 gdk_window_get_size (window, &window_width, &window_height);
3485 if (orientation == GTK_ORIENTATION_HORIZONTAL)
3486 for (xx = window_width/2 - 15; xx <= window_width/2 + 15; xx += 5)
3487 draw_dot (window, light_gc, dark_gc, xx, window_height/2 - 1, 3);
3489 for (yy = window_height/2 - 15; yy <= window_height/2 + 15; yy += 5)
3490 draw_dot (window, light_gc, dark_gc, window_width/2 - 1, yy, 3);
3494 for (yy = y + ythick; yy < (y + height - ythick); yy += 3)
3495 for (xx = x + xthick; xx < (x + width - xthick); xx += 6)
3497 draw_dot (window, light_gc, dark_gc, xx, yy, 2);
3498 draw_dot (window, light_gc, dark_gc, xx + 3, yy + 1, 2);
3502 gdk_gc_set_clip_rectangle (light_gc, NULL);
3503 gdk_gc_set_clip_rectangle (dark_gc, NULL);
3507 gtk_default_draw_expander (GtkStyle *style,
3509 GtkStateType state_type,
3512 const gchar *detail,
3517 /* FIXME replace macro with a style property */
3524 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], area);
3525 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], area);
3531 points[0].y = y + (PM_SIZE + 2) / 6;
3532 points[1].x = points[0].x + 1 * (PM_SIZE + 2);
3533 points[1].y = points[0].y;
3534 points[2].x = (points[0].x + 1 * (PM_SIZE + 2) / 2);
3535 points[2].y = y + 2 * (PM_SIZE + 2) / 3;
3539 points[0].x = x + 1 * ((PM_SIZE + 2) / 6 + 2);
3540 points[0].y = y - 1;
3541 points[1].x = points[0].x;
3542 points[1].y = points[0].y + (PM_SIZE + 2);
3543 points[2].x = (points[0].x + 1 * (2 * (PM_SIZE + 2) / 3 - 1));
3544 points[2].y = points[0].y + (PM_SIZE + 2) / 2;
3547 gdk_draw_polygon (window, style->base_gc[GTK_STATE_NORMAL],
3549 gdk_draw_polygon (window, style->fg_gc[GTK_STATE_NORMAL],
3555 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], NULL);
3556 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], NULL);
3562 typedef struct _ByteRange ByteRange;
3571 range_new (guint start,
3574 ByteRange *br = g_new (ByteRange, 1);
3583 get_insensitive_layout (PangoLayout *layout)
3585 GSList *embossed_ranges = NULL;
3586 GSList *stippled_ranges = NULL;
3587 PangoLayoutIter *iter;
3588 GSList *tmp_list = NULL;
3589 PangoLayout *new_layout;
3590 PangoAttrList *attrs;
3591 GdkBitmap *stipple = NULL;
3593 iter = pango_layout_get_iter (layout);
3597 PangoLayoutRun *run;
3598 PangoAttribute *attr;
3599 gboolean need_stipple = FALSE;
3602 run = pango_layout_iter_get_run (iter);
3606 tmp_list = run->item->extra_attrs;
3608 while (tmp_list != NULL)
3610 attr = tmp_list->data;
3611 switch (attr->klass->type)
3613 case PANGO_ATTR_FOREGROUND:
3614 case PANGO_ATTR_BACKGROUND:
3615 need_stipple = TRUE;
3625 tmp_list = g_slist_next (tmp_list);
3628 br = range_new (run->item->offset, run->item->offset + run->item->length);
3631 stippled_ranges = g_slist_prepend (stippled_ranges, br);
3633 embossed_ranges = g_slist_prepend (embossed_ranges, br);
3636 while (pango_layout_iter_next_run (iter));
3638 pango_layout_iter_free (iter);
3640 new_layout = pango_layout_copy (layout);
3642 attrs = pango_layout_get_attributes (new_layout);
3646 /* Create attr list if there wasn't one */
3647 attrs = pango_attr_list_new ();
3648 pango_layout_set_attributes (new_layout, attrs);
3649 pango_attr_list_unref (attrs);
3652 tmp_list = embossed_ranges;
3653 while (tmp_list != NULL)
3655 PangoAttribute *attr;
3656 ByteRange *br = tmp_list->data;
3658 attr = gdk_pango_attr_embossed_new (TRUE);
3660 attr->start_index = br->start;
3661 attr->end_index = br->end;
3663 pango_attr_list_change (attrs, attr);
3667 tmp_list = g_slist_next (tmp_list);
3670 g_slist_free (embossed_ranges);
3672 tmp_list = stippled_ranges;
3673 while (tmp_list != NULL)
3675 PangoAttribute *attr;
3676 ByteRange *br = tmp_list->data;
3678 if (stipple == NULL)
3680 #define gray50_width 2
3681 #define gray50_height 2
3682 static char gray50_bits[] = {
3686 stipple = gdk_bitmap_create_from_data (NULL,
3687 gray50_bits, gray50_width,
3691 attr = gdk_pango_attr_stipple_new (stipple);
3693 attr->start_index = br->start;
3694 attr->end_index = br->end;
3696 pango_attr_list_change (attrs, attr);
3700 tmp_list = g_slist_next (tmp_list);
3703 g_slist_free (stippled_ranges);
3706 g_object_unref (G_OBJECT (stipple));
3712 gtk_default_draw_layout (GtkStyle *style,
3714 GtkStateType state_type,
3717 const gchar *detail,
3720 PangoLayout *layout)
3722 g_return_if_fail (GTK_IS_STYLE (style));
3723 g_return_if_fail (window != NULL);
3726 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], area);
3728 if (state_type == GTK_STATE_INSENSITIVE)
3732 ins = get_insensitive_layout (layout);
3734 gdk_draw_layout (window, style->fg_gc[state_type], x, y, ins);
3736 g_object_unref (G_OBJECT (ins));
3740 gdk_draw_layout (window, style->fg_gc[state_type], x, y, layout);
3744 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], NULL);
3748 gtk_style_shade (GdkColor *a,
3756 red = (gdouble) a->red / 65535.0;
3757 green = (gdouble) a->green / 65535.0;
3758 blue = (gdouble) a->blue / 65535.0;
3760 rgb_to_hls (&red, &green, &blue);
3765 else if (green < 0.0)
3771 else if (blue < 0.0)
3774 hls_to_rgb (&red, &green, &blue);
3776 b->red = red * 65535.0;
3777 b->green = green * 65535.0;
3778 b->blue = blue * 65535.0;
3782 rgb_to_hls (gdouble *r,
3823 l = (max + min) / 2;
3830 s = (max - min) / (max + min);
3832 s = (max - min) / (2 - max - min);
3836 h = (green - blue) / delta;
3837 else if (green == max)
3838 h = 2 + (blue - red) / delta;
3839 else if (blue == max)
3840 h = 4 + (red - green) / delta;
3853 hls_to_rgb (gdouble *h,
3866 if (lightness <= 0.5)
3867 m2 = lightness * (1 + saturation);
3869 m2 = lightness + saturation - lightness * saturation;
3870 m1 = 2 * lightness - m2;
3872 if (saturation == 0)
3887 r = m1 + (m2 - m1) * hue / 60;
3891 r = m1 + (m2 - m1) * (240 - hue) / 60;
3902 g = m1 + (m2 - m1) * hue / 60;
3906 g = m1 + (m2 - m1) * (240 - hue) / 60;
3917 b = m1 + (m2 - m1) * hue / 60;
3921 b = m1 + (m2 - m1) * (240 - hue) / 60;
3932 gtk_paint_hline (GtkStyle *style,
3934 GtkStateType state_type,
3937 const gchar *detail,
3942 g_return_if_fail (GTK_IS_STYLE (style));
3943 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
3945 GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, area, widget, detail, x1, x2, y);
3949 gtk_paint_vline (GtkStyle *style,
3951 GtkStateType state_type,
3954 const gchar *detail,
3959 g_return_if_fail (GTK_IS_STYLE (style));
3960 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
3962 GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, area, widget, detail, y1, y2, x);
3966 gtk_paint_shadow (GtkStyle *style,
3968 GtkStateType state_type,
3969 GtkShadowType shadow_type,
3972 const gchar *detail,
3978 g_return_if_fail (GTK_IS_STYLE (style));
3979 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
3981 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
3985 gtk_paint_polygon (GtkStyle *style,
3987 GtkStateType state_type,
3988 GtkShadowType shadow_type,
3991 const gchar *detail,
3996 g_return_if_fail (GTK_IS_STYLE (style));
3997 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
3999 GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, area, widget, detail, points, npoints, fill);
4003 gtk_paint_arrow (GtkStyle *style,
4005 GtkStateType state_type,
4006 GtkShadowType shadow_type,
4009 const gchar *detail,
4010 GtkArrowType arrow_type,
4017 g_return_if_fail (GTK_IS_STYLE (style));
4018 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
4020 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, area, widget, detail, arrow_type, fill, x, y, width, height);
4024 gtk_paint_diamond (GtkStyle *style,
4026 GtkStateType state_type,
4027 GtkShadowType shadow_type,
4030 const gchar *detail,
4036 g_return_if_fail (GTK_IS_STYLE (style));
4037 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
4039 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4043 gtk_paint_string (GtkStyle *style,
4045 GtkStateType state_type,
4048 const gchar *detail,
4051 const gchar *string)
4053 g_return_if_fail (GTK_IS_STYLE (style));
4054 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
4056 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, area, widget, detail, x, y, string);
4060 gtk_paint_box (GtkStyle *style,
4062 GtkStateType state_type,
4063 GtkShadowType shadow_type,
4066 const gchar *detail,
4072 g_return_if_fail (GTK_IS_STYLE (style));
4073 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
4075 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4079 gtk_paint_flat_box (GtkStyle *style,
4081 GtkStateType state_type,
4082 GtkShadowType shadow_type,
4085 const gchar *detail,
4091 g_return_if_fail (GTK_IS_STYLE (style));
4092 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
4094 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4098 gtk_paint_check (GtkStyle *style,
4100 GtkStateType state_type,
4101 GtkShadowType shadow_type,
4104 const gchar *detail,
4110 g_return_if_fail (GTK_IS_STYLE (style));
4111 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
4113 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4117 gtk_paint_option (GtkStyle *style,
4119 GtkStateType state_type,
4120 GtkShadowType shadow_type,
4123 const gchar *detail,
4129 g_return_if_fail (GTK_IS_STYLE (style));
4130 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
4132 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4136 gtk_paint_tab (GtkStyle *style,
4138 GtkStateType state_type,
4139 GtkShadowType shadow_type,
4142 const gchar *detail,
4148 g_return_if_fail (GTK_IS_STYLE (style));
4149 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
4151 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4155 gtk_paint_shadow_gap (GtkStyle *style,
4157 GtkStateType state_type,
4158 GtkShadowType shadow_type,
4166 GtkPositionType gap_side,
4170 g_return_if_fail (GTK_IS_STYLE (style));
4171 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
4173 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);
4178 gtk_paint_box_gap (GtkStyle *style,
4180 GtkStateType state_type,
4181 GtkShadowType shadow_type,
4189 GtkPositionType gap_side,
4193 g_return_if_fail (GTK_IS_STYLE (style));
4194 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
4196 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);
4200 gtk_paint_extension (GtkStyle *style,
4202 GtkStateType state_type,
4203 GtkShadowType shadow_type,
4211 GtkPositionType gap_side)
4213 g_return_if_fail (GTK_IS_STYLE (style));
4214 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
4216 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, gap_side);
4220 gtk_paint_focus (GtkStyle *style,
4224 const gchar *detail,
4230 g_return_if_fail (GTK_IS_STYLE (style));
4231 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
4233 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, area, widget, detail, x, y, width, height);
4237 gtk_paint_slider (GtkStyle *style,
4239 GtkStateType state_type,
4240 GtkShadowType shadow_type,
4243 const gchar *detail,
4248 GtkOrientation orientation)
4250 g_return_if_fail (GTK_IS_STYLE (style));
4251 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
4253 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
4257 gtk_paint_handle (GtkStyle *style,
4259 GtkStateType state_type,
4260 GtkShadowType shadow_type,
4263 const gchar *detail,
4268 GtkOrientation orientation)
4270 g_return_if_fail (GTK_IS_STYLE (style));
4271 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
4273 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
4277 gtk_paint_expander (GtkStyle *style,
4279 GtkStateType state_type,
4282 const gchar *detail,
4287 g_return_if_fail (GTK_IS_STYLE (style));
4288 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
4290 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type, area,
4291 widget, detail, x, y, is_open);
4295 gtk_paint_layout (GtkStyle *style,
4297 GtkStateType state_type,
4300 const gchar *detail,
4303 PangoLayout *layout)
4305 g_return_if_fail (GTK_IS_STYLE (style));
4306 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
4308 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, area,
4309 widget, detail, x, y, layout);