]>
Commit | Line | Data |
---|---|---|
9ce192d4 RD |
1 | // Scintilla source code edit control |
2 | // KeyMap.cxx - defines a mapping between keystrokes and commands | |
3 | // Copyright 1998-2000 by Neil Hodgson <neilh@scintilla.org> | |
4 | // The License.txt file describes the conditions under which this software may be distributed. | |
5 | ||
6 | #include "Platform.h" | |
7 | ||
8 | #include "Scintilla.h" | |
9 | ||
10 | #include "KeyMap.h" | |
11 | ||
12 | KeyMap::KeyMap() : kmap(0), len(0), alloc(0) { | |
13 | for (int i = 0; MapDefault[i].key; i++) { | |
14 | AssignCmdKey(MapDefault[i].key, | |
15 | MapDefault[i].modifiers, | |
16 | MapDefault[i].msg); | |
17 | } | |
18 | } | |
19 | ||
20 | KeyMap::~KeyMap() { | |
21 | Clear(); | |
22 | } | |
23 | ||
24 | void KeyMap::Clear() { | |
25 | delete []kmap; | |
26 | kmap = 0; | |
27 | len = 0; | |
28 | alloc = 0; | |
29 | } | |
30 | ||
d134f170 | 31 | void KeyMap::AssignCmdKey(int key, int modifiers, unsigned int msg) { |
9ce192d4 RD |
32 | if ((len+1) >= alloc) { |
33 | KeyToCommand *ktcNew = new KeyToCommand[alloc + 5]; | |
34 | if (!ktcNew) | |
35 | return; | |
36 | for (int k=0;k<len;k++) | |
37 | ktcNew[k] = kmap[k]; | |
38 | alloc += 5; | |
39 | delete []kmap; | |
40 | kmap = ktcNew; | |
41 | } | |
42 | for (int keyIndex = 0; keyIndex < len; keyIndex++) { | |
43 | if ((key == kmap[keyIndex].key) && (modifiers == kmap[keyIndex].modifiers)) { | |
44 | kmap[keyIndex].msg = msg; | |
45 | return; | |
46 | } | |
47 | } | |
48 | kmap[len].key = key; | |
49 | kmap[len].modifiers = modifiers; | |
50 | kmap[len].msg = msg; | |
51 | len++; | |
52 | } | |
53 | ||
d134f170 | 54 | unsigned int KeyMap::Find(int key, int modifiers) { |
9ce192d4 RD |
55 | for (int i=0; i < len; i++) { |
56 | if ((key == kmap[i].key) && (modifiers == kmap[i].modifiers)) { | |
57 | return kmap[i].msg; | |
58 | } | |
59 | } | |
60 | return 0; | |
61 | } | |
62 | ||
63 | KeyToCommand KeyMap::MapDefault[] = { | |
d134f170 RD |
64 | {SCK_DOWN, SCI_NORM, SCI_LINEDOWN}, |
65 | {SCK_DOWN, SCI_SHIFT, SCI_LINEDOWNEXTEND}, | |
66 | {SCK_DOWN, SCI_CTRL, SCI_LINESCROLLDOWN}, | |
67 | {SCK_UP, SCI_NORM, SCI_LINEUP}, | |
68 | {SCK_UP, SCI_SHIFT, SCI_LINEUPEXTEND}, | |
69 | {SCK_UP, SCI_CTRL, SCI_LINESCROLLUP}, | |
70 | {SCK_LEFT, SCI_NORM, SCI_CHARLEFT}, | |
71 | {SCK_LEFT, SCI_SHIFT, SCI_CHARLEFTEXTEND}, | |
72 | {SCK_LEFT, SCI_CTRL, SCI_WORDLEFT}, | |
73 | {SCK_LEFT, SCI_CSHIFT, SCI_WORDLEFTEXTEND}, | |
74 | {SCK_RIGHT, SCI_NORM, SCI_CHARRIGHT}, | |
75 | {SCK_RIGHT, SCI_SHIFT, SCI_CHARRIGHTEXTEND}, | |
76 | {SCK_RIGHT, SCI_CTRL, SCI_WORDRIGHT}, | |
77 | {SCK_RIGHT, SCI_CSHIFT, SCI_WORDRIGHTEXTEND}, | |
78 | {SCK_HOME, SCI_NORM, SCI_VCHOME}, | |
79 | {SCK_HOME, SCI_SHIFT, SCI_VCHOMEEXTEND}, | |
80 | {SCK_HOME, SCI_CTRL, SCI_DOCUMENTSTART}, | |
81 | {SCK_HOME, SCI_CSHIFT, SCI_DOCUMENTSTARTEXTEND}, | |
82 | {SCK_END, SCI_NORM, SCI_LINEEND}, | |
83 | {SCK_END, SCI_SHIFT, SCI_LINEENDEXTEND}, | |
84 | {SCK_END, SCI_CTRL, SCI_DOCUMENTEND}, | |
85 | {SCK_END, SCI_CSHIFT, SCI_DOCUMENTENDEXTEND}, | |
86 | {SCK_PRIOR, SCI_NORM, SCI_PAGEUP}, | |
87 | {SCK_PRIOR, SCI_SHIFT, SCI_PAGEUPEXTEND}, | |
88 | {SCK_NEXT, SCI_NORM, SCI_PAGEDOWN}, | |
89 | {SCK_NEXT, SCI_SHIFT, SCI_PAGEDOWNEXTEND}, | |
90 | {SCK_DELETE, SCI_NORM, SCI_CLEAR}, | |
91 | {SCK_DELETE, SCI_SHIFT, SCI_CUT}, | |
92 | {SCK_DELETE, SCI_CTRL, SCI_DELWORDRIGHT}, | |
93 | {SCK_INSERT, SCI_NORM, SCI_EDITTOGGLEOVERTYPE}, | |
94 | {SCK_INSERT, SCI_SHIFT, SCI_PASTE}, | |
95 | {SCK_INSERT, SCI_CTRL, SCI_COPY}, | |
96 | {SCK_ESCAPE, SCI_NORM, SCI_CANCEL}, | |
97 | {SCK_BACK, SCI_NORM, SCI_DELETEBACK}, | |
98 | {SCK_BACK, SCI_SHIFT, SCI_DELETEBACK}, | |
99 | {SCK_BACK, SCI_CTRL, SCI_DELWORDLEFT}, | |
100 | {SCK_BACK, SCI_ALT, SCI_UNDO}, | |
101 | {'Z', SCI_CTRL, SCI_UNDO}, | |
f6bcfd97 | 102 | {'Y', SCI_CTRL, SCI_REDO}, |
d134f170 RD |
103 | {'X', SCI_CTRL, SCI_CUT}, |
104 | {'C', SCI_CTRL, SCI_COPY}, | |
105 | {'V', SCI_CTRL, SCI_PASTE}, | |
f6bcfd97 | 106 | {'A', SCI_CTRL, SCI_SELECTALL}, |
d134f170 RD |
107 | {SCK_TAB, SCI_NORM, SCI_TAB}, |
108 | {SCK_TAB, SCI_SHIFT, SCI_BACKTAB}, | |
109 | {SCK_RETURN, SCI_NORM, SCI_NEWLINE}, | |
110 | {SCK_ADD, SCI_CTRL, SCI_ZOOMIN}, | |
111 | {SCK_SUBTRACT, SCI_CTRL, SCI_ZOOMOUT}, | |
112 | {SCK_DIVIDE, SCI_CTRL, SCI_SETZOOM}, | |
f6bcfd97 BP |
113 | //'L', SCI_CTRL, SCI_FORMFEED, |
114 | {'L', SCI_CTRL, SCI_LINECUT}, | |
115 | {'L', SCI_CSHIFT, SCI_LINEDELETE}, | |
116 | {'T', SCI_CTRL, SCI_LINETRANSPOSE}, | |
117 | {'U', SCI_CTRL, SCI_LOWERCASE}, | |
118 | {'U', SCI_CSHIFT, SCI_UPPERCASE}, | |
119 | {0,0,0}, | |
9ce192d4 RD |
120 | }; |
121 |