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/math_inset.h"
22 #include "mathed/math_data.h"
24 #include "insets/updatableinset.h"
27 #include <boost/assert.hpp>
32 CursorSlice::CursorSlice()
33 : inset_(0), idx_(0), par_(0), pos_(0), boundary_(false)
37 CursorSlice::CursorSlice(InsetBase & p)
38 : inset_(&p), idx_(0), par_(0), pos_(0), boundary_(false)
40 ///BOOST_ASSERT(inset_);
44 size_t CursorSlice::nargs() const
47 return inset_->nargs();
51 size_t CursorSlice::nrows() const
54 return inset_->nrows();
58 size_t CursorSlice::ncols() const
61 return inset_->ncols();
65 CursorSlice::idx_type CursorSlice::idx() const
71 CursorSlice::idx_type & CursorSlice::idx()
77 CursorSlice::par_type CursorSlice::par() const
83 CursorSlice::par_type & CursorSlice::par()
89 CursorSlice::pos_type CursorSlice::pos() const
95 CursorSlice::pos_type & CursorSlice::pos()
101 CursorSlice::pos_type CursorSlice::lastpos() const
103 BOOST_ASSERT(inset_);
104 return inset_->asMathInset() ? cell().size() : paragraph().size();
108 bool CursorSlice::boundary() const
114 bool & CursorSlice::boundary()
120 CursorSlice::row_type CursorSlice::row() const
122 BOOST_ASSERT(asMathInset());
123 return asMathInset()->row(idx_);
127 CursorSlice::col_type CursorSlice::col() const
129 BOOST_ASSERT(asMathInset());
130 return asMathInset()->col(idx_);
134 MathInset * CursorSlice::asMathInset() const
136 BOOST_ASSERT(inset_);
137 return inset_->asMathInset();
141 UpdatableInset * CursorSlice::asUpdatableInset() const
143 BOOST_ASSERT(inset_);
144 return inset_->asUpdatableInset();
148 MathArray & CursorSlice::cell() const
150 BOOST_ASSERT(asMathInset());
151 return asMathInset()->cell(idx_);
155 LyXText * CursorSlice::text() const
157 BOOST_ASSERT(inset_);
158 return inset_->getText(idx_);
162 Paragraph & CursorSlice::paragraph()
164 // access to the main lyx text must be handled in the cursor
165 BOOST_ASSERT(text());
166 return *text()->getPar(par_);
170 Paragraph const & CursorSlice::paragraph() const
172 // access to the main lyx text must be handled in the cursor
173 BOOST_ASSERT(text());
174 return *text()->getPar(par_);
178 bool operator==(CursorSlice const & p, CursorSlice const & q)
180 return p.inset_ == q.inset_
187 bool operator!=(CursorSlice const & p, CursorSlice const & q)
189 return p.inset_ != q.inset_
196 bool operator<(CursorSlice const & p, CursorSlice const & q)
198 if (p.inset_ != q.inset_) {
199 lyxerr << "can't compare cursor and anchor in different insets\n"
200 << "p: " << p << '\n' << "q: " << q << endl;
203 if (p.idx_ != q.idx_)
204 return p.idx_ < q.idx_;
205 if (p.par_ != q.par_)
206 return p.par_ < q.par_;
207 return p.pos_ < q.pos_;
211 bool operator>(CursorSlice const & p, CursorSlice const & q)
217 std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
220 << "inset: " << item.inset_
221 // << " text: " << item.text()
222 << " idx: " << item.idx_
223 << " par: " << item.par_
224 << " pos: " << item.pos_
225 // << " x: " << item.inset_->x()
226 // << " y: " << item.inset_->y()