GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Oct 21, 2014 9:39 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Simple application for Copy and Paste to OpenOffice
PostPosted: Wed Feb 15, 2012 3:39 am 
Offline

Joined: Wed Feb 15, 2012 2:35 am
Posts: 2
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


Top
 Profile  
 
 Post subject: Re: Simple application for Copy and Paste to OpenOffice
PostPosted: Fri Feb 17, 2012 9:55 am 
Offline

Joined: Wed Feb 15, 2012 2:35 am
Posts: 2
Hi,

I can answer the question myself(Not very sure the exact reason).

The reason is that I did not call gtk_main() at all!! Because I thought it is just a GUI initiating function and main event loop for windows. Since what I wanted to do is to put image to the clipboard, so I did not call gtk_main(). And one more thing is that if you want to paste things into OOo, you have to call the function: gtk_clipboard_set_with_owner. But if you want to paste things into GIMP, you can call gtk_clipboard_set_with_owner or gtk_clipboard_set_image. Kind of strange!

Maybe these things are very obvious for most of the people. But I'm stupid enough that I ignore the gtk_main() function.

For your reference.
Weka


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group