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"
19 #include "FuncRequest.h"
20 #include "FuncStatus.h"
21 #include "support/gettext.h"
22 #include "LaTeXFeatures.h"
23 #include "MetricsInfo.h"
25 #include "support/lstrings.h"
33 using support::bformat;
36 // FIXME: handle numbers in gui, currently they are only read and written
38 InsetMathSplit::InsetMathSplit(Buffer * buf, docstring const & name,
39 char valign, bool numbered)
40 : InsetMathGrid(buf, 1, 1, valign, docstring()), name_(name),
46 Inset * InsetMathSplit::clone() const
48 return new InsetMathSplit(*this);
52 char InsetMathSplit::defaultColAlign(col_type col)
54 if (name_ == "gathered")
56 if (name_ == "lgathered")
58 if (name_ == "rgathered")
63 || name_ == "alignedat")
64 return colAlign(hullAlign, col);
69 char InsetMathSplit::displayColAlign(idx_type idx) const
71 if (name_ == "gathered")
73 if (name_ == "lgathered")
75 if (name_ == "rgathered")
80 || name_ == "alignedat")
81 return colAlign(hullAlign, col(idx));
82 return InsetMathGrid::displayColAlign(idx);
86 int InsetMathSplit::displayColSpace(col_type col) const
88 if (name_ == "split" || name_ == "aligned" || name_ == "align")
89 return colSpace(hullAlign, col);
90 if (name_ == "alignedat")
91 return colSpace(hullAlignAt, col);
97 void InsetMathSplit::metrics(MetricsInfo & mi, Dimension & dim) const
99 Changer dummy = mi.base.changeEnsureMath();
100 InsetMathGrid::metrics(mi, dim);
105 void InsetMathSplit::draw(PainterInfo & pi, int x, int y) const
107 Changer dummy = pi.base.changeEnsureMath();
108 InsetMathGrid::draw(pi, x, y);
112 bool InsetMathSplit::getStatus(Cursor & cur, FuncRequest const & cmd,
113 FuncStatus & flag) const
115 switch (cmd.action()) {
116 case LFUN_TABULAR_FEATURE: {
117 string s = cmd.getArg(0);
118 if (s == "add-vline-left" || s == "add-vline-right") {
119 flag.message(bformat(
120 from_utf8(N_("Can't add vertical grid lines in '%1$s'")),
122 flag.setEnabled(false);
125 if (s == "align-left" || s == "align-center" || s == "align-right") {
126 flag.setEnabled(false);
134 return InsetMathGrid::getStatus(cur, cmd, flag);
138 void InsetMathSplit::write(WriteStream & ws) const
140 MathEnsurer ensurer(ws);
144 if (!numbered_ && name_ == "align")
145 suffix = from_ascii("*");
146 ws << "\\begin{" << name_ << suffix << '}';
147 bool open = ws.startOuterRow();
148 bool const hasArg(name_ == "alignedat");
149 if (name_ != "split" && name_ != "align") {
150 if (verticalAlignment() != 'c')
151 ws << '[' << verticalAlignment() << ']';
153 docstring const first(asString(cell(0)));
154 // prevent misinterpretation of the first character of
155 // the first cell as optional argument (bug 10361)
156 if (!first.empty() && first[0] == '[')
161 ws << '{' << static_cast<unsigned int>((ncols() + 1)/2) << '}';
162 InsetMathGrid::write(ws);
165 ws << "\\end{" << name_ << suffix << "}\n";
171 void InsetMathSplit::infoize(odocstream & os) const
173 docstring name = name_;
174 name[0] = support::uppercase(name[0]);
175 if (name_ == "align" && !numbered_)
182 void InsetMathSplit::mathmlize(MathStream & ms) const
184 // split, gathered, aligned, alignedat
185 // At the moment, those seem to display just fine without any
186 // special treatment.
188 // lgathered and rgathered could use the proper alignment, but
189 // it's not clear how to do that without copying a lot of code.
190 // One idea would be to wrap the table in an <mrow>, and set the
191 // alignment there via CSS.
192 // FIXME how to handle numbered and unnumbered align?
193 InsetMathGrid::mathmlize(ms);
197 void InsetMathSplit::htmlize(HtmlStream & ms) const
199 // split, gathered, aligned, alignedat
200 // At the moment, those seem to display just fine without any
201 // special treatment.
203 // lgathered and rgathered could use the proper alignment.
204 // FIXME how to handle numbered and unnumbered align?
205 InsetMathGrid::htmlize(ms);
209 void InsetMathSplit::validate(LaTeXFeatures & features) const
211 if (name_ == "split" || name_ == "gathered" || name_ == "aligned" ||
212 name_ == "alignedat" || name_ == "align")
213 features.require("amsmath");
214 else if (name_ == "lgathered" || name_ == "rgathered")
215 features.require("mathtools");
216 InsetMathGrid::validate(features);