]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkcolorbutton.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / gtk / gtkcolorbutton.c
index da33b980f02639d88c9f0c9a333f2bf6e794c491..52c1ec52516f12f5dc1f973394ccd630c7ebb355 100644 (file)
@@ -14,9 +14,7 @@
  * Library General Public License for more details.
  *
  * You should have received a copy of the GNU Library General Public
- * License along with the Gnome Library; see the file COPYING.LIB.  If not,
- * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 /* Color picker button for GNOME
  *
  * Modified by the GTK+ Team and others 2003.  See the AUTHORS
  * file for a list of people on the GTK+ Team.  See the ChangeLog
  * files for a list of changes.  These files are distributed with
- * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
  */
 
-#include <config.h>
+#define GDK_DISABLE_DEPRECATION_WARNINGS
+#include "config.h"
 
 #include "gtkcolorbutton.h"
-#include "gdk/gdkkeysyms.h"
-#include "gdk-pixbuf/gdk-pixbuf.h"
+
 #include "gtkbutton.h"
 #include "gtkmain.h"
-#include "gtkalignment.h"
-#include "gtkcolorsel.h"
-#include "gtkcolorseldialog.h"
+#include "gtkcolorchooser.h"
+#include "gtkcolorchooserprivate.h"
+#include "gtkcolorchooserdialog.h"
 #include "gtkdnd.h"
 #include "gtkdrawingarea.h"
-#include "gtkframe.h"
-#include "gtksignal.h"
 #include "gtkmarshalers.h"
 #include "gtkprivate.h"
 #include "gtkintl.h"
-#include "gtkalias.h"
+
+
+/**
+ * SECTION:gtkcolorbutton
+ * @Short_description: A button to launch a color selection dialog
+ * @Title: GtkColorButton
+ * @See_also: #GtkColorSelectionDialog, #GtkFontButton
+ *
+ * The #GtkColorButton is a button which displays the currently selected
+ * color an allows to open a color selection dialog to change the color.
+ * It is suitable widget for selecting a color in a preference dialog.
+ */
+
 
 /* Size of checks and gray levels for alpha compositing checkerboard */
 #define CHECK_SIZE  4
-#define CHECK_DARK  21845  /* 65535 / 3     */
-#define CHECK_LIGHT 43690 
-
-#define GTK_COLOR_BUTTON_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_COLOR_BUTTON, GtkColorButtonPrivate))
+#define CHECK_DARK  (1.0 / 3.0)
+#define CHECK_LIGHT (2.0 / 3.0)
 
-struct _GtkColorButtonPrivate 
+struct _GtkColorButtonPrivate
 {
-  GdkPixbuf *pixbuf;    /* Pixbuf for rendering sample */
-  GdkGC *gc;            /* GC for drawing */
-  
   GtkWidget *draw_area; /* Widget where we draw the color sample */
   GtkWidget *cs_dialog; /* Color selection dialog */
-  
+
   gchar *title;         /* Title for the color selection window */
-  
-  GdkColor color;
-  guint16 alpha;
-  
+  GdkRGBA rgba;
+
   guint use_alpha : 1;  /* Use alpha or not */
 };
 
 /* Properties */
-enum 
+enum
 {
   PROP_0,
   PROP_USE_ALPHA,
   PROP_TITLE,
   PROP_COLOR,
-  PROP_ALPHA
+  PROP_ALPHA,
+  PROP_RGBA
 };
 
 /* Signals */
-enum 
+enum
 {
   COLOR_SET,
   LAST_SIGNAL
 };
 
-static void gtk_color_button_class_init    (GtkColorButtonClass *klass);
-static void gtk_color_button_init          (GtkColorButton      *color_button);
-
 /* gobject signals */
 static void gtk_color_button_finalize      (GObject             *object);
 static void gtk_color_button_set_property  (GObject        *object,
-                                           guint           param_id,
-                                           const GValue   *value,
-                                           GParamSpec     *pspec);
+                                            guint           param_id,
+                                            const GValue   *value,
+                                            GParamSpec     *pspec);
 static void gtk_color_button_get_property  (GObject        *object,
-                                           guint           param_id,
-                                           GValue         *value,
-                                           GParamSpec     *pspec);
+                                            guint           param_id,
+                                            GValue         *value,
+                                            GParamSpec     *pspec);
 
 /* gtkwidget signals */
-static void gtk_color_button_realize       (GtkWidget *widget);
-static void gtk_color_button_unrealize     (GtkWidget *widget);
-static void gtk_color_button_state_changed (GtkWidget           *widget, 
-                                           GtkStateType         previous_state);
-static void gtk_color_button_style_set     (GtkWidget *widget, 
-                                           GtkStyle  *previous_style);
+static void gtk_color_button_state_changed (GtkWidget           *widget,
+                                            GtkStateType         previous_state);
 
 /* gtkbutton signals */
 static void gtk_color_button_clicked       (GtkButton           *button);
 
 /* source side drag signals */
 static void gtk_color_button_drag_begin (GtkWidget        *widget,
-                                        GdkDragContext   *context,
-                                        gpointer          data);
+                                         GdkDragContext   *context,
+                                         gpointer          data);
 static void gtk_color_button_drag_data_get (GtkWidget        *widget,
                                             GdkDragContext   *context,
                                             GtkSelectionData *selection_data,
                                             guint             info,
                                             guint             time,
-                                            GtkColorButton   *color_button);
+                                            GtkColorButton   *button);
 
 /* target side drag signals */
 static void gtk_color_button_drag_data_received (GtkWidget        *widget,
-                                                GdkDragContext   *context,
-                                                gint              x,
-                                                gint              y,
-                                                GtkSelectionData *selection_data,
-                                                guint             info,
-                                                guint32           time,
-                                                GtkColorButton   *color_button);
+                                                 GdkDragContext   *context,
+                                                 gint              x,
+                                                 gint              y,
+                                                 GtkSelectionData *selection_data,
+                                                 guint             info,
+                                                 guint32           time,
+                                                 GtkColorButton   *button);
 
 
-static gpointer parent_class = NULL;
 static guint color_button_signals[LAST_SIGNAL] = { 0 };
 
 static const GtkTargetEntry drop_types[] = { { "application/x-color", 0, 0 } };
 
