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

#include "config.h"

#include <string.h>

#include <gtk/gtk.h>

#include "libgimpcolor/gimpcolor.h"
#include "libgimpwidgets/gimpwidgets.h"

#include "widgets-types.h"

32 33 34
#include "config/gimpcoreconfig.h"

#include "core/gimp.h"
35 36 37 38 39
#include "core/gimpcontext.h"

#include "gimpcoloreditor.h"
#include "gimpdocked.h"
#include "gimpfgbgeditor.h"
40
#include "gimpfgbgview.h"
41
#include "gimpsessioninfo-aux.h"
42 43 44 45

#include "gimp-intl.h"


46 47 48 49 50 51 52 53 54
enum
{
  PROP_0,
  PROP_CONTEXT
};


static void   gimp_color_editor_docked_iface_init (GimpDockedInterface  *iface);

55
static void   gimp_color_editor_dispose         (GObject           *object);
56 57 58 59 60 61 62 63
static void   gimp_color_editor_set_property    (GObject           *object,
                                                 guint              property_id,
                                                 const GValue      *value,
                                                 GParamSpec        *pspec);
static void   gimp_color_editor_get_property    (GObject           *object,
                                                 guint              property_id,
                                                 GValue            *value,
                                                 GParamSpec        *pspec);
64 65 66 67 68 69 70

static void   gimp_color_editor_style_set       (GtkWidget         *widget,
                                                 GtkStyle          *prev_style);

static void   gimp_color_editor_set_aux_info    (GimpDocked        *docked,
                                                 GList             *aux_info);
static GList *gimp_color_editor_get_aux_info     (GimpDocked       *docked);
71 72 73
static GtkWidget *gimp_color_editor_get_preview (GimpDocked        *docked,
                                                 GimpContext       *context,
                                                 GtkIconSize        size);
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
static void   gimp_color_editor_set_context     (GimpDocked        *docked,
                                                 GimpContext       *context);

static void   gimp_color_editor_fg_changed      (GimpContext       *context,
                                                 const GimpRGB     *rgb,
                                                 GimpColorEditor   *editor);
static void   gimp_color_editor_bg_changed      (GimpContext       *context,
                                                 const GimpRGB     *rgb,
                                                 GimpColorEditor   *editor);
static void   gimp_color_editor_color_changed   (GimpColorSelector *selector,
                                                 const GimpRGB     *rgb,
                                                 const GimpHSV     *hsv,
                                                 GimpColorEditor   *editor);
static void   gimp_color_editor_tab_toggled     (GtkWidget         *widget,
                                                 GimpColorEditor   *editor);
static void   gimp_color_editor_fg_bg_notify    (GtkWidget         *widget,
                                                 GParamSpec        *pspec,
                                                 GimpColorEditor   *editor);
92
#ifndef GDK_WINDOWING_QUARTZ
93 94 95
static void   gimp_color_editor_color_picked    (GtkWidget         *widget,
                                                 const GimpRGB     *rgb,
                                                 GimpColorEditor   *editor);
96
#endif
97 98
static void   gimp_color_editor_entry_changed   (GimpColorHexEntry *entry,
                                                 GimpColorEditor   *editor);
99 100


101 102
G_DEFINE_TYPE_WITH_CODE (GimpColorEditor, gimp_color_editor, GIMP_TYPE_EDITOR,
                         G_IMPLEMENT_INTERFACE (GIMP_TYPE_DOCKED,
103
                                                gimp_color_editor_docked_iface_init))
104

105
#define parent_class gimp_color_editor_parent_class
106

107
static GimpDockedInterface *parent_docked_iface = NULL;
108 109 110 111 112


static void
gimp_color_editor_class_init (GimpColorEditorClass* klass)
{
113 114
  GObjectClass   *object_class = G_OBJECT_CLASS (klass);
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
115

116
  object_class->dispose      = gimp_color_editor_dispose;
117 118
  object_class->set_property = gimp_color_editor_set_property;
  object_class->get_property = gimp_color_editor_get_property;
119

120
  widget_class->style_set    = gimp_color_editor_style_set;
121

122 123 124 125
  g_object_class_install_property (object_class, PROP_CONTEXT,
                                   g_param_spec_object ("context",
                                                        NULL, NULL,
                                                        GIMP_TYPE_CONTEXT,
126
                                                        GIMP_PARAM_READWRITE));
127 128
}

