gtk_selection_data_get_text on drag and drop



Hi,

I have a question about drag and drop handling.

Currently, I've add this code to handle drag and drop :

gtk_drag_dest_set(emuwin, GTK_DEST_DEFAULT_ALL, NULL, 0, GDK_ACTION_COPY);
gtk_drag_dest_add_text_targets(emuwin);
g_signal_connect(emuwin, "drag-data-received", G_CALLBACK(on_drag_and_drop),
ewin);


And my callback function :

/* Callback function for the drag and drop event */
gboolean on_drag_and_drop(G_GNUC_UNUSED GtkWidget *win, G_GNUC_UNUSED
GdkDragContext *dc, G_GNUC_UNUSED gint x, G_GNUC_UNUSED gint y,
G_GNUC_UNUSED GtkSelectionData *data, G_GNUC_UNUSED guint info,
G_GNUC_UNUSED guint t, TilemEmulatorWindow * ewin) {

        printf("drag and drop !!\n");
        char* filename = (char*)gtk_selection_data_get_text(data);  // The
problem is not the "cast"
        load_file_from_file(ewin->emu, filename );
        return FALSE;
}

But when I try to use this code, filename looks like this
file:///home/tib/foo.txt\r\n  (escaped characters \r\n are only visible when
I use gdb).
I've tried to do not cast gtk_selection_data_get_text return value but same
problem.

So to really get a correct filename I must do an ugly hack :

filename = filename + 7;
int size = strlen(filename);
filename[size - 2] = '\0';

So my question is what's wrong in my code...?
Or maybe there's a glib function I should use ?
Maybe I should use "gtk_drag_get_data"  then "gdk_drag_get_selection" and
use GdkAtom ?

Please help ;)

Thank you by advance.

Regards.

Thibault Duponchelle



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