gimpcolorselection.c 26.1 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
 * License along with this library.  If not, see
19
 * <https://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
enum
{
  PROP_0,
  PROP_CONFIG
};


85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
struct _GimpColorSelectionPrivate
{
  gboolean                  show_alpha;

  GimpHSV                   hsv;
  GimpRGB                   rgb;
  GimpColorSelectorChannel  channel;

  GtkWidget                *left_vbox;
  GtkWidget                *right_vbox;

  GtkWidget                *notebook;
  GtkWidget                *scales;

  GtkWidget                *new_color;
  GtkWidget                *old_color;
};

103
#define GET_PRIVATE(obj) (((GimpColorSelection *) (obj))->priv)
104 105


106 107 108 109
static void   gimp_color_selection_set_property      (GObject            *object,
                                                      guint               property_id,
                                                      const GValue       *value,
                                                      GParamSpec         *pspec);
110 111

static void   gimp_color_selection_switch_page       (GtkWidget          *widget,
112
                                                      gpointer            page,
113 114 115 116 117 118 119 120 121 122
                                                      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);
123 124 125
static void   gimp_color_selection_color_picked      (GtkWidget          *widget,
                                                      const GimpRGB      *rgb,
                                                      GimpColorSelection *selection);
126 127
static void   gimp_color_selection_entry_changed     (GimpColorHexEntry  *entry,
                                                      GimpColorSelection *selection);
128 129 130 131 132 133 134 135 136 137
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);


138 139
G_DEFINE_TYPE_WITH_PRIVATE (GimpColorSelection, gimp_color_selection,
                            GTK_TYPE_BOX)
140

141
#define parent_class gimp_color_selection_parent_class
142

143
static guint selection_signals[LAST_SIGNAL] = { 0, };
144 145 146 147 148


static void
gimp_color_selection_class_init (GimpColorSelectionClass *klass)
{
149 150 151 152 153 154 155 156
  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",
157 158
                                                        "Config",
                                                        "The color config used by this color selection",
159 160 161
                                                        GIMP_TYPE_COLOR_CONFIG,
                                                        G_PARAM_WRITABLE));

162
  selection_signals[COLOR_CHANGED] =
163
    g_signal_new ("color-changed",
164 165 166 167 168 169 170
                  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);

171
  gtk_widget_class_set_css_name (GTK_WIDGET_CLASS (klass), "GimpColorSelection");
172 173 174 175 176
}

