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::Internal { |
12 | |
13 | #define SCI_NORM KeyMod::Norm |
14 | #define SCI_SHIFT KeyMod::Shift |
15 | #define SCI_CTRL KeyMod::Ctrl |
16 | #define SCI_ALT KeyMod::Alt |
17 | #define SCI_META KeyMod::Meta |
18 | #define SCI_SUPER KeyMod::Super |
19 | #define SCI_CSHIFT (KeyMod::Ctrl | KeyMod::Shift) |
20 | #define SCI_ASHIFT (KeyMod::Alt | KeyMod::Shift) |
21 | |
22 | /** |
23 | */ |
24 | class KeyModifiers { |
25 | public: |
26 | Scintilla::Keys key; |
27 | Scintilla::KeyMod modifiers; |
28 | KeyModifiers(Scintilla::Keys key_, Scintilla::KeyMod 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 | Scintilla::Keys key; |
43 | Scintilla::KeyMod modifiers; |
44 | Scintilla::Message msg; |
45 | }; |
46 | |
47 | /** |
48 | */ |
49 | class KeyMap { |
50 | std::map<KeyModifiers, Scintilla::Message> kmap; |
51 | static const KeyToCommand MapDefault[]; |
52 | |
53 | public: |
54 | KeyMap(); |
55 | void Clear() noexcept; |
56 | void AssignCmdKey(Scintilla::Keys key, Scintilla::KeyMod modifiers, Scintilla::Message msg); |
57 | Scintilla::Message Find(Scintilla::Keys key, Scintilla::KeyMod modifiers) const; // 0 returned on failure |
58 | const std::map<KeyModifiers, Scintilla::Message> &GetKeyMap() const noexcept; |
59 | }; |
60 | |
61 | } |
62 | |
63 | #endif |
64 | |