~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to app/tools/gimpcolorpickertool.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* The GIMP -- an image manipulation program
 
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995-2001 Spencer Kimball, Peter Mattis, and others
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify
25
25
 
26
26
#include "tools-types.h"
27
27
 
28
 
#include "core/gimp.h"
29
28
#include "core/gimpdrawable.h"
30
 
#include "core/gimpimage.h"
31
 
#include "core/gimptoolinfo.h"
32
29
 
33
30
#include "widgets/gimpcolorframe.h"
34
 
#include "widgets/gimpdialogfactory.h"
35
31
#include "widgets/gimphelp-ids.h"
36
 
#include "widgets/gimppaletteeditor.h"
37
32
#include "widgets/gimptooldialog.h"
38
 
#include "widgets/gimpviewabledialog.h"
 
33
#include "widgets/gimpwidgets-utils.h"
39
34
 
40
35
#include "display/gimpdisplay.h"
41
36
 
48
43
 
49
44
/*  local function prototypes  */
50
45
 
51
 
static void      gimp_color_picker_tool_class_init (GimpColorPickerToolClass *klass);
52
 
static void      gimp_color_picker_tool_init       (GimpColorPickerTool      *tool);
53
 
static GObject * gimp_color_picker_tool_constructor(GType              type,
54
 
                                                    guint              n_params,
55
 
                                                    GObjectConstructParam *params);
 
46
static GObject * gimp_color_picker_tool_constructor  (GType            type,
 
47
                                                      guint            n_params,
 
48
                                                      GObjectConstructParam *params);
56
49
static void      gimp_color_picker_tool_finalize     (GObject         *object);
57
50
 
58
51
static void      gimp_color_picker_tool_control      (GimpTool        *tool,
59
52
                                                      GimpToolAction   action,
60
 
                                                      GimpDisplay     *gdisp);
 
53
                                                      GimpDisplay     *display);
61
54
static void      gimp_color_picker_tool_modifier_key (GimpTool        *tool,
62
55
                                                      GdkModifierType  key,
63
56
                                                      gboolean         press,
64
57
                                                      GdkModifierType  state,
65
 
                                                      GimpDisplay     *gdisp);
 
58
                                                      GimpDisplay     *display);
66
59
static void      gimp_color_picker_tool_oper_update  (GimpTool        *tool,
67
60
                                                      GimpCoords      *coords,
68
61
                                                      GdkModifierType  state,
69
 
                                                      GimpDisplay     *gdisp);
 
62
                                                      gboolean         proximity,
 
63
                                                      GimpDisplay     *display);
70
64
 
71
65
static void      gimp_color_picker_tool_picked       (GimpColorTool   *color_tool,
72
66
                                                      GimpColorPickState  pick_state,
84
78
                                                  gint                 color_index);
85
79
 
86
80
 
87
 
static GimpColorToolClass *parent_class = NULL;
 
81
G_DEFINE_TYPE (GimpColorPickerTool, gimp_color_picker_tool,
 
82
               GIMP_TYPE_COLOR_TOOL)
 
83
 
 
84
#define parent_class gimp_color_picker_tool_parent_class
88
85
 
89
86
 
90
87
void
94
91
  (* callback) (GIMP_TYPE_COLOR_PICKER_TOOL,
95
92
                GIMP_TYPE_COLOR_PICKER_OPTIONS,
96
93
                gimp_color_picker_options_gui,
97
 
                0,
 
94
                GIMP_CONTEXT_FOREGROUND_MASK | GIMP_CONTEXT_BACKGROUND_MASK,
98
95
                "gimp-color-picker-tool",
99
96
                _("Color Picker"),
100
 
                _("Pick colors from the image"),
 
97
                _("Color Picker Tool: Set colors from image pixels"),
101
98
                N_("C_olor Picker"), "O",
102
99
                NULL, GIMP_HELP_TOOL_COLOR_PICKER,
103
100
                GIMP_STOCK_TOOL_COLOR_PICKER,
104
101
                data);
105
102
}
106
103
 
107
 
GtkType
108
 
gimp_color_picker_tool_get_type (void)
109
 