static void
gimp_color_selection_init (GimpColorSelection *selection)
{
177
  GimpColorSelectionPrivate *priv;
178 179 180 181 182 183 184 185 186 187
  GtkWidget                 *main_hbox;
  GtkWidget                 *hbox;
  GtkWidget                 *vbox;
  GtkWidget                 *frame;
  GtkWidget                 *label;
  GtkWidget                 *entry;
  GtkWidget                 *button;
  GtkSizeGroup              *new_group;
  GtkSizeGroup              *old_group;

188
  selection->priv = gimp_color_selection_get_instance_private (selection);
189 190 191

  priv = selection->priv;

192
  priv->show_alpha = TRUE;
193

194 195 196
  gtk_orientable_set_orientation (GTK_ORIENTABLE (selection),
                                  GTK_ORIENTATION_VERTICAL);

197 198
  gimp_rgba_set (&priv->rgb, 0.0, 0.0, 0.0, 1.0);
  gimp_rgb_to_hsv (&priv->rgb, &priv->hsv);
199

200
  priv->channel = GIMP_COLOR_SELECTOR_RED;
201

202
  main_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
203
  gtk_box_pack_start (GTK_BOX (selection), main_hbox, TRUE, TRUE, 0);
204 205 206
  gtk_widget_show (main_hbox);

  /*  The left vbox with the notebook  */
207 208
  priv->left_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
  gtk_box_pack_start (GTK_BOX (main_hbox), priv->left_vbox,
209
                      TRUE, TRUE, 0);
210
  gtk_widget_show (priv->left_vbox);
211

212 213 214 215 216 217
  if (_gimp_ensure_modules_func)
    {
      g_type_class_ref (GIMP_TYPE_COLOR_SELECT);
      _gimp_ensure_modules_func ();
    }

218 219 220 221
  priv->notebook = gimp_color_selector_new (GIMP_TYPE_COLOR_NOTEBOOK,
                                            &priv->rgb,
                                            &priv->hsv,
                                            priv->channel);
222 223 224 225

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

226
  gimp_color_selector_set_toggles_visible
227 228
    (GIMP_COLOR_SELECTOR (priv->notebook), FALSE);
  gtk_box_pack_start (GTK_BOX (priv->left_vbox), priv->notebook,
229
                      TRUE, TRUE, 0);
230
  gtk_widget_show (priv->notebook);
231

232
  g_signal_connect (priv->notebook, "color-changed",
233 234
                    G_CALLBACK (gimp_color_selection_notebook_changed),
                    selection);
235
  g_signal_connect (gimp_color_notebook_get_notebook (GIMP_COLOR_NOTEBOOK (priv->notebook)),
236
                    "switch-page",
237 238 239
                    G_CALLBACK (gimp_color_selection_switch_page),
                    selection);

240
  /*  The hbox for the color_areas  */
241
  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
242
  gtk_box_pack_end (GTK_BOX (priv->left_vbox), hbox, FALSE, FALSE, 0);
243 244 245
  gtk_widget_show (hbox);

  /*  The labels  */
246
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
247 248 249 250
  gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
  gtk_widget_show (vbox);

  label = gtk_label_new (_("Current:"));
251
  gtk_label_set_xalign (GTK_LABEL (label), 1.0);
252 253 254 255 256 257 258 259
  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:"));
260
  gtk_label_set_xalign (GTK_LABEL (label), 1.0);
261 262 263 264 265 266 267 268 269 270 271 272 273
  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);

274
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
275 276
  gtk_container_add (GTK_CONTAINER (frame), vbox);
  gtk_widget_show (vbox);
277

278 279 280 281 282 283 284 285 286 287 288
  priv->new_color = gimp_color_area_new (&priv->rgb,
                                         priv->show_alpha ?
                                         GIMP_COLOR_AREA_SMALL_CHECKS :
                                         GIMP_COLOR_AREA_FLAT,
                                         GDK_BUTTON1_MASK |
                                         GDK_BUTTON2_MASK);
  gtk_size_group_add_widget (new_group, priv->new_color);
  gtk_box_pack_start (GTK_BOX (vbox), priv->new_color, FALSE, FALSE, 0);
  gtk_widget_show (priv->new_color);

  g_signal_connect (priv->new_color, "color-changed",
Sven Neumann's avatar
Sven Neumann committed
289 290
                    G_CALLBACK (gimp_color_selection_new_color_changed),
                    selection);
291

292 293 294 295 296 297 298 299 300 301
  priv->old_color = gimp_color_area_new (&priv->rgb,
                                         priv->show_alpha ?
                                         GIMP_COLOR_AREA_SMALL_CHECKS :
                                         GIMP_COLOR_AREA_FLAT,
                                         GDK_BUTTON1_MASK |
                                         GDK_BUTTON2_MASK);
  gtk_drag_dest_unset (priv->old_color);
  gtk_size_group_add_widget (old_group, priv->old_color);
  gtk_box_pack_start (GTK_BOX (vbox), priv->old_color, FALSE, FALSE, 0);
  gtk_widget_show (priv->old_color);
302 303

  /*  The right vbox with color scales  */
304 305
  priv->right_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
  gtk_box_pack_start (GTK_BOX (main_hbox), priv->right_vbox,
306
                      TRUE, TRUE, 0);
307
  gtk_widget_show (priv->right_vbox);
308

309 310 311 312
  priv->scales = gimp_color_selector_new (GIMP_TYPE_COLOR_SCALES,
                                          &priv->rgb,
                                          &priv->hsv,
                                          priv->channel);
