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
|
|
|
|
2002-05-11 07:30:09 +08:00
|
|
|
#ifdef __GNUC__
|
2002-05-03 20:45:22 +08:00
|
|
|
#warning FIXME #include "gui/gui-types.h"
|
2002-05-11 07:30:09 +08:00
|
|
|
#endif
|
2002-05-03 20:45:22 +08:00
|
|
|
#include "gui/gui-types.h"
|
|
|
|
|
2001-11-28 07:26:25 +08:00
|
|
|
#include "core/gimp.h"
|
|
|
|
#include "core/gimpcontext.h"
|
|
|
|
|
2001-04-18 05:43:29 +08:00
|
|
|
#include "gui/color-notebook.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
|
|
|
|
2001-01-15 14:24:24 +08:00
|
|
|
struct _GimpColorPanel
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-15 14:24:24 +08:00
|
|
|
GimpColorButton parent;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-12-04 06:16:56 +08:00
|
|
|
GimpContext *context;
|
|
|
|
|
2001-01-15 14:24:24 +08:00
|
|
|
ColorNotebook *color_notebook;
|
1997-11-25 06:05:25 +08:00
|
|
|
};
|
|
|
|
|
removed the gimp_busy boolean, check whether user_installation is needed
2001-07-10 Michael Natterer <mitch@gimp.org>
* app/app_procs.[ch]: removed the gimp_busy boolean, check whether
user_installation is needed here, not in user_install.c, parse
gtkrc an friends only if(!no_interface), create the Gimp object
before parsing gimp's rc files an pas it to the parse functions,
many other cleanups.
* app/appenums.h: added MessageHandlerType and StackTraceMode.
* app/appenv.h: removed MessageHandlerType, declare all global
variables from main.c (no more hidden global stuff please).
* app/errors.[ch]: added the fatal message func here (from main.c),
removed the StackTraceMode enum.
* app/gimprc.[ch]: renamed functions to gimprc_*(), pass a Gimp
pointer to some functions.
* app/gimpunit.c
* app/unitrc.h: ok, this is ugly: renamed all functions to
_gimp_unit_*() and made them public. The unit list is part
of the Gimp object now, so pass a Gimp* to all functions.
* app/libgimp_glue.[ch]: added EEKy wrappers for all gimp_unit_*()
functions which are used by widgets.
* app/main.c: cleaned up the global variables, removed the fatal
message handler, call app_init() directly, not via the
user_install stuff, misc. cleanups.
* app/user_install.[ch]: removed the check if user_installation is
needed (done by app_procs.c now).
* app/core/gimp.[ch]: added the user_unit list and the "busy"
boolean. Moved gimp_[set|unset]_busy() here. Added
gimp_initialize() which is called after unitrc and gimprc are
parsed.
* app/batch.c
* app/colormaps.c
* app/devices.c
* app/disp_callbacks.c
* app/gdisplay_ops.c
* app/gimphelp.c
* app/module_db.c
* app/nav_window.c
* app/plug_in.c
* app/core/gimpcontext.c
* app/core/gimpdatafiles.c
* app/core/gimpimage-convert.c
* app/core/gimpimage-duplicate.c
* app/core/gimpimage.c
* app/core/gimpparasite.c
* app/core/gimpparasitelist.h
* app/gui/file-open-dialog.c
* app/gui/gui.[ch]
* app/gui/info-dialog.c
* app/gui/info-window.c
* app/gui/preferences-dialog.c
* app/gui/session.c
* app/gui/tips-dialog.c
* app/gui/toolbox.c
* app/tools/gimpblendtool.c
* app/tools/gimpbucketfilltool.c
* app/tools/gimpcolorpickertool.c
* app/tools/gimpfuzzyselecttool.c
* app/tools/gimptransformtool.c
* app/tools/tool_manager.c
* app/widgets/gimpcolorpanel.c
* app/widgets/gimpcursor.c
* app/xcf/xcf-load.c
* app/xcf/xcf-save.c
* app/xcf/xcf.c
* tools/pdbgen/Makefile.am
* tools/pdbgen/app.pl
* tools/pdbgen/enums.pl
* tools/pdbgen/pdb/image.pdb
* tools/pdbgen/pdb/message.pdb
* tools/pdbgen/pdb/unit.pdb
* app/pdb/image_cmds.c
* app/pdb/message_cmds.c
* app/pdb/unit_cmds.c: changed accordingly, minor cleanups.
2001-07-11 03:16:16 +08:00
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
/* local function prototypes */
|
2001-10-17 19:33:43 +08:00
|
|
|
|
2001-11-28 07:26:25 +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
|
|
|
|
2001-11-28 07:26:25 +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);
|
|
|
|
|
|
|
|
static void gimp_color_panel_select_callback (ColorNotebook *notebook,
|
|
|
|
const GimpRGB *color,
|
|
|
|
ColorNotebookState state,
|
|
|
|
gpointer data);
|
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)
|
|
|
|
{
|
|
|
|
GtkObjectClass *object_class;
|
2001-11-28 07:26:25 +08:00
|
|
|
GtkWidgetClass *widget_class;
|
2001-01-15 14:24:24 +08:00
|
|
|
GtkButtonClass *button_class;
|
|
|
|
GimpColorButtonClass *color_button_class;
|
|
|
|
|
2001-10-17 19:33:43 +08:00
|
|
|
object_class = GTK_OBJECT_CLASS (klass);
|
2001-11-28 07:26:25 +08:00
|
|
|
widget_class = GTK_WIDGET_CLASS (klass);
|
2001-10-17 19:33:43 +08:00
|
|
|
button_class = GTK_BUTTON_CLASS (klass);
|
|
|
|
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)
|
|
|
|
{
|
2003-05-23 20:00:49 +08:00
|
|
|
panel->context = NULL;
|
|
|
|
panel->color_notebook = 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
|
|
|
|
2001-01-15 14:24:24 +08:00
|
|
|
if (panel->color_notebook)
|
2000-04-03 23:40:30 +08:00
|
|
|
{
|
2001-01-15 14:24:24 +08:00
|
|
|
color_notebook_hide (panel->color_notebook);
|
|
|
|
color_notebook_free (panel->color_notebook);
|
2001-08-01 00:55:59 +08:00
|
|
|
panel->color_notebook = 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
|
|
|
|
2003-05-23 20:00:49 +08:00
|
|
|
if (panel->color_notebook)
|
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);
|
|
|
|
color_notebook_set_color (panel->color_notebook, &color);
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2001-01-15 14:24:24 +08:00
|
|
|
if (! panel->color_notebook)
|
|
|
|
{
|
|
|
|
panel->color_notebook =
|
2003-11-11 01:55:44 +08:00
|
|
|
color_notebook_new (NULL, GIMP_COLOR_BUTTON (button)->title, NULL, NULL,
|
2003-11-08 23:32:38 +08:00
|
|
|
GTK_WIDGET (button),
|
2003-05-16 19:53:50 +08:00
|
|
|
NULL, NULL,
|
2001-01-21 21:41:07 +08:00
|
|
|
(const GimpRGB *) &color,
|
2001-01-15 14:24:24 +08:00
|
|
|
gimp_color_panel_select_callback,
|
|
|
|
panel,
|
|
|
|
FALSE,
|
|
|
|
gimp_color_button_has_alpha (GIMP_COLOR_BUTTON (button)));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-05-23 20:00:49 +08:00
|
|
|
color_notebook_show (panel->color_notebook);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-01-21 21:41:07 +08:00
|
|
|
gimp_color_panel_select_callback (ColorNotebook *notebook,
|
|
|
|
const GimpRGB *color,
|
2001-01-15 14:24:24 +08:00
|
|
|
ColorNotebookState state,
|
|
|
|
gpointer data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-02-18 21:43:50 +08:00
|
|
|
GimpColorPanel *panel = GIMP_COLOR_PANEL (data);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-15 14:24:24 +08:00
|
|
|
if (panel->color_notebook)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case COLOR_NOTEBOOK_UPDATE:
|
|
|
|
break;
|
|
|
|
case COLOR_NOTEBOOK_OK:
|
2001-01-15 14:24:24 +08:00
|
|
|
gimp_color_button_set_color (GIMP_COLOR_BUTTON (panel), color);
|
1999-08-22 19:45:31 +08:00
|
|
|
/* Fallthrough */
|
|
|
|
case COLOR_NOTEBOOK_CANCEL:
|
2001-01-15 14:24:24 +08:00
|
|
|
color_notebook_hide (panel->color_notebook);
|
1999-08-22 19:45:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|