gimpcolorselection.c 24.3 KB
Newer Older
1 2 3 4 5 6
/* LIBGIMP - The GIMP Library
 * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
 *
 * gimpcolorselection.c
 * Copyright (C) 2003 Michael Natterer <mitch@gimp.org>
 *
7
 * This library is free software: you can redistribute it and/or
8 9
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
10
 * version 3 of the License, or (at your option) any later version.
11
 *
12
 * This library is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18 19
 * License along with this library.  If not, see
 * <http://www.gnu.org/licenses/>.
20 21 22 23
 */

#include "config.h"

24
#include <gegl.h>
25 26 27
#include <gtk/gtk.h>

#include "libgimpcolor/gimpcolor.h"
28
#include "libgimpconfig/gimpconfig.h"
29 30 31 32 33 34

#include "gimpwidgetstypes.h"

#include "gimpcolorarea.h"
#include "gimpcolornotebook.h"
#include "gimpcolorscales.h"
35
#include "gimpcolorselect.h"
36 37
#include "gimpcolorselection.h"
#include "gimphelpui.h"
38
#include "gimpicons.h"
39
#include "gimpwidgets.h"
40 41
#include "gimpwidgets-private.h"

42 43 44 45 46
#include "gimpwidgetsmarshal.h"

#include "libgimp/libgimp-intl.h"


47 48 49 50 51 52 53 54 55
/**
 * SECTION: gimpcolorselection
 * @title: GimpColorSelection
 * @short_description: Widget for doing a color selection.
 *
 * Widget for doing a color selection.
 **/


56 57 58 59 60 61 62
#define COLOR_AREA_SIZE  20


typedef enum
{
  UPDATE_NOTEBOOK  = 1 << 0,
  UPDATE_SCALES    = 1 << 1,
63 64
  UPDATE_ENTRY     = 1 << 2,
  UPDATE_COLOR     = 1 << 3
65 66
} UpdateType;

67 68 69 70 71
#define UPDATE_ALL (UPDATE_NOTEBOOK | \
                    UPDATE_SCALES   | \
                    UPDATE_ENTRY    | \
                    UPDATE_COLOR)

72 73 74 75 76 77
enum
{
  COLOR_CHANGED,
  LAST_SIGNAL
};

78 79 80 81 82 83 84 85 86 87 88
enum
{
  PROP_0,
  PROP_CONFIG
};


static void   gimp_color_selection_set_property      (GObject            *object,
                                                      guint               property_id,
                                                      const GValue       *value,
                                                      GParamSpec         *pspec);
89 90

static void   gimp_color_selection_switch_page       (GtkWidget          *widget,
91
                                                      gpointer            page,
92 93 94 95 96 97 98 99 100 101
                                                      guint               page_num,
                                                      GimpColorSelection *selection);
static void   gimp_color_selection_notebook_changed  (GimpColorSelector  *selector,
                                                      const GimpRGB      *rgb,
                                                      const GimpHSV      *hsv,
                                                      GimpColorSelection *selection);
static void   gimp_color_selection_scales_changed    (GimpColorSelector  *selector,
                                                      const GimpRGB      *rgb,
                                                      const GimpHSV      *hsv,
                                                      GimpColorSelection *selection);
102 103 104
static void   gimp_color_selection_color_picked      (GtkWidget          *widget,
                                                      const GimpRGB      *rgb,
                                                      GimpColorSelection *selection);
105 106
static void   gimp_color_selection_entry_changed     (GimpColorHexEntry  *entry,
                                                      GimpColorSelection *selection);
107 108 109 110 111 112 113 114 115 116
static void   gimp_color_selection_channel_changed   (GimpColorSelector  *selector,
                                                      GimpColorSelectorChannel channel,
                                                      GimpColorSelection *selection);
static void   gimp_color_selection_new_color_changed (GtkWidget          *widget,
                                                      GimpColorSelection *selection);

static void   gimp_color_selection_update            (GimpColorSelection *selection,
                                                      UpdateType          update);


117
G_DEFINE_TYPE (GimpColorSelection, gimp_color_selection, GTK_TYPE_BOX)
118

119
#define parent_class gimp_color_selection_parent_class
120

121
static guint selection_signals[LAST_SIGNAL] = { 0 };
122 123 124 125 126


