44 {
"RETURN", WKC_RETURN},
45 {
"BACKQUOTE", WKC_BACKQUOTE},
60 {
"NUM_PLUS", WKC_NUM_PLUS},
61 {
"NUM_MINUS", WKC_NUM_MINUS},
72 static uint16
ParseCode(
const char *start,
const char *end)
75 while (start < end && *start ==
' ') start++;
76 while (end > start && *end ==
' ') end--;
77 for (uint i = 0; i <
lengthof(_keycode_to_name); i++) {
78 if (strlen(_keycode_to_name[i].
name) == (size_t)(end - start) && strncasecmp(start, _keycode_to_name[i].name, end - start) == 0) {
79 return _keycode_to_name[i].
keycode;
82 if (end - start == 1) {
83 if (*start >=
'a' && *start <=
'z')
return *start - (
'a'-
'A');
85 if (*(
const uint8 *)start < 128)
return *start;
101 const char *cur = start;
102 while (*cur !=
'+' && cur != end) cur++;
104 if (code == 0)
return 0;
105 if (code & WKC_SPECIAL_KEYS) {
107 if (code & ~WKC_SPECIAL_KEYS)
return 0;
111 if (keycode & ~WKC_SPECIAL_KEYS)
return 0;
114 if (cur == end)
break;
128 const char *start = value;
129 while (*start !=
'\0') {
130 const char *end = start;
131 while (*end !=
'\0' && *end !=
',') end++;
133 if (keycode != 0) hotkey->
AddKeycode(keycode);
134 start = (*end ==
',') ? end + 1: end;
156 if (keycode & WKC_SHIFT) {
161 if (keycode & WKC_CTRL) {
166 if (keycode & WKC_ALT) {
171 if (keycode & WKC_META) {
177 keycode = keycode & ~WKC_SPECIAL_KEYS;
179 for (uint i = 0; i <
lengthof(_keycode_to_name); i++) {
180 if (_keycode_to_name[i].keycode == keycode) {
185 assert(keycode < 128);
203 static char buf[128];
205 for (uint i = 0; i < hotkey->keycodes.
Length(); i++) {
223 if (default_keycode != 0) this->
AddKeycode(default_keycode);
236 const uint16 *keycode = default_keycodes;
237 while (*keycode != 0) {
250 this->keycodes.
Include(keycode);
253 HotkeyList::HotkeyList(
const char *ini_group,
Hotkey *items, GlobalHotkeyHandlerFunc global_hotkey_handler) :
254 global_hotkey_handler(global_hotkey_handler), ini_group(ini_group), items(items)
257 *_hotkey_lists->
Append() =
this;
260 HotkeyList::~HotkeyList()
262 _hotkey_lists->
Erase(_hotkey_lists->
Find(
this));
272 for (
Hotkey *hotkey = this->items; hotkey->name != NULL; ++hotkey) {
275 hotkey->keycodes.Clear();
288 for (
const Hotkey *hotkey = this->items; hotkey->name != NULL; ++hotkey) {
302 for (
const Hotkey *list = this->items; list->name != NULL; ++list) {
303 if (list->keycodes.Contains(keycode |
WKC_GLOBAL_HOTKEY) || (!global_only && list->keycodes.Contains(keycode))) {
311 static void SaveLoadHotkeys(
bool save)
316 for (
HotkeyList **list = _hotkey_lists->
Begin(); list != _hotkey_lists->
End(); ++list) {
332 SaveLoadHotkeys(
false);
338 SaveLoadHotkeys(
true);
341 void HandleGlobalHotkeys(
WChar key, uint16 keycode)
343 for (
HotkeyList **list = _hotkey_lists->
Begin(); list != _hotkey_lists->
End(); ++list) {
344 if ((*list)->global_hotkey_handler == NULL)
continue;
346 int hotkey = (*list)->CheckMatch(keycode,
true);
347 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.
const T * Begin() const
Get the pointer to the first item (const)
#define lastof(x)
Get the last element of an fixed size array.
Simple vector template class.
IniGroup * GetGroup(const char *name, size_t len=0, bool create_new=true)
Get the group with the given name.
const T * End() const
Get the pointer behind the last valid item (const)
Functions, definitions and such used only by the GUI.
A single "line" in an ini file.
T * Append(uint to_add=1)
Append an item and return it.
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.
uint Length() const
Get the number of items in the list.
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.
const T * Find(const T &item) const
Search for the first occurrence of an item.
static SmallVector< HotkeyList *, 16 > * _hotkey_lists
List of all HotkeyLists.
#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.
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...
bool Include(const T &item)
Tests whether a item is present in the vector, and appends it to the end if not.
void Erase(T *item)
Removes given item from this vector.
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.