2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
|
* \file InsetMathAMSArray.cpp
|
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>
|
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "InsetMathAMSArray.h"
|
2007-11-05 23:46:17 +00:00
|
|
|
|
|
|
|
|
|
#include "LaTeXFeatures.h"
|
2007-04-26 16:05:57 +00:00
|
|
|
|
#include "MathData.h"
|
2006-10-22 10:15:23 +00:00
|
|
|
|
#include "MathStream.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "MathSupport.h"
|
2007-11-05 23:46:17 +00:00
|
|
|
|
#include "MetricsInfo.h"
|
2002-02-13 13:15:15 +00:00
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "FuncRequest.h"
|
2005-04-03 12:07:49 +00:00
|
|
|
|
#include "FuncStatus.h"
|
2007-11-29 07:04:28 +00:00
|
|
|
|
#include "support/gettext.h"
|
2005-04-03 12:07:49 +00:00
|
|
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
2007-11-06 21:45:24 +00:00
|
|
|
|
|
2008-05-06 10:36:32 +00:00
|
|
|
|
#include <ostream>
|
|
|
|
|
|
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
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
|
Inset * InsetMathAMSArray::clone() const
|
2002-02-13 13:15:15 +00:00
|
|
|
|
{
|
2007-08-30 18:03:17 +00:00
|
|
|
|
return 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
|
void 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;
|
2007-09-23 22:39:49 +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
|
|
|
|
{
|
2007-09-23 22:39:49 +00:00
|
|
|
|
Dimension const dim = dimension(*pi.base.bv);
|
|
|
|
|
int const yy = y - dim.ascent();
|
2006-04-11 13:57:05 +00:00
|
|
|
|
// Drawing the deco after an ArrayChanger does not work
|
2007-09-23 22:39:49 +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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool InsetMathAMSArray::getStatus(Cursor & 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_));
|
2008-05-29 15:14:00 +00:00
|
|
|
|
flag.setEnabled(false);
|
2005-04-03 12:07:49 +00:00
|
|
|
|
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
|
|
|
|
{
|
2008-06-17 11:10:43 +00:00
|
|
|
|
MathEnsurer ensurer(os);
|
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
|