From 210d55e8a677248959b0564c1a2942f6b3aebe3d Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Fri, 10 Oct 2003 04:31:35 +0000 Subject: [PATCH] Se agrega ejemplo de DND. --- tests/gtkmm/dnd/Makefile.am | 5 ++ tests/gtkmm/dnd/dndwindow.cc | 81 ++++++++++++++++++++++++++ tests/gtkmm/dnd/dndwindow.h | 45 ++++++++++++++ tests/gtkmm/dnd/main.cc | 30 ++++++++++ tests/{ => gtkmm}/gtkmm.cpp | 0 tests/{ => gtkmm}/gtkmm_hello.cpp | 0 tests/{ => gtkmm}/gtkmm_hello.h | 0 tests/{ => gtkmm}/gtkmm_hello_main.cpp | 0 8 files changed, 161 insertions(+) create mode 100644 tests/gtkmm/dnd/Makefile.am create mode 100644 tests/gtkmm/dnd/dndwindow.cc create mode 100644 tests/gtkmm/dnd/dndwindow.h create mode 100644 tests/gtkmm/dnd/main.cc rename tests/{ => gtkmm}/gtkmm.cpp (100%) rename tests/{ => gtkmm}/gtkmm_hello.cpp (100%) rename tests/{ => gtkmm}/gtkmm_hello.h (100%) rename tests/{ => gtkmm}/gtkmm_hello_main.cpp (100%) diff --git a/tests/gtkmm/dnd/Makefile.am b/tests/gtkmm/dnd/Makefile.am new file mode 100644 index 0000000..5797489 --- /dev/null +++ b/tests/gtkmm/dnd/Makefile.am @@ -0,0 +1,5 @@ +include $(top_srcdir)/examples/Makefile.am_fragment + +#Build the executable, but don't install it. +noinst_PROGRAMS = drag_and_drop +drag_and_drop_SOURCES = dndwindow.h dndwindow.cc main.cc diff --git a/tests/gtkmm/dnd/dndwindow.cc b/tests/gtkmm/dnd/dndwindow.cc new file mode 100644 index 0000000..c9f444e --- /dev/null +++ b/tests/gtkmm/dnd/dndwindow.cc @@ -0,0 +1,81 @@ +//$Id$ -*- 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 + +DnDWindow::DnDWindow() +: m_Button_Drag("Drag Here\n"), + m_Label_Drop("Drop here\n") +{ + set_title("DnD example"); + + add(m_HBox); + + //Targets: + std::list 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_Drag.drag_source_set(listTargets); + + //Connect signals: + m_Button_Drag.signal_drag_data_get().connect( SigC::slot(*this, &DnDWindow::on_button_drag_data_get)); + + m_HBox.pack_start(m_Button_Drag); + + //Drop site: + + //Make m_Label_Drop a DnD drop destination: + m_Label_Drop.drag_dest_set(listTargets); + + //Connect signals: + m_Label_Drop.signal_drag_data_received().connect( SigC::slot(*this, &DnDWindow::on_label_drop_drag_data_received) ); + + m_HBox.pack_start(m_Label_Drop); + + show_all(); +} + +DnDWindow::~DnDWindow() +{ +} + +void DnDWindow::on_button_drag_data_get(const Glib::RefPtr&, 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*)"I'm Data!", 9); +} + +void DnDWindow::on_label_drop_drag_data_received(const Glib::RefPtr& context, int, int, 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)) + { + std::cout << "Received \"" << (gchar *)(selection_data->data) << "\" in label " << std::endl; + } + + context->drag_finish(false, false, time); +} diff --git a/tests/gtkmm/dnd/dndwindow.h b/tests/gtkmm/dnd/dndwindow.h new file mode 100644 index 0000000..afb486f --- /dev/null +++ b/tests/gtkmm/dnd/dndwindow.h @@ -0,0 +1,45 @@ +//$Id$ -*- 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 +#include +#include +#include + +class DnDWindow : public Gtk::Window +{ + +public: + DnDWindow(); + virtual ~DnDWindow(); + +protected: + //Signal handlers: + virtual void on_button_drag_data_get(const Glib::RefPtr& context, GtkSelectionData* selection_data, guint info, guint time); + virtual void on_label_drop_drag_data_received(const Glib::RefPtr& context, int x, int y, GtkSelectionData* selection_data, guint info, guint time); + + //Member widgets: + Gtk::HBox m_HBox; + Gtk::Button m_Button_Drag; + Gtk::Label m_Label_Drop; +}; + +#endif // GTKMM_EXAMPLE_DNDWINDOW_H diff --git a/tests/gtkmm/dnd/main.cc b/tests/gtkmm/dnd/main.cc new file mode 100644 index 0000000..913295f --- /dev/null +++ b/tests/gtkmm/dnd/main.cc @@ -0,0 +1,30 @@ +//$Id$ -*- 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 +#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; +} diff --git a/tests/gtkmm.cpp b/tests/gtkmm/gtkmm.cpp similarity index 100% rename from tests/gtkmm.cpp rename to tests/gtkmm/gtkmm.cpp diff --git a/tests/gtkmm_hello.cpp b/tests/gtkmm/gtkmm_hello.cpp similarity index 100% rename from tests/gtkmm_hello.cpp rename to tests/gtkmm/gtkmm_hello.cpp diff --git a/tests/gtkmm_hello.h b/tests/gtkmm/gtkmm_hello.h similarity index 100% rename from tests/gtkmm_hello.h rename to tests/gtkmm/gtkmm_hello.h diff --git a/tests/gtkmm_hello_main.cpp b/tests/gtkmm/gtkmm_hello_main.cpp similarity index 100% rename from tests/gtkmm_hello_main.cpp rename to tests/gtkmm/gtkmm_hello_main.cpp -- 2.43.0