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

« back to all changes in this revision

Viewing changes to app/widgets/gimpclipboard.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
24
24
 
25
25
#include "widgets-types.h"
26
26
 
27
 
#include "base/pixel-region.h"
28
 
#include "base/tile-manager.h"
29
 
 
30
27
#include "core/gimp.h"
31
28
#include "core/gimpbuffer.h"
32
 
#include "core/gimpviewable.h"
33
29
 
34
30
#include "gimpclipboard.h"
35
 
#include "gimpdnd.h"
 
31
#include "gimppixbuf.h"
36
32
#include "gimpselectiondata.h"
37
33
 
38
34
#include "gimp-intl.h"
45
41
 
46
42
struct _GimpClipboard
47
43
{
48
 
  GSList          *pixbuf_formats;
49
 
 
50
 
  GtkTargetEntry  *target_entries;
51
 
  gint             n_target_entries;
52
 
  gchar          **savers;
 
44
  GSList         *pixbuf_formats;
 
45
 
 
46
  GtkTargetEntry *target_entries;
 
47
  gint            n_target_entries;
 
48
 
 
49
  GtkTargetEntry *svg_target_entries;
 
50
  gint            n_svg_target_entries;
 
51
 
 
52
  GimpBuffer     *buffer;
 
53
  gchar          *svg;
53
54
};
54
55
 
55
56
 
56
57
static GimpClipboard * gimp_clipboard_get        (Gimp             *gimp);
 
58
static void            gimp_clipboard_clear      (GimpClipboard    *gimp_clip);
57
59
static void            gimp_clipboard_free       (GimpClipboard    *gimp_clip);
58
60
 
59
 
static void      gimp_clipboard_buffer_changed   (Gimp             *gimp);
60
 
static void      gimp_clipboard_set_buffer       (Gimp             *gimp,
61
 
                                                  GimpBuffer       *buffer);
 
61
static GdkAtom * gimp_clipboard_wait_for_targets (Gimp             *gimp,
 
62
                                                  gint             *n_targets);
 
63
static GdkAtom   gimp_clipboard_wait_for_buffer  (Gimp             *gimp);
 
64
static GdkAtom   gimp_clipboard_wait_for_svg     (Gimp             *gimp);
62
65
 
63
66
static void      gimp_clipboard_send_buffer      (GtkClipboard     *clipboard,
64
67
                                                  GtkSelectionData *selection_data,
65
68
                                                  guint             info,
66
69
                                                  Gimp             *gimp);
67
 
 
68
 
static GdkAtom * gimp_clipboard_wait_for_targets (gint             *n_targets);
69
 
static GdkAtom   gimp_clipboard_wait_for_buffer  (Gimp             *gimp);
70
 
 
71
 
static gint      gimp_clipboard_format_compare   (GdkPixbufFormat  *a,
72
 
                                                  GdkPixbufFormat  *b);
73
 
 
 
70
static void      gimp_clipboard_send_svg         (GtkClipboard     *clipboard,
 
71
                                                  GtkSelectionData *selection_data,
 
72
                                                  guint             info,
 
73
                                                  Gimp             *gimp);
 
74
 
 
75
 
 
76
/*  public functions  */
74
77
 
75
78
void
76
79
gimp_clipboard_init (Gimp *gimp)
89
92
  g_object_set_data_full (G_OBJECT (gimp), GIMP_CLIPBOARD_KEY,
90
93
                          gimp_clip, (GDestroyNotify) gimp_clipboard_free);
91
94
 
92
 
  gimp_clipboard_set_buffer (gimp, gimp->global_buffer);
93
 
 
94
 
  g_signal_connect_object (gimp, "buffer_changed",
95
 
                           G_CALLBACK (gimp_clipboard_buffer_changed),
96
 
                           NULL, 0);
97
 
 
98
 
  gimp_clip->pixbuf_formats =
99
 
    g_slist_sort (gdk_pixbuf_get_formats (),
100
 
                  (GCompareFunc) gimp_clipboard_format_compare);
 
