13
0

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

This commit is contained in:
Paul Davis 2013-03-20 17:33:25 -04:00
parent 9eaefe3d12
commit 7b998ceba1
2 changed files with 101 additions and 49 deletions

View File

@ -495,15 +495,6 @@ Editor::drop_paths (const RefPtr<Gdk::DragContext>& context,
context->drag_finish (true, false, time);
}
void
Editor::drop_regions (const RefPtr<Gdk::DragContext>& /*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;

View File

@ -1002,63 +1002,124 @@ Editor::canvas_note_event (GdkEvent *event, ArdourCanvas::Item* item)
}
bool
Editor::track_canvas_drag_motion (Glib::RefPtr<Gdk::DragContext> const & /*c*/, int x, int y, guint /*time*/)
Editor::track_canvas_drag_motion (Glib::RefPtr<Gdk::DragContext> const& context, int x, int y, guint time)
{
double wx;
double wy;
boost::shared_ptr<Region> region;
boost::shared_ptr<Region> 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<TimeAxisView*, int> const tv = trackview_by_y_position (py);
std::pair<TimeAxisView*, int> const tv = trackview_by_y_position (py);
if (tv.first == 0) {
return true;
if (tv.first != 0) {
rtav = dynamic_cast<RouteTimeAxisView*> (tv.first);
if (rtav != 0 && rtav->is_track ()) {
region = _regions->get_dragged_region ();
if (region) {
if ((boost::dynamic_pointer_cast<AudioRegion> (region) != 0 &&
dynamic_cast<AudioTimeAxisView*> (tv.first) != 0) ||
(boost::dynamic_pointer_cast<MidiRegion> (region) != 0 &&
dynamic_cast<MidiTimeAxisView*> (tv.first) != 0)) {
/* audio to audio
OR
midi to midi
*/
context->drag_status (context->get_suggested_action(), time);
return true;
}
}
}
RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*> (tv.first);
if (rtav == 0 || !rtav->is_track ()) {
return true;
}
boost::shared_ptr<Region> region = _regions->get_dragged_region ();
if (!region) {
return true;
}
boost::shared_ptr<Region> region_copy = RegionFactory::create (region, true);
if (boost::dynamic_pointer_cast<AudioRegion> (region_copy) != 0 &&
dynamic_cast<AudioTimeAxisView*> (tv.first) == 0) {
/* audio -> non-audio */
return true;
}
if (boost::dynamic_pointer_cast<MidiRegion> (region_copy) != 0 &&
dynamic_cast<MidiTimeAxisView*> (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<Gdk::DragContext>& /*context*/,
int x, int y,
const SelectionData& /*data*/,
guint /*info*/, guint /*time*/)
{
double wx;
double wy;
boost::shared_ptr<Region> region;
boost::shared_ptr<Region> 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<TimeAxisView*, int> const tv = trackview_by_y_position (py);
if (tv.first != 0) {
rtav = dynamic_cast<RouteTimeAxisView*> (tv.first);
if (rtav != 0 && rtav->is_track ()) {
boost::shared_ptr<Region> region = _regions->get_dragged_region ();
if (region) {
region_copy = RegionFactory::create (region, true);
if ((boost::dynamic_pointer_cast<AudioRegion> (region_copy) != 0 &&
dynamic_cast<AudioTimeAxisView*> (tv.first) != 0) ||
(boost::dynamic_pointer_cast<MidiRegion> (region_copy) != 0 &&
dynamic_cast<MidiTimeAxisView*> (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