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 * Stefano Ceccherini, burton666@libero.it 8 */ 9 10 11#include <Font.h> 12#include <InterfaceDefs.h> 13#include <SupportDefs.h> 14#include <TextView.h> 15 16#include "TextViewSupportBuffer.h" 17 18 19struct STEStyle { 20 BFont font; // font 21 rgb_color color; // pen color 22}; 23 24 25struct STEStyleRun { 26 long offset; // byte offset of first character of run 27 STEStyle style; // style info 28}; 29 30 31struct STEStyleRange { 32 long count; // number of style runs 33 STEStyleRun runs[1]; // array of count number of runs 34}; 35 36 37struct 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 42}; 43 44 45struct STEStyleRunDesc { 46 long offset; // byte offset of first character of run 47 long index; // index of corresponding style record 48}; 49 50 51// _BStyleRunDescBuffer_ class ------------------------------------------------- 52class _BStyleRunDescBuffer_ : public _BTextViewSupportBuffer_<STEStyleRunDesc> { 53public: 54 _BStyleRunDescBuffer_(); 55 56 void InsertDesc(STEStyleRunDesc* inDesc, 57 int32 index); 58 void RemoveDescs(int32 index, int32 count = 1); 59 60 int32 OffsetToRun(int32 offset) const; 61 void BumpOffset(int32 delta, int32 index); 62 63 STEStyleRunDesc* operator[](int32 index) const; 64}; 65 66 67inline STEStyleRunDesc* 68_BStyleRunDescBuffer_::operator[](int32 index) const 69{ 70 return &fBuffer[index]; 71} 72 73 74// _BStyleRecordBuffer_ class -------------------------------------------------- 75class _BStyleRecordBuffer_ : public _BTextViewSupportBuffer_<STEStyleRecord> { 76public: 77 _BStyleRecordBuffer_(); 78 79 int32 InsertRecord(const BFont* inFont, 80 const rgb_color* inColor); 81 void CommitRecord(int32 index); 82 void RemoveRecord(int32 index); 83 84 bool MatchRecord(const BFont* inFont, 85 const rgb_color* inColor, 86 int32* outIndex); 87 88 STEStyleRecord* operator[](int32 index) const; 89}; 90 91 92inline STEStyleRecord* 93_BStyleRecordBuffer_::operator[](int32 index) const 94{ 95 return &fBuffer[index]; 96} 97 98 99// StyleBuffer class -------------------------------------------------------- 100class BTextView::StyleBuffer { 101public: 102 StyleBuffer(const BFont* inFont, 103 const rgb_color* inColor); 104 105 void InvalidateNullStyle(); 106 bool IsValidNullStyle() const; 107 108 void SyncNullStyle(int32 offset); 109 void SetNullStyle(uint32 inMode, 110 const BFont* inFont, 111 const rgb_color* inColor, 112 int32 offset = 0); 113 void GetNullStyle(const BFont** font, 114 const rgb_color** color) const; 115 116 void GetStyle(int32 inOffset, BFont* outFont, 117 rgb_color* outColor) const; 118 void ContinuousGetStyle(BFont*, uint32*, 119 rgb_color*, bool*, int32, int32) const; 120 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; 129 130 void RemoveStyleRange(int32 fromOffset, 131 int32 toOffset); 132 void RemoveStyles(int32 index, int32 count = 1); 133 134 int32 Iterate(int32 fromOffset, int32 length, 135 InlineInput* input, 136 const BFont** outFont = NULL, 137 const rgb_color** outColor = NULL, 138 float* outAscent = NULL, 139 float* outDescen = NULL, 140 uint32* = NULL) const; 141 142 int32 OffsetToRun(int32 offset) const; 143 void BumpOffset(int32 delta, int32 index); 144 145 STEStyleRun operator[](int32 index) const; 146 int32 NumRuns() const; 147 148 const _BStyleRunDescBuffer_& RunBuffer() const; 149 const _BStyleRecordBuffer_& RecordBuffer() const; 150 151private: 152 _BStyleRunDescBuffer_ fStyleRunDesc; 153 _BStyleRecordBuffer_ fStyleRecord; 154 bool fValidNullStyle; 155 STEStyle fNullStyle; 156}; 157 158 159inline int32 160BTextView::StyleBuffer::NumRuns() const 161{ 162 return fStyleRunDesc.ItemCount(); 163} 164 165 166inline const _BStyleRunDescBuffer_& 167BTextView::StyleBuffer::RunBuffer() const 168{ 169 return fStyleRunDesc; 170} 171 172 173inline const _BStyleRecordBuffer_& 174BTextView::StyleBuffer::RecordBuffer() const 175{ 176 return fStyleRecord; 177} 178