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"
17 #include "Scintilla.h"
20 using namespace Scintilla
;
23 AutoComplete::AutoComplete() :
32 cancelAtStartPos(true),
34 dropRestOfWord(false),
35 ignoreCaseBehaviour(SC_CASEINSENSITIVEBEHAVIOUR_RESPECTCASE
) {
36 lb
= ListBox::Allocate();
38 fillUpChars
[0] = '\0';
41 AutoComplete::~AutoComplete() {
49 bool AutoComplete::Active() const {
53 void AutoComplete::Start(Window
&parent
, int ctrlID
,
54 int position
, Point location
, int startLen_
,
55 int lineHeight
, bool unicodeMode
, int technology
) {
59 lb
->Create(parent
, ctrlID
, location
, lineHeight
, unicodeMode
, technology
);
66 void AutoComplete::SetStopChars(const char *stopChars_
) {
67 strncpy(stopChars
, stopChars_
, sizeof(stopChars
));
68 stopChars
[sizeof(stopChars
) - 1] = '\0';
71 bool AutoComplete::IsStopChar(char ch
) {
72 return ch
&& strchr(stopChars
, ch
);
75 void AutoComplete::SetFillUpChars(const char *fillUpChars_
) {
76 strncpy(fillUpChars
, fillUpChars_
, sizeof(fillUpChars
));
77 fillUpChars
[sizeof(fillUpChars
) - 1] = '\0';
80 bool AutoComplete::IsFillUpChar(char ch
) {
81 return ch
&& strchr(fillUpChars
, ch
);
84 void AutoComplete::SetSeparator(char separator_
) {
85 separator
= separator_
;
88 char AutoComplete::GetSeparator() const {
92 void AutoComplete::SetTypesep(char separator_
) {
96 char AutoComplete::GetTypesep() const {
100 void AutoComplete::SetList(const char *list
) {
101 lb
->SetList(list
, separator
, typesep
);
104 void AutoComplete::Show(bool show
) {
110 void AutoComplete::Cancel() {
119 void AutoComplete::Move(int delta
) {
120 int count
= lb
->Length();
121 int current
= lb
->GetSelection();
123 if (current
>= count
)
130 void AutoComplete::Select(const char *word
) {
131 size_t lenWord
= strlen(word
);
133 const int maxItemLen
=1000;
134 int start
= 0; // lower bound of the api array block to search
135 int end
= lb
->Length() - 1; // upper bound of the api array block to search
136 while ((start
<= end
) && (location
== -1)) { // Binary searching loop
137 int pivot
= (start
+ end
) / 2;
138 char item
[maxItemLen
];
139 lb
->GetValue(pivot
, item
, maxItemLen
);
142 cond
= CompareNCaseInsensitive(word
, item
, lenWord
);
144 cond
= strncmp(word
, item
, lenWord
);
147 while (pivot
> start
) {
148 lb
->GetValue(pivot
-1, item
, maxItemLen
);
150 cond
= CompareNCaseInsensitive(word
, item
, lenWord
);
152 cond
= strncmp(word
, item
, lenWord
);
159 && ignoreCaseBehaviour
== SC_CASEINSENSITIVEBEHAVIOUR_RESPECTCASE
) {
160 // Check for exact-case match
161 for (; pivot
<= end
; pivot
++) {
162 lb
->GetValue(pivot
, item
, maxItemLen
);
163 if (!strncmp(word
, item
, lenWord
)) {
167 if (CompareNCaseInsensitive(word
, item
, lenWord
))
171 } else if (cond
< 0) {
173 } else if (cond
> 0) {
177 if (location
== -1 && autoHide
)
180 lb
->Select(location
);