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(docstring const & name, int m, int n)
36 : InsetMathGrid(m, n), name_(name)
40 InsetMathAMSArray::InsetMathAMSArray(docstring const & name)
41 : InsetMathGrid(1, 1), name_(name)
45 Inset * InsetMathAMSArray::clone() const
47 return new InsetMathAMSArray(*this);
51 char const * InsetMathAMSArray::name_left() const
53 if (name_ == "bmatrix")
55 if (name_ == "Bmatrix")
57 if (name_ == "vmatrix")
59 if (name_ == "Vmatrix")
61 if (name_ == "pmatrix")
67 char const * InsetMathAMSArray::name_right() const
69 if (name_ == "bmatrix")
71 if (name_ == "Bmatrix")
73 if (name_ == "vmatrix")
75 if (name_ == "Vmatrix")
77 if (name_ == "pmatrix")
83 void InsetMathAMSArray::metrics(MetricsInfo & mi, Dimension & dim) const
85 ArrayChanger dummy(mi.base);
86 InsetMathGrid::metrics(mi, dim);
91 void InsetMathAMSArray::draw(PainterInfo & pi, int x, int y) const
93 Dimension const dim = dimension(*pi.base.bv);
94 int const yy = y - dim.ascent();
95 // Drawing the deco after an ArrayChanger does not work
96 mathed_draw_deco(pi, x + 1, yy, 5, dim.height(), from_ascii(name_left()));
97 mathed_draw_deco(pi, x + dim.width() - 8, yy, 5, dim.height(), from_ascii(name_right()));
98 ArrayChanger dummy(pi.base);
99 InsetMathGrid::drawWithMargin(pi, x, y, 6, 8);
103 bool InsetMathAMSArray::getStatus(Cursor & cur, FuncRequest const & cmd,
104 FuncStatus & flag) const
106 switch (cmd.action) {
107 case LFUN_TABULAR_FEATURE: {
108 docstring const & s = cmd.argument();
109 if (s == "add-vline-left" || s == "add-vline-right") {
110 flag.message(bformat(
111 from_utf8(N_("Can't add vertical grid lines in '%1$s'")), name_));
112 flag.setEnabled(false);
115 return InsetMathGrid::getStatus(cur, cmd, flag);
118 return InsetMathGrid::getStatus(cur, cmd, flag);
123 void InsetMathAMSArray::write(WriteStream & os) const
125 MathEnsurer ensurer(os);
126 os << "\\begin{" << name_ << '}';
127 InsetMathGrid::write(os);
128 os << "\\end{" << name_ << '}';
132 void InsetMathAMSArray::infoize(odocstream & os) const
134 docstring name = name_;
135 name[0] = support::uppercase(name[0]);
140 void InsetMathAMSArray::normalize(NormalStream & os) const
142 os << '[' << name_ << ' ';
143 InsetMathGrid::normalize(os);
148 void InsetMathAMSArray::validate(LaTeXFeatures & features) const
151 // amscd is independent of amsmath although it is part of
152 // the amsmath bundle
153 features.require("amscd");
155 features.require("amsmath");
156 InsetMathGrid::validate(features);