2 * Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
5 #ifndef TEXT_DOCUMENT_H
6 #define TEXT_DOCUMENT_H
8 #include <Referenceable.h>
10 #include "CharacterStyle.h"
12 #include "Paragraph.h"
13 #include "TextListener.h"
14 #include "UndoableEditListener.h"
17 typedef List
<Paragraph
, false> ParagraphList
;
18 typedef List
<TextListenerRef
, false> TextListenerList
;
19 typedef List
<UndoableEditListenerRef
, false> UndoListenerList
;
22 typedef BReference
<TextDocument
> TextDocumentRef
;
25 class TextDocument
: public BReferenceable
{
29 CharacterStyle characterStyle
,
30 ParagraphStyle paragraphStyle
);
31 TextDocument(const TextDocument
& other
);
33 TextDocument
& operator=(const TextDocument
& other
);
34 bool operator==(const TextDocument
& other
) const;
35 bool operator!=(const TextDocument
& other
) const;
37 // Text insertion and removing
38 status_t
Insert(int32 textOffset
, const BString
& text
);
39 status_t
Insert(int32 textOffset
, const BString
& text
,
40 CharacterStyle style
);
41 status_t
Insert(int32 textOffset
, const BString
& text
,
42 CharacterStyle characterStyle
,
43 ParagraphStyle paragraphStyle
);
45 status_t
Remove(int32 textOffset
, int32 length
);
47 status_t
Replace(int32 textOffset
, int32 length
,
49 status_t
Replace(int32 textOffset
, int32 length
,
51 CharacterStyle style
);
52 status_t
Replace(int32 textOffset
, int32 length
,
54 CharacterStyle characterStyle
,
55 ParagraphStyle paragraphStyle
);
56 status_t
Replace(int32 textOffset
, int32 length
,
57 TextDocumentRef document
);
60 const CharacterStyle
& CharacterStyleAt(int32 textOffset
) const;
61 const ParagraphStyle
& ParagraphStyleAt(int32 textOffset
) const;
64 const ParagraphList
& Paragraphs() const
65 { return fParagraphs
; }
67 int32
CountParagraphs() const;
69 int32
ParagraphIndexFor(int32 textOffset
,
70 int32
& paragraphOffset
) const;
72 const Paragraph
& ParagraphAt(int32 textOffset
,
73 int32
& paragraphOffset
) const;
75 const Paragraph
& ParagraphAt(int32 index
) const;
77 bool Append(const Paragraph
& paragraph
);
83 BString
Text(int32 textOffset
, int32 length
) const;
84 TextDocumentRef
SubDocument(int32 textOffset
,
87 void PrintToStream() const;
90 static TextDocumentRef
NormalizeText(const BString
& text
,
91 CharacterStyle characterStyle
,
92 ParagraphStyle paragraphStyle
);
95 bool AddListener(TextListenerRef listener
);
96 bool RemoveListener(TextListenerRef listener
);
98 UndoableEditListenerRef listener
);
99 bool RemoveUndoListener(
100 UndoableEditListenerRef listener
);
103 status_t
_Insert(int32 textOffset
,
104 TextDocumentRef document
,
105 int32
& firstParagraph
,
106 int32
& paragraphCount
);
107 status_t
_Remove(int32 textOffset
, int32 length
,
108 int32
& firstParagraph
,
109 int32
& paragraphCount
);
112 void _NotifyTextChanging(
113 TextChangingEvent
& event
) const;
114 void _NotifyTextChanged(
115 const TextChangedEvent
& event
) const;
116 void _NotifyUndoableEditHappened(
117 const UndoableEditRef
& edit
) const;
120 ParagraphList fParagraphs
;
121 Paragraph fEmptyLastParagraph
;
122 CharacterStyle fDefaultCharacterStyle
;
124 TextListenerList fTextListeners
;
125 UndoListenerList fUndoListeners
;
129 #endif // TEXT_DOCUMENT_H