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