xref: /haiku/src/apps/mail/Content.h (revision 8195a5a835117ab2da405e0d477153570b75d921)
1 /*
2 Open Tracker License
3 
4 Terms and Conditions
5 
6 Copyright (c) 1991-2001, Be Incorporated. All rights reserved.
7 
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
14 
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
28 
29 BeMail(TM), Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30 of Be Incorporated in the United States and other countries. Other brand product
31 names are registered trademarks or trademarks of their respective holders.
32 All rights reserved.
33 */
34 
35 //--------------------------------------------------------------------
36 //
37 //	Content.h
38 //
39 //--------------------------------------------------------------------
40 
41 #ifndef _CONTENT_H
42 #define _CONTENT_H
43 
44 #include <FilePanel.h>
45 #include <FindDirectory.h>
46 #include <Font.h>
47 #include <fs_attr.h>
48 #include <Point.h>
49 #include <Rect.h>
50 #include <MessageFilter.h>
51 
52 #include "KUndoBuffer.h"
53 
54 #define MESSAGE_TEXT		"Message:"
55 #define MESSAGE_TEXT_H		 16
56 #define MESSAGE_TEXT_V		 5
57 #define MESSAGE_FIELD_H		 59
58 #define MESSAGE_FIELD_V		 11
59 
60 #define CONTENT_TYPE		"content-type: "
61 #define CONTENT_ENCODING	"content-transfer-encoding: "
62 #define CONTENT_DISPOSITION	"Content-Disposition: "
63 #define MIME_TEXT			"text/"
64 #define MIME_MULTIPART		"multipart/"
65 
66 class TMailWindow;
67 class TScrollView;
68 class TTextView;
69 class BFile;
70 class BList;
71 class BPopupMenu;
72 
73 struct text_run_array;
74 
75 typedef struct
76 {
77 	bool header;
78 	bool raw;
79 	bool quote;
80 	bool incoming;
81 	bool close;
82 	bool mime;
83 	TTextView *view;
84 	BEmailMessage *mail;
85 	BList *enclosures;
86 	sem_id *stop_sem;
87 } reader_info;
88 
89 enum ENCLOSURE_TYPE
90 {
91 	TYPE_ENCLOSURE = 100,
92 	TYPE_BE_ENCLOSURE,
93 	TYPE_URL,
94 	TYPE_MAILTO
95 };
96 
97 struct hyper_text {
98 	int32 type;
99 	char *name;
100 	char *content_type;
101 	char *encoding;
102 	int32 text_start;
103 	int32 text_end;
104 	BMailComponent *component;
105 	bool saved;
106 	bool have_ref;
107 	entry_ref ref;
108 	node_ref node;
109 };
110 
111 class TSavePanel;
112 
113 
114 //====================================================================
115 
116 class TContentView : public BView
117 {
118 	public:
119 		TContentView(BRect, bool incoming, BEmailMessage *mail, BFont*,
120 			bool showHeader, bool coloredQuotes);
121 		virtual void MessageReceived(BMessage *);
122 		void FindString(const char *);
123 		void Focus(bool);
124 		void FrameResized(float, float);
125 
126 		TTextView *fTextView;
127 
128 	private:
129 		bool	fFocus;
130 		bool	fIncoming;
131 		float	fOffset;
132 };
133 
134 //====================================================================
135 
136 enum {
137 	S_CLEAR_ERRORS = 1,
138 	S_SHOW_ERRORS = 2
139 };
140 
141 class TTextView : public BTextView
142 {
143 	public:
144 		TTextView(BRect, BRect, bool incoming, BEmailMessage *mail,
145 			TContentView *, BFont *, bool showHeader, bool coloredQuotes);
146 		~TTextView();
147 
148 		virtual	void AttachedToWindow();
149 		virtual void KeyDown(const char*, int32);
150 		virtual void MakeFocus(bool);
151 		virtual void MessageReceived(BMessage*);
152 		virtual void MouseDown(BPoint);
153 		virtual void MouseMoved(BPoint, uint32, const BMessage*);
154 		virtual void InsertText(const char *text, int32 length, int32 offset,
155 			const text_run_array *runs);
156 		virtual void  DeleteText(int32 start, int32 finish);
157 
158 		void ClearList();
159 		void LoadMessage(BEmailMessage *mail, bool quoteIt, const char *insertText);
160 		void Open(hyper_text*);
161 		status_t Save(BMessage *, bool makeNewFile = true);
162 		void StopLoad();
163 		void AddAsContent(BEmailMessage *mail, bool wrap, uint32 charset, mail_encoding encoding);
164 		void CheckSpelling(int32 start, int32 end,
165 			int32 flags = S_CLEAR_ERRORS | S_SHOW_ERRORS);
166 		void FindSpellBoundry(int32 length, int32 offset, int32 *start,
167 			int32 *end);
168 		void EnableSpellCheck(bool enable);
169 
170 		void AddQuote(int32 start, int32 finish);
171 		void RemoveQuote(int32 start, int32 finish);
172 
173 		void	WindowActivated(bool flag);
174 		void	Undo(BClipboard *clipboard);
175 		void	Redo();
176 
177 		const BFont *Font() const { return &fFont; }
178 
179 		bool fHeader;
180 		bool fColoredQuotes;
181 		bool fReady;
182 
183 	private:
184 		struct { bool replaced, deleted; } fUndoState;
185 		KUndoBuffer	fUndoBuffer;
186 
187 		struct { bool active, replace; } fInputMethodUndoState;
188 		KUndoBuffer	fInputMethodUndoBuffer;
189 			// For handling Input Method changes in undo.
190 
191 		struct spell_mark;
192 
193 		spell_mark *FindSpellMark(int32 start, int32 end, spell_mark **_previousMark = NULL);
194 		void UpdateSpellMarks(int32 offset, int32 length);
195 		status_t AddSpellMark(int32 start, int32 end);
196 		bool RemoveSpellMark(int32 start, int32 end);
197 		void RemoveSpellMarks();
198 
199 		void ContentChanged(void);
200 
201 		class Reader;
202 		friend class TTextView::Reader;
203 
204 		char *fYankBuffer;
205 		int32 fLastPosition;
206 		BFile *fFile;
207 		BEmailMessage *fMail;
208 			// for incoming/replied/forwarded mails only
209 		BFont fFont;
210 		TContentView *fParent;
211 		sem_id fStopSem;
212 		bool fStopLoading;
213 		thread_id fThread;
214 		BList *fEnclosures;
215 		BPopUpMenu *fEnclosureMenu;
216 		BPopUpMenu *fLinkMenu;
217 		TSavePanel *fPanel;
218 		bool fIncoming;
219 		bool fSpellCheck;
220 		bool fRaw;
221 		bool fCursor;
222 
223 		struct spell_mark
224 		{
225 			spell_mark *next;
226 			int32	start;
227 			int32	end;
228 			struct text_run_array *style;
229 		};
230 
231 		spell_mark *fFirstSpellMark;
232 
233 		class Reader
234 		{
235 			public:
236 				Reader(bool header,bool raw,bool quote,bool incoming,bool stripHeaders,bool mime,
237 					TTextView *view,BEmailMessage *mail,BList *list,sem_id sem);
238 
239 				static status_t Run(void *);
240 
241 			private:
242 				bool ParseMail(BMailContainer *container,BTextMailComponent *ignore);
243 				bool Process(const char *data, int32 len, bool isHeader = false);
244 				bool Insert(const char *line, int32 count, bool isHyperLink, bool isHeader = false);
245 
246 				bool Lock();
247 				status_t Unlock();
248 
249 				bool fHeader;
250 				bool fRaw;
251 				bool fQuote;
252 				bool fIncoming;
253 				bool fStripHeader;
254 				bool fMime;
255 				TTextView *fView;
256 				BEmailMessage *fMail;
257 				BList *fEnclosures;
258 				sem_id fStopSem;
259 		};
260 };
261 
262 
263 //====================================================================
264 
265 class TSavePanel : public BFilePanel {
266 	public:
267 		TSavePanel(hyper_text*, TTextView*);
268 		virtual void SendMessage(const BMessenger*, BMessage*);
269 		void SetEnclosure(hyper_text*);
270 
271 	private:
272 		hyper_text *fEnclosure;
273 		TTextView *fView;
274 };
275 
276 //====================================================================
277 
278 class TextRunArray {
279 	public:
280 		TextRunArray(size_t entries);
281 		~TextRunArray();
282 
283 		text_run_array &Array() { return *fArray; }
284 		size_t MaxEntries() const { return fNumEntries; }
285 
286 	private:
287 		text_run_array *fArray;
288 		size_t fNumEntries;
289 };
290 
291 extern void FillInQuoteTextRuns(BTextView *view, const char *line, int32 length,
292 				const BFont &font, text_run_array *style, int32 maxStyles = 5);
293 
294 #endif	/* #ifndef _CONTENT_H */
295