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