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 "MathStream.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"
31 using support::bformat;
34 InsetMathAMSArray::InsetMathAMSArray(docstring const & name, int m, int n)
35 : InsetMathGrid(m, n), name_(name)
39 InsetMathAMSArray::InsetMathAMSArray(docstring const & name)
40 : InsetMathGrid(1, 1), name_(name)
44 auto_ptr<InsetBase> InsetMathAMSArray::doClone() const
46 return auto_ptr<InsetBase>(new InsetMathAMSArray(*this));
50 char const * InsetMathAMSArray::name_left() const
52 if (name_ == "bmatrix")
54 if (name_ == "Bmatrix")
56 if (name_ == "vmatrix")
58 if (name_ == "Vmatrix")
60 if (name_ == "pmatrix")
66 char const * InsetMathAMSArray::name_right() const
68 if (name_ == "bmatrix")
70 if (name_ == "Bmatrix")
72 if (name_ == "vmatrix")
74 if (name_ == "Vmatrix")
76 if (name_ == "pmatrix")
82 void InsetMathAMSArray::metrics(MetricsInfo & mi, Dimension & dim) const
84 ArrayChanger dummy(mi.base);
85 InsetMathGrid::metrics(mi, dim);
91 void InsetMathAMSArray::draw(PainterInfo & pi, int x, int y) const
93 int const yy = y - dim_.ascent();
94 // Drawing the deco after an ArrayChanger does not work
95 mathed_draw_deco(pi, x + 1, yy, 5, dim_.height(), from_ascii(name_left()));
96 mathed_draw_deco(pi, x + dim_.width() - 8, yy, 5, dim_.height(), from_ascii(name_right()));
97 ArrayChanger dummy(pi.base);
98 InsetMathGrid::drawWithMargin(pi, x, y, 6, 8);
102 bool InsetMathAMSArray::getStatus(LCursor & cur, FuncRequest const & cmd,
103 FuncStatus & flag) const
105 switch (cmd.action) {
106 case LFUN_TABULAR_FEATURE: {
107 docstring const & s = cmd.argument();
108 if (s == "add-vline-left" || s == "add-vline-right") {
109 flag.message(bformat(
110 from_utf8(N_("Can't add vertical grid lines in '%1$s'")), name_));
114 return InsetMathGrid::getStatus(cur, cmd, flag);
117 return InsetMathGrid::getStatus(cur, cmd, flag);
122 void InsetMathAMSArray::write(WriteStream & os) const
124 os << "\\begin{" << name_ << '}';
125 InsetMathGrid::write(os);
126 os << "\\end{" << name_ << '}';
130 void InsetMathAMSArray::infoize(odocstream & os) const
132 docstring name = name_;
133 name[0] = support::uppercase(name[0]);
138 void InsetMathAMSArray::normalize(NormalStream & os) const
140 os << '[' << name_ << ' ';
141 InsetMathGrid::normalize(os);
146 void InsetMathAMSArray::validate(LaTeXFeatures & features) const
148 features.require("amsmath");
149 InsetMathGrid::validate(features);