remove Glib::ustring from gtk2_ardour
[ardour.git] / gtk2_ardour / editor_canvas.cc
index 97df092faaed6f43b9bc0aeb536dd32e5058bc21..52850644be0f3c5f6f07444136b5e47952070a6a 100644 (file)
@@ -45,6 +45,7 @@
 #include "region_view.h"
 #include "editor_group_tabs.h"
 #include "editor_routes.h"
+#include "editor_summary.h"
 
 #include "i18n.h"
 
@@ -104,13 +105,8 @@ Editor::initialize_canvas ()
        track_canvas->set_center_scroll_region (false);
        track_canvas->set_dither (Gdk::RGB_DITHER_NONE);
 
-       Glib::RefPtr<Gdk::Screen> screen = get_screen();
-
-       if (!screen) {
-               screen = Gdk::Screen::get_default();
-       }
-       physical_screen_width = screen->get_width ();
-       physical_screen_height = screen->get_height ();
+        gint phys_width = physical_screen_width (Glib::RefPtr<Gdk::Window>());
+        gint phys_height = physical_screen_height (Glib::RefPtr<Gdk::Window>());
 
        /* stuff for the verbose canvas cursor */
 
@@ -141,14 +137,14 @@ Editor::initialize_canvas ()
 
 #ifdef GTKOSX
        /*XXX please don't laugh. this actually improves canvas performance on osx */
-       bogus_background_rect =  new ArdourCanvas::SimpleRect (*time_line_group, 0.0, 0.0, max_canvas_coordinate/3, physical_screen_height);
+       bogus_background_rect =  new ArdourCanvas::SimpleRect (*time_line_group, 0.0, 0.0, max_canvas_coordinate/3, phys_height);
        bogus_background_rect->property_outline_pixels() = 0;
 #endif
-       transport_loop_range_rect = new ArdourCanvas::SimpleRect (*time_line_group, 0.0, 0.0, 0.0, physical_screen_height);
+       transport_loop_range_rect = new ArdourCanvas::SimpleRect (*time_line_group, 0.0, 0.0, 0.0, phys_height);
        transport_loop_range_rect->property_outline_pixels() = 1;
        transport_loop_range_rect->hide();
 
-       transport_punch_range_rect = new ArdourCanvas::SimpleRect (*time_line_group, 0.0, 0.0, 0.0, physical_screen_height);
+       transport_punch_range_rect = new ArdourCanvas::SimpleRect (*time_line_group, 0.0, 0.0, 0.0, phys_height);
        transport_punch_range_rect->property_outline_pixels() = 0;
        transport_punch_range_rect->hide();
 
