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);
20 return next_row == lt.rows().end() ||
21 next_row->par() != rit->par();
25 pos_type lastPos(LyXText const & lt, RowList::iterator rit)
27 if (rit->par()->empty())
30 if (isParEnd(lt, rit)) {
31 return rit->par()->size() - 1;
33 return boost::next(rit)->pos() - 1;
40 bool nextRowIsAllInset(Row const & row, pos_type last)
42 ParagraphList::iterator pit = row.par();
44 if (last + 1 >= pit->size())
47 if (!pit->isInset(last + 1))
50 InsetOld const * i = pit->getInset(last + 1);
51 return i->needFullRow() || i->display();
57 pos_type lastPrintablePos(LyXText const & lt, RowList::iterator rit)
59 pos_type const last = lastPos(lt, rit);
61 // if this row is an end of par, just act like lastPos()
62 if (isParEnd(lt, rit))
65 bool const nextrownotinset = !nextRowIsAllInset(*rit, last);
67 if (nextrownotinset && rit->par()->isSeparator(last))
74 int numberOfSeparators(LyXText const & lt, RowList::iterator rit)
76 pos_type const last = lastPrintablePos(lt, rit);
77 ParagraphList::iterator pit = rit->par();
81 pos_type p = max(rit->pos(), pit->beginningOfBody());
82 for (; p < last; ++p) {
83 if (pit->isSeparator(p)) {
91 // This is called _once_ from LyXText and should at least be moved into
92 // an anonymous namespace there. (Lgb)
93 int numberOfHfills(LyXText const & lt, RowList::iterator rit)
95 pos_type const last = lastPos(lt, rit);
96 pos_type first = rit->pos();
97 ParagraphList::iterator pit = rit->par();
99 // hfill *DO* count at the beginning of paragraphs!
101 while (first < last && pit->isHfill(first)) {
106 first = max(first, pit->beginningOfBody());
110 // last, because the end is ignored!
111 for (pos_type p = first; p < last; ++p) {
119 // This is called _once_ from LyXText and should at least be moved into
120 // an anonymous namespace there. (Lgb)
121 int numberOfLabelHfills(LyXText const & lt, RowList::iterator rit)
123 pos_type last = lastPos(lt, rit);
124 pos_type first = rit->pos();
125 ParagraphList::iterator pit = rit->par();
127 // hfill *DO* count at the beginning of paragraphs!
129 while (first < last && pit->isHfill(first))
133 last = min(last, pit->beginningOfBody());
136 // last, because the end is ignored!
137 for (pos_type p = first; p < last; ++p) {
145 bool hfillExpansion(LyXText const & lt, RowList::iterator rit, pos_type pos)
147 ParagraphList::iterator pit = rit->par();
149 if (!pit->isHfill(pos))
152 // at the end of a row it does not count
153 // unless another hfill exists on the line
154 if (pos >= lastPos(lt, rit)) {
155 pos_type i = rit->pos();
156 while (i < pos && !pit->isHfill(i)) {
164 // at the beginning of a row it does not count, if it is not
165 // the first row of a paragaph
166 if (rit->isParStart())
169 // in some labels it does not count
170 if (pit->layout()->margintype != MARGIN_MANUAL
171 && pos < pit->beginningOfBody())
174 // if there is anything between the first char of the row and
175 // the specified position that is not a newline and not a hfill,
176 // the hfill will count, otherwise not
177 pos_type i = rit->pos();
178 while (i < pos && (pit->isNewline(i) || pit->isHfill(i)))