]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/scintilla/src/KeyMap.cxx
9ab9694df15b9b99d9ec18a45d571c92950c925d
[wxWidgets.git] / contrib / src / stc / scintilla / src / KeyMap.cxx
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
31 void KeyMap::AssignCmdKey(int key, int modifiers, UINT msg) {
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
54 UINT KeyMap::Find(int key, int modifiers) {
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[] = {
64 VK_DOWN, SCI_NORM, SCI_LINEDOWN,
65 VK_DOWN, SCI_SHIFT, SCI_LINEDOWNEXTEND,
66 VK_UP, SCI_NORM, SCI_LINEUP,
67 VK_UP, SCI_SHIFT, SCI_LINEUPEXTEND,
68 VK_LEFT, SCI_NORM, SCI_CHARLEFT,
69 VK_LEFT, SCI_SHIFT, SCI_CHARLEFTEXTEND,
70 VK_LEFT, SCI_CTRL, SCI_WORDLEFT,
71 VK_LEFT, SCI_CSHIFT, SCI_WORDLEFTEXTEND,
72 VK_RIGHT, SCI_NORM, SCI_CHARRIGHT,
73 VK_RIGHT, SCI_SHIFT, SCI_CHARRIGHTEXTEND,
74 VK_RIGHT, SCI_CTRL, SCI_WORDRIGHT,
75 VK_RIGHT, SCI_CSHIFT, SCI_WORDRIGHTEXTEND,
76 VK_HOME, SCI_NORM, SCI_VCHOME,
77 VK_HOME, SCI_SHIFT, SCI_VCHOMEEXTEND,
78 VK_HOME, SCI_CTRL, SCI_DOCUMENTSTART,
79 VK_HOME, SCI_CSHIFT, SCI_DOCUMENTSTARTEXTEND,
80 VK_END, SCI_NORM, SCI_LINEEND,
81 VK_END, SCI_SHIFT, SCI_LINEENDEXTEND,
82 VK_END, SCI_CTRL, SCI_DOCUMENTEND,
83 VK_END, SCI_CSHIFT, SCI_DOCUMENTENDEXTEND,
84 VK_PRIOR, SCI_NORM, SCI_PAGEUP,
85 VK_PRIOR, SCI_SHIFT, SCI_PAGEUPEXTEND,
86 VK_NEXT, SCI_NORM, SCI_PAGEDOWN,
87 VK_NEXT, SCI_SHIFT, SCI_PAGEDOWNEXTEND,
88 VK_DELETE, SCI_NORM, WM_CLEAR,
89 VK_DELETE, SCI_SHIFT, WM_CUT,
90 VK_DELETE, SCI_CTRL, SCI_DELWORDRIGHT,
91 VK_INSERT, SCI_NORM, SCI_EDITTOGGLEOVERTYPE,
92 VK_INSERT, SCI_SHIFT, WM_PASTE,
93 VK_INSERT, SCI_CTRL, WM_COPY,
94 VK_ESCAPE, SCI_NORM, SCI_CANCEL,
95 VK_BACK, SCI_NORM, SCI_DELETEBACK,
96 VK_BACK, SCI_CTRL, SCI_DELWORDLEFT,
97 'Z', SCI_CTRL, WM_UNDO,
98 'Y', SCI_CTRL, SCI_REDO,
99 'X', SCI_CTRL, WM_CUT,
100 'C', SCI_CTRL, WM_COPY,
101 'V', SCI_CTRL, WM_PASTE,
102 'A', SCI_CTRL, SCI_SELECTALL,
103 VK_TAB, SCI_NORM, SCI_TAB,
104 VK_TAB, SCI_SHIFT, SCI_BACKTAB,
105 VK_RETURN, SCI_NORM, SCI_NEWLINE,
106 VK_ADD, SCI_CTRL, SCI_ZOOMIN,
107 VK_SUBTRACT, SCI_CTRL, SCI_ZOOMOUT,
108 //'L', SCI_CTRL, SCI_FORMFEED,
109 'L', SCI_CTRL, SCI_LINECUT,
110 'L', SCI_CSHIFT, SCI_LINEDELETE,
111 'T', SCI_CTRL, SCI_LINETRANSPOSE,
112 'U', SCI_CTRL, SCI_LOWERCASE,
113 'U', SCI_CSHIFT, SCI_UPPERCASE,
114 0,0,0,
115 };
116