313
  gimp_color_selector_set_toggles_visible
314 315 316 317
    (GIMP_COLOR_SELECTOR (priv->scales), TRUE);
  gimp_color_selector_set_show_alpha (GIMP_COLOR_SELECTOR (priv->scales),
                                      priv->show_alpha);
  gtk_box_pack_start (GTK_BOX (priv->right_vbox), priv->scales,
318
                      TRUE, TRUE, 0);
319
  gtk_widget_show (priv->scales);
320

321
  g_signal_connect (priv->scales, "channel-changed",
322 323
                    G_CALLBACK (gimp_color_selection_channel_changed),
                    selection);
324
  g_signal_connect (priv->scales, "color-changed",
325 326
                    G_CALLBACK (gimp_color_selection_scales_changed),
                    selection);
327

328
  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
329
  gtk_box_pack_start (GTK_BOX (priv->right_vbox), hbox, FALSE, FALSE, 0);
330 331
  gtk_widget_show (hbox);

332 333 334 335 336 337 338 339 340 341
  /*  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 */
342 343 344 345
  entry = gimp_color_hex_entry_new ();
  gtk_box_pack_end (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
  gtk_widget_show (entry);

346
  label = gtk_label_new_with_mnemonic (_("HTML _notation:"));
347 348 349 350 351 352
  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);

353
  g_signal_connect (entry, "color-changed",
354 355
                    G_CALLBACK (gimp_color_selection_entry_changed),
                    selection);
356 357
}

358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
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;
    }
}


379 380 381 382 383 384 385
/**
 * gimp_color_selection_new:
 *
 * Creates a new #GimpColorSelection widget.
 *
 * Return value: The new #GimpColorSelection widget.
 **/
386 387 388
GtkWidget *
gimp_color_selection_new (void)
{
389
  return g_object_new (GIMP_TYPE_COLOR_SELECTION, NULL);
390 391
}

392 393 394 395 396 397 398
/**
 * 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.
 **/
399 400 401 402
void
gimp_color_selection_set_show_alpha (GimpColorSelection *selection,
                                     gboolean            show_alpha)
{
403 404
  GimpColorSelectionPrivate *priv;

405 406
  g_return_if_fail (GIMP_IS_COLOR_SELECTION (selection));

407 408 409
  priv = GET_PRIVATE (selection);

  if (show_alpha != priv->show_alpha)
410
    {
411
      priv->show_alpha = show_alpha ? TRUE : FALSE;
412 413

      gimp_color_selector_set_show_alpha
414
        (GIMP_COLOR_SELECTOR (priv->notebook), priv->show_alpha);
415
      gimp_color_selector_set_show_alpha
416
        (GIMP_COLOR_SELECTOR (priv->scales), priv->show_alpha);
417

418 419
      gimp_color_area_set_type (GIMP_COLOR_AREA (priv->new_color),
                                priv->show_alpha ?
420 421
                                GIMP_COLOR_AREA_SMALL_CHECKS :
                                GIMP_COLOR_AREA_FLAT);
422 423
      gimp_color_area_set_type (GIMP_COLOR_AREA (priv->old_color),
                                priv->show_alpha ?
424 425 426 427 428
                                GIMP_COLOR_AREA_SMALL_CHECKS :
                                GIMP_COLOR_AREA_FLAT);
    }
}

429 430 431 432 433 434 435 436
/**
 * 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.
 **/
437 438 439 440 441
gboolean
gimp_color_selection_get_show_alpha (GimpColorSelection *selection)
{
  g_return_val_if_fail (GIMP_IS_COLOR_SELECTION (selection), FALSE);

442
  return GET_PRIVATE (selection)->show_alpha;
443 444
}

445 446 447 448 449 450 451
/**
 * 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.
 **/
