]> git.lyx.org Git - lyx.git/blob - src/mathed/math_macrotemplate.C
mathed65.diff
[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 "math_macro.h"
9 #include "macro_support.h"
10 #include "support/LOstream.h"
11 #include "support/LAssert.h"
12 #include "debug.h"
13 #include "Painter.h"
14
15 using namespace std;
16
17 MathMacroTemplate::MathMacroTemplate() :
18         MathParInset(LM_ST_TEXT, "undefined", LM_OT_MACRO),
19         na_(0), users_()
20 {}
21
22
23 MathMacroTemplate::MathMacroTemplate(string const & nm, int na) :
24         MathParInset(LM_ST_TEXT, nm, LM_OT_MACRO),
25         na_(na), users_()
26 {}
27
28
29 int MathMacroTemplate::nargs() const
30 {
31         return na_;
32 }
33
34
35 void MathMacroTemplate::WriteDef(ostream & os, bool fragile) const
36 {
37         os << "\n\\newcommand{\\" << name << "}";
38
39         if (na_ > 0)
40                 os << "[" << na_ << "]";
41
42         os << "{";
43 #ifdef WITH_WARNINGS
44 #warning stupid cast
45 #endif
46         const_cast<MathMacroTemplate *>(this)->Write(os, fragile);
47         os << "}\n";
48 }
49
50
51 void MathMacroTemplate::Metrics()
52 {
53         MathParInset::Metrics();
54         width   += 4;
55         ascent  += 2;
56         descent += 2;
57 }
58
59
60 void MathMacroTemplate::draw(Painter & pain, int x, int y)
61 {
62         MathParInset::draw(pain, x + 2, y + 1);
63         int w = Width();
64         int a = Ascent();
65         int h = Height();
66         pain.rectangle(x, y - a, w, h, LColor::blue);
67 }
68