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;
67 pos_type lastPrintablePos(Paragraph const & par, RowList::iterator rit)
69 pos_type const last = lastPos(par, rit);
71 // if this row is an end of par, just act like lastPos()
72 if (isParEnd(par, rit))
79 int numberOfSeparators(Paragraph const & par, RowList::iterator rit)
81 pos_type const last = lastPrintablePos(par, rit);
83 pos_type p = max(rit->pos(), par.beginningOfBody());
84 for ( ; p < last; ++p)
85 if (par.isSeparator(p))
91 // This is called _once_ from LyXText and should at least be moved into
92 // an anonymous namespace there. (Lgb)
93 int numberOfHfills(Paragraph const & par, RowList::iterator rit)
95 pos_type const last = lastPos(par, rit);
96 pos_type first = rit->pos();
98 // hfill *DO* count at the beginning of paragraphs!
100 while (first < last && par.isHfill(first))
104 first = max(first, par.beginningOfBody());
108 // last, because the end is ignored!
109 for (pos_type p = first; p < last; ++p)
117 // This is called _once_ from LyXText and should at least be moved into
118 // an anonymous namespace there. (Lgb)
119 int numberOfLabelHfills(Paragraph const & par, RowList::iterator rit)
121 pos_type last = lastPos(par, rit);
122 pos_type first = rit->pos();
124 // hfill *DO* count at the beginning of paragraphs!
126 while (first < last && par.isHfill(first))
130 last = min(last, par.beginningOfBody());
133 // last, because the end is ignored!
134 for (pos_type p = first; p < last; ++p) {
142 bool hfillExpansion(Paragraph const & par, RowList::iterator rit, pos_type pos)
144 if (!par.isHfill(pos))
147 // at the end of a row it does not count
148 // unless another hfill exists on the line
149 if (pos >= lastPos(par, rit))
150 for (pos_type i = rit->pos(); i < pos && !par.isHfill(i); ++i)
153 // at the beginning of a row it does not count, if it is not
154 // the first row of a paragaph
155 if (rit->isParStart())
158 // in some labels it does not count
159 if (par.layout()->margintype != MARGIN_MANUAL
160 && pos < par.beginningOfBody())
163 // if there is anything between the first char of the row and
164 // the specified position that is not a newline and not a hfill,
165 // the hfill will count, otherwise not
166 pos_type i = rit->pos();
167 while (i < pos && (par.isNewline(i) || par.isHfill(i)))