X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fcursor_slice.C;h=02e7b4ab6270d82dbd3b3b8976c68a2ac8668b29;hb=3f8fa07c6ed38218d6a4048f2993a512aa942c96;hp=a537aee3aa373a2d9a0d7ca412705c9dc4468dc7;hpb=0d43ba149a41e8860dde316ccbd4336d6b0bbdfa;p=lyx.git diff --git a/src/cursor_slice.C b/src/cursor_slice.C index a537aee3aa..02e7b4ab62 100644 --- a/src/cursor_slice.C +++ b/src/cursor_slice.C @@ -18,129 +18,82 @@ #include "lyxtext.h" #include "paragraph.h" -#include "mathed/math_inset.h" -#include "mathed/math_data.h" +#include "mathed/InsetMath.h" +#include "mathed/MathData.h" -#include "insets/updatableinset.h" +#include -#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) + : inset_(&p), idx_(0), pit_(0), pos_(0) { BOOST_ASSERT(inset_); } -size_t CursorSlice::nargs() const +MathArray & CursorSlice::cell() const { - BOOST_ASSERT(inset_); - return inset_->nargs(); + return inset_->asInsetMath()->cell(idx_); } -size_t CursorSlice::nrows() const +Paragraph & CursorSlice::paragraph() { - BOOST_ASSERT(inset_); - return inset_->nrows(); + return text()->getPar(pit_); } -size_t CursorSlice::ncols() const +Paragraph const & CursorSlice::paragraph() const { - BOOST_ASSERT(inset_); - return inset_->ncols(); + return text()->getPar(pit_); } -CursorSlice::pos_type CursorSlice::lastpos() const +pos_type CursorSlice::lastpos() const { BOOST_ASSERT(inset_); - return inset_->asMathInset() ? cell().size() : paragraph().size(); + return inset_->asInsetMath() ? cell().size() : paragraph().size(); } CursorSlice::row_type CursorSlice::row() const { - BOOST_ASSERT(asMathInset()); - return asMathInset()->row(idx_); + BOOST_ASSERT(asInsetMath()); + return asInsetMath()->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(); -} - - -UpdatableInset * CursorSlice::asUpdatableInset() const -{ - BOOST_ASSERT(inset_); - return inset_->asUpdatableInset(); -} - - -MathArray & CursorSlice::cell() const -{ - BOOST_ASSERT(asMathInset()); - return asMathInset()->cell(idx_); -} - - -LyXText * CursorSlice::text() const -{ - 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(par_); -} - - -Paragraph const & CursorSlice::paragraph() const -{ - // access to the main lyx text must be handled in the cursor - BOOST_ASSERT(text()); - return text()->getPar(par_); + BOOST_ASSERT(asInsetMath()); + return asInsetMath()->col(idx_); } bool operator==(CursorSlice const & p, CursorSlice const & q) { - return &p.inset() == &q.inset() + return p.inset_ == q.inset_ && p.idx() == q.idx() - && p.par() == q.par() + && p.pit() == q.pit() && p.pos() == q.pos(); } bool operator!=(CursorSlice const & p, CursorSlice const & q) { - return &p.inset() != &q.inset() + return p.inset_ != q.inset_ || p.idx() != q.idx() - || p.par() != q.par() + || p.pit() != q.pit() || p.pos() != q.pos(); } @@ -150,12 +103,12 @@ bool operator<(CursorSlice const & p, CursorSlice const & q) 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(); + if (p.pit() != q.pit()) + return p.pit() < q.pit(); return p.pos() < q.pos(); } @@ -166,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) { return os << "inset: " << &item.inset() // << " text: " << item.text() << " idx: " << item.idx() - << " par: " << item.par() + << " par: " << item.pit() << " pos: " << item.pos() // << " x: " << item.inset().x() // << " y: " << item.inset().y() ; } + + +} // namespace lyx