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 "paragraph.h"
21 #include "mathed/InsetMath.h"
22 #include "mathed/MathData.h"
24 #include <boost/assert.hpp>
32 CursorSlice::CursorSlice()
33 : inset_(0), idx_(0), pit_(0), pos_(0)
37 CursorSlice::CursorSlice(InsetBase & p)
38 : inset_(&p), idx_(0), pit_(0), pos_(0)
44 MathArray & CursorSlice::cell() const
46 return inset_->asInsetMath()->cell(idx_);
50 Paragraph & CursorSlice::paragraph()
52 return text()->getPar(pit_);
56 Paragraph const & CursorSlice::paragraph() const
58 return text()->getPar(pit_);
62 pos_type CursorSlice::lastpos() const
65 return inset_->asInsetMath() ? cell().size() : paragraph().size();
69 CursorSlice::row_type CursorSlice::row() const
71 BOOST_ASSERT(asInsetMath());
72 return asInsetMath()->row(idx_);
76 CursorSlice::col_type CursorSlice::col() const
78 BOOST_ASSERT(asInsetMath());
79 return asInsetMath()->col(idx_);
83 bool operator==(CursorSlice const & p, CursorSlice const & q)
85 return p.inset_ == q.inset_
88 && p.pos() == q.pos();
92 bool operator!=(CursorSlice const & p, CursorSlice const & q)
94 return p.inset_ != q.inset_
97 || p.pos() != q.pos();
101 bool operator<(CursorSlice const & p, CursorSlice const & q)
103 if (&p.inset() != &q.inset()) {
104 lyxerr << "can't compare cursor and anchor in different insets\n"
105 << "p: " << p << '\n' << "q: " << q << endl;
108 if (p.idx() != q.idx())
109 return p.idx() < q.idx();
110 if (p.pit() != q.pit())
111 return p.pit() < q.pit();
112 return p.pos() < q.pos();
116 bool operator>(CursorSlice const & p, CursorSlice const & q)
122 bool operator<=(CursorSlice const & p, CursorSlice const & q)
128 std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
131 << "inset: " << &item.inset()
132 // << " text: " << item.text()
133 << " idx: " << item.idx()
134 << " par: " << item.pit()
135 << " pos: " << item.pos()
136 // << " x: " << item.inset().x()
137 // << " y: " << item.inset().y()