~ubuntu-branches/ubuntu/hoary/gimp/hoary

« back to all changes in this revision

Viewing changes to app/actions/palette-editor-commands.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2005-04-04 14:51:23 UTC
  • Revision ID: james.westby@ubuntu.com-20050404145123-9py049eeelfymur8
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* The GIMP -- an image manipulation program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
17
 */
 
18
 
 
19
#include "config.h"
 
20
 
 
21
#include <gtk/gtk.h>
 
22
 
 
23
#include "libgimpwidgets/gimpwidgets.h"
 
24
 
 
25
#include "actions-types.h"
 
26
 
 
27
#include "core/gimp.h"
 
28
#include "core/gimpcontext.h"
 
29
#include "core/gimpdatafactory.h"
 
30
#include "core/gimppalette.h"
 
31
 
 
32
#include "widgets/gimpcolordialog.h"
 
33
#include "widgets/gimpdialogfactory.h"
 
34
#include "widgets/gimppaletteeditor.h"
 
35
 
 
36
#include "palette-editor-commands.h"
 
37
 
 
38
#include "gimp-intl.h"
 
39
 
 
40
 
 
41
/*  local function prototypes  */
 
42
 
 
43
static void  palette_editor_edit_color_update (GimpColorDialog      *dialog,
 
44
                                               const GimpRGB        *color,
 
45
                                               GimpColorDialogState  state,
 
46
                                               GimpPaletteEditor    *editor);
 
47
 
 
48
 
 
49
/*  public functions  */
 
50
 
 
51
void
 
52
palette_editor_edit_color_cmd_callback (GtkAction *action,
 
53
                                        gpointer   data)
 
54
{
 
55
  GimpPaletteEditor *editor      = GIMP_PALETTE_EDITOR (data);
 
56
  GimpDataEditor    *data_editor = GIMP_DATA_EDITOR (data);
 
57
  GimpPalette       *palette;
 
58
 
 
59
  if (! (data_editor->data && data_editor->data_editable && editor->color))
 
60
    return;
 
61
 
 
62
  palette = GIMP_PALETTE (data_editor->data);
 
63
 
 
64
  if (! editor->color_dialog)
 
65
    {
 
66
      editor->color_dialog =
 
67
        gimp_color_dialog_new (GIMP_VIEWABLE (palette),
 
68
                               _("Edit Palette Color"),
 
69
                               GIMP_STOCK_PALETTE,
 
70
                               _("Edit Color Palette Entry"),
 
71
                               GTK_WIDGET (editor),
 
72
                               gimp_dialog_factory_from_name ("toplevel"),
 
73
                               "gimp-palette-editor-color-dialog",
 
74
                               (const GimpRGB *) &editor->color->color,
 
75
                               FALSE, FALSE);
 
76
 
 
77
      g_signal_connect (editor->color_dialog, "destroy",
 
78
                        G_CALLBACK (gtk_widget_destroyed),
 
79
                        &editor->color_dialog);
 
80
 
 
81
      g_signal_connect (editor->color_dialog, "update",
 
82
                        G_CALLBACK (palette_editor_edit_color_update),
 
83
                        editor);
 
84
    }
 
85
  else
 
86
    {
 
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);
 
91
    }
 
92
 
 
93
  gtk_window_present (GTK_WINDOW (editor->color_dialog));
 
94
}
 
95
 
 
96
void
 
97
palette_editor_new_color_cmd_callback (GtkAction *action,
 
98
                                       gint       value,
 
99
                                       gpointer   data)
 
100
{
 
101
  GimpPaletteEditor *editor      = GIMP_PALETTE_EDITOR (data);
 
102
  GimpDataEditor    *data_editor = GIMP_DATA_EDITOR (data);
 
103
 
 
104
  if (data_editor->data && data_editor->data_editable)
 
105
    {
 
106
      GimpPalette *palette = GIMP_PALETTE (data_editor->data);
 
107
      GimpContext *context;
 
108
      GimpRGB      color;
 
109
 
 
110
      context = gimp_get_user_context (data_editor->data_factory->gimp);
 
111
 
 
112
      if (value)
 
113
        gimp_context_get_background (context, &color);
 
114
      else
 
115
        gimp_context_get_foreground (context, &color);
 
116
 
 
117
      editor->color = gimp_palette_add_entry (palette, NULL, &color);
 
118
    }
 
119
}
 
120
 
 
121
void
 
122
palette_editor_delete_color_cmd_callback (GtkAction *action,
 
123
                                          gpointer   data)
 
124
{
 
125
  GimpPaletteEditor *editor      = GIMP_PALETTE_EDITOR (data);
 
126
  GimpDataEditor    *data_editor = GIMP_DATA_EDITOR (data);
 
127
 
 
128
  if (data_editor->data && data_editor->data_editable && editor->color)
 
129
    {
 
130
      GimpPalette *palette = GIMP_PALETTE (data_editor->data);
 
131
 
 
132
      gimp_palette_delete_entry (palette, editor->color);
 
133
    }
 
134
}
 
135
 
 
136
void
 
137
palette_editor_zoom_cmd_callback (GtkAction *action,
 
138
                                  gint       value,
 
139
                                  gpointer   data)
 
140
{
 
141
  GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
 
142
 
 
143
  gimp_palette_editor_zoom (editor, (GimpZoomType) value);
 
144
}
 
145
 
 
146
 
 
147
/*  private functions  */
 
148
 
 
149
static void
 
150
palette_editor_edit_color_update (GimpColorDialog      *dialog,
 
151
                                  const GimpRGB        *color,
 
152
                                  GimpColorDialogState  state,
 
153
                                  GimpPaletteEditor    *editor)
 
154
{
 
155
  GimpPalette *palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
 
156
 
 
157
  switch (state)
 
158
    {
 
159
    case GIMP_COLOR_DIALOG_UPDATE:
 
160
      break;
 
161
 
 
162
    case GIMP_COLOR_DIALOG_OK:
 
163
      if (editor->color)
 
164
        {
 
165
          editor->color->color = *color;
 
166
          gimp_data_dirty (GIMP_DATA (palette));
 
167
        }
 
168
      /* Fallthrough */
 
169
 
 
170
    case GIMP_COLOR_DIALOG_CANCEL:
 
171
      gtk_widget_hide (editor->color_dialog);
 
172
      break;
 
173
    }
 
174
}