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.
|
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pönitz
|
2003-08-19 13:00:56 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
2010-02-18 08:28:46 +00:00
|
|
|
#include <sstream>
|
2008-05-06 10:36:32 +00:00
|
|
|
#include <ostream>
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2010-02-18 08:28:46 +00:00
|
|
|
using namespace std;
|
|
|
|
using namespace lyx::support;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2010-02-18 08:28:46 +00:00
|
|
|
namespace lyx {
|
2003-07-25 17:11:25 +00:00
|
|
|
|
2002-02-13 13:15:15 +00:00
|
|
|
|
2009-11-08 11:45:46 +00:00
|
|
|
InsetMathAMSArray::InsetMathAMSArray(Buffer * buf, docstring const & name,
|
|
|
|
int m, int n)
|
|
|
|
: InsetMathGrid(buf, m, n), name_(name)
|
2002-02-13 13:15:15 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2009-11-08 11:45:46 +00:00
|
|
|
InsetMathAMSArray::InsetMathAMSArray(Buffer * buf, docstring const & name)
|
|
|
|
: InsetMathGrid(buf, 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
|
|
|
|
{
|
2010-04-09 18:15:17 +00:00
|
|
|
switch (cmd.action_) {
|
2010-02-18 08:28:46 +00:00
|
|
|
case LFUN_INSET_MODIFY: {
|
|
|
|
istringstream is(to_utf8(cmd.argument()));
|
|
|
|
string s;
|
|
|
|
is >> s;
|
|
|
|
if (s != "tabular")
|
|
|
|
break;
|
|
|
|
is >> s;
|
2005-04-03 12:07:49 +00:00
|
|
|
if (s == "add-vline-left" || s == "add-vline-right") {
|
|
|
|
flag.message(bformat(
|
2010-02-18 08:28:46 +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;
|
|
|
|
}
|
2010-02-18 08:28:46 +00:00
|
|
|
break;
|
2005-04-03 12:07:49 +00:00
|
|
|
}
|
|
|
|
default:
|
2010-02-18 08:28:46 +00:00
|
|
|
break;
|
2006-04-05 23:56:29 +00:00
|
|
|
}
|
2010-02-18 08:28:46 +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 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
|
|
|
{
|
2008-07-27 00:47:28 +00:00
|
|
|
if (name_ == "CD")
|
2008-07-27 11:32:26 +00:00
|
|
|
// amscd is independent of amsmath although it is part of
|
|
|
|
// the amsmath bundle
|
2008-07-27 00:47:28 +00:00
|
|
|
features.require("amscd");
|
2008-07-27 11:32:26 +00:00
|
|
|
else
|
|
|
|
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
|