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 n)
36 : InsetMathGrid(buf, 2, n, 'c', from_ascii("ll"))
40 Inset * InsetMathCases::clone() const
42 return new InsetMathCases(*this);
46 void InsetMathCases::metrics(MetricsInfo & mi, Dimension & dim) const
48 InsetMathGrid::metrics(mi, dim);
52 void InsetMathCases::draw(PainterInfo & pi, int x, int y) const
54 Dimension const dim = dimension(*pi.base.bv);
55 mathed_draw_deco(pi, x + 1, y - dim.ascent(), 6, dim.height(), from_ascii("{"));
56 InsetMathGrid::draw(pi, x, y);
57 setPosCache(pi, x, y);
61 void InsetMathCases::doDispatch(Cursor & cur, FuncRequest & cmd)
63 //lyxerr << "*** InsetMathCases: request: " << cmd << endl;
64 switch (cmd.action()) {
65 case LFUN_TABULAR_FEATURE: {
66 string s = cmd.getArg(0);
67 // vertical lines and adding/deleting columns is not allowed for \cases
68 // FIXME: "I suspect that the break after cur.undispatched() should be a
69 // return; the recordUndo seems bogus too." (lasgouttes)
70 if (s == "append-column" || s == "delete-column"
71 || s == "add-vline-left" || s == "add-vline-right") {
80 InsetMathGrid::doDispatch(cur, cmd);
84 bool InsetMathCases::getStatus(Cursor & cur, FuncRequest const & cmd,
85 FuncStatus & flag) const
87 switch (cmd.action()) {
88 case LFUN_TABULAR_FEATURE: {
89 string s = cmd.getArg(0);
90 if (s == "add-vline-left" || s == "add-vline-right") {
91 flag.setEnabled(false);
93 from_utf8(N_("No vertical grid lines in 'cases': feature %1$s")),
97 if (s == "append-column" || s == "delete-column") {
98 flag.setEnabled(false);
100 from_utf8(N_("Changing number of columns not allowed in "
101 "'cases': feature %1$s")), from_utf8(s)));
109 return InsetMathGrid::getStatus(cur, cmd, flag);
113 void InsetMathCases::write(WriteStream & os) const
115 MathEnsurer ensurer(os);
118 bool open = os.startOuterRow();
119 os << "\\begin{cases}\n";
120 InsetMathGrid::write(os);
123 os << "\\end{cases}";
129 void InsetMathCases::normalize(NormalStream & os) const
132 InsetMathGrid::normalize(os);
137 void InsetMathCases::maple(MapleStream & os) const
140 InsetMathGrid::maple(os);
145 void InsetMathCases::mathmlize(MathStream & ms) const
147 ms << "<mo form='prefix' fence='true' stretchy='true' symmetric='true'>{</mo>";
148 InsetMathGrid::mathmlize(ms);
153 // We need a brace here, somehow.
154 void InsetMathCases::htmlize(HtmlStream & ms) const
156 InsetMathGrid::htmlize(ms, "class='cases'");
160 void InsetMathCases::infoize(odocstream & os) const
166 void InsetMathCases::validate(LaTeXFeatures & features) const
168 features.require("amsmath");
169 InsetMathGrid::validate(features);
170 if (features.runparams().math_flavor == OutputParams::MathAsHTML)
171 // CSS based on eLyXer's, with modifications suggested in bug #8755
172 features.addCSSSnippet(
173 "table.cases{display: inline-block; text-align: center; border: none;"
174 "border-left: thin solid black; vertical-align: middle; padding-left: 0.5ex;}\n"
175 "table.cases td {text-align: left; border: none;}");
179 int InsetMathCases::displayColSpace(col_type) const