129 130 131 132 133 134 135 136 137 138 139 140 141 142
static void
gimp_color_editor_docked_iface_init (GimpDockedInterface *iface)
{
  parent_docked_iface = g_type_interface_peek_parent (iface);

  if (! parent_docked_iface)
    parent_docked_iface = g_type_default_interface_peek (GIMP_TYPE_DOCKED);

  iface->get_preview  = gimp_color_editor_get_preview;
  iface->set_aux_info = gimp_color_editor_set_aux_info;
  iface->get_aux_info = gimp_color_editor_get_aux_info;
  iface->set_context  = gimp_color_editor_set_context;
}

143 144 145 146
static void
gimp_color_editor_init (GimpColorEditor *editor)
{
  GtkWidget   *notebook;
147 148 149
  GtkWidget   *hbox;
  GtkWidget   *vbox;
  GtkWidget   *button;
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
  gint         content_spacing;
  gint         button_spacing;
  GtkIconSize  button_icon_size;
  GimpRGB      rgb;
  GimpHSV      hsv;
  GList       *list;
  GSList      *group;

  editor->context = NULL;
  editor->edit_bg = FALSE;

  gimp_rgba_set (&rgb, 0.0, 0.0, 0.0, 1.0);
  gimp_rgb_to_hsv (&rgb, &hsv);

  gtk_widget_style_get (GTK_WIDGET (editor),
165
                        "content-spacing",  &content_spacing,
166
                        "button-spacing",   &button_spacing,
167
                        "button-icon-size", &button_icon_size,
168
                        NULL);
169

170 171
  editor->hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, button_spacing);
  gtk_box_set_homogeneous (GTK_BOX (editor->hbox), TRUE);
172 173 174 175 176 177 178 179 180 181 182 183
  gtk_box_pack_start (GTK_BOX (editor), editor->hbox, FALSE, FALSE, 0);
  gtk_widget_show (editor->hbox);

  editor->notebook = gimp_color_selector_new (GIMP_TYPE_COLOR_NOTEBOOK,
                                              &rgb, &hsv,
                                              GIMP_COLOR_SELECTOR_HUE);
  gimp_color_selector_set_show_alpha (GIMP_COLOR_SELECTOR (editor->notebook),
                                      FALSE);
  gtk_box_pack_start (GTK_BOX (editor), editor->notebook,
                      TRUE, TRUE, content_spacing);
  gtk_widget_show (editor->notebook);

184
  g_signal_connect (editor->notebook, "color-changed",
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
                    G_CALLBACK (gimp_color_editor_color_changed),
                    editor);

  notebook = GIMP_COLOR_NOTEBOOK (editor->notebook)->notebook;

  gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), FALSE);
  gtk_notebook_set_show_border (GTK_NOTEBOOK (notebook), FALSE);

  gimp_color_notebook_set_has_page (GIMP_COLOR_NOTEBOOK (editor->notebook),
                                    GIMP_TYPE_COLOR_SCALES, TRUE);

  group = NULL;

  for (list = GIMP_COLOR_NOTEBOOK (editor->notebook)->selectors;
       list;
       list = g_list_next (list))
    {
      GimpColorSelector      *selector;
      GimpColorSelectorClass *selector_class;
      GtkWidget              *button;
      GtkWidget              *image;

      selector       = GIMP_COLOR_SELECTOR (list->data);
      selector_class = GIMP_COLOR_SELECTOR_GET_CLASS (selector);

      button = gtk_radio_button_new (group);
      group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
      gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE);
      gtk_box_pack_start (GTK_BOX (editor->hbox), button, TRUE, TRUE, 0);
      gtk_widget_show (button);

      image = gtk_image_new_from_stock (selector_class->stock_id,
                                        GTK_ICON_SIZE_BUTTON);
      gtk_container_add (GTK_CONTAINER (button), image);
      gtk_widget_show (image);

      gimp_help_set_help_data (button,
222
                               selector_class->name, selector_class->help_id);
223 224 225 226 227 228 229 230 231

      g_object_set_data (G_OBJECT (button),   "selector", selector);
      g_object_set_data (G_OBJECT (selector), "button",   button);

      g_signal_connect (button, "toggled",
                        G_CALLBACK (gimp_color_editor_tab_toggled),
                        editor);
    }

232 233
  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
  gtk_box_set_homogeneous (GTK_BOX (hbox), TRUE);
234 235
  gtk_box_pack_start (GTK_BOX (editor), hbox, FALSE, FALSE, 0);
  gtk_widget_show (hbox);
