actionmap: Implement key translations
[openblackhole/openblackhole-enigma2.git] / lib / actions / action.h
1 #ifndef __lib_driver_action_h
2 #define __lib_driver_action_h
3
4 #include <lib/base/object.h>
5
6 #include <lib/python/python.h>
7 #include <string>
8 #include <map>
9 #include <vector>
10
11 class eWidget;
12
13 SWIG_IGNORE(eActionMap);
14 class eActionMap: public iObject
15 {
16         DECLARE_REF(eActionMap);
17 #ifdef SWIG
18         eActionMap();
19         ~eActionMap();
20 #endif
21 public:
22 #ifndef SWIG
23         eActionMap();
24         ~eActionMap();
25         void bindAction(const std::string &context, int priority, int id, eWidget *widget);
26         void unbindAction(eWidget *widget, int id);
27 #endif
28
29         void bindAction(const std::string &context, int priority, SWIG_PYOBJECT(ePyObject) function);
30         void unbindAction(const std::string &context, SWIG_PYOBJECT(ePyObject) function);
31
32         void bindKey(const std::string &domain, const std::string &device, int key, int flags, const std::string &context, const std::string &action);
33         void bindTranslation(const std::string &domain, const std::string &device, int keyin, int keyout, int toggle);
34         void bindToggle(const std::string &domain, const std::string &device, int togglekey);
35         void unbindKeyDomain(const std::string &domain);
36
37         void keyPressed(const std::string &device, int key, int flags);
38
39 #ifndef SWIG
40         static RESULT getInstance(ePtr<eActionMap> &);
41 private:
42         static eActionMap *instance;
43         struct eActionBinding
44         {
45                 eActionBinding()
46                         :m_prev_seen_make_key(-1)
47                 {}
48 //              eActionContext *m_context;
49                 std::string m_context; // FIXME
50                 std::string m_domain;
51
52                 ePyObject m_fnc;
53
54                 eWidget *m_widget;
55                 int m_id;
56                 int m_prev_seen_make_key;
57         };
58
59         std::multimap<int, eActionBinding> m_bindings;
60
61         struct eTranslationBinding
62         {
63                 int m_keyin;
64                 int m_keyout;
65                 int m_toggle;
66                 std::string m_domain;
67         };
68         struct eDeviceBinding
69         {
70                 int m_togglekey;
71                 int m_toggle;
72                 std::vector<eTranslationBinding> m_translations;
73         };
74         std::map <std::string, eDeviceBinding> m_rcDevices;
75
76         friend struct compare_string_keybind_native;
77         struct eNativeKeyBinding
78         {
79                 std::string m_device;
80                 std::string m_domain;
81                 int m_key;
82                 int m_flags;
83
84 //              eActionContext *m_context;
85                 int m_action;
86         };
87
88         std::multimap<std::string, eNativeKeyBinding> m_native_keys;
89
90         friend struct compare_string_keybind_python;
91         struct ePythonKeyBinding
92         {
93                 std::string m_device;
94                 std::string m_domain;
95                 int m_key;
96                 int m_flags;
97
98                 std::string m_action;
99         };
100
101         std::multimap<std::string, ePythonKeyBinding> m_python_keys;
102 #endif
103 };
104 SWIG_TEMPLATE_TYPEDEF(ePtr<eActionMap>, eActionMap);
105 SWIG_EXTEND(ePtr<eActionMap>,
106         static ePtr<eActionMap> getInstance()
107         {
108                 extern ePtr<eActionMap> NewActionMapPtr(void);
109                 return NewActionMapPtr();
110         }
111 );
112
113 #endif