~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to libgimpwidgets/gimpcolorselection.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include <gtk/gtk.h>
26
26
 
27
27
#include "libgimpcolor/gimpcolor.h"
 
28
#include "libgimpconfig/gimpconfig.h"
28
29
 
29
30
#include "gimpwidgetstypes.h"
30
31
 
50
51
{
51
52
  UPDATE_NOTEBOOK  = 1 << 0,
52
53
  UPDATE_SCALES    = 1 << 1,
53
 
  UPDATE_NEW_COLOR = 1 << 2
 
54
  UPDATE_ENTRY     = 1 << 2,
 
55
  UPDATE_COLOR     = 1 << 3
54
56
} UpdateType;
55
57
 
 
58
#define UPDATE_ALL (UPDATE_NOTEBOOK | \
 
59
                    UPDATE_SCALES   | \
 
60
                    UPDATE_ENTRY    | \
 
61
                    UPDATE_COLOR)
 
62
 
56
63
enum
57
64
{
58
65
  COLOR_CHANGED,
59
66
  LAST_SIGNAL
60
67
};
61
68
 
62
 
 
63
 
static void   gimp_color_selection_class_init (GimpColorSelectionClass *klass);
64
 
static void   gimp_color_selection_init       (GimpColorSelection      *selection);
 
69
enum
 
70
{
 
71
  PROP_0,
 
72
  PROP_CONFIG
 
73
};
 
74
 
 
75
 
 
76
static void   gimp_color_selection_set_property      (GObject            *object,
 
77
                                                      guint               property_id,
 
78
                                                      const GValue       *value,
 
79
                                                      GParamSpec         *pspec);
65
80
 
66
81
static void   gimp_color_selection_switch_page       (GtkWidget          *widget,
67
82
                                                      GtkNotebookPage    *page,
75
90
                                                      const GimpRGB      *rgb,
76
91
                                                      const GimpHSV      *hsv,
77
92
                                                      GimpColorSelection *selection);
 
93
static void   gimp_color_selection_color_picked      (GtkWidget          *widget,
 
94
                                                      const GimpRGB      *rgb,
 
95
                                                      GimpColorSelection *selection);
 
96
static void   gimp_color_selection_entry_changed     (GimpColorHexEntry  *entry,
 
97
                                                      GimpColorSelection *selection);
78
98
static void   gimp_color_selection_channel_changed   (GimpColorSelector  *selector,
79
99
                                                      GimpColorSelectorChannel channel,
80
100
                                                      GimpColorSelection *selection);
85
105
                                                      UpdateType          update);
86
106
 
87
107
 
88
 
static GtkVBoxClass *parent_class = NULL;
89
 
 
90
 
static guint  selection_signals[LAST_SIGNAL] = { 0 };
91
 
 
92
 
 
93
 
GType
94
 
gimp_color_selection_get_type (void)
95
 
{
96
 
  static GType selection_type = 0;
97
 
 
98
 
  if (! selection_type)
99
 
    {
100
 
      static const GTypeInfo selection_info =
101
 
      {
102
 
        sizeof (GimpColorSelectionClass),
103
 
        (GBaseInitFunc) NULL,
104
 
        (GBaseFinalizeFunc) NULL,
105
 
        (GClassInitFunc) gimp_color_selection_class_init,
106
 
        NULL,           /* class_finalize */
107
 
        NULL,           /* class_data     */
108
 
        sizeof (GimpColorSelection),
109
 
        0,              /* n_preallocs    */
110
 
        (GInstanceInitFunc) gimp_color_selection_init,
111
 
      };
112
 
 
113
 
      selection_type = g_type_register_static (GTK_TYPE_VBOX,
114
 
                                              "GimpColorSelection",
115
 
                                              &selection_info, 0);
116
 
    }
117
 
 
118
 
  return selection_type;
119
 
}
 
108
G_DEFINE_TYPE (GimpColorSelection, gimp_color_selection, GTK_TYPE_VBOX)
 
109
 
 
110
#define parent_class gimp_color_selection_parent_class
 
111
 
 
112
static guint selection_signals[LAST_SIGNAL] = { 0 };
 
113
 
120
114
 
