X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fiterators.C;h=6622fd31ac481531374a231325e57a163318f43e;hb=a9c2dd92df8c538e6ab39bbd136c2da9a0315eb1;hp=bc1e2fc4ef596790b6055bfaeb981a7a82f7b1fa;hpb=260c7f3187a7dd392888b1d1eea513abffd8f2f7;p=lyx.git diff --git a/src/iterators.C b/src/iterators.C index bc1e2fc4ef..6622fd31ac 100644 --- a/src/iterators.C +++ b/src/iterators.C @@ -42,3 +42,45 @@ ParIterator & ParIterator::operator++() } return *this; } + + +ParConstIterator & ParConstIterator::operator++() +{ + while (!positions.empty()) { + ParPosition & p = positions.top(); + + // Does the current inset contain more "cells" ? + if (p.index >= 0) { + ++p.index; + Paragraph * par = p.it.getInset()->getFirstParagraph(p.index); + if (par) { + positions.push(ParPosition(par)); + return *this; + } + ++p.it; + } else + // The following line is needed because the value of + // p.it may be invalid if inset was added/removed to + // the paragraph pointed by the iterator + p.it = p.par->insetlist.begin(); + + // Try to find the next inset that contains paragraphs + InsetList::iterator end = p.par->insetlist.end(); + for (; p.it != end; ++p.it) { + Paragraph * par = p.it.getInset()->getFirstParagraph(0); + if (par) { + p.index = 0; + positions.push(ParPosition(par)); + return *this; + } + } + // Try to go to the next paragarph + if (p.par->next()) { + p = ParPosition(p.par->next()); + return *this; + } + + positions.pop(); + } + return *this; +}