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