42 {
"BACKSPACE", WKC_BACKSPACE},
43 {
"RETURN", WKC_RETURN},
44 {
"BACKQUOTE", WKC_BACKQUOTE},
59 {
"NUM_PLUS", WKC_NUM_PLUS},
60 {
"NUM_MINUS", WKC_NUM_MINUS},
71 static uint16
ParseCode(
const char *start,
const char *end)
74 while (start < end && *start ==
' ') start++;
75 while (end > start && *end ==
' ') end--;
76 for (uint i = 0; i <
lengthof(_keycode_to_name); i++) {
77 if (strlen(_keycode_to_name[i].
name) == (size_t)(end - start) && strncasecmp(start, _keycode_to_name[i].name, end - start) == 0) {
78 return _keycode_to_name[i].
keycode;
81 if (end - start == 1) {
82 if (*start >=
'a' && *start <=
'z')
return *start - (
'a'-
'A');
84 if (*(
const uint8 *)start < 128)
return *start;
100 const char *cur = start;
101 while (*cur !=
'+' && cur != end) cur++;
103 if (code == 0)
return 0;
104 if (code & WKC_SPECIAL_KEYS) {
106 if (code & ~WKC_SPECIAL_KEYS)
return 0;
110 if (keycode & ~WKC_SPECIAL_KEYS)
return 0;
113 if (cur == end)
break;
127 const char *start = value;
128 while (*start !=
'\0') {
129 const char *end = start;
130 while (*end !=
'\0' && *end !=
',') end++;
132 if (keycode != 0) hotkey->
AddKeycode(keycode);
133 start = (*end ==
',') ? end + 1: end;
155 if (keycode & WKC_SHIFT) {
160 if (keycode & WKC_CTRL) {
165 if (keycode & WKC_ALT) {
170 if (keycode & WKC_META) {
176 keycode = keycode & ~WKC_SPECIAL_KEYS;
178 for (uint i = 0; i <
lengthof(_keycode_to_name); i++) {
179 if (_keycode_to_name[i].keycode == keycode) {
184 assert(keycode < 128);
202 static char buf[128];
204 for (uint i = 0; i < hotkey->keycodes.size(); i++) {
222 if (default_keycode != 0) this->
AddKeycode(default_keycode);
235 const uint16 *keycode = default_keycodes;
236 while (*keycode != 0) {
249 include(this->keycodes, keycode);
252 HotkeyList::HotkeyList(
const char *ini_group,
Hotkey *items, GlobalHotkeyHandlerFunc global_hotkey_handler) :
253 global_hotkey_handler(global_hotkey_handler), ini_group(ini_group), items(items)
259 HotkeyList::~HotkeyList()
271 for (
Hotkey *hotkey = this->items; hotkey->name !=
nullptr; ++hotkey) {
273 if (item !=
nullptr) {
274 hotkey->keycodes.clear();
287 for (
const Hotkey *hotkey = this->items; hotkey->name !=
nullptr; ++hotkey) {
301 for (
const Hotkey *list = this->items; list->name !=
nullptr; ++list) {
302 auto begin = list->keycodes.begin();
303 auto end = list->keycodes.end();
304 if (std::find(begin, end, keycode |
WKC_GLOBAL_HOTKEY) != end || (!global_only && std::find(begin, end, keycode) != end)) {
312 static void SaveLoadHotkeys(
bool save)
333 SaveLoadHotkeys(
false);
339 SaveLoadHotkeys(
true);
342 void HandleGlobalHotkeys(
WChar key, uint16 keycode)
345 if (list->global_hotkey_handler ==
nullptr)
continue;
347 int hotkey = list->CheckMatch(keycode,
true);
348 if (hotkey >= 0 && (list->global_hotkey_handler(hotkey) ==
ES_HANDLED))
return;
const char * name
Name of the keycode.
A group within an ini file.
static char * strecat(char *dst, const char *src, const char *last)
Appends characters from one string to another.
All data for a single hotkey.
Hotkey(uint16 default_keycode, const char *name, int num)
Create a new Hotkey object with a single default keycode.
Hotkey related functions.
#define lastof(x)
Get the last element of an fixed size array.
IniGroup * GetGroup(const char *name, size_t len=0, bool create_new=true)
Get the group with the given name.
Functions, definitions and such used only by the GUI.
A single "line" in an ini file.
static void ParseHotkeys(Hotkey *hotkey, const char *value)
Parse a string to the keycodes it represents.
Functions related to low-level strings.
void Load(IniFile *ini)
Load HotkeyList from IniFile.
WindowKeyCodes keycode
The keycode.
static uint16 ParseKeycode(const char *start, const char *end)
Parse a string representation of a keycode.
void Save(IniFile *ini) const
Save HotkeyList to IniFile.
bool SaveToDisk(const char *filename)
Save the Ini file's data to the disk.
void SetValue(const char *value)
Replace the current value with another value.
void LoadFromDisk(const char *filename, Subdirectory subdir)
Load the Ini file's data from the disk.
A path without any base directory.
Definition of base types and functions in a cross-platform compatible way.
A number of safeguards to prevent using unsafe methods.
List of hotkeys for a window.
char * value
The value of this item.
#define lengthof(x)
Return the length of an fixed size array.
void AddKeycode(uint16 keycode)
Add a keycode to this hotkey, from now that keycode will be matched in addition to any previously add...
Types related to reading/writing '*.ini' files.
void LoadHotkeysFromConfig()
Load the hotkeys from the config file.
Ini file that supports both loading and saving.
bool include(std::vector< T > &vec, const T &item)
Helper function to append an item to a vector if it is not already contained Consider using std::set...
IniItem * GetItem(const char *name, bool create)
Get the item with the given name, and if it doesn't exist and create is true it creates a new item...
static uint16 ParseCode(const char *start, const char *end)
Try to parse a single part of a keycode.
static const KeycodeNames _keycode_to_name[]
Array of non-standard keycodes that can be used in the hotkeys config file.
void SaveHotkeysToConfig()
Save the hotkeys to the config file.
int CheckMatch(uint16 keycode, bool global_only=false) const
Check if a keycode is bound to something.
static const char * KeycodeToString(uint16 keycode)
Convert a hotkey to it's string representation so it can be written to the config file...
The passed event is handled.
String representation of a keycode.
uint32 WChar
Type for wide characters, i.e.
const char * SaveKeycodes(const Hotkey *hotkey)
Convert all keycodes attached to a hotkey to a single string.
Fake keycode bit to indicate global hotkeys.
static std::vector< HotkeyList * > * _hotkey_lists
List of all HotkeyLists.