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