]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathXArrow.cpp
a2aef402d28beb7e7fa7db60c370041985059ed9
[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
22 namespace lyx {
23
24
25 InsetMathXArrow::InsetMathXArrow(docstring const & name)
26         : InsetMathFracBase(), name_(name)
27 {}
28
29
30 Inset * InsetMathXArrow::clone() const
31 {
32         return new InsetMathXArrow(*this);
33 }
34
35
36 void InsetMathXArrow::metrics(MetricsInfo & mi, Dimension & dim) const
37 {
38         ScriptChanger dummy(mi.base);
39         Dimension dim0;
40         cell(0).metrics(mi, dim0);
41         Dimension dim1;
42         cell(1).metrics(mi, dim1);
43         dim.wid = std::max(dim0.width(), dim1.width()) + 10;
44         dim.asc = dim0.height() + 10;
45         dim.des = dim1.height();
46         metricsMarkers(dim);
47         // Cache the inset dimension. 
48         setDimCache(mi, dim);
49 }
50
51
52 void InsetMathXArrow::draw(PainterInfo & pi, int x, int y) const
53 {
54         ScriptChanger dummy(pi.base);
55         cell(0).draw(pi, x + 5, y - 10);
56         Dimension const & dim1 = cell(1).dimension(*pi.base.bv);
57         cell(1).draw(pi, x + 5, y + dim1.height());
58         Dimension const dim = dimension(*pi.base.bv);
59         mathed_draw_deco(pi, x + 1, y - 7, dim.wid - 2, 5, name_);
60         drawMarkers(pi, x, y);
61 }
62
63
64 void InsetMathXArrow::write(WriteStream & os) const
65 {
66         os << '\\' << name_;
67         if (cell(1).size())
68                 os << '[' << cell(1) << ']';
69         os << '{' << cell(0) << '}';
70 }
71
72
73 void InsetMathXArrow::normalize(NormalStream & os) const
74 {
75         os << "[xarrow " << name_ << ' ' <<  cell(0) << ' ' << cell(1) << ']';
76 }
77
78
79 void InsetMathXArrow::validate(LaTeXFeatures & features) const
80 {
81         features.require("amsmath");
82         InsetMathNest::validate(features);
83 }
84
85
86 } // namespace lyx