xref: /haiku/src/apps/haikudepot/textview/Paragraph.h (revision 3d2fd2acaf1ed103639675b3116c2ac874aa174d)
1 /*
2  * Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>.
3  * Copyright 2021, Andrew Lindesay <apl@lindesay.co.nz>.
4  * All rights reserved. Distributed under the terms of the MIT License.
5  */
6 #ifndef PARAGRAPH_H
7 #define PARAGRAPH_H
8 
9 #include <vector>
10 
11 #include "ParagraphStyle.h"
12 #include "TextSpan.h"
13 
14 
15 class Paragraph {
16 public:
17 								Paragraph();
18 								Paragraph(const ParagraphStyle& style);
19 								Paragraph(const Paragraph& other);
20 
21 			Paragraph&			operator=(const Paragraph& other);
22 			bool				operator==(const Paragraph& other) const;
23 			bool				operator!=(const Paragraph& other) const;
24 
25 			void				SetStyle(const ParagraphStyle& style);
Style()26 	inline	const ParagraphStyle& Style() const
27 									{ return fStyle; }
28 
29 			int32				CountTextSpans() const;
30 			const TextSpan&		TextSpanAtIndex(int32 index) const;
31 
32 			bool				Prepend(const TextSpan& span);
33 			bool				Append(const TextSpan& span);
34 			bool				Insert(int32 offset, const TextSpan& span);
35 			bool				Remove(int32 offset, int32 length);
36 			void				Clear();
37 
38 			int32				Length() const;
39 			bool				IsEmpty() const;
40 			bool				EndsWith(BString string) const;
41 
42 			BString				Text() const;
43 			BString				Text(int32 start, int32 length) const;
44 			Paragraph			SubParagraph(int32 start, int32 length) const;
45 
46 			void				PrintToStream() const;
47 
48 private:
49 			void				_InvalidateCachedLength();
50 
51 private:
52 			ParagraphStyle		fStyle;
53 			std::vector<TextSpan>
54 								fTextSpans;
55 	mutable	int32				fCachedLength;
56 };
57 
58 
59 #endif // PARAGRAPH_H
60