refXml->get_widget("text", m_text); // m_text is a textview widget //Targets: std::list listTargets; listTargets.push_back( Gtk::TargetEntry("UTF8_STRING") ); m_text->drag_dest_set(listTargets); m_text->signal_drag_data_received().connect(sigc::mem_fun(*this, &SynthesisFrame::on_text_drop_drag_data_received) ); void SynthesisFrame::on_text_drop_drag_data_received(const Glib::RefPtr& context, int, int, const Gtk::SelectionData& selection_data, guint, guint time) { if((selection_data.get_length() >= 0) && (selection_data.get_format() == 8)) { if (selection_data.get_data_type() == "UTF8_STRING") { try { m_text->get_buffer()->set_text(""); //Glib::ustring txt = Glib::file_get_contents( Glib::filename_from_utf8((Glib::filename_from_uri(selection_data.get_data_as_string()))) ); Utils::display_error( *this, "before loading: " + Glib::filename_from_uri(selection_data.get_data_as_string())); Glib::ustring txt; Glib::RefPtr ifile = Glib::IOChannel::create_from_file(Glib::locale_from_utf8(Glib::filename_from_uri(selection_data.get_data_as_string())), "r"); ifile->read_to_end(txt); ifile->close(); m_text->get_buffer()->set_text(txt); std::cout << "Received => "<< selection_data.get_data_type() << std::endl; std::cout << "Received data => "<< selection_data.get_data_as_string() << std::endl; std::cout << "Received content => "<< txt << std::endl; } catch (Glib::ConvertError& e) { Utils::display_error( *this, e.what() ); } catch (Glib::FileError& e) { Utils::display_error( *this, e.what() ); } } else { std::cout << "No Received" << std::endl; } } context->drag_finish(true, true, time); }