#include "math_support.h"
#include "math_symbolinset.h"
#include "math_mathmlstream.h"
+#include "funcrequest.h"
#include "support/LAssert.h"
#include "debug.h"
}
-MathXArray const & MathScriptInset::down() const
+MathArray const & MathScriptInset::down() const
{
- return xcell(0);
+ return cell(0);
}
-MathXArray & MathScriptInset::down()
+MathArray & MathScriptInset::down()
{
- return xcell(0);
+ return cell(0);
}
-MathXArray const & MathScriptInset::up() const
+MathArray const & MathScriptInset::up() const
{
- return xcell(1);
+ return cell(1);
}
-MathXArray & MathScriptInset::up()
+MathArray & MathScriptInset::up()
{
- return xcell(1);
+ return cell(1);
}
}
-MathXArray const & MathScriptInset::nuc() const
+MathArray const & MathScriptInset::nuc() const
{
- return xcell(2);
+ return cell(2);
}
-MathXArray & MathScriptInset::nuc()
+MathArray & MathScriptInset::nuc()
{
- return xcell(2);
+ return cell(2);
}
void MathScriptInset::metrics(MathMetricsInfo & mi) const
{
- MathNestInset::metrics(mi);
+ cell(2).metrics(mi);
MathScriptChanger dummy(mi.base);
+ cell(0).metrics(mi);
+ cell(1).metrics(mi);
dim_.w = 0;
if (hasLimits()) {
dim_.w = nwid();
{
if (nuc().size())
nuc().draw(pi, x + dxx(), y);
- else if (editing())
- drawStr(pi, pi.base.font, x + dxx(), y, ".");
+ else {
+ nuc().setXY(x + dxx(), y);
+ if (editing())
+ drawStr(pi, pi.base.font, x + dxx(), y, ".");
+ }
MathScriptChanger dummy(pi.base);
if (hasUp())
up().draw(pi, x + dx1(), y - dy1());
}
-void MathScriptInset::removeEmptyScripts()
-{
- for (int i = 0; i <= 1; ++i)
- if (script_[i] && cell(i).size() == 0) {
- cell(i).clear();
- script_[i] = false;
- }
-}
-
-
void MathScriptInset::removeScript(bool up)
{
cell(up).clear();
}
-bool MathScriptInset::empty() const
-{
- return !script_[0] && !script_[1] && cell(2).empty();
-}
-
-
bool MathScriptInset::hasUp() const
{
return script_[1];
bool MathScriptInset::idxUpDown(idx_type & idx, pos_type & pos, bool up,
int) const
{
- if ((idx == 1 && up) || (idx == 0 && !up))
- return false;
+ if (idx == 1) {
+ // if we are 'up' we can't go further up
+ if (up)
+ return false;
+ // otherwise go to last base position
+ idx = 2;
+ pos = cell(2).size();
+ }
- // in nuclues?
- if (idx == 2) {
- idx = up;
- pos = 0;
- } else {
+ else if (idx == 0) {
+ // if we are 'down' we can't go further down
+ if (!up)
+ return false;
idx = 2;
- pos = cell(2).size();
+ pos = cell(2).size();
+ }
+
+ else {
+ // in nucleus
+ // don't go up/down if there is no cell.
+ if (!has(up))
+ return false;
+ // go up/down only if in the last position
+ // or in the first position of something with displayed limits
+ if (pos == cell(2).size() || (pos == 0 && hasLimits())) {
+ idx = up;
+ pos = 0;
+ return true;
+ }
+ return false;
}
return true;
}
void MathScriptInset::write(WriteStream & os) const
{
if (nuc().size()) {
- os << nuc().data();
- if (nuc().back()->takesLimits()) {
+ os << nuc();
+ //if (nuc().back()->takesLimits()) {
if (limits_ == -1)
os << "\\nolimits ";
if (limits_ == 1)
os << "\\limits ";
- }
+ //}
} else {
if (os.firstitem())
lyxerr[Debug::MATHED] << "suppressing {} when writing\n";
}
if (hasDown() && down().size())
- os << "_{" << down().data() << '}';
+ os << "_{" << down() << '}';
if (hasUp() && up().size())
- os << "^{" << up().data() << '}';
+ os << "^{" << up() << '}';
if (lock_ && !os.latex())
os << "\\lyxlock ";
os << "[sub ";
if (nuc().size())
- os << nuc().data() << ' ';
+ os << nuc() << ' ';
else
os << "[par]";
if (u && d)
- os << down().data() << ' ' << up().data() << ']';
+ os << down() << ' ' << up() << ']';
else if (d)
- os << down().data() << ']';
+ os << down() << ']';
else if (u)
- os << up().data() << ']';
+ os << up() << ']';
}
void MathScriptInset::maplize(MapleStream & os) const
{
if (nuc().size())
- os << nuc().data();
+ os << nuc();
if (hasDown() && down().size())
- os << '[' << down().data() << ']';
+ os << '[' << down() << ']';
if (hasUp() && up().size())
- os << "^(" << up().data() << ')';
+ os << "^(" << up() << ')';
}
bool u = hasUp() && up().size();
if (nuc().size()) {
- if (d)
- os << "Subscript[" << nuc().data();
+ if (d)
+ os << "Subscript[" << nuc();
else
- os << nuc().data();
+ os << nuc();
}
if (u)
- os << "^(" << up().data() << ")";
+ os << "^(" << up() << ')';
if (nuc().size())
if (d)
- os << "," << down().data() << "]";
+ os << ',' << down() << ']';
}
os << MTag("msub");
if (nuc().size())
- os << nuc().data();
+ os << nuc();
else
os << "<mrow/>";
if (u && d)
- os << down().data() << up().data() << ETag("msubsup");
+ os << down() << up() << ETag("msubsup");
else if (u)
- os << up().data() << ETag("msup");
+ os << up() << ETag("msup");
else if (d)
- os << down().data() << ETag("msub");
+ os << down() << ETag("msub");
}
void MathScriptInset::octavize(OctaveStream & os) const
{
if (nuc().size())
- os << nuc().data();
+ os << nuc();
if (hasDown() && down().size())
- os << '[' << down().data() << ']';
+ os << '[' << down() << ']';
if (hasUp() && up().size())
- os << "^(" << up().data() << ')';
+ os << "^(" << up() << ')';
}
void MathScriptInset::infoize(std::ostream & os) const
{
os << "Scripts";
+}
+
+
+void MathScriptInset::infoize2(std::ostream & os) const
+{
if (limits_)
os << (limits_ == 1 ? ", Displayed limits" : ", Inlined limits");
}
+
+
+void MathScriptInset::notifyCursorLeaves(idx_type idx)
+{
+ MathNestInset::notifyCursorLeaves(idx);
+
+ // remove empty scripts if possible
+ if (idx != 2 && script_[idx] && cell(idx).empty()) {
+ cell(idx).clear();
+ script_[idx] = false;
+ }
+}
+
+
+MathInset::result_type MathScriptInset::dispatch
+ (FuncRequest const & cmd, idx_type & idx, pos_type & pos)
+{
+ if (cmd.action == LFUN_MATH_LIMITS) {
+ if (!cmd.argument.empty()) {
+ if (cmd.argument == "limits")
+ limits_ = 1;
+ else if (cmd.argument == "nolimits")
+ limits_ = -1;
+ else
+ limits_ = 0;
+ } else if (limits_ == 0)
+ limits_ = (hasLimits()) ? -1 : 1;
+ else
+ limits_ = 0;
+ return DISPATCHED;
+ }
+
+ return MathNestInset::dispatch(cmd, idx, pos);
+}