]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMath.cpp
Fix #10871 compiler warnings.
[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 InsetMath::marker_type InsetMath::marker(BufferView const *) const
62 {
63         return nargs() > 0 ? MARKER : NO_MARKER;
64 }
65
66
67 bool InsetMath::addToMathRow(MathRow & mrow, MetricsInfo & mi) const
68 {
69         MathRow::Element e(mi, MathRow::INSET, mathClass());
70         e.inset = this;
71         e.marker = mi.base.macro_nesting ? NO_MARKER : marker(mi.base.bv);
72         mrow.push_back(e);
73         return true;
74 }
75
76
77 void InsetMath::dump() const
78 {
79         lyxerr << "---------------------------------------------" << endl;
80         odocstringstream os;
81         otexrowstream ots(os);
82         WriteStream wi(ots, false, true, WriteStream::wsDefault);
83         write(wi);
84         lyxerr << to_utf8(os.str());
85         lyxerr << "\n---------------------------------------------" << endl;
86 }
87
88
89 void InsetMath::metricsT(TextMetricsInfo const &, Dimension &) const
90 {
91         LYXERR0("InsetMath::metricsT(Text) called directly!");
92 }
93
94
95 void InsetMath::drawT(TextPainter &, int, int) const
96 {
97         LYXERR0("InsetMath::drawT(Text) called directly!");
98 }
99
100
101 void InsetMath::write(WriteStream & os) const
102 {
103         MathEnsurer ensurer(os);
104         docstring const s = name();
105         os << "\\" << s;
106         // We need an extra ' ' unless this is a single-char-non-ASCII name
107         // or anything non-ASCII follows
108         if (s.size() != 1 || isAlphaASCII(s[0]))
109                 os.pendingSpace(true);
110 }
111
112
113 int InsetMath::plaintext(odocstringstream &,
114         OutputParams const &, size_t) const
115 {
116         // all math plain text output shall take place in InsetMathHull
117         LATTEST(false);
118         return 0;
119 }
120
121
122 void InsetMath::normalize(NormalStream & os) const
123 {
124         os << '[' << name() << "] ";
125 }
126
127
128 void InsetMath::octave(OctaveStream & os) const
129 {
130         NormalStream ns(os.os());
131         normalize(ns);
132 }
133
134
135 void InsetMath::maple(MapleStream & os) const
136 {
137         NormalStream ns(os.os());
138         normalize(ns);
139 }
140
141
142 void InsetMath::maxima(MaximaStream & os) const
143 {
144         MapleStream ns(os.os());
145         maple(ns);
146 }
147
148
149 void InsetMath::mathematica(MathematicaStream & os) const
150 {
151         NormalStream ns(os.os());
152         normalize(ns);
153 }
154
155
156 void InsetMath::mathmlize(MathStream & os) const
157 {
158         os << "<!-- " << from_utf8(insetName(lyxCode())) << " -->";
159         os << MTag("mi");
160         NormalStream ns(os.os());
161         normalize(ns);
162         os << ETag("mi");
163 }
164
165
166 void InsetMath::htmlize(HtmlStream & os) const
167 {
168         os << "<!-- " << from_utf8(insetName(lyxCode())) << " -->";
169         os << MTag("span", "style='color: red;'");
170         NormalStream ns(os.os());
171         normalize(ns);
172         os << ETag("span");
173 }
174
175
176 HullType InsetMath::getType() const
177 {
178         return hullNone;
179 }
180
181
182 ostream & operator<<(ostream & os, MathAtom const & at)
183 {
184         odocstringstream oss;
185         otexrowstream ots(oss);
186         WriteStream wi(ots, false, false, WriteStream::wsDefault);
187         at->write(wi);
188         return os << to_utf8(oss.str());
189 }
190
191
192 odocstream & operator<<(odocstream & os, MathAtom const & at)
193 {
194         otexrowstream ots(os);
195         WriteStream wi(ots, false, false, WriteStream::wsDefault);
196         at->write(wi);
197         return os;
198 }
199
200
201 } // namespace lyx