update from jack burton
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4245 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Copyright (c) 2001-2002, OpenBeOS
|
// Copyright (c) 2001-2003, OpenBeOS
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
// copy of this software and associated documentation files (the "Software"),
|
// copy of this software and associated documentation files (the "Software"),
|
||||||
@@ -25,7 +25,6 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Standard Includes -----------------------------------------------------------
|
// Standard Includes -----------------------------------------------------------
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
// System Includes -------------------------------------------------------------
|
// System Includes -------------------------------------------------------------
|
||||||
#include "LineBuffer.h"
|
#include "LineBuffer.h"
|
||||||
@@ -40,90 +39,94 @@
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
_BLineBuffer_::_BLineBuffer_()
|
_BLineBuffer_::_BLineBuffer_()
|
||||||
: fBlockSize(20),
|
: _BTextViewSupportBuffer_<STELine>(20, 2)
|
||||||
fItemCount(2),
|
|
||||||
fPhysicalSize(22),
|
|
||||||
fObjectList(NULL)
|
|
||||||
{
|
{
|
||||||
fObjectList = new STELine[fPhysicalSize];
|
|
||||||
|
|
||||||
memset(fObjectList, 0, fPhysicalSize * sizeof(STELine));
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
_BLineBuffer_::~_BLineBuffer_()
|
_BLineBuffer_::~_BLineBuffer_()
|
||||||
{
|
{
|
||||||
delete[] fObjectList;
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void _BLineBuffer_::InsertLine(STELine *line, int32 index)
|
void
|
||||||
|
_BLineBuffer_::InsertLine(STELine *inLine, int32 index)
|
||||||
{
|
{
|
||||||
if (fItemCount == fPhysicalSize - 1)
|
InsertItemsAt(1, index, inLine);
|
||||||
{
|
}
|
||||||
STELine *new_list = new STELine[fPhysicalSize + fBlockSize];
|
//------------------------------------------------------------------------------
|
||||||
|
void
|
||||||
|
_BLineBuffer_::RemoveLines(int32 index, int32 count)
|
||||||
|
{
|
||||||
|
RemoveItemsAt(count, index);
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
void
|
||||||
|
_BLineBuffer_::RemoveLineRange(int32 fromOffset, int32 toOffset)
|
||||||
|
{
|
||||||
|
int32 fromLine = OffsetToLine(fromOffset);
|
||||||
|
int32 toLine = OffsetToLine(toOffset);
|
||||||
|
|
||||||
memcpy(new_list, fObjectList, fPhysicalSize * sizeof(STELine));
|
int32 count = toLine - fromLine;
|
||||||
delete fObjectList;
|
if (count > 0)
|
||||||
fObjectList = new_list;
|
RemoveLines(fromLine + 1, count);
|
||||||
|
|
||||||
fPhysicalSize += fBlockSize;
|
BumpOffset(fromOffset - toOffset, fromLine + 1);
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
int32
|
||||||
|
_BLineBuffer_::OffsetToLine(int32 offset) const
|
||||||
|
{
|
||||||
|
int32 minIndex = 0;
|
||||||
|
int32 maxIndex = fItemCount - 1;
|
||||||
|
int32 index = 0;
|
||||||
|
|
||||||
|
while (minIndex < maxIndex) {
|
||||||
|
index = (minIndex + maxIndex) >> 1;
|
||||||
|
if (offset >= fBuffer[index].offset) {
|
||||||
|
if (offset < fBuffer[index + 1].offset)
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
minIndex = index + 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
maxIndex = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index < fItemCount)
|
return index;
|
||||||
memmove(fObjectList + index + 1, fObjectList + index,
|
|
||||||
(fItemCount - index) * sizeof(STELine));
|
|
||||||
memcpy(fObjectList + index, line, sizeof(STELine));
|
|
||||||
|
|
||||||
fItemCount++;
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void _BLineBuffer_::RemoveLines(int32 index, int32 count)
|
int32 _BLineBuffer_::PixelToLine(float pixel) const
|
||||||
{
|
{
|
||||||
memmove(fObjectList + index, fObjectList + index + count,
|
int32 minIndex = 0;
|
||||||
(fItemCount - index - count) * sizeof(STELine));
|
int32 maxIndex = fItemCount - 1;
|
||||||
|
int32 index = 0;
|
||||||
|
|
||||||
fItemCount -= count;
|
while (minIndex < maxIndex) {
|
||||||
}
|
index = (minIndex + maxIndex) >> 1;
|
||||||
//------------------------------------------------------------------------------
|
if (pixel >= fBuffer[index].origin) {
|
||||||
void _BLineBuffer_::RemoveLineRange(int32 from, int32 to)
|
if (pixel < fBuffer[index + 1].origin)
|
||||||
{
|
break;
|
||||||
int32 linefrom = OffsetToLine(from);
|
else
|
||||||
int32 lineto = OffsetToLine(to);
|
minIndex = index + 1;
|
||||||
|
}
|
||||||
if (linefrom < lineto)
|
else
|
||||||
RemoveLines(linefrom + 1, lineto - linefrom);
|
maxIndex = index;
|
||||||
|
|
||||||
BumpOffset(linefrom + 1, from - to);
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
int32 _BLineBuffer_::OffsetToLine(int32 offset) const
|
|
||||||
{
|
|
||||||
if (offset == 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
for (int i = 0; i < fItemCount; i++)
|
|
||||||
{
|
|
||||||
if (offset < fObjectList[i].fOffset)
|
|
||||||
return i - 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return fItemCount - 2;
|
return index;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
int32 _BLineBuffer_::PixelToLine(float height) const
|
void
|
||||||
|
_BLineBuffer_::BumpOrigin(float delta, long index)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < fItemCount; i++)
|
for (long i = index; i < fItemCount; i++)
|
||||||
{
|
fBuffer[i].origin += delta;
|
||||||
if (height < fObjectList[i].fHeight)
|
|
||||||
return i - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return fItemCount - 2;
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void _BLineBuffer_::BumpOffset(int32 line, int32 offset)
|
void
|
||||||
|
_BLineBuffer_::BumpOffset(int32 delta, int32 index)
|
||||||
{
|
{
|
||||||
for (int i = line; i < fItemCount; i++)
|
for (long i = index; i < fItemCount; i++)
|
||||||
fObjectList[i].fOffset += offset;
|
fBuffer[i].offset += delta;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Copyright (c) 2001-2002, OpenBeOS
|
// Copyright (c) 2001-2003, OpenBeOS
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
// copy of this software and associated documentation files (the "Software"),
|
// copy of this software and associated documentation files (the "Software"),
|
||||||
@@ -27,45 +27,56 @@
|
|||||||
// Standard Includes -----------------------------------------------------------
|
// Standard Includes -----------------------------------------------------------
|
||||||
|
|
||||||
// System Includes -------------------------------------------------------------
|
// System Includes -------------------------------------------------------------
|
||||||
#include "SupportDefs.h"
|
#include <SupportDefs.h>
|
||||||
|
#include "TextViewSupportBuffer.h"
|
||||||
|
|
||||||
// Project Includes ------------------------------------------------------------
|
// Project Includes ------------------------------------------------------------
|
||||||
|
|
||||||
// Local Includes --------------------------------------------------------------
|
// Local Includes --------------------------------------------------------------
|
||||||
|
|
||||||
// Local Defines ---------------------------------------------------------------
|
// Local Defines ---------------------------------------------------------------
|
||||||
struct STELine {
|
typedef struct STELine {
|
||||||
int32 fOffset;
|
long offset; // offset of first character of line
|
||||||
float fHeight;
|
float origin; // pixel position of top of line
|
||||||
float fLineHeight;
|
float ascent; // maximum ascent for line
|
||||||
float fWidth;
|
float width; // width of line
|
||||||
};
|
} STELine, *STELinePtr;
|
||||||
|
|
||||||
// Globals ---------------------------------------------------------------------
|
// Globals ---------------------------------------------------------------------
|
||||||
|
|
||||||
// _BLineBuffer_ class ---------------------------------------------------------
|
// _BLineBuffer_ class ---------------------------------------------------------
|
||||||
class _BLineBuffer_ {
|
class _BLineBuffer_ : public _BTextViewSupportBuffer_<STELine> {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
_BLineBuffer_();
|
_BLineBuffer_();
|
||||||
virtual ~_BLineBuffer_();
|
virtual ~_BLineBuffer_();
|
||||||
|
|
||||||
void InsertLine(STELine *line, int32);
|
void InsertLine(STELine *inLine, int32 index);
|
||||||
void RemoveLines(int32 index, int32 count);
|
void RemoveLines(int32 index, int32 count = 1);
|
||||||
void RemoveLineRange(int32 from, int32 to);
|
void RemoveLineRange(int32 fromOffset, int32 toOffset);
|
||||||
|
|
||||||
int32 OffsetToLine(int32 offset) const;
|
int32 OffsetToLine(int32 offset) const;
|
||||||
int32 PixelToLine(float height) const;
|
int32 PixelToLine(float pixel) const;
|
||||||
|
|
||||||
void BumpOffset(int32 line, int32 offset);
|
void BumpOrigin(float delta, int32 index);
|
||||||
void BumpOrigin(float, int32);
|
void BumpOffset(int32 delta, int32 index);
|
||||||
|
|
||||||
int32 fBlockSize;
|
long NumLines() const;
|
||||||
int32 fItemCount;
|
const STELinePtr operator[](int32 index) const;
|
||||||
size_t fPhysicalSize;
|
|
||||||
STELine *fObjectList;
|
|
||||||
};
|
};
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
inline int32
|
||||||
|
_BLineBuffer_::NumLines() const
|
||||||
|
{
|
||||||
|
return fItemCount - 1;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
inline const STELinePtr
|
||||||
|
_BLineBuffer_::operator[](int32 index) const
|
||||||
|
{
|
||||||
|
return &fBuffer[index];
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* $Log $
|
* $Log $
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Copyright (c) 2001-2002, OpenBeOS
|
// Copyright (c) 2001-2003, OpenBeOS
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
// copy of this software and associated documentation files (the "Software"),
|
// copy of this software and associated documentation files (the "Software"),
|
||||||
@@ -38,115 +38,536 @@
|
|||||||
// Globals ---------------------------------------------------------------------
|
// Globals ---------------------------------------------------------------------
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
_BStyleBuffer_::_BStyleBuffer_(const BFont *font, const rgb_color *color)
|
_BStyleRunDescBuffer_::_BStyleRunDescBuffer_()
|
||||||
: fRuns(10, 10),
|
: _BTextViewSupportBuffer_<STEStyleRunDesc>(20)
|
||||||
fRecords(10, 10)
|
|
||||||
{
|
|
||||||
rgb_color black = {0, 0, 0, 255};
|
|
||||||
|
|
||||||
SetNullStyle(0, font ? font : be_plain_font, color ? color : &black, 0);
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
_BStyleBuffer_::~_BStyleBuffer_()
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void _BStyleBuffer_::SetNullStyle(uint32 mode, const BFont *font,
|
void
|
||||||
const rgb_color *color, int32)
|
_BStyleRunDescBuffer_::InsertDesc(STEStyleRunDescPtr inDesc, int32 index)
|
||||||
{
|
{
|
||||||
// TODO: use mode.
|
InsertItemsAt(1, index, inDesc);
|
||||||
if (font)
|
|
||||||
fNullStyle.fFont = *font;
|
|
||||||
|
|
||||||
if (color)
|
|
||||||
fNullStyle.fColor = *color;
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void _BStyleBuffer_::GetNullStyle(const BFont **font, const rgb_color **color) const
|
void
|
||||||
|
_BStyleRunDescBuffer_::RemoveDescs(int32 index, int32 count)
|
||||||
{
|
{
|
||||||
*font = &fNullStyle.fFont;
|
RemoveItemsAt(count, index);
|
||||||
*color = &fNullStyle.fColor;
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void _BStyleBuffer_::SyncNullStyle(int32)
|
int32
|
||||||
|
_BStyleRunDescBuffer_::OffsetToRun(int32 offset) const
|
||||||
{
|
{
|
||||||
}
|
if (fItemCount <= 1)
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void _BStyleBuffer_::InvalidateNullStyle()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
bool _BStyleBuffer_::IsValidNullStyle() const
|
|
||||||
{
|
|
||||||
// TODO: why would a style be invalid?
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void _BStyleBuffer_::SetStyle(uint32 mode, const BFont *font, BFont *,
|
|
||||||
const rgb_color *color, rgb_color *) const
|
|
||||||
{
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void _BStyleBuffer_::GetStyle(uint32 mode, BFont *font, rgb_color *color) const
|
|
||||||
{
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void _BStyleBuffer_::SetStyleRange(int32 from, int32 to, int32, uint32 mode,
|
|
||||||
const BFont *, const rgb_color *)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
int32 _BStyleBuffer_::GetStyleRange(int32 from, int32 to) const
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void _BStyleBuffer_::ContinuousGetStyle(BFont *, uint32 *, rgb_color *, bool *,
|
|
||||||
int32, int32) const
|
|
||||||
{
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void _BStyleBuffer_::RemoveStyles(int32 from, int32 to)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void _BStyleBuffer_::RemoveStyleRange(int32 from, int32 to)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
int32 _BStyleBuffer_::OffsetToRun(int32 offset) const
|
|
||||||
{
|
|
||||||
if (offset == 0)
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (int i = 0; i < fRuns.fCount; i++)
|
int32 minIndex = 0;
|
||||||
{
|
int32 maxIndex = fItemCount;
|
||||||
if (offset < fRuns.fItems[i].fOffset)
|
int32 index = 0;
|
||||||
return i - 1;
|
|
||||||
|
while (minIndex < maxIndex) {
|
||||||
|
index = (minIndex + maxIndex) >> 1;
|
||||||
|
if (offset >= fBuffer[index].offset) {
|
||||||
|
if (index >= (fItemCount - 1)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (offset < fBuffer[index + 1].offset)
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
minIndex = index + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
maxIndex = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fRuns.fCount - 2;
|
return index;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void _BStyleBuffer_::BumpOffset(int32 run, int32 offset)
|
void
|
||||||
|
_BStyleRunDescBuffer_::BumpOffset(int32 delta, int32 index)
|
||||||
{
|
{
|
||||||
for (int i = run; i < fRuns.fCount; i++)
|
for (int32 i = index; i < fItemCount; i++)
|
||||||
fRuns.fItems[i].fOffset += offset;
|
fBuffer[i].offset += delta;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
/*void _BStyleBuffer_::Iterate(int32, int32, _BInlineInput_ *, const BFont **,
|
_BStyleRecordBuffer_::_BStyleRecordBuffer_()
|
||||||
const rgb_color **, float *, uint32 *) const
|
: _BTextViewSupportBuffer_<STEStyleRecord>()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
int32
|
||||||
|
_BStyleRecordBuffer_::InsertRecord(const BFont *inFont,
|
||||||
|
const rgb_color *inColor)
|
||||||
|
{
|
||||||
|
int32 index = 0;
|
||||||
|
|
||||||
|
// look for style in buffer
|
||||||
|
if (MatchRecord(inFont, inColor, &index))
|
||||||
|
return (index);
|
||||||
|
|
||||||
|
// style not found, add it
|
||||||
|
font_height fh;
|
||||||
|
inFont->GetHeight(&fh);
|
||||||
|
|
||||||
|
// check if there's any unused space
|
||||||
|
for (index = 0; index < fItemCount; index++) {
|
||||||
|
if (fBuffer[index].refs < 1) {
|
||||||
|
fBuffer[index].refs = 0;
|
||||||
|
fBuffer[index].ascent = fh.ascent;
|
||||||
|
fBuffer[index].descent = fh.descent + fh.leading;
|
||||||
|
fBuffer[index].style.font = *inFont;
|
||||||
|
fBuffer[index].style.color = *inColor;
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// no unused space, expand the buffer
|
||||||
|
index = fItemCount;
|
||||||
|
STEStyleRecord newRecord;
|
||||||
|
newRecord.refs = 0;
|
||||||
|
newRecord.ascent = fh.ascent;
|
||||||
|
newRecord.descent = fh.descent + fh.leading;
|
||||||
|
newRecord.style.font = *inFont;
|
||||||
|
newRecord.style.color = *inColor;
|
||||||
|
InsertItemsAt(1, index, &newRecord);
|
||||||
|
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
void
|
||||||
|
_BStyleRecordBuffer_::CommitRecord(
|
||||||
|
int32 index)
|
||||||
|
{
|
||||||
|
fBuffer[index].refs++;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
void
|
||||||
|
_BStyleRecordBuffer_::RemoveRecord(
|
||||||
|
int32 index)
|
||||||
|
{
|
||||||
|
fBuffer[index].refs--;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
bool
|
||||||
|
_BStyleRecordBuffer_::MatchRecord(const BFont *inFont,
|
||||||
|
const rgb_color *inColor, int32 *outIndex)
|
||||||
|
{
|
||||||
|
for (int32 i = 0; i < fItemCount; i++) {
|
||||||
|
if ( (inFont->Size() == fBuffer[i].style.font.Size()) &&
|
||||||
|
(inFont->Shear() == fBuffer[i].style.font.Shear()) &&
|
||||||
|
(inFont->Face() == fBuffer[i].style.font.Face()) &&
|
||||||
|
(inColor->red == fBuffer[i].style.color.red) &&
|
||||||
|
(inColor->green == fBuffer[i].style.color.green) &&
|
||||||
|
(inColor->blue == fBuffer[i].style.color.blue) &&
|
||||||
|
(inColor->alpha == fBuffer[i].style.color.alpha) ) {
|
||||||
|
*outIndex = i;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
_BStyleBuffer_::_BStyleBuffer_(const BFont *inFont, const rgb_color *inColor)
|
||||||
|
{
|
||||||
|
fValidNullStyle = true;
|
||||||
|
fNullStyle.font = *inFont;
|
||||||
|
fNullStyle.color = *inColor;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
void
|
||||||
|
_BStyleBuffer_::InvalidateNullStyle()
|
||||||
|
{
|
||||||
|
fValidNullStyle = false;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
bool
|
||||||
|
_BStyleBuffer_::IsValidNullStyle() const
|
||||||
|
{
|
||||||
|
return fValidNullStyle;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
void
|
||||||
|
_BStyleBuffer_::SyncNullStyle(int32 offset)
|
||||||
|
{
|
||||||
|
if ((fValidNullStyle) || (fStyleRunDesc.ItemCount() < 1))
|
||||||
|
return;
|
||||||
|
|
||||||
|
int32 index = OffsetToRun(offset);
|
||||||
|
fNullStyle = fStyleRecord[fStyleRunDesc[index]->index]->style;
|
||||||
|
|
||||||
|
fValidNullStyle = true;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
void
|
||||||
|
_BStyleBuffer_::SetNullStyle(uint32 inMode, const BFont *inFont,
|
||||||
|
const rgb_color *inColor, int32 offset)
|
||||||
|
{
|
||||||
|
if ((fValidNullStyle) || (fStyleRunDesc.ItemCount() < 1))
|
||||||
|
SetStyle(inMode, inFont, &fNullStyle.font, inColor, &fNullStyle.color);
|
||||||
|
else {
|
||||||
|
int32 index = OffsetToRun(offset - 1);
|
||||||
|
fNullStyle = fStyleRecord[fStyleRunDesc[index]->index]->style;
|
||||||
|
SetStyle(inMode, inFont, &fNullStyle.font, inColor, &fNullStyle.color);
|
||||||
|
}
|
||||||
|
|
||||||
|
fValidNullStyle = true;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
void
|
||||||
|
_BStyleBuffer_::GetNullStyle(const BFont **font,
|
||||||
|
const rgb_color **color) const
|
||||||
|
{
|
||||||
|
if (font)
|
||||||
|
*font = &fNullStyle.font;
|
||||||
|
if (color)
|
||||||
|
*color = &fNullStyle.color;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
bool
|
||||||
|
_BStyleBuffer_::IsContinuousStyle(uint32 *ioMode, STEStylePtr outStyle,
|
||||||
|
int32 fromOffset, int32 toOffset)
|
||||||
|
{
|
||||||
|
if (fStyleRunDesc.ItemCount() < 1) {
|
||||||
|
SetStyle(*ioMode, &fNullStyle.font, &outStyle->font,
|
||||||
|
&fNullStyle.color, &outStyle->color);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool result = true;
|
||||||
|
int32 fromIndex = OffsetToRun(fromOffset);
|
||||||
|
int32 toIndex = OffsetToRun(toOffset - 1);
|
||||||
|
|
||||||
|
if (fromIndex == toIndex) {
|
||||||
|
int32 styleIndex = fStyleRunDesc[fromIndex]->index;
|
||||||
|
STEStylePtr style = &fStyleRecord[styleIndex]->style;
|
||||||
|
|
||||||
|
SetStyle(*ioMode, &style->font, &outStyle->font, &style->color,
|
||||||
|
&outStyle->color);
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int32 styleIndex = fStyleRunDesc[toIndex]->index;
|
||||||
|
STEStyle theStyle = fStyleRecord[styleIndex]->style;
|
||||||
|
//STEStylePtr style = NULL;
|
||||||
|
|
||||||
|
/* for (int32 i = fromIndex; i < toIndex; i++) {
|
||||||
|
styleIndex = fStyleRunDesc[i]->index;
|
||||||
|
style = &fStyleRecord[styleIndex]->style;
|
||||||
|
|
||||||
|
if (*ioMode & doFont) {
|
||||||
|
if (strcmp(theStyle.font, style->font) != 0) {
|
||||||
|
*ioMode &= ~doFont;
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*ioMode & doSize) {
|
||||||
|
if (theStyle.size != style->size) {
|
||||||
|
*ioMode &= ~doSize;
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*ioMode & doShear) {
|
||||||
|
if (theStyle.shear != style->shear) {
|
||||||
|
*ioMode &= ~doShear;
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*ioMode & doUnderline) {
|
||||||
|
if (theStyle.underline != style->underline) {
|
||||||
|
*ioMode &= ~doUnderline;
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*ioMode & doColor) {
|
||||||
|
if ( (theStyle.color.red != style->color.red) ||
|
||||||
|
(theStyle.color.green != style->color.green) ||
|
||||||
|
(theStyle.color.blue != style->color.blue) ||
|
||||||
|
(theStyle.color.alpha != style->color.alpha) ) {
|
||||||
|
*ioMode &= ~doColor;
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*ioMode & doExtra) {
|
||||||
|
if (theStyle.extra != style->extra) {
|
||||||
|
*ioMode &= ~doExtra;
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
SetStyle(*ioMode, &theStyle.font, &outStyle->font, &theStyle.color,
|
||||||
|
&outStyle->color);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
void
|
||||||
|
_BStyleBuffer_::SetStyleRange(int32 fromOffset, int32 toOffset,
|
||||||
|
int32 textLen, uint32 inMode,
|
||||||
|
const BFont *inFont, const rgb_color *inColor)
|
||||||
|
{
|
||||||
|
if (inFont == NULL)
|
||||||
|
inFont = &fNullStyle.font;
|
||||||
|
|
||||||
|
if (inColor == NULL)
|
||||||
|
inColor = &fNullStyle.color;
|
||||||
|
|
||||||
|
if (fromOffset == toOffset) {
|
||||||
|
SetNullStyle(inMode, inFont, inColor, fromOffset);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fStyleRunDesc.ItemCount() < 1) {
|
||||||
|
STEStyleRunDesc newDesc;
|
||||||
|
newDesc.offset = fromOffset;
|
||||||
|
newDesc.index = fStyleRecord.InsertRecord(inFont, inColor);
|
||||||
|
fStyleRunDesc.InsertDesc(&newDesc, 0);
|
||||||
|
fStyleRecord.CommitRecord(newDesc.index);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32 styleIndex = 0;
|
||||||
|
int32 offset = fromOffset;
|
||||||
|
int32 runIndex = OffsetToRun(offset);
|
||||||
|
do {
|
||||||
|
STEStyleRunDesc runDesc = *fStyleRunDesc[runIndex];
|
||||||
|
int32 runEnd = textLen;
|
||||||
|
if (runIndex < (fStyleRunDesc.ItemCount() - 1))
|
||||||
|
runEnd = fStyleRunDesc[runIndex + 1]->offset;
|
||||||
|
|
||||||
|
STEStyle style = fStyleRecord[runDesc.index]->style;
|
||||||
|
SetStyle(inMode, inFont, &style.font, inColor, &style.color);
|
||||||
|
|
||||||
|
styleIndex = fStyleRecord.InsertRecord(inFont, inColor);
|
||||||
|
|
||||||
|
if ( (runDesc.offset == offset) && (runIndex > 0) &&
|
||||||
|
(fStyleRunDesc[runIndex - 1]->index == styleIndex) ) {
|
||||||
|
RemoveStyles(runIndex);
|
||||||
|
runIndex--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (styleIndex != runDesc.index) {
|
||||||
|
if (offset > runDesc.offset) {
|
||||||
|
STEStyleRunDesc newDesc;
|
||||||
|
newDesc.offset = offset;
|
||||||
|
newDesc.index = styleIndex;
|
||||||
|
fStyleRunDesc.InsertDesc(&newDesc, runIndex + 1);
|
||||||
|
fStyleRecord.CommitRecord(newDesc.index);
|
||||||
|
runIndex++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fStyleRunDesc[runIndex]->index = styleIndex;
|
||||||
|
fStyleRecord.CommitRecord(styleIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (toOffset < runEnd) {
|
||||||
|
STEStyleRunDesc newDesc;
|
||||||
|
newDesc.offset = toOffset;
|
||||||
|
newDesc.index = runDesc.index;
|
||||||
|
fStyleRunDesc.InsertDesc(&newDesc, runIndex + 1);
|
||||||
|
fStyleRecord.CommitRecord(newDesc.index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
runIndex++;
|
||||||
|
offset = runEnd;
|
||||||
|
} while (offset < toOffset);
|
||||||
|
|
||||||
|
if ( (offset == toOffset) && (runIndex < fStyleRunDesc.ItemCount()) &&
|
||||||
|
(fStyleRunDesc[runIndex]->index == styleIndex) )
|
||||||
|
RemoveStyles(runIndex);
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
void
|
||||||
|
_BStyleBuffer_::GetStyle(int32 inOffset, BFont *outFont,
|
||||||
|
rgb_color *outColor) const
|
||||||
|
{
|
||||||
|
if (fStyleRunDesc.ItemCount() < 1)
|
||||||
|
{
|
||||||
|
if (outFont)
|
||||||
|
*outFont = fNullStyle.font;
|
||||||
|
if (outColor)
|
||||||
|
*outColor = fNullStyle.color;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32 runIndex = OffsetToRun(inOffset);
|
||||||
|
int32 styleIndex = fStyleRunDesc[runIndex]->index;
|
||||||
|
|
||||||
|
if (outFont)
|
||||||
|
*outFont = fStyleRecord[styleIndex]->style.font;
|
||||||
|
if (outColor)
|
||||||
|
*outColor = fStyleRecord[styleIndex]->style.color;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
STEStyleRangePtr
|
||||||
|
_BStyleBuffer_::GetStyleRange(int32 startOffset,
|
||||||
|
int32 endOffset) const
|
||||||
|
{
|
||||||
|
STEStyleRangePtr result = NULL;
|
||||||
|
|
||||||
|
int32 startIndex = OffsetToRun(startOffset);
|
||||||
|
int32 endIndex = OffsetToRun(endOffset);
|
||||||
|
|
||||||
|
int32 numStyles = endIndex - startIndex + 1;
|
||||||
|
numStyles = (numStyles < 1) ? 1 : numStyles;
|
||||||
|
result = (STEStyleRangePtr)malloc(sizeof(int32) +
|
||||||
|
(sizeof(STEStyleRun) * numStyles));
|
||||||
|
|
||||||
|
result->count = numStyles;
|
||||||
|
STEStyleRunPtr run = &result->runs[0];
|
||||||
|
for (int32 index = 0; index < numStyles; index++) {
|
||||||
|
*run = (*this)[startIndex + index];
|
||||||
|
run->offset -= startOffset;
|
||||||
|
run->offset = (run->offset < 0) ? 0 : run->offset;
|
||||||
|
run++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
void
|
||||||
|
_BStyleBuffer_::RemoveStyleRange(int32 fromOffset, int32 toOffset)
|
||||||
|
{
|
||||||
|
int32 fromIndex = fStyleRunDesc.OffsetToRun(fromOffset);
|
||||||
|
int32 toIndex = fStyleRunDesc.OffsetToRun(toOffset) - 1;
|
||||||
|
|
||||||
|
int32 count = toIndex - fromIndex;
|
||||||
|
if (count > 0) {
|
||||||
|
RemoveStyles(fromIndex + 1, count);
|
||||||
|
toIndex = fromIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
fStyleRunDesc.BumpOffset(fromOffset - toOffset, fromIndex + 1);
|
||||||
|
|
||||||
|
if ((toIndex == fromIndex) && (toIndex < (fStyleRunDesc.ItemCount() - 1))) {
|
||||||
|
STEStyleRunDescPtr runDesc = fStyleRunDesc[toIndex + 1];
|
||||||
|
runDesc->offset = fromOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fromIndex < (fStyleRunDesc.ItemCount() - 1)) {
|
||||||
|
STEStyleRunDescPtr runDesc = fStyleRunDesc[fromIndex];
|
||||||
|
if (runDesc->offset == (runDesc + 1)->offset) {
|
||||||
|
RemoveStyles(fromIndex);
|
||||||
|
fromIndex--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((fromIndex >= 0) && (fromIndex < (fStyleRunDesc.ItemCount() - 1))) {
|
||||||
|
STEStyleRunDescPtr runDesc = fStyleRunDesc[fromIndex];
|
||||||
|
if (runDesc->index == (runDesc + 1)->index)
|
||||||
|
RemoveStyles(fromIndex + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
void
|
||||||
|
_BStyleBuffer_::RemoveStyles(int32 index, int32 count)
|
||||||
|
{
|
||||||
|
for (int32 i = index; i < (index + count); i++)
|
||||||
|
fStyleRecord.RemoveRecord(fStyleRunDesc[i]->index);
|
||||||
|
|
||||||
|
fStyleRunDesc.RemoveDescs(index, count);
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
int32
|
||||||
|
_BStyleBuffer_::Iterate(int32 fromOffset, int32 length, /*_BInlineInput_ *,*/
|
||||||
|
const BFont **outFont, const rgb_color **outColor,
|
||||||
|
float *outAscent, float *outDescent, uint32 *) const
|
||||||
|
{
|
||||||
|
int32 numRuns = fStyleRunDesc.ItemCount();
|
||||||
|
if ((length < 1) || (numRuns < 1))
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
int32 result = length;
|
||||||
|
int32 runIndex = fStyleRunDesc.OffsetToRun(fromOffset);
|
||||||
|
STEStyleRunDescPtr run = fStyleRunDesc[runIndex];
|
||||||
|
|
||||||
|
if (outFont != NULL)
|
||||||
|
*outFont = &fStyleRecord[run->index]->style.font;
|
||||||
|
if (outColor != NULL)
|
||||||
|
*outColor = &fStyleRecord[run->index]->style.color;
|
||||||
|
if (outAscent != NULL)
|
||||||
|
*outAscent = fStyleRecord[run->index]->ascent;
|
||||||
|
if (outDescent != NULL)
|
||||||
|
*outDescent = fStyleRecord[run->index]->descent;
|
||||||
|
|
||||||
|
if (runIndex < (numRuns - 1)) {
|
||||||
|
int32 nextOffset = (run + 1)->offset - fromOffset;
|
||||||
|
result = (result > nextOffset) ? nextOffset : result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
int32
|
||||||
|
_BStyleBuffer_::OffsetToRun(int32 offset) const
|
||||||
|
{
|
||||||
|
return fStyleRunDesc.OffsetToRun(offset);
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
void
|
||||||
|
_BStyleBuffer_::BumpOffset(int32 delta, int32 index)
|
||||||
|
{
|
||||||
|
fStyleRunDesc.BumpOffset(delta, index);
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
void
|
||||||
|
_BStyleBuffer_::SetStyle(uint32 mode, const BFont *fromFont,
|
||||||
|
BFont *toFont, const rgb_color *fromColor,
|
||||||
|
rgb_color *toColor)
|
||||||
|
{
|
||||||
|
if (mode & doFont)
|
||||||
|
toFont->SetFamilyAndStyle(fromFont->FamilyAndStyle());
|
||||||
|
|
||||||
|
if (mode & doSize) {
|
||||||
|
if (mode & addSize)
|
||||||
|
toFont->SetSize(fromFont->Size());
|
||||||
|
else
|
||||||
|
toFont->SetSize(fromFont->Size());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode & doShear)
|
||||||
|
toFont->SetShear(fromFont->Shear());
|
||||||
|
|
||||||
|
if (mode & doUnderline)
|
||||||
|
toFont->SetFace(fromFont->Face());
|
||||||
|
|
||||||
|
if (mode & doColor)
|
||||||
|
*toColor = *fromColor;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
STEStyleRun
|
||||||
|
_BStyleBuffer_::operator[](int32 index) const
|
||||||
|
{
|
||||||
|
STEStyleRun run;
|
||||||
|
|
||||||
|
if (fStyleRunDesc.ItemCount() < 1) {
|
||||||
|
run.offset = 0;
|
||||||
|
run.style = fNullStyle;
|
||||||
|
} else {
|
||||||
|
STEStyleRunDescPtr runDesc = fStyleRunDesc[index];
|
||||||
|
STEStyleRecordPtr record = fStyleRecord[runDesc->index];
|
||||||
|
run.offset = runDesc->offset;
|
||||||
|
run.style = record->style;
|
||||||
|
}
|
||||||
|
|
||||||
|
return run;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/*void _BStyleBuffer_::ContinuousGetStyle(BFont *, uint32 *, rgb_color *, bool *,
|
||||||
|
int32, int32) const
|
||||||
{
|
{
|
||||||
}*/
|
}*/
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
STEStyleRecord *_BStyleBuffer_::operator[](int32 index)
|
|
||||||
{
|
|
||||||
if (index < fRecords.fCount)
|
|
||||||
return fRecords.fItems + index;
|
|
||||||
else
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* $Log $
|
* $Log $
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Copyright (c) 2001-2002, OpenBeOS
|
// Copyright (c) 2001-2003, OpenBeOS
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
// copy of this software and associated documentation files (the "Software"),
|
// copy of this software and associated documentation files (the "Software"),
|
||||||
@@ -29,67 +29,171 @@
|
|||||||
// System Includes -------------------------------------------------------------
|
// System Includes -------------------------------------------------------------
|
||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
#include <InterfaceDefs.h>
|
#include <InterfaceDefs.h>
|
||||||
|
#include "TextViewSupportBuffer.h"
|
||||||
#include <Font.h>
|
#include <Font.h>
|
||||||
|
|
||||||
// Project Includes ------------------------------------------------------------
|
// Project Includes ------------------------------------------------------------
|
||||||
|
|
||||||
// Local Includes --------------------------------------------------------------
|
// Local Includes --------------------------------------------------------------
|
||||||
#include "TextViewSupportBuffer.h"
|
|
||||||
|
|
||||||
// Local Defines ---------------------------------------------------------------
|
// Local Defines ---------------------------------------------------------------
|
||||||
struct STEStyleRunDesc {
|
enum {
|
||||||
int32 fOffset;
|
doFont = 0x00000001, // set font
|
||||||
int32 fStyle;
|
doSize = 0x00000002, // set size
|
||||||
|
doShear = 0x00000004, // set shear
|
||||||
|
doUnderline = 0x00000008, // set underline
|
||||||
|
doColor = 0x00000010, // set color
|
||||||
|
doExtra = 0x00000020, // set the extra field
|
||||||
|
doAll = 0x0000003F, // set everything
|
||||||
|
addSize = 0x00010000 // add size value
|
||||||
};
|
};
|
||||||
|
|
||||||
struct STEStyleRecord {
|
typedef struct STEStyle {
|
||||||
BFont fFont;
|
BFont font; // font
|
||||||
rgb_color fColor;
|
rgb_color color; // pen color
|
||||||
};
|
} STEStyle, *STEStylePtr;
|
||||||
|
|
||||||
|
typedef struct STEStyleRun {
|
||||||
|
long offset; // byte offset of first character of run
|
||||||
|
STEStyle style; // style info
|
||||||
|
} STEStyleRun, *STEStyleRunPtr;
|
||||||
|
|
||||||
|
typedef struct STEStyleRange {
|
||||||
|
long count; // number of style runs
|
||||||
|
STEStyleRun runs[1]; // array of count number of runs
|
||||||
|
} STEStyleRange, *STEStyleRangePtr;
|
||||||
|
|
||||||
|
typedef struct STEStyleRecord {
|
||||||
|
long refs; // reference count for this style
|
||||||
|
float ascent; // ascent for this style
|
||||||
|
float descent; // descent for this style
|
||||||
|
STEStyle style; // style info
|
||||||
|
} STEStyleRecord, *STEStyleRecordPtr;
|
||||||
|
|
||||||
|
typedef struct STEStyleRunDesc {
|
||||||
|
long offset; // byte offset of first character of run
|
||||||
|
long index; // index of corresponding style record
|
||||||
|
} STEStyleRunDesc, *STEStyleRunDescPtr;
|
||||||
|
|
||||||
// Globals ---------------------------------------------------------------------
|
// Globals ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
// _BStyleRunDescBuffer_ class -------------------------------------------------
|
||||||
|
class _BStyleRunDescBuffer_ : public _BTextViewSupportBuffer_<STEStyleRunDesc> {
|
||||||
|
|
||||||
|
public:
|
||||||
|
_BStyleRunDescBuffer_();
|
||||||
|
|
||||||
|
void InsertDesc(STEStyleRunDescPtr inDesc, int32 index);
|
||||||
|
void RemoveDescs(int32 index, int32 count = 1);
|
||||||
|
|
||||||
|
long OffsetToRun(int32 offset) const;
|
||||||
|
void BumpOffset(int32 delta, int32 index);
|
||||||
|
|
||||||
|
const STEStyleRunDescPtr operator[](int32 index) const;
|
||||||
|
};
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
inline const
|
||||||
|
STEStyleRunDescPtr _BStyleRunDescBuffer_::operator[](int32 index) const
|
||||||
|
{
|
||||||
|
return &fBuffer[index];
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// _BStyleRecordBuffer_ class --------------------------------------------------
|
||||||
|
class _BStyleRecordBuffer_ : public _BTextViewSupportBuffer_<STEStyleRecord> {
|
||||||
|
|
||||||
|
public:
|
||||||
|
_BStyleRecordBuffer_();
|
||||||
|
|
||||||
|
int32 InsertRecord(const BFont *inFont, const rgb_color *inColor);
|
||||||
|
void CommitRecord(int32 index);
|
||||||
|
void RemoveRecord(int32 index);
|
||||||
|
|
||||||
|
bool MatchRecord(const BFont *inFont, const rgb_color *inColor,
|
||||||
|
int32 *outIndex);
|
||||||
|
|
||||||
|
const STEStyleRecordPtr operator[](int32 index) const;
|
||||||
|
};
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
inline const
|
||||||
|
STEStyleRecordPtr _BStyleRecordBuffer_::operator[](int32 index) const
|
||||||
|
{
|
||||||
|
return &fBuffer[index];
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
// _BStyleBuffer_ class --------------------------------------------------------
|
// _BStyleBuffer_ class --------------------------------------------------------
|
||||||
class _BStyleBuffer_ {
|
class _BStyleBuffer_ {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
_BStyleBuffer_(const BFont *, const rgb_color *);
|
_BStyleBuffer_(const BFont *inFont,
|
||||||
virtual ~_BStyleBuffer_();
|
const rgb_color *inColor);
|
||||||
|
|
||||||
void SetNullStyle(uint32, const BFont *, const rgb_color *, int32);
|
void InvalidateNullStyle();
|
||||||
void GetNullStyle(const BFont **, const rgb_color **) const;
|
bool IsValidNullStyle() const;
|
||||||
void SyncNullStyle(int32);
|
|
||||||
void InvalidateNullStyle();
|
|
||||||
bool IsValidNullStyle() const;
|
|
||||||
|
|
||||||
void SetStyle(uint32, const BFont *, BFont *, const rgb_color *,
|
void SyncNullStyle(int32 offset);
|
||||||
rgb_color *) const;
|
void SetNullStyle(uint32 inMode, const BFont *inFont,
|
||||||
void GetStyle(uint32, BFont *, rgb_color *) const;
|
const rgb_color *inColor, int32 offset = 0);
|
||||||
|
void GetNullStyle(const BFont **font,
|
||||||
|
const rgb_color **color) const;
|
||||||
|
|
||||||
void SetStyleRange(int32, int32, int32, uint32 mode, const BFont *,
|
bool IsContinuousStyle(uint32 *ioMode, STEStylePtr outStyle,
|
||||||
const rgb_color *);
|
int32 fromOffset, int32 toOffset);
|
||||||
int32 GetStyleRange(int32, int32) const;
|
void SetStyleRange(int32 fromOffset, int32 toOffset,
|
||||||
|
int32 textLen, uint32 inMode,
|
||||||
|
const BFont *inFont, const rgb_color *inColor);
|
||||||
|
void GetStyle(int32 inOffset, BFont *outFont,
|
||||||
|
rgb_color *outColor) const;
|
||||||
|
STEStyleRangePtr GetStyleRange(int32 startOffset, int32 endOffset) const;
|
||||||
|
|
||||||
void ContinuousGetStyle(BFont *, uint32 *, rgb_color *, bool *,
|
void RemoveStyleRange(int32 fromOffset, int32 toOffset);
|
||||||
int32, int32) const;
|
void RemoveStyles(int32 index, int32 count = 1);
|
||||||
|
|
||||||
void RemoveStyles(int32 from, int32 to);
|
int32 Iterate(int32 fromOffset, int32 length, /*_BInlineInput_ *,*/
|
||||||
void RemoveStyleRange(int32 from, int32 to);
|
const BFont **outFont = NULL,
|
||||||
|
const rgb_color **outColor = NULL,
|
||||||
|
float *outAscent = NULL,
|
||||||
|
float *outDescen = NULL, uint32 * = NULL) const;
|
||||||
|
|
||||||
int32 OffsetToRun(int32 offset) const;
|
int32 OffsetToRun(int32 offset) const;
|
||||||
|
void BumpOffset(int32 delta, int32 index);
|
||||||
|
|
||||||
void BumpOffset(int32 run, int32 offset);
|
void SetStyle(uint32 mode, const BFont *fromFont,
|
||||||
// void Iterate(int32, int32, _BInlineInput_ *, const BFont **,
|
BFont *toFont, const rgb_color *fromColor,
|
||||||
// const rgb_color **, float *, uint32 *) const;
|
rgb_color *toColor);
|
||||||
|
|
||||||
STEStyleRecord *operator[](int32);
|
STEStyleRun operator[](int32 index) const;
|
||||||
|
|
||||||
private:
|
int32 NumRuns() const;
|
||||||
_BTextViewSupportBuffer_<STEStyleRunDesc> fRuns;
|
const _BStyleRunDescBuffer_& RunBuffer() const;
|
||||||
_BTextViewSupportBuffer_<STEStyleRecord> fRecords;
|
const _BStyleRecordBuffer_& RecordBuffer() const;
|
||||||
STEStyleRecord fNullStyle;
|
|
||||||
|
protected:
|
||||||
|
_BStyleRunDescBuffer_ fStyleRunDesc;
|
||||||
|
_BStyleRecordBuffer_ fStyleRecord;
|
||||||
|
bool fValidNullStyle;
|
||||||
|
STEStyle fNullStyle;
|
||||||
};
|
};
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
inline int32
|
||||||
|
_BStyleBuffer_::NumRuns() const
|
||||||
|
{
|
||||||
|
return fStyleRunDesc.ItemCount();
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
inline const
|
||||||
|
_BStyleRunDescBuffer_ &_BStyleBuffer_::RunBuffer() const
|
||||||
|
{
|
||||||
|
return fStyleRunDesc;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
inline const
|
||||||
|
_BStyleRecordBuffer_ &_BStyleBuffer_::RecordBuffer() const
|
||||||
|
{
|
||||||
|
return fStyleRecord;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* $Log $
|
* $Log $
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Copyright (c) 2001-2002, OpenBeOS
|
// Copyright (c) 2001-2003, OpenBeOS
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
// copy of this software and associated documentation files (the "Software"),
|
// copy of this software and associated documentation files (the "Software"),
|
||||||
@@ -25,14 +25,15 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Standard Includes -----------------------------------------------------------
|
// Standard Includes -----------------------------------------------------------
|
||||||
#include <string.h>
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
// System Includes -------------------------------------------------------------
|
// System Includes -------------------------------------------------------------
|
||||||
|
#include "TextGapBuffer.h"
|
||||||
|
|
||||||
// Project Includes ------------------------------------------------------------
|
// Project Includes ------------------------------------------------------------
|
||||||
|
|
||||||
// Local Includes --------------------------------------------------------------
|
// Local Includes --------------------------------------------------------------
|
||||||
#include "TextGapBuffer.h"
|
|
||||||
|
|
||||||
// Local Defines ---------------------------------------------------------------
|
// Local Defines ---------------------------------------------------------------
|
||||||
|
|
||||||
@@ -40,95 +41,180 @@
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
_BTextGapBuffer_::_BTextGapBuffer_()
|
_BTextGapBuffer_::_BTextGapBuffer_()
|
||||||
: fText(NULL),
|
: fExtraCount(2048),
|
||||||
fLogicalBytes(0),
|
fItemCount(0),
|
||||||
fPhysicalBytes(2048)
|
fBuffer(NULL),
|
||||||
|
fBufferCount(fExtraCount + fItemCount),
|
||||||
|
fGapIndex(fItemCount),
|
||||||
|
fGapCount(fBufferCount - fGapIndex),
|
||||||
|
fScratchBuffer(NULL),
|
||||||
|
fScratchSize(0)
|
||||||
{
|
{
|
||||||
fText = new char[fPhysicalBytes];
|
fBuffer = (char *)malloc(fExtraCount + fItemCount);
|
||||||
*fText = '\0';
|
fScratchBuffer = (char*)malloc(0);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
_BTextGapBuffer_::~_BTextGapBuffer_()
|
_BTextGapBuffer_::~_BTextGapBuffer_()
|
||||||
{
|
{
|
||||||
delete[] fText;
|
free(fBuffer);
|
||||||
|
free(fScratchBuffer);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void _BTextGapBuffer_::InsertText(const char *text, int32 length, int32 offset)
|
void
|
||||||
|
_BTextGapBuffer_::InsertText(const char *inText, int32 inNumItems,
|
||||||
|
int32 inAtIndex)
|
||||||
{
|
{
|
||||||
// If needed, resize buffer
|
if (inNumItems < 1)
|
||||||
if (fPhysicalBytes < fLogicalBytes + length + 1)
|
return;
|
||||||
Resize(fLogicalBytes + length + 1);
|
|
||||||
|
|
||||||
// Move text after insertion point
|
inAtIndex = (inAtIndex > fItemCount) ? fItemCount : inAtIndex;
|
||||||
memcpy(fText + offset + length, fText + offset,
|
inAtIndex = (inAtIndex < 0) ? 0 : inAtIndex;
|
||||||
fLogicalBytes + 1 - offset);
|
|
||||||
|
|
||||||
// Copy new text
|
if (inAtIndex != fGapIndex)
|
||||||
memcpy(fText + offset, text, length);
|
MoveGapTo(inAtIndex);
|
||||||
|
|
||||||
// Update used bytes
|
if (fGapCount < inNumItems)
|
||||||
fLogicalBytes += length;
|
SizeGapTo(inNumItems + fExtraCount);
|
||||||
|
|
||||||
|
memcpy(fBuffer + fGapIndex, inText, inNumItems);
|
||||||
|
|
||||||
|
fGapCount -= inNumItems;
|
||||||
|
fGapIndex += inNumItems;
|
||||||
|
fItemCount += inNumItems;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void _BTextGapBuffer_::RemoveRange(int32 from, int32 to)
|
void
|
||||||
|
_BTextGapBuffer_::RemoveRange(int32 start, int32 end)
|
||||||
{
|
{
|
||||||
// Move text after deletion point
|
long inAtIndex = start;
|
||||||
memcpy(fText + from, fText + to, fLogicalBytes + 1 - to);
|
long inNumItems = end - start;
|
||||||
|
|
||||||
// Update used bytes
|
if (inNumItems < 1)
|
||||||
fLogicalBytes -= to - from;
|
return;
|
||||||
|
|
||||||
|
inAtIndex = (inAtIndex > fItemCount - 1) ? (fItemCount - 1) : inAtIndex;
|
||||||
|
inAtIndex = (inAtIndex < 0) ? 0 : inAtIndex;
|
||||||
|
|
||||||
|
MoveGapTo(inAtIndex);
|
||||||
|
|
||||||
|
fGapCount += inNumItems;
|
||||||
|
fItemCount -= inNumItems;
|
||||||
|
|
||||||
|
if (fGapCount > fExtraCount)
|
||||||
|
SizeGapTo(fExtraCount);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
char *_BTextGapBuffer_::Text()
|
void
|
||||||
|
_BTextGapBuffer_::MoveGapTo(int32 toIndex)
|
||||||
{
|
{
|
||||||
if (fLogicalBytes == 0 || fText[fLogicalBytes - 1] != '\0')
|
if (toIndex == fGapIndex)
|
||||||
{
|
return;
|
||||||
if (fPhysicalBytes < fLogicalBytes + 1)
|
|
||||||
{
|
|
||||||
char *new_text = new char[fLogicalBytes + 1];
|
|
||||||
|
|
||||||
if (fText)
|
long gapEndIndex = fGapIndex + fGapCount;
|
||||||
{
|
long srcIndex = 0;
|
||||||
memcpy(new_text, fText, fLogicalBytes );
|
long dstIndex = 0;
|
||||||
delete fText;
|
long count = 0;
|
||||||
}
|
if (toIndex > fGapIndex) {
|
||||||
|
long trailGapCount = fBufferCount - gapEndIndex;
|
||||||
fText = new_text;
|
srcIndex = toIndex + (gapEndIndex - toIndex);
|
||||||
}
|
dstIndex = fGapIndex;
|
||||||
|
count = fGapCount + (toIndex - srcIndex);
|
||||||
fText[fLogicalBytes] = '\0';
|
count = (count > trailGapCount) ? trailGapCount : count;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
srcIndex = toIndex;
|
||||||
|
dstIndex = toIndex + (gapEndIndex - fGapIndex);
|
||||||
|
count = gapEndIndex - dstIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fText;
|
if (count > 0)
|
||||||
}
|
memmove(fBuffer + dstIndex, fBuffer + srcIndex, count);
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
char *_BTextGapBuffer_::RealText()
|
|
||||||
{
|
|
||||||
return fText;
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
char _BTextGapBuffer_::RealCharAt(int32 offset) const
|
|
||||||
{
|
|
||||||
return *(fText + offset);
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void _BTextGapBuffer_::Resize(int32 size)
|
|
||||||
{
|
|
||||||
if (fPhysicalBytes < size)
|
|
||||||
{
|
|
||||||
char *text = new char[size];
|
|
||||||
|
|
||||||
if (fText)
|
fGapIndex = toIndex;
|
||||||
{
|
}
|
||||||
memcpy(text, fText, fLogicalBytes);
|
//------------------------------------------------------------------------------
|
||||||
delete fText;
|
void
|
||||||
|
_BTextGapBuffer_::SizeGapTo(long inCount)
|
||||||
|
{
|
||||||
|
if (inCount == fGapCount)
|
||||||
|
return;
|
||||||
|
|
||||||
|
fBuffer = (char *)realloc(fBuffer, fItemCount + inCount);
|
||||||
|
memmove(fBuffer + fGapIndex + inCount,
|
||||||
|
fBuffer + fGapIndex + fGapCount,
|
||||||
|
fBufferCount - (fGapIndex + fGapCount));
|
||||||
|
|
||||||
|
fGapCount = inCount;
|
||||||
|
fBufferCount = fItemCount + fGapCount;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
const char *
|
||||||
|
_BTextGapBuffer_::GetString(int32 fromOffset, int32 numChars)
|
||||||
|
{
|
||||||
|
char *result = "";
|
||||||
|
|
||||||
|
if (numChars < 1)
|
||||||
|
return (result);
|
||||||
|
|
||||||
|
bool isStartBeforeGap = (fromOffset < fGapIndex);
|
||||||
|
bool isEndBeforeGap = ((fromOffset + numChars - 1) < fGapIndex);
|
||||||
|
|
||||||
|
if (isStartBeforeGap == isEndBeforeGap) {
|
||||||
|
result = fBuffer + fromOffset;
|
||||||
|
if (!isStartBeforeGap)
|
||||||
|
result += fGapCount;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (fScratchSize < numChars) {
|
||||||
|
fScratchBuffer = (char *)realloc(fScratchBuffer, numChars);
|
||||||
|
fScratchSize = numChars;
|
||||||
}
|
}
|
||||||
|
|
||||||
fText = text;
|
for (long i = 0; i < numChars; i++)
|
||||||
fPhysicalBytes = size;
|
fScratchBuffer[i] = (*this)[fromOffset + i];
|
||||||
|
|
||||||
|
result = fScratchBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
bool
|
||||||
|
_BTextGapBuffer_::FindChar(char inChar, long fromIndex, long *ioDelta)
|
||||||
|
{
|
||||||
|
long numChars = *ioDelta;
|
||||||
|
for (long i = 0; i < numChars; i++) {
|
||||||
|
if (((*this)[fromIndex + i] & 0xc0) == 0x80)
|
||||||
|
continue;
|
||||||
|
if ((*this)[fromIndex + i] == inChar) {
|
||||||
|
*ioDelta = i;
|
||||||
|
return (true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
const char *
|
||||||
|
_BTextGapBuffer_::Text()
|
||||||
|
{
|
||||||
|
MoveGapTo(fItemCount);
|
||||||
|
fBuffer[fItemCount] = '\0';
|
||||||
|
|
||||||
|
return fBuffer;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/*char *_BTextGapBuffer_::RealText()
|
||||||
|
{
|
||||||
|
return fText;
|
||||||
|
}*/
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/*char
|
||||||
|
_BTextGapBuffer_::RealCharAt(int32 offset) const
|
||||||
|
{
|
||||||
|
return *(fBuffer + offset);
|
||||||
|
}*/
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* $Log $
|
* $Log $
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Copyright (c) 2001-2002, OpenBeOS
|
// Copyright (c) 2001-2003, OpenBeOS
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
// copy of this software and associated documentation files (the "Software"),
|
// copy of this software and associated documentation files (the "Software"),
|
||||||
@@ -41,34 +41,57 @@
|
|||||||
class _BTextGapBuffer_ {
|
class _BTextGapBuffer_ {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
_BTextGapBuffer_();
|
_BTextGapBuffer_();
|
||||||
virtual ~_BTextGapBuffer_();
|
virtual ~_BTextGapBuffer_();
|
||||||
|
|
||||||
void InsertText(const char *text, int32 length, int32 offset);
|
void InsertText(const char *inText, int32 inNumItems, int32 inAtIndex);
|
||||||
void RemoveRange(int32 from, int32 to);
|
void RemoveRange(int32 start, int32 end);
|
||||||
|
|
||||||
char *Text();
|
void MoveGapTo(int32 toIndex);
|
||||||
char *RealText();
|
void SizeGapTo(int32 inCount);
|
||||||
void GetString(int32 offset, int32 length, char *buffer);
|
|
||||||
void GetString(int32, int32 *);
|
|
||||||
|
|
||||||
char RealCharAt(int32 offset) const;
|
const char *GetString(int32 fromOffset, int32 numChars);
|
||||||
bool FindChar(char c, int32 inOffset, int32 *outOffset);
|
bool FindChar(char inChar, int32 fromIndex, int32 *ioDelta);
|
||||||
|
|
||||||
void SizeGapTo(int32);
|
const char *Text();
|
||||||
void MoveGapTo(int32);
|
int32 Length() const;
|
||||||
void InsertText(BFile *, int32, int32, int32);
|
char operator[](int32 index) const;
|
||||||
bool PasswordMode() const;
|
|
||||||
void SetPasswordMode(bool);
|
|
||||||
|
|
||||||
void Resize(int32 size);
|
|
||||||
|
|
||||||
char *fText;
|
// char *RealText();
|
||||||
int32 fLogicalBytes;
|
// void GetString(int32 offset, int32 length, char *buffer);
|
||||||
int32 fPhysicalBytes;
|
// void GetString(int32, int32 *);
|
||||||
|
|
||||||
|
// char RealCharAt(int32 offset) const;
|
||||||
|
|
||||||
|
// void InsertText(BFile *, int32, int32, int32);
|
||||||
|
// bool PasswordMode() const;
|
||||||
|
// void SetPasswordMode(bool);
|
||||||
|
|
||||||
|
// void Resize(int32 size);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int32 fExtraCount; // when realloc()-ing
|
||||||
|
int32 fItemCount; // logical count
|
||||||
|
char *fBuffer; // allocated memory
|
||||||
|
int32 fBufferCount; // physical count
|
||||||
|
int32 fGapIndex; // gap position
|
||||||
|
int32 fGapCount; // gap count
|
||||||
|
char *fScratchBuffer; // for GetString
|
||||||
|
int32 fScratchSize; // scratch size
|
||||||
};
|
};
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
inline int32
|
||||||
|
_BTextGapBuffer_::Length() const
|
||||||
|
{
|
||||||
|
return fItemCount;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
inline char
|
||||||
|
_BTextGapBuffer_::operator[](long index) const
|
||||||
|
{
|
||||||
|
return (index < fGapIndex) ? fBuffer[index] : fBuffer[index + fGapCount];
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* $Log $
|
* $Log $
|
||||||
*
|
*
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Copyright (c) 2001-2002, OpenBeOS
|
// Copyright (c) 2001-2003, OpenBeOS
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
// copy of this software and associated documentation files (the "Software"),
|
// copy of this software and associated documentation files (the "Software"),
|
||||||
@@ -25,8 +25,12 @@
|
|||||||
// buffer classes.
|
// buffer classes.
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef __TEXT_VIEW_SUPPORT_BUFFER__H__
|
||||||
|
#define __TEXT_VIEW_SUPPORT_BUFFER__H__
|
||||||
|
|
||||||
// Standard Includes -----------------------------------------------------------
|
// Standard Includes -----------------------------------------------------------
|
||||||
#include <malloc.h>
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
// System Includes -------------------------------------------------------------
|
// System Includes -------------------------------------------------------------
|
||||||
#include "SupportDefs.h"
|
#include "SupportDefs.h"
|
||||||
@@ -44,57 +48,99 @@ template <class T>
|
|||||||
class _BTextViewSupportBuffer_ {
|
class _BTextViewSupportBuffer_ {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
_BTextViewSupportBuffer_(int32 count, int32 blockSize);
|
_BTextViewSupportBuffer_(long inExtraCount = 0,
|
||||||
|
long inCount = 0);
|
||||||
virtual ~_BTextViewSupportBuffer_();
|
virtual ~_BTextViewSupportBuffer_();
|
||||||
|
|
||||||
void InsertItemsAt(int32 offset, int32 count, const T *items);
|
void InsertItemsAt(int32 inNumItems, int32 inAtIndex, const T *inItem);
|
||||||
void RemoveItemsAt(int32 offset, int32 count);
|
void RemoveItemsAt(int32 inNumItems, int32 inAtIndex);
|
||||||
|
|
||||||
int32 fBlockSize;
|
int32 ItemCount() const;
|
||||||
int32 fCount;
|
|
||||||
int32 fPhysicalSize;
|
//protected:
|
||||||
T *fItems;
|
int32 fExtraCount;
|
||||||
int32 fReserved;
|
int32 fItemCount;
|
||||||
|
T* fBuffer;
|
||||||
|
int32 fBufferCount;
|
||||||
};
|
};
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
template <class T>
|
template <class T>
|
||||||
_BTextViewSupportBuffer_<T>::_BTextViewSupportBuffer_(int32 count, int32 blockSize)
|
_BTextViewSupportBuffer_<T>::_BTextViewSupportBuffer_(long inExtraCount,
|
||||||
:
|
long inCount)
|
||||||
fBlockSize(blockSize),
|
: fExtraCount(inExtraCount),
|
||||||
fCount(count),
|
fItemCount(inCount),
|
||||||
fPhysicalSize(count + blockSize),
|
fBuffer(NULL),
|
||||||
fItems(NULL)
|
fBufferCount(fExtraCount + fItemCount)
|
||||||
{
|
{
|
||||||
fItems = (T*)malloc(fPhysicalSize * sizeof(T));
|
fBuffer = (T *)calloc(fExtraCount + fItemCount, sizeof(T));
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
template <class T>
|
template <class T>
|
||||||
_BTextViewSupportBuffer_<T>::~_BTextViewSupportBuffer_()
|
_BTextViewSupportBuffer_<T>::~_BTextViewSupportBuffer_()
|
||||||
{
|
{
|
||||||
free(fItems);
|
free(fBuffer);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
template <class T>
|
template <class T>
|
||||||
void _BTextViewSupportBuffer_<T>::InsertItemsAt(int32 offset, int32 count,
|
void _BTextViewSupportBuffer_<T>::InsertItemsAt(int32 inNumItems,
|
||||||
const T *items)
|
int32 inAtIndex,
|
||||||
|
const T *inItem)
|
||||||
{
|
{
|
||||||
if (fPhysicalSize < fCount + count)
|
if (inNumItems < 1)
|
||||||
{
|
return;
|
||||||
int32 new_size = (((fCount + count) / fBlockSize) + 1) * fBlockSize;
|
|
||||||
|
|
||||||
fItems = realloc(fItems, new_size);
|
inAtIndex = (inAtIndex > fItemCount) ? fItemCount : inAtIndex;
|
||||||
|
inAtIndex = (inAtIndex < 0) ? 0 : inAtIndex;
|
||||||
|
|
||||||
|
long delta = inNumItems * sizeof(T);
|
||||||
|
long logSize = fItemCount * sizeof(T);
|
||||||
|
if ((logSize + delta) >= fBufferCount) {
|
||||||
|
fBufferCount = logSize + delta + (fExtraCount * sizeof(T));
|
||||||
|
fBuffer = (T *)realloc(fBuffer, fBufferCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(fItems + offset, items, count);
|
T *loc = fBuffer + inAtIndex;
|
||||||
fCount += count;
|
memmove(loc + inNumItems, loc, (fItemCount - inAtIndex) * sizeof(T));
|
||||||
|
memcpy(loc, inItem, delta);
|
||||||
|
|
||||||
|
fItemCount += inNumItems;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
template <class T>
|
template <class T>
|
||||||
void _BTextViewSupportBuffer_<T>::RemoveItemsAt(int32 offset, int32 count)
|
void
|
||||||
|
_BTextViewSupportBuffer_<T>::RemoveItemsAt(int32 inNumItems,
|
||||||
|
int32 inAtIndex)
|
||||||
{
|
{
|
||||||
|
if (inNumItems < 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
inAtIndex = (inAtIndex > fItemCount - 1) ? (fItemCount - 1) : inAtIndex;
|
||||||
|
inAtIndex = (inAtIndex < 0) ? 0 : inAtIndex;
|
||||||
|
|
||||||
|
T *loc = fBuffer + inAtIndex;
|
||||||
|
memmove(loc, loc + inNumItems,
|
||||||
|
(fItemCount - (inNumItems + inAtIndex)) * sizeof(T));
|
||||||
|
|
||||||
|
long delta = inNumItems * sizeof(T);
|
||||||
|
long logSize = fItemCount * sizeof(T);
|
||||||
|
long extraSize = fBufferCount - (logSize - delta);
|
||||||
|
if (extraSize > (fExtraCount * sizeof(T))) {
|
||||||
|
fBufferCount = (logSize - delta) + (fExtraCount * sizeof(T));
|
||||||
|
fBuffer = (T *)realloc(fBuffer, fBufferCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
fItemCount -= inNumItems;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
template<class T>
|
||||||
|
inline int32
|
||||||
|
_BTextViewSupportBuffer_<T>::ItemCount() const
|
||||||
|
{
|
||||||
|
return fItemCount;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#endif // __TEXT_VIEW_SUPPORT_BUFFER__H__
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* $Log $
|
* $Log $
|
||||||
|
|||||||
Reference in New Issue
Block a user