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__
27 #include <sigc++/signal.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
42 XMLNode& get_state (void);
43 int set_state (const XMLNode&);
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);
93 static ModifierMask snap_modifier () { return ModifierMask (snap_mod); }
95 static guint edit_button() { return edit_but; }
96 static void set_edit_button (guint);
97 static guint edit_modifier() { return edit_mod; }
98 static void set_edit_modifier(guint);
100 static guint delete_button() { return delete_but; }
101 static void set_delete_button(guint);
102 static guint delete_modifier() { return delete_mod; }
103 static void set_delete_modifier(guint);
105 static bool is_edit_event (GdkEventButton*);
106 static bool is_delete_event (GdkEventButton*);
107 static bool is_context_menu_event (GdkEventButton*);
108 static bool is_button2_event (GdkEventButton*);
110 static Keyboard& the_keyboard() { return *_the_keyboard; }
112 static bool some_magic_widget_has_focus ();
113 static void magic_widget_grab_focus ();
114 static void magic_widget_drop_focus ();
116 static void setup_keybindings ();
117 static void keybindings_changed ();
118 static void save_keybindings ();
119 static bool load_keybindings (std::string path);
120 static void set_can_save_keybindings (bool yn);
121 static std::string current_binding_name () { return _current_binding_name; }
122 static std::map<std::string,std::string> binding_files;
124 struct AccelKeyLess {
125 bool operator() (const Gtk::AccelKey a, const Gtk::AccelKey b) const {
126 if (a.get_key() != b.get_key()) {
127 return a.get_key() < b.get_key();
129 return a.get_mod() < b.get_mod();
135 static Keyboard* _the_keyboard;
140 static guint edit_but;
141 static guint edit_mod;
142 static guint delete_but;
143 static guint delete_mod;
144 static guint snap_mod;
145 static guint button2_modifiers;
146 static Gtk::Window* current_window;
147 static std::string user_keybindings_path;
148 static bool can_save_keybindings;
149 static bool bindings_changed_after_save_became_legal;
150 static std::string _current_binding_name;
152 typedef std::pair<std::string,std::string> two_strings;
154 static std::map<Gtk::AccelKey,two_strings,AccelKeyLess> release_keys;
156 static gint _snooper (GtkWidget*, GdkEventKey*, gpointer);
157 gint snooper (GtkWidget*, GdkEventKey*);
159 static void set_modifier (uint32_t newval, uint32_t& variable);
161 static bool _some_magic_widget_has_focus;
164 #endif /* __ardour_keyboard_h__ */