2 * \file math_amsarrayinset.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 "math_amsarrayinset.h"
15 #include "math_data.h"
16 #include "math_mathmlstream.h"
17 #include "math_streamstr.h"
18 #include "math_support.h"
20 #include "funcrequest.h"
21 #include "FuncStatus.h"
24 #include "support/lstrings.h"
25 #include "support/std_ostream.h"
30 using lyx::support::bformat;
33 MathAMSArrayInset::MathAMSArrayInset(string const & name, int m, int n)
34 : MathGridInset(m, n), name_(name)
38 MathAMSArrayInset::MathAMSArrayInset(string const & name)
39 : MathGridInset(1, 1), name_(name)
43 auto_ptr<InsetBase> MathAMSArrayInset::doClone() const
45 return auto_ptr<InsetBase>(new MathAMSArrayInset(*this));
49 char const * MathAMSArrayInset::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 * MathAMSArrayInset::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 MathAMSArrayInset::metrics(MetricsInfo & mi, Dimension & dim) const
83 ArrayChanger dummy(mi.base);
84 MathGridInset::metrics(mi, dim);
90 void MathAMSArrayInset::draw(PainterInfo & pi, int x, int y) const
92 int const yy = y - dim_.ascent();
93 // Drawing the deco after an ArrayChanger does not work
94 mathed_draw_deco(pi, x + 1, yy, 5, dim_.height(), name_left());
95 mathed_draw_deco(pi, x + dim_.width() - 8, yy, 5, dim_.height(), name_right());
96 ArrayChanger dummy(pi.base);
97 MathGridInset::drawWithMargin(pi, x, y, 6, 8);
101 bool MathAMSArrayInset::getStatus(LCursor & cur, FuncRequest const & cmd,
102 FuncStatus & flag) const
104 switch (cmd.action) {
105 case LFUN_TABULAR_FEATURE: {
106 string const s = cmd.argument;
107 if (s == "add-vline-left" || s == "add-vline-right") {
108 flag.message(bformat(
109 N_("Can't add vertical grid lines in '%1$s'"),
114 return MathGridInset::getStatus(cur, cmd, flag);
117 return MathGridInset::getStatus(cur, cmd, flag);
122 void MathAMSArrayInset::write(WriteStream & os) const
124 os << "\\begin{" << name_ << '}';
125 MathGridInset::write(os);
126 os << "\\end{" << name_ << '}';
130 void MathAMSArrayInset::infoize(std::ostream & os) const
133 name[0] = lyx::support::uppercase(name[0]);
138 void MathAMSArrayInset::normalize(NormalStream & os) const
140 os << '[' << name_ << ' ';
141 MathGridInset::normalize(os);
146 void MathAMSArrayInset::validate(LaTeXFeatures & features) const
148 features.require("amsmath");
149 MathGridInset::validate(features);