radically change Keyboard/Binding API design to disconnect Gtk::Action lookup from...
[ardour.git] / libs / gtkmm2ext / gtkmm2ext / keyboard.h
index 2123e6ff6969477b7035b985d7ee97d48477e1c3..48a1bdcaad2b2817c16cef6b80e658610102c072 100644 (file)
@@ -29,6 +29,7 @@
 #include <gtkmm/accelkey.h>
 
 #include "pbd/stateful.h"
+#include "pbd/signals.h"
 
 #include "gtkmm2ext/visibility.h"
 
@@ -38,6 +39,8 @@ namespace Gtk {
 
 namespace Gtkmm2ext {
 
+class Bindings;
+
 class LIBGTKMM2EXT_API Keyboard : public sigc::trackable, PBD::Stateful
 {
   public:
@@ -70,8 +73,6 @@ class LIBGTKMM2EXT_API Keyboard : public sigc::trackable, PBD::Stateful
        static const char* secondary_modifier_name ();
        static const char* tertiary_modifier_name ();
        static const char* level4_modifier_name ();
-       static const char* copy_modifier_name ();
-       static const char* rangeselect_modifier_name ();
 
        static void set_primary_modifier (uint32_t newval) {
                set_modifier (newval, PrimaryModifier);
@@ -106,6 +107,8 @@ class LIBGTKMM2EXT_API Keyboard : public sigc::trackable, PBD::Stateful
 
        bool leave_window (GdkEventCrossing *ev, Gtk::Window*);
        bool enter_window (GdkEventCrossing *ev, Gtk::Window*);
+       bool focus_in_window (GdkEventFocus *ev, Gtk::Window*);
+       bool focus_out_window (GdkEventFocus *ev, Gtk::Window*);
 
        static bool modifier_state_contains (guint state, ModifierMask);
        static bool modifier_state_equals   (guint state, ModifierMask);
@@ -113,13 +116,22 @@ class LIBGTKMM2EXT_API Keyboard : public sigc::trackable, PBD::Stateful
        static bool no_modifiers_active (guint state);
 
        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 void set_snap_delta_modifier (guint);
+       /** @return Modifier mask to temporarily toggle between relative and absolute grid setting.
+        *  Absolute grid is for aligning objects with the grid lines.
+        *  Relative grid is for maintaining an initial position relative to the grid lines.
+        *  With this modifier:
+        *  - magnetic or normal grid should snap relative to an initial grid offset
+        *  - no grid should snap relative to the grid.
+        */
+       static ModifierMask snap_delta_modifier () { return ModifierMask (snap_delta_mod); }
+
        static guint edit_button() { return edit_but; }
        static void set_edit_button (guint);
        static guint edit_modifier() { return edit_mod; }
@@ -134,7 +146,7 @@ class LIBGTKMM2EXT_API Keyboard : public sigc::trackable, PBD::Stateful
        static void set_insert_note_button (guint);
        static guint insert_note_modifier() { return insert_note_mod; }
        static void set_insert_note_modifier(guint);
-       
+
        static bool is_edit_event (GdkEventButton*);
        static bool is_delete_event (GdkEventButton*);
        static bool is_insert_note_event (GdkEventButton*);
@@ -146,28 +158,29 @@ class LIBGTKMM2EXT_API Keyboard : public sigc::trackable, PBD::Stateful
        static bool some_magic_widget_has_focus ();
        static void magic_widget_grab_focus ();
        static void magic_widget_drop_focus ();
+       static Gtk::Window* get_current_window () { return current_window; };
 
        static void close_current_dialog ();
 
        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();
-                   }
-           }
-       };
+        static bool catch_user_event_for_pre_dialog_focus (GdkEvent* ev, Gtk::Window* w);
+
+       static bool load_keybindings (std::string const& path);
+       static void save_keybindings (std::string const& path);
+
+       int reset_bindings ();
 
        sigc::signal0<void> ZoomVerticalModifierReleased;
 
+       static std::vector<Bindings*> bindings;
+       static Bindings* get_bindings (std::string const& name);
+       static PBD::Signal0<void> BindingsChanged;
+
   protected:
        static Keyboard* _the_keyboard;
 
@@ -181,6 +194,7 @@ class LIBGTKMM2EXT_API Keyboard : public sigc::trackable, PBD::Stateful
        static guint     insert_note_but;
        static guint     insert_note_mod;
        static guint     snap_mod;
+       static guint     snap_delta_mod;
        static guint     button2_modifiers;
        static Gtk::Window* current_window;
        static std::string user_keybindings_path;
@@ -190,14 +204,17 @@ class LIBGTKMM2EXT_API Keyboard : public sigc::trackable, PBD::Stateful
 
        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;
+
+        static Gtk::Window* pre_dialog_active_window;
+
+       static int read_keybindings (std::string const& path);
+       static int store_keybindings (std::string const& path);
 };
 
 } /* namespace */