@@ -160,60 +156,60 @@ Editor::initialize_canvas ()
 
        meter_bar_group = new ArdourCanvas::Group (*track_canvas->root ());
        if (Profile->get_sae()) {
-               meter_bar = new ArdourCanvas::SimpleRect (*meter_bar_group, 0.0, 0.0, physical_screen_width, timebar_height - 1);
+               meter_bar = new ArdourCanvas::SimpleRect (*meter_bar_group, 0.0, 0.0, phys_width, timebar_height - 1);
                meter_bar->property_outline_pixels() = 1;
        } else {
-               meter_bar = new ArdourCanvas::SimpleRect (*meter_bar_group, 0.0, 0.0, physical_screen_width, timebar_height);
+               meter_bar = new ArdourCanvas::SimpleRect (*meter_bar_group, 0.0, 0.0, phys_width, timebar_height);
                meter_bar->property_outline_pixels() = 0;
        }
        meter_bar->property_outline_what() = (0x1 | 0x8);
 
        tempo_bar_group = new ArdourCanvas::Group (*track_canvas->root ());
        if (Profile->get_sae()) {
-               tempo_bar = new ArdourCanvas::SimpleRect (*tempo_bar_group, 0.0, 0.0, physical_screen_width, (timebar_height - 1));
+               tempo_bar = new ArdourCanvas::SimpleRect (*tempo_bar_group, 0.0, 0.0, phys_width, (timebar_height - 1));
                tempo_bar->property_outline_pixels() = 1;
        } else {
-               tempo_bar = new ArdourCanvas::SimpleRect (*tempo_bar_group, 0.0, 0.0, physical_screen_width, (timebar_height));
+               tempo_bar = new ArdourCanvas::SimpleRect (*tempo_bar_group, 0.0, 0.0, phys_width, (timebar_height));
                tempo_bar->property_outline_pixels() = 0;
        }
        tempo_bar->property_outline_what() = (0x1 | 0x8);
 
        range_marker_bar_group = new ArdourCanvas::Group (*track_canvas->root ());
        if (Profile->get_sae()) {
-               range_marker_bar = new ArdourCanvas::SimpleRect (*range_marker_bar_group, 0.0, 0.0, physical_screen_width, (timebar_height - 1));
+               range_marker_bar = new ArdourCanvas::SimpleRect (*range_marker_bar_group, 0.0, 0.0, phys_width, (timebar_height - 1));
                range_marker_bar->property_outline_pixels() = 1;
        } else {
-               range_marker_bar = new ArdourCanvas::SimpleRect (*range_marker_bar_group, 0.0, 0.0, physical_screen_width, (timebar_height));
+               range_marker_bar = new ArdourCanvas::SimpleRect (*range_marker_bar_group, 0.0, 0.0, phys_width, (timebar_height));
                range_marker_bar->property_outline_pixels() = 0;
        }
        range_marker_bar->property_outline_what() = (0x1 | 0x8);
 
        transport_marker_bar_group = new ArdourCanvas::Group (*track_canvas->root ());
        if (Profile->get_sae()) {
-               transport_marker_bar = new ArdourCanvas::SimpleRect (*transport_marker_bar_group, 0.0, 0.0,  physical_screen_width, (timebar_height - 1));
+               transport_marker_bar = new ArdourCanvas::SimpleRect (*transport_marker_bar_group, 0.0, 0.0,  phys_width, (timebar_height - 1));
                transport_marker_bar->property_outline_pixels() = 1;
        } else {
-               transport_marker_bar = new ArdourCanvas::SimpleRect (*transport_marker_bar_group, 0.0, 0.0,  physical_screen_width, (timebar_height));
+               transport_marker_bar = new ArdourCanvas::SimpleRect (*transport_marker_bar_group, 0.0, 0.0,  phys_width, (timebar_height));
                transport_marker_bar->property_outline_pixels() = 0;
        }
        transport_marker_bar->property_outline_what() = (0x1 | 0x8);
 
        marker_bar_group = new ArdourCanvas::Group (*track_canvas->root ());
        if (Profile->get_sae()) {
-               marker_bar = new ArdourCanvas::SimpleRect (*marker_bar_group, 0.0, 0.0, physical_screen_width, (timebar_height - 1));
+               marker_bar = new ArdourCanvas::SimpleRect (*marker_bar_group, 0.0, 0.0, phys_width, (timebar_height - 1));
                marker_bar->property_outline_pixels() = 1;
        } else {
-               marker_bar = new ArdourCanvas::SimpleRect (*marker_bar_group, 0.0, 0.0, physical_screen_width, (timebar_height));
+               marker_bar = new ArdourCanvas::SimpleRect (*marker_bar_group, 0.0, 0.0, phys_width, (timebar_height));
                marker_bar->property_outline_pixels() = 0;
        }
        marker_bar->property_outline_what() = (0x1 | 0x8);
 
        cd_marker_bar_group = new ArdourCanvas::Group (*track_canvas->root ());
        if (Profile->get_sae()) {
-               cd_marker_bar = new ArdourCanvas::SimpleRect (*cd_marker_bar_group, 0.0, 0.0, physical_screen_width, (timebar_height - 1));
+               cd_marker_bar = new ArdourCanvas::SimpleRect (*cd_marker_bar_group, 0.0, 0.0, phys_width, (timebar_height - 1));
                cd_marker_bar->property_outline_pixels() = 1;
        } else {
-               cd_marker_bar = new ArdourCanvas::SimpleRect (*cd_marker_bar_group, 0.0, 0.0, physical_screen_width, (timebar_height));
+               cd_marker_bar = new ArdourCanvas::SimpleRect (*cd_marker_bar_group, 0.0, 0.0, phys_width, (timebar_height));
                cd_marker_bar->property_outline_pixels() = 0;
        }
        cd_marker_bar->property_outline_what() = (0x1 | 0x8);
