2 * \file CursorSlice.cpp
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 "CursorSlice.h"
20 #include "Paragraph.h"
22 #include "insets/Inset.h"
24 #include "mathed/InsetMath.h"
25 #include "mathed/MathData.h"
27 #include <boost/assert.hpp>
28 #include <boost/bind.hpp>
36 CursorSlice::CursorSlice()
37 : inset_(0), idx_(0), pit_(0), pos_(0)
41 CursorSlice::CursorSlice(Inset & p)
42 : inset_(&p), idx_(0), pit_(0), pos_(0)
45 inset_->destroyed.connect(
46 boost::bind(&CursorSlice::invalidate, this));
50 CursorSlice::CursorSlice(CursorSlice const & cs)
56 CursorSlice & CursorSlice::operator=(CursorSlice const & cs)
64 inset_->destroyed.connect(
65 boost::bind(&CursorSlice::invalidate, this));
71 void CursorSlice::invalidate()
77 bool CursorSlice::isValid() const
83 MathData & CursorSlice::cell() const
85 return inset_->asInsetMath()->cell(idx_);
89 Paragraph & CursorSlice::paragraph()
91 return text()->getPar(pit_);
95 Paragraph const & CursorSlice::paragraph() const
97 return text()->getPar(pit_);
101 pos_type CursorSlice::lastpos() const
103 BOOST_ASSERT(inset_);
104 return inset_->asInsetMath() ? cell().size() : paragraph().size();
108 CursorSlice::row_type CursorSlice::row() const
110 BOOST_ASSERT(asInsetMath());
111 return asInsetMath()->row(idx_);
115 CursorSlice::col_type CursorSlice::col() const
117 BOOST_ASSERT(asInsetMath());
118 return asInsetMath()->col(idx_);
122 bool operator==(CursorSlice const & p, CursorSlice const & q)
124 return &p.inset() == &q.inset()
125 && p.idx() == q.idx()
126 && p.pit() == q.pit()
127 && p.pos() == q.pos();
131 bool operator!=(CursorSlice const & p, CursorSlice const & q)
133 return &p.inset() != &q.inset()
134 || p.idx() != q.idx()
135 || p.pit() != q.pit()
136 || p.pos() != q.pos();
140 bool operator<(CursorSlice const & p, CursorSlice const & q)
142 if (&p.inset() != &q.inset()) {
143 lyxerr << "can't compare cursor and anchor in different insets\n"
144 << "p: " << p << '\n' << "q: " << q << endl;
147 if (p.idx() != q.idx())
148 return p.idx() < q.idx();
149 if (p.pit() != q.pit())
150 return p.pit() < q.pit();
151 return p.pos() < q.pos();
155 bool operator>(CursorSlice const & p, CursorSlice const & q)
161 bool operator<=(CursorSlice const & p, CursorSlice const & q)
167 std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
170 << "inset: " << &item.inset()
171 // << " text: " << item.text()
172 << " idx: " << item.idx()
173 << " par: " << item.pit()
174 << " pos: " << item.pos()
175 // << " x: " << item.inset().x()
176 // << " y: " << item.inset().y()