46
42
struct _GimpClipboard
48
GSList *pixbuf_formats;
50
GtkTargetEntry *target_entries;
51
gint n_target_entries;
44
GSList *pixbuf_formats;
46
GtkTargetEntry *target_entries;
47
gint n_target_entries;
49
GtkTargetEntry *svg_target_entries;
50
gint n_svg_target_entries;
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);
59
static void gimp_clipboard_buffer_changed (Gimp *gimp);
60
static void gimp_clipboard_set_buffer (Gimp *gimp,
61
static GdkAtom * gimp_clipboard_wait_for_targets (Gimp *gimp,
63
static GdkAtom gimp_clipboard_wait_for_buffer (Gimp *gimp);
64
static GdkAtom gimp_clipboard_wait_for_svg (Gimp *gimp);
63
66
static void gimp_clipboard_send_buffer (GtkClipboard *clipboard,
64
67
GtkSelectionData *selection_data,
68
static GdkAtom * gimp_clipboard_wait_for_targets (gint *n_targets);
69
static GdkAtom gimp_clipboard_wait_for_buffer (Gimp *gimp);
71
static gint gimp_clipboard_format_compare (GdkPixbufFormat *a,
70
static void gimp_clipboard_send_svg (GtkClipboard *clipboard,
71
GtkSelectionData *selection_data,
76
/* public functions */
76
79
gimp_clipboard_init (Gimp *gimp)
156
gimp_clip->n_svg_target_entries = 2;
157
gimp_clip->svg_target_entries = g_new0 (GtkTargetEntry, 2);
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;
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;
167
169
gimp_clipboard_exit (Gimp *gimp)
171
GtkClipboard *clipboard;
169
173
g_return_if_fail (GIMP_IS_GIMP (gimp));
171
g_signal_handlers_disconnect_by_func (gimp,
172
G_CALLBACK (gimp_clipboard_buffer_changed),
174
gimp_clipboard_set_buffer (gimp, NULL);
175
clipboard = gtk_clipboard_get_for_display (gdk_display_get_default (),
176
GDK_SELECTION_CLIPBOARD);
178
if (clipboard && gtk_clipboard_get_owner (clipboard) == G_OBJECT (gimp))
179
gtk_clipboard_store (clipboard);
176
181
g_object_set_data (G_OBJECT (gimp), GIMP_CLIPBOARD_KEY, NULL);
192
197
gimp_clipboard_has_buffer (Gimp *gimp)
199
GimpClipboard *gimp_clip;
200
GtkClipboard *clipboard;
194
202
g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
196
if (gimp->global_buffer)
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);
208
gtk_clipboard_get_owner (clipboard) != G_OBJECT (gimp) &&
209
gimp_clipboard_wait_for_buffer (gimp) != GDK_NONE)
214
gimp_clip = gimp_clipboard_get (gimp);
216
return (gimp_clip->buffer != NULL);
204
tile_manager_new_from_pixbuf (GdkPixbuf *pixbuf)
220
* gimp_clipboard_has_svg:
221
* @gimp: pointer to #Gimp
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.
227
* Return value: %TRUE if there's SVG data in the clipboard, %FALSE otherwise
230
gimp_clipboard_has_svg (Gimp *gimp)
215
g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
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);
222
tiles = tile_manager_new (width, height, channels);
224
pixel_region_init (&destPR, tiles, 0, 0, width, height, TRUE);
226
for (y = 0, pixels = gdk_pixbuf_get_pixels (pixbuf);
228
y++, pixels += rowstride)
232
GimpClipboard *gimp_clip;
233
GtkClipboard *clipboard;
235
g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
237
clipboard = gtk_clipboard_get_for_display (gdk_display_get_default (),
238
GDK_SELECTION_CLIPBOARD);
241
gtk_clipboard_get_owner (clipboard) != G_OBJECT (gimp) &&
242
gimp_clipboard_wait_for_svg (gimp) != GDK_NONE)
230
pixel_region_set_row (&destPR, 0, y, width, pixels);
247
gimp_clip = gimp_clipboard_get (gimp);
249
return (gimp_clip->svg != NULL);
273
GdkPixbuf *pixbuf = gimp_selection_data_get_pixbuf (data);
290
GdkPixbuf *pixbuf = gtk_selection_data_get_pixbuf (data);
275
292
gtk_selection_data_free (data);
279
TileManager *tiles = tile_manager_new_from_pixbuf (pixbuf);
296
buffer = gimp_buffer_new_from_pixbuf (pixbuf, _("Clipboard"));
281
297
g_object_unref (pixbuf);
283
buffer = gimp_buffer_new (tiles, _("Clipboard"), FALSE);
287
301
gimp_unset_busy (gimp);
290
if (! buffer && gimp->global_buffer)
291
buffer = g_object_ref (gimp->global_buffer);
304
gimp_clip = gimp_clipboard_get (gimp);
306
if (! buffer && gimp_clip->buffer)
307
buffer = g_object_ref (gimp_clip->buffer);
313
* gimp_clipboard_get_svg:
314
* @gimp: pointer to #Gimp
315
* @svg_length: returns the size of the SVG stream in bytes
317
* Retrieves SVG data from %GDK_SELECTION_CLIPBOARD or from the global
318
* SVG buffer of @gimp.
320
* The returned data needs to be freed when it's no longer needed.
322
* Return value: a reference to a #GimpBuffer or %NULL if there's no
326
gimp_clipboard_get_svg (Gimp *gimp,
329
GimpClipboard *gimp_clip;
330
GtkClipboard *clipboard;
334
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
335
g_return_val_if_fail (svg_length != NULL, NULL);
337
clipboard = gtk_clipboard_get_for_display (gdk_display_get_default (),
338
GDK_SELECTION_CLIPBOARD);
341
gtk_clipboard_get_owner (clipboard) != G_OBJECT (gimp) &&
342
(atom = gimp_clipboard_wait_for_svg (gimp)) != GDK_NONE)
344
GtkSelectionData *data;
346
gimp_set_busy (gimp);
348
data = gtk_clipboard_wait_for_contents (clipboard, atom);
352
const guchar *stream;
354
stream = gimp_selection_data_get_stream (data, svg_length);
357
svg = g_memdup (stream, *svg_length);
359
gtk_selection_data_free (data);
362
gimp_unset_busy (gimp);
365
gimp_clip = gimp_clipboard_get (gimp);
367
if (! svg && gimp_clip->svg)
369
svg = g_strdup (gimp_clip->svg);
370
*svg_length = strlen (svg);
377
* gimp_clipboard_set_buffer:
378
* @gimp: pointer to #Gimp
379
* @buffer: a #GimpBuffer, or %NULL.
381
* Offers the buffer in %GDK_SELECTION_CLIPBOARD.
384
gimp_clipboard_set_buffer (Gimp *gimp,
387
GimpClipboard *gimp_clip;
388
GtkClipboard *clipboard;
390
g_return_if_fail (GIMP_IS_GIMP (gimp));
391
g_return_if_fail (buffer == NULL || GIMP_IS_BUFFER (buffer));
393
clipboard = gtk_clipboard_get_for_display (gdk_display_get_default (),
394
GDK_SELECTION_CLIPBOARD);
398
gimp_clip = gimp_clipboard_get (gimp);
400
gimp_clipboard_clear (gimp_clip);
404
gimp_clip->buffer = g_object_ref (buffer);
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,
413
/* mark the first entry (image/png) as suitable for storing */
414
gtk_clipboard_set_can_store (clipboard, gimp_clip->target_entries, 1);
416
else if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (gimp))
418
gtk_clipboard_clear (clipboard);
423
* gimp_clipboard_set_svg:
424
* @gimp: pointer to #Gimp
425
* @svg: a string containing the SVG data, or %NULL
427
* Offers SVG data in %GDK_SELECTION_CLIPBOARD.
430
gimp_clipboard_set_svg (Gimp *gimp,
433
GimpClipboard *gimp_clip;
434
GtkClipboard *clipboard;
436
g_return_if_fail (GIMP_IS_GIMP (gimp));
438
clipboard = gtk_clipboard_get_for_display (gdk_display_get_default (),
439
GDK_SELECTION_CLIPBOARD);
443
gimp_clip = gimp_clipboard_get (gimp);
445
gimp_clipboard_clear (gimp_clip);
449
gimp_clip->svg = g_strdup (svg);
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,
458
/* mark the first entry (image/svg) as suitable for storing */
459
gtk_clipboard_set_can_store (clipboard, gimp_clip->svg_target_entries, 1);
461
else if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (gimp))
463
gtk_clipboard_clear (clipboard);
468
* gimp_clipboard_set_text:
469
* @gimp: pointer to #Gimp
470
* @text: a %NULL-terminated string in UTF-8 encoding
472
* Offers @text in %GDK_SELECTION_CLIPBOARD and %GDK_SELECTION_PRIMARY.
475
gimp_clipboard_set_text (Gimp *gimp,
478
GtkClipboard *clipboard;
480
g_return_if_fail (GIMP_IS_GIMP (gimp));
481
g_return_if_fail (text != NULL);
483
gimp_clipboard_clear (gimp_clipboard_get (gimp));
485
clipboard = gtk_clipboard_get_for_display (gdk_display_get_default (),
486
GDK_SELECTION_CLIPBOARD);
488
gtk_clipboard_set_text (clipboard, text, -1);
490
clipboard = gtk_clipboard_get_for_display (gdk_display_get_default (),
491
GDK_SELECTION_PRIMARY);
493
gtk_clipboard_set_text (clipboard, text, -1);
297
497
/* private functions */
506
gimp_clipboard_clear (GimpClipboard *gimp_clip)
508
if (gimp_clip->buffer)
510
g_object_unref (gimp_clip->buffer);
511
gimp_clip->buffer = NULL;
516
g_free (gimp_clip->svg);
517
gimp_clip->svg = NULL;
306
522
gimp_clipboard_free (GimpClipboard *gimp_clip)
526
gimp_clipboard_clear (gimp_clip);
308
528
g_slist_free (gimp_clip->pixbuf_formats);
530
for (i = 0; i < gimp_clip->n_target_entries; i++)
531
g_free (gimp_clip->target_entries[i].target);
309
533
g_free (gimp_clip->target_entries);
310
g_strfreev (gimp_clip->savers);
535
for (i = 0; i < gimp_clip->n_svg_target_entries; i++)
536
g_free (gimp_clip->svg_target_entries[i].target);
538
g_free (gimp_clip->svg_target_entries);
311
540
g_free (gimp_clip);
315
gimp_clipboard_buffer_changed (Gimp *gimp)
317
gimp_clipboard_set_buffer (gimp, gimp->global_buffer);
321
gimp_clipboard_set_buffer (Gimp *gimp,
324
GimpClipboard *gimp_clip = gimp_clipboard_get (gimp);
325
GtkClipboard *clipboard;
327
clipboard = gtk_clipboard_get_for_display (gdk_display_get_default (),
328
GDK_SELECTION_CLIPBOARD);
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,
341
else if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (gimp))
343
gtk_clipboard_clear (clipboard);
348
gimp_clipboard_wait_for_targets (gint *n_targets)
544
gimp_clipboard_wait_for_targets (Gimp *gimp,
350
547
GtkClipboard *clipboard;
452
690
GimpClipboard *gimp_clip = gimp_clipboard_get (gimp);
453
GimpBuffer *buffer = gimp->global_buffer;
454
691
GdkPixbuf *pixbuf;
456
693
gimp_set_busy (gimp);
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));
464
GdkAtom atom = gdk_atom_intern (gimp_clip->target_entries[info].target,
467
g_print ("sending pixbuf data as '%s' (%s)\n",
468
gimp_clip->target_entries[info].target,
469
gimp_clip->savers[info]);
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);
706
gtk_selection_data_set_pixbuf (selection_data, pixbuf);
479
713
gimp_unset_busy (gimp);
483
gimp_clipboard_format_compare (GdkPixbufFormat *a,
717
gimp_clipboard_send_svg (GtkClipboard *clipboard,
718
GtkSelectionData *selection_data,
486
gchar *a_name = gdk_pixbuf_format_get_name (a);
487
gchar *b_name = gdk_pixbuf_format_get_name (b);
490
#ifdef GDK_WINDOWING_WIN32
491
/* move BMP to the front of the list */
492
if (strcmp (a_name, "bmp") == 0)
494
else if (strcmp (b_name, "bmp") == 0)
499
/* move PNG to the front of the list */
500
if (strcmp (a_name, "png") == 0)
502
else if (strcmp (b_name, "png") == 0)
505
/* move JPEG to the end of the list */
506
else if (strcmp (a_name, "jpeg") == 0)
508
else if (strcmp (b_name, "jpeg") == 0)
511
/* move GIF to the end of the list */
512
else if (strcmp (a_name, "gif") == 0)
514
else if (strcmp (b_name, "gif") == 0)
722
GimpClipboard *gimp_clip = gimp_clipboard_get (gimp);
724
gimp_set_busy (gimp);
728
if (gimp->be_verbose)
729
g_printerr ("clipboard: sending SVG data as '%s'\n",
730
gimp_clip->svg_target_entries[info].target);
732
gimp_selection_data_set_stream (selection_data,
733
(const guchar *) gimp_clip->svg,
734
strlen (gimp_clip->svg));
737
gimp_unset_busy (gimp);