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