]> git.lyx.org Git - lyx.git/blob - src/mathed/math_pos.C
revert most of the stuff that got reverted yesterday but was not
[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 MathCursorPos::MathCursorPos()
12         : par_(0), idx_(0), pos_(0)
13 {}
14
15
16 MathCursorPos::MathCursorPos(MathInset * p)
17         : par_(p), idx_(0), pos_(0)
18 {
19         lyx::Assert(par_);
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 MathXArray & MathCursorPos::xcell(MathArray::idx_type idx) const
38 {
39         lyx::Assert(par_);
40         return par_->xcell(idx);
41 }
42
43
44 MathXArray & MathCursorPos::xcell() const
45 {
46         lyx::Assert(par_);
47         return par_->xcell(idx_);
48 }
49
50
51 int MathCursorPos::xpos() const
52 {
53         return xcell().xo() + xcell().pos2x(pos_);
54 }
55
56
57 int MathCursorPos::ypos() const
58 {
59         return xcell().yo();
60 }
61
62
63 std::ostream & operator<<(std::ostream & os, MathCursorPos const & p)
64 {
65         os << "(par: " << p.par_ << " idx: " << p.idx_ << " pos: " << p.pos_ << ")";
66         return os;
67 }
68
69
70 bool operator==(MathCursorPos const & p, MathCursorPos const & q)
71 {
72         return p.par_ == q.par_ && p.idx_ == q.idx_ && p.pos_ == q.pos_;
73 }
74
75
76 bool operator!=(MathCursorPos const & p, MathCursorPos const & q)
77 {
78         return p.par_ != q.par_ || p.idx_ != q.idx_ || p.pos_ != q.pos_;
79 }
80
81
82 bool operator<(MathCursorPos const & p, MathCursorPos const & q)
83 {
84         if (p.par_ != q.par_) {
85                 lyxerr << "can't compare cursor and anchor in different insets\n";
86                 return true;
87         }
88         if (p.idx_ != q.idx_)
89                 return p.idx_ < q.idx_;
90         return p.pos_ < q.pos_;
91 }
92
93