]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathColor.cpp
rename MathArray into MathData
[lyx.git] / src / mathed / InsetMathColor.cpp
1 /**
2  * \file InsetMathColor.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "InsetMathColor.h"
14 #include "MathData.h"
15 #include "MathStream.h"
16 #include "MathSupport.h"
17 #include "LaTeXFeatures.h"
18
19 #include "support/std_ostream.h"
20
21
22 namespace lyx {
23
24 using std::auto_ptr;
25 using std::string;
26
27 InsetMathColor::InsetMathColor(bool oldstyle, LColor_color const & color)
28         : InsetMathNest(1), oldstyle_(oldstyle),
29           color_(from_utf8(lcolor.getLaTeXName(color)))
30 {}
31
32
33 InsetMathColor::InsetMathColor(bool oldstyle, docstring const & color)
34         : InsetMathNest(1), oldstyle_(oldstyle), color_(color)
35 {}
36
37
38 auto_ptr<InsetBase> InsetMathColor::doClone() const
39 {
40         return auto_ptr<InsetBase>(new InsetMathColor(*this));
41 }
42
43
44 bool InsetMathColor::metrics(MetricsInfo & mi, Dimension & dim) const
45 {
46         cell(0).metrics(mi, dim);
47         metricsMarkers(dim);
48         if (dim_ == dim)
49                 return false;
50         dim_ = dim;
51         return true;
52 }
53
54
55 void InsetMathColor::draw(PainterInfo & pi, int x, int y) const
56 {
57         LColor_color origcol = pi.base.font.color();
58         pi.base.font.setColor(lcolor.getFromLaTeXName(to_utf8(color_)));
59         cell(0).draw(pi, x + 1, y);
60         pi.base.font.setColor(origcol);
61         drawMarkers(pi, x, y);
62         setPosCache(pi, x, y);
63 }
64
65
66 /// color "none" (reset to default) needs special treatment
67 static bool normalcolor(docstring const & color)
68 {
69         return color == "none";
70 }
71
72
73 void InsetMathColor::validate(LaTeXFeatures & features) const
74 {
75         InsetMathNest::validate(features);
76         if (!normalcolor(color_))
77                 features.require("color");
78 }
79
80
81 void InsetMathColor::write(WriteStream & os) const
82 {
83         if (normalcolor(color_))
84                 // reset to default color inside another color inset
85                 os << "{\\normalcolor " << cell(0) << '}';
86         else if (oldstyle_)
87                 os << "{\\color{" << color_ << '}' << cell(0) << '}';
88         else
89                 os << "\\textcolor{" << color_ << "}{" << cell(0) << '}';
90 }
91
92
93 void InsetMathColor::normalize(NormalStream & os) const
94 {
95         os << "[color " << color_ << ' ' << cell(0) << ']';
96 }
97
98
99 void InsetMathColor::infoize(odocstream & os) const
100 {
101         os << "Color: " << color_;
102 }
103
104
105 } // namespace lyx