]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/scintilla/src/AutoComplete.cxx
1 // Scintilla source code edit control
2 /** @file AutoComplete.cxx
3 ** Defines the auto completion list box.
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.
15 #include "AutoComplete.h"
17 AutoComplete::AutoComplete() :
26 cancelAtStartPos(true),
28 dropRestOfWord(false) {
29 lb
= ListBox::Allocate();
31 fillUpChars
[0] = '\0';
34 AutoComplete::~AutoComplete() {
42 bool AutoComplete::Active() {
46 void AutoComplete::Start(Window
&parent
, int ctrlID
, int position
,
47 int startLen_
, int lineHeight
, bool unicodeMode
) {
51 lb
->Create(parent
, ctrlID
, lineHeight
, unicodeMode
);
58 void AutoComplete::SetStopChars(const char *stopChars_
) {
59 strncpy(stopChars
, stopChars_
, sizeof(stopChars
));
60 stopChars
[sizeof(stopChars
) - 1] = '\0';
63 bool AutoComplete::IsStopChar(char ch
) {
64 return ch
&& strchr(stopChars
, ch
);
67 void AutoComplete::SetFillUpChars(const char *fillUpChars_
) {
68 strncpy(fillUpChars
, fillUpChars_
, sizeof(fillUpChars
));
69 fillUpChars
[sizeof(fillUpChars
) - 1] = '\0';
72 bool AutoComplete::IsFillUpChar(char ch
) {
73 return ch
&& strchr(fillUpChars
, ch
);
76 void AutoComplete::SetSeparator(char separator_
) {
77 separator
= separator_
;
80 char AutoComplete::GetSeparator() {
84 void AutoComplete::SetTypesep(char separator_
) {
88 char AutoComplete::GetTypesep() {
92 void AutoComplete::SetList(const char *list
) {
94 char *words
= new char[strlen(list
) + 1];
97 char *startword
= words
;
100 for (; words
&& words
[i
]; i
++) {
101 if (words
[i
] == separator
) {
105 lb
->Append(startword
, numword
?atoi(numword
+ 1):-1);
106 startword
= words
+ i
+ 1;
108 } else if (words
[i
] == typesep
) {
115 lb
->Append(startword
, numword
?atoi(numword
+ 1):-1);
121 void AutoComplete::Show() {
126 void AutoComplete::Cancel() {
134 void AutoComplete::Move(int delta
) {
135 int count
= lb
->Length();
136 int current
= lb
->GetSelection();
138 if (current
>= count
)
145 void AutoComplete::Select(const char *word
) {
146 size_t lenWord
= strlen(word
);
148 const int maxItemLen
=1000;
149 char item
[maxItemLen
];
150 int start
= 0; // lower bound of the api array block to search
151 int end
= lb
->Length() - 1; // upper bound of the api array block to search
152 while ((start
<= end
) && (location
== -1)) { // Binary searching loop
153 int pivot
= (start
+ end
) / 2;
154 lb
->GetValue(pivot
, item
, maxItemLen
);
157 cond
= CompareNCaseInsensitive(word
, item
, lenWord
);
159 cond
= strncmp(word
, item
, lenWord
);
162 while (pivot
> start
) {
163 lb
->GetValue(pivot
-1, item
, maxItemLen
);
165 cond
= CompareNCaseInsensitive(word
, item
, lenWord
);
167 cond
= strncmp(word
, item
, lenWord
);
173 } else if (cond
< 0) {
175 } else if (cond
> 0) {
179 if (location
== -1 && autoHide
)
182 lb
->Select(location
);