]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_macrotemplate.C
make \newcommand{\bb}[1]{\mathbf{#1}} work for read/write/display.
[lyx.git] / src / mathed / math_macrotemplate.C
index cfb1b36b80b01465284ab6b9fa408766a2dace9a..3fe31bc7b7477df0fb072a87e6973c080ebf6d9b 100644 (file)
@@ -1,66 +1,72 @@
-#include <config.h>
-
 #ifdef __GNUG__
 #pragma implementation
 #endif
 
 #include "math_macrotemplate.h"
-#include "math_macro.h"
-#include "macro_support.h"
-#include "support/LOstream.h"
-#include "support/LAssert.h"
-#include "debug.h"
+#include "math_mathmlstream.h"
 #include "Painter.h"
+#include "debug.h"
 
-using namespace std;
 
-MathMacroTemplate::MathMacroTemplate() :
-       MathParInset(LM_ST_TEXT, "undefined", LM_OT_MACRO),
-       na_(0), users_()
+MathMacroTemplate::MathMacroTemplate()
+       : MathNestInset(1), numargs_(0), name_()
 {}
 
-MathMacroTemplate::MathMacroTemplate(string const & nm, int na) :
-       MathParInset(LM_ST_TEXT, nm, LM_OT_MACRO),
-       na_(na), users_()
-{}
+
+MathMacroTemplate::MathMacroTemplate(string const & nm, int numargs)
+       : MathNestInset(1), numargs_(numargs), name_(nm)
+{
+       if (numargs_ > 9)
+               lyxerr << "MathMacroTemplate::MathMacroTemplate: wrong # of arguments: "
+                       << numargs_ << std::endl;
+}
 
 
-int MathMacroTemplate::nargs() const
+MathInset * MathMacroTemplate::clone() const
 {
-       return na_;
+       //lyxerr << "cloning MacroTemplate!\n";
+       return new MathMacroTemplate(*this);
 }
 
 
-void MathMacroTemplate::WriteDef(ostream & os, bool fragile) const
+int MathMacroTemplate::numargs() const
 {
-       os << "\n\\newcommand{\\" << name << "}";
+       return numargs_;
+}
 
-       if (na_ > 0 )
-               os << "[" << na_ << "]";
 
-       os << "{";
-#ifdef WITH_WARNINGS
-#warning stupid cast
-#endif
-       const_cast<MathMacroTemplate *>(this)->Write(os, fragile);
-       os << "}\n";
+void MathMacroTemplate::numargs(int numargs)
+{
+       numargs_ = numargs;
+}
+
+
+string const & MathMacroTemplate::name() const
+{
+       return name_;
+}
+
+
+void MathMacroTemplate::metrics(MathMetricsInfo const & mi) const
+{
+       xcell(0).metrics(mi);
+       width_   = xcell(0).width() + 4;
+       ascent_  = xcell(0).ascent() + 2;
+       descent_ = xcell(0).descent() + 2;
 }
 
 
-void MathMacroTemplate::Metrics()
+void MathMacroTemplate::draw(Painter & pain, int x, int y) const
 {
-       MathParInset::Metrics();
-       width   += 4;
-       ascent  += 2;
-       descent += 2;
+       xcell(0).draw(pain, x + 2, y + 1);
+       pain.rectangle(x, y - ascent(), width(), height(), LColor::blue);
 }
 
 
-void MathMacroTemplate::draw(Painter & pain, int x, int y)
+void MathMacroTemplate::write(WriteStream & os) const
 {
-       MathParInset::draw(pain, x + 2, y + 1);
-       int w = Width();
-       int a = Ascent();
-       int h = Height();
-       pain.rectangle(x, y - a, w, h, LColor::blue);
+       os << "\n\\newcommand{\\" << name_.c_str() << '}';
+       if (numargs_ > 0)
+               os << '[' << numargs_ << ']';
+       os << '{' << cell(0) << "}\n";
 }