]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/scintilla/src/AutoComplete.cxx
48aaee38ae75cbb7d598f24184a076db443aec76
1 // Scintilla source code edit control
2 /** @file AutoComplete.cxx
3 ** Defines the auto completion list box.
5 // Copyright 1998-2002 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() :
24 cancelAtStartPos(true),
26 dropRestOfWord(false) {
28 fillUpChars
[0] = '\0';
31 AutoComplete::~AutoComplete() {
35 bool AutoComplete::Active() {
39 void AutoComplete::Start(Window
&parent
, int ctrlID
, int position
, int startLen_
) {
41 lb
.Create(parent
, ctrlID
);
49 void AutoComplete::SetStopChars(const char *stopChars_
) {
50 strncpy(stopChars
, stopChars_
, sizeof(stopChars
));
51 stopChars
[sizeof(stopChars
) - 1] = '\0';
54 bool AutoComplete::IsStopChar(char ch
) {
55 return ch
&& strchr(stopChars
, ch
);
58 void AutoComplete::SetFillUpChars(const char *fillUpChars_
) {
59 strncpy(fillUpChars
, fillUpChars_
, sizeof(fillUpChars
));
60 fillUpChars
[sizeof(fillUpChars
) - 1] = '\0';
63 bool AutoComplete::IsFillUpChar(char ch
) {
64 return ch
&& strchr(fillUpChars
, ch
);
67 void AutoComplete::SetSeparator(char separator_
) {
68 separator
= separator_
;
71 char AutoComplete::GetSeparator() {
75 void AutoComplete::SetList(const char *list
) {
77 char *words
= new char[strlen(list
) + 1];
80 char *startword
= words
;
82 for (; words
&& words
[i
]; i
++) {
83 if (words
[i
] == separator
) {
86 startword
= words
+ i
+ 1;
96 void AutoComplete::Show() {
101 void AutoComplete::Cancel() {
109 void AutoComplete::Move(int delta
) {
110 int count
= lb
.Length();
111 int current
= lb
.GetSelection();
113 if (current
>= count
)
120 void AutoComplete::Select(const char *word
) {
121 int lenWord
= strlen(word
);
123 const int maxItemLen
=1000;
124 char item
[maxItemLen
];
125 int start
= 0; // lower bound of the api array block to search
126 int end
= lb
.Length() - 1; // upper bound of the api array block to search
127 while ((start
<= end
) && (location
== -1)) { // Binary searching loop
128 int pivot
= (start
+ end
) / 2;
129 lb
.GetValue(pivot
, item
, maxItemLen
);
132 cond
= CompareNCaseInsensitive(word
, item
, lenWord
);
134 cond
= strncmp(word
, item
, lenWord
);
137 while (pivot
> start
) {
138 lb
.GetValue(pivot
-1, item
, maxItemLen
);
140 cond
= CompareNCaseInsensitive(word
, item
, lenWord
);
142 cond
= strncmp(word
, item
, lenWord
);
148 } else if (cond
< 0) {
150 } else if (cond
> 0) {
154 if (location
== -1 && autoHide
)