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 "gtkbox.h"
|
|
|
|
#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"
|
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
|
|
|
|
* color. By default, the chooser presents a prefined 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.
|
|
|
|
*
|
|
|
|
* The chooser automatically remembers the last selection, as well
|
|
|
|
* as custom colors.
|
|
|
|
*
|
|
|
|
* To change the initially selected color, use gtk_color_chooser_set_rgba().
|
|
|
|
* To get the selected font use gtk_color_chooser_get_rgba().
|
|
|
|
*
|
|
|
|
* The #GtkColorChooserWidget is used in the #GtkColorChooserDialog
|
|
|
|
* to provide a dialog for selecting colors.
|
|
|
|
*
|
|
|
|
* Since: 3.4
|
|
|
|
*/
|
|
|
|
|
2012-01-29 15:42:34 +00:00
|
|
|
struct _GtkColorChooserWidgetPrivate
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkColorChooserWidget, gtk_color_chooser_widget, GTK_TYPE_BOX,
|
2013-06-27 19:02:52 +00:00
|
|
|
G_ADD_PRIVATE (GtkColorChooserWidget)
|
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;
|
|
|
|
|
2012-01-29 15:42:34 +00:00
|
|
|
if (cc->priv->current == swatch)
|
|
|
|
return;
|
2012-02-04 05:02:49 +00:00
|
|
|
|
2012-01-29 15:42:34 +00:00
|
|
|
if (cc->priv->current != NULL)
|
2014-04-12 08:09:46 +00:00
|
|
|
{
|
|
|
|
gtk_widget_unset_state_flags (GTK_WIDGET (cc->priv->current), GTK_STATE_FLAG_SELECTED);
|
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (cc->priv->current));
|
|
|
|
}
|
|
|
|
|
2012-02-09 04:48:11 +00:00
|
|
|
gtk_widget_set_state_flags (GTK_WIDGET (swatch), GTK_STATE_FLAG_SELECTED, FALSE);
|
2012-01-29 15:42:34 +00:00
|
|
|
cc->priv->current = swatch;
|
2014-04-12 08:09:46 +00:00
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (cc->priv->current));
|
2012-02-04 05:02:49 +00:00
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_swatch_get_rgba (swatch, &color);
|
2012-01-30 23:37:00 +00:00
|
|
|
g_settings_set (cc->priv->settings, "selected-color", "(bdddd)",
|
|
|
|
TRUE, color.red, color.green, color.blue, color.alpha);
|
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
g_object_notify (G_OBJECT (cc), "rgba");
|
2012-01-29 15:42:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
swatch_activate (GtkColorSwatch *swatch,
|
|
|
|
GtkColorChooserWidget *cc)
|
|
|
|
{
|
|
|
|
GdkRGBA color;
|
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_swatch_get_rgba (swatch, &color);
|
2012-01-29 15:42:34 +00:00
|
|
|
_gtk_color_chooser_color_activated (GTK_COLOR_CHOOSER (cc), &color);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
swatch_customize (GtkColorSwatch *swatch,
|
|
|
|
GtkColorChooserWidget *cc)
|
|
|
|
{
|
|
|
|
GdkRGBA color;
|
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_swatch_get_rgba (swatch, &color);
|
|
|
|
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (cc->priv->editor), &color);
|
2012-01-29 15:42:34 +00:00
|
|
|
|
|
|
|
gtk_widget_hide (cc->priv->palette);
|
|
|
|
gtk_widget_show (cc->priv->editor);
|
2012-02-09 03:12:31 +00:00
|
|
|
g_object_notify (G_OBJECT (cc), "show-editor");
|
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
|
|
|
{
|
|
|
|
g_signal_connect (p, "activate", G_CALLBACK (swatch_activate), data);
|
|
|
|
g_signal_connect (p, "customize", G_CALLBACK (swatch_customize), data);
|
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
|
|
|
button_activate (GtkColorSwatch *swatch,
|
|
|
|
GtkColorChooserWidget *cc)
|
2012-01-29 15:42:34 +00:00
|
|
|
{
|
2012-02-04 05:02:49 +00:00
|
|
|
/* somewhat random, makes the hairline nicely visible */
|
|
|
|
GdkRGBA color = { 0.75, 0.25, 0.25, 1.0 };
|
|
|
|
|
|
|
|
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (cc->priv->editor), &color);
|
|
|
|
|
|
|
|
gtk_widget_hide (cc->priv->palette);
|
|
|
|
gtk_widget_show (cc->priv->editor);
|
2012-02-09 03:12:31 +00:00
|
|
|
g_object_notify (G_OBJECT (cc), "show-editor");
|
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
|
|
|
{
|
2012-02-04 05:02:49 +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-02-08 23:06:50 +00:00
|
|
|
GList *children, *l;
|
2012-01-31 05:31:41 +00:00
|
|
|
GtkWidget *child;
|
2012-01-29 15:42:34 +00:00
|
|
|
|
|
|
|
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(dddd)"));
|
|
|
|
|
2012-02-08 23:06:50 +00:00
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (cc->priv->custom));
|
|
|
|
for (l = g_list_nth (children, 1); l != NULL; l = l->next)
|
2012-01-29 15:42:34 +00:00
|
|
|
{
|
2012-02-08 23:06:50 +00:00
|
|
|
child = l->data;
|
2012-02-03 23:34:33 +00:00
|
|
|
if (gtk_color_swatch_get_rgba (GTK_COLOR_SWATCH (child), &color))
|
2012-02-04 05:02:49 +00:00
|
|
|
g_variant_builder_add (&builder, "(dddd)",
|
|
|
|
color.red, color.green, color.blue, color.alpha);
|
2012-01-29 15:42:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
variant = g_variant_builder_end (&builder);
|
|
|
|
g_settings_set_value (cc->priv->settings, "custom-colors", variant);
|
2012-02-08 23:06:50 +00:00
|
|
|
|
|
|
|
g_list_free (children);
|
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)
|
|
|
|
{
|
|
|
|
GList *children, *l;
|
2012-02-04 06:45:55 +00:00
|
|
|
GList *palettes, *p;
|
2012-02-04 05:02:49 +00:00
|
|
|
GtkWidget *swatch;
|
2012-02-04 06:45:55 +00:00
|
|
|
GtkWidget *grid;
|
2012-02-04 05:02:49 +00:00
|
|
|
|
|
|
|
cc->priv->use_alpha = use_alpha;
|
|
|
|
gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER (cc->priv->editor), use_alpha);
|
|
|
|
|
2012-02-04 06:45:55 +00:00
|
|
|
palettes = gtk_container_get_children (GTK_CONTAINER (cc->priv->palette));
|
|
|
|
for (p = palettes; p; p = p->next)
|
2012-02-04 05:02:49 +00:00
|
|
|
{
|
2012-02-04 06:45:55 +00:00
|
|
|
grid = p->data;
|
|
|
|
|
2012-02-09 01:21:10 +00:00
|
|
|
if (!GTK_IS_CONTAINER (grid))
|
2012-02-04 06:45:55 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (grid));
|
2012-02-04 05:02:49 +00:00
|
|
|
for (l = children; l; l = l->next)
|
|
|
|
{
|
|
|
|
swatch = l->data;
|
|
|
|
gtk_color_swatch_set_use_alpha (GTK_COLOR_SWATCH (swatch), use_alpha);
|
|
|
|
}
|
|
|
|
g_list_free (children);
|
|
|
|
}
|
2012-02-04 06:45:55 +00:00
|
|
|
g_list_free (palettes);
|
2012-02-04 05:02:49 +00:00
|
|
|
|
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (cc));
|
|
|
|
}
|
|
|
|
|
|
|
|
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 };
|
|
|
|
|
|
|
|
if (cc->priv->current)
|
|
|
|
gtk_color_swatch_get_rgba (cc->priv->current, &color);
|
|
|
|
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (cc->priv->editor), &color);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_set_visible (cc->priv->editor, show_editor);
|
|
|
|
gtk_widget_set_visible (cc->priv->palette, !show_editor);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* UI construction {{{1 */
|
|
|
|
|
2012-02-12 00:03:45 +00:00
|
|
|
static guint
|
|
|
|
scale_round (gdouble value, gdouble scale)
|
|
|
|
{
|
|
|
|
value = floor (value * scale + 0.5);
|
|
|
|
value = MAX (value, 0);
|
|
|
|
value = MIN (value, scale);
|
|
|
|
return (guint)value;
|
|
|
|
}
|
|
|
|
|
2012-02-21 00:46:40 +00:00
|
|
|
static gchar *
|
2012-02-12 00:03:45 +00:00
|
|
|
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-03-04 05:28:08 +00:00
|
|
|
static void
|
|
|
|
remove_palette (GtkColorChooserWidget *cc)
|
|
|
|
{
|
|
|
|
GList *children, *l;
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
2013-02-17 15:01:06 +00:00
|
|
|
if (cc->priv->current != NULL &&
|
|
|
|
gtk_widget_get_parent (GTK_WIDGET (cc->priv->current)) != cc->priv->custom)
|
|
|
|
cc->priv->current = NULL;
|
|
|
|
|
2012-03-04 05:28:08 +00:00
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (cc->priv->palette));
|
|
|
|
for (l = children; l; l = l->next)
|
|
|
|
{
|
|
|
|
widget = l->data;
|
|
|
|
if (widget == cc->priv->custom_label || widget == cc->priv->custom)
|
|
|
|
continue;
|
|
|
|
gtk_container_remove (GTK_CONTAINER (cc->priv->palette), widget);
|
|
|
|
}
|
|
|
|
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,
|
2012-02-09 04:21:41 +00:00
|
|
|
gint colors_per_line,
|
|
|
|
gint n_colors,
|
|
|
|
GdkRGBA *colors,
|
|
|
|
const gchar **names)
|
2012-01-29 15:42:34 +00:00
|
|
|
{
|
|
|
|
GtkWidget *grid;
|
|
|
|
GtkWidget *p;
|
2012-02-09 04:21:41 +00:00
|
|
|
AtkObject *atk_obj;
|
2012-02-04 06:45:55 +00:00
|
|
|
gint line, pos;
|
|
|
|
gint i;
|
|
|
|
gint left, right;
|
|
|
|
|
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);
|
|
|
|
gtk_container_add (GTK_CONTAINER (cc->priv->palette), grid);
|
|
|
|
|
|
|
|
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 ();
|
2012-02-12 00:03:45 +00:00
|
|
|
atk_obj = gtk_widget_get_accessible (p);
|
2012-02-09 04:21:41 +00:00
|
|
|
if (names)
|
|
|
|
{
|
2014-01-05 04:30:28 +00:00
|
|
|
atk_object_set_name (atk_obj,
|
|
|
|
g_dpgettext2 (GETTEXT_PACKAGE, "Color name", names[i]));
|
2012-02-12 00:03:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gchar *text, *name;
|
|
|
|
|
|
|
|
name = accessible_color_name (&colors[i]);
|
|
|
|
text = g_strdup_printf (_("Color: %s"), name);
|
2014-01-05 04:30:28 +00:00
|
|
|
atk_object_set_name (atk_obj, text);
|
2012-02-12 00:03:45 +00:00
|
|
|
g_free (text);
|
|
|
|
g_free (name);
|
2012-02-09 04:21:41 +00:00
|
|
|
}
|
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
|
|
|
{
|
|
|
|
if (pos == left)
|
2012-02-08 22:38:20 +00:00
|
|
|
gtk_style_context_add_class (gtk_widget_get_style_context (p), GTK_STYLE_CLASS_LEFT);
|
2012-02-04 06:45:55 +00:00
|
|
|
else if (pos == right)
|
2012-02-08 22:38:20 +00:00
|
|
|
gtk_style_context_add_class (gtk_widget_get_style_context (p), GTK_STYLE_CLASS_RIGHT);
|
|
|
|
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), p, pos, line, 1, 1);
|
2012-02-04 06:45:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (pos == 0)
|
2012-02-08 22:38:20 +00:00
|
|
|
gtk_style_context_add_class (gtk_widget_get_style_context (p), GTK_STYLE_CLASS_TOP);
|
2012-02-04 06:45:55 +00:00
|
|
|
else if (pos == colors_per_line - 1)
|
2012-02-08 22:38:20 +00:00
|
|
|
gtk_style_context_add_class (gtk_widget_get_style_context (p), GTK_STYLE_CLASS_BOTTOM);
|
|
|
|
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), p, line, pos, 1, 1);
|
2012-02-04 06:45:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_show_all (grid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
remove_default_palette (GtkColorChooserWidget *cc)
|
|
|
|
{
|
|
|
|
if (!cc->priv->has_default_palette)
|
|
|
|
return;
|
|
|
|
|
2012-03-04 05:28:08 +00:00
|
|
|
remove_palette (cc);
|
2012-02-04 06:45:55 +00:00
|
|
|
cc->priv->has_default_palette = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_default_palette (GtkColorChooserWidget *cc)
|
|
|
|
{
|
|
|
|
const gchar *default_colors[9][3] = {
|
2012-01-31 01:01:23 +00:00
|
|
|
{ "#ef2929", "#cc0000", "#a40000" }, /* Scarlet Red */
|
|
|
|
{ "#fcaf3e", "#f57900", "#ce5c00" }, /* Orange */
|
|
|
|
{ "#fce94f", "#edd400", "#c4a000" }, /* Butter */
|
|
|
|
{ "#8ae234", "#73d216", "#4e9a06" }, /* Chameleon */
|
|
|
|
{ "#729fcf", "#3465a4", "#204a87" }, /* Sky Blue */
|
|
|
|
{ "#ad7fa8", "#75507b", "#5c3566" }, /* Plum */
|
|
|
|
{ "#e9b96e", "#c17d11", "#8f5902" }, /* Chocolate */
|
|
|
|
{ "#888a85", "#555753", "#2e3436" }, /* Aluminum 1 */
|
|
|
|
{ "#eeeeec", "#d3d7cf", "#babdb6" } /* Aluminum 2 */
|
2012-01-29 15:42:34 +00:00
|
|
|
};
|
2012-02-09 04:21:41 +00:00
|
|
|
const gchar *color_names[] = {
|
2012-02-10 22:38:22 +00:00
|
|
|
NC_("Color name", "Light Scarlet Red"),
|
|
|
|
NC_("Color name", "Scarlet Red"),
|
|
|
|
NC_("Color name", "Dark Scarlet Red"),
|
|
|
|
NC_("Color name", "Light Orange"),
|
|
|
|
NC_("Color name", "Orange"),
|
|
|
|
NC_("Color name", "Dark Orange"),
|
|
|
|
NC_("Color name", "Light Butter"),
|
|
|
|
NC_("Color name", "Butter"),
|
|
|
|
NC_("Color name", "Dark Butter"),
|
|
|
|
NC_("Color name", "Light Chameleon"),
|
|
|
|
NC_("Color name", "Chameleon"),
|
|
|
|
NC_("Color name", "Dark Chameleon"),
|
|
|
|
NC_("Color name", "Light Sky Blue"),
|
|
|
|
NC_("Color name", "Sky Blue"),
|
|
|
|
NC_("Color name", "Dark Sky Blue"),
|
|
|
|
NC_("Color name", "Light Plum"),
|
|
|
|
NC_("Color name", "Plum"),
|
|
|
|
NC_("Color name", "Dark Plum"),
|
|
|
|
NC_("Color name", "Light Chocolate"),
|
|
|
|
NC_("Color name", "Chocolate"),
|
|
|
|
NC_("Color name", "Dark Chocolate"),
|
|
|
|
NC_("Color name", "Light Aluminum 1"),
|
|
|
|
NC_("Color name", "Aluminum 1"),
|
|
|
|
NC_("Color name", "Dark Aluminum 1"),
|
|
|
|
NC_("Color name", "Light Aluminum 2"),
|
|
|
|
NC_("Color name", "Aluminum 2"),
|
|
|
|
NC_("Color name", "Dark Aluminum 2")
|
2012-02-09 04:21:41 +00:00
|
|
|
};
|
2012-02-04 06:45:55 +00:00
|
|
|
const gchar *default_grays[9] = {
|
2012-02-09 04:21:41 +00:00
|
|
|
"#000000", /* black */
|
|
|
|
"#2e3436", /* very dark gray */
|
|
|
|
"#555753", /* darker gray */
|
|
|
|
"#888a85", /* dark gray */
|
|
|
|
"#babdb6", /* medium gray */
|
|
|
|
"#d3d7cf", /* light gray */
|
|
|
|
"#eeeeec", /* lighter gray */
|
|
|
|
"#f3f3f3", /* very light gray */
|
|
|
|
"#ffffff" /* white */
|
|
|
|
};
|
|
|
|
const gchar *gray_names[] = {
|
2012-02-10 22:38:22 +00:00
|
|
|
NC_("Color name", "Black"),
|
|
|
|
NC_("Color name", "Very Dark Gray"),
|
|
|
|
NC_("Color name", "Darker Gray"),
|
|
|
|
NC_("Color name", "Dark Gray"),
|
|
|
|
NC_("Color name", "Medium Gray"),
|
|
|
|
NC_("Color name", "Light Gray"),
|
|
|
|
NC_("Color name", "Lighter Gray"),
|
|
|
|
NC_("Color name", "Very Light Gray"),
|
|
|
|
NC_("Color name", "White")
|
2012-01-31 01:31:13 +00:00
|
|
|
};
|
2012-02-04 06:45:55 +00:00
|
|
|
GdkRGBA colors[9*3];
|
|
|
|
gint i, j;
|
2012-01-29 15:42:34 +00:00
|
|
|
|
2012-02-04 06:45:55 +00:00
|
|
|
for (i = 0; i < 9; i++)
|
|
|
|
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
|
|
|
|
2012-03-08 02:12:32 +00:00
|
|
|
add_palette (cc, GTK_ORIENTATION_VERTICAL, 3, 9*3, colors, color_names);
|
2012-01-29 15:42:34 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 9; i++)
|
2012-02-04 06:45:55 +00:00
|
|
|
gdk_rgba_parse (&colors[i], default_grays[i]);
|
2012-01-29 15:42:34 +00:00
|
|
|
|
2012-03-08 02:12:32 +00:00
|
|
|
add_palette (cc, GTK_ORIENTATION_HORIZONTAL, 9, 9, colors, gray_names);
|
2012-01-29 15:42:34 +00:00
|
|
|
|
2012-02-04 06:45:55 +00:00
|
|
|
cc->priv->has_default_palette = TRUE;
|
|
|
|
}
|
2012-01-29 15:42:34 +00:00
|
|
|
|
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;
|
|
|
|
gint i;
|
|
|
|
GdkRGBA color;
|
|
|
|
GVariant *variant;
|
|
|
|
GVariantIter iter;
|
|
|
|
gboolean selected;
|
2012-02-09 04:21:41 +00:00
|
|
|
AtkObject *atk_obj;
|
2012-02-12 00:03:45 +00:00
|
|
|
gchar *text, *name;
|
2012-01-29 15:42:34 +00:00
|
|
|
|
2013-06-27 19:02:52 +00:00
|
|
|
cc->priv = gtk_color_chooser_widget_get_instance_private (cc);
|
2012-02-03 06:41:45 +00:00
|
|
|
|
2012-02-09 01:21:10 +00:00
|
|
|
cc->priv->use_alpha = TRUE;
|
|
|
|
|
2012-02-04 06:45:55 +00:00
|
|
|
gtk_orientable_set_orientation (GTK_ORIENTABLE (cc), GTK_ORIENTATION_VERTICAL);
|
|
|
|
cc->priv->palette = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
|
|
|
gtk_container_add (GTK_CONTAINER (cc), cc->priv->palette);
|
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-08 23:06:50 +00:00
|
|
|
cc->priv->custom = box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
|
|
|
|
g_object_set (box, "margin-top", 12, NULL);
|
|
|
|
gtk_box_pack_end (GTK_BOX (cc->priv->palette), box, FALSE, TRUE, 0);
|
2012-02-04 06:45:55 +00:00
|
|
|
|
|
|
|
/* translators: label for the custom section in the color chooser */
|
|
|
|
cc->priv->custom_label = label = gtk_label_new (_("Custom"));
|
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_START);
|
|
|
|
gtk_box_pack_end (GTK_BOX (cc->priv->palette), label, FALSE, TRUE, 0);
|
2012-01-29 15:42:34 +00:00
|
|
|
|
2012-01-31 05:31:41 +00:00
|
|
|
cc->priv->button = button = gtk_color_swatch_new ();
|
2012-02-20 12:53:10 +00:00
|
|
|
gtk_widget_set_name (button, "add-color-button");
|
2012-02-09 04:21:41 +00:00
|
|
|
atk_obj = gtk_widget_get_accessible (button);
|
2014-01-05 14:19:58 +00:00
|
|
|
atk_object_set_name (atk_obj, _("Custom color"));
|
|
|
|
atk_object_set_description (atk_obj, _("Create a custom color"));
|
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);
|
2012-02-08 23:06:50 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (box), button);
|
2012-01-29 15:42:34 +00:00
|
|
|
|
2013-01-23 12:48:26 +00:00
|
|
|
cc->priv->settings = g_settings_new ("org.gtk.Settings.ColorChooser");
|
2012-01-29 15:42:34 +00:00
|
|
|
variant = g_settings_get_value (cc->priv->settings, "custom-colors");
|
|
|
|
g_variant_iter_init (&iter, variant);
|
|
|
|
i = 0;
|
2012-02-04 06:45:55 +00:00
|
|
|
p = NULL;
|
2012-01-29 15:42:34 +00:00
|
|
|
while (g_variant_iter_loop (&iter, "(dddd)", &color.red, &color.green, &color.blue, &color.alpha))
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
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-29 15:42:34 +00:00
|
|
|
gtk_color_swatch_set_can_drop (GTK_COLOR_SWATCH (p), TRUE);
|
2012-02-09 04:21:41 +00:00
|
|
|
atk_obj = gtk_widget_get_accessible (p);
|
2012-02-12 00:03:45 +00:00
|
|
|
name = accessible_color_name (&color);
|
|
|
|
text = g_strdup_printf (_("Custom color %d: %s"), i, name);
|
2014-01-05 15:54:43 +00:00
|
|
|
atk_object_set_name (atk_obj, text);
|
2012-02-09 04:21:41 +00:00
|
|
|
g_free (text);
|
2012-02-12 00:03:45 +00:00
|
|
|
g_free (name);
|
2012-01-29 15:42:34 +00:00
|
|
|
connect_custom_signals (p, cc);
|
2012-02-08 23:06:50 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (box), p);
|
2012-01-29 15:42:34 +00:00
|
|
|
|
|
|
|
if (i == 8)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
g_variant_unref (variant);
|
|
|
|
|
|
|
|
cc->priv->editor = gtk_color_editor_new ();
|
2012-02-09 20:10:21 +00:00
|
|
|
gtk_widget_set_halign (cc->priv->editor, GTK_ALIGN_CENTER);
|
|
|
|
gtk_widget_set_hexpand (cc->priv->editor, TRUE);
|
|
|
|
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
|
|
|
gtk_container_add (GTK_CONTAINER (cc), box);
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), cc->priv->editor);
|
2012-01-29 15:42:34 +00:00
|
|
|
|
|
|
|
g_settings_get (cc->priv->settings, "selected-color", "(bdddd)",
|
|
|
|
&selected,
|
|
|
|
&color.red, &color.green, &color.blue, &color.alpha);
|
|
|
|
if (selected)
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (cc), &color);
|
2012-01-29 15:42:34 +00:00
|
|
|
|
|
|
|
gtk_widget_show_all (GTK_WIDGET (cc));
|
|
|
|
gtk_widget_hide (GTK_WIDGET (cc->priv->editor));
|
|
|
|
gtk_widget_hide (GTK_WIDGET (cc));
|
|
|
|
|
|
|
|
gtk_widget_set_no_show_all (cc->priv->palette, TRUE);
|
|
|
|
gtk_widget_set_no_show_all (cc->priv->editor, TRUE);
|
2012-02-03 06:41:45 +00:00
|
|
|
|
|
|
|
cc->priv->size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
|
|
|
|
gtk_size_group_add_widget (cc->priv->size_group, cc->priv->palette);
|
2012-02-09 20:10:21 +00:00
|
|
|
gtk_size_group_add_widget (cc->priv->size_group, box);
|
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)
|
|
|
|
{
|
2012-01-31 07:05:37 +00:00
|
|
|
GtkColorChooserWidget *cw = GTK_COLOR_CHOOSER_WIDGET (object);
|
2012-01-29 15:42:34 +00:00
|
|
|
GtkColorChooser *cc = GTK_COLOR_CHOOSER (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2012-02-03 23:34:33 +00:00
|
|
|
case PROP_RGBA:
|
2012-01-29 15:42:34 +00:00
|
|
|
{
|
|
|
|
GdkRGBA color;
|
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_chooser_get_rgba (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:
|
|
|
|
g_value_set_boolean (value, cw->priv->use_alpha);
|
2012-01-31 07:05:37 +00:00
|
|
|
break;
|
2012-02-01 06:53:08 +00:00
|
|
|
case PROP_SHOW_EDITOR:
|
|
|
|
g_value_set_boolean (value, gtk_widget_get_visible (cw->priv->editor));
|
|
|
|
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);
|
|
|
|
|
2012-02-03 06:41:45 +00:00
|
|
|
g_object_unref (cc->priv->size_group);
|
2012-01-29 15:42:34 +00:00
|
|
|
g_object_unref (cc->priv->settings);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_color_chooser_widget_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_color_chooser_widget_class_init (GtkColorChooserWidgetClass *class)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
* Since: 3.4
|
|
|
|
*/
|
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));
|
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);
|
|
|
|
|
|
|
|
if (gtk_widget_get_visible (cc->priv->editor))
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (cc->priv->editor), color);
|
2012-01-29 15:42:34 +00:00
|
|
|
else if (cc->priv->current)
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_swatch_get_rgba (cc->priv->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
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
if (!cc->priv->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)
|
|
|
|
{
|
|
|
|
GtkWidget *last;
|
|
|
|
GtkWidget *p;
|
2012-02-08 23:06:50 +00:00
|
|
|
GList *children;
|
2012-01-31 05:31:41 +00:00
|
|
|
|
2012-02-08 23:06:50 +00:00
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (cc->priv->custom));
|
2012-02-09 03:12:31 +00:00
|
|
|
if (g_list_length (children) >= 8)
|
2012-02-01 07:00:21 +00:00
|
|
|
{
|
2012-02-08 23:06:50 +00:00
|
|
|
last = g_list_last (children)->data;
|
|
|
|
gtk_widget_destroy (last);
|
2012-02-01 07:00:21 +00:00
|
|
|
}
|
2012-01-31 05:31:41 +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);
|
|
|
|
|
2012-02-08 23:06:50 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (cc->priv->custom), p);
|
|
|
|
gtk_box_reorder_child (GTK_BOX (cc->priv->custom), p, 1);
|
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);
|
|
|
|
GList *children, *l;
|
2012-02-04 06:45:55 +00:00
|
|
|
GList *palettes, *p;
|
2012-01-29 15:42:34 +00:00
|
|
|
GtkColorSwatch *swatch;
|
2012-02-08 23:06:50 +00:00
|
|
|
GtkWidget *w;
|
2012-01-29 15:42:34 +00:00
|
|
|
GdkRGBA c;
|
|
|
|
|
2012-02-04 06:45:55 +00:00
|
|
|
palettes = gtk_container_get_children (GTK_CONTAINER (cc->priv->palette));
|
|
|
|
for (p = palettes; p; p = p->next)
|
2012-01-29 15:42:34 +00:00
|
|
|
{
|
2012-02-08 23:06:50 +00:00
|
|
|
w = p->data;
|
|
|
|
if (!GTK_IS_GRID (w) && !GTK_IS_BOX (w))
|
2012-02-04 06:45:55 +00:00
|
|
|
continue;
|
|
|
|
|
2012-02-08 23:06:50 +00:00
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (w));
|
2012-01-29 15:42:34 +00:00
|
|
|
for (l = children; l; l = l->next)
|
|
|
|
{
|
|
|
|
swatch = l->data;
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_swatch_get_rgba (swatch, &c);
|
|
|
|
if (!cc->priv->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))
|
|
|
|
{
|
|
|
|
select_swatch (cc, swatch);
|
|
|
|
g_list_free (children);
|
2012-09-16 04:48:42 +00:00
|
|
|
g_list_free (palettes);
|
2012-01-29 15:42:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_list_free (children);
|
|
|
|
}
|
2012-02-04 06:45:55 +00:00
|
|
|
g_list_free (palettes);
|
2012-01-29 15:42:34 +00:00
|
|
|
|
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,
|
2012-02-04 06:45:55 +00:00
|
|
|
gint colors_per_line,
|
|
|
|
gint n_colors,
|
|
|
|
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);
|
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
|
|
|
|
*
|
|
|
|
* Since: 3.4
|
|
|
|
*/
|
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: */
|