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.
14 #include "CharClassify.h"
15 #include "AutoComplete.h"
18 using namespace Scintilla
;
21 AutoComplete::AutoComplete() :
30 cancelAtStartPos(true),
32 dropRestOfWord(false) {
33 lb
= ListBox::Allocate();
35 fillUpChars
[0] = '\0';
38 AutoComplete::~AutoComplete() {
46 bool AutoComplete::Active() const {
50 void AutoComplete::Start(Window
&parent
, int ctrlID
,
51 int position
, Point location
, int startLen_
,
52 int lineHeight
, bool unicodeMode
) {
56 lb
->Create(parent
, ctrlID
, location
, lineHeight
, unicodeMode
);
63 void AutoComplete::SetStopChars(const char *stopChars_
) {
64 strncpy(stopChars
, stopChars_
, sizeof(stopChars
));
65 stopChars
[sizeof(stopChars
) - 1] = '\0';
68 bool AutoComplete::IsStopChar(char ch
) {
69 return ch
&& strchr(stopChars
, ch
);
72 void AutoComplete::SetFillUpChars(const char *fillUpChars_
) {
73 strncpy(fillUpChars
, fillUpChars_
, sizeof(fillUpChars
));
74 fillUpChars
[sizeof(fillUpChars
) - 1] = '\0';
77 bool AutoComplete::IsFillUpChar(char ch
) {
78 return ch
&& strchr(fillUpChars
, ch
);
81 void AutoComplete::SetSeparator(char separator_
) {
82 separator
= separator_
;
85 char AutoComplete::GetSeparator() const {
89 void AutoComplete::SetTypesep(char separator_
) {
93 char AutoComplete::GetTypesep() const {
97 void AutoComplete::SetList(const char *list
) {
98 lb
->SetList(list
, separator
, typesep
);
101 void AutoComplete::Show(bool show
) {
107 void AutoComplete::Cancel() {
116 void AutoComplete::Move(int delta
) {
117 int count
= lb
->Length();
118 int current
= lb
->GetSelection();
120 if (current
>= count
)
127 void AutoComplete::Select(const char *word
) {
128 size_t lenWord
= strlen(word
);
130 const int maxItemLen
=1000;
131 char item
[maxItemLen
];
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 lb
->GetValue(pivot
, item
, maxItemLen
);
139 cond
= CompareNCaseInsensitive(word
, item
, lenWord
);
141 cond
= strncmp(word
, item
, lenWord
);
144 while (pivot
> start
) {
145 lb
->GetValue(pivot
-1, item
, maxItemLen
);
147 cond
= CompareNCaseInsensitive(word
, item
, lenWord
);
149 cond
= strncmp(word
, item
, lenWord
);
156 // Check for exact-case match
157 for (; pivot
<= end
; pivot
++) {
158 lb
->GetValue(pivot
, item
, maxItemLen
);
159 if (!strncmp(word
, item
, lenWord
)) {
163 if (CompareNCaseInsensitive(word
, item
, lenWord
))
167 } else if (cond
< 0) {
169 } else if (cond
> 0) {
173 if (location
== -1 && autoHide
)
176 lb
->Select(location
);