Re: [gtk-osx-users] Pasting images from clipboard
- From: Miroslav Rajcic <mrajcic hotmail com>
- To: "gtk-osx-users-list gnome org" <gtk-osx-users-list gnome org>
- Subject: Re: [gtk-osx-users] Pasting images from clipboard
- Date: Wed, 10 Feb 2016 14:23:49 +0000
I created a small sample, and I can still reproduce the issue.
Code features "Paste Image" button, that tries to fetch image from the clipboard if available.
On my Mac Mini (OS X 10.7.5) I always see message box "ERROR: Failed to get image from the clipboard!",
telling me that there is an image on clipboard, but it failed to fetch it.
Bug recipe is to open some .jpg or .png image in some picture viewer app and copy it to clipboard, then press
"Paste image" button.
Entire sample program code is given below.
Additionally, I have put entire sample project and a sample binary installer (created with "make
osxinstaller" from sources) online at:
http://notecase.sourceforge.net/temp/paste_sample_src.zip
http://notecase.sourceforge.net/temp/test-1.0.pkg
Regards,
Miroslav
PS. Code:
#include <gtk/gtk.h>
#include <string>
GtkWidget *window1;
GtkWidget *textview1;
int gtkMessageBox(const char *szText)
{
GtkWidget* msgbox = gtk_message_dialog_new ( (GtkWindow*)window1,
GTK_DIALOG_DESTROY_WITH_PARENT,
(GtkMessageType)GTK_MESSAGE_INFO,
(GtkButtonsType)GTK_BUTTONS_OK,
"%s", szText);
gtk_widget_grab_focus (msgbox);
gint result = gtk_dialog_run (GTK_DIALOG (msgbox));
gtk_widget_destroy (msgbox);
return result;
}
extern "C" void OnPasteClipboardTargetsReceivedFunc(GtkClipboard *clipboard, GdkAtom *atoms, gint n_atoms,
gpointer data)
{
//get image
if(gtk_targets_include_image(atoms, n_atoms, FALSE)){
GdkPixbuf *pixbuf = gtk_clipboard_wait_for_image(clipboard);
if(!pixbuf)
gtkMessageBox("ERROR: Failed to get image from the clipboard!");
else
gtkMessageBox("Success!");
}
else
gtkMessageBox("No image found!");
}
void on_paste1_activate (GtkMenuItem *menuitem, gpointer user_data)
{
GtkClipboard *clipboard = gtk_widget_get_clipboard (textview1, GDK_SELECTION_CLIPBOARD);
gtk_clipboard_request_targets(clipboard, OnPasteClipboardTargetsReceivedFunc, NULL);
}
void create_gui()
{
window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window1), "Clipboard test");
gtk_window_set_default_size (GTK_WINDOW (window1), 500, 350);
gtk_widget_show (window1);
GtkWidget *vbox1 = gtk_vbox_new (FALSE, 0);
gtk_widget_show (vbox1);
gtk_container_add (GTK_CONTAINER (window1), vbox1);
GtkWidget *button1 = gtk_button_new_with_mnemonic("Paste Image");
gtk_widget_set_size_request (button1, -1, 40);
gtk_widget_show (button1);
gtk_container_add (GTK_CONTAINER (vbox1), button1);
g_signal_connect(button1, "clicked", G_CALLBACK (on_paste1_activate), NULL);
GtkWidget *scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
gtk_widget_show (scrolledwindow1);
gtk_container_add (GTK_CONTAINER (vbox1), scrolledwindow1);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow1), GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
GtkTextBuffer *buffer = gtk_text_buffer_new (NULL);
textview1 = gtk_text_view_new_with_buffer (buffer);
gtk_widget_show (textview1);
gtk_container_add (GTK_CONTAINER (scrolledwindow1), textview1);
g_signal_connect (window1, "destroy", G_CALLBACK (gtk_main_quit), NULL);
}
int main (int argc, char *argv[])
{
gtk_init (&argc, &argv);
create_gui();
gtk_main ();
return 0;
}
From: Gtk-osx-users-list <gtk-osx-users-list-bounces gnome org> on behalf of Miroslav Rajcic <mrajcic hotmail
com>
Sent: Tuesday, February 9, 2016 11:27 AM
To: gtk-osx-users-list gnome org
Subject: [gtk-osx-users] Pasting images from clipboard
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);
if(!pixbuf){
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
below).
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
problematic.
Regards,
Miroslav
________________________________________
From: Gtk-osx-users-list <gtk-osx-users-list-bounces gnome org> on behalf of Miroslav Rajcic <mrajcic hotmail
com>
Sent: Wednesday, February 10, 2016 10:52 AM
To: gtk-osx-users-list gnome org
Subject: 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
call).
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.
Regards,
Miroslav
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]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]