-GType
-gtk_color_button_get_type (void)
-{
-  static GType color_button_type = 0;
-  
-  if (!color_button_type)
-    {
-      static const GTypeInfo color_button_info =
-      {
-        sizeof (GtkColorButtonClass),
-        NULL,           /* base_init */
-        NULL,           /* base_finalize */
-        (GClassInitFunc) gtk_color_button_class_init,
-        NULL,           /* class_finalize */
-        NULL,           /* class_data */
-        sizeof (GtkColorButton),
-        0,              /* n_preallocs */
-        (GInstanceInitFunc) gtk_color_button_init,
-      };
-      
-      color_button_type =
-        g_type_register_static (GTK_TYPE_BUTTON, I_("GtkColorButton"),
-                                &color_button_info, 0);
-    }
-  
-  return color_button_type;
-}
+static void gtk_color_button_iface_init (GtkColorChooserInterface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (GtkColorButton, gtk_color_button, GTK_TYPE_BUTTON,
+                         G_IMPLEMENT_INTERFACE (GTK_TYPE_COLOR_CHOOSER,
+                                                gtk_color_button_iface_init))
 
 static void
 gtk_color_button_class_init (GtkColorButtonClass *klass)
@@ -178,31 +150,26 @@ gtk_color_button_class_init (GtkColorButtonClass *klass)
   widget_class = GTK_WIDGET_CLASS (klass);
   button_class = GTK_BUTTON_CLASS (klass);
 
-  parent_class = g_type_class_peek_parent (klass);
-
   gobject_class->get_property = gtk_color_button_get_property;
   gobject_class->set_property = gtk_color_button_set_property;
   gobject_class->finalize = gtk_color_button_finalize;
   widget_class->state_changed = gtk_color_button_state_changed;
-  widget_class->realize = gtk_color_button_realize;
-  widget_class->unrealize = gtk_color_button_unrealize;
-  widget_class->style_set = gtk_color_button_style_set;
   button_class->clicked = gtk_color_button_clicked;
   klass->color_set = NULL;
 
   /**
    * GtkColorButton:use-alpha:
    *
-   * If this property is set to %TRUE, the color swatch on the button is rendered against a 
-   * checkerboard background to show its opacity and the opacity slider is displayed in the 
-   * color selection dialog. 
+   * If this property is set to %TRUE, the color swatch on the button is
+   * rendered against a checkerboard background to show its opacity and
+   * the opacity slider is displayed in the color selection dialog.
    *
    * Since: 2.4
    */
   g_object_class_install_property (gobject_class,
                                    PROP_USE_ALPHA,
-                                   g_param_spec_boolean ("use-alpha", P_("Use alpha"), 
-                                                         P_("Whether or not to give the color an alpha value"),
+                                   g_param_spec_boolean ("use-alpha", P_("Use alpha"),
+                                                         P_("Whether to give the color an alpha value"),
                                                          FALSE,
                                                          GTK_PARAM_READWRITE));
 
@@ -215,8 +182,8 @@ gtk_color_button_class_init (GtkColorButtonClass *klass)
    */
   g_object_class_install_property (gobject_class,
                                    PROP_TITLE,
-                                   g_param_spec_string ("title", 
-                                                       P_("Title"), 
+                                   g_param_spec_string ("title",
+                                                        P_("Title"),
                                                         P_("The title of the color selection dialog"),
                                                         _("Pick a Color"),
                                                         GTK_PARAM_READWRITE));
@@ -227,6 +194,8 @@ gtk_color_button_class_init (GtkColorButtonClass *klass)
    * The selected color.
    *
    * Since: 2.4
+   *
+   * Deprecated: 3.4: Use #GtkColorButton:rgba instead.
    */
   g_object_class_install_property (gobject_class,
                                    PROP_COLOR,
@@ -234,12 +203,12 @@ gtk_color_button_class_init (GtkColorButtonClass *klass)
                                                        P_("Current Color"),
                                                        P_("The selected color"),
                                                        GDK_TYPE_COLOR,
-                                                       GTK_PARAM_READWRITE));
+                                                       GTK_PARAM_READWRITE | G_PARAM_DEPRECATED));
 
   /**
    * GtkColorButton:alpha:
    *
-   * The selected opacity value (0 fully transparent, 65535 fully opaque). 
+   * The selected opacity value (0 fully transparent, 65535 fully opaque).
    *
    * Since: 2.4
    */
@@ -250,373 +219,257 @@ gtk_color_button_class_init (GtkColorButtonClass *klass)
                                                       P_("The selected opacity value (0 fully transparent, 65535 fully opaque)"),
                                                       0, 65535, 65535,
                                                       GTK_PARAM_READWRITE));
-        
+
+  /**
+   * GtkColorButton:rgba:
+   *
+   * The RGBA color.
+   *
+   * Since: 3.0
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_RGBA,
+                                   g_param_spec_boxed ("rgba",
+                                                       P_("Current RGBA Color"),
+                                                       P_("The selected RGBA color"),
+                                                       GDK_TYPE_RGBA,
+                                                       GTK_PARAM_READWRITE));
+
+
   /**
    * GtkColorButton::color-set:
    * @widget: the object which received the signal.
-   * 
-   * The ::color-set signal is emitted when the user selects a color. When handling this signal,
-   * use gtk_color_button_get_color() and gtk_color_button_get_alpha() to find out which color 
-   * was just selected.
+   *
+   * The ::color-set signal is emitted when the user selects a color.
+   * When handling this signal, use gtk_color_button_get_rgba() to
+   * find out which color was just selected.
+   *
+   * Note that this signal is only emitted when the <emphasis>user</emphasis>
+   * changes the color. If you need to react to programmatic color changes
+   * as well, use the notify::color signal.
    *
    * Since: 2.4
    */
-  color_button_signals[COLOR_SET] = g_signal_new (I_("color_set"),
-                                                 G_TYPE_FROM_CLASS (gobject_class),
-                                                 G_SIGNAL_RUN_FIRST,
-                                                 G_STRUCT_OFFSET (GtkColorButtonClass, color_set),
-                                                 NULL, NULL,
-                                                 _gtk_marshal_VOID__VOID,
-                                                 G_TYPE_NONE, 0);
+  color_button_signals[COLOR_SET] = g_signal_new (I_("color-set"),
+                                                  G_TYPE_FROM_CLASS (gobject_class),
+                                                  G_SIGNAL_RUN_FIRST,
+                                                  G_STRUCT_OFFSET (GtkColorButtonClass, color_set),
+                                                  NULL, NULL,
+                                                  _gtk_marshal_VOID__VOID,
+                                                  G_TYPE_NONE, 0);
 
   g_type_class_add_private (gobject_class, sizeof (GtkColorButtonPrivate));
 }
 
