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"
35 #include "gtksettings.h" /* _gtk_settings_parse_convert() */
37 #define LIGHTNESS_MULT 1.3
38 #define DARKNESS_MULT 0.7
41 /* --- typedefs & structures --- */
49 /* --- prototypes --- */
50 static void gtk_style_init (GtkStyle *style);
51 static void gtk_style_class_init (GtkStyleClass *klass);
52 static void gtk_style_finalize (GObject *object);
53 static void gtk_style_realize (GtkStyle *style,
54 GdkColormap *colormap);
55 static void gtk_style_real_realize (GtkStyle *style);
56 static void gtk_style_real_unrealize (GtkStyle *style);
57 static void gtk_style_real_copy (GtkStyle *style,
59 static void gtk_style_real_set_background (GtkStyle *style,
61 GtkStateType state_type);
62 static GtkStyle *gtk_style_real_clone (GtkStyle *style);
63 static void gtk_style_real_init_from_rc (GtkStyle *style,
64 GtkRcStyle *rc_style);
65 static GdkPixbuf *gtk_default_render_icon (GtkStyle *style,
66 const GtkIconSource *source,
67 GtkTextDirection direction,
72 static void gtk_default_draw_hline (GtkStyle *style,
74 GtkStateType state_type,
81 static void gtk_default_draw_vline (GtkStyle *style,
83 GtkStateType state_type,
90 static void gtk_default_draw_shadow (GtkStyle *style,
92 GtkStateType state_type,
93 GtkShadowType shadow_type,
101 static void gtk_default_draw_polygon (GtkStyle *style,
103 GtkStateType state_type,
104 GtkShadowType shadow_type,
111 static void gtk_default_draw_arrow (GtkStyle *style,
113 GtkStateType state_type,
114 GtkShadowType shadow_type,
118 GtkArrowType arrow_type,
124 static void gtk_default_draw_diamond (GtkStyle *style,
126 GtkStateType state_type,
127 GtkShadowType shadow_type,
135 static void gtk_default_draw_string (GtkStyle *style,
137 GtkStateType state_type,
143 const gchar *string);
144 static void gtk_default_draw_box (GtkStyle *style,
146 GtkStateType state_type,
147 GtkShadowType shadow_type,
155 static void gtk_default_draw_flat_box (GtkStyle *style,
157 GtkStateType state_type,
158 GtkShadowType shadow_type,
166 static void gtk_default_draw_check (GtkStyle *style,
168 GtkStateType state_type,
169 GtkShadowType shadow_type,
177 static void gtk_default_draw_option (GtkStyle *style,
179 GtkStateType state_type,
180 GtkShadowType shadow_type,
188 static void gtk_default_draw_tab (GtkStyle *style,
190 GtkStateType state_type,
191 GtkShadowType shadow_type,
199 static void gtk_default_draw_shadow_gap (GtkStyle *style,
201 GtkStateType state_type,
202 GtkShadowType shadow_type,
210 GtkPositionType gap_side,
213 static void gtk_default_draw_box_gap (GtkStyle *style,
215 GtkStateType state_type,
216 GtkShadowType shadow_type,
224 GtkPositionType gap_side,
227 static void gtk_default_draw_extension (GtkStyle *style,
229 GtkStateType state_type,
230 GtkShadowType shadow_type,
238 GtkPositionType gap_side);
239 static void gtk_default_draw_focus (GtkStyle *style,
248 static void gtk_default_draw_slider (GtkStyle *style,
250 GtkStateType state_type,
251 GtkShadowType shadow_type,
259 GtkOrientation orientation);
260 static void gtk_default_draw_handle (GtkStyle *style,
262 GtkStateType state_type,
263 GtkShadowType shadow_type,
271 GtkOrientation orientation);
272 static void gtk_default_draw_expander (GtkStyle *style,
274 GtkStateType state_type,
281 static void gtk_default_draw_layout (GtkStyle *style,
283 GtkStateType state_type,
290 PangoLayout *layout);
291 static void gtk_default_draw_resize_grip (GtkStyle *style,
293 GtkStateType state_type,
303 static void gtk_style_shade (GdkColor *a,
306 static void rgb_to_hls (gdouble *r,
309 static void hls_to_rgb (gdouble *h,
314 /* --- variables --- */
315 static GdkColor gtk_default_normal_fg = { 0, 0, 0, 0 };
316 static GdkColor gtk_default_active_fg = { 0, 0, 0, 0 };
317 static GdkColor gtk_default_prelight_fg = { 0, 0, 0, 0 };
318 static GdkColor gtk_default_selected_fg = { 0, 0xffff, 0xffff, 0xffff };
319 static GdkColor gtk_default_insensitive_fg = { 0, 0x7530, 0x7530, 0x7530 };
321 static GdkColor gtk_default_normal_bg = { 0, 0xd6d6, 0xd6d6, 0xd6d6 };
322 static GdkColor gtk_default_active_bg = { 0, 0xc350, 0xc350, 0xc350 };
323 static GdkColor gtk_default_prelight_bg = { 0, 0xea60, 0xea60, 0xea60 };
324 static GdkColor gtk_default_selected_bg = { 0, 0, 0, 0x9c40 };
325 static GdkColor gtk_default_insensitive_bg = { 0, 0xd6d6, 0xd6d6, 0xd6d6 };
327 static gpointer parent_class = NULL;
328 static GdkFont *static_default_font = NULL;
331 /* --- functions --- */
333 gtk_style_get_type (void)
335 static GType style_type = 0;
339 static const GTypeInfo style_info =
341 sizeof (GtkStyleClass),
342 (GBaseInitFunc) NULL,
343 (GBaseFinalizeFunc) NULL,
344 (GClassInitFunc) gtk_style_class_init,
345 NULL, /* class_finalize */
346 NULL, /* class_data */
349 (GInstanceInitFunc) gtk_style_init,
352 style_type = g_type_register_static (G_TYPE_OBJECT,
361 gtk_style_init (GtkStyle *style)
365 style->font_desc = pango_font_description_from_string ("Sans 10");
367 if (!static_default_font)
369 static_default_font = gdk_font_from_description (style->font_desc);
371 if (!static_default_font)
372 static_default_font = gdk_font_load ("fixed");
374 if (!static_default_font)
375 g_error ("Unable to load \"fixed\" font");
378 style->font = static_default_font;
379 gdk_font_ref (style->font);
381 style->attach_count = 0;
382 style->colormap = NULL;
385 style->black.red = 0;
386 style->black.green = 0;
387 style->black.blue = 0;
389 style->white.red = 65535;
390 style->white.green = 65535;
391 style->white.blue = 65535;
393 style->black_gc = NULL;
394 style->white_gc = NULL;
396 style->fg[GTK_STATE_NORMAL] = gtk_default_normal_fg;
397 style->fg[GTK_STATE_ACTIVE] = gtk_default_active_fg;
398 style->fg[GTK_STATE_PRELIGHT] = gtk_default_prelight_fg;
399 style->fg[GTK_STATE_SELECTED] = gtk_default_selected_fg;
400 style->fg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
402 style->bg[GTK_STATE_NORMAL] = gtk_default_normal_bg;
403 style->bg[GTK_STATE_ACTIVE] = gtk_default_active_bg;
404 style->bg[GTK_STATE_PRELIGHT] = gtk_default_prelight_bg;
405 style->bg[GTK_STATE_SELECTED] = gtk_default_selected_bg;
406 style->bg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_bg;
408 for (i = 0; i < 4; i++)
410 style->text[i] = style->fg[i];
411 style->base[i] = style->white;
414 style->base[GTK_STATE_SELECTED] = gtk_default_selected_bg;
415 style->base[GTK_STATE_INSENSITIVE] = gtk_default_prelight_bg;
416 style->text[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
418 for (i = 0; i < 5; i++)
419 style->bg_pixmap[i] = NULL;
421 style->rc_style = NULL;
423 for (i = 0; i < 5; i++)
425 style->fg_gc[i] = NULL;
426 style->bg_gc[i] = NULL;
427 style->light_gc[i] = NULL;
428 style->dark_gc[i] = NULL;
429 style->mid_gc[i] = NULL;
430 style->text_gc[i] = NULL;
431 style->base_gc[i] = NULL;
434 style->xthickness = 2;
435 style->ythickness = 2;
437 style->property_cache = NULL;
441 gtk_style_class_init (GtkStyleClass *klass)
443 GObjectClass *object_class = G_OBJECT_CLASS (klass);
445 parent_class = g_type_class_peek_parent (klass);
447 object_class->finalize = gtk_style_finalize;
449 klass->clone = gtk_style_real_clone;
450 klass->copy = gtk_style_real_copy;
451 klass->init_from_rc = gtk_style_real_init_from_rc;
452 klass->realize = gtk_style_real_realize;
453 klass->unrealize = gtk_style_real_unrealize;
454 klass->set_background = gtk_style_real_set_background;
455 klass->render_icon = gtk_default_render_icon;
457 klass->draw_hline = gtk_default_draw_hline;
458 klass->draw_vline = gtk_default_draw_vline;
459 klass->draw_shadow = gtk_default_draw_shadow;
460 klass->draw_polygon = gtk_default_draw_polygon;
461 klass->draw_arrow = gtk_default_draw_arrow;
462 klass->draw_diamond = gtk_default_draw_diamond;
463 klass->draw_string = gtk_default_draw_string;
464 klass->draw_box = gtk_default_draw_box;
465 klass->draw_flat_box = gtk_default_draw_flat_box;
466 klass->draw_check = gtk_default_draw_check;
467 klass->draw_option = gtk_default_draw_option;
468 klass->draw_tab = gtk_default_draw_tab;
469 klass->draw_shadow_gap = gtk_default_draw_shadow_gap;
470 klass->draw_box_gap = gtk_default_draw_box_gap;
471 klass->draw_extension = gtk_default_draw_extension;
472 klass->draw_focus = gtk_default_draw_focus;
473 klass->draw_slider = gtk_default_draw_slider;
474 klass->draw_handle = gtk_default_draw_handle;
475 klass->draw_expander = gtk_default_draw_expander;
476 klass->draw_layout = gtk_default_draw_layout;
477 klass->draw_resize_grip = gtk_default_draw_resize_grip;
481 gtk_style_finalize (GObject *object)
483 GtkStyle *style = GTK_STYLE (object);
485 g_return_if_fail (style->attach_count == 0);
487 if (style->property_cache)
491 for (i = 0; i < style->property_cache->n_nodes; i++)
493 PropertyValue *node = g_bsearch_array_get_nth (style->property_cache, i);
495 g_param_spec_unref (node->pspec);
496 g_value_unset (&node->value);
498 g_bsearch_array_destroy (style->property_cache);
499 style->property_cache = NULL;
504 if (style->styles->data != style)
505 g_slist_remove (style->styles, style);
508 GSList *tmp_list = style->styles->next;
512 GTK_STYLE (tmp_list->data)->styles = style->styles->next;
513 tmp_list = tmp_list->next;
515 g_slist_free_1 (style->styles);
519 gdk_font_unref (style->font);
520 pango_font_description_free (style->font_desc);
523 gtk_rc_style_unref (style->rc_style);
525 G_OBJECT_CLASS (parent_class)->finalize (object);
530 gtk_style_copy (GtkStyle *style)
534 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
536 new_style = GTK_STYLE_GET_CLASS (style)->clone (style);
537 GTK_STYLE_GET_CLASS (style)->copy (new_style, style);
543 gtk_style_duplicate (GtkStyle *style)
547 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
549 new_style = gtk_style_copy (style);
551 style->styles = g_slist_append (style->styles, new_style);
552 new_style->styles = style->styles;
562 style = g_object_new (GTK_TYPE_STYLE, NULL);
567 /*************************************************************
569 * Attach a style to a window; this process allocates the
570 * colors and creates the GC's for the style - it specializes
571 * it to a particular visual and colormap. The process
572 * may involve the creation of a new style if the style
573 * has already been attached to a window with a different
574 * style and colormap.
579 * Either the style parameter, or a newly created style.
580 * If the style is newly created, the style parameter
581 * will be dereferenced, and the new style will have
582 * a reference count belonging to the caller.
584 * FIXME: The sequence -
585 * create a style => s1
586 * attach s1 to v1, c1 => s1
587 * attach s1 to v2, c2 => s2
588 * detach s1 from v1, c1
589 * attach s1 to v2, c2 => s3
590 * results in two separate, unlinked styles s2 and s3 which
591 * are identical and could be shared. To fix this, we would
592 * want to never remove a style from the list of linked
593 * styles as long as as it has a reference count. However, the
594 * disadvantage of doing it this way means that we would need two
595 * passes through the linked list when attaching (one to check for
596 * matching styles, one to look for empty unattached styles - but
597 * it will almost never be longer than 2 elements.
598 *************************************************************/
601 gtk_style_attach (GtkStyle *style,
605 GtkStyle *new_style = NULL;
606 GdkColormap *colormap;
608 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
609 g_return_val_if_fail (window != NULL, NULL);
611 colormap = gdk_window_get_colormap (window);
614 style->styles = g_slist_append (NULL, style);
616 styles = style->styles;
619 new_style = styles->data;
621 if (new_style->attach_count == 0)
623 gtk_style_realize (new_style, colormap);
626 else if (new_style->colormap == colormap)
630 styles = styles->next;
635 new_style = gtk_style_duplicate (style);
636 gtk_style_realize (new_style, colormap);
639 /* A style gets a refcount from being attached */
640 if (new_style->attach_count == 0)
641 gtk_style_ref (new_style);
643 /* Another refcount belongs to the parent */
644 if (style != new_style)
646 gtk_style_unref (style);
647 gtk_style_ref (new_style);
650 new_style->attach_count++;
656 gtk_style_detach (GtkStyle *style)
658 g_return_if_fail (GTK_IS_STYLE (style));
660 style->attach_count -= 1;
661 if (style->attach_count == 0)
663 GTK_STYLE_GET_CLASS (style)->unrealize (style);
665 gdk_colormap_unref (style->colormap);
666 style->colormap = NULL;
668 gtk_style_unref (style);
673 gtk_style_ref (GtkStyle *style)
675 return (GtkStyle *) g_object_ref (G_OBJECT (style));
679 gtk_style_unref (GtkStyle *style)
681 g_object_unref (G_OBJECT (style));
685 gtk_style_realize (GtkStyle *style,
686 GdkColormap *colormap)
688 g_return_if_fail (GTK_IS_STYLE (style));
689 g_return_if_fail (GDK_IS_COLORMAP (colormap));
691 style->colormap = gdk_colormap_ref (colormap);
692 style->depth = gdk_colormap_get_visual (colormap)->depth;
694 GTK_STYLE_GET_CLASS (style)->realize (style);
698 gtk_style_lookup_icon_set (GtkStyle *style,
699 const char *stock_id)
703 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
704 g_return_val_if_fail (stock_id != NULL, NULL);
706 iter = style->icon_factories;
709 GtkIconSet *icon_set = gtk_icon_factory_lookup (GTK_ICON_FACTORY (iter->data),
714 iter = g_slist_next (iter);
717 return gtk_icon_factory_lookup_default (stock_id);
721 gtk_draw_hline (GtkStyle *style,
723 GtkStateType state_type,
728 g_return_if_fail (GTK_IS_STYLE (style));
729 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
731 GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, NULL, NULL, NULL, x1, x2, y);
736 gtk_draw_vline (GtkStyle *style,
738 GtkStateType state_type,
743 g_return_if_fail (GTK_IS_STYLE (style));
744 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
746 GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, NULL, NULL, NULL, y1, y2, x);
751 gtk_draw_shadow (GtkStyle *style,
753 GtkStateType state_type,
754 GtkShadowType shadow_type,
760 g_return_if_fail (GTK_IS_STYLE (style));
761 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
763 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
767 gtk_draw_polygon (GtkStyle *style,
769 GtkStateType state_type,
770 GtkShadowType shadow_type,
775 g_return_if_fail (GTK_IS_STYLE (style));
776 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_polygon != NULL);
778 GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, NULL, NULL, NULL, points, npoints, fill);
782 gtk_draw_arrow (GtkStyle *style,
784 GtkStateType state_type,
785 GtkShadowType shadow_type,
786 GtkArrowType arrow_type,
793 g_return_if_fail (GTK_IS_STYLE (style));
794 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
796 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, NULL, NULL, NULL, arrow_type, fill, x, y, width, height);
801 gtk_draw_diamond (GtkStyle *style,
803 GtkStateType state_type,
804 GtkShadowType shadow_type,
810 g_return_if_fail (GTK_IS_STYLE (style));
811 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
813 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
818 gtk_draw_string (GtkStyle *style,
820 GtkStateType state_type,
825 g_return_if_fail (GTK_IS_STYLE (style));
826 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
828 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, NULL, NULL, NULL, x, y, string);
832 gtk_draw_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_box != NULL);
844 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
848 gtk_draw_flat_box (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_flat_box != NULL);
860 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
864 gtk_draw_check (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_check != NULL);
876 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
880 gtk_draw_option (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_option != NULL);
892 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
896 gtk_draw_tab (GtkStyle *style,
898 GtkStateType state_type,
899 GtkShadowType shadow_type,
905 g_return_if_fail (GTK_IS_STYLE (style));
906 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
908 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
912 gtk_draw_shadow_gap (GtkStyle *style,
914 GtkStateType state_type,
915 GtkShadowType shadow_type,
920 GtkPositionType gap_side,
924 g_return_if_fail (GTK_IS_STYLE (style));
925 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
927 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);
931 gtk_draw_box_gap (GtkStyle *style,
933 GtkStateType state_type,
934 GtkShadowType shadow_type,
939 GtkPositionType gap_side,
943 g_return_if_fail (GTK_IS_STYLE (style));
944 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
946 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);
950 gtk_draw_extension (GtkStyle *style,
952 GtkStateType state_type,
953 GtkShadowType shadow_type,
958 GtkPositionType gap_side)
960 g_return_if_fail (GTK_IS_STYLE (style));
961 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
963 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, gap_side);
967 gtk_draw_focus (GtkStyle *style,
974 g_return_if_fail (GTK_IS_STYLE (style));
975 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
977 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, NULL, NULL, NULL, x, y, width, height);
981 gtk_draw_slider (GtkStyle *style,
983 GtkStateType state_type,
984 GtkShadowType shadow_type,
989 GtkOrientation orientation)
991 g_return_if_fail (GTK_IS_STYLE (style));
992 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
994 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
998 gtk_draw_handle (GtkStyle *style,
1000 GtkStateType state_type,
1001 GtkShadowType shadow_type,
1006 GtkOrientation orientation)
1008 g_return_if_fail (GTK_IS_STYLE (style));
1009 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
1011 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
1015 gtk_draw_expander (GtkStyle *style,
1017 GtkStateType state_type,
1022 g_return_if_fail (GTK_IS_STYLE (style));
1023 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
1025 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type,
1031 gtk_draw_layout (GtkStyle *style,
1033 GtkStateType state_type,
1037 PangoLayout *layout)
1039 g_return_if_fail (GTK_IS_STYLE (style));
1040 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
1042 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, use_text,
1048 gtk_draw_resize_grip (GtkStyle *style,
1050 GtkStateType state_type,
1057 g_return_if_fail (GTK_IS_STYLE (style));
1058 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
1060 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, window, state_type,
1063 x, y, width, height);
1068 gtk_style_set_background (GtkStyle *style,
1070 GtkStateType state_type)
1072 g_return_if_fail (GTK_IS_STYLE (style));
1073 g_return_if_fail (window != NULL);
1075 GTK_STYLE_GET_CLASS (style)->set_background (style, window, state_type);
1078 /* Default functions */
1080 gtk_style_real_clone (GtkStyle *style)
1082 return GTK_STYLE (g_object_new (G_OBJECT_TYPE (style), NULL));
1086 gtk_style_real_copy (GtkStyle *style,
1091 for (i = 0; i < 5; i++)
1093 style->fg[i] = src->fg[i];
1094 style->bg[i] = src->bg[i];
1095 style->text[i] = src->text[i];
1096 style->base[i] = src->base[i];
1098 style->bg_pixmap[i] = src->bg_pixmap[i];
1102 gdk_font_unref (style->font);
1103 style->font = src->font;
1105 gdk_font_ref (style->font);
1107 if (style->font_desc)
1108 pango_font_description_free (style->font_desc);
1110 style->font_desc = pango_font_description_copy (src->font_desc);
1112 style->font_desc = NULL;
1114 style->xthickness = src->xthickness;
1115 style->ythickness = src->ythickness;
1117 if (style->rc_style)
1118 gtk_rc_style_unref (style->rc_style);
1119 style->rc_style = src->rc_style;
1121 gtk_rc_style_ref (src->rc_style);
1123 /* don't copy, just clear cache */
1124 if (style->property_cache)
1128 for (i = 0; i < style->property_cache->n_nodes; i++)
1130 PropertyValue *node = g_bsearch_array_get_nth (style->property_cache, i);
1132 g_param_spec_unref (node->pspec);
1133 g_value_unset (&node->value);
1135 g_bsearch_array_destroy (style->property_cache);
1136 style->property_cache = NULL;
1141 gtk_style_real_init_from_rc (GtkStyle *style,
1142 GtkRcStyle *rc_style)
1147 /* cache _should_ be still empty */
1148 if (style->property_cache)
1152 for (i = 0; i < style->property_cache->n_nodes; i++)
1154 PropertyValue *node = g_bsearch_array_get_nth (style->property_cache, i);
1156 g_param_spec_unref (node->pspec);
1157 g_value_unset (&node->value);
1159 g_bsearch_array_destroy (style->property_cache);
1160 style->property_cache = NULL;
1163 if (rc_style->font_desc)
1165 pango_font_description_free (style->font_desc);
1166 style->font_desc = pango_font_description_copy (rc_style->font_desc);
1168 old_font = style->font;
1169 style->font = gdk_font_from_description (style->font_desc);
1171 gdk_font_unref (old_font);
1173 style->font = old_font;
1176 for (i = 0; i < 5; i++)
1178 if (rc_style->color_flags[i] & GTK_RC_FG)
1179 style->fg[i] = rc_style->fg[i];
1180 if (rc_style->color_flags[i] & GTK_RC_BG)
1181 style->bg[i] = rc_style->bg[i];
1182 if (rc_style->color_flags[i] & GTK_RC_TEXT)
1183 style->text[i] = rc_style->text[i];
1184 if (rc_style->color_flags[i] & GTK_RC_BASE)
1185 style->base[i] = rc_style->base[i];
1188 if (rc_style->xthickness >= 0)
1189 style->xthickness = rc_style->xthickness;
1190 if (rc_style->ythickness >= 0)
1191 style->ythickness = rc_style->ythickness;
1193 if (rc_style->icon_factories)
1197 style->icon_factories = g_slist_copy (rc_style->icon_factories);
1199 iter = style->icon_factories;
1200 while (iter != NULL)
1202 g_object_ref (G_OBJECT (iter->data));
1204 iter = g_slist_next (iter);
1210 style_property_values_cmp (gconstpointer bsearch_node1,
1211 gconstpointer bsearch_node2)
1213 const PropertyValue *val1 = bsearch_node1;
1214 const PropertyValue *val2 = bsearch_node2;
1217 cmp = G_BSEARCH_ARRAY_CMP (val1->widget_type, val2->widget_type);
1219 cmp = G_BSEARCH_ARRAY_CMP (val1->pspec, val2->pspec);
1225 _gtk_style_peek_property_value (GtkStyle *style,
1228 GtkRcPropertyParser parser)
1230 PropertyValue *pcache, key = { 0, NULL, { 0, } };
1231 const GtkRcProperty *rcprop = NULL;
1233 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1234 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), NULL);
1235 g_return_val_if_fail (g_type_is_a (pspec->owner_type, GTK_TYPE_WIDGET), NULL);
1236 g_return_val_if_fail (g_type_is_a (widget_type, pspec->owner_type), NULL);
1238 /* need value cache array */
1239 if (!style->property_cache)
1240 style->property_cache = g_bsearch_array_new (sizeof (PropertyValue),
1241 style_property_values_cmp,
1243 /* lookup, or insert value if not yet present */
1244 key.widget_type = widget_type;
1246 pcache = g_bsearch_array_insert (style->property_cache, &key, FALSE);
1247 if (G_VALUE_TYPE (&pcache->value))
1248 return &pcache->value;
1250 /* cache miss, initialize value type, then set contents */
1251 g_param_spec_ref (pcache->pspec);
1252 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1254 /* value provided by rc style? */
1255 if (style->rc_style)
1257 GQuark prop_quark = g_quark_from_string (pspec->name);
1261 rcprop = _gtk_rc_style_lookup_rc_property (style->rc_style,
1262 g_type_qname (widget_type),
1266 widget_type = g_type_parent (widget_type);
1268 while (g_type_is_a (widget_type, pspec->owner_type));
1271 /* when supplied by rc style, we need to convert */
1272 if (rcprop && !_gtk_settings_parse_convert (parser, &rcprop->value,
1273 pspec, &pcache->value))
1275 gchar *contents = g_strdup_value_contents (&rcprop->value);
1277 g_message ("%s: failed to retrive property `%s::%s' of type `%s' from rc file value \"%s\" of type `%s'",
1279 g_type_name (pspec->owner_type), pspec->name,
1280 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1282 G_VALUE_TYPE_NAME (&rcprop->value));
1284 rcprop = NULL; /* needs default */
1287 /* not supplied by rc style (or conversion failed), revert to default */
1289 g_param_value_set_default (pspec, &pcache->value);
1291 return &pcache->value;
1295 gtk_style_real_realize (GtkStyle *style)
1297 GdkGCValues gc_values;
1298 GdkGCValuesMask gc_values_mask;
1302 for (i = 0; i < 5; i++)
1304 gtk_style_shade (&style->bg[i], &style->light[i], LIGHTNESS_MULT);
1305 gtk_style_shade (&style->bg[i], &style->dark[i], DARKNESS_MULT);
1307 style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
1308 style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
1309 style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
1312 gdk_color_black (style->colormap, &style->black);
1313 gdk_color_white (style->colormap, &style->white);
1315 gc_values_mask = GDK_GC_FOREGROUND | GDK_GC_FONT;
1316 if (style->font->type == GDK_FONT_FONT)
1318 gc_values.font = style->font;
1320 else if (style->font->type == GDK_FONT_FONTSET)
1322 gc_values.font = static_default_font;
1325 gc_values.foreground = style->black;
1326 style->black_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1328 gc_values.foreground = style->white;
1329 style->white_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1331 for (i = 0; i < 5; i++)
1333 if (style->rc_style && style->rc_style->bg_pixmap_name[i])
1334 style->bg_pixmap[i] = gtk_rc_load_image (style->colormap,
1336 style->rc_style->bg_pixmap_name[i]);
1338 if (!gdk_color_alloc (style->colormap, &style->fg[i]))
1339 g_warning ("unable to allocate color: ( %d %d %d )",
1340 style->fg[i].red, style->fg[i].green, style->fg[i].blue);
1341 if (!gdk_color_alloc (style->colormap, &style->bg[i]))
1342 g_warning ("unable to allocate color: ( %d %d %d )",
1343 style->bg[i].red, style->bg[i].green, style->bg[i].blue);
1344 if (!gdk_color_alloc (style->colormap, &style->light[i]))
1345 g_warning ("unable to allocate color: ( %d %d %d )",
1346 style->light[i].red, style->light[i].green, style->light[i].blue);
1347 if (!gdk_color_alloc (style->colormap, &style->dark[i]))
1348 g_warning ("unable to allocate color: ( %d %d %d )",
1349 style->dark[i].red, style->dark[i].green, style->dark[i].blue);
1350 if (!gdk_color_alloc (style->colormap, &style->mid[i]))
1351 g_warning ("unable to allocate color: ( %d %d %d )",
1352 style->mid[i].red, style->mid[i].green, style->mid[i].blue);
1353 if (!gdk_color_alloc (style->colormap, &style->text[i]))
1354 g_warning ("unable to allocate color: ( %d %d %d )",
1355 style->text[i].red, style->text[i].green, style->text[i].blue);
1356 if (!gdk_color_alloc (style->colormap, &style->base[i]))
1357 g_warning ("unable to allocate color: ( %d %d %d )",
1358 style->base[i].red, style->base[i].green, style->base[i].blue);
1360 gc_values.foreground = style->fg[i];
1361 style->fg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1363 gc_values.foreground = style->bg[i];
1364 style->bg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1366 gc_values.foreground = style->light[i];
1367 style->light_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1369 gc_values.foreground = style->dark[i];
1370 style->dark_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1372 gc_values.foreground = style->mid[i];
1373 style->mid_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1375 gc_values.foreground = style->text[i];
1376 style->text_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1378 gc_values.foreground = style->base[i];
1379 style->base_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1384 gtk_style_real_unrealize (GtkStyle *style)
1388 gtk_gc_release (style->black_gc);
1389 gtk_gc_release (style->white_gc);
1391 for (i = 0; i < 5; i++)
1393 gtk_gc_release (style->fg_gc[i]);
1394 gtk_gc_release (style->bg_gc[i]);
1395 gtk_gc_release (style->light_gc[i]);
1396 gtk_gc_release (style->dark_gc[i]);
1397 gtk_gc_release (style->mid_gc[i]);
1398 gtk_gc_release (style->text_gc[i]);
1399 gtk_gc_release (style->base_gc[i]);
1401 if (style->bg_pixmap[i] && style->bg_pixmap[i] != (GdkPixmap*) GDK_PARENT_RELATIVE)
1402 gdk_pixmap_unref (style->bg_pixmap[i]);
1405 gdk_colormap_free_colors (style->colormap, style->fg, 5);
1406 gdk_colormap_free_colors (style->colormap, style->bg, 5);
1407 gdk_colormap_free_colors (style->colormap, style->light, 5);
1408 gdk_colormap_free_colors (style->colormap, style->dark, 5);
1409 gdk_colormap_free_colors (style->colormap, style->mid, 5);
1410 gdk_colormap_free_colors (style->colormap, style->text, 5);
1411 gdk_colormap_free_colors (style->colormap, style->base, 5);
1415 gtk_style_real_set_background (GtkStyle *style,
1417 GtkStateType state_type)
1420 gint parent_relative;
1422 if (style->bg_pixmap[state_type])
1424 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1427 parent_relative = TRUE;
1431 pixmap = style->bg_pixmap[state_type];
1432 parent_relative = FALSE;
1435 gdk_window_set_back_pixmap (window, pixmap, parent_relative);
1438 gdk_window_set_background (window, &style->bg[state_type]);
1442 gtk_style_render_icon (GtkStyle *style,
1443 const GtkIconSource *source,
1444 GtkTextDirection direction,
1448 const gchar *detail)
1452 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1453 g_return_val_if_fail (GTK_STYLE_GET_CLASS (style)->render_icon != NULL, NULL);
1455 pixbuf = GTK_STYLE_GET_CLASS (style)->render_icon (style, source, direction, state,
1456 size, widget, detail);
1458 g_return_val_if_fail (pixbuf != NULL, NULL);
1463 /* Default functions */
1465 gtk_style_apply_default_background (GtkStyle *style,
1468 GtkStateType state_type,
1475 GdkRectangle new_rect, old_rect;
1481 old_rect.width = width;
1482 old_rect.height = height;
1484 if (!gdk_rectangle_intersect (area, &old_rect, &new_rect))
1491 new_rect.width = width;
1492 new_rect.height = height;
1495 if (!style->bg_pixmap[state_type] ||
1496 GDK_IS_PIXMAP (window) ||
1497 (!set_bg && style->bg_pixmap[state_type] != (GdkPixmap*) GDK_PARENT_RELATIVE))
1499 GdkGC *gc = style->bg_gc[state_type];
1501 if (style->bg_pixmap[state_type])
1503 gdk_gc_set_fill (gc, GDK_TILED);
1504 gdk_gc_set_tile (gc, style->bg_pixmap[state_type]);
1507 gdk_draw_rectangle (window, gc, TRUE,
1508 new_rect.x, new_rect.y, new_rect.width, new_rect.height);
1509 if (style->bg_pixmap[state_type])
1510 gdk_gc_set_fill (gc, GDK_SOLID);
1516 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1517 gdk_window_set_back_pixmap (window, NULL, TRUE);
1519 gdk_window_set_back_pixmap (window, style->bg_pixmap[state_type], FALSE);
1522 gdk_window_clear_area (window,
1523 new_rect.x, new_rect.y,
1524 new_rect.width, new_rect.height);
1529 scale_or_ref (GdkPixbuf *src,
1533 if (width == gdk_pixbuf_get_width (src) &&
1534 height == gdk_pixbuf_get_height (src))
1536 gdk_pixbuf_ref (src);
1541 return gdk_pixbuf_scale_simple (src,
1543 GDK_INTERP_BILINEAR);
1548 gtk_default_render_icon (GtkStyle *style,
1549 const GtkIconSource *source,
1550 GtkTextDirection direction,
1554 const gchar *detail)
1560 GdkPixbuf *base_pixbuf;
1562 /* Oddly, style can be NULL in this function, because
1563 * GtkIconSet can be used without a style and if so
1564 * it uses this function.
1567 base_pixbuf = gtk_icon_source_get_pixbuf (source);
1569 g_return_val_if_fail (base_pixbuf != NULL, NULL);
1571 if (!gtk_icon_size_lookup (size, &width, &height))
1573 g_warning (G_STRLOC ": invalid icon size `%d'", size);
1577 /* If the size was wildcarded, then scale; otherwise, leave it
1580 if (gtk_icon_source_get_size_wildcarded (source))
1581 scaled = scale_or_ref (base_pixbuf, width, height);
1583 scaled = GDK_PIXBUF (g_object_ref (G_OBJECT (base_pixbuf)));
1585 /* If the state was wildcarded, then generate a state. */
1586 if (gtk_icon_source_get_state_wildcarded (source))
1588 if (state == GTK_STATE_INSENSITIVE)
1590 stated = gdk_pixbuf_copy (scaled);
1592 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
1595 gdk_pixbuf_unref (scaled);
1597 else if (state == GTK_STATE_PRELIGHT)
1599 stated = gdk_pixbuf_copy (scaled);
1601 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
1604 gdk_pixbuf_unref (scaled);
1618 gtk_default_draw_hline (GtkStyle *style,
1620 GtkStateType state_type,
1623 const gchar *detail,
1628 gint thickness_light;
1629 gint thickness_dark;
1632 g_return_if_fail (GTK_IS_STYLE (style));
1633 g_return_if_fail (window != NULL);
1635 thickness_light = style->ythickness / 2;
1636 thickness_dark = style->ythickness - thickness_light;
1640 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
1641 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
1644 if (detail && !strcmp (detail, "label"))
1646 if (state_type == GTK_STATE_INSENSITIVE)
1647 gdk_draw_line (window, style->white_gc, x1 + 1, y + 1, x2 + 1, y + 1);
1648 gdk_draw_line (window, style->fg_gc[state_type], x1, y, x2, y);
1652 for (i = 0; i < thickness_dark; i++)
1654 gdk_draw_line (window, style->light_gc[state_type], x2 - i - 1, y + i, x2, y + i);
1655 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x2 - i - 1, y + i);
1658 y += thickness_dark;
1659 for (i = 0; i < thickness_light; i++)
1661 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x1 + thickness_light - i - 1, y + i);
1662 gdk_draw_line (window, style->light_gc[state_type], x1 + thickness_light - i - 1, y + i, x2, y + i);
1668 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
1669 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
1675 gtk_default_draw_vline (GtkStyle *style,
1677 GtkStateType state_type,
1680 const gchar *detail,
1685 gint thickness_light;
1686 gint thickness_dark;
1689 g_return_if_fail (GTK_IS_STYLE (style));
1690 g_return_if_fail (window != NULL);
1692 thickness_light = style->xthickness / 2;
1693 thickness_dark = style->xthickness - thickness_light;
1697 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
1698 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
1700 for (i = 0; i < thickness_dark; i++)
1702 gdk_draw_line (window, style->light_gc[state_type], x + i, y2 - i - 1, x + i, y2);
1703 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y2 - i - 1);
1706 x += thickness_dark;
1707 for (i = 0; i < thickness_light; i++)
1709 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y1 + thickness_light - i);
1710 gdk_draw_line (window, style->light_gc[state_type], x + i, y1 + thickness_light - i, x + i, y2);
1714 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
1715 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
1721 gtk_default_draw_shadow (GtkStyle *style,
1723 GtkStateType state_type,
1724 GtkShadowType shadow_type,
1727 const gchar *detail,
1735 gint thickness_light;
1736 gint thickness_dark;
1739 g_return_if_fail (GTK_IS_STYLE (style));
1740 g_return_if_fail (window != NULL);
1742 if ((width == -1) && (height == -1))
1743 gdk_window_get_size (window, &width, &height);
1744 else if (width == -1)
1745 gdk_window_get_size (window, &width, NULL);
1746 else if (height == -1)
1747 gdk_window_get_size (window, NULL, &height);
1749 switch (shadow_type)
1751 case GTK_SHADOW_NONE:
1754 case GTK_SHADOW_ETCHED_IN:
1755 gc1 = style->light_gc[state_type];
1756 gc2 = style->dark_gc[state_type];
1758 case GTK_SHADOW_OUT:
1759 case GTK_SHADOW_ETCHED_OUT:
1760 gc1 = style->dark_gc[state_type];
1761 gc2 = style->light_gc[state_type];
1767 gdk_gc_set_clip_rectangle (gc1, area);
1768 gdk_gc_set_clip_rectangle (gc2, area);
1769 if (shadow_type == GTK_SHADOW_IN ||
1770 shadow_type == GTK_SHADOW_OUT)
1772 gdk_gc_set_clip_rectangle (style->black_gc, area);
1773 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
1777 switch (shadow_type)
1779 case GTK_SHADOW_NONE:
1783 gdk_draw_line (window, gc1,
1784 x, y + height - 1, x + width - 1, y + height - 1);
1785 gdk_draw_line (window, gc1,
1786 x + width - 1, y, x + width - 1, y + height - 1);
1788 gdk_draw_line (window, style->bg_gc[state_type],
1789 x + 1, y + height - 2, x + width - 2, y + height - 2);
1790 gdk_draw_line (window, style->bg_gc[state_type],
1791 x + width - 2, y + 1, x + width - 2, y + height - 2);
1793 gdk_draw_line (window, style->black_gc,
1794 x + 1, y + 1, x + width - 2, y + 1);
1795 gdk_draw_line (window, style->black_gc,
1796 x + 1, y + 1, x + 1, y + height - 2);
1798 gdk_draw_line (window, gc2,
1799 x, y, x + width - 1, y);
1800 gdk_draw_line (window, gc2,
1801 x, y, x, y + height - 1);
1804 case GTK_SHADOW_OUT:
1805 gdk_draw_line (window, gc1,
1806 x + 1, y + height - 2, x + width - 2, y + height - 2);
1807 gdk_draw_line (window, gc1,
1808 x + width - 2, y + 1, x + width - 2, y + height - 2);
1810 gdk_draw_line (window, gc2,
1811 x, y, x + width - 1, y);
1812 gdk_draw_line (window, gc2,
1813 x, y, x, y + height - 1);
1815 gdk_draw_line (window, style->bg_gc[state_type],
1816 x + 1, y + 1, x + width - 2, y + 1);
1817 gdk_draw_line (window, style->bg_gc[state_type],
1818 x + 1, y + 1, x + 1, y + height - 2);
1820 gdk_draw_line (window, style->black_gc,
1821 x, y + height - 1, x + width - 1, y + height - 1);
1822 gdk_draw_line (window, style->black_gc,
1823 x + width - 1, y, x + width - 1, y + height - 1);
1826 case GTK_SHADOW_ETCHED_IN:
1827 case GTK_SHADOW_ETCHED_OUT:
1828 thickness_light = 1;
1831 for (i = 0; i < thickness_dark; i++)
1833 gdk_draw_line (window, gc1,
1837 y + height - i - 1);
1838 gdk_draw_line (window, gc1,
1842 y + height - i - 1);
1844 gdk_draw_line (window, gc2,
1849 gdk_draw_line (window, gc2,
1853 y + height - i - 2);
1856 for (i = 0; i < thickness_light; i++)
1858 gdk_draw_line (window, gc1,
1859 x + thickness_dark + i,
1860 y + thickness_dark + i,
1861 x + width - thickness_dark - i - 1,
1862 y + thickness_dark + i);
1863 gdk_draw_line (window, gc1,
1864 x + thickness_dark + i,
1865 y + thickness_dark + i,
1866 x + thickness_dark + i,
1867 y + height - thickness_dark - i - 1);
1869 gdk_draw_line (window, gc2,
1870 x + thickness_dark + i,
1871 y + height - thickness_light - i - 1,
1872 x + width - thickness_light - 1,
1873 y + height - thickness_light - i - 1);
1874 gdk_draw_line (window, gc2,
1875 x + width - thickness_light - i - 1,
1876 y + thickness_dark + i,
1877 x + width - thickness_light - i - 1,
1878 y + height - thickness_light - 1);
1884 gdk_gc_set_clip_rectangle (gc1, NULL);
1885 gdk_gc_set_clip_rectangle (gc2, NULL);
1886 if (shadow_type == GTK_SHADOW_IN ||
1887 shadow_type == GTK_SHADOW_OUT)
1889 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
1890 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
1896 gtk_default_draw_polygon (GtkStyle *style,
1898 GtkStateType state_type,
1899 GtkShadowType shadow_type,
1902 const gchar *detail,
1907 static const gdouble pi_over_4 = G_PI_4;
1908 static const gdouble pi_3_over_4 = G_PI_4 * 3;
1918 g_return_if_fail (GTK_IS_STYLE (style));
1919 g_return_if_fail (window != NULL);
1920 g_return_if_fail (points != NULL);
1922 switch (shadow_type)
1925 gc1 = style->bg_gc[state_type];
1926 gc2 = style->dark_gc[state_type];
1927 gc3 = style->light_gc[state_type];
1928 gc4 = style->black_gc;
1930 case GTK_SHADOW_ETCHED_IN:
1931 gc1 = style->light_gc[state_type];
1932 gc2 = style->dark_gc[state_type];
1933 gc3 = style->dark_gc[state_type];
1934 gc4 = style->light_gc[state_type];
1936 case GTK_SHADOW_OUT:
1937 gc1 = style->dark_gc[state_type];
1938 gc2 = style->light_gc[state_type];
1939 gc3 = style->black_gc;
1940 gc4 = style->bg_gc[state_type];
1942 case GTK_SHADOW_ETCHED_OUT:
1943 gc1 = style->dark_gc[state_type];
1944 gc2 = style->light_gc[state_type];
1945 gc3 = style->light_gc[state_type];
1946 gc4 = style->dark_gc[state_type];
1954 gdk_gc_set_clip_rectangle (gc1, area);
1955 gdk_gc_set_clip_rectangle (gc2, area);
1956 gdk_gc_set_clip_rectangle (gc3, area);
1957 gdk_gc_set_clip_rectangle (gc4, area);
1961 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, npoints);
1965 for (i = 0; i < npoints; i++)
1967 if ((points[i].x == points[i+1].x) &&
1968 (points[i].y == points[i+1].y))
1974 angle = atan2 (points[i+1].y - points[i].y,
1975 points[i+1].x - points[i].x);
1978 if ((angle > -pi_3_over_4) && (angle < pi_over_4))
1980 if (angle > -pi_over_4)
1991 gdk_draw_line (window, gc1,
1992 points[i].x-xadjust, points[i].y-yadjust,
1993 points[i+1].x-xadjust, points[i+1].y-yadjust);
1994 gdk_draw_line (window, gc3,
1995 points[i].x, points[i].y,
1996 points[i+1].x, points[i+1].y);
2000 if ((angle < -pi_3_over_4) || (angle > pi_3_over_4))
2011 gdk_draw_line (window, gc4,
2012 points[i].x+xadjust, points[i].y+yadjust,
2013 points[i+1].x+xadjust, points[i+1].y+yadjust);
2014 gdk_draw_line (window, gc2,
2015 points[i].x, points[i].y,
2016 points[i+1].x, points[i+1].y);
2022 gdk_gc_set_clip_rectangle (gc1, NULL);
2023 gdk_gc_set_clip_rectangle (gc2, NULL);
2024 gdk_gc_set_clip_rectangle (gc3, NULL);
2025 gdk_gc_set_clip_rectangle (gc4, NULL);
2030 gtk_default_draw_arrow (GtkStyle *style,
2032 GtkStateType state_type,
2033 GtkShadowType shadow_type,
2036 const gchar *detail,
2037 GtkArrowType arrow_type,
2052 g_return_if_fail (GTK_IS_STYLE (style));
2053 g_return_if_fail (window != NULL);
2055 switch (shadow_type)
2058 gc1 = style->bg_gc[state_type];
2059 gc2 = style->dark_gc[state_type];
2060 gc3 = style->light_gc[state_type];
2061 gc4 = style->black_gc;
2063 case GTK_SHADOW_OUT:
2064 gc1 = style->dark_gc[state_type];
2065 gc2 = style->light_gc[state_type];
2066 gc3 = style->black_gc;
2067 gc4 = style->bg_gc[state_type];
2069 case GTK_SHADOW_ETCHED_IN:
2070 gc1 = style->light_gc[state_type];
2071 gc2 = style->dark_gc[state_type];
2075 case GTK_SHADOW_ETCHED_OUT:
2076 gc1 = style->dark_gc[state_type];
2077 gc2 = style->light_gc[state_type];
2085 if ((width == -1) && (height == -1))
2086 gdk_window_get_size (window, &width, &height);
2087 else if (width == -1)
2088 gdk_window_get_size (window, &width, NULL);
2089 else if (height == -1)
2090 gdk_window_get_size (window, NULL, &height);
2092 half_width = width / 2;
2093 half_height = height / 2;
2097 gdk_gc_set_clip_rectangle (gc1, area);
2098 gdk_gc_set_clip_rectangle (gc2, area);
2101 gdk_gc_set_clip_rectangle (gc3, area);
2102 gdk_gc_set_clip_rectangle (gc4, area);
2111 points[0].x = x + half_width;
2114 points[1].y = y + height - 1;
2115 points[2].x = x + width - 1;
2116 points[2].y = y + height - 1;
2118 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
2121 switch (shadow_type)
2124 case GTK_SHADOW_OUT:
2126 gdk_draw_line (window, gc1,
2127 x + 1, y + height - 2,
2128 x + width - 2, y + height - 2);
2129 gdk_draw_line (window, gc3,
2130 x + 0, y + height - 1,
2131 x + width - 1, y + height - 1);
2133 gdk_draw_line (window, gc1,
2134 x + width - 2, y + height - 1,
2135 x + half_width, y + 1);
2136 gdk_draw_line (window, gc3,
2137 x + width - 1, y + height - 1,
2140 gdk_draw_line (window, gc4,
2141 x + half_width, y + 1,
2142 x + 1, y + height - 1);
2143 gdk_draw_line (window, gc2,
2148 case GTK_SHADOW_ETCHED_IN:
2149 case GTK_SHADOW_ETCHED_OUT:
2150 gdk_draw_line (window, gc1,
2151 x + half_width, y + 1,
2152 x + 1, y + height - 1);
2153 gdk_draw_line (window, gc1,
2154 x + 1, y + height - 1,
2155 x + width - 1, y + height - 1);
2156 gdk_draw_line (window, gc1,
2157 x + width - 1, y + height - 1,
2158 x + half_width + 1, y + 1);
2160 points[0].x = x + half_width;
2163 points[1].y = y + height - 2;
2164 points[2].x = x + width - 2;
2165 points[2].y = y + height - 2;
2167 gdk_draw_polygon (window, gc2, FALSE, points, 3);
2175 case GTK_ARROW_DOWN:
2178 points[0].x = x + width - 1;
2182 points[2].x = x + half_width;
2183 points[2].y = y + height - 1;
2185 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
2187 switch (shadow_type)
2190 case GTK_SHADOW_OUT:
2191 gdk_draw_line (window, gc4,
2193 y + 1, x + 1, y + 1);
2194 gdk_draw_line (window, gc2,
2198 gdk_draw_line (window, gc4,
2200 x + half_width, y + height - 2);
2201 gdk_draw_line (window, gc2,
2203 x + half_width, y + height - 1);
2205 gdk_draw_line (window, gc1,
2206 x + half_width, y + height - 2,
2208 gdk_draw_line (window, gc3,
2209 x + half_width, y + height - 1,
2213 case GTK_SHADOW_ETCHED_IN:
2214 case GTK_SHADOW_ETCHED_OUT:
2215 gdk_draw_line (window, gc1,
2216 x + width - 1, y + 1,
2218 gdk_draw_line (window, gc1,
2220 x + half_width + 1, y + height - 1);
2221 gdk_draw_line (window, gc1,
2222 x + half_width + 1, y + height - 2,
2225 points[0].x = x + width - 2;
2229 points[2].x = x + half_width;
2230 points[2].y = y + height - 2;
2232 gdk_draw_polygon (window, gc2, FALSE, points, 3);
2239 case GTK_ARROW_LEFT:
2243 points[0].y = y + half_height;
2244 points[1].x = x + width - 1;
2245 points[1].y = y + height - 1;
2246 points[2].x = x + width - 1;
2249 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
2252 switch (shadow_type)
2255 case GTK_SHADOW_OUT:
2256 gdk_draw_line (window, gc1,
2257 x + 1, y + half_height,
2258 x + width - 1, y + height - 1);
2259 gdk_draw_line (window, gc3,
2261 x + width - 1, y + height - 1);
2263 gdk_draw_line (window, gc1,
2264 x + width - 2, y + height - 1,
2265 x + width - 2, y + 1);
2266 gdk_draw_line (window, gc3,
2267 x + width - 1, y + height - 1,
2270 gdk_draw_line (window, gc4,
2271 x + width - 1, y + 1,
2272 x + 1, y + half_height);
2273 gdk_draw_line (window, gc2,
2275 x, y + half_height);
2278 case GTK_SHADOW_ETCHED_IN:
2279 case GTK_SHADOW_ETCHED_OUT:
2280 gdk_draw_line (window, gc1,
2281 x + width - 1, y + 1,
2282 x + 1, y + half_height);
2283 gdk_draw_line (window, gc1,
2284 x + 1, y + half_height + 1,
2285 x + width - 1, y + height - 1);
2286 gdk_draw_line (window, gc1,
2287 x + width - 1, y + height - 1,
2288 x + width - 1, y + 1);
2290 points[0].x = x + width - 2;
2293 points[1].y = y + half_height;
2294 points[2].x = x + width - 2;
2295 points[2].y = y + height - 2;
2297 gdk_draw_polygon (window, gc2, FALSE, points, 3);
2304 case GTK_ARROW_RIGHT:
2307 points[0].x = x + width - 1;
2308 points[0].y = y + half_height;
2312 points[2].y = y + height - 1;
2314 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
2317 switch (shadow_type)
2320 case GTK_SHADOW_OUT:
2321 gdk_draw_line (window, gc4,
2322 x + width - 1, y + half_height,
2324 gdk_draw_line (window, gc2,
2325 x + width - 1, y + half_height,
2327 gdk_draw_line (window, gc4,
2329 x + 1, y + height - 2);
2330 gdk_draw_line (window, gc2,
2334 gdk_draw_line (window, gc1,
2335 x + 1, y + height - 2,
2336 x + width - 1, y + half_height);
2337 gdk_draw_line (window, gc3,
2339 x + width - 1, y + half_height);
2342 case GTK_SHADOW_ETCHED_IN:
2343 case GTK_SHADOW_ETCHED_OUT:
2344 gdk_draw_line (window, gc1,
2345 x + width - 1, y + half_height + 1,
2347 gdk_draw_line (window, gc1,
2349 x + 1, y + height - 1);
2350 gdk_draw_line (window, gc1,
2351 x + 1, y + height - 1,
2352 x + width - 1, y + half_height + 1);
2354 points[0].x = x + width - 2;
2355 points[0].y = y + half_height;
2359 points[2].y = y + height - 1;
2361 gdk_draw_polygon (window, gc2, FALSE, points, 3);
2372 gdk_gc_set_clip_rectangle (gc1, NULL);
2373 gdk_gc_set_clip_rectangle (gc2, NULL);
2376 gdk_gc_set_clip_rectangle (gc3, NULL);
2377 gdk_gc_set_clip_rectangle (gc4, NULL);
2383 gtk_default_draw_diamond (GtkStyle *style,
2385 GtkStateType state_type,
2386 GtkShadowType shadow_type,
2389 const gchar *detail,
2397 GdkGC *outer_nw = NULL;
2398 GdkGC *outer_ne = NULL;
2399 GdkGC *outer_sw = NULL;
2400 GdkGC *outer_se = NULL;
2401 GdkGC *middle_nw = NULL;
2402 GdkGC *middle_ne = NULL;
2403 GdkGC *middle_sw = NULL;
2404 GdkGC *middle_se = NULL;
2405 GdkGC *inner_nw = NULL;
2406 GdkGC *inner_ne = NULL;
2407 GdkGC *inner_sw = NULL;
2408 GdkGC *inner_se = NULL;
2410 g_return_if_fail (GTK_IS_STYLE (style));
2411 g_return_if_fail (window != NULL);
2413 if ((width == -1) && (height == -1))
2414 gdk_window_get_size (window, &width, &height);
2415 else if (width == -1)
2416 gdk_window_get_size (window, &width, NULL);
2417 else if (height == -1)
2418 gdk_window_get_size (window, NULL, &height);
2420 half_width = width / 2;
2421 half_height = height / 2;
2425 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
2426 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2427 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
2428 gdk_gc_set_clip_rectangle (style->black_gc, area);
2431 switch (shadow_type)
2434 inner_sw = inner_se = style->bg_gc[state_type];
2435 middle_sw = middle_se = style->light_gc[state_type];
2436 outer_sw = outer_se = style->light_gc[state_type];
2437 inner_nw = inner_ne = style->black_gc;
2438 middle_nw = middle_ne = style->dark_gc[state_type];
2439 outer_nw = outer_ne = style->dark_gc[state_type];
2442 case GTK_SHADOW_OUT:
2443 inner_sw = inner_se = style->dark_gc[state_type];
2444 middle_sw = middle_se = style->dark_gc[state_type];
2445 outer_sw = outer_se = style->black_gc;
2446 inner_nw = inner_ne = style->bg_gc[state_type];
2447 middle_nw = middle_ne = style->light_gc[state_type];
2448 outer_nw = outer_ne = style->light_gc[state_type];
2451 case GTK_SHADOW_ETCHED_IN:
2452 inner_sw = inner_se = style->bg_gc[state_type];
2453 middle_sw = middle_se = style->dark_gc[state_type];
2454 outer_sw = outer_se = style->light_gc[state_type];
2455 inner_nw = inner_ne = style->bg_gc[state_type];
2456 middle_nw = middle_ne = style->light_gc[state_type];
2457 outer_nw = outer_ne = style->dark_gc[state_type];
2460 case GTK_SHADOW_ETCHED_OUT:
2461 inner_sw = inner_se = style->bg_gc[state_type];
2462 middle_sw = middle_se = style->light_gc[state_type];
2463 outer_sw = outer_se = style->dark_gc[state_type];
2464 inner_nw = inner_ne = style->bg_gc[state_type];
2465 middle_nw = middle_ne = style->dark_gc[state_type];
2466 outer_nw = outer_ne = style->light_gc[state_type];
2476 gdk_draw_line (window, inner_sw,
2477 x + 2, y + half_height,
2478 x + half_width, y + height - 2);
2479 gdk_draw_line (window, inner_se,
2480 x + half_width, y + height - 2,
2481 x + width - 2, y + half_height);
2482 gdk_draw_line (window, middle_sw,
2483 x + 1, y + half_height,
2484 x + half_width, y + height - 1);
2485 gdk_draw_line (window, middle_se,
2486 x + half_width, y + height - 1,
2487 x + width - 1, y + half_height);
2488 gdk_draw_line (window, outer_sw,
2490 x + half_width, y + height);
2491 gdk_draw_line (window, outer_se,
2492 x + half_width, y + height,
2493 x + width, y + half_height);
2495 gdk_draw_line (window, inner_nw,
2496 x + 2, y + half_height,
2497 x + half_width, y + 2);
2498 gdk_draw_line (window, inner_ne,
2499 x + half_width, y + 2,
2500 x + width - 2, y + half_height);
2501 gdk_draw_line (window, middle_nw,
2502 x + 1, y + half_height,
2503 x + half_width, y + 1);
2504 gdk_draw_line (window, middle_ne,
2505 x + half_width, y + 1,
2506 x + width - 1, y + half_height);
2507 gdk_draw_line (window, outer_nw,
2510 gdk_draw_line (window, outer_ne,
2512 x + width, y + half_height);
2517 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
2518 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
2519 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
2520 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2525 gtk_default_draw_string (GtkStyle *style,
2527 GtkStateType state_type,
2530 const gchar *detail,
2533 const gchar *string)
2535 g_return_if_fail (GTK_IS_STYLE (style));
2536 g_return_if_fail (window != NULL);
2540 gdk_gc_set_clip_rectangle (style->white_gc, area);
2541 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], area);
2544 if (state_type == GTK_STATE_INSENSITIVE)
2545 gdk_draw_string (window, style->font, style->white_gc, x + 1, y + 1, string);
2547 gdk_draw_string (window, style->font, style->fg_gc[state_type], x, y, string);
2551 gdk_gc_set_clip_rectangle (style->white_gc, NULL);
2552 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], NULL);
2557 gtk_default_draw_box (GtkStyle *style,
2559 GtkStateType state_type,
2560 GtkShadowType shadow_type,
2563 const gchar *detail,
2569 g_return_if_fail (GTK_IS_STYLE (style));
2570 g_return_if_fail (window != NULL);
2572 if (width == -1 && height == -1)
2573 gdk_window_get_size (window, &width, &height);
2574 else if (width == -1)
2575 gdk_window_get_size (window, &width, NULL);
2576 else if (height == -1)
2577 gdk_window_get_size (window, NULL, &height);
2579 if (!style->bg_pixmap[state_type] ||
2580 GDK_IS_PIXMAP (window))
2583 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2585 gdk_draw_rectangle (window, style->bg_gc[state_type], TRUE,
2586 x, y, width, height);
2588 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
2591 gtk_style_apply_default_background (style, window,
2592 widget && !GTK_WIDGET_NO_WINDOW (widget),
2593 state_type, area, x, y, width, height);
2595 gtk_paint_shadow (style, window, state_type, shadow_type, area, widget, detail,
2596 x, y, width, height);
2600 get_darkened_gc (GdkWindow *window,
2604 GdkColor src = *color;
2608 gc = gdk_gc_new (window);
2610 while (darken_count)
2612 gtk_style_shade (&src, &shaded, 0.93);
2617 gdk_gc_set_rgb_fg_color (gc, &shaded);
2623 gtk_default_draw_flat_box (GtkStyle *style,
2625 GtkStateType state_type,
2626 GtkShadowType shadow_type,
2629 const gchar *detail,
2636 GdkGC *freeme = NULL;
2638 g_return_if_fail (GTK_IS_STYLE (style));
2639 g_return_if_fail (window != NULL);
2641 if (width == -1 && height == -1)
2642 gdk_window_get_size (window, &width, &height);
2643 else if (width == -1)
2644 gdk_window_get_size (window, &width, NULL);
2645 else if (height == -1)
2646 gdk_window_get_size (window, NULL, &height);
2650 if (state_type == GTK_STATE_SELECTED)
2652 if (!strcmp ("text", detail))
2653 gc1 = style->bg_gc[GTK_STATE_SELECTED];
2654 else if (!strcmp ("cell_even_sorted", detail) ||
2655 !strcmp ("cell_odd_sorted", detail) ||
2656 !strcmp ("cell_even_ruled_sorted", detail) ||
2657 !strcmp ("cell_odd_ruled_sorted", detail))
2659 freeme = get_darkened_gc (window, &style->bg[state_type], 1);
2664 gc1 = style->bg_gc[state_type];
2669 if (!strcmp ("viewportbin", detail))
2670 gc1 = style->bg_gc[GTK_STATE_NORMAL];
2671 else if (!strcmp ("entry_bg", detail))
2672 gc1 = style->base_gc[state_type];
2674 /* For trees: even rows are base color, odd rows are a shade of
2675 * the base color, the sort column is a shade of the original color
2679 /* FIXME when we have style properties, clean this up.
2682 else if (!strcmp ("cell_even", detail) ||
2683 !strcmp ("cell_odd", detail) ||
2684 !strcmp ("cell_even_ruled", detail))
2686 gc1 = style->base_gc[state_type];
2688 else if (!strcmp ("cell_even_sorted", detail) ||
2689 !strcmp ("cell_odd_sorted", detail) ||
2690 !strcmp ("cell_odd_ruled", detail) ||
2691 !strcmp ("cell_even_ruled_sorted", detail))
2693 freeme = get_darkened_gc (window, &style->base[state_type], 1);
2696 else if (!strcmp ("cell_odd_ruled_sorted", detail))
2698 freeme = get_darkened_gc (window, &style->base[state_type], 2);
2702 gc1 = style->bg_gc[state_type];
2706 gc1 = style->bg_gc[state_type];
2708 if (!style->bg_pixmap[state_type] || gc1 != style->bg_gc[state_type] ||
2709 GDK_IS_PIXMAP (window))
2712 gdk_gc_set_clip_rectangle (gc1, area);
2714 gdk_draw_rectangle (window, gc1, TRUE,
2715 x, y, width, height);
2717 if (detail && !strcmp ("tooltip", detail))
2718 gdk_draw_rectangle (window, style->black_gc, FALSE,
2719 x, y, width - 1, height - 1);
2722 gdk_gc_set_clip_rectangle (gc1, NULL);
2725 gtk_style_apply_default_background (style, window,
2726 widget && !GTK_WIDGET_NO_WINDOW (widget),
2727 state_type, area, x, y, width, height);
2731 g_object_unref (G_OBJECT (freeme));
2735 gtk_default_draw_check (GtkStyle *style,
2737 GtkStateType state_type,
2738 GtkShadowType shadow_type,
2741 const gchar *detail,
2747 if (detail && strcmp (detail, "cellcheck") == 0)
2749 gdk_draw_rectangle (window,
2750 widget->style->fg_gc[state_type],
2755 if (shadow_type == GTK_SHADOW_IN)
2757 gdk_draw_line (window,
2758 widget->style->fg_gc[state_type],
2762 gdk_draw_line (window,
2763 widget->style->fg_gc[state_type],
2772 gtk_paint_box (style, window, state_type, shadow_type, area, widget, detail,
2773 x, y, width, height);
2778 gtk_default_draw_option (GtkStyle *style,
2780 GtkStateType state_type,
2781 GtkShadowType shadow_type,
2784 const gchar *detail,
2790 if (detail && strcmp (detail, "cellradio") == 0)
2792 gdk_draw_arc (window,
2793 widget->style->fg_gc[state_type],
2800 if (shadow_type == GTK_SHADOW_IN)
2802 gdk_draw_arc (window,
2803 widget->style->fg_gc[state_type],
2814 gtk_paint_diamond (style, window, state_type, shadow_type, area, widget,
2815 detail, x, y, width, height);
2820 gtk_default_draw_tab (GtkStyle *style,
2822 GtkStateType state_type,
2823 GtkShadowType shadow_type,
2826 const gchar *detail,
2832 g_return_if_fail (GTK_IS_STYLE (style));
2833 g_return_if_fail (window != NULL);
2835 gtk_paint_box (style, window, state_type, shadow_type, area, widget, detail,
2836 x, y, width, height);
2840 gtk_default_draw_shadow_gap (GtkStyle *style,
2842 GtkStateType state_type,
2843 GtkShadowType shadow_type,
2846 const gchar *detail,
2851 GtkPositionType gap_side,
2860 g_return_if_fail (GTK_IS_STYLE (style));
2861 g_return_if_fail (window != NULL);
2863 if (width == -1 && height == -1)
2864 gdk_window_get_size (window, &width, &height);
2865 else if (width == -1)
2866 gdk_window_get_size (window, &width, NULL);
2867 else if (height == -1)
2868 gdk_window_get_size (window, NULL, &height);
2870 switch (shadow_type)
2872 case GTK_SHADOW_NONE:
2875 gc1 = style->dark_gc[state_type];
2876 gc2 = style->black_gc;
2877 gc3 = style->bg_gc[state_type];
2878 gc4 = style->light_gc[state_type];
2880 case GTK_SHADOW_ETCHED_IN:
2881 gc1 = style->dark_gc[state_type];
2882 gc2 = style->light_gc[state_type];
2883 gc3 = style->dark_gc[state_type];
2884 gc4 = style->light_gc[state_type];
2886 case GTK_SHADOW_OUT:
2887 gc1 = style->light_gc[state_type];
2888 gc2 = style->bg_gc[state_type];
2889 gc3 = style->dark_gc[state_type];
2890 gc4 = style->black_gc;
2892 case GTK_SHADOW_ETCHED_OUT:
2893 gc1 = style->light_gc[state_type];
2894 gc2 = style->dark_gc[state_type];
2895 gc3 = style->light_gc[state_type];
2896 gc4 = style->dark_gc[state_type];
2901 gdk_gc_set_clip_rectangle (gc1, area);
2902 gdk_gc_set_clip_rectangle (gc2, area);
2903 gdk_gc_set_clip_rectangle (gc3, area);
2904 gdk_gc_set_clip_rectangle (gc4, area);
2907 switch (shadow_type)
2909 case GTK_SHADOW_NONE:
2911 case GTK_SHADOW_OUT:
2912 case GTK_SHADOW_ETCHED_IN:
2913 case GTK_SHADOW_ETCHED_OUT:
2917 gdk_draw_line (window, gc1,
2918 x, y, x, y + height - 1);
2919 gdk_draw_line (window, gc2,
2920 x + 1, y, x + 1, y + height - 2);
2922 gdk_draw_line (window, gc3,
2923 x + 1, y + height - 2, x + width - 2, y + height - 2);
2924 gdk_draw_line (window, gc3,
2925 x + width - 2, y, x + width - 2, y + height - 2);
2926 gdk_draw_line (window, gc4,
2927 x, y + height - 1, x + width - 1, y + height - 1);
2928 gdk_draw_line (window, gc4,
2929 x + width - 1, y, x + width - 1, y + height - 1);
2932 gdk_draw_line (window, gc1,
2933 x, y, x + gap_x - 1, y);
2934 gdk_draw_line (window, gc2,
2935 x + 1, y + 1, x + gap_x - 1, y + 1);
2936 gdk_draw_line (window, gc2,
2937 x + gap_x, y, x + gap_x, y);
2939 if ((width - (gap_x + gap_width)) > 0)
2941 gdk_draw_line (window, gc1,
2942 x + gap_x + gap_width, y, x + width - 2, y);
2943 gdk_draw_line (window, gc2,
2944 x + gap_x + gap_width, y + 1, x + width - 2, y + 1);
2945 gdk_draw_line (window, gc2,
2946 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
2949 case GTK_POS_BOTTOM:
2950 gdk_draw_line (window, gc1,
2951 x, y, x + width - 1, y);
2952 gdk_draw_line (window, gc1,
2953 x, y, x, y + height - 1);
2954 gdk_draw_line (window, gc2,
2955 x + 1, y + 1, x + width - 2, y + 1);
2956 gdk_draw_line (window, gc2,
2957 x + 1, y + 1, x + 1, y + height - 1);
2959 gdk_draw_line (window, gc3,
2960 x + width - 2, y + 1, x + width - 2, y + height - 1);
2961 gdk_draw_line (window, gc4,
2962 x + width - 1, y, x + width - 1, y + height - 1);
2965 gdk_draw_line (window, gc4,
2966 x, y + height - 1, x + gap_x - 1, y + height - 1);
2967 gdk_draw_line (window, gc3,
2968 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
2969 gdk_draw_line (window, gc3,
2970 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
2972 if ((width - (gap_x + gap_width)) > 0)
2974 gdk_draw_line (window, gc4,
2975 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
2976 gdk_draw_line (window, gc3,
2977 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
2978 gdk_draw_line (window, gc3,
2979 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
2983 gdk_draw_line (window, gc1,
2984 x, y, x + width - 1, y);
2985 gdk_draw_line (window, gc2,
2986 x, y + 1, x + width - 2, y + 1);
2988 gdk_draw_line (window, gc3,
2989 x, y + height - 2, x + width - 2, y + height - 2);
2990 gdk_draw_line (window, gc3,
2991 x + width - 2, y + 1, x + width - 2, y + height - 2);
2992 gdk_draw_line (window, gc4,
2993 x, y + height - 1, x + width - 1, y + height - 1);
2994 gdk_draw_line (window, gc4,
2995 x + width - 1, y, x + width - 1, y + height - 1);
2998 gdk_draw_line (window, gc1,
2999 x, y, x, y + gap_x - 1);
3000 gdk_draw_line (window, gc2,
3001 x + 1, y + 1, x + 1, y + gap_x - 1);
3002 gdk_draw_line (window, gc2,
3003 x, y + gap_x, x, y + gap_x);
3005 if ((width - (gap_x + gap_width)) > 0)
3007 gdk_draw_line (window, gc1,
3008 x, y + gap_x + gap_width, x, y + height - 2);
3009 gdk_draw_line (window, gc2,
3010 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
3011 gdk_draw_line (window, gc2,
3012 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
3016 gdk_draw_line (window, gc1,
3017 x, y, x + width - 1, y);
3018 gdk_draw_line (window, gc1,
3019 x, y, x, y + height - 1);
3020 gdk_draw_line (window, gc2,
3021 x + 1, y + 1, x + width - 1, y + 1);
3022 gdk_draw_line (window, gc2,
3023 x + 1, y + 1, x + 1, y + height - 2);
3025 gdk_draw_line (window, gc3,
3026 x + 1, y + height - 2, x + width - 1, y + height - 2);
3027 gdk_draw_line (window, gc4,
3028 x, y + height - 1, x + width - 1, y + height - 1);
3031 gdk_draw_line (window, gc4,
3032 x + width - 1, y, x + width - 1, y + gap_x - 1);
3033 gdk_draw_line (window, gc3,
3034 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
3035 gdk_draw_line (window, gc3,
3036 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
3038 if ((width - (gap_x + gap_width)) > 0)
3040 gdk_draw_line (window, gc4,
3041 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
3042 gdk_draw_line (window, gc3,
3043 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
3044 gdk_draw_line (window, gc3,
3045 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
3053 gdk_gc_set_clip_rectangle (gc1, NULL);
3054 gdk_gc_set_clip_rectangle (gc2, NULL);
3055 gdk_gc_set_clip_rectangle (gc3, NULL);
3056 gdk_gc_set_clip_rectangle (gc4, NULL);
3061 gtk_default_draw_box_gap (GtkStyle *style,
3063 GtkStateType state_type,
3064 GtkShadowType shadow_type,
3067 const gchar *detail,
3072 GtkPositionType gap_side,
3081 g_return_if_fail (GTK_IS_STYLE (style));
3082 g_return_if_fail (window != NULL);
3084 gtk_style_apply_default_background (style, window,
3085 widget && !GTK_WIDGET_NO_WINDOW (widget),
3086 state_type, area, x, y, width, height);
3088 if (width == -1 && height == -1)
3089 gdk_window_get_size (window, &width, &height);
3090 else if (width == -1)
3091 gdk_window_get_size (window, &width, NULL);
3092 else if (height == -1)
3093 gdk_window_get_size (window, NULL, &height);
3095 switch (shadow_type)
3097 case GTK_SHADOW_NONE:
3100 gc1 = style->dark_gc[state_type];
3101 gc2 = style->black_gc;
3102 gc3 = style->bg_gc[state_type];
3103 gc4 = style->light_gc[state_type];
3105 case GTK_SHADOW_ETCHED_IN:
3106 gc1 = style->dark_gc[state_type];
3107 gc2 = style->light_gc[state_type];
3108 gc3 = style->dark_gc[state_type];
3109 gc4 = style->light_gc[state_type];
3111 case GTK_SHADOW_OUT:
3112 gc1 = style->light_gc[state_type];
3113 gc2 = style->bg_gc[state_type];
3114 gc3 = style->dark_gc[state_type];
3115 gc4 = style->black_gc;
3117 case GTK_SHADOW_ETCHED_OUT:
3118 gc1 = style->light_gc[state_type];
3119 gc2 = style->dark_gc[state_type];
3120 gc3 = style->light_gc[state_type];
3121 gc4 = style->dark_gc[state_type];
3127 gdk_gc_set_clip_rectangle (gc1, area);
3128 gdk_gc_set_clip_rectangle (gc2, area);
3129 gdk_gc_set_clip_rectangle (gc3, area);
3130 gdk_gc_set_clip_rectangle (gc4, area);
3133 switch (shadow_type)
3135 case GTK_SHADOW_NONE:
3137 case GTK_SHADOW_OUT:
3138 case GTK_SHADOW_ETCHED_IN:
3139 case GTK_SHADOW_ETCHED_OUT:
3143 gdk_draw_line (window, gc1,
3144 x, y, x, y + height - 1);
3145 gdk_draw_line (window, gc2,
3146 x + 1, y, x + 1, y + height - 2);
3148 gdk_draw_line (window, gc3,
3149 x + 1, y + height - 2, x + width - 2, y + height - 2);
3150 gdk_draw_line (window, gc3,
3151 x + width - 2, y, x + width - 2, y + height - 2);
3152 gdk_draw_line (window, gc4,
3153 x, y + height - 1, x + width - 1, y + height - 1);
3154 gdk_draw_line (window, gc4,
3155 x + width - 1, y, x + width - 1, y + height - 1);
3158 gdk_draw_line (window, gc1,
3159 x, y, x + gap_x - 1, y);
3160 gdk_draw_line (window, gc2,
3161 x + 1, y + 1, x + gap_x - 1, y + 1);
3162 gdk_draw_line (window, gc2,
3163 x + gap_x, y, x + gap_x, y);
3165 if ((width - (gap_x + gap_width)) > 0)
3167 gdk_draw_line (window, gc1,
3168 x + gap_x + gap_width, y, x + width - 2, y);
3169 gdk_draw_line (window, gc2,
3170 x + gap_x + gap_width, y + 1, x + width - 2, y + 1);
3171 gdk_draw_line (window, gc2,
3172 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
3175 case GTK_POS_BOTTOM:
3176 gdk_draw_line (window, gc1,
3177 x, y, x + width - 1, y);
3178 gdk_draw_line (window, gc1,
3179 x, y, x, y + height - 1);
3180 gdk_draw_line (window, gc2,
3181 x + 1, y + 1, x + width - 2, y + 1);
3182 gdk_draw_line (window, gc2,
3183 x + 1, y + 1, x + 1, y + height - 1);
3185 gdk_draw_line (window, gc3,
3186 x + width - 2, y + 1, x + width - 2, y + height - 1);
3187 gdk_draw_line (window, gc4,
3188 x + width - 1, y, x + width - 1, y + height - 1);
3191 gdk_draw_line (window, gc4,
3192 x, y + height - 1, x + gap_x - 1, y + height - 1);
3193 gdk_draw_line (window, gc3,
3194 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
3195 gdk_draw_line (window, gc3,
3196 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
3198 if ((width - (gap_x + gap_width)) > 0)
3200 gdk_draw_line (window, gc4,
3201 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
3202 gdk_draw_line (window, gc3,
3203 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
3204 gdk_draw_line (window, gc3,
3205 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
3209 gdk_draw_line (window, gc1,
3210 x, y, x + width - 1, y);
3211 gdk_draw_line (window, gc2,
3212 x, y + 1, x + width - 2, y + 1);
3214 gdk_draw_line (window, gc3,
3215 x, y + height - 2, x + width - 2, y + height - 2);
3216 gdk_draw_line (window, gc3,
3217 x + width - 2, y + 1, x + width - 2, y + height - 2);
3218 gdk_draw_line (window, gc4,
3219 x, y + height - 1, x + width - 1, y + height - 1);
3220 gdk_draw_line (window, gc4,
3221 x + width - 1, y, x + width - 1, y + height - 1);
3224 gdk_draw_line (window, gc1,
3225 x, y, x, y + gap_x - 1);
3226 gdk_draw_line (window, gc2,
3227 x + 1, y + 1, x + 1, y + gap_x - 1);
3228 gdk_draw_line (window, gc2,
3229 x, y + gap_x, x, y + gap_x);
3231 if ((width - (gap_x + gap_width)) > 0)
3233 gdk_draw_line (window, gc1,
3234 x, y + gap_x + gap_width, x, y + height - 2);
3235 gdk_draw_line (window, gc2,
3236 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
3237 gdk_draw_line (window, gc2,
3238 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
3242 gdk_draw_line (window, gc1,
3243 x, y, x + width - 1, y);
3244 gdk_draw_line (window, gc1,
3245 x, y, x, y + height - 1);
3246 gdk_draw_line (window, gc2,
3247 x + 1, y + 1, x + width - 1, y + 1);
3248 gdk_draw_line (window, gc2,
3249 x + 1, y + 1, x + 1, y + height - 2);
3251 gdk_draw_line (window, gc3,
3252 x + 1, y + height - 2, x + width - 1, y + height - 2);
3253 gdk_draw_line (window, gc4,
3254 x, y + height - 1, x + width - 1, y + height - 1);
3257 gdk_draw_line (window, gc4,
3258 x + width - 1, y, x + width - 1, y + gap_x - 1);
3259 gdk_draw_line (window, gc3,
3260 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
3261 gdk_draw_line (window, gc3,
3262 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
3264 if ((width - (gap_x + gap_width)) > 0)
3266 gdk_draw_line (window, gc4,
3267 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
3268 gdk_draw_line (window, gc3,
3269 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
3270 gdk_draw_line (window, gc3,
3271 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
3279 gdk_gc_set_clip_rectangle (gc1, NULL);
3280 gdk_gc_set_clip_rectangle (gc2, NULL);
3281 gdk_gc_set_clip_rectangle (gc3, NULL);
3282 gdk_gc_set_clip_rectangle (gc4, NULL);
3287 gtk_default_draw_extension (GtkStyle *style,
3289 GtkStateType state_type,
3290 GtkShadowType shadow_type,
3293 const gchar *detail,
3298 GtkPositionType gap_side)
3305 g_return_if_fail (GTK_IS_STYLE (style));
3306 g_return_if_fail (window != NULL);
3308 gtk_style_apply_default_background (style, window,
3309 widget && !GTK_WIDGET_NO_WINDOW (widget),
3310 GTK_STATE_NORMAL, area, x, y, width, height);
3312 if (width == -1 && height == -1)
3313 gdk_window_get_size (window, &width, &height);
3314 else if (width == -1)
3315 gdk_window_get_size (window, &width, NULL);
3316 else if (height == -1)
3317 gdk_window_get_size (window, NULL, &height);
3319 switch (shadow_type)
3321 case GTK_SHADOW_NONE:
3324 gc1 = style->dark_gc[state_type];
3325 gc2 = style->black_gc;
3326 gc3 = style->bg_gc[state_type];
3327 gc4 = style->light_gc[state_type];
3329 case GTK_SHADOW_ETCHED_IN:
3330 gc1 = style->dark_gc[state_type];
3331 gc2 = style->light_gc[state_type];
3332 gc3 = style->dark_gc[state_type];
3333 gc4 = style->light_gc[state_type];
3335 case GTK_SHADOW_OUT:
3336 gc1 = style->light_gc[state_type];
3337 gc2 = style->bg_gc[state_type];
3338 gc3 = style->dark_gc[state_type];
3339 gc4 = style->black_gc;
3341 case GTK_SHADOW_ETCHED_OUT:
3342 gc1 = style->light_gc[state_type];
3343 gc2 = style->dark_gc[state_type];
3344 gc3 = style->light_gc[state_type];
3345 gc4 = style->dark_gc[state_type];
3351 gdk_gc_set_clip_rectangle (gc1, area);
3352 gdk_gc_set_clip_rectangle (gc2, area);
3353 gdk_gc_set_clip_rectangle (gc3, area);
3354 gdk_gc_set_clip_rectangle (gc4, area);
3357 switch (shadow_type)
3359 case GTK_SHADOW_NONE:
3361 case GTK_SHADOW_OUT:
3362 case GTK_SHADOW_ETCHED_IN:
3363 case GTK_SHADOW_ETCHED_OUT:
3367 gtk_style_apply_default_background (style, window,
3368 widget && !GTK_WIDGET_NO_WINDOW (widget),
3370 x + style->xthickness,
3372 width - (2 * style->xthickness),
3373 height - (style->ythickness));
3374 gdk_draw_line (window, gc1,
3375 x, y, x, y + height - 2);
3376 gdk_draw_line (window, gc2,
3377 x + 1, y, x + 1, y + height - 2);
3379 gdk_draw_line (window, gc3,
3380 x + 2, y + height - 2, x + width - 2, y + height - 2);
3381 gdk_draw_line (window, gc3,
3382 x + width - 2, y, x + width - 2, y + height - 2);
3383 gdk_draw_line (window, gc4,
3384 x + 1, y + height - 1, x + width - 2, y + height - 1);
3385 gdk_draw_line (window, gc4,
3386 x + width - 1, y, x + width - 1, y + height - 2);
3388 case GTK_POS_BOTTOM:
3389 gtk_style_apply_default_background (style, window,
3390 widget && !GTK_WIDGET_NO_WINDOW (widget),
3392 x + style->xthickness,
3393 y + style->ythickness,
3394 width - (2 * style->xthickness),
3395 height - (style->ythickness));
3396 gdk_draw_line (window, gc1,
3397 x + 1, y, x + width - 2, y);
3398 gdk_draw_line (window, gc1,
3399 x, y + 1, x, y + height - 1);
3400 gdk_draw_line (window, gc2,
3401 x + 1, y + 1, x + width - 2, y + 1);
3402 gdk_draw_line (window, gc2,
3403 x + 1, y + 1, x + 1, y + height - 1);
3405 gdk_draw_line (window, gc3,
3406 x + width - 2, y + 2, x + width - 2, y + height - 1);
3407 gdk_draw_line (window, gc4,
3408 x + width - 1, y + 1, x + width - 1, y + height - 1);
3411 gtk_style_apply_default_background (style, window,
3412 widget && !GTK_WIDGET_NO_WINDOW (widget),
3415 y + style->ythickness,
3416 width - (style->xthickness),
3417 height - (2 * style->ythickness));
3418 gdk_draw_line (window, gc1,
3419 x, y, x + width - 2, y);
3420 gdk_draw_line (window, gc2,
3421 x + 1, y + 1, x + width - 2, y + 1);
3423 gdk_draw_line (window, gc3,
3424 x, y + height - 2, x + width - 2, y + height - 2);
3425 gdk_draw_line (window, gc3,
3426 x + width - 2, y + 2, x + width - 2, y + height - 2);
3427 gdk_draw_line (window, gc4,
3428 x, y + height - 1, x + width - 2, y + height - 1);
3429 gdk_draw_line (window, gc4,
3430 x + width - 1, y + 1, x + width - 1, y + height - 2);
3433 gtk_style_apply_default_background (style, window,
3434 widget && !GTK_WIDGET_NO_WINDOW (widget),
3436 x + style->xthickness,
3437 y + style->ythickness,
3438 width - (style->xthickness),
3439 height - (2 * style->ythickness));
3440 gdk_draw_line (window, gc1,
3441 x + 1, y, x + width - 1, y);
3442 gdk_draw_line (window, gc1,
3443 x, y + 1, x, y + height - 2);
3444 gdk_draw_line (window, gc2,
3445 x + 1, y + 1, x + width - 1, y + 1);
3446 gdk_draw_line (window, gc2,
3447 x + 1, y + 1, x + 1, y + height - 2);
3449 gdk_draw_line (window, gc3,
3450 x + 2, y + height - 2, x + width - 1, y + height - 2);
3451 gdk_draw_line (window, gc4,
3452 x + 1, y + height - 1, x + width - 1, y + height - 1);
3459 gdk_gc_set_clip_rectangle (gc1, NULL);
3460 gdk_gc_set_clip_rectangle (gc2, NULL);
3461 gdk_gc_set_clip_rectangle (gc3, NULL);
3462 gdk_gc_set_clip_rectangle (gc4, NULL);
3467 gtk_default_draw_focus (GtkStyle *style,
3471 const gchar *detail,
3477 g_return_if_fail (GTK_IS_STYLE (style));
3478 g_return_if_fail (window != NULL);
3480 if (width == -1 && height == -1)
3482 gdk_window_get_size (window, &width, &height);
3486 else if (width == -1)
3488 gdk_window_get_size (window, &width, NULL);
3491 else if (height == -1)
3493 gdk_window_get_size (window, NULL, &height);
3498 gdk_gc_set_clip_rectangle (style->black_gc, area);
3500 if (detail && !strcmp (detail, "add-mode"))
3502 gdk_gc_set_line_attributes (style->black_gc, 1, GDK_LINE_ON_OFF_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);
3511 else if (detail && strcmp (detail, "treeview") == 0)
3514 gdk_gc_set_background (style->black_gc, &style->white);
3515 gdk_gc_set_line_attributes (style->black_gc, 1, GDK_LINE_DOUBLE_DASH, 0, 0);
3516 gdk_gc_set_dashes (style->black_gc, 0, "\4\4", 2);
3518 gdk_draw_rectangle (window,
3519 style->black_gc, FALSE,
3520 x, y, width, height);
3522 gdk_gc_set_line_attributes (style->black_gc, 1, GDK_LINE_SOLID, 0, 0);
3526 gdk_draw_rectangle (window,
3527 style->black_gc, FALSE,
3528 x, y, width, height);
3532 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
3536 gtk_default_draw_slider (GtkStyle *style,
3538 GtkStateType state_type,
3539 GtkShadowType shadow_type,
3542 const gchar *detail,
3547 GtkOrientation orientation)
3549 g_return_if_fail (GTK_IS_STYLE (style));
3550 g_return_if_fail (window != NULL);
3552 if (width == -1 && height == -1)
3553 gdk_window_get_size (window, &width, &height);
3554 else if (width == -1)
3555 gdk_window_get_size (window, &width, NULL);
3556 else if (height == -1)
3557 gdk_window_get_size (window, NULL, &height);
3559 gtk_paint_box (style, window, state_type, shadow_type,
3560 area, widget, detail, x, y, width, height);
3562 if (orientation == GTK_ORIENTATION_HORIZONTAL)
3563 gtk_paint_vline (style, window, state_type, area, widget, detail,
3565 height - style->ythickness - 1, width / 2);
3567 gtk_paint_hline (style, window, state_type, area, widget, detail,
3569 width - style->xthickness - 1, height / 2);
3573 draw_dot (GdkWindow *window,
3581 size = CLAMP (size, 2, 3);
3585 gdk_draw_point (window, light_gc, x, y);
3586 gdk_draw_point (window, light_gc, x+1, y+1);
3588 else if (size == 3);
3590 gdk_draw_point (window, light_gc, x, y);
3591 gdk_draw_point (window, light_gc, x+1, y);
3592 gdk_draw_point (window, light_gc, x, y+1);
3593 gdk_draw_point (window, dark_gc, x+1, y+2);
3594 gdk_draw_point (window, dark_gc, x+2, y+1);
3595 gdk_draw_point (window, dark_gc, x+2, y+2);
3600 gtk_default_draw_handle (GtkStyle *style,
3602 GtkStateType state_type,
3603 GtkShadowType shadow_type,
3606 const gchar *detail,
3611 GtkOrientation orientation)
3614 gint xthick, ythick;
3615 GdkGC *light_gc, *dark_gc;
3620 g_return_if_fail (GTK_IS_STYLE (style));
3621 g_return_if_fail (window != NULL);
3623 if (width == -1 && height == -1)
3624 gdk_window_get_size (window, &width, &height);
3625 else if (width == -1)
3626 gdk_window_get_size (window, &width, NULL);
3627 else if (height == -1)
3628 gdk_window_get_size (window, NULL, &height);
3630 gtk_paint_box (style, window, state_type, shadow_type, area, widget,
3631 detail, x, y, width, height);
3634 if (!strcmp (detail, "paned"))
3636 /* we want to ignore the shadow border in paned widgets */
3640 light_gc = style->light_gc[state_type];
3641 dark_gc = style->black_gc;
3645 xthick = style->xthickness;
3646 ythick = style->ythickness;
3648 light_gc = style->light_gc[state_type];
3649 dark_gc = style->dark_gc[state_type];
3652 rect.x = x + xthick;
3653 rect.y = y + ythick;
3654 rect.width = width - (xthick * 2);
3655 rect.height = height - (ythick * 2);
3658 intersect = gdk_rectangle_intersect (area, &rect, &dest);
3668 gdk_gc_set_clip_rectangle (light_gc, &dest);
3669 gdk_gc_set_clip_rectangle (dark_gc, &dest);
3671 if (!strcmp (detail, "paned"))
3676 gdk_window_get_size (window, &window_width, &window_height);
3678 if (orientation == GTK_ORIENTATION_HORIZONTAL)
3679 for (xx = window_width/2 - 15; xx <= window_width/2 + 15; xx += 5)
3680 draw_dot (window, light_gc, dark_gc, xx, window_height/2 - 1, 3);
3682 for (yy = window_height/2 - 15; yy <= window_height/2 + 15; yy += 5)
3683 draw_dot (window, light_gc, dark_gc, window_width/2 - 1, yy, 3);
3687 for (yy = y + ythick; yy < (y + height - ythick); yy += 3)
3688 for (xx = x + xthick; xx < (x + width - xthick); xx += 6)
3690 draw_dot (window, light_gc, dark_gc, xx, yy, 2);
3691 draw_dot (window, light_gc, dark_gc, xx + 3, yy + 1, 2);
3695 gdk_gc_set_clip_rectangle (light_gc, NULL);
3696 gdk_gc_set_clip_rectangle (dark_gc, NULL);
3700 gtk_default_draw_expander (GtkStyle *style,
3702 GtkStateType state_type,
3705 const gchar *detail,
3710 /* FIXME replace macro with a style property */
3717 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], area);
3718 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], area);
3724 points[0].y = y + (PM_SIZE + 2) / 6;
3725 points[1].x = points[0].x + 1 * (PM_SIZE + 2);
3726 points[1].y = points[0].y;
3727 points[2].x = (points[0].x + 1 * (PM_SIZE + 2) / 2);
3728 points[2].y = y + 2 * (PM_SIZE + 2) / 3;
3732 points[0].x = x + 1 * ((PM_SIZE + 2) / 6 + 2);
3733 points[0].y = y - 1;
3734 points[1].x = points[0].x;
3735 points[1].y = points[0].y + (PM_SIZE + 2);
3736 points[2].x = (points[0].x + 1 * (2 * (PM_SIZE + 2) / 3 - 1));
3737 points[2].y = points[0].y + (PM_SIZE + 2) / 2;
3740 gdk_draw_polygon (window, style->base_gc[GTK_STATE_NORMAL],
3742 gdk_draw_polygon (window, style->fg_gc[GTK_STATE_NORMAL],
3748 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], NULL);
3749 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], NULL);
3755 typedef struct _ByteRange ByteRange;
3764 range_new (guint start,
3767 ByteRange *br = g_new (ByteRange, 1);
3776 get_insensitive_layout (PangoLayout *layout)
3778 GSList *embossed_ranges = NULL;
3779 GSList *stippled_ranges = NULL;
3780 PangoLayoutIter *iter;
3781 GSList *tmp_list = NULL;
3782 PangoLayout *new_layout;
3783 PangoAttrList *attrs;
3784 GdkBitmap *stipple = NULL;
3786 iter = pango_layout_get_iter (layout);
3790 PangoLayoutRun *run;
3791 PangoAttribute *attr;
3792 gboolean need_stipple = FALSE;
3795 run = pango_layout_iter_get_run (iter);
3799 tmp_list = run->item->extra_attrs;
3801 while (tmp_list != NULL)
3803 attr = tmp_list->data;
3804 switch (attr->klass->type)
3806 case PANGO_ATTR_FOREGROUND:
3807 case PANGO_ATTR_BACKGROUND:
3808 need_stipple = TRUE;
3818 tmp_list = g_slist_next (tmp_list);
3821 br = range_new (run->item->offset, run->item->offset + run->item->length);
3824 stippled_ranges = g_slist_prepend (stippled_ranges, br);
3826 embossed_ranges = g_slist_prepend (embossed_ranges, br);
3829 while (pango_layout_iter_next_run (iter));
3831 pango_layout_iter_free (iter);
3833 new_layout = pango_layout_copy (layout);
3835 attrs = pango_layout_get_attributes (new_layout);
3839 /* Create attr list if there wasn't one */
3840 attrs = pango_attr_list_new ();
3841 pango_layout_set_attributes (new_layout, attrs);
3842 pango_attr_list_unref (attrs);
3845 tmp_list = embossed_ranges;
3846 while (tmp_list != NULL)
3848 PangoAttribute *attr;
3849 ByteRange *br = tmp_list->data;
3851 attr = gdk_pango_attr_embossed_new (TRUE);
3853 attr->start_index = br->start;
3854 attr->end_index = br->end;
3856 pango_attr_list_change (attrs, attr);
3860 tmp_list = g_slist_next (tmp_list);
3863 g_slist_free (embossed_ranges);
3865 tmp_list = stippled_ranges;
3866 while (tmp_list != NULL)
3868 PangoAttribute *attr;
3869 ByteRange *br = tmp_list->data;
3871 if (stipple == NULL)
3873 #define gray50_width 2
3874 #define gray50_height 2
3875 static char gray50_bits[] = {
3879 stipple = gdk_bitmap_create_from_data (NULL,
3880 gray50_bits, gray50_width,
3884 attr = gdk_pango_attr_stipple_new (stipple);
3886 attr->start_index = br->start;
3887 attr->end_index = br->end;
3889 pango_attr_list_change (attrs, attr);
3893 tmp_list = g_slist_next (tmp_list);
3896 g_slist_free (stippled_ranges);
3899 g_object_unref (G_OBJECT (stipple));
3905 gtk_default_draw_layout (GtkStyle *style,
3907 GtkStateType state_type,
3911 const gchar *detail,
3914 PangoLayout *layout)
3918 g_return_if_fail (GTK_IS_STYLE (style));
3919 g_return_if_fail (window != NULL);
3921 gc = use_text ? style->text_gc[state_type] : style->fg_gc[state_type];
3924 gdk_gc_set_clip_rectangle (gc, area);
3926 if (state_type == GTK_STATE_INSENSITIVE)
3930 ins = get_insensitive_layout (layout);
3932 gdk_draw_layout (window, gc, x, y, ins);
3934 g_object_unref (G_OBJECT (ins));
3938 gdk_draw_layout (window, gc, x, y, layout);
3942 gdk_gc_set_clip_rectangle (gc, NULL);
3946 gtk_default_draw_resize_grip (GtkStyle *style,
3948 GtkStateType state_type,
3951 const gchar *detail,
3958 g_return_if_fail (GTK_IS_STYLE (style));
3959 g_return_if_fail (window != NULL);
3963 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
3964 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
3967 /* make it square */
3968 if (width != height)
3969 width = height = MIN (width, height);
3973 case GDK_WINDOW_EDGE_SOUTH_EAST:
3980 while (xi < (x + width - 3))
3982 gdk_draw_line (window,
3983 style->light_gc[state_type],
3990 gdk_draw_line (window,
3991 style->dark_gc[state_type],
3998 gdk_draw_line (window,
3999 style->dark_gc[state_type],
4009 g_assert_not_reached ();
4015 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
4016 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
4021 gtk_style_shade (GdkColor *a,
4029 red = (gdouble) a->red / 65535.0;
4030 green = (gdouble) a->green / 65535.0;
4031 blue = (gdouble) a->blue / 65535.0;
4033 rgb_to_hls (&red, &green, &blue);
4038 else if (green < 0.0)
4044 else if (blue < 0.0)
4047 hls_to_rgb (&red, &green, &blue);
4049 b->red = red * 65535.0;
4050 b->green = green * 65535.0;
4051 b->blue = blue * 65535.0;
4055 rgb_to_hls (gdouble *r,
4096 l = (max + min) / 2;
4103 s = (max - min) / (max + min);
4105 s = (max - min) / (2 - max - min);
4109 h = (green - blue) / delta;
4110 else if (green == max)
4111 h = 2 + (blue - red) / delta;
4112 else if (blue == max)
4113 h = 4 + (red - green) / delta;
4126 hls_to_rgb (gdouble *h,
4139 if (lightness <= 0.5)
4140 m2 = lightness * (1 + saturation);
4142 m2 = lightness + saturation - lightness * saturation;
4143 m1 = 2 * lightness - m2;
4145 if (saturation == 0)
4160 r = m1 + (m2 - m1) * hue / 60;
4164 r = m1 + (m2 - m1) * (240 - hue) / 60;
4175 g = m1 + (m2 - m1) * hue / 60;
4179 g = m1 + (m2 - m1) * (240 - hue) / 60;
4190 b = m1 + (m2 - m1) * hue / 60;
4194 b = m1 + (m2 - m1) * (240 - hue) / 60;
4205 gtk_paint_hline (GtkStyle *style,
4207 GtkStateType state_type,
4210 const gchar *detail,
4215 g_return_if_fail (GTK_IS_STYLE (style));
4216 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
4218 GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, area, widget, detail, x1, x2, y);
4222 gtk_paint_vline (GtkStyle *style,
4224 GtkStateType state_type,
4227 const gchar *detail,
4232 g_return_if_fail (GTK_IS_STYLE (style));
4233 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
4235 GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, area, widget, detail, y1, y2, x);
4239 gtk_paint_shadow (GtkStyle *style,
4241 GtkStateType state_type,
4242 GtkShadowType shadow_type,
4245 const gchar *detail,
4251 g_return_if_fail (GTK_IS_STYLE (style));
4252 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
4254 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4258 gtk_paint_polygon (GtkStyle *style,
4260 GtkStateType state_type,
4261 GtkShadowType shadow_type,
4264 const gchar *detail,
4269 g_return_if_fail (GTK_IS_STYLE (style));
4270 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
4272 GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, area, widget, detail, points, npoints, fill);
4276 gtk_paint_arrow (GtkStyle *style,
4278 GtkStateType state_type,
4279 GtkShadowType shadow_type,
4282 const gchar *detail,
4283 GtkArrowType arrow_type,
4290 g_return_if_fail (GTK_IS_STYLE (style));
4291 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
4293 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, area, widget, detail, arrow_type, fill, x, y, width, height);
4297 gtk_paint_diamond (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_diamond != NULL);
4312 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4316 gtk_paint_string (GtkStyle *style,
4318 GtkStateType state_type,
4321 const gchar *detail,
4324 const gchar *string)
4326 g_return_if_fail (GTK_IS_STYLE (style));
4327 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
4329 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, area, widget, detail, x, y, string);
4333 gtk_paint_box (GtkStyle *style,
4335 GtkStateType state_type,
4336 GtkShadowType shadow_type,
4339 const gchar *detail,
4345 g_return_if_fail (GTK_IS_STYLE (style));
4346 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
4348 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4352 gtk_paint_flat_box (GtkStyle *style,
4354 GtkStateType state_type,
4355 GtkShadowType shadow_type,
4358 const gchar *detail,
4364 g_return_if_fail (GTK_IS_STYLE (style));
4365 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
4367 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4371 gtk_paint_check (GtkStyle *style,
4373 GtkStateType state_type,
4374 GtkShadowType shadow_type,
4377 const gchar *detail,
4383 g_return_if_fail (GTK_IS_STYLE (style));
4384 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
4386 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4390 gtk_paint_option (GtkStyle *style,
4392 GtkStateType state_type,
4393 GtkShadowType shadow_type,
4396 const gchar *detail,
4402 g_return_if_fail (GTK_IS_STYLE (style));
4403 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
4405 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4409 gtk_paint_tab (GtkStyle *style,
4411 GtkStateType state_type,
4412 GtkShadowType shadow_type,
4415 const gchar *detail,
4421 g_return_if_fail (GTK_IS_STYLE (style));
4422 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
4424 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4428 gtk_paint_shadow_gap (GtkStyle *style,
4430 GtkStateType state_type,
4431 GtkShadowType shadow_type,
4439 GtkPositionType gap_side,
4443 g_return_if_fail (GTK_IS_STYLE (style));
4444 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
4446 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);
4451 gtk_paint_box_gap (GtkStyle *style,
4453 GtkStateType state_type,
4454 GtkShadowType shadow_type,
4462 GtkPositionType gap_side,
4466 g_return_if_fail (GTK_IS_STYLE (style));
4467 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
4469 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);
4473 gtk_paint_extension (GtkStyle *style,
4475 GtkStateType state_type,
4476 GtkShadowType shadow_type,
4484 GtkPositionType gap_side)
4486 g_return_if_fail (GTK_IS_STYLE (style));
4487 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
4489 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, gap_side);
4493 gtk_paint_focus (GtkStyle *style,
4497 const gchar *detail,
4503 g_return_if_fail (GTK_IS_STYLE (style));
4504 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
4506 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, area, widget, detail, x, y, width, height);
4510 gtk_paint_slider (GtkStyle *style,
4512 GtkStateType state_type,
4513 GtkShadowType shadow_type,
4516 const gchar *detail,
4521 GtkOrientation orientation)
4523 g_return_if_fail (GTK_IS_STYLE (style));
4524 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
4526 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
4530 gtk_paint_handle (GtkStyle *style,
4532 GtkStateType state_type,
4533 GtkShadowType shadow_type,
4536 const gchar *detail,
4541 GtkOrientation orientation)
4543 g_return_if_fail (GTK_IS_STYLE (style));
4544 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
4546 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
4550 gtk_paint_expander (GtkStyle *style,
4552 GtkStateType state_type,
4555 const gchar *detail,
4560 g_return_if_fail (GTK_IS_STYLE (style));
4561 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
4563 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type, area,
4564 widget, detail, x, y, is_open);
4568 gtk_paint_layout (GtkStyle *style,
4570 GtkStateType state_type,
4574 const gchar *detail,
4577 PangoLayout *layout)
4579 g_return_if_fail (GTK_IS_STYLE (style));
4580 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
4582 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, use_text, area,
4583 widget, detail, x, y, layout);
4587 gtk_paint_resize_grip (GtkStyle *style,
4589 GtkStateType state_type,
4592 const gchar *detail,
4600 g_return_if_fail (GTK_IS_STYLE (style));
4601 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
4603 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, window, state_type,
4604 area, widget, detail,
4605 edge, x, y, width, height);
4609 gtk_border_copy (const GtkBorder *border)
4611 return (GtkBorder *)g_memdup (border, sizeof (GtkBorder));
4615 gtk_border_free (GtkBorder *border)