Shut up.
[ardour.git] / gtk2_ardour / keyboard.h
index 1b81f710f8fd8c21b9d1a3785f2db9732f2c362b..a10fdbd6ba9799f9d530586d7ddabc7d94a322e1 100644 (file)
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id$
 */
 
 #ifndef __ardour_keyboard_h__
 #define __ardour_keyboard_h__
 
+#include <map>
 #include <vector>
 #include <string>
 
 #include <sigc++/signal.h>
 #include <gtk/gtk.h>
+#include <gtkmm/accelkey.h>
 
-#include <ardour/types.h>
-#include <ardour/stateful.h>
+#include "ardour/types.h"
+#include "pbd/stateful.h"
 
-using std::vector;
-using std::string;
+#include "selection.h"
 
-class KeyboardTarget;
-class ArdourDialog;
+using std::string;
 
-class Keyboard : public sigc::trackable, Stateful
+class Keyboard : public sigc::trackable, PBD::Stateful
 {
   public:
        Keyboard ();
@@ -45,32 +44,34 @@ class Keyboard : public sigc::trackable, Stateful
        XMLNode& get_state (void);
        int set_state (const XMLNode&);
 
-       typedef vector<uint32_t> State;
-       
-       void set_target (KeyboardTarget *);
-       void set_default_target (KeyboardTarget *);
-       void allow_focus (bool);
-
-       gint focus_in_handler (GdkEventFocus*);
-       gint focus_out_handler (GdkEventFocus*);
-
-       int  get_prefix(float&, bool& was_floating);
-       void start_prefix ();
-
-       static State  translate_key_name (const string&);
-       static string get_real_keyname (const string& name);
-
-       void register_target (KeyboardTarget *);
-
-       void set_current_dialog (ArdourDialog*);
-       void close_current_dialog ();
-
+       typedef std::vector<uint32_t> State;
        typedef uint32_t ModifierMask;
 
-       static uint32_t Control;
-       static uint32_t Shift;
-       static uint32_t Alt;
-       static uint32_t Meta;
+       static uint32_t PrimaryModifier;
+       static uint32_t SecondaryModifier;
+       static uint32_t TertiaryModifier;
+       static uint32_t Level4Modifier;
+       static uint32_t CopyModifier;
+       static uint32_t RangeSelectModifier;
+
+       static void set_primary_modifier (uint32_t newval) {
+               set_modifier (newval, PrimaryModifier);
+       }
+       static void set_secondary_modifier (uint32_t newval) {
+               set_modifier (newval, SecondaryModifier);
+       }
+       static void set_tertiary_modifier (uint32_t newval) {
+               set_modifier (newval, TertiaryModifier);
+       }
+       static void set_level4_modifier (uint32_t newval) {
+               set_modifier (newval, Level4Modifier);
+       }
+       static void set_copy_modifier (uint32_t newval) {
+               set_modifier (newval, CopyModifier);
+       }
+       static void set_range_select_modifier (uint32_t newval) {
+               set_modifier (newval, RangeSelectModifier);
+       }
 
        bool key_is_down (uint32_t keyval);
 
@@ -80,12 +81,15 @@ class Keyboard : public sigc::trackable, Stateful
                return (ev->state & RelevantModifierKeyMask) == 0;
        }
 
+       bool leave_window (GdkEventCrossing *ev, Gtk::Window*);
+       bool enter_window (GdkEventCrossing *ev, Gtk::Window*);
+
        static bool modifier_state_contains (guint state, ModifierMask);
        static bool modifier_state_equals   (guint state, ModifierMask);
 
-       static bool no_modifiers_active (guint state);
+       static Selection::Operation selection_type (guint state);
 
-       static void set_meta_modifier (guint);
+       static bool no_modifiers_active (guint state);
 
        static void set_snap_modifier (guint);
        static ModifierMask snap_modifier () { return ModifierMask (snap_mod); }
@@ -103,51 +107,60 @@ class Keyboard : public sigc::trackable, Stateful
        static bool is_edit_event (GdkEventButton*);
        static bool is_delete_event (GdkEventButton*);
        static bool is_context_menu_event (GdkEventButton*);
+       static bool is_button2_event (GdkEventButton*);
 
        static Keyboard& the_keyboard() { return *_the_keyboard; }
 
+       static bool some_magic_widget_has_focus ();
+       static void magic_widget_grab_focus ();
+       static void magic_widget_drop_focus ();
+
+       static void setup_keybindings ();
+       static void keybindings_changed ();
+       static void save_keybindings ();
+       static bool load_keybindings (std::string path);
+       static void set_can_save_keybindings (bool yn);
+       static std::string current_binding_name () { return _current_binding_name; }
+       static std::map<std::string,std::string> binding_files;
+
+       struct AccelKeyLess {
+           bool operator() (const Gtk::AccelKey a, const Gtk::AccelKey b) const {
+                   if (a.get_key() != b.get_key()) {
+                           return a.get_key() < b.get_key();
+                   } else {
+                           return a.get_mod() < b.get_mod();
+                   }
+           }
+       };
+
   private:
        static Keyboard* _the_keyboard;
 
-       bool   _queue_events;
-       bool   _flush_queue;
-       guint32 playback_ignore_count;
-
        guint           snooper_id;
        State           state;
-       KeyboardTarget* target;
-       KeyboardTarget* default_target;
-       bool            focus_allowed;
-       bool            collecting_prefix;
-       string          current_prefix;
-       int*            modifier_masks;
-       int             modifier_mask;
-       int             min_keycode;
-       int             max_keycode;
-       ArdourDialog*   current_dialog;
-       std::vector<ArdourDialog*> known_dialogs;
 
        static guint     edit_but;
        static guint     edit_mod;
        static guint     delete_but;
        static guint     delete_mod;
        static guint     snap_mod;
+       static guint     button2_modifiers;
+       static Gtk::Window* current_window;
+       static std::string user_keybindings_path;
+       static bool can_save_keybindings;
+       static bool bindings_changed_after_save_became_legal;
+       static std::string _current_binding_name;
+
+       typedef std::pair<std::string,std::string> two_strings;
+
+       static std::map<Gtk::AccelKey,two_strings,AccelKeyLess> release_keys;
 
        static gint _snooper (GtkWidget*, GdkEventKey*, gpointer);
        gint snooper (GtkWidget*, GdkEventKey*);
-       
-       void maybe_unset_target (KeyboardTarget *);
-       void queue_event (GdkEventKey*);
-       void playback_queue ();
-       void clear_queue ();
-       void get_modifier_masks ();
-       void check_modifier_state ();
-       void clear_modifier_state ();
-       gint enter_window (GdkEventCrossing*, KeyboardTarget*);
-       gint leave_window (GdkEventCrossing*);
-       gint current_dialog_vanished (GdkEventAny*);
-
-       void check_meta_numlock (char keycode, guint mod, string modname);
+
+       static void set_modifier (uint32_t newval, uint32_t& variable);
+
+       static bool _some_magic_widget_has_focus;
 };
 
 #endif /* __ardour_keyboard_h__ */