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

« back to all changes in this revision

Viewing changes to app/widgets/gimpselectioneditor.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 Spencer Kimball and Peter Mattis
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify
44
44
 
45
45
#include "gimpselectioneditor.h"
46
46
#include "gimpdnd.h"
 
47
#include "gimpdocked.h"
47
48
#include "gimpmenufactory.h"
48
49
#include "gimpview.h"
49
50
#include "gimpviewrenderer.h"
52
53
#include "gimp-intl.h"
53
54
 
54
55
 
55
 
static void   gimp_selection_editor_class_init (GimpSelectionEditorClass *klass);
56
 
static void   gimp_selection_editor_init       (GimpSelectionEditor      *selection_editor);
 
56
static void  gimp_selection_editor_docked_iface_init (GimpDockedInterface *iface);
57
57
 
58
58
static GObject * gimp_selection_editor_constructor (GType                type,
59
59
                                                    guint                n_params,
60
60
                                                    GObjectConstructParam *params);
61
61
 
62
62
static void   gimp_selection_editor_set_image      (GimpImageEditor     *editor,
63
 
                                                    GimpImage           *gimage);
64
 
 
65
 
static gboolean gimp_selection_preview_button_press(GtkWidget           *widget,
 
63
                                                    GimpImage           *image);
 
64
 
 
65
static void   gimp_selection_editor_set_context    (GimpDocked          *docked,
 
66
                                                    GimpContext         *context);
 
67
 
 
68
static gboolean gimp_selection_view_button_press   (GtkWidget           *widget,
66
69
                                                    GdkEventButton      *bevent,
67
70
                                                    GimpSelectionEditor *editor);
68
71
static void   gimp_selection_editor_drop_color     (GtkWidget           *widget,
 
72
                                                    gint                 x,
 
73
                                                    gint                 y,
69
74
                                                    const GimpRGB       *color,
70
75
                                                    gpointer             data);
71
76
 
72
 
