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::idx(idx_type idx)
45 CursorSlice::idx_type CursorSlice::idx() const
51 void CursorSlice::par(par_type par)
57 CursorSlice::par_type CursorSlice::par() const
63 void CursorSlice::pos(pos_type pos)
69 CursorSlice::pos_type CursorSlice::pos() const
75 void CursorSlice::boundary(bool boundary)
81 bool CursorSlice::boundary() const
87 MathInset * CursorSlice::asMathInset() const
89 return static_cast<MathInset *>(const_cast<InsetBase *>(inset_));
93 UpdatableInset * CursorSlice::asUpdatableInset() const
95 return static_cast<UpdatableInset *>(const_cast<InsetBase *>(inset_));
99 MathArray & CursorSlice::cell(CursorSlice::idx_type idx) const
101 BOOST_ASSERT(inset_);
102 BOOST_ASSERT(asMathInset());
103 return asMathInset()->cell(idx);
107 MathArray & CursorSlice::cell() const
109 BOOST_ASSERT(inset_);
110 return asMathInset()->cell(idx_);
114 void CursorSlice::getPos(int & x, int & y) const
116 BOOST_ASSERT(inset_);
117 asMathInset()->getPos(idx_, pos_, x, y);
121 void CursorSlice::setPos(int pos)
127 LyXText * CursorSlice::text() const
129 return asUpdatableInset() ? asUpdatableInset()->getText(idx_) : 0;
133 bool operator==(CursorSlice const & p, CursorSlice const & q)
135 return p.inset_ == q.inset_
142 bool operator!=(CursorSlice const & p, CursorSlice const & q)
144 return p.inset_ != q.inset_
151 bool operator<(CursorSlice const & p, CursorSlice const & q)
153 if (p.inset_ != q.inset_) {
154 lyxerr << "can't compare cursor and anchor in different insets\n"
155 << "p: " << p << '\n' << "q: " << q << endl;
158 if (p.idx_ != q.idx_)
159 return p.idx_ < q.idx_;
160 if (p.par_ != q.par_)
161 return p.par_ < q.par_;
162 return p.pos_ < q.pos_;
166 bool operator>(CursorSlice const & p, CursorSlice const & q)
172 std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
174 os << " inset: " << item.inset_
175 << " text: " << item.text()
176 << " idx: " << item.idx_
177 << " par: " << item.par_
178 << " pos: " << item.pos_
179 // << " x: " << item.inset_->x()
180 // << " y: " << item.inset_->y()