3 #include "lyxrow_funcs.h"
9 #include "support/LAssert.h"
11 #include <boost/next_prior.hpp>
15 using lyx::support::Assert;
22 bool isParEnd(Paragraph const & par, RowList::iterator rit)
25 if ((boost::next(rit) == par.rows.end()) != (rit->end() >= par.size())) {
27 lyxerr << "broken row 1: end: " << rit->end() << " next: "
28 << boost::next(rit)->pos() << endl;
33 return boost::next(rit) == par.rows.end();
37 pos_type lastPos(Paragraph const & par, RowList::iterator rit)
42 if (isParEnd(par, rit))
43 return par.size() - 1;
45 if (1 && boost::next(rit)->pos() != rit->end()) {
47 lyxerr << "broken row 2: end: " << rit->end() << " next: "
48 << boost::next(rit)->pos() << endl;
52 return boost::next(rit)->pos() - 1;
58 bool nextRowIsAllInset(Paragraph const & par, pos_type last)
60 if (last + 1 >= par.size())
63 if (!par.isInset(last + 1))
66 InsetOld const * i = par.getInset(last + 1);
67 return i->needFullRow() || i->display();
73 pos_type lastPrintablePos(Paragraph const & par, RowList::iterator rit)
75 pos_type const last = lastPos(par, rit);
77 // if this row is an end of par, just act like lastPos()
78 if (isParEnd(par, rit))
81 if (!nextRowIsAllInset(par, last) && par.isSeparator(last))
88 int numberOfSeparators(Paragraph const & par, RowList::iterator rit)
90 pos_type const last = lastPrintablePos(par, rit);
92 pos_type p = max(rit->pos(), par.beginningOfBody());
93 for ( ; p < last; ++p)
94 if (par.isSeparator(p))
100 // This is called _once_ from LyXText and should at least be moved into
101 // an anonymous namespace there. (Lgb)
102 int numberOfHfills(Paragraph const & par, RowList::iterator rit)
104 pos_type const last = lastPos(par, rit);
105 pos_type first = rit->pos();
107 // hfill *DO* count at the beginning of paragraphs!
109 while (first < last && par.isHfill(first))
113 first = max(first, par.beginningOfBody());
117 // last, because the end is ignored!
118 for (pos_type p = first; p < last; ++p)
126 // This is called _once_ from LyXText and should at least be moved into
127 // an anonymous namespace there. (Lgb)
128 int numberOfLabelHfills(Paragraph const & par, RowList::iterator rit)
130 pos_type last = lastPos(par, rit);
131 pos_type first = rit->pos();
133 // hfill *DO* count at the beginning of paragraphs!
135 while (first < last && par.isHfill(first))
139 last = min(last, par.beginningOfBody());
142 // last, because the end is ignored!
143 for (pos_type p = first; p < last; ++p) {
151 bool hfillExpansion(Paragraph const & par, RowList::iterator rit, pos_type pos)
153 if (!par.isHfill(pos))
156 // at the end of a row it does not count
157 // unless another hfill exists on the line
158 if (pos >= lastPos(par, rit))
159 for (pos_type i = rit->pos(); i < pos && !par.isHfill(i); ++i)
162 // at the beginning of a row it does not count, if it is not
163 // the first row of a paragaph
164 if (rit->isParStart())
167 // in some labels it does not count
168 if (par.layout()->margintype != MARGIN_MANUAL
169 && pos < par.beginningOfBody())
172 // if there is anything between the first char of the row and
173 // the specified position that is not a newline and not a hfill,
174 // the hfill will count, otherwise not
175 pos_type i = rit->pos();
176 while (i < pos && (par.isNewline(i) || par.isHfill(i)))