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 "CharacterSet.h"
16 #include "AutoComplete.h"
19 using namespace Scintilla
;
22 AutoComplete::AutoComplete() :
31 cancelAtStartPos(true),
33 dropRestOfWord(false) {
34 lb
= ListBox::Allocate();
36 fillUpChars
[0] = '\0';
39 AutoComplete::~AutoComplete() {
47 bool AutoComplete::Active() const {
51 void AutoComplete::Start(Window
&parent
, int ctrlID
,
52 int position
, Point location
, int startLen_
,
53 int lineHeight
, bool unicodeMode
) {
57 lb
->Create(parent
, ctrlID
, location
, lineHeight
, unicodeMode
);
64 void AutoComplete::SetStopChars(const char *stopChars_
) {
65 strncpy(stopChars
, stopChars_
, sizeof(stopChars
));
66 stopChars
[sizeof(stopChars
) - 1] = '\0';
69 bool AutoComplete::IsStopChar(char ch
) {
70 return ch
&& strchr(stopChars
, ch
);
73 void AutoComplete::SetFillUpChars(const char *fillUpChars_
) {
74 strncpy(fillUpChars
, fillUpChars_
, sizeof(fillUpChars
));
75 fillUpChars
[sizeof(fillUpChars
) - 1] = '\0';
78 bool AutoComplete::IsFillUpChar(char ch
) {
79 return ch
&& strchr(fillUpChars
, ch
);
82 void AutoComplete::SetSeparator(char separator_
) {
83 separator
= separator_
;
86 char AutoComplete::GetSeparator() const {
90 void AutoComplete::SetTypesep(char separator_
) {
94 char AutoComplete::GetTypesep() const {
98 void AutoComplete::SetList(const char *list
) {
99 lb
->SetList(list
, separator
, typesep
);
102 void AutoComplete::Show(bool show
) {
108 void AutoComplete::Cancel() {
117 void AutoComplete::Move(int delta
) {
118 int count
= lb
->Length();
119 int current
= lb
->GetSelection();
121 if (current
>= count
)
128 void AutoComplete::Select(const char *word
) {
129 size_t lenWord
= strlen(word
);
131 const int maxItemLen
=1000;
132 int start
= 0; // lower bound of the api array block to search
133 int end
= lb
->Length() - 1; // upper bound of the api array block to search
134 while ((start
<= end
) && (location
== -1)) { // Binary searching loop
135 int pivot
= (start
+ end
) / 2;
136 char item
[maxItemLen
];
137 lb
->GetValue(pivot
, item
, maxItemLen
);
140 cond
= CompareNCaseInsensitive(word
, item
, lenWord
);
142 cond
= strncmp(word
, item
, lenWord
);
145 while (pivot
> start
) {
146 lb
->GetValue(pivot
-1, item
, maxItemLen
);
148 cond
= CompareNCaseInsensitive(word
, item
, lenWord
);
150 cond
= strncmp(word
, item
, lenWord
);
157 // Check for exact-case match
158 for (; pivot
<= end
; pivot
++) {
159 lb
->GetValue(pivot
, item
, maxItemLen
);
160 if (!strncmp(word
, item
, lenWord
)) {
164 if (CompareNCaseInsensitive(word
, item
, lenWord
))
168 } else if (cond
< 0) {
170 } else if (cond
> 0) {
174 if (location
== -1 && autoHide
)
177 lb
->Select(location
);