]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkcolorsel.c
Merge libgdk and libgtk
[~andy/gtk] / gtk / gtkcolorsel.c
index 200d35b5cd32a25943816daefdfd9185edf9bae9..2f029ac333227b2997909679eb47afc8b4f725c2 100644 (file)
@@ -32,8 +32,7 @@
 #include <math.h>
 #include <string.h>
 
-#include "gdkconfig.h"
-#include "gdk/gdkkeysyms.h"
+#include "gdk/gdk.h"
 #include "gtkhsv.h"
 #include "gtkwindow.h"
 #include "gtkselection.h"
 #include "gtkprivate.h"
 #include "gtkintl.h"
 
+
+/**
+ * SECTION:gtkcolorsel
+ * @Short_description: A widget used to select a color
+ * @Title: GtkColorSelection
+ *
+ * The #GtkColorSelection is a widget that is used to select
+ * a color.  It consists of a color wheel and number of sliders
+ * and entry boxes for color parameters such as hue, saturation,
+ * value, red, green, blue, and opacity.  It is found on the standard
+ * color selection dialog box #GtkColorSelectionDialog.
+ */
+
+
+/* Keep it in sync with gtksettings.c:default_color_palette */
+#define DEFAULT_COLOR_PALETTE   "black:white:gray50:red:purple:blue:light blue:green:yellow:orange:lavender:brown:goldenrod4:dodger blue:pink:light green:gray10:gray30:gray75:gray90"
+
 /* Number of elements in the custom palatte */
 #define GTK_CUSTOM_PALETTE_WIDTH 10
 #define GTK_CUSTOM_PALETTE_HEIGHT 2
@@ -99,7 +115,8 @@ enum {
   PROP_HAS_PALETTE,
   PROP_HAS_OPACITY_CONTROL,
   PROP_CURRENT_COLOR,
-  PROP_CURRENT_ALPHA
+  PROP_CURRENT_ALPHA,
+  PROP_CURRENT_RGBA
 };
 
 enum {
@@ -159,7 +176,7 @@ struct _GtkColorSelectionPrivate
 };
 
 
-static void gtk_color_selection_destroy                (GtkObject               *object);
+static void gtk_color_selection_destroy                (GtkWidget               *widget);
 static void gtk_color_selection_finalize        (GObject                *object);
 static void update_color                       (GtkColorSelection       *colorsel);
 static void gtk_color_selection_set_property    (GObject                 *object,
@@ -235,8 +252,6 @@ static void shutdown_eyedropper (GtkWidget *widget);
 
 static guint color_selection_signals[LAST_SIGNAL] = { 0 };
 
-static const gchar default_colors[] = "black:white:gray50:red:purple:blue:light blue:green:yellow:orange:lavender:brown:goldenrod4:dodger blue:pink:light green:gray10:gray30:gray75:gray90";
-
 static GtkColorSelectionChangePaletteFunc noscreen_change_palette_hook = default_noscreen_change_palette_func;
 static GtkColorSelectionChangePaletteWithScreenFunc change_palette_hook = default_change_palette_func;
 
@@ -289,7 +304,6 @@ static void
 gtk_color_selection_class_init (GtkColorSelectionClass *klass)
 {
   GObjectClass *gobject_class;
-  GtkObjectClass *object_class;
   GtkWidgetClass *widget_class;
   
   gobject_class = G_OBJECT_CLASS (klass);
@@ -297,10 +311,8 @@ gtk_color_selection_class_init (GtkColorSelectionClass *klass)
   gobject_class->set_property = gtk_color_selection_set_property;
   gobject_class->get_property = gtk_color_selection_get_property;
 
-  object_class = GTK_OBJECT_CLASS (klass);
-  object_class->destroy = gtk_color_selection_destroy;
-  
   widget_class = GTK_WIDGET_CLASS (klass);
+  widget_class->destroy = gtk_color_selection_destroy;
   widget_class->realize = gtk_color_selection_realize;
   widget_class->unrealize = gtk_color_selection_unrealize;
   widget_class->show_all = gtk_color_selection_show_all;
@@ -334,23 +346,39 @@ gtk_color_selection_class_init (GtkColorSelectionClass *klass)
                                                      P_("The current opacity value (0 fully transparent, 65535 fully opaque)"),
                                                      0, 65535, 65535,
                                                      GTK_PARAM_READWRITE));
