]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkstyle.c
Treat backup files the same way as hidden files, to be closer to what
[~andy/gtk] / gtk / gtkstyle.c
index 9c4ca5a5124653a184f67fad6d1080dcbfcf5741..8fa082a6b3dee386e255bdeb4aaf99fe5c29b0f7 100644 (file)
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
 
+#include <config.h>
 #include <math.h>
 #include <stdlib.h>
 #include <string.h>
 #include "gtkgc.h"
+#include "gtkmarshalers.h"
 #include "gtkrc.h"
 #include "gtkspinbutton.h"
 #include "gtkstyle.h"
@@ -35,6 +37,7 @@
 #include "gtkthemes.h"
 #include "gtkiconfactory.h"
 #include "gtksettings.h"       /* _gtk_settings_parse_convert() */
+#include "gtkalias.h"
 
 #define LIGHTNESS_MULT  1.3
 #define DARKNESS_MULT   0.7
@@ -46,7 +49,6 @@ typedef struct {
   GValue      value;
 } PropertyValue;
 
-
 /* --- prototypes --- */
 static void     gtk_style_init                 (GtkStyle       *style);
 static void     gtk_style_class_init           (GtkStyleClass  *klass);
@@ -312,108 +314,46 @@ static void hls_to_rgb                   (gdouble         *h,
                                         gdouble         *l,
                                         gdouble         *s);
 
+static void style_unrealize_cursor_gcs (GtkStyle *style);
+
+static GdkFont *gtk_style_get_font_internal (GtkStyle *style);
 
 /*
  * Data for default check and radio buttons
  */
 
