1999-09-27 18:44:28 +00:00
|
|
|
/* This file is part of
|
1999-11-15 12:01:38 +00:00
|
|
|
* ======================================================
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
2000-03-09 03:36:48 +00:00
|
|
|
* Copyright 1995 Matthias Ettrich
|
|
|
|
* Copyright 1995-2000 The LyX Team.
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
1999-11-15 12:01:38 +00:00
|
|
|
* ====================================================== */
|
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
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "texrow.h"
|
|
|
|
#include "lyxparagraph.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;
|
2000-08-07 20:58:24 +00:00
|
|
|
using std::endl;
|
1999-11-22 16:19:48 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// Delete linked list
|
|
|
|
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
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// Defines paragraph and position for the beginning of this row
|
1999-11-22 16:19:48 +00:00
|
|
|
void TexRow::start(LyXParagraph * par, int pos)
|
|
|
|
{
|
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
|
|
|
// Insert node when line is completed
|
|
|
|
void TexRow::newline()
|
|
|
|
{
|
1999-11-22 16:19:48 +00:00
|
|
|
RowItem tmp;
|
2000-06-08 23:16:16 +00:00
|
|
|
tmp.pos(lastpos);
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lastpar)
|
2000-06-08 23:16:16 +00:00
|
|
|
tmp.id(lastpar->id());
|
1999-09-27 18:44:28 +00:00
|
|
|
else
|
2000-06-08 23:16:16 +00:00
|
|
|
tmp.id(-1);
|
|
|
|
tmp.rownumber(++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
|
|
|
class same_rownumber {
|
|
|
|
public:
|
|
|
|
same_rownumber(TexRow::RowList::value_type const & v):vt(v){}
|
|
|
|
bool operator()(TexRow::RowList::value_type const & vt1) const {
|
|
|
|
return vt.rownumber() == vt1.rownumber();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2000-08-05 05:17:18 +00:00
|
|
|
private:
|
|
|
|
TexRow::RowList::value_type const & vt;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool TexRow::getIdFromRow(int row, int & id, int & pos) const
|
|
|
|
{
|
|
|
|
RowList::value_type vt;
|
|
|
|
vt.rownumber(row);
|
|
|
|
RowList::const_iterator cit =
|
|
|
|
find_if(rowlist.begin(), rowlist.end(), same_rownumber(vt));
|
|
|
|
|
|
|
|
if (cit != rowlist.end()) {
|
|
|
|
#if 0
|
1999-11-22 16:19:48 +00:00
|
|
|
RowList::iterator kit = rowlist.begin();
|
2000-08-05 05:17:18 +00:00
|
|
|
RowList::iterator end = rowlist.end();
|
1999-09-27 18:44:28 +00:00
|
|
|
// Increase the pos of all rows with the
|
|
|
|
// same id (and where the pos is larger)
|
|
|
|
// to avoid putting errorinsets at the
|
|
|
|
// same pos.
|
2000-11-04 10:00:12 +00:00
|
|
|
for (; kit != end; ++kit) {
|
1999-11-22 16:19:48 +00:00
|
|
|
if (&(*kit) != &(*cit)
|
2000-06-08 23:16:16 +00:00
|
|
|
&& (*kit).id() == (*cit).id()
|
|
|
|
&& (*kit).pos() >= (*cit).pos())
|
|
|
|
(*kit).pos((*kit).pos() + 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2000-08-05 05:17:18 +00:00
|
|
|
#endif
|
2000-06-08 23:16:16 +00:00
|
|
|
id = (*cit).id();
|
|
|
|
pos = (*cit).pos();
|
2000-08-05 05:17:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
id = -1;
|
|
|
|
pos = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// should perhaps have a better name...
|
|
|
|
// Increase the pos of all rows with the
|
|
|
|
// same id (and where the pos is larger)
|
|
|
|
// to avoid putting errorinsets at the
|
|
|
|
// same pos.
|
|
|
|
void TexRow::increasePos(int id, int pos) const
|
|
|
|
{
|
|
|
|
RowList::iterator kit = rowlist.begin();
|
|
|
|
RowList::iterator end = rowlist.end();
|
2000-11-04 10:00:12 +00:00
|
|
|
for (; kit != end; ++kit) {
|
2000-08-05 05:17:18 +00:00
|
|
|
if (id == (*kit).id()
|
|
|
|
&& pos < (*kit).pos()) {
|
|
|
|
(*kit).pos((*kit).pos() + 1);
|
2001-01-22 16:10:19 +00:00
|
|
|
lyxerr.debug()
|
|
|
|
<< "TeXRow::increasePos: ideally this "
|
2000-08-05 05:17:18 +00:00
|
|
|
"should never happen..." << endl;
|
|
|
|
}
|
|
|
|
// When verified to work this clause should be deleted.
|
|
|
|
if (id == (*kit).id()
|
|
|
|
&& pos == (*kit).pos()) {
|
2001-01-22 16:10:19 +00:00
|
|
|
lyxerr.debug()
|
|
|
|
<< "TexRow::increasePos: this should happen "
|
2000-08-05 05:17:18 +00:00
|
|
|
"maximum one time for each run of "
|
|
|
|
"increasePos!" << endl;
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-22 16:19:48 +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;
|
|
|
|
}
|