]> git.lyx.org Git - lyx.git/blob - src/cursor_slice.C
64 bit compile fixes.
[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), par_(0), pos_(0), boundary_(false)
34 {}
35
36
37 CursorSlice::CursorSlice(InsetBase & p)
38         : inset_(&p), idx_(0), par_(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::idx_type CursorSlice::idx() const
66 {
67         return idx_;
68 }
69
70
71 CursorSlice::idx_type & CursorSlice::idx()
72 {
73         return idx_;
74 }
75
76
77 CursorSlice::par_type CursorSlice::par() const
78 {
79         return par_;
80 }
81
82
83 CursorSlice::par_type & CursorSlice::par()
84 {
85         return par_;
86 }
87
88
89 CursorSlice::pos_type CursorSlice::pos() const
90 {
91         return pos_;
92 }
93
94
95 CursorSlice::pos_type & CursorSlice::pos()
96 {
97         return pos_;
98 }
99
100
101 CursorSlice::pos_type CursorSlice::lastpos() const
102 {
103         BOOST_ASSERT(inset_);
104         return inset_->asMathInset() ? cell().size() : paragraph().size();
105 }
106
107
108 bool CursorSlice::boundary() const
109 {
110         return boundary_;
111 }
112
113
114 bool & CursorSlice::boundary()
115 {
116         return boundary_;
117 }
118
119
120 CursorSlice::row_type CursorSlice::row() const
121 {
122         BOOST_ASSERT(asMathInset());
123         return asMathInset()->row(idx_);
124 }
125
126
127 CursorSlice::col_type CursorSlice::col() const
128 {
129         BOOST_ASSERT(asMathInset());
130         return asMathInset()->col(idx_);
131 }
132
133
134 MathInset * CursorSlice::asMathInset() const
135 {
136         BOOST_ASSERT(inset_);
137         return inset_->asMathInset();
138 }
139
140
141 UpdatableInset * CursorSlice::asUpdatableInset() const
142 {
143         BOOST_ASSERT(inset_);
144         return inset_->asUpdatableInset();
145 }
146
147
148 MathArray & CursorSlice::cell() const
149 {
150         BOOST_ASSERT(asMathInset());
151         return asMathInset()->cell(idx_);
152 }
153
154
155 LyXText * CursorSlice::text() const
156 {
157         BOOST_ASSERT(inset_);
158         return inset_->getText(idx_);
159 }
160
161
162 Paragraph & CursorSlice::paragraph()
163 {
164         // access to the main lyx text must be handled in the cursor
165         BOOST_ASSERT(text());
166         return *text()->getPar(par_);
167 }
168
169
170 Paragraph const & CursorSlice::paragraph() const
171 {
172         // access to the main lyx text must be handled in the cursor
173         BOOST_ASSERT(text());
174         return *text()->getPar(par_);
175 }
176
177
178 bool operator==(CursorSlice const & p, CursorSlice const & q)
179 {
180         return &p.inset() == &q.inset()
181                && p.idx() == q.idx()
182                && p.par() == q.par()
183                && p.pos() == q.pos();
184 }
185
186
187 bool operator!=(CursorSlice const & p, CursorSlice const & q)
188 {
189         return &p.inset() != &q.inset()
190                || p.idx() != q.idx()
191                || p.par() != q.par()
192                || p.pos() != q.pos();
193 }
194
195
196 bool operator<(CursorSlice const & p, CursorSlice const & q)
197 {
198         if (&p.inset() != &q.inset()) {
199                 lyxerr << "can't compare cursor and anchor in different insets\n"
200                        << "p: " << p << '\n' << "q: " << q << endl;
201                 return true;
202         }
203         if (p.idx() != q.idx())
204                 return p.idx() < q.idx();
205         if (p.par() != q.par())
206                 return p.par() < q.par();
207         return p.pos() < q.pos();
208 }
209
210
211 bool operator>(CursorSlice const & p, CursorSlice const & q)
212 {
213         return q < p;
214 }
215
216
217 std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
218 {
219         return os
220            << "inset: " << &item.inset()
221 //         << " text: " << item.text()
222            << " idx: " << item.idx()
223            << " par: " << item.par()
224            << " pos: " << item.pos()
225 //         << " x: " << item.inset().x()
226 //         << " y: " << item.inset().y()
227 ;
228 }