Fix thinkos in cubasish theme
[ardour.git] / gtk2_ardour / cursor_context.h
1 /*
2  * Copyright (C) 2014 David Robillard <d@drobilla.net>
3  *
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.
8  *
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.
13  *
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.
17  */
18
19 #ifndef __ardour_gtk_cursor_context_h__
20 #define __ardour_gtk_cursor_context_h__
21
22 #include <boost/shared_ptr.hpp>
23 #include <gdkmm/cursor.h>
24
25 class Editor;
26
27 /**
28    A scoped handle for changing the editor mouse cursor.
29
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.
33
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.
41 */
42 class CursorContext
43 {
44 public:
45         /** A smart handle for a cursor change context. */
46         typedef boost::shared_ptr<CursorContext> Handle;
47
48         ~CursorContext();
49
50         /** Change the editor cursor and return a cursor context handle.
51          *
52          * When the returned handle goes out of scope, the cursor will be reset to
53          * the previous value.
54          */
55         static Handle create(Editor& editor, Gdk::Cursor* cursor);
56
57         /** Change the editor cursor of an existing cursor context. */
58         void change(Gdk::Cursor* cursor);
59
60         /** Set a context handle to a new context.
61          *
62          * If the handle points to an existing context, it will first be reset
63          * before the new context is created.
64          */
65         static void set(Handle* handle, Editor& editor, Gdk::Cursor* cursor);
66
67 private:
68         Editor&      _editor;
69         size_t       _index;
70
71         CursorContext(Editor& editor, Gdk::Cursor* cursor);
72 };
73
74 #endif /* __ardour_gtk_cursor_context_h__ */