home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 February / CMCD0205.ISO / Linux / gimp-2.2.0.tar.gz / gimp-2.2.0.tar / gimp-2.2.0 / libgimpwidgets / gimpcolorbutton.c < prev    next >
C/C++ Source or Header  |  2004-11-07  |  21KB  |  687 lines

  1. /* LIBGIMP - The GIMP Library
  2.  * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
  3.  *
  4.  * gimpcolorbutton.c
  5.  * Copyright (C) 1999-2001 Sven Neumann
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2 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.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Library 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, write to the
  19.  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  20.  * Boston, MA 02111-1307, USA.
  21.  */
  22.  
  23. #include "config.h"
  24.  
  25. #include <string.h>
  26.  
  27. #include <gtk/gtk.h>
  28.  
  29. #include "libgimpcolor/gimpcolor.h"
  30.  
  31. #include "gimpwidgetstypes.h"
  32.  
  33. #include "gimpcolorarea.h"
  34. #include "gimpcolorbutton.h"
  35. #include "gimpcolornotebook.h"
  36. #include "gimpcolorselection.h"
  37. #include "gimpdialog.h"
  38. #include "gimphelpui.h"
  39. #include "gimpstock.h"
  40. #include "gimpwidgets-private.h"
  41.  
  42. #include "libgimp/libgimp-intl.h"
  43.  
  44.  
  45. #define COLOR_SELECTION_KEY "gimp-color-selection"
  46. #define RESPONSE_RESET      1
  47.  
  48. #define TODOUBLE(i) (i / 65535.0)
  49. #define TOUINT16(d) ((guint16) (d * 65535 + 0.5))
  50.  
  51.  
  52. #define GIMP_COLOR_BUTTON_COLOR_FG    "color-button-use-foreground"
  53. #define GIMP_COLOR_BUTTON_COLOR_BG    "color-button-use-background"
  54. #define GIMP_COLOR_BUTTON_COLOR_BLACK "color-button-use-black"
  55. #define GIMP_COLOR_BUTTON_COLOR_WHITE "color-button-use-white"
  56.  
  57.  
  58. enum
  59. {
  60.   COLOR_CHANGED,
  61.   LAST_SIGNAL
  62. };
  63.  
  64.  
  65. static void     gimp_color_button_class_init   (GimpColorButtonClass *klass);
  66. static void     gimp_color_button_init         (GimpColorButton      *button,
  67.                                                 GimpColorButtonClass *klass);
  68.  
  69. static void     gimp_color_button_destroy           (GtkObject       *object);
  70.  
  71. static gboolean gimp_color_button_button_press      (GtkWidget       *widget,
  72.                                                      GdkEventButton  *bevent);
  73. static void     gimp_color_button_state_changed     (GtkWidget       *widget,
  74.                                                      GtkStateType     prev_state);
  75. static void     gimp_color_button_clicked           (GtkButton       *button);
  76. static GType    gimp_color_button_get_action_type   (GimpColorButton *button);
  77.  
  78. static void     gimp_color_button_dialog_response   (GtkWidget       *dialog,
  79.                                                      gint             response_id,
  80.                                                      GimpColorButton *button);
  81. static void     gimp_color_button_use_color         (GtkAction       *action,
  82.                                                      GimpColorButton *button);
  83. static void     gimp_color_button_area_changed      (GtkWidget       *color_area,
  84.                                                      GimpColorButton *button);
  85. static void     gimp_color_button_selection_changed (GtkWidget       *selection,
  86.                                                      GimpColorButton *button);
  87. static void     gimp_color_button_help_func         (const gchar     *help_id,
  88.                                                      gpointer         help_data);
  89.  
  90.  
  91. static GtkActionEntry actions[] =
  92. {
  93.   { "color-button-popup", NULL,
  94.     "Color Button Menu", NULL, NULL,
  95.     NULL
  96.   },
  97.  
  98.   { GIMP_COLOR_BUTTON_COLOR_FG, NULL,
  99.     N_("_Foreground Color"), NULL, NULL,
  100.     G_CALLBACK (gimp_color_button_use_color)
  101.   },
  102.   { GIMP_COLOR_BUTTON_COLOR_BG, NULL,
  103.     N_("_Background Color"), NULL, NULL,
  104.     G_CALLBACK (gimp_color_button_use_color)
  105.   },
  106.   { GIMP_COLOR_BUTTON_COLOR_BLACK, NULL,
  107.     N_("Blac_k"), NULL, NULL,
  108.     G_CALLBACK (gimp_color_button_use_color)
  109.   },
  110.   { GIMP_COLOR_BUTTON_COLOR_WHITE, NULL,
  111.     N_("_White"), NULL, NULL,
  112.     G_CALLBACK (gimp_color_button_use_color)
  113.   }
  114. };
  115.  
  116. static guint   gimp_color_button_signals[LAST_SIGNAL] = { 0 };
  117.  
  118. static GimpButtonClass * parent_class = NULL;
  119.  
  120.  
  121. GType
  122. gimp_color_button_get_type (void)
  123. {
  124.   static GType button_type = 0;
  125.  
  126.   if (!button_type)
  127.     {
  128.       static const GTypeInfo button_info =
  129.       {
  130.         sizeof (GimpColorButtonClass),
  131.         (GBaseInitFunc) NULL,
  132.         (GBaseFinalizeFunc) NULL,
  133.         (GClassInitFunc) gimp_color_button_class_init,
  134.         NULL,           /* class_finalize */
  135.         NULL,           /* class_data     */
  136.         sizeof (GimpColorButton),
  137.         0,              /* n_preallocs    */
  138.         (GInstanceInitFunc) gimp_color_button_init,
  139.       };
  140.  
  141.       button_type = g_type_register_static (GIMP_TYPE_BUTTON,
  142.                                             "GimpColorButton",
  143.                                             &button_info, 0);
  144.     }
  145.  
  146.   return button_type;
  147. }
  148.  
  149. static void
  150. gimp_color_button_class_init (GimpColorButtonClass *klass)
  151. {
  152.   GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
  153.   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
  154.   GtkButtonClass *button_class = GTK_BUTTON_CLASS (klass);
  155.  
  156.   parent_class = g_type_class_peek_parent (klass);
  157.  
  158.   gimp_color_button_signals[COLOR_CHANGED] =
  159.     g_signal_new ("color_changed",
  160.                   G_TYPE_FROM_CLASS (klass),
  161.                   G_SIGNAL_RUN_FIRST,
  162.                   G_STRUCT_OFFSET (GimpColorButtonClass, color_changed),
  163.                   NULL, NULL,
  164.                   g_cclosure_marshal_VOID__VOID,
  165.                   G_TYPE_NONE, 0);
  166.  
  167.   object_class->destroy            = gimp_color_button_destroy;
  168.  
  169.   widget_class->button_press_event = gimp_color_button_button_press;
  170.   widget_class->state_changed      = gimp_color_button_state_changed;
  171.  
  172.   button_class->clicked            = gimp_color_button_clicked;
  173.  
  174.   klass->color_changed             = NULL;
  175.   klass->get_action_type           = gimp_color_button_get_action_type;
  176. }
  177.  
  178. static void
  179. gimp_color_button_init (GimpColorButton      *button,
  180.                         GimpColorButtonClass *klass)
  181. {
  182.   GtkActionGroup *group;
  183.   GtkUIManager   *ui_manager;
  184.   GimpRGB         color;
  185.   gint            i;
  186.  
  187.   button->continuous_update = FALSE;
  188.   button->title             = NULL;
  189.   button->dialog            = NULL;
  190.  
  191.   gimp_rgba_set (&color, 0.0, 0.0, 0.0, 1.0);
  192.   button->color_area = gimp_color_area_new (&color, FALSE, GDK_BUTTON2_MASK);
  193.   g_signal_connect (button->color_area, "color_changed",
  194.                     G_CALLBACK (gimp_color_button_area_changed),
  195.                     button);
  196.  
  197.   gtk_container_add (GTK_CONTAINER (button), button->color_area);
  198.   gtk_widget_show (button->color_area);
  199.  
  200.   /* right-click opens a popup */
  201.   button->popup_menu = ui_manager = gtk_ui_manager_new ();
  202.  
  203.   group = gtk_action_group_new ("color-button");
  204.  
  205.   for (i = 0; i < G_N_ELEMENTS (actions); i++)
  206.     {
  207.       const gchar *label   = gettext (actions[i].label);
  208.       const gchar *tooltip = gettext (actions[i].tooltip);
  209.       GtkAction   *action;
  210.  
  211.       action = g_object_new (klass->get_action_type (button),
  212.                              "name",     actions[i].name,
  213.                              "label",    label,
  214.                              "tooltip",  tooltip,
  215.                              "stock-id", actions[i].stock_id,
  216.                              NULL);
  217.  
  218.       if (actions[i].callback)
  219.         g_signal_connect (action, "activate",
  220.                           actions[i].callback,
  221.                           button);
  222.  
  223.       gtk_action_group_add_action_with_accel (group, action,
  224.                                               actions[i].accelerator);
  225.  
  226.       g_object_unref (action);
  227.     }
  228.  
  229.   gtk_ui_manager_insert_action_group (ui_manager, group, -1);
  230.   g_object_unref (group);
  231.  
  232.   gtk_ui_manager_add_ui_from_string
  233.     (ui_manager,
  234.      "<ui>\n"
  235.      "  <popup action=\"color-button-popup\">\n"
  236.      "    <menuitem action=\"" GIMP_COLOR_BUTTON_COLOR_FG "\" />\n"
  237.      "    <menuitem action=\"" GIMP_COLOR_BUTTON_COLOR_BG "\" />\n"
  238.      "    <separator />\n"
  239.      "    <menuitem action=\"" GIMP_COLOR_BUTTON_COLOR_BLACK "\" />\n"
  240.      "    <menuitem action=\"" GIMP_COLOR_BUTTON_COLOR_WHITE "\" />\n"
  241.      "  </popup>\n"
  242.      "</ui>\n",
  243.      -1, NULL);
  244. }
  245.  
  246. static void
  247. gimp_color_button_destroy (GtkObject *object)
  248. {
  249.   GimpColorButton *button = GIMP_COLOR_BUTTON (object);
  250.  
  251.   if (button->title)
  252.     {
  253.       g_free (button->title);
  254.       button->title = NULL;
  255.     }
  256.  
  257.   if (button->dialog)
  258.     {
  259.       gtk_widget_destroy (button->dialog);
  260.       button->dialog = NULL;
  261.     }
  262.  
  263.   if (button->color_area)
  264.     {
  265.       gtk_widget_destroy (button->color_area);
  266.       button->color_area = NULL;
  267.     }
  268.  
  269.   if (button->popup_menu)
  270.     {
  271.       g_object_unref (button->popup_menu);
  272.       button->popup_menu = NULL;
  273.     }
  274.  
  275.   GTK_OBJECT_CLASS (parent_class)->destroy (object);
  276. }
  277.  
  278. static gboolean
  279. gimp_color_button_button_press (GtkWidget      *widget,
  280.                                 GdkEventButton *bevent)
  281. {
  282.   GimpColorButton *button = GIMP_COLOR_BUTTON (widget);
  283.  
  284.   if (bevent->button == 3)
  285.     {
  286.       GtkWidget *menu = gtk_ui_manager_get_widget (button->popup_menu,
  287.                                                    "/color-button-popup");
  288.  
  289.       gtk_menu_set_screen (GTK_MENU (menu), gtk_widget_get_screen (widget));
  290.  
  291.       gtk_menu_popup (GTK_MENU (menu),
  292.                       NULL, NULL, NULL, NULL,
  293.                       bevent->button, bevent->time);
  294.     }
  295.  
  296.   if (GTK_WIDGET_CLASS (parent_class)->button_press_event)
  297.     return GTK_WIDGET_CLASS (parent_class)->button_press_event (widget, bevent);
  298.  
  299.   return FALSE;
  300. }
  301.  
  302. static void
  303. gimp_color_button_state_changed (GtkWidget    *widget,
  304.                                  GtkStateType  prev_state)
  305. {
  306.   g_return_if_fail (GIMP_IS_COLOR_BUTTON (widget));
  307.  
  308.   if (! GTK_WIDGET_IS_SENSITIVE (widget) && GIMP_COLOR_BUTTON (widget)->dialog)
  309.     gtk_widget_hide (GIMP_COLOR_BUTTON (widget)->dialog);
  310.  
  311.   if (GTK_WIDGET_CLASS (parent_class)->state_changed)
  312.     GTK_WIDGET_CLASS (parent_class)->state_changed (widget, prev_state);
  313. }
  314.  
  315. static void
  316. gimp_color_button_clicked (GtkButton *button)
  317. {
  318.   GimpColorButton *color_button = GIMP_COLOR_BUTTON (button);
  319.  
  320.   if (! color_button->dialog)
  321.     {
  322.       GtkWidget *dialog;
  323.       GtkWidget *selection;
  324.       GimpRGB    color;
  325.  
  326.       gimp_color_button_get_color (color_button, &color);
  327.  
  328.       dialog = color_button->dialog =
  329.         gimp_dialog_new (color_button->title, COLOR_SELECTION_KEY,
  330.                          GTK_WIDGET (button), 0,
  331.                          gimp_color_button_help_func, NULL,
  332.  
  333.                          GIMP_STOCK_RESET, RESPONSE_RESET,
  334.                          GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
  335.                          GTK_STOCK_OK,     GTK_RESPONSE_OK,
  336.  
  337.                          NULL);
  338.  
  339.       g_signal_connect (dialog, "response",
  340.                         G_CALLBACK (gimp_color_button_dialog_response),
  341.                         color_button);
  342.       g_signal_connect (dialog, "destroy",
  343.                         G_CALLBACK (gtk_widget_destroyed),
  344.                         &color_button->dialog);
  345.  
  346.       selection = gimp_color_selection_new ();
  347.       gtk_container_set_border_width (GTK_CONTAINER (selection), 6);
  348.       gimp_color_selection_set_show_alpha (GIMP_COLOR_SELECTION (selection),
  349.                                            gimp_color_button_has_alpha (color_button));
  350.       gimp_color_selection_set_color (GIMP_COLOR_SELECTION (selection), &color);
  351.       gimp_color_selection_set_old_color (GIMP_COLOR_SELECTION (selection),
  352.                                           &color);
  353.       gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), selection);
  354.       gtk_widget_show (selection);
  355.  
  356.       g_signal_connect (selection, "color_changed",
  357.                         G_CALLBACK (gimp_color_button_selection_changed),
  358.                         button);
  359.  
  360.       g_object_set_data (G_OBJECT (color_button->dialog), COLOR_SELECTION_KEY,
  361.                          selection);
  362.     }
  363.  
  364.   gtk_window_present (GTK_WINDOW (color_button->dialog));
  365. }
  366.  
  367. static GType
  368. gimp_color_button_get_action_type (GimpColorButton *button)
  369. {
  370.   return GTK_TYPE_ACTION;
  371. }
  372.  
  373.  
  374. /*  public functions  */
  375.  
  376. /**
  377.  * gimp_color_button_new:
  378.  * @title: String that will be used as title for the color_selector.
  379.  * @width: Width of the colorpreview in pixels.
  380.  * @height: Height of the colorpreview in pixels.
  381.  * @color: A pointer to a #GimpRGB color.
  382.  * @type:
  383.  *
  384.  * Creates a new #GimpColorButton widget.
  385.  *
  386.  * This returns a button with a preview showing the color.
  387.  * When the button is clicked a GtkColorSelectionDialog is opened.
  388.  * If the user changes the color the new color is written into the
  389.  * array that was used to pass the initial color and the "color_changed"
  390.  * signal is emitted.
  391.  *
  392.  * Returns: Pointer to the new #GimpColorButton widget.
  393.  **/
  394. GtkWidget *
  395. gimp_color_button_new (const gchar       *title,
  396.                        gint               width,
  397.                        gint               height,
  398.                        const GimpRGB     *color,
  399.                        GimpColorAreaType  type)
  400. {
  401.   GimpColorButton *button;
  402.  
  403.   g_return_val_if_fail (color != NULL, NULL);
  404.  
  405.   button = g_object_new (GIMP_TYPE_COLOR_BUTTON, NULL);
  406.  
  407.   button->title = g_strdup (title);
  408.  
  409.   gtk_widget_set_size_request (GTK_WIDGET (button->color_area), width, height);
  410.  
  411.   gimp_color_area_set_type (GIMP_COLOR_AREA (button->color_area), type);
  412.   gimp_color_area_set_color (GIMP_COLOR_AREA (button->color_area), color);
  413.  
  414.   return GTK_WIDGET (button);
  415. }
  416.  
  417. /**
  418.  * gimp_color_button_set_color:
  419.  * @button: Pointer to a #GimpColorButton.
  420.  * @color: Pointer to the new #GimpRGB color.
  421.  *
  422.  * Sets the @button to the given @color.
  423.  **/
  424. void
  425. gimp_color_button_set_color (GimpColorButton *button,
  426.                              const GimpRGB   *color)
  427. {
  428.   g_return_if_fail (GIMP_IS_COLOR_BUTTON (button));
  429.   g_return_if_fail (color != NULL);
  430.  
  431.   gimp_color_area_set_color (GIMP_COLOR_AREA (button->color_area), color);
  432. }
  433.  
  434. /**
  435.  * gimp_color_button_get_color:
  436.  * @button: Pointer to a #GimpColorButton.
  437.  * @color: Pointer to a #GimpRGB struct used to return the color.
  438.  *
  439.  * Retrieves the currently set color from the @button.
  440.  **/
  441. void
  442. gimp_color_button_get_color (GimpColorButton *button,
  443.                              GimpRGB         *color)
  444. {
  445.   g_return_if_fail (GIMP_IS_COLOR_BUTTON (button));
  446.   g_return_if_fail (color != NULL);
  447.  
  448.   gimp_color_area_get_color (GIMP_COLOR_AREA (button->color_area), color);
  449. }
  450.  
  451. /**
  452.  * gimp_color_button_has_alpha:
  453.  * @button: Pointer to a #GimpColorButton.
  454.  *
  455.  * Checks whether the @buttons shows transparency information.
  456.  *
  457.  * Returns: %TRUE if the @button shows transparency information, %FALSE
  458.  * otherwise.
  459.  **/
  460. gboolean
  461. gimp_color_button_has_alpha (GimpColorButton *button)
  462. {
  463.   g_return_val_if_fail (GIMP_IS_COLOR_BUTTON (button), FALSE);
  464.  
  465.   return gimp_color_area_has_alpha (GIMP_COLOR_AREA (button->color_area));
  466. }
  467.  
  468. /**
  469.  * gimp_color_button_set_type:
  470.  * @button: Pointer to a #GimpColorButton.
  471.  * @type: the new #GimpColorAreaType
  472.  *
  473.  * Sets the @button to the given @type. See also gimp_color_area_set_type().
  474.  **/
  475. void
  476. gimp_color_button_set_type (GimpColorButton   *button,
  477.                             GimpColorAreaType  type)
  478. {
  479.   g_return_if_fail (GIMP_IS_COLOR_BUTTON (button));
  480.  
  481.   gimp_color_area_set_type (GIMP_COLOR_AREA (button->color_area), type);
  482. }
  483.  
  484. /**
  485.  * gimp_color_button_get_update:
  486.  * @button: A #GimpColorButton widget.
  487.  *
  488.  * Returns the color button's @continuous_update property.
  489.  *
  490.  * Return value: the @continuous_update property.
  491.  **/
  492. gboolean
  493. gimp_color_button_get_update (GimpColorButton *button)
  494. {
  495.   g_return_val_if_fail (GIMP_IS_COLOR_BUTTON (button), FALSE);
  496.  
  497.   return button->continuous_update;
  498. }
  499.  
  500. /**
  501.  * gimp_color_button_set_update:
  502.  * @button:     A #GimpColorButton widget.
  503.  * @continuous: The new setting of the @continuous_update property.
  504.  *
  505.  * When set to #TRUE, the @button will emit the "color_changed"
  506.  * continuously while the color is changed in the color selection
  507.  * dialog.
  508.  **/
  509. void
  510. gimp_color_button_set_update (GimpColorButton *button,
  511.                               gboolean         continuous)
  512. {
  513.   g_return_if_fail (GIMP_IS_COLOR_BUTTON (button));
  514.  
  515.   if (continuous != button->continuous_update)
  516.     {
  517.       button->continuous_update = continuous ? TRUE : FALSE;
  518.  
  519.       if (button->dialog)
  520.         {
  521.           GimpColorSelection *selection;
  522.           GimpRGB             color;
  523.  
  524.           selection = g_object_get_data (G_OBJECT (button->dialog),
  525.                                          COLOR_SELECTION_KEY);
  526.  
  527.           if (button->continuous_update)
  528.             {
  529.               gimp_color_selection_get_color (selection, &color);
  530.               gimp_color_button_set_color (button, &color);
  531.             }
  532.           else
  533.             {
  534.               gimp_color_selection_get_old_color (selection, &color);
  535.               gimp_color_button_set_color (button, &color);
  536.             }
  537.         }
  538.     }
  539. }
  540.  
  541.  
  542. /*  private functions  */
  543.  
  544. static void
  545. gimp_color_button_dialog_response (GtkWidget       *dialog,
  546.                                    gint             response_id,
  547.                                    GimpColorButton *button)
  548. {
  549.   GtkWidget *selection;
  550.   GimpRGB    color;
  551.  
  552.   selection = g_object_get_data (G_OBJECT (dialog), COLOR_SELECTION_KEY);
  553.  
  554.   switch (response_id)
  555.     {
  556.     case RESPONSE_RESET:
  557.       gimp_color_selection_reset (GIMP_COLOR_SELECTION (selection));
  558.       break;
  559.  
  560.     case GTK_RESPONSE_OK:
  561.       if (! button->continuous_update)
  562.         {
  563.           gimp_color_selection_get_color (GIMP_COLOR_SELECTION (selection),
  564.                                           &color);
  565.           gimp_color_button_set_color (button, &color);
  566.         }
  567.  
  568.       gtk_widget_hide (dialog);
  569.       break;
  570.  
  571.     default:
  572.       if (button->continuous_update)
  573.         {
  574.           gimp_color_selection_get_old_color (GIMP_COLOR_SELECTION (selection),
  575.                                               &color);
  576.           gimp_color_button_set_color (button, &color);
  577.         }
  578.  
  579.       gtk_widget_hide (dialog);
  580.       break;
  581.     }
  582. }
  583.  
  584. static void
  585. gimp_color_button_use_color (GtkAction       *action,
  586.                              GimpColorButton *button)
  587. {
  588.   const gchar *name;
  589.   GimpRGB      color;
  590.  
  591.   name = gtk_action_get_name (action);
  592.   gimp_color_button_get_color (button, &color);
  593.  
  594.   if (! strcmp (name, GIMP_COLOR_BUTTON_COLOR_FG))
  595.     {
  596.       if (_gimp_get_foreground_func)
  597.         _gimp_get_foreground_func (&color);
  598.       else
  599.         gimp_rgba_set (&color, 0.0, 0.0, 0.0, 1.0);
  600.     }
  601.   else if (! strcmp (name, GIMP_COLOR_BUTTON_COLOR_BG))
  602.     {
  603.       if (_gimp_get_background_func)
  604.         _gimp_get_background_func (&color);
  605.       else
  606.         gimp_rgba_set (&color, 1.0, 1.0, 1.0, 1.0);
  607.     }
  608.   else if (! strcmp (name, GIMP_COLOR_BUTTON_COLOR_BLACK))
  609.     {
  610.       gimp_rgba_set (&color, 0.0, 0.0, 0.0, 1.0);
  611.     }
  612.   else if (! strcmp (name, GIMP_COLOR_BUTTON_COLOR_WHITE))
  613.     {
  614.       gimp_rgba_set (&color, 1.0, 1.0, 1.0, 1.0);
  615.     }
  616.  
  617.   gimp_color_button_set_color (button, &color);
  618. }
  619.  
  620. static void
  621. gimp_color_button_area_changed (GtkWidget       *color_area,
  622.                                 GimpColorButton *button)
  623. {
  624.   if (button->dialog)
  625.     {
  626.       GimpColorSelection *selection;
  627.       GimpRGB             color;
  628.  
  629.       selection = g_object_get_data (G_OBJECT (button->dialog),
  630.                                      COLOR_SELECTION_KEY);
  631.  
  632.       gimp_color_button_get_color (button, &color);
  633.  
  634.       g_signal_handlers_block_by_func (selection,
  635.                                        gimp_color_button_selection_changed,
  636.                                        button);
  637.  
  638.       gimp_color_selection_set_color (selection, &color);
  639.  
  640.       g_signal_handlers_unblock_by_func (selection,
  641.                                          gimp_color_button_selection_changed,
  642.                                          button);
  643.     }
  644.  
  645.   g_signal_emit (button, gimp_color_button_signals[COLOR_CHANGED], 0);
  646. }
  647.  
  648. static void
  649. gimp_color_button_selection_changed (GtkWidget       *selection,
  650.                                      GimpColorButton *button)
  651. {
  652.   if (button->continuous_update)
  653.     {
  654.       GimpRGB color;
  655.  
  656.       gimp_color_selection_get_color (GIMP_COLOR_SELECTION (selection), &color);
  657.  
  658.       g_signal_handlers_block_by_func (button->color_area,
  659.                                        gimp_color_button_area_changed,
  660.                                        button);
  661.  
  662.       gimp_color_area_set_color (GIMP_COLOR_AREA (button->color_area), &color);
  663.  
  664.       g_signal_handlers_unblock_by_func (button->color_area,
  665.                                          gimp_color_button_area_changed,
  666.                                          button);
  667.  
  668.       g_signal_emit (button, gimp_color_button_signals[COLOR_CHANGED], 0);
  669.     }
  670. }
  671.  
  672. static void
  673. gimp_color_button_help_func (const gchar *help_id,
  674.                              gpointer     help_data)
  675. {
  676.   GimpColorSelection *selection;
  677.   GimpColorNotebook  *notebook;
  678.  
  679.   selection = g_object_get_data (G_OBJECT (help_data), COLOR_SELECTION_KEY);
  680.  
  681.   notebook = GIMP_COLOR_NOTEBOOK (selection->notebook);
  682.  
  683.   help_id = GIMP_COLOR_SELECTOR_GET_CLASS (notebook->cur_page)->help_id;
  684.  
  685.   gimp_standard_help_func (help_id, NULL);
  686. }
  687.