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 < 4; i++)
234 style->text[i] = style->fg[i];
235 style->base[i] = style->white;
238 style->base[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_bg;
239 style->text[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_bg;
241 for (i = 0; i < 5; i++)
242 style->bg_pixmap[i] = NULL;
244 for (i = 0; i < 5; i++)
246 style->fg_gc[i] = NULL;
247 style->bg_gc[i] = NULL;
248 style->light_gc[i] = NULL;
249 style->dark_gc[i] = NULL;
250 style->mid_gc[i] = NULL;
251 style->text_gc[i] = NULL;
252 style->base_gc[i] = NULL;
255 unattached_styles = g_slist_prepend (unattached_styles, style);
261 gtk_style_attach (GtkStyle *style,
265 GdkColormap *colormap;
268 g_return_val_if_fail (style != NULL, NULL);
269 g_return_val_if_fail (window != NULL, NULL);
271 colormap = gdk_window_get_colormap (window);
272 depth = gdk_window_get_visual (window)->depth;
274 new_style = gtk_style_find (style, colormap, depth);
276 if (new_style && (new_style != style))
278 gtk_style_unref (style);
280 gtk_style_ref (style);
283 if (style->attach_count == 0)
284 unattached_styles = g_slist_remove (unattached_styles, style);
286 style->attach_count += 1;
292 gtk_style_detach (GtkStyle *style)
296 g_return_if_fail (style != NULL);
298 style->attach_count -= 1;
299 if (style->attach_count == 0)
301 unattached_styles = g_slist_prepend (unattached_styles, style);
303 gtk_gc_release (style->black_gc);
304 gtk_gc_release (style->white_gc);
306 style->black_gc = NULL;
307 style->white_gc = NULL;
309 for (i = 0; i < 5; i++)
311 gtk_gc_release (style->fg_gc[i]);
312 gtk_gc_release (style->bg_gc[i]);
313 gtk_gc_release (style->light_gc[i]);
314 gtk_gc_release (style->dark_gc[i]);
315 gtk_gc_release (style->mid_gc[i]);
316 gtk_gc_release (style->text_gc[i]);
317 gtk_gc_release (style->base_gc[i]);
319 style->fg_gc[i] = NULL;
320 style->bg_gc[i] = NULL;
321 style->light_gc[i] = NULL;
322 style->dark_gc[i] = NULL;
323 style->mid_gc[i] = NULL;
324 style->text_gc[i] = NULL;
325 style->base_gc[i] = NULL;
329 style->colormap = NULL;
332 gtk_style_remove (style);
336 gtk_style_ref (GtkStyle *style)
338 g_return_val_if_fail (style != NULL, NULL);
340 style->ref_count += 1;
345 gtk_style_unref (GtkStyle *style)
347 g_return_if_fail (style != NULL);
349 style->ref_count -= 1;
350 if (style->ref_count == 0)
351 gtk_style_destroy (style);
355 gtk_style_set_background (GtkStyle *style,
357 GtkStateType state_type)
360 gint parent_relative;
362 g_return_if_fail (style != NULL);
363 g_return_if_fail (window != NULL);
365 if (style->bg_pixmap[state_type])
367 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
370 parent_relative = TRUE;
374 pixmap = style->bg_pixmap[state_type];
375 parent_relative = FALSE;
378 gdk_window_set_back_pixmap (window, pixmap, parent_relative);
381 gdk_window_set_background (window, &style->bg[state_type]);
386 gtk_draw_hline (GtkStyle *style,
388 GtkStateType state_type,
393 g_return_if_fail (style != NULL);
394 g_return_if_fail (style->klass != NULL);
395 g_return_if_fail (style->klass->draw_hline != NULL);
397 (*style->klass->draw_hline) (style, window, state_type, x1, x2, y);
402 gtk_draw_vline (GtkStyle *style,
404 GtkStateType state_type,
409 g_return_if_fail (style != NULL);
410 g_return_if_fail (style->klass != NULL);
411 g_return_if_fail (style->klass->draw_vline != NULL);
413 (*style->klass->draw_vline) (style, window, state_type, y1, y2, x);
418 gtk_draw_shadow (GtkStyle *style,
420 GtkStateType state_type,
421 GtkShadowType shadow_type,
427 g_return_if_fail (style != NULL);
428 g_return_if_fail (style->klass != NULL);
429 g_return_if_fail (style->klass->draw_shadow != NULL);
431 (*style->klass->draw_shadow) (style, window, state_type, shadow_type, x, y, width, height);
435 gtk_draw_polygon (GtkStyle *style,
437 GtkStateType state_type,
438 GtkShadowType shadow_type,
443 g_return_if_fail (style != NULL);
444 g_return_if_fail (style->klass != NULL);
445 g_return_if_fail (style->klass->draw_shadow != NULL);
447 (*style->klass->draw_polygon) (style, window, state_type, shadow_type, points, npoints, fill);
451 gtk_draw_arrow (GtkStyle *style,
453 GtkStateType state_type,
454 GtkShadowType shadow_type,
455 GtkArrowType arrow_type,
462 g_return_if_fail (style != NULL);
463 g_return_if_fail (style->klass != NULL);
464 g_return_if_fail (style->klass->draw_arrow != NULL);
466 (*style->klass->draw_arrow) (style, window, state_type, shadow_type, arrow_type, fill, x, y, width, height);
471 gtk_draw_diamond (GtkStyle *style,
473 GtkStateType state_type,
474 GtkShadowType shadow_type,
480 g_return_if_fail (style != NULL);
481 g_return_if_fail (style->klass != NULL);
482 g_return_if_fail (style->klass->draw_diamond != NULL);
484 (*style->klass->draw_diamond) (style, window, state_type, shadow_type, x, y, width, height);
489 gtk_draw_oval (GtkStyle *style,
491 GtkStateType state_type,
492 GtkShadowType shadow_type,
498 g_return_if_fail (style != NULL);
499 g_return_if_fail (style->klass != NULL);
500 g_return_if_fail (style->klass->draw_oval != NULL);
502 (*style->klass->draw_oval) (style, window, state_type, shadow_type, x, y, width, height);
506 gtk_draw_string (GtkStyle *style,
508 GtkStateType state_type,
513 g_return_if_fail (style != NULL);
514 g_return_if_fail (style->klass != NULL);
515 g_return_if_fail (style->klass->draw_oval != NULL);
517 (*style->klass->draw_string) (style, window, state_type, x, y, string);
522 gtk_style_init (GtkStyle *style)
524 GdkGCValues gc_values;
525 GdkGCValuesMask gc_values_mask;
526 GdkColormap *colormap;
529 g_return_if_fail (style != NULL);
531 if (style->attach_count == 0)
533 for (i = 0; i < 5; i++)
535 gtk_style_shade (&style->bg[i], &style->light[i], LIGHTNESS_MULT);
536 gtk_style_shade (&style->bg[i], &style->dark[i], DARKNESS_MULT);
538 style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
539 style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
540 style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
543 colormap = style->colormap;
545 gdk_color_black (colormap, &style->black);
546 gdk_color_white (colormap, &style->white);
548 gc_values_mask = GDK_GC_FOREGROUND | GDK_GC_FONT;
549 if (style->font->type == GDK_FONT_FONT)
551 gc_values.font = style->font;
553 else if (style->font->type == GDK_FONT_FONTSET)
555 gc_values.font = default_font;
558 gc_values.foreground = style->black;
559 style->black_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
561 gc_values.foreground = style->white;
562 style->white_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
564 for (i = 0; i < 5; i++)
566 if (!gdk_color_alloc (colormap, &style->fg[i]))
567 g_warning ("unable to allocate color: ( %d %d %d )",
568 style->fg[i].red, style->fg[i].green, style->fg[i].blue);
569 if (!gdk_color_alloc (colormap, &style->bg[i]))
570 g_warning ("unable to allocate color: ( %d %d %d )",
571 style->bg[i].red, style->bg[i].green, style->bg[i].blue);
572 if (!gdk_color_alloc (colormap, &style->light[i]))
573 g_warning ("unable to allocate color: ( %d %d %d )",
574 style->light[i].red, style->light[i].green, style->light[i].blue);
575 if (!gdk_color_alloc (colormap, &style->dark[i]))
576 g_warning ("unable to allocate color: ( %d %d %d )",
577 style->dark[i].red, style->dark[i].green, style->dark[i].blue);
578 if (!gdk_color_alloc (colormap, &style->mid[i]))
579 g_warning ("unable to allocate color: ( %d %d %d )",
580 style->mid[i].red, style->mid[i].green, style->mid[i].blue);
581 if (!gdk_color_alloc (colormap, &style->text[i]))
582 g_warning ("unable to allocate color: ( %d %d %d )",
583 style->text[i].red, style->text[i].green, style->text[i].blue);
584 if (!gdk_color_alloc (colormap, &style->base[i]))
585 g_warning ("unable to allocate color: ( %d %d %d )",
586 style->base[i].red, style->base[i].green, style->base[i].blue);
588 gc_values.foreground = style->fg[i];
589 style->fg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
591 gc_values.foreground = style->bg[i];
592 style->bg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
594 gc_values.foreground = style->light[i];
595 style->light_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
597 gc_values.foreground = style->dark[i];
598 style->dark_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
600 gc_values.foreground = style->mid[i];
601 style->mid_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
603 gc_values.foreground = style->text[i];
604 style->text_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
606 gc_values.foreground = style->base[i];
607 style->base_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
613 gtk_styles_init (void)
619 style_cache = g_cache_new ((GCacheNewFunc) gtk_style_new_from_key,
620 (GCacheDestroyFunc) gtk_style_unref,
621 (GCacheDupFunc) gtk_style_key_dup,
622 (GCacheDestroyFunc) gtk_style_key_destroy,
623 (GHashFunc) gtk_style_key_hash,
624 (GHashFunc) gtk_style_value_hash,
625 (GCompareFunc) gtk_style_key_compare);
630 gtk_style_remove (GtkStyle *style)
634 g_cache_remove (style_cache, style);
638 gtk_style_find (GtkStyle *style,
648 for (i = 0; i < 5; i++)
650 key.fg[i] = style->fg[i];
651 key.bg[i] = style->bg[i];
652 key.text[i] = style->text[i];
653 key.base[i] = style->base[i];
654 key.bg_pixmap[i] = style->bg_pixmap[i];
657 key.font = style->font;
658 key.klass = style->klass;
662 style = g_cache_insert (style_cache, &key);
668 gtk_style_new_from_key (GtkStyleKey *key)
675 list = unattached_styles;
682 if ((style->depth != -1) && (style->depth != key->depth))
687 if (style->colormap && (style->colormap != key->colormap))
692 if (style->klass != key->klass)
697 if (!gdk_font_equal (style->font, key->font))
703 for (i = 0; style && (i < 5); i++)
705 if (style->bg_pixmap[i] != key->bg_pixmap[i])
711 if ((style->fg[i].red != key->fg[i].red) ||
712 (style->fg[i].green != key->fg[i].green) ||
713 (style->fg[i].blue != key->fg[i].blue))
719 if ((style->bg[i].red != key->bg[i].red) ||
720 (style->bg[i].green != key->bg[i].green) ||
721 (style->bg[i].blue != key->bg[i].blue))
727 if ((style->text[i].red != key->text[i].red) ||
728 (style->text[i].green != key->text[i].green) ||
729 (style->text[i].blue != key->text[i].blue))
735 if ((style->base[i].red != key->base[i].red) ||
736 (style->base[i].green != key->base[i].green) ||
737 (style->base[i].blue != key->base[i].blue))
746 gtk_style_ref (style);
753 style = g_new0 (GtkStyle, 1);
755 style->ref_count = 1;
756 style->attach_count = 0;
758 style->font = key->font;
759 gdk_font_ref (style->font);
761 style->depth = key->depth;
762 style->colormap = key->colormap;
763 style->klass = key->klass;
765 style->black.red = 0;
766 style->black.green = 0;
767 style->black.blue = 0;
769 style->white.red = 65535;
770 style->white.green = 65535;
771 style->white.blue = 65535;
773 style->black_gc = NULL;
774 style->white_gc = NULL;
776 for (i = 0; i < 5; i++)
778 style->fg[i] = key->fg[i];
779 style->bg[i] = key->bg[i];
780 style->text[i] = key->text[i];
781 style->base[i] = key->base[i];
784 for (i = 0; i < 5; i++)
785 style->bg_pixmap[i] = key->bg_pixmap[i];
787 for (i = 0; i < 5; i++)
789 style->fg_gc[i] = NULL;
790 style->bg_gc[i] = NULL;
791 style->light_gc[i] = NULL;
792 style->dark_gc[i] = NULL;
793 style->mid_gc[i] = NULL;
794 style->text_gc[i] = NULL;
795 style->base_gc[i] = NULL;
799 if (style->depth == -1)
800 style->depth = key->depth;
801 if (!style->colormap)
802 style->colormap = key->colormap;
804 gtk_style_init (style);
810 gtk_style_key_dup (GtkStyleKey *key)
812 GtkStyleKey *new_key;
815 key_mem_chunk = g_mem_chunk_new ("key mem chunk", sizeof (GtkStyleKey),
816 1024, G_ALLOC_AND_FREE);
818 new_key = g_chunk_new (GtkStyleKey, key_mem_chunk);
826 gtk_style_destroy (GtkStyle *style)
830 if (style->attach_count > 0)
832 gtk_gc_release (style->black_gc);
833 gtk_gc_release (style->white_gc);
835 for (i = 0; i < 5; i++)
837 gtk_gc_release (style->fg_gc[i]);
838 gtk_gc_release (style->bg_gc[i]);
839 gtk_gc_release (style->light_gc[i]);
840 gtk_gc_release (style->dark_gc[i]);
841 gtk_gc_release (style->mid_gc[i]);
842 gtk_gc_release (style->text_gc[i]);
843 gtk_gc_release (style->base_gc[i]);
847 unattached_styles = g_slist_remove (unattached_styles, style);
849 gdk_font_unref (style->font);
854 gtk_style_key_destroy (GtkStyleKey *key)
856 g_mem_chunk_free (key_mem_chunk, key);
860 gtk_style_key_hash (GtkStyleKey *key)
867 for (i = 0; i < 5; i++)
869 hash_val += key->fg[i].red + key->fg[i].green + key->fg[i].blue;
870 hash_val += key->bg[i].red + key->bg[i].green + key->bg[i].blue;
871 hash_val += key->text[i].red + key->text[i].green + key->text[i].blue;
872 hash_val += key->base[i].red + key->base[i].green + key->base[i].blue;
875 hash_val += (guint) gdk_font_id (key->font);
876 hash_val += (guint) key->depth;
877 hash_val += (gulong) key->colormap;
878 hash_val += (gulong) key->klass;
884 gtk_style_value_hash (GtkStyle *style)
891 for (i = 0; i < 5; i++)
893 hash_val += style->fg[i].red + style->fg[i].green + style->fg[i].blue;
894 hash_val += style->bg[i].red + style->bg[i].green + style->bg[i].blue;
895 hash_val += style->text[i].red + style->text[i].green + style->text[i].blue;
896 hash_val += style->base[i].red + style->base[i].green + style->base[i].blue;
899 hash_val += (guint) gdk_font_id (style->font);
900 hash_val += (gulong) style->klass;
906 gtk_style_key_compare (GtkStyleKey *a,
911 if (a->depth != b->depth)
913 if (a->colormap != b->colormap)
915 if (a->klass != b->klass)
917 if (!gdk_font_equal (a->font, b->font))
920 for (i = 0; i < 5; i++)
922 if (a->bg_pixmap[i] != b->bg_pixmap[i])
925 if ((a->fg[i].red != b->fg[i].red) ||
926 (a->fg[i].green != b->fg[i].green) ||
927 (a->fg[i].blue != b->fg[i].blue))
929 if ((a->bg[i].red != b->bg[i].red) ||
930 (a->bg[i].green != b->bg[i].green) ||
931 (a->bg[i].blue != b->bg[i].blue))
933 if ((a->text[i].red != b->text[i].red) ||
934 (a->text[i].green != b->text[i].green) ||
935 (a->text[i].blue != b->text[i].blue))
937 if ((a->base[i].red != b->base[i].red) ||
938 (a->base[i].green != b->base[i].green) ||
939 (a->base[i].blue != b->base[i].blue))
948 gtk_default_draw_hline (GtkStyle *style,
950 GtkStateType state_type,
955 gint thickness_light;
959 g_return_if_fail (style != NULL);
960 g_return_if_fail (window != NULL);
962 thickness_light = style->klass->ythickness / 2;
963 thickness_dark = style->klass->ythickness - thickness_light;
965 for (i = 0; i < thickness_dark; i++)
967 gdk_draw_line (window, style->light_gc[state_type], x2 - i - 1, y + i, x2, y + i);
968 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x2 - i - 1, y + i);
972 for (i = 0; i < thickness_light; i++)
974 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x1 + thickness_light - i - 1, y + i);
975 gdk_draw_line (window, style->light_gc[state_type], x1 + thickness_light - i - 1, y + i, x2, y + i);
981 gtk_default_draw_vline (GtkStyle *style,
983 GtkStateType state_type,
988 gint thickness_light;
992 g_return_if_fail (style != NULL);
993 g_return_if_fail (window != NULL);
995 thickness_light = style->klass->xthickness / 2;
996 thickness_dark = style->klass->xthickness - thickness_light;
998 for (i = 0; i < thickness_dark; i++)
1000 gdk_draw_line (window, style->light_gc[state_type], x + i, y2 - i - 1, x + i, y2);
1001 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y2 - i - 1);
1004 x += thickness_dark;
1005 for (i = 0; i < thickness_light; i++)
1007 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y1 + thickness_light - i);
1008 gdk_draw_line (window, style->light_gc[state_type], x + i, y1 + thickness_light - i, x + i, y2);
1014 gtk_default_draw_shadow (GtkStyle *style,
1016 GtkStateType state_type,
1017 GtkShadowType shadow_type,
1025 gint thickness_light;
1026 gint thickness_dark;
1029 g_return_if_fail (style != NULL);
1030 g_return_if_fail (window != NULL);
1032 if ((width == -1) && (height == -1))
1033 gdk_window_get_size (window, &width, &height);
1034 else if (width == -1)
1035 gdk_window_get_size (window, &width, NULL);
1036 else if (height == -1)
1037 gdk_window_get_size (window, NULL, &height);
1039 switch (shadow_type)
1041 case GTK_SHADOW_NONE:
1046 case GTK_SHADOW_ETCHED_IN:
1047 gc1 = style->light_gc[state_type];
1048 gc2 = style->dark_gc[state_type];
1050 case GTK_SHADOW_OUT:
1051 case GTK_SHADOW_ETCHED_OUT:
1052 gc1 = style->dark_gc[state_type];
1053 gc2 = style->light_gc[state_type];
1057 switch (shadow_type)
1059 case GTK_SHADOW_NONE:
1063 gdk_draw_line (window, gc1,
1064 x, y + height - 1, x + width - 1, y + height - 1);
1065 gdk_draw_line (window, gc1,
1066 x + width - 1, y, x + width - 1, y + height - 1);
1068 gdk_draw_line (window, style->bg_gc[state_type],
1069 x + 1, y + height - 2, x + width - 2, y + height - 2);
1070 gdk_draw_line (window, style->bg_gc[state_type],
1071 x + width - 2, y + 1, x + width - 2, y + height - 2);
1073 gdk_draw_line (window, style->black_gc,
1074 x + 1, y + 1, x + width - 2, y + 1);
1075 gdk_draw_line (window, style->black_gc,
1076 x + 1, y + 1, x + 1, y + height - 2);
1078 gdk_draw_line (window, gc2,
1079 x, y, x + width - 1, y);
1080 gdk_draw_line (window, gc2,
1081 x, y, x, y + height - 1);
1084 case GTK_SHADOW_OUT:
1085 gdk_draw_line (window, gc1,
1086 x + 1, y + height - 2, x + width - 2, y + height - 2);
1087 gdk_draw_line (window, gc1,
1088 x + width - 2, y + 1, x + width - 2, y + height - 2);
1090 gdk_draw_line (window, gc2,
1091 x, y, x + width - 1, y);
1092 gdk_draw_line (window, gc2,
1093 x, y, x, y + height - 1);
1095 gdk_draw_line (window, style->bg_gc[state_type],
1096 x + 1, y + 1, x + width - 2, y + 1);
1097 gdk_draw_line (window, style->bg_gc[state_type],
1098 x + 1, y + 1, x + 1, y + height - 2);
1100 gdk_draw_line (window, style->black_gc,
1101 x, y + height - 1, x + width - 1, y + height - 1);
1102 gdk_draw_line (window, style->black_gc,
1103 x + width - 1, y, x + width - 1, y + height - 1);
1106 case GTK_SHADOW_ETCHED_IN:
1107 case GTK_SHADOW_ETCHED_OUT:
1108 thickness_light = 1;
1111 for (i = 0; i < thickness_dark; i++)
1113 gdk_draw_line (window, gc1,
1117 y + height - i - 1);
1118 gdk_draw_line (window, gc1,
1122 y + height - i - 1);
1124 gdk_draw_line (window, gc2,
1129 gdk_draw_line (window, gc2,
1133 y + height - i - 2);
1136 for (i = 0; i < thickness_light; i++)
1138 gdk_draw_line (window, gc1,
1139 x + thickness_dark + i,
1140 y + thickness_dark + i,
1141 x + width - thickness_dark - i - 1,
1142 y + thickness_dark + i);
1143 gdk_draw_line (window, gc1,
1144 x + thickness_dark + i,
1145 y + thickness_dark + i,
1146 x + thickness_dark + i,
1147 y + height - thickness_dark - i - 1);
1149 gdk_draw_line (window, gc2,
1150 x + thickness_dark + i,
1151 y + height - thickness_light - i - 1,
1152 x + width - thickness_light - 1,
1153 y + height - thickness_light - i - 1);
1154 gdk_draw_line (window, gc2,
1155 x + width - thickness_light - i - 1,
1156 y + thickness_dark + i,
1157 x + width - thickness_light - i - 1,
1158 y + height - thickness_light - 1);
1166 gtk_default_draw_polygon (GtkStyle *style,
1168 GtkStateType state_type,
1169 GtkShadowType shadow_type,
1175 #define M_PI 3.14159265358979323846
1178 #define M_PI_4 0.78539816339744830962
1181 static const gdouble pi_over_4 = M_PI_4;
1182 static const gdouble pi_3_over_4 = M_PI_4 * 3;
1193 g_return_if_fail (style != NULL);
1194 g_return_if_fail (window != NULL);
1195 g_return_if_fail (points != NULL);
1197 switch (shadow_type)
1200 gc1 = style->bg_gc[state_type];
1201 gc2 = style->dark_gc[state_type];
1202 gc3 = style->light_gc[state_type];
1203 gc4 = style->black_gc;
1205 case GTK_SHADOW_OUT:
1206 gc1 = style->dark_gc[state_type];
1207 gc2 = style->light_gc[state_type];
1208 gc3 = style->black_gc;
1209 gc4 = style->bg_gc[state_type];
1216 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, npoints);
1220 for (i = 0; i < npoints; i++)
1222 if ((points[i].x == points[i+1].x) &&
1223 (points[i].y == points[i+1].y))
1229 angle = atan2 (points[i+1].y - points[i].y,
1230 points[i+1].x - points[i].x);
1233 if ((angle > -pi_3_over_4) && (angle < pi_over_4))
1235 if (angle > -pi_over_4)
1246 gdk_draw_line (window, gc1,
1247 points[i].x-xadjust, points[i].y-yadjust,
1248 points[i+1].x-xadjust, points[i+1].y-yadjust);
1249 gdk_draw_line (window, gc3,
1250 points[i].x, points[i].y,
1251 points[i+1].x, points[i+1].y);
1255 if ((angle < -pi_3_over_4) || (angle > pi_3_over_4))
1266 gdk_draw_line (window, gc4,
1267 points[i].x+xadjust, points[i].y+yadjust,
1268 points[i+1].x+xadjust, points[i+1].y+yadjust);
1269 gdk_draw_line (window, gc2,
1270 points[i].x, points[i].y,
1271 points[i+1].x, points[i+1].y);
1278 gtk_default_draw_arrow (GtkStyle *style,
1280 GtkStateType state_type,
1281 GtkShadowType shadow_type,
1282 GtkArrowType arrow_type,
1297 g_return_if_fail (style != NULL);
1298 g_return_if_fail (window != NULL);
1300 switch (shadow_type)
1303 gc1 = style->bg_gc[state_type];
1304 gc2 = style->dark_gc[state_type];
1305 gc3 = style->light_gc[state_type];
1306 gc4 = style->black_gc;
1308 case GTK_SHADOW_OUT:
1309 gc1 = style->dark_gc[state_type];
1310 gc2 = style->light_gc[state_type];
1311 gc3 = style->black_gc;
1312 gc4 = style->bg_gc[state_type];
1318 if ((width == -1) && (height == -1))
1319 gdk_window_get_size (window, &width, &height);
1320 else if (width == -1)
1321 gdk_window_get_size (window, &width, NULL);
1322 else if (height == -1)
1323 gdk_window_get_size (window, NULL, &height);
1325 half_width = width / 2;
1326 half_height = height / 2;
1333 points[0].x = x + half_width;
1336 points[1].y = y + height - 1;
1337 points[2].x = x + width - 1;
1338 points[2].y = y + height - 1;
1340 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
1343 gdk_draw_line (window, gc1,
1344 x + 1, y + height - 2,
1345 x + width - 2, y + height - 2);
1346 gdk_draw_line (window, gc3,
1347 x + 0, y + height - 1,
1348 x + width - 1, y + height - 1);
1350 gdk_draw_line (window, gc1,
1351 x + width - 2, y + height - 1,
1352 x + half_width, y + 1);
1353 gdk_draw_line (window, gc3,
1354 x + width - 1, y + height - 1,
1357 gdk_draw_line (window, gc4,
1358 x + half_width, y + 1,
1359 x + 1, y + height - 1);
1360 gdk_draw_line (window, gc2,
1364 case GTK_ARROW_DOWN:
1367 points[0].x = x + width - 1;
1371 points[2].x = x + half_width;
1372 points[2].y = y + height - 1;
1374 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
1377 gdk_draw_line (window, gc4,
1379 y + 1, x + 1, y + 1);
1380 gdk_draw_line (window, gc2,
1384 gdk_draw_line (window, gc4,
1386 x + half_width, y + height - 2);
1387 gdk_draw_line (window, gc2,
1389 x + half_width, y + height - 1);
1391 gdk_draw_line (window, gc1,
1392 x + half_width, y + height - 2,
1394 gdk_draw_line (window, gc3,
1395 x + half_width, y + height - 1,
1398 case GTK_ARROW_LEFT:
1402 points[0].y = y + half_height;
1403 points[1].x = x + width - 1;
1404 points[1].y = y + height - 1;
1405 points[2].x = x + width - 1;
1408 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
1411 gdk_draw_line (window, gc1,
1412 x + 1, y + half_height,
1413 x + width - 1, y + height - 1);
1414 gdk_draw_line (window, gc3,
1416 x + width - 1, y + height - 1);
1418 gdk_draw_line (window, gc1,
1419 x + width - 2, y + height - 1,
1420 x + width - 2, y + 1);
1421 gdk_draw_line (window, gc3,
1422 x + width - 1, y + height - 1,
1425 gdk_draw_line (window, gc4,
1426 x + width - 1, y + 1,
1427 x + 1, y + half_height);
1428 gdk_draw_line (window, gc2,
1430 x, y + half_height);
1432 case GTK_ARROW_RIGHT:
1435 points[0].x = x + width - 1;
1436 points[0].y = y + half_height;
1440 points[2].y = y + height - 1;
1442 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
1445 gdk_draw_line (window, gc4,
1446 x + width - 1, y + half_height,
1448 gdk_draw_line (window, gc2,
1449 x + width - 1, y + half_height,
1452 gdk_draw_line (window, gc4,
1454 x + 1, y + height - 2);
1455 gdk_draw_line (window, gc2,
1459 gdk_draw_line (window, gc1,
1460 x + 1, y + height - 2,
1461 x + width - 1, y + half_height);
1462 gdk_draw_line (window, gc3,
1464 x + width - 1, y + half_height);
1471 gtk_default_draw_diamond (GtkStyle *style,
1473 GtkStateType state_type,
1474 GtkShadowType shadow_type,
1483 g_return_if_fail (style != NULL);
1484 g_return_if_fail (window != NULL);
1486 if ((width == -1) && (height == -1))
1487 gdk_window_get_size (window, &width, &height);
1488 else if (width == -1)
1489 gdk_window_get_size (window, &width, NULL);
1490 else if (height == -1)
1491 gdk_window_get_size (window, NULL, &height);
1493 half_width = width / 2;
1494 half_height = height / 2;
1496 switch (shadow_type)
1499 gdk_draw_line (window, style->bg_gc[state_type],
1500 x + 2, y + half_height,
1501 x + half_width, y + height - 2);
1502 gdk_draw_line (window, style->bg_gc[state_type],
1503 x + half_width, y + height - 2,
1504 x + width - 2, y + half_height);
1505 gdk_draw_line (window, style->light_gc[state_type],
1506 x + 1, y + half_height,
1507 x + half_width, y + height - 1);
1508 gdk_draw_line (window, style->light_gc[state_type],
1509 x + half_width, y + height - 1,
1510 x + width - 1, y + half_height);
1511 gdk_draw_line (window, style->light_gc[state_type],
1513 x + half_width, y + height);
1514 gdk_draw_line (window, style->light_gc[state_type],
1515 x + half_width, y + height,
1516 x + width, y + half_height);
1518 gdk_draw_line (window, style->black_gc,
1519 x + 2, y + half_height,
1520 x + half_width, y + 2);
1521 gdk_draw_line (window, style->black_gc,
1522 x + half_width, y + 2,
1523 x + width - 2, y + half_height);
1524 gdk_draw_line (window, style->dark_gc[state_type],
1525 x + 1, y + half_height,
1526 x + half_width, y + 1);
1527 gdk_draw_line (window, style->dark_gc[state_type],
1528 x + half_width, y + 1,
1529 x + width - 1, y + half_height);
1530 gdk_draw_line (window, style->dark_gc[state_type],
1533 gdk_draw_line (window, style->dark_gc[state_type],
1535 x + width, y + half_height);
1537 case GTK_SHADOW_OUT:
1538 gdk_draw_line (window, style->dark_gc[state_type],
1539 x + 2, y + half_height,
1540 x + half_width, y + height - 2);
1541 gdk_draw_line (window, style->dark_gc[state_type],
1542 x + half_width, y + height - 2,
1543 x + width - 2, y + half_height);
1544 gdk_draw_line (window, style->dark_gc[state_type],
1545 x + 1, y + half_height,
1546 x + half_width, y + height - 1);
1547 gdk_draw_line (window, style->dark_gc[state_type],
1548 x + half_width, y + height - 1,
1549 x + width - 1, y + half_height);
1550 gdk_draw_line (window, style->black_gc,
1552 x + half_width, y + height);
1553 gdk_draw_line (window, style->black_gc,
1554 x + half_width, y + height,
1555 x + width, y + half_height);
1557 gdk_draw_line (window, style->bg_gc[state_type],
1558 x + 2, y + half_height,
1559 x + half_width, y + 2);
1560 gdk_draw_line (window, style->bg_gc[state_type],
1561 x + half_width, y + 2,
1562 x + width - 2, y + half_height);
1563 gdk_draw_line (window, style->light_gc[state_type],
1564 x + 1, y + half_height,
1565 x + half_width, y + 1);
1566 gdk_draw_line (window, style->light_gc[state_type],
1567 x + half_width, y + 1,
1568 x + width - 1, y + half_height);
1569 gdk_draw_line (window, style->light_gc[state_type],
1572 gdk_draw_line (window, style->light_gc[state_type],
1574 x + width, y + half_height);
1583 gtk_default_draw_oval (GtkStyle *style,
1585 GtkStateType state_type,
1586 GtkShadowType shadow_type,
1592 g_return_if_fail (style != NULL);
1593 g_return_if_fail (window != NULL);
1597 gtk_default_draw_string (GtkStyle *style,
1599 GtkStateType state_type,
1602 const gchar *string)
1604 g_return_if_fail (style != NULL);
1605 g_return_if_fail (window != NULL);
1607 if (state_type == GTK_STATE_INSENSITIVE)
1608 gdk_draw_string (window, style->font, style->white_gc, x + 1, y + 1, string);
1609 gdk_draw_string (window, style->font, style->fg_gc[state_type], x, y, string);
1614 gtk_style_shade (GdkColor *a,
1622 red = (gdouble) a->red / 65535.0;
1623 green = (gdouble) a->green / 65535.0;
1624 blue = (gdouble) a->blue / 65535.0;
1626 rgb_to_hls (&red, &green, &blue);
1631 else if (green < 0.0)
1637 else if (blue < 0.0)
1640 hls_to_rgb (&red, &green, &blue);
1642 b->red = red * 65535.0;
1643 b->green = green * 65535.0;
1644 b->blue = blue * 65535.0;
1648 rgb_to_hls (gdouble *r,
1689 l = (max + min) / 2;
1696 s = (max - min) / (max + min);
1698 s = (max - min) / (2 - max - min);
1702 h = (green - blue) / delta;
1703 else if (green == max)
1704 h = 2 + (blue - red) / delta;
1705 else if (blue == max)
1706 h = 4 + (red - green) / delta;
1719 hls_to_rgb (gdouble *h,
1732 if (lightness <= 0.5)
1733 m2 = lightness * (1 + saturation);
1735 m2 = lightness + saturation - lightness * saturation;
1736 m1 = 2 * lightness - m2;
1738 if (saturation == 0)
1753 r = m1 + (m2 - m1) * hue / 60;
1757 r = m1 + (m2 - m1) * (240 - hue) / 60;
1768 g = m1 + (m2 - m1) * hue / 60;
1772 g = m1 + (m2 - m1) * (240 - hue) / 60;
1783 b = m1 + (m2 - m1) * hue / 60;
1787 b = m1 + (m2 - m1) * (240 - hue) / 60;