LyX 1.5.0 is released
[lyx.git] / src / CursorSlice.cpp
blob47b518cbfd2e72c3eaf0ff2953f33ca1d31ca8d3
1 /**
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
8 * \author André Pönitz
9 * \author Jürgen Vigna
11 * Full author contact details are available in file CREDITS.
14 #include <config.h>
16 #include "CursorSlice.h"
18 #include "debug.h"
19 #include "Text.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>
29 using std::endl;
32 namespace lyx {
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)
43 BOOST_ASSERT(inset_);
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
67 BOOST_ASSERT(inset_);
68 return inset_->asInsetMath() ? cell().size() : paragraph().size();
72 pit_type CursorSlice::lastpit() const
74 if (inset().inMathed())
75 return 0;
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()
97 && p.idx() == q.idx()
98 && p.pit() == q.pit()
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;
117 BOOST_ASSERT(false);
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)
129 return q < p;
133 bool operator<=(CursorSlice const & p, CursorSlice const & q)
135 return !(q < p);
139 std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
141 return os
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()
153 } // namespace lyx