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