2 * \file CursorSlice.cpp
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 "CursorSlice.h"
20 #include "Paragraph.h"
22 #include "insets/Inset.h"
24 #include "mathed/InsetMath.h"
25 #include "mathed/MathData.h"
27 #include <boost/assert.hpp>
35 CursorSlice::CursorSlice()
36 : inset_(0), idx_(0), pit_(0), pos_(0)
40 CursorSlice::CursorSlice(Inset
& p
)
41 : inset_(&p
), idx_(0), pit_(0), pos_(0)
47 MathData
& CursorSlice::cell() const
49 return inset_
->asInsetMath()->cell(idx_
);
53 Paragraph
& CursorSlice::paragraph()
55 return text()->getPar(pit_
);
59 Paragraph
const & CursorSlice::paragraph() const
61 return text()->getPar(pit_
);
65 pos_type
CursorSlice::lastpos() const
68 return inset_
->asInsetMath() ? cell().size() : paragraph().size();
72 pit_type
CursorSlice::lastpit() const
74 if (inset().inMathed())
76 return text()->paragraphs().size() - 1;
80 CursorSlice::row_type
CursorSlice::row() const
82 BOOST_ASSERT(asInsetMath());
83 return asInsetMath()->row(idx_
);
87 CursorSlice::col_type
CursorSlice::col() const
89 BOOST_ASSERT(asInsetMath());
90 return asInsetMath()->col(idx_
);
94 bool operator==(CursorSlice
const & p
, CursorSlice
const & q
)
96 return &p
.inset() == &q
.inset()
99 && p
.pos() == q
.pos();
103 bool operator!=(CursorSlice
const & p
, CursorSlice
const & q
)
105 return &p
.inset() != &q
.inset()
106 || p
.idx() != q
.idx()
107 || p
.pit() != q
.pit()
108 || p
.pos() != q
.pos();
112 bool operator<(CursorSlice
const & p
, CursorSlice
const & q
)
114 if (&p
.inset() != &q
.inset()) {
115 lyxerr
<< "can't compare cursor and anchor in different insets\n"
116 << "p: " << p
<< '\n' << "q: " << q
<< endl
;
119 if (p
.idx() != q
.idx())
120 return p
.idx() < q
.idx();
121 if (p
.pit() != q
.pit())
122 return p
.pit() < q
.pit();
123 return p
.pos() < q
.pos();
127 bool operator>(CursorSlice
const & p
, CursorSlice
const & q
)
133 bool operator<=(CursorSlice
const & p
, CursorSlice
const & q
)
139 std::ostream
& operator<<(std::ostream
& os
, CursorSlice
const & item
)
142 << "inset: " << &item
.inset()
143 // << " text: " << item.text()
144 << " idx: " << item
.idx()
145 << " par: " << item
.pit()
146 << " pos: " << item
.pos()
147 // << " x: " << item.inset().x()
148 // << " y: " << item.inset().y()