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 == "append-column"
120 && (name_ == "gathered" || name_ == "lgathered" || name_ == "rgathered")) {
121 // gathered does not support multiple columns
122 flag.setEnabled(false);
125 if (s == "add-vline-left" || s == "add-vline-right") {
126 flag.message(bformat(
127 from_utf8(N_("Can't add vertical grid lines in '%1$s'")),
129 flag.setEnabled(false);
132 if (s == "align-left" || s == "align-center" || s == "align-right") {
133 flag.setEnabled(false);
141 return InsetMathGrid::getStatus(cur, cmd, flag);
145 void InsetMathSplit::write(WriteStream & ws) const
147 MathEnsurer ensurer(ws);
151 if (!numbered_ && name_ == "align")
152 suffix = from_ascii("*");
153 ws << "\\begin{" << name_ << suffix << '}';
154 bool open = ws.startOuterRow();
155 bool const hasArg(name_ == "alignedat");
156 if (name_ != "split" && name_ != "align") {
157 if (verticalAlignment() != 'c')
158 ws << '[' << verticalAlignment() << ']';
160 docstring const first(asString(cell(0)));
161 // prevent misinterpretation of the first character of
162 // the first cell as optional argument (bug 10361)
163 if (!first.empty() && first[0] == '[')
168 ws << '{' << static_cast<unsigned int>((ncols() + 1)/2) << '}';
169 InsetMathGrid::write(ws);
172 ws << "\\end{" << name_ << suffix << "}\n";
178 void InsetMathSplit::infoize(odocstream & os) const
180 docstring name = name_;
181 name[0] = support::uppercase(name[0]);
182 if (name_ == "align" && !numbered_)
189 void InsetMathSplit::mathmlize(MathStream & ms) const
191 // split, gathered, aligned, alignedat
192 // At the moment, those seem to display just fine without any
193 // special treatment.
195 // lgathered and rgathered could use the proper alignment, but
196 // it's not clear how to do that without copying a lot of code.
197 // One idea would be to wrap the table in an <mrow>, and set the
198 // alignment there via CSS.
199 // FIXME how to handle numbered and unnumbered align?
200 InsetMathGrid::mathmlize(ms);
204 void InsetMathSplit::htmlize(HtmlStream & ms) const
206 // split, gathered, aligned, alignedat
207 // At the moment, those seem to display just fine without any
208 // special treatment.
210 // lgathered and rgathered could use the proper alignment.
211 // FIXME how to handle numbered and unnumbered align?
212 InsetMathGrid::htmlize(ms);
216 void InsetMathSplit::validate(LaTeXFeatures & features) const
218 if (name_ == "split" || name_ == "gathered" || name_ == "aligned" ||
219 name_ == "alignedat" || name_ == "align")
220 features.require("amsmath");
221 else if (name_ == "lgathered" || name_ == "rgathered")
222 features.require("mathtools");
223 InsetMathGrid::validate(features);