]> git.lyx.org Git - lyx.git/blob - src/mathed/math_spaceinset.C
90652b45a4616f1342abeb547b7a92151e3fc05e
[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 using std::ostream;
14
15
16 MathSpaceInset::MathSpaceInset(int sp, short ot, short st)
17         : MathedInset("", ot, st), space_(sp)
18 {}
19
20
21 MathedInset * MathSpaceInset::Clone()
22 {
23         return new MathSpaceInset(space_, GetType(), GetStyle());
24 }
25
26
27 void MathSpaceInset::draw(Painter & pain, int x, int y)
28
29         
30 // XPoint p[4] = {{++x, y-3}, {x, y}, {x+width-2, y}, {x+width-2, y-3}};
31         
32 // Sadly, HP-UX CC can't handle that kind of initialization.
33         
34         int xp[4];
35         int yp[4];
36         
37         xp[0] = ++x;            yp[0] = y - 3;
38         xp[1] = x;                 yp[1] = y;
39         xp[2] = x + width - 2;  yp[2] = y;
40         xp[3] = x + width - 2;  yp[3] = y - 3;
41         
42         pain.lines(xp, yp, 4, (space_) ? LColor::latex : LColor::math);
43 }
44
45
46 void MathSpaceInset::Write(ostream & os, bool /* fragile */)
47 {
48         if (space_ >= 0 && space_ < 6) {
49                 os << '\\' << latex_mathspace[space_] << ' ';
50         }
51 }
52
53 void MathSpaceInset::WriteNormal(ostream & os)
54 {
55         os << "{space " << space_ << "} ";
56 }
57
58
59 void MathSpaceInset::Metrics()
60 {
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();
76 }
77
78
79 int MathSpaceInset::GetSpace()
80 {
81         return space_;
82 }