236 237 238

  /*  FG/BG editor  */
  editor->fg_bg = gimp_fg_bg_editor_new (NULL);
239
  gtk_box_pack_start (GTK_BOX (hbox), editor->fg_bg, TRUE, TRUE, 0);
240 241 242 243 244
  gtk_widget_show (editor->fg_bg);

  g_signal_connect (editor->fg_bg, "notify::active-color",
                    G_CALLBACK (gimp_color_editor_fg_bg_notify),
                    editor);
245

246
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
247 248 249
  gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
  gtk_widget_show (vbox);

250
#ifndef GDK_WINDOWING_QUARTZ
251 252 253 254 255 256 257 258
  /*  The color picker  */
  button = gimp_pick_button_new ();
  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
  gtk_widget_show (button);

  g_signal_connect (button, "color-picked",
                    G_CALLBACK (gimp_color_editor_color_picked),
                    editor);
259
#endif
260 261 262 263

  /*  The hex triplet entry  */
  editor->hex_entry = gimp_color_hex_entry_new ();
  gimp_help_set_help_data (editor->hex_entry,
264 265 266
                           _("Hexadecimal color notation as used in HTML and "
                             "CSS.  This entry also accepts CSS color names."),
                           NULL);
267 268 269 270 271 272 273 274
  gtk_box_pack_end (GTK_BOX (vbox), editor->hex_entry, FALSE, FALSE, 0);
  gtk_widget_show (editor->hex_entry);

  g_signal_connect (editor->hex_entry, "color-changed",
                    G_CALLBACK (gimp_color_editor_entry_changed),
                    editor);
}

275 276 277 278 279 280 281 282 283 284 285
static void
gimp_color_editor_dispose (GObject *object)
{
  GimpColorEditor *editor = GIMP_COLOR_EDITOR (object);

  if (editor->context)
    gimp_docked_set_context (GIMP_DOCKED (editor), NULL);

  G_OBJECT_CLASS (parent_class)->dispose (object);
}

286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
static void
gimp_color_editor_set_property (GObject      *object,
                                guint         property_id,
                                const GValue *value,
                                GParamSpec   *pspec)
{
  switch (property_id)
    {
    case PROP_CONTEXT:
      gimp_docked_set_context (GIMP_DOCKED (object),
                               g_value_get_object (value));
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
    }
302 303 304
}

static void
305 306 307 308
gimp_color_editor_get_property (GObject    *object,
                                guint       property_id,
                                GValue     *value,
                                GParamSpec *pspec)
309
{
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
  GimpColorEditor *editor = GIMP_COLOR_EDITOR (object);

  switch (property_id)
    {
    case PROP_CONTEXT:
      g_value_set_object (value, editor->context);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
    }
}

static GtkWidget *
gimp_color_editor_get_preview (GimpDocked  *docked,
                               GimpContext *context,
                               GtkIconSize  size)
{
  GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (docked));
  GtkWidget   *preview;
  gint         width;
  gint         height;

  preview = gimp_fg_bg_view_new (context);

  if (gtk_icon_size_lookup_for_settings (settings, size, &width, &height))
    gtk_widget_set_size_request (preview, width, height);

  return preview;
}

341 342 343 344 345 346 347 348 349 350
#define AUX_INFO_CURRENT_PAGE "current-page"

static void
gimp_color_editor_set_aux_info (GimpDocked *docked,
                                GList      *aux_info)
{
  GimpColorEditor *editor   = GIMP_COLOR_EDITOR (docked);
  GtkWidget       *notebook = GIMP_COLOR_NOTEBOOK (editor->notebook)->notebook;
  GList           *list;

351 352
  parent_docked_iface->set_aux_info (docked, aux_info);

353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
  for (list = aux_info; list; list = g_list_next (list))
    {
      GimpSessionInfoAux *aux = list->data;

      if (! strcmp (aux->name, AUX_INFO_CURRENT_PAGE))
        {
          GList *children;
          GList *child;

          children = gtk_container_get_children (GTK_CONTAINER (notebook));

          for (child = children; child; child = g_list_next (child))
            {
              if (! strcmp (G_OBJECT_TYPE_NAME (child->data), aux->value))
                {
                  GtkWidget *button;

                  button = g_object_get_data (G_OBJECT (child->data), "button");

                  if (button)
                    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
                                                  TRUE);

                  break;
                }
            }

          g_list_free (children);
        }
    }
}

