diff options
Diffstat (limited to 'scintilla/src/KeyMap.cxx')
-rw-r--r-- | scintilla/src/KeyMap.cxx | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/scintilla/src/KeyMap.cxx b/scintilla/src/KeyMap.cxx index a659a77..74e7a2d 100644 --- a/scintilla/src/KeyMap.cxx +++ b/scintilla/src/KeyMap.cxx @@ -5,6 +5,10 @@ // Copyright 1998-2003 by Neil Hodgson <neilh@scintilla.org>
// The License.txt file describes the conditions under which this software may be distributed.
+#include <stdlib.h>
+
+#include <vector>
+
#include "Platform.h"
#include "Scintilla.h"
@@ -15,7 +19,7 @@ using namespace Scintilla;
#endif
-KeyMap::KeyMap() : kmap(0), len(0), alloc(0) {
+KeyMap::KeyMap() {
for (int i = 0; MapDefault[i].key; i++) {
AssignCmdKey(MapDefault[i].key,
MapDefault[i].modifiers,
@@ -28,37 +32,25 @@ KeyMap::~KeyMap() { }
void KeyMap::Clear() {
- delete []kmap;
- kmap = 0;
- len = 0;
- alloc = 0;
+ kmap.clear();
}
void KeyMap::AssignCmdKey(int key, int modifiers, unsigned int msg) {
- if ((len+1) >= alloc) {
- KeyToCommand *ktcNew = new KeyToCommand[alloc + 5];
- if (!ktcNew)
- return;
- for (int k = 0; k < len; k++)
- ktcNew[k] = kmap[k];
- alloc += 5;
- delete []kmap;
- kmap = ktcNew;
- }
- for (int keyIndex = 0; keyIndex < len; keyIndex++) {
+ for (size_t keyIndex = 0; keyIndex < kmap.size(); keyIndex++) {
if ((key == kmap[keyIndex].key) && (modifiers == kmap[keyIndex].modifiers)) {
kmap[keyIndex].msg = msg;
return;
}
}
- kmap[len].key = key;
- kmap[len].modifiers = modifiers;
- kmap[len].msg = msg;
- len++;
+ KeyToCommand ktc;
+ ktc.key = key;
+ ktc.modifiers = modifiers;
+ ktc.msg = msg;
+ kmap.push_back(ktc);
}
unsigned int KeyMap::Find(int key, int modifiers) {
- for (int i = 0; i < len; i++) {
+ for (size_t i = 0; i < kmap.size(); i++) {
if ((key == kmap[i].key) && (modifiers == kmap[i].modifiers)) {
return kmap[i].msg;
}
|