Commit d7cff079 authored by Matthias Clasen's avatar Matthias Clasen

Misc cleanups

parent ed5aa953
...@@ -114,6 +114,13 @@ gtk_color_chooser_default_init (GtkColorChooserInterface *iface) ...@@ -114,6 +114,13 @@ gtk_color_chooser_default_init (GtkColorChooserInterface *iface)
1, G_TYPE_STRING); 1, G_TYPE_STRING);
} }
void
_gtk_color_chooser_color_activated (GtkColorChooser *chooser,
const GdkRGBA *color)
{
g_signal_emit (chooser, signals[COLOR_ACTIVATED], 0, color);
}
/** /**
* gtk_color_chooser_get_rgba: * gtk_color_chooser_get_rgba:
* @chooser: a #GtkColorChooser * @chooser: a #GtkColorChooser
...@@ -149,13 +156,6 @@ gtk_color_chooser_set_rgba (GtkColorChooser *chooser, ...@@ -149,13 +156,6 @@ gtk_color_chooser_set_rgba (GtkColorChooser *chooser,
GTK_COLOR_CHOOSER_GET_IFACE (chooser)->set_rgba (chooser, color); GTK_COLOR_CHOOSER_GET_IFACE (chooser)->set_rgba (chooser, color);
} }
void
_gtk_color_chooser_color_activated (GtkColorChooser *chooser,
const GdkRGBA *color)
{
g_signal_emit (chooser, signals[COLOR_ACTIVATED], 0, color);
}
/** /**
* gtk_color_chooser_get_use_alpha: * gtk_color_chooser_get_use_alpha:
* @chooser: a #GtkColorChooser * @chooser: a #GtkColorChooser
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include "gtkcolorchooserwidget.h" #include "gtkcolorchooserwidget.h"
#include "gtkcoloreditor.h" #include "gtkcoloreditor.h"
#include "gtkcolorswatch.h" #include "gtkcolorswatch.h"
#include "gtkcolorutils.h"
#include "gtkbox.h" #include "gtkbox.h"
#include "gtkgrid.h" #include "gtkgrid.h"
#include "gtklabel.h" #include "gtklabel.h"
...@@ -64,6 +63,7 @@ struct _GtkColorChooserWidgetPrivate ...@@ -64,6 +63,7 @@ struct _GtkColorChooserWidgetPrivate
{ {
GtkWidget *palette; GtkWidget *palette;
GtkWidget *editor; GtkWidget *editor;
GtkSizeGroup *size_group;
GtkWidget *colors; GtkWidget *colors;
GtkWidget *grays; GtkWidget *grays;
...@@ -71,9 +71,8 @@ struct _GtkColorChooserWidgetPrivate ...@@ -71,9 +71,8 @@ struct _GtkColorChooserWidgetPrivate
GtkWidget *button; GtkWidget *button;
GtkColorSwatch *current; GtkColorSwatch *current;
gboolean use_alpha;
GtkSizeGroup *size_group; gboolean use_alpha;
GSettings *settings; GSettings *settings;
}; };
...@@ -100,10 +99,12 @@ select_swatch (GtkColorChooserWidget *cc, ...@@ -100,10 +99,12 @@ select_swatch (GtkColorChooserWidget *cc,
if (cc->priv->current == swatch) if (cc->priv->current == swatch)
return; return;
if (cc->priv->current != NULL) if (cc->priv->current != NULL)
gtk_color_swatch_set_selected (cc->priv->current, FALSE); gtk_color_swatch_set_selected (cc->priv->current, FALSE);
gtk_color_swatch_set_selected (swatch, TRUE); gtk_color_swatch_set_selected (swatch, TRUE);
cc->priv->current = swatch; cc->priv->current = swatch;
gtk_color_swatch_get_rgba (swatch, &color); gtk_color_swatch_get_rgba (swatch, &color);
g_settings_set (cc->priv->settings, "selected-color", "(bdddd)", g_settings_set (cc->priv->settings, "selected-color", "(bdddd)",
TRUE, color.red, color.green, color.blue, color.alpha); TRUE, color.red, color.green, color.blue, color.alpha);
...@@ -111,26 +112,6 @@ select_swatch (GtkColorChooserWidget *cc, ...@@ -111,26 +112,6 @@ select_swatch (GtkColorChooserWidget *cc,
g_object_notify (G_OBJECT (cc), "rgba"); g_object_notify (G_OBJECT (cc), "rgba");
} }
static void save_custom_colors (GtkColorChooserWidget *cc);
static void
button_activate (GtkColorSwatch *swatch,
GtkColorChooserWidget *cc)
{
GdkRGBA color;
/* somewhat random, makes the hairline nicely visible */
color.red = 0.75;
color.green = 0.25;
color.blue = 0.25;
color.alpha = 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);
}
static void static void
swatch_activate (GtkColorSwatch *swatch, swatch_activate (GtkColorSwatch *swatch,
GtkColorChooserWidget *cc) GtkColorChooserWidget *cc)
...@@ -163,7 +144,8 @@ swatch_selected (GtkColorSwatch *swatch, ...@@ -163,7 +144,8 @@ swatch_selected (GtkColorSwatch *swatch,
} }
static void static void
connect_swatch_signals (GtkWidget *p, gpointer data) connect_swatch_signals (GtkWidget *p,
gpointer data)
{ {
g_signal_connect (p, "activate", G_CALLBACK (swatch_activate), data); g_signal_connect (p, "activate", G_CALLBACK (swatch_activate), data);
g_signal_connect (p, "customize", G_CALLBACK (swatch_customize), data); g_signal_connect (p, "customize", G_CALLBACK (swatch_customize), data);
...@@ -171,17 +153,23 @@ connect_swatch_signals (GtkWidget *p, gpointer data) ...@@ -171,17 +153,23 @@ connect_swatch_signals (GtkWidget *p, gpointer data)
} }
static void static void
connect_button_signals (GtkWidget *p, gpointer data) button_activate (GtkColorSwatch *swatch,
GtkColorChooserWidget *cc)
{ {
g_signal_connect (p, "activate", G_CALLBACK (button_activate), data); /* 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);
} }
static void static void
connect_custom_signals (GtkWidget *p, gpointer data) connect_button_signals (GtkWidget *p,
gpointer data)
{ {
connect_swatch_signals (p, data); g_signal_connect (p, "activate", G_CALLBACK (button_activate), data);
g_signal_connect_swapped (p, "notify::color",
G_CALLBACK (save_custom_colors), data);
} }
static void static void
...@@ -200,16 +188,72 @@ save_custom_colors (GtkColorChooserWidget *cc) ...@@ -200,16 +188,72 @@ save_custom_colors (GtkColorChooserWidget *cc)
{ {
i++; i++;
if (gtk_color_swatch_get_rgba (GTK_COLOR_SWATCH (child), &color)) if (gtk_color_swatch_get_rgba (GTK_COLOR_SWATCH (child), &color))
{ g_variant_builder_add (&builder, "(dddd)",
g_variant_builder_add (&builder, "(dddd)", color.red, color.green, color.blue, color.alpha);
color.red, color.green, color.blue, color.alpha);
}
} }
variant = g_variant_builder_end (&builder); variant = g_variant_builder_end (&builder);
g_settings_set_value (cc->priv->settings, "custom-colors", variant); g_settings_set_value (cc->priv->settings, "custom-colors", variant);
} }
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)
{
GtkWidget *grids[3];
gint i;
GList *children, *l;
GtkWidget *swatch;
cc->priv->use_alpha = use_alpha;
gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER (cc->priv->editor), use_alpha);
grids[0] = cc->priv->colors;
grids[1] = cc->priv->grays;
grids[2] = cc->priv->custom;
for (i = 0; i < 3; i++)
{
children = gtk_container_get_children (GTK_CONTAINER (grids[i]));
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);
}
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 void static void
gtk_color_chooser_widget_init (GtkColorChooserWidget *cc) gtk_color_chooser_widget_init (GtkColorChooserWidget *cc)
{ {
...@@ -290,7 +334,6 @@ gtk_color_chooser_widget_init (GtkColorChooserWidget *cc) ...@@ -290,7 +334,6 @@ gtk_color_chooser_widget_init (GtkColorChooserWidget *cc)
for (i = 0; i < 9; i++) for (i = 0; i < 9; i++)
{ {
gdk_rgba_parse (&color, default_grayscale[i]); gdk_rgba_parse (&color, default_grayscale[i]);
color.alpha = 1.0;
p = gtk_color_swatch_new (); p = gtk_color_swatch_new ();
connect_swatch_signals (p, cc); connect_swatch_signals (p, cc);
...@@ -378,6 +421,8 @@ gtk_color_chooser_widget_init (GtkColorChooserWidget *cc) ...@@ -378,6 +421,8 @@ gtk_color_chooser_widget_init (GtkColorChooserWidget *cc)
gtk_size_group_add_widget (cc->priv->size_group, alignment); gtk_size_group_add_widget (cc->priv->size_group, alignment);
} }
/* GObject implementation {{{1 */
static void static void
gtk_color_chooser_widget_get_property (GObject *object, gtk_color_chooser_widget_get_property (GObject *object,
guint prop_id, guint prop_id,
...@@ -409,44 +454,6 @@ gtk_color_chooser_widget_get_property (GObject *object, ...@@ -409,44 +454,6 @@ gtk_color_chooser_widget_get_property (GObject *object,
} }
} }
static void
gtk_color_chooser_widget_set_use_alpha (GtkColorChooserWidget *cc,
gboolean use_alpha)
{
GtkWidget *grids[3];
gint i;
GList *children, *l;
GtkWidget *swatch;
cc->priv->use_alpha = use_alpha;
gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER (cc->priv->editor), use_alpha);
grids[0] = cc->priv->colors;
grids[1] = cc->priv->grays;
grids[2] = cc->priv->custom;
for (i = 0; i < 3; i++)
{
children = gtk_container_get_children (GTK_CONTAINER (grids[i]));
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);
}
gtk_widget_queue_draw (GTK_WIDGET (cc));
}
static void
gtk_color_chooser_widget_set_show_editor (GtkColorChooserWidget *cc,
gboolean show_editor)
{
gtk_widget_set_visible (cc->priv->editor, show_editor);
gtk_widget_set_visible (cc->priv->palette, !show_editor);
}
static void static void
gtk_color_chooser_widget_set_property (GObject *object, gtk_color_chooser_widget_set_property (GObject *object,
guint prop_id, guint prop_id,
...@@ -514,6 +521,8 @@ gtk_color_chooser_widget_class_init (GtkColorChooserWidgetClass *class) ...@@ -514,6 +521,8 @@ gtk_color_chooser_widget_class_init (GtkColorChooserWidgetClass *class)
g_type_class_add_private (object_class, sizeof (GtkColorChooserWidgetPrivate)); g_type_class_add_private (object_class, sizeof (GtkColorChooserWidgetPrivate));
} }
/* GtkColorChooser implementation {{{1 */
static void static void
gtk_color_chooser_widget_get_rgba (GtkColorChooser *chooser, gtk_color_chooser_widget_get_rgba (GtkColorChooser *chooser,
GdkRGBA *color) GdkRGBA *color)
...@@ -615,6 +624,8 @@ gtk_color_chooser_widget_iface_init (GtkColorChooserInterface *iface) ...@@ -615,6 +624,8 @@ gtk_color_chooser_widget_iface_init (GtkColorChooserInterface *iface)
iface->set_rgba = gtk_color_chooser_widget_set_rgba; iface->set_rgba = gtk_color_chooser_widget_set_rgba;
} }
/* Public API {{{1 */
/** /**
* gtk_color_chooser_widget_new: * gtk_color_chooser_widget_new:
* *
...@@ -629,3 +640,5 @@ gtk_color_chooser_widget_new (void) ...@@ -629,3 +640,5 @@ gtk_color_chooser_widget_new (void)
{ {
return g_object_new (GTK_TYPE_COLOR_CHOOSER_WIDGET, NULL); return g_object_new (GTK_TYPE_COLOR_CHOOSER_WIDGET, NULL);
} }
/* vim:set foldmethod=marker: */
...@@ -30,16 +30,15 @@ ...@@ -30,16 +30,15 @@
#include "config.h" #include "config.h"
#include "gtkcolorchooserprivate.h"
#include "gtkcoloreditor.h" #include "gtkcoloreditor.h"
#include "gtkcolorchooserprivate.h"
#include "gtkcolorplane.h" #include "gtkcolorplane.h"
#include "gtkcolorscale.h" #include "gtkcolorscale.h"
#include "gtkcolorswatch.h" #include "gtkcolorswatch.h"
#include "gtkcolorutils.h" #include "gtkcolorutils.h"
#include "gtkgrid.h" #include "gtkgrid.h"
#include "gtkorientable.h" #include "gtkorientable.h"
#include "gtkaspectframe.h"
#include "gtkdrawingarea.h"
#include "gtkentry.h" #include "gtkentry.h"
#include "gtkoverlay.h" #include "gtkoverlay.h"
#include "gtkadjustment.h" #include "gtkadjustment.h"
...@@ -75,7 +74,7 @@ struct _GtkColorEditorPrivate ...@@ -75,7 +74,7 @@ struct _GtkColorEditorPrivate
GtkAdjustment *a_adj; GtkAdjustment *a_adj;
guint text_changed : 1; guint text_changed : 1;
guint use_alpha : 1; guint use_alpha : 1;
}; };
enum enum
...@@ -101,21 +100,15 @@ scale_round (gdouble value, gdouble scale) ...@@ -101,21 +100,15 @@ scale_round (gdouble value, gdouble scale)
} }
static void static void
update_entry (GtkColorEditor *editor) entry_set_rgba (GtkColorEditor *editor,
const GdkRGBA *color)
{ {
gchar *text; gchar *text;
gdouble h, s, v;
gdouble r, g, b;
h = gtk_adjustment_get_value (editor->priv->h_adj);
s = gtk_adjustment_get_value (editor->priv->s_adj);
v = gtk_adjustment_get_value (editor->priv->v_adj);
gtk_hsv_to_rgb (h, s, v, &r, &g, &b);
text = g_strdup_printf ("#%02X%02X%02X", text = g_strdup_printf ("#%02X%02X%02X",
scale_round (r, 255), scale_round (color->red, 255),
scale_round (g, 255), scale_round (color->green, 255),
scale_round (b, 255)); scale_round (color->blue, 255));
gtk_entry_set_text (GTK_ENTRY (editor->priv->entry), text); gtk_entry_set_text (GTK_ENTRY (editor->priv->entry), text);
editor->priv->text_changed = FALSE; editor->priv->text_changed = FALSE;
g_free (text); g_free (text);
...@@ -164,16 +157,20 @@ static void ...@@ -164,16 +157,20 @@ static void
hsv_changed (GtkColorEditor *editor) hsv_changed (GtkColorEditor *editor)
{ {
GdkRGBA color; GdkRGBA color;
gdouble h, s, v; gdouble h, s, v, a;
h = gtk_adjustment_get_value (editor->priv->h_adj); h = gtk_adjustment_get_value (editor->priv->h_adj);
s = gtk_adjustment_get_value (editor->priv->s_adj); s = gtk_adjustment_get_value (editor->priv->s_adj);
v = gtk_adjustment_get_value (editor->priv->v_adj); v = gtk_adjustment_get_value (editor->priv->v_adj);
a = gtk_adjustment_get_value (editor->priv->a_adj);
gtk_hsv_to_rgb (h, s, v, &color.red, &color.green, &color.blue); gtk_hsv_to_rgb (h, s, v, &color.red, &color.green, &color.blue);
color.alpha = gtk_adjustment_get_value (editor->priv->a_adj); color.alpha = a;
update_entry (editor);
gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (editor->priv->swatch), &color); gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (editor->priv->swatch), &color);
gtk_color_scale_set_rgba (GTK_COLOR_SCALE (editor->priv->a_slider), &color); gtk_color_scale_set_rgba (GTK_COLOR_SCALE (editor->priv->a_slider), &color);
entry_set_rgba (editor, &color);
g_object_notify (G_OBJECT (editor), "rgba"); g_object_notify (G_OBJECT (editor), "rgba");
} }
...@@ -300,7 +297,8 @@ get_child_position (GtkOverlay *overlay, ...@@ -300,7 +297,8 @@ get_child_position (GtkOverlay *overlay,
} }
static void static void
value_changed (GtkAdjustment *a, GtkAdjustment *as) value_changed (GtkAdjustment *a,
GtkAdjustment *as)
{ {
gdouble scale; gdouble scale;
...@@ -311,7 +309,8 @@ value_changed (GtkAdjustment *a, GtkAdjustment *as) ...@@ -311,7 +309,8 @@ value_changed (GtkAdjustment *a, GtkAdjustment *as)
} }
static GtkAdjustment * static GtkAdjustment *
scaled_adjustment (GtkAdjustment *a, gdouble scale) scaled_adjustment (GtkAdjustment *a,
gdouble scale)
{ {
GtkAdjustment *as; GtkAdjustment *as;
...@@ -329,7 +328,9 @@ scaled_adjustment (GtkAdjustment *a, gdouble scale) ...@@ -329,7 +328,9 @@ scaled_adjustment (GtkAdjustment *a, gdouble scale)
} }
static gboolean static gboolean
popup_draw (GtkWidget *popup, cairo_t *cr, GtkColorEditor *editor) popup_draw (GtkWidget *popup,
cairo_t *cr,
GtkColorEditor *editor)
{ {
GtkStyleContext *context; GtkStyleContext *context;
gint width, height; gint width, height;
...@@ -344,14 +345,40 @@ popup_draw (GtkWidget *popup, cairo_t *cr, GtkColorEditor *editor) ...@@ -344,14 +345,40 @@ popup_draw (GtkWidget *popup, cairo_t *cr, GtkColorEditor *editor)
return FALSE; return FALSE;
} }
static GtkWidget *
create_popup (GtkColorEditor *editor,
GtkWidget *attach,
GtkWidget *contents)
{
GtkWidget *popup;
popup = gtk_alignment_new (0.5, 0.5, 0, 0);
gtk_alignment_set_padding (GTK_ALIGNMENT (popup), 12, 12, 12, 12);
gtk_style_context_add_class (gtk_widget_get_style_context (popup), GTK_STYLE_CLASS_TOOLTIP);
gtk_container_add (GTK_CONTAINER (popup), contents);
gtk_widget_show_all (popup);
gtk_widget_hide (popup);
gtk_widget_set_no_show_all (popup, TRUE);
g_signal_connect (popup, "draw", G_CALLBACK (popup_draw), editor);
gtk_overlay_add_overlay (GTK_OVERLAY (editor->priv->overlay), popup);
g_signal_connect (attach, "popup-menu", G_CALLBACK (popup_edit), editor);
return popup;
}
static void static void
gtk_color_editor_init (GtkColorEditor *editor) gtk_color_editor_init (GtkColorEditor *editor)
{ {
GtkWidget *grid; GtkWidget *grid;
GtkWidget *box;
GtkWidget *slider; GtkWidget *slider;
GtkWidget *alignment; GtkWidget *alignment;
GtkAdjustment *adj; GtkWidget *entry;
GtkWidget *swatch;
GtkAdjustment *h_adj, *s_adj, *v_adj, *a_adj;
GdkRGBA transparent = { 0, 0, 0, 0 }; GdkRGBA transparent = { 0, 0, 0, 0 };
editor->priv = G_TYPE_INSTANCE_GET_PRIVATE (editor, editor->priv = G_TYPE_INSTANCE_GET_PRIVATE (editor,
...@@ -359,60 +386,53 @@ gtk_color_editor_init (GtkColorEditor *editor) ...@@ -359,60 +386,53 @@ gtk_color_editor_init (GtkColorEditor *editor)
GtkColorEditorPrivate); GtkColorEditorPrivate);
editor->priv->use_alpha = TRUE; editor->priv->use_alpha = TRUE;
editor->priv->h_adj = gtk_adjustment_new (0, 0, 1, 0.01, 0.1, 0); editor->priv->h_adj = h_adj = gtk_adjustment_new (0, 0, 1, 0.01, 0.1, 0);
editor->priv->s_adj = gtk_adjustment_new (0, 0, 1, 0.01, 0.1, 0); editor->priv->s_adj = s_adj = gtk_adjustment_new (0, 0, 1, 0.01, 0.1, 0);
editor->priv->v_adj = gtk_adjustment_new (0, 0, 1, 0.01, 0.1, 0); editor->priv->v_adj = v_adj = gtk_adjustment_new (0, 0, 1, 0.01, 0.1, 0);
editor->priv->a_adj = gtk_adjustment_new (0, 0, 1, 0.01, 0.1, 0); editor->priv->a_adj = a_adj = gtk_adjustment_new (0, 0, 1, 0.01, 0.1, 0);
g_object_ref_sink (editor->priv->h_adj);
g_object_ref_sink (editor->priv->s_adj);
g_object_ref_sink (editor->priv->v_adj);
g_object_ref_sink (editor->priv->a_adj);
g_signal_connect_swapped (editor->priv->h_adj, "value-changed",
G_CALLBACK (hsv_changed), editor);
g_signal_connect_swapped (editor->priv->s_adj, "value-changed",
G_CALLBACK (hsv_changed), editor);
g_signal_connect_swapped (editor->priv->a_adj, "value-changed",
G_CALLBACK (hsv_changed), editor);
g_signal_connect_swapped (editor->priv->v_adj, "value-changed",
G_CALLBACK (hsv_changed), editor);
gtk_widget_push_composite_child (); g_object_ref_sink (h_adj);
g_object_ref_sink (s_adj);
g_object_ref_sink (v_adj);
g_object_ref_sink (a_adj);
editor->priv->overlay = gtk_overlay_new (); g_signal_connect_swapped (h_adj, "value-changed", G_CALLBACK (hsv_changed), editor);
gtk_widget_override_background_color (editor->priv->overlay, 0, &transparent); g_signal_connect_swapped (s_adj, "value-changed", G_CALLBACK (hsv_changed), editor);
editor->priv->grid = grid = gtk_grid_new (); g_signal_connect_swapped (v_adj, "value-changed", G_CALLBACK (hsv_changed), editor);
gtk_grid_set_row_spacing (GTK_GRID (grid), 12); g_signal_connect_swapped (a_adj, "value-changed", G_CALLBACK (hsv_changed), editor);
gtk_grid_set_column_spacing (GTK_GRID (grid), 12);
gtk_widget_push_composite_child ();
editor->priv->swatch = gtk_color_swatch_new (); /* Construct the main UI */
gtk_widget_set_sensitive (editor->priv->swatch, FALSE); editor->priv->swatch = swatch = gtk_color_swatch_new ();
gtk_color_swatch_set_corner_radii (GTK_COLOR_SWATCH (editor->priv->swatch), 2, 2, 2, 2); gtk_widget_set_sensitive (swatch, FALSE);
gtk_color_swatch_set_corner_radii (GTK_COLOR_SWATCH (swatch), 2, 2, 2, 2);
editor->priv->entry = gtk_entry_new (); editor->priv->entry = entry = gtk_entry_new ();
g_signal_connect (editor->priv->entry, "activate", g_signal_connect (entry, "activate", G_CALLBACK (entry_apply), editor);
G_CALLBACK (entry_apply), editor); g_signal_connect (entry, "notify::text", G_CALLBACK (entry_text_changed), editor);
g_signal_connect (editor->priv->entry, "notify::text", g_signal_connect (entry, "focus-out-event", G_CALLBACK (entry_focus_out), editor);
G_CALLBACK (entry_text_changed), editor);
g_signal_connect (editor->priv->entry, "focus-out-event",
G_CALLBACK (entry_focus_out), editor);
editor->priv->h_slider = slider = gtk_color_scale_new (editor->priv->h_adj, editor->priv->h_slider = slider = gtk_color_scale_new (h_adj, GTK_COLOR_SCALE_HUE);
GTK_COLOR_SCALE_HUE);
gtk_orientable_set_orientation (GTK_ORIENTABLE (slider), GTK_ORIENTATION_VERTICAL); gtk_orientable_set_orientation (GTK_ORIENTABLE (slider), GTK_ORIENTATION_VERTICAL);
if (gtk_widget_get_direction (slider) == GTK_TEXT_DIR_RTL) if (gtk_widget_get_direction (slider) == GTK_TEXT_DIR_RTL)
gtk_style_context_add_class (gtk_widget_get_style_context (slider), GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE); gtk_style_context_add_class (gtk_widget_get_style_context (slider),
GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE);
else else
gtk_style_context_add_class (gtk_widget_get_style_context (slider), GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW); gtk_style_context_add_class (gtk_widget_get_style_context (slider),
GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW);
editor->priv->sv_plane = gtk_color_plane_new (h_adj, s_adj, v_adj);
gtk_widget_set_size_request (editor->priv->sv_plane, 300, 300);
editor->priv->a_slider = slider = gtk_color_scale_new (editor->priv->a_adj, editor->priv->a_slider = slider = gtk_color_scale_new (a_adj, GTK_COLOR_SCALE_ALPHA);
GTK_COLOR_SCALE_ALPHA);
gtk_orientable_set_orientation (GTK_ORIENTABLE (slider), GTK_ORIENTATION_HORIZONTAL); gtk_orientable_set_orientation (GTK_ORIENTABLE (slider), GTK_ORIENTATION_HORIZONTAL);
gtk_style_context_add_class (gtk_widget_get_style_context (slider), GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE); gtk_style_context_add_class (gtk_widget_get_style_context (slider),
GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE);
editor->priv->sv_plane = gtk_color_plane_new (editor->priv->h_adj, editor->priv->grid = grid = gtk_grid_new ();
editor->priv->s_adj, gtk_grid_set_row_spacing (GTK_GRID (grid), 12);
editor->priv->v_adj); gtk_grid_set_column_spacing (GTK_GRID (grid), 12);
gtk_widget_set_size_request (editor->priv->sv_plane, 300, 300);
gtk_grid_attach (GTK_GRID (grid), editor->priv->swatch, 1, 0, 1, 1); gtk_grid_attach (GTK_GRID (grid), editor->priv->swatch, 1, 0, 1, 1);
gtk_grid_attach (GTK_GRID (grid), editor->priv->entry, 2, 0, 1, 1); gtk_grid_attach (GTK_GRID (grid), editor->priv->entry, 2, 0, 1, 1);
...@@ -425,96 +445,60 @@ gtk_color_editor_init (GtkColorEditor *editor) ...@@ -425,96 +445,60 @@ gtk_color_editor_init (GtkColorEditor *editor)
*/ */
alignment = gtk_alignment_new (0.5, 0.5, 0, 0); alignment = gtk_alignment_new (0.5, 0.5, 0, 0);
gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 30, 30); gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 30, 30);
gtk_container_add (GTK_CONTAINER (editor->priv->overlay), alignment);
gtk_container_add (GTK_CONTAINER (alignment), grid); gtk_container_add (GTK_CONTAINER (alignment), grid);
editor->priv->sv_popup = gtk_alignment_new (0.5, 0.5, 0, 0); editor->priv->overlay = gtk_overlay_new ();
gtk_style_context_add_class (gtk_widget_get_style_context (editor->priv->sv_popup), gtk_widget_override_background_color (editor->priv->overlay, 0, &transparent);
GTK_STYLE_CLASS_TOOLTIP); gtk_container_add (GTK_CONTAINER (editor->priv->overlay), alignment);
gtk_alignment_set_padding (GTK_ALIGNMENT (editor->priv->sv_popup), 12, 12, 12, 12);
/* Construct the sv popup */
editor->priv->s_entry = entry = gtk_spin_button_new (scaled_adjustment (s_adj, 100), 1, 0);
g_signal_connect (entry, "key-press-event", G_CALLBACK (popup_key_press), editor);
editor->priv->v_entry = entry = gtk_spin_button_new (scaled_adjustment (v_adj, 100), 1, 0);
g_signal_connect (entry, "key-press-event", G_CALLBACK (popup_key_press), editor);
grid = gtk_grid_new (); grid = gtk_grid_new ();
gtk_grid_set_column_spacing (GTK_GRID (grid), 6); gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
adj = scaled_adjustment (editor->priv->s_adj, 100);
editor->priv->s_entry = gtk_spin_button_new (adj, 1, 0);
g_signal_connect (editor->priv->s_entry, "key-press-event",
G_CALLBACK (popup_key_press), editor);
adj = scaled_adjustment (editor->priv->v_adj, 100);
editor->priv->v_entry = gtk_spin_button_new (adj, 1, 0);
g_signal_connect (editor->priv->v_entry, "key-press-event",
G_CALLBACK (popup_key_press), editor);
gtk_container_add (GTK_CONTAINER (editor->priv->sv_popup), grid);
gtk_grid_attach (GTK_GRID (grid), gtk_label_new (C_("Color channel", "S")), 0, 0, 1, 1); gtk_grid_attach (GTK_GRID (grid), gtk_label_new (C_("Color channel", "S")), 0, 0, 1, 1);
gtk_grid_attach (GTK_GRID (grid), editor->priv->s_entry, 1, 0, 1, 1); gtk_grid_attach (GTK_GRID (grid), editor->priv->s_entry, 1, 0, 1, 1);
gtk_grid_attach (GTK_GRID (grid), gtk_label_new (C_("Color channel", "V")), 0, 1, 1, 1); gtk_grid_attach (GTK_GRID (grid), gtk_label_new (C_("Color channel", "V")), 0, 1, 1, 1);
gtk_grid_attach (GTK_GRID (grid), editor->priv->v_entry, 1, 1, 1, 1); gtk_grid_attach (GTK_GRID (grid), editor->priv->v_entry, 1, 1, 1, 1);