static GList *
gimp_color_editor_get_aux_info (GimpDocked *docked)
{
  GimpColorEditor    *editor   = GIMP_COLOR_EDITOR (docked);
  GimpColorNotebook  *notebook = GIMP_COLOR_NOTEBOOK (editor->notebook);
390 391 392
  GList              *aux_info;

  aux_info = parent_docked_iface->get_aux_info (docked);
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417

  if (notebook->cur_page)
    {
      GimpSessionInfoAux *aux;

      aux = gimp_session_info_aux_new (AUX_INFO_CURRENT_PAGE,
                                       G_OBJECT_TYPE_NAME (notebook->cur_page));
      aux_info = g_list_append (aux_info, aux);
    }

  return aux_info;
}

static void
gimp_color_editor_set_context (GimpDocked  *docked,
                               GimpContext *context)
{
  GimpColorEditor *editor = GIMP_COLOR_EDITOR (docked);

  if (context == editor->context)
    return;

  if (editor->context)
    {
      g_signal_handlers_disconnect_by_func (editor->context,
418 419
                                            gimp_color_editor_fg_changed,
                                            editor);
420
      g_signal_handlers_disconnect_by_func (editor->context,
421 422
                                            gimp_color_editor_bg_changed,
                                            editor);
423 424 425 426

      g_object_unref (editor->context);
    }

427 428 429
  editor->context = context;

  if (editor->context)
430 431 432
    {
      GimpRGB rgb;

433
      g_object_ref (editor->context);
434

435
      g_signal_connect (editor->context, "foreground-changed",
436 437
                        G_CALLBACK (gimp_color_editor_fg_changed),
                        editor);
438
      g_signal_connect (editor->context, "background-changed",
439 440
                        G_CALLBACK (gimp_color_editor_bg_changed),
                        editor);
441 442 443 444 445 446 447 448 449 450 451

      if (editor->edit_bg)
        {
          gimp_context_get_background (editor->context, &rgb);
          gimp_color_editor_bg_changed (editor->context, &rgb, editor);
        }
      else
        {
          gimp_context_get_foreground (editor->context, &rgb);
          gimp_color_editor_fg_changed (editor->context, &rgb, editor);
        }
452

453 454 455
      g_object_set_data (G_OBJECT (context->gimp->config->color_management),
                         "gimp-context", editor->context);

456 457
      gimp_color_selector_set_config (GIMP_COLOR_SELECTOR (editor->notebook),
                                      context->gimp->config->color_management);
458 459 460

      g_object_set_data (G_OBJECT (context->gimp->config->color_management),
                         "gimp-context", NULL);
461 462 463 464 465 466 467 468
    }

  gimp_fg_bg_editor_set_context (GIMP_FG_BG_EDITOR (editor->fg_bg), context);
}

GtkWidget *
gimp_color_editor_new (GimpContext *context)
{
469 470 471
  return g_object_new (GIMP_TYPE_COLOR_EDITOR,
                       "context", context,
                       NULL);
472 473 474 475 476 477 478 479
}

static void
gimp_color_editor_style_set (GtkWidget *widget,
                             GtkStyle  *prev_style)
{
  GimpColorEditor *editor = GIMP_COLOR_EDITOR (widget);

480
  GTK_WIDGET_CLASS (parent_class)->style_set (widget, prev_style);
481 482 483 484 485 486

  if (editor->hbox)
    gimp_editor_set_box_style (GIMP_EDITOR (editor), GTK_BOX (editor->hbox));
}


487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516
static void
gimp_color_editor_set_color (GimpColorEditor *editor,
                             const GimpRGB   *rgb)
{
  GimpHSV hsv;

  gimp_rgb_to_hsv (rgb, &hsv);

  g_signal_handlers_block_by_func (editor->notebook,
                                   gimp_color_editor_color_changed,
                                   editor);

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

  g_signal_handlers_unblock_by_func (editor->notebook,
                                     gimp_color_editor_color_changed,
                                     editor);

  g_signal_handlers_block_by_func (editor->hex_entry,
                                   gimp_color_editor_entry_changed,
                                   editor);

  gimp_color_hex_entry_set_color (GIMP_COLOR_HEX_ENTRY (editor->hex_entry),
                                  rgb);

  g_signal_handlers_unblock_by_func (editor->hex_entry,
                                     gimp_color_editor_entry_changed,
                                     editor);
}
517 518 519 520 521 522 523