452 453 454 455
void
gimp_color_selection_set_color (GimpColorSelection *selection,
                                const GimpRGB      *color)
{
456 457
  GimpColorSelectionPrivate *priv;

458 459 460
  g_return_if_fail (GIMP_IS_COLOR_SELECTION (selection));
  g_return_if_fail (color != NULL);

461 462 463 464
  priv = GET_PRIVATE (selection);

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

466
  gimp_color_selection_update (selection, UPDATE_ALL);
467 468 469 470

  gimp_color_selection_color_changed (selection);
}

471 472 473 474 475
/**
 * gimp_color_selection_get_color:
 * @selection: A #GimpColorSelection widget.
 * @color:     Return location for the @selection's current @color.
 *
476
 * This function returns the #GimpColorSelection's current color.
477
 **/
478 479 480 481 482 483 484
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);

485
  *color = GET_PRIVATE (selection)->rgb;
486 487
}

488 489 490 491 492 493 494
/**
 * gimp_color_selection_set_old_color:
 * @selection: A #GimpColorSelection widget.
 * @color:     The @color to set as old color.
 *
 * Sets the #GimpColorSelection's old color.
 **/
495 496 497 498
void
gimp_color_selection_set_old_color (GimpColorSelection *selection,
                                    const GimpRGB      *color)
{
499 500
  GimpColorSelectionPrivate *priv;

501 502 503
  g_return_if_fail (GIMP_IS_COLOR_SELECTION (selection));
  g_return_if_fail (color != NULL);

504 505 506
  priv = GET_PRIVATE (selection);

  gimp_color_area_set_color (GIMP_COLOR_AREA (priv->old_color), color);
507 508
}

509 510 511 512 513
/**
 * gimp_color_selection_get_old_color:
 * @selection: A #GimpColorSelection widget.
 * @color:     Return location for the @selection's old @color.
 *
514
 * This function returns the #GimpColorSelection's old color.
515
 **/
516 517 518 519
void
gimp_color_selection_get_old_color (GimpColorSelection *selection,
                                    GimpRGB            *color)
{
520 521
  GimpColorSelectionPrivate *priv;

522 523 524
  g_return_if_fail (GIMP_IS_COLOR_SELECTION (selection));
  g_return_if_fail (color != NULL);

525 526 527
  priv = GET_PRIVATE (selection);

  gimp_color_area_get_color (GIMP_COLOR_AREA (priv->old_color), color);
528 529
}

530 531 532 533 534 535
/**
 * gimp_color_selection_reset:
 * @selection: A #GimpColorSelection widget.
 *
 * Sets the #GimpColorSelection's current color to its old color.
 **/
536 537 538
void
gimp_color_selection_reset (GimpColorSelection *selection)
{
539 540
  GimpColorSelectionPrivate *priv;
  GimpRGB                    color;
541 542 543

  g_return_if_fail (GIMP_IS_COLOR_SELECTION (selection));

544 545 546
  priv = GET_PRIVATE (selection);

  gimp_color_area_get_color (GIMP_COLOR_AREA (priv->old_color), &color);
547 548 549
  gimp_color_selection_set_color (selection, &color);
}

550 551 552 553
/**
 * gimp_color_selection_color_changed:
 * @selection: A #GimpColorSelection widget.
 *
554
 * Emits the "color-changed" signal.
555
 **/
556 557 558 559 560 561 562 563
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);
}

564 565
/**
 * gimp_color_selection_set_config:
566 567
 * @selection: A #GimpColorSelection widget.
 * @config:    A #GimpColorConfig object.
568 569 570
 *
 * Sets the color management configuration to use with this color selection.
 *
571
 * Since: 2.4
572 573 574 575 576
 */
