3 #include "lyxrow_funcs.h"
8 #include <boost/next_prior.hpp>
16 bool isParEnd(LyXText const & lt, RowList::iterator rit)
18 RowList::iterator next_row = boost::next(rit);
20 return next_row == lt.rows().end() ||
21 next_row->par() != rit->par();
25 // It seems that this is only used in LyXText, it
26 // perhaps this function should be moved into LyXText. (Lgb)
27 pos_type lastPos(LyXText const & lt, RowList::iterator rit)
29 if (rit->par()->empty())
32 if (isParEnd(lt, rit)) {
33 return rit->par()->size() - 1;
35 return boost::next(rit)->pos() - 1;
42 bool nextRowIsAllInset(Row const & row, pos_type last)
44 Paragraph const * par = row.par();
46 if (last + 1 >= par->size())
49 if (!par->isInset(last + 1))
52 Inset const * i = par->getInset(last + 1);
53 return i->needFullRow() || i->display();
59 pos_type lastPrintablePos(LyXText const & lt, RowList::iterator rit)
61 pos_type const last = lastPos(lt, rit);
63 // if this row is an end of par, just act like lastPos()
64 if (isParEnd(lt, rit))
67 bool const nextrownotinset = !nextRowIsAllInset(*rit, last);
69 if (nextrownotinset && rit->par()->isSeparator(last))
76 int numberOfSeparators(LyXText const & lt, RowList::iterator rit)
78 pos_type const last = lastPrintablePos(lt, rit);
79 Paragraph const * par = rit->par();
83 pos_type p = max(rit->pos(), par->beginningOfBody());
84 for (; p < last; ++p) {
85 if (par->isSeparator(p)) {
93 // This is called _once_ from LyXText and should at least be moved into
94 // an anonymous namespace there. (Lgb)
95 int numberOfHfills(LyXText const & lt, RowList::iterator rit)
97 pos_type const last = lastPos(lt, rit);
98 pos_type first = rit->pos();
99 Paragraph const * par = rit->par();
101 // hfill *DO* count at the beginning of paragraphs!
103 while (first < last && par->isHfill(first)) {
108 first = max(first, par->beginningOfBody());
112 // last, because the end is ignored!
113 for (pos_type p = first; p < last; ++p) {
121 // This is called _once_ from LyXText and should at least be moved into
122 // an anonymous namespace there. (Lgb)
123 int numberOfLabelHfills(LyXText const & lt, RowList::iterator rit)
125 pos_type last = lastPos(lt, rit);
126 pos_type first = rit->pos();
127 Paragraph const * par = rit->par();
129 // hfill *DO* count at the beginning of paragraphs!
131 while (first < last && par->isHfill(first))
135 last = min(last, par->beginningOfBody());
138 // last, because the end is ignored!
139 for (pos_type p = first; p < last; ++p) {
147 bool hfillExpansion(LyXText const & lt, RowList::iterator rit, pos_type pos)
149 Paragraph const * par = rit->par();
151 if (!par->isHfill(pos))
154 // at the end of a row it does not count
155 // unless another hfill exists on the line
156 if (pos >= lastPos(lt, rit)) {
157 pos_type i = rit->pos();
158 while (i < pos && !par->isHfill(i)) {
166 // at the beginning of a row it does not count, if it is not
167 // the first row of a paragaph
168 if (rit->isParStart())
171 // in some labels it does not count
172 if (par->layout()->margintype != MARGIN_MANUAL
173 && pos < par->beginningOfBody())
176 // if there is anything between the first char of the row and
177 // the specified position that is not a newline and not a hfill,
178 // the hfill will count, otherwise not
179 pos_type i = rit->pos();
180 while (i < pos && (par->isNewline(i) || par->isHfill(i)))