{
110
 
  static GtkType tool_type = 0;
111
 
 
112
 
  if (! tool_type)
113
 
    {
114
 
      static const GTypeInfo tool_info =
115
 
      {
116
 
        sizeof (GimpColorPickerToolClass),
117
 
        (GBaseInitFunc) NULL,
118
 
        (GBaseFinalizeFunc) NULL,
119
 
        (GClassInitFunc) gimp_color_picker_tool_class_init,
120
 
        NULL,           /* class_finalize */
121
 
        NULL,           /* class_data     */
122
 
        sizeof (GimpColorPickerTool),
123
 
        0,              /* n_preallocs    */
124
 
        (GInstanceInitFunc) gimp_color_picker_tool_init,
125
 
      };
126
 
 
127
 
      tool_type = g_type_register_static (GIMP_TYPE_COLOR_TOOL,
128
 
                                          "GimpColorPickerTool",
129
 
                                          &tool_info, 0);
130
 
    }
131
 
 
132
 
  return tool_type;
133
 
}
134
 
 
135
104
static void
136
105
gimp_color_picker_tool_class_init (GimpColorPickerToolClass *klass)
137
106
{
139
108
  GimpToolClass      *tool_class       = GIMP_TOOL_CLASS (klass);
140
109
  GimpColorToolClass *color_tool_class = GIMP_COLOR_TOOL_CLASS (klass);
141
110
 
142
 
  parent_class = g_type_class_peek_parent (klass);
143
 
 
144
111
  object_class->constructor = gimp_color_picker_tool_constructor;
145
112
  object_class->finalize    = gimp_color_picker_tool_finalize;
146
113
 
172
139
  tool = GIMP_TOOL (object);
173
140
 
174
141
  gimp_color_tool_enable (GIMP_COLOR_TOOL (object),
175
 
                          GIMP_COLOR_OPTIONS (tool->tool_info->tool_options));
 
142
                          GIMP_COLOR_TOOL_GET_OPTIONS (tool));
176
143
 
177
144
  return object;
178
145
}
183
150
  GimpColorPickerTool *picker_tool = GIMP_COLOR_PICKER_TOOL (object);
184
151
 
185
152
  if (picker_tool->dialog)
186
 
    gimp_color_picker_tool_info_response (NULL, GTK_RESPONSE_CLOSE, picker_tool);
 
153
    gimp_color_picker_tool_info_response (NULL, GTK_RESPONSE_CLOSE,
 
154
                                          picker_tool);
187
155
 
188
156
  G_OBJECT_CLASS (parent_class)->finalize (object);
189
157
}
191
159
static void
192
160
gimp_color_picker_tool_control (GimpTool       *tool,
193
161
                                GimpToolAction  action,
194
 
                                GimpDisplay    *gdisp)
 
162
                                GimpDisplay    *display)
195
163
{
196
164
  GimpColorPickerTool *picker_tool = GIMP_COLOR_PICKER_TOOL (tool);
197
165
 
198
166
  switch (action)
199
167
    {
200
 
    case HALT:
 
168
    case GIMP_TOOL_ACTION_PAUSE:
 
169
    case GIMP_TOOL_ACTION_RESUME:
 
170
      break;
 
171
 
 
172
    case GIMP_TOOL_ACTION_HALT:
201
173
      if (picker_tool->dialog)
202
174
        gimp_color_picker_tool_info_response (NULL, GTK_RESPONSE_CLOSE,
203
175
                                              picker_tool);
204
176
      break;
205
 
 
206
 
    default:
207
 
      break;
208
177
    }
209
178
 
210
 
  GIMP_TOOL_CLASS (parent_class)->control (tool, action, gdisp);
 
179
  GIMP_TOOL_CLASS (parent_class)->control (tool, action, display);
211
180
}
212
181
 
213
182
static void
215
184
                                     GdkModifierType  key,
216
185
                                     gboolean         press,
217
186
                                     GdkModifierType  state,
218
 
                                     GimpDisplay     *gdisp)
 
187
                                     GimpDisplay     *display)