static void
gimp_color_selection_class_init (GimpColorSelectionClass *klass)
{
127 128 129 130 131 132 133 134
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->set_property = gimp_color_selection_set_property;

  klass->color_changed       = NULL;

  g_object_class_install_property (object_class, PROP_CONFIG,
                                   g_param_spec_object ("config",
135 136
                                                        "Config",
                                                        "The color config used by this color selection",
137 138 139
                                                        GIMP_TYPE_COLOR_CONFIG,
                                                        G_PARAM_WRITABLE));

140
  selection_signals[COLOR_CHANGED] =
141
    g_signal_new ("color-changed",
142 143 144 145 146 147 148 149 150 151 152 153
                  G_TYPE_FROM_CLASS (klass),
                  G_SIGNAL_RUN_FIRST,
                  G_STRUCT_OFFSET (GimpColorSelectionClass, color_changed),
                  NULL, NULL,
                  g_cclosure_marshal_VOID__VOID,
                  G_TYPE_NONE, 0);

}

static void
gimp_color_selection_init (GimpColorSelection *selection)
{
154 155 156 157 158 159 160 161 162
  GtkWidget    *main_hbox;
  GtkWidget    *hbox;
  GtkWidget    *vbox;
  GtkWidget    *frame;
  GtkWidget    *label;
  GtkWidget    *entry;
  GtkWidget    *button;
  GtkSizeGroup *new_group;
  GtkSizeGroup *old_group;
163 164 165

  selection->show_alpha = TRUE;

166 167 168
  gtk_orientable_set_orientation (GTK_ORIENTABLE (selection),
                                  GTK_ORIENTATION_VERTICAL);

169 170 171
  gimp_rgba_set (&selection->rgb, 0.0, 0.0, 0.0, 1.0);
  gimp_rgb_to_hsv (&selection->rgb, &selection->hsv);

172
  selection->channel = GIMP_COLOR_SELECTOR_RED;
173

174
  main_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
175
  gtk_box_pack_start (GTK_BOX (selection), main_hbox, TRUE, TRUE, 0);
176 177 178
  gtk_widget_show (main_hbox);

  /*  The left vbox with the notebook  */
179
  selection->left_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
180 181 182 183
  gtk_box_pack_start (GTK_BOX (main_hbox), selection->left_vbox,
                      TRUE, TRUE, 0);
  gtk_widget_show (selection->left_vbox);

184 185 186 187 188 189
  if (_gimp_ensure_modules_func)
    {
      g_type_class_ref (GIMP_TYPE_COLOR_SELECT);
      _gimp_ensure_modules_func ();
    }

190 191 192 193
  selection->notebook = gimp_color_selector_new (GIMP_TYPE_COLOR_NOTEBOOK,
                                                 &selection->rgb,
                                                 &selection->hsv,
                                                 selection->channel);
194 195 196 197

  if (_gimp_ensure_modules_func)
    g_type_class_unref (g_type_class_peek (GIMP_TYPE_COLOR_SELECT));

198 199 200 201 202 203
  gimp_color_selector_set_toggles_visible
    (GIMP_COLOR_SELECTOR (selection->notebook), FALSE);
  gtk_box_pack_start (GTK_BOX (selection->left_vbox), selection->notebook,
                      TRUE, TRUE, 0);
  gtk_widget_show (selection->notebook);

204
  g_signal_connect (selection->notebook, "color-changed",
205 206 207
                    G_CALLBACK (gimp_color_selection_notebook_changed),
                    selection);
  g_signal_connect (GIMP_COLOR_NOTEBOOK (selection->notebook)->notebook,
208
                    "switch-page",
209 210 211
                    G_CALLBACK (gimp_color_selection_switch_page),
                    selection);

212
  /*  The hbox for the color_areas  */
213
  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
214 215 216 217
  gtk_box_pack_end (GTK_BOX (selection->left_vbox), hbox, FALSE, FALSE, 0);
  gtk_widget_show (hbox);

  /*  The labels  */
218
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
219 220 221 222
  gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
  gtk_widget_show (vbox);

  label = gtk_label_new (_("Current:"));
223
  gtk_label_set_xalign (GTK_LABEL (label), 1.0);
224 225 226 227 228 229 230 231
  gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
  gtk_widget_show (label);

  new_group = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL);
  gtk_size_group_add_widget (new_group, label);
  g_object_unref (new_group);

  label = gtk_label_new (_("Old:"));
232
  gtk_label_set_xalign (GTK_LABEL (label), 1.0);
