]> git.lyx.org Git - lyx.git/blob - src/mathed/math_macrotemplate.C
fix pullArg when pressing <Delete> at the end of an cell
[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         MathInset(1, "undefined", LM_OT_MACRO), numargs_(0)
12 {}
13
14
15 MathMacroTemplate::MathMacroTemplate(string const & nm, int numargs) :
16         MathInset(1, nm, LM_OT_MACRO), numargs_(numargs)
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 void MathMacroTemplate::Write(std::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, int, int)
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 }