From: Abdelrazak Younes Date: Sun, 8 Nov 2009 11:45:46 +0000 (+0000) Subject: Make Buffer argument mandatory in most of the InsetMath based class... boring work... X-Git-Tag: 2.0.0~5207 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=ff4460603e3888948b46f0ab5bfa69a862d538ad;p=features.git Make Buffer argument mandatory in most of the InsetMath based class... boring work... Math manual loads and save correctly it seems but expect some instability period. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31898 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/Buffer.cpp b/src/Buffer.cpp index f9c6211061..e2618b43dc 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -2569,7 +2569,7 @@ void Buffer::updateMacros(DocIterator & it, DocIterator & scope) const // get macro data MathMacroTemplate & macroTemplate = static_cast(*iit->inset); - MacroContext mc(*this, it); + MacroContext mc(this, it); macroTemplate.updateToContext(mc); // valid? @@ -2581,8 +2581,10 @@ void Buffer::updateMacros(DocIterator & it, DocIterator & scope) const continue; // register macro + // FIXME (Abdel), I don't understandt why we pass 'it' here + // instead of 'macroTemplate' defined above... is this correct? d->macros[macroTemplate.name()][it] = - Impl::ScopeMacro(scope, MacroData(*this, it)); + Impl::ScopeMacro(scope, MacroData(const_cast(this), it)); } // next paragraph @@ -2662,7 +2664,7 @@ void Buffer::updateMacroInstances() const // update macro in all cells of the InsetMathNest DocIterator::idx_type n = minset->nargs(); - MacroContext mc = MacroContext(*this, it); + MacroContext mc = MacroContext(this, it); for (DocIterator::idx_type i = 0; i < n; ++i) { MathData & data = minset->cell(i); data.updateMacros(0, mc); diff --git a/src/Cursor.cpp b/src/Cursor.cpp index 72afe06759..a9c07f21aa 100644 --- a/src/Cursor.cpp +++ b/src/Cursor.cpp @@ -1441,7 +1441,7 @@ bool Cursor::macroModeClose() if (in && in->interpretString(*this, s)) return true; MathAtom atom = buffer()->getMacro(name, *this, false) ? - MathAtom(new MathMacro(name)) : createInsetMath(name); + MathAtom(new MathMacro(buffer(), name)) : createInsetMath(name, buffer()); // try to put argument into macro, if we just inserted a macro bool macroArg = false; @@ -1895,8 +1895,8 @@ void Cursor::handleFont(string const & font) } else { // cursor in between. split cell MathData::iterator bt = cell().begin(); - MathAtom at = createInsetMath(from_utf8(font)); - at.nucleus()->cell(0) = MathData(bt, bt + pos()); + MathAtom at = createInsetMath(from_utf8(font), buffer()); + at.nucleus()->cell(0) = MathData(buffer(), bt, bt + pos()); cell().erase(bt, bt + pos()); popBackward(); plainInsert(at); diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp index 944119f965..2fb55173e8 100644 --- a/src/CutAndPaste.cpp +++ b/src/CutAndPaste.cpp @@ -1104,7 +1104,8 @@ docstring grabSelection(Cursor const & cur) if (i1.idx() == i2.idx()) { if (i1.inset().asInsetMath()) { MathData::const_iterator it = i1.cell().begin(); - return asString(MathData(it + i1.pos(), it + i2.pos())); + Buffer * buf = cur.buffer(); + return asString(MathData(buf, it + i1.pos(), it + i2.pos())); } else { return from_ascii("unknown selection 1"); } diff --git a/src/Text3.cpp b/src/Text3.cpp index fa6c6e4ab3..e1ec72d078 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -141,7 +141,7 @@ static void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display) #ifdef ENABLE_ASSERTIONS const int old_pos = cur.pos(); #endif - cur.insert(new InsetMathHull(hullSimple, cur.buffer())); + cur.insert(new InsetMathHull(cur.buffer(), hullSimple)); #ifdef ENABLE_ASSERTIONS LASSERT(old_pos == cur.pos(), /**/); #endif @@ -184,7 +184,7 @@ static void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display) } else cur.insert(formula); } else { - cur.insert(new MathMacroTemplate(sel, cur.buffer())); + cur.insert(new MathMacroTemplate(cur.buffer(), sel)); } } if (valid) @@ -207,7 +207,7 @@ void regexpDispatch(Cursor & cur, FuncRequest const & cmd) // It may happen that sel is empty but there is a selection replaceSelection(cur); - cur.insert(new InsetMathHull(hullRegexp, cur.buffer())); + cur.insert(new InsetMathHull(cur.buffer(), hullRegexp)); cur.nextInset()->edit(cur, true); cur.niceInsert(sel); @@ -1753,7 +1753,8 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) MacroType type = MacroTypeNewcommand; if (s2 == "def") type = MacroTypeDef; - MathMacroTemplate * inset = new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, false, type, cur.buffer()); + MathMacroTemplate * inset = new MathMacroTemplate(cur.buffer(), + from_utf8(token(s, ' ', 0)), nargs, false, type); inset->setBuffer(bv->buffer()); insertInset(cur, inset); @@ -1781,7 +1782,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) case LFUN_MATH_BIGDELIM: { cur.recordUndo(); cap::replaceSelection(cur); - cur.insert(new InsetMathHull(hullSimple, cur.buffer())); + cur.insert(new InsetMathHull(cur.buffer(), hullSimple)); checkAndActivateInset(cur, true); LASSERT(cur.inMathed(), /**/); cur.dispatch(cmd); diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp index 8a62776f39..8a7d281e71 100644 --- a/src/TextMetrics.cpp +++ b/src/TextMetrics.cpp @@ -447,7 +447,7 @@ bool TextMetrics::redoParagraph(pit_type const pit) - right_margin; Font const & font = ii->inset->noFontChange() ? bufferfont : displayFont(pit, ii->pos); - MacroContext mc(buffer, parPos); + MacroContext mc(&buffer, parPos); MetricsInfo mi(bv_, font.fontInfo(), w, mc); ii->inset->metrics(mi, dim); Dimension const old_dim = pm.insetDimension(ii->inset); diff --git a/src/insets/Inset.h b/src/insets/Inset.h index e5a11df800..9cf6cf2b30 100644 --- a/src/insets/Inset.h +++ b/src/insets/Inset.h @@ -506,7 +506,7 @@ public: protected: /// Constructors - Inset() : buffer_(0) {} + Inset(Buffer * buf = 0) : buffer_(buf) {} Inset(Inset const &) : buffer_(0) {} /// replicate ourselves diff --git a/src/mathed/CommandInset.cpp b/src/mathed/CommandInset.cpp index 84894adf2f..be67c3d52e 100644 --- a/src/mathed/CommandInset.cpp +++ b/src/mathed/CommandInset.cpp @@ -23,8 +23,8 @@ using namespace std; namespace lyx { -CommandInset::CommandInset(docstring const & name, bool needs_math_mode) - : InsetMathNest(2), name_(name), needs_math_mode_(needs_math_mode), +CommandInset::CommandInset(Buffer * buf, docstring const & name, bool needs_math_mode) + : InsetMathNest(buf, 2), name_(name), needs_math_mode_(needs_math_mode), set_label_(false) { lock_ = true; diff --git a/src/mathed/CommandInset.h b/src/mathed/CommandInset.h index 73f938df22..770ecb388d 100644 --- a/src/mathed/CommandInset.h +++ b/src/mathed/CommandInset.h @@ -25,7 +25,8 @@ namespace lyx { class CommandInset : public InsetMathNest { public: /// - explicit CommandInset(docstring const & name, bool needs_math_mode = true); + explicit CommandInset(Buffer * buf, docstring const & name, + bool needs_math_mode = true); /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// diff --git a/src/mathed/InsetFormulaMacro.h b/src/mathed/InsetFormulaMacro.h index 7d08dc3d75..6e3752a36d 100644 --- a/src/mathed/InsetFormulaMacro.h +++ b/src/mathed/InsetFormulaMacro.h @@ -29,9 +29,9 @@ class Lexer; class InsetFormulaMacro : public InsetMathNest { public: /// - InsetFormulaMacro(); + InsetFormulaMacro(Buffer * buf); /// construct a macro hull from its name and the number of arguments - InsetFormulaMacro(docstring const & name, int nargs, docstring const & t); + InsetFormulaMacro(Buffer * buf, docstring const & name, int nargs, docstring const & t); /// constructs a mocro from its LaTeX definition explicit InsetFormulaMacro(docstring const & s); /// diff --git a/src/mathed/InsetMath.cpp b/src/mathed/InsetMath.cpp index d6c40d7e30..51b4deee70 100644 --- a/src/mathed/InsetMath.cpp +++ b/src/mathed/InsetMath.cpp @@ -29,7 +29,7 @@ namespace lyx { MathData & InsetMath::cell(idx_type) { - static MathData dummyCell; + static MathData dummyCell(&buffer()); LYXERR0("I don't have any cell"); return dummyCell; } diff --git a/src/mathed/InsetMath.h b/src/mathed/InsetMath.h index 538b0b63cc..555762c8c7 100644 --- a/src/mathed/InsetMath.h +++ b/src/mathed/InsetMath.h @@ -93,6 +93,8 @@ class ReplaceData; class InsetMath : public Inset { public: + /// + InsetMath(Buffer * buf = 0) : Inset(buf) {} /// identification as math inset InsetMath * asInsetMath() { return this; } /// identification as math inset diff --git a/src/mathed/InsetMathAMSArray.cpp b/src/mathed/InsetMathAMSArray.cpp index 9bcff0c41f..b9efc3d0e2 100644 --- a/src/mathed/InsetMathAMSArray.cpp +++ b/src/mathed/InsetMathAMSArray.cpp @@ -32,13 +32,14 @@ namespace lyx { using support::bformat; -InsetMathAMSArray::InsetMathAMSArray(docstring const & name, int m, int n) - : InsetMathGrid(m, n), name_(name) +InsetMathAMSArray::InsetMathAMSArray(Buffer * buf, docstring const & name, + int m, int n) + : InsetMathGrid(buf, m, n), name_(name) {} -InsetMathAMSArray::InsetMathAMSArray(docstring const & name) - : InsetMathGrid(1, 1), name_(name) +InsetMathAMSArray::InsetMathAMSArray(Buffer * buf, docstring const & name) + : InsetMathGrid(buf, 1, 1), name_(name) {} diff --git a/src/mathed/InsetMathAMSArray.h b/src/mathed/InsetMathAMSArray.h index 9cf98a5cd7..76ca3208fb 100644 --- a/src/mathed/InsetMathAMSArray.h +++ b/src/mathed/InsetMathAMSArray.h @@ -21,9 +21,9 @@ namespace lyx { class InsetMathAMSArray : public InsetMathGrid { public: /// - InsetMathAMSArray(docstring const &, int m, int n); + InsetMathAMSArray(Buffer * buf, docstring const &, int m, int n); /// - InsetMathAMSArray(docstring const &); + InsetMathAMSArray(Buffer * buf, docstring const &); /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// diff --git a/src/mathed/InsetMathArray.cpp b/src/mathed/InsetMathArray.cpp index f8cc87e772..fd7ceebe31 100644 --- a/src/mathed/InsetMathArray.cpp +++ b/src/mathed/InsetMathArray.cpp @@ -28,19 +28,21 @@ using namespace std; namespace lyx { -InsetMathArray::InsetMathArray(docstring const & name, int m, int n) - : InsetMathGrid(m, n), name_(name) +InsetMathArray::InsetMathArray(Buffer * buf, docstring const & name, int m, + int n) + : InsetMathGrid(buf, m, n), name_(name) {} -InsetMathArray::InsetMathArray(docstring const & name, int m, int n, - char valign, docstring const & halign) - : InsetMathGrid(m, n, valign, halign), name_(name) +InsetMathArray::InsetMathArray(Buffer * buf, docstring const & name, int m, + int n, char valign, docstring const & halign) + : InsetMathGrid(buf, m, n, valign, halign), name_(name) {} -InsetMathArray::InsetMathArray(docstring const & name, docstring const & str) - : InsetMathGrid(1, 1), name_(name) +InsetMathArray::InsetMathArray(Buffer * buf, docstring const & name, + docstring const & str) + : InsetMathGrid(buf, 1, 1), name_(name) { vector< vector > dat; istringstream is(to_utf8(str)); @@ -60,8 +62,7 @@ InsetMathArray::InsetMathArray(docstring const & name, docstring const & str) for (row_type row = 0; row < dat.size(); ++row) for (col_type col = 0; col < dat[0].size(); ++col) mathed_parse_cell(cell(index(row, col)), - from_utf8(dat[row][col]), - Parse::NORMAL, &buffer()); + from_utf8(dat[row][col]), Parse::NORMAL); } diff --git a/src/mathed/InsetMathArray.h b/src/mathed/InsetMathArray.h index 8768b3ed0f..79236882c7 100644 --- a/src/mathed/InsetMathArray.h +++ b/src/mathed/InsetMathArray.h @@ -22,12 +22,12 @@ namespace lyx { class InsetMathArray : public InsetMathGrid { public: /// - InsetMathArray(docstring const &, int m, int n); + InsetMathArray(Buffer * buf, docstring const &, int m, int n); /// - InsetMathArray(docstring const &, int m, int n, + InsetMathArray(Buffer * buf, docstring const &, int m, int n, char valign, docstring const & halign); /// convenience constructor from whitespace/newline separated data - InsetMathArray(docstring const &, docstring const & str); + InsetMathArray(Buffer * buf, docstring const &, docstring const & str); /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// diff --git a/src/mathed/InsetMathBoldSymbol.cpp b/src/mathed/InsetMathBoldSymbol.cpp index e53ff6c6cd..7382dc4dae 100644 --- a/src/mathed/InsetMathBoldSymbol.cpp +++ b/src/mathed/InsetMathBoldSymbol.cpp @@ -21,8 +21,8 @@ namespace lyx { -InsetMathBoldSymbol::InsetMathBoldSymbol(Kind kind) - : InsetMathNest(1), kind_(kind) +InsetMathBoldSymbol::InsetMathBoldSymbol(Buffer * buf, Kind kind) + : InsetMathNest(buf, 1), kind_(kind) {} diff --git a/src/mathed/InsetMathBoldSymbol.h b/src/mathed/InsetMathBoldSymbol.h index 67b0dfa4b7..77d27bc965 100644 --- a/src/mathed/InsetMathBoldSymbol.h +++ b/src/mathed/InsetMathBoldSymbol.h @@ -27,7 +27,7 @@ public: BM_HEAVY }; /// - InsetMathBoldSymbol(Kind kind = AMS_BOLD); + InsetMathBoldSymbol(Buffer * buf, Kind kind = AMS_BOLD); /// docstring name() const; /// diff --git a/src/mathed/InsetMathBox.cpp b/src/mathed/InsetMathBox.cpp index ab73d91448..07866610de 100644 --- a/src/mathed/InsetMathBox.cpp +++ b/src/mathed/InsetMathBox.cpp @@ -32,8 +32,8 @@ namespace lyx { // ///////////////////////////////////////////////////////////////////// -InsetMathBox::InsetMathBox(docstring const & name) - : InsetMathNest(1), name_(name) +InsetMathBox::InsetMathBox(Buffer * buf, docstring const & name) + : InsetMathNest(buf, 1), name_(name) {} @@ -90,8 +90,8 @@ void InsetMathBox::validate(LaTeXFeatures & features) const ///////////////////////////////////////////////////////////////////// -InsetMathFBox::InsetMathFBox() - : InsetMathNest(1) +InsetMathFBox::InsetMathFBox(Buffer * buf) + : InsetMathNest(buf, 1) {} @@ -140,8 +140,8 @@ void InsetMathFBox::infoize(odocstream & os) const ///////////////////////////////////////////////////////////////////// -InsetMathMakebox::InsetMathMakebox(bool framebox) - : InsetMathNest(3), framebox_(framebox) +InsetMathMakebox::InsetMathMakebox(Buffer * buf, bool framebox) + : InsetMathNest(buf, 3), framebox_(framebox) {} @@ -245,8 +245,8 @@ void InsetMathMakebox::infoize(odocstream & os) const // ///////////////////////////////////////////////////////////////////// -InsetMathBoxed::InsetMathBoxed() - : InsetMathNest(1) +InsetMathBoxed::InsetMathBoxed(Buffer * buf) + : InsetMathNest(buf, 1) {} diff --git a/src/mathed/InsetMathBox.h b/src/mathed/InsetMathBox.h index 5839439ed7..fd8cc4ffb3 100644 --- a/src/mathed/InsetMathBox.h +++ b/src/mathed/InsetMathBox.h @@ -23,7 +23,7 @@ namespace lyx { class InsetMathBox : public InsetMathNest { public: /// - explicit InsetMathBox(docstring const & name); + explicit InsetMathBox(Buffer * buf, docstring const & name); /// mode_type currentMode() const { return TEXT_MODE; } /// @@ -52,7 +52,7 @@ private: class InsetMathFBox : public InsetMathNest { public: /// - InsetMathFBox(); + InsetMathFBox(Buffer * buf); /// mode_type currentMode() const { return TEXT_MODE; } /// @@ -75,7 +75,7 @@ private: class InsetMathMakebox : public InsetMathNest { public: /// - InsetMathMakebox(bool framebox); + InsetMathMakebox(Buffer * buf, bool framebox); /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// @@ -100,7 +100,7 @@ private: class InsetMathBoxed : public InsetMathNest { public: /// - InsetMathBoxed(); + InsetMathBoxed(Buffer * buf); /// void validate(LaTeXFeatures & features) const; /// diff --git a/src/mathed/InsetMathBrace.cpp b/src/mathed/InsetMathBrace.cpp index d2d2e3fc16..c1034c9aee 100644 --- a/src/mathed/InsetMathBrace.cpp +++ b/src/mathed/InsetMathBrace.cpp @@ -26,13 +26,13 @@ using namespace std; namespace lyx { -InsetMathBrace::InsetMathBrace() - : InsetMathNest(1) +InsetMathBrace::InsetMathBrace(Buffer * buf) + : InsetMathNest(buf, 1) {} InsetMathBrace::InsetMathBrace(MathData const & ar) - : InsetMathNest(1) + : InsetMathNest(const_cast(ar.buffer()), 1) { cell(0) = ar; } diff --git a/src/mathed/InsetMathBrace.h b/src/mathed/InsetMathBrace.h index 4893db7c69..e8e3ea9557 100644 --- a/src/mathed/InsetMathBrace.h +++ b/src/mathed/InsetMathBrace.h @@ -22,7 +22,7 @@ namespace lyx { class InsetMathBrace : public InsetMathNest { public: /// - InsetMathBrace(); + InsetMathBrace(Buffer * buf); /// InsetMathBrace(MathData const & ar); /// identifies brace insets diff --git a/src/mathed/InsetMathCases.cpp b/src/mathed/InsetMathCases.cpp index 32aa5a5e0f..5e1ee21fdb 100644 --- a/src/mathed/InsetMathCases.cpp +++ b/src/mathed/InsetMathCases.cpp @@ -32,8 +32,8 @@ using namespace lyx::support; namespace lyx { -InsetMathCases::InsetMathCases(row_type n) - : InsetMathGrid(2, n, 'c', from_ascii("ll")) +InsetMathCases::InsetMathCases(Buffer * buf, row_type n) + : InsetMathGrid(buf, 2, n, 'c', from_ascii("ll")) {} diff --git a/src/mathed/InsetMathCases.h b/src/mathed/InsetMathCases.h index 9ceac475ea..d5abb1eea6 100644 --- a/src/mathed/InsetMathCases.h +++ b/src/mathed/InsetMathCases.h @@ -23,7 +23,7 @@ class LaTeXFeatures; class InsetMathCases : public InsetMathGrid { public: /// - explicit InsetMathCases(row_type rows = 1u); + explicit InsetMathCases(Buffer * buf, row_type rows = 1u); /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// diff --git a/src/mathed/InsetMathColor.cpp b/src/mathed/InsetMathColor.cpp index 233a38090c..7d005621e6 100644 --- a/src/mathed/InsetMathColor.cpp +++ b/src/mathed/InsetMathColor.cpp @@ -24,14 +24,15 @@ namespace lyx { -InsetMathColor::InsetMathColor(bool oldstyle, ColorCode color) - : InsetMathNest(1), oldstyle_(oldstyle), +InsetMathColor::InsetMathColor(Buffer * buf, bool oldstyle, ColorCode color) + : InsetMathNest(buf, 1), oldstyle_(oldstyle), color_(from_utf8(lcolor.getLaTeXName(color))) {} -InsetMathColor::InsetMathColor(bool oldstyle, docstring const & color) - : InsetMathNest(1), oldstyle_(oldstyle), color_(color) +InsetMathColor::InsetMathColor(Buffer * buf, bool oldstyle, + docstring const & color) + : InsetMathNest(buf, 1), oldstyle_(oldstyle), color_(color) {} diff --git a/src/mathed/InsetMathColor.h b/src/mathed/InsetMathColor.h index 19f1636b17..848a46fc7c 100644 --- a/src/mathed/InsetMathColor.h +++ b/src/mathed/InsetMathColor.h @@ -23,10 +23,9 @@ namespace lyx { class InsetMathColor : public InsetMathNest { public: /// Create a color inset from LyX color number - explicit InsetMathColor(bool oldstyle, - ColorCode color = Color_none); + InsetMathColor(Buffer * buf, bool oldstyle, ColorCode color = Color_none); /// Create a color inset from LaTeX color name - explicit InsetMathColor(bool oldstyle, docstring const & color); + InsetMathColor(Buffer * buf, bool oldstyle, docstring const & color); /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// we write extra braces in any case... diff --git a/src/mathed/InsetMathComment.cpp b/src/mathed/InsetMathComment.cpp index f64f372900..ebfba7a859 100644 --- a/src/mathed/InsetMathComment.cpp +++ b/src/mathed/InsetMathComment.cpp @@ -21,13 +21,13 @@ namespace lyx { -InsetMathComment::InsetMathComment() - : InsetMathNest(1) +InsetMathComment::InsetMathComment(Buffer * buf) + : InsetMathNest(buf, 1) {} -InsetMathComment::InsetMathComment(docstring const & str) - : InsetMathNest(1) +InsetMathComment::InsetMathComment(Buffer * buf, docstring const & str) + : InsetMathNest(buf, 1) { // FIXME UNICODE asArray(str, cell(0)); diff --git a/src/mathed/InsetMathComment.h b/src/mathed/InsetMathComment.h index 8699cedbba..bb775a74cb 100644 --- a/src/mathed/InsetMathComment.h +++ b/src/mathed/InsetMathComment.h @@ -23,9 +23,9 @@ class latexkeys; class InsetMathComment : public InsetMathNest { public: /// - InsetMathComment(); + InsetMathComment(Buffer * buf); /// - explicit InsetMathComment(docstring const &); + explicit InsetMathComment(Buffer * buf, docstring const &); /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// diff --git a/src/mathed/InsetMathDecoration.cpp b/src/mathed/InsetMathDecoration.cpp index 026b3da672..0ece491a7d 100644 --- a/src/mathed/InsetMathDecoration.cpp +++ b/src/mathed/InsetMathDecoration.cpp @@ -29,8 +29,8 @@ namespace lyx { -InsetMathDecoration::InsetMathDecoration(latexkeys const * key) - : InsetMathNest(1), key_(key) +InsetMathDecoration::InsetMathDecoration(Buffer * buf, latexkeys const * key) + : InsetMathNest(buf, 1), key_(key) { // lyxerr << " creating deco " << key->name << endl; } diff --git a/src/mathed/InsetMathDecoration.h b/src/mathed/InsetMathDecoration.h index 3fa1be7075..a8106d4889 100644 --- a/src/mathed/InsetMathDecoration.h +++ b/src/mathed/InsetMathDecoration.h @@ -24,7 +24,7 @@ class latexkeys; class InsetMathDecoration : public InsetMathNest { public: /// - explicit InsetMathDecoration(latexkeys const * key); + explicit InsetMathDecoration(Buffer * buf, latexkeys const * key); /// void draw(PainterInfo &, int x, int y) const; /// diff --git a/src/mathed/InsetMathDelim.cpp b/src/mathed/InsetMathDelim.cpp index 95a172ea64..4c873f15e8 100644 --- a/src/mathed/InsetMathDelim.cpp +++ b/src/mathed/InsetMathDelim.cpp @@ -38,14 +38,15 @@ static docstring convertDelimToLatexName(docstring const & name) } -InsetMathDelim::InsetMathDelim(docstring const & l, docstring const & r) - : InsetMathNest(1), left_(l), right_(r) +InsetMathDelim::InsetMathDelim(Buffer * buf, docstring const & l, + docstring const & r) + : InsetMathNest(buf, 1), left_(l), right_(r) {} -InsetMathDelim::InsetMathDelim - (docstring const & l, docstring const & r, MathData const & ar) - : InsetMathNest(1), left_(l), right_(r) +InsetMathDelim::InsetMathDelim(Buffer * buf, docstring const & l, docstring const & r, + MathData const & ar) + : InsetMathNest(buf, 1), left_(l), right_(r) { cell(0) = ar; } diff --git a/src/mathed/InsetMathDelim.h b/src/mathed/InsetMathDelim.h index de7f11442b..67e1db0906 100644 --- a/src/mathed/InsetMathDelim.h +++ b/src/mathed/InsetMathDelim.h @@ -24,9 +24,10 @@ namespace lyx { class InsetMathDelim : public InsetMathNest { public: /// - InsetMathDelim(docstring const & left, docstring const & right); + InsetMathDelim(Buffer * buf, docstring const & left, docstring const & right); /// - InsetMathDelim(docstring const & left, docstring const & right, MathData const &); + InsetMathDelim(Buffer * buf, docstring const & left, docstring const & right, + MathData const &); /// InsetMathDelim * asDelimInset() { return this; } /// diff --git a/src/mathed/InsetMathDiff.cpp b/src/mathed/InsetMathDiff.cpp index f4d544bbb6..1e990d7ffb 100644 --- a/src/mathed/InsetMathDiff.cpp +++ b/src/mathed/InsetMathDiff.cpp @@ -19,8 +19,8 @@ namespace lyx { -InsetMathDiff::InsetMathDiff() - : InsetMathNest(1) +InsetMathDiff::InsetMathDiff(Buffer * buf) + : InsetMathNest(buf, 1) {} diff --git a/src/mathed/InsetMathDiff.h b/src/mathed/InsetMathDiff.h index 557f16fed2..6253168397 100644 --- a/src/mathed/InsetMathDiff.h +++ b/src/mathed/InsetMathDiff.h @@ -24,7 +24,7 @@ namespace lyx { class InsetMathDiff : public InsetMathNest { public: /// - InsetMathDiff(); + InsetMathDiff(Buffer * buf); /// void addDer(MathData const & der); /// diff --git a/src/mathed/InsetMathEnsureMath.cpp b/src/mathed/InsetMathEnsureMath.cpp index eb8da97827..f06cbe5552 100644 --- a/src/mathed/InsetMathEnsureMath.cpp +++ b/src/mathed/InsetMathEnsureMath.cpp @@ -21,8 +21,8 @@ namespace lyx { -InsetMathEnsureMath::InsetMathEnsureMath() - : InsetMathNest(1) +InsetMathEnsureMath::InsetMathEnsureMath(Buffer * buf) + : InsetMathNest(buf, 1) {} diff --git a/src/mathed/InsetMathEnsureMath.h b/src/mathed/InsetMathEnsureMath.h index d6e9a242b5..1bad7c8fb6 100644 --- a/src/mathed/InsetMathEnsureMath.h +++ b/src/mathed/InsetMathEnsureMath.h @@ -22,7 +22,7 @@ namespace lyx { /// Inset for ensuring math mode class InsetMathEnsureMath : public InsetMathNest { public: - InsetMathEnsureMath(); + InsetMathEnsureMath(Buffer * buf); /// mode_type currentMode() const { return MATH_MODE; } /// diff --git a/src/mathed/InsetMathEnv.cpp b/src/mathed/InsetMathEnv.cpp index e350d19a98..a7fb33c69d 100644 --- a/src/mathed/InsetMathEnv.cpp +++ b/src/mathed/InsetMathEnv.cpp @@ -21,8 +21,8 @@ namespace lyx { -InsetMathEnv::InsetMathEnv(docstring const & name) - : InsetMathNest(1), name_(name) +InsetMathEnv::InsetMathEnv(Buffer * buf, docstring const & name) + : InsetMathNest(buf, 1), name_(name) {} diff --git a/src/mathed/InsetMathEnv.h b/src/mathed/InsetMathEnv.h index 035aa68e5c..14b72072bc 100644 --- a/src/mathed/InsetMathEnv.h +++ b/src/mathed/InsetMathEnv.h @@ -24,7 +24,7 @@ namespace lyx { class InsetMathEnv : public InsetMathNest { public: /// - InsetMathEnv(docstring const & name_); + InsetMathEnv(Buffer * buf, docstring const & name_); /// void draw(PainterInfo &, int x, int y) const; /// diff --git a/src/mathed/InsetMathExFunc.cpp b/src/mathed/InsetMathExFunc.cpp index 990040ef7c..3398e9049a 100644 --- a/src/mathed/InsetMathExFunc.cpp +++ b/src/mathed/InsetMathExFunc.cpp @@ -24,13 +24,13 @@ using namespace std; namespace lyx { -InsetMathExFunc::InsetMathExFunc(docstring const & name) - : InsetMathNest(1), name_(name) +InsetMathExFunc::InsetMathExFunc(Buffer * buf, docstring const & name) + : InsetMathNest(buf, 1), name_(name) {} -InsetMathExFunc::InsetMathExFunc(docstring const & name, MathData const & ar) - : InsetMathNest(1), name_(name) +InsetMathExFunc::InsetMathExFunc(Buffer * buf, docstring const & name, MathData const & ar) + : InsetMathNest(buf, 1), name_(name) { cell(0) = ar; } diff --git a/src/mathed/InsetMathExFunc.h b/src/mathed/InsetMathExFunc.h index 7a5b25310f..fb6dda8b36 100644 --- a/src/mathed/InsetMathExFunc.h +++ b/src/mathed/InsetMathExFunc.h @@ -26,9 +26,9 @@ namespace lyx { class InsetMathExFunc : public InsetMathNest { public: /// - explicit InsetMathExFunc(docstring const & name); + InsetMathExFunc(Buffer * buf, docstring const & name); /// - InsetMathExFunc(docstring const & name, MathData const & ar); + InsetMathExFunc(Buffer * buf, docstring const & name, MathData const & ar); /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// diff --git a/src/mathed/InsetMathExInt.cpp b/src/mathed/InsetMathExInt.cpp index d3753de9db..5313f0adc3 100644 --- a/src/mathed/InsetMathExInt.cpp +++ b/src/mathed/InsetMathExInt.cpp @@ -22,8 +22,8 @@ namespace lyx { -InsetMathExInt::InsetMathExInt(docstring const & name) - : InsetMathNest(4), symbol_(name) +InsetMathExInt::InsetMathExInt(Buffer * buf, docstring const & name) + : InsetMathNest(buf, 4), symbol_(name) {} // 0 - core diff --git a/src/mathed/InsetMathExInt.h b/src/mathed/InsetMathExInt.h index 00f7ed9f57..a4d2e8e90d 100644 --- a/src/mathed/InsetMathExInt.h +++ b/src/mathed/InsetMathExInt.h @@ -25,7 +25,7 @@ namespace lyx { class InsetMathExInt : public InsetMathNest { public: /// - explicit InsetMathExInt(docstring const & name_); + explicit InsetMathExInt(Buffer * buf, docstring const & name_); /// void symbol(docstring const &); /// diff --git a/src/mathed/InsetMathFont.cpp b/src/mathed/InsetMathFont.cpp index 7f55851d21..57078817d6 100644 --- a/src/mathed/InsetMathFont.cpp +++ b/src/mathed/InsetMathFont.cpp @@ -23,8 +23,8 @@ namespace lyx { -InsetMathFont::InsetMathFont(latexkeys const * key) - : InsetMathNest(1), key_(key) +InsetMathFont::InsetMathFont(Buffer * buf, latexkeys const * key) + : InsetMathNest(buf, 1), key_(key) {} diff --git a/src/mathed/InsetMathFont.h b/src/mathed/InsetMathFont.h index e002ad1a11..e687bc0ede 100644 --- a/src/mathed/InsetMathFont.h +++ b/src/mathed/InsetMathFont.h @@ -24,7 +24,7 @@ class latexkeys; class InsetMathFont : public InsetMathNest { public: /// - explicit InsetMathFont(latexkeys const * key); + explicit InsetMathFont(Buffer * buf, latexkeys const * key); /// InsetMathFont * asFontInset() { return this; } /// diff --git a/src/mathed/InsetMathFontOld.cpp b/src/mathed/InsetMathFontOld.cpp index 6b132cfc27..f4b87ba4c6 100644 --- a/src/mathed/InsetMathFontOld.cpp +++ b/src/mathed/InsetMathFontOld.cpp @@ -22,8 +22,8 @@ namespace lyx { -InsetMathFontOld::InsetMathFontOld(latexkeys const * key) - : InsetMathNest(1), key_(key) +InsetMathFontOld::InsetMathFontOld(Buffer * buf, latexkeys const * key) + : InsetMathNest(buf, 1), key_(key) { //lock(true); } diff --git a/src/mathed/InsetMathFontOld.h b/src/mathed/InsetMathFontOld.h index 61d55b0e75..c27bfa6658 100644 --- a/src/mathed/InsetMathFontOld.h +++ b/src/mathed/InsetMathFontOld.h @@ -24,7 +24,7 @@ class latexkeys; class InsetMathFontOld : public InsetMathNest { public: /// - explicit InsetMathFontOld(latexkeys const * key); + explicit InsetMathFontOld(Buffer * buf, latexkeys const * key); /// we are in text mode. mode_type currentMode() const { return TEXT_MODE; } /// we write extra braces in any case... diff --git a/src/mathed/InsetMathFrac.cpp b/src/mathed/InsetMathFrac.cpp index 2c2d697543..7f5323b8d6 100644 --- a/src/mathed/InsetMathFrac.cpp +++ b/src/mathed/InsetMathFrac.cpp @@ -35,8 +35,8 @@ namespace lyx { ///////////////////////////////////////////////////////////////////// -InsetMathFracBase::InsetMathFracBase(idx_type ncells) - : InsetMathNest(ncells) +InsetMathFracBase::InsetMathFracBase(Buffer * buf, idx_type ncells) + : InsetMathNest(buf, ncells) {} @@ -59,8 +59,8 @@ bool InsetMathFracBase::idxUpDown(Cursor & cur, bool up) const ///////////////////////////////////////////////////////////////////// -InsetMathFrac::InsetMathFrac(Kind kind, InsetMath::idx_type ncells) - : InsetMathFracBase(ncells), kind_(kind) +InsetMathFrac::InsetMathFrac(Buffer * buf, Kind kind, InsetMath::idx_type ncells) + : InsetMathFracBase(buf, ncells), kind_(kind) {} @@ -417,8 +417,8 @@ void InsetMathFrac::validate(LaTeXFeatures & features) const ///////////////////////////////////////////////////////////////////// -InsetMathBinom::InsetMathBinom(Kind kind) - : kind_(kind) +InsetMathBinom::InsetMathBinom(Buffer * buf, Kind kind) + : InsetMathFracBase(buf), kind_(kind) {} diff --git a/src/mathed/InsetMathFrac.h b/src/mathed/InsetMathFrac.h index 3d9b3854e2..36e7ba363b 100644 --- a/src/mathed/InsetMathFrac.h +++ b/src/mathed/InsetMathFrac.h @@ -23,7 +23,7 @@ namespace lyx { class InsetMathFracBase : public InsetMathNest { public: /// - explicit InsetMathFracBase(idx_type ncells = 2); + InsetMathFracBase(Buffer * buf, idx_type ncells = 2); /// bool idxUpDown(Cursor &, bool up) const; /// @@ -52,7 +52,7 @@ public: UNIT }; /// - explicit InsetMathFrac(Kind kind = FRAC, idx_type ncells = 2); + explicit InsetMathFrac(Buffer * buf, Kind kind = FRAC, idx_type ncells = 2); /// bool idxForward(Cursor &) const; /// @@ -106,7 +106,7 @@ public: BRACK }; /// - explicit InsetMathBinom(Kind kind = BINOM); + explicit InsetMathBinom(Buffer * buf, Kind kind = BINOM); /// void write(WriteStream & os) const; /// diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp index 4a7a685c1a..46148a6628 100644 --- a/src/mathed/InsetMathGrid.cpp +++ b/src/mathed/InsetMathGrid.cpp @@ -112,8 +112,8 @@ InsetMathGrid::ColInfo::ColInfo() ////////////////////////////////////////////////////////////// -InsetMathGrid::InsetMathGrid() - : InsetMathNest(1), +InsetMathGrid::InsetMathGrid(Buffer * buf) + : InsetMathNest(buf, 1), rowinfo_(1 + 1), colinfo_(1 + 1), cellinfo_(1), @@ -123,8 +123,8 @@ InsetMathGrid::InsetMathGrid() } -InsetMathGrid::InsetMathGrid(col_type m, row_type n) - : InsetMathNest(m * n), +InsetMathGrid::InsetMathGrid(Buffer * buf, col_type m, row_type n) + : InsetMathNest(buf, m * n), rowinfo_(n + 1), colinfo_(m + 1), cellinfo_(m * n), @@ -134,8 +134,9 @@ InsetMathGrid::InsetMathGrid(col_type m, row_type n) } -InsetMathGrid::InsetMathGrid(col_type m, row_type n, char v, docstring const & h) - : InsetMathNest(m * n), +InsetMathGrid::InsetMathGrid(Buffer * buf, col_type m, row_type n, char v, + docstring const & h) + : InsetMathNest(buf, m * n), rowinfo_(n + 1), colinfo_(m + 1), cellinfo_(m * n), @@ -1273,15 +1274,12 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd) is >> n; topaste = cap::selection(n); } - InsetMathGrid grid(1, 1); + InsetMathGrid grid(buffer_, 1, 1); if (!topaste.empty()) if ((topaste.size() == 1 && topaste.at(0) < 0x80) - || !mathed_parse_normal(grid, topaste, parseflg, - cur.buffer())) { + || !mathed_parse_normal(grid, topaste, parseflg)) { resetGrid(grid); - mathed_parse_normal(grid, topaste, - parseflg | Parse::VERBATIM, - cur.buffer()); + mathed_parse_normal(grid, topaste, parseflg | Parse::VERBATIM); } if (grid.nargs() == 1) { diff --git a/src/mathed/InsetMathGrid.h b/src/mathed/InsetMathGrid.h index a512969afb..926216ea1c 100644 --- a/src/mathed/InsetMathGrid.h +++ b/src/mathed/InsetMathGrid.h @@ -92,11 +92,12 @@ public: public: /// sets nrows and ncols to 1, vertical alingment to 'c' - InsetMathGrid(); + InsetMathGrid(Buffer * buf); /// Note: columns first! - InsetMathGrid(col_type m, row_type n); + InsetMathGrid(Buffer * buf, col_type m, row_type n); /// - InsetMathGrid(col_type m, row_type n, char valign, docstring const & halign); + InsetMathGrid(Buffer * buf, col_type m, row_type n, char valign, + docstring const & halign); /// void metrics(MetricsInfo & mi, Dimension &) const; /// diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index 92fa33ecdf..d7e085582a 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -136,7 +136,7 @@ docstring hullName(HullType type) static InsetLabel * dummy_pointer = 0; InsetMathHull::InsetMathHull(Buffer * buf) - : InsetMathGrid(1, 1), type_(hullNone), nonum_(1, false), + : InsetMathGrid(buf, 1, 1), type_(hullNone), nonum_(1, false), label_(1, dummy_pointer), preview_(new RenderPreview(this)) { //lyxerr << "sizeof InsetMath: " << sizeof(InsetMath) << endl; @@ -149,8 +149,8 @@ InsetMathHull::InsetMathHull(Buffer * buf) } -InsetMathHull::InsetMathHull(HullType type, Buffer * buf) - : InsetMathGrid(getCols(type), 1), type_(type), nonum_(1, false), +InsetMathHull::InsetMathHull(Buffer * buf, HullType type) + : InsetMathGrid(buf, getCols(type), 1), type_(type), nonum_(1, false), label_(1, dummy_pointer), preview_(new RenderPreview(this)) { buffer_ = buf; @@ -159,7 +159,7 @@ InsetMathHull::InsetMathHull(HullType type, Buffer * buf) } -InsetMathHull::InsetMathHull(InsetMathHull const & other) : InsetMathGrid() +InsetMathHull::InsetMathHull(InsetMathHull const & other) : InsetMathGrid(other) { operator=(other); } @@ -800,7 +800,7 @@ void InsetMathHull::glueall() MathData ar; for (idx_type i = 0; i < nargs(); ++i) ar.append(cell(i)); - *this = InsetMathHull(hullSimple, &buffer()); + *this = InsetMathHull(buffer_, hullSimple); cell(0) = ar; setDefaults(); } @@ -813,7 +813,7 @@ void InsetMathHull::splitTo2Cols() for (row_type row = 0; row < nrows(); ++row) { idx_type const i = 2 * row; pos_type pos = firstRelOp(cell(i)); - cell(i + 1) = MathData(cell(i).begin() + pos, cell(i).end()); + cell(i + 1) = MathData(buffer_, cell(i).begin() + pos, cell(i).end()); cell(i).erase(pos, cell(i).size()); } } @@ -828,7 +828,7 @@ void InsetMathHull::splitTo3Cols() for (row_type row = 0; row < nrows(); ++row) { idx_type const i = 3 * row + 1; if (cell(i).size()) { - cell(i + 1) = MathData(cell(i).begin() + 1, cell(i).end()); + cell(i + 1) = MathData(buffer_, cell(i).begin() + 1, cell(i).end()); cell(i).erase(1, cell(i).size()); } } @@ -1107,7 +1107,7 @@ void InsetMathHull::doExtern(Cursor & cur, FuncRequest & func) ar = cur.cell(); lyxerr << "use whole cell: " << ar << endl; } else { - ar = MathData(cur.cell().begin() + pos + 1, cur.cell().end()); + ar = MathData(buffer_, cur.cell().begin() + pos + 1, cur.cell().end()); lyxerr << "use partial cell form pos: " << pos << endl; } cur.cell().append(eq); @@ -1512,7 +1512,7 @@ void InsetMathHull::handleFont(Cursor & cur, docstring const & arg, if (cur.inset().asInsetMath()->name() == font) cur.handleFont(to_utf8(font)); else { - cur.handleNest(createInsetMath(font)); + cur.handleNest(createInsetMath(font, cur.buffer())); cur.insert(arg); } } @@ -1525,7 +1525,7 @@ void InsetMathHull::handleFont2(Cursor & cur, docstring const & arg) bool b; font.fromString(to_utf8(arg), b); if (font.fontInfo().color() != Color_inherit) { - MathAtom at = MathAtom(new InsetMathColor(true, font.fontInfo().color())); + MathAtom at = MathAtom(new InsetMathColor(buffer_, true, font.fontInfo().color())); cur.handleNest(at, 0); } } @@ -1637,7 +1637,7 @@ void InsetMathHull::write(ostream & os) const void InsetMathHull::read(Lexer & lex) { MathAtom at; - mathed_parse_normal(at, lex, Parse::NORMAL, &buffer()); + mathed_parse_normal(buffer_, at, lex, Parse::NORMAL); operator=(*at->asHullInset()); } @@ -1645,7 +1645,7 @@ void InsetMathHull::read(Lexer & lex) bool InsetMathHull::readQuiet(Lexer & lex) { MathAtom at; - bool success = mathed_parse_normal(at, lex, Parse::QUIET, &buffer()); + bool success = mathed_parse_normal(buffer_, at, lex, Parse::QUIET); if (success) operator=(*at->asHullInset()); return success; diff --git a/src/mathed/InsetMathHull.h b/src/mathed/InsetMathHull.h index bde73af1b9..4cdb1b4f88 100644 --- a/src/mathed/InsetMathHull.h +++ b/src/mathed/InsetMathHull.h @@ -28,9 +28,9 @@ class RenderPreview; class InsetMathHull : public InsetMathGrid { public: /// - InsetMathHull(Buffer * buf = 0); + InsetMathHull(Buffer * buf); /// - explicit InsetMathHull(HullType type, Buffer * buf = 0); + InsetMathHull(Buffer * buf, HullType type); /// ~InsetMathHull(); /// diff --git a/src/mathed/InsetMathLefteqn.cpp b/src/mathed/InsetMathLefteqn.cpp index 838ff25080..ec4fe7e9b0 100644 --- a/src/mathed/InsetMathLefteqn.cpp +++ b/src/mathed/InsetMathLefteqn.cpp @@ -17,8 +17,8 @@ namespace lyx { -InsetMathLefteqn::InsetMathLefteqn() - : InsetMathNest(1) +InsetMathLefteqn::InsetMathLefteqn(Buffer * buf) + : InsetMathNest(buf, 1) {} diff --git a/src/mathed/InsetMathLefteqn.h b/src/mathed/InsetMathLefteqn.h index 6742e7327e..1adb0bd400 100644 --- a/src/mathed/InsetMathLefteqn.h +++ b/src/mathed/InsetMathLefteqn.h @@ -23,7 +23,7 @@ namespace lyx { class InsetMathLefteqn : public InsetMathNest { public: /// - InsetMathLefteqn(); + InsetMathLefteqn(Buffer * buf); /// docstring name() const; /// diff --git a/src/mathed/InsetMathLim.cpp b/src/mathed/InsetMathLim.cpp index 508acc237e..892cded83d 100644 --- a/src/mathed/InsetMathLim.cpp +++ b/src/mathed/InsetMathLim.cpp @@ -19,9 +19,9 @@ namespace lyx { -InsetMathLim::InsetMathLim - (MathData const & f, MathData const & x, MathData const & x0) - : InsetMathNest(3) +InsetMathLim::InsetMathLim(Buffer * buf, MathData const & f, MathData const & x, + MathData const & x0) + : InsetMathNest(buf, 3) { cell(0) = f; cell(1) = x; diff --git a/src/mathed/InsetMathLim.h b/src/mathed/InsetMathLim.h index f10055b436..11d18dc06e 100644 --- a/src/mathed/InsetMathLim.h +++ b/src/mathed/InsetMathLim.h @@ -24,7 +24,8 @@ namespace lyx { class InsetMathLim : public InsetMathNest { public: /// - InsetMathLim(MathData const & f, MathData const & x, MathData const & x0); + InsetMathLim(Buffer * buf, MathData const & f, MathData const & x, + MathData const & x0); /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// diff --git a/src/mathed/InsetMathMatrix.h b/src/mathed/InsetMathMatrix.h index 11fa18349c..570b39b081 100644 --- a/src/mathed/InsetMathMatrix.h +++ b/src/mathed/InsetMathMatrix.h @@ -25,7 +25,7 @@ public: /// explicit InsetMathMatrix(InsetMathGrid const &); /// - explicit InsetMathMatrix(docstring const & str); + explicit InsetMathMatrix(Buffer * buf, docstring const & str); /// identifies MatrixInsets InsetMathMatrix const * asMatrixInset() const { return this; } diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp index c1fbc12e0b..d49b9af500 100644 --- a/src/mathed/InsetMathNest.cpp +++ b/src/mathed/InsetMathNest.cpp @@ -79,9 +79,11 @@ using cap::replaceSelection; using cap::selClearOrDel; -InsetMathNest::InsetMathNest(idx_type nargs) - : cells_(nargs), lock_(false), mouse_hover_(false) -{} +InsetMathNest::InsetMathNest(Buffer * buf, idx_type nargs) + : InsetMath(buf), cells_(nargs), lock_(false), mouse_hover_(false) +{ + setBuffer(*buf); +} InsetMathNest::InsetMathNest(InsetMathNest const & inset) @@ -440,7 +442,7 @@ void InsetMathNest::handleFont(Cursor & cur, docstring const & arg, if (cur.inset().asInsetMath()->name() == font) cur.handleFont(to_utf8(font)); else - handleNest(cur, createInsetMath(font), arg); + handleNest(cur, createInsetMath(font, cur.buffer()), arg); } @@ -520,7 +522,7 @@ void InsetMathNest::handleFont2(Cursor & cur, docstring const & arg) font.fromString(to_utf8(arg), b); if (font.fontInfo().color() != Color_inherit && font.fontInfo().color() != Color_ignore) - handleNest(cur, MathAtom(new InsetMathColor(true, font.fontInfo().color()))); + handleNest(cur, MathAtom(new InsetMathColor(buffer_, true, font.fontInfo().color()))); // FIXME: support other font changes here as well? } @@ -955,7 +957,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd) case LFUN_FONT_UNDERLINE: cur.recordUndo(); - cur.handleNest(createInsetMath("underline")); + cur.handleNest(createInsetMath("underline", cur.buffer())); break; case LFUN_MATH_MODE: { #if 1 @@ -968,9 +970,9 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd) selClearOrDel(cur); //cur.plainInsert(MathAtom(new InsetMathMBox(cur.bv()))); if (currentMode() <= Inset::TEXT_MODE) - cur.plainInsert(MathAtom(new InsetMathEnsureMath)); + cur.plainInsert(MathAtom(new InsetMathEnsureMath(buffer_))); else - cur.plainInsert(MathAtom(new InsetMathBox(from_ascii("mbox")))); + cur.plainInsert(MathAtom(new InsetMathBox(buffer_, from_ascii("mbox")))); cur.posBackward(); cur.pushBackward(*cur.nextInset()); cur.niceInsert(save_selection); @@ -996,7 +998,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd) cur.macroModeClose(); docstring const save_selection = grabAndEraseSelection(cur); selClearOrDel(cur); - cur.plainInsert(MathAtom(new InsetMathHull(hullRegexp, cur.buffer()))); + cur.plainInsert(MathAtom(new InsetMathHull(buffer_, hullRegexp))); cur.posBackward(); cur.pushBackward(*cur.nextInset()); cur.niceInsert(save_selection); @@ -1029,8 +1031,8 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd) if (n < 1) n = 1; v_align += 'c'; - cur.niceInsert( - MathAtom(new InsetMathArray(from_ascii("array"), m, n, (char)v_align[0], h_align))); + cur.niceInsert(MathAtom(new InsetMathArray(buffer_, + from_ascii("array"), m, n, (char)v_align[0], h_align))); break; } @@ -1046,7 +1048,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd) if (n < 1) n = 1; cur.niceInsert( - MathAtom(new InsetMathAMSArray(name, m, n))); + MathAtom(new InsetMathAMSArray(buffer_, name, m, n))); break; } @@ -1059,7 +1061,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd) if (rs.empty()) rs = ')'; cur.recordUndo(); - cur.handleNest(MathAtom(new InsetMathDelim(ls, rs))); + cur.handleNest(MathAtom(new InsetMathDelim(buffer_, ls, rs))); break; } @@ -1173,7 +1175,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd) docstring const & name = cmd.argument(); string data; if (name == "ref") { - InsetMathRef tmp(name); + InsetMathRef tmp(buffer_, name); data = tmp.createDialogStr(to_utf8(name)); } else if (name == "mathspace") { InsetMathSpace tmp; @@ -1473,6 +1475,7 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type const c) save_selection = grabAndEraseSelection(cur); cur.clearTargetX(); + Buffer * buf = cur.buffer(); // handle macroMode if (cur.inMacroMode()) { @@ -1503,24 +1506,24 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type const c) if (c == '\\') { cur.backspace(); if (currentMode() <= InsetMath::TEXT_MODE) - cur.niceInsert(createInsetMath("textbackslash")); + cur.niceInsert(createInsetMath("textbackslash", buf)); else - cur.niceInsert(createInsetMath("backslash")); + cur.niceInsert(createInsetMath("backslash", buf)); } else if (c == '^' && currentMode() == InsetMath::MATH_MODE) { cur.backspace(); - cur.niceInsert(createInsetMath("mathcircumflex")); + cur.niceInsert(createInsetMath("mathcircumflex", buf)); } else if (c == '{') { cur.backspace(); - cur.niceInsert(MathAtom(new InsetMathBrace)); + cur.niceInsert(MathAtom(new InsetMathBrace(buf))); } else if (c == '%') { cur.backspace(); - cur.niceInsert(MathAtom(new InsetMathComment)); + cur.niceInsert(MathAtom(new InsetMathComment(buf))); } else if (c == '#') { LASSERT(cur.activeMacro(), /**/); cur.activeMacro()->setName(name + docstring(1, c)); } else { cur.backspace(); - cur.niceInsert(createInsetMath(docstring(1, c))); + cur.niceInsert(createInsetMath(docstring(1, c), buf)); } return true; } @@ -1564,7 +1567,7 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type const c) } } if (c == '{') - cur.niceInsert(MathAtom(new InsetMathBrace)); + cur.niceInsert(MathAtom(new InsetMathBrace(buf))); else if (c != ' ') interpretChar(cur, c); return true; @@ -1657,11 +1660,11 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type const c) return true; } if (c == '~') { - cur.niceInsert(createInsetMath("sim")); + cur.niceInsert(createInsetMath("sim", buf)); return true; } if (currentMode() == InsetMath::MATH_MODE && !isAsciiOrMathAlpha(c)) { - MathAtom at = createInsetMath("text"); + MathAtom at = createInsetMath("text", buf); at.nucleus()->cell(0).push_back(MathAtom(new InsetMathChar(c))); cur.niceInsert(at); cur.posForward(); @@ -1669,18 +1672,18 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type const c) } } else { if (c == '^') { - cur.niceInsert(createInsetMath("textasciicircum")); + cur.niceInsert(createInsetMath("textasciicircum", buf)); return true; } if (c == '~') { - cur.niceInsert(createInsetMath("textasciitilde")); + cur.niceInsert(createInsetMath("textasciitilde", buf)); return true; } } if (c == '{' || c == '}' || c == '&' || c == '$' || c == '#' || c == '%' || c == '_') { - cur.niceInsert(createInsetMath(docstring(1, c))); + cur.niceInsert(createInsetMath(docstring(1, c), buf)); return true; } @@ -1738,7 +1741,7 @@ bool InsetMathNest::script(Cursor & cur, bool up, //lyxerr << "handling script: up: " << up << endl; if (cur.inMacroMode() && cur.macroName() == "\\") { if (up) - cur.niceInsert(createInsetMath("mathcircumflex")); + cur.niceInsert(createInsetMath("mathcircumflex", cur.buffer())); else interpretChar(cur, '_'); return true; @@ -1764,10 +1767,10 @@ bool InsetMathNest::script(Cursor & cur, bool up, // one if in the very first position of the array if (cur.pos() == 0) { //lyxerr << "new scriptinset" << endl; - cur.insert(new InsetMathScript(up)); + cur.insert(new InsetMathScript(buffer_, up)); } else { //lyxerr << "converting prev atom " << endl; - cur.prevAtom() = MathAtom(new InsetMathScript(cur.prevAtom(), up)); + cur.prevAtom() = MathAtom(new InsetMathScript(buffer_, cur.prevAtom(), up)); } --cur.pos(); InsetMathScript * inset = cur.nextAtom().nucleus()->asScriptInset(); diff --git a/src/mathed/InsetMathNest.h b/src/mathed/InsetMathNest.h index 2607f5bbbb..59c60d98d3 100644 --- a/src/mathed/InsetMathNest.h +++ b/src/mathed/InsetMathNest.h @@ -27,7 +27,7 @@ namespace lyx { class InsetMathNest : public InsetMath { public: /// nestinsets have a fixed size to start with - explicit InsetMathNest(idx_type ncells); + InsetMathNest(Buffer * buf, idx_type ncells); /// virtual ~InsetMathNest() {} /// diff --git a/src/mathed/InsetMathOverset.h b/src/mathed/InsetMathOverset.h index 0738693550..edcdd020e2 100644 --- a/src/mathed/InsetMathOverset.h +++ b/src/mathed/InsetMathOverset.h @@ -21,6 +21,8 @@ namespace lyx { /// Inset for overset class InsetMathOverset : public InsetMathFracBase { public: + /// + InsetMathOverset(Buffer * buf) : InsetMathFracBase(buf) {} /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// diff --git a/src/mathed/InsetMathPar.cpp b/src/mathed/InsetMathPar.cpp index 26445c2d0d..0638b8eb6c 100644 --- a/src/mathed/InsetMathPar.cpp +++ b/src/mathed/InsetMathPar.cpp @@ -19,7 +19,8 @@ namespace lyx { -InsetMathPar::InsetMathPar(MathData const & ar) +InsetMathPar::InsetMathPar(Buffer * buf, MathData const & ar) + : InsetMathHull(buf) { cells_[0] = ar; } diff --git a/src/mathed/InsetMathPar.h b/src/mathed/InsetMathPar.h index 05d2dabdb0..0a178f4396 100644 --- a/src/mathed/InsetMathPar.h +++ b/src/mathed/InsetMathPar.h @@ -21,9 +21,9 @@ namespace lyx { class InsetMathPar : public InsetMathHull { public: /// - InsetMathPar() {} + InsetMathPar(Buffer * buf) : InsetMathHull(buf) {} /// - InsetMathPar(MathData const & ar); + InsetMathPar(Buffer * buf, MathData const & ar); /// mode_type currentMode() const { return TEXT_MODE; } /// diff --git a/src/mathed/InsetMathPhantom.cpp b/src/mathed/InsetMathPhantom.cpp index f070e55053..d6cd1b2446 100644 --- a/src/mathed/InsetMathPhantom.cpp +++ b/src/mathed/InsetMathPhantom.cpp @@ -20,8 +20,8 @@ namespace lyx { -InsetMathPhantom::InsetMathPhantom(Kind k) - : InsetMathNest(1), kind_(k) +InsetMathPhantom::InsetMathPhantom(Buffer * buf, Kind k) + : InsetMathNest(buf, 1), kind_(k) {} diff --git a/src/mathed/InsetMathPhantom.h b/src/mathed/InsetMathPhantom.h index 9d21bbdeff..cbc01b0435 100644 --- a/src/mathed/InsetMathPhantom.h +++ b/src/mathed/InsetMathPhantom.h @@ -26,7 +26,7 @@ public: hphantom }; /// - explicit InsetMathPhantom(Kind); + explicit InsetMathPhantom(Buffer * buf, Kind); /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// diff --git a/src/mathed/InsetMathRef.cpp b/src/mathed/InsetMathRef.cpp index 7dace38d1b..4fda1197cf 100644 --- a/src/mathed/InsetMathRef.cpp +++ b/src/mathed/InsetMathRef.cpp @@ -35,13 +35,13 @@ using namespace std; namespace lyx { -InsetMathRef::InsetMathRef() - : CommandInset(from_ascii("ref"), false) +InsetMathRef::InsetMathRef(Buffer * buf) + : CommandInset(buf, from_ascii("ref"), false) {} -InsetMathRef::InsetMathRef(docstring const & data) - : CommandInset(data, false) +InsetMathRef::InsetMathRef(Buffer * buf, docstring const & data) + : CommandInset(buf, data, false) {} diff --git a/src/mathed/InsetMathRef.h b/src/mathed/InsetMathRef.h index b26678ce66..7b788c7814 100644 --- a/src/mathed/InsetMathRef.h +++ b/src/mathed/InsetMathRef.h @@ -23,9 +23,9 @@ class Buffer; class InsetMathRef : public CommandInset { public: /// - InsetMathRef(); + InsetMathRef(Buffer * buf); /// - explicit InsetMathRef(docstring const & data); + explicit InsetMathRef(Buffer * buf, docstring const & data); /// //void write(WriteStream & os) const; /// diff --git a/src/mathed/InsetMathRoot.cpp b/src/mathed/InsetMathRoot.cpp index 0a6759c2af..38c09469c9 100644 --- a/src/mathed/InsetMathRoot.cpp +++ b/src/mathed/InsetMathRoot.cpp @@ -23,8 +23,8 @@ using namespace std; namespace lyx { -InsetMathRoot::InsetMathRoot() - : InsetMathNest(2) +InsetMathRoot::InsetMathRoot(Buffer * buf) + : InsetMathNest(buf, 2) {} diff --git a/src/mathed/InsetMathRoot.h b/src/mathed/InsetMathRoot.h index 1fd6e08d0d..cfcac0a7f3 100644 --- a/src/mathed/InsetMathRoot.h +++ b/src/mathed/InsetMathRoot.h @@ -23,7 +23,7 @@ namespace lyx { class InsetMathRoot : public InsetMathNest { public: /// - InsetMathRoot(); + InsetMathRoot(Buffer * buf); /// bool idxUpDown(Cursor & cur, bool up) const; /// diff --git a/src/mathed/InsetMathScript.cpp b/src/mathed/InsetMathScript.cpp index b445de9473..8fde3ec81b 100644 --- a/src/mathed/InsetMathScript.cpp +++ b/src/mathed/InsetMathScript.cpp @@ -32,18 +32,18 @@ using namespace std; namespace lyx { -InsetMathScript::InsetMathScript() - : InsetMathNest(1), cell_1_is_up_(false), limits_(0) +InsetMathScript::InsetMathScript(Buffer * buf) + : InsetMathNest(buf, 1), cell_1_is_up_(false), limits_(0) {} -InsetMathScript::InsetMathScript(bool up) - : InsetMathNest(2), cell_1_is_up_(up), limits_(0) +InsetMathScript::InsetMathScript(Buffer * buf, bool up) + : InsetMathNest(buf, 2), cell_1_is_up_(up), limits_(0) {} -InsetMathScript::InsetMathScript(MathAtom const & at, bool up) - : InsetMathNest(2), cell_1_is_up_(up), limits_(0) +InsetMathScript::InsetMathScript(Buffer * buf, MathAtom const & at, bool up) + : InsetMathNest(buf, 2), cell_1_is_up_(up), limits_(0) { LASSERT(nargs() >= 1, /**/); cell(0).push_back(at); diff --git a/src/mathed/InsetMathScript.h b/src/mathed/InsetMathScript.h index 7917f0cd8c..569bc79f35 100644 --- a/src/mathed/InsetMathScript.h +++ b/src/mathed/InsetMathScript.h @@ -25,11 +25,11 @@ namespace lyx { class InsetMathScript : public InsetMathNest { public: /// create inset without scripts - InsetMathScript(); + InsetMathScript(Buffer * buf); /// create inset with single script - explicit InsetMathScript(bool up); + explicit InsetMathScript(Buffer * buf, bool up); /// create inset with single script and given nucleus - InsetMathScript(MathAtom const & at, bool up); + InsetMathScript(Buffer * buf, MathAtom const & at, bool up); /// mode_type currentMode() const { return MATH_MODE; } /// diff --git a/src/mathed/InsetMathSize.cpp b/src/mathed/InsetMathSize.cpp index d1f34c831e..d3a16317ba 100644 --- a/src/mathed/InsetMathSize.cpp +++ b/src/mathed/InsetMathSize.cpp @@ -23,8 +23,8 @@ namespace lyx { -InsetMathSize::InsetMathSize(latexkeys const * l) - : InsetMathNest(1), key_(l), style_(Styles(convert(l->extra))) +InsetMathSize::InsetMathSize(Buffer * buf, latexkeys const * l) + : InsetMathNest(buf, 1), key_(l), style_(Styles(convert(l->extra))) {} diff --git a/src/mathed/InsetMathSize.h b/src/mathed/InsetMathSize.h index 855b318559..714ae97fb9 100644 --- a/src/mathed/InsetMathSize.h +++ b/src/mathed/InsetMathSize.h @@ -25,7 +25,7 @@ class latexkeys; class InsetMathSize : public InsetMathNest { public: /// - explicit InsetMathSize(latexkeys const * l); + explicit InsetMathSize(Buffer * buf, latexkeys const * l); /// we write extra braces in any case... bool extraBraces() const { return true; } /// diff --git a/src/mathed/InsetMathSplit.cpp b/src/mathed/InsetMathSplit.cpp index 93799d8837..3f7478321e 100644 --- a/src/mathed/InsetMathSplit.cpp +++ b/src/mathed/InsetMathSplit.cpp @@ -32,8 +32,9 @@ namespace lyx { using support::bformat; -InsetMathSplit::InsetMathSplit(docstring const & name, char valign) - : InsetMathGrid(1, 1, valign, docstring()), name_(name) +InsetMathSplit::InsetMathSplit(Buffer * buf, docstring const & name, + char valign) + : InsetMathGrid(buf, 1, 1, valign, docstring()), name_(name) { } diff --git a/src/mathed/InsetMathSplit.h b/src/mathed/InsetMathSplit.h index 9a8d4b93d4..123f925869 100644 --- a/src/mathed/InsetMathSplit.h +++ b/src/mathed/InsetMathSplit.h @@ -21,7 +21,8 @@ namespace lyx { class InsetMathSplit : public InsetMathGrid { public: /// - explicit InsetMathSplit(docstring const & name, char valign = 'c'); + explicit InsetMathSplit(Buffer * buf, docstring const & name, + char valign = 'c'); /// void draw(PainterInfo & pi, int x, int y) const; /// diff --git a/src/mathed/InsetMathSqrt.cpp b/src/mathed/InsetMathSqrt.cpp index 7fff18f6f1..f738e2c17b 100644 --- a/src/mathed/InsetMathSqrt.cpp +++ b/src/mathed/InsetMathSqrt.cpp @@ -19,8 +19,8 @@ namespace lyx { -InsetMathSqrt::InsetMathSqrt() - : InsetMathNest(1) +InsetMathSqrt::InsetMathSqrt(Buffer * buf) + : InsetMathNest(buf, 1) {} diff --git a/src/mathed/InsetMathSqrt.h b/src/mathed/InsetMathSqrt.h index aaa1ac03c0..485f66a574 100644 --- a/src/mathed/InsetMathSqrt.h +++ b/src/mathed/InsetMathSqrt.h @@ -23,7 +23,7 @@ namespace lyx { class InsetMathSqrt : public InsetMathNest { public: /// - InsetMathSqrt(); + InsetMathSqrt(Buffer * buf); /// void draw(PainterInfo &, int x, int y) const; /// diff --git a/src/mathed/InsetMathStackrel.cpp b/src/mathed/InsetMathStackrel.cpp index d67d9fed8f..0a934f21d2 100644 --- a/src/mathed/InsetMathStackrel.cpp +++ b/src/mathed/InsetMathStackrel.cpp @@ -18,7 +18,7 @@ using namespace std; namespace lyx { -InsetMathStackrel::InsetMathStackrel() +InsetMathStackrel::InsetMathStackrel(Buffer * buf) : InsetMathFracBase(buf) {} diff --git a/src/mathed/InsetMathStackrel.h b/src/mathed/InsetMathStackrel.h index b27f1cd8b7..87397f3bbf 100644 --- a/src/mathed/InsetMathStackrel.h +++ b/src/mathed/InsetMathStackrel.h @@ -26,7 +26,7 @@ namespace lyx { class InsetMathStackrel : public InsetMathFracBase { public: /// - InsetMathStackrel(); + InsetMathStackrel(Buffer * buf); /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// diff --git a/src/mathed/InsetMathSubstack.cpp b/src/mathed/InsetMathSubstack.cpp index e4abe635e4..1736da409f 100644 --- a/src/mathed/InsetMathSubstack.cpp +++ b/src/mathed/InsetMathSubstack.cpp @@ -31,8 +31,8 @@ namespace lyx { using support::bformat; -InsetMathSubstack::InsetMathSubstack() - : InsetMathGrid(1, 1) +InsetMathSubstack::InsetMathSubstack(Buffer * buf) + : InsetMathGrid(buf, 1, 1) {} diff --git a/src/mathed/InsetMathSubstack.h b/src/mathed/InsetMathSubstack.h index c0576aaa6b..fbf5f756cc 100644 --- a/src/mathed/InsetMathSubstack.h +++ b/src/mathed/InsetMathSubstack.h @@ -23,7 +23,7 @@ namespace lyx { class InsetMathSubstack : public InsetMathGrid { public: /// - InsetMathSubstack(); + InsetMathSubstack(Buffer * buf); /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// diff --git a/src/mathed/InsetMathTabular.cpp b/src/mathed/InsetMathTabular.cpp index fcdd32c993..083b0e5ef5 100644 --- a/src/mathed/InsetMathTabular.cpp +++ b/src/mathed/InsetMathTabular.cpp @@ -22,14 +22,15 @@ namespace lyx { -InsetMathTabular::InsetMathTabular(docstring const & name, int m, int n) - : InsetMathGrid(m, n), name_(name) +InsetMathTabular::InsetMathTabular(Buffer * buf, docstring const & name, int m, + int n) + : InsetMathGrid(buf, m, n), name_(name) {} -InsetMathTabular::InsetMathTabular(docstring const & name, int m, int n, - char valign, docstring const & halign) - : InsetMathGrid(m, n, valign, halign), name_(name) +InsetMathTabular::InsetMathTabular(Buffer * buf, docstring const & name, int m, + int n, char valign, docstring const & halign) + : InsetMathGrid(buf, m, n, valign, halign), name_(name) {} diff --git a/src/mathed/InsetMathTabular.h b/src/mathed/InsetMathTabular.h index 0fb6c27961..a4aa50f1b9 100644 --- a/src/mathed/InsetMathTabular.h +++ b/src/mathed/InsetMathTabular.h @@ -22,9 +22,9 @@ namespace lyx { class InsetMathTabular : public InsetMathGrid { public: /// - InsetMathTabular(docstring const &, int m, int n); + InsetMathTabular(Buffer * buf, docstring const &, int m, int n); /// - InsetMathTabular(docstring const &, int m, int n, + InsetMathTabular(Buffer * buf, docstring const &, int m, int n, char valign, docstring const & halign); /// void metrics(MetricsInfo & mi, Dimension & dim) const; diff --git a/src/mathed/InsetMathUnderset.h b/src/mathed/InsetMathUnderset.h index 321f26fef0..0f298e1f73 100644 --- a/src/mathed/InsetMathUnderset.h +++ b/src/mathed/InsetMathUnderset.h @@ -21,6 +21,8 @@ namespace lyx { /// Inset for underset class InsetMathUnderset : public InsetMathFracBase { public: + /// + InsetMathUnderset(Buffer * buf) : InsetMathFracBase(buf) {} /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// diff --git a/src/mathed/InsetMathXArrow.cpp b/src/mathed/InsetMathXArrow.cpp index d2b1199187..d9579ba5cf 100644 --- a/src/mathed/InsetMathXArrow.cpp +++ b/src/mathed/InsetMathXArrow.cpp @@ -23,8 +23,8 @@ using namespace std; namespace lyx { -InsetMathXArrow::InsetMathXArrow(docstring const & name) - : InsetMathFracBase(), name_(name) +InsetMathXArrow::InsetMathXArrow(Buffer * buf, docstring const & name) + : InsetMathFracBase(buf), name_(name) {} diff --git a/src/mathed/InsetMathXArrow.h b/src/mathed/InsetMathXArrow.h index d21dd42222..469bec1d0b 100644 --- a/src/mathed/InsetMathXArrow.h +++ b/src/mathed/InsetMathXArrow.h @@ -22,7 +22,7 @@ namespace lyx { class InsetMathXArrow : public InsetMathFracBase { public: /// - explicit InsetMathXArrow(docstring const & name); + explicit InsetMathXArrow(Buffer * buf, docstring const & name); /// void draw(PainterInfo & pi, int x, int y) const; /// diff --git a/src/mathed/InsetMathXYMatrix.cpp b/src/mathed/InsetMathXYMatrix.cpp index 6b11ac2415..39ac88586a 100644 --- a/src/mathed/InsetMathXYMatrix.cpp +++ b/src/mathed/InsetMathXYMatrix.cpp @@ -20,9 +20,10 @@ namespace lyx { -InsetMathXYMatrix::InsetMathXYMatrix(Length const & s, char c) - : InsetMathGrid(1, 1), spacing_(s), spacing_code_(c) -{} +InsetMathXYMatrix::InsetMathXYMatrix(Buffer * buf, Length const & s, char c) + : InsetMathGrid(buf, 1, 1), spacing_(s), spacing_code_(c) +{ +} Inset * InsetMathXYMatrix::clone() const diff --git a/src/mathed/InsetMathXYMatrix.h b/src/mathed/InsetMathXYMatrix.h index 8e11a0b489..ee20149d30 100644 --- a/src/mathed/InsetMathXYMatrix.h +++ b/src/mathed/InsetMathXYMatrix.h @@ -22,7 +22,7 @@ namespace lyx { class InsetMathXYMatrix : public InsetMathGrid { public: /// - InsetMathXYMatrix(Length const & = Length(), char c = '\0'); + InsetMathXYMatrix(Buffer * buf, Length const & = Length(), char c = '\0'); /// void metrics(MetricsInfo &, Dimension &) const; /// diff --git a/src/mathed/MacroTable.cpp b/src/mathed/MacroTable.cpp index 1a7ba80295..5c0604017b 100644 --- a/src/mathed/MacroTable.cpp +++ b/src/mathed/MacroTable.cpp @@ -39,23 +39,23 @@ namespace lyx { // ///////////////////////////////////////////////////////////////////// -MacroData::MacroData() - : queried_(true), numargs_(0), optionals_(0), lockCount_(0), +MacroData::MacroData(Buffer * buf) + : buffer_(buf), queried_(true), numargs_(0), optionals_(0), lockCount_(0), redefinition_(false), type_(MacroTypeNewcommand) {} -MacroData::MacroData(Buffer const & buf, DocIterator const & pos) - : buffer_(&buf), pos_(pos), queried_(false), numargs_(0), +MacroData::MacroData(Buffer * buf, DocIterator const & pos) + : buffer_(buf), pos_(pos), queried_(false), numargs_(0), optionals_(0), lockCount_(0), redefinition_(false), type_(MacroTypeNewcommand) { } -MacroData::MacroData(MathMacroTemplate const & macro) - : queried_(false), numargs_(0), optionals_(0), lockCount_(0), +MacroData::MacroData(Buffer * buf, MathMacroTemplate const & macro) + : buffer_(buf), queried_(false), numargs_(0), optionals_(0), lockCount_(0), redefinition_(false), type_(MacroTypeNewcommand) { queryData(macro); @@ -67,7 +67,8 @@ void MacroData::expand(vector const & args, MathData & to) const updateData(); // Hack. Any inset with a cell would do. - static InsetMathSqrt inset; + static InsetMathSqrt inset(0); + inset.setBuffer(const_cast(*buffer_)); // FIXME UNICODE asArray(display_.empty() ? definition_ : display_, inset.cell(0)); @@ -197,11 +198,11 @@ void MacroTable::insert(docstring const & name, MacroData const & data) } -void MacroTable::insert(docstring const & def, string const & requires) +void MacroTable::insert(Buffer * buf, docstring const & def, string const & requires) { //lyxerr << "MacroTable::insert, def: " << to_utf8(def) << endl; - MathMacroTemplate mac(def); - MacroData data(mac); + MathMacroTemplate mac(buf, def); + MacroData data(buf, mac); data.requires() = requires; insert(mac.name(), data); } @@ -232,7 +233,7 @@ void MacroTable::dump() // ///////////////////////////////////////////////////////////////////// -MacroContext::MacroContext(Buffer const & buf, DocIterator const & pos) +MacroContext::MacroContext(Buffer const * buf, DocIterator const & pos) : buf_(buf), pos_(pos) { } @@ -240,7 +241,7 @@ MacroContext::MacroContext(Buffer const & buf, DocIterator const & pos) MacroData const * MacroContext::get(docstring const & name) const { - return buf_.getMacro(name, pos_); + return buf_->getMacro(name, pos_); } } // namespace lyx diff --git a/src/mathed/MacroTable.h b/src/mathed/MacroTable.h index d1b455b03a..24e896c6b2 100644 --- a/src/mathed/MacroTable.h +++ b/src/mathed/MacroTable.h @@ -39,11 +39,11 @@ enum MacroType { class MacroData { public: /// Constructor to make STL containers happy - MacroData(); + MacroData(Buffer * buf = 0); /// Create lazy MacroData which only queries the macro template when needed - MacroData(Buffer const & buf, DocIterator const & pos); + MacroData(Buffer * buf, DocIterator const & pos); /// Create non-lazy MacroData which directly queries the macro template - MacroData(MathMacroTemplate const & macro); + MacroData(Buffer * buf, MathMacroTemplate const & macro); /// docstring const & definition() const { updateData(); return definition_; } @@ -153,7 +153,7 @@ class MacroTable : public std::map { public: /// Parse full "\\def..." or "\\newcommand..." or ... - void insert(docstring const & definition, std::string const &); + void insert(Buffer * buf, docstring const & definition, std::string const &); /// Insert pre-digested macro definition void insert(docstring const & name, MacroData const & data); /// @@ -179,14 +179,14 @@ public: class MacroContext { public: /// construct context for the insets at pos - MacroContext(Buffer const & buf, DocIterator const & pos); + MacroContext(Buffer const * buf, DocIterator const & pos); /// Lookup macro MacroData const * get(docstring const & name) const; private: /// - Buffer const & buf_; + Buffer const * buf_; /// DocIterator const & pos_; }; diff --git a/src/mathed/MathData.cpp b/src/mathed/MathData.cpp index 7474632cae..b52c34f5d2 100644 --- a/src/mathed/MathData.cpp +++ b/src/mathed/MathData.cpp @@ -46,8 +46,8 @@ using namespace std; namespace lyx { -MathData::MathData(const_iterator from, const_iterator to) - : base_type(from, to) +MathData::MathData(Buffer * buf, const_iterator from, const_iterator to) + : base_type(from, to), buffer_(buf) {} @@ -469,6 +469,7 @@ void MathData::updateMacros(Cursor * cur, MacroContext const & mc) void MathData::detachMacroParameters(Cursor * cur, const size_type macroPos) { MathMacro * macroInset = operator[](macroPos).nucleus()->asMacro(); + Buffer * buf = cur->buffer(); // detach all arguments vector detachedArgs; @@ -523,7 +524,7 @@ void MathData::detachMacroParameters(Cursor * cur, const size_type macroPos) for (size_t q = 0; q < arg.size(); ++q) { if (arg[q]->getChar() == ']') { // put brace - brace = new InsetMathBrace(); + brace = new InsetMathBrace(buf); break; } } @@ -672,6 +673,7 @@ void MathData::collectOptionalParameters(Cursor * cur, size_t & pos, MathAtom & scriptToPutAround, const pos_type macroPos, const int thisPos, const int thisSlice) { + Buffer * buf = cur ? cur->buffer() : 0; // insert optional arguments? while (params.size() < numOptionalParams && pos < size() @@ -709,7 +711,7 @@ void MathData::collectOptionalParameters(Cursor * cur, } // add everything between [ and ] as optional argument - MathData optarg(begin() + pos + 1, begin() + right); + MathData optarg(buf, begin() + pos + 1, begin() + right); // a brace? bool brace = false; diff --git a/src/mathed/MathData.h b/src/mathed/MathData.h index d44455a0a3..fa2dc9dfa6 100644 --- a/src/mathed/MathData.h +++ b/src/mathed/MathData.h @@ -25,6 +25,7 @@ namespace lyx { +class Buffer; class BufferView; class Cursor; class DocIterator; @@ -61,9 +62,13 @@ public: public: /// - MathData() {} + MathData(Buffer * buf = 0) : buffer_(buf) {} /// - MathData(const_iterator from, const_iterator to); + MathData(Buffer * buf, const_iterator from, const_iterator to); + /// + Buffer * buffer() { return buffer_; } + /// + Buffer const * buffer() const { return buffer_; } /// void append(MathData const & ar); @@ -167,7 +172,8 @@ protected: mutable int slevel_; mutable int sshift_; mutable int kerning_; - + Buffer * buffer_; + private: /// is this an exact match at this position? bool find1(MathData const & ar, size_type pos) const; diff --git a/src/mathed/MathExtern.cpp b/src/mathed/MathExtern.cpp index c42da422e4..f8f7cba3b1 100644 --- a/src/mathed/MathExtern.cpp +++ b/src/mathed/MathExtern.cpp @@ -301,9 +301,9 @@ void replaceNested( MathData & ar, TestItemFunc testOpen, TestItemFunc testClose, - ReplaceArgumentFunc replaceArg -) + ReplaceArgumentFunc replaceArg) { + Buffer * buf = ar.buffer(); // use indices rather than iterators for the loop because we are going // to modify the array. for (size_t i = 0; i < ar.size(); ++i) { @@ -318,7 +318,7 @@ void replaceNested( continue; // replace the original stuff by the new inset - ar[i] = replaceArg(MathData(it + 1, jt)); + ar[i] = replaceArg(MathData(buf, it + 1, jt)); ar.erase(it + 1, jt + 1); } } @@ -332,6 +332,7 @@ void replaceNested( void splitScripts(MathData & ar) { + Buffer * buf = ar.buffer(); //lyxerr << "\nScripts from: " << ar << endl; for (size_t i = 0; i < ar.size(); ++i) { InsetMathScript const * script = ar[i]->asScriptInset(); @@ -354,7 +355,7 @@ void splitScripts(MathData & ar) // create extra script inset and move superscript over InsetMathScript * p = ar[i].nucleus()->asScriptInset(); - auto_ptr q(new InsetMathScript(true)); + auto_ptr q(new InsetMathScript(buf, true)); swap(q->up(), p->up()); p->removeScript(true); @@ -382,6 +383,7 @@ void splitScripts(MathData & ar) void extractExps(MathData & ar) { + Buffer * buf = ar.buffer(); //lyxerr << "\nExps from: " << ar << endl; for (size_t i = 0; i + 1 < ar.size(); ++i) { // is this 'e'? @@ -394,7 +396,7 @@ void extractExps(MathData & ar) continue; // create a proper exp-inset as replacement - ar[i] = MathAtom(new InsetMathExFunc(from_ascii("exp"), sup->cell(1))); + ar[i] = MathAtom(new InsetMathExFunc(buf, from_ascii("exp"), sup->cell(1))); ar.erase(i + 1); } //lyxerr << "\nExps to: " << ar << endl; @@ -406,6 +408,7 @@ void extractExps(MathData & ar) // void extractDets(MathData & ar) { + Buffer * buf = ar.buffer(); //lyxerr << "\ndet from: " << ar << endl; for (MathData::iterator it = ar.begin(); it != ar.end(); ++it) { InsetMathDelim const * del = (*it)->asDelimInset(); @@ -413,7 +416,7 @@ void extractDets(MathData & ar) continue; if (!del->isAbs()) continue; - *it = MathAtom(new InsetMathExFunc(from_ascii("det"), del->cell(0))); + *it = MathAtom(new InsetMathExFunc(buf, from_ascii("det"), del->cell(0))); } //lyxerr << "\ndet to: " << ar << endl; } @@ -480,7 +483,8 @@ bool testCloseParen(MathAtom const & at) MathAtom replaceParenDelims(const MathData & ar) { - return MathAtom(new InsetMathDelim(from_ascii("("), from_ascii(")"), ar)); + return MathAtom(new InsetMathDelim(const_cast(ar.buffer()), + from_ascii("("), from_ascii(")"), ar)); } @@ -498,7 +502,8 @@ bool testCloseBracket(MathAtom const & at) MathAtom replaceBracketDelims(const MathData & ar) { - return MathAtom(new InsetMathDelim(from_ascii("["), from_ascii("]"), ar)); + return MathAtom(new InsetMathDelim(const_cast(ar.buffer()), + from_ascii("["), from_ascii("]"), ar)); } @@ -526,6 +531,8 @@ void extractFunctions(MathData & ar) if (ar.size() < 2) return; + Buffer * buf = ar.buffer(); + //lyxerr << "\nFunctions from: " << ar << endl; for (size_t i = 0; i + 1 < ar.size(); ++i) { MathData::iterator it = ar.begin() + i; @@ -556,7 +563,7 @@ void extractFunctions(MathData & ar) extractScript(exp, jt, ar.end(), true); // create a proper inset as replacement - auto_ptr p(new InsetMathExFunc(name)); + auto_ptr p(new InsetMathExFunc(buf, name)); // jt points to the "argument". Get hold of this. MathData::iterator st = extractArgument(p->cell(0), jt, ar.end(), true); @@ -621,6 +628,8 @@ void extractIntegrals(MathData & ar) if (ar.size() < 3) return; + Buffer * buf = ar.buffer(); + //lyxerr << "\nIntegrals from: " << ar << endl; for (size_t i = 0; i + 1 < ar.size(); ++i) { MathData::iterator it = ar.begin() + i; @@ -638,14 +647,14 @@ void extractIntegrals(MathData & ar) continue; // core ist part from behind the scripts to the 'd' - auto_ptr p(new InsetMathExInt(from_ascii("int"))); + auto_ptr p(new InsetMathExInt(buf, from_ascii("int"))); // handle scripts if available if (!testIntSymbol(*it)) { p->cell(2) = (*it)->asScriptInset()->down(); p->cell(3) = (*it)->asScriptInset()->up(); } - p->cell(0) = MathData(it + 1, jt); + p->cell(0) = MathData(buf, it + 1, jt); // use the "thing" behind the 'd' as differential MathData::iterator tt = extractArgument(p->cell(1), jt + 1, ar.end()); @@ -712,6 +721,8 @@ void extractSums(MathData & ar) if (ar.size() < 2) return; + Buffer * buf = ar.buffer(); + //lyxerr << "\nSums from: " << ar << endl; for (size_t i = 0; i + 1 < ar.size(); ++i) { MathData::iterator it = ar.begin() + i; @@ -721,7 +732,7 @@ void extractSums(MathData & ar) continue; // create a proper inset as replacement - auto_ptr p(new InsetMathExInt(from_ascii("sum"))); + auto_ptr p(new InsetMathExInt(buf, from_ascii("sum"))); // collect lower bound and summation index InsetMathScript const * sub = ar[i]->asScriptInset(); @@ -733,8 +744,8 @@ void extractSums(MathData & ar) if (xt != ar.end()) { // we found a '=', use everything in front of that as index, // and everything behind as lower index - p->cell(1) = MathData(ar.begin(), xt); - p->cell(2) = MathData(xt + 1, ar.end()); + p->cell(1) = MathData(buf, ar.begin(), xt); + p->cell(2) = MathData(buf, xt + 1, ar.end()); } else { // use everything as summation index, don't use scripts. p->cell(1) = ar; @@ -793,6 +804,7 @@ bool testDiffFrac(MathAtom const & at) void extractDiff(MathData & ar) { + Buffer * buf = ar.buffer(); //lyxerr << "\nDiffs from: " << ar << endl; for (size_t i = 0; i < ar.size(); ++i) { MathData::iterator it = ar.begin() + i; @@ -808,7 +820,7 @@ void extractDiff(MathData & ar) } // create a proper diff inset - auto_ptr diff(new InsetMathDiff); + auto_ptr diff(new InsetMathDiff(buf)); // collect function, let jt point behind last used item MathData::iterator jt = it + 1; @@ -820,13 +832,13 @@ void extractDiff(MathData & ar) // FIXME //n = 1; if (numer.size() > 2) - diff->cell(0) = MathData(numer.begin() + 2, numer.end()); + diff->cell(0) = MathData(buf, numer.begin() + 2, numer.end()); else jt = extractTerm(diff->cell(0), jt, ar.end()); } else { // simply d f(x) / d... or d/d... if (numer.size() > 1) - diff->cell(0) = MathData(numer.begin() + 1, numer.end()); + diff->cell(0) = MathData(buf, numer.begin() + 1, numer.end()); else jt = extractTerm(diff->cell(0), jt, ar.end()); } @@ -848,11 +860,11 @@ void extractDiff(MathData & ar) if (extractNumber(script->up(), mult)) { //lyxerr << "mult: " << mult << endl; for (int i = 0; i < mult; ++i) - diff->addDer(MathData(dt + 1, st)); + diff->addDer(MathData(buf, dt + 1, st)); } } else { // just d.../dx - diff->addDer(MathData(dt + 1, et)); + diff->addDer(MathData(buf, dt + 1, et)); } dt = et; } @@ -881,6 +893,7 @@ bool testRightArrow(MathAtom const & at) // assume 'extractDelims' ran before void extractLims(MathData & ar) { + Buffer * buf = ar.buffer(); //lyxerr << "\nLimits from: " << ar << endl; for (size_t i = 0; i < ar.size(); ++i) { MathData::iterator it = ar.begin() + i; @@ -901,8 +914,8 @@ void extractLims(MathData & ar) continue; // the -> splits the subscript int x and x0 - MathData x = MathData(s.begin(), st); - MathData x0 = MathData(st + 1, s.end()); + MathData x = MathData(buf, s.begin(), st); + MathData x0 = MathData(buf, st + 1, s.end()); // use something behind the script as core MathData f; @@ -912,7 +925,7 @@ void extractLims(MathData & ar) ar.erase(it + 1, tt); // create a proper inset as replacement - *it = MathAtom(new InsetMathLim(f, x, x0)); + *it = MathAtom(new InsetMathLim(buf, f, x, x0)); } //lyxerr << "\nLimits to: " << ar << endl; } @@ -1254,7 +1267,8 @@ namespace { vs << ar; string expr = to_utf8(os.str()); string out; - + // FIXME const cast + Buffer * buf = const_cast(ar.buffer()); lyxerr << "pipe: ar: '" << ar << "'\n" << "pipe: expr: '" << expr << "'" << endl; @@ -1304,13 +1318,14 @@ namespace { out = out.substr(i + 6); // parse output as matrix or single number - MathAtom at(new InsetMathArray(from_ascii("array"), from_utf8(out))); + MathAtom at(new InsetMathArray(buf, from_ascii("array"), from_utf8(out))); InsetMathArray const * mat = at->asArrayInset(); - MathData res; + MathData res(buf); if (mat->ncols() == 1 && mat->nrows() == 1) res.append(mat->cell(0)); else { - res.push_back(MathAtom(new InsetMathDelim(from_ascii("("), from_ascii(")")))); + res.push_back(MathAtom( + new InsetMathDelim(buf, from_ascii("("), from_ascii(")")))); res.back().nucleus()->cell(0).push_back(at); } return res; diff --git a/src/mathed/MathFactory.cpp b/src/mathed/MathFactory.cpp index 267432affd..1d6d83baf8 100644 --- a/src/mathed/MathFactory.cpp +++ b/src/mathed/MathFactory.cpp @@ -145,7 +145,7 @@ void initSymbols() string macro; string requires; is >> macro >> requires; - MacroTable::globalMacros().insert(from_utf8(macro), requires); + MacroTable::globalMacros().insert(0, from_utf8(macro), requires); continue; } @@ -300,13 +300,13 @@ latexkeys const * in_word_set(docstring const & str) } -MathAtom createInsetMath(char const * const s) +MathAtom createInsetMath(char const * const s, Buffer * buf) { - return createInsetMath(from_utf8(s)); + return createInsetMath(from_utf8(s), buf); } -MathAtom createInsetMath(docstring const & s) +MathAtom createInsetMath(docstring const & s, Buffer * buf) { //lyxerr << "creating inset with name: '" << to_utf8(s) << '\'' << endl; latexkeys const * l = in_word_set(s); @@ -314,13 +314,13 @@ MathAtom createInsetMath(docstring const & s) docstring const & inset = l->inset; //lyxerr << " found inset: '" << inset << '\'' << endl; if (inset == "ref") - return MathAtom(new InsetMathRef(l->name)); + return MathAtom(new InsetMathRef(buf, l->name)); if (inset == "overset") - return MathAtom(new InsetMathOverset); + return MathAtom(new InsetMathOverset(buf)); if (inset == "underset") - return MathAtom(new InsetMathUnderset); + return MathAtom(new InsetMathUnderset(buf)); if (inset == "decoration") - return MathAtom(new InsetMathDecoration(l)); + return MathAtom(new InsetMathDecoration(buf, l)); if (inset == "space") return MathAtom(new InsetMathSpace(to_ascii(l->name), "")); if (inset == "dots") @@ -330,19 +330,19 @@ MathAtom createInsetMath(docstring const & s) // InsetMathMBox is proposed to replace InsetMathBox, // but is not ready yet (it needs a BufferView for // construction) - return MathAtom(new InsetMathBox(l->name)); + return MathAtom(new InsetMathBox(buf, l->name)); // if (inset == "fbox") // return MathAtom(new InsetMathFBox(l)); if (inset == "style") - return MathAtom(new InsetMathSize(l)); + return MathAtom(new InsetMathSize(buf, l)); if (inset == "font") - return MathAtom(new InsetMathFont(l)); + return MathAtom(new InsetMathFont(buf, l)); if (inset == "oldfont") - return MathAtom(new InsetMathFontOld(l)); + return MathAtom(new InsetMathFontOld(buf, l)); if (inset == "matrix") - return MathAtom(new InsetMathAMSArray(s)); + return MathAtom(new InsetMathAMSArray(buf, s)); if (inset == "split") - return MathAtom(new InsetMathSplit(s)); + return MathAtom(new InsetMathSplit(buf, s)); if (inset == "big") // we can't create a InsetMathBig, since the argument // is missing. @@ -356,13 +356,13 @@ MathAtom createInsetMath(docstring const & s) && s[2] >= '1' && s[2] <= '9') return MathAtom(new MathMacroArgument(s[2] - '0')); if (s == "boxed") - return MathAtom(new InsetMathBoxed()); + return MathAtom(new InsetMathBoxed(buf)); if (s == "fbox") - return MathAtom(new InsetMathFBox()); + return MathAtom(new InsetMathFBox(buf)); if (s == "framebox") - return MathAtom(new InsetMathMakebox(true)); + return MathAtom(new InsetMathMakebox(buf, true)); if (s == "makebox") - return MathAtom(new InsetMathMakebox(false)); + return MathAtom(new InsetMathMakebox(buf, false)); if (s == "kern") return MathAtom(new InsetMathKern); if (s.substr(0, 8) == "xymatrix") { @@ -390,94 +390,94 @@ MathAtom createInsetMath(docstring const & s) spacing = Length(to_ascii(s.substr(i))); } } - return MathAtom(new InsetMathXYMatrix(spacing, spacing_code)); + return MathAtom(new InsetMathXYMatrix(buf, spacing, spacing_code)); } if (s == "xrightarrow" || s == "xleftarrow") - return MathAtom(new InsetMathXArrow(s)); + return MathAtom(new InsetMathXArrow(buf, s)); if (s == "split" || s == "gathered" || s == "aligned" || s == "alignedat") - return MathAtom(new InsetMathSplit(s)); + return MathAtom(new InsetMathSplit(buf, s)); if (s == "cases") - return MathAtom(new InsetMathCases); + return MathAtom(new InsetMathCases(buf)); if (s == "substack") - return MathAtom(new InsetMathSubstack); + return MathAtom(new InsetMathSubstack(buf)); if (s == "subarray" || s == "array") - return MathAtom(new InsetMathArray(s, 1, 1)); + return MathAtom(new InsetMathArray(buf, s, 1, 1)); if (s == "sqrt") - return MathAtom(new InsetMathSqrt); + return MathAtom(new InsetMathSqrt(buf)); if (s == "root") - return MathAtom(new InsetMathRoot); + return MathAtom(new InsetMathRoot(buf)); if (s == "tabular") - return MathAtom(new InsetMathTabular(s, 1, 1)); + return MathAtom(new InsetMathTabular(buf, s, 1, 1)); if (s == "stackrel") - return MathAtom(new InsetMathStackrel); + return MathAtom(new InsetMathStackrel(buf)); if (s == "binom") - return MathAtom(new InsetMathBinom(InsetMathBinom::BINOM)); + return MathAtom(new InsetMathBinom(buf, InsetMathBinom::BINOM)); if (s == "dbinom") - return MathAtom(new InsetMathBinom(InsetMathBinom::DBINOM)); + return MathAtom(new InsetMathBinom(buf, InsetMathBinom::DBINOM)); if (s == "tbinom") - return MathAtom(new InsetMathBinom(InsetMathBinom::TBINOM)); + return MathAtom(new InsetMathBinom(buf, InsetMathBinom::TBINOM)); if (s == "choose") - return MathAtom(new InsetMathBinom(InsetMathBinom::CHOOSE)); + return MathAtom(new InsetMathBinom(buf, InsetMathBinom::CHOOSE)); if (s == "brace") - return MathAtom(new InsetMathBinom(InsetMathBinom::BRACE)); + return MathAtom(new InsetMathBinom(buf, InsetMathBinom::BRACE)); if (s == "brack") - return MathAtom(new InsetMathBinom(InsetMathBinom::BRACK)); + return MathAtom(new InsetMathBinom(buf, InsetMathBinom::BRACK)); if (s == "frac") - return MathAtom(new InsetMathFrac); + return MathAtom(new InsetMathFrac(buf)); if (s == "cfrac") - return MathAtom(new InsetMathFrac(InsetMathFrac::CFRAC)); + return MathAtom(new InsetMathFrac(buf, InsetMathFrac::CFRAC)); if (s == "dfrac") - return MathAtom(new InsetMathFrac(InsetMathFrac::DFRAC)); + return MathAtom(new InsetMathFrac(buf, InsetMathFrac::DFRAC)); if (s == "tfrac") - return MathAtom(new InsetMathFrac(InsetMathFrac::TFRAC)); + return MathAtom(new InsetMathFrac(buf, InsetMathFrac::TFRAC)); if (s == "over") - return MathAtom(new InsetMathFrac(InsetMathFrac::OVER)); + return MathAtom(new InsetMathFrac(buf, InsetMathFrac::OVER)); if (s == "nicefrac") - return MathAtom(new InsetMathFrac(InsetMathFrac::NICEFRAC)); + return MathAtom(new InsetMathFrac(buf, InsetMathFrac::NICEFRAC)); if (s == "unitfrac") - return MathAtom(new InsetMathFrac(InsetMathFrac::UNITFRAC)); + return MathAtom(new InsetMathFrac(buf, InsetMathFrac::UNITFRAC)); // These string values are only for math toolbar use, no LaTeX names if (s == "unitfracthree") - return MathAtom(new InsetMathFrac(InsetMathFrac::UNITFRAC, 3)); + return MathAtom(new InsetMathFrac(buf, InsetMathFrac::UNITFRAC, 3)); if (s == "unitone") - return MathAtom(new InsetMathFrac(InsetMathFrac::UNIT, 1)); + return MathAtom(new InsetMathFrac(buf, InsetMathFrac::UNIT, 1)); if (s == "unittwo") - return MathAtom(new InsetMathFrac(InsetMathFrac::UNIT)); + return MathAtom(new InsetMathFrac(buf, InsetMathFrac::UNIT)); if (s == "cfracleft") - return MathAtom(new InsetMathFrac(InsetMathFrac::CFRACLEFT)); + return MathAtom(new InsetMathFrac(buf, InsetMathFrac::CFRACLEFT)); if (s == "cfracright") - return MathAtom(new InsetMathFrac(InsetMathFrac::CFRACRIGHT)); + return MathAtom(new InsetMathFrac(buf, InsetMathFrac::CFRACRIGHT)); //if (s == "infer") // return MathAtom(new MathInferInset); if (s == "atop") - return MathAtom(new InsetMathFrac(InsetMathFrac::ATOP)); + return MathAtom(new InsetMathFrac(buf, InsetMathFrac::ATOP)); if (s == "lefteqn") - return MathAtom(new InsetMathLefteqn); + return MathAtom(new InsetMathLefteqn(buf)); if (s == "boldsymbol") - return MathAtom(new InsetMathBoldSymbol(InsetMathBoldSymbol::AMS_BOLD)); + return MathAtom(new InsetMathBoldSymbol(buf, InsetMathBoldSymbol::AMS_BOLD)); if (s == "bm") - return MathAtom(new InsetMathBoldSymbol(InsetMathBoldSymbol::BM_BOLD)); + return MathAtom(new InsetMathBoldSymbol(buf, InsetMathBoldSymbol::BM_BOLD)); if (s == "heavysymbol" || s == "hm") - return MathAtom(new InsetMathBoldSymbol(InsetMathBoldSymbol::BM_HEAVY)); + return MathAtom(new InsetMathBoldSymbol(buf, InsetMathBoldSymbol::BM_HEAVY)); if (s == "color" || s == "normalcolor") - return MathAtom(new InsetMathColor(true)); + return MathAtom(new InsetMathColor(buf, true)); if (s == "textcolor") - return MathAtom(new InsetMathColor(false)); + return MathAtom(new InsetMathColor(buf, false)); if (s == "hphantom") - return MathAtom(new InsetMathPhantom(InsetMathPhantom::hphantom)); + return MathAtom(new InsetMathPhantom(buf, InsetMathPhantom::hphantom)); if (s == "phantom") - return MathAtom(new InsetMathPhantom(InsetMathPhantom::phantom)); + return MathAtom(new InsetMathPhantom(buf, InsetMathPhantom::phantom)); if (s == "vphantom") - return MathAtom(new InsetMathPhantom(InsetMathPhantom::vphantom)); + return MathAtom(new InsetMathPhantom(buf, InsetMathPhantom::vphantom)); if (s == "ensuremath") - return MathAtom(new InsetMathEnsureMath); + return MathAtom(new InsetMathEnsureMath(buf)); if (isSpecialChar(s)) return MathAtom(new InsetMathSpecialChar(s)); if (s == "regexp") - return MathAtom(new InsetMathHull(hullRegexp)); + return MathAtom(new InsetMathHull(buf, hullRegexp)); - return MathAtom(new MathMacro(s)); + return MathAtom(new MathMacro(buf, s)); } diff --git a/src/mathed/MathFactory.h b/src/mathed/MathFactory.h index 82515baeb8..9837ca75e2 100644 --- a/src/mathed/MathFactory.h +++ b/src/mathed/MathFactory.h @@ -24,8 +24,8 @@ class MathAtom; class MathData; -MathAtom createInsetMath(docstring const &); -MathAtom createInsetMath(char const * const); +MathAtom createInsetMath(docstring const &, Buffer * buf); +MathAtom createInsetMath(char const * const, Buffer * buf); /** Fills ar with the contents of str. * str is created by the frontend dialog's and returned to the LyX core. diff --git a/src/mathed/MathMacro.cpp b/src/mathed/MathMacro.cpp index f29a5e4ac7..f1aeb13293 100644 --- a/src/mathed/MathMacro.cpp +++ b/src/mathed/MathMacro.cpp @@ -116,10 +116,10 @@ private: }; -MathMacro::MathMacro(docstring const & name) - : InsetMathNest(0), name_(name), displayMode_(DISPLAY_INIT), - attachedArgsNum_(0), optionals_(0), nextFoldMode_(true), - macro_(0), needsUpdate_(false), appetite_(9) +MathMacro::MathMacro(Buffer * buf, docstring const & name) + : InsetMathNest(buf, 0), name_(name), displayMode_(DISPLAY_INIT), + expanded_(buf), attachedArgsNum_(0), optionals_(0), nextFoldMode_(true), + macroBackup_(buf), macro_(0), needsUpdate_(false), appetite_(9) {} @@ -634,7 +634,7 @@ bool MathMacro::notifyCursorLeaves(Cursor const & old, Cursor & cur) cur.recordUndoInset(); cur.popForward(); cur.backspace(); - cur.insert(createInsetMath(unfolded_name)); + cur.insert(createInsetMath(unfolded_name, cur.buffer())); if (left) cur.backwardPos(); cur.updateFlags(Update::Force); diff --git a/src/mathed/MathMacro.h b/src/mathed/MathMacro.h index 801c19dfb8..b431a9a9a5 100644 --- a/src/mathed/MathMacro.h +++ b/src/mathed/MathMacro.h @@ -26,7 +26,7 @@ namespace lyx { class MathMacro : public InsetMathNest { public: /// A macro can be built from an existing template - MathMacro(docstring const & name); + MathMacro(Buffer * buf, docstring const & name); /// virtual MathMacro * asMacro() { return this; } /// diff --git a/src/mathed/MathMacroTemplate.cpp b/src/mathed/MathMacroTemplate.cpp index fc5e57a5e4..257c55f639 100644 --- a/src/mathed/MathMacroTemplate.cpp +++ b/src/mathed/MathMacroTemplate.cpp @@ -57,9 +57,9 @@ using support::bformat; class InsetLabelBox : public InsetMathNest { public: /// - InsetLabelBox(MathAtom const & atom, docstring label, + InsetLabelBox(Buffer * buf, MathAtom const & atom, docstring label, MathMacroTemplate const & parent, bool frame = false); - InsetLabelBox(docstring label, MathMacroTemplate const & parent, + InsetLabelBox(Buffer * buf, docstring label, MathMacroTemplate const & parent, bool frame = false); /// void metrics(MetricsInfo & mi, Dimension & dim) const; @@ -78,17 +78,17 @@ protected: }; -InsetLabelBox::InsetLabelBox(MathAtom const & atom, docstring label, +InsetLabelBox::InsetLabelBox(Buffer * buf, MathAtom const & atom, docstring label, MathMacroTemplate const & parent, bool frame) - : InsetMathNest(1), parent_(parent), label_(label), frame_(frame) + : InsetMathNest(buf, 1), parent_(parent), label_(label), frame_(frame) { cell(0).insert(0, atom); } -InsetLabelBox::InsetLabelBox(docstring label, +InsetLabelBox::InsetLabelBox(Buffer * buf, docstring label, MathMacroTemplate const & parent, bool frame) - : InsetMathNest(1), parent_(parent), label_(label), frame_(frame) + : InsetMathNest(buf, 1), parent_(parent), label_(label), frame_(frame) { } @@ -181,7 +181,7 @@ void InsetLabelBox::draw(PainterInfo & pi, int x, int y) const class DisplayLabelBox : public InsetLabelBox { public: /// - DisplayLabelBox(MathAtom const & atom, docstring label, + DisplayLabelBox(Buffer * buf, MathAtom const & atom, docstring label, MathMacroTemplate const & parent); /// @@ -195,10 +195,10 @@ protected: }; -DisplayLabelBox::DisplayLabelBox(MathAtom const & atom, +DisplayLabelBox::DisplayLabelBox(Buffer * buf, MathAtom const & atom, docstring label, MathMacroTemplate const & parent) - : InsetLabelBox(atom, label, parent, true) + : InsetLabelBox(buf, atom, label, parent, true) { } @@ -279,9 +279,9 @@ void InsetMathWrapper::draw(PainterInfo & pi, int x, int y) const class InsetColoredCell : public InsetMathNest { public: /// - InsetColoredCell(ColorCode min, ColorCode max); + InsetColoredCell(Buffer * buf, ColorCode min, ColorCode max); /// - InsetColoredCell(ColorCode min, ColorCode max, MathAtom const & atom); + InsetColoredCell(Buffer * buf, ColorCode min, ColorCode max, MathAtom const & atom); /// void draw(PainterInfo &, int x, int y) const; /// @@ -297,14 +297,14 @@ protected: }; -InsetColoredCell::InsetColoredCell(ColorCode min, ColorCode max) - : InsetMathNest(1), min_(min), max_(max) +InsetColoredCell::InsetColoredCell(Buffer * buf, ColorCode min, ColorCode max) + : InsetMathNest(buf, 1), min_(min), max_(max) { } -InsetColoredCell::InsetColoredCell(ColorCode min, ColorCode max, MathAtom const & atom) - : InsetMathNest(1), min_(min), max_(max) +InsetColoredCell::InsetColoredCell(Buffer * buf, ColorCode min, ColorCode max, MathAtom const & atom) + : InsetMathNest(buf, 1), min_(min), max_(max) { cell(0).insert(0, atom); } @@ -391,23 +391,20 @@ void InsetNameWrapper::draw(PainterInfo & pi, int x, int y) const MathMacroTemplate::MathMacroTemplate(Buffer * buf) - : InsetMathNest(3), numargs_(0), argsInLook_(0), optionals_(0), + : InsetMathNest(buf, 3), numargs_(0), argsInLook_(0), optionals_(0), type_(MacroTypeNewcommand), lookOutdated_(true) { - buffer_ = buf; initMath(); } -MathMacroTemplate::MathMacroTemplate(docstring const & name, int numargs, - int optionals, MacroType type, Buffer * buf, - vector const & optionalValues, +MathMacroTemplate::MathMacroTemplate(Buffer * buf, docstring const & name, int numargs, + int optionals, MacroType type, vector const & optionalValues, MathData const & def, MathData const & display) - : InsetMathNest(optionals + 3), numargs_(numargs), argsInLook_(numargs), + : InsetMathNest(buf, optionals + 3), numargs_(numargs), argsInLook_(numargs), optionals_(optionals), optionalValues_(optionalValues), type_(type), lookOutdated_(true) { - buffer_ = buf; initMath(); if (numargs_ > 9) @@ -425,15 +422,15 @@ MathMacroTemplate::MathMacroTemplate(docstring const & name, int numargs, } -MathMacroTemplate::MathMacroTemplate(docstring const & str, Buffer * buf) - : InsetMathNest(3), numargs_(0), optionals_(0), +MathMacroTemplate::MathMacroTemplate(Buffer * buf, docstring const & str) + : InsetMathNest(buf, 3), numargs_(0), optionals_(0), type_(MacroTypeNewcommand), lookOutdated_(true) { buffer_ = buf; initMath(); - MathData ar; - mathed_parse_cell(ar, str, Parse::NORMAL, buf); + MathData ar(buf); + mathed_parse_cell(ar, str, Parse::NORMAL); if (ar.size() != 1 || !ar[0]->asMacroTemplate()) { lyxerr << "Cannot read macro from '" << ar << "'" << endl; asArray(from_ascii("invalidmacro"), cell(0)); @@ -482,21 +479,23 @@ void MathMacroTemplate::createLook(int args) const argsInLook_ = args; // \foo - look_.push_back(MathAtom(new InsetLabelBox(_("Name"), *this, false))); + look_.push_back(MathAtom( + new InsetLabelBox(buffer_, _("Name"), *this, false))); MathData & nameData = look_[look_.size() - 1].nucleus()->cell(0); nameData.push_back(MathAtom(new InsetNameWrapper(&cell(0), *this))); // [#1][#2] int i = 0; if (optionals_ > 0) { - look_.push_back(MathAtom(new InsetLabelBox(_("optional"), *this, false))); + look_.push_back(MathAtom( + new InsetLabelBox(buffer_, _("optional"), *this, false))); MathData * optData = &look_[look_.size() - 1].nucleus()->cell(0); for (; i < optionals_; ++i) { // color it light grey, if it is to be removed when the cursor leaves if (i == argsInLook_) { optData->push_back(MathAtom( - new InsetColoredCell(Color_mathbg, Color_mathmacrooldarg))); + new InsetColoredCell(buffer_, Color_mathbg, Color_mathmacrooldarg))); optData = &(*optData)[optData->size() - 1].nucleus()->cell(0); } @@ -511,7 +510,7 @@ void MathMacroTemplate::createLook(int args) const MathData arg; arg.push_back(MathAtom(new MathMacroArgument(i + 1))); if (i >= argsInLook_) { - look_.push_back(MathAtom(new InsetColoredCell( + look_.push_back(MathAtom(new InsetColoredCell(buffer_, Color_mathbg, Color_mathmacrooldarg, MathAtom(new InsetMathBrace(arg))))); } else @@ -520,7 +519,7 @@ void MathMacroTemplate::createLook(int args) const for (; i < argsInLook_; ++i) { MathData arg; arg.push_back(MathAtom(new MathMacroArgument(i + 1))); - look_.push_back(MathAtom(new InsetColoredCell( + look_.push_back(MathAtom(new InsetColoredCell(buffer_, Color_mathbg, Color_mathmacronewarg, MathAtom(new InsetMathBrace(arg))))); } @@ -531,12 +530,12 @@ void MathMacroTemplate::createLook(int args) const // definition look_.push_back(MathAtom( - new InsetLabelBox(MathAtom( + new InsetLabelBox(buffer_, MathAtom( new InsetMathWrapper(&cell(defIdx()))), _("TeX"), *this, true))); // display look_.push_back(MathAtom( - new DisplayLabelBox(MathAtom( + new DisplayLabelBox(buffer_, MathAtom( new InsetMathWrapper(&cell(displayIdx()))), _("LyX"), *this))); } @@ -1108,8 +1107,8 @@ bool MathMacroTemplate::getStatus(Cursor & /*cur*/, FuncRequest const & cmd, void MathMacroTemplate::read(Lexer & lex) { - MathData ar; - mathed_parse_cell(ar, lex.getStream(), Parse::NORMAL, &buffer()); + MathData ar(buffer_); + mathed_parse_cell(ar, lex.getStream(), Parse::NORMAL); if (ar.size() != 1 || !ar[0]->asMacroTemplate()) { lyxerr << "Cannot read macro from '" << ar << "'" << endl; lyxerr << "Read: " << to_utf8(asString(ar)) << endl; diff --git a/src/mathed/MathMacroTemplate.h b/src/mathed/MathMacroTemplate.h index 4b6b98924b..f6ac948d87 100644 --- a/src/mathed/MathMacroTemplate.h +++ b/src/mathed/MathMacroTemplate.h @@ -26,15 +26,15 @@ namespace lyx { class MathMacroTemplate : public InsetMathNest { public: /// - MathMacroTemplate(Buffer * buf = 0); + MathMacroTemplate(Buffer * buf); /// - MathMacroTemplate(docstring const & name, int nargs, int optional, - MacroType type, Buffer * buf = 0, + MathMacroTemplate(Buffer * buf, docstring const & name, int nargs, + int optional, MacroType type, std::vector const & optionalValues = std::vector(), MathData const & def = MathData(), MathData const & display = MathData()); /// - explicit MathMacroTemplate(const docstring & str, Buffer * buf = 0); + MathMacroTemplate(Buffer * buf, const docstring & str); /// bool editable() const { return true; } /// diff --git a/src/mathed/MathParser.cpp b/src/mathed/MathParser.cpp index 74db5acc92..7c67f0df87 100644 --- a/src/mathed/MathParser.cpp +++ b/src/mathed/MathParser.cpp @@ -681,12 +681,12 @@ void Parser::error(string const & msg) bool Parser::parse(MathAtom & at) { skipSpaces(); - MathData ar; + MathData ar(buffer_); parse(ar, false, InsetMath::UNDECIDED_MODE); if (ar.size() != 1 || ar.front()->getType() == hullNone) { if (!(mode_ & Parse::QUIET)) lyxerr << "unusual contents found: " << ar << endl; - at = MathAtom(new InsetMathPar(ar)); + at = MathAtom(new InsetMathPar(buffer_, ar)); //if (at->nargs() > 0) // at.nucleus()->cell(0) = ar; //else @@ -737,7 +737,7 @@ docstring Parser::parse_verbatim_item() MathData Parser::parse(unsigned flags, mode_type mode) { - MathData ar; + MathData ar(buffer_); parse(ar, flags, mode); return ar; } @@ -745,7 +745,7 @@ MathData Parser::parse(unsigned flags, mode_type mode) bool Parser::parse(MathData & array, unsigned flags, mode_type mode) { - InsetMathGrid grid(1, 1); + InsetMathGrid grid(buffer_, 1, 1); parse1(grid, flags, mode, false); array = grid.cell(0); return success_; @@ -766,6 +766,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, InsetMathGrid::row_type cellrow = 0; InsetMathGrid::col_type cellcol = 0; MathData * cell = &grid.cell(grid.index(cellrow, cellcol)); + Buffer * buf = buffer_; if (grid.asHullInset()) grid.asHullInset()->numbered(cellrow, numbered); @@ -835,18 +836,18 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, Token const & n = getToken(); if (n.cat() == catMath) { // TeX's $$...$$ syntax for displayed math - cell->push_back(MathAtom(new InsetMathHull(hullEquation, buffer_))); + cell->push_back(MathAtom(new InsetMathHull(buffer_, hullEquation))); parse2(cell->back(), FLAG_SIMPLE, InsetMath::MATH_MODE, false); getToken(); // skip the second '$' token } else { // simple $...$ stuff putback(); if (mode == InsetMath::UNDECIDED_MODE) { - cell->push_back(MathAtom(new InsetMathHull(hullSimple, buffer_))); + cell->push_back(MathAtom(new InsetMathHull(buffer_, hullSimple))); parse2(cell->back(), FLAG_SIMPLE, InsetMath::MATH_MODE, false); } else { // Don't create nested math hulls (bug #5392) - cell->push_back(MathAtom(new InsetMathEnsureMath)); + cell->push_back(MathAtom(new InsetMathEnsureMath(buffer_))); parse(cell->back().nucleus()->cell(0), FLAG_SIMPLE, InsetMath::MATH_MODE); } } @@ -917,14 +918,14 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, // we need no new script inset if the last thing was a scriptinset, // which has that script already not the same script already if (!cell->size()) - cell->push_back(MathAtom(new InsetMathScript(up))); + cell->push_back(MathAtom(new InsetMathScript(buffer_, up))); else if (cell->back()->asScriptInset() && !cell->back()->asScriptInset()->has(up)) cell->back().nucleus()->asScriptInset()->ensure(up); else if (cell->back()->asScriptInset()) - cell->push_back(MathAtom(new InsetMathScript(up))); + cell->push_back(MathAtom(new InsetMathScript(buffer_, up))); else - cell->back() = MathAtom(new InsetMathScript(cell->back(), up)); + cell->back() = MathAtom(new InsetMathScript(buffer_, cell->back(), up)); InsetMathScript * p = cell->back().nucleus()->asScriptInset(); // special handling of {}-bases // Here we could remove the brace inset for things @@ -958,7 +959,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, || mode == InsetMath::TEXT_MODE) { cell->push_back(MathAtom(new InsetMathChar(c))); } else { - MathAtom at = createInsetMath("text"); + MathAtom at = createInsetMath("text", buf); at.nucleus()->cell(0).push_back(MathAtom(new InsetMathChar(c))); while (nextToken().cat() == catOther && !isAsciiOrMathAlpha(nextToken().character())) { @@ -977,7 +978,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, break; s += t.asString(); } - cell->push_back(MathAtom(new InsetMathComment(s))); + cell->push_back(MathAtom(new InsetMathComment(buffer_, s))); skipSpaces(); } @@ -1017,8 +1018,8 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, if (nextToken().cat() == catBegin) parse(display, FLAG_ITEM, InsetMath::MATH_MODE); - cell->push_back(MathAtom(new MathMacroTemplate(name, - nargs, 0, MacroTypeDef, buffer_, + cell->push_back(MathAtom(new MathMacroTemplate(buffer_, name, + nargs, 0, MacroTypeDef, vector(), def, display))); } @@ -1062,8 +1063,8 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, if (nextToken().cat() == catBegin) parse(display, FLAG_ITEM, InsetMath::MATH_MODE); - cell->push_back(MathAtom(new MathMacroTemplate(name, - nargs, optionals, MacroTypeNewcommand, buffer_, + cell->push_back(MathAtom(new MathMacroTemplate(buffer_, name, + nargs, optionals, MacroTypeNewcommand, optionalValues, def, display))); } @@ -1180,8 +1181,8 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, if (nextToken().cat() == catBegin) parse(display, FLAG_ITEM, InsetMath::MATH_MODE); - cell->push_back(MathAtom(new MathMacroTemplate(name, - nargs, optionals, MacroTypeNewcommandx, buffer_, + cell->push_back(MathAtom(new MathMacroTemplate(buffer_, name, + nargs, optionals, MacroTypeNewcommandx, optionalValues, def, display))); } @@ -1190,7 +1191,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, error("bad math environment"); break; } - cell->push_back(MathAtom(new InsetMathHull(hullSimple, buffer_))); + cell->push_back(MathAtom(new InsetMathHull(buffer_, hullSimple))); parse2(cell->back(), FLAG_SIMPLE2, InsetMath::MATH_MODE, false); } @@ -1199,7 +1200,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, error("bad math environment"); break; } - cell->push_back(MathAtom(new InsetMathHull(hullEquation, buffer_))); + cell->push_back(MathAtom(new InsetMathHull(buffer_, hullEquation))); parse2(cell->back(), FLAG_EQUATION, InsetMath::MATH_MODE, false); } @@ -1326,11 +1327,11 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, MathData ar; parse(ar, FLAG_OPTION, mode); if (ar.size()) { - cell->push_back(MathAtom(new InsetMathRoot)); + cell->push_back(MathAtom(new InsetMathRoot(buffer_))); cell->back().nucleus()->cell(0) = ar; parse(cell->back().nucleus()->cell(1), FLAG_ITEM, mode); } else { - cell->push_back(MathAtom(new InsetMathSqrt)); + cell->push_back(MathAtom(new InsetMathSqrt(buffer_))); parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode); } } @@ -1340,11 +1341,11 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, MathData ar; parse(ar, FLAG_OPTION, mode); if (ar.size()) { - cell->push_back(MathAtom(new InsetMathFrac(InsetMathFrac::UNIT))); + cell->push_back(MathAtom(new InsetMathFrac(buffer_, InsetMathFrac::UNIT))); cell->back().nucleus()->cell(0) = ar; parse(cell->back().nucleus()->cell(1), FLAG_ITEM, mode); } else { - cell->push_back(MathAtom(new InsetMathFrac(InsetMathFrac::UNIT, 1))); + cell->push_back(MathAtom(new InsetMathFrac(buffer_, InsetMathFrac::UNIT, 1))); parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode); } } @@ -1354,10 +1355,10 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, MathData ar; parse(ar, FLAG_OPTION, mode); if (ar.size()) { - cell->push_back(MathAtom(new InsetMathFrac(InsetMathFrac::UNITFRAC, 3))); + cell->push_back(MathAtom(new InsetMathFrac(buffer_, InsetMathFrac::UNITFRAC, 3))); cell->back().nucleus()->cell(2) = ar; } else { - cell->push_back(MathAtom(new InsetMathFrac(InsetMathFrac::UNITFRAC))); + cell->push_back(MathAtom(new InsetMathFrac(buffer_, InsetMathFrac::UNITFRAC))); } parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode); parse(cell->back().nucleus()->cell(1), FLAG_ITEM, mode); @@ -1368,11 +1369,11 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, docstring const arg = getArg('[', ']'); //lyxerr << "got so far: '" << arg << "'" << endl; if (arg == "l") - cell->push_back(MathAtom(new InsetMathFrac(InsetMathFrac::CFRACLEFT))); + cell->push_back(MathAtom(new InsetMathFrac(buffer_, InsetMathFrac::CFRACLEFT))); else if (arg == "r") - cell->push_back(MathAtom(new InsetMathFrac(InsetMathFrac::CFRACRIGHT))); + cell->push_back(MathAtom(new InsetMathFrac(buffer_, InsetMathFrac::CFRACRIGHT))); else if (arg.empty() || arg == "c") - cell->push_back(MathAtom(new InsetMathFrac(InsetMathFrac::CFRAC))); + cell->push_back(MathAtom(new InsetMathFrac(buffer_, InsetMathFrac::CFRAC))); else { error("found invalid optional argument"); break; @@ -1382,14 +1383,14 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, } else if (t.cs() == "xrightarrow" || t.cs() == "xleftarrow") { - cell->push_back(createInsetMath(t.cs())); + cell->push_back(createInsetMath(t.cs(), buf)); parse(cell->back().nucleus()->cell(1), FLAG_OPTION, mode); parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode); } else if (t.cs() == "ref" || t.cs() == "eqref" || t.cs() == "prettyref" || t.cs() == "pageref" || t.cs() == "vpageref" || t.cs() == "vref") { - cell->push_back(MathAtom(new InsetMathRef(t.cs()))); + cell->push_back(MathAtom(new InsetMathRef(buffer_, t.cs()))); parse(cell->back().nucleus()->cell(1), FLAG_OPTION, mode); parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode); } @@ -1408,7 +1409,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, skipSpaces(); Token const & tr = getToken(); docstring const r = tr.cs() == "|" ? from_ascii("Vert") : tr.asString(); - cell->push_back(MathAtom(new InsetMathDelim(l, r, ar))); + cell->push_back(MathAtom(new InsetMathDelim(buf, l, r, ar))); } else if (t.cs() == "right") { @@ -1426,7 +1427,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, if (name == "array" || name == "subarray") { docstring const valign = parse_verbatim_option() + 'c'; docstring const halign = parse_verbatim_item(); - cell->push_back(MathAtom(new InsetMathArray(name, + cell->push_back(MathAtom(new InsetMathArray(buffer_, name, InsetMathGrid::guessColumns(halign), 1, (char)valign[0], halign))); parse2(cell->back(), FLAG_END, mode, false); } @@ -1434,13 +1435,13 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, else if (name == "tabular") { docstring const valign = parse_verbatim_option() + 'c'; docstring const halign = parse_verbatim_item(); - cell->push_back(MathAtom(new InsetMathTabular(name, + cell->push_back(MathAtom(new InsetMathTabular(buffer_, name, InsetMathGrid::guessColumns(halign), 1, (char)valign[0], halign))); parse2(cell->back(), FLAG_END, InsetMath::TEXT_MODE, false); } else if (name == "split" || name == "cases") { - cell->push_back(createInsetMath(name)); + cell->push_back(createInsetMath(name, buf)); parse2(cell->back(), FLAG_END, mode, false); } @@ -1448,7 +1449,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, docstring const valign = parse_verbatim_option() + 'c'; // ignore this for a while getArg('{', '}'); - cell->push_back(MathAtom(new InsetMathSplit(name, (char)valign[0]))); + cell->push_back(MathAtom(new InsetMathSplit(buffer_, name, (char)valign[0]))); parse2(cell->back(), FLAG_END, mode, false); } @@ -1457,7 +1458,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, error("bad math environment"); break; } - cell->push_back(MathAtom(new InsetMathHull(hullSimple, buffer_))); + cell->push_back(MathAtom(new InsetMathHull(buffer_, hullSimple))); parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, true); } @@ -1467,7 +1468,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, error("bad math environment"); break; } - cell->push_back(MathAtom(new InsetMathHull(hullEquation, buffer_))); + cell->push_back(MathAtom(new InsetMathHull(buffer_, hullEquation))); parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, (name == "equation")); } @@ -1476,7 +1477,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, error("bad math environment"); break; } - cell->push_back(MathAtom(new InsetMathHull(hullEqnArray, buffer_))); + cell->push_back(MathAtom(new InsetMathHull(buffer_, hullEqnArray))); parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name)); } @@ -1485,7 +1486,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, error("bad math environment"); break; } - cell->push_back(MathAtom(new InsetMathHull(hullAlign, buffer_))); + cell->push_back(MathAtom(new InsetMathHull(buffer_, hullAlign))); parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name)); } @@ -1494,7 +1495,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, error("bad math environment"); break; } - cell->push_back(MathAtom(new InsetMathHull(hullFlAlign, buffer_))); + cell->push_back(MathAtom(new InsetMathHull(buffer_, hullFlAlign))); parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name)); } @@ -1505,7 +1506,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, } // ignore this for a while getArg('{', '}'); - cell->push_back(MathAtom(new InsetMathHull(hullAlignAt, buffer_))); + cell->push_back(MathAtom(new InsetMathHull(buffer_, hullAlignAt))); parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name)); } @@ -1516,7 +1517,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, } // ignore this for a while getArg('{', '}'); - cell->push_back(MathAtom(new InsetMathHull(hullXAlignAt, buffer_))); + cell->push_back(MathAtom(new InsetMathHull(buffer_, hullXAlignAt))); parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name)); } @@ -1527,7 +1528,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, } // ignore this for a while getArg('{', '}'); - cell->push_back(MathAtom(new InsetMathHull(hullXXAlignAt, buffer_))); + cell->push_back(MathAtom(new InsetMathHull(buffer_, hullXXAlignAt))); parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name)); } @@ -1536,7 +1537,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, error("bad math environment"); break; } - cell->push_back(MathAtom(new InsetMathHull(hullMultline, buffer_))); + cell->push_back(MathAtom(new InsetMathHull(buffer_, hullMultline))); parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name)); } @@ -1545,17 +1546,18 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, error("bad math environment"); break; } - cell->push_back(MathAtom(new InsetMathHull(hullGather, buffer_))); + cell->push_back(MathAtom(new InsetMathHull(buffer_, hullGather))); parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name)); } else if (latexkeys const * l = in_word_set(name)) { if (l->inset == "matrix") { - cell->push_back(createInsetMath(name)); + cell->push_back(createInsetMath(name, buf)); parse2(cell->back(), FLAG_END, mode, false); } else if (l->inset == "split") { docstring const valign = parse_verbatim_option() + 'c'; - cell->push_back(MathAtom(new InsetMathSplit(name, (char)valign[0]))); + cell->push_back(MathAtom( + new InsetMathSplit(buffer_, name, (char)valign[0]))); parse2(cell->back(), FLAG_END, mode, false); } else { success_ = false; @@ -1568,7 +1570,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, << "'." << endl; } // create generic environment inset - cell->push_back(MathAtom(new InsetMathEnv(name))); + cell->push_back(MathAtom(new InsetMathEnv(buffer_, name))); parse(cell->back().nucleus()->cell(0), FLAG_END, mode); } } @@ -1581,7 +1583,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, << to_utf8(name) << "'" << endl; } // create generic environment inset - cell->push_back(MathAtom(new InsetMathEnv(name))); + cell->push_back(MathAtom(new InsetMathEnv(buffer_, name))); parse(cell->back().nucleus()->cell(0), FLAG_END, mode); } } @@ -1617,7 +1619,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, if (grid.asHullInset()) { grid.asHullInset()->label(cellrow, label); } else { - cell->push_back(createInsetMath(t.cs())); + cell->push_back(createInsetMath(t.cs(), buf)); cell->push_back(MathAtom(new InsetMathBrace(ar))); } } @@ -1625,7 +1627,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, else if (t.cs() == "choose" || t.cs() == "over" || t.cs() == "atop" || t.cs() == "brace" || t.cs() == "brack") { - MathAtom at = createInsetMath(t.cs()); + MathAtom at = createInsetMath(t.cs(), buf); at.nucleus()->cell(0) = *cell; cell->clear(); parse(at.nucleus()->cell(1), flags, mode); @@ -1635,25 +1637,25 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, else if (t.cs() == "color") { docstring const color = parse_verbatim_item(); - cell->push_back(MathAtom(new InsetMathColor(true, color))); + cell->push_back(MathAtom(new InsetMathColor(buffer_, true, color))); parse(cell->back().nucleus()->cell(0), flags, mode); return success_; } else if (t.cs() == "textcolor") { docstring const color = parse_verbatim_item(); - cell->push_back(MathAtom(new InsetMathColor(false, color))); + cell->push_back(MathAtom(new InsetMathColor(buffer_, false, color))); parse(cell->back().nucleus()->cell(0), FLAG_ITEM, InsetMath::TEXT_MODE); } else if (t.cs() == "normalcolor") { - cell->push_back(createInsetMath(t.cs())); + cell->push_back(createInsetMath(t.cs(), buf)); parse(cell->back().nucleus()->cell(0), flags, mode); return success_; } else if (t.cs() == "substack") { - cell->push_back(createInsetMath(t.cs())); + cell->push_back(createInsetMath(t.cs(), buf)); parse2(cell->back(), FLAG_ITEM, mode, false); } @@ -1661,12 +1663,12 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, odocstringstream os; while (good() && nextToken().cat() != catBegin) os << getToken().asInput(); - cell->push_back(createInsetMath(t.cs() + os.str())); + cell->push_back(createInsetMath(t.cs() + os.str(), buf)); parse2(cell->back(), FLAG_ITEM, mode, false); } else if (t.cs() == "framebox" || t.cs() == "makebox") { - cell->push_back(createInsetMath(t.cs())); + cell->push_back(createInsetMath(t.cs(), buf)); parse(cell->back().nucleus()->cell(0), FLAG_OPTION, InsetMath::TEXT_MODE); parse(cell->back().nucleus()->cell(1), FLAG_OPTION, InsetMath::TEXT_MODE); parse(cell->back().nucleus()->cell(2), FLAG_ITEM, InsetMath::TEXT_MODE); @@ -1675,9 +1677,9 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, else if (t.cs() == "tag") { if (nextToken().character() == '*') { getToken(); - cell->push_back(createInsetMath(t.cs() + '*')); + cell->push_back(createInsetMath(t.cs() + '*', buf)); } else - cell->push_back(createInsetMath(t.cs())); + cell->push_back(createInsetMath(t.cs(), buf)); parse(cell->back().nucleus()->cell(0), FLAG_ITEM, InsetMath::TEXT_MODE); } @@ -1690,10 +1692,10 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, else { // Since the Length class cannot use length variables // we must not create an InsetMathSpace. - cell->push_back(MathAtom(new MathMacro(name))); + cell->push_back(MathAtom(new MathMacro(buffer_, name))); MathData ar; mathed_parse_cell(ar, '{' + arg + '}', - Parse::NORMAL, buffer_); + Parse::NORMAL); cell->append(ar); } } @@ -1702,7 +1704,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, else if (t.cs() == "infer") { MathData ar; parse(ar, FLAG_OPTION, mode); - cell->push_back(createInsetMath(t.cs())); + cell->push_back(createInsetMath(t.cs(), buf)); parse2(cell->back(), FLAG_ITEM, mode, false); } @@ -1772,19 +1774,19 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, cell->push_back(MathAtom( new InsetMathBig(t.cs(), delim))); else { - cell->push_back(createInsetMath(t.cs())); + cell->push_back(createInsetMath(t.cs(), buf)); putback(); } } else if (l->inset == "font") { - cell->push_back(createInsetMath(t.cs())); + cell->push_back(createInsetMath(t.cs(), buf)); parse(cell->back().nucleus()->cell(0), FLAG_ITEM, asMode(mode, l->extra)); } else if (l->inset == "oldfont") { - cell->push_back(createInsetMath(t.cs())); + cell->push_back(createInsetMath(t.cs(), buf)); parse(cell->back().nucleus()->cell(0), flags | FLAG_ALIGN, asMode(mode, l->extra)); if (prevToken().cat() != catAlign && @@ -1794,7 +1796,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, } else if (l->inset == "style") { - cell->push_back(createInsetMath(t.cs())); + cell->push_back(createInsetMath(t.cs(), buf)); parse(cell->back().nucleus()->cell(0), flags | FLAG_ALIGN, mode); if (prevToken().cat() != catAlign && @@ -1804,7 +1806,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, } else { - MathAtom at = createInsetMath(t.cs()); + MathAtom at = createInsetMath(t.cs(), buf); for (InsetMath::idx_type i = 0; i < at->nargs(); ++i) parse(at.nucleus()->cell(i), FLAG_ITEM, asMode(mode, l->extra)); @@ -1852,8 +1854,8 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, } if (!is_unicode_symbol) { MathAtom at = is_user_macro ? - MathAtom(new MathMacro(t.cs())) - : createInsetMath(t.cs()); + MathAtom(new MathMacro(buffer_, t.cs())) + : createInsetMath(t.cs(), buf); InsetMath::mode_type m = mode; //if (m == InsetMath::UNDECIDED_MODE) //lyxerr << "default creation: m1: " << m << endl; @@ -1891,40 +1893,38 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, } // anonymous namespace -bool mathed_parse_cell(MathData & ar, docstring const & str, - Parse::flags f, Buffer * buf) +bool mathed_parse_cell(MathData & ar, docstring const & str, Parse::flags f) { - return Parser(str, f, buf).parse(ar, 0, f & Parse::TEXTMODE ? + return Parser(str, f, ar.buffer()).parse(ar, 0, f & Parse::TEXTMODE ? InsetMath::TEXT_MODE : InsetMath::MATH_MODE); } -bool mathed_parse_cell(MathData & ar, istream & is, - Parse::flags f, Buffer * buf) +bool mathed_parse_cell(MathData & ar, istream & is, Parse::flags f) { - return Parser(is, f, buf).parse(ar, 0, f & Parse::TEXTMODE ? + return Parser(is, f, ar.buffer()).parse(ar, 0, f & Parse::TEXTMODE ? InsetMath::TEXT_MODE : InsetMath::MATH_MODE); } -bool mathed_parse_normal(MathAtom & t, docstring const & str, - Parse::flags f, Buffer * buf) +bool mathed_parse_normal(Buffer * buf, MathAtom & t, docstring const & str, + Parse::flags f) { return Parser(str, f, buf).parse(t); } -bool mathed_parse_normal(MathAtom & t, Lexer & lex, - Parse::flags f, Buffer * buf) +bool mathed_parse_normal(Buffer * buf, MathAtom & t, Lexer & lex, + Parse::flags f) { return Parser(lex, f, buf).parse(t); } bool mathed_parse_normal(InsetMathGrid & grid, docstring const & str, - Parse::flags f, Buffer * buf) + Parse::flags f) { - return Parser(str, f, buf).parse1(grid, 0, f & Parse::TEXTMODE ? + return Parser(str, f, &grid.buffer()).parse1(grid, 0, f & Parse::TEXTMODE ? InsetMath::TEXT_MODE : InsetMath::MATH_MODE, false); } diff --git a/src/mathed/MathParser.h b/src/mathed/MathParser.h index 31cbecc272..c4ae6f8994 100644 --- a/src/mathed/MathParser.h +++ b/src/mathed/MathParser.h @@ -62,25 +62,25 @@ public: latexkeys const * in_word_set(docstring const & str); /// parse formula from a string -bool mathed_parse_normal(MathAtom &, docstring const &, - Parse::flags f = Parse::NORMAL, Buffer * buf = 0); +bool mathed_parse_normal(Buffer * buf, MathAtom &, docstring const &, + Parse::flags f = Parse::NORMAL); /// parse formula from the LyX lexxer -bool mathed_parse_normal(MathAtom &, Lexer &, - Parse::flags f = Parse::NORMAL, Buffer * buf = 0); +bool mathed_parse_normal(Buffer * buf, MathAtom &, Lexer &, + Parse::flags f = Parse::NORMAL); /// parse formula from a string into a grid bool mathed_parse_normal(InsetMathGrid &, docstring const &, - Parse::flags f = Parse::NORMAL, Buffer * buf = 0); + Parse::flags f = Parse::NORMAL); /// parse a single cell from a string bool mathed_parse_cell(MathData & ar, docstring const &, - Parse::flags f = Parse::NORMAL, Buffer * buf = 0); + Parse::flags f = Parse::NORMAL); /// parse a single cell from a stream. Only use this for reading from .lyx /// file format, for the reason see Parser::tokenize(std::istream &). bool mathed_parse_cell(MathData & ar, std::istream &, - Parse::flags f = Parse::NORMAL, Buffer * buf = 0); + Parse::flags f = Parse::NORMAL); void initParser();