void _BStyleBuffer_::RemoveStyleRange(int32 fromOffset, int32 toOffset) { int32 fromIndex = fStyleRunDesc.OffsetToRun(fromOffset); int32 toIndex = fStyleRunDesc.OffsetToRun(toOffset) - 1; int32 count = toIndex - fromIndex; if (count > 0) { RemoveStyles(fromIndex + 1, count); toIndex = fromIndex; } fStyleRunDesc.BumpOffset(fromOffset - toOffset, fromIndex + 1); if ((toIndex == fromIndex) && (toIndex < (fStyleRunDesc.ItemCount() - 1))) { STEStyleRunDescPtr runDesc = fStyleRunDesc[toIndex + 1]; runDesc->offset = fromOffset; } if (fromIndex < (fStyleRunDesc.ItemCount() - 1)) { STEStyleRunDescPtr runDesc = fStyleRunDesc[fromIndex]; if (runDesc->offset == (runDesc + 1)->offset) { RemoveStyles(fromIndex); fromIndex--; } } if ((fromIndex >= 0) && (fromIndex < (fStyleRunDesc.ItemCount() - 1))) { STEStyleRunDescPtr runDesc = fStyleRunDesc[fromIndex]; if (runDesc->index == (runDesc + 1)->index) RemoveStyles(fromIndex + 1); } }
void BTextView::StyleBuffer::RemoveStyleRange(int32 fromOffset, int32 toOffset) { int32 fromIndex = fStyleRunDesc.OffsetToRun(fromOffset); int32 toIndex = fStyleRunDesc.OffsetToRun(toOffset) - 1; int32 count = toIndex - fromIndex; if (count > 0) { RemoveStyles(fromIndex + 1, count); toIndex = fromIndex; } fStyleRunDesc.BumpOffset(fromOffset - toOffset, fromIndex + 1); if (toIndex == fromIndex && toIndex < fStyleRunDesc.ItemCount() - 1) { STEStyleRunDesc* runDesc = fStyleRunDesc[toIndex + 1]; runDesc->offset = fromOffset; } if (fromIndex < fStyleRunDesc.ItemCount() - 1) { STEStyleRunDesc* runDesc = fStyleRunDesc[fromIndex]; if (runDesc->offset == (runDesc + 1)->offset) { RemoveStyles(fromIndex); fromIndex--; } } if (fromIndex >= 0 && fromIndex < fStyleRunDesc.ItemCount() - 1) { STEStyleRunDesc* runDesc = fStyleRunDesc[fromIndex]; if (runDesc->index == (runDesc + 1)->index) RemoveStyles(fromIndex + 1); } }
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); }