added Gtkmm2ext::rounded_rectangle() cairo pseudo-method
[ardour.git] / libs / gtkmm2ext / gtkmm2ext / bindings.h
1 #ifndef __libgtkmm2ext_bindings_h__
2 #define __libgtkmm2ext_bindings_h__
3
4 #include <map>
5 #include <stdint.h>
6 #include <gdk/gdkkeysyms.h>
7 #include <gtkmm/action.h>
8 #include <gtkmm/action.h>
9 #include <gtkmm/radioaction.h>
10 #include <gtkmm/toggleaction.h>
11
12 namespace Gtkmm2ext {
13
14 class KeyboardKey
15 {
16   public:
17         enum Operation { 
18                 Press,
19                 Release
20         };
21
22         KeyboardKey () {
23                 _val = GDK_VoidSymbol;
24         }
25         
26         KeyboardKey (uint32_t state, uint32_t keycode);
27         
28         uint32_t state() const { return _val >> 32; }
29         uint32_t key() const { return _val & 0xffff; }
30         
31         bool operator<(const KeyboardKey& other) const {
32                 return _val < other._val;
33         }
34
35         bool operator==(const KeyboardKey& other) const {
36                 return _val == other._val;
37         }
38
39         std::string name() const;
40         static bool make_key (const std::string&, KeyboardKey&);
41         static void set_ignored_state (int mask) {
42                 _ignored_state = mask;
43         }
44
45   private:
46         uint64_t _val;
47         static uint32_t _ignored_state;
48 };
49
50 class ActionMap {
51   public:
52         ActionMap() {}
53         ~ActionMap() {}
54
55         Glib::RefPtr<Gtk::Action> register_action (const char* path,
56                                                    const char* name, const char* label, sigc::slot<void> sl);
57         Glib::RefPtr<Gtk::Action> register_radio_action (const char* path, Gtk::RadioAction::Group&,
58                                                          const char* name, const char* label, 
59                                                          sigc::slot<void,GtkAction*> sl,
60                                                          int value);
61         Glib::RefPtr<Gtk::Action> register_toggle_action (const char*path,
62                                                           const char* name, const char* label, sigc::slot<void> sl);
63
64         Glib::RefPtr<Gtk::Action> find_action (const std::string& name);
65
66   private:
67         typedef std::map<std::string, Glib::RefPtr<Gtk::Action> > _ActionMap;
68         _ActionMap actions;
69 };        
70
71 class Bindings {
72   public:
73         Bindings();
74         ~Bindings ();
75
76         void add (KeyboardKey, KeyboardKey::Operation, Glib::RefPtr<Gtk::Action>);
77         void remove (KeyboardKey, KeyboardKey::Operation);
78         bool activate (KeyboardKey, KeyboardKey::Operation);
79
80         bool load (const std::string& path);
81         bool save (const std::string& path);
82         
83         void set_action_map (ActionMap&);
84
85   private:
86         typedef std::map<KeyboardKey,Glib::RefPtr<Gtk::Action> > KeybindingMap;
87         KeybindingMap press_bindings;
88         KeybindingMap release_bindings;
89
90         ActionMap* action_map;
91 };
92
93 } // namespace
94
95 #endif /* __libgtkmm2ext_bindings_h__ */