+//$Id: dndwindow.cc 5 2003-10-10 04:31:35Z luca $ -*- c++ -*-
+
+/* gtkmm example Copyright (C) 2002 gtkmm development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "dndwindow.h"
+#include <iostream>
+
+DnDWindow::DnDWindow()
+: m_Button_Canio("Drag Canio\n"),
+ m_Button_Y("Drop Y\n"),
+ m_Button_Codo("Drag Codo\n")
+{
+ set_title("Editor");
+
+ add(m_HBox);
+
+ m_HBox.pack_start(m_VBox);
+ m_HBox.pack_start(m_WorkPlace);
+ m_WorkPlace.set_size_request(300, 300);
+
+ //Targets:
+ std::list<Gtk::TargetEntry> listTargets;
+ listTargets.push_back( Gtk::TargetEntry("STRING") );
+ listTargets.push_back( Gtk::TargetEntry("text/plain") );
+
+ //Drag site:
+
+ //Make m_Button_Drag a DnD drag source:
+ m_Button_Canio.drag_source_set(listTargets);
+ m_Button_Y.drag_source_set(listTargets);
+ m_Button_Codo.drag_source_set(listTargets);
+
+ //Connect signals:
+ m_Button_Canio.signal_drag_data_get().connect( SigC::slot(*this, &DnDWindow::on_canio_drag_data_get));
+ m_Button_Y.signal_drag_data_get().connect( SigC::slot(*this, &DnDWindow::on_y_drag_data_get));
+ m_Button_Codo.signal_drag_data_get().connect( SigC::slot(*this, &DnDWindow::on_codo_drag_data_get));
+
+
+ m_VBox.pack_start(m_Button_Canio);
+ m_VBox.pack_start(m_Button_Y);
+ m_VBox.pack_start(m_Button_Codo);
+
+
+ //Drop site:
+
+ //Make m_Label_Drop a DnD drop destination:
+ m_WorkPlace.drag_dest_set(listTargets);
+
+ //Connect signals:
+ m_WorkPlace.signal_drag_data_received().connect( SigC::slot(*this, &DnDWindow::on_label_drop_drag_data_received) );
+
+
+ show_all();
+}
+
+DnDWindow::~DnDWindow()
+{
+}
+
+// Boton presionado en el codo
+void DnDWindow::on_item_button_down()
+{
+ std::cout << "boton abajo" << std::endl;
+}
+
+
+void DnDWindow::on_canio_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, GtkSelectionData* selection_data, guint, guint)
+{
+ //TODO: The gtkmm API needs to change to use a Gtk::SelectionData instead of a GtkSelectionData.
+ //That should happen for gtkmm 2.4.
+ gtk_selection_data_set (selection_data, selection_data->target, 8, (const guchar*)"canio.png", 9);
+}
+
+void DnDWindow::on_y_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, GtkSelectionData* selection_data, guint, guint)
+{
+ //TODO: The gtkmm API needs to change to use a Gtk::SelectionData instead of a GtkSelectionData.
+ //That should happen for gtkmm 2.4.
+ gtk_selection_data_set (selection_data, selection_data->target, 8, (const guchar*)"y.png", 5);
+}
+
+void DnDWindow::on_codo_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, GtkSelectionData* selection_data, guint, guint)
+{
+ //TODO: The gtkmm API needs to change to use a Gtk::SelectionData instead of a GtkSelectionData.
+ //That should happen for gtkmm 2.4.
+ gtk_selection_data_set (selection_data, selection_data->target, 8, (const guchar*)"codo.png", 8);
+}
+
+void DnDWindow::on_label_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, GtkSelectionData* selection_data, guint, guint time)
+{
+ //TODO: The gtkmm API needs to change to use a Gtk::SelectionData instead of a GtkSelectionData.
+ //That should happen for gtkmm 2.4.
+
+ if ((selection_data->length >= 0) && (selection_data->format == 8))
+ {
+ CItem *a = Gtk::manage( new CItem((const char *)selection_data->data) );
+ /* Ajusto coordenada x e y para que caigan en un lugar de una cuadricula de
+ * 32x32 */
+ int i,j;
+ i = x/32;
+ j = y/32;
+ m_WorkPlace.put(*a, i*32, j*32);
+ a->show();
+ //listaItems.push_back(a);
+ }
+
+ context->drag_finish(false, false, time);
+}
+