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.
17 #include "CharacterSet.h"
18 #include "AutoComplete.h"
19 #include "Scintilla.h"
22 using namespace Scintilla
;
25 AutoComplete::AutoComplete() :
34 cancelAtStartPos(true),
36 dropRestOfWord(false),
37 ignoreCaseBehaviour(SC_CASEINSENSITIVEBEHAVIOUR_RESPECTCASE
) {
38 lb
= ListBox::Allocate();
40 fillUpChars
[0] = '\0';
43 AutoComplete::~AutoComplete() {
51 bool AutoComplete::Active() const {
55 void AutoComplete::Start(Window
&parent
, int ctrlID
,
56 int position
, Point location
, int startLen_
,
57 int lineHeight
, bool unicodeMode
, int technology
) {
61 lb
->Create(parent
, ctrlID
, location
, lineHeight
, unicodeMode
, technology
);
68 void AutoComplete::SetStopChars(const char *stopChars_
) {
69 strncpy(stopChars
, stopChars_
, sizeof(stopChars
));
70 stopChars
[sizeof(stopChars
) - 1] = '\0';
73 bool AutoComplete::IsStopChar(char ch
) {
74 return ch
&& strchr(stopChars
, ch
);
77 void AutoComplete::SetFillUpChars(const char *fillUpChars_
) {
78 strncpy(fillUpChars
, fillUpChars_
, sizeof(fillUpChars
));
79 fillUpChars
[sizeof(fillUpChars
) - 1] = '\0';
82 bool AutoComplete::IsFillUpChar(char ch
) {
83 return ch
&& strchr(fillUpChars
, ch
);
86 void AutoComplete::SetSeparator(char separator_
) {
87 separator
= separator_
;
90 char AutoComplete::GetSeparator() const {
94 void AutoComplete::SetTypesep(char separator_
) {
98 char AutoComplete::GetTypesep() const {
102 void AutoComplete::SetList(const char *list
) {
103 lb
->SetList(list
, separator
, typesep
);
106 int AutoComplete::GetSelection() const {
107 return lb
->GetSelection();
110 std::string
AutoComplete::GetValue(int item
) const {
111 char value
[maxItemLen
];
112 lb
->GetValue(item
, value
, sizeof(value
));
113 return std::string(value
);
116 void AutoComplete::Show(bool show
) {
122 void AutoComplete::Cancel() {
131 void AutoComplete::Move(int delta
) {
132 int count
= lb
->Length();
133 int current
= lb
->GetSelection();
135 if (current
>= count
)
142 void AutoComplete::Select(const char *word
) {
143 size_t lenWord
= strlen(word
);
145 int start
= 0; // lower bound of the api array block to search
146 int end
= lb
->Length() - 1; // upper bound of the api array block to search
147 while ((start
<= end
) && (location
== -1)) { // Binary searching loop
148 int pivot
= (start
+ end
) / 2;
149 char item
[maxItemLen
];
150 lb
->GetValue(pivot
, item
, maxItemLen
);
153 cond
= CompareNCaseInsensitive(word
, item
, lenWord
);
155 cond
= strncmp(word
, item
, lenWord
);
158 while (pivot
> start
) {
159 lb
->GetValue(pivot
-1, item
, maxItemLen
);
161 cond
= CompareNCaseInsensitive(word
, item
, lenWord
);
163 cond
= strncmp(word
, item
, lenWord
);
170 && ignoreCaseBehaviour
== SC_CASEINSENSITIVEBEHAVIOUR_RESPECTCASE
) {
171 // Check for exact-case match
172 for (; pivot
<= end
; pivot
++) {
173 lb
->GetValue(pivot
, item
, maxItemLen
);
174 if (!strncmp(word
, item
, lenWord
)) {
178 if (CompareNCaseInsensitive(word
, item
, lenWord
))
182 } else if (cond
< 0) {
184 } else if (cond
> 0) {
188 if (location
== -1 && autoHide
)
191 lb
->Select(location
);