repository_infos: Enable automatic updates on the main Haiku repostiory.
[haiku.git] / src / apps / haikudepot / textview / TextDocumentLayout.h
blob6f111e75bb65b4a988e531c6b66cc859375d0007
1 /*
2 * Copyright 2013-2015, Stephan Aßmus <superstippi@gmx.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
5 #ifndef TEXT_DOCUMENT_LAYOUT_H
6 #define TEXT_DOCUMENT_LAYOUT_H
8 #include <Referenceable.h>
10 #include "List.h"
11 #include "TextDocument.h"
12 #include "ParagraphLayout.h"
15 class BView;
18 class ParagraphLayoutInfo {
19 public:
20 ParagraphLayoutInfo()
22 y(0.0f),
23 layout()
27 ParagraphLayoutInfo(float y, const ParagraphLayoutRef& layout)
29 y(y),
30 layout(layout)
34 ParagraphLayoutInfo(const ParagraphLayoutInfo& other)
36 y(other.y),
37 layout(other.layout)
42 ParagraphLayoutInfo& operator=(const ParagraphLayoutInfo& other)
44 y = other.y;
45 layout = other.layout;
46 return *this;
49 bool operator==(const ParagraphLayoutInfo& other) const
51 return y == other.y
52 && layout == other.layout;
55 bool operator!=(const ParagraphLayoutInfo& other) const
57 return !(*this == other);
60 public:
61 float y;
62 ParagraphLayoutRef layout;
66 typedef List<ParagraphLayoutInfo, false> ParagraphLayoutList;
69 class TextDocumentLayout : public BReferenceable {
70 public:
71 TextDocumentLayout();
72 TextDocumentLayout(
73 const TextDocumentRef& document);
74 TextDocumentLayout(
75 const TextDocumentLayout& other);
76 virtual ~TextDocumentLayout();
78 void SetTextDocument(
79 const TextDocumentRef& document);
81 void Invalidate();
82 void InvalidateParagraphs(int32 start, int32 count);
84 void SetWidth(float width);
85 float Width() const
86 { return fWidth; }
88 float Height();
89 void Draw(BView* view, const BPoint& offset,
90 const BRect& updateRect);
92 int32 LineIndexForOffset(int32 textOffset);
93 int32 FirstOffsetOnLine(int32 lineIndex);
94 int32 LastOffsetOnLine(int32 lineIndex);
95 int32 CountLines();
97 void GetLineBounds(int32 lineIndex,
98 float& x1, float& y1,
99 float& x2, float& y2);
101 void GetTextBounds(int32 textOffset,
102 float& x1, float& y1,
103 float& x2, float& y2);
105 int32 TextOffsetAt(float x, float y,
106 bool& rightOfCenter);
108 private:
109 void _Init();
110 void _ValidateLayout();
111 void _Layout();
113 void _DrawLayout(BView* view,
114 const ParagraphLayoutInfo& layout) const;
116 int32 _ParagraphLayoutIndexForOffset(
117 int32& textOffset);
118 int32 _ParagraphLayoutIndexForLineIndex(
119 int32& lineIndex,
120 int32& paragraphOffset);
122 private:
123 float fWidth;
124 bool fLayoutValid;
126 TextDocumentRef fDocument;
127 TextListenerRef fTextListener;
128 ParagraphLayoutList fParagraphLayouts;
132 typedef BReference<TextDocumentLayout> TextDocumentLayoutRef;
134 #endif // TEXT_DOCUMENT_LAYOUT_H