]> git.lyx.org Git - lyx.git/blob - src/mathed/math_spaceinset.C
LyX Drinkers United: patch 2
[lyx.git] / src / mathed / math_spaceinset.C
1 #include <config.h>
2
3 #ifdef __GNUG__
4 #pragma implementation
5 #endif
6
7 #include "math_spaceinset.h"
8 #include "LColor.h"
9 #include "Painter.h"
10 #include "mathed/support.h"
11 #include "support/LOstream.h"
12
13
14 MathSpaceInset::MathSpaceInset(int sp, MathInsetTypes ot)
15         : MathInset("", ot), space_(sp)
16 {}
17
18
19 MathInset * MathSpaceInset::Clone() const
20 {
21         return new MathSpaceInset(*this);
22 }
23
24
25 void MathSpaceInset::draw(Painter & pain, int x, int y)
26
27         
28 // XPoint p[4] = {{++x, y-3}, {x, y}, {x+width-2, y}, {x+width-2, y-3}};
29         
30 // Sadly, HP-UX CC can't handle that kind of initialization.
31         
32         int xp[4];
33         int yp[4];
34         
35         xp[0] = ++x;             yp[0] = y - 3;
36         xp[1] = x;                   yp[1] = y;
37         xp[2] = x + width_ - 2;  yp[2] = y;
38         xp[3] = x + width_ - 2;  yp[3] = y - 3;
39         
40         pain.lines(xp, yp, 4, (space_) ? LColor::latex : LColor::math);
41 }
42
43
44 void MathSpaceInset::Write(std::ostream & os, bool /* fragile */) const
45 {
46         if (space_ >= 0 && space_ < 6) {
47                 os << '\\' << latex_mathspace[space_] << ' ';
48         }
49 }
50
51
52 void MathSpaceInset::WriteNormal(std::ostream & os) const
53 {
54         os << "[space " << space_ << "] ";
55 }
56
57
58 void MathSpaceInset::Metrics(MathStyles st)
59 {
60         size_ = st;
61         width_ = space_ ? space_ * 2 : 2;
62         if (space_ > 3)
63                 width_ *= 2;
64         if (space_ == 5)
65                 width_ *= 2;
66         width_ += 4;
67         ascent_ = 4;
68         descent_ = 0;
69 }
70
71
72 void MathSpaceInset::SetSpace(int sp)
73
74         space_ = sp;
75         Metrics(size_);
76 }
77
78
79 int MathSpaceInset::GetSpace()
80 {
81         return space_;
82 }