]> git.lyx.org Git - features.git/commitdiff
new hierarchy for frac-like things
authorAndré Pönitz <poenitz@gmx.net>
Wed, 8 Aug 2001 17:26:30 +0000 (17:26 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Wed, 8 Aug 2001 17:26:30 +0000 (17:26 +0000)
'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

30 files changed:
src/mathed/ChangeLog
src/mathed/Makefile.am
src/mathed/array.C
src/mathed/array.h
src/mathed/math_arrayinset.C
src/mathed/math_cursor.C
src/mathed/math_fracbase.C [new file with mode: 0644]
src/mathed/math_fracbase.h [new file with mode: 0644]
src/mathed/math_fracinset.C
src/mathed/math_fracinset.h
src/mathed/math_funcinset.C
src/mathed/math_funcinset.h
src/mathed/math_gridinset.C
src/mathed/math_gridinset.h
src/mathed/math_inset.C
src/mathed/math_inset.h
src/mathed/math_macro.C
src/mathed/math_macro.h
src/mathed/math_macrotable.C
src/mathed/math_macrotemplate.C
src/mathed/math_macrotemplate.h
src/mathed/math_matrixinset.C
src/mathed/math_nestinset.C
src/mathed/math_nestinset.h
src/mathed/math_parser.C
src/mathed/math_parser.h
src/mathed/math_sizeinset.C
src/mathed/math_sizeinset.h
src/mathed/math_stackrelinset.C [new file with mode: 0644]
src/mathed/math_stackrelinset.h [new file with mode: 0644]

index 7457bdc80dfeda483aca51229dbc207873662758..9d777481e7b8d0be01660ff6402da9116a875692 100644 (file)
@@ -1,4 +1,13 @@
 
+2001-08-08  André Pönitz  <poenitz@gmx.net>
+
+       *       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  <poenitz@gmx.net>
 
        * formulamacro.C: fix nasty bug due to missing copy constructor
index 8a94d7e5607d2e6b5f0f23d9fe925081c8429818..fada409d2e9a08647346bc3b86423a8b7f07d467 100644 (file)
@@ -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 \
index db18ed90bba31def5ec94dced0812969ecf172c4..8881c07cf6478d66708c630bef8c6dc22c39bd8f 100644 (file)
@@ -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;
index 46a69578d4d9e30b803e02f2b425f86e7eff144a..8947ef4d47c00c03ed784959c3123a61ead24766 100644 (file)
@@ -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;
        ///
index d01dd9caa2f678aaefc2d418a839cbece6e8495a..ff92bc9199efbb8607994ac32aab87fc5a805721 100644 (file)
@@ -7,7 +7,7 @@
 
 
 MathArrayInset::MathArrayInset(int m, int n)
-       : MathGridInset(m, n, "array")
+       : MathGridInset(m, n)
 {}
 
 
index 124a770c4275d463ec029eb5fa765f256c05b253..370964b1495ffae783319bed4c471f5ed6bf7892 100644 (file)
@@ -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 (file)
index 0000000..9736d34
--- /dev/null
@@ -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 (file)
index 0000000..05935d9
--- /dev/null
@@ -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
index 96ad21049c74cd5ac52a2248c2ffb46c74757259..6f6853f31efddf443721c25b4d21d4d14c667d93 100644 (file)
@@ -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;
-}
-
index 49f350cef2d85f5fd7c69820c0d71601f66ce873..9e0031c57be58665bdbfaf0bc23810bd4153fab2 100644 (file)
@@ -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
index 26f95fc3efd513a64ac7237fcd54ba53f6361d19..d34245db74a9195d093a09ee2de9579637690cca 100644 (file)
@@ -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_ << ' ';
index b84acef93975b6852da655e1f996710d43d66a4f..ad6a9791ff3e0080824ad028cb28fdbde6c6aed0 100644 (file)
@@ -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
index 5cb230c18ce77ba80d1ba098db818f9141346cb2..33b211b9ff4492bd931d0ee479e00f3e107875b8 100644 (file)
@@ -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";
index 1b4e4ca2697da803489f9b9801553761682dee49..885ae2b1dfcc97a81d529d59b1d7d58c26827788 100644 (file)
@@ -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;
        ///
index 31dd692391ade73bd5ca397f490f538ca7914a5e..b7649d8ef13a0463ddc3ce0a5d5e0207943d7614 100644 (file)
@@ -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] ";
 }
 
 
index 6ff7f6c33884651f667e69c22b56b65f7331bf4a..cdfc968a2dbdf6789b1edb97277d36f9bc41be9c 100644 (file)
@@ -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
index 24d31eeccc6c9061218b431d9cbe986311ee8775..12738d6d4890d1938c9ecdf9d9b5c6850f807afc 100644 (file)
@@ -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);
 }
index 777b4f508c73455af40b622c6860894b04233550..d54f064acb54fdaa59bdfd8ebe7fccb7ad4c1a96 100644 (file)
@@ -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 &);
 };
 
 
index 27fb617a518d356545afec23aae54f3232233699..72a83a633f91fe9bdd9e622e99515262076158f4 100644 (file)
@@ -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));
 
index 60affcd5c4054b4d31bf1233ae662655ca1c09f1..09b6075f210dcb5e9313d40f0b0fc0ce31894a0d 100644 (file)
@@ -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_ << "}";
index 7e64b1e2dbdcbcfc4e66be2c1506bc06d53b7d06..a8c028cac5807f5e0c1bd78ccd539ea529cc3aec 100644 (file)
@@ -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
index 81a4b064831b5e5cbd8bdc99917fdd6c8c2e166d..4684a59820c8ee3a471f888513eebe7f14bef21a 100644 (file)
@@ -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
index 7738433acb0e4604c1ea407a071ebd4d4f685743..32ab637300641da3bf61a9dc9b4aefed833db9dc 100644 (file)
@@ -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
index fc694721aa14a11c65e719636f48946748fa512b..97569f452644306f66fd456caf206df89542aadc 100644 (file)
@@ -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;
index 0bcf7bed27c524226135188d1ffe7fcad5c85de7..df7ee5ceb79673f775a4585c0ad22400ea1ae517 100644 (file)
@@ -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<MathGridInset *>(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<MathMatrixInset *>(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:
                {
index 9b356fbec429f8b4cfd54b58a993875ba9f31404..5cf3638ed49a59a55a7c4aac70a364b0f511c2b8 100644 (file)
@@ -47,8 +47,6 @@ enum MathTokenEnum
        ///
        LM_TK_FRAC,
        ///
-       LM_TK_CHOOSE,
-       ///
        LM_TK_SQRT,
        ///
        LM_TK_BEGIN,
index 2f9d98b3108917a94cb9eff53b677eb74b5c30ee..37a19b2aec5e03a3f46a94c57c5b77ed91f5d64b 100644 (file)
@@ -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:
index fa23904ea5f140ff3b405b889660fa1857d48f76..15f2b1d031fca6c4a39dc64c4f8123249e7f74f6 100644 (file)
@@ -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 (file)
index 0000000..081c3b4
--- /dev/null
@@ -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 (file)
index 0000000..3de330a
--- /dev/null
@@ -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