95
  gimp_clip->pixbuf_formats = gimp_pixbuf_get_formats ();
101
96
 
102
97
  for (list = gimp_clip->pixbuf_formats; list; list = g_slist_next (list))
103
98
    {
123
118
 
124
119
      gimp_clip->target_entries = g_new0 (GtkTargetEntry,
125
120
                                          gimp_clip->n_target_entries);
126
 
      gimp_clip->savers         = g_new0 (gchar *,
127
 
                                          gimp_clip->n_target_entries + 1);
128
121
 
129
122
      for (list = gimp_clip->pixbuf_formats; list; list = g_slist_next (list))
130
123
        {
141
134
 
142
135
              for (type = mime_types; *type; type++)
143
136
                {
144
 
                  gchar *mime_type = *type;
 
137
                  const gchar *mime_type = *type;
145
138
 
146
139
                  if (gimp->be_verbose)
147
 
                    g_print ("GimpClipboard: writable pixbuf format: %s\n",
 
140
                    g_print ("clipboard: writable pixbuf format: %s\n",
148
141
                             mime_type);
149
142
 
150
143
                  gimp_clip->target_entries[i].target = g_strdup (mime_type);
151
144
                  gimp_clip->target_entries[i].flags  = 0;
152
145
                  gimp_clip->target_entries[i].info   = i;
153
146
 
154
 
                  gimp_clip->savers[i]                = g_strdup (format_name);
155
 
 
156
147
                  i++;
157
148
                }
158
149
 
161
152
            }
162
153
        }
163
154
    }
 
155
 
 
156
  gimp_clip->n_svg_target_entries = 2;
 
157
  gimp_clip->svg_target_entries   = g_new0 (GtkTargetEntry, 2);
 
158
 
 
159
  gimp_clip->svg_target_entries[0].target = g_strdup ("image/svg");
 
160
  gimp_clip->svg_target_entries[0].flags  = 0;
 
161
  gimp_clip->svg_target_entries[0].info   = 0;
 
162
 
 
163
  gimp_clip->svg_target_entries[1].target = g_strdup ("image/svg+xml");
 
164
  gimp_clip->svg_target_entries[1].flags  = 0;
 
165
  gimp_clip->svg_target_entries[1].info   = 1;
164
166
}
165
167
 
166
168
void
167
169
gimp_clipboard_exit (Gimp *gimp)
168
170
{
 
171
  GtkClipboard *clipboard;
 
172
 
169
173
  g_return_if_fail (GIMP_IS_GIMP (gimp));
170
174
 
171
 
  g_signal_handlers_disconnect_by_func (gimp,
172
 
                                        G_CALLBACK (gimp_clipboard_buffer_changed),
173
 
                                        NULL);
174
 
  gimp_clipboard_set_buffer (gimp, NULL);
 
175
  clipboard = gtk_clipboard_get_for_display (gdk_display_get_default (),
 
176
                                             GDK_SELECTION_CLIPBOARD);
 
177
 
 
178
  if (clipboard && gtk_clipboard_get_owner (clipboard) == G_OBJECT (gimp))
 
179
    gtk_clipboard_store (clipboard);
175
180
 
176
181
  g_object_set_data (G_OBJECT (gimp), GIMP_CLIPBOARD_KEY, NULL);
177
182
}
191
196
gboolean
192
197
gimp_clipboard_has_buffer (Gimp *gimp)
193
198
{
 
199
  GimpClipboard *gimp_clip;
 
200
  GtkClipboard  *clipboard;
 
201
 
194
202
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
195
203
 
196
 
  if (gimp->global_buffer)
197
 
    return TRUE;
198
 
 
199
 
  return (gimp_clipboard_wait_for_buffer (gimp) != GDK_NONE);
 
204
  clipboard = gtk_clipboard_get_for_display (gdk_display_get_default (),
 
205
                                             GDK_SELECTION_CLIPBOARD);
 
206
 
 
207
  if (clipboard                                                &&
 
208
      gtk_clipboard_get_owner (clipboard)   != G_OBJECT (gimp) &&
 
209
      gimp_clipboard_wait_for_buffer (gimp) != GDK_NONE)
 
210
    {
 
211
      return TRUE;
 
212
    }
 
213
 
 
214
  gimp_clip = gimp_clipboard_get (gimp);
 
215
 
 
216
  return (gimp_clip->buffer != NULL);
200
217
}
201
218
 
