void MathArray::substitute(MathMacro const & m)
{
- MathArray tmp;
for (iterator it = begin(); it != end(); ++it)
- it->substitute(tmp, m);
- swap(tmp);
+ it->substitute(m);
}
}
-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);
}
///
MathInset * nucleus() const { return nucleus_; }
///
- void substitute(MathArray &, const MathMacro &) const;
+ void substitute(const MathMacro &);
///
void write(std::ostream &, bool) const;
///
}
-void MathInset::substitute(MathArray & array, MathMacro const &) const
-{
- array.push_back(clone());
-}
+void MathInset::substitute(MathMacro const &)
+{}
bool MathInset::idxNext(int &, int &) const
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;
///
MathMacroArgument::MathMacroArgument(int n)
- : number_(n)
+ : MathNestInset(1), number_(n), expanded_(false)
{
if (n < 1 || n > 9) {
lyxerr << "MathMacroArgument::MathMacroArgument: wrong Argument id: "
}
-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_);
}
}
-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;
}
#ifndef MATHMACROARGUMENT_H
#define MATHMACROARGUMENT_H
-#include "math_inset.h"
+#include "math_nestinset.h"
#ifdef __GNUG__
#pragma interface
/** A macro argument
\author Alejandro Aguilar Sierra
*/
-class MathMacroArgument : public MathInset {
+class MathMacroArgument : public MathNestInset {
public:
///
explicit MathMacroArgument(int);
///
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
}
-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);
}
/// 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;