Tidy up region gain line drawing slightly so that it doesn't overhang its region...
[ardour.git] / gtk2_ardour / 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 __ardour_keyboard_h__
21 #define __ardour_keyboard_h__
22
23 #include <map>
24 #include <vector>
25 #include <string>
26
27 #include <sigc++/signal.h>
28 #include <gtk/gtk.h>
29 #include <gtkmm/window.h>
30 #include <gtkmm/accelkey.h>
31
32 #include <ardour/types.h>
33 #include <pbd/stateful.h>
34
35 #include "selection.h"
36
37 using std::string;
38
39 class Keyboard : public sigc::trackable, Stateful
40 {
41   public:
42         Keyboard ();
43         ~Keyboard ();
44
45         XMLNode& get_state (void);
46         int set_state (const XMLNode&);
47
48         typedef std::vector<uint32_t> State;
49         typedef uint32_t ModifierMask;
50
51         static uint32_t PrimaryModifier;
52         static uint32_t SecondaryModifier;
53         static uint32_t TertiaryModifier;
54         static uint32_t Level4Modifier;
55         static uint32_t CopyModifier;
56         static uint32_t RangeSelectModifier;
57
58         static void set_primary_modifier (uint32_t newval) {
59                 set_modifier (newval, PrimaryModifier);
60         }
61         static void set_secondary_modifier (uint32_t newval) {
62                 set_modifier (newval, SecondaryModifier);
63         }
64         static void set_tertiary_modifier (uint32_t newval) {
65                 set_modifier (newval, TertiaryModifier);
66         }
67         static void set_level4_modifier (uint32_t newval) {
68                 set_modifier (newval, Level4Modifier);
69         }
70         static void set_copy_modifier (uint32_t newval) {
71                 set_modifier (newval, CopyModifier);
72         }
73         static void set_range_select_modifier (uint32_t newval) {
74                 set_modifier (newval, RangeSelectModifier);
75         }
76
77         bool key_is_down (uint32_t keyval);
78
79         static GdkModifierType RelevantModifierKeyMask;
80
81         static bool no_modifier_keys_pressed(GdkEventButton* ev) {
82                 return (ev->state & RelevantModifierKeyMask) == 0;
83         }
84
85         bool leave_window (GdkEventCrossing *ev, Gtk::Window*);
86         bool enter_window (GdkEventCrossing *ev, Gtk::Window*);
87
88         static bool modifier_state_contains (guint state, ModifierMask);
89         static bool modifier_state_equals   (guint state, ModifierMask);
90
91         static Selection::Operation selection_type (guint state);
92
93         static bool no_modifiers_active (guint state);
94
95         static void set_snap_modifier (guint);
96         static ModifierMask snap_modifier () { return ModifierMask (snap_mod); }
97
98         static guint edit_button() { return edit_but; }
99         static void set_edit_button (guint);
100         static guint edit_modifier() { return edit_mod; }
101         static void set_edit_modifier(guint);
102
103         static guint delete_button() { return delete_but; }
104         static void set_delete_button(guint);
105         static guint delete_modifier() { return delete_mod; }
106         static void set_delete_modifier(guint);
107
108         static bool is_edit_event (GdkEventButton*);
109         static bool is_delete_event (GdkEventButton*);
110         static bool is_context_menu_event (GdkEventButton*);
111         static bool is_button2_event (GdkEventButton*);
112
113         static Keyboard& the_keyboard() { return *_the_keyboard; }
114
115         static bool some_magic_widget_has_focus ();
116         static void magic_widget_grab_focus ();
117         static void magic_widget_drop_focus ();
118
119         static void setup_keybindings ();
120         static void keybindings_changed ();
121         static void save_keybindings ();
122         static bool load_keybindings (std::string path);
123         static void set_can_save_keybindings (bool yn);
124         static std::string current_binding_name () { return _current_binding_name; }
125         static std::map<std::string,std::string> binding_files;
126
127         struct AccelKeyLess {
128             bool operator() (const Gtk::AccelKey a, const Gtk::AccelKey b) const {
129                     if (a.get_key() != b.get_key()) {
130                             return a.get_key() < b.get_key();
131                     } else {
132                             return a.get_mod() < b.get_mod();
133                     }
134             }
135         };
136
137   private:
138         static Keyboard* _the_keyboard;
139
140         guint           snooper_id;
141         State           state;
142
143         static guint     edit_but;
144         static guint     edit_mod;
145         static guint     delete_but;
146         static guint     delete_mod;
147         static guint     snap_mod;
148         static guint     button2_modifiers;
149         static Gtk::Window* current_window;
150         static std::string user_keybindings_path;
151         static bool can_save_keybindings;
152         static bool bindings_changed_after_save_became_legal;
153         static std::string _current_binding_name;
154
155         typedef std::pair<std::string,std::string> two_strings;
156
157         static std::map<Gtk::AccelKey,two_strings,AccelKeyLess> release_keys;
158
159         static gint _snooper (GtkWidget*, GdkEventKey*, gpointer);
160         gint snooper (GtkWidget*, GdkEventKey*);
161
162         static void set_modifier (uint32_t newval, uint32_t& variable);
163
164         static bool _some_magic_widget_has_focus;
165 };
166
167 #endif /* __ardour_keyboard_h__ */