2 * \file InsetMathAMSArray.C
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 "LaTeXFeatures.h"
14 #include "InsetMathAMSArray.h"
16 #include "MathMLStream.h"
17 #include "MathStream.h"
18 #include "MathSupport.h"
20 #include "funcrequest.h"
21 #include "FuncStatus.h"
24 #include "support/lstrings.h"
25 #include "support/std_ostream.h"
33 using support::bformat;
36 InsetMathAMSArray::InsetMathAMSArray(string const & name, int m, int n)
37 : InsetMathGrid(m, n), name_(name)
41 InsetMathAMSArray::InsetMathAMSArray(string const & name)
42 : InsetMathGrid(1, 1), name_(name)
46 auto_ptr<InsetBase> InsetMathAMSArray::doClone() const
48 return auto_ptr<InsetBase>(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);
93 void InsetMathAMSArray::draw(PainterInfo & pi, int x, int y) const
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(), name_left());
98 mathed_draw_deco(pi, x + dim_.width() - 8, yy, 5, dim_.height(), name_right());
99 ArrayChanger dummy(pi.base);
100 InsetMathGrid::drawWithMargin(pi, x, y, 6, 8);
104 bool InsetMathAMSArray::getStatus(LCursor & 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'")),
117 return InsetMathGrid::getStatus(cur, cmd, flag);
120 return InsetMathGrid::getStatus(cur, cmd, flag);
125 void InsetMathAMSArray::write(WriteStream & os) const
127 os << "\\begin{" << name_ << '}';
128 InsetMathGrid::write(os);
129 os << "\\end{" << name_ << '}';
133 void InsetMathAMSArray::infoize(std::ostream & os) const
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
151 features.require("amsmath");
152 InsetMathGrid::validate(features);