2 * Copyright (C) 2014 David Robillard <d@drobilla.net>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #ifndef __ardour_gtk_cursor_context_h__
20 #define __ardour_gtk_cursor_context_h__
22 #include <boost/shared_ptr.hpp>
23 #include <gdkmm/cursor.h>
28 A scoped handle for changing the editor mouse cursor.
30 This is a safe way to change the cursor that ensures it is only modified in
31 a strict stack-like fashion. Whenever this handle goes out of scope, the
32 cursor is restored to the previous one.
34 This is not quite entirely fool-proof, there is one case to be careful of:
35 if a cursor context handle exists, to change it, you must first reset that
36 handle (destroying the context) then set it. Assigning a new context to a
37 non-NULL handle will create the new context (pushing a cursor), then destroy
38 the old one, which would attempt to pop a non-top context which is an
39 error. To account for this, when replacing a possibly existing context, use
40 set() which will automatically do the right thing.
45 /** A smart handle for a cursor change context. */
46 typedef boost::shared_ptr<CursorContext> Handle;
50 /** Change the editor cursor and return a cursor context handle.
52 * When the returned handle goes out of scope, the cursor will be reset to
55 static Handle create(Editor& editor, Gdk::Cursor* cursor);
57 /** Change the editor cursor of an existing cursor context. */
58 void change(Gdk::Cursor* cursor);
60 /** Set a context handle to a new context.
62 * If the handle points to an existing context, it will first be reset
63 * before the new context is created.
65 static void set(Handle* handle, Editor& editor, Gdk::Cursor* cursor);
71 CursorContext(Editor& editor, Gdk::Cursor* cursor);
74 #endif /* __ardour_gtk_cursor_context_h__ */