2003-08-19 13:00:56 +00:00
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
* \file InsetMathSubstack.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-14 14:52:23 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "InsetMathSubstack.h"
|
2007-11-06 21:45:24 +00:00
|
|
|
|
2007-04-26 16:05:57 +00:00
|
|
|
#include "MathData.h"
|
2006-10-22 10:15:23 +00:00
|
|
|
#include "MathStream.h"
|
2002-02-14 14:52:23 +00:00
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "FuncRequest.h"
|
2005-04-03 12:07:49 +00:00
|
|
|
#include "FuncStatus.h"
|
2016-06-04 08:41:13 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
|
|
|
#include "MetricsInfo.h"
|
2005-04-03 12:07:49 +00:00
|
|
|
|
2016-06-04 08:41:13 +00:00
|
|
|
#include "support/gettext.h"
|
2005-04-03 12:07:49 +00:00
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
2008-05-06 10:36:32 +00:00
|
|
|
#include <ostream>
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
using support::bformat;
|
|
|
|
|
2002-02-14 14:52:23 +00:00
|
|
|
|
2009-11-08 11:45:46 +00:00
|
|
|
InsetMathSubstack::InsetMathSubstack(Buffer * buf)
|
|
|
|
: InsetMathGrid(buf, 1, 1)
|
2002-02-14 14:52:23 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
Inset * InsetMathSubstack::clone() const
|
2002-02-14 14:52:23 +00:00
|
|
|
{
|
2007-08-30 18:03:17 +00:00
|
|
|
return new InsetMathSubstack(*this);
|
2002-02-14 14:52:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
void InsetMathSubstack::metrics(MetricsInfo & mi, Dimension & dim) const
|
2002-02-14 14:52:23 +00:00
|
|
|
{
|
2016-11-22 10:26:15 +00:00
|
|
|
Changer dummy2 = mi.base.changeEnsureMath();
|
2016-11-20 18:53:16 +00:00
|
|
|
Changer dummy = mi.base.changeArray();
|
2016-05-23 21:30:23 +00:00
|
|
|
InsetMathGrid::metrics(mi, dim);
|
2003-05-14 16:29:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathSubstack::draw(PainterInfo & pi, int x, int y) const
|
2003-05-14 16:29:25 +00:00
|
|
|
{
|
2016-11-22 10:26:15 +00:00
|
|
|
Changer dummy2 = pi.base.changeEnsureMath();
|
2016-11-20 18:53:16 +00:00
|
|
|
Changer dummy = pi.base.changeArray();
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::draw(pi, x + 1, y);
|
2003-05-14 16:29:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
bool InsetMathSubstack::getStatus(Cursor & cur, FuncRequest const & cmd,
|
2005-04-03 12:07:49 +00:00
|
|
|
FuncStatus & flag) const
|
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2015-12-11 02:15:52 +00:00
|
|
|
case LFUN_TABULAR_FEATURE: {
|
|
|
|
string s = cmd.getArg(0);
|
2005-04-03 12:07:49 +00:00
|
|
|
if (s == "add-vline-left" || s == "add-vline-right") {
|
|
|
|
flag.message(bformat(
|
2007-08-30 18:03:17 +00:00
|
|
|
from_utf8(N_("Can't add vertical grid lines in '%1$s'")),
|
2015-12-11 02:15:52 +00:00
|
|
|
from_utf8("substack")));
|
2008-05-29 15:14:00 +00:00
|
|
|
flag.setEnabled(false);
|
2005-04-03 12:07:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-12-11 02:15:52 +00:00
|
|
|
// in contrary to \subarray, the columns in \substack
|
2010-11-29 03:18:02 +00:00
|
|
|
// are always centered and this cannot be changed
|
|
|
|
if (s == "align-left" || s == "align-right") {
|
|
|
|
flag.message(bformat(
|
|
|
|
from_utf8(N_("Can't change horizontal alignment in '%1$s'")),
|
2015-12-11 02:15:52 +00:00
|
|
|
from_utf8("substack")));
|
2010-11-29 03:18:02 +00:00
|
|
|
flag.setEnabled(false);
|
|
|
|
return true;
|
|
|
|
}
|
2010-02-18 08:28:46 +00:00
|
|
|
break;
|
2005-04-03 12:07:49 +00:00
|
|
|
}
|
2010-11-29 03:18:02 +00:00
|
|
|
|
2005-04-03 12:07:49 +00:00
|
|
|
default:
|
2010-02-18 08:28:46 +00:00
|
|
|
break;
|
2005-04-03 12:07:49 +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-10-22 10:15:23 +00:00
|
|
|
void InsetMathSubstack::infoize(odocstream & os) const
|
2003-05-14 16:29:25 +00:00
|
|
|
{
|
|
|
|
os << "Substack ";
|
2002-02-14 14:52:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathSubstack::write(WriteStream & os) const
|
2002-02-14 14:52:23 +00:00
|
|
|
{
|
2008-06-17 11:10:43 +00:00
|
|
|
MathEnsurer ensurer(os);
|
2002-02-14 14:52:23 +00:00
|
|
|
os << "\\substack{";
|
2015-10-07 03:13:21 +00:00
|
|
|
bool open = os.startOuterRow();
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::write(os);
|
2002-02-14 14:52:23 +00:00
|
|
|
os << "}\n";
|
2015-10-07 03:13:21 +00:00
|
|
|
if (open)
|
|
|
|
os.startOuterRow();
|
2002-02-14 14:52:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathSubstack::normalize(NormalStream & os) const
|
2002-02-14 14:52:23 +00:00
|
|
|
{
|
|
|
|
os << "[substack ";
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::normalize(os);
|
2002-11-27 10:30:28 +00:00
|
|
|
os << ']';
|
2002-02-14 14:52:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathSubstack::maple(MapleStream & os) const
|
2002-02-14 14:52:23 +00:00
|
|
|
{
|
|
|
|
os << "substack(";
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::maple(os);
|
2002-11-27 10:30:28 +00:00
|
|
|
os << ')';
|
2002-02-14 14:52:23 +00:00
|
|
|
}
|
2005-03-30 09:05:30 +00:00
|
|
|
|
|
|
|
|
2011-04-01 23:41:17 +00:00
|
|
|
void InsetMathSubstack::mathmlize(MathStream & os) const
|
|
|
|
{
|
|
|
|
int movers = 0;
|
|
|
|
row_type const numrows = nrows();
|
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
|
|
|
if (row < numrows - 1) {
|
|
|
|
movers ++;
|
|
|
|
os << MTag("munder");
|
|
|
|
}
|
|
|
|
os << MTag("mrow") << cell(index(row, 0)) << ETag("mrow");
|
|
|
|
}
|
|
|
|
for (int i = 1; i <= movers; ++i)
|
|
|
|
os << ETag("munder");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-31 21:17:30 +00:00
|
|
|
void InsetMathSubstack::htmlize(HtmlStream & os) const
|
|
|
|
{
|
|
|
|
os << MTag("span", "class='substack'");
|
2011-04-01 23:41:17 +00:00
|
|
|
for (row_type row = 0; row < nrows(); ++row)
|
2010-03-31 21:17:30 +00:00
|
|
|
os << MTag("span") << cell(index(row, 0)) << ETag("span");
|
|
|
|
os << ETag("span");
|
|
|
|
}
|
|
|
|
|
2011-04-01 23:41:17 +00:00
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathSubstack::validate(LaTeXFeatures & features) const
|
2005-03-30 09:05:30 +00:00
|
|
|
{
|
2010-03-31 21:17:30 +00:00
|
|
|
if (features.runparams().isLaTeX())
|
|
|
|
features.require("amsmath");
|
|
|
|
else if (features.runparams().math_flavor == OutputParams::MathAsHTML)
|
2011-12-06 22:17:13 +00:00
|
|
|
features.addCSSSnippet(
|
2010-03-31 21:17:30 +00:00
|
|
|
"span.substack{display: inline-block; vertical-align: middle; text-align:center; font-size: 75%;}\n"
|
2011-12-06 22:17:13 +00:00
|
|
|
"span.substack span{display: block;}");
|
2011-04-01 23:41:17 +00:00
|
|
|
|
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
|