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));
51 // Señales para cambiar el icono cuando empieza el drag.
52 m_Button_Canio.signal_drag_begin().connect( SigC::slot(*this, &DnDWindow::on_canio_drag_begin));
53 m_Button_Y.signal_drag_begin().connect( SigC::slot(*this, &DnDWindow::on_y_drag_begin));
54 m_Button_Codo.signal_drag_begin().connect( SigC::slot(*this, &DnDWindow::on_codo_drag_begin));
56 m_VBox.pack_start(m_Button_Canio);
57 m_VBox.pack_start(m_Button_Y);
58 m_VBox.pack_start(m_Button_Codo);
63 //Make m_Label_Drop a DnD drop destination:
64 m_WorkPlace.drag_dest_set(listTargets);
67 m_WorkPlace.signal_drag_data_received().connect( SigC::slot(*this, &DnDWindow::on_label_drop_drag_data_received) );
73 DnDWindow::~DnDWindow()
77 // Boton presionado en el codo
78 void DnDWindow::on_item_button_down()
80 std::cout << "boton abajo" << std::endl;
84 void DnDWindow::on_canio_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint, guint)
86 //TODO: The gtkmm API needs to change to use a Gtk::SelectionData instead of a GtkSelectionData.
87 //That should happen for gtkmm 2.4.
88 Glib::RefPtr<Gdk::Pixbuf> image;
89 image = Gdk::Pixbuf::create_from_file("canio.png");
90 // Cambio el icono de DND seteando el "hot spot" en el centro.
91 context->set_icon(image, image->get_width() / 2, image->get_height() / 2);
92 gtk_selection_data_set (selection_data, selection_data->target, 8, (const guchar*)"canio.png", 9);
95 void DnDWindow::on_y_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*)"y.png", 5);
102 void DnDWindow::on_codo_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, GtkSelectionData* selection_data, guint, guint)
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.
106 gtk_selection_data_set (selection_data, selection_data->target, 8, (const guchar*)"codo.png", 8);
109 void DnDWindow::on_label_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, GtkSelectionData* selection_data, guint, guint time)
111 //TODO: The gtkmm API needs to change to use a Gtk::SelectionData instead of a GtkSelectionData.
112 //That should happen for gtkmm 2.4.
114 if ((selection_data->length >= 0) && (selection_data->format == 8))
116 CItem *a = Gtk::manage( new CItem((const char *)selection_data->data) );
117 /* Ajusto coordenada x e y para que caigan en un lugar de una cuadricula de
122 m_WorkPlace.put(*a, i*32, j*32);
124 //listaItems.push_back(a);
127 context->drag_finish(false, false, time);
130 void DnDWindow::on_canio_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
132 Glib::RefPtr<Gdk::Pixbuf> image;
133 image = Gdk::Pixbuf::create_from_file("canio.png");
134 context->set_icon(image, image->get_width() / 2, image->get_height() / 4);
137 void DnDWindow::on_y_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
139 Glib::RefPtr<Gdk::Pixbuf> image;
140 image = Gdk::Pixbuf::create_from_file("y.png");
141 context->set_icon(image, image->get_width() / 4, image->get_height() / 4);
144 void DnDWindow::on_codo_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
146 Glib::RefPtr<Gdk::Pixbuf> image;
147 image = Gdk::Pixbuf::create_from_file("codo.png");
148 context->set_icon(image, 0, 0);//image->get_width() / 2, image->get_height() / 2);