repository_infos: Enable automatic updates on the main Haiku repostiory.
[haiku.git] / src / apps / haikudepot / textview / TextDocument.h
blob102956641a00f58a0d5aa759c41cf1fc4c72002f
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 TEXT_DOCUMENT_H
6 #define TEXT_DOCUMENT_H
8 #include <Referenceable.h>
10 #include "CharacterStyle.h"
11 #include "List.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;
21 class TextDocument;
22 typedef BReference<TextDocument> TextDocumentRef;
25 class TextDocument : public BReferenceable {
26 public:
27 TextDocument();
28 TextDocument(
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,
48 const BString& text);
49 status_t Replace(int32 textOffset, int32 length,
50 const BString& text,
51 CharacterStyle style);
52 status_t Replace(int32 textOffset, int32 length,
53 const BString& text,
54 CharacterStyle characterStyle,
55 ParagraphStyle paragraphStyle);
56 status_t Replace(int32 textOffset, int32 length,
57 TextDocumentRef document);
59 // Style access
60 const CharacterStyle& CharacterStyleAt(int32 textOffset) const;
61 const ParagraphStyle& ParagraphStyleAt(int32 textOffset) const;
63 // Paragraph access
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);
79 // Query information
80 int32 Length() const;
82 BString Text() const;
83 BString Text(int32 textOffset, int32 length) const;
84 TextDocumentRef SubDocument(int32 textOffset,
85 int32 length) const;
87 void PrintToStream() const;
89 // Support
90 static TextDocumentRef NormalizeText(const BString& text,
91 CharacterStyle characterStyle,
92 ParagraphStyle paragraphStyle);
94 // Listener support
95 bool AddListener(TextListenerRef listener);
96 bool RemoveListener(TextListenerRef listener);
97 bool AddUndoListener(
98 UndoableEditListenerRef listener);
99 bool RemoveUndoListener(
100 UndoableEditListenerRef listener);
102 private:
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);
111 private:
112 void _NotifyTextChanging(
113 TextChangingEvent& event) const;
114 void _NotifyTextChanged(
115 const TextChangedEvent& event) const;
116 void _NotifyUndoableEditHappened(
117 const UndoableEditRef& edit) const;
119 private:
120 ParagraphList fParagraphs;
121 Paragraph fEmptyLastParagraph;
122 CharacterStyle fDefaultCharacterStyle;
124 TextListenerList fTextListeners;
125 UndoListenerList fUndoListeners;
129 #endif // TEXT_DOCUMENT_H