3 #include "lyxrow_funcs.h"
8 #include <boost/next_prior.hpp>
17 bool isParEnd(LyXText const & lt,
18 ParagraphList::iterator pit, RowList::iterator rit)
20 RowList::iterator next_row = boost::next(rit);
21 return next_row == lt.rows().end() || lt.getPar(next_row) != pit;
25 pos_type lastPos(LyXText const & lt,
26 ParagraphList::iterator pit, RowList::iterator rit)
31 if (isParEnd(lt, pit, rit))
32 return pit->size() - 1;
34 return boost::next(rit)->pos() - 1;
40 bool nextRowIsAllInset(
41 ParagraphList::iterator pit, RowList::iterator rit, pos_type last)
43 if (last + 1 >= pit->size())
46 if (!pit->isInset(last + 1))
49 InsetOld const * i = pit->getInset(last + 1);
50 return i->needFullRow() || i->display();
56 pos_type lastPrintablePos(LyXText const & lt,
57 ParagraphList::iterator pit, RowList::iterator rit)
59 pos_type const last = lastPos(lt, pit, rit);
61 // if this row is an end of par, just act like lastPos()
62 if (isParEnd(lt, pit, rit))
65 if (!nextRowIsAllInset(pit, rit, last) && pit->isSeparator(last))
72 int numberOfSeparators(LyXText const & lt,
73 ParagraphList::iterator pit, RowList::iterator rit)
75 pos_type const last = lastPrintablePos(lt, pit, rit);
77 pos_type p = max(rit->pos(), pit->beginningOfBody());
78 for ( ; p < last; ++p)
79 if (pit->isSeparator(p))
85 // This is called _once_ from LyXText and should at least be moved into
86 // an anonymous namespace there. (Lgb)
87 int numberOfHfills(LyXText const & lt,
88 ParagraphList::iterator pit, RowList::iterator rit)
90 pos_type const last = lastPos(lt, pit, rit);
91 pos_type first = rit->pos();
93 // hfill *DO* count at the beginning of paragraphs!
95 while (first < last && pit->isHfill(first))
99 first = max(first, pit->beginningOfBody());
103 // last, because the end is ignored!
104 for (pos_type p = first; p < last; ++p) {
112 // This is called _once_ from LyXText and should at least be moved into
113 // an anonymous namespace there. (Lgb)
114 int numberOfLabelHfills(LyXText const & lt,
115 ParagraphList::iterator pit, RowList::iterator rit)
117 pos_type last = lastPos(lt, pit, rit);
118 pos_type first = rit->pos();
120 // hfill *DO* count at the beginning of paragraphs!
122 while (first < last && pit->isHfill(first))
126 last = min(last, pit->beginningOfBody());
129 // last, because the end is ignored!
130 for (pos_type p = first; p < last; ++p) {
138 bool hfillExpansion(LyXText const & lt,
139 ParagraphList::iterator pit, RowList::iterator rit, pos_type pos)
141 if (!pit->isHfill(pos))
144 // at the end of a row it does not count
145 // unless another hfill exists on the line
146 if (pos >= lastPos(lt, pit, rit))
147 for (pos_type i = rit->pos(); i < pos && !pit->isHfill(i); ++i)
150 // at the beginning of a row it does not count, if it is not
151 // the first row of a paragaph
152 if (rit->isParStart())
155 // in some labels it does not count
156 if (pit->layout()->margintype != MARGIN_MANUAL
157 && pos < pit->beginningOfBody())
160 // if there is anything between the first char of the row and
161 // the specified position that is not a newline and not a hfill,
162 // the hfill will count, otherwise not
163 pos_type i = rit->pos();
164 while (i < pos && (pit->isNewline(i) || pit->isHfill(i)))