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 Library 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 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library 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.
22 #include "gtkwidget.h"
25 #define LIGHTNESS_MULT 1.3
26 #define DARKNESS_MULT 0.7
29 typedef struct _GtkStyleKey GtkStyleKey;
38 GdkPixmap *bg_pixmap[5];
43 GdkColormap *colormap;
48 static void gtk_style_init (GtkStyle *style);
49 static void gtk_styles_init (void);
50 static void gtk_style_remove (GtkStyle *style);
51 static GtkStyle* gtk_style_find (GtkStyle *style,
54 static GtkStyle* gtk_style_new_from_key (GtkStyleKey *key);
55 static GtkStyleKey* gtk_style_key_dup (GtkStyleKey *key);
56 static void gtk_style_destroy (GtkStyle *style);
57 static void gtk_style_key_destroy (GtkStyleKey *key);
58 static guint gtk_style_key_hash (GtkStyleKey *key);
59 static guint gtk_style_value_hash (GtkStyle *style);
60 static gint gtk_style_key_compare (GtkStyleKey *a,
63 static void gtk_default_draw_hline (GtkStyle *style,
65 GtkStateType state_type,
69 static void gtk_default_draw_vline (GtkStyle *style,
71 GtkStateType state_type,
75 static void gtk_default_draw_shadow (GtkStyle *style,
77 GtkStateType state_type,
78 GtkShadowType shadow_type,
83 static void gtk_default_draw_polygon (GtkStyle *style,
85 GtkStateType state_type,
86 GtkShadowType shadow_type,
90 static void gtk_default_draw_arrow (GtkStyle *style,
92 GtkStateType state_type,
93 GtkShadowType shadow_type,
94 GtkArrowType arrow_type,
100 static void gtk_default_draw_diamond (GtkStyle *style,
102 GtkStateType state_type,
103 GtkShadowType shadow_type,
108 static void gtk_default_draw_oval (GtkStyle *style,
110 GtkStateType state_type,
111 GtkShadowType shadow_type,
116 static void gtk_default_draw_string (GtkStyle *style,
118 GtkStateType state_type,
121 const gchar *string);
123 static void gtk_style_shade (GdkColor *a, GdkColor *b, gdouble k);
124 static void rgb_to_hls (gdouble *r, gdouble *g, gdouble *b);
125 static void hls_to_rgb (gdouble *h, gdouble *l, gdouble *s);
128 static GtkStyleClass default_class =
132 gtk_default_draw_hline,
133 gtk_default_draw_vline,
134 gtk_default_draw_shadow,
135 gtk_default_draw_polygon,
136 gtk_default_draw_arrow,
137 gtk_default_draw_diamond,
138 gtk_default_draw_oval,
139 gtk_default_draw_string,
142 static GdkColor gtk_default_normal_fg = { 0, 0, 0, 0 };
143 static GdkColor gtk_default_active_fg = { 0, 0, 0, 0 };
144 static GdkColor gtk_default_prelight_fg = { 0, 0, 0, 0 };
145 static GdkColor gtk_default_selected_fg = { 0, 0xffff, 0xffff, 0xffff };
146 static GdkColor gtk_default_insensitive_fg = { 0, 0x7530, 0x7530, 0x7530 };
148 static GdkColor gtk_default_normal_bg = { 0, 0xd6d6, 0xd6d6, 0xd6d6 };
149 static GdkColor gtk_default_active_bg = { 0, 0xc350, 0xc350, 0xc350 };
150 static GdkColor gtk_default_prelight_bg = { 0, 0xea60, 0xea60, 0xea60 };
151 static GdkColor gtk_default_selected_bg = { 0, 0, 0, 0x9c40 };
152 static GdkColor gtk_default_insensitive_bg = { 0, 0xd6d6, 0xd6d6, 0xd6d6 };
154 static GdkFont *default_font = NULL;
156 static gint initialize = TRUE;
157 static GCache *style_cache = NULL;
158 static GSList *unattached_styles = NULL;
160 static GMemChunk *key_mem_chunk = NULL;
163 gtk_style_copy (GtkStyle *style)
168 g_return_val_if_fail (style != NULL, NULL);
170 new_style = gtk_style_new ();
172 for (i = 0; i < 5; i++)
174 new_style->fg[i] = style->fg[i];
175 new_style->bg[i] = style->bg[i];
176 new_style->text[i] = style->text[i];
177 new_style->base[i] = style->base[i];
179 new_style->bg_pixmap[i] = style->bg_pixmap[i];
182 new_style->font = style->font;
183 gdk_font_ref (new_style->font);
194 style = g_new0 (GtkStyle, 1);
198 gdk_font_load ("-adobe-helvetica-medium-r-normal--*-120-*-*-*-*-*-*");
200 style->font = default_font;
201 gdk_font_ref (style->font);
203 style->ref_count = 1;
204 style->attach_count = 0;
205 style->colormap = NULL;
207 style->klass = &default_class;
209 style->black.red = 0;
210 style->black.green = 0;
211 style->black.blue = 0;
213 style->white.red = 65535;
214 style->white.green = 65535;
215 style->white.blue = 65535;
217 style->black_gc = NULL;
218 style->white_gc = NULL;
220 style->fg[GTK_STATE_NORMAL] = gtk_default_normal_fg;
221 style->fg[GTK_STATE_ACTIVE] = gtk_default_active_fg;
222 style->fg[GTK_STATE_PRELIGHT] = gtk_default_prelight_fg;
223 style->fg[GTK_STATE_SELECTED] = gtk_default_selected_fg;
224 style->fg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
226 style->bg[GTK_STATE_NORMAL] = gtk_default_normal_bg;
227 style->bg[GTK_STATE_ACTIVE] = gtk_default_active_bg;
228 style->bg[GTK_STATE_PRELIGHT] = gtk_default_prelight_bg;
229 style->bg[GTK_STATE_SELECTED] = gtk_default_selected_bg;
230 style->bg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_bg;
232 for (i = 0; i < 5; i++)
234 style->text[i] = style->fg[i];
235 style->base[i] = style->white;
238 for (i = 0; i < 5; i++)
239 style->bg_pixmap[i] = NULL;
241 for (i = 0; i < 5; i++)
243 style->fg_gc[i] = NULL;
244 style->bg_gc[i] = NULL;
245 style->light_gc[i] = NULL;
246 style->dark_gc[i] = NULL;
247 style->mid_gc[i] = NULL;
248 style->text_gc[i] = NULL;
249 style->base_gc[i] = NULL;
252 unattached_styles = g_slist_prepend (unattached_styles, style);
258 gtk_style_attach (GtkStyle *style,
262 GdkColormap *colormap;
265 g_return_val_if_fail (style != NULL, NULL);
266 g_return_val_if_fail (window != NULL, NULL);
268 colormap = gdk_window_get_colormap (window);
269 depth = gdk_window_get_visual (window)->depth;
271 new_style = gtk_style_find (style, colormap, depth);
273 if (new_style && (new_style != style))
275 gtk_style_unref (style);
277 gtk_style_ref (style);
280 if (style->attach_count == 0)
281 unattached_styles = g_slist_remove (unattached_styles, style);
283 style->attach_count += 1;
289 gtk_style_detach (GtkStyle *style)
293 g_return_if_fail (style != NULL);
295 style->attach_count -= 1;
296 if (style->attach_count == 0)
298 unattached_styles = g_slist_prepend (unattached_styles, style);
300 gtk_gc_release (style->black_gc);
301 gtk_gc_release (style->white_gc);
303 style->black_gc = NULL;
304 style->white_gc = NULL;
306 for (i = 0; i < 5; i++)
308 gtk_gc_release (style->fg_gc[i]);
309 gtk_gc_release (style->bg_gc[i]);
310 gtk_gc_release (style->light_gc[i]);
311 gtk_gc_release (style->dark_gc[i]);
312 gtk_gc_release (style->mid_gc[i]);
313 gtk_gc_release (style->text_gc[i]);
314 gtk_gc_release (style->base_gc[i]);
316 style->fg_gc[i] = NULL;
317 style->bg_gc[i] = NULL;
318 style->light_gc[i] = NULL;
319 style->dark_gc[i] = NULL;
320 style->mid_gc[i] = NULL;
321 style->text_gc[i] = NULL;
322 style->base_gc[i] = NULL;
326 style->colormap = NULL;
329 gtk_style_remove (style);
333 gtk_style_ref (GtkStyle *style)
335 g_return_val_if_fail (style != NULL, NULL);
337 style->ref_count += 1;
342 gtk_style_unref (GtkStyle *style)
344 g_return_if_fail (style != NULL);
346 style->ref_count -= 1;
347 if (style->ref_count == 0)
348 gtk_style_destroy (style);
352 gtk_style_set_background (GtkStyle *style,
354 GtkStateType state_type)
357 gint parent_relative;
359 g_return_if_fail (style != NULL);
360 g_return_if_fail (window != NULL);
362 if (style->bg_pixmap[state_type])
364 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
367 parent_relative = TRUE;
371 pixmap = style->bg_pixmap[state_type];
372 parent_relative = FALSE;
375 gdk_window_set_back_pixmap (window, pixmap, parent_relative);
378 gdk_window_set_background (window, &style->bg[state_type]);
383 gtk_draw_hline (GtkStyle *style,
385 GtkStateType state_type,
390 g_return_if_fail (style != NULL);
391 g_return_if_fail (style->klass != NULL);
392 g_return_if_fail (style->klass->draw_hline != NULL);
394 (*style->klass->draw_hline) (style, window, state_type, x1, x2, y);
399 gtk_draw_vline (GtkStyle *style,
401 GtkStateType state_type,
406 g_return_if_fail (style != NULL);
407 g_return_if_fail (style->klass != NULL);
408 g_return_if_fail (style->klass->draw_vline != NULL);
410 (*style->klass->draw_vline) (style, window, state_type, y1, y2, x);
415 gtk_draw_shadow (GtkStyle *style,
417 GtkStateType state_type,
418 GtkShadowType shadow_type,
424 g_return_if_fail (style != NULL);
425 g_return_if_fail (style->klass != NULL);
426 g_return_if_fail (style->klass->draw_shadow != NULL);
428 (*style->klass->draw_shadow) (style, window, state_type, shadow_type, x, y, width, height);
432 gtk_draw_polygon (GtkStyle *style,
434 GtkStateType state_type,
435 GtkShadowType shadow_type,
440 g_return_if_fail (style != NULL);
441 g_return_if_fail (style->klass != NULL);
442 g_return_if_fail (style->klass->draw_shadow != NULL);
444 (*style->klass->draw_polygon) (style, window, state_type, shadow_type, points, npoints, fill);
448 gtk_draw_arrow (GtkStyle *style,
450 GtkStateType state_type,
451 GtkShadowType shadow_type,
452 GtkArrowType arrow_type,
459 g_return_if_fail (style != NULL);
460 g_return_if_fail (style->klass != NULL);
461 g_return_if_fail (style->klass->draw_arrow != NULL);
463 (*style->klass->draw_arrow) (style, window, state_type, shadow_type, arrow_type, fill, x, y, width, height);
468 gtk_draw_diamond (GtkStyle *style,
470 GtkStateType state_type,
471 GtkShadowType shadow_type,
477 g_return_if_fail (style != NULL);
478 g_return_if_fail (style->klass != NULL);
479 g_return_if_fail (style->klass->draw_diamond != NULL);
481 (*style->klass->draw_diamond) (style, window, state_type, shadow_type, x, y, width, height);
486 gtk_draw_oval (GtkStyle *style,
488 GtkStateType state_type,
489 GtkShadowType shadow_type,
495 g_return_if_fail (style != NULL);
496 g_return_if_fail (style->klass != NULL);
497 g_return_if_fail (style->klass->draw_oval != NULL);
499 (*style->klass->draw_oval) (style, window, state_type, shadow_type, x, y, width, height);
503 gtk_draw_string (GtkStyle *style,
505 GtkStateType state_type,
510 g_return_if_fail (style != NULL);
511 g_return_if_fail (style->klass != NULL);
512 g_return_if_fail (style->klass->draw_oval != NULL);
514 (*style->klass->draw_string) (style, window, state_type, x, y, string);
519 gtk_style_init (GtkStyle *style)
521 GdkGCValues gc_values;
522 GdkGCValuesMask gc_values_mask;
523 GdkColormap *colormap;
526 g_return_if_fail (style != NULL);
528 if (style->attach_count == 0)
530 for (i = 0; i < 5; i++)
532 gtk_style_shade (&style->bg[i], &style->light[i], LIGHTNESS_MULT);
533 gtk_style_shade (&style->bg[i], &style->dark[i], DARKNESS_MULT);
535 style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
536 style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
537 style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
540 colormap = style->colormap;
542 gdk_color_black (colormap, &style->black);
543 gdk_color_white (colormap, &style->white);
545 gc_values_mask = GDK_GC_FOREGROUND | GDK_GC_FONT;
546 if (style->font->type == GDK_FONT_FONT)
548 gc_values.font = style->font;
550 else if (style->font->type == GDK_FONT_FONTSET)
552 gc_values.font = default_font;
555 gc_values.foreground = style->black;
556 style->black_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
558 gc_values.foreground = style->white;
559 style->white_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
561 for (i = 0; i < 5; i++)
563 if (!gdk_color_alloc (colormap, &style->fg[i]))
564 g_warning ("unable to allocate color: ( %d %d %d )",
565 style->fg[i].red, style->fg[i].green, style->fg[i].blue);
566 if (!gdk_color_alloc (colormap, &style->bg[i]))
567 g_warning ("unable to allocate color: ( %d %d %d )",
568 style->bg[i].red, style->bg[i].green, style->bg[i].blue);
569 if (!gdk_color_alloc (colormap, &style->light[i]))
570 g_warning ("unable to allocate color: ( %d %d %d )",
571 style->light[i].red, style->light[i].green, style->light[i].blue);
572 if (!gdk_color_alloc (colormap, &style->dark[i]))
573 g_warning ("unable to allocate color: ( %d %d %d )",
574 style->dark[i].red, style->dark[i].green, style->dark[i].blue);
575 if (!gdk_color_alloc (colormap, &style->mid[i]))
576 g_warning ("unable to allocate color: ( %d %d %d )",
577 style->mid[i].red, style->mid[i].green, style->mid[i].blue);
578 if (!gdk_color_alloc (colormap, &style->text[i]))
579 g_warning ("unable to allocate color: ( %d %d %d )",
580 style->text[i].red, style->text[i].green, style->text[i].blue);
581 if (!gdk_color_alloc (colormap, &style->base[i]))
582 g_warning ("unable to allocate color: ( %d %d %d )",
583 style->base[i].red, style->base[i].green, style->base[i].blue);
585 gc_values.foreground = style->fg[i];
586 style->fg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
588 gc_values.foreground = style->bg[i];
589 style->bg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
591 gc_values.foreground = style->light[i];
592 style->light_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
594 gc_values.foreground = style->dark[i];
595 style->dark_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
597 gc_values.foreground = style->mid[i];
598 style->mid_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
600 gc_values.foreground = style->text[i];
601 style->text_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
603 gc_values.foreground = style->base[i];
604 style->base_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
610 gtk_styles_init (void)
616 style_cache = g_cache_new ((GCacheNewFunc) gtk_style_new_from_key,
617 (GCacheDestroyFunc) gtk_style_unref,
618 (GCacheDupFunc) gtk_style_key_dup,
619 (GCacheDestroyFunc) gtk_style_key_destroy,
620 (GHashFunc) gtk_style_key_hash,
621 (GHashFunc) gtk_style_value_hash,
622 (GCompareFunc) gtk_style_key_compare);
627 gtk_style_remove (GtkStyle *style)
631 g_cache_remove (style_cache, style);
635 gtk_style_find (GtkStyle *style,
645 for (i = 0; i < 5; i++)
647 key.fg[i] = style->fg[i];
648 key.bg[i] = style->bg[i];
649 key.text[i] = style->text[i];
650 key.base[i] = style->base[i];
651 key.bg_pixmap[i] = style->bg_pixmap[i];
654 key.font = style->font;
655 key.klass = style->klass;
659 style = g_cache_insert (style_cache, &key);
665 gtk_style_new_from_key (GtkStyleKey *key)
672 list = unattached_styles;
679 if ((style->depth != -1) && (style->depth != key->depth))
684 if (style->colormap && (style->colormap != key->colormap))
689 if (style->klass != key->klass)
694 if (!gdk_font_equal (style->font, key->font))
700 for (i = 0; style && (i < 5); i++)
702 if (style->bg_pixmap[i] != key->bg_pixmap[i])
708 if ((style->fg[i].red != key->fg[i].red) ||
709 (style->fg[i].green != key->fg[i].green) ||
710 (style->fg[i].blue != key->fg[i].blue))
716 if ((style->bg[i].red != key->bg[i].red) ||
717 (style->bg[i].green != key->bg[i].green) ||
718 (style->bg[i].blue != key->bg[i].blue))
724 if ((style->text[i].red != key->text[i].red) ||
725 (style->text[i].green != key->text[i].green) ||
726 (style->text[i].blue != key->text[i].blue))
732 if ((style->base[i].red != key->base[i].red) ||
733 (style->base[i].green != key->base[i].green) ||
734 (style->base[i].blue != key->base[i].blue))
743 gtk_style_ref (style);
750 style = g_new0 (GtkStyle, 1);
752 style->ref_count = 1;
753 style->attach_count = 0;
755 style->font = key->font;
756 gdk_font_ref (style->font);
758 style->depth = key->depth;
759 style->colormap = key->colormap;
760 style->klass = key->klass;
762 style->black.red = 0;
763 style->black.green = 0;
764 style->black.blue = 0;
766 style->white.red = 65535;
767 style->white.green = 65535;
768 style->white.blue = 65535;
770 style->black_gc = NULL;
771 style->white_gc = NULL;
773 for (i = 0; i < 5; i++)
775 style->fg[i] = key->fg[i];
776 style->bg[i] = key->bg[i];
777 style->text[i] = key->text[i];
778 style->base[i] = key->base[i];
781 for (i = 0; i < 5; i++)
782 style->bg_pixmap[i] = key->bg_pixmap[i];
784 for (i = 0; i < 5; i++)
786 style->fg_gc[i] = NULL;
787 style->bg_gc[i] = NULL;
788 style->light_gc[i] = NULL;
789 style->dark_gc[i] = NULL;
790 style->mid_gc[i] = NULL;
791 style->text_gc[i] = NULL;
792 style->base_gc[i] = NULL;
796 if (style->depth == -1)
797 style->depth = key->depth;
798 if (!style->colormap)
799 style->colormap = key->colormap;
801 gtk_style_init (style);
807 gtk_style_key_dup (GtkStyleKey *key)
809 GtkStyleKey *new_key;
812 key_mem_chunk = g_mem_chunk_new ("key mem chunk", sizeof (GtkStyleKey),
813 1024, G_ALLOC_AND_FREE);
815 new_key = g_chunk_new (GtkStyleKey, key_mem_chunk);
823 gtk_style_destroy (GtkStyle *style)
827 if (style->attach_count > 0)
829 gtk_gc_release (style->black_gc);
830 gtk_gc_release (style->white_gc);
832 for (i = 0; i < 5; i++)
834 gtk_gc_release (style->fg_gc[i]);
835 gtk_gc_release (style->bg_gc[i]);
836 gtk_gc_release (style->light_gc[i]);
837 gtk_gc_release (style->dark_gc[i]);
838 gtk_gc_release (style->mid_gc[i]);
839 gtk_gc_release (style->text_gc[i]);
840 gtk_gc_release (style->base_gc[i]);
844 unattached_styles = g_slist_remove (unattached_styles, style);
846 gdk_font_unref (style->font);
851 gtk_style_key_destroy (GtkStyleKey *key)
853 g_mem_chunk_free (key_mem_chunk, key);
857 gtk_style_key_hash (GtkStyleKey *key)
864 for (i = 0; i < 5; i++)
866 hash_val += key->fg[i].red + key->fg[i].green + key->fg[i].blue;
867 hash_val += key->bg[i].red + key->bg[i].green + key->bg[i].blue;
868 hash_val += key->text[i].red + key->text[i].green + key->text[i].blue;
869 hash_val += key->base[i].red + key->base[i].green + key->base[i].blue;
872 hash_val += (guint) gdk_font_id (key->font);
873 hash_val += (guint) key->depth;
874 hash_val += (gulong) key->colormap;
875 hash_val += (gulong) key->klass;
881 gtk_style_value_hash (GtkStyle *style)
888 for (i = 0; i < 5; i++)
890 hash_val += style->fg[i].red + style->fg[i].green + style->fg[i].blue;
891 hash_val += style->bg[i].red + style->bg[i].green + style->bg[i].blue;
892 hash_val += style->text[i].red + style->text[i].green + style->text[i].blue;
893 hash_val += style->base[i].red + style->base[i].green + style->base[i].blue;
896 hash_val += (guint) gdk_font_id (style->font);
897 hash_val += (gulong) style->klass;
903 gtk_style_key_compare (GtkStyleKey *a,
908 if (a->depth != b->depth)
910 if (a->colormap != b->colormap)
912 if (a->klass != b->klass)
914 if (!gdk_font_equal (a->font, b->font))
917 for (i = 0; i < 5; i++)
919 if (a->bg_pixmap[i] != b->bg_pixmap[i])
922 if ((a->fg[i].red != b->fg[i].red) ||
923 (a->fg[i].green != b->fg[i].green) ||
924 (a->fg[i].blue != b->fg[i].blue))
926 if ((a->bg[i].red != b->bg[i].red) ||
927 (a->bg[i].green != b->bg[i].green) ||
928 (a->bg[i].blue != b->bg[i].blue))
930 if ((a->text[i].red != b->text[i].red) ||
931 (a->text[i].green != b->text[i].green) ||
932 (a->text[i].blue != b->text[i].blue))
934 if ((a->base[i].red != b->base[i].red) ||
935 (a->base[i].green != b->base[i].green) ||
936 (a->base[i].blue != b->base[i].blue))
945 gtk_default_draw_hline (GtkStyle *style,
947 GtkStateType state_type,
952 gint thickness_light;
956 g_return_if_fail (style != NULL);
957 g_return_if_fail (window != NULL);
959 thickness_light = style->klass->ythickness / 2;
960 thickness_dark = style->klass->ythickness - thickness_light;
962 for (i = 0; i < thickness_dark; i++)
964 gdk_draw_line (window, style->light_gc[state_type], x2 - i - 1, y + i, x2, y + i);
965 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x2 - i - 1, y + i);
969 for (i = 0; i < thickness_light; i++)
971 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x1 + thickness_light - i - 1, y + i);
972 gdk_draw_line (window, style->light_gc[state_type], x1 + thickness_light - i - 1, y + i, x2, y + i);
978 gtk_default_draw_vline (GtkStyle *style,
980 GtkStateType state_type,
985 gint thickness_light;
989 g_return_if_fail (style != NULL);
990 g_return_if_fail (window != NULL);
992 thickness_light = style->klass->xthickness / 2;
993 thickness_dark = style->klass->xthickness - thickness_light;
995 for (i = 0; i < thickness_dark; i++)
997 gdk_draw_line (window, style->light_gc[state_type], x + i, y2 - i - 1, x + i, y2);
998 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y2 - i - 1);
1001 x += thickness_dark;
1002 for (i = 0; i < thickness_light; i++)
1004 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y1 + thickness_light - i);
1005 gdk_draw_line (window, style->light_gc[state_type], x + i, y1 + thickness_light - i, x + i, y2);
1011 gtk_default_draw_shadow (GtkStyle *style,
1013 GtkStateType state_type,
1014 GtkShadowType shadow_type,
1022 gint thickness_light;
1023 gint thickness_dark;
1026 g_return_if_fail (style != NULL);
1027 g_return_if_fail (window != NULL);
1029 if ((width == -1) && (height == -1))
1030 gdk_window_get_size (window, &width, &height);
1031 else if (width == -1)
1032 gdk_window_get_size (window, &width, NULL);
1033 else if (height == -1)
1034 gdk_window_get_size (window, NULL, &height);
1036 switch (shadow_type)
1038 case GTK_SHADOW_NONE:
1043 case GTK_SHADOW_ETCHED_IN:
1044 gc1 = style->light_gc[state_type];
1045 gc2 = style->dark_gc[state_type];
1047 case GTK_SHADOW_OUT:
1048 case GTK_SHADOW_ETCHED_OUT:
1049 gc1 = style->dark_gc[state_type];
1050 gc2 = style->light_gc[state_type];
1054 switch (shadow_type)
1056 case GTK_SHADOW_NONE:
1060 gdk_draw_line (window, gc1,
1061 x, y + height - 1, x + width - 1, y + height - 1);
1062 gdk_draw_line (window, gc1,
1063 x + width - 1, y, x + width - 1, y + height - 1);
1065 gdk_draw_line (window, style->bg_gc[state_type],
1066 x + 1, y + height - 2, x + width - 2, y + height - 2);
1067 gdk_draw_line (window, style->bg_gc[state_type],
1068 x + width - 2, y + 1, x + width - 2, y + height - 2);
1070 gdk_draw_line (window, style->black_gc,
1071 x + 1, y + 1, x + width - 2, y + 1);
1072 gdk_draw_line (window, style->black_gc,
1073 x + 1, y + 1, x + 1, y + height - 2);
1075 gdk_draw_line (window, gc2,
1076 x, y, x + width - 1, y);
1077 gdk_draw_line (window, gc2,
1078 x, y, x, y + height - 1);
1081 case GTK_SHADOW_OUT:
1082 gdk_draw_line (window, gc1,
1083 x + 1, y + height - 2, x + width - 2, y + height - 2);
1084 gdk_draw_line (window, gc1,
1085 x + width - 2, y + 1, x + width - 2, y + height - 2);
1087 gdk_draw_line (window, gc2,
1088 x, y, x + width - 1, y);
1089 gdk_draw_line (window, gc2,
1090 x, y, x, y + height - 1);
1092 gdk_draw_line (window, style->bg_gc[state_type],
1093 x + 1, y + 1, x + width - 2, y + 1);
1094 gdk_draw_line (window, style->bg_gc[state_type],
1095 x + 1, y + 1, x + 1, y + height - 2);
1097 gdk_draw_line (window, style->black_gc,
1098 x, y + height - 1, x + width - 1, y + height - 1);
1099 gdk_draw_line (window, style->black_gc,
1100 x + width - 1, y, x + width - 1, y + height - 1);
1103 case GTK_SHADOW_ETCHED_IN:
1104 case GTK_SHADOW_ETCHED_OUT:
1105 thickness_light = 1;
1108 for (i = 0; i < thickness_dark; i++)
1110 gdk_draw_line (window, gc1,
1114 y + height - i - 1);
1115 gdk_draw_line (window, gc1,
1119 y + height - i - 1);
1121 gdk_draw_line (window, gc2,
1126 gdk_draw_line (window, gc2,
1130 y + height - i - 2);
1133 for (i = 0; i < thickness_light; i++)
1135 gdk_draw_line (window, gc1,
1136 x + thickness_dark + i,
1137 y + thickness_dark + i,
1138 x + width - thickness_dark - i - 1,
1139 y + thickness_dark + i);
1140 gdk_draw_line (window, gc1,
1141 x + thickness_dark + i,
1142 y + thickness_dark + i,
1143 x + thickness_dark + i,
1144 y + height - thickness_dark - i - 1);
1146 gdk_draw_line (window, gc2,
1147 x + thickness_dark + i,
1148 y + height - thickness_light - i - 1,
1149 x + width - thickness_light - 1,
1150 y + height - thickness_light - i - 1);
1151 gdk_draw_line (window, gc2,
1152 x + width - thickness_light - i - 1,
1153 y + thickness_dark + i,
1154 x + width - thickness_light - i - 1,
1155 y + height - thickness_light - 1);
1163 gtk_default_draw_polygon (GtkStyle *style,
1165 GtkStateType state_type,
1166 GtkShadowType shadow_type,
1172 #define M_PI 3.14159265358979323846
1175 #define M_PI_4 0.78539816339744830962
1178 static const gdouble pi_over_4 = M_PI_4;
1179 static const gdouble pi_3_over_4 = M_PI_4 * 3;
1190 g_return_if_fail (style != NULL);
1191 g_return_if_fail (window != NULL);
1192 g_return_if_fail (points != NULL);
1194 switch (shadow_type)
1197 gc1 = style->bg_gc[state_type];
1198 gc2 = style->dark_gc[state_type];
1199 gc3 = style->light_gc[state_type];
1200 gc4 = style->black_gc;
1202 case GTK_SHADOW_OUT:
1203 gc1 = style->dark_gc[state_type];
1204 gc2 = style->light_gc[state_type];
1205 gc3 = style->black_gc;
1206 gc4 = style->bg_gc[state_type];
1213 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, npoints);
1217 for (i = 0; i < npoints; i++)
1219 if ((points[i].x == points[i+1].x) &&
1220 (points[i].y == points[i+1].y))
1226 angle = atan2 (points[i+1].y - points[i].y,
1227 points[i+1].x - points[i].x);
1230 if ((angle > -pi_3_over_4) && (angle < pi_over_4))
1232 if (angle > -pi_over_4)
1243 gdk_draw_line (window, gc1,
1244 points[i].x-xadjust, points[i].y-yadjust,
1245 points[i+1].x-xadjust, points[i+1].y-yadjust);
1246 gdk_draw_line (window, gc3,
1247 points[i].x, points[i].y,
1248 points[i+1].x, points[i+1].y);
1252 if ((angle < -pi_3_over_4) || (angle > pi_3_over_4))
1263 gdk_draw_line (window, gc4,
1264 points[i].x+xadjust, points[i].y+yadjust,
1265 points[i+1].x+xadjust, points[i+1].y+yadjust);
1266 gdk_draw_line (window, gc2,
1267 points[i].x, points[i].y,
1268 points[i+1].x, points[i+1].y);
1275 gtk_default_draw_arrow (GtkStyle *style,
1277 GtkStateType state_type,
1278 GtkShadowType shadow_type,
1279 GtkArrowType arrow_type,
1294 g_return_if_fail (style != NULL);
1295 g_return_if_fail (window != NULL);
1297 switch (shadow_type)
1300 gc1 = style->bg_gc[state_type];
1301 gc2 = style->dark_gc[state_type];
1302 gc3 = style->light_gc[state_type];
1303 gc4 = style->black_gc;
1305 case GTK_SHADOW_OUT:
1306 gc1 = style->dark_gc[state_type];
1307 gc2 = style->light_gc[state_type];
1308 gc3 = style->black_gc;
1309 gc4 = style->bg_gc[state_type];
1315 if ((width == -1) && (height == -1))
1316 gdk_window_get_size (window, &width, &height);
1317 else if (width == -1)
1318 gdk_window_get_size (window, &width, NULL);
1319 else if (height == -1)
1320 gdk_window_get_size (window, NULL, &height);
1322 half_width = width / 2;
1323 half_height = height / 2;
1330 points[0].x = x + half_width;
1333 points[1].y = y + height - 1;
1334 points[2].x = x + width - 1;
1335 points[2].y = y + height - 1;
1337 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
1340 gdk_draw_line (window, gc1,
1341 x + 1, y + height - 2,
1342 x + width - 2, y + height - 2);
1343 gdk_draw_line (window, gc3,
1344 x + 0, y + height - 1,
1345 x + width - 1, y + height - 1);
1347 gdk_draw_line (window, gc1,
1348 x + width - 2, y + height - 1,
1349 x + half_width, y + 1);
1350 gdk_draw_line (window, gc3,
1351 x + width - 1, y + height - 1,
1354 gdk_draw_line (window, gc4,
1355 x + half_width, y + 1,
1356 x + 1, y + height - 1);
1357 gdk_draw_line (window, gc2,
1361 case GTK_ARROW_DOWN:
1364 points[0].x = x + width - 1;
1368 points[2].x = x + half_width;
1369 points[2].y = y + height - 1;
1371 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
1374 gdk_draw_line (window, gc4,
1376 y + 1, x + 1, y + 1);
1377 gdk_draw_line (window, gc2,
1381 gdk_draw_line (window, gc4,
1383 x + half_width, y + height - 2);
1384 gdk_draw_line (window, gc2,
1386 x + half_width, y + height - 1);
1388 gdk_draw_line (window, gc1,
1389 x + half_width, y + height - 2,
1391 gdk_draw_line (window, gc3,
1392 x + half_width, y + height - 1,
1395 case GTK_ARROW_LEFT:
1399 points[0].y = y + half_height;
1400 points[1].x = x + width - 1;
1401 points[1].y = y + height - 1;
1402 points[2].x = x + width - 1;
1405 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
1408 gdk_draw_line (window, gc1,
1409 x + 1, y + half_height,
1410 x + width - 1, y + height - 1);
1411 gdk_draw_line (window, gc3,
1413 x + width - 1, y + height - 1);
1415 gdk_draw_line (window, gc1,
1416 x + width - 2, y + height - 1,
1417 x + width - 2, y + 1);
1418 gdk_draw_line (window, gc3,
1419 x + width - 1, y + height - 1,
1422 gdk_draw_line (window, gc4,
1423 x + width - 1, y + 1,
1424 x + 1, y + half_height);
1425 gdk_draw_line (window, gc2,
1427 x, y + half_height);
1429 case GTK_ARROW_RIGHT:
1432 points[0].x = x + width - 1;
1433 points[0].y = y + half_height;
1437 points[2].y = y + height - 1;
1439 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
1442 gdk_draw_line (window, gc4,
1443 x + width - 1, y + half_height,
1445 gdk_draw_line (window, gc2,
1446 x + width - 1, y + half_height,
1449 gdk_draw_line (window, gc4,
1451 x + 1, y + height - 2);
1452 gdk_draw_line (window, gc2,
1456 gdk_draw_line (window, gc1,
1457 x + 1, y + height - 2,
1458 x + width - 1, y + half_height);
1459 gdk_draw_line (window, gc3,
1461 x + width - 1, y + half_height);
1468 gtk_default_draw_diamond (GtkStyle *style,
1470 GtkStateType state_type,
1471 GtkShadowType shadow_type,
1480 g_return_if_fail (style != NULL);
1481 g_return_if_fail (window != NULL);
1483 if ((width == -1) && (height == -1))
1484 gdk_window_get_size (window, &width, &height);
1485 else if (width == -1)
1486 gdk_window_get_size (window, &width, NULL);
1487 else if (height == -1)
1488 gdk_window_get_size (window, NULL, &height);
1490 half_width = width / 2;
1491 half_height = height / 2;
1493 switch (shadow_type)
1496 gdk_draw_line (window, style->bg_gc[state_type],
1497 x + 2, y + half_height,
1498 x + half_width, y + height - 2);
1499 gdk_draw_line (window, style->bg_gc[state_type],
1500 x + half_width, y + height - 2,
1501 x + width - 2, y + half_height);
1502 gdk_draw_line (window, style->light_gc[state_type],
1503 x + 1, y + half_height,
1504 x + half_width, y + height - 1);
1505 gdk_draw_line (window, style->light_gc[state_type],
1506 x + half_width, y + height - 1,
1507 x + width - 1, y + half_height);
1508 gdk_draw_line (window, style->light_gc[state_type],
1510 x + half_width, y + height);
1511 gdk_draw_line (window, style->light_gc[state_type],
1512 x + half_width, y + height,
1513 x + width, y + half_height);
1515 gdk_draw_line (window, style->black_gc,
1516 x + 2, y + half_height,
1517 x + half_width, y + 2);
1518 gdk_draw_line (window, style->black_gc,
1519 x + half_width, y + 2,
1520 x + width - 2, y + half_height);
1521 gdk_draw_line (window, style->dark_gc[state_type],
1522 x + 1, y + half_height,
1523 x + half_width, y + 1);
1524 gdk_draw_line (window, style->dark_gc[state_type],
1525 x + half_width, y + 1,
1526 x + width - 1, y + half_height);
1527 gdk_draw_line (window, style->dark_gc[state_type],
1530 gdk_draw_line (window, style->dark_gc[state_type],
1532 x + width, y + half_height);
1534 case GTK_SHADOW_OUT:
1535 gdk_draw_line (window, style->dark_gc[state_type],
1536 x + 2, y + half_height,
1537 x + half_width, y + height - 2);
1538 gdk_draw_line (window, style->dark_gc[state_type],
1539 x + half_width, y + height - 2,
1540 x + width - 2, y + half_height);
1541 gdk_draw_line (window, style->dark_gc[state_type],
1542 x + 1, y + half_height,
1543 x + half_width, y + height - 1);
1544 gdk_draw_line (window, style->dark_gc[state_type],
1545 x + half_width, y + height - 1,
1546 x + width - 1, y + half_height);
1547 gdk_draw_line (window, style->black_gc,
1549 x + half_width, y + height);
1550 gdk_draw_line (window, style->black_gc,
1551 x + half_width, y + height,
1552 x + width, y + half_height);
1554 gdk_draw_line (window, style->bg_gc[state_type],
1555 x + 2, y + half_height,
1556 x + half_width, y + 2);
1557 gdk_draw_line (window, style->bg_gc[state_type],
1558 x + half_width, y + 2,
1559 x + width - 2, y + half_height);
1560 gdk_draw_line (window, style->light_gc[state_type],
1561 x + 1, y + half_height,
1562 x + half_width, y + 1);
1563 gdk_draw_line (window, style->light_gc[state_type],
1564 x + half_width, y + 1,
1565 x + width - 1, y + half_height);
1566 gdk_draw_line (window, style->light_gc[state_type],
1569 gdk_draw_line (window, style->light_gc[state_type],
1571 x + width, y + half_height);
1580 gtk_default_draw_oval (GtkStyle *style,
1582 GtkStateType state_type,
1583 GtkShadowType shadow_type,
1589 g_return_if_fail (style != NULL);
1590 g_return_if_fail (window != NULL);
1594 gtk_default_draw_string (GtkStyle *style,
1596 GtkStateType state_type,
1599 const gchar *string)
1601 g_return_if_fail (style != NULL);
1602 g_return_if_fail (window != NULL);
1604 if (state_type == GTK_STATE_INSENSITIVE)
1605 gdk_draw_string (window, style->font, style->white_gc, x + 1, y + 1, string);
1606 gdk_draw_string (window, style->font, style->fg_gc[state_type], x, y, string);
1611 gtk_style_shade (GdkColor *a,
1619 red = (gdouble) a->red / 65535.0;
1620 green = (gdouble) a->green / 65535.0;
1621 blue = (gdouble) a->blue / 65535.0;
1623 rgb_to_hls (&red, &green, &blue);
1628 else if (green < 0.0)
1634 else if (blue < 0.0)
1637 hls_to_rgb (&red, &green, &blue);
1639 b->red = red * 65535.0;
1640 b->green = green * 65535.0;
1641 b->blue = blue * 65535.0;
1645 rgb_to_hls (gdouble *r,
1686 l = (max + min) / 2;
1693 s = (max - min) / (max + min);
1695 s = (max - min) / (2 - max - min);
1699 h = (green - blue) / delta;
1700 else if (green == max)
1701 h = 2 + (blue - red) / delta;
1702 else if (blue == max)
1703 h = 4 + (red - green) / delta;
1716 hls_to_rgb (gdouble *h,
1729 if (lightness <= 0.5)
1730 m2 = lightness * (1 + saturation);
1732 m2 = lightness + saturation - lightness * saturation;
1733 m1 = 2 * lightness - m2;
1735 if (saturation == 0)
1750 r = m1 + (m2 - m1) * hue / 60;
1754 r = m1 + (m2 - m1) * (240 - hue) / 60;
1765 g = m1 + (m2 - m1) * hue / 60;
1769 g = m1 + (m2 - m1) * (240 - hue) / 60;
1780 b = m1 + (m2 - m1) * hue / 60;
1784 b = m1 + (m2 - m1) * (240 - hue) / 60;