]> Pileus Git - ~andy/gtk/blob - gtk/gtkstyle.c
Move wholly deprecated files to a subdirectory
[~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 "config.h"
28 #include <math.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <gobject/gvaluecollector.h>
32 #include "gtkmarshalers.h"
33 #include "gtkpango.h"
34 #include "gtkrc.h"
35 #include "gtkspinbutton.h"
36 #include "gtkstyle.h"
37 #include "gtkstylecontextprivate.h"
38 #include "gtkwidget.h"
39 #include "gtkiconfactory.h"
40 #include "gtkintl.h"
41 #include "gtkdebug.h"
42 #include "gtkspinner.h"
43 #include "gtkborder.h"
44
45 /**
46  * SECTION:gtkstyle
47  * @Short_description: Deprecated object that holds style information
48  *     for widgets
49  * @Title: GtkStyle
50  *
51  * A #GtkStyle object encapsulates the information that provides the look and
52  * feel for a widget.
53  *
54  * <warning>
55  * In GTK+ 3.0, GtkStyle has been deprecated and replaced by #GtkStyleContext.
56  * </warning>
57  *
58  * Each #GtkWidget has an associated #GtkStyle object that is used when
59  * rendering that widget. Also, a #GtkStyle holds information for the five
60  * possible widget states though not every widget supports all five
61  * states; see #GtkStateType.
62  *
63  * Usually the #GtkStyle for a widget is the same as the default style that
64  * is set by GTK+ and modified the theme engine.
65  *
66  * Usually applications should not need to use or modify the #GtkStyle of
67  * their widgets.
68  */
69
70
71 #define LIGHTNESS_MULT  1.3
72 #define DARKNESS_MULT   0.7
73
74 /* --- typedefs & structures --- */
75 typedef struct {
76   GType       widget_type;
77   GParamSpec *pspec;
78   GValue      value;
79 } PropertyValue;
80
81 #define GTK_STYLE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_STYLE, GtkStylePrivate))
82
83 typedef struct _GtkStylePrivate GtkStylePrivate;
84
85 struct _GtkStylePrivate {
86   GtkStyleContext *context;
87   gulong context_changed_id;
88 };
89
90 enum {
91   PROP_0,
92   PROP_CONTEXT
93 };
94
95 /* --- prototypes --- */
96 static void      gtk_style_finalize             (GObject        *object);
97 static void      gtk_style_constructed          (GObject        *object);
98 static void      gtk_style_set_property         (GObject        *object,
99                                                  guint           prop_id,
100                                                  const GValue   *value,
101                                                  GParamSpec     *pspec);
102 static void      gtk_style_get_property         (GObject        *object,
103                                                  guint           prop_id,
104                                                  GValue         *value,
105                                                  GParamSpec     *pspec);
106
107 static void      gtk_style_real_realize        (GtkStyle        *style);
108 static void      gtk_style_real_unrealize      (GtkStyle        *style);
109 static void      gtk_style_real_copy           (GtkStyle        *style,
110                                                 GtkStyle        *src);
111 static void      gtk_style_real_set_background (GtkStyle        *style,
112                                                 GdkWindow       *window,
113                                                 GtkStateType     state_type);
114 static GtkStyle *gtk_style_real_clone          (GtkStyle        *style);
115 static void      gtk_style_real_init_from_rc   (GtkStyle        *style,
116                                                 GtkRcStyle      *rc_style);
117 static GdkPixbuf *gtk_default_render_icon      (GtkStyle            *style,
118                                                 const GtkIconSource *source,
119                                                 GtkTextDirection     direction,
120                                                 GtkStateType         state,
121                                                 GtkIconSize          size,
122                                                 GtkWidget           *widget,
123                                                 const gchar         *detail);
124 static void gtk_default_draw_hline      (GtkStyle        *style,
125                                          cairo_t         *cr,
126                                          GtkStateType     state_type,
127                                          GtkWidget       *widget,
128                                          const gchar     *detail,
129                                          gint             x1,
130                                          gint             x2,
131                                          gint             y);
132 static void gtk_default_draw_vline      (GtkStyle        *style,
133                                          cairo_t         *cr,
134                                          GtkStateType     state_type,
135                                          GtkWidget       *widget,
136                                          const gchar     *detail,
137                                          gint             y1,
138                                          gint             y2,
139                                          gint             x);
140 static void gtk_default_draw_shadow     (GtkStyle        *style,
141                                          cairo_t         *cr,
142                                          GtkStateType     state_type,
143                                          GtkShadowType    shadow_type,
144                                          GtkWidget       *widget,
145                                          const gchar     *detail,
146                                          gint             x,
147                                          gint             y,
148                                          gint             width,
149                                          gint             height);
150 static void gtk_default_draw_arrow      (GtkStyle        *style,
151                                          cairo_t         *cr,
152                                          GtkStateType     state_type,
153                                          GtkShadowType    shadow_type,
154                                          GtkWidget       *widget,
155                                          const gchar     *detail,
156                                          GtkArrowType     arrow_type,
157                                          gboolean         fill,
158                                          gint             x,
159                                          gint             y,
160                                          gint             width,
161                                          gint             height);
162 static void gtk_default_draw_diamond    (GtkStyle        *style,
163                                          cairo_t         *cr,
164                                          GtkStateType     state_type,
165                                          GtkShadowType    shadow_type,
166                                          GtkWidget       *widget,
167                                          const gchar     *detail,
168                                          gint             x,
169                                          gint             y,
170                                          gint             width,
171                                          gint             height);
172 static void gtk_default_draw_box        (GtkStyle        *style,
173                                          cairo_t         *cr,
174                                          GtkStateType     state_type,
175                                          GtkShadowType    shadow_type,
176                                          GtkWidget       *widget,
177                                          const gchar     *detail,
178                                          gint             x,
179                                          gint             y,
180                                          gint             width,
181                                          gint             height);
182 static void gtk_default_draw_flat_box   (GtkStyle        *style,
183                                          cairo_t         *cr,
184                                          GtkStateType     state_type,
185                                          GtkShadowType    shadow_type,
186                                          GtkWidget       *widget,
187                                          const gchar     *detail,
188                                          gint             x,
189                                          gint             y,
190                                          gint             width,
191                                          gint             height);
192 static void gtk_default_draw_check      (GtkStyle        *style,
193                                          cairo_t         *cr,
194                                          GtkStateType     state_type,
195                                          GtkShadowType    shadow_type,
196                                          GtkWidget       *widget,
197                                          const gchar     *detail,
198                                          gint             x,
199                                          gint             y,
200                                          gint             width,
201                                          gint             height);
202 static void gtk_default_draw_option     (GtkStyle        *style,
203                                          cairo_t         *cr,
204                                          GtkStateType     state_type,
205                                          GtkShadowType    shadow_type,
206                                          GtkWidget       *widget,
207                                          const gchar     *detail,
208                                          gint             x,
209                                          gint             y,
210                                          gint             width,
211                                          gint             height);
212 static void gtk_default_draw_tab        (GtkStyle        *style,
213                                          cairo_t         *cr,
214                                          GtkStateType     state_type,
215                                          GtkShadowType    shadow_type,
216                                          GtkWidget       *widget,
217                                          const gchar     *detail,
218                                          gint             x,
219                                          gint             y,
220                                          gint             width,
221                                          gint             height);
222 static void gtk_default_draw_shadow_gap (GtkStyle        *style,
223                                          cairo_t         *cr,
224                                          GtkStateType     state_type,
225                                          GtkShadowType    shadow_type,
226                                          GtkWidget       *widget,
227                                          const gchar     *detail,
228                                          gint             x,
229                                          gint             y,
230                                          gint             width,
231                                          gint             height,
232                                          GtkPositionType  gap_side,
233                                          gint             gap_x,
234                                          gint             gap_width);
235 static void gtk_default_draw_box_gap    (GtkStyle        *style,
236                                          cairo_t         *cr,
237                                          GtkStateType     state_type,
238                                          GtkShadowType    shadow_type,
239                                          GtkWidget       *widget,
240                                          const gchar     *detail,
241                                          gint             x,
242                                          gint             y,
243                                          gint             width,
244                                          gint             height,
245                                          GtkPositionType  gap_side,
246                                          gint             gap_x,
247                                          gint             gap_width);
248 static void gtk_default_draw_extension  (GtkStyle        *style,
249                                          cairo_t         *cr,
250                                          GtkStateType     state_type,
251                                          GtkShadowType    shadow_type,
252                                          GtkWidget       *widget,
253                                          const gchar     *detail,
254                                          gint             x,
255                                          gint             y,
256                                          gint             width,
257                                          gint             height,
258                                          GtkPositionType  gap_side);
259 static void gtk_default_draw_focus      (GtkStyle        *style,
260                                          cairo_t         *cr,
261                                          GtkStateType     state_type,
262                                          GtkWidget       *widget,
263                                          const gchar     *detail,
264                                          gint             x,
265                                          gint             y,
266                                          gint             width,
267                                          gint             height);
268 static void gtk_default_draw_slider     (GtkStyle        *style,
269                                          cairo_t         *cr,
270                                          GtkStateType     state_type,
271                                          GtkShadowType    shadow_type,
272                                          GtkWidget       *widget,
273                                          const gchar     *detail,
274                                          gint             x,
275                                          gint             y,
276                                          gint             width,
277                                          gint             height,
278                                          GtkOrientation   orientation);
279 static void gtk_default_draw_handle     (GtkStyle        *style,
280                                          cairo_t         *cr,
281                                          GtkStateType     state_type,
282                                          GtkShadowType    shadow_type,
283                                          GtkWidget       *widget,
284                                          const gchar     *detail,
285                                          gint             x,
286                                          gint             y,
287                                          gint             width,
288                                          gint             height,
289                                          GtkOrientation   orientation);
290 static void gtk_default_draw_expander   (GtkStyle        *style,
291                                          cairo_t         *cr,
292                                          GtkStateType     state_type,
293                                          GtkWidget       *widget,
294                                          const gchar     *detail,
295                                          gint             x,
296                                          gint             y,
297                                          GtkExpanderStyle expander_style);
298 static void gtk_default_draw_layout     (GtkStyle        *style,
299                                          cairo_t         *cr,
300                                          GtkStateType     state_type,
301                                          gboolean         use_text,
302                                          GtkWidget       *widget,
303                                          const gchar     *detail,
304                                          gint             x,
305                                          gint             y,
306                                          PangoLayout     *layout);
307 static void gtk_default_draw_resize_grip (GtkStyle       *style,
308                                           cairo_t        *cr,
309                                           GtkStateType    state_type,
310                                           GtkWidget      *widget,
311                                           const gchar    *detail,
312                                           GdkWindowEdge   edge,
313                                           gint            x,
314                                           gint            y,
315                                           gint            width,
316                                           gint            height);
317 static void gtk_default_draw_spinner     (GtkStyle       *style,
318                                           cairo_t        *cr,
319                                           GtkStateType    state_type,
320                                           GtkWidget      *widget,
321                                           const gchar    *detail,
322                                           guint           step,
323                                           gint            x,
324                                           gint            y,
325                                           gint            width,
326                                           gint            height);
327
328 static void rgb_to_hls                  (gdouble         *r,
329                                          gdouble         *g,
330                                          gdouble         *b);
331 static void hls_to_rgb                  (gdouble         *h,
332                                          gdouble         *l,
333                                          gdouble         *s);
334
335 static void transform_detail_string (const gchar     *detail,
336                                      GtkStyleContext *context);
337
338 /*
339  * Data for default check and radio buttons
340  */
341
342 static const GtkRequisition default_option_indicator_size = { 7, 13 };
343 static const GtkBorder default_option_indicator_spacing = { 7, 5, 2, 2 };
344
345 #define GTK_GRAY                0xdcdc, 0xdada, 0xd5d5
346 #define GTK_DARK_GRAY           0xc4c4, 0xc2c2, 0xbdbd
347 #define GTK_LIGHT_GRAY          0xeeee, 0xebeb, 0xe7e7
348 #define GTK_WHITE               0xffff, 0xffff, 0xffff
349 #define GTK_BLUE                0x4b4b, 0x6969, 0x8383
350 #define GTK_VERY_DARK_GRAY      0x9c9c, 0x9a9a, 0x9494
351 #define GTK_BLACK               0x0000, 0x0000, 0x0000
352 #define GTK_WEAK_GRAY           0x7530, 0x7530, 0x7530
353
354 /* --- variables --- */
355 static const GdkColor gtk_default_normal_fg =      { 0, GTK_BLACK };
356 static const GdkColor gtk_default_active_fg =      { 0, GTK_BLACK };
357 static const GdkColor gtk_default_prelight_fg =    { 0, GTK_BLACK };
358 static const GdkColor gtk_default_selected_fg =    { 0, GTK_WHITE };
359 static const GdkColor gtk_default_insensitive_fg = { 0, GTK_WEAK_GRAY };
360
361 static const GdkColor gtk_default_normal_bg =      { 0, GTK_GRAY };
362 static const GdkColor gtk_default_active_bg =      { 0, GTK_DARK_GRAY };
363 static const GdkColor gtk_default_prelight_bg =    { 0, GTK_LIGHT_GRAY };
364 static const GdkColor gtk_default_selected_bg =    { 0, GTK_BLUE };
365 static const GdkColor gtk_default_insensitive_bg = { 0, GTK_GRAY };
366 static const GdkColor gtk_default_selected_base =  { 0, GTK_BLUE };
367 static const GdkColor gtk_default_active_base =    { 0, GTK_VERY_DARK_GRAY };
368
369 /* --- signals --- */
370 static guint realize_signal = 0;
371 static guint unrealize_signal = 0;
372
373 G_DEFINE_TYPE (GtkStyle, gtk_style, G_TYPE_OBJECT)
374
375 /* --- functions --- */
376
377 static void
378 gtk_style_init (GtkStyle *style)
379 {
380   gint i;
381
382   style->font_desc = pango_font_description_from_string ("Sans 10");
383
384   style->attach_count = 0;
385   
386   style->black.red = 0;
387   style->black.green = 0;
388   style->black.blue = 0;
389   
390   style->white.red = 65535;
391   style->white.green = 65535;
392   style->white.blue = 65535;
393   
394   style->fg[GTK_STATE_NORMAL] = gtk_default_normal_fg;
395   style->fg[GTK_STATE_ACTIVE] = gtk_default_active_fg;
396   style->fg[GTK_STATE_PRELIGHT] = gtk_default_prelight_fg;
397   style->fg[GTK_STATE_SELECTED] = gtk_default_selected_fg;
398   style->fg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
399   
400   style->bg[GTK_STATE_NORMAL] = gtk_default_normal_bg;
401   style->bg[GTK_STATE_ACTIVE] = gtk_default_active_bg;
402   style->bg[GTK_STATE_PRELIGHT] = gtk_default_prelight_bg;
403   style->bg[GTK_STATE_SELECTED] = gtk_default_selected_bg;
404   style->bg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_bg;
405   
406   for (i = 0; i < 4; i++)
407     {
408       style->text[i] = style->fg[i];
409       style->base[i] = style->white;
410     }
411
412   style->base[GTK_STATE_SELECTED] = gtk_default_selected_base;
413   style->text[GTK_STATE_SELECTED] = style->white;
414   style->base[GTK_STATE_ACTIVE] = gtk_default_active_base;
415   style->text[GTK_STATE_ACTIVE] = style->white;
416   style->base[GTK_STATE_INSENSITIVE] = gtk_default_prelight_bg;
417   style->text[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
418   
419   style->rc_style = NULL;
420   
421   style->xthickness = 2;
422   style->ythickness = 2;
423
424   style->property_cache = NULL;
425 }
426
427 static void
428 gtk_style_class_init (GtkStyleClass *klass)
429 {
430   GObjectClass *object_class = G_OBJECT_CLASS (klass);
431   
432   object_class->finalize = gtk_style_finalize;
433   object_class->set_property = gtk_style_set_property;
434   object_class->get_property = gtk_style_get_property;
435   object_class->constructed = gtk_style_constructed;
436
437   klass->clone = gtk_style_real_clone;
438   klass->copy = gtk_style_real_copy;
439   klass->init_from_rc = gtk_style_real_init_from_rc;
440   klass->realize = gtk_style_real_realize;
441   klass->unrealize = gtk_style_real_unrealize;
442   klass->set_background = gtk_style_real_set_background;
443   klass->render_icon = gtk_default_render_icon;
444
445   klass->draw_hline = gtk_default_draw_hline;
446   klass->draw_vline = gtk_default_draw_vline;
447   klass->draw_shadow = gtk_default_draw_shadow;
448   klass->draw_arrow = gtk_default_draw_arrow;
449   klass->draw_diamond = gtk_default_draw_diamond;
450   klass->draw_box = gtk_default_draw_box;
451   klass->draw_flat_box = gtk_default_draw_flat_box;
452   klass->draw_check = gtk_default_draw_check;
453   klass->draw_option = gtk_default_draw_option;
454   klass->draw_tab = gtk_default_draw_tab;
455   klass->draw_shadow_gap = gtk_default_draw_shadow_gap;
456   klass->draw_box_gap = gtk_default_draw_box_gap;
457   klass->draw_extension = gtk_default_draw_extension;
458   klass->draw_focus = gtk_default_draw_focus;
459   klass->draw_slider = gtk_default_draw_slider;
460   klass->draw_handle = gtk_default_draw_handle;
461   klass->draw_expander = gtk_default_draw_expander;
462   klass->draw_layout = gtk_default_draw_layout;
463   klass->draw_resize_grip = gtk_default_draw_resize_grip;
464   klass->draw_spinner = gtk_default_draw_spinner;
465
466   g_type_class_add_private (object_class, sizeof (GtkStylePrivate));
467
468   g_object_class_install_property (object_class,
469                                    PROP_CONTEXT,
470                                    g_param_spec_object ("context",
471                                                         P_("Style context"),
472                                                         P_("GtkStyleContext to get style from"),
473                                                         GTK_TYPE_STYLE_CONTEXT,
474                                                         G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
475
476   /**
477    * GtkStyle::realize:
478    * @style: the object which received the signal
479    *
480    * Emitted when the style has been initialized for a particular
481    * visual. Connecting to this signal is probably seldom
482    * useful since most of the time applications and widgets only
483    * deal with styles that have been already realized.
484    *
485    * Since: 2.4
486    */
487   realize_signal = g_signal_new (I_("realize"),
488                                  G_TYPE_FROM_CLASS (object_class),
489                                  G_SIGNAL_RUN_FIRST,
490                                  G_STRUCT_OFFSET (GtkStyleClass, realize),
491                                  NULL, NULL,
492                                  _gtk_marshal_VOID__VOID,
493                                  G_TYPE_NONE, 0);
494   /**
495    * GtkStyle::unrealize:
496    * @style: the object which received the signal
497    *
498    * Emitted when the aspects of the style specific to a particular visual
499    * is being cleaned up. A connection to this signal can be useful
500    * if a widget wants to cache objects as object data on #GtkStyle.
501    * This signal provides a convenient place to free such cached objects.
502    *
503    * Since: 2.4
504    */
505   unrealize_signal = g_signal_new (I_("unrealize"),
506                                    G_TYPE_FROM_CLASS (object_class),
507                                    G_SIGNAL_RUN_FIRST,
508                                    G_STRUCT_OFFSET (GtkStyleClass, unrealize),
509                                    NULL, NULL,
510                                    _gtk_marshal_VOID__VOID,
511                                    G_TYPE_NONE, 0);
512 }
513
514 static void
515 gtk_style_finalize (GObject *object)
516 {
517   GtkStyle *style = GTK_STYLE (object);
518   GtkStylePrivate *priv = GTK_STYLE_GET_PRIVATE (style);
519   gint i;
520
521   g_return_if_fail (style->attach_count == 0);
522
523   /* All the styles in the list have the same 
524    * style->styles pointer. If we delete the 
525    * *first* style from the list, we need to update
526    * the style->styles pointers from all the styles.
527    * Otherwise we simply remove the node from
528    * the list.
529    */
530   if (style->styles)
531     {
532       if (style->styles->data != style)
533         style->styles = g_slist_remove (style->styles, style);
534       else
535         {
536           GSList *tmp_list = style->styles->next;
537           
538           while (tmp_list)
539             {
540               GTK_STYLE (tmp_list->data)->styles = style->styles->next;
541               tmp_list = tmp_list->next;
542             }
543           g_slist_free_1 (style->styles);
544         }
545     }
546
547   g_slist_foreach (style->icon_factories, (GFunc) g_object_unref, NULL);
548   g_slist_free (style->icon_factories);
549
550   pango_font_description_free (style->font_desc);
551
552   if (style->private_font_desc)
553     pango_font_description_free (style->private_font_desc);
554
555   if (style->rc_style)
556     g_object_unref (style->rc_style);
557
558   if (priv->context)
559     {
560       if (priv->context_changed_id)
561         g_signal_handler_disconnect (priv->context, priv->context_changed_id);
562
563       g_object_unref (priv->context);
564     }
565
566   for (i = 0; i < 5; i++)
567     {
568       if (style->background[i])
569         cairo_pattern_destroy (style->background[i]);
570     }
571
572   G_OBJECT_CLASS (gtk_style_parent_class)->finalize (object);
573 }
574
575 static void
576 gtk_style_set_property (GObject      *object,
577                         guint         prop_id,
578                         const GValue *value,
579                         GParamSpec   *pspec)
580 {
581   GtkStylePrivate *priv;
582
583   priv = GTK_STYLE_GET_PRIVATE (object);
584
585   switch (prop_id)
586     {
587     case PROP_CONTEXT:
588       priv->context = g_value_dup_object (value);
589       break;
590     default:
591       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
592       break;
593     }
594 }
595
596 static void
597 gtk_style_get_property (GObject      *object,
598                         guint         prop_id,
599                         GValue       *value,
600                         GParamSpec   *pspec)
601 {
602   GtkStylePrivate *priv;
603
604   priv = GTK_STYLE_GET_PRIVATE (object);
605
606   switch (prop_id)
607     {
608     case PROP_CONTEXT:
609       g_value_set_object (value, priv->context);
610       break;
611     default:
612       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
613       break;
614     }
615 }
616
617 static void
618 set_color (GtkStyle        *style,
619            GtkStyleContext *context,
620            GtkStateType     state,
621            GtkRcFlags       prop)
622 {
623   GtkStateFlags flags;
624   GdkRGBA *color = NULL;
625   GdkColor *dest = { 0 }; /* Shut up gcc */
626
627   switch (state)
628     {
629     case GTK_STATE_ACTIVE:
630       flags = GTK_STATE_FLAG_ACTIVE;
631       break;
632     case GTK_STATE_PRELIGHT:
633       flags = GTK_STATE_FLAG_PRELIGHT;
634       break;
635     case GTK_STATE_SELECTED:
636       flags = GTK_STATE_FLAG_SELECTED;
637       break;
638     case GTK_STATE_INSENSITIVE:
639       flags = GTK_STATE_FLAG_INSENSITIVE;
640       break;
641     default:
642       flags = 0;
643     }
644
645   switch (prop)
646     {
647     case GTK_RC_BG:
648       gtk_style_context_get (context, flags,
649                              "background-color", &color,
650                              NULL);
651       dest = &style->bg[state];
652       break;
653     case GTK_RC_FG:
654       gtk_style_context_get (context, flags,
655                              "color", &color,
656                              NULL);
657       dest = &style->fg[state];
658       break;
659     case GTK_RC_TEXT:
660       gtk_style_context_get (context, flags,
661                              "color", &color,
662                              NULL);
663       dest = &style->text[state];
664       break;
665     case GTK_RC_BASE:
666       gtk_style_context_get (context, flags,
667                              "background-color", &color,
668                              NULL);
669       dest = &style->base[state];
670       break;
671     }
672
673   if (color)
674     {
675       dest->pixel = 0;
676       dest->red = CLAMP ((guint) (color->red * 65535), 0, 65535);
677       dest->green = CLAMP ((guint) (color->green * 65535), 0, 65535);
678       dest->blue = CLAMP ((guint) (color->blue * 65535), 0, 65535);
679       gdk_rgba_free (color);
680     }
681 }
682
683 static void
684 gtk_style_update_from_context (GtkStyle *style)
685 {
686   GtkStylePrivate *priv;
687   GtkStateType state;
688   GtkBorder padding;
689   gint i;
690
691   priv = GTK_STYLE_GET_PRIVATE (style);
692
693   for (state = GTK_STATE_NORMAL; state <= GTK_STATE_INSENSITIVE; state++)
694     {
695       if (gtk_style_context_has_class (priv->context, "entry"))
696         {
697           gtk_style_context_save (priv->context);
698           gtk_style_context_remove_class (priv->context, "entry");
699           set_color (style, priv->context, state, GTK_RC_BG);
700           set_color (style, priv->context, state, GTK_RC_FG);
701           gtk_style_context_restore (priv->context);
702
703           set_color (style, priv->context, state, GTK_RC_BASE);
704           set_color (style, priv->context, state, GTK_RC_TEXT);
705         }
706       else
707         {
708           gtk_style_context_save (priv->context);
709           gtk_style_context_add_class (priv->context, "entry");
710           set_color (style, priv->context, state, GTK_RC_BASE);
711           set_color (style, priv->context, state, GTK_RC_TEXT);
712           gtk_style_context_restore (priv->context);
713
714           set_color (style, priv->context, state, GTK_RC_BG);
715           set_color (style, priv->context, state, GTK_RC_FG);
716         }
717     }
718
719   if (style->font_desc)
720     pango_font_description_free (style->font_desc);
721
722   gtk_style_context_get (priv->context, 0,
723                          "font", &style->font_desc,
724                          NULL);
725   gtk_style_context_get_padding (priv->context, 0, &padding);
726
727   style->xthickness = padding.left;
728   style->ythickness = padding.top;
729
730   for (i = 0; i < 5; i++)
731     {
732       _gtk_style_shade (&style->bg[i], &style->light[i], LIGHTNESS_MULT);
733       _gtk_style_shade (&style->bg[i], &style->dark[i], DARKNESS_MULT);
734
735       style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
736       style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
737       style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
738
739       style->text_aa[i].red = (style->text[i].red + style->base[i].red) / 2;
740       style->text_aa[i].green = (style->text[i].green + style->base[i].green) / 2;
741       style->text_aa[i].blue = (style->text[i].blue + style->base[i].blue) / 2;
742     }
743
744   style->black.red = 0x0000;
745   style->black.green = 0x0000;
746   style->black.blue = 0x0000;
747
748   style->white.red = 0xffff;
749   style->white.green = 0xffff;
750   style->white.blue = 0xffff;
751
752   for (i = 0; i < 5; i++)
753     {
754       if (style->background[i])
755         cairo_pattern_destroy (style->background[i]);
756
757       style->background[i] = cairo_pattern_create_rgb (style->bg[i].red / 65535.0,
758                                                        style->bg[i].green / 65535.0,
759                                                        style->bg[i].blue / 65535.0);
760     }
761 }
762
763 static void
764 style_context_changed (GtkStyleContext *context,
765                        gpointer         user_data)
766 {
767   gtk_style_update_from_context (GTK_STYLE (user_data));
768 }
769
770 static void
771 gtk_style_constructed (GObject *object)
772 {
773   GtkStylePrivate *priv;
774
775   priv = GTK_STYLE_GET_PRIVATE (object);
776
777   if (priv->context)
778     {
779       gtk_style_update_from_context (GTK_STYLE (object));
780
781       priv->context_changed_id = g_signal_connect (priv->context, "changed",
782                                                    G_CALLBACK (style_context_changed), object);
783     }
784 }
785
786 /**
787  * gtk_style_copy:
788  * @style: a #GtkStyle
789  *
790  * Creates a copy of the passed in #GtkStyle object.
791  *
792  * Returns: (transfer full): a copy of @style
793  *
794  * Deprecated:3.0: Use #GtkStyleContext instead
795  */
796 GtkStyle*
797 gtk_style_copy (GtkStyle *style)
798 {
799   GtkStyle *new_style;
800   
801   g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
802   
803   new_style = GTK_STYLE_GET_CLASS (style)->clone (style);
804   GTK_STYLE_GET_CLASS (style)->copy (new_style, style);
805
806   return new_style;
807 }
808
809 GtkStyle*
810 _gtk_style_new_for_path (GdkScreen     *screen,
811                          GtkWidgetPath *path)
812 {
813   GtkStyleContext *context;
814   GtkStyle *style;
815
816   context = gtk_style_context_new ();
817
818   if (screen)
819     gtk_style_context_set_screen (context, screen);
820
821   gtk_style_context_set_path (context, path);
822
823   style = g_object_new (GTK_TYPE_STYLE,
824                         "context", context,
825                         NULL);
826
827   g_object_unref (context);
828
829   return style;
830 }
831
832 /**
833  * gtk_style_new:
834  *
835  * Creates a new #GtkStyle.
836  *
837  * Returns: a new #GtkStyle.
838  *
839  * Deprecated: 3.0: Use #GtkStyleContext
840  */
841 GtkStyle*
842 gtk_style_new (void)
843 {
844   GtkWidgetPath *path;
845   GtkStyle *style;
846
847   path = gtk_widget_path_new ();
848   gtk_widget_path_append_type (path, GTK_TYPE_WIDGET);
849
850   style = _gtk_style_new_for_path (gdk_screen_get_default (), path);
851
852   gtk_widget_path_free (path);
853
854   return style;
855 }
856
857 /**
858  * gtk_style_has_context:
859  * @style: a #GtkStyle
860  *
861  * Returns whether @style has an associated #GtkStyleContext.
862  *
863  * Returns: %TRUE if @style has a #GtkStyleContext
864  *
865  * Since: 3.0
866  */
867 gboolean
868 gtk_style_has_context (GtkStyle *style)
869 {
870   GtkStylePrivate *priv;
871
872   priv = GTK_STYLE_GET_PRIVATE (style);
873
874   return priv->context != NULL;
875 }
876
877 /**
878  * gtk_style_attach: (skip)
879  * @style: a #GtkStyle.
880  * @window: a #GdkWindow.
881  *
882  * Attaches a style to a window; this process allocates the
883  * colors and creates the GC's for the style - it specializes
884  * it to a particular visual. The process may involve the creation
885  * of a new style if the style has already been attached to a
886  * window with a different style and visual.
887  *
888  * Since this function may return a new object, you have to use it
889  * in the following way:
890  * <literal>style = gtk_style_attach (style, window)</literal>
891  *
892  * Returns: Either @style, or a newly-created #GtkStyle.
893  *   If the style is newly created, the style parameter
894  *   will be unref'ed, and the new style will have
895  *   a reference count belonging to the caller.
896  *
897  * Deprecated:3.0: Use gtk_widget_style_attach() instead
898  */
899 GtkStyle*
900 gtk_style_attach (GtkStyle  *style,
901                   GdkWindow *window)
902 {
903   g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
904   g_return_val_if_fail (window != NULL, NULL);
905
906   return style;
907 }
908
909 /**
910  * gtk_style_detach:
911  * @style: a #GtkStyle
912  *
913  * Detaches a style from a window. If the style is not attached
914  * to any windows anymore, it is unrealized. See gtk_style_attach().
915  *
916  * Deprecated:3.0: Use #GtkStyleContext instead
917  */
918 void
919 gtk_style_detach (GtkStyle *style)
920 {
921   g_return_if_fail (GTK_IS_STYLE (style));
922 }
923
924 /**
925  * gtk_style_lookup_icon_set:
926  * @style: a #GtkStyle
927  * @stock_id: an icon name
928  *
929  * Looks up @stock_id in the icon factories associated with @style
930  * and the default icon factory, returning an icon set if found,
931  * otherwise %NULL.
932  *
933  * Return value: (transfer none): icon set of @stock_id
934  *
935  * Deprecated:3.0: Use gtk_style_context_lookup_icon_set() instead
936  */
937 GtkIconSet*
938 gtk_style_lookup_icon_set (GtkStyle   *style,
939                            const char *stock_id)
940 {
941   GtkStylePrivate *priv;
942
943   g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
944   g_return_val_if_fail (stock_id != NULL, NULL);
945
946   priv = GTK_STYLE_GET_PRIVATE (style);
947
948   if (priv->context)
949     return gtk_style_context_lookup_icon_set (priv->context, stock_id);
950
951   return gtk_icon_factory_lookup_default (stock_id);
952 }
953
954 /**
955  * gtk_style_lookup_color:
956  * @style: a #GtkStyle
957  * @color_name: the name of the logical color to look up
958  * @color: (out): the #GdkColor to fill in
959  *
960  * Looks up @color_name in the style's logical color mappings,
961  * filling in @color and returning %TRUE if found, otherwise
962  * returning %FALSE. Do not cache the found mapping, because
963  * it depends on the #GtkStyle and might change when a theme
964  * switch occurs.
965  *
966  * Return value: %TRUE if the mapping was found.
967  *
968  * Since: 2.10
969  *
970  * Deprecated:3.0: Use gtk_style_context_lookup_color() instead
971  **/
972 gboolean
973 gtk_style_lookup_color (GtkStyle   *style,
974                         const char *color_name,
975                         GdkColor   *color)
976 {
977   GtkStylePrivate *priv;
978   gboolean result;
979   GdkRGBA rgba;
980
981   g_return_val_if_fail (GTK_IS_STYLE (style), FALSE);
982   g_return_val_if_fail (color_name != NULL, FALSE);
983   g_return_val_if_fail (color != NULL, FALSE);
984
985   priv = GTK_STYLE_GET_PRIVATE (style);
986
987   if (!priv->context)
988     return FALSE;
989
990   result = gtk_style_context_lookup_color (priv->context, color_name, &rgba);
991
992   if (color)
993     {
994       color->red = (guint16) (rgba.red * 65535);
995       color->green = (guint16) (rgba.green * 65535);
996       color->blue = (guint16) (rgba.blue * 65535);
997       color->pixel = 0;
998     }
999
1000   return result;
1001 }
1002
1003 /**
1004  * gtk_style_set_background:
1005  * @style: a #GtkStyle
1006  * @window: a #GdkWindow
1007  * @state_type: a state
1008  * 
1009  * Sets the background of @window to the background color or pixmap
1010  * specified by @style for the given state.
1011  *
1012  * Deprecated:3.0: Use gtk_style_context_set_background() instead
1013  */
1014 void
1015 gtk_style_set_background (GtkStyle    *style,
1016                           GdkWindow   *window,
1017                           GtkStateType state_type)
1018 {
1019   g_return_if_fail (GTK_IS_STYLE (style));
1020   g_return_if_fail (window != NULL);
1021   
1022   GTK_STYLE_GET_CLASS (style)->set_background (style, window, state_type);
1023 }
1024
1025 /* Default functions */
1026 static GtkStyle *
1027 gtk_style_real_clone (GtkStyle *style)
1028 {
1029   GtkStylePrivate *priv;
1030
1031   priv = GTK_STYLE_GET_PRIVATE (style);
1032
1033   return g_object_new (G_OBJECT_TYPE (style),
1034                        "context", priv->context,
1035                        NULL);
1036 }
1037
1038 static void
1039 gtk_style_real_copy (GtkStyle *style,
1040                      GtkStyle *src)
1041 {
1042   gint i;
1043   
1044   for (i = 0; i < 5; i++)
1045     {
1046       style->fg[i] = src->fg[i];
1047       style->bg[i] = src->bg[i];
1048       style->text[i] = src->text[i];
1049       style->base[i] = src->base[i];
1050
1051       if (style->background[i])
1052         cairo_pattern_destroy (style->background[i]),
1053       style->background[i] = src->background[i];
1054       if (style->background[i])
1055         cairo_pattern_reference (style->background[i]);
1056     }
1057
1058   if (style->font_desc)
1059     pango_font_description_free (style->font_desc);
1060   if (src->font_desc)
1061     style->font_desc = pango_font_description_copy (src->font_desc);
1062   else
1063     style->font_desc = NULL;
1064   
1065   style->xthickness = src->xthickness;
1066   style->ythickness = src->ythickness;
1067
1068   if (style->rc_style)
1069     g_object_unref (style->rc_style);
1070   style->rc_style = src->rc_style;
1071   if (src->rc_style)
1072     g_object_ref (src->rc_style);
1073
1074   g_slist_foreach (style->icon_factories, (GFunc) g_object_unref, NULL);
1075   g_slist_free (style->icon_factories);
1076   style->icon_factories = g_slist_copy (src->icon_factories);
1077   g_slist_foreach (style->icon_factories, (GFunc) g_object_ref, NULL);
1078 }
1079
1080 static void
1081 gtk_style_real_init_from_rc (GtkStyle   *style,
1082                              GtkRcStyle *rc_style)
1083 {
1084 }
1085
1086 /**
1087  * gtk_style_get_style_property:
1088  * @style: a #GtkStyle
1089  * @widget_type: the #GType of a descendant of #GtkWidget
1090  * @property_name: the name of the style property to get
1091  * @value: a #GValue where the value of the property being
1092  *     queried will be stored
1093  *
1094  * Queries the value of a style property corresponding to a
1095  * widget class is in the given style.
1096  *
1097  * Since: 2.16
1098  */
1099 void 
1100 gtk_style_get_style_property (GtkStyle     *style,
1101                               GType        widget_type,
1102                               const gchar *property_name,
1103                               GValue      *value)
1104 {
1105   GtkStylePrivate *priv;
1106   GtkWidgetClass *klass;
1107   GParamSpec *pspec;
1108   const GValue *peek_value;
1109
1110   klass = g_type_class_ref (widget_type);
1111   pspec = gtk_widget_class_find_style_property (klass, property_name);
1112   g_type_class_unref (klass);
1113
1114   if (!pspec)
1115     {
1116       g_warning ("%s: widget class `%s' has no property named `%s'",
1117                  G_STRLOC,
1118                  g_type_name (widget_type),
1119                  property_name);
1120       return;
1121     }
1122
1123   priv = GTK_STYLE_GET_PRIVATE (style);
1124   peek_value = _gtk_style_context_peek_style_property (priv->context,
1125                                                        widget_type,
1126                                                        0, pspec);
1127
1128   if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
1129     g_value_copy (peek_value, value);
1130   else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
1131     g_value_transform (peek_value, value);
1132   else
1133     g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
1134                pspec->name,
1135                g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1136                G_VALUE_TYPE_NAME (value));
1137 }
1138
1139 /**
1140  * gtk_style_get_valist:
1141  * @style: a #GtkStyle
1142  * @widget_type: the #GType of a descendant of #GtkWidget
1143  * @first_property_name: the name of the first style property to get
1144  * @var_args: a <type>va_list</type> of pairs of property names and
1145  *     locations to return the property values, starting with the
1146  *     location for @first_property_name.
1147  *
1148  * Non-vararg variant of gtk_style_get().
1149  * Used primarily by language bindings.
1150  *
1151  * Since: 2.16
1152  */
1153 void 
1154 gtk_style_get_valist (GtkStyle    *style,
1155                       GType        widget_type,
1156                       const gchar *first_property_name,
1157                       va_list      var_args)
1158 {
1159   GtkStylePrivate *priv;
1160   const char *property_name;
1161   GtkWidgetClass *klass;
1162
1163   g_return_if_fail (GTK_IS_STYLE (style));
1164
1165   klass = g_type_class_ref (widget_type);
1166
1167   priv = GTK_STYLE_GET_PRIVATE (style);
1168   property_name = first_property_name;
1169   while (property_name)
1170     {
1171       GParamSpec *pspec;
1172       const GValue *peek_value;
1173       gchar *error;
1174
1175       pspec = gtk_widget_class_find_style_property (klass, property_name);
1176
1177       if (!pspec)
1178         {
1179           g_warning ("%s: widget class `%s' has no property named `%s'",
1180                      G_STRLOC,
1181                      g_type_name (widget_type),
1182                      property_name);
1183           break;
1184         }
1185
1186       peek_value = _gtk_style_context_peek_style_property (priv->context, widget_type,
1187                                                            0, pspec);
1188       G_VALUE_LCOPY (peek_value, var_args, 0, &error);
1189       if (error)
1190         {
1191           g_warning ("%s: %s", G_STRLOC, error);
1192           g_free (error);
1193           break;
1194         }
1195
1196       property_name = va_arg (var_args, gchar*);
1197     }
1198
1199   g_type_class_unref (klass);
1200 }
1201
1202 /**
1203  * gtk_style_get:
1204  * @style: a #GtkStyle
1205  * @widget_type: the #GType of a descendant of #GtkWidget
1206  * @first_property_name: the name of the first style property to get
1207  * @...: pairs of property names and locations to
1208  *   return the property values, starting with the location for
1209  *   @first_property_name, terminated by %NULL.
1210  *
1211  * Gets the values of a multiple style properties for @widget_type
1212  * from @style.
1213  *
1214  * Since: 2.16
1215  */
1216 void
1217 gtk_style_get (GtkStyle    *style,
1218                GType        widget_type,
1219                const gchar *first_property_name,
1220                ...)
1221 {
1222   va_list var_args;
1223
1224   va_start (var_args, first_property_name);
1225   gtk_style_get_valist (style, widget_type, first_property_name, var_args);
1226   va_end (var_args);
1227 }
1228
1229 static void
1230 gtk_style_real_realize (GtkStyle *style)
1231 {
1232 }
1233
1234 static void
1235 gtk_style_real_unrealize (GtkStyle *style)
1236 {
1237 }
1238
1239 static void
1240 gtk_style_real_set_background (GtkStyle    *style,
1241                                GdkWindow   *window,
1242                                GtkStateType state_type)
1243 {
1244   gdk_window_set_background_pattern (window, style->background[state_type]);
1245 }
1246
1247 /**
1248  * gtk_style_render_icon:
1249  * @style: a #GtkStyle
1250  * @source: the #GtkIconSource specifying the icon to render
1251  * @direction: a text direction
1252  * @state: a state
1253  * @size: (type int): the size to render the icon at. A size of
1254  *     (GtkIconSize)-1 means render at the size of the source and
1255  *     don't scale.
1256  * @widget: (allow-none): the widget
1257  * @detail: (allow-none): a style detail
1258  *
1259  * Renders the icon specified by @source at the given @size
1260  * according to the given parameters and returns the result in a
1261  * pixbuf.
1262  *
1263  * Return value: (transfer full): a newly-created #GdkPixbuf
1264  *     containing the rendered icon
1265  *
1266  * Deprecated:3.0: Use gtk_render_icon_pixbuf() instead
1267  */
1268 GdkPixbuf *
1269 gtk_style_render_icon (GtkStyle            *style,
1270                        const GtkIconSource *source,
1271                        GtkTextDirection     direction,
1272                        GtkStateType         state,
1273                        GtkIconSize          size,
1274                        GtkWidget           *widget,
1275                        const gchar         *detail)
1276 {
1277   GdkPixbuf *pixbuf;
1278   
1279   g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1280   g_return_val_if_fail (GTK_STYLE_GET_CLASS (style)->render_icon != NULL, NULL);
1281   
1282   pixbuf = GTK_STYLE_GET_CLASS (style)->render_icon (style, source, direction, state,
1283                                                      size, widget, detail);
1284
1285   g_return_val_if_fail (pixbuf != NULL, NULL);
1286
1287   return pixbuf;
1288 }
1289
1290 /* Default functions */
1291
1292 /**
1293  * gtk_style_apply_default_background:
1294  * @style:
1295  * @cr:
1296  * @window:
1297  * @state_type:
1298  * @x:
1299  * @y:
1300  * @width:
1301  * @height:
1302  *
1303  * Deprecated:3.0: Use #GtkStyleContext instead
1304  */
1305 void
1306 gtk_style_apply_default_background (GtkStyle          *style,
1307                                     cairo_t           *cr,
1308                                     GdkWindow         *window,
1309                                     GtkStateType       state_type,
1310                                     gint               x,
1311                                     gint               y,
1312                                     gint               width,
1313                                     gint               height)
1314 {
1315   cairo_save (cr);
1316
1317   if (style->background[state_type] == NULL)
1318     {
1319       GdkWindow *parent = gdk_window_get_parent (window);
1320       int x_offset, y_offset;
1321
1322       if (parent)
1323         {
1324           gdk_window_get_position (window, &x_offset, &y_offset);
1325           cairo_translate (cr, -x_offset, -y_offset);
1326           gtk_style_apply_default_background (style, cr,
1327                                               parent, state_type,
1328                                               x + x_offset, y + y_offset,
1329                                               width, height);
1330           goto out;
1331         }
1332       else
1333         gdk_cairo_set_source_color (cr, &style->bg[state_type]);
1334     }
1335   else
1336     cairo_set_source (cr, style->background[state_type]);
1337
1338   cairo_rectangle (cr, x, y, width, height);
1339   cairo_fill (cr);
1340
1341 out:
1342   cairo_restore (cr);
1343 }
1344
1345 static GdkPixbuf *
1346 gtk_default_render_icon (GtkStyle            *style,
1347                          const GtkIconSource *source,
1348                          GtkTextDirection     direction,
1349                          GtkStateType         state,
1350                          GtkIconSize          size,
1351                          GtkWidget           *widget,
1352                          const gchar         *detail)
1353 {
1354   GtkStyleContext *context;
1355   GtkStylePrivate *priv;
1356   GtkStateFlags flags = 0;
1357   GdkPixbuf *pixbuf;
1358
1359   if (widget)
1360     context = gtk_widget_get_style_context (widget);
1361   else
1362     {
1363       priv = GTK_STYLE_GET_PRIVATE (style);
1364       context = priv->context;
1365     }
1366
1367   if (!context)
1368     return NULL;
1369
1370   gtk_style_context_save (context);
1371
1372   if (detail)
1373     transform_detail_string (detail, context);
1374
1375   switch (state)
1376     {
1377     case GTK_STATE_PRELIGHT:
1378       flags |= GTK_STATE_FLAG_PRELIGHT;
1379       break;
1380     case GTK_STATE_INSENSITIVE:
1381       flags |= GTK_STATE_FLAG_INSENSITIVE;
1382       break;
1383     default:
1384       break;
1385     }
1386
1387   gtk_style_context_set_state (context, flags);
1388
1389   pixbuf = gtk_render_icon_pixbuf (context, source, size);
1390
1391   gtk_style_context_restore (context);
1392
1393   return pixbuf;
1394 }
1395
1396 static void
1397 _cairo_draw_line (cairo_t  *cr,
1398                   GdkColor *color,
1399                   gint      x1,
1400                   gint      y1,
1401                   gint      x2,
1402                   gint      y2)
1403 {
1404   cairo_save (cr);
1405
1406   gdk_cairo_set_source_color (cr, color);
1407   cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
1408
1409   cairo_move_to (cr, x1 + 0.5, y1 + 0.5);
1410   cairo_line_to (cr, x2 + 0.5, y2 + 0.5);
1411   cairo_stroke (cr);
1412
1413   cairo_restore (cr);
1414 }
1415
1416 static void
1417 transform_detail_string (const gchar     *detail,
1418                          GtkStyleContext *context)
1419 {
1420   if (!detail)
1421     return;
1422
1423   if (strcmp (detail, "arrow") == 0)
1424     gtk_style_context_add_class (context, "arrow");
1425   else if (strcmp (detail, "button") == 0)
1426     gtk_style_context_add_class (context, "button");
1427   else if (strcmp (detail, "buttondefault") == 0)
1428     {
1429       gtk_style_context_add_class (context, "button");
1430       gtk_style_context_add_class (context, "default");
1431     }
1432   else if (strcmp (detail, "calendar") == 0)
1433     gtk_style_context_add_class (context, "calendar");
1434   else if (strcmp (detail, "cellcheck") == 0)
1435     {
1436       gtk_style_context_add_class (context, "cell");
1437       gtk_style_context_add_class (context, "check");
1438     }
1439   else if (strcmp (detail, "cellradio") == 0)
1440     {
1441       gtk_style_context_add_class (context, "cell");
1442       gtk_style_context_add_class (context, "radio");
1443     }
1444   else if (strcmp (detail, "checkbutton") == 0)
1445     gtk_style_context_add_class (context, "check");
1446   else if (strcmp (detail, "check") == 0)
1447     {
1448       gtk_style_context_add_class (context, "check");
1449       gtk_style_context_add_class (context, "menu");
1450     }
1451   else if (strcmp (detail, "radiobutton") == 0)
1452     {
1453       gtk_style_context_add_class (context, "radio");
1454     }
1455   else if (strcmp (detail, "option") == 0)
1456     {
1457       gtk_style_context_add_class (context, "radio");
1458       gtk_style_context_add_class (context, "menu");
1459     }
1460   else if (strcmp (detail, "entry") == 0 ||
1461            strcmp (detail, "entry_bg") == 0)
1462     gtk_style_context_add_class (context, "entry");
1463   else if (strcmp (detail, "expander") == 0)
1464     gtk_style_context_add_class (context, "expander");
1465   else if (strcmp (detail, "tooltip") == 0)
1466     gtk_style_context_add_class (context, "tooltip");
1467   else if (strcmp (detail, "frame") == 0)
1468     gtk_style_context_add_class (context, "frame");
1469   else if (strcmp (detail, "scrolled_window") == 0)
1470     gtk_style_context_add_class (context, "scrolled-window");
1471   else if (strcmp (detail, "viewport") == 0 ||
1472            strcmp (detail, "viewportbin") == 0)
1473     gtk_style_context_add_class (context, "viewport");
1474   else if (strncmp (detail, "trough", 6) == 0)
1475     gtk_style_context_add_class (context, "trough");
1476   else if (strcmp (detail, "spinbutton") == 0)
1477     gtk_style_context_add_class (context, "spinbutton");
1478   else if (strcmp (detail, "spinbutton_up") == 0)
1479     {
1480       gtk_style_context_add_class (context, "spinbutton");
1481       gtk_style_context_add_class (context, "button");
1482       gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
1483     }
1484   else if (strcmp (detail, "spinbutton_down") == 0)
1485     {
1486       gtk_style_context_add_class (context, "spinbutton");
1487       gtk_style_context_add_class (context, "button");
1488       gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
1489     }
1490   else if ((detail[0] == 'h' || detail[0] == 'v') &&
1491            strncmp (&detail[1], "scrollbar_", 10) == 0)
1492     {
1493       gtk_style_context_add_class (context, "button");
1494       gtk_style_context_add_class (context, "scrollbar");
1495     }
1496   else if (strcmp (detail, "slider") == 0)
1497     {
1498       gtk_style_context_add_class (context, "slider");
1499       gtk_style_context_add_class (context, "scrollbar");
1500     }
1501   else if (strcmp (detail, "vscale") == 0 ||
1502            strcmp (detail, "hscale") == 0)
1503     {
1504       gtk_style_context_add_class (context, "slider");
1505       gtk_style_context_add_class (context, "scale");
1506     }
1507   else if (strcmp (detail, "menuitem") == 0)
1508     {
1509       gtk_style_context_add_class (context, "menuitem");
1510       gtk_style_context_add_class (context, "menu");
1511     }
1512   else if (strcmp (detail, "menu") == 0)
1513     {
1514       gtk_style_context_add_class (context, "popup");
1515       gtk_style_context_add_class (context, "menu");
1516     }
1517   else if (strcmp (detail, "accellabel") == 0)
1518     gtk_style_context_add_class (context, "accelerator");
1519   else if (strcmp (detail, "menubar") == 0)
1520     gtk_style_context_add_class (context, "menubar");
1521   else if (strcmp (detail, "base") == 0)
1522     gtk_style_context_add_class (context, "background");
1523   else if (strcmp (detail, "bar") == 0 ||
1524            strcmp (detail, "progressbar") == 0)
1525     gtk_style_context_add_class (context, "progressbar");
1526   else if (strcmp (detail, "toolbar") == 0)
1527     gtk_style_context_add_class (context, "toolbar");
1528   else if (strcmp (detail, "handlebox_bin") == 0)
1529     gtk_style_context_add_class (context, "dock");
1530   else if (strcmp (detail, "notebook") == 0)
1531     gtk_style_context_add_class (context, "notebook");
1532   else if (strcmp (detail, "tab") == 0)
1533     {
1534       gtk_style_context_add_class (context, "notebook");
1535       gtk_style_context_add_region (context, GTK_STYLE_REGION_TAB, 0);
1536     }
1537   else if (g_str_has_prefix (detail, "cell"))
1538     {
1539       GtkRegionFlags row, col;
1540       gboolean ruled = FALSE;
1541       GStrv tokens;
1542       guint i;
1543
1544       tokens = g_strsplit (detail, "_", -1);
1545       row = col = 0;
1546       i = 0;
1547
1548       while (tokens[i])
1549         {
1550           if (strcmp (tokens[i], "even") == 0)
1551             row |= GTK_REGION_EVEN;
1552           else if (strcmp (tokens[i], "odd") == 0)
1553             row |= GTK_REGION_ODD;
1554           else if (strcmp (tokens[i], "start") == 0)
1555             col |= GTK_REGION_FIRST;
1556           else if (strcmp (tokens[i], "end") == 0)
1557             col |= GTK_REGION_LAST;
1558           else if (strcmp (tokens[i], "ruled") == 0)
1559             ruled = TRUE;
1560           else if (strcmp (tokens[i], "sorted") == 0)
1561             col |= GTK_REGION_SORTED;
1562
1563           i++;
1564         }
1565
1566       if (!ruled)
1567         row &= ~(GTK_REGION_EVEN | GTK_REGION_ODD);
1568
1569       gtk_style_context_add_class (context, "cell");
1570       gtk_style_context_add_region (context, "row", row);
1571       gtk_style_context_add_region (context, "column", col);
1572
1573       g_strfreev (tokens);
1574     }
1575 }
1576
1577 static void
1578 gtk_default_draw_hline (GtkStyle     *style,
1579                         cairo_t       *cr,
1580                         GtkStateType  state_type,
1581                         GtkWidget     *widget,
1582                         const gchar   *detail,
1583                         gint          x1,
1584                         gint          x2,
1585                         gint          y)
1586 {
1587   GtkStyleContext *context;
1588   GtkStylePrivate *priv;
1589
1590   if (widget)
1591     context = gtk_widget_get_style_context (widget);
1592   else
1593     {
1594       priv = GTK_STYLE_GET_PRIVATE (style);
1595       context = priv->context;
1596     }
1597
1598   gtk_style_context_save (context);
1599
1600   if (detail)
1601     transform_detail_string (detail, context);
1602
1603   cairo_save (cr);
1604
1605   gtk_render_line (context, cr,
1606                    x1, y, x2, y);
1607
1608   cairo_restore (cr);
1609
1610   gtk_style_context_restore (context);
1611 }
1612
1613
1614 static void
1615 gtk_default_draw_vline (GtkStyle      *style,
1616                         cairo_t       *cr,
1617                         GtkStateType  state_type,
1618                         GtkWidget     *widget,
1619                         const gchar   *detail,
1620                         gint          y1,
1621                         gint          y2,
1622                         gint          x)
1623 {
1624   GtkStyleContext *context;
1625   GtkStylePrivate *priv;
1626
1627   if (widget)
1628     context = gtk_widget_get_style_context (widget);
1629   else
1630     {
1631       priv = GTK_STYLE_GET_PRIVATE (style);
1632       context = priv->context;
1633     }
1634
1635   gtk_style_context_save (context);
1636
1637   if (detail)
1638     transform_detail_string (detail, context);
1639
1640   cairo_save (cr);
1641
1642   gtk_render_line (context, cr,
1643                    x, y1, x, y2);
1644
1645   cairo_restore (cr);
1646   gtk_style_context_restore (context);
1647 }
1648
1649 static void
1650 gtk_default_draw_shadow (GtkStyle      *style,
1651                          cairo_t       *cr,
1652                          GtkStateType   state_type,
1653                          GtkShadowType  shadow_type,
1654                          GtkWidget     *widget,
1655                          const gchar   *detail,
1656                          gint           x,
1657                          gint           y,
1658                          gint           width,
1659                          gint           height)
1660 {
1661   GtkStyleContext *context;
1662   GtkStylePrivate *priv;
1663
1664   if (shadow_type == GTK_SHADOW_NONE)
1665     return;
1666
1667   if (widget)
1668     context = gtk_widget_get_style_context (widget);
1669   else
1670     {
1671       priv = GTK_STYLE_GET_PRIVATE (style);
1672       context = priv->context;
1673     }
1674
1675   gtk_style_context_save (context);
1676
1677   if (detail)
1678     transform_detail_string (detail, context);
1679
1680   cairo_save (cr);
1681
1682   gtk_render_frame (context, cr,
1683                     (gdouble) x,
1684                     (gdouble) y,
1685                     (gdouble) width,
1686                     (gdouble) height);
1687
1688   cairo_restore (cr);
1689   gtk_style_context_restore (context);
1690 }
1691
1692 static void
1693 draw_arrow (cairo_t       *cr,
1694             GdkColor      *color,
1695             GtkArrowType   arrow_type,
1696             gint           x,
1697             gint           y,
1698             gint           width,
1699             gint           height)
1700 {
1701   gdk_cairo_set_source_color (cr, color);
1702   cairo_save (cr);
1703     
1704   if (arrow_type == GTK_ARROW_DOWN)
1705     {
1706       cairo_move_to (cr, x,              y);
1707       cairo_line_to (cr, x + width,      y);
1708       cairo_line_to (cr, x + width / 2., y + height);
1709     }
1710   else if (arrow_type == GTK_ARROW_UP)
1711     {
1712       cairo_move_to (cr, x,              y + height);
1713       cairo_line_to (cr, x + width / 2., y);
1714       cairo_line_to (cr, x + width,      y + height);
1715     }
1716   else if (arrow_type == GTK_ARROW_LEFT)
1717     {
1718       cairo_move_to (cr, x + width,      y);
1719       cairo_line_to (cr, x + width,      y + height);
1720       cairo_line_to (cr, x,              y + height / 2.);
1721     }
1722   else if (arrow_type == GTK_ARROW_RIGHT)
1723     {
1724       cairo_move_to (cr, x,              y);
1725       cairo_line_to (cr, x + width,      y + height / 2.);
1726       cairo_line_to (cr, x,              y + height);
1727     }
1728
1729   cairo_close_path (cr);
1730   cairo_fill (cr);
1731
1732   cairo_restore (cr);
1733 }
1734
1735 static void
1736 gtk_default_draw_arrow (GtkStyle      *style,
1737                         cairo_t       *cr,
1738                         GtkStateType   state,
1739                         GtkShadowType  shadow,
1740                         GtkWidget     *widget,
1741                         const gchar   *detail,
1742                         GtkArrowType   arrow_type,
1743                         gboolean       fill,
1744                         gint           x,
1745                         gint           y,
1746                         gint           width,
1747                         gint           height)
1748 {
1749   GtkStyleContext *context;
1750   GtkStylePrivate *priv;
1751   GtkStateFlags flags = 0;
1752   gdouble angle, size;
1753
1754   if (arrow_type == GTK_ARROW_NONE)
1755     return;
1756
1757   if (widget)
1758     context = gtk_widget_get_style_context (widget);
1759   else
1760     {
1761       priv = GTK_STYLE_GET_PRIVATE (style);
1762       context = priv->context;
1763     }
1764
1765   gtk_style_context_save (context);
1766
1767   if (detail)
1768     transform_detail_string (detail, context);
1769
1770   switch (arrow_type)
1771     {
1772     case GTK_ARROW_UP:
1773       angle = 0;
1774       size = width;
1775       break;
1776     case GTK_ARROW_RIGHT:
1777       angle = G_PI / 2;
1778       size = height;
1779       break;
1780     case GTK_ARROW_DOWN:
1781       angle = G_PI;
1782       size = width;
1783       break;
1784     case GTK_ARROW_LEFT:
1785       angle = 3 * (G_PI / 2);
1786       size = height;
1787       break;
1788     default:
1789       g_assert_not_reached ();
1790     }
1791
1792   switch (state)
1793     {
1794     case GTK_STATE_PRELIGHT:
1795       flags |= GTK_STATE_FLAG_PRELIGHT;
1796       break;
1797     case GTK_STATE_SELECTED:
1798       flags |= GTK_STATE_FLAG_SELECTED;
1799       break;
1800     case GTK_STATE_INSENSITIVE:
1801       flags |= GTK_STATE_FLAG_INSENSITIVE;
1802       break;
1803     case GTK_STATE_ACTIVE:
1804       flags |= GTK_STATE_FLAG_ACTIVE;
1805       break;
1806     default:
1807       break;
1808     }
1809
1810   gtk_style_context_set_state (context, flags);
1811
1812   cairo_save (cr);
1813
1814   gtk_render_arrow (context,
1815                     cr, angle,
1816                     (gdouble) x,
1817                     (gdouble) y,
1818                     size);
1819
1820   cairo_restore (cr);
1821   gtk_style_context_restore (context);
1822 }
1823
1824 static void
1825 gtk_default_draw_diamond (GtkStyle      *style,
1826                           cairo_t       *cr,
1827                           GtkStateType   state_type,
1828                           GtkShadowType  shadow_type,
1829                           GtkWidget     *widget,
1830                           const gchar   *detail,
1831                           gint           x,
1832                           gint           y,
1833                           gint           width,
1834                           gint           height)
1835 {
1836   gint half_width;
1837   gint half_height;
1838   GdkColor *outer_nw = NULL;
1839   GdkColor *outer_ne = NULL;
1840   GdkColor *outer_sw = NULL;
1841   GdkColor *outer_se = NULL;
1842   GdkColor *middle_nw = NULL;
1843   GdkColor *middle_ne = NULL;
1844   GdkColor *middle_sw = NULL;
1845   GdkColor *middle_se = NULL;
1846   GdkColor *inner_nw = NULL;
1847   GdkColor *inner_ne = NULL;
1848   GdkColor *inner_sw = NULL;
1849   GdkColor *inner_se = NULL;
1850   
1851   half_width = width / 2;
1852   half_height = height / 2;
1853   
1854   switch (shadow_type)
1855     {
1856     case GTK_SHADOW_IN:
1857       inner_sw = inner_se = &style->bg[state_type];
1858       middle_sw = middle_se = &style->light[state_type];
1859       outer_sw = outer_se = &style->light[state_type];
1860       inner_nw = inner_ne = &style->black;
1861       middle_nw = middle_ne = &style->dark[state_type];
1862       outer_nw = outer_ne = &style->dark[state_type];
1863       break;
1864           
1865     case GTK_SHADOW_OUT:
1866       inner_sw = inner_se = &style->dark[state_type];
1867       middle_sw = middle_se = &style->dark[state_type];
1868       outer_sw = outer_se = &style->black;
1869       inner_nw = inner_ne = &style->bg[state_type];
1870       middle_nw = middle_ne = &style->light[state_type];
1871       outer_nw = outer_ne = &style->light[state_type];
1872       break;
1873
1874     case GTK_SHADOW_ETCHED_IN:
1875       inner_sw = inner_se = &style->bg[state_type];
1876       middle_sw = middle_se = &style->dark[state_type];
1877       outer_sw = outer_se = &style->light[state_type];
1878       inner_nw = inner_ne = &style->bg[state_type];
1879       middle_nw = middle_ne = &style->light[state_type];
1880       outer_nw = outer_ne = &style->dark[state_type];
1881       break;
1882
1883     case GTK_SHADOW_ETCHED_OUT:
1884       inner_sw = inner_se = &style->bg[state_type];
1885       middle_sw = middle_se = &style->light[state_type];
1886       outer_sw = outer_se = &style->dark[state_type];
1887       inner_nw = inner_ne = &style->bg[state_type];
1888       middle_nw = middle_ne = &style->dark[state_type];
1889       outer_nw = outer_ne = &style->light[state_type];
1890       break;
1891       
1892     default:
1893
1894       break;
1895     }
1896
1897   if (inner_sw)
1898     {
1899       _cairo_draw_line (cr, inner_sw,
1900                         x + 2, y + half_height,
1901                         x + half_width, y + height - 2);
1902       _cairo_draw_line (cr, inner_se,
1903                         x + half_width, y + height - 2,
1904                         x + width - 2, y + half_height);
1905       _cairo_draw_line (cr, middle_sw,
1906                         x + 1, y + half_height,
1907                         x + half_width, y + height - 1);
1908       _cairo_draw_line (cr, middle_se,
1909                         x + half_width, y + height - 1,
1910                         x + width - 1, y + half_height);
1911       _cairo_draw_line (cr, outer_sw,
1912                         x, y + half_height,
1913                         x + half_width, y + height);
1914       _cairo_draw_line (cr, outer_se,
1915                         x + half_width, y + height,
1916                         x + width, y + half_height);
1917   
1918       _cairo_draw_line (cr, inner_nw,
1919                         x + 2, y + half_height,
1920                         x + half_width, y + 2);
1921       _cairo_draw_line (cr, inner_ne,
1922                         x + half_width, y + 2,
1923                         x + width - 2, y + half_height);
1924       _cairo_draw_line (cr, middle_nw,
1925                         x + 1, y + half_height,
1926                         x + half_width, y + 1);
1927       _cairo_draw_line (cr, middle_ne,
1928                         x + half_width, y + 1,
1929                         x + width - 1, y + half_height);
1930       _cairo_draw_line (cr, outer_nw,
1931                         x, y + half_height,
1932                         x + half_width, y);
1933       _cairo_draw_line (cr, outer_ne,
1934                         x + half_width, y,
1935                         x + width, y + half_height);
1936     }
1937 }
1938
1939 static void
1940 option_menu_get_props (GtkWidget      *widget,
1941                        GtkRequisition *indicator_size,
1942                        GtkBorder      *indicator_spacing)
1943 {
1944   GtkRequisition *tmp_size = NULL;
1945   GtkBorder *tmp_spacing = NULL;
1946
1947   if (tmp_size)
1948     {
1949       *indicator_size = *tmp_size;
1950       gtk_requisition_free (tmp_size);
1951     }
1952   else
1953     *indicator_size = default_option_indicator_size;
1954
1955   if (tmp_spacing)
1956     {
1957       *indicator_spacing = *tmp_spacing;
1958       gtk_border_free (tmp_spacing);
1959     }
1960   else
1961     *indicator_spacing = default_option_indicator_spacing;
1962 }
1963
1964 static void 
1965 gtk_default_draw_box (GtkStyle      *style,
1966                       cairo_t       *cr,
1967                       GtkStateType   state_type,
1968                       GtkShadowType  shadow_type,
1969                       GtkWidget     *widget,
1970                       const gchar   *detail,
1971                       gint           x,
1972                       gint           y,
1973                       gint           width,
1974                       gint           height)
1975 {
1976   GtkStyleContext *context;
1977   GtkStylePrivate *priv;
1978   GtkStateFlags flags = 0;
1979
1980   if (widget)
1981     context = gtk_widget_get_style_context (widget);
1982   else
1983     {
1984       priv = GTK_STYLE_GET_PRIVATE (style);
1985       context = priv->context;
1986     }
1987
1988   gtk_style_context_save (context);
1989
1990   if (detail)
1991     transform_detail_string (detail, context);
1992
1993   switch (state_type)
1994     {
1995     case GTK_STATE_ACTIVE:
1996       flags |= GTK_STATE_FLAG_ACTIVE;
1997       break;
1998     case GTK_STATE_PRELIGHT:
1999       flags |= GTK_STATE_FLAG_PRELIGHT;
2000       break;
2001     case GTK_STATE_SELECTED:
2002       flags |= GTK_STATE_FLAG_SELECTED;
2003       break;
2004     case GTK_STATE_INSENSITIVE:
2005       flags |= GTK_STATE_FLAG_INSENSITIVE;
2006       break;
2007     default:
2008       break;
2009     }
2010
2011   if (shadow_type == GTK_SHADOW_IN)
2012     flags |= GTK_STATE_FLAG_ACTIVE;
2013
2014   gtk_style_context_set_state (context, flags);
2015
2016   cairo_save (cr);
2017
2018   if (gtk_style_context_has_class (context, GTK_STYLE_CLASS_PROGRESSBAR))
2019     gtk_render_activity (context, cr, x, y, width, height);
2020   else
2021     {
2022       gtk_render_background (context, cr, x, y, width, height);
2023
2024       if (shadow_type != GTK_SHADOW_NONE)
2025         gtk_render_frame (context, cr, x, y, width, height);
2026     }
2027
2028   cairo_restore (cr);
2029   gtk_style_context_restore (context);
2030 }
2031
2032 static void 
2033 gtk_default_draw_flat_box (GtkStyle      *style,
2034                            cairo_t       *cr,
2035                            GtkStateType   state_type,
2036                            GtkShadowType  shadow_type,
2037                            GtkWidget     *widget,
2038                            const gchar   *detail,
2039                            gint           x,
2040                            gint           y,
2041                            gint           width,
2042                            gint           height)
2043 {
2044   GtkStyleContext *context;
2045   GtkStylePrivate *priv;
2046   GtkStateFlags flags = 0;
2047
2048   if (widget)
2049     context = gtk_widget_get_style_context (widget);
2050   else
2051     {
2052       priv = GTK_STYLE_GET_PRIVATE (style);
2053       context = priv->context;
2054     }
2055
2056   gtk_style_context_save (context);
2057
2058   if (detail)
2059     transform_detail_string (detail, context);
2060
2061   switch (state_type)
2062     {
2063     case GTK_STATE_PRELIGHT:
2064       flags |= GTK_STATE_FLAG_PRELIGHT;
2065       break;
2066     case GTK_STATE_SELECTED:
2067       flags |= GTK_STATE_FLAG_SELECTED;
2068       break;
2069     case GTK_STATE_INSENSITIVE:
2070       flags |= GTK_STATE_FLAG_INSENSITIVE;
2071       break;
2072     case GTK_STATE_ACTIVE:
2073       flags |= GTK_STATE_FLAG_ACTIVE;
2074       break;
2075     case GTK_STATE_FOCUSED:
2076       flags |= GTK_STATE_FLAG_FOCUSED;
2077       break;
2078     default:
2079       break;
2080     }
2081
2082   gtk_style_context_set_state (context, flags);
2083
2084   cairo_save (cr);
2085
2086   gtk_render_background (context, cr,
2087                          (gdouble) x,
2088                          (gdouble) y,
2089                          (gdouble) width,
2090                          (gdouble) height);
2091
2092   cairo_restore (cr);
2093   gtk_style_context_restore (context);
2094 }
2095
2096 static void 
2097 gtk_default_draw_check (GtkStyle      *style,
2098                         cairo_t       *cr,
2099                         GtkStateType   state_type,
2100                         GtkShadowType  shadow_type,
2101                         GtkWidget     *widget,
2102                         const gchar   *detail,
2103                         gint           x,
2104                         gint           y,
2105                         gint           width,
2106                         gint           height)
2107 {
2108   GtkStyleContext *context;
2109   GtkStylePrivate *priv;
2110   GtkStateFlags flags = 0;
2111
2112   if (widget)
2113     context = gtk_widget_get_style_context (widget);
2114   else
2115     {
2116       priv = GTK_STYLE_GET_PRIVATE (style);
2117       context = priv->context;
2118     }
2119
2120   gtk_style_context_save (context);
2121
2122   if (detail)
2123     transform_detail_string (detail, context);
2124
2125   switch (state_type)
2126     {
2127     case GTK_STATE_PRELIGHT:
2128       flags |= GTK_STATE_FLAG_PRELIGHT;
2129       break;
2130     case GTK_STATE_SELECTED:
2131       flags |= GTK_STATE_FLAG_SELECTED;
2132       break;
2133     case GTK_STATE_INSENSITIVE:
2134       flags |= GTK_STATE_FLAG_INSENSITIVE;
2135       break;
2136     default:
2137       break;
2138     }
2139
2140   if (shadow_type == GTK_SHADOW_IN)
2141     flags |= GTK_STATE_FLAG_ACTIVE;
2142   else if (shadow_type == GTK_SHADOW_ETCHED_IN)
2143     flags |= GTK_STATE_FLAG_INCONSISTENT;
2144
2145   gtk_style_context_set_state (context, flags);
2146
2147   cairo_save (cr);
2148
2149   gtk_render_check (context,
2150                     cr, x, y,
2151                     width, height);
2152
2153   cairo_restore (cr);
2154   gtk_style_context_restore (context);
2155 }
2156
2157 static void 
2158 gtk_default_draw_option (GtkStyle      *style,
2159                          cairo_t       *cr,
2160                          GtkStateType   state_type,
2161                          GtkShadowType  shadow_type,
2162                          GtkWidget     *widget,
2163                          const gchar   *detail,
2164                          gint           x,
2165                          gint           y,
2166                          gint           width,
2167                          gint           height)
2168 {
2169   GtkStyleContext *context;
2170   GtkStylePrivate *priv;
2171   GtkStateFlags flags = 0;
2172
2173   if (widget)
2174     context = gtk_widget_get_style_context (widget);
2175   else
2176     {
2177       priv = GTK_STYLE_GET_PRIVATE (style);
2178       context = priv->context;
2179     }
2180
2181   gtk_style_context_save (context);
2182
2183   if (detail)
2184     transform_detail_string (detail, context);
2185
2186   switch (state_type)
2187     {
2188     case GTK_STATE_PRELIGHT:
2189       flags |= GTK_STATE_FLAG_PRELIGHT;
2190       break;
2191     case GTK_STATE_SELECTED:
2192       flags |= GTK_STATE_FLAG_SELECTED;
2193       break;
2194     case GTK_STATE_INSENSITIVE:
2195       flags |= GTK_STATE_FLAG_INSENSITIVE;
2196       break;
2197     default:
2198       break;
2199     }
2200
2201   if (shadow_type == GTK_SHADOW_IN)
2202     flags |= GTK_STATE_FLAG_ACTIVE;
2203   else if (shadow_type == GTK_SHADOW_ETCHED_IN)
2204     flags |= GTK_STATE_FLAG_INCONSISTENT;
2205
2206   gtk_style_context_set_state (context, flags);
2207
2208   cairo_save (cr);
2209   gtk_render_option (context, cr,
2210                      (gdouble) x,
2211                      (gdouble) y,
2212                      (gdouble) width,
2213                      (gdouble) height);
2214
2215   cairo_restore (cr);
2216   gtk_style_context_restore (context);
2217 }
2218
2219 static void
2220 gtk_default_draw_tab (GtkStyle      *style,
2221                       cairo_t       *cr,
2222                       GtkStateType   state_type,
2223                       GtkShadowType  shadow_type,
2224                       GtkWidget     *widget,
2225                       const gchar   *detail,
2226                       gint           x,
2227                       gint           y,
2228                       gint           width,
2229                       gint           height)
2230 {
2231 #define ARROW_SPACE 4
2232
2233   GtkRequisition indicator_size;
2234   GtkBorder indicator_spacing;
2235   gint arrow_height;
2236
2237   option_menu_get_props (widget, &indicator_size, &indicator_spacing);
2238
2239   indicator_size.width += (indicator_size.width % 2) - 1;
2240   arrow_height = indicator_size.width / 2 + 1;
2241
2242   x += (width - indicator_size.width) / 2;
2243   y += (height - (2 * arrow_height + ARROW_SPACE)) / 2;
2244
2245   if (state_type == GTK_STATE_INSENSITIVE)
2246     {
2247       draw_arrow (cr, &style->white,
2248                   GTK_ARROW_UP, x + 1, y + 1,
2249                   indicator_size.width, arrow_height);
2250       
2251       draw_arrow (cr, &style->white,
2252                   GTK_ARROW_DOWN, x + 1, y + arrow_height + ARROW_SPACE + 1,
2253                   indicator_size.width, arrow_height);
2254     }
2255   
2256   draw_arrow (cr, &style->fg[state_type],
2257               GTK_ARROW_UP, x, y,
2258               indicator_size.width, arrow_height);
2259   
2260   
2261   draw_arrow (cr, &style->fg[state_type],
2262               GTK_ARROW_DOWN, x, y + arrow_height + ARROW_SPACE,
2263               indicator_size.width, arrow_height);
2264 }
2265
2266 static void 
2267 gtk_default_draw_shadow_gap (GtkStyle       *style,
2268                              cairo_t        *cr,
2269                              GtkStateType    state_type,
2270                              GtkShadowType   shadow_type,
2271                              GtkWidget      *widget,
2272                              const gchar    *detail,
2273                              gint            x,
2274                              gint            y,
2275                              gint            width,
2276                              gint            height,
2277                              GtkPositionType gap_side,
2278                              gint            gap_x,
2279                              gint            gap_width)
2280 {
2281   GtkStyleContext *context;
2282   GtkStylePrivate *priv;
2283   GtkStateFlags flags = 0;
2284
2285   if (shadow_type == GTK_SHADOW_NONE)
2286     return;
2287
2288   if (widget)
2289     context = gtk_widget_get_style_context (widget);
2290   else
2291     {
2292       priv = GTK_STYLE_GET_PRIVATE (style);
2293       context = priv->context;
2294     }
2295
2296   gtk_style_context_save (context);
2297
2298   if (detail)
2299     transform_detail_string (detail, context);
2300
2301   switch (state_type)
2302     {
2303     case GTK_STATE_ACTIVE:
2304       flags |= GTK_STATE_FLAG_ACTIVE;
2305       break;
2306     case GTK_STATE_PRELIGHT:
2307       flags |= GTK_STATE_FLAG_PRELIGHT;
2308       break;
2309     case GTK_STATE_SELECTED:
2310       flags |= GTK_STATE_FLAG_SELECTED;
2311       break;
2312     case GTK_STATE_INSENSITIVE:
2313       flags |= GTK_STATE_FLAG_INSENSITIVE;
2314       break;
2315     default:
2316       break;
2317     }
2318
2319   gtk_style_context_set_state (context, flags);
2320
2321   cairo_save (cr);
2322   gtk_render_frame_gap (context, cr,
2323                         (gdouble) x,
2324                         (gdouble) y,
2325                         (gdouble) width,
2326                         (gdouble) height,
2327                         gap_side,
2328                         (gdouble) gap_x,
2329                         (gdouble) gap_x + gap_width);
2330
2331   cairo_restore (cr);
2332   gtk_style_context_restore (context);
2333 }
2334
2335 static void 
2336 gtk_default_draw_box_gap (GtkStyle       *style,
2337                           cairo_t        *cr,
2338                           GtkStateType    state_type,
2339                           GtkShadowType   shadow_type,
2340                           GtkWidget      *widget,
2341                           const gchar    *detail,
2342                           gint            x,
2343                           gint            y,
2344                           gint            width,
2345                           gint            height,
2346                           GtkPositionType gap_side,
2347                           gint            gap_x,
2348                           gint            gap_width)
2349 {
2350   GtkStyleContext *context;
2351   GtkStylePrivate *priv;
2352   GtkStateFlags flags = 0;
2353
2354   if (widget)
2355     context = gtk_widget_get_style_context (widget);
2356   else
2357     {
2358       priv = GTK_STYLE_GET_PRIVATE (style);
2359       context = priv->context;
2360     }
2361
2362   gtk_style_context_save (context);
2363
2364   if (detail)
2365     transform_detail_string (detail, context);
2366
2367   switch (state_type)
2368     {
2369     case GTK_STATE_ACTIVE:
2370       flags |= GTK_STATE_FLAG_ACTIVE;
2371       break;
2372     case GTK_STATE_PRELIGHT:
2373       flags |= GTK_STATE_FLAG_PRELIGHT;
2374       break;
2375     case GTK_STATE_SELECTED:
2376       flags |= GTK_STATE_FLAG_SELECTED;
2377       break;
2378     case GTK_STATE_INSENSITIVE:
2379       flags |= GTK_STATE_FLAG_INSENSITIVE;
2380       break;
2381     default:
2382       break;
2383     }
2384
2385   gtk_style_context_set_state (context, flags);
2386
2387   cairo_save (cr);
2388   gtk_render_background (context, cr,
2389                          (gdouble) x,
2390                          (gdouble) y,
2391                          (gdouble) width,
2392                          (gdouble) height);
2393
2394
2395   if (shadow_type != GTK_SHADOW_NONE)
2396     gtk_render_frame_gap (context, cr,
2397                           (gdouble) x,
2398                           (gdouble) y,
2399                           (gdouble) width,
2400                           (gdouble) height,
2401                           gap_side,
2402                           (gdouble) gap_x,
2403                           (gdouble) gap_x + gap_width);
2404   
2405   cairo_restore (cr);
2406   gtk_style_context_restore (context);
2407 }
2408
2409 static void 
2410 gtk_default_draw_extension (GtkStyle       *style,
2411                             cairo_t        *cr,
2412                             GtkStateType    state_type,
2413                             GtkShadowType   shadow_type,
2414                             GtkWidget      *widget,
2415                             const gchar    *detail,
2416                             gint            x,
2417                             gint            y,
2418                             gint            width,
2419                             gint            height,
2420                             GtkPositionType gap_side)
2421 {
2422   GtkStyleContext *context;
2423   GtkStylePrivate *priv;
2424   GtkStateFlags flags = 0;
2425
2426   if (widget)
2427     context = gtk_widget_get_style_context (widget);
2428   else
2429     {
2430       priv = GTK_STYLE_GET_PRIVATE (style);
2431       context = priv->context;
2432     }
2433
2434   gtk_style_context_save (context);
2435
2436   if (detail)
2437     transform_detail_string (detail, context);
2438
2439   switch (state_type)
2440     {
2441     case GTK_STATE_ACTIVE:
2442       flags |= GTK_STATE_FLAG_ACTIVE;
2443       break;
2444     case GTK_STATE_PRELIGHT:
2445       flags |= GTK_STATE_FLAG_PRELIGHT;
2446       break;
2447     case GTK_STATE_SELECTED:
2448       flags |= GTK_STATE_FLAG_SELECTED;
2449       break;
2450     case GTK_STATE_INSENSITIVE:
2451       flags |= GTK_STATE_FLAG_INSENSITIVE;
2452       break;
2453     default:
2454       break;
2455     }
2456
2457   gtk_style_context_set_state (context, flags);
2458
2459   cairo_save (cr);
2460
2461   gtk_render_extension (context, cr,
2462                         (gdouble) x,
2463                         (gdouble) y,
2464                         (gdouble) width,
2465                         (gdouble) height,
2466                         gap_side);
2467
2468   cairo_restore (cr);
2469   gtk_style_context_restore (context);
2470 }
2471
2472 static void 
2473 gtk_default_draw_focus (GtkStyle      *style,
2474                         cairo_t       *cr,
2475                         GtkStateType   state_type,
2476                         GtkWidget     *widget,
2477                         const gchar   *detail,
2478                         gint           x,
2479                         gint           y,
2480                         gint           width,
2481                         gint           height)
2482 {
2483   GtkStyleContext *context;
2484   GtkStylePrivate *priv;
2485
2486   if (widget)
2487     context = gtk_widget_get_style_context (widget);
2488   else
2489     {
2490       priv = GTK_STYLE_GET_PRIVATE (style);
2491       context = priv->context;
2492     }
2493
2494   gtk_style_context_save (context);
2495
2496   if (detail)
2497     transform_detail_string (detail, context);
2498
2499   cairo_save (cr);
2500
2501   gtk_render_focus (context, cr,
2502                     (gdouble) x,
2503                     (gdouble) y,
2504                     (gdouble) width,
2505                     (gdouble) height);
2506
2507   cairo_restore (cr);
2508   gtk_style_context_restore (context);
2509 }
2510
2511 static void 
2512 gtk_default_draw_slider (GtkStyle      *style,
2513                          cairo_t       *cr,
2514                          GtkStateType   state_type,
2515                          GtkShadowType  shadow_type,
2516                          GtkWidget     *widget,
2517                          const gchar   *detail,
2518                          gint           x,
2519                          gint           y,
2520                          gint           width,
2521                          gint           height,
2522                          GtkOrientation orientation)
2523 {
2524   GtkStyleContext *context;
2525   GtkStylePrivate *priv;
2526   GtkStateFlags flags = 0;
2527
2528   if (widget)
2529     context = gtk_widget_get_style_context (widget);
2530   else
2531     {
2532       priv = GTK_STYLE_GET_PRIVATE (style);
2533       context = priv->context;
2534     }
2535
2536   gtk_style_context_save (context);
2537
2538   if (detail)
2539     transform_detail_string (detail, context);
2540
2541   switch (state_type)
2542     {
2543     case GTK_STATE_PRELIGHT:
2544       flags |= GTK_STATE_FLAG_PRELIGHT;
2545       break;
2546     case GTK_STATE_SELECTED:
2547       flags |= GTK_STATE_FLAG_SELECTED;
2548       break;
2549     case GTK_STATE_INSENSITIVE:
2550       flags |= GTK_STATE_FLAG_INSENSITIVE;
2551       break;
2552     default:
2553       break;
2554     }
2555
2556   gtk_style_context_set_state (context, flags);
2557
2558   cairo_save (cr);
2559
2560   gtk_render_slider (context, cr,  x, y, width, height, orientation);
2561
2562   cairo_restore (cr);
2563   gtk_style_context_restore (context);
2564 }
2565
2566 static void 
2567 gtk_default_draw_handle (GtkStyle      *style,
2568                          cairo_t       *cr,
2569                          GtkStateType   state_type,
2570                          GtkShadowType  shadow_type,
2571                          GtkWidget     *widget,
2572                          const gchar   *detail,
2573                          gint           x,
2574                          gint           y,
2575                          gint           width,
2576                          gint           height,
2577                          GtkOrientation orientation)
2578 {
2579   GtkStyleContext *context;
2580   GtkStylePrivate *priv;
2581   GtkStateFlags flags = 0;
2582
2583   if (widget)
2584     context = gtk_widget_get_style_context (widget);
2585   else
2586     {
2587       priv = GTK_STYLE_GET_PRIVATE (style);
2588       context = priv->context;
2589     }
2590
2591   gtk_style_context_save (context);
2592
2593   if (detail)
2594     transform_detail_string (detail, context);
2595
2596   switch (state_type)
2597     {
2598     case GTK_STATE_PRELIGHT:
2599       flags |= GTK_STATE_FLAG_PRELIGHT;
2600       break;
2601     case GTK_STATE_SELECTED:
2602       flags |= GTK_STATE_FLAG_SELECTED;
2603       break;
2604     case GTK_STATE_INSENSITIVE:
2605       flags |= GTK_STATE_FLAG_INSENSITIVE;
2606       break;
2607     default:
2608       break;
2609     }
2610
2611   gtk_style_context_set_state (context, flags);
2612
2613   cairo_save (cr);
2614
2615   gtk_render_handle (context, cr,
2616                      (gdouble) x,
2617                      (gdouble) y,
2618                      (gdouble) width,
2619                      (gdouble) height);
2620
2621   cairo_restore (cr);
2622   gtk_style_context_restore (context);
2623 }
2624
2625 static void
2626 gtk_default_draw_expander (GtkStyle        *style,
2627                            cairo_t         *cr,
2628                            GtkStateType     state_type,
2629                            GtkWidget       *widget,
2630                            const gchar     *detail,
2631                            gint             x,
2632                            gint             y,
2633                            GtkExpanderStyle expander_style)
2634 {
2635   GtkStyleContext *context;
2636   GtkStylePrivate *priv;
2637   GtkStateFlags flags = 0;
2638   gint size;
2639
2640   if (widget)
2641     context = gtk_widget_get_style_context (widget);
2642   else
2643     {
2644       priv = GTK_STYLE_GET_PRIVATE (style);
2645       context = priv->context;
2646     }
2647
2648   gtk_style_context_save (context);
2649
2650   if (detail)
2651     transform_detail_string (detail, context);
2652
2653   gtk_style_context_add_class (context, "expander");
2654
2655   switch (state_type)
2656     {
2657     case GTK_STATE_PRELIGHT:
2658       flags |= GTK_STATE_FLAG_PRELIGHT;
2659       break;
2660     case GTK_STATE_SELECTED:
2661       flags |= GTK_STATE_FLAG_SELECTED;
2662       break;
2663     case GTK_STATE_INSENSITIVE:
2664       flags |= GTK_STATE_FLAG_INSENSITIVE;
2665       break;
2666     default:
2667       break;
2668     }
2669
2670   if (widget &&
2671       gtk_widget_class_find_style_property (GTK_WIDGET_GET_CLASS (widget),
2672                                             "expander-size"))
2673     gtk_widget_style_get (widget, "expander-size", &size, NULL);
2674   else
2675     size = 12;
2676
2677   if (expander_style == GTK_EXPANDER_EXPANDED)
2678     flags |= GTK_STATE_FLAG_ACTIVE;
2679
2680   gtk_style_context_set_state (context, flags);
2681
2682   cairo_save (cr);
2683
2684   gtk_render_expander (context, cr,
2685                        (gdouble) x - (size / 2),
2686                        (gdouble) y - (size / 2),
2687                        (gdouble) size,
2688                        (gdouble) size);
2689
2690   cairo_restore (cr);
2691   gtk_style_context_restore (context);
2692 }
2693
2694 static void
2695 gtk_default_draw_layout (GtkStyle        *style,
2696                          cairo_t         *cr,
2697                          GtkStateType     state_type,
2698                          gboolean         use_text,
2699                          GtkWidget       *widget,
2700                          const gchar     *detail,
2701                          gint             x,
2702                          gint             y,
2703                          PangoLayout     *layout)
2704 {
2705   GtkStyleContext *context;
2706   GtkStylePrivate *priv;
2707   GtkStateFlags flags = 0;
2708
2709   if (widget)
2710     context = gtk_widget_get_style_context (widget);
2711   else
2712     {
2713       priv = GTK_STYLE_GET_PRIVATE (style);
2714       context = priv->context;
2715     }
2716
2717   gtk_style_context_save (context);
2718
2719   if (detail)
2720     transform_detail_string (detail, context);
2721
2722   switch (state_type)
2723     {
2724     case GTK_STATE_PRELIGHT:
2725       flags |= GTK_STATE_FLAG_PRELIGHT;
2726       break;
2727     case GTK_STATE_SELECTED:
2728       flags |= GTK_STATE_FLAG_SELECTED;
2729       break;
2730     case GTK_STATE_INSENSITIVE:
2731       flags |= GTK_STATE_FLAG_INSENSITIVE;
2732       break;
2733     default:
2734       break;
2735     }
2736
2737   gtk_style_context_set_state (context, flags);
2738
2739   cairo_save (cr);
2740
2741   gtk_render_layout (context, cr,
2742                      (gdouble) x,
2743                      (gdouble) y,
2744                      layout);
2745
2746   cairo_restore (cr);
2747   gtk_style_context_restore (context);
2748 }
2749
2750 static void
2751 gtk_default_draw_resize_grip (GtkStyle       *style,
2752                               cairo_t        *cr,
2753                               GtkStateType    state_type,
2754                               GtkWidget      *widget,
2755                               const gchar    *detail,
2756                               GdkWindowEdge   edge,
2757                               gint            x,
2758                               gint            y,
2759                               gint            width,
2760                               gint            height)
2761 {
2762   GtkStyleContext *context;
2763   GtkStylePrivate *priv;
2764   GtkStateFlags flags = 0;
2765   GtkJunctionSides sides = 0;
2766
2767   if (widget)
2768     context = gtk_widget_get_style_context (widget);
2769   else
2770     {
2771       priv = GTK_STYLE_GET_PRIVATE (style);
2772       context = priv->context;
2773     }
2774
2775   gtk_style_context_save (context);
2776
2777   if (detail)
2778     transform_detail_string (detail, context);
2779
2780   gtk_style_context_add_class (context, "grip");
2781
2782   switch (state_type)
2783     {
2784     case GTK_STATE_PRELIGHT:
2785       flags |= GTK_STATE_FLAG_PRELIGHT;
2786       break;
2787     case GTK_STATE_SELECTED:
2788       flags |= GTK_STATE_FLAG_SELECTED;
2789       break;
2790     case GTK_STATE_INSENSITIVE:
2791       flags |= GTK_STATE_FLAG_INSENSITIVE;
2792       break;
2793     default:
2794       break;
2795     }
2796
2797   gtk_style_context_set_state (context, flags);
2798
2799   switch (edge)
2800     {
2801     case GDK_WINDOW_EDGE_NORTH_WEST:
2802       sides = GTK_JUNCTION_CORNER_TOPLEFT;
2803       break;
2804     case GDK_WINDOW_EDGE_NORTH:
2805       sides = GTK_JUNCTION_TOP;
2806       break;
2807     case GDK_WINDOW_EDGE_NORTH_EAST:
2808       sides = GTK_JUNCTION_CORNER_TOPRIGHT;
2809       break;
2810     case GDK_WINDOW_EDGE_WEST:
2811       sides = GTK_JUNCTION_LEFT;
2812       break;
2813     case GDK_WINDOW_EDGE_EAST:
2814       sides = GTK_JUNCTION_RIGHT;
2815       break;
2816     case GDK_WINDOW_EDGE_SOUTH_WEST:
2817       sides = GTK_JUNCTION_CORNER_BOTTOMLEFT;
2818       break;
2819     case GDK_WINDOW_EDGE_SOUTH:
2820       sides = GTK_JUNCTION_BOTTOM;
2821       break;
2822     case GDK_WINDOW_EDGE_SOUTH_EAST:
2823       sides = GTK_JUNCTION_CORNER_BOTTOMRIGHT;
2824       break;
2825     }
2826
2827   gtk_style_context_set_junction_sides (context, sides);
2828
2829   cairo_save (cr);
2830
2831   gtk_render_handle (context, cr,
2832                      (gdouble) x,
2833                      (gdouble) y,
2834                      (gdouble) width,
2835                      (gdouble) height);
2836
2837   cairo_restore (cr);
2838   gtk_style_context_restore (context);
2839 }
2840
2841 static void
2842 gtk_default_draw_spinner (GtkStyle     *style,
2843                           cairo_t      *cr,
2844                           GtkStateType  state_type,
2845                           GtkWidget    *widget,
2846                           const gchar  *detail,
2847                           guint         step,
2848                           gint          x,
2849                           gint          y,
2850                           gint          width,
2851                           gint          height)
2852 {
2853   GdkColor *color;
2854   guint num_steps;
2855   gdouble dx, dy;
2856   gdouble radius;
2857   gdouble half;
2858   gint i;
2859   guint real_step;
2860
2861   num_steps = 12;
2862   real_step = step % num_steps;
2863
2864   /* set a clip region for the expose event */
2865   cairo_rectangle (cr, x, y, width, height);
2866   cairo_clip (cr);
2867
2868   cairo_translate (cr, x, y);
2869
2870   /* draw clip region */
2871   cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
2872
2873   color = &style->fg[state_type];
2874   dx = width / 2;
2875   dy = height / 2;
2876   radius = MIN (width / 2, height / 2);
2877   half = num_steps / 2;
2878
2879   for (i = 0; i < num_steps; i++)
2880     {
2881       gint inset = 0.7 * radius;
2882
2883       /* transparency is a function of time and intial value */
2884       gdouble t = (gdouble) ((i + num_steps - real_step)
2885                              % num_steps) / num_steps;
2886
2887       cairo_save (cr);
2888
2889       cairo_set_source_rgba (cr,
2890                              color->red / 65535.,
2891                              color->green / 65535.,
2892                              color->blue / 65535.,
2893                              t);
2894
2895       cairo_set_line_width (cr, 2.0);
2896       cairo_move_to (cr,
2897                      dx + (radius - inset) * cos (i * G_PI / half),
2898                      dy + (radius - inset) * sin (i * G_PI / half));
2899       cairo_line_to (cr,
2900                      dx + radius * cos (i * G_PI / half),
2901                      dy + radius * sin (i * G_PI / half));
2902       cairo_stroke (cr);
2903
2904       cairo_restore (cr);
2905     }
2906 }
2907
2908 void
2909 _gtk_style_shade (const GdkColor *a,
2910                   GdkColor       *b,
2911                   gdouble         k)
2912 {
2913   gdouble red;
2914   gdouble green;
2915   gdouble blue;
2916   
2917   red = (gdouble) a->red / 65535.0;
2918   green = (gdouble) a->green / 65535.0;
2919   blue = (gdouble) a->blue / 65535.0;
2920   
2921   rgb_to_hls (&red, &green, &blue);
2922   
2923   green *= k;
2924   if (green > 1.0)
2925     green = 1.0;
2926   else if (green < 0.0)
2927     green = 0.0;
2928   
2929   blue *= k;
2930   if (blue > 1.0)
2931     blue = 1.0;
2932   else if (blue < 0.0)
2933     blue = 0.0;
2934   
2935   hls_to_rgb (&red, &green, &blue);
2936   
2937   b->red = red * 65535.0;
2938   b->green = green * 65535.0;
2939   b->blue = blue * 65535.0;
2940 }
2941
2942 static void
2943 rgb_to_hls (gdouble *r,
2944             gdouble *g,
2945             gdouble *b)
2946 {
2947   gdouble min;
2948   gdouble max;
2949   gdouble red;
2950   gdouble green;
2951   gdouble blue;
2952   gdouble h, l, s;
2953   gdouble delta;
2954   
2955   red = *r;
2956   green = *g;
2957   blue = *b;
2958   
2959   if (red > green)
2960     {
2961       if (red > blue)
2962         max = red;
2963       else
2964         max = blue;
2965       
2966       if (green < blue)
2967         min = green;
2968       else
2969         min = blue;
2970     }
2971   else
2972     {
2973       if (green > blue)
2974         max = green;
2975       else
2976         max = blue;
2977       
2978       if (red < blue)
2979         min = red;
2980       else
2981         min = blue;
2982     }
2983   
2984   l = (max + min) / 2;
2985   s = 0;
2986   h = 0;
2987   
2988   if (max != min)
2989     {
2990       if (l <= 0.5)
2991         s = (max - min) / (max + min);
2992       else
2993         s = (max - min) / (2 - max - min);
2994       
2995       delta = max -min;
2996       if (red == max)
2997         h = (green - blue) / delta;
2998       else if (green == max)
2999         h = 2 + (blue - red) / delta;
3000       else if (blue == max)
3001         h = 4 + (red - green) / delta;
3002       
3003       h *= 60;
3004       if (h < 0.0)
3005         h += 360;
3006     }
3007   
3008   *r = h;
3009   *g = l;
3010   *b = s;
3011 }
3012
3013 static void
3014 hls_to_rgb (gdouble *h,
3015             gdouble *l,
3016             gdouble *s)
3017 {
3018   gdouble hue;
3019   gdouble lightness;
3020   gdouble saturation;
3021   gdouble m1, m2;
3022   gdouble r, g, b;
3023   
3024   lightness = *l;
3025   saturation = *s;
3026   
3027   if (lightness <= 0.5)
3028     m2 = lightness * (1 + saturation);
3029   else
3030     m2 = lightness + saturation - lightness * saturation;
3031   m1 = 2 * lightness - m2;
3032   
3033   if (saturation == 0)
3034     {
3035       *h = lightness;
3036       *l = lightness;
3037       *s = lightness;
3038     }
3039   else
3040     {
3041       hue = *h + 120;
3042       while (hue > 360)
3043         hue -= 360;
3044       while (hue < 0)
3045         hue += 360;
3046       
3047       if (hue < 60)
3048         r = m1 + (m2 - m1) * hue / 60;
3049       else if (hue < 180)
3050         r = m2;
3051       else if (hue < 240)
3052         r = m1 + (m2 - m1) * (240 - hue) / 60;
3053       else
3054         r = m1;
3055       
3056       hue = *h;
3057       while (hue > 360)
3058         hue -= 360;
3059       while (hue < 0)
3060         hue += 360;
3061       
3062       if (hue < 60)
3063         g = m1 + (m2 - m1) * hue / 60;
3064       else if (hue < 180)
3065         g = m2;
3066       else if (hue < 240)
3067         g = m1 + (m2 - m1) * (240 - hue) / 60;
3068       else
3069         g = m1;
3070       
3071       hue = *h - 120;
3072       while (hue > 360)
3073         hue -= 360;
3074       while (hue < 0)
3075         hue += 360;
3076       
3077       if (hue < 60)
3078         b = m1 + (m2 - m1) * hue / 60;
3079       else if (hue < 180)
3080         b = m2;
3081       else if (hue < 240)
3082         b = m1 + (m2 - m1) * (240 - hue) / 60;
3083       else
3084         b = m1;
3085       
3086       *h = r;
3087       *l = g;
3088       *s = b;
3089     }
3090 }
3091
3092
3093 /**
3094  * gtk_paint_hline:
3095  * @style: a #GtkStyle
3096  * @cr: a #caio_t
3097  * @state_type: a state
3098  * @widget: (allow-none): the widget
3099  * @detail: (allow-none): a style detail
3100  * @x1: the starting x coordinate
3101  * @x2: the ending x coordinate
3102  * @y: the y coordinate
3103  *
3104  * Draws a horizontal line from (@x1, @y) to (@x2, @y) in @cr
3105  * using the given style and state.
3106  *
3107  * Deprecated:3.0: Use gtk_render_line() instead
3108  **/
3109 void
3110 gtk_paint_hline (GtkStyle           *style,
3111                  cairo_t            *cr,
3112                  GtkStateType        state_type,
3113                  GtkWidget          *widget,
3114                  const gchar        *detail,
3115                  gint                x1,
3116                  gint                x2,
3117                  gint                y)
3118 {
3119   g_return_if_fail (GTK_IS_STYLE (style));
3120   g_return_if_fail (cr != NULL);
3121   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
3122
3123   cairo_save (cr);
3124
3125   GTK_STYLE_GET_CLASS (style)->draw_hline (style, cr, state_type,
3126                                            widget, detail,
3127                                            x1, x2, y);
3128
3129   cairo_restore (cr);
3130 }
3131
3132 /**
3133  * gtk_paint_vline:
3134  * @style: a #GtkStyle
3135  * @cr: a #cairo_t
3136  * @state_type: a state
3137  * @widget: (allow-none): the widget
3138  * @detail: (allow-none): a style detail
3139  * @y1_: the starting y coordinate
3140  * @y2_: the ending y coordinate
3141  * @x: the x coordinate
3142  *
3143  * Draws a vertical line from (@x, @y1_) to (@x, @y2_) in @cr
3144  * using the given style and state.
3145  *
3146  * Deprecated:3.0: Use gtk_render_line() instead
3147  */
3148 void
3149 gtk_paint_vline (GtkStyle           *style,
3150                  cairo_t            *cr,
3151                  GtkStateType        state_type,
3152                  GtkWidget          *widget,
3153                  const gchar        *detail,
3154                  gint                y1_,
3155                  gint                y2_,
3156                  gint                x)
3157 {
3158   g_return_if_fail (GTK_IS_STYLE (style));
3159   g_return_if_fail (cr != NULL);
3160   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
3161
3162   cairo_save (cr);
3163
3164   GTK_STYLE_GET_CLASS (style)->draw_vline (style, cr, state_type,
3165                                            widget, detail,
3166                                            y1_, y2_, x);
3167
3168   cairo_restore (cr);
3169 }
3170
3171 /**
3172  * gtk_paint_shadow:
3173  * @style: a #GtkStyle
3174  * @cr: a #cairo_t
3175  * @state_type: a state
3176  * @shadow_type: type of shadow to draw
3177  * @widget: (allow-none): the widget
3178  * @detail: (allow-none): a style detail
3179  * @x: x origin of the rectangle
3180  * @y: y origin of the rectangle
3181  * @width: width of the rectangle
3182  * @height: width of the rectangle
3183  *
3184  * Draws a shadow around the given rectangle in @cr
3185  * using the given style and state and shadow type.
3186  *
3187  * Deprecated:3.0: Use gtk_render_frame() instead
3188  */
3189 void
3190 gtk_paint_shadow (GtkStyle           *style,
3191                   cairo_t            *cr,
3192                   GtkStateType        state_type,
3193                   GtkShadowType       shadow_type,
3194                   GtkWidget          *widget,
3195                   const gchar        *detail,
3196                   gint                x,
3197                   gint                y,
3198                   gint                width,
3199                   gint                height)
3200 {
3201   g_return_if_fail (GTK_IS_STYLE (style));
3202   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
3203   g_return_if_fail (cr != NULL);
3204   g_return_if_fail (width >= 0);
3205   g_return_if_fail (height >= 0);
3206
3207   cairo_save (cr);
3208
3209   GTK_STYLE_GET_CLASS (style)->draw_shadow (style, cr, state_type, shadow_type,
3210                                             widget, detail,
3211                                             x, y, width, height);
3212
3213   cairo_restore (cr);
3214 }
3215
3216 /**
3217  * gtk_paint_arrow:
3218  * @style: a #GtkStyle
3219  * @cr: a #cairo_t
3220  * @state_type: a state
3221  * @shadow_type: the type of shadow to draw
3222  * @widget: (allow-none): the widget
3223  * @detail: (allow-none): a style detail
3224  * @arrow_type: the type of arrow to draw
3225  * @fill: %TRUE if the arrow tip should be filled
3226  * @x: x origin of the rectangle to draw the arrow in
3227  * @y: y origin of the rectangle to draw the arrow in
3228  * @width: width of the rectangle to draw the arrow in
3229  * @height: height of the rectangle to draw the arrow in
3230  *
3231  * Draws an arrow in the given rectangle on @cr using the given
3232  * parameters. @arrow_type determines the direction of the arrow.
3233  *
3234  * Deprecated:3.0: Use gtk_render_arrow() instead
3235  */
3236 void
3237 gtk_paint_arrow (GtkStyle           *style,
3238                  cairo_t            *cr,
3239                  GtkStateType        state_type,
3240                  GtkShadowType       shadow_type,
3241                  GtkWidget          *widget,
3242                  const gchar        *detail,
3243                  GtkArrowType        arrow_type,
3244                  gboolean            fill,
3245                  gint                x,
3246                  gint                y,
3247                  gint                width,
3248                  gint                height)
3249 {
3250   g_return_if_fail (GTK_IS_STYLE (style));
3251   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
3252   g_return_if_fail (cr != NULL);
3253   g_return_if_fail (width >= 0);
3254   g_return_if_fail (height >= 0);
3255
3256   cairo_save (cr);
3257
3258   GTK_STYLE_GET_CLASS (style)->draw_arrow (style, cr, state_type, shadow_type,
3259                                            widget, detail,
3260                                            arrow_type, fill, x, y, width, height);
3261
3262   cairo_restore (cr);
3263 }
3264
3265 /**
3266  * gtk_paint_diamond:
3267  * @style: a #GtkStyle
3268  * @cr: a #cairo_t
3269  * @state_type: a state
3270  * @shadow_type: the type of shadow to draw
3271  * @widget: (allow-none): the widget
3272  * @detail: (allow-none): a style detail
3273  * @x: x origin of the rectangle to draw the diamond in
3274  * @y: y origin of the rectangle to draw the diamond in
3275  * @width: width of the rectangle to draw the diamond in
3276  * @height: height of the rectangle to draw the diamond in
3277  *
3278  * Draws a diamond in the given rectangle on @window using the given
3279  * parameters.
3280  *
3281  * Deprecated:3.0: Use cairo instead
3282  */
3283 void
3284 gtk_paint_diamond (GtkStyle           *style,
3285                    cairo_t            *cr,
3286                    GtkStateType        state_type,
3287                    GtkShadowType       shadow_type,
3288                    GtkWidget          *widget,
3289                    const gchar        *detail,
3290                    gint                x,
3291                    gint                y,
3292                    gint                width,
3293                    gint                height)
3294 {
3295   g_return_if_fail (GTK_IS_STYLE (style));
3296   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
3297   g_return_if_fail (cr != NULL);
3298   g_return_if_fail (width >= 0);
3299   g_return_if_fail (height >= 0);
3300
3301   cairo_save (cr);
3302
3303   GTK_STYLE_GET_CLASS (style)->draw_diamond (style, cr, state_type, shadow_type,
3304                                              widget, detail,
3305                                              x, y, width, height);
3306
3307   cairo_restore (cr);
3308 }
3309
3310 /**
3311  * gtk_paint_box:
3312  * @style: a #GtkStyle
3313  * @cr: a #cairo_t
3314  * @state_type: a state
3315  * @shadow_type: the type of shadow to draw
3316  * @widget: (allow-none): the widget
3317  * @detail: (allow-none): a style detail
3318  * @x: x origin of the box
3319  * @y: y origin of the box
3320  * @width: the width of the box
3321  * @height: the height of the box
3322  *
3323  * Draws a box on @cr with the given parameters.
3324  *
3325  * Deprecated:3.0: Use gtk_render_frame() and gtk_render_background() instead
3326  */
3327 void
3328 gtk_paint_box (GtkStyle           *style,
3329                cairo_t            *cr,
3330                GtkStateType        state_type,
3331                GtkShadowType       shadow_type,
3332                GtkWidget          *widget,
3333                const gchar        *detail,
3334                gint                x,
3335                gint                y,
3336                gint                width,
3337                gint                height)
3338 {
3339   g_return_if_fail (GTK_IS_STYLE (style));
3340   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
3341   g_return_if_fail (cr != NULL);
3342
3343   cairo_save (cr);
3344
3345   GTK_STYLE_GET_CLASS (style)->draw_box (style, cr, state_type, shadow_type,
3346                                          widget, detail,
3347                                          x, y, width, height);
3348
3349   cairo_restore (cr);
3350 }
3351
3352 /**
3353  * gtk_paint_flat_box:
3354  * @style: a #GtkStyle
3355  * @cr: a #cairo_t
3356  * @state_type: a state
3357  * @shadow_type: the type of shadow to draw
3358  * @widget: (allow-none): the widget
3359  * @detail: (allow-none): a style detail
3360  * @x: x origin of the box
3361  * @y: y origin of the box
3362  * @width: the width of the box
3363  * @height: the height of the box
3364  *
3365  * Draws a flat box on @cr with the given parameters.
3366  *
3367  * Deprecated:3.0: Use gtk_render_frame() and gtk_render_background() instead
3368  */
3369 void
3370 gtk_paint_flat_box (GtkStyle           *style,
3371                     cairo_t            *cr,
3372                     GtkStateType        state_type,
3373                     GtkShadowType       shadow_type,
3374                     GtkWidget          *widget,
3375                     const gchar        *detail,
3376                     gint                x,
3377                     gint                y,
3378                     gint                width,
3379                     gint                height)
3380 {
3381   g_return_if_fail (GTK_IS_STYLE (style));
3382   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
3383   g_return_if_fail (cr != NULL);
3384   g_return_if_fail (width >= 0);
3385   g_return_if_fail (height >= 0);
3386
3387   cairo_save (cr);
3388
3389   GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, cr, state_type, shadow_type,
3390                                               widget, detail,
3391                                               x, y, width, height);
3392
3393   cairo_restore (cr);
3394 }
3395
3396 /**
3397  * gtk_paint_check:
3398  * @style: a #GtkStyle
3399  * @cr: a #cairo_t
3400  * @state_type: a state
3401  * @shadow_type: the type of shadow to draw
3402  * @widget: (allow-none): the widget
3403  * @detail: (allow-none): a style detail
3404  * @x: x origin of the rectangle to draw the check in
3405  * @y: y origin of the rectangle to draw the check in
3406  * @width: the width of the rectangle to draw the check in
3407  * @height: the height of the rectangle to draw the check in
3408  *
3409  * Draws a check button indicator in the given rectangle on @cr with
3410  * the given parameters.
3411  *
3412  * Deprecated:3.0: Use gtk_render_check() instead
3413  */
3414 void
3415 gtk_paint_check (GtkStyle           *style,
3416                  cairo_t            *cr,
3417                  GtkStateType        state_type,
3418                  GtkShadowType       shadow_type,
3419                  GtkWidget          *widget,
3420                  const gchar        *detail,
3421                  gint                x,
3422                  gint                y,
3423                  gint                width,
3424                  gint                height)
3425 {
3426   g_return_if_fail (GTK_IS_STYLE (style));
3427   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
3428   g_return_if_fail (cr != NULL);
3429
3430   cairo_save (cr);
3431
3432   GTK_STYLE_GET_CLASS (style)->draw_check (style, cr, state_type, shadow_type,
3433                                            widget, detail,
3434                                            x, y, width, height);
3435
3436   cairo_restore (cr);
3437 }
3438
3439 /**
3440  * gtk_paint_option:
3441  * @style: a #GtkStyle
3442  * @cr: a #cairo_t
3443  * @state_type: a state
3444  * @shadow_type: the type of shadow to draw
3445  * @widget: (allow-none): the widget
3446  * @detail: (allow-none): a style detail
3447  * @x: x origin of the rectangle to draw the option in
3448  * @y: y origin of the rectangle to draw the option in
3449  * @width: the width of the rectangle to draw the option in
3450  * @height: the height of the rectangle to draw the option in
3451  *
3452  * Draws a radio button indicator in the given rectangle on @cr with
3453  * the given parameters.
3454  *
3455  * Deprecated:3.0: Use gtk_render_option() instead
3456  */
3457 void
3458 gtk_paint_option (GtkStyle           *style,
3459                   cairo_t            *cr,
3460                   GtkStateType        state_type,
3461                   GtkShadowType       shadow_type,
3462                   GtkWidget          *widget,
3463                   const gchar        *detail,
3464                   gint                x,
3465                   gint                y,
3466                   gint                width,
3467                   gint                height)
3468 {
3469   g_return_if_fail (GTK_IS_STYLE (style));
3470   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
3471   g_return_if_fail (cr != NULL);
3472
3473   cairo_save (cr);
3474
3475   GTK_STYLE_GET_CLASS (style)->draw_option (style, cr, state_type, shadow_type,
3476                                             widget, detail,
3477                                             x, y, width, height);
3478
3479   cairo_restore (cr);
3480 }
3481
3482 /**
3483  * gtk_paint_tab:
3484  * @style: a #GtkStyle
3485  * @cr: a #cairo_t
3486  * @state_type: a state
3487  * @shadow_type: the type of shadow to draw
3488  * @widget: (allow-none): the widget
3489  * @detail: (allow-none): a style detail
3490  * @x: x origin of the rectangle to draw the tab in
3491  * @y: y origin of the rectangle to draw the tab in
3492  * @width: the width of the rectangle to draw the tab in
3493  * @height: the height of the rectangle to draw the tab in
3494  *
3495  * Draws an option menu tab (i.e. the up and down pointing arrows)
3496  * in the given rectangle on @cr using the given parameters.
3497  *
3498  * Deprecated:3.0: Use cairo instead
3499  */
3500 void
3501 gtk_paint_tab (GtkStyle           *style,
3502                cairo_t            *cr,
3503                GtkStateType        state_type,
3504                GtkShadowType       shadow_type,
3505                GtkWidget          *widget,
3506                const gchar        *detail,
3507                gint                x,
3508                gint                y,
3509                gint                width,
3510                gint                height)
3511 {
3512   g_return_if_fail (GTK_IS_STYLE (style));
3513   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
3514   g_return_if_fail (cr != NULL);
3515
3516   cairo_save (cr);
3517
3518   GTK_STYLE_GET_CLASS (style)->draw_tab (style, cr, state_type, shadow_type,
3519                                          widget, detail,
3520                                          x, y, width, height);
3521
3522   cairo_restore (cr);
3523 }
3524
3525 /**
3526  * gtk_paint_shadow_gap:
3527  * @style: a #GtkStyle
3528  * @cr: a #cairo_t
3529  * @state_type: a state
3530  * @shadow_type: type of shadow to draw
3531  * @widget: (allow-none): the widget
3532  * @detail: (allow-none): a style detail
3533  * @x: x origin of the rectangle
3534  * @y: y origin of the rectangle
3535  * @width: width of the rectangle
3536  * @height: width of the rectangle
3537  * @gap_side: side in which to leave the gap
3538  * @gap_x: starting position of the gap
3539  * @gap_width: width of the gap
3540  *
3541  * Draws a shadow around the given rectangle in @cr
3542  * using the given style and state and shadow type, leaving a
3543  * gap in one side.
3544  *
3545  * Deprecated:3.0: Use gtk_render_frame_gap() instead
3546  */
3547 void
3548 gtk_paint_shadow_gap (GtkStyle           *style,
3549                       cairo_t            *cr,
3550                       GtkStateType        state_type,
3551                       GtkShadowType       shadow_type,
3552                       GtkWidget          *widget,
3553                       const gchar        *detail,
3554                       gint                x,
3555                       gint                y,
3556                       gint                width,
3557                       gint                height,
3558                       GtkPositionType     gap_side,
3559                       gint                gap_x,
3560                       gint                gap_width)
3561 {
3562   g_return_if_fail (GTK_IS_STYLE (style));
3563   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
3564   g_return_if_fail (cr != NULL);
3565   g_return_if_fail (width >= 0);
3566   g_return_if_fail (height >= 0);
3567
3568   cairo_save (cr);
3569
3570   GTK_STYLE_GET_CLASS (style)->draw_shadow_gap (style, cr, state_type, shadow_type,
3571                                                 widget, detail,
3572                                                 x, y, width, height, gap_side, gap_x, gap_width);
3573
3574   cairo_restore (cr);
3575 }
3576
3577 /**
3578  * gtk_paint_box_gap:
3579  * @style: a #GtkStyle
3580  * @cr: a #cairo_t
3581  * @state_type: a state
3582  * @shadow_type: type of shadow to draw
3583  * @widget: (allow-none): the widget
3584  * @detail: (allow-none): a style detail
3585  * @x: x origin of the rectangle
3586  * @y: y origin of the rectangle
3587  * @width: width of the rectangle
3588  * @height: width of the rectangle
3589  * @gap_side: side in which to leave the gap
3590  * @gap_x: starting position of the gap
3591  * @gap_width: width of the gap
3592  *
3593  * Draws a box in @cr using the given style and state and shadow type,
3594  * leaving a gap in one side.
3595  *
3596  * Deprecated:3.0: Use gtk_render_frame_gap() instead
3597  */
3598 void
3599 gtk_paint_box_gap (GtkStyle           *style,
3600                    cairo_t            *cr,
3601                    GtkStateType        state_type,
3602                    GtkShadowType       shadow_type,
3603                    GtkWidget          *widget,
3604                    const gchar        *detail,
3605                    gint                x,
3606                    gint                y,
3607                    gint                width,
3608                    gint                height,
3609                    GtkPositionType     gap_side,
3610                    gint                gap_x,
3611                    gint                gap_width)
3612 {
3613   g_return_if_fail (GTK_IS_STYLE (style));
3614   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
3615   g_return_if_fail (cr != NULL);
3616   g_return_if_fail (width >= 0);
3617   g_return_if_fail (height >= 0);
3618
3619   cairo_save (cr);
3620
3621   GTK_STYLE_GET_CLASS (style)->draw_box_gap (style, cr, state_type, shadow_type,
3622                                              widget, detail,
3623                                              x, y, width, height, gap_side, gap_x, gap_width);
3624
3625   cairo_restore (cr);
3626 }
3627
3628 /**
3629  * gtk_paint_extension:
3630  * @style: a #GtkStyle
3631  * @cr: a #cairo_t
3632  * @state_type: a state
3633  * @shadow_type: type of shadow to draw
3634  * @widget: (allow-none): the widget
3635  * @detail: (allow-none): a style detail
3636  * @x: x origin of the extension
3637  * @y: y origin of the extension
3638  * @width: width of the extension
3639  * @height: width of the extension
3640  * @gap_side: the side on to which the extension is attached
3641  *
3642  * Draws an extension, i.e. a notebook tab.
3643  *
3644  * Deprecated:3.0: Use gtk_render_extension() instead
3645  **/
3646 void
3647 gtk_paint_extension (GtkStyle           *style,
3648                      cairo_t            *cr,
3649                      GtkStateType        state_type,
3650                      GtkShadowType       shadow_type,
3651                      GtkWidget          *widget,
3652                      const gchar        *detail,
3653                      gint                x,
3654                      gint                y,
3655                      gint                width,
3656                      gint                height,
3657                      GtkPositionType     gap_side)
3658 {
3659   g_return_if_fail (GTK_IS_STYLE (style));
3660   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
3661   g_return_if_fail (cr != NULL);
3662   g_return_if_fail (width >= 0);
3663   g_return_if_fail (height >= 0);
3664
3665   cairo_save (cr);
3666
3667   GTK_STYLE_GET_CLASS (style)->draw_extension (style, cr, state_type, shadow_type,
3668                                                widget, detail,
3669                                                x, y, width, height, gap_side);
3670
3671   cairo_restore (cr);
3672 }
3673
3674 /**
3675  * gtk_paint_focus:
3676  * @style: a #GtkStyle
3677  * @cr: a #cairo_t
3678  * @state_type: a state
3679  * @widget: (allow-none): the widget
3680  * @detail: (allow-none): a style detail
3681  * @x: the x origin of the rectangle around which to draw a focus indicator
3682  * @y: the y origin of the rectangle around which to draw a focus indicator
3683  * @width: the width of the rectangle around which to draw a focus indicator
3684  * @height: the height of the rectangle around which to draw a focus indicator
3685  *
3686  * Draws a focus indicator around the given rectangle on @cr using the
3687  * given style.
3688  *
3689  * Deprecated:3.0: Use gtk_render_focus() instead
3690  */
3691 void
3692 gtk_paint_focus (GtkStyle           *style,
3693                  cairo_t            *cr,
3694                  GtkStateType        state_type,
3695                  GtkWidget          *widget,
3696                  const gchar        *detail,
3697                  gint                x,
3698                  gint                y,
3699                  gint                width,
3700                  gint                height)
3701 {
3702   g_return_if_fail (GTK_IS_STYLE (style));
3703   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
3704   g_return_if_fail (cr != NULL);
3705   g_return_if_fail (width >= 0);
3706   g_return_if_fail (height >= 0);
3707
3708   cairo_save (cr);
3709
3710   GTK_STYLE_GET_CLASS (style)->draw_focus (style, cr, state_type,
3711                                            widget, detail,
3712                                            x, y, width, height);
3713
3714   cairo_restore (cr);
3715 }
3716
3717 /**
3718  * gtk_paint_slider:
3719  * @style: a #GtkStyle
3720  * @cr: a #cairo_t
3721  * @state_type: a state
3722  * @shadow_type: a shadow
3723  * @widget: (allow-none): the widget
3724  * @detail: (allow-none): a style detail
3725  * @x: the x origin of the rectangle in which to draw a slider
3726  * @y: the y origin of the rectangle in which to draw a slider
3727  * @width: the width of the rectangle in which to draw a slider
3728  * @height: the height of the rectangle in which to draw a slider
3729  * @orientation: the orientation to be used
3730  *
3731  * Draws a slider in the given rectangle on @cr using the
3732  * given style and orientation.
3733  *
3734  * Deprecated:3.0: Use gtk_render_slider() instead
3735  **/
3736 void
3737 gtk_paint_slider (GtkStyle           *style,
3738                   cairo_t            *cr,
3739                   GtkStateType        state_type,
3740                   GtkShadowType       shadow_type,
3741                   GtkWidget          *widget,
3742                   const gchar        *detail,
3743                   gint                x,
3744                   gint                y,
3745                   gint                width,
3746                   gint                height,
3747                   GtkOrientation      orientation)
3748 {
3749   g_return_if_fail (GTK_IS_STYLE (style));
3750   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
3751   g_return_if_fail (cr != NULL);
3752   g_return_if_fail (width >= 0);
3753   g_return_if_fail (height >= 0);
3754
3755   cairo_save (cr);
3756
3757   GTK_STYLE_GET_CLASS (style)->draw_slider (style, cr, state_type, shadow_type,
3758                                             widget, detail,
3759                                             x, y, width, height, orientation);
3760
3761   cairo_restore (cr);
3762 }
3763
3764 /**
3765  * gtk_paint_handle:
3766  * @style: a #GtkStyle
3767  * @cr: a #cairo_t
3768  * @state_type: a state
3769  * @shadow_type: type of shadow to draw
3770  * @widget: (allow-none): the widget
3771  * @detail: (allow-none): a style detail
3772  * @x: x origin of the handle
3773  * @y: y origin of the handle
3774  * @width: with of the handle
3775  * @height: height of the handle
3776  * @orientation: the orientation of the handle
3777  *
3778  * Draws a handle as used in #GtkHandleBox and #GtkPaned.
3779  *
3780  * Deprecated:3.0: Use gtk_render_handle() instead
3781  **/
3782 void
3783 gtk_paint_handle (GtkStyle           *style,
3784                   cairo_t            *cr,
3785                   GtkStateType        state_type,
3786                   GtkShadowType       shadow_type,
3787                   GtkWidget          *widget,
3788                   const gchar        *detail,
3789                   gint                x,
3790                   gint                y,
3791                   gint                width,
3792                   gint                height,
3793                   GtkOrientation      orientation)
3794 {
3795   g_return_if_fail (GTK_IS_STYLE (style));
3796   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
3797   g_return_if_fail (cr != NULL);
3798   g_return_if_fail (width >= 0);
3799   g_return_if_fail (height >= 0);
3800
3801   cairo_save (cr);
3802
3803   GTK_STYLE_GET_CLASS (style)->draw_handle (style, cr, state_type, shadow_type,
3804                                             widget, detail,
3805                                             x, y, width, height, orientation);
3806
3807   cairo_restore (cr);
3808 }
3809
3810 /**
3811  * gtk_paint_expander:
3812  * @style: a #GtkStyle
3813  * @cr: a #cairo_t
3814  * @state_type: a state
3815  * @widget: (allow-none): the widget
3816  * @detail: (allow-none): a style detail
3817  * @x: the x position to draw the expander at
3818  * @y: the y position to draw the expander at
3819  * @expander_style: the style to draw the expander in; determines
3820  *   whether the expander is collapsed, expanded, or in an
3821  *   intermediate state.
3822  *
3823  * Draws an expander as used in #GtkTreeView. @x and @y specify the
3824  * center the expander. The size of the expander is determined by the
3825  * "expander-size" style property of @widget.  (If widget is not
3826  * specified or doesn't have an "expander-size" property, an
3827  * unspecified default size will be used, since the caller doesn't
3828  * have sufficient information to position the expander, this is
3829  * likely not useful.) The expander is expander_size pixels tall
3830  * in the collapsed position and expander_size pixels wide in the
3831  * expanded position.
3832  *
3833  * Deprecated:3.0: Use gtk_render_expander() instead
3834  **/
3835 void
3836 gtk_paint_expander (GtkStyle           *style,
3837                     cairo_t            *cr,
3838                     GtkStateType        state_type,
3839                     GtkWidget          *widget,
3840                     const gchar        *detail,
3841                     gint                x,
3842                     gint                y,
3843                     GtkExpanderStyle    expander_style)
3844 {
3845   g_return_if_fail (GTK_IS_STYLE (style));
3846   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
3847   g_return_if_fail (cr != NULL);
3848
3849   cairo_save (cr);
3850
3851   GTK_STYLE_GET_CLASS (style)->draw_expander (style, cr, state_type,
3852                                               widget, detail,
3853                                               x, y, expander_style);
3854
3855   cairo_restore (cr);
3856 }
3857
3858 /**
3859  * gtk_paint_layout:
3860  * @style: a #GtkStyle
3861  * @cr: a #cairo_t
3862  * @state_type: a state
3863  * @use_text: whether to use the text or foreground
3864  *            graphics context of @style
3865  * @widget: (allow-none): the widget
3866  * @detail: (allow-none): a style detail
3867  * @x: x origin
3868  * @y: y origin
3869  * @layout: the layout to draw
3870  *
3871  * Draws a layout on @cr using the given parameters.
3872  *
3873  * Deprecated:3.0: Use gtk_render_layout() instead
3874  **/
3875 void
3876 gtk_paint_layout (GtkStyle           *style,
3877                   cairo_t            *cr,
3878                   GtkStateType        state_type,
3879                   gboolean            use_text,
3880                   GtkWidget          *widget,
3881                   const gchar        *detail,
3882                   gint                x,
3883                   gint                y,
3884                   PangoLayout        *layout)
3885 {
3886   g_return_if_fail (GTK_IS_STYLE (style));
3887   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
3888   g_return_if_fail (cr != NULL);
3889
3890   cairo_save (cr);
3891
3892   GTK_STYLE_GET_CLASS (style)->draw_layout (style, cr, state_type, use_text,
3893                                             widget, detail,
3894                                             x, y, layout);
3895
3896   cairo_restore (cr);
3897 }
3898
3899 /**
3900  * gtk_paint_resize_grip:
3901  * @style: a #GtkStyle
3902  * @cr: a #cairo_t
3903  * @state_type: a state
3904  * @widget: (allow-none): the widget
3905  * @detail: (allow-none): a style detail
3906  * @edge: the edge in which to draw the resize grip
3907  * @x: the x origin of the rectangle in which to draw the resize grip
3908  * @y: the y origin of the rectangle in which to draw the resize grip
3909  * @width: the width of the rectangle in which to draw the resize grip
3910  * @height: the height of the rectangle in which to draw the resize grip
3911  *
3912  * Draws a resize grip in the given rectangle on @cr using the given
3913  * parameters.
3914  *
3915  * Deprecated:3.0: Use gtk_render_handle() instead
3916  */
3917 void
3918 gtk_paint_resize_grip (GtkStyle           *style,
3919                        cairo_t            *cr,
3920                        GtkStateType        state_type,
3921                        GtkWidget          *widget,
3922                        const gchar        *detail,
3923                        GdkWindowEdge       edge,
3924                        gint                x,
3925                        gint                y,
3926                        gint                width,
3927                        gint                height)
3928 {
3929   g_return_if_fail (GTK_IS_STYLE (style));
3930   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
3931   g_return_if_fail (cr != NULL);
3932
3933   cairo_save (cr);
3934
3935   GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, cr, state_type,
3936                                                  widget, detail,
3937                                                  edge, x, y, width, height);
3938   cairo_restore (cr);
3939 }
3940
3941 /**
3942  * gtk_paint_spinner:
3943  * @style: a #GtkStyle
3944  * @cr: a #cairo_t
3945  * @state_type: a state
3946  * @widget: (allow-none): the widget (may be %NULL)
3947  * @detail: (allow-none): a style detail (may be %NULL)
3948  * @step: the nth step, a value between 0 and #GtkSpinner:num-steps
3949  * @x: the x origin of the rectangle in which to draw the spinner
3950  * @y: the y origin of the rectangle in which to draw the spinner
3951  * @width: the width of the rectangle in which to draw the spinner
3952  * @height: the height of the rectangle in which to draw the spinner
3953  *
3954  * Draws a spinner on @window using the given parameters.
3955  *
3956  * Deprecated:3.0: Use gtk_render_activity() instead
3957  */
3958 void
3959 gtk_paint_spinner (GtkStyle           *style,
3960                    cairo_t            *cr,
3961                    GtkStateType        state_type,
3962                    GtkWidget          *widget,
3963                    const gchar        *detail,
3964                    guint               step,
3965                    gint                x,
3966                    gint                y,
3967                    gint                width,
3968                    gint                height)
3969 {
3970   g_return_if_fail (GTK_IS_STYLE (style));
3971   g_return_if_fail (cr != NULL);
3972   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_spinner != NULL);
3973
3974   cairo_save (cr);
3975
3976   GTK_STYLE_GET_CLASS (style)->draw_spinner (style, cr, state_type,
3977                                              widget, detail,
3978                                              step, x, y, width, height);
3979
3980   cairo_restore (cr);
3981 }