]> git.lyx.org Git - lyx.git/blob - src/mathed/math_macroarg.C
- remove MathStyles cache from those insets that don't need it
[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 & mi) const
39 {
40         mi_ = mi;
41         if (expanded_) {
42                 xcell(0).metrics(mi_);
43                 width_   = xcell(0).width();
44                 ascent_  = xcell(0).ascent();
45                 descent_ = xcell(0).descent();
46         } else
47                 mathed_string_dim(LM_TC_TEX, mi_, str_, ascent_, descent_, width_);
48 }
49
50
51 void MathMacroArgument::draw(Painter & pain, int x, int y) const
52 {
53         if (expanded_)
54                 xcell(0).draw(pain, x, y);
55         else
56                 drawStr(pain, LM_TC_TEX, mi_, x, y, str_);
57 }
58
59
60 void MathMacroArgument::writeNormal(std::ostream & os) const
61 {
62         os << "[macroarg " << number_ << "] ";
63 }
64
65
66 void MathMacroArgument::substitute(MathMacro const & m)
67 {
68         cell(0) = m.cell(number_ - 1);
69         expanded_ = true;
70 }
71