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