2 * Copyright 2001-2006, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Marc Flerackers (mflerackers@androme.be)
10 #include "LineBuffer.h"
13 BTextView::LineBuffer::LineBuffer()
14 : _BTextViewSupportBuffer_
<STELine
>(20, 2)
19 BTextView::LineBuffer::~LineBuffer()
25 BTextView::LineBuffer::InsertLine(STELine
* inLine
, int32 index
)
27 InsertItemsAt(1, index
, inLine
);
32 BTextView::LineBuffer::RemoveLines(int32 index
, int32 count
)
34 RemoveItemsAt(count
, index
);
39 BTextView::LineBuffer::RemoveLineRange(int32 fromOffset
, int32 toOffset
)
41 int32 fromLine
= OffsetToLine(fromOffset
);
42 int32 toLine
= OffsetToLine(toOffset
);
44 int32 count
= toLine
- fromLine
;
46 RemoveLines(fromLine
+ 1, count
);
48 BumpOffset(fromOffset
- toOffset
, fromLine
+ 1);
53 BTextView::LineBuffer::OffsetToLine(int32 offset
) const
56 int32 maxIndex
= fItemCount
- 1;
59 while (minIndex
< maxIndex
) {
60 index
= (minIndex
+ maxIndex
) >> 1;
61 if (offset
>= fBuffer
[index
].offset
) {
62 if (offset
< fBuffer
[index
+ 1].offset
)
75 BTextView::LineBuffer::PixelToLine(float pixel
) const
78 int32 maxIndex
= fItemCount
- 1;
81 while (minIndex
< maxIndex
) {
82 index
= (minIndex
+ maxIndex
) >> 1;
83 if (pixel
>= fBuffer
[index
].origin
) {
84 if (pixel
< fBuffer
[index
+ 1].origin
)
97 BTextView::LineBuffer::BumpOrigin(float delta
, int32 index
)
99 for (long i
= index
; i
< fItemCount
; i
++)
100 fBuffer
[i
].origin
+= delta
;
105 BTextView::LineBuffer::BumpOffset(int32 delta
, int32 index
)
107 for (long i
= index
; i
< fItemCount
; i
++)
108 fBuffer
[i
].offset
+= delta
;
113 BTextView::LineBuffer::MaxWidth() const
119 STELine
* line
= &fBuffer
[0];
120 for (int32 i
= 0; i
< fItemCount
; i
++) {
121 if (maxWidth
< line
->width
)
122 maxWidth
= line
->width
;