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