-static void
-render (GtkColorButton *color_button)
+static gboolean
+gtk_color_button_has_alpha (GtkColorButton *button)
 {
-  gint dark_r, dark_g, dark_b;
-  gint light_r, light_g, light_b;
-  gint i, j, rowstride;
-  gint width, height;
-  gint c1[3], c2[3];
-  guchar *pixels;
-  guint8 insensitive_r = 0;
-  guint8 insensitive_g = 0;
-  guint8 insensitive_b = 0;
-
-  width = color_button->priv->draw_area->allocation.width;
-  height = color_button->priv->draw_area->allocation.height;
-  if (color_button->priv->pixbuf == NULL || 
-      gdk_pixbuf_get_width (color_button->priv->pixbuf) != width ||
-      gdk_pixbuf_get_height (color_button->priv->pixbuf) != height) 
-    {
-      if (color_button->priv->pixbuf != NULL)
-       g_object_unref (color_button->priv->pixbuf);
-      color_button->priv->pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, width, height);
-    }
-  
-
-  /* Compute dark and light check colors */
-
-  insensitive_r = GTK_WIDGET(color_button)->style->bg[GTK_STATE_INSENSITIVE].red >> 8;
-  insensitive_g = GTK_WIDGET(color_button)->style->bg[GTK_STATE_INSENSITIVE].green >> 8;
-  insensitive_b = GTK_WIDGET(color_button)->style->bg[GTK_STATE_INSENSITIVE].blue >> 8;
-
-  if (color_button->priv->use_alpha) 
-    {
-      dark_r = ((CHECK_DARK << 16) + (color_button->priv->color.red - CHECK_DARK) * color_button->priv->alpha) >> 24;
-      dark_g = ((CHECK_DARK << 16) + (color_button->priv->color.green - CHECK_DARK) * color_button->priv->alpha) >> 24;
-      dark_b = ((CHECK_DARK << 16) + (color_button->priv->color.blue - CHECK_DARK) * color_button->priv->alpha) >> 24;
-      
-      light_r = ((CHECK_LIGHT << 16) + (color_button->priv->color.red - CHECK_LIGHT) * color_button->priv->alpha) >> 24;
-      light_g = ((CHECK_LIGHT << 16) + (color_button->priv->color.green - CHECK_LIGHT) * color_button->priv->alpha) >> 24;
-      light_b = ((CHECK_LIGHT << 16) + (color_button->priv->color.blue - CHECK_LIGHT) * color_button->priv->alpha) >> 24;
-    } 
-  else 
-    {
-      dark_r = light_r = color_button->priv->color.red >> 8;
-      dark_g = light_g = color_button->priv->color.green >> 8;
-      dark_b = light_b = color_button->priv->color.blue >> 8;
-    }
-
-  /* Fill image buffer */
-  pixels = gdk_pixbuf_get_pixels (color_button->priv->pixbuf);
-  rowstride = gdk_pixbuf_get_rowstride (color_button->priv->pixbuf);
-  for (j = 0; j < height; j++) 
-    {
-      if ((j / CHECK_SIZE) & 1) 
-        {
-          c1[0] = dark_r;
-          c1[1] = dark_g;
-          c1[2] = dark_b;
-          
-          c2[0] = light_r;
-          c2[1] = light_g;
-          c2[2] = light_b;
-        } 
-      else 
-        {
-          c1[0] = light_r;
-          c1[1] = light_g;
-          c1[2] = light_b;
-          
-          c2[0] = dark_r;
-          c2[1] = dark_g;
-          c2[2] = dark_b;
-        }
-      
-    for (i = 0; i < width; i++) 
-      {
-        if (!GTK_WIDGET_SENSITIVE (GTK_WIDGET (color_button)) && (i+j)%2) 
-          {
-            *(pixels + j * rowstride + i * 3) = insensitive_r;
-            *(pixels + j * rowstride + i * 3 + 1) = insensitive_g;
-            *(pixels + j * rowstride + i * 3 + 2) = insensitive_b;
-          } 
-        else if ((i / CHECK_SIZE) & 1) 
-          {
-            *(pixels + j * rowstride + i * 3)     = c1[0];
-            *(pixels + j * rowstride + i * 3 + 1) = c1[1];
-            *(pixels + j * rowstride + i * 3 + 2) = c1[2];
-          }
-        else
-          {
-            *(pixels + j * rowstride + i * 3)     = c2[0];
-            *(pixels + j * rowstride + i * 3 + 1) = c2[1];
-            *(pixels + j * rowstride + i * 3 + 2) = c2[2];
-          }
-      }
-    }
+  return button->priv->use_alpha && button->priv->rgba.alpha < 1;
 }
 
 /* Handle exposure events for the color picker's drawing area */
 static gint
-expose_event (GtkWidget      *widget, 
-              GdkEventExpose *event, 
-              gpointer        data)
+gtk_color_button_draw_cb (GtkWidget *widget,
+                          cairo_t   *cr,
+                          gpointer   data)
 {
-  GtkColorButton *color_button = GTK_COLOR_BUTTON (data);
-
-  gint width = color_button->priv->draw_area->allocation.width;
-  gint height = color_button->priv->draw_area->allocation.height;
-
-  if (color_button->priv->pixbuf == NULL ||
-      width != gdk_pixbuf_get_width (color_button->priv->pixbuf) ||
-      height != gdk_pixbuf_get_height (color_button->priv->pixbuf)) 
-    render (color_button);
-
-  gdk_draw_pixbuf (widget->window,
-                   color_button->priv->gc,
-                   color_button->priv->pixbuf,
-                   event->area.x - widget->allocation.x,
-                   event->area.y - widget->allocation.y,
-                   event->area.x,
-                   event->area.y,
-                   event->area.width,
-                   event->area.height,
-                   GDK_RGB_DITHER_MAX,
-                   event->area.x - widget->allocation.x,
-                   event->area.y - widget->allocation.y);
-  return FALSE;
-}
+  GtkColorButton *button = GTK_COLOR_BUTTON (data);
+  cairo_pattern_t *checkered;
 
-static void
-gtk_color_button_realize (GtkWidget *widget)
-{
-  GtkColorButton *color_button = GTK_COLOR_BUTTON (widget);
-
-  GTK_WIDGET_CLASS (parent_class)->realize (widget);
+  if (gtk_color_button_has_alpha (button))
+    {
+      cairo_set_source_rgb (cr, CHECK_DARK, CHECK_DARK, CHECK_DARK);
+      cairo_paint (cr);
 
-  color_button->priv->gc = gdk_gc_new (widget->window);
+      cairo_set_source_rgb (cr, CHECK_LIGHT, CHECK_LIGHT, CHECK_LIGHT);
+      cairo_scale (cr, CHECK_SIZE, CHECK_SIZE);
 
-  render (color_button);
-}
-
-static void
-gtk_color_button_unrealize (GtkWidget *widget)
-{
-  GtkColorButton *color_button = GTK_COLOR_BUTTON (widget);
+      checkered = _gtk_color_chooser_get_checkered_pattern ();
+      cairo_mask (cr, checkered);
+      cairo_pattern_destroy (checkered);
 
-  g_object_unref (color_button->priv->gc);
-  color_button->priv->gc = NULL;
+      gdk_cairo_set_source_rgba (cr, &button->priv->rgba);
+    }
+  else
+    {
+      cairo_set_source_rgb (cr,
+                            button->priv->rgba.red,
+                            button->priv->rgba.green,
+                            button->priv->rgba.blue);
+    }
 
-  GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
-}
+  cairo_paint (cr);
 