202
 
 
203
 
static TileManager *
204
 
tile_manager_new_from_pixbuf (GdkPixbuf *pixbuf)
 
219
/**
 
220
 * gimp_clipboard_has_svg:
 
221
 * @gimp: pointer to #Gimp
 
222
 *
 
223
 * Tests if there's SVG data in %GDK_SELECTION_CLIPBOARD.
 
224
 * This is done in a main-loop similar to
 
225
 * gtk_clipboard_wait_is_text_available(). The same caveats apply here.
 
226
 *
 
227
 * Return value: %TRUE if there's SVG data in the clipboard, %FALSE otherwise
 
228
 **/
 
229
gboolean
 
230
gimp_clipboard_has_svg (Gimp *gimp)
205
231
{
206
 
  TileManager *tiles;
207
 
  guchar      *pixels;
208
 
  PixelRegion  destPR;
209
 
  gint         width;
210
 
  gint         height;
211
 
  gint         rowstride;
212
 
  gint         channels;
213
 
  gint         y;
214
 
 
215
 
  g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
216
 
 
217
 
  width     = gdk_pixbuf_get_width (pixbuf);
218
 
  height    = gdk_pixbuf_get_height (pixbuf);
219
 
  rowstride = gdk_pixbuf_get_rowstride (pixbuf);
220
 
  channels  = gdk_pixbuf_get_n_channels (pixbuf);
221
 
 
222
 
  tiles = tile_manager_new (width, height, channels);
223
 
 
224
 
  pixel_region_init (&destPR, tiles, 0, 0, width, height, TRUE);
225
 
 
226
 
  for (y = 0, pixels = gdk_pixbuf_get_pixels (pixbuf);
227
 
       y < height;
228
 
       y++, pixels += rowstride)
 
232
  GimpClipboard *gimp_clip;
 
233
  GtkClipboard  *clipboard;
 
234
 
 
235
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
 
236
 
 
237
  clipboard = gtk_clipboard_get_for_display (gdk_display_get_default (),
 
238
                                             GDK_SELECTION_CLIPBOARD);
 
239
 
 
240
  if (clipboard                                              &&
 
241
      gtk_clipboard_get_owner (clipboard) != G_OBJECT (gimp) &&
 
242
      gimp_clipboard_wait_for_svg (gimp)  != GDK_NONE)
229
243
    {
230
 
      pixel_region_set_row (&destPR, 0, y, width, pixels);
231
 
   }
232
 
 
233
 
  return tiles;
 
244
      return TRUE;
 
245
    }
 
246
 
 
247
  gimp_clip = gimp_clipboard_get (gimp);
 
248
 
 
249
  return (gimp_clip->svg != NULL);
234
250
}
235
251
 
