]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/AutoComplete.cxx
7f7412e43fa9f10d37910ff87248d6ff616a2267
1 // Scintilla source code edit control
2 /** @file AutoComplete.cxx
3 ** Defines the auto completion list box.
5 // Copyright 1998-2001 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() :
24 cancelAtStartPos(true),
27 fillUpChars
[0] = '\0';
30 AutoComplete::~AutoComplete() {
34 bool AutoComplete::Active() {
38 void AutoComplete::Start(Window
&parent
, int ctrlID
, int position
, int startLen_
) {
40 lb
.Create(parent
, ctrlID
);
48 void AutoComplete::SetStopChars(const char *stopChars_
) {
49 strncpy(stopChars
, stopChars_
, sizeof(stopChars
));
50 stopChars
[sizeof(stopChars
) - 1] = '\0';
53 bool AutoComplete::IsStopChar(char ch
) {
54 return ch
&& strchr(stopChars
, ch
);
57 void AutoComplete::SetFillUpChars(const char *fillUpChars_
) {
58 strncpy(fillUpChars
, fillUpChars_
, sizeof(fillUpChars
));
59 fillUpChars
[sizeof(fillUpChars
) - 1] = '\0';
62 bool AutoComplete::IsFillUpChar(char ch
) {
63 return ch
&& strchr(fillUpChars
, ch
);
66 void AutoComplete::SetSeparator(char separator_
) {
67 separator
= separator_
;
70 char AutoComplete::GetSeparator() {
74 void AutoComplete::SetList(const char *list
) {
76 char *words
= new char[strlen(list
) + 1];
79 char *startword
= words
;
81 for (; words
&& words
[i
]; i
++) {
82 if (words
[i
] == separator
) {
85 startword
= words
+ i
+ 1;
95 void AutoComplete::Show() {
100 void AutoComplete::Cancel() {
108 void AutoComplete::Move(int delta
) {
109 int count
= lb
.Length();
110 int current
= lb
.GetSelection();
112 if (current
>= count
)
119 void AutoComplete::Select(const char *word
) {
120 int lenWord
= strlen(word
);
122 const int maxItemLen
=1000;
123 char item
[maxItemLen
];
124 int start
= 0; // lower bound of the api array block to search
125 int end
= lb
.Length() - 1; // upper bound of the api array block to search
126 while ((start
<= end
) && (location
== -1)) { // Binary searching loop
127 int pivot
= (start
+ end
) / 2;
128 lb
.GetValue(pivot
, item
, maxItemLen
);
131 cond
= CompareNCaseInsensitive(word
, item
, lenWord
);
133 cond
= strncmp(word
, item
, lenWord
);
136 while (pivot
> start
) {
137 lb
.GetValue(pivot
-1, item
, maxItemLen
);
139 cond
= CompareNCaseInsensitive(word
, item
, lenWord
);
141 cond
= strncmp(word
, item
, lenWord
);
147 } else if (cond
< 0) {
149 } else if (cond
> 0) {
153 if (location
== -1 && autoHide
)