X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fcursor_slice.C;h=02e7b4ab6270d82dbd3b3b8976c68a2ac8668b29;hb=3f8fa07c6ed38218d6a4048f2993a512aa942c96;hp=6c4befd0a6ee6cc2b35dd48b9845f1b9cc211e53;hpb=69bee02a8901793b34ac5ca6d07e93910cef4005;p=lyx.git diff --git a/src/cursor_slice.C b/src/cursor_slice.C index 6c4befd0a6..02e7b4ab62 100644 --- a/src/cursor_slice.C +++ b/src/cursor_slice.C @@ -15,192 +15,101 @@ #include "cursor_slice.h" #include "debug.h" +#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) -{ - ///BOOST_ASSERT(inset_); -} - - -void CursorSlice::idx(idx_type idx) -{ - idx_ = idx; -} - - -size_t CursorSlice::nargs() const -{ - return inset_->nargs(); -} - - -size_t CursorSlice::ncols() const -{ - return inset_->ncols(); -} - - -CursorSlice::idx_type CursorSlice::idx() const -{ - return idx_; -} - - -CursorSlice::idx_type & CursorSlice::idx() -{ - return idx_; -} - - -void CursorSlice::par(par_type par) +CursorSlice::CursorSlice(InsetBase & p) + : inset_(&p), idx_(0), pit_(0), pos_(0) { - par_ = par; -} - - -CursorSlice::par_type CursorSlice::par() const -{ - return par_; -} - - -CursorSlice::par_type & CursorSlice::par() -{ - return par_; + BOOST_ASSERT(inset_); } -void CursorSlice::pos(pos_type pos) +MathArray & CursorSlice::cell() const { - pos_ = pos; + return inset_->asInsetMath()->cell(idx_); } -CursorSlice::pos_type CursorSlice::pos() const +Paragraph & CursorSlice::paragraph() { - return pos_; + return text()->getPar(pit_); } -CursorSlice::pos_type & CursorSlice::pos() +Paragraph const & CursorSlice::paragraph() const { - return pos_; + return text()->getPar(pit_); } -CursorSlice::pos_type CursorSlice::lastpos() const +pos_type CursorSlice::lastpos() const { BOOST_ASSERT(inset_); -#warning implement me for texted, too. - return inset_->asMathInset() ? cell().size() : 0; -} - - -void CursorSlice::boundary(bool boundary) -{ - boundary_ = boundary; -} - - -bool CursorSlice::boundary() const -{ - return boundary_; + return inset_->asInsetMath() ? cell().size() : paragraph().size(); } CursorSlice::row_type CursorSlice::row() const { - BOOST_ASSERT(asMathInset()); - asMathInset()->row(idx_); + BOOST_ASSERT(asInsetMath()); + return asInsetMath()->row(idx_); } CursorSlice::col_type CursorSlice::col() const { - BOOST_ASSERT(asMathInset()); - asMathInset()->col(idx_); -} - - -MathInset * CursorSlice::asMathInset() const -{ - return inset_ ? inset_->asMathInset() : 0; -} - - -UpdatableInset * CursorSlice::asUpdatableInset() const -{ - return inset_ ? inset_->asUpdatableInset() : 0; -} - - -MathArray & CursorSlice::cell() const -{ - BOOST_ASSERT(asMathInset()); - return asMathInset()->cell(idx_); -} - - -void CursorSlice::getScreenPos(int & x, int & y) const -{ - BOOST_ASSERT(asMathInset()); - asMathInset()->getScreenPos(idx_, pos_, x, y); -} - - -LyXText * CursorSlice::text() 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(); } @@ -210,76 +119,24 @@ bool operator>(CursorSlice const & p, CursorSlice const & q) } -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; -} - - - - -void increment(CursorBase & it) +bool operator<=(CursorSlice const & p, CursorSlice const & q) { - CursorSlice & top = it.back(); - MathArray & ar = top.asMathInset()->cell(top.idx_); - - // move into the current inset if possible - // it is impossible for pos() == size()! - MathInset * n = 0; - if (top.pos_ != ar.size()) - n = (ar.begin() + top.pos_)->nucleus(); - if (n && n->isActive()) { - it.push_back(CursorSlice(n)); - return; - } - - // otherwise move on one cell back if possible - if (top.pos_ < ar.size()) { - // pos() == size() is valid! - ++top.pos_; - return; - } - - // otherwise try to move on one cell if possible - while (top.idx_ + 1 < top.asMathInset()->nargs()) { - // idx() == nargs() is _not_ valid! - ++top.idx_; - if (top.asMathInset()->validCell(top.idx_)) { - top.pos_ = 0; - return; - } - } - - // otherwise leave array, move on one back - // this might yield pos() == size(), but that's a ok. - it.pop_back(); - // it certainly invalidates top - ++it.back().pos_; + return !(q < p); } -CursorBase ibegin(InsetBase * p) +std::ostream & operator<<(std::ostream & os, CursorSlice const & item) { - CursorBase it; - it.push_back(CursorSlice(p)); - return it; + 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() +; } -CursorBase iend(InsetBase * p) -{ - CursorBase it; - it.push_back(CursorSlice(p)); - CursorSlice & top = it.back(); - top.idx_ = top.asMathInset()->nargs() - 1; - top.pos_ = top.asMathInset()->cell(top.idx_).size(); - return it; -} +} // namespace lyx