summaryrefslogtreecommitdiff
path: root/gtk2_ardour/editor_canvas_events.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2013-03-20 17:33:25 -0400
committerPaul Davis <paul@linuxaudiosystems.com>2013-03-20 17:33:25 -0400
commit7b998ceba1f6f0af601d69432d8e15e09530b347 (patch)
treec9bd2cd4539339904484bc9ff88a0c169a8530a1 /gtk2_ardour/editor_canvas_events.cc
parent9eaefe3d12dbd5ca7e6a08a3fd9e781d2b569f1b (diff)
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
Diffstat (limited to 'gtk2_ardour/editor_canvas_events.cc')
-rw-r--r--gtk2_ardour/editor_canvas_events.cc125
1 files changed, 93 insertions, 32 deletions
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<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) {
- RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*> (tv.first);
- if (rtav == 0 || !rtav->is_track ()) {
- return true;
- }
+ rtav = dynamic_cast<RouteTimeAxisView*> (tv.first);
+
+ if (rtav != 0 && rtav->is_track ()) {
- boost::shared_ptr<Region> region = _regions->get_dragged_region ();
+ 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)) {
- if (!region) {
- return true;
+ /* audio to audio
+ OR
+ midi to midi
+ */
+
+ context->drag_status (context->get_suggested_action(), time);
+ return true;
+ }
+ }
}
+ }
- boost::shared_ptr<Region> region_copy = RegionFactory::create (region, true);
+ /* no drop here */
+ context->drag_status (Gdk::DragAction (0), time);
+ return false;
+}
- if (boost::dynamic_pointer_cast<AudioRegion> (region_copy) != 0 &&
- dynamic_cast<AudioTimeAxisView*> (tv.first) == 0) {
+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;
- /* audio -> non-audio */
- return true;
- }
+ track_canvas->window_to_world (x, y, wx, wy);
- if (boost::dynamic_pointer_cast<MidiRegion> (region_copy) != 0 &&
- dynamic_cast<MidiTimeAxisView*> (tv.first) == 0) {
+ 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;
- /* MIDI -> non-MIDI */
- return true;
- }
+ framepos_t const pos = event_frame (&event, &px, &py);
- _drags->set (new RegionInsertDrag (this, region_copy, rtav, pos), &event);
- }
+ std::pair<TimeAxisView*, int> const tv = trackview_by_y_position (py);
- _drags->motion_handler (&event, false);
+ if (tv.first != 0) {
- return true;
+ 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