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