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