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
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2003-08-23 00:17:00 +00:00
|
|
|
* \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"
|
2008-02-18 07:14:42 +00:00
|
|
|
|
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
|
|
|
{
|
2011-03-10 04:05:49 +00:00
|
|
|
if (started)
|
|
|
|
return;
|
|
|
|
|
2003-05-07 21:27:29 +00:00
|
|
|
lastid = id;
|
1999-09-27 18:44:28 +00:00
|
|
|
lastpos = pos;
|
2011-03-10 04:05:49 +00:00
|
|
|
started = true;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
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);
|
2011-03-10 04:05:49 +00:00
|
|
|
started = false;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2010-02-08 17:39:55 +00:00
|
|
|
void TexRow::newlines(int num_lines)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < num_lines; ++i) {
|
|
|
|
newline();
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
bool foundid = false;
|
|
|
|
|
2008-10-18 16:07:04 +00:00
|
|
|
// this loop finds the last *nonempty* row with the same id
|
2007-08-13 14:04:35 +00:00
|
|
|
// and position <= pos
|
2008-10-18 16:07:04 +00:00
|
|
|
RowList::const_iterator bestrow = rowlist.begin();
|
|
|
|
RowList::const_iterator it = rowlist.begin();
|
|
|
|
RowList::const_iterator const end = rowlist.end();
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
if (it->id() == id && it->pos() <= pos) {
|
2007-08-13 14:04:35 +00:00
|
|
|
foundid = true;
|
2008-10-18 16:07:04 +00:00
|
|
|
if (bestrow->id() != id || it->pos() > bestrow->pos())
|
|
|
|
bestrow = it;
|
2007-08-13 14:04:35 +00:00
|
|
|
} else if (foundid)
|
|
|
|
break;
|
|
|
|
}
|
2007-08-13 19:07:46 +00:00
|
|
|
if (!foundid)
|
|
|
|
return rowlist.size();
|
2010-04-16 18:52:40 +00:00
|
|
|
return distance(rowlist.begin(), bestrow) + 1;
|
2002-03-21 17:27:08 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|