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"
|
|
|
|
|
|
|
|
#include "gtkcolorchooserprivate.h"
|
|
|
|
#include "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"
|
2012-01-29 15:42:34 +00:00
|
|
|
#include "gtkintl.h"
|
2012-02-03 06:41:45 +00:00
|
|
|
#include "gtksizegroup.h"
|
2019-03-16 03:48:26 +00:00
|
|
|
#include "gtkstylecontext.h"
|
2019-07-31 14:55:12 +00:00
|
|
|
#include "gtkboxlayout.h"
|
2020-04-08 11:43:28 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2012-01-29 15:42:34 +00:00
|
|
|
|
2012-02-09 04:21:41 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
2012-02-04 00:40:36 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gtkcolorchooserwidget
|
|
|
|
* @Short_description: A widget for choosing colors
|
|
|
|
* @Title: GtkColorChooserWidget
|
|
|
|
* @See_also: #GtkColorChooserDialog
|
|
|
|
*
|
|
|
|
* The #GtkColorChooserWidget widget lets the user select a
|
2014-12-30 12:46:11 +00:00
|
|
|
* color. By default, the chooser presents a predefined palette
|
2012-02-04 00:40:36 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* The chooser automatically remembers the last selection, as well
|
|
|
|
* as custom colors.
|
|
|
|
*
|
|
|
|
* To change the initially selected color, use gtk_color_chooser_set_rgba().
|
2014-06-28 03:53:03 +00:00
|
|
|
* To get the selected color use gtk_color_chooser_get_rgba().
|
2012-02-04 00:40:36 +00:00
|
|
|
*
|
|
|
|
* The #GtkColorChooserWidget is used in the #GtkColorChooserDialog
|
|
|
|
* to provide a dialog for selecting colors.
|
|
|
|
*
|
2016-01-14 04:34:03 +00:00
|
|
|
* # CSS names
|
|
|
|
*
|
|
|
|
* GtkColorChooserWidget has a single CSS node with name colorchooser.
|
2012-02-04 00:40:36 +00:00
|
|
|
*/
|
|
|
|
|
2019-05-28 00:04:01 +00:00
|
|
|
typedef struct _GtkColorChooserWidgetPrivate GtkColorChooserWidgetPrivate;
|
|
|
|
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-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
|
|
|
|
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,
|
2012-02-09 04:21:41 +00:00
|
|
|
GdkRGBA *colors,
|
2020-07-24 18:40:36 +00:00
|
|
|
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);
|
2020-08-24 21:20:17 +00:00
|
|
|
|
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 ();
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2012-02-04 06:45:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_default_palette (GtkColorChooserWidget *cc)
|
|
|
|
{
|
2020-09-11 08:38:47 +00:00
|
|
|
const char *default_colors[8][3] = {
|
|
|
|
{ "#99c1f1", "#3584e4", "#1a5fb4" }, /* Blue */
|
|
|
|
{ "#8ff0a4", "#33d17a", "#26a269" }, /* Green */
|
|
|
|
{ "#f9f06b", "#f6d32d", "#e5a50a" }, /* Yellow */
|
|
|
|
{ "#ffbe6f", "#ff7800", "#c64600" }, /* Orange */
|
|
|
|
{ "#f66151", "#e01b24", "#a51d2d" }, /* Red */
|
|
|
|
{ "#dc8add", "#9141ac", "#613583" }, /* Purple */
|
|
|
|
{ "#cdab8f", "#986a44", "#63452c" }, /* Brown */
|
|
|
|
{ "#f6f5f4", "#9a9996", "#3d3846" } /* Neutral */
|
2012-01-29 15:42:34 +00:00
|
|
|
};
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *color_names[] = {
|
2020-09-11 08:38:47 +00:00
|
|
|
NC_("Color name", "Blue 1"),
|
|
|
|
NC_("Color name", "Blue 2"),
|
|
|
|
NC_("Color name", "Blue 3"),
|
|
|
|
NC_("Color name", "Green 1"),
|
|
|
|
NC_("Color name", "Green 2"),
|
|
|
|
NC_("Color name", "Green 3"),
|
|
|
|
NC_("Color name", "Yellow 1"),
|
|
|
|
NC_("Color name", "Yellow 2"),
|
|
|
|
NC_("Color name", "Yellow 3"),
|
|
|
|
NC_("Color name", "Orange 1"),
|
|
|
|
NC_("Color name", "Orange 2"),
|
|
|
|
NC_("Color name", "Orange 3"),
|
|
|
|
NC_("Color name", "Red 1"),
|
|
|
|
NC_("Color name", "Red 2"),
|
|
|
|
NC_("Color name", "Red 3"),
|
|
|
|
NC_("Color name", "Purple 1"),
|
|
|
|
NC_("Color name", "Purple 2"),
|
|
|
|
NC_("Color name", "Purple 3"),
|
|
|
|
NC_("Color name", "Brown 1"),
|
|
|
|
NC_("Color name", "Brown 2"),
|
|
|
|
NC_("Color name", "Brown 3"),
|
|
|
|
NC_("Color name", "Neutral 1"),
|
|
|
|
NC_("Color name", "Neutral 2"),
|
|
|
|
NC_("Color name", "Neutral 3")
|
2012-02-09 04:21:41 +00:00
|
|
|
};
|
2020-09-11 08:38:47 +00:00
|
|
|
|
|
|
|
GdkRGBA colors[8*3];
|
2020-07-24 13:54:49 +00:00
|
|
|
int i, j;
|
2012-01-29 15:42:34 +00:00
|
|
|
|
2020-09-11 08:38:47 +00:00
|
|
|
for (i = 0; i < 8; i++)
|
2012-02-04 06:45:55 +00:00
|
|
|
for (j = 0; j < 3; j++)
|
|
|
|
gdk_rgba_parse (&colors[i*3 + j], default_colors[i][j]);
|
2012-01-29 15:42:34 +00:00
|
|
|
|
2020-09-11 08:38:47 +00:00
|
|
|
add_palette (cc, GTK_ORIENTATION_VERTICAL, 3, 8*3, 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;
|
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);
|
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:
|
|
|
|
*
|
|
|
|
* The ::show-editor property is %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-01 06:53:08 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_SHOW_EDITOR,
|
|
|
|
g_param_spec_boolean ("show-editor", P_("Show editor"), P_("Show editor"),
|
|
|
|
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
|
|
|
|
*
|
|
|
|
* Emits the #GtkColorChooser::color-activated signal for
|
|
|
|
* 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;
|
2012-02-08 23:06:50 +00:00
|
|
|
GList *children;
|
2020-05-09 12:26:52 +00:00
|
|
|
GtkWidget *p;
|
|
|
|
|
|
|
|
children = NULL;
|
|
|
|
for (widget = gtk_widget_get_first_child (cc->custom);
|
|
|
|
widget != NULL;
|
|
|
|
widget = gtk_widget_get_next_sibling (widget))
|
|
|
|
children = g_list_prepend (children, widget);
|
2012-01-31 05:31:41 +00:00
|
|
|
|
2020-09-11 08:38:47 +00:00
|
|
|
if (g_list_length (children) >= 8)
|
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);
|
2012-02-01 07:00:21 +00:00
|
|
|
}
|
2012-02-08 23:06:50 +00:00
|
|
|
g_list_free (children);
|
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);
|
2012-03-07 02:07:02 +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
|
|
|
}
|
|
|
|
|
2012-02-04 05:02:49 +00:00
|
|
|
/* Public API {{{1 */
|
|
|
|
|
2012-02-04 00:40:36 +00:00
|
|
|
/**
|
|
|
|
* gtk_color_chooser_widget_new:
|
|
|
|
*
|
|
|
|
* Creates a new #GtkColorChooserWidget.
|
|
|
|
*
|
|
|
|
* Returns: a new #GtkColorChooserWidget
|
|
|
|
*/
|
2012-01-29 15:42:34 +00:00
|
|
|
GtkWidget *
|
|
|
|
gtk_color_chooser_widget_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_COLOR_CHOOSER_WIDGET, NULL);
|
|
|
|
}
|
2012-02-04 05:02:49 +00:00
|
|
|
|
|
|
|
/* vim:set foldmethod=marker: */
|