-  
+
+  /**
+   * GtkColorSelection:current-rgba
+   *
+   * The current RGBA color.
+   *
+   * Since: 3.0
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_CURRENT_RGBA,
+                                   g_param_spec_boxed ("current-rgba",
+                                                       P_("Current RGBA"),
+                                                       P_("The current RGBA color"),
+                                                       GDK_TYPE_RGBA,
+                                                       GTK_PARAM_READWRITE));
+
+  /**
+   * GtkColorSelection::color-changed:
+   * @colorselection: the object which received the signal.
+   *
+   * This signal is emitted when the color changes in the #GtkColorSelection
+   * according to its update policy.
+   */
   color_selection_signals[COLOR_CHANGED] =
     g_signal_new (I_("color-changed"),
-                 G_OBJECT_CLASS_TYPE (object_class),
+                 G_OBJECT_CLASS_TYPE (gobject_class),
                  G_SIGNAL_RUN_FIRST,
                  G_STRUCT_OFFSET (GtkColorSelectionClass, color_changed),
                  NULL, NULL,
                  _gtk_marshal_VOID__VOID,
                  G_TYPE_NONE, 0);
 
-  gtk_settings_install_property (g_param_spec_string ("gtk-color-palette",
-                                                      P_("Custom palette"),
-                                                      P_("Palette to use in the color selector"),
-                                                      default_colors,
-                                                      GTK_PARAM_READWRITE));
-
-   g_type_class_add_private (gobject_class, sizeof (GtkColorSelectionPrivate));
+  g_type_class_add_private (gobject_class, sizeof (GtkColorSelectionPrivate));
 }
 
 static void
@@ -373,10 +401,10 @@ gtk_color_selection_init (GtkColorSelection *colorsel)
   priv->default_set = FALSE;
   priv->default_alpha_set = FALSE;
   
-  top_hbox = gtk_hbox_new (FALSE, 12);
+  top_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
   gtk_box_pack_start (GTK_BOX (colorsel), top_hbox, FALSE, FALSE, 0);
   
-  vbox = gtk_vbox_new (FALSE, 6);
+  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
   priv->triangle_colorsel = gtk_hsv_new ();
   g_signal_connect (priv->triangle_colorsel, "changed",
                     G_CALLBACK (hsv_changed), colorsel);
@@ -386,7 +414,7 @@ gtk_color_selection_init (GtkColorSelection *colorsel)
   gtk_widget_set_tooltip_text (priv->triangle_colorsel,
                         _("Select the color you want from the outer ring. Select the darkness or lightness of that color using the inner triangle."));
   
-  hbox = gtk_hbox_new (FALSE, 6);
+  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
   gtk_box_pack_end (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
   
   frame = gtk_frame_new (NULL);
@@ -410,7 +438,7 @@ gtk_color_selection_init (GtkColorSelection *colorsel)
   gtk_widget_set_tooltip_text (button,
                         _("Click the eyedropper, then click a color anywhere on your screen to select that color."));
   
-  top_right_vbox = gtk_vbox_new (FALSE, 6);
+  top_right_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
   gtk_box_pack_start (GTK_BOX (top_hbox), top_right_vbox, FALSE, FALSE, 0);
   table = gtk_table_new (8, 6, FALSE);
   gtk_box_pack_start (GTK_BOX (top_right_vbox), table, FALSE, FALSE, 0);
@@ -430,14 +458,14 @@ gtk_color_selection_init (GtkColorSelection *colorsel)
                          _("Amount of green light in the color."));
   make_label_spinbutton (colorsel, &priv->blue_spinbutton, _("_Blue:"), table, 6, 2, COLORSEL_BLUE,
                          _("Amount of blue light in the color."));
