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
),
39 heightLBDefault(100) {
40 lb
= ListBox::Allocate();
42 fillUpChars
[0] = '\0';
45 AutoComplete::~AutoComplete() {
53 bool AutoComplete::Active() const {
57 void AutoComplete::Start(Window
&parent
, int ctrlID
,
58 int position
, Point location
, int startLen_
,
59 int lineHeight
, bool unicodeMode
, int technology
) {
63 lb
->Create(parent
, ctrlID
, location
, lineHeight
, unicodeMode
, technology
);
70 void AutoComplete::SetStopChars(const char *stopChars_
) {
71 strncpy(stopChars
, stopChars_
, sizeof(stopChars
));
72 stopChars
[sizeof(stopChars
) - 1] = '\0';
75 bool AutoComplete::IsStopChar(char ch
) {
76 return ch
&& strchr(stopChars
, ch
);
79 void AutoComplete::SetFillUpChars(const char *fillUpChars_
) {
80 strncpy(fillUpChars
, fillUpChars_
, sizeof(fillUpChars
));
81 fillUpChars
[sizeof(fillUpChars
) - 1] = '\0';
84 bool AutoComplete::IsFillUpChar(char ch
) {
85 return ch
&& strchr(fillUpChars
, ch
);
88 void AutoComplete::SetSeparator(char separator_
) {
89 separator
= separator_
;
92 char AutoComplete::GetSeparator() const {
96 void AutoComplete::SetTypesep(char separator_
) {
100 char AutoComplete::GetTypesep() const {
104 void AutoComplete::SetList(const char *list
) {
105 lb
->SetList(list
, separator
, typesep
);
108 int AutoComplete::GetSelection() const {
109 return lb
->GetSelection();
112 std::string
AutoComplete::GetValue(int item
) const {
113 char value
[maxItemLen
];
114 lb
->GetValue(item
, value
, sizeof(value
));
115 return std::string(value
);
118 void AutoComplete::Show(bool show
) {
124 void AutoComplete::Cancel() {
133 void AutoComplete::Move(int delta
) {
134 int count
= lb
->Length();
135 int current
= lb
->GetSelection();
137 if (current
>= count
)
144 void AutoComplete::Select(const char *word
) {
145 size_t lenWord
= strlen(word
);
147 int start
= 0; // lower bound of the api array block to search
148 int end
= lb
->Length() - 1; // upper bound of the api array block to search
149 while ((start
<= end
) && (location
== -1)) { // Binary searching loop
150 int pivot
= (start
+ end
) / 2;
151 char item
[maxItemLen
];
152 lb
->GetValue(pivot
, item
, maxItemLen
);
155 cond
= CompareNCaseInsensitive(word
, item
, lenWord
);
157 cond
= strncmp(word
, item
, lenWord
);
160 while (pivot
> start
) {
161 lb
->GetValue(pivot
-1, item
, maxItemLen
);
163 cond
= CompareNCaseInsensitive(word
, item
, lenWord
);
165 cond
= strncmp(word
, item
, lenWord
);
172 && ignoreCaseBehaviour
== SC_CASEINSENSITIVEBEHAVIOUR_RESPECTCASE
) {
173 // Check for exact-case match
174 for (; pivot
<= end
; pivot
++) {
175 lb
->GetValue(pivot
, item
, maxItemLen
);
176 if (!strncmp(word
, item
, lenWord
)) {
180 if (CompareNCaseInsensitive(word
, item
, lenWord
))
184 } else if (cond
< 0) {
186 } else if (cond
> 0) {
190 if (location
== -1 && autoHide
)
193 lb
->Select(location
);