-static void
-gtk_color_button_style_set (GtkWidget *widget, 
-                           GtkStyle  *previous_style)
-{
-  GtkColorButton *color_button = GTK_COLOR_BUTTON (widget);
+  if (!gtk_widget_is_sensitive (GTK_WIDGET (button)))
+    {
+      GtkStyleContext *context;
+      GdkRGBA color;
 
-  GTK_WIDGET_CLASS (parent_class)->style_set (widget, previous_style);
+      context = gtk_widget_get_style_context (widget);
+      gtk_style_context_get_background_color (context, GTK_STATE_FLAG_INSENSITIVE, &color);
 
-  if (GTK_WIDGET_REALIZED (widget)) 
-    {
-      if (color_button->priv->pixbuf != NULL)
-       g_object_unref (color_button->priv->pixbuf);
-      color_button->priv->pixbuf = NULL;
+      gdk_cairo_set_source_rgba (cr, &color);
+      checkered = _gtk_color_chooser_get_checkered_pattern ();
+      cairo_mask (cr, checkered);
+      cairo_pattern_destroy (checkered);
     }
+
+  return FALSE;
 }
 
 static void
-gtk_color_button_state_changed (GtkWidget   *widget, 
-                                          GtkStateType previous_state)
+gtk_color_button_state_changed (GtkWidget   *widget,
+                                GtkStateType previous_state)
 {
-  GtkColorButton *color_button = GTK_COLOR_BUTTON (widget);
-
-  if (widget->state == GTK_STATE_INSENSITIVE || previous_state == GTK_STATE_INSENSITIVE)
-    {
-      if (color_button->priv->pixbuf != NULL)
-       g_object_unref (color_button->priv->pixbuf);
-      color_button->priv->pixbuf = NULL;
-    }
+  gtk_widget_queue_draw (widget);
 }
 
 static void
 gtk_color_button_drag_data_received (GtkWidget        *widget,
-                                    GdkDragContext   *context,
-                                    gint              x,
-                                    gint              y,
-                                    GtkSelectionData *selection_data,
-                                    guint             info,
-                                    guint32           time,
-                                    GtkColorButton   *color_button)
-{
+                                     GdkDragContext   *context,
+                                     gint              x,
+                                     gint              y,
+                                     GtkSelectionData *selection_data,
+                                     guint             info,
+                                     guint32           time,
+                                     GtkColorButton   *button)
+{
+  gint length;
   guint16 *dropped;
 
-  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"));
+      g_warning ("%s: Received invalid color data", G_STRFUNC);
       return;
     }
 
 
-  dropped = (guint16 *)selection_data->data;
-
-  color_button->priv->color.red = dropped[0];
-  color_button->priv->color.green = dropped[1];
-  color_button->priv->color.blue = dropped[2];
-  color_button->priv->alpha = dropped[3];
+  dropped = (guint16 *) gtk_selection_data_get_data (selection_data);
 
-  if (color_button->priv->pixbuf != NULL)
-    g_object_unref (color_button->priv->pixbuf);
-  color_button->priv->pixbuf = NULL;
+  button->priv->rgba.red = dropped[0] / 65535.;
+  button->priv->rgba.green = dropped[1] / 65535.;
+  button->priv->rgba.blue = dropped[2] / 65535.;
+  button->priv->rgba.alpha = dropped[3] / 65535.;
 
-  gtk_widget_queue_draw (color_button->priv->draw_area);
+  gtk_widget_queue_draw (button->priv->draw_area);
 
-  g_signal_emit (color_button, color_button_signals[COLOR_SET], 0);
+  g_signal_emit (button, color_button_signals[COLOR_SET], 0);
 
-  g_object_freeze_notify (G_OBJECT (color_button));
-  g_object_notify (G_OBJECT (color_button), "color");
-  g_object_notify (G_OBJECT (color_button), "alpha");
-  g_object_thaw_notify (G_OBJECT (color_button));
+  g_object_freeze_notify (G_OBJECT (button));
+  g_object_notify (G_OBJECT (button), "color");
+  g_object_notify (G_OBJECT (button), "alpha");
+  g_object_notify (G_OBJECT (button), "rgba");
+  g_object_thaw_notify (G_OBJECT (button));
 }
 
 static void
 set_color_icon (GdkDragContext *context,
-               GdkColor       *color)
+                GdkRGBA        *rgba)
 {
-  GdkPixbuf *pixbuf;
-  guint32 pixel;
+  cairo_surface_t *surface;
+  cairo_t *cr;
 
-  pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE,
-                          8, 48, 32);
+  surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
+                                        48, 32);
+  cr = cairo_create (surface);
 
-  pixel = ((color->red & 0xff00) << 16) | 
-          ((color->green & 0xff00) << 8) | 
-           (color->blue & 0xff00);
+  gdk_cairo_set_source_rgba (cr, rgba);
+  cairo_paint (cr);
 
-  gdk_pixbuf_fill (pixbuf, pixel);
-  
-  gtk_drag_set_icon_pixbuf (context, pixbuf, -2, -2);
-  g_object_unref (pixbuf);
+  gtk_drag_set_icon_surface (context, surface);
+
+  cairo_destroy (cr);
+  cairo_surface_destroy (surface);
 }
 
 static void
 gtk_color_button_drag_begin (GtkWidget      *widget,
-                            GdkDragContext *context,
-                            gpointer        data)
+                             GdkDragContext *context,
+                             gpointer        data)
 {
-  GtkColorButton *color_button = data;
-  
-  set_color_icon (context, &color_button->priv->color);
+  GtkColorButton *button = data;
+
+  set_color_icon (context, &button->priv->rgba);
 }
 
 static void
 gtk_color_button_drag_data_get (GtkWidget        *widget,
-                               GdkDragContext   *context,
-                               GtkSelectionData *selection_data,
-                               guint             info,
-                               guint             time,
-                               GtkColorButton   *color_button)
+                                GdkDragContext   *context,
+                                GtkSelectionData *selection_data,
+                                guint             info,
+                                guint             time,
+                                GtkColorButton   *button)
 {
   guint16 dropped[4];
 
-  dropped[0] = color_button->priv->color.red;
-  dropped[1] = color_button->priv->color.green;
-  dropped[2] = color_button->priv->color.blue;
-  dropped[3] = color_button->priv->alpha;
+  dropped[0] = (guint16) (button->priv->rgba.red * 65535);
+  dropped[1] = (guint16) (button->priv->rgba.green * 65535);
+  dropped[2] = (guint16) (button->priv->rgba.blue * 65535);
+  dropped[3] = (guint16) (button->priv->rgba.alpha * 65535);
 
-  gtk_selection_data_set (selection_data, selection_data->target,
-                         16, (guchar *)dropped, 8);
+  gtk_selection_data_set (selection_data,
+                          gtk_selection_data_get_target (selection_data),
+                          16, (guchar *)dropped, 8);
 }
 
 static void
-gtk_color_button_init (GtkColorButton *color_button)
+gtk_color_button_init (GtkColorButton *button)
 {
-  GtkWidget *alignment;
-  GtkWidget *frame;
   PangoLayout *layout;
   PangoRectangle rect;
 
   /* Create the widgets */
-  color_button->priv = GTK_COLOR_BUTTON_GET_PRIVATE (color_button);
+  button->priv = G_TYPE_INSTANCE_GET_PRIVATE (button,
+                                              GTK_TYPE_COLOR_BUTTON,
+                                              GtkColorButtonPrivate);
 
   gtk_widget_push_composite_child ();
 
-  alignment = gtk_alignment_new (0.5, 0.5, 0.5, 1.0);
-  gtk_container_set_border_width (GTK_CONTAINER (alignment), 1);
-  gtk_container_add (GTK_CONTAINER (color_button), alignment);
-  gtk_widget_show (alignment);
-
-  frame = gtk_frame_new (NULL);
-  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_OUT);
-  gtk_container_add (GTK_CONTAINER (alignment), frame);
-  gtk_widget_show (frame);
-
-  /* Just some widget we can hook to expose-event on */
-  color_button->priv->draw_area = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
-
-  layout = gtk_widget_create_pango_layout (GTK_WIDGET (color_button), "Black");
+  button->priv->draw_area = gtk_drawing_area_new ();
+  layout = gtk_widget_create_pango_layout (GTK_WIDGET (button), "Black");
   pango_layout_get_pixel_extents (layout, NULL, &rect);
   g_object_unref (layout);
 
-  gtk_widget_set_size_request (color_button->priv->draw_area, rect.width - 2, rect.height - 2);
-  g_signal_connect (color_button->priv->draw_area, "expose-event",
-                    G_CALLBACK (expose_event), color_button);
-  gtk_container_add (GTK_CONTAINER (frame), color_button->priv->draw_area);
-  gtk_widget_show (color_button->priv->draw_area);
+  gtk_widget_set_size_request (button->priv->draw_area, 
+                               rect.width, rect.height);
 
