32
32
#include "widgets-types.h"
34
#include "config/gimpcoreconfig.h"
36
#include "core/gimp.h"
34
37
#include "core/gimpcontext.h"
36
39
#include "gimpcoloreditor.h"
37
40
#include "gimpdocked.h"
38
41
#include "gimpfgbgeditor.h"
42
#include "gimpfgbgview.h"
39
43
#include "gimpsessioninfo.h"
41
45
#include "gimp-intl.h"
44
static void gimp_color_editor_class_init (GimpColorEditorClass *klass);
45
static void gimp_color_editor_init (GimpColorEditor *editor);
46
static void gimp_color_editor_docked_iface_init (GimpDockedInterface *docked_iface);
55
static void gimp_color_editor_docked_iface_init (GimpDockedInterface *iface);
57
static void gimp_color_editor_set_property (GObject *object,
61
static void gimp_color_editor_get_property (GObject *object,
48
66
static void gimp_color_editor_destroy (GtkObject *object);
49
68
static void gimp_color_editor_style_set (GtkWidget *widget,
50
69
GtkStyle *prev_style);
52
71
static void gimp_color_editor_set_aux_info (GimpDocked *docked,
54
73
static GList *gimp_color_editor_get_aux_info (GimpDocked *docked);
74
static GtkWidget *gimp_color_editor_get_preview (GimpDocked *docked,
55
77
static void gimp_color_editor_set_context (GimpDocked *docked,
56
78
GimpContext *context);
58
static void gimp_color_editor_destroy (GtkObject *object);
60
80
static void gimp_color_editor_fg_changed (GimpContext *context,
61
81
const GimpRGB *rgb,
62
82
GimpColorEditor *editor);
75
95
static void gimp_color_editor_color_picked (GtkWidget *widget,
76
96
const GimpRGB *rgb,
77
97
GimpColorEditor *editor);
80
static GimpEditorClass *parent_class = NULL;
84
gimp_color_editor_get_type (void)
86
static GType type = 0;
90
static const GTypeInfo editor_info =
92
sizeof (GimpColorEditorClass),
94
(GBaseFinalizeFunc) NULL,
95
(GClassInitFunc) gimp_color_editor_class_init,
96
NULL, /* class_finalize */
97
NULL, /* class_data */
98
sizeof (GimpColorEditor),
100
(GInstanceInitFunc) gimp_color_editor_init,
102
static const GInterfaceInfo docked_iface_info =
104
(GInterfaceInitFunc) gimp_color_editor_docked_iface_init,
105
NULL, /* iface_finalize */
106
NULL /* iface_data */
109
type = g_type_register_static (GIMP_TYPE_EDITOR,
113
g_type_add_interface_static (type, GIMP_TYPE_DOCKED,
98
static void gimp_color_editor_entry_changed (GimpColorHexEntry *entry,
99
GimpColorEditor *editor);
102
G_DEFINE_TYPE_WITH_CODE (GimpColorEditor, gimp_color_editor, GIMP_TYPE_EDITOR,
103
G_IMPLEMENT_INTERFACE (GIMP_TYPE_DOCKED,
104
gimp_color_editor_docked_iface_init))
106
#define parent_class gimp_color_editor_parent_class
108
static GimpDockedInterface *parent_docked_iface = NULL;
121
112
gimp_color_editor_class_init (GimpColorEditorClass* klass)
123
GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
124
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
126
parent_class = g_type_class_peek_parent (klass);
128
object_class->destroy = gimp_color_editor_destroy;
130
widget_class->style_set = gimp_color_editor_style_set;
114
GObjectClass *object_class = G_OBJECT_CLASS (klass);
115
GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass);
116
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
118
object_class->set_property = gimp_color_editor_set_property;
119
object_class->get_property = gimp_color_editor_get_property;
121
gtk_object_class->destroy = gimp_color_editor_destroy;
123
widget_class->style_set = gimp_color_editor_style_set;
125
g_object_class_install_property (object_class, PROP_CONTEXT,
126
g_param_spec_object ("context",
129
GIMP_PARAM_READWRITE));
133
gimp_color_editor_docked_iface_init (GimpDockedInterface *iface)
135
parent_docked_iface = g_type_interface_peek_parent (iface);
137
if (! parent_docked_iface)
138
parent_docked_iface = g_type_default_interface_peek (GIMP_TYPE_DOCKED);
140
iface->get_preview = gimp_color_editor_get_preview;
141
iface->set_aux_info = gimp_color_editor_set_aux_info;
142
iface->get_aux_info = gimp_color_editor_get_aux_info;
143
iface->set_context = gimp_color_editor_set_context;
134
147
gimp_color_editor_init (GimpColorEditor *editor)
136
149
GtkWidget *notebook;
137
153
gint content_spacing;
138
154
gint button_spacing;
139
155
GtkIconSize button_icon_size;
149
165
gimp_rgb_to_hsv (&rgb, &hsv);
151
167
gtk_widget_style_get (GTK_WIDGET (editor),
152
"content_spacing", &content_spacing,
153
"button_spacing", &button_spacing,
154
"button_icon_size", &button_icon_size,
168
"content-spacing", &content_spacing,
169
"button-spacing", &button_spacing,
170
"button-icon-size", &button_icon_size,
157
173
editor->hbox = gtk_hbox_new (TRUE, button_spacing);
158
174
gtk_box_pack_start (GTK_BOX (editor), editor->hbox, FALSE, FALSE, 0);
218
/* The color picker */
222
button = gimp_pick_button_new ();
223
gtk_box_pack_start (GTK_BOX (editor->hbox), button, TRUE, TRUE, 0);
224
gtk_widget_show (button);
226
g_signal_connect (button, "color_picked",
227
G_CALLBACK (gimp_color_editor_color_picked),
234
hbox = gtk_hbox_new (TRUE, 6);
235
gtk_box_pack_start (GTK_BOX (editor), hbox, FALSE, FALSE, 0);
236
gtk_widget_show (hbox);
231
238
/* FG/BG editor */
232
239
editor->fg_bg = gimp_fg_bg_editor_new (NULL);
233
gtk_widget_set_size_request (editor->fg_bg, -1, 48);
234
gtk_box_pack_start (GTK_BOX (editor), editor->fg_bg, FALSE, FALSE, 0);
240
gtk_box_pack_start (GTK_BOX (hbox), editor->fg_bg, TRUE, TRUE, 0);
235
241
gtk_widget_show (editor->fg_bg);
237
243
g_signal_connect (editor->fg_bg, "notify::active-color",
238
244
G_CALLBACK (gimp_color_editor_fg_bg_notify),
243
gimp_color_editor_docked_iface_init (GimpDockedInterface *docked_iface)
245
docked_iface->set_aux_info = gimp_color_editor_set_aux_info;
246
docked_iface->get_aux_info = gimp_color_editor_get_aux_info;
247
docked_iface->set_context = gimp_color_editor_set_context;
247
vbox = gtk_vbox_new (FALSE, 3);
248
gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
249
gtk_widget_show (vbox);
251
/* The color picker */
252
button = gimp_pick_button_new ();
253
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
254
gtk_widget_show (button);
256
g_signal_connect (button, "color-picked",
257
G_CALLBACK (gimp_color_editor_color_picked),
260
/* The hex triplet entry */
261
editor->hex_entry = gimp_color_hex_entry_new ();
262
gimp_help_set_help_data (editor->hex_entry,
263
_("Hexadecimal color notation as used in HTML and "
264
"CSS. This entry also accepts CSS color names."),
266
gtk_box_pack_end (GTK_BOX (vbox), editor->hex_entry, FALSE, FALSE, 0);
267
gtk_widget_show (editor->hex_entry);
269
g_signal_connect (editor->hex_entry, "color-changed",
270
G_CALLBACK (gimp_color_editor_entry_changed),
275
gimp_color_editor_set_property (GObject *object,
283
gimp_docked_set_context (GIMP_DOCKED (object),
284
g_value_get_object (value));
287
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
293
gimp_color_editor_get_property (GObject *object,
298
GimpColorEditor *editor = GIMP_COLOR_EDITOR (object);
303
g_value_set_object (value, editor->context);
306
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
312
gimp_color_editor_destroy (GtkObject *object)
314
GimpColorEditor *editor = GIMP_COLOR_EDITOR (object);
317
gimp_docked_set_context (GIMP_DOCKED (editor), NULL);
319
GTK_OBJECT_CLASS (parent_class)->destroy (object);
323
gimp_color_editor_get_preview (GimpDocked *docked,
324
GimpContext *context,
327
GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (docked));
332
preview = gimp_fg_bg_view_new (context);
334
if (gtk_icon_size_lookup_for_settings (settings, size, &width, &height))
335
gtk_widget_set_size_request (preview, width, height);
250
340
#define AUX_INFO_CURRENT_PAGE "current-page"
320
414
if (editor->context)
322
416
g_signal_handlers_disconnect_by_func (editor->context,
323
gimp_color_editor_fg_changed,
417
gimp_color_editor_fg_changed,
325
419
g_signal_handlers_disconnect_by_func (editor->context,
326
gimp_color_editor_bg_changed,
420
gimp_color_editor_bg_changed,
329
423
g_object_unref (editor->context);
330
editor->context = NULL;
426
editor->context = context;
337
editor->context = g_object_ref (context);
432
g_object_ref (editor->context);
339
g_signal_connect (editor->context, "foreground_changed",
340
G_CALLBACK (gimp_color_editor_fg_changed),
342
g_signal_connect (editor->context, "background_changed",
343
G_CALLBACK (gimp_color_editor_bg_changed),
434
g_signal_connect (editor->context, "foreground-changed",
435
G_CALLBACK (gimp_color_editor_fg_changed),
437
g_signal_connect (editor->context, "background-changed",
438
G_CALLBACK (gimp_color_editor_bg_changed),
346
441
if (editor->edit_bg)
353
448
gimp_context_get_foreground (editor->context, &rgb);
354
449
gimp_color_editor_fg_changed (editor->context, &rgb, editor);
452
g_object_set_data (G_OBJECT (context->gimp->config->color_management),
453
"gimp-context", editor->context);
455
gimp_color_selector_set_config (GIMP_COLOR_SELECTOR (editor->notebook),
456
context->gimp->config->color_management);
458
g_object_set_data (G_OBJECT (context->gimp->config->color_management),
459
"gimp-context", NULL);
358
462
gimp_fg_bg_editor_set_context (GIMP_FG_BG_EDITOR (editor->fg_bg), context);
362
gimp_color_editor_destroy (GtkObject *object)
364
GimpColorEditor *editor = GIMP_COLOR_EDITOR (object);
367
gimp_docked_set_context (GIMP_DOCKED (editor), NULL);
369
GTK_OBJECT_CLASS (parent_class)->destroy (object);
373
/* public functions */
376
466
gimp_color_editor_new (GimpContext *context)
378
GimpColorEditor *editor;
380
g_return_val_if_fail (context == NULL || GIMP_IS_CONTEXT (context), NULL);
382
editor = g_object_new (GIMP_TYPE_COLOR_EDITOR, NULL);
385
gimp_docked_set_context (GIMP_DOCKED (editor), context);
387
return GTK_WIDGET (editor);
468
return g_object_new (GIMP_TYPE_COLOR_EDITOR,
404
/* public functions */
488
gimp_color_editor_set_color (GimpColorEditor *editor,
493
gimp_rgb_to_hsv (rgb, &hsv);
495
g_signal_handlers_block_by_func (editor->notebook,
496
gimp_color_editor_color_changed,
499
gimp_color_selector_set_color (GIMP_COLOR_SELECTOR (editor->notebook),
502
g_signal_handlers_unblock_by_func (editor->notebook,
503
gimp_color_editor_color_changed,
506
g_signal_handlers_block_by_func (editor->hex_entry,
507
gimp_color_editor_entry_changed,
510
gimp_color_hex_entry_set_color (GIMP_COLOR_HEX_ENTRY (editor->hex_entry),
513
g_signal_handlers_unblock_by_func (editor->hex_entry,
514
gimp_color_editor_entry_changed,
407
519
gimp_color_editor_fg_changed (GimpContext *context,