2002-05-30 03:37:24 +00:00
|
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
|
* \file TexRow.cpp
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2002-05-30 03:37:24 +00:00
|
|
|
|
* \author Matthias Ettrich
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author John Levon
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-05-30 03:37:24 +00:00
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "TexRow.h"
|
2007-11-29 07:04:28 +00:00
|
|
|
|
#include "support/debug.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-09-05 22:17:02 +00:00
|
|
|
|
#include <algorithm>
|
2003-05-07 21:27:29 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
void TexRow::reset()
|
|
|
|
|
{
|
1999-11-22 16:19:48 +00:00
|
|
|
|
rowlist.clear();
|
2003-05-07 21:27:29 +00:00
|
|
|
|
lastid = -1;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
lastpos = -1;
|
|
|
|
|
}
|
|
|
|
|
|
1999-11-22 16:19:48 +00:00
|
|
|
|
|
2003-05-07 21:27:29 +00:00
|
|
|
|
void TexRow::start(int id, int pos)
|
1999-11-22 16:19:48 +00:00
|
|
|
|
{
|
2003-05-07 21:27:29 +00:00
|
|
|
|
lastid = id;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
lastpos = pos;
|
|
|
|
|
}
|
|
|
|
|
|
1999-11-22 16:19:48 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
void TexRow::newline()
|
|
|
|
|
{
|
2003-05-07 21:27:29 +00:00
|
|
|
|
int const id = lastid;
|
2007-08-13 14:04:35 +00:00
|
|
|
|
RowList::value_type tmp(id, lastpos);
|
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
|
|
|
|
|
{
|
2007-08-14 09:44:38 +00:00
|
|
|
|
if (row <= 0 || row > int(rowlist.size())) {
|
2007-08-13 14:04:35 +00:00
|
|
|
|
id = -1;
|
|
|
|
|
pos = 0;
|
|
|
|
|
return false;
|
2000-08-05 05:17:18 +00:00
|
|
|
|
}
|
2007-08-13 14:04:35 +00:00
|
|
|
|
|
|
|
|
|
id = rowlist[row - 1].id();
|
|
|
|
|
pos = rowlist[row - 1].pos();
|
|
|
|
|
return true;
|
2000-08-05 05:17:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-13 14:04:35 +00:00
|
|
|
|
int TexRow::getRowFromIdPos(int id, int pos) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2007-08-13 14:04:35 +00:00
|
|
|
|
int bestrow = 0;
|
|
|
|
|
bool foundid = false;
|
|
|
|
|
|
|
|
|
|
// this loop finds the last *nonempty* row whith the same id
|
|
|
|
|
// and position <= pos
|
|
|
|
|
for (unsigned r = 0, n = rowlist.size(); r != n; ++r) {
|
|
|
|
|
if (rowlist[r].id() == id && rowlist[r].pos() <= pos) {
|
|
|
|
|
foundid = true;
|
|
|
|
|
if (rowlist[bestrow].id() != id || rowlist[r].pos() > rowlist[bestrow].pos())
|
|
|
|
|
bestrow = r;
|
|
|
|
|
} else if (foundid)
|
|
|
|
|
break;
|
|
|
|
|
}
|
2007-08-13 19:07:46 +00:00
|
|
|
|
if (!foundid)
|
|
|
|
|
return rowlist.size();
|
2007-08-13 14:04:35 +00:00
|
|
|
|
return bestrow;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|