Small cleanups to dragging code. Fix assertion failure on dragging a regions' parent...
authorCarl Hetherington <carl@carlh.net>
Wed, 5 May 2010 22:09:07 +0000 (22:09 +0000)
committerCarl Hetherington <carl@carlh.net>
Wed, 5 May 2010 22:09:07 +0000 (22:09 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@7068 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/editor_canvas.cc
gtk2_ardour/editor_canvas_events.cc
gtk2_ardour/editor_drag.cc
gtk2_ardour/editor_drag.h
gtk2_ardour/editor_markers.cc
gtk2_ardour/editor_mouse.cc
gtk2_ardour/editor_ops.cc
gtk2_ardour/editor_regions.cc

index 757445114f09117e79ad4837f1b84bb749809d09..d47799b622f2cc96740ab2472a71fbf7464abc17 100644 (file)
@@ -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<Gdk::DragContext>& context,
                                         int x, int y,
index 8b57ccb8dfd1b1c9fd0930af805e0d98c630bdd4..28074c23e8219ee53982e5a4d1f02474f895070e 100644 (file)
@@ -996,6 +996,10 @@ Editor::track_canvas_drag_motion (Glib::RefPtr<Gdk::DragContext> const & /*c*/,
 
                boost::shared_ptr<Region> region = _regions->get_dragged_region ();
 
+               if (!region) {
+                       return true;
+               }
+
                boost::shared_ptr<Region> region_copy = RegionFactory::create (region);
 
                if (boost::dynamic_pointer_cast<AudioRegion> (region_copy) != 0 &&
index 1fb4fabf45a268de9b40ed9c5c8ef93ea43b4683..e039ae94a6ad63d3079abec52e1d3fdc7937b955 100644 (file)
@@ -67,24 +67,14 @@ DragManager::~DragManager ()
        abort ();
 }
 
+/** Call abort for each active drag */
 void
 DragManager::abort ()
-{
-       for (list<Drag*>::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<Drag*>::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<RegionView*> const & v)
index d0bd00f5e6ed156334aea6dcc022b2aa54359442..fb5ef3da9e80c201da46b8b59543fae6d7375cff 100644 (file)
@@ -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<Drag*> _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;
index dad515671e559b7bc50a970b81ac1b4987f2373d..0b3874b441b3276b8b32200929731d3eedb631d2 100644 (file)
@@ -1119,7 +1119,7 @@ Editor::new_transport_marker_menu_popdown ()
        // hide rects
        transport_bar_drag_rect->hide();
 
-       _drags->break_drag ();
+       _drags->abort ();
 }
 
 void
index c8864eed3abb18b54ff7898ac8c20466f269689d..d75dce80791f640ce2eb03a10f3d08d463be638f 100644 (file)
@@ -2551,7 +2551,7 @@ void
 Editor::escape ()
 {
        if (_drags->active ()) {
-               _drags->break_drag ();
+               _drags->abort ();
        } else {
                selection->clear ();
        }
index 8aa9489497d376d4f29f5405810b55bfe405d1f6..8e17999d83a59d51b2f974108d0947b46d0e349b 100644 (file)
@@ -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 ();
        }
 }
 
index 9d00015b8d28672f33706defa7f98625d53f13c6..69890044fd412c85181cff4e56feed7a699d27c9 100644 (file)
@@ -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<Gdk::DragContext>& context,
        vector<ustring> 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<Region>
 EditorRegions::get_dragged_region ()
 {
        list<boost::shared_ptr<Region> > regions;
        TreeView* source;
        _display.get_object_drag_data (regions, &source);
+
+       if (regions.empty()) {
+               return boost::shared_ptr<Region> ();
+       }
+       
        assert (regions.size() == 1);
        return regions.front ();
 }