@@ -244,14 +240,14 @@ Editor::initialize_canvas ()
        transport_punchin_line->property_x1() = 0.0;
        transport_punchin_line->property_y1() = 0.0;
        transport_punchin_line->property_x2() = 0.0;
-       transport_punchin_line->property_y2() = physical_screen_height;
+       transport_punchin_line->property_y2() = phys_height;
        transport_punchin_line->hide ();
 
        transport_punchout_line  = new ArdourCanvas::SimpleLine (*_master_group);
        transport_punchout_line->property_x1() = 0.0;
        transport_punchout_line->property_y1() = 0.0;
        transport_punchout_line->property_x2() = 0.0;
-       transport_punchout_line->property_y2() = physical_screen_height;
+       transport_punchout_line->property_y2() = phys_height;
        transport_punchout_line->hide();
 
        // used to show zoom mode active zooming
@@ -329,16 +325,12 @@ Editor::track_canvas_size_allocated ()
        _canvas_width = canvas_allocation.get_width();
        _canvas_height = canvas_allocation.get_height();
 
-       if (session) {
+       if (_session) {
                TrackViewList::iterator i;
-               double height = 0;
 
                for (i = track_views.begin(); i != track_views.end(); ++i) {
-                       height += (*i)->effective_height ();
                        (*i)->clip_to_viewport ();
                }
-
-               full_canvas_height = height + canvas_timebars_vsize;
        }
 
        if (height_changed) {
@@ -361,7 +353,6 @@ Editor::track_canvas_size_allocated ()
                }
        }
 
-       handle_new_duration ();
        update_fixed_rulers();
        redisplay_tempo (false);
        _summary->set_overlays_dirty ();
@@ -377,10 +368,9 @@ Editor::controls_layout_size_request (Requisition* req)
        double pos = 0;
        for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
                pos += (*i)->effective_height ();
-               (*i)->clip_to_viewport ();
        }
 
-       gint height = min ((gint) pos, (gint) (physical_screen_height - 600));
+       gint height = min ((gint) pos, (gint) (physical_screen_height(get_window()) - 600));
 
        bool changed = false;
 
@@ -393,7 +383,7 @@ Editor::controls_layout_size_request (Requisition* req)
 
        /* don't get too big. the fudge factors here are just guesses */
 
