]> git.lyx.org Git - lyx.git/blob - src/mathed/math_macroarg.C
architectural changes to tex2lyx
[lyx.git] / src / mathed / math_macroarg.C
1 #include "math_macroarg.h"
2 #include "math_macro.h"
3 #include "math_mathmlstream.h"
4 #include "math_support.h"
5 #include "debug.h"
6
7 using std::endl;
8 using std::auto_ptr;
9
10
11 MathMacroArgument::MathMacroArgument(int n)
12         : MathNestInset(1), number_(n), expanded_(false)
13 {
14         if (n < 1 || n > 9) {
15                 lyxerr << "MathMacroArgument::MathMacroArgument: wrong Argument id: "
16                         << n << endl;
17         }
18         str_[0] = '#';
19         str_[1] = static_cast<unsigned char>('0' + n);
20         str_[2] = '\0';
21 }
22
23
24 auto_ptr<InsetBase> MathMacroArgument::clone() const
25 {
26         return auto_ptr<InsetBase>(new MathMacroArgument(*this));
27 }
28
29
30 void MathMacroArgument::write(WriteStream & os) const
31 {
32         os << str_;
33 }
34
35
36 void MathMacroArgument::metrics(MetricsInfo & mi, Dimension & dim) const
37 {
38         if (expanded_)
39                 cell(0).metrics(mi, dim_);
40         else
41                 mathed_string_dim(mi.base.font, str_, dim_);
42         dim = 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 }