2004-03-30 12:14:01 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file dociterator.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
2004-07-25 00:04:42 +00:00
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
2004-03-30 12:14:01 +00:00
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
2004-03-01 17:12:09 +00:00
|
|
|
|
|
|
|
|
|
#include "dociterator.h"
|
|
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
#include "lyxtext.h"
|
|
|
|
|
#include "lyxrow.h"
|
|
|
|
|
#include "paragraph.h"
|
|
|
|
|
|
|
|
|
|
#include "mathed/math_data.h"
|
|
|
|
|
#include "mathed/math_inset.h"
|
|
|
|
|
|
|
|
|
|
#include <boost/assert.hpp>
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
using std::endl;
|
|
|
|
|
|
2004-03-01 17:12:09 +00:00
|
|
|
|
|
2004-04-13 06:27:29 +00:00
|
|
|
|
// We could be able to get rid of this if only every BufferView were
|
|
|
|
|
// associated to a buffer on construction.
|
|
|
|
|
DocIterator::DocIterator()
|
|
|
|
|
: inset_(0)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DocIterator::DocIterator(InsetBase & inset)
|
|
|
|
|
: inset_(&inset)
|
2004-03-18 16:41:45 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
DocIterator doc_iterator_begin(InsetBase & inset)
|
2004-03-18 16:41:45 +00:00
|
|
|
|
{
|
2004-03-31 19:11:56 +00:00
|
|
|
|
DocIterator dit(inset);
|
2004-03-30 08:18:09 +00:00
|
|
|
|
dit.forwardPos();
|
|
|
|
|
return dit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
DocIterator doc_iterator_end(InsetBase & inset)
|
2004-03-30 08:18:09 +00:00
|
|
|
|
{
|
2004-03-31 19:11:56 +00:00
|
|
|
|
return DocIterator(inset);
|
2004-03-18 16:41:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
InsetBase * DocIterator::nextInset()
|
2004-03-01 17:12:09 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
BOOST_ASSERT(!empty());
|
2004-03-01 17:12:09 +00:00
|
|
|
|
if (pos() == lastpos())
|
|
|
|
|
return 0;
|
2004-04-03 08:37:12 +00:00
|
|
|
|
if (inMathed())
|
2004-03-01 17:12:09 +00:00
|
|
|
|
return nextAtom().nucleus();
|
|
|
|
|
return paragraph().isInset(pos()) ? paragraph().getInset(pos()) : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
InsetBase * DocIterator::prevInset()
|
2004-03-01 17:12:09 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
BOOST_ASSERT(!empty());
|
2004-03-01 17:12:09 +00:00
|
|
|
|
if (pos() == 0)
|
|
|
|
|
return 0;
|
2004-04-03 08:37:12 +00:00
|
|
|
|
if (inMathed())
|
2004-03-01 17:12:09 +00:00
|
|
|
|
return prevAtom().nucleus();
|
|
|
|
|
return paragraph().isInset(pos() - 1) ? paragraph().getInset(pos() - 1) : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
InsetBase const * DocIterator::prevInset() const
|
2004-03-01 17:12:09 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
BOOST_ASSERT(!empty());
|
2004-03-01 17:12:09 +00:00
|
|
|
|
if (pos() == 0)
|
|
|
|
|
return 0;
|
2004-04-03 08:37:12 +00:00
|
|
|
|
if (inMathed())
|
2004-03-01 17:12:09 +00:00
|
|
|
|
return prevAtom().nucleus();
|
|
|
|
|
return paragraph().isInset(pos() - 1) ? paragraph().getInset(pos() - 1) : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
MathAtom const & DocIterator::prevAtom() const
|
2004-03-01 17:12:09 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
BOOST_ASSERT(!empty());
|
2004-03-01 17:12:09 +00:00
|
|
|
|
BOOST_ASSERT(pos() > 0);
|
|
|
|
|
return cell()[pos() - 1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
MathAtom & DocIterator::prevAtom()
|
2004-03-01 17:12:09 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
BOOST_ASSERT(!empty());
|
2004-03-01 17:12:09 +00:00
|
|
|
|
BOOST_ASSERT(pos() > 0);
|
|
|
|
|
return cell()[pos() - 1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
MathAtom const & DocIterator::nextAtom() const
|
2004-03-01 17:12:09 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
BOOST_ASSERT(!empty());
|
2004-04-13 06:27:29 +00:00
|
|
|
|
//lyxerr << "lastpos: " << lastpos() << " next atom:\n" << *this << endl;
|
2004-03-01 17:12:09 +00:00
|
|
|
|
BOOST_ASSERT(pos() < lastpos());
|
|
|
|
|
return cell()[pos()];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
MathAtom & DocIterator::nextAtom()
|
2004-03-01 17:12:09 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
BOOST_ASSERT(!empty());
|
2004-04-13 06:27:29 +00:00
|
|
|
|
//lyxerr << "lastpos: " << lastpos() << " next atom:\n" << *this << endl;
|
2004-03-01 17:12:09 +00:00
|
|
|
|
BOOST_ASSERT(pos() < lastpos());
|
|
|
|
|
return cell()[pos()];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
LyXText * DocIterator::text() const
|
2004-03-01 17:12:09 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
BOOST_ASSERT(!empty());
|
2004-03-18 12:53:43 +00:00
|
|
|
|
return top().text();
|
2004-03-01 17:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
Paragraph & DocIterator::paragraph()
|
2004-03-01 17:12:09 +00:00
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(inTexted());
|
2004-03-18 12:53:43 +00:00
|
|
|
|
return top().paragraph();
|
2004-03-01 17:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
Paragraph const & DocIterator::paragraph() const
|
2004-03-01 17:12:09 +00:00
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(inTexted());
|
2004-03-18 12:53:43 +00:00
|
|
|
|
return top().paragraph();
|
2004-03-01 17:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
Row & DocIterator::textRow()
|
2004-03-01 17:12:09 +00:00
|
|
|
|
{
|
|
|
|
|
return *paragraph().getRow(pos());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
Row const & DocIterator::textRow() const
|
2004-03-01 17:12:09 +00:00
|
|
|
|
{
|
|
|
|
|
return *paragraph().getRow(pos());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
DocIterator::par_type DocIterator::lastpar() const
|
2004-03-01 17:12:09 +00:00
|
|
|
|
{
|
|
|
|
|
return inMathed() ? 0 : text()->paragraphs().size() - 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
DocIterator::pos_type DocIterator::lastpos() const
|
2004-03-01 17:12:09 +00:00
|
|
|
|
{
|
|
|
|
|
return inMathed() ? cell().size() : paragraph().size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
DocIterator::row_type DocIterator::crow() const
|
2004-03-01 17:12:09 +00:00
|
|
|
|
{
|
|
|
|
|
return paragraph().row(pos());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
DocIterator::row_type DocIterator::lastcrow() const
|
2004-03-01 17:12:09 +00:00
|
|
|
|
{
|
|
|
|
|
return paragraph().rows.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
DocIterator::idx_type DocIterator::lastidx() const
|
2004-03-01 17:12:09 +00:00
|
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
|
return top().lastidx();
|
2004-03-01 17:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
size_t DocIterator::nargs() const
|
2004-03-01 17:12:09 +00:00
|
|
|
|
{
|
|
|
|
|
// assume 1x1 grid for main text
|
2004-03-18 12:53:43 +00:00
|
|
|
|
return top().nargs();
|
2004-03-01 17:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
size_t DocIterator::ncols() const
|
2004-03-01 17:12:09 +00:00
|
|
|
|
{
|
|
|
|
|
// assume 1x1 grid for main text
|
2004-03-18 12:53:43 +00:00
|
|
|
|
return top().ncols();
|
2004-03-01 17:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
size_t DocIterator::nrows() const
|
2004-03-01 17:12:09 +00:00
|
|
|
|
{
|
|
|
|
|
// assume 1x1 grid for main text
|
2004-03-18 12:53:43 +00:00
|
|
|
|
return top().nrows();
|
2004-03-01 17:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
DocIterator::row_type DocIterator::row() const
|
2004-03-01 17:12:09 +00:00
|
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
|
return top().row();
|
2004-03-01 17:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
DocIterator::col_type DocIterator::col() const
|
2004-03-01 17:12:09 +00:00
|
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
|
return top().col();
|
2004-03-01 17:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
MathArray const & DocIterator::cell() const
|
2004-03-01 17:12:09 +00:00
|
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
|
BOOST_ASSERT(inMathed());
|
2004-03-01 17:12:09 +00:00
|
|
|
|
return top().cell();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
MathArray & DocIterator::cell()
|
2004-03-01 17:12:09 +00:00
|
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
|
BOOST_ASSERT(inMathed());
|
2004-03-01 17:12:09 +00:00
|
|
|
|
return top().cell();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
bool DocIterator::inMathed() const
|
2004-03-01 17:12:09 +00:00
|
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
|
return !empty() && inset().inMathed();
|
2004-03-01 17:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
bool DocIterator::inTexted() const
|
2004-03-01 17:12:09 +00:00
|
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
|
return !empty() && !inset().inMathed();
|
2004-03-01 17:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
LyXText * DocIterator::innerText() const
|
2004-03-01 17:12:09 +00:00
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(!empty());
|
2004-03-18 12:53:43 +00:00
|
|
|
|
// go up until first non-0 text is hit
|
|
|
|
|
// (innermost text is 0 in mathed)
|
|
|
|
|
for (int i = size() - 1; i >= 0; --i)
|
|
|
|
|
if (operator[](i).text())
|
|
|
|
|
return operator[](i).text();
|
|
|
|
|
return 0;
|
2004-03-01 17:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
InsetBase * DocIterator::innerInsetOfType(int code) const
|
2004-03-01 17:12:09 +00:00
|
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
|
for (int i = size() - 1; i >= 0; --i)
|
2004-03-01 17:12:09 +00:00
|
|
|
|
if (operator[](i).inset_->lyxCode() == code)
|
|
|
|
|
return operator[](i).inset_;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
void DocIterator::forwardPos()
|
2004-03-01 17:12:09 +00:00
|
|
|
|
{
|
2004-03-30 08:18:09 +00:00
|
|
|
|
//this dog bites his tail
|
|
|
|
|
if (empty()) {
|
|
|
|
|
push_back(CursorSlice(*inset_));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-01 17:12:09 +00:00
|
|
|
|
CursorSlice & top = back();
|
2004-03-25 09:16:36 +00:00
|
|
|
|
//lyxerr << "XXX\n" << *this << endl;
|
|
|
|
|
|
|
|
|
|
// this is used twice and shows up in the profiler!
|
|
|
|
|
pos_type const lastp = lastpos();
|
2004-03-01 17:12:09 +00:00
|
|
|
|
|
|
|
|
|
// move into an inset to the right if possible
|
|
|
|
|
InsetBase * n = 0;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
|
|
|
|
|
if (top.pos() != lastp) {
|
2004-03-01 17:12:09 +00:00
|
|
|
|
// this is impossible for pos() == size()
|
|
|
|
|
if (inMathed()) {
|
|
|
|
|
n = (top.cell().begin() + top.pos())->nucleus();
|
|
|
|
|
} else {
|
|
|
|
|
if (paragraph().isInset(top.pos()))
|
|
|
|
|
n = paragraph().getInset(top.pos());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (n && n->isActive()) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
//lyxerr << "... descend" << endl;
|
2004-03-18 12:53:43 +00:00
|
|
|
|
push_back(CursorSlice(*n));
|
2004-03-01 17:12:09 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// otherwise move on one position if possible
|
|
|
|
|
if (top.pos() < lastp) {
|
|
|
|
|
//lyxerr << "... next pos" << endl;
|
2004-03-01 17:12:09 +00:00
|
|
|
|
++top.pos();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2004-03-25 09:16:36 +00:00
|
|
|
|
//lyxerr << "... no next pos" << endl;
|
2004-03-01 17:12:09 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// otherwise move on one paragraph if possible
|
2004-03-01 17:12:09 +00:00
|
|
|
|
if (top.par() < lastpar()) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
//lyxerr << "... next par" << endl;
|
2004-03-01 17:12:09 +00:00
|
|
|
|
++top.par();
|
|
|
|
|
top.pos() = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2004-03-25 09:16:36 +00:00
|
|
|
|
//lyxerr << "... no next par" << endl;
|
2004-03-01 17:12:09 +00:00
|
|
|
|
|
|
|
|
|
// otherwise try to move on one cell if possible
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (top.idx() < lastidx()) {
|
|
|
|
|
//lyxerr << "... next idx" << endl;
|
2004-03-01 17:12:09 +00:00
|
|
|
|
++top.idx();
|
|
|
|
|
top.par() = 0;
|
|
|
|
|
top.pos() = 0;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return;
|
2004-03-01 17:12:09 +00:00
|
|
|
|
}
|
2004-03-25 09:16:36 +00:00
|
|
|
|
//lyxerr << "... no next idx" << endl;
|
2004-03-01 17:12:09 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// otherwise leave inset and jump over inset as a whole
|
2004-03-01 17:12:09 +00:00
|
|
|
|
pop_back();
|
|
|
|
|
// 'top' is invalid now...
|
|
|
|
|
if (size())
|
2004-03-18 16:41:45 +00:00
|
|
|
|
++back().pos();
|
2004-03-25 09:16:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
void DocIterator::forwardPar()
|
2004-03-28 22:00:22 +00:00
|
|
|
|
{
|
|
|
|
|
forwardPos();
|
|
|
|
|
while (!empty() && (!inTexted() || pos() != 0))
|
|
|
|
|
forwardPos();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
void DocIterator::forwardChar()
|
2004-03-25 09:16:36 +00:00
|
|
|
|
{
|
2004-03-28 22:00:22 +00:00
|
|
|
|
forwardPos();
|
2004-03-25 09:16:36 +00:00
|
|
|
|
while (size() != 0 && pos() == lastpos())
|
2004-04-03 08:37:12 +00:00
|
|
|
|
forwardPos();
|
2004-03-25 09:16:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
void DocIterator::forwardInset()
|
2004-03-27 12:37:41 +00:00
|
|
|
|
{
|
2004-04-03 08:37:12 +00:00
|
|
|
|
forwardPos();
|
2004-03-27 12:37:41 +00:00
|
|
|
|
while (size() != 0 && (pos() == lastpos() || nextInset() == 0))
|
|
|
|
|
forwardPos();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
void DocIterator::backwardChar()
|
2004-03-25 09:16:36 +00:00
|
|
|
|
{
|
2004-03-30 08:18:09 +00:00
|
|
|
|
backwardPos();
|
|
|
|
|
while (size() != 0 && pos() == lastpos())
|
2004-04-03 08:37:12 +00:00
|
|
|
|
backwardPos();
|
2004-03-30 08:18:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
void DocIterator::backwardPos()
|
2004-03-30 08:18:09 +00:00
|
|
|
|
{
|
|
|
|
|
//this dog bites his tail
|
|
|
|
|
if (empty()) {
|
|
|
|
|
push_back(CursorSlice(*inset_));
|
|
|
|
|
back().idx() = lastidx();
|
|
|
|
|
back().par() = lastpar();
|
|
|
|
|
back().pos() = lastpos();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CursorSlice & top = back();
|
|
|
|
|
|
|
|
|
|
if (top.pos() != 0) {
|
|
|
|
|
--top.pos();
|
|
|
|
|
} else if (top.par() != 0) {
|
|
|
|
|
--top.par();
|
|
|
|
|
top.pos() = lastpos();
|
|
|
|
|
return;
|
|
|
|
|
} else if (top.idx() != 0) {
|
|
|
|
|
--top.idx();
|
|
|
|
|
top.par() = lastpar();
|
|
|
|
|
top.pos() = lastpos();
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
pop_back();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// move into an inset to the left if possible
|
|
|
|
|
InsetBase * n = 0;
|
2004-04-03 08:37:12 +00:00
|
|
|
|
|
2004-03-30 08:18:09 +00:00
|
|
|
|
if (inMathed()) {
|
|
|
|
|
n = (top.cell().begin() + top.pos())->nucleus();
|
|
|
|
|
} else {
|
|
|
|
|
if (paragraph().isInset(top.pos()))
|
|
|
|
|
n = paragraph().getInset(top.pos());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (n && n->isActive()) {
|
|
|
|
|
push_back(CursorSlice(*n));
|
|
|
|
|
back().idx() = lastidx();
|
|
|
|
|
back().par() = lastpar();
|
|
|
|
|
back().pos() = lastpos();
|
|
|
|
|
}
|
2004-03-01 17:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-08-14 21:03:55 +00:00
|
|
|
|
bool DocIterator::hasPart(DocIterator const & it) const
|
|
|
|
|
{
|
|
|
|
|
// it can't be a part if it is larger
|
|
|
|
|
if (it.size() > size())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// as inset adresses are the 'last' level
|
|
|
|
|
return &it.back().inset() == &operator[](it.size() - 1).inset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
std::ostream & operator<<(std::ostream & os, DocIterator const & dit)
|
2004-03-01 17:12:09 +00:00
|
|
|
|
{
|
2004-03-08 21:14:45 +00:00
|
|
|
|
for (size_t i = 0, n = dit.size(); i != n; ++i)
|
|
|
|
|
os << " " << dit.operator[](i) << "\n";
|
2004-03-01 17:12:09 +00:00
|
|
|
|
return os;
|
|
|
|
|
}
|
2004-03-08 21:14:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
StableDocIterator::StableDocIterator(const DocIterator & dit)
|
2004-03-08 21:14:45 +00:00
|
|
|
|
{
|
|
|
|
|
data_ = dit;
|
|
|
|
|
for (size_t i = 0, n = data_.size(); i != n; ++i)
|
|
|
|
|
data_[i].inset_ = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
DocIterator
|
|
|
|
|
StableDocIterator::asDocIterator(InsetBase * inset) const
|
2004-03-08 21:14:45 +00:00
|
|
|
|
{
|
|
|
|
|
// this function re-creates the cache of inset pointers
|
2004-03-25 09:16:36 +00:00
|
|
|
|
//lyxerr << "converting:\n" << *this << endl;
|
2004-03-31 19:11:56 +00:00
|
|
|
|
DocIterator dit = DocIterator(*inset);
|
2004-03-08 21:14:45 +00:00
|
|
|
|
for (size_t i = 0, n = data_.size(); i != n; ++i) {
|
|
|
|
|
dit.push_back(data_[i]);
|
|
|
|
|
dit.back().inset_ = inset;
|
|
|
|
|
if (i + 1 != n)
|
|
|
|
|
inset = dit.nextInset();
|
|
|
|
|
}
|
2004-03-25 09:16:36 +00:00
|
|
|
|
//lyxerr << "convert:\n" << *this << " to:\n" << dit << endl;
|
2004-03-08 21:14:45 +00:00
|
|
|
|
return dit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
std::ostream & operator<<(std::ostream & os, StableDocIterator const & dit)
|
2004-03-08 21:14:45 +00:00
|
|
|
|
{
|
|
|
|
|
for (size_t i = 0, n = dit.data_.size(); i != n; ++i)
|
|
|
|
|
os << " " << dit.data_[i] << "\n";
|
|
|
|
|
return os;
|
|
|
|
|
}
|