121
115
static void
122
116
gimp_color_selection_class_init (GimpColorSelectionClass *klass)
123
117
{
124
 
  parent_class = g_type_class_peek_parent (klass);
 
118
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
119
 
 
120
  object_class->set_property = gimp_color_selection_set_property;
 
121
 
 
122
  klass->color_changed       = NULL;
 
123
 
 
124
  g_object_class_install_property (object_class, PROP_CONFIG,
 
125
                                   g_param_spec_object ("config",
 
126
                                                        NULL, NULL,
 
127
                                                        GIMP_TYPE_COLOR_CONFIG,
 
128
                                                        G_PARAM_WRITABLE));
125
129
 
126
130
  selection_signals[COLOR_CHANGED] =
127
 
    g_signal_new ("color_changed",
 
131
    g_signal_new ("color-changed",
128
132
                  G_TYPE_FROM_CLASS (klass),
129
133
                  G_SIGNAL_RUN_FIRST,
130
134
                  G_STRUCT_OFFSET (GimpColorSelectionClass, color_changed),
132
136
                  g_cclosure_marshal_VOID__VOID,
133
137
                  G_TYPE_NONE, 0);
134
138
 
135
 
  klass->color_changed = NULL;
136
139
}
137
140
 
138
141
static void
141
144
  GtkWidget *main_hbox;
142
145
  GtkWidget *frame;
143
146
  GtkWidget *table;
 
147
  GtkWidget *hbox;
 
148
  GtkWidget *label;
 
149
  GtkWidget *entry;
 
150
  GtkWidget *button;
144
151
 
145
152
  selection->show_alpha = TRUE;
146
153
 
179
186
                      TRUE, TRUE, 0);
180
187
  gtk_widget_show (selection->notebook);
181
188
 
182
 
  g_signal_connect (selection->notebook, "color_changed",
 
189
  g_signal_connect (selection->notebook, "color-changed",
183
190
                    G_CALLBACK (gimp_color_selection_notebook_changed),
184
191
                    selection);
185
192
  g_signal_connect (GIMP_COLOR_NOTEBOOK (selection->notebook)->notebook,
186
 
                    "switch_page",
 
193
                    "switch-page",
187
194
                    G_CALLBACK (gimp_color_selection_switch_page),
188
195
                    selection);
189
196
 
200
207
  gtk_widget_set_size_request (frame, -1, COLOR_AREA_SIZE);
201
208
 
202
209
  gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
203
 
                             _("Current:"), 1.0, 0.5,
204
 
                             frame, 1, FALSE);
 
210
                             _("Current:"), 1.0, 0.5,
 
211
                             frame, 1, FALSE);
205
212
 
206
213
  selection->new_color = gimp_color_area_new (&selection->rgb,
207
214
                                              selection->show_alpha ?
212
219
  gtk_container_add (GTK_CONTAINER (frame), selection->new_color);
213
220
  gtk_widget_show (selection->new_color);
214
221
 
215
 
  g_signal_connect (selection->new_color, "color_changed",
216
 
                    G_CALLBACK (gimp_color_selection_new_color_changed),
217
 
                    selection);
 
222
  g_signal_connect (selection->new_color, "color-changed",
 
223
                    G_CALLBACK (gimp_color_selection_new_color_changed),
 
224
                    selection);
218
225
 
219
226
  /*  The old color area  */
220
227
  frame = gtk_frame_new (NULL);
222
229
  gtk_widget_set_size_request (frame, -1, COLOR_AREA_SIZE);
223
230
 
224
231
  gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
225
 
                             _("Old:"), 1.0, 0.5,
226
 
                             frame, 1, FALSE);
 
232
                             _("Old:"), 1.0, 0.5,
 
233
                             frame, 1, FALSE);
227
234
 
228
235
  selection->old_color = gimp_color_area_new (&selection->rgb,
229
236
                                              selection->show_alpha ?
253
260
                      TRUE, TRUE, 0);
254
261
  gtk_widget_show (selection->scales);
255
262
 
