]> git.lyx.org Git - features.git/commitdiff
partial fix for the macro problem
authorAndré Pönitz <poenitz@gmx.net>
Tue, 11 Sep 2001 15:46:51 +0000 (15:46 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Tue, 11 Sep 2001 15:46:51 +0000 (15:46 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2727 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/array.C
src/mathed/math_atom.C
src/mathed/math_atom.h
src/mathed/math_inset.C
src/mathed/math_inset.h
src/mathed/math_macroarg.C
src/mathed/math_macroarg.h
src/mathed/math_nestinset.C
src/mathed/math_nestinset.h

index 9460af42045c24f4498ed9f01e38ac84abe109b1..2815e24b4e53e9b964d25c4828b3e7de677955c3 100644 (file)
@@ -30,10 +30,8 @@ int MathArray::last() const
 
 void MathArray::substitute(MathMacro const & m)
 {
-       MathArray tmp;
        for (iterator it = begin(); it != end(); ++it)
-               it->substitute(tmp, m);
-       swap(tmp);
+               it->substitute(m);
 }
 
 
index cedad2b5c54ac8ca64eefa4a1d46ec1a0acc7783..d9d3d6be2b79bfd40592f9f4c0fe5948bc8bd3a9 100644 (file)
@@ -351,14 +351,14 @@ bool MathAtom::hasLimits() const
 }
 
 
-void MathAtom::substitute(MathArray & array, MathMacro const & m) const
+void MathAtom::substitute(MathMacro const & m)
 {
        if (nucleus())
-               nucleus()->substitute(array, m);
+               nucleus()->substitute(m);
        if (up())
-               up()->substitute(array, m);
+               up()->substitute(m);
        if (down())
-               down()->substitute(array, m);
+               down()->substitute(m);
 }
 
 
index c5b7e7af0c32e8398ebfb6793c7d9078762382ca..b6137142ce9636c0fe213bf29e231ebe57d30b2a 100644 (file)
@@ -101,7 +101,7 @@ public:
        ///
        MathInset * nucleus() const { return nucleus_; }
        ///
-       void substitute(MathArray &, const MathMacro &) const;
+       void substitute(const MathMacro &);
        ///
        void write(std::ostream &, bool) const;
        ///
index e132d5ce50bd39317aef40817b5b397005b7dad3..5d10501998d45fce3f0d0732e468c4107f0d95c3 100644 (file)
@@ -121,10 +121,8 @@ MathArray const & MathInset::cell(int) const
 }
 
 
-void MathInset::substitute(MathArray & array, MathMacro const &) const
-{
-       array.push_back(clone());
-}
+void MathInset::substitute(MathMacro const &)
+{}
 
 
 bool MathInset::idxNext(int &, int &) const
index 05b134ebe8053994b7dc502147a1c735beefb189..ed6c4c95917d09a0174b8dc23794c00343504ce3 100644 (file)
@@ -56,8 +56,8 @@ public:
        virtual void writeNormal(std::ostream &) const;
        /// reproduce itself
        virtual MathInset * clone() const = 0;
-       /// appends itself with macro arguments substituted
-       virtual void substitute(MathArray & array, MathMacro const & macro) const;
+       ///substitutes macro arguments if necessary
+       virtual void substitute(MathMacro const & macro);
        /// compute the size of the object, sets ascend_, descend_ and width_
        virtual void metrics(MathStyles st) const;
        /// 
index df4be793fec25c3f8488f0597095dc07aa254865..72fdd546bf6881268846cb59d50b965eb7c7f4ed 100644 (file)
@@ -11,7 +11,7 @@
 
 
 MathMacroArgument::MathMacroArgument(int n)
