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

« back to all changes in this revision

Viewing changes to app/display/gimpdisplayshell-dnd.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
22
22
 
23
23
#include <gtk/gtk.h>
24
24
 
 
25
#include "libgimpbase/gimpbase.h"
 
26
 
25
27
#include "display-types.h"
26
28
 
27
29
#include "core/gimp.h"
29
31
#include "core/gimpbuffer.h"
30
32
#include "core/gimpcontainer.h"
31
33
#include "core/gimpcontext.h"
32
 
#include "core/gimpdrawable.h"
33
34
#include "core/gimpdrawable-bucket-fill.h"
34
35
#include "core/gimpimage.h"
35
36
#include "core/gimpimage-merge.h"
36
37
#include "core/gimpimage-undo.h"
37
38
#include "core/gimplayer.h"
 
39
#include "core/gimplayermask.h"
38
40
#include "core/gimppattern.h"
39
41
#include "core/gimpprogress.h"
40
42
 
47
49
#include "vectors/gimpvectors.h"
48
50
#include "vectors/gimpvectors-import.h"
49
51
 
 
52
#include "widgets/gimpdnd.h"
 
53
 
50
54
#include "gimpdisplay.h"
51
55
#include "gimpdisplayshell.h"
52
56
#include "gimpdisplayshell-dnd.h"
64
68
#endif
65
69
 
66
70
 
 
71
/*  local function prototypes  */
 
72
 
 
73
static void   gimp_display_shell_drop_drawable  (GtkWidget       *widget,
 
74
                                                 gint             x,
 
75
                                                 gint             y,
 
76
                                                 GimpViewable    *viewable,
 
77
                                                 gpointer         data);
 
78
static void   gimp_display_shell_drop_vectors   (GtkWidget       *widget,
 
79
                                                 gint             x,
 
80
                                                 gint             y,
 
81
                                                 GimpViewable    *viewable,
 
82
                                                 gpointer         data);
 
83
static void   gimp_display_shell_drop_svg       (GtkWidget       *widget,
 
84
                                                 gint             x,
 
85
                                                 gint             y,
 
86
                                                 const guchar    *svg_data,
 
87
                                                 gsize            svg_data_length,
 
88
                                                 gpointer         data);
 
89
static void   gimp_display_shell_drop_pattern   (GtkWidget       *widget,
 
90
                                                 gint             x,
 
91
                                                 gint             y,
 
92
                                                 GimpViewable    *viewable,
 
93
                                                 gpointer         data);
 
94
static void   gimp_display_shell_drop_color     (GtkWidget       *widget,
 
95
                                                 gint             x,
 
96
                                                 gint             y,
 
97
                                                 const GimpRGB   *color,
 
98
                                                 gpointer         data);
 
99
static void   gimp_display_shell_drop_buffer    (GtkWidget       *widget,
 
100
                                                 gint             x,
 
101
                                                 gint             y,
 
102
                                                 GimpViewable    *viewable,
 
103
                                                 gpointer         data);
 
104
static void   gimp_display_shell_drop_uri_list  (GtkWidget       *widget,
 
105
                                                 gint             x,
 
106
                                                 gint             y,
 
107
                                                 GList           *uri_list,
 
108
                                                 gpointer         data);
 
109
static void   gimp_display_shell_drop_component (GtkWidget       *widget,
 
110
                                                 gint             x,
 
111
                                                 gint             y,
 
112
                                                 GimpImage       *image,
 
113
                                                 GimpChannelType  component,
 
114
                                                 gpointer         data);
 
115
static void   gimp_display_shell_drop_pixbuf    (GtkWidget       *widget,
 
116
                                                 gint             x,
 
117
                                                 gint             y,
 
118
                                                 GdkPixbuf       *pixbuf,
 
119
                                                 gpointer         data);
 
120
 
 
121
 
 
122
/*  public functions  */
 
123
 
67
124
void
 
125
gimp_display_shell_dnd_init (GimpDisplayShell *shell)
 
