some changes, improved double buffered mode, it still has some problems, though

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17374 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini 2006-05-08 20:13:35 +00:00
parent 07cc05136f
commit 5a5960830d

View File

@ -309,8 +309,7 @@ BTextView::Instantiate(BMessage *archive)
CALLED(); CALLED();
if (validate_instantiation(archive, "BTextView")) if (validate_instantiation(archive, "BTextView"))
return new BTextView(archive); return new BTextView(archive);
else return NULL;
return NULL;
} }
@ -324,36 +323,50 @@ BTextView::Archive(BMessage *data, bool deep) const
{ {
CALLED(); CALLED();
status_t err = BView::Archive(data, deep); status_t err = BView::Archive(data, deep);
if (err == B_OK)
err = data->AddString("_text", Text());
if (err == B_OK)
err = data->AddInt32("_align", fAlignment);
if (err == B_OK)
err = data->AddFloat("_tab", fTabWidth);
if (err == B_OK)
err = data->AddInt32("_col_sp", fColorSpace);
if (err == B_OK)
err = data->AddRect("_trect", fTextRect);
if (err == B_OK)
err = data->AddInt32("_max", fMaxBytes);
if (err == B_OK)
err = data->AddInt32("_sel", fSelStart);
if (err == B_OK)
err = data->AddInt32("_sel", fSelEnd);
if (err == B_OK)
err = data->AddBool("_stylable", fStylable);
if (err == B_OK)
err = data->AddBool("_auto_in", fAutoindent);
if (err == B_OK)
err = data->AddBool("_wrap", fWrap);
if (err == B_OK)
err = data->AddBool("_nsel", !fSelectable);
if (err == B_OK)
err = data->AddBool("_nedit", !fEditable);
data->AddString("_text", Text()); if (err == B_OK && fDisallowedChars != NULL)
data->AddInt32("_align", fAlignment); err = data->AddData("_dis_ch", B_RAW_TYPE, fDisallowedChars->Items(),
data->AddFloat("_tab", fTabWidth);
data->AddInt32("_col_sp", fColorSpace);
data->AddRect("_trect", fTextRect);
data->AddInt32("_max", fMaxBytes);
data->AddInt32("_sel", fSelStart);
data->AddInt32("_sel", fSelEnd);
data->AddBool("_stylable", fStylable);
data->AddBool("_auto_in", fAutoindent);
data->AddBool("_wrap", fWrap);
data->AddBool("_nsel", !fSelectable);
data->AddBool("_nedit", !fEditable);
if (fDisallowedChars != NULL)
data->AddData("_dis_ch", B_RAW_TYPE, fDisallowedChars->Items(),
fDisallowedChars->CountItems() * sizeof(int32)); fDisallowedChars->CountItems() * sizeof(int32));
int32 runSize = 0; if (err == B_OK) {
text_run_array *runArray = RunArray(0, TextLength()); int32 runSize = 0;
text_run_array *runArray = RunArray(0, TextLength());
void *flattened = FlattenRunArray(runArray, &runSize); void *flattened = FlattenRunArray(runArray, &runSize);
if (flattened != NULL) { if (flattened != NULL) {
data->AddData("_runs", B_RAW_TYPE, flattened, runSize); data->AddData("_runs", B_RAW_TYPE, flattened, runSize);
free(flattened); free(flattened);
} else } else
err = B_NO_MEMORY; err = B_NO_MEMORY;
FreeRunArray(runArray); FreeRunArray(runArray);
}
return err; return err;
} }
@ -385,10 +398,7 @@ BTextView::AttachedToWindow()
UpdateScrollbars(); UpdateScrollbars();
if (!fCursor) SetViewCursor(B_CURSOR_SYSTEM_DEFAULT);
SetViewCursor(B_CURSOR_I_BEAM);
else
SetViewCursor(B_CURSOR_SYSTEM_DEFAULT);
} }
@ -606,7 +616,6 @@ BTextView::MouseDown(BPoint where)
void void
BTextView::MouseUp(BPoint where) BTextView::MouseUp(BPoint where)
{ {
CALLED();
PerformMouseUp(where); PerformMouseUp(where);
} }
@ -786,9 +795,7 @@ BTextView::Pulse()
void void
BTextView::FrameResized(float width, float height) BTextView::FrameResized(float width, float height)
{ {
CALLED();
BView::FrameResized(width, height); BView::FrameResized(width, height);
UpdateScrollbars(); UpdateScrollbars();
} }
@ -801,7 +808,6 @@ BTextView::FrameResized(float width, float height)
void void
BTextView::MakeFocus(bool focusState) BTextView::MakeFocus(bool focusState)
{ {
CALLED();
BView::MakeFocus(focusState); BView::MakeFocus(focusState);
if (focusState && Window() && Window()->IsActive()) { if (focusState && Window() && Window()->IsActive()) {
@ -821,7 +827,7 @@ void
BTextView::MessageReceived(BMessage *message) BTextView::MessageReceived(BMessage *message)
{ {
// TODO: block input if not editable (Andrew) // TODO: block input if not editable (Andrew)
CALLED();
// was this message dropped? // was this message dropped?
if (message->WasDropped()) { if (message->WasDropped()) {
BPoint dropOffset; BPoint dropOffset;
@ -980,13 +986,10 @@ BTextView::ResolveSpecifier(BMessage *message, int32 index,
status_t status_t
BTextView::GetSupportedSuites(BMessage *data) BTextView::GetSupportedSuites(BMessage *data)
{ {
CALLED();
status_t err;
if (data == NULL) if (data == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
err = data->AddString("suites", "suite/vnd.Be-text-view"); status_t err = data->AddString("suites", "suite/vnd.Be-text-view");
if (err < B_OK) if (err < B_OK)
return err; return err;
@ -1097,7 +1100,6 @@ BTextView::SetText(BFile *inFile, int32 inOffset, int32 inLength,
void void
BTextView::Insert(const char *inText, const text_run_array *inRuns) BTextView::Insert(const char *inText, const text_run_array *inRuns)
{ {
CALLED();
Insert(fSelStart, inText, strlen(inText), inRuns); Insert(fSelStart, inText, strlen(inText), inRuns);
} }
@ -1106,7 +1108,6 @@ void
BTextView::Insert(const char *inText, int32 inLength, BTextView::Insert(const char *inText, int32 inLength,
const text_run_array *inRuns) const text_run_array *inRuns)
{ {
CALLED();
Insert(fSelStart, inText, inLength, inRuns); Insert(fSelStart, inText, inLength, inRuns);
} }
@ -1144,7 +1145,6 @@ BTextView::Insert(int32 startOffset, const char *inText, int32 inLength,
void void
BTextView::Delete() BTextView::Delete()
{ {
CALLED();
Delete(fSelStart, fSelEnd); Delete(fSelStart, fSelEnd);
} }
@ -1275,7 +1275,6 @@ BTextView::GoToLine(int32 index)
void void
BTextView::Cut(BClipboard *clipboard) BTextView::Cut(BClipboard *clipboard)
{ {
CALLED();
CancelInputMethod(); CancelInputMethod();
if (fUndo) { if (fUndo) {
delete fUndo; delete fUndo;
@ -1292,8 +1291,6 @@ BTextView::Cut(BClipboard *clipboard)
void void
BTextView::Copy(BClipboard *clipboard) BTextView::Copy(BClipboard *clipboard)
{ {
CALLED();
CancelInputMethod(); CancelInputMethod();
if (clipboard->Lock()) { if (clipboard->Lock()) {
@ -1364,8 +1361,6 @@ BTextView::Paste(BClipboard *clipboard)
void void
BTextView::Clear() BTextView::Clear()
{ {
CALLED();
// We always check for fUndo != NULL (not only here), // We always check for fUndo != NULL (not only here),
// because when fUndo is NULL, undo is deactivated. // because when fUndo is NULL, undo is deactivated.
if (fUndo) { if (fUndo) {
@ -1380,7 +1375,6 @@ BTextView::Clear()
bool bool
BTextView::AcceptsPaste(BClipboard *clipboard) BTextView::AcceptsPaste(BClipboard *clipboard)
{ {
CALLED();
bool result = false; bool result = false;
if (fEditable && clipboard && clipboard->Lock()) { if (fEditable && clipboard && clipboard->Lock()) {
@ -1396,7 +1390,6 @@ BTextView::AcceptsPaste(BClipboard *clipboard)
bool bool
BTextView::AcceptsDrop(const BMessage *inMessage) BTextView::AcceptsDrop(const BMessage *inMessage)
{ {
CALLED();
if (fEditable && inMessage && inMessage->HasData("text/plain", B_MIME_TYPE)) if (fEditable && inMessage && inMessage->HasData("text/plain", B_MIME_TYPE))
return true; return true;
@ -1482,7 +1475,6 @@ BTextView::Select(int32 startOffset, int32 endOffset)
void void
BTextView::SelectAll() BTextView::SelectAll()
{ {
CALLED();
Select(0, fText->Length()); Select(0, fText->Length());
} }
@ -1494,7 +1486,6 @@ BTextView::SelectAll()
void void
BTextView::GetSelection(int32 *outStart, int32 *outEnd) const BTextView::GetSelection(int32 *outStart, int32 *outEnd) const
{ {
CALLED();
int32 start = 0, end = 0; int32 start = 0, end = 0;
if (fSelectable) { if (fSelectable) {
@ -1552,7 +1543,6 @@ BTextView::SetFontAndColor(int32 startOffset, int32 endOffset, const BFont* font
void void
BTextView::GetFontAndColor(int32 inOffset, BFont *outFont, rgb_color *outColor) const BTextView::GetFontAndColor(int32 inOffset, BFont *outFont, rgb_color *outColor) const
{ {
CALLED();
fStyles->GetStyle(inOffset, outFont, outColor); fStyles->GetStyle(inOffset, outFont, outColor);
} }
@ -1560,7 +1550,6 @@ BTextView::GetFontAndColor(int32 inOffset, BFont *outFont, rgb_color *outColor)
void void
BTextView::GetFontAndColor(BFont *outFont, uint32 *outMode, rgb_color *outColor, bool *outEqColor) const BTextView::GetFontAndColor(BFont *outFont, uint32 *outMode, rgb_color *outColor, bool *outEqColor) const
{ {
CALLED();
fStyles->ContinuousGetStyle(outFont, outMode, outColor, outEqColor, fSelStart, fSelEnd); fStyles->ContinuousGetStyle(outFont, outMode, outColor, outEqColor, fSelStart, fSelEnd);
} }
@ -2192,7 +2181,6 @@ BTextView::IsEditable() const
void void
BTextView::SetWordWrap(bool wrap) BTextView::SetWordWrap(bool wrap)
{ {
CALLED();
if (wrap == fWrap) if (wrap == fWrap)
return; return;
@ -2266,7 +2254,6 @@ BTextView::MaxBytes() const
void void
BTextView::DisallowChar(uint32 aChar) BTextView::DisallowChar(uint32 aChar)
{ {
CALLED();
if (fDisallowedChars == NULL) if (fDisallowedChars == NULL)
fDisallowedChars = new BList; fDisallowedChars = new BList;
if (!fDisallowedChars->HasItem(reinterpret_cast<void *>(aChar))) if (!fDisallowedChars->HasItem(reinterpret_cast<void *>(aChar)))
@ -2280,7 +2267,6 @@ BTextView::DisallowChar(uint32 aChar)
void void
BTextView::AllowChar(uint32 aChar) BTextView::AllowChar(uint32 aChar)
{ {
CALLED();
if (fDisallowedChars != NULL) if (fDisallowedChars != NULL)
fDisallowedChars->RemoveItem(reinterpret_cast<void *>(aChar)); fDisallowedChars->RemoveItem(reinterpret_cast<void *>(aChar));
} }
@ -2373,7 +2359,6 @@ BTextView::ColorSpace() const
void void
BTextView::MakeResizable(bool resize, BView *resizeView) BTextView::MakeResizable(bool resize, BView *resizeView)
{ {
CALLED();
if (resize) { if (resize) {
fResizable = true; fResizable = true;
fContainerView = resizeView; fContainerView = resizeView;
@ -2690,7 +2675,6 @@ BTextView::DeleteText(int32 fromOffset, int32 toOffset)
void void
BTextView::Undo(BClipboard *clipboard) BTextView::Undo(BClipboard *clipboard)
{ {
CALLED();
if (fUndo) if (fUndo)
fUndo->Undo(clipboard); fUndo->Undo(clipboard);
} }
@ -3214,7 +3198,6 @@ BTextView::Refresh(int32 fromOffset, int32 toOffset, bool erase, bool scroll)
void void
BTextView::RecalculateLineBreaks(int32 *startLine, int32 *endLine) BTextView::RecalculateLineBreaks(int32 *startLine, int32 *endLine)
{ {
CALLED();
// are we insane? // are we insane?
*startLine = (*startLine < 0) ? 0 : *startLine; *startLine = (*startLine < 0) ? 0 : *startLine;
*endLine = (*endLine > fLines->NumLines() - 1) ? fLines->NumLines() - 1 : *endLine; *endLine = (*endLine > fLines->NumLines() - 1) ? fLines->NumLines() - 1 : *endLine;
@ -3289,7 +3272,6 @@ BTextView::RecalculateLineBreaks(int32 *startLine, int32 *endLine)
int32 int32
BTextView::FindLineBreak(int32 fromOffset, float *outAscent, float *outDescent, float *ioWidth) BTextView::FindLineBreak(int32 fromOffset, float *outAscent, float *outDescent, float *ioWidth)
{ {
CALLED();
*outAscent = 0.0; *outAscent = 0.0;
*outDescent = 0.0; *outDescent = 0.0;
@ -3552,18 +3534,23 @@ BTextView::DrawLines(int32 startLine, int32 endLine, int32 startOffset, bool era
BRect clipRect = Bounds() & fTextRect; BRect clipRect = Bounds() & fTextRect;
clipRect.InsetBy(-1, -1); clipRect.InsetBy(-1, -1);
BView *view = this; BRegion newClip;
if (fOffscreen && fOffscreen->Lock()) { newClip.Set(clipRect);
view = fOffscreen->ChildAt(0); ConstrainClippingRegion(&newClip);
} else {
BRegion newClip;
newClip.Set(clipRect);
ConstrainClippingRegion(&newClip);
}
// set the low color to the view color so that // set the low color to the view color so that
// drawing to a non-white background will work // drawing to a non-white background will work
view->SetLowColor(view->ViewColor()); SetLowColor(ViewColor());
BView *view = NULL;
if (fOffscreen == NULL)
view = this;
else {
fOffscreen->Lock();
view = fOffscreen->ChildAt(0);
view->SetLowColor(ViewColor());
view->FillRect(view->Bounds(), B_SOLID_LOW);
}
long maxLine = fLines->NumLines() - 1; long maxLine = fLines->NumLines() - 1;
startLine = (startLine < 0) ? 0 : startLine; startLine = (startLine < 0) ? 0 : startLine;
@ -3603,6 +3590,7 @@ BTextView::DrawLines(int32 startLine, int32 endLine, int32 startOffset, bool era
GetTextRegion(fInline->Offset(), fInline->Offset() + fInline->Length(), &inputRegion); GetTextRegion(fInline->Offset(), fInline->Offset() + fInline->Length(), &inputRegion);
float startLeft = fTextRect.left; float startLeft = fTextRect.left;
BPoint leftTop(startLeft, line->origin);
for (long i = startLine; i <= endLine; i++) { for (long i = startLine; i <= endLine; i++) {
long length = (line + 1)->offset - line->offset; long length = (line + 1)->offset - line->offset;
// DrawString() chokes if you draw a newline // DrawString() chokes if you draw a newline
@ -3712,13 +3700,15 @@ BTextView::DrawLines(int32 startLine, int32 endLine, int32 startOffset, bool era
} }
} }
if (view == this) if (fOffscreen != NULL) {
ConstrainClippingRegion(NULL);
else {
view->Sync(); view->Sync();
BPoint penLocation = view->PenLocation();
BRect drawRect(leftTop.x, leftTop.y, penLocation.x, penLocation.y);
DrawBitmap(fOffscreen, drawRect, drawRect);
fOffscreen->Unlock(); fOffscreen->Unlock();
DrawBitmap(fOffscreen, B_ORIGIN);
} }
ConstrainClippingRegion(NULL);
} }
@ -3785,7 +3775,6 @@ BTextView::DragCaret(int32 offset)
void void
BTextView::StopMouseTracking() BTextView::StopMouseTracking()
{ {
CALLED();
delete fTrackingMouse; delete fTrackingMouse;
fTrackingMouse = NULL; fTrackingMouse = NULL;
@ -3800,7 +3789,6 @@ BTextView::StopMouseTracking()
bool bool
BTextView::PerformMouseUp(BPoint where) BTextView::PerformMouseUp(BPoint where)
{ {
CALLED();
if (fClickRunner == NULL) if (fClickRunner == NULL)
return false; return false;
@ -3815,7 +3803,6 @@ BTextView::PerformMouseUp(BPoint where)
bool bool
BTextView::PerformMouseMoved(BPoint where, uint32 code) BTextView::PerformMouseMoved(BPoint where, uint32 code)
{ {
CALLED();
if (fClickRunner == NULL) if (fClickRunner == NULL)
return false; return false;
@ -3885,7 +3872,6 @@ BTextView::TrackDrag(BPoint where)
void void
BTextView::InitiateDrag() BTextView::InitiateDrag()
{ {
CALLED();
BMessage *message = new BMessage(B_MIME_DATA); BMessage *message = new BMessage(B_MIME_DATA);
BBitmap *dragBitmap = NULL; BBitmap *dragBitmap = NULL;
BPoint bitmapPoint; BPoint bitmapPoint;
@ -3918,7 +3904,6 @@ BTextView::InitiateDrag()
bool bool
BTextView::MessageDropped(BMessage *inMessage, BPoint where, BPoint offset) BTextView::MessageDropped(BMessage *inMessage, BPoint where, BPoint offset)
{ {
CALLED();
ASSERT(inMessage); ASSERT(inMessage);
void *from = NULL; void *from = NULL;
@ -4088,7 +4073,6 @@ BTextView::DeleteOffscreen()
void void
BTextView::Activate() BTextView::Activate()
{ {
CALLED();
fActive = true; fActive = true;
// Create a new offscreen BBitmap // Create a new offscreen BBitmap
@ -4106,7 +4090,7 @@ BTextView::Activate()
ulong buttons; ulong buttons;
GetMouse(&where, &buttons, false); GetMouse(&where, &buttons, false);
if (Bounds().Contains(where)) if (Bounds().Contains(where))
SetViewCursor(B_CURSOR_I_BEAM); TrackMouse(where, NULL);
} }
@ -4115,7 +4099,6 @@ BTextView::Activate()
void void
BTextView::Deactivate() BTextView::Deactivate()
{ {
CALLED();
fActive = false; fActive = false;
CancelInputMethod(); CancelInputMethod();
@ -4311,9 +4294,9 @@ BTextView::CountProperties(BMessage *specifier, int32 form, const char *property
reply->AddInt32("result", TextLength()); reply->AddInt32("result", TextLength());
reply->AddInt32("error", B_OK); reply->AddInt32("error", B_OK);
return true; return true;
}
} else return false;
return false;
} }