-       : number_(n)
+       : MathNestInset(1), number_(n), expanded_(false)
 {
        if (n < 1 || n > 9) {
                lyxerr << "MathMacroArgument::MathMacroArgument: wrong Argument id: "
@@ -29,39 +29,30 @@ MathInset * MathMacroArgument::clone() const
 }
 
 
-void MathMacroArgument::draw(Painter & pain, int x, int y) const
-{
-       drawStr(pain, LM_TC_TEX, size(), x, y, str_);
-}
-
-
-int MathMacroArgument::ascent() const
-{
-       return mathed_char_ascent(LM_TC_TEX, size(), 'I');
-}
-
-
-int MathMacroArgument::descent() const
-{
-       return mathed_char_descent(LM_TC_TEX, size(), 'I');
-}
-
-
-int MathMacroArgument::width() const
+void MathMacroArgument::write(std::ostream & os, bool /*fragile*/) const
 {
-       return mathed_string_width(LM_TC_TEX, size(), str_);
+       os << '#' << number_;
 }
 
 
-void MathMacroArgument::write(std::ostream & os, bool /*fragile*/) const
+void MathMacroArgument::metrics(MathStyles st) const
 {
-       os << '#' << number_ << ' ';
+       if (expanded_) {
+               xcell(0).metrics(st);
+               width_   = xcell(0).width();
+               ascent_  = xcell(0).ascent();
+               descent_ = xcell(0).descent();
+       } else
+               mathed_string_dim(LM_TC_TEX, size(), str_, width_, ascent_, descent_);
 }
 
 
-void MathMacroArgument::metrics(MathStyles st) const
+void MathMacroArgument::draw(Painter & pain, int x, int y) const
 {
-       size_ = st;
+       if (expanded_)
+               xcell(0).draw(pain, x, y);
+       else
+               drawStr(pain, LM_TC_TEX, size(), x, y, str_);
 }
 
 
@@ -71,8 +62,9 @@ void MathMacroArgument::writeNormal(std::ostream & os) const
 }
 
 
-void MathMacroArgument::substitute(MathArray & array, MathMacro const & m) const
+void MathMacroArgument::substitute(MathMacro const & m)
 {
-       array.push_back(m.cell(number_ - 1));
+       cell(0) = m.cell(number_ - 1);
+       expanded_ = true;
 }
 
index 26fad2dad06d05e58bb1c3ece7641bd5977380a8..3bf884684e8d4f388e0c5489a5bae54510d5ba82 100644 (file)
@@ -2,7 +2,7 @@
 #ifndef MATHMACROARGUMENT_H
 #define MATHMACROARGUMENT_H
 
-#include "math_inset.h"
+#include "math_nestinset.h"
 
 #ifdef __GNUG__
 #pragma interface
@@ -11,7 +11,7 @@
 /** A macro argument
     \author Alejandro Aguilar Sierra
 */
-class MathMacroArgument : public MathInset {
+class MathMacroArgument : public MathNestInset {
 public:
        ///
        explicit MathMacroArgument(int);
@@ -26,19 +26,15 @@ public:
        ///
        void writeNormal(std::ostream &) const;
        ///
-       void substitute(MathArray & array, MathMacro const & macro) const;
-       /// 
-       int ascent() const;
-       ///
-       int descent() const;
-       ///
-       int width() const;
+       void substitute(MathMacro const & macro);
 
 private:
        /// A number between 1 and 9
        int number_;
        ///
        char str_[3];
+       ///
+       bool expanded_;
 };
 
 #endif
index 386798529f7f8cf5f96a2a7cce9c3a9d5b22b1fb..3d1de5e64eda6427c324cef853ba2af916ae013e 100644 (file)
@@ -41,15 +41,10 @@ MathArray const & MathNestInset::cell(int i) const
 }
 
 
-void MathNestInset::substitute(MathArray & array, MathMacro const & m) const
+void MathNestInset::substitute(MathMacro const & m)
 {
-#warning Huch?
-/*
-       MathNestInset * p = clone();
-       array.push_back(clone());
        for (int i = 0; i < nargs(); ++i)
-               array.back().cellsubstitute(m);
-*/
+               cell(i).substitute(m);
 }
 
 
index 068fbad16531d239bd1aaa3bafc3c97f772bf431..123fc267497b1c12e2eed65ea5d1f1a8d1623cec 100644 (file)
@@ -23,7 +23,7 @@ public:
        /// draw the object, sets xo_ and yo_ cached values 
        void draw(Painter &, int x, int y) const;
        /// appends itself with macro arguments substituted
-       void substitute(MathArray & array, MathMacro const & macro) const;
+       void substitute(MathMacro const & macro); 
 
        /// The left key
        bool idxLeft(int & idx, int & pos) const;