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