126
{
 
127
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
 
128
 
 
129
  gimp_dnd_uri_list_dest_add  (GTK_WIDGET (shell),
 
130
                               gimp_display_shell_drop_uri_list,
 
131
                               shell);
 
132
  gimp_dnd_viewable_dest_add  (GTK_WIDGET (shell), GIMP_TYPE_LAYER,
 
133
                               gimp_display_shell_drop_drawable,
 
134
                               shell);
 
135
  gimp_dnd_viewable_dest_add  (GTK_WIDGET (shell), GIMP_TYPE_LAYER_MASK,
 
136
                               gimp_display_shell_drop_drawable,
 
137
                               shell);
 
138
  gimp_dnd_viewable_dest_add  (GTK_WIDGET (shell), GIMP_TYPE_CHANNEL,
 
139
                               gimp_display_shell_drop_drawable,
 
140
                               shell);
 
141
  gimp_dnd_viewable_dest_add  (GTK_WIDGET (shell), GIMP_TYPE_VECTORS,
 
142
                               gimp_display_shell_drop_vectors,
 
143
                               shell);
 
144
  gimp_dnd_viewable_dest_add  (GTK_WIDGET (shell), GIMP_TYPE_PATTERN,
 
145
                               gimp_display_shell_drop_pattern,
 
146
                               shell);
 
147
  gimp_dnd_viewable_dest_add  (GTK_WIDGET (shell), GIMP_TYPE_BUFFER,
 
148
                               gimp_display_shell_drop_buffer,
 
149
                               shell);
 
150
  gimp_dnd_color_dest_add     (GTK_WIDGET (shell),
 
151
                               gimp_display_shell_drop_color,
 
152
                               shell);
 
153
  gimp_dnd_svg_dest_add       (GTK_WIDGET (shell),
 
154
                               gimp_display_shell_drop_svg,
 
155
                               shell);
 
156
  gimp_dnd_component_dest_add (GTK_WIDGET (shell),
 
157
                               gimp_display_shell_drop_component,
 
158
                               shell);
 
159
  gimp_dnd_pixbuf_dest_add    (GTK_WIDGET (shell),
 
160
                               gimp_display_shell_drop_pixbuf,
 
161
                               shell);
 
162
}
 
163
 
 
164
 
 
165
/*  private functions  */
 
166
 
 
167
static void
68
168
gimp_display_shell_drop_drawable (GtkWidget    *widget,
 
169
                                  gint          x,
 
170
                                  gint          y,
69
171
                                  GimpViewable *viewable,
70
172
                                  gpointer      data)
71
173
{
72
 
  GimpDisplayShell *shell  = GIMP_DISPLAY_SHELL (data);
73
 
  GimpImage        *gimage = shell->gdisp->gimage;
 
174
  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (data);
 
175
  GimpImage        *image = shell->display->image;
74
176
  GType             new_type;
75
177
  GimpItem         *new_item;
76
178
 
77
179
  D (g_print ("drop drawable on canvas\n"));
78
180
 
79
 
  if (gimage->gimp->busy)
 
181
  if (image->gimp->busy)
80
182
    return;
81
183
 
82
184
  if (GIMP_IS_LAYER (viewable))
84
186
  else
85
187
    new_type = GIMP_TYPE_LAYER;
86
188
 
87
 
  new_item = gimp_item_convert (GIMP_ITEM (viewable), gimage, new_type, TRUE);
 
189
  new_item = gimp_item_convert (GIMP_ITEM (viewable), image, new_type, TRUE);
88
190
 
89
191
  if (new_item)
90
192
    {
94
196
 
95
197
      new_layer = GIMP_LAYER (new_item);
96
198
 
97
 
      gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_EDIT_PASTE,
 
199
      gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_EDIT_PASTE,
98
200
                                   _("Drop New Layer"));
99
201
 
100
202
      gimp_display_shell_untransform_viewport (shell, &x, &y, &width, &height);
106
208
 
107
209
      gimp_item_translate (new_item, off_x, off_y, FALSE);
108
210
 
109
 
      gimp_image_add_layer (gimage, new_layer, -1);
110
 
 
111
 
      gimp_image_undo_group_end (gimage);
112
 
 
113
 
      gimp_image_flush (gimage);
114
 
 
115
 
      gimp_context_set_display (gimp_get_user_context (gimage->gimp),
116
 
                                shell->gdisp);
 
211
      gimp_image_add_layer (image, new_layer, -1);
 
212
 
 
213
      gimp_image_undo_group_end (image);
 
214
 
 
215
      gimp_image_flush (image);
 
216
 
 
217
      gimp_context_set_display (gimp_get_user_context (image->gimp),
 
218
                                shell->display);
117
219
    }
