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
46 return inset_->nargs();
50 size_t CursorSlice::nrows() const
52 return inset_->nrows();
56 size_t CursorSlice::ncols() const
58 return inset_->ncols();
62 CursorSlice::idx_type CursorSlice::idx() const
68 CursorSlice::idx_type & CursorSlice::idx()
74 CursorSlice::par_type CursorSlice::par() const
80 CursorSlice::par_type & CursorSlice::par()
86 CursorSlice::pos_type CursorSlice::pos() const
92 CursorSlice::pos_type & CursorSlice::pos()
98 CursorSlice::pos_type CursorSlice::lastpos() const
100 return (inset_ && inset_->asMathInset()) ? cell().size() : paragraph().size();
104 bool CursorSlice::boundary() const
110 bool & CursorSlice::boundary()
116 CursorSlice::row_type CursorSlice::row() const
118 BOOST_ASSERT(asMathInset());
119 return asMathInset()->row(idx_);
123 CursorSlice::col_type CursorSlice::col() const
125 BOOST_ASSERT(asMathInset());
126 return asMathInset()->col(idx_);
130 MathInset * CursorSlice::asMathInset() const
132 return inset_ ? inset_->asMathInset() : 0;
136 UpdatableInset * CursorSlice::asUpdatableInset() const
138 return inset_ ? inset_->asUpdatableInset() : 0;
142 MathArray & CursorSlice::cell() const
144 BOOST_ASSERT(asMathInset());
145 return asMathInset()->cell(idx_);
149 LyXText * CursorSlice::text() const
151 return inset_ ? inset_->getText(idx_) : 0;
155 Paragraph & CursorSlice::paragraph()
157 // access to the main lyx text must be handled in the cursor
158 BOOST_ASSERT(text());
159 return *text()->getPar(par_);
163 Paragraph const & CursorSlice::paragraph() const
165 // access to the main lyx text must be handled in the cursor
166 BOOST_ASSERT(text());
167 return *text()->getPar(par_);
171 bool operator==(CursorSlice const & p, CursorSlice const & q)
173 return p.inset_ == q.inset_
180 bool operator!=(CursorSlice const & p, CursorSlice const & q)
182 return p.inset_ != q.inset_
189 bool operator<(CursorSlice const & p, CursorSlice const & q)
191 if (p.inset_ != q.inset_) {
192 lyxerr << "can't compare cursor and anchor in different insets\n"
193 << "p: " << p << '\n' << "q: " << q << endl;
196 if (p.idx_ != q.idx_)
197 return p.idx_ < q.idx_;
198 if (p.par_ != q.par_)
199 return p.par_ < q.par_;
200 return p.pos_ < q.pos_;
204 bool operator>(CursorSlice const & p, CursorSlice const & q)
210 std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
213 // << "inset: " << item.inset_
214 // << " text: " << item.text()
215 << " idx: " << item.idx_
216 << " par: " << item.par_
217 << " pos: " << item.pos_
218 // << " x: " << item.inset_->x()
219 // << " y: " << item.inset_->y()