Implemented BTextView::SetText(BFile *.... etc.)

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8038 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini 2004-06-18 09:51:10 +00:00
parent e3a2e77198
commit 895207da06
3 changed files with 72 additions and 3 deletions

View File

@ -29,11 +29,12 @@
#include <cstring>
// System Includes -------------------------------------------------------------
#include "TextGapBuffer.h"
#include <File.h>
// Project Includes ------------------------------------------------------------
// Local Includes --------------------------------------------------------------
#include "TextGapBuffer.h"
// Local Defines ---------------------------------------------------------------
@ -84,6 +85,41 @@ _BTextGapBuffer_::InsertText(const char *inText, int32 inNumItems,
}
//------------------------------------------------------------------------------
void
_BTextGapBuffer_::InsertText(BFile *file, int32 fileOffset, int32 inNumItems, int32 inAtIndex)
{
off_t fileSize;
if (file->GetSize(&fileSize) != B_OK
|| !file->IsReadable())
return;
// Clamp the text length to the file size
fileSize -= fileOffset;
if (fileSize < inNumItems)
inNumItems = fileSize;
if (inNumItems < 1)
return;
inAtIndex = (inAtIndex > fItemCount) ? fItemCount : inAtIndex;
inAtIndex = (inAtIndex < 0) ? 0 : inAtIndex;
if (inAtIndex != fGapIndex)
MoveGapTo(inAtIndex);
if (fGapCount < inNumItems)
SizeGapTo(inNumItems + fExtraCount);
// Finally, read the data and put it into the buffer
if (file->ReadAt(fileOffset, fBuffer + fGapIndex, inNumItems) > 0) {
fGapCount -= inNumItems;
fGapIndex += inNumItems;
fItemCount += inNumItems;
}
}
//------------------------------------------------------------------------------
void
_BTextGapBuffer_::RemoveRange(int32 start, int32 end)
{
long inAtIndex = start;

View File

@ -39,6 +39,7 @@
// Globals ---------------------------------------------------------------------
class BFile;
// _BTextGapBuffer_ class ------------------------------------------------------
class _BTextGapBuffer_ {
@ -47,6 +48,7 @@ public:
virtual ~_BTextGapBuffer_();
void InsertText(const char *inText, int32 inNumItems, int32 inAtIndex);
void InsertText(BFile *file, int32 fileOffset, int32 amount, int32 atIndex);
void RemoveRange(int32 start, int32 end);
void MoveGapTo(int32 toIndex);

View File

@ -951,11 +951,42 @@ BTextView::SetText(const char *inText, int32 inLength,
}
//------------------------------------------------------------------------------
void
BTextView::SetText(BFile *inFile, int32 startOffset, int32 inLength,
BTextView::SetText(BFile *inFile, int32 inOffset, int32 inLength,
const text_run_array *inRuns)
{
CALLED();
// TODO:
// TODO: Should probably call _DoDeleteText() here
if (fText->Length() > 0)
DeleteText(0, fText->Length());
fText->InsertText(inFile, inOffset, inLength, 0);
// update the start offsets of each line below offset
fLines->BumpOffset(inLength, LineAt(inOffset) + 1);
// update the style runs
fStyles->BumpOffset(inLength, fStyles->OffsetToRun(inOffset - 1) + 1);
if (inRuns != NULL)
//SetStyleRange(inOffset, inOffset + inLength, inStyles, false);
SetRunArray(inOffset, inOffset + inLength, inRuns);
else {
// apply nullStyle to inserted text
fStyles->SyncNullStyle(inOffset);
fStyles->SetStyleRange(inOffset, inOffset + inLength,
fText->Length(), doAll, NULL, NULL);
}
fSelStart = fSelEnd = 0;
// recalc line breaks and draw the text
Refresh(0, inLength, true, true);
// draw the caret
if (fActive) {
if (!fCaretVisible)
InvertCaret();
}
}
//------------------------------------------------------------------------------
void