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), pit_(0), pos_(0)
37 CursorSlice::CursorSlice(InsetBase & p)
38 : inset_(&p), idx_(0), pit_(0), pos_(0)
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()
109 BOOST_ASSERT(inset_);
110 return inset_->getText(idx_);
113 LyXText const * CursorSlice::text() const
115 BOOST_ASSERT(inset_);
116 return inset_->getText(idx_);
120 Paragraph & CursorSlice::paragraph()
122 // access to the main lyx text must be handled in the cursor
123 BOOST_ASSERT(text());
124 return text()->getPar(pit_);
128 Paragraph const & CursorSlice::paragraph() const
130 // access to the main lyx text must be handled in the cursor
131 BOOST_ASSERT(text());
132 return text()->getPar(pit_);
136 bool operator==(CursorSlice const & p, CursorSlice const & q)
138 return &p.inset() == &q.inset()
139 && p.idx() == q.idx()
140 && p.pit() == q.pit()
141 && p.pos() == q.pos();
145 bool operator!=(CursorSlice const & p, CursorSlice const & q)
147 return &p.inset() != &q.inset()
148 || p.idx() != q.idx()
149 || p.pit() != q.pit()
150 || p.pos() != q.pos();
154 bool operator<(CursorSlice const & p, CursorSlice const & q)
156 if (&p.inset() != &q.inset()) {
157 lyxerr << "can't compare cursor and anchor in different insets\n"
158 << "p: " << p << '\n' << "q: " << q << endl;
161 if (p.idx() != q.idx())
162 return p.idx() < q.idx();
163 if (p.pit() != q.pit())
164 return p.pit() < q.pit();
165 return p.pos() < q.pos();
169 bool operator>(CursorSlice const & p, CursorSlice const & q)
175 bool operator<=(CursorSlice const & p, CursorSlice const & q)
181 std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
184 << "inset: " << &item.inset()
185 // << " text: " << item.text()
186 << " idx: " << item.idx()
187 << " par: " << item.pit()
188 << " pos: " << item.pos()
189 // << " x: " << item.inset().x()
190 // << " y: " << item.inset().y()