]> git.lyx.org Git - lyx.git/blob - src/cursor_slice.C
some integer type changes for inset unification
[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
19 #include "mathed/math_inset.h"
20 #include "insets/updatableinset.h"
21
22 #include <boost/assert.hpp>
23
24 using std::endl;
25
26
27 CursorSlice::CursorSlice()
28         : inset_(0), idx_(0), par_(0), pos_(0), boundary_(false)
29 {}
30
31
32 CursorSlice::CursorSlice(InsetBase * p)
33         : inset_(p), idx_(0), par_(0), pos_(0), boundary_(false)
34 {
35         ///BOOST_ASSERT(inset_);
36 }
37
38
39 void CursorSlice::par(lyx::paroffset_type par)
40 {
41         par_ = par;
42 }
43
44
45 lyx::paroffset_type CursorSlice::par() const
46 {
47         return par_;
48 }
49
50
51 void CursorSlice::pos(lyx::pos_type pos)
52 {
53         pos_ = pos;
54 }
55
56
57 lyx::pos_type CursorSlice::pos() const
58 {
59         return pos_;
60 }
61
62
63 void CursorSlice::boundary(bool boundary)
64 {
65         boundary_ = boundary;
66 }
67
68
69 bool CursorSlice::boundary() const
70 {
71         return boundary_;
72 }
73
74
75 MathInset * CursorSlice::asMathInset() const
76 {
77         return static_cast<MathInset *>(const_cast<InsetBase *>(inset_));
78 }
79
80
81 UpdatableInset * CursorSlice::asUpdatableInset() const
82 {
83         return static_cast<UpdatableInset *>(const_cast<InsetBase *>(inset_));
84 }
85
86
87 MathArray & CursorSlice::cell(CursorSlice::idx_type idx) const
88 {
89         BOOST_ASSERT(inset_);
90         return asMathInset()->cell(idx);
91 }
92
93
94 MathArray & CursorSlice::cell() const
95 {
96         BOOST_ASSERT(inset_);
97         return asMathInset()->cell(idx_);
98 }
99
100
101 void CursorSlice::getPos(int & x, int & y) const
102 {
103         asMathInset()->getPos(idx_, pos_, x, y);
104 }
105
106
107 void CursorSlice::setPos(int pos)
108 {
109         pos_ = pos;
110 }
111
112
113 LyXText * CursorSlice::text() const
114 {
115         return asUpdatableInset()->getText(idx_);
116 }
117
118
119 bool operator==(CursorSlice const & p, CursorSlice const & q)
120 {
121         return p.inset_ == q.inset_
122                && p.idx_ == q.idx_
123                && p.par_ == q.par_
124                && p.pos_ == q.pos_;
125 }
126
127
128 bool operator!=(CursorSlice const & p, CursorSlice const & q)
129 {
130         return p.inset_ != q.inset_
131                || p.idx_ != q.idx_
132                || p.par_ != q.par_
133                || p.pos_ != q.pos_;
134 }
135
136
137 bool operator<(CursorSlice const & p, CursorSlice const & q)
138 {
139         if (p.inset_ != q.inset_) {
140                 lyxerr << "can't compare cursor and anchor in different insets\n"
141                        << "p: " << p << '\n' << "q: " << q << endl;
142                 return true;
143         }
144         if (p.idx_ != q.idx_)
145                 return p.idx_ < q.idx_;
146         if (p.par_ != q.par_)
147                 return p.par_ < q.par_;
148         return p.pos_ < q.pos_;
149 }
150
151
152 //std::ostream & operator<<(std::ostream & os, CursorSlice const & p)
153 //{
154 //      os << "(par: " << p.inset_ << " idx: " << p.idx_ << " pos: " << p.pos_ << ')';
155 //      return os;
156 //}
157
158
159 std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
160 {
161         os << " inset: " << item.inset_
162 //         << " text: " << item.text()
163            << " idx: " << item.idx_
164 //         << " par: " << item.par_
165 //         << " pos: " << item.pos_
166 //         << " x: " << item.inset_->x()
167 //         << " y: " << item.inset_->y()
168 ;
169         return os;
170 }
171
172