-  gtk_table_attach_defaults (GTK_TABLE (table), gtk_hseparator_new (), 0, 8, 3, 4); 
+  gtk_table_attach_defaults (GTK_TABLE (table), gtk_separator_new (GTK_ORIENTATION_HORIZONTAL), 0, 8, 3, 4); 
 
   priv->opacity_label = gtk_label_new_with_mnemonic (_("Op_acity:")); 
   gtk_misc_set_alignment (GTK_MISC (priv->opacity_label), 0.0, 0.5); 
   gtk_table_attach_defaults (GTK_TABLE (table), priv->opacity_label, 0, 1, 4, 5); 
-  adjust = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 255.0, 1.0, 1.0, 0.0)); 
+  adjust = gtk_adjustment_new (0.0, 0.0, 255.0, 1.0, 1.0, 0.0);
   g_object_set_data (G_OBJECT (adjust), I_("COLORSEL"), colorsel); 
-  priv->opacity_slider = gtk_hscale_new (adjust);
+  priv->opacity_slider = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, adjust);
   gtk_widget_set_tooltip_text (priv->opacity_slider,
                         _("Transparency of the color."));
   gtk_label_set_mnemonic_widget (GTK_LABEL (priv->opacity_label),
@@ -499,7 +527,7 @@ gtk_color_selection_init (GtkColorSelection *colorsel)
        }
     }
   set_selected_palette (colorsel, 0, 0);
-  priv->palette_frame = gtk_vbox_new (FALSE, 6);
+  priv->palette_frame = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
   label = gtk_label_new_with_mnemonic (_("_Palette:"));
   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
   gtk_box_pack_start (GTK_BOX (priv->palette_frame), label, FALSE, FALSE, 0);
