]> git.lyx.org Git - lyx.git/blob - src/mathed/math_pos.C
perhaps a fix for the latest crashes
[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(MathAtom & t)
17         : par_(&t), idx_(0), pos_(0)
18 {
19         lyx::Assert(par_);
20         lyx::Assert(par_->nucleus());
21 }
22
23
24 MathArray & MathCursorPos::cell(MathArray::idx_type idx) const
25 {
26         lyx::Assert(par_);
27         lyx::Assert(par_->nucleus());
28         return par_->nucleus()->cell(idx);
29 }
30
31
32 MathArray & MathCursorPos::cell() const
33 {
34         lyx::Assert(par_);
35         lyx::Assert(par_->nucleus());
36         return par_->nucleus()->cell(idx_);
37 }
38
39
40 MathXArray & MathCursorPos::xcell(MathArray::idx_type idx) const
41 {
42         lyx::Assert(par_);
43         lyx::Assert(par_->nucleus());
44         return par_->nucleus()->xcell(idx);
45 }
46
47
48 MathXArray & MathCursorPos::xcell() const
49 {
50         lyx::Assert(par_);
51         lyx::Assert(par_->nucleus());
52         return par_->nucleus()->xcell(idx_);
53 }
54
55
56 int MathCursorPos::xpos() const
57 {
58         return xcell().xo() + xcell().pos2x(pos_);
59 }
60
61
62 int MathCursorPos::ypos() const
63 {
64         return xcell().yo();
65 }
66
67
68 std::ostream & operator<<(std::ostream & os, MathCursorPos const & p)
69 {
70         os << "(par: " << p.par_ << " idx: " << p.idx_ << " pos: " << p.pos_ << ")";
71         return os;
72 }
73
74
75 bool operator==(MathCursorPos const & p, MathCursorPos const & q)
76 {
77         return p.par_ == q.par_ && p.idx_ == q.idx_ && p.pos_ == q.pos_;
78 }
79
80
81 bool operator!=(MathCursorPos const & p, MathCursorPos const & q)
82 {
83         return p.par_ != q.par_ || p.idx_ != q.idx_ || p.pos_ != q.pos_;
84 }
85
86
87 bool operator<(MathCursorPos const & p, MathCursorPos const & q)
88 {
89         if (p.par_ != q.par_) {
90                 lyxerr << "can't compare cursor and anchor in different insets\n";
91                 return true;
92         }
93         if (p.idx_ != q.idx_)
94                 return p.idx_ < q.idx_;
95         return p.pos_ < q.pos_;
96 }
97
98