Hi ,
Currently I'm trying to write an simple application that it can append an image data to the clipboard so that user can paste it into OOo(I'm working on RHEL 5.2 with GTK2.2, GNOME).
This application is integrated with a TCL/TK user interface. users can choose a picture they want and press Ctrl+C and use Ctrl+p to paste it into OOo. The whole thing is basically for scientific data analyzing and making report......... and my application will be invoked automatically when Ctrl+C is pressed.
here is what I have done, but it is not working
Code:
code snippet:
GError * error = NULL;
GdkPixbuf * pixbuf = gdk_pixbuf_new_from_file( "./ClipboardTest.bmp", &error );
gtk_clipboard_set_image( gtk_clipboard_get( GDK_SELECTION_CLIPBOARD ), pixbuf );
gtk_clipboard_store( gtk_clipboard_get( GDK_SELECTION_CLIPBOARD ) );
But this does not work. When I try to paste it into Calc, it always says that "the content of clipboard can not be pasted". When I try to paste it into Google Doc, it always says that wrong format of the data on clipboard.
So I tried another way to do it
Code:
code snippet:
g_signal_connect(G_OBJECT( gtk_clipboard_get( GDK_SELECTION_CLIPBOARD )), "owner-changed", owner_changed, NULL);
int formatCount = GetTargetEntryCount(); // just a function finding out the total count
GtkTargetEntry target_entries[formatCount];
SetTargetEntry ( formatCount, target_entries ); // setting up the correct words
gtk_clipboard_set_with_owner ( gtk_clipboard_get( GDK_SELECTION_CLIPBOARD ) ,
target_entries,
formatCount,
(GtkClipboardGetFunc) clipboard_send_buffer,
(GtkClipboardClearFunc) NULL,
G_OBJECT ( pixbuf ) );
gtk_clipboard_set_can_store ( gtk_clipboard_get( GDK_SELECTION_CLIPBOARD ), target_entries, 0);
This method also failed. This time no message poping up when I was trying to paste into OOo and Google Docs. And most importantly, the callback function " (GtkClipboardGetFunc) clipboard_send_buffer " is never called while I was pasting to other applications !!!!
I have dug into the code of GIMP and found that GIMP almost does the same thing as above. But GIMP can do a perfect job copying images from it and paste into OOo. And if you invoke GIMP with verbose option, you can see the callback is called while pasting into OOo. And I checked the API "gtk_clipboard_set_image" in GTK, it seems to do the same thing above.
So I have no idea what is wrong with it. there must be a major error in my application. I cannot do a thorough investigation for GIMP, OpenOffice source code(or maybe firefox). It should be a conceptual mis-understading to GTK and Clipboard.
So please help me out and give me some indications.
Thanks a lot!!
Weka