static void   gimp_selection_editor_mask_changed   (GimpImage           *gimage,
 
77
static void   gimp_selection_editor_mask_changed   (GimpImage           *image,
73
78
                                                    GimpSelectionEditor *editor);
74
79
 
75
80
 
76
 
static GimpImageEditorClass *parent_class = NULL;
77
 
 
78
 
 
79
 
GType
80
 
gimp_selection_editor_get_type (void)
81
 
{
82
 
  static GType editor_type = 0;
83
 
 
84
 
  if (! editor_type)
85
 
    {
86
 
      static const GTypeInfo editor_info =
87
 
      {
88
 
        sizeof (GimpSelectionEditorClass),
89
 
        (GBaseInitFunc) NULL,
90
 
        (GBaseFinalizeFunc) NULL,
91
 
        (GClassInitFunc) gimp_selection_editor_class_init,
92
 
        NULL,           /* class_finalize */
93
 
        NULL,           /* class_data     */
94
 
        sizeof (GimpSelectionEditor),
95
 
        0,              /* n_preallocs    */
96
 
        (GInstanceInitFunc) gimp_selection_editor_init,
97
 
      };
98
 
 
99
 
      editor_type = g_type_register_static (GIMP_TYPE_IMAGE_EDITOR,
100
 
                                            "GimpSelectionEditor",
101
 
                                            &editor_info, 0);
102
 
    }
103
 
 
104
 
  return editor_type;
105
 
}
 
81
G_DEFINE_TYPE_WITH_CODE (GimpSelectionEditor, gimp_selection_editor,
 
82
                         GIMP_TYPE_IMAGE_EDITOR,
 
83
                         G_IMPLEMENT_INTERFACE (GIMP_TYPE_DOCKED,
 
84
                                                gimp_selection_editor_docked_iface_init))
 
85
 
 
86
#define parent_class gimp_selection_editor_parent_class
 
87
 
 
88
static GimpDockedInterface *parent_docked_iface = NULL;
 
89
 
106
90
 
107
91
static void
108
 
gimp_selection_editor_class_init (GimpSelectionEditorClass* klass)
 
92
gimp_selection_editor_class_init (GimpSelectionEditorClass *klass)
109
93
{
110
94
  GObjectClass         *object_class       = G_OBJECT_CLASS (klass);
111
95
  GimpImageEditorClass *image_editor_class = GIMP_IMAGE_EDITOR_CLASS (klass);
112
96
 
113
 
  parent_class = g_type_class_peek_parent (klass);
114
 
 
115
97
  object_class->constructor     = gimp_selection_editor_constructor;
116
98
 
117
99
  image_editor_class->set_image = gimp_selection_editor_set_image;
118
100
}
119
101
 
120
102
static void
 
103
gimp_selection_editor_docked_iface_init (GimpDockedInterface *iface)
 
104
{
 
105
  parent_docked_iface = g_type_interface_peek_parent (iface);
 
106
 
 
107
  if (! parent_docked_iface)
 
108
    parent_docked_iface = g_type_default_interface_peek (GIMP_TYPE_DOCKED);
 
109
 
 
110
  iface->set_context = gimp_selection_editor_set_context;
 
111
}
 
112
 
 
113
static void
121
114
gimp_selection_editor_init (GimpSelectionEditor *editor)
122
115
{
123
116
  GtkWidget *frame;
127
120
  gtk_box_pack_start (GTK_BOX (editor), frame, TRUE, TRUE, 0);
128
121
  gtk_widget_show (frame);
129
122
 
130
 
  editor->preview = gimp_view_new_by_types (GIMP_TYPE_VIEW,
131
 
                                            GIMP_TYPE_SELECTION,
132
 
                                            GIMP_VIEW_SIZE_HUGE,
133
 
                                            0, TRUE);
134
 
  gimp_view_renderer_set_background (GIMP_VIEW (editor->preview)->renderer,
 
123
  editor->view = gimp_view_new_by_types (NULL,
 
124
                                         GIMP_TYPE_VIEW,
 
125
                                         GIMP_TYPE_SELECTION,
 
126
                                         GIMP_VIEW_SIZE_HUGE,
 
127
                                         0, TRUE);
 
128
  gimp_view_renderer_set_background (GIMP_VIEW (editor->view)->renderer,
135
129
                                     GIMP_STOCK_TEXTURE);
136
 
  gtk_widget_set_size_request (editor->preview,
 
130
  gtk_widget_set_size_request (editor->view,
137
131
                               GIMP_VIEW_SIZE_HUGE, GIMP_VIEW_SIZE_HUGE);
138
 
  gimp_view_set_expand (GIMP_VIEW (editor->preview), TRUE);
139
 
  gtk_container_add (GTK_CONTAINER (frame), editor->preview);
140
 
  gtk_widget_show (editor->preview);
 
132
  gimp_view_set_expand (GIMP_VIEW (editor->view), TRUE);
 
133
  gtk_container_add (GTK_CONTAINER (frame), editor->view);
 
134
  gtk_widget_show (editor->view);
141
135
 
142
 
  g_signal_connect (editor->preview, "button_press_event",
143
 
                    G_CALLBACK (gimp_selection_preview_button_press),
 
136
  g_signal_connect (editor->view, "button-press-event",
 
137
                    G_CALLBACK (gimp_selection_view_button_press),
144
138
                    editor);
145
139
 
146
 
  gimp_dnd_color_dest_add (editor->preview,
 
140
  gimp_dnd_color_dest_add (editor->view,
147
141
                           gimp_selection_editor_drop_color,
148
142
                           editor);
149
143
 
197
191
 
198
192
static void
199
193
gimp_selection_editor_set_image (GimpImageEditor *image_editor,
200
 
                                 GimpImage       *gimage)
 
194
                                 GimpImage       *image)
201
195
{
202
196
  GimpSelectionEditor *editor = GIMP_SELECTION_EDITOR (image_editor);
203
197
 
204
 
  if (image_editor->gimage)
 
198
  if (image_editor->image)
205
199
    {
206
 
      g_signal_handlers_disconnect_by_func (image_editor->gimage,
 
200
      g_signal_handlers_disconnect_by_func (image_editor->image,
207
201
                                            gimp_selection_editor_mask_changed,
208
202
                                            editor);
209
203
    }
210
204
 
211
 
  GIMP_IMAGE_EDITOR_CLASS (parent_class)->set_image (image_editor, gimage);
 
205
  GIMP_IMAGE_EDITOR_CLASS (parent_class)->set_image (image_editor, image);
212
206
 
213
 
  if (gimage)
 
207
  if (image)
214
208
    {
215
 
      g_signal_connect (gimage, "mask_changed",
 
209
      g_signal_connect (image, "mask-changed",
216
210
                        G_CALLBACK (gimp_selection_editor_mask_changed),
217
211
                        editor);
218
212
 
219
 
      gimp_view_set_viewable (GIMP_VIEW (editor->preview),
220
 
                              GIMP_VIEWABLE (gimp_image_get_mask (gimage)));
 
213
      gimp_view_set_viewable (GIMP_VIEW (editor->view),
 
214
                              GIMP_VIEWABLE (gimp_image_get_mask (image)));
221
215
    }
222
216
  else
223
217
    {
224
 
      gimp_view_set_viewable (GIMP_VIEW (editor->preview), NULL);
 
218
      gimp_view_set_viewable (GIMP_VIEW (editor->view), NULL);
225
219
    }
226
220
}
227
221
 
 
222
static void
 
223
gimp_selection_editor_set_context (GimpDocked  *docked,
 
224
                                   GimpContext *context)
 
225
{
 
226
  GimpSelectionEditor *editor = GIMP_SELECTION_EDITOR (docked);
 
227
 
 
228
  parent_docked_iface->set_context (docked, context);
 
229
 
 
230
  gimp_view_renderer_set_context (GIMP_VIEW (editor->view)->renderer,
 
231
                                  context);
 
232
}
 
233
 
228
234
 
229
235
/*  public functions  */
230
236
 
235
241
 
236
242
  return g_object_new (GIMP_TYPE_SELECTION_EDITOR,
237
243
                       "menu-factory",    menu_factory,
238
 
                       "menu-identifier", "<SelectionEditor>",
239
 
                       "ui-path",         "/selection-editor-popup",
 
244
                       "menu-identifier", "<Selection>",
 
245
                       "ui-path",         "/selection-popup",
240
246
                       NULL);
241
247
}
242
248
 
243
249
static gboolean
244
 
gimp_selection_preview_button_press (GtkWidget           *widget,
245
 
                                     GdkEventButton      *bevent,
246
 
                                     GimpSelectionEditor *editor)
 
250
gimp_selection_view_button_press (GtkWidget           *widget,
 
251
                                  GdkEventButton      *bevent,
 
252
                                  GimpSelectionEditor *editor)
247
253
{
248
254
  GimpImageEditor      *image_editor = GIMP_IMAGE_EDITOR (editor);
249
255
  GimpViewRenderer     *renderer;
250
256
  GimpToolInfo         *tool_info;
251
257
  GimpSelectionOptions *options;
252
258
  GimpDrawable         *drawable;
253
 
  SelectOps             operation = SELECTION_REPLACE;
 
259
  GimpChannelOps        operation = GIMP_CHANNEL_OP_REPLACE;
254
260
  gint                  x, y;
255
261
  GimpRGB               color;
256
262
 
257
 
  if (! image_editor->gimage)
 
263
  if (! image_editor->image)
258
264
    return TRUE;
259
265
 
260
 
  renderer = GIMP_VIEW (editor->preview)->renderer;
 
266
  renderer = GIMP_VIEW (editor->view)->renderer;
261
267
 
262
 
  tool_info = (GimpToolInfo *)
263
 
    gimp_container_get_child_by_name (image_editor->gimage->gimp->tool_info_list,
264
 
                                      "gimp-by-color-select-tool");
 
268
  tool_info = gimp_get_tool_info (image_editor->image->gimp,
 
269
                                  "gimp-by-color-select-tool");
265
270
 
266
271
  if (! tool_info)
267
272
    return TRUE;
268
273
 
269
274
  options = GIMP_SELECTION_OPTIONS (tool_info->tool_options);
270
275
 
271
 
  drawable = gimp_image_active_drawable (image_editor->gimage);
 
276
  drawable = gimp_image_active_drawable (image_editor->image);
272
277
 
273
278
  if (! drawable)
274
279
    return TRUE;
277
282
    {
278
283
      if (bevent->state & GDK_CONTROL_MASK)
279
284
        {
280
 
          operation = SELECTION_INTERSECT;
 
285
          operation = GIMP_CHANNEL_OP_INTERSECT;
281
286
        }
282
287
      else
283
288
        {
284
 
          operation = SELECTION_ADD;
 
289
          operation = GIMP_CHANNEL_OP_ADD;
285
290
        }
286
291
    }
287
292
  else if (bevent->state & GDK_CONTROL_MASK)
288
293
    {
289
 
      operation = SELECTION_SUBTRACT;
 
294
      operation = GIMP_CHANNEL_OP_SUBTRACT;
290
295
    }
291
296
 
292
 
  x = image_editor->gimage->width  * bevent->x / renderer->width;
293
 
  y = image_editor->gimage->height * bevent->y / renderer->height;
 
297
  x = image_editor->image->width  * bevent->x / renderer->width;
 
298
  y = image_editor->image->height * bevent->y / renderer->height;
294
299
 
295
 
  if (gimp_image_pick_color (image_editor->gimage, drawable, x, y,
 
300
  if (gimp_image_pick_color (image_editor->image, drawable, x, y,
296
301
                             options->sample_merged,
297
302
                             FALSE, 0.0,
298
303
                             NULL,
299
304
                             &color, NULL))
300
305
    {
301
 
      gimp_channel_select_by_color (gimp_image_get_mask (image_editor->gimage),
 
306
      gimp_channel_select_by_color (gimp_image_get_mask (image_editor->image),
302
307
                                    drawable,
303
308
                                    options->sample_merged,
304
309
                                    &color,
305
310
                                    options->threshold,
306
311
                                    options->select_transparent,
 
312
                                    options->select_criterion,
307
313
                                    operation,
308
314
                                    options->antialias,
309
315
                                    options->feather,
310
316
                                    options->feather_radius,
311
317
                                    options->feather_radius);
312
 
      gimp_image_flush (image_editor->gimage);
 
318
      gimp_image_flush (image_editor->image);
313
319
    }
314
320
 
315
321
  return TRUE;
317
323
 
318
324
static void
319
325
gimp_selection_editor_drop_color (GtkWidget     *widget,
 
326
                                  gint           x,
 
327
                                  gint           y,
320
328
                                  const GimpRGB *color,
321
329
                                  gpointer       data)
322
330
{
325
333
  GimpSelectionOptions *options;
326
334
  GimpDrawable         *drawable;
327
335
 
328
 
  if (! editor->gimage)
 
336
  if (! editor->image)
329
337
    return;
330
338
 
331
 
  tool_info = (GimpToolInfo *)
332
 
    gimp_container_get_child_by_name (editor->gimage->gimp->tool_info_list,
333
 
                                      "gimp-by-color-select-tool");
334
 
 
 
339
  tool_info = gimp_get_tool_info (editor->image->gimp,
 
340
                                  "gimp-by-color-select-tool");
335
341
  if (! tool_info)
336
342
    return;
337
343
 
338
344
  options = GIMP_SELECTION_OPTIONS (tool_info->tool_options);
339
345
 
340
 
  drawable = gimp_image_active_drawable (editor->gimage);
 
346
  drawable = gimp_image_active_drawable (editor->image);
341
347
 
342
348
  if (! drawable)
343
349
    return;
344
350
 
345
 
  gimp_channel_select_by_color (gimp_image_get_mask (editor->gimage),
 
351
  gimp_channel_select_by_color (gimp_image_get_mask (editor->image),
346
352
                                drawable,
347
353
                                options->sample_merged,
348
354
                                color,
349
355
                                options->threshold,
350
356
                                options->select_transparent,
 
357
                                options->select_criterion,
351
358
                                options->operation,
352
359
                                options->antialias,
353
360
                                options->feather,
354
361
                                options->feather_radius,
355
362
                                options->feather_radius);
356
 
  gimp_image_flush (editor->gimage);
 
363
  gimp_image_flush (editor->image);
357
364
}
358
365
 
359
366
static void
360
 
gimp_selection_editor_mask_changed (GimpImage           *gimage,
 
367
gimp_selection_editor_mask_changed (GimpImage           *image,
361
368
                                    GimpSelectionEditor *editor)
362
369
{
363
 
  gimp_view_renderer_invalidate (GIMP_VIEW (editor->preview)->renderer);
 
370
  gimp_view_renderer_invalidate (GIMP_VIEW (editor->view)->renderer);
364
371
}