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 return (inset_ && inset_->asMathInset()) ? cell().size() : paragraph().size();
107 bool CursorSlice::boundary() const
113 bool & CursorSlice::boundary()
119 CursorSlice::row_type CursorSlice::row() const
121 BOOST_ASSERT(asMathInset());
122 return asMathInset()->row(idx_);
126 CursorSlice::col_type CursorSlice::col() const
128 BOOST_ASSERT(asMathInset());
129 return asMathInset()->col(idx_);
133 MathInset * CursorSlice::asMathInset() const
135 return inset_ ? inset_->asMathInset() : 0;
139 UpdatableInset * CursorSlice::asUpdatableInset() const
141 return inset_ ? inset_->asUpdatableInset() : 0;
145 MathArray & CursorSlice::cell() const
147 BOOST_ASSERT(asMathInset());
148 return asMathInset()->cell(idx_);
152 LyXText * CursorSlice::text() const
154 return inset_ ? inset_->getText(idx_) : 0;
158 Paragraph & CursorSlice::paragraph()
160 // access to the main lyx text must be handled in the cursor
161 BOOST_ASSERT(text());
162 return *text()->getPar(par_);
166 Paragraph const & CursorSlice::paragraph() const
168 // access to the main lyx text must be handled in the cursor
169 BOOST_ASSERT(text());
170 return *text()->getPar(par_);
174 bool operator==(CursorSlice const & p, CursorSlice const & q)
176 return p.inset_ == q.inset_
183 bool operator!=(CursorSlice const & p, CursorSlice const & q)
185 return p.inset_ != q.inset_
192 bool operator<(CursorSlice const & p, CursorSlice const & q)
194 if (p.inset_ != q.inset_) {
195 lyxerr << "can't compare cursor and anchor in different insets\n"
196 << "p: " << p << '\n' << "q: " << q << endl;
199 if (p.idx_ != q.idx_)
200 return p.idx_ < q.idx_;
201 if (p.par_ != q.par_)
202 return p.par_ < q.par_;
203 return p.pos_ < q.pos_;
207 bool operator>(CursorSlice const & p, CursorSlice const & q)
213 std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
216 // << "inset: " << item.inset_
217 // << " text: " << item.text()
218 << " idx: " << item.idx_
219 << " par: " << item.par_
220 << " pos: " << item.pos_
221 // << " x: " << item.inset_->x()
222 // << " y: " << item.inset_->y()