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 __libgtkmm2ext_keyboard_h__
21 #define __libgtkmm2ext_keyboard_h__
27 #include <sigc++/signal.h>
29 #include <gtkmm/accelkey.h>
31 #include "pbd/stateful.h"
39 class Keyboard : public sigc::trackable, PBD::Stateful
45 XMLNode& get_state (void);
46 int set_state (const XMLNode&, int version);
48 virtual void setup_keybindings () = 0;
50 typedef std::vector<uint32_t> State;
51 typedef uint32_t ModifierMask;
53 static uint32_t PrimaryModifier;
54 static uint32_t SecondaryModifier;
55 static uint32_t TertiaryModifier;
56 static uint32_t Level4Modifier;
57 static uint32_t CopyModifier;
58 static uint32_t RangeSelectModifier;
59 static uint32_t GainFineScaleModifier;
60 static uint32_t GainExtraFineScaleModifier;
62 static const char* primary_modifier_name ();
63 static const char* secondary_modifier_name ();
64 static const char* tertiary_modifier_name ();
65 static const char* level4_modifier_name ();
66 static const char* copy_modifier_name ();
67 static const char* rangeselect_modifier_name ();
69 static void set_primary_modifier (uint32_t newval) {
70 set_modifier (newval, PrimaryModifier);
72 static void set_secondary_modifier (uint32_t newval) {
73 set_modifier (newval, SecondaryModifier);
75 static void set_tertiary_modifier (uint32_t newval) {
76 set_modifier (newval, TertiaryModifier);
78 static void set_level4_modifier (uint32_t newval) {
79 set_modifier (newval, Level4Modifier);
81 static void set_copy_modifier (uint32_t newval) {
82 set_modifier (newval, CopyModifier);
84 static void set_range_select_modifier (uint32_t newval) {
85 set_modifier (newval, RangeSelectModifier);
88 bool key_is_down (uint32_t keyval);
90 static GdkModifierType RelevantModifierKeyMask;
92 static bool no_modifier_keys_pressed(GdkEventButton* ev) {
93 return (ev->state & RelevantModifierKeyMask) == 0;
96 static bool no_modifier_keys_pressed(GdkEventKey* ev) {
97 return (ev->state & RelevantModifierKeyMask) == 0;
100 bool leave_window (GdkEventCrossing *ev, Gtk::Window*);
101 bool enter_window (GdkEventCrossing *ev, Gtk::Window*);
103 static bool modifier_state_contains (guint state, ModifierMask);
104 static bool modifier_state_equals (guint state, ModifierMask);
106 static bool no_modifiers_active (guint state);
108 static void set_snap_modifier (guint);
110 /** @return Modifier mask to temporarily toggle grid setting; with this modifier
111 * - magnetic or normal grid should become no grid and
112 * - no grid should become normal grid
114 static ModifierMask snap_modifier () { return ModifierMask (snap_mod); }
116 static guint edit_button() { return edit_but; }
117 static void set_edit_button (guint);
118 static guint edit_modifier() { return edit_mod; }
119 static void set_edit_modifier(guint);
121 static guint delete_button() { return delete_but; }
122 static void set_delete_button(guint);
123 static guint delete_modifier() { return delete_mod; }
124 static void set_delete_modifier(guint);
126 static guint insert_note_button() { return insert_note_but; }
127 static void set_insert_note_button (guint);
128 static guint insert_note_modifier() { return insert_note_mod; }
129 static void set_insert_note_modifier(guint);
131 static bool is_edit_event (GdkEventButton*);
132 static bool is_delete_event (GdkEventButton*);
133 static bool is_insert_note_event (GdkEventButton*);
134 static bool is_context_menu_event (GdkEventButton*);
135 static bool is_button2_event (GdkEventButton*);
137 static Keyboard& the_keyboard() { return *_the_keyboard; }
139 static bool some_magic_widget_has_focus ();
140 static void magic_widget_grab_focus ();
141 static void magic_widget_drop_focus ();
143 static void close_current_dialog ();
145 static void keybindings_changed ();
146 static void save_keybindings ();
147 static bool load_keybindings (std::string path);
148 static void set_can_save_keybindings (bool yn);
149 static std::string current_binding_name () { return _current_binding_name; }
150 static std::map<std::string,std::string> binding_files;
152 struct AccelKeyLess {
153 bool operator() (const Gtk::AccelKey a, const Gtk::AccelKey b) const {
154 if (a.get_key() != b.get_key()) {
155 return a.get_key() < b.get_key();
157 return a.get_mod() < b.get_mod();
162 sigc::signal0<void> ShiftReleased;
165 static Keyboard* _the_keyboard;
170 static guint edit_but;
171 static guint edit_mod;
172 static guint delete_but;
173 static guint delete_mod;
174 static guint insert_note_but;
175 static guint insert_note_mod;
176 static guint snap_mod;
177 static guint button2_modifiers;
178 static Gtk::Window* current_window;
179 static std::string user_keybindings_path;
180 static bool can_save_keybindings;
181 static bool bindings_changed_after_save_became_legal;
182 static std::string _current_binding_name;
184 typedef std::pair<std::string,std::string> two_strings;
186 static std::map<Gtk::AccelKey,two_strings,AccelKeyLess> release_keys;
188 static gint _snooper (GtkWidget*, GdkEventKey*, gpointer);
189 gint snooper (GtkWidget*, GdkEventKey*);
191 static void set_modifier (uint32_t newval, uint32_t& variable);
193 static bool _some_magic_widget_has_focus;
198 #endif /* __libgtkmm2ext_keyboard_h__ */