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