- Fixed crash during unarchiving, caused by the use of the wrong variable (thanks to Bill Hayden for reporting), and added a check which would have avoided the crash.

- Style changes to StyleBuffer.cpp plus a small fix in ContinuousGetStyle().


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8723 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini 2004-08-30 09:02:31 +00:00
parent 2d2e1091d5
commit 74dca7b4f4
2 changed files with 80 additions and 72 deletions

View File

@ -1,5 +1,5 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Copyright (c) 2001-2003, OpenBeOS // Copyright (c) 2001-2004, Haiku, Inc.
// //
// 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"),
@ -20,42 +20,36 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
// File Name: StyleBuffer.cpp // File Name: StyleBuffer.cpp
// Author: Marc Flerackers (mflerackers@androme.be) // Authors: Marc Flerackers (mflerackers@androme.be)
// Stefano Ceccherini (burton666@libero.it)
// Description: Style storage used by BTextView // Description: Style storage used by BTextView
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Standard Includes -----------------------------------------------------------
// System Includes -------------------------------------------------------------
#include "InlineInput.h" #include "InlineInput.h"
#include "StyleBuffer.h" #include "StyleBuffer.h"
// Project Includes ------------------------------------------------------------
// Local Includes -------------------------------------------------------------- // _BStyleRunDescBuffer_
// Local Defines ---------------------------------------------------------------
// Globals ---------------------------------------------------------------------
//------------------------------------------------------------------------------
_BStyleRunDescBuffer_::_BStyleRunDescBuffer_() _BStyleRunDescBuffer_::_BStyleRunDescBuffer_()
: _BTextViewSupportBuffer_<STEStyleRunDesc>(20) : _BTextViewSupportBuffer_<STEStyleRunDesc>(20)
{ {
} }
//------------------------------------------------------------------------------
void void
_BStyleRunDescBuffer_::InsertDesc(STEStyleRunDescPtr inDesc, int32 index) _BStyleRunDescBuffer_::InsertDesc(STEStyleRunDescPtr inDesc, int32 index)
{ {
InsertItemsAt(1, index, inDesc); InsertItemsAt(1, index, inDesc);
} }
//------------------------------------------------------------------------------
void void
_BStyleRunDescBuffer_::RemoveDescs(int32 index, int32 count) _BStyleRunDescBuffer_::RemoveDescs(int32 index, int32 count)
{ {
RemoveItemsAt(count, index); RemoveItemsAt(count, index);
} }
//------------------------------------------------------------------------------
int32 int32
_BStyleRunDescBuffer_::OffsetToRun(int32 offset) const _BStyleRunDescBuffer_::OffsetToRun(int32 offset) const
{ {
@ -85,19 +79,24 @@ _BStyleRunDescBuffer_::OffsetToRun(int32 offset) const
return index; return index;
} }
//------------------------------------------------------------------------------
void void
_BStyleRunDescBuffer_::BumpOffset(int32 delta, int32 index) _BStyleRunDescBuffer_::BumpOffset(int32 delta, int32 index)
{ {
for (int32 i = index; i < fItemCount; i++) for (int32 i = index; i < fItemCount; i++)
fBuffer[i].offset += delta; fBuffer[i].offset += delta;
} }
//------------------------------------------------------------------------------
// _BStyleRecordBuffer_
_BStyleRecordBuffer_::_BStyleRecordBuffer_() _BStyleRecordBuffer_::_BStyleRecordBuffer_()
: _BTextViewSupportBuffer_<STEStyleRecord>() : _BTextViewSupportBuffer_<STEStyleRecord>()
{ {
} }
//------------------------------------------------------------------------------
int32 int32
_BStyleRecordBuffer_::InsertRecord(const BFont *inFont, _BStyleRecordBuffer_::InsertRecord(const BFont *inFont,
const rgb_color *inColor) const rgb_color *inColor)
@ -136,21 +135,24 @@ _BStyleRecordBuffer_::InsertRecord(const BFont *inFont,
return index; return index;
} }
//------------------------------------------------------------------------------
void void
_BStyleRecordBuffer_::CommitRecord( _BStyleRecordBuffer_::CommitRecord(
int32 index) int32 index)
{ {
fBuffer[index].refs++; fBuffer[index].refs++;
} }
//------------------------------------------------------------------------------
void void
_BStyleRecordBuffer_::RemoveRecord( _BStyleRecordBuffer_::RemoveRecord(
int32 index) int32 index)
{ {
fBuffer[index].refs--; fBuffer[index].refs--;
} }
//------------------------------------------------------------------------------
bool bool
_BStyleRecordBuffer_::MatchRecord(const BFont *inFont, _BStyleRecordBuffer_::MatchRecord(const BFont *inFont,
const rgb_color *inColor, int32 *outIndex) const rgb_color *inColor, int32 *outIndex)
@ -170,26 +172,31 @@ _BStyleRecordBuffer_::MatchRecord(const BFont *inFont,
return false; return false;
} }
//------------------------------------------------------------------------------
// _BStyleBuffer_
_BStyleBuffer_::_BStyleBuffer_(const BFont *inFont, const rgb_color *inColor) _BStyleBuffer_::_BStyleBuffer_(const BFont *inFont, const rgb_color *inColor)
{ {
fValidNullStyle = true; fValidNullStyle = true;
fNullStyle.font = *inFont; fNullStyle.font = *inFont;
fNullStyle.color = *inColor; fNullStyle.color = *inColor;
} }
//------------------------------------------------------------------------------
void void
_BStyleBuffer_::InvalidateNullStyle() _BStyleBuffer_::InvalidateNullStyle()
{ {
fValidNullStyle = false; fValidNullStyle = false;
} }
//------------------------------------------------------------------------------
bool bool
_BStyleBuffer_::IsValidNullStyle() const _BStyleBuffer_::IsValidNullStyle() const
{ {
return fValidNullStyle; return fValidNullStyle;
} }
//------------------------------------------------------------------------------
void void
_BStyleBuffer_::SyncNullStyle(int32 offset) _BStyleBuffer_::SyncNullStyle(int32 offset)
{ {
@ -201,7 +208,8 @@ _BStyleBuffer_::SyncNullStyle(int32 offset)
fValidNullStyle = true; fValidNullStyle = true;
} }
//------------------------------------------------------------------------------
void void
_BStyleBuffer_::SetNullStyle(uint32 inMode, const BFont *inFont, _BStyleBuffer_::SetNullStyle(uint32 inMode, const BFont *inFont,
const rgb_color *inColor, int32 offset) const rgb_color *inColor, int32 offset)
@ -216,7 +224,8 @@ _BStyleBuffer_::SetNullStyle(uint32 inMode, const BFont *inFont,
fValidNullStyle = true; fValidNullStyle = true;
} }
//------------------------------------------------------------------------------
void void
_BStyleBuffer_::GetNullStyle(const BFont **font, _BStyleBuffer_::GetNullStyle(const BFont **font,
const rgb_color **color) const const rgb_color **color) const
@ -226,7 +235,8 @@ _BStyleBuffer_::GetNullStyle(const BFont **font,
if (color) if (color)
*color = &fNullStyle.color; *color = &fNullStyle.color;
} }
//------------------------------------------------------------------------------
void void
_BStyleBuffer_::SetStyleRange(int32 fromOffset, int32 toOffset, _BStyleBuffer_::SetStyleRange(int32 fromOffset, int32 toOffset,
int32 textLen, uint32 inMode, int32 textLen, uint32 inMode,
@ -303,13 +313,12 @@ _BStyleBuffer_::SetStyleRange(int32 fromOffset, int32 toOffset,
(fStyleRunDesc[runIndex]->index == styleIndex) ) (fStyleRunDesc[runIndex]->index == styleIndex) )
RemoveStyles(runIndex); RemoveStyles(runIndex);
} }
//------------------------------------------------------------------------------
void void
_BStyleBuffer_::GetStyle(int32 inOffset, BFont *outFont, _BStyleBuffer_::GetStyle(int32 inOffset, BFont *outFont, rgb_color *outColor) const
rgb_color *outColor) const
{ {
if (fStyleRunDesc.ItemCount() < 1) if (fStyleRunDesc.ItemCount() < 1) {
{
if (outFont) if (outFont)
*outFont = fNullStyle.font; *outFont = fNullStyle.font;
if (outColor) if (outColor)
@ -325,10 +334,10 @@ _BStyleBuffer_::GetStyle(int32 inOffset, BFont *outFont,
if (outColor) if (outColor)
*outColor = fStyleRecord[styleIndex]->style.color; *outColor = fStyleRecord[styleIndex]->style.color;
} }
//------------------------------------------------------------------------------
STEStyleRangePtr STEStyleRangePtr
_BStyleBuffer_::GetStyleRange(int32 startOffset, _BStyleBuffer_::GetStyleRange(int32 startOffset, int32 endOffset) const
int32 endOffset) const
{ {
STEStyleRangePtr result = NULL; STEStyleRangePtr result = NULL;
@ -351,7 +360,8 @@ _BStyleBuffer_::GetStyleRange(int32 startOffset,
return result; return result;
} }
//------------------------------------------------------------------------------
void void
_BStyleBuffer_::RemoveStyleRange(int32 fromOffset, int32 toOffset) _BStyleBuffer_::RemoveStyleRange(int32 fromOffset, int32 toOffset)
{ {
@ -385,7 +395,8 @@ _BStyleBuffer_::RemoveStyleRange(int32 fromOffset, int32 toOffset)
RemoveStyles(fromIndex + 1); RemoveStyles(fromIndex + 1);
} }
} }
//------------------------------------------------------------------------------
void void
_BStyleBuffer_::RemoveStyles(int32 index, int32 count) _BStyleBuffer_::RemoveStyles(int32 index, int32 count)
{ {
@ -394,7 +405,8 @@ _BStyleBuffer_::RemoveStyles(int32 index, int32 count)
fStyleRunDesc.RemoveDescs(index, count); fStyleRunDesc.RemoveDescs(index, count);
} }
//------------------------------------------------------------------------------
int32 int32
_BStyleBuffer_::Iterate(int32 fromOffset, int32 length, _BInlineInput_ *input, _BStyleBuffer_::Iterate(int32 fromOffset, int32 length, _BInlineInput_ *input,
const BFont **outFont, const rgb_color **outColor, const BFont **outFont, const rgb_color **outColor,
@ -426,19 +438,22 @@ _BStyleBuffer_::Iterate(int32 fromOffset, int32 length, _BInlineInput_ *input,
return result; return result;
} }
//------------------------------------------------------------------------------
int32 int32
_BStyleBuffer_::OffsetToRun(int32 offset) const _BStyleBuffer_::OffsetToRun(int32 offset) const
{ {
return fStyleRunDesc.OffsetToRun(offset); return fStyleRunDesc.OffsetToRun(offset);
} }
//------------------------------------------------------------------------------
void void
_BStyleBuffer_::BumpOffset(int32 delta, int32 index) _BStyleBuffer_::BumpOffset(int32 delta, int32 index)
{ {
fStyleRunDesc.BumpOffset(delta, index); fStyleRunDesc.BumpOffset(delta, index);
} }
//------------------------------------------------------------------------------
void void
_BStyleBuffer_::SetStyle(uint32 mode, const BFont *fromFont, _BStyleBuffer_::SetStyle(uint32 mode, const BFont *fromFont,
BFont *toFont, const rgb_color *fromColor, BFont *toFont, const rgb_color *fromColor,
@ -463,7 +478,8 @@ _BStyleBuffer_::SetStyle(uint32 mode, const BFont *fromFont,
if (mode & doColor) if (mode & doColor)
*toColor = *fromColor; *toColor = *fromColor;
} }
//------------------------------------------------------------------------------
STEStyleRun STEStyleRun
_BStyleBuffer_::operator[](int32 index) const _BStyleBuffer_::operator[](int32 index) const
{ {
@ -481,7 +497,8 @@ _BStyleBuffer_::operator[](int32 index) const
return run; return run;
} }
//------------------------------------------------------------------------------
void void
_BStyleBuffer_::ContinuousGetStyle(BFont *outFont, uint32 *ioMode, _BStyleBuffer_::ContinuousGetStyle(BFont *outFont, uint32 *ioMode,
rgb_color *outColor, bool *sameColor, int32 fromOffset, int32 toOffset) const rgb_color *outColor, bool *sameColor, int32 fromOffset, int32 toOffset) const
@ -502,7 +519,6 @@ _BStyleBuffer_::ContinuousGetStyle(BFont *outFont, uint32 *ioMode,
int32 fromIndex = OffsetToRun(fromOffset); int32 fromIndex = OffsetToRun(fromOffset);
int32 toIndex = OffsetToRun(toOffset - 1); int32 toIndex = OffsetToRun(toOffset - 1);
bool result = true;
if (fromIndex == toIndex) { if (fromIndex == toIndex) {
int32 styleIndex = fStyleRunDesc[fromIndex]->index; int32 styleIndex = fStyleRunDesc[fromIndex]->index;
STEStylePtr style = &fStyleRecord[styleIndex]->style; STEStylePtr style = &fStyleRecord[styleIndex]->style;
@ -517,6 +533,7 @@ _BStyleBuffer_::ContinuousGetStyle(BFont *outFont, uint32 *ioMode,
*sameColor = true; *sameColor = true;
} else { } else {
bool oneColor = true;
int32 styleIndex = fStyleRunDesc[toIndex]->index; int32 styleIndex = fStyleRunDesc[toIndex]->index;
STEStyle theStyle = fStyleRecord[styleIndex]->style; STEStyle theStyle = fStyleRecord[styleIndex]->style;
STEStylePtr style = NULL; STEStylePtr style = NULL;
@ -526,30 +543,23 @@ _BStyleBuffer_::ContinuousGetStyle(BFont *outFont, uint32 *ioMode,
style = &fStyleRecord[styleIndex]->style; style = &fStyleRecord[styleIndex]->style;
if (mode & doFont) { if (mode & doFont) {
if (theStyle.font != style->font) { if (theStyle.font != style->font)
mode &= ~doFont; mode &= ~doFont;
result = false;
}
} }
if (mode & doSize) { if (mode & doSize) {
if (theStyle.font.Size() != style->font.Size()) { if (theStyle.font.Size() != style->font.Size())
mode &= ~doSize; mode &= ~doSize;
result = false;
}
} }
if (mode & doShear) { if (mode & doShear) {
if (theStyle.font.Shear() != style->font.Shear()) { if (theStyle.font.Shear() != style->font.Shear())
mode &= ~doShear; mode &= ~doShear;
result = false;
}
} }
if (mode & doUnderline) { if (mode & doUnderline) {
// if (theStyle.underline != style->font.underline) { // if (theStyle.underline != style->font.underline) {
mode &= ~doUnderline; mode &= ~doUnderline;
// result = false;
// } // }
} }
@ -559,14 +569,13 @@ _BStyleBuffer_::ContinuousGetStyle(BFont *outFont, uint32 *ioMode,
(theStyle.color.blue != style->color.blue) || (theStyle.color.blue != style->color.blue) ||
(theStyle.color.alpha != style->color.alpha) ) { (theStyle.color.alpha != style->color.alpha) ) {
mode &= ~doColor; mode &= ~doColor;
result = false; oneColor = false;
} }
} }
if (mode & doExtra) { if (mode & doExtra) {
// if (theStyle.extra != style->font.extra) { // if (theStyle.extra != style->font.extra) {
mode &= ~doExtra; mode &= ~doExtra;
// result = false;
// } // }
} }
} }
@ -578,13 +587,6 @@ _BStyleBuffer_::ContinuousGetStyle(BFont *outFont, uint32 *ioMode,
if (outColor) if (outColor)
*outColor = theStyle.color; *outColor = theStyle.color;
if (sameColor) if (sameColor)
*sameColor = result; *sameColor = oneColor;
} }
} }
/*
* $Log $
*
* $Id $
*
*/

View File

@ -177,6 +177,8 @@ sPropertyList[] = {
}; };
/*! \brief Creates a BTextView object with the given charachteristics.
*/
BTextView::BTextView(BRect frame, const char *name, BRect textRect, BTextView::BTextView(BRect frame, const char *name, BRect textRect,
uint32 resizeMask, uint32 flags) uint32 resizeMask, uint32 flags)
: BView(frame, name, resizeMask, : BView(frame, name, resizeMask,
@ -187,6 +189,8 @@ BTextView::BTextView(BRect frame, const char *name, BRect textRect,
} }
/*! \brief Creates a BTextView object with the given charachteristics.
*/
BTextView::BTextView(BRect frame, const char *name, BRect textRect, BTextView::BTextView(BRect frame, const char *name, BRect textRect,
const BFont *initialFont, const rgb_color *initialColor, const BFont *initialFont, const rgb_color *initialColor,
uint32 resizeMask, uint32 flags) uint32 resizeMask, uint32 flags)
@ -266,12 +270,14 @@ BTextView::BTextView(BMessage *archive)
} }
ssize_t runSize = 0; ssize_t runSize = 0;
const void *flattenedRunArray = NULL; const void *flattenedRun = NULL;
if (archive->FindData("_runs", B_RAW_TYPE, &flattenedRunArray, &runSize) == B_OK) { if (archive->FindData("_runs", B_RAW_TYPE, &flattenedRun, &runSize) == B_OK) {
text_run_array *runArray = UnflattenRunArray(runArray, (int32 *)&runSize); text_run_array *runArray = UnflattenRunArray(flattenedRun, (int32 *)&runSize);
SetRunArray(0, TextLength(), runArray); if (runArray) {
free(runArray); SetRunArray(0, TextLength(), runArray);
free(runArray);
}
} }
} }
@ -4290,7 +4296,7 @@ BTextView::HandleInputMethodChanged(BMessage *message)
if (fInline->IsActive()) { if (fInline->IsActive()) {
int32 oldOffset = fInline->Offset(); int32 oldOffset = fInline->Offset();
DeleteText(oldOffset, oldOffset + fInline->Length()); DeleteText(oldOffset, oldOffset + fInline->Length());
fSelStart = fSelEnd = oldOffset; fClickOffset = fSelStart = fSelEnd = oldOffset;
} }
int32 stringLen = strlen(string); int32 stringLen = strlen(string);