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"
24 #include "support/lstrings.h"
32 using support::bformat;
35 // FIXME: handle numbers in gui, currently they are only read and written
37 InsetMathSplit::InsetMathSplit(Buffer * buf, docstring const & name,
38 char valign, bool numbered)
39 : InsetMathGrid(buf, 1, 1, valign, docstring()), name_(name),
45 Inset * InsetMathSplit::clone() const
47 return new InsetMathSplit(*this);
51 // FIXME: InsetMathGrid should be changed to let the real column alignment be
52 // given by a virtual method like displayColAlign, because the values produced
53 // by defaultColAlign can be invalidated by lfuns such as add-column. I suspect
54 // that for the moment the values produced by defaultColAlign are not used,
55 // notably because alignment is not implemented in the LyXHTML output.
56 char InsetMathSplit::defaultColAlign(col_type col)
58 if (name_ == "gathered")
60 if (name_ == "lgathered")
62 if (name_ == "rgathered")
67 || name_ == "alignedat")
68 return colAlign(hullAlign, col);
73 char InsetMathSplit::displayColAlign(idx_type idx) const
75 if (name_ == "gathered")
77 if (name_ == "lgathered")
79 if (name_ == "rgathered")
84 || name_ == "alignedat")
85 return colAlign(hullAlign, col(idx));
86 return InsetMathGrid::displayColAlign(idx);
90 int InsetMathSplit::displayColSpace(col_type col) const
92 if (name_ == "split" || name_ == "aligned" || name_ == "align")
93 return colSpace(hullAlign, col);
94 if (name_ == "alignedat")
95 return colSpace(hullAlignAt, col);
101 void InsetMathSplit::draw(PainterInfo & pi, int x, int y) const
103 InsetMathGrid::draw(pi, x, y);
104 setPosCache(pi, x, y);
108 bool InsetMathSplit::getStatus(Cursor & cur, FuncRequest const & cmd,
109 FuncStatus & flag) const
111 switch (cmd.action()) {
112 case LFUN_TABULAR_FEATURE: {
113 string s = cmd.getArg(0);
114 if (s == "add-vline-left" || s == "add-vline-right") {
115 flag.message(bformat(
116 from_utf8(N_("Can't add vertical grid lines in '%1$s'")),
118 flag.setEnabled(false);
121 if (s == "align-left" || s == "align-center" || s == "align-right") {
122 flag.setEnabled(false);
130 return InsetMathGrid::getStatus(cur, cmd, flag);
134 void InsetMathSplit::write(WriteStream & ws) const
136 MathEnsurer ensurer(ws);
140 if (!numbered_ && name_ == "align")
141 suffix = from_ascii("*");
142 ws << "\\begin{" << name_ << suffix << '}';
143 bool open = ws.startOuterRow();
144 bool const hasArg(name_ == "alignedat");
145 if (name_ != "split" && name_ != "align") {
146 if (verticalAlignment() != 'c')
147 ws << '[' << verticalAlignment() << ']';
149 docstring const first(asString(cell(0)));
150 // prevent misinterpretation of the first character of
151 // the first cell as optional argument (bug 10361)
152 if (!first.empty() && first[0] == '[')
157 ws << '{' << static_cast<unsigned int>((ncols() + 1)/2) << '}';
158 InsetMathGrid::write(ws);
161 ws << "\\end{" << name_ << suffix << "}\n";
167 void InsetMathSplit::infoize(odocstream & os) const
169 docstring name = name_;
170 name[0] = support::uppercase(name[0]);
171 if (name_ == "align" && !numbered_)
178 void InsetMathSplit::mathmlize(MathStream & ms) const
180 // split, gathered, aligned, alignedat
181 // At the moment, those seem to display just fine without any
182 // special treatment.
184 // lgathered and rgathered could use the proper alignment, but
185 // it's not clear how to do that without copying a lot of code.
186 // One idea would be to wrap the table in an <mrow>, and set the
187 // alignment there via CSS.
188 // FIXME how to handle numbered and unnumbered align?
189 InsetMathGrid::mathmlize(ms);
193 void InsetMathSplit::htmlize(HtmlStream & ms) const
195 // split, gathered, aligned, alignedat
196 // At the moment, those seem to display just fine without any
197 // special treatment.
199 // lgathered and rgathered could use the proper alignment.
200 // FIXME how to handle numbered and unnumbered align?
201 InsetMathGrid::htmlize(ms);
205 void InsetMathSplit::validate(LaTeXFeatures & features) const
207 if (name_ == "split" || name_ == "gathered" || name_ == "aligned" ||
208 name_ == "alignedat" || name_ == "align")
209 features.require("amsmath");
210 else if (name_ == "lgathered" || name_ == "rgathered")
211 features.require("mathtools");
212 InsetMathGrid::validate(features);