From 9d44c3b97187fc63eb6dcfba353c07b7b501ffb3 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 30 Dec 2005 20:38:41 +0000 Subject: [PATCH] drag-n-drop to canvas from region list works git-svn-id: svn://localhost/trunk/ardour2@218 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/editor.h | 16 ++++++++++- gtk2_ardour/editor_canvas.cc | 40 +++++++++++++++++++++++++- gtk2_ardour/editor_ops.cc | 4 +-- libs/gtkmm2ext/gtkmm2ext/dndtreeview.h | 20 ++++++++----- 4 files changed, 68 insertions(+), 12 deletions(-) diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index 25ff94c561..480a7f1cb7 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -902,7 +902,7 @@ class Editor : public PublicEditor void amplitude_zoom (gdouble scale); void amplitude_zoom_step (bool in); - void insert_region_list_drag (ARDOUR::AudioRegion&); + void insert_region_list_drag (ARDOUR::AudioRegion&, int x, int y); void insert_region_list_selection (float times); void insert_sndfile (bool as_tracks); @@ -1547,6 +1547,20 @@ class Editor : public PublicEditor guint time); + void drop_paths (const Glib::RefPtr& context, + gint x, + gint y, + const Gtk::SelectionData& data, + guint info, + guint time); + + void drop_regions (const Glib::RefPtr& context, + gint x, + gint y, + const Gtk::SelectionData& data, + guint info, + guint time); + /* audio export */ ExportDialog *export_dialog; diff --git a/gtk2_ardour/editor_canvas.cc b/gtk2_ardour/editor_canvas.cc index 8e91715576..8b496f170f 100644 --- a/gtk2_ardour/editor_canvas.cc +++ b/gtk2_ardour/editor_canvas.cc @@ -21,6 +21,8 @@ #include #include +#include + #include "ardour_ui.h" #include "editor.h" #include "waveview.h" @@ -95,9 +97,12 @@ Editor::initialize_canvas () track_canvas.signal_leave_notify_event().connect (mem_fun(*this, &Editor::left_track_canvas)); /* set up drag-n-drop */ + vector target_table; - target_table.push_back (TargetEntry ("STRING")); + // Drag-N-Drop from the region list can generate this target + target_table.push_back (TargetEntry ("regions")); + target_table.push_back (TargetEntry ("text/plain")); target_table.push_back (TargetEntry ("text/uri-list")); target_table.push_back (TargetEntry ("application/x-rootwin-drop")); @@ -404,6 +409,19 @@ Editor::track_canvas_drag_data_received (const RefPtr& context int x, int y, const SelectionData& data, guint info, guint time) +{ + if (data.get_target() == "regions") { + drop_regions (context, x, y, data, info, time); + } else { + drop_paths (context, x, y, data, info, time); + } +} + +void +Editor::drop_paths (const RefPtr& context, + int x, int y, + const SelectionData& data, + guint info, guint time) { TimeAxisView* tvp; AudioTimeAxisView* tv; @@ -457,3 +475,23 @@ Editor::track_canvas_drag_data_received (const RefPtr& context context->drag_finish (true, false, time); } +void +Editor::drop_regions (const RefPtr& context, + int x, int y, + const SelectionData& data, + guint info, guint time) +{ + const DnDTreeView::SerializedObjectPointers* sr = reinterpret_cast (data.get_data()); + + for (uint32_t i = 0; i < sr->cnt; ++i) { + + Region* r = reinterpret_cast (sr->ptr[i]); + AudioRegion* ar; + + if ((ar = dynamic_cast(r)) != 0) { + insert_region_list_drag (*ar, x, y); + } + } + + context->drag_finish (true, false, time); +} diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index a4f3ffd02a..a971a17750 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -1458,9 +1458,8 @@ Editor::clear_locations () /* INSERT/REPLACE */ void -Editor::insert_region_list_drag (AudioRegion& region) +Editor::insert_region_list_drag (AudioRegion& region, int x, int y) { - int x, y; double wx, wy; double cx, cy; TimeAxisView *tv; @@ -1468,7 +1467,6 @@ Editor::insert_region_list_drag (AudioRegion& region) AudioTimeAxisView *atv = 0; Playlist *playlist; - track_canvas.get_pointer (x, y); track_canvas.window_to_world (x, y, wx, wy); GdkEvent event; diff --git a/libs/gtkmm2ext/gtkmm2ext/dndtreeview.h b/libs/gtkmm2ext/gtkmm2ext/dndtreeview.h index bc7a2df10f..d1c2bc4659 100644 --- a/libs/gtkmm2ext/gtkmm2ext/dndtreeview.h +++ b/libs/gtkmm2ext/gtkmm2ext/dndtreeview.h @@ -16,6 +16,19 @@ class DnDTreeView : public Gtk::TreeView public: DnDTreeView (); ~DnDTreeView() {} + + /* this is the structure pointed to if add_object_drag() is called + and a drop happens on a destination which has declared itself + willing to accept a target of the type named in the call + to add_object_drag(). + */ + + struct SerializedObjectPointers { + uint32_t size; + uint32_t cnt; + char type[32]; + void* ptr[0]; + }; void add_drop_targets (std::list&); void add_object_drag (int column, std::string type_name); @@ -51,13 +64,6 @@ class DnDTreeView : public Gtk::TreeView Gdk::DragAction suggested_action; int data_column; - struct SerializedObjectPointers { - uint32_t size; - uint32_t cnt; - char type[32]; - void* ptr[0]; - }; - SerializedObjectPointers* serialize_pointers (Glib::RefPtr m, Gtk::TreeSelection::ListHandle_Path*, Glib::ustring type);