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 <boost/next_prior.hpp>
30 bool isParEnd(Paragraph const & par, RowList::iterator rit)
33 if ((boost::next(rit) == par.rows.end()) != (rit->end() >= par.size())) {
35 lyxerr << "broken row 1: end: " << rit->end() << " next: "
36 << boost::next(rit)->pos() << endl;
41 return boost::next(rit) == par.rows.end();
45 pos_type lastPos(Paragraph const & par, RowList::iterator rit)
50 if (isParEnd(par, rit))
51 return par.size() - 1;
53 if (1 && boost::next(rit)->pos() != rit->end()) {
55 lyxerr << "broken row 2: end: " << rit->end() << " next: "
56 << boost::next(rit)->pos() << endl;
60 return boost::next(rit)->pos() - 1;
63 pos_type lastPos(Paragraph const &, RowList::iterator rit)
65 return rit->end() - 1;
70 int numberOfSeparators(Paragraph const & par, RowList::iterator rit)
72 pos_type const last = lastPos(par, rit);
74 pos_type p = max(rit->pos(), par.beginningOfBody());
75 for ( ; p < last; ++p)
76 if (par.isSeparator(p))
82 // This is called _once_ from LyXText and should at least be moved into
83 // an anonymous namespace there. (Lgb)
84 int numberOfHfills(Paragraph const & par, RowList::iterator rit)
86 pos_type const last = lastPos(par, rit);
87 pos_type first = rit->pos();
89 // hfill *DO* count at the beginning of paragraphs!
91 while (first < last && par.isHfill(first))
95 first = max(first, par.beginningOfBody());
99 // last, because the end is ignored!
100 for (pos_type p = first; p < last; ++p)
108 // This is called _once_ from LyXText and should at least be moved into
109 // an anonymous namespace there. (Lgb)
110 int numberOfLabelHfills(Paragraph const & par, RowList::iterator rit)
112 pos_type last = lastPos(par, rit);
113 pos_type first = rit->pos();
115 // hfill *DO* count at the beginning of paragraphs!
117 while (first < last && par.isHfill(first))
121 last = min(last, par.beginningOfBody());
124 // last, because the end is ignored!
125 for (pos_type p = first; p < last; ++p) {
133 bool hfillExpansion(Paragraph const & par, RowList::iterator rit, pos_type pos)
135 if (!par.isHfill(pos))
138 // at the end of a row it does not count
139 // unless another hfill exists on the line
140 if (pos >= lastPos(par, rit))
141 for (pos_type i = rit->pos(); i < pos && !par.isHfill(i); ++i)
144 // at the beginning of a row it does not count, if it is not
145 // the first row of a paragaph
146 if (rit->isParStart())
149 // in some labels it does not count
150 if (par.layout()->margintype != MARGIN_MANUAL
151 && pos < par.beginningOfBody())
154 // if there is anything between the first char of the row and
155 // the specified position that is not a newline and not a hfill,
156 // the hfill will count, otherwise not
157 pos_type i = rit->pos();
158 while (i < pos && (par.isNewline(i) || par.isHfill(i)))