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 "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"
30 using support::bformat;
33 InsetMathAMSArray::InsetMathAMSArray(docstring const & name, int m, int n)
34 : InsetMathGrid(m, n), name_(name)
38 InsetMathAMSArray::InsetMathAMSArray(docstring const & name)
39 : InsetMathGrid(1, 1), name_(name)
43 Inset * InsetMathAMSArray::clone() const
45 return new InsetMathAMSArray(*this);
49 char const * InsetMathAMSArray::name_left() const
51 if (name_ == "bmatrix")
53 if (name_ == "Bmatrix")
55 if (name_ == "vmatrix")
57 if (name_ == "Vmatrix")
59 if (name_ == "pmatrix")
65 char const * InsetMathAMSArray::name_right() const
67 if (name_ == "bmatrix")
69 if (name_ == "Bmatrix")
71 if (name_ == "vmatrix")
73 if (name_ == "Vmatrix")
75 if (name_ == "pmatrix")
81 void InsetMathAMSArray::metrics(MetricsInfo & mi, Dimension & dim) const
83 ArrayChanger dummy(mi.base);
84 InsetMathGrid::metrics(mi, dim);
89 Dimension const InsetMathAMSArray::dimension(BufferView const & bv) const
91 Dimension dim = InsetMathGrid::dimension(bv);
97 void InsetMathAMSArray::draw(PainterInfo & pi, int x, int y) const
99 Dimension const dim = dimension(*pi.base.bv);
100 int const yy = y - dim.ascent();
101 // Drawing the deco after an ArrayChanger does not work
102 mathed_draw_deco(pi, x + 1, yy, 5, dim.height(), from_ascii(name_left()));
103 mathed_draw_deco(pi, x + dim.width() - 8, yy, 5, dim.height(), from_ascii(name_right()));
104 ArrayChanger dummy(pi.base);
105 InsetMathGrid::drawWithMargin(pi, x, y, 6, 8);
109 bool InsetMathAMSArray::getStatus(Cursor & cur, FuncRequest const & cmd,
110 FuncStatus & flag) const
112 switch (cmd.action) {
113 case LFUN_TABULAR_FEATURE: {
114 docstring const & s = cmd.argument();
115 if (s == "add-vline-left" || s == "add-vline-right") {
116 flag.message(bformat(
117 from_utf8(N_("Can't add vertical grid lines in '%1$s'")), name_));
121 return InsetMathGrid::getStatus(cur, cmd, flag);
124 return InsetMathGrid::getStatus(cur, cmd, flag);
129 void InsetMathAMSArray::write(WriteStream & os) const
131 os << "\\begin{" << name_ << '}';
132 InsetMathGrid::write(os);
133 os << "\\end{" << name_ << '}';
137 void InsetMathAMSArray::infoize(odocstream & os) const
139 docstring name = name_;
140 name[0] = support::uppercase(name[0]);
145 void InsetMathAMSArray::normalize(NormalStream & os) const
147 os << '[' << name_ << ' ';
148 InsetMathGrid::normalize(os);
153 void InsetMathAMSArray::validate(LaTeXFeatures & features) const
155 features.require("amsmath");
156 InsetMathGrid::validate(features);