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