2 * Copyright 2013-2015, Stephan Aßmus <superstippi@gmx.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
5 #ifndef TEXT_DOCUMENT_LAYOUT_H
6 #define TEXT_DOCUMENT_LAYOUT_H
8 #include <Referenceable.h>
11 #include "TextDocument.h"
12 #include "ParagraphLayout.h"
18 class ParagraphLayoutInfo
{
27 ParagraphLayoutInfo(float y
, const ParagraphLayoutRef
& layout
)
34 ParagraphLayoutInfo(const ParagraphLayoutInfo
& other
)
42 ParagraphLayoutInfo
& operator=(const ParagraphLayoutInfo
& other
)
45 layout
= other
.layout
;
49 bool operator==(const ParagraphLayoutInfo
& other
) const
52 && layout
== other
.layout
;
55 bool operator!=(const ParagraphLayoutInfo
& other
) const
57 return !(*this == other
);
62 ParagraphLayoutRef layout
;
66 typedef List
<ParagraphLayoutInfo
, false> ParagraphLayoutList
;
69 class TextDocumentLayout
: public BReferenceable
{
73 const TextDocumentRef
& document
);
75 const TextDocumentLayout
& other
);
76 virtual ~TextDocumentLayout();
79 const TextDocumentRef
& document
);
82 void InvalidateParagraphs(int32 start
, int32 count
);
84 void SetWidth(float width
);
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
);
97 void GetLineBounds(int32 lineIndex
,
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
);
110 void _ValidateLayout();
113 void _DrawLayout(BView
* view
,
114 const ParagraphLayoutInfo
& layout
) const;
116 int32
_ParagraphLayoutIndexForOffset(
118 int32
_ParagraphLayoutIndexForLineIndex(
120 int32
& paragraphOffset
);
126 TextDocumentRef fDocument
;
127 TextListenerRef fTextListener
;
128 ParagraphLayoutList fParagraphLayouts
;
132 typedef BReference
<TextDocumentLayout
> TextDocumentLayoutRef
;
134 #endif // TEXT_DOCUMENT_LAYOUT_H