+ if (!_cursors->is_invalid (cursor)) {
+ _cursor_stack.push_back (cursor);
+ set_canvas_cursor (cursor);
+ }
+ return _cursor_stack.size() - 1;
+}
+
+void
+Editor::pop_canvas_cursor ()
+{
+ while (true) {
+ if (_cursor_stack.size() <= 1) {
+ PBD::error << "attempt to pop default cursor" << endmsg;
+ return;
+ }
+
+ _cursor_stack.pop_back();
+ if (_cursor_stack.back()) {
+ /* Popped to an existing cursor, we're done. Otherwise, the
+ context that created this cursor has been destroyed, so we need
+ to skip to the next down the stack. */
+ set_canvas_cursor (_cursor_stack.back());
+ return;
+ }
+ }
+}
+
+Gdk::Cursor*
+Editor::which_grabber_cursor () const
+{
+ Gdk::Cursor* c = _cursors->grabber;
+
+ switch (_edit_point) {
+ case EditAtMouse:
+ c = _cursors->grabber_edit_point;
+ break;
+ default:
+ boost::shared_ptr<Movable> m = _movable.lock();
+ if (m && m->locked()) {
+ c = _cursors->speaker;
+ }
+ break;
+ }
+
+ return c;
+}
+
+Gdk::Cursor*
+Editor::which_trim_cursor (bool left) const
+{
+ if (!entered_regionview) {
+ return 0;
+ }
+
+ Trimmable::CanTrim ct = entered_regionview->region()->can_trim ();
+
+ if (left) {
+
+ if (ct & Trimmable::FrontTrimEarlier) {
+ return _cursors->left_side_trim;
+ } else {
+ return _cursors->left_side_trim_right_only;
+ }
+ } else {
+ if (ct & Trimmable::EndTrimLater) {
+ return _cursors->right_side_trim;
+ } else {
+ return _cursors->right_side_trim_left_only;
+ }
+ }
+}
+
+Gdk::Cursor*
+Editor::which_mode_cursor () const
+{
+ Gdk::Cursor* mode_cursor = MouseCursors::invalid_cursor ();
+
+ switch (mouse_mode) {
+ case MouseRange:
+ mode_cursor = _cursors->selector;
+ break;
+
+ case MouseCut:
+ mode_cursor = _cursors->scissors;
+ break;
+
+ case MouseObject:
+ case MouseContent:
+ /* don't use mode cursor, pick a grabber cursor based on the item */
+ break;
+
+ case MouseDraw:
+ mode_cursor = _cursors->midi_pencil;
+ break;
+
+ case MouseTimeFX:
+ mode_cursor = _cursors->time_fx; // just use playhead
+ break;
+
+ case MouseAudition:
+ mode_cursor = _cursors->speaker;
+ break;
+ }
+
+ /* up-down cursor as a cue that automation can be dragged up and down when in join object/range mode */
+ if (get_smart_mode()) {
+
+ double x, y;
+ get_pointer_position (x, y);
+
+ if (x >= 0 && y >= 0) {
+
+ vector<ArdourCanvas::Item const *> items;
+
+ /* Note how we choose a specific scroll group to get
+ * items from. This could be problematic.
+ */
+
+ hv_scroll_group->add_items_at_point (ArdourCanvas::Duple (x,y), items);
+
+ // first item will be the upper most
+
+ if (!items.empty()) {
+ const ArdourCanvas::Item* i = items.front();
+
+ if (i && i->parent() && i->parent()->get_data (X_("timeselection"))) {
+ pair<TimeAxisView*, int> tvp = trackview_by_y_position (_last_motion_y);
+ if (dynamic_cast<AutomationTimeAxisView*> (tvp.first)) {
+ mode_cursor = _cursors->up_down;
+ }
+ }
+ }
+ }
+ }
+
+ return mode_cursor;
+}
+
+Gdk::Cursor*
+Editor::which_track_cursor () const
+{
+ Gdk::Cursor* cursor = MouseCursors::invalid_cursor();
+
+ switch (_join_object_range_state) {
+ case JOIN_OBJECT_RANGE_NONE:
+ case JOIN_OBJECT_RANGE_OBJECT:
+ cursor = which_grabber_cursor ();
+ break;
+ case JOIN_OBJECT_RANGE_RANGE:
+ cursor = _cursors->selector;
+ break;
+ }
+
+ return cursor;
+}
+
+Gdk::Cursor*
+Editor::which_canvas_cursor(ItemType type) const
+{
+ Gdk::Cursor* cursor = which_mode_cursor ();
+
+ if (mouse_mode == MouseRange) {
+ switch (type) {
+ case StartSelectionTrimItem:
+ cursor = _cursors->left_side_trim;
+ break;
+ case EndSelectionTrimItem:
+ cursor = _cursors->right_side_trim;
+ break;
+ default:
+ break;
+ }
+ }
+
+ if ((mouse_mode == MouseObject || get_smart_mode ()) ||
+ mouse_mode == MouseContent) {
+
+ /* find correct cursor to use in object/smart mode */
+
+ switch (type) {
+ case RegionItem:
+ /* We don't choose a cursor for these items on top of a region view,
+ because this would push a new context on the enter stack which
+ means switching the region context for things like smart mode
+ won't actualy change the cursor. */
+ // case RegionViewNameHighlight:
+ // case RegionViewName:
+ // case WaveItem:
+ case StreamItem:
+ case AutomationTrackItem:
+ cursor = which_track_cursor ();
+ break;
+ case PlayheadCursorItem:
+ switch (_edit_point) {
+ case EditAtMouse:
+ cursor = _cursors->grabber_edit_point;
+ break;
+ default:
+ cursor = _cursors->grabber;
+ break;
+ }
+ break;
+ case SelectionItem:
+ cursor = _cursors->selector;
+ break;
+ case ControlPointItem:
+ cursor = _cursors->fader;
+ break;
+ case GainLineItem:
+ cursor = _cursors->cross_hair;
+ break;
+ case AutomationLineItem:
+ cursor = _cursors->cross_hair;
+ break;
+ case StartSelectionTrimItem:
+ cursor = _cursors->left_side_trim;
+ break;
+ case EndSelectionTrimItem:
+ cursor = _cursors->right_side_trim;
+ break;
+ case FadeInItem:
+ cursor = _cursors->fade_in;
+ break;
+ case FadeInHandleItem:
+ cursor = _cursors->fade_in;
+ break;
+ case FadeInTrimHandleItem:
+ cursor = _cursors->fade_in;
+ break;
+ case FadeOutItem:
+ cursor = _cursors->fade_out;
+ break;
+ case FadeOutHandleItem:
+ cursor = _cursors->fade_out;
+ break;
+ case FadeOutTrimHandleItem:
+ cursor = _cursors->fade_out;
+ break;
+ case FeatureLineItem:
+ cursor = _cursors->cross_hair;
+ break;
+ case LeftFrameHandle:
+ if ( effective_mouse_mode() == MouseObject ) // (smart mode): if the user is in the btm half, show the trim cursor
+ cursor = which_trim_cursor (true);
+ else
+ cursor = _cursors->selector; // (smart mode): in the top half, just show the selection (range) cursor
+ break;
+ case RightFrameHandle:
+ if ( effective_mouse_mode() == MouseObject ) //see above
+ cursor = which_trim_cursor (false);
+ else
+ cursor = _cursors->selector;
+ break;
+ case StartCrossFadeItem:
+ cursor = _cursors->fade_in;
+ break;
+ case EndCrossFadeItem:
+ cursor = _cursors->fade_out;
+ break;
+ case CrossfadeViewItem:
+ cursor = _cursors->cross_hair;
+ break;
+ case NoteItem:
+ cursor = _cursors->grabber_note;
+ default:
+ break;
+ }
+
+ } else if (mouse_mode == MouseDraw) {
+
+ /* ControlPointItem is not really specific to region gain mode
+ but it is the same cursor so don't worry about this for now.
+ The result is that we'll see the fader cursor if we enter
+ non-region-gain-line control points while in MouseDraw
+ mode, even though we can't edit them in this mode.
+ */
+
+ switch (type) {
+ case GainLineItem:
+ case ControlPointItem:
+ cursor = _cursors->fader;
+ break;
+ case NoteItem:
+ cursor = _cursors->grabber_note;
+ default:
+ break;
+ }
+ }
+
+ switch (type) {
+ /* These items use the timebar cursor at all times */
+ case TimecodeRulerItem:
+ case MinsecRulerItem:
+ case BBTRulerItem:
+ case SamplesRulerItem:
+ cursor = _cursors->timebar;
+ break;
+
+ /* These items use the grabber cursor at all times */
+ case MeterMarkerItem:
+ case TempoMarkerItem:
+ case MeterBarItem:
+ case TempoBarItem:
+ case MarkerItem:
+ case MarkerBarItem:
+ case RangeMarkerBarItem:
+ case CdMarkerBarItem:
+ case VideoBarItem:
+ case TransportMarkerBarItem:
+ case DropZoneItem:
+ cursor = which_grabber_cursor();
+ break;
+
+ default:
+ break;
+ }
+
+ return cursor;
+}
+
+void
+Editor::choose_canvas_cursor_on_entry (ItemType type)
+{
+ if (_drags->active()) {
+ return;
+ }
+
+ Gdk::Cursor* cursor = which_canvas_cursor(type);
+
+ if (!_cursors->is_invalid (cursor)) {
+ // Push a new enter context
+ const EnterContext ctx = { type, CursorContext::create(*this, cursor) };
+ _enter_stack.push_back(ctx);
+ }
+}
+
+void
+Editor::update_all_enter_cursors ()
+{
+ for (std::vector<EnterContext>::iterator i = _enter_stack.begin(); i != _enter_stack.end(); ++i) {
+ i->cursor_ctx->change(which_canvas_cursor(i->item_type));
+ }
+}
+
+double
+Editor::trackviews_height() const
+{
+ if (!_trackview_group) {
+ return 0;
+ }
+
+ return _visible_canvas_height - _trackview_group->canvas_origin().y;