219
188
{
220
 
  GimpColorPickerOptions *options;
221
 
 
222
 
  options = GIMP_COLOR_PICKER_OPTIONS (tool->tool_info->tool_options);
 
189
  GimpColorPickerOptions *options = GIMP_COLOR_PICKER_TOOL_GET_OPTIONS (tool);
223
190
 
224
191
  if (key == GDK_SHIFT_MASK)
225
192
    {
226
 
      g_object_set (options, "add-to-palette", ! options->add_to_palette,
 
193
      g_object_set (options, "use-info-window", ! options->use_info_window,
227
194
                    NULL);
228
195
    }
229
196
  else if (key == GDK_CONTROL_MASK)
230
197
    {
231
 
       switch (options->pick_mode)
 
198
      switch (options->pick_mode)
232
199
        {
233
 
        case GIMP_COLOR_PICK_MODE_NONE:
234
 
          break;
235
 
 
236
200
        case GIMP_COLOR_PICK_MODE_FOREGROUND:
237
201
          g_object_set (options, "pick-mode", GIMP_COLOR_PICK_MODE_BACKGROUND,
238
202
                        NULL);
242
206
          g_object_set (options, "pick-mode", GIMP_COLOR_PICK_MODE_FOREGROUND,
243
207
                        NULL);
244
208
          break;
 
209
 
 
210
        default:
 
211
          break;
245
212
        }
246
213
 
247
214
    }
251
218
gimp_color_picker_tool_oper_update (GimpTool        *tool,
252
219
                                    GimpCoords      *coords,
253
220
                                    GdkModifierType  state,
254
 
                                    GimpDisplay     *gdisp)
 
221
                                    gboolean         proximity,
 
222
                                    GimpDisplay     *display)
255
223
{
256
 
  GimpColorPickerOptions *options;
257
 
 
258
 
  options = GIMP_COLOR_PICKER_OPTIONS (tool->tool_info->tool_options);
 
224
  GimpColorPickerTool    *picker_tool = GIMP_COLOR_PICKER_TOOL (tool);
 
225
  GimpColorPickerOptions *options = GIMP_COLOR_PICKER_TOOL_GET_OPTIONS (tool);
259
226
 
260
227
  GIMP_COLOR_TOOL (tool)->pick_mode = options->pick_mode;
 
228
 
 
229
  gimp_tool_pop_status (tool, display);
 
230
  if (proximity)
 
231
    {
 
232
      gchar           *status_help = NULL;
 
233
      GdkModifierType  shift_mod = 0;
 
234
 
 
235
      if (! picker_tool->dialog)
 
236
        {
 
237
          shift_mod = GDK_SHIFT_MASK;
 
238
        }
 
239
      switch (options->pick_mode)
 
240
        {
 
241
        case GIMP_COLOR_PICK_MODE_NONE:
 
242
          status_help = gimp_suggest_modifiers (_("Click in any image to view"
 
243
                                                  " its color"),
 
244
                                                shift_mod & ~state,
 
245
                                                NULL, NULL, NULL);
 
246
          break;
 
247
 
 
248
        case GIMP_COLOR_PICK_MODE_FOREGROUND:
 
249
          status_help = gimp_suggest_modifiers (_("Click in any image to pick"
 
250
                                                  " the foreground color"),
 
251
                                                (shift_mod
 
252
                                                 | GDK_CONTROL_MASK) & ~state,
 
253
                                                NULL, NULL, NULL);
 
254
          break;
 
255
 
 
256
        case GIMP_COLOR_PICK_MODE_BACKGROUND:
 
257
          status_help = gimp_suggest_modifiers (_("Click in any image to pick"
 
258
                                                  " the background color"),
 
259
                                                (shift_mod
 
260
                                                 | GDK_CONTROL_MASK) & ~state,
 
261
                                                NULL, NULL, NULL);
 
262
          break;
 
263
 
 
264
        case GIMP_COLOR_PICK_MODE_PALETTE:
 
265
          status_help = gimp_suggest_modifiers (_("Click in any image to add"
 
266
                                                  " the color to the palette"),
 
267
                                                shift_mod & ~state,
 
268
                                                NULL, NULL, NULL);
 
269
          break;
 
270
        }
 
271
      if (status_help != NULL)
 
272
        {
 
273
          gimp_tool_push_status (tool, display, status_help);
 
274
          g_free (status_help);
 
275
        }
 
276
    }
 
277
 
 
278
  GIMP_TOOL_CLASS (parent_class)->oper_update (tool, coords, state, proximity,
 
279
                                               display);
261
280
}
262
281
 
263
282
static void
267
286
                               GimpRGB            *color,
268
287
                               gint                color_index)
