From 90c1e0ffd284f0383073a63c5b2b83208c4f49d9 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 23 Jan 2015 15:15:29 -0500 Subject: [PATCH] allow use of null pointer as a valid cursor (implies using cursor of parent window) --- gtk2_ardour/editor_canvas.cc | 10 +++++----- gtk2_ardour/editor_drag.cc | 21 +++++++++++---------- gtk2_ardour/mouse_cursors.cc | 7 +++++++ gtk2_ardour/mouse_cursors.h | 11 +++++++++++ 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/gtk2_ardour/editor_canvas.cc b/gtk2_ardour/editor_canvas.cc index 611d5ac054..4a5378f145 100644 --- a/gtk2_ardour/editor_canvas.cc +++ b/gtk2_ardour/editor_canvas.cc @@ -1012,7 +1012,7 @@ Editor::set_canvas_cursor (Gdk::Cursor* cursor) { Glib::RefPtr win = _track_canvas->get_window(); - if (win && cursor) { + if (win && !_cursors->is_invalid (cursor)) { win->set_cursor (*cursor); } } @@ -1020,7 +1020,7 @@ Editor::set_canvas_cursor (Gdk::Cursor* cursor) size_t Editor::push_canvas_cursor (Gdk::Cursor* cursor) { - if (cursor) { + if (!_cursors->is_invalid (cursor)) { _cursor_stack.push_back (cursor); set_canvas_cursor (cursor); } @@ -1095,7 +1095,7 @@ Editor::which_trim_cursor (bool left) const Gdk::Cursor* Editor::which_mode_cursor () const { - Gdk::Cursor* mode_cursor = 0; + Gdk::Cursor* mode_cursor = _cursors->invalid_cursor (); switch (mouse_mode) { case MouseRange: @@ -1161,7 +1161,7 @@ Editor::which_mode_cursor () const Gdk::Cursor* Editor::which_track_cursor () const { - Gdk::Cursor* cursor = 0; + Gdk::Cursor* cursor = _cursors->invalid_cursor(); switch (_join_object_range_state) { case JOIN_OBJECT_RANGE_NONE: @@ -1332,7 +1332,7 @@ Editor::choose_canvas_cursor_on_entry (ItemType type) Gdk::Cursor* cursor = which_canvas_cursor(type); - if (cursor) { + if (!_cursors->is_invalid (cursor)) { // Push a new enter context const EnterContext ctx = { type, CursorContext::create(*this, cursor) }; _enter_stack.push_back(ctx); diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index 17fe93139a..9d97f132fc 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -234,11 +234,13 @@ Drag::swap_grab (ArdourCanvas::Item* new_item, Gdk::Cursor* cursor, uint32_t /*t _item->ungrab (); _item = new_item; - if (cursor == 0) { - _item->grab (); + if (!_cursor_ctx) { + _cursor_ctx = CursorContext::create (*_editor, cursor); } else { - _item->grab (); + _cursor_ctx->change (cursor); } + + _item->grab (); } void @@ -271,12 +273,11 @@ Drag::start_grab (GdkEvent* event, Gdk::Cursor *cursor) _last_pointer_y = _grab_y; - if (cursor == 0) { - _item->grab (); - } else { + _item->grab (); + + if (!_editor->cursors()->is_invalid (cursor)) { /* CAIROCANVAS need a variant here that passes *cursor */ - _item->grab (); - _cursor_ctx = CursorContext::create(*_editor, cursor); + _cursor_ctx = CursorContext::create (*_editor, cursor); } if (_editor->session() && _editor->session()->transport_rolling()) { @@ -4151,7 +4152,7 @@ SelectionDrag::start_grab (GdkEvent* event, Gdk::Cursor*) return; } - Gdk::Cursor* cursor = 0; + Gdk::Cursor* cursor = _editor->cursors()->invalid_cursor(); switch (_operation) { case CreateSelection: @@ -4489,7 +4490,7 @@ RangeMarkerBarDrag::start_grab (GdkEvent* event, Gdk::Cursor *) return; } - Gdk::Cursor* cursor = 0; + Gdk::Cursor* cursor = _editor->cursors()->invalid_cursor(); if (!_editor->temp_location) { _editor->temp_location = new Location (*_editor->session()); diff --git a/gtk2_ardour/mouse_cursors.cc b/gtk2_ardour/mouse_cursors.cc index d735ed6c64..93bba191f8 100644 --- a/gtk2_ardour/mouse_cursors.cc +++ b/gtk2_ardour/mouse_cursors.cc @@ -211,4 +211,11 @@ MouseCursors::set_cursor_set (const std::string& name) midi_resize = new Cursor (SIZING); midi_erase = new Cursor (DRAPED_BOX); up_down = new Cursor (SB_V_DOUBLE_ARROW); + + { + char pix[4] = { 0, 0, 0, 0 }; + RefPtr bits = Bitmap::create (pix, 2, 2); + Color c; + _invalid = new Cursor (bits, bits, c, c, 0, 0); + } } diff --git a/gtk2_ardour/mouse_cursors.h b/gtk2_ardour/mouse_cursors.h index 6c5c94b5e9..756b2657d9 100644 --- a/gtk2_ardour/mouse_cursors.h +++ b/gtk2_ardour/mouse_cursors.h @@ -73,11 +73,22 @@ public: Gdk::Cursor* expand_left_right; Gdk::Cursor* expand_up_down; + /* This cursor is not intended to be used directly, it just + serves as an out-of-bounds value when we need to indicate + "no cursor". NULL/0 doesn't work for this, because it + is actually a valid value for a Gdk::Cursor - it indicates + "use the parent window's cursor" + */ + + bool is_invalid (Gdk::Cursor* c) const { return c == _invalid; } + Gdk::Cursor* invalid_cursor() const { return _invalid; } + private: std::string _cursor_set; void drop_all (); Gdk::Cursor* make_cursor (const char* name, int hotspot_x = 0, int hotspot_y = 0); + Gdk::Cursor* _invalid; }; #endif /* __gtk2_ardour_mouse_cursors__ */