aboutsummaryrefslogtreecommitdiff
path: root/backends/common/keymap-manager.h
blob: bc93400f3bdc7afcf9bf6e5a5769729496a7a389 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef COMMON_KEYMAP_MANAGER
#define COMMON_KEYMAP_MANAGER

#include "backends/common/hardware-key.h"
#include "backends/common/keymap.h"
#include "common/config-manager.h"
#include "common/hash-str.h"
#include "common/hashmap.h"

namespace Common {

class KeymapManager {
public:

	class Domain {
	public:
		Domain() : _defaultKeymap(0) {}
		~Domain() { deleteAllKeyMaps(); }

		void addDefaultKeymap(Keymap *map);
		void addKeymap(const String& name, Keymap *map);

		void deleteAllKeyMaps();

		Keymap *getDefaultKeymap();
		Keymap *getKeymap(const String& name);

	private:
		typedef HashMap<String, Keymap*, 
			IgnoreCase_Hash, IgnoreCase_EqualTo> KeymapMap;

		Keymap *_defaultKeymap;
		KeymapMap _keymaps;
	};

	void registerHardwareKeySet(HardwareKeySet *keys);

	void registerDefaultGlobalKeymap(Keymap *map);
	void registerGlobalKeymap(const String& name, Keymap *map);

	void registerDefaultGameKeymap(Keymap *map);
	void registerGameKeymap(const String& name, Keymap *map);

	void unregisterAllGameKeymaps();

	Keymap *getKeymap(const String& name);

private:

	void initKeymap(ConfigManager::Domain *domain, const String& name, Keymap *keymap);
	bool loadKeymap(ConfigManager::Domain *domain, const String& name, Keymap *keymap);
	void saveKeymap(ConfigManager::Domain *domain, const String& name, const Keymap *keymap);
	void automaticMap(Keymap *map);
	bool isMapComplete(const Keymap *map);

	Domain _globalDomain;
	Domain _gameDomain;

	HardwareKeySet *_hardwareKeys;
};

} // end of namespace Common

#endif