-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 05/17/2011 09:07 AM, Thibault Duponchelle wrote: > 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 ?
Nothing is wrong with your code, except the ugly hack.. You probably need to do something like list gchar **list; gint i = 0; list = g_uri_list_extract_uris((const gchar *) gtk_selection_data_get_data(selection_data)); if (list) { while (list[i] != NULL) { filename = g_filename_from_uri(list[i], NULL, NULL); i++' } g_strfreev(list) } Hope that helps, Kevin - -- Get my public GnuPG key from http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x7D0BD5D1 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/ iEYEARECAAYFAk3SkskACgkQ6w2kMH0L1dGXxwCdHiTVdz796H3FiqA1jupl31ng K7YAn0iOKD9tYV7XawHSlPnreXqGNPf4 =z5uz -----END PGP SIGNATURE----- _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list