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 "paragraph.h"
21 #include "support/LAssert.h"
23 #include <boost/next_prior.hpp>
26 using lyx::support::Assert;
33 bool isParEnd(Paragraph const & par, RowList::iterator rit)
36 if ((boost::next(rit) == par.rows.end()) != (rit->end() >= par.size())) {
38 lyxerr << "broken row 1: end: " << rit->end() << " next: "
39 << boost::next(rit)->pos() << endl;
44 return boost::next(rit) == par.rows.end();
48 pos_type lastPos(Paragraph const & par, RowList::iterator rit)
53 if (isParEnd(par, rit))
54 return par.size() - 1;
56 if (1 && boost::next(rit)->pos() != rit->end()) {
58 lyxerr << "broken row 2: end: " << rit->end() << " next: "
59 << boost::next(rit)->pos() << endl;
63 return boost::next(rit)->pos() - 1;
66 pos_type lastPos(Paragraph const &, RowList::iterator rit)
68 return rit->end() - 1;
73 int numberOfSeparators(Paragraph const & par, RowList::iterator rit)
75 pos_type const last = lastPos(par, rit);
77 pos_type p = max(rit->pos(), par.beginningOfBody());
78 for ( ; p < last; ++p)
79 if (par.isSeparator(p))
85 // This is called _once_ from LyXText and should at least be moved into
86 // an anonymous namespace there. (Lgb)
87 int numberOfHfills(Paragraph const & par, RowList::iterator rit)
89 pos_type const last = lastPos(par, rit);
90 pos_type first = rit->pos();
92 // hfill *DO* count at the beginning of paragraphs!
94 while (first < last && par.isHfill(first))
98 first = max(first, par.beginningOfBody());
102 // last, because the end is ignored!
103 for (pos_type p = first; p < last; ++p)
111 // This is called _once_ from LyXText and should at least be moved into
112 // an anonymous namespace there. (Lgb)
113 int numberOfLabelHfills(Paragraph const & par, RowList::iterator rit)
115 pos_type last = lastPos(par, rit);
116 pos_type first = rit->pos();
118 // hfill *DO* count at the beginning of paragraphs!
120 while (first < last && par.isHfill(first))
124 last = min(last, par.beginningOfBody());
127 // last, because the end is ignored!
128 for (pos_type p = first; p < last; ++p) {
136 bool hfillExpansion(Paragraph const & par, RowList::iterator rit, pos_type pos)
138 if (!par.isHfill(pos))
141 // at the end of a row it does not count
142 // unless another hfill exists on the line
143 if (pos >= lastPos(par, rit))
144 for (pos_type i = rit->pos(); i < pos && !par.isHfill(i); ++i)
147 // at the beginning of a row it does not count, if it is not
148 // the first row of a paragaph
149 if (rit->isParStart())
152 // in some labels it does not count
153 if (par.layout()->margintype != MARGIN_MANUAL
154 && pos < par.beginningOfBody())
157 // if there is anything between the first char of the row and
158 // the specified position that is not a newline and not a hfill,
159 // the hfill will count, otherwise not
160 pos_type i = rit->pos();
161 while (i < pos && (par.isNewline(i) || par.isHfill(i)))