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