]> git.lyx.org Git - lyx.git/blob - src/mathed/math_macroarg.C
fix macro, small cleanup
[lyx.git] / src / mathed / math_macroarg.C
1 #include <config.h>
2
3 #ifdef __GNUG__
4 #pragma implementation
5 #endif
6
7 #include "math_macroarg.h"
8 #include "mathed/support.h"
9 #include "debug.h"
10
11
12 MathMacroArgument::MathMacroArgument()
13         : expnd_mode_(false), number_(1)
14 {
15         SetType(LM_OT_MACRO_ARG);
16 }
17
18
19 MathMacroArgument::MathMacroArgument(int n)
20         : expnd_mode_(false), number_(n)
21 {
22         SetType(LM_OT_MACRO_ARG);
23 }
24
25
26 MathedInset * MathMacroArgument::Clone()
27 {
28         return this;
29 }
30
31
32 void MathMacroArgument::setNumber(int n)
33 {
34         number_ = n;
35 }
36
37
38 void MathMacroArgument::setExpand(bool e)
39 {
40         expnd_mode_ = e;
41 }
42
43
44 bool MathMacroArgument::getExpand() const
45 {
46         return expnd_mode_;
47 }
48
49
50 void MathMacroArgument::draw(Painter & pain, int x, int baseline)
51 {
52         if (expnd_mode_) {
53                 MathParInset::draw(pain, x, baseline);
54         } else {
55                 std::ostringstream ost;
56                 ost << '#' << number_;
57                 drawStr(pain, LM_TC_TEX, size(), x, baseline, ost.str().c_str());
58         }
59 }
60
61 void MathMacroArgument::Metrics()
62 {
63         if (expnd_mode_) {
64                 MathParInset::Metrics();
65         } else {
66                 std::ostringstream ost;
67                 ost << '#' << number_;
68                 width = mathed_string_width(LM_TC_TEX, size(), ost.str().c_str());
69                 mathed_string_height(LM_TC_TEX, size(), ost.str().c_str(),
70                                      ascent, descent);
71         }
72 }
73
74
75 void MathMacroArgument::Write(ostream & os, bool fragile)
76 {
77         if (expnd_mode_) {
78                 MathParInset::Write(os, fragile);
79         } else {
80                 os << '#' << number_ << ' ';
81         }
82 }