2003-12-15 11:36:19 +00:00
|
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
|
* \file CursorSlice.cpp
|
2003-12-15 11:36:19 +00:00
|
|
|
|
* 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>
|
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "CursorSlice.h"
|
2007-05-25 23:17:24 +00:00
|
|
|
|
|
2007-04-29 23:33:02 +00:00
|
|
|
|
#include "Text.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "Paragraph.h"
|
2003-12-15 11:36:19 +00:00
|
|
|
|
|
2007-11-29 07:04:28 +00:00
|
|
|
|
#include "support/debug.h"
|
|
|
|
|
|
2007-05-25 23:17:24 +00:00
|
|
|
|
#include "insets/Inset.h"
|
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "mathed/InsetMath.h"
|
2007-04-26 16:06:39 +00:00
|
|
|
|
#include "mathed/MathData.h"
|
2004-01-14 18:17:02 +00:00
|
|
|
|
|
2003-12-15 11:36:19 +00:00
|
|
|
|
#include <boost/assert.hpp>
|
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
|
#include <ostream>
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
|
using namespace std;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
2007-07-17 17:46:54 +00:00
|
|
|
|
namespace lyx {
|
2003-12-15 11:36:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
|
CursorSlice::CursorSlice(Inset & 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_);
|
2007-05-25 23:17:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 16:06:39 +00:00
|
|
|
|
MathData & 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-23 20:55:34 +00:00
|
|
|
|
Paragraph & 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_);
|
2008-01-10 08:46:04 +00:00
|
|
|
|
return inset_->asInsetMath() ? cell().size()
|
|
|
|
|
: (text()->empty() ? 0 : paragraph().size());
|
2004-01-15 17:34:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-06-09 12:39:46 +00:00
|
|
|
|
pit_type CursorSlice::lastpit() const
|
|
|
|
|
{
|
|
|
|
|
if (inset().inMathed())
|
|
|
|
|
return 0;
|
|
|
|
|
return text()->paragraphs().size() - 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-13 13:36:19 +00:00
|
|
|
|
void CursorSlice::forwardPos()
|
|
|
|
|
{
|
|
|
|
|
// move on one position if possible
|
|
|
|
|
if (pos() < lastpos()) {
|
|
|
|
|
//lyxerr << "... next pos" << endl;
|
|
|
|
|
++pos();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// otherwise move on one paragraph if possible
|
|
|
|
|
if (pit() < lastpit()) {
|
|
|
|
|
//lyxerr << "... next par" << endl;
|
|
|
|
|
++pit();
|
|
|
|
|
pos() = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-23 21:00:41 +00:00
|
|
|
|
// otherwise move on one cell
|
|
|
|
|
//lyxerr << "... next idx" << endl;
|
2007-08-23 21:35:40 +00:00
|
|
|
|
|
|
|
|
|
BOOST_ASSERT(idx() < nargs());
|
|
|
|
|
|
|
|
|
|
++idx();
|
|
|
|
|
pit() = 0;
|
|
|
|
|
pos() = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CursorSlice::forwardIdx()
|
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(idx() < nargs());
|
|
|
|
|
|
2007-08-23 21:00:41 +00:00
|
|
|
|
++idx();
|
|
|
|
|
pit() = 0;
|
|
|
|
|
pos() = 0;
|
2007-08-13 13:36:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CursorSlice::backwardPos()
|
|
|
|
|
{
|
|
|
|
|
if (pos() != 0) {
|
|
|
|
|
--pos();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pit() != 0) {
|
|
|
|
|
--pit();
|
|
|
|
|
pos() = lastpos();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (idx() != 0) {
|
|
|
|
|
--idx();
|
|
|
|
|
pit() = lastpit();
|
|
|
|
|
pos() = lastpos();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOST_ASSERT(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool CursorSlice::at_end() const
|
|
|
|
|
{
|
|
|
|
|
return idx() == lastidx() && pit() == lastpit() && pos() == lastpos();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool CursorSlice::at_begin() const
|
|
|
|
|
{
|
|
|
|
|
return idx() == 0 && pit() == 0 && pos() == 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-12-15 11:36:19 +00:00
|
|
|
|
bool operator==(CursorSlice const & p, CursorSlice const & q)
|
|
|
|
|
{
|
2007-05-25 23:17:24 +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)
|
|
|
|
|
{
|
2007-05-25 23:17:24 +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()) {
|
2007-11-28 22:12:03 +00:00
|
|
|
|
LYXERR0("can't compare cursor and anchor in different insets\n"
|
|
|
|
|
<< "p: " << p << '\n' << "q: " << q);
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
|
ostream & operator<<(ostream & os, CursorSlice const & item)
|
2003-12-15 11:36:19 +00:00
|
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
|
return os
|
2007-11-28 22:12:03 +00:00
|
|
|
|
<< "inset: " << (void *)&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
|