TextDocumentLayout: Fixed invalidating

* Add new ParagraphLayouts for new Paragraphs in the TextDocument.
 * Actually mark layout invalid, so that height changes in paragraphs
   are accounted for and newly added paragraphs are positioned.
This commit is contained in:
Stephan Aßmus
2014-01-20 00:50:38 +01:00
parent fa8b5d525e
commit 57246b1477
@@ -64,27 +64,42 @@ TextDocumentLayout::SetTextDocument(const TextDocumentRef& document)
void void
TextDocumentLayout::Invalidate() TextDocumentLayout::Invalidate()
{ {
InvalidateParagraphs(0, fParagraphLayouts.CountItems()); if (fDocument.Get() != NULL)
InvalidateParagraphs(0, fDocument->Paragraphs().CountItems());
} }
void void
TextDocumentLayout::InvalidateParagraphs(int32 start, int32 count) TextDocumentLayout::InvalidateParagraphs(int32 start, int32 count)
{ {
if (start < 0 || fDocument.Get() == NULL) if (start < 0 || count == 0 || fDocument.Get() == NULL)
return; return;
fLayoutValid = false;
const ParagraphList& paragraphs = fDocument->Paragraphs(); const ParagraphList& paragraphs = fDocument->Paragraphs();
while (count > 0) { while (count > 0) {
if (start >= fParagraphLayouts.CountItems()) if (start >= paragraphs.CountItems())
break; break;
const Paragraph& paragraph = paragraphs.ItemAtFast(start); const Paragraph& paragraph = paragraphs.ItemAtFast(start);
const ParagraphLayoutInfo& info = fParagraphLayouts.ItemAtFast(start); if (start >= fParagraphLayouts.CountItems()) {
info.layout->SetParagraph(paragraph); ParagraphLayoutRef layout(new(std::nothrow) ParagraphLayout(
paragraph), true);
if (layout.Get() == NULL
|| !fParagraphLayouts.Add(ParagraphLayoutInfo(0.0f, layout))) {
fprintf(stderr, "TextDocumentLayout::InvalidateParagraphs() - "
"out of memory\n");
return;
}
} else {
const ParagraphLayoutInfo& info = fParagraphLayouts.ItemAtFast(
start);
info.layout->SetParagraph(paragraph);
}
start++; start++;
count--;
} }
} }