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)
48 CursorSlice::CursorSlice(CursorSlice const & cs)
54 CursorSlice & CursorSlice::operator=(CursorSlice const & cs)
64 void CursorSlice::invalidate()
70 bool CursorSlice::isValid() const
76 MathData & CursorSlice::cell() const
78 return inset_->asInsetMath()->cell(idx_);
82 Paragraph & CursorSlice::paragraph()
84 return text()->getPar(pit_);
88 Paragraph const & CursorSlice::paragraph() const
90 return text()->getPar(pit_);
94 pos_type CursorSlice::lastpos() const
97 return inset_->asInsetMath() ? cell().size() : paragraph().size();
101 pit_type CursorSlice::lastpit() const
103 if (inset().inMathed())
105 return text()->paragraphs().size() - 1;
109 CursorSlice::row_type CursorSlice::row() const
111 BOOST_ASSERT(asInsetMath());
112 return asInsetMath()->row(idx_);
116 CursorSlice::col_type CursorSlice::col() const
118 BOOST_ASSERT(asInsetMath());
119 return asInsetMath()->col(idx_);
123 bool operator==(CursorSlice const & p, CursorSlice const & q)
125 return &p.inset() == &q.inset()
126 && p.idx() == q.idx()
127 && p.pit() == q.pit()
128 && p.pos() == q.pos();
132 bool operator!=(CursorSlice const & p, CursorSlice const & q)
134 return &p.inset() != &q.inset()
135 || p.idx() != q.idx()
136 || p.pit() != q.pit()
137 || p.pos() != q.pos();
141 bool operator<(CursorSlice const & p, CursorSlice const & q)
143 if (&p.inset() != &q.inset()) {
144 lyxerr << "can't compare cursor and anchor in different insets\n"
145 << "p: " << p << '\n' << "q: " << q << endl;
148 if (p.idx() != q.idx())
149 return p.idx() < q.idx();
150 if (p.pit() != q.pit())
151 return p.pit() < q.pit();
152 return p.pos() < q.pos();
156 bool operator>(CursorSlice const & p, CursorSlice const & q)
162 bool operator<=(CursorSlice const & p, CursorSlice const & q)
168 std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
171 << "inset: " << &item.inset()
172 // << " text: " << item.text()
173 << " idx: " << item.idx()
174 << " par: " << item.pit()
175 << " pos: " << item.pos()
176 // << " x: " << item.inset().x()
177 // << " y: " << item.inset().y()