2003-07-01 19:52:07 +00:00
|
|
|
/*
|
2008-07-01 22:57:50 +00:00
|
|
|
* GTK - The GIMP Toolkit
|
2003-07-01 19:52:07 +00:00
|
|
|
* Copyright (C) 1998, 1999 Red Hat, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This Library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This Library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
/* Color picker button for GNOME
|
|
|
|
*
|
|
|
|
* Author: Federico Mena <federico@nuclecu.unam.mx>
|
|
|
|
*
|
|
|
|
* 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
|
2011-01-03 22:18:43 +00:00
|
|
|
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
2003-07-01 19:52:07 +00:00
|
|
|
*/
|
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
#define GDK_DISABLE_DEPRECATION_WARNINGS
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
#include "gtkcolorbutton.h"
|
2011-01-04 17:21:41 +00:00
|
|
|
|
2003-07-01 19:52:07 +00:00
|
|
|
#include "gtkbutton.h"
|
|
|
|
#include "gtkmain.h"
|
2012-02-01 06:51:42 +00:00
|
|
|
#include "gtkcolorchooser.h"
|
|
|
|
#include "gtkcolorchooserdialog.h"
|
2003-07-01 19:52:07 +00:00
|
|
|
#include "gtkdnd.h"
|
|
|
|
#include "gtkdrawingarea.h"
|
|
|
|
#include "gtkmarshalers.h"
|
2005-03-22 02:14:55 +00:00
|
|
|
#include "gtkprivate.h"
|
2003-07-01 19:52:07 +00:00
|
|
|
#include "gtkintl.h"
|
|
|
|
|
2010-11-06 02:19:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:gtkcolorbutton
|
|
|
|
* @Short_description: A button to launch a color selection dialog
|
|
|
|
* @Title: GtkColorButton
|
|
|
|
* @See_also: #GtkColorSelectionDialog, #GtkFontButton
|
|
|
|
*
|
2011-01-03 22:18:43 +00:00
|
|
|
* 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.
|
2010-11-06 02:19:32 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2003-07-01 19:52:07 +00:00
|
|
|
/* Size of checks and gray levels for alpha compositing checkerboard */
|
|
|
|
#define CHECK_SIZE 4
|
2010-07-11 23:10:08 +00:00
|
|
|
#define CHECK_DARK (1.0 / 3.0)
|
|
|
|
#define CHECK_LIGHT (2.0 / 3.0)
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2012-02-09 15:48:10 +00:00
|
|
|
#define COLOR_SAMPLE_MARGIN 1
|
2003-09-30 22:48:10 +00:00
|
|
|
|
2011-01-03 22:18:43 +00:00
|
|
|
struct _GtkColorButtonPrivate
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2005-05-11 19:16:19 +00:00
|
|
|
GtkWidget *draw_area; /* Widget where we draw the color sample */
|
2003-07-01 19:52:07 +00:00
|
|
|
GtkWidget *cs_dialog; /* Color selection dialog */
|
2011-01-03 22:18:43 +00:00
|
|
|
|
2003-07-01 19:52:07 +00:00
|
|
|
gchar *title; /* Title for the color selection window */
|
2010-10-22 15:58:24 +00:00
|
|
|
GdkRGBA rgba;
|
|
|
|
|
2003-07-01 19:52:07 +00:00
|
|
|
guint use_alpha : 1; /* Use alpha or not */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Properties */
|
2011-01-03 22:18:43 +00:00
|
|
|
enum
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_USE_ALPHA,
|
|
|
|
PROP_TITLE,
|
|
|
|
PROP_COLOR,
|
2010-10-22 15:58:24 +00:00
|
|
|
PROP_ALPHA,
|
|
|
|
PROP_RGBA
|
2003-07-01 19:52:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Signals */
|
2011-01-03 22:18:43 +00:00
|
|
|
enum
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
|
|
|
COLOR_SET,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
/* gobject signals */
|
|
|
|
static void gtk_color_button_finalize (GObject *object);
|
|
|
|
static void gtk_color_button_set_property (GObject *object,
|
2011-01-03 22:18:43 +00:00
|
|
|
guint param_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2003-07-01 19:52:07 +00:00
|
|
|
static void gtk_color_button_get_property (GObject *object,
|
2011-01-03 22:18:43 +00:00
|
|
|
guint param_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
/* gtkwidget signals */
|
2011-01-03 22:18:43 +00:00
|
|
|
static void gtk_color_button_state_changed (GtkWidget *widget,
|
|
|
|
GtkStateType previous_state);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
/* gtkbutton signals */
|
|
|
|
static void gtk_color_button_clicked (GtkButton *button);
|
|
|
|
|
|
|
|
/* source side drag signals */
|
|
|
|
static void gtk_color_button_drag_begin (GtkWidget *widget,
|
2011-01-03 22:18:43 +00:00
|
|
|
GdkDragContext *context,
|
|
|
|
gpointer data);
|
2003-07-01 19:52:07 +00:00
|
|
|
static void gtk_color_button_drag_data_get (GtkWidget *widget,
|
|
|
|
GdkDragContext *context,
|
|
|
|
GtkSelectionData *selection_data,
|
|
|
|
guint info,
|
|
|
|
guint time,
|
2012-02-03 23:34:33 +00:00
|
|
|
GtkColorButton *button);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
/* target side drag signals */
|
|
|
|
static void gtk_color_button_drag_data_received (GtkWidget *widget,
|
2011-01-03 22:18:43 +00:00
|
|
|
GdkDragContext *context,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
GtkSelectionData *selection_data,
|
|
|
|
guint info,
|
|
|
|
guint32 time,
|
2012-02-03 23:34:33 +00:00
|
|
|
GtkColorButton *button);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
static guint color_button_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2005-03-01 06:25:55 +00:00
|
|
|
static const GtkTargetEntry drop_types[] = { { "application/x-color", 0, 0 } };
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
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))
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_color_button_class_init (GtkColorButtonClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GtkWidgetClass *widget_class;
|
|
|
|
GtkButtonClass *button_class;
|
|
|
|
|
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
button_class = GTK_BUTTON_CLASS (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;
|
|
|
|
button_class->clicked = gtk_color_button_clicked;
|
|
|
|
klass->color_set = NULL;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkColorButton:use-alpha:
|
|
|
|
*
|
2012-02-04 00:40:36 +00:00
|
|
|
* 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.
|
2003-07-01 19:52:07 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_USE_ALPHA,
|
2011-01-03 22:18:43 +00:00
|
|
|
g_param_spec_boolean ("use-alpha", P_("Use alpha"),
|
2010-08-10 08:23:49 +00:00
|
|
|
P_("Whether to give the color an alpha value"),
|
2003-07-01 19:52:07 +00:00
|
|
|
FALSE,
|
2005-03-22 02:14:55 +00:00
|
|
|
GTK_PARAM_READWRITE));
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkColorButton:title:
|
|
|
|
*
|
|
|
|
* The title of the color selection dialog
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_TITLE,
|
2011-01-03 22:18:43 +00:00
|
|
|
g_param_spec_string ("title",
|
|
|
|
P_("Title"),
|
2004-01-16 23:10:05 +00:00
|
|
|
P_("The title of the color selection dialog"),
|
2003-11-05 23:23:05 +00:00
|
|
|
_("Pick a Color"),
|
2005-03-22 02:14:55 +00:00
|
|
|
GTK_PARAM_READWRITE));
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkColorButton:color:
|
|
|
|
*
|
|
|
|
* The selected color.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
2011-12-13 11:02:13 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.4: Use #GtkColorButton:rgba instead.
|
2003-07-01 19:52:07 +00:00
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_COLOR,
|
|
|
|
g_param_spec_boxed ("color",
|
2004-01-16 23:10:05 +00:00
|
|
|
P_("Current Color"),
|
|
|
|
P_("The selected color"),
|
2003-07-01 19:52:07 +00:00
|
|
|
GDK_TYPE_COLOR,
|
2011-12-13 11:02:13 +00:00
|
|
|
GTK_PARAM_READWRITE | G_PARAM_DEPRECATED));
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkColorButton:alpha:
|
|
|
|
*
|
2011-01-03 22:18:43 +00:00
|
|
|
* The selected opacity value (0 fully transparent, 65535 fully opaque).
|
2003-07-01 19:52:07 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_ALPHA,
|
|
|
|
g_param_spec_uint ("alpha",
|
2004-01-16 23:10:05 +00:00
|
|
|
P_("Current Alpha"),
|
|
|
|
P_("The selected opacity value (0 fully transparent, 65535 fully opaque)"),
|
2003-07-01 19:52:07 +00:00
|
|
|
0, 65535, 65535,
|
2005-03-22 02:14:55 +00:00
|
|
|
GTK_PARAM_READWRITE));
|
2010-10-22 15:58:24 +00:00
|
|
|
|
|
|
|
/**
|
2011-01-03 22:18:43 +00:00
|
|
|
* GtkColorButton:rgba:
|
2010-10-22 15:58:24 +00:00
|
|
|
*
|
|
|
|
* 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));
|
|
|
|
|
|
|
|
|
2003-07-01 19:52:07 +00:00
|
|
|
/**
|
|
|
|
* GtkColorButton::color-set:
|
|
|
|
* @widget: the object which received the signal.
|
2011-01-03 22:18:43 +00:00
|
|
|
*
|
|
|
|
* 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() (or gtk_color_button_get_rgba()) to
|
|
|
|
* find out which color was just selected.
|
2006-05-31 04:06:12 +00:00
|
|
|
*
|
|
|
|
* 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.
|
2003-07-01 19:52:07 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
2008-08-11 13:07:18 +00:00
|
|
|
color_button_signals[COLOR_SET] = g_signal_new (I_("color-set"),
|
2011-01-03 22:18:43 +00:00
|
|
|
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);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2006-05-31 04:38:16 +00:00
|
|
|
g_type_class_add_private (gobject_class, sizeof (GtkColorButtonPrivate));
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
2010-07-11 23:10:08 +00:00
|
|
|
static gboolean
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_button_has_alpha (GtkColorButton *button)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2012-02-03 23:34:33 +00:00
|
|
|
return button->priv->use_alpha && button->priv->rgba.alpha < 1;
|
2010-07-11 23:10:08 +00:00
|
|
|
}
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2010-07-11 23:10:08 +00:00
|
|
|
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;
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2010-07-11 23:10:08 +00:00
|
|
|
if (checkered == NULL)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2010-07-11 23:10:08 +00:00
|
|
|
checkered = cairo_image_surface_create_for_data (data,
|
|
|
|
CAIRO_FORMAT_A8,
|
|
|
|
2, 2, 4);
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
2010-07-11 23:10:08 +00:00
|
|
|
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;
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle exposure events for the color picker's drawing area */
|
|
|
|
static gint
|
2011-01-03 22:18:43 +00:00
|
|
|
gtk_color_button_draw_cb (GtkWidget *widget,
|
2010-09-08 15:58:45 +00:00
|
|
|
cairo_t *cr,
|
|
|
|
gpointer data)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2012-02-03 23:34:33 +00:00
|
|
|
GtkColorButton *button = GTK_COLOR_BUTTON (data);
|
2010-07-11 23:10:08 +00:00
|
|
|
cairo_pattern_t *checkered;
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
if (gtk_color_button_has_alpha (button))
|
2010-07-11 23:10:08 +00:00
|
|
|
{
|
|
|
|
cairo_set_source_rgb (cr, CHECK_DARK, CHECK_DARK, CHECK_DARK);
|
|
|
|
cairo_paint (cr);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2010-07-11 23:10:08 +00:00
|
|
|
cairo_set_source_rgb (cr, CHECK_LIGHT, CHECK_LIGHT, CHECK_LIGHT);
|
|
|
|
cairo_scale (cr, CHECK_SIZE, CHECK_SIZE);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2010-07-11 23:10:08 +00:00
|
|
|
checkered = gtk_color_button_get_checkered ();
|
|
|
|
cairo_mask (cr, checkered);
|
|
|
|
cairo_pattern_destroy (checkered);
|
2006-01-23 10:46:02 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
gdk_cairo_set_source_rgba (cr, &button->priv->rgba);
|
2010-07-11 23:10:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-10-22 15:58:24 +00:00
|
|
|
cairo_set_source_rgb (cr,
|
2012-02-03 23:34:33 +00:00
|
|
|
button->priv->rgba.red,
|
|
|
|
button->priv->rgba.green,
|
|
|
|
button->priv->rgba.blue);
|
2010-07-11 23:10:08 +00:00
|
|
|
}
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2010-07-11 23:10:08 +00:00
|
|
|
cairo_paint (cr);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
if (!gtk_widget_is_sensitive (GTK_WIDGET (button)))
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2011-01-10 01:30:25 +00:00
|
|
|
GtkStyleContext *context;
|
|
|
|
GdkRGBA color;
|
|
|
|
|
|
|
|
context = gtk_widget_get_style_context (widget);
|
|
|
|
gtk_style_context_get_background_color (context, GTK_STATE_FLAG_INSENSITIVE, &color);
|
|
|
|
|
|
|
|
gdk_cairo_set_source_rgba (cr, &color);
|
2010-07-11 23:10:08 +00:00
|
|
|
checkered = gtk_color_button_get_checkered ();
|
|
|
|
cairo_mask (cr, checkered);
|
|
|
|
cairo_pattern_destroy (checkered);
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
2010-07-11 23:10:08 +00:00
|
|
|
|
|
|
|
return FALSE;
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-01-03 22:18:43 +00:00
|
|
|
gtk_color_button_state_changed (GtkWidget *widget,
|
2010-07-11 23:10:08 +00:00
|
|
|
GtkStateType previous_state)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2010-07-11 23:10:08 +00:00
|
|
|
gtk_widget_queue_draw (widget);
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_color_button_drag_data_received (GtkWidget *widget,
|
2011-01-03 22:18:43 +00:00
|
|
|
GdkDragContext *context,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
GtkSelectionData *selection_data,
|
|
|
|
guint info,
|
|
|
|
guint32 time,
|
2012-02-03 23:34:33 +00:00
|
|
|
GtkColorButton *button)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2010-12-15 23:56:14 +00:00
|
|
|
gint length;
|
2003-07-01 19:52:07 +00:00
|
|
|
guint16 *dropped;
|
|
|
|
|
2010-12-15 23:56:14 +00:00
|
|
|
length = gtk_selection_data_get_length (selection_data);
|
|
|
|
|
|
|
|
if (length < 0)
|
2003-07-01 19:52:07 +00:00
|
|
|
return;
|
|
|
|
|
2003-08-02 09:22:38 +00:00
|
|
|
/* We accept drops with the wrong format, since the KDE color
|
|
|
|
* chooser incorrectly drops application/x-color with format 8.
|
|
|
|
*/
|
2010-12-15 23:56:14 +00:00
|
|
|
if (length != 8)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2011-04-29 20:50:17 +00:00
|
|
|
g_warning ("%s: Received invalid color data", G_STRFUNC);
|
2003-07-01 19:52:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-15 23:56:14 +00:00
|
|
|
dropped = (guint16 *) gtk_selection_data_get_data (selection_data);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
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.;
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_widget_queue_draw (button->priv->draw_area);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
g_signal_emit (button, color_button_signals[COLOR_SET], 0);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
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));
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_color_icon (GdkDragContext *context,
|
2010-10-22 15:58:24 +00:00
|
|
|
GdkRGBA *rgba)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2010-10-22 15:58:24 +00:00
|
|
|
cairo_surface_t *surface;
|
|
|
|
cairo_t *cr;
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2010-10-22 15:58:24 +00:00
|
|
|
surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
|
|
|
|
48, 32);
|
|
|
|
cr = cairo_create (surface);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2010-10-22 15:58:24 +00:00
|
|
|
gdk_cairo_set_source_rgba (cr, rgba);
|
|
|
|
cairo_paint (cr);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2010-10-22 15:58:24 +00:00
|
|
|
gtk_drag_set_icon_surface (context, surface);
|
|
|
|
|
|
|
|
cairo_destroy (cr);
|
|
|
|
cairo_surface_destroy (surface);
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_color_button_drag_begin (GtkWidget *widget,
|
2011-01-03 22:18:43 +00:00
|
|
|
GdkDragContext *context,
|
|
|
|
gpointer data)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2012-02-03 23:34:33 +00:00
|
|
|
GtkColorButton *button = data;
|
2010-10-22 15:58:24 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
set_color_icon (context, &button->priv->rgba);
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_color_button_drag_data_get (GtkWidget *widget,
|
2011-01-03 22:18:43 +00:00
|
|
|
GdkDragContext *context,
|
|
|
|
GtkSelectionData *selection_data,
|
|
|
|
guint info,
|
|
|
|
guint time,
|
2012-02-03 23:34:33 +00:00
|
|
|
GtkColorButton *button)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
|
|
|
guint16 dropped[4];
|
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
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);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2010-12-15 23:56:14 +00:00
|
|
|
gtk_selection_data_set (selection_data,
|
|
|
|
gtk_selection_data_get_target (selection_data),
|
2011-01-03 22:18:43 +00:00
|
|
|
16, (guchar *)dropped, 8);
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_button_init (GtkColorButton *button)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
|
|
|
PangoLayout *layout;
|
|
|
|
PangoRectangle rect;
|
|
|
|
|
|
|
|
/* Create the widgets */
|
2012-02-03 23:34:33 +00:00
|
|
|
button->priv = G_TYPE_INSTANCE_GET_PRIVATE (button,
|
|
|
|
GTK_TYPE_COLOR_BUTTON,
|
|
|
|
GtkColorButtonPrivate);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
gtk_widget_push_composite_child ();
|
|
|
|
|
2012-02-09 15:48:10 +00:00
|
|
|
button->priv->draw_area = gtk_drawing_area_new ();
|
|
|
|
g_object_set (button->priv->draw_area,
|
|
|
|
"margin-top", COLOR_SAMPLE_MARGIN,
|
|
|
|
"margin-bottom", COLOR_SAMPLE_MARGIN,
|
|
|
|
"margin-left", 16,
|
|
|
|
"margin-right", 16,
|
|
|
|
NULL);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
layout = gtk_widget_create_pango_layout (GTK_WIDGET (button), "Black");
|
2003-07-01 19:52:07 +00:00
|
|
|
pango_layout_get_pixel_extents (layout, NULL, &rect);
|
2005-11-27 20:23:46 +00:00
|
|
|
g_object_unref (layout);
|
|
|
|
|
2012-02-09 15:48:10 +00:00
|
|
|
gtk_widget_set_size_request (button->priv->draw_area,
|
|
|
|
rect.width, rect.height - 2 * COLOR_SAMPLE_MARGIN);
|
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
g_signal_connect (button->priv->draw_area, "draw",
|
|
|
|
G_CALLBACK (gtk_color_button_draw_cb), button);
|
2012-02-09 15:48:10 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (button), button->priv->draw_area);
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_widget_show (button->priv->draw_area);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
button->priv->title = g_strdup (_("Pick a Color")); /* default title */
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
/* Start with opaque black, alpha disabled */
|
2012-02-03 23:34:33 +00:00
|
|
|
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;
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_drag_dest_set (GTK_WIDGET (button),
|
2003-07-01 19:52:07 +00:00
|
|
|
GTK_DEST_DEFAULT_MOTION |
|
|
|
|
GTK_DEST_DEFAULT_HIGHLIGHT |
|
|
|
|
GTK_DEST_DEFAULT_DROP,
|
|
|
|
drop_types, 1, GDK_ACTION_COPY);
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_drag_source_set (GTK_WIDGET (button),
|
2003-07-01 19:52:07 +00:00
|
|
|
GDK_BUTTON1_MASK|GDK_BUTTON3_MASK,
|
|
|
|
drop_types, 1,
|
|
|
|
GDK_ACTION_COPY);
|
2012-02-03 23:34:33 +00:00
|
|
|
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);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
gtk_widget_pop_composite_child ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_color_button_finalize (GObject *object)
|
|
|
|
{
|
2012-02-03 23:34:33 +00:00
|
|
|
GtkColorButton *button = GTK_COLOR_BUTTON (object);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
if (button->priv->cs_dialog != NULL)
|
|
|
|
gtk_widget_destroy (button->priv->cs_dialog);
|
|
|
|
button->priv->cs_dialog = NULL;
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
g_free (button->priv->title);
|
|
|
|
button->priv->title = NULL;
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2006-05-02 23:56:43 +00:00
|
|
|
G_OBJECT_CLASS (gtk_color_button_parent_class)->finalize (object);
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_color_button_new:
|
|
|
|
*
|
2011-01-03 22:18:43 +00:00
|
|
|
* 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.
|
2003-07-01 19:52:07 +00:00
|
|
|
*
|
2011-01-03 22:18:43 +00:00
|
|
|
* Returns: a new color button
|
2003-07-01 19:52:07 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gtk_color_button_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_COLOR_BUTTON, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_color_button_new_with_color:
|
2011-01-03 22:18:43 +00:00
|
|
|
* @color: A #GdkColor to set the current color with
|
2003-07-01 19:52:07 +00:00
|
|
|
*
|
2011-01-03 22:18:43 +00:00
|
|
|
* Creates a new color button.
|
2003-07-01 19:52:07 +00:00
|
|
|
*
|
2011-01-03 22:18:43 +00:00
|
|
|
* Returns: a new color button
|
2003-07-01 19:52:07 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2011-12-13 11:02:13 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.4: Use gtk_color_button_new_with_rgba() instead.
|
2003-07-01 19:52:07 +00:00
|
|
|
*/
|
|
|
|
GtkWidget *
|
2004-01-26 20:21:09 +00:00
|
|
|
gtk_color_button_new_with_color (const GdkColor *color)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_COLOR_BUTTON, "color", color, NULL);
|
|
|
|
}
|
|
|
|
|
2010-10-23 21:02:40 +00:00
|
|
|
/**
|
|
|
|
* gtk_color_button_new_with_rgba:
|
2011-01-03 22:18:43 +00:00
|
|
|
* @rgba: A #GdkRGBA to set the current color with
|
2010-10-23 21:02:40 +00:00
|
|
|
*
|
|
|
|
* Creates a new color button.
|
|
|
|
*
|
|
|
|
* Returns: a new color button
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
*/
|
2010-10-22 15:58:24 +00:00
|
|
|
GtkWidget *
|
|
|
|
gtk_color_button_new_with_rgba (const GdkRGBA *rgba)
|
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_COLOR_BUTTON, "rgba", rgba, NULL);
|
|
|
|
}
|
|
|
|
|
2003-07-01 19:52:07 +00:00
|
|
|
static gboolean
|
2011-01-03 22:18:43 +00:00
|
|
|
dialog_destroy (GtkWidget *widget,
|
|
|
|
gpointer data)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2012-02-03 23:34:33 +00:00
|
|
|
GtkColorButton *button = GTK_COLOR_BUTTON (data);
|
2011-01-03 22:18:43 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
button->priv->cs_dialog = NULL;
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-01 06:51:42 +00:00
|
|
|
dialog_response (GtkDialog *dialog,
|
|
|
|
gint response,
|
|
|
|
gpointer data)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2012-02-01 06:51:42 +00:00
|
|
|
if (response == GTK_RESPONSE_CANCEL)
|
|
|
|
gtk_widget_hide (GTK_WIDGET (dialog));
|
|
|
|
else if (response == GTK_RESPONSE_OK)
|
|
|
|
{
|
2012-02-03 23:34:33 +00:00
|
|
|
GtkColorButton *button = GTK_COLOR_BUTTON (data);
|
2012-02-01 06:51:42 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (dialog),
|
|
|
|
&button->priv->rgba);
|
2012-02-01 06:51:42 +00:00
|
|
|
|
|
|
|
gtk_widget_hide (GTK_WIDGET (dialog));
|
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_widget_queue_draw (button->priv->draw_area);
|
2011-01-03 22:18:43 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
g_signal_emit (button, color_button_signals[COLOR_SET], 0);
|
2012-02-01 06:51:42 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
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));
|
2012-02-01 06:51:42 +00:00
|
|
|
}
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_button_clicked (GtkButton *b)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2012-02-03 23:34:33 +00:00
|
|
|
GtkColorButton *button = GTK_COLOR_BUTTON (b);
|
2012-02-01 06:51:42 +00:00
|
|
|
GtkWidget *dialog;
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
/* if dialog already exists, make sure it's shown and raised */
|
2012-02-03 23:34:33 +00:00
|
|
|
if (!button->priv->cs_dialog)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
|
|
|
/* Create the dialog and connects its buttons */
|
|
|
|
GtkWidget *parent;
|
2011-01-03 22:18:43 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
parent = gtk_widget_get_toplevel (GTK_WIDGET (button));
|
2011-01-03 22:18:43 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
button->priv->cs_dialog = dialog = gtk_color_chooser_dialog_new (button->priv->title, NULL);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2010-01-04 06:49:26 +00:00
|
|
|
if (gtk_widget_is_toplevel (parent) && GTK_IS_WINDOW (parent))
|
2006-05-24 19:44:20 +00:00
|
|
|
{
|
2012-02-01 06:51:42 +00:00
|
|
|
if (GTK_WINDOW (parent) != gtk_window_get_transient_for (GTK_WINDOW (dialog)))
|
|
|
|
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
|
2011-01-03 22:18:43 +00:00
|
|
|
|
2012-02-01 06:51:42 +00:00
|
|
|
gtk_window_set_modal (GTK_WINDOW (dialog),
|
2011-01-03 22:18:43 +00:00
|
|
|
gtk_window_get_modal (GTK_WINDOW (parent)));
|
|
|
|
}
|
2010-06-02 02:24:16 +00:00
|
|
|
|
2012-02-01 06:51:42 +00:00
|
|
|
g_signal_connect (dialog, "response",
|
2012-02-03 23:34:33 +00:00
|
|
|
G_CALLBACK (dialog_response), button);
|
2012-02-01 06:51:42 +00:00
|
|
|
g_signal_connect (dialog, "destroy",
|
2012-02-03 23:34:33 +00:00
|
|
|
G_CALLBACK (dialog_destroy), button);
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER (button->priv->cs_dialog),
|
|
|
|
button->priv->use_alpha);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_window_present (GTK_WINDOW (button->priv->cs_dialog));
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_color_button_set_color:
|
2012-02-03 23:34:33 +00:00
|
|
|
* @button: a #GtkColorButton
|
2011-01-03 22:18:43 +00:00
|
|
|
* @color: A #GdkColor to set the current color with
|
2003-07-01 19:52:07 +00:00
|
|
|
*
|
|
|
|
* Sets the current color to be @color.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
2011-12-13 11:02:13 +00:00
|
|
|
*
|
2012-02-04 00:40:36 +00:00
|
|
|
* Deprecated: Use gtk_color_chooser_set_rgba() instead.
|
2011-01-03 22:18:43 +00:00
|
|
|
*/
|
2003-07-01 19:52:07 +00:00
|
|
|
void
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_button_set_color (GtkColorButton *button,
|
2011-01-03 22:18:43 +00:00
|
|
|
const GdkColor *color)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2012-02-03 23:34:33 +00:00
|
|
|
g_return_if_fail (GTK_IS_COLOR_BUTTON (button));
|
2005-09-14 04:48:38 +00:00
|
|
|
g_return_if_fail (color != NULL);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
button->priv->rgba.red = color->red / 65535.;
|
|
|
|
button->priv->rgba.green = color->green / 65535.;
|
|
|
|
button->priv->rgba.blue = color->blue / 65535.;
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_widget_queue_draw (button->priv->draw_area);
|
2011-01-03 22:18:43 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
g_object_notify (G_OBJECT (button), "color");
|
|
|
|
g_object_notify (G_OBJECT (button), "rgba");
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_color_button_set_alpha:
|
2012-02-03 23:34:33 +00:00
|
|
|
* @button: a #GtkColorButton
|
2011-01-03 22:18:43 +00:00
|
|
|
* @alpha: an integer between 0 and 65535
|
2003-07-01 19:52:07 +00:00
|
|
|
*
|
2011-01-03 22:18:43 +00:00
|
|
|
* Sets the current opacity to be @alpha.
|
2003-07-01 19:52:07 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2012-02-04 00:40:36 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.4: Use gtk_color_chooser_set_rgba() instead.
|
2011-01-03 22:18:43 +00:00
|
|
|
*/
|
2003-07-01 19:52:07 +00:00
|
|
|
void
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_button_set_alpha (GtkColorButton *button,
|
2011-01-03 22:18:43 +00:00
|
|
|
guint16 alpha)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2012-02-03 23:34:33 +00:00
|
|
|
g_return_if_fail (GTK_IS_COLOR_BUTTON (button));
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
button->priv->rgba.alpha = alpha / 65535.;
|
2004-01-21 23:29:08 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_widget_queue_draw (button->priv->draw_area);
|
2004-01-21 23:29:08 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
g_object_notify (G_OBJECT (button), "alpha");
|
|
|
|
g_object_notify (G_OBJECT (button), "rgba");
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_color_button_get_color:
|
2012-02-03 23:34:33 +00:00
|
|
|
* @button: a #GtkColorButton
|
2011-01-03 22:18:43 +00:00
|
|
|
* @color: (out): a #GdkColor to fill in with the current color
|
2003-07-01 19:52:07 +00:00
|
|
|
*
|
|
|
|
* Sets @color to be the current color in the #GtkColorButton widget.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
2011-12-13 11:02:13 +00:00
|
|
|
*
|
2012-02-04 00:40:36 +00:00
|
|
|
* Deprecated: 3.4: Use gtk_color_chooser_get_rgba() instead.
|
2011-01-03 22:18:43 +00:00
|
|
|
*/
|
2003-07-01 19:52:07 +00:00
|
|
|
void
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_button_get_color (GtkColorButton *button,
|
2011-01-03 22:18:43 +00:00
|
|
|
GdkColor *color)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2012-02-03 23:34:33 +00:00
|
|
|
g_return_if_fail (GTK_IS_COLOR_BUTTON (button));
|
2010-10-22 15:58:24 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
color->red = (guint16) (button->priv->rgba.red * 65535);
|
|
|
|
color->green = (guint16) (button->priv->rgba.green * 65535);
|
|
|
|
color->blue = (guint16) (button->priv->rgba.blue * 65535);
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_color_button_get_alpha:
|
2012-02-03 23:34:33 +00:00
|
|
|
* @button: a #GtkColorButton
|
2003-07-01 19:52:07 +00:00
|
|
|
*
|
2011-01-03 22:18:43 +00:00
|
|
|
* Returns the current alpha value.
|
2003-07-01 19:52:07 +00:00
|
|
|
*
|
2011-01-03 22:18:43 +00:00
|
|
|
* Return value: an integer between 0 and 65535
|
2003-07-01 19:52:07 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2012-02-04 00:40:36 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.4: Use gtk_color_chooser_get_rgba() instead.
|
2011-01-03 22:18:43 +00:00
|
|
|
*/
|
2003-07-01 19:52:07 +00:00
|
|
|
guint16
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_button_get_alpha (GtkColorButton *button)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2012-02-03 23:34:33 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_COLOR_BUTTON (button), 0);
|
2010-10-22 15:58:24 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
return (guint16) (button->priv->rgba.alpha * 65535);
|
2010-10-22 15:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_color_button_set_rgba:
|
2012-02-03 23:34:33 +00:00
|
|
|
* @button: a #GtkColorButton
|
2010-10-22 15:58:24 +00:00
|
|
|
* @rgba: a #GdkRGBA to set the current color with
|
|
|
|
*
|
|
|
|
* Sets the current color to be @rgba.
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
2012-02-04 00:40:36 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.4: Use gtk_color_chooser_set_rgba() instead.
|
2011-01-03 22:18:43 +00:00
|
|
|
*/
|
2010-10-22 15:58:24 +00:00
|
|
|
void
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_button_set_rgba (GtkColorButton *button,
|
2010-10-22 15:58:24 +00:00
|
|
|
const GdkRGBA *rgba)
|
|
|
|
{
|
2012-02-03 23:34:33 +00:00
|
|
|
g_return_if_fail (GTK_IS_COLOR_BUTTON (button));
|
2010-10-22 15:58:24 +00:00
|
|
|
g_return_if_fail (rgba != NULL);
|
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
button->priv->rgba = *rgba;
|
|
|
|
gtk_widget_queue_draw (button->priv->draw_area);
|
2011-02-03 14:02:15 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
g_object_notify (G_OBJECT (button), "color");
|
|
|
|
g_object_notify (G_OBJECT (button), "alpha");
|
|
|
|
g_object_notify (G_OBJECT (button), "rgba");
|
2010-10-22 15:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_color_button_get_rgba:
|
2012-02-03 23:34:33 +00:00
|
|
|
* @button: a #GtkColorButton
|
2010-12-08 14:30:42 +00:00
|
|
|
* @rgba: (out): a #GdkRGBA to fill in with the current color
|
2010-10-22 15:58:24 +00:00
|
|
|
*
|
|
|
|
* Sets @rgba to be the current color in the #GtkColorButton widget.
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
2012-02-04 00:40:36 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.4: Use gtk_color_chooser_get_rgba() instead.
|
2011-01-03 22:18:43 +00:00
|
|
|
*/
|
2010-10-22 15:58:24 +00:00
|
|
|
void
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_button_get_rgba (GtkColorButton *button,
|
2010-10-22 15:58:24 +00:00
|
|
|
GdkRGBA *rgba)
|
|
|
|
{
|
2012-02-03 23:34:33 +00:00
|
|
|
g_return_if_fail (GTK_IS_COLOR_BUTTON (button));
|
2010-10-22 15:58:24 +00:00
|
|
|
g_return_if_fail (rgba != NULL);
|
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
*rgba = button->priv->rgba;
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_color_button_set_use_alpha:
|
2012-02-03 23:34:33 +00:00
|
|
|
* @button: a #GtkColorButton
|
2011-01-03 22:18:43 +00:00
|
|
|
* @use_alpha: %TRUE if color button should use alpha channel, %FALSE if not
|
2003-07-01 19:52:07 +00:00
|
|
|
*
|
|
|
|
* Sets whether or not the color button should use the alpha channel.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
2012-02-04 00:40:36 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.4: Use gtk_color_chooser_set_use_alpha() instead.
|
2003-07-01 19:52:07 +00:00
|
|
|
*/
|
|
|
|
void
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_button_set_use_alpha (GtkColorButton *button,
|
2011-01-03 22:18:43 +00:00
|
|
|
gboolean use_alpha)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2012-02-03 23:34:33 +00:00
|
|
|
g_return_if_fail (GTK_IS_COLOR_BUTTON (button));
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
use_alpha = (use_alpha != FALSE);
|
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
if (button->priv->use_alpha != use_alpha)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2012-02-03 23:34:33 +00:00
|
|
|
button->priv->use_alpha = use_alpha;
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_widget_queue_draw (button->priv->draw_area);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
g_object_notify (G_OBJECT (button), "use-alpha");
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_color_button_get_use_alpha:
|
2012-02-03 23:34:33 +00:00
|
|
|
* @button: a #GtkColorButton
|
2003-07-01 19:52:07 +00:00
|
|
|
*
|
2011-01-03 22:18:43 +00:00
|
|
|
* Does the color selection dialog use the alpha channel ?
|
2003-07-01 19:52:07 +00:00
|
|
|
*
|
2011-01-03 22:18:43 +00:00
|
|
|
* Returns: %TRUE if the color sample uses alpha channel, %FALSE if not
|
2003-07-01 19:52:07 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2012-02-04 00:40:36 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.4: Use gtk_color_chooser_get_use_alpha() instead.
|
2003-07-01 19:52:07 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_button_get_use_alpha (GtkColorButton *button)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2012-02-03 23:34:33 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_COLOR_BUTTON (button), FALSE);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
return button->priv->use_alpha;
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_color_button_set_title:
|
2012-02-03 23:34:33 +00:00
|
|
|
* @button: a #GtkColorButton
|
2011-01-03 22:18:43 +00:00
|
|
|
* @title: String containing new window title
|
2003-07-01 19:52:07 +00:00
|
|
|
*
|
|
|
|
* Sets the title for the color selection dialog.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
|
|
|
void
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_button_set_title (GtkColorButton *button,
|
2011-01-03 22:18:43 +00:00
|
|
|
const gchar *title)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
|
|
|
gchar *old_title;
|
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
g_return_if_fail (GTK_IS_COLOR_BUTTON (button));
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
old_title = button->priv->title;
|
|
|
|
button->priv->title = g_strdup (title);
|
2003-07-01 19:52:07 +00:00
|
|
|
g_free (old_title);
|
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
if (button->priv->cs_dialog)
|
|
|
|
gtk_window_set_title (GTK_WINDOW (button->priv->cs_dialog),
|
|
|
|
button->priv->title);
|
2011-01-03 22:18:43 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
g_object_notify (G_OBJECT (button), "title");
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_color_button_get_title:
|
2012-02-03 23:34:33 +00:00
|
|
|
* @button: a #GtkColorButton
|
2003-07-01 19:52:07 +00:00
|
|
|
*
|
|
|
|
* Gets the title of the color selection dialog.
|
|
|
|
*
|
|
|
|
* Returns: An internal string, do not free the return value
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
2011-06-06 18:13:44 +00:00
|
|
|
const gchar *
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_button_get_title (GtkColorButton *button)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2012-02-03 23:34:33 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_COLOR_BUTTON (button), NULL);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
return button->priv->title;
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_color_button_set_property (GObject *object,
|
2011-01-03 22:18:43 +00:00
|
|
|
guint param_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2012-02-03 23:34:33 +00:00
|
|
|
GtkColorButton *button = GTK_COLOR_BUTTON (object);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2011-01-03 22:18:43 +00:00
|
|
|
switch (param_id)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
|
|
|
case PROP_USE_ALPHA:
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_button_set_use_alpha (button, g_value_get_boolean (value));
|
2003-07-01 19:52:07 +00:00
|
|
|
break;
|
|
|
|
case PROP_TITLE:
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_button_set_title (button, g_value_get_string (value));
|
2003-07-01 19:52:07 +00:00
|
|
|
break;
|
|
|
|
case PROP_COLOR:
|
2012-01-03 17:12:15 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_button_set_rgba (button, &rgba);
|
2012-01-03 17:12:15 +00:00
|
|
|
}
|
2003-07-01 19:52:07 +00:00
|
|
|
break;
|
|
|
|
case PROP_ALPHA:
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_button_set_alpha (button, g_value_get_uint (value));
|
2003-07-01 19:52:07 +00:00
|
|
|
break;
|
2010-10-22 15:58:24 +00:00
|
|
|
case PROP_RGBA:
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_button_set_rgba (button, g_value_get_boxed (value));
|
2010-10-22 15:58:24 +00:00
|
|
|
break;
|
2003-07-01 19:52:07 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_color_button_get_property (GObject *object,
|
2011-01-03 22:18:43 +00:00
|
|
|
guint param_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2012-02-03 23:34:33 +00:00
|
|
|
GtkColorButton *button = GTK_COLOR_BUTTON (object);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2011-01-03 22:18:43 +00:00
|
|
|
switch (param_id)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
|
|
|
case PROP_USE_ALPHA:
|
2012-02-03 23:34:33 +00:00
|
|
|
g_value_set_boolean (value, gtk_color_button_get_use_alpha (button));
|
2003-07-01 19:52:07 +00:00
|
|
|
break;
|
|
|
|
case PROP_TITLE:
|
2012-02-03 23:34:33 +00:00
|
|
|
g_value_set_string (value, gtk_color_button_get_title (button));
|
2003-07-01 19:52:07 +00:00
|
|
|
break;
|
|
|
|
case PROP_COLOR:
|
2012-01-03 17:12:15 +00:00
|
|
|
{
|
|
|
|
GdkColor color;
|
|
|
|
GdkRGBA rgba;
|
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_button_get_rgba (button, &rgba);
|
2012-01-03 17:12:15 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2003-07-01 19:52:07 +00:00
|
|
|
break;
|
|
|
|
case PROP_ALPHA:
|
2012-02-03 23:34:33 +00:00
|
|
|
g_value_set_uint (value, gtk_color_button_get_alpha (button));
|
2003-07-01 19:52:07 +00:00
|
|
|
break;
|
2010-10-22 15:58:24 +00:00
|
|
|
case PROP_RGBA:
|
|
|
|
{
|
|
|
|
GdkRGBA rgba;
|
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_button_get_rgba (button, &rgba);
|
2010-10-22 15:58:24 +00:00
|
|
|
g_value_set_boxed (value, &rgba);
|
|
|
|
}
|
|
|
|
break;
|
2003-07-01 19:52:07 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-02-03 23:34:33 +00:00
|
|
|
|
2012-02-04 06:45:55 +00:00
|
|
|
static void
|
|
|
|
gtk_color_button_add_palette (GtkColorChooser *chooser,
|
|
|
|
gboolean horizontal,
|
|
|
|
gint colors_per_line,
|
|
|
|
gint n_colors,
|
|
|
|
GdkRGBA *colors)
|
|
|
|
{
|
|
|
|
GtkColorButton *button = GTK_COLOR_BUTTON (chooser);
|
|
|
|
|
|
|
|
if (button->priv->cs_dialog)
|
|
|
|
gtk_color_chooser_add_palette (GTK_COLOR_CHOOSER (button->priv->cs_dialog),
|
|
|
|
horizontal, colors_per_line, n_colors, colors);
|
|
|
|
}
|
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
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;
|
2012-02-04 06:45:55 +00:00
|
|
|
iface->add_palette = gtk_color_button_add_palette;
|
2012-02-03 23:34:33 +00:00
|
|
|
}
|
|
|
|
|