1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
#include "libgimpwidgets/gimpwidgets.h"
25
#include "actions-types.h"
27
#include "core/gimp.h"
28
#include "core/gimpcontext.h"
29
#include "core/gimpdatafactory.h"
30
#include "core/gimppalette.h"
32
#include "widgets/gimpcolordialog.h"
33
#include "widgets/gimpdialogfactory.h"
34
#include "widgets/gimppaletteeditor.h"
36
#include "palette-editor-commands.h"
38
#include "gimp-intl.h"
41
/* local function prototypes */
43
static void palette_editor_edit_color_update (GimpColorDialog *dialog,
45
GimpColorDialogState state,
46
GimpPaletteEditor *editor);
49
/* public functions */
52
palette_editor_edit_color_cmd_callback (GtkAction *action,
55
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
56
GimpDataEditor *data_editor = GIMP_DATA_EDITOR (data);
59
if (! (data_editor->data && data_editor->data_editable && editor->color))
62
palette = GIMP_PALETTE (data_editor->data);
64
if (! editor->color_dialog)
66
editor->color_dialog =
67
gimp_color_dialog_new (GIMP_VIEWABLE (palette),
68
_("Edit Palette Color"),
70
_("Edit Color Palette Entry"),
72
gimp_dialog_factory_from_name ("toplevel"),
73
"gimp-palette-editor-color-dialog",
74
(const GimpRGB *) &editor->color->color,
77
g_signal_connect (editor->color_dialog, "destroy",
78
G_CALLBACK (gtk_widget_destroyed),
79
&editor->color_dialog);
81
g_signal_connect (editor->color_dialog, "update",
82
G_CALLBACK (palette_editor_edit_color_update),
87
gimp_viewable_dialog_set_viewable (GIMP_VIEWABLE_DIALOG (editor->color_dialog),
88
GIMP_VIEWABLE (palette));
89
gimp_color_dialog_set_color (GIMP_COLOR_DIALOG (editor->color_dialog),
90
&editor->color->color);
93
gtk_window_present (GTK_WINDOW (editor->color_dialog));
97
palette_editor_new_color_cmd_callback (GtkAction *action,
101
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
102
GimpDataEditor *data_editor = GIMP_DATA_EDITOR (data);
104
if (data_editor->data && data_editor->data_editable)
106
GimpPalette *palette = GIMP_PALETTE (data_editor->data);
107
GimpContext *context;
110
context = gimp_get_user_context (data_editor->data_factory->gimp);
113
gimp_context_get_background (context, &color);
115
gimp_context_get_foreground (context, &color);
117
editor->color = gimp_palette_add_entry (palette, NULL, &color);
122
palette_editor_delete_color_cmd_callback (GtkAction *action,
125
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
126
GimpDataEditor *data_editor = GIMP_DATA_EDITOR (data);
128
if (data_editor->data && data_editor->data_editable && editor->color)
130
GimpPalette *palette = GIMP_PALETTE (data_editor->data);
132
gimp_palette_delete_entry (palette, editor->color);
137
palette_editor_zoom_cmd_callback (GtkAction *action,
141
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
143
gimp_palette_editor_zoom (editor, (GimpZoomType) value);
147
/* private functions */
150
palette_editor_edit_color_update (GimpColorDialog *dialog,
151
const GimpRGB *color,
152
GimpColorDialogState state,
153
GimpPaletteEditor *editor)
155
GimpPalette *palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
159
case GIMP_COLOR_DIALOG_UPDATE:
162
case GIMP_COLOR_DIALOG_OK:
165
editor->color->color = *color;
166
gimp_data_dirty (GIMP_DATA (palette));
170
case GIMP_COLOR_DIALOG_CANCEL:
171
gtk_widget_hide (editor->color_dialog);