236
252
/**
249
265
GimpBuffer *
250
266
gimp_clipboard_get_buffer (Gimp *gimp)
251
267
{
252
 
  GimpBuffer   *buffer = NULL;
253
 
  GtkClipboard *clipboard;
254
 
  GdkAtom       atom;
 
268
  GimpClipboard *gimp_clip;
 
269
  GtkClipboard  *clipboard;
 
270
  GdkAtom        atom;
 
271
  GimpBuffer    *buffer = NULL;
255
272
 
256
273
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
257
274
 
270
287
 
271
288
      if (data)
272
289
        {
273
 
          GdkPixbuf *pixbuf = gimp_selection_data_get_pixbuf (data);
 
290
          GdkPixbuf *pixbuf = gtk_selection_data_get_pixbuf (data);
274
291
 
275
292
          gtk_selection_data_free (data);
276
293
 
277
294
          if (pixbuf)
278
295
            {
279
 
              TileManager *tiles = tile_manager_new_from_pixbuf (pixbuf);
280
 
 
 
296
              buffer = gimp_buffer_new_from_pixbuf (pixbuf, _("Clipboard"));
281
297
              g_object_unref (pixbuf);
282
 
 
283
 
              buffer = gimp_buffer_new (tiles, _("Clipboard"), FALSE);
284
298
            }
285
299
        }
286
300
 
287
301
      gimp_unset_busy (gimp);
288
302
    }
289
303
 
290
 
  if (! buffer && gimp->global_buffer)
291
 
    buffer = g_object_ref (gimp->global_buffer);
 
304
  gimp_clip = gimp_clipboard_get (gimp);
 
305
 
 
306
  if (! buffer && gimp_clip->buffer)
 
307
    buffer = g_object_ref (gimp_clip->buffer);
292
308
 
293
309
  return buffer;
294
310
}
295
311
 
 
312
/**
 
313
 * gimp_clipboard_get_svg:
 
314
 * @gimp: pointer to #Gimp
 
315
 * @svg_length: returns the size of the SVG stream in bytes
 
316
 *
 
317
 * Retrieves SVG data from %GDK_SELECTION_CLIPBOARD or from the global
 
318
 * SVG buffer of @gimp.
 
319
 *
 
320
 * The returned data needs to be freed when it's no longer needed.
 
321
 *
 
322
 * Return value: a reference to a #GimpBuffer or %NULL if there's no
 
323
 *               image data
 
324
 **/
 
325
gchar *
 
326
gimp_clipboard_get_svg (Gimp  *gimp,
 
327
                        gsize *svg_length)
 
328
{
 
329
  GimpClipboard *gimp_clip;
 
330
  GtkClipboard  *clipboard;
 
331
  GdkAtom        atom;
 
332
  gchar         *svg = NULL;
 
333
 
 
334
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
 
335
  g_return_val_if_fail (svg_length != NULL, NULL);
 
336
 
 
337
  clipboard = gtk_clipboard_get_for_display (gdk_display_get_default (),
 
338
                                             GDK_SELECTION_CLIPBOARD);
 
339
 
 
340
  if (clipboard                                                      &&
 
341
      gtk_clipboard_get_owner (clipboard)         != G_OBJECT (gimp) &&
 
342
      (atom = gimp_clipboard_wait_for_svg (gimp)) != GDK_NONE)
 
343
    {
 
344
      GtkSelectionData *data;
 
345
 
 
346
      gimp_set_busy (gimp);
 
347
 
 
348
      data = gtk_clipboard_wait_for_contents (clipboard, atom);
 
349
 
 
350
      if (data)
 
351
        {
 
352
          const guchar *stream;
 
353
 
 
354
          stream = gimp_selection_data_get_stream (data, svg_length);
 
355
 
 
356
          if (stream)
 
357
            svg = g_memdup (stream, *svg_length);
 
358
 
 
359
          gtk_selection_data_free (data);
 
360
        }
 
361
 
 
362
      gimp_unset_busy (gimp);
 
363
    }
 
364
 
 
365
  gimp_clip = gimp_clipboard_get (gimp);
 
366
 
 
367
  if (! svg && gimp_clip->svg)
 
368
    {
 
369
      svg = g_strdup (gimp_clip->svg);
 
370
      *svg_length = strlen (svg);
 
371
    }
 
372
 
 
373
  return svg;
 
374
}
 
375
 
 
376
/**
 
377
 * gimp_clipboard_set_buffer:
 
378
 * @gimp:   pointer to #Gimp
 
379
 * @buffer: a #GimpBuffer, or %NULL.
 
380
 *
 
381
 * Offers the buffer in %GDK_SELECTION_CLIPBOARD.
 
382
 **/
 
383
void
 
384
gimp_clipboard_set_buffer (Gimp       *gimp,
 
385
                           GimpBuffer *buffer)
 
