00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef KEYBINDINGS_H
00021 #define KEYBINDINGS_H
00022
00023 #include <list>
00024 #include <map>
00025 #include <string>
00026
00027 #include <cwidget/curses++.h>
00028
00029 namespace cwidget
00030 {
00031 namespace config
00032 {
00037 struct key
00038 {
00040 wint_t ch;
00041
00043 bool function_key;
00044
00045 key()
00046 :ch((wint_t) ERR), function_key(true)
00047 {
00048 }
00049
00050 key(wint_t _ch, bool _function_key)
00051 :ch(_ch), function_key(_function_key)
00052 {
00053 }
00054
00056 bool operator<(const key &other) const
00057 {
00058 return ch < other.ch || (ch == other.ch &&
00059 !function_key && other.function_key);
00060 }
00061
00062 bool operator==(const key &other) const
00063 {
00064 return ch == other.ch && function_key == other.function_key;
00065 }
00066 };
00067
00068 typedef std::vector<key> keybinding;
00069
00070 class keybindings
00071 {
00072 std::map<std::string, keybinding> keymap;
00073
00074 keybindings *parent;
00075
00076
00077
00078 keybindings(const keybindings &_parent);
00079 public:
00080 keybindings(keybindings *_parent=NULL):parent(_parent) {}
00081
00085 std::wstring keyname(const std::string &tag);
00086
00087
00091 std::wstring readable_keyname(const std::string &tag);
00092
00093 keybinding get(std::string tag)
00094
00095 {
00096 std::map<std::string, keybinding>::iterator found=keymap.find(tag);
00097
00098 if(found==keymap.end())
00099 return keybinding();
00100 else
00101 return found->second;
00102 }
00103
00104 void set(std::string tag, keybinding strokes);
00105
00106
00107
00108 void set(std::string tag, const key &stroke)
00109 {
00110 keybinding strokes;
00111 strokes.push_back(stroke);
00112 set(tag, strokes);
00113 }
00114
00115 bool key_matches(const key &k, std::string tag);
00116
00117
00118 };
00119
00120 key parse_key(std::wstring keystr);
00121
00122
00123 std::wstring keyname(const key &k);
00124
00125
00129 std::wstring readable_keyname(const key &k);
00130
00131 extern keybindings global_bindings;
00132
00133
00134 }
00135 }
00136
00137
00138
00139
00140
00141
00142
00143 #define KEY_CTRL(x) key(((x)&~(64|32)), false)
00144 #define KEY_ALT(x) key((0x200 | (x)), false)
00145
00146
00147 #endif