xref: /haiku/src/kits/interface/textview_support/LineBuffer.h (revision 239222b2369c39dc52df52b0a7cdd6cc0a91bc92)
1 /*
2  * Copyright 2001-2006, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Marc Flerackers (mflerackers@androme.be)
7  */
8 
9 #include <SupportDefs.h>
10 #include <TextView.h>
11 
12 #include "TextViewSupportBuffer.h"
13 
14 struct STELine {
15 	long		offset;		// offset of first character of line
16 	float		origin;		// pixel position of top of line
17 	float		ascent;		// maximum ascent for line
18 	float		width;		// cached width of line in pixels
19 };
20 
21 
22 class BTextView::LineBuffer : public _BTextViewSupportBuffer_<STELine> {
23 
24 public:
25 						LineBuffer();
26 virtual					~LineBuffer();
27 
28 		void			InsertLine(STELine *inLine, int32 index);
29 		void			RemoveLines(int32 index, int32 count = 1);
30 		void			RemoveLineRange(int32 fromOffset, int32 toOffset);
31 
32 		int32			OffsetToLine(int32 offset) const;
33 		int32			PixelToLine(float pixel) const;
34 
35 		void			BumpOrigin(float delta, int32 index);
36 		void			BumpOffset(int32 delta, int32 index);
37 
38 		long			NumLines() const;
39 		float			MaxWidth() const;
40 		STELine *		operator[](int32 index) const;
41 };
42 
43 
44 inline int32
45 BTextView::LineBuffer::NumLines() const
46 {
47 	return fItemCount - 1;
48 }
49 
50 
51 inline STELine *
52 BTextView::LineBuffer::operator[](int32 index) const
53 {
54 	return &fBuffer[index];
55 }
56