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 <boost/assert.hpp>
29 CursorSlice::CursorSlice()
30 : inset_(0), idx_(0), pit_(0), pos_(0)
34 CursorSlice::CursorSlice(InsetBase & p)
35 : inset_(&p), idx_(0), pit_(0), pos_(0)
41 size_t CursorSlice::nargs() const
44 return inset_->nargs();
48 size_t CursorSlice::nrows() const
51 return inset_->nrows();
55 size_t CursorSlice::ncols() const
58 return inset_->ncols();
62 CursorSlice::pos_type CursorSlice::lastpos() const
65 return inset_->asMathInset() ? cell().size() : paragraph().size();
69 CursorSlice::row_type CursorSlice::row() const
71 BOOST_ASSERT(asMathInset());
72 return asMathInset()->row(idx_);
76 CursorSlice::col_type CursorSlice::col() const
78 BOOST_ASSERT(asMathInset());
79 return asMathInset()->col(idx_);
83 MathInset * CursorSlice::asMathInset() const
86 return inset_->asMathInset();
90 MathArray & CursorSlice::cell() const
92 BOOST_ASSERT(asMathInset());
93 return asMathInset()->cell(idx_);
97 LyXText * CursorSlice::text()
100 return inset_->getText(idx_);
103 LyXText const * CursorSlice::text() const
105 BOOST_ASSERT(inset_);
106 return inset_->getText(idx_);
110 Paragraph & CursorSlice::paragraph()
112 // access to the main lyx text must be handled in the cursor
113 BOOST_ASSERT(text());
114 return text()->getPar(pit_);
118 Paragraph const & CursorSlice::paragraph() const
120 // access to the main lyx text must be handled in the cursor
121 BOOST_ASSERT(text());
122 return text()->getPar(pit_);
126 bool operator==(CursorSlice const & p, CursorSlice const & q)
128 return &p.inset() == &q.inset()
129 && p.idx() == q.idx()
130 && p.pit() == q.pit()
131 && p.pos() == q.pos();
135 bool operator!=(CursorSlice const & p, CursorSlice const & q)
137 return &p.inset() != &q.inset()
138 || p.idx() != q.idx()
139 || p.pit() != q.pit()
140 || p.pos() != q.pos();
144 bool operator<(CursorSlice const & p, CursorSlice const & q)
146 if (&p.inset() != &q.inset()) {
147 lyxerr << "can't compare cursor and anchor in different insets\n"
148 << "p: " << p << '\n' << "q: " << q << endl;
151 if (p.idx() != q.idx())
152 return p.idx() < q.idx();
153 if (p.pit() != q.pit())
154 return p.pit() < q.pit();
155 return p.pos() < q.pos();
159 bool operator>(CursorSlice const & p, CursorSlice const & q)
165 bool operator<=(CursorSlice const & p, CursorSlice const & q)
171 std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
174 << "inset: " << &item.inset()
175 // << " text: " << item.text()
176 << " idx: " << item.idx()
177 << " par: " << item.pit()
178 << " pos: " << item.pos()
179 // << " x: " << item.inset().x()
180 // << " y: " << item.inset().y()