]> git.lyx.org Git - lyx.git/blob - src/mathed/math_amsarrayinset.C
Fix math cursor positioning bug
[lyx.git] / src / mathed / math_amsarrayinset.C
1 /**
2  * \file math_amsarrayinset.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 "LaTeXFeatures.h"
14 #include "math_amsarrayinset.h"
15 #include "math_data.h"
16 #include "math_mathmlstream.h"
17 #include "math_streamstr.h"
18 #include "math_support.h"
19
20 using std::string;
21 using std::auto_ptr;
22
23
24 MathAMSArrayInset::MathAMSArrayInset(string const & name, int m, int n)
25         : MathGridInset(m, n), name_(name)
26 {}
27
28
29 MathAMSArrayInset::MathAMSArrayInset(string const & name)
30         : MathGridInset(1, 1), name_(name)
31 {}
32
33
34 auto_ptr<InsetBase> MathAMSArrayInset::doClone() const
35 {
36         return auto_ptr<InsetBase>(new MathAMSArrayInset(*this));
37 }
38
39
40 char const * MathAMSArrayInset::name_left() const
41 {
42         if (name_ == "bmatrix")
43                 return "[";
44         if (name_ == "Bmatrix")
45                 return "{";
46         if (name_ == "vmatrix")
47                 return "|";
48         if (name_ == "Vmatrix")
49                 return "Vert";
50         if (name_ == "pmatrix")
51                 return "(";
52         return ".";
53 }
54
55
56 char const * MathAMSArrayInset::name_right() const
57 {
58         if (name_ == "bmatrix")
59                 return "]";
60         if (name_ == "Bmatrix")
61                 return "}";
62         if (name_ == "vmatrix")
63                 return "|";
64         if (name_ == "Vmatrix")
65                 return "Vert";
66         if (name_ == "pmatrix")
67                 return ")";
68         return ".";
69 }
70
71
72 void MathAMSArrayInset::metrics(MetricsInfo & mi, Dimension & dim) const
73 {
74         MetricsInfo m = mi;
75         if (m.base.style == LM_ST_DISPLAY)
76                 m.base.style = LM_ST_TEXT;
77         MathGridInset::metrics(m, dim);
78         dim.wid += 12;
79         dim_ = dim;
80 }
81
82
83 void MathAMSArrayInset::draw(PainterInfo & pi, int x, int y) const
84 {
85         MathGridInset::draw(pi, x + 6, y);
86         int const yy = y - dim_.ascent();
87         mathed_draw_deco(pi, x + 1, yy, 5, dim_.height(), name_left());
88         mathed_draw_deco(pi, x + dim_.width() - 6, yy, 5, dim_.height(), name_right());
89         setPosCache(pi, x, y);
90 }
91
92
93 void MathAMSArrayInset::write(WriteStream & os) const
94 {
95         os << "\\begin{" << name_ << '}';
96         MathGridInset::write(os);
97         os << "\\end{" << name_ << '}';
98 }
99
100
101 void MathAMSArrayInset::normalize(NormalStream & os) const
102 {
103         os << '[' << name_ << ' ';
104         MathGridInset::normalize(os);
105         os << ']';
106 }
107
108
109 void MathAMSArrayInset::validate(LaTeXFeatures & features) const
110 {
111         features.require("amsmath");
112         MathGridInset::validate(features);
113 }