@@ -568,6 +596,9 @@ gtk_color_selection_set_property (GObject         *object,
     case PROP_CURRENT_ALPHA:
       gtk_color_selection_set_current_alpha (colorsel, g_value_get_uint (value));
       break;
+    case PROP_CURRENT_RGBA:
+      gtk_color_selection_set_current_rgba (colorsel, g_value_get_boxed (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -599,18 +630,26 @@ gtk_color_selection_get_property (GObject     *object,
     case PROP_CURRENT_ALPHA:
       g_value_set_uint (value, gtk_color_selection_get_current_alpha (colorsel));
       break;
+    case PROP_CURRENT_RGBA:
+      {
+        GdkRGBA rgba;
+
+        gtk_color_selection_get_current_rgba (colorsel, &rgba);
+        g_value_set_boxed (value, &rgba);
+      }
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
     }
 }
 
-/* GtkObject methods */
+/* GtkWidget methods */
 
 static void
-gtk_color_selection_destroy (GtkObject *object)
+gtk_color_selection_destroy (GtkWidget *widget)
 {
-  GtkColorSelection *cselection = GTK_COLOR_SELECTION (object);
+  GtkColorSelection *cselection = GTK_COLOR_SELECTION (widget);
   GtkColorSelectionPrivate *priv = cselection->private_data;
 
   if (priv->dropper_grab_widget)
@@ -619,11 +658,9 @@ gtk_color_selection_destroy (GtkObject *object)
       priv->dropper_grab_widget = NULL;
     }
 
-  GTK_OBJECT_CLASS (gtk_color_selection_parent_class)->destroy (object);
+  GTK_WIDGET_CLASS (gtk_color_selection_parent_class)->destroy (widget);
 }
 
-/* GtkWidget methods */
-
 static void
 gtk_color_selection_realize (GtkWidget *widget)
 {
@@ -677,7 +714,9 @@ gtk_color_selection_grab_broken (GtkWidget          *widget,
  *
  */
 
-static void color_sample_draw_sample (GtkColorSelection *colorsel, int which);
+static void color_sample_draw_sample (GtkColorSelection *colorsel,
+                                      int                which,
+                                      cairo_t *          cr);
 static void color_sample_update_samples (GtkColorSelection *colorsel);
 
 static void
@@ -768,6 +807,7 @@ color_sample_drop_handle (GtkWidget        *widget,
 {
   GtkColorSelection *colorsel = data;
   GtkColorSelectionPrivate *priv;
+  gint length;
   guint16 *vals;
   gdouble color[4];
   priv = colorsel->private_data;
@@ -778,21 +818,23 @@ color_sample_drop_handle (GtkWidget        *widget,
    * B
    * opacity
    */
-  
-  if (selection_data->length < 0)
+
+  length = gtk_selection_data_get_length (selection_data);
+
+  if (length < 0)
     return;
   
   /* We accept drops with the wrong format, since the KDE color
    * chooser incorrectly drops application/x-color with format 8.
    */
-  if (selection_data->length != 8)
+  if (length != 8)
     {
       g_warning ("Received invalid color data\n");
       return;
     }
-  
-  vals = (guint16 *)selection_data->data;
-  
+
+  vals = (guint16 *) gtk_selection_data_get_data (selection_data);
+
   if (widget == priv->cur_sample)
     {
       color[0] = (gdouble)vals[0] / 0xffff;
@@ -836,13 +878,14 @@ color_sample_drag_handle (GtkWidget        *widget,
 
 /* which = 0 means draw old sample, which = 1 means draw new */
 static void
-color_sample_draw_sample (GtkColorSelection *colorsel, int which)
+color_sample_draw_sample (GtkColorSelection *colorsel,
+                          int                which,
+                          cairo_t           *cr)
 {
-  GtkAllocation allocation;
   GtkWidget *da;
-  gint x, y, wid, heig, goff;
+  gint x, y, goff;
   GtkColorSelectionPrivate *priv;
-  cairo_t *cr;
+  int width, height;
   
   g_return_if_fail (colorsel != NULL);
   priv = colorsel->private_data;
@@ -865,25 +908,21 @@ color_sample_draw_sample (GtkColorSelection *colorsel, int which)
       goff =  old_sample_allocation.width % 32;
     }
 
-  cr = gdk_cairo_create (gtk_widget_get_window (da));
-
-  gtk_widget_get_allocation (da, &allocation);
-  wid = allocation.width;
-  heig = allocation.height;
-
   /* Below needs tweaking for non-power-of-two */  
+  width = gtk_widget_get_allocated_width (da);
+  height = gtk_widget_get_allocated_height (da);
   
   if (priv->has_opacity)
     {
       /* Draw checks in background */
 
       cairo_set_source_rgb (cr, 0.5, 0.5, 0.5);
-      cairo_rectangle (cr, 0, 0, wid, heig);
+      cairo_rectangle (cr, 0, 0, width, height);
       cairo_fill (cr);
 
       cairo_set_source_rgb (cr, 0.75, 0.75, 0.75);
-      for (x = goff & -CHECK_SIZE; x < goff + wid; x += CHECK_SIZE)
-       for (y = 0; y < heig; y += CHECK_SIZE)
+      for (x = goff & -CHECK_SIZE; x < goff + width; x += CHECK_SIZE)
+       for (y = 0; y < height; y += CHECK_SIZE)
          if ((x / CHECK_SIZE + y / CHECK_SIZE) % 2 == 0)
            cairo_rectangle (cr, x - goff, y, CHECK_SIZE, CHECK_SIZE);
       cairo_fill (cr);
@@ -908,10 +947,8 @@ color_sample_draw_sample (GtkColorSelection *colorsel, int which)
                               priv->color[COLORSEL_OPACITY] : 1.0);
     }
 
-  cairo_rectangle (cr, 0, 0, wid, heig);
+  cairo_rectangle (cr, 0, 0, width, height);
   cairo_fill (cr);
-
-  cairo_destroy (cr);
 }
 
 
@@ -924,21 +961,21 @@ color_sample_update_samples (GtkColorSelection *colorsel)
 }
 
 static gboolean
-color_old_sample_expose (GtkWidget         *da,
-                        GdkEventExpose    *event,
-                        GtkColorSelection *colorsel)
+color_old_sample_draw (GtkWidget         *da,
+                       cairo_t           *cr,
+                       GtkColorSelection *colorsel)
 {
-  color_sample_draw_sample (colorsel, 0);
+  color_sample_draw_sample (colorsel, 0, cr);
   return FALSE;
 }
 
 
 static gboolean
-color_cur_sample_expose (GtkWidget         *da,
-                        GdkEventExpose    *event,
-                        GtkColorSelection *colorsel)
+color_cur_sample_draw (GtkWidget         *da,
+                       cairo_t           *cr,
+                       GtkColorSelection *colorsel)
 {
-  color_sample_draw_sample (colorsel, 1);
+  color_sample_draw_sample (colorsel, 1, cr);
   return FALSE;
 }
 
@@ -1015,7 +1052,7 @@ color_sample_new (GtkColorSelection *colorsel)
   
   priv = colorsel->private_data;
   
-  priv->sample_area = gtk_hbox_new (FALSE, 0);
+  priv->sample_area = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
   priv->old_sample = gtk_drawing_area_new ();
   priv->cur_sample = gtk_drawing_area_new ();
 
@@ -1024,11 +1061,11 @@ color_sample_new (GtkColorSelection *colorsel)
   gtk_box_pack_start (GTK_BOX (priv->sample_area), priv->cur_sample,
                      TRUE, TRUE, 0);
   
-  g_signal_connect (priv->old_sample, "expose-event",
-                   G_CALLBACK (color_old_sample_expose),
+  g_signal_connect (priv->old_sample, "draw",
+                   G_CALLBACK (color_old_sample_draw),
                    colorsel);
-  g_signal_connect (priv->cur_sample, "expose-event",
-                   G_CALLBACK (color_cur_sample_expose),
+  g_signal_connect (priv->cur_sample, "draw",
+                   G_CALLBACK (color_cur_sample_draw),
                    colorsel);
   
   color_sample_setup_dnd (colorsel, priv->old_sample);
@@ -1070,41 +1107,28 @@ palette_get_color (GtkWidget *drawing_area, gdouble *color)
   color[3] = 1.0;
 }
 
-static void
-palette_paint (GtkWidget    *drawing_area,
-              GdkRectangle *area,
-              gpointer      data)
+static gboolean
+palette_draw (GtkWidget *drawing_area,
+               cairo_t   *cr,
+              gpointer   data)
 {
-  GdkWindow *window;
-  cairo_t *cr;
   gint focus_width;
 
-  window = gtk_widget_get_window (drawing_area);
-
-  if (window == NULL)
-    return;
-
-  cr = gdk_cairo_create (window);
-
   gdk_cairo_set_source_color (cr, &gtk_widget_get_style (drawing_area)->bg[GTK_STATE_NORMAL]);
-  gdk_cairo_rectangle (cr, area);
-  cairo_fill (cr);
+  cairo_paint (cr);
   
   if (gtk_widget_has_focus (drawing_area))
     {
-      GtkAllocation allocation;
-
       set_focus_line_attributes (drawing_area, cr, &focus_width);
 
-      gtk_widget_get_allocation (drawing_area, &allocation);
       cairo_rectangle (cr,
                        focus_width / 2., focus_width / 2.,
-                       allocation.width - focus_width,
-                       allocation.height - focus_width);
+                       gtk_widget_get_allocated_width (drawing_area) - focus_width,
+                       gtk_widget_get_allocated_height (drawing_area) - focus_width);
       cairo_stroke (cr);
     }
 
-  cairo_destroy (cr);
+  return FALSE;
 }
 
 static void
@@ -1210,13 +1234,13 @@ get_current_colors (GtkColorSelection *colorsel)
   gchar *palette;
 
   settings = gtk_widget_get_settings (GTK_WIDGET (colorsel));
-  g_object_get (settings,
-               "gtk-color-palette", &palette,
-               NULL);
+  g_object_get (settings, "gtk-color-palette", &palette, NULL);
   
   if (!gtk_color_selection_palette_from_string (palette, &colors, &n_colors))
     {
-      gtk_color_selection_palette_from_string (default_colors, &colors, &n_colors);
+      gtk_color_selection_palette_from_string (DEFAULT_COLOR_PALETTE,
+                                               &colors,
+                                               &n_colors);
     }
   else
     {
@@ -1228,14 +1252,17 @@ get_current_colors (GtkColorSelection *colorsel)
          GdkColor *tmp_colors = colors;
          gint tmp_n_colors = n_colors;
          
-         gtk_color_selection_palette_from_string (default_colors, &colors, &n_colors);
+         gtk_color_selection_palette_from_string (DEFAULT_COLOR_PALETTE,
+                                                   &colors,
+                                                   &n_colors);
          memcpy (colors, tmp_colors, sizeof (GdkColor) * tmp_n_colors);
 
          g_free (tmp_colors);
        }
     }
 
-  g_assert (n_colors >= GTK_CUSTOM_PALETTE_WIDTH * GTK_CUSTOM_PALETTE_HEIGHT);
+  /* make sure that we fill every slot */
+  g_assert (n_colors == GTK_CUSTOM_PALETTE_WIDTH * GTK_CUSTOM_PALETTE_HEIGHT);
   g_free (palette);
   
   return colors;
@@ -1348,19 +1375,6 @@ palette_set_color (GtkWidget         *drawing_area,
   g_object_set_data_full (G_OBJECT (drawing_area), I_("color_val"), new_color, (GDestroyNotify)g_free);
 }
 
-static gboolean
-palette_expose (GtkWidget      *drawing_area,
-               GdkEventExpose *event,
-               gpointer        data)
-{
-  if (gtk_widget_get_window (drawing_area) == NULL)
-    return FALSE;
-  
-  palette_paint (drawing_area, &(event->area), data);
-  
-  return FALSE;
-}
-
 static void
 popup_position_func (GtkMenu   *menu,
                      gint      *x,
@@ -1381,8 +1395,8 @@ popup_position_func (GtkMenu   *menu,
   gdk_window_get_origin (gtk_widget_get_window (widget),
                          &root_x, &root_y);
 
-  gtk_size_request_get_size (GTK_SIZE_REQUEST (menu),
-                             &req, NULL);
+  gtk_widget_get_preferred_size (GTK_WIDGET (menu),
+                                 &req, NULL);
   gtk_widget_get_allocation (widget, &allocation);
 
   /* Put corner of menu centered on color cell */
@@ -1521,23 +1535,26 @@ palette_drop_handle (GtkWidget        *widget,
                     gpointer          data)
 {
   GtkColorSelection *colorsel = GTK_COLOR_SELECTION (data);
+  gint length;
   guint16 *vals;
   gdouble color[4];
-  
-  if (selection_data->length < 0)
+
+  length = gtk_selection_data_get_length (selection_data);
+
+  if (length < 0)
     return;
   
   /* We accept drops with the wrong format, since the KDE color
    * chooser incorrectly drops application/x-color with format 8.
    */
-  if (selection_data->length != 8)
+  if (length != 8)
     {
       g_warning ("Received invalid color data\n");
       return;
     }
-  
-  vals = (guint16 *)selection_data->data;
-  
+
+  vals = (guint16 *) gtk_selection_data_get_data (selection_data);
+
   color[0] = (gdouble)vals[0] / 0xffff;
   color[1] = (gdouble)vals[1] / 0xffff;
   color[2] = (gdouble)vals[2] / 0xffff;
@@ -1604,8 +1621,8 @@ palette_new (GtkColorSelection *colorsel)
                          | GDK_ENTER_NOTIFY_MASK
                          | GDK_LEAVE_NOTIFY_MASK);
   
-  g_signal_connect (retval, "expose-event",
-                   G_CALLBACK (palette_expose), colorsel);
+  g_signal_connect (retval, "draw",
+                   G_CALLBACK (palette_draw), colorsel);
   g_signal_connect (retval, "button-press-event",
                    G_CALLBACK (palette_press), colorsel);
   g_signal_connect (retval, "button-release-event",
@@ -1687,10 +1704,9 @@ grab_color_at_pointer (GdkScreen *screen,
   
   priv = colorsel->private_data;
   
-  pixbuf = gdk_pixbuf_get_from_drawable (NULL, root_window, NULL,
-                                         x_root, y_root,
-                                         0, 0,
-                                         1, 1);
+  pixbuf = gdk_pixbuf_get_from_window (root_window,
+                                       x_root, y_root,
+                                       1, 1);
   if (!pixbuf)
     {
       gint x, y;
@@ -1698,10 +1714,9 @@ grab_color_at_pointer (GdkScreen *screen,
       GdkWindow *window = gdk_display_get_window_at_device_position (display, device, &x, &y);
       if (!window)
        return;
-      pixbuf = gdk_pixbuf_get_from_drawable (NULL, window, NULL,
-                                             x, y,
-                                             0, 0,
-                                             1, 1);
+      pixbuf = gdk_pixbuf_get_from_window (window,
+                                           x, y,
+                                           1, 1);
       if (!pixbuf)
        return;
     }
@@ -1902,7 +1917,7 @@ get_screen_color (GtkWidget *button)
 
   device = gtk_get_current_event_device ();
 
-  if (device->source == GDK_SOURCE_KEYBOARD)
+  if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
     {
       keyb_device = device;
       pointer_device = gdk_device_get_associated_device (device);
@@ -2136,16 +2151,16 @@ make_label_spinbutton (GtkColorSelection *colorsel,
 
   if (channel_type == COLORSEL_HUE)
     {
-      adjust = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 360.0, 1.0, 1.0, 0.0));
+      adjust = gtk_adjustment_new (0.0, 0.0, 360.0, 1.0, 1.0, 0.0);
     }
   else if (channel_type == COLORSEL_SATURATION ||
           channel_type == COLORSEL_VALUE)
     {
-      adjust = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 100.0, 1.0, 1.0, 0.0));
+      adjust = gtk_adjustment_new (0.0, 0.0, 100.0, 1.0, 1.0, 0.0);
     }
   else
     {
-      adjust = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 255.0, 1.0, 1.0, 0.0));
+      adjust = gtk_adjustment_new (0.0, 0.0, 255.0, 1.0, 1.0, 0.0);
     }
   g_object_set_data (G_OBJECT (adjust), I_("COLORSEL"), colorsel);
   *spinbutton = gtk_spin_button_new (adjust, 10.0, 0);
@@ -2671,6 +2686,142 @@ gtk_color_selection_get_previous_alpha (GtkColorSelection *colorsel)
   return priv->has_opacity ? UNSCALE (priv->old_color[COLORSEL_OPACITY]) : 65535;
 }
 
+/**
+ * gtk_color_selection_set_current_rgba:
+ * @colorsel: a #GtkColorSelection.
+ * @rgba: A #GdkRGBA to set the current color with
+ *
+ * Sets the current color to be @rgba.  The first time this is called, it will
+ * also set the original color to be @rgba too.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_color_selection_set_current_rgba (GtkColorSelection *colorsel,
+                                      const GdkRGBA     *rgba)
+{
+  GtkColorSelectionPrivate *priv;
+  gint i;
+
+  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
+  g_return_if_fail (rgba != NULL);
+
+  priv = colorsel->private_data;
+  priv->changing = TRUE;
+
+  priv->color[COLORSEL_RED] = CLAMP (rgba->red, 0, 1);
+  priv->color[COLORSEL_GREEN] = CLAMP (rgba->green, 0, 1);
+  priv->color[COLORSEL_BLUE] = CLAMP (rgba->blue, 0, 1);
+  priv->color[COLORSEL_OPACITY] = CLAMP (rgba->alpha, 0, 1);
+
+  gtk_rgb_to_hsv (priv->color[COLORSEL_RED],
+                 priv->color[COLORSEL_GREEN],
+                 priv->color[COLORSEL_BLUE],
+                 &priv->color[COLORSEL_HUE],
+                 &priv->color[COLORSEL_SATURATION],
+                 &priv->color[COLORSEL_VALUE]);
+
+  if (priv->default_set == FALSE)
+    {
+      for (i = 0; i < COLORSEL_NUM_CHANNELS; i++)
+       priv->old_color[i] = priv->color[i];
+    }
+
+  priv->default_set = TRUE;
+  update_color (colorsel);
+}
+
+/**
+ * gtk_color_selection_get_current_rgba:
+ * @colorsel: a #GtkColorSelection.
+ * @rgba: (out): a #GdkRGBA to fill in with the current color.
+ *
+ * Sets @rgba to be the current color in the GtkColorSelection widget.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_color_selection_get_current_rgba (GtkColorSelection *colorsel,
+                                      GdkRGBA           *rgba)
+{
+  GtkColorSelectionPrivate *priv;
+
+  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
+  g_return_if_fail (rgba != NULL);
+
+  priv = colorsel->private_data;
+  rgba->red = priv->color[COLORSEL_RED];
+  rgba->green = priv->color[COLORSEL_GREEN];
+  rgba->blue = priv->color[COLORSEL_BLUE];
+  rgba->alpha = (priv->has_opacity) ? priv->color[COLORSEL_OPACITY] : 1;
+}
+
+/**
+ * gtk_color_selection_set_previous_rgba:
+ * @colorsel: a #GtkColorSelection.
+ * @rgba: a #GdkRGBA to set the previous color with
+ *
+ * Sets the 'previous' color to be @rgba.  This function should be called with
+ * some hesitations, as it might seem confusing to have that color change.
+ * Calling gtk_color_selection_set_current_rgba() will also set this color the first
+ * time it is called.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_color_selection_set_previous_rgba (GtkColorSelection *colorsel,
+                                       const GdkRGBA     *rgba)
+{
+  GtkColorSelectionPrivate *priv;
+
+  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
+  g_return_if_fail (rgba != NULL);
+
+  priv = colorsel->private_data;
+  priv->changing = TRUE;
+
+  priv->old_color[COLORSEL_RED] = CLAMP (rgba->red, 0, 1);
+  priv->old_color[COLORSEL_GREEN] = CLAMP (rgba->green, 0, 1);
+  priv->old_color[COLORSEL_BLUE] = CLAMP (rgba->blue, 0, 1);
+  priv->old_color[COLORSEL_OPACITY] = CLAMP (rgba->alpha, 0, 1);
+
+  gtk_rgb_to_hsv (priv->old_color[COLORSEL_RED],
+                 priv->old_color[COLORSEL_GREEN],
+                 priv->old_color[COLORSEL_BLUE],
+                 &priv->old_color[COLORSEL_HUE],
+                 &priv->old_color[COLORSEL_SATURATION],
+                 &priv->old_color[COLORSEL_VALUE]);
+
+  color_sample_update_samples (colorsel);
+  priv->default_set = TRUE;
+  priv->changing = FALSE;
+}
+
+/**
+ * gtk_color_selection_get_previous_rgba:
+ * @colorsel: a #GtkColorSelection.
+ * @rgba: a #GdkRGBA to fill in with the original color value.
+ *
+ * Fills @rgba in with the original color value.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_color_selection_get_previous_rgba (GtkColorSelection *colorsel,
+                                       GdkRGBA           *rgba)
+{
+  GtkColorSelectionPrivate *priv;
+
+  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
+  g_return_if_fail (rgba != NULL);
+
+  priv = colorsel->private_data;
+  rgba->red = priv->old_color[COLORSEL_RED];
+  rgba->green = priv->old_color[COLORSEL_GREEN];
+  rgba->blue = priv->old_color[COLORSEL_BLUE];
+  rgba->alpha = (priv->has_opacity) ? priv->old_color[COLORSEL_OPACITY] : 1;
+}
+
 /**
  * gtk_color_selection_set_palette_color:
  * @colorsel: a #GtkColorSelection.