+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;
+ GList *palettes, *p;
+ GtkWidget *swatch;
+ GtkWidget *grid;
+
+ cc->priv->use_alpha = use_alpha;
+ gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER (cc->priv->editor), use_alpha);
+
+ palettes = gtk_container_get_children (GTK_CONTAINER (cc->priv->palette));
+ for (p = palettes; p; p = p->next)
+ {
+ grid = p->data;
+
+ if (!GTK_IS_CONTAINER (grid))
+ continue;
+
+ children = gtk_container_get_children (GTK_CONTAINER (grid));
+ 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);
+ }
+ g_list_free (palettes);
+
+ 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 */
+
+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;
+}
+
+static gchar *
+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));
+}
+
+static void
+remove_palette (GtkColorChooserWidget *cc)
+{
+ GList *children, *l;
+ GtkWidget *widget;
+
+ if (cc->priv->current != NULL &&
+ gtk_widget_get_parent (GTK_WIDGET (cc->priv->current)) != cc->priv->custom)
+ cc->priv->current = NULL;
+
+ 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);
+}
+
+static void
+add_palette (GtkColorChooserWidget *cc,
+ GtkOrientation orientation,
+ gint colors_per_line,
+ gint n_colors,
+ GdkRGBA *colors,
+ const gchar **names)