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 "paragraph.h"
|
2003-08-22 07:49:57 +00:00
|
|
|
|
|
2003-04-01 16:55:48 +00:00
|
|
|
|
using lyx::pos_type;
|
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-10-17 10:31:47 +00:00
|
|
|
|
pos_type lastPos(Paragraph const & par, Row const & row)
|
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-10-22 16:30:57 +00:00
|
|
|
|
pos_type pos = row.endpos() - 1;
|
2003-10-17 10:31:47 +00:00
|
|
|
|
if (pos == par.size())
|
|
|
|
|
--pos;
|
|
|
|
|
return pos;
|
2003-04-01 16:55:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-17 10:31:47 +00:00
|
|
|
|
int numberOfSeparators(Paragraph const & par, Row const & row)
|
2003-04-01 16:55:48 +00:00
|
|
|
|
{
|
2003-10-17 10:31:47 +00:00
|
|
|
|
pos_type const last = lastPos(par, row);
|
2003-07-29 01:46:09 +00:00
|
|
|
|
int n = 0;
|
2003-10-17 10:31:47 +00:00
|
|
|
|
pos_type p = max(row.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-10-17 10:31:47 +00:00
|
|
|
|
int numberOfHfills(Paragraph const & par, Row const & row)
|
2003-04-01 16:55:48 +00:00
|
|
|
|
{
|
2003-10-17 10:31:47 +00:00
|
|
|
|
pos_type const last = lastPos(par, row);
|
|
|
|
|
pos_type first = row.pos();
|
2003-04-01 16:55:48 +00:00
|
|
|
|
|
|
|
|
|
// hfill *DO* count at the beginning of paragraphs!
|
2003-10-21 16:19:05 +00:00
|
|
|
|
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-10-21 16:19:05 +00:00
|
|
|
|
}
|
2003-04-01 16:55:48 +00:00
|
|
|
|
|
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-10-17 10:31:47 +00:00
|
|
|
|
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;
|
2003-10-17 10:31:47 +00:00
|
|
|
|
}
|
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-10-17 10:31:47 +00:00
|
|
|
|
int numberOfLabelHfills(Paragraph const & par, Row const & row)
|
2003-04-01 16:55:48 +00:00
|
|
|
|
{
|
2003-10-17 10:31:47 +00:00
|
|
|
|
pos_type last = lastPos(par, row);
|
|
|
|
|
pos_type first = row.pos();
|
2003-04-01 16:55:48 +00:00
|
|
|
|
|
|
|
|
|
// hfill *DO* count at the beginning of paragraphs!
|
2003-10-21 16:19:05 +00:00
|
|
|
|
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-10-21 16:19:05 +00:00
|
|
|
|
}
|
2003-04-01 16:55:48 +00:00
|
|
|
|
|
2003-08-15 08:03:54 +00:00
|
|
|
|
last = min(last, par.beginningOfBody());
|
2003-04-01 16:55:48 +00:00
|
|
|
|
int n = 0;
|
|
|
|
|
|
2003-10-17 10:31:47 +00:00
|
|
|
|
// last, because the end is ignored
|
2003-04-01 16:55:48 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
2003-10-17 10:31:47 +00:00
|
|
|
|
|
2003-04-01 16:55:48 +00:00
|
|
|
|
return n;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-17 10:31:47 +00:00
|
|
|
|
bool hfillExpansion(Paragraph const & par, Row const & row, 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-10-22 16:30:57 +00:00
|
|
|
|
if (pos >= row.endpos()) {
|
2003-10-17 10:31:47 +00:00
|
|
|
|
for (pos_type i = row.pos(); i < pos && !par.isHfill(i); ++i)
|
2003-04-01 16:55:48 +00:00
|
|
|
|
return false;
|
2003-10-20 11:41:21 +00:00
|
|
|
|
}
|
2003-04-01 16:55:48 +00:00
|
|
|
|
|
|
|
|
|
// at the beginning of a row it does not count, if it is not
|
|
|
|
|
// the first row of a paragaph
|
2003-10-22 16:30:57 +00:00
|
|
|
|
if (row.pos() == 0)
|
2003-04-01 16:55:48 +00:00
|
|
|
|
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
|
2003-10-17 10:31:47 +00:00
|
|
|
|
pos_type i = row.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;
|
|
|
|
|
}
|