233 234 235 236 237 238 239 240 241 242 243 244 245
  gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
  gtk_widget_show (label);

  old_group = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL);
  gtk_size_group_add_widget (old_group, label);
  g_object_unref (old_group);

  /*  The color areas  */
  frame = gtk_frame_new (NULL);
  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
  gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
  gtk_widget_show (frame);

246
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
247 248
  gtk_container_add (GTK_CONTAINER (frame), vbox);
  gtk_widget_show (vbox);
249 250 251 252 253 254 255

  selection->new_color = gimp_color_area_new (&selection->rgb,
                                              selection->show_alpha ?
                                              GIMP_COLOR_AREA_SMALL_CHECKS :
                                              GIMP_COLOR_AREA_FLAT,
                                              GDK_BUTTON1_MASK |
                                              GDK_BUTTON2_MASK);
256 257
  gtk_size_group_add_widget (new_group, selection->new_color);
  gtk_box_pack_start (GTK_BOX (vbox), selection->new_color, FALSE, FALSE, 0);
258 259
  gtk_widget_show (selection->new_color);

260
  g_signal_connect (selection->new_color, "color-changed",
Sven Neumann's avatar
Sven Neumann committed
261 262
                    G_CALLBACK (gimp_color_selection_new_color_changed),
                    selection);
263 264 265 266 267 268 269 270

  selection->old_color = gimp_color_area_new (&selection->rgb,
                                              selection->show_alpha ?
                                              GIMP_COLOR_AREA_SMALL_CHECKS :
                                              GIMP_COLOR_AREA_FLAT,
                                              GDK_BUTTON1_MASK |
                                              GDK_BUTTON2_MASK);
  gtk_drag_dest_unset (selection->old_color);
271 272
  gtk_size_group_add_widget (old_group, selection->old_color);
  gtk_box_pack_start (GTK_BOX (vbox), selection->old_color, FALSE, FALSE, 0);
273 274 275
  gtk_widget_show (selection->old_color);

  /*  The right vbox with color scales  */
276
  selection->right_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
  gtk_box_pack_start (GTK_BOX (main_hbox), selection->right_vbox,
                      TRUE, TRUE, 0);
  gtk_widget_show (selection->right_vbox);

  selection->scales = gimp_color_selector_new (GIMP_TYPE_COLOR_SCALES,
                                               &selection->rgb,
                                               &selection->hsv,
                                               selection->channel);
  gimp_color_selector_set_toggles_visible
    (GIMP_COLOR_SELECTOR (selection->scales), TRUE);
  gimp_color_selector_set_show_alpha (GIMP_COLOR_SELECTOR (selection->scales),
                                      selection->show_alpha);
  gtk_box_pack_start (GTK_BOX (selection->right_vbox), selection->scales,
                      TRUE, TRUE, 0);
  gtk_widget_show (selection->scales);

293
  g_signal_connect (selection->scales, "channel-changed",
294 295
                    G_CALLBACK (gimp_color_selection_channel_changed),
                    selection);
296
  g_signal_connect (selection->scales, "color-changed",
297 298
                    G_CALLBACK (gimp_color_selection_scales_changed),
                    selection);
299

300
  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
301
  gtk_box_pack_start (GTK_BOX (selection->right_vbox), hbox, FALSE, FALSE, 0);
302 303
  gtk_widget_show (hbox);

304 305 306 307 308 309 310 311 312 313
  /*  The color picker  */
  button = gimp_pick_button_new ();
  gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
  gtk_widget_show (button);

  g_signal_connect (button, "color-picked",
                    G_CALLBACK (gimp_color_selection_color_picked),
                    selection);

  /* The hex triplet entry */
314 315
  entry = gimp_color_hex_entry_new ();
  gimp_help_set_help_data (entry,
316 317 318
                           _("Hexadecimal color notation as used in HTML and "
                             "CSS.  This entry also accepts CSS color names."),
                           NULL);
319 320 321
  gtk_box_pack_end (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
  gtk_widget_show (entry);

322
  label = gtk_label_new_with_mnemonic (_("HTML _notation:"));
323 324 325 326 327 328
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
  gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0);
  gtk_widget_show (label);

  g_object_set_data (G_OBJECT (selection), "color-hex-entry", entry);

329
  g_signal_connect (entry, "color-changed",
330 331
                    G_CALLBACK (gimp_color_selection_entry_changed),
                    selection);
332 333
}

