]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/scintilla/src/AutoComplete.cxx
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 "AutoComplete.h"
17 AutoComplete::AutoComplete() :
26 cancelAtStartPos(true),
28 dropRestOfWord(false) {
29 lb
= ListBox::Allocate();
31 fillUpChars
[0] = '\0';
34 AutoComplete::~AutoComplete() {
42 bool AutoComplete::Active() {
46 void AutoComplete::Start(Window
&parent
, int ctrlID
,
47 int position
, Point location
, int startLen_
,
48 int lineHeight
, bool unicodeMode
) {
52 lb
->Create(parent
, ctrlID
, location
, lineHeight
, unicodeMode
);
59 void AutoComplete::SetStopChars(const char *stopChars_
) {
60 strncpy(stopChars
, stopChars_
, sizeof(stopChars
));
61 stopChars
[sizeof(stopChars
) - 1] = '\0';
64 bool AutoComplete::IsStopChar(char ch
) {
65 return ch
&& strchr(stopChars
, ch
);
68 void AutoComplete::SetFillUpChars(const char *fillUpChars_
) {
69 strncpy(fillUpChars
, fillUpChars_
, sizeof(fillUpChars
));
70 fillUpChars
[sizeof(fillUpChars
) - 1] = '\0';
73 bool AutoComplete::IsFillUpChar(char ch
) {
74 return ch
&& strchr(fillUpChars
, ch
);
77 void AutoComplete::SetSeparator(char separator_
) {
78 separator
= separator_
;
81 char AutoComplete::GetSeparator() {
85 void AutoComplete::SetTypesep(char separator_
) {
89 char AutoComplete::GetTypesep() {
93 void AutoComplete::SetList(const char *list
) {
94 lb
->SetList(list
, separator
, typesep
);
97 void AutoComplete::Show(bool show
) {
103 void AutoComplete::Cancel() {
112 void AutoComplete::Move(int delta
) {
113 int count
= lb
->Length();
114 int current
= lb
->GetSelection();
116 if (current
>= count
)
123 void AutoComplete::Select(const char *word
) {
124 size_t lenWord
= strlen(word
);
126 const int maxItemLen
=1000;
127 char item
[maxItemLen
];
128 int start
= 0; // lower bound of the api array block to search
129 int end
= lb
->Length() - 1; // upper bound of the api array block to search
130 while ((start
<= end
) && (location
== -1)) { // Binary searching loop
131 int pivot
= (start
+ end
) / 2;
132 lb
->GetValue(pivot
, item
, maxItemLen
);
135 cond
= CompareNCaseInsensitive(word
, item
, lenWord
);
137 cond
= strncmp(word
, item
, lenWord
);
140 while (pivot
> start
) {
141 lb
->GetValue(pivot
-1, item
, maxItemLen
);
143 cond
= CompareNCaseInsensitive(word
, item
, lenWord
);
145 cond
= strncmp(word
, item
, lenWord
);
152 // Check for exact-case match
153 for (; pivot
<= end
; pivot
++) {
154 lb
->GetValue(pivot
, item
, maxItemLen
);
155 if (!strncmp(word
, item
, lenWord
)) {
159 if (CompareNCaseInsensitive(word
, item
, lenWord
))
163 } else if (cond
< 0) {
165 } else if (cond
> 0) {
169 if (location
== -1 && autoHide
)
172 lb
->Select(location
);