]> Pileus Git - ~andy/gtk/blob - gtk/gtkstyle.c
Large changes to the Win32 backend, partially made necessary by the
[~andy/gtk] / gtk / gtkstyle.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 /*
21  * Modified by the GTK+ Team and others 1997-1999.  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/. 
25  */
26
27 #include <math.h>
28 #include <string.h>
29 #include "gtkgc.h"
30 #include "gtkrc.h"
31 #include "gtkstyle.h"
32 #include "gtkwidget.h"
33 #include "gtkthemes.h"
34
35
36 #define LIGHTNESS_MULT  1.3
37 #define DARKNESS_MULT   0.7
38
39 /* actually glib should do that for us */
40 #ifndef M_PI
41 #define M_PI    3.14159265358979323846
42 #endif /* M_PI */
43 #ifndef M_PI_4
44 #define M_PI_4  0.78539816339744830962
45 #endif /* M_PI_4 */
46
47 static void         gtk_style_init         (GtkStyle    *style,
48                                             GdkColormap *colormap,
49                                             gint         depth);
50 static void         gtk_style_destroy      (GtkStyle    *style);
51
52 static void gtk_default_draw_hline      (GtkStyle        *style,
53                                          GdkWindow       *window,
54                                          GtkStateType     state_type,
55                                          GdkRectangle    *area,
56                                          GtkWidget       *widget,
57                                          const gchar     *detail,
58                                          gint             x1,
59                                          gint             x2,
60                                          gint             y);
61 static void gtk_default_draw_vline      (GtkStyle        *style,
62                                          GdkWindow       *window,
63                                          GtkStateType     state_type,
64                                          GdkRectangle    *area,
65                                          GtkWidget       *widget,
66                                          const gchar     *detail,
67                                          gint             y1,
68                                          gint             y2,
69                                          gint             x);
70 static void gtk_default_draw_shadow     (GtkStyle        *style,
71                                          GdkWindow       *window,
72                                          GtkStateType     state_type,
73                                          GtkShadowType    shadow_type,
74                                          GdkRectangle    *area,
75                                          GtkWidget       *widget,
76                                          const gchar     *detail,
77                                          gint             x,
78                                          gint             y,
79                                          gint             width,
80                                          gint             height);
81 static void gtk_default_draw_shadow     (GtkStyle        *style,
82                                          GdkWindow       *window,
83                                          GtkStateType     state_type,
84                                          GtkShadowType    shadow_type,
85                                          GdkRectangle    *area,
86                                          GtkWidget       *widget,
87                                          const gchar     *detail,
88                                          gint             x,
89                                          gint             y,
90                                          gint             width,
91                                          gint             height);
92 static void gtk_default_draw_polygon    (GtkStyle        *style,
93                                          GdkWindow       *window,
94                                          GtkStateType     state_type,
95                                          GtkShadowType    shadow_type,
96                                          GdkRectangle    *area,
97                                          GtkWidget       *widget,
98                                          const gchar     *detail,
99                                          GdkPoint        *points,
100                                          gint             npoints,
101                                          gboolean         fill);
102 static void gtk_default_draw_arrow      (GtkStyle        *style,
103                                          GdkWindow       *window,
104                                          GtkStateType     state_type,
105                                          GtkShadowType    shadow_type,
106                                          GdkRectangle    *area,
107                                          GtkWidget       *widget,
108                                          const gchar     *detail,
109                                          GtkArrowType     arrow_type,
110                                          gboolean         fill,
111                                          gint             x,
112                                          gint             y,
113                                          gint             width,
114                                          gint             height);
115 static void gtk_default_draw_diamond    (GtkStyle        *style,
116                                          GdkWindow       *window,
117                                          GtkStateType     state_type,
118                                          GtkShadowType    shadow_type,
119                                          GdkRectangle    *area,
120                                          GtkWidget       *widget,
121                                          const gchar     *detail,
122                                          gint             x,
123                                          gint             y,
124                                          gint             width,
125                                          gint             height);
126 static void gtk_default_draw_oval       (GtkStyle        *style,
127                                          GdkWindow       *window,
128                                          GtkStateType     state_type,
129                                          GtkShadowType    shadow_type,
130                                          GdkRectangle    *area,
131                                          GtkWidget       *widget,
132                                          const gchar     *detail,
133                                          gint             x,
134                                          gint             y,
135                                          gint             width,
136                                          gint             height);
137 static void gtk_default_draw_string     (GtkStyle        *style,
138                                          GdkWindow       *window,
139                                          GtkStateType     state_type,
140                                          GdkRectangle    *area,
141                                          GtkWidget       *widget,
142                                          const gchar     *detail,
143                                          gint             x,
144                                          gint             y,
145                                          const gchar     *string);
146 static void gtk_default_draw_box        (GtkStyle        *style,
147                                          GdkWindow       *window,
148                                          GtkStateType     state_type,
149                                          GtkShadowType    shadow_type,
150                                          GdkRectangle    *area,
151                                          GtkWidget       *widget,
152                                          const gchar     *detail,
153                                          gint             x,
154                                          gint             y,
155                                          gint             width,
156                                          gint             height);
157 static void gtk_default_draw_flat_box   (GtkStyle        *style,
158                                          GdkWindow       *window,
159                                          GtkStateType     state_type,
160                                          GtkShadowType    shadow_type,
161                                          GdkRectangle    *area,
162                                          GtkWidget       *widget,
163                                          const gchar     *detail,
164                                          gint             x,
165                                          gint             y,
166                                          gint             width,
167                                          gint             height);
168 static void gtk_default_draw_check      (GtkStyle        *style,
169                                          GdkWindow       *window,
170                                          GtkStateType     state_type,
171                                          GtkShadowType    shadow_type,
172                                          GdkRectangle    *area,
173                                          GtkWidget       *widget,
174                                          const gchar     *detail,
175                                          gint             x,
176                                          gint             y,
177                                          gint             width,
178                                          gint             height);
179 static void gtk_default_draw_option     (GtkStyle        *style,
180                                          GdkWindow       *window,
181                                          GtkStateType     state_type,
182                                          GtkShadowType    shadow_type,
183                                          GdkRectangle    *area,
184                                          GtkWidget       *widget,
185                                          const gchar     *detail,
186                                          gint             x,
187                                          gint             y,
188                                          gint             width,
189                                          gint             height);
190 static void gtk_default_draw_cross      (GtkStyle        *style,
191                                          GdkWindow       *window,
192                                          GtkStateType     state_type,
193                                          GtkShadowType    shadow_type,
194                                          GdkRectangle    *area,
195                                          GtkWidget       *widget,
196                                          const gchar     *detail,
197                                          gint             x,
198                                          gint             y,
199                                          gint             width,
200                                          gint             height);
201 static void gtk_default_draw_ramp       (GtkStyle        *style,
202                                          GdkWindow       *window,
203                                          GtkStateType     state_type,
204                                          GtkShadowType    shadow_type,
205                                          GdkRectangle    *area,
206                                          GtkWidget       *widget,
207                                          const gchar     *detail,
208                                          GtkArrowType     arrow_type,
209                                          gint             x,
210                                          gint             y,
211                                          gint             width,
212                                          gint             height);
213 static void gtk_default_draw_tab        (GtkStyle        *style,
214                                          GdkWindow       *window,
215                                          GtkStateType     state_type,
216                                          GtkShadowType    shadow_type,
217                                          GdkRectangle    *area,
218                                          GtkWidget       *widget,
219                                          const gchar     *detail,
220                                          gint             x,
221                                          gint             y,
222                                          gint             width,
223                                          gint             height);
224 static void gtk_default_draw_shadow_gap (GtkStyle        *style,
225                                          GdkWindow       *window,
226                                          GtkStateType     state_type,
227                                          GtkShadowType    shadow_type,
228                                          GdkRectangle    *area,
229                                          GtkWidget       *widget,
230                                          const gchar     *detail,
231                                          gint             x,
232                                          gint             y,
233                                          gint             width,
234                                          gint             height,
235                                          GtkPositionType  gap_side,
236                                          gint             gap_x,
237                                          gint             gap_width);
238 static void gtk_default_draw_box_gap    (GtkStyle        *style,
239                                          GdkWindow       *window,
240                                          GtkStateType     state_type,
241                                          GtkShadowType    shadow_type,
242                                          GdkRectangle    *area,
243                                          GtkWidget       *widget,
244                                          const gchar     *detail,
245                                          gint             x,
246                                          gint             y,
247                                          gint             width,
248                                          gint             height,
249                                          GtkPositionType  gap_side,
250                                          gint             gap_x,
251                                          gint             gap_width);
252 static void gtk_default_draw_extension  (GtkStyle        *style,
253                                          GdkWindow       *window,
254                                          GtkStateType     state_type,
255                                          GtkShadowType    shadow_type,
256                                          GdkRectangle    *area,
257                                          GtkWidget       *widget,
258                                          const gchar     *detail,
259                                          gint             x,
260                                          gint             y,
261                                          gint             width,
262                                          gint             height,
263                                          GtkPositionType  gap_side);
264 static void gtk_default_draw_focus      (GtkStyle        *style,
265                                          GdkWindow       *window,
266                                          GdkRectangle    *area,
267                                          GtkWidget       *widget,
268                                          const gchar     *detail,
269                                          gint             x,
270                                          gint             y,
271                                          gint             width,
272                                          gint             height);
273 static void gtk_default_draw_slider     (GtkStyle        *style,
274                                          GdkWindow       *window,
275                                          GtkStateType     state_type,
276                                          GtkShadowType    shadow_type,
277                                          GdkRectangle    *area,
278                                          GtkWidget       *widget,
279                                          const gchar     *detail,
280                                          gint             x,
281                                          gint             y,
282                                          gint             width,
283                                          gint             height,
284                                          GtkOrientation   orientation);
285 static void gtk_default_draw_handle     (GtkStyle        *style,
286                                          GdkWindow       *window,
287                                          GtkStateType     state_type,
288                                          GtkShadowType    shadow_type,
289                                          GdkRectangle    *area,
290                                          GtkWidget       *widget,
291                                          const gchar     *detail,
292                                          gint             x,
293                                          gint             y,
294                                          gint             width,
295                                          gint             height,
296                                          GtkOrientation   orientation);
297
298 static void gtk_style_shade (GdkColor *a, GdkColor *b, gdouble k);
299 static void rgb_to_hls (gdouble *r, gdouble *g, gdouble *b);
300 static void hls_to_rgb (gdouble *h, gdouble *l, gdouble *s);
301
302
303 static const GtkStyleClass default_class =
304 {
305   2,
306   2,
307   gtk_default_draw_hline,
308   gtk_default_draw_vline,
309   gtk_default_draw_shadow,
310   gtk_default_draw_polygon,
311   gtk_default_draw_arrow,
312   gtk_default_draw_diamond,
313   gtk_default_draw_oval,
314   gtk_default_draw_string,
315   gtk_default_draw_box,
316   gtk_default_draw_flat_box,
317   gtk_default_draw_check,
318   gtk_default_draw_option,
319   gtk_default_draw_cross,
320   gtk_default_draw_ramp,
321   gtk_default_draw_tab,
322   gtk_default_draw_shadow_gap,
323   gtk_default_draw_box_gap,
324   gtk_default_draw_extension,
325   gtk_default_draw_focus,
326   gtk_default_draw_slider,
327   gtk_default_draw_handle
328 };
329 GdkFont *default_font = NULL;
330
331 static GdkColor gtk_default_normal_fg =      { 0,      0,      0,      0 };
332 static GdkColor gtk_default_active_fg =      { 0,      0,      0,      0 };
333 static GdkColor gtk_default_prelight_fg =    { 0,      0,      0,      0 };
334 static GdkColor gtk_default_selected_fg =    { 0, 0xffff, 0xffff, 0xffff };
335 static GdkColor gtk_default_insensitive_fg = { 0, 0x7530, 0x7530, 0x7530 };
336
337 static GdkColor gtk_default_normal_bg =      { 0, 0xd6d6, 0xd6d6, 0xd6d6 };
338 static GdkColor gtk_default_active_bg =      { 0, 0xc350, 0xc350, 0xc350 };
339 static GdkColor gtk_default_prelight_bg =    { 0, 0xea60, 0xea60, 0xea60 };
340 static GdkColor gtk_default_selected_bg =    { 0,      0,      0, 0x9c40 };
341 static GdkColor gtk_default_insensitive_bg = { 0, 0xd6d6, 0xd6d6, 0xd6d6 };
342
343 GtkStyle*
344 gtk_style_copy (GtkStyle *style)
345 {
346   GtkStyle *new_style;
347   guint i;
348   
349   g_return_val_if_fail (style != NULL, NULL);
350   
351   new_style = gtk_style_new ();
352   
353   for (i = 0; i < 5; i++)
354     {
355       new_style->fg[i] = style->fg[i];
356       new_style->bg[i] = style->bg[i];
357       new_style->text[i] = style->text[i];
358       new_style->base[i] = style->base[i];
359       
360       new_style->bg_pixmap[i] = style->bg_pixmap[i];
361     }
362   
363   gdk_font_unref (new_style->font);
364   new_style->font = style->font;
365   gdk_font_ref (new_style->font);
366
367   if (style->rc_style)
368     {
369       new_style->rc_style = style->rc_style;
370       gtk_rc_style_ref (style->rc_style);
371     }
372   
373   if (style->engine)
374     {
375       new_style->engine = style->engine;
376       gtk_theme_engine_ref (new_style->engine);
377       new_style->engine->duplicate_style (new_style, style);
378     }
379
380   return new_style;
381 }
382
383 static GtkStyle*
384 gtk_style_duplicate (GtkStyle *style)
385 {
386   GtkStyle *new_style;
387   
388   g_return_val_if_fail (style != NULL, NULL);
389   
390   new_style = gtk_style_copy (style);
391   
392   style->styles = g_slist_append (style->styles, new_style);
393   new_style->styles = style->styles;  
394   
395   return new_style;
396 }
397
398 GtkStyle*
399 gtk_style_new (void)
400 {
401   GtkStyle *style;
402   gint i;
403   
404   style = g_new0 (GtkStyle, 1);
405   
406   if (!default_font)
407     {
408       default_font =
409         gdk_font_load ("-adobe-helvetica-medium-r-normal--*-120-*-*-*-*-iso8859-1");
410       if (!default_font)
411         default_font = gdk_font_load ("fixed");
412       if (!default_font)
413         g_error ("Unable to load default font.");
414     }
415   
416   style->font = default_font;
417   gdk_font_ref (style->font);
418   
419   style->ref_count = 1;
420   style->attach_count = 0;
421   style->colormap = NULL;
422   style->depth = -1;
423   style->klass = (GtkStyleClass *)&default_class;
424   
425   style->black.red = 0;
426   style->black.green = 0;
427   style->black.blue = 0;
428   
429   style->white.red = 65535;
430   style->white.green = 65535;
431   style->white.blue = 65535;
432   
433   style->black_gc = NULL;
434   style->white_gc = NULL;
435   
436   style->fg[GTK_STATE_NORMAL] = gtk_default_normal_fg;
437   style->fg[GTK_STATE_ACTIVE] = gtk_default_active_fg;
438   style->fg[GTK_STATE_PRELIGHT] = gtk_default_prelight_fg;
439   style->fg[GTK_STATE_SELECTED] = gtk_default_selected_fg;
440   style->fg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
441   
442   style->bg[GTK_STATE_NORMAL] = gtk_default_normal_bg;
443   style->bg[GTK_STATE_ACTIVE] = gtk_default_active_bg;
444   style->bg[GTK_STATE_PRELIGHT] = gtk_default_prelight_bg;
445   style->bg[GTK_STATE_SELECTED] = gtk_default_selected_bg;
446   style->bg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_bg;
447   
448   for (i = 0; i < 4; i++)
449     {
450       style->text[i] = style->fg[i];
451       style->base[i] = style->white;
452     }
453   
454   style->base[GTK_STATE_INSENSITIVE] = gtk_default_prelight_bg;
455   style->text[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
456   
457   for (i = 0; i < 5; i++)
458     style->bg_pixmap[i] = NULL;
459   
460   style->engine = NULL;
461   style->engine_data = NULL;
462   
463   style->rc_style = NULL;
464   
465   for (i = 0; i < 5; i++)
466     {
467       style->fg_gc[i] = NULL;
468       style->bg_gc[i] = NULL;
469       style->light_gc[i] = NULL;
470       style->dark_gc[i] = NULL;
471       style->mid_gc[i] = NULL;
472       style->text_gc[i] = NULL;
473       style->base_gc[i] = NULL;
474     }
475   
476   return style;
477 }
478
479 /*************************************************************
480  * gtk_style_attach:
481  *     Attach a style to a window; this process allocates the
482  *     colors and creates the GC's for the style - it specializes
483  *     it to a particular visual and colormap. The process
484  *     may involve the creation of a new style if the style
485  *     has already been attached to a window with a different
486  *     style and colormap.
487  *   arguments:
488  *     style:
489  *     window: 
490  *   results:
491  *     Either the style parameter, or a newly created style.
492  *     If the style is newly created, the style parameter
493  *     will be dereferenced, and the new style will have
494  *     a reference count belonging to the caller.
495  *
496  * FIXME: The sequence - 
497  *    create a style => s1
498  *    attach s1 to v1, c1 => s1
499  *    attach s1 to v2, c2 => s2
500  *    detach s1 from v1, c1
501  *    attach s1 to v2, c2 => s3
502  * results in two separate, unlinked styles s2 and s3 which
503  * are identical and could be shared. To fix this, we would
504  * want to never remove a style from the list of linked
505  * styles as long as as it has a reference count. However, the 
506  * disadvantage of doing it this way means that we would need two 
507  * passes through the linked list when attaching (one to check for 
508  * matching styles, one to look for empty unattached styles - but 
509  * it will almost never be longer than 2 elements.
510  *************************************************************/
511
512 GtkStyle*
513 gtk_style_attach (GtkStyle  *style,
514                   GdkWindow *window)
515 {
516   GSList *styles;
517   GtkStyle *new_style = NULL;
518   GdkColormap *colormap;
519   gint depth;
520   
521   g_return_val_if_fail (style != NULL, NULL);
522   g_return_val_if_fail (window != NULL, NULL);
523   
524   colormap = gdk_window_get_colormap (window);
525   depth = gdk_window_get_visual (window)->depth;
526   
527   if (!style->styles)
528     style->styles = g_slist_append (NULL, style);
529   
530   styles = style->styles;
531   while (styles)
532     {
533       new_style = styles->data;
534       
535       if (new_style->attach_count == 0)
536         {
537           gtk_style_init (new_style, colormap, depth);
538           break;
539         }
540       else if (new_style->colormap == colormap &&
541                new_style->depth == depth)
542         break;
543       
544       new_style = NULL;
545       styles = styles->next;
546     }
547   
548   if (!new_style)
549     {
550       new_style = gtk_style_duplicate (style);
551       gtk_style_init (new_style, colormap, depth);
552     }
553
554   /* A style gets a refcount from being attached */
555   if (new_style->attach_count == 0)
556     gtk_style_ref (new_style);
557
558   /* Another refcount belongs to the parent */
559   if (style != new_style) 
560     {
561       gtk_style_unref (style);
562       gtk_style_ref (new_style);
563     }
564   
565   new_style->attach_count++;
566   
567   return new_style;
568 }
569
570 void
571 gtk_style_detach (GtkStyle *style)
572 {
573   gint i;
574   
575   g_return_if_fail (style != NULL);
576   
577   style->attach_count -= 1;
578   if (style->attach_count == 0)
579     {
580       if (style->engine)
581         style->engine->unrealize_style (style);
582       
583       gtk_gc_release (style->black_gc);
584       gtk_gc_release (style->white_gc);
585       
586       for (i = 0; i < 5; i++)
587         {
588           gtk_gc_release (style->fg_gc[i]);
589           gtk_gc_release (style->bg_gc[i]);
590           gtk_gc_release (style->light_gc[i]);
591           gtk_gc_release (style->dark_gc[i]);
592           gtk_gc_release (style->mid_gc[i]);
593           gtk_gc_release (style->text_gc[i]);
594           gtk_gc_release (style->base_gc[i]);
595         }
596       
597       gtk_style_unref (style);
598     }
599 }
600
601 GtkStyle*
602 gtk_style_ref (GtkStyle *style)
603 {
604   g_return_val_if_fail (style != NULL, NULL);
605   g_return_val_if_fail (style->ref_count > 0, NULL);
606   
607   style->ref_count += 1;
608   return style;
609 }
610
611 void
612 gtk_style_unref (GtkStyle *style)
613 {
614   g_return_if_fail (style != NULL);
615   g_return_if_fail (style->ref_count > 0);
616   
617   style->ref_count -= 1;
618   if (style->ref_count == 0)
619     gtk_style_destroy (style);
620 }
621
622 static void
623 gtk_style_init (GtkStyle    *style,
624                 GdkColormap *colormap,
625                 gint         depth)
626 {
627   GdkGCValues gc_values;
628   GdkGCValuesMask gc_values_mask;
629   gint i;
630   
631   g_return_if_fail (style != NULL);
632   
633   style->colormap = colormap;
634   style->depth = depth;
635   
636   for (i = 0; i < 5; i++)
637     {
638       gtk_style_shade (&style->bg[i], &style->light[i], LIGHTNESS_MULT);
639       gtk_style_shade (&style->bg[i], &style->dark[i], DARKNESS_MULT);
640       
641       style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
642       style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
643       style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
644     }
645   
646   gdk_color_black (colormap, &style->black);
647   gdk_color_white (colormap, &style->white);
648   
649   gc_values_mask = GDK_GC_FOREGROUND | GDK_GC_FONT;
650   if (style->font->type == GDK_FONT_FONT)
651     {
652       gc_values.font = style->font;
653     }
654   else if (style->font->type == GDK_FONT_FONTSET)
655     {
656       gc_values.font = default_font;
657     }
658   
659   gc_values.foreground = style->black;
660   style->black_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
661   
662   gc_values.foreground = style->white;
663   style->white_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
664   
665   for (i = 0; i < 5; i++)
666     {
667       if (style->rc_style && style->rc_style->bg_pixmap_name[i])
668         style->bg_pixmap[i] = gtk_rc_load_image (style->colormap,
669                                                  &style->bg[i],
670                                                  style->rc_style->bg_pixmap_name[i]);
671       
672       if (!gdk_color_alloc (colormap, &style->fg[i]))
673         g_warning ("unable to allocate color: ( %d %d %d )",
674                    style->fg[i].red, style->fg[i].green, style->fg[i].blue);
675       if (!gdk_color_alloc (colormap, &style->bg[i]))
676         g_warning ("unable to allocate color: ( %d %d %d )",
677                    style->bg[i].red, style->bg[i].green, style->bg[i].blue);
678       if (!gdk_color_alloc (colormap, &style->light[i]))
679         g_warning ("unable to allocate color: ( %d %d %d )",
680                    style->light[i].red, style->light[i].green, style->light[i].blue);
681       if (!gdk_color_alloc (colormap, &style->dark[i]))
682         g_warning ("unable to allocate color: ( %d %d %d )",
683                    style->dark[i].red, style->dark[i].green, style->dark[i].blue);
684       if (!gdk_color_alloc (colormap, &style->mid[i]))
685         g_warning ("unable to allocate color: ( %d %d %d )",
686                    style->mid[i].red, style->mid[i].green, style->mid[i].blue);
687       if (!gdk_color_alloc (colormap, &style->text[i]))
688         g_warning ("unable to allocate color: ( %d %d %d )",
689                    style->text[i].red, style->text[i].green, style->text[i].blue);
690       if (!gdk_color_alloc (colormap, &style->base[i]))
691         g_warning ("unable to allocate color: ( %d %d %d )",
692                    style->base[i].red, style->base[i].green, style->base[i].blue);
693       
694       gc_values.foreground = style->fg[i];
695       style->fg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
696       
697       gc_values.foreground = style->bg[i];
698       style->bg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
699       
700       gc_values.foreground = style->light[i];
701       style->light_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
702       
703       gc_values.foreground = style->dark[i];
704       style->dark_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
705       
706       gc_values.foreground = style->mid[i];
707       style->mid_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
708       
709       gc_values.foreground = style->text[i];
710       style->text_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
711       
712       gc_values.foreground = style->base[i];
713       style->base_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
714     }
715   
716   if (style->engine)
717     style->engine->realize_style (style);
718 }
719
720 static void
721 gtk_style_destroy (GtkStyle *style)
722 {
723   g_return_if_fail (style->attach_count == 0);
724   
725   if (style->styles)
726     {
727       if (style->styles->data != style)
728         g_slist_remove (style->styles, style);
729       else
730         {
731           GSList *tmp_list = style->styles->next;
732           
733           while (tmp_list)
734             {
735               ((GtkStyle*) tmp_list->data)->styles = style->styles->next;
736               tmp_list = tmp_list->next;
737             }
738           g_slist_free_1 (style->styles);
739         }
740     }
741   
742   if (style->engine)
743     {
744       style->engine->destroy_style (style);
745       gtk_theme_engine_unref (style->engine);
746     }
747   
748   gdk_font_unref (style->font);
749   if (style->rc_style)
750     gtk_rc_style_unref (style->rc_style);
751   
752   g_free (style);
753 }
754
755 void
756 gtk_draw_hline (GtkStyle     *style,
757                 GdkWindow    *window,
758                 GtkStateType  state_type,
759                 gint          x1,
760                 gint          x2,
761                 gint          y)
762 {
763   g_return_if_fail (style != NULL);
764   g_return_if_fail (style->klass != NULL);
765   g_return_if_fail (style->klass->draw_hline != NULL);
766   
767   style->klass->draw_hline (style, window, state_type, NULL, NULL, NULL, x1, x2, y);
768 }
769
770
771 void
772 gtk_draw_vline (GtkStyle     *style,
773                 GdkWindow    *window,
774                 GtkStateType  state_type,
775                 gint          y1,
776                 gint          y2,
777                 gint          x)
778 {
779   g_return_if_fail (style != NULL);
780   g_return_if_fail (style->klass != NULL);
781   g_return_if_fail (style->klass->draw_vline != NULL);
782   
783   style->klass->draw_vline (style, window, state_type, NULL, NULL, NULL, y1, y2, x);
784 }
785
786
787 void
788 gtk_draw_shadow (GtkStyle      *style,
789                  GdkWindow     *window,
790                  GtkStateType   state_type,
791                  GtkShadowType  shadow_type,
792                  gint           x,
793                  gint           y,
794                  gint           width,
795                  gint           height)
796 {
797   g_return_if_fail (style != NULL);
798   g_return_if_fail (style->klass != NULL);
799   g_return_if_fail (style->klass->draw_shadow != NULL);
800   
801   style->klass->draw_shadow (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
802 }
803
804 void
805 gtk_draw_polygon (GtkStyle      *style,
806                   GdkWindow     *window,
807                   GtkStateType   state_type,
808                   GtkShadowType  shadow_type,
809                   GdkPoint      *points,
810                   gint           npoints,
811                   gboolean       fill)
812 {
813   g_return_if_fail (style != NULL);
814   g_return_if_fail (style->klass != NULL);
815   g_return_if_fail (style->klass->draw_polygon != NULL);
816   
817   style->klass->draw_polygon (style, window, state_type, shadow_type, NULL, NULL, NULL, points, npoints, fill);
818 }
819
820 void
821 gtk_draw_arrow (GtkStyle      *style,
822                 GdkWindow     *window,
823                 GtkStateType   state_type,
824                 GtkShadowType  shadow_type,
825                 GtkArrowType   arrow_type,
826                 gboolean       fill,
827                 gint           x,
828                 gint           y,
829                 gint           width,
830                 gint           height)
831 {
832   g_return_if_fail (style != NULL);
833   g_return_if_fail (style->klass != NULL);
834   g_return_if_fail (style->klass->draw_arrow != NULL);
835   
836   style->klass->draw_arrow (style, window, state_type, shadow_type, NULL, NULL, NULL, arrow_type, fill, x, y, width, height);
837 }
838
839
840 void
841 gtk_draw_diamond (GtkStyle      *style,
842                   GdkWindow     *window,
843                   GtkStateType   state_type,
844                   GtkShadowType  shadow_type,
845                   gint           x,
846                   gint           y,
847                   gint           width,
848                   gint           height)
849 {
850   g_return_if_fail (style != NULL);
851   g_return_if_fail (style->klass != NULL);
852   g_return_if_fail (style->klass->draw_diamond != NULL);
853   
854   style->klass->draw_diamond (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
855 }
856
857
858 void
859 gtk_draw_oval (GtkStyle      *style,
860                GdkWindow     *window,
861                GtkStateType   state_type,
862                GtkShadowType  shadow_type,
863                gint           x,
864                gint           y,
865                gint           width,
866                gint           height)
867 {
868   g_return_if_fail (style != NULL);
869   g_return_if_fail (style->klass != NULL);
870   g_return_if_fail (style->klass->draw_oval != NULL);
871   
872   style->klass->draw_oval (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
873 }
874
875 void
876 gtk_draw_string (GtkStyle      *style,
877                  GdkWindow     *window,
878                  GtkStateType   state_type,
879                  gint           x,
880                  gint           y,
881                  const gchar   *string)
882 {
883   g_return_if_fail (style != NULL);
884   g_return_if_fail (style->klass != NULL);
885   g_return_if_fail (style->klass->draw_string != NULL);
886   
887   style->klass->draw_string (style, window, state_type, NULL, NULL, NULL, x, y, string);
888 }
889
890 void
891 gtk_draw_box (GtkStyle      *style,
892               GdkWindow     *window,
893               GtkStateType   state_type,
894               GtkShadowType  shadow_type,
895               gint           x,
896               gint           y,
897               gint           width,
898               gint           height)
899 {
900   g_return_if_fail (style != NULL);
901   g_return_if_fail (style->klass != NULL);
902   g_return_if_fail (style->klass->draw_box != NULL);
903   
904   style->klass->draw_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
905 }
906
907 void
908 gtk_draw_flat_box (GtkStyle      *style,
909                    GdkWindow     *window,
910                    GtkStateType   state_type,
911                    GtkShadowType  shadow_type,
912                    gint           x,
913                    gint           y,
914                    gint           width,
915                    gint           height)
916 {
917   g_return_if_fail (style != NULL);
918   g_return_if_fail (style->klass != NULL);
919   g_return_if_fail (style->klass->draw_flat_box != NULL);
920   
921   style->klass->draw_flat_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
922 }
923
924 void
925 gtk_draw_check (GtkStyle      *style,
926                 GdkWindow     *window,
927                 GtkStateType   state_type,
928                 GtkShadowType  shadow_type,
929                 gint           x,
930                 gint           y,
931                 gint           width,
932                 gint           height)
933 {
934   g_return_if_fail (style != NULL);
935   g_return_if_fail (style->klass != NULL);
936   g_return_if_fail (style->klass->draw_check != NULL);
937   
938   style->klass->draw_check (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
939 }
940
941 void
942 gtk_draw_option (GtkStyle      *style,
943                  GdkWindow     *window,
944                  GtkStateType   state_type,
945                  GtkShadowType  shadow_type,
946                  gint           x,
947                  gint           y,
948                  gint           width,
949                  gint           height)
950 {
951   g_return_if_fail (style != NULL);
952   g_return_if_fail (style->klass != NULL);
953   g_return_if_fail (style->klass->draw_option != NULL);
954   
955   style->klass->draw_option (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
956 }
957
958 void
959 gtk_draw_cross (GtkStyle      *style,
960                 GdkWindow     *window,
961                 GtkStateType   state_type,
962                 GtkShadowType  shadow_type,
963                 gint           x,
964                 gint           y,
965                 gint           width,
966                 gint           height)
967 {
968   g_return_if_fail (style != NULL);
969   g_return_if_fail (style->klass != NULL);
970   g_return_if_fail (style->klass->draw_cross != NULL);
971   
972   style->klass->draw_cross (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
973 }
974
975 void
976 gtk_draw_ramp (GtkStyle      *style,
977                GdkWindow     *window,
978                GtkStateType   state_type,
979                GtkShadowType  shadow_type,
980                GtkArrowType   arrow_type,
981                gint           x,
982                gint           y,
983                gint           width,
984                gint           height)
985 {
986   g_return_if_fail (style != NULL);
987   g_return_if_fail (style->klass != NULL);
988   g_return_if_fail (style->klass->draw_ramp != NULL);
989   
990   style->klass->draw_ramp (style, window, state_type, shadow_type, NULL, NULL, NULL, arrow_type, x, y, width, height);
991 }
992
993 void
994 gtk_draw_tab (GtkStyle      *style,
995               GdkWindow     *window,
996               GtkStateType   state_type,
997               GtkShadowType  shadow_type,
998               gint           x,
999               gint           y,
1000               gint           width,
1001               gint           height)
1002 {
1003   g_return_if_fail (style != NULL);
1004   g_return_if_fail (style->klass != NULL);
1005   g_return_if_fail (style->klass->draw_tab != NULL);
1006   
1007   style->klass->draw_tab (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1008 }
1009
1010 void
1011 gtk_draw_shadow_gap (GtkStyle       *style,
1012                      GdkWindow      *window,
1013                      GtkStateType    state_type,
1014                      GtkShadowType   shadow_type,
1015                      gint            x,
1016                      gint            y,
1017                      gint            width,
1018                      gint            height,
1019                      GtkPositionType gap_side,
1020                      gint            gap_x,
1021                      gint            gap_width)
1022 {
1023   g_return_if_fail (style != NULL);
1024   g_return_if_fail (style->klass != NULL);
1025   g_return_if_fail (style->klass->draw_shadow_gap != NULL);
1026   
1027   style->klass->draw_shadow_gap (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, gap_side, gap_x, gap_width);
1028 }
1029
1030 void
1031 gtk_draw_box_gap (GtkStyle       *style,
1032                   GdkWindow      *window,
1033                   GtkStateType    state_type,
1034                   GtkShadowType   shadow_type,
1035                   gint            x,
1036                   gint            y,
1037                   gint            width,
1038                   gint            height,
1039                   GtkPositionType gap_side,
1040                   gint            gap_x,
1041                   gint            gap_width)
1042 {
1043   g_return_if_fail (style != NULL);
1044   g_return_if_fail (style->klass != NULL);
1045   g_return_if_fail (style->klass->draw_box_gap != NULL);
1046   
1047   style->klass->draw_box_gap (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, gap_side, gap_x, gap_width);
1048 }
1049
1050 void
1051 gtk_draw_extension (GtkStyle       *style,
1052                     GdkWindow      *window,
1053                     GtkStateType    state_type,
1054                     GtkShadowType   shadow_type,
1055                     gint            x,
1056                     gint            y,
1057                     gint            width,
1058                     gint            height,
1059                     GtkPositionType gap_side)
1060 {
1061   g_return_if_fail (style != NULL);
1062   g_return_if_fail (style->klass != NULL);
1063   g_return_if_fail (style->klass->draw_extension != NULL);
1064   
1065   style->klass->draw_extension (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, gap_side);
1066 }
1067
1068 void
1069 gtk_draw_focus (GtkStyle      *style,
1070                 GdkWindow     *window,
1071                 gint           x,
1072                 gint           y,
1073                 gint           width,
1074                 gint           height)
1075 {
1076   g_return_if_fail (style != NULL);
1077   g_return_if_fail (style->klass != NULL);
1078   g_return_if_fail (style->klass->draw_focus != NULL);
1079   
1080   style->klass->draw_focus (style, window, NULL, NULL, NULL, x, y, width, height);
1081 }
1082
1083 void 
1084 gtk_draw_slider (GtkStyle      *style,
1085                  GdkWindow     *window,
1086                  GtkStateType   state_type,
1087                  GtkShadowType  shadow_type,
1088                  gint           x,
1089                  gint           y,
1090                  gint           width,
1091                  gint           height,
1092                  GtkOrientation orientation)
1093 {
1094   g_return_if_fail (style != NULL);
1095   g_return_if_fail (style->klass != NULL);
1096   g_return_if_fail (style->klass->draw_slider != NULL);
1097   
1098   style->klass->draw_slider (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
1099 }
1100
1101 void 
1102 gtk_draw_handle (GtkStyle      *style,
1103                  GdkWindow     *window,
1104                  GtkStateType   state_type,
1105                  GtkShadowType  shadow_type,
1106                  gint           x,
1107                  gint           y,
1108                  gint           width,
1109                  gint           height,
1110                  GtkOrientation orientation)
1111 {
1112   g_return_if_fail (style != NULL);
1113   g_return_if_fail (style->klass != NULL);
1114   g_return_if_fail (style->klass->draw_handle != NULL);
1115   
1116   style->klass->draw_handle (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
1117 }
1118
1119 void
1120 gtk_style_set_background (GtkStyle    *style,
1121                           GdkWindow   *window,
1122                           GtkStateType state_type)
1123 {
1124   GdkPixmap *pixmap;
1125   gint parent_relative;
1126   
1127   g_return_if_fail (style != NULL);
1128   g_return_if_fail (window != NULL);
1129   
1130   if (style->engine && style->engine->set_background)
1131     {
1132       style->engine->set_background (style, window, state_type);
1133       
1134       return;
1135     }
1136   
1137   if (style->bg_pixmap[state_type])
1138     {
1139       if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1140         {
1141           pixmap = NULL;
1142           parent_relative = TRUE;
1143         }
1144       else
1145         {
1146           pixmap = style->bg_pixmap[state_type];
1147           parent_relative = FALSE;
1148         }
1149       
1150       gdk_window_set_back_pixmap (window, pixmap, parent_relative);
1151     }
1152   else
1153     gdk_window_set_background (window, &style->bg[state_type]);
1154 }
1155
1156
1157 /* Default functions */
1158 void
1159 gtk_style_apply_default_background (GtkStyle     *style,
1160                                     GdkWindow    *window,
1161                                     gboolean      set_bg,
1162                                     GtkStateType  state_type, 
1163                                     GdkRectangle *area, 
1164                                     gint          x, 
1165                                     gint          y, 
1166                                     gint          width, 
1167                                     gint          height)
1168 {
1169   GdkRectangle new_rect, old_rect;
1170   
1171   if (area)
1172     {
1173       old_rect.x = x;
1174       old_rect.y = y;
1175       old_rect.width = width;
1176       old_rect.height = height;
1177       
1178       if (!gdk_rectangle_intersect (area, &old_rect, &new_rect))
1179         return;
1180     }
1181   else
1182     {
1183       new_rect.x = x;
1184       new_rect.y = y;
1185       new_rect.width = width;
1186       new_rect.height = height;
1187     }
1188   
1189   if (!style->bg_pixmap[state_type] ||
1190       gdk_window_get_type (window) == GDK_WINDOW_PIXMAP ||
1191       (!set_bg && style->bg_pixmap[state_type] != (GdkPixmap*) GDK_PARENT_RELATIVE))
1192     {
1193       GdkGC *gc = style->bg_gc[state_type];
1194       
1195       if (style->bg_pixmap[state_type])
1196         {
1197           gdk_gc_set_fill (gc, GDK_TILED);
1198           gdk_gc_set_tile (gc, style->bg_pixmap[state_type]);
1199         }
1200       
1201       gdk_draw_rectangle (window, gc, TRUE, 
1202                           new_rect.x, new_rect.y, new_rect.width, new_rect.height);
1203       if (style->bg_pixmap[state_type])
1204         gdk_gc_set_fill (gc, GDK_SOLID);
1205     }
1206   else
1207     {
1208       if (set_bg)
1209         {
1210           if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1211             gdk_window_set_back_pixmap (window, NULL, TRUE);
1212           else
1213             gdk_window_set_back_pixmap (window, style->bg_pixmap[state_type], FALSE);
1214         }
1215       
1216       gdk_window_clear_area (window, 
1217                              new_rect.x, new_rect.y, 
1218                              new_rect.width, new_rect.height);
1219     }
1220 }
1221
1222 static void
1223 gtk_default_draw_hline (GtkStyle     *style,
1224                         GdkWindow    *window,
1225                         GtkStateType  state_type,
1226                         GdkRectangle  *area,
1227                         GtkWidget     *widget,
1228                         const gchar   *detail,
1229                         gint          x1,
1230                         gint          x2,
1231                         gint          y)
1232 {
1233   gint thickness_light;
1234   gint thickness_dark;
1235   gint i;
1236   
1237   g_return_if_fail (style != NULL);
1238   g_return_if_fail (window != NULL);
1239   
1240   thickness_light = style->klass->ythickness / 2;
1241   thickness_dark = style->klass->ythickness - thickness_light;
1242   
1243   if (area)
1244     {
1245       gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
1246       gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
1247     }
1248   
1249   if (detail && !strcmp (detail, "label"))
1250     {
1251       if (state_type == GTK_STATE_INSENSITIVE)
1252         gdk_draw_line (window, style->white_gc, x1 + 1, y + 1, x2 + 1, y + 1);   
1253       gdk_draw_line (window, style->fg_gc[state_type], x1, y, x2, y);     
1254     }
1255   else
1256     {
1257       for (i = 0; i < thickness_dark; i++)
1258         {
1259           gdk_draw_line (window, style->light_gc[state_type], x2 - i - 1, y + i, x2, y + i);
1260           gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x2 - i - 1, y + i);
1261         }
1262       
1263       y += thickness_dark;
1264       for (i = 0; i < thickness_light; i++)
1265         {
1266           gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x1 + thickness_light - i - 1, y + i);
1267           gdk_draw_line (window, style->light_gc[state_type], x1 + thickness_light - i - 1, y + i, x2, y + i);
1268         }
1269     }
1270   
1271   if (area)
1272     {
1273       gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
1274       gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
1275     }
1276 }
1277
1278
1279 static void
1280 gtk_default_draw_vline (GtkStyle     *style,
1281                         GdkWindow    *window,
1282                         GtkStateType  state_type,
1283                         GdkRectangle  *area,
1284                         GtkWidget     *widget,
1285                         const gchar   *detail,
1286                         gint          y1,
1287                         gint          y2,
1288                         gint          x)
1289 {
1290   gint thickness_light;
1291   gint thickness_dark;
1292   gint i;
1293   
1294   g_return_if_fail (style != NULL);
1295   g_return_if_fail (window != NULL);
1296   
1297   thickness_light = style->klass->xthickness / 2;
1298   thickness_dark = style->klass->xthickness - thickness_light;
1299   
1300   if (area)
1301     {
1302       gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
1303       gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
1304     }
1305   for (i = 0; i < thickness_dark; i++)
1306     {
1307       gdk_draw_line (window, style->light_gc[state_type], x + i, y2 - i - 1, x + i, y2);
1308       gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y2 - i - 1);
1309     }
1310   
1311   x += thickness_dark;
1312   for (i = 0; i < thickness_light; i++)
1313     {
1314       gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y1 + thickness_light - i);
1315       gdk_draw_line (window, style->light_gc[state_type], x + i, y1 + thickness_light - i, x + i, y2);
1316     }
1317   if (area)
1318     {
1319       gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
1320       gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
1321     }
1322 }
1323
1324
1325 static void
1326 gtk_default_draw_shadow (GtkStyle      *style,
1327                          GdkWindow     *window,
1328                          GtkStateType   state_type,
1329                          GtkShadowType  shadow_type,
1330                          GdkRectangle  *area,
1331                          GtkWidget     *widget,
1332                          const gchar   *detail,
1333                          gint           x,
1334                          gint           y,
1335                          gint           width,
1336                          gint           height)
1337 {
1338   GdkGC *gc1 = NULL;
1339   GdkGC *gc2 = NULL;
1340   gint thickness_light;
1341   gint thickness_dark;
1342   gint i;
1343   
1344   g_return_if_fail (style != NULL);
1345   g_return_if_fail (window != NULL);
1346   
1347   if ((width == -1) && (height == -1))
1348     gdk_window_get_size (window, &width, &height);
1349   else if (width == -1)
1350     gdk_window_get_size (window, &width, NULL);
1351   else if (height == -1)
1352     gdk_window_get_size (window, NULL, &height);
1353   
1354   switch (shadow_type)
1355     {
1356     case GTK_SHADOW_NONE:
1357       return;
1358     case GTK_SHADOW_IN:
1359     case GTK_SHADOW_ETCHED_IN:
1360       gc1 = style->light_gc[state_type];
1361       gc2 = style->dark_gc[state_type];
1362       break;
1363     case GTK_SHADOW_OUT:
1364     case GTK_SHADOW_ETCHED_OUT:
1365       gc1 = style->dark_gc[state_type];
1366       gc2 = style->light_gc[state_type];
1367       break;
1368     }
1369   
1370   if (area)
1371     {
1372       gdk_gc_set_clip_rectangle (gc1, area);
1373       gdk_gc_set_clip_rectangle (gc2, area);
1374       if (shadow_type == GTK_SHADOW_IN || 
1375           shadow_type == GTK_SHADOW_OUT)
1376         {
1377           gdk_gc_set_clip_rectangle (style->black_gc, area);
1378           gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
1379         }
1380     }
1381   
1382   switch (shadow_type)
1383     {
1384     case GTK_SHADOW_NONE:
1385       break;
1386       
1387     case GTK_SHADOW_IN:
1388       gdk_draw_line (window, gc1,
1389                      x, y + height - 1, x + width - 1, y + height - 1);
1390       gdk_draw_line (window, gc1,
1391                      x + width - 1, y, x + width - 1, y + height - 1);
1392       
1393       gdk_draw_line (window, style->bg_gc[state_type],
1394                      x + 1, y + height - 2, x + width - 2, y + height - 2);
1395       gdk_draw_line (window, style->bg_gc[state_type],
1396                      x + width - 2, y + 1, x + width - 2, y + height - 2);
1397       
1398       gdk_draw_line (window, style->black_gc,
1399                      x + 1, y + 1, x + width - 2, y + 1);
1400       gdk_draw_line (window, style->black_gc,
1401                      x + 1, y + 1, x + 1, y + height - 2);
1402       
1403       gdk_draw_line (window, gc2,
1404                      x, y, x + width - 1, y);
1405       gdk_draw_line (window, gc2,
1406                      x, y, x, y + height - 1);
1407       break;
1408       
1409     case GTK_SHADOW_OUT:
1410       gdk_draw_line (window, gc1,
1411                      x + 1, y + height - 2, x + width - 2, y + height - 2);
1412       gdk_draw_line (window, gc1,
1413                      x + width - 2, y + 1, x + width - 2, y + height - 2);
1414       
1415       gdk_draw_line (window, gc2,
1416                      x, y, x + width - 1, y);
1417       gdk_draw_line (window, gc2,
1418                      x, y, x, y + height - 1);
1419       
1420       gdk_draw_line (window, style->bg_gc[state_type],
1421                      x + 1, y + 1, x + width - 2, y + 1);
1422       gdk_draw_line (window, style->bg_gc[state_type],
1423                      x + 1, y + 1, x + 1, y + height - 2);
1424       
1425       gdk_draw_line (window, style->black_gc,
1426                      x, y + height - 1, x + width - 1, y + height - 1);
1427       gdk_draw_line (window, style->black_gc,
1428                      x + width - 1, y, x + width - 1, y + height - 1);
1429       break;
1430       
1431     case GTK_SHADOW_ETCHED_IN:
1432     case GTK_SHADOW_ETCHED_OUT:
1433       thickness_light = 1;
1434       thickness_dark = 1;
1435       
1436       for (i = 0; i < thickness_dark; i++)
1437         {
1438           gdk_draw_line (window, gc1,
1439                          x + i,
1440                          y + height - i - 1,
1441                          x + width - i - 1,
1442                          y + height - i - 1);
1443           gdk_draw_line (window, gc1,
1444                          x + width - i - 1,
1445                          y + i,
1446                          x + width - i - 1,
1447                          y + height - i - 1);
1448           
1449           gdk_draw_line (window, gc2,
1450                          x + i,
1451                          y + i,
1452                          x + width - i - 2,
1453                          y + i);
1454           gdk_draw_line (window, gc2,
1455                          x + i,
1456                          y + i,
1457                          x + i,
1458                          y + height - i - 2);
1459         }
1460       
1461       for (i = 0; i < thickness_light; i++)
1462         {
1463           gdk_draw_line (window, gc1,
1464                          x + thickness_dark + i,
1465                          y + thickness_dark + i,
1466                          x + width - thickness_dark - i - 1,
1467                          y + thickness_dark + i);
1468           gdk_draw_line (window, gc1,
1469                          x + thickness_dark + i,
1470                          y + thickness_dark + i,
1471                          x + thickness_dark + i,
1472                          y + height - thickness_dark - i - 1);
1473           
1474           gdk_draw_line (window, gc2,
1475                          x + thickness_dark + i,
1476                          y + height - thickness_light - i - 1,
1477                          x + width - thickness_light - 1,
1478                          y + height - thickness_light - i - 1);
1479           gdk_draw_line (window, gc2,
1480                          x + width - thickness_light - i - 1,
1481                          y + thickness_dark + i,
1482                          x + width - thickness_light - i - 1,
1483                          y + height - thickness_light - 1);
1484         }
1485       break;
1486     }
1487   if (area)
1488     {
1489       gdk_gc_set_clip_rectangle (gc1, NULL);
1490       gdk_gc_set_clip_rectangle (gc2, NULL);
1491       if (shadow_type == GTK_SHADOW_IN || 
1492           shadow_type == GTK_SHADOW_OUT)
1493         {
1494           gdk_gc_set_clip_rectangle (style->black_gc, NULL);
1495           gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
1496         }
1497     }
1498 }
1499
1500 static void
1501 gtk_default_draw_polygon (GtkStyle      *style,
1502                           GdkWindow     *window,
1503                           GtkStateType   state_type,
1504                           GtkShadowType  shadow_type,
1505                           GdkRectangle  *area,
1506                           GtkWidget     *widget,
1507                           const gchar   *detail,
1508                           GdkPoint      *points,
1509                           gint           npoints,
1510                           gboolean       fill)
1511 {
1512   static const gdouble pi_over_4 = M_PI_4;
1513   static const gdouble pi_3_over_4 = M_PI_4 * 3;
1514   GdkGC *gc1;
1515   GdkGC *gc2;
1516   GdkGC *gc3;
1517   GdkGC *gc4;
1518   gdouble angle;
1519   gint xadjust;
1520   gint yadjust;
1521   gint i;
1522   
1523   g_return_if_fail (style != NULL);
1524   g_return_if_fail (window != NULL);
1525   g_return_if_fail (points != NULL);
1526   
1527   switch (shadow_type)
1528     {
1529     case GTK_SHADOW_IN:
1530       gc1 = style->bg_gc[state_type];
1531       gc2 = style->dark_gc[state_type];
1532       gc3 = style->light_gc[state_type];
1533       gc4 = style->black_gc;
1534       break;
1535     case GTK_SHADOW_ETCHED_IN:
1536       gc1 = style->light_gc[state_type];
1537       gc2 = style->dark_gc[state_type];
1538       gc3 = style->dark_gc[state_type];
1539       gc4 = style->light_gc[state_type];
1540       break;
1541     case GTK_SHADOW_OUT:
1542       gc1 = style->dark_gc[state_type];
1543       gc2 = style->light_gc[state_type];
1544       gc3 = style->black_gc;
1545       gc4 = style->bg_gc[state_type];
1546       break;
1547     case GTK_SHADOW_ETCHED_OUT:
1548       gc1 = style->dark_gc[state_type];
1549       gc2 = style->light_gc[state_type];
1550       gc3 = style->light_gc[state_type];
1551       gc4 = style->dark_gc[state_type];
1552       break;
1553     default:
1554       return;
1555     }
1556   
1557   if (area)
1558     {
1559       gdk_gc_set_clip_rectangle (gc1, area);
1560       gdk_gc_set_clip_rectangle (gc2, area);
1561       gdk_gc_set_clip_rectangle (gc3, area);
1562       gdk_gc_set_clip_rectangle (gc4, area);
1563     }
1564   
1565   if (fill)
1566     gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, npoints);
1567   
1568   npoints--;
1569   
1570   for (i = 0; i < npoints; i++)
1571     {
1572       if ((points[i].x == points[i+1].x) &&
1573           (points[i].y == points[i+1].y))
1574         {
1575           angle = 0;
1576         }
1577       else
1578         {
1579           angle = atan2 (points[i+1].y - points[i].y,
1580                          points[i+1].x - points[i].x);
1581         }
1582       
1583       if ((angle > -pi_3_over_4) && (angle < pi_over_4))
1584         {
1585           if (angle > -pi_over_4)
1586             {
1587               xadjust = 0;
1588               yadjust = 1;
1589             }
1590           else
1591             {
1592               xadjust = 1;
1593               yadjust = 0;
1594             }
1595           
1596           gdk_draw_line (window, gc1,
1597                          points[i].x-xadjust, points[i].y-yadjust,
1598                          points[i+1].x-xadjust, points[i+1].y-yadjust);
1599           gdk_draw_line (window, gc3,
1600                          points[i].x, points[i].y,
1601                          points[i+1].x, points[i+1].y);
1602         }
1603       else
1604         {
1605           if ((angle < -pi_3_over_4) || (angle > pi_3_over_4))
1606             {
1607               xadjust = 0;
1608               yadjust = 1;
1609             }
1610           else
1611             {
1612               xadjust = 1;
1613               yadjust = 0;
1614             }
1615           
1616           gdk_draw_line (window, gc4,
1617                          points[i].x+xadjust, points[i].y+yadjust,
1618                          points[i+1].x+xadjust, points[i+1].y+yadjust);
1619           gdk_draw_line (window, gc2,
1620                          points[i].x, points[i].y,
1621                          points[i+1].x, points[i+1].y);
1622         }
1623     }
1624
1625   if (area)
1626     {
1627       gdk_gc_set_clip_rectangle (gc1, NULL);
1628       gdk_gc_set_clip_rectangle (gc2, NULL);
1629       gdk_gc_set_clip_rectangle (gc3, NULL);
1630       gdk_gc_set_clip_rectangle (gc4, NULL);
1631     }
1632 }
1633
1634 static void
1635 gtk_default_draw_arrow (GtkStyle      *style,
1636                         GdkWindow     *window,
1637                         GtkStateType   state_type,
1638                         GtkShadowType  shadow_type,
1639                         GdkRectangle  *area,
1640                         GtkWidget     *widget,
1641                         const gchar   *detail,
1642                         GtkArrowType   arrow_type,
1643                         gboolean       fill,
1644                         gint           x,
1645                         gint           y,
1646                         gint           width,
1647                         gint           height)
1648 {
1649   GdkGC *gc1;
1650   GdkGC *gc2;
1651   GdkGC *gc3;
1652   GdkGC *gc4;
1653   gint half_width;
1654   gint half_height;
1655   GdkPoint points[3];
1656   
1657   g_return_if_fail (style != NULL);
1658   g_return_if_fail (window != NULL);
1659   
1660   switch (shadow_type)
1661     {
1662     case GTK_SHADOW_IN:
1663       gc1 = style->bg_gc[state_type];
1664       gc2 = style->dark_gc[state_type];
1665       gc3 = style->light_gc[state_type];
1666       gc4 = style->black_gc;
1667       break;
1668     case GTK_SHADOW_OUT:
1669       gc1 = style->dark_gc[state_type];
1670       gc2 = style->light_gc[state_type];
1671       gc3 = style->black_gc;
1672       gc4 = style->bg_gc[state_type];
1673       break;
1674     case GTK_SHADOW_ETCHED_IN:
1675       gc1 = style->light_gc[state_type];
1676       gc2 = style->dark_gc[state_type];
1677       gc3 = NULL;
1678       gc4 = NULL;
1679       break;
1680     case GTK_SHADOW_ETCHED_OUT:
1681       gc1 = style->dark_gc[state_type];
1682       gc2 = style->light_gc[state_type];
1683       gc3 = NULL;
1684       gc4 = NULL;
1685       break;
1686     default:
1687       return;
1688     }
1689   
1690   if ((width == -1) && (height == -1))
1691     gdk_window_get_size (window, &width, &height);
1692   else if (width == -1)
1693     gdk_window_get_size (window, &width, NULL);
1694   else if (height == -1)
1695     gdk_window_get_size (window, NULL, &height);
1696   
1697   half_width = width / 2;
1698   half_height = height / 2;
1699   
1700   if (area)
1701     {
1702       gdk_gc_set_clip_rectangle (gc1, area);
1703       gdk_gc_set_clip_rectangle (gc2, area);
1704       if ((gc3) && (gc4))
1705         {
1706           gdk_gc_set_clip_rectangle (gc3, area);
1707           gdk_gc_set_clip_rectangle (gc4, area);
1708         }
1709     }
1710   
1711   switch (arrow_type)
1712     {
1713     case GTK_ARROW_UP:
1714       if (fill)
1715         {
1716           points[0].x = x + half_width;
1717           points[0].y = y;
1718           points[1].x = x;
1719           points[1].y = y + height - 1;
1720           points[2].x = x + width - 1;
1721           points[2].y = y + height - 1;
1722           
1723           gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
1724         }
1725       
1726       switch (shadow_type)
1727         {
1728         case GTK_SHADOW_IN:
1729         case GTK_SHADOW_OUT:
1730           
1731           gdk_draw_line (window, gc1,
1732                          x + 1, y + height - 2,
1733                          x + width - 2, y + height - 2);
1734           gdk_draw_line (window, gc3,
1735                          x + 0, y + height - 1,
1736                          x + width - 1, y + height - 1);
1737           
1738           gdk_draw_line (window, gc1,
1739                          x + width - 2, y + height - 1,
1740                          x + half_width, y + 1);
1741           gdk_draw_line (window, gc3,
1742                          x + width - 1, y + height - 1,
1743                          x + half_width, y);
1744           
1745           gdk_draw_line (window, gc4,
1746                          x + half_width, y + 1,
1747                          x + 1, y + height - 1);
1748           gdk_draw_line (window, gc2,
1749                          x + half_width, y,
1750                          x, y + height - 1);
1751           break;
1752           
1753         case GTK_SHADOW_ETCHED_IN:
1754         case GTK_SHADOW_ETCHED_OUT:
1755           gdk_draw_line (window, gc1,
1756                          x + half_width, y + 1,
1757                          x + 1, y + height - 1);
1758           gdk_draw_line (window, gc1,
1759                          x + 1, y + height - 1,
1760                          x + width - 1, y + height - 1);
1761           gdk_draw_line (window, gc1,
1762                          x + width - 1, y + height - 1,
1763                          x + half_width + 1, y + 1);
1764           
1765           points[0].x = x + half_width;
1766           points[0].y = y;
1767           points[1].x = x;
1768           points[1].y = y + height - 2;
1769           points[2].x = x + width - 2;
1770           points[2].y = y + height - 2;
1771           
1772           gdk_draw_polygon (window, gc2, FALSE, points, 3);
1773           break;
1774           
1775         default:
1776           break;
1777         }
1778       break;
1779       
1780     case GTK_ARROW_DOWN:
1781       if (fill)
1782         {
1783           points[0].x = x + width - 1;
1784           points[0].y = y;
1785           points[1].x = x;
1786           points[1].y = y;
1787           points[2].x = x + half_width;
1788           points[2].y = y + height - 1;
1789           
1790           gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
1791         }
1792       switch (shadow_type)
1793         {
1794         case GTK_SHADOW_IN:
1795         case GTK_SHADOW_OUT:
1796           gdk_draw_line (window, gc4,
1797                          x + width - 2,
1798                          y + 1, x + 1, y + 1);
1799           gdk_draw_line (window, gc2,
1800                          x + width - 1, y,
1801                          x, y);
1802           
1803           gdk_draw_line (window, gc4,
1804                          x + 1, y,
1805                          x + half_width, y + height - 2);
1806           gdk_draw_line (window, gc2,
1807                          x, y,
1808                          x + half_width, y + height - 1);
1809           
1810           gdk_draw_line (window, gc1,
1811                          x + half_width, y + height - 2,
1812                          x + width - 2, y);
1813           gdk_draw_line (window, gc3,
1814                          x + half_width, y + height - 1,
1815                          x + width - 1, y);
1816           break;
1817           
1818         case GTK_SHADOW_ETCHED_IN:
1819         case GTK_SHADOW_ETCHED_OUT:
1820           gdk_draw_line (window, gc1,
1821                          x + width - 1, y + 1,
1822                          x + 1, y + 1);
1823           gdk_draw_line (window, gc1,
1824                          x + 1, y + 1,
1825                          x + half_width + 1, y + height - 1);
1826           gdk_draw_line (window, gc1,
1827                          x + half_width + 1, y + height - 2,
1828                          x + width - 1, y);
1829           
1830           points[0].x = x + width - 2;
1831           points[0].y = y;
1832           points[1].x = x;
1833           points[1].y = y;
1834           points[2].x = x + half_width;
1835           points[2].y = y + height - 2;
1836           
1837           gdk_draw_polygon (window, gc2, FALSE, points, 3);
1838           break;
1839           
1840         default:
1841           break;
1842         }
1843       break;
1844     case GTK_ARROW_LEFT:
1845       if (fill)
1846         {
1847           points[0].x = x;
1848           points[0].y = y + half_height;
1849           points[1].x = x + width - 1;
1850           points[1].y = y + height - 1;
1851           points[2].x = x + width - 1;
1852           points[2].y = y;
1853           
1854           gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
1855         }
1856       
1857       switch (shadow_type)
1858         {
1859         case GTK_SHADOW_IN:
1860         case GTK_SHADOW_OUT:
1861           gdk_draw_line (window, gc1,
1862                          x + 1, y + half_height,
1863                          x + width - 1, y + height - 1);
1864           gdk_draw_line (window, gc3,
1865                          x, y + half_height,
1866                          x + width - 1, y + height - 1);
1867           
1868           gdk_draw_line (window, gc1,
1869                          x + width - 2, y + height - 1,
1870                          x + width - 2, y + 1);
1871           gdk_draw_line (window, gc3,
1872                          x + width - 1, y + height - 1,
1873                          x + width - 1, y);
1874           
1875           gdk_draw_line (window, gc4,
1876                          x + width - 1, y + 1,
1877                          x + 1, y + half_height);
1878           gdk_draw_line (window, gc2,
1879                          x + width - 1, y,
1880                          x, y + half_height);
1881           break;
1882           
1883         case GTK_SHADOW_ETCHED_IN:
1884         case GTK_SHADOW_ETCHED_OUT:
1885           gdk_draw_line (window, gc1,
1886                          x + width - 1, y + 1,
1887                          x + 1, y + half_height);
1888           gdk_draw_line (window, gc1,
1889                          x + 1, y + half_height + 1,
1890                          x + width - 1, y + height - 1);
1891           gdk_draw_line (window, gc1,
1892                          x + width - 1, y + height - 1,
1893                          x + width - 1, y + 1);
1894           
1895           points[0].x = x + width - 2;
1896           points[0].y = y;
1897           points[1].x = x;
1898           points[1].y = y + half_height;
1899           points[2].x = x + width - 2;
1900           points[2].y = y + height - 2;
1901           
1902           gdk_draw_polygon (window, gc2, FALSE, points, 3);
1903           break;
1904           
1905         default:
1906           break;
1907         }
1908       break;
1909     case GTK_ARROW_RIGHT:
1910       if (fill)
1911         {
1912           points[0].x = x + width - 1;
1913           points[0].y = y + half_height;
1914           points[1].x = x;
1915           points[1].y = y;
1916           points[2].x = x;
1917           points[2].y = y + height - 1;
1918           
1919           gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
1920         }
1921       
1922       switch (shadow_type)
1923         {
1924         case GTK_SHADOW_IN:
1925         case GTK_SHADOW_OUT:
1926           gdk_draw_line (window, gc4,
1927                          x + width - 1, y + half_height,
1928                          x + 1, y + 1);
1929           gdk_draw_line (window, gc2,
1930                          x + width - 1, y + half_height,
1931                          x, y);
1932           gdk_draw_line (window, gc4,
1933                          x + 1, y + 1,
1934                          x + 1, y + height - 2);
1935           gdk_draw_line (window, gc2,
1936                          x, y,
1937                          x, y + height - 1);
1938           
1939           gdk_draw_line (window, gc1,
1940                          x + 1, y + height - 2,
1941                          x + width - 1, y + half_height);
1942           gdk_draw_line (window, gc3,
1943                          x, y + height - 1,
1944                          x + width - 1, y + half_height);
1945           break;
1946           
1947         case GTK_SHADOW_ETCHED_IN:
1948         case GTK_SHADOW_ETCHED_OUT:
1949           gdk_draw_line (window, gc1,
1950                          x + width - 1, y + half_height + 1,
1951                          x + 1, y + 1);
1952           gdk_draw_line (window, gc1,
1953                          x + 1, y + 1,
1954                          x + 1, y + height - 1);
1955           gdk_draw_line (window, gc1,
1956                          x + 1, y + height - 1,
1957                          x + width - 1, y + half_height + 1);
1958           
1959           points[0].x = x + width - 2;
1960           points[0].y = y + half_height;
1961           points[1].x = x;
1962           points[1].y = y;
1963           points[2].x = x;
1964           points[2].y = y + height - 1;
1965           
1966           gdk_draw_polygon (window, gc2, FALSE, points, 3);
1967           break;
1968           
1969         default:
1970           break;
1971         }
1972       break;
1973     }
1974
1975   if (area)
1976     {
1977       gdk_gc_set_clip_rectangle (gc1, NULL);
1978       gdk_gc_set_clip_rectangle (gc2, NULL);
1979       if (gc3)
1980         {
1981           gdk_gc_set_clip_rectangle (gc3, NULL);
1982           gdk_gc_set_clip_rectangle (gc4, NULL);
1983         }
1984     }
1985 }
1986
1987 static void
1988 gtk_default_draw_diamond (GtkStyle      *style,
1989                           GdkWindow     *window,
1990                           GtkStateType   state_type,
1991                           GtkShadowType  shadow_type,
1992                           GdkRectangle  *area,
1993                           GtkWidget     *widget,
1994                           const gchar   *detail,
1995                           gint           x,
1996                           gint           y,
1997                           gint           width,
1998                           gint           height)
1999 {
2000   gint half_width;
2001   gint half_height;
2002   
2003   g_return_if_fail (style != NULL);
2004   g_return_if_fail (window != NULL);
2005   
2006   if ((width == -1) && (height == -1))
2007     gdk_window_get_size (window, &width, &height);
2008   else if (width == -1)
2009     gdk_window_get_size (window, &width, NULL);
2010   else if (height == -1)
2011     gdk_window_get_size (window, NULL, &height);
2012   
2013   half_width = width / 2;
2014   half_height = height / 2;
2015   
2016   if (area)
2017     {
2018       gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
2019       gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2020       gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
2021       gdk_gc_set_clip_rectangle (style->black_gc, area);
2022     }
2023   switch (shadow_type)
2024     {
2025     case GTK_SHADOW_IN:
2026       gdk_draw_line (window, style->bg_gc[state_type],
2027                      x + 2, y + half_height,
2028                      x + half_width, y + height - 2);
2029       gdk_draw_line (window, style->bg_gc[state_type],
2030                      x + half_width, y + height - 2,
2031                      x + width - 2, y + half_height);
2032       gdk_draw_line (window, style->light_gc[state_type],
2033                      x + 1, y + half_height,
2034                      x + half_width, y + height - 1);
2035       gdk_draw_line (window, style->light_gc[state_type],
2036                      x + half_width, y + height - 1,
2037                      x + width - 1, y + half_height);
2038       gdk_draw_line (window, style->light_gc[state_type],
2039                      x, y + half_height,
2040                      x + half_width, y + height);
2041       gdk_draw_line (window, style->light_gc[state_type],
2042                      x + half_width, y + height,
2043                      x + width, y + half_height);
2044       
2045       gdk_draw_line (window, style->black_gc,
2046                      x + 2, y + half_height,
2047                      x + half_width, y + 2);
2048       gdk_draw_line (window, style->black_gc,
2049                      x + half_width, y + 2,
2050                      x + width - 2, y + half_height);
2051       gdk_draw_line (window, style->dark_gc[state_type],
2052                      x + 1, y + half_height,
2053                      x + half_width, y + 1);
2054       gdk_draw_line (window, style->dark_gc[state_type],
2055                      x + half_width, y + 1,
2056                      x + width - 1, y + half_height);
2057       gdk_draw_line (window, style->dark_gc[state_type],
2058                      x, y + half_height,
2059                      x + half_width, y);
2060       gdk_draw_line (window, style->dark_gc[state_type],
2061                      x + half_width, y,
2062                      x + width, y + half_height);
2063       break;
2064     case GTK_SHADOW_OUT:
2065       gdk_draw_line (window, style->dark_gc[state_type],
2066                      x + 2, y + half_height,
2067                      x + half_width, y + height - 2);
2068       gdk_draw_line (window, style->dark_gc[state_type],
2069                      x + half_width, y + height - 2,
2070                      x + width - 2, y + half_height);
2071       gdk_draw_line (window, style->dark_gc[state_type],
2072                      x + 1, y + half_height,
2073                      x + half_width, y + height - 1);
2074       gdk_draw_line (window, style->dark_gc[state_type],
2075                      x + half_width, y + height - 1,
2076                      x + width - 1, y + half_height);
2077       gdk_draw_line (window, style->black_gc,
2078                      x, y + half_height,
2079                      x + half_width, y + height);
2080       gdk_draw_line (window, style->black_gc,
2081                      x + half_width, y + height,
2082                      x + width, y + half_height);
2083       
2084       gdk_draw_line (window, style->bg_gc[state_type],
2085                      x + 2, y + half_height,
2086                      x + half_width, y + 2);
2087       gdk_draw_line (window, style->bg_gc[state_type],
2088                      x + half_width, y + 2,
2089                      x + width - 2, y + half_height);
2090       gdk_draw_line (window, style->light_gc[state_type],
2091                      x + 1, y + half_height,
2092                      x + half_width, y + 1);
2093       gdk_draw_line (window, style->light_gc[state_type],
2094                      x + half_width, y + 1,
2095                      x + width - 1, y + half_height);
2096       gdk_draw_line (window, style->light_gc[state_type],
2097                      x, y + half_height,
2098                      x + half_width, y);
2099       gdk_draw_line (window, style->light_gc[state_type],
2100                      x + half_width, y,
2101                      x + width, y + half_height);
2102       break;
2103     default:
2104       break;
2105     }
2106   if (area)
2107     {
2108       gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
2109       gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
2110       gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
2111       gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2112     }
2113 }
2114
2115 static void
2116 gtk_default_draw_oval (GtkStyle      *style,
2117                        GdkWindow     *window,
2118                        GtkStateType   state_type,
2119                        GtkShadowType  shadow_type,
2120                        GdkRectangle  *area,
2121                        GtkWidget     *widget,
2122                        const gchar   *detail,
2123                        gint           x,
2124                        gint           y,
2125                        gint           width,
2126                        gint           height)
2127 {
2128   g_return_if_fail (style != NULL);
2129   g_return_if_fail (window != NULL);
2130
2131   g_warning ("gtk_default_draw_oval(): FIXME, this function is currently unimplemented");
2132 }
2133
2134 static void
2135 gtk_default_draw_string (GtkStyle      *style,
2136                          GdkWindow     *window,
2137                          GtkStateType   state_type,
2138                          GdkRectangle  *area,
2139                          GtkWidget     *widget,
2140                          const gchar   *detail,
2141                          gint           x,
2142                          gint           y,
2143                          const gchar   *string)
2144 {
2145   g_return_if_fail (style != NULL);
2146   g_return_if_fail (window != NULL);
2147   
2148   if (area)
2149     {
2150       gdk_gc_set_clip_rectangle (style->white_gc, area);
2151       gdk_gc_set_clip_rectangle (style->fg_gc[state_type], area);
2152     }
2153
2154   if (state_type == GTK_STATE_INSENSITIVE)
2155     gdk_draw_string (window, style->font, style->white_gc, x + 1, y + 1, string);
2156
2157   gdk_draw_string (window, style->font, style->fg_gc[state_type], x, y, string);
2158
2159   if (area)
2160     {
2161       gdk_gc_set_clip_rectangle (style->white_gc, NULL);
2162       gdk_gc_set_clip_rectangle (style->fg_gc[state_type], NULL);
2163     }
2164 }
2165
2166 static void 
2167 gtk_default_draw_box (GtkStyle      *style,
2168                       GdkWindow     *window,
2169                       GtkStateType   state_type,
2170                       GtkShadowType  shadow_type,
2171                       GdkRectangle  *area,
2172                       GtkWidget     *widget,
2173                       const gchar   *detail,
2174                       gint           x,
2175                       gint           y,
2176                       gint           width,
2177                       gint           height)
2178 {
2179   g_return_if_fail (style != NULL);
2180   g_return_if_fail (window != NULL);
2181   
2182   if (width == -1 && height == -1)
2183     gdk_window_get_size (window, &width, &height);
2184   else if (width == -1)
2185     gdk_window_get_size (window, &width, NULL);
2186   else if (height == -1)
2187     gdk_window_get_size (window, NULL, &height);
2188   
2189   if (!style->bg_pixmap[state_type] || 
2190       gdk_window_get_type (window) == GDK_WINDOW_PIXMAP)
2191     {
2192       if (area)
2193         gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2194
2195       gdk_draw_rectangle (window, style->bg_gc[state_type], TRUE,
2196                           x, y, width, height);
2197       if (area)
2198         gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
2199     }
2200   else
2201     gtk_style_apply_default_background (style, window,
2202                                         widget && !GTK_WIDGET_NO_WINDOW (widget),
2203                                         state_type, area, x, y, width, height);
2204   
2205   gtk_paint_shadow (style, window, state_type, shadow_type, area, widget, detail,
2206                     x, y, width, height);
2207 }
2208
2209 static void 
2210 gtk_default_draw_flat_box (GtkStyle      *style,
2211                            GdkWindow     *window,
2212                            GtkStateType   state_type,
2213                            GtkShadowType  shadow_type,
2214                            GdkRectangle  *area,
2215                            GtkWidget     *widget,
2216                            const gchar   *detail,
2217                            gint           x,
2218                            gint           y,
2219                            gint           width,
2220                            gint           height)
2221 {
2222   GdkGC *gc1;
2223   
2224   g_return_if_fail (style != NULL);
2225   g_return_if_fail (window != NULL);
2226   
2227   if (width == -1 && height == -1)
2228     gdk_window_get_size (window, &width, &height);
2229   else if (width == -1)
2230     gdk_window_get_size (window, &width, NULL);
2231   else if (height == -1)
2232     gdk_window_get_size (window, NULL, &height);
2233   
2234   if (detail)
2235     {
2236       if (!strcmp ("text", detail) && state_type == GTK_STATE_SELECTED)
2237         gc1 = style->bg_gc[GTK_STATE_SELECTED];
2238       else if (!strcmp ("viewportbin", detail))
2239         gc1 = style->bg_gc[GTK_STATE_NORMAL];
2240       else if (!strcmp ("entry_bg", detail))
2241         gc1 = style->base_gc[state_type];
2242       else
2243         gc1 = style->bg_gc[state_type];
2244     }
2245   else
2246     gc1 = style->bg_gc[state_type];
2247   
2248   if (!style->bg_pixmap[state_type] || gc1 != style->bg_gc[state_type] ||
2249       gdk_window_get_type (window) == GDK_WINDOW_PIXMAP)
2250     {
2251       if (area)
2252         gdk_gc_set_clip_rectangle (gc1, area);
2253
2254       gdk_draw_rectangle (window, gc1, TRUE,
2255                           x, y, width, height);
2256
2257       if (detail && !strcmp ("tooltip", detail))
2258         gdk_draw_rectangle (window, style->black_gc, FALSE,
2259                             x, y, width - 1, height - 1);
2260
2261       if (area)
2262         gdk_gc_set_clip_rectangle (gc1, NULL);
2263     }
2264   else
2265     gtk_style_apply_default_background (style, window,
2266                                         widget && !GTK_WIDGET_NO_WINDOW (widget),
2267                                         state_type, area, x, y, width, height);
2268 }
2269
2270 static void 
2271 gtk_default_draw_check (GtkStyle      *style,
2272                         GdkWindow     *window,
2273                         GtkStateType   state_type,
2274                         GtkShadowType  shadow_type,
2275                         GdkRectangle  *area,
2276                         GtkWidget     *widget,
2277                         const gchar   *detail,
2278                         gint           x,
2279                         gint           y,
2280                         gint           width,
2281                         gint           height)
2282 {
2283   gtk_paint_box (style, window, state_type, shadow_type, area, widget, detail,
2284                  x, y, width, height);
2285 }
2286
2287 static void 
2288 gtk_default_draw_option (GtkStyle      *style,
2289                          GdkWindow     *window,
2290                          GtkStateType   state_type,
2291                          GtkShadowType  shadow_type,
2292                          GdkRectangle  *area,
2293                          GtkWidget     *widget,
2294                          const gchar   *detail,
2295                          gint           x,
2296                          gint           y,
2297                          gint           width,
2298                          gint           height)
2299 {
2300   gtk_paint_diamond (style, window, state_type, shadow_type, area, widget, 
2301                      detail, x, y, width, height);
2302 }
2303
2304 static void 
2305 gtk_default_draw_cross (GtkStyle      *style,
2306                         GdkWindow     *window,
2307                         GtkStateType   state_type,
2308                         GtkShadowType  shadow_type,
2309                         GdkRectangle  *area,
2310                         GtkWidget     *widget,
2311                         const gchar   *detail,
2312                         gint           x,
2313                         gint           y,
2314                         gint           width,
2315                         gint           height)
2316 {
2317   g_return_if_fail (style != NULL);
2318   g_return_if_fail (window != NULL);
2319
2320   g_warning ("gtk_default_draw_cross(): FIXME, this function is currently unimplemented");
2321 }
2322
2323 static void 
2324 gtk_default_draw_ramp    (GtkStyle      *style,
2325                           GdkWindow     *window,
2326                           GtkStateType   state_type,
2327                           GtkShadowType  shadow_type,
2328                           GdkRectangle  *area,
2329                           GtkWidget     *widget,
2330                           const gchar   *detail,
2331                           GtkArrowType   arrow_type,
2332                           gint           x,
2333                           gint           y,
2334                           gint           width,
2335                           gint           height)
2336 {
2337   g_return_if_fail (style != NULL);
2338   g_return_if_fail (window != NULL);
2339
2340   g_warning ("gtk_default_draw_ramp(): FIXME, this function is currently unimplemented");
2341 }
2342
2343 static void
2344 gtk_default_draw_tab (GtkStyle      *style,
2345                       GdkWindow     *window,
2346                       GtkStateType   state_type,
2347                       GtkShadowType  shadow_type,
2348                       GdkRectangle  *area,
2349                       GtkWidget     *widget,
2350                       const gchar   *detail,
2351                       gint           x,
2352                       gint           y,
2353                       gint           width,
2354                       gint           height)
2355 {
2356   g_return_if_fail (style != NULL);
2357   g_return_if_fail (window != NULL);
2358   
2359   gtk_paint_box (style, window, state_type, shadow_type, area, widget, detail,
2360                  x, y, width, height);
2361 }
2362
2363 static void 
2364 gtk_default_draw_shadow_gap (GtkStyle       *style,
2365                              GdkWindow      *window,
2366                              GtkStateType    state_type,
2367                              GtkShadowType   shadow_type,
2368                              GdkRectangle   *area,
2369                              GtkWidget      *widget,
2370                              const gchar    *detail,
2371                              gint            x,
2372                              gint            y,
2373                              gint            width,
2374                              gint            height,
2375                              GtkPositionType gap_side,
2376                              gint            gap_x,
2377                              gint            gap_width)
2378 {
2379   GdkGC *gc1 = NULL;
2380   GdkGC *gc2 = NULL;
2381   GdkGC *gc3 = NULL;
2382   GdkGC *gc4 = NULL;
2383   
2384   g_return_if_fail (style != NULL);
2385   g_return_if_fail (window != NULL);
2386   
2387   if (width == -1 && height == -1)
2388     gdk_window_get_size (window, &width, &height);
2389   else if (width == -1)
2390     gdk_window_get_size (window, &width, NULL);
2391   else if (height == -1)
2392     gdk_window_get_size (window, NULL, &height);
2393   
2394   switch (shadow_type)
2395     {
2396     case GTK_SHADOW_NONE:
2397       return;
2398     case GTK_SHADOW_IN:
2399       gc1 = style->dark_gc[state_type];
2400       gc2 = style->black_gc;
2401       gc3 = style->bg_gc[state_type];
2402       gc4 = style->light_gc[state_type];
2403       break;
2404     case GTK_SHADOW_ETCHED_IN:
2405       gc1 = style->dark_gc[state_type];
2406       gc2 = style->light_gc[state_type];
2407       gc3 = style->dark_gc[state_type];
2408       gc4 = style->light_gc[state_type];
2409       break;
2410     case GTK_SHADOW_OUT:
2411       gc1 = style->light_gc[state_type];
2412       gc2 = style->bg_gc[state_type];
2413       gc3 = style->dark_gc[state_type];
2414       gc4 = style->black_gc;
2415       break;
2416     case GTK_SHADOW_ETCHED_OUT:
2417       gc1 = style->light_gc[state_type];
2418       gc2 = style->dark_gc[state_type];
2419       gc3 = style->light_gc[state_type];
2420       gc4 = style->dark_gc[state_type];
2421       break;
2422     }
2423   if (area)
2424     {
2425       gdk_gc_set_clip_rectangle (gc1, area);
2426       gdk_gc_set_clip_rectangle (gc2, area);
2427       gdk_gc_set_clip_rectangle (gc3, area);
2428       gdk_gc_set_clip_rectangle (gc4, area);
2429     }
2430   
2431   switch (shadow_type)
2432     {
2433     case GTK_SHADOW_NONE:
2434     case GTK_SHADOW_IN:
2435     case GTK_SHADOW_OUT:
2436     case GTK_SHADOW_ETCHED_IN:
2437     case GTK_SHADOW_ETCHED_OUT:
2438       switch (gap_side)
2439         {
2440         case GTK_POS_TOP:
2441           gdk_draw_line (window, gc1,
2442                          x, y, x, y + height - 1);
2443           gdk_draw_line (window, gc2,
2444                          x + 1, y, x + 1, y + height - 2);
2445           
2446           gdk_draw_line (window, gc3,
2447                          x + 1, y + height - 2, x + width - 2, y + height - 2);
2448           gdk_draw_line (window, gc3,
2449                          x + width - 2, y, x + width - 2, y + height - 2);
2450           gdk_draw_line (window, gc4,
2451                          x, y + height - 1, x + width - 1, y + height - 1);
2452           gdk_draw_line (window, gc4,
2453                          x + width - 1, y, x + width - 1, y + height - 1);
2454           if (gap_x > 0)
2455             {
2456               gdk_draw_line (window, gc1,
2457                              x, y, x + gap_x - 1, y);
2458               gdk_draw_line (window, gc2,
2459                              x + 1, y + 1, x + gap_x - 1, y + 1);
2460               gdk_draw_line (window, gc2,
2461                              x + gap_x, y, x + gap_x, y);
2462             }
2463           if ((width - (gap_x + gap_width)) > 0)
2464             {
2465               gdk_draw_line (window, gc1,
2466                              x + gap_x + gap_width, y, x + width - 2, y);
2467               gdk_draw_line (window, gc2,
2468                              x + gap_x + gap_width, y + 1, x + width - 2, y + 1);
2469               gdk_draw_line (window, gc2,
2470                              x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
2471             }
2472           break;
2473         case GTK_POS_BOTTOM:
2474           gdk_draw_line (window, gc1,
2475                          x, y, x + width - 1, y);
2476           gdk_draw_line (window, gc1,
2477                          x, y, x, y + height - 1);
2478           gdk_draw_line (window, gc2,
2479                          x + 1, y + 1, x + width - 2, y + 1);
2480           gdk_draw_line (window, gc2,
2481                          x + 1, y + 1, x + 1, y + height - 1);
2482           
2483           gdk_draw_line (window, gc3,
2484                          x + width - 2, y + 1, x + width - 2, y + height - 1);
2485           gdk_draw_line (window, gc4,
2486                          x + width - 1, y, x + width - 1, y + height - 1);
2487           if (gap_x > 0)
2488             {
2489               gdk_draw_line (window, gc4,
2490                              x, y + height - 1, x + gap_x - 1, y + height - 1);
2491               gdk_draw_line (window, gc3,
2492                              x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
2493               gdk_draw_line (window, gc3,
2494                              x + gap_x, y + height - 1, x + gap_x, y + height - 1);
2495             }
2496           if ((width - (gap_x + gap_width)) > 0)
2497             {
2498               gdk_draw_line (window, gc4,
2499                              x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
2500               gdk_draw_line (window, gc3,
2501                              x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
2502               gdk_draw_line (window, gc3,
2503                              x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
2504             }
2505           break;
2506         case GTK_POS_LEFT:
2507           gdk_draw_line (window, gc1,
2508                          x, y, x + width - 1, y);
2509           gdk_draw_line (window, gc2,
2510                          x, y + 1, x + width - 2, y + 1);
2511           
2512           gdk_draw_line (window, gc3,
2513                          x, y + height - 2, x + width - 2, y + height - 2);
2514           gdk_draw_line (window, gc3,
2515                          x + width - 2, y + 1, x + width - 2, y + height - 2);
2516           gdk_draw_line (window, gc4,
2517                          x, y + height - 1, x + width - 1, y + height - 1);
2518           gdk_draw_line (window, gc4,
2519                          x + width - 1, y, x + width - 1, y + height - 1);
2520           if (gap_x > 0)
2521             {
2522               gdk_draw_line (window, gc1,
2523                              x, y, x, y + gap_x - 1);
2524               gdk_draw_line (window, gc2,
2525                              x + 1, y + 1, x + 1, y + gap_x - 1);
2526               gdk_draw_line (window, gc2,
2527                              x, y + gap_x, x, y + gap_x);
2528             }
2529           if ((width - (gap_x + gap_width)) > 0)
2530             {
2531               gdk_draw_line (window, gc1,
2532                              x, y + gap_x + gap_width, x, y + height - 2);
2533               gdk_draw_line (window, gc2,
2534                              x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
2535               gdk_draw_line (window, gc2,
2536                              x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
2537             }
2538           break;
2539         case GTK_POS_RIGHT:
2540           gdk_draw_line (window, gc1,
2541                          x, y, x + width - 1, y);
2542           gdk_draw_line (window, gc1,
2543                          x, y, x, y + height - 1);
2544           gdk_draw_line (window, gc2,
2545                          x + 1, y + 1, x + width - 1, y + 1);
2546           gdk_draw_line (window, gc2,
2547                          x + 1, y + 1, x + 1, y + height - 2);
2548           
2549           gdk_draw_line (window, gc3,
2550                          x + 1, y + height - 2, x + width - 1, y + height - 2);
2551           gdk_draw_line (window, gc4,
2552                          x, y + height - 1, x + width - 1, y + height - 1);
2553           if (gap_x > 0)
2554             {
2555               gdk_draw_line (window, gc4,
2556                              x + width - 1, y, x + width - 1, y + gap_x - 1);
2557               gdk_draw_line (window, gc3,
2558                              x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
2559               gdk_draw_line (window, gc3,
2560                              x + width - 1, y + gap_x, x + width - 1, y + gap_x);
2561             }
2562           if ((width - (gap_x + gap_width)) > 0)
2563             {
2564               gdk_draw_line (window, gc4,
2565                              x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
2566               gdk_draw_line (window, gc3,
2567                              x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
2568               gdk_draw_line (window, gc3,
2569                              x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
2570             }
2571           break;
2572         }
2573     }
2574
2575   if (area)
2576     {
2577       gdk_gc_set_clip_rectangle (gc1, NULL);
2578       gdk_gc_set_clip_rectangle (gc2, NULL);
2579       gdk_gc_set_clip_rectangle (gc3, NULL);
2580       gdk_gc_set_clip_rectangle (gc4, NULL);
2581     }
2582 }
2583
2584 static void 
2585 gtk_default_draw_box_gap (GtkStyle       *style,
2586                           GdkWindow      *window,
2587                           GtkStateType    state_type,
2588                           GtkShadowType   shadow_type,
2589                           GdkRectangle   *area,
2590                           GtkWidget      *widget,
2591                           const gchar    *detail,
2592                           gint            x,
2593                           gint            y,
2594                           gint            width,
2595                           gint            height,
2596                           GtkPositionType gap_side,
2597                           gint            gap_x,
2598                           gint            gap_width)
2599 {
2600   GdkGC *gc1 = NULL;
2601   GdkGC *gc2 = NULL;
2602   GdkGC *gc3 = NULL;
2603   GdkGC *gc4 = NULL;
2604   
2605   g_return_if_fail (style != NULL);
2606   g_return_if_fail (window != NULL);
2607   
2608   gtk_style_apply_default_background (style, window,
2609                                       widget && !GTK_WIDGET_NO_WINDOW (widget),
2610                                       state_type, area, x, y, width, height);
2611   
2612   if (width == -1 && height == -1)
2613     gdk_window_get_size (window, &width, &height);
2614   else if (width == -1)
2615     gdk_window_get_size (window, &width, NULL);
2616   else if (height == -1)
2617     gdk_window_get_size (window, NULL, &height);
2618   
2619   switch (shadow_type)
2620     {
2621     case GTK_SHADOW_NONE:
2622       return;
2623     case GTK_SHADOW_IN:
2624       gc1 = style->dark_gc[state_type];
2625       gc2 = style->black_gc;
2626       gc3 = style->bg_gc[state_type];
2627       gc4 = style->light_gc[state_type];
2628       break;
2629     case GTK_SHADOW_ETCHED_IN:
2630       gc1 = style->dark_gc[state_type];
2631       gc2 = style->light_gc[state_type];
2632       gc3 = style->dark_gc[state_type];
2633       gc4 = style->light_gc[state_type];
2634       break;
2635     case GTK_SHADOW_OUT:
2636       gc1 = style->light_gc[state_type];
2637       gc2 = style->bg_gc[state_type];
2638       gc3 = style->dark_gc[state_type];
2639       gc4 = style->black_gc;
2640       break;
2641     case GTK_SHADOW_ETCHED_OUT:
2642       gc1 = style->light_gc[state_type];
2643       gc2 = style->dark_gc[state_type];
2644       gc3 = style->light_gc[state_type];
2645       gc4 = style->dark_gc[state_type];
2646       break;
2647     }
2648
2649   if (area)
2650     {
2651       gdk_gc_set_clip_rectangle (gc1, area);
2652       gdk_gc_set_clip_rectangle (gc2, area);
2653       gdk_gc_set_clip_rectangle (gc3, area);
2654       gdk_gc_set_clip_rectangle (gc4, area);
2655     }
2656   
2657   switch (shadow_type)
2658     {
2659     case GTK_SHADOW_NONE:
2660     case GTK_SHADOW_IN:
2661     case GTK_SHADOW_OUT:
2662     case GTK_SHADOW_ETCHED_IN:
2663     case GTK_SHADOW_ETCHED_OUT:
2664       switch (gap_side)
2665         {
2666         case GTK_POS_TOP:
2667           gdk_draw_line (window, gc1,
2668                          x, y, x, y + height - 1);
2669           gdk_draw_line (window, gc2,
2670                          x + 1, y, x + 1, y + height - 2);
2671           
2672           gdk_draw_line (window, gc3,
2673                          x + 1, y + height - 2, x + width - 2, y + height - 2);
2674           gdk_draw_line (window, gc3,
2675                          x + width - 2, y, x + width - 2, y + height - 2);
2676           gdk_draw_line (window, gc4,
2677                          x, y + height - 1, x + width - 1, y + height - 1);
2678           gdk_draw_line (window, gc4,
2679                          x + width - 1, y, x + width - 1, y + height - 1);
2680           if (gap_x > 0)
2681             {
2682               gdk_draw_line (window, gc1,
2683                              x, y, x + gap_x - 1, y);
2684               gdk_draw_line (window, gc2,
2685                              x + 1, y + 1, x + gap_x - 1, y + 1);
2686               gdk_draw_line (window, gc2,
2687                              x + gap_x, y, x + gap_x, y);
2688             }
2689           if ((width - (gap_x + gap_width)) > 0)
2690             {
2691               gdk_draw_line (window, gc1,
2692                              x + gap_x + gap_width, y, x + width - 2, y);
2693               gdk_draw_line (window, gc2,
2694                              x + gap_x + gap_width, y + 1, x + width - 2, y + 1);
2695               gdk_draw_line (window, gc2,
2696                              x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
2697             }
2698           break;
2699         case  GTK_POS_BOTTOM:
2700           gdk_draw_line (window, gc1,
2701                          x, y, x + width - 1, y);
2702           gdk_draw_line (window, gc1,
2703                          x, y, x, y + height - 1);
2704           gdk_draw_line (window, gc2,
2705                          x + 1, y + 1, x + width - 2, y + 1);
2706           gdk_draw_line (window, gc2,
2707                          x + 1, y + 1, x + 1, y + height - 1);
2708           
2709           gdk_draw_line (window, gc3,
2710                          x + width - 2, y + 1, x + width - 2, y + height - 1);
2711           gdk_draw_line (window, gc4,
2712                          x + width - 1, y, x + width - 1, y + height - 1);
2713           if (gap_x > 0)
2714             {
2715               gdk_draw_line (window, gc4,
2716                              x, y + height - 1, x + gap_x - 1, y + height - 1);
2717               gdk_draw_line (window, gc3,
2718                              x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
2719               gdk_draw_line (window, gc3,
2720                              x + gap_x, y + height - 1, x + gap_x, y + height - 1);
2721             }
2722           if ((width - (gap_x + gap_width)) > 0)
2723             {
2724               gdk_draw_line (window, gc4,
2725                              x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
2726               gdk_draw_line (window, gc3,
2727                              x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
2728               gdk_draw_line (window, gc3,
2729                              x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
2730             }
2731           break;
2732         case GTK_POS_LEFT:
2733           gdk_draw_line (window, gc1,
2734                          x, y, x + width - 1, y);
2735           gdk_draw_line (window, gc2,
2736                          x, y + 1, x + width - 2, y + 1);
2737           
2738           gdk_draw_line (window, gc3,
2739                          x, y + height - 2, x + width - 2, y + height - 2);
2740           gdk_draw_line (window, gc3,
2741                          x + width - 2, y + 1, x + width - 2, y + height - 2);
2742           gdk_draw_line (window, gc4,
2743                          x, y + height - 1, x + width - 1, y + height - 1);
2744           gdk_draw_line (window, gc4,
2745                          x + width - 1, y, x + width - 1, y + height - 1);
2746           if (gap_x > 0)
2747             {
2748               gdk_draw_line (window, gc1,
2749                              x, y, x, y + gap_x - 1);
2750               gdk_draw_line (window, gc2,
2751                              x + 1, y + 1, x + 1, y + gap_x - 1);
2752               gdk_draw_line (window, gc2,
2753                              x, y + gap_x, x, y + gap_x);
2754             }
2755           if ((width - (gap_x + gap_width)) > 0)
2756             {
2757               gdk_draw_line (window, gc1,
2758                              x, y + gap_x + gap_width, x, y + height - 2);
2759               gdk_draw_line (window, gc2,
2760                              x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
2761               gdk_draw_line (window, gc2,
2762                              x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
2763             }
2764           break;
2765         case GTK_POS_RIGHT:
2766           gdk_draw_line (window, gc1,
2767                          x, y, x + width - 1, y);
2768           gdk_draw_line (window, gc1,
2769                          x, y, x, y + height - 1);
2770           gdk_draw_line (window, gc2,
2771                          x + 1, y + 1, x + width - 1, y + 1);
2772           gdk_draw_line (window, gc2,
2773                          x + 1, y + 1, x + 1, y + height - 2);
2774           
2775           gdk_draw_line (window, gc3,
2776                          x + 1, y + height - 2, x + width - 1, y + height - 2);
2777           gdk_draw_line (window, gc4,
2778                          x, y + height - 1, x + width - 1, y + height - 1);
2779           if (gap_x > 0)
2780             {
2781               gdk_draw_line (window, gc4,
2782                              x + width - 1, y, x + width - 1, y + gap_x - 1);
2783               gdk_draw_line (window, gc3,
2784                              x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
2785               gdk_draw_line (window, gc3,
2786                              x + width - 1, y + gap_x, x + width - 1, y + gap_x);
2787             }
2788           if ((width - (gap_x + gap_width)) > 0)
2789             {
2790               gdk_draw_line (window, gc4,
2791                              x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
2792               gdk_draw_line (window, gc3,
2793                              x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
2794               gdk_draw_line (window, gc3,
2795                              x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
2796             }
2797           break;
2798         }
2799     }
2800
2801   if (area)
2802     {
2803       gdk_gc_set_clip_rectangle (gc1, NULL);
2804       gdk_gc_set_clip_rectangle (gc2, NULL);
2805       gdk_gc_set_clip_rectangle (gc3, NULL);
2806       gdk_gc_set_clip_rectangle (gc4, NULL);
2807     }
2808 }
2809
2810 static void 
2811 gtk_default_draw_extension (GtkStyle       *style,
2812                             GdkWindow      *window,
2813                             GtkStateType    state_type,
2814                             GtkShadowType   shadow_type,
2815                             GdkRectangle   *area,
2816                             GtkWidget      *widget,
2817                             const gchar    *detail,
2818                             gint            x,
2819                             gint            y,
2820                             gint            width,
2821                             gint            height,
2822                             GtkPositionType gap_side)
2823 {
2824   GdkGC *gc1 = NULL;
2825   GdkGC *gc2 = NULL;
2826   GdkGC *gc3 = NULL;
2827   GdkGC *gc4 = NULL;
2828   
2829   g_return_if_fail (style != NULL);
2830   g_return_if_fail (window != NULL);
2831   
2832   gtk_style_apply_default_background (style, window,
2833                                       widget && !GTK_WIDGET_NO_WINDOW (widget),
2834                                       GTK_STATE_NORMAL, area, x, y, width, height);
2835   
2836   if (width == -1 && height == -1)
2837     gdk_window_get_size (window, &width, &height);
2838   else if (width == -1)
2839     gdk_window_get_size (window, &width, NULL);
2840   else if (height == -1)
2841     gdk_window_get_size (window, NULL, &height);
2842   
2843   switch (shadow_type)
2844     {
2845     case GTK_SHADOW_NONE:
2846       return;
2847     case GTK_SHADOW_IN:
2848       gc1 = style->dark_gc[state_type];
2849       gc2 = style->black_gc;
2850       gc3 = style->bg_gc[state_type];
2851       gc4 = style->light_gc[state_type];
2852       break;
2853     case GTK_SHADOW_ETCHED_IN:
2854       gc1 = style->dark_gc[state_type];
2855       gc2 = style->light_gc[state_type];
2856       gc3 = style->dark_gc[state_type];
2857       gc4 = style->light_gc[state_type];
2858       break;
2859     case GTK_SHADOW_OUT:
2860       gc1 = style->light_gc[state_type];
2861       gc2 = style->bg_gc[state_type];
2862       gc3 = style->dark_gc[state_type];
2863       gc4 = style->black_gc;
2864       break;
2865     case GTK_SHADOW_ETCHED_OUT:
2866       gc1 = style->light_gc[state_type];
2867       gc2 = style->dark_gc[state_type];
2868       gc3 = style->light_gc[state_type];
2869       gc4 = style->dark_gc[state_type];
2870       break;
2871     }
2872
2873   if (area)
2874     {
2875       gdk_gc_set_clip_rectangle (gc1, area);
2876       gdk_gc_set_clip_rectangle (gc2, area);
2877       gdk_gc_set_clip_rectangle (gc3, area);
2878       gdk_gc_set_clip_rectangle (gc4, area);
2879     }
2880
2881   switch (shadow_type)
2882     {
2883     case GTK_SHADOW_NONE:
2884     case GTK_SHADOW_IN:
2885     case GTK_SHADOW_OUT:
2886     case GTK_SHADOW_ETCHED_IN:
2887     case GTK_SHADOW_ETCHED_OUT:
2888       switch (gap_side)
2889         {
2890         case GTK_POS_TOP:
2891           gtk_style_apply_default_background (style, window,
2892                                               widget && !GTK_WIDGET_NO_WINDOW (widget),
2893                                               state_type, area,
2894                                               x + style->klass->xthickness, 
2895                                               y, 
2896                                               width - (2 * style->klass->xthickness), 
2897                                               height - (style->klass->ythickness));
2898           gdk_draw_line (window, gc1,
2899                          x, y, x, y + height - 2);
2900           gdk_draw_line (window, gc2,
2901                          x + 1, y, x + 1, y + height - 2);
2902           
2903           gdk_draw_line (window, gc3,
2904                          x + 2, y + height - 2, x + width - 2, y + height - 2);
2905           gdk_draw_line (window, gc3,
2906                          x + width - 2, y, x + width - 2, y + height - 2);
2907           gdk_draw_line (window, gc4,
2908                          x + 1, y + height - 1, x + width - 2, y + height - 1);
2909           gdk_draw_line (window, gc4,
2910                          x + width - 1, y, x + width - 1, y + height - 2);
2911           break;
2912         case GTK_POS_BOTTOM:
2913           gtk_style_apply_default_background (style, window,
2914                                               widget && !GTK_WIDGET_NO_WINDOW (widget),
2915                                               state_type, area,
2916                                               x + style->klass->xthickness, 
2917                                               y + style->klass->ythickness, 
2918                                               width - (2 * style->klass->xthickness), 
2919                                               height - (style->klass->ythickness));
2920           gdk_draw_line (window, gc1,
2921                          x + 1, y, x + width - 2, y);
2922           gdk_draw_line (window, gc1,
2923                          x, y + 1, x, y + height - 1);
2924           gdk_draw_line (window, gc2,
2925                          x + 1, y + 1, x + width - 2, y + 1);
2926           gdk_draw_line (window, gc2,
2927                          x + 1, y + 1, x + 1, y + height - 1);
2928           
2929           gdk_draw_line (window, gc3,
2930                          x + width - 2, y + 2, x + width - 2, y + height - 1);
2931           gdk_draw_line (window, gc4,
2932                          x + width - 1, y + 1, x + width - 1, y + height - 1);
2933           break;
2934         case GTK_POS_LEFT:
2935           gtk_style_apply_default_background (style, window,
2936                                               widget && !GTK_WIDGET_NO_WINDOW (widget),
2937                                               state_type, area,
2938                                               x, 
2939                                               y + style->klass->ythickness, 
2940                                               width - (style->klass->xthickness), 
2941                                               height - (2 * style->klass->ythickness));
2942           gdk_draw_line (window, gc1,
2943                          x, y, x + width - 2, y);
2944           gdk_draw_line (window, gc2,
2945                          x + 1, y + 1, x + width - 2, y + 1);
2946           
2947           gdk_draw_line (window, gc3,
2948                          x, y + height - 2, x + width - 2, y + height - 2);
2949           gdk_draw_line (window, gc3,
2950                          x + width - 2, y + 2, x + width - 2, y + height - 2);
2951           gdk_draw_line (window, gc4,
2952                          x, y + height - 1, x + width - 2, y + height - 1);
2953           gdk_draw_line (window, gc4,
2954                          x + width - 1, y + 1, x + width - 1, y + height - 2);
2955           break;
2956         case GTK_POS_RIGHT:
2957           gtk_style_apply_default_background (style, window,
2958                                               widget && !GTK_WIDGET_NO_WINDOW (widget),
2959                                               state_type, area,
2960                                               x + style->klass->xthickness, 
2961                                               y + style->klass->ythickness, 
2962                                               width - (style->klass->xthickness), 
2963                                               height - (2 * style->klass->ythickness));
2964           gdk_draw_line (window, gc1,
2965                          x + 1, y, x + width - 1, y);
2966           gdk_draw_line (window, gc1,
2967                          x, y + 1, x, y + height - 2);
2968           gdk_draw_line (window, gc2,
2969                          x + 1, y + 1, x + width - 1, y + 1);
2970           gdk_draw_line (window, gc2,
2971                          x + 1, y + 1, x + 1, y + height - 2);
2972           
2973           gdk_draw_line (window, gc3,
2974                          x + 2, y + height - 2, x + width - 1, y + height - 2);
2975           gdk_draw_line (window, gc4,
2976                          x + 1, y + height - 1, x + width - 1, y + height - 1);
2977           break;
2978         }
2979     }
2980
2981   if (area)
2982     {
2983       gdk_gc_set_clip_rectangle (gc1, NULL);
2984       gdk_gc_set_clip_rectangle (gc2, NULL);
2985       gdk_gc_set_clip_rectangle (gc3, NULL);
2986       gdk_gc_set_clip_rectangle (gc4, NULL);
2987     }
2988 }
2989
2990 static void 
2991 gtk_default_draw_focus (GtkStyle      *style,
2992                         GdkWindow     *window,
2993                         GdkRectangle  *area,
2994                         GtkWidget     *widget,
2995                         const gchar   *detail,
2996                         gint           x,
2997                         gint           y,
2998                         gint           width,
2999                         gint           height)
3000 {
3001   g_return_if_fail (style != NULL);
3002   g_return_if_fail (window != NULL);
3003   
3004   if (width == -1 && height == -1)
3005     {
3006       gdk_window_get_size (window, &width, &height);
3007       width -= 1;
3008       height -= 1;
3009     }
3010   else if (width == -1)
3011     {
3012       gdk_window_get_size (window, &width, NULL);
3013       width -= 1;
3014     }
3015   else if (height == -1)
3016     {
3017       gdk_window_get_size (window, NULL, &height);
3018       height -= 1;
3019     }
3020
3021   if (area)
3022     gdk_gc_set_clip_rectangle (style->black_gc, area);
3023
3024   if (detail && !strcmp (detail, "add-mode"))
3025     {
3026       gdk_gc_set_line_attributes (style->black_gc, 1, GDK_LINE_ON_OFF_DASH, 0, 0);
3027       gdk_gc_set_dashes (style->black_gc, 0, "\4\4", 2);
3028       
3029       gdk_draw_rectangle (window,
3030                           style->black_gc, FALSE,
3031                           x, y, width, height);
3032       
3033       gdk_gc_set_line_attributes (style->black_gc, 1, GDK_LINE_SOLID, 0, 0);
3034     }
3035   else
3036     {
3037       gdk_draw_rectangle (window,
3038                           style->black_gc, FALSE,
3039                           x, y, width, height);
3040     }
3041
3042   if (area)
3043     gdk_gc_set_clip_rectangle (style->black_gc, NULL);
3044 }
3045
3046 static void 
3047 gtk_default_draw_slider (GtkStyle      *style,
3048                          GdkWindow     *window,
3049                          GtkStateType   state_type,
3050                          GtkShadowType  shadow_type,
3051                          GdkRectangle  *area,
3052                          GtkWidget     *widget,
3053                          const gchar   *detail,
3054                          gint           x,
3055                          gint           y,
3056                          gint           width,
3057                          gint           height,
3058                          GtkOrientation orientation)
3059 {
3060   g_return_if_fail (style != NULL);
3061   g_return_if_fail (window != NULL);
3062   
3063   if (width == -1 && height == -1)
3064     gdk_window_get_size (window, &width, &height);
3065   else if (width == -1)
3066     gdk_window_get_size (window, &width, NULL);
3067   else if (height == -1)
3068     gdk_window_get_size (window, NULL, &height);
3069   
3070   gtk_paint_box (style, window, state_type, shadow_type,
3071                  area, widget, detail, x, y, width, height);
3072
3073   if (orientation == GTK_ORIENTATION_HORIZONTAL)
3074     gtk_paint_vline (style, window, state_type, area, widget, detail, 
3075                      style->klass->ythickness, 
3076                      height - style->klass->ythickness - 1, width / 2);
3077   else
3078     gtk_paint_hline (style, window, state_type, area, widget, detail, 
3079                      style->klass->xthickness, 
3080                      width - style->klass->xthickness - 1, height / 2);
3081 }
3082
3083 static void
3084 draw_dot (GdkWindow    *window,
3085           GdkGC        *light_gc,
3086           GdkGC        *dark_gc,
3087           gint          x,
3088           gint          y,
3089           gushort       size)
3090 {
3091   
3092   size = CLAMP (size, 2, 3);
3093
3094   if (size == 2)
3095     {
3096       gdk_draw_point (window, light_gc, x, y);
3097       gdk_draw_point (window, light_gc, x+1, y+1);
3098     }
3099   else if (size == 3);
3100     {
3101       gdk_draw_point (window, light_gc, x, y);
3102       gdk_draw_point (window, light_gc, x+1, y);
3103       gdk_draw_point (window, light_gc, x, y+1);
3104       gdk_draw_point (window, dark_gc, x+1, y+2);
3105       gdk_draw_point (window, dark_gc, x+2, y+1);
3106       gdk_draw_point (window, dark_gc, x+2, y+2);
3107     }
3108 }
3109
3110 static void 
3111 gtk_default_draw_handle (GtkStyle      *style,
3112                          GdkWindow     *window,
3113                          GtkStateType   state_type,
3114                          GtkShadowType  shadow_type,
3115                          GdkRectangle  *area,
3116                          GtkWidget     *widget,
3117                          const gchar   *detail,
3118                          gint           x,
3119                          gint           y,
3120                          gint           width,
3121                          gint           height,
3122                          GtkOrientation orientation)
3123 {
3124   gint xx, yy;
3125   gint xthick, ythick;
3126   GdkGC *light_gc, *dark_gc;
3127   GdkRectangle rect;
3128   GdkRectangle dest;
3129   gint intersect;
3130   
3131   g_return_if_fail (style != NULL);
3132   g_return_if_fail (window != NULL);
3133   
3134   if (width == -1 && height == -1)
3135     gdk_window_get_size (window, &width, &height);
3136   else if (width == -1)
3137     gdk_window_get_size (window, &width, NULL);
3138   else if (height == -1)
3139     gdk_window_get_size (window, NULL, &height);
3140   
3141   gtk_paint_box (style, window, state_type, shadow_type, area, widget, 
3142                  detail, x, y, width, height);
3143   
3144
3145   if (!strcmp (detail, "paned"))
3146     {
3147       /* we want to ignore the shadow border in paned widgets */
3148       xthick = 0;
3149       ythick = 0;
3150
3151       light_gc = style->light_gc[state_type];
3152       dark_gc = style->black_gc;
3153     }
3154   else
3155     {
3156       xthick = style->klass->xthickness;
3157       ythick = style->klass->ythickness;
3158
3159       light_gc = style->light_gc[state_type];
3160       dark_gc = style->dark_gc[state_type];
3161     }
3162   
3163   rect.x = x + xthick;
3164   rect.y = y + ythick;
3165   rect.width = width - (xthick * 2);
3166   rect.height = height - (ythick * 2);
3167
3168   if (area)
3169       intersect = gdk_rectangle_intersect (area, &rect, &dest);
3170   else
3171     {
3172       intersect = TRUE;
3173       dest = rect;
3174     }
3175
3176   if (!intersect)
3177     return;
3178
3179   gdk_gc_set_clip_rectangle (light_gc, &dest);
3180   gdk_gc_set_clip_rectangle (dark_gc, &dest);
3181
3182   if (!strcmp (detail, "paned"))
3183     {
3184       gint window_width;
3185       gint window_height;
3186
3187       gdk_window_get_size (window, &window_width, &window_height);
3188
3189       if (orientation == GTK_ORIENTATION_HORIZONTAL)
3190         for (xx = window_width/2 - 15; xx <= window_width/2 + 15; xx += 5)
3191           draw_dot (window, light_gc, dark_gc, xx, window_height/2 - 1, 3);
3192       else
3193         for (yy = window_height/2 - 15; yy <= window_height/2 + 15; yy += 5)
3194           draw_dot (window, light_gc, dark_gc, window_width/2 - 1, yy, 3);
3195     }
3196   else
3197     {
3198       for (yy = y + ythick; yy < (y + height - ythick); yy += 3)
3199         for (xx = x + xthick; xx < (x + width - xthick); xx += 6)
3200           {
3201             draw_dot (window, light_gc, dark_gc, xx, yy, 2);
3202             draw_dot (window, light_gc, dark_gc, xx + 3, yy + 1, 2);
3203           }
3204     }
3205
3206   gdk_gc_set_clip_rectangle (light_gc, NULL);
3207   gdk_gc_set_clip_rectangle (dark_gc, NULL);
3208 }
3209
3210 static void
3211 gtk_style_shade (GdkColor *a,
3212                  GdkColor *b,
3213                  gdouble   k)
3214 {
3215   gdouble red;
3216   gdouble green;
3217   gdouble blue;
3218   
3219   red = (gdouble) a->red / 65535.0;
3220   green = (gdouble) a->green / 65535.0;
3221   blue = (gdouble) a->blue / 65535.0;
3222   
3223   rgb_to_hls (&red, &green, &blue);
3224   
3225   green *= k;
3226   if (green > 1.0)
3227     green = 1.0;
3228   else if (green < 0.0)
3229     green = 0.0;
3230   
3231   blue *= k;
3232   if (blue > 1.0)
3233     blue = 1.0;
3234   else if (blue < 0.0)
3235     blue = 0.0;
3236   
3237   hls_to_rgb (&red, &green, &blue);
3238   
3239   b->red = red * 65535.0;
3240   b->green = green * 65535.0;
3241   b->blue = blue * 65535.0;
3242 }
3243
3244 static void
3245 rgb_to_hls (gdouble *r,
3246             gdouble *g,
3247             gdouble *b)
3248 {
3249   gdouble min;
3250   gdouble max;
3251   gdouble red;
3252   gdouble green;
3253   gdouble blue;
3254   gdouble h, l, s;
3255   gdouble delta;
3256   
3257   red = *r;
3258   green = *g;
3259   blue = *b;
3260   
3261   if (red > green)
3262     {
3263       if (red > blue)
3264         max = red;
3265       else
3266         max = blue;
3267       
3268       if (green < blue)
3269         min = green;
3270       else
3271         min = blue;
3272     }
3273   else
3274     {
3275       if (green > blue)
3276         max = green;
3277       else
3278         max = blue;
3279       
3280       if (red < blue)
3281         min = red;
3282       else
3283         min = blue;
3284     }
3285   
3286   l = (max + min) / 2;
3287   s = 0;
3288   h = 0;
3289   
3290   if (max != min)
3291     {
3292       if (l <= 0.5)
3293         s = (max - min) / (max + min);
3294       else
3295         s = (max - min) / (2 - max - min);
3296       
3297       delta = max -min;
3298       if (red == max)
3299         h = (green - blue) / delta;
3300       else if (green == max)
3301         h = 2 + (blue - red) / delta;
3302       else if (blue == max)
3303         h = 4 + (red - green) / delta;
3304       
3305       h *= 60;
3306       if (h < 0.0)
3307         h += 360;
3308     }
3309   
3310   *r = h;
3311   *g = l;
3312   *b = s;
3313 }
3314
3315 static void
3316 hls_to_rgb (gdouble *h,
3317             gdouble *l,
3318             gdouble *s)
3319 {
3320   gdouble hue;
3321   gdouble lightness;
3322   gdouble saturation;
3323   gdouble m1, m2;
3324   gdouble r, g, b;
3325   
3326   lightness = *l;
3327   saturation = *s;
3328   
3329   if (lightness <= 0.5)
3330     m2 = lightness * (1 + saturation);
3331   else
3332     m2 = lightness + saturation - lightness * saturation;
3333   m1 = 2 * lightness - m2;
3334   
3335   if (saturation == 0)
3336     {
3337       *h = lightness;
3338       *l = lightness;
3339       *s = lightness;
3340     }
3341   else
3342     {
3343       hue = *h + 120;
3344       while (hue > 360)
3345         hue -= 360;
3346       while (hue < 0)
3347         hue += 360;
3348       
3349       if (hue < 60)
3350         r = m1 + (m2 - m1) * hue / 60;
3351       else if (hue < 180)
3352         r = m2;
3353       else if (hue < 240)
3354         r = m1 + (m2 - m1) * (240 - hue) / 60;
3355       else
3356         r = m1;
3357       
3358       hue = *h;
3359       while (hue > 360)
3360         hue -= 360;
3361       while (hue < 0)
3362         hue += 360;
3363       
3364       if (hue < 60)
3365         g = m1 + (m2 - m1) * hue / 60;
3366       else if (hue < 180)
3367         g = m2;
3368       else if (hue < 240)
3369         g = m1 + (m2 - m1) * (240 - hue) / 60;
3370       else
3371         g = m1;
3372       
3373       hue = *h - 120;
3374       while (hue > 360)
3375         hue -= 360;
3376       while (hue < 0)
3377         hue += 360;
3378       
3379       if (hue < 60)
3380         b = m1 + (m2 - m1) * hue / 60;
3381       else if (hue < 180)
3382         b = m2;
3383       else if (hue < 240)
3384         b = m1 + (m2 - m1) * (240 - hue) / 60;
3385       else
3386         b = m1;
3387       
3388       *h = r;
3389       *l = g;
3390       *s = b;
3391     }
3392 }
3393
3394 void 
3395 gtk_paint_hline (GtkStyle      *style,
3396                  GdkWindow     *window,
3397                  GtkStateType   state_type,
3398                  GdkRectangle  *area,
3399                  GtkWidget     *widget,
3400                  const gchar   *detail,
3401                  gint          x1,
3402                  gint          x2,
3403                  gint          y)
3404 {
3405   g_return_if_fail (style != NULL);
3406   g_return_if_fail (style->klass != NULL);
3407   g_return_if_fail (style->klass->draw_hline != NULL);
3408   
3409   style->klass->draw_hline (style, window, state_type, area, widget, detail, x1, x2, y);
3410 }
3411
3412 void
3413 gtk_paint_vline (GtkStyle      *style,
3414                  GdkWindow     *window,
3415                  GtkStateType   state_type,
3416                  GdkRectangle  *area,
3417                  GtkWidget     *widget,
3418                  const gchar   *detail,
3419                  gint          y1,
3420                  gint          y2,
3421                  gint          x)
3422 {
3423   g_return_if_fail (style != NULL);
3424   g_return_if_fail (style->klass != NULL);
3425   g_return_if_fail (style->klass->draw_vline != NULL);
3426   
3427   style->klass->draw_vline (style, window, state_type, area, widget, detail, y1, y2, x);
3428 }
3429
3430 void
3431 gtk_paint_shadow (GtkStyle     *style,
3432                   GdkWindow    *window,
3433                   GtkStateType  state_type,
3434                   GtkShadowType shadow_type,
3435                   GdkRectangle *area,
3436                   GtkWidget    *widget,
3437                   const gchar  *detail,
3438                   gint          x,
3439                   gint          y,
3440                   gint          width,
3441                   gint          height)
3442 {
3443   g_return_if_fail (style != NULL);
3444   g_return_if_fail (style->klass != NULL);
3445   g_return_if_fail (style->klass->draw_shadow != NULL);
3446   
3447   style->klass->draw_shadow (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
3448 }
3449
3450 void
3451 gtk_paint_polygon (GtkStyle      *style,
3452                    GdkWindow     *window,
3453                    GtkStateType   state_type,
3454                    GtkShadowType  shadow_type,
3455                    GdkRectangle  *area,
3456                    GtkWidget     *widget,
3457                    const gchar   *detail,
3458                    GdkPoint      *points,
3459                    gint           npoints,
3460                    gboolean       fill)
3461 {
3462   g_return_if_fail (style != NULL);
3463   g_return_if_fail (style->klass != NULL);
3464   g_return_if_fail (style->klass->draw_shadow != NULL);
3465   
3466   style->klass->draw_polygon (style, window, state_type, shadow_type, area, widget, detail, points, npoints, fill);
3467 }
3468
3469 void
3470 gtk_paint_arrow (GtkStyle      *style,
3471                  GdkWindow     *window,
3472                  GtkStateType   state_type,
3473                  GtkShadowType  shadow_type,
3474                  GdkRectangle  *area,
3475                  GtkWidget     *widget,
3476                  const gchar   *detail,
3477                  GtkArrowType   arrow_type,
3478                  gboolean       fill,
3479                  gint           x,
3480                  gint           y,
3481                  gint           width,
3482                  gint           height)
3483 {
3484   g_return_if_fail (style != NULL);
3485   g_return_if_fail (style->klass != NULL);
3486   g_return_if_fail (style->klass->draw_arrow != NULL);
3487   
3488   style->klass->draw_arrow (style, window, state_type, shadow_type, area, widget, detail, arrow_type, fill, x, y, width, height);
3489 }
3490
3491 void
3492 gtk_paint_diamond (GtkStyle      *style,
3493                    GdkWindow     *window,
3494                    GtkStateType   state_type,
3495                    GtkShadowType  shadow_type,
3496                    GdkRectangle  *area,
3497                    GtkWidget     *widget,
3498                    const gchar   *detail,
3499                    gint        x,
3500                    gint        y,
3501                    gint        width,
3502                    gint        height)
3503 {
3504   g_return_if_fail (style != NULL);
3505   g_return_if_fail (style->klass != NULL);
3506   g_return_if_fail (style->klass->draw_diamond != NULL);
3507   
3508   style->klass->draw_diamond (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
3509 }
3510
3511 void
3512 gtk_paint_oval (GtkStyle      *style,
3513                 GdkWindow     *window,
3514                 GtkStateType   state_type,
3515                 GtkShadowType  shadow_type,
3516                 GdkRectangle  *area,
3517                 GtkWidget     *widget,
3518                 const gchar   *detail,
3519                 gint           x,
3520                 gint           y,
3521                 gint           width,
3522                 gint           height)
3523 {
3524   g_return_if_fail (style != NULL);
3525   g_return_if_fail (style->klass != NULL);
3526   g_return_if_fail (style->klass->draw_oval != NULL);
3527   
3528   style->klass->draw_oval (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
3529 }
3530
3531 void
3532 gtk_paint_string (GtkStyle      *style,
3533                   GdkWindow     *window,
3534                   GtkStateType   state_type,
3535                   GdkRectangle  *area,
3536                   GtkWidget     *widget,
3537                   const gchar   *detail,
3538                   gint           x,
3539                   gint           y,
3540                   const gchar   *string)
3541 {
3542   g_return_if_fail (style != NULL);
3543   g_return_if_fail (style->klass != NULL);
3544   g_return_if_fail (style->klass->draw_string != NULL);
3545   
3546   style->klass->draw_string (style, window, state_type, area, widget, detail, x, y, string);
3547 }
3548
3549 void
3550 gtk_paint_box (GtkStyle      *style,
3551                GdkWindow     *window,
3552                GtkStateType   state_type,
3553                GtkShadowType  shadow_type,
3554                GdkRectangle  *area,
3555                GtkWidget     *widget,
3556                const gchar   *detail,
3557                gint           x,
3558                gint           y,
3559                gint           width,
3560                gint           height)
3561 {
3562   g_return_if_fail (style != NULL);
3563   g_return_if_fail (style->klass != NULL);
3564   g_return_if_fail (style->klass->draw_box != NULL);
3565   
3566   style->klass->draw_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
3567 }
3568
3569 void
3570 gtk_paint_flat_box (GtkStyle      *style,
3571                     GdkWindow     *window,
3572                     GtkStateType   state_type,
3573                     GtkShadowType  shadow_type,
3574                     GdkRectangle  *area,
3575                     GtkWidget     *widget,
3576                     const gchar   *detail,
3577                     gint           x,
3578                     gint           y,
3579                     gint           width,
3580                     gint           height)
3581 {
3582   g_return_if_fail (style != NULL);
3583   g_return_if_fail (style->klass != NULL);
3584   g_return_if_fail (style->klass->draw_flat_box != NULL);
3585   
3586   style->klass->draw_flat_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
3587 }
3588
3589 void
3590 gtk_paint_check (GtkStyle      *style,
3591                  GdkWindow     *window,
3592                  GtkStateType   state_type,
3593                  GtkShadowType  shadow_type,
3594                  GdkRectangle  *area,
3595                  GtkWidget     *widget,
3596                  const gchar   *detail,
3597                  gint           x,
3598                  gint           y,
3599                  gint           width,
3600                  gint           height)
3601 {
3602   g_return_if_fail (style != NULL);
3603   g_return_if_fail (style->klass != NULL);
3604   g_return_if_fail (style->klass->draw_check != NULL);
3605   
3606   style->klass->draw_check (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
3607 }
3608
3609 void
3610 gtk_paint_option (GtkStyle      *style,
3611                   GdkWindow     *window,
3612                   GtkStateType   state_type,
3613                   GtkShadowType  shadow_type,
3614                   GdkRectangle  *area,
3615                   GtkWidget     *widget,
3616                   const gchar   *detail,
3617                   gint           x,
3618                   gint           y,
3619                   gint           width,
3620                   gint           height)
3621 {
3622   g_return_if_fail (style != NULL);
3623   g_return_if_fail (style->klass != NULL);
3624   g_return_if_fail (style->klass->draw_option != NULL);
3625   
3626   style->klass->draw_option (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
3627 }
3628
3629 void
3630 gtk_paint_cross (GtkStyle      *style,
3631                  GdkWindow     *window,
3632                  GtkStateType   state_type,
3633                  GtkShadowType  shadow_type,
3634                  GdkRectangle  *area,
3635                  GtkWidget     *widget,
3636                  const gchar   *detail,
3637                  gint           x,
3638                  gint           y,
3639                  gint           width,
3640                  gint           height)
3641 {
3642   g_return_if_fail (style != NULL);
3643   g_return_if_fail (style->klass != NULL);
3644   g_return_if_fail (style->klass->draw_cross != NULL);
3645   
3646   style->klass->draw_cross (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
3647 }
3648
3649 void
3650 gtk_paint_ramp (GtkStyle      *style,
3651                 GdkWindow     *window,
3652                 GtkStateType   state_type,
3653                 GtkShadowType  shadow_type,
3654                 GdkRectangle  *area,
3655                 GtkWidget     *widget,
3656                 const gchar   *detail,
3657                 GtkArrowType   arrow_type,
3658                 gint           x,
3659                 gint           y,
3660                 gint           width,
3661                 gint           height)
3662 {
3663   g_return_if_fail (style != NULL);
3664   g_return_if_fail (style->klass != NULL);
3665   g_return_if_fail (style->klass->draw_ramp != NULL);
3666   
3667   style->klass->draw_ramp (style, window, state_type, shadow_type, area, widget, detail, arrow_type, x, y, width, height);
3668 }
3669
3670 void
3671 gtk_paint_tab (GtkStyle      *style,
3672                GdkWindow     *window,
3673                GtkStateType   state_type,
3674                GtkShadowType  shadow_type,
3675                GdkRectangle  *area,
3676                GtkWidget     *widget,
3677                const gchar   *detail,
3678                gint           x,
3679                gint           y,
3680                gint           width,
3681                gint           height)
3682 {
3683   g_return_if_fail (style != NULL);
3684   g_return_if_fail (style->klass != NULL);
3685   g_return_if_fail (style->klass->draw_tab != NULL);
3686   
3687   style->klass->draw_tab (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
3688 }
3689
3690 void
3691 gtk_paint_shadow_gap (GtkStyle       *style,
3692                       GdkWindow      *window,
3693                       GtkStateType    state_type,
3694                       GtkShadowType   shadow_type,
3695                       GdkRectangle   *area,
3696                       GtkWidget      *widget,
3697                       gchar          *detail,
3698                       gint            x,
3699                       gint            y,
3700                       gint            width,
3701                       gint            height,
3702                       GtkPositionType gap_side,
3703                       gint            gap_x,
3704                       gint            gap_width)
3705 {
3706   g_return_if_fail (style != NULL);
3707   g_return_if_fail (style->klass != NULL);
3708   g_return_if_fail (style->klass->draw_shadow_gap != NULL);
3709   
3710   style->klass->draw_shadow_gap (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, gap_side, gap_x, gap_width);
3711 }
3712
3713
3714 void
3715 gtk_paint_box_gap (GtkStyle       *style,
3716                    GdkWindow      *window,
3717                    GtkStateType    state_type,
3718                    GtkShadowType   shadow_type,
3719                    GdkRectangle   *area,
3720                    GtkWidget      *widget,
3721                    gchar          *detail,
3722                    gint            x,
3723                    gint            y,
3724                    gint            width,
3725                    gint            height,
3726                    GtkPositionType gap_side,
3727                    gint            gap_x,
3728                    gint            gap_width)
3729 {
3730   g_return_if_fail (style != NULL);
3731   g_return_if_fail (style->klass != NULL);
3732   g_return_if_fail (style->klass->draw_box_gap != NULL);
3733   
3734   style->klass->draw_box_gap (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, gap_side, gap_x, gap_width);
3735 }
3736
3737 void
3738 gtk_paint_extension (GtkStyle       *style,
3739                      GdkWindow      *window,
3740                      GtkStateType    state_type,
3741                      GtkShadowType   shadow_type,
3742                      GdkRectangle   *area,
3743                      GtkWidget      *widget,
3744                      gchar          *detail,
3745                      gint            x,
3746                      gint            y,
3747                      gint            width,
3748                      gint            height,
3749                      GtkPositionType gap_side)
3750 {
3751   g_return_if_fail (style != NULL);
3752   g_return_if_fail (style->klass != NULL);
3753   g_return_if_fail (style->klass->draw_extension != NULL);
3754   
3755   style->klass->draw_extension (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, gap_side);
3756 }
3757
3758 void
3759 gtk_paint_focus (GtkStyle      *style,
3760                  GdkWindow     *window,
3761                  GdkRectangle  *area,
3762                  GtkWidget     *widget,
3763                  const gchar   *detail,
3764                  gint           x,
3765                  gint           y,
3766                  gint           width,
3767                  gint           height)
3768 {
3769   g_return_if_fail (style != NULL);
3770   g_return_if_fail (style->klass != NULL);
3771   g_return_if_fail (style->klass->draw_focus != NULL);
3772   
3773   style->klass->draw_focus (style, window, area, widget, detail, x, y, width, height);
3774 }
3775
3776 void
3777 gtk_paint_slider (GtkStyle      *style,
3778                   GdkWindow     *window,
3779                   GtkStateType   state_type,
3780                   GtkShadowType  shadow_type,
3781                   GdkRectangle  *area,
3782                   GtkWidget     *widget,
3783                   const gchar   *detail,
3784                   gint           x,
3785                   gint           y,
3786                   gint           width,
3787                   gint           height,
3788                   GtkOrientation orientation)
3789 {
3790   g_return_if_fail (style != NULL);
3791   g_return_if_fail (style->klass != NULL);
3792   g_return_if_fail (style->klass->draw_slider != NULL);
3793   
3794   style->klass->draw_slider (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
3795 }
3796
3797 void
3798 gtk_paint_handle (GtkStyle      *style,
3799                   GdkWindow     *window,
3800                   GtkStateType   state_type,
3801                   GtkShadowType  shadow_type,
3802                   GdkRectangle  *area,
3803                   GtkWidget     *widget,
3804                   const gchar   *detail,
3805                   gint           x,
3806                   gint           y,
3807                   gint           width,
3808                   gint           height,
3809                   GtkOrientation orientation)
3810 {
3811   g_return_if_fail (style != NULL);
3812   g_return_if_fail (style->klass != NULL);
3813   g_return_if_fail (style->klass->draw_handle != NULL);
3814   
3815   style->klass->draw_handle (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
3816 }