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 "paragraph.h"
17 #include "lyxlayout.h"
20 #include "support/LAssert.h"
22 #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;
69 bool nextRowIsAllInset(Paragraph const & par, pos_type last)
71 if (last + 1 >= par.size())
74 if (!par.isInset(last + 1))
77 InsetOld const * i = par.getInset(last + 1);
78 return i->needFullRow() || i->display();
84 pos_type lastPrintablePos(Paragraph const & par, RowList::iterator rit)
86 pos_type const last = lastPos(par, rit);
88 // if this row is an end of par, just act like lastPos()
89 if (isParEnd(par, rit))
92 if (!nextRowIsAllInset(par, last) && par.isSeparator(last))
99 int numberOfSeparators(Paragraph const & par, RowList::iterator rit)
101 pos_type const last = lastPrintablePos(par, rit);
103 pos_type p = max(rit->pos(), par.beginningOfBody());
104 for ( ; p < last; ++p)
105 if (par.isSeparator(p))
111 // This is called _once_ from LyXText and should at least be moved into
112 // an anonymous namespace there. (Lgb)
113 int numberOfHfills(Paragraph const & par, RowList::iterator rit)
115 pos_type const 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 first = max(first, par.beginningOfBody());
128 // last, because the end is ignored!
129 for (pos_type p = first; p < last; ++p)
137 // This is called _once_ from LyXText and should at least be moved into
138 // an anonymous namespace there. (Lgb)
139 int numberOfLabelHfills(Paragraph const & par, RowList::iterator rit)
141 pos_type last = lastPos(par, rit);
142 pos_type first = rit->pos();
144 // hfill *DO* count at the beginning of paragraphs!
146 while (first < last && par.isHfill(first))
150 last = min(last, par.beginningOfBody());
153 // last, because the end is ignored!
154 for (pos_type p = first; p < last; ++p) {
162 bool hfillExpansion(Paragraph const & par, RowList::iterator rit, pos_type pos)
164 if (!par.isHfill(pos))
167 // at the end of a row it does not count
168 // unless another hfill exists on the line
169 if (pos >= lastPos(par, rit))
170 for (pos_type i = rit->pos(); i < pos && !par.isHfill(i); ++i)
173 // at the beginning of a row it does not count, if it is not
174 // the first row of a paragaph
175 if (rit->isParStart())
178 // in some labels it does not count
179 if (par.layout()->margintype != MARGIN_MANUAL
180 && pos < par.beginningOfBody())
183 // if there is anything between the first char of the row and
184 // the specified position that is not a newline and not a hfill,
185 // the hfill will count, otherwise not
186 pos_type i = rit->pos();
187 while (i < pos && (par.isNewline(i) || par.isHfill(i)))