2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
2006-09-17 09:14:18 +00:00
|
|
|
|
* \file InsetMathSplit.C
|
2003-08-19 13:00:56 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "InsetMathSplit.h"
|
|
|
|
|
#include "MathData.h"
|
|
|
|
|
#include "MathMLStream.h"
|
|
|
|
|
#include "MathStream.h"
|
2001-09-05 12:57:13 +00:00
|
|
|
|
|
2005-04-03 12:07:49 +00:00
|
|
|
|
#include "funcrequest.h"
|
|
|
|
|
#include "FuncStatus.h"
|
|
|
|
|
#include "gettext.h"
|
2006-04-13 10:31:32 +00:00
|
|
|
|
#include "LaTeXFeatures.h"
|
2003-10-06 15:43:21 +00:00
|
|
|
|
|
2005-04-03 12:07:49 +00:00
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
#include "support/std_ostream.h"
|
|
|
|
|
|
|
|
|
|
|
2006-09-01 15:41:38 +00:00
|
|
|
|
using lyx::docstring;
|
2005-04-03 12:07:49 +00:00
|
|
|
|
using lyx::support::bformat;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2003-07-25 17:11:25 +00:00
|
|
|
|
using std::auto_ptr;
|
|
|
|
|
|
2001-09-05 12:57:13 +00:00
|
|
|
|
|
2006-10-02 20:01:30 +00:00
|
|
|
|
InsetMathSplit::InsetMathSplit(string const & name, char valign)
|
|
|
|
|
: InsetMathGrid(1, 1, valign, string()), name_(name)
|
2001-09-05 12:57:13 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
auto_ptr<InsetBase> InsetMathSplit::doClone() const
|
2001-09-05 12:57:13 +00:00
|
|
|
|
{
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return auto_ptr<InsetBase>(new InsetMathSplit(*this));
|
2001-09-05 12:57:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
char InsetMathSplit::defaultColAlign(col_type col)
|
2002-02-15 14:50:40 +00:00
|
|
|
|
{
|
|
|
|
|
if (name_ == "split")
|
|
|
|
|
return 'l';
|
|
|
|
|
if (name_ == "gathered")
|
|
|
|
|
return 'c';
|
|
|
|
|
if (name_ == "aligned")
|
|
|
|
|
return (col & 1) ? 'l' : 'r';
|
2004-08-14 14:03:42 +00:00
|
|
|
|
if (name_ == "alignedat")
|
|
|
|
|
return (col & 1) ? 'l' : 'r';
|
2002-02-15 14:50:40 +00:00
|
|
|
|
return 'l';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathSplit::draw(PainterInfo & pi, int x, int y) const
|
2005-04-04 13:40:27 +00:00
|
|
|
|
{
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathGrid::draw(pi, x, y);
|
2005-04-04 13:40:27 +00:00
|
|
|
|
setPosCache(pi, x, y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathSplit::getStatus(LCursor & cur, FuncRequest const & cmd,
|
2005-04-03 12:07:49 +00:00
|
|
|
|
FuncStatus & flag) const
|
|
|
|
|
{
|
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
case LFUN_TABULAR_FEATURE: {
|
2006-09-01 15:41:38 +00:00
|
|
|
|
docstring const & s = cmd.argument();
|
2005-04-03 12:07:49 +00:00
|
|
|
|
if (s == "add-vline-left" || s == "add-vline-right") {
|
|
|
|
|
flag.message(bformat(
|
2006-09-11 08:54:10 +00:00
|
|
|
|
lyx::from_utf8(N_("Can't add vertical grid lines in '%1$s'")),
|
|
|
|
|
lyx::from_utf8(name_)));
|
2005-04-03 12:07:49 +00:00
|
|
|
|
flag.enabled(false);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return InsetMathGrid::getStatus(cur, cmd, flag);
|
2005-04-03 12:07:49 +00:00
|
|
|
|
}
|
|
|
|
|
default:
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return InsetMathGrid::getStatus(cur, cmd, flag);
|
2005-04-03 12:07:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathSplit::write(WriteStream & ws) const
|
2001-09-05 12:57:13 +00:00
|
|
|
|
{
|
2001-12-03 16:24:50 +00:00
|
|
|
|
if (ws.fragile())
|
|
|
|
|
ws << "\\protect";
|
2002-11-27 10:30:28 +00:00
|
|
|
|
ws << "\\begin{" << name_ << '}';
|
2006-10-02 20:01:30 +00:00
|
|
|
|
if (name_ != "split" && valign() != 'c')
|
|
|
|
|
ws << '[' << valign() << ']';
|
2005-10-14 10:50:23 +00:00
|
|
|
|
if (name_ == "alignedat")
|
|
|
|
|
ws << '{' << static_cast<unsigned int>((ncols() + 1)/2) << '}';
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathGrid::write(ws);
|
2001-12-03 16:24:50 +00:00
|
|
|
|
if (ws.fragile())
|
|
|
|
|
ws << "\\protect";
|
2002-02-15 14:50:40 +00:00
|
|
|
|
ws << "\\end{" << name_ << "}\n";
|
2001-09-05 12:57:13 +00:00
|
|
|
|
}
|
2005-04-03 12:07:49 +00:00
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathSplit::infoize(std::ostream & os) const
|
2005-04-03 12:07:49 +00:00
|
|
|
|
{
|
|
|
|
|
string name = name_;
|
|
|
|
|
name[0] = lyx::support::uppercase(name[0]);
|
|
|
|
|
os << name << ' ';
|
|
|
|
|
}
|
2006-04-13 10:31:32 +00:00
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathSplit::validate(LaTeXFeatures & features) const
|
2006-04-13 10:31:32 +00:00
|
|
|
|
{
|
2006-10-03 19:45:43 +00:00
|
|
|
|
if (name_ == "split" || name_ == "gathered" || name_ == "aligned" ||
|
|
|
|
|
name_ == "alignedat")
|
|
|
|
|
features.require("amsmath");
|
|
|
|
|
InsetMathGrid::validate(features);
|
2006-04-13 10:31:32 +00:00
|
|
|
|
}
|