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>
8 #ifndef _AUTO_COMPLETER_H
9 #define _AUTO_COMPLETER_H
11 #include <MessageFilter.h>
16 class BAutoCompleter
{
20 Choice(const BString
& choiceText
,
21 const BString
& displayText
, int32 matchPos
,
25 fDisplayText(displayText
),
31 const BString
& Text() const { return fText
; }
32 const BString
& DisplayText() const { return fDisplayText
; }
33 int32
MatchPos() const { return fMatchPos
; }
34 int32
MatchLen() const { return fMatchLen
; }
45 virtual ~EditView() {}
47 virtual BRect
GetAdjustmentFrame() = 0;
48 virtual void GetEditViewState(BString
& text
,
50 virtual void SetEditViewState(const BString
& text
,
52 int32 selectionLength
= 0) = 0;
55 class PatternSelector
{
57 virtual ~PatternSelector() {}
59 virtual void SelectPatternBounds(const BString
& text
,
60 int32 caretPos
, int32
* start
,
67 virtual ~ChoiceModel() {}
69 virtual void FetchChoicesFor(const BString
& pattern
) = 0;
71 virtual int32
CountChoices() const = 0;
72 virtual const Choice
* ChoiceAt(int32 index
) const = 0;
75 class CompletionStyle
;
78 virtual ~ChoiceView() {}
80 virtual void SelectChoiceAt(int32 index
) = 0;
81 virtual void ShowChoices(
82 BAutoCompleter::CompletionStyle
* completer
)
84 virtual void HideChoices() = 0;
85 virtual bool ChoicesAreShown() = 0;
86 virtual int32
CountVisibleChoices() const = 0;
89 class CompletionStyle
{
91 CompletionStyle(EditView
* editView
,
92 ChoiceModel
* choiceModel
,
93 ChoiceView
* choiceView
,
94 PatternSelector
* patternSelector
);
95 virtual ~CompletionStyle();
97 virtual bool Select(int32 index
) = 0;
98 virtual bool SelectNext(bool wrap
= false) = 0;
99 virtual bool SelectPrevious(bool wrap
= false) = 0;
100 virtual bool IsChoiceSelected() const = 0;
101 virtual int32
SelectedChoiceIndex() const = 0;
103 virtual void ApplyChoice(bool hideChoices
= true) = 0;
104 virtual void CancelChoice() = 0;
106 virtual void EditViewStateChanged(bool updateChoices
) = 0;
108 void SetEditView(EditView
* view
);
109 void SetPatternSelector(PatternSelector
* selector
);
110 void SetChoiceModel(ChoiceModel
* model
);
111 void SetChoiceView(ChoiceView
* view
);
113 EditView
* GetEditView() { return fEditView
; }
114 PatternSelector
* GetPatternSelector()
115 { return fPatternSelector
; }
116 ChoiceModel
* GetChoiceModel() { return fChoiceModel
; }
117 ChoiceView
* GetChoiceView() { return fChoiceView
; }
121 PatternSelector
* fPatternSelector
;
122 ChoiceModel
* fChoiceModel
;
123 ChoiceView
* fChoiceView
;
128 CompletionStyle
* completionStyle
= NULL
);
129 BAutoCompleter(EditView
* editView
,
130 ChoiceModel
* choiceModel
,
131 ChoiceView
* choiceView
,
132 PatternSelector
* patternSelector
);
133 virtual ~BAutoCompleter();
135 void EditViewStateChanged(
136 bool updateChoices
= true);
138 bool Select(int32 index
);
139 bool SelectNext(bool wrap
= false);
140 bool SelectPrevious(bool wrap
= false);
141 bool IsChoiceSelected() const;
142 int32
CountChoices() const;
143 int32
CountVisibleChoices() const;
144 int32
SelectedChoiceIndex() const;
146 void ApplyChoice(bool hideChoices
= true);
149 void SetEditView(EditView
* view
);
150 void SetPatternSelector(PatternSelector
* selector
);
151 void SetChoiceModel(ChoiceModel
* model
);
152 void SetChoiceView(ChoiceView
* view
);
154 void SetCompletionStyle(CompletionStyle
* style
);
157 CompletionStyle
* fCompletionStyle
;
161 #endif // _AUTO_COMPLETER_H