3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
9 * Full author contact details are available in file CREDITS.
14 #include "lyxrow_funcs.h"
16 #include "lyxlayout.h"
19 #include "support/LAssert.h"
21 #include <boost/next_prior.hpp>
24 using lyx::support::Assert;
31 bool isParEnd(Paragraph const & par, RowList::iterator rit)
34 if ((boost::next(rit) == par.rows.end()) != (rit->end() >= par.size())) {
36 lyxerr << "broken row 1: end: " << rit->end() << " next: "
37 << boost::next(rit)->pos() << endl;
42 return boost::next(rit) == par.rows.end();
46 pos_type lastPos(Paragraph const & par, RowList::iterator rit)
51 if (isParEnd(par, rit))
52 return par.size() - 1;
54 if (1 && boost::next(rit)->pos() != rit->end()) {
56 lyxerr << "broken row 2: end: " << rit->end() << " next: "
57 << boost::next(rit)->pos() << endl;
61 return boost::next(rit)->pos() - 1;
64 pos_type lastPos(Paragraph const &, RowList::iterator rit)
66 return rit->end() - 1;
71 int numberOfSeparators(Paragraph const & par, RowList::iterator rit)
73 pos_type const last = lastPos(par, rit);
75 pos_type p = max(rit->pos(), par.beginningOfBody());
76 for ( ; p < last; ++p)
77 if (par.isSeparator(p))
83 // This is called _once_ from LyXText and should at least be moved into
84 // an anonymous namespace there. (Lgb)
85 int numberOfHfills(Paragraph const & par, RowList::iterator rit)
87 pos_type const last = lastPos(par, rit);
88 pos_type first = rit->pos();
90 // hfill *DO* count at the beginning of paragraphs!
92 while (first < last && par.isHfill(first))
96 first = max(first, par.beginningOfBody());
100 // last, because the end is ignored!
101 for (pos_type p = first; p < last; ++p)
109 // This is called _once_ from LyXText and should at least be moved into
110 // an anonymous namespace there. (Lgb)
111 int numberOfLabelHfills(Paragraph const & par, RowList::iterator rit)
113 pos_type last = lastPos(par, rit);
114 pos_type first = rit->pos();
116 // hfill *DO* count at the beginning of paragraphs!
118 while (first < last && par.isHfill(first))
122 last = min(last, par.beginningOfBody());
125 // last, because the end is ignored!
126 for (pos_type p = first; p < last; ++p) {
134 bool hfillExpansion(Paragraph const & par, RowList::iterator rit, pos_type pos)
136 if (!par.isHfill(pos))
139 // at the end of a row it does not count
140 // unless another hfill exists on the line
141 if (pos >= lastPos(par, rit))
142 for (pos_type i = rit->pos(); i < pos && !par.isHfill(i); ++i)
145 // at the beginning of a row it does not count, if it is not
146 // the first row of a paragaph
147 if (rit->isParStart())
150 // in some labels it does not count
151 if (par.layout()->margintype != MARGIN_MANUAL
152 && pos < par.beginningOfBody())
155 // if there is anything between the first char of the row and
156 // the specified position that is not a newline and not a hfill,
157 // the hfill will count, otherwise not
158 pos_type i = rit->pos();
159 while (i < pos && (par.isNewline(i) || par.isHfill(i)))