-  color_button->priv->title = g_strdup (_("Pick a Color")); /* default title */
+  g_signal_connect (button->priv->draw_area, "draw",
+                    G_CALLBACK (gtk_color_button_draw_cb), button);
+  gtk_container_add (GTK_CONTAINER (button), button->priv->draw_area);
+  gtk_widget_show (button->priv->draw_area);
 
-  /* Create the buffer for the image so that we can create an image.  
-   * Also create the picker's pixmap.
-   */
-  color_button->priv->pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, rect.width, rect.height);
-
-  color_button->priv->gc = NULL;
+  button->priv->title = g_strdup (_("Pick a Color")); /* default title */
 
   /* Start with opaque black, alpha disabled */
+  button->priv->rgba.red = 0;
+  button->priv->rgba.green = 0;
+  button->priv->rgba.blue = 0;
+  button->priv->rgba.alpha = 1;
+  button->priv->use_alpha = FALSE;
 
-  color_button->priv->color.red = 0;
-  color_button->priv->color.green = 0;
-  color_button->priv->color.blue = 0;
-  color_button->priv->alpha = 65535;
-  color_button->priv->use_alpha = FALSE;
-
-  gtk_drag_dest_set (GTK_WIDGET (color_button),
+  gtk_drag_dest_set (GTK_WIDGET (button),
                      GTK_DEST_DEFAULT_MOTION |
                      GTK_DEST_DEFAULT_HIGHLIGHT |
                      GTK_DEST_DEFAULT_DROP,
                      drop_types, 1, GDK_ACTION_COPY);
-  gtk_drag_source_set (GTK_WIDGET(color_button),
+  gtk_drag_source_set (GTK_WIDGET (button),
                        GDK_BUTTON1_MASK|GDK_BUTTON3_MASK,
                        drop_types, 1,
                        GDK_ACTION_COPY);
-  g_signal_connect (color_button, "drag_begin",
-                   G_CALLBACK (gtk_color_button_drag_begin), color_button);
-  g_signal_connect (color_button, "drag_data_received",
-                    G_CALLBACK (gtk_color_button_drag_data_received), color_button);
-  g_signal_connect (color_button, "drag_data_get",
-                    G_CALLBACK (gtk_color_button_drag_data_get), color_button);
+  g_signal_connect (button, "drag-begin",
+                    G_CALLBACK (gtk_color_button_drag_begin), button);
+  g_signal_connect (button, "drag-data-received",
+                    G_CALLBACK (gtk_color_button_drag_data_received), button);
+  g_signal_connect (button, "drag-data-get",
+                    G_CALLBACK (gtk_color_button_drag_data_get), button);
 
   gtk_widget_pop_composite_child ();
 }
@@ -624,33 +477,31 @@ gtk_color_button_init (GtkColorButton *color_button)
 static void
 gtk_color_button_finalize (GObject *object)
 {
-  GtkColorButton *color_button = GTK_COLOR_BUTTON (object);
+  GtkColorButton *button = GTK_COLOR_BUTTON (object);
 
-  if (color_button->priv->cs_dialog != NULL)
-    gtk_widget_destroy (color_button->priv->cs_dialog);
-  color_button->priv->cs_dialog = NULL;
+  if (button->priv->cs_dialog != NULL)
+    gtk_widget_destroy (button->priv->cs_dialog);
+  button->priv->cs_dialog = NULL;
 
-  if (color_button->priv->pixbuf != NULL)
-    g_object_unref (color_button->priv->pixbuf);
-  color_button->priv->pixbuf = NULL;
+  g_free (button->priv->title);
+  button->priv->title = NULL;
 
-  g_free (color_button->priv->title);
-  color_button->priv->title = NULL;
-
-  G_OBJECT_CLASS (parent_class)->finalize (object);
+  G_OBJECT_CLASS (gtk_color_button_parent_class)->finalize (object);
 }
 
 
 /**
  * gtk_color_button_new:
  *
- * Creates a new color button. This returns a widget in the form of
- * a small button containing a swatch representing the current selected 
- * color. When the button is clicked, a color-selection dialog will open, 
- * allowing the user to select a color. The swatch will be updated to reflect 
- * the new color when the user finishes.
+ * Creates a new color button.
+ *
+ * This returns a widget in the form of a small button containing
+ * a swatch representing the current selected color. When the button
+ * is clicked, a color-selection dialog will open, allowing the user
+ * to select a color. The swatch will be updated to reflect the new
+ * color when the user finishes.
  *
- * Returns: a new color button.
+ * Returns: a new color button
  *
  * Since: 2.4
  */
@@ -662,13 +513,15 @@ gtk_color_button_new (void)
 
 /**
  * gtk_color_button_new_with_color:
- * @color: A #GdkColor to set the current color with.
+ * @color: A #GdkColor to set the current color with
  *
- * Creates a new color button. 
+ * Creates a new color button.
  *
- * Returns: a new color button.
+ * Returns: a new color button
  *
  * Since: 2.4
+ *
+ * Deprecated: 3.4: Use gtk_color_button_new_with_rgba() instead.
  */
 GtkWidget *
 gtk_color_button_new_with_color (const GdkColor *color)
@@ -676,278 +529,331 @@ gtk_color_button_new_with_color (const GdkColor *color)
   return g_object_new (GTK_TYPE_COLOR_BUTTON, "color", color, NULL);
 }
 
-static void
-dialog_ok_clicked (GtkWidget *widget, 
-                  gpointer   data)
+/**
+ * gtk_color_button_new_with_rgba:
+ * @rgba: A #GdkRGBA to set the current color with
+ *
+ * Creates a new color button.
+ *
+ * Returns: a new color button
+ *
+ * Since: 3.0
+ */
+GtkWidget *
+gtk_color_button_new_with_rgba (const GdkRGBA *rgba)
 {
-  GtkColorButton *color_button = GTK_COLOR_BUTTON (data);
-  GtkColorSelection *color_selection;
+  return g_object_new (GTK_TYPE_COLOR_BUTTON, "rgba", rgba, NULL);
+}
 
-  color_selection = GTK_COLOR_SELECTION (GTK_COLOR_SELECTION_DIALOG (color_button->priv->cs_dialog)->colorsel);
+static gboolean
+dialog_destroy (GtkWidget *widget,
+                gpointer   data)
+{
+  GtkColorButton *button = GTK_COLOR_BUTTON (data);
 
-  gtk_color_selection_get_current_color (color_selection, &color_button->priv->color);
-  color_button->priv->alpha = gtk_color_selection_get_current_alpha (color_selection);
+  button->priv->cs_dialog = NULL;
 
-  if (color_button->priv->pixbuf != NULL)
-    g_object_unref (color_button->priv->pixbuf);
-  color_button->priv->pixbuf = NULL;
+  return FALSE;
+}
 