void
gimp_color_selection_set_config (GimpColorSelection *selection,
                                 GimpColorConfig    *config)
{
577 578
  GimpColorSelectionPrivate *priv;

579 580 581
  g_return_if_fail (GIMP_IS_COLOR_SELECTION (selection));
  g_return_if_fail (config == NULL || GIMP_IS_COLOR_CONFIG (config));

582 583 584
  priv = GET_PRIVATE (selection);

  gimp_color_selector_set_config (GIMP_COLOR_SELECTOR (priv->notebook),
585
                                  config);
586
  gimp_color_selector_set_config (GIMP_COLOR_SELECTOR (priv->scales),
587
                                  config);
588
  gimp_color_area_set_color_config (GIMP_COLOR_AREA (priv->old_color),
589
                                    config);
590
  gimp_color_area_set_color_config (GIMP_COLOR_AREA (priv->new_color),
591
                                    config);
592
}
593

594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
/**
 * gimp_color_selection_get_notebook:
 * @selection: A #GimpColorSelection widget.
 *
 * Returns: The selection's #GimpColorNotebook.
 *
 * Since: GIMP 3.0
 */
GtkWidget *
gimp_color_selection_get_notebook (GimpColorSelection *selection)
{
  g_return_val_if_fail (GIMP_IS_COLOR_SELECTION (selection), NULL);

  return GET_PRIVATE (selection)->notebook;
}

/**
 * gimp_color_selection_get_right_vbox:
 * @selection: A #GimpColorSelection widget.
 *
 * Returns: The selection's right #GtkBox which contains the color scales.
 *
 * Since: GIMP 3.0
 */
GtkWidget *
gimp_color_selection_get_right_vbox (GimpColorSelection *selection)
{
  g_return_val_if_fail (GIMP_IS_COLOR_SELECTION (selection), NULL);

  return GET_PRIVATE (selection)->right_vbox;
}


627 628 629 630
/*  private functions  */

static void
gimp_color_selection_switch_page (GtkWidget          *widget,
631
                                  gpointer            page,
632 633 634
                                  guint               page_num,
                                  GimpColorSelection *selection)
{
635 636 637 638
  GimpColorSelectionPrivate *priv     = GET_PRIVATE (selection);
  GimpColorNotebook         *notebook = GIMP_COLOR_NOTEBOOK (priv->notebook);
  GimpColorSelector         *current;
  gboolean                   sensitive;
639

640 641 642
  current = gimp_color_notebook_get_current_selector (notebook);

  sensitive = (GIMP_COLOR_SELECTOR_GET_CLASS (current)->set_channel != NULL);
643 644

  gimp_color_selector_set_toggles_sensitive
645
    (GIMP_COLOR_SELECTOR (priv->scales), sensitive);
646 647 648 649 650 651 652 653
}

static void
gimp_color_selection_notebook_changed (GimpColorSelector  *selector,
                                       const GimpRGB      *rgb,
                                       const GimpHSV      *hsv,
                                       GimpColorSelection *selection)
{
654 655 656 657
  GimpColorSelectionPrivate *priv = GET_PRIVATE (selection);

  priv->hsv = *hsv;
  priv->rgb = *rgb;
658

659 660
  gimp_color_selection_update (selection,
                               UPDATE_SCALES | UPDATE_ENTRY | UPDATE_COLOR);
661 662 663 664 665 666 667 668 669
  gimp_color_selection_color_changed (selection);
}

static void
gimp_color_selection_scales_changed (GimpColorSelector  *selector,
                                     const GimpRGB      *rgb,
                                     const GimpHSV      *hsv,
                                     GimpColorSelection *selection)
{
670 671 672 673
  GimpColorSelectionPrivate *priv = GET_PRIVATE (selection);

  priv->rgb = *rgb;
  priv->hsv = *hsv;
674

675 676 677 678 679
  gimp_color_selection_update (selection,
                               UPDATE_ENTRY | UPDATE_NOTEBOOK | UPDATE_COLOR);
  gimp_color_selection_color_changed (selection);
}

680 681 682 683 684 685 686 687
static void
gimp_color_selection_color_picked (GtkWidget          *widget,
                                   const GimpRGB      *rgb,
                                   GimpColorSelection *selection)
{
  gimp_color_selection_set_color (selection, rgb);
}

