keybindings.h
Go to the documentation of this file.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
00034 namespace cwidget
00035 {
00036 namespace config
00037 {
00042 struct key
00043 {
00045 wint_t ch;
00046
00048 bool function_key;
00049
00050 key()
00051 :ch((wint_t) ERR), function_key(true)
00052 {
00053 }
00054
00055 key(wint_t _ch, bool _function_key)
00056 :ch(_ch), function_key(_function_key)
00057 {
00058 }
00059
00061 bool operator<(const key &other) const
00062 {
00063 return ch < other.ch || (ch == other.ch &&
00064 !function_key && other.function_key);
00065 }
00066
00067 bool operator==(const key &other) const
00068 {
00069 return ch == other.ch && function_key == other.function_key;
00070 }
00071 };
00072
00074 typedef std::vector<key> keybinding;
00075
00087 class keybindings
00088 {
00089 std::map<std::string, keybinding> keymap;
00090
00091 keybindings *parent;
00092
00093
00094
00095 keybindings(const keybindings &_parent);
00096 public:
00101 keybindings(keybindings *_parent=NULL):parent(_parent) {}
00102
00108 std::wstring keyname(const std::string &tag);
00109
00110
00117 std::wstring readable_keyname(const std::string &tag);
00118
00120 keybinding get(std::string tag)
00121 {
00122 std::map<std::string, keybinding>::iterator found=keymap.find(tag);
00123
00124 if(found==keymap.end())
00125 return keybinding();
00126 else
00127 return found->second;
00128 }
00129
00139 void set(std::string tag, keybinding strokes);
00140
00149 void set(std::string tag, const key &stroke)
00150 {
00151 keybinding strokes;
00152 strokes.push_back(stroke);
00153 set(tag, strokes);
00154 }
00155
00163 bool key_matches(const key &k, std::string tag);
00164 };
00165
00172 key parse_key(std::wstring keystr);
00173
00183 std::wstring keyname(const key &k);
00184
00191 std::wstring readable_keyname(const key &k);
00192
00198 extern keybindings global_bindings;
00199 }
00200 }
00201
00202
00203
00204
00205
00206
00207
00208
00215 #define KEY_CTRL(x) key(((x)&~(64|32)), false)
00216 #define KEY_ALT(x) key((0x200 | (x)), false)
00217
00218
00219 #endif