-  gtk_widget_hide (color_button->priv->cs_dialog);
+static void
+dialog_response (GtkDialog *dialog,
+                 gint       response,
+                 gpointer   data)
+{
+  if (response == GTK_RESPONSE_CANCEL)
+    gtk_widget_hide (GTK_WIDGET (dialog));
+  else if (response == GTK_RESPONSE_OK)
+    {
+      GtkColorButton *button = GTK_COLOR_BUTTON (data);
 
-  gtk_widget_queue_draw (color_button->priv->draw_area);
+      gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (dialog),
+                                  &button->priv->rgba);
 
-  g_signal_emit (color_button, color_button_signals[COLOR_SET], 0);
+      gtk_widget_hide (GTK_WIDGET (dialog));
 
-  g_object_freeze_notify (G_OBJECT (color_button));
-  g_object_notify (G_OBJECT (color_button), "color");
-  g_object_notify (G_OBJECT (color_button), "alpha");
-  g_object_thaw_notify (G_OBJECT (color_button));
-}
+      gtk_widget_queue_draw (button->priv->draw_area);
 
-static gboolean
-dialog_destroy (GtkWidget *widget, 
-               gpointer   data)
-{
-  GtkColorButton *color_button = GTK_COLOR_BUTTON (data);
-  
-  color_button->priv->cs_dialog = NULL;
+      g_signal_emit (button, color_button_signals[COLOR_SET], 0);
 
-  return FALSE;
+      g_object_freeze_notify (G_OBJECT (button));
+      g_object_notify (G_OBJECT (button), "color");
+      g_object_notify (G_OBJECT (button), "alpha");
+      g_object_notify (G_OBJECT (button), "rgba");
+      g_object_thaw_notify (G_OBJECT (button));
+    }
 }
 
+/* Create the dialog and connects its buttons */
 static void
-dialog_cancel_clicked (GtkWidget *widget,
-                      gpointer   data)
+ensure_dialog (GtkColorButton *button)
 {
-  GtkColorButton *color_button = GTK_COLOR_BUTTON (data);
-  
-  gtk_widget_hide (color_button->priv->cs_dialog);  
+  GtkWidget *parent, *dialog;
+
+  if (button->priv->cs_dialog != NULL)
+    return;
+
+  parent = gtk_widget_get_toplevel (GTK_WIDGET (button));
+
+  button->priv->cs_dialog = dialog = gtk_color_chooser_dialog_new (button->priv->title, NULL);
+
+  if (gtk_widget_is_toplevel (parent) && GTK_IS_WINDOW (parent))
+  {
+    if (GTK_WINDOW (parent) != gtk_window_get_transient_for (GTK_WINDOW (dialog)))
+      gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
+
+    gtk_window_set_modal (GTK_WINDOW (dialog),
+                            gtk_window_get_modal (GTK_WINDOW (parent)));
+  }
+
+  g_signal_connect (dialog, "response",
+                    G_CALLBACK (dialog_response), button);
+  g_signal_connect (dialog, "destroy",
+                    G_CALLBACK (dialog_destroy), button);
 }
 
+
 static void
-gtk_color_button_clicked (GtkButton *button)
+gtk_color_button_clicked (GtkButton *b)
 {
-  GtkColorButton *color_button = GTK_COLOR_BUTTON (button);
-  GtkColorSelectionDialog *color_dialog;
+  GtkColorButton *button = GTK_COLOR_BUTTON (b);
 
   /* if dialog already exists, make sure it's shown and raised */
-  if (!color_button->priv->cs_dialog) 
-    {
-      /* Create the dialog and connects its buttons */
-      GtkWidget *parent;
-      
-      parent = gtk_widget_get_toplevel (GTK_WIDGET (color_button));
-      
-      color_button->priv->cs_dialog = gtk_color_selection_dialog_new (color_button->priv->title);
-      
-      color_dialog = GTK_COLOR_SELECTION_DIALOG (color_button->priv->cs_dialog);
-
-      if (parent)
-        gtk_window_set_transient_for (GTK_WINDOW (color_dialog),
-                                      GTK_WINDOW (parent));
-      
-      g_signal_connect (color_dialog->ok_button, "clicked",
-                        G_CALLBACK (dialog_ok_clicked), color_button);
-      g_signal_connect (color_dialog->cancel_button, "clicked",
-                       G_CALLBACK (dialog_cancel_clicked), color_button);
-      g_signal_connect (color_dialog, "destroy",
-                        G_CALLBACK (dialog_destroy), color_button);
-      
-      /* If there is a grabbed window, set new dialog as modal */
-      if (gtk_grab_get_current ())
-        gtk_window_set_modal (GTK_WINDOW (color_button->priv->cs_dialog),TRUE);
-    }
+  ensure_dialog (button);
 
-  color_dialog = GTK_COLOR_SELECTION_DIALOG (color_button->priv->cs_dialog);
+  gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER (button->priv->cs_dialog),
+                                   button->priv->use_alpha);
 
-  gtk_color_selection_set_has_opacity_control (GTK_COLOR_SELECTION (color_dialog->colorsel),
-                                               color_button->priv->use_alpha);
-  
-  gtk_color_selection_set_previous_color (GTK_COLOR_SELECTION (color_dialog->colorsel), 
-                                         &color_button->priv->color);
-  gtk_color_selection_set_previous_alpha (GTK_COLOR_SELECTION (color_dialog->colorsel), 
-                                         color_button->priv->alpha);
+  gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (button->priv->cs_dialog),
+                              &button->priv->rgba);
 
-  gtk_color_selection_set_current_color (GTK_COLOR_SELECTION (color_dialog->colorsel), 
-                                        &color_button->priv->color);
-  gtk_color_selection_set_current_alpha (GTK_COLOR_SELECTION (color_dialog->colorsel), 
-                                        color_button->priv->alpha);
-
-  gtk_window_present (GTK_WINDOW (color_button->priv->cs_dialog));
+  gtk_window_present (GTK_WINDOW (button->priv->cs_dialog));
 }
 
 /**
  * gtk_color_button_set_color:
- * @color_button: a #GtkColorButton.
- * @color: A #GdkColor to set the current color with.
+ * @button: a #GtkColorButton
+ * @color: A #GdkColor to set the current color with
  *
  * Sets the current color to be @color.
  *
  * Since: 2.4
- **/
+ *
+ * Deprecated: Use gtk_color_chooser_set_rgba() instead.
+ */
 void
-gtk_color_button_set_color (GtkColorButton *color_button,
-                           const GdkColor *color)
+gtk_color_button_set_color (GtkColorButton *button,
+                            const GdkColor *color)
 {
-  g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button));
+  g_return_if_fail (GTK_IS_COLOR_BUTTON (button));
   g_return_if_fail (color != NULL);
 
-  color_button->priv->color.red = color->red;
-  color_button->priv->color.green = color->green;
-  color_button->priv->color.blue = color->blue;
+  button->priv->rgba.red = color->red / 65535.;
+  button->priv->rgba.green = color->green / 65535.;
+  button->priv->rgba.blue = color->blue / 65535.;
 
-  if (color_button->priv->pixbuf != NULL)
-    g_object_unref (color_button->priv->pixbuf);
-  color_button->priv->pixbuf = NULL;
+  gtk_widget_queue_draw (button->priv->draw_area);
 
