#include "MathSupport.h"
#include "Buffer.h"
-#include "BufferList.h"
#include "BufferView.h"
#include "CoordCache.h"
#include "Cursor.h"
///
void setOwner(MathMacro * mathMacro) { mathMacro_ = mathMacro; }
///
+ MathMacro const * owner() { return mathMacro_; }
+ ///
InsetCode lyxCode() const { return ARGUMENT_PROXY_CODE; }
///
void metrics(MetricsInfo & mi, Dimension & dim) const {
/// This needs to be called every time a copy of the owner is created
/// (bug 9418).
void updateChildren(MathMacro * owner);
+ /// Recursively update the pointers of all expanded macros
+ /// appearing in the arguments of the current macro
+ void updateNestedChildren(MathMacro * owner, InsetMathNest * ni);
/// name of macro
docstring name_;
/// current display mode
ArgumentProxy * p = dynamic_cast<ArgumentProxy *>(expanded_[i].nucleus());
if (p)
p->setOwner(owner);
+
+ InsetMathNest * ni = expanded_[i].nucleus()->asNestInset();
+ if (ni)
+ updateNestedChildren(owner, ni);
}
- if (macro_ && lyxrc.preview == LyXRC::PREVIEW_ON) {
- // As MathData::metrics() is not called when instant preview is
- // on, we have to update macro_ by ourselves. In this case, we
- // simply let it point to the last known good copy of MacroData.
+ if (macro_) {
+ // The macro_ pointer is updated when MathData::metrics() is
+ // called. However, when instant preview is on or the macro is
+ // not on screen, MathData::metrics() is not called and we may
+ // have a dangling pointer. As a safety measure, when a macro
+ // is copied, always let macro_ point to the backup copy of the
+ // MacroData structure. This backup is updated every time the
+ // macro is changed, so it will not become stale.
macro_ = ¯oBackup_;
}
}
+void MathMacro::Private::updateNestedChildren(MathMacro * owner, InsetMathNest * ni)
+{
+ for (size_t i = 0; i < ni->nargs(); ++i) {
+ MathData & ar = ni->cell(i);
+ for (size_t j = 0; j < ar.size(); ++j) {
+ ArgumentProxy * ap = dynamic_cast
+ <ArgumentProxy *>(ar[j].nucleus());
+ if (ap) {
+ MathMacro::Private * md = ap->owner()->d;
+ if (md->macro_)
+ md->macro_ = &md->macroBackup_;
+ ap->setOwner(owner);
+ }
+ InsetMathNest * imn = ar[j].nucleus()->asNestInset();
+ if (imn)
+ updateNestedChildren(owner, imn);
+ }
+ }
+}
+
+
MathMacro::MathMacro(Buffer * buf, docstring const & name)
: InsetMathNest(buf, 0), d(new Private(buf, name))
{}
MathMacro::MathMacro(MathMacro const & that)
: InsetMathNest(that), d(new Private(*that.d))
{
+ setBuffer(*that.buffer_);
d->updateChildren(this);
}
int expy = y;
if (d->displayMode_ == DISPLAY_INIT || d->displayMode_ == DISPLAY_INTERACTIVE_INIT) {
- FontSetChanger dummy(pi.base, "lyxtex");
+ Changer dummy = pi.base.changeFontSet("lyxtex");
pi.pain.text(x, y, from_ascii("\\") + name(), pi.base.font);
} else if (d->displayMode_ == DISPLAY_UNFOLDED) {
- FontSetChanger dummy(pi.base, "lyxtex");
+ Changer dummy = pi.base.changeFontSet("lyxtex");
pi.pain.text(x, y, from_ascii("\\"), pi.base.font);
x += mathed_string_width(pi.base.font, from_ascii("\\")) + 1;
cell(0).draw(pi, x, y);
docstring const xmlname = d->macro_->xmlname();
if (!xmlname.empty()) {
char const * type = d->macro_->MathMLtype();
- os << '<' << type << "> " << xmlname << " /<"
+ os << '<' << type << "> " << xmlname << " </"
<< type << '>';
return;
}