]> git.lyx.org Git - lyx.git/blob - src/mathed/math_macroarg.C
use stream-like syntax for LaTeX output
[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 "mathed/support.h"
9 #include "debug.h"
10
11
12
13 MathMacroArgument::MathMacroArgument(int n)
14         : MathNestInset(1), number_(n), expanded_(false)
15 {
16         if (n < 1 || n > 9) {
17                 lyxerr << "MathMacroArgument::MathMacroArgument: wrong Argument id: "
18                         << n << std::endl;
19         }
20         str_[0] = '#';
21         str_[1] = '0' + n;
22         str_[2] = '\0';
23 }
24
25
26 MathInset * MathMacroArgument::clone() const
27 {
28         return new MathMacroArgument(*this);
29 }
30
31
32 void MathMacroArgument::write(MathWriteInfo & os) const
33 {
34         os << '#' << number_;
35 }
36
37
38 void MathMacroArgument::metrics(MathMetricsInfo const & st) const
39 {
40         if (expanded_) {
41                 xcell(0).metrics(st);
42                 width_   = xcell(0).width();
43                 ascent_  = xcell(0).ascent();
44                 descent_ = xcell(0).descent();
45         } else
46                 mathed_string_dim(LM_TC_TEX, size_.size, str_, ascent_, descent_, width_);
47 }
48
49
50 void MathMacroArgument::draw(Painter & pain, int x, int y) const
51 {
52         if (expanded_)
53                 xcell(0).draw(pain, x, y);
54         else
55                 drawStr(pain, LM_TC_TEX, size_.size, x, y, str_);
56 }
57
58
59 void MathMacroArgument::writeNormal(std::ostream & os) const
60 {
61         os << "[macroarg " << number_ << "] ";
62 }
63
64
65 void MathMacroArgument::substitute(MathMacro const & m)
66 {
67         cell(0) = m.cell(number_ - 1);
68         expanded_ = true;
69 }
70