]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathXArrow.cpp
06ef4a52403c691a8cc7766ed03382ef273f64f3
[lyx.git] / src / mathed / InsetMathXArrow.cpp
1 /**
2  * \file InsetMathXArrow.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 "InsetMathXArrow.h"
14 #include "MathData.h"
15 #include "MathStream.h"
16 #include "MathStream.h"
17 #include "MathSupport.h"
18
19 #include "LaTeXFeatures.h"
20
21 using namespace std;
22
23 namespace lyx {
24
25
26 InsetMathXArrow::InsetMathXArrow(Buffer * buf, docstring const & name)
27         : InsetMathFracBase(buf), name_(name)
28 {}
29
30
31 Inset * InsetMathXArrow::clone() const
32 {
33         return new InsetMathXArrow(*this);
34 }
35
36
37 void InsetMathXArrow::metrics(MetricsInfo & mi, Dimension & dim) const
38 {
39         ScriptChanger dummy(mi.base);
40         Dimension dim0;
41         cell(0).metrics(mi, dim0);
42         Dimension dim1;
43         cell(1).metrics(mi, dim1);
44         dim.wid = max(dim0.width(), dim1.width()) + 10;
45         dim.asc = dim0.height() + 10;
46         dim.des = dim1.height();
47         metricsMarkers(dim);
48 }
49
50
51 void InsetMathXArrow::draw(PainterInfo & pi, int x, int y) const
52 {
53         ScriptChanger dummy(pi.base);
54         Dimension const dim00 = dimension(*pi.base.bv);
55         Dimension const & dim01 = cell(0).dimension(*pi.base.bv);
56         // center the cells with the decoration
57         cell(0).draw(pi, x + dim00.width()/2 - dim01.width()/2, y - 10);
58         Dimension const & dim1 = cell(1).dimension(*pi.base.bv);
59         cell(1).draw(pi, x + dim00.width()/2 - dim1.width()/2, y + dim1.height());
60         Dimension const dim = dimension(*pi.base.bv);
61         mathed_draw_deco(pi, x + 1, y - 7, dim.wid - 2, 5, name_);
62         drawMarkers(pi, x, y);
63 }
64
65
66 void InsetMathXArrow::write(WriteStream & os) const
67 {
68         MathEnsurer ensurer(os);
69         os << '\\' << name_;
70         if (!cell(1).empty())
71                 os << '[' << cell(1) << ']';
72         os << '{' << cell(0) << '}';
73 }
74
75
76 void InsetMathXArrow::normalize(NormalStream & os) const
77 {
78         os << "[xarrow " << name_ << ' ' <<  cell(0) << ' ' << cell(1) << ']';
79 }
80
81
82 void InsetMathXArrow::mathmlize(MathStream & ms) const
83 {
84         char const * const arrow = name_ == "xleftarrow" 
85                         ? "&larr;" : "&rarr;";
86         ms << "<munderover accent='false' accentunder='false'>"
87            << arrow << cell(1) << cell(0)
88            << "</munderover>";
89 }
90
91
92 void InsetMathXArrow::htmlize(HtmlStream & os) const
93 {
94         char const * const arrow = name_ == "xleftarrow" 
95                         ? "&larr;" : "&rarr;";
96         os << MTag("span", "class='xarrow'")
97                  << MTag("span", "class='xatop'") << cell(0) << ETag("span")
98                  << MTag("span", "class='xabottom'") << arrow << ETag("span")
99                  << ETag("span");
100 }
101
102
103 void InsetMathXArrow::validate(LaTeXFeatures & features) const
104 {
105         features.require("amsmath");
106         if (features.runparams().math_flavor == OutputParams::MathAsHTML)
107                 // CSS adapted from eLyXer
108                 features.addCSSSnippet(
109                         "span.xarrow{display: inline-block; vertical-align: middle; text-align:center;}\n"
110                         "span.xatop{display: block;}\n"
111                         "span.xabottom{display: block;}");
112         InsetMathNest::validate(features);
113 }
114
115
116 } // namespace lyx