]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/scintilla/src/AutoComplete.cxx
5bc50d1efab3dfe8db55159a75ff693d6349e4e0
[wxWidgets.git] / contrib / src / stc / scintilla / src / AutoComplete.cxx
1 // Scintilla source code edit control
2 // AutoComplete.cxx - defines the auto completion list box
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 <stdlib.h>
7 #include <string.h>
8
9 #include "Platform.h"
10
11 #include "AutoComplete.h"
12
13 AutoComplete::AutoComplete() :
14 active(false),
15 separator(' '),
16 ignoreCase(false),
17 chooseSingle(false),
18 posStart(0),
19 startLen(0),
20 cancelAtStartPos(true) {
21 stopChars[0] = '\0';
22 fillUpChars[0] = '\0';
23 }
24
25 AutoComplete::~AutoComplete() {
26 lb.Destroy();
27 }
28
29 bool AutoComplete::Active() {
30 return active;
31 }
32
33 void AutoComplete::Start(Window &parent, int ctrlID, int position, int startLen_) {
34 if (!lb.Created()) {
35 lb.Create(parent, ctrlID);
36 }
37 lb.Clear();
38 active = true;
39 startLen = startLen_;
40 posStart = position;
41 }
42
43 void AutoComplete::SetStopChars(const char *stopChars_) {
44 strncpy(stopChars, stopChars_, sizeof(stopChars));
45 stopChars[sizeof(stopChars) - 1] = '\0';
46 }
47
48 bool AutoComplete::IsStopChar(char ch) {
49 return ch && strchr(stopChars, ch);
50 }
51
52 void AutoComplete::SetFillUpChars(const char *fillUpChars_) {
53 strncpy(fillUpChars, fillUpChars_, sizeof(fillUpChars));
54 fillUpChars[sizeof(fillUpChars) - 1] = '\0';
55 }
56
57 bool AutoComplete::IsFillUpChar(char ch) {
58 return ch && strchr(fillUpChars, ch);
59 }
60
61 void AutoComplete::SetSeparator(char separator_) {
62 separator = separator_;
63 }
64
65 char AutoComplete::GetSeparator() {
66 return separator;
67 }
68
69 void AutoComplete::SetList(const char *list) {
70 lb.Clear();
71 char *words = new char[strlen(list) + 1];
72 if (words) {
73 strcpy(words, list);
74 char *startword = words;
75 int i = 0;
76 for (; words && words[i]; i++) {
77 if (words[i] == separator) {
78 words[i] = '\0';
79 lb.Append(startword);
80 startword = words + i + 1;
81 }
82 }
83 if (startword) {
84 lb.Append(startword);
85 }
86 delete []words;
87 }
88 lb.Sort();
89 }
90
91 void AutoComplete::Show() {
92 lb.Show();
93 lb.Select(0);
94 }
95
96 void AutoComplete::Cancel() {
97 if (lb.Created()) {
98 lb.Destroy();
99 active = false;
100 }
101 }
102
103
104 void AutoComplete::Move(int delta) {
105 int count = lb.Length();
106 int current = lb.GetSelection();
107 current += delta;
108 if (current >= count)
109 current = count - 1;
110 if (current < 0)
111 current = 0;
112 lb.Select(current);
113 }
114
115 void AutoComplete::Select(const char *word) {
116 int pos = lb.Find(word);
117 //Platform::DebugPrintf("Autocompleting at <%s> %d\n", wordCurrent, pos);
118 if (pos != -1)
119 lb.Select(pos);
120 }
121