]> git.lyx.org Git - lyx.git/blob - src/mathed/math_macroarg.C
oh well
[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_defs.h"
8 #include "math_mathmlstream.h"
9 #include "math_support.h"
10 #include "debug.h"
11
12
13 using std::endl;
14
15
16 MathMacroArgument::MathMacroArgument(int n, MathTextCodes code)
17         : MathNestInset(1), number_(n), expanded_(false), code_(code)
18 {
19         if (n < 1 || n > 9) {
20                 lyxerr << "MathMacroArgument::MathMacroArgument: wrong Argument id: "
21                         << n << endl;
22         }
23         str_[0] = '#';
24         str_[1] = static_cast<unsigned char>('0' + n);
25         str_[2] = '\0';
26 }
27
28
29 MathInset * MathMacroArgument::clone() const
30 {
31         return new MathMacroArgument(*this);
32 }
33
34
35 void MathMacroArgument::write(WriteStream & os) const
36 {
37         if (code_ == LM_TC_MIN)
38                 os << str_;
39         else
40                 os << '\\' << math_font_name(code_) << '{' << str_ << '}';
41 }
42
43
44 void MathMacroArgument::metrics(MathMetricsInfo const & mi) const
45 {
46         whichFont(font_, LM_TC_TEX, mi);
47         if (expanded_) {
48                 xcell(0).metrics(mi);
49                 width_   = xcell(0).width();
50                 ascent_  = xcell(0).ascent();
51                 descent_ = xcell(0).descent();
52         } else
53                 mathed_string_dim(font_, str_, ascent_, descent_, width_);
54 }
55
56
57 void MathMacroArgument::draw(Painter & pain, int x, int y) const
58 {
59         if (expanded_)
60                 xcell(0).draw(pain, x, y);
61         else
62                 drawStr(pain, font_, x, y, str_);
63 }
64
65
66 void MathMacroArgument::normalize(NormalStream & os) const
67 {
68         os << "[macroarg " << str_ << "] ";
69 }
70
71
72 void MathMacroArgument::substitute(MathMacro const & m)
73 {
74         cell(0) = m.cell(number_ - 1);
75         if (code_ != LM_TC_MIN)
76                 for (MathArray::iterator it = cell(0).begin(); it != cell(0).end(); ++it)
77                         it->nucleus()->handleFont(code_);
78         expanded_ = true;
79 }