Fix: Don't allow right-click to close world generation progress window. (#13084)
[openttd-github.git] / src / hotkeys.h
blob88b714590b033f8ebbabfebec24bf71d671662e9
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
8 /** @file hotkeys.h %Hotkey related functions. */
10 #ifndef HOTKEYS_H
11 #define HOTKEYS_H
13 #include "gfx_type.h"
14 #include "window_type.h"
15 #include "string_type.h"
17 /**
18 * All data for a single hotkey. The name (for saving/loading a configfile),
19 * a list of keycodes and a number to help identifying this hotkey.
21 struct Hotkey {
22 Hotkey(uint16_t default_keycode, const std::string &name, int num);
23 Hotkey(const std::vector<uint16_t> &default_keycodes, const std::string &name, int num);
25 void AddKeycode(uint16_t keycode);
27 const std::string name;
28 int num;
29 std::set<uint16_t> keycodes;
32 struct IniFile;
34 /**
35 * List of hotkeys for a window.
37 struct HotkeyList {
38 typedef EventState (*GlobalHotkeyHandlerFunc)(int hotkey);
40 HotkeyList(const std::string &ini_group, const std::vector<Hotkey> &items, GlobalHotkeyHandlerFunc global_hotkey_handler = nullptr);
41 ~HotkeyList();
43 void Load(const IniFile &ini);
44 void Save(IniFile &ini) const;
46 int CheckMatch(uint16_t keycode, bool global_only = false) const;
48 GlobalHotkeyHandlerFunc global_hotkey_handler;
49 private:
50 const std::string ini_group;
51 std::vector<Hotkey> items;
53 /**
54 * Dummy private copy constructor to prevent compilers from
55 * copying the structure, which fails due to _hotkey_lists.
57 HotkeyList(const HotkeyList &other);
60 bool IsQuitKey(uint16_t keycode);
62 void LoadHotkeysFromConfig();
63 void SaveHotkeysToConfig();
66 void HandleGlobalHotkeys(char32_t key, uint16_t keycode);
68 #endif /* HOTKEYS_H */