3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "cursor_slice.h"
16 #include "mathed/math_inset.h"
17 #include "insets/updatableinset.h"
19 #include <boost/assert.hpp>
24 CursorSlice::CursorSlice()
25 : inset_(0), idx_(0), par_(0), pos_(0)
29 CursorSlice::CursorSlice(InsetBase * p)
30 : inset_(p), idx_(0), par_(0), pos_(0)
32 ///BOOST_ASSERT(inset_);
36 MathInset * CursorSlice::asMathInset() const
38 return static_cast<MathInset *>(const_cast<InsetBase *>(inset_));
42 UpdatableInset * CursorSlice::asUpdatableInset() const
44 return static_cast<UpdatableInset *>(const_cast<InsetBase *>(inset_));
48 MathArray & CursorSlice::cell(CursorSlice::idx_type idx) const
51 return asMathInset()->cell(idx);
55 MathArray & CursorSlice::cell() const
58 return asMathInset()->cell(idx_);
62 void CursorSlice::getPos(int & x, int & y) const
64 asMathInset()->getPos(idx_, pos_, x, y);
68 void CursorSlice::setPos(int pos)
74 LyXText * CursorSlice::text() const
76 return asUpdatableInset()->getText(idx_);
80 bool operator==(CursorSlice const & p, CursorSlice const & q)
82 return p.inset_ == q.inset_
89 bool operator!=(CursorSlice const & p, CursorSlice const & q)
91 return p.inset_ != q.inset_
98 bool operator<(CursorSlice const & p, CursorSlice const & q)
100 if (p.inset_ != q.inset_) {
101 lyxerr << "can't compare cursor and anchor in different insets\n"
102 << "p: " << p << '\n' << "q: " << q << endl;
105 if (p.idx_ != q.idx_)
106 return p.idx_ < q.idx_;
107 if (p.par_ != q.par_)
108 return p.par_ < q.par_;
109 return p.pos_ < q.pos_;
113 //std::ostream & operator<<(std::ostream & os, CursorSlice const & p)
115 // os << "(par: " << p.inset_ << " idx: " << p.idx_ << " pos: " << p.pos_ << ')';
120 std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
122 os << " inset: " << item.inset_
123 // << " text: " << item.text()
124 << " idx: " << item.idx_
125 // << " par: " << item.par_
126 // << " pos: " << item.pos_
127 // << " x: " << item.inset_->x()
128 // << " y: " << item.inset_->y()