2003-04-01 16:55:48 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "lyxrow_funcs.h"
|
|
|
|
#include "lyxtext.h"
|
|
|
|
#include "paragraph.h"
|
|
|
|
#include "lyxlayout.h"
|
2003-08-22 07:49:57 +00:00
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
#include "support/LAssert.h"
|
2003-04-01 16:55:48 +00:00
|
|
|
|
|
|
|
#include <boost/next_prior.hpp>
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
using lyx::pos_type;
|
2003-08-22 07:49:57 +00:00
|
|
|
using lyx::support::Assert;
|
2003-08-14 08:34:13 +00:00
|
|
|
|
2003-04-01 16:55:48 +00:00
|
|
|
using std::max;
|
|
|
|
using std::min;
|
2003-08-22 07:49:57 +00:00
|
|
|
using std::endl;
|
2003-04-01 16:55:48 +00:00
|
|
|
|
|
|
|
|
2003-08-15 08:03:54 +00:00
|
|
|
bool isParEnd(Paragraph const & par, RowList::iterator rit)
|
2003-04-01 16:55:48 +00:00
|
|
|
{
|
2003-08-22 07:49:57 +00:00
|
|
|
#if 0
|
|
|
|
if ((boost::next(rit) == par.rows.end()) != (rit->end() >= par.size())) {
|
|
|
|
lyxerr << endl;
|
|
|
|
lyxerr << "broken row 1: end: " << rit->end() << " next: "
|
|
|
|
<< boost::next(rit)->pos() << endl;
|
|
|
|
lyxerr << endl;
|
|
|
|
Assert(false);
|
|
|
|
}
|
|
|
|
#endif
|
2003-08-15 08:03:54 +00:00
|
|
|
return boost::next(rit) == par.rows.end();
|
2003-04-01 16:55:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-15 08:03:54 +00:00
|
|
|
pos_type lastPos(Paragraph const & par, RowList::iterator rit)
|
2003-04-01 16:55:48 +00:00
|
|
|
{
|
2003-08-15 08:03:54 +00:00
|
|
|
if (par.empty())
|
2003-04-01 16:55:48 +00:00
|
|
|
return 0;
|
|
|
|
|
2003-08-15 08:03:54 +00:00
|
|
|
if (isParEnd(par, rit))
|
|
|
|
return par.size() - 1;
|
2003-07-29 01:46:09 +00:00
|
|
|
|
2003-08-22 07:49:57 +00:00
|
|
|
if (1 && boost::next(rit)->pos() != rit->end()) {
|
|
|
|
lyxerr << endl;
|
|
|
|
lyxerr << "broken row 2: end: " << rit->end() << " next: "
|
|
|
|
<< boost::next(rit)->pos() << endl;
|
|
|
|
lyxerr << endl;
|
|
|
|
Assert(false);
|
|
|
|
}
|
2003-07-29 01:46:09 +00:00
|
|
|
return boost::next(rit)->pos() - 1;
|
2003-04-01 16:55:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2003-08-22 07:49:57 +00:00
|
|
|
bool nextRowIsAllInset(Paragraph const & par, pos_type last)
|
2003-04-01 16:55:48 +00:00
|
|
|
{
|
2003-08-15 08:03:54 +00:00
|
|
|
if (last + 1 >= par.size())
|
2003-04-01 16:55:48 +00:00
|
|
|
return false;
|
|
|
|
|
2003-08-15 08:03:54 +00:00
|
|
|
if (!par.isInset(last + 1))
|
2003-04-01 16:55:48 +00:00
|
|
|
return false;
|
|
|
|
|
2003-08-15 08:03:54 +00:00
|
|
|
InsetOld const * i = par.getInset(last + 1);
|
2003-04-01 16:55:48 +00:00
|
|
|
return i->needFullRow() || i->display();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anon namespace
|
|
|
|
|
|
|
|
|
2003-08-15 08:03:54 +00:00
|
|
|
pos_type lastPrintablePos(Paragraph const & par, RowList::iterator rit)
|
2003-04-01 16:55:48 +00:00
|
|
|
{
|
2003-08-15 08:03:54 +00:00
|
|
|
pos_type const last = lastPos(par, rit);
|
2003-04-01 16:55:48 +00:00
|
|
|
|
|
|
|
// if this row is an end of par, just act like lastPos()
|
2003-08-15 08:03:54 +00:00
|
|
|
if (isParEnd(par, rit))
|
2003-04-01 16:55:48 +00:00
|
|
|
return last;
|
|
|
|
|
2003-08-15 08:03:54 +00:00
|
|
|
if (!nextRowIsAllInset(par, last) && par.isSeparator(last))
|
2003-04-01 16:55:48 +00:00
|
|
|
return last - 1;
|
|
|
|
|
|
|
|
return last;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-15 08:03:54 +00:00
|
|
|
int numberOfSeparators(Paragraph const & par, RowList::iterator rit)
|
2003-04-01 16:55:48 +00:00
|
|
|
{
|
2003-08-15 08:03:54 +00:00
|
|
|
pos_type const last = lastPrintablePos(par, rit);
|
2003-07-29 01:46:09 +00:00
|
|
|
int n = 0;
|
2003-08-15 08:03:54 +00:00
|
|
|
pos_type p = max(rit->pos(), par.beginningOfBody());
|
2003-07-29 01:46:09 +00:00
|
|
|
for ( ; p < last; ++p)
|
2003-08-15 08:03:54 +00:00
|
|
|
if (par.isSeparator(p))
|
2003-07-29 01:46:09 +00:00
|
|
|
++n;
|
|
|
|
return n;
|
2003-04-01 16:55:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// This is called _once_ from LyXText and should at least be moved into
|
|
|
|
// an anonymous namespace there. (Lgb)
|
2003-08-15 08:03:54 +00:00
|
|
|
int numberOfHfills(Paragraph const & par, RowList::iterator rit)
|
2003-04-01 16:55:48 +00:00
|
|
|
{
|
2003-08-15 08:03:54 +00:00
|
|
|
pos_type const last = lastPos(par, rit);
|
2003-04-01 16:55:48 +00:00
|
|
|
pos_type first = rit->pos();
|
|
|
|
|
|
|
|
// hfill *DO* count at the beginning of paragraphs!
|
|
|
|
if (first) {
|
2003-08-15 08:03:54 +00:00
|
|
|
while (first < last && par.isHfill(first))
|
2003-04-01 16:55:48 +00:00
|
|
|
++first;
|
|
|
|
}
|
|
|
|
|
2003-08-15 08:03:54 +00:00
|
|
|
first = max(first, par.beginningOfBody());
|
2003-04-01 16:55:48 +00:00
|
|
|
|
|
|
|
int n = 0;
|
|
|
|
|
|
|
|
// last, because the end is ignored!
|
2003-08-15 08:03:54 +00:00
|
|
|
for (pos_type p = first; p < last; ++p)
|
|
|
|
if (par.isHfill(p))
|
2003-04-01 16:55:48 +00:00
|
|
|
++n;
|
2003-08-15 08:03:54 +00:00
|
|
|
|
2003-04-01 16:55:48 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// This is called _once_ from LyXText and should at least be moved into
|
|
|
|
// an anonymous namespace there. (Lgb)
|
2003-08-15 08:03:54 +00:00
|
|
|
int numberOfLabelHfills(Paragraph const & par, RowList::iterator rit)
|
2003-04-01 16:55:48 +00:00
|
|
|
{
|
2003-08-15 08:03:54 +00:00
|
|
|
pos_type last = lastPos(par, rit);
|
2003-04-01 16:55:48 +00:00
|
|
|
pos_type first = rit->pos();
|
|
|
|
|
|
|
|
// hfill *DO* count at the beginning of paragraphs!
|
|
|
|
if (first) {
|
2003-08-15 08:03:54 +00:00
|
|
|
while (first < last && par.isHfill(first))
|
2003-04-01 16:55:48 +00:00
|
|
|
++first;
|
|
|
|
}
|
|
|
|
|
2003-08-15 08:03:54 +00:00
|
|
|
last = min(last, par.beginningOfBody());
|
2003-04-01 16:55:48 +00:00
|
|
|
int n = 0;
|
|
|
|
|
|
|
|
// last, because the end is ignored!
|
|
|
|
for (pos_type p = first; p < last; ++p) {
|
2003-08-15 08:03:54 +00:00
|
|
|
if (par.isHfill(p))
|
2003-04-01 16:55:48 +00:00
|
|
|
++n;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-15 08:03:54 +00:00
|
|
|
bool hfillExpansion(Paragraph const & par, RowList::iterator rit, pos_type pos)
|
2003-04-01 16:55:48 +00:00
|
|
|
{
|
2003-08-15 08:03:54 +00:00
|
|
|
if (!par.isHfill(pos))
|
2003-04-01 16:55:48 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// at the end of a row it does not count
|
|
|
|
// unless another hfill exists on the line
|
2003-08-15 08:03:54 +00:00
|
|
|
if (pos >= lastPos(par, rit))
|
|
|
|
for (pos_type i = rit->pos(); i < pos && !par.isHfill(i); ++i)
|
2003-04-01 16:55:48 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// at the beginning of a row it does not count, if it is not
|
|
|
|
// the first row of a paragaph
|
|
|
|
if (rit->isParStart())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// in some labels it does not count
|
2003-08-15 08:03:54 +00:00
|
|
|
if (par.layout()->margintype != MARGIN_MANUAL
|
|
|
|
&& pos < par.beginningOfBody())
|
2003-04-01 16:55:48 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// if there is anything between the first char of the row and
|
|
|
|
// the specified position that is not a newline and not a hfill,
|
|
|
|
// the hfill will count, otherwise not
|
|
|
|
pos_type i = rit->pos();
|
2003-08-15 08:03:54 +00:00
|
|
|
while (i < pos && (par.isNewline(i) || par.isHfill(i)))
|
2003-04-01 16:55:48 +00:00
|
|
|
++i;
|
|
|
|
|
|
|
|
return i != pos;
|
|
|
|
}
|