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