2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file math_scriptinset.C
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2003-08-02 11:30:30 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
#include "math_scriptinset.h"
|
2003-09-07 21:25:37 +00:00
|
|
|
|
#include "math_data.h"
|
|
|
|
|
#include "math_mathmlstream.h"
|
2001-11-08 12:15:12 +00:00
|
|
|
|
#include "math_support.h"
|
2001-11-27 13:57:49 +00:00
|
|
|
|
#include "math_symbolinset.h"
|
2003-10-29 10:47:21 +00:00
|
|
|
|
#include "dispatchresult.h"
|
2004-01-20 14:25:24 +00:00
|
|
|
|
#include "cursor.h"
|
2003-09-07 21:25:37 +00:00
|
|
|
|
#include "debug.h"
|
2002-08-28 17:59:32 +00:00
|
|
|
|
#include "funcrequest.h"
|
2003-10-06 15:43:21 +00:00
|
|
|
|
|
2003-09-16 09:01:15 +00:00
|
|
|
|
#include <boost/assert.hpp>
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2002-02-16 15:59:55 +00:00
|
|
|
|
using std::max;
|
2003-07-25 17:11:25 +00:00
|
|
|
|
using std::auto_ptr;
|
2003-08-02 11:30:30 +00:00
|
|
|
|
using std::endl;
|
2002-02-16 15:59:55 +00:00
|
|
|
|
|
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
|
MathScriptInset::MathScriptInset()
|
2004-03-25 09:16:36 +00:00
|
|
|
|
: MathNestInset(1), cell_1_is_up_(false), limits_(0)
|
|
|
|
|
{}
|
2001-10-12 12:02:49 +00:00
|
|
|
|
|
|
|
|
|
|
2001-09-11 10:58:17 +00:00
|
|
|
|
MathScriptInset::MathScriptInset(bool up)
|
2004-03-25 09:16:36 +00:00
|
|
|
|
: MathNestInset(2), cell_1_is_up_(up), limits_(0)
|
|
|
|
|
{}
|
2001-10-12 12:02:49 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
|
MathScriptInset::MathScriptInset(MathAtom const & at, bool up)
|
2004-03-25 09:16:36 +00:00
|
|
|
|
: MathNestInset(2), cell_1_is_up_(up), limits_(0)
|
2002-07-30 13:56:02 +00:00
|
|
|
|
{
|
2004-04-05 10:37:16 +00:00
|
|
|
|
BOOST_ASSERT(nargs() >= 1);
|
2004-03-25 09:16:36 +00:00
|
|
|
|
cell(0).push_back(at);
|
2002-07-30 13:56:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-07-25 17:11:25 +00:00
|
|
|
|
auto_ptr<InsetBase> MathScriptInset::clone() const
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2003-07-25 17:11:25 +00:00
|
|
|
|
return auto_ptr<InsetBase>(new MathScriptInset(*this));
|
2001-07-26 06:46:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-09-24 16:25:06 +00:00
|
|
|
|
MathScriptInset const * MathScriptInset::asScriptInset() const
|
|
|
|
|
{
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
|
|
|
|
|
|
MathScriptInset * MathScriptInset::asScriptInset()
|
2001-07-26 06:46:50 +00:00
|
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
|
return this;
|
2001-07-26 06:46:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-16 12:36:23 +00:00
|
|
|
|
bool MathScriptInset::idxFirst(LCursor & cur) const
|
2001-07-26 06:46:50 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
cur.idx() = 0;
|
2004-01-15 17:34:44 +00:00
|
|
|
|
cur.pos() = 0;
|
2002-07-30 13:56:02 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-16 12:36:23 +00:00
|
|
|
|
bool MathScriptInset::idxLast(LCursor & cur) const
|
2002-07-30 13:56:02 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
cur.idx() = 0;
|
2004-01-15 17:34:44 +00:00
|
|
|
|
cur.pos() = nuc().size();
|
2002-07-30 13:56:02 +00:00
|
|
|
|
return true;
|
2001-07-26 06:46:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-02 14:29:42 +00:00
|
|
|
|
MathArray const & MathScriptInset::down() const
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
2004-04-05 10:37:16 +00:00
|
|
|
|
if (nargs() == 3)
|
|
|
|
|
return cell(2);
|
|
|
|
|
BOOST_ASSERT(nargs() > 1);
|
|
|
|
|
return cell(1);
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-02 14:29:42 +00:00
|
|
|
|
MathArray & MathScriptInset::down()
|
2002-07-30 13:56:02 +00:00
|
|
|
|
{
|
2004-04-05 10:37:16 +00:00
|
|
|
|
if (nargs() == 3)
|
|
|
|
|
return cell(2);
|
|
|
|
|
BOOST_ASSERT(nargs() > 1);
|
|
|
|
|
return cell(1);
|
2002-07-30 13:56:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-02 14:29:42 +00:00
|
|
|
|
MathArray const & MathScriptInset::up() const
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
2004-04-05 10:37:16 +00:00
|
|
|
|
BOOST_ASSERT(nargs() > 1);
|
2002-08-02 14:29:42 +00:00
|
|
|
|
return cell(1);
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-02 14:29:42 +00:00
|
|
|
|
MathArray & MathScriptInset::up()
|
2001-09-11 10:58:17 +00:00
|
|
|
|
{
|
2004-04-05 10:37:16 +00:00
|
|
|
|
BOOST_ASSERT(nargs() > 1);
|
2002-08-02 14:29:42 +00:00
|
|
|
|
return cell(1);
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathScriptInset::ensure(bool up)
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (nargs() == 1) {
|
|
|
|
|
// just nucleus so far
|
|
|
|
|
cells_.push_back(MathArray());
|
|
|
|
|
cell_1_is_up_ = up;
|
2004-04-03 08:37:12 +00:00
|
|
|
|
} else if (nargs() == 2 && !has(up)) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (up) {
|
|
|
|
|
cells_.push_back(cell(1));
|
|
|
|
|
cell(1).clear();
|
|
|
|
|
} else {
|
|
|
|
|
cells_.push_back(MathArray());
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-02 14:29:42 +00:00
|
|
|
|
MathArray const & MathScriptInset::nuc() const
|
2002-07-30 13:56:02 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return cell(0);
|
2002-07-30 13:56:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-02 14:29:42 +00:00
|
|
|
|
MathArray & MathScriptInset::nuc()
|
2002-07-30 13:56:02 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return cell(0);
|
2002-07-30 13:56:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int MathScriptInset::dy0() const
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
2002-07-30 13:56:02 +00:00
|
|
|
|
int nd = ndes();
|
2001-10-12 12:02:49 +00:00
|
|
|
|
if (!hasDown())
|
|
|
|
|
return nd;
|
|
|
|
|
int des = down().ascent();
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (hasLimits())
|
2001-10-12 12:02:49 +00:00
|
|
|
|
des += nd + 2;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
else
|
2002-02-16 15:59:55 +00:00
|
|
|
|
des = max(des, nd);
|
2001-10-12 12:02:49 +00:00
|
|
|
|
return des;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
|
int MathScriptInset::dy1() const
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
2002-07-30 13:56:02 +00:00
|
|
|
|
int na = nasc();
|
2001-10-12 12:02:49 +00:00
|
|
|
|
if (!hasUp())
|
|
|
|
|
return na;
|
|
|
|
|
int asc = up().descent();
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (hasLimits())
|
2001-10-12 12:02:49 +00:00
|
|
|
|
asc += na + 2;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
else
|
2002-02-16 15:59:55 +00:00
|
|
|
|
asc = max(asc, na);
|
2002-08-02 14:04:16 +00:00
|
|
|
|
asc = max(asc, 5);
|
2001-10-12 12:02:49 +00:00
|
|
|
|
return asc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
|
int MathScriptInset::dx0() const
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(hasDown());
|
2003-05-27 13:55:03 +00:00
|
|
|
|
return hasLimits() ? (dim_.wid - down().width()) / 2 : nwid();
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
|
int MathScriptInset::dx1() const
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(hasUp());
|
2003-05-27 13:55:03 +00:00
|
|
|
|
return hasLimits() ? (dim_.wid - up().width()) / 2 : nwid();
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
|
int MathScriptInset::dxx() const
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
2003-05-27 13:55:03 +00:00
|
|
|
|
return hasLimits() ? (dim_.wid - nwid()) / 2 : 0;
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
|
int MathScriptInset::nwid() const
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
2002-08-02 14:04:16 +00:00
|
|
|
|
return nuc().size() ? nuc().width() : 2;
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
|
int MathScriptInset::nasc() const
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
2002-08-02 14:04:16 +00:00
|
|
|
|
return nuc().size() ? nuc().ascent() : 5;
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
|
int MathScriptInset::ndes() const
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
2002-08-02 14:04:16 +00:00
|
|
|
|
return nuc().size() ? nuc().descent() : 0;
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-02 10:03:27 +00:00
|
|
|
|
void MathScriptInset::metrics(MetricsInfo & mi, Dimension & dim) const
|
2002-03-21 17:42:56 +00:00
|
|
|
|
{
|
2002-08-05 16:21:19 +00:00
|
|
|
|
cell(0).metrics(mi);
|
2004-03-25 09:16:36 +00:00
|
|
|
|
ScriptChanger dummy(mi.base);
|
|
|
|
|
if (nargs() > 1)
|
|
|
|
|
cell(1).metrics(mi);
|
|
|
|
|
if (nargs() > 2)
|
|
|
|
|
cell(2).metrics(mi);
|
2004-01-30 11:41:12 +00:00
|
|
|
|
dim.wid = 0;
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (hasLimits()) {
|
2004-01-30 11:41:12 +00:00
|
|
|
|
dim.wid = nwid();
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (hasUp())
|
2004-01-30 11:41:12 +00:00
|
|
|
|
dim.wid = max(dim.wid, up().width());
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (hasDown())
|
2004-01-30 11:41:12 +00:00
|
|
|
|
dim.wid = max(dim.wid, down().width());
|
2002-07-30 13:56:02 +00:00
|
|
|
|
} else {
|
|
|
|
|
if (hasUp())
|
2004-01-30 11:41:12 +00:00
|
|
|
|
dim.wid = max(dim.wid, up().width());
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (hasDown())
|
2004-01-30 11:41:12 +00:00
|
|
|
|
dim.wid = max(dim.wid, down().width());
|
|
|
|
|
dim.wid += nwid();
|
2002-07-30 13:56:02 +00:00
|
|
|
|
}
|
2004-01-30 11:41:12 +00:00
|
|
|
|
dim.asc = dy1() + (hasUp() ? up().ascent() : 0);
|
|
|
|
|
dim.des = dy0() + (hasDown() ? down().descent() : 0);
|
|
|
|
|
metricsMarkers(dim);
|
|
|
|
|
dim_ = dim;
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-21 14:20:48 +00:00
|
|
|
|
void MathScriptInset::draw(PainterInfo & pi, int x, int y) const
|
2002-03-21 17:42:56 +00:00
|
|
|
|
{
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (nuc().size())
|
|
|
|
|
nuc().draw(pi, x + dxx(), y);
|
2002-09-11 08:26:02 +00:00
|
|
|
|
else {
|
|
|
|
|
nuc().setXY(x + dxx(), y);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
if (editing(pi.base.bv))
|
2002-09-11 08:26:02 +00:00
|
|
|
|
drawStr(pi, pi.base.font, x + dxx(), y, ".");
|
|
|
|
|
}
|
2003-03-21 14:20:48 +00:00
|
|
|
|
ScriptChanger dummy(pi.base);
|
2002-06-18 15:44:30 +00:00
|
|
|
|
if (hasUp())
|
2002-07-30 13:56:02 +00:00
|
|
|
|
up().draw(pi, x + dx1(), y - dy1());
|
2002-06-18 15:44:30 +00:00
|
|
|
|
if (hasDown())
|
2002-07-30 13:56:02 +00:00
|
|
|
|
down().draw(pi, x + dx0(), y + dy0());
|
2003-05-28 13:22:36 +00:00
|
|
|
|
drawMarkers(pi, x, y);
|
2002-06-18 15:44:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-05-28 13:22:36 +00:00
|
|
|
|
void MathScriptInset::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
|
2002-03-21 17:42:56 +00:00
|
|
|
|
{
|
2002-03-19 16:55:58 +00:00
|
|
|
|
if (hasUp())
|
2003-05-28 13:22:36 +00:00
|
|
|
|
up().metricsT(mi, dim);
|
2002-03-19 16:55:58 +00:00
|
|
|
|
if (hasDown())
|
2003-05-28 13:22:36 +00:00
|
|
|
|
down().metricsT(mi, dim);
|
|
|
|
|
nuc().metricsT(mi, dim);
|
2002-03-18 11:45:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-21 06:57:13 +00:00
|
|
|
|
void MathScriptInset::drawT(TextPainter & pain, int x, int y) const
|
2002-03-21 17:42:56 +00:00
|
|
|
|
{
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (nuc().size())
|
|
|
|
|
nuc().drawT(pain, x + dxx(), y);
|
2002-03-18 11:45:53 +00:00
|
|
|
|
if (hasUp())
|
2002-07-30 13:56:02 +00:00
|
|
|
|
up().drawT(pain, x + dx1(), y - dy1());
|
2002-03-18 11:45:53 +00:00
|
|
|
|
if (hasDown())
|
2002-07-30 13:56:02 +00:00
|
|
|
|
down().drawT(pain, x + dx0(), y + dy0());
|
2002-03-18 11:45:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
|
bool MathScriptInset::hasLimits() const
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
2002-07-08 13:03:37 +00:00
|
|
|
|
// obvious cases
|
2001-11-27 13:57:49 +00:00
|
|
|
|
if (limits_ == 1)
|
|
|
|
|
return true;
|
|
|
|
|
if (limits_ == -1)
|
|
|
|
|
return false;
|
|
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
|
// we can only display limits if the nucleus wants some
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (!nuc().size())
|
2001-11-27 13:57:49 +00:00
|
|
|
|
return false;
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (!nuc().back()->isScriptable())
|
2001-11-27 13:57:49 +00:00
|
|
|
|
return false;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
2001-11-27 13:57:49 +00:00
|
|
|
|
// per default \int has limits beside the \int even in displayed formulas
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (nuc().back()->asSymbolInset())
|
|
|
|
|
if (nuc().back()->asSymbolInset()->name().find("int") != string::npos)
|
2001-11-27 13:57:49 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// assume "real" limits for everything else
|
|
|
|
|
return true;
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathScriptInset::removeScript(bool up)
|
|
|
|
|
{
|
2004-08-13 15:06:46 +00:00
|
|
|
|
lyxerr << "MathScriptInset::removeScript: 1 up: " << up << endl;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (nargs() == 2) {
|
2004-08-13 15:06:46 +00:00
|
|
|
|
lyxerr << "MathScriptInset::removeScript: a up: " << up << endl;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (up == cell_1_is_up_)
|
|
|
|
|
cells_.pop_back();
|
2004-08-13 15:06:46 +00:00
|
|
|
|
lyxerr << "MathScriptInset::removeScript: b up: " << up << endl;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
} else if (nargs() == 3) {
|
|
|
|
|
if (up == true) {
|
|
|
|
|
swap(cells_[1], cells_[2]);
|
|
|
|
|
cell_1_is_up_ = false;
|
|
|
|
|
} else {
|
|
|
|
|
cell_1_is_up_ = true;
|
|
|
|
|
}
|
2004-04-05 16:31:52 +00:00
|
|
|
|
cells_.pop_back();
|
2004-03-25 09:16:36 +00:00
|
|
|
|
}
|
2004-08-13 15:06:46 +00:00
|
|
|
|
lyxerr << "MathScriptInset::removeScript: 2 up: " << up << endl;
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool MathScriptInset::has(bool up) const
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return idxOfScript(up);
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool MathScriptInset::hasUp() const
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
//lyxerr << "1up: " << bool(cell_1_is_up_) << endl;
|
2004-04-05 16:31:52 +00:00
|
|
|
|
//lyxerr << "hasUp: " << bool(idxOfScript(true)) << endl;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return idxOfScript(true);
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool MathScriptInset::hasDown() const
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
//lyxerr << "1up: " << bool(cell_1_is_up_) << endl;
|
2004-04-05 16:31:52 +00:00
|
|
|
|
//lyxerr << "hasDown: " << bool(idxOfScript(false)) << endl;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return idxOfScript(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InsetBase::idx_type MathScriptInset::idxOfScript(bool up) const
|
|
|
|
|
{
|
|
|
|
|
if (nargs() == 1)
|
|
|
|
|
return 0;
|
|
|
|
|
if (nargs() == 2)
|
2004-04-05 16:31:52 +00:00
|
|
|
|
return (cell_1_is_up_ == up) ? 1 : 0;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (nargs() == 3)
|
|
|
|
|
return up ? 1 : 2;
|
|
|
|
|
BOOST_ASSERT(false);
|
2004-03-27 01:18:51 +00:00
|
|
|
|
// Silence compiler
|
|
|
|
|
return 0;
|
2001-07-26 06:46:50 +00:00
|
|
|
|
}
|
2001-10-12 15:38:58 +00:00
|
|
|
|
|
|
|
|
|
|
2004-01-16 12:36:23 +00:00
|
|
|
|
bool MathScriptInset::idxRight(LCursor &) const
|
2001-10-12 15:38:58 +00:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-16 12:36:23 +00:00
|
|
|
|
bool MathScriptInset::idxLeft(LCursor &) const
|
2001-10-12 15:38:58 +00:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
bool MathScriptInset::idxUpDown(LCursor & cur, bool up) const
|
2002-03-21 17:42:56 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// in nucleus?
|
|
|
|
|
if (cur.idx() == 0) {
|
|
|
|
|
// don't go up/down if there is no cell in this direction
|
2002-08-09 08:14:18 +00:00
|
|
|
|
if (!has(up))
|
|
|
|
|
return false;
|
2003-02-10 15:45:56 +00:00
|
|
|
|
// go up/down only if in the last position
|
|
|
|
|
// or in the first position of something with displayed limits
|
2004-01-15 17:34:44 +00:00
|
|
|
|
if (cur.pos() == cur.lastpos() || (cur.pos() == 0 && hasLimits())) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
cur.idx() = idxOfScript(up);
|
2004-01-15 17:34:44 +00:00
|
|
|
|
cur.pos() = 0;
|
2003-02-10 15:45:56 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2002-08-09 08:14:18 +00:00
|
|
|
|
}
|
2004-03-25 09:16:36 +00:00
|
|
|
|
|
|
|
|
|
// Are we 'up'?
|
2004-04-05 16:31:52 +00:00
|
|
|
|
if (has(up) && cur.idx() == idxOfScript(true)) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// can't go further up
|
|
|
|
|
if (up)
|
|
|
|
|
return false;
|
|
|
|
|
// otherwise go to last position in the nucleus
|
|
|
|
|
cur.idx() = 0;
|
|
|
|
|
cur.pos() = cur.lastpos();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Are we 'down'?
|
2004-04-05 16:31:52 +00:00
|
|
|
|
if (has(up) && cur.idx() == idxOfScript(false)) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// can't go further down
|
|
|
|
|
if (!up)
|
|
|
|
|
return false;
|
|
|
|
|
// otherwise go to last position in the nucleus
|
|
|
|
|
cur.idx() = 0;
|
|
|
|
|
cur.pos() = cur.lastpos();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
2001-11-08 12:06:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
|
void MathScriptInset::write(WriteStream & os) const
|
2001-11-07 08:51:35 +00:00
|
|
|
|
{
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (nuc().size()) {
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << nuc();
|
2002-09-30 06:48:53 +00:00
|
|
|
|
//if (nuc().back()->takesLimits()) {
|
2001-11-08 12:06:56 +00:00
|
|
|
|
if (limits_ == -1)
|
|
|
|
|
os << "\\nolimits ";
|
|
|
|
|
if (limits_ == 1)
|
|
|
|
|
os << "\\limits ";
|
2002-09-30 06:48:53 +00:00
|
|
|
|
//}
|
2002-07-30 13:56:02 +00:00
|
|
|
|
} else {
|
|
|
|
|
if (os.firstitem())
|
2003-08-02 11:30:30 +00:00
|
|
|
|
lyxerr[Debug::MATHED] << "suppressing {} when writing"
|
|
|
|
|
<< endl;
|
2002-07-30 13:56:02 +00:00
|
|
|
|
else
|
|
|
|
|
os << "{}";
|
|
|
|
|
}
|
2001-11-08 12:06:56 +00:00
|
|
|
|
|
2002-07-31 17:26:14 +00:00
|
|
|
|
if (hasDown() && down().size())
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << "_{" << down() << '}';
|
2001-11-08 12:06:56 +00:00
|
|
|
|
|
2002-07-31 17:26:14 +00:00
|
|
|
|
if (hasUp() && up().size())
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << "^{" << up() << '}';
|
2002-08-01 15:53:46 +00:00
|
|
|
|
|
|
|
|
|
if (lock_ && !os.latex())
|
|
|
|
|
os << "\\lyxlock ";
|
2001-11-07 08:51:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-09 08:35:57 +00:00
|
|
|
|
void MathScriptInset::normalize(NormalStream & os) const
|
2002-03-21 17:42:56 +00:00
|
|
|
|
{
|
2002-07-30 13:56:02 +00:00
|
|
|
|
bool d = hasDown() && down().size();
|
|
|
|
|
bool u = hasUp() && up().size();
|
2001-11-08 12:06:56 +00:00
|
|
|
|
|
2002-07-30 17:51:19 +00:00
|
|
|
|
if (u && d)
|
|
|
|
|
os << "[subsup ";
|
|
|
|
|
else if (u)
|
2001-11-08 12:06:56 +00:00
|
|
|
|
os << "[sup ";
|
2002-07-30 17:51:19 +00:00
|
|
|
|
else if (d)
|
2001-11-08 12:06:56 +00:00
|
|
|
|
os << "[sub ";
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (nuc().size())
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << nuc() << ' ';
|
2001-11-08 12:06:56 +00:00
|
|
|
|
else
|
|
|
|
|
os << "[par]";
|
|
|
|
|
|
2002-07-30 17:51:19 +00:00
|
|
|
|
if (u && d)
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << down() << ' ' << up() << ']';
|
2002-07-30 17:51:19 +00:00
|
|
|
|
else if (d)
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << down() << ']';
|
2002-07-30 17:51:19 +00:00
|
|
|
|
else if (u)
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << up() << ']';
|
2001-11-08 12:06:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-02-14 14:30:09 +00:00
|
|
|
|
void MathScriptInset::maple(MapleStream & os) const
|
2001-11-07 08:51:35 +00:00
|
|
|
|
{
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (nuc().size())
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << nuc();
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (hasDown() && down().size())
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << '[' << down() << ']';
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (hasUp() && up().size())
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << "^(" << up() << ')';
|
2001-11-07 08:51:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-02-14 14:30:09 +00:00
|
|
|
|
void MathScriptInset::mathematica(MathematicaStream & os) const
|
2002-07-01 11:17:14 +00:00
|
|
|
|
{
|
2002-07-30 13:56:02 +00:00
|
|
|
|
bool d = hasDown() && down().size();
|
|
|
|
|
bool u = hasUp() && up().size();
|
2002-07-01 11:17:14 +00:00
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (nuc().size()) {
|
2002-11-27 10:30:28 +00:00
|
|
|
|
if (d)
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << "Subscript[" << nuc();
|
2002-07-01 11:17:14 +00:00
|
|
|
|
else
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << nuc();
|
2002-07-30 13:56:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-07-01 11:17:14 +00:00
|
|
|
|
if (u)
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << "^(" << up() << ')';
|
2002-07-01 11:17:14 +00:00
|
|
|
|
|
2004-02-02 17:32:56 +00:00
|
|
|
|
if (nuc().size()) {
|
2002-07-01 11:17:14 +00:00
|
|
|
|
if (d)
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << ',' << down() << ']';
|
2004-02-02 17:32:56 +00:00
|
|
|
|
}
|
2002-07-01 11:17:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-02 17:32:56 +00:00
|
|
|
|
void MathScriptInset::mathmlize(MathMLStream & os) const
|
2001-11-07 08:51:35 +00:00
|
|
|
|
{
|
2002-07-31 17:26:14 +00:00
|
|
|
|
bool d = hasDown() && down().size();
|
|
|
|
|
bool u = hasUp() && up().size();
|
2001-11-07 17:30:26 +00:00
|
|
|
|
|
2001-11-08 12:06:56 +00:00
|
|
|
|
if (u && d)
|
|
|
|
|
os << MTag("msubsup");
|
|
|
|
|
else if (u)
|
|
|
|
|
os << MTag("msup");
|
|
|
|
|
else if (d)
|
|
|
|
|
os << MTag("msub");
|
2001-11-07 17:30:26 +00:00
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (nuc().size())
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << nuc();
|
2001-11-07 17:30:26 +00:00
|
|
|
|
else
|
|
|
|
|
os << "<mrow/>";
|
|
|
|
|
|
2001-11-08 12:06:56 +00:00
|
|
|
|
if (u && d)
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << down() << up() << ETag("msubsup");
|
2001-11-08 12:06:56 +00:00
|
|
|
|
else if (u)
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << up() << ETag("msup");
|
2001-11-08 12:06:56 +00:00
|
|
|
|
else if (d)
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << down() << ETag("msub");
|
2001-11-08 12:06:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-07 17:30:26 +00:00
|
|
|
|
|
2003-02-14 14:30:09 +00:00
|
|
|
|
void MathScriptInset::octave(OctaveStream & os) const
|
2001-11-08 12:06:56 +00:00
|
|
|
|
{
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (nuc().size())
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << nuc();
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (hasDown() && down().size())
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << '[' << down() << ']';
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (hasUp() && up().size())
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << "^(" << up() << ')';
|
2001-11-07 08:51:35 +00:00
|
|
|
|
}
|
2002-07-08 13:03:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathScriptInset::infoize(std::ostream & os) const
|
|
|
|
|
{
|
2002-08-01 11:48:53 +00:00
|
|
|
|
os << "Scripts";
|
2003-01-07 11:24:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathScriptInset::infoize2(std::ostream & os) const
|
|
|
|
|
{
|
2002-07-08 13:03:37 +00:00
|
|
|
|
if (limits_)
|
2002-08-01 11:48:53 +00:00
|
|
|
|
os << (limits_ == 1 ? ", Displayed limits" : ", Inlined limits");
|
2002-07-08 13:03:37 +00:00
|
|
|
|
}
|
2002-08-28 17:59:32 +00:00
|
|
|
|
|
|
|
|
|
|
2004-04-05 16:31:52 +00:00
|
|
|
|
void MathScriptInset::notifyCursorLeaves(LCursor & cur)
|
2002-10-29 08:23:32 +00:00
|
|
|
|
{
|
2004-04-05 16:31:52 +00:00
|
|
|
|
MathNestInset::notifyCursorLeaves(cur);
|
2002-10-29 08:23:32 +00:00
|
|
|
|
|
2004-08-13 15:06:46 +00:00
|
|
|
|
lyxerr << "MathScriptInset::notifyCursorLeaves: 1 " << cur << endl;
|
|
|
|
|
|
2002-10-29 08:23:32 +00:00
|
|
|
|
// remove empty scripts if possible
|
2004-08-13 19:19:24 +00:00
|
|
|
|
if (1) {
|
2004-04-05 16:36:03 +00:00
|
|
|
|
if (nargs() > 2 && cur.idx() == 2 && cell(2).empty()) {
|
2004-04-05 16:31:52 +00:00
|
|
|
|
// must be a subscript...
|
|
|
|
|
removeScript(false);
|
2004-04-05 16:36:03 +00:00
|
|
|
|
} else if (nargs() > 1 && cur.idx() == 1 && cell(1).empty()) {
|
2004-04-05 16:31:52 +00:00
|
|
|
|
// could be either subscript or super script
|
|
|
|
|
removeScript(cell_1_is_up_);
|
2002-10-29 08:23:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-13 15:06:46 +00:00
|
|
|
|
lyxerr << "MathScriptInset::notifyCursorLeaves: 2 " << cur << endl;
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-29 08:23:32 +00:00
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
void MathScriptInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
|
2002-08-28 17:59:32 +00:00
|
|
|
|
{
|
2004-02-16 11:58:51 +00:00
|
|
|
|
//lyxerr << "MathScriptInset: request: " << cmd << std::endl;
|
2004-02-11 14:45:44 +00:00
|
|
|
|
|
2002-08-28 17:59:32 +00:00
|
|
|
|
if (cmd.action == LFUN_MATH_LIMITS) {
|
2002-10-28 10:47:24 +00:00
|
|
|
|
if (!cmd.argument.empty()) {
|
|
|
|
|
if (cmd.argument == "limits")
|
|
|
|
|
limits_ = 1;
|
|
|
|
|
else if (cmd.argument == "nolimits")
|
|
|
|
|
limits_ = -1;
|
|
|
|
|
else
|
|
|
|
|
limits_ = 0;
|
|
|
|
|
} else if (limits_ == 0)
|
2004-01-07 08:36:30 +00:00
|
|
|
|
limits_ = hasLimits() ? -1 : 1;
|
2002-10-28 10:47:24 +00:00
|
|
|
|
else
|
|
|
|
|
limits_ = 0;
|
2004-02-16 11:58:51 +00:00
|
|
|
|
return;
|
2002-08-28 17:59:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-02-16 11:58:51 +00:00
|
|
|
|
MathNestInset::priv_dispatch(cur, cmd);
|
2002-08-28 17:59:32 +00:00
|
|
|
|
}
|