]> git.saurik.com Git - wxWidgets.git/blame - contrib/src/stc/scintilla/src/KeyMap.cxx
Patch #1106564, corrects possible 100% CPU load condition.
[wxWidgets.git] / contrib / src / stc / scintilla / src / KeyMap.cxx
CommitLineData
9ce192d4 1// Scintilla source code edit control
9e730a78 2/** @file KeyMap.cxx
65ec6247
RD
3 ** Defines a mapping between keystrokes and commands.
4 **/
8e54aaed 5// Copyright 1998-2003 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
14KeyMap::KeyMap() : kmap(0), len(0), alloc(0) {
15 for (int i = 0; MapDefault[i].key; i++) {
9e730a78 16 AssignCmdKey(MapDefault[i].key,
9ce192d4 17 MapDefault[i].modifiers,
8e54aaed 18 MapDefault[i].msg);
9ce192d4
RD
19 }
20}
21
22KeyMap::~KeyMap() {
23 Clear();
24}
25
26void KeyMap::Clear() {
27 delete []kmap;
28 kmap = 0;
29 len = 0;
30 alloc = 0;
31}
32
d134f170 33void 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;
8e54aaed 38 for (int k = 0; k < len; k++)
9ce192d4
RD
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 56unsigned int KeyMap::Find(int key, int modifiers) {
8e54aaed 57 for (int i = 0; i < len; i++) {
9ce192d4
RD
58 if ((key == kmap[i].key) && (modifiers == kmap[i].modifiers)) {
59 return kmap[i].msg;
60 }
61 }
62 return 0;
63}
64
1a2fb4cd 65const 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},
8e54aaed
RD
69 {SCK_DOWN, SCI_ASHIFT, SCI_LINEDOWNRECTEXTEND},
70 {SCK_UP, SCI_NORM, SCI_LINEUP},
d134f170
RD
71 {SCK_UP, SCI_SHIFT, SCI_LINEUPEXTEND},
72 {SCK_UP, SCI_CTRL, SCI_LINESCROLLUP},
8e54aaed
RD
73 {SCK_UP, SCI_ASHIFT, SCI_LINEUPRECTEXTEND},
74 {'[', SCI_CTRL, SCI_PARAUP},
75 {'[', SCI_CSHIFT, SCI_PARAUPEXTEND},
76 {']', SCI_CTRL, SCI_PARADOWN},
77 {']', SCI_CSHIFT, SCI_PARADOWNEXTEND},
d134f170
RD
78 {SCK_LEFT, SCI_NORM, SCI_CHARLEFT},
79 {SCK_LEFT, SCI_SHIFT, SCI_CHARLEFTEXTEND},
80 {SCK_LEFT, SCI_CTRL, SCI_WORDLEFT},
81 {SCK_LEFT, SCI_CSHIFT, SCI_WORDLEFTEXTEND},
8e54aaed 82 {SCK_LEFT, SCI_ASHIFT, SCI_CHARLEFTRECTEXTEND},
d134f170
RD
83 {SCK_RIGHT, SCI_NORM, SCI_CHARRIGHT},
84 {SCK_RIGHT, SCI_SHIFT, SCI_CHARRIGHTEXTEND},
85 {SCK_RIGHT, SCI_CTRL, SCI_WORDRIGHT},
86 {SCK_RIGHT, SCI_CSHIFT, SCI_WORDRIGHTEXTEND},
8e54aaed
RD
87 {SCK_RIGHT, SCI_ASHIFT, SCI_CHARRIGHTRECTEXTEND},
88 {'/', SCI_CTRL, SCI_WORDPARTLEFT},
89 {'/', SCI_CSHIFT, SCI_WORDPARTLEFTEXTEND},
90 {'\\', SCI_CTRL, SCI_WORDPARTRIGHT},
91 {'\\', SCI_CSHIFT, SCI_WORDPARTRIGHTEXTEND},
92 {SCK_HOME, SCI_NORM, SCI_VCHOME},
d134f170
RD
93 {SCK_HOME, SCI_SHIFT, SCI_VCHOMEEXTEND},
94 {SCK_HOME, SCI_CTRL, SCI_DOCUMENTSTART},
95 {SCK_HOME, SCI_CSHIFT, SCI_DOCUMENTSTARTEXTEND},
f114b858 96 {SCK_HOME, SCI_ALT, SCI_HOMEDISPLAY},
8e54aaed
RD
97// {SCK_HOME, SCI_ASHIFT, SCI_HOMEDISPLAYEXTEND},
98 {SCK_HOME, SCI_ASHIFT, SCI_VCHOMERECTEXTEND},
99 {SCK_END, SCI_NORM, SCI_LINEEND},
d134f170
RD
100 {SCK_END, SCI_SHIFT, SCI_LINEENDEXTEND},
101 {SCK_END, SCI_CTRL, SCI_DOCUMENTEND},
102 {SCK_END, SCI_CSHIFT, SCI_DOCUMENTENDEXTEND},
f114b858 103 {SCK_END, SCI_ALT, SCI_LINEENDDISPLAY},
8e54aaed
RD
104// {SCK_END, SCI_ASHIFT, SCI_LINEENDDISPLAYEXTEND},
105 {SCK_END, SCI_ASHIFT, SCI_LINEENDRECTEXTEND},
106 {SCK_PRIOR, SCI_NORM, SCI_PAGEUP},
d134f170 107 {SCK_PRIOR, SCI_SHIFT, SCI_PAGEUPEXTEND},
8e54aaed 108 {SCK_PRIOR, SCI_ASHIFT, SCI_PAGEUPRECTEXTEND},
d134f170
RD
109 {SCK_NEXT, SCI_NORM, SCI_PAGEDOWN},
110 {SCK_NEXT, SCI_SHIFT, SCI_PAGEDOWNEXTEND},
8e54aaed 111 {SCK_NEXT, SCI_ASHIFT, SCI_PAGEDOWNRECTEXTEND},
d134f170
RD
112 {SCK_DELETE, SCI_NORM, SCI_CLEAR},
113 {SCK_DELETE, SCI_SHIFT, SCI_CUT},
114 {SCK_DELETE, SCI_CTRL, SCI_DELWORDRIGHT},
65ec6247 115 {SCK_DELETE, SCI_CSHIFT, SCI_DELLINERIGHT},
d134f170
RD
116 {SCK_INSERT, SCI_NORM, SCI_EDITTOGGLEOVERTYPE},
117 {SCK_INSERT, SCI_SHIFT, SCI_PASTE},
118 {SCK_INSERT, SCI_CTRL, SCI_COPY},
119 {SCK_ESCAPE, SCI_NORM, SCI_CANCEL},
120 {SCK_BACK, SCI_NORM, SCI_DELETEBACK},
121 {SCK_BACK, SCI_SHIFT, SCI_DELETEBACK},
122 {SCK_BACK, SCI_CTRL, SCI_DELWORDLEFT},
123 {SCK_BACK, SCI_ALT, SCI_UNDO},
9e730a78 124 {SCK_BACK, SCI_CSHIFT, SCI_DELLINELEFT},
d134f170 125 {'Z', SCI_CTRL, SCI_UNDO},
f6bcfd97 126 {'Y', SCI_CTRL, SCI_REDO},
d134f170
RD
127 {'X', SCI_CTRL, SCI_CUT},
128 {'C', SCI_CTRL, SCI_COPY},
129 {'V', SCI_CTRL, SCI_PASTE},
f6bcfd97 130 {'A', SCI_CTRL, SCI_SELECTALL},
d134f170
RD
131 {SCK_TAB, SCI_NORM, SCI_TAB},
132 {SCK_TAB, SCI_SHIFT, SCI_BACKTAB},
133 {SCK_RETURN, SCI_NORM, SCI_NEWLINE},
f114b858 134 {SCK_RETURN, SCI_SHIFT, SCI_NEWLINE},
d134f170
RD
135 {SCK_ADD, SCI_CTRL, SCI_ZOOMIN},
136 {SCK_SUBTRACT, SCI_CTRL, SCI_ZOOMOUT},
137 {SCK_DIVIDE, SCI_CTRL, SCI_SETZOOM},
f6bcfd97
BP
138 //'L', SCI_CTRL, SCI_FORMFEED,
139 {'L', SCI_CTRL, SCI_LINECUT},
140 {'L', SCI_CSHIFT, SCI_LINEDELETE},
e14d10b0 141 {'T', SCI_CSHIFT, SCI_LINECOPY},
f6bcfd97 142 {'T', SCI_CTRL, SCI_LINETRANSPOSE},
9e730a78 143 {'D', SCI_CTRL, SCI_LINEDUPLICATE},
f6bcfd97
BP
144 {'U', SCI_CTRL, SCI_LOWERCASE},
145 {'U', SCI_CSHIFT, SCI_UPPERCASE},
146 {0,0,0},
9ce192d4
RD
147};
148