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