2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
2006-09-17 09:14:18 +00:00
|
|
|
|
* \file InsetMathAMSArray.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.
|
|
|
|
|
*/
|
|
|
|
|
|
2002-02-13 13:15:15 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2005-03-30 09:05:30 +00:00
|
|
|
|
#include "LaTeXFeatures.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "InsetMathAMSArray.h"
|
|
|
|
|
#include "MathData.h"
|
2006-10-22 10:15:23 +00:00
|
|
|
|
#include "MathStream.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "MathStream.h"
|
|
|
|
|
#include "MathSupport.h"
|
2002-02-13 13:15:15 +00:00
|
|
|
|
|
2005-04-03 12:07:49 +00:00
|
|
|
|
#include "funcrequest.h"
|
|
|
|
|
#include "FuncStatus.h"
|
|
|
|
|
#include "gettext.h"
|
|
|
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
#include "support/std_ostream.h"
|
|
|
|
|
|
2003-07-25 17:11:25 +00:00
|
|
|
|
using std::auto_ptr;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
|
using support::bformat;
|
2003-07-25 17:11:25 +00:00
|
|
|
|
|
2002-02-13 13:15:15 +00:00
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
InsetMathAMSArray::InsetMathAMSArray(docstring const & name, int m, int n)
|
2006-09-16 18:11:38 +00:00
|
|
|
|
: InsetMathGrid(m, n), name_(name)
|
2002-02-13 13:15:15 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
InsetMathAMSArray::InsetMathAMSArray(docstring const & name)
|
2006-09-16 18:11:38 +00:00
|
|
|
|
: InsetMathGrid(1, 1), name_(name)
|
2002-02-13 13:15:15 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
auto_ptr<InsetBase> InsetMathAMSArray::doClone() const
|
2002-02-13 13:15:15 +00:00
|
|
|
|
{
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return auto_ptr<InsetBase>(new InsetMathAMSArray(*this));
|
2002-02-13 13:15:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
char const * InsetMathAMSArray::name_left() const
|
2002-02-13 13:15:15 +00:00
|
|
|
|
{
|
|
|
|
|
if (name_ == "bmatrix")
|
|
|
|
|
return "[";
|
2002-08-12 07:05:02 +00:00
|
|
|
|
if (name_ == "Bmatrix")
|
|
|
|
|
return "{";
|
2002-02-14 14:19:52 +00:00
|
|
|
|
if (name_ == "vmatrix")
|
|
|
|
|
return "|";
|
|
|
|
|
if (name_ == "Vmatrix")
|
|
|
|
|
return "Vert";
|
2002-02-15 14:50:40 +00:00
|
|
|
|
if (name_ == "pmatrix")
|
|
|
|
|
return "(";
|
|
|
|
|
return ".";
|
2002-02-13 13:15:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
char const * InsetMathAMSArray::name_right() const
|
2002-02-13 13:15:15 +00:00
|
|
|
|
{
|
|
|
|
|
if (name_ == "bmatrix")
|
|
|
|
|
return "]";
|
2002-08-12 07:05:02 +00:00
|
|
|
|
if (name_ == "Bmatrix")
|
|
|
|
|
return "}";
|
2002-02-14 14:19:52 +00:00
|
|
|
|
if (name_ == "vmatrix")
|
|
|
|
|
return "|";
|
|
|
|
|
if (name_ == "Vmatrix")
|
|
|
|
|
return "Vert";
|
2002-02-15 14:50:40 +00:00
|
|
|
|
if (name_ == "pmatrix")
|
|
|
|
|
return ")";
|
|
|
|
|
return ".";
|
2002-02-13 13:15:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-11-28 15:15:49 +00:00
|
|
|
|
bool InsetMathAMSArray::metrics(MetricsInfo & mi, Dimension & dim) const
|
2002-02-13 13:15:15 +00:00
|
|
|
|
{
|
2006-04-11 13:57:05 +00:00
|
|
|
|
ArrayChanger dummy(mi.base);
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathGrid::metrics(mi, dim);
|
2005-04-04 22:11:53 +00:00
|
|
|
|
dim.wid += 14;
|
2006-11-28 15:15:49 +00:00
|
|
|
|
bool const changed = dim_ != dim;
|
2004-04-06 19:25:39 +00:00
|
|
|
|
dim_ = dim;
|
2006-11-28 15:15:49 +00:00
|
|
|
|
return changed;
|
2002-02-13 13:15:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathAMSArray::draw(PainterInfo & pi, int x, int y) const
|
2002-03-21 17:42:56 +00:00
|
|
|
|
{
|
2003-05-28 13:22:36 +00:00
|
|
|
|
int const yy = y - dim_.ascent();
|
2006-04-11 13:57:05 +00:00
|
|
|
|
// Drawing the deco after an ArrayChanger does not work
|
2006-10-22 10:15:23 +00:00
|
|
|
|
mathed_draw_deco(pi, x + 1, yy, 5, dim_.height(), from_ascii(name_left()));
|
|
|
|
|
mathed_draw_deco(pi, x + dim_.width() - 8, yy, 5, dim_.height(), from_ascii(name_right()));
|
2006-04-11 13:57:05 +00:00
|
|
|
|
ArrayChanger dummy(pi.base);
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathGrid::drawWithMargin(pi, x, y, 6, 8);
|
2002-02-13 13:15:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathAMSArray::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-10-22 10:15:23 +00:00
|
|
|
|
from_utf8(N_("Can't add vertical grid lines in '%1$s'")), 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);
|
2006-04-05 23:56:29 +00:00
|
|
|
|
}
|
2005-04-03 12:07:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathAMSArray::write(WriteStream & os) const
|
2002-02-13 13:15:15 +00:00
|
|
|
|
{
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << "\\begin{" << name_ << '}';
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathGrid::write(os);
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << "\\end{" << name_ << '}';
|
2002-02-13 13:15:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
void InsetMathAMSArray::infoize(odocstream & os) const
|
2005-04-03 12:07:49 +00:00
|
|
|
|
{
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring name = name_;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
name[0] = support::uppercase(name[0]);
|
2005-04-03 12:07:49 +00:00
|
|
|
|
os << name << ' ';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathAMSArray::normalize(NormalStream & os) const
|
2002-02-13 13:15:15 +00:00
|
|
|
|
{
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << '[' << name_ << ' ';
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathGrid::normalize(os);
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << ']';
|
2002-02-13 13:15:15 +00:00
|
|
|
|
}
|
2005-03-30 09:05:30 +00:00
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathAMSArray::validate(LaTeXFeatures & features) const
|
2005-03-30 09:05:30 +00:00
|
|
|
|
{
|
|
|
|
|
features.require("amsmath");
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathGrid::validate(features);
|
2005-03-30 09:05:30 +00:00
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|