1 // Scintilla source code edit control
2 /** @file KeyMap.h
3  ** Defines a mapping between keystrokes and commands.
4  **/
5 // Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org>
6 // The License.txt file describes the conditions under which this software may be distributed.
7 
8 #ifndef KEYMAP_H
9 #define KEYMAP_H
10 
11 namespace Scintilla {
12 
13 #define SCI_NORM 0
14 #define SCI_SHIFT SCMOD_SHIFT
15 #define SCI_CTRL SCMOD_CTRL
16 #define SCI_ALT SCMOD_ALT
17 #define SCI_META SCMOD_META
18 #define SCI_SUPER SCMOD_SUPER
19 #define SCI_CSHIFT (SCI_CTRL | SCI_SHIFT)
20 #define SCI_ASHIFT (SCI_ALT | SCI_SHIFT)
21 
22 /**
23  */
24 class KeyModifiers {
25 public:
26 	int key;
27 	int modifiers;
KeyModifiers(int key_,int modifiers_)28 	KeyModifiers(int key_, int modifiers_) noexcept : key(key_), modifiers(modifiers_) {
29 	}
30 	bool operator<(const KeyModifiers &other) const noexcept {
31 		if (key == other.key)
32 			return modifiers < other.modifiers;
33 		else
34 			return key < other.key;
35 	}
36 };
37 
38 /**
39  */
40 class KeyToCommand {
41 public:
42 	int key;
43 	int modifiers;
44 	unsigned int msg;
45 };
46 
47 /**
48  */
49 class KeyMap {
50 	std::map<KeyModifiers, unsigned int> kmap;
51 	static const KeyToCommand MapDefault[];
52 
53 public:
54 	KeyMap();
55 	~KeyMap();
56 	void Clear() noexcept;
57 	void AssignCmdKey(int key, int modifiers, unsigned int msg);
58 	unsigned int Find(int key, int modifiers) const;	// 0 returned on failure
59 	const std::map<KeyModifiers, unsigned int> &GetKeyMap() const noexcept;
60 };
61 
62 }
63 
64 #endif
65