256
 
  g_signal_connect (selection->scales, "channel_changed",
 
263
  g_signal_connect (selection->scales, "channel-changed",
257
264
                    G_CALLBACK (gimp_color_selection_channel_changed),
258
265
                    selection);
259
 
  g_signal_connect (selection->scales, "color_changed",
 
266
  g_signal_connect (selection->scales, "color-changed",
260
267
                    G_CALLBACK (gimp_color_selection_scales_changed),
261
268
                    selection);
262
 
}
 
269
 
 
270
  hbox = gtk_hbox_new (FALSE, 6);
 
271
  gtk_box_pack_start (GTK_BOX (selection->right_vbox), hbox, FALSE, FALSE, 0);
 
272
  gtk_widget_show (hbox);
 
273
 
 
274
  /*  The color picker  */
 
275
  button = gimp_pick_button_new ();
 
276
  gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
 
277
  gtk_widget_show (button);
 
278
 
 
279
  g_signal_connect (button, "color-picked",
 
280
                    G_CALLBACK (gimp_color_selection_color_picked),
 
281
                    selection);
 
282
 
 
283
  /* The hex triplet entry */
 
284
  entry = gimp_color_hex_entry_new ();
 
285
  gimp_help_set_help_data (entry,
 
286
                           _("Hexadecimal color notation as used in HTML and "
 
287
                             "CSS.  This entry also accepts CSS color names."),
 
288
                           NULL);
 
289
  gtk_box_pack_end (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
 
290
  gtk_widget_show (entry);
 
291
 
 
292
  label = gtk_label_new_with_mnemonic (_("HTML _notation:"));
 
293
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
 
294
  gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0);
 
295
  gtk_widget_show (label);
 
296
 
 
297
  g_object_set_data (G_OBJECT (selection), "color-hex-entry", entry);
 
298
 
 
299
  g_signal_connect (entry, "color-changed",
 
300
                    G_CALLBACK (gimp_color_selection_entry_changed),
 
301
                    selection);
 
302
}
 
303
 
 
304
static void
 
305
gimp_color_selection_set_property (GObject      *object,
 
306
                                   guint         property_id,
 
307
                                   const GValue *value,
 
308
                                   GParamSpec   *pspec)
 
309
{
 
310
  GimpColorSelection *selection = GIMP_COLOR_SELECTION (object);
 
311
 
 
312
  switch (property_id)
 
313
    {
 
314
    case PROP_CONFIG:
 
315
      gimp_color_selection_set_config (selection, g_value_get_object (value));
 
316
      break;
 
317
 
 
318
    default:
 
319
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
320
      break;
 
321
    }
 
322
}
 
323
 
263
324
 
264
325
/**
265
326
 * gimp_color_selection_new:
340
401
  selection->rgb = *color;
341
402
  gimp_rgb_to_hsv (&selection->rgb, &selection->hsv);
342
403
 
343
 
  gimp_color_selection_update (selection,
344
 
                               UPDATE_NOTEBOOK   |
345
 
                               UPDATE_SCALES     |
346
 
                               UPDATE_NEW_COLOR);
 
404
  gimp_color_selection_update (selection, UPDATE_ALL);
347
405
 
348
406
  gimp_color_selection_color_changed (selection);
349
407
}
420
478
 * gimp_color_selection_color_changed:
421
479
 * @selection: A #GimpColorSelection widget.
422
480
 *
423
 
 * Emits the "color_changed" signal.
 
481
 * Emits the "color-changed" signal.
424
482
 **/
425
483
void
426
484
gimp_color_selection_color_changed (GimpColorSelection *selection)
430
488
  g_signal_emit (selection, selection_signals[COLOR_CHANGED], 0);
431
489
}
432
490
 
 
491
/**
 
492
 * gimp_color_selection_set_config:
 
493
 * @selection:
 
494
 * @config:
 
495
 *
 
496
 * Sets the color management configuration to use with this color selection.
 
497
 *
 
498
 * Since: GIMP 2.4
 
499
 */
 
500
void
 
501
gimp_color_selection_set_config (GimpColorSelection *selection,
 
502
                                 GimpColorConfig    *config)
 
503
{
 
504
  g_return_if_fail (GIMP_IS_COLOR_SELECTION (selection));
 
505
  g_return_if_fail (config == NULL || GIMP_IS_COLOR_CONFIG (config));
 
506
 
 
507
  gimp_color_selector_set_config (GIMP_COLOR_SELECTOR (selection->notebook),
 
508
                                  config);
 
509
  gimp_color_selector_set_config (GIMP_COLOR_SELECTOR (selection->scales),
 
510
                                  config);
 
511
}
433
512
 
