From c800129f2b84b996f5d2a03229f8696c32efa141 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Tue, 11 Sep 2001 15:46:51 +0000 Subject: [PATCH] partial fix for the macro problem git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2727 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/array.C | 4 +--- src/mathed/math_atom.C | 8 +++---- src/mathed/math_atom.h | 2 +- src/mathed/math_inset.C | 6 ++--- src/mathed/math_inset.h | 4 ++-- src/mathed/math_macroarg.C | 46 +++++++++++++++---------------------- src/mathed/math_macroarg.h | 14 ++++------- src/mathed/math_nestinset.C | 9 ++------ src/mathed/math_nestinset.h | 2 +- 9 files changed, 37 insertions(+), 58 deletions(-) diff --git a/src/mathed/array.C b/src/mathed/array.C index 9460af4204..2815e24b4e 100644 --- a/src/mathed/array.C +++ b/src/mathed/array.C @@ -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); } diff --git a/src/mathed/math_atom.C b/src/mathed/math_atom.C index cedad2b5c5..d9d3d6be2b 100644 --- a/src/mathed/math_atom.C +++ b/src/mathed/math_atom.C @@ -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); } diff --git a/src/mathed/math_atom.h b/src/mathed/math_atom.h index c5b7e7af0c..b6137142ce 100644 --- a/src/mathed/math_atom.h +++ b/src/mathed/math_atom.h @@ -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; /// diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index e132d5ce50..5d10501998 100644 --- a/src/mathed/math_inset.C +++ b/src/mathed/math_inset.C @@ -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 diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 05b134ebe8..ed6c4c9591 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -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; /// diff --git a/src/mathed/math_macroarg.C b/src/mathed/math_macroarg.C index df4be793fe..72fdd546bf 100644 --- a/src/mathed/math_macroarg.C +++ b/src/mathed/math_macroarg.C @@ -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; } diff --git a/src/mathed/math_macroarg.h b/src/mathed/math_macroarg.h index 26fad2dad0..3bf884684e 100644 --- a/src/mathed/math_macroarg.h +++ b/src/mathed/math_macroarg.h @@ -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 diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index 386798529f..3d1de5e64e 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -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); } diff --git a/src/mathed/math_nestinset.h b/src/mathed/math_nestinset.h index 068fbad165..123fc26749 100644 --- a/src/mathed/math_nestinset.h +++ b/src/mathed/math_nestinset.h @@ -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; -- 2.39.2