1 #ifndef __TAB_HOTKEY_TYPES_h__
2 #define __TAB_HOTKEY_TYPES_h__
3 
4 #include <map>
5 #include <set>
6 #include <vector>
7 
8 #include <wx/string.h>
9 #include <wx/hashmap.h>
10 #include <wx/hashset.h>
11 #include "KeynameConverter.h"
12 
13 class wxCmd;
14 //added by vbs
15 WX_DECLARE_HASH_SET(int, wxIntegerHash, wxIntegerEqual, IdSet);
16 WX_DECLARE_HASH_SET(wxCmd*, wxPointerHash, wxPointerEqual, CmdSet);
17 
18 typedef std::pair<wxString, wxString>			key_command;
19 typedef std::set<key_command>					key_command_set;
20 typedef std::vector<key_command>				key_commands_sorted;
21 typedef std::set<wxString>						key_set;
22 typedef std::map<wxString, key_set>				key_binding_c2k;
23 typedef std::vector<wxString>					command_list_sorted;
24 typedef std::map<wxString, wxString>			key_sym_map;
25 typedef std::map<wxString, wxString>			key_sym_set_map;
26 
27 class key_binding
28 {
29 public:
30 	key_binding();
31 
32 	typedef std::map<unsigned, key_command>		key_binding_map;
33 
34 	void bind( const wxString& cmd, const wxString& keyString );
35 	void unbindAllCmds( const wxString& cmd );
36 	void unbindAllKeys( const wxString& key );
37 	void unbind( const wxString& cmd, const wxString& keyString );
38 	void clear();
39 
40 	void setMetaKey( const wxString& key );
41 	const wxString& getMetaKey() const;
42 
43 	void addKeySym( const wxString& name, const wxString& keyString );
44 	void addKeySymSet( const wxString& name, const wxString& keyString );
45 
46 	bool exists( const wxString& command, const wxString& key );
47 	bool isEmpty() const;
48 
49 	const key_binding operator-(const key_binding &other) const;
50 
51 
52 	void setKeySymsSet( const key_sym_set_map& keySyms );
53 	void setKeySyms( const key_sym_map& keySyms );
54 	const key_sym_map& getKeySyms() const;
55 	const key_sym_map& getKeySymsSet() const;
56 
57 	key_commands_sorted getBinds() const;
58 	//const key_binding_k2c& getK2C() const;
59 
60 	wxString resolveKeySymKeyAndSet( const wxString& key ) const;
61 	wxString resolveKeySymKey( const wxString& key ) const;
62 	bool operator==( const key_binding& other ) const;
63 
64 	bool isCmd1MatchingCmd2( const wxString& cmd1, const wxString& cmd2 );
65 
66 private:
67 	const wxString resolveKeySymSetName( const wxString& symName ) const;
68 	const wxString resolveKeySymSetKey( const wxString& key ) const;
69 	const wxString resolveKeySymName( const wxString& symName ) const;
70 
71 	//define different "views" onto the bindings
72 	typedef std::map<wxString, command_list_sorted>				KeyGroupMap;
73 	KeyGroupMap													m_groups;
74 	KeyGroupMap													m_groupsAny;
75 
76 	key_command_set												m_keyCmdSet;
77 	key_command_set												m_keyCmdSetAny;
78 
79 	key_sym_map													m_keySyms;
80 	key_sym_map													m_keySymsRev;
81 
82 	key_sym_set_map												m_keySymsSet;
83 	key_sym_set_map												m_keySymsSetRev;
84 
85 	wxString													m_meta;
86 	//key_binding_map		m_binds;
87 	//key_binding_c2k		m_c2k; //for faster lookups. keep this in sync with m_binds
88 	//unsigned			m_nextOrderIdx;
89 	//bool				m_isNormalized;
90 };
91 //typedef std::set<spring_key>				key_set;
92 //typedef std::map<wxString, key_set>			key_binding_c2k;
93 //typedef std::map<spring_key, command_set>	key_binding_k2c;
94 
95 typedef std::map<wxString, key_binding>			key_binding_collection;
96 
97 #endif
98