]> git.lyx.org Git - lyx.git/blob - src/mathed/math_macroarg.C
fix #1073
[lyx.git] / src / mathed / math_macroarg.C
1
2 #include "math_macroarg.h"
3 #include "math_macro.h"
4 #include "math_mathmlstream.h"
5 #include "math_support.h"
6 #include "debug.h"
7
8
9 using std::endl;
10
11
12 MathMacroArgument::MathMacroArgument(int n)
13         : MathNestInset(1), number_(n), expanded_(false)
14 {
15         if (n < 1 || n > 9) {
16                 lyxerr << "MathMacroArgument::MathMacroArgument: wrong Argument id: "
17                         << n << endl;
18         }
19         str_[0] = '#';
20         str_[1] = static_cast<unsigned char>('0' + n);
21         str_[2] = '\0';
22 }
23
24
25 MathInset * MathMacroArgument::clone() const
26 {
27         return new MathMacroArgument(*this);
28 }
29
30
31 void MathMacroArgument::write(WriteStream & os) const
32 {
33         os << str_;
34 }
35
36
37 void MathMacroArgument::metrics(MetricsInfo & mi) const
38 {
39         if (expanded_)
40                 dim_ = cell(0).metrics(mi);
41         else
42                 mathed_string_dim(mi.base.font, str_, dim_);
43 }
44
45
46 void MathMacroArgument::draw(PainterInfo & pi, int x, int y) const
47 {
48         if (expanded_)
49                 cell(0).draw(pi, x, y);
50         else
51                 drawStrRed(pi, x, y, str_);
52 }
53
54
55 void MathMacroArgument::normalize(NormalStream & os) const
56 {
57         os << "[macroarg " << str_ << "] ";
58 }
59
60
61 void MathMacroArgument::substitute(MathMacro const & m)
62 {
63         cell(0) = m.cell(number_ - 1);
64         expanded_ = true;
65 }