--- /dev/null
+## Process this file with automake to produce Makefile.in
+
+INCLUDES = \
+ -DPACKAGE_DATA_DIR=\""$(datadir)"\" \
+ -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
+ @PACKAGE_CFLAGS@
+
+bin_PROGRAMS = drag_and_drop
+
+drag_and_drop_SOURCES = main.cc \
+ dndwindow.cc \
+ dndwindow.h \
+ item.cc \
+ item.h
+
+drag_and_drop_LDADD = @PACKAGE_LIBS@
+
+
--- /dev/null
+dnl Process this file with autoconf to produce a configure script.
+
+AC_INIT(configure.in)
+AM_INIT_AUTOMAKE(drag_and_drop, 0.1)
+AM_MAINTAINER_MODE
+
+GNOME_COMMON_INIT
+
+AC_ISC_POSIX
+AC_PROG_CXX
+AM_PROG_CC_STDC
+AC_HEADER_STDC
+
+pkg_modules="libgnomeui-2.0"
+PKG_CHECK_MODULES(PACKAGE,
+ gtkmm-2.0 >= 2.0.0 )
+AC_SUBST(PACKAGE_CFLAGS)
+AC_SUBST(PACKAGE_LIBS)
+
+AC_OUTPUT([
+Makefile
+])
+
--- /dev/null
+//$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);
+}
+
--- /dev/null
+//$Id: dndwindow.h 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
+ */
+
+#ifndef GTKMM_EXAMPLE_DNDWINDOW_H
+#define GTKMM_EXAMPLE_DNDWINDOW_H
+
+#include <gtkmm/label.h>
+#include <gtkmm/window.h>
+#include <gtkmm/box.h>
+#include <gtkmm/button.h>
+#include <gtkmm/fixed.h>
+#include "item.h"
+
+class DnDWindow : public Gtk::Window
+{
+
+public:
+ DnDWindow();
+ virtual ~DnDWindow();
+
+protected:
+ //Signal handlers:
+ virtual void on_canio_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time);
+ virtual void on_y_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time);
+ virtual void on_codo_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time);
+ virtual void on_label_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, GtkSelectionData* selection_data, guint info, guint time);
+
+
+ void on_item_button_down();
+ //Member widgets:
+ Gtk::HBox m_HBox;
+ Gtk::VBox m_VBox;
+ Gtk::Button m_Button_Canio;
+ Gtk::Button m_Button_Y;
+ Gtk::Button m_Button_Codo;
+ Gtk::Fixed m_WorkPlace;
+ std::list<CItem *> listaItems;
+};
+
+#endif // GTKMM_EXAMPLE_DNDWINDOW_H
--- /dev/null
+
+
+#include "item.h"
+#include <iostream>
+
+CItem::CItem(const char *filename):Gtk::DrawingArea()
+{
+ std::cout << "CItem::CItem() -> Usando " << filename << std::endl;
+ image = Gdk::Pixbuf::create_from_file(filename);
+
+ std::cout << "CItem::CItem() -> w = " << image->get_width() << " h = " << image->get_height() << std::endl;
+ set_size_request(image->get_width(), image->get_height());
+}
+
+CItem::~CItem()
+{
+}
+
+bool CItem::on_expose_event(GdkEventExpose* event)
+{
+ image->render_to_drawable(get_window(), get_style()->get_black_gc(), \
+ 0, 0, 0, 0, image->get_width(), image->get_height(), Gdk::RGB_DITHER_NONE, 0, 0);
+
+ Gtk::DrawingArea::on_expose_event(event);
+ return true;
+}
+
+
--- /dev/null
+
+
+#ifndef GTKMM_EXAMPLE_DRAWINGAREALINES_H
+#define GTKMM_EXAMPLE_DRAWINGAREALINES_H
+
+#include <gtkmm/drawingarea.h>
+#include <gdkmm.h>
+
+//Custom drawing area with modified expose_event.
+class CItem:public Gtk::DrawingArea {
+public:
+ CItem(const char *filename);
+ ~CItem();
+ bool on_expose_event(GdkEventExpose* event);
+private:
+ Glib::RefPtr<Gdk::Pixbuf> image;
+};
+
+#endif //GTKMM_EXAMPLE_DRAWINGAREALINES_H
+
--- /dev/null
+//$Id: main.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 <gtkmm/main.h>
+#include "dndwindow.h"
+
+int main (int argc, char *argv[])
+{
+ Gtk::Main kit(argc, argv);
+
+ DnDWindow dndWindow;
+ Gtk::Main::run(dndWindow); //Shows the window and returns when it is closed.
+
+ return 0;
+}