]> git.lyx.org Git - lyx.git/blob - src/cursor_slice.C
par->pit renaming
[lyx.git] / src / cursor_slice.C
1 /**
2  * \file cursor_slice.C
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 "cursor_slice.h"
17 #include "debug.h"
18 #include "lyxtext.h"
19 #include "paragraph.h"
20
21 #include "mathed/math_inset.h"
22 #include "mathed/math_data.h"
23
24 #include "insets/updatableinset.h"
25
26
27 #include <boost/assert.hpp>
28
29 using std::endl;
30
31
32 CursorSlice::CursorSlice()
33         : inset_(0), idx_(0), pit_(0), pos_(0), boundary_(false)
34 {}
35
36
37 CursorSlice::CursorSlice(InsetBase & p)
38         : inset_(&p), idx_(0), pit_(0), pos_(0), boundary_(false)
39 {
40         BOOST_ASSERT(inset_);
41 }
42
43
44 size_t CursorSlice::nargs() const
45 {
46         BOOST_ASSERT(inset_);
47         return inset_->nargs();
48 }
49
50
51 size_t CursorSlice::nrows() const
52 {
53         BOOST_ASSERT(inset_);
54         return inset_->nrows();
55 }
56
57
58 size_t CursorSlice::ncols() const
59 {
60         BOOST_ASSERT(inset_);
61         return inset_->ncols();
62 }
63
64
65 CursorSlice::pos_type CursorSlice::lastpos() const
66 {
67         BOOST_ASSERT(inset_);
68         return inset_->asMathInset() ? cell().size() : paragraph().size();
69 }
70
71
72 CursorSlice::row_type CursorSlice::row() const
73 {
74         BOOST_ASSERT(asMathInset());
75         return asMathInset()->row(idx_);
76 }
77
78
79 CursorSlice::col_type CursorSlice::col() const
80 {
81         BOOST_ASSERT(asMathInset());
82         return asMathInset()->col(idx_);
83 }
84
85
86 MathInset * CursorSlice::asMathInset() const
87 {
88         BOOST_ASSERT(inset_);
89         return inset_->asMathInset();
90 }
91
92
93 UpdatableInset * CursorSlice::asUpdatableInset() const
94 {
95         BOOST_ASSERT(inset_);
96         return inset_->asUpdatableInset();
97 }
98
99
100 MathArray & CursorSlice::cell() const
101 {
102         BOOST_ASSERT(asMathInset());
103         return asMathInset()->cell(idx_);
104 }
105
106
107 LyXText * CursorSlice::text() const
108 {
109         BOOST_ASSERT(inset_);
110         return inset_->getText(idx_);
111 }
112
113
114 Paragraph & CursorSlice::paragraph()
115 {
116         // access to the main lyx text must be handled in the cursor
117         BOOST_ASSERT(text());
118         return text()->getPar(pit_);
119 }
120
121
122 Paragraph const & CursorSlice::paragraph() const
123 {
124         // access to the main lyx text must be handled in the cursor
125         BOOST_ASSERT(text());
126         return text()->getPar(pit_);
127 }
128
129
130 bool operator==(CursorSlice const & p, CursorSlice const & q)
131 {
132         return &p.inset() == &q.inset()
133                && p.idx() == q.idx()
134                && p.pit() == q.pit()
135                && p.pos() == q.pos();
136 }
137
138
139 bool operator!=(CursorSlice const & p, CursorSlice const & q)
140 {
141         return &p.inset() != &q.inset()
142                || p.idx() != q.idx()
143                || p.pit() != q.pit()
144                || p.pos() != q.pos();
145 }
146
147
148 bool operator<(CursorSlice const & p, CursorSlice const & q)
149 {
150         if (&p.inset() != &q.inset()) {
151                 lyxerr << "can't compare cursor and anchor in different insets\n"
152                        << "p: " << p << '\n' << "q: " << q << endl;
153                 BOOST_ASSERT(false);
154         }
155         if (p.idx() != q.idx())
156                 return p.idx() < q.idx();
157         if (p.pit() != q.pit())
158                 return p.pit() < q.pit();
159         return p.pos() < q.pos();
160 }
161
162
163 bool operator>(CursorSlice const & p, CursorSlice const & q)
164 {
165         return q < p;
166 }
167
168
169 bool operator<=(CursorSlice const & p, CursorSlice const & q)
170 {
171         return !(q < p);
172 }
173
174
175 std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
176 {
177         return os
178            << "inset: " << &item.inset()
179 //         << " text: " << item.text()
180            << " idx: " << item.idx()
181            << " par: " << item.pit()
182            << " pos: " << item.pos()
183 //         << " x: " << item.inset().x()
184 //         << " y: " << item.inset().y()
185 ;
186 }