1 //$Id: dndwindow.cc 5 2003-10-10 04:31:35Z luca $ -*- c++ -*-
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_Canio("Drag Canio\n"),
24 m_Button_Y("Drop Y\n"),
25 m_Button_Codo("Drag Codo\n")
31 m_HBox.pack_start(m_VBox);
32 m_HBox.pack_start(m_WorkPlace);
33 m_WorkPlace.set_size_request(300, 300);
36 std::list<Gtk::TargetEntry> listTargets;
37 listTargets.push_back( Gtk::TargetEntry("STRING") );
38 listTargets.push_back( Gtk::TargetEntry("text/plain") );
42 //Make m_Button_Drag a DnD drag source:
43 m_Button_Canio.drag_source_set(listTargets);
44 m_Button_Y.drag_source_set(listTargets);
45 m_Button_Codo.drag_source_set(listTargets);
48 m_Button_Canio.signal_drag_data_get().connect( SigC::slot(*this, &DnDWindow::on_canio_drag_data_get));
49 m_Button_Y.signal_drag_data_get().connect( SigC::slot(*this, &DnDWindow::on_y_drag_data_get));
50 m_Button_Codo.signal_drag_data_get().connect( SigC::slot(*this, &DnDWindow::on_codo_drag_data_get));
53 m_VBox.pack_start(m_Button_Canio);
54 m_VBox.pack_start(m_Button_Y);
55 m_VBox.pack_start(m_Button_Codo);
60 //Make m_Label_Drop a DnD drop destination:
61 m_WorkPlace.drag_dest_set(listTargets);
64 m_WorkPlace.signal_drag_data_received().connect( SigC::slot(*this, &DnDWindow::on_label_drop_drag_data_received) );
70 DnDWindow::~DnDWindow()
74 // Boton presionado en el codo
75 void DnDWindow::on_item_button_down()
77 std::cout << "boton abajo" << std::endl;
81 void DnDWindow::on_canio_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, GtkSelectionData* selection_data, guint, guint)
83 //TODO: The gtkmm API needs to change to use a Gtk::SelectionData instead of a GtkSelectionData.
84 //That should happen for gtkmm 2.4.
85 gtk_selection_data_set (selection_data, selection_data->target, 8, (const guchar*)"canio.png", 9);
88 void DnDWindow::on_y_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, GtkSelectionData* selection_data, guint, guint)
90 //TODO: The gtkmm API needs to change to use a Gtk::SelectionData instead of a GtkSelectionData.
91 //That should happen for gtkmm 2.4.
92 gtk_selection_data_set (selection_data, selection_data->target, 8, (const guchar*)"y.png", 5);
95 void DnDWindow::on_codo_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, GtkSelectionData* selection_data, guint, guint)
97 //TODO: The gtkmm API needs to change to use a Gtk::SelectionData instead of a GtkSelectionData.
98 //That should happen for gtkmm 2.4.
99 gtk_selection_data_set (selection_data, selection_data->target, 8, (const guchar*)"codo.png", 8);
102 void DnDWindow::on_label_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, GtkSelectionData* selection_data, guint, guint time)
104 //TODO: The gtkmm API needs to change to use a Gtk::SelectionData instead of a GtkSelectionData.
105 //That should happen for gtkmm 2.4.
107 if ((selection_data->length >= 0) && (selection_data->format == 8))
109 CItem *a = Gtk::manage( new CItem((const char *)selection_data->data) );
110 /* Ajusto coordenada x e y para que caigan en un lugar de una cuadricula de
115 m_WorkPlace.put(*a, i*32, j*32);
117 //listaItems.push_back(a);
120 context->drag_finish(false, false, time);