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