Translations update
[openttd/fttd.git] / src / hotkeys.h
blobb236fffb1a0f7f524db1c8a94540146782f67e01
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
10 /** @file hotkeys.h %Hotkey related functions. */
12 #ifndef HOTKEYS_H
13 #define HOTKEYS_H
15 #include <vector>
17 #include "core/smallvec_type.hpp"
18 #include "gfx_type.h"
19 #include "window_type.h"
20 #include "string.h"
22 /**
23 * All data for a single hotkey. The name (for saving/loading a configfile),
24 * a list of keycodes and a number to help identifying this hotkey.
26 struct Hotkey {
27 const char *const name; ///< Name of the hotkey in the config file.
28 const int num; ///< Hotkey identifier in its group.
29 /* We cannot make the default hotkeys an array because not all the
30 * compilers we support allow to statically construct an array. */
31 uint16 default0; ///< First default keycode for the hotkey.
32 uint16 default1; ///< First default keycode for the hotkey.
33 uint16 default2; ///< First default keycode for the hotkey.
34 uint16 default3; ///< First default keycode for the hotkey.
36 CONSTEXPR Hotkey (const char *name, const int num, uint16 k0 = 0,
37 uint16 k1 = 0, uint16 k2 = 0, uint16 k3 = 0)
38 : name(name), num(num),
39 default0(k0), default1(k1), default2(k2), default3(k3)
45 struct IniFile;
47 /**
48 * List of hotkeys for a window.
50 struct HotkeyList {
51 private:
52 typedef EventState (*GlobalHotkeyHandlerFunc)(int hotkey);
54 struct Mapping {
55 uint16 keycode;
56 int value;
58 CONSTEXPR Mapping (uint16 keycode, int value)
59 : keycode (keycode), value (value)
64 std::vector <Mapping> mappings;
65 const char *const ini_group;
66 const Hotkey *const descs;
67 const uint ndescs;
69 void init (void);
71 public:
72 GlobalHotkeyHandlerFunc global_hotkey_handler;
74 template <uint N>
75 HotkeyList (const char *ini_group, const Hotkey (&items) [N], GlobalHotkeyHandlerFunc global_hotkey_handler = NULL)
76 : mappings(), ini_group(ini_group), descs(items), ndescs(N),
77 global_hotkey_handler(global_hotkey_handler)
79 this->init();
82 ~HotkeyList();
84 void Load(IniFile *ini);
85 void Save(IniFile *ini) const;
87 int CheckMatch(uint16 keycode, bool global_only = false) const;
89 private:
90 /**
91 * Dummy private copy constructor to prevent compilers from
92 * copying the structure, which fails due to _hotkey_lists.
94 HotkeyList(const HotkeyList &other);
96 /** Helper function to push a mapping. */
97 void push_mapping (uint16 keycode, int value)
99 this->mappings.push_back (Mapping (keycode, value));
103 bool IsQuitKey(uint16 keycode);
105 void LoadHotkeysFromConfig();
106 void SaveHotkeysToConfig();
109 void HandleGlobalHotkeys(WChar key, uint16 keycode);
111 #endif /* HOTKEYS_H */