]> git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/KeyMap.cxx
c223d5b59ae58746ebd7d2f71d94f43c2dd77f0e
[wxWidgets.git] / src / stc / scintilla / src / KeyMap.cxx
1 // Scintilla source code edit control
2 /** @file KeyMap.cxx
3 ** Defines a mapping between keystrokes and commands.
4 **/
5 // Copyright 1998-2003 by Neil Hodgson <neilh@scintilla.org>
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 #ifdef SCI_NAMESPACE
15 using namespace Scintilla;
16 #endif
17
18 KeyMap::KeyMap() : kmap(0), len(0), alloc(0) {
19 for (int i = 0; MapDefault[i].key; i++) {
20 AssignCmdKey(MapDefault[i].key,
21 MapDefault[i].modifiers,
22 MapDefault[i].msg);
23 }
24 }
25
26 KeyMap::~KeyMap() {
27 Clear();
28 }
29
30 void KeyMap::Clear() {
31 delete []kmap;
32 kmap = 0;
33 len = 0;
34 alloc = 0;
35 }
36
37 void KeyMap::AssignCmdKey(int key, int modifiers, unsigned int msg) {
38 if ((len+1) >= alloc) {
39 KeyToCommand *ktcNew = new KeyToCommand[alloc + 5];
40 if (!ktcNew)
41 return;
42 for (int k = 0; k < len; k++)
43 ktcNew[k] = kmap[k];
44 alloc += 5;
45 delete []kmap;
46 kmap = ktcNew;
47 }
48 for (int keyIndex = 0; keyIndex < len; keyIndex++) {
49 if ((key == kmap[keyIndex].key) && (modifiers == kmap[keyIndex].modifiers)) {
50 kmap[keyIndex].msg = msg;
51 return;
52 }
53 }
54 kmap[len].key = key;
55 kmap[len].modifiers = modifiers;
56 kmap[len].msg = msg;
57 len++;
58 }
59
60 unsigned int KeyMap::Find(int key, int modifiers) {
61 for (int i = 0; i < len; i++) {
62 if ((key == kmap[i].key) && (modifiers == kmap[i].modifiers)) {
63 return kmap[i].msg;
64 }
65 }
66 return 0;
67 }
68
69 const KeyToCommand KeyMap::MapDefault[] = {
70 {SCK_DOWN, SCI_NORM, SCI_LINEDOWN},
71 {SCK_DOWN, SCI_SHIFT, SCI_LINEDOWNEXTEND},
72 {SCK_DOWN, SCI_CTRL, SCI_LINESCROLLDOWN},
73 {SCK_DOWN, SCI_ASHIFT, SCI_LINEDOWNRECTEXTEND},
74 {SCK_UP, SCI_NORM, SCI_LINEUP},
75 {SCK_UP, SCI_SHIFT, SCI_LINEUPEXTEND},
76 {SCK_UP, SCI_CTRL, SCI_LINESCROLLUP},
77 {SCK_UP, SCI_ASHIFT, SCI_LINEUPRECTEXTEND},
78 {'[', SCI_CTRL, SCI_PARAUP},
79 {'[', SCI_CSHIFT, SCI_PARAUPEXTEND},
80 {']', SCI_CTRL, SCI_PARADOWN},
81 {']', SCI_CSHIFT, SCI_PARADOWNEXTEND},
82 {SCK_LEFT, SCI_NORM, SCI_CHARLEFT},
83 {SCK_LEFT, SCI_SHIFT, SCI_CHARLEFTEXTEND},
84 {SCK_LEFT, SCI_CTRL, SCI_WORDLEFT},
85 {SCK_LEFT, SCI_CSHIFT, SCI_WORDLEFTEXTEND},
86 {SCK_LEFT, SCI_ASHIFT, SCI_CHARLEFTRECTEXTEND},
87 {SCK_RIGHT, SCI_NORM, SCI_CHARRIGHT},
88 {SCK_RIGHT, SCI_SHIFT, SCI_CHARRIGHTEXTEND},
89 {SCK_RIGHT, SCI_CTRL, SCI_WORDRIGHT},
90 {SCK_RIGHT, SCI_CSHIFT, SCI_WORDRIGHTEXTEND},
91 {SCK_RIGHT, SCI_ASHIFT, SCI_CHARRIGHTRECTEXTEND},
92 {'/', SCI_CTRL, SCI_WORDPARTLEFT},
93 {'/', SCI_CSHIFT, SCI_WORDPARTLEFTEXTEND},
94 {'\\', SCI_CTRL, SCI_WORDPARTRIGHT},
95 {'\\', SCI_CSHIFT, SCI_WORDPARTRIGHTEXTEND},
96 {SCK_HOME, SCI_NORM, SCI_VCHOME},
97 {SCK_HOME, SCI_SHIFT, SCI_VCHOMEEXTEND},
98 {SCK_HOME, SCI_CTRL, SCI_DOCUMENTSTART},
99 {SCK_HOME, SCI_CSHIFT, SCI_DOCUMENTSTARTEXTEND},
100 {SCK_HOME, SCI_ALT, SCI_HOMEDISPLAY},
101 // {SCK_HOME, SCI_ASHIFT, SCI_HOMEDISPLAYEXTEND},
102 {SCK_HOME, SCI_ASHIFT, SCI_VCHOMERECTEXTEND},
103 {SCK_END, SCI_NORM, SCI_LINEEND},
104 {SCK_END, SCI_SHIFT, SCI_LINEENDEXTEND},
105 {SCK_END, SCI_CTRL, SCI_DOCUMENTEND},
106 {SCK_END, SCI_CSHIFT, SCI_DOCUMENTENDEXTEND},
107 {SCK_END, SCI_ALT, SCI_LINEENDDISPLAY},
108 // {SCK_END, SCI_ASHIFT, SCI_LINEENDDISPLAYEXTEND},
109 {SCK_END, SCI_ASHIFT, SCI_LINEENDRECTEXTEND},
110 {SCK_PRIOR, SCI_NORM, SCI_PAGEUP},
111 {SCK_PRIOR, SCI_SHIFT, SCI_PAGEUPEXTEND},
112 {SCK_PRIOR, SCI_ASHIFT, SCI_PAGEUPRECTEXTEND},
113 {SCK_NEXT, SCI_NORM, SCI_PAGEDOWN},
114 {SCK_NEXT, SCI_SHIFT, SCI_PAGEDOWNEXTEND},
115 {SCK_NEXT, SCI_ASHIFT, SCI_PAGEDOWNRECTEXTEND},
116 {SCK_DELETE, SCI_NORM, SCI_CLEAR},
117 {SCK_DELETE, SCI_SHIFT, SCI_CUT},
118 {SCK_DELETE, SCI_CTRL, SCI_DELWORDRIGHT},
119 {SCK_DELETE, SCI_CSHIFT, SCI_DELLINERIGHT},
120 {SCK_INSERT, SCI_NORM, SCI_EDITTOGGLEOVERTYPE},
121 {SCK_INSERT, SCI_SHIFT, SCI_PASTE},
122 {SCK_INSERT, SCI_CTRL, SCI_COPY},
123 {SCK_ESCAPE, SCI_NORM, SCI_CANCEL},
124 {SCK_BACK, SCI_NORM, SCI_DELETEBACK},
125 {SCK_BACK, SCI_SHIFT, SCI_DELETEBACK},
126 {SCK_BACK, SCI_CTRL, SCI_DELWORDLEFT},
127 {SCK_BACK, SCI_ALT, SCI_UNDO},
128 {SCK_BACK, SCI_CSHIFT, SCI_DELLINELEFT},
129 {'Z', SCI_CTRL, SCI_UNDO},
130 {'Y', SCI_CTRL, SCI_REDO},
131 {'X', SCI_CTRL, SCI_CUT},
132 {'C', SCI_CTRL, SCI_COPY},
133 {'V', SCI_CTRL, SCI_PASTE},
134 {'A', SCI_CTRL, SCI_SELECTALL},
135 {SCK_TAB, SCI_NORM, SCI_TAB},
136 {SCK_TAB, SCI_SHIFT, SCI_BACKTAB},
137 {SCK_RETURN, SCI_NORM, SCI_NEWLINE},
138 {SCK_RETURN, SCI_SHIFT, SCI_NEWLINE},
139 {SCK_ADD, SCI_CTRL, SCI_ZOOMIN},
140 {SCK_SUBTRACT, SCI_CTRL, SCI_ZOOMOUT},
141 {SCK_DIVIDE, SCI_CTRL, SCI_SETZOOM},
142 //'L', SCI_CTRL, SCI_FORMFEED,
143 {'L', SCI_CTRL, SCI_LINECUT},
144 {'L', SCI_CSHIFT, SCI_LINEDELETE},
145 {'T', SCI_CSHIFT, SCI_LINECOPY},
146 {'T', SCI_CTRL, SCI_LINETRANSPOSE},
147 {'D', SCI_CTRL, SCI_SELECTIONDUPLICATE},
148 {'U', SCI_CTRL, SCI_LOWERCASE},
149 {'U', SCI_CSHIFT, SCI_UPPERCASE},
150 {0,0,0},
151 };
152