]> git.lyx.org Git - lyx.git/blob - src/mathed/math_spaceinset.C
macro rework
[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 int MathSpaceInset::width() const
55 {
56         switch (space_) {
57                 case 0: return 6;
58                 case 1: return 8;
59                 case 2: return 10;
60                 case 3: return 6;
61                 case 4: return 8;
62                 case 5: return 10;
63                 case 6: return 20;
64                 case 7: return 40;
65                 case 8: return -2;
66                 case 9: return  2;
67                 default: return 6;
68         }
69 }
70
71
72 int MathSpaceInset::ascent() const
73 {
74         return 4;
75 }
76
77
78 int MathSpaceInset::descent() const
79 {
80         return 0;
81 }
82
83
84 void MathSpaceInset::metrics(MetricsInfo &, Dimension & dim) const
85 {
86         dim.wid = width();
87         dim.asc = ascent();
88         dim.des = descent();
89 }
90
91
92 void MathSpaceInset::draw(PainterInfo & pi, int x, int y) const
93 {
94         // Sadly, HP-UX CC can't handle that kind of initialization.
95         // XPoint p[4] = {{++x, y-3}, {x, y}, {x+width-2, y}, {x+width-2, y-3}};
96         if (space_ >= nSpace - 2)
97                 return;
98
99         int xp[4];
100         int yp[4];
101         int w = width();
102
103         xp[0] = ++x;        yp[0] = y - 3;
104         xp[1] = x;          yp[1] = y;
105         xp[2] = x + w - 2;  yp[2] = y;
106         xp[3] = x + w - 2;  yp[3] = y - 3;
107
108         pi.pain.lines(xp, yp, 4, (space_ < 3) ? LColor::latex : LColor::math);
109 }
110
111
112 void MathSpaceInset::incSpace()
113 {
114         space_ = (space_ + 1) % (nSpace - 2);
115 }
116
117
118 void MathSpaceInset::validate(LaTeXFeatures & features) const
119 {
120         if (space_ >= 0 && space_< nSpace) {
121                 if ((latex_mathspace[space_] == "negmedspace")
122                  || (latex_mathspace[space_] == "negthickspace"))
123                         features.require("amsmath");
124         }
125 }
126
127
128 void MathSpaceInset::maple(MapleStream & os) const
129 {
130         os << ' ';
131 }
132
133 void MathSpaceInset::mathematica(MathematicaStream & os) const
134 {
135         os << ' ';
136 }
137
138
139 void MathSpaceInset::octave(OctaveStream & os) const
140 {
141         os << ' ';
142 }
143
144
145 void MathSpaceInset::normalize(NormalStream & os) const
146 {
147         os << "[space " << int(space_) << "] ";
148 }
149
150
151 void MathSpaceInset::write(WriteStream & os) const
152 {
153         if (space_ >= 0 && space_ < nSpace) {
154                 os << '\\' << latex_mathspace[space_];
155                 os.pendingSpace(true);
156         }
157 }