A bit more re-organization.
[lyx.git] / src / mathed / InsetMathAMSArray.cpp
blobb9efc3d0e2853631d2c20c98e3cf0e97312cdb60
1 /**
2 * \file InsetMathAMSArray.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author André Pönitz
8 * Full author contact details are available in file CREDITS.
9 */
11 #include <config.h>
13 #include "InsetMathAMSArray.h"
15 #include "LaTeXFeatures.h"
16 #include "MathData.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"
27 #include <ostream>
30 namespace lyx {
32 using support::bformat;
35 InsetMathAMSArray::InsetMathAMSArray(Buffer * buf, docstring const & name,
36 int m, int n)
37 : InsetMathGrid(buf, m, n), name_(name)
41 InsetMathAMSArray::InsetMathAMSArray(Buffer * buf, docstring const & name)
42 : InsetMathGrid(buf, 1, 1), name_(name)
46 Inset * InsetMathAMSArray::clone() const
48 return new InsetMathAMSArray(*this);
52 char const * InsetMathAMSArray::name_left() const
54 if (name_ == "bmatrix")
55 return "[";
56 if (name_ == "Bmatrix")
57 return "{";
58 if (name_ == "vmatrix")
59 return "|";
60 if (name_ == "Vmatrix")
61 return "Vert";
62 if (name_ == "pmatrix")
63 return "(";
64 return ".";
68 char const * InsetMathAMSArray::name_right() const
70 if (name_ == "bmatrix")
71 return "]";
72 if (name_ == "Bmatrix")
73 return "}";
74 if (name_ == "vmatrix")
75 return "|";
76 if (name_ == "Vmatrix")
77 return "Vert";
78 if (name_ == "pmatrix")
79 return ")";
80 return ".";
84 void InsetMathAMSArray::metrics(MetricsInfo & mi, Dimension & dim) const
86 ArrayChanger dummy(mi.base);
87 InsetMathGrid::metrics(mi, dim);
88 dim.wid += 14;
92 void InsetMathAMSArray::draw(PainterInfo & pi, int x, int y) const
94 Dimension const dim = dimension(*pi.base.bv);
95 int const yy = y - dim.ascent();
96 // Drawing the deco after an ArrayChanger does not work
97 mathed_draw_deco(pi, x + 1, yy, 5, dim.height(), from_ascii(name_left()));
98 mathed_draw_deco(pi, x + dim.width() - 8, yy, 5, dim.height(), from_ascii(name_right()));
99 ArrayChanger dummy(pi.base);
100 InsetMathGrid::drawWithMargin(pi, x, y, 6, 8);
104 bool InsetMathAMSArray::getStatus(Cursor & cur, FuncRequest const & cmd,
105 FuncStatus & flag) const
107 switch (cmd.action) {
108 case LFUN_TABULAR_FEATURE: {
109 docstring const & s = cmd.argument();
110 if (s == "add-vline-left" || s == "add-vline-right") {
111 flag.message(bformat(
112 from_utf8(N_("Can't add vertical grid lines in '%1$s'")), name_));
113 flag.setEnabled(false);
114 return true;
116 return InsetMathGrid::getStatus(cur, cmd, flag);
118 default:
119 return InsetMathGrid::getStatus(cur, cmd, flag);
124 void InsetMathAMSArray::write(WriteStream & os) const
126 MathEnsurer ensurer(os);
127 os << "\\begin{" << name_ << '}';
128 InsetMathGrid::write(os);
129 os << "\\end{" << name_ << '}';
133 void InsetMathAMSArray::infoize(odocstream & os) const
135 docstring name = name_;
136 name[0] = support::uppercase(name[0]);
137 os << name << ' ';
141 void InsetMathAMSArray::normalize(NormalStream & os) const
143 os << '[' << name_ << ' ';
144 InsetMathGrid::normalize(os);
145 os << ']';
149 void InsetMathAMSArray::validate(LaTeXFeatures & features) const
151 if (name_ == "CD")
152 // amscd is independent of amsmath although it is part of
153 // the amsmath bundle
154 features.require("amscd");
155 else
156 features.require("amsmath");
157 InsetMathGrid::validate(features);
161 } // namespace lyx