-  gtk_widget_queue_draw (color_button->priv->draw_area);
-  
-  g_object_notify (G_OBJECT (color_button), "color");
+  g_object_notify (G_OBJECT (button), "color");
+  g_object_notify (G_OBJECT (button), "rgba");
 }
 
 
 /**
  * gtk_color_button_set_alpha:
- * @color_button: a #GtkColorButton.
- * @alpha: an integer between 0 and 65535.
+ * @button: a #GtkColorButton
+ * @alpha: an integer between 0 and 65535
  *
- * Sets the current opacity to be @alpha. 
+ * Sets the current opacity to be @alpha.
  *
  * Since: 2.4
- **/
+ *
+ * Deprecated: 3.4: Use gtk_color_chooser_set_rgba() instead.
+ */
 void
-gtk_color_button_set_alpha (GtkColorButton *color_button,
-                           guint16         alpha)
+gtk_color_button_set_alpha (GtkColorButton *button,
+                            guint16         alpha)
 {
-  g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button));
-
-  color_button->priv->alpha = alpha;
+  g_return_if_fail (GTK_IS_COLOR_BUTTON (button));
 
-  if (color_button->priv->pixbuf != NULL)
-    g_object_unref (color_button->priv->pixbuf);
-  color_button->priv->pixbuf = NULL;
+  button->priv->rgba.alpha = alpha / 65535.;
 
-  gtk_widget_queue_draw (color_button->priv->draw_area);
+  gtk_widget_queue_draw (button->priv->draw_area);
 
-  g_object_notify (G_OBJECT (color_button), "alpha");
+  g_object_notify (G_OBJECT (button), "alpha");
+  g_object_notify (G_OBJECT (button), "rgba");
 }
 
 /**
  * gtk_color_button_get_color:
- * @color_button: a #GtkColorButton.
- * @color: a #GdkColor to fill in with the current color.
+ * @button: a #GtkColorButton
+ * @color: (out): a #GdkColor to fill in with the current color
  *
  * Sets @color to be the current color in the #GtkColorButton widget.
  *
  * Since: 2.4
- **/
+ *
+ * Deprecated: 3.4: Use gtk_color_chooser_get_rgba() instead.
+ */
 void
-gtk_color_button_get_color (GtkColorButton *color_button,
-                           GdkColor       *color)
+gtk_color_button_get_color (GtkColorButton *button,
+                            GdkColor       *color)
 {
-  g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button));
-  
-  color->red = color_button->priv->color.red;
-  color->green = color_button->priv->color.green;
-  color->blue = color_button->priv->color.blue;
+  g_return_if_fail (GTK_IS_COLOR_BUTTON (button));
+
+  color->red = (guint16) (button->priv->rgba.red * 65535);
+  color->green = (guint16) (button->priv->rgba.green * 65535);
+  color->blue = (guint16) (button->priv->rgba.blue * 65535);
 }
 
 /**
  * gtk_color_button_get_alpha:
- * @color_button: a #GtkColorButton.
+ * @button: a #GtkColorButton
  *
- * Returns the current alpha value. 
+ * Returns the current alpha value.
  *
- * Return value: an integer between 0 and 65535.
+ * Return value: an integer between 0 and 65535
  *
  * Since: 2.4
- **/
+ *
+ * Deprecated: 3.4: Use gtk_color_chooser_get_rgba() instead.
+ */
 guint16
-gtk_color_button_get_alpha (GtkColorButton *color_button)
+gtk_color_button_get_alpha (GtkColorButton *button)
 {
-  g_return_val_if_fail (GTK_IS_COLOR_BUTTON (color_button), 0);
-  
-  return color_button->priv->alpha;
+  g_return_val_if_fail (GTK_IS_COLOR_BUTTON (button), 0);
+
+  return (guint16) (button->priv->rgba.alpha * 65535);
+}
+
+/**
+ * gtk_color_button_set_rgba: (skip)
+ * @button: a #GtkColorButton
+ * @rgba: a #GdkRGBA to set the current color with
+ *
+ * Sets the current color to be @rgba.
+ *
+ * Since: 3.0
+ *
+ * Deprecated: 3.4: Use gtk_color_chooser_set_rgba() instead.
+ */
+void
+gtk_color_button_set_rgba (GtkColorButton *button,
+                           const GdkRGBA  *rgba)
+{
+  g_return_if_fail (GTK_IS_COLOR_BUTTON (button));
+  g_return_if_fail (rgba != NULL);
+
+  button->priv->rgba = *rgba;
+  gtk_widget_queue_draw (button->priv->draw_area);
+
+  g_object_notify (G_OBJECT (button), "color");
+  g_object_notify (G_OBJECT (button), "alpha");
+  g_object_notify (G_OBJECT (button), "rgba");
+}
+
+/**
+ * gtk_color_button_get_rgba: (skip)
+ * @button: a #GtkColorButton
+ * @rgba: (out): a #GdkRGBA to fill in with the current color
+ *
+ * Sets @rgba to be the current color in the #GtkColorButton widget.
+ *
+ * Since: 3.0
+ *
+ * Deprecated: 3.4: Use gtk_color_chooser_get_rgba() instead.
+ */
+void
+gtk_color_button_get_rgba (GtkColorButton *button,
+                           GdkRGBA        *rgba)
+{
+  g_return_if_fail (GTK_IS_COLOR_BUTTON (button));
+  g_return_if_fail (rgba != NULL);
+
+  *rgba = button->priv->rgba;
 }
 
 /**
  * gtk_color_button_set_use_alpha:
- * @color_button: a #GtkColorButton.
- * @use_alpha: %TRUE if color button should use alpha channel, %FALSE if not.
+ * @button: a #GtkColorButton
+ * @use_alpha: %TRUE if color button should use alpha channel, %FALSE if not
  *
  * Sets whether or not the color button should use the alpha channel.
  *
  * Since: 2.4
+ *
+ * Deprecated: 3.4: Use gtk_color_chooser_set_use_alpha() instead.
  */
 void
-gtk_color_button_set_use_alpha (GtkColorButton *color_button, 
-                               gboolean        use_alpha)
+gtk_color_button_set_use_alpha (GtkColorButton *button,
+                                gboolean        use_alpha)
 {
-  g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button));
+  g_return_if_fail (GTK_IS_COLOR_BUTTON (button));
 
   use_alpha = (use_alpha != FALSE);
 
-  if (color_button->priv->use_alpha != use_alpha) 
+  if (button->priv->use_alpha != use_alpha)
     {
-      color_button->priv->use_alpha = use_alpha;
+      button->priv->use_alpha = use_alpha;
 
-      render (color_button);
-      gtk_widget_queue_draw (color_button->priv->draw_area);
+      gtk_widget_queue_draw (button->priv->draw_area);
 
-      g_object_notify (G_OBJECT (color_button), "use-alpha");
+      g_object_notify (G_OBJECT (button), "use-alpha");
     }
 }
 
 /**
  * gtk_color_button_get_use_alpha:
- * @color_button: a #GtkColorButton.
+ * @button: a #GtkColorButton
  *
- * Does the color selection dialog use the alpha channel?
+ * Does the color selection dialog use the alpha channel ?
  *
- * Returns: %TRUE if the color sample uses alpha channel, %FALSE if not.
+ * Returns: %TRUE if the color sample uses alpha channel, %FALSE if not
  *
  * Since: 2.4
+ *
+ * Deprecated: 3.4: Use gtk_color_chooser_get_use_alpha() instead.
  */
 gboolean
