script/mathop seperation. new base class "MathUpDownInset" for both. This one was more difficult than expected... *sigh* Cursor movement is possibly again "unusual" but that should be fixable... Andre' -- André Pönitz ............................................. [EMAIL PROTECTED]
? mathed99.diff Index: Makefile.am =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/Makefile.am,v retrieving revision 1.22 diff -u -p -r1.22 Makefile.am --- Makefile.am 2001/06/25 00:06:30 1.22 +++ Makefile.am 2001/07/11 17:00:56 @@ -66,6 +66,8 @@ libmathed_la_SOURCES = \ math_spaceinset.h \ math_sqrtinset.C \ math_sqrtinset.h \ + math_updowninset.C \ + math_updowninset.h \ math_utils.C \ math_utils.h \ matriz.C \ Index: array.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/array.C,v retrieving revision 1.30 diff -u -p -r1.30 array.C --- array.C 2001/07/06 12:09:30 1.30 +++ array.C 2001/07/11 17:00:56 @@ -243,7 +243,7 @@ MathScriptInset * MathArray::prevScriptI prev(pos); MathInset * inset = GetInset(pos); - if (inset && inset->isScriptInset()) + if (inset && inset->isUpDownInset()) return static_cast<MathScriptInset *>(inset); return 0; @@ -252,7 +252,7 @@ MathScriptInset * MathArray::prevScriptI MathScriptInset * MathArray::nextScriptInset(int pos) const { MathInset * inset = GetInset(pos); - if (inset && inset->isScriptInset()) + if (inset && inset->isUpDownInset()) return static_cast<MathScriptInset *>(inset); return 0; Index: math_accentinset.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_accentinset.C,v retrieving revision 1.12 diff -u -p -r1.12 math_accentinset.C --- math_accentinset.C 2001/07/10 13:17:43 1.12 +++ math_accentinset.C 2001/07/11 17:00:56 @@ -17,7 +17,7 @@ MathInset * MathAccentInset::clone() con return new MathAccentInset(*this); } -void MathAccentInset::Metrics(MathStyles st) +void MathAccentInset::Metrics(MathStyles st, int, int) { xcell(0).Metrics(st); ascent_ = xcell(0).ascent(); Index: math_accentinset.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_accentinset.h,v retrieving revision 1.8 diff -u -p -r1.8 math_accentinset.h --- math_accentinset.h 2001/07/10 13:17:43 1.8 +++ math_accentinset.h 2001/07/11 17:00:56 @@ -20,7 +20,7 @@ public: /// void WriteNormal(std::ostream &) const; /// - void Metrics(MathStyles st); + void Metrics(MathStyles st, int asc = 0, int des = 0); /// int getAccentCode() const; /// Index: math_bigopinset.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_bigopinset.C,v retrieving revision 1.13 diff -u -p -r1.13 math_bigopinset.C --- math_bigopinset.C 2001/07/09 16:59:56 1.13 +++ math_bigopinset.C 2001/07/11 17:00:56 @@ -1,17 +1,15 @@ #include <config.h> -#include <functional> - #include "math_bigopinset.h" -#include "LColor.h" #include "Painter.h" #include "mathed/support.h" #include "support/LOstream.h" + using std::ostream; MathBigopInset::MathBigopInset(string const & name, int id) - : MathScriptInset(false, true), lims_(0), sym_(id) + : MathUpDownInset(false, false), sym_(id), limits_(0) { SetName(name); } @@ -23,132 +21,116 @@ MathInset * MathBigopInset::clone() cons } +int MathBigopInset::limits() const +{ + return limits_; +} + + +void MathBigopInset::limits(int limits) +{ + limits_ = limits; +} + +bool MathBigopInset::hasLimits() const +{ + return limits_ == 1 || (limits_ == 0 && size() == LM_ST_DISPLAY); +} + + void MathBigopInset::Write(ostream & os, bool fragile) const { //bool f = sym_ != LM_int && sym_ != LM_oint && size() == LM_ST_DISPLAY; os << '\\' << name(); - if (limits() == 1) - os << "\\limits "; - else if (limits() == -1) - os << "\\nolimits "; - else - os << ' '; - MathScriptInset::Write(os, fragile); + MathUpDownInset::Write(os, fragile); } void MathBigopInset::WriteNormal(ostream & os) const { - os << "[bigop " << name(); - if (limits() == 1) - os << "\\limits "; - else if (limits() == -1) - os << "\\nolimits "; - else - os << ' '; - MathScriptInset::WriteNormal(os); - os << "] "; + os << "[bigop " << name() << "] "; } -void MathBigopInset::Metrics(MathStyles st) + +void MathBigopInset::Metrics(MathStyles st, int, int) { - MathScriptInset::Metrics(st); + //cerr << "\nBigopDraw\n"; size(st); - string s; - short t; if (sym_ < 256 || sym_ == LM_oint) { - char const c = (sym_ == LM_oint) ? LM_int : sym_; - s += c; - t = LM_TC_BSYM; + ssym_ = string(); + ssym_ += (sym_ == LM_oint) ? LM_int : sym_; + code_ = LM_TC_BSYM; } else { - s = name(); - t = LM_TC_TEXTRM; + ssym_ = name(); + code_ = LM_TC_TEXTRM; } - int asc, des, wid; - mathed_string_dim(t, size(), s, asc, des, wid); + int wid; + mathed_string_dim(code_, size(), ssym_, ascent_, descent_, wid); if (sym_ == LM_oint) wid += 2; + //cerr << " asc: " << ascent_ << " des: " << descent_ + // << " wid: " << wid << "\n"; + //cerr << " hasLimits: " << hasLimits() << " up: " + // << up() << " down: " << down() << "\n"; + + width_ = wid; if (hasLimits()) { - ascent_ = asc + xcell(0).height() + 2; - descent_ = des + xcell(1).height() + 2; - width_ = std::max(width_, wid); + xcell(0).Metrics(st); + xcell(1).Metrics(st); + //cerr << " 0: ascent_: " << xcell(0).ascent() << " descent_: " << + // xcell(0).descent() << " width_: " << xcell(0).width() << "\n"; + //cerr << " 1: ascent_: " << xcell(1).ascent() << " descent_: " << + // xcell(1).descent() << " width_: " << xcell(1).width() << "\n"; + if (up()) { + ascent_ += xcell(0).height() + 1; + width_ = std::max(width_, xcell(0).width()); + dy0_ = - (ascent_ - xcell(0).ascent()); + } + if (down()) { + descent_ += xcell(1).height() + 1; + width_ = std::max(width_, xcell(1).width()); + dy1_ = descent_ - xcell(1).descent(); + } + dxx_ = (width_ - wid) / 2; + dx0_ = (width_ - xcell(0).width()) / 2; + dx1_ = (width_ - xcell(1).width()) / 2; + //cerr << " ascent_: " << ascent_ << " descent_: " + // << descent_ << " width_: " << width_ << "\n"; + //cerr << " dx0_: " << dx0_ << " dx1_: " << dx1_ + // << " dxx_: " << dxx_ << "\n"; + //cerr << " dy0_: " << dy0_ << " dy1_: " << dy1_ + // << "\n"; } else { - ascent_ = std::max(ascent_, asc); - descent_ = std::max(descent_, des); - width_ += wid; + MathUpDownInset::Metrics(st, ascent_, descent_); + width_ += wid; + dx0_ = wid; + dx1_ = wid; + dxx_ = 0; } - } void MathBigopInset::draw(Painter & pain, int x, int y) -{ +{ xo(x); yo(y); - string s; - short t; - - if (sym_ < 256 || sym_ == LM_oint) { - s += (sym_ == LM_oint) ? LM_int : sym_; - t = LM_TC_BSYM; - } else { - s = name(); - t = LM_TC_TEXTRM; - } - if (sym_ == LM_oint) { - int wid; - int asc; - int des; - mathed_char_dim(t, size(), LM_int, asc, des, wid); - wid += 2; - pain.arc(x - 1, y - (asc - des) / 2, wid, wid, 0, 360 * 64, LColor::mathline); - } + pain.text(x + dxx_, y, ssym_, mathed_get_font(code_, size())); - int asc, des, wid; - mathed_string_dim(t, size(), s, asc, des, wid); + if (up()) + xcell(0).draw(pain, x + dx0_, y + dy0_); + if (down()) + xcell(1).draw(pain, x + dx1_, y + dy1_); - if (hasLimits()) { - int w = width(); - pain.text(x + (w - wid)/2, y, s, mathed_get_font(t, size())); - xcell(0).draw - (pain, x + (w - xcell(0).width())/2, y - asc - xcell(0).descent() - 1); - xcell(1).draw - (pain, x + (w - xcell(1).width())/2, y + des + xcell(1).ascent() + 1); - } else { - pain.text(x, y, s, mathed_get_font(t, size())); - MathScriptInset::draw(pain, x + wid, y); + if (sym_ == LM_oint) { + int xx = x - 1; + int yy = y - (ascent_ - descent_) / 2; + pain.arc(xx, yy, width_, width_, 0, 360 * 64, LColor::mathline); } } -int MathBigopInset::limits() const -{ - return lims_; -} - - -void MathBigopInset::limits(int limit) -{ - lims_ = limit; -} - -bool MathBigopInset::hasLimits() const -{ - return limits() == 1 || (limits() == 0 && size() == LM_ST_DISPLAY); -} - - -void MathBigopInset::idxDelete(int & idx, bool & popit, bool & deleteit) -{ - if (idx == 0) - up(false); - else - down(false); - popit = true; - deleteit = true; -} Index: math_bigopinset.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_bigopinset.h,v retrieving revision 1.9 diff -u -p -r1.9 math_bigopinset.h --- math_bigopinset.h 2001/07/09 16:59:56 1.9 +++ math_bigopinset.h 2001/07/11 17:00:56 @@ -2,35 +2,43 @@ #ifndef MATH_BIGOPINSET_H #define MATH_BIGOPINSET_H -#include "math_scriptinset.h" +#include "math_updowninset.h" /// big operators -class MathBigopInset : public MathScriptInset { +class MathBigopInset : public MathUpDownInset { public: /// MathBigopInset(string const &, int); /// MathInset * clone() const; /// - void draw(Painter &, int, int); - /// void Write(std::ostream &, bool fragile) const; /// void WriteNormal(std::ostream &) const; /// - void Metrics(MathStyles st); - /// - int limits() const; + void Metrics(MathStyles st, int asc = 0, int des = 0); /// - bool hasLimits() const; + void draw(Painter &, int, int); /// void limits(int); /// - void idxDelete(int & idx, bool & popit, bool & deleteit); + int limits() const; private: - /// 1: \limits, -1: \nolimits, 0: use default - int lims_; + /// + bool hasLimits() const; /// int sym_; + /// + string ssym_; + /// + short code_; + /// 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_; }; #endif Index: math_cursor.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_cursor.C,v retrieving revision 1.57 diff -u -p -r1.57 math_cursor.C --- math_cursor.C 2001/07/10 13:17:43 1.57 +++ math_cursor.C 2001/07/11 17:00:56 @@ -306,9 +306,9 @@ void MathCursor::SetPos(int x, int y) lyxerr << "found idx: " << idx_ << " cursor: " << cursor_ << "\n"; MathInset * n = nextInset(); MathInset * p = prevInset(); - if (n && (n->isActive() || n->isScriptInset()) && n->covers(x, y)) + if (n && (n->isActive() || n->isUpDownInset()) && n->covers(x, y)) push(n, true); - else if (p && (p->isActive() || p->isScriptInset()) && p->covers(x, y)) { + else if (p && (p->isActive() || p->isUpDownInset()) && p->covers(x, +y)) { array().prev(cursor_); push(p, false); } else @@ -536,7 +536,7 @@ bool MathCursor::toggleLimits() return false; MathInset * p = prevInset(); int old = p->limits(); - p->limits(old == -1 ? 1 : -1); + p->limits(old < 0 ? 1 : -1); return old != p->limits(); } @@ -556,13 +556,12 @@ in_word_set(s) << " \n"; if (s[0] == '^') { MathScriptInset * p = nearbyScriptInset(); if (!p) { - p = new MathScriptInset; + p = new MathScriptInset(true, false); insert(p); array().prev(cursor_); } push(p, true); - if (!p->up()) - p->up(true); + p->up(true); idx_ = 0; return; } @@ -570,13 +569,12 @@ in_word_set(s) << " \n"; if (s[0] == '_') { MathScriptInset * p = nearbyScriptInset(); if (!p) { - p = new MathScriptInset; + p = new MathScriptInset(false, true); insert(p); array().prev(cursor_); } push(p, true); - if (!p->down()) - p->down(true); + p->down(true); idx_ = 1; return; } Index: math_decorationinset.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_decorationinset.C,v retrieving revision 1.13 diff -u -p -r1.13 math_decorationinset.C --- math_decorationinset.C 2001/07/10 17:21:26 1.13 +++ math_decorationinset.C 2001/07/11 17:00:56 @@ -28,7 +28,7 @@ MathInset * MathDecorationInset::clone() -void MathDecorationInset::Metrics(MathStyles st) +void MathDecorationInset::Metrics(MathStyles st, int, int) { xcell(0).Metrics(st); size_ = st; Index: math_decorationinset.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_decorationinset.h,v retrieving revision 1.8 diff -u -p -r1.8 math_decorationinset.h --- math_decorationinset.h 2001/07/06 12:09:31 1.8 +++ math_decorationinset.h 2001/07/11 17:00:56 @@ -22,7 +22,7 @@ public: /// void Write(std::ostream &, bool fragile) const; /// - void Metrics(MathStyles st); + void Metrics(MathStyles st, int asc = 0, int des = 0); private: /// int deco_; Index: math_deliminset.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_deliminset.C,v retrieving revision 1.10 diff -u -p -r1.10 math_deliminset.C --- math_deliminset.C 2001/07/09 10:19:49 1.10 +++ math_deliminset.C 2001/07/11 17:00:56 @@ -89,7 +89,7 @@ int MathDelimInset::dw() const } -void MathDelimInset::Metrics(MathStyles st) +void MathDelimInset::Metrics(MathStyles st, int, int) { xcell(0).Metrics(st); size_ = st; Index: math_deliminset.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_deliminset.h,v retrieving revision 1.5 diff -u -p -r1.5 math_deliminset.h --- math_deliminset.h 2001/06/28 10:25:20 1.5 +++ math_deliminset.h 2001/07/11 17:00:56 @@ -22,7 +22,7 @@ public: /// void Write(std::ostream &, bool fragile) const; /// - void Metrics(MathStyles st); + void Metrics(MathStyles st, int asc = 0, int des = 0); private: int dw() const; /// Index: math_dotsinset.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_dotsinset.C,v retrieving revision 1.10 diff -u -p -r1.10 math_dotsinset.C --- math_dotsinset.C 2001/07/09 10:19:49 1.10 +++ math_dotsinset.C 2001/07/11 17:00:56 @@ -33,7 +33,7 @@ void MathDotsInset::draw(Painter & pain, } -void MathDotsInset::Metrics(MathStyles st) +void MathDotsInset::Metrics(MathStyles st, int, int) { size(st); mathed_char_dim(LM_TC_VAR, size(), 'M', ascent_, descent_, width_); Index: math_dotsinset.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_dotsinset.h,v retrieving revision 1.7 diff -u -p -r1.7 math_dotsinset.h --- math_dotsinset.h 2001/06/28 10:25:20 1.7 +++ math_dotsinset.h 2001/07/11 17:00:56 @@ -23,7 +23,7 @@ public: /// void WriteNormal(std::ostream &) const; /// - void Metrics(MathStyles st); + void Metrics(MathStyles st, int asc = 0, int des = 0); protected: /// int dh_; Index: math_fracinset.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_fracinset.C,v retrieving revision 1.18 diff -u -p -r1.18 math_fracinset.C --- math_fracinset.C 2001/07/09 10:19:49 1.18 +++ math_fracinset.C 2001/07/11 17:00:56 @@ -24,7 +24,7 @@ MathInset * MathFracInset::clone() const } -void MathFracInset::Metrics(MathStyles st) +void MathFracInset::Metrics(MathStyles st, int, int) { size_ = smallerStyleFrac(st); xcell(0).Metrics(size_); Index: math_fracinset.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_fracinset.h,v retrieving revision 1.12 diff -u -p -r1.12 math_fracinset.h --- math_fracinset.h 2001/07/09 10:19:49 1.12 +++ math_fracinset.h 2001/07/11 17:00:56 @@ -22,7 +22,7 @@ public: /// virtual void WriteNormal(std::ostream &) const; /// - virtual void Metrics(MathStyles st); + virtual void Metrics(MathStyles st, int asc = 0, int des = 0); /// virtual void draw(Painter &, int x, int baseline); /// Index: math_funcinset.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_funcinset.C,v retrieving revision 1.11 diff -u -p -r1.11 math_funcinset.C --- math_funcinset.C 2001/07/09 10:19:49 1.11 +++ math_funcinset.C 2001/07/11 17:00:56 @@ -55,7 +55,7 @@ void MathFuncInset::WriteNormal(std::ost } -void MathFuncInset::Metrics(MathStyles st) +void MathFuncInset::Metrics(MathStyles st, int, int) { LyXFont font = WhichFont(LM_TC_TEXTRM, size()); #ifndef NO_LATEX Index: math_funcinset.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_funcinset.h,v retrieving revision 1.9 diff -u -p -r1.9 math_funcinset.h --- math_funcinset.h 2001/07/06 12:09:31 1.9 +++ math_funcinset.h 2001/07/11 17:00:56 @@ -25,7 +25,7 @@ public: /// void WriteNormal(std::ostream &) const; /// - void Metrics(MathStyles st); + void Metrics(MathStyles st, int asc = 0, int des = 0); private: /// bool lims_; Index: math_grid.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_grid.C,v retrieving revision 1.6 diff -u -p -r1.6 math_grid.C --- math_grid.C 2001/07/09 16:59:56 1.6 +++ math_grid.C 2001/07/11 17:00:56 @@ -7,7 +7,6 @@ #include "math_grid.h" #include "support/LOstream.h" #include "debug.h" -#include "Painter.h" namespace { @@ -77,7 +76,7 @@ char MathGridInset::valign() const return v_align_; } -void MathGridInset::Metrics(MathStyles st) +void MathGridInset::Metrics(MathStyles st, int, int) { // let the cells adjust themselves MathInset::Metrics(st); Index: math_grid.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_grid.h,v retrieving revision 1.5 diff -u -p -r1.5 math_grid.h --- math_grid.h 2001/07/09 16:59:56 1.5 +++ math_grid.h 2001/07/11 17:00:56 @@ -58,7 +58,7 @@ public: /// void Write(std::ostream &, bool fragile) const; /// - void Metrics(MathStyles st); + void Metrics(MathStyles st, int asc = 0, int des = 0); /// void draw(Painter &, int, int); /// Index: math_inset.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_inset.C,v retrieving revision 1.32 diff -u -p -r1.32 math_inset.C --- math_inset.C 2001/07/09 16:59:56 1.32 +++ math_inset.C 2001/07/11 17:00:56 @@ -70,12 +70,6 @@ void MathInset::limits(int) { } -bool MathInset::hasLimits() const -{ - return false; -} - - string const & MathInset::name() const { return name_; @@ -186,7 +180,7 @@ void MathInset::substitute(MathArray & a array.push_back(p); } -void MathInset::Metrics(MathStyles st) +void MathInset::Metrics(MathStyles st, int, int) { size_ = st; for (int i = 0; i < nargs(); ++i) @@ -373,4 +367,3 @@ bool MathInset::covers(int x, int y) con y >= yo_ - ascent_ && y <= yo_ + descent_; } - Index: math_inset.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_inset.h,v retrieving revision 1.34 diff -u -p -r1.34 math_inset.h --- math_inset.h 2001/07/09 16:59:57 1.34 +++ math_inset.h 2001/07/11 17:00:56 @@ -60,7 +60,7 @@ public: /// Appends itself with macro arguments substituted virtual void substitute(MathArray & array, MathMacro const & macro) const; /// Compute the size of the object - virtual void Metrics(MathStyles st) = 0; + virtual void Metrics(MathStyles st, int = 0, int = 0) = 0; /// virtual int ascent() const; /// @@ -70,8 +70,6 @@ public: /// virtual int height() const; /// - virtual bool hasLimits() const; - /// virtual int limits() const; /// virtual void limits(int); @@ -174,7 +172,7 @@ public: /// bool covers(int x, int y) const; /// Identifies ScriptInsets - virtual bool isScriptInset() const { return false; } + virtual bool isUpDownInset() const { return false; } /// Identifies AccentInsets virtual bool isAccentInset() const { return false; } /// Index: math_macro.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_macro.C,v retrieving revision 1.61 diff -u -p -r1.61 math_macro.C --- math_macro.C 2001/07/09 10:19:50 1.61 +++ math_macro.C 2001/07/11 17:00:56 @@ -44,7 +44,7 @@ MathInset * MathMacro::clone() const } -void MathMacro::Metrics(MathStyles st) +void MathMacro::Metrics(MathStyles st, int, int) { if (mathcursor && mathcursor->isInside(this)) { expanded_ = tmplate_->xcell(0); Index: math_macro.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_macro.h,v retrieving revision 1.43 diff -u -p -r1.43 math_macro.h --- math_macro.h 2001/06/28 10:25:20 1.43 +++ math_macro.h 2001/07/11 17:00:56 @@ -41,7 +41,7 @@ public: /// void draw(Painter &, int, int); /// - void Metrics(MathStyles st); + void Metrics(MathStyles st, int asc = 0, int des = 0); /// MathInset * clone() const; /// Index: math_macroarg.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_macroarg.C,v retrieving revision 1.13 diff -u -p -r1.13 math_macroarg.C --- math_macroarg.C 2001/07/04 17:20:46 1.13 +++ math_macroarg.C 2001/07/11 17:00:56 @@ -38,7 +38,7 @@ void MathMacroArgument::draw(Painter & p } -void MathMacroArgument::Metrics(MathStyles st) +void MathMacroArgument::Metrics(MathStyles st, int, int) { char str[] = "#0"; str[1] += number_; Index: math_macroarg.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_macroarg.h,v retrieving revision 1.10 diff -u -p -r1.10 math_macroarg.h --- math_macroarg.h 2001/06/28 10:25:20 1.10 +++ math_macroarg.h 2001/07/11 17:00:56 @@ -18,7 +18,7 @@ public: /// MathInset * clone() const; /// - void Metrics(MathStyles st); + void Metrics(MathStyles st, int asc = 0, int des = 0); /// void draw(Painter &, int x, int baseline); /// Index: math_macrotable.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_macrotable.C,v retrieving revision 1.19 diff -u -p -r1.19 math_macrotable.C --- math_macrotable.C 2001/07/10 13:17:43 1.19 +++ math_macrotable.C 2001/07/11 17:00:56 @@ -114,7 +114,7 @@ void MathMacroTable::builtinMacros() { MathMacroTemplate * t = new MathMacroTemplate("emptyset", 0); MathAccentInset * p = new MathAccentInset(LM_not); - p->cell(0).push_back('0', LM_TC_VAR); + p->cell(0).push_back('O', LM_TC_VAR); t->push_back(p); insertTemplate(t); } Index: math_macrotemplate.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_macrotemplate.C,v retrieving revision 1.22 diff -u -p -r1.22 math_macrotemplate.C --- math_macrotemplate.C 2001/07/09 10:19:50 1.22 +++ math_macrotemplate.C 2001/07/11 17:00:56 @@ -51,7 +51,7 @@ void MathMacroTemplate::Write(std::ostre } -void MathMacroTemplate::Metrics(MathStyles st) +void MathMacroTemplate::Metrics(MathStyles st, int, int) { xcell(0).Metrics(st); size_ = st; Index: math_macrotemplate.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_macrotemplate.h,v retrieving revision 1.16 diff -u -p -r1.16 math_macrotemplate.h --- math_macrotemplate.h 2001/06/28 10:25:20 1.16 +++ math_macrotemplate.h 2001/07/11 17:00:56 @@ -34,7 +34,7 @@ public: /// void draw(Painter &, int, int); /// - void Metrics(MathStyles st); + void Metrics(MathStyles st, int asc = 0, int des = 0); private: /// int numargs_; Index: math_matrixinset.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_matrixinset.C,v retrieving revision 1.26 diff -u -p -r1.26 math_matrixinset.C --- math_matrixinset.C 2001/07/10 10:40:23 1.26 +++ math_matrixinset.C 2001/07/11 17:00:56 @@ -97,7 +97,7 @@ MathInset * MathMatrixInset::clone() con } -void MathMatrixInset::Metrics(MathStyles /* st */) +void MathMatrixInset::Metrics(MathStyles /* st */, int, int) { size_ = (GetType() == LM_OT_SIMPLE) ? LM_ST_TEXT : LM_ST_DISPLAY; Index: math_matrixinset.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_matrixinset.h,v retrieving revision 1.14 diff -u -p -r1.14 math_matrixinset.h --- math_matrixinset.h 2001/07/06 12:09:31 1.14 +++ math_matrixinset.h 2001/07/11 17:00:56 @@ -29,7 +29,7 @@ public: /// void Write(std::ostream &, bool fragile) const; /// - void Metrics(MathStyles st); + void Metrics(MathStyles st, int asc = 0, int des = 0); /// void draw(Painter &, int, int); /// Index: math_parser.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_parser.C,v retrieving revision 1.62 diff -u -p -r1.62 math_parser.C --- math_parser.C 2001/07/10 13:17:43 1.62 +++ math_parser.C 2001/07/11 17:00:56 @@ -38,6 +38,7 @@ #include "math_funcinset.h" #include "math_spaceinset.h" #include "math_sizeinset.h" +#include "math_scriptinset.h" #include "math_dotsinset.h" #include "math_fracinset.h" #include "math_deliminset.h" @@ -342,11 +343,11 @@ void handle_frac(MathArray & dat, string } -MathScriptInset * lastScriptInset(MathArray & array) +MathScriptInset * lastUpDownInset(MathArray & array, bool up, bool down) { MathInset * p = array.back_inset(); - if (!p || !p->isScriptInset()) { - p = new MathScriptInset; + if (!p || !p->isUpDownInset()) { + p = new MathScriptInset(up, down); array.push_back(p); } return static_cast<MathScriptInset *>(p); @@ -580,7 +581,7 @@ void mathed_parse(MathArray & array, uns { MathArray ar; mathed_parse(ar, FLAG_BRACE_OPT | FLAG_BRACE_LAST); - MathScriptInset * p = lastScriptInset(array); + MathScriptInset * p = lastUpDownInset(array, true, false); p->setData(ar, 0); p->up(true); break; @@ -590,7 +591,7 @@ void mathed_parse(MathArray & array, uns { MathArray ar; mathed_parse(ar, FLAG_BRACE_OPT | FLAG_BRACE_LAST); - MathScriptInset * p = lastScriptInset(array); + MathScriptInset * p = lastUpDownInset(array, false, true); p->setData(ar, 1); p->down(true); break; @@ -598,7 +599,7 @@ void mathed_parse(MathArray & array, uns case LM_TK_LIMIT: { - MathScriptInset * p = lastScriptInset(array); + MathScriptInset * p = lastUpDownInset(array, false, false); if (p) p->limits(yylval.l->id ? 1 : -1); break; Index: math_root.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_root.C,v retrieving revision 1.31 diff -u -p -r1.31 math_root.C --- math_root.C 2001/07/09 10:19:50 1.31 +++ math_root.C 2001/07/11 17:00:56 @@ -34,7 +34,7 @@ MathInset * MathRootInset::clone() const } -void MathRootInset::Metrics(MathStyles st) +void MathRootInset::Metrics(MathStyles st, int, int) { MathInset::Metrics(st); size_ = st; Index: math_root.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_root.h,v retrieving revision 1.30 diff -u -p -r1.30 math_root.h --- math_root.h 2001/06/28 10:25:20 1.30 +++ math_root.h 2001/07/11 17:00:56 @@ -39,7 +39,7 @@ public: /// void WriteNormal(std::ostream &) const; /// - void Metrics(MathStyles st); + void Metrics(MathStyles st, int asc = 0, int des = 0); /// bool idxUp(int & idx, int & pos) const; /// Index: math_scriptinset.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_scriptinset.C,v retrieving revision 1.7 diff -u -p -r1.7 math_scriptinset.C --- math_scriptinset.C 2001/07/09 16:59:57 1.7 +++ math_scriptinset.C 2001/07/11 17:00:56 @@ -4,22 +4,16 @@ #pragma implementation #endif -#include <functional> - #include "math_scriptinset.h" -#include "LColor.h" -#include "Painter.h" -#include "debug.h" -#include "mathed/support.h" #include "support/LOstream.h" -MathScriptInset::MathScriptInset() - : MathInset(2), up_(false), down_(false) -{} +//MathScriptInset::MathScriptInset() +// : MathUpDownInset(false, false) +//{} MathScriptInset::MathScriptInset(bool up, bool down) - : MathInset(2), up_(up), down_(down) + : MathUpDownInset(up, down) {} @@ -29,67 +23,6 @@ MathInset * MathScriptInset::clone() con } -void MathScriptInset::Metrics(MathStyles st) -{ - size_ = smallerStyleScript(st); - xcell(0).Metrics(size_); - xcell(1).Metrics(size_); - - width_ = std::max(xcell(0).width(), xcell(1).width()) + 2; - if (up()) - ascent_ = std::max(ascent_, xcell(0).height() + 9); - if (down()) - descent_ = std::max(descent_, xcell(1).height()); -} - - -bool MathScriptInset::up() const -{ - return up_; -} - -bool MathScriptInset::down() const -{ - return down_; -} - -void MathScriptInset::up(bool b) -{ - up_ = b; -} - -void MathScriptInset::down(bool b) -{ - down_ = b; -} - - -void MathScriptInset::draw(Painter & pain, int x, int y) -{ - xo(x); - yo(y); - if (up()) - xcell(0).draw(pain, x, y - xcell(0).descent() - 9); - if (down()) - xcell(1).draw(pain, x, y + xcell(1).ascent()); -} - - -void MathScriptInset::Write(std::ostream & os, bool fragile) const -{ - if (up()) { - os << "^{"; - cell(0).Write(os, fragile); - os << "}"; - } - if (down()) { - os << "_{"; - cell(1).Write(os, fragile); - os << "}"; - } -} - - void MathScriptInset::WriteNormal(std::ostream & os) const { if (up()) { @@ -102,86 +35,6 @@ void MathScriptInset::WriteNormal(std::o cell(1).WriteNormal(os); os << "] "; } -} - -bool MathScriptInset::idxRight(int &, int &) const -{ - return false; -} - -bool MathScriptInset::idxLeft(int &, int &) const -{ - return false; -} - - -bool MathScriptInset::idxUp(int & idx, int & pos) const -{ - if (idx == 0 || !up()) - return false; - idx = 0; - pos = 0; - return true; -} - -bool MathScriptInset::idxDown(int & idx, int & pos) const -{ - if (idx == 1 || !down()) - return false; - idx = 1; - pos = 0; - return true; -} - -bool MathScriptInset::idxFirst(int & idx, int & pos) const -{ - idx = up() ? 0 : 1; - pos = 0; - return true; -} - -bool MathScriptInset::idxLast(int & idx, int & pos) const -{ - idx = down() ? 1 : 0; - pos = cell(idx).size(); - return true; -} - - -bool MathScriptInset::idxFirstUp(int & idx, int & pos) const -{ - if (!up()) - return false; - idx = 0; - pos = 0; - return true; -} - -bool MathScriptInset::idxFirstDown(int & idx, int & pos) const -{ - if (!down()) - return false; - idx = 1; - pos = 0; - return true; -} - -bool MathScriptInset::idxLastUp(int & idx, int & pos) const -{ - if (!up()) - return false; - idx = 0; - pos = cell(idx).size(); - return true; -} - -bool MathScriptInset::idxLastDown(int & idx, int & pos) const -{ - if (!down()) - return false; - idx = 1; - pos = cell(idx).size(); - return true; } Index: math_scriptinset.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_scriptinset.h,v retrieving revision 1.4 diff -u -p -r1.4 math_scriptinset.h --- math_scriptinset.h 2001/07/09 16:59:57 1.4 +++ math_scriptinset.h 2001/07/11 17:00:56 @@ -2,7 +2,7 @@ #ifndef MATH_SCRIPTINSET_H #define MATH_SCRIPTINSET_H -#include "math_inset.h" +#include "math_updowninset.h" #ifdef __GNUG__ #pragma interface @@ -12,61 +12,20 @@ \author André Pönitz */ -class MathScriptInset : public MathInset { +class MathScriptInset : public MathUpDownInset { public: /// - MathScriptInset(); + //MathScriptInset(); /// MathScriptInset(bool up, bool down); /// MathInset * clone() const; /// - void Write(std::ostream &, bool fragile) const; - /// void WriteNormal(std::ostream &) const; - /// - void Metrics(MathStyles st); - /// - void draw(Painter &, int x, int baseline); - /// - bool idxUp(int & idx, int & pos) const; - /// - bool idxDown(int & idx, int & pos) const; - /// - bool idxLeft(int & idx, int & pos) const; - /// - bool idxRight(int & idx, int & pos) const; - /// - bool idxFirst(int & idx, int & pos) const; - /// - bool idxFirstUp(int & idx, int & pos) const; - /// - bool idxFirstDown(int & idx, int & pos) const; - /// - bool idxLast(int & idx, int & pos) const; - /// - bool idxLastUp(int & idx, int & pos) const; - /// - bool idxLastDown(int & idx, int & pos) const; - /// - bool up() const; - /// - bool down() const; - /// - void up(bool); - /// - void down(bool); - /// - bool isActive() const { return false; } /// Identifies ScriptInsets - bool isScriptInset() const { return true; } + bool isUpDownInset() const { return true; } /// void idxDelete(int & idx, bool & popit, bool & deleteit); -private: - /// - bool up_; - /// - bool down_; }; #endif Index: math_sizeinset.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_sizeinset.C,v retrieving revision 1.4 diff -u -p -r1.4 math_sizeinset.C --- math_sizeinset.C 2001/07/09 10:19:50 1.4 +++ math_sizeinset.C 2001/07/11 17:00:56 @@ -45,7 +45,7 @@ void MathSizeInset::draw(Painter & pain, } -void MathSizeInset::Metrics(MathStyles /* st */) +void MathSizeInset::Metrics(MathStyles /* st */, int, int) { xcell(0).Metrics(style_); ascent_ = xcell(0).ascent_; Index: math_sizeinset.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_sizeinset.h,v retrieving revision 1.2 diff -u -p -r1.2 math_sizeinset.h --- math_sizeinset.h 2001/06/28 10:25:20 1.2 +++ math_sizeinset.h 2001/07/11 17:00:56 @@ -20,7 +20,7 @@ public: /// virtual MathInset * clone() const; /// - void Metrics(MathStyles st); + void Metrics(MathStyles st, int asc = 0, int des = 0); /// void draw(Painter &, int x, int baseline); /// Index: math_spaceinset.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_spaceinset.C,v retrieving revision 1.11 diff -u -p -r1.11 math_spaceinset.C --- math_spaceinset.C 2001/07/09 10:19:50 1.11 +++ math_spaceinset.C 2001/07/11 17:00:56 @@ -55,7 +55,7 @@ void MathSpaceInset::WriteNormal(std::os } -void MathSpaceInset::Metrics(MathStyles st) +void MathSpaceInset::Metrics(MathStyles st, int, int) { size_ = st; width_ = space_ ? space_ * 2 : 2; Index: math_spaceinset.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_spaceinset.h,v retrieving revision 1.9 diff -u -p -r1.9 math_spaceinset.h --- math_spaceinset.h 2001/07/09 10:19:50 1.9 +++ math_spaceinset.h 2001/07/11 17:00:56 @@ -23,7 +23,7 @@ public: /// void WriteNormal(std::ostream &) const; /// - void Metrics(MathStyles st); + void Metrics(MathStyles st, int asc = 0, int des = 0); /// void SetSpace(int sp); /// Index: math_sqrtinset.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_sqrtinset.C,v retrieving revision 1.13 diff -u -p -r1.13 math_sqrtinset.C --- math_sqrtinset.C 2001/07/09 10:19:50 1.13 +++ math_sqrtinset.C 2001/07/11 17:00:56 @@ -22,7 +22,7 @@ MathInset * MathSqrtInset::clone() const } -void MathSqrtInset::Metrics(MathStyles st) +void MathSqrtInset::Metrics(MathStyles st, int, int) { xcell(0).Metrics(st); size_ = st; Index: math_sqrtinset.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_sqrtinset.h,v retrieving revision 1.6 diff -u -p -r1.6 math_sqrtinset.h --- math_sqrtinset.h 2001/06/28 10:25:20 1.6 +++ math_sqrtinset.h 2001/07/11 17:00:56 @@ -24,6 +24,6 @@ public: /// void WriteNormal(std::ostream &) const; /// - void Metrics(MathStyles st); + void Metrics(MathStyles st, int asc = 0, int des = 0); }; #endif Index: math_updowninset.C =================================================================== RCS file: math_updowninset.C diff -N math_updowninset.C --- /dev/null Tue May 5 22:32:27 1998 +++ math_updowninset.C Wed Jul 11 19:00:56 2001 @@ -0,0 +1,178 @@ +#include <config.h> + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include "math_updowninset.h" +#include "support/LOstream.h" + + +MathUpDownInset::MathUpDownInset() + : MathInset(2), up_(false), down_(false) +{} + +MathUpDownInset::MathUpDownInset(bool up, bool down) + : MathInset(2), up_(up), down_(down) +{} + + +MathInset * MathUpDownInset::clone() const +{ + return new MathUpDownInset(*this); +} + + +bool MathUpDownInset::up() const +{ + return up_; +} + +bool MathUpDownInset::down() const +{ + return down_; +} + +void MathUpDownInset::up(bool b) +{ + up_ = b; +} + +void MathUpDownInset::down(bool b) +{ + down_ = b; +} + + +bool MathUpDownInset::idxRight(int &, int &) const +{ + return false; +} + +bool MathUpDownInset::idxLeft(int &, int &) const +{ + return false; +} + + +bool MathUpDownInset::idxUp(int & idx, int & pos) const +{ + if (idx == 0 || !up()) + return false; + idx = 0; + pos = 0; + return true; +} + +bool MathUpDownInset::idxDown(int & idx, int & pos) const +{ + if (idx == 1 || !down()) + return false; + idx = 1; + pos = 0; + return true; +} + +bool MathUpDownInset::idxFirst(int & idx, int & pos) const +{ + idx = up() ? 0 : 1; + pos = 0; + return true; +} + +bool MathUpDownInset::idxLast(int & idx, int & pos) const +{ + idx = down() ? 1 : 0; + pos = cell(idx).size(); + return true; +} + + +bool MathUpDownInset::idxFirstUp(int & idx, int & pos) const +{ + if (!up()) + return false; + idx = 0; + pos = 0; + return true; +} + +bool MathUpDownInset::idxFirstDown(int & idx, int & pos) const +{ + if (!down()) + return false; + idx = 1; + pos = 0; + return true; +} + +bool MathUpDownInset::idxLastUp(int & idx, int & pos) const +{ + if (!up()) + return false; + idx = 0; + pos = cell(idx).size(); + return true; +} + +bool MathUpDownInset::idxLastDown(int & idx, int & pos) const +{ + if (!down()) + return false; + idx = 1; + pos = cell(idx).size(); + return true; +} + + +void MathUpDownInset::idxDelete(int & idx, bool & popit, bool & deleteit) +{ + if (idx == 0) + up(false); + else + down(false); + popit = true; + deleteit = !(up() || down()); +} + +void MathUpDownInset::Write(std::ostream & os, bool fragile) const +{ + if (up()) { + os << "^{"; + cell(0).Write(os, fragile); + os << "}"; + } + if (down()) { + os << "_{"; + cell(1).Write(os, fragile); + os << "}"; + } +} + +void MathUpDownInset::Metrics(MathStyles st, int asc, int des) +{ + if (up()) + xcell(0).Metrics(st); + if (down()) + xcell(1).Metrics(st); + + // we assume that asc, des, wid are the metrics of the item in front + // of this MathScriptInset + width_ = std::max(xcell(0).width(), xcell(1).width()); + ascent_ = up() ? xcell(0).height() + 9 : 0; + descent_ = down() ? xcell(1).height() : 0; + dy0_ = - asc - xcell(0).descent(); + dy1_ = des + xcell(1).ascent(); +} + + +void MathUpDownInset::draw(Painter & pain, int x, int y) +{ + xo(x); + yo(y); + if (up()) + xcell(0).draw(pain, x, y + dy0_); + if (down()) + xcell(1).draw(pain, x, y + dy1_); +} + Index: math_updowninset.h =================================================================== RCS file: math_updowninset.h diff -N math_updowninset.h --- /dev/null Tue May 5 22:32:27 1998 +++ math_updowninset.h Wed Jul 11 19:00:56 2001 @@ -0,0 +1,75 @@ +// -*- C++ -*- +#ifndef MATH_UPDOWNINSET_H +#define MATH_UPDOWNINSET_H + +#include "math_inset.h" + +#ifdef __GNUG__ +#pragma interface +#endif + +/** Abstract base class for super- and subscripts and mathop inset + \author André Pönitz + */ + +class MathUpDownInset : public MathInset { +public: + /// + MathUpDownInset(); + /// + MathUpDownInset(bool up, bool down); + /// + MathInset * clone() const; + /// + void Write(std::ostream &, bool fragile) const; + /// + void Metrics(MathStyles st, int asc = 0, int des = 0); + /// + void draw(Painter &, int x, int baseline); + /// + bool idxUp(int & idx, int & pos) const; + /// + bool idxDown(int & idx, int & pos) const; + /// + bool idxLeft(int & idx, int & pos) const; + /// + bool idxRight(int & idx, int & pos) const; + /// + bool idxFirst(int & idx, int & pos) const; + /// + bool idxFirstUp(int & idx, int & pos) const; + /// + bool idxFirstDown(int & idx, int & pos) const; + /// + bool idxLast(int & idx, int & pos) const; + /// + bool idxLastUp(int & idx, int & pos) const; + /// + bool idxLastDown(int & idx, int & pos) const; + /// + bool up() const; + /// + bool down() const; + /// + void up(bool); + /// + void down(bool); + /// + bool isActive() const { return false; } + /// Identifies ScriptInsets + bool isUpDownInset() const { return true; } + /// + void idxDelete(int & idx, bool & popit, bool & deleteit); +private: + /// + bool up_; + /// + bool down_; +protected: + /// + int dy0_; + /// + int dy1_; +}; + +#endif Index: xarray.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/xarray.C,v retrieving revision 1.4 diff -u -p -r1.4 xarray.C --- xarray.C 2001/07/06 12:09:32 1.4 +++ xarray.C 2001/07/11 17:00:56 @@ -14,12 +14,13 @@ using std::max; using std::min; + MathXArray::MathXArray() : width_(0), ascent_(0), descent_(0), xo_(0), yo_(0), style_(LM_ST_TEXT) {} -void MathXArray::Metrics(MathStyles st) +void MathXArray::Metrics(MathStyles st, int, int) { if (data_.empty()) { mathed_char_dim(LM_TC_VAR, st, 'I', ascent_, descent_, width_); @@ -31,24 +32,28 @@ void MathXArray::Metrics(MathStyles st) width_ = 0; style_ = st; + // keep last values for scriptInset's need to look back + int asc = 0; + int des = 0; + int wid = 0; + mathed_char_height(LM_TC_VAR, st, 'I', asc, des); + for (int pos = 0; pos < data_.size(); data_.next(pos)) { MathInset * p = data_.GetInset(pos); if (p) { - p->Metrics(st); - ascent_ = max(ascent_, p->ascent()); - descent_ = max(descent_, p->descent()); - width_ += p->width(); + // only MathUpDownInsets will use the asc/des information... + p->Metrics(st, asc, des); + asc = p->ascent(); + des = p->descent(); + wid = p->width(); } else { char cx = data_.GetChar(pos); MathTextCodes fc = data_.GetCode(pos); - int asc; - int des; - int wid; mathed_char_dim(fc, style_, cx, asc, des, wid); - ascent_ = max(ascent_, asc); - descent_ = max(descent_, des); - width_ += wid; } + ascent_ = max(ascent_, asc); + descent_ = max(descent_, des); + width_ += wid; } } Index: xarray.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/xarray.h,v retrieving revision 1.2 diff -u -p -r1.2 xarray.h --- xarray.h 2001/07/04 17:17:32 1.2 +++ xarray.h 2001/07/11 17:00:56 @@ -18,7 +18,7 @@ public: /// MathXArray(); /// - void Metrics(MathStyles st); + void Metrics(MathStyles st, int asc = 0, int des = 0); /// void draw(Painter & pain, int x, int y);