3 #include "lyxrow_funcs.h"
8 #include <boost/next_prior.hpp>
16 bool isParEnd(LyXText const & lt, RowList::iterator rit)
18 RowList::iterator next_row = boost::next(rit);
19 return next_row == lt.rows().end() || next_row->par() != rit->par();
23 pos_type lastPos(LyXText const & lt, RowList::iterator rit)
25 if (rit->par()->empty())
28 if (isParEnd(lt, rit))
29 return rit->par()->size() - 1;
31 return boost::next(rit)->pos() - 1;
37 bool nextRowIsAllInset(Row const & row, pos_type last)
39 ParagraphList::iterator pit = row.par();
41 if (last + 1 >= pit->size())
44 if (!pit->isInset(last + 1))
47 InsetOld const * i = pit->getInset(last + 1);
48 return i->needFullRow() || i->display();
54 pos_type lastPrintablePos(LyXText const & lt, RowList::iterator rit)
56 pos_type const last = lastPos(lt, rit);
58 // if this row is an end of par, just act like lastPos()
59 if (isParEnd(lt, rit))
62 bool const nextrownotinset = !nextRowIsAllInset(*rit, last);
64 if (nextrownotinset && rit->par()->isSeparator(last))
71 int numberOfSeparators(LyXText const & lt, RowList::iterator rit)
73 pos_type const last = lastPrintablePos(lt, rit);
74 ParagraphList::iterator pit = rit->par();
76 pos_type p = max(rit->pos(), pit->beginningOfBody());
77 for ( ; p < last; ++p)
78 if (pit->isSeparator(p))
84 // This is called _once_ from LyXText and should at least be moved into
85 // an anonymous namespace there. (Lgb)
86 int numberOfHfills(LyXText const & lt, RowList::iterator rit)
88 pos_type const last = lastPos(lt, rit);
89 pos_type first = rit->pos();
90 ParagraphList::iterator pit = rit->par();
92 // hfill *DO* count at the beginning of paragraphs!
94 while (first < last && pit->isHfill(first))
98 first = max(first, pit->beginningOfBody());
102 // last, because the end is ignored!
103 for (pos_type p = first; p < last; ++p) {
111 // This is called _once_ from LyXText and should at least be moved into
112 // an anonymous namespace there. (Lgb)
113 int numberOfLabelHfills(LyXText const & lt, RowList::iterator rit)
115 pos_type last = lastPos(lt, rit);
116 pos_type first = rit->pos();
117 ParagraphList::iterator pit = rit->par();
119 // hfill *DO* count at the beginning of paragraphs!
121 while (first < last && pit->isHfill(first))
125 last = min(last, pit->beginningOfBody());
128 // last, because the end is ignored!
129 for (pos_type p = first; p < last; ++p) {
137 bool hfillExpansion(LyXText const & lt, RowList::iterator rit, pos_type pos)
139 ParagraphList::iterator pit = rit->par();
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, 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)))