]> git.lyx.org Git - lyx.git/blob - src/mathed/math_pos.C
Georg Baum's vspace change
[lyx.git] / src / mathed / math_pos.C
1 /**
2  * \file math_pos.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "math_pos.h"
14 #include "math_inset.h"
15 #include "debug.h"
16
17 #include <boost/assert.hpp>
18
19 using std::endl;
20
21
22 CursorPos::CursorPos()
23         : inset_(0), idx_(0), pos_(0)
24 {}
25
26
27 CursorPos::CursorPos(MathInset * p)
28         : inset_(p), idx_(0), pos_(0)
29 {
30         BOOST_ASSERT(inset_);
31 }
32
33
34
35 MathArray & CursorPos::cell(MathArray::idx_type idx) const
36 {
37         BOOST_ASSERT(inset_);
38         return inset_->cell(idx);
39 }
40
41
42 MathArray & CursorPos::cell() const
43 {
44         BOOST_ASSERT(inset_);
45         return inset_->cell(idx_);
46 }
47
48
49 void CursorPos::getPos(int & x, int & y) const
50 {
51         inset_->getPos(idx_, pos_, x, y);
52 }
53
54
55 void CursorPos::setPos(MathArray::pos_type pos)
56 {
57         pos_ = pos;
58 }
59
60
61 std::ostream & operator<<(std::ostream & os, CursorPos const & p)
62 {
63         os << "(par: " << p.inset_ << " idx: " << p.idx_ << " pos: " << p.pos_ << ')';
64         return os;
65 }
66
67
68 bool operator==(CursorPos const & p, CursorPos const & q)
69 {
70         return p.inset_ == q.inset_ && p.idx_ == q.idx_ && p.pos_ == q.pos_;
71 }
72
73
74 bool operator!=(CursorPos const & p, CursorPos const & q)
75 {
76         return p.inset_ != q.inset_ || p.idx_ != q.idx_ || p.pos_ != q.pos_;
77 }
78
79
80 bool operator<(CursorPos const & p, CursorPos const & q)
81 {
82         if (p.inset_ != q.inset_) {
83                 lyxerr << "can't compare cursor and anchor in different insets\n"
84                        << "p: " << p << '\n' << "q: " << q << endl;
85                 return true;
86         }
87         if (p.idx_ != q.idx_)
88                 return p.idx_ < q.idx_;
89         return p.pos_ < q.pos_;
90 }