2 * \file InsetMathAMSArray.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "InsetMathAMSArray.h"
15 #include "LaTeXFeatures.h"
17 #include "MathStream.h"
18 #include "MathSupport.h"
19 #include "MetricsInfo.h"
21 #include "FuncRequest.h"
22 #include "FuncStatus.h"
23 #include "support/gettext.h"
25 #include "support/lstrings.h"
32 using support::bformat
;
35 InsetMathAMSArray::InsetMathAMSArray(Buffer
* buf
, docstring
const & name
,
37 : InsetMathGrid(buf
, m
, n
), name_(name
)
41 InsetMathAMSArray::InsetMathAMSArray(Buffer
* buf
, docstring
const & name
)
42 : InsetMathGrid(buf
, 1, 1), name_(name
)
46 Inset
* InsetMathAMSArray::clone() const
48 return new InsetMathAMSArray(*this);
52 char const * InsetMathAMSArray::name_left() const
54 if (name_
== "bmatrix")
56 if (name_
== "Bmatrix")
58 if (name_
== "vmatrix")
60 if (name_
== "Vmatrix")
62 if (name_
== "pmatrix")
68 char const * InsetMathAMSArray::name_right() const
70 if (name_
== "bmatrix")
72 if (name_
== "Bmatrix")
74 if (name_
== "vmatrix")
76 if (name_
== "Vmatrix")
78 if (name_
== "pmatrix")
84 void InsetMathAMSArray::metrics(MetricsInfo
& mi
, Dimension
& dim
) const
86 ArrayChanger
dummy(mi
.base
);
87 InsetMathGrid::metrics(mi
, dim
);
92 void InsetMathAMSArray::draw(PainterInfo
& pi
, int x
, int y
) const
94 Dimension
const dim
= dimension(*pi
.base
.bv
);
95 int const yy
= y
- dim
.ascent();
96 // Drawing the deco after an ArrayChanger does not work
97 mathed_draw_deco(pi
, x
+ 1, yy
, 5, dim
.height(), from_ascii(name_left()));
98 mathed_draw_deco(pi
, x
+ dim
.width() - 8, yy
, 5, dim
.height(), from_ascii(name_right()));
99 ArrayChanger
dummy(pi
.base
);
100 InsetMathGrid::drawWithMargin(pi
, x
, y
, 6, 8);
104 bool InsetMathAMSArray::getStatus(Cursor
& cur
, FuncRequest
const & cmd
,
105 FuncStatus
& flag
) const
107 switch (cmd
.action
) {
108 case LFUN_TABULAR_FEATURE
: {
109 docstring
const & s
= cmd
.argument();
110 if (s
== "add-vline-left" || s
== "add-vline-right") {
111 flag
.message(bformat(
112 from_utf8(N_("Can't add vertical grid lines in '%1$s'")), name_
));
113 flag
.setEnabled(false);
116 return InsetMathGrid::getStatus(cur
, cmd
, flag
);
119 return InsetMathGrid::getStatus(cur
, cmd
, flag
);
124 void InsetMathAMSArray::write(WriteStream
& os
) const
126 MathEnsurer
ensurer(os
);
127 os
<< "\\begin{" << name_
<< '}';
128 InsetMathGrid::write(os
);
129 os
<< "\\end{" << name_
<< '}';
133 void InsetMathAMSArray::infoize(odocstream
& os
) const
135 docstring name
= name_
;
136 name
[0] = support::uppercase(name
[0]);
141 void InsetMathAMSArray::normalize(NormalStream
& os
) const
143 os
<< '[' << name_
<< ' ';
144 InsetMathGrid::normalize(os
);
149 void InsetMathAMSArray::validate(LaTeXFeatures
& features
) const
152 // amscd is independent of amsmath although it is part of
153 // the amsmath bundle
154 features
.require("amscd");
156 features
.require("amsmath");
157 InsetMathGrid::validate(features
);