269
288
{
270
 
  GimpTool               *tool        = GIMP_TOOL (color_tool);
271
289
  GimpColorPickerTool    *picker_tool = GIMP_COLOR_PICKER_TOOL (color_tool);
272
290
  GimpColorPickerOptions *options;
273
 
  GimpContext            *user_context;
274
 
 
275
 
  options = GIMP_COLOR_PICKER_OPTIONS (color_tool->options);
276
 
 
277
 
  if (! picker_tool->dialog)
 
291
 
 
292
  options = GIMP_COLOR_PICKER_TOOL_GET_OPTIONS (color_tool);
 
293
 
 
294
  if (options->use_info_window && ! picker_tool->dialog)
278
295
    gimp_color_picker_tool_info_create (picker_tool);
279
296
 
280
 
  gimp_color_picker_tool_info_update (picker_tool, sample_type,
281
 
                                      color, color_index);
282
 
 
283
 
  user_context = gimp_get_user_context (tool->gdisp->gimage->gimp);
284
 
 
285
 
  if (options->add_to_palette)
286
 
    {
287
 
      GimpDialogFactory *dialog_factory;
288
 
      GdkScreen         *screen;
289
 
      GtkWidget         *dockable;
290
 
      GtkWidget         *palette_editor;
291
 
      GimpData          *data;
292
 
 
293
 
      dialog_factory = gimp_dialog_factory_from_name ("dock");
294
 
      screen         = gtk_widget_get_screen (tool->gdisp->shell);
295
 
 
296
 
      dockable = gimp_dialog_factory_dialog_raise (dialog_factory,
297
 
                                                   screen,
298
 
                                                   "gimp-palette-editor",
299
 
                                                   -1);
300
 
 
301
 
      palette_editor = gtk_bin_get_child (GTK_BIN (dockable));
302
 
 
303
 
      data = gimp_data_editor_get_data (GIMP_DATA_EDITOR (palette_editor));
304
 
 
305
 
      if (! data)
306
 
        {
307
 
          data = GIMP_DATA (gimp_context_get_palette (user_context));
308
 
 
309
 
          gimp_data_editor_set_data (GIMP_DATA_EDITOR (palette_editor), data);
310
 
        }
311
 
 
312
 
      gimp_palette_editor_pick_color (GIMP_PALETTE_EDITOR (palette_editor),
313
 
                                      color, pick_state);
314
 
    }
315
 
 
316
 
  switch (options->pick_mode)
317
 
    {
318
 
    case GIMP_COLOR_PICK_MODE_NONE:
319
 
      break;
320
 
 
321
 
    case GIMP_COLOR_PICK_MODE_FOREGROUND:
322
 
      gimp_context_set_foreground (user_context, color);
323
 
      break;
324
 
 
325
 
    case GIMP_COLOR_PICK_MODE_BACKGROUND:
326
 
      gimp_context_set_background (user_context, color);
327
 
      break;
328
 
    }
 
297
  if (picker_tool->dialog)
 
298
    gimp_color_picker_tool_info_update (picker_tool, sample_type,
 
299
                                        color, color_index);
 
300
 
 
301
  GIMP_COLOR_TOOL_CLASS (parent_class)->picked (color_tool, pick_state,
 
302
                                                sample_type, color,
 
303
                                                color_index);
329
304
}
330
305
 
331
306
static void
339
314
  g_return_if_fail (tool->drawable != NULL);
340
315
 
341
316
  picker_tool->dialog = gimp_tool_dialog_new (tool->tool_info,
342
 
                                              NULL /* tool->gdisp->shell */,
 
317
                                              NULL /* tool->display->shell */,
343
318
                                              _("Color Picker Information"),
344
319
 
345
320
                                              GTK_STOCK_CLOSE,
347
322
 
348
323
                                              NULL);
349
324
 
 
325
  gtk_window_set_focus_on_map (GTK_WINDOW (picker_tool->dialog), FALSE);
 
326
 
350
327
  gimp_viewable_dialog_set_viewable (GIMP_VIEWABLE_DIALOG (picker_tool->dialog),
351
 
                                     GIMP_VIEWABLE (tool->drawable));
 
328
                                     GIMP_VIEWABLE (tool->drawable),
 
329
                                     GIMP_CONTEXT (gimp_tool_get_options (tool)));
352
330
 
353
331
  g_signal_connect (picker_tool->dialog, "response",
354
332
                    G_CALLBACK (gimp_color_picker_tool_info_response),
411
389
                                    GimpRGB             *color,
412
390
                                    gint                 color_index)
413
391
{
414
 
  gimp_color_area_set_color (GIMP_COLOR_AREA (picker_tool->color_area), color);
 
392
  gimp_color_area_set_color (GIMP_COLOR_AREA (picker_tool->color_area),
 
393
                             color);
415
394
 
416
395
  gimp_color_frame_set_color (GIMP_COLOR_FRAME (picker_tool->color_frame1),
417
396
                              sample_type, color, color_index);