2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
|
* \file InsetMathScript.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.
|
|
|
|
|
*/
|
|
|
|
|
|
2003-08-02 11:30:30 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "InsetMathScript.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"
|
|
|
|
|
#include "InsetMathSymbol.h"
|
2007-03-23 02:12:48 +00:00
|
|
|
|
#include "InsetMathFont.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "DispatchResult.h"
|
2007-04-26 14:56:30 +00:00
|
|
|
|
#include "Cursor.h"
|
2003-09-07 21:25:37 +00:00
|
|
|
|
#include "debug.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "FuncRequest.h"
|
|
|
|
|
#include "Undo.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
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
2006-08-13 22:54:59 +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-08-02 11:30:30 +00:00
|
|
|
|
using std::endl;
|
2002-02-16 15:59:55 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathScript::InsetMathScript()
|
|
|
|
|
: InsetMathNest(1), cell_1_is_up_(false), limits_(0)
|
2004-03-25 09:16:36 +00:00
|
|
|
|
{}
|
2001-10-12 12:02:49 +00:00
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathScript::InsetMathScript(bool up)
|
|
|
|
|
: InsetMathNest(2), cell_1_is_up_(up), limits_(0)
|
2004-03-25 09:16:36 +00:00
|
|
|
|
{}
|
2001-10-12 12:02:49 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathScript::InsetMathScript(MathAtom const & at, bool up)
|
|
|
|
|
: InsetMathNest(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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
|
Inset * InsetMathScript::clone() const
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2007-08-30 18:03:17 +00:00
|
|
|
|
return new InsetMathScript(*this);
|
2001-07-26 06:46:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathScript const * InsetMathScript::asScriptInset() const
|
2001-09-24 16:25:06 +00:00
|
|
|
|
{
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathScript * InsetMathScript::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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool InsetMathScript::idxFirst(Cursor & 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool InsetMathScript::idxLast(Cursor & 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData const & InsetMathScript::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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData & InsetMathScript::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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData const & InsetMathScript::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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData & InsetMathScript::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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathScript::ensure(bool up)
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (nargs() == 1) {
|
|
|
|
|
// just nucleus so far
|
2007-04-26 16:05:57 +00:00
|
|
|
|
cells_.push_back(MathData());
|
2004-03-25 09:16:36 +00:00
|
|
|
|
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 {
|
2007-04-26 16:05:57 +00:00
|
|
|
|
cells_.push_back(MathData());
|
2004-03-25 09:16:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData const & InsetMathScript::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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData & InsetMathScript::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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-03-23 02:12:48 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
bool isAlphaSymbol(MathAtom const & at)
|
|
|
|
|
{
|
|
|
|
|
if (at->asCharInset() ||
|
|
|
|
|
(at->asSymbolInset() &&
|
|
|
|
|
at->asSymbolInset()->isOrdAlpha()))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (at->asFontInset()) {
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData const & ar = at->asFontInset()->cell(0);
|
2007-03-23 02:12:48 +00:00
|
|
|
|
for (size_t i = 0; i < ar.size(); ++i) {
|
|
|
|
|
if (!(ar[i]->asCharInset() ||
|
|
|
|
|
(ar[i]->asSymbolInset() &&
|
|
|
|
|
ar[i]->asSymbolInset()->isOrdAlpha())))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
2007-09-24 13:52:04 +00:00
|
|
|
|
int InsetMathScript::dy01(BufferView const & bv, int asc, int des, int what) const
|
2007-03-18 15:00:57 +00:00
|
|
|
|
{
|
|
|
|
|
int dasc = 0;
|
|
|
|
|
int slevel = 0;
|
2007-03-23 02:12:48 +00:00
|
|
|
|
bool isCharBox = nuc().size() ? isAlphaSymbol(nuc().back()) : false;
|
2007-03-18 15:00:57 +00:00
|
|
|
|
if (hasDown()) {
|
2007-09-24 13:52:04 +00:00
|
|
|
|
Dimension const & dimdown = down().dimension(bv);
|
|
|
|
|
dasc = dimdown.ascent();
|
2007-03-18 15:00:57 +00:00
|
|
|
|
slevel = nuc().slevel();
|
|
|
|
|
int ascdrop = dasc - slevel;
|
2007-03-23 02:12:48 +00:00
|
|
|
|
int desdrop = isCharBox ? 0 : des + nuc().sshift();
|
2007-03-18 15:00:57 +00:00
|
|
|
|
int mindes = nuc().mindes();
|
|
|
|
|
des = max(desdrop, ascdrop);
|
|
|
|
|
des = max(mindes, des);
|
|
|
|
|
}
|
|
|
|
|
if (hasUp()) {
|
2007-09-24 13:52:04 +00:00
|
|
|
|
Dimension const & dimup = up().dimension(bv);
|
2007-03-18 15:00:57 +00:00
|
|
|
|
int minasc = nuc().minasc();
|
2007-03-23 02:12:48 +00:00
|
|
|
|
int ascdrop = isCharBox ? 0 : asc - up().mindes();
|
2007-09-24 13:52:04 +00:00
|
|
|
|
int udes = dimup.descent();
|
2007-03-18 15:00:57 +00:00
|
|
|
|
asc = udes + nuc().sshift();
|
|
|
|
|
asc = max(ascdrop, asc);
|
|
|
|
|
asc = max(minasc, asc);
|
|
|
|
|
if (hasDown()) {
|
|
|
|
|
int del = asc - udes - dasc;
|
|
|
|
|
if (del + des <= 2) {
|
2007-03-28 00:02:15 +00:00
|
|
|
|
int newdes = 2 - del;
|
2007-03-18 15:00:57 +00:00
|
|
|
|
del = slevel - asc + udes;
|
|
|
|
|
if (del > 0) {
|
|
|
|
|
asc += del;
|
2007-03-28 00:02:15 +00:00
|
|
|
|
newdes -= del;
|
2007-03-18 15:00:57 +00:00
|
|
|
|
}
|
2007-03-28 00:02:15 +00:00
|
|
|
|
des = max(des, newdes);
|
2007-03-18 15:00:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return what ? asc : des;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-24 13:52:04 +00:00
|
|
|
|
int InsetMathScript::dy0(BufferView const & bv) const
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
2007-09-24 13:52:04 +00:00
|
|
|
|
int nd = ndes(bv);
|
2001-10-12 12:02:49 +00:00
|
|
|
|
if (!hasDown())
|
|
|
|
|
return nd;
|
2007-09-24 13:52:04 +00:00
|
|
|
|
int des = down().dimension(bv).ascent();
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (hasLimits())
|
2001-10-12 12:02:49 +00:00
|
|
|
|
des += nd + 2;
|
2007-03-18 15:00:57 +00:00
|
|
|
|
else {
|
2007-09-24 13:52:04 +00:00
|
|
|
|
int na = nasc(bv);
|
|
|
|
|
des = dy01(bv, na, nd, 0);
|
2007-03-18 15:00:57 +00:00
|
|
|
|
}
|
2001-10-12 12:02:49 +00:00
|
|
|
|
return des;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-24 13:52:04 +00:00
|
|
|
|
int InsetMathScript::dy1(BufferView const & bv) const
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
2007-09-24 13:52:04 +00:00
|
|
|
|
int na = nasc(bv);
|
2001-10-12 12:02:49 +00:00
|
|
|
|
if (!hasUp())
|
|
|
|
|
return na;
|
2007-09-24 13:52:04 +00:00
|
|
|
|
int asc = up().dimension(bv).descent();
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (hasLimits())
|
2001-10-12 12:02:49 +00:00
|
|
|
|
asc += na + 2;
|
2007-03-18 15:00:57 +00:00
|
|
|
|
else {
|
2007-09-24 13:52:04 +00:00
|
|
|
|
int nd = ndes(bv);
|
|
|
|
|
asc = dy01(bv, na, nd, 1);
|
2007-03-18 15:00:57 +00:00
|
|
|
|
}
|
2002-08-02 14:04:16 +00:00
|
|
|
|
asc = max(asc, 5);
|
2001-10-12 12:02:49 +00:00
|
|
|
|
return asc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-23 22:39:49 +00:00
|
|
|
|
int InsetMathScript::dx0(BufferView const & bv) const
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(hasDown());
|
2007-09-23 22:39:49 +00:00
|
|
|
|
Dimension const dim = dimension(bv);
|
2007-09-24 13:52:04 +00:00
|
|
|
|
return hasLimits() ? (dim.wid - down().dimension(bv).width()) / 2 : nwid(bv);
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-23 22:39:49 +00:00
|
|
|
|
int InsetMathScript::dx1(BufferView const & bv) const
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(hasUp());
|
2007-09-23 22:39:49 +00:00
|
|
|
|
Dimension const dim = dimension(bv);
|
2007-09-24 13:52:04 +00:00
|
|
|
|
return hasLimits() ? (dim.wid - up().dimension(bv).width()) / 2 : nwid(bv) + nker();
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-23 22:39:49 +00:00
|
|
|
|
int InsetMathScript::dxx(BufferView const & bv) const
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
2007-09-23 22:39:49 +00:00
|
|
|
|
Dimension const dim = dimension(bv);
|
2007-09-24 13:52:04 +00:00
|
|
|
|
return hasLimits() ? (dim.wid - nwid(bv)) / 2 : 0;
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-24 13:52:04 +00:00
|
|
|
|
int InsetMathScript::nwid(BufferView const & bv) const
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
2007-09-24 13:52:04 +00:00
|
|
|
|
return nuc().size() ? nuc().dimension(bv).width() : 2;
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-24 13:52:04 +00:00
|
|
|
|
int InsetMathScript::nasc(BufferView const & bv) const
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
2007-09-24 13:52:04 +00:00
|
|
|
|
return nuc().size() ? nuc().dimension(bv).ascent() : 5;
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-24 13:52:04 +00:00
|
|
|
|
int InsetMathScript::ndes(BufferView const & bv) const
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
2007-09-24 13:52:04 +00:00
|
|
|
|
return nuc().size() ? nuc().dimension(bv).descent() : 0;
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-03-21 17:21:59 +00:00
|
|
|
|
int InsetMathScript::nker() const
|
|
|
|
|
{
|
|
|
|
|
if (nuc().size()) {
|
|
|
|
|
int kerning = nuc().kerning();
|
|
|
|
|
return kerning > 0 ? kerning : 0;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
|
void InsetMathScript::metrics(MetricsInfo & mi, Dimension & dim) const
|
2002-03-21 17:42:56 +00:00
|
|
|
|
{
|
2007-09-24 13:52:04 +00:00
|
|
|
|
Dimension dim0;
|
|
|
|
|
Dimension dim1;
|
|
|
|
|
Dimension dim2;
|
|
|
|
|
cell(0).metrics(mi, dim0);
|
2004-03-25 09:16:36 +00:00
|
|
|
|
ScriptChanger dummy(mi.base);
|
|
|
|
|
if (nargs() > 1)
|
2007-09-24 13:52:04 +00:00
|
|
|
|
cell(1).metrics(mi, dim1);
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (nargs() > 2)
|
2007-09-24 13:52:04 +00:00
|
|
|
|
cell(2).metrics(mi, dim2);
|
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
dim.wid = 0;
|
2007-09-24 13:52:04 +00:00
|
|
|
|
BufferView & bv = *mi.base.bv;
|
|
|
|
|
// FIXME: data copying... not very efficient.
|
|
|
|
|
Dimension dimup;
|
|
|
|
|
Dimension dimdown;
|
|
|
|
|
if (hasUp())
|
|
|
|
|
dimup = up().dimension(bv);
|
|
|
|
|
if (hasDown())
|
|
|
|
|
dimdown = down().dimension(bv);
|
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (hasLimits()) {
|
2007-09-24 13:52:04 +00:00
|
|
|
|
dim.wid = nwid(bv);
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (hasUp())
|
2007-09-24 13:52:04 +00:00
|
|
|
|
dim.wid = max(dim.wid, dimup.width());
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (hasDown())
|
2007-09-24 13:52:04 +00:00
|
|
|
|
dim.wid = max(dim.wid, dimdown.width());
|
2002-07-30 13:56:02 +00:00
|
|
|
|
} else {
|
|
|
|
|
if (hasUp())
|
2007-09-24 13:52:04 +00:00
|
|
|
|
dim.wid = max(dim.wid, nker() + dimup.width());
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (hasDown())
|
2007-09-24 13:52:04 +00:00
|
|
|
|
dim.wid = max(dim.wid, dimdown.width());
|
|
|
|
|
dim.wid += nwid(bv);
|
2002-07-30 13:56:02 +00:00
|
|
|
|
}
|
2007-09-24 13:52:04 +00:00
|
|
|
|
int na = nasc(bv);
|
2007-03-18 15:00:57 +00:00
|
|
|
|
if (hasUp()) {
|
2007-09-24 13:52:04 +00:00
|
|
|
|
int asc = dy1(bv) + dimup.ascent();
|
2007-03-18 15:00:57 +00:00
|
|
|
|
dim.asc = max(na, asc);
|
|
|
|
|
} else
|
|
|
|
|
dim.asc = na;
|
2007-09-24 13:52:04 +00:00
|
|
|
|
int nd = ndes(bv);
|
2007-03-18 15:00:57 +00:00
|
|
|
|
if (hasDown()) {
|
2007-09-24 13:52:04 +00:00
|
|
|
|
int des = dy0(bv) + dimdown.descent();
|
2007-03-18 15:00:57 +00:00
|
|
|
|
dim.des = max(nd, des);
|
|
|
|
|
} else
|
|
|
|
|
dim.des = nd;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
metricsMarkers(dim);
|
2007-09-23 22:39:49 +00:00
|
|
|
|
// Cache the inset dimension.
|
|
|
|
|
setDimCache(mi, dim);
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathScript::draw(PainterInfo & pi, int x, int y) const
|
2002-03-21 17:42:56 +00:00
|
|
|
|
{
|
2007-09-24 13:52:04 +00:00
|
|
|
|
BufferView & bv = *pi.base.bv;
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (nuc().size())
|
2007-09-24 13:52:04 +00:00
|
|
|
|
nuc().draw(pi, x + dxx(bv), y);
|
2002-09-11 08:26:02 +00:00
|
|
|
|
else {
|
2007-09-24 13:52:04 +00:00
|
|
|
|
nuc().setXY(bv, x + dxx(bv), y);
|
|
|
|
|
if (editing(&bv))
|
|
|
|
|
pi.draw(x + dxx(bv), y, char_type('.'));
|
2002-09-11 08:26:02 +00:00
|
|
|
|
}
|
2003-03-21 14:20:48 +00:00
|
|
|
|
ScriptChanger dummy(pi.base);
|
2002-06-18 15:44:30 +00:00
|
|
|
|
if (hasUp())
|
2007-09-24 13:52:04 +00:00
|
|
|
|
up().draw(pi, x + dx1(bv), y - dy1(bv));
|
2002-06-18 15:44:30 +00:00
|
|
|
|
if (hasDown())
|
2007-09-24 13:52:04 +00:00
|
|
|
|
down().draw(pi, x + dx0(bv), y + dy0(bv));
|
2003-05-28 13:22:36 +00:00
|
|
|
|
drawMarkers(pi, x, y);
|
2002-06-18 15:44:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathScript::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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathScript::drawT(TextPainter & pain, int x, int y) const
|
2002-03-21 17:42:56 +00:00
|
|
|
|
{
|
2007-09-24 13:52:04 +00:00
|
|
|
|
// FIXME: BROKEN
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (nuc().size())
|
2007-09-23 22:39:49 +00:00
|
|
|
|
nuc().drawT(pain, x + 1, y);
|
2002-03-18 11:45:53 +00:00
|
|
|
|
if (hasUp())
|
2007-09-24 13:52:04 +00:00
|
|
|
|
up().drawT(pain, x + 1, y - 1 /*dy1()*/);
|
2002-03-18 11:45:53 +00:00
|
|
|
|
if (hasDown())
|
2007-09-24 13:52:04 +00:00
|
|
|
|
down().drawT(pain, x + 1, y + 1 /*dy0()*/);
|
2002-03-18 11:45:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathScript::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
|
|
|
|
|
2006-06-26 15:01:35 +00:00
|
|
|
|
if (nuc().back()->asSymbolInset()) {
|
|
|
|
|
// \intop is an alias for \int\limits, \ointop == \oint\limits
|
2006-10-22 10:15:23 +00:00
|
|
|
|
if (nuc().back()->asSymbolInset()->name().find(from_ascii("intop")) != string::npos)
|
2006-06-26 15:01:35 +00:00
|
|
|
|
return true;
|
|
|
|
|
// per default \int has limits beside the \int even in displayed formulas
|
2006-10-22 10:15:23 +00:00
|
|
|
|
if (nuc().back()->asSymbolInset()->name().find(from_ascii("int")) != string::npos)
|
2001-11-27 13:57:49 +00:00
|
|
|
|
return false;
|
2006-06-26 15:01:35 +00:00
|
|
|
|
}
|
2001-11-27 13:57:49 +00:00
|
|
|
|
|
|
|
|
|
// assume "real" limits for everything else
|
|
|
|
|
return true;
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathScript::removeScript(bool up)
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (nargs() == 2) {
|
|
|
|
|
if (up == cell_1_is_up_)
|
|
|
|
|
cells_.pop_back();
|
|
|
|
|
} 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
|
|
|
|
}
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathScript::has(bool up) const
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return idxOfScript(up);
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathScript::hasUp() const
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathScript::hasDown() const
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
|
Inset::idx_type InsetMathScript::idxOfScript(bool up) const
|
2004-03-25 09:16:36 +00:00
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool InsetMathScript::idxRight(Cursor &) const
|
2001-10-12 15:38:58 +00:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool InsetMathScript::idxLeft(Cursor &) const
|
2001-10-12 15:38:58 +00:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool InsetMathScript::idxUpDown(Cursor & 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'?
|
2007-05-29 20:41:31 +00:00
|
|
|
|
if (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'?
|
2007-05-29 20:41:31 +00:00
|
|
|
|
if (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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathScript::write(WriteStream & os) const
|
2001-11-07 08:51:35 +00:00
|
|
|
|
{
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (nuc().size()) {
|
2006-11-11 15:26:31 +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())
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::MATHED) << "suppressing {} when writing"
|
2003-08-02 11:30:30 +00:00
|
|
|
|
<< endl;
|
2002-07-30 13:56:02 +00:00
|
|
|
|
else
|
|
|
|
|
os << "{}";
|
|
|
|
|
}
|
2001-11-08 12:06:56 +00:00
|
|
|
|
|
2006-08-17 21:07:24 +00:00
|
|
|
|
if (hasDown() /*&& down().size()*/)
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << "_{" << down() << '}';
|
2001-11-08 12:06:56 +00:00
|
|
|
|
|
2006-08-17 21:07:24 +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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathScript::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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathScript::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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathScript::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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
void InsetMathScript::mathmlize(MathStream & 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
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathScript::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
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
void InsetMathScript::infoize(odocstream & os) const
|
2002-07-08 13:03:37 +00:00
|
|
|
|
{
|
2002-08-01 11:48:53 +00:00
|
|
|
|
os << "Scripts";
|
2003-01-07 11:24:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
void InsetMathScript::infoize2(odocstream & os) const
|
2003-01-07 11:24:43 +00:00
|
|
|
|
{
|
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
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool InsetMathScript::notifyCursorLeaves(Cursor & cur)
|
2002-10-29 08:23:32 +00:00
|
|
|
|
{
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathNest::notifyCursorLeaves(cur);
|
2002-10-29 08:23:32 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
//lyxerr << "InsetMathScript::notifyCursorLeaves: 1 " << cur << endl;
|
2004-08-13 15:06:46 +00:00
|
|
|
|
|
2002-10-29 08:23:32 +00:00
|
|
|
|
// remove empty scripts if possible
|
2006-03-11 16:34:52 +00:00
|
|
|
|
if (nargs() > 2) {
|
|
|
|
|
// Case of two scripts. In this case, 1 = super, 2 = sub
|
|
|
|
|
if (cur.idx() == 2 && cell(2).empty()) {
|
|
|
|
|
// must be a subscript...
|
2006-08-17 21:07:24 +00:00
|
|
|
|
recordUndoInset(cur);
|
2006-03-11 16:34:52 +00:00
|
|
|
|
removeScript(false);
|
2006-08-17 21:32:04 +00:00
|
|
|
|
return true;
|
2006-03-11 16:34:52 +00:00
|
|
|
|
} else if (cur.idx() == 1 && cell(1).empty()) {
|
|
|
|
|
// must be a superscript...
|
2006-08-17 21:07:24 +00:00
|
|
|
|
recordUndoInset(cur);
|
2006-03-11 16:34:52 +00:00
|
|
|
|
removeScript(true);
|
2006-08-17 21:32:04 +00:00
|
|
|
|
return true;
|
2006-03-11 16:34:52 +00:00
|
|
|
|
}
|
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
|
2006-08-17 21:07:24 +00:00
|
|
|
|
recordUndoInset(cur);
|
2004-04-05 16:31:52 +00:00
|
|
|
|
removeScript(cell_1_is_up_);
|
2006-08-17 21:07:24 +00:00
|
|
|
|
// Let the script inset commit suicide. This is
|
2007-04-26 14:56:30 +00:00
|
|
|
|
// modelled on Cursor.pullArg(), but tries not to
|
2006-08-17 21:07:24 +00:00
|
|
|
|
// invoke notifyCursorLeaves again and does not touch
|
|
|
|
|
// cur (since the top slice will be deleted
|
|
|
|
|
// afterwards))
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData ar = cell(0);
|
2007-04-26 14:56:30 +00:00
|
|
|
|
Cursor tmpcur = cur;
|
2006-08-17 21:07:24 +00:00
|
|
|
|
tmpcur.pop();
|
|
|
|
|
tmpcur.cell().erase(tmpcur.pos());
|
|
|
|
|
tmpcur.cell().insert(tmpcur.pos(), ar);
|
2006-08-17 21:32:04 +00:00
|
|
|
|
return true;
|
2002-10-29 08:23:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
//lyxerr << "InsetMathScript::notifyCursorLeaves: 2 " << cur << endl;
|
2006-08-17 21:32:04 +00:00
|
|
|
|
return false;
|
2004-08-13 15:06:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-10-29 08:23:32 +00:00
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void InsetMathScript::doDispatch(Cursor & cur, FuncRequest & cmd)
|
2002-08-28 17:59:32 +00:00
|
|
|
|
{
|
2006-09-16 18:11:38 +00:00
|
|
|
|
//lyxerr << "InsetMathScript: 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) {
|
2006-09-01 15:41:38 +00:00
|
|
|
|
if (!cmd.argument().empty()) {
|
|
|
|
|
if (cmd.argument() == "limits")
|
2002-10-28 10:47:24 +00:00
|
|
|
|
limits_ = 1;
|
2006-09-01 15:41:38 +00:00
|
|
|
|
else if (cmd.argument() == "nolimits")
|
2002-10-28 10:47:24 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathNest::doDispatch(cur, cmd);
|
2002-08-28 17:59:32 +00:00
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|