X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fcursor_slice.C;h=02e7b4ab6270d82dbd3b3b8976c68a2ac8668b29;hb=35204f8f33d7400a5fefeffea533fb4cb4097211;hp=7094014d89c1cd6cc1a50256ca38ab9f313bc13f;hpb=25bafa277251eaf01e3068921442b1584ce77975;p=lyx.git diff --git a/src/cursor_slice.C b/src/cursor_slice.C index 7094014d89..02e7b4ab62 100644 --- a/src/cursor_slice.C +++ b/src/cursor_slice.C @@ -15,151 +15,101 @@ #include "cursor_slice.h" #include "debug.h" +#include "lyxtext.h" +#include "paragraph.h" -#include "mathed/math_inset.h" -#include "insets/updatableinset.h" +#include "mathed/InsetMath.h" +#include "mathed/MathData.h" #include + +namespace lyx { + using std::endl; CursorSlice::CursorSlice() - : inset_(0), idx_(0), par_(0), pos_(0), boundary_(false) + : inset_(0), idx_(0), pit_(0), pos_(0) {} -CursorSlice::CursorSlice(InsetBase * p) - : inset_(p), idx_(0), par_(0), pos_(0), boundary_(false) +CursorSlice::CursorSlice(InsetBase & p) + : inset_(&p), idx_(0), pit_(0), pos_(0) { - ///BOOST_ASSERT(inset_); -} - - -void CursorSlice::idx(idx_type idx) -{ - idx_ = idx; -} - - -CursorSlice::idx_type CursorSlice::idx() const -{ - return idx_; -} - - -void CursorSlice::par(par_type par) -{ - par_ = par; -} - - -CursorSlice::par_type CursorSlice::par() const -{ - return par_; -} - - -void CursorSlice::pos(pos_type pos) -{ - pos_ = pos; -} - - -CursorSlice::pos_type CursorSlice::pos() const -{ - return pos_; -} - - -void CursorSlice::boundary(bool boundary) -{ - boundary_ = boundary; -} - - -bool CursorSlice::boundary() const -{ - return boundary_; -} - - -MathInset * CursorSlice::asMathInset() const -{ - return static_cast(const_cast(inset_)); + BOOST_ASSERT(inset_); } -UpdatableInset * CursorSlice::asUpdatableInset() const +MathArray & CursorSlice::cell() const { - return static_cast(const_cast(inset_)); + return inset_->asInsetMath()->cell(idx_); } -MathArray & CursorSlice::cell(CursorSlice::idx_type idx) const +Paragraph & CursorSlice::paragraph() { - BOOST_ASSERT(inset_); - BOOST_ASSERT(asMathInset()); - return asMathInset()->cell(idx); + return text()->getPar(pit_); } -MathArray & CursorSlice::cell() const +Paragraph const & CursorSlice::paragraph() const { - BOOST_ASSERT(inset_); - return asMathInset()->cell(idx_); + return text()->getPar(pit_); } -void CursorSlice::getPos(int & x, int & y) const +pos_type CursorSlice::lastpos() const { BOOST_ASSERT(inset_); - asMathInset()->getPos(idx_, pos_, x, y); + return inset_->asInsetMath() ? cell().size() : paragraph().size(); } -void CursorSlice::setPos(int pos) +CursorSlice::row_type CursorSlice::row() const { - pos_ = pos; + BOOST_ASSERT(asInsetMath()); + return asInsetMath()->row(idx_); } -LyXText * CursorSlice::text() const +CursorSlice::col_type CursorSlice::col() const { - return asUpdatableInset() ? asUpdatableInset()->getText(idx_) : 0; + BOOST_ASSERT(asInsetMath()); + return asInsetMath()->col(idx_); } 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_; + && 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_; + || 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(); } @@ -169,15 +119,24 @@ bool operator>(CursorSlice const & p, CursorSlice const & q) } +bool operator<=(CursorSlice const & p, CursorSlice const & q) +{ + return !(q < p); +} + + std::ostream & operator<<(std::ostream & os, CursorSlice const & item) { - os << " inset: " << item.inset_ - << " text: " << item.text() - << " idx: " << item.idx_ - << " par: " << item.par_ - << " pos: " << item.pos_ -// << " x: " << item.inset_->x() -// << " y: " << item.inset_->y() + return os + << "inset: " << &item.inset() +// << " text: " << item.text() + << " idx: " << item.idx() + << " par: " << item.pit() + << " pos: " << item.pos() +// << " x: " << item.inset().x() +// << " y: " << item.inset().y() ; - return os; } + + +} // namespace lyx