]> git.lyx.org Git - lyx.git/blob - src/mathed/MathMacroArgument.cpp
* Inset:
[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 #include "debug.h"
18
19
20 namespace lyx {
21
22 using std::endl;
23 using std::size_t;
24
25
26 MathMacroArgument::MathMacroArgument(size_t n)
27         : number_(n)
28 {
29         if (n < 1 || n > 9) {
30                 lyxerr << "MathMacroArgument::MathMacroArgument: wrong Argument id: "
31                         << n << endl;
32         }
33         // The profiler tells us not to use
34         // str_ = '#' + convert<docstring>(n);
35         // so we do the conversion of n to ASCII manually.
36         // This works because 1 <= n <= 9.
37         str_.resize(2);
38         str_[0] = '#';
39         str_[1] = '0' + n;
40 }
41
42
43 Inset * MathMacroArgument::clone() const
44 {
45         return new MathMacroArgument(*this);
46 }
47
48
49 void MathMacroArgument::write(WriteStream & os) const
50 {
51         os << str_;
52 }
53
54
55 void MathMacroArgument::metrics(MetricsInfo & mi, Dimension & dim) const
56 {
57         mathed_string_dim(mi.base.font, str_, dim);
58 }
59
60
61 void MathMacroArgument::draw(PainterInfo & pi, int x, int y) const
62 {
63         drawStrRed(pi, x, y, str_);
64         setPosCache(pi, x, y);
65 }
66
67
68 void MathMacroArgument::normalize(NormalStream & os) const
69 {
70         os << "[macroarg " << str_ << "] ";
71 }
72
73
74 } // namespace lyx