unix linefeeds
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4244 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
2a0650c030
commit
9fdfaac6f3
@ -1,135 +1,135 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, OpenBeOS
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: LineBuffer.cpp
|
||||
// Author: Marc Flerackers (mflerackers@androme.be)
|
||||
// Description: Line storage used by BTextView
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Standard Includes -----------------------------------------------------------
|
||||
#include <string.h>
|
||||
|
||||
// System Includes -------------------------------------------------------------
|
||||
#include "LineBuffer.h"
|
||||
|
||||
// Project Includes ------------------------------------------------------------
|
||||
|
||||
// Local Includes --------------------------------------------------------------
|
||||
|
||||
// Local Defines ---------------------------------------------------------------
|
||||
|
||||
// Globals ---------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_BLineBuffer_::_BLineBuffer_()
|
||||
: fBlockSize(20),
|
||||
fItemCount(2),
|
||||
fPhysicalSize(22),
|
||||
fObjectList(NULL)
|
||||
{
|
||||
fObjectList = new STELine[fPhysicalSize];
|
||||
|
||||
memset(fObjectList, 0, fPhysicalSize * sizeof(STELine));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
_BLineBuffer_::~_BLineBuffer_()
|
||||
{
|
||||
delete[] fObjectList;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void _BLineBuffer_::InsertLine(STELine *line, int32 index)
|
||||
{
|
||||
if (fItemCount == fPhysicalSize - 1)
|
||||
{
|
||||
STELine *new_list = new STELine[fPhysicalSize + fBlockSize];
|
||||
|
||||
memcpy(new_list, fObjectList, fPhysicalSize * sizeof(STELine));
|
||||
delete fObjectList;
|
||||
fObjectList = new_list;
|
||||
|
||||
fPhysicalSize += fBlockSize;
|
||||
}
|
||||
|
||||
if (index < fItemCount)
|
||||
memmove(fObjectList + index + 1, fObjectList + index,
|
||||
(fItemCount - index) * sizeof(STELine));
|
||||
memcpy(fObjectList + index, line, sizeof(STELine));
|
||||
|
||||
fItemCount++;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void _BLineBuffer_::RemoveLines(int32 index, int32 count)
|
||||
{
|
||||
memmove(fObjectList + index, fObjectList + index + count,
|
||||
(fItemCount - index - count) * sizeof(STELine));
|
||||
|
||||
fItemCount -= count;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void _BLineBuffer_::RemoveLineRange(int32 from, int32 to)
|
||||
{
|
||||
int32 linefrom = OffsetToLine(from);
|
||||
int32 lineto = OffsetToLine(to);
|
||||
|
||||
if (linefrom < lineto)
|
||||
RemoveLines(linefrom + 1, lineto - linefrom);
|
||||
|
||||
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;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
int32 _BLineBuffer_::PixelToLine(float height) const
|
||||
{
|
||||
for (int i = 0; i < fItemCount; i++)
|
||||
{
|
||||
if (height < fObjectList[i].fHeight)
|
||||
return i - 1;
|
||||
}
|
||||
|
||||
return fItemCount - 2;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void _BLineBuffer_::BumpOffset(int32 line, int32 offset)
|
||||
{
|
||||
for (int i = line; i < fItemCount; i++)
|
||||
fObjectList[i].fOffset += offset;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* $Log $
|
||||
*
|
||||
* $Id $
|
||||
*
|
||||
*/
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, OpenBeOS
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: LineBuffer.cpp
|
||||
// Author: Marc Flerackers (mflerackers@androme.be)
|
||||
// Description: Line storage used by BTextView
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Standard Includes -----------------------------------------------------------
|
||||
#include <string.h>
|
||||
|
||||
// System Includes -------------------------------------------------------------
|
||||
#include "LineBuffer.h"
|
||||
|
||||
// Project Includes ------------------------------------------------------------
|
||||
|
||||
// Local Includes --------------------------------------------------------------
|
||||
|
||||
// Local Defines ---------------------------------------------------------------
|
||||
|
||||
// Globals ---------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_BLineBuffer_::_BLineBuffer_()
|
||||
: fBlockSize(20),
|
||||
fItemCount(2),
|
||||
fPhysicalSize(22),
|
||||
fObjectList(NULL)
|
||||
{
|
||||
fObjectList = new STELine[fPhysicalSize];
|
||||
|
||||
memset(fObjectList, 0, fPhysicalSize * sizeof(STELine));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
_BLineBuffer_::~_BLineBuffer_()
|
||||
{
|
||||
delete[] fObjectList;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void _BLineBuffer_::InsertLine(STELine *line, int32 index)
|
||||
{
|
||||
if (fItemCount == fPhysicalSize - 1)
|
||||
{
|
||||
STELine *new_list = new STELine[fPhysicalSize + fBlockSize];
|
||||
|
||||
memcpy(new_list, fObjectList, fPhysicalSize * sizeof(STELine));
|
||||
delete fObjectList;
|
||||
fObjectList = new_list;
|
||||
|
||||
fPhysicalSize += fBlockSize;
|
||||
}
|
||||
|
||||
if (index < fItemCount)
|
||||
memmove(fObjectList + index + 1, fObjectList + index,
|
||||
(fItemCount - index) * sizeof(STELine));
|
||||
memcpy(fObjectList + index, line, sizeof(STELine));
|
||||
|
||||
fItemCount++;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void _BLineBuffer_::RemoveLines(int32 index, int32 count)
|
||||
{
|
||||
memmove(fObjectList + index, fObjectList + index + count,
|
||||
(fItemCount - index - count) * sizeof(STELine));
|
||||
|
||||
fItemCount -= count;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void _BLineBuffer_::RemoveLineRange(int32 from, int32 to)
|
||||
{
|
||||
int32 linefrom = OffsetToLine(from);
|
||||
int32 lineto = OffsetToLine(to);
|
||||
|
||||
if (linefrom < lineto)
|
||||
RemoveLines(linefrom + 1, lineto - linefrom);
|
||||
|
||||
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;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
int32 _BLineBuffer_::PixelToLine(float height) const
|
||||
{
|
||||
for (int i = 0; i < fItemCount; i++)
|
||||
{
|
||||
if (height < fObjectList[i].fHeight)
|
||||
return i - 1;
|
||||
}
|
||||
|
||||
return fItemCount - 2;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void _BLineBuffer_::BumpOffset(int32 line, int32 offset)
|
||||
{
|
||||
for (int i = line; i < fItemCount; i++)
|
||||
fObjectList[i].fOffset += offset;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* $Log $
|
||||
*
|
||||
* $Id $
|
||||
*
|
||||
*/
|
||||
|
@ -1,75 +1,75 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, OpenBeOS
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: LineBuffer.h
|
||||
// Author: Marc Flerackers (mflerackers@androme.be)
|
||||
// Description: Line storage used by BTextView
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Standard Includes -----------------------------------------------------------
|
||||
|
||||
// System Includes -------------------------------------------------------------
|
||||
#include "SupportDefs.h"
|
||||
|
||||
// Project Includes ------------------------------------------------------------
|
||||
|
||||
// Local Includes --------------------------------------------------------------
|
||||
|
||||
// Local Defines ---------------------------------------------------------------
|
||||
struct STELine {
|
||||
int32 fOffset;
|
||||
float fHeight;
|
||||
float fLineHeight;
|
||||
float fWidth;
|
||||
};
|
||||
|
||||
// Globals ---------------------------------------------------------------------
|
||||
|
||||
// _BLineBuffer_ class ---------------------------------------------------------
|
||||
class _BLineBuffer_ {
|
||||
|
||||
public:
|
||||
_BLineBuffer_();
|
||||
virtual ~_BLineBuffer_();
|
||||
|
||||
void InsertLine(STELine *line, int32);
|
||||
void RemoveLines(int32 index, int32 count);
|
||||
void RemoveLineRange(int32 from, int32 to);
|
||||
|
||||
int32 OffsetToLine(int32 offset) const;
|
||||
int32 PixelToLine(float height) const;
|
||||
|
||||
void BumpOffset(int32 line, int32 offset);
|
||||
void BumpOrigin(float, int32);
|
||||
|
||||
int32 fBlockSize;
|
||||
int32 fItemCount;
|
||||
size_t fPhysicalSize;
|
||||
STELine *fObjectList;
|
||||
};
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* $Log $
|
||||
*
|
||||
* $Id $
|
||||
*
|
||||
*/
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, OpenBeOS
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: LineBuffer.h
|
||||
// Author: Marc Flerackers (mflerackers@androme.be)
|
||||
// Description: Line storage used by BTextView
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Standard Includes -----------------------------------------------------------
|
||||
|
||||
// System Includes -------------------------------------------------------------
|
||||
#include "SupportDefs.h"
|
||||
|
||||
// Project Includes ------------------------------------------------------------
|
||||
|
||||
// Local Includes --------------------------------------------------------------
|
||||
|
||||
// Local Defines ---------------------------------------------------------------
|
||||
struct STELine {
|
||||
int32 fOffset;
|
||||
float fHeight;
|
||||
float fLineHeight;
|
||||
float fWidth;
|
||||
};
|
||||
|
||||
// Globals ---------------------------------------------------------------------
|
||||
|
||||
// _BLineBuffer_ class ---------------------------------------------------------
|
||||
class _BLineBuffer_ {
|
||||
|
||||
public:
|
||||
_BLineBuffer_();
|
||||
virtual ~_BLineBuffer_();
|
||||
|
||||
void InsertLine(STELine *line, int32);
|
||||
void RemoveLines(int32 index, int32 count);
|
||||
void RemoveLineRange(int32 from, int32 to);
|
||||
|
||||
int32 OffsetToLine(int32 offset) const;
|
||||
int32 PixelToLine(float height) const;
|
||||
|
||||
void BumpOffset(int32 line, int32 offset);
|
||||
void BumpOrigin(float, int32);
|
||||
|
||||
int32 fBlockSize;
|
||||
int32 fItemCount;
|
||||
size_t fPhysicalSize;
|
||||
STELine *fObjectList;
|
||||
};
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* $Log $
|
||||
*
|
||||
* $Id $
|
||||
*
|
||||
*/
|
||||
|
@ -1,156 +1,156 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, OpenBeOS
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: StyleBuffer.cpp
|
||||
// Author: Marc Flerackers (mflerackers@androme.be)
|
||||
// Description: Style storage used by BTextView
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Standard Includes -----------------------------------------------------------
|
||||
|
||||
// System Includes -------------------------------------------------------------
|
||||
#include "StyleBuffer.h"
|
||||
|
||||
// Project Includes ------------------------------------------------------------
|
||||
|
||||
// Local Includes --------------------------------------------------------------
|
||||
|
||||
// Local Defines ---------------------------------------------------------------
|
||||
|
||||
// Globals ---------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_BStyleBuffer_::_BStyleBuffer_(const BFont *font, const rgb_color *color)
|
||||
: fRuns(10, 10),
|
||||
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,
|
||||
const rgb_color *color, int32)
|
||||
{
|
||||
// TODO: use mode.
|
||||
if (font)
|
||||
fNullStyle.fFont = *font;
|
||||
|
||||
if (color)
|
||||
fNullStyle.fColor = *color;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void _BStyleBuffer_::GetNullStyle(const BFont **font, const rgb_color **color) const
|
||||
{
|
||||
*font = &fNullStyle.fFont;
|
||||
*color = &fNullStyle.fColor;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void _BStyleBuffer_::SyncNullStyle(int32)
|
||||
{
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
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;
|
||||
|
||||
for (int i = 0; i < fRuns.fCount; i++)
|
||||
{
|
||||
if (offset < fRuns.fItems[i].fOffset)
|
||||
return i - 1;
|
||||
}
|
||||
|
||||
return fRuns.fCount - 2;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void _BStyleBuffer_::BumpOffset(int32 run, int32 offset)
|
||||
{
|
||||
for (int i = run; i < fRuns.fCount; i++)
|
||||
fRuns.fItems[i].fOffset += offset;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
/*void _BStyleBuffer_::Iterate(int32, int32, _BInlineInput_ *, const BFont **,
|
||||
const rgb_color **, float *, uint32 *) const
|
||||
{
|
||||
}*/
|
||||
//------------------------------------------------------------------------------
|
||||
STEStyleRecord *_BStyleBuffer_::operator[](int32 index)
|
||||
{
|
||||
if (index < fRecords.fCount)
|
||||
return fRecords.fItems + index;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* $Log $
|
||||
*
|
||||
* $Id $
|
||||
*
|
||||
*/
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, OpenBeOS
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: StyleBuffer.cpp
|
||||
// Author: Marc Flerackers (mflerackers@androme.be)
|
||||
// Description: Style storage used by BTextView
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Standard Includes -----------------------------------------------------------
|
||||
|
||||
// System Includes -------------------------------------------------------------
|
||||
#include "StyleBuffer.h"
|
||||
|
||||
// Project Includes ------------------------------------------------------------
|
||||
|
||||
// Local Includes --------------------------------------------------------------
|
||||
|
||||
// Local Defines ---------------------------------------------------------------
|
||||
|
||||
// Globals ---------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_BStyleBuffer_::_BStyleBuffer_(const BFont *font, const rgb_color *color)
|
||||
: fRuns(10, 10),
|
||||
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,
|
||||
const rgb_color *color, int32)
|
||||
{
|
||||
// TODO: use mode.
|
||||
if (font)
|
||||
fNullStyle.fFont = *font;
|
||||
|
||||
if (color)
|
||||
fNullStyle.fColor = *color;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void _BStyleBuffer_::GetNullStyle(const BFont **font, const rgb_color **color) const
|
||||
{
|
||||
*font = &fNullStyle.fFont;
|
||||
*color = &fNullStyle.fColor;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void _BStyleBuffer_::SyncNullStyle(int32)
|
||||
{
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
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;
|
||||
|
||||
for (int i = 0; i < fRuns.fCount; i++)
|
||||
{
|
||||
if (offset < fRuns.fItems[i].fOffset)
|
||||
return i - 1;
|
||||
}
|
||||
|
||||
return fRuns.fCount - 2;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void _BStyleBuffer_::BumpOffset(int32 run, int32 offset)
|
||||
{
|
||||
for (int i = run; i < fRuns.fCount; i++)
|
||||
fRuns.fItems[i].fOffset += offset;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
/*void _BStyleBuffer_::Iterate(int32, int32, _BInlineInput_ *, const BFont **,
|
||||
const rgb_color **, float *, uint32 *) const
|
||||
{
|
||||
}*/
|
||||
//------------------------------------------------------------------------------
|
||||
STEStyleRecord *_BStyleBuffer_::operator[](int32 index)
|
||||
{
|
||||
if (index < fRecords.fCount)
|
||||
return fRecords.fItems + index;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* $Log $
|
||||
*
|
||||
* $Id $
|
||||
*
|
||||
*/
|
||||
|
@ -1,99 +1,99 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, OpenBeOS
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: StyleBuffer.h
|
||||
// Author: Marc Flerackers (mflerackers@androme.be)
|
||||
// Description: Style storage used by BTextView
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Standard Includes -----------------------------------------------------------
|
||||
|
||||
// System Includes -------------------------------------------------------------
|
||||
#include <SupportDefs.h>
|
||||
#include <InterfaceDefs.h>
|
||||
#include <Font.h>
|
||||
|
||||
// Project Includes ------------------------------------------------------------
|
||||
|
||||
// Local Includes --------------------------------------------------------------
|
||||
#include "TextViewSupportBuffer.h"
|
||||
|
||||
// Local Defines ---------------------------------------------------------------
|
||||
struct STEStyleRunDesc {
|
||||
int32 fOffset;
|
||||
int32 fStyle;
|
||||
};
|
||||
|
||||
struct STEStyleRecord {
|
||||
BFont fFont;
|
||||
rgb_color fColor;
|
||||
};
|
||||
|
||||
// Globals ---------------------------------------------------------------------
|
||||
|
||||
// _BStyleBuffer_ class --------------------------------------------------------
|
||||
class _BStyleBuffer_ {
|
||||
|
||||
public:
|
||||
_BStyleBuffer_(const BFont *, const rgb_color *);
|
||||
virtual ~_BStyleBuffer_();
|
||||
|
||||
void SetNullStyle(uint32, const BFont *, const rgb_color *, int32);
|
||||
void GetNullStyle(const BFont **, const rgb_color **) const;
|
||||
void SyncNullStyle(int32);
|
||||
void InvalidateNullStyle();
|
||||
bool IsValidNullStyle() const;
|
||||
|
||||
void SetStyle(uint32, const BFont *, BFont *, const rgb_color *,
|
||||
rgb_color *) const;
|
||||
void GetStyle(uint32, BFont *, rgb_color *) const;
|
||||
|
||||
void SetStyleRange(int32, int32, int32, uint32 mode, const BFont *,
|
||||
const rgb_color *);
|
||||
int32 GetStyleRange(int32, int32) const;
|
||||
|
||||
void ContinuousGetStyle(BFont *, uint32 *, rgb_color *, bool *,
|
||||
int32, int32) const;
|
||||
|
||||
void RemoveStyles(int32 from, int32 to);
|
||||
void RemoveStyleRange(int32 from, int32 to);
|
||||
|
||||
int32 OffsetToRun(int32 offset) const;
|
||||
|
||||
void BumpOffset(int32 run, int32 offset);
|
||||
// void Iterate(int32, int32, _BInlineInput_ *, const BFont **,
|
||||
// const rgb_color **, float *, uint32 *) const;
|
||||
|
||||
STEStyleRecord *operator[](int32);
|
||||
|
||||
private:
|
||||
_BTextViewSupportBuffer_<STEStyleRunDesc> fRuns;
|
||||
_BTextViewSupportBuffer_<STEStyleRecord> fRecords;
|
||||
STEStyleRecord fNullStyle;
|
||||
};
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* $Log $
|
||||
*
|
||||
* $Id $
|
||||
*
|
||||
*/
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, OpenBeOS
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: StyleBuffer.h
|
||||
// Author: Marc Flerackers (mflerackers@androme.be)
|
||||
// Description: Style storage used by BTextView
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Standard Includes -----------------------------------------------------------
|
||||
|
||||
// System Includes -------------------------------------------------------------
|
||||
#include <SupportDefs.h>
|
||||
#include <InterfaceDefs.h>
|
||||
#include <Font.h>
|
||||
|
||||
// Project Includes ------------------------------------------------------------
|
||||
|
||||
// Local Includes --------------------------------------------------------------
|
||||
#include "TextViewSupportBuffer.h"
|
||||
|
||||
// Local Defines ---------------------------------------------------------------
|
||||
struct STEStyleRunDesc {
|
||||
int32 fOffset;
|
||||
int32 fStyle;
|
||||
};
|
||||
|
||||
struct STEStyleRecord {
|
||||
BFont fFont;
|
||||
rgb_color fColor;
|
||||
};
|
||||
|
||||
// Globals ---------------------------------------------------------------------
|
||||
|
||||
// _BStyleBuffer_ class --------------------------------------------------------
|
||||
class _BStyleBuffer_ {
|
||||
|
||||
public:
|
||||
_BStyleBuffer_(const BFont *, const rgb_color *);
|
||||
virtual ~_BStyleBuffer_();
|
||||
|
||||
void SetNullStyle(uint32, const BFont *, const rgb_color *, int32);
|
||||
void GetNullStyle(const BFont **, const rgb_color **) const;
|
||||
void SyncNullStyle(int32);
|
||||
void InvalidateNullStyle();
|
||||
bool IsValidNullStyle() const;
|
||||
|
||||
void SetStyle(uint32, const BFont *, BFont *, const rgb_color *,
|
||||
rgb_color *) const;
|
||||
void GetStyle(uint32, BFont *, rgb_color *) const;
|
||||
|
||||
void SetStyleRange(int32, int32, int32, uint32 mode, const BFont *,
|
||||
const rgb_color *);
|
||||
int32 GetStyleRange(int32, int32) const;
|
||||
|
||||
void ContinuousGetStyle(BFont *, uint32 *, rgb_color *, bool *,
|
||||
int32, int32) const;
|
||||
|
||||
void RemoveStyles(int32 from, int32 to);
|
||||
void RemoveStyleRange(int32 from, int32 to);
|
||||
|
||||
int32 OffsetToRun(int32 offset) const;
|
||||
|
||||
void BumpOffset(int32 run, int32 offset);
|
||||
// void Iterate(int32, int32, _BInlineInput_ *, const BFont **,
|
||||
// const rgb_color **, float *, uint32 *) const;
|
||||
|
||||
STEStyleRecord *operator[](int32);
|
||||
|
||||
private:
|
||||
_BTextViewSupportBuffer_<STEStyleRunDesc> fRuns;
|
||||
_BTextViewSupportBuffer_<STEStyleRecord> fRecords;
|
||||
STEStyleRecord fNullStyle;
|
||||
};
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* $Log $
|
||||
*
|
||||
* $Id $
|
||||
*
|
||||
*/
|
||||
|
@ -1,138 +1,138 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, OpenBeOS
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: TextGapBuffer.cpp
|
||||
// Author: Marc Flerackers (mflerackers@androme.be)
|
||||
// Description: Text storage used by BTextView
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Standard Includes -----------------------------------------------------------
|
||||
#include <string.h>
|
||||
|
||||
// System Includes -------------------------------------------------------------
|
||||
|
||||
// Project Includes ------------------------------------------------------------
|
||||
|
||||
// Local Includes --------------------------------------------------------------
|
||||
#include "TextGapBuffer.h"
|
||||
|
||||
// Local Defines ---------------------------------------------------------------
|
||||
|
||||
// Globals ---------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_BTextGapBuffer_::_BTextGapBuffer_()
|
||||
: fText(NULL),
|
||||
fLogicalBytes(0),
|
||||
fPhysicalBytes(2048)
|
||||
{
|
||||
fText = new char[fPhysicalBytes];
|
||||
*fText = '\0';
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
_BTextGapBuffer_::~_BTextGapBuffer_()
|
||||
{
|
||||
delete[] fText;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void _BTextGapBuffer_::InsertText(const char *text, int32 length, int32 offset)
|
||||
{
|
||||
// If needed, resize buffer
|
||||
if (fPhysicalBytes < fLogicalBytes + length + 1)
|
||||
Resize(fLogicalBytes + length + 1);
|
||||
|
||||
// Move text after insertion point
|
||||
memcpy(fText + offset + length, fText + offset,
|
||||
fLogicalBytes + 1 - offset);
|
||||
|
||||
// Copy new text
|
||||
memcpy(fText + offset, text, length);
|
||||
|
||||
// Update used bytes
|
||||
fLogicalBytes += length;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void _BTextGapBuffer_::RemoveRange(int32 from, int32 to)
|
||||
{
|
||||
// Move text after deletion point
|
||||
memcpy(fText + from, fText + to, fLogicalBytes + 1 - to);
|
||||
|
||||
// Update used bytes
|
||||
fLogicalBytes -= to - from;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
char *_BTextGapBuffer_::Text()
|
||||
{
|
||||
if (fLogicalBytes == 0 || fText[fLogicalBytes - 1] != '\0')
|
||||
{
|
||||
if (fPhysicalBytes < fLogicalBytes + 1)
|
||||
{
|
||||
char *new_text = new char[fLogicalBytes + 1];
|
||||
|
||||
if (fText)
|
||||
{
|
||||
memcpy(new_text, fText, fLogicalBytes );
|
||||
delete fText;
|
||||
}
|
||||
|
||||
fText = new_text;
|
||||
}
|
||||
|
||||
fText[fLogicalBytes] = '\0';
|
||||
}
|
||||
|
||||
return fText;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
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)
|
||||
{
|
||||
memcpy(text, fText, fLogicalBytes);
|
||||
delete fText;
|
||||
}
|
||||
|
||||
fText = text;
|
||||
fPhysicalBytes = size;
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* $Log $
|
||||
*
|
||||
* $Id $
|
||||
*
|
||||
*/
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, OpenBeOS
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: TextGapBuffer.cpp
|
||||
// Author: Marc Flerackers (mflerackers@androme.be)
|
||||
// Description: Text storage used by BTextView
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Standard Includes -----------------------------------------------------------
|
||||
#include <string.h>
|
||||
|
||||
// System Includes -------------------------------------------------------------
|
||||
|
||||
// Project Includes ------------------------------------------------------------
|
||||
|
||||
// Local Includes --------------------------------------------------------------
|
||||
#include "TextGapBuffer.h"
|
||||
|
||||
// Local Defines ---------------------------------------------------------------
|
||||
|
||||
// Globals ---------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_BTextGapBuffer_::_BTextGapBuffer_()
|
||||
: fText(NULL),
|
||||
fLogicalBytes(0),
|
||||
fPhysicalBytes(2048)
|
||||
{
|
||||
fText = new char[fPhysicalBytes];
|
||||
*fText = '\0';
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
_BTextGapBuffer_::~_BTextGapBuffer_()
|
||||
{
|
||||
delete[] fText;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void _BTextGapBuffer_::InsertText(const char *text, int32 length, int32 offset)
|
||||
{
|
||||
// If needed, resize buffer
|
||||
if (fPhysicalBytes < fLogicalBytes + length + 1)
|
||||
Resize(fLogicalBytes + length + 1);
|
||||
|
||||
// Move text after insertion point
|
||||
memcpy(fText + offset + length, fText + offset,
|
||||
fLogicalBytes + 1 - offset);
|
||||
|
||||
// Copy new text
|
||||
memcpy(fText + offset, text, length);
|
||||
|
||||
// Update used bytes
|
||||
fLogicalBytes += length;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void _BTextGapBuffer_::RemoveRange(int32 from, int32 to)
|
||||
{
|
||||
// Move text after deletion point
|
||||
memcpy(fText + from, fText + to, fLogicalBytes + 1 - to);
|
||||
|
||||
// Update used bytes
|
||||
fLogicalBytes -= to - from;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
char *_BTextGapBuffer_::Text()
|
||||
{
|
||||
if (fLogicalBytes == 0 || fText[fLogicalBytes - 1] != '\0')
|
||||
{
|
||||
if (fPhysicalBytes < fLogicalBytes + 1)
|
||||
{
|
||||
char *new_text = new char[fLogicalBytes + 1];
|
||||
|
||||
if (fText)
|
||||
{
|
||||
memcpy(new_text, fText, fLogicalBytes );
|
||||
delete fText;
|
||||
}
|
||||
|
||||
fText = new_text;
|
||||
}
|
||||
|
||||
fText[fLogicalBytes] = '\0';
|
||||
}
|
||||
|
||||
return fText;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
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)
|
||||
{
|
||||
memcpy(text, fText, fLogicalBytes);
|
||||
delete fText;
|
||||
}
|
||||
|
||||
fText = text;
|
||||
fPhysicalBytes = size;
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* $Log $
|
||||
*
|
||||
* $Id $
|
||||
*
|
||||
*/
|
||||
|
@ -1,77 +1,77 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, OpenBeOS
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: TextGapBuffer.h
|
||||
// Author: Marc Flerackers (mflerackers@androme.be)
|
||||
// Description: Text storage used by BTextView
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Standard Includes -----------------------------------------------------------
|
||||
|
||||
// System Includes -------------------------------------------------------------
|
||||
#include "SupportDefs.h"
|
||||
|
||||
// Project Includes ------------------------------------------------------------
|
||||
|
||||
// Local Includes --------------------------------------------------------------
|
||||
|
||||
// Local Defines ---------------------------------------------------------------
|
||||
|
||||
// Globals ---------------------------------------------------------------------
|
||||
|
||||
// _BTextGapBuffer_ class ------------------------------------------------------
|
||||
class _BTextGapBuffer_ {
|
||||
|
||||
public:
|
||||
_BTextGapBuffer_();
|
||||
virtual ~_BTextGapBuffer_();
|
||||
|
||||
void InsertText(const char *text, int32 length, int32 offset);
|
||||
void RemoveRange(int32 from, int32 to);
|
||||
|
||||
char *Text();
|
||||
char *RealText();
|
||||
void GetString(int32 offset, int32 length, char *buffer);
|
||||
void GetString(int32, int32 *);
|
||||
|
||||
char RealCharAt(int32 offset) const;
|
||||
bool FindChar(char c, int32 inOffset, int32 *outOffset);
|
||||
|
||||
void SizeGapTo(int32);
|
||||
void MoveGapTo(int32);
|
||||
void InsertText(BFile *, int32, int32, int32);
|
||||
bool PasswordMode() const;
|
||||
void SetPasswordMode(bool);
|
||||
|
||||
void Resize(int32 size);
|
||||
|
||||
char *fText;
|
||||
int32 fLogicalBytes;
|
||||
int32 fPhysicalBytes;
|
||||
};
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* $Log $
|
||||
*
|
||||
* $Id $
|
||||
*
|
||||
*/
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, OpenBeOS
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: TextGapBuffer.h
|
||||
// Author: Marc Flerackers (mflerackers@androme.be)
|
||||
// Description: Text storage used by BTextView
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Standard Includes -----------------------------------------------------------
|
||||
|
||||
// System Includes -------------------------------------------------------------
|
||||
#include "SupportDefs.h"
|
||||
|
||||
// Project Includes ------------------------------------------------------------
|
||||
|
||||
// Local Includes --------------------------------------------------------------
|
||||
|
||||
// Local Defines ---------------------------------------------------------------
|
||||
|
||||
// Globals ---------------------------------------------------------------------
|
||||
|
||||
// _BTextGapBuffer_ class ------------------------------------------------------
|
||||
class _BTextGapBuffer_ {
|
||||
|
||||
public:
|
||||
_BTextGapBuffer_();
|
||||
virtual ~_BTextGapBuffer_();
|
||||
|
||||
void InsertText(const char *text, int32 length, int32 offset);
|
||||
void RemoveRange(int32 from, int32 to);
|
||||
|
||||
char *Text();
|
||||
char *RealText();
|
||||
void GetString(int32 offset, int32 length, char *buffer);
|
||||
void GetString(int32, int32 *);
|
||||
|
||||
char RealCharAt(int32 offset) const;
|
||||
bool FindChar(char c, int32 inOffset, int32 *outOffset);
|
||||
|
||||
void SizeGapTo(int32);
|
||||
void MoveGapTo(int32);
|
||||
void InsertText(BFile *, int32, int32, int32);
|
||||
bool PasswordMode() const;
|
||||
void SetPasswordMode(bool);
|
||||
|
||||
void Resize(int32 size);
|
||||
|
||||
char *fText;
|
||||
int32 fLogicalBytes;
|
||||
int32 fPhysicalBytes;
|
||||
};
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* $Log $
|
||||
*
|
||||
* $Id $
|
||||
*
|
||||
*/
|
||||
|
@ -1,104 +1,104 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, OpenBeOS
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: TextViewSupportBuffer.h
|
||||
// Author: Marc Flerackers (mflerackers@androme.be)
|
||||
// Description: Template class used to implement the various BTextView
|
||||
// buffer classes.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Standard Includes -----------------------------------------------------------
|
||||
#include <malloc.h>
|
||||
|
||||
// System Includes -------------------------------------------------------------
|
||||
#include "SupportDefs.h"
|
||||
|
||||
// Project Includes ------------------------------------------------------------
|
||||
|
||||
// Local Includes --------------------------------------------------------------
|
||||
|
||||
// Local Defines ---------------------------------------------------------------
|
||||
|
||||
// Globals ---------------------------------------------------------------------
|
||||
|
||||
// _BTextViewSupportBuffer_ class ----------------------------------------------
|
||||
template <class T>
|
||||
class _BTextViewSupportBuffer_ {
|
||||
|
||||
public:
|
||||
_BTextViewSupportBuffer_(int32 count, int32 blockSize);
|
||||
virtual ~_BTextViewSupportBuffer_();
|
||||
|
||||
void InsertItemsAt(int32 offset, int32 count, const T *items);
|
||||
void RemoveItemsAt(int32 offset, int32 count);
|
||||
|
||||
int32 fBlockSize;
|
||||
int32 fCount;
|
||||
int32 fPhysicalSize;
|
||||
T *fItems;
|
||||
int32 fReserved;
|
||||
};
|
||||
//------------------------------------------------------------------------------
|
||||
template <class T>
|
||||
_BTextViewSupportBuffer_<T>::_BTextViewSupportBuffer_(int32 count, int32 blockSize)
|
||||
:
|
||||
fBlockSize(blockSize),
|
||||
fCount(count),
|
||||
fPhysicalSize(count + blockSize),
|
||||
fItems(NULL)
|
||||
{
|
||||
fItems = (T*)malloc(fPhysicalSize * sizeof(T));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
template <class T>
|
||||
_BTextViewSupportBuffer_<T>::~_BTextViewSupportBuffer_()
|
||||
{
|
||||
free(fItems);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
template <class T>
|
||||
void _BTextViewSupportBuffer_<T>::InsertItemsAt(int32 offset, int32 count,
|
||||
const T *items)
|
||||
{
|
||||
if (fPhysicalSize < fCount + count)
|
||||
{
|
||||
int32 new_size = (((fCount + count) / fBlockSize) + 1) * fBlockSize;
|
||||
|
||||
fItems = realloc(fItems, new_size);
|
||||
}
|
||||
|
||||
memcpy(fItems + offset, items, count);
|
||||
fCount += count;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
template <class T>
|
||||
void _BTextViewSupportBuffer_<T>::RemoveItemsAt(int32 offset, int32 count)
|
||||
{
|
||||
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* $Log $
|
||||
*
|
||||
* $Id $
|
||||
*
|
||||
*/
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, OpenBeOS
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: TextViewSupportBuffer.h
|
||||
// Author: Marc Flerackers (mflerackers@androme.be)
|
||||
// Description: Template class used to implement the various BTextView
|
||||
// buffer classes.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Standard Includes -----------------------------------------------------------
|
||||
#include <malloc.h>
|
||||
|
||||
// System Includes -------------------------------------------------------------
|
||||
#include "SupportDefs.h"
|
||||
|
||||
// Project Includes ------------------------------------------------------------
|
||||
|
||||
// Local Includes --------------------------------------------------------------
|
||||
|
||||
// Local Defines ---------------------------------------------------------------
|
||||
|
||||
// Globals ---------------------------------------------------------------------
|
||||
|
||||
// _BTextViewSupportBuffer_ class ----------------------------------------------
|
||||
template <class T>
|
||||
class _BTextViewSupportBuffer_ {
|
||||
|
||||
public:
|
||||
_BTextViewSupportBuffer_(int32 count, int32 blockSize);
|
||||
virtual ~_BTextViewSupportBuffer_();
|
||||
|
||||
void InsertItemsAt(int32 offset, int32 count, const T *items);
|
||||
void RemoveItemsAt(int32 offset, int32 count);
|
||||
|
||||
int32 fBlockSize;
|
||||
int32 fCount;
|
||||
int32 fPhysicalSize;
|
||||
T *fItems;
|
||||
int32 fReserved;
|
||||
};
|
||||
//------------------------------------------------------------------------------
|
||||
template <class T>
|
||||
_BTextViewSupportBuffer_<T>::_BTextViewSupportBuffer_(int32 count, int32 blockSize)
|
||||
:
|
||||
fBlockSize(blockSize),
|
||||
fCount(count),
|
||||
fPhysicalSize(count + blockSize),
|
||||
fItems(NULL)
|
||||
{
|
||||
fItems = (T*)malloc(fPhysicalSize * sizeof(T));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
template <class T>
|
||||
_BTextViewSupportBuffer_<T>::~_BTextViewSupportBuffer_()
|
||||
{
|
||||
free(fItems);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
template <class T>
|
||||
void _BTextViewSupportBuffer_<T>::InsertItemsAt(int32 offset, int32 count,
|
||||
const T *items)
|
||||
{
|
||||
if (fPhysicalSize < fCount + count)
|
||||
{
|
||||
int32 new_size = (((fCount + count) / fBlockSize) + 1) * fBlockSize;
|
||||
|
||||
fItems = realloc(fItems, new_size);
|
||||
}
|
||||
|
||||
memcpy(fItems + offset, items, count);
|
||||
fCount += count;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
template <class T>
|
||||
void _BTextViewSupportBuffer_<T>::RemoveItemsAt(int32 offset, int32 count)
|
||||
{
|
||||
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* $Log $
|
||||
*
|
||||
* $Id $
|
||||
*
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user