Fix/implement #6292, Shift + scroll wheel Scrolling in the ruler area
[ardour.git] / gtk2_ardour / editor_canvas_events.cc
index adb896af8b8235b46e08998f87f56338a8767cd3..7dcfe37fe506501461deb48bd89337144c4b2520 100644 (file)
@@ -37,7 +37,6 @@
 #include "editor.h"
 #include "keyboard.h"
 #include "public_editor.h"
-#include "ardour_ui.h"
 #include "audio_region_view.h"
 #include "audio_streamview.h"
 #include "audio_time_axis.h"
@@ -49,6 +48,7 @@
 #include "editor_drag.h"
 #include "midi_time_axis.h"
 #include "editor_regions.h"
+#include "ui_config.h"
 #include "verbose_cursor.h"
 
 #include "i18n.h"
@@ -64,11 +64,6 @@ using Gtkmm2ext::Keyboard;
 bool
 Editor::track_canvas_scroll (GdkEventScroll* ev)
 {
-       if (Keyboard::some_magic_widget_has_focus()) {
-               return false;
-       }
-       
-       framepos_t xdelta;
        int direction = ev->direction;
 
        /* this event arrives without transformation by the canvas, so we have
@@ -77,7 +72,6 @@ Editor::track_canvas_scroll (GdkEventScroll* ev)
 
        Duple event_coords = _track_canvas->window_to_canvas (Duple (ev->x, ev->y));
 
-  retry:
        switch (direction) {
        case GDK_SCROLL_UP:
                if (Keyboard::modifier_state_equals (ev->state, Keyboard::ScrollZoomHorizontalModifier)) {
@@ -88,8 +82,8 @@ Editor::track_canvas_scroll (GdkEventScroll* ev)
                        zoom_focus = temp_focus;
                        return true;
                } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::ScrollHorizontalModifier)) {
-                       direction = GDK_SCROLL_LEFT;
-                       goto retry;
+                       scroll_left_step ();
+                       return true;
                } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::ScrollZoomVerticalModifier)) {
                        if (!current_stepping_trackview) {
                                step_timeout = Glib::signal_timeout().connect (sigc::mem_fun(*this, &Editor::track_height_step_timeout), 500);
@@ -117,8 +111,8 @@ Editor::track_canvas_scroll (GdkEventScroll* ev)
                        zoom_focus = temp_focus;
                        return true;
                } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::ScrollHorizontalModifier)) {
-                       direction = GDK_SCROLL_RIGHT;
-                       goto retry;
+                       scroll_right_step ();
+                       return true;
                } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::ScrollZoomVerticalModifier)) {
                        if (!current_stepping_trackview) {
                                step_timeout = Glib::signal_timeout().connect (sigc::mem_fun(*this, &Editor::track_height_step_timeout), 500);
@@ -138,21 +132,13 @@ Editor::track_canvas_scroll (GdkEventScroll* ev)
                break;
 
        case GDK_SCROLL_LEFT:
-               xdelta = (current_page_samples() / 8);
-               if (leftmost_frame > xdelta) {
-                       reset_x_origin (leftmost_frame - xdelta);
-               } else {
-                       reset_x_origin (0);
-               }
+               scroll_left_step ();
+               return true;
                break;
 
        case GDK_SCROLL_RIGHT:
-               xdelta = (current_page_samples() / 8);
-               if (max_framepos - xdelta > leftmost_frame) {
-                       reset_x_origin (leftmost_frame + xdelta);
-               } else {
-                       reset_x_origin (max_framepos - current_page_samples());
-               }
+               scroll_right_step ();
+               return true;
                break;
 
        default:
@@ -329,7 +315,7 @@ Editor::canvas_wave_view_event (GdkEvent *event, ArdourCanvas::Item* item, Regio
        }
 
        return ret;
-}       
+}
 
 
 bool
@@ -688,17 +674,18 @@ bool
 Editor::canvas_line_event (GdkEvent *event, ArdourCanvas::Item* item, AutomationLine* al)
 {
        ItemType type;
-
-       if (dynamic_cast<AudioRegionGainLine*> (al) != 0) {
+       AudioRegionGainLine* gl;
+       if ((gl = dynamic_cast<AudioRegionGainLine*> (al)) != 0) {
                type = GainLineItem;
+               clicked_regionview = &gl->region_view ();
        } else {
                type = AutomationLineItem;
+               clicked_regionview = 0;
        }
 
        clicked_control_point = 0;
        clicked_axisview = &al->trackview;
        clicked_routeview = dynamic_cast<RouteTimeAxisView*>(clicked_axisview);
-       clicked_regionview = 0;
 
        return typed_event (item, event, type);
 }
@@ -1031,19 +1018,20 @@ Editor::canvas_meter_marker_event (GdkEvent *event, ArdourCanvas::Item* item, Me
 bool
 Editor::canvas_ruler_event (GdkEvent *event, ArdourCanvas::Item* item, ItemType type)
 {
-       framepos_t xdelta;
        bool handled = false;
 
        if (event->type == GDK_SCROLL) {
-               
+
                /* scroll events in the rulers are handled a little differently from
                   scrolling elsewhere in the canvas.
                */
 
                switch (event->scroll.direction) {
                case GDK_SCROLL_UP:
-
-                       if (Profile->get_mixbus()) {
+                       if (Keyboard::modifier_state_equals(event->scroll.state,
+                                                           Keyboard::ScrollHorizontalModifier)) {
+                               scroll_left_half_page ();
+                       } else if (Profile->get_mixbus()) {
                                //for mouse-wheel zoom, force zoom-focus to mouse
                                Editing::ZoomFocus temp_focus = zoom_focus;
                                zoom_focus = Editing::ZoomFocusMouse;
@@ -1054,9 +1042,12 @@ Editor::canvas_ruler_event (GdkEvent *event, ArdourCanvas::Item* item, ItemType
                        }
                        handled = true;
                        break;
-                       
+
                case GDK_SCROLL_DOWN:
-                       if (Profile->get_mixbus()) {
+                       if (Keyboard::modifier_state_equals(event->scroll.state,
+                                                           Keyboard::ScrollHorizontalModifier)) {
+                               scroll_right_half_page ();
+                       } else if (Profile->get_mixbus()) {
                                //for mouse-wheel zoom, force zoom-focus to mouse
                                Editing::ZoomFocus temp_focus = zoom_focus;
                                zoom_focus = Editing::ZoomFocusMouse;
@@ -1067,27 +1058,17 @@ Editor::canvas_ruler_event (GdkEvent *event, ArdourCanvas::Item* item, ItemType
                        }
                        handled = true;
                        break;
-                       
+
                case GDK_SCROLL_LEFT:
-                       xdelta = (current_page_samples() / 2);
-                       if (leftmost_frame > xdelta) {
-                               reset_x_origin (leftmost_frame - xdelta);
-                       } else {
-                               reset_x_origin (0);
-                       }
+                       scroll_left_half_page ();
                        handled = true;
                        break;
-                       
+
                case GDK_SCROLL_RIGHT:
-                       xdelta = (current_page_samples() / 2);
-                       if (max_framepos - xdelta > leftmost_frame) {
-                               reset_x_origin (leftmost_frame + xdelta);
-                       } else {
-                               reset_x_origin (max_framepos - current_page_samples());
-                       }
+                       scroll_right_half_page ();
                        handled = true;
                        break;
-                       
+
                default:
                        /* what? */
                        break;
@@ -1129,9 +1110,9 @@ Editor::canvas_note_event (GdkEvent *event, ArdourCanvas::Item* item)
 bool
 Editor::canvas_drop_zone_event (GdkEvent* event)
 {
-       GdkEventScroll scroll;  
+       GdkEventScroll scroll;
        ArdourCanvas::Duple winpos;
-       
+
        switch (event->type) {
        case GDK_BUTTON_RELEASE:
                if (event->button.button == 1) {
@@ -1192,18 +1173,18 @@ Editor::track_canvas_drag_motion (Glib::RefPtr<Gdk::DragContext> const& context,
 
        std::pair<TimeAxisView*, int> const tv = trackview_by_y_position (py, false);
        bool can_drop = false;
-       
+
        if (tv.first != 0) {
 
                /* over a time axis view of some kind */
 
                rtav = dynamic_cast<RouteTimeAxisView*> (tv.first);
-               
+
                if (rtav != 0 && rtav->is_track ()) {
                        /* over a track, not a bus */
                        can_drop = true;
                }
-                       
+
 
        } else {
                /* not over a time axis view, so drop is possible */
@@ -1212,7 +1193,7 @@ Editor::track_canvas_drag_motion (Glib::RefPtr<Gdk::DragContext> const& context,
 
        if (can_drop) {
                region = _regions->get_dragged_region ();
-               
+
                if (region) {
 
                        if (tv.first == 0
@@ -1226,17 +1207,17 @@ Editor::track_canvas_drag_motion (Glib::RefPtr<Gdk::DragContext> const& context,
                                context->drag_status (context->get_suggested_action(), time);
                                return true;
                        }
-                       
+
                        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)) {
-                               
-                               /* audio to audio 
-                                  OR 
+
+                               /* audio to audio
+                                  OR
                                   midi to midi
                                */
-                               
+
                                context->drag_status (context->get_suggested_action(), time);
                                return true;
                        }
@@ -1246,7 +1227,7 @@ Editor::track_canvas_drag_motion (Glib::RefPtr<Gdk::DragContext> const& context,
                         * TODO: check if file is audio/midi, allow drops on same track-type only,
                         * currently: if audio is dropped on a midi-track, it is only added to the region-list
                         */
-                       if (Profile->get_sae() || ARDOUR_UI::config()->get_only_copy_imported_files()) {
+                       if (Profile->get_sae() || UIConfiguration::instance().get_only_copy_imported_files()) {
                                context->drag_status(Gdk::ACTION_COPY, time);
                        } else {
                                if ((context->get_actions() & (Gdk::ACTION_COPY | Gdk::ACTION_LINK | Gdk::ACTION_MOVE)) == Gdk::ACTION_COPY) {