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