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 "MathStream.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 InsetMathSplit::InsetMathSplit(docstring const & name, char valign)
36 : InsetMathGrid(1, 1, valign, docstring()), name_(name)
41 Inset * InsetMathSplit::clone() const
43 return new InsetMathSplit(*this);
47 char InsetMathSplit::defaultColAlign(col_type col)
51 if (name_ == "gathered")
53 if (name_ == "aligned")
54 return (col & 1) ? 'l' : 'r';
55 if (name_ == "alignedat")
56 return (col & 1) ? 'l' : 'r';
61 void InsetMathSplit::draw(PainterInfo & pi, int x, int y) const
63 InsetMathGrid::draw(pi, x, y);
64 setPosCache(pi, x, y);
68 bool InsetMathSplit::getStatus(Cursor & cur, FuncRequest const & cmd,
69 FuncStatus & flag) const
72 case LFUN_TABULAR_FEATURE: {
73 docstring const & s = cmd.argument();
74 if (s == "add-vline-left" || s == "add-vline-right") {
76 from_utf8(N_("Can't add vertical grid lines in '%1$s'")), name_));
77 flag.setEnabled(false);
80 return InsetMathGrid::getStatus(cur, cmd, flag);
83 return InsetMathGrid::getStatus(cur, cmd, flag);
88 void InsetMathSplit::write(WriteStream & ws) const
90 MathEnsurer ensurer(ws);
93 ws << "\\begin{" << name_ << '}';
94 if (name_ != "split" && verticalAlignment() != 'c')
95 ws << '[' << verticalAlignment() << ']';
96 if (name_ == "alignedat")
97 ws << '{' << static_cast<unsigned int>((ncols() + 1)/2) << '}';
98 InsetMathGrid::write(ws);
101 ws << "\\end{" << name_ << "}\n";
105 void InsetMathSplit::infoize(odocstream & os) const
107 docstring name = name_;
108 name[0] = support::uppercase(name[0]);
113 void InsetMathSplit::validate(LaTeXFeatures & features) const
115 if (name_ == "split" || name_ == "gathered" || name_ == "aligned" ||
116 name_ == "alignedat")
117 features.require("amsmath");
118 InsetMathGrid::validate(features);