2003-08-23 00:17:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file lyxrow_funcs.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
2003-04-01 16:55:48 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "lyxrow_funcs.h"
|
2003-08-22 07:49:57 +00:00
|
|
|
|
#include "debug.h"
|
2003-09-06 12:36:58 +00:00
|
|
|
|
#include "lyxlayout.h"
|
|
|
|
|
#include "lyxrow.h"
|
|
|
|
|
#include "lyxtext.h"
|
|
|
|
|
#include "paragraph.h"
|
2003-08-22 07:49:57 +00:00
|
|
|
|
|
|
|
|
|
#include "support/LAssert.h"
|
2003-04-01 16:55:48 +00:00
|
|
|
|
|
|
|
|
|
#include <boost/next_prior.hpp>
|
|
|
|
|
|
|
|
|
|
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-09-04 15:21:34 +00:00
|
|
|
|
#if 1
|
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
|
|
|
|
}
|
2003-09-04 15:21:34 +00:00
|
|
|
|
#else
|
|
|
|
|
pos_type lastPos(Paragraph const &, RowList::iterator rit)
|
2003-04-01 16:55:48 +00:00
|
|
|
|
{
|
2003-09-04 15:21:34 +00:00
|
|
|
|
return rit->end() - 1;
|
2003-04-01 16:55:48 +00:00
|
|
|
|
}
|
2003-09-04 15:21:34 +00:00
|
|
|
|
#endif
|
2003-04-01 16:55:48 +00:00
|
|
|
|
|
|
|
|
|
|
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-09-04 15:21:34 +00:00
|
|
|
|
pos_type const last = lastPos(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;
|
|
|
|
|
}
|