2010-07-03 13:27:32 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2012-01-01 17:22:32 +00:00
|
|
|
/** @file hotkeys.h %Hotkey related functions. */
|
2010-07-03 13:27:32 +00:00
|
|
|
|
|
|
|
#ifndef HOTKEYS_H
|
|
|
|
#define HOTKEYS_H
|
|
|
|
|
|
|
|
#include "core/smallvec_type.hpp"
|
2010-07-03 21:43:44 +00:00
|
|
|
#include "gfx_type.h"
|
2013-06-15 15:31:22 +00:00
|
|
|
#include "window_type.h"
|
2013-08-05 20:36:28 +00:00
|
|
|
#include "string_type.h"
|
2010-07-03 13:27:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* All data for a single hotkey. The name (for saving/loading a configfile),
|
|
|
|
* a list of keycodes and a number to help identifying this hotkey.
|
|
|
|
*/
|
|
|
|
struct Hotkey {
|
2013-06-15 15:27:33 +00:00
|
|
|
Hotkey(uint16 default_keycode, const char *name, int num);
|
|
|
|
Hotkey(const uint16 *default_keycodes, const char *name, int num);
|
2010-07-03 13:27:32 +00:00
|
|
|
|
2013-06-15 15:27:33 +00:00
|
|
|
void AddKeycode(uint16 keycode);
|
2010-07-03 13:27:32 +00:00
|
|
|
|
|
|
|
const char *name;
|
|
|
|
int num;
|
2019-03-03 17:30:09 +00:00
|
|
|
std::vector<uint16> keycodes;
|
2010-07-03 13:27:32 +00:00
|
|
|
};
|
|
|
|
|
2019-04-10 21:07:06 +00:00
|
|
|
#define HOTKEY_LIST_END Hotkey((uint16)0, nullptr, -1)
|
2010-07-03 13:27:32 +00:00
|
|
|
|
2013-06-15 15:28:09 +00:00
|
|
|
struct IniFile;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List of hotkeys for a window.
|
|
|
|
*/
|
|
|
|
struct HotkeyList {
|
2013-06-15 15:31:22 +00:00
|
|
|
typedef EventState (*GlobalHotkeyHandlerFunc)(int hotkey);
|
|
|
|
|
2019-04-10 21:07:06 +00:00
|
|
|
HotkeyList(const char *ini_group, Hotkey *items, GlobalHotkeyHandlerFunc global_hotkey_handler = nullptr);
|
2013-06-15 15:28:09 +00:00
|
|
|
~HotkeyList();
|
|
|
|
|
|
|
|
void Load(IniFile *ini);
|
|
|
|
void Save(IniFile *ini) const;
|
|
|
|
|
|
|
|
int CheckMatch(uint16 keycode, bool global_only = false) const;
|
|
|
|
|
2013-06-15 15:31:22 +00:00
|
|
|
GlobalHotkeyHandlerFunc global_hotkey_handler;
|
2013-06-15 15:28:09 +00:00
|
|
|
private:
|
|
|
|
const char *ini_group;
|
|
|
|
Hotkey *items;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dummy private copy constructor to prevent compilers from
|
|
|
|
* copying the structure, which fails due to _hotkey_lists.
|
|
|
|
*/
|
|
|
|
HotkeyList(const HotkeyList &other);
|
|
|
|
};
|
2010-07-03 13:27:32 +00:00
|
|
|
|
2010-07-04 11:28:16 +00:00
|
|
|
bool IsQuitKey(uint16 keycode);
|
|
|
|
|
2010-07-03 13:28:15 +00:00
|
|
|
void LoadHotkeysFromConfig();
|
|
|
|
void SaveHotkeysToConfig();
|
|
|
|
|
2010-07-03 21:43:44 +00:00
|
|
|
|
2013-08-05 20:36:28 +00:00
|
|
|
void HandleGlobalHotkeys(WChar key, uint16 keycode);
|
2010-07-03 21:43:44 +00:00
|
|
|
|
2010-07-03 13:27:32 +00:00
|
|
|
#endif /* HOTKEYS_H */
|