Exemplo n.º 1
0
STEStyleRange*
BTextView::StyleBuffer::GetStyleRange(int32 startOffset, int32 endOffset) const
{
	int32 startIndex = OffsetToRun(startOffset);
	int32 endIndex = OffsetToRun(endOffset);

	int32 numStyles = endIndex - startIndex + 1;
	if (numStyles < 1)
		numStyles = 1;

	STEStyleRange* result = AllocateStyleRange(numStyles);
	if (!result)
		return NULL;

	STEStyleRun* run = &result->runs[0];
	for (int32 index = 0; index < numStyles; index++) {
		*run = (*this)[startIndex + index];
		run->offset -= startOffset;
		if (run->offset < 0)
			run->offset = 0;
		run++;
	}

	return result;
}
Exemplo n.º 2
0
STEStyleRangePtr
_BStyleBuffer_::GetStyleRange(int32 startOffset, int32 endOffset) const
{
	STEStyleRangePtr result = NULL;
	
	int32 startIndex = OffsetToRun(startOffset);
	int32 endIndex = OffsetToRun(endOffset);
	
	int32 numStyles = endIndex - startIndex + 1;
	numStyles = (numStyles < 1) ? 1 : numStyles;
	result = (STEStyleRangePtr)malloc(sizeof(int32) +
									  (sizeof(STEStyleRun) * numStyles));

	if (!result)
		return NULL;
		
	result->count = numStyles;
	STEStyleRunPtr run = &result->runs[0];
	for (int32 index = 0; index < numStyles; index++) {
		*run = (*this)[startIndex + index];
		run->offset -= startOffset;
		run->offset = (run->offset < 0) ? 0 : run->offset;
		run++;
	}
	
	return result;
}
Exemplo n.º 3
0
void
BTextView::StyleBuffer::ContinuousGetStyle(BFont *outFont, uint32 *ioMode,
	rgb_color *outColor, bool *sameColor, int32 fromOffset,
	int32 toOffset) const
{
	uint32 mode = B_FONT_ALL;

	if (fStyleRunDesc.ItemCount() < 1) {
		if (ioMode)
			*ioMode = mode;
		if (outFont)
			*outFont = fNullStyle.font;
		if (outColor)
			*outColor = fNullStyle.color;
		if (sameColor)
			*sameColor = true;
		return;
	}

	int32 fromIndex = OffsetToRun(fromOffset);
	int32 toIndex = OffsetToRun(toOffset - 1);

	if (fromIndex == toIndex) {
		int32 styleIndex = fStyleRunDesc[fromIndex]->index;
		const STEStyle* style = &fStyleRecord[styleIndex]->style;

		if (ioMode)
			*ioMode = mode;
		if (outFont)
			*outFont = style->font;
		if (outColor)
			*outColor = style->color;
		if (sameColor)
			*sameColor = true;
	} else {
		bool oneColor = true;
		int32 styleIndex = fStyleRunDesc[toIndex]->index;
		STEStyle theStyle = fStyleRecord[styleIndex]->style;

		for (int32 i = fromIndex; i < toIndex; i++) {
			styleIndex = fStyleRunDesc[i]->index;
			FixupMode(fStyleRecord[styleIndex]->style, theStyle, mode,
				oneColor);
		}

		if (ioMode)
			*ioMode = mode;
		if (outFont)
			*outFont = theStyle.font;
		if (outColor)
			*outColor = theStyle.color;
		if (sameColor)
			*sameColor = oneColor;
	}
}
Exemplo n.º 4
0
void
_BStyleBuffer_::SyncNullStyle(int32 offset)
{
	if ((fValidNullStyle) || (fStyleRunDesc.ItemCount() < 1))
		return;
	
	int32 index = OffsetToRun(offset);
	fNullStyle = fStyleRecord[fStyleRunDesc[index]->index]->style;

	fValidNullStyle = true;
}	
Exemplo n.º 5
0
void
BTextView::StyleBuffer::SyncNullStyle(int32 offset)
{
	if (fValidNullStyle || fStyleRunDesc.ItemCount() < 1)
		return;

	int32 index = OffsetToRun(offset);
	fNullStyle = fStyleRecord[fStyleRunDesc[index]->index]->style;

	fValidNullStyle = true;
}
Exemplo n.º 6
0
void
_BStyleBuffer_::SetNullStyle(uint32 inMode, const BFont *inFont,
								  const rgb_color *inColor, int32 offset)
{
	if ((fValidNullStyle) || (fStyleRunDesc.ItemCount() < 1))
		SetStyle(inMode, inFont, &fNullStyle.font, inColor, &fNullStyle.color);
	else {
		int32 index = OffsetToRun(offset - 1);
		fNullStyle = fStyleRecord[fStyleRunDesc[index]->index]->style;
		SetStyle(inMode, inFont, &fNullStyle.font, inColor, &fNullStyle.color);	
	}
	
	fValidNullStyle = true;
}
Exemplo n.º 7
0
void
BTextView::StyleBuffer::SetNullStyle(uint32 inMode, const BFont *inFont,
	const rgb_color *inColor, int32 offset)
{
	if (fValidNullStyle || fStyleRunDesc.ItemCount() < 1) {
		SetStyleFromMode(inMode, inFont, &fNullStyle.font, inColor,
			&fNullStyle.color);
	} else {
		int32 index = OffsetToRun(offset - 1);
		fNullStyle = fStyleRecord[fStyleRunDesc[index]->index]->style;
		SetStyleFromMode(inMode, inFont, &fNullStyle.font, inColor,
			&fNullStyle.color);
	}

	fValidNullStyle = true;
}
Exemplo n.º 8
0
void
_BStyleBuffer_::GetStyle(int32 inOffset, BFont *outFont, rgb_color *outColor) const
{
	if (fStyleRunDesc.ItemCount() < 1) {
		if (outFont)
			*outFont = fNullStyle.font;
		if (outColor)
			*outColor = fNullStyle.color;
		return;
	}
	
	int32 runIndex = OffsetToRun(inOffset);
	int32 styleIndex = fStyleRunDesc[runIndex]->index;

	if (outFont)
		*outFont = fStyleRecord[styleIndex]->style.font;
	if (outColor)
		*outColor = fStyleRecord[styleIndex]->style.color;
}
Exemplo n.º 9
0
void
_BStyleBuffer_::ContinuousGetStyle(BFont *outFont, uint32 *ioMode,
				rgb_color *outColor, bool *sameColor, int32 fromOffset, int32 toOffset) const
{
	uint32 mode = B_FONT_ALL;

	if (fStyleRunDesc.ItemCount() < 1) {
		if (ioMode)
			*ioMode = mode;
		if (outFont)
			*outFont = fNullStyle.font;
		if (outColor)
			*outColor = fNullStyle.color;
		if (sameColor)
			*sameColor = true;	
		return;
	}
		
	int32 fromIndex = OffsetToRun(fromOffset);
	int32 toIndex = OffsetToRun(toOffset - 1);
	
	if (fromIndex == toIndex) {		
		int32 styleIndex = fStyleRunDesc[fromIndex]->index;
		STEStylePtr style = &fStyleRecord[styleIndex]->style;
		
		if (ioMode)
			*ioMode = mode;
		if (outFont)
			*outFont = style->font;
		if (outColor)
			*outColor = style->color;
		if (sameColor)
			*sameColor = true;	
		
	} else {
		bool oneColor = true;
		int32 		styleIndex = fStyleRunDesc[toIndex]->index;
		STEStyle	theStyle = fStyleRecord[styleIndex]->style;
		STEStylePtr	style = NULL;
		
		for (int32 i = fromIndex; i < toIndex; i++) {
			styleIndex = fStyleRunDesc[i]->index;
			style = &fStyleRecord[styleIndex]->style;
			
			if (mode & B_FONT_FAMILY_AND_STYLE) {
				if (theStyle.font != style->font)
					mode &= ~B_FONT_FAMILY_AND_STYLE;
			}
				
			if (mode & B_FONT_SIZE) {
				if (theStyle.font.Size() != style->font.Size())
					mode &= ~B_FONT_SIZE;
			}
				
			if (mode & B_FONT_SHEAR) {
				if (theStyle.font.Shear() != style->font.Shear())
					mode &= ~B_FONT_SHEAR;
			}
								
			if ( (theStyle.color.red != style->color.red) ||
				 (theStyle.color.green != style->color.green) ||
				 (theStyle.color.blue != style->color.blue) ||
				 (theStyle.color.alpha != style->color.alpha) ) {
				oneColor = false;
			}
			
			// TODO: Finish this: handle B_FONT_FACE, B_FONT_FLAGS, etc.
			// if needed
			
		}
		
		if (ioMode)
			*ioMode = mode;
		if (outFont)
			*outFont = theStyle.font;
		if (outColor)
			*outColor = theStyle.color;
		if (sameColor)
			*sameColor = oneColor;	
	}
}
Exemplo n.º 10
0
void
_BStyleBuffer_::SetStyleRange(int32 fromOffset, int32 toOffset,
								   int32 textLen, uint32 inMode,
								   const BFont *inFont, const rgb_color *inColor)
{
	if (inFont == NULL)
		inFont = &fNullStyle.font;

	if (inColor == NULL)
		inColor = &fNullStyle.color;

	if (fromOffset == toOffset) {
		SetNullStyle(inMode, inFont, inColor, fromOffset);
		return;
	}
	
	if (fStyleRunDesc.ItemCount() < 1) {
		STEStyleRunDesc newDesc;
		newDesc.offset = fromOffset;
		newDesc.index = fStyleRecord.InsertRecord(inFont, inColor);
		fStyleRunDesc.InsertDesc(&newDesc, 0);
		fStyleRecord.CommitRecord(newDesc.index);
		return;
	}

	int32 styleIndex = 0;
	int32 offset = fromOffset;
	int32 runIndex = OffsetToRun(offset);
	do {
		STEStyleRunDesc	runDesc = *fStyleRunDesc[runIndex];
		int32			runEnd = textLen;
		if (runIndex < (fStyleRunDesc.ItemCount() - 1))
			runEnd = fStyleRunDesc[runIndex + 1]->offset;
		
		STEStyle style = fStyleRecord[runDesc.index]->style;
		SetStyle(inMode, inFont, &style.font, inColor, &style.color);
	
		styleIndex = fStyleRecord.InsertRecord(&style.font, &style.color);
		
		if ( (runDesc.offset == offset) && (runIndex > 0) && 
			 (fStyleRunDesc[runIndex - 1]->index == styleIndex) ) {
			RemoveStyles(runIndex);
			runIndex--;	
		}

		if (styleIndex != runDesc.index) {
			if (offset > runDesc.offset) {
				STEStyleRunDesc newDesc;
				newDesc.offset = offset;
				newDesc.index = styleIndex;
				fStyleRunDesc.InsertDesc(&newDesc, runIndex + 1);
				fStyleRecord.CommitRecord(newDesc.index);
				runIndex++;		
			} else {
				fStyleRunDesc[runIndex]->index = styleIndex;
				fStyleRecord.CommitRecord(styleIndex);
			}
				
			if (toOffset < runEnd) {
				STEStyleRunDesc newDesc;
				newDesc.offset = toOffset;
				newDesc.index = runDesc.index;
				fStyleRunDesc.InsertDesc(&newDesc, runIndex + 1);
				fStyleRecord.CommitRecord(newDesc.index);
			}
		}
		
		runIndex++;
		offset = runEnd;	
	} while (offset < toOffset);
	
	if ( (offset == toOffset) && (runIndex < fStyleRunDesc.ItemCount()) &&
		 (fStyleRunDesc[runIndex]->index == styleIndex) )
		RemoveStyles(runIndex);
}