X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fcursor_slice.C;h=59e544736641527e4a129fd010c535eb697bb04b;hb=37e82a546392d43f787826b85481a11f2a27af15;hp=deec39303e9a296ce2b03282ea084ad2389377ff;hpb=a97ed20502fb6a19949cf7ef6fc18a6c6d9e347b;p=lyx.git diff --git a/src/cursor_slice.C b/src/cursor_slice.C index deec39303e..59e5447366 100644 --- a/src/cursor_slice.C +++ b/src/cursor_slice.C @@ -3,7 +3,10 @@ * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * + * \author Lars Gullik Bjønnes + * \author Matthias Ettrich * \author André Pönitz + * \author Jürgen Vigna * * Full author contact details are available in file CREDITS. */ @@ -12,122 +15,172 @@ #include "cursor_slice.h" #include "debug.h" +#include "lyxtext.h" +#include "paragraph.h" #include "mathed/math_inset.h" +#include "mathed/math_data.h" + #include "insets/updatableinset.h" + #include using std::endl; CursorSlice::CursorSlice() - : inset_(0), idx_(0), par_(0), pos_(0) + : inset_(0), idx_(0), pit_(0), pos_(0), boundary_(false) {} -CursorSlice::CursorSlice(InsetBase * p) - : inset_(p), idx_(0), par_(0), pos_(0) +CursorSlice::CursorSlice(InsetBase & p) + : inset_(&p), idx_(0), pit_(0), pos_(0), boundary_(false) { - ///BOOST_ASSERT(inset_); + BOOST_ASSERT(inset_); } -MathInset * CursorSlice::asMathInset() const +size_t CursorSlice::nargs() const { - return static_cast(const_cast(inset_)); + BOOST_ASSERT(inset_); + return inset_->nargs(); } -UpdatableInset * CursorSlice::asUpdatableInset() const +size_t CursorSlice::nrows() const { - return static_cast(const_cast(inset_)); + BOOST_ASSERT(inset_); + return inset_->nrows(); } -MathArray & CursorSlice::cell(CursorSlice::idx_type idx) const +size_t CursorSlice::ncols() const { BOOST_ASSERT(inset_); - return asMathInset()->cell(idx); + return inset_->ncols(); } -MathArray & CursorSlice::cell() const +CursorSlice::pos_type CursorSlice::lastpos() const { BOOST_ASSERT(inset_); - return asMathInset()->cell(idx_); + return inset_->asMathInset() ? cell().size() : paragraph().size(); +} + + +CursorSlice::row_type CursorSlice::row() const +{ + BOOST_ASSERT(asMathInset()); + return asMathInset()->row(idx_); +} + + +CursorSlice::col_type CursorSlice::col() const +{ + BOOST_ASSERT(asMathInset()); + return asMathInset()->col(idx_); +} + + +MathInset * CursorSlice::asMathInset() const +{ + BOOST_ASSERT(inset_); + return inset_->asMathInset(); } -void CursorSlice::getPos(int & x, int & y) const +UpdatableInset * CursorSlice::asUpdatableInset() const { - asMathInset()->getPos(idx_, pos_, x, y); + BOOST_ASSERT(inset_); + return inset_->asUpdatableInset(); } -void CursorSlice::setPos(int pos) +MathArray & CursorSlice::cell() const { - pos_ = pos; + BOOST_ASSERT(asMathInset()); + return asMathInset()->cell(idx_); } LyXText * CursorSlice::text() const { - return asUpdatableInset()->getText(idx_); + BOOST_ASSERT(inset_); + return inset_->getText(idx_); +} + + +Paragraph & CursorSlice::paragraph() +{ + // access to the main lyx text must be handled in the cursor + BOOST_ASSERT(text()); + return text()->getPar(pit_); +} + + +Paragraph const & CursorSlice::paragraph() const +{ + // access to the main lyx text must be handled in the cursor + BOOST_ASSERT(text()); + return text()->getPar(pit_); } bool operator==(CursorSlice const & p, CursorSlice const & q) { - return p.inset_ == q.inset_ - && p.idx_ == q.idx_ - && p.par_ == q.par_ - && p.pos_ == q.pos_; + return &p.inset() == &q.inset() + && p.idx() == q.idx() + && p.pit() == q.pit() + && p.pos() == q.pos(); } bool operator!=(CursorSlice const & p, CursorSlice const & q) { - return p.inset_ != q.inset_ - || p.idx_ != q.idx_ - || p.par_ != q.par_ - || p.pos_ != q.pos_; + return &p.inset() != &q.inset() + || p.idx() != q.idx() + || p.pit() != q.pit() + || p.pos() != q.pos(); } bool operator<(CursorSlice const & p, CursorSlice const & q) { - if (p.inset_ != q.inset_) { + if (&p.inset() != &q.inset()) { lyxerr << "can't compare cursor and anchor in different insets\n" << "p: " << p << '\n' << "q: " << q << endl; - return true; + BOOST_ASSERT(false); } - if (p.idx_ != q.idx_) - return p.idx_ < q.idx_; - if (p.par_ != q.par_) - return p.par_ < q.par_; - return p.pos_ < q.pos_; + if (p.idx() != q.idx()) + return p.idx() < q.idx(); + if (p.pit() != q.pit()) + return p.pit() < q.pit(); + return p.pos() < q.pos(); } -//std::ostream & operator<<(std::ostream & os, CursorSlice const & p) -//{ -// os << "(par: " << p.inset_ << " idx: " << p.idx_ << " pos: " << p.pos_ << ')'; -// return os; -//} +bool operator>(CursorSlice const & p, CursorSlice const & q) +{ + return q < p; +} + + +bool operator<=(CursorSlice const & p, CursorSlice const & q) +{ + return !(q < p); +} std::ostream & operator<<(std::ostream & os, CursorSlice const & item) { - os << " inset: " << item.inset_ + return os + << "inset: " << &item.inset() // << " text: " << item.text() - << " idx: " << item.idx_ -// << " par: " << item.par_ -// << " pos: " << item.pos_ -// << " x: " << item.inset_->x() -// << " y: " << item.inset_->y() + << " idx: " << item.idx() + << " par: " << item.pit() + << " pos: " << item.pos() +// << " x: " << item.inset().x() +// << " y: " << item.inset().y() ; - return os; } - -