]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_macroarg.C
fix typo that put too many include paths for most people
[lyx.git] / src / mathed / math_macroarg.C
index b79589ef69696936635b99185a8a16692a38a935..8033d70b84fb7bf58ab289b0078202cf49424c8f 100644 (file)
@@ -1,84 +1,79 @@
-#include <config.h>
+#ifdef __GNUG__
+#pragma implementation
+#endif
 
 #include "math_macroarg.h"
-#include "mathed/support.h"
+#include "math_macro.h"
+#include "math_defs.h"
+#include "math_mathmlstream.h"
+#include "math_support.h"
 #include "debug.h"
 
 
-MathMacroArgument::MathMacroArgument()
-       : expnd_mode_(false), number_(1)
-{
-       SetType(LM_OT_MACRO_ARG);
-}
+using std::endl;
 
 
-MathMacroArgument::MathMacroArgument(int n)
-       : expnd_mode_(false), number_(n)
+MathMacroArgument::MathMacroArgument(int n, MathTextCodes code)
+       : MathNestInset(1), number_(n), expanded_(false), code_(code)
 {
-       SetType(LM_OT_MACRO_ARG);
+       if (n < 1 || n > 9) {
+               lyxerr << "MathMacroArgument::MathMacroArgument: wrong Argument id: "
+                       << n << endl;
+       }
+       str_[0] = '#';
+       str_[1] = static_cast<unsigned char>('0' + n);
+       str_[2] = '\0';
 }
 
 
-MathMacroArgument::~MathMacroArgument()
+MathInset * MathMacroArgument::clone() const
 {
-       lyxerr << "help, destroyme!" << std::endl;
+       return new MathMacroArgument(*this);
 }
 
 
-MathedInset * MathMacroArgument::Clone()
+void MathMacroArgument::write(WriteStream & os) const
 {
-       return this;
+       if (code_ == LM_TC_MIN)
+               os << str_;
+       else
+               os << '\\' << math_font_name(code_) << '{' << str_ << '}';
 }
 
 
-void MathMacroArgument::setNumber(int n)
+void MathMacroArgument::metrics(MathMetricsInfo const & mi) const
 {
-       number_ = n;
+       whichFont(font_, LM_TC_TEX, mi);
+       if (expanded_) {
+               xcell(0).metrics(mi);
+               width_   = xcell(0).width();
+               ascent_  = xcell(0).ascent();
+               descent_ = xcell(0).descent();
+       } else
+               mathed_string_dim(font_, str_, ascent_, descent_, width_);
 }
 
 
-void MathMacroArgument::setExpand(bool e)
+void MathMacroArgument::draw(Painter & pain, int x, int y) const
 {
-       expnd_mode_ = e;
+       if (expanded_)
+               xcell(0).draw(pain, x, y);
+       else
+               drawStr(pain, font_, x, y, str_);
 }
 
 
-bool MathMacroArgument::getExpand() const
+void MathMacroArgument::normalize(NormalStream & os) const
 {
-       return expnd_mode_;
+       os << "[macroarg " << str_ << "] ";
 }
 
 
-void MathMacroArgument::draw(Painter & pain, int x, int baseline)
-{
-       if (expnd_mode_) {
-               MathParInset::draw(pain, x, baseline);
-       } else {
-               std::ostringstream ost;
-               ost << '#' << number_;
-               drawStr(pain, LM_TC_TEX, size(), x, baseline, ost.str().c_str());
-       }
-}
-
-void MathMacroArgument::Metrics()
+void MathMacroArgument::substitute(MathMacro const & m)
 {
-       if (expnd_mode_) {
-               MathParInset::Metrics();
-       } else {
-               std::ostringstream ost;
-               ost << '#' << number_;
-               width = mathed_string_width(LM_TC_TEX, size(), ost.str().c_str());
-               mathed_string_height(LM_TC_TEX, size(), ost.str().c_str(),
-                                    ascent, descent);
-       }
-}
-
-
-void MathMacroArgument::Write(ostream & os, bool fragile)
-{
-       if (expnd_mode_) {
-               MathParInset::Write(os, fragile);
-       } else {
-               os << '#' << number_ << ' ';
-       }
+       cell(0) = m.cell(number_ - 1);
+       if (code_ != LM_TC_MIN)
+               for (MathArray::iterator it = cell(0).begin(); it != cell(0).end(); ++it)
+                       it->nucleus()->handleFont(code_);
+       expanded_ = true;
 }