118
220
}
119
221
 
120
 
void
 
222
static void
121
223
gimp_display_shell_drop_vectors (GtkWidget    *widget,
 
224
                                 gint          x,
 
225
                                 gint          y,
122
226
                                 GimpViewable *viewable,
123
227
                                 gpointer      data)
124
228
{
125
 
  GimpDisplayShell *shell  = GIMP_DISPLAY_SHELL (data);
126
 
  GimpImage        *gimage = shell->gdisp->gimage;
 
229
  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (data);
 
230
  GimpImage        *image = shell->display->image;
127
231
  GimpItem         *new_item;
128
232
 
129
233
  D (g_print ("drop vectors on canvas\n"));
130
234
 
131
 
  if (gimage->gimp->busy)
 
235
  if (image->gimp->busy)
132
236
    return;
133
237
 
134
 
  new_item = gimp_item_convert (GIMP_ITEM (viewable), gimage,
 
238
  new_item = gimp_item_convert (GIMP_ITEM (viewable), image,
135
239
                                G_TYPE_FROM_INSTANCE (viewable), TRUE);
136
240
 
137
241
  if (new_item)
138
242
    {
139
243
      GimpVectors *new_vectors = GIMP_VECTORS (new_item);
140
244
 
141
 
      gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_EDIT_PASTE,
 
245
      gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_EDIT_PASTE,
142
246
                                   _("Drop New Path"));
143
247
 
144
 
      gimp_image_add_vectors (gimage, new_vectors, -1);
145
 
 
146
 
      gimp_image_undo_group_end (gimage);
147
 
 
148
 
      gimp_image_flush (gimage);
149
 
 
150
 
      gimp_context_set_display (gimp_get_user_context (gimage->gimp),
151
 
                                shell->gdisp);
 
248
      gimp_image_add_vectors (image, new_vectors, -1);
 
249
 
 
250
      gimp_image_undo_group_end (image);
 
251
 
 
252
      gimp_image_flush (image);
 
253
 
 
254
      gimp_context_set_display (gimp_get_user_context (image->gimp),
 
255
                                shell->display);
152
256
    }
153
257
}
154
258
 
155
 
void
 
259
static void
156
260
gimp_display_shell_drop_svg (GtkWidget     *widget,
 
261
                             gint           x,
 
262
                             gint           y,
157
263
                             const guchar  *svg_data,
158
264
                             gsize          svg_data_len,
159
265
                             gpointer       data)
160
266
{
161
 
  GimpDisplayShell *shell  = GIMP_DISPLAY_SHELL (data);
162
 
  GimpImage        *gimage = shell->gdisp->gimage;
 
267
  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (data);
 
268
  GimpImage        *image = shell->display->image;
163
269
  GError           *error  = NULL;
164
270
 
165
271
  D (g_print ("drop SVG on canvas\n"));
166
272
 
167
 
  if (gimage->gimp->busy)
 
273
  if (image->gimp->busy)
168
274
    return;
169
275
 
170
 
  if (! gimp_vectors_import_buffer (gimage,
 
276
  if (! gimp_vectors_import_buffer (image,
171
277
                                    (const gchar *) svg_data, svg_data_len,
172
 
                                    TRUE, TRUE, -1, &error))
 
278
                                    TRUE, TRUE, -1, NULL, &error))
173
279
    {
174
 
      g_message (error->message);
 
280
      gimp_message (image->gimp, G_OBJECT (shell->display), GIMP_MESSAGE_ERROR,
 
281
                    "%s", error->message);
175
282
      g_clear_error (&error);
176
283
    }
177
284
  else
178
285
    {
179
 
      gimp_image_flush (gimage);
 
286
      gimp_image_flush (image);
180
287
 
181
 
      gimp_context_set_display (gimp_get_user_context (gimage->gimp),
182
 
                                shell->gdisp);
 
288
      gimp_context_set_display (gimp_get_user_context (image->gimp),
 
289
                                shell->display);
183
290
    }
184
291
}
185
292
 
