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"
24 #include "support/gettext.h"
25 #include "support/lstrings.h"
32 using namespace lyx::support;
37 InsetMathAMSArray::InsetMathAMSArray(Buffer * buf, docstring const & name,
39 : InsetMathGrid(buf, m, n), name_(name)
43 InsetMathAMSArray::InsetMathAMSArray(Buffer * buf, docstring const & name)
44 : InsetMathGrid(buf, 1, 1), name_(name)
48 Inset * InsetMathAMSArray::clone() const
50 return new InsetMathAMSArray(*this);
54 char const * InsetMathAMSArray::name_left() const
56 if (name_ == "bmatrix")
58 if (name_ == "Bmatrix")
60 if (name_ == "vmatrix")
62 if (name_ == "Vmatrix")
64 if (name_ == "pmatrix")
70 char const * InsetMathAMSArray::name_right() const
72 if (name_ == "bmatrix")
74 if (name_ == "Bmatrix")
76 if (name_ == "vmatrix")
78 if (name_ == "Vmatrix")
80 if (name_ == "pmatrix")
86 void InsetMathAMSArray::metrics(MetricsInfo & mi, Dimension & dim) const
89 mi.base.changeStyle(LM_ST_TEXT, mi.base.style == LM_ST_DISPLAY);
90 InsetMathGrid::metrics(mi, dim);
95 void InsetMathAMSArray::draw(PainterInfo & pi, int x, int y) const
97 Dimension const dim = dimension(*pi.base.bv);
98 int const yy = y - dim.ascent();
99 // Drawing the deco after changeStyle does not work
100 mathed_draw_deco(pi, x + 1, yy, 5, dim.height(), from_ascii(name_left()));
101 mathed_draw_deco(pi, x + dim.width() - 8, yy, 5, dim.height(), from_ascii(name_right()));
103 pi.base.changeStyle(LM_ST_TEXT, pi.base.style == LM_ST_DISPLAY);
104 InsetMathGrid::drawWithMargin(pi, x, y, 6, 8);
108 bool InsetMathAMSArray::getStatus(Cursor & cur, FuncRequest const & cmd,
109 FuncStatus & flag) const
111 switch (cmd.action()) {
112 case LFUN_TABULAR_FEATURE: {
113 string s = cmd.getArg(0);
114 if (s == "add-vline-left" || s == "add-vline-right") {
115 flag.message(bformat(
116 from_utf8(N_("Can't add vertical grid lines in '%1$s'")),
118 flag.setEnabled(false);
126 return InsetMathGrid::getStatus(cur, cmd, flag);
130 void InsetMathAMSArray::write(WriteStream & os) const
132 MathEnsurer ensurer(os);
133 os << "\\begin{" << name_ << '}';
134 bool open = os.startOuterRow();
135 InsetMathGrid::write(os);
136 os << "\\end{" << name_ << '}';
142 void InsetMathAMSArray::infoize(odocstream & os) const
144 docstring name = name_;
145 name[0] = support::uppercase(name[0]);
150 void InsetMathAMSArray::normalize(NormalStream & os) const
152 os << '[' << name_ << ' ';
153 InsetMathGrid::normalize(os);
158 void InsetMathAMSArray::validate(LaTeXFeatures & features) const
161 // amscd is independent of amsmath although it is part of
162 // the amsmath bundle
163 features.require("amscd");
165 features.require("amsmath");
166 InsetMathGrid::validate(features);