]> git.lyx.org Git - lyx.git/blob - src/mathed/MathMacroArgument.cpp
ebf2ee615e969a08b80ccc56f23ee144fb388e22
[lyx.git] / src / mathed / MathMacroArgument.cpp
1 /**
2  * \file MathMacroArgument.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alejandro Aguilar Sierra
7  * \author André Pönitz
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "MathMacroArgument.h"
15 #include "MathStream.h"
16 #include "MathSupport.h"
17
18 #include "debug.h"
19
20
21 namespace lyx {
22
23 using std::endl;
24 using std::size_t;
25
26
27 MathMacroArgument::MathMacroArgument(size_t n)
28         : number_(n)
29 {
30         if (n < 1 || n > 9) {
31                 lyxerr << "MathMacroArgument::MathMacroArgument: wrong Argument id: "
32                         << n << endl;
33         }
34
35         // The profiler tells us not to use
36         // str_ = '#' + convert<docstring>(n);
37         // so we do the conversion of n to ASCII manually.
38         // This works because 1 <= n <= 9.
39         str_.resize(2);
40         str_[0] = '#';
41         str_[1] = '0' + n;
42 }
43
44
45 Inset * MathMacroArgument::clone() const
46 {
47         return new MathMacroArgument(*this);
48 }
49
50
51 void MathMacroArgument::setNumber(std::size_t n)
52 {
53         if (n < 1 || n > 9) {
54                 lyxerr << "MathMacroArgument::setNumber: wrong Argument id: "
55                 << n << endl;
56         }
57
58         number_ = n;
59         str_[1] = '0' + n;
60 }
61
62
63 void MathMacroArgument::write(WriteStream & os) const
64 {
65         os << str_;
66 }
67
68
69 void MathMacroArgument::metrics(MetricsInfo & mi, Dimension & dim) const
70 {
71         mathed_string_dim(mi.base.font, str_, dim);
72 }
73
74
75 void MathMacroArgument::draw(PainterInfo & pi, int x, int y) const
76 {
77         drawStrRed(pi, x, y, str_);
78         setPosCache(pi, x, y);
79 }
80
81
82 void MathMacroArgument::normalize(NormalStream & os) const
83 {
84         os << "[macroarg " << str_ << "] ";
85 }
86
87
88 } // namespace lyx