386
{
 
387
  GimpClipboard *gimp_clip;
 
388
  GtkClipboard  *clipboard;
 
389
 
 
390
  g_return_if_fail (GIMP_IS_GIMP (gimp));
 
391
  g_return_if_fail (buffer == NULL || GIMP_IS_BUFFER (buffer));
 
392
 
 
393
  clipboard = gtk_clipboard_get_for_display (gdk_display_get_default (),
 
394
                                             GDK_SELECTION_CLIPBOARD);
 
395
  if (! clipboard)
 
396
    return;
 
397
 
 
398
  gimp_clip = gimp_clipboard_get (gimp);
 
399
 
 
400
  gimp_clipboard_clear (gimp_clip);
 
401
 
 
402
  if (buffer)
 
403
    {
 
404
      gimp_clip->buffer = g_object_ref (buffer);
 
405
 
 
406
      gtk_clipboard_set_with_owner (clipboard,
 
407
                                    gimp_clip->target_entries,
 
408
                                    gimp_clip->n_target_entries,
 
409
                                    (GtkClipboardGetFunc) gimp_clipboard_send_buffer,
 
410
                                    (GtkClipboardClearFunc) NULL,
 
411
                                    G_OBJECT (gimp));
 
412
 
 
413
      /*  mark the first entry (image/png) as suitable for storing  */
 
414
      gtk_clipboard_set_can_store (clipboard, gimp_clip->target_entries, 1);
 
415
    }
 
416
  else if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (gimp))
 
417
    {
 
418
      gtk_clipboard_clear (clipboard);
 
419
    }
 
420
}
 
421
 
 
422
/**
 
423
 * gimp_clipboard_set_svg:
 
424
 * @gimp: pointer to #Gimp
 
425
 * @svg: a string containing the SVG data, or %NULL
 
426
 *
 
427
 * Offers SVG data in %GDK_SELECTION_CLIPBOARD.
 
428
 **/
 
429
void
 
430
gimp_clipboard_set_svg (Gimp        *gimp,
 
431
                        const gchar *svg)
 
432
{
 
433
  GimpClipboard *gimp_clip;
 
434
  GtkClipboard  *clipboard;
 
435
 
 
436
  g_return_if_fail (GIMP_IS_GIMP (gimp));
 
437
 
 
438
  clipboard = gtk_clipboard_get_for_display (gdk_display_get_default (),
 
439
                                             GDK_SELECTION_CLIPBOARD);
 
440
  if (! clipboard)
 
441
    return;
 
442
 
 
443
  gimp_clip = gimp_clipboard_get (gimp);
 
444
 
 
445
  gimp_clipboard_clear (gimp_clip);
 
446
 
 
447
  if (svg)
 
448
    {
 
449
      gimp_clip->svg = g_strdup (svg);
 
450
 
 
451
      gtk_clipboard_set_with_owner (clipboard,
 
452
                                    gimp_clip->svg_target_entries,
 
453
                                    gimp_clip->n_svg_target_entries,
 
454
                                    (GtkClipboardGetFunc) gimp_clipboard_send_svg,
 
455
                                    (GtkClipboardClearFunc) NULL,
 
456
                                    G_OBJECT (gimp));
 
457
 
 
458
      /*  mark the first entry (image/svg) as suitable for storing  */
 
459
      gtk_clipboard_set_can_store (clipboard, gimp_clip->svg_target_entries, 1);
 
460
    }
 
461
  else if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (gimp))
 
462
    {
 
463
      gtk_clipboard_clear (clipboard);
 
464
    }
 
465
}
 
466
 
 
467
/**
 
468
 * gimp_clipboard_set_text:
 
469
 * @gimp: pointer to #Gimp
 
470
 * @text: a %NULL-terminated string in UTF-8 encoding
 
471
 *
 
472
 * Offers @text in %GDK_SELECTION_CLIPBOARD and %GDK_SELECTION_PRIMARY.
 
473
 **/
 
474
void
 
475
gimp_clipboard_set_text (Gimp        *gimp,
 
476
                         const gchar *text)
 
