1/*
2 * Copyright 2002-2006, project beam (http://sourceforge.net/projects/beam).
3 * All rights reserved. Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Oliver Tappe <beam@hirschkaefer.de>
7 */
8#ifndef _AUTO_COMPLETER_DEFAULT_IMPL_H
9#define _AUTO_COMPLETER_DEFAULT_IMPL_H
10
11#include <ListView.h>
12#include <String.h>
13
14#include "AutoCompleter.h"
15
16class BDefaultPatternSelector : public BAutoCompleter::PatternSelector {
17public:
18	virtual	void				SelectPatternBounds(const BString& text,
19									int32 caretPos, int32* start,
20									int32* length);
21};
22
23
24class BDefaultCompletionStyle : public BAutoCompleter::CompletionStyle {
25public:
26								BDefaultCompletionStyle(
27									BAutoCompleter::EditView* editView,
28									BAutoCompleter::ChoiceModel* choiceModel,
29									BAutoCompleter::ChoiceView* choiceView,
30									BAutoCompleter::PatternSelector*
31										patternSelector);
32	virtual						~BDefaultCompletionStyle();
33
34	virtual	bool				Select(int32 index);
35	virtual	bool				SelectNext(bool wrap = false);
36	virtual	bool				SelectPrevious(bool wrap = false);
37	virtual	bool				IsChoiceSelected() const;
38	virtual	int32				SelectedChoiceIndex() const;
39
40	virtual	void				ApplyChoice(bool hideChoices = true);
41	virtual	void				CancelChoice();
42
43	virtual	void				EditViewStateChanged(bool updateChoices);
44
45private:
46			BString				fFullEnteredText;
47			int32				fSelectedIndex;
48			int32				fPatternStartPos;
49			int32				fPatternLength;
50			bool				fIgnoreEditViewStateChanges;
51};
52
53
54class BDefaultChoiceView : public BAutoCompleter::ChoiceView {
55protected:
56	class ListView : public BListView {
57	public:
58								ListView(
59									BAutoCompleter::CompletionStyle* completer);
60		virtual	void			SelectionChanged();
61		virtual	void			MessageReceived(BMessage* msg);
62		virtual	void			MouseDown(BPoint point);
63		virtual	void			AttachedToWindow();
64
65	private:
66				BAutoCompleter::CompletionStyle* fCompleter;
67	};
68
69	class ListItem : public BListItem {
70	public:
71								ListItem(const BAutoCompleter::Choice* choice);
72		virtual	void			DrawItem(BView* owner, BRect frame,
73									bool complete = false);
74	private:
75				BString			fPreText;
76				BString			fMatchText;
77				BString			fPostText;
78	};
79
80public:
81								BDefaultChoiceView();
82	virtual						~BDefaultChoiceView();
83
84	virtual	void				SelectChoiceAt(int32 index);
85	virtual	void				ShowChoices(
86									BAutoCompleter::CompletionStyle* completer);
87	virtual	void				HideChoices();
88	virtual	bool				ChoicesAreShown();
89	virtual int32				CountVisibleChoices() const;
90
91				void			SetMaxVisibleChoices(int32 choices);
92				int32			MaxVisibleChoices() const;
93
94private:
95			BWindow*			fWindow;
96			ListView*			fListView;
97			int32				fMaxVisibleChoices;
98};
99
100#endif // _AUTO_COMPLETER_DEFAULT_IMPL_H
101