]> git.lyx.org Git - lyx.git/blob - src/mathed/math_macrotemplate.C
split super/subscript handling in new base class MathUpDownInset and
[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(1, "undefined", LM_OT_MACRO), numargs_(0), users_()
14 {}
15
16
17 MathMacroTemplate::MathMacroTemplate(string const & nm, int numargs) :
18         MathInset(1, nm, LM_OT_MACRO), numargs_(numargs), users_()
19 {}
20
21
22 MathInset * MathMacroTemplate::clone() const
23 {
24         lyxerr << "cloning MacroTemplate!\n";
25         return new MathMacroTemplate(*this);
26 }
27
28
29 int MathMacroTemplate::numargs() const
30 {
31         return numargs_;
32 }
33
34
35 void MathMacroTemplate::numargs(int numargs)
36 {
37         numargs_ = numargs;
38 }
39
40
41 void MathMacroTemplate::Write(std::ostream & os, bool fragile) const
42 {
43         os << "\n\\newcommand{\\" << name_ << "}";
44
45         if (numargs_ > 0)
46                 os << "[" << numargs_ << "]";
47
48         os << "{";
49         cell(0).Write(os, fragile);
50         os << "}\n";
51 }
52
53
54 void MathMacroTemplate::Metrics(MathStyles st, int, int)
55 {
56         xcell(0).Metrics(st);
57         size_    = st;
58         width_   = xcell(0).width() + 4;
59         ascent_  = xcell(0).ascent() + 2;
60         descent_ = xcell(0).descent() + 2;
61 }
62
63
64 void MathMacroTemplate::draw(Painter & pain, int x, int y)
65 {
66         xo(x);
67         yo(y);
68         xcell(0).draw(pain, x + 2, y + 1);
69         pain.rectangle(x, y - ascent(), width(), height(), LColor::blue);
70 }