From 8b7b3a589507e2bed9777f2854ea731c454492e4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Mon, 6 Aug 2001 17:20:26 +0000 Subject: [PATCH] - fix nasty bug due to missing InsetFormula copy c'tor - make all cache variables mutable, remove const_casts git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2426 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/ChangeLog | 11 ++++++ src/mathed/Makefile.am | 4 ++ src/mathed/array.C | 42 +++++++++------------ src/mathed/array.h | 8 ++-- src/mathed/formula.C | 10 +++-- src/mathed/formula.h | 6 ++- src/mathed/formulabase.C | 2 - src/mathed/formulabase.h | 2 +- src/mathed/formulamacro.C | 14 +++++-- src/mathed/formulamacro.h | 8 +++- src/mathed/math_arrayinset.h | 2 +- src/mathed/math_charinset.C | 8 +++- src/mathed/math_charinset.h | 4 +- src/mathed/math_cursor.C | 61 +++++++++++++++++-------------- src/mathed/math_cursor.h | 13 +++---- src/mathed/math_decorationinset.C | 4 +- src/mathed/math_decorationinset.h | 12 +++--- src/mathed/math_deliminset.C | 4 +- src/mathed/math_deliminset.h | 4 +- src/mathed/math_diminset.h | 9 +++-- src/mathed/math_dotsinset.C | 4 +- src/mathed/math_dotsinset.h | 8 ++-- src/mathed/math_fracinset.C | 4 +- src/mathed/math_fracinset.h | 26 ++++++------- src/mathed/math_funcinset.C | 4 +- src/mathed/math_funcinset.h | 4 +- src/mathed/math_gridinset.C | 4 +- src/mathed/math_gridinset.h | 32 ++++++++-------- src/mathed/math_inset.C | 21 +++++++++-- src/mathed/math_inset.h | 30 +++++++-------- src/mathed/math_macro.C | 10 ++--- src/mathed/math_macro.h | 6 +-- src/mathed/math_macroarg.C | 2 +- src/mathed/math_macroarg.h | 4 +- src/mathed/math_macrotemplate.C | 4 +- src/mathed/math_macrotemplate.h | 4 +- src/mathed/math_matrixinset.C | 4 +- src/mathed/math_matrixinset.h | 4 +- src/mathed/math_nestinset.C | 9 ++--- src/mathed/math_nestinset.h | 24 ++++++------ src/mathed/math_parser.C | 14 ++++++- src/mathed/math_rootinset.C | 4 +- src/mathed/math_rootinset.h | 4 +- src/mathed/math_scriptinset.C | 4 +- src/mathed/math_scriptinset.h | 26 ++++++------- src/mathed/math_sizeinset.C | 4 +- src/mathed/math_sizeinset.h | 6 +-- src/mathed/math_spaceinset.C | 4 +- src/mathed/math_spaceinset.h | 4 +- src/mathed/math_sqrtinset.C | 4 +- src/mathed/math_sqrtinset.h | 4 +- src/mathed/math_symbolinset.C | 4 +- src/mathed/math_symbolinset.h | 16 ++++---- src/mathed/xarray.C | 20 +++++----- src/mathed/xarray.h | 16 ++++---- 55 files changed, 312 insertions(+), 258 deletions(-) diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index c83bbb342b..9001a95578 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,14 @@ + +2001-08-06 André Pönitz + + * formulamacro.C: fix nasty bug due to missing copy constructor + + * math_bigopinset.[Ch]: revival for things like \int, \sum + + * math_funcliminset.[Ch]: dedicated new inset for \lim, \max, \min... + + * math_diminset.h: make cahce variables mutable + 2001-08-01 André Pönitz * math_cursor.C: diff --git a/src/mathed/Makefile.am b/src/mathed/Makefile.am index f81e176edb..277d713f0a 100644 --- a/src/mathed/Makefile.am +++ b/src/mathed/Makefile.am @@ -20,6 +20,8 @@ libmathed_la_SOURCES = \ formulamacro.h \ math_arrayinset.C \ math_arrayinset.h \ + math_bigopinset.C \ + math_bigopinset.h \ math_charinset.C \ math_charinset.h \ math_cursor.C \ @@ -37,6 +39,8 @@ libmathed_la_SOURCES = \ math_fracinset.h \ math_funcinset.C \ math_funcinset.h \ + math_funcliminset.C \ + math_funcliminset.h \ math_gridinset.C \ math_gridinset.h \ math_hash.C \ diff --git a/src/mathed/array.C b/src/mathed/array.C index 9ba5cb6af1..a42580f17a 100644 --- a/src/mathed/array.C +++ b/src/mathed/array.C @@ -38,8 +38,11 @@ MathArray::MathArray(MathArray const & array, int from, int to) void MathArray::deep_copy(int pos1, int pos2) { - for (int pos = pos1; pos < pos2; ++pos) - bf_[pos] = bf_[pos]->clone(); + for (int pos = pos1; pos < pos2; ++pos) { + MathInset * p = bf_[pos]->clone(); + //lyxerr << "cloning: '" << bf_[pos] << " to " << p << "'\n"; + bf_[pos] = p; + } } @@ -53,20 +56,9 @@ bool MathArray::next(int & pos) const } -bool MathArray::prev(int & pos) const +int MathArray::last() const { - if (pos == 0) - return false; - - --pos; - return true; -} - - -bool MathArray::last(int & pos) const -{ - pos = bf_.size(); - return prev(pos); + return size() - 1; } @@ -87,15 +79,15 @@ MathArray & MathArray::operator=(MathArray const & array) } -MathInset * MathArray::nextInset(int pos) const +MathInset * MathArray::nextInset(int pos) { return (pos == size()) ? 0 : bf_[pos]; } -MathInset * MathArray::prevInset(int pos) const +MathInset const * MathArray::nextInset(int pos) const { - return (pos == 0) ? 0 : bf_[pos - 1]; + return (pos == size()) ? 0 : bf_[pos]; } @@ -220,15 +212,14 @@ void MathArray::erase(int pos1, int pos2) MathInset * MathArray::back() const { - return prevInset(size()); + return size() ? bf_.back() : 0; } void MathArray::dump2(ostream & os) const { for (buffer_type::const_iterator it = bf_.begin(); it != bf_.end(); ++it) - os << int(*it) << ' '; - os << endl; + os << *it << ' '; } @@ -273,8 +264,11 @@ void MathArray::validate(LaTeXFeatures & features) const void MathArray::pop_back() { - int pos = size(); - prev(pos); - erase(pos, size()); + if (!size()) { + lyxerr << "pop_back from empty array!\n"; + return; + } + delete back(); + bf_.pop_back(); } diff --git a/src/mathed/array.h b/src/mathed/array.h index bcbe00a997..836bc74029 100644 --- a/src/mathed/array.h +++ b/src/mathed/array.h @@ -76,11 +76,9 @@ public: /// void erase(); /// - bool prev(int & pos) const; - /// bool next(int & pos) const; /// - bool last(int & pos) const; + int last() const; /// @@ -103,9 +101,9 @@ public: /// /// - MathInset * nextInset(int pos) const; + MathInset * nextInset(int pos); /// - MathInset * prevInset(int pos) const; + MathInset const * nextInset(int pos) const; /// unsigned char getChar(int pos) const; /// read subsequent chars of the same kind. diff --git a/src/mathed/formula.C b/src/mathed/formula.C index 5802cfa4df..88dacdbed8 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -55,6 +55,11 @@ InsetFormula::InsetFormula() {} +InsetFormula::InsetFormula(const InsetFormula & f) + : InsetFormulaBase(f), par_(static_cast(f.par_->clone())) +{} + + InsetFormula::InsetFormula(MathInsetTypes t) : par_(new MathMatrixInset(t)) {} @@ -148,8 +153,7 @@ void InsetFormula::draw(BufferView * bv, LyXFont const &, void InsetFormula::metrics() const { - const_cast(par_) - -> metrics(display() ? LM_ST_DISPLAY : LM_ST_TEXT); + par_->metrics(display() ? LM_ST_DISPLAY : LM_ST_TEXT); } vector const InsetFormula::getLabelList() const @@ -314,7 +318,7 @@ bool InsetFormula::display() const } -MathInset * InsetFormula::par() const +MathInset const * InsetFormula::par() const { return par_; } diff --git a/src/mathed/formula.h b/src/mathed/formula.h index 30be0a5d2a..0bbe02cdc3 100644 --- a/src/mathed/formula.h +++ b/src/mathed/formula.h @@ -32,12 +32,16 @@ public: /// InsetFormula(); /// + InsetFormula(InsetFormula const &); + /// explicit InsetFormula(MathInsetTypes); /// explicit InsetFormula(string const &); /// ~InsetFormula(); /// + void operator=(InsetFormula const &); + /// int ascent(BufferView *, LyXFont const &) const; /// int descent(BufferView *, LyXFont const &) const; @@ -77,7 +81,7 @@ public: /// void handleExtern(string const & arg, BufferView * bv); /// - MathInset * par() const; + MathInset const * par() const; /// bool display() const; /// diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index e748bbf137..5cba2ecf43 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -191,8 +191,6 @@ void InsetFormulaBase::edit(BufferView * bv, int x, int /*y*/, unsigned int) void InsetFormulaBase::edit(BufferView * bv, bool front) { -#warning Please have a look if this is right (Jug) -#warning Does not look wrong... although I do not know what it is supposed to do (Andre) edit(bv, front ? 0 : 1, 0, 0); } diff --git a/src/mathed/formulabase.h b/src/mathed/formulabase.h index c04fa737a5..a433d723bd 100644 --- a/src/mathed/formulabase.h +++ b/src/mathed/formulabase.h @@ -118,7 +118,7 @@ public: /// virtual std::vector const getLabelList() const; /// - virtual MathInset * par() const = 0; + virtual MathInset const * par() const = 0; /// virtual void metrics() const = 0; protected: diff --git a/src/mathed/formulamacro.C b/src/mathed/formulamacro.C index efd6c696a2..d7e4b460c4 100644 --- a/src/mathed/formulamacro.C +++ b/src/mathed/formulamacro.C @@ -47,6 +47,12 @@ InsetFormulaMacro::InsetFormulaMacro() {} +InsetFormulaMacro::InsetFormulaMacro(InsetFormulaMacro const & m) + : InsetFormulaBase(m), + tmacro_(static_cast(m.tmacro_->clone())) +{} + + InsetFormulaMacro::InsetFormulaMacro(string nm, int na) : tmacro_(new MathMacroTemplate(nm, na)) { @@ -185,15 +191,15 @@ MathInsetTypes InsetFormulaMacro::getType() const } -MathInset * InsetFormulaMacro::par() const +MathInset const * InsetFormulaMacro::par() const { - return const_cast(tmacro_); + return tmacro_; } void InsetFormulaMacro::metrics() const { - par()->metrics(LM_ST_TEXT); + tmacro_->metrics(LM_ST_TEXT); } @@ -223,7 +229,7 @@ void InsetFormulaMacro::draw(BufferView * bv, LyXFont const & f, // formula float t = tmacro().width() + 5; x -= t; - par()->draw(pain, int(x), baseline); + tmacro_->draw(pain, int(x), baseline); x += t; } diff --git a/src/mathed/formulamacro.h b/src/mathed/formulamacro.h index a52f641923..3ae2f5ce1a 100644 --- a/src/mathed/formulamacro.h +++ b/src/mathed/formulamacro.h @@ -33,12 +33,16 @@ class MathMacroTemplate; class InsetFormulaMacro: public InsetFormulaBase { public: /// - explicit InsetFormulaMacro(); + InsetFormulaMacro(); + /// + InsetFormulaMacro(InsetFormulaMacro const &); /// explicit InsetFormulaMacro(string name, int na); /// ~InsetFormulaMacro(); /// + void operator=(InsetFormulaMacro const &); + /// int ascent(BufferView *, LyXFont const &) const; /// int descent(BufferView *, LyXFont const &) const; @@ -69,7 +73,7 @@ public: /// MathInsetTypes getType() const; /// - MathInset * par() const; + MathInset const * par() const; /// void metrics() const; private: diff --git a/src/mathed/math_arrayinset.h b/src/mathed/math_arrayinset.h index 240c2bf42c..1dc35f05a1 100644 --- a/src/mathed/math_arrayinset.h +++ b/src/mathed/math_arrayinset.h @@ -14,7 +14,7 @@ public: /// MathArrayInset(int m, int n); /// - virtual MathInset * clone() const; + MathInset * clone() const; /// void write(std::ostream &, bool fragile) const; /// diff --git a/src/mathed/math_charinset.C b/src/mathed/math_charinset.C index 7316603ade..a5eca98288 100644 --- a/src/mathed/math_charinset.C +++ b/src/mathed/math_charinset.C @@ -42,7 +42,13 @@ int MathCharInset::width() const } -void MathCharInset::draw(Painter & pain, int x, int y) +void MathCharInset::metrics(MathStyles st) const +{ + size_ = st; +} + + +void MathCharInset::draw(Painter & pain, int x, int y) const { xo(x); yo(y); diff --git a/src/mathed/math_charinset.h b/src/mathed/math_charinset.h index 718faab5b5..9cc0fbb3d6 100644 --- a/src/mathed/math_charinset.h +++ b/src/mathed/math_charinset.h @@ -19,7 +19,9 @@ public: /// MathInset * clone() const; /// - void draw(Painter &, int x, int baseline); + void metrics(MathStyles st) const; + /// + void draw(Painter &, int x, int y) const; /// void write(std::ostream &, bool fragile) const; /// diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index 7eca200b1e..abb95af028 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -30,12 +30,14 @@ #include "formulabase.h" #include "math_cursor.h" #include "math_arrayinset.h" +#include "math_bigopinset.h" #include "math_symbolinset.h" #include "math_decorationinset.h" #include "math_deliminset.h" #include "math_dotsinset.h" #include "math_fracinset.h" #include "math_funcinset.h" +#include "math_funcliminset.h" #include "math_gridinset.h" #include "math_macro.h" #include "math_macroarg.h" @@ -195,7 +197,7 @@ void MathCursor::seldump(char const *) const } -bool MathCursor::isInside(MathInset * p) const +bool MathCursor::isInside(MathInset const * p) const { for (unsigned i = 0; i < Cursor_.size(); ++i) if (parInset(i) == p) @@ -222,9 +224,9 @@ bool MathCursor::openable(MathInset * p, bool sel, bool useupdown) const } -bool MathCursor::plainLeft() +void MathCursor::plainLeft() { - return array().prev(cursor().pos_); + --cursor().pos_; } @@ -249,8 +251,10 @@ bool MathCursor::left(bool sel) push(p, false); return true; } - if (plainLeft()) + if (cursor().pos_) { + plainLeft(); return true; + } if (cursor().par_->idxLeft(cursor().idx_, cursor().pos_)) return true; if (pop()) @@ -294,14 +298,14 @@ bool MathCursor::right(bool sel) void MathCursor::first() { Cursor_.clear(); - push(formula_->par(), true); + push(outerPar(), true); } void MathCursor::last() { Cursor_.clear(); - push(formula_->par(), false); + push(outerPar(), false); } @@ -314,7 +318,7 @@ void MathCursor::setPos(int x, int y) lastcode_ = LM_TC_MIN; first(); - cursor().par_ = formula()->par(); + cursor().par_ = outerPar(); while (1) { cursor().idx_ = -1; @@ -370,7 +374,7 @@ void MathCursor::end() clearLastCode(); if (!cursor().par_->idxEnd(cursor().idx_, cursor().pos_)) { pop(); - array().next(cursor().pos_); + ++cursor().pos_; } dump("end 2"); } @@ -403,7 +407,7 @@ void MathCursor::insert(char c, MathTextCodes t) } array().insert(cursor().pos_, c, t); - array().next(cursor().pos_); + ++cursor().pos_; } @@ -586,9 +590,9 @@ bool MathCursor::down(bool sel) bool MathCursor::toggleLimits() { - if (!prevIsInset()) - return false; MathScriptInset * p = prevScriptInset(); + if (!p) + return false; int old = p->limits(); p->limits(old < 0 ? 1 : -1); return old != p->limits(); @@ -670,9 +674,15 @@ void MathCursor::interpret(string const & s) p = new MathFuncInset(s); } else { switch (l->token) { - case LM_TK_SYM: case LM_TK_BIGSYM: + p = new MathBigopInset(l); + break; + case LM_TK_FUNCLIM: + p = new MathFuncLimInset(l); + break; + + case LM_TK_SYM: p = new MathSymbolInset(l); break; @@ -1049,7 +1059,7 @@ MathInset * MathCursor::prevInset() const { normalize(); int c = cursor().pos_; - if (!array().prev(c)) + if (!c) return 0; return array().nextInset(c); } @@ -1065,7 +1075,7 @@ MathInset * MathCursor::nextInset() const MathScriptInset * MathCursor::prevScriptInset() const { normalize(); - MathInset * p = array().prevInset(cursor().pos_); + MathInset * p = prevInset(); return (p && p->isScriptInset()) ? static_cast(p) : 0; } @@ -1073,7 +1083,7 @@ MathScriptInset * MathCursor::prevScriptInset() const MathSpaceInset * MathCursor::prevSpaceInset() const { normalize(); - MathInset * p = array().prevInset(cursor().pos_); + MathInset * p = prevInset(); return (p && p->isSpaceInset()) ? static_cast(p) : 0; } @@ -1101,18 +1111,6 @@ MathXArray & MathCursor::xarray() const } -bool MathCursor::nextIsInset() const -{ - return cursor().pos_ < array().size() && MathIsInset(nextCode()); -} - - -bool MathCursor::prevIsInset() const -{ - return cursor().pos_ > 0 && MathIsInset(prevCode()); -} - - int MathCursor::xpos() const { normalize(); @@ -1153,7 +1151,7 @@ void MathCursor::splitCell() void MathCursor::breakLine() { - MathMatrixInset * p = static_cast(formula()->par()); + MathMatrixInset * p = outerPar(); if (p->getType() == LM_OT_SIMPLE || p->getType() == LM_OT_EQUATION) { p->mutate(LM_OT_EQNARRAY); p->addRow(0); @@ -1314,3 +1312,10 @@ bool MathCursorPos::idxRight() { return par_->idxRight(idx_, pos_); } + + +MathMatrixInset * MathCursor::outerPar() const +{ + return + static_cast(const_cast(formula_->par())); +} diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index f68bb114b6..0d3381edb9 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -24,10 +24,11 @@ #include "math_defs.h" class MathInset; +class MathArrayInset; class MathFuncInset; +class MathMatrixInset; class MathScriptInset; class MathSpaceInset; -class MathArrayInset; class InsetFormulaBase; class MathArray; class MathXArray; @@ -97,7 +98,7 @@ public: /// Put the cursor in the last position void last(); /// - bool plainLeft(); + void plainLeft(); /// void plainRight(); /// @@ -176,7 +177,7 @@ public: /// void pullArg(bool goright); /// - bool isInside(MathInset *) const; + bool isInside(MathInset const *) const; /// MathTextCodes nextCode() const; /// @@ -243,6 +244,8 @@ public: /// MathInset * parInset(int i) const; /// + MathMatrixInset * outerPar() const; + /// void seldump(char const * str) const; /// void dump(char const * str) const; @@ -252,10 +255,6 @@ public: /// void gotoX(int x); - /// - bool nextIsInset() const; - /// - bool prevIsInset() const; /// void merge(MathArray const & arr); /// diff --git a/src/mathed/math_decorationinset.C b/src/mathed/math_decorationinset.C index 9f2d73989d..aec0bb25f2 100644 --- a/src/mathed/math_decorationinset.C +++ b/src/mathed/math_decorationinset.C @@ -25,7 +25,7 @@ MathInset * MathDecorationInset::clone() const -void MathDecorationInset::metrics(MathStyles st) +void MathDecorationInset::metrics(MathStyles st) const { xcell(0).metrics(st); size_ = st; @@ -51,7 +51,7 @@ void MathDecorationInset::metrics(MathStyles st) } } -void MathDecorationInset::draw(Painter & pain, int x, int y) +void MathDecorationInset::draw(Painter & pain, int x, int y) const { xo(x); yo(x); diff --git a/src/mathed/math_decorationinset.h b/src/mathed/math_decorationinset.h index 657f93bf53..98cd9058c7 100644 --- a/src/mathed/math_decorationinset.h +++ b/src/mathed/math_decorationinset.h @@ -21,11 +21,11 @@ public: /// MathInset * clone() const; /// - void draw(Painter &, int, int); + void draw(Painter &, int x, int y) const; /// void write(std::ostream &, bool fragile) const; /// - void metrics(MathStyles st); + void metrics(MathStyles st) const; /// void writeNormal(std::ostream & os) const; private: @@ -33,9 +33,9 @@ private: latexkeys const * key_; /// bool upper_; - /// height of deco - int dh_; - /// vertical offset of deco - int dy_; + /// height cache of deco + mutable int dh_; + /// vertical offset cache of deco + mutable int dy_; }; #endif diff --git a/src/mathed/math_deliminset.C b/src/mathed/math_deliminset.C index 914f1635f9..5e2d30bf35 100644 --- a/src/mathed/math_deliminset.C +++ b/src/mathed/math_deliminset.C @@ -51,7 +51,7 @@ void MathDelimInset::write(std::ostream & os, bool fragile) const } -void MathDelimInset::draw(Painter & pain, int x, int y) +void MathDelimInset::draw(Painter & pain, int x, int y) const { xo(x); yo(y); @@ -86,7 +86,7 @@ int MathDelimInset::dw() const } -void MathDelimInset::metrics(MathStyles st) +void MathDelimInset::metrics(MathStyles st) const { xcell(0).metrics(st); size_ = st; diff --git a/src/mathed/math_deliminset.h b/src/mathed/math_deliminset.h index 30b98208aa..712148bb84 100644 --- a/src/mathed/math_deliminset.h +++ b/src/mathed/math_deliminset.h @@ -18,11 +18,11 @@ public: /// MathInset * clone() const; /// - void draw(Painter &, int, int); + void draw(Painter &, int x, int y) const; /// void write(std::ostream &, bool fragile) const; /// - void metrics(MathStyles st); + void metrics(MathStyles st) const; private: int dw() const; /// diff --git a/src/mathed/math_diminset.h b/src/mathed/math_diminset.h index 931efa9f4b..e9e612450f 100644 --- a/src/mathed/math_diminset.h +++ b/src/mathed/math_diminset.h @@ -4,7 +4,8 @@ #include "math_inset.h" -/// thing that need the dimension cache +/// things that need the dimension cache + class MathDimInset : public MathInset { public: MathDimInset(); @@ -17,10 +18,10 @@ public: protected: /// - int width_; + mutable int width_; /// - int ascent_; + mutable int ascent_; /// - int descent_; + mutable int descent_; }; #endif diff --git a/src/mathed/math_dotsinset.C b/src/mathed/math_dotsinset.C index 35cb293964..1391970bc0 100644 --- a/src/mathed/math_dotsinset.C +++ b/src/mathed/math_dotsinset.C @@ -21,7 +21,7 @@ MathInset * MathDotsInset::clone() const } -void MathDotsInset::draw(Painter & pain, int x, int y) +void MathDotsInset::draw(Painter & pain, int x, int y) const { mathed_draw_deco(pain, x + 2, y - dh_, width_ - 2, ascent_, key_->id); if (key_->id == LM_vdots || key_->id == LM_ddots) @@ -32,7 +32,7 @@ void MathDotsInset::draw(Painter & pain, int x, int y) } -void MathDotsInset::metrics(MathStyles st) +void MathDotsInset::metrics(MathStyles st) const { size(st); mathed_char_dim(LM_TC_VAR, size(), 'M', ascent_, descent_, width_); diff --git a/src/mathed/math_dotsinset.h b/src/mathed/math_dotsinset.h index 2e0c8cb798..c2d87c7f6d 100644 --- a/src/mathed/math_dotsinset.h +++ b/src/mathed/math_dotsinset.h @@ -19,16 +19,16 @@ public: /// MathInset * clone() const; /// - void draw(Painter &, int, int); + void draw(Painter &, int x, int y) const; /// void write(std::ostream &, bool fragile) const; /// void writeNormal(std::ostream &) const; /// - void metrics(MathStyles st); + void metrics(MathStyles st) const; protected: - /// - int dh_; + /// cache for the thing's heigth + mutable int dh_; /// latexkeys const * key_; }; diff --git a/src/mathed/math_fracinset.C b/src/mathed/math_fracinset.C index 911cc3394e..96ad21049c 100644 --- a/src/mathed/math_fracinset.C +++ b/src/mathed/math_fracinset.C @@ -19,7 +19,7 @@ MathInset * MathFracInset::clone() const } -void MathFracInset::metrics(MathStyles st) +void MathFracInset::metrics(MathStyles st) const { size_ = smallerStyleFrac(st); xcell(0).metrics(size_); @@ -30,7 +30,7 @@ void MathFracInset::metrics(MathStyles st) } -void MathFracInset::draw(Painter & pain, int x, int y) +void MathFracInset::draw(Painter & pain, int x, int y) const { xo(x); yo(y); diff --git a/src/mathed/math_fracinset.h b/src/mathed/math_fracinset.h index e90e95abeb..49f350cef2 100644 --- a/src/mathed/math_fracinset.h +++ b/src/mathed/math_fracinset.h @@ -16,31 +16,31 @@ public: /// explicit MathFracInset(const string & name); /// - virtual MathInset * clone() const; + MathInset * clone() const; /// - virtual void write(std::ostream &, bool fragile) const; + void write(std::ostream &, bool fragile) const; /// - virtual void writeNormal(std::ostream &) const; + void writeNormal(std::ostream &) const; /// - virtual void metrics(MathStyles st); + void metrics(MathStyles st) const; /// - virtual void draw(Painter &, int x, int baseline); + void draw(Painter &, int x, int y) const; /// - virtual bool idxUp(int &, int &) const; + bool idxUp(int &, int &) const; /// - virtual bool idxDown(int &, int &) const; + bool idxDown(int &, int &) const; /// - virtual bool idxLeft(int &, int &) const; + bool idxLeft(int &, int &) const; /// - virtual bool idxRight(int &, int &) const; + bool idxRight(int &, int &) const; /// - virtual bool idxFirstUp(int & idx, int & pos) const; + bool idxFirstUp(int & idx, int & pos) const; /// - virtual bool idxFirstDown(int & idx, int & pos) const; + bool idxFirstDown(int & idx, int & pos) const; /// - virtual bool idxLastUp(int & idx, int & pos) const; + bool idxLastUp(int & idx, int & pos) const; /// - virtual bool idxLastDown(int & idx, int & pos) const; + bool idxLastDown(int & idx, int & pos) const; }; #endif diff --git a/src/mathed/math_funcinset.C b/src/mathed/math_funcinset.C index 36f83a1056..9c61edc158 100644 --- a/src/mathed/math_funcinset.C +++ b/src/mathed/math_funcinset.C @@ -38,7 +38,7 @@ void MathFuncInset::writeNormal(std::ostream & os) const } -void MathFuncInset::metrics(MathStyles st) +void MathFuncInset::metrics(MathStyles st) const { size_ = st; if (name_.empty()) @@ -48,7 +48,7 @@ void MathFuncInset::metrics(MathStyles st) } -void MathFuncInset::draw(Painter & pain, int x, int y) +void MathFuncInset::draw(Painter & pain, int x, int y) const { xo(x); yo(y); diff --git a/src/mathed/math_funcinset.h b/src/mathed/math_funcinset.h index 70c0ce61e6..b84acef939 100644 --- a/src/mathed/math_funcinset.h +++ b/src/mathed/math_funcinset.h @@ -19,9 +19,9 @@ public: /// MathInset * clone() const; /// - void MathFuncInset::metrics(MathStyles st); + void metrics(MathStyles st) const; /// - void draw(Painter &, int, int); + void draw(Painter &, int x, int y) const; /// void write(std::ostream &, bool fragile) const; /// diff --git a/src/mathed/math_gridinset.C b/src/mathed/math_gridinset.C index 44bd4816ac..2648283d11 100644 --- a/src/mathed/math_gridinset.C +++ b/src/mathed/math_gridinset.C @@ -74,7 +74,7 @@ char MathGridInset::valign() const return v_align_; } -void MathGridInset::metrics(MathStyles st) +void MathGridInset::metrics(MathStyles st) const { // let the cells adjust themselves MathNestInset::metrics(st); @@ -193,7 +193,7 @@ void MathGridInset::metrics(MathStyles st) */ } -void MathGridInset::draw(Painter & pain, int x, int y) +void MathGridInset::draw(Painter & pain, int x, int y) const { xo(x); yo(y); diff --git a/src/mathed/math_gridinset.h b/src/mathed/math_gridinset.h index 6216e55780..b3a7e9c522 100644 --- a/src/mathed/math_gridinset.h +++ b/src/mathed/math_gridinset.h @@ -20,15 +20,15 @@ class MathGridInset : public MathNestInset { struct RowInfo { /// RowInfo(); - /// - int descent_; - /// - int ascent_; - /// - int offset_; - /// + /// cached descent + mutable int descent_; + /// cached ascent + mutable int ascent_; + /// cached offset + mutable int offset_; + /// hline abow this row? bool upperline_; - /// + /// hline below this row? bool lowerline_; }; @@ -40,11 +40,11 @@ class MathGridInset : public MathNestInset { char h_align_; /// cache for drawing int h_offset; - /// - int width_; - /// - int offset_; - /// + /// cached width + mutable int width_; + /// cached offset + mutable int offset_; + /// bool leftline_; /// bool rightline_; @@ -54,13 +54,11 @@ public: /// MathGridInset(int m, int n, string const & nm); /// - virtual MathInset * clone() const = 0; - /// void write(std::ostream &, bool fragile) const; /// - void metrics(MathStyles st); + void metrics(MathStyles st) const; /// - void draw(Painter &, int, int); + void draw(Painter &, int x, int y) const; /// void halign(string const &); /// diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index c086bb9b50..12774e37ba 100644 --- a/src/mathed/math_inset.C +++ b/src/mathed/math_inset.C @@ -55,7 +55,7 @@ MathStyles MathInset::size() const } -void MathInset::size(MathStyles s) +void MathInset::size(MathStyles s) const { size_ = s; } @@ -80,13 +80,13 @@ int MathInset::yo() const } -void MathInset::xo(int x) +void MathInset::xo(int x) const { xo_ = x; } -void MathInset::yo(int y) +void MathInset::yo(int y) const { yo_ = y; } @@ -307,7 +307,20 @@ void MathInset::code(MathTextCodes t) } -void MathInset::metrics(MathStyles st) +void MathInset::metrics(MathStyles st) const { + lyxerr[Debug::MATHED] << "MathInset::metrics() called directly!\n"; size_ = st; } + + +void MathInset::draw(Painter &, int, int) const +{ + lyxerr << "MathInset::draw() called directly!\n"; +} + + +void MathInset::write(std::ostream &, bool) const +{ + lyxerr << "MathInset::write() called directly!\n"; +} diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index b2c215d19d..c2475b1d14 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -50,9 +50,9 @@ public: virtual ~MathInset() {} /// draw the object, sets xo_ and yo_ cached values - virtual void draw(Painter &, int x, int baseline) = 0; + virtual void draw(Painter &, int x, int y) const; /// write LaTeX and Lyx code - virtual void write(std::ostream &, bool fragile) const = 0; + virtual void write(std::ostream &, bool fragile) const; /// write normalized content virtual void writeNormal(std::ostream &) const; /// reproduce itself @@ -60,17 +60,17 @@ public: /// appends itself with macro arguments substituted virtual void substitute(MathArray & array, MathMacro const & macro) const; /// compute the size of the object, sets ascend_, descend_ and width_ - virtual void metrics(MathStyles st); + virtual void metrics(MathStyles st) const; /// - virtual int ascent() const = 0; + virtual int ascent() const { return 1; } /// - virtual int descent() const = 0; + virtual int descent() const { return 1; } /// - virtual int width() const = 0; + virtual int width() const { return 2; } /// virtual int height() const; /// - string const & name() const; + virtual string const & name() const; /// virtual void setName(string const & n); /// @@ -136,9 +136,9 @@ public: /// virtual int yo() const; /// - virtual void xo(int tx); + virtual void xo(int tx) const; /// - virtual void yo(int ty); + virtual void yo(int ty) const; /// /// @@ -203,19 +203,19 @@ public: protected: /// usually the LaTeX name of the thingy string name_; - /// - void size(MathStyles s); + /// _sets_ style + void size(MathStyles s) const; /// the used font size - MathStyles size_; + mutable MathStyles size_; /// the inherited text style - MathTextCodes code_; + mutable MathTextCodes code_; private: /// the following are used for positioning the cursor with the mouse /// cached cursor start position in pixels from the document left - int xo_; + mutable int xo_; /// cached cursor start position in pixels from the document top - int yo_; + mutable int yo_; }; std::ostream & operator<<(std::ostream &, MathInset const &); diff --git a/src/mathed/math_macro.C b/src/mathed/math_macro.C index 13b439d41a..24d31eeccc 100644 --- a/src/mathed/math_macro.C +++ b/src/mathed/math_macro.C @@ -49,7 +49,7 @@ MathInset * MathMacro::clone() const } -void MathMacro::metrics(MathStyles st) +void MathMacro::metrics(MathStyles st) const { if (mathcursor && mathcursor->isInside(this)) { expanded_ = tmplate_->xcell(0); @@ -67,7 +67,7 @@ void MathMacro::metrics(MathStyles st) mathed_string_dim(LM_TC_TEXTRM, size_, "#1: ", lasc, ldes, lwid); for (int i = 0; i < nargs(); ++i) { - MathXArray & c = xcell(i); + MathXArray const & c = xcell(i); c.metrics(st); width_ = std::max(width_, c.width() + lwid); descent_ += std::max(c.ascent(), lasc) + 5; @@ -85,7 +85,7 @@ void MathMacro::metrics(MathStyles st) } -void MathMacro::draw(Painter & pain, int x, int y) +void MathMacro::draw(Painter & pain, int x, int y) const { xo(x); yo(y); @@ -109,7 +109,7 @@ void MathMacro::draw(Painter & pain, int x, int y) mathed_string_dim(LM_TC_TEXTRM, size_, "#1: ", lasc, ldes, lwid); for (int i = 0; i < nargs(); ++i) { - MathXArray & c = xcell(i); + MathXArray const & c = xcell(i); h += std::max(c.ascent(), lasc) + 5; c.draw(pain, x + lwid, h); char str[] = "#1:"; @@ -190,5 +190,5 @@ void MathMacro::validate(LaTeXFeatures & features) const { if (name_ == "binom") features.binom = true; - MathInset::validate(features); + //MathInset::validate(features); } diff --git a/src/mathed/math_macro.h b/src/mathed/math_macro.h index 6348743e8a..777b4f508c 100644 --- a/src/mathed/math_macro.h +++ b/src/mathed/math_macro.h @@ -41,9 +41,9 @@ public: /// MathMacro(MathMacro const &); /// - void draw(Painter &, int, int); + void draw(Painter &, int x, int y) const; /// - void metrics(MathStyles st); + void metrics(MathStyles st) const; /// MathInset * clone() const; /// @@ -69,7 +69,7 @@ private: /// MathMacroTemplate const * const tmplate_; /// - MathXArray expanded_; + mutable MathXArray expanded_; /// void operator=(MathMacro const &); }; diff --git a/src/mathed/math_macroarg.C b/src/mathed/math_macroarg.C index 22ff523059..8e003ecf0d 100644 --- a/src/mathed/math_macroarg.C +++ b/src/mathed/math_macroarg.C @@ -29,7 +29,7 @@ MathInset * MathMacroArgument::clone() const } -void MathMacroArgument::draw(Painter & pain, int x, int y) +void MathMacroArgument::draw(Painter & pain, int x, int y) const { drawStr(pain, LM_TC_TEX, size(), x, y, str_); } diff --git a/src/mathed/math_macroarg.h b/src/mathed/math_macroarg.h index 10f9248249..9d5f221fe4 100644 --- a/src/mathed/math_macroarg.h +++ b/src/mathed/math_macroarg.h @@ -18,9 +18,9 @@ public: /// MathInset * clone() const; /// - //void metrics(MathStyles st); + //void metrics(MathStyles st) const; /// - void draw(Painter &, int x, int baseline); + void draw(Painter &, int x, int y) const; /// void write(std::ostream &, bool fragile) const; /// diff --git a/src/mathed/math_macrotemplate.C b/src/mathed/math_macrotemplate.C index 9756b25741..60affcd5c4 100644 --- a/src/mathed/math_macrotemplate.C +++ b/src/mathed/math_macrotemplate.C @@ -49,7 +49,7 @@ void MathMacroTemplate::write(std::ostream & os, bool fragile) const } -void MathMacroTemplate::metrics(MathStyles st) +void MathMacroTemplate::metrics(MathStyles st) const { xcell(0).metrics(st); size_ = st; @@ -59,7 +59,7 @@ void MathMacroTemplate::metrics(MathStyles st) } -void MathMacroTemplate::draw(Painter & pain, int x, int y) +void MathMacroTemplate::draw(Painter & pain, int x, int y) const { xo(x); yo(y); diff --git a/src/mathed/math_macrotemplate.h b/src/mathed/math_macrotemplate.h index b7f138b639..e00164d0f9 100644 --- a/src/mathed/math_macrotemplate.h +++ b/src/mathed/math_macrotemplate.h @@ -30,9 +30,9 @@ public: /// void numargs(int); /// - void draw(Painter &, int, int); + void draw(Painter &, int x, int y) const; /// - void metrics(MathStyles st); + void metrics(MathStyles st) const; private: /// int numargs_; diff --git a/src/mathed/math_matrixinset.C b/src/mathed/math_matrixinset.C index be321b53fc..bb830b8e42 100644 --- a/src/mathed/math_matrixinset.C +++ b/src/mathed/math_matrixinset.C @@ -93,7 +93,7 @@ MathInset * MathMatrixInset::clone() const } -void MathMatrixInset::metrics(MathStyles /* st */) +void MathMatrixInset::metrics(MathStyles) const { size_ = (getType() == LM_OT_SIMPLE) ? LM_ST_TEXT : LM_ST_DISPLAY; @@ -116,7 +116,7 @@ void MathMatrixInset::metrics(MathStyles /* st */) } -void MathMatrixInset::draw(Painter & pain, int x, int y) +void MathMatrixInset::draw(Painter & pain, int x, int y) const { xo(x); yo(y); diff --git a/src/mathed/math_matrixinset.h b/src/mathed/math_matrixinset.h index 00349182ea..a48af2f1cb 100644 --- a/src/mathed/math_matrixinset.h +++ b/src/mathed/math_matrixinset.h @@ -27,9 +27,9 @@ public: /// void write(std::ostream &, bool fragile) const; /// - void metrics(MathStyles st); + void metrics(MathStyles st) const; /// - void draw(Painter &, int, int); + void draw(Painter &, int x, int y) const; /// string label(int row) const; /// diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index 86743e483b..7738433acb 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -45,14 +45,13 @@ MathArray const & MathNestInset::cell(int i) const void MathNestInset::substitute(MathArray & array, MathMacro const & m) const { - MathNestInset * p = static_cast(clone()); + array.push_back(clone()); for (int i = 0; i < nargs(); ++i) - p->cell(i).substitute(m); - array.push_back(p); + array.back()->cell(i).substitute(m); } -void MathNestInset::metrics(MathStyles st) +void MathNestInset::metrics(MathStyles st) const { size_ = st; for (int i = 0; i < nargs(); ++i) @@ -60,7 +59,7 @@ void MathNestInset::metrics(MathStyles st) } -void MathNestInset::draw(Painter & pain, int x, int y) +void MathNestInset::draw(Painter & pain, int x, int y) const { xo(x); yo(y); diff --git a/src/mathed/math_nestinset.h b/src/mathed/math_nestinset.h index f2f37a22ae..fc694721aa 100644 --- a/src/mathed/math_nestinset.h +++ b/src/mathed/math_nestinset.h @@ -18,32 +18,32 @@ public: /// explicit MathNestInset(int na = 0, string const & nm = string()); + /// + void metrics(MathStyles st) const; /// draw the object, sets xo_ and yo_ cached values - virtual void draw(Painter &, int x, int baseline); + void draw(Painter &, int x, int y) const; /// appends itself with macro arguments substituted - virtual void substitute(MathArray & array, MathMacro const & macro) const; - /// compute the size of the object, sets ascend_, descend_ and width_ - virtual void metrics(MathStyles st) = 0; + void substitute(MathArray & array, MathMacro const & macro) const; /// The left key - virtual bool idxLeft(int & idx, int & pos) const; + bool idxLeft(int & idx, int & pos) const; /// The right key - virtual bool idxRight(int & idx, int & pos) const; + bool idxRight(int & idx, int & pos) const; /// Move one physical cell up - virtual bool idxNext(int & idx, int & pos) const; + bool idxNext(int & idx, int & pos) const; /// Move one physical cell down - virtual bool idxPrev(int & idx, int & pos) const; + bool idxPrev(int & idx, int & pos) const; /// Target pos when we enter the inset from the left by pressing "Right" - virtual bool idxFirst(int & idx, int & pos) const; + bool idxFirst(int & idx, int & pos) const; /// Target pos when we enter the inset from the right by pressing "Left" - virtual bool idxLast(int & idx, int & pos) const; + bool idxLast(int & idx, int & pos) const; /// Where should we go if we press home? - virtual bool idxHome(int & idx, int & pos) const; + bool idxHome(int & idx, int & pos) const; /// Where should we go if we press end? - virtual bool idxEnd(int & idx, int & pos) const; + bool idxEnd(int & idx, int & pos) const; /// int nargs() const; diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index 50ed6a79c9..2cd0047749 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -29,12 +29,13 @@ #include "array.h" #include "math_inset.h" #include "math_arrayinset.h" -#include "math_symbolinset.h" +#include "math_bigopinset.h" #include "math_dotsinset.h" #include "math_decorationinset.h" #include "math_deliminset.h" #include "math_fracinset.h" #include "math_funcinset.h" +#include "math_funcliminset.h" #include "math_macro.h" #include "math_macrotable.h" #include "math_macrotemplate.h" @@ -44,6 +45,7 @@ #include "math_sizeinset.h" #include "math_spaceinset.h" #include "math_sqrtinset.h" +#include "math_symbolinset.h" #include "debug.h" #include "mathed/support.h" #include "lyxlex.h" @@ -657,8 +659,16 @@ void mathed_parse_into(MathArray & array, unsigned flags) break; case LM_TK_BIGSYM: - case LM_TK_SYM: + limits = 0; + array.push_back(new MathBigopInset(yylval.l)); + break; + case LM_TK_FUNCLIM: + limits = 0; + array.push_back(new MathFuncLimInset(yylval.l)); + break; + + case LM_TK_SYM: limits = 0; array.push_back(new MathSymbolInset(yylval.l)); break; diff --git a/src/mathed/math_rootinset.C b/src/mathed/math_rootinset.C index 1f188a47df..5e2cf7c7ea 100644 --- a/src/mathed/math_rootinset.C +++ b/src/mathed/math_rootinset.C @@ -30,7 +30,7 @@ MathInset * MathRootInset::clone() const } -void MathRootInset::metrics(MathStyles st) +void MathRootInset::metrics(MathStyles st) const { MathNestInset::metrics(st); size_ = st; @@ -40,7 +40,7 @@ void MathRootInset::metrics(MathStyles st) } -void MathRootInset::draw(Painter & pain, int x, int y) +void MathRootInset::draw(Painter & pain, int x, int y) const { xo(x); yo(y); diff --git a/src/mathed/math_rootinset.h b/src/mathed/math_rootinset.h index b832973948..97e56ea625 100644 --- a/src/mathed/math_rootinset.h +++ b/src/mathed/math_rootinset.h @@ -33,13 +33,13 @@ public: /// MathInset * clone() const; /// - void draw(Painter &, int x, int baseline); + void draw(Painter &, int x, int y) const; /// void write(std::ostream &, bool fragile) const; /// void writeNormal(std::ostream &) const; /// - void metrics(MathStyles st); + void metrics(MathStyles st) const; /// bool idxUp(int & idx, int & pos) const; /// diff --git a/src/mathed/math_scriptinset.C b/src/mathed/math_scriptinset.C index 49b0bb89fe..073593a48b 100644 --- a/src/mathed/math_scriptinset.C +++ b/src/mathed/math_scriptinset.C @@ -211,7 +211,7 @@ void MathScriptInset::writeNormal(std::ostream & os) const } -void MathScriptInset::metrics(MathStyles st) +void MathScriptInset::metrics(MathStyles st) const { size_ = st; MathStyles tt = smallerStyleScript(st); @@ -261,7 +261,7 @@ void MathScriptInset::metrics(MathStyles st) } -void MathScriptInset::draw(Painter & pain, int x, int y) +void MathScriptInset::draw(Painter & pain, int x, int y) const { xo(x); yo(y); diff --git a/src/mathed/math_scriptinset.h b/src/mathed/math_scriptinset.h index b7a2f646c0..7a95bf6018 100644 --- a/src/mathed/math_scriptinset.h +++ b/src/mathed/math_scriptinset.h @@ -30,9 +30,9 @@ public: /// void writeNormal(std::ostream &) const; /// - void metrics(MathStyles st); + void metrics(MathStyles st) const; /// - void draw(Painter &, int x, int baseline); + void draw(Painter &, int x, int y) const; /// bool idxUp(int & idx, int & pos) const; @@ -82,20 +82,18 @@ private: bool up_; /// bool down_; - /// - string ssym_; /// 1: \limits, -1: \nolimits, 0: use default int limits_; - /// x offset for drawing the superscript - int dx0_; - /// x offset for drawing the subscript - int dx1_; - /// x offset for drawing the inner symbol - int dxx_; - /// - int dy0_; - /// - int dy1_; + /// x offset cache for drawing the superscript + mutable int dx0_; + /// x offset cache for drawing the subscript + mutable int dx1_; + /// x offset cache for drawing the inner symbol + mutable int dxx_; + /// y offset cache for drawing the superscript + mutable int dy0_; + /// y offset cache for drawing the subscript + mutable int dy1_; /// MathInset * symbol_; }; diff --git a/src/mathed/math_sizeinset.C b/src/mathed/math_sizeinset.C index e498cfdd28..2f9d98b310 100644 --- a/src/mathed/math_sizeinset.C +++ b/src/mathed/math_sizeinset.C @@ -35,7 +35,7 @@ MathInset * MathSizeInset::clone() const } -void MathSizeInset::draw(Painter & pain, int x, int y) +void MathSizeInset::draw(Painter & pain, int x, int y) const { xo(x); yo(y); @@ -43,7 +43,7 @@ void MathSizeInset::draw(Painter & pain, int x, int y) } -void MathSizeInset::metrics(MathStyles /* st */) +void MathSizeInset::metrics(MathStyles /* st */) const { xcell(0).metrics(style_); ascent_ = xcell(0).ascent_; diff --git a/src/mathed/math_sizeinset.h b/src/mathed/math_sizeinset.h index 283e46da9d..fa23904ea5 100644 --- a/src/mathed/math_sizeinset.h +++ b/src/mathed/math_sizeinset.h @@ -18,11 +18,11 @@ public: /// explicit MathSizeInset(MathStyles st); /// - virtual MathInset * clone() const; + MathInset * clone() const; /// - void metrics(MathStyles st); + void metrics(MathStyles st) const; /// - void draw(Painter &, int x, int baseline); + void draw(Painter &, int x, int y) const; /// void write(std::ostream &, bool fragile) const; /// diff --git a/src/mathed/math_spaceinset.C b/src/mathed/math_spaceinset.C index 75620aa8eb..aacab30ca4 100644 --- a/src/mathed/math_spaceinset.C +++ b/src/mathed/math_spaceinset.C @@ -19,7 +19,7 @@ MathInset * MathSpaceInset::clone() const } -void MathSpaceInset::draw(Painter & pain, int x, int y) +void MathSpaceInset::draw(Painter & pain, int x, int y) const { // XPoint p[4] = {{++x, y-3}, {x, y}, {x+width-2, y}, {x+width-2, y-3}}; @@ -51,7 +51,7 @@ void MathSpaceInset::writeNormal(std::ostream & os) const } -void MathSpaceInset::metrics(MathStyles st) +void MathSpaceInset::metrics(MathStyles st) const { size_ = st; width_ = space_ ? space_ * 2 : 2; diff --git a/src/mathed/math_spaceinset.h b/src/mathed/math_spaceinset.h index b6c0f525c1..b8afcb568b 100644 --- a/src/mathed/math_spaceinset.h +++ b/src/mathed/math_spaceinset.h @@ -17,13 +17,13 @@ public: /// MathInset * clone() const; /// - void draw(Painter &, int, int); + void draw(Painter &, int x, int y) const; /// void write(std::ostream &, bool fragile) const; /// void writeNormal(std::ostream &) const; /// - void metrics(MathStyles st); + void metrics(MathStyles st) const; /// bool isSpaceInset() const { return true; } /// diff --git a/src/mathed/math_sqrtinset.C b/src/mathed/math_sqrtinset.C index cd0a585683..956fbb28b9 100644 --- a/src/mathed/math_sqrtinset.C +++ b/src/mathed/math_sqrtinset.C @@ -19,7 +19,7 @@ MathInset * MathSqrtInset::clone() const } -void MathSqrtInset::metrics(MathStyles st) +void MathSqrtInset::metrics(MathStyles st) const { xcell(0).metrics(st); size_ = st; @@ -29,7 +29,7 @@ void MathSqrtInset::metrics(MathStyles st) } -void MathSqrtInset::draw(Painter & pain, int x, int y) +void MathSqrtInset::draw(Painter & pain, int x, int y) const { xo(x); yo(y); diff --git a/src/mathed/math_sqrtinset.h b/src/mathed/math_sqrtinset.h index f3cdf82b2a..cf7c5d89c2 100644 --- a/src/mathed/math_sqrtinset.h +++ b/src/mathed/math_sqrtinset.h @@ -18,12 +18,12 @@ public: /// MathInset * clone() const; /// - void draw(Painter &, int x, int baseline); + void draw(Painter &, int x, int y) const; /// void write(std::ostream &, bool fragile) const; /// void writeNormal(std::ostream &) const; /// - void metrics(MathStyles st); + void metrics(MathStyles st) const; }; #endif diff --git a/src/mathed/math_symbolinset.C b/src/mathed/math_symbolinset.C index 12aebfd950..1afc2938aa 100644 --- a/src/mathed/math_symbolinset.C +++ b/src/mathed/math_symbolinset.C @@ -28,7 +28,7 @@ void MathSymbolInset::writeNormal(ostream & os) const } -void MathSymbolInset::metrics(MathStyles st) +void MathSymbolInset::metrics(MathStyles st) const { size(st); @@ -45,7 +45,7 @@ void MathSymbolInset::metrics(MathStyles st) } -void MathSymbolInset::draw(Painter & pain, int x, int y) +void MathSymbolInset::draw(Painter & pain, int x, int y) const { xo(x); yo(y); diff --git a/src/mathed/math_symbolinset.h b/src/mathed/math_symbolinset.h index 88a3414bac..e327799c54 100644 --- a/src/mathed/math_symbolinset.h +++ b/src/mathed/math_symbolinset.h @@ -6,7 +6,9 @@ struct latexkeys; -/// big operators +// "normal" symbols that don't take limits and don't grow in displayed +// formulae + class MathSymbolInset : public MathDimInset { public: /// @@ -18,18 +20,14 @@ public: /// void writeNormal(std::ostream &) const; /// - void metrics(MathStyles st); - /// - void draw(Painter &, int, int); + void metrics(MathStyles st) const; /// - bool isScriptable() const { return true; } + void draw(Painter &, int x, int y) const; private: /// latexkeys const * sym_; - /// - string ssym_; - /// - MathTextCodes code_; + /// cache for the symbol's onscreen string representation + mutable string ssym_; }; #endif diff --git a/src/mathed/xarray.C b/src/mathed/xarray.C index 4ac1584d5c..58d1b77a8c 100644 --- a/src/mathed/xarray.C +++ b/src/mathed/xarray.C @@ -9,6 +9,7 @@ #include "mathed/support.h" #include "math_defs.h" #include "Painter.h" +#include "debug.h" using std::max; using std::min; @@ -19,7 +20,7 @@ MathXArray::MathXArray() {} -void MathXArray::metrics(MathStyles st) +void MathXArray::metrics(MathStyles st) const { if (data_.empty()) { mathed_char_dim(LM_TC_VAR, st, 'I', ascent_, descent_, width_); @@ -31,12 +32,13 @@ void MathXArray::metrics(MathStyles st) width_ = 0; style_ = st; + //lyxerr << "MathXArray::metrics(): '" << data_ << "'\n"; for (int pos = 0; pos < data_.size(); ++pos) { - MathInset * p = data_.nextInset(pos); + MathInset const * p = data_.nextInset(pos); p->metrics(st); - int asc = p->ascent(); - int des = p->descent(); - int wid = p->width(); + int asc = p->ascent(); + int des = p->descent(); + int wid = p->width(); ascent_ = max(ascent_, asc); descent_ = max(descent_, des); width_ += wid; @@ -44,7 +46,7 @@ void MathXArray::metrics(MathStyles st) } -void MathXArray::draw(Painter & pain, int x, int y) +void MathXArray::draw(Painter & pain, int x, int y) const { xo_ = x; yo_ = y; @@ -55,7 +57,7 @@ void MathXArray::draw(Painter & pain, int x, int y) } for (int pos = 0; pos < data_.size(); ++pos) { - MathInset * p = data_.nextInset(pos); + MathInset const * p = data_.nextInset(pos); p->draw(pain, x, y); x += p->width(); } @@ -81,8 +83,8 @@ int MathXArray::x2pos(int targetx) const lastx = currx; currx += width(pos); } - if (abs(lastx - targetx) < abs(currx - targetx)) - data_.prev(pos); + if (abs(lastx - targetx) < abs(currx - targetx) && pos > 0) + --pos; return pos; } diff --git a/src/mathed/xarray.h b/src/mathed/xarray.h index 6e96aa9c9f..06cbececc4 100644 --- a/src/mathed/xarray.h +++ b/src/mathed/xarray.h @@ -18,9 +18,9 @@ public: /// MathXArray(); /// - void metrics(MathStyles st); + void metrics(MathStyles st) const; /// - void draw(Painter & pain, int x, int y); + void draw(Painter & pain, int x, int y) const; /// int xo() const { return xo_; } @@ -48,17 +48,17 @@ public: /// MathArray data_; /// - int width_; + mutable int width_; /// - int ascent_; + mutable int ascent_; /// - int descent_; + mutable int descent_; /// - int xo_; + mutable int xo_; /// - int yo_; + mutable int yo_; /// - MathStyles style_; + mutable MathStyles style_; }; std::ostream & operator<<(std::ostream & os, MathXArray const & ar); -- 2.39.2