2012-01-29 15:42:34 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2012-01-29 15:42:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2022-10-27 01:52:06 +00:00
|
|
|
#include "deprecated/gtkcolorchooserprivate.h"
|
|
|
|
#include "deprecated/gtkcolorchooserwidget.h"
|
2012-02-09 00:36:10 +00:00
|
|
|
#include "gtkcoloreditorprivate.h"
|
|
|
|
#include "gtkcolorswatchprivate.h"
|
2012-01-29 15:42:34 +00:00
|
|
|
#include "gtkgrid.h"
|
|
|
|
#include "gtklabel.h"
|
|
|
|
#include "gtkorientable.h"
|
2012-02-01 06:53:08 +00:00
|
|
|
#include "gtkprivate.h"
|
2022-09-24 13:07:56 +00:00
|
|
|
#include <glib/gi18n-lib.h>
|
2012-02-03 06:41:45 +00:00
|
|
|
#include "gtksizegroup.h"
|
2019-07-31 14:55:12 +00:00
|
|
|
#include "gtkboxlayout.h"
|
2020-04-08 11:43:28 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2020-09-11 13:31:17 +00:00
|
|
|
#include "gdkrgbaprivate.h"
|
2012-01-29 15:42:34 +00:00
|
|
|
|
2012-02-09 04:21:41 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
2022-10-27 01:52:06 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
|
|
|
|
2012-02-04 00:40:36 +00:00
|
|
|
/**
|
2021-02-26 16:26:09 +00:00
|
|
|
* GtkColorChooserWidget:
|
2012-02-04 00:40:36 +00:00
|
|
|
*
|
2021-02-26 16:26:09 +00:00
|
|
|
* The `GtkColorChooserWidget` widget lets the user select a color.
|
|
|
|
*
|
|
|
|
* By default, the chooser presents a predefined palette of colors,
|
|
|
|
* plus a small number of settable custom colors. It is also possible
|
|
|
|
* to select a different color with the single-color editor.
|
|
|
|
*
|
|
|
|
* To enter the single-color editing mode, use the context menu of any
|
|
|
|
* color of the palette, or use the '+' button to add a new custom color.
|
2012-02-04 00:40:36 +00:00
|
|
|
*
|
|
|
|
* The chooser automatically remembers the last selection, as well
|
|
|
|
* as custom colors.
|
|
|
|
*
|
2021-02-26 16:26:09 +00:00
|
|
|
* To create a `GtkColorChooserWidget`, use [ctor@Gtk.ColorChooserWidget.new].
|
|
|
|
*
|
|
|
|
* To change the initially selected color, use
|
|
|
|
* [method@Gtk.ColorChooser.set_rgba]. To get the selected color use
|
|
|
|
* [method@Gtk.ColorChooser.get_rgba].
|
2012-02-04 00:40:36 +00:00
|
|
|
*
|
2021-02-26 16:26:09 +00:00
|
|
|
* The `GtkColorChooserWidget` is used in the [class@Gtk.ColorChooserDialog]
|
2012-02-04 00:40:36 +00:00
|
|
|
* to provide a dialog for selecting colors.
|
|
|
|
*
|
2016-01-14 04:34:03 +00:00
|
|
|
* # CSS names
|
|
|
|
*
|
2021-02-26 16:26:09 +00:00
|
|
|
* `GtkColorChooserWidget` has a single CSS node with name colorchooser.
|
2022-10-27 01:52:06 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 4.10: Direct use of `GtkColorChooserWidget` is deprecated.
|
2012-02-04 00:40:36 +00:00
|
|
|
*/
|
|
|
|
|
2019-05-28 00:04:01 +00:00
|
|
|
typedef struct _GtkColorChooserWidgetClass GtkColorChooserWidgetClass;
|
|
|
|
|
|
|
|
struct _GtkColorChooserWidget
|
|
|
|
{
|
2019-07-31 14:55:12 +00:00
|
|
|
GtkWidget parent_instance;
|
2019-05-28 00:04:01 +00:00
|
|
|
|
2012-01-29 15:42:34 +00:00
|
|
|
GtkWidget *palette;
|
|
|
|
GtkWidget *editor;
|
2012-02-04 05:02:49 +00:00
|
|
|
GtkSizeGroup *size_group;
|
2012-01-29 15:42:34 +00:00
|
|
|
|
2012-02-04 06:45:55 +00:00
|
|
|
GtkWidget *custom_label;
|
2012-01-29 15:42:34 +00:00
|
|
|
GtkWidget *custom;
|
|
|
|
|
2012-01-31 05:31:41 +00:00
|
|
|
GtkWidget *button;
|
2012-01-29 15:42:34 +00:00
|
|
|
GtkColorSwatch *current;
|
|
|
|
|
2012-02-04 05:02:49 +00:00
|
|
|
gboolean use_alpha;
|
2012-02-04 06:45:55 +00:00
|
|
|
gboolean has_default_palette;
|
2012-02-03 06:41:45 +00:00
|
|
|
|
2012-01-29 15:42:34 +00:00
|
|
|
GSettings *settings;
|
2020-09-11 12:42:03 +00:00
|
|
|
|
|
|
|
int max_custom;
|
2012-01-29 15:42:34 +00:00
|
|
|
};
|
|
|
|
|
2020-03-28 21:09:52 +00:00
|
|
|
struct _GtkColorChooserWidgetClass
|
|
|
|
{
|
|
|
|
GtkWidgetClass parent_class;
|
|
|
|
};
|
|
|
|
|
2012-01-29 15:42:34 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_ZERO,
|
2012-02-03 23:34:33 +00:00
|
|
|
PROP_RGBA,
|
|
|
|
PROP_USE_ALPHA,
|
2012-02-01 06:53:08 +00:00
|
|
|
PROP_SHOW_EDITOR
|
2012-01-29 15:42:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void gtk_color_chooser_widget_iface_init (GtkColorChooserInterface *iface);
|
|
|
|
|
2019-07-31 14:55:12 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkColorChooserWidget, gtk_color_chooser_widget, GTK_TYPE_WIDGET,
|
2012-01-29 15:42:34 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_COLOR_CHOOSER,
|
|
|
|
gtk_color_chooser_widget_iface_init))
|
|
|
|
|
|
|
|
static void
|
|
|
|
select_swatch (GtkColorChooserWidget *cc,
|
|
|
|
GtkColorSwatch *swatch)
|
|
|
|
{
|
2012-01-30 23:37:00 +00:00
|
|
|
GdkRGBA color;
|
2020-02-22 00:56:44 +00:00
|
|
|
double red, green, blue, alpha;
|
2012-01-30 23:37:00 +00:00
|
|
|
|
2020-03-28 21:09:52 +00:00
|
|
|
if (cc->current == swatch)
|
2012-01-29 15:42:34 +00:00
|
|
|
return;
|
2012-02-04 05:02:49 +00:00
|
|
|
|
2020-03-28 21:09:52 +00:00
|
|
|
if (cc->current != NULL)
|
|
|
|
gtk_widget_unset_state_flags (GTK_WIDGET (cc->current), GTK_STATE_FLAG_SELECTED);
|
2014-04-12 08:09:46 +00:00
|
|
|
|
2012-02-09 04:48:11 +00:00
|
|
|
gtk_widget_set_state_flags (GTK_WIDGET (swatch), GTK_STATE_FLAG_SELECTED, FALSE);
|
2020-03-28 21:09:52 +00:00
|
|
|
cc->current = swatch;
|
2012-02-04 05:02:49 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_swatch_get_rgba (swatch, &color);
|
2016-01-22 21:25:29 +00:00
|
|
|
|
2020-02-22 00:56:44 +00:00
|
|
|
red = color.red;
|
|
|
|
green = color.green;
|
|
|
|
blue = color.blue;
|
|
|
|
alpha = color.alpha;
|
2020-03-28 21:09:52 +00:00
|
|
|
g_settings_set (cc->settings, "selected-color", "(bdddd)",
|
2020-02-22 00:56:44 +00:00
|
|
|
TRUE, red, green, blue, alpha);
|
2012-01-30 23:37:00 +00:00
|
|
|
|
2020-03-28 21:09:52 +00:00
|
|
|
if (gtk_widget_get_visible (GTK_WIDGET (cc->editor)))
|
|
|
|
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (cc->editor), &color);
|
2016-01-22 21:25:29 +00:00
|
|
|
else
|
|
|
|
g_object_notify (G_OBJECT (cc), "rgba");
|
2012-01-29 15:42:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
swatch_selected (GtkColorSwatch *swatch,
|
2012-02-09 04:48:11 +00:00
|
|
|
GtkStateFlags previous,
|
2012-01-29 15:42:34 +00:00
|
|
|
GtkColorChooserWidget *cc)
|
|
|
|
{
|
2012-02-09 04:48:11 +00:00
|
|
|
GtkStateFlags flags;
|
|
|
|
|
|
|
|
flags = gtk_widget_get_state_flags (GTK_WIDGET (swatch));
|
|
|
|
if ((flags & GTK_STATE_FLAG_SELECTED) != (previous & GTK_STATE_FLAG_SELECTED) &&
|
|
|
|
(flags & GTK_STATE_FLAG_SELECTED) != 0)
|
|
|
|
select_swatch (cc, swatch);
|
2012-01-29 15:42:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-04 05:02:49 +00:00
|
|
|
connect_swatch_signals (GtkWidget *p,
|
|
|
|
gpointer data)
|
2012-01-29 15:42:34 +00:00
|
|
|
{
|
2012-02-09 04:48:11 +00:00
|
|
|
g_signal_connect (p, "state-flags-changed", G_CALLBACK (swatch_selected), data);
|
2012-01-29 15:42:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-04 05:02:49 +00:00
|
|
|
connect_button_signals (GtkWidget *p,
|
|
|
|
gpointer data)
|
2012-01-29 15:42:34 +00:00
|
|
|
{
|
2019-06-12 03:02:15 +00:00
|
|
|
// g_signal_connect (p, "activate", G_CALLBACK (button_activate), data);
|
2012-01-29 15:42:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-01-31 05:31:41 +00:00
|
|
|
save_custom_colors (GtkColorChooserWidget *cc)
|
2012-01-29 15:42:34 +00:00
|
|
|
{
|
|
|
|
GVariantBuilder builder;
|
|
|
|
GVariant *variant;
|
|
|
|
GdkRGBA color;
|
2012-01-31 05:31:41 +00:00
|
|
|
GtkWidget *child;
|
2020-05-09 12:26:52 +00:00
|
|
|
gboolean first;
|
2012-01-29 15:42:34 +00:00
|
|
|
|
|
|
|
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(dddd)"));
|
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
for (child = gtk_widget_get_first_child (cc->custom), first = TRUE;
|
|
|
|
child != NULL;
|
|
|
|
child = gtk_widget_get_next_sibling (child), first = FALSE)
|
2012-01-29 15:42:34 +00:00
|
|
|
{
|
2020-05-09 12:26:52 +00:00
|
|
|
if (first)
|
|
|
|
continue;
|
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
if (gtk_color_swatch_get_rgba (GTK_COLOR_SWATCH (child), &color))
|
2020-02-22 00:56:44 +00:00
|
|
|
{
|
|
|
|
double red, green, blue, alpha;
|
|
|
|
|
|
|
|
red = color.red;
|
|
|
|
green = color.green;
|
|
|
|
blue = color.blue;
|
|
|
|
alpha = color.alpha;
|
|
|
|
g_variant_builder_add (&builder, "(dddd)", red, green, blue, alpha);
|
|
|
|
}
|
2012-01-29 15:42:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
variant = g_variant_builder_end (&builder);
|
2020-03-28 21:09:52 +00:00
|
|
|
g_settings_set_value (cc->settings, "custom-colors", variant);
|
2012-01-29 15:42:34 +00:00
|
|
|
}
|
|
|
|
|
2012-02-04 05:02:49 +00:00
|
|
|
static void
|
|
|
|
connect_custom_signals (GtkWidget *p,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
connect_swatch_signals (p, data);
|
|
|
|
g_signal_connect_swapped (p, "notify::rgba",
|
|
|
|
G_CALLBACK (save_custom_colors), data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_color_chooser_widget_set_use_alpha (GtkColorChooserWidget *cc,
|
|
|
|
gboolean use_alpha)
|
|
|
|
{
|
2020-05-07 18:23:36 +00:00
|
|
|
GtkWidget *child;
|
2012-02-04 06:45:55 +00:00
|
|
|
GtkWidget *grid;
|
2012-02-04 05:02:49 +00:00
|
|
|
|
2020-03-28 21:09:52 +00:00
|
|
|
if (cc->use_alpha == use_alpha)
|
2014-06-08 15:31:54 +00:00
|
|
|
return;
|
|
|
|
|
2020-03-28 21:09:52 +00:00
|
|
|
cc->use_alpha = use_alpha;
|
|
|
|
gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER (cc->editor), use_alpha);
|
2012-02-04 05:02:49 +00:00
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
for (grid = gtk_widget_get_first_child (cc->palette);
|
|
|
|
grid != NULL;
|
|
|
|
grid = gtk_widget_get_next_sibling (grid))
|
2012-02-04 05:02:49 +00:00
|
|
|
{
|
2020-05-07 18:23:36 +00:00
|
|
|
for (child = gtk_widget_get_first_child (grid);
|
|
|
|
child != NULL;
|
|
|
|
child = gtk_widget_get_next_sibling (child))
|
2012-02-04 05:02:49 +00:00
|
|
|
{
|
2020-05-07 18:23:36 +00:00
|
|
|
if (GTK_IS_COLOR_SWATCH (child))
|
|
|
|
gtk_color_swatch_set_use_alpha (GTK_COLOR_SWATCH (child), use_alpha);
|
2012-02-04 05:02:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (cc));
|
2014-06-08 15:31:54 +00:00
|
|
|
g_object_notify (G_OBJECT (cc), "use-alpha");
|
2012-02-04 05:02:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_color_chooser_widget_set_show_editor (GtkColorChooserWidget *cc,
|
|
|
|
gboolean show_editor)
|
|
|
|
{
|
|
|
|
if (show_editor)
|
|
|
|
{
|
|
|
|
GdkRGBA color = { 0.75, 0.25, 0.25, 1.0 };
|
|
|
|
|
2020-03-28 21:09:52 +00:00
|
|
|
if (cc->current)
|
|
|
|
gtk_color_swatch_get_rgba (cc->current, &color);
|
|
|
|
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (cc->editor), &color);
|
2012-02-04 05:02:49 +00:00
|
|
|
}
|
|
|
|
|
2020-03-28 21:09:52 +00:00
|
|
|
gtk_widget_set_visible (cc->editor, show_editor);
|
|
|
|
gtk_widget_set_visible (cc->palette, !show_editor);
|
2012-02-04 05:02:49 +00:00
|
|
|
}
|
|
|
|
|
2014-05-21 23:23:56 +00:00
|
|
|
static void
|
|
|
|
update_from_editor (GtkColorEditor *editor,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GtkColorChooserWidget *widget)
|
|
|
|
{
|
2014-05-22 10:29:24 +00:00
|
|
|
if (gtk_widget_get_visible (GTK_WIDGET (editor)))
|
2014-05-21 23:23:56 +00:00
|
|
|
g_object_notify (G_OBJECT (widget), "rgba");
|
|
|
|
}
|
|
|
|
|
2012-02-04 05:02:49 +00:00
|
|
|
/* UI construction {{{1 */
|
|
|
|
|
2012-03-04 05:28:08 +00:00
|
|
|
static void
|
|
|
|
remove_palette (GtkColorChooserWidget *cc)
|
|
|
|
{
|
|
|
|
GList *children, *l;
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
2020-03-28 21:09:52 +00:00
|
|
|
if (cc->current != NULL &&
|
|
|
|
gtk_widget_get_parent (GTK_WIDGET (cc->current)) != cc->custom)
|
|
|
|
cc->current = NULL;
|
2013-02-17 15:01:06 +00:00
|
|
|
|
2020-05-07 18:23:36 +00:00
|
|
|
children = NULL;
|
|
|
|
for (widget = gtk_widget_get_first_child (cc->palette);
|
|
|
|
widget != NULL;
|
|
|
|
widget = gtk_widget_get_next_sibling (widget))
|
|
|
|
children = g_list_prepend (children, widget);
|
|
|
|
|
2012-03-04 05:28:08 +00:00
|
|
|
for (l = children; l; l = l->next)
|
|
|
|
{
|
|
|
|
widget = l->data;
|
2020-03-28 21:09:52 +00:00
|
|
|
if (widget == cc->custom_label || widget == cc->custom)
|
2012-03-04 05:28:08 +00:00
|
|
|
continue;
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_remove (GTK_BOX (cc->palette), widget);
|
2012-03-04 05:28:08 +00:00
|
|
|
}
|
|
|
|
g_list_free (children);
|
|
|
|
}
|
2012-02-12 00:03:45 +00:00
|
|
|
|
2020-10-07 19:56:11 +00:00
|
|
|
static guint
|
|
|
|
scale_round (double value,
|
|
|
|
double scale)
|
|
|
|
{
|
|
|
|
value = floor (value * scale + 0.5);
|
|
|
|
value = MAX (value, 0);
|
|
|
|
value = MIN (value, scale);
|
|
|
|
return (guint)value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
accessible_color_name (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));
|
|
|
|
}
|
|
|
|
|
2012-01-29 15:42:34 +00:00
|
|
|
static void
|
2012-02-09 04:21:41 +00:00
|
|
|
add_palette (GtkColorChooserWidget *cc,
|
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,
|
2020-10-07 19:56:11 +00:00
|
|
|
GdkRGBA *colors,
|
|
|
|
const char **names)
|
2012-01-29 15:42:34 +00:00
|
|
|
{
|
|
|
|
GtkWidget *grid;
|
|
|
|
GtkWidget *p;
|
2020-07-24 13:54:49 +00:00
|
|
|
int line, pos;
|
|
|
|
int i;
|
|
|
|
int left, right;
|
2012-02-04 06:45:55 +00:00
|
|
|
|
2012-03-04 05:28:08 +00:00
|
|
|
if (colors == NULL)
|
|
|
|
{
|
|
|
|
remove_palette (cc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-04 06:45:55 +00:00
|
|
|
grid = gtk_grid_new ();
|
|
|
|
gtk_widget_set_margin_bottom (grid, 12);
|
|
|
|
gtk_grid_set_row_spacing (GTK_GRID (grid), 2);
|
|
|
|
gtk_grid_set_column_spacing (GTK_GRID (grid), 4);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (cc->palette), grid);
|
2012-02-04 06:45:55 +00:00
|
|
|
|
|
|
|
left = 0;
|
|
|
|
right = colors_per_line - 1;
|
|
|
|
if (gtk_widget_get_direction (GTK_WIDGET (cc)) == GTK_TEXT_DIR_RTL)
|
|
|
|
{
|
|
|
|
i = left;
|
|
|
|
left = right;
|
|
|
|
right = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < n_colors; i++)
|
|
|
|
{
|
|
|
|
p = gtk_color_swatch_new ();
|
2020-10-07 19:56:11 +00:00
|
|
|
if (names)
|
|
|
|
{
|
|
|
|
gtk_accessible_update_property (GTK_ACCESSIBLE (p),
|
|
|
|
GTK_ACCESSIBLE_PROPERTY_LABEL,
|
|
|
|
g_dpgettext2 (GETTEXT_PACKAGE, "Color name", names[i]),
|
|
|
|
-1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
char *text;
|
|
|
|
|
|
|
|
name = accessible_color_name (&colors[i]);
|
|
|
|
text = g_strdup_printf (_("Color: %s"), name);
|
|
|
|
gtk_accessible_update_property (GTK_ACCESSIBLE (p),
|
|
|
|
GTK_ACCESSIBLE_PROPERTY_LABEL, text,
|
|
|
|
-1);
|
|
|
|
g_free (name);
|
|
|
|
g_free (text);
|
|
|
|
}
|
2012-02-04 06:45:55 +00:00
|
|
|
gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (p), &colors[i]);
|
|
|
|
connect_swatch_signals (p, cc);
|
|
|
|
|
|
|
|
line = i / colors_per_line;
|
|
|
|
pos = i % colors_per_line;
|
|
|
|
|
2012-03-07 02:07:02 +00:00
|
|
|
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
2012-02-04 06:45:55 +00:00
|
|
|
{
|
2020-01-29 11:11:39 +00:00
|
|
|
if (pos == left)
|
2020-08-13 23:49:02 +00:00
|
|
|
gtk_widget_add_css_class (p, "left");
|
2020-01-29 11:11:39 +00:00
|
|
|
else if (pos == right)
|
2020-08-13 23:49:02 +00:00
|
|
|
gtk_widget_add_css_class (p, "right");
|
2012-02-08 22:38:20 +00:00
|
|
|
|
2020-01-29 11:11:39 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), p, pos, line, 1, 1);
|
2012-02-04 06:45:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (pos == 0)
|
2020-08-13 23:49:02 +00:00
|
|
|
gtk_widget_add_css_class (p, "top");
|
2012-02-04 06:45:55 +00:00
|
|
|
else if (pos == colors_per_line - 1)
|
2020-08-13 23:49:02 +00:00
|
|
|
gtk_widget_add_css_class (p, "bottom");
|
2012-02-08 22:38:20 +00:00
|
|
|
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), p, line, pos, 1, 1);
|
2012-02-04 06:45:55 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-11 12:42:03 +00:00
|
|
|
|
|
|
|
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
|
|
cc->max_custom = MAX (cc->max_custom, colors_per_line);
|
|
|
|
else
|
|
|
|
cc->max_custom = MAX (cc->max_custom, n_colors / colors_per_line);
|
2012-02-04 06:45:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
remove_default_palette (GtkColorChooserWidget *cc)
|
|
|
|
{
|
2020-03-28 21:09:52 +00:00
|
|
|
if (!cc->has_default_palette)
|
2012-02-04 06:45:55 +00:00
|
|
|
return;
|
|
|
|
|
2012-03-04 05:28:08 +00:00
|
|
|
remove_palette (cc);
|
2020-03-28 21:09:52 +00:00
|
|
|
cc->has_default_palette = FALSE;
|
2020-09-11 12:42:03 +00:00
|
|
|
cc->max_custom = 0;
|
2012-02-04 06:45:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_default_palette (GtkColorChooserWidget *cc)
|
|
|
|
{
|
2020-09-13 21:59:26 +00:00
|
|
|
GdkRGBA colors[9*5] = {
|
|
|
|
GDK_RGBA("99c1f1"), GDK_RGBA("62a0ea"), GDK_RGBA("3584e4"), GDK_RGBA("1c71d8"), GDK_RGBA("1a5fb4"), /* Blue */
|
|
|
|
GDK_RGBA("8ff0a4"), GDK_RGBA("57e389"), GDK_RGBA("33d17a"), GDK_RGBA("2ec27e"), GDK_RGBA("26a269"), /* Green */
|
|
|
|
GDK_RGBA("f9f06b"), GDK_RGBA("f8e45c"), GDK_RGBA("f6d32d"), GDK_RGBA("f5c211"), GDK_RGBA("e5a50a"), /* Yellow */
|
|
|
|
GDK_RGBA("ffbe6f"), GDK_RGBA("ffa348"), GDK_RGBA("ff7800"), GDK_RGBA("e66100"), GDK_RGBA("c64600"), /* Orange */
|
|
|
|
GDK_RGBA("f66151"), GDK_RGBA("ed333b"), GDK_RGBA("e01b24"), GDK_RGBA("c01c28"), GDK_RGBA("a51d2d"), /* Red */
|
|
|
|
GDK_RGBA("dc8add"), GDK_RGBA("c061cb"), GDK_RGBA("9141ac"), GDK_RGBA("813d9c"), GDK_RGBA("613583"), /* Purple */
|
|
|
|
GDK_RGBA("cdab8f"), GDK_RGBA("b5835a"), GDK_RGBA("986a44"), GDK_RGBA("865e3c"), GDK_RGBA("63452c"), /* Brown */
|
|
|
|
GDK_RGBA("ffffff"), GDK_RGBA("f6f5f4"), GDK_RGBA("deddda"), GDK_RGBA("c0bfbc"), GDK_RGBA("9a9996"), /* Light */
|
|
|
|
GDK_RGBA("77767b"), GDK_RGBA("5e5c64"), GDK_RGBA("3d3846"), GDK_RGBA("241f31"), GDK_RGBA("000000") /* Dark */
|
2012-01-29 15:42:34 +00:00
|
|
|
};
|
2020-10-07 19:56:11 +00:00
|
|
|
const char *color_names[] = {
|
|
|
|
NC_("Color name", "Very Light Blue"),
|
|
|
|
NC_("Color name", "Light Blue"),
|
|
|
|
NC_("Color name", "Blue"),
|
|
|
|
NC_("Color name", "Dark Blue"),
|
|
|
|
NC_("Color name", "Very Dark Blue"),
|
|
|
|
NC_("Color name", "Very Light Green"),
|
|
|
|
NC_("Color name", "Light Green"),
|
|
|
|
NC_("Color name", "Green"),
|
|
|
|
NC_("Color name", "Dark Green"),
|
|
|
|
NC_("Color name", "Very Dark Green"),
|
|
|
|
NC_("Color name", "Very Light Yellow"),
|
|
|
|
NC_("Color name", "Light Yellow"),
|
|
|
|
NC_("Color name", "Yellow"),
|
|
|
|
NC_("Color name", "Dark Yellow"),
|
|
|
|
NC_("Color name", "Very Dark Yellow"),
|
|
|
|
NC_("Color name", "Very Light Orange"),
|
|
|
|
NC_("Color name", "Light Orange"),
|
|
|
|
NC_("Color name", "Orange"),
|
|
|
|
NC_("Color name", "Dark Orange"),
|
|
|
|
NC_("Color name", "Very Dark Orange"),
|
|
|
|
NC_("Color name", "Very Light Red"),
|
|
|
|
NC_("Color name", "Light Red"),
|
|
|
|
NC_("Color name", "Red"),
|
|
|
|
NC_("Color name", "Dark Red"),
|
|
|
|
NC_("Color name", "Very Dark Red"),
|
|
|
|
NC_("Color name", "Very Light Purple"),
|
|
|
|
NC_("Color name", "Light Purple"),
|
|
|
|
NC_("Color name", "Purple"),
|
|
|
|
NC_("Color name", "Dark Purple"),
|
|
|
|
NC_("Color name", "Very Dark Purple"),
|
|
|
|
NC_("Color name", "Very Light Brown"),
|
|
|
|
NC_("Color name", "Light Brown"),
|
|
|
|
NC_("Color name", "Brown"),
|
|
|
|
NC_("Color name", "Dark Brown"),
|
|
|
|
NC_("Color name", "Very Dark Brown"),
|
|
|
|
NC_("Color name", "White"),
|
|
|
|
NC_("Color name", "Light Gray 1"),
|
|
|
|
NC_("Color name", "Light Gray 2"),
|
|
|
|
NC_("Color name", "Light Gray 3"),
|
|
|
|
NC_("Color name", "Light Gray 4"),
|
|
|
|
NC_("Color name", "Dark Gray 1"),
|
|
|
|
NC_("Color name", "Dark Gray 2"),
|
|
|
|
NC_("Color name", "Dark Gray 3"),
|
|
|
|
NC_("Color name", "Dark Gray 4"),
|
|
|
|
NC_("Color name", "Black"),
|
|
|
|
};
|
2020-09-11 08:38:47 +00:00
|
|
|
|
2020-10-07 19:56:11 +00:00
|
|
|
add_palette (cc, GTK_ORIENTATION_VERTICAL, 5, 9*5, colors, color_names);
|
2012-01-29 15:42:34 +00:00
|
|
|
|
2020-03-28 21:09:52 +00:00
|
|
|
cc->has_default_palette = TRUE;
|
2012-02-04 06:45:55 +00:00
|
|
|
}
|
2012-01-29 15:42:34 +00:00
|
|
|
|
2019-06-12 03:02:15 +00:00
|
|
|
static void
|
2019-06-15 03:56:45 +00:00
|
|
|
gtk_color_chooser_widget_activate_color_customize (GtkWidget *widget,
|
|
|
|
const char *name,
|
|
|
|
GVariant *parameter)
|
2019-06-12 03:02:15 +00:00
|
|
|
{
|
2019-06-15 03:56:45 +00:00
|
|
|
GtkColorChooserWidget *cc = GTK_COLOR_CHOOSER_WIDGET (widget);
|
2020-02-22 00:56:44 +00:00
|
|
|
double red, green, blue, alpha;
|
2019-06-12 03:02:15 +00:00
|
|
|
GdkRGBA color;
|
|
|
|
|
2020-02-22 00:56:44 +00:00
|
|
|
g_variant_get (parameter, "(dddd)", &red, &green, &blue, &alpha);
|
|
|
|
color.red = red;
|
|
|
|
color.green = green;
|
|
|
|
color.blue = blue;
|
|
|
|
color.alpha = alpha;
|
2019-06-12 03:02:15 +00:00
|
|
|
|
2020-03-28 21:09:52 +00:00
|
|
|
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (cc->editor), &color);
|
2019-06-12 03:02:15 +00:00
|
|
|
|
2020-03-28 21:09:52 +00:00
|
|
|
gtk_widget_hide (cc->palette);
|
|
|
|
gtk_widget_show (cc->editor);
|
2019-06-12 03:02:15 +00:00
|
|
|
g_object_notify (G_OBJECT (cc), "show-editor");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-06-15 03:56:45 +00:00
|
|
|
gtk_color_chooser_widget_activate_color_select (GtkWidget *widget,
|
|
|
|
const char *name,
|
|
|
|
GVariant *parameter)
|
2019-06-12 03:02:15 +00:00
|
|
|
{
|
2019-06-15 03:56:45 +00:00
|
|
|
GtkColorChooserWidget *cc = GTK_COLOR_CHOOSER_WIDGET (widget);
|
2019-06-12 03:02:15 +00:00
|
|
|
GdkRGBA color;
|
2020-02-22 00:56:44 +00:00
|
|
|
double red, green, blue, alpha;
|
2019-06-12 03:02:15 +00:00
|
|
|
|
2020-02-22 00:56:44 +00:00
|
|
|
g_variant_get (parameter, "(dddd)", &red, &green, &blue, &alpha);
|
|
|
|
color.red = red;
|
|
|
|
color.green = green;
|
|
|
|
color.blue = blue;
|
|
|
|
color.alpha = alpha;
|
2019-06-12 03:02:15 +00:00
|
|
|
|
|
|
|
_gtk_color_chooser_color_activated (GTK_COLOR_CHOOSER (cc), &color);
|
|
|
|
}
|
|
|
|
|
2012-02-04 06:45:55 +00:00
|
|
|
static void
|
|
|
|
gtk_color_chooser_widget_init (GtkColorChooserWidget *cc)
|
|
|
|
{
|
2012-02-08 23:06:50 +00:00
|
|
|
GtkWidget *box;
|
2012-02-04 06:45:55 +00:00
|
|
|
GtkWidget *p;
|
|
|
|
GtkWidget *button;
|
|
|
|
GtkWidget *label;
|
2020-07-24 13:54:49 +00:00
|
|
|
int i;
|
2019-12-10 13:22:52 +00:00
|
|
|
double color[4];
|
|
|
|
GdkRGBA rgba;
|
2012-02-04 06:45:55 +00:00
|
|
|
GVariant *variant;
|
|
|
|
GVariantIter iter;
|
|
|
|
gboolean selected;
|
2020-10-07 19:56:11 +00:00
|
|
|
char *name;
|
|
|
|
char *text;
|
2012-01-29 15:42:34 +00:00
|
|
|
|
2020-03-28 21:09:52 +00:00
|
|
|
cc->use_alpha = TRUE;
|
2012-02-09 01:21:10 +00:00
|
|
|
|
2020-03-28 21:09:52 +00:00
|
|
|
cc->palette = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
|
|
|
gtk_widget_set_parent (cc->palette, GTK_WIDGET (cc));
|
2012-01-29 15:42:34 +00:00
|
|
|
|
2012-02-04 06:45:55 +00:00
|
|
|
add_default_palette (cc);
|
2012-01-29 15:42:34 +00:00
|
|
|
|
2012-02-04 06:45:55 +00:00
|
|
|
/* translators: label for the custom section in the color chooser */
|
2020-03-28 21:09:52 +00:00
|
|
|
cc->custom_label = label = gtk_label_new (_("Custom"));
|
2012-02-04 06:45:55 +00:00
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_START);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (cc->palette), label);
|
2018-12-26 07:20:34 +00:00
|
|
|
|
2020-03-28 21:09:52 +00:00
|
|
|
cc->custom = box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
|
2018-12-26 07:20:34 +00:00
|
|
|
g_object_set (box, "margin-top", 12, NULL);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (cc->palette), box);
|
2012-01-29 15:42:34 +00:00
|
|
|
|
2020-03-28 21:09:52 +00:00
|
|
|
cc->button = button = gtk_color_swatch_new ();
|
2012-02-20 12:53:10 +00:00
|
|
|
gtk_widget_set_name (button, "add-color-button");
|
2012-01-30 14:56:20 +00:00
|
|
|
connect_button_signals (button, cc);
|
|
|
|
gtk_color_swatch_set_icon (GTK_COLOR_SWATCH (button), "list-add-symbolic");
|
2014-01-05 15:54:43 +00:00
|
|
|
gtk_color_swatch_set_selectable (GTK_COLOR_SWATCH (button), FALSE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), button);
|
2012-01-29 15:42:34 +00:00
|
|
|
|
2020-03-28 21:09:52 +00:00
|
|
|
cc->settings = g_settings_new ("org.gtk.gtk4.Settings.ColorChooser");
|
|
|
|
variant = g_settings_get_value (cc->settings, I_("custom-colors"));
|
2012-01-29 15:42:34 +00:00
|
|
|
g_variant_iter_init (&iter, variant);
|
|
|
|
i = 0;
|
2012-02-04 06:45:55 +00:00
|
|
|
p = NULL;
|
2019-12-10 13:22:52 +00:00
|
|
|
while (g_variant_iter_loop (&iter, "(dddd)", &color[0], &color[1], &color[2], &color[3]))
|
2012-01-29 15:42:34 +00:00
|
|
|
{
|
|
|
|
i++;
|
|
|
|
p = gtk_color_swatch_new ();
|
2019-12-10 13:22:52 +00:00
|
|
|
|
|
|
|
rgba.red = color[0];
|
|
|
|
rgba.green = color[1];
|
|
|
|
rgba.blue = color[2];
|
|
|
|
rgba.alpha = color[3];
|
|
|
|
|
|
|
|
gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (p), &rgba);
|
2020-10-07 19:56:11 +00:00
|
|
|
|
|
|
|
name = accessible_color_name (&rgba);
|
|
|
|
text = g_strdup_printf (_("Custom color %d: %s"), i, name);
|
|
|
|
gtk_accessible_update_property (GTK_ACCESSIBLE (p),
|
|
|
|
GTK_ACCESSIBLE_PROPERTY_LABEL, text,
|
|
|
|
-1);
|
|
|
|
g_free (name);
|
|
|
|
g_free (text);
|
|
|
|
|
2012-01-29 15:42:34 +00:00
|
|
|
gtk_color_swatch_set_can_drop (GTK_COLOR_SWATCH (p), TRUE);
|
|
|
|
connect_custom_signals (p, cc);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), p);
|
2012-01-29 15:42:34 +00:00
|
|
|
|
2018-12-29 06:38:55 +00:00
|
|
|
if (i == 8)
|
2012-01-29 15:42:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
g_variant_unref (variant);
|
|
|
|
|
2020-03-28 21:09:52 +00:00
|
|
|
cc->editor = gtk_color_editor_new ();
|
|
|
|
gtk_widget_set_halign (cc->editor, GTK_ALIGN_CENTER);
|
|
|
|
gtk_widget_set_hexpand (cc->editor, TRUE);
|
|
|
|
g_signal_connect (cc->editor, "notify::rgba",
|
2014-05-21 23:23:56 +00:00
|
|
|
G_CALLBACK (update_from_editor), cc);
|
2012-02-09 20:10:21 +00:00
|
|
|
|
2020-03-28 21:09:52 +00:00
|
|
|
gtk_widget_set_parent (cc->editor, GTK_WIDGET (cc));
|
2012-01-29 15:42:34 +00:00
|
|
|
|
2020-03-28 21:09:52 +00:00
|
|
|
g_settings_get (cc->settings, I_("selected-color"), "(bdddd)",
|
2012-01-29 15:42:34 +00:00
|
|
|
&selected,
|
2019-12-10 13:22:52 +00:00
|
|
|
&color[0], &color[1], &color[2], &color[3]);
|
2012-01-29 15:42:34 +00:00
|
|
|
if (selected)
|
2019-12-10 13:22:52 +00:00
|
|
|
{
|
|
|
|
rgba.red = color[0];
|
|
|
|
rgba.green = color[1];
|
|
|
|
rgba.blue = color[2];
|
|
|
|
rgba.alpha = color[3];
|
|
|
|
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (cc), &rgba);
|
|
|
|
}
|
2012-01-29 15:42:34 +00:00
|
|
|
|
2020-03-28 21:09:52 +00:00
|
|
|
gtk_widget_hide (GTK_WIDGET (cc->editor));
|
2012-01-29 15:42:34 +00:00
|
|
|
}
|
|
|
|
|
2012-02-04 05:02:49 +00:00
|
|
|
/* GObject implementation {{{1 */
|
|
|
|
|
2012-01-29 15:42:34 +00:00
|
|
|
static void
|
|
|
|
gtk_color_chooser_widget_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2020-03-28 21:09:52 +00:00
|
|
|
GtkColorChooserWidget *cc = GTK_COLOR_CHOOSER_WIDGET (object);
|
2012-01-29 15:42:34 +00:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2012-02-03 23:34:33 +00:00
|
|
|
case PROP_RGBA:
|
2012-01-29 15:42:34 +00:00
|
|
|
{
|
|
|
|
GdkRGBA color;
|
|
|
|
|
2020-03-28 21:09:52 +00:00
|
|
|
gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (cc), &color);
|
2012-01-29 15:42:34 +00:00
|
|
|
g_value_set_boxed (value, &color);
|
|
|
|
}
|
2012-01-31 07:05:37 +00:00
|
|
|
break;
|
2012-02-03 23:34:33 +00:00
|
|
|
case PROP_USE_ALPHA:
|
2020-03-28 21:09:52 +00:00
|
|
|
g_value_set_boolean (value, cc->use_alpha);
|
2012-01-31 07:05:37 +00:00
|
|
|
break;
|
2012-02-01 06:53:08 +00:00
|
|
|
case PROP_SHOW_EDITOR:
|
2020-03-28 21:09:52 +00:00
|
|
|
g_value_set_boolean (value, gtk_widget_get_visible (cc->editor));
|
2012-02-01 06:53:08 +00:00
|
|
|
break;
|
2012-01-29 15:42:34 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_color_chooser_widget_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkColorChooserWidget *cc = GTK_COLOR_CHOOSER_WIDGET (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2012-02-03 23:34:33 +00:00
|
|
|
case PROP_RGBA:
|
|
|
|
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (cc),
|
|
|
|
g_value_get_boxed (value));
|
2012-01-31 07:05:37 +00:00
|
|
|
break;
|
2012-02-03 23:34:33 +00:00
|
|
|
case PROP_USE_ALPHA:
|
|
|
|
gtk_color_chooser_widget_set_use_alpha (cc,
|
|
|
|
g_value_get_boolean (value));
|
2012-01-31 07:05:37 +00:00
|
|
|
break;
|
2012-02-01 06:53:08 +00:00
|
|
|
case PROP_SHOW_EDITOR:
|
|
|
|
gtk_color_chooser_widget_set_show_editor (cc,
|
|
|
|
g_value_get_boolean (value));
|
|
|
|
break;
|
2012-01-29 15:42:34 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_color_chooser_widget_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkColorChooserWidget *cc = GTK_COLOR_CHOOSER_WIDGET (object);
|
|
|
|
|
2020-03-28 21:09:52 +00:00
|
|
|
g_object_unref (cc->settings);
|
2012-01-29 15:42:34 +00:00
|
|
|
|
2020-03-28 21:09:52 +00:00
|
|
|
gtk_widget_unparent (cc->editor);
|
|
|
|
gtk_widget_unparent (cc->palette);
|
2019-07-31 14:55:12 +00:00
|
|
|
|
2012-01-29 15:42:34 +00:00
|
|
|
G_OBJECT_CLASS (gtk_color_chooser_widget_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_color_chooser_widget_class_init (GtkColorChooserWidgetClass *class)
|
|
|
|
{
|
2019-07-31 14:55:12 +00:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
|
2012-01-29 15:42:34 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
|
|
|
|
|
|
|
object_class->get_property = gtk_color_chooser_widget_get_property;
|
|
|
|
object_class->set_property = gtk_color_chooser_widget_set_property;
|
|
|
|
object_class->finalize = gtk_color_chooser_widget_finalize;
|
|
|
|
|
2020-04-08 11:43:28 +00:00
|
|
|
widget_class->grab_focus = gtk_widget_grab_focus_child;
|
|
|
|
widget_class->focus = gtk_widget_focus_child;
|
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
g_object_class_override_property (object_class, PROP_RGBA, "rgba");
|
|
|
|
g_object_class_override_property (object_class, PROP_USE_ALPHA, "use-alpha");
|
2012-01-29 15:42:34 +00:00
|
|
|
|
2012-02-04 00:40:36 +00:00
|
|
|
/**
|
|
|
|
* GtkColorChooserWidget:show-editor:
|
|
|
|
*
|
2021-02-26 16:26:09 +00:00
|
|
|
* %TRUE when the color chooser is showing the single-color editor.
|
|
|
|
*
|
|
|
|
* It can be set to switch the color chooser into single-color editing mode.
|
2012-02-04 00:40:36 +00:00
|
|
|
*/
|
2012-02-01 06:53:08 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_SHOW_EDITOR,
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_boolean ("show-editor", NULL, NULL,
|
2012-02-01 06:53:08 +00:00
|
|
|
FALSE, GTK_PARAM_READWRITE));
|
2016-01-14 04:34:03 +00:00
|
|
|
|
2019-07-31 14:55:12 +00:00
|
|
|
gtk_widget_class_set_css_name (widget_class, I_("colorchooser"));
|
|
|
|
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT);
|
2019-06-15 03:56:45 +00:00
|
|
|
|
2019-12-23 18:36:32 +00:00
|
|
|
/**
|
|
|
|
* GtkColorChooserWidget|color.select:
|
|
|
|
* @red: the red value, between 0 and 1
|
|
|
|
* @green: the green value, between 0 and 1
|
|
|
|
* @blue: the blue value, between 0 and 1
|
|
|
|
* @alpha: the alpha value, between 0 and 1
|
|
|
|
*
|
2021-02-26 16:26:09 +00:00
|
|
|
* Emits the [signal@Gtk.ColorChooser::color-activated] signal for
|
2019-12-23 18:36:32 +00:00
|
|
|
* the given color.
|
|
|
|
*/
|
2019-07-31 14:55:12 +00:00
|
|
|
gtk_widget_class_install_action (widget_class, "color.select", "(dddd)",
|
2019-06-22 18:24:46 +00:00
|
|
|
gtk_color_chooser_widget_activate_color_select);
|
2019-12-23 18:36:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkColorChooserWidget|color.customize:
|
|
|
|
* @red: the red value, between 0 and 1
|
|
|
|
* @green: the green value, between 0 and 1
|
|
|
|
* @blue: the blue value, between 0 and 1
|
|
|
|
* @alpha: the alpha value, between 0 and 1
|
|
|
|
*
|
|
|
|
* Activates the color editor for the given color.
|
|
|
|
*/
|
2019-07-31 14:55:12 +00:00
|
|
|
gtk_widget_class_install_action (widget_class, "color.customize", "(dddd)",
|
2019-06-22 18:24:46 +00:00
|
|
|
gtk_color_chooser_widget_activate_color_customize);
|
2012-01-29 15:42:34 +00:00
|
|
|
}
|
|
|
|
|
2012-02-04 05:02:49 +00:00
|
|
|
/* GtkColorChooser implementation {{{1 */
|
|
|
|
|
2012-01-29 15:42:34 +00:00
|
|
|
static void
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_chooser_widget_get_rgba (GtkColorChooser *chooser,
|
|
|
|
GdkRGBA *color)
|
2012-01-29 15:42:34 +00:00
|
|
|
{
|
|
|
|
GtkColorChooserWidget *cc = GTK_COLOR_CHOOSER_WIDGET (chooser);
|
|
|
|
|
2020-03-28 21:09:52 +00:00
|
|
|
if (gtk_widget_get_visible (cc->editor))
|
|
|
|
gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (cc->editor), color);
|
|
|
|
else if (cc->current)
|
|
|
|
gtk_color_swatch_get_rgba (cc->current, color);
|
2012-01-29 15:42:34 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
color->red = 1.0;
|
|
|
|
color->green = 1.0;
|
|
|
|
color->blue = 1.0;
|
|
|
|
color->alpha = 1.0;
|
|
|
|
}
|
2012-01-31 07:05:37 +00:00
|
|
|
|
2020-03-28 21:09:52 +00:00
|
|
|
if (!cc->use_alpha)
|
2012-01-31 07:05:37 +00:00
|
|
|
color->alpha = 1.0;
|
2012-01-29 15:42:34 +00:00
|
|
|
}
|
|
|
|
|
2012-01-31 05:31:41 +00:00
|
|
|
static void
|
|
|
|
add_custom_color (GtkColorChooserWidget *cc,
|
|
|
|
const GdkRGBA *color)
|
|
|
|
{
|
2020-05-09 12:26:52 +00:00
|
|
|
GtkWidget *widget;
|
|
|
|
GtkWidget *p;
|
2020-09-11 12:42:03 +00:00
|
|
|
int n;
|
2020-05-09 12:26:52 +00:00
|
|
|
|
2020-09-11 12:42:03 +00:00
|
|
|
n = 0;
|
2020-05-09 12:26:52 +00:00
|
|
|
for (widget = gtk_widget_get_first_child (cc->custom);
|
|
|
|
widget != NULL;
|
|
|
|
widget = gtk_widget_get_next_sibling (widget))
|
2020-09-11 12:42:03 +00:00
|
|
|
n++;
|
2012-01-31 05:31:41 +00:00
|
|
|
|
2020-09-11 12:42:03 +00:00
|
|
|
while (n >= cc->max_custom)
|
2012-02-01 07:00:21 +00:00
|
|
|
{
|
2020-03-28 21:09:52 +00:00
|
|
|
GtkWidget *last = gtk_widget_get_last_child (cc->custom);
|
2016-01-30 21:31:27 +00:00
|
|
|
|
2020-04-16 21:08:31 +00:00
|
|
|
if (last == (GtkWidget *)cc->current)
|
|
|
|
cc->current = NULL;
|
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_remove (GTK_BOX (cc->custom), last);
|
2020-09-11 12:42:03 +00:00
|
|
|
n--;
|
2012-02-01 07:00:21 +00:00
|
|
|
}
|
2012-01-31 05:31:41 +00:00
|
|
|
|
|
|
|
p = gtk_color_swatch_new ();
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (p), color);
|
2012-01-31 05:31:41 +00:00
|
|
|
gtk_color_swatch_set_can_drop (GTK_COLOR_SWATCH (p), TRUE);
|
|
|
|
connect_custom_signals (p, cc);
|
|
|
|
|
2020-03-28 21:09:52 +00:00
|
|
|
gtk_box_insert_child_after (GTK_BOX (cc->custom), p, gtk_widget_get_first_child (cc->custom));
|
2012-01-31 05:31:41 +00:00
|
|
|
gtk_widget_show (p);
|
|
|
|
|
|
|
|
select_swatch (cc, GTK_COLOR_SWATCH (p));
|
|
|
|
save_custom_colors (cc);
|
|
|
|
}
|
|
|
|
|
2012-01-29 15:42:34 +00:00
|
|
|
static void
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_chooser_widget_set_rgba (GtkColorChooser *chooser,
|
|
|
|
const GdkRGBA *color)
|
2012-01-29 15:42:34 +00:00
|
|
|
{
|
|
|
|
GtkColorChooserWidget *cc = GTK_COLOR_CHOOSER_WIDGET (chooser);
|
2020-05-07 18:23:36 +00:00
|
|
|
GtkWidget *swatch;
|
2012-02-08 23:06:50 +00:00
|
|
|
GtkWidget *w;
|
2020-05-09 12:26:52 +00:00
|
|
|
|
2012-01-29 15:42:34 +00:00
|
|
|
GdkRGBA c;
|
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
for (w = gtk_widget_get_first_child (cc->palette);
|
|
|
|
w != NULL;
|
|
|
|
w = gtk_widget_get_next_sibling (w))
|
2012-01-29 15:42:34 +00:00
|
|
|
{
|
2012-02-08 23:06:50 +00:00
|
|
|
if (!GTK_IS_GRID (w) && !GTK_IS_BOX (w))
|
2012-02-04 06:45:55 +00:00
|
|
|
continue;
|
|
|
|
|
2020-05-07 18:23:36 +00:00
|
|
|
for (swatch = gtk_widget_get_first_child (w);
|
|
|
|
swatch != NULL;
|
|
|
|
swatch = gtk_widget_get_next_sibling (swatch))
|
2012-01-29 15:42:34 +00:00
|
|
|
{
|
2020-05-07 18:23:36 +00:00
|
|
|
gtk_color_swatch_get_rgba (GTK_COLOR_SWATCH (swatch), &c);
|
2020-03-28 21:09:52 +00:00
|
|
|
if (!cc->use_alpha)
|
2012-01-31 07:05:37 +00:00
|
|
|
c.alpha = color->alpha;
|
2012-01-29 15:42:34 +00:00
|
|
|
if (gdk_rgba_equal (color, &c))
|
|
|
|
{
|
2020-05-07 18:23:36 +00:00
|
|
|
select_swatch (cc, GTK_COLOR_SWATCH (swatch));
|
2012-01-29 15:42:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-31 05:31:41 +00:00
|
|
|
add_custom_color (cc, color);
|
2012-01-29 15:42:34 +00:00
|
|
|
}
|
|
|
|
|
2012-02-04 06:45:55 +00:00
|
|
|
static void
|
|
|
|
gtk_color_chooser_widget_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)
|
|
|
|
{
|
|
|
|
GtkColorChooserWidget *cc = GTK_COLOR_CHOOSER_WIDGET (chooser);
|
|
|
|
|
|
|
|
remove_default_palette (cc);
|
2020-10-07 19:56:11 +00:00
|
|
|
add_palette (cc, orientation, colors_per_line, n_colors, colors, NULL);
|
2020-08-24 21:20:17 +00:00
|
|
|
|
|
|
|
gtk_box_reorder_child_after (GTK_BOX (cc->palette), cc->custom_label, gtk_widget_get_last_child (cc->palette));
|
|
|
|
gtk_box_reorder_child_after (GTK_BOX (cc->palette), cc->custom, cc->custom_label);
|
2012-02-04 06:45:55 +00:00
|
|
|
}
|
|
|
|
|
2012-01-29 15:42:34 +00:00
|
|
|
static void
|
|
|
|
gtk_color_chooser_widget_iface_init (GtkColorChooserInterface *iface)
|
|
|
|
{
|
2012-02-03 23:34:33 +00:00
|
|
|
iface->get_rgba = gtk_color_chooser_widget_get_rgba;
|
|
|
|
iface->set_rgba = gtk_color_chooser_widget_set_rgba;
|
2012-02-04 06:45:55 +00:00
|
|
|
iface->add_palette = gtk_color_chooser_widget_add_palette;
|
2012-01-29 15:42:34 +00:00
|
|
|
}
|
2021-02-26 16:26:09 +00:00
|
|
|
|
|
|
|
/* Public API {{{1 */
|
2020-09-14 01:44:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_color_chooser_widget_new:
|
|
|
|
*
|
2021-02-26 16:26:09 +00:00
|
|
|
* Creates a new `GtkColorChooserWidget`.
|
2020-09-14 01:44:50 +00:00
|
|
|
*
|
2021-02-26 16:26:09 +00:00
|
|
|
* Returns: a new `GtkColorChooserWidget`
|
2020-09-14 01:44:50 +00:00
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gtk_color_chooser_widget_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_COLOR_CHOOSER_WIDGET, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vim:set foldmethod=marker: */
|