3 #include "lyxrow_funcs.h"
8 #include <boost/next_prior.hpp>
17 bool isParEnd(LyXText const & lt,
18 ParagraphList::iterator pit, RowList::iterator rit)
20 return boost::next(rit) == lt.endRow(pit);
24 pos_type lastPos(LyXText const & lt,
25 ParagraphList::iterator pit, RowList::iterator rit)
30 if (isParEnd(lt, pit, rit))
31 return pit->size() - 1;
33 return boost::next(rit)->pos() - 1;
39 bool nextRowIsAllInset(
40 ParagraphList::iterator pit, RowList::iterator rit, pos_type last)
42 if (last + 1 >= pit->size())
45 if (!pit->isInset(last + 1))
48 InsetOld const * i = pit->getInset(last + 1);
49 return i->needFullRow() || i->display();
55 pos_type lastPrintablePos(LyXText const & lt,
56 ParagraphList::iterator pit, RowList::iterator rit)
58 pos_type const last = lastPos(lt, pit, rit);
60 // if this row is an end of par, just act like lastPos()
61 if (isParEnd(lt, pit, rit))
64 if (!nextRowIsAllInset(pit, rit, last) && pit->isSeparator(last))
71 int numberOfSeparators(LyXText const & lt,
72 ParagraphList::iterator pit, RowList::iterator rit)
74 pos_type const last = lastPrintablePos(lt, pit, rit);
76 pos_type p = max(rit->pos(), pit->beginningOfBody());
77 for ( ; p < last; ++p)
78 if (pit->isSeparator(p))
84 // This is called _once_ from LyXText and should at least be moved into
85 // an anonymous namespace there. (Lgb)
86 int numberOfHfills(LyXText const & lt,
87 ParagraphList::iterator pit, RowList::iterator rit)
89 pos_type const last = lastPos(lt, pit, rit);
90 pos_type first = rit->pos();
92 // hfill *DO* count at the beginning of paragraphs!
94 while (first < last && pit->isHfill(first))
98 first = max(first, pit->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(LyXText const & lt,
114 ParagraphList::iterator pit, RowList::iterator rit)
116 pos_type last = lastPos(lt, pit, rit);
117 pos_type first = rit->pos();
119 // hfill *DO* count at the beginning of paragraphs!
121 while (first < last && pit->isHfill(first))
125 last = min(last, pit->beginningOfBody());
128 // last, because the end is ignored!
129 for (pos_type p = first; p < last; ++p) {
137 bool hfillExpansion(LyXText const & lt,
138 ParagraphList::iterator pit, RowList::iterator rit, pos_type pos)
140 if (!pit->isHfill(pos))
143 // at the end of a row it does not count
144 // unless another hfill exists on the line
145 if (pos >= lastPos(lt, pit, rit))
146 for (pos_type i = rit->pos(); i < pos && !pit->isHfill(i); ++i)
149 // at the beginning of a row it does not count, if it is not
150 // the first row of a paragaph
151 if (rit->isParStart())
154 // in some labels it does not count
155 if (pit->layout()->margintype != MARGIN_MANUAL
156 && pos < pit->beginningOfBody())
159 // if there is anything between the first char of the row and
160 // the specified position that is not a newline and not a hfill,
161 // the hfill will count, otherwise not
162 pos_type i = rit->pos();
163 while (i < pos && (pit->isNewline(i) || pit->isHfill(i)))