* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
-#include <config.h>
+#include "config.h"
#include "gtkcolorbutton.h"
#include "gdk/gdkkeysyms.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"
/* 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 CHECK_DARK (1.0 / 3.0)
+#define CHECK_LIGHT (2.0 / 3.0)
-#define GTK_COLOR_BUTTON_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_COLOR_BUTTON, 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 */
};
PROP_USE_ALPHA,
PROP_TITLE,
PROP_COLOR,
- PROP_ALPHA
+ PROP_ALPHA,
+ PROP_RGBA
};
/* Signals */
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,
GParamSpec *pspec);
/* gtkwidget signals */
-static void gtk_color_button_realize (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);
/* gtkbutton signals */
static void gtk_color_button_clicked (GtkButton *button);
GtkColorButton *color_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;
-}
+G_DEFINE_TYPE (GtkColorButton, gtk_color_button, GTK_TYPE_BUTTON)
static void
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->style_set = gtk_color_button_style_set;
button_class->clicked = gtk_color_button_clicked;
klass->color_set = NULL;
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"),
+ P_("Whether to give the color an alpha value"),
FALSE,
GTK_PARAM_READWRITE));
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_color() and
+ * gtk_color_button_get_alpha() 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"),
+ 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),
g_type_class_add_private (gobject_class, sizeof (GtkColorButtonPrivate));
}
-static void
-render (GtkColorButton *color_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 */
+static gboolean
+gtk_color_button_has_alpha (GtkColorButton *color_button)
+{
+ return color_button->priv->use_alpha &&
+ color_button->priv->rgba.alpha < 1;
+}
- 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;
+static cairo_pattern_t *
+gtk_color_button_get_checkered (void)
+{
+ /* need to respect pixman's stride being a multiple of 4 */
+ static unsigned char data[8] = { 0xFF, 0x00, 0x00, 0x00,
+ 0x00, 0xFF, 0x00, 0x00 };
+ static cairo_surface_t *checkered = NULL;
+ cairo_pattern_t *pattern;
- 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
+ if (checkered == NULL)
{
- 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;
+ checkered = cairo_image_surface_create_for_data (data,
+ CAIRO_FORMAT_A8,
+ 2, 2, 4);
}
- /* 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];
- }
- }
- }
+ pattern = cairo_pattern_create_for_surface (checkered);
+ cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
+ cairo_pattern_set_filter (pattern, CAIRO_FILTER_NEAREST);
+
+ return pattern;
}
/* 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);
+ cairo_pattern_t *checkered;
- 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;
-}
-
-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 (color_button))
+ {
+ cairo_set_source_rgb (cr, CHECK_DARK, CHECK_DARK, CHECK_DARK);
+ cairo_paint (cr);
- if (color_button->priv->gc == NULL)
- 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);
-}
+ checkered = gtk_color_button_get_checkered ();
+ cairo_mask (cr, checkered);
+ cairo_pattern_destroy (checkered);
-static void
-gtk_color_button_style_set (GtkWidget *widget,
- GtkStyle *previous_style)
-{
- GtkColorButton *color_button = GTK_COLOR_BUTTON (widget);
+ gdk_cairo_set_source_rgba (cr, &color_button->priv->rgba);
+ }
+ else
+ {
+ cairo_set_source_rgb (cr,
+ color_button->priv->rgba.red,
+ color_button->priv->rgba.green,
+ color_button->priv->rgba.blue);
+ }
- GTK_WIDGET_CLASS (parent_class)->style_set (widget, previous_style);
+ cairo_paint (cr);
- if (GTK_WIDGET_REALIZED (widget))
+ if (!gtk_widget_is_sensitive (GTK_WIDGET (color_button)))
{
- if (color_button->priv->pixbuf != NULL)
- g_object_unref (color_button->priv->pixbuf);
- color_button->priv->pixbuf = NULL;
+ gdk_cairo_set_source_color (cr, >k_widget_get_style (GTK_WIDGET(color_button))->bg[GTK_STATE_INSENSITIVE]);
+ checkered = gtk_color_button_get_checkered ();
+ cairo_mask (cr, checkered);
+ cairo_pattern_destroy (checkered);
}
+
+ return FALSE;
}
static void
gtk_color_button_state_changed (GtkWidget *widget,
- GtkStateType previous_state)
+ 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
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];
-
- if (color_button->priv->pixbuf != NULL)
- g_object_unref (color_button->priv->pixbuf);
- color_button->priv->pixbuf = NULL;
+ color_button->priv->rgba.red = dropped[0] / 65535.;
+ color_button->priv->rgba.green = dropped[1] / 65535.;
+ color_button->priv->rgba.blue = dropped[2] / 65535.;
+ color_button->priv->rgba.alpha = dropped[3] / 65535.;
gtk_widget_queue_draw (color_button->priv->draw_area);
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_notify (G_OBJECT (color_button), "rgba");
g_object_thaw_notify (G_OBJECT (color_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
gpointer data)
{
GtkColorButton *color_button = data;
-
- set_color_icon (context, &color_button->priv->color);
+
+ set_color_icon (context, &color_button->priv->rgba);
}
static void
{
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) (color_button->priv->rgba.red * 65535);
+ dropped[1] = (guint16) (color_button->priv->rgba.green * 65535);
+ dropped[2] = (guint16) (color_button->priv->rgba.blue * 65535);
+ dropped[3] = (guint16) (color_button->priv->rgba.alpha * 65535);
gtk_selection_data_set (selection_data, selection_data->target,
16, (guchar *)dropped, 8);
PangoRectangle rect;
/* Create the widgets */
- color_button->priv = GTK_COLOR_BUTTON_GET_PRIVATE (color_button);
+ color_button->priv = G_TYPE_INSTANCE_GET_PRIVATE (color_button,
+ GTK_TYPE_COLOR_BUTTON,
+ GtkColorButtonPrivate);
gtk_widget_push_composite_child ();
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);
+ g_signal_connect (color_button->priv->draw_area, "draw",
+ G_CALLBACK (gtk_color_button_draw_cb), color_button);
gtk_container_add (GTK_CONTAINER (frame), color_button->priv->draw_area);
gtk_widget_show (color_button->priv->draw_area);
color_button->priv->title = g_strdup (_("Pick a Color")); /* default title */
- /* 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;
-
/* Start with opaque black, alpha disabled */
- 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->rgba.red = 0;
+ color_button->priv->rgba.green = 0;
+ color_button->priv->rgba.blue = 0;
+ color_button->priv->rgba.alpha = 1;
color_button->priv->use_alpha = FALSE;
gtk_drag_dest_set (GTK_WIDGET (color_button),
GDK_BUTTON1_MASK|GDK_BUTTON3_MASK,
drop_types, 1,
GDK_ACTION_COPY);
- g_signal_connect (color_button, "drag_begin",
+ 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_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_signal_connect (color_button, "drag-data-get",
G_CALLBACK (gtk_color_button_drag_data_get), color_button);
gtk_widget_pop_composite_child ();
{
GtkColorButton *color_button = GTK_COLOR_BUTTON (object);
- if (color_button->priv->gc != NULL)
- g_object_unref (color_button->priv->gc);
- color_button->priv->gc = NULL;
-
if (color_button->priv->cs_dialog != NULL)
gtk_widget_destroy (color_button->priv->cs_dialog);
color_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 (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);
}
return g_object_new (GTK_TYPE_COLOR_BUTTON, "color", color, NULL);
}
+/**
+ * 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)
+{
+ return g_object_new (GTK_TYPE_COLOR_BUTTON, "rgba", rgba, NULL);
+}
+
static void
dialog_ok_clicked (GtkWidget *widget,
gpointer data)
{
GtkColorButton *color_button = GTK_COLOR_BUTTON (data);
GtkColorSelection *color_selection;
+ GtkColorSelectionDialog *selection_dialog;
- color_selection = GTK_COLOR_SELECTION (GTK_COLOR_SELECTION_DIALOG (color_button->priv->cs_dialog)->colorsel);
-
- gtk_color_selection_get_current_color (color_selection, &color_button->priv->color);
- color_button->priv->alpha = gtk_color_selection_get_current_alpha (color_selection);
+ selection_dialog = GTK_COLOR_SELECTION_DIALOG (color_button->priv->cs_dialog);
+ color_selection = GTK_COLOR_SELECTION (gtk_color_selection_dialog_get_color_selection (selection_dialog));
- if (color_button->priv->pixbuf != NULL)
- g_object_unref (color_button->priv->pixbuf);
- color_button->priv->pixbuf = NULL;
+ gtk_color_selection_get_current_rgba (color_selection, &color_button->priv->rgba);
gtk_widget_hide (color_button->priv->cs_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_notify (G_OBJECT (color_button), "rgba");
g_object_thaw_notify (G_OBJECT (color_button));
}
gtk_color_button_clicked (GtkButton *button)
{
GtkColorButton *color_button = GTK_COLOR_BUTTON (button);
+ GtkColorSelection *color_selection;
GtkColorSelectionDialog *color_dialog;
/* if dialog already exists, make sure it's shown and raised */
{
/* Create the dialog and connects its buttons */
GtkWidget *parent;
+ GtkWidget *ok_button, *cancel_button;
parent = gtk_widget_get_toplevel (GTK_WIDGET (color_button));
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));
+ if (gtk_widget_is_toplevel (parent) && GTK_IS_WINDOW (parent))
+ {
+ if (GTK_WINDOW (parent) != gtk_window_get_transient_for (GTK_WINDOW (color_dialog)))
+ gtk_window_set_transient_for (GTK_WINDOW (color_dialog), GTK_WINDOW (parent));
+
+ gtk_window_set_modal (GTK_WINDOW (color_dialog),
+ gtk_window_get_modal (GTK_WINDOW (parent)));
+ }
+
+ g_object_get (color_dialog,
+ "ok-button", &ok_button,
+ "cancel-button", &cancel_button,
+ NULL);
- g_signal_connect (color_dialog->ok_button, "clicked",
+ g_signal_connect (ok_button, "clicked",
G_CALLBACK (dialog_ok_clicked), color_button);
- g_signal_connect (color_dialog->cancel_button, "clicked",
+ g_signal_connect (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);
}
color_dialog = GTK_COLOR_SELECTION_DIALOG (color_button->priv->cs_dialog);
+ color_selection = GTK_COLOR_SELECTION (gtk_color_selection_dialog_get_color_selection (color_dialog));
- gtk_color_selection_set_has_opacity_control (GTK_COLOR_SELECTION (color_dialog->colorsel),
+ gtk_color_selection_set_has_opacity_control (color_selection,
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_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_color_selection_set_previous_rgba (color_selection,
+ &color_button->priv->rgba);
+ gtk_color_selection_set_current_rgba (color_selection,
+ &color_button->priv->rgba);
gtk_window_present (GTK_WINDOW (color_button->priv->cs_dialog));
}
g_return_if_fail (GTK_IS_COLOR_BUTTON (color_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;
-
- if (color_button->priv->pixbuf != NULL)
- g_object_unref (color_button->priv->pixbuf);
- color_button->priv->pixbuf = NULL;
+ color_button->priv->rgba.red = color->red / 65535.;
+ color_button->priv->rgba.green = color->green / 65535.;
+ color_button->priv->rgba.blue = color->blue / 65535.;
gtk_widget_queue_draw (color_button->priv->draw_area);
g_object_notify (G_OBJECT (color_button), "color");
+ g_object_notify (G_OBJECT (color_button), "rgba");
}
{
g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button));
- color_button->priv->alpha = alpha;
-
- if (color_button->priv->pixbuf != NULL)
- g_object_unref (color_button->priv->pixbuf);
- color_button->priv->pixbuf = NULL;
+ color_button->priv->rgba.alpha = alpha / 65535.;
gtk_widget_queue_draw (color_button->priv->draw_area);
g_object_notify (G_OBJECT (color_button), "alpha");
+ g_object_notify (G_OBJECT (color_button), "rgba");
}
/**
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;
+
+ color->red = (guint16) (color_button->priv->rgba.red * 65535);
+ color->green = (guint16) (color_button->priv->rgba.green * 65535);
+ color->blue = (guint16) (color_button->priv->rgba.blue * 65535);
}
/**
gtk_color_button_get_alpha (GtkColorButton *color_button)
{
g_return_val_if_fail (GTK_IS_COLOR_BUTTON (color_button), 0);
-
- return color_button->priv->alpha;
+
+ return (guint16) (color_button->priv->rgba.alpha * 65535);
+}
+
+/**
+ * gtk_color_button_set_rgba:
+ * @color_button: a #GtkColorButton.
+ * @rgba: a #GdkRGBA to set the current color with
+ *
+ * Sets the current color to be @rgba.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_color_button_set_rgba (GtkColorButton *color_button,
+ const GdkRGBA *rgba)
+{
+ g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button));
+ g_return_if_fail (rgba != NULL);
+
+ color_button->priv->rgba = *rgba;
+
+ g_object_notify (G_OBJECT (color_button), "rgba");
+}
+
+/**
+ * gtk_color_button_get_rgba:
+ * @color_button: a #GtkColorButton.
+ * @rgba: a #GdkRGBA to fill in with the current color
+ *
+ * Sets @rgba to be the current color in the #GtkColorButton widget.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_color_button_get_rgba (GtkColorButton *color_button,
+ GdkRGBA *rgba)
+{
+ g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button));
+ g_return_if_fail (rgba != NULL);
+
+ *rgba = color_button->priv->rgba;
}
/**
{
color_button->priv->use_alpha = use_alpha;
- render (color_button);
gtk_widget_queue_draw (color_button->priv->draw_area);
g_object_notify (G_OBJECT (color_button), "use-alpha");
case PROP_ALPHA:
gtk_color_button_set_alpha (color_button, g_value_get_uint (value));
break;
+ case PROP_RGBA:
+ gtk_color_button_set_rgba (color_button, g_value_get_boxed (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
case PROP_ALPHA:
g_value_set_uint (value, gtk_color_button_get_alpha (color_button));
break;
+ case PROP_RGBA:
+ {
+ GdkRGBA rgba;
+
+ gtk_color_button_get_rgba (color_button, &rgba);
+ g_value_set_boxed (value, &rgba);
+ }
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
}
}
-
-#define __GTK_COLOR_BUTTON_C__
-#include "gtkaliasdef.c"