]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/scintilla/src/KeyMap.cxx
implemented IsModified() and DiscardEdits()
[wxWidgets.git] / contrib / 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-2001 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 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
33 void KeyMap::AssignCmdKey(int key, int modifiers, unsigned int msg) {
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
56 unsigned int KeyMap::Find(int key, int modifiers) {
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
65 const KeyToCommand KeyMap::MapDefault[] = {
66 {SCK_DOWN, SCI_NORM, SCI_LINEDOWN},
67 {SCK_DOWN, SCI_SHIFT, SCI_LINEDOWNEXTEND},
68 {SCK_DOWN, SCI_CTRL, SCI_LINESCROLLDOWN},
69 {SCK_DOWN, SCI_ALT, SCI_PARADOWN},
70 {SCK_DOWN, SCI_ASHIFT, SCI_PARADOWNEXTEND},
71 {SCK_UP, SCI_NORM, SCI_LINEUP},
72 {SCK_UP, SCI_SHIFT, SCI_LINEUPEXTEND},
73 {SCK_UP, SCI_CTRL, SCI_LINESCROLLUP},
74 {SCK_UP, SCI_ALT, SCI_PARAUP},
75 {SCK_UP, SCI_ASHIFT, SCI_PARAUPEXTEND},
76 {SCK_LEFT, SCI_NORM, SCI_CHARLEFT},
77 {SCK_LEFT, SCI_SHIFT, SCI_CHARLEFTEXTEND},
78 {SCK_LEFT, SCI_CTRL, SCI_WORDLEFT},
79 {SCK_LEFT, SCI_CSHIFT, SCI_WORDLEFTEXTEND},
80 {SCK_LEFT, SCI_ALT, SCI_WORDPARTLEFT},
81 {SCK_LEFT, SCI_ASHIFT, SCI_WORDPARTLEFTEXTEND},
82 {SCK_RIGHT, SCI_NORM, SCI_CHARRIGHT},
83 {SCK_RIGHT, SCI_SHIFT, SCI_CHARRIGHTEXTEND},
84 {SCK_RIGHT, SCI_CTRL, SCI_WORDRIGHT},
85 {SCK_RIGHT, SCI_CSHIFT, SCI_WORDRIGHTEXTEND},
86 {SCK_RIGHT, SCI_ALT, SCI_WORDPARTRIGHT},
87 {SCK_RIGHT, SCI_ASHIFT, SCI_WORDPARTRIGHTEXTEND},
88 {SCK_HOME, SCI_NORM, SCI_VCHOME},
89 {SCK_HOME, SCI_SHIFT, SCI_VCHOMEEXTEND},
90 {SCK_HOME, SCI_CTRL, SCI_DOCUMENTSTART},
91 {SCK_HOME, SCI_CSHIFT, SCI_DOCUMENTSTARTEXTEND},
92 {SCK_HOME, SCI_ALT, SCI_HOMEDISPLAY},
93 {SCK_HOME, SCI_ASHIFT, SCI_HOMEDISPLAYEXTEND},
94 {SCK_END, SCI_NORM, SCI_LINEEND},
95 {SCK_END, SCI_SHIFT, SCI_LINEENDEXTEND},
96 {SCK_END, SCI_CTRL, SCI_DOCUMENTEND},
97 {SCK_END, SCI_CSHIFT, SCI_DOCUMENTENDEXTEND},
98 {SCK_END, SCI_ALT, SCI_LINEENDDISPLAY},
99 {SCK_END, SCI_ASHIFT, SCI_LINEENDDISPLAYEXTEND},
100 {SCK_PRIOR, SCI_NORM, SCI_PAGEUP},
101 {SCK_PRIOR, SCI_SHIFT, SCI_PAGEUPEXTEND},
102 {SCK_NEXT, SCI_NORM, SCI_PAGEDOWN},
103 {SCK_NEXT, SCI_SHIFT, SCI_PAGEDOWNEXTEND},
104 {SCK_DELETE, SCI_NORM, SCI_CLEAR},
105 {SCK_DELETE, SCI_SHIFT, SCI_CUT},
106 {SCK_DELETE, SCI_CTRL, SCI_DELWORDRIGHT},
107 {SCK_DELETE, SCI_CSHIFT, SCI_DELLINERIGHT},
108 {SCK_INSERT, SCI_NORM, SCI_EDITTOGGLEOVERTYPE},
109 {SCK_INSERT, SCI_SHIFT, SCI_PASTE},
110 {SCK_INSERT, SCI_CTRL, SCI_COPY},
111 {SCK_ESCAPE, SCI_NORM, SCI_CANCEL},
112 {SCK_BACK, SCI_NORM, SCI_DELETEBACK},
113 {SCK_BACK, SCI_SHIFT, SCI_DELETEBACK},
114 {SCK_BACK, SCI_CTRL, SCI_DELWORDLEFT},
115 {SCK_BACK, SCI_ALT, SCI_UNDO},
116 {SCK_BACK, SCI_CSHIFT, SCI_DELLINELEFT},
117 {'Z', SCI_CTRL, SCI_UNDO},
118 {'Y', SCI_CTRL, SCI_REDO},
119 {'X', SCI_CTRL, SCI_CUT},
120 {'C', SCI_CTRL, SCI_COPY},
121 {'V', SCI_CTRL, SCI_PASTE},
122 {'A', SCI_CTRL, SCI_SELECTALL},
123 {SCK_TAB, SCI_NORM, SCI_TAB},
124 {SCK_TAB, SCI_SHIFT, SCI_BACKTAB},
125 {SCK_RETURN, SCI_NORM, SCI_NEWLINE},
126 {SCK_RETURN, SCI_SHIFT, SCI_NEWLINE},
127 {SCK_ADD, SCI_CTRL, SCI_ZOOMIN},
128 {SCK_SUBTRACT, SCI_CTRL, SCI_ZOOMOUT},
129 {SCK_DIVIDE, SCI_CTRL, SCI_SETZOOM},
130 //'L', SCI_CTRL, SCI_FORMFEED,
131 {'L', SCI_CTRL, SCI_LINECUT},
132 {'L', SCI_CSHIFT, SCI_LINEDELETE},
133 {'T', SCI_CSHIFT, SCI_LINECOPY},
134 {'T', SCI_CTRL, SCI_LINETRANSPOSE},
135 {'D', SCI_CTRL, SCI_LINEDUPLICATE},
136 {'U', SCI_CTRL, SCI_LOWERCASE},
137 {'U', SCI_CSHIFT, SCI_UPPERCASE},
138 {0,0,0},
139 };
140