Remove idiocy.
[ardour2.git] / gtk2_ardour / keyboard.h
blobe34c424329f3e0761ffd5325be2d7421b8d86b28
1 /*
2 Copyright (C) 2001 Paul Davis
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
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __ardour_keyboard_h__
21 #define __ardour_keyboard_h__
23 #include <map>
24 #include <vector>
25 #include <string>
27 #include <sigc++/signal.h>
28 #include <gtk/gtk.h>
29 #include <gtkmm/accelkey.h>
31 #include "ardour/types.h"
32 #include "pbd/stateful.h"
34 #include "selection.h"
36 class Keyboard : public sigc::trackable, PBD::Stateful
38 public:
39 Keyboard ();
40 ~Keyboard ();
42 XMLNode& get_state (void);
43 int set_state (const XMLNode&, int version);
45 typedef std::vector<uint32_t> State;
46 typedef uint32_t ModifierMask;
48 static uint32_t PrimaryModifier;
49 static uint32_t SecondaryModifier;
50 static uint32_t TertiaryModifier;
51 static uint32_t Level4Modifier;
52 static uint32_t CopyModifier;
53 static uint32_t RangeSelectModifier;
55 static void set_primary_modifier (uint32_t newval) {
56 set_modifier (newval, PrimaryModifier);
58 static void set_secondary_modifier (uint32_t newval) {
59 set_modifier (newval, SecondaryModifier);
61 static void set_tertiary_modifier (uint32_t newval) {
62 set_modifier (newval, TertiaryModifier);
64 static void set_level4_modifier (uint32_t newval) {
65 set_modifier (newval, Level4Modifier);
67 static void set_copy_modifier (uint32_t newval) {
68 set_modifier (newval, CopyModifier);
70 static void set_range_select_modifier (uint32_t newval) {
71 set_modifier (newval, RangeSelectModifier);
74 bool key_is_down (uint32_t keyval);
76 static GdkModifierType RelevantModifierKeyMask;
78 static bool no_modifier_keys_pressed(GdkEventButton* ev) {
79 return (ev->state & RelevantModifierKeyMask) == 0;
82 bool leave_window (GdkEventCrossing *ev, Gtk::Window*);
83 bool enter_window (GdkEventCrossing *ev, Gtk::Window*);
85 static bool modifier_state_contains (guint state, ModifierMask);
86 static bool modifier_state_equals (guint state, ModifierMask);
88 static Selection::Operation selection_type (guint state);
90 static bool no_modifiers_active (guint state);
92 static void set_snap_modifier (guint);
94 /** @return Modifier mask to temporarily toggle grid setting; with this modifier
95 * - magnetic or normal grid should become no grid and
96 * - no grid should become normal grid
98 static ModifierMask snap_modifier () { return ModifierMask (snap_mod); }
100 static guint edit_button() { return edit_but; }
101 static void set_edit_button (guint);
102 static guint edit_modifier() { return edit_mod; }
103 static void set_edit_modifier(guint);
105 static guint delete_button() { return delete_but; }
106 static void set_delete_button(guint);
107 static guint delete_modifier() { return delete_mod; }
108 static void set_delete_modifier(guint);
110 static bool is_edit_event (GdkEventButton*);
111 static bool is_delete_event (GdkEventButton*);
112 static bool is_context_menu_event (GdkEventButton*);
113 static bool is_button2_event (GdkEventButton*);
115 static Keyboard& the_keyboard() { return *_the_keyboard; }
117 static bool some_magic_widget_has_focus ();
118 static void magic_widget_grab_focus ();
119 static void magic_widget_drop_focus ();
121 static void setup_keybindings ();
122 static void keybindings_changed ();
123 static void save_keybindings ();
124 static bool load_keybindings (std::string path);
125 static void set_can_save_keybindings (bool yn);
126 static std::string current_binding_name () { return _current_binding_name; }
127 static std::map<std::string,std::string> binding_files;
129 struct AccelKeyLess {
130 bool operator() (const Gtk::AccelKey a, const Gtk::AccelKey b) const {
131 if (a.get_key() != b.get_key()) {
132 return a.get_key() < b.get_key();
133 } else {
134 return a.get_mod() < b.get_mod();
139 private:
140 static Keyboard* _the_keyboard;
142 guint snooper_id;
143 State state;
145 static guint edit_but;
146 static guint edit_mod;
147 static guint delete_but;
148 static guint delete_mod;
149 static guint snap_mod;
150 static guint button2_modifiers;
151 static Gtk::Window* current_window;
152 static std::string user_keybindings_path;
153 static bool can_save_keybindings;
154 static bool bindings_changed_after_save_became_legal;
155 static std::string _current_binding_name;
157 typedef std::pair<std::string,std::string> two_strings;
159 static std::map<Gtk::AccelKey,two_strings,AccelKeyLess> release_keys;
161 static gint _snooper (GtkWidget*, GdkEventKey*, gpointer);
162 gint snooper (GtkWidget*, GdkEventKey*);
164 static void set_modifier (uint32_t newval, uint32_t& variable);
166 static bool _some_magic_widget_has_focus;
169 #endif /* __ardour_keyboard_h__ */