From: Carl Hetherington Date: Wed, 5 May 2010 22:09:07 +0000 (+0000) Subject: Small cleanups to dragging code. Fix assertion failure on dragging a regions' parent... X-Git-Tag: 3.0-alpha5~2113 X-Git-Url: https://main.carlh.net/gitweb/?a=commitdiff_plain;h=8c423ea2284289a59e1cd549e7661114fa978ec8;p=ardour.git Small cleanups to dragging code. Fix assertion failure on dragging a regions' parent entry from the region list to the canvas (which may be #2811). Fixes to drags of regions onto and then back off canvas; should fix #3109. git-svn-id: svn://localhost/ardour2/branches/3.0@7068 d708f5d6-7413-0410-9779-e7cbd77b26cf --- diff --git a/gtk2_ardour/editor_canvas.cc b/gtk2_ardour/editor_canvas.cc index 757445114f..d47799b622 100644 --- a/gtk2_ardour/editor_canvas.cc +++ b/gtk2_ardour/editor_canvas.cc @@ -438,6 +438,7 @@ Editor::track_canvas_map_handler (GdkEventAny* /*ev*/) return false; } +/** This is called when something is dropped onto the track canvas */ void Editor::track_canvas_drag_data_received (const RefPtr& context, int x, int y, diff --git a/gtk2_ardour/editor_canvas_events.cc b/gtk2_ardour/editor_canvas_events.cc index 8b57ccb8df..28074c23e8 100644 --- a/gtk2_ardour/editor_canvas_events.cc +++ b/gtk2_ardour/editor_canvas_events.cc @@ -996,6 +996,10 @@ Editor::track_canvas_drag_motion (Glib::RefPtr const & /*c*/, boost::shared_ptr region = _regions->get_dragged_region (); + if (!region) { + return true; + } + boost::shared_ptr region_copy = RegionFactory::create (region); if (boost::dynamic_pointer_cast (region_copy) != 0 && diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index 1fb4fabf45..e039ae94a6 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -67,24 +67,14 @@ DragManager::~DragManager () abort (); } +/** Call abort for each active drag */ void DragManager::abort () -{ - for (list::const_iterator i = _drags.begin(); i != _drags.end(); ++i) { - (*i)->end_grab (0); - delete *i; - } - - _drags.clear (); -} - -void -DragManager::break_drag () { _ending = true; for (list::const_iterator i = _drags.begin(); i != _drags.end(); ++i) { - (*i)->break_drag (); + (*i)->abort (); delete *i; } @@ -119,6 +109,9 @@ DragManager::start_grab (GdkEvent* e) } } +/** Call end_grab for each active drag. + * @return true if any drag reported movement having occurred. + */ bool DragManager::end_grab (GdkEvent* e) { @@ -243,7 +236,10 @@ Drag::start_grab (GdkEvent* event, Gdk::Cursor *cursor) } } -/** @param event GDK event, or 0. +/** Call to end a drag `successfully'. Ungrabs item and calls + * subclass' finished() method. + * + * @param event GDK event, or 0. * @return true if some movement occurred, otherwise false. */ bool @@ -323,8 +319,9 @@ Drag::motion_handler (GdkEvent* event, bool from_autoscroll) return false; } +/** Call to abort a drag. Ungrabs item and calls subclass's aborted () */ void -Drag::break_drag () +Drag::abort () { if (_item) { _item->ungrab (0); @@ -1450,7 +1447,9 @@ RegionInsertDrag::finished (GdkEvent* /*event*/, bool /*movement_occurred*/) void RegionInsertDrag::aborted () { - /* XXX: TODO */ + delete _primary; + _primary = 0; + _views.clear (); } RegionSpliceDrag::RegionSpliceDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list const & v) diff --git a/gtk2_ardour/editor_drag.h b/gtk2_ardour/editor_drag.h index d0bd00f5e6..fb5ef3da9e 100644 --- a/gtk2_ardour/editor_drag.h +++ b/gtk2_ardour/editor_drag.h @@ -50,14 +50,13 @@ public: bool motion_handler (GdkEvent *, bool); void abort (); - void break_drag (); void add (Drag *); void set (Drag *, GdkEvent *, Gdk::Cursor* c = 0); void start_grab (GdkEvent *); bool end_grab (GdkEvent *); bool have_item (ArdourCanvas::Item *) const; - /** @return true if an end drag or break_drag is in progress */ + /** @return true if an end drag or abort is in progress */ bool ending () const { return _ending; } @@ -84,7 +83,7 @@ public: private: Editor* _editor; std::list _drags; - bool _ending; ///< true if end_grab or break_drag is in progress, otherwise false + bool _ending; ///< true if end_grab or abort is in progress, otherwise false double _current_pointer_x; ///< trackview x of the current pointer double _current_pointer_y; ///< trackview y of the current pointer nframes64_t _current_pointer_frame; ///< frame that the pointer is now at @@ -108,7 +107,7 @@ public: void swap_grab (ArdourCanvas::Item *, Gdk::Cursor *, uint32_t); bool motion_handler (GdkEvent*, bool); - void break_drag (); + void abort (); nframes64_t adjusted_frame (nframes64_t, GdkEvent const *, bool snap = true) const; nframes64_t adjusted_current_frame (GdkEvent const *, bool snap = true) const; diff --git a/gtk2_ardour/editor_markers.cc b/gtk2_ardour/editor_markers.cc index dad515671e..0b3874b441 100644 --- a/gtk2_ardour/editor_markers.cc +++ b/gtk2_ardour/editor_markers.cc @@ -1119,7 +1119,7 @@ Editor::new_transport_marker_menu_popdown () // hide rects transport_bar_drag_rect->hide(); - _drags->break_drag (); + _drags->abort (); } void diff --git a/gtk2_ardour/editor_mouse.cc b/gtk2_ardour/editor_mouse.cc index c8864eed3a..d75dce8079 100644 --- a/gtk2_ardour/editor_mouse.cc +++ b/gtk2_ardour/editor_mouse.cc @@ -2551,7 +2551,7 @@ void Editor::escape () { if (_drags->active ()) { - _drags->break_drag (); + _drags->abort (); } else { selection->clear (); } diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index 8aa9489497..8e17999d83 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -3760,7 +3760,7 @@ Editor::cut_copy (CutCopyOp op) Glib::signal_idle().connect (sigc::bind (sigc::mem_fun(*this, &Editor::really_remove_marker), loc)); } - _drags->break_drag (); + _drags->abort (); return; } @@ -3841,7 +3841,7 @@ Editor::cut_copy (CutCopyOp op) } if (op == Cut || op == Clear) { - _drags->break_drag (); + _drags->abort (); } } diff --git a/gtk2_ardour/editor_regions.cc b/gtk2_ardour/editor_regions.cc index 9d00015b8d..69890044fd 100644 --- a/gtk2_ardour/editor_regions.cc +++ b/gtk2_ardour/editor_regions.cc @@ -44,6 +44,7 @@ #include "region_view.h" #include "utils.h" #include "editor_regions.h" +#include "editor_drag.h" #include "i18n.h" @@ -1097,6 +1098,8 @@ EditorRegions::drag_data_received (const RefPtr& context, vector paths; if (data.get_target() == "GTK_TREE_MODEL_ROW") { + /* something is being dragged over the region list */ + _editor->_drags->abort (); _display.on_drag_data_received (context, x, y, data, info, time); return; } @@ -1155,12 +1158,18 @@ EditorRegions::name_edit (const Glib::ustring& path, const Glib::ustring& new_te } +/** @return Region that has been dragged out of the list, or 0 */ boost::shared_ptr EditorRegions::get_dragged_region () { list > regions; TreeView* source; _display.get_object_drag_data (regions, &source); + + if (regions.empty()) { + return boost::shared_ptr (); + } + assert (regions.size() == 1); return regions.front (); }