477
{
 
478
  GtkClipboard *clipboard;
 
479
 
 
480
  g_return_if_fail (GIMP_IS_GIMP (gimp));
 
481
  g_return_if_fail (text != NULL);
 
482
 
 
483
  gimp_clipboard_clear (gimp_clipboard_get (gimp));
 
484
 
 
485
  clipboard = gtk_clipboard_get_for_display (gdk_display_get_default (),
 
486
                                             GDK_SELECTION_CLIPBOARD);
 
487
  if (clipboard)
 
488
    gtk_clipboard_set_text (clipboard, text, -1);
 
489
 
 
490
  clipboard = gtk_clipboard_get_for_display (gdk_display_get_default (),
 
491
                                             GDK_SELECTION_PRIMARY);
 
492
  if (clipboard)
 
493
    gtk_clipboard_set_text (clipboard, text, -1);
 
494
}
 
495
 
296
496
 
297
497
/*  private functions  */
298
498
 
303
503
}
304
504
 
305
505
static void
 
506
gimp_clipboard_clear (GimpClipboard *gimp_clip)
 
507
{
 
508
  if (gimp_clip->buffer)
 
509
    {
 
510
      g_object_unref (gimp_clip->buffer);
 
511
      gimp_clip->buffer = NULL;
 
512
    }
 
513
 
 
514
  if (gimp_clip->svg)
 
515
    {
 
516
      g_free (gimp_clip->svg);
 
517
      gimp_clip->svg = NULL;
 
518
    }
 
519
}
 
520
 
 
521
static void
306
522
gimp_clipboard_free (GimpClipboard *gimp_clip)
307
523
{
 
524
  gint i;
 
525
 
 
526
  gimp_clipboard_clear (gimp_clip);
 
527
 
308
528
  g_slist_free (gimp_clip->pixbuf_formats);
 
529
 
 
530
  for (i = 0; i < gimp_clip->n_target_entries; i++)
 
531
    g_free (gimp_clip->target_entries[i].target);
 
532
 
309
533
  g_free (gimp_clip->target_entries);
310
 
  g_strfreev (gimp_clip->savers);
 
534
 
 
535
  for (i = 0; i < gimp_clip->n_svg_target_entries; i++)
 
536
    g_free (gimp_clip->svg_target_entries[i].target);
 
537
 
 
538
  g_free (gimp_clip->svg_target_entries);
 
539
 
311
540
  g_free (gimp_clip);
312
541
}
313
542
 
314
 
static void
315
 
gimp_clipboard_buffer_changed (Gimp *gimp)
316
 
{
317
 
  gimp_clipboard_set_buffer (gimp, gimp->global_buffer);
318
 
}
319
 
 
320
 
static void
321
 
gimp_clipboard_set_buffer (Gimp       *gimp,
322
 
                           GimpBuffer *buffer)
323
 
{
324
 
  GimpClipboard *gimp_clip = gimp_clipboard_get (gimp);
325
 
  GtkClipboard  *clipboard;
326
 
 
327
 
  clipboard = gtk_clipboard_get_for_display (gdk_display_get_default (),
328
 
                                             GDK_SELECTION_CLIPBOARD);
329
 
  if (! clipboard)
330
 
    return;
331
 
 
332
 
  if (buffer)
333
 
    {
334
 
      gtk_clipboard_set_with_owner (clipboard,
335
 
                                    gimp_clip->target_entries,
336
 
                                    gimp_clip->n_target_entries,
337
 
                                    (GtkClipboardGetFunc)   gimp_clipboard_send_buffer,
338
 
                                    (GtkClipboardClearFunc) NULL,
339
 
                                    G_OBJECT (gimp));
340
 
    }
341
 
  else if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (gimp))
342
 
    {
343
 
      gtk_clipboard_clear (clipboard);
344
 
    }
345
 
}
346
 
 
347
543
static GdkAtom *
348
 
gimp_clipboard_wait_for_targets (gint *n_targets)
 
544
gimp_clipboard_wait_for_targets (Gimp *gimp,
 
545
                                 gint *n_targets)
