2 * \file InsetMathCases.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 "InsetMathCases.h"
16 #include "FuncRequest.h"
17 #include "FuncStatus.h"
18 #include "support/gettext.h"
19 #include "LaTeXFeatures.h"
21 #include "MathStream.h"
22 #include "MathSupport.h"
23 #include "MetricsInfo.h"
25 #include "support/lstrings.h"
30 using namespace lyx::support;
35 InsetMathCases::InsetMathCases(Buffer * buf, row_type rows)
36 : InsetMathGrid(buf, 2, rows, 'c', from_ascii("ll"))
40 Inset * InsetMathCases::clone() const
42 return new InsetMathCases(*this);
46 void InsetMathCases::metrics(MetricsInfo & mi, Dimension & dim) const
48 Changer dummy = mi.base.changeEnsureMath();
49 InsetMathGrid::metrics(mi, dim);
53 void InsetMathCases::draw(PainterInfo & pi, int x, int y) const
55 Changer dummy = pi.base.changeEnsureMath();
56 Dimension const dim = dimension(*pi.base.bv);
57 mathed_draw_deco(pi, x + 1, y - dim.ascent(), 6, dim.height(), from_ascii("{"));
58 InsetMathGrid::draw(pi, x, y);
62 void InsetMathCases::doDispatch(Cursor & cur, FuncRequest & cmd)
64 //lyxerr << "*** InsetMathCases: request: " << cmd << endl;
65 switch (cmd.action()) {
66 case LFUN_TABULAR_FEATURE: {
67 string s = cmd.getArg(0);
68 // vertical lines and adding/deleting columns is not allowed for \cases
69 // FIXME: "I suspect that the break after cur.undispatched() should be a
70 // return; the recordUndo seems bogus too." (lasgouttes)
71 if (s == "append-column" || s == "delete-column"
72 || s == "add-vline-left" || s == "add-vline-right") {
81 InsetMathGrid::doDispatch(cur, cmd);
85 bool InsetMathCases::getStatus(Cursor & cur, FuncRequest const & cmd,
86 FuncStatus & flag) const
88 switch (cmd.action()) {
89 case LFUN_TABULAR_FEATURE: {
90 string s = cmd.getArg(0);
91 if (s == "add-vline-left" || s == "add-vline-right") {
92 flag.setEnabled(false);
94 from_utf8(N_("No vertical grid lines in 'cases': feature %1$s")),
98 if (s == "append-column" || s == "delete-column") {
99 flag.setEnabled(false);
100 flag.message(bformat(
101 from_utf8(N_("Changing number of columns not allowed in "
102 "'cases': feature %1$s")), from_utf8(s)));
110 return InsetMathGrid::getStatus(cur, cmd, flag);
114 void InsetMathCases::write(TeXMathStream & os) const
116 MathEnsurer ensurer(os);
119 bool open = os.startOuterRow();
120 os << "\\begin{cases}\n";
121 InsetMathGrid::write(os);
124 os << "\\end{cases}";
130 void InsetMathCases::normalize(NormalStream & os) const
133 InsetMathGrid::normalize(os);
138 void InsetMathCases::maple(MapleStream & os) const
141 InsetMathGrid::maple(os);
146 void InsetMathCases::mathmlize(MathMLStream & ms) const
148 ms << "<" << from_ascii(ms.namespacedTag("mo"))
149 << " form='prefix' fence='true' stretchy='true' symmetric='true'>"
151 << "</" << from_ascii(ms.namespacedTag("mo")) << ">";
152 InsetMathGrid::mathmlize(ms);
157 // We need a brace here, somehow.
158 void InsetMathCases::htmlize(HtmlStream & ms) const
160 InsetMathGrid::htmlize(ms, "class='cases'");
164 void InsetMathCases::infoize(odocstream & os) const
170 void InsetMathCases::validate(LaTeXFeatures & features) const
172 features.require("amsmath");
173 InsetMathGrid::validate(features);
174 if (features.runparams().math_flavor == OutputParams::MathAsHTML)
175 // CSS based on eLyXer's, with modifications suggested in bug #8755
176 features.addCSSSnippet(
177 "table.cases{display: inline-block; text-align: center; border: none;"
178 "border-left: thin solid black; vertical-align: middle; padding-left: 0.5ex;}\n"
179 "table.cases td {text-align: left; border: none;}");
183 int InsetMathCases::displayColSpace(col_type) const