334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
static void
gimp_color_selection_set_property (GObject      *object,
                                   guint         property_id,
                                   const GValue *value,
                                   GParamSpec   *pspec)
{
  GimpColorSelection *selection = GIMP_COLOR_SELECTION (object);

  switch (property_id)
    {
    case PROP_CONFIG:
      gimp_color_selection_set_config (selection, g_value_get_object (value));
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
    }
}


355 356 357 358 359 360 361
/**
 * gimp_color_selection_new:
 *
 * Creates a new #GimpColorSelection widget.
 *
 * Return value: The new #GimpColorSelection widget.
 **/
362 363 364
GtkWidget *
gimp_color_selection_new (void)
{
365
  return g_object_new (GIMP_TYPE_COLOR_SELECTION, NULL);
366 367
}

368 369 370 371 372 373 374
/**
 * gimp_color_selection_set_show_alpha:
 * @selection:  A #GimpColorSelection widget.
 * @show_alpha: The new @show_alpha setting.
 *
 * Sets the @show_alpha property of the @selection widget.
 **/
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
void
gimp_color_selection_set_show_alpha (GimpColorSelection *selection,
                                     gboolean            show_alpha)
{
  g_return_if_fail (GIMP_IS_COLOR_SELECTION (selection));

  if (show_alpha != selection->show_alpha)
    {
      selection->show_alpha = show_alpha ? TRUE : FALSE;

      gimp_color_selector_set_show_alpha
        (GIMP_COLOR_SELECTOR (selection->notebook), selection->show_alpha);
      gimp_color_selector_set_show_alpha
        (GIMP_COLOR_SELECTOR (selection->scales), selection->show_alpha);

      gimp_color_area_set_type (GIMP_COLOR_AREA (selection->new_color),
                                selection->show_alpha ?
                                GIMP_COLOR_AREA_SMALL_CHECKS :
                                GIMP_COLOR_AREA_FLAT);
      gimp_color_area_set_type (GIMP_COLOR_AREA (selection->old_color),
                                selection->show_alpha ?
                                GIMP_COLOR_AREA_SMALL_CHECKS :
                                GIMP_COLOR_AREA_FLAT);
    }
}

401 402 403 404 405 406 407 408
/**
 * gimp_color_selection_get_show_alpha:
 * @selection: A #GimpColorSelection widget.
 *
 * Returns the @selection's @show_alpha property.
 *
 * Return value: #TRUE if the #GimpColorSelection has alpha controls.
 **/
409 410 411 412 413 414 415 416
gboolean
gimp_color_selection_get_show_alpha (GimpColorSelection *selection)
{
  g_return_val_if_fail (GIMP_IS_COLOR_SELECTION (selection), FALSE);

  return selection->show_alpha;
}

417 418 419 420 421 422 423
/**
 * gimp_color_selection_set_color:
 * @selection: A #GimpColorSelection widget.
 * @color:     The @color to set as current color.
 *
 * Sets the #GimpColorSelection's current color to the new @color.
 **/
424 425 426 427 428 429 430 431 432 433
void
gimp_color_selection_set_color (GimpColorSelection *selection,
                                const GimpRGB      *color)
{
  g_return_if_fail (GIMP_IS_COLOR_SELECTION (selection));
  g_return_if_fail (color != NULL);

  selection->rgb = *color;
  gimp_rgb_to_hsv (&selection->rgb, &selection->hsv);

434
  gimp_color_selection_update (selection, UPDATE_ALL);
435 436 437 438

  gimp_color_selection_color_changed (selection);
}

439 440 441 442 443
/**
 * gimp_color_selection_get_color:
 * @selection: A #GimpColorSelection widget.
 * @color:     Return location for the @selection's current @color.
 *
444
 * This function returns the #GimpColorSelection's current color.
445
 **/
446 447 448 449 450 451 452 453 454 455
void
gimp_color_selection_get_color (GimpColorSelection *selection,
                                GimpRGB            *color)
{
  g_return_if_fail (GIMP_IS_COLOR_SELECTION (selection));
  g_return_if_fail (color != NULL);

  *color = selection->rgb;
}

456 457 458 459 460 461 462
/**
 * gimp_color_selection_set_old_color:
 * @selection: A #GimpColorSelection widget.
 * @color:     The @color to set as old color.
 *
 * Sets the #GimpColorSelection's old color.
 **/
