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.
|
|
|
|
*
|
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.
|
|
|
|
*/
|
|
|
|
|
2003-08-02 11:30:30 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2008-02-09 22:06:06 +00:00
|
|
|
#include "BufferView.h"
|
|
|
|
#include "Cursor.h"
|
|
|
|
#include "DispatchResult.h"
|
|
|
|
#include "FuncRequest.h"
|
|
|
|
#include "InsetMathFont.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "InsetMathScript.h"
|
2008-02-09 22:06:06 +00:00
|
|
|
#include "InsetMathSymbol.h"
|
2010-03-30 01:31:25 +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"
|
2008-02-09 22:06:06 +00:00
|
|
|
|
2007-11-29 07:04:28 +00:00
|
|
|
#include "support/debug.h"
|
2003-10-06 15:43:21 +00:00
|
|
|
|
2008-04-30 08:26:40 +00:00
|
|
|
#include "support/lassert.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
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 {
|
2006-08-13 22:54:59 +00:00
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
2009-11-08 11:45:46 +00:00
|
|
|
InsetMathScript::InsetMathScript(Buffer * buf)
|
|
|
|
: InsetMathNest(buf, 1), cell_1_is_up_(false), limits_(0)
|
2004-03-25 09:16:36 +00:00
|
|
|
{}
|
2001-10-12 12:02:49 +00:00
|
|
|
|
|
|
|
|
2009-11-08 11:45:46 +00:00
|
|
|
InsetMathScript::InsetMathScript(Buffer * buf, bool up)
|
|
|
|
: InsetMathNest(buf, 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
|
|
|
|
2009-11-08 11:45:46 +00:00
|
|
|
InsetMathScript::InsetMathScript(Buffer * buf, MathAtom const & at, bool up)
|
|
|
|
: InsetMathNest(buf, 2), cell_1_is_up_(up), limits_(0)
|
2002-07-30 13:56:02 +00:00
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(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);
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(nargs() > 1, /**/);
|
2004-04-05 10:37:16 +00:00
|
|
|
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);
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(nargs() > 1, /**/);
|
2004-04-05 10:37:16 +00:00
|
|
|
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
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(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
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(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
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(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
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(hasUp(), /**/);
|
2007-09-23 22:39:49 +00:00
|
|
|
Dimension const dim = dimension(bv);
|
2007-12-22 14:39:22 +00:00
|
|
|
return hasLimits() ? (dim.wid - up().dimension(bv).width()) / 2 : nwid(bv) + nker(&bv);
|
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-12-22 14:39:22 +00:00
|
|
|
int InsetMathScript::nker(BufferView const * bv) const
|
2007-03-21 17:21:59 +00:00
|
|
|
{
|
|
|
|
if (nuc().size()) {
|
2007-12-22 14:39:22 +00:00
|
|
|
int kerning = nuc().kerning(bv);
|
2007-03-21 17:21:59 +00:00
|
|
|
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-12-22 14:39:22 +00:00
|
|
|
dim.wid = max(dim.wid, nker(mi.base.bv) + 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);
|
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
|
|
|
{
|
2007-11-28 22:12:03 +00:00
|
|
|
//lyxerr << "1up: " << bool(cell_1_is_up_));
|
|
|
|
//lyxerr << "hasUp: " << bool(idxOfScript(true)));
|
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
|
|
|
{
|
2007-11-28 22:12:03 +00:00
|
|
|
//LYXERR0("1up: " << bool(cell_1_is_up_));
|
|
|
|
//LYXERR0("hasDown: " << bool(idxOfScript(false)));
|
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;
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(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-11-05 19:44:03 +00:00
|
|
|
bool InsetMathScript::idxForward(Cursor &) const
|
2001-10-12 15:38:58 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-05 19:44:03 +00:00
|
|
|
bool InsetMathScript::idxBackward(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
|
|
|
{
|
2008-06-17 11:10:43 +00:00
|
|
|
MathEnsurer ensurer(os);
|
2008-06-16 01:21:17 +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-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::MATHED, "suppressing {} when writing");
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-25 21:47:42 +00:00
|
|
|
// FIXME XHTML
|
|
|
|
// It may be worth trying to output munder, mover, and munderover
|
|
|
|
// in certain cases, e.g., for display formulas. But then we would
|
|
|
|
// need to know if we're in a display formula.
|
2009-12-31 15:46:39 +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
|
|
|
|
2009-12-31 15:46:39 +00:00
|
|
|
if (nuc().size())
|
|
|
|
os << MTag("mrow") << nuc() << ETag("mrow");
|
|
|
|
else
|
2009-12-17 15:39:18 +00:00
|
|
|
os << "<mrow />";
|
2001-11-07 17:30:26 +00:00
|
|
|
|
2001-11-08 12:06:56 +00:00
|
|
|
if (u && d)
|
2009-12-17 15:39:18 +00:00
|
|
|
os << MTag("mrow") << down() << ETag("mrow")
|
|
|
|
<< MTag("mrow") << up() << ETag("mrow")
|
|
|
|
<< ETag("msubsup");
|
2001-11-08 12:06:56 +00:00
|
|
|
else if (u)
|
2009-12-17 15:39:18 +00:00
|
|
|
os << MTag("mrow") << up() << ETag("mrow") << ETag("msup");
|
2001-11-08 12:06:56 +00:00
|
|
|
else if (d)
|
2009-12-17 15:39:18 +00:00
|
|
|
os << MTag("mrow") << down() << ETag("mrow") << ETag("msub");
|
2001-11-08 12:06:56 +00:00
|
|
|
}
|
|
|
|
|
2001-11-07 17:30:26 +00:00
|
|
|
|
2010-03-30 01:31:25 +00:00
|
|
|
void InsetMathScript::htmlize(HtmlStream & os) const
|
|
|
|
{
|
|
|
|
bool d = hasDown() && down().size();
|
|
|
|
bool u = hasUp() && up().size();
|
|
|
|
|
|
|
|
if (nuc().size())
|
|
|
|
os << nuc();
|
|
|
|
|
|
|
|
if (u && d)
|
|
|
|
os << MTag("span", "class='scripts'")
|
2010-03-30 22:51:11 +00:00
|
|
|
<< MTag("span") << up() << ETag("span")
|
|
|
|
<< MTag("span") << down() << ETag("span")
|
2010-03-30 01:31:25 +00:00
|
|
|
<< ETag("span");
|
|
|
|
else if (u)
|
|
|
|
os << MTag("sup", "class='math'") << up() << ETag("sup");
|
|
|
|
else if (d)
|
|
|
|
os << MTag("sub", "class='math'") << down() << ETag("sub");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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_)
|
2007-11-28 22:12:03 +00:00
|
|
|
os << from_ascii(limits_ == 1 ? ", Displayed limits" : ", Inlined limits");
|
2002-07-08 13:03:37 +00:00
|
|
|
}
|
2002-08-28 17:59:32 +00:00
|
|
|
|
|
|
|
|
2008-02-22 20:45:18 +00:00
|
|
|
bool InsetMathScript::notifyCursorLeaves(Cursor const & old, Cursor & cur)
|
2002-10-29 08:23:32 +00:00
|
|
|
{
|
2008-02-22 20:45:18 +00:00
|
|
|
InsetMathNest::notifyCursorLeaves(old, cur);
|
2002-10-29 08:23:32 +00:00
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
//LYXERR0("InsetMathScript::notifyCursorLeaves: 1 " << cur);
|
2004-08-13 15:06:46 +00:00
|
|
|
|
2008-02-09 22:04:30 +00:00
|
|
|
// Remove empty scripts if possible:
|
|
|
|
|
|
|
|
// The case of two scripts, but only one got empty (1 = super, 2 = sub).
|
|
|
|
// We keep the script inset, but remove the empty script.
|
|
|
|
if (nargs() > 2 && (!cell(1).empty() || !cell(2).empty())) {
|
|
|
|
if (cell(2).empty()) {
|
2006-03-11 16:34:52 +00:00
|
|
|
// must be a subscript...
|
2009-10-08 12:32:11 +00:00
|
|
|
old.recordUndoInset();
|
2006-03-11 16:34:52 +00:00
|
|
|
removeScript(false);
|
2010-04-15 17:34:34 +00:00
|
|
|
cur.updateFlags(cur.result().update() | Update::SinglePar);
|
2006-08-17 21:32:04 +00:00
|
|
|
return true;
|
2008-02-09 22:04:30 +00:00
|
|
|
} else if (cell(1).empty()) {
|
2006-03-11 16:34:52 +00:00
|
|
|
// must be a superscript...
|
2009-10-08 12:32:11 +00:00
|
|
|
old.recordUndoInset();
|
2006-03-11 16:34:52 +00:00
|
|
|
removeScript(true);
|
2010-04-15 17:34:34 +00:00
|
|
|
cur.updateFlags(cur.result().update() | Update::SinglePar);
|
2006-08-17 21:32:04 +00:00
|
|
|
return true;
|
2006-03-11 16:34:52 +00:00
|
|
|
}
|
2008-02-09 22:04:30 +00:00
|
|
|
}
|
|
|
|
// Now the two suicide cases:
|
|
|
|
// * we have only one script which is empty
|
|
|
|
// * we have two scripts which are both empty.
|
|
|
|
// The script inset is removed completely.
|
|
|
|
if ((nargs() == 2 && cell(1).empty())
|
|
|
|
|| (nargs() == 3 && cell(1).empty() && cell(2).empty())) {
|
2008-02-09 22:06:06 +00:00
|
|
|
// Make undo step. We cannot use cur for this because
|
2008-02-22 20:45:18 +00:00
|
|
|
// it does not necessarily point to us anymore. But we
|
|
|
|
// should be on top of the cursor old.
|
|
|
|
Cursor insetCur = old;
|
|
|
|
int scriptSlice = insetCur.find(this);
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(scriptSlice != -1, /**/);
|
2008-02-22 20:45:18 +00:00
|
|
|
insetCur.cutOff(scriptSlice);
|
|
|
|
insetCur.recordUndoInset();
|
2008-02-09 22:06:06 +00:00
|
|
|
|
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
|
2008-02-09 22:06:06 +00:00
|
|
|
// afterwards)
|
2007-04-26 16:05:57 +00:00
|
|
|
MathData ar = cell(0);
|
2008-02-22 20:45:18 +00:00
|
|
|
insetCur.pop();
|
|
|
|
insetCur.cell().erase(insetCur.pos());
|
|
|
|
insetCur.cell().insert(insetCur.pos(), ar);
|
2008-02-09 23:20:11 +00:00
|
|
|
|
|
|
|
// redraw
|
2010-04-15 17:34:34 +00:00
|
|
|
cur.updateFlags(cur.result().update() | Update::SinglePar);
|
2006-08-17 21:32:04 +00:00
|
|
|
return true;
|
2002-10-29 08:23:32 +00:00
|
|
|
}
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
//LYXERR0("InsetMathScript::notifyCursorLeaves: 2 " << cur);
|
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
|
|
|
{
|
2007-11-28 22:12:03 +00:00
|
|
|
//LYXERR("InsetMathScript: request: " << cmd);
|
2004-02-11 14:45:44 +00:00
|
|
|
|
2010-04-09 19:00:42 +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
|
|
|
|
|
|
|
|
2010-03-30 01:31:25 +00:00
|
|
|
// the idea for dual scripts came from the eLyXer code
|
|
|
|
void InsetMathScript::validate(LaTeXFeatures & features) const
|
|
|
|
{
|
2010-03-31 18:24:52 +00:00
|
|
|
if (features.runparams().math_flavor == OutputParams::MathAsHTML)
|
2010-03-30 01:31:25 +00:00
|
|
|
features.addPreambleSnippet("<style type=\"text/css\">\n"
|
|
|
|
"span.scripts{display: inline-block; vertical-align: middle; text-align:center; font-size: 75%;}\n"
|
2010-03-30 22:51:11 +00:00
|
|
|
"span.scripts span {display: block;}\n"
|
2010-03-30 01:31:25 +00:00
|
|
|
"sub.math{font-size: 75%;}\n"
|
|
|
|
"sup.math{font-size: 75%;}\n"
|
|
|
|
"</style>");
|
2010-03-31 21:24:16 +00:00
|
|
|
InsetMathNest::validate(features);
|
2010-03-30 01:31:25 +00:00
|
|
|
}
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|