colinf's patch to make the cursor be the dbl vertical arrow when over the track resiz...
[ardour2.git] / gtk2_ardour / keyboard.h
blobe8ded792b9f0de89e494cc592a450ce531613a86
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/window.h>
30 #include <gtkmm/accelkey.h>
32 #include <ardour/types.h>
33 #include <pbd/stateful.h>
35 #include "selection.h"
37 using std::string;
39 class Keyboard : public sigc::trackable, Stateful
41 public:
42 Keyboard ();
43 ~Keyboard ();
45 XMLNode& get_state (void);
46 int set_state (const XMLNode&);
48 typedef std::vector<uint32_t> State;
49 typedef uint32_t ModifierMask;
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;
58 static void set_primary_modifier (uint32_t newval) {
59 set_modifier (newval, PrimaryModifier);
61 static void set_secondary_modifier (uint32_t newval) {
62 set_modifier (newval, SecondaryModifier);
64 static void set_tertiary_modifier (uint32_t newval) {
65 set_modifier (newval, TertiaryModifier);
67 static void set_level4_modifier (uint32_t newval) {
68 set_modifier (newval, Level4Modifier);
70 static void set_copy_modifier (uint32_t newval) {
71 set_modifier (newval, CopyModifier);
73 static void set_range_select_modifier (uint32_t newval) {
74 set_modifier (newval, RangeSelectModifier);
77 bool key_is_down (uint32_t keyval);
79 static GdkModifierType RelevantModifierKeyMask;
81 static bool no_modifier_keys_pressed(GdkEventButton* ev) {
82 return (ev->state & RelevantModifierKeyMask) == 0;
85 bool leave_window (GdkEventCrossing *ev, Gtk::Window*);
86 bool enter_window (GdkEventCrossing *ev, Gtk::Window*);
88 static bool modifier_state_contains (guint state, ModifierMask);
89 static bool modifier_state_equals (guint state, ModifierMask);
91 static Selection::Operation selection_type (guint state);
93 static bool no_modifiers_active (guint state);
95 static void set_snap_modifier (guint);
96 static ModifierMask snap_modifier () { return ModifierMask (snap_mod); }
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);
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);
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*);
113 static Keyboard& the_keyboard() { return *_the_keyboard; }
115 static bool some_magic_widget_has_focus ();
116 static void magic_widget_grab_focus ();
117 static void magic_widget_drop_focus ();
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;
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();
137 private:
138 static Keyboard* _the_keyboard;
140 guint snooper_id;
141 State state;
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;
155 typedef std::pair<std::string,std::string> two_strings;
157 static std::map<Gtk::AccelKey,two_strings,AccelKeyLess> release_keys;
159 static gint _snooper (GtkWidget*, GdkEventKey*, gpointer);
160 gint snooper (GtkWidget*, GdkEventKey*);
162 static void set_modifier (uint32_t newval, uint32_t& variable);
164 static bool _some_magic_widget_has_focus;
167 #endif /* __ardour_keyboard_h__ */