1/*
2 * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT license.
4 */
5#ifndef HYPER_TEXT_VIEW_H
6#define HYPER_TEXT_VIEW_H
7
8#include <TextView.h>
9
10
11// TODO: The current implementation works correctly only for insertions at the
12// end of the text. It doesn't keep track of any other insertions or deletions.
13
14
15class HyperTextView;
16
17
18class HyperTextAction {
19public:
20								HyperTextAction();
21	virtual						~HyperTextAction();
22
23	virtual	void				MouseOver(HyperTextView* view, BPoint where,
24									int32 startOffset, int32 endOffset,
25									BMessage* message);
26	virtual	void				MouseAway(HyperTextView* view, BPoint where,
27									int32 startOffset, int32 endOffset,
28									BMessage* message);
29	virtual	void				Clicked(HyperTextView* view, BPoint where,
30									BMessage* message);
31};
32
33
34class HyperTextView : public BTextView {
35public:
36								HyperTextView(const char* name,
37									uint32 flags = B_WILL_DRAW
38										| B_PULSE_NEEDED);
39								HyperTextView(BRect frame, const char* name,
40									BRect textRect, uint32 resizeMask,
41									uint32 flags = B_WILL_DRAW
42										| B_PULSE_NEEDED);
43	virtual						~HyperTextView();
44
45	virtual	void				MouseDown(BPoint where);
46	virtual	void				MouseUp(BPoint where);
47	virtual	void				MouseMoved(BPoint where, uint32 transit,
48									const BMessage* dragMessage);
49
50			void				AddHyperTextAction(int32 startOffset,
51									int32 endOffset, HyperTextAction* action);
52
53			void				InsertHyperText(const char* inText,
54									HyperTextAction* action,
55									const text_run_array* inRuns = NULL);
56			void				InsertHyperText(const char* inText,
57									int32 inLength, HyperTextAction* action,
58									const text_run_array* inRuns = NULL);
59private:
60			struct ActionInfo;
61			class ActionInfoList;
62
63			HyperTextAction*	_ActionAt(const BPoint& where) const;
64			const ActionInfo*	_ActionInfoAt(const BPoint& where) const;
65
66private:
67			ActionInfoList*		fActionInfos;
68			const ActionInfo*	fLastActionInfo;
69};
70
71
72#endif	// HYPER_TEXT_VIEW_H
73