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 <string>
00024 #include <list>
00025
00026 #include <cwidget-config.h>
00027
00028 #ifdef CWIDGET_HAVE_HASH_MAP
00029 #include <hash_map>
00030 #else
00031 #ifdef CWIDGET_HAVE_EXT_HASH_MAP
00032 #include <ext/hash_map>
00033 #else
00034
00035 #include <map>
00036 #define hash_map map
00037 #endif
00038 #endif
00039
00040 #include <cwidget/generic/util/strhash.h>
00041 #include <cwidget/curses++.h>
00042
00043 namespace cwidget
00044 {
00045 namespace config
00046 {
00051 struct key
00052 {
00054 wint_t ch;
00055
00057 bool function_key;
00058
00059 key()
00060 :ch((wint_t) ERR), function_key(true)
00061 {
00062 }
00063
00064 key(wint_t _ch, bool _function_key)
00065 :ch(_ch), function_key(_function_key)
00066 {
00067 }
00068
00070 bool operator<(const key &other) const
00071 {
00072 return ch < other.ch || (ch == other.ch &&
00073 !function_key && other.function_key);
00074 }
00075
00076 bool operator==(const key &other) const
00077 {
00078 return ch == other.ch && function_key == other.function_key;
00079 }
00080 };
00081
00082 typedef std::vector<key> keybinding;
00083
00084 class keybindings
00085 {
00086 CWIDGET_HASH_NAMESPACE::hash_map<std::string, keybinding> keymap;
00087
00088 keybindings *parent;
00089
00090
00091
00092 keybindings(const keybindings &_parent);
00093 public:
00094 keybindings(keybindings *_parent=NULL):parent(_parent) {}
00095
00099 std::wstring keyname(const std::string &tag);
00100
00101
00105 std::wstring readable_keyname(const std::string &tag);
00106
00107 keybinding get(std::string tag)
00108
00109 {
00110 CWIDGET_HASH_NAMESPACE::hash_map<std::string, keybinding>::iterator found=keymap.find(tag);
00111
00112 if(found==keymap.end())
00113 return keybinding();
00114 else
00115 return found->second;
00116 }
00117
00118 void set(std::string tag, keybinding strokes);
00119
00120
00121
00122 void set(std::string tag, const key &stroke)
00123 {
00124 keybinding strokes;
00125 strokes.push_back(stroke);
00126 set(tag, strokes);
00127 }
00128
00129 bool key_matches(const key &k, std::string tag);
00130
00131
00132 };
00133
00134 key parse_key(std::wstring keystr);
00135
00136
00137 std::wstring keyname(const key &k);
00138
00139
00143 std::wstring readable_keyname(const key &k);
00144
00145 extern keybindings global_bindings;
00146
00147
00148 }
00149 }
00150
00151
00152
00153
00154
00155
00156
00157 #define KEY_CTRL(x) key(((x)&~(64|32)), false)
00158 #define KEY_ALT(x) key((0x200 | (x)), false)
00159
00160
00161 #endif