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
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "mathed/InsetMath.h"
|
2007-04-25 16:11:45 +00:00
|
|
|
|
#include "mathed/MathArray.h"
|
2004-01-14 18:17:02 +00:00
|
|
|
|
|
2003-12-15 11:36:19 +00:00
|
|
|
|
#include <boost/assert.hpp>
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
2003-12-15 11:36:19 +00:00
|
|
|
|
using std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CursorSlice::CursorSlice()
|
2005-07-15 15:49:40 +00:00
|
|
|
|
: inset_(0), idx_(0), pit_(0), pos_(0)
|
2003-12-15 11:36:19 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
CursorSlice::CursorSlice(InsetBase & p)
|
2005-07-15 15:49:40 +00:00
|
|
|
|
: inset_(&p), idx_(0), pit_(0), pos_(0)
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-07-18 11:00:15 +00:00
|
|
|
|
MathArray & CursorSlice::cell() const
|
2004-01-16 10:55:19 +00:00
|
|
|
|
{
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return inset_->asInsetMath()->cell(idx_);
|
2004-01-16 10:55:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-07-18 11:00:15 +00:00
|
|
|
|
Paragraph & CursorSlice::paragraph()
|
2004-01-20 14:25:24 +00:00
|
|
|
|
{
|
2005-07-18 11:00:15 +00:00
|
|
|
|
return text()->getPar(pit_);
|
2004-01-20 14:25:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-07-18 11:00:15 +00:00
|
|
|
|
Paragraph const & CursorSlice::paragraph() const
|
2004-01-16 10:55:19 +00:00
|
|
|
|
{
|
2005-07-18 11:00:15 +00:00
|
|
|
|
return text()->getPar(pit_);
|
2004-01-16 10:55:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
pos_type CursorSlice::lastpos() const
|
2004-01-15 17:34:44 +00:00
|
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
|
BOOST_ASSERT(inset_);
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return inset_->asInsetMath() ? 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
|
|
|
|
{
|
2006-09-16 18:11:38 +00:00
|
|
|
|
BOOST_ASSERT(asInsetMath());
|
|
|
|
|
return asInsetMath()->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
|
|
|
|
{
|
2006-09-16 18:11:38 +00:00
|
|
|
|
BOOST_ASSERT(asInsetMath());
|
|
|
|
|
return asInsetMath()->col(idx_);
|
2003-12-15 11:36:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool operator==(CursorSlice const & p, CursorSlice const & q)
|
|
|
|
|
{
|
2006-09-27 16:10:47 +00:00
|
|
|
|
return p.inset_ == q.inset_
|
2004-03-18 16:41:45 +00:00
|
|
|
|
&& 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)
|
|
|
|
|
{
|
2006-09-27 16:10:47 +00:00
|
|
|
|
return p.inset_ != q.inset_
|
2004-03-18 16:41:45 +00:00
|
|
|
|
|| 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
|
|
|
|
;
|
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|