]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkhsv.c
notebook: fixup the last commit
[~andy/gtk] / gtk / gtkhsv.c
index e6093fa3b5c045b79f07e7aad5bfbea82e7d0a0c..7c67fa50a2ddfaeeb73aa8cb1217cfe6bc7b6582 100644 (file)
 #include <math.h>
 #include <string.h>
 
-#include "gdk/gdkkeysyms.h"
-
 #include "gtkhsv.h"
 #include "gtkbindings.h"
 #include "gtkmarshalers.h"
-#include "gtktypeutils.h"
+#include "gtktypebuiltins.h"
 #include "gtkintl.h"
 
 /* Default width/height */
@@ -255,8 +253,6 @@ gtk_hsv_realize (GtkWidget *widget)
   priv->window = gdk_window_new (parent_window, &attr, attr_mask);
   gdk_window_set_user_data (priv->window, hsv);
   gdk_window_show (priv->window);
-
-  gtk_widget_style_attach (widget);
 }
 
 static void
@@ -669,22 +665,25 @@ compute_v (GtkHSV *hsv,
 /* Event handlers */
 
 static void
-set_cross_grab (GtkHSV *hsv,
-                guint32 time)
+set_cross_grab (GtkHSV    *hsv,
+                GdkDevice *device,
+                guint32    time)
 {
   GtkHSVPrivate *priv = hsv->priv;
   GdkCursor *cursor;
 
   cursor = gdk_cursor_new_for_display (gtk_widget_get_display (GTK_WIDGET (hsv)),
                                        GDK_CROSSHAIR);
-  gdk_pointer_grab (priv->window, FALSE,
-                    (GDK_POINTER_MOTION_MASK
-                     | GDK_POINTER_MOTION_HINT_MASK
-                     | GDK_BUTTON_RELEASE_MASK),
-                    NULL,
-                    cursor,
-                    time);
-  gdk_cursor_unref (cursor);
+  gdk_device_grab (device,
+                   priv->window,
+                   GDK_OWNERSHIP_NONE,
+                   FALSE,
+                   GDK_POINTER_MOTION_MASK
+                    | GDK_POINTER_MOTION_HINT_MASK
+                    | GDK_BUTTON_RELEASE_MASK,
+                   cursor,
+                   time);
+  g_object_unref (cursor);
 }
 
 static gboolean
@@ -709,15 +708,15 @@ gtk_hsv_button_press (GtkWidget      *widget,
 
   if (priv->mode != DRAG_NONE || event->button != 1)
     return FALSE;
-  
+
   x = event->x;
   y = event->y;
-  
+
   if (is_in_ring (hsv, x, y))
     {
       priv->mode = DRAG_H;
-      set_cross_grab (hsv, event->time);
-      
+      set_cross_grab (hsv, gdk_event_get_device ((GdkEvent *) event), event->time);
+
       gtk_hsv_set_color (hsv,
                          compute_v (hsv, x, y),
                          priv->s,
@@ -725,26 +724,26 @@ gtk_hsv_button_press (GtkWidget      *widget,
 
       gtk_widget_grab_focus (widget);
       priv->focus_on_ring = TRUE;
-      
+
       return TRUE;
     }
-  
+
   if (is_in_triangle (hsv, x, y))
     {
       gdouble s, v;
-      
+
       priv->mode = DRAG_SV;
-      set_cross_grab (hsv, event->time);
-      
+      set_cross_grab (hsv, gdk_event_get_device ((GdkEvent *) event), event->time);
+
       compute_sv (hsv, x, y, &s, &v);
       gtk_hsv_set_color (hsv, priv->h, s, v);
 
       gtk_widget_grab_focus (widget);
       priv->focus_on_ring = FALSE;
-      
+
       return TRUE;
     }
-  
+
   return FALSE;
 }
 
@@ -759,14 +758,13 @@ gtk_hsv_button_release (GtkWidget      *widget,
 
   if (priv->mode == DRAG_NONE || event->button != 1)
     return FALSE;
-  
+
   /* Set the drag mode to DRAG_NONE so that signal handlers for "catched"
    * can see that this is the final color state.
    */
-  
   mode = priv->mode;
   priv->mode = DRAG_NONE;
-  
+
   x = event->x;
   y = event->y;
 
@@ -786,8 +784,8 @@ gtk_hsv_button_release (GtkWidget      *widget,
       g_assert_not_reached ();
     }
 
-  gdk_display_pointer_ungrab (gdk_window_get_display (event->window),
-                              event->time);
+  gdk_device_ungrab (gdk_event_get_device ((GdkEvent *) event), event->time);
+
   return TRUE;
 }
 
@@ -797,8 +795,7 @@ gtk_hsv_motion (GtkWidget      *widget,
 {
   GtkHSV *hsv = GTK_HSV (widget);
   GtkHSVPrivate *priv = hsv->priv;
-  GdkModifierType mods;
-  double x, y;
+  gdouble x, y;
 
   if (priv->mode == DRAG_NONE)
     return FALSE;
@@ -806,7 +803,6 @@ gtk_hsv_motion (GtkWidget      *widget,
   gdk_event_request_motions (event);
   x = event->x;
   y = event->y;
-  mods = event->state;
 
   if (priv->mode == DRAG_H)
     {
@@ -997,10 +993,11 @@ paint_triangle (GtkHSV      *hsv,
   gint x_start, x_end;
   cairo_surface_t *source;
   gdouble r, g, b;
-  gchar *detail;
   gint stride;
   int width, height;
-  
+  GtkStyleContext *context;
+  GtkStateFlags state;
+
   priv = hsv->priv;
   width = gtk_widget_get_allocated_width (widget); 
   height = gtk_widget_get_allocated_height (widget); 
@@ -1142,14 +1139,20 @@ paint_triangle (GtkHSV      *hsv,
   b = priv->v;
   hsv_to_rgb (&r, &g, &b);
 
+  context = gtk_widget_get_style_context (widget);
+
+  gtk_style_context_save (context);
+  state = gtk_widget_get_state_flags (widget);
+  gtk_style_context_set_state (context, state);
+
   if (INTENSITY (r, g, b) > 0.5)
     {
-      detail = "colorwheel_light";
+      gtk_style_context_add_class (context, "light-area-focus");
       cairo_set_source_rgb (cr, 0., 0., 0.);
     }
   else
     {
-      detail = "colorwheel_dark";
+      gtk_style_context_add_class (context, "dark-area-focus");
       cairo_set_source_rgb (cr, 1., 1., 1.);
     }
 
@@ -1173,15 +1176,14 @@ paint_triangle (GtkHSV      *hsv,
                             "focus-padding", &focus_pad,
                             NULL);
 
-      gtk_paint_focus (gtk_widget_get_style (widget),
-                       cr,
-                       gtk_widget_get_state (widget),
-                       widget, detail,
-                       xx - FOCUS_RADIUS - focus_width - focus_pad,
-                       yy - FOCUS_RADIUS - focus_width - focus_pad,
-                       2 * (FOCUS_RADIUS + focus_width + focus_pad),
-                       2 * (FOCUS_RADIUS + focus_width + focus_pad));
+      gtk_render_focus (context, cr,
+                        xx - FOCUS_RADIUS - focus_width - focus_pad,
+                        yy - FOCUS_RADIUS - focus_width - focus_pad,
+                        2 * (FOCUS_RADIUS + focus_width + focus_pad),
+                        2 * (FOCUS_RADIUS + focus_width + focus_pad));
     }
+
+  gtk_style_context_restore (context);
 }
 
 /* Paints the contents of the HSV color selector */
@@ -1196,13 +1198,22 @@ gtk_hsv_draw (GtkWidget      *widget,
   paint_triangle (hsv, cr);
 
   if (gtk_widget_has_focus (widget) && priv->focus_on_ring)
-    gtk_paint_focus (gtk_widget_get_style (widget),
-                     cr,
-                     gtk_widget_get_state (widget),
-                     widget, NULL,
-                     0, 0,
-                     gtk_widget_get_allocated_width (widget),
-                     gtk_widget_get_allocated_height (widget));
+    {
+      GtkStyleContext *context;
+      GtkStateFlags state;
+
+      context = gtk_widget_get_style_context (widget);
+      state = gtk_widget_get_state_flags (widget);
+
+      gtk_style_context_save (context);
+      gtk_style_context_set_state (context, state);
+
+      gtk_render_focus (context, cr, 0, 0,
+                        gtk_widget_get_allocated_width (widget),
+                        gtk_widget_get_allocated_height (widget));
+
+      gtk_style_context_restore (context);
+    }
 
   return FALSE;
 }
@@ -1317,9 +1328,9 @@ gtk_hsv_set_color (GtkHSV *hsv,
 /**
  * gtk_hsv_get_color:
  * @hsv: An HSV color selector
- * @h: Return value for the hue
- * @s: Return value for the saturation
- * @v: Return value for the value
+ * @h: (out): Return value for the hue
+ * @s: (out): Return value for the saturation
+ * @v: (out): Return value for the value
  *
  * Queries the current color in an HSV color selector.
  * Returned values will be in the [0.0, 1.0] range.
@@ -1387,8 +1398,8 @@ gtk_hsv_set_metrics (GtkHSV *hsv,
 /**
  * gtk_hsv_get_metrics:
  * @hsv: An HSV color selector
- * @size: Return value for the diameter of the hue ring
- * @ring_width: Return value for the width of the hue ring
+ * @size: (out): Return value for the diameter of the hue ring
+ * @ring_width: (out): Return value for the width of the hue ring
  *
  * Queries the size and ring width of an HSV color selector.
  *
@@ -1444,9 +1455,9 @@ gtk_hsv_is_adjusting (GtkHSV *hsv)
  * @h: Hue
  * @s: Saturation
  * @v: Value
- * @r: Return value for the red component
- * @g: Return value for the green component
- * @b: Return value for the blue component
+ * @r: (out): Return value for the red component
+ * @g: (out): Return value for the green component
+ * @b: (out): Return value for the blue component
  *
  * Converts a color from HSV space to RGB.
  * Input values must be in the [0.0, 1.0] range; 
@@ -1483,9 +1494,9 @@ gtk_hsv_to_rgb (gdouble  h,
  * @r: Red
  * @g: Green
  * @b: Blue
- * @h: Return value for the hue component
- * @s: Return value for the saturation component
- * @v: Return value for the value component
+ * @h: (out): Return value for the hue component
+ * @s: (out): Return value for the saturation component
+ * @v: (out): Return value for the value component
  *
  * Converts a color from RGB space to HSV.
  * Input values must be in the [0.0, 1.0] range;