2 * \file InsetMathSplit.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 "InsetMathSplit.h"
16 #include "MathStream.h"
17 #include "MathSupport.h"
20 #include "FuncRequest.h"
21 #include "FuncStatus.h"
22 #include "support/gettext.h"
23 #include "LaTeXFeatures.h"
24 #include "MetricsInfo.h"
26 #include "support/lstrings.h"
34 using support::bformat;
37 // FIXME: handle numbers in gui, currently they are only read and written
39 InsetMathSplit::InsetMathSplit(Buffer * buf, docstring const & name,
40 char valign, bool numbered)
41 : InsetMathGrid(buf, 1, 1, valign, docstring()), name_(name),
47 Inset * InsetMathSplit::clone() const
49 return new InsetMathSplit(*this);
53 char InsetMathSplit::defaultColAlign(col_type col)
55 if (name_ == "gathered")
57 if (name_ == "lgathered")
59 if (name_ == "rgathered")
64 || name_ == "alignedat")
65 return colAlign(hullAlign, col);
70 char InsetMathSplit::displayColAlign(idx_type idx) const
72 if (name_ == "gathered")
74 if (name_ == "lgathered")
76 if (name_ == "rgathered")
81 || name_ == "alignedat")
82 return colAlign(hullAlign, col(idx));
83 return InsetMathGrid::displayColAlign(idx);
87 int InsetMathSplit::displayColSpace(col_type col) const
89 if (name_ == "split" || name_ == "aligned" || name_ == "align")
90 return colSpace(hullAlign, col);
91 if (name_ == "alignedat")
92 return colSpace(hullAlignAt, col);
98 void InsetMathSplit::metrics(MetricsInfo & mi, Dimension & dim) const
100 Changer dummy = mi.base.changeEnsureMath();
101 InsetMathGrid::metrics(mi, dim);
106 void InsetMathSplit::draw(PainterInfo & pi, int x, int y) const
108 Changer dummy = pi.base.changeEnsureMath();
109 InsetMathGrid::draw(pi, x, y);
113 bool InsetMathSplit::getStatus(Cursor & cur, FuncRequest const & cmd,
114 FuncStatus & flag) const
116 switch (cmd.action()) {
117 case LFUN_TABULAR_FEATURE: {
118 string s = cmd.getArg(0);
119 if (s == "add-vline-left" || s == "add-vline-right") {
120 flag.message(bformat(
121 from_utf8(N_("Can't add vertical grid lines in '%1$s'")),
123 flag.setEnabled(false);
126 if (s == "align-left" || s == "align-center" || s == "align-right") {
127 flag.setEnabled(false);
135 return InsetMathGrid::getStatus(cur, cmd, flag);
139 void InsetMathSplit::write(WriteStream & ws) const
141 MathEnsurer ensurer(ws);
145 if (!numbered_ && name_ == "align")
146 suffix = from_ascii("*");
147 ws << "\\begin{" << name_ << suffix << '}';
148 bool open = ws.startOuterRow();
149 bool const hasArg(name_ == "alignedat");
150 if (name_ != "split" && name_ != "align") {
151 if (verticalAlignment() != 'c')
152 ws << '[' << verticalAlignment() << ']';
154 docstring const first(asString(cell(0)));
155 // prevent misinterpretation of the first character of
156 // the first cell as optional argument (bug 10361)
157 if (!first.empty() && first[0] == '[')
162 ws << '{' << static_cast<unsigned int>((ncols() + 1)/2) << '}';
163 InsetMathGrid::write(ws);
166 ws << "\\end{" << name_ << suffix << "}\n";
172 void InsetMathSplit::infoize(odocstream & os) const
174 docstring name = name_;
175 name[0] = support::uppercase(name[0]);
176 if (name_ == "align" && !numbered_)
183 void InsetMathSplit::mathmlize(MathStream & ms) const
185 // split, gathered, aligned, alignedat
186 // At the moment, those seem to display just fine without any
187 // special treatment.
189 // lgathered and rgathered could use the proper alignment, but
190 // it's not clear how to do that without copying a lot of code.
191 // One idea would be to wrap the table in an <mrow>, and set the
192 // alignment there via CSS.
193 // FIXME how to handle numbered and unnumbered align?
194 InsetMathGrid::mathmlize(ms);
198 void InsetMathSplit::htmlize(HtmlStream & ms) const
200 // split, gathered, aligned, alignedat
201 // At the moment, those seem to display just fine without any
202 // special treatment.
204 // lgathered and rgathered could use the proper alignment.
205 // FIXME how to handle numbered and unnumbered align?
206 InsetMathGrid::htmlize(ms);
210 void InsetMathSplit::validate(LaTeXFeatures & features) const
212 if (name_ == "split" || name_ == "gathered" || name_ == "aligned" ||
213 name_ == "alignedat" || name_ == "align")
214 features.require("amsmath");
215 else if (name_ == "lgathered" || name_ == "rgathered")
216 features.require("mathtools");
217 InsetMathGrid::validate(features);