2 * \file InsetMathSplit.cpp
\r
3 * This file is part of LyX, the document processor.
\r
4 * Licence details can be found in the file COPYING.
\r
6 * \author André Pönitz
\r
8 * Full author contact details are available in file CREDITS.
\r
13 #include "InsetMathSplit.h"
\r
15 #include "MathData.h"
\r
16 #include "MathStream.h"
\r
17 #include "MathStream.h"
\r
19 #include "FuncRequest.h"
\r
20 #include "FuncStatus.h"
\r
21 #include "support/gettext.h"
\r
22 #include "LaTeXFeatures.h"
\r
24 #include "support/lstrings.h"
\r
28 using namespace std;
\r
32 using support::bformat;
\r
35 // FIXME: handle numbers in gui, currently they are only read and written
\r
37 InsetMathSplit::InsetMathSplit(Buffer * buf, docstring const & name,
\r
38 char valign, bool numbered)
\r
39 : InsetMathGrid(buf, 1, 1, valign, docstring()), name_(name),
\r
45 Inset * InsetMathSplit::clone() const
\r
47 return new InsetMathSplit(*this);
\r
51 //FIXME: This has probably no effect and can be removed.
\r
52 char InsetMathSplit::defaultColAlign(col_type col)
\r
54 if (name_ == "gathered")
\r
56 if (name_ == "lgathered")
\r
58 if (name_ == "rgathered")
\r
60 if (name_ == "split"
\r
61 || name_ == "aligned"
\r
63 || name_ == "alignedat")
\r
64 return colAlign(hullAlign, col);
\r
69 char InsetMathSplit::displayColAlign(idx_type idx) const
\r
71 if (name_ == "gathered")
\r
73 if (name_ == "lgathered")
\r
75 if (name_ == "rgathered")
\r
77 if (name_ == "split"
\r
78 || name_ == "aligned"
\r
80 || name_ == "alignedat")
\r
81 return colAlign(hullAlign, col(idx));
\r
82 return InsetMathGrid::displayColAlign(idx);
\r
86 int InsetMathSplit::displayColSpace(col_type col) const
\r
88 if (name_ == "split" || name_ == "aligned" || name_ == "align")
\r
89 return colSpace(hullAlign, col);
\r
90 if (name_ == "alignedat")
\r
91 return colSpace(hullAlignAt, col);
\r
97 void InsetMathSplit::draw(PainterInfo & pi, int x, int y) const
\r
99 InsetMathGrid::draw(pi, x, y);
\r
100 setPosCache(pi, x, y);
\r
104 bool InsetMathSplit::getStatus(Cursor & cur, FuncRequest const & cmd,
\r
105 FuncStatus & flag) const
\r
107 switch (cmd.action()) {
\r
108 case LFUN_INSET_MODIFY: {
\r
109 istringstream is(to_utf8(cmd.argument()));
\r
112 if (s != "tabular")
\r
115 if (s == "add-vline-left" || s == "add-vline-right") {
\r
116 flag.message(bformat(
\r
117 from_utf8(N_("Can't add vertical grid lines in '%1$s'")), name_));
\r
118 flag.setEnabled(false);
\r
121 if (s == "align-left" || s == "align-center" || s == "align-right") {
\r
122 flag.setEnabled(false);
\r
130 return InsetMathGrid::getStatus(cur, cmd, flag);
\r
134 void InsetMathSplit::write(WriteStream & ws) const
\r
136 MathEnsurer ensurer(ws);
\r
140 if (!numbered_ && name_ == "align")
\r
141 suffix = from_ascii("*");
\r
142 ws << "\\begin{" << name_ << suffix << '}';
\r
143 bool open = ws.startOuterRow();
\r
144 if (name_ != "split" && name_ != "align" && verticalAlignment() != 'c')
\r
145 ws << '[' << verticalAlignment() << ']';
\r
146 if (name_ == "alignedat")
\r
147 ws << '{' << static_cast<unsigned int>((ncols() + 1)/2) << '}';
\r
148 InsetMathGrid::write(ws);
\r
151 ws << "\\end{" << name_ << suffix << "}\n";
\r
153 ws.startOuterRow();
\r
157 void InsetMathSplit::infoize(odocstream & os) const
\r
159 docstring name = name_;
\r
160 name[0] = support::uppercase(name[0]);
\r
161 if (name_ == "align" && !numbered_)
\r
162 os << name << "* ";
\r
168 void InsetMathSplit::mathmlize(MathStream & ms) const
\r
170 // split, gathered, aligned, alignedat
\r
171 // At the moment, those seem to display just fine without any
\r
172 // special treatment.
\r
174 // lgathered and rgathered could use the proper alignment, but
\r
175 // it's not clear how to do that without copying a lot of code.
\r
176 // One idea would be to wrap the table in an <mrow>, and set the
\r
177 // alignment there via CSS.
\r
178 // FIXME how to handle numbered and unnumbered align?
\r
179 InsetMathGrid::mathmlize(ms);
\r
183 void InsetMathSplit::htmlize(HtmlStream & ms) const
\r
185 // split, gathered, aligned, alignedat
\r
186 // At the moment, those seem to display just fine without any
\r
187 // special treatment.
\r
189 // lgathered and rgathered could use the proper alignment.
\r
190 // FIXME how to handle numbered and unnumbered align?
\r
191 InsetMathGrid::htmlize(ms);
\r
195 void InsetMathSplit::validate(LaTeXFeatures & features) const
\r
197 if (name_ == "split" || name_ == "gathered" || name_ == "aligned" ||
\r
198 name_ == "alignedat" || name_ == "align")
\r
199 features.require("amsmath");
\r
200 else if (name_ == "lgathered" || name_ == "rgathered")
\r
201 features.require("mathtools");
\r
202 InsetMathGrid::validate(features);
\r