a big menu cleanup; vertical auto-scrolling; some code cleanups; an unfinished (and...
[ardour.git] / gtk2_ardour / editor_mouse.cc
index cdb0f05f67c5c5fb4a83eacac7f1ce5eaf36f1d6..b3343c42c33fd8dc79dd312aac96b9b3d04c0309 100644 (file)
@@ -1531,6 +1531,85 @@ Editor::left_automation_track ()
        return false;
 }
 
+void
+Editor::scrub ()
+{
+       double delta;
+       
+       if (scrubbing_direction == 0) {
+               /* first move */
+               session->request_locate (drag_info.current_pointer_frame, false);
+               session->request_transport_speed (0.1);
+               scrubbing_direction = 1;
+               
+       } else {
+               
+               if (last_scrub_x > drag_info.current_pointer_x) {
+                       
+                       /* pointer moved to the left */
+                       
+                       if (scrubbing_direction > 0) {
+                               
+                               /* we reversed direction to go backwards */
+                               
+                               scrub_reversals++;
+                               scrub_reverse_distance += (int) (last_scrub_x - drag_info.current_pointer_x);
+                               
+                       } else {
+                               
+                               /* still moving to the left (backwards) */
+                               
+                               scrub_reversals = 0;
+                               scrub_reverse_distance = 0;
+                               
+                               delta = 0.01 * (last_scrub_x - drag_info.current_pointer_x);
+                               session->request_transport_speed (session->transport_speed() - delta);
+                       }
+                       
+               } else {
+                       /* pointer moved to the right */
+                       
+                       if (scrubbing_direction < 0) {
+                               /* we reversed direction to go forward */
+                               
+                               scrub_reversals++;
+                               scrub_reverse_distance += (int) (drag_info.current_pointer_x - last_scrub_x);
+                               
+                       } else {
+                               /* still moving to the right */
+                               
+                               scrub_reversals = 0;
+                               scrub_reverse_distance = 0;
+                               
+                               delta = 0.01 * (drag_info.current_pointer_x - last_scrub_x);
+                               session->request_transport_speed (session->transport_speed() + delta);
+                       }
+               }
+               
+               /* if there have been more than 2 opposite motion moves detected, or one that moves
+                  back more than 10 pixels, reverse direction
+               */
+               
+               if (scrub_reversals >= 2 || scrub_reverse_distance > 10) {
+                       
+                       if (scrubbing_direction > 0) {
+                               /* was forwards, go backwards */
+                               session->request_transport_speed (-0.1);
+                               scrubbing_direction = -1;
+                       } else {
+                               /* was backwards, go forwards */
+                               session->request_transport_speed (0.1);
+                               scrubbing_direction = 1;
+                       }
+                       
+                       scrub_reverse_distance = 0;
+                       scrub_reversals = 0;
+               }
+       }
+       
+       last_scrub_x = drag_info.current_pointer_x;
+}
+
 bool
 Editor::motion_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_type, bool from_autoscroll)
 {
@@ -1547,7 +1626,7 @@ Editor::motion_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item
                */
                
                track_canvas->get_pointer (x, y);
-       }
+       } 
 
        if (current_stepping_trackview) {
                /* don't keep the persistent stepped trackview if the mouse moves */
@@ -1566,85 +1645,13 @@ Editor::motion_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item
        drag_info.current_pointer_frame = event_frame (event, &drag_info.current_pointer_x,
                                                       &drag_info.current_pointer_y);
 
+       
        switch (mouse_mode) {
        case MouseAudition:
                if (_scrubbing) {
-
-                       double delta;
-
-                       if (scrubbing_direction == 0) {
-                               /* first move */
-                               session->request_locate (drag_info.current_pointer_frame, false);
-                               session->request_transport_speed (0.1);
-                               scrubbing_direction = 1;
-
-                       } else {
-                               
-                               if (last_scrub_x > drag_info.current_pointer_x) {
-
-                                       /* pointer moved to the left */
-                                       
-                                       if (scrubbing_direction > 0) {
-
-                                               /* we reversed direction to go backwards */
-
-                                               scrub_reversals++;
-                                               scrub_reverse_distance += (int) (last_scrub_x - drag_info.current_pointer_x);
-
-                                       } else {
-
-                                               /* still moving to the left (backwards) */
-                                               
-                                               scrub_reversals = 0;
-                                               scrub_reverse_distance = 0;
-
-                                               delta = 0.01 * (last_scrub_x - drag_info.current_pointer_x);
-                                               session->request_transport_speed (session->transport_speed() - delta);
-                                       }
-                                       
-                               } else {
-                                       /* pointer moved to the right */
-
-                                       if (scrubbing_direction < 0) {
-                                               /* we reversed direction to go forward */
-
-                                               scrub_reversals++;
-                                               scrub_reverse_distance += (int) (drag_info.current_pointer_x - last_scrub_x);
-
-                                       } else {
-                                               /* still moving to the right */
-
-                                               scrub_reversals = 0;
-                                               scrub_reverse_distance = 0;
-                                               
-                                               delta = 0.01 * (drag_info.current_pointer_x - last_scrub_x);
-                                               session->request_transport_speed (session->transport_speed() + delta);
-                                       }
-                               }
-
-                               /* if there have been more than 2 opposite motion moves detected, or one that moves
-                                  back more than 10 pixels, reverse direction
-                               */
-
-                               if (scrub_reversals >= 2 || scrub_reverse_distance > 10) {
-
-                                       if (scrubbing_direction > 0) {
-                                               /* was forwards, go backwards */
-                                               session->request_transport_speed (-0.1);
-                                               scrubbing_direction = -1;
-                                       } else {
-                                               /* was backwards, go forwards */
-                                               session->request_transport_speed (0.1);
-                                               scrubbing_direction = 1;
-                                       }
-                                       
-                                       scrub_reverse_distance = 0;
-                                       scrub_reversals = 0;
-                               }
-                       }
-
-                       last_scrub_x = drag_info.current_pointer_x;
+                       scrub ();
                }
+               break;
 
        default:
                break;
@@ -1700,7 +1707,7 @@ Editor::motion_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item
          if (drag_info.item && (event->motion.state & Gdk::BUTTON1_MASK ||
                                 (event->motion.state & Gdk::BUTTON2_MASK))) {
                  if (!from_autoscroll) {
-                         maybe_autoscroll (event);
+                         maybe_autoscroll (&event->motion);
                  }
                  (this->*(drag_info.motion_callback)) (item, event);
                  goto handled;
@@ -1719,7 +1726,7 @@ Editor::motion_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item
                if (drag_info.item && (event->motion.state & GDK_BUTTON1_MASK ||
                                       (event->motion.state & GDK_BUTTON2_MASK))) {
                        if (!from_autoscroll) {
-                               maybe_autoscroll (event);
+                               maybe_autoscroll (&event->motion);
                        }
                        (this->*(drag_info.motion_callback)) (item, event);
                        goto handled;
@@ -1740,6 +1747,48 @@ Editor::motion_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item
        return false;
 }
 
+void
+Editor::break_drag ()
+{
+       stop_canvas_autoscroll ();
+       hide_verbose_canvas_cursor ();
+
+       if (drag_info.item) {
+               drag_info.item->ungrab (0);
+
+               /* put it back where it came from */
+
+               double cxw, cyw;
+               cxw = 0;
+               cyw = 0;
+               drag_info.item->i2w (cxw, cyw);
+               drag_info.item->move (drag_info.original_x - cxw, drag_info.original_y - cyw);
+       }
+
+       finalize_drag ();
+}
+
+void
+Editor::finalize_drag ()
+{
+       drag_info.item = 0;
+       drag_info.copy = false;
+       drag_info.motion_callback = 0;
+       drag_info.finished_callback = 0;
+       drag_info.dest_trackview = 0;
+       drag_info.source_trackview = 0;
+       drag_info.last_frame_position = 0;
+       drag_info.grab_frame = 0;
+       drag_info.last_pointer_frame = 0;
+       drag_info.current_pointer_frame = 0;
+       drag_info.brushing = false;
+
+       if (drag_info.copied_location) {
+               delete drag_info.copied_location;
+               drag_info.copied_location = 0;
+       }
+}
+
 void
 Editor::start_grab (GdkEvent* event, Gdk::Cursor *cursor)
 {
@@ -1784,6 +1833,10 @@ Editor::start_grab (GdkEvent* event, Gdk::Cursor *cursor)
        drag_info.brushing = false;
        drag_info.copied_location = 0;
 
+       drag_info.original_x = 0;
+       drag_info.original_y = 0;
+       drag_info.item->i2w (drag_info.original_x, drag_info.original_y);
+
        drag_info.item->grab (Gdk::POINTER_MOTION_MASK|Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK,
                              *cursor,
                              event->button.time);
@@ -1842,22 +1895,7 @@ Editor::end_grab (ArdourCanvas::Item* item, GdkEvent* event)
 
        hide_verbose_canvas_cursor();
 
-       drag_info.item = 0;
-       drag_info.copy = false;
-       drag_info.motion_callback = 0;
-       drag_info.finished_callback = 0;
-       drag_info.dest_trackview = 0;
-       drag_info.source_trackview = 0;
-       drag_info.last_frame_position = 0;
-       drag_info.grab_frame = 0;
-       drag_info.last_pointer_frame = 0;
-       drag_info.current_pointer_frame = 0;
-       drag_info.brushing = false;
-
-       if (drag_info.copied_location) {
-               delete drag_info.copied_location;
-               drag_info.copied_location = 0;
-       }
+       finalize_drag ();
 
        return did_drag;
 }
@@ -2343,8 +2381,8 @@ void
 Editor::marker_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event)
 {
        if (drag_info.first_move) {
-               marker_drag_motion_callback (item, event);
-
+               /* just a click, do nothing but whatever selection occured */
+               return;
        }
 
        _dragging_edit_point = false;
@@ -3400,8 +3438,19 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
                }
          
                // printf ("3: pending_region_position= %lu    %lu\n", pending_region_position, drag_info.last_frame_position );
-         
-               bool x_move_allowed = ( drag_info.copy || !drag_info.x_constrained && (Config->get_edit_mode() != Lock)) || ( drag_info.x_constrained && (Config->get_edit_mode() == Lock)) ;
+
+               bool x_move_allowed;
+               
+               if (Config->get_edit_mode() == Lock) {
+                       if (drag_info.copy) {
+                               x_move_allowed = !drag_info.x_constrained;
+                       } else {
+                               /* in locked edit mode, reverse the usual meaning of x_constrained */
+                               x_move_allowed = drag_info.x_constrained;
+                       }
+               } else {
+                       x_move_allowed = !drag_info.x_constrained;
+               }
 
                if ( pending_region_position != drag_info.last_frame_position && x_move_allowed ) {
 
@@ -3613,18 +3662,12 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
 void
 Editor::region_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event)
 {
-       nframes_t where;
-       RegionView* rv = reinterpret_cast<RegionView *> (drag_info.data);
-       pair<set<boost::shared_ptr<Playlist> >::iterator,bool> insert_result;
        bool nocommit = true;
-       double speed;
-       RouteTimeAxisView* atv;
-       bool regionview_y_movement;
-       bool regionview_x_movement;
        vector<RegionView*> copies;
-       RouteTimeAxisView* tvp1;
+       RouteTimeAxisView* source_tv;
        boost::shared_ptr<Diskstream> ds;
        boost::shared_ptr<Playlist> from_playlist;
+       vector<RegionView*> new_selection;
 
        /* first_move is set to false if the regionview has been moved in the 
           motion handler. 
@@ -3660,41 +3703,6 @@ Editor::region_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event
                goto out;
        }
 
-       /* get the playlist where this drag started. we can't use rv->region()->playlist()
-          because we may have copied the region and it has not been attached to a playlist.
-       */
-
-       assert ((tvp1 = dynamic_cast<RouteTimeAxisView*> (drag_info.source_trackview)));
-       assert ((ds = tvp1->get_diskstream()));
-       assert ((from_playlist = ds->playlist()));
-
-       /* adjust for track speed */
-       speed = 1.0;
-
-       atv = dynamic_cast<AudioTimeAxisView*> (drag_info.dest_trackview);
-
-       if (atv && atv->get_diskstream()) {
-               speed = atv->get_diskstream()->speed();
-       }
-
-       /* check all regions for motion because some might have been locked */
-       
-       regionview_x_movement = false;
-       regionview_y_movement = false;
-
-       for (list<RegionView*>::const_iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) {
-               if (drag_info.last_frame_position != (nframes_t) ((*i)->region()->position()/speed)) {
-                       regionview_x_movement = true;
-               }
-               
-               if (drag_info.dest_trackview != &(*i)->get_time_axis_view()) {
-                       regionview_y_movement = true;
-               }
-       }
-
-       //printf ("last_frame: %s position is %lu  %g\n", rv->get_time_axis_view().name().c_str(), drag_info.last_frame_position, speed); 
-       //printf ("last_rackview: %s \n", drag_info.dest_trackview->name().c_str()); 
-       
        char* op_string;
 
        if (drag_info.copy) {
@@ -3713,84 +3721,110 @@ Editor::region_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event
 
        begin_reversible_command (op_string);
 
-       if (regionview_y_movement) {
-
-               /* moved to a different audio track. */
-               
-               vector<RegionView*> new_selection;
-
-               for (list<RegionView*>::const_iterator i = selection->regions.by_layer().begin(); i != selection->regions.by_layer().end(); ) {
-                       
-                       RegionView* rv = (*i);              
+       for (list<RegionView*>::const_iterator i = selection->regions.by_layer().begin(); i != selection->regions.by_layer().end(); ) {
                        
-                       if (rv->region()->locked()) {
-                               ++i;
-                               continue;
-                       }
+               RegionView* rv = (*i);              
+               double ix1, ix2, iy1, iy2;
+               rv->get_canvas_frame()->get_bounds (ix1, iy1, ix2, iy2);
+               rv->get_canvas_group()->i2w (ix1, iy1);
+               TimeAxisView* dest_tv = trackview_by_y_position (iy1);
+               AudioTimeAxisView* dest_atv = dynamic_cast<AudioTimeAxisView*>(dest_tv);
+               double speed;
+               bool changed_tracks;
+               bool changed_position;
+               nframes_t where;
+
+               if (rv->region()->locked()) {
+                       ++i;
+                       continue;
+               }
 
-                       double ix1, ix2, iy1, iy2;
-                       rv->get_canvas_frame()->get_bounds (ix1, iy1, ix2, iy2);
-                       rv->get_canvas_group()->i2w (ix1, iy1);
-                       TimeAxisView* tvp2 = trackview_by_y_position (iy1);
-                       AudioTimeAxisView* atv2 = dynamic_cast<AudioTimeAxisView*>(tvp2);
+               /* adjust for track speed */
 
-                       boost::shared_ptr<Playlist> to_playlist = atv2->playlist();
+               speed = 1.0;
+               
+               if (dest_atv && dest_atv->get_diskstream()) {
+                       speed = dest_atv->get_diskstream()->speed();
+               }
+               
+               changed_position = (drag_info.last_frame_position != (nframes_t) (rv->region()->position()/speed));
+               changed_tracks = (dest_tv != &rv->get_time_axis_view());
 
+               if (changed_position && !drag_info.x_constrained) {
                        where = (nframes_t) (unit_to_frame (ix1) * speed);
-                       boost::shared_ptr<Region> new_region;
-
-                       if (drag_info.copy) {
-                               /* we already made a copy */
-                               new_region = rv->region();
-                       } else {
-                               new_region = RegionFactory::create (rv->region());
-                       }
-
-                       /* undo the previous hide_dependent_views so that xfades don't
-                          disappear on copying regions 
-                       */
-
-                       rv->get_time_axis_view().reveal_dependent_views (*rv);
-
-                       if (!drag_info.copy) {
-                               
-                               /* the region that used to be in the old playlist is not
-                                  moved to the new one - we make a copy of it. as a result,
-                                  any existing editor for the region should no longer be
-                                  visible.
-                               */ 
-           
-                               rv->hide_region_editor();
-                               rv->fake_set_opaque (false);
-
-                               /* remove the region from the old playlist */
+               } else {
+                       where = rv->region()->position();
+               }
+                       
+               /* undo the previous hide_dependent_views so that xfades don't
+                  disappear on copying regions 
+               */
+               
+               rv->get_time_axis_view().reveal_dependent_views (*rv);
+               
+               boost::shared_ptr<Region> new_region;
 
+               if (drag_info.copy) {
+                       /* we already made a copy */
+                       new_region = rv->region();
+               } else {
+                       new_region = RegionFactory::create (rv->region());
+               }
 
-                               session->add_command (new MementoCommand<Playlist>(*from_playlist, &from_playlist->get_state(), 0));    
-                               from_playlist->remove_region ((rv->region()));
-                               session->add_command (new MementoCommand<Playlist>(*from_playlist, 0, &from_playlist->get_state()));    
+               if (changed_tracks || drag_info.copy) {
 
-                       } else {
-
-                               /* the regionview we dragged around is a temporary copy, queue it for deletion */
-                               
-                               copies.push_back (rv);
-                       }
+                       boost::shared_ptr<Playlist> to_playlist = dest_atv->playlist();
 
                        latest_regionviews.clear ();
-                       
-                       sigc::connection c = atv2->view()->RegionViewAdded.connect (mem_fun(*this, &Editor::collect_new_region_view));
+
+                       sigc::connection c = dest_atv->view()->RegionViewAdded.connect (mem_fun(*this, &Editor::collect_new_region_view));
                        session->add_command (new MementoCommand<Playlist>(*to_playlist, &to_playlist->get_state(), 0));        
                        to_playlist->add_region (new_region, where);
                        session->add_command (new MementoCommand<Playlist>(*to_playlist, 0, &to_playlist->get_state()));        
                        c.disconnect ();
                                                              
                        if (!latest_regionviews.empty()) {
-                               new_selection.insert (new_selection.end(), latest_regionviews.begin(), latest_regionviews.end());
+                               // XXX why just the first one ? we only expect one
+                               dest_atv->reveal_dependent_views (*latest_regionviews.front());
+                               new_selection.push_back (latest_regionviews.front());
                        }
 
+               } else {
+                               
+                       /* just change the model */
+                       
+                       rv->region()->set_position (where, (void*) this);
+               }
+
+               if (changed_tracks && !drag_info.copy) {
+
+                       /* get the playlist where this drag started. we can't use rv->region()->playlist()
+                          because we may have copied the region and it has not been attached to a playlist.
+                       */
+                       
+                       assert ((source_tv = dynamic_cast<RouteTimeAxisView*> (&rv->get_time_axis_view())));
+                       assert ((ds = source_tv->get_diskstream()));
+                       assert ((from_playlist = ds->playlist()));
+
+                       /* moved to a different audio track, without copying */
+
+                       /* the region that used to be in the old playlist is not
+                          moved to the new one - we use a copy of it. as a result,
+                          any existing editor for the region should no longer be
+                          visible.
+                       */ 
+           
+                       rv->hide_region_editor();
+                       rv->fake_set_opaque (false);
+                       
+                       /* remove the region from the old playlist */
+
+                       session->add_command (new MementoCommand<Playlist>(*from_playlist, &from_playlist->get_state(), 0));    
+                       from_playlist->remove_region ((rv->region()));
+                       session->add_command (new MementoCommand<Playlist>(*from_playlist, 0, &from_playlist->get_state()));    
+                       
                        /* OK, this is where it gets tricky. If the playlist was being used by >1 tracks, and the region
-                          was selected in all of them, then removing it from the playlist will have removed all
+                          was selected in all of them, then removing it from a playlist will have removed all
                           trace of it from the selection (i.e. there were N regions selected, we removed 1,
                           but since its the same playlist for N tracks, all N tracks updated themselves, removed the
                           corresponding regionview, and the selection is now empty).
@@ -3806,104 +3840,36 @@ Editor::region_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event
                           we can just iterate.
                        */
 
-                       if (drag_info.copy) {
-                               ++i;
-                       } else {
-                               if (selection->regions.empty()) {
-                                       break;
-                               } else { 
-                                       i = selection->regions.by_layer().begin();
-                               }
+                       if (selection->regions.empty()) {
+                               break;
+                       } else { 
+                               i = selection->regions.by_layer().begin();
                        }
-               } 
-
-               selection->set (new_selection);
-
-       } else {
-
-               /* motion within a single track */
-
-               list<RegionView*> regions = selection->regions.by_layer();
 
+               } else {
+                       ++i;
+               }
+               
                if (drag_info.copy) {
-                       selection->clear_regions();
+                       copies.push_back (rv);
                }
-
-               for (list<RegionView*>::iterator i = regions.begin(); i != regions.end(); ++i) {
-
-                       rv = (*i);
-
-                       if (rv->region()->locked()) {
-                               continue;
-                       }
-                       
-
-                       if (regionview_x_movement) {
-                               double ownspeed = 1.0;
-                               atv = dynamic_cast<AudioTimeAxisView*> (&(rv->get_time_axis_view()));
-
-                               if (atv && atv->get_diskstream()) {
-                                       ownspeed = atv->get_diskstream()->speed();
-                               }
-                               
-                               /* base the new region position on the current position of the regionview.*/
-                               
-                               double ix1, ix2, iy1, iy2;
-                               
-                               rv->get_canvas_frame()->get_bounds (ix1, iy1, ix2, iy2);
-                               rv->get_canvas_group()->i2w (ix1, iy1);
-                               where = (nframes_t) (unit_to_frame (ix1) * ownspeed);
-                               
-                       } else {
-                               
-                               where = rv->region()->position();
-                       }
-
-                       /* add the undo */
-
-                       session->add_command (new MementoCommand<Playlist>(*from_playlist, &from_playlist->get_state(), 0));    
-                       
-                       if (drag_info.copy) {
-
-                               /* we already made a copy of the region */
-
-                               boost::shared_ptr<Region> newregion = rv->region();
-
-                               /* add it */
-
-                               latest_regionviews.clear ();
-                               sigc::connection c = atv->view()->RegionViewAdded.connect (mem_fun(*this, &Editor::collect_new_region_view));
-                               from_playlist->add_region (newregion, (nframes_t) (where * atv->get_diskstream()->speed()));
-                               c.disconnect ();
-
-                               if (!latest_regionviews.empty()) {
-                                       // XXX why just the first one ? we only expect one
-                                       atv->reveal_dependent_views (*latest_regionviews.front());
-                                       selection->add (latest_regionviews);
-                               }
-                               
-                               /* if the original region was locked, we don't care for the new one */
-                               
-                               newregion->set_locked (false);                  
-
-                       } else {
-
-                               /* just change the model */
-
-                               rv->region()->set_position (where, (void*) this);
-
-                       }
-
-                       /* add the redo */
-
-                       session->add_command (new MementoCommand<Playlist>(*from_playlist, 0, &from_playlist->get_state()));
-
-                       if (drag_info.copy) {
-                               copies.push_back (rv);
-                       }
+       }
+       
+       if (new_selection.empty()) {
+               if (drag_info.copy) {
+                       /* the region(view)s that are selected and being dragged around
+                          are copies and do not belong to any track. remove them
+                          from the selection right here.
+                       */
+                       selection->clear_regions();
                }
+       } else {
+               /* this will clear any existing selection that would have been
+                  cleared in the other clause above
+               */
+               selection->set (new_selection);
        }
-
+                       
   out:
        if (!nocommit) {
                commit_reversible_command ();
@@ -4347,7 +4313,7 @@ Editor::drag_selection (ArdourCanvas::Item* item, GdkEvent* event)
        }
        
        if (event->button.x >= horizontal_adjustment.get_value() + canvas_width) {
-               start_canvas_autoscroll (1);
+               start_canvas_autoscroll (1, 0);
        }
 
        if (start != end) {
@@ -4922,7 +4888,7 @@ Editor::drag_range_markerbar_op (ArdourCanvas::Item* item, GdkEvent* event)
        }
        
        if (event->button.x >= horizontal_adjustment.get_value() + canvas_width) {
-               start_canvas_autoscroll (1);
+               start_canvas_autoscroll (1, 0);
        }
        
        if (start != end) {