3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
7 * \author Matthias Ettrich
11 * Full author contact details are available in file CREDITS.
16 #include "cursor_slice.h"
19 #include "mathed/math_inset.h"
20 #include "insets/updatableinset.h"
22 #include <boost/assert.hpp>
27 CursorSlice::CursorSlice()
28 : inset_(0), idx_(0), par_(0), pos_(0), boundary_(false)
32 CursorSlice::CursorSlice(InsetBase * p)
33 : inset_(p), idx_(0), par_(0), pos_(0), boundary_(false)
35 ///BOOST_ASSERT(inset_);
39 void CursorSlice::par(lyx::paroffset_type par)
45 lyx::paroffset_type CursorSlice::par() const
51 void CursorSlice::pos(lyx::pos_type pos)
57 lyx::pos_type CursorSlice::pos() const
63 void CursorSlice::boundary(bool boundary)
69 bool CursorSlice::boundary() const
75 MathInset * CursorSlice::asMathInset() const
77 return static_cast<MathInset *>(const_cast<InsetBase *>(inset_));
81 UpdatableInset * CursorSlice::asUpdatableInset() const
83 return static_cast<UpdatableInset *>(const_cast<InsetBase *>(inset_));
87 MathArray & CursorSlice::cell(CursorSlice::idx_type idx) const
90 return asMathInset()->cell(idx);
94 MathArray & CursorSlice::cell() const
97 return asMathInset()->cell(idx_);
101 void CursorSlice::getPos(int & x, int & y) const
103 asMathInset()->getPos(idx_, pos_, x, y);
107 void CursorSlice::setPos(int pos)
113 LyXText * CursorSlice::text() const
115 return asUpdatableInset()->getText(idx_);
119 bool operator==(CursorSlice const & p, CursorSlice const & q)
121 return p.inset_ == q.inset_
128 bool operator!=(CursorSlice const & p, CursorSlice const & q)
130 return p.inset_ != q.inset_
137 bool operator<(CursorSlice const & p, CursorSlice const & q)
139 if (p.inset_ != q.inset_) {
140 lyxerr << "can't compare cursor and anchor in different insets\n"
141 << "p: " << p << '\n' << "q: " << q << endl;
144 if (p.idx_ != q.idx_)
145 return p.idx_ < q.idx_;
146 if (p.par_ != q.par_)
147 return p.par_ < q.par_;
148 return p.pos_ < q.pos_;
152 //std::ostream & operator<<(std::ostream & os, CursorSlice const & p)
154 // os << "(par: " << p.inset_ << " idx: " << p.idx_ << " pos: " << p.pos_ << ')';
159 std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
161 os << " inset: " << item.inset_
162 // << " text: " << item.text()
163 << " idx: " << item.idx_
164 // << " par: " << item.par_
165 // << " pos: " << item.pos_
166 // << " x: " << item.inset_->x()
167 // << " y: " << item.inset_->y()