]> git.lyx.org Git - lyx.git/blob - src/mathed/math_amsarrayinset.C
code cosmetics to the iterator fix
[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 #include "funcrequest.h"
21 #include "FuncStatus.h"
22 #include "gettext.h"
23
24 #include "support/lstrings.h"
25 #include "support/std_ostream.h"
26
27
28 using std::string;
29 using std::auto_ptr;
30 using lyx::support::bformat;
31
32
33 MathAMSArrayInset::MathAMSArrayInset(string const & name, int m, int n)
34         : MathGridInset(m, n), name_(name)
35 {}
36
37
38 MathAMSArrayInset::MathAMSArrayInset(string const & name)
39         : MathGridInset(1, 1), name_(name)
40 {}
41
42
43 auto_ptr<InsetBase> MathAMSArrayInset::doClone() const
44 {
45         return auto_ptr<InsetBase>(new MathAMSArrayInset(*this));
46 }
47
48
49 char const * MathAMSArrayInset::name_left() const
50 {
51         if (name_ == "bmatrix")
52                 return "[";
53         if (name_ == "Bmatrix")
54                 return "{";
55         if (name_ == "vmatrix")
56                 return "|";
57         if (name_ == "Vmatrix")
58                 return "Vert";
59         if (name_ == "pmatrix")
60                 return "(";
61         return ".";
62 }
63
64
65 char const * MathAMSArrayInset::name_right() const
66 {
67         if (name_ == "bmatrix")
68                 return "]";
69         if (name_ == "Bmatrix")
70                 return "}";
71         if (name_ == "vmatrix")
72                 return "|";
73         if (name_ == "Vmatrix")
74                 return "Vert";
75         if (name_ == "pmatrix")
76                 return ")";
77         return ".";
78 }
79
80
81 void MathAMSArrayInset::metrics(MetricsInfo & mi, Dimension & dim) const
82 {
83         MetricsInfo m = mi;
84         if (m.base.style == LM_ST_DISPLAY)
85                 m.base.style = LM_ST_TEXT;
86         MathGridInset::metrics(m, dim);
87         dim.wid += 14;
88         dim_ = dim;
89 }
90
91
92 void MathAMSArrayInset::draw(PainterInfo & pi, int x, int y) const
93 {
94         MathGridInset::drawWithMargin(pi, x, y, 6, 8);
95         int const yy = y - dim_.ascent();
96         mathed_draw_deco(pi, x + 1, yy, 5, dim_.height(), name_left());
97         mathed_draw_deco(pi, x + dim_.width() - 8, yy, 5, dim_.height(), name_right());
98         setPosCache(pi, x, y);
99 }
100
101
102 bool MathAMSArrayInset::getStatus(LCursor & cur, FuncRequest const & cmd,
103                 FuncStatus & flag) const
104 {
105         switch (cmd.action) {
106         case LFUN_TABULAR_FEATURE: {
107                 string const s = cmd.argument;
108                 if (s == "add-vline-left" || s == "add-vline-right") {
109                         flag.message(bformat(
110                         N_("Can't add vertical grid lines in '%1$s'"),
111                                 name_));
112                         flag.enabled(false);
113                         return true;
114                 }
115                 return MathGridInset::getStatus(cur, cmd, flag);
116         }
117         default:
118                 return MathGridInset::getStatus(cur, cmd, flag);
119         }
120 }
121
122
123 void MathAMSArrayInset::write(WriteStream & os) const
124 {
125         os << "\\begin{" << name_ << '}';
126         MathGridInset::write(os);
127         os << "\\end{" << name_ << '}';
128 }
129
130
131 void MathAMSArrayInset::infoize(std::ostream & os) const
132 {
133         string name = name_;
134         name[0] = lyx::support::uppercase(name[0]);
135         os << name << ' ';
136 }
137
138
139 void MathAMSArrayInset::normalize(NormalStream & os) const
140 {
141         os << '[' << name_ << ' ';
142         MathGridInset::normalize(os);
143         os << ']';
144 }
145
146
147 void MathAMSArrayInset::validate(LaTeXFeatures & features) const
148 {
149         features.require("amsmath");
150         MathGridInset::validate(features);
151 }