-       width =  min (width, (gint) (physical_screen_width - 300));
+       width =  min (width, (gint) (physical_screen_width(get_window()) - 300));
 
        if ((req->width != width) || (req->height != height)) {
                changed = true;
@@ -438,6 +428,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,
@@ -452,14 +443,14 @@ Editor::track_canvas_drag_data_received (const RefPtr<Gdk::DragContext>& context
 }
 
 bool
-Editor::idle_drop_paths (vector<ustring> paths, nframes64_t frame, double ypos)
+Editor::idle_drop_paths (vector<string> paths, nframes64_t frame, double ypos)
 {
        drop_paths_part_two (paths, frame, ypos);
        return false;
 }
 
 void
-Editor::drop_paths_part_two (const vector<ustring>& paths, nframes64_t frame, double ypos)
+Editor::drop_paths_part_two (const vector<string>& paths, nframes64_t frame, double ypos)
 {
        RouteTimeAxisView* tv;
 
@@ -480,7 +471,7 @@ Editor::drop_paths_part_two (const vector<ustring>& paths, nframes64_t frame, do
 
                /* check that its an audio track, not a bus */
 
-               if (tv->get_diskstream()) {
+               if (tv->track()) {
                        /* select the track, then embed/import */
                        selection->set (tv);
 
@@ -499,7 +490,7 @@ Editor::drop_paths (const RefPtr<Gdk::DragContext>& context,
                    const SelectionData& data,
                    guint info, guint time)
 {
-       vector<ustring> paths;
+       vector<string> paths;
        GdkEvent ev;
        nframes64_t frame;
        double wx;
@@ -541,46 +532,37 @@ Editor::drop_regions (const RefPtr<Gdk::DragContext>& /*context*/,
                      const SelectionData& /*data*/,
                      guint /*info*/, guint /*time*/)
 {
-       assert (_drag);
-       _drag->end_grab (0);
-       delete _drag;
-       _drag = 0;
+       _drags->end_grab (0);
 }
 
 void
-Editor::maybe_autoscroll (GdkEventMotion* event, bool allow_vert)
+Editor::maybe_autoscroll (bool allow_horiz, bool allow_vert)
 {
        nframes64_t rightmost_frame = leftmost_frame + current_page_frames();
-       nframes64_t frame = _drag->current_pointer_frame();
        bool startit = false;
 
+       double ty = _drags->current_pointer_y() - get_trackview_group_vertical_offset ();
+
        autoscroll_y = 0;
        autoscroll_x = 0;
-       if (event->y < canvas_timebars_vsize && allow_vert) {
+       if (ty < canvas_timebars_vsize && allow_vert) {
                autoscroll_y = -1;
                startit = true;
-       } else if (event->y > _canvas_height) {
+       } else if (ty > _canvas_height && allow_vert) {
                autoscroll_y = 1;
                startit = true;
        }
 
-       if (frame > rightmost_frame) {
-
+       if (_drags->current_pointer_frame() > rightmost_frame && allow_horiz) {
                if (rightmost_frame < max_frames) {
                        autoscroll_x = 1;
                        startit = true;
                }
-
-       } else if (frame < leftmost_frame) {
+       } else if (_drags->current_pointer_frame() < leftmost_frame && allow_horiz) {
                if (leftmost_frame > 0) {
                        autoscroll_x = -1;
                        startit = true;
                }
-
-       }
-
-       if (!allow_vertical_scroll) {
-               autoscroll_y = 0;
        }
 
        if ((autoscroll_x != last_autoscroll_x) || (autoscroll_y != last_autoscroll_y) || (autoscroll_x == 0 && autoscroll_y == 0)) {
@@ -610,23 +592,22 @@ Editor::autoscroll_canvas ()
        double new_pixel;
        double target_pixel;
 
-       assert (_drag);
-
        if (autoscroll_x_distance != 0) {
+
                if (autoscroll_x > 0) {
-                       autoscroll_x_distance = (unit_to_frame (_drag->current_pointer_x()) - (leftmost_frame + current_page_frames())) / 3;
+                       autoscroll_x_distance = (_drags->current_pointer_frame() - (leftmost_frame + current_page_frames())) / 3;
                } else if (autoscroll_x < 0) {
-                       autoscroll_x_distance = (leftmost_frame - unit_to_frame (_drag->current_pointer_x())) / 3;
+                       autoscroll_x_distance = (leftmost_frame - _drags->current_pointer_frame()) / 3;
 
                }
        }
 
        if (autoscroll_y_distance != 0) {
                if (autoscroll_y > 0) {
-                       autoscroll_y_distance = (_drag->current_pointer_y() - (get_trackview_group_vertical_offset() + _canvas_height)) / 3;
+                       autoscroll_y_distance = (_drags->current_pointer_y() - (get_trackview_group_vertical_offset() + _canvas_height)) / 3;
                } else if (autoscroll_y < 0) {
 
-                       autoscroll_y_distance = (vertical_adjustment.get_value () - _drag->current_pointer_y()) / 3;
+                       autoscroll_y_distance = (vertical_adjustment.get_value () - _drags->current_pointer_y()) / 3;
                }
        }
 
@@ -656,7 +637,7 @@ Editor::autoscroll_canvas ()
                        new_pixel = vertical_pos - autoscroll_y_distance;
                }
 
-               target_pixel = _drag->current_pointer_y() - autoscroll_y_distance;
+               target_pixel = _drags->current_pointer_y() - autoscroll_y_distance;
                target_pixel = max (target_pixel, 0.0);
 
        } else if (autoscroll_y > 0) {
@@ -671,7 +652,7 @@ Editor::autoscroll_canvas ()
 
                new_pixel = min (top_of_bottom_of_canvas, new_pixel);
 
-               target_pixel = _drag->current_pointer_y() + autoscroll_y_distance;
+               target_pixel = _drags->current_pointer_y() + autoscroll_y_distance;
 
                /* don't move to the full canvas height because the item will be invisible
                   (its top edge will line up with the bottom of the visible canvas.
@@ -680,7 +661,7 @@ Editor::autoscroll_canvas ()
                target_pixel = min (target_pixel, full_canvas_height - 10);
 
        } else {
-               target_pixel = _drag->current_pointer_y();
+               target_pixel = _drags->current_pointer_y();
                new_pixel = vertical_pos;
        }
 
@@ -702,11 +683,11 @@ Editor::autoscroll_canvas ()
        Gdk::ModifierType mask;
        canvas_window->get_pointer (x, y, mask);
        ev.type = GDK_MOTION_NOTIFY;
-       ev.state &= Gdk::BUTTON1_MASK;
+       ev.state = Gdk::BUTTON1_MASK;
        ev.x = x;
        ev.y = y;
 
-       motion_handler (_drag->item(), (GdkEvent*) &ev, true);
+       motion_handler (0, (GdkEvent*) &ev, true);
 
        autoscroll_cnt++;
 
@@ -725,7 +706,7 @@ Editor::autoscroll_canvas ()
 void
 Editor::start_canvas_autoscroll (int dx, int dy)
 {
-       if (!session || autoscroll_active) {
+       if (!_session || autoscroll_active) {
                return;
        }
 
@@ -746,7 +727,6 @@ Editor::start_canvas_autoscroll (int dx, int dy)
 void
 Editor::stop_canvas_autoscroll ()
 {
-
        if (autoscroll_timeout_tag >= 0) {
                g_source_remove (autoscroll_timeout_tag);
                autoscroll_timeout_tag = -1;
@@ -758,6 +738,7 @@ Editor::stop_canvas_autoscroll ()
 bool
 Editor::left_track_canvas (GdkEventCrossing */*ev*/)
 {
+        DropDownKeys ();
        set_entered_track (0);
        set_entered_regionview (0);
        reset_canvas_action_sensitivity (false);
@@ -786,20 +767,20 @@ Editor::tie_vertical_scrolling ()
 }
 
 void
-Editor::scroll_canvas_horizontally ()
+Editor::set_horizontal_position (double p)
 {
        /* horizontal scrolling only */
        double x1, y1, x2, y2, x_delta;
        _master_group->get_bounds (x1, y1, x2, y2);
 
-       x_delta = - (x1 +  horizontal_adjustment.get_value());
+       x_delta = - (x1 + p);
 
        _master_group->move (x_delta, 0);
        timebar_group->move (x_delta, 0);
        time_line_group->move (x_delta, 0);
        cursor_group->move (x_delta, 0);
 
-       leftmost_frame = (nframes64_t) floor (horizontal_adjustment.get_value() * frames_per_unit);
+       leftmost_frame = (nframes64_t) floor (p * frames_per_unit);
 
        update_fixed_rulers ();
        redisplay_tempo (true);
@@ -809,7 +790,7 @@ Editor::scroll_canvas_horizontally ()
        }
 
 #ifndef GTKOSX
-       if (!autoscroll_active) {
+       if (!autoscroll_active && !_stationary_playhead) {
                /* force rulers and canvas to move in lock step */
                while (gtk_events_pending ()) {
                        gtk_main_iteration ();
@@ -896,8 +877,8 @@ Editor::color_handler()
 /*
        redisplay_tempo (true);
 
-       if (session)
-               session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks); // redraw metric markers
+       if (_session)
+             _session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks); // redraw metric markers
 */
 }
 
@@ -927,3 +908,9 @@ Editor::update_canvas_now ()
                track_canvas->update_now ();
        }
 }
+
+double
+Editor::horizontal_position () const
+{
+       return frame_to_unit (leftmost_frame);
+}