189
296
                                const GimpRGB      *color,
190
297
                                GimpPattern        *pattern)
191
298
{
192
 
  GimpImage    *gimage = shell->gdisp->gimage;
 
299
  GimpImage    *image = shell->display->image;
193
300
  GimpDrawable *drawable;
194
301
 
195
 
  if (gimage->gimp->busy)
 
302
  if (image->gimp->busy)
196
303
    return;
197
304
 
198
 
  drawable = gimp_image_active_drawable (gimage);
 
305
  drawable = gimp_image_active_drawable (image);
199
306
 
200
307
  if (! drawable)
201
308
    return;
215
322
                                      fill_mode,
216
323
                                      GIMP_NORMAL_MODE, GIMP_OPACITY_OPAQUE,
217
324
                                      FALSE,             /* no seed fill */
218
 
                                      FALSE, 0.0, FALSE, /* fill params  */
 
325
                                      FALSE,             /* don't fill transp */
 
326
                                      GIMP_SELECT_CRITERION_COMPOSITE,
 
327
                                      0.0, FALSE,        /* fill params  */
219
328
                                      0.0, 0.0,          /* ignored      */
220
329
                                      color, pattern);
221
330
    }
222
331
 
223
 
  gimp_image_flush (gimage);
 
332
  gimp_image_flush (image);
224
333
 
225
 
  gimp_context_set_display (gimp_get_user_context (gimage->gimp),
226
 
                            shell->gdisp);
 
334
  gimp_context_set_display (gimp_get_user_context (image->gimp),
 
335
                            shell->display);
227
336
}
228
337
 
229
 
void
 
338
static void
230
339
gimp_display_shell_drop_pattern (GtkWidget    *widget,
 
340
                                 gint          x,
 
341
                                 gint          y,
231
342
                                 GimpViewable *viewable,
232
343
                                 gpointer      data)
233
344
{
239
350
                                    NULL, GIMP_PATTERN (viewable));
240
351
}
241
352
 
242
 
void
 
353
static void
243
354
gimp_display_shell_drop_color (GtkWidget     *widget,
 
355
                               gint           x,
 
356
                               gint           y,
244
357
                               const GimpRGB *color,
245
358
                               gpointer       data)
246
359
{
251
364
                                  color, NULL);
252
365
}
253
366
 
254
 
void
 
367
static void
255
368
gimp_display_shell_drop_buffer (GtkWidget    *widget,
 
369
                                gint          drop_x,
 
370
                                gint          drop_y,
256
371
                                GimpViewable *viewable,
257
372
                                gpointer      data)