-gtk_color_button_get_use_alpha (GtkColorButton *color_button)
+gtk_color_button_get_use_alpha (GtkColorButton *button)
 {
-  g_return_val_if_fail (GTK_IS_COLOR_BUTTON (color_button), FALSE);
+  g_return_val_if_fail (GTK_IS_COLOR_BUTTON (button), FALSE);
 
-  return color_button->priv->use_alpha;
+  return button->priv->use_alpha;
 }
 
 
 /**
  * gtk_color_button_set_title:
- * @color_button: a #GtkColorButton
- * @title: String containing new window title.
+ * @button: a #GtkColorButton
+ * @title: String containing new window title
  *
  * Sets the title for the color selection dialog.
  *
  * Since: 2.4
  */
 void
-gtk_color_button_set_title (GtkColorButton *color_button, 
-                           const gchar    *title)
+gtk_color_button_set_title (GtkColorButton *button,
+                            const gchar    *title)
 {
   gchar *old_title;
 
-  g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button));
+  g_return_if_fail (GTK_IS_COLOR_BUTTON (button));
 
-  old_title = color_button->priv->title;
-  color_button->priv->title = g_strdup (title);
+  old_title = button->priv->title;
+  button->priv->title = g_strdup (title);
   g_free (old_title);
 
-  if (color_button->priv->cs_dialog)
-    gtk_window_set_title (GTK_WINDOW (color_button->priv->cs_dialog), 
-                         color_button->priv->title);
-  
-  g_object_notify (G_OBJECT (color_button), "title");
+  if (button->priv->cs_dialog)
+    gtk_window_set_title (GTK_WINDOW (button->priv->cs_dialog),
+                          button->priv->title);
+
+  g_object_notify (G_OBJECT (button), "title");
 }
 
 /**
  * gtk_color_button_get_title:
- * @color_button: a #GtkColorButton
+ * @button: a #GtkColorButton
  *
  * Gets the title of the color selection dialog.
  *
@@ -955,35 +861,50 @@ gtk_color_button_set_title (GtkColorButton *color_button,
  *
  * Since: 2.4
  */
-G_CONST_RETURN gchar *
-gtk_color_button_get_title (GtkColorButton *color_button)
+const gchar *
+gtk_color_button_get_title (GtkColorButton *button)
 {
-  g_return_val_if_fail (GTK_IS_COLOR_BUTTON (color_button), NULL);
+  g_return_val_if_fail (GTK_IS_COLOR_BUTTON (button), NULL);
 
-  return color_button->priv->title;
+  return button->priv->title;
 }
 
 static void
 gtk_color_button_set_property (GObject      *object,
-                              guint         param_id,
-                              const GValue *value,
-                              GParamSpec   *pspec)
+                               guint         param_id,
+                               const GValue *value,
+                               GParamSpec   *pspec)
 {
-  GtkColorButton *color_button = GTK_COLOR_BUTTON (object);
+  GtkColorButton *button = GTK_COLOR_BUTTON (object);
 
-  switch (param_id) 
+  switch (param_id)
     {
     case PROP_USE_ALPHA:
-      gtk_color_button_set_use_alpha (color_button, g_value_get_boolean (value));
+      gtk_color_button_set_use_alpha (button, g_value_get_boolean (value));
       break;
     case PROP_TITLE:
-      gtk_color_button_set_title (color_button, g_value_get_string (value));
+      gtk_color_button_set_title (button, g_value_get_string (value));
       break;
     case PROP_COLOR:
-      gtk_color_button_set_color (color_button, g_value_get_boxed (value));
+      {
+        GdkColor *color;
+        GdkRGBA rgba;
+
+        color = g_value_get_boxed (value);
+
+        rgba.red = color->red / 65535.0;
+        rgba.green = color->green / 65535.0;
+        rgba.blue = color->blue / 65535.0;
+        rgba.alpha = 1.0;
+
+        gtk_color_button_set_rgba (button, &rgba);
+      }
       break;
     case PROP_ALPHA:
-      gtk_color_button_set_alpha (color_button, g_value_get_uint (value));
+      gtk_color_button_set_alpha (button, g_value_get_uint (value));
+      break;
+    case PROP_RGBA:
+      gtk_color_button_set_rgba (button, g_value_get_boxed (value));
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
@@ -993,27 +914,44 @@ gtk_color_button_set_property (GObject      *object,
 
 static void
 gtk_color_button_get_property (GObject    *object,
-                              guint       param_id,
-                              GValue     *value,
-                              GParamSpec *pspec)
+                               guint       param_id,
+                               GValue     *value,
+                               GParamSpec *pspec)
 {
-  GtkColorButton *color_button = GTK_COLOR_BUTTON (object);
-  GdkColor color;
+  GtkColorButton *button = GTK_COLOR_BUTTON (object);
 
-  switch (param_id) 
+  switch (param_id)
     {
     case PROP_USE_ALPHA:
-      g_value_set_boolean (value, gtk_color_button_get_use_alpha (color_button));
+      g_value_set_boolean (value, gtk_color_button_get_use_alpha (button));
       break;
     case PROP_TITLE:
-      g_value_set_string (value, gtk_color_button_get_title (color_button));
+      g_value_set_string (value, gtk_color_button_get_title (button));
       break;
     case PROP_COLOR:
-      gtk_color_button_get_color (color_button, &color);
-      g_value_set_boxed (value, &color);
+      {
+        GdkColor color;
+        GdkRGBA rgba;
+
+        gtk_color_button_get_rgba (button, &rgba);
+
+        color.red = (guint16) (rgba.red * 65535 + 0.5);
+        color.green = (guint16) (rgba.green * 65535 + 0.5);
+        color.blue = (guint16) (rgba.blue * 65535 + 0.5);
+
+        g_value_set_boxed (value, &color);
+      }
       break;
     case PROP_ALPHA:
-      g_value_set_uint (value, gtk_color_button_get_alpha (color_button));
+      g_value_set_uint (value, gtk_color_button_get_alpha (button));
+      break;
+    case PROP_RGBA:
+      {
+        GdkRGBA rgba;
+
+        gtk_color_button_get_rgba (button, &rgba);
+        g_value_set_boxed (value, &rgba);
+      }
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
@@ -1021,5 +959,29 @@ gtk_color_button_get_property (GObject    *object,
     }
 }
 
-#define __GTK_COLOR_BUTTON_C__
-#include "gtkaliasdef.c"
+static void
+gtk_color_button_add_palette (GtkColorChooser *chooser,
+                              GtkOrientation   orientation,
+                              gint             colors_per_line,
+                              gint             n_colors,
+                              GdkRGBA         *colors)
+{
+  GtkColorButton *button = GTK_COLOR_BUTTON (chooser);
+
+  ensure_dialog (button);
+
+  gtk_color_chooser_add_palette (GTK_COLOR_CHOOSER (button->priv->cs_dialog),
+                                   orientation, colors_per_line, n_colors, colors);
+}
+
+typedef void (* get_rgba) (GtkColorChooser *, GdkRGBA *);
+typedef void (* set_rgba) (GtkColorChooser *, const GdkRGBA *);
+
+static void
+gtk_color_button_iface_init (GtkColorChooserInterface *iface)
+{
+  iface->get_rgba = (get_rgba)gtk_color_button_get_rgba;
+  iface->set_rgba = (set_rgba)gtk_color_button_set_rgba;
+  iface->add_palette = gtk_color_button_add_palette;
+}
+