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