]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkhsv.c
treeview: Simplify code
[~andy/gtk] / gtk / gtkhsv.c
index 7c67fa50a2ddfaeeb73aa8cb1217cfe6bc7b6582..6266b4f17d040f2f3f11fe0db4e990c59985d3a4 100644 (file)
 #include "gtktypebuiltins.h"
 #include "gtkintl.h"
 
+
+/**
+ * SECTION:gtkhsv
+ * @Short_description: A 'color wheel' widget
+ * @Title: GtkHSV
+ * @See_also: #GtkColorSelection, #GtkColorSelectionDialog
+ *
+ * #GtkHSV is the 'color wheel' part of a complete color selector widget.
+ * It allows to select a color by determining its HSV components in an
+ * intuitive way. Moving the selection around the outer ring changes the hue,
+ * and moving the selection point inside the inner triangle changes value and
+ * saturation.
+ */
+
+
 /* Default width/height */
 #define DEFAULT_SIZE 100
 
@@ -140,6 +155,8 @@ gtk_hsv_class_init (GtkHSVClass *class)
   widget_class->focus = gtk_hsv_focus;
   widget_class->grab_broken_event = gtk_hsv_grab_broken;
 
+  gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_COLOR_CHOOSER);
+
   hsv_class->move = gtk_hsv_move;
 
   hsv_signals[CHANGED] =
@@ -845,13 +862,6 @@ paint_ring (GtkHSV  *hsv,
   cairo_surface_t *source;
   cairo_t *source_cr;
   gint stride;
-  gint focus_width;
-  gint focus_pad;
-
-  gtk_widget_style_get (widget,
-                        "focus-line-width", &focus_width,
-                        "focus-padding", &focus_pad,
-                        NULL);
 
   width = gtk_widget_get_allocated_width (widget);
   height = gtk_widget_get_allocated_height (widget);
@@ -976,8 +986,9 @@ get_color (gdouble h,
 
 /* Paints the HSV triangle */
 static void
-paint_triangle (GtkHSV      *hsv,
-                cairo_t     *cr)
+paint_triangle (GtkHSV   *hsv,
+                cairo_t  *cr,
+                gboolean  draw_focus)
 {
   GtkHSVPrivate *priv = hsv->priv;
   GtkWidget *widget = GTK_WIDGET (hsv);
@@ -1165,8 +1176,7 @@ paint_triangle (GtkHSV      *hsv,
   
   /* Draw focus outline */
 
-  if (gtk_widget_has_focus (widget) &&
-      !priv->focus_on_ring)
+  if (draw_focus && !priv->focus_on_ring)
     {
       gint focus_width;
       gint focus_pad;
@@ -1188,16 +1198,20 @@ paint_triangle (GtkHSV      *hsv,
 
 /* Paints the contents of the HSV color selector */
 static gboolean
-gtk_hsv_draw (GtkWidget      *widget,
-              cairo_t        *cr)
+gtk_hsv_draw (GtkWidget *widget,
+              cairo_t   *cr)
 {
   GtkHSV *hsv = GTK_HSV (widget);
   GtkHSVPrivate *priv = hsv->priv;
+  gboolean draw_focus;
+
+  draw_focus = gtk_widget_has_visible_focus (widget);
 
   paint_ring (hsv, cr);
-  paint_triangle (hsv, cr);
+  paint_triangle (hsv, cr, draw_focus);
 
-  if (gtk_widget_has_focus (widget) && priv->focus_on_ring)
+
+  if (draw_focus && priv->focus_on_ring)
     {
       GtkStyleContext *context;
       GtkStateFlags state;
@@ -1343,18 +1357,18 @@ gtk_hsv_get_color (GtkHSV *hsv,
                    double *s,
                    double *v)
 {
-  GtkHSVPrivate *priv = hsv->priv;
+  GtkHSVPrivate *priv;
 
   g_return_if_fail (GTK_IS_HSV (hsv));
 
   priv = hsv->priv;
-  
+
   if (h)
     *h = priv->h;
-  
+
   if (s)
     *s = priv->s;
-  
+
   if (v)
     *v = priv->v;
 }
@@ -1374,7 +1388,7 @@ gtk_hsv_set_metrics (GtkHSV *hsv,
                      gint    size,
                      gint    ring_width)
 {
-  GtkHSVPrivate *priv = hsv->priv;
+  GtkHSVPrivate *priv;
   int same_size;
 
   g_return_if_fail (GTK_IS_HSV (hsv));
@@ -1385,7 +1399,7 @@ gtk_hsv_set_metrics (GtkHSV *hsv,
   priv = hsv->priv;
 
   same_size = (priv->size == size);
-  
+
   priv->size = size;
   priv->ring_width = ring_width;
   
@@ -1410,7 +1424,7 @@ gtk_hsv_get_metrics (GtkHSV *hsv,
                      gint   *size,
                      gint   *ring_width)
 {
-  GtkHSVPrivate *priv = hsv->priv;
+  GtkHSVPrivate *priv;
 
   g_return_if_fail (GTK_IS_HSV (hsv));
 
@@ -1441,7 +1455,7 @@ gtk_hsv_get_metrics (GtkHSV *hsv,
 gboolean
 gtk_hsv_is_adjusting (GtkHSV *hsv)
 {
-  GtkHSVPrivate *priv = hsv->priv;
+  GtkHSVPrivate *priv;
 
   g_return_val_if_fail (GTK_IS_HSV (hsv), FALSE);
 
@@ -1603,3 +1617,4 @@ gtk_hsv_move (GtkHSV          *hsv,
   
   gtk_hsv_set_color (hsv, hue, sat, val);
 }
+