]> git.lyx.org Git - lyx.git/blob - src/mathed/math_colorinset.C
fix #1411
[lyx.git] / src / mathed / math_colorinset.C
1 /**
2  * \file math_colorinset.C
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 "math_colorinset.h"
14 #include "math_data.h"
15 #include "math_mathmlstream.h"
16 #include "math_support.h"
17
18 #include "LaTeXFeatures.h"
19
20 #include "support/std_ostream.h"
21
22 using std::auto_ptr;
23
24
25 MathColorInset::MathColorInset()
26         : MathNestInset(2)
27 {}
28
29
30 auto_ptr<InsetBase> MathColorInset::clone() const
31 {
32         return auto_ptr<InsetBase>(new MathColorInset(*this));
33 }
34
35
36 void MathColorInset::metrics(MetricsInfo & mi, Dimension & dim) const
37 {
38         FontSetChanger dummy(mi.base, "textnormal");
39         w_ = mathed_char_width(mi.base.font, '[');
40         MathNestInset::metrics(mi);
41         dim_   = cell(0).dim();
42         dim_.asc += 4;
43         dim_.des += 4;
44         dim_  += cell(1).dim();
45         dim_.wid += 2 * w_ + 4;
46         metricsMarkers();
47         dim = dim_;
48 }
49
50
51 void MathColorInset::draw(PainterInfo & pi, int x, int y) const
52 {
53         FontSetChanger dummy(pi.base, "textnormal");
54         drawMarkers(pi, x, y);
55
56         drawStrBlack(pi, x, y, "[");
57         x += w_;
58         cell(0).draw(pi, x, y);
59         x += cell(0).width();
60         drawStrBlack(pi, x, y, "]");
61         x += w_ + 2;
62
63         ColorChanger dummy1(pi.base.font, asString(cell(0)));
64         cell(1).draw(pi, x, y);
65 }
66
67
68 void MathColorInset::validate(LaTeXFeatures & features) const
69 {
70         MathNestInset::validate(features);
71         features.require("color");
72 }
73
74
75 void MathColorInset::write(WriteStream & os) const
76 {
77         os << "\\color" << '{' << cell(0) << '}' << '{' << cell(1) << '}';
78 }
79
80
81 void MathColorInset::normalize(NormalStream & os) const
82 {
83         os << "[color " << cell(0) << ' ' << cell(1) << ']';
84 }
85
86
87 void MathColorInset::infoize(std::ostream & os) const
88 {
89         os << "Color: " << cell(0);
90 }