Part 1 of loading 2.X sessions; some things work, some things don't, hacks a-plenty.
[ardour.git] / gtk2_ardour / keyboard.h
index ec55dc54db7e4ddd111fb3a983c7d1fc031211be..9f354f38e38d015f372bff5a365d7da765fabea4 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2001 Paul Davis 
+    Copyright (C) 2001 Paul Davis
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 #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 <pbd/stateful.h>
+#include "ardour/types.h"
+#include "pbd/stateful.h"
 
 #include "selection.h"
 
-using std::vector;
-using std::string;
-
-class Keyboard : public sigc::trackable, Stateful
+class Keyboard : public sigc::trackable, PBD::Stateful
 {
   public:
        Keyboard ();
        ~Keyboard ();
 
        XMLNode& get_state (void);
-       int set_state (const XMLNode&);
+       int set_state (const XMLNode&, int version = 3000);
 
-       typedef vector<uint32_t> State;
+       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);
 
@@ -69,9 +89,12 @@ class Keyboard : public sigc::trackable, Stateful
 
        static bool no_modifiers_active (guint state);
 
-       static void set_meta_modifier (guint);
-
        static void set_snap_modifier (guint);
+
+       /** @return Modifier mask to temporarily toggle grid setting; with this modifier
+        *  - magnetic or normal grid should become no grid and
+        *  - no grid should become normal grid
+        */
        static ModifierMask snap_modifier () { return ModifierMask (snap_mod); }
 
        static guint edit_button() { return edit_but; }
@@ -87,9 +110,32 @@ 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;
 
@@ -101,9 +147,23 @@ class Keyboard : public sigc::trackable, Stateful
        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*);
+
+       static void set_modifier (uint32_t newval, uint32_t& variable);
+
+       static bool _some_magic_widget_has_focus;
 };
 
 #endif /* __ardour_keyboard_h__ */