]> git.lyx.org Git - lyx.git/blob - src/mathed/math_pos.C
small up/down tweaking
[lyx.git] / src / mathed / math_pos.C
1 #ifdef __GNUG__
2 #pragma implementation
3 #endif
4
5 #include "config.h"
6 #include "math_pos.h"
7 #include "math_inset.h"
8 #include "debug.h"
9 #include "support/LAssert.h"
10 #include "support/LOstream.h"
11
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 void MathCursorPos::getPos(int & x, int & y) const
41 {
42         par_->getPos(idx_, pos_, x, y);
43 }
44
45
46 void MathCursorPos::setPos(MathArray::pos_type pos)
47 {
48         pos_ = pos;
49 }
50
51
52 std::ostream & operator<<(std::ostream & os, MathCursorPos const & p)
53 {
54         os << "(par: " << p.par_ << " idx: " << p.idx_ << " pos: " << p.pos_ << ')';
55         return os;
56 }
57
58
59 bool operator==(MathCursorPos const & p, MathCursorPos const & q)
60 {
61         return p.par_ == q.par_ && p.idx_ == q.idx_ && p.pos_ == q.pos_;
62 }
63
64
65 bool operator!=(MathCursorPos const & p, MathCursorPos const & q)
66 {
67         return p.par_ != q.par_ || p.idx_ != q.idx_ || p.pos_ != q.pos_;
68 }
69
70
71 bool operator<(MathCursorPos const & p, MathCursorPos const & q)
72 {
73         if (p.par_ != q.par_) {
74                 lyxerr << "can't compare cursor and anchor in different insets\n";
75                 return true;
76         }
77         if (p.idx_ != q.idx_)
78                 return p.idx_ < q.idx_;
79         return p.pos_ < q.pos_;
80 }