258
373
{
259
 
  GimpDisplayShell *shell  = GIMP_DISPLAY_SHELL (data);
260
 
  GimpImage        *gimage = shell->gdisp->gimage;
 
374
  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (data);
 
375
  GimpImage        *image = shell->display->image;
261
376
  GimpBuffer       *buffer;
262
377
  gint              x, y, width, height;
263
378
 
264
379
  D (g_print ("drop buffer on canvas\n"));
265
380
 
266
 
  if (gimage->gimp->busy)
 
381
  if (image->gimp->busy)
267
382
    return;
268
383
 
269
384
  buffer = GIMP_BUFFER (viewable);
272
387
 
273
388
  /* FIXME: popup a menu for selecting "Paste Into" */
274
389
 
275
 
  gimp_edit_paste (gimage, gimp_image_active_drawable (gimage),
276
 
                   buffer, FALSE,
 
390
  gimp_edit_paste (image, gimp_image_active_drawable (image),
 
391
                   buffer, FALSE,
277
392
                   x, y, width, height);
278
393
 
279
 
  gimp_image_flush (gimage);
 
394
  gimp_image_flush (image);
280
395
 
281
 
  gimp_context_set_display (gimp_get_user_context (gimage->gimp),
282
 
                            shell->gdisp);
 
396
  gimp_context_set_display (gimp_get_user_context (image->gimp),
 
397
                            shell->display);
283
398
}
284
399
 
285
 
void
 
400
static void
286
401
gimp_display_shell_drop_uri_list (GtkWidget *widget,
 
402
                                  gint       x,
 
403
                                  gint       y,
287
404
                                  GList     *uri_list,
288
405
                                  gpointer   data)
289
406
{
290
 
  GimpDisplayShell *shell  = GIMP_DISPLAY_SHELL (data);
291
 
  GimpImage        *gimage = shell->gdisp->gimage;
 
407
  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (data);
 
408
  GimpImage        *image = shell->display->image;
292
409
  GimpContext      *context;
293
410
  GList            *list;
294
411
 
295
412
  D (g_print ("drop uri list on canvas\n"));
296
413
 
297
 
  context = gimp_get_user_context (gimage->gimp);
 
414
  context = gimp_get_user_context (image->gimp);
298
415
 
299
416
  for (list = uri_list; list; list = g_list_next (list))
300
417
    {
301
418
      const gchar       *uri   = list->data;
302
 
      GimpLayer         *new_layer;
 
419
      GList             *new_layers;
303
420
      GimpPDBStatusType  status;
304
421
      GError            *error = NULL;
305
422
 
306
 
      new_layer = file_open_layer (gimage->gimp, context,
307
 
                                   GIMP_PROGRESS (shell->statusbar),
308
 
                                   gimage, uri,
309
 
                                   &status, &error);
 
423
      new_layers = file_open_layers (image->gimp, context,
 
424
                                     GIMP_PROGRESS (shell->display),
 
425
                                     image, FALSE,
 
426
                                     uri, GIMP_RUN_INTERACTIVE, NULL,
 
427
                                     &status, &error);
310
428
 
311
 
      if (new_layer)
 
429
      if (new_layers)
312
430
        {
313
 
          GimpItem *new_item = GIMP_ITEM (new_layer);
314
 
          gint      x, y;
315
 
          gint      width, height;
316
 
          gint      off_x, off_y;
 
431
          gint x, y;
 
432
          gint width, height;
317
433
 
318
434
          gimp_display_shell_untransform_viewport (shell, &x, &y,
319
435
                                                   &width, &height);
320
436
 
321
 
          gimp_item_offsets (new_item, &off_x, &off_y);
322
 
 
323
 
          off_x = x + (width  - gimp_item_width  (new_item)) / 2 - off_x;
324
 
          off_y = y + (height - gimp_item_height (new_item)) / 2 - off_y;
325
 
 
326
 
          gimp_item_translate (new_item, off_x, off_y, FALSE);
327
 
 
328
 
          gimp_image_add_layer (gimage, new_layer, -1);
329
 
        }
 
437
          gimp_image_add_layers (image, new_layers, -1,
 
438
                                 x, y, width, height,
 
439
                                 _("Drop layers"));
 
440
 
 
441
          g_list_free (new_layers);
 
442
       }
330
443
      else if (status != GIMP_PDB_CANCEL)
331
444
        {
332
 
          gchar *filename = file_utils_uri_to_utf8_filename (uri);
 
445
          gchar *filename = file_utils_uri_display_name (uri);
333
446
 
334
 
          g_message (_("Opening '%s' failed:\n\n%s"),
335
 
                     filename, error->message);
 
447
          gimp_message (image->gimp, G_OBJECT (shell->display),
 
448
                        GIMP_MESSAGE_ERROR,
 
449
                        _("Opening '%s' failed:\n\n%s"),
 
450
                        filename, error->message);
336
451
 
337
452
          g_clear_error (&error);
338
453
          g_free (filename);
339
454
        }
340
455
    }
341
456
 
342
 
  gimp_image_flush (gimage);
343
 
 
344
 
  gimp_context_set_display (context, shell->gdisp);
 
457
  gimp_image_flush (image);
 
458
 
 
459
  gimp_context_set_display (context, shell->display);
 
460
}
 
461
 
 
462
static void
 
463
gimp_display_shell_drop_component (GtkWidget       *widget,
 
464
                                   gint             x,
 
465
                                   gint             y,
 
466
                                   GimpImage       *image,
 
467
                                   GimpChannelType  component,
 
468
                                   gpointer         data)
 
