gtk_clipboard_wait_for_contents bug ?



I am trying to support pasting formatted text from OO.org Writer into my program using HTML clipboard format

Under Windows OS, using "clipboard spy" I can see that the OO.org Writer puts these formats to the clipboard:
- "HTML (HyperText Markup Language)"
- "HTML Format"

Problem is that, when I access to any of those, GtkSelectionData sel->format equals 32 (32 bit?) and the sel->length always equals 36 no matter if I copied 1 or 1000 characters to the clipboard !!!!

Additionally, if I try to print gdk_atom_name(sel->type) I get "ATOM" as a result instead of "HTML Format"!
gdk_atom_name(atomHtmlOther) gives "HTML Format" as a result.

Under Linux, OO.org Writer exports standard "text/html" clipboard format and that works fine.

Can anyone spot the bug in the code below ? Is this a bug in GTK Windows port ?
I am using latest GTK 2.12.9 (Windows build) from gtk.org.

Regards,
 Miroslav

PS. Here is the relevant code:

//paste handler
GtkClipboard *clipboard = gtk_widget_get_clipboard (textview, GDK_SELECTION_CLIPBOARD); gtk_clipboard_request_targets(clipboard, MyClipboardTargetsReceivedFunc, NULL);

...
void MyClipboardTargetsReceivedFunc(GtkClipboard *clipboard, GdkAtom *atoms, gint n_atoms, gpointer data)
{
   bool bHtmlFound = false;
   GdkAtom atomHtmlOther; //try to find any HTML format
   if(NULL != atoms)
   {
       for(int i=0; i<n_atoms; i++)
   {
       gchar *szName = gdk_atom_name(atoms[i]);
       printf("Clip format available: %s\n", szName);
       if(NULL != strstr(szName, "HTML")){
           bHtmlFound = true;
           atomHtmlOther = atoms[i]; //gdk_atom_intern(szName, FALSE);
       }
       g_free(szName);
       if(bHtmlFound)
           break;
   }
}

if(bHtmlFound && gtk_clipboard_wait_is_target_available(clipboard, atomHtmlOther))
{
GtkSelectionData *sel = gtk_clipboard_wait_for_contents(clipboard, atomHtmlOther);
   if(sel){
       gchar *szName = gdk_atom_name(atomHtmlOther); //TOFIX sel->type
       printf("Selected format type: %s\n", szName);
       g_free(szName);

   if(sel->format == 32)
   {
       //assume 32-bit ???!!!!
gchar *pszData = (gchar *)g_ucs4_to_utf8((gunichar *)sel->data, -1, NULL, NULL, NULL);
       ...
   }
}
}



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