]> 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 4a6964090c81db6deafbc2255e785b06c1b12942..8fa082a6b3dee386e255bdeb4aaf99fe5c29b0f7 100644 (file)
@@ -28,7 +28,6 @@
 #include <math.h>
 #include <stdlib.h>
 #include <string.h>
-#include "gtkalias.h"
 #include "gtkgc.h"
 #include "gtkmarshalers.h"
 #include "gtkrc.h"
@@ -38,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
@@ -325,128 +325,6 @@ static GdkFont *gtk_style_get_font_internal (GtkStyle *style);
 static const GtkRequisition default_option_indicator_size = { 7, 13 };
 static const 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,
-  CHECK_INCONSISTENT_TEXT,
-  RADIO_BASE,
-  RADIO_BLACK,
-  RADIO_DARK,
-  RADIO_LIGHT,
-  RADIO_MID,
-  RADIO_TEXT,
-  RADIO_INCONSISTENT_AA,
-  RADIO_INCONSISTENT_TEXT
-} IndicatorPart;
-
-/*
- * Extracted from check-13.png, width=13, height=13
- */
-static const guchar 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,0x00,0x00};
-static const guchar 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,0x00,0x00};
-static const guchar 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,0x00,0x00};
-static const guchar 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,0x00,0x00};
-static const guchar check_text_bits[] = {
-  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x03,0x80,0x01,0x80,0x00,0x58,
-  0x00,0x60,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-static const guchar 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,0x00,0x00};
-static const guchar 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,0x00,0x00};
-
-/*
- * Extracted from check-13-inconsistent.png, width=13, height=13
- */
-static const guchar check_inconsistent_text_bits[] = {
-  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf8,0x03,0xf8,
-  0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-#if 0
-/*
- * check_inconsistent_aa_bits is currently not used, since it is all zeros.
- */
-static const guchar check_inconsistent_aa_bits[] = {
-  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-#endif
-
-/*
- * Extracted from radio-13.png, width=13, height=13
- */
-static const guchar radio_black_bits[] = {
-  0x00,0x00,0xf0,0x01,0x0c,0x02,0x04,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
-  0x00,0x02,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0d,0x08};
-static const guchar radio_dark_bits[] = {
-  0xf0,0x00,0x0c,0x02,0x02,0x04,0x02,0x04,0x01,0x08,0x01,0x08,0x01,0x08,0x01,
-  0x08,0x00,0x08,0x02,0x04,0x0c,0x06,0xf0,0x01,0x00,0x00,0x00,0x00};
-static const guchar radio_mid_bits[] = {
-  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-static const guchar radio_light_bits[] = {
-  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x10,0x00,
-  0x10,0x00,0x10,0x00,0x08,0x00,0x08,0x00,0x06,0xe0,0x01,0x00,0x00};
-static const guchar 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,0x00,0x00};
-#if 0
-/*
- * radio_aa_bits is currently not used, since it is all zeros.
- */
-static const guchar radio_aa_bits[] = {
-  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-#endif
-static const guchar 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,0x00,0x00};
-
-/*
- * Extracted from radio-13.png, width=13, height=13
- */
-static const guchar radio_inconsistent_text_bits[] = {
-  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf8,0x03,0x00,
-  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-static const guchar radio_inconsistent_aa_bits[] = {
-  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf8,0x03,0x00,0x00,0xf8,
-  0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-
-static struct {
-  const guchar      *bits;
-  GList            *bmap_list; /* list of GdkBitmap */
-} 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 },
-  { check_inconsistent_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 },
-  { radio_inconsistent_aa_bits, NULL },
-  { radio_inconsistent_text_bits, NULL },
-};
 #define GTK_GRAY               0xdcdc, 0xdada, 0xd5d5
 #define GTK_DARK_GRAY          0xc4c4, 0xc2c2, 0xbdbd
 #define GTK_LIGHT_GRAY         0xeeee, 0xebeb, 0xe7e7
@@ -1668,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
@@ -2263,57 +2141,6 @@ sanitize_size (GdkWindow *window,
     gdk_drawable_get_size (window, NULL, height);
 }
 
-static GdkBitmap * 
-get_indicator_for_screen (GdkDrawable   *drawable,
-                         IndicatorPart  part)
-                         
-{
-  GdkScreen *screen = gdk_drawable_get_screen (drawable);
-  GdkBitmap *bitmap;
-  GList *tmp_list;
-  
-  tmp_list = indicator_parts[part].bmap_list;
-  while (tmp_list)
-    {
-      bitmap = tmp_list->data;
-      
-      if (gdk_drawable_get_screen (bitmap) == screen)
-       return bitmap;
-      
-      tmp_list = tmp_list->next;
-    }
-  
-  bitmap = gdk_bitmap_create_from_data (drawable,
-                                       (gchar *)indicator_parts[part].bits,
-                                       INDICATOR_PART_SIZE, INDICATOR_PART_SIZE);
-  indicator_parts[part].bmap_list = g_list_prepend (indicator_parts[part].bmap_list, bitmap);
-
-  return bitmap;
-}
-
-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);
-  
-  gdk_gc_set_ts_origin (gc, x, y);
-  gdk_gc_set_stipple (gc, get_indicator_for_screen (drawable, part));
-  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);
-}
-
 static void
 gtk_default_draw_hline (GtkStyle     *style,
                         GdkWindow    *window,
@@ -3065,7 +2892,7 @@ gtk_default_draw_polygon (GtkStyle      *style,
 
 static void
 draw_arrow (GdkWindow     *window,
-           GdkGC         *gc,
+           GdkColor      *color,
            GdkRectangle  *area,
            GtkArrowType   arrow_type,
            gint           x,
@@ -3073,34 +2900,44 @@ draw_arrow (GdkWindow     *window,
            gint           width,
            gint           height)
 {
-  gint i, j;
-
+  cairo_t *cr = gdk_cairo_create (window);
+  gdk_cairo_set_source_color (cr, color);
+  
   if (area)
-    gdk_gc_set_clip_rectangle (gc, area);
-
+    {
+      gdk_cairo_rectangle (cr, area);
+      cairo_clip (cr);
+    }
+    
   if (arrow_type == GTK_ARROW_DOWN)
     {
-      for (i = 0, j = 0; i < height; i++, j++)
-       gdk_draw_line (window, gc, x + j, y + i, x + width - j - 1, y + i);
+      cairo_move_to (cr, x,              y);
+      cairo_line_to (cr, x + width,      y);
+      cairo_line_to (cr, x + width / 2., y + height);
     }
   else if (arrow_type == GTK_ARROW_UP)
     {
-      for (i = height - 1, j = 0; i >= 0; i--, j++)
-       gdk_draw_line (window, gc, x + j, y + i, x + width - j - 1, y + i);
+      cairo_move_to (cr, x,              y + height);
+      cairo_line_to (cr, x + width / 2., y);
+      cairo_line_to (cr, x + width,      y + height);
     }
   else if (arrow_type == GTK_ARROW_LEFT)
     {
-      for (i = width - 1, j = 0; i >= 0; i--, j++)
-       gdk_draw_line (window, gc, x + i, y + j, x + i, y + height - j - 1);
+      cairo_move_to (cr, x + width,      y);
+      cairo_line_to (cr, x + width,      y + height);
+      cairo_line_to (cr, x,              y + height / 2.);
     }
   else if (arrow_type == GTK_ARROW_RIGHT)
     {
-      for (i = 0, j = 0; i < width; i++, j++)
-       gdk_draw_line (window, gc, x + i, y + j, x + i, y + height - j - 1);
+      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
@@ -3200,9 +3037,9 @@ gtk_default_draw_arrow (GtkStyle      *style,
     y++;
 
   if (state == GTK_STATE_INSENSITIVE)
-    draw_arrow (window, style->white_gc, area, arrow_type,
+    draw_arrow (window, &style->white, area, arrow_type,
                x + 1, y + 1, width, height);
-  draw_arrow (window, style->fg_gc[state], area, arrow_type,
+  draw_arrow (window, &style->fg[state], area, arrow_type,
              x, y, width, height);
 }
 
@@ -3393,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)
@@ -3468,9 +3305,9 @@ gtk_default_draw_box (GtkStyle      *style,
     {
       GdkGC *gc = style->bg_gc[state_type];
       
-      if (state_type == GTK_STATE_SELECTED && strcmp (detail, "paned") == 0)
+      if (state_type == GTK_STATE_SELECTED && detail && strcmp (detail, "paned") == 0)
        {
-         if (!GTK_WIDGET_HAS_FOCUS (widget))
+         if (widget && !GTK_WIDGET_HAS_FOCUS (widget))
            gc = style->base_gc[GTK_STATE_ACTIVE];
        }
 
@@ -3624,7 +3461,7 @@ gtk_default_draw_flat_box (GtkStyle      *style,
              GdkColor *color = NULL;
 
              gtk_widget_style_get (widget,
-                                   "even_row_color", &color,
+                                   "even-row-color", &color,
                                    NULL);
 
              if (color)
@@ -3642,7 +3479,7 @@ gtk_default_draw_flat_box (GtkStyle      *style,
              GdkColor *color;
 
              gtk_widget_style_get (widget,
-                                   "odd_row_color", &color,
+                                   "odd-row-color", &color,
                                    NULL);
 
              if (color)
@@ -3655,7 +3492,7 @@ gtk_default_draw_flat_box (GtkStyle      *style,
              else
                {
                  gtk_widget_style_get (widget,
-                                       "even_row_color", &color,
+                                       "even-row-color", &color,
                                        NULL);
 
                  if (color)
@@ -3676,11 +3513,11 @@ gtk_default_draw_flat_box (GtkStyle      *style,
 
              if (!strcmp ("cell_odd_sorted", detail))
                gtk_widget_style_get (widget,
-                                     "odd_row_color", &color,
+                                     "odd-row-color", &color,
                                      NULL);
              else
                gtk_widget_style_get (widget,
-                                     "even_row_color", &color,
+                                     "even-row-color", &color,
                                      NULL);
 
              if (color)
@@ -3701,7 +3538,7 @@ gtk_default_draw_flat_box (GtkStyle      *style,
              GdkColor *color = NULL;
 
              gtk_widget_style_get (widget,
-                                   "odd_row_color", &color,
+                                   "odd-row-color", &color,
                                    NULL);
 
              if (color)
@@ -3714,7 +3551,7 @@ gtk_default_draw_flat_box (GtkStyle      *style,
              else
                {
                  gtk_widget_style_get (widget,
-                                       "even_row_color", &color,
+                                       "even-row-color", &color,
                                        NULL);
 
                  if (color)
@@ -3760,21 +3597,6 @@ gtk_default_draw_flat_box (GtkStyle      *style,
     g_object_unref (freeme);
 }
 
-static GdkGC *
-create_aa_gc (GdkWindow *window, GtkStyle *style, GtkStateType state_type)
-{
-  GdkColor aa_color;
-  GdkGC *gc = gdk_gc_new (window);
-   
-  aa_color.red = (style->fg[state_type].red + style->bg[state_type].red) / 2;
-  aa_color.green = (style->fg[state_type].green + style->bg[state_type].green) / 2;
-  aa_color.blue = (style->fg[state_type].blue + style->bg[state_type].blue) / 2;
-  
-  gdk_gc_set_rgb_fg_color (gc, &aa_color);
-
-  return gc;
-}
-
 static void 
 gtk_default_draw_check (GtkStyle      *style,
                        GdkWindow     *window,
@@ -3788,92 +3610,116 @@ gtk_default_draw_check (GtkStyle      *style,
                        gint           width,
                        gint           height)
 {
-  if (detail && strcmp (detail, "cellcheck") == 0)
-    {
-      if (area)               
-       gdk_gc_set_clip_rectangle (widget->style->base_gc[state_type], area);
-      gdk_draw_rectangle (window,
-                         widget->style->base_gc[state_type],
-                         TRUE,
-                          x, y,
-                         width, height);
-      if (area)
-       {
-         gdk_gc_set_clip_rectangle (widget->style->base_gc[state_type], NULL);
-         gdk_gc_set_clip_rectangle (widget->style->text_gc[state_type], area);
-       }
-      gdk_draw_rectangle (window,
-                         widget->style->text_gc[state_type],
-                         FALSE,
-                          x, y,
-                         width, height);
-      if (area)               
-       gdk_gc_set_clip_rectangle (widget->style->text_gc[state_type], NULL);
-
-      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 if (shadow_type == GTK_SHADOW_ETCHED_IN) /* inconsistent */
-       {
-         draw_part (window, style->text_gc[state_type], area, x, y, CHECK_INCONSISTENT_TEXT);
-       }
-    }
-  else
+  cairo_t *cr = gdk_cairo_create (window);
+  enum { BUTTON, MENU, CELL } type = BUTTON;
+  int exterior_size;
+  int interior_size;
+  int pad;
+  
+  if (detail)
     {
-      GdkGC *free_me = NULL;
+      if (strcmp (detail, "cellcheck") == 0)
+       type = CELL;
+      else if (strcmp (detail, "check") == 0)
+       type = MENU;
+    }
       
-      GdkGC *base_gc;
-      GdkGC *text_gc;
-      GdkGC *aa_gc;
+  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 + INDICATOR_PART_SIZE - width) / 2;
-      y -= (1 + INDICATOR_PART_SIZE - height) / 2;
+  pad = style->xthickness + MAX (1, (exterior_size - 2 * style->xthickness) / 9);
+  interior_size = MAX (1, exterior_size - 2 * pad);
 
-      if (strcmp (detail, "check") == 0)       /* Menu item */
-       {
-         text_gc = style->fg_gc[state_type];
-         base_gc = style->bg_gc[state_type];
-         aa_gc = free_me = create_aa_gc (window, style, state_type);
-       }
+  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
-       {
-         if (state_type == GTK_STATE_ACTIVE)
-           {
-             text_gc = style->fg_gc[state_type];
-             base_gc = style->bg_gc[state_type];
-             aa_gc = free_me = create_aa_gc (window, style, state_type);
-           }
-         else
-           {
-             text_gc = style->text_gc[state_type];
-             base_gc = style->base_gc[state_type];
-             aa_gc = style->text_aa_gc[state_type];
-           }
+       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);
 
-         draw_part (window, base_gc, area, x, y, CHECK_BASE);
-         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);
-       }
+      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;
 
-      if (shadow_type == GTK_SHADOW_IN)
-       {
-         draw_part (window, text_gc, area, x, y, CHECK_TEXT);
-         draw_part (window, aa_gc, area, x, y, CHECK_AA);
-       }
-      else if (shadow_type == GTK_SHADOW_ETCHED_IN) /* inconsistent */
-       {
-         draw_part (window, text_gc, area, x, y, CHECK_INCONSISTENT_TEXT);
-       }
+    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 (free_me)
-       g_object_unref (free_me);
+  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 
@@ -3889,96 +3735,111 @@ gtk_default_draw_option (GtkStyle      *style,
                         gint           width,
                         gint           height)
 {
-  if (detail && strcmp (detail, "cellradio") == 0)
-    {
-      if (area)               
-       gdk_gc_set_clip_rectangle (widget->style->fg_gc[state_type], area);
-      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);
-       }
-      else if (shadow_type == GTK_SHADOW_ETCHED_IN) /* inconsistent */
-        {
-          draw_part (window, widget->style->fg_gc[state_type],
-                    area, x, y, CHECK_INCONSISTENT_TEXT);
-       }
-      if (area)               
-       gdk_gc_set_clip_rectangle (widget->style->fg_gc[state_type], NULL);
+  cairo_t *cr = gdk_cairo_create (window);
+  enum { BUTTON, MENU, CELL } type = BUTTON;
+  int exterior_size;
+  
+  if (detail)
+    {
+      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)
     {
-      GdkGC *free_me = NULL;
+    case BUTTON:
+    case CELL:
+      gdk_cairo_set_source_color (cr, &style->base[state_type]);
       
-      GdkGC *base_gc;
-      GdkGC *text_gc;
-      GdkGC *aa_gc;
+      cairo_arc (cr,
+                x + exterior_size / 2.,
+                y + exterior_size / 2.,
+                (exterior_size - 1) / 2.,
+                0, 2 * G_PI);
 
-      x -= (1 + INDICATOR_PART_SIZE - width) / 2;
-      y -= (1 + INDICATOR_PART_SIZE - height) / 2;
+      cairo_fill_preserve (cr);
 
-      if (strcmp (detail, "option") == 0)      /* Menu item */
-       {
-         text_gc = style->fg_gc[state_type];
-         base_gc = style->bg_gc[state_type];
-         aa_gc = free_me = create_aa_gc (window, style, state_type);
-       }
+      if (type == BUTTON)
+       gdk_cairo_set_source_color (cr, &style->fg[state_type]);
       else
-       {
-         if (state_type == GTK_STATE_ACTIVE)
-           {
-             text_gc = style->fg_gc[state_type];
-             base_gc = style->bg_gc[state_type];
-             aa_gc = free_me = create_aa_gc (window, style, state_type);
-           }
-         else
-           {
-             text_gc = style->text_gc[state_type];
-             base_gc = style->base_gc[state_type];
-             aa_gc = style->text_aa_gc[state_type];
-           }
+       gdk_cairo_set_source_color (cr, &style->text[state_type]);
+       
+      cairo_set_line_width (cr, 1.);
+      cairo_stroke (cr);
+      break;
 
-         draw_part (window, base_gc, area, x, y, RADIO_BASE);
-         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);
-       }
+    case MENU:
+      break;
+    }
+      
+  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)
+  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)
        {
-         draw_part (window, text_gc, area, x, y, RADIO_TEXT);
+         interior_size = 7;
+         pad = MAX (0, (exterior_size - interior_size) / 2);
        }
-      else if (shadow_type == GTK_SHADOW_ETCHED_IN) /* inconsistent */
+
+      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)
        {
-         if (strcmp (detail, "option") == 0)  /* Menu item */
-           {
-             draw_part (window, text_gc, area, x, y, CHECK_INCONSISTENT_TEXT);
-           }
-         else
-           {
-             draw_part (window, text_gc, area, x, y, RADIO_INCONSISTENT_TEXT);
-             draw_part (window, aa_gc, area, x, y, RADIO_INCONSISTENT_AA);
-           }
+         interior_size = 7;
+         pad = MAX (0, (exterior_size - interior_size) / 2);
        }
 
-      if (free_me)
-       g_object_unref (free_me);
+      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
@@ -4010,21 +3871,21 @@ gtk_default_draw_tab (GtkStyle      *style,
 
   if (state_type == GTK_STATE_INSENSITIVE)
     {
-      draw_arrow (window, style->white_gc, area,
+      draw_arrow (window, &style->white, area,
                  GTK_ARROW_UP, x + 1, y + 1,
                  indicator_size.width, arrow_height);
       
-      draw_arrow (window, style->white_gc, area,
+      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_gc[state_type], area,
+  draw_arrow (window, &style->fg[state_type], area,
              GTK_ARROW_UP, x, y,
              indicator_size.width, arrow_height);
   
   
-  draw_arrow (window, style->fg_gc[state_type], area,
+  draw_arrow (window, &style->fg[state_type], area,
              GTK_ARROW_DOWN, x, y + arrow_height + ARROW_SPACE,
              indicator_size.width, arrow_height);
 }
@@ -4653,12 +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;
   gint8 *dash_list = "\1\1";
-  gint dash_len;
 
   if (widget)
     {
@@ -4670,22 +4529,6 @@ gtk_default_draw_focus (GtkStyle      *style,
       free_dash_list = TRUE;
   }
 
-  sanitize_size (window, &width, &height);
-  
-  if (detail && !strcmp (detail, "colorwheel_light"))
-    gc = style->black_gc;
-  else if (detail && !strcmp (detail, "colorwheel_dark"))
-    gc = style->white_gc;
-  else 
-    gc = style->fg_gc[state_type];
-
-  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 (area)
-    gdk_gc_set_clip_rectangle (gc, area);
-
   if (detail && !strcmp (detail, "add-mode"))
     {
       if (free_dash_list)
@@ -4695,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.
-       */
-      
-      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 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++)
        {
-         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);
+         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;
       
-      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);
@@ -4877,13 +4691,13 @@ 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;
 
-      if (state_type == GTK_STATE_SELECTED && !GTK_WIDGET_HAS_FOCUS (widget))
+      if (state_type == GTK_STATE_SELECTED && widget && !GTK_WIDGET_HAS_FOCUS (widget))
        {
          GdkColor unfocused_light;
       
@@ -4926,7 +4740,7 @@ gtk_default_draw_handle (GtkStyle      *style,
   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)
@@ -4950,73 +4764,7 @@ gtk_default_draw_handle (GtkStyle      *style,
 
  out:
   if (free_me)
-    g_object_unref (G_OBJECT (free_me));
-}
-
-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;
-
-  switch (degrees)
-    {
-    case 0:
-      s = 0.0;
-      c = 1.0;
-      break;
-    case 90:
-      s = 1.0;
-      c = 0.0;
-      break;
-    case 180:
-      s = 0.0;
-      c = -1.0;
-      break;
-    default:
-      s = sin (degrees * G_PI / 180.0);
-      c = cos (degrees * G_PI / 180.0);
-      break;
-    }
-  
-  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 = floor (x);
-  point->y = floor (y);
-}
-
-static void
-gtk_style_draw_polygon_with_gc (GdkWindow *window, GdkGC *gc, gint line_width,
-                               gboolean do_fill, GdkPoint *points, gint n_points)
-{
-  gdk_gc_set_line_attributes (gc, line_width,
-                             GDK_LINE_SOLID,
-                             GDK_CAP_BUTT, GDK_JOIN_MITER);
-
-  gdk_draw_polygon (window, gc, do_fill, points, n_points);
-  gdk_gc_set_line_attributes (gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
+    g_object_unref (free_me);
 }
 
 static void
@@ -5030,34 +4778,36 @@ gtk_default_draw_expander (GtkStyle        *style,
                            gint             y,
                           GtkExpanderStyle expander_style)
 {
+#define DEFAULT_EXPANDER_SIZE 12
+
   gint expander_size;
-  GdkPoint points[3];
-  gint i;
-  gint line_width, o;
-  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);
-  line_width = MAX (1, expander_size/9);
-
+  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);
     }
 
-  /* a rough estimate of how much the joins of the triangle will overshoot. 
-   * 2.4 ~ 1 / tan (45 / 2)
-   */
-  o = ceil (2.4 * line_width / 2.0);
-  points[0].x = line_width / 2;
-  points[0].y = o;
-  points[1].x = expander_size / 2 + line_width / 2 - o;
-  points[1].y = expander_size / 2;
-  points[2].x = line_width / 2;
-  points[2].y = expander_size - o;
+  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)
     {
@@ -5077,35 +4827,62 @@ gtk_default_draw_expander (GtkStyle        *style,
       g_assert_not_reached ();
     }
 
-  create_expander_affine (affine, degrees, expander_size, x, y);
+  /* 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);
+  
+  radius = diameter / 2.;
+
+  /* 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);
 
-  for (i = 0; i < 3; i++)
-    apply_affine_on_point (affine, &points[i]);
+  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)
-    {
-      gtk_style_draw_polygon_with_gc (window, style->fg_gc[GTK_STATE_PRELIGHT],
-                                     1, TRUE, points, 3);
-    }
+    gdk_cairo_set_source_color (cr,
+                               &style->fg[GTK_STATE_PRELIGHT]);
   else if (state_type == GTK_STATE_ACTIVE)
-    {
-      gtk_style_draw_polygon_with_gc (window, style->light_gc[GTK_STATE_ACTIVE],
-                                     1, TRUE, points, 3);
-      gtk_style_draw_polygon_with_gc (window, style->fg_gc[GTK_STATE_NORMAL],
-                                     line_width, FALSE, points, 3);
-    }
+    gdk_cairo_set_source_color (cr,
+                               &style->light[GTK_STATE_ACTIVE]);
   else
-    {
-      gtk_style_draw_polygon_with_gc (window, style->base_gc[GTK_STATE_NORMAL],
-                                     1, TRUE, points, 3);
-      gtk_style_draw_polygon_with_gc (window, style->fg_gc[GTK_STATE_NORMAL],
-                                     line_width, 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;
@@ -5312,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);
   
@@ -5322,42 +5102,35 @@ gtk_default_draw_resize_grip (GtkStyle       *style,
       gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
     }
   
+  skip = -1;
   switch (edge)
     {
     case GDK_WINDOW_EDGE_NORTH_WEST:
       /* make it square */
       if (width < height)
-       {
-         height = width;
-       }
+       height = width;
       else if (height < width)
-       {
-         width = height;
-       }
+       width = height;
+      skip = 2;
       break;
     case GDK_WINDOW_EDGE_NORTH:
       if (width < height)
-       {
-         height = width;
-       }
+       height = width;
       break;
     case GDK_WINDOW_EDGE_NORTH_EAST:
       /* make it square, aligning to top right */
       if (width < height)
-       {
-         height = width;
-       }
+       height = width;
       else if (height < width)
        {
          x += (width - height);
          width = height;
        }
+      skip = 3;
       break;
     case GDK_WINDOW_EDGE_WEST:
       if (height < width)
-       {
-          width = height;
-       }
+       width = height;
       break;
     case GDK_WINDOW_EDGE_EAST:
       /* aligning to right */
@@ -5375,9 +5148,8 @@ gtk_default_draw_resize_grip (GtkStyle       *style,
          height = width;
        }
       else if (height < width)
-       {
-         width = height;
-       }
+       width = height;
+      skip = 1;
       break;
     case GDK_WINDOW_EDGE_SOUTH:
       /* align to bottom */
@@ -5399,15 +5171,26 @@ gtk_default_draw_resize_grip (GtkStyle       *style,
          x += (width - height);
          width = height;
        }
+      skip = 0;
       break;
     default:
       g_assert_not_reached ();
     }
   /* Clear background */
-  gtk_style_apply_default_background (style, window, FALSE,
-                                     state_type, area,
-                                     x, y, width, height);   
-
+  j = 0;
+  for (i = 0; i < 4; i++)
+    {
+      if (skip != i)
+       {
+         points[j].x = (i == 0 || i == 3) ? x : x + width;
+         points[j].y = (i < 2) ? y : y + height;
+         j++;
+       }
+    }
+  
+  gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, 
+                   points, skip < 0 ? 4 : 3);
+  
   switch (edge)
     {
     case GDK_WINDOW_EDGE_WEST:
@@ -5803,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: the widget
- * @detail: a style 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
@@ -5826,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);
 }
@@ -5835,9 +5620,10 @@ gtk_paint_hline (GtkStyle      *style,
  * @style: a #GtkStyle
  * @window: a #GdkWindow
  * @state_type: a state
- * @area: rectangle to which the output is clipped
- * @widget: the widget
- * @detail: a style 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)
  * @y1_: the starting y coordinate
  * @y2_: the ending y coordinate
  * @x: the x coordinate
@@ -5858,6 +5644,7 @@ gtk_paint_vline (GtkStyle      *style,
 {
   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);
 }
@@ -5868,9 +5655,10 @@ gtk_paint_vline (GtkStyle      *style,
  * @window: a #GdkWindow
  * @state_type: a state
  * @shadow_type: type of shadow to draw
- * @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 of the rectangle
  * @y: y origin of the rectangle
  * @width: width of the rectangle 
@@ -5894,6 +5682,7 @@ 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);
 }
@@ -5904,9 +5693,10 @@ gtk_paint_shadow (GtkStyle     *style,
  * @window: a #GdkWindow
  * @state_type: a state
  * @shadow_type: type of shadow to draw
- * @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)
  * @points: an array of #GdkPoint<!-- -->s
  * @npoints: length of @points
  * @fill: %TRUE if the polygon should be filled
@@ -5927,6 +5717,7 @@ gtk_paint_polygon (GtkStyle      *style,
 {
   g_return_if_fail (GTK_IS_STYLE (style));
   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);
 }
@@ -5937,9 +5728,10 @@ gtk_paint_polygon (GtkStyle      *style,
  * @window: a #GdkWindow
  * @state_type: a state
  * @shadow_type: the type of shadow to draw
- * @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)
  * @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
@@ -5967,6 +5759,7 @@ 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);
 }
@@ -5977,9 +5770,10 @@ gtk_paint_arrow (GtkStyle      *style,
  * @window: a #GdkWindow
  * @state_type: a state
  * @shadow_type: the type of shadow to draw
- * @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 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
@@ -6003,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);
 }
@@ -6012,9 +5807,10 @@ 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
@@ -6036,6 +5832,7 @@ 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);
 }
@@ -6046,9 +5843,10 @@ gtk_paint_string (GtkStyle      *style,
  * @window: a #GdkWindow
  * @state_type: a state
  * @shadow_type: the type of shadow to draw
- * @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 of the box
  * @y: y origin of the box
  * @width: the width of the box
@@ -6071,6 +5869,7 @@ 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);
 }
@@ -6081,9 +5880,10 @@ gtk_paint_box (GtkStyle      *style,
  * @window: a #GdkWindow
  * @state_type: a state
  * @shadow_type: the type of shadow to draw
- * @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 of the box
  * @y: y origin of the box
  * @width: the width of the box
@@ -6106,6 +5906,7 @@ 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);
 }
@@ -6116,9 +5917,10 @@ gtk_paint_flat_box (GtkStyle      *style,
  * @window: a #GdkWindow
  * @state_type: a state
  * @shadow_type: the type of shadow to draw
- * @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 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
@@ -6142,6 +5944,7 @@ 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);
 }
@@ -6152,9 +5955,10 @@ gtk_paint_check (GtkStyle      *style,
  * @window: a #GdkWindow
  * @state_type: a state
  * @shadow_type: the type of shadow to draw
- * @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 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
@@ -6178,6 +5982,7 @@ 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);
 }
@@ -6188,9 +5993,10 @@ gtk_paint_option (GtkStyle      *style,
  * @window: a #GdkWindow
  * @state_type: a state
  * @shadow_type: the type of shadow to draw
- * @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 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
@@ -6214,6 +6020,7 @@ 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);
 }