469
{
 
470
  GimpDisplayShell *shell      = GIMP_DISPLAY_SHELL (data);
 
471
  GimpImage        *dest_image = shell->display->image;
 
472
  GimpChannel      *channel;
 
473
  GimpItem         *new_item;
 
474
  const gchar      *desc;
 
475
 
 
476
  D (g_print ("drop component on canvas\n"));
 
477
 
 
478
  if (dest_image->gimp->busy)
 
479
    return;
 
480
 
 
481
  channel = gimp_channel_new_from_component (image, component, NULL, NULL);
 
482
 
 
483
  new_item = gimp_item_convert (GIMP_ITEM (channel), dest_image,
 
484
                                GIMP_TYPE_LAYER, TRUE);
 
485
 
 
486
  g_object_unref (channel);
 
487
 
 
488
  if (new_item)
 
489
    {
 
490
      GimpLayer *new_layer = GIMP_LAYER (new_item);
 
491
      gint       x, y, width, height;
 
492
      gint       off_x, off_y;
 
493
 
 
494
      gimp_enum_get_value (GIMP_TYPE_CHANNEL_TYPE, component,
 
495
                           NULL, NULL, &desc, NULL);
 
496
      gimp_object_take_name (GIMP_OBJECT (new_layer),
 
497
                             g_strdup_printf (_("%s Channel Copy"), desc));
 
498
 
 
499
      gimp_image_undo_group_start (dest_image, GIMP_UNDO_GROUP_EDIT_PASTE,
 
500
                                   _("Drop New Layer"));
 
501
 
 
502
      gimp_display_shell_untransform_viewport (shell, &x, &y, &width, &height);
 
503
 
 
504
      gimp_item_offsets (new_item, &off_x, &off_y);
 
505
 
 
506
      off_x = x + (width  - gimp_item_width  (new_item)) / 2 - off_x;
 
507
      off_y = y + (height - gimp_item_height (new_item)) / 2 - off_y;
 
508
 
 
509
      gimp_item_translate (new_item, off_x, off_y, FALSE);
 
510
 
 
511
      gimp_image_add_layer (dest_image, new_layer, -1);
 
512
 
 
513
      gimp_image_undo_group_end (dest_image);
 
514
 
 
515
      gimp_image_flush (dest_image);
 
516
 
 
517
      gimp_context_set_display (gimp_get_user_context (dest_image->gimp),
 
518
                                shell->display);
 
519
    }
 
520
}
 
521
 
 
522
static void
 
523
gimp_display_shell_drop_pixbuf (GtkWidget *widget,
 
524
                                gint       x,
 
525
                                gint       y,
 
526
                                GdkPixbuf *pixbuf,
 
527
                                gpointer   data)
 
528
{
 
529
  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (data);
 
530
  GimpImage        *image = shell->display->image;
 
531
  GimpLayer        *new_layer;
 
532
 
 
533
  D (g_print ("drop pixbuf on canvas\n"));
 
534
 
 
535
  if (image->gimp->busy)
 
536
    return;
 
537
 
 
538
  new_layer =
 
539
    gimp_layer_new_from_pixbuf (pixbuf, image,
 
540
                                gimp_image_base_type_with_alpha (image),
 
541
                                _("Dropped Buffer"),
 
542
                                GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
 
543
 
 
544
  if (new_layer)
 
545
    {
 
546
      GimpItem *new_item;
 
547
      gint      x, y, width, height;
 
548
      gint      off_x, off_y;
 
549
 
 
550
      new_item = GIMP_ITEM (new_layer);
 
551
 
 
552
      gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_EDIT_PASTE,
 
553
                                   _("Drop New Layer"));
 
554
 
 
555
      gimp_display_shell_untransform_viewport (shell, &x, &y, &width, &height);
 
556
 
 
557
      gimp_item_offsets (new_item, &off_x, &off_y);
 
558
 
 
559
      off_x = x + (width  - gimp_item_width  (new_item)) / 2 - off_x;
 
560
      off_y = y + (height - gimp_item_height (new_item)) / 2 - off_y;
 
561
 
 
562
      gimp_item_translate (new_item, off_x, off_y, FALSE);
 
563
 
 
564
      gimp_image_add_layer (image, new_layer, -1);
 
565
 
 
566
      gimp_image_undo_group_end (image);
 
567
 
 
568
      gimp_image_flush (image);
 
569
 
 
570
      gimp_context_set_display (gimp_get_user_context (image->gimp),
 
571
                                shell->display);
 
572
    }
345
573
}