Merge pull request #1404 from b4n/search/gtk-3-20-history
[geany-mirror.git] / scintilla / src / KeyMap.cxx
bloba6b1cf6c417fbde6192767eb13e77e397e1115e6
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.
8 #include <stdlib.h>
10 #include <stdexcept>
11 #include <vector>
12 #include <map>
14 #include "Platform.h"
16 #include "Scintilla.h"
18 #include "KeyMap.h"
20 #ifdef SCI_NAMESPACE
21 using namespace Scintilla;
22 #endif
24 KeyMap::KeyMap() {
25 for (int i = 0; MapDefault[i].key; i++) {
26 AssignCmdKey(MapDefault[i].key,
27 MapDefault[i].modifiers,
28 MapDefault[i].msg);
32 KeyMap::~KeyMap() {
33 Clear();
36 void KeyMap::Clear() {
37 kmap.clear();
40 void KeyMap::AssignCmdKey(int key, int modifiers, unsigned int msg) {
41 kmap[KeyModifiers(key, modifiers)] = msg;
44 unsigned int KeyMap::Find(int key, int modifiers) const {
45 std::map<KeyModifiers, unsigned int>::const_iterator it = kmap.find(KeyModifiers(key, modifiers));
46 return (it == kmap.end()) ? 0 : it->second;
49 #if PLAT_GTK_MACOSX
50 #define OS_X_KEYS 1
51 #else
52 #define OS_X_KEYS 0
53 #endif
55 // Define a modifier that is exactly Ctrl key on all platforms
56 // Most uses of Ctrl map to Cmd on OS X but some can't so use SCI_[S]CTRL_META
57 #if OS_X_KEYS
58 #define SCI_CTRL_META SCI_META
59 #define SCI_SCTRL_META (SCI_META | SCI_SHIFT)
60 #else
61 #define SCI_CTRL_META SCI_CTRL
62 #define SCI_SCTRL_META (SCI_CTRL | SCI_SHIFT)
63 #endif
65 const KeyToCommand KeyMap::MapDefault[] = {
67 #if OS_X_KEYS
68 {SCK_DOWN, SCI_CTRL, SCI_DOCUMENTEND},
69 {SCK_DOWN, SCI_CSHIFT, SCI_DOCUMENTENDEXTEND},
70 {SCK_UP, SCI_CTRL, SCI_DOCUMENTSTART},
71 {SCK_UP, SCI_CSHIFT, SCI_DOCUMENTSTARTEXTEND},
72 {SCK_LEFT, SCI_CTRL, SCI_VCHOME},
73 {SCK_LEFT, SCI_CSHIFT, SCI_VCHOMEEXTEND},
74 {SCK_RIGHT, SCI_CTRL, SCI_LINEEND},
75 {SCK_RIGHT, SCI_CSHIFT, SCI_LINEENDEXTEND},
76 #endif
78 {SCK_DOWN, SCI_NORM, SCI_LINEDOWN},
79 {SCK_DOWN, SCI_SHIFT, SCI_LINEDOWNEXTEND},
80 {SCK_DOWN, SCI_CTRL_META, SCI_LINESCROLLDOWN},
81 {SCK_DOWN, SCI_ASHIFT, SCI_LINEDOWNRECTEXTEND},
82 {SCK_UP, SCI_NORM, SCI_LINEUP},
83 {SCK_UP, SCI_SHIFT, SCI_LINEUPEXTEND},
84 {SCK_UP, SCI_CTRL_META, SCI_LINESCROLLUP},
85 {SCK_UP, SCI_ASHIFT, SCI_LINEUPRECTEXTEND},
86 {'[', SCI_CTRL, SCI_PARAUP},
87 {'[', SCI_CSHIFT, SCI_PARAUPEXTEND},
88 {']', SCI_CTRL, SCI_PARADOWN},
89 {']', SCI_CSHIFT, SCI_PARADOWNEXTEND},
90 {SCK_LEFT, SCI_NORM, SCI_CHARLEFT},
91 {SCK_LEFT, SCI_SHIFT, SCI_CHARLEFTEXTEND},
92 {SCK_LEFT, SCI_CTRL_META, SCI_WORDLEFT},
93 {SCK_LEFT, SCI_SCTRL_META, SCI_WORDLEFTEXTEND},
94 {SCK_LEFT, SCI_ASHIFT, SCI_CHARLEFTRECTEXTEND},
95 {SCK_RIGHT, SCI_NORM, SCI_CHARRIGHT},
96 {SCK_RIGHT, SCI_SHIFT, SCI_CHARRIGHTEXTEND},
97 {SCK_RIGHT, SCI_CTRL_META, SCI_WORDRIGHT},
98 {SCK_RIGHT, SCI_SCTRL_META, SCI_WORDRIGHTEXTEND},
99 {SCK_RIGHT, SCI_ASHIFT, SCI_CHARRIGHTRECTEXTEND},
100 {'/', SCI_CTRL, SCI_WORDPARTLEFT},
101 {'/', SCI_CSHIFT, SCI_WORDPARTLEFTEXTEND},
102 {'\\', SCI_CTRL, SCI_WORDPARTRIGHT},
103 {'\\', SCI_CSHIFT, SCI_WORDPARTRIGHTEXTEND},
104 {SCK_HOME, SCI_NORM, SCI_VCHOME},
105 {SCK_HOME, SCI_SHIFT, SCI_VCHOMEEXTEND},
106 {SCK_HOME, SCI_CTRL, SCI_DOCUMENTSTART},
107 {SCK_HOME, SCI_CSHIFT, SCI_DOCUMENTSTARTEXTEND},
108 {SCK_HOME, SCI_ALT, SCI_HOMEDISPLAY},
109 {SCK_HOME, SCI_ASHIFT, SCI_VCHOMERECTEXTEND},
110 {SCK_END, SCI_NORM, SCI_LINEEND},
111 {SCK_END, SCI_SHIFT, SCI_LINEENDEXTEND},
112 {SCK_END, SCI_CTRL, SCI_DOCUMENTEND},
113 {SCK_END, SCI_CSHIFT, SCI_DOCUMENTENDEXTEND},
114 {SCK_END, SCI_ALT, SCI_LINEENDDISPLAY},
115 {SCK_END, SCI_ASHIFT, SCI_LINEENDRECTEXTEND},
116 {SCK_PRIOR, SCI_NORM, SCI_PAGEUP},
117 {SCK_PRIOR, SCI_SHIFT, SCI_PAGEUPEXTEND},
118 {SCK_PRIOR, SCI_ASHIFT, SCI_PAGEUPRECTEXTEND},
119 {SCK_NEXT, SCI_NORM, SCI_PAGEDOWN},
120 {SCK_NEXT, SCI_SHIFT, SCI_PAGEDOWNEXTEND},
121 {SCK_NEXT, SCI_ASHIFT, SCI_PAGEDOWNRECTEXTEND},
122 {SCK_DELETE, SCI_NORM, SCI_CLEAR},
123 {SCK_DELETE, SCI_SHIFT, SCI_CUT},
124 {SCK_DELETE, SCI_CTRL, SCI_DELWORDRIGHT},
125 {SCK_DELETE, SCI_CSHIFT, SCI_DELLINERIGHT},
126 {SCK_INSERT, SCI_NORM, SCI_EDITTOGGLEOVERTYPE},
127 {SCK_INSERT, SCI_SHIFT, SCI_PASTE},
128 {SCK_INSERT, SCI_CTRL, SCI_COPY},
129 {SCK_ESCAPE, SCI_NORM, SCI_CANCEL},
130 {SCK_BACK, SCI_NORM, SCI_DELETEBACK},
131 {SCK_BACK, SCI_SHIFT, SCI_DELETEBACK},
132 {SCK_BACK, SCI_CTRL, SCI_DELWORDLEFT},
133 {SCK_BACK, SCI_ALT, SCI_UNDO},
134 {SCK_BACK, SCI_CSHIFT, SCI_DELLINELEFT},
135 {'Z', SCI_CTRL, SCI_UNDO},
136 #if OS_X_KEYS
137 {'Z', SCI_CSHIFT, SCI_REDO},
138 #else
139 {'Y', SCI_CTRL, SCI_REDO},
140 #endif
141 {'X', SCI_CTRL, SCI_CUT},
142 {'C', SCI_CTRL, SCI_COPY},
143 {'V', SCI_CTRL, SCI_PASTE},
144 {'A', SCI_CTRL, SCI_SELECTALL},
145 {SCK_TAB, SCI_NORM, SCI_TAB},
146 {SCK_TAB, SCI_SHIFT, SCI_BACKTAB},
147 {SCK_RETURN, SCI_NORM, SCI_NEWLINE},
148 {SCK_RETURN, SCI_SHIFT, SCI_NEWLINE},
149 {SCK_ADD, SCI_CTRL, SCI_ZOOMIN},
150 {SCK_SUBTRACT, SCI_CTRL, SCI_ZOOMOUT},
151 {SCK_DIVIDE, SCI_CTRL, SCI_SETZOOM},
152 {'L', SCI_CTRL, SCI_LINECUT},
153 {'L', SCI_CSHIFT, SCI_LINEDELETE},
154 {'T', SCI_CSHIFT, SCI_LINECOPY},
155 {'T', SCI_CTRL, SCI_LINETRANSPOSE},
156 {'D', SCI_CTRL, SCI_SELECTIONDUPLICATE},
157 {'U', SCI_CTRL, SCI_LOWERCASE},
158 {'U', SCI_CSHIFT, SCI_UPPERCASE},
159 {0,0,0},