]> git.lyx.org Git - lyx.git/blob - src/mathed/math_inset.C
Fix crash when cursor is in an empty script and the user clicks
[lyx.git] / src / mathed / math_inset.C
1 /**
2  * \file math_inset.C
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 "math_inset.h"
15 #include "math_data.h"
16 #include "math_mathmlstream.h"
17 #include "debug.h"
18
19 #include "support/lstrings.h"
20
21 #include <boost/current_function.hpp>
22
23 using std::string;
24 using std::ostream;
25 using std::endl;
26
27
28 MathArray & MathInset::cell(idx_type)
29 {
30         static MathArray dummyCell;
31         lyxerr << BOOST_CURRENT_FUNCTION << ": I don't have any cell" << endl;
32         return dummyCell;
33 }
34
35
36 MathArray const & MathInset::cell(idx_type) const
37 {
38         static MathArray dummyCell;
39         lyxerr << BOOST_CURRENT_FUNCTION << ": I don't have any cell" << endl;
40         return dummyCell;
41 }
42
43
44 void MathInset::dump() const
45 {
46         lyxerr << "---------------------------------------------" << endl;
47         WriteStream wi(lyxerr, false, true);
48         write(wi);
49         lyxerr << "\n---------------------------------------------" << endl;
50 }
51
52
53 void MathInset::metricsT(TextMetricsInfo const &, Dimension &) const
54 {
55 #ifdef WITH_WARNINGS
56         lyxerr << "MathInset::metricsT(Text) called directly!" << endl;
57 #endif
58 }
59
60
61 void MathInset::drawT(TextPainter &, int, int) const
62 {
63 #ifdef WITH_WARNINGS
64         lyxerr << "MathInset::drawT(Text) called directly!" << endl;
65 #endif
66 }
67
68
69
70 void MathInset::write(WriteStream & os) const
71 {
72         string const s = name();
73         os << '\\' << s.c_str();
74         // We need an extra ' ' unless this is a single-char-non-ASCII name
75         // or anything non-ASCII follows
76         if (s.size() != 1 || isalpha(s[0]))
77                 os.pendingSpace(true);
78 }
79
80
81 void MathInset::normalize(NormalStream & os) const
82 {
83         os << '[' << name().c_str() << "] ";
84 }
85
86
87 void MathInset::octave(OctaveStream & os) const
88 {
89         NormalStream ns(os.os());
90         normalize(ns);
91 }
92
93
94 void MathInset::maple(MapleStream & os) const
95 {
96         NormalStream ns(os.os());
97         normalize(ns);
98 }
99
100
101 void MathInset::maxima(MaximaStream & os) const
102 {
103         MapleStream ns(os.os());
104         maple(ns);
105 }
106
107
108 void MathInset::mathematica(MathematicaStream & os) const
109 {
110         NormalStream ns(os.os());
111         normalize(ns);
112 }
113
114
115 void MathInset::mathmlize(MathMLStream & os) const
116 {
117         NormalStream ns(os.os());
118         normalize(ns);
119 }
120
121
122 string const & MathInset::getType() const
123 {
124         static string const t = "none";
125         return t;
126 }
127
128
129 string MathInset::name() const
130 {
131         return "unknown";
132 }
133
134
135 ostream & operator<<(ostream & os, MathAtom const & at)
136 {
137         WriteStream wi(os, false, false);
138         at->write(wi);
139         return os;
140 }