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)
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::pos_type CursorSlice::lastpos() const
68 return inset_->asMathInset() ? cell().size() : paragraph().size();
72 CursorSlice::row_type CursorSlice::row() const
74 BOOST_ASSERT(asMathInset());
75 return asMathInset()->row(idx_);
79 CursorSlice::col_type CursorSlice::col() const
81 BOOST_ASSERT(asMathInset());
82 return asMathInset()->col(idx_);
86 MathInset * CursorSlice::asMathInset() const
89 return inset_->asMathInset();
93 UpdatableInset * CursorSlice::asUpdatableInset() const
96 return inset_->asUpdatableInset();
100 MathArray & CursorSlice::cell() const
102 BOOST_ASSERT(asMathInset());
103 return asMathInset()->cell(idx_);
107 LyXText * CursorSlice::text() const
109 BOOST_ASSERT(inset_);
110 return inset_->getText(idx_);
114 Paragraph & CursorSlice::paragraph()
116 // access to the main lyx text must be handled in the cursor
117 BOOST_ASSERT(text());
118 return text()->getPar(par_);
122 Paragraph const & CursorSlice::paragraph() const
124 // access to the main lyx text must be handled in the cursor
125 BOOST_ASSERT(text());
126 return text()->getPar(par_);
130 bool operator==(CursorSlice const & p, CursorSlice const & q)
132 return &p.inset() == &q.inset()
133 && p.idx() == q.idx()
134 && p.par() == q.par()
135 && p.pos() == q.pos();
139 bool operator!=(CursorSlice const & p, CursorSlice const & q)
141 return &p.inset() != &q.inset()
142 || p.idx() != q.idx()
143 || p.par() != q.par()
144 || p.pos() != q.pos();
148 bool operator<(CursorSlice const & p, CursorSlice const & q)
150 if (&p.inset() != &q.inset()) {
151 lyxerr << "can't compare cursor and anchor in different insets\n"
152 << "p: " << p << '\n' << "q: " << q << endl;
155 if (p.idx() != q.idx())
156 return p.idx() < q.idx();
157 if (p.par() != q.par())
158 return p.par() < q.par();
159 return p.pos() < q.pos();
163 bool operator>(CursorSlice const & p, CursorSlice const & q)
169 bool operator<=(CursorSlice const & p, CursorSlice const & q)
175 std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
178 << "inset: " << &item.inset()
179 // << " text: " << item.text()
180 << " idx: " << item.idx()
181 << " par: " << item.par()
182 << " pos: " << item.pos()
183 // << " x: " << item.inset().x()
184 // << " y: " << item.inset().y()