]> git.lyx.org Git - lyx.git/blob - src/mathed/math_macrotemplate.C
Reduce Michael's buglist.
[lyx.git] / src / mathed / math_macrotemplate.C
1 #ifdef __GNUG__
2 #pragma implementation
3 #endif
4
5 #include "math_macrotemplate.h"
6 #include "math_mathmlstream.h"
7 #include "Painter.h"
8 #include "debug.h"
9
10
11 MathMacroTemplate::MathMacroTemplate()
12         : MathNestInset(1), numargs_(0), name_()
13 {}
14
15
16 MathMacroTemplate::MathMacroTemplate(string const & nm, int numargs)
17         : MathNestInset(1), numargs_(numargs), name_(nm)
18 {
19         if (numargs_ > 9) {
20                 lyxerr << "MathMacroTemplate::MathMacroTemplate: wrong # of arguments: "
21                         << numargs_ << std::endl;
22         }
23 }
24
25
26 MathInset * MathMacroTemplate::clone() const
27 {
28         //lyxerr << "cloning MacroTemplate!\n";
29         return new MathMacroTemplate(*this);
30 }
31
32
33 int MathMacroTemplate::numargs() const
34 {
35         return numargs_;
36 }
37
38
39 void MathMacroTemplate::numargs(int numargs)
40 {
41         numargs_ = numargs;
42 }
43
44
45 string const & MathMacroTemplate::name() const
46 {
47         return name_;
48 }
49
50
51 void MathMacroTemplate::metrics(MathMetricsInfo const & mi) const
52 {
53         xcell(0).metrics(mi);
54         width_   = xcell(0).width() + 4;
55         ascent_  = xcell(0).ascent() + 2;
56         descent_ = xcell(0).descent() + 2;
57 }
58
59
60 void MathMacroTemplate::draw(Painter & pain, int x, int y) const
61 {
62         xcell(0).draw(pain, x + 2, y + 1);
63         pain.rectangle(x, y - ascent(), width(), height(), LColor::blue);
64 }
65
66
67 void MathMacroTemplate::write(WriteStream & os) const
68 {
69         os << "\n\\newcommand{\\" << name_.c_str() << '}';
70         if (numargs_ > 0)
71                 os << '[' << numargs_ << ']';
72         os << '{' << cell(0) << "}\n";
73 }