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"
20 #include "support/LAssert.h"
22 #include <boost/next_prior.hpp>
25 using lyx::support::Assert;
32 bool isParEnd(Paragraph const & par, RowList::iterator rit)
35 if ((boost::next(rit) == par.rows.end()) != (rit->end() >= par.size())) {
37 lyxerr << "broken row 1: end: " << rit->end() << " next: "
38 << boost::next(rit)->pos() << endl;
43 return boost::next(rit) == par.rows.end();
47 pos_type lastPos(Paragraph const & par, RowList::iterator rit)
52 if (isParEnd(par, rit))
53 return par.size() - 1;
55 if (1 && boost::next(rit)->pos() != rit->end()) {
57 lyxerr << "broken row 2: end: " << rit->end() << " next: "
58 << boost::next(rit)->pos() << endl;
62 return boost::next(rit)->pos() - 1;
65 pos_type lastPos(Paragraph const &, RowList::iterator rit)
67 return rit->end() - 1;
72 int numberOfSeparators(Paragraph const & par, RowList::iterator rit)
74 pos_type const last = lastPos(par, rit);
76 pos_type p = max(rit->pos(), par.beginningOfBody());
77 for ( ; p < last; ++p)
78 if (par.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(Paragraph const & par, RowList::iterator rit)
88 pos_type const last = lastPos(par, rit);
89 pos_type first = rit->pos();
91 // hfill *DO* count at the beginning of paragraphs!
93 while (first < last && par.isHfill(first))
97 first = max(first, par.beginningOfBody());
101 // last, because the end is ignored!
102 for (pos_type p = first; p < last; ++p)
110 // This is called _once_ from LyXText and should at least be moved into
111 // an anonymous namespace there. (Lgb)
112 int numberOfLabelHfills(Paragraph const & par, RowList::iterator rit)
114 pos_type last = lastPos(par, rit);
115 pos_type first = rit->pos();
117 // hfill *DO* count at the beginning of paragraphs!
119 while (first < last && par.isHfill(first))
123 last = min(last, par.beginningOfBody());
126 // last, because the end is ignored!
127 for (pos_type p = first; p < last; ++p) {
135 bool hfillExpansion(Paragraph const & par, RowList::iterator rit, pos_type pos)
137 if (!par.isHfill(pos))
140 // at the end of a row it does not count
141 // unless another hfill exists on the line
142 if (pos >= lastPos(par, rit))
143 for (pos_type i = rit->pos(); i < pos && !par.isHfill(i); ++i)
146 // at the beginning of a row it does not count, if it is not
147 // the first row of a paragaph
148 if (rit->isParStart())
151 // in some labels it does not count
152 if (par.layout()->margintype != MARGIN_MANUAL
153 && pos < par.beginningOfBody())
156 // if there is anything between the first char of the row and
157 // the specified position that is not a newline and not a hfill,
158 // the hfill will count, otherwise not
159 pos_type i = rit->pos();
160 while (i < pos && (par.isNewline(i) || par.isHfill(i)))