2002-05-30 03:37:24 +00:00
|
|
|
/**
|
|
|
|
* \file texrow.C
|
|
|
|
* Copyright 1995-2002 the LyX Team
|
|
|
|
* Read the file COPYING
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2002-05-30 03:37:24 +00:00
|
|
|
* \author Matthias Ettrich
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2000-08-05 05:17:18 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "texrow.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "paragraph.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-08-05 05:17:18 +00:00
|
|
|
using std::find_if;
|
2002-05-30 03:37:24 +00:00
|
|
|
using std::for_each;
|
2000-08-07 20:58:24 +00:00
|
|
|
using std::endl;
|
1999-11-22 16:19:48 +00:00
|
|
|
|
2002-05-30 03:37:24 +00:00
|
|
|
namespace {
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2002-05-30 03:37:24 +00:00
|
|
|
/// function object returning true when row number is found
|
|
|
|
class same_rownumber {
|
|
|
|
public:
|
|
|
|
same_rownumber(int row) : row_(row) {}
|
|
|
|
bool operator()(TexRow::RowList::value_type const & vt) const {
|
|
|
|
return vt.rownumber() == row_;
|
|
|
|
}
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2002-05-30 03:37:24 +00:00
|
|
|
private:
|
|
|
|
int row_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// increment the pos value of the argument if the par id
|
|
|
|
/// is the same, and the pos parameter is larger
|
|
|
|
class increase_pos {
|
|
|
|
public:
|
|
|
|
increase_pos(int id, int pos)
|
|
|
|
: id_(id), pos_(pos) {}
|
|
|
|
|
|
|
|
void operator()(TexRow::RowList::value_type & vt) const {
|
|
|
|
if (vt.id() != id_ || vt.pos() >= pos_)
|
|
|
|
return;
|
|
|
|
vt.pos(vt.pos() + 1);
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2002-05-30 03:37:24 +00:00
|
|
|
lyxerr[Debug::INFO]
|
|
|
|
<< "TeXRow::increasePos: ideally this "
|
|
|
|
"should never happen..." << endl;
|
|
|
|
|
|
|
|
// FIXME: When verified to work this clause should be deleted.
|
|
|
|
if (id_ == vt.id() && pos_ == vt.pos()) {
|
|
|
|
lyxerr[Debug::INFO]
|
|
|
|
<< "TexRow::increasePos: this should happen "
|
|
|
|
"maximum one time for each run of "
|
|
|
|
"increasePos!" << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int id_;
|
|
|
|
int pos_;
|
|
|
|
};
|
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
void TexRow::reset()
|
|
|
|
{
|
1999-11-22 16:19:48 +00:00
|
|
|
rowlist.clear();
|
1999-09-27 18:44:28 +00:00
|
|
|
count = 0;
|
|
|
|
lastpar = 0;
|
|
|
|
lastpos = -1;
|
|
|
|
}
|
|
|
|
|
1999-11-22 16:19:48 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void TexRow::start(Paragraph * par, int pos)
|
1999-11-22 16:19:48 +00:00
|
|
|
{
|
1999-09-27 18:44:28 +00:00
|
|
|
lastpar = par;
|
|
|
|
lastpos = pos;
|
|
|
|
}
|
|
|
|
|
1999-11-22 16:19:48 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
void TexRow::newline()
|
|
|
|
{
|
2002-05-30 03:37:24 +00:00
|
|
|
int const id = lastpar ? lastpar->id() : -1;
|
|
|
|
RowList::value_type tmp(id, lastpos, ++count);
|
1999-11-22 16:19:48 +00:00
|
|
|
rowlist.push_back(tmp);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-05 05:17:18 +00:00
|
|
|
bool TexRow::getIdFromRow(int row, int & id, int & pos) const
|
|
|
|
{
|
|
|
|
RowList::const_iterator cit =
|
2002-12-01 22:59:25 +00:00
|
|
|
find_if(rowlist.begin(), rowlist.end(),
|
2002-05-30 03:37:24 +00:00
|
|
|
same_rownumber(row));
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2000-08-05 05:17:18 +00:00
|
|
|
if (cit != rowlist.end()) {
|
2001-07-12 11:11:10 +00:00
|
|
|
id = cit->id();
|
|
|
|
pos = cit->pos();
|
2000-08-05 05:17:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
id = -1;
|
|
|
|
pos = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-30 03:37:24 +00:00
|
|
|
void TexRow::increasePos(int id, int pos)
|
2000-08-05 05:17:18 +00:00
|
|
|
{
|
2002-08-29 13:05:55 +00:00
|
|
|
for_each(rowlist.begin(), rowlist.end(), increase_pos(id, pos));
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-30 03:37:24 +00:00
|
|
|
TexRow & TexRow::operator+=(TexRow const & tr)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-22 16:19:48 +00:00
|
|
|
rowlist.insert(rowlist.end(), tr.rowlist.begin(), tr.rowlist.end());
|
1999-09-27 18:44:28 +00:00
|
|
|
return *this;
|
2002-03-21 17:27:08 +00:00
|
|
|
}
|