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