@@ -6224,9 +6031,10 @@ gtk_paint_tab (GtkStyle      *style,
  * @window: a #GdkWindow
  * @state_type: a state
  * @shadow_type: type of shadow to draw
- * @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 of the rectangle
  * @y: y origin of the rectangle
  * @width: width of the rectangle 
@@ -6257,6 +6065,7 @@ 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);
 }
@@ -6268,9 +6077,10 @@ gtk_paint_shadow_gap (GtkStyle       *style,
  * @window: a #GdkWindow
  * @state_type: a state
  * @shadow_type: type of shadow to draw
- * @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 of the rectangle
  * @y: y origin of the rectangle
  * @width: width of the rectangle 
@@ -6300,6 +6110,7 @@ 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);
 }
@@ -6310,9 +6121,10 @@ gtk_paint_box_gap (GtkStyle       *style,
  * @window: a #GdkWindow
  * @state_type: a state
  * @shadow_type: type of shadow to draw
- * @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 of the extension
  * @y: y origin of the extension
  * @width: width of the extension 
@@ -6337,6 +6149,7 @@ 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);
 }
@@ -6346,9 +6159,10 @@ gtk_paint_extension (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: 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
@@ -6371,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);
 }
@@ -6391,6 +6206,7 @@ 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);
 }
@@ -6401,9 +6217,10 @@ gtk_paint_slider (GtkStyle      *style,
  * @window: a #GdkWindow
  * @state_type: a state
  * @shadow_type: type of shadow to draw
- * @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 of the handle
  * @y: y origin of the handle
  * @width: with of the handle
@@ -6428,6 +6245,7 @@ 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);
 }
@@ -6437,14 +6255,25 @@ gtk_paint_handle (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: 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
+ * @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.
+ * 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,
@@ -6459,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);
@@ -6478,6 +6308,7 @@ 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);
@@ -6488,9 +6319,10 @@ gtk_paint_layout (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)
  * @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
@@ -6516,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,
@@ -6795,7 +6628,11 @@ draw_insertion_cursor (GtkWidget        *widget,
   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;
@@ -6887,3 +6724,6 @@ gtk_draw_insertion_cursor (GtkWidget        *widget,
   if (area)
     gdk_gc_set_clip_rectangle (gc, NULL);
 }
+
+#define __GTK_STYLE_C__
+#include "gtkaliasdef.c"