463 464 465 466 467 468 469 470 471 472
void
gimp_color_selection_set_old_color (GimpColorSelection *selection,
                                    const GimpRGB      *color)
{
  g_return_if_fail (GIMP_IS_COLOR_SELECTION (selection));
  g_return_if_fail (color != NULL);

  gimp_color_area_set_color (GIMP_COLOR_AREA (selection->old_color), color);
}

473 474 475 476 477
/**
 * gimp_color_selection_get_old_color:
 * @selection: A #GimpColorSelection widget.
 * @color:     Return location for the @selection's old @color.
 *
478
 * This function returns the #GimpColorSelection's old color.
479
 **/
480 481 482 483 484 485 486 487 488 489
void
gimp_color_selection_get_old_color (GimpColorSelection *selection,
                                    GimpRGB            *color)
{
  g_return_if_fail (GIMP_IS_COLOR_SELECTION (selection));
  g_return_if_fail (color != NULL);

  gimp_color_area_get_color (GIMP_COLOR_AREA (selection->old_color), color);
}

490 491 492 493 494 495
/**
 * gimp_color_selection_reset:
 * @selection: A #GimpColorSelection widget.
 *
 * Sets the #GimpColorSelection's current color to its old color.
 **/
496 497 498 499 500 501 502 503 504 505 506
void
gimp_color_selection_reset (GimpColorSelection *selection)
{
  GimpRGB color;

  g_return_if_fail (GIMP_IS_COLOR_SELECTION (selection));

  gimp_color_area_get_color (GIMP_COLOR_AREA (selection->old_color), &color);
  gimp_color_selection_set_color (selection, &color);
}

507 508 509 510
/**
 * gimp_color_selection_color_changed:
 * @selection: A #GimpColorSelection widget.
 *
511
 * Emits the "color-changed" signal.
512
 **/
513 514 515 516 517 518 519 520
void
gimp_color_selection_color_changed (GimpColorSelection *selection)
{
  g_return_if_fail (GIMP_IS_COLOR_SELECTION (selection));

  g_signal_emit (selection, selection_signals[COLOR_CHANGED], 0);
}

521 522
/**
 * gimp_color_selection_set_config:
523 524
 * @selection: A #GimpColorSelection widget.
 * @config:    A #GimpColorConfig object.
525 526 527
 *
 * Sets the color management configuration to use with this color selection.
 *
528
 * Since: 2.4
529 530 531 532 533 534 535 536 537 538 539 540
 */
void
gimp_color_selection_set_config (GimpColorSelection *selection,
                                 GimpColorConfig    *config)
{
  g_return_if_fail (GIMP_IS_COLOR_SELECTION (selection));
  g_return_if_fail (config == NULL || GIMP_IS_COLOR_CONFIG (config));

  gimp_color_selector_set_config (GIMP_COLOR_SELECTOR (selection->notebook),
                                  config);
  gimp_color_selector_set_config (GIMP_COLOR_SELECTOR (selection->scales),
                                  config);
541 542 543 544
  gimp_color_area_set_color_config (GIMP_COLOR_AREA (selection->old_color),
                                    config);
  gimp_color_area_set_color_config (GIMP_COLOR_AREA (selection->new_color),
                                    config);
545
}
546 547 548 549 550

/*  private functions  */

static void
gimp_color_selection_switch_page (GtkWidget          *widget,
551
                                  gpointer            page,
552 553 554
                                  guint               page_num,
                                  GimpColorSelection *selection)
{
555
  GimpColorNotebook *notebook = GIMP_COLOR_NOTEBOOK (selection->notebook);
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573
  gboolean           sensitive;

  sensitive =
    (GIMP_COLOR_SELECTOR_GET_CLASS (notebook->cur_page)->set_channel != NULL);

  gimp_color_selector_set_toggles_sensitive
    (GIMP_COLOR_SELECTOR (selection->scales), sensitive);
}

static void
gimp_color_selection_notebook_changed (GimpColorSelector  *selector,
                                       const GimpRGB      *rgb,
                                       const GimpHSV      *hsv,
                                       GimpColorSelection *selection)
{
  selection->hsv = *hsv;
  selection->rgb = *rgb;

574 575
  gimp_color_selection_update (selection,
                               UPDATE_SCALES | UPDATE_ENTRY | UPDATE_COLOR);
576 577 578 579 580 581 582 583 584 585 586 587
  gimp_color_selection_color_changed (selection);
}

