]> git.lyx.org Git - lyx.git/blob - src/CursorSlice.cpp
LyXText -> Text
[lyx.git] / src / CursorSlice.cpp
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.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author Matthias Ettrich
8  * \author André Pönitz
9  * \author Jürgen Vigna
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #include <config.h>
15
16 #include "CursorSlice.h"
17 #include "debug.h"
18 #include "Text.h"
19 #include "Paragraph.h"
20
21 #include "mathed/InsetMath.h"
22 #include "mathed/MathData.h"
23
24 #include <boost/assert.hpp>
25
26
27 namespace lyx {
28
29 using std::endl;
30
31
32 CursorSlice::CursorSlice()
33         : inset_(0), idx_(0), pit_(0), pos_(0)
34 {}
35
36
37 CursorSlice::CursorSlice(Inset & p)
38         : inset_(&p), idx_(0), pit_(0), pos_(0)
39 {
40         BOOST_ASSERT(inset_);
41 }
42
43
44 MathData & CursorSlice::cell() const
45 {
46         return inset_->asInsetMath()->cell(idx_);
47 }
48
49
50 Paragraph & CursorSlice::paragraph()
51 {
52         return text()->getPar(pit_);
53 }
54
55
56 Paragraph const & CursorSlice::paragraph() const
57 {
58         return text()->getPar(pit_);
59 }
60
61
62 pos_type CursorSlice::lastpos() const
63 {
64         BOOST_ASSERT(inset_);
65         return inset_->asInsetMath() ? cell().size() : paragraph().size();
66 }
67
68
69 CursorSlice::row_type CursorSlice::row() const
70 {
71         BOOST_ASSERT(asInsetMath());
72         return asInsetMath()->row(idx_);
73 }
74
75
76 CursorSlice::col_type CursorSlice::col() const
77 {
78         BOOST_ASSERT(asInsetMath());
79         return asInsetMath()->col(idx_);
80 }
81
82
83 bool operator==(CursorSlice const & p, CursorSlice const & q)
84 {
85         return p.inset_ == q.inset_
86                && p.idx() == q.idx()
87                && p.pit() == q.pit()
88                && p.pos() == q.pos();
89 }
90
91
92 bool operator!=(CursorSlice const & p, CursorSlice const & q)
93 {
94         return p.inset_ != q.inset_
95                || p.idx() != q.idx()
96                || p.pit() != q.pit()
97                || p.pos() != q.pos();
98 }
99
100
101 bool operator<(CursorSlice const & p, CursorSlice const & q)
102 {
103         if (&p.inset() != &q.inset()) {
104                 lyxerr << "can't compare cursor and anchor in different insets\n"
105                        << "p: " << p << '\n' << "q: " << q << endl;
106                 BOOST_ASSERT(false);
107         }
108         if (p.idx() != q.idx())
109                 return p.idx() < q.idx();
110         if (p.pit() != q.pit())
111                 return p.pit() < q.pit();
112         return p.pos() < q.pos();
113 }
114
115
116 bool operator>(CursorSlice const & p, CursorSlice const & q)
117 {
118         return q < p;
119 }
120
121
122 bool operator<=(CursorSlice const & p, CursorSlice const & q)
123 {
124         return !(q < p);
125 }
126
127
128 std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
129 {
130         return os
131            << "inset: " << &item.inset()
132 //         << " text: " << item.text()
133            << " idx: " << item.idx()
134            << " par: " << item.pit()
135            << " pos: " << item.pos()
136 //         << " x: " << item.inset().x()
137 //         << " y: " << item.inset().y()
138 ;
139 }
140
141
142 } // namespace lyx