1997-11-25 06:05:25 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (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
|
|
|
|
* along with this program; if not, write to the Free Software
|
1998-04-13 13:44:11 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2001-11-28 07:26:25 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
|
|
|
|
2001-05-08 11:48:54 +08:00
|
|
|
#include "widgets-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-11-28 07:26:25 +08:00
|
|
|
#include "core/gimp.h"
|
|
|
|
#include "core/gimpcontext.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
|
|
|
#include "gimpitemfactory.h"
|
|
|
|
|
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
|
|
|
|
2004-09-24 04:41:40 +08:00
|
|
|
static void gimp_color_panel_class_init (GimpColorPanelClass *klass);
|
|
|
|
static void gimp_color_panel_init (GimpColorPanel *panel);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-09-24 04:41:40 +08:00
|
|
|
static void gimp_color_panel_destroy (GtkObject *object);
|
|
|
|
static gboolean gimp_color_panel_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *bevent);
|
|
|
|
static void gimp_color_panel_color_changed (GimpColorButton *button);
|
|
|
|
static void gimp_color_panel_clicked (GtkButton *button);
|
2001-11-28 07:26:25 +08:00
|
|
|
|
2004-09-24 04:41:40 +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
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-15 14:24:24 +08:00
|
|
|
static GimpColorButtonClass *parent_class = NULL;
|
2001-01-15 09:48:53 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-10-17 19:33:43 +08:00
|
|
|
GType
|
2001-01-15 14:24:24 +08:00
|
|
|
gimp_color_panel_get_type (void)
|
1999-08-24 10:52:40 +08:00
|
|
|
{
|
2001-10-17 19:33:43 +08:00
|
|
|
static GType panel_type = 0;
|
1999-08-24 10:52:40 +08:00
|
|
|
|
2001-10-17 19:33:43 +08:00
|
|
|
if (! panel_type)
|
2001-01-15 14:24:24 +08:00
|
|
|
{
|
2001-10-17 19:33:43 +08:00
|
|
|
static const GTypeInfo panel_info =
|
2001-01-15 14:24:24 +08:00
|
|
|
{
|
2001-10-17 19:33:43 +08:00
|
|
|
sizeof (GimpColorPanelClass),
|
|
|
|
NULL, /* base_init */
|
|
|
|
NULL, /* base_finalize */
|
|
|
|
(GClassInitFunc) gimp_color_panel_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpColorPanel),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_color_panel_init,
|
2001-01-15 14:24:24 +08:00
|
|
|
};
|
|
|
|
|
2001-10-17 19:33:43 +08:00
|
|
|
panel_type = g_type_register_static (GIMP_TYPE_COLOR_BUTTON,
|
|
|
|
"GimpColorPanel",
|
|
|
|
&panel_info, 0);
|
2001-01-15 14:24:24 +08:00
|
|
|
}
|
2003-11-08 23:32:38 +08:00
|
|
|
|
2001-01-15 14:24:24 +08:00
|
|
|
return panel_type;
|
|
|
|
}
|
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)
|
|
|
|
{
|
2004-09-13 23:15:23 +08:00
|
|
|
GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
|
|
|
|
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
|
|
|
|
2001-10-17 19:33:43 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2001-01-15 14:24:24 +08:00
|
|
|
|
|
|
|
object_class->destroy = gimp_color_panel_destroy;
|
2001-11-28 07:26:25 +08:00
|
|
|
widget_class->button_press_event = gimp_color_panel_button_press;
|
2001-01-15 14:24:24 +08:00
|
|
|
button_class->clicked = gimp_color_panel_clicked;
|
2001-01-15 17:27:48 +08:00
|
|
|
color_button_class->color_changed = gimp_color_panel_color_changed;
|
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
|
2001-01-15 14:24:24 +08:00
|
|
|
gimp_color_panel_destroy (GtkObject *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
|
|
|
|
2001-11-28 07:26:25 +08:00
|
|
|
GTK_OBJECT_CLASS (parent_class)->destroy (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_color_panel_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *bevent)
|
|
|
|
{
|
|
|
|
if (bevent->button == 3)
|
|
|
|
{
|
|
|
|
GimpColorButton *color_button;
|
2002-12-04 06:16:56 +08:00
|
|
|
GimpColorPanel *color_panel;
|
2003-11-12 01:55:45 +08:00
|
|
|
GtkItemFactory *item_factory;
|
2002-12-04 06:16:56 +08:00
|
|
|
GimpRGB black, white;
|
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);
|
2003-11-12 01:55:45 +08:00
|
|
|
item_factory = GTK_ITEM_FACTORY (color_button->popup_menu);
|
2002-12-04 06:16:56 +08:00
|
|
|
|
2003-11-12 01:55:45 +08:00
|
|
|
gimp_item_factory_set_visible (item_factory,
|
2004-06-24 06:44:04 +08:00
|
|
|
"/Foreground color",
|
2002-12-04 06:16:56 +08:00
|
|
|
color_panel->context != NULL);
|
2003-11-12 01:55:45 +08:00
|
|
|
gimp_item_factory_set_visible (item_factory,
|
2004-06-24 06:44:04 +08:00
|
|
|
"/Background color",
|
2002-12-04 06:16:56 +08:00
|
|
|
color_panel->context != NULL);
|
2003-11-12 01:55:45 +08:00
|
|
|
gimp_item_factory_set_visible (item_factory,
|
2002-12-04 06:16:56 +08:00
|
|
|
"/fg-bg-separator",
|
|
|
|
color_panel->context != NULL);
|
|
|
|
|
|
|
|
if (color_panel->context)
|
|
|
|
{
|
|
|
|
GimpRGB fg, bg;
|
|
|
|
|
|
|
|
gimp_context_get_foreground (color_panel->context, &fg);
|
|
|
|
gimp_context_get_background (color_panel->context, &bg);
|
|
|
|
|
2003-11-12 01:55:45 +08:00
|
|
|
gimp_item_factory_set_color (item_factory,
|
2004-06-24 06:44:04 +08:00
|
|
|
"/Foreground color", &fg, FALSE);
|
2003-11-12 01:55:45 +08:00
|
|
|
gimp_item_factory_set_color (item_factory,
|
2004-06-24 06:44:04 +08:00
|
|
|
"/Background color", &bg, FALSE);
|
2002-12-04 06:16:56 +08:00
|
|
|
}
|
2001-11-28 07:26:25 +08:00
|
|
|
|
2002-03-04 01:38:12 +08:00
|
|
|
gimp_rgba_set (&black, 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE);
|
|
|
|
gimp_rgba_set (&white, 1.0, 1.0, 1.0, GIMP_OPACITY_OPAQUE);
|
2001-11-28 07:26:25 +08:00
|
|
|
|
2003-11-12 01:55:45 +08:00
|
|
|
gimp_item_factory_set_color (item_factory,
|
2001-11-28 07:26:25 +08:00
|
|
|
"/Black", &black, FALSE);
|
2003-11-12 01:55:45 +08:00
|
|
|
gimp_item_factory_set_color (item_factory,
|
2001-11-28 07:26:25 +08:00
|
|
|
"/White", &white, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2001-01-15 14:24:24 +08:00
|
|
|
GtkWidget *
|
2001-01-21 21:41:07 +08:00
|
|
|
gimp_color_panel_new (const gchar *title,
|
|
|
|
const GimpRGB *color,
|
2001-01-15 14:24:24 +08:00
|
|
|
GimpColorAreaType type,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-15 14:24:24 +08:00
|
|
|
GimpColorPanel *panel;
|
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);
|
2001-01-15 09:48:53 +08:00
|
|
|
|
2001-08-10 22:41:39 +08:00
|
|
|
panel = g_object_new (GIMP_TYPE_COLOR_PANEL, NULL);
|
2001-01-21 21:41:07 +08:00
|
|
|
|
|
|
|
GIMP_COLOR_BUTTON (panel)->title = g_strdup (title);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-15 14:24:24 +08:00
|
|
|
gimp_color_button_set_type (GIMP_COLOR_BUTTON (panel), type);
|
|
|
|
gimp_color_button_set_color (GIMP_COLOR_BUTTON (panel), color);
|
2001-12-29 21:26:29 +08:00
|
|
|
gtk_widget_set_size_request (GTK_WIDGET (panel), width, height);
|
2001-01-21 21:41:07 +08:00
|
|
|
|
2001-01-15 14:24:24 +08:00
|
|
|
return GTK_WIDGET (panel);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2002-12-04 06:16:56 +08:00
|
|
|
void
|
|
|
|
gimp_color_panel_set_context (GimpColorPanel *panel,
|
|
|
|
GimpContext *context)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_COLOR_PANEL (panel));
|
|
|
|
g_return_if_fail (context == NULL || GIMP_IS_CONTEXT (context));
|
|
|
|
|
|
|
|
panel->context = context;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2004-09-13 23:15:23 +08:00
|
|
|
if (panel->color_dialog)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-15 14:24:24 +08:00
|
|
|
gimp_color_button_get_color (GIMP_COLOR_BUTTON (button), &color);
|
2004-09-24 04:41:40 +08:00
|
|
|
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
|
|
|
|
2001-01-15 14:24:24 +08:00
|
|
|
static void
|
|
|
|
gimp_color_panel_clicked (GtkButton *button)
|
|
|
|
{
|
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
|
|
|
|
2001-01-15 14:24:24 +08:00
|
|
|
gimp_color_button_get_color (GIMP_COLOR_BUTTON (button), &color);
|
1999-08-22 19:45:31 +08:00
|
|
|
|
2004-09-13 23:15:23 +08:00
|
|
|
if (! panel->color_dialog)
|
2001-01-15 14:24:24 +08:00
|
|
|
{
|
2004-09-13 23:15:23 +08:00
|
|
|
panel->color_dialog =
|
2004-09-24 04:41:40 +08:00
|
|
|
gimp_color_dialog_new (NULL,
|
|
|
|
GIMP_COLOR_BUTTON (button)->title,
|
|
|
|
NULL, NULL,
|
|
|
|
GTK_WIDGET (button),
|
|
|
|
NULL, NULL,
|
|
|
|
(const GimpRGB *) &color,
|
|
|
|
FALSE,
|
|
|
|
gimp_color_button_has_alpha (GIMP_COLOR_BUTTON (button)));
|
|
|
|
|
|
|
|
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);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2004-09-24 04:41:40 +08:00
|
|
|
|
|
|
|
gtk_window_present (GTK_WINDOW (panel->color_dialog));
|
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:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_COLOR_DIALOG_OK:
|
|
|
|
gimp_color_button_set_color (GIMP_COLOR_BUTTON (panel), color);
|
|
|
|
/* Fallthrough */
|
|
|
|
|
|
|
|
case GIMP_COLOR_DIALOG_CANCEL:
|
|
|
|
gtk_widget_hide (panel->color_dialog);
|
1999-08-22 19:45:31 +08:00
|
|
|
}
|
|
|
|
}
|