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