static void
gimp_color_editor_fg_changed (GimpContext     *context,
                              const GimpRGB   *rgb,
                              GimpColorEditor *editor)
{
  if (! editor->edit_bg)
524
    gimp_color_editor_set_color (editor, rgb);
525 526 527 528 529 530 531 532
}

static void
gimp_color_editor_bg_changed (GimpContext     *context,
                              const GimpRGB   *rgb,
                              GimpColorEditor *editor)
{
  if (editor->edit_bg)
533
    gimp_color_editor_set_color (editor, rgb);
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568
}

static void
gimp_color_editor_color_changed (GimpColorSelector *selector,
                                 const GimpRGB     *rgb,
                                 const GimpHSV     *hsv,
                                 GimpColorEditor   *editor)
{
  if (editor->context)
    {
      if (editor->edit_bg)
        {
          g_signal_handlers_block_by_func (editor->context,
                                           gimp_color_editor_bg_changed,
                                           editor);

          gimp_context_set_background (editor->context, rgb);

          g_signal_handlers_unblock_by_func (editor->context,
                                             gimp_color_editor_bg_changed,
                                             editor);
        }
      else
        {
          g_signal_handlers_block_by_func (editor->context,
                                           gimp_color_editor_fg_changed,
                                           editor);

          gimp_context_set_foreground (editor->context, rgb);

          g_signal_handlers_unblock_by_func (editor->context,
                                             gimp_color_editor_fg_changed,
                                             editor);
        }
    }
569 570 571 572 573 574 575 576 577 578 579

  g_signal_handlers_block_by_func (editor->hex_entry,
                                   gimp_color_editor_entry_changed,
                                   editor);

  gimp_color_hex_entry_set_color (GIMP_COLOR_HEX_ENTRY (editor->hex_entry),
                                  rgb);

  g_signal_handlers_unblock_by_func (editor->hex_entry,
                                     gimp_color_editor_entry_changed,
                                     editor);
580 581 582 583 584 585
}

static void
gimp_color_editor_tab_toggled (GtkWidget       *widget,
                               GimpColorEditor *editor)
{
586
  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
587 588 589 590 591 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 627 628 629 630 631 632 633 634 635 636 637 638
    {
      GtkWidget *selector;

      selector = g_object_get_data (G_OBJECT (widget), "selector");

      if (selector)
        {
          GtkWidget *notebook;
          gint       page_num;

          notebook = GIMP_COLOR_NOTEBOOK (editor->notebook)->notebook;

          page_num = gtk_notebook_page_num (GTK_NOTEBOOK (notebook), selector);

          if (page_num >= 0)
            gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), page_num);
        }
    }
}

static void
gimp_color_editor_fg_bg_notify (GtkWidget       *widget,
                                GParamSpec      *pspec,
                                GimpColorEditor *editor)
{
  gboolean edit_bg;

  edit_bg = (GIMP_FG_BG_EDITOR (widget)->active_color ==
             GIMP_ACTIVE_COLOR_BACKGROUND);

  if (edit_bg != editor->edit_bg)
    {
      editor->edit_bg = edit_bg;

      if (editor->context)
        {
          GimpRGB rgb;

          if (edit_bg)
            {
              gimp_context_get_background (editor->context, &rgb);
              gimp_color_editor_bg_changed (editor->context, &rgb, editor);
            }
          else
            {
              gimp_context_get_foreground (editor->context, &rgb);
              gimp_color_editor_fg_changed (editor->context, &rgb, editor);
            }
        }
    }
}

639
#ifndef GDK_WINDOWING_QUARTZ
640 641 642 643 644 645 646 647 648 649 650 651 652
static void
gimp_color_editor_color_picked (GtkWidget       *widget,
                                const GimpRGB   *rgb,
                                GimpColorEditor *editor)
{
  if (editor->context)
    {
      if (editor->edit_bg)
        gimp_context_set_background (editor->context, rgb);
      else
        gimp_context_set_foreground (editor->context, rgb);
    }
}
653
#endif
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670

static void
gimp_color_editor_entry_changed (GimpColorHexEntry *entry,
                                 GimpColorEditor   *editor)
{
  GimpRGB  rgb;

  gimp_color_hex_entry_get_color (entry, &rgb);

  if (editor->context)
    {
      if (editor->edit_bg)
        gimp_context_set_background (editor->context, &rgb);
      else
        gimp_context_set_foreground (editor->context, &rgb);
    }
}