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
This commit is contained in:
Carl Hetherington 2010-05-05 22:09:07 +00:00
parent b092cfc216
commit 8c423ea228
8 changed files with 35 additions and 23 deletions

View 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,

View 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 &&

View 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)

View 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;

View File

@ -1119,7 +1119,7 @@ Editor::new_transport_marker_menu_popdown ()
// hide rects
transport_bar_drag_rect->hide();
_drags->break_drag ();
_drags->abort ();
}
void

View File

@ -2551,7 +2551,7 @@ void
Editor::escape ()
{
if (_drags->active ()) {
_drags->break_drag ();
_drags->abort ();
} else {
selection->clear ();
}

View 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 ();
}
}

View 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 ();
}