434
513
/*  private functions  */
435
514
 
458
537
  selection->hsv = *hsv;
459
538
  selection->rgb = *rgb;
460
539
 
461
 
  gimp_color_selection_update (selection, UPDATE_SCALES | UPDATE_NEW_COLOR);
 
540
  gimp_color_selection_update (selection,
 
541
                               UPDATE_SCALES | UPDATE_ENTRY | UPDATE_COLOR);
462
542
  gimp_color_selection_color_changed (selection);
463
543
}
464
544
 
471
551
  selection->rgb = *rgb;
472
552
  selection->hsv = *hsv;
473
553
 
474
 
  gimp_color_selection_update (selection, UPDATE_NOTEBOOK | UPDATE_NEW_COLOR);
 
554
  gimp_color_selection_update (selection,
 
555
                               UPDATE_ENTRY | UPDATE_NOTEBOOK | UPDATE_COLOR);
 
556
  gimp_color_selection_color_changed (selection);
 
557
}
 
558
 
 
559
static void
 
560
gimp_color_selection_color_picked (GtkWidget          *widget,
 
561
                                   const GimpRGB      *rgb,
 
562
                                   GimpColorSelection *selection)
 
563
{
 
564
  gimp_color_selection_set_color (selection, rgb);
 
565
}
 
566
 
 
567
static void
 
568
gimp_color_selection_entry_changed (GimpColorHexEntry  *entry,
 
569
                                    GimpColorSelection *selection)
 
570
{
 
571
  gimp_color_hex_entry_get_color (entry, &selection->rgb);
 
572
 
 
573
  gimp_rgb_to_hsv (&selection->rgb, &selection->hsv);
 
574
 
 
575
  gimp_color_selection_update (selection,
 
576
                               UPDATE_NOTEBOOK | UPDATE_SCALES | UPDATE_COLOR);
475
577
  gimp_color_selection_color_changed (selection);
476
578
}
477
579
 
493
595
  gimp_color_area_get_color (GIMP_COLOR_AREA (widget), &selection->rgb);
494
596
  gimp_rgb_to_hsv (&selection->rgb, &selection->hsv);
495
597
 
496
 
  gimp_color_selection_update (selection, UPDATE_NOTEBOOK | UPDATE_SCALES);
 
598
  gimp_color_selection_update (selection,
 
599
                               UPDATE_NOTEBOOK | UPDATE_SCALES | UPDATE_ENTRY);
497
600
  gimp_color_selection_color_changed (selection);
498
601
}
499
602
 
531
634
                                         selection);
532
635
    }
533
636
 
534
 
  if (update & UPDATE_NEW_COLOR)
 
637
  if (update & UPDATE_ENTRY)
 
638
    {
 
639
      GimpColorHexEntry *entry;
 
640
 
 
641
      entry = g_object_get_data (G_OBJECT (selection), "color-hex-entry");
 
642
 
 
643
      g_signal_handlers_block_by_func (entry,
 
644
                                       gimp_color_selection_entry_changed,
 
645
                                       selection);
 
646
 
 
647
      gimp_color_hex_entry_set_color (entry, &selection->rgb);
 
648
 
 
649
      g_signal_handlers_unblock_by_func (entry,
 
650
                                         gimp_color_selection_entry_changed,
 
651
                                         selection);
 
652
    }
 
653
 
 
654
  if (update & UPDATE_COLOR)
535
655
    {
536
656
      g_signal_handlers_block_by_func (selection->new_color,
537
657
                                       gimp_color_selection_new_color_changed,
538
 
                                       selection);
 
658
                                       selection);
539
659
 
540
660
      gimp_color_area_set_color (GIMP_COLOR_AREA (selection->new_color),
541
 
                                 &selection->rgb);
 
661
                                 &selection->rgb);
542
662
 
543
663
      g_signal_handlers_unblock_by_func (selection->new_color,
544
 
                                         gimp_color_selection_new_color_changed,
545
 
                                         selection);
 
664
                                         gimp_color_selection_new_color_changed,
 
665
                                         selection);
546
666
    }
547
667
}