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