]> git.lyx.org Git - lyx.git/blob - src/mathed/math_pos.C
fix #1073
[lyx.git] / src / mathed / math_pos.C
1
2 #include "config.h"
3 #include "math_pos.h"
4 #include "math_inset.h"
5 #include "debug.h"
6 #include "support/LAssert.h"
7 #include "support/LOstream.h"
8
9
10 MathCursorPos::MathCursorPos()
11         : par_(0), idx_(0), pos_(0)
12 {}
13
14
15 MathCursorPos::MathCursorPos(MathInset * p)
16         : par_(p), idx_(0), pos_(0)
17 {
18         lyx::Assert(par_);
19 }
20
21
22
23 MathArray & MathCursorPos::cell(MathArray::idx_type idx) const
24 {
25         lyx::Assert(par_);
26         return par_->cell(idx);
27 }
28
29
30 MathArray & MathCursorPos::cell() const
31 {
32         lyx::Assert(par_);
33         return par_->cell(idx_);
34 }
35
36
37 void MathCursorPos::getPos(int & x, int & y) const
38 {
39         par_->getPos(idx_, pos_, x, y);
40 }
41
42
43 void MathCursorPos::setPos(MathArray::pos_type pos)
44 {
45         pos_ = pos;
46 }
47
48
49 std::ostream & operator<<(std::ostream & os, MathCursorPos const & p)
50 {
51         os << "(par: " << p.par_ << " idx: " << p.idx_ << " pos: " << p.pos_ << ')';
52         return os;
53 }
54
55
56 bool operator==(MathCursorPos const & p, MathCursorPos const & q)
57 {
58         return p.par_ == q.par_ && p.idx_ == q.idx_ && p.pos_ == q.pos_;
59 }
60
61
62 bool operator!=(MathCursorPos const & p, MathCursorPos const & q)
63 {
64         return p.par_ != q.par_ || p.idx_ != q.idx_ || p.pos_ != q.pos_;
65 }
66
67
68 bool operator<(MathCursorPos const & p, MathCursorPos const & q)
69 {
70         if (p.par_ != q.par_) {
71                 lyxerr << "can't compare cursor and anchor in different insets\n";
72                 return true;
73         }
74         if (p.idx_ != q.idx_)
75                 return p.idx_ < q.idx_;
76         return p.pos_ < q.pos_;
77 }