2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1997-11-25 06:05:25 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1997-11-25 06:05:25 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1997-11-25 06:05:25 +08:00
|
|
|
* (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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2012-03-30 01:19:01 +08:00
|
|
|
#include <gegl.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2001-11-28 07:26:25 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
2011-04-28 20:23:33 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
2001-11-28 07:26:25 +08:00
|
|
|
|
2001-05-08 11:48:54 +08:00
|
|
|
#include "widgets-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2016-05-30 03:54:39 +08:00
|
|
|
#include "config/gimpcoreconfig.h"
|
|
|
|
|
2001-11-28 07:26:25 +08:00
|
|
|
#include "core/gimp.h"
|
|
|
|
#include "core/gimpcontext.h"
|
|
|
|
|
2004-11-04 20:15:49 +08:00
|
|
|
#include "gimpaction.h"
|
2004-09-24 04:41:40 +08:00
|
|
|
#include "gimpcolordialog.h"
|
2001-04-11 09:13:53 +08:00
|
|
|
#include "gimpcolorpanel.h"
|
2001-11-28 07:26:25 +08:00
|
|
|
|
2000-04-28 01:27:28 +08:00
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
/* local function prototypes */
|
2001-10-17 19:33:43 +08:00
|
|
|
|
2010-09-27 04:38:01 +08:00
|
|
|
static void gimp_color_panel_dispose (GObject *object);
|
|
|
|
|
2004-11-04 20:15:49 +08:00
|
|
|
static gboolean gimp_color_panel_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *bevent);
|
2010-09-27 04:38:01 +08:00
|
|
|
|
2004-11-04 20:15:49 +08:00
|
|
|
static void gimp_color_panel_clicked (GtkButton *button);
|
2010-09-27 04:38:01 +08:00
|
|
|
|
2004-11-04 20:15:49 +08:00
|
|
|
static void gimp_color_panel_color_changed (GimpColorButton *button);
|
|
|
|
static GType gimp_color_panel_get_action_type (GimpColorButton *button);
|
2001-11-28 07:26:25 +08:00
|
|
|
|
2004-11-04 20:15:49 +08:00
|
|
|
static void gimp_color_panel_dialog_update (GimpColorDialog *dialog,
|
|
|
|
const GimpRGB *color,
|
|
|
|
GimpColorDialogState state,
|
|
|
|
GimpColorPanel *panel);
|
1999-08-23 22:19:26 +08:00
|
|
|
|
2007-10-09 00:11:35 +08:00
|
|
|
|
2006-05-15 17:46:31 +08:00
|
|
|
G_DEFINE_TYPE (GimpColorPanel, gimp_color_panel, GIMP_TYPE_COLOR_BUTTON)
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
#define parent_class gimp_color_panel_parent_class
|
1999-08-24 10:52:40 +08:00
|
|
|
|
|
|
|
|
2001-01-15 14:24:24 +08:00
|
|
|
static void
|
|
|
|
gimp_color_panel_class_init (GimpColorPanelClass *klass)
|
|
|
|
{
|
2010-09-27 04:38:01 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2004-09-13 23:15:23 +08:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
GtkButtonClass *button_class = GTK_BUTTON_CLASS (klass);
|
|
|
|
GimpColorButtonClass *color_button_class = GIMP_COLOR_BUTTON_CLASS (klass);
|
2003-11-08 23:32:38 +08:00
|
|
|
|
2010-09-27 04:38:01 +08:00
|
|
|
object_class->dispose = gimp_color_panel_dispose;
|
2005-12-20 06:37:49 +08:00
|
|
|
|
2004-11-04 20:15:49 +08:00
|
|
|
widget_class->button_press_event = gimp_color_panel_button_press;
|
2005-12-20 06:37:49 +08:00
|
|
|
|
2004-11-04 20:15:49 +08:00
|
|
|
button_class->clicked = gimp_color_panel_clicked;
|
2005-12-20 06:37:49 +08:00
|
|
|
|
2004-11-04 20:15:49 +08:00
|
|
|
color_button_class->color_changed = gimp_color_panel_color_changed;
|
|
|
|
color_button_class->get_action_type = gimp_color_panel_get_action_type;
|
1999-08-24 10:52:40 +08:00
|
|
|
}
|
|
|
|
|
2001-01-15 14:24:24 +08:00
|
|
|
static void
|
|
|
|
gimp_color_panel_init (GimpColorPanel *panel)
|
|
|
|
{
|
2004-09-13 23:15:23 +08:00
|
|
|
panel->context = NULL;
|
|
|
|
panel->color_dialog = NULL;
|
2001-01-15 14:24:24 +08:00
|
|
|
}
|
1999-08-23 22:19:26 +08:00
|
|
|
|
2000-04-03 23:40:30 +08:00
|
|
|
static void
|
2010-09-27 04:38:01 +08:00
|
|
|
gimp_color_panel_dispose (GObject *object)
|
2000-04-03 23:40:30 +08:00
|
|
|
{
|
2004-02-18 21:43:50 +08:00
|
|
|
GimpColorPanel *panel = GIMP_COLOR_PANEL (object);
|
2000-04-03 23:40:30 +08:00
|
|
|
|
2004-09-13 23:15:23 +08:00
|
|
|
if (panel->color_dialog)
|
2000-04-03 23:40:30 +08:00
|
|
|
{
|
2004-09-24 04:41:40 +08:00
|
|
|
gtk_widget_destroy (panel->color_dialog);
|
2004-09-13 23:15:23 +08:00
|
|
|
panel->color_dialog = NULL;
|
2000-04-03 23:40:30 +08:00
|
|
|
}
|
2001-10-17 19:33:43 +08:00
|
|
|
|
2010-09-27 04:38:01 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
2001-11-28 07:26:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_color_panel_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *bevent)
|
|
|
|
{
|
2011-10-02 22:23:59 +08:00
|
|
|
if (gdk_event_triggers_context_menu ((GdkEvent *) bevent))
|
2001-11-28 07:26:25 +08:00
|
|
|
{
|
|
|
|
GimpColorButton *color_button;
|
2002-12-04 06:16:56 +08:00
|
|
|
GimpColorPanel *color_panel;
|
2004-11-04 20:15:49 +08:00
|
|
|
GtkUIManager *ui_manager;
|
|
|
|
GtkActionGroup *group;
|
|
|
|
GtkAction *action;
|
|
|
|
GimpRGB color;
|
2001-11-28 07:26:25 +08:00
|
|
|
|
|
|
|
color_button = GIMP_COLOR_BUTTON (widget);
|
2002-12-04 06:16:56 +08:00
|
|
|
color_panel = GIMP_COLOR_PANEL (widget);
|
2016-09-07 08:22:57 +08:00
|
|
|
ui_manager = gimp_color_button_get_ui_manager (color_button);
|
2002-12-04 06:16:56 +08:00
|
|
|
|
2004-11-04 20:15:49 +08:00
|
|
|
group = gtk_ui_manager_get_action_groups (ui_manager)->data;
|
|
|
|
|
|
|
|
action = gtk_action_group_get_action (group,
|
|
|
|
"color-button-use-foreground");
|
2005-03-23 02:51:57 +08:00
|
|
|
gtk_action_set_visible (action, color_panel->context != NULL);
|
2002-12-04 06:16:56 +08:00
|
|
|
|
2004-11-04 20:15:49 +08:00
|
|
|
action = gtk_action_group_get_action (group,
|
|
|
|
"color-button-use-background");
|
2005-03-23 02:51:57 +08:00
|
|
|
gtk_action_set_visible (action, color_panel->context != NULL);
|
2002-12-04 06:16:56 +08:00
|
|
|
|
2004-11-04 20:15:49 +08:00
|
|
|
if (color_panel->context)
|
|
|
|
{
|
|
|
|
action = gtk_action_group_get_action (group,
|
|
|
|
"color-button-use-foreground");
|
|
|
|
gimp_context_get_foreground (color_panel->context, &color);
|
|
|
|
g_object_set (action, "color", &color, NULL);
|
|
|
|
|
|
|
|
action = gtk_action_group_get_action (group,
|
|
|
|
"color-button-use-background");
|
|
|
|
gimp_context_get_background (color_panel->context, &color);
|
|
|
|
g_object_set (action, "color", &color, NULL);
|
2002-12-04 06:16:56 +08:00
|
|
|
}
|
2001-11-28 07:26:25 +08:00
|
|
|
|
2004-11-04 20:15:49 +08:00
|
|
|
action = gtk_action_group_get_action (group, "color-button-use-black");
|
|
|
|
gimp_rgba_set (&color, 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE);
|
|
|
|
g_object_set (action, "color", &color, NULL);
|
2001-11-28 07:26:25 +08:00
|
|
|
|
2004-11-04 20:15:49 +08:00
|
|
|
action = gtk_action_group_get_action (group, "color-button-use-white");
|
|
|
|
gimp_rgba_set (&color, 1.0, 1.0, 1.0, GIMP_OPACITY_OPAQUE);
|
|
|
|
g_object_set (action, "color", &color, NULL);
|
2001-11-28 07:26:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (GTK_WIDGET_CLASS (parent_class)->button_press_event)
|
|
|
|
return GTK_WIDGET_CLASS (parent_class)->button_press_event (widget, bevent);
|
|
|
|
|
|
|
|
return FALSE;
|
2000-04-03 23:40:30 +08:00
|
|
|
}
|
|
|
|
|
2004-11-04 20:15:49 +08:00
|
|
|
static void
|
|
|
|
gimp_color_panel_clicked (GtkButton *button)
|
|
|
|
{
|
|
|
|
GimpColorPanel *panel = GIMP_COLOR_PANEL (button);
|
|
|
|
GimpRGB color;
|
|
|
|
|
|
|
|
gimp_color_button_get_color (GIMP_COLOR_BUTTON (button), &color);
|
|
|
|
|
|
|
|
if (! panel->color_dialog)
|
|
|
|
{
|
2016-09-07 08:22:57 +08:00
|
|
|
GimpColorButton *color_button = GIMP_COLOR_BUTTON (button);
|
|
|
|
|
2004-11-04 20:15:49 +08:00
|
|
|
panel->color_dialog =
|
2006-09-26 16:55:41 +08:00
|
|
|
gimp_color_dialog_new (NULL, panel->context,
|
2016-09-07 08:22:57 +08:00
|
|
|
gimp_color_button_get_title (color_button),
|
2004-11-04 20:15:49 +08:00
|
|
|
NULL, NULL,
|
|
|
|
GTK_WIDGET (button),
|
|
|
|
NULL, NULL,
|
2012-04-01 21:46:48 +08:00
|
|
|
&color,
|
2016-09-07 08:22:57 +08:00
|
|
|
gimp_color_button_get_update (color_button),
|
|
|
|
gimp_color_button_has_alpha (color_button));
|
2004-11-04 20:15:49 +08:00
|
|
|
|
|
|
|
g_signal_connect (panel->color_dialog, "destroy",
|
|
|
|
G_CALLBACK (gtk_widget_destroyed),
|
|
|
|
&panel->color_dialog);
|
|
|
|
|
|
|
|
g_signal_connect (panel->color_dialog, "update",
|
|
|
|
G_CALLBACK (gimp_color_panel_dialog_update),
|
|
|
|
panel);
|
|
|
|
}
|
2016-05-15 23:36:26 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_color_dialog_set_color (GIMP_COLOR_DIALOG (panel->color_dialog),
|
|
|
|
&color);
|
|
|
|
}
|
2004-11-04 20:15:49 +08:00
|
|
|
|
|
|
|
gtk_window_present (GTK_WINDOW (panel->color_dialog));
|
|
|
|
}
|
|
|
|
|
|
|
|
static GType
|
|
|
|
gimp_color_panel_get_action_type (GimpColorButton *button)
|
|
|
|
{
|
|
|
|
return GIMP_TYPE_ACTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2001-01-15 14:24:24 +08:00
|
|
|
GtkWidget *
|
2001-01-21 21:41:07 +08:00
|
|
|
gimp_color_panel_new (const gchar *title,
|
2006-04-12 20:49:29 +08:00
|
|
|
const GimpRGB *color,
|
|
|
|
GimpColorAreaType type,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-12-04 06:16:56 +08:00
|
|
|
g_return_val_if_fail (title != NULL, NULL);
|
2001-01-15 14:24:24 +08:00
|
|
|
g_return_val_if_fail (color != NULL, NULL);
|
2011-02-16 03:54:52 +08:00
|
|
|
g_return_val_if_fail (width > 0, NULL);
|
|
|
|
g_return_val_if_fail (height > 0, NULL);
|
|
|
|
|
|
|
|
return g_object_new (GIMP_TYPE_COLOR_PANEL,
|
|
|
|
"title", title,
|
|
|
|
"type", type,
|
|
|
|
"color", color,
|
|
|
|
"area-width", width,
|
|
|
|
"area-height", height,
|
|
|
|
NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2001-01-15 14:24:24 +08:00
|
|
|
static void
|
|
|
|
gimp_color_panel_color_changed (GimpColorButton *button)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-02-18 21:43:50 +08:00
|
|
|
GimpColorPanel *panel = GIMP_COLOR_PANEL (button);
|
2001-01-15 14:24:24 +08:00
|
|
|
GimpRGB color;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2007-10-09 00:11:35 +08:00
|
|
|
if (panel->color_dialog)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2012-04-01 21:46:48 +08:00
|
|
|
GimpRGB dialog_color;
|
|
|
|
|
2001-01-15 14:24:24 +08:00
|
|
|
gimp_color_button_get_color (GIMP_COLOR_BUTTON (button), &color);
|
2012-04-01 21:46:48 +08:00
|
|
|
gimp_color_dialog_get_color (GIMP_COLOR_DIALOG (panel->color_dialog),
|
|
|
|
&dialog_color);
|
|
|
|
|
|
|
|
if (gimp_rgba_distance (&color, &dialog_color) > 0.00001 ||
|
|
|
|
color.a != dialog_color.a)
|
|
|
|
{
|
|
|
|
gimp_color_dialog_set_color (GIMP_COLOR_DIALOG (panel->color_dialog),
|
|
|
|
&color);
|
|
|
|
}
|
2001-01-15 14:24:24 +08:00
|
|
|
}
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-11-04 20:15:49 +08:00
|
|
|
void
|
|
|
|
gimp_color_panel_set_context (GimpColorPanel *panel,
|
|
|
|
GimpContext *context)
|
2001-01-15 14:24:24 +08:00
|
|
|
{
|
2004-11-04 20:15:49 +08:00
|
|
|
g_return_if_fail (GIMP_IS_COLOR_PANEL (panel));
|
|
|
|
g_return_if_fail (context == NULL || GIMP_IS_CONTEXT (context));
|
2004-09-24 04:41:40 +08:00
|
|
|
|
2004-11-04 20:15:49 +08:00
|
|
|
panel->context = context;
|
2016-05-30 03:54:39 +08:00
|
|
|
|
|
|
|
if (context)
|
2016-09-07 08:22:57 +08:00
|
|
|
gimp_color_button_set_color_config (GIMP_COLOR_BUTTON (panel),
|
|
|
|
context->gimp->config->color_management);
|
2004-11-04 20:15:49 +08:00
|
|
|
}
|
2004-09-24 04:41:40 +08:00
|
|
|
|
|
|
|
|
2004-11-04 20:15:49 +08:00
|
|
|
/* private functions */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
static void
|
2004-09-24 04:41:40 +08:00
|
|
|
gimp_color_panel_dialog_update (GimpColorDialog *dialog,
|
|
|
|
const GimpRGB *color,
|
|
|
|
GimpColorDialogState state,
|
|
|
|
GimpColorPanel *panel)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-09-24 04:41:40 +08:00
|
|
|
switch (state)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-09-24 04:41:40 +08:00
|
|
|
case GIMP_COLOR_DIALOG_UPDATE:
|
2012-04-01 21:46:48 +08:00
|
|
|
if (gimp_color_button_get_update (GIMP_COLOR_BUTTON (panel)))
|
|
|
|
gimp_color_button_set_color (GIMP_COLOR_BUTTON (panel), color);
|
2004-09-24 04:41:40 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_COLOR_DIALOG_OK:
|
2012-04-01 21:46:48 +08:00
|
|
|
if (! gimp_color_button_get_update (GIMP_COLOR_BUTTON (panel)))
|
|
|
|
gimp_color_button_set_color (GIMP_COLOR_BUTTON (panel), color);
|
|
|
|
gtk_widget_hide (panel->color_dialog);
|
|
|
|
break;
|
2007-10-09 00:11:35 +08:00
|
|
|
|
|
|
|
case GIMP_COLOR_DIALOG_CANCEL:
|
2012-04-01 21:46:48 +08:00
|
|
|
if (gimp_color_button_get_update (GIMP_COLOR_BUTTON (panel)))
|
|
|
|
gimp_color_button_set_color (GIMP_COLOR_BUTTON (panel), color);
|
2004-09-24 04:41:40 +08:00
|
|
|
gtk_widget_hide (panel->color_dialog);
|
2012-04-01 21:46:48 +08:00
|
|
|
break;
|
1999-08-22 19:45:31 +08:00
|
|
|
}
|
|
|
|
}
|