make MouseCursors invalid cursor API be static; use to initialize default cursor...
authorPaul Davis <paul@linuxaudiosystems.com>
Sat, 24 Jan 2015 17:26:58 +0000 (12:26 -0500)
committerPaul Davis <paul@linuxaudiosystems.com>
Sat, 24 Jan 2015 17:26:58 +0000 (12:26 -0500)
gtk2_ardour/editor_canvas.cc
gtk2_ardour/editor_drag.cc
gtk2_ardour/editor_drag.h
gtk2_ardour/mouse_cursors.cc
gtk2_ardour/mouse_cursors.h

index 4a5378f14569f58a3af8b1c8f35057a4c8753030..c1929bd38bb2e664d6827b5b9fa194c3114411bf 100644 (file)
@@ -1013,7 +1013,14 @@ Editor::set_canvas_cursor (Gdk::Cursor* cursor)
        Glib::RefPtr<Gdk::Window> win = _track_canvas->get_window();
 
        if (win && !_cursors->is_invalid (cursor)) {
-               win->set_cursor (*cursor);
+               /* glibmm 2.4 doesn't allow null cursor pointer because it uses
+                  a Gdk::Cursor& as the argument to Gdk::Window::set_cursor().
+                  But a null pointer just means "use parent window cursor",
+                  and so should be allowed. Gtkmm 3.x has fixed this API.
+
+                  For now, drop down and use C API
+               */
+               gdk_window_set_cursor (win->gobj(), cursor ? cursor->gobj() : 0);
        }
 }
 
@@ -1095,7 +1102,7 @@ Editor::which_trim_cursor (bool left) const
 Gdk::Cursor*
 Editor::which_mode_cursor () const
 {
-       Gdk::Cursor* mode_cursor = _cursors->invalid_cursor ();
+       Gdk::Cursor* mode_cursor = MouseCursors::invalid_cursor ();
 
        switch (mouse_mode) {
        case MouseRange:
@@ -1161,7 +1168,7 @@ Editor::which_mode_cursor () const
 Gdk::Cursor*
 Editor::which_track_cursor () const
 {
-       Gdk::Cursor* cursor = _cursors->invalid_cursor();
+       Gdk::Cursor* cursor = MouseCursors::invalid_cursor();
 
        switch (_join_object_range_state) {
        case JOIN_OBJECT_RANGE_NONE:
index 9d97f132fca65b7173cbbbaa81392ef44f034b57..e9c315cf96be3b3608afc7ccdcb5d8ddd06ce7fe 100644 (file)
@@ -4152,7 +4152,7 @@ SelectionDrag::start_grab (GdkEvent* event, Gdk::Cursor*)
                return;
        }
 
-       Gdk::Cursor* cursor = _editor->cursors()->invalid_cursor();
+       Gdk::Cursor* cursor = MouseCursors::invalid_cursor();
 
        switch (_operation) {
        case CreateSelection:
@@ -4490,7 +4490,7 @@ RangeMarkerBarDrag::start_grab (GdkEvent* event, Gdk::Cursor *)
                return;
        }
 
-       Gdk::Cursor* cursor = _editor->cursors()->invalid_cursor();
+       Gdk::Cursor* cursor = MouseCursors::invalid_cursor();
 
        if (!_editor->temp_location) {
                _editor->temp_location = new Location (*_editor->session());
index aec672d92f2ed5379d61bab436bab739794d048b..66ea64eb546f8b0a04f2f4bd8f9cfff46c11f34b 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "cursor_context.h"
 #include "editor_items.h"
+#include "mouse_cursors.h"
 
 namespace ARDOUR {
        class Location;
@@ -58,8 +59,8 @@ public:
 
        void abort ();
        void add (Drag *);
-       void set (Drag *, GdkEvent *, Gdk::Cursor* c = 0);
-       void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
+       void set (Drag *, GdkEvent *, Gdk::Cursor* c = MouseCursors::invalid_cursor());
+       void start_grab (GdkEvent *, Gdk::Cursor* c = MouseCursors::invalid_cursor());
        bool end_grab (GdkEvent *);
        bool have_item (ArdourCanvas::Item *) const;
 
index 93bba191f81ac1023065e8fc14381e722d895774..b50bfa11c6d1c0f4b34bd8a9e02b6a2ae2688358 100644 (file)
@@ -27,6 +27,8 @@
 
 using namespace ARDOUR_UI_UTILS;
 
+Gdk::Cursor* MouseCursors::_invalid = 0;
+
 MouseCursors::MouseCursors ()
        : cross_hair (0)
        , scissors (0)
@@ -211,11 +213,13 @@ 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<Bitmap> bits = Bitmap::create (pix, 2, 2);
-               Color c;
-               _invalid = new Cursor (bits, bits, c, c, 0, 0);
-       }
+}
+
+void
+MouseCursors::create_invalid()
+{
+       char pix[4] = { 0, 0, 0, 0 };
+       Glib::RefPtr<Gdk::Bitmap> bits = Gdk::Bitmap::create (pix, 2, 2);
+       Gdk::Color c;
+       _invalid = new Gdk::Cursor (bits, bits, c, c, 0, 0);
 }
index 756b2657d95446b21640015ff5d70f280ea788b0..7f43e19eecccbbd2daaf80a145b79aa040a98c3b 100644 (file)
@@ -80,15 +80,16 @@ public:
           "use the parent window's cursor"
        */
        
-       bool is_invalid (Gdk::Cursor* c) const { return c == _invalid; }
-       Gdk::Cursor* invalid_cursor() const { return _invalid; }
+       static bool is_invalid (Gdk::Cursor* c) { if (!_invalid) { create_invalid(); } return c == _invalid; }
+       static Gdk::Cursor* invalid_cursor() { if (!_invalid) { create_invalid(); } 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;
+       static Gdk::Cursor* _invalid;
+       static void create_invalid ();
 };
 
 #endif /* __gtk2_ardour_mouse_cursors__ */