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