3 #include "lyxrow_funcs.h"
8 #include <boost/next_prior.hpp>
17 bool isParEnd(Paragraph const & par, RowList::iterator rit)
19 return boost::next(rit) == par.rows.end();
23 pos_type lastPos(Paragraph const & par, RowList::iterator rit)
28 if (isParEnd(par, rit))
29 return par.size() - 1;
31 return boost::next(rit)->pos() - 1;
37 bool nextRowIsAllInset(
38 Paragraph const & par, pos_type last)
40 if (last + 1 >= par.size())
43 if (!par.isInset(last + 1))
46 InsetOld const * i = par.getInset(last + 1);
47 return i->needFullRow() || i->display();
53 pos_type lastPrintablePos(Paragraph const & par, RowList::iterator rit)
55 pos_type const last = lastPos(par, rit);
57 // if this row is an end of par, just act like lastPos()
58 if (isParEnd(par, rit))
61 if (!nextRowIsAllInset(par, last) && par.isSeparator(last))
68 int numberOfSeparators(Paragraph const & par, RowList::iterator rit)
70 pos_type const last = lastPrintablePos(par, rit);
72 pos_type p = max(rit->pos(), par.beginningOfBody());
73 for ( ; p < last; ++p)
74 if (par.isSeparator(p))
80 // This is called _once_ from LyXText and should at least be moved into
81 // an anonymous namespace there. (Lgb)
82 int numberOfHfills(Paragraph const & par, RowList::iterator rit)
84 pos_type const last = lastPos(par, rit);
85 pos_type first = rit->pos();
87 // hfill *DO* count at the beginning of paragraphs!
89 while (first < last && par.isHfill(first))
93 first = max(first, par.beginningOfBody());
97 // last, because the end is ignored!
98 for (pos_type p = first; p < last; ++p)
106 // This is called _once_ from LyXText and should at least be moved into
107 // an anonymous namespace there. (Lgb)
108 int numberOfLabelHfills(Paragraph const & par, RowList::iterator rit)
110 pos_type last = lastPos(par, rit);
111 pos_type first = rit->pos();
113 // hfill *DO* count at the beginning of paragraphs!
115 while (first < last && par.isHfill(first))
119 last = min(last, par.beginningOfBody());
122 // last, because the end is ignored!
123 for (pos_type p = first; p < last; ++p) {
131 bool hfillExpansion(Paragraph const & par, RowList::iterator rit, pos_type pos)
133 if (!par.isHfill(pos))
136 // at the end of a row it does not count
137 // unless another hfill exists on the line
138 if (pos >= lastPos(par, rit))
139 for (pos_type i = rit->pos(); i < pos && !par.isHfill(i); ++i)
142 // at the beginning of a row it does not count, if it is not
143 // the first row of a paragaph
144 if (rit->isParStart())
147 // in some labels it does not count
148 if (par.layout()->margintype != MARGIN_MANUAL
149 && pos < par.beginningOfBody())
152 // if there is anything between the first char of the row and
153 // the specified position that is not a newline and not a hfill,
154 // the hfill will count, otherwise not
155 pos_type i = rit->pos();
156 while (i < pos && (par.isNewline(i) || par.isHfill(i)))