Re: [gtk-osx-users] Pasting images from clipboard

Hi John,

I've tested with both .jpg and .png file formats, but they both fail.
I open the image by clicking on it in Finder and it would open in "Preview" app. Then I would run "Select 
all" and "Copy" items from the "Edit" menu to put the data into clipboard.

I've added the code that lists available clipboard format targets at the paste time (using gdk_atom_name 
The generated list is this:
10:40:07.644 Clipboard targets (4 items):
10:40:07.644 [ 0/ 4]: PVPboardInfoPboardType
10:40:07.644 [ 1/ 4]: dyn.ah62d4rv4gu8zazwuqm10c6xemf1gq54uqm10c6xenv61a3k
10:40:07.644 [ 2/ 4]: image/tiff
10:40:07.644 [ 3/ 4]: public.tiff

Looking at the code tiff should be supported. Will try to write small sample app to show the problem.


PS. I also listed all supported file formats on startup (using gdk_pixbuf_get_formats, 
gdk_pixbuf_format_get_name, ...).
Tiff is listed as having a full support (not just read-only):

10:37:31.554 Supported image formats:
10:37:32.080 #00: (GdkPixdata) The GdkPixdata format [READ-ONLY]
10:37:32.080 #01: (  ani) The ANI image format [READ-ONLY]
10:37:32.080 #02: (  bmp) The BMP image format []
10:37:32.080 #03: (  gif) The GIF image format [READ-ONLY]
10:37:32.080 #04: ( icns) The ICNS image format [READ-ONLY]
10:37:32.080 #05: (  ico) The ICO image format []
10:37:32.080 #06: ( jpeg) The JPEG image format []
10:37:32.080 #07: (  pcx) The PCX image format [READ-ONLY]
10:37:32.080 #08: (  png) The PNG image format []
10:37:32.080 #09: (  pnm) The PNM/PBM/PGM/PPM image format family [READ-ONLY]
10:37:32.080 #10: ( qtif) The QTIF image format [READ-ONLY]
10:37:32.080 #11: (  ras) The Sun raster image format [READ-ONLY]
10:37:32.080 #12: (  svg) Scalable Vector Graphics [READ-ONLY]
10:37:32.080 #13: (  tga) The Targa image format [READ-ONLY]
10:37:32.080 #14: ( tiff) The TIFF image format []
10:37:32.080 #15: ( wbmp) The WBMP image format [READ-ONLY]
10:37:32.080 #16: (  xbm) The XBM image format [READ-ONLY]
10:37:32.080 #17: (  xpm) The XPM image format [READ-ONLY]

From: John Ralls <jralls ceridwen us>
Sent: Tuesday, February 9, 2016 4:09 PM
To: Miroslav Rajcic
Cc: gtk-osx-users-list gnome org
Subject: Re: [gtk-osx-users] Pasting images from clipboard

On Feb 9, 2016, at 2:27 AM, Miroslav Rajcic <mrajcic hotmail com> wrote:

Is pasting images from the clipboard supported in GTK 2.x for OS X?
In my app, the same code doesn't work on OS X but works OK on all other platforms (Windows, Linux, BSD, 

Actual code goes like this:

- paste is initialized by call to:
    GtkClipboard *clipboard = gtk_widget_get_clipboard (g_text.m_pWidget, GDK_SELECTION_CLIPBOARD);
    gtk_clipboard_request_targets(clipboard, OnPasteClipboardTargetsReceivedFunc, NULL);

- inside OnPasteClipboardTargetsReceivedFunc callback, I do actual pasting with:
    if(gtk_targets_include_image(atoms, n_atoms, FALSE)){
        GtkPixbuf *pixbuf = gtk_clipboard_wait_for_image(clipboard);
            gtkMessageBox(_("Failed to open image from the clipboard!"));

This GTK API call fails consistently all the time (returning NULL) on OS X (triggering error message box 
Is this a known issue?

Note that pasting works OK for other types of content (text, RTF), but naturally I use different calls to 
fetch those.
The app is bundled with all image loaders, inserting image from file works OK, only clipboard operation is 

How are you putting the image into the clipboard and what kind of image is it? The quartz clipboard functions 
are implemented separately from the other platforms in gtkclipboard-quartz.c:

gtk_clipboard_wait_for_image (GtkClipboard *clipboard)
  const gchar *priority[] = { "image/png", "image/tiff", "image/jpeg", "image/gif", "image/bmp" };
  int i;
  GtkSelectionData *data;

  for (i = 0; i < G_N_ELEMENTS (priority); i++)
      data = gtk_clipboard_wait_for_contents (clipboard, gdk_atom_intern_static_string (priority[i]));

      if (data)
          GdkPixbuf *pixbuf = gtk_selection_data_get_pixbuf (data);

          gtk_selection_data_free (data);

          return pixbuf;

  return NULL;

Note that it will only handle the 5 image types in the "priority" array.

John Ralls

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]