MathHullInset * InsetFormula::hull()
{
lyx::Assert(par_->asHullInset());
- return par_->asHullInset();
+ return par_.nucleus()->asHullInset();
}
Inset::Code InsetFormula::lyxCode() const
void InsetFormula::mutate(string const & type)
{
- par()->mutate(type);
+ par_.nucleus()->mutate(type);
}
void draw(MathPainterInfo & pain, int x, int y) const;
///
MathAMSArrayInset * asAMSArrayInset() { return this; }
+ ///
+ MathAMSArrayInset const * asAMSArrayInset() const { return this; }
///
void write(WriteStream & os) const;
MathInset const * nucleus() const { return nucleus_; }
MathInset * nucleus() { return nucleus_; }
/// access to the inset
- MathInset * operator->() const { return nucleus_; }
+ MathInset const * operator->() const { return nucleus_; }
private:
///
bool MathCursor::toggleLimits()
{
- if (!hasNextAtom())
- return false;
- MathScriptInset * t = nextAtom()->asScriptInset();
- if (!t)
+ if (!hasNextAtom() || !nextAtom()->asScriptInset())
return false;
+ MathScriptInset * t = nextAtom().nucleus()->asScriptInset();
int old = t->limits();
t->limits(old < 0 ? 1 : -1);
return old != t->limits();
void MathCursor::macroModeClose()
{
- MathUnknownInset const * p = inMacroMode();
- if (!p)
+ if (!inMacroMode())
return;
+ MathUnknownInset * p = activeMacro();
p->finalize();
string s = p->name();
--pos();
string MathCursor::macroName() const
{
- return inMacroMode() ? inMacroMode()->name() : string();
+ return inMacroMode() ? activeMacro()->name() : string();
}
}
-MathUnknownInset const * MathCursor::inMacroMode() const
+bool MathCursor::inMacroMode() const
{
if (!hasPrevAtom())
- return 0;
+ return false;
MathUnknownInset const * p = prevAtom()->asUnknownInset();
- return (p && !p->final()) ? p : 0;
+ return p && !p->final();
+}
+
+
+MathUnknownInset * MathCursor::activeMacro()
+{
+ return inMacroMode() ? prevAtom().nucleus()->asUnknownInset() : 0;
+}
+
+
+MathUnknownInset const * MathCursor::activeMacro() const
+{
+ return inMacroMode() ? prevAtom()->asUnknownInset() : 0;
}
// remove empty scripts if possible
if (1) {
for (pos_type i = 0; i < size(); ++i) {
- MathScriptInset * p = array()[i]->asScriptInset();
+ MathScriptInset * p = array()[i].nucleus()->asScriptInset();
if (p) {
p->removeEmptyScripts();
//if (p->empty())
// Be warned: The 'logic' implemented in this function is highly fragile.
// A distance of one pixel or a '<' vs '<=' _really_ matters.
// So fiddle around with it only if you know what you are doing!
- int xo, yo;
+ int xo = 0;
+ int yo = 0;
getPos(xo, yo);
// check if we had something else in mind, if not, this is the future goal
// try neigbouring script insets
// try left
if (hasPrevAtom()) {
- MathScriptInset * p = prevAtom()->asScriptInset();
+ MathScriptInset const * p = prevAtom()->asScriptInset();
if (p && p->has(up)) {
--pos();
push(nextAtom());
// try right
if (hasNextAtom()) {
- MathScriptInset * p = nextAtom()->asScriptInset();
+ MathScriptInset const * p = nextAtom()->asScriptInset();
if (p && p->has(up)) {
push(nextAtom());
idx() = up;
if (name == "over" || name == "choose" || name == "atop") {
MathAtom t(createMathInset(name));
- t->asNestInset()->cell(0) = array();
+ t.nucleus()->asNestInset()->cell(0) = array();
array().clear();
pos() = 0;
niceInsert(t);
idx() = up;
pos() = 0;
} else if (hasPrevAtom() && prevAtom()->asScriptInset()) {
- prevAtom()->asScriptInset()->ensure(up);
+ prevAtom().nucleus()->asScriptInset()->ensure(up);
pushRight(prevAtom());
idx() = up;
pos() = size();
pos() = 0;
} else {
plainInsert(MathAtom(new MathScriptInset(up)));
- prevAtom()->asScriptInset()->ensure(up);
+ prevAtom().nucleus()->asScriptInset()->ensure(up);
pushRight(prevAtom());
idx() = up;
pos() = 0;
--pos();
plainErase();
int n = c - '0';
- MathMacroTemplate * p = formula()->par()->asMacroTemplate();
+ MathMacroTemplate const * p = formula()->par()->asMacroTemplate();
if (p && 1 <= n && n <= p->numargs())
insert(MathAtom(new MathMacroArgument(c - '0')));
else {
}
if (isalpha(c)) {
- inMacroMode()->setName(inMacroMode()->name() + c);
+ activeMacro()->setName(activeMacro()->name() + c);
return true;
}
return true;
}
if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
- prevAtom()->asSpaceInset()->incSpace();
+ prevAtom().nucleus()->asSpaceInset()->incSpace();
return true;
}
if (popRight())
{
if (hasNextAtom()) {
// toggle previous inset ...
- nextAtom()->lock(!nextAtom()->lock());
+ nextAtom().nucleus()->lock(!nextAtom()->lock());
} else if (popLeft() && hasNextAtom()) {
// ... or enclosing inset if we are in the last inset position
- nextAtom()->lock(!nextAtom()->lock());
+ nextAtom().nucleus()->lock(!nextAtom()->lock());
posRight();
}
}
// try to dispatch to adajcent items if they are not editable
// actually, this should only happen for mouse clicks...
if (hasNextAtom() && !openable(nextAtom(), false))
- if (int res = nextAtom()->dispatch(cmd, 0, 0))
+ if (int res = nextAtom().nucleus()->dispatch(cmd, 0, 0))
return res;
if (hasPrevAtom() && !openable(prevAtom(), false))
- if (int res = prevAtom()->dispatch(cmd, 0, 0))
+ if (int res = prevAtom().nucleus()->dispatch(cmd, 0, 0))
return res;
for (int i = Cursor_.size() - 1; i >= 0; --i) {
/// interpret name a name of a macro
void macroModeClose();
/// are we currently typing the name of a macro?
- MathUnknownInset const * inMacroMode() const;
+ bool inMacroMode() const;
+ /// get access to the macro we are currently typing
+ MathUnknownInset * activeMacro();
+ /// get access to the macro we are currently typing
+ MathUnknownInset const * activeMacro() const;
/// are we currently typing '#1' or '#2' or...?
bool inMacroArgMode() const;
/// are we in math mode (1), text mode (-1) or unsure?
//lyxerr << "\nMatrices from: " << ar << "\n";
// first pass for explicitly delimited stuff
for (MathArray::iterator it = ar.begin(); it != ar.end(); ++it) {
- MathDelimInset * del = (*it)->asDelimInset();
+ MathDelimInset const * del = (*it)->asDelimInset();
if (!del)
continue;
MathInset const * arr = singleItem(del->cell(0));
// second pass for AMS "pmatrix" etc
for (MathArray::iterator it = ar.begin(); it != ar.end(); ++it) {
- MathAMSArrayInset * ams = (*it)->asAMSArrayInset();
+ MathAMSArrayInset const * ams = (*it)->asAMSArrayInset();
if (!ams)
continue;
*it = MathAtom(new MathMatrixInset(*ams));
MathArray::iterator it = ar.begin() + i;
// is this script inset?
- MathScriptInset * p = (*it)->asScriptInset();
+ MathScriptInset * p = (*it).nucleus()->asScriptInset();
if (!p)
continue;
continue;
// we need an exponent but no subscript
- MathScriptInset * sup = (*(it + 1))->asScriptInset();
+ MathScriptInset const * sup = (*(it + 1))->asScriptInset();
if (!sup || sup->hasDown())
continue;
{
//lyxerr << "\ndet from: " << ar << "\n";
for (MathArray::iterator it = ar.begin(); it != ar.end(); ++it) {
- MathDelimInset * del = (*it)->asDelimInset();
+ MathDelimInset const * del = (*it)->asDelimInset();
if (!del)
continue;
if (!del->isAbs())
continue;
// guess so, if this is followed by
// a DelimInset with a single item in the cell
- MathDelimInset * del = (*jt)->asDelimInset();
+ MathDelimInset const * del = (*jt)->asDelimInset();
if (!del || del->cell(0).size() != 1)
continue;
// fall trough into main branch
MathExIntInset * p = new MathExIntInset("sum");
// collect lower bound and summation index
- MathScriptInset * sub = (*it)->asScriptInset();
+ MathScriptInset const * sub = (*it)->asScriptInset();
if (sub && sub->hasDown()) {
// try to figure out the summation index from the subscript
- MathArray & ar = sub->down();
- MathArray::iterator xt =
+ MathArray const & ar = sub->down();
+ MathArray::const_iterator xt =
find_if(ar.begin(), ar.end(), &testEqualSign);
if (xt != ar.end()) {
// we found a '=', use everything in front of that as index,
if (!testDiffFrac(*it))
continue;
- MathFracInset * f = (*it)->asFracInset();
+ MathFracInset const * f = (*it)->asFracInset();
if (!f) {
lyxerr << "should not happen\n";
continue;
// collect function, let jt point behind last used item
MathArray::iterator jt = it + 1;
//int n = 1;
- MathArray & numer = f->cell(0);
+ MathArray const & numer = f->cell(0);
if (numer.size() > 1 && numer[1]->asScriptInset()) {
// this is something like d^n f(x) / d... or d^n / d...
// FIXME
}
// collect denominator parts
- MathArray & denom = f->cell(1);
- for (MathArray::iterator dt = denom.begin(); dt != denom.end();) {
+ MathArray const & denom = f->cell(1);
+ for (MathArray::const_iterator dt = denom.begin(); dt != denom.end();) {
// find the next 'd'
- MathArray::iterator et = find_if(dt + 1, denom.end(), &testDiffItem);
+ MathArray::const_iterator et
+ = find_if(dt + 1, denom.end(), &testDiffItem);
// point before this
- MathArray::iterator st = et - 1;
- MathScriptInset * script = (*st)->asScriptInset();
+ MathArray::const_iterator st = et - 1;
+ MathScriptInset const * script = (*st)->asScriptInset();
if (script && script->hasUp()) {
// things like d.../dx^n
int mult = 1;
continue;
// the next one must be a subscript (without superscript)
- MathScriptInset * sub = (*(it + 1))->asScriptInset();
+ MathScriptInset const * sub = (*(it + 1))->asScriptInset();
if (!sub || !sub->hasDown() || sub->hasUp())
continue;
// and it must contain a -> symbol
- MathArray & s = sub->down();
- MathArray::iterator st = find_if(s.begin(), s.end(), &testRightArrow);
+ MathArray const & s = sub->down();
+ MathArray::const_iterator st = find_if(s.begin(), s.end(), &testRightArrow);
if (st == s.end())
continue;
res.append(mat->cell(0));
else {
res.push_back(MathAtom(new MathDelimInset("(", ")")));
- res.back()->cell(0).push_back(at);
+ res.back().nucleus()->cell(0).push_back(at);
}
return res;
}
/// identifies certain types of insets
virtual MathAMSArrayInset * asAMSArrayInset() { return 0; }
+ virtual MathAMSArrayInset const* asAMSArrayInset() const{ return 0; }
virtual MathArrayInset * asArrayInset() { return 0; }
virtual MathCharInset const * asCharInset() const { return 0; }
virtual MathDelimInset * asDelimInset() { return 0; }
virtual MathHullInset * asHullInset() { return 0; }
virtual MathHullInset const * asHullInset() const { return 0; }
virtual MathMacroTemplate * asMacroTemplate() { return 0; }
+ virtual MathMacroTemplate const* asMacroTemplate() const{ return 0; }
virtual MathMatrixInset const * asMatrixInset() const { return 0; }
virtual MathNestInset * asNestInset() { return 0; }
virtual MathNestInset const * asNestInset() const { return 0; }
virtual MathScriptInset * asScriptInset() { return 0; }
virtual MathScriptInset const * asScriptInset() const { return 0; }
virtual MathSpaceInset * asSpaceInset() { return 0; }
+ virtual MathSpaceInset const * asSpaceInset() const { return 0; }
virtual MathStringInset * asStringInset() { return 0; }
virtual MathStringInset const * asStringInset() const { return 0; }
virtual MathSymbolInset const * asSymbolInset() const { return 0; }
void metrics(MathMetricsInfo & st) const;
/// identifies macro templates
MathMacroTemplate * asMacroTemplate() { return this; }
+ /// identifies macro templates
+ MathMacroTemplate const * asMacroTemplate() const { return this; }
private:
///
int numargs_;
lyxerr << "unusual contents found: " << ar << endl;
at = MathAtom(new MathParInset);
if (at->nargs() > 0)
- at->cell(0) = ar;
+ at.nucleus()->cell(0) = ar;
else
lyxerr << "unusual contents found: " << ar << endl;
return true;
void Parser::parse2(MathAtom & at, unsigned flags, mode_type mode,
bool numbered)
{
- parse1(*(at->asGridInset()), flags, mode, numbered);
+ parse1(*(at.nucleus()->asGridInset()), flags, mode, numbered);
}
cell->push_back(MathAtom(new MathScriptInset(up)));
else if (cell->back()->asScriptInset() &&
!cell->back()->asScriptInset()->has(up))
- cell->back()->asScriptInset()->ensure(up);
+ cell->back().nucleus()->asScriptInset()->ensure(up);
else if (cell->back()->asScriptInset())
cell->push_back(MathAtom(new MathScriptInset(up)));
else
cell->back() = MathAtom(new MathScriptInset(cell->back(), up));
- MathScriptInset * p = cell->back()->asScriptInset();
+ MathScriptInset * p = cell->back().nucleus()->asScriptInset();
parse(p->cell(up), FLAG_ITEM, mode);
p->limits(limits);
limits = 0;
else if (t.cs() == "lyxlock") {
if (cell->size())
- cell->back()->lock(true);
+ cell->back().nucleus()->lock(true);
}
else if (t.cs() == "def" || t.cs() == "newcommand") {
parse(ar, FLAG_OPTION, mode);
if (ar.size()) {
cell->push_back(MathAtom(new MathRootInset));
- cell->back()->cell(0) = ar;
- parse(cell->back()->cell(1), FLAG_ITEM, mode);
+ cell->back().nucleus()->cell(0) = ar;
+ parse(cell->back().nucleus()->cell(1), FLAG_ITEM, mode);
} else {
cell->push_back(MathAtom(new MathSqrtInset));
- parse(cell->back()->cell(0), FLAG_ITEM, mode);
+ parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
}
}
else if (t.cs() == "ref") {
cell->push_back(MathAtom(new RefInset));
- parse(cell->back()->cell(1), FLAG_OPTION, mode);
- parse(cell->back()->cell(0), FLAG_ITEM, mode);
+ parse(cell->back().nucleus()->cell(1), FLAG_OPTION, mode);
+ parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
}
else if (t.cs() == "left") {
// lyxerr << "unknow math inset begin '" << name << "'\n";
// create generic environment inset
cell->push_back(MathAtom(new MathEnvInset(name)));
- parse(cell->back()->cell(0), FLAG_END, mode);
+ parse(cell->back().nucleus()->cell(0), FLAG_END, mode);
}
}
}
else if (t.cs() == "choose" || t.cs() == "over" || t.cs() == "atop") {
- MathAtom p = createMathInset(t.cs());
- p->cell(0) = *cell;
+ MathAtom at = createMathInset(t.cs());
+ at.nucleus()->cell(0) = *cell;
cell->clear();
- parse(p->cell(1), flags, mode);
- cell->push_back(p);
+ parse(at.nucleus()->cell(1), flags, mode);
+ cell->push_back(at);
return;
}
if (l) {
if (l->inset == "font") {
cell->push_back(createMathInset(t.cs()));
- parse(cell->back()->cell(0), FLAG_ITEM, asMode(l->extra));
+ parse(cell->back().nucleus()->cell(0), FLAG_ITEM, asMode(l->extra));
}
else if (l->inset == "oldfont") {
cell->push_back(createMathInset(t.cs()));
- parse(cell->back()->cell(0), flags, asMode(l->extra));
+ parse(cell->back().nucleus()->cell(0), flags, asMode(l->extra));
return;
}
else if (l->inset == "style") {
cell->push_back(createMathInset(t.cs()));
- parse(cell->back()->cell(0), flags, mode);
+ parse(cell->back().nucleus()->cell(0), flags, mode);
return;
}
parse(pos, FLAG_OPTION, MathInset::VERBATIM_MODE);
parse(width, FLAG_ITEM, MathInset::VERBATIM_MODE);
cell->push_back(createMathInset(t.cs()));
- parse(cell->back()->cell(0), FLAG_ITEM, MathInset::TEXT_MODE);
- cell->back()->asParboxInset()->setPosition(asString(pos));
- cell->back()->asParboxInset()->setWidth(asString(width));
+ parse(cell->back().nucleus()->cell(0), FLAG_ITEM, MathInset::TEXT_MODE);
+ cell->back().nucleus()->asParboxInset()->setPosition(asString(pos));
+ cell->back().nucleus()->asParboxInset()->setWidth(asString(width));
}
else {
- MathAtom p = createMathInset(t.cs());
- for (MathInset::idx_type i = 0; i < p->nargs(); ++i)
- parse(p->cell(i), FLAG_ITEM, asMode(l->extra));
- cell->push_back(p);
+ MathAtom at = createMathInset(t.cs());
+ for (MathInset::idx_type i = 0; i < at->nargs(); ++i)
+ parse(at.nucleus()->cell(i), FLAG_ITEM, asMode(l->extra));
+ cell->push_back(at);
}
}
else {
- MathAtom p = createMathInset(t.cs());
+ MathAtom at = createMathInset(t.cs());
MathInset::mode_type m = mode;
if (m == MathInset::UNDECIDED_MODE)
- m = p->currentMode();
- for (MathInset::idx_type i = 0; i < p->nargs(); ++i)
- parse(p->cell(i), FLAG_ITEM, m);
- cell->push_back(p);
+ m = at->currentMode();
+ for (MathInset::idx_type i = 0; i < at->nargs(); ++i)
+ parse(at.nucleus()->cell(i), FLAG_ITEM, m);
+ cell->push_back(at);
}
}
}
-void MathUnknownInset::setName(string const & name) const
+void MathUnknownInset::setName(string const & name)
{
name_ = name;
}
}
-void MathUnknownInset::finalize() const
+void MathUnknownInset::finalize()
{
final_ = true;
}
///
void draw(MathPainterInfo & pi, int x, int y) const;
///
- void setName(string const & name) const;
+ void setName(string const & name);
///
string name() const;
/// identifies UnknownInsets
///
void octavize(OctaveStream &) const;
///
- void finalize() const;
+ void finalize();
///
bool final() const;
private:
///
- mutable string name_;
+ string name_;
/// are we finished creating the name?
- mutable bool final_;
+ bool final_;
///
bool black_;
};