349
546
{
350
547
  GtkClipboard *clipboard;
351
548
 
370
567
 
371
568
          if (success)
372
569
            {
373
 
              gint i;
374
 
 
375
 
              for (i = 0; i < *n_targets; i++)
376
 
                g_print ("offered type: %s\n", gdk_atom_name (targets[i]));
377
 
 
378
 
              g_print ("\n");
 
570
              if (gimp->be_verbose)
 
571
                {
 
572
                  gint i;
 
573
 
 
574
                  for (i = 0; i < *n_targets; i++)
 
575
                    g_printerr ("clipboard: offered type: %s\n",
 
576
                                gdk_atom_name (targets[i]));
 
577
 
 
578
                  g_printerr ("\n");
 
579
                }
379
580
 
380
581
              return targets;
381
582
            }
393
594
  gint           n_targets;
394
595
  GdkAtom        result    = GDK_NONE;
395
596
 
396
 
  targets = gimp_clipboard_wait_for_targets (&n_targets);
 
597
  targets = gimp_clipboard_wait_for_targets (gimp, &n_targets);
397
598
 
398
599
  if (targets)
399
600
    {
405
606
          gchar           **mime_types;
406
607
          gchar           **type;
407
608
 
408
 
          g_print ("checking pixbuf format '%s'\n",
409
 
                   gdk_pixbuf_format_get_name (format));
 
609
          if (gimp->be_verbose)
 
610
            g_printerr ("clipboard: checking pixbuf format '%s'\n",
 
611
                        gdk_pixbuf_format_get_name (format));
410
612
 
411
613
          mime_types = gdk_pixbuf_format_get_mime_types (format);
412
614
 
416
618
              GdkAtom  atom      = gdk_atom_intern (mime_type, FALSE);
417
619
              gint     i;
418
620
 
419
 
              g_print (" - checking mime type '%s'\n", mime_type);
 
621
              if (gimp->be_verbose)
 
622
                g_printerr ("  - checking mime type '%s'\n", mime_type);
420
623
 
421
624
              for (i = 0; i < n_targets; i++)
422
625
                {
443
646
  return result;
444
647
}
445
648
 
 
649
static GdkAtom
 
650
gimp_clipboard_wait_for_svg (Gimp *gimp)
 
651
{
 
652
  GdkAtom *targets;
 
653
  gint     n_targets;
 
654
  GdkAtom  result = GDK_NONE;
 
655
 
 
656
  targets = gimp_clipboard_wait_for_targets (gimp, &n_targets);
 
657
 
 
658
  if (targets)
 
659
    {
 
660
      GdkAtom svg_atom     = gdk_atom_intern ("image/svg",     FALSE);
 
661
      GdkAtom svg_xml_atom = gdk_atom_intern ("image/svg+xml", FALSE);
 
662
      gint    i;
 
663
 
 
664
      for (i = 0; i < n_targets; i++)
 
665
        {
 
666
          if (targets[i] == svg_atom)
 
667
            {
 
668
              result = svg_atom;
 
669
              break;
 
670
            }
 
671
          else if (targets[i] == svg_xml_atom)
 
672
            {
 
673
              result = svg_xml_atom;
 
674
              break;
 
675
            }
 
676
        }
 
677
 
 
678
      g_free (targets);
 
679
    }
 
680
 
 
681
  return result;
 
682
}
 
683
 
446
684
static void
447
685
gimp_clipboard_send_buffer (GtkClipboard     *clipboard,
448
686
                            GtkSelectionData *selection_data,
450
688
                            Gimp             *gimp)
451
689
{
452
690
  GimpClipboard *gimp_clip = gimp_clipboard_get (gimp);
453
 
  GimpBuffer    *buffer    = gimp->global_buffer;
454
691
  GdkPixbuf     *pixbuf;
455
692
 
456
693
  gimp_set_busy (gimp);
457
694
 
458
 
  pixbuf = gimp_viewable_get_pixbuf (GIMP_VIEWABLE (buffer),
459
 
                                     gimp_buffer_get_width (buffer),
460
 
                                     gimp_buffer_get_height (buffer));
 
695
  pixbuf = gimp_viewable_get_pixbuf (GIMP_VIEWABLE (gimp_clip->buffer),
 
696
                                     gimp_get_user_context (gimp),
 
697
                                     gimp_buffer_get_width (gimp_clip->buffer),
 
698
                                     gimp_buffer_get_height (gimp_clip->buffer));
461
699
 
462
700
  if (pixbuf)
463
701
    {
464
 
      GdkAtom atom = gdk_atom_intern (gimp_clip->target_entries[info].target,
465
 
                                      FALSE);
466
 
 
467
 
      g_print ("sending pixbuf data as '%s' (%s)\n",
468
 
               gimp_clip->target_entries[info].target,
469
 
               gimp_clip->savers[info]);
470
 
 
471
 
      gimp_selection_data_set_pixbuf (selection_data, atom, pixbuf,
472
 
                                      gimp_clip->savers[info]);
 
702
      if (gimp->be_verbose)
 
703
        g_printerr ("clipboard: sending pixbuf data as '%s'\n",
 
704
                    gimp_clip->target_entries[info].target);
 
705
 
 
706
      gtk_selection_data_set_pixbuf (selection_data, pixbuf);
473
707
    }
474
708
  else
475
709
    {
479
713
  gimp_unset_busy (gimp);
480
714
}
481
715
 
482
 
static gint
483
 
gimp_clipboard_format_compare (GdkPixbufFormat *a,
484
 
                               GdkPixbufFormat *b)
 
716
static void
 
717
gimp_clipboard_send_svg (GtkClipboard     *clipboard,
 
718
                         GtkSelectionData *selection_data,
 
719
                         guint             info,
 
720
                         Gimp             *gimp)
485
721
{
486
 
  gchar *a_name = gdk_pixbuf_format_get_name (a);
487
 
  gchar *b_name = gdk_pixbuf_format_get_name (b);
488
 
  gint   retval = 0;
489
 
 
490
 
#ifdef GDK_WINDOWING_WIN32
491
 
  /*  move BMP to the front of the list  */
492
 
  if (strcmp (a_name, "bmp") == 0)
493
 
    retval = -1;
494
 
  else if (strcmp (b_name, "bmp") == 0)
495
 
    retval = 1;
496
 
  else
497
 
#endif
498
 
 
499
 
  /*  move PNG to the front of the list  */
500
 
  if (strcmp (a_name, "png") == 0)
501
 
    retval = -1;
502
 
  else if (strcmp (b_name, "png") == 0)
503
 
    retval = 1;
504
 
 
505
 
  /*  move JPEG to the end of the list  */
506
 
  else if (strcmp (a_name, "jpeg") == 0)
507
 
    retval = 1;
508
 
  else if (strcmp (b_name, "jpeg") == 0)
509
 
    retval = -1;
510
 
 
511
 
  /*  move GIF to the end of the list  */
512
 
  else if (strcmp (a_name, "gif") == 0)
513
 
    retval = 1;
514
 
  else if (strcmp (b_name, "gif") == 0)
515
 
    retval = -1;
516
 
 
517
 
  g_free (a_name);
518
 
  g_free (b_name);
519
 
 
520
 
  return retval;
 
722
  GimpClipboard *gimp_clip = gimp_clipboard_get (gimp);
 
723
 
 
724
  gimp_set_busy (gimp);
 
725
 
 
726
  if (gimp_clip->svg)
 
727
    {
 
728
      if (gimp->be_verbose)
 
729
        g_printerr ("clipboard: sending SVG data as '%s'\n",
 
730
                    gimp_clip->svg_target_entries[info].target);
 
731
 
 
732
      gimp_selection_data_set_stream (selection_data,
 
733
                                      (const guchar *) gimp_clip->svg,
 
734
                                      strlen (gimp_clip->svg));
 
735
    }
 
736
 
 
737
  gimp_unset_busy (gimp);
521
738
}