xref: /haiku/src/apps/terminal/TermViewStates.h (revision 9e25244c5e9051f6cd333820d6332397361abd6c)
1 /*
2  * Copyright 2001-2013, Haiku, Inc.
3  * Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net>
4  * Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
5  *
6  * Distributed under the terms of the MIT license.
7  * Authors:
8  *		Stefano Ceccherini, stefano.ceccherini@gmail.com
9  *		Kian Duffy, myob@users.sourceforge.net
10  *		Ingo Weinhold, ingo_weinhold@gmx.de
11  *		Siarzhuk Zharski, zharik@gmx.li
12  */
13 #ifndef TERMVIEW_STATES_H
14 #define TERMVIEW_STATES_H
15 
16 
17 #include "HyperLink.h"
18 #include "TerminalCharClassifier.h"
19 #include "TermView.h"
20 
21 
22 class TermView::State {
23 public:
24 								State(TermView* view);
25 	virtual						~State();
26 
27 	virtual	void				Entered();
28 	virtual	void				Exited();
29 
30 	virtual	bool				MessageReceived(BMessage* message);
31 									// returns true, if handled
32 
33 	virtual	void				ModifiersChanged(int32 oldModifiers,
34 									int32 modifiers);
35 	virtual void				KeyDown(const char* bytes, int32 numBytes);
36 
37 	virtual void				MouseDown(BPoint where, int32 buttons,
38 									int32 modifiers);
39 	virtual void				MouseMoved(BPoint where, uint32 transit,
40 									const BMessage* dragMessage, int32 modifiers);
41 	virtual void				MouseUp(BPoint where, int32 buttons);
42 
43 	virtual	void				WindowActivated(bool active);
44 
45 	virtual	void				VisibleTextBufferChanged();
46 
47 protected:
48 			TermView*			fView;
49 };
50 
51 
52 class TermView::StandardBaseState : public TermView::State {
53 public:
54 								StandardBaseState(TermView* view);
55 
56 protected:
57 			bool				_StandardMouseMoved(BPoint where,
58 									int32 modifiers);
59 };
60 
61 
62 class TermView::DefaultState : public TermView::StandardBaseState {
63 public:
64 								DefaultState(TermView* view);
65 
66 	virtual	void				ModifiersChanged(int32 oldModifiers,
67 									int32 modifiers);
68 
69 	virtual void				KeyDown(const char* bytes, int32 numBytes);
70 
71 	virtual void				MouseDown(BPoint where, int32 buttons,
72 									int32 modifiers);
73 	virtual void				MouseMoved(BPoint where, uint32 transit,
74 									const BMessage* dragMessage, int32 modifiers);
75 	virtual void				MouseUp(BPoint where, int32 buttons);
76 
77 	virtual	void				WindowActivated(bool active);
78 
79 private:
80 			bool				_CheckEnterHyperLinkState(int32 modifiers);
81 };
82 
83 
84 class TermView::SelectState : public TermView::StandardBaseState {
85 public:
86 								SelectState(TermView* view);
87 
88 			void				Prepare(BPoint where, int32 modifiers);
89 
90 	virtual	bool				MessageReceived(BMessage* message);
91 
92 	virtual void				MouseMoved(BPoint where, uint32 transit,
93 									const BMessage* dragMessage, int32 modifiers);
94 	virtual void				MouseUp(BPoint where, int32 buttons);
95 
96 private:
97 			void				_AutoScrollUpdate();
98 
99 private:
100 			int32				fSelectGranularity;
101 			bool				fCheckMouseTracking;
102 			bool				fMouseTracking;
103 };
104 
105 
106 class TermView::HyperLinkState : public TermView::State,
107 	private TermViewHighlighter {
108 public:
109 								HyperLinkState(TermView* view);
110 
111 	virtual	void				Entered();
112 	virtual	void				Exited();
113 
114 	virtual	void				ModifiersChanged(int32 oldModifiers,
115 									int32 modifiers);
116 
117 	virtual void				MouseDown(BPoint where, int32 buttons,
118 									int32 modifiers);
119 	virtual void				MouseMoved(BPoint where, uint32 transit,
120 									const BMessage* dragMessage, int32 modifiers);
121 
122 	virtual	void				WindowActivated(bool active);
123 
124 	virtual	void				VisibleTextBufferChanged();
125 
126 private:
127 	// TermViewHighlighter
128 	virtual	rgb_color			ForegroundColor();
129 	virtual	rgb_color			BackgroundColor();
130 	virtual	uint32				AdjustTextAttributes(uint32 attributes);
131 
132 private:
133 			struct CharPosition {
134 				int32	index;
135 				TermPos	position;
136 			};
137 
138 private:
139 			bool				_GetHyperLinkAt(BPoint where,
140 									bool pathPrefixOnly, HyperLink& _link,
141 									TermPos& _start, TermPos& _end);
142 			bool				_EntryExists(const BString& path,
143 									BString& _actualPath) const;
144 
145 			void				_UpdateHighlight();
146 			void				_UpdateHighlight(BPoint where, int32 modifiers);
147 			void				_ActivateHighlight(const TermPos& start,
148 									const TermPos& end);
149 			void				_DeactivateHighlight();
150 
151 private:
152 			DefaultCharClassifier fURLCharClassifier;
153 			DefaultCharClassifier fPathComponentCharClassifier;
154 			BString				fCurrentDirectory;
155 			TermViewHighlight	fHighlight;
156 			bool				fHighlightActive;
157 };
158 
159 
160 class TermView::HyperLinkMenuState : public TermView::State {
161 public:
162 								HyperLinkMenuState(TermView* view);
163 
164 			void				Prepare(BPoint point, const HyperLink& link);
165 
166 	virtual	void				Exited();
167 
168 	virtual	bool				MessageReceived(BMessage* message);
169 
170 private:
171 			class PopUpMenu;
172 
173 private:
174 			HyperLink			fLink;
175 };
176 
177 
178 #endif // TERMVIEW_STATES_H
179