From 7b998ceba1f6f0af601d69432d8e15e09530b347 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 20 Mar 2013 17:33:25 -0400 Subject: [PATCH] fix an old bug introduced when cth tried (valiantly) to make region-list -> DnD -> canvas behave like a regular region drag. this doesnt' work because the RegionInsertDrag() grabs the mouse and breaks the DnD. in addition, the code failed to correctly indicate when a drop was possible (over a Track) and when it was not (over a Bus) - this has also been fixed. the actual code in Editor::drop_regions() could and should be simplified - no reason to use a RegionInsertDrag here, but it was fast --- gtk2_ardour/editor_canvas.cc | 9 -- gtk2_ardour/editor_canvas_events.cc | 141 ++++++++++++++++++++-------- 2 files changed, 101 insertions(+), 49 deletions(-) diff --git a/gtk2_ardour/editor_canvas.cc b/gtk2_ardour/editor_canvas.cc index ec5f4c50e5..383241aec0 100644 --- a/gtk2_ardour/editor_canvas.cc +++ b/gtk2_ardour/editor_canvas.cc @@ -495,15 +495,6 @@ Editor::drop_paths (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*/) -{ - _drags->end_grab (0); -} - /** If the editor window is arranged such that the edge of the trackview is right up * against the edge of the screen, autoscroll will not work very well. In this situation, * we start autoscrolling some distance in from the right-hand-side of the screen edge; diff --git a/gtk2_ardour/editor_canvas_events.cc b/gtk2_ardour/editor_canvas_events.cc index 9d092ebc8f..631137fd2f 100644 --- a/gtk2_ardour/editor_canvas_events.cc +++ b/gtk2_ardour/editor_canvas_events.cc @@ -1002,63 +1002,124 @@ Editor::canvas_note_event (GdkEvent *event, ArdourCanvas::Item* item) } bool -Editor::track_canvas_drag_motion (Glib::RefPtr const & /*c*/, int x, int y, guint /*time*/) +Editor::track_canvas_drag_motion (Glib::RefPtr const& context, int x, int y, guint time) { double wx; double wy; + boost::shared_ptr region; + boost::shared_ptr region_copy; + RouteTimeAxisView* rtav; + GdkEvent event; + double px; + double py; + + string target = track_canvas->drag_dest_find_target (context, track_canvas->drag_dest_get_target_list()); + + if (target.empty()) { + return false; + } + track_canvas->window_to_world (x, y, wx, wy); - GdkEvent event; event.type = GDK_MOTION_NOTIFY; event.button.x = wx; event.button.y = wy; /* assume we're dragging with button 1 */ event.motion.state = Gdk::BUTTON1_MASK; - if (!_drags->active ()) { + (void) event_frame (&event, &px, &py); - double px; - double py; - framepos_t const pos = event_frame (&event, &px, &py); + std::pair const tv = trackview_by_y_position (py); - std::pair const tv = trackview_by_y_position (py); - if (tv.first == 0) { - return true; + if (tv.first != 0) { + + rtav = dynamic_cast (tv.first); + + if (rtav != 0 && rtav->is_track ()) { + + region = _regions->get_dragged_region (); + + if (region) { + + if ((boost::dynamic_pointer_cast (region) != 0 && + dynamic_cast (tv.first) != 0) || + (boost::dynamic_pointer_cast (region) != 0 && + dynamic_cast (tv.first) != 0)) { + + /* audio to audio + OR + midi to midi + */ + + context->drag_status (context->get_suggested_action(), time); + return true; + } + } } - - RouteTimeAxisView* rtav = dynamic_cast (tv.first); - if (rtav == 0 || !rtav->is_track ()) { - return true; - } - - boost::shared_ptr region = _regions->get_dragged_region (); - - if (!region) { - return true; - } - - boost::shared_ptr region_copy = RegionFactory::create (region, true); - - if (boost::dynamic_pointer_cast (region_copy) != 0 && - dynamic_cast (tv.first) == 0) { - - /* audio -> non-audio */ - return true; - } - - if (boost::dynamic_pointer_cast (region_copy) != 0 && - dynamic_cast (tv.first) == 0) { - - /* MIDI -> non-MIDI */ - return true; - } - - _drags->set (new RegionInsertDrag (this, region_copy, rtav, pos), &event); } - _drags->motion_handler (&event, false); + /* no drop here */ + context->drag_status (Gdk::DragAction (0), time); + return false; +} - return true; +void +Editor::drop_regions (const Glib::RefPtr& /*context*/, + int x, int y, + const SelectionData& /*data*/, + guint /*info*/, guint /*time*/) +{ + double wx; + double wy; + boost::shared_ptr region; + boost::shared_ptr region_copy; + RouteTimeAxisView* rtav; + GdkEvent event; + double px; + double py; + + track_canvas->window_to_world (x, y, wx, wy); + + event.type = GDK_MOTION_NOTIFY; + event.button.x = wx; + event.button.y = wy; + /* assume we're dragging with button 1 */ + event.motion.state = Gdk::BUTTON1_MASK; + + framepos_t const pos = event_frame (&event, &px, &py); + + std::pair const tv = trackview_by_y_position (py); + + if (tv.first != 0) { + + rtav = dynamic_cast (tv.first); + + if (rtav != 0 && rtav->is_track ()) { + + boost::shared_ptr region = _regions->get_dragged_region (); + + if (region) { + + region_copy = RegionFactory::create (region, true); + + + if ((boost::dynamic_pointer_cast (region_copy) != 0 && + dynamic_cast (tv.first) != 0) || + (boost::dynamic_pointer_cast (region_copy) != 0 && + dynamic_cast (tv.first) != 0)) { + + /* audio to audio + OR + midi to midi + */ + + + _drags->set (new RegionInsertDrag (this, region_copy, rtav, pos), &event); + _drags->end_grab (0); + } + } + } + } } bool