cache shaded meter-background regardless of color
[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 class XMLNode;
13
14 namespace Gtkmm2ext {
15
16 class KeyboardKey
17 {
18   public:
19         KeyboardKey () {
20                 _val = GDK_VoidSymbol;
21         }
22         
23         KeyboardKey (uint32_t state, uint32_t keycode);
24         
25         uint32_t state() const { return _val >> 32; }
26         uint32_t key() const { return _val & 0xffff; }
27         
28         bool operator<(const KeyboardKey& other) const {
29                 return _val < other._val;
30         }
31
32         bool operator==(const KeyboardKey& other) const {
33                 return _val == other._val;
34         }
35
36         std::string name() const;
37         static bool make_key (const std::string&, KeyboardKey&);
38
39   private:
40         uint64_t _val;
41 };
42
43 class MouseButton {
44   public:
45         MouseButton () {
46                 _val = ~0ULL;
47         }
48
49         MouseButton (uint32_t state, uint32_t button_number);
50         uint32_t state() const { return _val >> 32; }
51         uint32_t button() const { return _val & 0xffff; }
52
53         bool operator<(const MouseButton& other) const {
54                 return _val < other._val;
55         }
56
57         bool operator==(const MouseButton& other) const {
58                 return _val == other._val;
59         }
60
61         std::string name() const;
62         static bool make_button (const std::string&, MouseButton&);
63         static void set_ignored_state (int mask) {
64                 _ignored_state = mask;
65         }
66
67   private:
68         uint64_t _val;
69         static uint32_t _ignored_state;
70 };
71
72 class ActionMap {
73   public:
74         ActionMap() {}
75         ~ActionMap() {}
76
77         Glib::RefPtr<Gtk::Action> register_action (const char* path,
78                                                    const char* name, const char* label, sigc::slot<void> sl);
79         Glib::RefPtr<Gtk::Action> register_radio_action (const char* path, Gtk::RadioAction::Group&,
80                                                          const char* name, const char* label, 
81                                                          sigc::slot<void,GtkAction*> sl,
82                                                          int value);
83         Glib::RefPtr<Gtk::Action> register_toggle_action (const char*path,
84                                                           const char* name, const char* label, sigc::slot<void> sl);
85
86         Glib::RefPtr<Gtk::Action> find_action (const std::string& name);
87
88   private:
89         typedef std::map<std::string, Glib::RefPtr<Gtk::Action> > _ActionMap;
90         _ActionMap actions;
91 };        
92
93 class Bindings {
94   public:
95         enum Operation { 
96                 Press,
97                 Release
98         };
99         
100         Bindings();
101         ~Bindings ();
102
103         void add (KeyboardKey, Operation, Glib::RefPtr<Gtk::Action>);
104         void remove (KeyboardKey, Operation);
105         bool activate (KeyboardKey, Operation);
106
107         void add (MouseButton, Operation, Glib::RefPtr<Gtk::Action>);
108         void remove (MouseButton, Operation);
109         bool activate (MouseButton, Operation);
110
111         bool load (const std::string& path);
112         void load (const XMLNode& node);
113         bool save (const std::string& path);
114         void save (XMLNode& root);
115         
116         void set_action_map (ActionMap&);
117
118         static void set_ignored_state (int mask) {
119                 _ignored_state = mask;
120         }
121         static uint32_t ignored_state() { return _ignored_state; }
122
123   private:
124         typedef std::map<KeyboardKey,Glib::RefPtr<Gtk::Action> > KeybindingMap;
125
126         KeybindingMap press_bindings;
127         KeybindingMap release_bindings;
128
129         typedef std::map<MouseButton,Glib::RefPtr<Gtk::Action> > MouseButtonBindingMap;
130         MouseButtonBindingMap button_press_bindings;
131         MouseButtonBindingMap button_release_bindings;
132
133         ActionMap* action_map;
134         static uint32_t _ignored_state;
135 };
136
137 } // namespace
138
139 #endif /* __libgtkmm2ext_bindings_h__ */