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
40 /* --- typedefs & structures --- */
48 /* --- prototypes --- */
49 static void gtk_style_init (GtkStyle *style);
50 static void gtk_style_class_init (GtkStyleClass *klass);
51 static void gtk_style_finalize (GObject *object);
52 static void gtk_style_realize (GtkStyle *style,
53 GdkColormap *colormap);
54 static void gtk_style_real_realize (GtkStyle *style);
55 static void gtk_style_real_unrealize (GtkStyle *style);
56 static void gtk_style_real_copy (GtkStyle *style,
58 static void gtk_style_real_set_background (GtkStyle *style,
60 GtkStateType state_type);
61 static GtkStyle *gtk_style_real_clone (GtkStyle *style);
62 static void gtk_style_real_init_from_rc (GtkStyle *style,
63 GtkRcStyle *rc_style);
64 static GdkPixbuf *gtk_default_render_icon (GtkStyle *style,
65 const GtkIconSource *source,
66 GtkTextDirection direction,
71 static void gtk_default_draw_hline (GtkStyle *style,
73 GtkStateType state_type,
80 static void gtk_default_draw_vline (GtkStyle *style,
82 GtkStateType state_type,
89 static void gtk_default_draw_shadow (GtkStyle *style,
91 GtkStateType state_type,
92 GtkShadowType shadow_type,
100 static void gtk_default_draw_polygon (GtkStyle *style,
102 GtkStateType state_type,
103 GtkShadowType shadow_type,
110 static void gtk_default_draw_arrow (GtkStyle *style,
112 GtkStateType state_type,
113 GtkShadowType shadow_type,
117 GtkArrowType arrow_type,
123 static void gtk_default_draw_diamond (GtkStyle *style,
125 GtkStateType state_type,
126 GtkShadowType shadow_type,
134 static void gtk_default_draw_string (GtkStyle *style,
136 GtkStateType state_type,
142 const gchar *string);
143 static void gtk_default_draw_box (GtkStyle *style,
145 GtkStateType state_type,
146 GtkShadowType shadow_type,
154 static void gtk_default_draw_flat_box (GtkStyle *style,
156 GtkStateType state_type,
157 GtkShadowType shadow_type,
165 static void gtk_default_draw_check (GtkStyle *style,
167 GtkStateType state_type,
168 GtkShadowType shadow_type,
176 static void gtk_default_draw_option (GtkStyle *style,
178 GtkStateType state_type,
179 GtkShadowType shadow_type,
187 static void gtk_default_draw_tab (GtkStyle *style,
189 GtkStateType state_type,
190 GtkShadowType shadow_type,
198 static void gtk_default_draw_shadow_gap (GtkStyle *style,
200 GtkStateType state_type,
201 GtkShadowType shadow_type,
209 GtkPositionType gap_side,
212 static void gtk_default_draw_box_gap (GtkStyle *style,
214 GtkStateType state_type,
215 GtkShadowType shadow_type,
223 GtkPositionType gap_side,
226 static void gtk_default_draw_extension (GtkStyle *style,
228 GtkStateType state_type,
229 GtkShadowType shadow_type,
237 GtkPositionType gap_side);
238 static void gtk_default_draw_focus (GtkStyle *style,
247 static void gtk_default_draw_slider (GtkStyle *style,
249 GtkStateType state_type,
250 GtkShadowType shadow_type,
258 GtkOrientation orientation);
259 static void gtk_default_draw_handle (GtkStyle *style,
261 GtkStateType state_type,
262 GtkShadowType shadow_type,
270 GtkOrientation orientation);
271 static void gtk_default_draw_expander (GtkStyle *style,
273 GtkStateType state_type,
280 static void gtk_default_draw_layout (GtkStyle *style,
282 GtkStateType state_type,
288 PangoLayout *layout);
289 static void gtk_default_draw_resize_grip (GtkStyle *style,
291 GtkStateType state_type,
301 static void gtk_style_shade (GdkColor *a,
304 static void rgb_to_hls (gdouble *r,
307 static void hls_to_rgb (gdouble *h,
312 /* --- variables --- */
313 static GdkColor gtk_default_normal_fg = { 0, 0, 0, 0 };
314 static GdkColor gtk_default_active_fg = { 0, 0, 0, 0 };
315 static GdkColor gtk_default_prelight_fg = { 0, 0, 0, 0 };
316 static GdkColor gtk_default_selected_fg = { 0, 0xffff, 0xffff, 0xffff };
317 static GdkColor gtk_default_insensitive_fg = { 0, 0x7530, 0x7530, 0x7530 };
319 static GdkColor gtk_default_normal_bg = { 0, 0xd6d6, 0xd6d6, 0xd6d6 };
320 static GdkColor gtk_default_active_bg = { 0, 0xc350, 0xc350, 0xc350 };
321 static GdkColor gtk_default_prelight_bg = { 0, 0xea60, 0xea60, 0xea60 };
322 static GdkColor gtk_default_selected_bg = { 0, 0, 0, 0x9c40 };
323 static GdkColor gtk_default_insensitive_bg = { 0, 0xd6d6, 0xd6d6, 0xd6d6 };
325 static gpointer parent_class = NULL;
326 static GdkFont *static_default_font = NULL;
329 /* --- functions --- */
331 gtk_style_get_type (void)
333 static GType style_type = 0;
337 static const GTypeInfo style_info =
339 sizeof (GtkStyleClass),
340 (GBaseInitFunc) NULL,
341 (GBaseFinalizeFunc) NULL,
342 (GClassInitFunc) gtk_style_class_init,
343 NULL, /* class_finalize */
344 NULL, /* class_data */
347 (GInstanceInitFunc) gtk_style_init,
350 style_type = g_type_register_static (G_TYPE_OBJECT,
359 gtk_style_init (GtkStyle *style)
363 style->font_desc = pango_font_description_from_string ("Sans 10");
365 if (!static_default_font)
367 static_default_font = gdk_font_from_description (style->font_desc);
369 if (!static_default_font)
370 static_default_font = gdk_font_load ("fixed");
372 if (!static_default_font)
373 g_error ("Unable to load \"fixed\" font");
376 style->font = static_default_font;
377 gdk_font_ref (style->font);
379 style->attach_count = 0;
380 style->colormap = NULL;
383 style->black.red = 0;
384 style->black.green = 0;
385 style->black.blue = 0;
387 style->white.red = 65535;
388 style->white.green = 65535;
389 style->white.blue = 65535;
391 style->black_gc = NULL;
392 style->white_gc = NULL;
394 style->fg[GTK_STATE_NORMAL] = gtk_default_normal_fg;
395 style->fg[GTK_STATE_ACTIVE] = gtk_default_active_fg;
396 style->fg[GTK_STATE_PRELIGHT] = gtk_default_prelight_fg;
397 style->fg[GTK_STATE_SELECTED] = gtk_default_selected_fg;
398 style->fg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
400 style->bg[GTK_STATE_NORMAL] = gtk_default_normal_bg;
401 style->bg[GTK_STATE_ACTIVE] = gtk_default_active_bg;
402 style->bg[GTK_STATE_PRELIGHT] = gtk_default_prelight_bg;
403 style->bg[GTK_STATE_SELECTED] = gtk_default_selected_bg;
404 style->bg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_bg;
406 for (i = 0; i < 4; i++)
408 style->text[i] = style->fg[i];
409 style->base[i] = style->white;
412 style->base[GTK_STATE_INSENSITIVE] = gtk_default_prelight_bg;
413 style->text[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
415 for (i = 0; i < 5; i++)
416 style->bg_pixmap[i] = NULL;
418 style->rc_style = NULL;
420 for (i = 0; i < 5; i++)
422 style->fg_gc[i] = NULL;
423 style->bg_gc[i] = NULL;
424 style->light_gc[i] = NULL;
425 style->dark_gc[i] = NULL;
426 style->mid_gc[i] = NULL;
427 style->text_gc[i] = NULL;
428 style->base_gc[i] = NULL;
431 style->xthickness = 2;
432 style->ythickness = 2;
434 style->property_cache = NULL;
438 gtk_style_class_init (GtkStyleClass *klass)
440 GObjectClass *object_class = G_OBJECT_CLASS (klass);
442 parent_class = g_type_class_peek_parent (klass);
444 object_class->finalize = gtk_style_finalize;
446 klass->clone = gtk_style_real_clone;
447 klass->copy = gtk_style_real_copy;
448 klass->init_from_rc = gtk_style_real_init_from_rc;
449 klass->realize = gtk_style_real_realize;
450 klass->unrealize = gtk_style_real_unrealize;
451 klass->set_background = gtk_style_real_set_background;
452 klass->render_icon = gtk_default_render_icon;
454 klass->draw_hline = gtk_default_draw_hline;
455 klass->draw_vline = gtk_default_draw_vline;
456 klass->draw_shadow = gtk_default_draw_shadow;
457 klass->draw_polygon = gtk_default_draw_polygon;
458 klass->draw_arrow = gtk_default_draw_arrow;
459 klass->draw_diamond = gtk_default_draw_diamond;
460 klass->draw_string = gtk_default_draw_string;
461 klass->draw_box = gtk_default_draw_box;
462 klass->draw_flat_box = gtk_default_draw_flat_box;
463 klass->draw_check = gtk_default_draw_check;
464 klass->draw_option = gtk_default_draw_option;
465 klass->draw_tab = gtk_default_draw_tab;
466 klass->draw_shadow_gap = gtk_default_draw_shadow_gap;
467 klass->draw_box_gap = gtk_default_draw_box_gap;
468 klass->draw_extension = gtk_default_draw_extension;
469 klass->draw_focus = gtk_default_draw_focus;
470 klass->draw_slider = gtk_default_draw_slider;
471 klass->draw_handle = gtk_default_draw_handle;
472 klass->draw_expander = gtk_default_draw_expander;
473 klass->draw_layout = gtk_default_draw_layout;
474 klass->draw_resize_grip = gtk_default_draw_resize_grip;
478 gtk_style_finalize (GObject *object)
480 GtkStyle *style = GTK_STYLE (object);
482 g_return_if_fail (style->attach_count == 0);
484 if (style->property_cache)
488 for (i = 0; i < style->property_cache->n_nodes; i++)
490 PropertyValue *node = g_bsearch_array_get_nth (style->property_cache, i);
492 g_param_spec_unref (node->pspec);
493 g_value_unset (&node->value);
495 g_bsearch_array_destroy (style->property_cache);
496 style->property_cache = NULL;
501 if (style->styles->data != style)
502 g_slist_remove (style->styles, style);
505 GSList *tmp_list = style->styles->next;
509 GTK_STYLE (tmp_list->data)->styles = style->styles->next;
510 tmp_list = tmp_list->next;
512 g_slist_free_1 (style->styles);
516 gdk_font_unref (style->font);
517 pango_font_description_free (style->font_desc);
520 gtk_rc_style_unref (style->rc_style);
522 G_OBJECT_CLASS (parent_class)->finalize (object);
527 gtk_style_copy (GtkStyle *style)
531 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
533 new_style = GTK_STYLE_GET_CLASS (style)->clone (style);
534 GTK_STYLE_GET_CLASS (style)->copy (new_style, style);
540 gtk_style_duplicate (GtkStyle *style)
544 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
546 new_style = gtk_style_copy (style);
548 style->styles = g_slist_append (style->styles, new_style);
549 new_style->styles = style->styles;
559 style = g_object_new (GTK_TYPE_STYLE, NULL);
564 /*************************************************************
566 * Attach a style to a window; this process allocates the
567 * colors and creates the GC's for the style - it specializes
568 * it to a particular visual and colormap. The process
569 * may involve the creation of a new style if the style
570 * has already been attached to a window with a different
571 * style and colormap.
576 * Either the style parameter, or a newly created style.
577 * If the style is newly created, the style parameter
578 * will be dereferenced, and the new style will have
579 * a reference count belonging to the caller.
581 * FIXME: The sequence -
582 * create a style => s1
583 * attach s1 to v1, c1 => s1
584 * attach s1 to v2, c2 => s2
585 * detach s1 from v1, c1
586 * attach s1 to v2, c2 => s3
587 * results in two separate, unlinked styles s2 and s3 which
588 * are identical and could be shared. To fix this, we would
589 * want to never remove a style from the list of linked
590 * styles as long as as it has a reference count. However, the
591 * disadvantage of doing it this way means that we would need two
592 * passes through the linked list when attaching (one to check for
593 * matching styles, one to look for empty unattached styles - but
594 * it will almost never be longer than 2 elements.
595 *************************************************************/
598 gtk_style_attach (GtkStyle *style,
602 GtkStyle *new_style = NULL;
603 GdkColormap *colormap;
605 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
606 g_return_val_if_fail (window != NULL, NULL);
608 colormap = gdk_window_get_colormap (window);
611 style->styles = g_slist_append (NULL, style);
613 styles = style->styles;
616 new_style = styles->data;
618 if (new_style->attach_count == 0)
620 gtk_style_realize (new_style, colormap);
623 else if (new_style->colormap == colormap)
627 styles = styles->next;
632 new_style = gtk_style_duplicate (style);
633 gtk_style_realize (new_style, colormap);
636 /* A style gets a refcount from being attached */
637 if (new_style->attach_count == 0)
638 gtk_style_ref (new_style);
640 /* Another refcount belongs to the parent */
641 if (style != new_style)
643 gtk_style_unref (style);
644 gtk_style_ref (new_style);
647 new_style->attach_count++;
653 gtk_style_detach (GtkStyle *style)
655 g_return_if_fail (GTK_IS_STYLE (style));
657 style->attach_count -= 1;
658 if (style->attach_count == 0)
660 GTK_STYLE_GET_CLASS (style)->unrealize (style);
662 gdk_colormap_unref (style->colormap);
663 style->colormap = NULL;
665 gtk_style_unref (style);
670 gtk_style_ref (GtkStyle *style)
672 return (GtkStyle *) g_object_ref (G_OBJECT (style));
676 gtk_style_unref (GtkStyle *style)
678 g_object_unref (G_OBJECT (style));
682 gtk_style_realize (GtkStyle *style,
683 GdkColormap *colormap)
685 g_return_if_fail (GTK_IS_STYLE (style));
686 g_return_if_fail (GDK_IS_COLORMAP (colormap));
688 style->colormap = gdk_colormap_ref (colormap);
689 style->depth = gdk_colormap_get_visual (colormap)->depth;
691 GTK_STYLE_GET_CLASS (style)->realize (style);
695 gtk_style_lookup_icon_set (GtkStyle *style,
696 const char *stock_id)
700 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
701 g_return_val_if_fail (stock_id != NULL, NULL);
703 iter = style->icon_factories;
706 GtkIconSet *icon_set = gtk_icon_factory_lookup (GTK_ICON_FACTORY (iter->data),
711 iter = g_slist_next (iter);
714 return gtk_icon_factory_lookup_default (stock_id);
718 gtk_draw_hline (GtkStyle *style,
720 GtkStateType state_type,
725 g_return_if_fail (GTK_IS_STYLE (style));
726 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
728 GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, NULL, NULL, NULL, x1, x2, y);
733 gtk_draw_vline (GtkStyle *style,
735 GtkStateType state_type,
740 g_return_if_fail (GTK_IS_STYLE (style));
741 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
743 GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, NULL, NULL, NULL, y1, y2, x);
748 gtk_draw_shadow (GtkStyle *style,
750 GtkStateType state_type,
751 GtkShadowType shadow_type,
757 g_return_if_fail (GTK_IS_STYLE (style));
758 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
760 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
764 gtk_draw_polygon (GtkStyle *style,
766 GtkStateType state_type,
767 GtkShadowType shadow_type,
772 g_return_if_fail (GTK_IS_STYLE (style));
773 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_polygon != NULL);
775 GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, NULL, NULL, NULL, points, npoints, fill);
779 gtk_draw_arrow (GtkStyle *style,
781 GtkStateType state_type,
782 GtkShadowType shadow_type,
783 GtkArrowType arrow_type,
790 g_return_if_fail (GTK_IS_STYLE (style));
791 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
793 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, NULL, NULL, NULL, arrow_type, fill, x, y, width, height);
798 gtk_draw_diamond (GtkStyle *style,
800 GtkStateType state_type,
801 GtkShadowType shadow_type,
807 g_return_if_fail (GTK_IS_STYLE (style));
808 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
810 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
815 gtk_draw_string (GtkStyle *style,
817 GtkStateType state_type,
822 g_return_if_fail (GTK_IS_STYLE (style));
823 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
825 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, NULL, NULL, NULL, x, y, string);
829 gtk_draw_box (GtkStyle *style,
831 GtkStateType state_type,
832 GtkShadowType shadow_type,
838 g_return_if_fail (GTK_IS_STYLE (style));
839 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
841 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
845 gtk_draw_flat_box (GtkStyle *style,
847 GtkStateType state_type,
848 GtkShadowType shadow_type,
854 g_return_if_fail (GTK_IS_STYLE (style));
855 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
857 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
861 gtk_draw_check (GtkStyle *style,
863 GtkStateType state_type,
864 GtkShadowType shadow_type,
870 g_return_if_fail (GTK_IS_STYLE (style));
871 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
873 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
877 gtk_draw_option (GtkStyle *style,
879 GtkStateType state_type,
880 GtkShadowType shadow_type,
886 g_return_if_fail (GTK_IS_STYLE (style));
887 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
889 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
893 gtk_draw_tab (GtkStyle *style,
895 GtkStateType state_type,
896 GtkShadowType shadow_type,
902 g_return_if_fail (GTK_IS_STYLE (style));
903 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
905 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
909 gtk_draw_shadow_gap (GtkStyle *style,
911 GtkStateType state_type,
912 GtkShadowType shadow_type,
917 GtkPositionType gap_side,
921 g_return_if_fail (GTK_IS_STYLE (style));
922 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
924 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);
928 gtk_draw_box_gap (GtkStyle *style,
930 GtkStateType state_type,
931 GtkShadowType shadow_type,
936 GtkPositionType gap_side,
940 g_return_if_fail (GTK_IS_STYLE (style));
941 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
943 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);
947 gtk_draw_extension (GtkStyle *style,
949 GtkStateType state_type,
950 GtkShadowType shadow_type,
955 GtkPositionType gap_side)
957 g_return_if_fail (GTK_IS_STYLE (style));
958 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
960 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, gap_side);
964 gtk_draw_focus (GtkStyle *style,
971 g_return_if_fail (GTK_IS_STYLE (style));
972 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
974 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, NULL, NULL, NULL, x, y, width, height);
978 gtk_draw_slider (GtkStyle *style,
980 GtkStateType state_type,
981 GtkShadowType shadow_type,
986 GtkOrientation orientation)
988 g_return_if_fail (GTK_IS_STYLE (style));
989 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
991 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
995 gtk_draw_handle (GtkStyle *style,
997 GtkStateType state_type,
998 GtkShadowType shadow_type,
1003 GtkOrientation orientation)
1005 g_return_if_fail (GTK_IS_STYLE (style));
1006 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
1008 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
1012 gtk_draw_expander (GtkStyle *style,
1014 GtkStateType state_type,
1019 g_return_if_fail (GTK_IS_STYLE (style));
1020 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
1022 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type,
1028 gtk_draw_layout (GtkStyle *style,
1030 GtkStateType state_type,
1033 PangoLayout *layout)
1035 g_return_if_fail (GTK_IS_STYLE (style));
1036 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
1038 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type,
1044 gtk_draw_resize_grip (GtkStyle *style,
1046 GtkStateType state_type,
1053 g_return_if_fail (GTK_IS_STYLE (style));
1054 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
1056 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, window, state_type,
1059 x, y, width, height);
1064 gtk_style_set_background (GtkStyle *style,
1066 GtkStateType state_type)
1068 g_return_if_fail (GTK_IS_STYLE (style));
1069 g_return_if_fail (window != NULL);
1071 GTK_STYLE_GET_CLASS (style)->set_background (style, window, state_type);
1074 /* Default functions */
1076 gtk_style_real_clone (GtkStyle *style)
1078 return GTK_STYLE (g_object_new (G_OBJECT_TYPE (style), NULL));
1082 gtk_style_real_copy (GtkStyle *style,
1087 for (i = 0; i < 5; i++)
1089 style->fg[i] = src->fg[i];
1090 style->bg[i] = src->bg[i];
1091 style->text[i] = src->text[i];
1092 style->base[i] = src->base[i];
1094 style->bg_pixmap[i] = src->bg_pixmap[i];
1098 gdk_font_unref (style->font);
1099 style->font = src->font;
1101 gdk_font_ref (style->font);
1103 if (style->font_desc)
1104 pango_font_description_free (style->font_desc);
1106 style->font_desc = pango_font_description_copy (src->font_desc);
1108 style->font_desc = NULL;
1110 style->xthickness = src->xthickness;
1111 style->ythickness = src->ythickness;
1113 if (style->rc_style)
1114 gtk_rc_style_unref (style->rc_style);
1115 style->rc_style = src->rc_style;
1117 gtk_rc_style_ref (src->rc_style);
1119 /* don't copy, just clear cache */
1120 if (style->property_cache)
1124 for (i = 0; i < style->property_cache->n_nodes; i++)
1126 PropertyValue *node = g_bsearch_array_get_nth (style->property_cache, i);
1128 g_param_spec_unref (node->pspec);
1129 g_value_unset (&node->value);
1131 g_bsearch_array_destroy (style->property_cache);
1132 style->property_cache = NULL;
1137 gtk_style_real_init_from_rc (GtkStyle *style,
1138 GtkRcStyle *rc_style)
1143 /* cache _should_ be still empty */
1144 if (style->property_cache)
1148 for (i = 0; i < style->property_cache->n_nodes; i++)
1150 PropertyValue *node = g_bsearch_array_get_nth (style->property_cache, i);
1152 g_param_spec_unref (node->pspec);
1153 g_value_unset (&node->value);
1155 g_bsearch_array_destroy (style->property_cache);
1156 style->property_cache = NULL;
1159 if (rc_style->font_desc)
1161 pango_font_description_free (style->font_desc);
1162 style->font_desc = pango_font_description_copy (rc_style->font_desc);
1164 old_font = style->font;
1165 style->font = gdk_font_from_description (style->font_desc);
1167 gdk_font_unref (old_font);
1169 style->font = old_font;
1172 for (i = 0; i < 5; i++)
1174 if (rc_style->color_flags[i] & GTK_RC_FG)
1175 style->fg[i] = rc_style->fg[i];
1176 if (rc_style->color_flags[i] & GTK_RC_BG)
1177 style->bg[i] = rc_style->bg[i];
1178 if (rc_style->color_flags[i] & GTK_RC_TEXT)
1179 style->text[i] = rc_style->text[i];
1180 if (rc_style->color_flags[i] & GTK_RC_BASE)
1181 style->base[i] = rc_style->base[i];
1184 if (rc_style->xthickness >= 0)
1185 style->xthickness = rc_style->xthickness;
1186 if (rc_style->ythickness >= 0)
1187 style->ythickness = rc_style->ythickness;
1189 if (rc_style->icon_factories)
1193 style->icon_factories = g_slist_copy (rc_style->icon_factories);
1195 iter = style->icon_factories;
1196 while (iter != NULL)
1198 g_object_ref (G_OBJECT (iter->data));
1200 iter = g_slist_next (iter);
1206 style_property_values_cmp (gconstpointer bsearch_node1,
1207 gconstpointer bsearch_node2)
1209 const PropertyValue *val1 = bsearch_node1;
1210 const PropertyValue *val2 = bsearch_node2;
1213 cmp = G_BSEARCH_ARRAY_CMP (val1->widget_type, val2->widget_type);
1215 cmp = G_BSEARCH_ARRAY_CMP (val1->pspec, val2->pspec);
1221 _gtk_style_peek_property_value (GtkStyle *style,
1224 GtkRcPropertyParser parser)
1226 PropertyValue *pcache, key = { 0, NULL, { 0, } };
1227 const GtkRcProperty *rcprop = NULL;
1229 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1230 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), NULL);
1231 g_return_val_if_fail (g_type_is_a (pspec->owner_type, GTK_TYPE_WIDGET), NULL);
1232 g_return_val_if_fail (g_type_is_a (widget_type, pspec->owner_type), NULL);
1234 /* need value cache array */
1235 if (!style->property_cache)
1236 style->property_cache = g_bsearch_array_new (sizeof (PropertyValue),
1237 style_property_values_cmp,
1239 /* lookup, or insert value if not yet present */
1240 key.widget_type = widget_type;
1242 pcache = g_bsearch_array_insert (style->property_cache, &key, FALSE);
1243 if (G_VALUE_TYPE (&pcache->value))
1244 return &pcache->value;
1246 /* cache miss, initialize value type, then set contents */
1247 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1249 /* value provided by rc style? */
1250 if (style->rc_style)
1252 GQuark prop_quark = g_quark_from_string (pspec->name);
1256 rcprop = _gtk_rc_style_lookup_rc_property (style->rc_style,
1257 g_type_qname (widget_type),
1261 widget_type = g_type_parent (widget_type);
1263 while (g_type_is_a (widget_type, pspec->owner_type));
1266 /* when supplied by rc style, we need to convert */
1269 if (G_VALUE_TYPE (&rcprop->value) == G_TYPE_GSTRING)
1273 /* value still unparsed, need to revert to user supplied parser function */
1275 gstring = g_value_get_boxed (&rcprop->value);
1277 if (!parser || !parser (pspec, gstring, &pcache->value) ||
1278 g_param_value_validate (pspec, &pcache->value))
1280 gchar *contents = g_strescape (gstring->str, NULL);
1282 g_message ("%s: failed to parse property `%s::%s' of type `%s' from rc file value \"%s\"",
1284 g_type_name (pspec->owner_type), pspec->name,
1285 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1293 /* we use the normal conversion functionality of param specs */
1294 if (!g_param_value_convert (pspec, &rcprop->value, &pcache->value, TRUE))
1296 gchar *contents = g_strdup_value_contents (&rcprop->value);
1298 g_message ("%s: failed to retrive property `%s::%s' of type `%s' from rc file value \"%s\" of type `%s'",
1300 g_type_name (pspec->owner_type), pspec->name,
1301 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1303 G_VALUE_TYPE_NAME (&rcprop->value));
1310 /* not supplied by rc style (or conversion failed), revert to default */
1312 g_param_value_set_default (pspec, &pcache->value);
1314 return &pcache->value;
1318 gtk_style_real_realize (GtkStyle *style)
1320 GdkGCValues gc_values;
1321 GdkGCValuesMask gc_values_mask;
1325 for (i = 0; i < 5; i++)
1327 gtk_style_shade (&style->bg[i], &style->light[i], LIGHTNESS_MULT);
1328 gtk_style_shade (&style->bg[i], &style->dark[i], DARKNESS_MULT);
1330 style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
1331 style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
1332 style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
1335 gdk_color_black (style->colormap, &style->black);
1336 gdk_color_white (style->colormap, &style->white);
1338 gc_values_mask = GDK_GC_FOREGROUND | GDK_GC_FONT;
1339 if (style->font->type == GDK_FONT_FONT)
1341 gc_values.font = style->font;
1343 else if (style->font->type == GDK_FONT_FONTSET)
1345 gc_values.font = static_default_font;
1348 gc_values.foreground = style->black;
1349 style->black_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1351 gc_values.foreground = style->white;
1352 style->white_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1354 for (i = 0; i < 5; i++)
1356 if (style->rc_style && style->rc_style->bg_pixmap_name[i])
1357 style->bg_pixmap[i] = gtk_rc_load_image (style->colormap,
1359 style->rc_style->bg_pixmap_name[i]);
1361 if (!gdk_color_alloc (style->colormap, &style->fg[i]))
1362 g_warning ("unable to allocate color: ( %d %d %d )",
1363 style->fg[i].red, style->fg[i].green, style->fg[i].blue);
1364 if (!gdk_color_alloc (style->colormap, &style->bg[i]))
1365 g_warning ("unable to allocate color: ( %d %d %d )",
1366 style->bg[i].red, style->bg[i].green, style->bg[i].blue);
1367 if (!gdk_color_alloc (style->colormap, &style->light[i]))
1368 g_warning ("unable to allocate color: ( %d %d %d )",
1369 style->light[i].red, style->light[i].green, style->light[i].blue);
1370 if (!gdk_color_alloc (style->colormap, &style->dark[i]))
1371 g_warning ("unable to allocate color: ( %d %d %d )",
1372 style->dark[i].red, style->dark[i].green, style->dark[i].blue);
1373 if (!gdk_color_alloc (style->colormap, &style->mid[i]))
1374 g_warning ("unable to allocate color: ( %d %d %d )",
1375 style->mid[i].red, style->mid[i].green, style->mid[i].blue);
1376 if (!gdk_color_alloc (style->colormap, &style->text[i]))
1377 g_warning ("unable to allocate color: ( %d %d %d )",
1378 style->text[i].red, style->text[i].green, style->text[i].blue);
1379 if (!gdk_color_alloc (style->colormap, &style->base[i]))
1380 g_warning ("unable to allocate color: ( %d %d %d )",
1381 style->base[i].red, style->base[i].green, style->base[i].blue);
1383 gc_values.foreground = style->fg[i];
1384 style->fg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1386 gc_values.foreground = style->bg[i];
1387 style->bg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1389 gc_values.foreground = style->light[i];
1390 style->light_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1392 gc_values.foreground = style->dark[i];
1393 style->dark_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1395 gc_values.foreground = style->mid[i];
1396 style->mid_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1398 gc_values.foreground = style->text[i];
1399 style->text_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1401 gc_values.foreground = style->base[i];
1402 style->base_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1407 gtk_style_real_unrealize (GtkStyle *style)
1411 gtk_gc_release (style->black_gc);
1412 gtk_gc_release (style->white_gc);
1414 for (i = 0; i < 5; i++)
1416 gtk_gc_release (style->fg_gc[i]);
1417 gtk_gc_release (style->bg_gc[i]);
1418 gtk_gc_release (style->light_gc[i]);
1419 gtk_gc_release (style->dark_gc[i]);
1420 gtk_gc_release (style->mid_gc[i]);
1421 gtk_gc_release (style->text_gc[i]);
1422 gtk_gc_release (style->base_gc[i]);
1424 if (style->bg_pixmap[i] && style->bg_pixmap[i] != (GdkPixmap*) GDK_PARENT_RELATIVE)
1425 gdk_pixmap_unref (style->bg_pixmap[i]);
1428 gdk_colormap_free_colors (style->colormap, style->fg, 5);
1429 gdk_colormap_free_colors (style->colormap, style->bg, 5);
1430 gdk_colormap_free_colors (style->colormap, style->light, 5);
1431 gdk_colormap_free_colors (style->colormap, style->dark, 5);
1432 gdk_colormap_free_colors (style->colormap, style->mid, 5);
1433 gdk_colormap_free_colors (style->colormap, style->text, 5);
1434 gdk_colormap_free_colors (style->colormap, style->base, 5);
1438 gtk_style_real_set_background (GtkStyle *style,
1440 GtkStateType state_type)
1443 gint parent_relative;
1445 if (style->bg_pixmap[state_type])
1447 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1450 parent_relative = TRUE;
1454 pixmap = style->bg_pixmap[state_type];
1455 parent_relative = FALSE;
1458 gdk_window_set_back_pixmap (window, pixmap, parent_relative);
1461 gdk_window_set_background (window, &style->bg[state_type]);
1465 gtk_style_render_icon (GtkStyle *style,
1466 const GtkIconSource *source,
1467 GtkTextDirection direction,
1471 const gchar *detail)
1475 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1476 g_return_val_if_fail (GTK_STYLE_GET_CLASS (style)->render_icon != NULL, NULL);
1478 pixbuf = GTK_STYLE_GET_CLASS (style)->render_icon (style, source, direction, state,
1479 size, widget, detail);
1481 g_return_val_if_fail (pixbuf != NULL, NULL);
1486 /* Default functions */
1488 gtk_style_apply_default_background (GtkStyle *style,
1491 GtkStateType state_type,
1498 GdkRectangle new_rect, old_rect;
1504 old_rect.width = width;
1505 old_rect.height = height;
1507 if (!gdk_rectangle_intersect (area, &old_rect, &new_rect))
1514 new_rect.width = width;
1515 new_rect.height = height;
1518 if (!style->bg_pixmap[state_type] ||
1519 GDK_IS_PIXMAP (window) ||
1520 (!set_bg && style->bg_pixmap[state_type] != (GdkPixmap*) GDK_PARENT_RELATIVE))
1522 GdkGC *gc = style->bg_gc[state_type];
1524 if (style->bg_pixmap[state_type])
1526 gdk_gc_set_fill (gc, GDK_TILED);
1527 gdk_gc_set_tile (gc, style->bg_pixmap[state_type]);
1530 gdk_draw_rectangle (window, gc, TRUE,
1531 new_rect.x, new_rect.y, new_rect.width, new_rect.height);
1532 if (style->bg_pixmap[state_type])
1533 gdk_gc_set_fill (gc, GDK_SOLID);
1539 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1540 gdk_window_set_back_pixmap (window, NULL, TRUE);
1542 gdk_window_set_back_pixmap (window, style->bg_pixmap[state_type], FALSE);
1545 gdk_window_clear_area (window,
1546 new_rect.x, new_rect.y,
1547 new_rect.width, new_rect.height);
1552 scale_or_ref (GdkPixbuf *src,
1556 if (width == gdk_pixbuf_get_width (src) &&
1557 height == gdk_pixbuf_get_height (src))
1559 gdk_pixbuf_ref (src);
1564 return gdk_pixbuf_scale_simple (src,
1566 GDK_INTERP_BILINEAR);
1571 gtk_default_render_icon (GtkStyle *style,
1572 const GtkIconSource *source,
1573 GtkTextDirection direction,
1577 const gchar *detail)
1583 GdkPixbuf *base_pixbuf;
1585 /* Oddly, style can be NULL in this function, because
1586 * GtkIconSet can be used without a style and if so
1587 * it uses this function.
1590 base_pixbuf = gtk_icon_source_get_pixbuf (source);
1592 g_return_val_if_fail (base_pixbuf != NULL, NULL);
1594 if (!gtk_icon_size_lookup (size, &width, &height))
1596 g_warning (G_STRLOC ": invalid icon size `%d'", size);
1600 /* If the size was wildcarded, then scale; otherwise, leave it
1603 if (gtk_icon_source_get_size_wildcarded (source))
1604 scaled = scale_or_ref (base_pixbuf, width, height);
1606 scaled = GDK_PIXBUF (g_object_ref (G_OBJECT (base_pixbuf)));
1608 /* If the state was wildcarded, then generate a state. */
1609 if (gtk_icon_source_get_state_wildcarded (source))
1611 if (state == GTK_STATE_INSENSITIVE)
1613 stated = gdk_pixbuf_copy (scaled);
1615 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
1618 gdk_pixbuf_unref (scaled);
1620 else if (state == GTK_STATE_PRELIGHT)
1622 stated = gdk_pixbuf_copy (scaled);
1624 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
1627 gdk_pixbuf_unref (scaled);
1641 gtk_default_draw_hline (GtkStyle *style,
1643 GtkStateType state_type,
1646 const gchar *detail,
1651 gint thickness_light;
1652 gint thickness_dark;
1655 g_return_if_fail (GTK_IS_STYLE (style));
1656 g_return_if_fail (window != NULL);
1658 thickness_light = style->ythickness / 2;
1659 thickness_dark = style->ythickness - thickness_light;
1663 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
1664 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
1667 if (detail && !strcmp (detail, "label"))
1669 if (state_type == GTK_STATE_INSENSITIVE)
1670 gdk_draw_line (window, style->white_gc, x1 + 1, y + 1, x2 + 1, y + 1);
1671 gdk_draw_line (window, style->fg_gc[state_type], x1, y, x2, y);
1675 for (i = 0; i < thickness_dark; i++)
1677 gdk_draw_line (window, style->light_gc[state_type], x2 - i - 1, y + i, x2, y + i);
1678 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x2 - i - 1, y + i);
1681 y += thickness_dark;
1682 for (i = 0; i < thickness_light; i++)
1684 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x1 + thickness_light - i - 1, y + i);
1685 gdk_draw_line (window, style->light_gc[state_type], x1 + thickness_light - i - 1, y + i, x2, y + i);
1691 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
1692 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
1698 gtk_default_draw_vline (GtkStyle *style,
1700 GtkStateType state_type,
1703 const gchar *detail,
1708 gint thickness_light;
1709 gint thickness_dark;
1712 g_return_if_fail (GTK_IS_STYLE (style));
1713 g_return_if_fail (window != NULL);
1715 thickness_light = style->xthickness / 2;
1716 thickness_dark = style->xthickness - thickness_light;
1720 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
1721 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
1723 for (i = 0; i < thickness_dark; i++)
1725 gdk_draw_line (window, style->light_gc[state_type], x + i, y2 - i - 1, x + i, y2);
1726 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y2 - i - 1);
1729 x += thickness_dark;
1730 for (i = 0; i < thickness_light; i++)
1732 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y1 + thickness_light - i);
1733 gdk_draw_line (window, style->light_gc[state_type], x + i, y1 + thickness_light - i, x + i, y2);
1737 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
1738 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
1744 gtk_default_draw_shadow (GtkStyle *style,
1746 GtkStateType state_type,
1747 GtkShadowType shadow_type,
1750 const gchar *detail,
1758 gint thickness_light;
1759 gint thickness_dark;
1762 g_return_if_fail (GTK_IS_STYLE (style));
1763 g_return_if_fail (window != NULL);
1765 if ((width == -1) && (height == -1))
1766 gdk_window_get_size (window, &width, &height);
1767 else if (width == -1)
1768 gdk_window_get_size (window, &width, NULL);
1769 else if (height == -1)
1770 gdk_window_get_size (window, NULL, &height);
1772 switch (shadow_type)
1774 case GTK_SHADOW_NONE:
1777 case GTK_SHADOW_ETCHED_IN:
1778 gc1 = style->light_gc[state_type];
1779 gc2 = style->dark_gc[state_type];
1781 case GTK_SHADOW_OUT:
1782 case GTK_SHADOW_ETCHED_OUT:
1783 gc1 = style->dark_gc[state_type];
1784 gc2 = style->light_gc[state_type];
1790 gdk_gc_set_clip_rectangle (gc1, area);
1791 gdk_gc_set_clip_rectangle (gc2, area);
1792 if (shadow_type == GTK_SHADOW_IN ||
1793 shadow_type == GTK_SHADOW_OUT)
1795 gdk_gc_set_clip_rectangle (style->black_gc, area);
1796 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
1800 switch (shadow_type)
1802 case GTK_SHADOW_NONE:
1806 gdk_draw_line (window, gc1,
1807 x, y + height - 1, x + width - 1, y + height - 1);
1808 gdk_draw_line (window, gc1,
1809 x + width - 1, y, x + width - 1, y + height - 1);
1811 gdk_draw_line (window, style->bg_gc[state_type],
1812 x + 1, y + height - 2, x + width - 2, y + height - 2);
1813 gdk_draw_line (window, style->bg_gc[state_type],
1814 x + width - 2, y + 1, x + width - 2, y + height - 2);
1816 gdk_draw_line (window, style->black_gc,
1817 x + 1, y + 1, x + width - 2, y + 1);
1818 gdk_draw_line (window, style->black_gc,
1819 x + 1, y + 1, x + 1, y + height - 2);
1821 gdk_draw_line (window, gc2,
1822 x, y, x + width - 1, y);
1823 gdk_draw_line (window, gc2,
1824 x, y, x, y + height - 1);
1827 case GTK_SHADOW_OUT:
1828 gdk_draw_line (window, gc1,
1829 x + 1, y + height - 2, x + width - 2, y + height - 2);
1830 gdk_draw_line (window, gc1,
1831 x + width - 2, y + 1, x + width - 2, y + height - 2);
1833 gdk_draw_line (window, gc2,
1834 x, y, x + width - 1, y);
1835 gdk_draw_line (window, gc2,
1836 x, y, x, y + height - 1);
1838 gdk_draw_line (window, style->bg_gc[state_type],
1839 x + 1, y + 1, x + width - 2, y + 1);
1840 gdk_draw_line (window, style->bg_gc[state_type],
1841 x + 1, y + 1, x + 1, y + height - 2);
1843 gdk_draw_line (window, style->black_gc,
1844 x, y + height - 1, x + width - 1, y + height - 1);
1845 gdk_draw_line (window, style->black_gc,
1846 x + width - 1, y, x + width - 1, y + height - 1);
1849 case GTK_SHADOW_ETCHED_IN:
1850 case GTK_SHADOW_ETCHED_OUT:
1851 thickness_light = 1;
1854 for (i = 0; i < thickness_dark; i++)
1856 gdk_draw_line (window, gc1,
1860 y + height - i - 1);
1861 gdk_draw_line (window, gc1,
1865 y + height - i - 1);
1867 gdk_draw_line (window, gc2,
1872 gdk_draw_line (window, gc2,
1876 y + height - i - 2);
1879 for (i = 0; i < thickness_light; i++)
1881 gdk_draw_line (window, gc1,
1882 x + thickness_dark + i,
1883 y + thickness_dark + i,
1884 x + width - thickness_dark - i - 1,
1885 y + thickness_dark + i);
1886 gdk_draw_line (window, gc1,
1887 x + thickness_dark + i,
1888 y + thickness_dark + i,
1889 x + thickness_dark + i,
1890 y + height - thickness_dark - i - 1);
1892 gdk_draw_line (window, gc2,
1893 x + thickness_dark + i,
1894 y + height - thickness_light - i - 1,
1895 x + width - thickness_light - 1,
1896 y + height - thickness_light - i - 1);
1897 gdk_draw_line (window, gc2,
1898 x + width - thickness_light - i - 1,
1899 y + thickness_dark + i,
1900 x + width - thickness_light - i - 1,
1901 y + height - thickness_light - 1);
1907 gdk_gc_set_clip_rectangle (gc1, NULL);
1908 gdk_gc_set_clip_rectangle (gc2, NULL);
1909 if (shadow_type == GTK_SHADOW_IN ||
1910 shadow_type == GTK_SHADOW_OUT)
1912 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
1913 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
1919 gtk_default_draw_polygon (GtkStyle *style,
1921 GtkStateType state_type,
1922 GtkShadowType shadow_type,
1925 const gchar *detail,
1930 static const gdouble pi_over_4 = G_PI_4;
1931 static const gdouble pi_3_over_4 = G_PI_4 * 3;
1941 g_return_if_fail (GTK_IS_STYLE (style));
1942 g_return_if_fail (window != NULL);
1943 g_return_if_fail (points != NULL);
1945 switch (shadow_type)
1948 gc1 = style->bg_gc[state_type];
1949 gc2 = style->dark_gc[state_type];
1950 gc3 = style->light_gc[state_type];
1951 gc4 = style->black_gc;
1953 case GTK_SHADOW_ETCHED_IN:
1954 gc1 = style->light_gc[state_type];
1955 gc2 = style->dark_gc[state_type];
1956 gc3 = style->dark_gc[state_type];
1957 gc4 = style->light_gc[state_type];
1959 case GTK_SHADOW_OUT:
1960 gc1 = style->dark_gc[state_type];
1961 gc2 = style->light_gc[state_type];
1962 gc3 = style->black_gc;
1963 gc4 = style->bg_gc[state_type];
1965 case GTK_SHADOW_ETCHED_OUT:
1966 gc1 = style->dark_gc[state_type];
1967 gc2 = style->light_gc[state_type];
1968 gc3 = style->light_gc[state_type];
1969 gc4 = style->dark_gc[state_type];
1977 gdk_gc_set_clip_rectangle (gc1, area);
1978 gdk_gc_set_clip_rectangle (gc2, area);
1979 gdk_gc_set_clip_rectangle (gc3, area);
1980 gdk_gc_set_clip_rectangle (gc4, area);
1984 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, npoints);
1988 for (i = 0; i < npoints; i++)
1990 if ((points[i].x == points[i+1].x) &&
1991 (points[i].y == points[i+1].y))
1997 angle = atan2 (points[i+1].y - points[i].y,
1998 points[i+1].x - points[i].x);
2001 if ((angle > -pi_3_over_4) && (angle < pi_over_4))
2003 if (angle > -pi_over_4)
2014 gdk_draw_line (window, gc1,
2015 points[i].x-xadjust, points[i].y-yadjust,
2016 points[i+1].x-xadjust, points[i+1].y-yadjust);
2017 gdk_draw_line (window, gc3,
2018 points[i].x, points[i].y,
2019 points[i+1].x, points[i+1].y);
2023 if ((angle < -pi_3_over_4) || (angle > pi_3_over_4))
2034 gdk_draw_line (window, gc4,
2035 points[i].x+xadjust, points[i].y+yadjust,
2036 points[i+1].x+xadjust, points[i+1].y+yadjust);
2037 gdk_draw_line (window, gc2,
2038 points[i].x, points[i].y,
2039 points[i+1].x, points[i+1].y);
2045 gdk_gc_set_clip_rectangle (gc1, NULL);
2046 gdk_gc_set_clip_rectangle (gc2, NULL);
2047 gdk_gc_set_clip_rectangle (gc3, NULL);
2048 gdk_gc_set_clip_rectangle (gc4, NULL);
2053 gtk_default_draw_arrow (GtkStyle *style,
2055 GtkStateType state_type,
2056 GtkShadowType shadow_type,
2059 const gchar *detail,
2060 GtkArrowType arrow_type,
2075 g_return_if_fail (GTK_IS_STYLE (style));
2076 g_return_if_fail (window != NULL);
2078 switch (shadow_type)
2081 gc1 = style->bg_gc[state_type];
2082 gc2 = style->dark_gc[state_type];
2083 gc3 = style->light_gc[state_type];
2084 gc4 = style->black_gc;
2086 case GTK_SHADOW_OUT:
2087 gc1 = style->dark_gc[state_type];
2088 gc2 = style->light_gc[state_type];
2089 gc3 = style->black_gc;
2090 gc4 = style->bg_gc[state_type];
2092 case GTK_SHADOW_ETCHED_IN:
2093 gc1 = style->light_gc[state_type];
2094 gc2 = style->dark_gc[state_type];
2098 case GTK_SHADOW_ETCHED_OUT:
2099 gc1 = style->dark_gc[state_type];
2100 gc2 = style->light_gc[state_type];
2108 if ((width == -1) && (height == -1))
2109 gdk_window_get_size (window, &width, &height);
2110 else if (width == -1)
2111 gdk_window_get_size (window, &width, NULL);
2112 else if (height == -1)
2113 gdk_window_get_size (window, NULL, &height);
2115 half_width = width / 2;
2116 half_height = height / 2;
2120 gdk_gc_set_clip_rectangle (gc1, area);
2121 gdk_gc_set_clip_rectangle (gc2, area);
2124 gdk_gc_set_clip_rectangle (gc3, area);
2125 gdk_gc_set_clip_rectangle (gc4, area);
2134 points[0].x = x + half_width;
2137 points[1].y = y + height - 1;
2138 points[2].x = x + width - 1;
2139 points[2].y = y + height - 1;
2141 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
2144 switch (shadow_type)
2147 case GTK_SHADOW_OUT:
2149 gdk_draw_line (window, gc1,
2150 x + 1, y + height - 2,
2151 x + width - 2, y + height - 2);
2152 gdk_draw_line (window, gc3,
2153 x + 0, y + height - 1,
2154 x + width - 1, y + height - 1);
2156 gdk_draw_line (window, gc1,
2157 x + width - 2, y + height - 1,
2158 x + half_width, y + 1);
2159 gdk_draw_line (window, gc3,
2160 x + width - 1, y + height - 1,
2163 gdk_draw_line (window, gc4,
2164 x + half_width, y + 1,
2165 x + 1, y + height - 1);
2166 gdk_draw_line (window, gc2,
2171 case GTK_SHADOW_ETCHED_IN:
2172 case GTK_SHADOW_ETCHED_OUT:
2173 gdk_draw_line (window, gc1,
2174 x + half_width, y + 1,
2175 x + 1, y + height - 1);
2176 gdk_draw_line (window, gc1,
2177 x + 1, y + height - 1,
2178 x + width - 1, y + height - 1);
2179 gdk_draw_line (window, gc1,
2180 x + width - 1, y + height - 1,
2181 x + half_width + 1, y + 1);
2183 points[0].x = x + half_width;
2186 points[1].y = y + height - 2;
2187 points[2].x = x + width - 2;
2188 points[2].y = y + height - 2;
2190 gdk_draw_polygon (window, gc2, FALSE, points, 3);
2198 case GTK_ARROW_DOWN:
2201 points[0].x = x + width - 1;
2205 points[2].x = x + half_width;
2206 points[2].y = y + height - 1;
2208 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
2210 switch (shadow_type)
2213 case GTK_SHADOW_OUT:
2214 gdk_draw_line (window, gc4,
2216 y + 1, x + 1, y + 1);
2217 gdk_draw_line (window, gc2,
2221 gdk_draw_line (window, gc4,
2223 x + half_width, y + height - 2);
2224 gdk_draw_line (window, gc2,
2226 x + half_width, y + height - 1);
2228 gdk_draw_line (window, gc1,
2229 x + half_width, y + height - 2,
2231 gdk_draw_line (window, gc3,
2232 x + half_width, y + height - 1,
2236 case GTK_SHADOW_ETCHED_IN:
2237 case GTK_SHADOW_ETCHED_OUT:
2238 gdk_draw_line (window, gc1,
2239 x + width - 1, y + 1,
2241 gdk_draw_line (window, gc1,
2243 x + half_width + 1, y + height - 1);
2244 gdk_draw_line (window, gc1,
2245 x + half_width + 1, y + height - 2,
2248 points[0].x = x + width - 2;
2252 points[2].x = x + half_width;
2253 points[2].y = y + height - 2;
2255 gdk_draw_polygon (window, gc2, FALSE, points, 3);
2262 case GTK_ARROW_LEFT:
2266 points[0].y = y + half_height;
2267 points[1].x = x + width - 1;
2268 points[1].y = y + height - 1;
2269 points[2].x = x + width - 1;
2272 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
2275 switch (shadow_type)
2278 case GTK_SHADOW_OUT:
2279 gdk_draw_line (window, gc1,
2280 x + 1, y + half_height,
2281 x + width - 1, y + height - 1);
2282 gdk_draw_line (window, gc3,
2284 x + width - 1, y + height - 1);
2286 gdk_draw_line (window, gc1,
2287 x + width - 2, y + height - 1,
2288 x + width - 2, y + 1);
2289 gdk_draw_line (window, gc3,
2290 x + width - 1, y + height - 1,
2293 gdk_draw_line (window, gc4,
2294 x + width - 1, y + 1,
2295 x + 1, y + half_height);
2296 gdk_draw_line (window, gc2,
2298 x, y + half_height);
2301 case GTK_SHADOW_ETCHED_IN:
2302 case GTK_SHADOW_ETCHED_OUT:
2303 gdk_draw_line (window, gc1,
2304 x + width - 1, y + 1,
2305 x + 1, y + half_height);
2306 gdk_draw_line (window, gc1,
2307 x + 1, y + half_height + 1,
2308 x + width - 1, y + height - 1);
2309 gdk_draw_line (window, gc1,
2310 x + width - 1, y + height - 1,
2311 x + width - 1, y + 1);
2313 points[0].x = x + width - 2;
2316 points[1].y = y + half_height;
2317 points[2].x = x + width - 2;
2318 points[2].y = y + height - 2;
2320 gdk_draw_polygon (window, gc2, FALSE, points, 3);
2327 case GTK_ARROW_RIGHT:
2330 points[0].x = x + width - 1;
2331 points[0].y = y + half_height;
2335 points[2].y = y + height - 1;
2337 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
2340 switch (shadow_type)
2343 case GTK_SHADOW_OUT:
2344 gdk_draw_line (window, gc4,
2345 x + width - 1, y + half_height,
2347 gdk_draw_line (window, gc2,
2348 x + width - 1, y + half_height,
2350 gdk_draw_line (window, gc4,
2352 x + 1, y + height - 2);
2353 gdk_draw_line (window, gc2,
2357 gdk_draw_line (window, gc1,
2358 x + 1, y + height - 2,
2359 x + width - 1, y + half_height);
2360 gdk_draw_line (window, gc3,
2362 x + width - 1, y + half_height);
2365 case GTK_SHADOW_ETCHED_IN:
2366 case GTK_SHADOW_ETCHED_OUT:
2367 gdk_draw_line (window, gc1,
2368 x + width - 1, y + half_height + 1,
2370 gdk_draw_line (window, gc1,
2372 x + 1, y + height - 1);
2373 gdk_draw_line (window, gc1,
2374 x + 1, y + height - 1,
2375 x + width - 1, y + half_height + 1);
2377 points[0].x = x + width - 2;
2378 points[0].y = y + half_height;
2382 points[2].y = y + height - 1;
2384 gdk_draw_polygon (window, gc2, FALSE, points, 3);
2395 gdk_gc_set_clip_rectangle (gc1, NULL);
2396 gdk_gc_set_clip_rectangle (gc2, NULL);
2399 gdk_gc_set_clip_rectangle (gc3, NULL);
2400 gdk_gc_set_clip_rectangle (gc4, NULL);
2406 gtk_default_draw_diamond (GtkStyle *style,
2408 GtkStateType state_type,
2409 GtkShadowType shadow_type,
2412 const gchar *detail,
2420 GdkGC *outer_nw = NULL;
2421 GdkGC *outer_ne = NULL;
2422 GdkGC *outer_sw = NULL;
2423 GdkGC *outer_se = NULL;
2424 GdkGC *middle_nw = NULL;
2425 GdkGC *middle_ne = NULL;
2426 GdkGC *middle_sw = NULL;
2427 GdkGC *middle_se = NULL;
2428 GdkGC *inner_nw = NULL;
2429 GdkGC *inner_ne = NULL;
2430 GdkGC *inner_sw = NULL;
2431 GdkGC *inner_se = NULL;
2433 g_return_if_fail (GTK_IS_STYLE (style));
2434 g_return_if_fail (window != NULL);
2436 if ((width == -1) && (height == -1))
2437 gdk_window_get_size (window, &width, &height);
2438 else if (width == -1)
2439 gdk_window_get_size (window, &width, NULL);
2440 else if (height == -1)
2441 gdk_window_get_size (window, NULL, &height);
2443 half_width = width / 2;
2444 half_height = height / 2;
2448 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
2449 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2450 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
2451 gdk_gc_set_clip_rectangle (style->black_gc, area);
2454 switch (shadow_type)
2457 inner_sw = inner_se = style->bg_gc[state_type];
2458 middle_sw = middle_se = style->light_gc[state_type];
2459 outer_sw = outer_se = style->light_gc[state_type];
2460 inner_nw = inner_ne = style->black_gc;
2461 middle_nw = middle_ne = style->dark_gc[state_type];
2462 outer_nw = outer_ne = style->dark_gc[state_type];
2465 case GTK_SHADOW_OUT:
2466 inner_sw = inner_se = style->dark_gc[state_type];
2467 middle_sw = middle_se = style->dark_gc[state_type];
2468 outer_sw = outer_se = style->black_gc;
2469 inner_nw = inner_ne = style->bg_gc[state_type];
2470 middle_nw = middle_ne = style->light_gc[state_type];
2471 outer_nw = outer_ne = style->light_gc[state_type];
2474 case GTK_SHADOW_ETCHED_IN:
2475 inner_sw = inner_se = style->bg_gc[state_type];
2476 middle_sw = middle_se = style->dark_gc[state_type];
2477 outer_sw = outer_se = style->light_gc[state_type];
2478 inner_nw = inner_ne = style->bg_gc[state_type];
2479 middle_nw = middle_ne = style->light_gc[state_type];
2480 outer_nw = outer_ne = style->dark_gc[state_type];
2483 case GTK_SHADOW_ETCHED_OUT:
2484 inner_sw = inner_se = style->bg_gc[state_type];
2485 middle_sw = middle_se = style->light_gc[state_type];
2486 outer_sw = outer_se = style->dark_gc[state_type];
2487 inner_nw = inner_ne = style->bg_gc[state_type];
2488 middle_nw = middle_ne = style->dark_gc[state_type];
2489 outer_nw = outer_ne = style->light_gc[state_type];
2499 gdk_draw_line (window, inner_sw,
2500 x + 2, y + half_height,
2501 x + half_width, y + height - 2);
2502 gdk_draw_line (window, inner_se,
2503 x + half_width, y + height - 2,
2504 x + width - 2, y + half_height);
2505 gdk_draw_line (window, middle_sw,
2506 x + 1, y + half_height,
2507 x + half_width, y + height - 1);
2508 gdk_draw_line (window, middle_se,
2509 x + half_width, y + height - 1,
2510 x + width - 1, y + half_height);
2511 gdk_draw_line (window, outer_sw,
2513 x + half_width, y + height);
2514 gdk_draw_line (window, outer_se,
2515 x + half_width, y + height,
2516 x + width, y + half_height);
2518 gdk_draw_line (window, inner_nw,
2519 x + 2, y + half_height,
2520 x + half_width, y + 2);
2521 gdk_draw_line (window, inner_ne,
2522 x + half_width, y + 2,
2523 x + width - 2, y + half_height);
2524 gdk_draw_line (window, middle_nw,
2525 x + 1, y + half_height,
2526 x + half_width, y + 1);
2527 gdk_draw_line (window, middle_ne,
2528 x + half_width, y + 1,
2529 x + width - 1, y + half_height);
2530 gdk_draw_line (window, outer_nw,
2533 gdk_draw_line (window, outer_ne,
2535 x + width, y + half_height);
2540 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
2541 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
2542 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
2543 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2548 gtk_default_draw_string (GtkStyle *style,
2550 GtkStateType state_type,
2553 const gchar *detail,
2556 const gchar *string)
2558 g_return_if_fail (GTK_IS_STYLE (style));
2559 g_return_if_fail (window != NULL);
2563 gdk_gc_set_clip_rectangle (style->white_gc, area);
2564 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], area);
2567 if (state_type == GTK_STATE_INSENSITIVE)
2568 gdk_draw_string (window, style->font, style->white_gc, x + 1, y + 1, string);
2570 gdk_draw_string (window, style->font, style->fg_gc[state_type], x, y, string);
2574 gdk_gc_set_clip_rectangle (style->white_gc, NULL);
2575 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], NULL);
2580 gtk_default_draw_box (GtkStyle *style,
2582 GtkStateType state_type,
2583 GtkShadowType shadow_type,
2586 const gchar *detail,
2592 g_return_if_fail (GTK_IS_STYLE (style));
2593 g_return_if_fail (window != NULL);
2595 if (width == -1 && height == -1)
2596 gdk_window_get_size (window, &width, &height);
2597 else if (width == -1)
2598 gdk_window_get_size (window, &width, NULL);
2599 else if (height == -1)
2600 gdk_window_get_size (window, NULL, &height);
2602 if (!style->bg_pixmap[state_type] ||
2603 GDK_IS_PIXMAP (window))
2606 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2608 gdk_draw_rectangle (window, style->bg_gc[state_type], TRUE,
2609 x, y, width, height);
2611 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
2614 gtk_style_apply_default_background (style, window,
2615 widget && !GTK_WIDGET_NO_WINDOW (widget),
2616 state_type, area, x, y, width, height);
2618 gtk_paint_shadow (style, window, state_type, shadow_type, area, widget, detail,
2619 x, y, width, height);
2623 get_darkened_gc (GdkWindow *window,
2627 GdkColor src = *color;
2631 gc = gdk_gc_new (window);
2633 while (darken_count)
2635 gtk_style_shade (&src, &shaded, 0.93);
2640 gdk_gc_set_rgb_fg_color (gc, &shaded);
2646 gtk_default_draw_flat_box (GtkStyle *style,
2648 GtkStateType state_type,
2649 GtkShadowType shadow_type,
2652 const gchar *detail,
2659 GdkGC *freeme = NULL;
2661 g_return_if_fail (GTK_IS_STYLE (style));
2662 g_return_if_fail (window != NULL);
2664 if (width == -1 && height == -1)
2665 gdk_window_get_size (window, &width, &height);
2666 else if (width == -1)
2667 gdk_window_get_size (window, &width, NULL);
2668 else if (height == -1)
2669 gdk_window_get_size (window, NULL, &height);
2673 if (state_type == GTK_STATE_SELECTED)
2675 if (!strcmp ("text", detail))
2676 gc1 = style->bg_gc[GTK_STATE_SELECTED];
2677 else if (!strcmp ("cell_even_sorted", detail) ||
2678 !strcmp ("cell_odd_sorted", detail) ||
2679 !strcmp ("cell_even_ruled_sorted", detail) ||
2680 !strcmp ("cell_odd_ruled_sorted", detail))
2682 freeme = get_darkened_gc (window, &style->bg[state_type], 1);
2687 gc1 = style->bg_gc[state_type];
2692 if (!strcmp ("viewportbin", detail))
2693 gc1 = style->bg_gc[GTK_STATE_NORMAL];
2694 else if (!strcmp ("entry_bg", detail))
2695 gc1 = style->base_gc[state_type];
2697 /* For trees: even rows are base color, odd rows are a shade of
2698 * the base color, the sort column is a shade of the original color
2702 /* FIXME when we have style properties, clean this up.
2705 else if (!strcmp ("cell_even", detail) ||
2706 !strcmp ("cell_odd", detail) ||
2707 !strcmp ("cell_even_ruled", detail))
2709 gc1 = style->base_gc[state_type];
2711 else if (!strcmp ("cell_even_sorted", detail) ||
2712 !strcmp ("cell_odd_sorted", detail) ||
2713 !strcmp ("cell_odd_ruled", detail) ||
2714 !strcmp ("cell_even_ruled_sorted", detail))
2716 freeme = get_darkened_gc (window, &style->base[state_type], 1);
2719 else if (!strcmp ("cell_odd_ruled_sorted", detail))
2721 freeme = get_darkened_gc (window, &style->base[state_type], 2);
2725 gc1 = style->bg_gc[state_type];
2729 gc1 = style->bg_gc[state_type];
2731 if (!style->bg_pixmap[state_type] || gc1 != style->bg_gc[state_type] ||
2732 GDK_IS_PIXMAP (window))
2735 gdk_gc_set_clip_rectangle (gc1, area);
2737 gdk_draw_rectangle (window, gc1, TRUE,
2738 x, y, width, height);
2740 if (detail && !strcmp ("tooltip", detail))
2741 gdk_draw_rectangle (window, style->black_gc, FALSE,
2742 x, y, width - 1, height - 1);
2745 gdk_gc_set_clip_rectangle (gc1, NULL);
2748 gtk_style_apply_default_background (style, window,
2749 widget && !GTK_WIDGET_NO_WINDOW (widget),
2750 state_type, area, x, y, width, height);
2754 g_object_unref (G_OBJECT (freeme));
2758 gtk_default_draw_check (GtkStyle *style,
2760 GtkStateType state_type,
2761 GtkShadowType shadow_type,
2764 const gchar *detail,
2770 if (detail && strcmp (detail, "cellcheck") == 0)
2772 gdk_draw_rectangle (window,
2773 widget->style->fg_gc[state_type],
2778 if (shadow_type == GTK_SHADOW_IN)
2780 gdk_draw_line (window,
2781 widget->style->fg_gc[state_type],
2785 gdk_draw_line (window,
2786 widget->style->fg_gc[state_type],
2795 gtk_paint_box (style, window, state_type, shadow_type, area, widget, detail,
2796 x, y, width, height);
2801 gtk_default_draw_option (GtkStyle *style,
2803 GtkStateType state_type,
2804 GtkShadowType shadow_type,
2807 const gchar *detail,
2813 if (detail && strcmp (detail, "cellradio") == 0)
2815 gdk_draw_arc (window,
2816 widget->style->fg_gc[state_type],
2823 if (shadow_type == GTK_SHADOW_IN)
2825 gdk_draw_arc (window,
2826 widget->style->fg_gc[state_type],
2837 gtk_paint_diamond (style, window, state_type, shadow_type, area, widget,
2838 detail, x, y, width, height);
2843 gtk_default_draw_tab (GtkStyle *style,
2845 GtkStateType state_type,
2846 GtkShadowType shadow_type,
2849 const gchar *detail,
2855 g_return_if_fail (GTK_IS_STYLE (style));
2856 g_return_if_fail (window != NULL);
2858 gtk_paint_box (style, window, state_type, shadow_type, area, widget, detail,
2859 x, y, width, height);
2863 gtk_default_draw_shadow_gap (GtkStyle *style,
2865 GtkStateType state_type,
2866 GtkShadowType shadow_type,
2869 const gchar *detail,
2874 GtkPositionType gap_side,
2883 g_return_if_fail (GTK_IS_STYLE (style));
2884 g_return_if_fail (window != NULL);
2886 if (width == -1 && height == -1)
2887 gdk_window_get_size (window, &width, &height);
2888 else if (width == -1)
2889 gdk_window_get_size (window, &width, NULL);
2890 else if (height == -1)
2891 gdk_window_get_size (window, NULL, &height);
2893 switch (shadow_type)
2895 case GTK_SHADOW_NONE:
2898 gc1 = style->dark_gc[state_type];
2899 gc2 = style->black_gc;
2900 gc3 = style->bg_gc[state_type];
2901 gc4 = style->light_gc[state_type];
2903 case GTK_SHADOW_ETCHED_IN:
2904 gc1 = style->dark_gc[state_type];
2905 gc2 = style->light_gc[state_type];
2906 gc3 = style->dark_gc[state_type];
2907 gc4 = style->light_gc[state_type];
2909 case GTK_SHADOW_OUT:
2910 gc1 = style->light_gc[state_type];
2911 gc2 = style->bg_gc[state_type];
2912 gc3 = style->dark_gc[state_type];
2913 gc4 = style->black_gc;
2915 case GTK_SHADOW_ETCHED_OUT:
2916 gc1 = style->light_gc[state_type];
2917 gc2 = style->dark_gc[state_type];
2918 gc3 = style->light_gc[state_type];
2919 gc4 = style->dark_gc[state_type];
2924 gdk_gc_set_clip_rectangle (gc1, area);
2925 gdk_gc_set_clip_rectangle (gc2, area);
2926 gdk_gc_set_clip_rectangle (gc3, area);
2927 gdk_gc_set_clip_rectangle (gc4, area);
2930 switch (shadow_type)
2932 case GTK_SHADOW_NONE:
2934 case GTK_SHADOW_OUT:
2935 case GTK_SHADOW_ETCHED_IN:
2936 case GTK_SHADOW_ETCHED_OUT:
2940 gdk_draw_line (window, gc1,
2941 x, y, x, y + height - 1);
2942 gdk_draw_line (window, gc2,
2943 x + 1, y, x + 1, y + height - 2);
2945 gdk_draw_line (window, gc3,
2946 x + 1, y + height - 2, x + width - 2, y + height - 2);
2947 gdk_draw_line (window, gc3,
2948 x + width - 2, y, x + width - 2, y + height - 2);
2949 gdk_draw_line (window, gc4,
2950 x, y + height - 1, x + width - 1, y + height - 1);
2951 gdk_draw_line (window, gc4,
2952 x + width - 1, y, x + width - 1, y + height - 1);
2955 gdk_draw_line (window, gc1,
2956 x, y, x + gap_x - 1, y);
2957 gdk_draw_line (window, gc2,
2958 x + 1, y + 1, x + gap_x - 1, y + 1);
2959 gdk_draw_line (window, gc2,
2960 x + gap_x, y, x + gap_x, y);
2962 if ((width - (gap_x + gap_width)) > 0)
2964 gdk_draw_line (window, gc1,
2965 x + gap_x + gap_width, y, x + width - 2, y);
2966 gdk_draw_line (window, gc2,
2967 x + gap_x + gap_width, y + 1, x + width - 2, y + 1);
2968 gdk_draw_line (window, gc2,
2969 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
2972 case GTK_POS_BOTTOM:
2973 gdk_draw_line (window, gc1,
2974 x, y, x + width - 1, y);
2975 gdk_draw_line (window, gc1,
2976 x, y, x, y + height - 1);
2977 gdk_draw_line (window, gc2,
2978 x + 1, y + 1, x + width - 2, y + 1);
2979 gdk_draw_line (window, gc2,
2980 x + 1, y + 1, x + 1, y + height - 1);
2982 gdk_draw_line (window, gc3,
2983 x + width - 2, y + 1, x + width - 2, y + height - 1);
2984 gdk_draw_line (window, gc4,
2985 x + width - 1, y, x + width - 1, y + height - 1);
2988 gdk_draw_line (window, gc4,
2989 x, y + height - 1, x + gap_x - 1, y + height - 1);
2990 gdk_draw_line (window, gc3,
2991 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
2992 gdk_draw_line (window, gc3,
2993 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
2995 if ((width - (gap_x + gap_width)) > 0)
2997 gdk_draw_line (window, gc4,
2998 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
2999 gdk_draw_line (window, gc3,
3000 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
3001 gdk_draw_line (window, gc3,
3002 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
3006 gdk_draw_line (window, gc1,
3007 x, y, x + width - 1, y);
3008 gdk_draw_line (window, gc2,
3009 x, y + 1, x + width - 2, y + 1);
3011 gdk_draw_line (window, gc3,
3012 x, y + height - 2, x + width - 2, y + height - 2);
3013 gdk_draw_line (window, gc3,
3014 x + width - 2, y + 1, x + width - 2, y + height - 2);
3015 gdk_draw_line (window, gc4,
3016 x, y + height - 1, x + width - 1, y + height - 1);
3017 gdk_draw_line (window, gc4,
3018 x + width - 1, y, x + width - 1, y + height - 1);
3021 gdk_draw_line (window, gc1,
3022 x, y, x, y + gap_x - 1);
3023 gdk_draw_line (window, gc2,
3024 x + 1, y + 1, x + 1, y + gap_x - 1);
3025 gdk_draw_line (window, gc2,
3026 x, y + gap_x, x, y + gap_x);
3028 if ((width - (gap_x + gap_width)) > 0)
3030 gdk_draw_line (window, gc1,
3031 x, y + gap_x + gap_width, x, y + height - 2);
3032 gdk_draw_line (window, gc2,
3033 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
3034 gdk_draw_line (window, gc2,
3035 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
3039 gdk_draw_line (window, gc1,
3040 x, y, x + width - 1, y);
3041 gdk_draw_line (window, gc1,
3042 x, y, x, y + height - 1);
3043 gdk_draw_line (window, gc2,
3044 x + 1, y + 1, x + width - 1, y + 1);
3045 gdk_draw_line (window, gc2,
3046 x + 1, y + 1, x + 1, y + height - 2);
3048 gdk_draw_line (window, gc3,
3049 x + 1, y + height - 2, x + width - 1, y + height - 2);
3050 gdk_draw_line (window, gc4,
3051 x, y + height - 1, x + width - 1, y + height - 1);
3054 gdk_draw_line (window, gc4,
3055 x + width - 1, y, x + width - 1, y + gap_x - 1);
3056 gdk_draw_line (window, gc3,
3057 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
3058 gdk_draw_line (window, gc3,
3059 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
3061 if ((width - (gap_x + gap_width)) > 0)
3063 gdk_draw_line (window, gc4,
3064 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
3065 gdk_draw_line (window, gc3,
3066 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
3067 gdk_draw_line (window, gc3,
3068 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
3076 gdk_gc_set_clip_rectangle (gc1, NULL);
3077 gdk_gc_set_clip_rectangle (gc2, NULL);
3078 gdk_gc_set_clip_rectangle (gc3, NULL);
3079 gdk_gc_set_clip_rectangle (gc4, NULL);
3084 gtk_default_draw_box_gap (GtkStyle *style,
3086 GtkStateType state_type,
3087 GtkShadowType shadow_type,
3090 const gchar *detail,
3095 GtkPositionType gap_side,
3104 g_return_if_fail (GTK_IS_STYLE (style));
3105 g_return_if_fail (window != NULL);
3107 gtk_style_apply_default_background (style, window,
3108 widget && !GTK_WIDGET_NO_WINDOW (widget),
3109 state_type, area, x, y, width, height);
3111 if (width == -1 && height == -1)
3112 gdk_window_get_size (window, &width, &height);
3113 else if (width == -1)
3114 gdk_window_get_size (window, &width, NULL);
3115 else if (height == -1)
3116 gdk_window_get_size (window, NULL, &height);
3118 switch (shadow_type)
3120 case GTK_SHADOW_NONE:
3123 gc1 = style->dark_gc[state_type];
3124 gc2 = style->black_gc;
3125 gc3 = style->bg_gc[state_type];
3126 gc4 = style->light_gc[state_type];
3128 case GTK_SHADOW_ETCHED_IN:
3129 gc1 = style->dark_gc[state_type];
3130 gc2 = style->light_gc[state_type];
3131 gc3 = style->dark_gc[state_type];
3132 gc4 = style->light_gc[state_type];
3134 case GTK_SHADOW_OUT:
3135 gc1 = style->light_gc[state_type];
3136 gc2 = style->bg_gc[state_type];
3137 gc3 = style->dark_gc[state_type];
3138 gc4 = style->black_gc;
3140 case GTK_SHADOW_ETCHED_OUT:
3141 gc1 = style->light_gc[state_type];
3142 gc2 = style->dark_gc[state_type];
3143 gc3 = style->light_gc[state_type];
3144 gc4 = style->dark_gc[state_type];
3150 gdk_gc_set_clip_rectangle (gc1, area);
3151 gdk_gc_set_clip_rectangle (gc2, area);
3152 gdk_gc_set_clip_rectangle (gc3, area);
3153 gdk_gc_set_clip_rectangle (gc4, area);
3156 switch (shadow_type)
3158 case GTK_SHADOW_NONE:
3160 case GTK_SHADOW_OUT:
3161 case GTK_SHADOW_ETCHED_IN:
3162 case GTK_SHADOW_ETCHED_OUT:
3166 gdk_draw_line (window, gc1,
3167 x, y, x, y + height - 1);
3168 gdk_draw_line (window, gc2,
3169 x + 1, y, x + 1, y + height - 2);
3171 gdk_draw_line (window, gc3,
3172 x + 1, y + height - 2, x + width - 2, y + height - 2);
3173 gdk_draw_line (window, gc3,
3174 x + width - 2, y, x + width - 2, y + height - 2);
3175 gdk_draw_line (window, gc4,
3176 x, y + height - 1, x + width - 1, y + height - 1);
3177 gdk_draw_line (window, gc4,
3178 x + width - 1, y, x + width - 1, y + height - 1);
3181 gdk_draw_line (window, gc1,
3182 x, y, x + gap_x - 1, y);
3183 gdk_draw_line (window, gc2,
3184 x + 1, y + 1, x + gap_x - 1, y + 1);
3185 gdk_draw_line (window, gc2,
3186 x + gap_x, y, x + gap_x, y);
3188 if ((width - (gap_x + gap_width)) > 0)
3190 gdk_draw_line (window, gc1,
3191 x + gap_x + gap_width, y, x + width - 2, y);
3192 gdk_draw_line (window, gc2,
3193 x + gap_x + gap_width, y + 1, x + width - 2, y + 1);
3194 gdk_draw_line (window, gc2,
3195 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
3198 case GTK_POS_BOTTOM:
3199 gdk_draw_line (window, gc1,
3200 x, y, x + width - 1, y);
3201 gdk_draw_line (window, gc1,
3202 x, y, x, y + height - 1);
3203 gdk_draw_line (window, gc2,
3204 x + 1, y + 1, x + width - 2, y + 1);
3205 gdk_draw_line (window, gc2,
3206 x + 1, y + 1, x + 1, y + height - 1);
3208 gdk_draw_line (window, gc3,
3209 x + width - 2, y + 1, x + width - 2, y + height - 1);
3210 gdk_draw_line (window, gc4,
3211 x + width - 1, y, x + width - 1, y + height - 1);
3214 gdk_draw_line (window, gc4,
3215 x, y + height - 1, x + gap_x - 1, y + height - 1);
3216 gdk_draw_line (window, gc3,
3217 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
3218 gdk_draw_line (window, gc3,
3219 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
3221 if ((width - (gap_x + gap_width)) > 0)
3223 gdk_draw_line (window, gc4,
3224 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
3225 gdk_draw_line (window, gc3,
3226 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
3227 gdk_draw_line (window, gc3,
3228 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
3232 gdk_draw_line (window, gc1,
3233 x, y, x + width - 1, y);
3234 gdk_draw_line (window, gc2,
3235 x, y + 1, x + width - 2, y + 1);
3237 gdk_draw_line (window, gc3,
3238 x, y + height - 2, x + width - 2, y + height - 2);
3239 gdk_draw_line (window, gc3,
3240 x + width - 2, y + 1, x + width - 2, y + height - 2);
3241 gdk_draw_line (window, gc4,
3242 x, y + height - 1, x + width - 1, y + height - 1);
3243 gdk_draw_line (window, gc4,
3244 x + width - 1, y, x + width - 1, y + height - 1);
3247 gdk_draw_line (window, gc1,
3248 x, y, x, y + gap_x - 1);
3249 gdk_draw_line (window, gc2,
3250 x + 1, y + 1, x + 1, y + gap_x - 1);
3251 gdk_draw_line (window, gc2,
3252 x, y + gap_x, x, y + gap_x);
3254 if ((width - (gap_x + gap_width)) > 0)
3256 gdk_draw_line (window, gc1,
3257 x, y + gap_x + gap_width, x, y + height - 2);
3258 gdk_draw_line (window, gc2,
3259 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
3260 gdk_draw_line (window, gc2,
3261 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
3265 gdk_draw_line (window, gc1,
3266 x, y, x + width - 1, y);
3267 gdk_draw_line (window, gc1,
3268 x, y, x, y + height - 1);
3269 gdk_draw_line (window, gc2,
3270 x + 1, y + 1, x + width - 1, y + 1);
3271 gdk_draw_line (window, gc2,
3272 x + 1, y + 1, x + 1, y + height - 2);
3274 gdk_draw_line (window, gc3,
3275 x + 1, y + height - 2, x + width - 1, y + height - 2);
3276 gdk_draw_line (window, gc4,
3277 x, y + height - 1, x + width - 1, y + height - 1);
3280 gdk_draw_line (window, gc4,
3281 x + width - 1, y, x + width - 1, y + gap_x - 1);
3282 gdk_draw_line (window, gc3,
3283 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
3284 gdk_draw_line (window, gc3,
3285 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
3287 if ((width - (gap_x + gap_width)) > 0)
3289 gdk_draw_line (window, gc4,
3290 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
3291 gdk_draw_line (window, gc3,
3292 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
3293 gdk_draw_line (window, gc3,
3294 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
3302 gdk_gc_set_clip_rectangle (gc1, NULL);
3303 gdk_gc_set_clip_rectangle (gc2, NULL);
3304 gdk_gc_set_clip_rectangle (gc3, NULL);
3305 gdk_gc_set_clip_rectangle (gc4, NULL);
3310 gtk_default_draw_extension (GtkStyle *style,
3312 GtkStateType state_type,
3313 GtkShadowType shadow_type,
3316 const gchar *detail,
3321 GtkPositionType gap_side)
3328 g_return_if_fail (GTK_IS_STYLE (style));
3329 g_return_if_fail (window != NULL);
3331 gtk_style_apply_default_background (style, window,
3332 widget && !GTK_WIDGET_NO_WINDOW (widget),
3333 GTK_STATE_NORMAL, area, x, y, width, height);
3335 if (width == -1 && height == -1)
3336 gdk_window_get_size (window, &width, &height);
3337 else if (width == -1)
3338 gdk_window_get_size (window, &width, NULL);
3339 else if (height == -1)
3340 gdk_window_get_size (window, NULL, &height);
3342 switch (shadow_type)
3344 case GTK_SHADOW_NONE:
3347 gc1 = style->dark_gc[state_type];
3348 gc2 = style->black_gc;
3349 gc3 = style->bg_gc[state_type];
3350 gc4 = style->light_gc[state_type];
3352 case GTK_SHADOW_ETCHED_IN:
3353 gc1 = style->dark_gc[state_type];
3354 gc2 = style->light_gc[state_type];
3355 gc3 = style->dark_gc[state_type];
3356 gc4 = style->light_gc[state_type];
3358 case GTK_SHADOW_OUT:
3359 gc1 = style->light_gc[state_type];
3360 gc2 = style->bg_gc[state_type];
3361 gc3 = style->dark_gc[state_type];
3362 gc4 = style->black_gc;
3364 case GTK_SHADOW_ETCHED_OUT:
3365 gc1 = style->light_gc[state_type];
3366 gc2 = style->dark_gc[state_type];
3367 gc3 = style->light_gc[state_type];
3368 gc4 = style->dark_gc[state_type];
3374 gdk_gc_set_clip_rectangle (gc1, area);
3375 gdk_gc_set_clip_rectangle (gc2, area);
3376 gdk_gc_set_clip_rectangle (gc3, area);
3377 gdk_gc_set_clip_rectangle (gc4, area);
3380 switch (shadow_type)
3382 case GTK_SHADOW_NONE:
3384 case GTK_SHADOW_OUT:
3385 case GTK_SHADOW_ETCHED_IN:
3386 case GTK_SHADOW_ETCHED_OUT:
3390 gtk_style_apply_default_background (style, window,
3391 widget && !GTK_WIDGET_NO_WINDOW (widget),
3393 x + style->xthickness,
3395 width - (2 * style->xthickness),
3396 height - (style->ythickness));
3397 gdk_draw_line (window, gc1,
3398 x, y, x, y + height - 2);
3399 gdk_draw_line (window, gc2,
3400 x + 1, y, x + 1, y + height - 2);
3402 gdk_draw_line (window, gc3,
3403 x + 2, y + height - 2, x + width - 2, y + height - 2);
3404 gdk_draw_line (window, gc3,
3405 x + width - 2, y, x + width - 2, y + height - 2);
3406 gdk_draw_line (window, gc4,
3407 x + 1, y + height - 1, x + width - 2, y + height - 1);
3408 gdk_draw_line (window, gc4,
3409 x + width - 1, y, x + width - 1, y + height - 2);
3411 case GTK_POS_BOTTOM:
3412 gtk_style_apply_default_background (style, window,
3413 widget && !GTK_WIDGET_NO_WINDOW (widget),
3415 x + style->xthickness,
3416 y + style->ythickness,
3417 width - (2 * style->xthickness),
3418 height - (style->ythickness));
3419 gdk_draw_line (window, gc1,
3420 x + 1, y, x + width - 2, y);
3421 gdk_draw_line (window, gc1,
3422 x, y + 1, x, y + height - 1);
3423 gdk_draw_line (window, gc2,
3424 x + 1, y + 1, x + width - 2, y + 1);
3425 gdk_draw_line (window, gc2,
3426 x + 1, y + 1, x + 1, y + height - 1);
3428 gdk_draw_line (window, gc3,
3429 x + width - 2, y + 2, x + width - 2, y + height - 1);
3430 gdk_draw_line (window, gc4,
3431 x + width - 1, y + 1, x + width - 1, y + height - 1);
3434 gtk_style_apply_default_background (style, window,
3435 widget && !GTK_WIDGET_NO_WINDOW (widget),
3438 y + style->ythickness,
3439 width - (style->xthickness),
3440 height - (2 * style->ythickness));
3441 gdk_draw_line (window, gc1,
3442 x, y, x + width - 2, y);
3443 gdk_draw_line (window, gc2,
3444 x + 1, y + 1, x + width - 2, y + 1);
3446 gdk_draw_line (window, gc3,
3447 x, y + height - 2, x + width - 2, y + height - 2);
3448 gdk_draw_line (window, gc3,
3449 x + width - 2, y + 2, x + width - 2, y + height - 2);
3450 gdk_draw_line (window, gc4,
3451 x, y + height - 1, x + width - 2, y + height - 1);
3452 gdk_draw_line (window, gc4,
3453 x + width - 1, y + 1, x + width - 1, y + height - 2);
3456 gtk_style_apply_default_background (style, window,
3457 widget && !GTK_WIDGET_NO_WINDOW (widget),
3459 x + style->xthickness,
3460 y + style->ythickness,
3461 width - (style->xthickness),
3462 height - (2 * style->ythickness));
3463 gdk_draw_line (window, gc1,
3464 x + 1, y, x + width - 1, y);
3465 gdk_draw_line (window, gc1,
3466 x, y + 1, x, y + height - 2);
3467 gdk_draw_line (window, gc2,
3468 x + 1, y + 1, x + width - 1, y + 1);
3469 gdk_draw_line (window, gc2,
3470 x + 1, y + 1, x + 1, y + height - 2);
3472 gdk_draw_line (window, gc3,
3473 x + 2, y + height - 2, x + width - 1, y + height - 2);
3474 gdk_draw_line (window, gc4,
3475 x + 1, y + height - 1, x + width - 1, y + height - 1);
3482 gdk_gc_set_clip_rectangle (gc1, NULL);
3483 gdk_gc_set_clip_rectangle (gc2, NULL);
3484 gdk_gc_set_clip_rectangle (gc3, NULL);
3485 gdk_gc_set_clip_rectangle (gc4, NULL);
3490 gtk_default_draw_focus (GtkStyle *style,
3494 const gchar *detail,
3500 g_return_if_fail (GTK_IS_STYLE (style));
3501 g_return_if_fail (window != NULL);
3503 if (width == -1 && height == -1)
3505 gdk_window_get_size (window, &width, &height);
3509 else if (width == -1)
3511 gdk_window_get_size (window, &width, NULL);
3514 else if (height == -1)
3516 gdk_window_get_size (window, NULL, &height);
3521 gdk_gc_set_clip_rectangle (style->black_gc, area);
3523 if (detail && !strcmp (detail, "add-mode"))
3525 gdk_gc_set_line_attributes (style->black_gc, 1, GDK_LINE_ON_OFF_DASH, 0, 0);
3526 gdk_gc_set_dashes (style->black_gc, 0, "\4\4", 2);
3528 gdk_draw_rectangle (window,
3529 style->black_gc, FALSE,
3530 x, y, width, height);
3532 gdk_gc_set_line_attributes (style->black_gc, 1, GDK_LINE_SOLID, 0, 0);
3534 else if (detail && strcmp (detail, "treeview") == 0)
3537 gdk_gc_set_background (style->black_gc, &style->white);
3538 gdk_gc_set_line_attributes (style->black_gc, 1, GDK_LINE_DOUBLE_DASH, 0, 0);
3539 gdk_gc_set_dashes (style->black_gc, 0, "\4\4", 2);
3541 gdk_draw_rectangle (window,
3542 style->black_gc, FALSE,
3543 x, y, width, height);
3545 gdk_gc_set_line_attributes (style->black_gc, 1, GDK_LINE_SOLID, 0, 0);
3549 gdk_draw_rectangle (window,
3550 style->black_gc, FALSE,
3551 x, y, width, height);
3555 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
3559 gtk_default_draw_slider (GtkStyle *style,
3561 GtkStateType state_type,
3562 GtkShadowType shadow_type,
3565 const gchar *detail,
3570 GtkOrientation orientation)
3572 g_return_if_fail (GTK_IS_STYLE (style));
3573 g_return_if_fail (window != NULL);
3575 if (width == -1 && height == -1)
3576 gdk_window_get_size (window, &width, &height);
3577 else if (width == -1)
3578 gdk_window_get_size (window, &width, NULL);
3579 else if (height == -1)
3580 gdk_window_get_size (window, NULL, &height);
3582 gtk_paint_box (style, window, state_type, shadow_type,
3583 area, widget, detail, x, y, width, height);
3585 if (orientation == GTK_ORIENTATION_HORIZONTAL)
3586 gtk_paint_vline (style, window, state_type, area, widget, detail,
3588 height - style->ythickness - 1, width / 2);
3590 gtk_paint_hline (style, window, state_type, area, widget, detail,
3592 width - style->xthickness - 1, height / 2);
3596 draw_dot (GdkWindow *window,
3604 size = CLAMP (size, 2, 3);
3608 gdk_draw_point (window, light_gc, x, y);
3609 gdk_draw_point (window, light_gc, x+1, y+1);
3611 else if (size == 3);
3613 gdk_draw_point (window, light_gc, x, y);
3614 gdk_draw_point (window, light_gc, x+1, y);
3615 gdk_draw_point (window, light_gc, x, y+1);
3616 gdk_draw_point (window, dark_gc, x+1, y+2);
3617 gdk_draw_point (window, dark_gc, x+2, y+1);
3618 gdk_draw_point (window, dark_gc, x+2, y+2);
3623 gtk_default_draw_handle (GtkStyle *style,
3625 GtkStateType state_type,
3626 GtkShadowType shadow_type,
3629 const gchar *detail,
3634 GtkOrientation orientation)
3637 gint xthick, ythick;
3638 GdkGC *light_gc, *dark_gc;
3643 g_return_if_fail (GTK_IS_STYLE (style));
3644 g_return_if_fail (window != NULL);
3646 if (width == -1 && height == -1)
3647 gdk_window_get_size (window, &width, &height);
3648 else if (width == -1)
3649 gdk_window_get_size (window, &width, NULL);
3650 else if (height == -1)
3651 gdk_window_get_size (window, NULL, &height);
3653 gtk_paint_box (style, window, state_type, shadow_type, area, widget,
3654 detail, x, y, width, height);
3657 if (!strcmp (detail, "paned"))
3659 /* we want to ignore the shadow border in paned widgets */
3663 light_gc = style->light_gc[state_type];
3664 dark_gc = style->black_gc;
3668 xthick = style->xthickness;
3669 ythick = style->ythickness;
3671 light_gc = style->light_gc[state_type];
3672 dark_gc = style->dark_gc[state_type];
3675 rect.x = x + xthick;
3676 rect.y = y + ythick;
3677 rect.width = width - (xthick * 2);
3678 rect.height = height - (ythick * 2);
3681 intersect = gdk_rectangle_intersect (area, &rect, &dest);
3691 gdk_gc_set_clip_rectangle (light_gc, &dest);
3692 gdk_gc_set_clip_rectangle (dark_gc, &dest);
3694 if (!strcmp (detail, "paned"))
3699 gdk_window_get_size (window, &window_width, &window_height);
3701 if (orientation == GTK_ORIENTATION_HORIZONTAL)
3702 for (xx = window_width/2 - 15; xx <= window_width/2 + 15; xx += 5)
3703 draw_dot (window, light_gc, dark_gc, xx, window_height/2 - 1, 3);
3705 for (yy = window_height/2 - 15; yy <= window_height/2 + 15; yy += 5)
3706 draw_dot (window, light_gc, dark_gc, window_width/2 - 1, yy, 3);
3710 for (yy = y + ythick; yy < (y + height - ythick); yy += 3)
3711 for (xx = x + xthick; xx < (x + width - xthick); xx += 6)
3713 draw_dot (window, light_gc, dark_gc, xx, yy, 2);
3714 draw_dot (window, light_gc, dark_gc, xx + 3, yy + 1, 2);
3718 gdk_gc_set_clip_rectangle (light_gc, NULL);
3719 gdk_gc_set_clip_rectangle (dark_gc, NULL);
3723 gtk_default_draw_expander (GtkStyle *style,
3725 GtkStateType state_type,
3728 const gchar *detail,
3733 /* FIXME replace macro with a style property */
3740 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], area);
3741 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], area);
3747 points[0].y = y + (PM_SIZE + 2) / 6;
3748 points[1].x = points[0].x + 1 * (PM_SIZE + 2);
3749 points[1].y = points[0].y;
3750 points[2].x = (points[0].x + 1 * (PM_SIZE + 2) / 2);
3751 points[2].y = y + 2 * (PM_SIZE + 2) / 3;
3755 points[0].x = x + 1 * ((PM_SIZE + 2) / 6 + 2);
3756 points[0].y = y - 1;
3757 points[1].x = points[0].x;
3758 points[1].y = points[0].y + (PM_SIZE + 2);
3759 points[2].x = (points[0].x + 1 * (2 * (PM_SIZE + 2) / 3 - 1));
3760 points[2].y = points[0].y + (PM_SIZE + 2) / 2;
3763 gdk_draw_polygon (window, style->base_gc[GTK_STATE_NORMAL],
3765 gdk_draw_polygon (window, style->fg_gc[GTK_STATE_NORMAL],
3771 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], NULL);
3772 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], NULL);
3778 typedef struct _ByteRange ByteRange;
3787 range_new (guint start,
3790 ByteRange *br = g_new (ByteRange, 1);
3799 get_insensitive_layout (PangoLayout *layout)
3801 GSList *embossed_ranges = NULL;
3802 GSList *stippled_ranges = NULL;
3803 PangoLayoutIter *iter;
3804 GSList *tmp_list = NULL;
3805 PangoLayout *new_layout;
3806 PangoAttrList *attrs;
3807 GdkBitmap *stipple = NULL;
3809 iter = pango_layout_get_iter (layout);
3813 PangoLayoutRun *run;
3814 PangoAttribute *attr;
3815 gboolean need_stipple = FALSE;
3818 run = pango_layout_iter_get_run (iter);
3822 tmp_list = run->item->extra_attrs;
3824 while (tmp_list != NULL)
3826 attr = tmp_list->data;
3827 switch (attr->klass->type)
3829 case PANGO_ATTR_FOREGROUND:
3830 case PANGO_ATTR_BACKGROUND:
3831 need_stipple = TRUE;
3841 tmp_list = g_slist_next (tmp_list);
3844 br = range_new (run->item->offset, run->item->offset + run->item->length);
3847 stippled_ranges = g_slist_prepend (stippled_ranges, br);
3849 embossed_ranges = g_slist_prepend (embossed_ranges, br);
3852 while (pango_layout_iter_next_run (iter));
3854 pango_layout_iter_free (iter);
3856 new_layout = pango_layout_copy (layout);
3858 attrs = pango_layout_get_attributes (new_layout);
3862 /* Create attr list if there wasn't one */
3863 attrs = pango_attr_list_new ();
3864 pango_layout_set_attributes (new_layout, attrs);
3865 pango_attr_list_unref (attrs);
3868 tmp_list = embossed_ranges;
3869 while (tmp_list != NULL)
3871 PangoAttribute *attr;
3872 ByteRange *br = tmp_list->data;
3874 attr = gdk_pango_attr_embossed_new (TRUE);
3876 attr->start_index = br->start;
3877 attr->end_index = br->end;
3879 pango_attr_list_change (attrs, attr);
3883 tmp_list = g_slist_next (tmp_list);
3886 g_slist_free (embossed_ranges);
3888 tmp_list = stippled_ranges;
3889 while (tmp_list != NULL)
3891 PangoAttribute *attr;
3892 ByteRange *br = tmp_list->data;
3894 if (stipple == NULL)
3896 #define gray50_width 2
3897 #define gray50_height 2
3898 static char gray50_bits[] = {
3902 stipple = gdk_bitmap_create_from_data (NULL,
3903 gray50_bits, gray50_width,
3907 attr = gdk_pango_attr_stipple_new (stipple);
3909 attr->start_index = br->start;
3910 attr->end_index = br->end;
3912 pango_attr_list_change (attrs, attr);
3916 tmp_list = g_slist_next (tmp_list);
3919 g_slist_free (stippled_ranges);
3922 g_object_unref (G_OBJECT (stipple));
3928 gtk_default_draw_layout (GtkStyle *style,
3930 GtkStateType state_type,
3933 const gchar *detail,
3936 PangoLayout *layout)
3938 g_return_if_fail (GTK_IS_STYLE (style));
3939 g_return_if_fail (window != NULL);
3942 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], area);
3944 if (state_type == GTK_STATE_INSENSITIVE)
3948 ins = get_insensitive_layout (layout);
3950 gdk_draw_layout (window, style->fg_gc[state_type], x, y, ins);
3952 g_object_unref (G_OBJECT (ins));
3956 gdk_draw_layout (window, style->fg_gc[state_type], x, y, layout);
3960 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], NULL);
3964 gtk_default_draw_resize_grip (GtkStyle *style,
3966 GtkStateType state_type,
3969 const gchar *detail,
3976 g_return_if_fail (GTK_IS_STYLE (style));
3977 g_return_if_fail (window != NULL);
3981 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
3982 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
3985 /* make it square */
3986 if (width != height)
3987 width = height = MIN (width, height);
3991 case GDK_WINDOW_EDGE_SOUTH_EAST:
3998 while (xi < (x + width - 3))
4000 gdk_draw_line (window,
4001 style->light_gc[state_type],
4008 gdk_draw_line (window,
4009 style->dark_gc[state_type],
4016 gdk_draw_line (window,
4017 style->dark_gc[state_type],
4031 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
4032 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
4037 gtk_style_shade (GdkColor *a,
4045 red = (gdouble) a->red / 65535.0;
4046 green = (gdouble) a->green / 65535.0;
4047 blue = (gdouble) a->blue / 65535.0;
4049 rgb_to_hls (&red, &green, &blue);
4054 else if (green < 0.0)
4060 else if (blue < 0.0)
4063 hls_to_rgb (&red, &green, &blue);
4065 b->red = red * 65535.0;
4066 b->green = green * 65535.0;
4067 b->blue = blue * 65535.0;
4071 rgb_to_hls (gdouble *r,
4112 l = (max + min) / 2;
4119 s = (max - min) / (max + min);
4121 s = (max - min) / (2 - max - min);
4125 h = (green - blue) / delta;
4126 else if (green == max)
4127 h = 2 + (blue - red) / delta;
4128 else if (blue == max)
4129 h = 4 + (red - green) / delta;
4142 hls_to_rgb (gdouble *h,
4155 if (lightness <= 0.5)
4156 m2 = lightness * (1 + saturation);
4158 m2 = lightness + saturation - lightness * saturation;
4159 m1 = 2 * lightness - m2;
4161 if (saturation == 0)
4176 r = m1 + (m2 - m1) * hue / 60;
4180 r = m1 + (m2 - m1) * (240 - hue) / 60;
4191 g = m1 + (m2 - m1) * hue / 60;
4195 g = m1 + (m2 - m1) * (240 - hue) / 60;
4206 b = m1 + (m2 - m1) * hue / 60;
4210 b = m1 + (m2 - m1) * (240 - hue) / 60;
4221 gtk_paint_hline (GtkStyle *style,
4223 GtkStateType state_type,
4226 const gchar *detail,
4231 g_return_if_fail (GTK_IS_STYLE (style));
4232 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
4234 GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, area, widget, detail, x1, x2, y);
4238 gtk_paint_vline (GtkStyle *style,
4240 GtkStateType state_type,
4243 const gchar *detail,
4248 g_return_if_fail (GTK_IS_STYLE (style));
4249 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
4251 GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, area, widget, detail, y1, y2, x);
4255 gtk_paint_shadow (GtkStyle *style,
4257 GtkStateType state_type,
4258 GtkShadowType shadow_type,
4261 const gchar *detail,
4267 g_return_if_fail (GTK_IS_STYLE (style));
4268 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
4270 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4274 gtk_paint_polygon (GtkStyle *style,
4276 GtkStateType state_type,
4277 GtkShadowType shadow_type,
4280 const gchar *detail,
4285 g_return_if_fail (GTK_IS_STYLE (style));
4286 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
4288 GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, area, widget, detail, points, npoints, fill);
4292 gtk_paint_arrow (GtkStyle *style,
4294 GtkStateType state_type,
4295 GtkShadowType shadow_type,
4298 const gchar *detail,
4299 GtkArrowType arrow_type,
4306 g_return_if_fail (GTK_IS_STYLE (style));
4307 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
4309 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, area, widget, detail, arrow_type, fill, x, y, width, height);
4313 gtk_paint_diamond (GtkStyle *style,
4315 GtkStateType state_type,
4316 GtkShadowType shadow_type,
4319 const gchar *detail,
4325 g_return_if_fail (GTK_IS_STYLE (style));
4326 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
4328 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4332 gtk_paint_string (GtkStyle *style,
4334 GtkStateType state_type,
4337 const gchar *detail,
4340 const gchar *string)
4342 g_return_if_fail (GTK_IS_STYLE (style));
4343 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
4345 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, area, widget, detail, x, y, string);
4349 gtk_paint_box (GtkStyle *style,
4351 GtkStateType state_type,
4352 GtkShadowType shadow_type,
4355 const gchar *detail,
4361 g_return_if_fail (GTK_IS_STYLE (style));
4362 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
4364 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4368 gtk_paint_flat_box (GtkStyle *style,
4370 GtkStateType state_type,
4371 GtkShadowType shadow_type,
4374 const gchar *detail,
4380 g_return_if_fail (GTK_IS_STYLE (style));
4381 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
4383 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4387 gtk_paint_check (GtkStyle *style,
4389 GtkStateType state_type,
4390 GtkShadowType shadow_type,
4393 const gchar *detail,
4399 g_return_if_fail (GTK_IS_STYLE (style));
4400 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
4402 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4406 gtk_paint_option (GtkStyle *style,
4408 GtkStateType state_type,
4409 GtkShadowType shadow_type,
4412 const gchar *detail,
4418 g_return_if_fail (GTK_IS_STYLE (style));
4419 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
4421 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4425 gtk_paint_tab (GtkStyle *style,
4427 GtkStateType state_type,
4428 GtkShadowType shadow_type,
4431 const gchar *detail,
4437 g_return_if_fail (GTK_IS_STYLE (style));
4438 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
4440 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4444 gtk_paint_shadow_gap (GtkStyle *style,
4446 GtkStateType state_type,
4447 GtkShadowType shadow_type,
4455 GtkPositionType gap_side,
4459 g_return_if_fail (GTK_IS_STYLE (style));
4460 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
4462 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);
4467 gtk_paint_box_gap (GtkStyle *style,
4469 GtkStateType state_type,
4470 GtkShadowType shadow_type,
4478 GtkPositionType gap_side,
4482 g_return_if_fail (GTK_IS_STYLE (style));
4483 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
4485 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);
4489 gtk_paint_extension (GtkStyle *style,
4491 GtkStateType state_type,
4492 GtkShadowType shadow_type,
4500 GtkPositionType gap_side)
4502 g_return_if_fail (GTK_IS_STYLE (style));
4503 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
4505 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, gap_side);
4509 gtk_paint_focus (GtkStyle *style,
4513 const gchar *detail,
4519 g_return_if_fail (GTK_IS_STYLE (style));
4520 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
4522 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, area, widget, detail, x, y, width, height);
4526 gtk_paint_slider (GtkStyle *style,
4528 GtkStateType state_type,
4529 GtkShadowType shadow_type,
4532 const gchar *detail,
4537 GtkOrientation orientation)
4539 g_return_if_fail (GTK_IS_STYLE (style));
4540 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
4542 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
4546 gtk_paint_handle (GtkStyle *style,
4548 GtkStateType state_type,
4549 GtkShadowType shadow_type,
4552 const gchar *detail,
4557 GtkOrientation orientation)
4559 g_return_if_fail (GTK_IS_STYLE (style));
4560 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
4562 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
4566 gtk_paint_expander (GtkStyle *style,
4568 GtkStateType state_type,
4571 const gchar *detail,
4576 g_return_if_fail (GTK_IS_STYLE (style));
4577 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
4579 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type, area,
4580 widget, detail, x, y, is_open);
4584 gtk_paint_layout (GtkStyle *style,
4586 GtkStateType state_type,
4589 const gchar *detail,
4592 PangoLayout *layout)
4594 g_return_if_fail (GTK_IS_STYLE (style));
4595 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
4597 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, area,
4598 widget, detail, x, y, layout);
4602 gtk_paint_resize_grip (GtkStyle *style,
4604 GtkStateType state_type,
4607 const gchar *detail,
4615 g_return_if_fail (GTK_IS_STYLE (style));
4616 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
4618 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, window, state_type,
4619 area, widget, detail,
4620 edge, x, y, width, height);
4624 gtk_border_copy (const GtkBorder *border)
4626 return (GtkBorder *)g_memdup (border, sizeof (GtkBorder));
4630 gtk_border_free (GtkBorder *border)