]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMath.cpp
Get rid of Inset::setPosCache
[lyx.git] / src / mathed / InsetMath.cpp
1 /**
2  * \file InsetMath.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alejandro Aguilar Sierra
7  * \author André Pönitz
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "InsetMath.h"
15 #include "MathData.h"
16 #include "MathRow.h"
17 #include "MathStream.h"
18
19 #include "MetricsInfo.h"
20
21 #include "support/debug.h"
22 #include "support/docstream.h"
23 #include "support/gettext.h"
24 #include "support/lassert.h"
25 #include "support/lstrings.h"
26 #include "support/textutils.h"
27
28
29 using namespace std;
30
31 namespace lyx {
32
33 docstring InsetMath::name() const
34 {
35         return from_utf8("Unknown");
36 }
37
38
39 MathData & InsetMath::cell(idx_type)
40 {
41         static MathData dummyCell(&buffer());
42         LYXERR0("I don't have any cell");
43         return dummyCell;
44 }
45
46
47 MathData const & InsetMath::cell(idx_type) const
48 {
49         static MathData dummyCell;
50         LYXERR0("I don't have any cell");
51         return dummyCell;
52 }
53
54
55 MathClass InsetMath::mathClass() const
56 {
57         return MC_ORD;
58 }
59
60
61 bool InsetMath::addToMathRow(MathRow & mrow, MetricsInfo & ) const
62 {
63         MathRow::Element e(MathRow::INSET, mathClass());
64         e.inset = this;
65         mrow.push_back(e);
66         return true;
67 }
68
69 void InsetMath::metricsMarkers(MetricsInfo & mi, Dimension & dim,
70                            int framesize) const
71 {
72         if (!mi.base.macro_nesting)
73                 Inset::metricsMarkers(dim, framesize);
74 }
75
76
77 void InsetMath::metricsMarkers2(MetricsInfo & mi, Dimension & dim,
78                             int framesize) const
79 {
80         if (!mi.base.macro_nesting)
81                 Inset::metricsMarkers2(dim, framesize);
82 }
83
84
85 void InsetMath::drawMarkers(PainterInfo & pi, int x, int y) const
86 {
87         if (!pi.base.macro_nesting)
88                 Inset::drawMarkers(pi, x, y);
89 }
90
91
92 void InsetMath::drawMarkers2(PainterInfo & pi, int x, int y) const
93 {
94         if (!pi.base.macro_nesting)
95                 Inset::drawMarkers2(pi, x, y);
96 }
97
98
99
100 void InsetMath::dump() const
101 {
102         lyxerr << "---------------------------------------------" << endl;
103         odocstringstream os;
104         otexrowstream ots(os);
105         WriteStream wi(ots, false, true, WriteStream::wsDefault);
106         write(wi);
107         lyxerr << to_utf8(os.str());
108         lyxerr << "\n---------------------------------------------" << endl;
109 }
110
111
112 void InsetMath::metricsT(TextMetricsInfo const &, Dimension &) const
113 {
114         LYXERR0("InsetMath::metricsT(Text) called directly!");
115 }
116
117
118 void InsetMath::drawT(TextPainter &, int, int) const
119 {
120         LYXERR0("InsetMath::drawT(Text) called directly!");
121 }
122
123
124 void InsetMath::write(WriteStream & os) const
125 {
126         MathEnsurer ensurer(os);
127         docstring const s = name();
128         os << "\\" << s;
129         // We need an extra ' ' unless this is a single-char-non-ASCII name
130         // or anything non-ASCII follows
131         if (s.size() != 1 || isAlphaASCII(s[0]))
132                 os.pendingSpace(true);
133 }
134
135
136 int InsetMath::plaintext(odocstringstream &, 
137         OutputParams const &, size_t) const
138 {
139         // all math plain text output shall take place in InsetMathHull
140         LATTEST(false);
141         return 0;
142 }
143
144
145 void InsetMath::normalize(NormalStream & os) const
146 {
147         os << '[' << name() << "] ";
148 }
149
150
151 void InsetMath::octave(OctaveStream & os) const
152 {
153         NormalStream ns(os.os());
154         normalize(ns);
155 }
156
157
158 void InsetMath::maple(MapleStream & os) const
159 {
160         NormalStream ns(os.os());
161         normalize(ns);
162 }
163
164
165 void InsetMath::maxima(MaximaStream & os) const
166 {
167         MapleStream ns(os.os());
168         maple(ns);
169 }
170
171
172 void InsetMath::mathematica(MathematicaStream & os) const
173 {
174         NormalStream ns(os.os());
175         normalize(ns);
176 }
177
178
179 void InsetMath::mathmlize(MathStream & os) const
180 {
181         os << "<!-- " << from_utf8(insetName(lyxCode())) << " -->";
182         os << MTag("mi");
183         NormalStream ns(os.os());
184         normalize(ns);
185         os << ETag("mi");
186 }
187
188
189 void InsetMath::htmlize(HtmlStream & os) const
190 {
191         os << "<!-- " << from_utf8(insetName(lyxCode())) << " -->";
192         os << MTag("span", "style='color: red;'");
193         NormalStream ns(os.os());
194         normalize(ns);
195         os << ETag("span");
196 }
197
198
199 HullType InsetMath::getType() const
200 {
201         return hullNone;
202 }
203
204
205 ostream & operator<<(ostream & os, MathAtom const & at)
206 {
207         odocstringstream oss;
208         otexrowstream ots(oss);
209         WriteStream wi(ots, false, false, WriteStream::wsDefault);
210         at->write(wi);
211         return os << to_utf8(oss.str());
212 }
213
214
215 odocstream & operator<<(odocstream & os, MathAtom const & at)
216 {
217         otexrowstream ots(os);
218         WriteStream wi(ots, false, false, WriteStream::wsDefault);
219         at->write(wi);
220         return os;
221 }
222
223
224 } // namespace lyx