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