3 /* gtkmm example Copyright (C) 2002 gtkmm development team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "dndwindow.h"
22 DnDWindow::DnDWindow()
23 : m_Button_Drag("Drag Here\n"),
24 m_Label_Drop("Drop here\n")
26 set_title("DnD example");
31 std::list<Gtk::TargetEntry> listTargets;
32 listTargets.push_back( Gtk::TargetEntry("STRING") );
33 listTargets.push_back( Gtk::TargetEntry("text/plain") );
37 //Make m_Button_Drag a DnD drag source:
38 m_Button_Drag.drag_source_set(listTargets);
41 m_Button_Drag.signal_drag_data_get().connect( SigC::slot(*this, &DnDWindow::on_button_drag_data_get));
43 m_HBox.pack_start(m_Button_Drag);
47 //Make m_Label_Drop a DnD drop destination:
48 m_Label_Drop.drag_dest_set(listTargets);
51 m_Label_Drop.signal_drag_data_received().connect( SigC::slot(*this, &DnDWindow::on_label_drop_drag_data_received) );
53 m_HBox.pack_start(m_Label_Drop);
58 DnDWindow::~DnDWindow()
62 void DnDWindow::on_button_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, GtkSelectionData* selection_data, guint, guint)
64 //TODO: The gtkmm API needs to change to use a Gtk::SelectionData instead of a GtkSelectionData.
65 //That should happen for gtkmm 2.4.
67 gtk_selection_data_set (selection_data, selection_data->target, 8, (const guchar*)"I'm Data!", 9);
70 void DnDWindow::on_label_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int, int, GtkSelectionData* selection_data, guint, guint time)
72 //TODO: The gtkmm API needs to change to use a Gtk::SelectionData instead of a GtkSelectionData.
73 //That should happen for gtkmm 2.4.
75 if ((selection_data->length >= 0) && (selection_data->format == 8))
77 std::cout << "Received \"" << (gchar *)(selection_data->data) << "\" in label " << std::endl;
80 context->drag_finish(false, false, time);