]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathSpace.C
Fix comment according to Enricos explanation
[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 void InsetMathSpace::metrics(MetricsInfo &, Dimension & dim) const
89 {
90         dim.wid = width();
91         dim.asc = ascent();
92         dim.des = descent();
93 }
94
95
96 void InsetMathSpace::draw(PainterInfo & pi, int x, int y) const
97 {
98         // Sadly, HP-UX CC can't handle that kind of initialization.
99         // XPoint p[4] = {{++x, y-3}, {x, y}, {x+width-2, y}, {x+width-2, y-3}};
100         if (space_ >= nSpace - 2)
101                 return;
102
103         int xp[4];
104         int yp[4];
105         int w = width();
106
107         xp[0] = ++x;        yp[0] = y - 3;
108         xp[1] = x;          yp[1] = y;
109         xp[2] = x + w - 2;  yp[2] = y;
110         xp[3] = x + w - 2;  yp[3] = y - 3;
111
112         pi.pain.lines(xp, yp, 4, (space_ < 3) ? LColor::latex : LColor::math);
113 }
114
115
116 void InsetMathSpace::incSpace()
117 {
118         space_ = (space_ + 1) % (nSpace - 2);
119 }
120
121
122 void InsetMathSpace::validate(LaTeXFeatures & features) const
123 {
124         if (space_ >= 0 && space_< nSpace) {
125                 if ((latex_mathspace[space_] == string("negmedspace"))
126                  || (latex_mathspace[space_] == string("negthickspace")))
127                         features.require("amsmath");
128         }
129 }
130
131
132 void InsetMathSpace::maple(MapleStream & os) const
133 {
134         os << ' ';
135 }
136
137 void InsetMathSpace::mathematica(MathematicaStream & os) const
138 {
139         os << ' ';
140 }
141
142
143 void InsetMathSpace::octave(OctaveStream & os) const
144 {
145         os << ' ';
146 }
147
148
149 void InsetMathSpace::normalize(NormalStream & os) const
150 {
151         os << "[space " << int(space_) << "] ";
152 }
153
154
155 void InsetMathSpace::write(WriteStream & os) const
156 {
157         if (space_ >= 0 && space_ < nSpace) {
158                 os << '\\' << latex_mathspace[space_];
159                 os.pendingSpace(true);
160         }
161 }
162
163
164 } // namespace lyx