-static GtkRequisition default_option_indicator_size = { 7, 13 };
-static GtkBorder default_option_indicator_spacing = { 7, 5, 2, 2 };
-
-#define INDICATOR_PART_SIZE 13
-
-typedef enum {
-  CHECK_AA,
-  CHECK_BASE,
-  CHECK_BLACK,
-  CHECK_DARK,
-  CHECK_LIGHT,
-  CHECK_MID,
-  CHECK_TEXT,
-  RADIO_BASE,
-  RADIO_BLACK,
-  RADIO_DARK,
-  RADIO_LIGHT,
-  RADIO_MID,
-  RADIO_TEXT
-} IndicatorPart;
-
-static char check_aa_bits[] = {
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x58,0x00,0xa0,
- 0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-static char check_base_bits[] = {
- 0x00,0x00,0x00,0x00,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,
- 0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0x00,0x00,0x00,0x00};
-static char check_black_bits[] = {
- 0x00,0x00,0xfe,0x0f,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
- 0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x00,0x00};
-static char check_dark_bits[] = {
- 0xff,0x1f,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
- 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00};
-static char check_light_bits[] = {
- 0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,
- 0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0xfe,0x1f};
-static char check_mid_bits[] = {
- 0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,
- 0x08,0x00,0x08,0x00,0x08,0x00,0x08,0xfc,0x0f,0x00,0x00};
-static char check_text_bits[] = {
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x03,0x80,0x01,0x80,0x00,0xd8,
- 0x00,0x60,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-static char radio_base_bits[] = {
- 0x00,0x00,0x00,0x00,0xf0,0x01,0xf8,0x03,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,
- 0x07,0xfc,0x07,0xf8,0x03,0xf0,0x01,0x00,0x00,0x00,0x00};
-static char radio_black_bits[] = {
- 0x00,0x00,0xf0,0x01,0x08,0x02,0x04,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
- 0x00,0x02,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-static char radio_dark_bits[] = {
- 0xf0,0x01,0x08,0x02,0x04,0x04,0x02,0x04,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
- 0x00,0x01,0x00,0x02,0x00,0x0c,0x00,0x00,0x00,0x00,0x00};
-static char radio_light_bits[] = {
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x10,0x00,0x10,0x00,0x10,0x00,
- 0x10,0x00,0x10,0x00,0x08,0x00,0x04,0x08,0x02,0xf0,0x01};
-static char radio_mid_bits[] = {
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,
- 0x08,0x00,0x08,0x00,0x04,0x00,0x02,0xf0,0x01,0x00,0x00};
-static char radio_text_bits[] = {
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x00,0xf0,0x01,0xf0,0x01,0xf0,
- 0x01,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-
-static struct {
-  char      *bits;
-  GdkBitmap *bmap;
-} indicator_parts[] = {
-  { check_aa_bits, NULL },
-  { check_base_bits, NULL },
-  { check_black_bits, NULL },
-  { check_dark_bits, NULL },
-  { check_light_bits, NULL },
-  { check_mid_bits, NULL },
-  { check_text_bits, NULL },
-  { radio_base_bits, NULL },
-  { radio_black_bits, NULL },
-  { radio_dark_bits, NULL },
-  { radio_light_bits, NULL },
-  { radio_mid_bits, NULL },
-  { radio_text_bits, NULL }
-};
+static const GtkRequisition default_option_indicator_size = { 7, 13 };
+static const GtkBorder default_option_indicator_spacing = { 7, 5, 2, 2 };
+
+#define GTK_GRAY               0xdcdc, 0xdada, 0xd5d5
+#define GTK_DARK_GRAY          0xc4c4, 0xc2c2, 0xbdbd
+#define GTK_LIGHT_GRAY         0xeeee, 0xebeb, 0xe7e7
+#define GTK_WHITE              0xffff, 0xffff, 0xffff
+#define GTK_BLUE               0x4b4b, 0x6969, 0x8383
+#define GTK_VERY_DARK_GRAY     0x9c9c, 0x9a9a, 0x9494
+#define GTK_BLACK              0x0000, 0x0000, 0x0000
+#define GTK_WEAK_GRAY          0x7530, 0x7530, 0x7530
 
 /* --- variables --- */
-static GdkColor gtk_default_normal_fg =      { 0,      0,      0,      0 };
-static GdkColor gtk_default_active_fg =      { 0,      0,      0,      0 };
-static GdkColor gtk_default_prelight_fg =    { 0,      0,      0,      0 };
-static GdkColor gtk_default_selected_fg =    { 0, 0xffff, 0xffff, 0xffff };
-static GdkColor gtk_default_insensitive_fg = { 0, 0x7530, 0x7530, 0x7530 };
-
-static GdkColor gtk_default_normal_bg =      { 0, 0xd6d6, 0xd6d6, 0xd6d6 };
-static GdkColor gtk_default_active_bg =      { 0, 0xc350, 0xc350, 0xc350 };
-static GdkColor gtk_default_prelight_bg =    { 0, 0xea60, 0xea60, 0xea60 };
-static GdkColor gtk_default_selected_bg =    { 0,      0,      0, 0x9c40 };
-static GdkColor gtk_default_insensitive_bg = { 0, 0xd6d6, 0xd6d6, 0xd6d6 };
-static GdkColor gtk_default_selected_base =  { 0, 0xa4a4, 0xdfdf, 0xffff };
-static GdkColor gtk_default_active_base =    { 0, 0xbcbc, 0xd2d2, 0xeeee };
+static const GdkColor gtk_default_normal_fg =      { 0, GTK_BLACK };
+static const GdkColor gtk_default_active_fg =      { 0, GTK_BLACK };
+static const GdkColor gtk_default_prelight_fg =    { 0, GTK_BLACK };
+static const GdkColor gtk_default_selected_fg =    { 0, GTK_WHITE };
+static const GdkColor gtk_default_insensitive_fg = { 0, GTK_WEAK_GRAY };
+
+static const GdkColor gtk_default_normal_bg =      { 0, GTK_GRAY };
+static const GdkColor gtk_default_active_bg =      { 0, GTK_DARK_GRAY };
+static const GdkColor gtk_default_prelight_bg =    { 0, GTK_LIGHT_GRAY };
+static const GdkColor gtk_default_selected_bg =    { 0, GTK_BLUE };
+static const GdkColor gtk_default_insensitive_bg = { 0, GTK_GRAY };
+static const GdkColor gtk_default_selected_base =  { 0, GTK_BLUE };
+static const GdkColor gtk_default_active_base =    { 0, GTK_VERY_DARK_GRAY };
 
 static gpointer parent_class = NULL;
 
+/* --- signals --- */
+static guint realize_signal = 0;
+static guint unrealize_signal = 0;
 
 /* --- functions --- */
 GType
@@ -436,21 +376,61 @@ gtk_style_get_type (void)
         (GInstanceInitFunc) gtk_style_init,
       };
       
-      style_type = g_type_register_static (G_TYPE_OBJECT,
-                                          "GtkStyle",
+      style_type = g_type_register_static (G_TYPE_OBJECT, "GtkStyle",
                                           &style_info, 0);
     }
   
   return style_type;
 }
 
+/**
+ * _gtk_style_init_for_settings:
+ * @style: a #GtkStyle
+ * @settings: a #GtkSettings
+ * 
+ * Initializes the font description in @style according to the default
+ * font name of @settings. This is called for gtk_style_new() with
+ * the settings for the default screen (if any); if we are creating
+ * a style for a particular screen, we then call it again in a
+ * location where we know the correct settings.
+ * The reason for this is that gtk_rc_style_create_style() doesn't
+ * take the screen for an argument.
+ **/
+void
+_gtk_style_init_for_settings (GtkStyle    *style,
+                             GtkSettings *settings)
+{
+  const gchar *font_name = _gtk_rc_context_get_default_font_name (settings);
+
+  if (style->font_desc)
+    pango_font_description_free (style->font_desc);
+  
+  style->font_desc = pango_font_description_from_string (font_name);
+      
+  if (!pango_font_description_get_family (style->font_desc))
+    {
+      g_warning ("Default font does not have a family set");
+      pango_font_description_set_family (style->font_desc, "Sans");
+    }
+  if (pango_font_description_get_size (style->font_desc) <= 0)
+    {
+      g_warning ("Default font does not have a positive size");
+      pango_font_description_set_size (style->font_desc, 10 * PANGO_SCALE);
+    }
+}
+
 static void
 gtk_style_init (GtkStyle *style)
 {
   gint i;
   
-  style->font_desc = pango_font_description_from_string ("Sans 10");
-
+  GtkSettings *settings = gtk_settings_get_default ();
+  
+  if (settings)
+    _gtk_style_init_for_settings (style, settings);
+  else
+    style->font_desc = pango_font_description_from_string ("Sans 10");
+  
   style->attach_count = 0;
   style->colormap = NULL;
   style->depth = -1;
@@ -485,9 +465,9 @@ gtk_style_init (GtkStyle *style)
     }
 
   style->base[GTK_STATE_SELECTED] = gtk_default_selected_base;
-  style->text[GTK_STATE_SELECTED] = style->black;
+  style->text[GTK_STATE_SELECTED] = style->white;
   style->base[GTK_STATE_ACTIVE] = gtk_default_active_base;
-  style->text[GTK_STATE_ACTIVE] = style->black;
+  style->text[GTK_STATE_ACTIVE] = style->white;
   style->base[GTK_STATE_INSENSITIVE] = gtk_default_prelight_bg;
   style->text[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
   
@@ -552,6 +532,44 @@ gtk_style_class_init (GtkStyleClass *klass)
   klass->draw_expander = gtk_default_draw_expander;
   klass->draw_layout = gtk_default_draw_layout;
   klass->draw_resize_grip = gtk_default_draw_resize_grip;
+
+  
+  /**
+   * GtkStyle::realize:
+   * @style: the object which received the signal
+   *
+   * Emitted when the style has been initialized for a particular
+   * colormap and depth. Connecting to this signal is probably seldom
+   * useful since most of the time applications and widgets only
+   * deal with styles that have been already realized.
+   *
+   * Since: 2.4
+   */
+  realize_signal = g_signal_new ("realize",
+                                G_TYPE_FROM_CLASS (object_class),
+                                G_SIGNAL_RUN_FIRST,
+                                G_STRUCT_OFFSET (GtkStyleClass, realize),
+                                NULL, NULL,
+                                _gtk_marshal_VOID__VOID,
+                                G_TYPE_NONE, 0);
+  /**
+   * GtkStyle::unrealize:
+   * @style: the object which received the signal
+   *
+   * Emitted when the aspects of the style specific to a particular colormap
+   * and depth are being cleaned up. A connection to this signal can be useful
+   * if a widget wants to cache objects like a #GdkGC as object data on #GtkStyle.
+   * This signal provides a convenient place to free such cached objects.
+   *
+   * Since: 2.4
+   */
+  unrealize_signal = g_signal_new ("unrealize",
+                                  G_TYPE_FROM_CLASS (object_class),
+                                  G_SIGNAL_RUN_FIRST,
+                                  G_STRUCT_OFFSET (GtkStyleClass, unrealize),
+                                  NULL, NULL,
+                                  _gtk_marshal_VOID__VOID,
+                                  G_TYPE_NONE, 0);
 }
 
 static void
@@ -582,6 +600,13 @@ gtk_style_finalize (GObject *object)
 
   clear_property_cache (style);
   
+  /* All the styles in the list have the same 
+   * style->styles pointer. If we delete the 
+   * *first* style from the list, we need to update
+   * the style->styles pointers from all the styles.
+   * Otherwise we simply remove the node from
+   * the list.
+   */
   if (style->styles)
     {
       if (style->styles->data != style)
@@ -599,6 +624,19 @@ gtk_style_finalize (GObject *object)
         }
     }
 
+  if (style->icon_factories)
+    {
+      GSList *tmp_list = style->icon_factories;
+
+      while (tmp_list)
+       {
+         g_object_unref (tmp_list->data);
+         tmp_list = tmp_list->next;
+       }
+
+      g_slist_free (style->icon_factories);
+    }
+
   pango_font_description_free (style->font_desc);
   
   if (style->private_font)
@@ -636,6 +674,11 @@ gtk_style_duplicate (GtkStyle *style)
   
   new_style = gtk_style_copy (style);
   
+  /* All the styles in the list have the same 
+   * style->styles pointer. When we insert a new 
+   * style, we append it to the list to avoid having 
+   * to update the existing ones. 
+   */
   style->styles = g_slist_append (style->styles, new_style);
   new_style->styles = style->styles;  
   
@@ -661,7 +704,7 @@ gtk_style_new (void)
 /**
  * gtk_style_attach:
  * @style: a #GtkStyle.
- * @window: a #GtkWindow.
+ * @window: a #GdkWindow.
  * @returns: Either @style, or a newly-created #GtkStyle.
  *   If the style is newly created, the style parameter
  *   will be dereferenced, and the new style will have
@@ -673,22 +716,6 @@ gtk_style_new (void)
  * involve the creation of a new style if the style has already 
  * been attached to a window with a different style and colormap.
  **/
- /*
- * FIXME: The sequence - 
- *    create a style => s1
- *    attach s1 to v1, c1 => s1
- *    attach s1 to v2, c2 => s2
- *    detach s1 from v1, c1
- *    attach s1 to v2, c2 => s3
- * results in two separate, unlinked styles s2 and s3 which
- * are identical and could be shared. To fix this, we would
- * want to never remove a style from the list of linked
- * styles as long as as it has a reference count. However, the 
- * disadvantage of doing it this way means that we would need two 
- * passes through the linked list when attaching (one to check for 
- * matching styles, one to look for empty unattached styles - but 
- * it will almost never be longer than 2 elements.
- */
 GtkStyle*
 gtk_style_attach (GtkStyle  *style,
                   GdkWindow *window)
@@ -700,7 +727,7 @@ gtk_style_attach (GtkStyle  *style,
   g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
   g_return_val_if_fail (window != NULL, NULL);
   
-  colormap = gdk_window_get_colormap (window);
+  colormap = gdk_drawable_get_colormap (window);
   
   if (!style->styles)
     style->styles = g_slist_append (NULL, style);
@@ -710,21 +737,41 @@ gtk_style_attach (GtkStyle  *style,
     {
       new_style = styles->data;
       
-      if (new_style->attach_count == 0)
-        {
-          gtk_style_realize (new_style, colormap);
-          break;
-        }
-      else if (new_style->colormap == colormap)
+      if (new_style->colormap == colormap)
         break;
-      
+
       new_style = NULL;
       styles = styles->next;
     }
+
+  if (!new_style)
+    {
+      styles = style->styles;
+      
+      while (styles)
+       {
+         new_style = styles->data;
+         
+         if (new_style->attach_count == 0)
+           {
+             gtk_style_realize (new_style, colormap);
+             break;
+           }
+         
+         new_style = NULL;
+         styles = styles->next;
+       }
+    }
   
   if (!new_style)
     {
       new_style = gtk_style_duplicate (style);
+      if (gdk_colormap_get_screen (style->colormap) != gdk_colormap_get_screen (colormap) &&
+         new_style->private_font)
+       {
+         gdk_font_unref (new_style->private_font);
+         new_style->private_font = NULL;
+       }
       gtk_style_realize (new_style, colormap);
     }
 
@@ -752,11 +799,23 @@ gtk_style_detach (GtkStyle *style)
   style->attach_count -= 1;
   if (style->attach_count == 0)
     {
-      GTK_STYLE_GET_CLASS (style)->unrealize (style);
+      g_signal_emit (style, unrealize_signal, 0);
       
-      gdk_colormap_unref (style->colormap);
+      g_object_unref (style->colormap);
       style->colormap = NULL;
-      
+
+      if (style->private_font_desc)
+       {
+         if (style->private_font)
+           {
+             gdk_font_unref (style->private_font);
+             style->private_font = NULL;
+           }
+         
+         pango_font_description_free (style->private_font_desc);
+         style->private_font_desc = NULL;
+       }
+
       g_object_unref (style);
     }
 }
@@ -771,7 +830,7 @@ gtk_style_detach (GtkStyle *style)
 GtkStyle*
 gtk_style_ref (GtkStyle *style)
 {
-  return (GtkStyle *) g_object_ref (G_OBJECT (style));
+  return (GtkStyle *) g_object_ref (style);
 }
 
 /**
@@ -783,7 +842,7 @@ gtk_style_ref (GtkStyle *style)
 void
 gtk_style_unref (GtkStyle *style)
 {
-  g_object_unref (G_OBJECT (style));
+  g_object_unref (style);
 }
 
 static void
@@ -793,10 +852,10 @@ gtk_style_realize (GtkStyle    *style,
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GDK_IS_COLORMAP (colormap));
   
-  style->colormap = gdk_colormap_ref (colormap);
+  style->colormap = g_object_ref (colormap);
   style->depth = gdk_colormap_get_visual (colormap)->depth;
 
-  GTK_STYLE_GET_CLASS (style)->realize (style);
+  g_signal_emit (style, realize_signal, 0);
 }
 
 GtkIconSet*
@@ -834,7 +893,7 @@ gtk_style_lookup_icon_set (GtkStyle   *style,
  * Draws a horizontal line from (@x1, @y) to (@x2, @y) in @window
  * using the given style and state.
  * 
- * This function is deprecated, use gtk_paint_hline() instead.
+ * Deprecated: Use gtk_paint_hline() instead.
  **/
 void
 gtk_draw_hline (GtkStyle     *style,
@@ -856,27 +915,27 @@ gtk_draw_hline (GtkStyle     *style,
  * @style: a #GtkStyle
  * @window: a #GdkWindow
  * @state_type: a state
- * @y1: the starting y coordinate
- * @y2: the ending y coordinate
+ * @y1_: the starting y coordinate
+ * @y2_: the ending y coordinate
  * @x: the x coordinate
  * 
- * Draws a vertical line from (@x, @y1) to (@x, @y2) in @window
+ * Draws a vertical line from (@x, @y1_) to (@x, @y2_) in @window
  * using the given style and state.
  * 
- * This function is deprecated, use gtk_paint_vline() instead.
+ * Deprecated: Use gtk_paint_vline() instead.
  **/
 void
 gtk_draw_vline (GtkStyle     *style,
                 GdkWindow    *window,
                 GtkStateType  state_type,
-                gint          y1,
-                gint          y2,
+                gint          y1_,
+                gint          y2_,
                 gint          x)
 {
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
   
-  GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, NULL, NULL, NULL, y1, y2, x);
+  GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, NULL, NULL, NULL, y1_, y2_, x);
 }
 
 /**
@@ -893,7 +952,7 @@ gtk_draw_vline (GtkStyle     *style,
  * Draws a shadow around the given rectangle in @window 
  * using the given style and state and shadow type.
  * 
- * This function is deprecated, use gtk_paint_shadow() instead.
+ * Deprecated: Use gtk_paint_shadow() instead.
  */
 void
 gtk_draw_shadow (GtkStyle      *style,
@@ -917,13 +976,13 @@ gtk_draw_shadow (GtkStyle      *style,
  * @window: a #GdkWindow
  * @state_type: a state
  * @shadow_type: type of shadow to draw
- * @points: an array of #GdkPoint<!>s
+ * @points: an array of #GdkPoint<!-- -->s
  * @npoints: length of @points
  * @fill: %TRUE if the polygon should be filled
  * 
  * Draws a polygon on @window with the given parameters.
  *
- * This function is deprecated, use gtk_paint_polygon() instead.
+ * Deprecated: Use gtk_paint_polygon() instead.
  */ 
 void
 gtk_draw_polygon (GtkStyle      *style,
@@ -956,7 +1015,7 @@ gtk_draw_polygon (GtkStyle      *style,
  * Draws an arrow in the given rectangle on @window using the given 
  * parameters. @arrow_type determines the direction of the arrow.
  *
- * This function is deprecated, use gtk_paint_arrow() instead.
+ * Deprecated: Use gtk_paint_arrow() instead.
  */
 void
 gtk_draw_arrow (GtkStyle      *style,
@@ -987,9 +1046,10 @@ gtk_draw_arrow (GtkStyle      *style,
  * @width: width of the rectangle to draw the diamond in
  * @height: height of the rectangle to draw the diamond in
  *
- * Draws a diamond in the given rectangle on @window using the given parameters.
+ * Draws a diamond in the given rectangle on @window using the given
+ * parameters.
  *
- * This function is deprecated, use gtk_paint_diamond() instead.
+ * Deprecated: Use gtk_paint_diamond() instead.
  */
 void
 gtk_draw_diamond (GtkStyle      *style,
@@ -1018,7 +1078,7 @@ gtk_draw_diamond (GtkStyle      *style,
  * 
  * Draws a text string on @window with the given parameters.
  *
- * This function is deprecated, use gtk_paint_layout() instead.
+ * Deprecated: Use gtk_paint_layout() instead.
  */
 void
 gtk_draw_string (GtkStyle      *style,
@@ -1047,7 +1107,7 @@ gtk_draw_string (GtkStyle      *style,
  * 
  * Draws a box on @window with the given parameters.
  *
- * This function is deprecated, use gtk_paint_box() instead.
+ * Deprecated: Use gtk_paint_box() instead.
  */
 void
 gtk_draw_box (GtkStyle      *style,
@@ -1078,7 +1138,7 @@ gtk_draw_box (GtkStyle      *style,
  * 
  * Draws a flat box on @window with the given parameters.
  *
- * This function is deprecated, use gtk_paint_flat_box() instead.
+ * Deprecated: Use gtk_paint_flat_box() instead.
  */
 void
 gtk_draw_flat_box (GtkStyle      *style,
@@ -1110,7 +1170,7 @@ gtk_draw_flat_box (GtkStyle      *style,
  * Draws a check button indicator in the given rectangle on @window with 
  * the given parameters.
  *
- * This function is deprecated, use gtk_paint_check() instead.
+ * Deprecated: Use gtk_paint_check() instead.
  */
 void
 gtk_draw_check (GtkStyle      *style,
@@ -1142,7 +1202,7 @@ gtk_draw_check (GtkStyle      *style,
  * Draws a radio button indicator in the given rectangle on @window with 
  * the given parameters.
  *
- * This function is deprecated, use gtk_paint_option() instead.
+ * Deprecated: Use gtk_paint_option() instead.
  */
 void
 gtk_draw_option (GtkStyle      *style,
@@ -1174,7 +1234,7 @@ gtk_draw_option (GtkStyle      *style,
  * Draws an option menu tab (i.e. the up and down pointing arrows)
  * in the given rectangle on @window using the given parameters.
  * 
- * This function is deprecated, use gtk_paint_tab() instead.
+ * Deprecated: Use gtk_paint_tab() instead.
  */ 
 void
 gtk_draw_tab (GtkStyle      *style,
@@ -1192,6 +1252,26 @@ gtk_draw_tab (GtkStyle      *style,
   GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
 }
 
+/**
+ * gtk_draw_shadow_gap:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @shadow_type: type of shadow to draw
+ * @x: x origin of the rectangle
+ * @y: y origin of the rectangle
+ * @width: width of the rectangle 
+ * @height: width of the rectangle 
+ * @gap_side: side in which to leave the gap
+ * @gap_x: starting position of the gap
+ * @gap_width: width of the gap
+ *
+ * Draws a shadow around the given rectangle in @window 
+ * using the given style and state and shadow type, leaving a 
+ * gap in one side.
+ * 
+ * Deprecated: Use gtk_paint_shadow_gap() instead.
+*/
 void
 gtk_draw_shadow_gap (GtkStyle       *style,
                      GdkWindow      *window,
@@ -1211,6 +1291,25 @@ gtk_draw_shadow_gap (GtkStyle       *style,
   GTK_STYLE_GET_CLASS (style)->draw_shadow_gap (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, gap_side, gap_x, gap_width);
 }
 
+/**
+ * gtk_draw_box_gap:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @shadow_type: type of shadow to draw
+ * @x: x origin of the rectangle
+ * @y: y origin of the rectangle
+ * @width: width of the rectangle 
+ * @height: width of the rectangle 
+ * @gap_side: side in which to leave the gap
+ * @gap_x: starting position of the gap
+ * @gap_width: width of the gap
+ *
+ * Draws a box in @window using the given style and state and shadow type, 
+ * leaving a gap in one side.
+ * 
+ * Deprecated: Use gtk_paint_box_gap() instead.
+ */
 void
 gtk_draw_box_gap (GtkStyle       *style,
                   GdkWindow      *window,
@@ -1230,6 +1329,22 @@ gtk_draw_box_gap (GtkStyle       *style,
   GTK_STYLE_GET_CLASS (style)->draw_box_gap (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, gap_side, gap_x, gap_width);
 }
 
+/**
+ * gtk_draw_extension: 
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @shadow_type: type of shadow to draw
+ * @x: x origin of the extension
+ * @y: y origin of the extension
+ * @width: width of the extension 
+ * @height: width of the extension 
+ * @gap_side: the side on to which the extension is attached
+ * 
+ * Draws an extension, i.e. a notebook tab.
+ *
+ * Deprecated: Use gtk_paint_extension() instead.
+ **/
 void
 gtk_draw_extension (GtkStyle       *style,
                     GdkWindow      *window,
@@ -1259,7 +1374,7 @@ gtk_draw_extension (GtkStyle       *style,
  * Draws a focus indicator around the given rectangle on @window using the
  * given style.
  * 
- * This function is deprecated, use gtk_paint_focus() instead.
+ * Deprecated: Use gtk_paint_focus() instead.
  */
 void
 gtk_draw_focus (GtkStyle      *style,
@@ -1292,6 +1407,22 @@ gtk_draw_slider (GtkStyle      *style,
   GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
 }
 
+/**
+ * gtk_draw_handle:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @shadow_type: type of shadow to draw
+ * @x: x origin of the handle
+ * @y: y origin of the handle
+ * @width: with of the handle
+ * @height: height of the handle
+ * @orientation: the orientation of the handle
+ * 
+ * Draws a handle as used in #GtkHandleBox and #GtkPaned.
+ * 
+ * Deprecated: Use gtk_paint_handle() instead.
+ **/
 void 
 gtk_draw_handle (GtkStyle      *style,
                 GdkWindow     *window,
@@ -1309,6 +1440,19 @@ gtk_draw_handle (GtkStyle      *style,
   GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
 }
 
+/**
+ * gtk_draw_expander:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @x: the x position to draw the expander at
+ * @y: the y position to draw the expander at
+ * @expander_style: the style to draw the expander in
+ * 
+ * Draws an expander as used in #GtkTreeView.
+ * 
+ * Deprecated: Use gtk_paint_expander() instead.
+ **/
 void
 gtk_draw_expander (GtkStyle        *style,
                    GdkWindow       *window,
@@ -1347,8 +1491,7 @@ gtk_draw_layout (GtkStyle        *style,
  * @style: a #GtkStyle
  * @window: a #GdkWindow
  * @state_type: a state
- * @edge: the edge in which to draw the resize grip, currently only
- *    %GTK_WINDOW_EDGE_SOUTH_EAST is implemented
+ * @edge: the edge in which to draw the resize grip
  * @x: the x origin of the rectangle in which to draw the resize grip
  * @y: the y origin of the rectangle in which to draw the resize grip
  * @width: the width of the rectangle in which to draw the resize grip
@@ -1357,7 +1500,7 @@ gtk_draw_layout (GtkStyle        *style,
  * Draws a resize grip in the given rectangle on @window using the given
  * parameters. 
  * 
- * This function is deprecated, use gtk_paint_resize_grip() instead.
+ * Deprecated: Use gtk_paint_resize_grip() instead.
  */
 void
 gtk_draw_resize_grip (GtkStyle     *style,
@@ -1403,7 +1546,7 @@ gtk_style_set_background (GtkStyle    *style,
 static GtkStyle *
 gtk_style_real_clone (GtkStyle *style)
 {
-  return GTK_STYLE (g_object_new (G_OBJECT_TYPE (style), NULL));
+  return g_object_new (G_OBJECT_TYPE (style), NULL);
 }
 
 static void
@@ -1418,8 +1561,12 @@ gtk_style_real_copy (GtkStyle *style,
       style->bg[i] = src->bg[i];
       style->text[i] = src->text[i];
       style->base[i] = src->base[i];
-      
+
+      if (style->bg_pixmap[i])
+       g_object_unref (style->bg_pixmap[i]),
       style->bg_pixmap[i] = src->bg_pixmap[i];
+      if (style->bg_pixmap[i])
+       g_object_ref (style->bg_pixmap[i]);
     }
 
   if (style->private_font)
@@ -1486,8 +1633,7 @@ gtk_style_real_init_from_rc (GtkStyle   *style,
       iter = style->icon_factories;
       while (iter != NULL)
         {
-          g_object_ref (G_OBJECT (iter->data));
-          
+          g_object_ref (iter->data);
           iter = g_slist_next (iter);
         }
     }
@@ -1624,47 +1770,58 @@ gtk_style_real_realize (GtkStyle *style)
       style->text_aa[i].green = (style->text[i].green + style->base[i].green) / 2;
       style->text_aa[i].blue = (style->text[i].blue + style->base[i].blue) / 2;
     }
-  
-  gdk_color_black (style->colormap, &style->black);
-  gdk_color_white (style->colormap, &style->white);
-  
-  gc_values_mask = GDK_GC_FOREGROUND;
+
+  style->black.red = 0x0000;
+  style->black.green = 0x0000;
+  style->black.blue = 0x0000;
+  gdk_colormap_alloc_color (style->colormap, &style->black, FALSE, TRUE);
+
+  style->white.red = 0xffff;
+  style->white.green = 0xffff;
+  style->white.blue = 0xffff;
+  gdk_colormap_alloc_color (style->colormap, &style->white, FALSE, TRUE);
+
+  gc_values_mask = GDK_GC_FOREGROUND | GDK_GC_BACKGROUND;
   
   gc_values.foreground = style->black;
+  gc_values.background = style->white;
   style->black_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
   
   gc_values.foreground = style->white;
+  gc_values.background = style->black;
   style->white_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
   
+  gc_values_mask = GDK_GC_FOREGROUND;
+
   for (i = 0; i < 5; i++)
     {
       if (style->rc_style && style->rc_style->bg_pixmap_name[i])
-        style->bg_pixmap[i] = load_bg_image (style->colormap,
+       style->bg_pixmap[i] = load_bg_image (style->colormap,
                                             &style->bg[i],
                                             style->rc_style->bg_pixmap_name[i]);
       
-      if (!gdk_color_alloc (style->colormap, &style->fg[i]))
+      if (!gdk_colormap_alloc_color (style->colormap, &style->fg[i], FALSE, TRUE))
         g_warning ("unable to allocate color: ( %d %d %d )",
                    style->fg[i].red, style->fg[i].green, style->fg[i].blue);
-      if (!gdk_color_alloc (style->colormap, &style->bg[i]))
+      if (!gdk_colormap_alloc_color (style->colormap, &style->bg[i], FALSE, TRUE))
         g_warning ("unable to allocate color: ( %d %d %d )",
                    style->bg[i].red, style->bg[i].green, style->bg[i].blue);
-      if (!gdk_color_alloc (style->colormap, &style->light[i]))
+      if (!gdk_colormap_alloc_color (style->colormap, &style->light[i], FALSE, TRUE))
         g_warning ("unable to allocate color: ( %d %d %d )",
                    style->light[i].red, style->light[i].green, style->light[i].blue);
-      if (!gdk_color_alloc (style->colormap, &style->dark[i]))
+      if (!gdk_colormap_alloc_color (style->colormap, &style->dark[i], FALSE, TRUE))
         g_warning ("unable to allocate color: ( %d %d %d )",
                    style->dark[i].red, style->dark[i].green, style->dark[i].blue);
-      if (!gdk_color_alloc (style->colormap, &style->mid[i]))
+      if (!gdk_colormap_alloc_color (style->colormap, &style->mid[i], FALSE, TRUE))
         g_warning ("unable to allocate color: ( %d %d %d )",
                    style->mid[i].red, style->mid[i].green, style->mid[i].blue);
-      if (!gdk_color_alloc (style->colormap, &style->text[i]))
+      if (!gdk_colormap_alloc_color (style->colormap, &style->text[i], FALSE, TRUE))
         g_warning ("unable to allocate color: ( %d %d %d )",
                    style->text[i].red, style->text[i].green, style->text[i].blue);
-      if (!gdk_color_alloc (style->colormap, &style->base[i]))
+      if (!gdk_colormap_alloc_color (style->colormap, &style->base[i], FALSE, TRUE))
         g_warning ("unable to allocate color: ( %d %d %d )",
                    style->base[i].red, style->base[i].green, style->base[i].blue);
-      if (!gdk_color_alloc (style->colormap, &style->text_aa[i]))
+      if (!gdk_colormap_alloc_color (style->colormap, &style->text_aa[i], FALSE, TRUE))
         g_warning ("unable to allocate color: ( %d %d %d )",
                    style->text_aa[i].red, style->text_aa[i].green, style->text_aa[i].blue);
       
@@ -1714,7 +1871,11 @@ gtk_style_real_unrealize (GtkStyle *style)
       gtk_gc_release (style->text_aa_gc[i]);
 
       if (style->bg_pixmap[i] &&  style->bg_pixmap[i] != (GdkPixmap*) GDK_PARENT_RELATIVE)
-       gdk_pixmap_unref (style->bg_pixmap[i]);
+       {
+         g_object_unref (style->bg_pixmap[i]);
+         style->bg_pixmap[i] = NULL;
+       }
+      
     }
   
   gdk_colormap_free_colors (style->colormap, style->fg, 5);
@@ -1725,6 +1886,8 @@ gtk_style_real_unrealize (GtkStyle *style)
   gdk_colormap_free_colors (style->colormap, style->text, 5);
   gdk_colormap_free_colors (style->colormap, style->base, 5);
   gdk_colormap_free_colors (style->colormap, style->text_aa, 5);
+
+  style_unrealize_cursor_gcs (style);
 }
 
 static void
@@ -1760,13 +1923,14 @@ gtk_style_real_set_background (GtkStyle    *style,
  * @source: the #GtkIconSource specifying the icon to render
  * @direction: a text direction
  * @state: a state
- * @size: the size to render the icon at
+ * @size: the size to render the icon at. A size of (GtkIconSize)-1
+ *        means render at the size of the source and don't scale.
  * @widget: the widget 
  * @detail: a style detail
  * @returns: a newly-created #GdkPixbuf containing the rendered icon
  *
  * Renders the icon specified by @source at the given @size 
- * according to the given parameterss and returns the result in a 
+ * according to the given parameters and returns the result in a 
  * pixbuf.
  */
 GdkPixbuf *
@@ -1864,8 +2028,7 @@ scale_or_ref (GdkPixbuf *src,
   if (width == gdk_pixbuf_get_width (src) &&
       height == gdk_pixbuf_get_height (src))
     {
-      gdk_pixbuf_ref (src);
-      return src;
+      return g_object_ref (src);
     }
   else
     {
@@ -1889,6 +2052,8 @@ gtk_default_render_icon (GtkStyle            *style,
   GdkPixbuf *scaled;
   GdkPixbuf *stated;
   GdkPixbuf *base_pixbuf;
+  GdkScreen *screen;
+  GtkSettings *settings;
 
   /* Oddly, style can be NULL in this function, because
    * GtkIconSet can be used without a style and if so
@@ -1898,20 +2063,38 @@ gtk_default_render_icon (GtkStyle            *style,
   base_pixbuf = gtk_icon_source_get_pixbuf (source);
 
   g_return_val_if_fail (base_pixbuf != NULL, NULL);
+
+  if (widget && gtk_widget_has_screen (widget))
+    {
+      screen = gtk_widget_get_screen (widget);
+      settings = gtk_settings_get_for_screen (screen);
+    }
+  else if (style && style->colormap)
+    {
+      screen = gdk_colormap_get_screen (style->colormap);
+      settings = gtk_settings_get_for_screen (screen);
+    }
+  else
+    {
+      settings = gtk_settings_get_default ();
+      GTK_NOTE (MULTIHEAD,
+               g_warning ("Using the default screen for gtk_default_render_icon()"));
+    }
+
   
-  if (!gtk_icon_size_lookup (size, &width, &height))
+  if (size != (GtkIconSize) -1 && !gtk_icon_size_lookup_for_settings (settings, size, &width, &height))
     {
-      g_warning (G_STRLOC ": invalid icon size `%d'", size);
+      g_warning (G_STRLOC ": invalid icon size '%d'", size);
       return NULL;
     }
 
-  /* If the size was wildcarded, then scale; otherwise, leave it
-   * alone.
+  /* If the size was wildcarded, and we're allowed to scale, then scale; otherwise,
+   * leave it alone.
    */
-  if (gtk_icon_source_get_size_wildcarded (source))
+  if (size != (GtkIconSize)-1 && gtk_icon_source_get_size_wildcarded (source))
     scaled = scale_or_ref (base_pixbuf, width, height);
   else
-    scaled = GDK_PIXBUF (g_object_ref (G_OBJECT (base_pixbuf)));
+    scaled = g_object_ref (base_pixbuf);
 
   /* If the state was wildcarded, then generate a state. */
   if (gtk_icon_source_get_state_wildcarded (source))
@@ -1923,7 +2106,7 @@ gtk_default_render_icon (GtkStyle            *style,
           gdk_pixbuf_saturate_and_pixelate (scaled, stated,
                                             0.8, TRUE);
           
-          gdk_pixbuf_unref (scaled);
+          g_object_unref (scaled);
         }
       else if (state == GTK_STATE_PRELIGHT)
         {
@@ -1932,7 +2115,7 @@ gtk_default_render_icon (GtkStyle            *style,
           gdk_pixbuf_saturate_and_pixelate (scaled, stated,
                                             1.2, FALSE);
           
-          gdk_pixbuf_unref (scaled);
+          g_object_unref (scaled);
         }
       else
         {
@@ -1945,52 +2128,17 @@ gtk_default_render_icon (GtkStyle            *style,
   return stated;
 }
 
-static gboolean
+static void
 sanitize_size (GdkWindow *window,
               gint      *width,
               gint      *height)
 {
-  gboolean set_bg = FALSE;
-
   if ((*width == -1) && (*height == -1))
-    {
-      set_bg = GDK_IS_WINDOW (window);
-      gdk_window_get_size (window, width, height);
-    }
+    gdk_drawable_get_size (window, width, height);
   else if (*width == -1)
-    gdk_window_get_size (window, width, NULL);
+    gdk_drawable_get_size (window, width, NULL);
   else if (*height == -1)
-    gdk_window_get_size (window, NULL, height);
-
-  return set_bg;
-}
-
-static void
-draw_part (GdkDrawable  *drawable,
-          GdkGC        *gc,
-          GdkRectangle *area,
-          gint          x,
-          gint          y,
-          IndicatorPart part)
-{
-  if (area)
-    gdk_gc_set_clip_rectangle (gc, area);
-  
-  if (!indicator_parts[part].bmap)
-    indicator_parts[part].bmap = gdk_bitmap_create_from_data (drawable,
-                                                             indicator_parts[part].bits,
-                                                             INDICATOR_PART_SIZE, INDICATOR_PART_SIZE);
-
-  gdk_gc_set_ts_origin (gc, x, y);
-  gdk_gc_set_stipple (gc, indicator_parts[part].bmap);
-  gdk_gc_set_fill (gc, GDK_STIPPLED);
-
-  gdk_draw_rectangle (drawable, gc, TRUE, x, y, INDICATOR_PART_SIZE, INDICATOR_PART_SIZE);
-
-  gdk_gc_set_fill (gc, GDK_SOLID);
-
-  if (area)
-    gdk_gc_set_clip_rectangle (gc, NULL);
+    gdk_drawable_get_size (window, NULL, height);
 }
 
 static void
@@ -2030,15 +2178,15 @@ gtk_default_draw_hline (GtkStyle     *style,
     {
       for (i = 0; i < thickness_dark; i++)
         {
-          gdk_draw_line (window, style->light_gc[state_type], x2 - i - 1, y + i, x2, y + i);
           gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x2 - i - 1, y + i);
+          gdk_draw_line (window, style->light_gc[state_type], x2 - i, y + i, x2, y + i);
         }
       
       y += thickness_dark;
       for (i = 0; i < thickness_light; i++)
         {
           gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x1 + thickness_light - i - 1, y + i);
-          gdk_draw_line (window, style->light_gc[state_type], x1 + thickness_light - i - 1, y + i, x2, y + i);
+          gdk_draw_line (window, style->light_gc[state_type], x1 + thickness_light - i, y + i, x2, y + i);
         }
     }
   
@@ -2077,15 +2225,15 @@ gtk_default_draw_vline (GtkStyle     *style,
       gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
     }
   for (i = 0; i < thickness_dark; i++)
-    {
-      gdk_draw_line (window, style->light_gc[state_type], x + i, y2 - i - 1, x + i, y2);
+    { 
       gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y2 - i - 1);
+      gdk_draw_line (window, style->light_gc[state_type], x + i, y2 - i, x + i, y2);
     }
   
   x += thickness_dark;
   for (i = 0; i < thickness_light; i++)
     {
-      gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y1 + thickness_light - i);
+      gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y1 + thickness_light - i - 1);
       gdk_draw_line (window, style->light_gc[state_type], x + i, y1 + thickness_light - i, x + i, y2);
     }
   if (area)
@@ -2095,8 +2243,7 @@ gtk_default_draw_vline (GtkStyle     *style,
     }
 }
 
-
-void
+static void
 draw_thin_shadow (GtkStyle      *style,
                  GdkWindow     *window,
                  GtkStateType   state,
@@ -2125,9 +2272,9 @@ draw_thin_shadow (GtkStyle      *style,
                 x + width - 1, y,  x + width - 1, y + height - 1);
       
   gdk_draw_line (window, gc2,
-                x, y, x + width - 1, y);
+                x, y, x + width - 2, y);
   gdk_draw_line (window, gc2,
-                x, y, x, y + height - 1);
+                x, y, x, y + height - 2);
 
   if (area)
     {
@@ -2136,130 +2283,145 @@ draw_thin_shadow (GtkStyle      *style,
     }
 }
 
-void
-draw_spin_entry_shadow (GtkStyle      *style,
-                       GdkWindow     *window,
-                       GtkStateType   state,
-                       GdkRectangle  *area,
-                       gint           x,
-                       gint           y,
-                       gint           width,
-                       gint           height)
+static void
+draw_spinbutton_shadow (GtkStyle        *style,
+                       GdkWindow       *window,
+                       GtkStateType     state,
+                       GtkTextDirection direction,
+                       GdkRectangle    *area,
+                       gint             x,
+                       gint             y,
+                       gint             width,
+                       gint             height)
 {
-  gint window_width, window_height;
-  gboolean focus_inset;
-
-  gdk_window_get_size (window, &window_width, &window_height);
-
-  if (width == -1)
-    width = window_width;
-  if (height == 1)
-    height = window_height;
+  sanitize_size (window, &width, &height);
 
-  focus_inset = (width < window_width && height < window_height);
-  
   if (area)
     {
-      gdk_gc_set_clip_rectangle (style->light_gc[state], area);
-      gdk_gc_set_clip_rectangle (style->dark_gc[state], area);
       gdk_gc_set_clip_rectangle (style->black_gc, area);
       gdk_gc_set_clip_rectangle (style->bg_gc[state], area);
-      gdk_gc_set_clip_rectangle (style->base_gc[state], area);
+      gdk_gc_set_clip_rectangle (style->dark_gc[state], area);
+      gdk_gc_set_clip_rectangle (style->light_gc[state], area);
     }
 
-  gdk_draw_line (window, style->light_gc[state],
-                x, y + height - 1, x + width - 1, y + height - 1);
-
-  gdk_draw_line (window, 
-                style->base_gc[state],
-                x + width - 1,  y + 1, x + width - 1,  y + height - 3);
-      
-  if (!focus_inset)
+  if (direction == GTK_TEXT_DIR_LTR)
     {
+      gdk_draw_line (window, style->dark_gc[state],
+                    x, y, x + width - 1, y);
+      gdk_draw_line (window, style->black_gc,
+                    x, y + 1, x + width - 2, y + 1);
+      gdk_draw_line (window, style->black_gc,
+                    x + width - 2, y + 2, x + width - 2, y + height - 3);
+      gdk_draw_line (window, style->light_gc[state],
+                    x + width - 1, y + 1, x + width - 1, y + height - 2);
+      gdk_draw_line (window, style->light_gc[state],
+                    x, y + height - 1, x + width - 1, y + height - 1);
       gdk_draw_line (window, style->bg_gc[state],
-                    x + 1, y + height - 2, x + width - 1, y + height - 2);
-      gdk_draw_line (window, 
-                    style->base_gc[state],
-                    x + width - 2, y + 1, x + width - 2, y + height - 3);
-  
+                    x, y + height - 2, x + width - 2, y + height - 2);
+      gdk_draw_line (window, style->black_gc,
+                    x, y + 2, x, y + height - 3);
+    }
+  else
+    {
+      gdk_draw_line (window, style->dark_gc[state],
+                    x, y, x + width - 1, y);
+      gdk_draw_line (window, style->dark_gc[state],
+                    x, y + 1, x, y + height - 1);
       gdk_draw_line (window, style->black_gc,
                     x + 1, y + 1, x + width - 1, y + 1);
       gdk_draw_line (window, style->black_gc,
-                    x + 1, y + 1, x + 1, y + height - 2);
+                    x + 1, y + 2, x + 1, y + height - 2);
+      gdk_draw_line (window, style->black_gc,
+                    x + width - 1, y + 2, x + width - 1, y + height - 3);
+      gdk_draw_line (window, style->light_gc[state],
+                    x + 1, y + height - 1, x + width - 1, y + height - 1);
+      gdk_draw_line (window, style->bg_gc[state],
+                    x + 2, y + height - 2, x + width - 1, y + height - 2);
     }
-      
-  gdk_draw_line (window, style->dark_gc[state],
-                x, y, x + width - 1, y);
-  gdk_draw_line (window, style->dark_gc[state],
-                x, y, x, y + height - 1);
-
+  
   if (area)
     {
-      gdk_gc_set_clip_rectangle (style->light_gc[state], NULL);
-      gdk_gc_set_clip_rectangle (style->dark_gc[state], NULL);
       gdk_gc_set_clip_rectangle (style->black_gc, NULL);
       gdk_gc_set_clip_rectangle (style->bg_gc[state], NULL);
-      gdk_gc_set_clip_rectangle (style->base_gc[state], NULL);
+      gdk_gc_set_clip_rectangle (style->dark_gc[state], NULL);
+      gdk_gc_set_clip_rectangle (style->light_gc[state], NULL);
     }
 }
 
 static void
-draw_spinbutton_shadow (GtkStyle      *style,
-                       GdkWindow     *window,
-                       GtkStateType   state,
-                       GdkRectangle  *area,
-                       gint           x,
-                       gint           y,
-                       gint           width,
-                       gint           height)
+draw_menu_shadow (GtkStyle        *style,
+                 GdkWindow       *window,
+                 GtkStateType     state,
+                 GdkRectangle    *area,
+                 gint             x,
+                 gint             y,
+                 gint             width,
+                 gint             height)
 {
-  gint y_middle = y + height / 2;
-
-  sanitize_size (window, &width, &height);
-  
-  if (area)
+  if (style->ythickness > 0)
     {
-      gdk_gc_set_clip_rectangle (style->black_gc, area);
-      gdk_gc_set_clip_rectangle (style->bg_gc[state], area);
-      gdk_gc_set_clip_rectangle (style->dark_gc[state], area);
-      gdk_gc_set_clip_rectangle (style->light_gc[state], area);
+      if (style->ythickness > 1)
+       {
+         gdk_draw_line (window, style->dark_gc[state],
+                        x + 1, y + height - 2, x + width - 2, y + height - 2);
+         gdk_draw_line (window, style->black_gc,
+                        x, y + height - 1, x + width - 1, y + height - 1);
+       }
+      else
+       {
+         gdk_draw_line (window, style->dark_gc[state],
+                        x + 1, y + height - 1, x + width - 1, y + height - 1);
+       }
     }
   
-  gdk_draw_line (window, style->black_gc,
-                x, y + 2, x, y + height - 3);
-  gdk_draw_line (window, style->black_gc,
-                x, y + 1, x + width - 2, y + 1);
-  gdk_draw_line (window, style->black_gc,
-                x + width - 2, y + 2, x + width - 2, y + height - 3);
-  
-  gdk_draw_line (window, style->bg_gc[state],
-                x, y + height - 2, x + width - 2, y + height - 2);
-
-  gdk_draw_line (window, style->dark_gc[state],
-                x, y, x + width - 1, y);
-  gdk_draw_line (window, style->dark_gc[state],
-                x + 1, y_middle - 1, x + width - 3, y_middle - 1);
-  gdk_draw_line (window, style->dark_gc[state],
-                x + 1, y + height - 3, x + width - 3, y + height - 3);
-
-  gdk_draw_line (window, style->light_gc[state],
-                x + 1, y + 2, x + width - 3, y + 2);
-  gdk_draw_line (window, style->light_gc[state],
-                x + 1, y_middle, x + width - 3, y_middle);
-  gdk_draw_line (window, style->light_gc[state],
-                x + width - 1, y + 1, x + width - 1, y + height - 1);
-  gdk_draw_line (window, style->light_gc[state],
-                x, y + height - 1, x + width - 2, y + height - 1);
-      
-  if (area)
+  if (style->xthickness > 0)
     {
-      gdk_gc_set_clip_rectangle (style->black_gc, NULL);
-      gdk_gc_set_clip_rectangle (style->bg_gc[state], NULL);
-      gdk_gc_set_clip_rectangle (style->dark_gc[state], NULL);
-      gdk_gc_set_clip_rectangle (style->light_gc[state], NULL);
+      if (style->xthickness > 1)
+       {
+         gdk_draw_line (window, style->dark_gc[state],
+                        x + width - 2, y + 1, x + width - 2, y + height - 2);
+         
+         gdk_draw_line (window, style->black_gc,
+                        x + width - 1, y, x + width - 1, y + height - 1);
+       }
+      else
+       {
+         gdk_draw_line (window, style->dark_gc[state],
+                        x + width - 1, y + 1, x + width - 1, y + height - 1);
+       }
     }
+  
+  /* Light around top and left */
+  
+  if (style->ythickness > 0)
+    gdk_draw_line (window, style->black_gc,
+                  x, y, x + width - 2, y);
+  if (style->xthickness > 0)
+    gdk_draw_line (window, style->black_gc,
+                  x, y, x, y + height - 2);
+  
+  if (style->ythickness > 1)
+    gdk_draw_line (window, style->light_gc[state],
+                  x + 1, y + 1, x + width - 3, y + 1);
+  if (style->xthickness > 1)
+    gdk_draw_line (window, style->light_gc[state],
+                  x + 1, y + 1, x + 1, y + height - 3);
+}
+
+static GtkTextDirection
+get_direction (GtkWidget *widget)
+{
+  GtkTextDirection dir;
+  
+  if (widget)
+    dir = gtk_widget_get_direction (widget);
+  else
+    dir = GTK_TEXT_DIR_LTR;
+  
+  return dir;
 }
 
+
 static void
 gtk_default_draw_shadow (GtkStyle      *style,
                          GdkWindow     *window,
@@ -2299,21 +2461,21 @@ gtk_default_draw_shadow (GtkStyle      *style,
                            x, y, width, height);
          return;
        }
-      else if (widget && GTK_IS_SPIN_BUTTON (widget) &&
-              detail && strcmp (detail, "entry") == 0)
-       {
-         draw_spin_entry_shadow (style, window, state_type, area,
-                                 x, y, width, height);
-         return;
-       }
-      else if (widget && GTK_IS_SPIN_BUTTON (widget) &&
-              detail && strcmp (detail, "spinbutton") == 0)
+      if (widget && GTK_IS_SPIN_BUTTON (widget) &&
+         detail && strcmp (detail, "spinbutton") == 0)
        {
-         draw_spinbutton_shadow (style, window, state_type,
-                                 area, x, y, width, height);
+         draw_spinbutton_shadow (style, window, state_type, 
+                                 get_direction (widget), area, x, y, width, height);
+         
          return;
        }
     }
+
+  if (shadow_type == GTK_SHADOW_OUT && detail && strcmp (detail, "menu") == 0)
+    {
+      draw_menu_shadow (style, window, state_type, area, x, y, width, height);
+      return;
+    }
   
   sanitize_size (window, &width, &height);
   
@@ -2424,17 +2586,17 @@ gtk_default_draw_shadow (GtkStyle      *style,
 
       if (style->ythickness > 0)
         gdk_draw_line (window, gc2,
-                       x, y, x + width - 1, y);
+                       x, y, x + width - 2, y);
       if (style->xthickness > 0)
         gdk_draw_line (window, gc2,
-                       x, y, x, y + height - 1);
+                       x, y, x, y + height - 2);
 
       if (style->ythickness > 1)
         gdk_draw_line (window, style->bg_gc[state_type],
-                       x + 1, y + 1, x + width - 2, y + 1);
+                       x + 1, y + 1, x + width - 3, y + 1);
       if (style->xthickness > 1)
         gdk_draw_line (window, style->bg_gc[state_type],
-                       x + 1, y + 1, x + 1, y + height - 2);
+                       x + 1, y + 1, x + 1, y + height - 3);
       break;
       
     case GTK_SHADOW_ETCHED_IN:
@@ -2512,7 +2674,7 @@ gtk_default_draw_shadow (GtkStyle      *style,
                   gdk_draw_line (window, gc1,
                                  x + thickness_dark + i,
                                  y + thickness_dark + i,
-                                 x + width - thickness_dark - i - 1,
+                                 x + width - thickness_dark - i - 2,
                                  y + thickness_dark + i);
           
                   gdk_draw_line (window, gc2,
@@ -2535,11 +2697,57 @@ gtk_default_draw_shadow (GtkStyle      *style,
       
       break;
     }
-  if (area)
+
+  if (shadow_type == GTK_SHADOW_IN &&
+      widget && GTK_IS_SPIN_BUTTON (widget) &&
+      detail && strcmp (detail, "entry") == 0)
     {
-      gdk_gc_set_clip_rectangle (gc1, NULL);
-      gdk_gc_set_clip_rectangle (gc2, NULL);
-      if (shadow_type == GTK_SHADOW_IN || 
+      if (get_direction (widget) == GTK_TEXT_DIR_LTR)
+       {
+         gdk_draw_line (window,
+                        style->base_gc[state_type],
+                        x + width - 1, y + 2,
+                        x + width - 1, y + height - 3);
+         gdk_draw_line (window,
+                        style->base_gc[state_type],
+                        x + width - 2, y + 2,
+                        x + width - 2, y + height - 3);
+         gdk_draw_point (window,
+                         style->black_gc,
+                         x + width - 1, y + 1);
+         gdk_draw_point (window,
+                         style->bg_gc[state_type],
+                         x + width - 1, y + height - 2);
+       }
+      else
+       {
+         gdk_draw_line (window,
+                        style->base_gc[state_type],
+                        x, y + 2,
+                        x, y + height - 3);
+         gdk_draw_line (window,
+                        style->base_gc[state_type],
+                        x + 1, y + 2,
+                        x + 1, y + height - 3);
+         gdk_draw_point (window,
+                         style->black_gc,
+                         x, y + 1);
+         gdk_draw_line (window,
+                        style->bg_gc[state_type],
+                        x, y + height - 2,
+                        x + 1, y + height - 2);
+         gdk_draw_point (window,
+                         style->light_gc[state_type],
+                         x, y + height - 1);
+       }
+    }
+
+
+  if (area)
+    {
+      gdk_gc_set_clip_rectangle (gc1, NULL);
+      gdk_gc_set_clip_rectangle (gc2, NULL);
+      if (shadow_type == GTK_SHADOW_IN || 
           shadow_type == GTK_SHADOW_OUT)
         {
           gdk_gc_set_clip_rectangle (style->black_gc, NULL);
@@ -2683,109 +2891,122 @@ gtk_default_draw_polygon (GtkStyle      *style,
 }
 
 static void
-draw_varrow (GdkWindow     *window,
-            GdkGC         *gc,
-            GtkShadowType  shadow_type,
-            GdkRectangle  *area,
-            GtkArrowType   arrow_type,
-            gint           x,
-            gint           y,
-            gint           width,
-            gint           height)
+draw_arrow (GdkWindow     *window,
+           GdkColor      *color,
+           GdkRectangle  *area,
+           GtkArrowType   arrow_type,
+           gint           x,
+           gint           y,
+           gint           width,
+           gint           height)
 {
-  gint steps, extra;
-  gint y_start, y_increment;
-  gint i;
-
-  if (area)
-    gdk_gc_set_clip_rectangle (gc, area);
-  
-  width = width + width % 2 - 1;       /* Force odd */
+  cairo_t *cr = gdk_cairo_create (window);
+  gdk_cairo_set_source_color (cr, color);
   
-  steps = 1 + width / 2;
-
-  extra = height - steps;
-
+  if (area)
+    {
+      gdk_cairo_rectangle (cr, area);
+      cairo_clip (cr);
+    }
+    
   if (arrow_type == GTK_ARROW_DOWN)
     {
-      y_start = y;
-      y_increment = 1;
+      cairo_move_to (cr, x,              y);
+      cairo_line_to (cr, x + width,      y);
+      cairo_line_to (cr, x + width / 2., y + height);
     }
-  else
+  else if (arrow_type == GTK_ARROW_UP)
     {
-      y_start = y + height - 1;
-      y_increment = -1;
+      cairo_move_to (cr, x,              y + height);
+      cairo_line_to (cr, x + width / 2., y);
+      cairo_line_to (cr, x + width,      y + height);
     }
-
-  for (i = 0; i < extra; i++)
+  else if (arrow_type == GTK_ARROW_LEFT)
     {
-      gdk_draw_line (window, gc,
-                    x,              y_start + i * y_increment,
-                    x + width - 1,  y_start + i * y_increment);
+      cairo_move_to (cr, x + width,      y);
+      cairo_line_to (cr, x + width,      y + height);
+      cairo_line_to (cr, x,              y + height / 2.);
     }
-  for (; i < height; i++)
+  else if (arrow_type == GTK_ARROW_RIGHT)
     {
-      gdk_draw_line (window, gc,
-                    x + (i - extra),              y_start + i * y_increment,
-                    x + width - (i - extra) - 1,  y_start + i * y_increment);
+      cairo_move_to (cr, x,              y);
+      cairo_line_to (cr, x + width,      y + height / 2.);
+      cairo_line_to (cr, x,              y + height);
     }
-  
 
-  if (area)
-    gdk_gc_set_clip_rectangle (gc, NULL);
+  cairo_close_path (cr);
+  cairo_fill (cr);
+
+  cairo_destroy (cr);
 }
 
 static void
-draw_harrow (GdkWindow     *window,
-            GdkGC         *gc,
-            GtkShadowType  shadow_type,
-            GdkRectangle  *area,
-            GtkArrowType   arrow_type,
-            gint           x,
-            gint           y,
-            gint           width,
-            gint           height)
+calculate_arrow_geometry (GtkArrowType  arrow_type,
+                         gint         *x,
+                         gint         *y,
+                         gint         *width,
+                         gint         *height)
 {
-  gint steps, extra;
-  gint x_start, x_increment;
-  gint i;
-
-  if (area)
-    gdk_gc_set_clip_rectangle (gc, area);
+  gint w = *width;
+  gint h = *height;
   
-  height = height + height % 2 - 1;    /* Force odd */
-  
-  steps = 1 + height / 2;
-
-  extra = width - steps;
-
-  if (arrow_type == GTK_ARROW_RIGHT)
-    {
-      x_start = x;
-      x_increment = 1;
-    }
-  else
+  switch (arrow_type)
     {
-      x_start = x + width - 1;
-      x_increment = -1;
-    }
+    case GTK_ARROW_UP:
+    case GTK_ARROW_DOWN:
+      w += (w % 2) - 1;
+      h = (w / 2 + 1);
+      
+      if (h > *height)
+       {
+         h = *height;
+         w = 2 * h - 1;
+       }
+      
+      if (arrow_type == GTK_ARROW_DOWN)
+       {
+         if (*height % 2 == 1 || h % 2 == 0)
+           *height += 1;
+       }
+      else
+       {
+         if (*height % 2 == 0 || h % 2 == 0)
+           *height -= 1;
+       }
+      break;
 
-  for (i = 0; i < extra; i++)
-    {
-      gdk_draw_line (window, gc,
-                    x_start + i * x_increment, y,
-                    x_start + i * x_increment, y + height - 1);
-    }
-  for (; i < width; i++)
-    {
-      gdk_draw_line (window, gc,
-                    x_start + i * x_increment, y + (i - extra),
-                    x_start + i * x_increment, y + height - (i - extra) - 1);
+    case GTK_ARROW_RIGHT:
+    case GTK_ARROW_LEFT:
+      h += (h % 2) - 1;
+      w = (h / 2 + 1);
+      
+      if (w > *width)
+       {
+         w = *width;
+         h = 2 * w - 1;
+       }
+      
+      if (arrow_type == GTK_ARROW_RIGHT)
+       {
+         if (*width % 2 == 1 || w % 2 == 0)
+           *width += 1;
+       }
+      else
+       {
+         if (*width % 2 == 0 || w % 2 == 0)
+           *width -= 1;
+       }
+      break;
+      
+    default:
+      /* should not be reached */
+      break;
     }
-  
 
-  if (area)
-    gdk_gc_set_clip_rectangle (gc, NULL);
+  *x += (*width - w) / 2;
+  *y += (*height - h) / 2;
+  *height = h;
+  *width = w;
 }
 
 static void
@@ -2803,77 +3024,23 @@ gtk_default_draw_arrow (GtkStyle      *style,
                        gint           width,
                        gint           height)
 {
-  sanitize_size (window, &width, &height);
+  gint original_width, original_x;
   
-  if (detail && strcmp (detail, "spinbutton") == 0)
-    {
-      int hpad, vpad;
-      int my_height = height;
-      int my_width = width;
-      int vpad_add = 0;
-
-      if (my_height > my_width)
-       {
-         vpad_add = (my_height - my_width) / 2;
-         my_height = my_width;
-       }
-
-      hpad = my_width / 4;
-
-      if (hpad < 4)
-       hpad = 4;
-
-      vpad = 2 * hpad - 1;
+  sanitize_size (window, &width, &height);
 
-      x += hpad / 2;
-      y += vpad / 2;
+  original_width = width;
+  original_x = x;
 
-      y += vpad_add;
+  calculate_arrow_geometry (arrow_type, &x, &y, &width, &height);
 
-      draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
-                  x, y, my_width - hpad, my_height - vpad);
-    }
-  else if (detail && strcmp (detail, "vscrollbar") == 0)
-    {
-      gtk_paint_box (style, window, state, shadow, area,
-                    widget, detail, x, y, width, height);
-      
-      x += (width - 7) / 2;
-      y += (height - 5) / 2;
-      
-      draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
-                  x, y, 7, 5);
-    }
-  else if (detail && strcmp (detail, "hscrollbar") == 0)
-    {
-      gtk_paint_box (style, window, state, shadow, area,
-                    widget, detail, x, y, width, height);
-      
-      y += (height - 7) / 2;
-      x += (width - 5) / 2;
+  if (detail && strcmp (detail, "menu_scroll_arrow_up") == 0)
+    y++;
 
-      draw_harrow (window, style->fg_gc[state], shadow, area, arrow_type,
-                  x, y, 5, 7);
-    }
-  else
-    {
-      if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
-       {
-         x += (width - 7) / 2;
-         y += (height - 5) / 2;
-         
-         draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
-                      x, y, 7, 5);
-       }
-      else
-       {
-         x += (width - 5) / 2;
-         y += (height - 7) / 2;
-         
-         draw_harrow (window, style->fg_gc[state], shadow, area, arrow_type,
-                      x, y, 5, 7);
-       }
-    }
+  if (state == GTK_STATE_INSENSITIVE)
+    draw_arrow (window, &style->white, area, arrow_type,
+               x + 1, y + 1, width, height);
+  draw_arrow (window, &style->fg[state], area, arrow_type,
+             x, y, width, height);
 }
 
 static void
@@ -3024,9 +3191,13 @@ gtk_default_draw_string (GtkStyle      *style,
                          gint           y,
                          const gchar   *string)
 {
+  GdkDisplay *display;
+  
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (window != NULL);
   
+  display = gdk_drawable_get_display (window);
+  
   if (area)
     {
       gdk_gc_set_clip_rectangle (style->white_gc, area);
@@ -3034,9 +3205,13 @@ gtk_default_draw_string (GtkStyle      *style,
     }
 
   if (state_type == GTK_STATE_INSENSITIVE)
-    gdk_draw_string (window, gtk_style_get_font (style), style->white_gc, x + 1, y + 1, string);
+    gdk_draw_string (window,
+                    gtk_style_get_font_internal (style),
+                    style->white_gc, x + 1, y + 1, string);
 
-  gdk_draw_string (window, gtk_style_get_font (style), style->fg_gc[state_type], x, y, string);
+  gdk_draw_string (window,
+                  gtk_style_get_font_internal (style),
+                  style->fg_gc[state_type], x, y, string);
 
   if (area)
     {
@@ -3055,8 +3230,8 @@ option_menu_get_props (GtkWidget      *widget,
   
   if (widget)
     gtk_widget_style_get (widget, 
-                         "indicator_size", &tmp_size,
-                         "indicator_spacing", &tmp_spacing,
+                         "indicator-size", &tmp_size,
+                         "indicator-spacing", &tmp_spacing,
                          NULL);
 
   if (tmp_size)
@@ -3089,27 +3264,94 @@ gtk_default_draw_box (GtkStyle      *style,
                      gint           width,
                      gint           height)
 {
+  gboolean is_spinbutton_box = FALSE;
+  
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (window != NULL);
   
   sanitize_size (window, &width, &height);
+
+  if (widget && GTK_IS_SPIN_BUTTON (widget) && detail)
+    {
+      if (strcmp (detail, "spinbutton_up") == 0)
+       {
+         y += 2;
+         width -= 3;
+         height -= 2;
+
+         if (get_direction (widget) == GTK_TEXT_DIR_RTL)
+           x += 2;
+         else
+           x += 1;
+
+         is_spinbutton_box = TRUE;
+       }
+      else if (strcmp (detail, "spinbutton_down") == 0)
+       {
+         width -= 3;
+         height -= 2;
+
+         if (get_direction (widget) == GTK_TEXT_DIR_RTL)
+           x += 2;
+         else
+           x += 1;
+
+         is_spinbutton_box = TRUE;
+       }
+    }
   
   if (!style->bg_pixmap[state_type] || 
       GDK_IS_PIXMAP (window))
     {
+      GdkGC *gc = style->bg_gc[state_type];
+      
+      if (state_type == GTK_STATE_SELECTED && detail && strcmp (detail, "paned") == 0)
+       {
+         if (widget && !GTK_WIDGET_HAS_FOCUS (widget))
+           gc = style->base_gc[GTK_STATE_ACTIVE];
+       }
+
       if (area)
-       gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
+       gdk_gc_set_clip_rectangle (gc, area);
 
-      gdk_draw_rectangle (window, style->bg_gc[state_type], TRUE,
+      gdk_draw_rectangle (window, gc, TRUE,
                           x, y, width, height);
       if (area)
-       gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
+       gdk_gc_set_clip_rectangle (gc, NULL);
     }
   else
     gtk_style_apply_default_background (style, window,
                                         widget && !GTK_WIDGET_NO_WINDOW (widget),
                                         state_type, area, x, y, width, height);
-  
+
+  if (is_spinbutton_box)
+    {
+      GdkGC *upper_gc;
+      GdkGC *lower_gc;
+      
+      lower_gc = style->dark_gc[state_type];
+      if (shadow_type == GTK_SHADOW_OUT)
+       upper_gc = style->light_gc[state_type];
+      else
+       upper_gc = style->dark_gc[state_type];
+
+      if (area)
+       {
+         gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
+         gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
+       }
+      
+      gdk_draw_line (window, upper_gc, x, y, x + width - 1, y);
+      gdk_draw_line (window, lower_gc, x, y + height - 1, x + width - 1, y + height - 1);
+
+      if (area)
+       {
+         gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
+         gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
+       }
+      return;
+    }
+
   gtk_paint_shadow (style, window, state_type, shadow_type, area, widget, detail,
                     x, y, width, height);
 
@@ -3117,16 +3359,22 @@ gtk_default_draw_box (GtkStyle      *style,
     {
       GtkRequisition indicator_size;
       GtkBorder indicator_spacing;
+      gint vline_x;
 
       option_menu_get_props (widget, &indicator_size, &indicator_spacing);
 
       sanitize_size (window, &width, &height);
-  
+
+      if (get_direction (widget) == GTK_TEXT_DIR_RTL)
+       vline_x = x + indicator_size.width + indicator_spacing.left + indicator_spacing.right;
+      else 
+       vline_x = x + width - (indicator_size.width + indicator_spacing.left + indicator_spacing.right) - style->xthickness;
+
       gtk_paint_vline (style, window, state_type, area, widget,
                       detail,
                       y + style->ythickness + 1,
                       y + height - style->ythickness - 3,
-                      x + width - (indicator_size.width + indicator_spacing.left + indicator_spacing.right) - style->xthickness);
+                      vline_x);
     }
 }
 
@@ -3136,7 +3384,7 @@ get_darkened_gc (GdkWindow *window,
                  gint       darken_count)
 {
   GdkColor src = *color;
-  GdkColor shaded;
+  GdkColor shaded = *color;
   GdkGC *gc;
   
   gc = gdk_gc_new (window);
@@ -3147,7 +3395,7 @@ get_darkened_gc (GdkWindow *window,
       src = shaded;
       --darken_count;
     }
-  
+   
   gdk_gc_set_rgb_fg_color (gc, &shaded);
 
   return gc;
@@ -3206,27 +3454,115 @@ gtk_default_draw_flat_box (GtkStyle      *style,
            * for that row.
            */
 
-          /* FIXME when we have style properties, clean this up.
-           */
-          
           else if (!strcmp ("cell_even", detail) ||
                    !strcmp ("cell_odd", detail) ||
                    !strcmp ("cell_even_ruled", detail))
             {
-             gc1 = style->base_gc[state_type];
+             GdkColor *color = NULL;
+
+             gtk_widget_style_get (widget,
+                                   "even-row-color", &color,
+                                   NULL);
+
+             if (color)
+               {
+                 freeme = get_darkened_gc (window, color, 0);
+                 gc1 = freeme;
+
+                 gdk_color_free (color);
+               }
+             else
+               gc1 = style->base_gc[state_type];
             }
+         else if (!strcmp ("cell_odd_ruled", detail))
+           {
+             GdkColor *color;
+
+             gtk_widget_style_get (widget,
+                                   "odd-row-color", &color,
+                                   NULL);
+
+             if (color)
+               {
+                 freeme = get_darkened_gc (window, color, 0);
+                 gc1 = freeme;
+
+                 gdk_color_free (color);
+               }
+             else
+               {
+                 gtk_widget_style_get (widget,
+                                       "even-row-color", &color,
+                                       NULL);
+
+                 if (color)
+                   {
+                     freeme = get_darkened_gc (window, color, 1);
+                     gdk_color_free (color);
+                   }
+                 else
+                   freeme = get_darkened_gc (window, &style->base[state_type], 1);
+                 gc1 = freeme;
+               }
+           }
           else if (!strcmp ("cell_even_sorted", detail) ||
                    !strcmp ("cell_odd_sorted", detail) ||
-                   !strcmp ("cell_odd_ruled", detail) ||
                    !strcmp ("cell_even_ruled_sorted", detail))
             {
-             freeme = get_darkened_gc (window, &style->base[state_type], 1);
-              gc1 = freeme;
+             GdkColor *color = NULL;
+
+             if (!strcmp ("cell_odd_sorted", detail))
+               gtk_widget_style_get (widget,
+                                     "odd-row-color", &color,
+                                     NULL);
+             else
+               gtk_widget_style_get (widget,
+                                     "even-row-color", &color,
+                                     NULL);
+
+             if (color)
+               {
+                 freeme = get_darkened_gc (window, color, 1);
+                 gc1 = freeme;
+
+                 gdk_color_free (color);
+               }
+             else
+               {
+                 freeme = get_darkened_gc (window, &style->base[state_type], 1);
+                  gc1 = freeme;
+               }
             }
           else if (!strcmp ("cell_odd_ruled_sorted", detail))
             {
-              freeme = get_darkened_gc (window, &style->base[state_type], 2);
-              gc1 = freeme;
+             GdkColor *color = NULL;
+
+             gtk_widget_style_get (widget,
+                                   "odd-row-color", &color,
+                                   NULL);
+
+             if (color)
+               {
+                 freeme = get_darkened_gc (window, color, 1);
+                 gc1 = freeme;
+
+                 gdk_color_free (color);
+               }
+             else
+               {
+                 gtk_widget_style_get (widget,
+                                       "even-row-color", &color,
+                                       NULL);
+
+                 if (color)
+                   {
+                     freeme = get_darkened_gc (window, color, 2);
+                     gdk_color_free (color);
+                   }
+                 else
+                    freeme = get_darkened_gc (window, &style->base[state_type], 2);
+                  gc1 = freeme;
+               }
             }
           else
             gc1 = style->bg_gc[state_type];
@@ -3258,7 +3594,7 @@ gtk_default_draw_flat_box (GtkStyle      *style,
 
 
   if (freeme)
-    g_object_unref (G_OBJECT (freeme));
+    g_object_unref (freeme);
 }
 
 static void 
@@ -3274,56 +3610,116 @@ gtk_default_draw_check (GtkStyle      *style,
                        gint           width,
                        gint           height)
 {
-  if (detail && strcmp (detail, "cellcheck") == 0)
-    {
-      gdk_draw_rectangle (window,
-                         widget->style->base_gc[state_type],
-                         TRUE,
-                          x, y,
-                         width, height);
-      gdk_draw_rectangle (window,
-                         widget->style->text_gc[state_type],
-                         FALSE,
-                          x, y,
-                         width, height);
-
-      x -= (1 + INDICATOR_PART_SIZE - width) / 2;
-      y -= (((1 + INDICATOR_PART_SIZE - height) / 2) - 1);
-      if (shadow_type == GTK_SHADOW_IN)
-       {
-         draw_part (window, style->text_gc[state_type], area, x, y, CHECK_TEXT);
-         draw_part (window, style->text_aa_gc[state_type], area, x, y, CHECK_AA);
-       }
-    }
-  else
+  cairo_t *cr = gdk_cairo_create (window);
+  enum { BUTTON, MENU, CELL } type = BUTTON;
+  int exterior_size;
+  int interior_size;
+  int pad;
+  
+  if (detail)
     {
-      x -= (1 + INDICATOR_PART_SIZE - width) / 2;
-      y -= (1 + INDICATOR_PART_SIZE - height) / 2;
+      if (strcmp (detail, "cellcheck") == 0)
+       type = CELL;
+      else if (strcmp (detail, "check") == 0)
+       type = MENU;
+    }
       
-      if (strcmp (detail, "check") == 0)       /* Menu item */
-       {
-         if (shadow_type == GTK_SHADOW_IN)
-           {
-             draw_part (window, style->black_gc, area, x, y, CHECK_TEXT);
-             draw_part (window, style->dark_gc[state_type], area, x, y, CHECK_AA);
-           }
-       }
+  if (area)
+    {
+      gdk_cairo_rectangle (cr, area);
+      cairo_clip (cr);
+    }
+  
+  exterior_size = MIN (width, height);
+  if (exterior_size % 2 == 0) /* Ensure odd */
+    exterior_size -= -1;
+
+  pad = style->xthickness + MAX (1, (exterior_size - 2 * style->xthickness) / 9);
+  interior_size = MAX (1, exterior_size - 2 * pad);
+
+  if (interior_size < 7)
+    {
+      interior_size = 7;
+      pad = MAX (0, (exterior_size - interior_size) / 2);
+    }
+
+  x -= (1 + exterior_size - width) / 2;
+  y -= (1 + exterior_size - height) / 2;
+
+  switch (type)
+    {
+    case BUTTON:
+    case CELL:
+      if (type == BUTTON)
+       gdk_cairo_set_source_color (cr, &style->fg[state_type]);
       else
-       {
-         draw_part (window, style->black_gc, area, x, y, CHECK_BLACK);
-         draw_part (window, style->dark_gc[state_type], area, x, y, CHECK_DARK);
-         draw_part (window, style->mid_gc[state_type], area, x, y, CHECK_MID);
-         draw_part (window, style->light_gc[state_type], area, x, y, CHECK_LIGHT);
-         draw_part (window, style->base_gc[state_type], area, x, y, CHECK_BASE);
-         
-         if (shadow_type == GTK_SHADOW_IN)
-           {
-             draw_part (window, style->text_gc[state_type], area, x, y, CHECK_TEXT);
-             draw_part (window, style->text_aa_gc[state_type], area, x, y, CHECK_AA);
-           }
-       }
+       gdk_cairo_set_source_color (cr, &style->text[state_type]);
+       
+      cairo_set_line_width (cr, 1.0);
+      cairo_rectangle (cr, x + 0.5, y + 0.5, exterior_size - 1, exterior_size - 1);
+      cairo_stroke (cr);
+
+      gdk_cairo_set_source_color (cr, &style->base[state_type]);
+      cairo_rectangle (cr, x + 1, y + 1, exterior_size - 2, exterior_size - 2);
+      cairo_fill (cr);
+      break;
+
+    case MENU:
+      break;
+    }
+      
+  switch (type)
+    {
+    case BUTTON:
+    case CELL:
+      gdk_cairo_set_source_color (cr, &style->text[state_type]);
+      break;
+    case MENU:
+      gdk_cairo_set_source_color (cr, &style->fg[state_type]);
+      break;
+    }
+
+  if (shadow_type == GTK_SHADOW_IN)
+    {
+      cairo_translate (cr,
+                      x + pad, y + pad);
+      
+      cairo_scale (cr, interior_size / 7., interior_size / 7.);
+      
+      cairo_move_to  (cr, 7.0, 0.0);
+      cairo_line_to  (cr, 7.5, 1.0);
+      cairo_curve_to (cr, 5.3, 2.0,
+                     4.3, 4.0,
+                     3.5, 7.0);
+      cairo_curve_to (cr, 3.0, 5.7,
+                     1.3, 4.7,
+                     0.0, 4.7);
+      cairo_line_to  (cr, 0.2, 3.5);
+      cairo_curve_to (cr, 1.1, 3.5,
+                     2.3, 4.3,
+                     3.0, 5.0);
+      cairo_curve_to (cr, 1.0, 3.9,
+                     2.4, 4.1,
+                     3.2, 4.9);
+      cairo_curve_to (cr, 3.5, 3.1,
+                     5.2, 2.0,
+                     7.0, 0.0);
+      
+      cairo_fill (cr);
     }
+  else if (shadow_type == GTK_SHADOW_ETCHED_IN) /* inconsistent */
+    {
+      int line_thickness = MAX (1, (3 + interior_size * 2) / 7);
 
+      cairo_rectangle (cr,
+                      x + pad,
+                      y + pad + (1 + interior_size - line_thickness) / 2,
+                      interior_size,
+                      line_thickness);
+      cairo_fill (cr);
+    }
+  
+  cairo_destroy (cr);
 }
 
 static void 
@@ -3339,50 +3735,111 @@ gtk_default_draw_option (GtkStyle      *style,
                         gint           width,
                         gint           height)
 {
-  if (detail && strcmp (detail, "cellradio") == 0)
+  cairo_t *cr = gdk_cairo_create (window);
+  enum { BUTTON, MENU, CELL } type = BUTTON;
+  int exterior_size;
+  
+  if (detail)
     {
-      gdk_draw_arc (window,
-                   widget->style->fg_gc[state_type],
-                   FALSE,
-                    x, y,
-                   width,
-                   height,
-                   0, 360*64);
-
-      if (shadow_type == GTK_SHADOW_IN)
-       {
-         gdk_draw_arc (window,
-                       widget->style->fg_gc[state_type],
-                       TRUE,
-                        x + 2,
-                        y + 2,
-                       width - 4,
-                       height - 4,
-                       0, 360*64);
-       }
+      if (strcmp (detail, "radio") == 0)
+       type = CELL;
+      else if (strcmp (detail, "option") == 0)
+       type = MENU;
     }
-  else
+      
+  if (area)
+    {
+      gdk_cairo_rectangle (cr, area);
+      cairo_clip (cr);
+    }
+  
+  exterior_size = MIN (width, height);
+  if (exterior_size % 2 == 0) /* Ensure odd */
+    exterior_size -= -1;
+  
+  x -= (1 + exterior_size - width) / 2;
+  y -= (1 + exterior_size - height) / 2;
+
+  switch (type)
     {
-      x -= (1 + INDICATOR_PART_SIZE - width) / 2;
-      y -= (1 + INDICATOR_PART_SIZE - height) / 2;
+    case BUTTON:
+    case CELL:
+      gdk_cairo_set_source_color (cr, &style->base[state_type]);
+      
+      cairo_arc (cr,
+                x + exterior_size / 2.,
+                y + exterior_size / 2.,
+                (exterior_size - 1) / 2.,
+                0, 2 * G_PI);
+
+      cairo_fill_preserve (cr);
+
+      if (type == BUTTON)
+       gdk_cairo_set_source_color (cr, &style->fg[state_type]);
+      else
+       gdk_cairo_set_source_color (cr, &style->text[state_type]);
+       
+      cairo_set_line_width (cr, 1.);
+      cairo_stroke (cr);
+      break;
+
+    case MENU:
+      break;
+    }
       
-      if (strcmp (detail, "option") == 0)      /* Menu item */
+  switch (type)
+    {
+    case BUTTON:
+      gdk_cairo_set_source_color (cr, &style->text[state_type]);
+      break;
+    case CELL:
+      break;
+    case MENU:
+      gdk_cairo_set_source_color (cr, &style->fg[state_type]);
+      break;
+    }
+
+  if (shadow_type == GTK_SHADOW_IN)
+    {
+      int pad = style->xthickness + MAX (1, 2 * (exterior_size - 2 * style->xthickness) / 9);
+      int interior_size = MAX (1, exterior_size - 2 * pad);
+
+      if (interior_size < 5)
        {
-         if (shadow_type == GTK_SHADOW_IN)
-           draw_part (window, style->fg_gc[state_type], area, x, y, RADIO_TEXT);
+         interior_size = 7;
+         pad = MAX (0, (exterior_size - interior_size) / 2);
        }
-      else
+
+      cairo_arc (cr,
+                x + pad + interior_size / 2.,
+                y + pad + interior_size / 2.,
+                interior_size / 2.,
+                0, 2 * G_PI);
+      cairo_fill (cr);
+    }
+  else if (shadow_type == GTK_SHADOW_ETCHED_IN) /* inconsistent */
+    {
+      int pad = style->xthickness + MAX (1, (exterior_size - 2 * style->xthickness) / 9);
+      int interior_size = MAX (1, exterior_size - 2 * pad);
+      int line_thickness;
+
+      if (interior_size < 7)
        {
-         draw_part (window, style->black_gc, area, x, y, RADIO_BLACK);
-         draw_part (window, style->dark_gc[state_type], area, x, y, RADIO_DARK);
-         draw_part (window, style->mid_gc[state_type], area, x, y, RADIO_MID);
-         draw_part (window, style->light_gc[state_type], area, x, y, RADIO_LIGHT);
-         draw_part (window, style->base_gc[state_type], area, x, y, RADIO_BASE);
-         
-         if (shadow_type == GTK_SHADOW_IN)
-           draw_part (window, style->text_gc[state_type], area, x, y, RADIO_TEXT);
+         interior_size = 7;
+         pad = MAX (0, (exterior_size - interior_size) / 2);
        }
+
+      line_thickness = MAX (1, (3 + interior_size * 2) / 7);
+
+      cairo_rectangle (cr,
+                      x + pad,
+                      y + pad + (interior_size - line_thickness) / 2.,
+                      interior_size,
+                      line_thickness);
+      cairo_fill (cr);
     }
+  
+  cairo_destroy (cr);
 }
 
 static void
@@ -3398,18 +3855,39 @@ gtk_default_draw_tab (GtkStyle      *style,
                      gint           width,
                      gint           height)
 {
+#define ARROW_SPACE 4
+
   GtkRequisition indicator_size;
   GtkBorder indicator_spacing;
+  gint arrow_height;
   
   option_menu_get_props (widget, &indicator_size, &indicator_spacing);
 
+  indicator_size.width += (indicator_size.width % 2) - 1;
+  arrow_height = indicator_size.width / 2 + 1;
+
   x += (width - indicator_size.width) / 2;
-  y += (height - indicator_size.height) / 2 - 1;
+  y += (height - (2 * arrow_height + ARROW_SPACE)) / 2;
 
-  draw_varrow (window, style->black_gc, shadow_type, area, GTK_ARROW_UP,
-              x, y, indicator_size.width, 5);
-  draw_varrow (window, style->black_gc, shadow_type, area, GTK_ARROW_DOWN,
-              x, y + 8, indicator_size.width, 5);
+  if (state_type == GTK_STATE_INSENSITIVE)
+    {
+      draw_arrow (window, &style->white, area,
+                 GTK_ARROW_UP, x + 1, y + 1,
+                 indicator_size.width, arrow_height);
+      
+      draw_arrow (window, &style->white, area,
+                 GTK_ARROW_DOWN, x + 1, y + arrow_height + ARROW_SPACE + 1,
+                 indicator_size.width, arrow_height);
+    }
+  
+  draw_arrow (window, &style->fg[state_type], area,
+             GTK_ARROW_UP, x, y,
+             indicator_size.width, arrow_height);
+  
+  
+  draw_arrow (window, &style->fg[state_type], area,
+             GTK_ARROW_DOWN, x, y + arrow_height + ARROW_SPACE,
+             indicator_size.width, arrow_height);
 }
 
 static void 
@@ -4036,14 +4514,10 @@ gtk_default_draw_focus (GtkStyle      *style,
                        gint           width,
                        gint           height)
 {
-  GdkPoint points[5];
-  GdkGC    *gc;
+  cairo_t *cr;
   gboolean free_dash_list = FALSE;
   gint line_width = 1;
-  gchar *dash_list = "\1\1";
-  gint dash_len;
-
-  gc = style->fg_gc[state_type];
+  gint8 *dash_list = "\1\1";
 
   if (widget)
     {
@@ -4055,16 +4529,6 @@ gtk_default_draw_focus (GtkStyle      *style,
       free_dash_list = TRUE;
   }
 
-  sanitize_size (window, &width, &height);
-  
-  if (area)
-    gdk_gc_set_clip_rectangle (gc, area);
-
-  gdk_gc_set_line_attributes (gc, line_width,
-                             dash_list[0] ? GDK_LINE_ON_OFF_DASH : GDK_LINE_SOLID,
-                             GDK_CAP_BUTT, GDK_JOIN_MITER);
-
-
   if (detail && !strcmp (detail, "add-mode"))
     {
       if (free_dash_list)
@@ -4074,88 +4538,59 @@ gtk_default_draw_focus (GtkStyle      *style,
       free_dash_list = FALSE;
     }
 
-  points[0].x = x + line_width / 2;
-  points[0].y = y + line_width / 2;
-  points[1].x = x + width - line_width + line_width / 2;
-  points[1].y = y + line_width / 2;
-  points[2].x = x + width - line_width + line_width / 2;
-  points[2].y = y + height - line_width + line_width / 2;
-  points[3].x = x + line_width / 2;
-  points[3].y = y + height - line_width + line_width / 2;
-  points[4] = points[0];
+  sanitize_size (window, &width, &height);
 
-  if (!dash_list[0])
-    {
-      gdk_draw_lines (window, gc, points, 5);
-    }
+  cr = gdk_cairo_create (window);
+  
+  if (detail && !strcmp (detail, "colorwheel_light"))
+    cairo_set_source_rgb (cr, 0., 0., 0.);
+  else if (detail && !strcmp (detail, "colorwheel_dark"))
+    cairo_set_source_rgb (cr, 1., 1., 1.);
   else
+    gdk_cairo_set_source_color (cr, &style->fg[state_type]);
+
+  cairo_set_line_width (cr, line_width);
+
+  if (dash_list[0])
     {
-      /* We go through all the pain below because the X rasterization
-       * rules don't really work right for dashed lines if you
-       * want continuity in segments that go between top/right
-       * and left/bottom. For instance, a top left corner
-       * with a 1-1 dash is drawn as:
-       *
-       *  X X X 
-       *  X
-       *
-       *  X
-       *
-       * This is because pixels on the top and left boundaries
-       * of polygons are drawn, but not on the bottom and right.
-       * So, if you have a line going up that turns the corner
-       * and goes right, there is a one pixel shift in the pattern.
-       *
-       * So, to fix this, we drawn the top and right in one call,
-       * then the left and bottom in another call, fixing up
-       * the dash offset for the second call ourselves to get
-       * continuity at the upper left.
-       *
-       * It's not perfect since we really should have a join at
-       * the upper left and lower right instead of two intersecting
-       * lines but that's only really apparent for no-dashes,
-       * which (for this reason) are done as one polygon and
-       * don't to through this code path.
+      gint n_dashes = strlen (dash_list);
+      gdouble *dashes = g_new (gdouble, n_dashes);
+      gdouble total_length = 0;
+      gdouble dash_offset;
+      gint i;
+
+      for (i = 0; i < n_dashes; i++)
+       {
+         dashes[i] = dash_list[i];
+         total_length += dash_list[i];
+       }
+
+      /* The dash offset here aligns the pattern to integer pixels
+       * by starting the dash at the right side of the left border
+       * Negative dash offsets in cairo don't work
+       * (https://bugs.freedesktop.org/show_bug.cgi?id=2729)
        */
+      dash_offset = - line_width / 2.;
+      while (dash_offset < 0)
+       dash_offset += total_length;
       
-      dash_len = strlen (dash_list);
-      
-      if (dash_list[0])
-       gdk_gc_set_dashes (gc, 0, dash_list, dash_len);
-      
-      gdk_draw_lines (window, gc, points, 3);
-      
-      /* We draw this line one farther over than it is "supposed" to
-       * because of another rasterization problem ... if two 1 pixel
-       * unjoined lines meet at the lower right, there will be a missing
-       * pixel.
-       */
-      points[2].x += 1;
-      
-      if (dash_list[0])
-       {
-         gint dash_pixels = 0;
-         gint i;
-         
-         /* Adjust the dash offset for the bottom and left so we
-          * match up at the upper left.
-          */
-         for (i = 0; i < dash_len; i++)
-           dash_pixels += dash_list[i];
-      
-         if (dash_len % 2 == 1)
-           dash_pixels *= 2;
-         
-         gdk_gc_set_dashes (gc, dash_pixels - (width + height - 2 * line_width) % dash_pixels, dash_list, dash_len);
-       }
-      
-      gdk_draw_lines (window, gc, points + 2, 3);
+      cairo_set_dash (cr, dashes, n_dashes, dash_offset);
+      g_free (dashes);
     }
 
-  gdk_gc_set_line_attributes (gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
-
   if (area)
-    gdk_gc_set_clip_rectangle (gc, NULL);
+    {
+      gdk_cairo_rectangle (cr, area);
+      cairo_clip (cr);
+    }
+
+  cairo_rectangle (cr,
+                  x + line_width / 2.,
+                  y + line_width / 2.,
+                  width - line_width,
+                  height - line_width);
+  cairo_stroke (cr);
+  cairo_destroy (cr);
 
   if (free_dash_list)
     g_free (dash_list);
@@ -4214,7 +4649,7 @@ draw_dot (GdkWindow    *window,
       gdk_draw_point (window, light_gc, x, y);
       gdk_draw_point (window, light_gc, x+1, y+1);
     }
-  else if (size == 3);
+  else if (size == 3)
     {
       gdk_draw_point (window, light_gc, x, y);
       gdk_draw_point (window, light_gc, x+1, y);
@@ -4242,6 +4677,7 @@ gtk_default_draw_handle (GtkStyle      *style,
   gint xx, yy;
   gint xthick, ythick;
   GdkGC *light_gc, *dark_gc;
+  GdkGC *free_me = NULL;
   GdkRectangle rect;
   GdkRectangle dest;
   gint intersect;
@@ -4255,13 +4691,25 @@ gtk_default_draw_handle (GtkStyle      *style,
                  detail, x, y, width, height);
   
   
-  if (!strcmp (detail, "paned"))
+  if (detail && !strcmp (detail, "paned"))
     {
       /* we want to ignore the shadow border in paned widgets */
       xthick = 0;
       ythick = 0;
 
-      light_gc = style->light_gc[state_type];
+      if (state_type == GTK_STATE_SELECTED && widget && !GTK_WIDGET_HAS_FOCUS (widget))
+       {
+         GdkColor unfocused_light;
+      
+         gtk_style_shade (&style->base[GTK_STATE_ACTIVE], &unfocused_light,
+                          LIGHTNESS_MULT);
+
+         light_gc = free_me = gdk_gc_new (window);
+         gdk_gc_set_rgb_fg_color (light_gc, &unfocused_light);
+       }
+      else
+       light_gc = style->light_gc[state_type];
+
       dark_gc = style->black_gc;
     }
   else
@@ -4279,7 +4727,7 @@ gtk_default_draw_handle (GtkStyle      *style,
   rect.height = height - (ythick * 2);
 
   if (area)
-      intersect = gdk_rectangle_intersect (area, &rect, &dest);
+    intersect = gdk_rectangle_intersect (area, &rect, &dest);
   else
     {
       intersect = TRUE;
@@ -4287,12 +4735,12 @@ gtk_default_draw_handle (GtkStyle      *style,
     }
 
   if (!intersect)
-    return;
+    goto out;
 
   gdk_gc_set_clip_rectangle (light_gc, &dest);
   gdk_gc_set_clip_rectangle (dark_gc, &dest);
 
-  if (!strcmp (detail, "paned"))
+  if (detail && !strcmp (detail, "paned"))
     {
       if (orientation == GTK_ORIENTATION_HORIZONTAL)
        for (xx = x + width/2 - 15; xx <= x + width/2 + 15; xx += 5)
@@ -4313,43 +4761,10 @@ gtk_default_draw_handle (GtkStyle      *style,
 
   gdk_gc_set_clip_rectangle (light_gc, NULL);
   gdk_gc_set_clip_rectangle (dark_gc, NULL);
-}
-
-static void
-create_expander_affine (gdouble affine[6],
-                       gint    degrees,
-                       gint    expander_size,
-                       gint    x,
-                       gint    y)
-{
-  gdouble s, c;
-  gdouble width;
-  gdouble height;
-
-  width = expander_size / 4.0;
-  height = expander_size / 2.0;
-  
-  s = sin (degrees * G_PI / 180.0);
-  c = cos (degrees * G_PI / 180.0);
-  
-  affine[0] = c;
-  affine[1] = s;
-  affine[2] = -s;
-  affine[3] = c;
-  affine[4] = -width * c - height * -s + x;
-  affine[5] = -width * s - height * c + y;
-}
-
-static void
-apply_affine_on_point (double affine[6], GdkPoint *point)
-{
-  gdouble x, y;
 
-  x = point->x * affine[0] + point->y * affine[2] + affine[4];
-  y = point->x * affine[1] + point->y * affine[3] + affine[5];
-
-  point->x = x;
-  point->y = y;
+ out:
+  if (free_me)
+    g_object_unref (free_me);
 }
 
 static void
@@ -4363,39 +4778,47 @@ gtk_default_draw_expander (GtkStyle        *style,
                            gint             y,
                           GtkExpanderStyle expander_style)
 {
+#define DEFAULT_EXPANDER_SIZE 12
+
   gint expander_size;
-  GdkPoint points[3];
-  gint i;
-  gdouble affine[6];
+  gint line_width;
+  double vertical_overshoot;
+  int diameter;
+  double radius;
+  double x_double, y_double;
   gint degrees = 0;
-  
-  gtk_widget_style_get (widget,
-                       "expander_size", &expander_size,
-                       NULL);
 
+  cairo_t *cr = gdk_cairo_create (window);
+  
   if (area)
     {
-      gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], area);
-      gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], area);
+      gdk_cairo_rectangle (cr, area);
+      cairo_clip (cr);
     }
 
-  points[0].x = 0;
-  points[0].y = 0;
-  points[1].x = expander_size / 2;
-  points[1].y =  expander_size / 2;
-  points[2].x = 0;
-  points[2].y = expander_size;
+  if (widget &&
+      gtk_widget_class_find_style_property (GTK_WIDGET_GET_CLASS (widget),
+                                           "expander-size"))
+    {
+      gtk_widget_style_get (widget,
+                           "expander-size", &expander_size,
+                           NULL);
+    }
+  else
+    expander_size = DEFAULT_EXPANDER_SIZE;
+    
+  line_width = MAX (1, expander_size/9);
 
   switch (expander_style)
     {
     case GTK_EXPANDER_COLLAPSED:
-      degrees = 0;
+      degrees = (get_direction (widget) == GTK_TEXT_DIR_RTL) ? 180 : 0;
       break;
     case GTK_EXPANDER_SEMI_COLLAPSED:
-      degrees = 30;
+      degrees = (get_direction (widget) == GTK_TEXT_DIR_RTL) ? 150 : 30;
       break;
     case GTK_EXPANDER_SEMI_EXPANDED:
-      degrees = 60;
+      degrees = (get_direction (widget) == GTK_TEXT_DIR_RTL) ? 120 : 60;
       break;
     case GTK_EXPANDER_EXPANDED:
       degrees = 90;
@@ -4403,36 +4826,63 @@ gtk_default_draw_expander (GtkStyle        *style,
     default:
       g_assert_not_reached ();
     }
+
+  /* Compute distance that the stroke extends beyonds the end
+   * of the triangle we draw.
+   */
+  vertical_overshoot = line_width / 2.0 * (1. / tan (G_PI / 8));
+
+  /* For odd line widths, we end the vertical line of the triangle
+   * at a half pixel, so we round differently.
+   */
+  if (line_width % 2 == 1)
+    vertical_overshoot = ceil (0.5 + vertical_overshoot) - 0.5;
+  else
+    vertical_overshoot = ceil (vertical_overshoot);
+
+  /* Adjust the size of the triangle we draw so that the entire stroke fits
+   */
+  diameter = MAX (3, expander_size - 2 * vertical_overshoot);
+
+  /* If the line width is odd, we want the diameter to be even,
+   * and vice versa, so force the sum to be odd
+   */
+  diameter -= (1 - (diameter + line_width) % 2);
   
-  create_expander_affine (affine, degrees, expander_size, x, y);
+  radius = diameter / 2.;
 
-  for (i = 0; i < 3; i++)
-    apply_affine_on_point (affine, &points[i]);
+  /* Adjust the center so that the stroke is properly aligned with
+   * the pixel grid
+   */
+  x_double = floor (x - (radius + line_width) / 2.) + (radius + line_width) / 2.;
+  y_double = y + 0.5;
+  
+  cairo_translate (cr, x_double, y_double);
+  cairo_rotate (cr, degrees * M_PI / 180);
+
+  cairo_move_to (cr, - radius / 2., - radius);
+  cairo_line_to (cr,   radius / 2.,   0);
+  cairo_line_to (cr, - radius / 2.,   radius);
+  cairo_close_path (cr);
+  
+  cairo_set_line_width (cr, line_width);
 
   if (state_type == GTK_STATE_PRELIGHT)
-    {
-      gdk_draw_polygon (window, style->fg_gc[GTK_STATE_NORMAL],
-                       TRUE, points, 3);
-    }
+    gdk_cairo_set_source_color (cr,
+                               &style->fg[GTK_STATE_PRELIGHT]);
   else if (state_type == GTK_STATE_ACTIVE)
-    {
-      gdk_draw_polygon (window, style->light_gc[GTK_STATE_ACTIVE],
-                       TRUE, points, 3);
-      gdk_draw_polygon (window, style->fg_gc[GTK_STATE_NORMAL],
-                       FALSE, points, 3);
-    }
+    gdk_cairo_set_source_color (cr,
+                               &style->light[GTK_STATE_ACTIVE]);
   else
-    {
-      gdk_draw_polygon (window, style->base_gc[GTK_STATE_NORMAL],
-                       TRUE, points, 3);
-      gdk_draw_polygon (window, style->fg_gc[GTK_STATE_NORMAL],
-                       FALSE, points, 3);
-    }
-  if (area)
-    {
-      gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], NULL);
-      gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], NULL);
-    }
+    gdk_cairo_set_source_color (cr,
+                               &style->base[GTK_STATE_NORMAL]);
+  
+  cairo_fill_preserve (cr);
+  
+  gdk_cairo_set_source_color (cr, &style->fg[state_type]);
+  cairo_stroke (cr);
+  
+  cairo_destroy (cr);
 }
 
 typedef struct _ByteRange ByteRange;
@@ -4456,7 +4906,8 @@ range_new (guint start,
 }
 
 static PangoLayout*
-get_insensitive_layout (PangoLayout *layout)
+get_insensitive_layout (GdkDrawable *drawable,
+                       PangoLayout *layout)
 {
   GSList *embossed_ranges = NULL;
   GSList *stippled_ranges = NULL;
@@ -4555,11 +5006,11 @@ get_insensitive_layout (PangoLayout *layout)
         {
 #define gray50_width 2
 #define gray50_height 2
-          static char gray50_bits[] = {
+          static const char gray50_bits[] = {
             0x02, 0x01
           };
 
-          stipple = gdk_bitmap_create_from_data (NULL,
+          stipple = gdk_bitmap_create_from_data (drawable,
                                                  gray50_bits, gray50_width,
                                                  gray50_height);
         }
@@ -4579,7 +5030,7 @@ get_insensitive_layout (PangoLayout *layout)
   g_slist_free (stippled_ranges);
   
   if (stipple)
-    g_object_unref (G_OBJECT (stipple));
+    g_object_unref (stipple);
 
   return new_layout;
 }
@@ -4610,11 +5061,11 @@ gtk_default_draw_layout (GtkStyle        *style,
     {
       PangoLayout *ins;
 
-      ins = get_insensitive_layout (layout);
+      ins = get_insensitive_layout (window, layout);
       
       gdk_draw_layout (window, gc, x, y, ins);
 
-      g_object_unref (G_OBJECT (ins));
+      g_object_unref (ins);
     }
   else
     {
@@ -4638,6 +5089,9 @@ gtk_default_draw_resize_grip (GtkStyle       *style,
                               gint            width,
                               gint            height)
 {
+  GdkPoint points[4];
+  gint i, j, skip;
+
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (window != NULL);
   
@@ -4647,27 +5101,253 @@ gtk_default_draw_resize_grip (GtkStyle       *style,
       gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
       gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
     }
-
-  /* make it square, aligning to bottom right */
-  if (width < height)
+  
+  skip = -1;
+  switch (edge)
     {
-      y += (height - width);
-      height = width;
+    case GDK_WINDOW_EDGE_NORTH_WEST:
+      /* make it square */
+      if (width < height)
+       height = width;
+      else if (height < width)
+       width = height;
+      skip = 2;
+      break;
+    case GDK_WINDOW_EDGE_NORTH:
+      if (width < height)
+       height = width;
+      break;
+    case GDK_WINDOW_EDGE_NORTH_EAST:
+      /* make it square, aligning to top right */
+      if (width < height)
+       height = width;
+      else if (height < width)
+       {
+         x += (width - height);
+         width = height;
+       }
+      skip = 3;
+      break;
+    case GDK_WINDOW_EDGE_WEST:
+      if (height < width)
+       width = height;
+      break;
+    case GDK_WINDOW_EDGE_EAST:
+      /* aligning to right */
+      if (height < width)
+       {
+         x += (width - height);
+         width = height;
+       }
+      break;
+    case GDK_WINDOW_EDGE_SOUTH_WEST:
+      /* make it square, aligning to bottom left */
+      if (width < height)
+       {
+         y += (height - width);
+         height = width;
+       }
+      else if (height < width)
+       width = height;
+      skip = 1;
+      break;
+    case GDK_WINDOW_EDGE_SOUTH:
+      /* align to bottom */
+      if (width < height)
+       {
+         y += (height - width);
+         height = width;
+       }
+      break;
+    case GDK_WINDOW_EDGE_SOUTH_EAST:
+      /* make it square, aligning to bottom right */
+      if (width < height)
+       {
+         y += (height - width);
+         height = width;
+       }
+      else if (height < width)
+       {
+         x += (width - height);
+         width = height;
+       }
+      skip = 0;
+      break;
+    default:
+      g_assert_not_reached ();
     }
-  else if (height < width)
+  /* Clear background */
+  j = 0;
+  for (i = 0; i < 4; i++)
     {
-      x += (width - height);
-      width = height;
+      if (skip != i)
+       {
+         points[j].x = (i == 0 || i == 3) ? x : x + width;
+         points[j].y = (i < 2) ? y : y + height;
+         j++;
+       }
     }
-
-  /* Clear background */
-  gdk_draw_rectangle (window,
-                      style->bg_gc[state_type],
-                      TRUE,
-                      x, y, width, height);
+  
+  gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, 
+                   points, skip < 0 ? 4 : 3);
   
   switch (edge)
     {
+    case GDK_WINDOW_EDGE_WEST:
+    case GDK_WINDOW_EDGE_EAST:
+      {
+       gint xi;
+
+       xi = x;
+
+       while (xi < x + width)
+         {
+           gdk_draw_line (window,
+                          style->light_gc[state_type],
+                          xi, y,
+                          xi, y + height);
+
+           xi++;
+           gdk_draw_line (window,
+                          style->dark_gc[state_type],
+                          xi, y,
+                          xi, y + height);
+
+           xi += 2;
+         }
+      }
+      break;
+    case GDK_WINDOW_EDGE_NORTH:
+    case GDK_WINDOW_EDGE_SOUTH:
+      {
+       gint yi;
+
+       yi = y;
+
+       while (yi < y + height)
+         {
+           gdk_draw_line (window,
+                          style->light_gc[state_type],
+                          x, yi,
+                          x + width, yi);
+
+           yi++;
+           gdk_draw_line (window,
+                          style->dark_gc[state_type],
+                          x, yi,
+                          x + width, yi);
+
+           yi+= 2;
+         }
+      }
+      break;
+    case GDK_WINDOW_EDGE_NORTH_WEST:
+      {
+       gint xi, yi;
+
+       xi = x + width;
+       yi = y + height;
+
+       while (xi > x + 3)
+         {
+           gdk_draw_line (window,
+                          style->dark_gc[state_type],
+                          xi, y,
+                          x, yi);
+
+           --xi;
+           --yi;
+
+           gdk_draw_line (window,
+                          style->dark_gc[state_type],
+                          xi, y,
+                          x, yi);
+
+           --xi;
+           --yi;
+
+           gdk_draw_line (window,
+                          style->light_gc[state_type],
+                          xi, y,
+                          x, yi);
+
+           xi -= 3;
+           yi -= 3;
+           
+         }
+      }
+      break;
+    case GDK_WINDOW_EDGE_NORTH_EAST:
+      {
+        gint xi, yi;
+
+        xi = x;
+        yi = y + height;
+
+        while (xi < (x + width - 3))
+          {
+            gdk_draw_line (window,
+                           style->light_gc[state_type],
+                           xi, y,
+                           x + width, yi);                           
+
+            ++xi;
+            --yi;
+            
+            gdk_draw_line (window,
+                           style->dark_gc[state_type],
+                           xi, y,
+                           x + width, yi);                           
+
+            ++xi;
+            --yi;
+            
+            gdk_draw_line (window,
+                           style->dark_gc[state_type],
+                           xi, y,
+                           x + width, yi);
+
+            xi += 3;
+            yi -= 3;
+          }
+      }
+      break;
+    case GDK_WINDOW_EDGE_SOUTH_WEST:
+      {
+       gint xi, yi;
+
+       xi = x + width;
+       yi = y;
+
+       while (xi > x + 3)
+         {
+           gdk_draw_line (window,
+                          style->dark_gc[state_type],
+                          x, yi,
+                          xi, y + height);
+
+           --xi;
+           ++yi;
+
+           gdk_draw_line (window,
+                          style->dark_gc[state_type],
+                          x, yi,
+                          xi, y + height);
+
+           --xi;
+           ++yi;
+
+           gdk_draw_line (window,
+                          style->light_gc[state_type],
+                          x, yi,
+                          xi, y + height);
+
+           xi -= 3;
+           yi += 3;
+           
+         }
+      }
+      break;
     case GDK_WINDOW_EDGE_SOUTH_EAST:
       {
         gint xi, yi;
@@ -4906,9 +5586,10 @@ hls_to_rgb (gdouble *h,
  * @style: a #GtkStyle
  * @window: a #GdkWindow
  * @state_type: a state
- * @area: rectangle to which the output is clipped
- * @widget:
- * @detail: 
+ * @area: rectangle to which the output is clipped, or %NULL if the
+ *        output should not be clipped
+ * @widget: the widget (may be %NULL)
+ * @detail: a style detail (may be %NULL)
  * @x1: the starting x coordinate
  * @x2: the ending x coordinate
  * @y: the y coordinate
@@ -4929,6 +5610,7 @@ gtk_paint_hline (GtkStyle      *style,
 {
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
+  g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
   
   GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, area, widget, detail, x1, x2, y);
 }
@@ -4938,14 +5620,15 @@ gtk_paint_hline (GtkStyle      *style,
  * @style: a #GtkStyle
  * @window: a #GdkWindow
  * @state_type: a state
- * @area: rectangle to which the output is clipped
- * @widget:
- * @detail: 
- * @y1: the starting y coordinate
- * @y2: the ending y coordinate
+ * @area: rectangle to which the output is clipped, or %NULL if the
+ *        output should not be clipped
+ * @widget: the widget (may be %NULL)
+ * @detail: a style detail (may be %NULL)
+ * @y1_: the starting y coordinate
+ * @y2_: the ending y coordinate
  * @x: the x coordinate
  * 
- * Draws a vertical line from (@x, @y1) to (@x, @y1) in @window
+ * Draws a vertical line from (@x, @y1_) to (@x, @y2_) in @window
  * using the given style and state.
  */
 void
@@ -4955,16 +5638,35 @@ gtk_paint_vline (GtkStyle      *style,
                  GdkRectangle  *area,
                  GtkWidget     *widget,
                  const gchar   *detail,
-                 gint          y1,
-                 gint          y2,
+                 gint          y1_,
+                 gint          y2_,
                  gint          x)
 {
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
+  g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
   
-  GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, area, widget, detail, y1, y2, x);
+  GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, area, widget, detail, y1_, y2_, x);
 }
 
+/**
+ * gtk_paint_shadow:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @shadow_type: type of shadow to draw
+ * @area: clip rectangle or %NULL if the
+ *        output should not be clipped
+ * @widget: the widget (may be %NULL)
+ * @detail: a style detail (may be %NULL)
+ * @x: x origin of the rectangle
+ * @y: y origin of the rectangle
+ * @width: width of the rectangle 
+ * @height: width of the rectangle 
+ *
+ * Draws a shadow around the given rectangle in @window 
+ * using the given style and state and shadow type.
+ */
 void
 gtk_paint_shadow (GtkStyle     *style,
                   GdkWindow    *window,
@@ -4980,10 +5682,27 @@ gtk_paint_shadow (GtkStyle     *style,
 {
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
+  g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
   
   GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
 }
 
+/**
+ * gtk_paint_polygon:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @shadow_type: type of shadow to draw
+ * @area: clip rectangle, or %NULL if the
+ *        output should not be clipped
+ * @widget: the widget (may be %NULL)
+ * @detail: a style detail (may be %NULL)
+ * @points: an array of #GdkPoint<!-- -->s
+ * @npoints: length of @points
+ * @fill: %TRUE if the polygon should be filled
+ * 
+ * Draws a polygon on @window with the given parameters.
+ */ 
 void
 gtk_paint_polygon (GtkStyle      *style,
                    GdkWindow     *window,
@@ -4997,11 +5716,32 @@ gtk_paint_polygon (GtkStyle      *style,
                    gboolean       fill)
 {
   g_return_if_fail (GTK_IS_STYLE (style));
-  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
+  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_polygon != NULL);
+  g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
   
   GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, area, widget, detail, points, npoints, fill);
 }
 
+/**
+ * gtk_paint_arrow:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @shadow_type: the type of shadow to draw
+ * @area: clip rectangle, or %NULL if the
+ *        output should not be clipped
+ * @widget: the widget (may be %NULL)
+ * @detail: a style detail (may be %NULL)
+ * @arrow_type: the type of arrow to draw
+ * @fill: %TRUE if the arrow tip should be filled
+ * @x: x origin of the rectangle to draw the arrow in
+ * @y: y origin of the rectangle to draw the arrow in
+ * @width: width of the rectangle to draw the arrow in
+ * @height: height of the rectangle to draw the arrow in
+ * 
+ * Draws an arrow in the given rectangle on @window using the given 
+ * parameters. @arrow_type determines the direction of the arrow.
+ */
 void
 gtk_paint_arrow (GtkStyle      *style,
                  GdkWindow     *window,
@@ -5019,10 +5759,29 @@ gtk_paint_arrow (GtkStyle      *style,
 {
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
+  g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
   
   GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, area, widget, detail, arrow_type, fill, x, y, width, height);
 }
 
+/**
+ * gtk_paint_diamond:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @shadow_type: the type of shadow to draw
+ * @area: clip rectangle, or %NULL if the
+ *        output should not be clipped
+ * @widget: the widget (may be %NULL)
+ * @detail: a style detail (may be %NULL)
+ * @x: x origin of the rectangle to draw the diamond in
+ * @y: y origin of the rectangle to draw the diamond in
+ * @width: width of the rectangle to draw the diamond in
+ * @height: height of the rectangle to draw the diamond in
+ *
+ * Draws a diamond in the given rectangle on @window using the given
+ * parameters.
+ */
 void
 gtk_paint_diamond (GtkStyle      *style,
                    GdkWindow     *window,
@@ -5038,6 +5797,7 @@ gtk_paint_diamond (GtkStyle      *style,
 {
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
+  g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
   
   GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
 }
@@ -5047,16 +5807,17 @@ gtk_paint_diamond (GtkStyle      *style,
  * @style: a #GtkStyle
  * @window: a #GdkWindow
  * @state_type: a state
- * @area: clip rectangle
- * @widget: the widget
- * @detail: a style detail
+ * @area: clip rectangle, or %NULL if the
+ *        output should not be clipped
+ * @widget: the widget (may be %NULL)
+ * @detail: a style detail (may be %NULL)
  * @x: x origin
  * @y: y origin
  * @string: the string to draw
  * 
  * Draws a text string on @window with the given parameters.
  *
- * This function is deprecated, use gtk_paint_layout() instead.
+ * Deprecated: Use gtk_paint_layout() instead.
  */
 void
 gtk_paint_string (GtkStyle      *style,
@@ -5071,10 +5832,28 @@ gtk_paint_string (GtkStyle      *style,
 {
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
+  g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
   
   GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, area, widget, detail, x, y, string);
 }
 
+/**
+ * gtk_paint_box:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @shadow_type: the type of shadow to draw
+ * @area: clip rectangle, or %NULL if the
+ *        output should not be clipped
+ * @widget: the widget (may be %NULL)
+ * @detail: a style detail (may be %NULL)
+ * @x: x origin of the box
+ * @y: y origin of the box
+ * @width: the width of the box
+ * @height: the height of the box
+ * 
+ * Draws a box on @window with the given parameters.
+ */
 void
 gtk_paint_box (GtkStyle      *style,
                GdkWindow     *window,
@@ -5090,10 +5869,28 @@ gtk_paint_box (GtkStyle      *style,
 {
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
+  g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
   
   GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
 }
 
+/**
+ * gtk_paint_flat_box:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @shadow_type: the type of shadow to draw
+ * @area: clip rectangle, or %NULL if the
+ *        output should not be clipped
+ * @widget: the widget (may be %NULL)
+ * @detail: a style detail (may be %NULL)
+ * @x: x origin of the box
+ * @y: y origin of the box
+ * @width: the width of the box
+ * @height: the height of the box
+ * 
+ * Draws a flat box on @window with the given parameters.
+ */
 void
 gtk_paint_flat_box (GtkStyle      *style,
                     GdkWindow     *window,
@@ -5109,10 +5906,29 @@ gtk_paint_flat_box (GtkStyle      *style,
 {
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
+  g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
   
   GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
 }
 
+/**
+ * gtk_paint_check:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @shadow_type: the type of shadow to draw
+ * @area: clip rectangle, or %NULL if the
+ *        output should not be clipped
+ * @widget: the widget (may be %NULL)
+ * @detail: a style detail (may be %NULL)
+ * @x: x origin of the rectangle to draw the check in
+ * @y: y origin of the rectangle to draw the check in
+ * @width: the width of the rectangle to draw the check in
+ * @height: the height of the rectangle to draw the check in
+ * 
+ * Draws a check button indicator in the given rectangle on @window with 
+ * the given parameters.
+ */
 void
 gtk_paint_check (GtkStyle      *style,
                  GdkWindow     *window,
@@ -5128,10 +5944,29 @@ gtk_paint_check (GtkStyle      *style,
 {
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
+  g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
   
   GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
 }
 
+/**
+ * gtk_paint_option:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @shadow_type: the type of shadow to draw
+ * @area: clip rectangle, or %NULL if the
+ *        output should not be clipped
+ * @widget: the widget (may be %NULL)
+ * @detail: a style detail (may be %NULL)
+ * @x: x origin of the rectangle to draw the option in
+ * @y: y origin of the rectangle to draw the option in
+ * @width: the width of the rectangle to draw the option in
+ * @height: the height of the rectangle to draw the option in
+ *
+ * Draws a radio button indicator in the given rectangle on @window with 
+ * the given parameters.
+ */
 void
 gtk_paint_option (GtkStyle      *style,
                   GdkWindow     *window,
@@ -5147,10 +5982,29 @@ gtk_paint_option (GtkStyle      *style,
 {
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
+  g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
   
   GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
 }
 
+/**
+ * gtk_paint_tab:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @shadow_type: the type of shadow to draw
+ * @area: clip rectangle, or %NULL if the
+ *        output should not be clipped
+ * @widget: the widget (may be %NULL)
+ * @detail: a style detail (may be %NULL)
+ * @x: x origin of the rectangle to draw the tab in
+ * @y: y origin of the rectangle to draw the tab in
+ * @width: the width of the rectangle to draw the tab in
+ * @height: the height of the rectangle to draw the tab in
+ *
+ * Draws an option menu tab (i.e. the up and down pointing arrows)
+ * in the given rectangle on @window using the given parameters.
+ */ 
 void
 gtk_paint_tab (GtkStyle      *style,
                GdkWindow     *window,
@@ -5166,10 +6020,33 @@ gtk_paint_tab (GtkStyle      *style,
 {
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
+  g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
   
   GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
 }
 
+/**
+ * gtk_paint_shadow_gap:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @shadow_type: type of shadow to draw
+ * @area: clip rectangle, or %NULL if the
+ *        output should not be clipped
+ * @widget: the widget (may be %NULL)
+ * @detail: a style detail (may be %NULL)
+ * @x: x origin of the rectangle
+ * @y: y origin of the rectangle
+ * @width: width of the rectangle 
+ * @height: width of the rectangle 
+ * @gap_side: side in which to leave the gap
+ * @gap_x: starting position of the gap
+ * @gap_width: width of the gap
+ *
+ * Draws a shadow around the given rectangle in @window 
+ * using the given style and state and shadow type, leaving a 
+ * gap in one side.
+*/
 void
 gtk_paint_shadow_gap (GtkStyle       *style,
                       GdkWindow      *window,
@@ -5188,11 +6065,33 @@ gtk_paint_shadow_gap (GtkStyle       *style,
 {
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
+  g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
   
   GTK_STYLE_GET_CLASS (style)->draw_shadow_gap (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, gap_side, gap_x, gap_width);
 }
 
 
+/**
+ * gtk_paint_box_gap:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @shadow_type: type of shadow to draw
+ * @area: clip rectangle, or %NULL if the
+ *        output should not be clipped
+ * @widget: the widget (may be %NULL)
+ * @detail: a style detail (may be %NULL)
+ * @x: x origin of the rectangle
+ * @y: y origin of the rectangle
+ * @width: width of the rectangle 
+ * @height: width of the rectangle 
+ * @gap_side: side in which to leave the gap
+ * @gap_x: starting position of the gap
+ * @gap_width: width of the gap
+ *
+ * Draws a box in @window using the given style and state and shadow type, 
+ * leaving a gap in one side.
+ */
 void
 gtk_paint_box_gap (GtkStyle       *style,
                    GdkWindow      *window,
@@ -5211,10 +6110,29 @@ gtk_paint_box_gap (GtkStyle       *style,
 {
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
+  g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
   
   GTK_STYLE_GET_CLASS (style)->draw_box_gap (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, gap_side, gap_x, gap_width);
 }
 
+/**
+ * gtk_paint_extension: 
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @shadow_type: type of shadow to draw
+ * @area: clip rectangle, or %NULL if the
+ *        output should not be clipped
+ * @widget: the widget (may be %NULL)
+ * @detail: a style detail (may be %NULL)
+ * @x: x origin of the extension
+ * @y: y origin of the extension
+ * @width: width of the extension 
+ * @height: width of the extension 
+ * @gap_side: the side on to which the extension is attached
+ * 
+ * Draws an extension, i.e. a notebook tab.
+ **/
 void
 gtk_paint_extension (GtkStyle       *style,
                      GdkWindow      *window,
@@ -5231,10 +6149,28 @@ gtk_paint_extension (GtkStyle       *style,
 {
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
+  g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
   
   GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, gap_side);
 }
 
+/**
+ * gtk_paint_focus:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @area: clip rectangle, or %NULL if the
+ *        output should not be clipped
+ * @widget: the widget (may be %NULL)
+ * @detail: a style detail (may be %NULL)
+ * @x: the x origin of the rectangle around which to draw a focus indicator
+ * @y: the y origin of the rectangle around which to draw a focus indicator
+ * @width: the width of the rectangle around which to draw a focus indicator
+ * @height: the height of the rectangle around which to draw a focus indicator
+ *
+ * Draws a focus indicator around the given rectangle on @window using the
+ * given style.
+ */
 void
 gtk_paint_focus (GtkStyle      *style,
                  GdkWindow     *window,
@@ -5249,6 +6185,7 @@ gtk_paint_focus (GtkStyle      *style,
 {
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
+  g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
   
   GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, state_type, area, widget, detail, x, y, width, height);
 }
@@ -5269,10 +6206,29 @@ gtk_paint_slider (GtkStyle      *style,
 {
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
+  g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
   
   GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
 }
 
+/**
+ * gtk_paint_handle:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @shadow_type: type of shadow to draw
+ * @area: clip rectangle, or %NULL if the
+ *        output should not be clipped
+ * @widget: the widget (may be %NULL)
+ * @detail: a style detail (may be %NULL)
+ * @x: x origin of the handle
+ * @y: y origin of the handle
+ * @width: with of the handle
+ * @height: height of the handle
+ * @orientation: the orientation of the handle
+ * 
+ * Draws a handle as used in #GtkHandleBox and #GtkPaned.
+ **/
 void
 gtk_paint_handle (GtkStyle      *style,
                   GdkWindow     *window,
@@ -5289,10 +6245,36 @@ gtk_paint_handle (GtkStyle      *style,
 {
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
+  g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
   
   GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
 }
 
+/**
+ * gtk_paint_expander:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @area: clip rectangle, or %NULL if the
+ *        output should not be clipped
+ * @widget: the widget (may be %NULL)
+ * @detail: a style detail (may be %NULL)
+ * @x: the x position to draw the expander at
+ * @y: the y position to draw the expander at
+ * @expander_style: the style to draw the expander in; determines
+ *   whether the expander is collapsed, expanded, or in an
+ *   intermediate state.
+ * 
+ * Draws an expander as used in #GtkTreeView. @x and @y specify the
+ * center the expander. The size of the expander is determined by the
+ * "expander-size" style property of @widget.  (If widget is not
+ * specified or doesn't have an "expander-size" property, an
+ * unspecified default size will be used, since the caller doesn't
+ * have sufficient information to position the expander, this is
+ * likely not useful.) The expander is expander_size pixels tall
+ * in the collapsed position and expander_size pixels wide in the
+ * expanded position.
+ **/
 void
 gtk_paint_expander (GtkStyle        *style,
                     GdkWindow       *window,
@@ -5306,6 +6288,7 @@ gtk_paint_expander (GtkStyle        *style,
 {
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
+  g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
   
   GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type, area,
                                               widget, detail, x, y, expander_style);
@@ -5325,11 +6308,30 @@ gtk_paint_layout (GtkStyle        *style,
 {
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
+  g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
   
   GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, use_text, area,
                                             widget, detail, x, y, layout);
 }
 
+/**
+ * gtk_paint_resize_grip:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @area: clip rectangle, or %NULL if the
+ *        output should not be clipped
+ * @widget: the widget (may be %NULL)
+ * @detail: a style detail (may be %NULL)
+ * @edge: the edge in which to draw the resize grip
+ * @x: the x origin of the rectangle in which to draw the resize grip
+ * @y: the y origin of the rectangle in which to draw the resize grip
+ * @width: the width of the rectangle in which to draw the resize grip
+ * @height: the height of the rectangle in which to draw the resize grip
+ *
+ * Draws a resize grip in the given rectangle on @window using the given
+ * parameters. 
+ */
 void
 gtk_paint_resize_grip (GtkStyle      *style,
                        GdkWindow     *window,
@@ -5346,6 +6348,7 @@ gtk_paint_resize_grip (GtkStyle      *style,
 {
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
+  g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
 
   GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, window, state_type,
                                                  area, widget, detail,
@@ -5354,8 +6357,8 @@ gtk_paint_resize_grip (GtkStyle      *style,
 
 /**
  * gtk_border_copy:
- * @border: a #GtkBorder.
- * @returns: a copy of @border.
+ * @border_: a #GtkBorder.
+ * @returns: a copy of @border_.
  *
  * Copies a #GtkBorder structure.
  **/
@@ -5367,7 +6370,7 @@ gtk_border_copy (const GtkBorder *border)
 
 /**
  * gtk_border_free:
- * @border: a #GtkBorder.
+ * @border_: a #GtkBorder.
  * 
  * Frees a #GtkBorder structure.
  **/
@@ -5377,21 +6380,21 @@ gtk_border_free (GtkBorder *border)
   g_free (border);
 }
 
-/**
- * gtk_style_get_font:
- * @style: a #GtkStyle
- * 
- * Gets the #GdkFont to use for the given style. This is
- * meant only as a replacement for direct access to @style->font
- * and should not be used in new code. New code should
- * use @style->font_desc instead.
- * 
- * Return value: the #GdkFont for the style. This font is owned
- *   by the style; if you want to keep around a copy, you must
- *   call gdk_font_ref().
- **/
-GdkFont *
-gtk_style_get_font (GtkStyle *style)
+GType
+gtk_border_get_type (void)
+{
+  static GType our_type = 0;
+  
+  if (our_type == 0)
+    our_type = g_boxed_type_register_static ("GtkBorder",
+                                            (GBoxedCopyFunc) gtk_border_copy,
+                                            (GBoxedFreeFunc) gtk_border_free);
+
+  return our_type;
+}
+
+static GdkFont *
+gtk_style_get_font_internal (GtkStyle *style)
 {
   g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
 
@@ -5413,15 +6416,28 @@ gtk_style_get_font (GtkStyle *style)
   
   if (!style->private_font)
     {
+      GdkDisplay *display;
+
+      if (style->colormap)
+       {
+         display = gdk_screen_get_display (gdk_colormap_get_screen (style->colormap));
+       }
+      else
+       {
+         display = gdk_display_get_default ();
+         GTK_NOTE (MULTIHEAD,
+                   g_warning ("gtk_style_get_font() should not be called on an unattached style"));
+       }
+      
       if (style->font_desc)
        {
-         style->private_font = gdk_font_from_description (style->font_desc);
+         style->private_font = gdk_font_from_description_for_display (display, style->font_desc);
          style->private_font_desc = pango_font_description_copy (style->font_desc);
        }
 
       if (!style->private_font)
-       style->private_font = gdk_font_load ("fixed");
-
+       style->private_font = gdk_font_load_for_display (display, "fixed");
+      
       if (!style->private_font) 
        g_error ("Unable to load \"fixed\" font");
     }
@@ -5429,6 +6445,27 @@ gtk_style_get_font (GtkStyle *style)
   return style->private_font;
 }
 
+/**
+ * gtk_style_get_font:
+ * @style: a #GtkStyle
+ * 
+ * Gets the #GdkFont to use for the given style. This is
+ * meant only as a replacement for direct access to @style->font
+ * and should not be used in new code. New code should
+ * use @style->font_desc instead.
+ * 
+ * Return value: the #GdkFont for the style. This font is owned
+ *   by the style; if you want to keep around a copy, you must
+ *   call gdk_font_ref().
+ **/
+GdkFont *
+gtk_style_get_font (GtkStyle *style)
+{
+  g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
+
+  return gtk_style_get_font_internal (style);
+}
+
 /**
  * gtk_style_set_font:
  * @style: a #GtkStyle.
@@ -5464,58 +6501,229 @@ gtk_style_set_font (GtkStyle *style,
     }
 }
 
+typedef struct _CursorInfo CursorInfo;
+
+struct _CursorInfo
+{
+  GType for_type;
+  GdkGC *primary_gc;
+  GdkGC *secondary_gc;
+};
+
+static void
+style_unrealize_cursor_gcs (GtkStyle *style)
+{
+  CursorInfo *
+  
+  cursor_info = g_object_get_data (G_OBJECT (style), "gtk-style-cursor-info");
+  if (cursor_info)
+    {
+      if (cursor_info->primary_gc)
+       gtk_gc_release (cursor_info->primary_gc);
+
+      if (cursor_info->secondary_gc)
+       gtk_gc_release (cursor_info->secondary_gc);
+      
+      g_free (cursor_info);
+      g_object_set_data (G_OBJECT (style), "gtk-style-cursor-info", NULL);
+    }
+}
+
+static GdkGC *
+make_cursor_gc (GtkWidget   *widget,
+               const gchar *property_name,
+               const GdkColor *fallback)
+{
+  GdkGCValues gc_values;
+  GdkGCValuesMask gc_values_mask;
+  GdkColor *cursor_color;
+
+  gtk_widget_style_get (widget, property_name, &cursor_color, NULL);
+  
+  gc_values_mask = GDK_GC_FOREGROUND;
+  if (cursor_color)
+    {
+      gc_values.foreground = *cursor_color;
+      gdk_color_free (cursor_color);
+    }
+  else
+    gc_values.foreground = *fallback;
+  
+  gdk_rgb_find_color (widget->style->colormap, &gc_values.foreground);
+  return gtk_gc_get (widget->style->depth, widget->style->colormap, &gc_values, gc_values_mask);
+}
+
+static GdkGC *
+get_insertion_cursor_gc (GtkWidget *widget,
+                        gboolean   is_primary)
+{
+  CursorInfo *cursor_info;
+
+  cursor_info = g_object_get_data (G_OBJECT (widget->style), "gtk-style-cursor-info");
+  if (!cursor_info)
+    {
+      cursor_info = g_new (CursorInfo, 1);
+      g_object_set_data (G_OBJECT (widget->style), "gtk-style-cursor-info", cursor_info);
+      cursor_info->primary_gc = NULL;
+      cursor_info->secondary_gc = NULL;
+      cursor_info->for_type = G_TYPE_INVALID;
+    }
+
+  /* We have to keep track of the type because gtk_widget_style_get()
+   * can return different results when called on the same property and
+   * same style but for different widgets. :-(. That is,
+   * GtkEntry::cursor-color = "red" in a style will modify the cursor
+   * color for entries but not for text view.
+   */
+  if (cursor_info->for_type != G_OBJECT_TYPE (widget))
+    {
+      cursor_info->for_type = G_OBJECT_TYPE (widget);
+      if (cursor_info->primary_gc)
+       {
+         gtk_gc_release (cursor_info->primary_gc);
+         cursor_info->primary_gc = NULL;
+       }
+      if (cursor_info->secondary_gc)
+       {
+         gtk_gc_release (cursor_info->secondary_gc);
+         cursor_info->secondary_gc = NULL;
+       }
+    }
+
+  if (is_primary)
+    {
+      if (!cursor_info->primary_gc)
+       cursor_info->primary_gc = make_cursor_gc (widget,
+                                                 "cursor-color",
+                                                 &widget->style->black);
+       
+      return cursor_info->primary_gc;
+    }
+  else
+    {
+      static const GdkColor gray = { 0, 0x8888, 0x8888, 0x8888 };
+      
+      if (!cursor_info->secondary_gc)
+       cursor_info->secondary_gc = make_cursor_gc (widget,
+                                                   "secondary-cursor-color",
+                                                   &gray);
+       
+      return cursor_info->secondary_gc;
+    }
+}
+
+static void
+draw_insertion_cursor (GtkWidget        *widget,
+                      GdkDrawable      *drawable,
+                      GdkGC            *gc,
+                      GdkRectangle     *location,
+                      GtkTextDirection  direction,
+                      gboolean          draw_arrow)
+{
+  gint stem_width;
+  gint arrow_width;
+  gint x, y;
+  gint i;
+  gfloat cursor_aspect_ratio;
+  gint offset;
+  
+  g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
+
+  /* When changing the shape or size of the cursor here,
+   * propagate the changes to gtktextview.c:text_window_invalidate_cursors().
+   */
+
+  gtk_widget_style_get (widget, "cursor-aspect-ratio", &cursor_aspect_ratio, NULL);
+  
+  stem_width = location->height * cursor_aspect_ratio + 1;
+  arrow_width = stem_width + 1;
+
+  /* put (stem_width % 2) on the proper side of the cursor */
+  if (direction == GTK_TEXT_DIR_LTR)
+    offset = stem_width / 2;
+  else
+    offset = stem_width - stem_width / 2;
+  
+  for (i = 0; i < stem_width; i++)
+    gdk_draw_line (drawable, gc,
+                  location->x + i - offset, location->y,
+                  location->x + i - offset, location->y + location->height - 1);
+
+  if (draw_arrow)
+    {
+      if (direction == GTK_TEXT_DIR_RTL)
+        {
+          x = location->x - offset - 1;
+          y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
+  
+          for (i = 0; i < arrow_width; i++)
+            {
+              gdk_draw_line (drawable, gc,
+                             x, y + i + 1,
+                             x, y + 2 * arrow_width - i - 1);
+              x --;
+            }
+        }
+      else if (direction == GTK_TEXT_DIR_LTR)
+        {
+          x = location->x + stem_width - offset;
+          y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
+  
+          for (i = 0; i < arrow_width; i++) 
+            {
+              gdk_draw_line (drawable, gc,
+                             x, y + i + 1,
+                             x, y + 2 * arrow_width - i - 1);
+              x++;
+            }
+        }
+    }
+}
+
 /**
- * _gtk_draw_insertion_cursor:
- * @drawable: a #GdkDrawable
- * @gc: a #GdkGC
+ * gtk_draw_insertion_cursor:
+ * @widget:  a #GtkWidget
+ * @drawable: a #GdkDrawable 
+ * @area: rectangle to which the output is clipped, or %NULL if the
+ *        output should not be clipped
  * @location: location where to draw the cursor (@location->width is ignored)
- * @dir: text direction for the cursor, used to decide whether to draw a
- *       directional arrow on the cursor and in what direction. Unless both
- *       strong and weak cursors are displayed, this should be %GTK_TEXT_DIR_NONE.
+ * @is_primary: if the cursor should be the primary cursor color.
+ * @direction: whether the cursor is left-to-right or
+ *             right-to-left. Should never be #GTK_TEXT_DIR_NONE
+ * @draw_arrow: %TRUE to draw a directional arrow on the
+ *        cursor. Should be %FALSE unless the cursor is split.
  * 
  * Draws a text caret on @drawable at @location. This is not a style function
  * but merely a convenience function for drawing the standard cursor shape.
+ *
+ * Since: 2.4
  **/
 void
-_gtk_draw_insertion_cursor (GdkDrawable      *drawable,
-                           GdkGC            *gc,
-                           GdkRectangle     *location,
-                           GtkTextDirection  dir)
+gtk_draw_insertion_cursor (GtkWidget        *widget,
+                          GdkDrawable      *drawable,
+                          GdkRectangle     *area,
+                          GdkRectangle     *location,
+                          gboolean          is_primary,
+                          GtkTextDirection  direction,
+                          gboolean          draw_arrow)
 {
-  gint stem_width = location->height / 30 + 1;
-  gint arrow_width = stem_width + 1;
-  gint x, y;
-  gint i;
+  GdkGC *gc;
 
-  for (i = 0; i < stem_width; i++)
-    gdk_draw_line (drawable, gc,
-                  location->x + i - stem_width / 2, location->y,
-                  location->x + i - stem_width / 2, location->y + location->height);
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+  g_return_if_fail (GDK_IS_DRAWABLE (drawable));
+  g_return_if_fail (location != NULL);
+  g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
 
-  if (dir == GTK_TEXT_DIR_RTL)
-    {
-      x = location->x - stem_width / 2 - 1;
-      y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
+  gc = get_insertion_cursor_gc (widget, is_primary);
+  if (area)
+    gdk_gc_set_clip_rectangle (gc, area);
   
-      for (i = 0; i < arrow_width; i++)
-       {
-         gdk_draw_line (drawable, gc,
-                        x, y + i + 1,
-                        x, y + 2 * arrow_width - i - 1);
-         x --;
-       }
-    }
-  else if (dir == GTK_TEXT_DIR_LTR)
-    {
-      x = location->x + stem_width - stem_width / 2;
-      y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
+  draw_insertion_cursor (widget, drawable, gc,
+                        location, direction, draw_arrow);
   
-      for (i = 0; i < arrow_width; i++) 
-       {
-         gdk_draw_line (drawable, gc,
-                        x, y + i + 1,
-                        x, y + 2 * arrow_width - i - 1);
-         x++;
-       }
-    }
+  if (area)
+    gdk_gc_set_clip_rectangle (gc, NULL);
 }
+
+#define __GTK_STYLE_C__
+#include "gtkaliasdef.c"