repository_infos: Enable automatic updates on the main Haiku repostiory.
[haiku.git] / src / apps / webpositive / autocompletion / AutoCompleter.h
blobdab8268db26dc54123e06190862b13415d608a09
1 /*
2 * Copyright 2002-2006, project beam (http://sourceforge.net/projects/beam).
3 * All rights reserved. Distributed under the terms of the MIT License.
5 * Authors:
6 * Oliver Tappe <beam@hirschkaefer.de>
7 */
8 #ifndef _AUTO_COMPLETER_H
9 #define _AUTO_COMPLETER_H
11 #include <MessageFilter.h>
13 #include <Rect.h>
14 #include <String.h>
16 class BAutoCompleter {
17 public:
18 class Choice {
19 public:
20 Choice(const BString& choiceText,
21 const BString& displayText, int32 matchPos,
22 int32 matchLen)
24 fText(choiceText),
25 fDisplayText(displayText),
26 fMatchPos(matchPos),
27 fMatchLen(matchLen)
30 virtual ~Choice() {}
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; }
36 private:
37 BString fText;
38 BString fDisplayText;
39 int32 fMatchPos;
40 int32 fMatchLen;
43 class EditView {
44 public:
45 virtual ~EditView() {}
47 virtual BRect GetAdjustmentFrame() = 0;
48 virtual void GetEditViewState(BString& text,
49 int32* caretPos) = 0;
50 virtual void SetEditViewState(const BString& text,
51 int32 caretPos,
52 int32 selectionLength = 0) = 0;
55 class PatternSelector {
56 public:
57 virtual ~PatternSelector() {}
59 virtual void SelectPatternBounds(const BString& text,
60 int32 caretPos, int32* start,
61 int32* length) = 0;
64 class ChoiceModel {
65 public:
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;
76 class ChoiceView {
77 public:
78 virtual ~ChoiceView() {}
80 virtual void SelectChoiceAt(int32 index) = 0;
81 virtual void ShowChoices(
82 BAutoCompleter::CompletionStyle* completer)
83 = 0;
84 virtual void HideChoices() = 0;
85 virtual bool ChoicesAreShown() = 0;
86 virtual int32 CountVisibleChoices() const = 0;
89 class CompletionStyle {
90 public:
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; }
119 protected:
120 EditView* fEditView;
121 PatternSelector* fPatternSelector;
122 ChoiceModel* fChoiceModel;
123 ChoiceView* fChoiceView;
126 protected:
127 BAutoCompleter(
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);
147 void CancelChoice();
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);
156 private:
157 CompletionStyle* fCompletionStyle;
161 #endif // _AUTO_COMPLETER_H