2 * Copyright 2002-2006, project beam (http://sourceforge.net/projects/beam).
3 * All rights reserved. Distributed under the terms of the MIT License.
6 * Oliver Tappe <beam@hirschkaefer.de>
9 #include "AutoCompleter.h"
14 #include "AutoCompleterDefaultImpl.h"
17 // #pragma mark - DefaultPatternSelector
20 class DefaultPatternSelector
: public BAutoCompleter::PatternSelector
{
22 virtual void SelectPatternBounds(const BString
& text
, int32 caretPos
,
23 int32
* start
, int32
* length
);
28 DefaultPatternSelector::SelectPatternBounds(const BString
& text
,
29 int32 caretPos
, int32
* start
, int32
* length
)
31 if (!start
|| !length
)
34 *length
= text
.Length();
38 // #pragma mark - CompletionStyle
41 BAutoCompleter::CompletionStyle::CompletionStyle(EditView
* editView
,
42 ChoiceModel
* choiceModel
, ChoiceView
* choiceView
,
43 PatternSelector
* patternSelector
)
46 fPatternSelector(patternSelector
? patternSelector
47 : new DefaultPatternSelector()),
48 fChoiceModel(choiceModel
),
49 fChoiceView(choiceView
)
54 BAutoCompleter::CompletionStyle::~CompletionStyle()
59 delete fPatternSelector
;
64 BAutoCompleter::CompletionStyle::SetEditView(EditView
* view
)
72 BAutoCompleter::CompletionStyle::SetPatternSelector(
73 PatternSelector
* selector
)
75 delete fPatternSelector
;
76 fPatternSelector
= selector
;
81 BAutoCompleter::CompletionStyle::SetChoiceModel(ChoiceModel
* model
)
89 BAutoCompleter::CompletionStyle::SetChoiceView(ChoiceView
* view
)
96 // #pragma mark - BAutoCompleter
99 BAutoCompleter::BAutoCompleter(CompletionStyle
* completionStyle
)
101 fCompletionStyle(completionStyle
)
106 BAutoCompleter::BAutoCompleter(EditView
* editView
, ChoiceModel
* choiceModel
,
107 ChoiceView
* choiceView
, PatternSelector
* patternSelector
)
109 fCompletionStyle(new BDefaultCompletionStyle(editView
, choiceModel
,
110 choiceView
, patternSelector
))
115 BAutoCompleter::~BAutoCompleter()
117 delete fCompletionStyle
;
122 BAutoCompleter::Select(int32 index
)
124 if (fCompletionStyle
)
125 return fCompletionStyle
->Select(index
);
132 BAutoCompleter::SelectNext(bool wrap
)
134 if (fCompletionStyle
)
135 return fCompletionStyle
->SelectNext(wrap
);
142 BAutoCompleter::SelectPrevious(bool wrap
)
144 if (fCompletionStyle
)
145 return fCompletionStyle
->SelectPrevious(wrap
);
152 BAutoCompleter::IsChoiceSelected() const
154 if (fCompletionStyle
)
155 return fCompletionStyle
->IsChoiceSelected();
162 BAutoCompleter::CountChoices() const
164 if (fCompletionStyle
&& fCompletionStyle
->GetChoiceModel())
165 return fCompletionStyle
->GetChoiceModel()->CountChoices();
172 BAutoCompleter::CountVisibleChoices() const
174 if (fCompletionStyle
&& fCompletionStyle
->GetChoiceView())
175 return fCompletionStyle
->GetChoiceView()->CountVisibleChoices();
182 BAutoCompleter::SelectedChoiceIndex() const
184 if (fCompletionStyle
)
185 return fCompletionStyle
->SelectedChoiceIndex();
192 BAutoCompleter::ApplyChoice(bool hideChoices
)
194 if (fCompletionStyle
)
195 fCompletionStyle
->ApplyChoice(hideChoices
);
200 BAutoCompleter::CancelChoice()
202 if (fCompletionStyle
)
203 fCompletionStyle
->CancelChoice();
208 BAutoCompleter::EditViewStateChanged(bool updateChoices
)
210 if (fCompletionStyle
)
211 fCompletionStyle
->EditViewStateChanged(updateChoices
);
216 BAutoCompleter::SetEditView(EditView
* view
)
218 if (fCompletionStyle
)
219 fCompletionStyle
->SetEditView(view
);
224 BAutoCompleter::SetPatternSelector(PatternSelector
* selector
)
226 if (fCompletionStyle
)
227 fCompletionStyle
->SetPatternSelector(selector
);
232 BAutoCompleter::SetChoiceModel(ChoiceModel
* model
)
234 if (fCompletionStyle
)
235 fCompletionStyle
->SetChoiceModel(model
);
240 BAutoCompleter::SetChoiceView(ChoiceView
* view
)
242 if (fCompletionStyle
)
243 fCompletionStyle
->SetChoiceView(view
);
248 BAutoCompleter::SetCompletionStyle(CompletionStyle
* style
)
250 delete fCompletionStyle
;
251 fCompletionStyle
= style
;