]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkhsv.c
fix recent files issues
[~andy/gtk] / gtk / gtkhsv.c
index 764edb7398226a71be8dc8c11dedc4dcc458e3da..0bd8ff2decb78aedff2a26622783332b9bc0c0d2 100644 (file)
@@ -30,6 +30,8 @@
 #include "gtkbindings.h"
 #include "gtkcontainer.h"
 #include "gtkmarshalers.h"
+#include "gtkintl.h"
+#include "gtkalias.h"
 
 /*
  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
@@ -86,8 +88,6 @@ enum {
   LAST_SIGNAL
 };
 
-static void     gtk_hsv_class_init     (GtkHSVClass      *class);
-static void     gtk_hsv_init           (GtkHSV           *hsv);
 static void     gtk_hsv_destroy        (GtkObject        *object);
 static void     gtk_hsv_map            (GtkWidget        *widget);
 static void     gtk_hsv_unmap          (GtkWidget        *widget);
@@ -105,66 +105,32 @@ static gint     gtk_hsv_motion         (GtkWidget        *widget,
                                        GdkEventMotion   *event);
 static gint     gtk_hsv_expose         (GtkWidget        *widget,
                                        GdkEventExpose   *event);
+static gboolean gtk_hsv_grab_broken    (GtkWidget          *widget,
+                                       GdkEventGrabBroken *event);
 static gboolean gtk_hsv_focus          (GtkWidget        *widget,
                                        GtkDirectionType  direction);
 static void     gtk_hsv_move           (GtkHSV           *hsv,
                                        GtkDirectionType  dir);
-static GdkGC *  gtk_hsv_get_focus_gc   (GtkHSV           *hsv,
-                                       gint             *line_width);
 
 static guint hsv_signals[LAST_SIGNAL];
-static GtkWidgetClass *parent_class;
 
-
-/**
- * gtk_hsv_get_type:
- * @void:
- *
- * Registers the &GtkHSV class if necessary, and returns the type ID associated
- * to it.
- *
- * Return value: The type ID of the &GtkHSV class.
- **/
-GType
-gtk_hsv_get_type (void)
-{
-  static GType hsv_type = 0;
-  
-  if (!hsv_type) {
-    static const GTypeInfo hsv_info = {
-      sizeof (GtkHSVClass),
-      NULL,            /* base_init */
-      NULL,            /* base_finalize */
-      (GClassInitFunc) gtk_hsv_class_init,
-      NULL,            /* class_finalize */
-      NULL,            /* class_data */
-      sizeof (GtkHSV),
-      0,               /* n_preallocs */
-      (GInstanceInitFunc) gtk_hsv_init,
-    };
-    
-    hsv_type = g_type_register_static (GTK_TYPE_WIDGET, "GtkHSV",
-                                      &hsv_info, 0);
-  }
-  
-  return hsv_type;
-}
+G_DEFINE_TYPE (GtkHSV, gtk_hsv, GTK_TYPE_WIDGET)
 
 /* Class initialization function for the HSV color selector */
 static void
 gtk_hsv_class_init (GtkHSVClass *class)
 {
+  GObjectClass   *gobject_class;
   GtkObjectClass *object_class;
   GtkWidgetClass *widget_class;
   GtkHSVClass    *hsv_class;
   GtkBindingSet  *binding_set;
   
+  gobject_class = (GObjectClass *) class;
   object_class = (GtkObjectClass *) class;
   widget_class = (GtkWidgetClass *) class;
   hsv_class = GTK_HSV_CLASS (class);
   
-  parent_class = g_type_class_peek_parent (class);
-  
   object_class->destroy = gtk_hsv_destroy;
   
   widget_class->map = gtk_hsv_map;
@@ -178,11 +144,12 @@ gtk_hsv_class_init (GtkHSVClass *class)
   widget_class->motion_notify_event = gtk_hsv_motion;
   widget_class->expose_event = gtk_hsv_expose;
   widget_class->focus = gtk_hsv_focus;
+  widget_class->grab_broken_event = gtk_hsv_grab_broken;
   
   hsv_class->move = gtk_hsv_move;
   
   hsv_signals[CHANGED] =
-    g_signal_new ("changed",
+    g_signal_new (I_("changed"),
                  G_OBJECT_CLASS_TYPE (object_class),
                  G_SIGNAL_RUN_FIRST,
                  G_STRUCT_OFFSET (GtkHSVClass, changed),
@@ -191,7 +158,7 @@ gtk_hsv_class_init (GtkHSVClass *class)
                  G_TYPE_NONE, 0);
 
   hsv_signals[MOVE] =
-    g_signal_new ("move",
+    g_signal_new (I_("move"),
                  G_OBJECT_CLASS_TYPE (object_class),
                  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                  G_STRUCT_OFFSET (GtkHSVClass, move),
@@ -230,6 +197,8 @@ gtk_hsv_class_init (GtkHSVClass *class)
   gtk_binding_entry_add_signal (binding_set, GDK_KP_Left, 0,
                                 "move", 1,
                                 G_TYPE_ENUM, GTK_DIR_LEFT);
+
+  g_type_class_add_private (gobject_class, sizeof (HSVPrivate));   
 }
 
 /* Object initialization function for the HSV color selector */
@@ -237,10 +206,11 @@ static void
 gtk_hsv_init (GtkHSV *hsv)
 {
   HSVPrivate *priv;
+
+  priv = G_TYPE_INSTANCE_GET_PRIVATE (hsv, GTK_TYPE_HSV, HSVPrivate);
   
-  priv = g_new0 (HSVPrivate, 1);
   hsv->priv = priv;
-  
+
   GTK_WIDGET_SET_FLAGS (hsv, GTK_NO_WINDOW);
   GTK_WIDGET_SET_FLAGS (hsv, GTK_CAN_FOCUS);
   
@@ -256,19 +226,7 @@ gtk_hsv_init (GtkHSV *hsv)
 static void
 gtk_hsv_destroy (GtkObject *object)
 {
-  GtkHSV *hsv;
-  
-  g_return_if_fail (GTK_IS_HSV (object));
-  
-  hsv = GTK_HSV (object);
-
-  if (hsv->priv)
-    {
-      g_free (hsv->priv);
-      hsv->priv = NULL;
-    }
-
-  GTK_OBJECT_CLASS (parent_class)->destroy (object);
+  GTK_OBJECT_CLASS (gtk_hsv_parent_class)->destroy (object);
 }
 
 /* Default signal handlers */
@@ -285,7 +243,7 @@ gtk_hsv_map (GtkWidget *widget)
   hsv = GTK_HSV (widget);
   priv = hsv->priv;
 
-  GTK_WIDGET_CLASS (parent_class)->map (widget);
+  GTK_WIDGET_CLASS (gtk_hsv_parent_class)->map (widget);
 
   gdk_window_show (priv->window);
 }
@@ -303,7 +261,7 @@ gtk_hsv_unmap (GtkWidget *widget)
 
   gdk_window_hide (priv->window);
 
-  GTK_WIDGET_CLASS (parent_class)->unmap (widget);
+  GTK_WIDGET_CLASS (gtk_hsv_parent_class)->unmap (widget);
 }                                                                           
                                       
 /* Realize handler for the HSV color selector */
@@ -371,8 +329,8 @@ gtk_hsv_unrealize (GtkWidget *widget)
   g_object_unref (priv->gc);
   priv->gc = NULL;
   
-  if (GTK_WIDGET_CLASS (parent_class)->unrealize)
-    GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
+  if (GTK_WIDGET_CLASS (gtk_hsv_parent_class)->unrealize)
+    GTK_WIDGET_CLASS (gtk_hsv_parent_class)->unrealize (widget);
 }
 
 /* Size_request handler for the HSV color selector */
@@ -629,13 +587,10 @@ compute_sv (GtkHSV  *hsv,
            gdouble *s,
            gdouble *v)
 {
-  HSVPrivate *priv;
   int ihx, ihy, isx, isy, ivx, ivy;
   double hx, hy, sx, sy, vx, vy;
   double center;
   
-  priv = hsv->priv;
-  
   compute_triangle (hsv, &ihx, &ihy, &isx, &isy, &ivx, &ivy);
   center = GTK_WIDGET (hsv)->requisition.width / 2.0;
   hx = ihx - center;
@@ -733,13 +688,10 @@ compute_v (GtkHSV *hsv,
           gdouble x,
           gdouble y)
 {
-  HSVPrivate *priv;
   double center;
   double dx, dy;
   double angle;
   
-  priv = hsv->priv;
-  
   center = GTK_WIDGET (hsv)->requisition.width / 2.0;
   dx = x - center;
   dy = center - y;
@@ -774,6 +726,20 @@ set_cross_grab (GtkHSV *hsv,
   gdk_cursor_unref (cursor);
 }
 
+static gboolean 
+gtk_hsv_grab_broken (GtkWidget          *widget,
+                    GdkEventGrabBroken *event)
+{
+  GtkHSV *hsv = GTK_HSV (widget);
+  HSVPrivate *priv;
+  
+  priv = hsv->priv;
+  
+  priv->mode = DRAG_NONE;
+  
+  return TRUE;
+}
+
 /* Button_press_event handler for the HSV color selector */
 static gint
 gtk_hsv_button_press (GtkWidget      *widget,
@@ -921,7 +887,7 @@ gtk_hsv_motion (GtkWidget      *widget,
 /* Paints the hue ring */
 static void
 paint_ring (GtkHSV      *hsv,
-           GdkDrawable *drawable,
+           cairo_t     *cr,
            gint         x,
            gint         y,
            gint         width,
@@ -933,13 +899,12 @@ paint_ring (GtkHSV      *hsv,
   gdouble dx, dy, dist;
   gdouble center;
   gdouble inner, outer;
-  guchar *buf, *p;
+  guint32 *buf, *p;
   gdouble angle;
   gdouble hue;
   gdouble r, g, b;
-  GdkBitmap *mask;
-  GdkGC *gc;
-  GdkColor color;
+  cairo_surface_t *source;
+  cairo_t *source_cr;
   gint focus_width;
   gint focus_pad;
 
@@ -955,13 +920,13 @@ paint_ring (GtkHSV      *hsv,
   outer = priv->size / 2.0;
   inner = outer - priv->ring_width;
   
-  /* Paint the ring */
+  /* Create an image initialized with the ring colors */
   
-  buf = g_new (guchar, width * height * 3);
+  buf = g_new (guint32, width * height);
   
   for (yy = 0; yy < height; yy++)
     {
-      p = buf + yy * width * 3;
+      p = buf + yy * width;
       
       dy = -(yy + y - center);
       
@@ -972,8 +937,6 @@ paint_ring (GtkHSV      *hsv,
          dist = dx * dx + dy * dy;
          if (dist < ((inner-1) * (inner-1)) || dist > ((outer+1) * (outer+1)))
            {
-             *p++ = 0;
-             *p++ = 0;
              *p++ = 0;
              continue;
            }
@@ -989,54 +952,20 @@ paint_ring (GtkHSV      *hsv,
          b = 1.0;
          hsv_to_rgb (&r, &g, &b);
          
-         *p++ = floor (r * 255 + 0.5);
-         *p++ = floor (g * 255 + 0.5);
-         *p++ = floor (b * 255 + 0.5);
+         *p++ = (((int)floor (r * 255 + 0.5) << 16) |
+                 ((int)floor (g * 255 + 0.5) << 8) |
+                 (int)floor (b * 255 + 0.5));
        }
     }
-  
-  /* Create clipping mask */
-  
-  mask = gdk_pixmap_new (GTK_WIDGET (hsv)->window, width, height, 1);
 
-  gc = gdk_gc_new (mask);
-  
-  color.pixel = 0;
-  gdk_gc_set_foreground (gc, &color);
-  gdk_draw_rectangle (mask, gc, TRUE,
-                     0, 0, width, height);
-  
-  
-  color.pixel = 1;
-  gdk_gc_set_foreground (gc, &color);
-  gdk_draw_arc (mask, gc, TRUE,
-               focus_width + focus_pad - x, 
-               focus_width + focus_pad - y,
-               priv->size - 1, priv->size - 1,
-               0, 360 * 64);
-  
-  color.pixel = 0;
-  gdk_gc_set_foreground (gc, &color);
-  gdk_draw_arc (mask, gc, TRUE,
-               focus_width + focus_pad - x + priv->ring_width - 1, 
-               focus_width + focus_pad - y + priv->ring_width - 1,
-               priv->size - 2 * priv->ring_width + 1, priv->size - 2 * priv->ring_width + 1,
-               0, 360 * 64);
-  
-  g_object_unref (gc);
-  
-  gdk_gc_set_clip_mask (priv->gc, mask);
-  gdk_gc_set_clip_origin (priv->gc, 0, 0);
-  
-  /* Draw ring */
-  
-  gdk_draw_rgb_image_dithalign (drawable, priv->gc, 0, 0, width, height,
-                               GDK_RGB_DITHER_MAX,
-                               buf,
-                               width * 3,
-                               x, y);
-  
-  /* Draw value marker */
+  source = cairo_image_surface_create_for_data ((char *)buf,
+                                               CAIRO_FORMAT_RGB24,
+                                               width, height, 4 * width);
+
+  /* Now draw the value marker onto the source image, so that it
+   * will get properly clipped at the edges of the ring
+   */
+  source_cr = cairo_create (source);
   
   r = priv->h;
   g = 1.0;
@@ -1044,39 +973,35 @@ paint_ring (GtkHSV      *hsv,
   hsv_to_rgb (&r, &g, &b);
   
   if (INTENSITY (r, g, b) > 0.5)
-    {
-      color.red = 0x0000;
-      color.green = 0x0000;
-      color.blue = 0x0000;
-    }
+    cairo_set_source_rgb (source_cr, 0., 0., 0.);
   else
-    {
-      color.red = 0xffff;
-      color.green = 0xffff;
-      color.blue = 0xffff;
-    }
+    cairo_set_source_rgb (source_cr, 1., 1., 1.);
 
-  gdk_gc_set_rgb_fg_color (priv->gc, &color);
-  
-  gdk_draw_line (drawable, priv->gc,
-                -x + center, -y + center,
+  cairo_move_to (source_cr, -x + center, - y + center);
+  cairo_line_to (source_cr,
                 -x + center + cos (priv->h * 2.0 * G_PI) * center,
                 -y + center - sin (priv->h * 2.0 * G_PI) * center);
+  cairo_stroke (source_cr);
+  cairo_destroy (source_cr);
+
+  /* Draw the ring using the source image */
+
+  cairo_save (cr);
+    
+  cairo_set_source_surface (cr, source, x, y);
+  cairo_surface_destroy (source);
+
+  cairo_set_line_width (cr, priv->ring_width);
+  cairo_new_path (cr);
+  cairo_arc (cr,
+            center, center,
+            priv->size / 2. - priv->ring_width / 2.,
+            0, 2 * G_PI);
+  cairo_stroke (cr);
   
-  gdk_gc_set_clip_mask (priv->gc, NULL);
-  g_object_unref (mask);
+  cairo_restore (cr);
   
   g_free (buf);
-  
-  /* Draw ring outline */
-
-  if (GTK_WIDGET_HAS_FOCUS (hsv) && priv->focus_on_ring)
-    {
-      gtk_paint_focus (widget->style, drawable,
-                      GTK_WIDGET_STATE (widget),
-                      NULL, widget, NULL,
-                      x, y, width, height);
-    }
 }
 
 /* Converts an HSV triplet to an integer RGB triplet */
@@ -1101,10 +1026,15 @@ get_color (gdouble h,
                               ? ((a) + ((b) - (a)) * ((i) - (v1)) / ((v2) - (v1)))     \
                               : (a))
 
+/* Number of pixels we extend out from the edges when creating
+ * color source to avoid artifacts
+ */
+#define PAD 3
+
 /* Paints the HSV triangle */
 static void
 paint_triangle (GtkHSV      *hsv,
-               GdkDrawable *drawable,
+               cairo_t     *cr,
                gint         x,
                gint         y,
                gint         width,
@@ -1117,13 +1047,12 @@ paint_triangle (GtkHSV      *hsv,
   gint x2, y2, r2, g2, b2; /* Second vertex */
   gint x3, y3, r3, g3, b3; /* Third vertex */
   gint t;
-  guchar *buf, *p;
+  guint32 *buf, *p, c;
   gint xl, xr, rl, rr, gl, gr, bl, br; /* Scanline data */
   gint xx, yy;
-  GdkBitmap *mask;
-  GdkGC *gc;
-  GdkColor color;
-  GdkPoint points[3];
+  gint x_interp, y_interp;
+  gint x_start, x_end;
+  cairo_surface_t *source;
   gdouble r, g, b;
   gchar *detail;
   
@@ -1174,42 +1103,37 @@ paint_triangle (GtkHSV      *hsv,
   
   /* Shade the triangle */
   
-  buf = g_new (guchar, width * height * 3);
+  buf = g_new (guint32, width * height);
   
   for (yy = 0; yy < height; yy++)
     {
-      p = buf + yy * width * 3;
+      p = buf + yy * width;
       
-      if (yy + y < y1 || yy + y > y3)
-       for (xx = 0; xx < width; xx++)
-         {
-           *p++ = 0;
-           *p++ = 0;
-           *p++ = 0;
-         }
-      else {
-       if (yy + y < y2)
+      if (yy + y >= y1 - PAD && yy + y < y3 + PAD) {
+       y_interp = CLAMP (yy + y, y1, y3);
+       
+       if (y_interp < y2)
          {
-           xl = LERP (x1, x2, y1, y2, yy + y);
+           xl = LERP (x1, x2, y1, y2, y_interp);
            
-           rl = LERP (r1, r2, y1, y2, yy + y);
-           gl = LERP (g1, g2, y1, y2, yy + y);
-           bl = LERP (b1, b2, y1, y2, yy + y);
+           rl = LERP (r1, r2, y1, y2, y_interp);
+           gl = LERP (g1, g2, y1, y2, y_interp);
+           bl = LERP (b1, b2, y1, y2, y_interp);
          }
        else
          {
-           xl = LERP (x2, x3, y2, y3, yy + y);
+           xl = LERP (x2, x3, y2, y3, y_interp);
            
-           rl = LERP (r2, r3, y2, y3, yy + y);
-           gl = LERP (g2, g3, y2, y3, yy + y);
-           bl = LERP (b2, b3, y2, y3, yy + y);
+           rl = LERP (r2, r3, y2, y3, y_interp);
+           gl = LERP (g2, g3, y2, y3, y_interp);
+           bl = LERP (b2, b3, y2, y3, y_interp);
          }
        
-       xr = LERP (x1, x3, y1, y3, yy + y);
+       xr = LERP (x1, x3, y1, y3, y_interp);
        
-       rr = LERP (r1, r3, y1, y3, yy + y);
-       gr = LERP (g1, g3, y1, y3, yy + y);
-       br = LERP (b1, b3, y1, y3, yy + y);
+       rr = LERP (r1, r3, y1, y3, y_interp);
+       gr = LERP (g1, g3, y1, y3, y_interp);
+       br = LERP (b1, b3, y1, y3, y_interp);
        
        if (xl > xr)
          {
@@ -1218,69 +1142,53 @@ paint_triangle (GtkHSV      *hsv,
            SWAP (gl, gr, t);
            SWAP (bl, br, t);
          }
-       
-       for (xx = 0; xx < width; xx++)
+
+       x_start = MAX (xl - PAD, x);
+       x_end = MIN (xr + PAD, x + width);
+       x_start = MIN (x_start, x_end);
+
+       c = (rl << 16) | (gl << 8) | bl;
+
+       for (xx = x; xx < x_start; xx++)
+         *p++ = c;
+         
+       for (; xx < x_end; xx++)
          {
-           if (xx + x < xl || xx + x > xr)
-             {
-               *p++ = 0;
-               *p++ = 0;
-               *p++ = 0;
-             }
-           else
-             {
-               *p++ = LERP (rl, rr, xl, xr, xx + x);
-               *p++ = LERP (gl, gr, xl, xr, xx + x);
-               *p++ = LERP (bl, br, xl, xr, xx + x);
-             }
+           x_interp = CLAMP (xx, xl, xr);
+               
+           *p++ = ((LERP (rl, rr, xl, xr, x_interp) << 16) |
+                   (LERP (gl, gr, xl, xr, x_interp) << 8) |
+                   LERP (bl, br, xl, xr, x_interp));
          }
+
+       c = (rr << 16) | (gr << 8) | br;
+
+       for (; xx < x + width; xx++)
+         *p++ = c;
       }
     }
-  
-  /* Create clipping mask */
-  
-  mask = gdk_pixmap_new (widget->window, width, height, 1);
 
-  gc = gdk_gc_new (mask);
-  
-  color.pixel = 0;
-  gdk_gc_set_foreground (gc, &color);
-  gdk_draw_rectangle (mask, gc, TRUE,
-                     0, 0, width, height);
-  
-  color.pixel = 1;
-  gdk_gc_set_foreground (gc, &color);
+  source = cairo_image_surface_create_for_data ((char *)buf,
+                                               CAIRO_FORMAT_RGB24,
+                                               width, height, 4 * width);
   
-  points[0].x = x1 - x;
-  points[0].y = y1 - y;
-  points[1].x = x2 - x;
-  points[1].y = y2 - y;
-  points[2].x = x3 - x;
-  points[2].y = y3 - y;
-  gdk_draw_polygon (mask, gc, TRUE, points, 3);
-  
-  g_object_unref (gc);
-  
-  gdk_gc_set_clip_mask (priv->gc, mask);
-  gdk_gc_set_clip_origin (priv->gc, 0, 0);
-  
-  /* Draw triangle */
-  
-  gdk_draw_rgb_image_dithalign (drawable, priv->gc, 0, 0, width, height,
-                               GDK_RGB_DITHER_MAX,
-                               buf,
-                               width * 3,
-                               x, y);
+  /* Draw a triangle with the image as a source */
+
+  cairo_set_source_surface (cr, source, x, y);
+  cairo_surface_destroy (source);
   
-  gdk_gc_set_clip_mask (priv->gc, NULL);
-  g_object_unref (mask);
+  cairo_move_to (cr, x1, y1);
+  cairo_line_to (cr, x2, y2);
+  cairo_line_to (cr, x3, y3);
+  cairo_close_path (cr);
+  cairo_fill (cr);
   
   g_free (buf);
   
   /* Draw value marker */
   
-  xx = floor (sx + (vx - sx) * priv->v + (hx - vx) * priv->s * priv->v + 0.5) - x;
-  yy = floor (sy + (vy - sy) * priv->v + (hy - vy) * priv->s * priv->v + 0.5) - y;
+  xx = floor (sx + (vx - sx) * priv->v + (hx - vx) * priv->s * priv->v + 0.5);
+  yy = floor (sy + (vy - sy) * priv->v + (hy - vy) * priv->s * priv->v + 0.5);
   
   r = priv->h;
   g = priv->s;
@@ -1290,33 +1198,21 @@ paint_triangle (GtkHSV      *hsv,
   if (INTENSITY (r, g, b) > 0.5)
     {
       detail = "colorwheel_light";
-      color.red = 0x0000;
-      color.green = 0x0000;
-      color.blue = 0x0000;
+      cairo_set_source_rgb (cr, 0., 0., 0.);
     }
   else
     {
       detail = "colorwheel_dark";
-      color.red = 0xffff;
-      color.green = 0xffff;
-      color.blue = 0xffff;
+      cairo_set_source_rgb (cr, 1., 1., 1.);
     }
 
-  gdk_gc_set_rgb_fg_color (priv->gc, &color);
-
-#define OUTER_RADIUS 4
-#define INNER_RADIUS 3 
+#define RADIUS 4
 #define FOCUS_RADIUS 6
-  
-  gdk_draw_arc (drawable, priv->gc, FALSE,
-               xx - OUTER_RADIUS, yy - OUTER_RADIUS,
-               OUTER_RADIUS * 2, OUTER_RADIUS * 2,
-               0, 360 * 64);
-  gdk_draw_arc (drawable, priv->gc, FALSE,
-               xx - INNER_RADIUS, yy - INNER_RADIUS,
-               INNER_RADIUS * 2, INNER_RADIUS * 2,
-               0, 360 * 64);
 
+  cairo_new_path (cr);
+  cairo_arc (cr, xx, yy, RADIUS, 0, 2 * G_PI);
+  cairo_stroke (cr);
+  
   /* Draw focus outline */
 
   if (GTK_WIDGET_HAS_FOCUS (hsv) &&
@@ -1330,11 +1226,11 @@ paint_triangle (GtkHSV      *hsv,
                            "focus-padding", &focus_pad,
                            NULL);
   
-      gtk_paint_focus (widget->style, drawable,
+      gtk_paint_focus (widget->style, widget->window,
                       GTK_WIDGET_STATE (widget),
                       NULL, widget, detail,
-                      xx - FOCUS_RADIUS - focus_width - focus_pad, 
-                      yy - FOCUS_RADIUS - focus_width - focus_pad, 
+                      widget->allocation.x + xx - FOCUS_RADIUS - focus_width - focus_pad, 
+                      widget->allocation.y + yy - FOCUS_RADIUS - focus_width - focus_pad, 
                       2 * (FOCUS_RADIUS + focus_width + focus_pad), 
                       2 * (FOCUS_RADIUS + focus_width + focus_pad));
     }
@@ -1344,14 +1240,14 @@ paint_triangle (GtkHSV      *hsv,
 /* Paints the contents of the HSV color selector */
 static void
 paint (GtkHSV      *hsv,
-       GdkDrawable *drawable,
+       cairo_t     *cr,
        gint         x,
        gint         y,
        gint         width,
        gint         height)
 {
-  paint_ring (hsv, drawable, x, y, width, height);
-  paint_triangle (hsv, drawable, x, y, width, height);
+  paint_ring (hsv, cr, x, y, width, height);
+  paint_triangle (hsv, cr, x, y, width, height);
 }
 
 /* Expose_event handler for the HSV color selector */
@@ -1362,14 +1258,14 @@ gtk_hsv_expose (GtkWidget      *widget,
   GtkHSV *hsv;
   HSVPrivate *priv;
   GdkRectangle rect, dest;
-  GdkPixmap *pixmap;
+  cairo_t *cr;
   
   hsv = GTK_HSV (widget);
   priv = hsv->priv;
   
   if (!(GTK_WIDGET_DRAWABLE (widget) && event->window == widget->window))
     return FALSE;
-  
+
   rect.x = widget->allocation.x;
   rect.y = widget->allocation.y;
   rect.width = widget->allocation.width;
@@ -1378,31 +1274,24 @@ gtk_hsv_expose (GtkWidget      *widget,
   if (!gdk_rectangle_intersect (&event->area, &rect, &dest))
     return FALSE;
   
-  pixmap = gdk_pixmap_new (widget->window, dest.width, dest.height,
-                          gtk_widget_get_visual (widget)->depth);
-  
-  rect = dest;
-  rect.x = 0;
-  rect.y = 0;
-  
-  gdk_draw_rectangle (pixmap,
-                     widget->style->bg_gc[GTK_WIDGET_STATE (widget)],
-                     TRUE,
-                     0, 0, dest.width, dest.height);
-  paint (hsv, pixmap,
-        dest.x - widget->allocation.x, dest.y - widget->allocation.y,
+  cr = gdk_cairo_create (widget->window);
+
+  cairo_translate (cr, widget->allocation.x, widget->allocation.y);
+  paint (hsv, cr,
+        dest.x - widget->allocation.x,
+        dest.y - widget->allocation.y,
         dest.width, dest.height);
-  
-  gdk_draw_drawable (widget->window,
-                    priv->gc,
-                    pixmap,
-                    0, 0,
-                    dest.x,
-                    dest.y,
-                    event->area.width, event->area.height);
-  
-  g_object_unref (pixmap);
-  
+  cairo_destroy (cr);
+
+  if (GTK_WIDGET_HAS_FOCUS (hsv) && priv->focus_on_ring)
+    gtk_paint_focus (widget->style, widget->window,
+                    GTK_WIDGET_STATE (widget),
+                    &event->area, widget, NULL,
+                    widget->allocation.x,
+                    widget->allocation.y, 
+                    widget->allocation.width, 
+                    widget->allocation.height);
+
   return FALSE;
 }
 
@@ -1497,7 +1386,6 @@ gtk_hsv_set_color (GtkHSV *hsv,
 {
   HSVPrivate *priv;
   
-  g_return_if_fail (hsv != NULL);
   g_return_if_fail (GTK_IS_HSV (hsv));
   g_return_if_fail (h >= 0.0 && h <= 1.0);
   g_return_if_fail (s >= 0.0 && s <= 1.0);
@@ -1778,29 +1666,5 @@ gtk_hsv_move (GtkHSV          *hsv,
   gtk_hsv_set_color (hsv, hue, sat, val);
 }
 
-static GdkGC *
-gtk_hsv_get_focus_gc (GtkHSV *hsv,
-                     gint   *line_width)
-{
-  GdkGC *focus_gc;
-  GtkWidget *widget = GTK_WIDGET (hsv);
-  gint8 *dash_list;
-  
-  focus_gc = gdk_gc_new (widget->window);
-  gdk_gc_copy (focus_gc, widget->style->fg_gc[GTK_WIDGET_STATE (widget)]);
-
-  gtk_widget_style_get (widget,
-                       "focus-line-width", line_width,
-                       "focus-line-pattern", (gchar *)&dash_list,
-                       NULL);
-  
-  gdk_gc_set_line_attributes (focus_gc, *line_width,
-                             dash_list[0] ? GDK_LINE_ON_OFF_DASH : GDK_LINE_SOLID,
-                             GDK_CAP_BUTT, GDK_JOIN_MITER);
-  if (dash_list[0])
-    gdk_gc_set_dashes (focus_gc, 0, dash_list, strlen (dash_list));
-
-  g_free (dash_list);
-  
-  return focus_gc;
-}
+#define __GTK_HSV_C__
+#include "gtkaliasdef.c"