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:
parent
e3a2e77198
commit
895207da06
@ -29,11 +29,12 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
// System Includes -------------------------------------------------------------
|
// System Includes -------------------------------------------------------------
|
||||||
#include "TextGapBuffer.h"
|
#include <File.h>
|
||||||
|
|
||||||
// Project Includes ------------------------------------------------------------
|
// Project Includes ------------------------------------------------------------
|
||||||
|
|
||||||
// Local Includes --------------------------------------------------------------
|
// Local Includes --------------------------------------------------------------
|
||||||
|
#include "TextGapBuffer.h"
|
||||||
|
|
||||||
// Local Defines ---------------------------------------------------------------
|
// Local Defines ---------------------------------------------------------------
|
||||||
|
|
||||||
@ -84,6 +85,41 @@ _BTextGapBuffer_::InsertText(const char *inText, int32 inNumItems,
|
|||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void
|
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)
|
_BTextGapBuffer_::RemoveRange(int32 start, int32 end)
|
||||||
{
|
{
|
||||||
long inAtIndex = start;
|
long inAtIndex = start;
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
|
|
||||||
// Globals ---------------------------------------------------------------------
|
// Globals ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
class BFile;
|
||||||
// _BTextGapBuffer_ class ------------------------------------------------------
|
// _BTextGapBuffer_ class ------------------------------------------------------
|
||||||
class _BTextGapBuffer_ {
|
class _BTextGapBuffer_ {
|
||||||
|
|
||||||
@ -47,6 +48,7 @@ public:
|
|||||||
virtual ~_BTextGapBuffer_();
|
virtual ~_BTextGapBuffer_();
|
||||||
|
|
||||||
void InsertText(const char *inText, int32 inNumItems, int32 inAtIndex);
|
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 RemoveRange(int32 start, int32 end);
|
||||||
|
|
||||||
void MoveGapTo(int32 toIndex);
|
void MoveGapTo(int32 toIndex);
|
||||||
|
@ -951,11 +951,42 @@ BTextView::SetText(const char *inText, int32 inLength,
|
|||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void
|
void
|
||||||
BTextView::SetText(BFile *inFile, int32 startOffset, int32 inLength,
|
BTextView::SetText(BFile *inFile, int32 inOffset, int32 inLength,
|
||||||
const text_run_array *inRuns)
|
const text_run_array *inRuns)
|
||||||
{
|
{
|
||||||
CALLED();
|
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
|
void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user