]> git.lyx.org Git - lyx.git/blob - src/iterators.C
bug 183
[lyx.git] / src / iterators.C
1 #include <config.h>
2
3 #include "iterators.h"
4
5 ParIterator & ParIterator::operator++()
6 {
7         while (!positions.empty()) {
8                 ParPosition & p = positions.back();
9
10                 // Does the current inset contain more "cells" ?
11                 if (p.index >= 0) {
12                         ++p.index;
13                         Paragraph * par = (*p.it)->getFirstParagraph(p.index);
14                         if (par) {
15                                 positions.push_back(ParPosition(par));
16                                 return *this;
17                         }
18                         ++p.it;
19                 } else
20                         // The following line is needed because the value of
21                         // p.it may be invalid if inset was added/removed to
22                         // the paragraph pointed by the iterator
23                         p.it = p.par->inset_iterator_begin();
24
25                 // Try to find the next inset that contains paragraphs
26                 for ( ; p.it != p.par->inset_iterator_end(); ++p.it) {
27                         Paragraph * par = (*p.it)->getFirstParagraph(0);
28                         if (par) {
29                                 p.index = 0;
30                                 positions.push_back(ParPosition(par));
31                                 return *this;
32                         }
33                 }
34                 // Try to go to the next paragarph
35                 if (p.par->next()) {
36                         p = ParPosition(p.par->next());
37                         return *this;
38                 }
39
40                 positions.pop_back();
41         }
42         return *this;
43 }