2 * Copyright 2001-2006 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Marc Flerackers, mflerackers@androme.be
7 * Stefano Ceccherini, burton666@libero.it
12 #include <InterfaceDefs.h>
13 #include <SupportDefs.h>
16 #include "TextViewSupportBuffer.h"
21 rgb_color color
; // pen color
26 long offset
; // byte offset of first character of run
27 STEStyle style
; // style info
31 struct STEStyleRange
{
32 long count
; // number of style runs
33 STEStyleRun runs
[1]; // array of count number of runs
37 struct STEStyleRecord
{
38 long refs
; // reference count for this style
39 float ascent
; // ascent for this style
40 float descent
; // descent for this style
41 STEStyle style
; // style info
45 struct STEStyleRunDesc
{
46 long offset
; // byte offset of first character of run
47 long index
; // index of corresponding style record
51 // _BStyleRunDescBuffer_ class -------------------------------------------------
52 class _BStyleRunDescBuffer_
: public _BTextViewSupportBuffer_
<STEStyleRunDesc
> {
54 _BStyleRunDescBuffer_();
56 void InsertDesc(STEStyleRunDesc
* inDesc
,
58 void RemoveDescs(int32 index
, int32 count
= 1);
60 int32
OffsetToRun(int32 offset
) const;
61 void BumpOffset(int32 delta
, int32 index
);
63 STEStyleRunDesc
* operator[](int32 index
) const;
67 inline STEStyleRunDesc
*
68 _BStyleRunDescBuffer_::operator[](int32 index
) const
70 return &fBuffer
[index
];
74 // _BStyleRecordBuffer_ class --------------------------------------------------
75 class _BStyleRecordBuffer_
: public _BTextViewSupportBuffer_
<STEStyleRecord
> {
77 _BStyleRecordBuffer_();
79 int32
InsertRecord(const BFont
* inFont
,
80 const rgb_color
* inColor
);
81 void CommitRecord(int32 index
);
82 void RemoveRecord(int32 index
);
84 bool MatchRecord(const BFont
* inFont
,
85 const rgb_color
* inColor
,
88 STEStyleRecord
* operator[](int32 index
) const;
92 inline STEStyleRecord
*
93 _BStyleRecordBuffer_::operator[](int32 index
) const
95 return &fBuffer
[index
];
99 // StyleBuffer class --------------------------------------------------------
100 class BTextView::StyleBuffer
{
102 StyleBuffer(const BFont
* inFont
,
103 const rgb_color
* inColor
);
105 void InvalidateNullStyle();
106 bool IsValidNullStyle() const;
108 void SyncNullStyle(int32 offset
);
109 void SetNullStyle(uint32 inMode
,
111 const rgb_color
* inColor
,
113 void GetNullStyle(const BFont
** font
,
114 const rgb_color
** color
) const;
116 void GetStyle(int32 inOffset
, BFont
* outFont
,
117 rgb_color
* outColor
) const;
118 void ContinuousGetStyle(BFont
*, uint32
*,
119 rgb_color
*, bool*, int32
, int32
) const;
121 STEStyleRange
* AllocateStyleRange(
122 const int32 numStyles
) const;
123 void SetStyleRange(int32 fromOffset
,
124 int32 toOffset
, int32 textLen
,
125 uint32 inMode
, const BFont
* inFont
,
126 const rgb_color
* inColor
);
127 STEStyleRange
* GetStyleRange(int32 startOffset
,
128 int32 endOffset
) const;
130 void RemoveStyleRange(int32 fromOffset
,
132 void RemoveStyles(int32 index
, int32 count
= 1);
134 int32
Iterate(int32 fromOffset
, int32 length
,
136 const BFont
** outFont
= NULL
,
137 const rgb_color
** outColor
= NULL
,
138 float* outAscent
= NULL
,
139 float* outDescen
= NULL
,
140 uint32
* = NULL
) const;
142 int32
OffsetToRun(int32 offset
) const;
143 void BumpOffset(int32 delta
, int32 index
);
145 STEStyleRun
operator[](int32 index
) const;
146 int32
NumRuns() const;
148 const _BStyleRunDescBuffer_
& RunBuffer() const;
149 const _BStyleRecordBuffer_
& RecordBuffer() const;
152 _BStyleRunDescBuffer_ fStyleRunDesc
;
153 _BStyleRecordBuffer_ fStyleRecord
;
154 bool fValidNullStyle
;
160 BTextView::StyleBuffer::NumRuns() const
162 return fStyleRunDesc
.ItemCount();
166 inline const _BStyleRunDescBuffer_
&
167 BTextView::StyleBuffer::RunBuffer() const
169 return fStyleRunDesc
;
173 inline const _BStyleRecordBuffer_
&
174 BTextView::StyleBuffer::RecordBuffer() const