2003-12-15 11:36:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file cursor_slice.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
2004-01-13 12:28:35 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author Matthias Ettrich
|
2003-12-15 11:36:19 +00:00
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
2004-01-13 12:28:35 +00:00
|
|
|
|
* \author J<EFBFBD>rgen Vigna
|
2003-12-15 11:36:19 +00:00
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "cursor_slice.h"
|
|
|
|
|
#include "debug.h"
|
2004-01-20 14:25:24 +00:00
|
|
|
|
#include "lyxtext.h"
|
|
|
|
|
#include "paragraph.h"
|
2003-12-15 11:36:19 +00:00
|
|
|
|
|
|
|
|
|
#include "mathed/math_inset.h"
|
2004-01-14 18:17:02 +00:00
|
|
|
|
#include "mathed/math_data.h"
|
|
|
|
|
|
2003-12-15 11:36:19 +00:00
|
|
|
|
#include "insets/updatableinset.h"
|
|
|
|
|
|
2004-01-14 18:17:02 +00:00
|
|
|
|
|
2003-12-15 11:36:19 +00:00
|
|
|
|
#include <boost/assert.hpp>
|
|
|
|
|
|
|
|
|
|
using std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CursorSlice::CursorSlice()
|
2004-11-24 21:53:46 +00:00
|
|
|
|
: inset_(0), idx_(0), pit_(0), pos_(0), boundary_(false)
|
2003-12-15 11:36:19 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
CursorSlice::CursorSlice(InsetBase & p)
|
2004-11-24 21:53:46 +00:00
|
|
|
|
: inset_(&p), idx_(0), pit_(0), pos_(0), boundary_(false)
|
2003-12-15 11:36:19 +00:00
|
|
|
|
{
|
2004-03-18 16:41:45 +00:00
|
|
|
|
BOOST_ASSERT(inset_);
|
2003-12-15 11:36:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-16 10:55:19 +00:00
|
|
|
|
size_t CursorSlice::nargs() const
|
|
|
|
|
{
|
2004-02-20 11:00:41 +00:00
|
|
|
|
BOOST_ASSERT(inset_);
|
2004-01-16 10:55:19 +00:00
|
|
|
|
return inset_->nargs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
size_t CursorSlice::nrows() const
|
|
|
|
|
{
|
2004-02-20 11:00:41 +00:00
|
|
|
|
BOOST_ASSERT(inset_);
|
2004-01-20 14:25:24 +00:00
|
|
|
|
return inset_->nrows();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-16 10:55:19 +00:00
|
|
|
|
size_t CursorSlice::ncols() const
|
|
|
|
|
{
|
2004-02-20 11:00:41 +00:00
|
|
|
|
BOOST_ASSERT(inset_);
|
2004-01-16 10:55:19 +00:00
|
|
|
|
return inset_->ncols();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-15 17:34:44 +00:00
|
|
|
|
CursorSlice::pos_type CursorSlice::lastpos() const
|
|
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
|
BOOST_ASSERT(inset_);
|
|
|
|
|
return inset_->asMathInset() ? cell().size() : paragraph().size();
|
2004-01-15 17:34:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CursorSlice::row_type CursorSlice::row() const
|
2003-12-15 11:36:19 +00:00
|
|
|
|
{
|
2004-01-15 17:34:44 +00:00
|
|
|
|
BOOST_ASSERT(asMathInset());
|
2004-01-16 12:36:23 +00:00
|
|
|
|
return asMathInset()->row(idx_);
|
2003-12-15 11:36:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-15 17:34:44 +00:00
|
|
|
|
CursorSlice::col_type CursorSlice::col() const
|
2003-12-15 11:36:19 +00:00
|
|
|
|
{
|
2004-01-15 17:34:44 +00:00
|
|
|
|
BOOST_ASSERT(asMathInset());
|
2004-01-16 12:36:23 +00:00
|
|
|
|
return asMathInset()->col(idx_);
|
2003-12-15 11:36:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-15 17:34:44 +00:00
|
|
|
|
MathInset * CursorSlice::asMathInset() const
|
2003-12-15 11:36:19 +00:00
|
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
|
BOOST_ASSERT(inset_);
|
|
|
|
|
return inset_->asMathInset();
|
2004-01-15 17:34:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UpdatableInset * CursorSlice::asUpdatableInset() const
|
|
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
|
BOOST_ASSERT(inset_);
|
|
|
|
|
return inset_->asUpdatableInset();
|
2003-12-15 11:36:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MathArray & CursorSlice::cell() const
|
|
|
|
|
{
|
2004-01-15 11:58:35 +00:00
|
|
|
|
BOOST_ASSERT(asMathInset());
|
2003-12-15 11:36:19 +00:00
|
|
|
|
return asMathInset()->cell(idx_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-01-31 16:29:48 +00:00
|
|
|
|
LyXText * CursorSlice::text()
|
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(inset_);
|
|
|
|
|
return inset_->getText(idx_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LyXText const * CursorSlice::text() const
|
2003-12-15 11:36:19 +00:00
|
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
|
BOOST_ASSERT(inset_);
|
|
|
|
|
return inset_->getText(idx_);
|
2003-12-15 11:36:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
Paragraph & CursorSlice::paragraph()
|
|
|
|
|
{
|
|
|
|
|
// access to the main lyx text must be handled in the cursor
|
|
|
|
|
BOOST_ASSERT(text());
|
2004-11-24 21:53:46 +00:00
|
|
|
|
return text()->getPar(pit_);
|
2004-01-20 14:25:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Paragraph const & CursorSlice::paragraph() const
|
|
|
|
|
{
|
|
|
|
|
// access to the main lyx text must be handled in the cursor
|
|
|
|
|
BOOST_ASSERT(text());
|
2004-11-24 21:53:46 +00:00
|
|
|
|
return text()->getPar(pit_);
|
2004-01-20 14:25:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-12-15 11:36:19 +00:00
|
|
|
|
bool operator==(CursorSlice const & p, CursorSlice const & q)
|
|
|
|
|
{
|
2004-03-18 16:41:45 +00:00
|
|
|
|
return &p.inset() == &q.inset()
|
|
|
|
|
&& p.idx() == q.idx()
|
2004-11-24 21:53:46 +00:00
|
|
|
|
&& p.pit() == q.pit()
|
2004-03-18 16:41:45 +00:00
|
|
|
|
&& p.pos() == q.pos();
|
2003-12-15 11:36:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool operator!=(CursorSlice const & p, CursorSlice const & q)
|
|
|
|
|
{
|
2004-03-18 16:41:45 +00:00
|
|
|
|
return &p.inset() != &q.inset()
|
|
|
|
|
|| p.idx() != q.idx()
|
2004-11-24 21:53:46 +00:00
|
|
|
|
|| p.pit() != q.pit()
|
2004-03-18 16:41:45 +00:00
|
|
|
|
|| p.pos() != q.pos();
|
2003-12-15 11:36:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool operator<(CursorSlice const & p, CursorSlice const & q)
|
|
|
|
|
{
|
2004-03-18 16:41:45 +00:00
|
|
|
|
if (&p.inset() != &q.inset()) {
|
2003-12-15 11:36:19 +00:00
|
|
|
|
lyxerr << "can't compare cursor and anchor in different insets\n"
|
|
|
|
|
<< "p: " << p << '\n' << "q: " << q << endl;
|
2004-04-07 08:07:26 +00:00
|
|
|
|
BOOST_ASSERT(false);
|
2003-12-15 11:36:19 +00:00
|
|
|
|
}
|
2004-03-18 16:41:45 +00:00
|
|
|
|
if (p.idx() != q.idx())
|
|
|
|
|
return p.idx() < q.idx();
|
2004-11-24 21:53:46 +00:00
|
|
|
|
if (p.pit() != q.pit())
|
|
|
|
|
return p.pit() < q.pit();
|
2004-03-18 16:41:45 +00:00
|
|
|
|
return p.pos() < q.pos();
|
2003-12-15 11:36:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-13 14:13:51 +00:00
|
|
|
|
bool operator>(CursorSlice const & p, CursorSlice const & q)
|
|
|
|
|
{
|
|
|
|
|
return q < p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-04-07 13:15:34 +00:00
|
|
|
|
bool operator<=(CursorSlice const & p, CursorSlice const & q)
|
|
|
|
|
{
|
|
|
|
|
return !(q < p);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-12-15 11:36:19 +00:00
|
|
|
|
std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
|
|
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
|
return os
|
2004-03-18 16:41:45 +00:00
|
|
|
|
<< "inset: " << &item.inset()
|
2004-02-16 11:58:51 +00:00
|
|
|
|
// << " text: " << item.text()
|
2004-03-18 16:41:45 +00:00
|
|
|
|
<< " idx: " << item.idx()
|
2004-11-24 21:53:46 +00:00
|
|
|
|
<< " par: " << item.pit()
|
2004-03-18 16:41:45 +00:00
|
|
|
|
<< " pos: " << item.pos()
|
|
|
|
|
// << " x: " << item.inset().x()
|
|
|
|
|
// << " y: " << item.inset().y()
|
2003-12-15 11:36:19 +00:00
|
|
|
|
;
|
|
|
|
|
}
|