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
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2003-07-01 19:52:07 +00:00
|
|
|
*/
|
|
|
|
/* 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
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
2019-09-23 15:00:07 +00:00
|
|
|
#include "gtkbinlayout.h"
|
2003-07-01 19:52:07 +00:00
|
|
|
#include "gtkbutton.h"
|
2012-02-01 06:51:42 +00:00
|
|
|
#include "gtkcolorchooser.h"
|
2012-02-14 17:16:56 +00:00
|
|
|
#include "gtkcolorchooserprivate.h"
|
2012-02-01 06:51:42 +00:00
|
|
|
#include "gtkcolorchooserdialog.h"
|
2014-07-10 00:50:47 +00:00
|
|
|
#include "gtkcolorswatchprivate.h"
|
2015-11-22 04:26:08 +00:00
|
|
|
#include "gtkdragsource.h"
|
2020-02-29 02:47:17 +00:00
|
|
|
#include "gtkdroptarget.h"
|
2018-03-26 04:26:34 +00:00
|
|
|
#include "gtkintl.h"
|
|
|
|
#include "gtkmain.h"
|
2003-07-01 19:52:07 +00:00
|
|
|
#include "gtkmarshalers.h"
|
2005-03-22 02:14:55 +00:00
|
|
|
#include "gtkprivate.h"
|
2018-03-26 04:26:34 +00:00
|
|
|
#include "gtksnapshot.h"
|
2020-04-08 11:43:28 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2010-11-06 02:19:32 +00:00
|
|
|
|
|
|
|
/**
|
2021-02-22 00:42:17 +00:00
|
|
|
* GtkColorButton:
|
|
|
|
*
|
|
|
|
* The `GtkColorButton` allows to open a color chooser dialog to change
|
|
|
|
* the color.
|
|
|
|
*
|
|
|
|
* ![An example GtkColorButton](color-button.png)
|
2010-11-06 02:19:32 +00:00
|
|
|
*
|
2011-01-03 22:18:43 +00:00
|
|
|
* It is suitable widget for selecting a color in a preference dialog.
|
2015-10-30 05:15:57 +00:00
|
|
|
*
|
|
|
|
* # CSS nodes
|
|
|
|
*
|
2021-02-28 00:45:07 +00:00
|
|
|
* ```
|
2020-12-23 14:03:07 +00:00
|
|
|
* colorbutton
|
|
|
|
* ╰── button.color
|
|
|
|
* ╰── [content]
|
2021-02-28 00:45:07 +00:00
|
|
|
* ```
|
2020-12-23 14:03:07 +00:00
|
|
|
*
|
2021-02-22 00:42:17 +00:00
|
|
|
* `GtkColorButton` has a single CSS node with name colorbutton which
|
|
|
|
* contains a button node. To differentiate it from a plain `GtkButton`,
|
2020-12-23 14:03:07 +00:00
|
|
|
* it gets the .color style class.
|
2010-11-06 02:19:32 +00:00
|
|
|
*/
|
|
|
|
|
2019-05-28 00:03:46 +00:00
|
|
|
typedef struct _GtkColorButtonClass GtkColorButtonClass;
|
|
|
|
|
|
|
|
struct _GtkColorButton {
|
|
|
|
GtkWidget parent_instance;
|
|
|
|
|
2017-02-05 08:21:56 +00:00
|
|
|
GtkWidget *button;
|
|
|
|
|
2014-07-10 00:50:47 +00:00
|
|
|
GtkWidget *swatch; /* 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
|
|
|
|
2021-02-22 00:42:17 +00:00
|
|
|
char *title; /* Title for the color chooser dialog */
|
2010-10-22 15:58:24 +00:00
|
|
|
GdkRGBA rgba;
|
|
|
|
|
2020-04-13 04:17:00 +00:00
|
|
|
guint use_alpha : 1; /* Use alpha or not */
|
2016-01-27 02:27:12 +00:00
|
|
|
guint show_editor : 1;
|
2020-04-13 04:17:00 +00:00
|
|
|
guint modal : 1;
|
2020-04-13 04:28:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkColorButtonClass {
|
|
|
|
GtkWidgetClass parent_class;
|
|
|
|
|
|
|
|
void (* color_set) (GtkColorButton *cp);
|
2021-07-05 14:10:19 +00:00
|
|
|
void (* activate) (GtkColorButton *self);
|
2020-04-13 04:28:11 +00:00
|
|
|
};
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
/* 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,
|
2016-01-27 02:27:12 +00:00
|
|
|
PROP_RGBA,
|
2020-04-13 04:17:00 +00:00
|
|
|
PROP_SHOW_EDITOR,
|
|
|
|
PROP_MODAL
|
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,
|
2021-07-05 14:10:19 +00:00
|
|
|
ACTIVATE,
|
2003-07-01 19:52:07 +00:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
/* gobject signals */
|
2014-07-10 01:08:18 +00:00
|
|
|
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);
|
|
|
|
static void gtk_color_button_get_property (GObject *object,
|
|
|
|
guint param_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2020-09-20 16:03:47 +00:00
|
|
|
static void gtk_color_button_root (GtkWidget *widget);
|
|
|
|
|
2003-07-01 19:52:07 +00:00
|
|
|
/* gtkbutton signals */
|
2017-02-05 08:21:56 +00:00
|
|
|
static void gtk_color_button_clicked (GtkButton *button,
|
|
|
|
gpointer user_data);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
static guint color_button_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
static void gtk_color_button_iface_init (GtkColorChooserInterface *iface);
|
|
|
|
|
2017-02-05 08:21:56 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkColorButton, gtk_color_button, GTK_TYPE_WIDGET,
|
2012-02-03 23:34:33 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_COLOR_CHOOSER,
|
|
|
|
gtk_color_button_iface_init))
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2021-07-05 14:10:19 +00:00
|
|
|
static void
|
|
|
|
gtk_color_button_activate (GtkColorButton *self)
|
|
|
|
{
|
|
|
|
gtk_widget_activate (self->button);
|
|
|
|
}
|
|
|
|
|
2003-07-01 19:52:07 +00:00
|
|
|
static void
|
|
|
|
gtk_color_button_class_init (GtkColorButtonClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
2017-02-05 08:21:56 +00:00
|
|
|
GtkWidgetClass *widget_class;
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
2017-02-05 08:21:56 +00:00
|
|
|
widget_class = GTK_WIDGET_CLASS (klass);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
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;
|
2017-02-05 08:21:56 +00:00
|
|
|
|
2020-04-08 11:43:28 +00:00
|
|
|
widget_class->grab_focus = gtk_widget_grab_focus_child;
|
|
|
|
widget_class->focus = gtk_widget_focus_child;
|
2020-09-20 16:03:47 +00:00
|
|
|
widget_class->root = gtk_color_button_root;
|
2020-04-08 11:43:28 +00:00
|
|
|
|
2003-07-01 19:52:07 +00:00
|
|
|
klass->color_set = NULL;
|
2021-07-05 14:10:19 +00:00
|
|
|
klass->activate = gtk_color_button_activate;
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2020-10-03 15:07:14 +00:00
|
|
|
g_object_class_override_property (gobject_class, PROP_RGBA, "rgba");
|
|
|
|
g_object_class_override_property (gobject_class, PROP_USE_ALPHA, "use-alpha");
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
/**
|
2021-02-25 23:22:09 +00:00
|
|
|
* GtkColorButton:title: (attributes org.gtk.Property.get=gtk_color_button_get_title org.gtk.Property.set=gtk_color_button_set_title)
|
2003-07-01 19:52:07 +00:00
|
|
|
*
|
2021-02-22 00:42:17 +00:00
|
|
|
* The title of the color chooser dialog
|
2003-07-01 19:52:07 +00:00
|
|
|
*/
|
|
|
|
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
|
|
|
|
2010-10-22 15:58:24 +00:00
|
|
|
|
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
|
|
|
*
|
2021-02-22 00:42:17 +00:00
|
|
|
* Emitted when the user selects a color.
|
2006-05-31 04:06:12 +00:00
|
|
|
*
|
2021-02-22 00:42:17 +00:00
|
|
|
* When handling this signal, use [method@Gtk.ColorChooser.get_rgba]
|
|
|
|
* to find out which color was just selected.
|
|
|
|
*
|
|
|
|
* Note that this signal is only emitted when the user 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
|
|
|
*/
|
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,
|
2016-08-29 14:00:17 +00:00
|
|
|
NULL,
|
2011-01-03 22:18:43 +00:00
|
|
|
G_TYPE_NONE, 0);
|
2016-01-27 02:27:12 +00:00
|
|
|
|
2021-07-05 14:10:19 +00:00
|
|
|
/**
|
|
|
|
* GtkColorButton::activate:
|
|
|
|
* @widget: the object which received the signal.
|
|
|
|
*
|
|
|
|
* Emitted to when the color button is activated.
|
|
|
|
*
|
|
|
|
* The `::activate` signal on `GtkMenuButton` is an action signal and
|
|
|
|
* emitting it causes the button to pop up its dialog.
|
|
|
|
*
|
|
|
|
* Since: 4.4
|
|
|
|
*/
|
|
|
|
color_button_signals[ACTIVATE] =
|
|
|
|
g_signal_new (I_ ("activate"),
|
|
|
|
G_OBJECT_CLASS_TYPE (gobject_class),
|
|
|
|
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
|
|
|
|
G_STRUCT_OFFSET (GtkColorButtonClass, activate),
|
|
|
|
NULL, NULL,
|
|
|
|
NULL,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
|
|
gtk_widget_class_set_activate_signal (widget_class, color_button_signals[ACTIVATE]);
|
|
|
|
|
2016-01-27 02:27:12 +00:00
|
|
|
/**
|
|
|
|
* GtkColorButton:show-editor:
|
|
|
|
*
|
2021-02-22 00:42:17 +00:00
|
|
|
* Whether the color chooser should open in editor mode.
|
2016-01-27 02:27:12 +00:00
|
|
|
*
|
|
|
|
* This property should be used in cases where the palette
|
|
|
|
* in the editor would be redundant, such as when the color
|
|
|
|
* button is already part of a palette.
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_SHOW_EDITOR,
|
|
|
|
g_param_spec_boolean ("show-editor", P_("Show Editor"),
|
|
|
|
P_("Whether to show the color editor right away"),
|
|
|
|
FALSE,
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
|
2019-09-23 15:00:07 +00:00
|
|
|
|
2021-02-22 00:42:17 +00:00
|
|
|
/**
|
2021-02-25 23:22:09 +00:00
|
|
|
* GtkColorButton:modal: (attributes org.gtk.Property.get=gtk_color_button_get_modal org.gtk.Property.set=gtk_color_button_set_modal)
|
2021-02-22 00:42:17 +00:00
|
|
|
*
|
|
|
|
* Whether the color chooser dialog should be modal.
|
|
|
|
*/
|
2020-04-13 04:17:00 +00:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_MODAL,
|
|
|
|
g_param_spec_boolean ("modal", P_("Modal"),
|
|
|
|
P_("Whether the dialog is modal"),
|
|
|
|
TRUE,
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
|
|
|
|
|
|
|
|
|
2019-09-23 15:00:07 +00:00
|
|
|
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
|
2020-01-24 04:11:49 +00:00
|
|
|
gtk_widget_class_set_css_name (widget_class, "colorbutton");
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
2020-01-01 19:40:49 +00:00
|
|
|
static gboolean
|
2020-02-29 02:47:17 +00:00
|
|
|
gtk_color_button_drop (GtkDropTarget *dest,
|
|
|
|
const GValue *value,
|
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
GtkColorButton *button)
|
2020-01-01 19:40:49 +00:00
|
|
|
{
|
2020-02-29 02:47:17 +00:00
|
|
|
GdkRGBA *color = g_value_get_boxed (value);
|
|
|
|
|
|
|
|
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (button), color);
|
2020-02-16 17:48:45 +00:00
|
|
|
return TRUE;
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
2020-02-16 15:22:37 +00:00
|
|
|
static GdkContentProvider *
|
|
|
|
gtk_color_button_drag_prepare (GtkDragSource *source,
|
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
GtkColorButton *button)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2020-04-13 04:28:11 +00:00
|
|
|
return gdk_content_provider_new_typed (GDK_TYPE_RGBA, &button->rgba);
|
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;
|
2019-12-31 15:11:37 +00:00
|
|
|
GtkDragSource *source;
|
2020-01-01 19:40:49 +00:00
|
|
|
GtkDropTarget *dest;
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2020-04-13 04:28:11 +00:00
|
|
|
button->button = gtk_button_new ();
|
|
|
|
g_signal_connect (button->button, "clicked", G_CALLBACK (gtk_color_button_clicked), button);
|
|
|
|
gtk_widget_set_parent (button->button, GTK_WIDGET (button));
|
2017-02-05 08:21:56 +00:00
|
|
|
|
2020-10-22 03:54:09 +00:00
|
|
|
button->swatch = g_object_new (GTK_TYPE_COLOR_SWATCH,
|
|
|
|
"accessible-role", GTK_ACCESSIBLE_ROLE_IMG,
|
|
|
|
"selectable", FALSE,
|
|
|
|
"has-menu", FALSE,
|
|
|
|
NULL);
|
2020-04-13 04:28:11 +00:00
|
|
|
gtk_widget_set_can_focus (button->swatch, FALSE);
|
2020-08-07 23:37:33 +00:00
|
|
|
gtk_widget_remove_css_class (button->swatch, "activatable");
|
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);
|
|
|
|
|
2020-04-13 04:28:11 +00:00
|
|
|
gtk_widget_set_size_request (button->swatch, rect.width, rect.height);
|
2012-02-09 15:48:10 +00:00
|
|
|
|
2020-05-02 07:05:19 +00:00
|
|
|
gtk_button_set_child (GTK_BUTTON (button->button), button->swatch);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2020-04-13 04:28:11 +00:00
|
|
|
button->title = g_strdup (_("Pick a Color")); /* default title */
|
2003-07-01 19:52:07 +00:00
|
|
|
|
|
|
|
/* Start with opaque black, alpha disabled */
|
2020-04-13 04:28:11 +00:00
|
|
|
button->rgba.red = 0;
|
|
|
|
button->rgba.green = 0;
|
|
|
|
button->rgba.blue = 0;
|
|
|
|
button->rgba.alpha = 1;
|
|
|
|
button->use_alpha = FALSE;
|
|
|
|
button->modal = TRUE;
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2020-02-29 02:47:17 +00:00
|
|
|
dest = gtk_drop_target_new (GDK_TYPE_RGBA, GDK_ACTION_COPY);
|
|
|
|
g_signal_connect (dest, "drop", G_CALLBACK (gtk_color_button_drop), button);
|
2020-01-06 05:12:21 +00:00
|
|
|
gtk_widget_add_controller (GTK_WIDGET (button), GTK_EVENT_CONTROLLER (dest));
|
2019-12-31 15:11:37 +00:00
|
|
|
|
2020-01-06 19:46:14 +00:00
|
|
|
source = gtk_drag_source_new ();
|
2020-02-16 15:22:37 +00:00
|
|
|
g_signal_connect (source, "prepare", G_CALLBACK (gtk_color_button_drag_prepare), button);
|
2020-02-18 01:58:58 +00:00
|
|
|
gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (source), GTK_PHASE_CAPTURE);
|
2020-04-13 04:28:11 +00:00
|
|
|
gtk_widget_add_controller (button->button, GTK_EVENT_CONTROLLER (source));
|
2015-10-30 05:15:57 +00:00
|
|
|
|
2020-04-13 04:28:11 +00:00
|
|
|
gtk_widget_add_css_class (button->button, "color");
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2020-04-13 04:28:11 +00:00
|
|
|
if (button->cs_dialog != NULL)
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (button->cs_dialog));
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2020-04-13 04:28:11 +00:00
|
|
|
g_free (button->title);
|
|
|
|
gtk_widget_unparent (button->button);
|
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
|
2021-02-26 16:25:27 +00:00
|
|
|
* is clicked, a color chooser dialog will open, allowing the user
|
2011-01-03 22:18:43 +00:00
|
|
|
* 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
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gtk_color_button_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_COLOR_BUTTON, NULL);
|
|
|
|
}
|
|
|
|
|
2010-10-23 21:02:40 +00:00
|
|
|
/**
|
|
|
|
* gtk_color_button_new_with_rgba:
|
2021-02-26 16:25:27 +00:00
|
|
|
* @rgba: A `GdkRGBA` to set the current color with
|
2010-10-23 21:02:40 +00:00
|
|
|
*
|
2021-02-22 00:42:17 +00:00
|
|
|
* Creates a new color button showing the given color.
|
2010-10-23 21:02:40 +00:00
|
|
|
*
|
|
|
|
* Returns: a new color button
|
|
|
|
*/
|
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
|
|
|
|
2020-04-13 04:28:11 +00:00
|
|
|
button->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,
|
2020-07-24 13:54:49 +00:00
|
|
|
int response,
|
2012-02-01 06:51:42 +00:00
|
|
|
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
|
|
|
|
2020-04-13 04:28:11 +00:00
|
|
|
gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (dialog), &button->rgba);
|
|
|
|
gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (button->swatch), &button->rgba);
|
2012-02-01 06:51:42 +00:00
|
|
|
|
|
|
|
gtk_widget_hide (GTK_WIDGET (dialog));
|
2014-01-08 13:37:57 +00:00
|
|
|
g_object_ref (button);
|
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), "rgba");
|
|
|
|
g_object_thaw_notify (G_OBJECT (button));
|
2014-01-08 13:37:57 +00:00
|
|
|
g_object_unref (button);
|
2012-02-01 06:51:42 +00:00
|
|
|
}
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
2012-12-03 22:46:18 +00:00
|
|
|
/* Create the dialog and connects its buttons */
|
2003-07-01 19:52:07 +00:00
|
|
|
static void
|
2012-12-03 22:46:18 +00:00
|
|
|
ensure_dialog (GtkColorButton *button)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2012-12-03 22:46:18 +00:00
|
|
|
GtkWidget *parent, *dialog;
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2020-04-13 04:28:11 +00:00
|
|
|
if (button->cs_dialog != NULL)
|
2012-12-03 22:46:18 +00:00
|
|
|
return;
|
2011-01-03 22:18:43 +00:00
|
|
|
|
2019-05-20 04:47:50 +00:00
|
|
|
parent = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (button)));
|
2011-01-03 22:18:43 +00:00
|
|
|
|
2020-04-13 04:28:11 +00:00
|
|
|
button->cs_dialog = dialog = gtk_color_chooser_dialog_new (button->title, NULL);
|
2017-12-31 16:40:00 +00:00
|
|
|
gtk_window_set_hide_on_close (GTK_WINDOW (dialog), TRUE);
|
2020-04-13 04:28:11 +00:00
|
|
|
gtk_window_set_modal (GTK_WINDOW (dialog), button->modal);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2019-03-17 23:41:26 +00:00
|
|
|
if (GTK_IS_WINDOW (parent))
|
2020-09-20 16:03:47 +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
|
|
|
|
2020-09-20 16:03:47 +00:00
|
|
|
if (gtk_window_get_modal (GTK_WINDOW (parent)))
|
|
|
|
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
|
|
|
}
|
2012-12-03 22:46:18 +00:00
|
|
|
|
|
|
|
g_signal_connect (dialog, "response",
|
|
|
|
G_CALLBACK (dialog_response), button);
|
|
|
|
g_signal_connect (dialog, "destroy",
|
|
|
|
G_CALLBACK (dialog_destroy), button);
|
|
|
|
}
|
2010-06-02 02:24:16 +00:00
|
|
|
|
2020-09-20 16:03:47 +00:00
|
|
|
static void
|
|
|
|
gtk_color_button_root (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkColorButton *button = GTK_COLOR_BUTTON (widget);
|
|
|
|
GtkWidget *parent;
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_color_button_parent_class)->root (widget);
|
|
|
|
|
|
|
|
if (!button->cs_dialog)
|
|
|
|
return;
|
|
|
|
|
|
|
|
parent = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (button)));
|
|
|
|
if (GTK_IS_WINDOW (parent))
|
|
|
|
{
|
|
|
|
if (GTK_WINDOW (parent) != gtk_window_get_transient_for (GTK_WINDOW (button->cs_dialog)))
|
|
|
|
gtk_window_set_transient_for (GTK_WINDOW (button->cs_dialog), GTK_WINDOW (parent));
|
|
|
|
|
|
|
|
if (gtk_window_get_modal (GTK_WINDOW (parent)))
|
|
|
|
gtk_window_set_modal (GTK_WINDOW (button->cs_dialog), TRUE);
|
|
|
|
}
|
|
|
|
}
|
2012-12-03 22:46:18 +00:00
|
|
|
|
|
|
|
static void
|
2017-02-05 08:21:56 +00:00
|
|
|
gtk_color_button_clicked (GtkButton *b,
|
|
|
|
gpointer user_data)
|
2012-12-03 22:46:18 +00:00
|
|
|
{
|
2017-02-05 08:21:56 +00:00
|
|
|
GtkColorButton *button = user_data;
|
2012-12-03 22:46:18 +00:00
|
|
|
|
|
|
|
/* if dialog already exists, make sure it's shown and raised */
|
|
|
|
ensure_dialog (button);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2020-04-13 04:28:11 +00:00
|
|
|
g_object_set (button->cs_dialog, "show-editor", button->show_editor, NULL);
|
2016-01-27 02:27:12 +00:00
|
|
|
|
2020-04-13 04:28:11 +00:00
|
|
|
gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER (button->cs_dialog), button->use_alpha);
|
2003-07-01 19:52:07 +00:00
|
|
|
|
2020-04-13 04:28:11 +00:00
|
|
|
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (button->cs_dialog), &button->rgba);
|
2012-05-17 03:45:48 +00:00
|
|
|
|
2020-04-13 04:28:11 +00:00
|
|
|
gtk_window_present (GTK_WINDOW (button->cs_dialog));
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
2020-10-22 03:54:09 +00:00
|
|
|
static guint
|
|
|
|
scale_round (double value,
|
|
|
|
double scale)
|
|
|
|
{
|
|
|
|
value = floor (value * scale + 0.5);
|
|
|
|
value = CLAMP (value, 0, scale);
|
|
|
|
return (guint)value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
accessible_color_name (const GdkRGBA *color)
|
|
|
|
{
|
|
|
|
if (color->alpha < 1.0)
|
|
|
|
return g_strdup_printf (_("Red %d%%, Green %d%%, Blue %d%%, Alpha %d%%"),
|
|
|
|
scale_round (color->red, 100),
|
|
|
|
scale_round (color->green, 100),
|
|
|
|
scale_round (color->blue, 100),
|
|
|
|
scale_round (color->alpha, 100));
|
|
|
|
else
|
|
|
|
return g_strdup_printf (_("Red %d%%, Green %d%%, Blue %d%%"),
|
|
|
|
scale_round (color->red, 100),
|
|
|
|
scale_round (color->green, 100),
|
|
|
|
scale_round (color->blue, 100));
|
|
|
|
}
|
|
|
|
|
2016-10-11 11:10:02 +00:00
|
|
|
static void
|
|
|
|
gtk_color_button_set_rgba (GtkColorChooser *chooser,
|
|
|
|
const GdkRGBA *rgba)
|
2010-10-22 15:58:24 +00:00
|
|
|
{
|
2020-04-13 04:28:11 +00:00
|
|
|
GtkColorButton *button = GTK_COLOR_BUTTON (chooser);
|
2020-10-22 03:54:09 +00:00
|
|
|
char *text;
|
2014-07-10 01:08:18 +00:00
|
|
|
|
2016-10-11 11:10:02 +00:00
|
|
|
g_return_if_fail (GTK_IS_COLOR_BUTTON (chooser));
|
2010-10-22 15:58:24 +00:00
|
|
|
g_return_if_fail (rgba != NULL);
|
|
|
|
|
2020-04-13 04:28:11 +00:00
|
|
|
button->rgba = *rgba;
|
|
|
|
gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (button->swatch), &button->rgba);
|
2011-02-03 14:02:15 +00:00
|
|
|
|
2020-10-22 03:54:09 +00:00
|
|
|
text = accessible_color_name (rgba);
|
|
|
|
gtk_accessible_update_property (GTK_ACCESSIBLE (button->swatch),
|
|
|
|
GTK_ACCESSIBLE_PROPERTY_LABEL, text,
|
|
|
|
-1);
|
|
|
|
g_free (text);
|
|
|
|
|
2016-10-11 11:10:02 +00:00
|
|
|
g_object_notify (G_OBJECT (chooser), "rgba");
|
2010-10-22 15:58:24 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 11:10:02 +00:00
|
|
|
static void
|
|
|
|
gtk_color_button_get_rgba (GtkColorChooser *chooser,
|
2010-10-22 15:58:24 +00:00
|
|
|
GdkRGBA *rgba)
|
|
|
|
{
|
2020-04-13 04:28:11 +00:00
|
|
|
GtkColorButton *button = GTK_COLOR_BUTTON (chooser);
|
2018-06-04 19:54:35 +00:00
|
|
|
|
2016-10-11 11:10:02 +00:00
|
|
|
g_return_if_fail (GTK_IS_COLOR_BUTTON (chooser));
|
2010-10-22 15:58:24 +00:00
|
|
|
g_return_if_fail (rgba != NULL);
|
|
|
|
|
2020-04-13 04:28:11 +00:00
|
|
|
*rgba = button->rgba;
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
2014-05-05 18:22:52 +00:00
|
|
|
static void
|
2014-07-10 01:08:18 +00:00
|
|
|
set_use_alpha (GtkColorButton *button,
|
|
|
|
gboolean use_alpha)
|
2014-05-05 18:22:52 +00:00
|
|
|
{
|
|
|
|
use_alpha = (use_alpha != FALSE);
|
|
|
|
|
2020-04-13 04:28:11 +00:00
|
|
|
if (button->use_alpha != use_alpha)
|
2014-05-05 18:22:52 +00:00
|
|
|
{
|
2020-04-13 04:28:11 +00:00
|
|
|
button->use_alpha = use_alpha;
|
2014-05-05 18:22:52 +00:00
|
|
|
|
2020-04-13 04:28:11 +00:00
|
|
|
gtk_color_swatch_set_use_alpha (GTK_COLOR_SWATCH (button->swatch), use_alpha);
|
2014-05-05 18:22:52 +00:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (button), "use-alpha");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-01 19:52:07 +00:00
|
|
|
/**
|
2021-02-25 23:22:09 +00:00
|
|
|
* gtk_color_button_set_title: (attributes org.gtk.Method.set_property=title)
|
2021-02-22 00:42:17 +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
|
|
|
*
|
2021-02-22 00:42:17 +00:00
|
|
|
* Sets the title for the color chooser dialog.
|
2003-07-01 19:52:07 +00:00
|
|
|
*/
|
|
|
|
void
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_button_set_title (GtkColorButton *button,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *title)
|
2003-07-01 19:52:07 +00:00
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
char *old_title;
|
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
|
|
|
|
2020-04-13 04:28:11 +00:00
|
|
|
old_title = button->title;
|
|
|
|
button->title = g_strdup (title);
|
2003-07-01 19:52:07 +00:00
|
|
|
g_free (old_title);
|
|
|
|
|
2020-04-13 04:28:11 +00:00
|
|
|
if (button->cs_dialog)
|
|
|
|
gtk_window_set_title (GTK_WINDOW (button->cs_dialog), button->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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-25 23:22:09 +00:00
|
|
|
* gtk_color_button_get_title: (attributes org.gtk.Method.get_property=title)
|
2021-02-22 00:42:17 +00:00
|
|
|
* @button: a `GtkColorButton`
|
2003-07-01 19:52:07 +00:00
|
|
|
*
|
2021-02-22 00:42:17 +00:00
|
|
|
* Gets the title of the color chooser dialog.
|
2003-07-01 19:52:07 +00:00
|
|
|
*
|
|
|
|
* Returns: An internal string, do not free the return value
|
|
|
|
*/
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *
|
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
|
|
|
|
2020-04-13 04:28:11 +00:00
|
|
|
return button->title;
|
2003-07-01 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
2020-04-13 04:17:00 +00:00
|
|
|
/**
|
2021-02-25 23:22:09 +00:00
|
|
|
* gtk_color_button_set_modal: (attributes org.gtk.Method.set_property=modal)
|
2021-02-22 00:42:17 +00:00
|
|
|
* @button: a `GtkColorButton`
|
2020-04-13 04:17:00 +00:00
|
|
|
* @modal: %TRUE to make the dialog modal
|
|
|
|
*
|
|
|
|
* Sets whether the dialog should be modal.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_color_button_set_modal (GtkColorButton *button,
|
|
|
|
gboolean modal)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_COLOR_BUTTON (button));
|
|
|
|
|
2020-04-13 04:28:11 +00:00
|
|
|
if (button->modal == modal)
|
2020-04-13 04:17:00 +00:00
|
|
|
return;
|
|
|
|
|
2020-04-13 04:28:11 +00:00
|
|
|
button->modal = modal;
|
2020-04-13 04:17:00 +00:00
|
|
|
|
2020-04-13 04:28:11 +00:00
|
|
|
if (button->cs_dialog)
|
|
|
|
gtk_window_set_modal (GTK_WINDOW (button->cs_dialog), button->modal);
|
2020-04-13 04:17:00 +00:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (button), "modal");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-25 23:22:09 +00:00
|
|
|
* gtk_color_button_get_modal: (attributes org.gtk.Method.get_property=modal)
|
2021-02-22 00:42:17 +00:00
|
|
|
* @button: a `GtkColorButton`
|
2020-04-13 04:17:00 +00:00
|
|
|
*
|
|
|
|
* Gets whether the dialog is modal.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the dialog is modal
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gtk_color_button_get_modal (GtkColorButton *button)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_COLOR_BUTTON (button), FALSE);
|
|
|
|
|
2020-04-13 04:28:11 +00:00
|
|
|
return button->modal;
|
2020-04-13 04:17:00 +00:00
|
|
|
}
|
|
|
|
|
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:
|
2014-05-05 18:22:52 +00:00
|
|
|
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;
|
2010-10-22 15:58:24 +00:00
|
|
|
case PROP_RGBA:
|
2014-05-02 22:42:18 +00:00
|
|
|
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (button), g_value_get_boxed (value));
|
2010-10-22 15:58:24 +00:00
|
|
|
break;
|
2016-01-27 02:27:12 +00:00
|
|
|
case PROP_SHOW_EDITOR:
|
|
|
|
{
|
|
|
|
gboolean show_editor = g_value_get_boolean (value);
|
2020-04-13 04:28:11 +00:00
|
|
|
if (button->show_editor != show_editor)
|
2016-01-27 02:27:12 +00:00
|
|
|
{
|
2020-04-13 04:28:11 +00:00
|
|
|
button->show_editor = show_editor;
|
2016-01-27 02:27:12 +00:00
|
|
|
g_object_notify (object, "show-editor");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2020-04-13 04:17:00 +00:00
|
|
|
case PROP_MODAL:
|
|
|
|
gtk_color_button_set_modal (button, g_value_get_boolean (value));
|
|
|
|
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:
|
2020-04-13 04:28:11 +00:00
|
|
|
g_value_set_boolean (value, button->use_alpha);
|
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;
|
2010-10-22 15:58:24 +00:00
|
|
|
case PROP_RGBA:
|
|
|
|
{
|
|
|
|
GdkRGBA rgba;
|
|
|
|
|
2014-05-02 22:42:18 +00:00
|
|
|
gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (button), &rgba);
|
2010-10-22 15:58:24 +00:00
|
|
|
g_value_set_boxed (value, &rgba);
|
|
|
|
}
|
|
|
|
break;
|
2016-01-27 02:27:12 +00:00
|
|
|
case PROP_SHOW_EDITOR:
|
2020-04-13 04:28:11 +00:00
|
|
|
g_value_set_boolean (value, button->show_editor);
|
2016-01-27 02:27:12 +00:00
|
|
|
break;
|
2020-04-13 04:17:00 +00:00
|
|
|
case PROP_MODAL:
|
2020-04-13 04:28:11 +00:00
|
|
|
g_value_set_boolean (value, button->modal);
|
2020-04-13 04:17:00 +00:00
|
|
|
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,
|
2012-03-07 02:07:02 +00:00
|
|
|
GtkOrientation orientation,
|
2020-07-24 13:54:49 +00:00
|
|
|
int colors_per_line,
|
|
|
|
int n_colors,
|
2012-02-04 06:45:55 +00:00
|
|
|
GdkRGBA *colors)
|
|
|
|
{
|
|
|
|
GtkColorButton *button = GTK_COLOR_BUTTON (chooser);
|
|
|
|
|
2012-12-03 22:46:18 +00:00
|
|
|
ensure_dialog (button);
|
|
|
|
|
2020-04-13 04:28:11 +00:00
|
|
|
gtk_color_chooser_add_palette (GTK_COLOR_CHOOSER (button->cs_dialog),
|
2014-07-10 01:08:18 +00:00
|
|
|
orientation, colors_per_line, n_colors, colors);
|
2012-02-04 06:45:55 +00:00
|
|
|
}
|
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
static void
|
|
|
|
gtk_color_button_iface_init (GtkColorChooserInterface *iface)
|
|
|
|
{
|
2016-10-11 11:10:02 +00:00
|
|
|
iface->get_rgba = gtk_color_button_get_rgba;
|
|
|
|
iface->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
|
|
|
}
|