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