]> git.lyx.org Git - lyx.git/blob - src/mathed/math_macroarg.C
several small fixes for mathed
[lyx.git] / src / mathed / math_macroarg.C
1 /**
2  * \file math_macroarg.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alejandro Aguilar Sierra
7  * \author André Pönitz
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "math_macroarg.h"
15 #include "math_macro.h"
16 #include "math_mathmlstream.h"
17 #include "math_support.h"
18 #include "debug.h"
19
20 using std::endl;
21 using std::auto_ptr;
22
23
24 MathMacroArgument::MathMacroArgument(int n)
25         : MathNestInset(1), number_(n), expanded_(false)
26 {
27         if (n < 1 || n > 9) {
28                 lyxerr << "MathMacroArgument::MathMacroArgument: wrong Argument id: "
29                         << n << endl;
30         }
31         str_[0] = '#';
32         str_[1] = static_cast<unsigned char>('0' + n);
33         str_[2] = '\0';
34 }
35
36
37 auto_ptr<InsetBase> MathMacroArgument::clone() const
38 {
39         return auto_ptr<InsetBase>(new MathMacroArgument(*this));
40 }
41
42
43 void MathMacroArgument::write(WriteStream & os) const
44 {
45         os << str_;
46 }
47
48
49 void MathMacroArgument::metrics(MetricsInfo & mi, Dimension & dim) const
50 {
51         if (expanded_)
52                 cell(0).metrics(mi, dim_);
53         else
54                 mathed_string_dim(mi.base.font, str_, dim_);
55         dim = dim_;
56 }
57
58
59 void MathMacroArgument::draw(PainterInfo & pi, int x, int y) const
60 {
61         if (expanded_)
62                 cell(0).draw(pi, x, y);
63         else
64                 drawStrRed(pi, x, y, str_);
65 }
66
67
68 void MathMacroArgument::normalize(NormalStream & os) const
69 {
70         os << "[macroarg " << str_ << "] ";
71 }
72
73
74 void MathMacroArgument::substitute(MathMacro const & m)
75 {
76         cell(0) = m.cell(number_ - 1);
77         expanded_ = true;
78 }