688 689 690 691
static void
gimp_color_selection_entry_changed (GimpColorHexEntry  *entry,
                                    GimpColorSelection *selection)
{
692 693 694
  GimpColorSelectionPrivate *priv = GET_PRIVATE (selection);

  gimp_color_hex_entry_get_color (entry, &priv->rgb);
695

696
  gimp_rgb_to_hsv (&priv->rgb, &priv->hsv);
697 698 699

  gimp_color_selection_update (selection,
                               UPDATE_NOTEBOOK | UPDATE_SCALES | UPDATE_COLOR);
700 701 702 703 704 705 706 707
  gimp_color_selection_color_changed (selection);
}

static void
gimp_color_selection_channel_changed (GimpColorSelector        *selector,
                                      GimpColorSelectorChannel  channel,
                                      GimpColorSelection       *selection)
{
708
  GimpColorSelectionPrivate *priv = GET_PRIVATE (selection);
709

710 711 712 713
  priv->channel = channel;

  gimp_color_selector_set_channel (GIMP_COLOR_SELECTOR (priv->notebook),
                                   priv->channel);
714 715 716 717 718 719
}

static void
gimp_color_selection_new_color_changed (GtkWidget          *widget,
                                        GimpColorSelection *selection)
{
720 721 722 723
  GimpColorSelectionPrivate *priv = GET_PRIVATE (selection);

  gimp_color_area_get_color (GIMP_COLOR_AREA (widget), &priv->rgb);
  gimp_rgb_to_hsv (&priv->rgb, &priv->hsv);
724

725 726
  gimp_color_selection_update (selection,
                               UPDATE_NOTEBOOK | UPDATE_SCALES | UPDATE_ENTRY);
727 728 729 730 731 732 733
  gimp_color_selection_color_changed (selection);
}

static void
gimp_color_selection_update (GimpColorSelection *selection,
                             UpdateType          update)
{
734 735
  GimpColorSelectionPrivate *priv = GET_PRIVATE (selection);

736 737
  if (update & UPDATE_NOTEBOOK)
    {
738
      g_signal_handlers_block_by_func (priv->notebook,
739 740 741
                                       gimp_color_selection_notebook_changed,
                                       selection);

742 743 744
      gimp_color_selector_set_color (GIMP_COLOR_SELECTOR (priv->notebook),
                                     &priv->rgb,
                                     &priv->hsv);
745

746
      g_signal_handlers_unblock_by_func (priv->notebook,
747 748 749 750 751 752
                                         gimp_color_selection_notebook_changed,
                                         selection);
    }

  if (update & UPDATE_SCALES)
    {
753
      g_signal_handlers_block_by_func (priv->scales,
754 755 756
                                       gimp_color_selection_scales_changed,
                                       selection);

757 758 759
      gimp_color_selector_set_color (GIMP_COLOR_SELECTOR (priv->scales),
                                     &priv->rgb,
                                     &priv->hsv);
760

761
      g_signal_handlers_unblock_by_func (priv->scales,
762 763 764 765
                                         gimp_color_selection_scales_changed,
                                         selection);
    }

766 767 768 769 770 771 772 773 774 775
  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);

776
      gimp_color_hex_entry_set_color (entry, &priv->rgb);
777 778 779 780 781 782 783

      g_signal_handlers_unblock_by_func (entry,
                                         gimp_color_selection_entry_changed,
                                         selection);
    }

  if (update & UPDATE_COLOR)
784
    {
785
      g_signal_handlers_block_by_func (priv->new_color,
786
                                       gimp_color_selection_new_color_changed,
Sven Neumann's avatar
Sven Neumann committed
787
                                       selection);
788

789 790
      gimp_color_area_set_color (GIMP_COLOR_AREA (priv->new_color),
                                 &priv->rgb);
791

792
      g_signal_handlers_unblock_by_func (priv->new_color,
Sven Neumann's avatar
Sven Neumann committed
793 794
                                         gimp_color_selection_new_color_changed,
                                         selection);
795 796
    }
}