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_style_shade (GdkColor *a,
292 static void rgb_to_hls (gdouble *r,
295 static void hls_to_rgb (gdouble *h,
300 /* --- variables --- */
301 static GdkColor gtk_default_normal_fg = { 0, 0, 0, 0 };
302 static GdkColor gtk_default_active_fg = { 0, 0, 0, 0 };
303 static GdkColor gtk_default_prelight_fg = { 0, 0, 0, 0 };
304 static GdkColor gtk_default_selected_fg = { 0, 0xffff, 0xffff, 0xffff };
305 static GdkColor gtk_default_insensitive_fg = { 0, 0x7530, 0x7530, 0x7530 };
307 static GdkColor gtk_default_normal_bg = { 0, 0xd6d6, 0xd6d6, 0xd6d6 };
308 static GdkColor gtk_default_active_bg = { 0, 0xc350, 0xc350, 0xc350 };
309 static GdkColor gtk_default_prelight_bg = { 0, 0xea60, 0xea60, 0xea60 };
310 static GdkColor gtk_default_selected_bg = { 0, 0, 0, 0x9c40 };
311 static GdkColor gtk_default_insensitive_bg = { 0, 0xd6d6, 0xd6d6, 0xd6d6 };
313 static gpointer parent_class = NULL;
314 static GdkFont *static_default_font = NULL;
317 /* --- functions --- */
319 gtk_style_get_type (void)
321 static GType style_type = 0;
325 static const GTypeInfo style_info =
327 sizeof (GtkStyleClass),
328 (GBaseInitFunc) NULL,
329 (GBaseFinalizeFunc) NULL,
330 (GClassInitFunc) gtk_style_class_init,
331 NULL, /* class_finalize */
332 NULL, /* class_data */
335 (GInstanceInitFunc) gtk_style_init,
338 style_type = g_type_register_static (G_TYPE_OBJECT,
347 gtk_style_init (GtkStyle *style)
351 style->font_desc = pango_font_description_from_string ("Sans 10");
353 if (!static_default_font)
355 static_default_font = gdk_font_from_description (style->font_desc);
357 if (!static_default_font)
358 static_default_font = gdk_font_load ("fixed");
360 if (!static_default_font)
361 g_error ("Unable to load \"fixed\" font");
364 style->font = static_default_font;
365 gdk_font_ref (style->font);
367 style->attach_count = 0;
368 style->colormap = NULL;
371 style->black.red = 0;
372 style->black.green = 0;
373 style->black.blue = 0;
375 style->white.red = 65535;
376 style->white.green = 65535;
377 style->white.blue = 65535;
379 style->black_gc = NULL;
380 style->white_gc = NULL;
382 style->fg[GTK_STATE_NORMAL] = gtk_default_normal_fg;
383 style->fg[GTK_STATE_ACTIVE] = gtk_default_active_fg;
384 style->fg[GTK_STATE_PRELIGHT] = gtk_default_prelight_fg;
385 style->fg[GTK_STATE_SELECTED] = gtk_default_selected_fg;
386 style->fg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
388 style->bg[GTK_STATE_NORMAL] = gtk_default_normal_bg;
389 style->bg[GTK_STATE_ACTIVE] = gtk_default_active_bg;
390 style->bg[GTK_STATE_PRELIGHT] = gtk_default_prelight_bg;
391 style->bg[GTK_STATE_SELECTED] = gtk_default_selected_bg;
392 style->bg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_bg;
394 for (i = 0; i < 4; i++)
396 style->text[i] = style->fg[i];
397 style->base[i] = style->white;
400 style->base[GTK_STATE_INSENSITIVE] = gtk_default_prelight_bg;
401 style->text[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
403 for (i = 0; i < 5; i++)
404 style->bg_pixmap[i] = NULL;
406 style->rc_style = NULL;
408 for (i = 0; i < 5; i++)
410 style->fg_gc[i] = NULL;
411 style->bg_gc[i] = NULL;
412 style->light_gc[i] = NULL;
413 style->dark_gc[i] = NULL;
414 style->mid_gc[i] = NULL;
415 style->text_gc[i] = NULL;
416 style->base_gc[i] = NULL;
419 style->xthickness = 2;
420 style->ythickness = 2;
422 style->property_cache = NULL;
426 gtk_style_class_init (GtkStyleClass *klass)
428 GObjectClass *object_class = G_OBJECT_CLASS (klass);
430 parent_class = g_type_class_peek_parent (klass);
432 object_class->finalize = gtk_style_finalize;
434 klass->clone = gtk_style_real_clone;
435 klass->copy = gtk_style_real_copy;
436 klass->init_from_rc = gtk_style_real_init_from_rc;
437 klass->realize = gtk_style_real_realize;
438 klass->unrealize = gtk_style_real_unrealize;
439 klass->set_background = gtk_style_real_set_background;
440 klass->render_icon = gtk_default_render_icon;
442 klass->draw_hline = gtk_default_draw_hline;
443 klass->draw_vline = gtk_default_draw_vline;
444 klass->draw_shadow = gtk_default_draw_shadow;
445 klass->draw_polygon = gtk_default_draw_polygon;
446 klass->draw_arrow = gtk_default_draw_arrow;
447 klass->draw_diamond = gtk_default_draw_diamond;
448 klass->draw_string = gtk_default_draw_string;
449 klass->draw_box = gtk_default_draw_box;
450 klass->draw_flat_box = gtk_default_draw_flat_box;
451 klass->draw_check = gtk_default_draw_check;
452 klass->draw_option = gtk_default_draw_option;
453 klass->draw_tab = gtk_default_draw_tab;
454 klass->draw_shadow_gap = gtk_default_draw_shadow_gap;
455 klass->draw_box_gap = gtk_default_draw_box_gap;
456 klass->draw_extension = gtk_default_draw_extension;
457 klass->draw_focus = gtk_default_draw_focus;
458 klass->draw_slider = gtk_default_draw_slider;
459 klass->draw_handle = gtk_default_draw_handle;
460 klass->draw_expander = gtk_default_draw_expander;
461 klass->draw_layout = gtk_default_draw_layout;
465 gtk_style_finalize (GObject *object)
467 GtkStyle *style = GTK_STYLE (object);
469 g_return_if_fail (style->attach_count == 0);
471 if (style->property_cache)
475 for (i = 0; i < style->property_cache->n_nodes; i++)
477 PropertyValue *node = g_bsearch_array_get_nth (style->property_cache, i);
479 g_param_spec_unref (node->pspec);
480 g_value_unset (&node->value);
482 g_bsearch_array_destroy (style->property_cache);
483 style->property_cache = NULL;
488 if (style->styles->data != style)
489 g_slist_remove (style->styles, style);
492 GSList *tmp_list = style->styles->next;
496 GTK_STYLE (tmp_list->data)->styles = style->styles->next;
497 tmp_list = tmp_list->next;
499 g_slist_free_1 (style->styles);
503 gdk_font_unref (style->font);
504 pango_font_description_free (style->font_desc);
507 gtk_rc_style_unref (style->rc_style);
509 G_OBJECT_CLASS (parent_class)->finalize (object);
514 gtk_style_copy (GtkStyle *style)
518 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
520 new_style = GTK_STYLE_GET_CLASS (style)->clone (style);
521 GTK_STYLE_GET_CLASS (style)->copy (new_style, style);
527 gtk_style_duplicate (GtkStyle *style)
531 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
533 new_style = gtk_style_copy (style);
535 style->styles = g_slist_append (style->styles, new_style);
536 new_style->styles = style->styles;
546 style = g_object_new (GTK_TYPE_STYLE, NULL);
551 /*************************************************************
553 * Attach a style to a window; this process allocates the
554 * colors and creates the GC's for the style - it specializes
555 * it to a particular visual and colormap. The process
556 * may involve the creation of a new style if the style
557 * has already been attached to a window with a different
558 * style and colormap.
563 * Either the style parameter, or a newly created style.
564 * If the style is newly created, the style parameter
565 * will be dereferenced, and the new style will have
566 * a reference count belonging to the caller.
568 * FIXME: The sequence -
569 * create a style => s1
570 * attach s1 to v1, c1 => s1
571 * attach s1 to v2, c2 => s2
572 * detach s1 from v1, c1
573 * attach s1 to v2, c2 => s3
574 * results in two separate, unlinked styles s2 and s3 which
575 * are identical and could be shared. To fix this, we would
576 * want to never remove a style from the list of linked
577 * styles as long as as it has a reference count. However, the
578 * disadvantage of doing it this way means that we would need two
579 * passes through the linked list when attaching (one to check for
580 * matching styles, one to look for empty unattached styles - but
581 * it will almost never be longer than 2 elements.
582 *************************************************************/
585 gtk_style_attach (GtkStyle *style,
589 GtkStyle *new_style = NULL;
590 GdkColormap *colormap;
592 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
593 g_return_val_if_fail (window != NULL, NULL);
595 colormap = gdk_window_get_colormap (window);
598 style->styles = g_slist_append (NULL, style);
600 styles = style->styles;
603 new_style = styles->data;
605 if (new_style->attach_count == 0)
607 gtk_style_realize (new_style, colormap);
610 else if (new_style->colormap == colormap)
614 styles = styles->next;
619 new_style = gtk_style_duplicate (style);
620 gtk_style_realize (new_style, colormap);
623 /* A style gets a refcount from being attached */
624 if (new_style->attach_count == 0)
625 gtk_style_ref (new_style);
627 /* Another refcount belongs to the parent */
628 if (style != new_style)
630 gtk_style_unref (style);
631 gtk_style_ref (new_style);
634 new_style->attach_count++;
640 gtk_style_detach (GtkStyle *style)
642 g_return_if_fail (GTK_IS_STYLE (style));
644 style->attach_count -= 1;
645 if (style->attach_count == 0)
647 GTK_STYLE_GET_CLASS (style)->unrealize (style);
649 gdk_colormap_unref (style->colormap);
650 style->colormap = NULL;
652 gtk_style_unref (style);
657 gtk_style_ref (GtkStyle *style)
659 return (GtkStyle *) g_object_ref (G_OBJECT (style));
663 gtk_style_unref (GtkStyle *style)
665 g_object_unref (G_OBJECT (style));
669 gtk_style_realize (GtkStyle *style,
670 GdkColormap *colormap)
672 g_return_if_fail (GTK_IS_STYLE (style));
673 g_return_if_fail (GDK_IS_COLORMAP (colormap));
675 style->colormap = gdk_colormap_ref (colormap);
676 style->depth = gdk_colormap_get_visual (colormap)->depth;
678 GTK_STYLE_GET_CLASS (style)->realize (style);
682 gtk_style_lookup_icon_set (GtkStyle *style,
683 const char *stock_id)
687 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
688 g_return_val_if_fail (stock_id != NULL, NULL);
690 iter = style->icon_factories;
693 GtkIconSet *icon_set = gtk_icon_factory_lookup (GTK_ICON_FACTORY (iter->data),
698 iter = g_slist_next (iter);
701 return gtk_icon_factory_lookup_default (stock_id);
705 gtk_draw_hline (GtkStyle *style,
707 GtkStateType state_type,
712 g_return_if_fail (GTK_IS_STYLE (style));
713 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
715 GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, NULL, NULL, NULL, x1, x2, y);
720 gtk_draw_vline (GtkStyle *style,
722 GtkStateType state_type,
727 g_return_if_fail (GTK_IS_STYLE (style));
728 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
730 GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, NULL, NULL, NULL, y1, y2, x);
735 gtk_draw_shadow (GtkStyle *style,
737 GtkStateType state_type,
738 GtkShadowType shadow_type,
744 g_return_if_fail (GTK_IS_STYLE (style));
745 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
747 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
751 gtk_draw_polygon (GtkStyle *style,
753 GtkStateType state_type,
754 GtkShadowType shadow_type,
759 g_return_if_fail (GTK_IS_STYLE (style));
760 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_polygon != NULL);
762 GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, NULL, NULL, NULL, points, npoints, fill);
766 gtk_draw_arrow (GtkStyle *style,
768 GtkStateType state_type,
769 GtkShadowType shadow_type,
770 GtkArrowType arrow_type,
777 g_return_if_fail (GTK_IS_STYLE (style));
778 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
780 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, NULL, NULL, NULL, arrow_type, fill, x, y, width, height);
785 gtk_draw_diamond (GtkStyle *style,
787 GtkStateType state_type,
788 GtkShadowType shadow_type,
794 g_return_if_fail (GTK_IS_STYLE (style));
795 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
797 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
802 gtk_draw_string (GtkStyle *style,
804 GtkStateType state_type,
809 g_return_if_fail (GTK_IS_STYLE (style));
810 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
812 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, NULL, NULL, NULL, x, y, string);
816 gtk_draw_box (GtkStyle *style,
818 GtkStateType state_type,
819 GtkShadowType shadow_type,
825 g_return_if_fail (GTK_IS_STYLE (style));
826 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
828 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
832 gtk_draw_flat_box (GtkStyle *style,
834 GtkStateType state_type,
835 GtkShadowType shadow_type,
841 g_return_if_fail (GTK_IS_STYLE (style));
842 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
844 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
848 gtk_draw_check (GtkStyle *style,
850 GtkStateType state_type,
851 GtkShadowType shadow_type,
857 g_return_if_fail (GTK_IS_STYLE (style));
858 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
860 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
864 gtk_draw_option (GtkStyle *style,
866 GtkStateType state_type,
867 GtkShadowType shadow_type,
873 g_return_if_fail (GTK_IS_STYLE (style));
874 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
876 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
880 gtk_draw_tab (GtkStyle *style,
882 GtkStateType state_type,
883 GtkShadowType shadow_type,
889 g_return_if_fail (GTK_IS_STYLE (style));
890 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
892 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
896 gtk_draw_shadow_gap (GtkStyle *style,
898 GtkStateType state_type,
899 GtkShadowType shadow_type,
904 GtkPositionType gap_side,
908 g_return_if_fail (GTK_IS_STYLE (style));
909 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
911 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);
915 gtk_draw_box_gap (GtkStyle *style,
917 GtkStateType state_type,
918 GtkShadowType shadow_type,
923 GtkPositionType gap_side,
927 g_return_if_fail (GTK_IS_STYLE (style));
928 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
930 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);
934 gtk_draw_extension (GtkStyle *style,
936 GtkStateType state_type,
937 GtkShadowType shadow_type,
942 GtkPositionType gap_side)
944 g_return_if_fail (GTK_IS_STYLE (style));
945 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
947 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, gap_side);
951 gtk_draw_focus (GtkStyle *style,
958 g_return_if_fail (GTK_IS_STYLE (style));
959 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
961 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, NULL, NULL, NULL, x, y, width, height);
965 gtk_draw_slider (GtkStyle *style,
967 GtkStateType state_type,
968 GtkShadowType shadow_type,
973 GtkOrientation orientation)
975 g_return_if_fail (GTK_IS_STYLE (style));
976 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
978 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
982 gtk_draw_handle (GtkStyle *style,
984 GtkStateType state_type,
985 GtkShadowType shadow_type,
990 GtkOrientation orientation)
992 g_return_if_fail (GTK_IS_STYLE (style));
993 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
995 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
999 gtk_draw_expander (GtkStyle *style,
1001 GtkStateType state_type,
1006 g_return_if_fail (GTK_IS_STYLE (style));
1007 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
1009 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type,
1015 gtk_draw_layout (GtkStyle *style,
1017 GtkStateType state_type,
1020 PangoLayout *layout)
1022 g_return_if_fail (GTK_IS_STYLE (style));
1023 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
1025 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type,
1031 gtk_style_set_background (GtkStyle *style,
1033 GtkStateType state_type)
1035 g_return_if_fail (GTK_IS_STYLE (style));
1036 g_return_if_fail (window != NULL);
1038 GTK_STYLE_GET_CLASS (style)->set_background (style, window, state_type);
1041 /* Default functions */
1043 gtk_style_real_clone (GtkStyle *style)
1045 return GTK_STYLE (g_object_new (G_OBJECT_TYPE (style), NULL));
1049 gtk_style_real_copy (GtkStyle *style,
1054 for (i = 0; i < 5; i++)
1056 style->fg[i] = src->fg[i];
1057 style->bg[i] = src->bg[i];
1058 style->text[i] = src->text[i];
1059 style->base[i] = src->base[i];
1061 style->bg_pixmap[i] = src->bg_pixmap[i];
1065 gdk_font_unref (style->font);
1066 style->font = src->font;
1068 gdk_font_ref (style->font);
1070 if (style->font_desc)
1071 pango_font_description_free (style->font_desc);
1073 style->font_desc = pango_font_description_copy (src->font_desc);
1075 style->font_desc = NULL;
1077 style->xthickness = src->xthickness;
1078 style->ythickness = src->ythickness;
1080 if (style->rc_style)
1081 gtk_rc_style_unref (style->rc_style);
1082 style->rc_style = src->rc_style;
1084 gtk_rc_style_ref (src->rc_style);
1086 /* don't copy, just clear cache */
1087 if (style->property_cache)
1091 for (i = 0; i < style->property_cache->n_nodes; i++)
1093 PropertyValue *node = g_bsearch_array_get_nth (style->property_cache, i);
1095 g_param_spec_unref (node->pspec);
1096 g_value_unset (&node->value);
1098 g_bsearch_array_destroy (style->property_cache);
1099 style->property_cache = NULL;
1104 gtk_style_real_init_from_rc (GtkStyle *style,
1105 GtkRcStyle *rc_style)
1110 /* cache _should_ be still empty */
1111 if (style->property_cache)
1115 for (i = 0; i < style->property_cache->n_nodes; i++)
1117 PropertyValue *node = g_bsearch_array_get_nth (style->property_cache, i);
1119 g_param_spec_unref (node->pspec);
1120 g_value_unset (&node->value);
1122 g_bsearch_array_destroy (style->property_cache);
1123 style->property_cache = NULL;
1126 if (rc_style->font_desc)
1128 pango_font_description_free (style->font_desc);
1129 style->font_desc = pango_font_description_copy (rc_style->font_desc);
1131 old_font = style->font;
1132 style->font = gdk_font_from_description (style->font_desc);
1134 gdk_font_unref (old_font);
1136 style->font = old_font;
1139 for (i = 0; i < 5; i++)
1141 if (rc_style->color_flags[i] & GTK_RC_FG)
1142 style->fg[i] = rc_style->fg[i];
1143 if (rc_style->color_flags[i] & GTK_RC_BG)
1144 style->bg[i] = rc_style->bg[i];
1145 if (rc_style->color_flags[i] & GTK_RC_TEXT)
1146 style->text[i] = rc_style->text[i];
1147 if (rc_style->color_flags[i] & GTK_RC_BASE)
1148 style->base[i] = rc_style->base[i];
1151 if (rc_style->xthickness >= 0)
1152 style->xthickness = rc_style->xthickness;
1153 if (rc_style->ythickness >= 0)
1154 style->ythickness = rc_style->ythickness;
1156 if (rc_style->icon_factories)
1160 style->icon_factories = g_slist_copy (rc_style->icon_factories);
1162 iter = style->icon_factories;
1163 while (iter != NULL)
1165 g_object_ref (G_OBJECT (iter->data));
1167 iter = g_slist_next (iter);
1173 style_property_values_cmp (gconstpointer bsearch_node1,
1174 gconstpointer bsearch_node2)
1176 const PropertyValue *val1 = bsearch_node1;
1177 const PropertyValue *val2 = bsearch_node2;
1180 cmp = G_BSEARCH_ARRAY_CMP (val1->widget_type, val2->widget_type);
1182 cmp = G_BSEARCH_ARRAY_CMP (val1->pspec, val2->pspec);
1188 _gtk_style_peek_property_value (GtkStyle *style,
1191 GtkRcPropertyParser parser)
1193 PropertyValue *pcache, key = { 0, NULL, { 0, } };
1194 const GtkRcProperty *rcprop = NULL;
1196 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1197 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), NULL);
1198 g_return_val_if_fail (g_type_is_a (pspec->owner_type, GTK_TYPE_WIDGET), NULL);
1199 g_return_val_if_fail (g_type_is_a (widget_type, pspec->owner_type), NULL);
1201 /* need value cache array */
1202 if (!style->property_cache)
1203 style->property_cache = g_bsearch_array_new (sizeof (PropertyValue),
1204 style_property_values_cmp,
1206 /* lookup, or insert value if not yet present */
1207 key.widget_type = widget_type;
1209 pcache = g_bsearch_array_insert (style->property_cache, &key, FALSE);
1210 if (G_VALUE_TYPE (&pcache->value))
1211 return &pcache->value;
1213 /* cache miss, initialize value type, then set contents */
1214 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1216 /* value provided by rc style? */
1217 if (style->rc_style)
1219 GQuark prop_quark = g_quark_from_string (pspec->name);
1223 rcprop = _gtk_rc_style_lookup_rc_property (style->rc_style,
1224 g_type_qname (widget_type),
1228 widget_type = g_type_parent (widget_type);
1230 while (g_type_is_a (widget_type, pspec->owner_type));
1233 /* when supplied by rc style, we need to convert */
1236 if (G_VALUE_TYPE (&rcprop->value) == G_TYPE_GSTRING)
1240 /* value still unparsed, need to revert to user supplied parser function */
1242 gstring = g_value_get_boxed (&rcprop->value);
1244 if (!parser || !parser (pspec, gstring, &pcache->value) ||
1245 g_param_value_validate (pspec, &pcache->value))
1247 gchar *contents = g_strescape (gstring->str, NULL);
1249 g_message ("%s: failed to parse property `%s::%s' of type `%s' from rc file value \"%s\"",
1251 g_type_name (pspec->owner_type), pspec->name,
1252 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1260 /* we use the normal conversion functionality of param specs */
1261 if (!g_param_value_convert (pspec, &rcprop->value, &pcache->value, TRUE))
1263 gchar *contents = g_strdup_value_contents (&rcprop->value);
1265 g_message ("%s: failed to retrive property `%s::%s' of type `%s' from rc file value \"%s\" of type `%s'",
1267 g_type_name (pspec->owner_type), pspec->name,
1268 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1270 G_VALUE_TYPE_NAME (&rcprop->value));
1277 /* not supplied by rc style (or conversion failed), revert to default */
1279 g_param_value_set_default (pspec, &pcache->value);
1281 return &pcache->value;
1285 gtk_style_real_realize (GtkStyle *style)
1287 GdkGCValues gc_values;
1288 GdkGCValuesMask gc_values_mask;
1292 for (i = 0; i < 5; i++)
1294 gtk_style_shade (&style->bg[i], &style->light[i], LIGHTNESS_MULT);
1295 gtk_style_shade (&style->bg[i], &style->dark[i], DARKNESS_MULT);
1297 style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
1298 style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
1299 style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
1302 gdk_color_black (style->colormap, &style->black);
1303 gdk_color_white (style->colormap, &style->white);
1305 gc_values_mask = GDK_GC_FOREGROUND | GDK_GC_FONT;
1306 if (style->font->type == GDK_FONT_FONT)
1308 gc_values.font = style->font;
1310 else if (style->font->type == GDK_FONT_FONTSET)
1312 gc_values.font = static_default_font;
1315 gc_values.foreground = style->black;
1316 style->black_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1318 gc_values.foreground = style->white;
1319 style->white_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1321 for (i = 0; i < 5; i++)
1323 if (style->rc_style && style->rc_style->bg_pixmap_name[i])
1324 style->bg_pixmap[i] = gtk_rc_load_image (style->colormap,
1326 style->rc_style->bg_pixmap_name[i]);
1328 if (!gdk_color_alloc (style->colormap, &style->fg[i]))
1329 g_warning ("unable to allocate color: ( %d %d %d )",
1330 style->fg[i].red, style->fg[i].green, style->fg[i].blue);
1331 if (!gdk_color_alloc (style->colormap, &style->bg[i]))
1332 g_warning ("unable to allocate color: ( %d %d %d )",
1333 style->bg[i].red, style->bg[i].green, style->bg[i].blue);
1334 if (!gdk_color_alloc (style->colormap, &style->light[i]))
1335 g_warning ("unable to allocate color: ( %d %d %d )",
1336 style->light[i].red, style->light[i].green, style->light[i].blue);
1337 if (!gdk_color_alloc (style->colormap, &style->dark[i]))
1338 g_warning ("unable to allocate color: ( %d %d %d )",
1339 style->dark[i].red, style->dark[i].green, style->dark[i].blue);
1340 if (!gdk_color_alloc (style->colormap, &style->mid[i]))
1341 g_warning ("unable to allocate color: ( %d %d %d )",
1342 style->mid[i].red, style->mid[i].green, style->mid[i].blue);
1343 if (!gdk_color_alloc (style->colormap, &style->text[i]))
1344 g_warning ("unable to allocate color: ( %d %d %d )",
1345 style->text[i].red, style->text[i].green, style->text[i].blue);
1346 if (!gdk_color_alloc (style->colormap, &style->base[i]))
1347 g_warning ("unable to allocate color: ( %d %d %d )",
1348 style->base[i].red, style->base[i].green, style->base[i].blue);
1350 gc_values.foreground = style->fg[i];
1351 style->fg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1353 gc_values.foreground = style->bg[i];
1354 style->bg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1356 gc_values.foreground = style->light[i];
1357 style->light_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1359 gc_values.foreground = style->dark[i];
1360 style->dark_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1362 gc_values.foreground = style->mid[i];
1363 style->mid_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1365 gc_values.foreground = style->text[i];
1366 style->text_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1368 gc_values.foreground = style->base[i];
1369 style->base_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1374 gtk_style_real_unrealize (GtkStyle *style)
1378 gtk_gc_release (style->black_gc);
1379 gtk_gc_release (style->white_gc);
1381 for (i = 0; i < 5; i++)
1383 gtk_gc_release (style->fg_gc[i]);
1384 gtk_gc_release (style->bg_gc[i]);
1385 gtk_gc_release (style->light_gc[i]);
1386 gtk_gc_release (style->dark_gc[i]);
1387 gtk_gc_release (style->mid_gc[i]);
1388 gtk_gc_release (style->text_gc[i]);
1389 gtk_gc_release (style->base_gc[i]);
1391 if (style->bg_pixmap[i] && style->bg_pixmap[i] != (GdkPixmap*) GDK_PARENT_RELATIVE)
1392 gdk_pixmap_unref (style->bg_pixmap[i]);
1395 gdk_colormap_free_colors (style->colormap, style->fg, 5);
1396 gdk_colormap_free_colors (style->colormap, style->bg, 5);
1397 gdk_colormap_free_colors (style->colormap, style->light, 5);
1398 gdk_colormap_free_colors (style->colormap, style->dark, 5);
1399 gdk_colormap_free_colors (style->colormap, style->mid, 5);
1400 gdk_colormap_free_colors (style->colormap, style->text, 5);
1401 gdk_colormap_free_colors (style->colormap, style->base, 5);
1405 gtk_style_real_set_background (GtkStyle *style,
1407 GtkStateType state_type)
1410 gint parent_relative;
1412 if (style->bg_pixmap[state_type])
1414 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1417 parent_relative = TRUE;
1421 pixmap = style->bg_pixmap[state_type];
1422 parent_relative = FALSE;
1425 gdk_window_set_back_pixmap (window, pixmap, parent_relative);
1428 gdk_window_set_background (window, &style->bg[state_type]);
1432 gtk_style_render_icon (GtkStyle *style,
1433 const GtkIconSource *source,
1434 GtkTextDirection direction,
1438 const gchar *detail)
1442 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1443 g_return_val_if_fail (GTK_STYLE_GET_CLASS (style)->render_icon != NULL, NULL);
1445 pixbuf = GTK_STYLE_GET_CLASS (style)->render_icon (style, source, direction, state,
1446 size, widget, detail);
1448 g_return_val_if_fail (pixbuf != NULL, NULL);
1453 /* Default functions */
1455 gtk_style_apply_default_background (GtkStyle *style,
1458 GtkStateType state_type,
1465 GdkRectangle new_rect, old_rect;
1471 old_rect.width = width;
1472 old_rect.height = height;
1474 if (!gdk_rectangle_intersect (area, &old_rect, &new_rect))
1481 new_rect.width = width;
1482 new_rect.height = height;
1485 if (!style->bg_pixmap[state_type] ||
1486 GDK_IS_PIXMAP (window) ||
1487 (!set_bg && style->bg_pixmap[state_type] != (GdkPixmap*) GDK_PARENT_RELATIVE))
1489 GdkGC *gc = style->bg_gc[state_type];
1491 if (style->bg_pixmap[state_type])
1493 gdk_gc_set_fill (gc, GDK_TILED);
1494 gdk_gc_set_tile (gc, style->bg_pixmap[state_type]);
1497 gdk_draw_rectangle (window, gc, TRUE,
1498 new_rect.x, new_rect.y, new_rect.width, new_rect.height);
1499 if (style->bg_pixmap[state_type])
1500 gdk_gc_set_fill (gc, GDK_SOLID);
1506 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1507 gdk_window_set_back_pixmap (window, NULL, TRUE);
1509 gdk_window_set_back_pixmap (window, style->bg_pixmap[state_type], FALSE);
1512 gdk_window_clear_area (window,
1513 new_rect.x, new_rect.y,
1514 new_rect.width, new_rect.height);
1519 scale_or_ref (GdkPixbuf *src,
1523 if (width == gdk_pixbuf_get_width (src) &&
1524 height == gdk_pixbuf_get_height (src))
1526 gdk_pixbuf_ref (src);
1531 return gdk_pixbuf_scale_simple (src,
1533 GDK_INTERP_BILINEAR);
1538 gtk_default_render_icon (GtkStyle *style,
1539 const GtkIconSource *source,
1540 GtkTextDirection direction,
1544 const gchar *detail)
1551 /* Oddly, style can be NULL in this function, because
1552 * GtkIconSet can be used without a style and if so
1553 * it uses this function.
1556 g_return_val_if_fail (source->pixbuf != NULL, NULL);
1558 if (!gtk_icon_size_lookup (size, &width, &height))
1560 g_warning (G_STRLOC ": invalid icon size `%d'", size);
1564 /* If the size was wildcarded, then scale; otherwise, leave it
1567 if (source->any_size)
1568 scaled = scale_or_ref (source->pixbuf, width, height);
1570 scaled = GDK_PIXBUF (g_object_ref (G_OBJECT (source->pixbuf)));
1572 /* If the state was wildcarded, then generate a state. */
1573 if (source->any_state)
1575 if (state == GTK_STATE_INSENSITIVE)
1577 stated = gdk_pixbuf_copy (scaled);
1579 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
1582 gdk_pixbuf_unref (scaled);
1584 else if (state == GTK_STATE_PRELIGHT)
1586 stated = gdk_pixbuf_copy (scaled);
1588 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
1591 gdk_pixbuf_unref (scaled);
1605 gtk_default_draw_hline (GtkStyle *style,
1607 GtkStateType state_type,
1610 const gchar *detail,
1615 gint thickness_light;
1616 gint thickness_dark;
1619 g_return_if_fail (GTK_IS_STYLE (style));
1620 g_return_if_fail (window != NULL);
1622 thickness_light = style->ythickness / 2;
1623 thickness_dark = style->ythickness - thickness_light;
1627 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
1628 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
1631 if (detail && !strcmp (detail, "label"))
1633 if (state_type == GTK_STATE_INSENSITIVE)
1634 gdk_draw_line (window, style->white_gc, x1 + 1, y + 1, x2 + 1, y + 1);
1635 gdk_draw_line (window, style->fg_gc[state_type], x1, y, x2, y);
1639 for (i = 0; i < thickness_dark; i++)
1641 gdk_draw_line (window, style->light_gc[state_type], x2 - i - 1, y + i, x2, y + i);
1642 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x2 - i - 1, y + i);
1645 y += thickness_dark;
1646 for (i = 0; i < thickness_light; i++)
1648 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x1 + thickness_light - i - 1, y + i);
1649 gdk_draw_line (window, style->light_gc[state_type], x1 + thickness_light - i - 1, y + i, x2, y + i);
1655 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
1656 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
1662 gtk_default_draw_vline (GtkStyle *style,
1664 GtkStateType state_type,
1667 const gchar *detail,
1672 gint thickness_light;
1673 gint thickness_dark;
1676 g_return_if_fail (GTK_IS_STYLE (style));
1677 g_return_if_fail (window != NULL);
1679 thickness_light = style->xthickness / 2;
1680 thickness_dark = style->xthickness - thickness_light;
1684 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
1685 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
1687 for (i = 0; i < thickness_dark; i++)
1689 gdk_draw_line (window, style->light_gc[state_type], x + i, y2 - i - 1, x + i, y2);
1690 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y2 - i - 1);
1693 x += thickness_dark;
1694 for (i = 0; i < thickness_light; i++)
1696 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y1 + thickness_light - i);
1697 gdk_draw_line (window, style->light_gc[state_type], x + i, y1 + thickness_light - i, x + i, y2);
1701 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
1702 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
1708 gtk_default_draw_shadow (GtkStyle *style,
1710 GtkStateType state_type,
1711 GtkShadowType shadow_type,
1714 const gchar *detail,
1722 gint thickness_light;
1723 gint thickness_dark;
1726 g_return_if_fail (GTK_IS_STYLE (style));
1727 g_return_if_fail (window != NULL);
1729 if ((width == -1) && (height == -1))
1730 gdk_window_get_size (window, &width, &height);
1731 else if (width == -1)
1732 gdk_window_get_size (window, &width, NULL);
1733 else if (height == -1)
1734 gdk_window_get_size (window, NULL, &height);
1736 switch (shadow_type)
1738 case GTK_SHADOW_NONE:
1741 case GTK_SHADOW_ETCHED_IN:
1742 gc1 = style->light_gc[state_type];
1743 gc2 = style->dark_gc[state_type];
1745 case GTK_SHADOW_OUT:
1746 case GTK_SHADOW_ETCHED_OUT:
1747 gc1 = style->dark_gc[state_type];
1748 gc2 = style->light_gc[state_type];
1754 gdk_gc_set_clip_rectangle (gc1, area);
1755 gdk_gc_set_clip_rectangle (gc2, area);
1756 if (shadow_type == GTK_SHADOW_IN ||
1757 shadow_type == GTK_SHADOW_OUT)
1759 gdk_gc_set_clip_rectangle (style->black_gc, area);
1760 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
1764 switch (shadow_type)
1766 case GTK_SHADOW_NONE:
1770 gdk_draw_line (window, gc1,
1771 x, y + height - 1, x + width - 1, y + height - 1);
1772 gdk_draw_line (window, gc1,
1773 x + width - 1, y, x + width - 1, y + height - 1);
1775 gdk_draw_line (window, style->bg_gc[state_type],
1776 x + 1, y + height - 2, x + width - 2, y + height - 2);
1777 gdk_draw_line (window, style->bg_gc[state_type],
1778 x + width - 2, y + 1, x + width - 2, y + height - 2);
1780 gdk_draw_line (window, style->black_gc,
1781 x + 1, y + 1, x + width - 2, y + 1);
1782 gdk_draw_line (window, style->black_gc,
1783 x + 1, y + 1, x + 1, y + height - 2);
1785 gdk_draw_line (window, gc2,
1786 x, y, x + width - 1, y);
1787 gdk_draw_line (window, gc2,
1788 x, y, x, y + height - 1);
1791 case GTK_SHADOW_OUT:
1792 gdk_draw_line (window, gc1,
1793 x + 1, y + height - 2, x + width - 2, y + height - 2);
1794 gdk_draw_line (window, gc1,
1795 x + width - 2, y + 1, x + width - 2, y + height - 2);
1797 gdk_draw_line (window, gc2,
1798 x, y, x + width - 1, y);
1799 gdk_draw_line (window, gc2,
1800 x, y, x, y + height - 1);
1802 gdk_draw_line (window, style->bg_gc[state_type],
1803 x + 1, y + 1, x + width - 2, y + 1);
1804 gdk_draw_line (window, style->bg_gc[state_type],
1805 x + 1, y + 1, x + 1, y + height - 2);
1807 gdk_draw_line (window, style->black_gc,
1808 x, y + height - 1, x + width - 1, y + height - 1);
1809 gdk_draw_line (window, style->black_gc,
1810 x + width - 1, y, x + width - 1, y + height - 1);
1813 case GTK_SHADOW_ETCHED_IN:
1814 case GTK_SHADOW_ETCHED_OUT:
1815 thickness_light = 1;
1818 for (i = 0; i < thickness_dark; i++)
1820 gdk_draw_line (window, gc1,
1824 y + height - i - 1);
1825 gdk_draw_line (window, gc1,
1829 y + height - i - 1);
1831 gdk_draw_line (window, gc2,
1836 gdk_draw_line (window, gc2,
1840 y + height - i - 2);
1843 for (i = 0; i < thickness_light; i++)
1845 gdk_draw_line (window, gc1,
1846 x + thickness_dark + i,
1847 y + thickness_dark + i,
1848 x + width - thickness_dark - i - 1,
1849 y + thickness_dark + i);
1850 gdk_draw_line (window, gc1,
1851 x + thickness_dark + i,
1852 y + thickness_dark + i,
1853 x + thickness_dark + i,
1854 y + height - thickness_dark - i - 1);
1856 gdk_draw_line (window, gc2,
1857 x + thickness_dark + i,
1858 y + height - thickness_light - i - 1,
1859 x + width - thickness_light - 1,
1860 y + height - thickness_light - i - 1);
1861 gdk_draw_line (window, gc2,
1862 x + width - thickness_light - i - 1,
1863 y + thickness_dark + i,
1864 x + width - thickness_light - i - 1,
1865 y + height - thickness_light - 1);
1871 gdk_gc_set_clip_rectangle (gc1, NULL);
1872 gdk_gc_set_clip_rectangle (gc2, NULL);
1873 if (shadow_type == GTK_SHADOW_IN ||
1874 shadow_type == GTK_SHADOW_OUT)
1876 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
1877 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
1883 gtk_default_draw_polygon (GtkStyle *style,
1885 GtkStateType state_type,
1886 GtkShadowType shadow_type,
1889 const gchar *detail,
1894 static const gdouble pi_over_4 = G_PI_4;
1895 static const gdouble pi_3_over_4 = G_PI_4 * 3;
1905 g_return_if_fail (GTK_IS_STYLE (style));
1906 g_return_if_fail (window != NULL);
1907 g_return_if_fail (points != NULL);
1909 switch (shadow_type)
1912 gc1 = style->bg_gc[state_type];
1913 gc2 = style->dark_gc[state_type];
1914 gc3 = style->light_gc[state_type];
1915 gc4 = style->black_gc;
1917 case GTK_SHADOW_ETCHED_IN:
1918 gc1 = style->light_gc[state_type];
1919 gc2 = style->dark_gc[state_type];
1920 gc3 = style->dark_gc[state_type];
1921 gc4 = style->light_gc[state_type];
1923 case GTK_SHADOW_OUT:
1924 gc1 = style->dark_gc[state_type];
1925 gc2 = style->light_gc[state_type];
1926 gc3 = style->black_gc;
1927 gc4 = style->bg_gc[state_type];
1929 case GTK_SHADOW_ETCHED_OUT:
1930 gc1 = style->dark_gc[state_type];
1931 gc2 = style->light_gc[state_type];
1932 gc3 = style->light_gc[state_type];
1933 gc4 = style->dark_gc[state_type];
1941 gdk_gc_set_clip_rectangle (gc1, area);
1942 gdk_gc_set_clip_rectangle (gc2, area);
1943 gdk_gc_set_clip_rectangle (gc3, area);
1944 gdk_gc_set_clip_rectangle (gc4, area);
1948 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, npoints);
1952 for (i = 0; i < npoints; i++)
1954 if ((points[i].x == points[i+1].x) &&
1955 (points[i].y == points[i+1].y))
1961 angle = atan2 (points[i+1].y - points[i].y,
1962 points[i+1].x - points[i].x);
1965 if ((angle > -pi_3_over_4) && (angle < pi_over_4))
1967 if (angle > -pi_over_4)
1978 gdk_draw_line (window, gc1,
1979 points[i].x-xadjust, points[i].y-yadjust,
1980 points[i+1].x-xadjust, points[i+1].y-yadjust);
1981 gdk_draw_line (window, gc3,
1982 points[i].x, points[i].y,
1983 points[i+1].x, points[i+1].y);
1987 if ((angle < -pi_3_over_4) || (angle > pi_3_over_4))
1998 gdk_draw_line (window, gc4,
1999 points[i].x+xadjust, points[i].y+yadjust,
2000 points[i+1].x+xadjust, points[i+1].y+yadjust);
2001 gdk_draw_line (window, gc2,
2002 points[i].x, points[i].y,
2003 points[i+1].x, points[i+1].y);
2009 gdk_gc_set_clip_rectangle (gc1, NULL);
2010 gdk_gc_set_clip_rectangle (gc2, NULL);
2011 gdk_gc_set_clip_rectangle (gc3, NULL);
2012 gdk_gc_set_clip_rectangle (gc4, NULL);
2017 gtk_default_draw_arrow (GtkStyle *style,
2019 GtkStateType state_type,
2020 GtkShadowType shadow_type,
2023 const gchar *detail,
2024 GtkArrowType arrow_type,
2039 g_return_if_fail (GTK_IS_STYLE (style));
2040 g_return_if_fail (window != NULL);
2042 switch (shadow_type)
2045 gc1 = style->bg_gc[state_type];
2046 gc2 = style->dark_gc[state_type];
2047 gc3 = style->light_gc[state_type];
2048 gc4 = style->black_gc;
2050 case GTK_SHADOW_OUT:
2051 gc1 = style->dark_gc[state_type];
2052 gc2 = style->light_gc[state_type];
2053 gc3 = style->black_gc;
2054 gc4 = style->bg_gc[state_type];
2056 case GTK_SHADOW_ETCHED_IN:
2057 gc1 = style->light_gc[state_type];
2058 gc2 = style->dark_gc[state_type];
2062 case GTK_SHADOW_ETCHED_OUT:
2063 gc1 = style->dark_gc[state_type];
2064 gc2 = style->light_gc[state_type];
2072 if ((width == -1) && (height == -1))
2073 gdk_window_get_size (window, &width, &height);
2074 else if (width == -1)
2075 gdk_window_get_size (window, &width, NULL);
2076 else if (height == -1)
2077 gdk_window_get_size (window, NULL, &height);
2079 half_width = width / 2;
2080 half_height = height / 2;
2084 gdk_gc_set_clip_rectangle (gc1, area);
2085 gdk_gc_set_clip_rectangle (gc2, area);
2088 gdk_gc_set_clip_rectangle (gc3, area);
2089 gdk_gc_set_clip_rectangle (gc4, area);
2098 points[0].x = x + half_width;
2101 points[1].y = y + height - 1;
2102 points[2].x = x + width - 1;
2103 points[2].y = y + height - 1;
2105 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
2108 switch (shadow_type)
2111 case GTK_SHADOW_OUT:
2113 gdk_draw_line (window, gc1,
2114 x + 1, y + height - 2,
2115 x + width - 2, y + height - 2);
2116 gdk_draw_line (window, gc3,
2117 x + 0, y + height - 1,
2118 x + width - 1, y + height - 1);
2120 gdk_draw_line (window, gc1,
2121 x + width - 2, y + height - 1,
2122 x + half_width, y + 1);
2123 gdk_draw_line (window, gc3,
2124 x + width - 1, y + height - 1,
2127 gdk_draw_line (window, gc4,
2128 x + half_width, y + 1,
2129 x + 1, y + height - 1);
2130 gdk_draw_line (window, gc2,
2135 case GTK_SHADOW_ETCHED_IN:
2136 case GTK_SHADOW_ETCHED_OUT:
2137 gdk_draw_line (window, gc1,
2138 x + half_width, y + 1,
2139 x + 1, y + height - 1);
2140 gdk_draw_line (window, gc1,
2141 x + 1, y + height - 1,
2142 x + width - 1, y + height - 1);
2143 gdk_draw_line (window, gc1,
2144 x + width - 1, y + height - 1,
2145 x + half_width + 1, y + 1);
2147 points[0].x = x + half_width;
2150 points[1].y = y + height - 2;
2151 points[2].x = x + width - 2;
2152 points[2].y = y + height - 2;
2154 gdk_draw_polygon (window, gc2, FALSE, points, 3);
2162 case GTK_ARROW_DOWN:
2165 points[0].x = x + width - 1;
2169 points[2].x = x + half_width;
2170 points[2].y = y + height - 1;
2172 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
2174 switch (shadow_type)
2177 case GTK_SHADOW_OUT:
2178 gdk_draw_line (window, gc4,
2180 y + 1, x + 1, y + 1);
2181 gdk_draw_line (window, gc2,
2185 gdk_draw_line (window, gc4,
2187 x + half_width, y + height - 2);
2188 gdk_draw_line (window, gc2,
2190 x + half_width, y + height - 1);
2192 gdk_draw_line (window, gc1,
2193 x + half_width, y + height - 2,
2195 gdk_draw_line (window, gc3,
2196 x + half_width, y + height - 1,
2200 case GTK_SHADOW_ETCHED_IN:
2201 case GTK_SHADOW_ETCHED_OUT:
2202 gdk_draw_line (window, gc1,
2203 x + width - 1, y + 1,
2205 gdk_draw_line (window, gc1,
2207 x + half_width + 1, y + height - 1);
2208 gdk_draw_line (window, gc1,
2209 x + half_width + 1, y + height - 2,
2212 points[0].x = x + width - 2;
2216 points[2].x = x + half_width;
2217 points[2].y = y + height - 2;
2219 gdk_draw_polygon (window, gc2, FALSE, points, 3);
2226 case GTK_ARROW_LEFT:
2230 points[0].y = y + half_height;
2231 points[1].x = x + width - 1;
2232 points[1].y = y + height - 1;
2233 points[2].x = x + width - 1;
2236 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
2239 switch (shadow_type)
2242 case GTK_SHADOW_OUT:
2243 gdk_draw_line (window, gc1,
2244 x + 1, y + half_height,
2245 x + width - 1, y + height - 1);
2246 gdk_draw_line (window, gc3,
2248 x + width - 1, y + height - 1);
2250 gdk_draw_line (window, gc1,
2251 x + width - 2, y + height - 1,
2252 x + width - 2, y + 1);
2253 gdk_draw_line (window, gc3,
2254 x + width - 1, y + height - 1,
2257 gdk_draw_line (window, gc4,
2258 x + width - 1, y + 1,
2259 x + 1, y + half_height);
2260 gdk_draw_line (window, gc2,
2262 x, y + half_height);
2265 case GTK_SHADOW_ETCHED_IN:
2266 case GTK_SHADOW_ETCHED_OUT:
2267 gdk_draw_line (window, gc1,
2268 x + width - 1, y + 1,
2269 x + 1, y + half_height);
2270 gdk_draw_line (window, gc1,
2271 x + 1, y + half_height + 1,
2272 x + width - 1, y + height - 1);
2273 gdk_draw_line (window, gc1,
2274 x + width - 1, y + height - 1,
2275 x + width - 1, y + 1);
2277 points[0].x = x + width - 2;
2280 points[1].y = y + half_height;
2281 points[2].x = x + width - 2;
2282 points[2].y = y + height - 2;
2284 gdk_draw_polygon (window, gc2, FALSE, points, 3);
2291 case GTK_ARROW_RIGHT:
2294 points[0].x = x + width - 1;
2295 points[0].y = y + half_height;
2299 points[2].y = y + height - 1;
2301 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
2304 switch (shadow_type)
2307 case GTK_SHADOW_OUT:
2308 gdk_draw_line (window, gc4,
2309 x + width - 1, y + half_height,
2311 gdk_draw_line (window, gc2,
2312 x + width - 1, y + half_height,
2314 gdk_draw_line (window, gc4,
2316 x + 1, y + height - 2);
2317 gdk_draw_line (window, gc2,
2321 gdk_draw_line (window, gc1,
2322 x + 1, y + height - 2,
2323 x + width - 1, y + half_height);
2324 gdk_draw_line (window, gc3,
2326 x + width - 1, y + half_height);
2329 case GTK_SHADOW_ETCHED_IN:
2330 case GTK_SHADOW_ETCHED_OUT:
2331 gdk_draw_line (window, gc1,
2332 x + width - 1, y + half_height + 1,
2334 gdk_draw_line (window, gc1,
2336 x + 1, y + height - 1);
2337 gdk_draw_line (window, gc1,
2338 x + 1, y + height - 1,
2339 x + width - 1, y + half_height + 1);
2341 points[0].x = x + width - 2;
2342 points[0].y = y + half_height;
2346 points[2].y = y + height - 1;
2348 gdk_draw_polygon (window, gc2, FALSE, points, 3);
2359 gdk_gc_set_clip_rectangle (gc1, NULL);
2360 gdk_gc_set_clip_rectangle (gc2, NULL);
2363 gdk_gc_set_clip_rectangle (gc3, NULL);
2364 gdk_gc_set_clip_rectangle (gc4, NULL);
2370 gtk_default_draw_diamond (GtkStyle *style,
2372 GtkStateType state_type,
2373 GtkShadowType shadow_type,
2376 const gchar *detail,
2384 GdkGC *outer_nw = NULL;
2385 GdkGC *outer_ne = NULL;
2386 GdkGC *outer_sw = NULL;
2387 GdkGC *outer_se = NULL;
2388 GdkGC *middle_nw = NULL;
2389 GdkGC *middle_ne = NULL;
2390 GdkGC *middle_sw = NULL;
2391 GdkGC *middle_se = NULL;
2392 GdkGC *inner_nw = NULL;
2393 GdkGC *inner_ne = NULL;
2394 GdkGC *inner_sw = NULL;
2395 GdkGC *inner_se = NULL;
2397 g_return_if_fail (GTK_IS_STYLE (style));
2398 g_return_if_fail (window != NULL);
2400 if ((width == -1) && (height == -1))
2401 gdk_window_get_size (window, &width, &height);
2402 else if (width == -1)
2403 gdk_window_get_size (window, &width, NULL);
2404 else if (height == -1)
2405 gdk_window_get_size (window, NULL, &height);
2407 half_width = width / 2;
2408 half_height = height / 2;
2412 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
2413 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2414 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
2415 gdk_gc_set_clip_rectangle (style->black_gc, area);
2418 switch (shadow_type)
2421 inner_sw = inner_se = style->bg_gc[state_type];
2422 middle_sw = middle_se = style->light_gc[state_type];
2423 outer_sw = outer_se = style->light_gc[state_type];
2424 inner_nw = inner_ne = style->black_gc;
2425 middle_nw = middle_ne = style->dark_gc[state_type];
2426 outer_nw = outer_ne = style->dark_gc[state_type];
2429 case GTK_SHADOW_OUT:
2430 inner_sw = inner_se = style->dark_gc[state_type];
2431 middle_sw = middle_se = style->dark_gc[state_type];
2432 outer_sw = outer_se = style->black_gc;
2433 inner_nw = inner_ne = style->bg_gc[state_type];
2434 middle_nw = middle_ne = style->light_gc[state_type];
2435 outer_nw = outer_ne = style->light_gc[state_type];
2438 case GTK_SHADOW_ETCHED_IN:
2439 inner_sw = inner_se = style->bg_gc[state_type];
2440 middle_sw = middle_se = style->dark_gc[state_type];
2441 outer_sw = outer_se = style->light_gc[state_type];
2442 inner_nw = inner_ne = style->bg_gc[state_type];
2443 middle_nw = middle_ne = style->light_gc[state_type];
2444 outer_nw = outer_ne = style->dark_gc[state_type];
2447 case GTK_SHADOW_ETCHED_OUT:
2448 inner_sw = inner_se = style->bg_gc[state_type];
2449 middle_sw = middle_se = style->light_gc[state_type];
2450 outer_sw = outer_se = style->dark_gc[state_type];
2451 inner_nw = inner_ne = style->bg_gc[state_type];
2452 middle_nw = middle_ne = style->dark_gc[state_type];
2453 outer_nw = outer_ne = style->light_gc[state_type];
2463 gdk_draw_line (window, inner_sw,
2464 x + 2, y + half_height,
2465 x + half_width, y + height - 2);
2466 gdk_draw_line (window, inner_se,
2467 x + half_width, y + height - 2,
2468 x + width - 2, y + half_height);
2469 gdk_draw_line (window, middle_sw,
2470 x + 1, y + half_height,
2471 x + half_width, y + height - 1);
2472 gdk_draw_line (window, middle_se,
2473 x + half_width, y + height - 1,
2474 x + width - 1, y + half_height);
2475 gdk_draw_line (window, outer_sw,
2477 x + half_width, y + height);
2478 gdk_draw_line (window, outer_se,
2479 x + half_width, y + height,
2480 x + width, y + half_height);
2482 gdk_draw_line (window, inner_nw,
2483 x + 2, y + half_height,
2484 x + half_width, y + 2);
2485 gdk_draw_line (window, inner_ne,
2486 x + half_width, y + 2,
2487 x + width - 2, y + half_height);
2488 gdk_draw_line (window, middle_nw,
2489 x + 1, y + half_height,
2490 x + half_width, y + 1);
2491 gdk_draw_line (window, middle_ne,
2492 x + half_width, y + 1,
2493 x + width - 1, y + half_height);
2494 gdk_draw_line (window, outer_nw,
2497 gdk_draw_line (window, outer_ne,
2499 x + width, y + half_height);
2504 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
2505 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
2506 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
2507 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2512 gtk_default_draw_string (GtkStyle *style,
2514 GtkStateType state_type,
2517 const gchar *detail,
2520 const gchar *string)
2522 g_return_if_fail (GTK_IS_STYLE (style));
2523 g_return_if_fail (window != NULL);
2527 gdk_gc_set_clip_rectangle (style->white_gc, area);
2528 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], area);
2531 if (state_type == GTK_STATE_INSENSITIVE)
2532 gdk_draw_string (window, style->font, style->white_gc, x + 1, y + 1, string);
2534 gdk_draw_string (window, style->font, style->fg_gc[state_type], x, y, string);
2538 gdk_gc_set_clip_rectangle (style->white_gc, NULL);
2539 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], NULL);
2544 gtk_default_draw_box (GtkStyle *style,
2546 GtkStateType state_type,
2547 GtkShadowType shadow_type,
2550 const gchar *detail,
2556 g_return_if_fail (GTK_IS_STYLE (style));
2557 g_return_if_fail (window != NULL);
2559 if (width == -1 && height == -1)
2560 gdk_window_get_size (window, &width, &height);
2561 else if (width == -1)
2562 gdk_window_get_size (window, &width, NULL);
2563 else if (height == -1)
2564 gdk_window_get_size (window, NULL, &height);
2566 if (!style->bg_pixmap[state_type] ||
2567 GDK_IS_PIXMAP (window))
2570 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2572 gdk_draw_rectangle (window, style->bg_gc[state_type], TRUE,
2573 x, y, width, height);
2575 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
2578 gtk_style_apply_default_background (style, window,
2579 widget && !GTK_WIDGET_NO_WINDOW (widget),
2580 state_type, area, x, y, width, height);
2582 gtk_paint_shadow (style, window, state_type, shadow_type, area, widget, detail,
2583 x, y, width, height);
2587 get_darkened_gc (GdkWindow *window,
2591 GdkColor src = *color;
2595 gc = gdk_gc_new (window);
2597 while (darken_count)
2599 gtk_style_shade (&src, &shaded, 0.93);
2604 gdk_gc_set_rgb_fg_color (gc, &shaded);
2610 gtk_default_draw_flat_box (GtkStyle *style,
2612 GtkStateType state_type,
2613 GtkShadowType shadow_type,
2616 const gchar *detail,
2623 GdkGC *freeme = NULL;
2625 g_return_if_fail (GTK_IS_STYLE (style));
2626 g_return_if_fail (window != NULL);
2628 if (width == -1 && height == -1)
2629 gdk_window_get_size (window, &width, &height);
2630 else if (width == -1)
2631 gdk_window_get_size (window, &width, NULL);
2632 else if (height == -1)
2633 gdk_window_get_size (window, NULL, &height);
2637 if (state_type == GTK_STATE_SELECTED)
2639 if (!strcmp ("text", detail))
2640 gc1 = style->bg_gc[GTK_STATE_SELECTED];
2641 else if (!strcmp ("cell_even_sorted", detail) ||
2642 !strcmp ("cell_odd_sorted", detail) ||
2643 !strcmp ("cell_even_ruled_sorted", detail) ||
2644 !strcmp ("cell_odd_ruled_sorted", detail))
2646 freeme = get_darkened_gc (window, &style->bg[state_type], 1);
2651 gc1 = style->bg_gc[state_type];
2656 if (!strcmp ("viewportbin", detail))
2657 gc1 = style->bg_gc[GTK_STATE_NORMAL];
2658 else if (!strcmp ("entry_bg", detail))
2659 gc1 = style->base_gc[state_type];
2661 /* For trees: even rows are base color, odd rows are a shade of
2662 * the base color, the sort column is a shade of the original color
2666 /* FIXME when we have style properties, clean this up.
2669 else if (!strcmp ("cell_even", detail) ||
2670 !strcmp ("cell_odd", detail) ||
2671 !strcmp ("cell_even_ruled", detail))
2673 gc1 = style->base_gc[state_type];
2675 else if (!strcmp ("cell_even_sorted", detail) ||
2676 !strcmp ("cell_odd_sorted", detail) ||
2677 !strcmp ("cell_odd_ruled", detail) ||
2678 !strcmp ("cell_even_ruled_sorted", detail))
2680 freeme = get_darkened_gc (window, &style->base[state_type], 1);
2683 else if (!strcmp ("cell_odd_ruled_sorted", detail))
2685 freeme = get_darkened_gc (window, &style->base[state_type], 2);
2689 gc1 = style->bg_gc[state_type];
2693 gc1 = style->bg_gc[state_type];
2695 if (!style->bg_pixmap[state_type] || gc1 != style->bg_gc[state_type] ||
2696 GDK_IS_PIXMAP (window))
2699 gdk_gc_set_clip_rectangle (gc1, area);
2701 gdk_draw_rectangle (window, gc1, TRUE,
2702 x, y, width, height);
2704 if (detail && !strcmp ("tooltip", detail))
2705 gdk_draw_rectangle (window, style->black_gc, FALSE,
2706 x, y, width - 1, height - 1);
2709 gdk_gc_set_clip_rectangle (gc1, NULL);
2712 gtk_style_apply_default_background (style, window,
2713 widget && !GTK_WIDGET_NO_WINDOW (widget),
2714 state_type, area, x, y, width, height);
2718 g_object_unref (G_OBJECT (freeme));
2722 gtk_default_draw_check (GtkStyle *style,
2724 GtkStateType state_type,
2725 GtkShadowType shadow_type,
2728 const gchar *detail,
2734 if (detail && strcmp (detail, "cellcheck") == 0)
2736 gdk_draw_rectangle (window,
2737 widget->style->fg_gc[state_type],
2742 if (shadow_type == GTK_SHADOW_IN)
2744 gdk_draw_line (window,
2745 widget->style->fg_gc[state_type],
2749 gdk_draw_line (window,
2750 widget->style->fg_gc[state_type],
2759 gtk_paint_box (style, window, state_type, shadow_type, area, widget, detail,
2760 x, y, width, height);
2765 gtk_default_draw_option (GtkStyle *style,
2767 GtkStateType state_type,
2768 GtkShadowType shadow_type,
2771 const gchar *detail,
2777 if (detail && strcmp (detail, "cellradio") == 0)
2779 gdk_draw_arc (window,
2780 widget->style->fg_gc[state_type],
2787 if (shadow_type == GTK_SHADOW_IN)
2789 gdk_draw_arc (window,
2790 widget->style->fg_gc[state_type],
2801 gtk_paint_diamond (style, window, state_type, shadow_type, area, widget,
2802 detail, x, y, width, height);
2807 gtk_default_draw_tab (GtkStyle *style,
2809 GtkStateType state_type,
2810 GtkShadowType shadow_type,
2813 const gchar *detail,
2819 g_return_if_fail (GTK_IS_STYLE (style));
2820 g_return_if_fail (window != NULL);
2822 gtk_paint_box (style, window, state_type, shadow_type, area, widget, detail,
2823 x, y, width, height);
2827 gtk_default_draw_shadow_gap (GtkStyle *style,
2829 GtkStateType state_type,
2830 GtkShadowType shadow_type,
2833 const gchar *detail,
2838 GtkPositionType gap_side,
2847 g_return_if_fail (GTK_IS_STYLE (style));
2848 g_return_if_fail (window != NULL);
2850 if (width == -1 && height == -1)
2851 gdk_window_get_size (window, &width, &height);
2852 else if (width == -1)
2853 gdk_window_get_size (window, &width, NULL);
2854 else if (height == -1)
2855 gdk_window_get_size (window, NULL, &height);
2857 switch (shadow_type)
2859 case GTK_SHADOW_NONE:
2862 gc1 = style->dark_gc[state_type];
2863 gc2 = style->black_gc;
2864 gc3 = style->bg_gc[state_type];
2865 gc4 = style->light_gc[state_type];
2867 case GTK_SHADOW_ETCHED_IN:
2868 gc1 = style->dark_gc[state_type];
2869 gc2 = style->light_gc[state_type];
2870 gc3 = style->dark_gc[state_type];
2871 gc4 = style->light_gc[state_type];
2873 case GTK_SHADOW_OUT:
2874 gc1 = style->light_gc[state_type];
2875 gc2 = style->bg_gc[state_type];
2876 gc3 = style->dark_gc[state_type];
2877 gc4 = style->black_gc;
2879 case GTK_SHADOW_ETCHED_OUT:
2880 gc1 = style->light_gc[state_type];
2881 gc2 = style->dark_gc[state_type];
2882 gc3 = style->light_gc[state_type];
2883 gc4 = style->dark_gc[state_type];
2888 gdk_gc_set_clip_rectangle (gc1, area);
2889 gdk_gc_set_clip_rectangle (gc2, area);
2890 gdk_gc_set_clip_rectangle (gc3, area);
2891 gdk_gc_set_clip_rectangle (gc4, area);
2894 switch (shadow_type)
2896 case GTK_SHADOW_NONE:
2898 case GTK_SHADOW_OUT:
2899 case GTK_SHADOW_ETCHED_IN:
2900 case GTK_SHADOW_ETCHED_OUT:
2904 gdk_draw_line (window, gc1,
2905 x, y, x, y + height - 1);
2906 gdk_draw_line (window, gc2,
2907 x + 1, y, x + 1, y + height - 2);
2909 gdk_draw_line (window, gc3,
2910 x + 1, y + height - 2, x + width - 2, y + height - 2);
2911 gdk_draw_line (window, gc3,
2912 x + width - 2, y, x + width - 2, y + height - 2);
2913 gdk_draw_line (window, gc4,
2914 x, y + height - 1, x + width - 1, y + height - 1);
2915 gdk_draw_line (window, gc4,
2916 x + width - 1, y, x + width - 1, y + height - 1);
2919 gdk_draw_line (window, gc1,
2920 x, y, x + gap_x - 1, y);
2921 gdk_draw_line (window, gc2,
2922 x + 1, y + 1, x + gap_x - 1, y + 1);
2923 gdk_draw_line (window, gc2,
2924 x + gap_x, y, x + gap_x, y);
2926 if ((width - (gap_x + gap_width)) > 0)
2928 gdk_draw_line (window, gc1,
2929 x + gap_x + gap_width, y, x + width - 2, y);
2930 gdk_draw_line (window, gc2,
2931 x + gap_x + gap_width, y + 1, x + width - 2, y + 1);
2932 gdk_draw_line (window, gc2,
2933 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
2936 case GTK_POS_BOTTOM:
2937 gdk_draw_line (window, gc1,
2938 x, y, x + width - 1, y);
2939 gdk_draw_line (window, gc1,
2940 x, y, x, y + height - 1);
2941 gdk_draw_line (window, gc2,
2942 x + 1, y + 1, x + width - 2, y + 1);
2943 gdk_draw_line (window, gc2,
2944 x + 1, y + 1, x + 1, y + height - 1);
2946 gdk_draw_line (window, gc3,
2947 x + width - 2, y + 1, x + width - 2, y + height - 1);
2948 gdk_draw_line (window, gc4,
2949 x + width - 1, y, x + width - 1, y + height - 1);
2952 gdk_draw_line (window, gc4,
2953 x, y + height - 1, x + gap_x - 1, y + height - 1);
2954 gdk_draw_line (window, gc3,
2955 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
2956 gdk_draw_line (window, gc3,
2957 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
2959 if ((width - (gap_x + gap_width)) > 0)
2961 gdk_draw_line (window, gc4,
2962 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
2963 gdk_draw_line (window, gc3,
2964 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
2965 gdk_draw_line (window, gc3,
2966 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
2970 gdk_draw_line (window, gc1,
2971 x, y, x + width - 1, y);
2972 gdk_draw_line (window, gc2,
2973 x, y + 1, x + width - 2, y + 1);
2975 gdk_draw_line (window, gc3,
2976 x, y + height - 2, x + width - 2, y + height - 2);
2977 gdk_draw_line (window, gc3,
2978 x + width - 2, y + 1, x + width - 2, y + height - 2);
2979 gdk_draw_line (window, gc4,
2980 x, y + height - 1, x + width - 1, y + height - 1);
2981 gdk_draw_line (window, gc4,
2982 x + width - 1, y, x + width - 1, y + height - 1);
2985 gdk_draw_line (window, gc1,
2986 x, y, x, y + gap_x - 1);
2987 gdk_draw_line (window, gc2,
2988 x + 1, y + 1, x + 1, y + gap_x - 1);
2989 gdk_draw_line (window, gc2,
2990 x, y + gap_x, x, y + gap_x);
2992 if ((width - (gap_x + gap_width)) > 0)
2994 gdk_draw_line (window, gc1,
2995 x, y + gap_x + gap_width, x, y + height - 2);
2996 gdk_draw_line (window, gc2,
2997 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
2998 gdk_draw_line (window, gc2,
2999 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
3003 gdk_draw_line (window, gc1,
3004 x, y, x + width - 1, y);
3005 gdk_draw_line (window, gc1,
3006 x, y, x, y + height - 1);
3007 gdk_draw_line (window, gc2,
3008 x + 1, y + 1, x + width - 1, y + 1);
3009 gdk_draw_line (window, gc2,
3010 x + 1, y + 1, x + 1, y + height - 2);
3012 gdk_draw_line (window, gc3,
3013 x + 1, y + height - 2, x + width - 1, y + height - 2);
3014 gdk_draw_line (window, gc4,
3015 x, y + height - 1, x + width - 1, y + height - 1);
3018 gdk_draw_line (window, gc4,
3019 x + width - 1, y, x + width - 1, y + gap_x - 1);
3020 gdk_draw_line (window, gc3,
3021 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
3022 gdk_draw_line (window, gc3,
3023 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
3025 if ((width - (gap_x + gap_width)) > 0)
3027 gdk_draw_line (window, gc4,
3028 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
3029 gdk_draw_line (window, gc3,
3030 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
3031 gdk_draw_line (window, gc3,
3032 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
3040 gdk_gc_set_clip_rectangle (gc1, NULL);
3041 gdk_gc_set_clip_rectangle (gc2, NULL);
3042 gdk_gc_set_clip_rectangle (gc3, NULL);
3043 gdk_gc_set_clip_rectangle (gc4, NULL);
3048 gtk_default_draw_box_gap (GtkStyle *style,
3050 GtkStateType state_type,
3051 GtkShadowType shadow_type,
3054 const gchar *detail,
3059 GtkPositionType gap_side,
3068 g_return_if_fail (GTK_IS_STYLE (style));
3069 g_return_if_fail (window != NULL);
3071 gtk_style_apply_default_background (style, window,
3072 widget && !GTK_WIDGET_NO_WINDOW (widget),
3073 state_type, area, x, y, width, height);
3075 if (width == -1 && height == -1)
3076 gdk_window_get_size (window, &width, &height);
3077 else if (width == -1)
3078 gdk_window_get_size (window, &width, NULL);
3079 else if (height == -1)
3080 gdk_window_get_size (window, NULL, &height);
3082 switch (shadow_type)
3084 case GTK_SHADOW_NONE:
3087 gc1 = style->dark_gc[state_type];
3088 gc2 = style->black_gc;
3089 gc3 = style->bg_gc[state_type];
3090 gc4 = style->light_gc[state_type];
3092 case GTK_SHADOW_ETCHED_IN:
3093 gc1 = style->dark_gc[state_type];
3094 gc2 = style->light_gc[state_type];
3095 gc3 = style->dark_gc[state_type];
3096 gc4 = style->light_gc[state_type];
3098 case GTK_SHADOW_OUT:
3099 gc1 = style->light_gc[state_type];
3100 gc2 = style->bg_gc[state_type];
3101 gc3 = style->dark_gc[state_type];
3102 gc4 = style->black_gc;
3104 case GTK_SHADOW_ETCHED_OUT:
3105 gc1 = style->light_gc[state_type];
3106 gc2 = style->dark_gc[state_type];
3107 gc3 = style->light_gc[state_type];
3108 gc4 = style->dark_gc[state_type];
3114 gdk_gc_set_clip_rectangle (gc1, area);
3115 gdk_gc_set_clip_rectangle (gc2, area);
3116 gdk_gc_set_clip_rectangle (gc3, area);
3117 gdk_gc_set_clip_rectangle (gc4, area);
3120 switch (shadow_type)
3122 case GTK_SHADOW_NONE:
3124 case GTK_SHADOW_OUT:
3125 case GTK_SHADOW_ETCHED_IN:
3126 case GTK_SHADOW_ETCHED_OUT:
3130 gdk_draw_line (window, gc1,
3131 x, y, x, y + height - 1);
3132 gdk_draw_line (window, gc2,
3133 x + 1, y, x + 1, y + height - 2);
3135 gdk_draw_line (window, gc3,
3136 x + 1, y + height - 2, x + width - 2, y + height - 2);
3137 gdk_draw_line (window, gc3,
3138 x + width - 2, y, x + width - 2, y + height - 2);
3139 gdk_draw_line (window, gc4,
3140 x, y + height - 1, x + width - 1, y + height - 1);
3141 gdk_draw_line (window, gc4,
3142 x + width - 1, y, x + width - 1, y + height - 1);
3145 gdk_draw_line (window, gc1,
3146 x, y, x + gap_x - 1, y);
3147 gdk_draw_line (window, gc2,
3148 x + 1, y + 1, x + gap_x - 1, y + 1);
3149 gdk_draw_line (window, gc2,
3150 x + gap_x, y, x + gap_x, y);
3152 if ((width - (gap_x + gap_width)) > 0)
3154 gdk_draw_line (window, gc1,
3155 x + gap_x + gap_width, y, x + width - 2, y);
3156 gdk_draw_line (window, gc2,
3157 x + gap_x + gap_width, y + 1, x + width - 2, y + 1);
3158 gdk_draw_line (window, gc2,
3159 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
3162 case GTK_POS_BOTTOM:
3163 gdk_draw_line (window, gc1,
3164 x, y, x + width - 1, y);
3165 gdk_draw_line (window, gc1,
3166 x, y, x, y + height - 1);
3167 gdk_draw_line (window, gc2,
3168 x + 1, y + 1, x + width - 2, y + 1);
3169 gdk_draw_line (window, gc2,
3170 x + 1, y + 1, x + 1, y + height - 1);
3172 gdk_draw_line (window, gc3,
3173 x + width - 2, y + 1, x + width - 2, y + height - 1);
3174 gdk_draw_line (window, gc4,
3175 x + width - 1, y, x + width - 1, y + height - 1);
3178 gdk_draw_line (window, gc4,
3179 x, y + height - 1, x + gap_x - 1, y + height - 1);
3180 gdk_draw_line (window, gc3,
3181 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
3182 gdk_draw_line (window, gc3,
3183 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
3185 if ((width - (gap_x + gap_width)) > 0)
3187 gdk_draw_line (window, gc4,
3188 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
3189 gdk_draw_line (window, gc3,
3190 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
3191 gdk_draw_line (window, gc3,
3192 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
3196 gdk_draw_line (window, gc1,
3197 x, y, x + width - 1, y);
3198 gdk_draw_line (window, gc2,
3199 x, y + 1, x + width - 2, y + 1);
3201 gdk_draw_line (window, gc3,
3202 x, y + height - 2, x + width - 2, y + height - 2);
3203 gdk_draw_line (window, gc3,
3204 x + width - 2, y + 1, x + width - 2, y + height - 2);
3205 gdk_draw_line (window, gc4,
3206 x, y + height - 1, x + width - 1, y + height - 1);
3207 gdk_draw_line (window, gc4,
3208 x + width - 1, y, x + width - 1, y + height - 1);
3211 gdk_draw_line (window, gc1,
3212 x, y, x, y + gap_x - 1);
3213 gdk_draw_line (window, gc2,
3214 x + 1, y + 1, x + 1, y + gap_x - 1);
3215 gdk_draw_line (window, gc2,
3216 x, y + gap_x, x, y + gap_x);
3218 if ((width - (gap_x + gap_width)) > 0)
3220 gdk_draw_line (window, gc1,
3221 x, y + gap_x + gap_width, x, y + height - 2);
3222 gdk_draw_line (window, gc2,
3223 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
3224 gdk_draw_line (window, gc2,
3225 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
3229 gdk_draw_line (window, gc1,
3230 x, y, x + width - 1, y);
3231 gdk_draw_line (window, gc1,
3232 x, y, x, y + height - 1);
3233 gdk_draw_line (window, gc2,
3234 x + 1, y + 1, x + width - 1, y + 1);
3235 gdk_draw_line (window, gc2,
3236 x + 1, y + 1, x + 1, y + height - 2);
3238 gdk_draw_line (window, gc3,
3239 x + 1, y + height - 2, x + width - 1, y + height - 2);
3240 gdk_draw_line (window, gc4,
3241 x, y + height - 1, x + width - 1, y + height - 1);
3244 gdk_draw_line (window, gc4,
3245 x + width - 1, y, x + width - 1, y + gap_x - 1);
3246 gdk_draw_line (window, gc3,
3247 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
3248 gdk_draw_line (window, gc3,
3249 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
3251 if ((width - (gap_x + gap_width)) > 0)
3253 gdk_draw_line (window, gc4,
3254 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
3255 gdk_draw_line (window, gc3,
3256 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
3257 gdk_draw_line (window, gc3,
3258 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
3266 gdk_gc_set_clip_rectangle (gc1, NULL);
3267 gdk_gc_set_clip_rectangle (gc2, NULL);
3268 gdk_gc_set_clip_rectangle (gc3, NULL);
3269 gdk_gc_set_clip_rectangle (gc4, NULL);
3274 gtk_default_draw_extension (GtkStyle *style,
3276 GtkStateType state_type,
3277 GtkShadowType shadow_type,
3280 const gchar *detail,
3285 GtkPositionType gap_side)
3292 g_return_if_fail (GTK_IS_STYLE (style));
3293 g_return_if_fail (window != NULL);
3295 gtk_style_apply_default_background (style, window,
3296 widget && !GTK_WIDGET_NO_WINDOW (widget),
3297 GTK_STATE_NORMAL, area, x, y, width, height);
3299 if (width == -1 && height == -1)
3300 gdk_window_get_size (window, &width, &height);
3301 else if (width == -1)
3302 gdk_window_get_size (window, &width, NULL);
3303 else if (height == -1)
3304 gdk_window_get_size (window, NULL, &height);
3306 switch (shadow_type)
3308 case GTK_SHADOW_NONE:
3311 gc1 = style->dark_gc[state_type];
3312 gc2 = style->black_gc;
3313 gc3 = style->bg_gc[state_type];
3314 gc4 = style->light_gc[state_type];
3316 case GTK_SHADOW_ETCHED_IN:
3317 gc1 = style->dark_gc[state_type];
3318 gc2 = style->light_gc[state_type];
3319 gc3 = style->dark_gc[state_type];
3320 gc4 = style->light_gc[state_type];
3322 case GTK_SHADOW_OUT:
3323 gc1 = style->light_gc[state_type];
3324 gc2 = style->bg_gc[state_type];
3325 gc3 = style->dark_gc[state_type];
3326 gc4 = style->black_gc;
3328 case GTK_SHADOW_ETCHED_OUT:
3329 gc1 = style->light_gc[state_type];
3330 gc2 = style->dark_gc[state_type];
3331 gc3 = style->light_gc[state_type];
3332 gc4 = style->dark_gc[state_type];
3338 gdk_gc_set_clip_rectangle (gc1, area);
3339 gdk_gc_set_clip_rectangle (gc2, area);
3340 gdk_gc_set_clip_rectangle (gc3, area);
3341 gdk_gc_set_clip_rectangle (gc4, area);
3344 switch (shadow_type)
3346 case GTK_SHADOW_NONE:
3348 case GTK_SHADOW_OUT:
3349 case GTK_SHADOW_ETCHED_IN:
3350 case GTK_SHADOW_ETCHED_OUT:
3354 gtk_style_apply_default_background (style, window,
3355 widget && !GTK_WIDGET_NO_WINDOW (widget),
3357 x + style->xthickness,
3359 width - (2 * style->xthickness),
3360 height - (style->ythickness));
3361 gdk_draw_line (window, gc1,
3362 x, y, x, y + height - 2);
3363 gdk_draw_line (window, gc2,
3364 x + 1, y, x + 1, y + height - 2);
3366 gdk_draw_line (window, gc3,
3367 x + 2, y + height - 2, x + width - 2, y + height - 2);
3368 gdk_draw_line (window, gc3,
3369 x + width - 2, y, x + width - 2, y + height - 2);
3370 gdk_draw_line (window, gc4,
3371 x + 1, y + height - 1, x + width - 2, y + height - 1);
3372 gdk_draw_line (window, gc4,
3373 x + width - 1, y, x + width - 1, y + height - 2);
3375 case GTK_POS_BOTTOM:
3376 gtk_style_apply_default_background (style, window,
3377 widget && !GTK_WIDGET_NO_WINDOW (widget),
3379 x + style->xthickness,
3380 y + style->ythickness,
3381 width - (2 * style->xthickness),
3382 height - (style->ythickness));
3383 gdk_draw_line (window, gc1,
3384 x + 1, y, x + width - 2, y);
3385 gdk_draw_line (window, gc1,
3386 x, y + 1, x, y + height - 1);
3387 gdk_draw_line (window, gc2,
3388 x + 1, y + 1, x + width - 2, y + 1);
3389 gdk_draw_line (window, gc2,
3390 x + 1, y + 1, x + 1, y + height - 1);
3392 gdk_draw_line (window, gc3,
3393 x + width - 2, y + 2, x + width - 2, y + height - 1);
3394 gdk_draw_line (window, gc4,
3395 x + width - 1, y + 1, x + width - 1, y + height - 1);
3398 gtk_style_apply_default_background (style, window,
3399 widget && !GTK_WIDGET_NO_WINDOW (widget),
3402 y + style->ythickness,
3403 width - (style->xthickness),
3404 height - (2 * style->ythickness));
3405 gdk_draw_line (window, gc1,
3406 x, y, x + width - 2, y);
3407 gdk_draw_line (window, gc2,
3408 x + 1, y + 1, x + width - 2, y + 1);
3410 gdk_draw_line (window, gc3,
3411 x, y + height - 2, x + width - 2, y + height - 2);
3412 gdk_draw_line (window, gc3,
3413 x + width - 2, y + 2, x + width - 2, y + height - 2);
3414 gdk_draw_line (window, gc4,
3415 x, y + height - 1, x + width - 2, y + height - 1);
3416 gdk_draw_line (window, gc4,
3417 x + width - 1, y + 1, x + width - 1, y + height - 2);
3420 gtk_style_apply_default_background (style, window,
3421 widget && !GTK_WIDGET_NO_WINDOW (widget),
3423 x + style->xthickness,
3424 y + style->ythickness,
3425 width - (style->xthickness),
3426 height - (2 * style->ythickness));
3427 gdk_draw_line (window, gc1,
3428 x + 1, y, x + width - 1, y);
3429 gdk_draw_line (window, gc1,
3430 x, y + 1, x, y + height - 2);
3431 gdk_draw_line (window, gc2,
3432 x + 1, y + 1, x + width - 1, y + 1);
3433 gdk_draw_line (window, gc2,
3434 x + 1, y + 1, x + 1, y + height - 2);
3436 gdk_draw_line (window, gc3,
3437 x + 2, y + height - 2, x + width - 1, y + height - 2);
3438 gdk_draw_line (window, gc4,
3439 x + 1, y + height - 1, x + width - 1, y + height - 1);
3446 gdk_gc_set_clip_rectangle (gc1, NULL);
3447 gdk_gc_set_clip_rectangle (gc2, NULL);
3448 gdk_gc_set_clip_rectangle (gc3, NULL);
3449 gdk_gc_set_clip_rectangle (gc4, NULL);
3454 gtk_default_draw_focus (GtkStyle *style,
3458 const gchar *detail,
3464 g_return_if_fail (GTK_IS_STYLE (style));
3465 g_return_if_fail (window != NULL);
3467 if (width == -1 && height == -1)
3469 gdk_window_get_size (window, &width, &height);
3473 else if (width == -1)
3475 gdk_window_get_size (window, &width, NULL);
3478 else if (height == -1)
3480 gdk_window_get_size (window, NULL, &height);
3485 gdk_gc_set_clip_rectangle (style->black_gc, area);
3487 if (detail && !strcmp (detail, "add-mode"))
3489 gdk_gc_set_line_attributes (style->black_gc, 1, GDK_LINE_ON_OFF_DASH, 0, 0);
3490 gdk_gc_set_dashes (style->black_gc, 0, "\4\4", 2);
3492 gdk_draw_rectangle (window,
3493 style->black_gc, FALSE,
3494 x, y, width, height);
3496 gdk_gc_set_line_attributes (style->black_gc, 1, GDK_LINE_SOLID, 0, 0);
3498 else if (detail && strcmp (detail, "treeview") == 0)
3501 gdk_gc_set_background (style->black_gc, &style->white);
3502 gdk_gc_set_line_attributes (style->black_gc, 1, GDK_LINE_DOUBLE_DASH, 0, 0);
3503 gdk_gc_set_dashes (style->black_gc, 0, "\4\4", 2);
3505 gdk_draw_rectangle (window,
3506 style->black_gc, FALSE,
3507 x, y, width, height);
3509 gdk_gc_set_line_attributes (style->black_gc, 1, GDK_LINE_SOLID, 0, 0);
3513 gdk_draw_rectangle (window,
3514 style->black_gc, FALSE,
3515 x, y, width, height);
3519 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
3523 gtk_default_draw_slider (GtkStyle *style,
3525 GtkStateType state_type,
3526 GtkShadowType shadow_type,
3529 const gchar *detail,
3534 GtkOrientation orientation)
3536 g_return_if_fail (GTK_IS_STYLE (style));
3537 g_return_if_fail (window != NULL);
3539 if (width == -1 && height == -1)
3540 gdk_window_get_size (window, &width, &height);
3541 else if (width == -1)
3542 gdk_window_get_size (window, &width, NULL);
3543 else if (height == -1)
3544 gdk_window_get_size (window, NULL, &height);
3546 gtk_paint_box (style, window, state_type, shadow_type,
3547 area, widget, detail, x, y, width, height);
3549 if (orientation == GTK_ORIENTATION_HORIZONTAL)
3550 gtk_paint_vline (style, window, state_type, area, widget, detail,
3552 height - style->ythickness - 1, width / 2);
3554 gtk_paint_hline (style, window, state_type, area, widget, detail,
3556 width - style->xthickness - 1, height / 2);
3560 draw_dot (GdkWindow *window,
3568 size = CLAMP (size, 2, 3);
3572 gdk_draw_point (window, light_gc, x, y);
3573 gdk_draw_point (window, light_gc, x+1, y+1);
3575 else if (size == 3);
3577 gdk_draw_point (window, light_gc, x, y);
3578 gdk_draw_point (window, light_gc, x+1, y);
3579 gdk_draw_point (window, light_gc, x, y+1);
3580 gdk_draw_point (window, dark_gc, x+1, y+2);
3581 gdk_draw_point (window, dark_gc, x+2, y+1);
3582 gdk_draw_point (window, dark_gc, x+2, y+2);
3587 gtk_default_draw_handle (GtkStyle *style,
3589 GtkStateType state_type,
3590 GtkShadowType shadow_type,
3593 const gchar *detail,
3598 GtkOrientation orientation)
3601 gint xthick, ythick;
3602 GdkGC *light_gc, *dark_gc;
3607 g_return_if_fail (GTK_IS_STYLE (style));
3608 g_return_if_fail (window != NULL);
3610 if (width == -1 && height == -1)
3611 gdk_window_get_size (window, &width, &height);
3612 else if (width == -1)
3613 gdk_window_get_size (window, &width, NULL);
3614 else if (height == -1)
3615 gdk_window_get_size (window, NULL, &height);
3617 gtk_paint_box (style, window, state_type, shadow_type, area, widget,
3618 detail, x, y, width, height);
3621 if (!strcmp (detail, "paned"))
3623 /* we want to ignore the shadow border in paned widgets */
3627 light_gc = style->light_gc[state_type];
3628 dark_gc = style->black_gc;
3632 xthick = style->xthickness;
3633 ythick = style->ythickness;
3635 light_gc = style->light_gc[state_type];
3636 dark_gc = style->dark_gc[state_type];
3639 rect.x = x + xthick;
3640 rect.y = y + ythick;
3641 rect.width = width - (xthick * 2);
3642 rect.height = height - (ythick * 2);
3645 intersect = gdk_rectangle_intersect (area, &rect, &dest);
3655 gdk_gc_set_clip_rectangle (light_gc, &dest);
3656 gdk_gc_set_clip_rectangle (dark_gc, &dest);
3658 if (!strcmp (detail, "paned"))
3663 gdk_window_get_size (window, &window_width, &window_height);
3665 if (orientation == GTK_ORIENTATION_HORIZONTAL)
3666 for (xx = window_width/2 - 15; xx <= window_width/2 + 15; xx += 5)
3667 draw_dot (window, light_gc, dark_gc, xx, window_height/2 - 1, 3);
3669 for (yy = window_height/2 - 15; yy <= window_height/2 + 15; yy += 5)
3670 draw_dot (window, light_gc, dark_gc, window_width/2 - 1, yy, 3);
3674 for (yy = y + ythick; yy < (y + height - ythick); yy += 3)
3675 for (xx = x + xthick; xx < (x + width - xthick); xx += 6)
3677 draw_dot (window, light_gc, dark_gc, xx, yy, 2);
3678 draw_dot (window, light_gc, dark_gc, xx + 3, yy + 1, 2);
3682 gdk_gc_set_clip_rectangle (light_gc, NULL);
3683 gdk_gc_set_clip_rectangle (dark_gc, NULL);
3687 gtk_default_draw_expander (GtkStyle *style,
3689 GtkStateType state_type,
3692 const gchar *detail,
3697 /* FIXME replace macro with a style property */
3704 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], area);
3705 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], area);
3711 points[0].y = y + (PM_SIZE + 2) / 6;
3712 points[1].x = points[0].x + 1 * (PM_SIZE + 2);
3713 points[1].y = points[0].y;
3714 points[2].x = (points[0].x + 1 * (PM_SIZE + 2) / 2);
3715 points[2].y = y + 2 * (PM_SIZE + 2) / 3;
3719 points[0].x = x + 1 * ((PM_SIZE + 2) / 6 + 2);
3720 points[0].y = y - 1;
3721 points[1].x = points[0].x;
3722 points[1].y = points[0].y + (PM_SIZE + 2);
3723 points[2].x = (points[0].x + 1 * (2 * (PM_SIZE + 2) / 3 - 1));
3724 points[2].y = points[0].y + (PM_SIZE + 2) / 2;
3727 gdk_draw_polygon (window, style->base_gc[GTK_STATE_NORMAL],
3729 gdk_draw_polygon (window, style->fg_gc[GTK_STATE_NORMAL],
3735 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], NULL);
3736 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], NULL);
3742 typedef struct _ByteRange ByteRange;
3751 range_new (guint start,
3754 ByteRange *br = g_new (ByteRange, 1);
3763 get_insensitive_layout (PangoLayout *layout)
3765 GSList *embossed_ranges = NULL;
3766 GSList *stippled_ranges = NULL;
3767 PangoLayoutIter *iter;
3768 GSList *tmp_list = NULL;
3769 PangoLayout *new_layout;
3770 PangoAttrList *attrs;
3771 GdkBitmap *stipple = NULL;
3773 iter = pango_layout_get_iter (layout);
3777 PangoLayoutRun *run;
3778 PangoAttribute *attr;
3779 gboolean need_stipple = FALSE;
3782 run = pango_layout_iter_get_run (iter);
3786 tmp_list = run->item->extra_attrs;
3788 while (tmp_list != NULL)
3790 attr = tmp_list->data;
3791 switch (attr->klass->type)
3793 case PANGO_ATTR_FOREGROUND:
3794 case PANGO_ATTR_BACKGROUND:
3795 need_stipple = TRUE;
3805 tmp_list = g_slist_next (tmp_list);
3808 br = range_new (run->item->offset, run->item->offset + run->item->length);
3811 stippled_ranges = g_slist_prepend (stippled_ranges, br);
3813 embossed_ranges = g_slist_prepend (embossed_ranges, br);
3816 while (pango_layout_iter_next_run (iter));
3818 pango_layout_iter_free (iter);
3820 new_layout = pango_layout_copy (layout);
3822 attrs = pango_layout_get_attributes (new_layout);
3826 /* Create attr list if there wasn't one */
3827 attrs = pango_attr_list_new ();
3828 pango_layout_set_attributes (new_layout, attrs);
3829 pango_attr_list_unref (attrs);
3832 tmp_list = embossed_ranges;
3833 while (tmp_list != NULL)
3835 PangoAttribute *attr;
3836 ByteRange *br = tmp_list->data;
3838 attr = gdk_pango_attr_embossed_new (TRUE);
3840 attr->start_index = br->start;
3841 attr->end_index = br->end;
3843 pango_attr_list_change (attrs, attr);
3847 tmp_list = g_slist_next (tmp_list);
3850 g_slist_free (embossed_ranges);
3852 tmp_list = stippled_ranges;
3853 while (tmp_list != NULL)
3855 PangoAttribute *attr;
3856 ByteRange *br = tmp_list->data;
3858 if (stipple == NULL)
3860 #define gray50_width 2
3861 #define gray50_height 2
3862 static char gray50_bits[] = {
3866 stipple = gdk_bitmap_create_from_data (NULL,
3867 gray50_bits, gray50_width,
3871 attr = gdk_pango_attr_stipple_new (stipple);
3873 attr->start_index = br->start;
3874 attr->end_index = br->end;
3876 pango_attr_list_change (attrs, attr);
3880 tmp_list = g_slist_next (tmp_list);
3883 g_slist_free (stippled_ranges);
3886 g_object_unref (G_OBJECT (stipple));
3892 gtk_default_draw_layout (GtkStyle *style,
3894 GtkStateType state_type,
3897 const gchar *detail,
3900 PangoLayout *layout)
3902 g_return_if_fail (GTK_IS_STYLE (style));
3903 g_return_if_fail (window != NULL);
3906 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], area);
3908 if (state_type == GTK_STATE_INSENSITIVE)
3912 ins = get_insensitive_layout (layout);
3914 gdk_draw_layout (window, style->fg_gc[state_type], x, y, ins);
3916 g_object_unref (G_OBJECT (ins));
3920 gdk_draw_layout (window, style->fg_gc[state_type], x, y, layout);
3924 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], NULL);
3928 gtk_style_shade (GdkColor *a,
3936 red = (gdouble) a->red / 65535.0;
3937 green = (gdouble) a->green / 65535.0;
3938 blue = (gdouble) a->blue / 65535.0;
3940 rgb_to_hls (&red, &green, &blue);
3945 else if (green < 0.0)
3951 else if (blue < 0.0)
3954 hls_to_rgb (&red, &green, &blue);
3956 b->red = red * 65535.0;
3957 b->green = green * 65535.0;
3958 b->blue = blue * 65535.0;
3962 rgb_to_hls (gdouble *r,
4003 l = (max + min) / 2;
4010 s = (max - min) / (max + min);
4012 s = (max - min) / (2 - max - min);
4016 h = (green - blue) / delta;
4017 else if (green == max)
4018 h = 2 + (blue - red) / delta;
4019 else if (blue == max)
4020 h = 4 + (red - green) / delta;
4033 hls_to_rgb (gdouble *h,
4046 if (lightness <= 0.5)
4047 m2 = lightness * (1 + saturation);
4049 m2 = lightness + saturation - lightness * saturation;
4050 m1 = 2 * lightness - m2;
4052 if (saturation == 0)
4067 r = m1 + (m2 - m1) * hue / 60;
4071 r = m1 + (m2 - m1) * (240 - hue) / 60;
4082 g = m1 + (m2 - m1) * hue / 60;
4086 g = m1 + (m2 - m1) * (240 - hue) / 60;
4097 b = m1 + (m2 - m1) * hue / 60;
4101 b = m1 + (m2 - m1) * (240 - hue) / 60;
4112 gtk_paint_hline (GtkStyle *style,
4114 GtkStateType state_type,
4117 const gchar *detail,
4122 g_return_if_fail (GTK_IS_STYLE (style));
4123 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
4125 GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, area, widget, detail, x1, x2, y);
4129 gtk_paint_vline (GtkStyle *style,
4131 GtkStateType state_type,
4134 const gchar *detail,
4139 g_return_if_fail (GTK_IS_STYLE (style));
4140 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
4142 GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, area, widget, detail, y1, y2, x);
4146 gtk_paint_shadow (GtkStyle *style,
4148 GtkStateType state_type,
4149 GtkShadowType shadow_type,
4152 const gchar *detail,
4158 g_return_if_fail (GTK_IS_STYLE (style));
4159 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
4161 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4165 gtk_paint_polygon (GtkStyle *style,
4167 GtkStateType state_type,
4168 GtkShadowType shadow_type,
4171 const gchar *detail,
4176 g_return_if_fail (GTK_IS_STYLE (style));
4177 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
4179 GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, area, widget, detail, points, npoints, fill);
4183 gtk_paint_arrow (GtkStyle *style,
4185 GtkStateType state_type,
4186 GtkShadowType shadow_type,
4189 const gchar *detail,
4190 GtkArrowType arrow_type,
4197 g_return_if_fail (GTK_IS_STYLE (style));
4198 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
4200 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, area, widget, detail, arrow_type, fill, x, y, width, height);
4204 gtk_paint_diamond (GtkStyle *style,
4206 GtkStateType state_type,
4207 GtkShadowType shadow_type,
4210 const gchar *detail,
4216 g_return_if_fail (GTK_IS_STYLE (style));
4217 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
4219 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4223 gtk_paint_string (GtkStyle *style,
4225 GtkStateType state_type,
4228 const gchar *detail,
4231 const gchar *string)
4233 g_return_if_fail (GTK_IS_STYLE (style));
4234 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
4236 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, area, widget, detail, x, y, string);
4240 gtk_paint_box (GtkStyle *style,
4242 GtkStateType state_type,
4243 GtkShadowType shadow_type,
4246 const gchar *detail,
4252 g_return_if_fail (GTK_IS_STYLE (style));
4253 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
4255 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4259 gtk_paint_flat_box (GtkStyle *style,
4261 GtkStateType state_type,
4262 GtkShadowType shadow_type,
4265 const gchar *detail,
4271 g_return_if_fail (GTK_IS_STYLE (style));
4272 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
4274 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4278 gtk_paint_check (GtkStyle *style,
4280 GtkStateType state_type,
4281 GtkShadowType shadow_type,
4284 const gchar *detail,
4290 g_return_if_fail (GTK_IS_STYLE (style));
4291 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
4293 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4297 gtk_paint_option (GtkStyle *style,
4299 GtkStateType state_type,
4300 GtkShadowType shadow_type,
4303 const gchar *detail,
4309 g_return_if_fail (GTK_IS_STYLE (style));
4310 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
4312 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4316 gtk_paint_tab (GtkStyle *style,
4318 GtkStateType state_type,
4319 GtkShadowType shadow_type,
4322 const gchar *detail,
4328 g_return_if_fail (GTK_IS_STYLE (style));
4329 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
4331 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4335 gtk_paint_shadow_gap (GtkStyle *style,
4337 GtkStateType state_type,
4338 GtkShadowType shadow_type,
4346 GtkPositionType gap_side,
4350 g_return_if_fail (GTK_IS_STYLE (style));
4351 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
4353 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);
4358 gtk_paint_box_gap (GtkStyle *style,
4360 GtkStateType state_type,
4361 GtkShadowType shadow_type,
4369 GtkPositionType gap_side,
4373 g_return_if_fail (GTK_IS_STYLE (style));
4374 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
4376 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);
4380 gtk_paint_extension (GtkStyle *style,
4382 GtkStateType state_type,
4383 GtkShadowType shadow_type,
4391 GtkPositionType gap_side)
4393 g_return_if_fail (GTK_IS_STYLE (style));
4394 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
4396 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, gap_side);
4400 gtk_paint_focus (GtkStyle *style,
4404 const gchar *detail,
4410 g_return_if_fail (GTK_IS_STYLE (style));
4411 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
4413 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, area, widget, detail, x, y, width, height);
4417 gtk_paint_slider (GtkStyle *style,
4419 GtkStateType state_type,
4420 GtkShadowType shadow_type,
4423 const gchar *detail,
4428 GtkOrientation orientation)
4430 g_return_if_fail (GTK_IS_STYLE (style));
4431 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
4433 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
4437 gtk_paint_handle (GtkStyle *style,
4439 GtkStateType state_type,
4440 GtkShadowType shadow_type,
4443 const gchar *detail,
4448 GtkOrientation orientation)
4450 g_return_if_fail (GTK_IS_STYLE (style));
4451 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
4453 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
4457 gtk_paint_expander (GtkStyle *style,
4459 GtkStateType state_type,
4462 const gchar *detail,
4467 g_return_if_fail (GTK_IS_STYLE (style));
4468 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
4470 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type, area,
4471 widget, detail, x, y, is_open);
4475 gtk_paint_layout (GtkStyle *style,
4477 GtkStateType state_type,
4480 const gchar *detail,
4483 PangoLayout *layout)
4485 g_return_if_fail (GTK_IS_STYLE (style));
4486 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
4488 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, area,
4489 widget, detail, x, y, layout);