Compiler fix for 201110.
[ardour.git] / libs / gtkmm2ext / gtkmm2ext / keyboard.h
1 /*
2     Copyright (C) 2001 Paul Davis
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
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef __libgtkmm2ext_keyboard_h__
21 #define __libgtkmm2ext_keyboard_h__
22
23 #include <map>
24 #include <vector>
25 #include <string>
26
27 #include <gtk/gtk.h>
28 #include <gtkmm/accelkey.h>
29
30 #include "pbd/stateful.h"
31 #include "pbd/signals.h"
32
33 #include "gtkmm2ext/visibility.h"
34
35 namespace Gtk {
36         class Window;
37 }
38
39 namespace Gtkmm2ext {
40
41 class Bindings;
42 class ActionMap;
43
44 class LIBGTKMM2EXT_API Keyboard : public sigc::trackable, PBD::Stateful
45 {
46   public:
47         Keyboard ();
48         ~Keyboard ();
49
50         XMLNode& get_state (void);
51         int set_state (const XMLNode&, int version);
52
53         virtual void setup_keybindings () = 0;
54         static void reset_relevant_modifier_key_mask ();
55
56         typedef std::vector<uint32_t> State;
57         typedef uint32_t ModifierMask;
58
59         static uint32_t PrimaryModifier;
60         static uint32_t SecondaryModifier;
61         static uint32_t TertiaryModifier;
62         static uint32_t Level4Modifier;
63         static uint32_t CopyModifier;
64         static uint32_t RangeSelectModifier;
65         static uint32_t GainFineScaleModifier;
66         static uint32_t GainExtraFineScaleModifier;
67
68         // Modifiers for scroll wheel
69         static uint32_t ScrollZoomVerticalModifier;
70         static uint32_t ScrollZoomHorizontalModifier;
71         static uint32_t ScrollHorizontalModifier;
72
73         static const char* primary_modifier_name ();
74         static const char* secondary_modifier_name ();
75         static const char* tertiary_modifier_name ();
76         static const char* level4_modifier_name ();
77
78         static const char* primary_modifier_short_name ();
79         static const char* secondary_modifier_short_name ();
80         static const char* tertiary_modifier_short_name ();
81         static const char* level4_modifier_short_name ();
82
83         static void set_primary_modifier (uint32_t newval) {
84                 set_modifier (newval, PrimaryModifier);
85         }
86         static void set_secondary_modifier (uint32_t newval) {
87                 set_modifier (newval, SecondaryModifier);
88         }
89         static void set_tertiary_modifier (uint32_t newval) {
90                 set_modifier (newval, TertiaryModifier);
91         }
92         static void set_level4_modifier (uint32_t newval) {
93                 set_modifier (newval, Level4Modifier);
94         }
95         static void set_copy_modifier (uint32_t newval) {
96                 set_modifier (newval, CopyModifier);
97         }
98         static void set_range_select_modifier (uint32_t newval) {
99                 set_modifier (newval, RangeSelectModifier);
100         }
101
102         bool key_is_down (uint32_t keyval);
103
104         static GdkModifierType RelevantModifierKeyMask;
105
106         static bool no_modifier_keys_pressed(GdkEventButton* ev) {
107                 return (ev->state & RelevantModifierKeyMask) == 0;
108         }
109
110         static bool no_modifier_keys_pressed(GdkEventKey* ev) {
111                 return (ev->state & RelevantModifierKeyMask) == 0;
112         }
113
114         bool leave_window (GdkEventCrossing *ev, Gtk::Window*);
115         bool enter_window (GdkEventCrossing *ev, Gtk::Window*);
116         bool focus_in_window (GdkEventFocus *ev, Gtk::Window*);
117         bool focus_out_window (GdkEventFocus *ev, Gtk::Window*);
118
119         static bool modifier_state_contains (guint state, ModifierMask);
120         static bool modifier_state_equals   (guint state, ModifierMask);
121
122         static bool no_modifiers_active (guint state);
123
124         static void set_snap_modifier (guint);
125         /** @return Modifier mask to temporarily toggle grid setting; with this modifier
126          *  - magnetic or normal grid should become no grid and
127          *  - no grid should become normal grid
128          */
129         static ModifierMask snap_modifier () { return ModifierMask (snap_mod); }
130
131         static void set_snap_delta_modifier (guint);
132         /** @return Modifier mask to temporarily toggle between relative and absolute grid setting.
133          *  Absolute grid is for aligning objects with the grid lines.
134          *  Relative grid is for maintaining an initial position relative to the grid lines.
135          *  With this modifier:
136          *  - magnetic or normal grid should snap relative to an initial grid offset
137          *  - no grid should snap relative to the grid.
138          */
139         static ModifierMask snap_delta_modifier () { return ModifierMask (snap_delta_mod); }
140
141         static guint edit_button() { return edit_but; }
142         static void set_edit_button (guint);
143         static guint edit_modifier() { return edit_mod; }
144         static void set_edit_modifier(guint);
145
146         static guint delete_button() { return delete_but; }
147         static void set_delete_button(guint);
148         static guint delete_modifier() { return delete_mod; }
149         static void set_delete_modifier(guint);
150
151         static guint insert_note_button() { return insert_note_but; }
152         static void set_insert_note_button (guint);
153         static guint insert_note_modifier() { return insert_note_mod; }
154         static void set_insert_note_modifier(guint);
155
156         static bool is_edit_event (GdkEventButton*);
157         static bool is_delete_event (GdkEventButton*);
158         static bool is_insert_note_event (GdkEventButton*);
159         static bool is_context_menu_event (GdkEventButton*);
160         static bool is_button2_event (GdkEventButton*);
161
162         static Keyboard& the_keyboard() { return *_the_keyboard; }
163
164         static bool some_magic_widget_has_focus ();
165         static void magic_widget_grab_focus ();
166         static void magic_widget_drop_focus ();
167         static Gtk::Window* get_current_window () { return current_window; };
168
169         static void close_current_dialog ();
170
171         static void keybindings_changed ();
172         static void save_keybindings ();
173         static void set_can_save_keybindings (bool yn);
174         static std::string current_binding_name () { return _current_binding_name; }
175         static std::map<std::string,std::string> binding_files;
176
177         static bool catch_user_event_for_pre_dialog_focus (GdkEvent* ev, Gtk::Window* w);
178
179         static bool load_keybindings (std::string const& path);
180         static void save_keybindings (std::string const& path);
181
182         static std::string binding_filename_suffix;
183
184         int reset_bindings ();
185
186         sigc::signal0<void> ZoomVerticalModifierReleased;
187         static sigc::signal0<void> RelevantModifierKeysChanged;
188
189   protected:
190         static Keyboard* _the_keyboard;
191
192         guint           snooper_id;
193         State           state;
194
195         static guint     edit_but;
196         static guint     edit_mod;
197         static guint     delete_but;
198         static guint     delete_mod;
199         static guint     insert_note_but;
200         static guint     insert_note_mod;
201         static guint     snap_mod;
202         static guint     snap_delta_mod;
203         static guint     button2_modifiers;
204         static Gtk::Window* current_window;
205         static std::string user_keybindings_path;
206         static bool can_save_keybindings;
207         static bool bindings_changed_after_save_became_legal;
208         static std::string _current_binding_name;
209
210         typedef std::pair<std::string,std::string> two_strings;
211
212         static gint _snooper (GtkWidget*, GdkEventKey*, gpointer);
213         gint snooper (GtkWidget*, GdkEventKey*);
214
215         static void set_modifier (uint32_t newval, uint32_t& variable);
216
217         static bool _some_magic_widget_has_focus;
218
219         static Gtk::Window* pre_dialog_active_window;
220
221         static int read_keybindings (std::string const& path);
222         static int store_keybindings (std::string const& path);
223 };
224
225 } /* namespace */
226
227 #endif /* __libgtkmm2ext_keyboard_h__ */