2003-11-08 23:32:38 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
2001-11-16 22:13:10 +08:00
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
1999-11-01 05:00:32 +08:00
|
|
|
*
|
2000-02-26 11:41:06 +08:00
|
|
|
* gimpcolorbutton.c
|
2001-01-11 06:49:45 +08:00
|
|
|
* Copyright (C) 1999-2001 Sven Neumann
|
1999-11-01 05:00:32 +08:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
1999-11-18 05:13:50 +08:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
1999-11-01 05:00:32 +08:00
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
2003-11-08 23:32:38 +08:00
|
|
|
*
|
|
|
|
* This library 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
|
1999-11-01 05:00:32 +08:00
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
1999-11-18 05:13:50 +08:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
1999-11-01 05:00:32 +08:00
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
1999-11-20 09:01:25 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2004-11-04 20:15:49 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2000-05-31 07:38:46 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2001-01-25 06:36:18 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
2000-12-29 23:22:01 +08:00
|
|
|
|
2001-01-25 06:36:18 +08:00
|
|
|
#include "gimpwidgetstypes.h"
|
2000-12-29 23:22:01 +08:00
|
|
|
|
2001-01-11 06:49:45 +08:00
|
|
|
#include "gimpcolorarea.h"
|
1999-11-01 05:00:32 +08:00
|
|
|
#include "gimpcolorbutton.h"
|
2003-11-12 01:55:45 +08:00
|
|
|
#include "gimpcolornotebook.h"
|
|
|
|
#include "gimpcolorselection.h"
|
|
|
|
#include "gimpdialog.h"
|
|
|
|
#include "gimphelpui.h"
|
|
|
|
#include "gimpstock.h"
|
2003-05-24 02:27:05 +08:00
|
|
|
#include "gimpwidgets-private.h"
|
2001-01-25 06:36:18 +08:00
|
|
|
|
|
|
|
#include "libgimp/libgimp-intl.h"
|
2000-01-27 09:54:52 +08:00
|
|
|
|
1999-11-16 02:37:03 +08:00
|
|
|
|
2003-11-12 01:55:45 +08:00
|
|
|
#define COLOR_SELECTION_KEY "gimp-color-selection"
|
|
|
|
#define RESPONSE_RESET 1
|
|
|
|
|
2001-12-29 21:26:29 +08:00
|
|
|
#define TODOUBLE(i) (i / 65535.0)
|
|
|
|
#define TOUINT16(d) ((guint16) (d * 65535 + 0.5))
|
|
|
|
|
|
|
|
|
2004-11-04 20:15:49 +08:00
|
|
|
#define GIMP_COLOR_BUTTON_COLOR_FG "color-button-use-foreground"
|
|
|
|
#define GIMP_COLOR_BUTTON_COLOR_BG "color-button-use-background"
|
|
|
|
#define GIMP_COLOR_BUTTON_COLOR_BLACK "color-button-use-black"
|
|
|
|
#define GIMP_COLOR_BUTTON_COLOR_WHITE "color-button-use-white"
|
|
|
|
|
2001-11-16 22:13:10 +08:00
|
|
|
|
2001-09-21 18:47:19 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
COLOR_CHANGED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2005-05-21 02:07:20 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2005-05-21 04:42:39 +08:00
|
|
|
PROP_TITLE,
|
|
|
|
PROP_COLOR,
|
|
|
|
PROP_TYPE,
|
|
|
|
PROP_UPDATE
|
2005-05-21 02:07:20 +08:00
|
|
|
};
|
|
|
|
|
2001-09-21 18:47:19 +08:00
|
|
|
|
2003-11-12 01:55:45 +08:00
|
|
|
static void gimp_color_button_class_init (GimpColorButtonClass *klass);
|
2004-11-04 20:15:49 +08:00
|
|
|
static void gimp_color_button_init (GimpColorButton *button,
|
|
|
|
GimpColorButtonClass *klass);
|
2003-11-12 01:55:45 +08:00
|
|
|
|
2005-05-21 02:07:20 +08:00
|
|
|
static void gimp_color_button_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_color_button_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_color_button_finalize (GObject *object);
|
|
|
|
|
2003-11-12 01:55:45 +08:00
|
|
|
static void gimp_color_button_destroy (GtkObject *object);
|
|
|
|
|
|
|
|
static gboolean gimp_color_button_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *bevent);
|
|
|
|
static void gimp_color_button_state_changed (GtkWidget *widget,
|
|
|
|
GtkStateType prev_state);
|
|
|
|
static void gimp_color_button_clicked (GtkButton *button);
|
2004-11-04 20:15:49 +08:00
|
|
|
static GType gimp_color_button_get_action_type (GimpColorButton *button);
|
|
|
|
|
2003-11-12 01:55:45 +08:00
|
|
|
static void gimp_color_button_dialog_response (GtkWidget *dialog,
|
|
|
|
gint response_id,
|
|
|
|
GimpColorButton *button);
|
2004-11-04 20:15:49 +08:00
|
|
|
static void gimp_color_button_use_color (GtkAction *action,
|
|
|
|
GimpColorButton *button);
|
2003-11-12 01:55:45 +08:00
|
|
|
static void gimp_color_button_area_changed (GtkWidget *color_area,
|
|
|
|
GimpColorButton *button);
|
|
|
|
static void gimp_color_button_selection_changed (GtkWidget *selection,
|
|
|
|
GimpColorButton *button);
|
|
|
|
static void gimp_color_button_help_func (const gchar *help_id,
|
|
|
|
gpointer help_data);
|
1999-11-16 02:37:03 +08:00
|
|
|
|
|
|
|
|
2005-05-21 04:42:39 +08:00
|
|
|
static const GtkActionEntry actions[] =
|
2000-11-18 08:25:42 +08:00
|
|
|
{
|
2004-11-04 20:15:49 +08:00
|
|
|
{ "color-button-popup", NULL,
|
|
|
|
"Color Button Menu", NULL, NULL,
|
|
|
|
NULL
|
|
|
|
},
|
|
|
|
|
|
|
|
{ GIMP_COLOR_BUTTON_COLOR_FG, NULL,
|
|
|
|
N_("_Foreground Color"), NULL, NULL,
|
|
|
|
G_CALLBACK (gimp_color_button_use_color)
|
|
|
|
},
|
|
|
|
{ GIMP_COLOR_BUTTON_COLOR_BG, NULL,
|
|
|
|
N_("_Background Color"), NULL, NULL,
|
|
|
|
G_CALLBACK (gimp_color_button_use_color)
|
|
|
|
},
|
|
|
|
{ GIMP_COLOR_BUTTON_COLOR_BLACK, NULL,
|
|
|
|
N_("Blac_k"), NULL, NULL,
|
|
|
|
G_CALLBACK (gimp_color_button_use_color)
|
|
|
|
},
|
|
|
|
{ GIMP_COLOR_BUTTON_COLOR_WHITE, NULL,
|
|
|
|
N_("_White"), NULL, NULL,
|
|
|
|
G_CALLBACK (gimp_color_button_use_color)
|
|
|
|
}
|
1999-11-16 02:37:03 +08:00
|
|
|
};
|
1999-11-01 05:00:32 +08:00
|
|
|
|
2001-09-21 18:47:19 +08:00
|
|
|
static guint gimp_color_button_signals[LAST_SIGNAL] = { 0 };
|
1999-11-01 05:00:32 +08:00
|
|
|
|
2001-09-21 18:47:19 +08:00
|
|
|
static GimpButtonClass * parent_class = NULL;
|
1999-11-01 05:00:32 +08:00
|
|
|
|
2000-11-18 08:25:42 +08:00
|
|
|
|
2001-09-21 18:47:19 +08:00
|
|
|
GType
|
|
|
|
gimp_color_button_get_type (void)
|
1999-11-01 05:00:32 +08:00
|
|
|
{
|
2003-01-05 23:41:23 +08:00
|
|
|
static GType button_type = 0;
|
2001-07-31 01:17:36 +08:00
|
|
|
|
2003-01-05 23:41:23 +08:00
|
|
|
if (!button_type)
|
2001-07-31 01:17:36 +08:00
|
|
|
{
|
2003-01-05 23:41:23 +08:00
|
|
|
static const GTypeInfo button_info =
|
2001-09-21 18:47:19 +08:00
|
|
|
{
|
|
|
|
sizeof (GimpColorButtonClass),
|
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_color_button_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpColorButton),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_color_button_init,
|
|
|
|
};
|
1999-11-01 05:00:32 +08:00
|
|
|
|
2003-01-05 23:41:23 +08:00
|
|
|
button_type = g_type_register_static (GIMP_TYPE_BUTTON,
|
2003-11-12 01:55:45 +08:00
|
|
|
"GimpColorButton",
|
|
|
|
&button_info, 0);
|
2001-07-31 01:17:36 +08:00
|
|
|
}
|
2003-11-08 23:32:38 +08:00
|
|
|
|
2003-01-05 23:41:23 +08:00
|
|
|
return button_type;
|
1999-11-01 05:00:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-01-15 14:24:24 +08:00
|
|
|
gimp_color_button_class_init (GimpColorButtonClass *klass)
|
1999-11-01 05:00:32 +08:00
|
|
|
{
|
2005-05-21 02:07:20 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
GtkButtonClass *button_class = GTK_BUTTON_CLASS (klass);
|
2005-05-21 04:42:39 +08:00
|
|
|
GimpRGB color;
|
2003-11-08 23:32:38 +08:00
|
|
|
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-25 05:27:11 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
1999-11-01 05:00:32 +08:00
|
|
|
|
2003-11-08 23:32:38 +08:00
|
|
|
gimp_color_button_signals[COLOR_CHANGED] =
|
2005-05-27 21:05:26 +08:00
|
|
|
g_signal_new ("color-changed",
|
2004-11-04 20:15:49 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpColorButtonClass, color_changed),
|
|
|
|
NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
2000-11-18 08:25:42 +08:00
|
|
|
|
2005-05-21 02:07:20 +08:00
|
|
|
object_class->get_property = gimp_color_button_get_property;
|
|
|
|
object_class->set_property = gimp_color_button_set_property;
|
|
|
|
object_class->finalize = gimp_color_button_finalize;
|
|
|
|
|
|
|
|
gtk_object_class->destroy = gimp_color_button_destroy;
|
1999-11-01 05:00:32 +08:00
|
|
|
|
2001-11-28 07:26:25 +08:00
|
|
|
widget_class->button_press_event = gimp_color_button_button_press;
|
|
|
|
widget_class->state_changed = gimp_color_button_state_changed;
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-25 05:27:11 +08:00
|
|
|
|
2001-11-28 07:26:25 +08:00
|
|
|
button_class->clicked = gimp_color_button_clicked;
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-25 05:27:11 +08:00
|
|
|
|
2001-11-28 07:26:25 +08:00
|
|
|
klass->color_changed = NULL;
|
2004-11-04 20:15:49 +08:00
|
|
|
klass->get_action_type = gimp_color_button_get_action_type;
|
2005-05-21 02:07:20 +08:00
|
|
|
|
2005-05-21 04:42:39 +08:00
|
|
|
gimp_rgba_set (&color, 0.0, 0.0, 0.0, 1.0);
|
|
|
|
|
2005-05-21 02:07:20 +08:00
|
|
|
/**
|
|
|
|
* GimpColorButton:title:
|
|
|
|
*
|
|
|
|
* The title to be used for the color selection dialog.
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class, PROP_TITLE,
|
|
|
|
g_param_spec_string ("title", NULL, NULL,
|
|
|
|
NULL,
|
2006-01-31 00:10:56 +08:00
|
|
|
GIMP_PARAM_READWRITE |
|
2005-05-21 02:07:20 +08:00
|
|
|
G_PARAM_CONSTRUCT_ONLY));
|
2005-05-21 04:42:39 +08:00
|
|
|
/**
|
|
|
|
* GimpColorButton:color:
|
|
|
|
*
|
|
|
|
* The color displayed in the button's color area.
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class, PROP_COLOR,
|
|
|
|
gimp_param_spec_rgb ("color", NULL, NULL,
|
2006-04-27 23:19:59 +08:00
|
|
|
TRUE, &color,
|
2006-01-31 00:10:56 +08:00
|
|
|
GIMP_PARAM_READWRITE |
|
2005-05-21 04:42:39 +08:00
|
|
|
G_PARAM_CONSTRUCT));
|
|
|
|
/**
|
|
|
|
* GimpColorButton:type:
|
|
|
|
*
|
|
|
|
* The type of the button's color area.
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class, PROP_TYPE,
|
|
|
|
g_param_spec_enum ("type", NULL, NULL,
|
|
|
|
GIMP_TYPE_COLOR_AREA_TYPE,
|
|
|
|
GIMP_COLOR_AREA_FLAT,
|
2006-01-31 00:10:56 +08:00
|
|
|
GIMP_PARAM_READWRITE |
|
2005-05-21 04:42:39 +08:00
|
|
|
G_PARAM_CONSTRUCT));
|
|
|
|
/**
|
|
|
|
* GimpColorButton:continuous-update:
|
|
|
|
*
|
|
|
|
* The update policy of the color button.
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class, PROP_UPDATE,
|
|
|
|
g_param_spec_boolean ("continuous-update",
|
|
|
|
NULL, NULL,
|
|
|
|
FALSE,
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT));
|
1999-11-01 05:00:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-11-04 20:15:49 +08:00
|
|
|
gimp_color_button_init (GimpColorButton *button,
|
|
|
|
GimpColorButtonClass *klass)
|
1999-11-01 05:00:32 +08:00
|
|
|
{
|
2004-11-04 20:15:49 +08:00
|
|
|
GtkActionGroup *group;
|
|
|
|
GtkUIManager *ui_manager;
|
|
|
|
gint i;
|
2001-01-15 14:24:24 +08:00
|
|
|
|
2005-05-21 04:42:39 +08:00
|
|
|
button->title = NULL;
|
|
|
|
button->dialog = NULL;
|
|
|
|
|
|
|
|
button->color_area = g_object_new (GIMP_TYPE_COLOR_AREA,
|
2005-06-04 20:02:36 +08:00
|
|
|
"drag-mask", GDK_BUTTON1_MASK,
|
2005-05-21 04:42:39 +08:00
|
|
|
NULL);
|
2001-01-15 14:24:24 +08:00
|
|
|
|
2005-05-27 21:05:26 +08:00
|
|
|
g_signal_connect (button->color_area, "color-changed",
|
2004-11-04 20:15:49 +08:00
|
|
|
G_CALLBACK (gimp_color_button_area_changed),
|
|
|
|
button);
|
2001-01-15 14:24:24 +08:00
|
|
|
|
2003-01-05 23:41:23 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (button), button->color_area);
|
|
|
|
gtk_widget_show (button->color_area);
|
2003-11-08 23:32:38 +08:00
|
|
|
|
2001-01-15 14:24:24 +08:00
|
|
|
/* right-click opens a popup */
|
2004-11-04 20:15:49 +08:00
|
|
|
button->popup_menu = ui_manager = gtk_ui_manager_new ();
|
|
|
|
|
|
|
|
group = gtk_action_group_new ("color-button");
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (actions); i++)
|
|
|
|
{
|
2004-11-08 02:24:12 +08:00
|
|
|
const gchar *label = gettext (actions[i].label);
|
|
|
|
const gchar *tooltip = gettext (actions[i].tooltip);
|
2004-11-04 20:15:49 +08:00
|
|
|
GtkAction *action;
|
|
|
|
|
|
|
|
action = g_object_new (klass->get_action_type (button),
|
|
|
|
"name", actions[i].name,
|
|
|
|
"label", label,
|
|
|
|
"tooltip", tooltip,
|
|
|
|
"stock-id", actions[i].stock_id,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (actions[i].callback)
|
|
|
|
g_signal_connect (action, "activate",
|
|
|
|
actions[i].callback,
|
|
|
|
button);
|
|
|
|
|
|
|
|
gtk_action_group_add_action_with_accel (group, action,
|
|
|
|
actions[i].accelerator);
|
|
|
|
|
|
|
|
g_object_unref (action);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_ui_manager_insert_action_group (ui_manager, group, -1);
|
|
|
|
g_object_unref (group);
|
|
|
|
|
|
|
|
gtk_ui_manager_add_ui_from_string
|
|
|
|
(ui_manager,
|
|
|
|
"<ui>\n"
|
|
|
|
" <popup action=\"color-button-popup\">\n"
|
|
|
|
" <menuitem action=\"" GIMP_COLOR_BUTTON_COLOR_FG "\" />\n"
|
|
|
|
" <menuitem action=\"" GIMP_COLOR_BUTTON_COLOR_BG "\" />\n"
|
|
|
|
" <separator />\n"
|
|
|
|
" <menuitem action=\"" GIMP_COLOR_BUTTON_COLOR_BLACK "\" />\n"
|
|
|
|
" <menuitem action=\"" GIMP_COLOR_BUTTON_COLOR_WHITE "\" />\n"
|
|
|
|
" </popup>\n"
|
|
|
|
"</ui>\n",
|
|
|
|
-1, NULL);
|
1999-11-01 05:00:32 +08:00
|
|
|
}
|
|
|
|
|
2001-09-21 18:47:19 +08:00
|
|
|
static void
|
2005-05-21 02:07:20 +08:00
|
|
|
gimp_color_button_finalize (GObject *object)
|
1999-11-01 05:00:32 +08:00
|
|
|
{
|
2004-07-13 22:55:16 +08:00
|
|
|
GimpColorButton *button = GIMP_COLOR_BUTTON (object);
|
1999-11-01 05:00:32 +08:00
|
|
|
|
2003-01-05 23:41:23 +08:00
|
|
|
if (button->title)
|
1999-11-01 05:00:32 +08:00
|
|
|
{
|
2003-01-05 23:41:23 +08:00
|
|
|
g_free (button->title);
|
|
|
|
button->title = NULL;
|
2001-09-21 18:47:19 +08:00
|
|
|
}
|
1999-11-01 05:00:32 +08:00
|
|
|
|
2005-05-21 02:07:20 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_color_button_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpColorButton *button = GIMP_COLOR_BUTTON (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_TITLE:
|
|
|
|
g_value_set_string (value, button->title);
|
|
|
|
break;
|
|
|
|
|
2005-05-21 04:42:39 +08:00
|
|
|
case PROP_COLOR:
|
|
|
|
g_object_get_property (G_OBJECT (button->color_area), "color", value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_TYPE:
|
|
|
|
g_object_get_property (G_OBJECT (button->color_area), "type", value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_UPDATE:
|
|
|
|
g_value_set_boolean (value, button->continuous_update);
|
|
|
|
break;
|
|
|
|
|
2005-05-21 02:07:20 +08:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_color_button_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpColorButton *button = GIMP_COLOR_BUTTON (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_TITLE:
|
|
|
|
g_free (button->title);
|
|
|
|
button->title = g_value_dup_string (value);
|
|
|
|
break;
|
|
|
|
|
2005-05-21 04:42:39 +08:00
|
|
|
case PROP_COLOR:
|
|
|
|
g_object_set_property (G_OBJECT (button->color_area), "color", value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_TYPE:
|
|
|
|
g_object_set_property (G_OBJECT (button->color_area), "type", value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_UPDATE:
|
|
|
|
gimp_color_button_set_update (button, g_value_get_boolean (value));
|
|
|
|
break;
|
|
|
|
|
2005-05-21 02:07:20 +08:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_color_button_destroy (GtkObject *object)
|
|
|
|
{
|
|
|
|
GimpColorButton *button = GIMP_COLOR_BUTTON (object);
|
|
|
|
|
2003-01-05 23:41:23 +08:00
|
|
|
if (button->dialog)
|
2001-09-21 18:47:19 +08:00
|
|
|
{
|
2003-01-05 23:41:23 +08:00
|
|
|
gtk_widget_destroy (button->dialog);
|
|
|
|
button->dialog = NULL;
|
2001-09-21 18:47:19 +08:00
|
|
|
}
|
|
|
|
|
2003-01-05 23:41:23 +08:00
|
|
|
if (button->color_area)
|
2001-09-21 18:47:19 +08:00
|
|
|
{
|
2003-01-05 23:41:23 +08:00
|
|
|
gtk_widget_destroy (button->color_area);
|
|
|
|
button->color_area = NULL;
|
1999-11-01 05:00:32 +08:00
|
|
|
}
|
2003-05-25 22:23:43 +08:00
|
|
|
|
2004-11-04 20:15:49 +08:00
|
|
|
if (button->popup_menu)
|
|
|
|
{
|
|
|
|
g_object_unref (button->popup_menu);
|
|
|
|
button->popup_menu = NULL;
|
|
|
|
}
|
|
|
|
|
2003-05-25 22:23:43 +08:00
|
|
|
GTK_OBJECT_CLASS (parent_class)->destroy (object);
|
2001-09-21 18:47:19 +08:00
|
|
|
}
|
|
|
|
|
2001-11-28 07:26:25 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_color_button_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *bevent)
|
|
|
|
{
|
2004-07-13 22:55:16 +08:00
|
|
|
GimpColorButton *button = GIMP_COLOR_BUTTON (widget);
|
2001-11-28 07:26:25 +08:00
|
|
|
|
|
|
|
if (bevent->button == 3)
|
|
|
|
{
|
2004-11-08 02:24:12 +08:00
|
|
|
GtkWidget *menu = gtk_ui_manager_get_widget (button->popup_menu,
|
|
|
|
"/color-button-popup");
|
2004-11-04 20:15:49 +08:00
|
|
|
|
|
|
|
gtk_menu_set_screen (GTK_MENU (menu), gtk_widget_get_screen (widget));
|
2003-11-08 23:32:38 +08:00
|
|
|
|
2004-11-04 20:15:49 +08:00
|
|
|
gtk_menu_popup (GTK_MENU (menu),
|
|
|
|
NULL, NULL, NULL, NULL,
|
|
|
|
bevent->button, bevent->time);
|
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;
|
|
|
|
}
|
|
|
|
|
2001-09-21 18:47:19 +08:00
|
|
|
static void
|
|
|
|
gimp_color_button_state_changed (GtkWidget *widget,
|
2004-11-04 20:15:49 +08:00
|
|
|
GtkStateType prev_state)
|
2003-11-08 23:32:38 +08:00
|
|
|
{
|
2001-09-21 18:47:19 +08:00
|
|
|
g_return_if_fail (GIMP_IS_COLOR_BUTTON (widget));
|
|
|
|
|
2001-11-28 07:26:25 +08:00
|
|
|
if (! GTK_WIDGET_IS_SENSITIVE (widget) && GIMP_COLOR_BUTTON (widget)->dialog)
|
2001-09-21 18:47:19 +08:00
|
|
|
gtk_widget_hide (GIMP_COLOR_BUTTON (widget)->dialog);
|
|
|
|
|
|
|
|
if (GTK_WIDGET_CLASS (parent_class)->state_changed)
|
2001-11-28 07:26:25 +08:00
|
|
|
GTK_WIDGET_CLASS (parent_class)->state_changed (widget, prev_state);
|
1999-11-01 05:00:32 +08:00
|
|
|
}
|
2000-02-18 07:48:13 +08:00
|
|
|
|
2004-11-04 20:15:49 +08:00
|
|
|
static void
|
|
|
|
gimp_color_button_clicked (GtkButton *button)
|
|
|
|
{
|
|
|
|
GimpColorButton *color_button = GIMP_COLOR_BUTTON (button);
|
|
|
|
|
|
|
|
if (! color_button->dialog)
|
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkWidget *selection;
|
|
|
|
GimpRGB color;
|
|
|
|
|
|
|
|
gimp_color_button_get_color (color_button, &color);
|
|
|
|
|
|
|
|
dialog = color_button->dialog =
|
|
|
|
gimp_dialog_new (color_button->title, COLOR_SELECTION_KEY,
|
2005-05-20 20:56:05 +08:00
|
|
|
gtk_widget_get_toplevel (GTK_WIDGET (button)), 0,
|
2004-11-04 20:15:49 +08:00
|
|
|
gimp_color_button_help_func, NULL,
|
|
|
|
|
|
|
|
GIMP_STOCK_RESET, RESPONSE_RESET,
|
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_OK, GTK_RESPONSE_OK,
|
|
|
|
|
|
|
|
NULL);
|
|
|
|
|
2005-09-28 02:51:44 +08:00
|
|
|
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
|
|
|
|
RESPONSE_RESET,
|
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
2005-02-10 19:00:46 +08:00
|
|
|
|
2004-11-04 20:15:49 +08:00
|
|
|
g_signal_connect (dialog, "response",
|
|
|
|
G_CALLBACK (gimp_color_button_dialog_response),
|
|
|
|
color_button);
|
|
|
|
g_signal_connect (dialog, "destroy",
|
|
|
|
G_CALLBACK (gtk_widget_destroyed),
|
|
|
|
&color_button->dialog);
|
|
|
|
|
|
|
|
selection = gimp_color_selection_new ();
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (selection), 6);
|
|
|
|
gimp_color_selection_set_show_alpha (GIMP_COLOR_SELECTION (selection),
|
|
|
|
gimp_color_button_has_alpha (color_button));
|
|
|
|
gimp_color_selection_set_color (GIMP_COLOR_SELECTION (selection), &color);
|
|
|
|
gimp_color_selection_set_old_color (GIMP_COLOR_SELECTION (selection),
|
|
|
|
&color);
|
|
|
|
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), selection);
|
|
|
|
gtk_widget_show (selection);
|
|
|
|
|
2005-05-27 21:05:26 +08:00
|
|
|
g_signal_connect (selection, "color-changed",
|
2004-11-04 20:15:49 +08:00
|
|
|
G_CALLBACK (gimp_color_button_selection_changed),
|
|
|
|
button);
|
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (color_button->dialog), COLOR_SELECTION_KEY,
|
|
|
|
selection);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_window_present (GTK_WINDOW (color_button->dialog));
|
|
|
|
}
|
|
|
|
|
|
|
|
static GType
|
|
|
|
gimp_color_button_get_action_type (GimpColorButton *button)
|
|
|
|
{
|
|
|
|
return GTK_TYPE_ACTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2001-01-11 06:49:45 +08:00
|
|
|
/**
|
|
|
|
* gimp_color_button_new:
|
|
|
|
* @title: String that will be used as title for the color_selector.
|
|
|
|
* @width: Width of the colorpreview in pixels.
|
|
|
|
* @height: Height of the colorpreview in pixels.
|
|
|
|
* @color: A pointer to a #GimpRGB color.
|
2003-11-08 23:32:38 +08:00
|
|
|
* @type:
|
|
|
|
*
|
2001-01-11 06:49:45 +08:00
|
|
|
* Creates a new #GimpColorButton widget.
|
|
|
|
*
|
|
|
|
* This returns a button with a preview showing the color.
|
|
|
|
* When the button is clicked a GtkColorSelectionDialog is opened.
|
|
|
|
* If the user changes the color the new color is written into the
|
2005-05-27 21:05:26 +08:00
|
|
|
* array that was used to pass the initial color and the "color-changed"
|
2001-01-11 06:49:45 +08:00
|
|
|
* signal is emitted.
|
2003-11-08 23:32:38 +08:00
|
|
|
*
|
2001-01-11 06:49:45 +08:00
|
|
|
* Returns: Pointer to the new #GimpColorButton widget.
|
|
|
|
**/
|
|
|
|
GtkWidget *
|
2001-01-15 14:24:24 +08:00
|
|
|
gimp_color_button_new (const gchar *title,
|
2004-11-04 20:15:49 +08:00
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
const GimpRGB *color,
|
|
|
|
GimpColorAreaType type)
|
1999-11-01 05:00:32 +08:00
|
|
|
{
|
2003-01-05 23:41:23 +08:00
|
|
|
GimpColorButton *button;
|
2003-11-08 23:32:38 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (color != NULL, NULL);
|
1999-11-01 05:00:32 +08:00
|
|
|
|
2005-05-21 02:07:20 +08:00
|
|
|
button = g_object_new (GIMP_TYPE_COLOR_BUTTON,
|
|
|
|
"title", title,
|
2005-05-21 04:42:39 +08:00
|
|
|
"type", type,
|
|
|
|
"color", color,
|
2005-05-21 02:07:20 +08:00
|
|
|
NULL);
|
2003-11-08 23:32:38 +08:00
|
|
|
|
2003-01-05 23:41:23 +08:00
|
|
|
gtk_widget_set_size_request (GTK_WIDGET (button->color_area), width, height);
|
1999-11-16 02:37:03 +08:00
|
|
|
|
2003-01-05 23:41:23 +08:00
|
|
|
return GTK_WIDGET (button);
|
1999-11-01 05:00:32 +08:00
|
|
|
}
|
|
|
|
|
2000-02-18 07:48:13 +08:00
|
|
|
/**
|
2001-01-11 06:49:45 +08:00
|
|
|
* gimp_color_button_set_color:
|
2003-01-05 23:41:23 +08:00
|
|
|
* @button: Pointer to a #GimpColorButton.
|
2001-01-11 06:49:45 +08:00
|
|
|
* @color: Pointer to the new #GimpRGB color.
|
2003-11-08 23:32:38 +08:00
|
|
|
*
|
2003-01-05 23:41:23 +08:00
|
|
|
* Sets the @button to the given @color.
|
2000-11-18 08:25:42 +08:00
|
|
|
**/
|
2003-11-08 23:32:38 +08:00
|
|
|
void
|
2003-01-05 23:41:23 +08:00
|
|
|
gimp_color_button_set_color (GimpColorButton *button,
|
2004-11-04 20:15:49 +08:00
|
|
|
const GimpRGB *color)
|
2000-02-18 07:48:13 +08:00
|
|
|
{
|
2003-01-05 23:41:23 +08:00
|
|
|
g_return_if_fail (GIMP_IS_COLOR_BUTTON (button));
|
2001-01-11 06:49:45 +08:00
|
|
|
g_return_if_fail (color != NULL);
|
|
|
|
|
2003-01-05 23:41:23 +08:00
|
|
|
gimp_color_area_set_color (GIMP_COLOR_AREA (button->color_area), color);
|
2005-05-21 04:42:39 +08:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (button), "color");
|
2000-02-18 07:48:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2001-01-11 06:49:45 +08:00
|
|
|
* gimp_color_button_get_color:
|
2003-01-05 23:41:23 +08:00
|
|
|
* @button: Pointer to a #GimpColorButton.
|
|
|
|
* @color: Pointer to a #GimpRGB struct used to return the color.
|
2003-11-08 23:32:38 +08:00
|
|
|
*
|
2003-01-05 23:41:23 +08:00
|
|
|
* Retrieves the currently set color from the @button.
|
2000-11-18 08:25:42 +08:00
|
|
|
**/
|
2001-01-11 06:49:45 +08:00
|
|
|
void
|
2003-01-05 23:41:23 +08:00
|
|
|
gimp_color_button_get_color (GimpColorButton *button,
|
2004-11-04 20:15:49 +08:00
|
|
|
GimpRGB *color)
|
2000-02-18 07:48:13 +08:00
|
|
|
{
|
2003-01-05 23:41:23 +08:00
|
|
|
g_return_if_fail (GIMP_IS_COLOR_BUTTON (button));
|
2001-01-15 14:24:24 +08:00
|
|
|
g_return_if_fail (color != NULL);
|
|
|
|
|
2003-01-05 23:41:23 +08:00
|
|
|
gimp_color_area_get_color (GIMP_COLOR_AREA (button->color_area), color);
|
2000-02-18 07:48:13 +08:00
|
|
|
}
|
|
|
|
|
2000-02-03 10:35:08 +08:00
|
|
|
/**
|
2001-01-11 06:49:45 +08:00
|
|
|
* gimp_color_button_has_alpha:
|
2003-01-05 23:41:23 +08:00
|
|
|
* @button: Pointer to a #GimpColorButton.
|
2001-05-05 04:39:29 +08:00
|
|
|
*
|
2003-01-05 23:41:23 +08:00
|
|
|
* Checks whether the @buttons shows transparency information.
|
2001-05-05 04:39:29 +08:00
|
|
|
*
|
2003-01-05 23:41:23 +08:00
|
|
|
* Returns: %TRUE if the @button shows transparency information, %FALSE
|
|
|
|
* otherwise.
|
2000-11-18 08:25:42 +08:00
|
|
|
**/
|
2001-01-11 06:49:45 +08:00
|
|
|
gboolean
|
2003-01-05 23:41:23 +08:00
|
|
|
gimp_color_button_has_alpha (GimpColorButton *button)
|
1999-11-16 02:37:03 +08:00
|
|
|
{
|
2003-01-05 23:41:23 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_COLOR_BUTTON (button), FALSE);
|
1999-11-16 02:37:03 +08:00
|
|
|
|
2003-01-05 23:41:23 +08:00
|
|
|
return gimp_color_area_has_alpha (GIMP_COLOR_AREA (button->color_area));
|
1999-11-16 02:37:03 +08:00
|
|
|
}
|
|
|
|
|
2003-01-05 23:41:23 +08:00
|
|
|
/**
|
|
|
|
* gimp_color_button_set_type:
|
|
|
|
* @button: Pointer to a #GimpColorButton.
|
|
|
|
* @type: the new #GimpColorAreaType
|
|
|
|
*
|
|
|
|
* Sets the @button to the given @type. See also gimp_color_area_set_type().
|
|
|
|
**/
|
2001-01-15 14:24:24 +08:00
|
|
|
void
|
2003-01-05 23:41:23 +08:00
|
|
|
gimp_color_button_set_type (GimpColorButton *button,
|
2004-11-04 20:15:49 +08:00
|
|
|
GimpColorAreaType type)
|
2001-01-15 14:24:24 +08:00
|
|
|
{
|
2003-01-05 23:41:23 +08:00
|
|
|
g_return_if_fail (GIMP_IS_COLOR_BUTTON (button));
|
2001-01-15 14:24:24 +08:00
|
|
|
|
2003-01-05 23:41:23 +08:00
|
|
|
gimp_color_area_set_type (GIMP_COLOR_AREA (button->color_area), type);
|
2005-05-21 04:42:39 +08:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (button), "type");
|
2001-01-15 14:24:24 +08:00
|
|
|
}
|
|
|
|
|
2003-11-12 01:55:45 +08:00
|
|
|
/**
|
|
|
|
* gimp_color_button_get_update:
|
|
|
|
* @button: A #GimpColorButton widget.
|
|
|
|
*
|
|
|
|
* Returns the color button's @continuous_update property.
|
|
|
|
*
|
|
|
|
* Return value: the @continuous_update property.
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
gimp_color_button_get_update (GimpColorButton *button)
|
1999-11-01 05:00:32 +08:00
|
|
|
{
|
2003-11-12 01:55:45 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_COLOR_BUTTON (button), FALSE);
|
1999-11-01 05:00:32 +08:00
|
|
|
|
2003-11-12 01:55:45 +08:00
|
|
|
return button->continuous_update;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_color_button_set_update:
|
|
|
|
* @button: A #GimpColorButton widget.
|
|
|
|
* @continuous: The new setting of the @continuous_update property.
|
|
|
|
*
|
2005-05-27 21:05:26 +08:00
|
|
|
* When set to #TRUE, the @button will emit the "color-changed"
|
2003-11-12 01:55:45 +08:00
|
|
|
* continuously while the color is changed in the color selection
|
|
|
|
* dialog.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_color_button_set_update (GimpColorButton *button,
|
|
|
|
gboolean continuous)
|
|
|
|
{
|
1999-11-01 05:00:32 +08:00
|
|
|
g_return_if_fail (GIMP_IS_COLOR_BUTTON (button));
|
2000-11-18 08:25:42 +08:00
|
|
|
|
2003-11-12 01:55:45 +08:00
|
|
|
if (continuous != button->continuous_update)
|
|
|
|
{
|
|
|
|
button->continuous_update = continuous ? TRUE : FALSE;
|
|
|
|
|
|
|
|
if (button->dialog)
|
|
|
|
{
|
|
|
|
GimpColorSelection *selection;
|
|
|
|
GimpRGB color;
|
|
|
|
|
|
|
|
selection = g_object_get_data (G_OBJECT (button->dialog),
|
|
|
|
COLOR_SELECTION_KEY);
|
|
|
|
|
|
|
|
if (button->continuous_update)
|
|
|
|
{
|
|
|
|
gimp_color_selection_get_color (selection, &color);
|
|
|
|
gimp_color_button_set_color (button, &color);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_color_selection_get_old_color (selection, &color);
|
|
|
|
gimp_color_button_set_color (button, &color);
|
|
|
|
}
|
|
|
|
}
|
2005-05-21 04:42:39 +08:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (button), "continuous-update");
|
2003-11-12 01:55:45 +08:00
|
|
|
}
|
|
|
|
}
|
2001-11-28 07:26:25 +08:00
|
|
|
|
1999-11-01 05:00:32 +08:00
|
|
|
|
2004-11-04 20:15:49 +08:00
|
|
|
/* private functions */
|
1999-11-01 05:00:32 +08:00
|
|
|
|
2003-11-08 23:32:38 +08:00
|
|
|
static void
|
2003-11-12 01:55:45 +08:00
|
|
|
gimp_color_button_dialog_response (GtkWidget *dialog,
|
|
|
|
gint response_id,
|
|
|
|
GimpColorButton *button)
|
1999-11-01 05:00:32 +08:00
|
|
|
{
|
2003-11-12 01:55:45 +08:00
|
|
|
GtkWidget *selection;
|
|
|
|
GimpRGB color;
|
2000-11-18 08:25:42 +08:00
|
|
|
|
2003-11-12 01:55:45 +08:00
|
|
|
selection = g_object_get_data (G_OBJECT (dialog), COLOR_SELECTION_KEY);
|
1999-11-01 05:00:32 +08:00
|
|
|
|
2003-11-12 01:55:45 +08:00
|
|
|
switch (response_id)
|
|
|
|
{
|
|
|
|
case RESPONSE_RESET:
|
|
|
|
gimp_color_selection_reset (GIMP_COLOR_SELECTION (selection));
|
|
|
|
break;
|
1999-11-01 05:00:32 +08:00
|
|
|
|
2003-11-12 01:55:45 +08:00
|
|
|
case GTK_RESPONSE_OK:
|
|
|
|
if (! button->continuous_update)
|
|
|
|
{
|
|
|
|
gimp_color_selection_get_color (GIMP_COLOR_SELECTION (selection),
|
|
|
|
&color);
|
|
|
|
gimp_color_button_set_color (button, &color);
|
|
|
|
}
|
1999-11-01 05:00:32 +08:00
|
|
|
|
2003-11-12 01:55:45 +08:00
|
|
|
gtk_widget_hide (dialog);
|
|
|
|
break;
|
1999-11-01 05:00:32 +08:00
|
|
|
|
2003-11-12 01:55:45 +08:00
|
|
|
default:
|
|
|
|
if (button->continuous_update)
|
|
|
|
{
|
|
|
|
gimp_color_selection_get_old_color (GIMP_COLOR_SELECTION (selection),
|
|
|
|
&color);
|
|
|
|
gimp_color_button_set_color (button, &color);
|
|
|
|
}
|
2000-11-18 08:25:42 +08:00
|
|
|
|
2003-11-12 01:55:45 +08:00
|
|
|
gtk_widget_hide (dialog);
|
|
|
|
break;
|
|
|
|
}
|
1999-11-01 05:00:32 +08:00
|
|
|
}
|
|
|
|
|
2003-11-08 23:32:38 +08:00
|
|
|
static void
|
2004-11-04 20:15:49 +08:00
|
|
|
gimp_color_button_use_color (GtkAction *action,
|
|
|
|
GimpColorButton *button)
|
1999-11-16 02:37:03 +08:00
|
|
|
{
|
2004-11-04 20:15:49 +08:00
|
|
|
const gchar *name;
|
|
|
|
GimpRGB color;
|
1999-11-16 02:37:03 +08:00
|
|
|
|
2004-11-04 20:15:49 +08:00
|
|
|
name = gtk_action_get_name (action);
|
|
|
|
gimp_color_button_get_color (button, &color);
|
2000-11-18 08:25:42 +08:00
|
|
|
|
2004-11-04 20:15:49 +08:00
|
|
|
if (! strcmp (name, GIMP_COLOR_BUTTON_COLOR_FG))
|
2001-11-16 22:13:10 +08:00
|
|
|
{
|
2003-05-25 22:23:43 +08:00
|
|
|
if (_gimp_get_foreground_func)
|
|
|
|
_gimp_get_foreground_func (&color);
|
2003-11-12 01:55:45 +08:00
|
|
|
else
|
|
|
|
gimp_rgba_set (&color, 0.0, 0.0, 0.0, 1.0);
|
2004-11-04 20:15:49 +08:00
|
|
|
}
|
|
|
|
else if (! strcmp (name, GIMP_COLOR_BUTTON_COLOR_BG))
|
|
|
|
{
|
2003-05-25 22:23:43 +08:00
|
|
|
if (_gimp_get_background_func)
|
|
|
|
_gimp_get_background_func (&color);
|
2003-11-12 01:55:45 +08:00
|
|
|
else
|
|
|
|
gimp_rgba_set (&color, 1.0, 1.0, 1.0, 1.0);
|
2004-11-04 20:15:49 +08:00
|
|
|
}
|
|
|
|
else if (! strcmp (name, GIMP_COLOR_BUTTON_COLOR_BLACK))
|
|
|
|
{
|
2003-11-12 01:55:45 +08:00
|
|
|
gimp_rgba_set (&color, 0.0, 0.0, 0.0, 1.0);
|
2004-11-04 20:15:49 +08:00
|
|
|
}
|
|
|
|
else if (! strcmp (name, GIMP_COLOR_BUTTON_COLOR_WHITE))
|
|
|
|
{
|
2003-11-12 01:55:45 +08:00
|
|
|
gimp_rgba_set (&color, 1.0, 1.0, 1.0, 1.0);
|
2001-11-16 22:13:10 +08:00
|
|
|
}
|
2000-11-18 08:25:42 +08:00
|
|
|
|
2004-11-04 20:15:49 +08:00
|
|
|
gimp_color_button_set_color (button, &color);
|
1999-11-16 02:37:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-11-12 01:55:45 +08:00
|
|
|
gimp_color_button_area_changed (GtkWidget *color_area,
|
|
|
|
GimpColorButton *button)
|
1999-11-16 02:37:03 +08:00
|
|
|
{
|
2003-01-05 23:41:23 +08:00
|
|
|
if (button->dialog)
|
2000-02-18 07:48:13 +08:00
|
|
|
{
|
2003-11-12 01:55:45 +08:00
|
|
|
GimpColorSelection *selection;
|
|
|
|
GimpRGB color;
|
|
|
|
|
|
|
|
selection = g_object_get_data (G_OBJECT (button->dialog),
|
|
|
|
COLOR_SELECTION_KEY);
|
2001-01-11 06:49:45 +08:00
|
|
|
|
2003-11-12 01:55:45 +08:00
|
|
|
gimp_color_button_get_color (button, &color);
|
2003-11-08 23:32:38 +08:00
|
|
|
|
2003-11-12 01:55:45 +08:00
|
|
|
g_signal_handlers_block_by_func (selection,
|
|
|
|
gimp_color_button_selection_changed,
|
|
|
|
button);
|
2001-12-29 21:26:29 +08:00
|
|
|
|
2003-11-12 01:55:45 +08:00
|
|
|
gimp_color_selection_set_color (selection, &color);
|
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (selection,
|
|
|
|
gimp_color_button_selection_changed,
|
|
|
|
button);
|
2000-02-18 07:48:13 +08:00
|
|
|
}
|
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_emit (button, gimp_color_button_signals[COLOR_CHANGED], 0);
|
1999-11-16 02:37:03 +08:00
|
|
|
}
|
|
|
|
|
2003-11-12 01:55:45 +08:00
|
|
|
static void
|
|
|
|
gimp_color_button_selection_changed (GtkWidget *selection,
|
|
|
|
GimpColorButton *button)
|
|
|
|
{
|
|
|
|
if (button->continuous_update)
|
|
|
|
{
|
|
|
|
GimpRGB color;
|
|
|
|
|
|
|
|
gimp_color_selection_get_color (GIMP_COLOR_SELECTION (selection), &color);
|
|
|
|
|
|
|
|
g_signal_handlers_block_by_func (button->color_area,
|
|
|
|
gimp_color_button_area_changed,
|
|
|
|
button);
|
|
|
|
|
|
|
|
gimp_color_area_set_color (GIMP_COLOR_AREA (button->color_area), &color);
|
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (button->color_area,
|
|
|
|
gimp_color_button_area_changed,
|
|
|
|
button);
|
|
|
|
|
|
|
|
g_signal_emit (button, gimp_color_button_signals[COLOR_CHANGED], 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_color_button_help_func (const gchar *help_id,
|
|
|
|
gpointer help_data)
|
|
|
|
{
|
|
|
|
GimpColorSelection *selection;
|
|
|
|
GimpColorNotebook *notebook;
|
|
|
|
|
|
|
|
selection = g_object_get_data (G_OBJECT (help_data), COLOR_SELECTION_KEY);
|
|
|
|
|
|
|
|
notebook = GIMP_COLOR_NOTEBOOK (selection->notebook);
|
|
|
|
|
2003-11-19 07:44:35 +08:00
|
|
|
help_id = GIMP_COLOR_SELECTOR_GET_CLASS (notebook->cur_page)->help_id;
|
2003-11-12 01:55:45 +08:00
|
|
|
|
|
|
|
gimp_standard_help_func (help_id, NULL);
|
|
|
|
}
|