]> git.lyx.org Git - lyx.git/blob - src/mathed/math_macrotemplate.C
LyX Drinkers Union: patch 1
[lyx.git] / src / mathed / math_macrotemplate.C
1 #include <config.h>
2
3 #ifdef __GNUG__
4 #pragma implementation
5 #endif
6
7 #include "math_macrotemplate.h"
8 #include "Painter.h"
9 #include "debug.h"
10
11
12 MathMacroTemplate::MathMacroTemplate() :
13         MathInset("undefined", LM_OT_MACRO, 1), numargs_(0), users_()
14 {}
15
16
17 MathMacroTemplate::MathMacroTemplate(string const & nm, int numargs) :
18         MathInset(nm, LM_OT_MACRO, 1), numargs_(numargs), users_()
19 {}
20
21
22 MathMacroTemplate * MathMacroTemplate::Clone() const
23 {
24         lyxerr << "cloning MacroTemplate!\n";
25         return new MathMacroTemplate(*this);
26 }
27
28 int MathMacroTemplate::numargs() const
29 {
30         return numargs_;
31 }
32
33 void MathMacroTemplate::numargs(int numargs)
34 {
35         numargs_ = numargs;
36 }
37
38
39 void MathMacroTemplate::Write(ostream & os, bool fragile) const
40 {
41         os << "\n\\newcommand{\\" << name_ << "}";
42
43         if (numargs_ > 0)
44                 os << "[" << numargs_ << "]";
45
46         os << "{";
47         cell(0).Write(os, fragile);
48         os << "}\n";
49 }
50
51
52 void MathMacroTemplate::Metrics(MathStyles st)
53 {
54         xcell(0).Metrics(st);
55         size_    = st;
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)
63 {
64         xo(x);
65         yo(y);
66         xcell(0).draw(pain, x + 2, y + 1);
67         pain.rectangle(x, y - ascent(), width(), height(), LColor::blue);
68 }
69