X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/blobdiff_plain/3e385dbab78eb0336e82855d829a76a111514a38..d664a4c16bb56138b53e8d6dba92e199bd3ea6c7:/tests/GUI/dndwindow.cc diff --git a/tests/GUI/dndwindow.cc b/tests/GUI/dndwindow.cc index e365208..9aaf567 100644 --- a/tests/GUI/dndwindow.cc +++ b/tests/GUI/dndwindow.cc @@ -26,16 +26,28 @@ DnDWindow::DnDWindow() { set_title("Editor"); + ico_canio = Gdk::Pixbuf::create_from_file("canio.png"); + ico_y = Gdk::Pixbuf::create_from_file("y.png"); + ico_codo = Gdk::Pixbuf::create_from_file("codo.png"); + add(m_HBox); - m_HBox.pack_start(m_VBox); - m_HBox.pack_start(m_WorkPlace); - m_WorkPlace.set_size_request(300, 300); + m_HBox.pack_start(m_VBox, false, false, 0); + + m_VBox.pack_start(m_Button_Canio); + m_VBox.pack_start(m_Button_Y); + m_VBox.pack_start(m_Button_Codo); + + m_HBox.pack_start(scroll); + scroll.add(m_WorkPlace); + scroll.set_size_request(600, 600); + m_WorkPlace.set_size_request(600, 600); //Targets: - std::list listTargets; listTargets.push_back( Gtk::TargetEntry("STRING") ); listTargets.push_back( Gtk::TargetEntry("text/plain") ); + listTargets.push_back( Gtk::TargetEntry("POINTER") ); + listTargets.push_back( Gtk::TargetEntry("application/pointer") ); //Drag site: @@ -53,20 +65,12 @@ DnDWindow::DnDWindow() m_Button_Y.signal_drag_begin().connect( SigC::slot(*this, &DnDWindow::on_y_drag_begin)); m_Button_Codo.signal_drag_begin().connect( SigC::slot(*this, &DnDWindow::on_codo_drag_begin)); - 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: + + //Connect signals: m_WorkPlace.signal_drag_data_received().connect( SigC::slot(*this, &DnDWindow::on_label_drop_drag_data_received) ); - show_all(); } @@ -80,15 +84,28 @@ void DnDWindow::on_item_button_down() std::cout << "boton abajo" << std::endl; } +void DnDWindow::on_canio_drag_begin(const Glib::RefPtr &context) +{ + context->set_icon(ico_canio, 5, 5); //ico_canio->get_width(), ico_canio->get_height()); +} + +void DnDWindow::on_y_drag_begin(const Glib::RefPtr &context) +{ + context->set_icon(ico_y, 5, 5); //ico_canio->get_width(), ico_canio->get_height()); +} + +void DnDWindow::on_codo_drag_begin(const Glib::RefPtr &context) +{ + context->set_icon(ico_codo, 5, 5); //ico_canio->get_width(), ico_canio->get_height()); +} + + + void DnDWindow::on_canio_drag_data_get(const Glib::RefPtr& context, 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. - Glib::RefPtr image; - image = Gdk::Pixbuf::create_from_file("canio.png"); - // Cambio el icono de DND seteando el "hot spot" en el centro. - context->set_icon(image, image->get_width() / 2, image->get_height() / 2); gtk_selection_data_set (selection_data, selection_data->target, 8, (const guchar*)"canio.png", 9); } @@ -110,41 +127,52 @@ void DnDWindow::on_label_drop_drag_data_received(const Glib::RefPtrformat == 10) { + m_WorkPlace.move(*drag_get_source_widget(context), i*32, j*32); + } + + // El Drag es desde la barra de tareas 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); + // Seteo la lista de tipos de drags + a->drag_source_set(listTargets); + // Conecto las señales + a->signal_drag_data_get().connect( SigC::slot(*this, &DnDWindow::on_item_drag_data_get)); + + // Utilizo el SigC::bind para que el callback on_drag_begin acepte un + // parametro extra, en este caso un CItem *. Esto se hace para + // que cuando el usuario quiera mover un item, saber que item es + // y pedirle su ícono para mostrar cono icono durante la operacion, + // Esto va a permitir, que si un widget tiene una imagen rotara o algo + // raro se vea el widget tal cual. + a->signal_drag_begin().connect(SigC::bind( SigC::slot(*this, &DnDWindow::on_item_drag_begin), a)); + a->show(); - //listaItems.push_back(a); + listaItems.push_back(a); } context->drag_finish(false, false, time); } -void DnDWindow::on_canio_drag_begin(const Glib::RefPtr& context) -{ - Glib::RefPtr image; - image = Gdk::Pixbuf::create_from_file("canio.png"); - context->set_icon(image, image->get_width() / 2, image->get_height() / 4); -} - -void DnDWindow::on_y_drag_begin(const Glib::RefPtr& context) +void DnDWindow::on_item_drag_begin(const Glib::RefPtr& context, CItem *item) { - Glib::RefPtr image; - image = Gdk::Pixbuf::create_from_file("y.png"); - context->set_icon(image, image->get_width() / 4, image->get_height() / 4); + context->set_icon(item->get_image(), 5, 5); } -void DnDWindow::on_codo_drag_begin(const Glib::RefPtr& context) +void DnDWindow::on_item_drag_data_get(const Glib::RefPtr& context, GtkSelectionData* selection_data, guint info, guint time) { - Glib::RefPtr image; - image = Gdk::Pixbuf::create_from_file("codo.png"); - context->set_icon(image, 0, 0);//image->get_width() / 2, image->get_height() / 2); + // El 10 creo que es el format + gtk_selection_data_set (selection_data, selection_data->target, 10, (const guchar*)"codo.png", 8); }