1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
32 #include "gtkwidget.h"
33 #include "gtkthemes.h"
34 #include "gtkiconfactory.h"
36 #define LIGHTNESS_MULT 1.3
37 #define DARKNESS_MULT 0.7
39 /* actually glib should do that for us */
41 #define M_PI 3.14159265358979323846
44 #define M_PI_4 0.78539816339744830962
47 static void gtk_style_realize (GtkStyle *style,
48 GdkColormap *colormap);
50 static void gtk_style_real_realize (GtkStyle *style);
51 static void gtk_style_real_unrealize (GtkStyle *style);
52 static void gtk_style_real_copy (GtkStyle *style,
54 static void gtk_style_real_set_background (GtkStyle *style,
56 GtkStateType state_type);
57 static GtkStyle *gtk_style_real_clone (GtkStyle *style);
58 static void gtk_style_real_init_from_rc (GtkStyle *style,
59 GtkRcStyle *rc_style);
62 static GdkPixbuf *gtk_default_render_icon (GtkStyle *style,
63 const GtkIconSource *source,
64 GtkTextDirection direction,
70 static void gtk_default_draw_hline (GtkStyle *style,
72 GtkStateType state_type,
79 static void gtk_default_draw_vline (GtkStyle *style,
81 GtkStateType state_type,
88 static void gtk_default_draw_shadow (GtkStyle *style,
90 GtkStateType state_type,
91 GtkShadowType shadow_type,
99 static void gtk_default_draw_polygon (GtkStyle *style,
101 GtkStateType state_type,
102 GtkShadowType shadow_type,
109 static void gtk_default_draw_arrow (GtkStyle *style,
111 GtkStateType state_type,
112 GtkShadowType shadow_type,
116 GtkArrowType arrow_type,
122 static void gtk_default_draw_diamond (GtkStyle *style,
124 GtkStateType state_type,
125 GtkShadowType shadow_type,
133 static void gtk_default_draw_string (GtkStyle *style,
135 GtkStateType state_type,
141 const gchar *string);
142 static void gtk_default_draw_box (GtkStyle *style,
144 GtkStateType state_type,
145 GtkShadowType shadow_type,
153 static void gtk_default_draw_flat_box (GtkStyle *style,
155 GtkStateType state_type,
156 GtkShadowType shadow_type,
164 static void gtk_default_draw_check (GtkStyle *style,
166 GtkStateType state_type,
167 GtkShadowType shadow_type,
175 static void gtk_default_draw_option (GtkStyle *style,
177 GtkStateType state_type,
178 GtkShadowType shadow_type,
186 static void gtk_default_draw_tab (GtkStyle *style,
188 GtkStateType state_type,
189 GtkShadowType shadow_type,
197 static void gtk_default_draw_shadow_gap (GtkStyle *style,
199 GtkStateType state_type,
200 GtkShadowType shadow_type,
208 GtkPositionType gap_side,
211 static void gtk_default_draw_box_gap (GtkStyle *style,
213 GtkStateType state_type,
214 GtkShadowType shadow_type,
222 GtkPositionType gap_side,
225 static void gtk_default_draw_extension (GtkStyle *style,
227 GtkStateType state_type,
228 GtkShadowType shadow_type,
236 GtkPositionType gap_side);
237 static void gtk_default_draw_focus (GtkStyle *style,
246 static void gtk_default_draw_slider (GtkStyle *style,
248 GtkStateType state_type,
249 GtkShadowType shadow_type,
257 GtkOrientation orientation);
258 static void gtk_default_draw_handle (GtkStyle *style,
260 GtkStateType state_type,
261 GtkShadowType shadow_type,
269 GtkOrientation orientation);
270 static void gtk_default_draw_expander (GtkStyle *style,
272 GtkStateType state_type,
279 static void gtk_default_draw_layout (GtkStyle *style,
281 GtkStateType state_type,
287 PangoLayout *layout);
289 static void gtk_style_shade (GdkColor *a, GdkColor *b, gdouble k);
290 static void rgb_to_hls (gdouble *r, gdouble *g, gdouble *b);
291 static void hls_to_rgb (gdouble *h, gdouble *l, gdouble *s);
293 GdkFont *default_font = NULL;
295 static GdkColor gtk_default_normal_fg = { 0, 0, 0, 0 };
296 static GdkColor gtk_default_active_fg = { 0, 0, 0, 0 };
297 static GdkColor gtk_default_prelight_fg = { 0, 0, 0, 0 };
298 static GdkColor gtk_default_selected_fg = { 0, 0xffff, 0xffff, 0xffff };
299 static GdkColor gtk_default_insensitive_fg = { 0, 0x7530, 0x7530, 0x7530 };
301 static GdkColor gtk_default_normal_bg = { 0, 0xd6d6, 0xd6d6, 0xd6d6 };
302 static GdkColor gtk_default_active_bg = { 0, 0xc350, 0xc350, 0xc350 };
303 static GdkColor gtk_default_prelight_bg = { 0, 0xea60, 0xea60, 0xea60 };
304 static GdkColor gtk_default_selected_bg = { 0, 0, 0, 0x9c40 };
305 static GdkColor gtk_default_insensitive_bg = { 0, 0xd6d6, 0xd6d6, 0xd6d6 };
307 static gpointer parent_class = NULL;
309 static void gtk_style_init (GtkStyle *style);
310 static void gtk_style_class_init (GtkStyleClass *klass);
311 static void gtk_style_finalize (GObject *object);
314 gtk_style_get_type (void)
316 static GType object_type = 0;
320 static const GTypeInfo object_info =
322 sizeof (GtkStyleClass),
323 (GBaseInitFunc) NULL,
324 (GBaseFinalizeFunc) NULL,
325 (GClassInitFunc) gtk_style_class_init,
326 NULL, /* class_finalize */
327 NULL, /* class_data */
330 (GInstanceInitFunc) gtk_style_init,
333 object_type = g_type_register_static (G_TYPE_OBJECT,
342 gtk_style_init (GtkStyle *style)
346 style->font_desc = pango_font_description_from_string ("Sans 10");
350 default_font = gdk_font_from_description (style->font_desc);
353 default_font = gdk_font_load ("fixed");
356 g_error ("Unable to load \"fixed\" font!");
359 style->font = default_font;
360 gdk_font_ref (style->font);
362 style->attach_count = 0;
363 style->colormap = NULL;
366 style->black.red = 0;
367 style->black.green = 0;
368 style->black.blue = 0;
370 style->white.red = 65535;
371 style->white.green = 65535;
372 style->white.blue = 65535;
374 style->black_gc = NULL;
375 style->white_gc = NULL;
377 style->fg[GTK_STATE_NORMAL] = gtk_default_normal_fg;
378 style->fg[GTK_STATE_ACTIVE] = gtk_default_active_fg;
379 style->fg[GTK_STATE_PRELIGHT] = gtk_default_prelight_fg;
380 style->fg[GTK_STATE_SELECTED] = gtk_default_selected_fg;
381 style->fg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
383 style->bg[GTK_STATE_NORMAL] = gtk_default_normal_bg;
384 style->bg[GTK_STATE_ACTIVE] = gtk_default_active_bg;
385 style->bg[GTK_STATE_PRELIGHT] = gtk_default_prelight_bg;
386 style->bg[GTK_STATE_SELECTED] = gtk_default_selected_bg;
387 style->bg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_bg;
389 for (i = 0; i < 4; i++)
391 style->text[i] = style->fg[i];
392 style->base[i] = style->white;
395 style->base[GTK_STATE_INSENSITIVE] = gtk_default_prelight_bg;
396 style->text[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
398 for (i = 0; i < 5; i++)
399 style->bg_pixmap[i] = NULL;
401 style->rc_style = NULL;
403 for (i = 0; i < 5; i++)
405 style->fg_gc[i] = NULL;
406 style->bg_gc[i] = NULL;
407 style->light_gc[i] = NULL;
408 style->dark_gc[i] = NULL;
409 style->mid_gc[i] = NULL;
410 style->text_gc[i] = NULL;
411 style->base_gc[i] = NULL;
414 style->xthickness = 2;
415 style->ythickness = 2;
419 gtk_style_class_init (GtkStyleClass *klass)
421 GObjectClass *object_class = G_OBJECT_CLASS (klass);
423 parent_class = g_type_class_peek_parent (klass);
425 object_class->finalize = gtk_style_finalize;
427 klass->clone = gtk_style_real_clone;
428 klass->copy = gtk_style_real_copy;
429 klass->init_from_rc = gtk_style_real_init_from_rc;
430 klass->realize = gtk_style_real_realize;
431 klass->unrealize = gtk_style_real_unrealize;
432 klass->set_background = gtk_style_real_set_background;
433 klass->render_icon = gtk_default_render_icon;
435 klass->draw_hline = gtk_default_draw_hline;
436 klass->draw_vline = gtk_default_draw_vline;
437 klass->draw_shadow = gtk_default_draw_shadow;
438 klass->draw_polygon = gtk_default_draw_polygon;
439 klass->draw_arrow = gtk_default_draw_arrow;
440 klass->draw_diamond = gtk_default_draw_diamond;
441 klass->draw_string = gtk_default_draw_string;
442 klass->draw_box = gtk_default_draw_box;
443 klass->draw_flat_box = gtk_default_draw_flat_box;
444 klass->draw_check = gtk_default_draw_check;
445 klass->draw_option = gtk_default_draw_option;
446 klass->draw_tab = gtk_default_draw_tab;
447 klass->draw_shadow_gap = gtk_default_draw_shadow_gap;
448 klass->draw_box_gap = gtk_default_draw_box_gap;
449 klass->draw_extension = gtk_default_draw_extension;
450 klass->draw_focus = gtk_default_draw_focus;
451 klass->draw_slider = gtk_default_draw_slider;
452 klass->draw_handle = gtk_default_draw_handle;
453 klass->draw_expander = gtk_default_draw_expander;
454 klass->draw_layout = gtk_default_draw_layout;
458 gtk_style_finalize (GObject *object)
460 GtkStyle *style = GTK_STYLE (object);
462 g_return_if_fail (style->attach_count == 0);
466 if (style->styles->data != style)
467 g_slist_remove (style->styles, style);
470 GSList *tmp_list = style->styles->next;
474 ((GtkStyle*) tmp_list->data)->styles = style->styles->next;
475 tmp_list = tmp_list->next;
477 g_slist_free_1 (style->styles);
481 gdk_font_unref (style->font);
482 pango_font_description_free (style->font_desc);
485 gtk_rc_style_unref (style->rc_style);
487 G_OBJECT_CLASS (parent_class)->finalize (object);
492 gtk_style_copy (GtkStyle *style)
496 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
498 new_style = GTK_STYLE_GET_CLASS (style)->clone (style);
499 GTK_STYLE_GET_CLASS (style)->copy (new_style, style);
505 gtk_style_duplicate (GtkStyle *style)
509 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
511 new_style = gtk_style_copy (style);
513 style->styles = g_slist_append (style->styles, new_style);
514 new_style->styles = style->styles;
524 style = g_object_new (GTK_TYPE_STYLE, NULL);
529 /*************************************************************
531 * Attach a style to a window; this process allocates the
532 * colors and creates the GC's for the style - it specializes
533 * it to a particular visual and colormap. The process
534 * may involve the creation of a new style if the style
535 * has already been attached to a window with a different
536 * style and colormap.
541 * Either the style parameter, or a newly created style.
542 * If the style is newly created, the style parameter
543 * will be dereferenced, and the new style will have
544 * a reference count belonging to the caller.
546 * FIXME: The sequence -
547 * create a style => s1
548 * attach s1 to v1, c1 => s1
549 * attach s1 to v2, c2 => s2
550 * detach s1 from v1, c1
551 * attach s1 to v2, c2 => s3
552 * results in two separate, unlinked styles s2 and s3 which
553 * are identical and could be shared. To fix this, we would
554 * want to never remove a style from the list of linked
555 * styles as long as as it has a reference count. However, the
556 * disadvantage of doing it this way means that we would need two
557 * passes through the linked list when attaching (one to check for
558 * matching styles, one to look for empty unattached styles - but
559 * it will almost never be longer than 2 elements.
560 *************************************************************/
563 gtk_style_attach (GtkStyle *style,
567 GtkStyle *new_style = NULL;
568 GdkColormap *colormap;
570 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
571 g_return_val_if_fail (window != NULL, NULL);
573 colormap = gdk_window_get_colormap (window);
576 style->styles = g_slist_append (NULL, style);
578 styles = style->styles;
581 new_style = styles->data;
583 if (new_style->attach_count == 0)
585 gtk_style_realize (new_style, colormap);
588 else if (new_style->colormap == colormap)
592 styles = styles->next;
597 new_style = gtk_style_duplicate (style);
598 gtk_style_realize (new_style, colormap);
601 /* A style gets a refcount from being attached */
602 if (new_style->attach_count == 0)
603 gtk_style_ref (new_style);
605 /* Another refcount belongs to the parent */
606 if (style != new_style)
608 gtk_style_unref (style);
609 gtk_style_ref (new_style);
612 new_style->attach_count++;
618 gtk_style_detach (GtkStyle *style)
620 g_return_if_fail (GTK_IS_STYLE (style));
622 style->attach_count -= 1;
623 if (style->attach_count == 0)
625 GTK_STYLE_GET_CLASS (style)->unrealize (style);
627 gdk_colormap_unref (style->colormap);
628 style->colormap = NULL;
630 gtk_style_unref (style);
635 gtk_style_ref (GtkStyle *style)
637 return (GtkStyle *) g_object_ref (G_OBJECT (style));
641 gtk_style_unref (GtkStyle *style)
643 g_object_unref (G_OBJECT (style));
647 gtk_style_realize (GtkStyle *style,
648 GdkColormap *colormap)
650 g_return_if_fail (GTK_IS_STYLE (style));
651 g_return_if_fail (GDK_IS_COLORMAP (colormap));
653 style->colormap = gdk_colormap_ref (colormap);
654 style->depth = gdk_colormap_get_visual (colormap)->depth;
656 GTK_STYLE_GET_CLASS (style)->realize (style);
660 gtk_style_lookup_icon_set (GtkStyle *style,
661 const char *stock_id)
665 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
666 g_return_val_if_fail (stock_id != NULL, NULL);
668 iter = style->icon_factories;
671 GtkIconSet *icon_set =
672 gtk_icon_factory_lookup (GTK_ICON_FACTORY (iter->data),
678 iter = g_slist_next (iter);
681 return gtk_icon_factory_lookup_default (stock_id);
685 gtk_draw_hline (GtkStyle *style,
687 GtkStateType state_type,
692 g_return_if_fail (GTK_IS_STYLE (style));
693 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
695 GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, NULL, NULL, NULL, x1, x2, y);
700 gtk_draw_vline (GtkStyle *style,
702 GtkStateType state_type,
707 g_return_if_fail (GTK_IS_STYLE (style));
708 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
710 GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, NULL, NULL, NULL, y1, y2, x);
715 gtk_draw_shadow (GtkStyle *style,
717 GtkStateType state_type,
718 GtkShadowType shadow_type,
724 g_return_if_fail (GTK_IS_STYLE (style));
725 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
727 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
731 gtk_draw_polygon (GtkStyle *style,
733 GtkStateType state_type,
734 GtkShadowType shadow_type,
739 g_return_if_fail (GTK_IS_STYLE (style));
740 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_polygon != NULL);
742 GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, NULL, NULL, NULL, points, npoints, fill);
746 gtk_draw_arrow (GtkStyle *style,
748 GtkStateType state_type,
749 GtkShadowType shadow_type,
750 GtkArrowType arrow_type,
757 g_return_if_fail (GTK_IS_STYLE (style));
758 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
760 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, NULL, NULL, NULL, arrow_type, fill, x, y, width, height);
765 gtk_draw_diamond (GtkStyle *style,
767 GtkStateType state_type,
768 GtkShadowType shadow_type,
774 g_return_if_fail (GTK_IS_STYLE (style));
775 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
777 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
782 gtk_draw_string (GtkStyle *style,
784 GtkStateType state_type,
789 g_return_if_fail (GTK_IS_STYLE (style));
790 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
792 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, NULL, NULL, NULL, x, y, string);
796 gtk_draw_box (GtkStyle *style,
798 GtkStateType state_type,
799 GtkShadowType shadow_type,
805 g_return_if_fail (GTK_IS_STYLE (style));
806 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
808 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
812 gtk_draw_flat_box (GtkStyle *style,
814 GtkStateType state_type,
815 GtkShadowType shadow_type,
821 g_return_if_fail (GTK_IS_STYLE (style));
822 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
824 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
828 gtk_draw_check (GtkStyle *style,
830 GtkStateType state_type,
831 GtkShadowType shadow_type,
837 g_return_if_fail (GTK_IS_STYLE (style));
838 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
840 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
844 gtk_draw_option (GtkStyle *style,
846 GtkStateType state_type,
847 GtkShadowType shadow_type,
853 g_return_if_fail (GTK_IS_STYLE (style));
854 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
856 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
860 gtk_draw_tab (GtkStyle *style,
862 GtkStateType state_type,
863 GtkShadowType shadow_type,
869 g_return_if_fail (GTK_IS_STYLE (style));
870 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
872 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
876 gtk_draw_shadow_gap (GtkStyle *style,
878 GtkStateType state_type,
879 GtkShadowType shadow_type,
884 GtkPositionType gap_side,
888 g_return_if_fail (GTK_IS_STYLE (style));
889 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
891 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);
895 gtk_draw_box_gap (GtkStyle *style,
897 GtkStateType state_type,
898 GtkShadowType shadow_type,
903 GtkPositionType gap_side,
907 g_return_if_fail (GTK_IS_STYLE (style));
908 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
910 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);
914 gtk_draw_extension (GtkStyle *style,
916 GtkStateType state_type,
917 GtkShadowType shadow_type,
922 GtkPositionType gap_side)
924 g_return_if_fail (GTK_IS_STYLE (style));
925 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
927 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, gap_side);
931 gtk_draw_focus (GtkStyle *style,
938 g_return_if_fail (GTK_IS_STYLE (style));
939 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
941 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, NULL, NULL, NULL, x, y, width, height);
945 gtk_draw_slider (GtkStyle *style,
947 GtkStateType state_type,
948 GtkShadowType shadow_type,
953 GtkOrientation orientation)
955 g_return_if_fail (GTK_IS_STYLE (style));
956 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
958 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
962 gtk_draw_handle (GtkStyle *style,
964 GtkStateType state_type,
965 GtkShadowType shadow_type,
970 GtkOrientation orientation)
972 g_return_if_fail (GTK_IS_STYLE (style));
973 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
975 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
979 gtk_draw_expander (GtkStyle *style,
981 GtkStateType state_type,
986 g_return_if_fail (GTK_IS_STYLE (style));
987 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
989 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type,
995 gtk_draw_layout (GtkStyle *style,
997 GtkStateType state_type,
1000 PangoLayout *layout)
1002 g_return_if_fail (GTK_IS_STYLE (style));
1003 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
1005 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type,
1011 gtk_style_set_background (GtkStyle *style,
1013 GtkStateType state_type)
1015 g_return_if_fail (GTK_IS_STYLE (style));
1016 g_return_if_fail (window != NULL);
1018 GTK_STYLE_GET_CLASS (style)->set_background (style, window, state_type);
1021 /* Default functions */
1023 gtk_style_real_clone (GtkStyle *style)
1025 return GTK_STYLE (g_object_new (G_OBJECT_TYPE (style), NULL));
1029 gtk_style_real_copy (GtkStyle *style,
1034 for (i = 0; i < 5; i++)
1036 style->fg[i] = src->fg[i];
1037 style->bg[i] = src->bg[i];
1038 style->text[i] = src->text[i];
1039 style->base[i] = src->base[i];
1041 style->bg_pixmap[i] = src->bg_pixmap[i];
1045 gdk_font_unref (style->font);
1046 style->font = src->font;
1048 gdk_font_ref (style->font);
1050 if (style->font_desc)
1051 pango_font_description_free (style->font_desc);
1053 style->font_desc = pango_font_description_copy (src->font_desc);
1055 style->font_desc = NULL;
1057 style->xthickness = src->xthickness;
1058 style->ythickness = src->ythickness;
1060 if (style->rc_style)
1061 gtk_rc_style_unref (style->rc_style);
1062 style->rc_style = src->rc_style;
1064 gtk_rc_style_ref (src->rc_style);
1068 gtk_style_real_init_from_rc (GtkStyle *style,
1069 GtkRcStyle *rc_style)
1074 if (rc_style->font_desc)
1076 pango_font_description_free (style->font_desc);
1077 style->font_desc = pango_font_description_copy (rc_style->font_desc);
1079 old_font = style->font;
1080 style->font = gdk_font_from_description (style->font_desc);
1082 gdk_font_unref (old_font);
1084 style->font = old_font;
1087 for (i = 0; i < 5; i++)
1089 if (rc_style->color_flags[i] & GTK_RC_FG)
1090 style->fg[i] = rc_style->fg[i];
1091 if (rc_style->color_flags[i] & GTK_RC_BG)
1092 style->bg[i] = rc_style->bg[i];
1093 if (rc_style->color_flags[i] & GTK_RC_TEXT)
1094 style->text[i] = rc_style->text[i];
1095 if (rc_style->color_flags[i] & GTK_RC_BASE)
1096 style->base[i] = rc_style->base[i];
1099 if (rc_style->xthickness >= 0)
1100 style->xthickness = rc_style->xthickness;
1101 if (rc_style->ythickness >= 0)
1102 style->ythickness = rc_style->ythickness;
1105 if (rc_style->icon_factories)
1109 style->icon_factories = g_slist_copy (rc_style->icon_factories);
1111 iter = style->icon_factories;
1112 while (iter != NULL)
1114 g_object_ref (G_OBJECT (iter->data));
1116 iter = g_slist_next (iter);
1122 gtk_style_real_realize (GtkStyle *style)
1124 GdkGCValues gc_values;
1125 GdkGCValuesMask gc_values_mask;
1129 for (i = 0; i < 5; i++)
1131 gtk_style_shade (&style->bg[i], &style->light[i], LIGHTNESS_MULT);
1132 gtk_style_shade (&style->bg[i], &style->dark[i], DARKNESS_MULT);
1134 style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
1135 style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
1136 style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
1139 gdk_color_black (style->colormap, &style->black);
1140 gdk_color_white (style->colormap, &style->white);
1142 gc_values_mask = GDK_GC_FOREGROUND | GDK_GC_FONT;
1143 if (style->font->type == GDK_FONT_FONT)
1145 gc_values.font = style->font;
1147 else if (style->font->type == GDK_FONT_FONTSET)
1149 gc_values.font = default_font;
1152 gc_values.foreground = style->black;
1153 style->black_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1155 gc_values.foreground = style->white;
1156 style->white_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1158 for (i = 0; i < 5; i++)
1160 if (style->rc_style && style->rc_style->bg_pixmap_name[i])
1161 style->bg_pixmap[i] = gtk_rc_load_image (style->colormap,
1163 style->rc_style->bg_pixmap_name[i]);
1165 if (!gdk_color_alloc (style->colormap, &style->fg[i]))
1166 g_warning ("unable to allocate color: ( %d %d %d )",
1167 style->fg[i].red, style->fg[i].green, style->fg[i].blue);
1168 if (!gdk_color_alloc (style->colormap, &style->bg[i]))
1169 g_warning ("unable to allocate color: ( %d %d %d )",
1170 style->bg[i].red, style->bg[i].green, style->bg[i].blue);
1171 if (!gdk_color_alloc (style->colormap, &style->light[i]))
1172 g_warning ("unable to allocate color: ( %d %d %d )",
1173 style->light[i].red, style->light[i].green, style->light[i].blue);
1174 if (!gdk_color_alloc (style->colormap, &style->dark[i]))
1175 g_warning ("unable to allocate color: ( %d %d %d )",
1176 style->dark[i].red, style->dark[i].green, style->dark[i].blue);
1177 if (!gdk_color_alloc (style->colormap, &style->mid[i]))
1178 g_warning ("unable to allocate color: ( %d %d %d )",
1179 style->mid[i].red, style->mid[i].green, style->mid[i].blue);
1180 if (!gdk_color_alloc (style->colormap, &style->text[i]))
1181 g_warning ("unable to allocate color: ( %d %d %d )",
1182 style->text[i].red, style->text[i].green, style->text[i].blue);
1183 if (!gdk_color_alloc (style->colormap, &style->base[i]))
1184 g_warning ("unable to allocate color: ( %d %d %d )",
1185 style->base[i].red, style->base[i].green, style->base[i].blue);
1187 gc_values.foreground = style->fg[i];
1188 style->fg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1190 gc_values.foreground = style->bg[i];
1191 style->bg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1193 gc_values.foreground = style->light[i];
1194 style->light_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1196 gc_values.foreground = style->dark[i];
1197 style->dark_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1199 gc_values.foreground = style->mid[i];
1200 style->mid_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1202 gc_values.foreground = style->text[i];
1203 style->text_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1205 gc_values.foreground = style->base[i];
1206 style->base_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1211 gtk_style_real_unrealize (GtkStyle *style)
1215 gtk_gc_release (style->black_gc);
1216 gtk_gc_release (style->white_gc);
1218 for (i = 0; i < 5; i++)
1220 gtk_gc_release (style->fg_gc[i]);
1221 gtk_gc_release (style->bg_gc[i]);
1222 gtk_gc_release (style->light_gc[i]);
1223 gtk_gc_release (style->dark_gc[i]);
1224 gtk_gc_release (style->mid_gc[i]);
1225 gtk_gc_release (style->text_gc[i]);
1226 gtk_gc_release (style->base_gc[i]);
1228 if (style->bg_pixmap[i] && style->bg_pixmap[i] != (GdkPixmap*) GDK_PARENT_RELATIVE)
1229 gdk_pixmap_unref (style->bg_pixmap[i]);
1232 gdk_colormap_free_colors (style->colormap, style->fg, 5);
1233 gdk_colormap_free_colors (style->colormap, style->bg, 5);
1234 gdk_colormap_free_colors (style->colormap, style->light, 5);
1235 gdk_colormap_free_colors (style->colormap, style->dark, 5);
1236 gdk_colormap_free_colors (style->colormap, style->mid, 5);
1237 gdk_colormap_free_colors (style->colormap, style->text, 5);
1238 gdk_colormap_free_colors (style->colormap, style->base, 5);
1242 gtk_style_real_set_background (GtkStyle *style,
1244 GtkStateType state_type)
1247 gint parent_relative;
1249 if (style->bg_pixmap[state_type])
1251 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1254 parent_relative = TRUE;
1258 pixmap = style->bg_pixmap[state_type];
1259 parent_relative = FALSE;
1262 gdk_window_set_back_pixmap (window, pixmap, parent_relative);
1265 gdk_window_set_background (window, &style->bg[state_type]);
1269 gtk_style_render_icon (GtkStyle *style,
1270 const GtkIconSource *source,
1271 GtkTextDirection direction,
1275 const gchar *detail)
1279 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1280 g_return_val_if_fail (GTK_STYLE_GET_CLASS (style)->render_icon != NULL, NULL);
1282 pixbuf = GTK_STYLE_GET_CLASS (style)->render_icon (style, source, direction, state,
1283 size, widget, detail);
1285 g_return_val_if_fail (pixbuf != NULL, NULL);
1290 /* Default functions */
1292 gtk_style_apply_default_background (GtkStyle *style,
1295 GtkStateType state_type,
1302 GdkRectangle new_rect, old_rect;
1308 old_rect.width = width;
1309 old_rect.height = height;
1311 if (!gdk_rectangle_intersect (area, &old_rect, &new_rect))
1318 new_rect.width = width;
1319 new_rect.height = height;
1322 if (!style->bg_pixmap[state_type] ||
1323 GDK_IS_PIXMAP (window) ||
1324 (!set_bg && style->bg_pixmap[state_type] != (GdkPixmap*) GDK_PARENT_RELATIVE))
1326 GdkGC *gc = style->bg_gc[state_type];
1328 if (style->bg_pixmap[state_type])
1330 gdk_gc_set_fill (gc, GDK_TILED);
1331 gdk_gc_set_tile (gc, style->bg_pixmap[state_type]);
1334 gdk_draw_rectangle (window, gc, TRUE,
1335 new_rect.x, new_rect.y, new_rect.width, new_rect.height);
1336 if (style->bg_pixmap[state_type])
1337 gdk_gc_set_fill (gc, GDK_SOLID);
1343 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1344 gdk_window_set_back_pixmap (window, NULL, TRUE);
1346 gdk_window_set_back_pixmap (window, style->bg_pixmap[state_type], FALSE);
1349 gdk_window_clear_area (window,
1350 new_rect.x, new_rect.y,
1351 new_rect.width, new_rect.height);
1356 scale_or_ref (GdkPixbuf *src,
1360 if (width == gdk_pixbuf_get_width (src) &&
1361 height == gdk_pixbuf_get_height (src))
1363 gdk_pixbuf_ref (src);
1368 return gdk_pixbuf_scale_simple (src,
1370 GDK_INTERP_BILINEAR);
1375 gtk_default_render_icon (GtkStyle *style,
1376 const GtkIconSource *source,
1377 GtkTextDirection direction,
1381 const gchar *detail)
1388 /* Oddly, style can be NULL in this function, because
1389 * GtkIconSet can be used without a style and if so
1390 * it uses this function.
1393 g_return_val_if_fail (source->pixbuf != NULL, NULL);
1395 if (!gtk_icon_size_lookup (size, &width, &height))
1397 g_warning ("Bad icon size '%s' passed to render_icon", size);
1401 /* If the size was wildcarded, then scale; otherwise, leave it
1404 if (source->any_size)
1405 scaled = scale_or_ref (source->pixbuf, width, height);
1407 scaled = GDK_PIXBUF (g_object_ref (G_OBJECT (source->pixbuf)));
1409 /* If the state was wildcarded, then generate a state. */
1410 if (source->any_state)
1412 if (state == GTK_STATE_INSENSITIVE)
1414 stated = gdk_pixbuf_copy (scaled);
1416 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
1419 gdk_pixbuf_unref (scaled);
1421 else if (state == GTK_STATE_PRELIGHT)
1423 stated = gdk_pixbuf_copy (scaled);
1425 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
1428 gdk_pixbuf_unref (scaled);
1442 gtk_default_draw_hline (GtkStyle *style,
1444 GtkStateType state_type,
1447 const gchar *detail,
1452 gint thickness_light;
1453 gint thickness_dark;
1456 g_return_if_fail (GTK_IS_STYLE (style));
1457 g_return_if_fail (window != NULL);
1459 thickness_light = style->ythickness / 2;
1460 thickness_dark = style->ythickness - thickness_light;
1464 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
1465 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
1468 if (detail && !strcmp (detail, "label"))
1470 if (state_type == GTK_STATE_INSENSITIVE)
1471 gdk_draw_line (window, style->white_gc, x1 + 1, y + 1, x2 + 1, y + 1);
1472 gdk_draw_line (window, style->fg_gc[state_type], x1, y, x2, y);
1476 for (i = 0; i < thickness_dark; i++)
1478 gdk_draw_line (window, style->light_gc[state_type], x2 - i - 1, y + i, x2, y + i);
1479 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x2 - i - 1, y + i);
1482 y += thickness_dark;
1483 for (i = 0; i < thickness_light; i++)
1485 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x1 + thickness_light - i - 1, y + i);
1486 gdk_draw_line (window, style->light_gc[state_type], x1 + thickness_light - i - 1, y + i, x2, y + i);
1492 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
1493 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
1499 gtk_default_draw_vline (GtkStyle *style,
1501 GtkStateType state_type,
1504 const gchar *detail,
1509 gint thickness_light;
1510 gint thickness_dark;
1513 g_return_if_fail (GTK_IS_STYLE (style));
1514 g_return_if_fail (window != NULL);
1516 thickness_light = style->xthickness / 2;
1517 thickness_dark = style->xthickness - thickness_light;
1521 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
1522 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
1524 for (i = 0; i < thickness_dark; i++)
1526 gdk_draw_line (window, style->light_gc[state_type], x + i, y2 - i - 1, x + i, y2);
1527 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y2 - i - 1);
1530 x += thickness_dark;
1531 for (i = 0; i < thickness_light; i++)
1533 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y1 + thickness_light - i);
1534 gdk_draw_line (window, style->light_gc[state_type], x + i, y1 + thickness_light - i, x + i, y2);
1538 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
1539 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
1545 gtk_default_draw_shadow (GtkStyle *style,
1547 GtkStateType state_type,
1548 GtkShadowType shadow_type,
1551 const gchar *detail,
1559 gint thickness_light;
1560 gint thickness_dark;
1563 g_return_if_fail (GTK_IS_STYLE (style));
1564 g_return_if_fail (window != NULL);
1566 if ((width == -1) && (height == -1))
1567 gdk_window_get_size (window, &width, &height);
1568 else if (width == -1)
1569 gdk_window_get_size (window, &width, NULL);
1570 else if (height == -1)
1571 gdk_window_get_size (window, NULL, &height);
1573 switch (shadow_type)
1575 case GTK_SHADOW_NONE:
1578 case GTK_SHADOW_ETCHED_IN:
1579 gc1 = style->light_gc[state_type];
1580 gc2 = style->dark_gc[state_type];
1582 case GTK_SHADOW_OUT:
1583 case GTK_SHADOW_ETCHED_OUT:
1584 gc1 = style->dark_gc[state_type];
1585 gc2 = style->light_gc[state_type];
1591 gdk_gc_set_clip_rectangle (gc1, area);
1592 gdk_gc_set_clip_rectangle (gc2, area);
1593 if (shadow_type == GTK_SHADOW_IN ||
1594 shadow_type == GTK_SHADOW_OUT)
1596 gdk_gc_set_clip_rectangle (style->black_gc, area);
1597 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
1601 switch (shadow_type)
1603 case GTK_SHADOW_NONE:
1607 gdk_draw_line (window, gc1,
1608 x, y + height - 1, x + width - 1, y + height - 1);
1609 gdk_draw_line (window, gc1,
1610 x + width - 1, y, x + width - 1, y + height - 1);
1612 gdk_draw_line (window, style->bg_gc[state_type],
1613 x + 1, y + height - 2, x + width - 2, y + height - 2);
1614 gdk_draw_line (window, style->bg_gc[state_type],
1615 x + width - 2, y + 1, x + width - 2, y + height - 2);
1617 gdk_draw_line (window, style->black_gc,
1618 x + 1, y + 1, x + width - 2, y + 1);
1619 gdk_draw_line (window, style->black_gc,
1620 x + 1, y + 1, x + 1, y + height - 2);
1622 gdk_draw_line (window, gc2,
1623 x, y, x + width - 1, y);
1624 gdk_draw_line (window, gc2,
1625 x, y, x, y + height - 1);
1628 case GTK_SHADOW_OUT:
1629 gdk_draw_line (window, gc1,
1630 x + 1, y + height - 2, x + width - 2, y + height - 2);
1631 gdk_draw_line (window, gc1,
1632 x + width - 2, y + 1, x + width - 2, y + height - 2);
1634 gdk_draw_line (window, gc2,
1635 x, y, x + width - 1, y);
1636 gdk_draw_line (window, gc2,
1637 x, y, x, y + height - 1);
1639 gdk_draw_line (window, style->bg_gc[state_type],
1640 x + 1, y + 1, x + width - 2, y + 1);
1641 gdk_draw_line (window, style->bg_gc[state_type],
1642 x + 1, y + 1, x + 1, y + height - 2);
1644 gdk_draw_line (window, style->black_gc,
1645 x, y + height - 1, x + width - 1, y + height - 1);
1646 gdk_draw_line (window, style->black_gc,
1647 x + width - 1, y, x + width - 1, y + height - 1);
1650 case GTK_SHADOW_ETCHED_IN:
1651 case GTK_SHADOW_ETCHED_OUT:
1652 thickness_light = 1;
1655 for (i = 0; i < thickness_dark; i++)
1657 gdk_draw_line (window, gc1,
1661 y + height - i - 1);
1662 gdk_draw_line (window, gc1,
1666 y + height - i - 1);
1668 gdk_draw_line (window, gc2,
1673 gdk_draw_line (window, gc2,
1677 y + height - i - 2);
1680 for (i = 0; i < thickness_light; i++)
1682 gdk_draw_line (window, gc1,
1683 x + thickness_dark + i,
1684 y + thickness_dark + i,
1685 x + width - thickness_dark - i - 1,
1686 y + thickness_dark + i);
1687 gdk_draw_line (window, gc1,
1688 x + thickness_dark + i,
1689 y + thickness_dark + i,
1690 x + thickness_dark + i,
1691 y + height - thickness_dark - i - 1);
1693 gdk_draw_line (window, gc2,
1694 x + thickness_dark + i,
1695 y + height - thickness_light - i - 1,
1696 x + width - thickness_light - 1,
1697 y + height - thickness_light - i - 1);
1698 gdk_draw_line (window, gc2,
1699 x + width - thickness_light - i - 1,
1700 y + thickness_dark + i,
1701 x + width - thickness_light - i - 1,
1702 y + height - thickness_light - 1);
1708 gdk_gc_set_clip_rectangle (gc1, NULL);
1709 gdk_gc_set_clip_rectangle (gc2, NULL);
1710 if (shadow_type == GTK_SHADOW_IN ||
1711 shadow_type == GTK_SHADOW_OUT)
1713 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
1714 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
1720 gtk_default_draw_polygon (GtkStyle *style,
1722 GtkStateType state_type,
1723 GtkShadowType shadow_type,
1726 const gchar *detail,
1731 static const gdouble pi_over_4 = M_PI_4;
1732 static const gdouble pi_3_over_4 = M_PI_4 * 3;
1742 g_return_if_fail (GTK_IS_STYLE (style));
1743 g_return_if_fail (window != NULL);
1744 g_return_if_fail (points != NULL);
1746 switch (shadow_type)
1749 gc1 = style->bg_gc[state_type];
1750 gc2 = style->dark_gc[state_type];
1751 gc3 = style->light_gc[state_type];
1752 gc4 = style->black_gc;
1754 case GTK_SHADOW_ETCHED_IN:
1755 gc1 = style->light_gc[state_type];
1756 gc2 = style->dark_gc[state_type];
1757 gc3 = style->dark_gc[state_type];
1758 gc4 = style->light_gc[state_type];
1760 case GTK_SHADOW_OUT:
1761 gc1 = style->dark_gc[state_type];
1762 gc2 = style->light_gc[state_type];
1763 gc3 = style->black_gc;
1764 gc4 = style->bg_gc[state_type];
1766 case GTK_SHADOW_ETCHED_OUT:
1767 gc1 = style->dark_gc[state_type];
1768 gc2 = style->light_gc[state_type];
1769 gc3 = style->light_gc[state_type];
1770 gc4 = style->dark_gc[state_type];
1778 gdk_gc_set_clip_rectangle (gc1, area);
1779 gdk_gc_set_clip_rectangle (gc2, area);
1780 gdk_gc_set_clip_rectangle (gc3, area);
1781 gdk_gc_set_clip_rectangle (gc4, area);
1785 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, npoints);
1789 for (i = 0; i < npoints; i++)
1791 if ((points[i].x == points[i+1].x) &&
1792 (points[i].y == points[i+1].y))
1798 angle = atan2 (points[i+1].y - points[i].y,
1799 points[i+1].x - points[i].x);
1802 if ((angle > -pi_3_over_4) && (angle < pi_over_4))
1804 if (angle > -pi_over_4)
1815 gdk_draw_line (window, gc1,
1816 points[i].x-xadjust, points[i].y-yadjust,
1817 points[i+1].x-xadjust, points[i+1].y-yadjust);
1818 gdk_draw_line (window, gc3,
1819 points[i].x, points[i].y,
1820 points[i+1].x, points[i+1].y);
1824 if ((angle < -pi_3_over_4) || (angle > pi_3_over_4))
1835 gdk_draw_line (window, gc4,
1836 points[i].x+xadjust, points[i].y+yadjust,
1837 points[i+1].x+xadjust, points[i+1].y+yadjust);
1838 gdk_draw_line (window, gc2,
1839 points[i].x, points[i].y,
1840 points[i+1].x, points[i+1].y);
1846 gdk_gc_set_clip_rectangle (gc1, NULL);
1847 gdk_gc_set_clip_rectangle (gc2, NULL);
1848 gdk_gc_set_clip_rectangle (gc3, NULL);
1849 gdk_gc_set_clip_rectangle (gc4, NULL);
1854 gtk_default_draw_arrow (GtkStyle *style,
1856 GtkStateType state_type,
1857 GtkShadowType shadow_type,
1860 const gchar *detail,
1861 GtkArrowType arrow_type,
1876 g_return_if_fail (GTK_IS_STYLE (style));
1877 g_return_if_fail (window != NULL);
1879 switch (shadow_type)
1882 gc1 = style->bg_gc[state_type];
1883 gc2 = style->dark_gc[state_type];
1884 gc3 = style->light_gc[state_type];
1885 gc4 = style->black_gc;
1887 case GTK_SHADOW_OUT:
1888 gc1 = style->dark_gc[state_type];
1889 gc2 = style->light_gc[state_type];
1890 gc3 = style->black_gc;
1891 gc4 = style->bg_gc[state_type];
1893 case GTK_SHADOW_ETCHED_IN:
1894 gc1 = style->light_gc[state_type];
1895 gc2 = style->dark_gc[state_type];
1899 case GTK_SHADOW_ETCHED_OUT:
1900 gc1 = style->dark_gc[state_type];
1901 gc2 = style->light_gc[state_type];
1909 if ((width == -1) && (height == -1))
1910 gdk_window_get_size (window, &width, &height);
1911 else if (width == -1)
1912 gdk_window_get_size (window, &width, NULL);
1913 else if (height == -1)
1914 gdk_window_get_size (window, NULL, &height);
1916 half_width = width / 2;
1917 half_height = height / 2;
1921 gdk_gc_set_clip_rectangle (gc1, area);
1922 gdk_gc_set_clip_rectangle (gc2, area);
1925 gdk_gc_set_clip_rectangle (gc3, area);
1926 gdk_gc_set_clip_rectangle (gc4, area);
1935 points[0].x = x + half_width;
1938 points[1].y = y + height - 1;
1939 points[2].x = x + width - 1;
1940 points[2].y = y + height - 1;
1942 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
1945 switch (shadow_type)
1948 case GTK_SHADOW_OUT:
1950 gdk_draw_line (window, gc1,
1951 x + 1, y + height - 2,
1952 x + width - 2, y + height - 2);
1953 gdk_draw_line (window, gc3,
1954 x + 0, y + height - 1,
1955 x + width - 1, y + height - 1);
1957 gdk_draw_line (window, gc1,
1958 x + width - 2, y + height - 1,
1959 x + half_width, y + 1);
1960 gdk_draw_line (window, gc3,
1961 x + width - 1, y + height - 1,
1964 gdk_draw_line (window, gc4,
1965 x + half_width, y + 1,
1966 x + 1, y + height - 1);
1967 gdk_draw_line (window, gc2,
1972 case GTK_SHADOW_ETCHED_IN:
1973 case GTK_SHADOW_ETCHED_OUT:
1974 gdk_draw_line (window, gc1,
1975 x + half_width, y + 1,
1976 x + 1, y + height - 1);
1977 gdk_draw_line (window, gc1,
1978 x + 1, y + height - 1,
1979 x + width - 1, y + height - 1);
1980 gdk_draw_line (window, gc1,
1981 x + width - 1, y + height - 1,
1982 x + half_width + 1, y + 1);
1984 points[0].x = x + half_width;
1987 points[1].y = y + height - 2;
1988 points[2].x = x + width - 2;
1989 points[2].y = y + height - 2;
1991 gdk_draw_polygon (window, gc2, FALSE, points, 3);
1999 case GTK_ARROW_DOWN:
2002 points[0].x = x + width - 1;
2006 points[2].x = x + half_width;
2007 points[2].y = y + height - 1;
2009 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
2011 switch (shadow_type)
2014 case GTK_SHADOW_OUT:
2015 gdk_draw_line (window, gc4,
2017 y + 1, x + 1, y + 1);
2018 gdk_draw_line (window, gc2,
2022 gdk_draw_line (window, gc4,
2024 x + half_width, y + height - 2);
2025 gdk_draw_line (window, gc2,
2027 x + half_width, y + height - 1);
2029 gdk_draw_line (window, gc1,
2030 x + half_width, y + height - 2,
2032 gdk_draw_line (window, gc3,
2033 x + half_width, y + height - 1,
2037 case GTK_SHADOW_ETCHED_IN:
2038 case GTK_SHADOW_ETCHED_OUT:
2039 gdk_draw_line (window, gc1,
2040 x + width - 1, y + 1,
2042 gdk_draw_line (window, gc1,
2044 x + half_width + 1, y + height - 1);
2045 gdk_draw_line (window, gc1,
2046 x + half_width + 1, y + height - 2,
2049 points[0].x = x + width - 2;
2053 points[2].x = x + half_width;
2054 points[2].y = y + height - 2;
2056 gdk_draw_polygon (window, gc2, FALSE, points, 3);
2063 case GTK_ARROW_LEFT:
2067 points[0].y = y + half_height;
2068 points[1].x = x + width - 1;
2069 points[1].y = y + height - 1;
2070 points[2].x = x + width - 1;
2073 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
2076 switch (shadow_type)
2079 case GTK_SHADOW_OUT:
2080 gdk_draw_line (window, gc1,
2081 x + 1, y + half_height,
2082 x + width - 1, y + height - 1);
2083 gdk_draw_line (window, gc3,
2085 x + width - 1, y + height - 1);
2087 gdk_draw_line (window, gc1,
2088 x + width - 2, y + height - 1,
2089 x + width - 2, y + 1);
2090 gdk_draw_line (window, gc3,
2091 x + width - 1, y + height - 1,
2094 gdk_draw_line (window, gc4,
2095 x + width - 1, y + 1,
2096 x + 1, y + half_height);
2097 gdk_draw_line (window, gc2,
2099 x, y + half_height);
2102 case GTK_SHADOW_ETCHED_IN:
2103 case GTK_SHADOW_ETCHED_OUT:
2104 gdk_draw_line (window, gc1,
2105 x + width - 1, y + 1,
2106 x + 1, y + half_height);
2107 gdk_draw_line (window, gc1,
2108 x + 1, y + half_height + 1,
2109 x + width - 1, y + height - 1);
2110 gdk_draw_line (window, gc1,
2111 x + width - 1, y + height - 1,
2112 x + width - 1, y + 1);
2114 points[0].x = x + width - 2;
2117 points[1].y = y + half_height;
2118 points[2].x = x + width - 2;
2119 points[2].y = y + height - 2;
2121 gdk_draw_polygon (window, gc2, FALSE, points, 3);
2128 case GTK_ARROW_RIGHT:
2131 points[0].x = x + width - 1;
2132 points[0].y = y + half_height;
2136 points[2].y = y + height - 1;
2138 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
2141 switch (shadow_type)
2144 case GTK_SHADOW_OUT:
2145 gdk_draw_line (window, gc4,
2146 x + width - 1, y + half_height,
2148 gdk_draw_line (window, gc2,
2149 x + width - 1, y + half_height,
2151 gdk_draw_line (window, gc4,
2153 x + 1, y + height - 2);
2154 gdk_draw_line (window, gc2,
2158 gdk_draw_line (window, gc1,
2159 x + 1, y + height - 2,
2160 x + width - 1, y + half_height);
2161 gdk_draw_line (window, gc3,
2163 x + width - 1, y + half_height);
2166 case GTK_SHADOW_ETCHED_IN:
2167 case GTK_SHADOW_ETCHED_OUT:
2168 gdk_draw_line (window, gc1,
2169 x + width - 1, y + half_height + 1,
2171 gdk_draw_line (window, gc1,
2173 x + 1, y + height - 1);
2174 gdk_draw_line (window, gc1,
2175 x + 1, y + height - 1,
2176 x + width - 1, y + half_height + 1);
2178 points[0].x = x + width - 2;
2179 points[0].y = y + half_height;
2183 points[2].y = y + height - 1;
2185 gdk_draw_polygon (window, gc2, FALSE, points, 3);
2196 gdk_gc_set_clip_rectangle (gc1, NULL);
2197 gdk_gc_set_clip_rectangle (gc2, NULL);
2200 gdk_gc_set_clip_rectangle (gc3, NULL);
2201 gdk_gc_set_clip_rectangle (gc4, NULL);
2207 gtk_default_draw_diamond (GtkStyle *style,
2209 GtkStateType state_type,
2210 GtkShadowType shadow_type,
2213 const gchar *detail,
2221 GdkGC *outer_nw = NULL;
2222 GdkGC *outer_ne = NULL;
2223 GdkGC *outer_sw = NULL;
2224 GdkGC *outer_se = NULL;
2225 GdkGC *middle_nw = NULL;
2226 GdkGC *middle_ne = NULL;
2227 GdkGC *middle_sw = NULL;
2228 GdkGC *middle_se = NULL;
2229 GdkGC *inner_nw = NULL;
2230 GdkGC *inner_ne = NULL;
2231 GdkGC *inner_sw = NULL;
2232 GdkGC *inner_se = NULL;
2234 g_return_if_fail (GTK_IS_STYLE (style));
2235 g_return_if_fail (window != NULL);
2237 if ((width == -1) && (height == -1))
2238 gdk_window_get_size (window, &width, &height);
2239 else if (width == -1)
2240 gdk_window_get_size (window, &width, NULL);
2241 else if (height == -1)
2242 gdk_window_get_size (window, NULL, &height);
2244 half_width = width / 2;
2245 half_height = height / 2;
2249 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
2250 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2251 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
2252 gdk_gc_set_clip_rectangle (style->black_gc, area);
2255 switch (shadow_type)
2258 inner_sw = inner_se = style->bg_gc[state_type];
2259 middle_sw = middle_se = style->light_gc[state_type];
2260 outer_sw = outer_se = style->light_gc[state_type];
2261 inner_nw = inner_ne = style->black_gc;
2262 middle_nw = middle_ne = style->dark_gc[state_type];
2263 outer_nw = outer_ne = style->dark_gc[state_type];
2266 case GTK_SHADOW_OUT:
2267 inner_sw = inner_se = style->dark_gc[state_type];
2268 middle_sw = middle_se = style->dark_gc[state_type];
2269 outer_sw = outer_se = style->black_gc;
2270 inner_nw = inner_ne = style->bg_gc[state_type];
2271 middle_nw = middle_ne = style->light_gc[state_type];
2272 outer_nw = outer_ne = style->light_gc[state_type];
2275 case GTK_SHADOW_ETCHED_IN:
2276 inner_sw = inner_se = style->bg_gc[state_type];
2277 middle_sw = middle_se = style->dark_gc[state_type];
2278 outer_sw = outer_se = style->light_gc[state_type];
2279 inner_nw = inner_ne = style->bg_gc[state_type];
2280 middle_nw = middle_ne = style->light_gc[state_type];
2281 outer_nw = outer_ne = style->dark_gc[state_type];
2284 case GTK_SHADOW_ETCHED_OUT:
2285 inner_sw = inner_se = style->bg_gc[state_type];
2286 middle_sw = middle_se = style->light_gc[state_type];
2287 outer_sw = outer_se = style->dark_gc[state_type];
2288 inner_nw = inner_ne = style->bg_gc[state_type];
2289 middle_nw = middle_ne = style->dark_gc[state_type];
2290 outer_nw = outer_ne = style->light_gc[state_type];
2300 gdk_draw_line (window, inner_sw,
2301 x + 2, y + half_height,
2302 x + half_width, y + height - 2);
2303 gdk_draw_line (window, inner_se,
2304 x + half_width, y + height - 2,
2305 x + width - 2, y + half_height);
2306 gdk_draw_line (window, middle_sw,
2307 x + 1, y + half_height,
2308 x + half_width, y + height - 1);
2309 gdk_draw_line (window, middle_se,
2310 x + half_width, y + height - 1,
2311 x + width - 1, y + half_height);
2312 gdk_draw_line (window, outer_sw,
2314 x + half_width, y + height);
2315 gdk_draw_line (window, outer_se,
2316 x + half_width, y + height,
2317 x + width, y + half_height);
2319 gdk_draw_line (window, inner_nw,
2320 x + 2, y + half_height,
2321 x + half_width, y + 2);
2322 gdk_draw_line (window, inner_ne,
2323 x + half_width, y + 2,
2324 x + width - 2, y + half_height);
2325 gdk_draw_line (window, middle_nw,
2326 x + 1, y + half_height,
2327 x + half_width, y + 1);
2328 gdk_draw_line (window, middle_ne,
2329 x + half_width, y + 1,
2330 x + width - 1, y + half_height);
2331 gdk_draw_line (window, outer_nw,
2334 gdk_draw_line (window, outer_ne,
2336 x + width, y + half_height);
2341 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
2342 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
2343 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
2344 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2349 gtk_default_draw_string (GtkStyle *style,
2351 GtkStateType state_type,
2354 const gchar *detail,
2357 const gchar *string)
2359 g_return_if_fail (GTK_IS_STYLE (style));
2360 g_return_if_fail (window != NULL);
2364 gdk_gc_set_clip_rectangle (style->white_gc, area);
2365 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], area);
2368 if (state_type == GTK_STATE_INSENSITIVE)
2369 gdk_draw_string (window, style->font, style->white_gc, x + 1, y + 1, string);
2371 gdk_draw_string (window, style->font, style->fg_gc[state_type], x, y, string);
2375 gdk_gc_set_clip_rectangle (style->white_gc, NULL);
2376 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], NULL);
2381 gtk_default_draw_box (GtkStyle *style,
2383 GtkStateType state_type,
2384 GtkShadowType shadow_type,
2387 const gchar *detail,
2393 g_return_if_fail (GTK_IS_STYLE (style));
2394 g_return_if_fail (window != NULL);
2396 if (width == -1 && height == -1)
2397 gdk_window_get_size (window, &width, &height);
2398 else if (width == -1)
2399 gdk_window_get_size (window, &width, NULL);
2400 else if (height == -1)
2401 gdk_window_get_size (window, NULL, &height);
2403 if (!style->bg_pixmap[state_type] ||
2404 GDK_IS_PIXMAP (window))
2407 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2409 gdk_draw_rectangle (window, style->bg_gc[state_type], TRUE,
2410 x, y, width, height);
2412 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
2415 gtk_style_apply_default_background (style, window,
2416 widget && !GTK_WIDGET_NO_WINDOW (widget),
2417 state_type, area, x, y, width, height);
2419 gtk_paint_shadow (style, window, state_type, shadow_type, area, widget, detail,
2420 x, y, width, height);
2424 get_darkened_gc (GdkWindow *window,
2428 GdkColor src = *color;
2432 gc = gdk_gc_new (window);
2434 while (darken_count)
2436 gtk_style_shade (&src, &shaded, 0.93);
2441 gdk_gc_set_rgb_fg_color (gc, &shaded);
2447 gtk_default_draw_flat_box (GtkStyle *style,
2449 GtkStateType state_type,
2450 GtkShadowType shadow_type,
2453 const gchar *detail,
2460 GdkGC *freeme = NULL;
2462 g_return_if_fail (GTK_IS_STYLE (style));
2463 g_return_if_fail (window != NULL);
2465 if (width == -1 && height == -1)
2466 gdk_window_get_size (window, &width, &height);
2467 else if (width == -1)
2468 gdk_window_get_size (window, &width, NULL);
2469 else if (height == -1)
2470 gdk_window_get_size (window, NULL, &height);
2474 if (state_type == GTK_STATE_SELECTED)
2476 if (!strcmp ("text", detail))
2477 gc1 = style->bg_gc[GTK_STATE_SELECTED];
2478 else if (!strcmp ("cell_even_sorted", detail) ||
2479 !strcmp ("cell_odd_sorted", detail) ||
2480 !strcmp ("cell_even_ruled_sorted", detail) ||
2481 !strcmp ("cell_odd_ruled_sorted", detail))
2483 freeme = get_darkened_gc (window, &style->bg[state_type], 1);
2488 gc1 = style->bg_gc[state_type];
2493 if (!strcmp ("viewportbin", detail))
2494 gc1 = style->bg_gc[GTK_STATE_NORMAL];
2495 else if (!strcmp ("entry_bg", detail))
2496 gc1 = style->base_gc[state_type];
2498 /* For trees: even rows are base color, odd rows are a shade of
2499 * the base color, the sort column is a shade of the original color
2503 /* FIXME when we have style properties, clean this up.
2506 else if (!strcmp ("cell_even", detail) ||
2507 !strcmp ("cell_odd", detail) ||
2508 !strcmp ("cell_even_ruled", detail))
2510 gc1 = style->base_gc[state_type];
2512 else if (!strcmp ("cell_even_sorted", detail) ||
2513 !strcmp ("cell_odd_sorted", detail) ||
2514 !strcmp ("cell_odd_ruled", detail) ||
2515 !strcmp ("cell_even_ruled_sorted", detail))
2517 freeme = get_darkened_gc (window, &style->base[state_type], 1);
2520 else if (!strcmp ("cell_odd_ruled_sorted", detail))
2522 freeme = get_darkened_gc (window, &style->base[state_type], 2);
2526 gc1 = style->bg_gc[state_type];
2530 gc1 = style->bg_gc[state_type];
2532 if (!style->bg_pixmap[state_type] || gc1 != style->bg_gc[state_type] ||
2533 GDK_IS_PIXMAP (window))
2536 gdk_gc_set_clip_rectangle (gc1, area);
2538 gdk_draw_rectangle (window, gc1, TRUE,
2539 x, y, width, height);
2541 if (detail && !strcmp ("tooltip", detail))
2542 gdk_draw_rectangle (window, style->black_gc, FALSE,
2543 x, y, width - 1, height - 1);
2546 gdk_gc_set_clip_rectangle (gc1, NULL);
2549 gtk_style_apply_default_background (style, window,
2550 widget && !GTK_WIDGET_NO_WINDOW (widget),
2551 state_type, area, x, y, width, height);
2555 g_object_unref (G_OBJECT (freeme));
2559 gtk_default_draw_check (GtkStyle *style,
2561 GtkStateType state_type,
2562 GtkShadowType shadow_type,
2565 const gchar *detail,
2571 if (detail && strcmp (detail, "cellcheck") == 0)
2573 gdk_draw_rectangle (window,
2574 widget->style->fg_gc[state_type],
2579 if (shadow_type == GTK_SHADOW_IN)
2581 gdk_draw_line (window,
2582 widget->style->fg_gc[state_type],
2586 gdk_draw_line (window,
2587 widget->style->fg_gc[state_type],
2596 gtk_paint_box (style, window, state_type, shadow_type, area, widget, detail,
2597 x, y, width, height);
2602 gtk_default_draw_option (GtkStyle *style,
2604 GtkStateType state_type,
2605 GtkShadowType shadow_type,
2608 const gchar *detail,
2614 if (detail && strcmp (detail, "cellradio") == 0)
2616 gdk_draw_arc (window,
2617 widget->style->fg_gc[state_type],
2624 if (shadow_type == GTK_SHADOW_IN)
2626 gdk_draw_arc (window,
2627 widget->style->fg_gc[state_type],
2638 gtk_paint_diamond (style, window, state_type, shadow_type, area, widget,
2639 detail, x, y, width, height);
2644 gtk_default_draw_tab (GtkStyle *style,
2646 GtkStateType state_type,
2647 GtkShadowType shadow_type,
2650 const gchar *detail,
2656 g_return_if_fail (GTK_IS_STYLE (style));
2657 g_return_if_fail (window != NULL);
2659 gtk_paint_box (style, window, state_type, shadow_type, area, widget, detail,
2660 x, y, width, height);
2664 gtk_default_draw_shadow_gap (GtkStyle *style,
2666 GtkStateType state_type,
2667 GtkShadowType shadow_type,
2670 const gchar *detail,
2675 GtkPositionType gap_side,
2684 g_return_if_fail (GTK_IS_STYLE (style));
2685 g_return_if_fail (window != NULL);
2687 if (width == -1 && height == -1)
2688 gdk_window_get_size (window, &width, &height);
2689 else if (width == -1)
2690 gdk_window_get_size (window, &width, NULL);
2691 else if (height == -1)
2692 gdk_window_get_size (window, NULL, &height);
2694 switch (shadow_type)
2696 case GTK_SHADOW_NONE:
2699 gc1 = style->dark_gc[state_type];
2700 gc2 = style->black_gc;
2701 gc3 = style->bg_gc[state_type];
2702 gc4 = style->light_gc[state_type];
2704 case GTK_SHADOW_ETCHED_IN:
2705 gc1 = style->dark_gc[state_type];
2706 gc2 = style->light_gc[state_type];
2707 gc3 = style->dark_gc[state_type];
2708 gc4 = style->light_gc[state_type];
2710 case GTK_SHADOW_OUT:
2711 gc1 = style->light_gc[state_type];
2712 gc2 = style->bg_gc[state_type];
2713 gc3 = style->dark_gc[state_type];
2714 gc4 = style->black_gc;
2716 case GTK_SHADOW_ETCHED_OUT:
2717 gc1 = style->light_gc[state_type];
2718 gc2 = style->dark_gc[state_type];
2719 gc3 = style->light_gc[state_type];
2720 gc4 = style->dark_gc[state_type];
2725 gdk_gc_set_clip_rectangle (gc1, area);
2726 gdk_gc_set_clip_rectangle (gc2, area);
2727 gdk_gc_set_clip_rectangle (gc3, area);
2728 gdk_gc_set_clip_rectangle (gc4, area);
2731 switch (shadow_type)
2733 case GTK_SHADOW_NONE:
2735 case GTK_SHADOW_OUT:
2736 case GTK_SHADOW_ETCHED_IN:
2737 case GTK_SHADOW_ETCHED_OUT:
2741 gdk_draw_line (window, gc1,
2742 x, y, x, y + height - 1);
2743 gdk_draw_line (window, gc2,
2744 x + 1, y, x + 1, y + height - 2);
2746 gdk_draw_line (window, gc3,
2747 x + 1, y + height - 2, x + width - 2, y + height - 2);
2748 gdk_draw_line (window, gc3,
2749 x + width - 2, y, x + width - 2, y + height - 2);
2750 gdk_draw_line (window, gc4,
2751 x, y + height - 1, x + width - 1, y + height - 1);
2752 gdk_draw_line (window, gc4,
2753 x + width - 1, y, x + width - 1, y + height - 1);
2756 gdk_draw_line (window, gc1,
2757 x, y, x + gap_x - 1, y);
2758 gdk_draw_line (window, gc2,
2759 x + 1, y + 1, x + gap_x - 1, y + 1);
2760 gdk_draw_line (window, gc2,
2761 x + gap_x, y, x + gap_x, y);
2763 if ((width - (gap_x + gap_width)) > 0)
2765 gdk_draw_line (window, gc1,
2766 x + gap_x + gap_width, y, x + width - 2, y);
2767 gdk_draw_line (window, gc2,
2768 x + gap_x + gap_width, y + 1, x + width - 2, y + 1);
2769 gdk_draw_line (window, gc2,
2770 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
2773 case GTK_POS_BOTTOM:
2774 gdk_draw_line (window, gc1,
2775 x, y, x + width - 1, y);
2776 gdk_draw_line (window, gc1,
2777 x, y, x, y + height - 1);
2778 gdk_draw_line (window, gc2,
2779 x + 1, y + 1, x + width - 2, y + 1);
2780 gdk_draw_line (window, gc2,
2781 x + 1, y + 1, x + 1, y + height - 1);
2783 gdk_draw_line (window, gc3,
2784 x + width - 2, y + 1, x + width - 2, y + height - 1);
2785 gdk_draw_line (window, gc4,
2786 x + width - 1, y, x + width - 1, y + height - 1);
2789 gdk_draw_line (window, gc4,
2790 x, y + height - 1, x + gap_x - 1, y + height - 1);
2791 gdk_draw_line (window, gc3,
2792 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
2793 gdk_draw_line (window, gc3,
2794 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
2796 if ((width - (gap_x + gap_width)) > 0)
2798 gdk_draw_line (window, gc4,
2799 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
2800 gdk_draw_line (window, gc3,
2801 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
2802 gdk_draw_line (window, gc3,
2803 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
2807 gdk_draw_line (window, gc1,
2808 x, y, x + width - 1, y);
2809 gdk_draw_line (window, gc2,
2810 x, y + 1, x + width - 2, y + 1);
2812 gdk_draw_line (window, gc3,
2813 x, y + height - 2, x + width - 2, y + height - 2);
2814 gdk_draw_line (window, gc3,
2815 x + width - 2, y + 1, x + width - 2, y + height - 2);
2816 gdk_draw_line (window, gc4,
2817 x, y + height - 1, x + width - 1, y + height - 1);
2818 gdk_draw_line (window, gc4,
2819 x + width - 1, y, x + width - 1, y + height - 1);
2822 gdk_draw_line (window, gc1,
2823 x, y, x, y + gap_x - 1);
2824 gdk_draw_line (window, gc2,
2825 x + 1, y + 1, x + 1, y + gap_x - 1);
2826 gdk_draw_line (window, gc2,
2827 x, y + gap_x, x, y + gap_x);
2829 if ((width - (gap_x + gap_width)) > 0)
2831 gdk_draw_line (window, gc1,
2832 x, y + gap_x + gap_width, x, y + height - 2);
2833 gdk_draw_line (window, gc2,
2834 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
2835 gdk_draw_line (window, gc2,
2836 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
2840 gdk_draw_line (window, gc1,
2841 x, y, x + width - 1, y);
2842 gdk_draw_line (window, gc1,
2843 x, y, x, y + height - 1);
2844 gdk_draw_line (window, gc2,
2845 x + 1, y + 1, x + width - 1, y + 1);
2846 gdk_draw_line (window, gc2,
2847 x + 1, y + 1, x + 1, y + height - 2);
2849 gdk_draw_line (window, gc3,
2850 x + 1, y + height - 2, x + width - 1, y + height - 2);
2851 gdk_draw_line (window, gc4,
2852 x, y + height - 1, x + width - 1, y + height - 1);
2855 gdk_draw_line (window, gc4,
2856 x + width - 1, y, x + width - 1, y + gap_x - 1);
2857 gdk_draw_line (window, gc3,
2858 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
2859 gdk_draw_line (window, gc3,
2860 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
2862 if ((width - (gap_x + gap_width)) > 0)
2864 gdk_draw_line (window, gc4,
2865 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
2866 gdk_draw_line (window, gc3,
2867 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
2868 gdk_draw_line (window, gc3,
2869 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
2877 gdk_gc_set_clip_rectangle (gc1, NULL);
2878 gdk_gc_set_clip_rectangle (gc2, NULL);
2879 gdk_gc_set_clip_rectangle (gc3, NULL);
2880 gdk_gc_set_clip_rectangle (gc4, NULL);
2885 gtk_default_draw_box_gap (GtkStyle *style,
2887 GtkStateType state_type,
2888 GtkShadowType shadow_type,
2891 const gchar *detail,
2896 GtkPositionType gap_side,
2905 g_return_if_fail (GTK_IS_STYLE (style));
2906 g_return_if_fail (window != NULL);
2908 gtk_style_apply_default_background (style, window,
2909 widget && !GTK_WIDGET_NO_WINDOW (widget),
2910 state_type, area, x, y, width, height);
2912 if (width == -1 && height == -1)
2913 gdk_window_get_size (window, &width, &height);
2914 else if (width == -1)
2915 gdk_window_get_size (window, &width, NULL);
2916 else if (height == -1)
2917 gdk_window_get_size (window, NULL, &height);
2919 switch (shadow_type)
2921 case GTK_SHADOW_NONE:
2924 gc1 = style->dark_gc[state_type];
2925 gc2 = style->black_gc;
2926 gc3 = style->bg_gc[state_type];
2927 gc4 = style->light_gc[state_type];
2929 case GTK_SHADOW_ETCHED_IN:
2930 gc1 = style->dark_gc[state_type];
2931 gc2 = style->light_gc[state_type];
2932 gc3 = style->dark_gc[state_type];
2933 gc4 = style->light_gc[state_type];
2935 case GTK_SHADOW_OUT:
2936 gc1 = style->light_gc[state_type];
2937 gc2 = style->bg_gc[state_type];
2938 gc3 = style->dark_gc[state_type];
2939 gc4 = style->black_gc;
2941 case GTK_SHADOW_ETCHED_OUT:
2942 gc1 = style->light_gc[state_type];
2943 gc2 = style->dark_gc[state_type];
2944 gc3 = style->light_gc[state_type];
2945 gc4 = style->dark_gc[state_type];
2951 gdk_gc_set_clip_rectangle (gc1, area);
2952 gdk_gc_set_clip_rectangle (gc2, area);
2953 gdk_gc_set_clip_rectangle (gc3, area);
2954 gdk_gc_set_clip_rectangle (gc4, area);
2957 switch (shadow_type)
2959 case GTK_SHADOW_NONE:
2961 case GTK_SHADOW_OUT:
2962 case GTK_SHADOW_ETCHED_IN:
2963 case GTK_SHADOW_ETCHED_OUT:
2967 gdk_draw_line (window, gc1,
2968 x, y, x, y + height - 1);
2969 gdk_draw_line (window, gc2,
2970 x + 1, y, x + 1, y + height - 2);
2972 gdk_draw_line (window, gc3,
2973 x + 1, y + height - 2, x + width - 2, y + height - 2);
2974 gdk_draw_line (window, gc3,
2975 x + width - 2, y, x + width - 2, y + height - 2);
2976 gdk_draw_line (window, gc4,
2977 x, y + height - 1, x + width - 1, y + height - 1);
2978 gdk_draw_line (window, gc4,
2979 x + width - 1, y, x + width - 1, y + height - 1);
2982 gdk_draw_line (window, gc1,
2983 x, y, x + gap_x - 1, y);
2984 gdk_draw_line (window, gc2,
2985 x + 1, y + 1, x + gap_x - 1, y + 1);
2986 gdk_draw_line (window, gc2,
2987 x + gap_x, y, x + gap_x, y);
2989 if ((width - (gap_x + gap_width)) > 0)
2991 gdk_draw_line (window, gc1,
2992 x + gap_x + gap_width, y, x + width - 2, y);
2993 gdk_draw_line (window, gc2,
2994 x + gap_x + gap_width, y + 1, x + width - 2, y + 1);
2995 gdk_draw_line (window, gc2,
2996 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
2999 case GTK_POS_BOTTOM:
3000 gdk_draw_line (window, gc1,
3001 x, y, x + width - 1, y);
3002 gdk_draw_line (window, gc1,
3003 x, y, x, y + height - 1);
3004 gdk_draw_line (window, gc2,
3005 x + 1, y + 1, x + width - 2, y + 1);
3006 gdk_draw_line (window, gc2,
3007 x + 1, y + 1, x + 1, y + height - 1);
3009 gdk_draw_line (window, gc3,
3010 x + width - 2, y + 1, x + width - 2, y + height - 1);
3011 gdk_draw_line (window, gc4,
3012 x + width - 1, y, x + width - 1, y + height - 1);
3015 gdk_draw_line (window, gc4,
3016 x, y + height - 1, x + gap_x - 1, y + height - 1);
3017 gdk_draw_line (window, gc3,
3018 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
3019 gdk_draw_line (window, gc3,
3020 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
3022 if ((width - (gap_x + gap_width)) > 0)
3024 gdk_draw_line (window, gc4,
3025 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
3026 gdk_draw_line (window, gc3,
3027 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
3028 gdk_draw_line (window, gc3,
3029 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
3033 gdk_draw_line (window, gc1,
3034 x, y, x + width - 1, y);
3035 gdk_draw_line (window, gc2,
3036 x, y + 1, x + width - 2, y + 1);
3038 gdk_draw_line (window, gc3,
3039 x, y + height - 2, x + width - 2, y + height - 2);
3040 gdk_draw_line (window, gc3,
3041 x + width - 2, y + 1, x + width - 2, y + height - 2);
3042 gdk_draw_line (window, gc4,
3043 x, y + height - 1, x + width - 1, y + height - 1);
3044 gdk_draw_line (window, gc4,
3045 x + width - 1, y, x + width - 1, y + height - 1);
3048 gdk_draw_line (window, gc1,
3049 x, y, x, y + gap_x - 1);
3050 gdk_draw_line (window, gc2,
3051 x + 1, y + 1, x + 1, y + gap_x - 1);
3052 gdk_draw_line (window, gc2,
3053 x, y + gap_x, x, y + gap_x);
3055 if ((width - (gap_x + gap_width)) > 0)
3057 gdk_draw_line (window, gc1,
3058 x, y + gap_x + gap_width, x, y + height - 2);
3059 gdk_draw_line (window, gc2,
3060 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
3061 gdk_draw_line (window, gc2,
3062 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
3066 gdk_draw_line (window, gc1,
3067 x, y, x + width - 1, y);
3068 gdk_draw_line (window, gc1,
3069 x, y, x, y + height - 1);
3070 gdk_draw_line (window, gc2,
3071 x + 1, y + 1, x + width - 1, y + 1);
3072 gdk_draw_line (window, gc2,
3073 x + 1, y + 1, x + 1, y + height - 2);
3075 gdk_draw_line (window, gc3,
3076 x + 1, y + height - 2, x + width - 1, y + height - 2);
3077 gdk_draw_line (window, gc4,
3078 x, y + height - 1, x + width - 1, y + height - 1);
3081 gdk_draw_line (window, gc4,
3082 x + width - 1, y, x + width - 1, y + gap_x - 1);
3083 gdk_draw_line (window, gc3,
3084 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
3085 gdk_draw_line (window, gc3,
3086 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
3088 if ((width - (gap_x + gap_width)) > 0)
3090 gdk_draw_line (window, gc4,
3091 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
3092 gdk_draw_line (window, gc3,
3093 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
3094 gdk_draw_line (window, gc3,
3095 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
3103 gdk_gc_set_clip_rectangle (gc1, NULL);
3104 gdk_gc_set_clip_rectangle (gc2, NULL);
3105 gdk_gc_set_clip_rectangle (gc3, NULL);
3106 gdk_gc_set_clip_rectangle (gc4, NULL);
3111 gtk_default_draw_extension (GtkStyle *style,
3113 GtkStateType state_type,
3114 GtkShadowType shadow_type,
3117 const gchar *detail,
3122 GtkPositionType gap_side)
3129 g_return_if_fail (GTK_IS_STYLE (style));
3130 g_return_if_fail (window != NULL);
3132 gtk_style_apply_default_background (style, window,
3133 widget && !GTK_WIDGET_NO_WINDOW (widget),
3134 GTK_STATE_NORMAL, area, x, y, width, height);
3136 if (width == -1 && height == -1)
3137 gdk_window_get_size (window, &width, &height);
3138 else if (width == -1)
3139 gdk_window_get_size (window, &width, NULL);
3140 else if (height == -1)
3141 gdk_window_get_size (window, NULL, &height);
3143 switch (shadow_type)
3145 case GTK_SHADOW_NONE:
3148 gc1 = style->dark_gc[state_type];
3149 gc2 = style->black_gc;
3150 gc3 = style->bg_gc[state_type];
3151 gc4 = style->light_gc[state_type];
3153 case GTK_SHADOW_ETCHED_IN:
3154 gc1 = style->dark_gc[state_type];
3155 gc2 = style->light_gc[state_type];
3156 gc3 = style->dark_gc[state_type];
3157 gc4 = style->light_gc[state_type];
3159 case GTK_SHADOW_OUT:
3160 gc1 = style->light_gc[state_type];
3161 gc2 = style->bg_gc[state_type];
3162 gc3 = style->dark_gc[state_type];
3163 gc4 = style->black_gc;
3165 case GTK_SHADOW_ETCHED_OUT:
3166 gc1 = style->light_gc[state_type];
3167 gc2 = style->dark_gc[state_type];
3168 gc3 = style->light_gc[state_type];
3169 gc4 = style->dark_gc[state_type];
3175 gdk_gc_set_clip_rectangle (gc1, area);
3176 gdk_gc_set_clip_rectangle (gc2, area);
3177 gdk_gc_set_clip_rectangle (gc3, area);
3178 gdk_gc_set_clip_rectangle (gc4, area);
3181 switch (shadow_type)
3183 case GTK_SHADOW_NONE:
3185 case GTK_SHADOW_OUT:
3186 case GTK_SHADOW_ETCHED_IN:
3187 case GTK_SHADOW_ETCHED_OUT:
3191 gtk_style_apply_default_background (style, window,
3192 widget && !GTK_WIDGET_NO_WINDOW (widget),
3194 x + style->xthickness,
3196 width - (2 * style->xthickness),
3197 height - (style->ythickness));
3198 gdk_draw_line (window, gc1,
3199 x, y, x, y + height - 2);
3200 gdk_draw_line (window, gc2,
3201 x + 1, y, x + 1, y + height - 2);
3203 gdk_draw_line (window, gc3,
3204 x + 2, y + height - 2, x + width - 2, y + height - 2);
3205 gdk_draw_line (window, gc3,
3206 x + width - 2, y, x + width - 2, y + height - 2);
3207 gdk_draw_line (window, gc4,
3208 x + 1, y + height - 1, x + width - 2, y + height - 1);
3209 gdk_draw_line (window, gc4,
3210 x + width - 1, y, x + width - 1, y + height - 2);
3212 case GTK_POS_BOTTOM:
3213 gtk_style_apply_default_background (style, window,
3214 widget && !GTK_WIDGET_NO_WINDOW (widget),
3216 x + style->xthickness,
3217 y + style->ythickness,
3218 width - (2 * style->xthickness),
3219 height - (style->ythickness));
3220 gdk_draw_line (window, gc1,
3221 x + 1, y, x + width - 2, y);
3222 gdk_draw_line (window, gc1,
3223 x, y + 1, x, y + height - 1);
3224 gdk_draw_line (window, gc2,
3225 x + 1, y + 1, x + width - 2, y + 1);
3226 gdk_draw_line (window, gc2,
3227 x + 1, y + 1, x + 1, y + height - 1);
3229 gdk_draw_line (window, gc3,
3230 x + width - 2, y + 2, x + width - 2, y + height - 1);
3231 gdk_draw_line (window, gc4,
3232 x + width - 1, y + 1, x + width - 1, y + height - 1);
3235 gtk_style_apply_default_background (style, window,
3236 widget && !GTK_WIDGET_NO_WINDOW (widget),
3239 y + style->ythickness,
3240 width - (style->xthickness),
3241 height - (2 * style->ythickness));
3242 gdk_draw_line (window, gc1,
3243 x, y, x + width - 2, y);
3244 gdk_draw_line (window, gc2,
3245 x + 1, y + 1, x + width - 2, y + 1);
3247 gdk_draw_line (window, gc3,
3248 x, y + height - 2, x + width - 2, y + height - 2);
3249 gdk_draw_line (window, gc3,
3250 x + width - 2, y + 2, x + width - 2, y + height - 2);
3251 gdk_draw_line (window, gc4,
3252 x, y + height - 1, x + width - 2, y + height - 1);
3253 gdk_draw_line (window, gc4,
3254 x + width - 1, y + 1, x + width - 1, y + height - 2);
3257 gtk_style_apply_default_background (style, window,
3258 widget && !GTK_WIDGET_NO_WINDOW (widget),
3260 x + style->xthickness,
3261 y + style->ythickness,
3262 width - (style->xthickness),
3263 height - (2 * style->ythickness));
3264 gdk_draw_line (window, gc1,
3265 x + 1, y, x + width - 1, y);
3266 gdk_draw_line (window, gc1,
3267 x, y + 1, x, y + height - 2);
3268 gdk_draw_line (window, gc2,
3269 x + 1, y + 1, x + width - 1, y + 1);
3270 gdk_draw_line (window, gc2,
3271 x + 1, y + 1, x + 1, y + height - 2);
3273 gdk_draw_line (window, gc3,
3274 x + 2, y + height - 2, x + width - 1, y + height - 2);
3275 gdk_draw_line (window, gc4,
3276 x + 1, y + height - 1, x + width - 1, y + height - 1);
3283 gdk_gc_set_clip_rectangle (gc1, NULL);
3284 gdk_gc_set_clip_rectangle (gc2, NULL);
3285 gdk_gc_set_clip_rectangle (gc3, NULL);
3286 gdk_gc_set_clip_rectangle (gc4, NULL);
3291 gtk_default_draw_focus (GtkStyle *style,
3295 const gchar *detail,
3301 g_return_if_fail (GTK_IS_STYLE (style));
3302 g_return_if_fail (window != NULL);
3304 if (width == -1 && height == -1)
3306 gdk_window_get_size (window, &width, &height);
3310 else if (width == -1)
3312 gdk_window_get_size (window, &width, NULL);
3315 else if (height == -1)
3317 gdk_window_get_size (window, NULL, &height);
3322 gdk_gc_set_clip_rectangle (style->black_gc, area);
3324 if (detail && !strcmp (detail, "add-mode"))
3326 gdk_gc_set_line_attributes (style->black_gc, 1, GDK_LINE_ON_OFF_DASH, 0, 0);
3327 gdk_gc_set_dashes (style->black_gc, 0, "\4\4", 2);
3329 gdk_draw_rectangle (window,
3330 style->black_gc, FALSE,
3331 x, y, width, height);
3333 gdk_gc_set_line_attributes (style->black_gc, 1, GDK_LINE_SOLID, 0, 0);
3337 gdk_draw_rectangle (window,
3338 style->black_gc, FALSE,
3339 x, y, width, height);
3343 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
3347 gtk_default_draw_slider (GtkStyle *style,
3349 GtkStateType state_type,
3350 GtkShadowType shadow_type,
3353 const gchar *detail,
3358 GtkOrientation orientation)
3360 g_return_if_fail (GTK_IS_STYLE (style));
3361 g_return_if_fail (window != NULL);
3363 if (width == -1 && height == -1)
3364 gdk_window_get_size (window, &width, &height);
3365 else if (width == -1)
3366 gdk_window_get_size (window, &width, NULL);
3367 else if (height == -1)
3368 gdk_window_get_size (window, NULL, &height);
3370 gtk_paint_box (style, window, state_type, shadow_type,
3371 area, widget, detail, x, y, width, height);
3373 if (orientation == GTK_ORIENTATION_HORIZONTAL)
3374 gtk_paint_vline (style, window, state_type, area, widget, detail,
3376 height - style->ythickness - 1, width / 2);
3378 gtk_paint_hline (style, window, state_type, area, widget, detail,
3380 width - style->xthickness - 1, height / 2);
3384 draw_dot (GdkWindow *window,
3392 size = CLAMP (size, 2, 3);
3396 gdk_draw_point (window, light_gc, x, y);
3397 gdk_draw_point (window, light_gc, x+1, y+1);
3399 else if (size == 3);
3401 gdk_draw_point (window, light_gc, x, y);
3402 gdk_draw_point (window, light_gc, x+1, y);
3403 gdk_draw_point (window, light_gc, x, y+1);
3404 gdk_draw_point (window, dark_gc, x+1, y+2);
3405 gdk_draw_point (window, dark_gc, x+2, y+1);
3406 gdk_draw_point (window, dark_gc, x+2, y+2);
3411 gtk_default_draw_handle (GtkStyle *style,
3413 GtkStateType state_type,
3414 GtkShadowType shadow_type,
3417 const gchar *detail,
3422 GtkOrientation orientation)
3425 gint xthick, ythick;
3426 GdkGC *light_gc, *dark_gc;
3431 g_return_if_fail (GTK_IS_STYLE (style));
3432 g_return_if_fail (window != NULL);
3434 if (width == -1 && height == -1)
3435 gdk_window_get_size (window, &width, &height);
3436 else if (width == -1)
3437 gdk_window_get_size (window, &width, NULL);
3438 else if (height == -1)
3439 gdk_window_get_size (window, NULL, &height);
3441 gtk_paint_box (style, window, state_type, shadow_type, area, widget,
3442 detail, x, y, width, height);
3445 if (!strcmp (detail, "paned"))
3447 /* we want to ignore the shadow border in paned widgets */
3451 light_gc = style->light_gc[state_type];
3452 dark_gc = style->black_gc;
3456 xthick = style->xthickness;
3457 ythick = style->ythickness;
3459 light_gc = style->light_gc[state_type];
3460 dark_gc = style->dark_gc[state_type];
3463 rect.x = x + xthick;
3464 rect.y = y + ythick;
3465 rect.width = width - (xthick * 2);
3466 rect.height = height - (ythick * 2);
3469 intersect = gdk_rectangle_intersect (area, &rect, &dest);
3479 gdk_gc_set_clip_rectangle (light_gc, &dest);
3480 gdk_gc_set_clip_rectangle (dark_gc, &dest);
3482 if (!strcmp (detail, "paned"))
3487 gdk_window_get_size (window, &window_width, &window_height);
3489 if (orientation == GTK_ORIENTATION_HORIZONTAL)
3490 for (xx = window_width/2 - 15; xx <= window_width/2 + 15; xx += 5)
3491 draw_dot (window, light_gc, dark_gc, xx, window_height/2 - 1, 3);
3493 for (yy = window_height/2 - 15; yy <= window_height/2 + 15; yy += 5)
3494 draw_dot (window, light_gc, dark_gc, window_width/2 - 1, yy, 3);
3498 for (yy = y + ythick; yy < (y + height - ythick); yy += 3)
3499 for (xx = x + xthick; xx < (x + width - xthick); xx += 6)
3501 draw_dot (window, light_gc, dark_gc, xx, yy, 2);
3502 draw_dot (window, light_gc, dark_gc, xx + 3, yy + 1, 2);
3506 gdk_gc_set_clip_rectangle (light_gc, NULL);
3507 gdk_gc_set_clip_rectangle (dark_gc, NULL);
3511 gtk_default_draw_expander (GtkStyle *style,
3513 GtkStateType state_type,
3516 const gchar *detail,
3521 /* FIXME replace macro with a style property */
3528 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], area);
3529 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], area);
3535 points[0].y = y + (PM_SIZE + 2) / 6;
3536 points[1].x = points[0].x + 1 * (PM_SIZE + 2);
3537 points[1].y = points[0].y;
3538 points[2].x = (points[0].x + 1 * (PM_SIZE + 2) / 2);
3539 points[2].y = y + 2 * (PM_SIZE + 2) / 3;
3543 points[0].x = x + 1 * ((PM_SIZE + 2) / 6 + 2);
3544 points[0].y = y - 1;
3545 points[1].x = points[0].x;
3546 points[1].y = points[0].y + (PM_SIZE + 2);
3547 points[2].x = (points[0].x + 1 * (2 * (PM_SIZE + 2) / 3 - 1));
3548 points[2].y = points[0].y + (PM_SIZE + 2) / 2;
3551 gdk_draw_polygon (window, style->base_gc[GTK_STATE_NORMAL],
3553 gdk_draw_polygon (window, style->fg_gc[GTK_STATE_NORMAL],
3559 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], NULL);
3560 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], NULL);
3566 typedef struct _ByteRange ByteRange;
3575 range_new (guint start,
3578 ByteRange *br = g_new (ByteRange, 1);
3587 get_insensitive_layout (PangoLayout *layout)
3589 GSList *embossed_ranges = NULL;
3590 GSList *stippled_ranges = NULL;
3591 PangoLayoutIter *iter;
3592 GSList *tmp_list = NULL;
3593 PangoLayout *new_layout;
3594 PangoAttrList *attrs;
3595 GdkBitmap *stipple = NULL;
3597 iter = pango_layout_get_iter (layout);
3601 PangoLayoutRun *run;
3602 PangoAttribute *attr;
3603 gboolean need_stipple = FALSE;
3606 run = pango_layout_iter_get_run (iter);
3610 tmp_list = run->item->extra_attrs;
3612 while (tmp_list != NULL)
3614 attr = tmp_list->data;
3615 switch (attr->klass->type)
3617 case PANGO_ATTR_FOREGROUND:
3618 case PANGO_ATTR_BACKGROUND:
3619 need_stipple = TRUE;
3629 tmp_list = g_slist_next (tmp_list);
3632 br = range_new (run->item->offset, run->item->offset + run->item->length);
3635 stippled_ranges = g_slist_prepend (stippled_ranges, br);
3637 embossed_ranges = g_slist_prepend (embossed_ranges, br);
3640 while (pango_layout_iter_next_run (iter));
3642 pango_layout_iter_free (iter);
3644 new_layout = pango_layout_copy (layout);
3646 attrs = pango_layout_get_attributes (new_layout);
3650 /* Create attr list if there wasn't one */
3651 attrs = pango_attr_list_new ();
3652 pango_layout_set_attributes (new_layout, attrs);
3653 pango_attr_list_unref (attrs);
3656 tmp_list = embossed_ranges;
3657 while (tmp_list != NULL)
3659 PangoAttribute *attr;
3660 ByteRange *br = tmp_list->data;
3662 attr = gdk_pango_attr_embossed_new (TRUE);
3664 attr->start_index = br->start;
3665 attr->end_index = br->end;
3667 pango_attr_list_change (attrs, attr);
3671 tmp_list = g_slist_next (tmp_list);
3674 g_slist_free (embossed_ranges);
3676 tmp_list = stippled_ranges;
3677 while (tmp_list != NULL)
3679 PangoAttribute *attr;
3680 ByteRange *br = tmp_list->data;
3682 if (stipple == NULL)
3684 #define gray50_width 2
3685 #define gray50_height 2
3686 static char gray50_bits[] = {
3690 stipple = gdk_bitmap_create_from_data (NULL,
3691 gray50_bits, gray50_width,
3695 attr = gdk_pango_attr_stipple_new (stipple);
3697 attr->start_index = br->start;
3698 attr->end_index = br->end;
3700 pango_attr_list_change (attrs, attr);
3704 tmp_list = g_slist_next (tmp_list);
3707 g_slist_free (stippled_ranges);
3710 g_object_unref (G_OBJECT (stipple));
3716 gtk_default_draw_layout (GtkStyle *style,
3718 GtkStateType state_type,
3721 const gchar *detail,
3724 PangoLayout *layout)
3726 g_return_if_fail (GTK_IS_STYLE (style));
3727 g_return_if_fail (window != NULL);
3730 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], area);
3732 if (state_type == GTK_STATE_INSENSITIVE)
3736 ins = get_insensitive_layout (layout);
3738 gdk_draw_layout (window, style->fg_gc[state_type], x, y, ins);
3740 g_object_unref (G_OBJECT (ins));
3744 gdk_draw_layout (window, style->fg_gc[state_type], x, y, layout);
3748 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], NULL);
3752 gtk_style_shade (GdkColor *a,
3760 red = (gdouble) a->red / 65535.0;
3761 green = (gdouble) a->green / 65535.0;
3762 blue = (gdouble) a->blue / 65535.0;
3764 rgb_to_hls (&red, &green, &blue);
3769 else if (green < 0.0)
3775 else if (blue < 0.0)
3778 hls_to_rgb (&red, &green, &blue);
3780 b->red = red * 65535.0;
3781 b->green = green * 65535.0;
3782 b->blue = blue * 65535.0;
3786 rgb_to_hls (gdouble *r,
3827 l = (max + min) / 2;
3834 s = (max - min) / (max + min);
3836 s = (max - min) / (2 - max - min);
3840 h = (green - blue) / delta;
3841 else if (green == max)
3842 h = 2 + (blue - red) / delta;
3843 else if (blue == max)
3844 h = 4 + (red - green) / delta;
3857 hls_to_rgb (gdouble *h,
3870 if (lightness <= 0.5)
3871 m2 = lightness * (1 + saturation);
3873 m2 = lightness + saturation - lightness * saturation;
3874 m1 = 2 * lightness - m2;
3876 if (saturation == 0)
3891 r = m1 + (m2 - m1) * hue / 60;
3895 r = m1 + (m2 - m1) * (240 - hue) / 60;
3906 g = m1 + (m2 - m1) * hue / 60;
3910 g = m1 + (m2 - m1) * (240 - hue) / 60;
3921 b = m1 + (m2 - m1) * hue / 60;
3925 b = m1 + (m2 - m1) * (240 - hue) / 60;
3936 gtk_paint_hline (GtkStyle *style,
3938 GtkStateType state_type,
3941 const gchar *detail,
3946 g_return_if_fail (GTK_IS_STYLE (style));
3947 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
3949 GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, area, widget, detail, x1, x2, y);
3953 gtk_paint_vline (GtkStyle *style,
3955 GtkStateType state_type,
3958 const gchar *detail,
3963 g_return_if_fail (GTK_IS_STYLE (style));
3964 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
3966 GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, area, widget, detail, y1, y2, x);
3970 gtk_paint_shadow (GtkStyle *style,
3972 GtkStateType state_type,
3973 GtkShadowType shadow_type,
3976 const gchar *detail,
3982 g_return_if_fail (GTK_IS_STYLE (style));
3983 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
3985 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
3989 gtk_paint_polygon (GtkStyle *style,
3991 GtkStateType state_type,
3992 GtkShadowType shadow_type,
3995 const gchar *detail,
4000 g_return_if_fail (GTK_IS_STYLE (style));
4001 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
4003 GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, area, widget, detail, points, npoints, fill);
4007 gtk_paint_arrow (GtkStyle *style,
4009 GtkStateType state_type,
4010 GtkShadowType shadow_type,
4013 const gchar *detail,
4014 GtkArrowType arrow_type,
4021 g_return_if_fail (GTK_IS_STYLE (style));
4022 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
4024 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, area, widget, detail, arrow_type, fill, x, y, width, height);
4028 gtk_paint_diamond (GtkStyle *style,
4030 GtkStateType state_type,
4031 GtkShadowType shadow_type,
4034 const gchar *detail,
4040 g_return_if_fail (GTK_IS_STYLE (style));
4041 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
4043 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4047 gtk_paint_string (GtkStyle *style,
4049 GtkStateType state_type,
4052 const gchar *detail,
4055 const gchar *string)
4057 g_return_if_fail (GTK_IS_STYLE (style));
4058 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
4060 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, area, widget, detail, x, y, string);
4064 gtk_paint_box (GtkStyle *style,
4066 GtkStateType state_type,
4067 GtkShadowType shadow_type,
4070 const gchar *detail,
4076 g_return_if_fail (GTK_IS_STYLE (style));
4077 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
4079 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4083 gtk_paint_flat_box (GtkStyle *style,
4085 GtkStateType state_type,
4086 GtkShadowType shadow_type,
4089 const gchar *detail,
4095 g_return_if_fail (GTK_IS_STYLE (style));
4096 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
4098 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4102 gtk_paint_check (GtkStyle *style,
4104 GtkStateType state_type,
4105 GtkShadowType shadow_type,
4108 const gchar *detail,
4114 g_return_if_fail (GTK_IS_STYLE (style));
4115 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
4117 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4121 gtk_paint_option (GtkStyle *style,
4123 GtkStateType state_type,
4124 GtkShadowType shadow_type,
4127 const gchar *detail,
4133 g_return_if_fail (GTK_IS_STYLE (style));
4134 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
4136 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4140 gtk_paint_tab (GtkStyle *style,
4142 GtkStateType state_type,
4143 GtkShadowType shadow_type,
4146 const gchar *detail,
4152 g_return_if_fail (GTK_IS_STYLE (style));
4153 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
4155 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4159 gtk_paint_shadow_gap (GtkStyle *style,
4161 GtkStateType state_type,
4162 GtkShadowType shadow_type,
4170 GtkPositionType gap_side,
4174 g_return_if_fail (GTK_IS_STYLE (style));
4175 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
4177 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);
4182 gtk_paint_box_gap (GtkStyle *style,
4184 GtkStateType state_type,
4185 GtkShadowType shadow_type,
4193 GtkPositionType gap_side,
4197 g_return_if_fail (GTK_IS_STYLE (style));
4198 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
4200 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);
4204 gtk_paint_extension (GtkStyle *style,
4206 GtkStateType state_type,
4207 GtkShadowType shadow_type,
4215 GtkPositionType gap_side)
4217 g_return_if_fail (GTK_IS_STYLE (style));
4218 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
4220 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, gap_side);
4224 gtk_paint_focus (GtkStyle *style,
4228 const gchar *detail,
4234 g_return_if_fail (GTK_IS_STYLE (style));
4235 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
4237 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, area, widget, detail, x, y, width, height);
4241 gtk_paint_slider (GtkStyle *style,
4243 GtkStateType state_type,
4244 GtkShadowType shadow_type,
4247 const gchar *detail,
4252 GtkOrientation orientation)
4254 g_return_if_fail (GTK_IS_STYLE (style));
4255 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
4257 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
4261 gtk_paint_handle (GtkStyle *style,
4263 GtkStateType state_type,
4264 GtkShadowType shadow_type,
4267 const gchar *detail,
4272 GtkOrientation orientation)
4274 g_return_if_fail (GTK_IS_STYLE (style));
4275 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
4277 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
4281 gtk_paint_expander (GtkStyle *style,
4283 GtkStateType state_type,
4286 const gchar *detail,
4291 g_return_if_fail (GTK_IS_STYLE (style));
4292 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
4294 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type, area,
4295 widget, detail, x, y, is_open);
4299 gtk_paint_layout (GtkStyle *style,
4301 GtkStateType state_type,
4304 const gchar *detail,
4307 PangoLayout *layout)
4309 g_return_if_fail (GTK_IS_STYLE (style));
4310 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
4312 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, area,
4313 widget, detail, x, y, layout);