]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathSpace.C
Almost fix 'make check'. The only remaining problem is an undefined
[lyx.git] / src / mathed / InsetMathSpace.C
1 /**
2  * \file InsetMathSpace.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 "InsetMathSpace.h"
14 #include "MathData.h"
15 #include "MathStream.h"
16
17 #include "LaTeXFeatures.h"
18 #include "LColor.h"
19
20 #include "frontends/Painter.h"
21
22
23 namespace lyx {
24
25 using std::string;
26 using std::auto_ptr;
27
28
29 char const * latex_mathspace[] = {
30         "!", "negmedspace", "negthickspace",  // negative space
31         ",", ":", ";", "quad", "qquad",       // positive space
32         "lyxnegspace", "lyxposspace"          // LyX special ("unvisible space")
33 };
34
35 int const nSpace = sizeof(latex_mathspace)/sizeof(char *);
36
37
38 InsetMathSpace::InsetMathSpace(int sp)
39         : space_(sp)
40 {}
41
42
43 InsetMathSpace::InsetMathSpace(docstring const & name)
44         : space_(1)
45 {
46         for (int i = 0; i < nSpace; ++i)
47                 if (latex_mathspace[i] == name)
48                         space_ = i;
49 }
50
51
52 auto_ptr<InsetBase> InsetMathSpace::doClone() const
53 {
54         return auto_ptr<InsetBase>(new InsetMathSpace(*this));
55 }
56
57
58 int InsetMathSpace::width() const
59 {
60         switch (space_) {
61                 case 0: return 6;
62                 case 1: return 8;
63                 case 2: return 10;
64                 case 3: return 6;
65                 case 4: return 8;
66                 case 5: return 10;
67                 case 6: return 20;
68                 case 7: return 40;
69                 case 8: return -2;
70                 case 9: return  2;
71                 default: return 6;
72         }
73 }
74
75
76 int InsetMathSpace::ascent() const
77 {
78         return 4;
79 }
80
81
82 int InsetMathSpace::descent() const
83 {
84         return 0;
85 }
86
87
88 bool InsetMathSpace::metrics(MetricsInfo &, Dimension & dim) const
89 {
90         dim.wid = width();
91         dim.asc = ascent();
92         dim.des = descent();
93         if (dim_ == dim)
94                 return false;
95         dim_ = dim;
96         return true;
97 }
98
99
100 void InsetMathSpace::draw(PainterInfo & pi, int x, int y) const
101 {
102         // Sadly, HP-UX CC can't handle that kind of initialization.
103         // XPoint p[4] = {{++x, y-3}, {x, y}, {x+width-2, y}, {x+width-2, y-3}};
104         if (space_ >= nSpace - 2)
105                 return;
106
107         int xp[4];
108         int yp[4];
109         int w = width();
110
111         xp[0] = ++x;        yp[0] = y - 3;
112         xp[1] = x;          yp[1] = y;
113         xp[2] = x + w - 2;  yp[2] = y;
114         xp[3] = x + w - 2;  yp[3] = y - 3;
115
116         pi.pain.lines(xp, yp, 4, (space_ < 3) ? LColor::latex : LColor::math);
117 }
118
119
120 void InsetMathSpace::incSpace()
121 {
122         space_ = (space_ + 1) % (nSpace - 2);
123 }
124
125
126 void InsetMathSpace::validate(LaTeXFeatures & features) const
127 {
128         if (space_ >= 0 && space_< nSpace) {
129                 if ((latex_mathspace[space_] == string("negmedspace"))
130                  || (latex_mathspace[space_] == string("negthickspace")))
131                         features.require("amsmath");
132         }
133 }
134
135
136 void InsetMathSpace::maple(MapleStream & os) const
137 {
138         os << ' ';
139 }
140
141 void InsetMathSpace::mathematica(MathematicaStream & os) const
142 {
143         os << ' ';
144 }
145
146
147 void InsetMathSpace::octave(OctaveStream & os) const
148 {
149         os << ' ';
150 }
151
152
153 void InsetMathSpace::normalize(NormalStream & os) const
154 {
155         os << "[space " << int(space_) << "] ";
156 }
157
158
159 void InsetMathSpace::write(WriteStream & os) const
160 {
161         if (space_ >= 0 && space_ < nSpace) {
162                 os << '\\' << latex_mathspace[space_];
163                 os.pendingSpace(true);
164         }
165 }
166
167
168 } // namespace lyx