hotkeys.h

Go to the documentation of this file.
00001 /* $Id: hotkeys.h 25669 2013-08-05 20:36:28Z michi_cc $ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * 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.
00006  * 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.
00007  * 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/>.
00008  */
00009 
00012 #ifndef HOTKEYS_H
00013 #define HOTKEYS_H
00014 
00015 #include "core/smallvec_type.hpp"
00016 #include "gfx_type.h"
00017 #include "window_type.h"
00018 #include "string_type.h"
00019 
00024 struct Hotkey {
00025   Hotkey(uint16 default_keycode, const char *name, int num);
00026   Hotkey(const uint16 *default_keycodes, const char *name, int num);
00027 
00028   void AddKeycode(uint16 keycode);
00029 
00030   const char *name;
00031   int num;
00032   SmallVector<uint16, 1> keycodes;
00033 };
00034 
00035 #define HOTKEY_LIST_END Hotkey((uint16)0, NULL, -1)
00036 
00037 struct IniFile;
00038 
00042 struct HotkeyList {
00043   typedef EventState (*GlobalHotkeyHandlerFunc)(int hotkey);
00044 
00045   HotkeyList(const char *ini_group, Hotkey *items, GlobalHotkeyHandlerFunc global_hotkey_handler = NULL);
00046   ~HotkeyList();
00047 
00048   void Load(IniFile *ini);
00049   void Save(IniFile *ini) const;
00050 
00051   int CheckMatch(uint16 keycode, bool global_only = false) const;
00052 
00053   GlobalHotkeyHandlerFunc global_hotkey_handler;
00054 private:
00055   const char *ini_group;
00056   Hotkey *items;
00057 
00062   HotkeyList(const HotkeyList &other);
00063 };
00064 
00065 bool IsQuitKey(uint16 keycode);
00066 
00067 void LoadHotkeysFromConfig();
00068 void SaveHotkeysToConfig();
00069 
00070 
00071 void HandleGlobalHotkeys(WChar key, uint16 keycode);
00072 
00073 #endif /* HOTKEYS_H */