]> git.lyx.org Git - lyx.git/blob - src/mathed/math_colorinset.C
remove strain on Angus's eyes.
[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         cell(1).metrics(mi, dim);
39         if (editing()) {
40                 FontSetChanger dummy(mi.base, "textnormal");
41                 cell(0).metrics(mi);
42                 dim  += cell(0).dim();
43                 w_ = mathed_char_width(mi.base.font, '[');
44                 dim.asc += 4;
45                 dim.des += 4;
46                 dim.wid += 2 * w_ + 4;
47                 metricsMarkers();
48         }
49         dim_ = dim;
50 }
51
52
53 void MathColorInset::draw(PainterInfo & pi, int x, int y) const
54 {
55         if (editing()) {
56                 FontSetChanger dummy(pi.base, "textnormal");
57                 drawMarkers(pi, x, y);
58                 drawStrBlack(pi, x, y, "[");
59                 x += w_;
60                 cell(0).draw(pi, x, y);
61                 x += cell(0).width();
62                 drawStrBlack(pi, x, y, "]");
63                 x += w_ + 2;
64         }
65
66         ColorChanger dummy1(pi.base.font, asString(cell(0)));
67         cell(1).draw(pi, x, y);
68 }
69
70
71 void MathColorInset::validate(LaTeXFeatures & features) const
72 {
73         MathNestInset::validate(features);
74         features.require("color");
75 }
76
77
78 void MathColorInset::write(WriteStream & os) const
79 {
80         os << "\\color" << '{' << cell(0) << '}' << '{' << cell(1) << '}';
81 }
82
83
84 void MathColorInset::normalize(NormalStream & os) const
85 {
86         os << "[color " << cell(0) << ' ' << cell(1) << ']';
87 }
88
89
90 void MathColorInset::infoize(std::ostream & os) const
91 {
92         os << "Color: " << cell(0);
93 }