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