static void
gimp_color_selection_scales_changed (GimpColorSelector  *selector,
                                     const GimpRGB      *rgb,
                                     const GimpHSV      *hsv,
                                     GimpColorSelection *selection)
{
  selection->rgb = *rgb;
  selection->hsv = *hsv;

588 589 590 591 592
  gimp_color_selection_update (selection,
                               UPDATE_ENTRY | UPDATE_NOTEBOOK | UPDATE_COLOR);
  gimp_color_selection_color_changed (selection);
}

593 594 595 596 597 598 599 600
static void
gimp_color_selection_color_picked (GtkWidget          *widget,
                                   const GimpRGB      *rgb,
                                   GimpColorSelection *selection)
{
  gimp_color_selection_set_color (selection, rgb);
}

601 602 603 604 605 606 607 608 609 610
static void
gimp_color_selection_entry_changed (GimpColorHexEntry  *entry,
                                    GimpColorSelection *selection)
{
  gimp_color_hex_entry_get_color (entry, &selection->rgb);

  gimp_rgb_to_hsv (&selection->rgb, &selection->hsv);

  gimp_color_selection_update (selection,
                               UPDATE_NOTEBOOK | UPDATE_SCALES | UPDATE_COLOR);
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631
  gimp_color_selection_color_changed (selection);
}

static void
gimp_color_selection_channel_changed (GimpColorSelector        *selector,
                                      GimpColorSelectorChannel  channel,
                                      GimpColorSelection       *selection)
{
  selection->channel = channel;

  gimp_color_selector_set_channel (GIMP_COLOR_SELECTOR (selection->notebook),
                                   selection->channel);
}

static void
gimp_color_selection_new_color_changed (GtkWidget          *widget,
                                        GimpColorSelection *selection)
{
  gimp_color_area_get_color (GIMP_COLOR_AREA (widget), &selection->rgb);
  gimp_rgb_to_hsv (&selection->rgb, &selection->hsv);

632 633
  gimp_color_selection_update (selection,
                               UPDATE_NOTEBOOK | UPDATE_SCALES | UPDATE_ENTRY);
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670
  gimp_color_selection_color_changed (selection);
}

static void
gimp_color_selection_update (GimpColorSelection *selection,
                             UpdateType          update)
{
  if (update & UPDATE_NOTEBOOK)
    {
      g_signal_handlers_block_by_func (selection->notebook,
                                       gimp_color_selection_notebook_changed,
                                       selection);

      gimp_color_selector_set_color (GIMP_COLOR_SELECTOR (selection->notebook),
                                     &selection->rgb,
                                     &selection->hsv);

      g_signal_handlers_unblock_by_func (selection->notebook,
                                         gimp_color_selection_notebook_changed,
                                         selection);
    }

  if (update & UPDATE_SCALES)
    {
      g_signal_handlers_block_by_func (selection->scales,
                                       gimp_color_selection_scales_changed,
                                       selection);

      gimp_color_selector_set_color (GIMP_COLOR_SELECTOR (selection->scales),
                                     &selection->rgb,
                                     &selection->hsv);

      g_signal_handlers_unblock_by_func (selection->scales,
                                         gimp_color_selection_scales_changed,
                                         selection);
    }

671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688
  if (update & UPDATE_ENTRY)
    {
      GimpColorHexEntry *entry;

      entry = g_object_get_data (G_OBJECT (selection), "color-hex-entry");

      g_signal_handlers_block_by_func (entry,
                                       gimp_color_selection_entry_changed,
                                       selection);

      gimp_color_hex_entry_set_color (entry, &selection->rgb);

      g_signal_handlers_unblock_by_func (entry,
                                         gimp_color_selection_entry_changed,
                                         selection);
    }

  if (update & UPDATE_COLOR)
689 690 691
    {
      g_signal_handlers_block_by_func (selection->new_color,
                                       gimp_color_selection_new_color_changed,
Sven Neumann's avatar
Sven Neumann committed
692
                                       selection);
693 694

      gimp_color_area_set_color (GIMP_COLOR_AREA (selection->new_color),
Sven Neumann's avatar
Sven Neumann committed
695
                                 &selection->rgb);
696 697

      g_signal_handlers_unblock_by_func (selection->new_color,
Sven Neumann's avatar
Sven Neumann committed
698 699
                                         gimp_color_selection_new_color_changed,
                                         selection);
700 701
    }
}