From: André Pönitz Date: Wed, 8 Aug 2001 17:26:30 +0000 (+0000) Subject: new hierarchy for frac-like things X-Git-Tag: 1.6.10~20888 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=cbf29c8fdcce744d30fa050666d5a47e6c19840c;p=features.git new hierarchy for frac-like things 'native' \stackrel support remove MathInset::name_ member (sizeof(MathInset) == 20 on IA32 now); git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2457 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 7457bdc80d..9d777481e7 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,4 +1,13 @@ +2001-08-08 André Pönitz + + * math_fracbase.[Ch]: + * math_fracinset.[Ch]: new hierarchy + + * math_stackrelbase.[Ch]: native \stackrel support + + * math_inset.[Ch]: removal of the name_ member + 2001-08-06 André Pönitz * formulamacro.C: fix nasty bug due to missing copy constructor diff --git a/src/mathed/Makefile.am b/src/mathed/Makefile.am index 8a94d7e560..fada409d2e 100644 --- a/src/mathed/Makefile.am +++ b/src/mathed/Makefile.am @@ -39,6 +39,8 @@ libmathed_la_SOURCES = \ math_dotsinset.h \ math_fracinset.C \ math_fracinset.h \ + math_fracbase.C \ + math_fracbase.h \ math_funcinset.C \ math_funcinset.h \ math_funcliminset.C \ @@ -72,6 +74,8 @@ libmathed_la_SOURCES = \ math_spaceinset.h \ math_sqrtinset.C \ math_sqrtinset.h \ + math_stackrelinset.C \ + math_stackrelinset.h \ math_symbolinset.C \ math_symbolinset.h \ support.C \ diff --git a/src/mathed/array.C b/src/mathed/array.C index db18ed90bb..8881c07cf6 100644 --- a/src/mathed/array.C +++ b/src/mathed/array.C @@ -87,24 +87,6 @@ unsigned char MathArray::getChar(int pos) const } -/* -string MathArray::getString(int & pos) const -{ - string s; - if (isInset(pos)) - return s; - - MathTextCodes const fcode = getCode(pos); - do { - s += getChar(pos); - ++pos; - } while (pos < size() && !isInset(pos) && getCode(pos) == fcode); - - return s; -} -*/ - - MathTextCodes MathArray::getCode(int pos) const { return pos < size() ? (bf_[pos]->code()) : LM_TC_MIN; diff --git a/src/mathed/array.h b/src/mathed/array.h index 46a69578d4..8947ef4d47 100644 --- a/src/mathed/array.h +++ b/src/mathed/array.h @@ -21,7 +21,6 @@ #include "mathed/support.h" #include "math_defs.h" -#include "LString.h" class MathInset; class MathMacro; @@ -104,9 +103,6 @@ public: MathInset const * nextInset(int pos) const; /// unsigned char getChar(int pos) const; - /// read subsequent chars of the same kind. - // pos is afterwards one behind the last char belonging to the string - string getString(int & pos) const; /// MathTextCodes getCode(int pos) const; /// diff --git a/src/mathed/math_arrayinset.C b/src/mathed/math_arrayinset.C index d01dd9caa2..ff92bc9199 100644 --- a/src/mathed/math_arrayinset.C +++ b/src/mathed/math_arrayinset.C @@ -7,7 +7,7 @@ MathArrayInset::MathArrayInset(int m, int n) - : MathGridInset(m, n, "array") + : MathGridInset(m, n) {} diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index 124a770c42..370964b149 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -47,6 +47,7 @@ #include "math_rootinset.h" #include "math_spaceinset.h" #include "math_sqrtinset.h" +#include "math_stackrelinset.h" #include "support/lstrings.h" #include "math_scriptinset.h" #include "math_parser.h" @@ -686,11 +687,11 @@ void MathCursor::interpret(string const & s) break; case LM_TK_STACK: - p = new MathFracInset("stackrel"); + p = new MathStackrelInset; break; case LM_TK_FRAC: - p = new MathFracInset("frac"); + p = new MathFracInset; break; case LM_TK_SQRT: diff --git a/src/mathed/math_fracbase.C b/src/mathed/math_fracbase.C new file mode 100644 index 0000000000..9736d348fd --- /dev/null +++ b/src/mathed/math_fracbase.C @@ -0,0 +1,72 @@ +#ifdef __GNUG__ +#pragma implementation +#endif + +#include "math_fracbase.h" + + +MathFracbaseInset::MathFracbaseInset() + : MathNestInset(2) +{} + + +bool MathFracbaseInset::idxRight(int &, int &) const +{ + return false; +} + + +bool MathFracbaseInset::idxLeft(int &, int &) const +{ + return false; +} + + +bool MathFracbaseInset::idxUp(int & idx, int &) const +{ + if (idx == 0) + return false; + idx = 0; + return true; +} + + +bool MathFracbaseInset::idxDown(int & idx, int &) const +{ + if (idx == 1) + return false; + idx = 1; + return true; +} + + +bool MathFracbaseInset::idxFirstUp(int & idx, int & pos) const +{ + idx = 0; + pos = 0; + return true; +} + + +bool MathFracbaseInset::idxFirstDown(int & idx, int & pos) const +{ + idx = 1; + pos = 0; + return true; +} + + +bool MathFracbaseInset::idxLastUp(int & idx, int & pos) const +{ + idx = 0; + pos = cell(idx).size(); + return true; +} + + +bool MathFracbaseInset::idxLastDown(int & idx, int & pos) const +{ + idx = 1; + pos = cell(idx).size(); + return true; +} diff --git a/src/mathed/math_fracbase.h b/src/mathed/math_fracbase.h new file mode 100644 index 0000000000..05935d93a1 --- /dev/null +++ b/src/mathed/math_fracbase.h @@ -0,0 +1,33 @@ +// -*- C++ -*- +#ifndef MATH_FRACBASE_H +#define MATH_FRACBASE_H + +#include "math_nestinset.h" + +#ifdef __GNUG__ +#pragma interface +#endif + +class MathFracbaseInset : public MathNestInset { +public: + /// + MathFracbaseInset(); + /// + bool idxUp(int &, int &) const; + /// + bool idxDown(int &, int &) const; + /// + bool idxLeft(int &, int &) const; + /// + bool idxRight(int &, int &) const; + /// + bool idxFirstUp(int & idx, int & pos) const; + /// + bool idxFirstDown(int & idx, int & pos) const; + /// + bool idxLastUp(int & idx, int & pos) const; + /// + bool idxLastDown(int & idx, int & pos) const; +}; + +#endif diff --git a/src/mathed/math_fracinset.C b/src/mathed/math_fracinset.C index 96ad21049c..6f6853f31e 100644 --- a/src/mathed/math_fracinset.C +++ b/src/mathed/math_fracinset.C @@ -8,8 +8,7 @@ #include "support/LOstream.h" -MathFracInset::MathFracInset(string const & name) - : MathNestInset(2, name) +MathFracInset::MathFracInset() {} @@ -37,15 +36,13 @@ void MathFracInset::draw(Painter & pain, int x, int y) const int m = x + width() / 2; xcell(0).draw(pain, m - xcell(0).width() / 2, y - xcell(0).descent() - 3 - 5); xcell(1).draw(pain, m - xcell(1).width() / 2, y + xcell(1).ascent() + 3 - 5); - - if (name() == "frac") - pain.line(x + 2, y - 5, x + width() - 4, y - 5, LColor::mathline); + pain.line(x + 2, y - 5, x + width() - 4, y - 5, LColor::mathline); } void MathFracInset::write(std::ostream & os, bool fragile) const { - os << '\\' << name() << '{'; + os << "\\frac{"; cell(0).write(os, fragile); os << "}{"; cell(1).write(os, fragile); @@ -55,66 +52,9 @@ void MathFracInset::write(std::ostream & os, bool fragile) const void MathFracInset::writeNormal(std::ostream & os) const { - os << '[' << name() << ' '; + os << "[frac "; cell(0).writeNormal(os); os << " "; cell(1).writeNormal(os); os << "] "; } - - -bool MathFracInset::idxRight(int &, int &) const -{ - return false; -} - -bool MathFracInset::idxLeft(int &, int &) const -{ - return false; -} - - -bool MathFracInset::idxUp(int & idx, int &) const -{ - if (idx == 0) - return false; - idx = 0; - return true; -} - -bool MathFracInset::idxDown(int & idx, int &) const -{ - if (idx == 1) - return false; - idx = 1; - return true; -} - -bool MathFracInset::idxFirstUp(int & idx, int & pos) const -{ - idx = 0; - pos = 0; - return true; -} - -bool MathFracInset::idxFirstDown(int & idx, int & pos) const -{ - idx = 1; - pos = 0; - return true; -} - -bool MathFracInset::idxLastUp(int & idx, int & pos) const -{ - idx = 0; - pos = cell(idx).size(); - return true; -} - -bool MathFracInset::idxLastDown(int & idx, int & pos) const -{ - idx = 1; - pos = cell(idx).size(); - return true; -} - diff --git a/src/mathed/math_fracinset.h b/src/mathed/math_fracinset.h index 49f350cef2..9e0031c57b 100644 --- a/src/mathed/math_fracinset.h +++ b/src/mathed/math_fracinset.h @@ -2,19 +2,19 @@ #ifndef MATH_FRACINSET_H #define MATH_FRACINSET_H -#include "math_nestinset.h" +#include "math_fracbase.h" #ifdef __GNUG__ #pragma interface #endif -/** Fraction like objects (frac, stackrel, binom) +/** Fraction like objects (frac, binom) \author Alejandro Aguilar Sierra */ -class MathFracInset : public MathNestInset { +class MathFracInset : public MathFracbaseInset { public: /// - explicit MathFracInset(const string & name); + MathFracInset(); /// MathInset * clone() const; /// @@ -25,22 +25,6 @@ public: void metrics(MathStyles st) const; /// void draw(Painter &, int x, int y) const; - /// - bool idxUp(int &, int &) const; - /// - bool idxDown(int &, int &) const; - /// - bool idxLeft(int &, int &) const; - /// - bool idxRight(int &, int &) const; - /// - bool idxFirstUp(int & idx, int & pos) const; - /// - bool idxFirstDown(int & idx, int & pos) const; - /// - bool idxLastUp(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 26f95fc3ef..d34245db74 100644 --- a/src/mathed/math_funcinset.C +++ b/src/mathed/math_funcinset.C @@ -15,9 +15,8 @@ extern LyXFont WhichFont(short type, int size); MathFuncInset::MathFuncInset(string const & nm) -{ - name_ = nm; -} + : name_(nm) +{} MathInset * MathFuncInset::clone() const @@ -26,6 +25,18 @@ MathInset * MathFuncInset::clone() const } +string const & MathFuncInset::name() const +{ + return name_; +} + + +void MathFuncInset::setName(string const & n) +{ + name_ = n; +} + + void MathFuncInset::write(std::ostream & os, bool /* fragile */) const { os << "\\" << name_ << ' '; diff --git a/src/mathed/math_funcinset.h b/src/mathed/math_funcinset.h index b84acef939..ad6a9791ff 100644 --- a/src/mathed/math_funcinset.h +++ b/src/mathed/math_funcinset.h @@ -26,5 +26,12 @@ public: void write(std::ostream &, bool fragile) const; /// void writeNormal(std::ostream &) const; + /// + string const & name() const; + /// + void setName(string const & n); +private: + /// + string name_; }; #endif diff --git a/src/mathed/math_gridinset.C b/src/mathed/math_gridinset.C index 5cb230c18c..33b211b9ff 100644 --- a/src/mathed/math_gridinset.C +++ b/src/mathed/math_gridinset.C @@ -29,8 +29,8 @@ MathGridInset::ColInfo::ColInfo() {} -MathGridInset::MathGridInset(int m, int n, string const & nm) - : MathNestInset(m * n, nm), rowinfo_(n), colinfo_(m), v_align_('c') +MathGridInset::MathGridInset(int m, int n) + : MathNestInset(m * n), rowinfo_(n), colinfo_(m), v_align_('c') { if (m <= 0) lyxerr << "positve number of columns expected\n"; diff --git a/src/mathed/math_gridinset.h b/src/mathed/math_gridinset.h index 1b4e4ca269..885ae2b1df 100644 --- a/src/mathed/math_gridinset.h +++ b/src/mathed/math_gridinset.h @@ -52,7 +52,7 @@ class MathGridInset : public MathNestInset { public: /// - MathGridInset(int m, int n, string const & nm); + MathGridInset(int m, int n); /// void write(std::ostream &, bool fragile) const; /// diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index 31dd692391..b7649d8ef1 100644 --- a/src/mathed/math_inset.C +++ b/src/mathed/math_inset.C @@ -26,8 +26,8 @@ int MathInset::workwidth; -MathInset::MathInset(string const & name) - : name_(name), size_(LM_ST_DISPLAY), code_(LM_TC_MIN), xo_(0), yo_(0) +MathInset::MathInset() + : size_(LM_ST_DISPLAY), code_(LM_TC_MIN), xo_(0), yo_(0) {} @@ -37,18 +37,6 @@ int MathInset::height() const } -string const & MathInset::name() const -{ - return name_; -} - - -void MathInset::setName(string const & n) -{ - name_ = n; -} - - MathStyles MathInset::size() const { return size_; @@ -248,7 +236,7 @@ void MathInset::userSetSize(MathStyles sz) void MathInset::writeNormal(std::ostream & os) const { - os << "[" << name_ << "] "; + os << "[unknown] "; } diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 6ff7f6c338..cdfc968a2d 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -28,7 +28,6 @@ #pragma interface #endif -#include "LString.h" #include "symbol_def.h" #include "xarray.h" @@ -44,7 +43,7 @@ class LaTeXFeatures; class MathInset { public: /// - explicit MathInset(string const & nm = string()); + MathInset(); /// the virtual base destructor virtual ~MathInset() {} @@ -70,10 +69,6 @@ public: /// virtual int height() const; /// - virtual string const & name() const; - /// - virtual void setName(string const & n); - /// virtual MathStyles size() const; /// Where should we go when we press the up cursor key? @@ -205,8 +200,6 @@ public: virtual void code(MathTextCodes t); protected: - /// usually the LaTeX name of the thingy - string name_; /// _sets_ style void size(MathStyles s) const; /// the used font size diff --git a/src/mathed/math_macro.C b/src/mathed/math_macro.C index 24d31eeccc..12738d6d48 100644 --- a/src/mathed/math_macro.C +++ b/src/mathed/math_macro.C @@ -33,7 +33,7 @@ using std::endl; MathMacro::MathMacro(MathMacroTemplate const & t) - : MathNestInset(t.numargs(), t.name()), tmplate_(&t) + : MathNestInset(t.numargs()), tmplate_(&t) {} @@ -48,6 +48,10 @@ MathInset * MathMacro::clone() const return new MathMacro(*this); } +string const & MathMacro::name() const +{ + return tmplate_->name(); +} void MathMacro::metrics(MathStyles st) const { @@ -59,7 +63,7 @@ void MathMacro::metrics(MathStyles st) const ascent_ = expanded_.ascent() + 2; descent_ = expanded_.descent() + 2; - width_ += mathed_string_width(LM_TC_TEXTRM, size_, name_) + 10; + width_ += mathed_string_width(LM_TC_TEXTRM, size_, name()) + 10; int lasc; int ldes; @@ -97,9 +101,9 @@ void MathMacro::draw(Painter & pain, int x, int y) const if (mathcursor && mathcursor->isInside(this)) { int h = y - ascent() + 2 + expanded_.ascent(); - drawStr(pain, LM_TC_TEXTRM, size(), x + 3, h, name_); + drawStr(pain, LM_TC_TEXTRM, size(), x + 3, h, name()); - int const w = mathed_string_width(LM_TC_TEXTRM, size(), name_); + int const w = mathed_string_width(LM_TC_TEXTRM, size(), name()); expanded_.draw(pain, x + w + 12, h); h += expanded_.descent(); @@ -132,7 +136,7 @@ void MathMacro::dump(std::ostream & os) const { MathMacroTable::dump(); os << "\n macro: '" << this << "'\n"; - os << " name: '" << name_ << "'\n"; + os << " name: '" << name() << "'\n"; os << " template: '" << tmplate_ << "'\n"; os << " template: '" << *tmplate_ << "'\n"; os << endl; @@ -140,7 +144,7 @@ void MathMacro::dump(std::ostream & os) const void MathMacro::write(std::ostream & os, bool fragile) const { - os << '\\' << name_; + os << '\\' << name(); for (int i = 0; i < nargs(); ++i) { os << '{'; cell(i).write(os, fragile); @@ -153,7 +157,7 @@ void MathMacro::write(std::ostream & os, bool fragile) const void MathMacro::writeNormal(std::ostream & os) const { - os << "[macro " << name_ << " "; + os << "[macro " << name() << " "; for (int i = 0; i < nargs(); ++i) { cell(i).writeNormal(os); os << ' '; @@ -188,7 +192,7 @@ bool MathMacro::idxRight(int &, int &) const void MathMacro::validate(LaTeXFeatures & features) const { - if (name_ == "binom") + if (name() == "binom") features.binom = true; //MathInset::validate(features); } diff --git a/src/mathed/math_macro.h b/src/mathed/math_macro.h index 777b4f508c..d54f064acb 100644 --- a/src/mathed/math_macro.h +++ b/src/mathed/math_macro.h @@ -66,12 +66,15 @@ public: void validate(LaTeXFeatures &) const; private: + /// + void operator=(MathMacro const &); + /// + string const & name() const; + /// MathMacroTemplate const * const tmplate_; /// mutable MathXArray expanded_; - /// - void operator=(MathMacro const &); }; diff --git a/src/mathed/math_macrotable.C b/src/mathed/math_macrotable.C index 27fb617a51..72a83a633f 100644 --- a/src/mathed/math_macrotable.C +++ b/src/mathed/math_macrotable.C @@ -102,7 +102,7 @@ void MathMacroTable::builtinMacros() // binom has two arguments { - MathFracInset * frac = new MathFracInset("atop"); + MathFracInset * frac = new MathFracInset; frac->cell(0).push_back(new MathMacroArgument(1)); frac->cell(1).push_back(new MathMacroArgument(2)); diff --git a/src/mathed/math_macrotemplate.C b/src/mathed/math_macrotemplate.C index 60affcd5c4..09b6075f21 100644 --- a/src/mathed/math_macrotemplate.C +++ b/src/mathed/math_macrotemplate.C @@ -8,12 +8,12 @@ MathMacroTemplate::MathMacroTemplate() - : MathNestInset(1), numargs_(0) + : MathNestInset(1), numargs_(0), name_() {} MathMacroTemplate::MathMacroTemplate(string const & nm, int numargs) - : MathNestInset(1, nm), numargs_(numargs) + : MathNestInset(1), numargs_(numargs), name_(nm) {} @@ -36,6 +36,12 @@ void MathMacroTemplate::numargs(int numargs) } +string const & MathMacroTemplate::name() const +{ + return name_; +} + + void MathMacroTemplate::write(std::ostream & os, bool fragile) const { os << "\n\\newcommand{\\" << name_ << "}"; diff --git a/src/mathed/math_macrotemplate.h b/src/mathed/math_macrotemplate.h index 7e64b1e2db..a8c028cac5 100644 --- a/src/mathed/math_macrotemplate.h +++ b/src/mathed/math_macrotemplate.h @@ -30,12 +30,16 @@ public: /// void numargs(int); /// + string const & name() const; + /// void draw(Painter &, int x, int y) const; /// void metrics(MathStyles st) const; private: /// int numargs_; + /// + string name_; }; #endif diff --git a/src/mathed/math_matrixinset.C b/src/mathed/math_matrixinset.C index 81a4b06483..4684a59820 100644 --- a/src/mathed/math_matrixinset.C +++ b/src/mathed/math_matrixinset.C @@ -77,14 +77,14 @@ int firstRelOp(MathArray const & array) } MathMatrixInset::MathMatrixInset(MathInsetTypes t) - : MathGridInset(getCols(t), 1, "formula"), objtype_(t), nonum_(1), label_(1) + : MathGridInset(getCols(t), 1), objtype_(t), nonum_(1), label_(1) { halign(getAlign(t, ncols())); } MathMatrixInset::MathMatrixInset() - : MathGridInset(1, 1, "formula"), objtype_(LM_OT_SIMPLE), nonum_(1), label_(1) + : MathGridInset(1, 1), objtype_(LM_OT_SIMPLE), nonum_(1), label_(1) {} MathInset * MathMatrixInset::clone() const diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index 7738433acb..32ab637300 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -6,11 +6,9 @@ #include "debug.h" -MathNestInset::MathNestInset(int nargs, string const & name) +MathNestInset::MathNestInset(int nargs) : MathDimInset(), cells_(nargs) -{ - name_ = name; -} +{} int MathNestInset::nargs() const diff --git a/src/mathed/math_nestinset.h b/src/mathed/math_nestinset.h index fc694721aa..97569f4526 100644 --- a/src/mathed/math_nestinset.h +++ b/src/mathed/math_nestinset.h @@ -16,7 +16,7 @@ class LaTeXFeatures; class MathNestInset : public MathDimInset { public: /// - explicit MathNestInset(int na = 0, string const & nm = string()); + explicit MathNestInset(int ncells); /// void metrics(MathStyles st) const; diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index 0bcf7bed27..df7ee5ceb7 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -45,6 +45,7 @@ #include "math_sizeinset.h" #include "math_spaceinset.h" #include "math_sqrtinset.h" +#include "math_stackrelinset.h" #include "math_symbolinset.h" #include "debug.h" #include "mathed/support.h" @@ -386,14 +387,12 @@ MathInset * lastScriptInset(MathArray & array, bool up, bool down, int limits) static bool curr_num; static string curr_label; -void mathed_parse_lines(MathInset * inset, int col, - bool numbered, bool outmost) +void mathed_parse_lines(MathGridInset * p, int col, bool numbered, bool outmost) { // save global variables bool const saved_num = curr_num; string const saved_label = curr_label; - MathGridInset * p = static_cast(inset); for (int row = 0; true; ++row) { // reset global variables curr_num = numbered; @@ -456,41 +455,41 @@ MathMatrixInset * mathed_parse_normal() MathInsetTypes typ = latex_mathenv[i].typ; p = new MathMatrixInset(typ); - MathMatrixInset * m = static_cast(p); + switch (typ) { case LM_OT_SIMPLE: { curr_num = latex_mathenv[i].numbered; curr_label.erase(); - mathed_parse_into(m->cell(0), 0); - m->numbered(0, curr_num); - m->label(0, curr_label); + mathed_parse_into(p->cell(0), 0); + p->numbered(0, curr_num); + p->label(0, curr_label); break; } case LM_OT_EQUATION: { curr_num = latex_mathenv[i].numbered; curr_label.erase(); - mathed_parse_into(m->cell(0), FLAG_END); - m->numbered(0, curr_num); - m->label(0, curr_label); + mathed_parse_into(p->cell(0), FLAG_END); + p->numbered(0, curr_num); + p->label(0, curr_label); break; } case LM_OT_EQNARRAY: { - mathed_parse_lines(m, 3, latex_mathenv[i].numbered, true); + mathed_parse_lines(p, 3, latex_mathenv[i].numbered, true); break; } case LM_OT_ALIGN: { - m->halign(lexArg('{')); - mathed_parse_lines(m, 2, latex_mathenv[i].numbered, true); + p->halign(lexArg('{')); + mathed_parse_lines(p, 2, latex_mathenv[i].numbered, true); break; } case LM_OT_ALIGNAT: { - m->halign(lexArg('{')); - mathed_parse_lines(m, 2, latex_mathenv[i].numbered, true); + p->halign(lexArg('{')); + mathed_parse_lines(p, 2, latex_mathenv[i].numbered, true); break; } @@ -499,8 +498,6 @@ MathMatrixInset * mathed_parse_normal() << "1: unknown math environment: " << typ << "\n"; } - p->setName(latex_mathenv[i].basename); - break; } @@ -513,15 +510,6 @@ MathMatrixInset * mathed_parse_normal() } -void handle_frac(MathArray & array, string const & name) -{ - MathFracInset * p = new MathFracInset(name); - mathed_parse_into(p->cell(0), FLAG_ITEM); - mathed_parse_into(p->cell(1), FLAG_ITEM); - array.push_back(p); -} - - void mathed_parse_into(MathArray & array, unsigned flags) { static int plevel = -1; @@ -686,17 +674,23 @@ void mathed_parse_into(MathArray & array, unsigned flags) array.push_back(new MathDotsInset(yylval.l)); break; - case LM_TK_CHOOSE: - handle_frac(array, "atop"); - break; - case LM_TK_STACK: - handle_frac(array, "stackrel"); + { + MathStackrelInset * p = new MathStackrelInset; + mathed_parse_into(p->cell(0), FLAG_ITEM); + mathed_parse_into(p->cell(1), FLAG_ITEM); + array.push_back(p); break; + } case LM_TK_FRAC: - handle_frac(array, "frac"); + { + MathFracInset * p = new MathFracInset; + mathed_parse_into(p->cell(0), FLAG_ITEM); + mathed_parse_into(p->cell(1), FLAG_ITEM); + array.push_back(p); break; + } case LM_TK_SQRT: { diff --git a/src/mathed/math_parser.h b/src/mathed/math_parser.h index 9b356fbec4..5cf3638ed4 100644 --- a/src/mathed/math_parser.h +++ b/src/mathed/math_parser.h @@ -47,8 +47,6 @@ enum MathTokenEnum /// LM_TK_FRAC, /// - LM_TK_CHOOSE, - /// LM_TK_SQRT, /// LM_TK_BEGIN, diff --git a/src/mathed/math_sizeinset.C b/src/mathed/math_sizeinset.C index 2f9d98b310..37a19b2aec 100644 --- a/src/mathed/math_sizeinset.C +++ b/src/mathed/math_sizeinset.C @@ -8,12 +8,10 @@ MathSizeInset::MathSizeInset(MathStyles st) : MathNestInset(1), style_(st) -{ - name_ = verbose(); -} +{} -char const * MathSizeInset::verbose() const +char const * MathSizeInset::name() const { switch (style_) { case LM_ST_DISPLAY: diff --git a/src/mathed/math_sizeinset.h b/src/mathed/math_sizeinset.h index fa23904ea5..15f2b1d031 100644 --- a/src/mathed/math_sizeinset.h +++ b/src/mathed/math_sizeinset.h @@ -30,7 +30,7 @@ public: private: /// - char const * verbose() const; + char const * name() const; /// MathStyles style_; }; diff --git a/src/mathed/math_stackrelinset.C b/src/mathed/math_stackrelinset.C new file mode 100644 index 0000000000..081c3b4c6d --- /dev/null +++ b/src/mathed/math_stackrelinset.C @@ -0,0 +1,58 @@ +#ifdef __GNUG__ +#pragma implementation +#endif + +#include "math_stackrelinset.h" +#include "mathed/support.h" +#include "support/LOstream.h" + + +MathStackrelInset::MathStackrelInset() +{} + + +MathInset * MathStackrelInset::clone() const +{ + return new MathStackrelInset(*this); +} + + +void MathStackrelInset::metrics(MathStyles st) const +{ + size_ = smallerStyleFrac(st); + xcell(0).metrics(size_); + xcell(1).metrics(st); + width_ = std::max(xcell(0).width(), xcell(1).width()) + 4; + ascent_ = xcell(1).ascent() + xcell(0).height() + 4; + descent_ = xcell(1).descent(); +} + + +void MathStackrelInset::draw(Painter & pain, int x, int y) const +{ + xo(x); + yo(y); + int m = x + width() / 2; + xcell(0).draw(pain, m - xcell(0).width() / 2, y - xcell(0).height() - 4); + xcell(1).draw(pain, m - xcell(1).width() / 2, y); +} + + +void MathStackrelInset::write(std::ostream & os, bool fragile) const +{ + os << "\\stackrel{"; + cell(0).write(os, fragile); + os << "}{"; + cell(1).write(os, fragile); + os << '}'; +} + + +void MathStackrelInset::writeNormal(std::ostream & os) const +{ + os << "[stackrel "; + cell(0).writeNormal(os); + os << " "; + cell(1).writeNormal(os); + os << "] "; +} diff --git a/src/mathed/math_stackrelinset.h b/src/mathed/math_stackrelinset.h new file mode 100644 index 0000000000..3de330a50f --- /dev/null +++ b/src/mathed/math_stackrelinset.h @@ -0,0 +1,30 @@ +// -*- C++ -*- +#ifndef MATH_STACKRELINSET_H +#define MATH_STACKRELINSET_H + +#include "math_fracbase.h" + +#ifdef __GNUG__ +#pragma interface +#endif + +/** Stackrel objects + \author André Pönitz + */ +class MathStackrelInset : public MathFracbaseInset { +public: + /// + MathStackrelInset(); + /// + MathInset * clone() const; + /// + void write(std::ostream &, bool fragile) const; + /// + void writeNormal(std::ostream &) const; + /// + void metrics(MathStyles st) const; + /// + void draw(Painter &, int x, int y) const; +}; + +#endif