]> git.lyx.org Git - lyx.git/blob - src/mathed/MathMacroArgument.cpp
eb3d86a86d2412d293302f055d95a6e7482ae0b0
[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::auto_ptr;
24 using std::size_t;
25 using std::vector;
26
27
28 MathMacroArgument::MathMacroArgument(size_t n)
29         : number_(n)
30 {
31         if (n < 1 || n > 9) {
32                 lyxerr << "MathMacroArgument::MathMacroArgument: wrong Argument id: "
33                         << n << endl;
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 auto_ptr<Inset> MathMacroArgument::doClone() const
46 {
47         return auto_ptr<Inset>(new MathMacroArgument(*this));
48 }
49
50
51 void MathMacroArgument::write(WriteStream & os) const
52 {
53         os << str_;
54 }
55
56
57 bool MathMacroArgument::metrics(MetricsInfo & mi, Dimension & dim) const
58 {
59         mathed_string_dim(mi.base.font, str_, dim);
60         if (dim_ == dim)
61                 return false;
62         dim_ = dim;
63         return true;
64 }
65
66
67 void MathMacroArgument::draw(PainterInfo & pi, int x, int y) const
68 {
69         drawStrRed(pi, x, y, str_);
70         setPosCache(pi, x, y);
71 }
72
73
74 void MathMacroArgument::normalize(NormalStream & os) const
75 {
76         os << "[macroarg " << str_ << "] ";
77 }
78
79
80 } // namespace lyx