]> git.lyx.org Git - lyx.git/blob - src/mathed/math_spaceinset.C
ws changes
[lyx.git] / src / mathed / math_spaceinset.C
1 #ifdef __GNUG__
2 #pragma implementation
3 #endif
4
5 #include "math_spaceinset.h"
6 #include "math_support.h"
7 #include "LColor.h"
8 #include "frontends/Painter.h"
9 #include "math_mathmlstream.h"
10 #include "LaTeXFeatures.h"
11 #include "debug.h"
12
13
14 char const * latex_mathspace[] = {
15         "!", "negmedspace", "negthickspace",  // negative space
16         ",", ":", ";", "quad", "qquad",       // positive space
17         "lyxnegspace", "lyxposspace"          // LyX special ("unvisible space")
18 };
19
20 int const nSpace = sizeof(latex_mathspace)/sizeof(char *);
21
22
23 MathSpaceInset::MathSpaceInset(int sp)
24         : space_(sp)
25 {}
26
27
28 MathSpaceInset::MathSpaceInset(string const & name)
29         : space_(1)
30 {
31         for (int i = 0; i < nSpace; ++i)
32                 if (latex_mathspace[i] == name)
33                         space_ = i;
34 }
35
36
37
38 MathInset * MathSpaceInset::clone() const
39 {
40         return new MathSpaceInset(*this);
41 }
42
43
44 void MathSpaceInset::metrics(MathMetricsInfo &) const
45 {
46         switch (space_) {
47                 case 0: dim_.w = 6; break;
48                 case 1: dim_.w = 8; break;
49                 case 2: dim_.w = 10; break;
50                 case 3: dim_.w = 6; break;
51                 case 4: dim_.w = 8; break;
52                 case 5: dim_.w = 10; break;
53                 case 6: dim_.w = 20; break;
54                 case 7: dim_.w = 40; break;
55                 case 8: dim_.w = -2; break;
56                 case 9: dim_.w =  2; break;
57                 default: dim_.w = 6;
58         }
59         dim_.a = 4;
60         dim_.d = 0;
61 }
62
63
64 void MathSpaceInset::draw(MathPainterInfo & pi, int x, int y) const
65 {
66
67 // Sadly, HP-UX CC can't handle that kind of initialization.
68 // XPoint p[4] = {{++x, y-3}, {x, y}, {x+width-2, y}, {x+width-2, y-3}};
69         if (space_ >= nSpace - 2)
70                 return;
71
72         int xp[4];
73         int yp[4];
74
75         xp[0] = ++x;              yp[0] = y - 3;
76         xp[1] = x;                yp[1] = y;
77         xp[2] = x + width() - 2;  yp[2] = y;
78         xp[3] = x + width() - 2;  yp[3] = y - 3;
79
80         pi.pain.lines(xp, yp, 4, (space_ < 3) ? LColor::latex : LColor::math);
81 }
82
83
84 void MathSpaceInset::incSpace()
85 {
86         space_ = (space_ + 1) % (nSpace - 2);
87 }
88
89 void MathSpaceInset::validate(LaTeXFeatures & features) const
90 {
91         if (space_ >= 0 && space_< nSpace) {
92                 if ((latex_mathspace[space_] == "negmedspace")
93                  || (latex_mathspace[space_] == "negthickspace"))
94                         features.require("amsmath");
95         }
96 }
97
98
99 void MathSpaceInset::maplize(MapleStream & os) const
100 {
101         os << ' ';
102 }
103
104 void MathSpaceInset::mathematicize(MathematicaStream & os) const
105 {
106         os << ' ';
107 }
108
109
110 void MathSpaceInset::octavize(OctaveStream & os) const
111 {
112         os << ' ';
113 }
114
115
116 void MathSpaceInset::normalize(NormalStream & os) const
117 {
118         os << "[space " << int(space_) << "] ";
119 }
120
121
122 void MathSpaceInset::write(WriteStream & os) const
123 {
124         if (space_ >= 0 && space_ < nSpace) {
125                 os << '\\' << latex_mathspace[space_];
126                 os.pendingSpace(true);
127         }
128 }