-#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()
+void MathMacroTemplate::metrics(MathMetricsInfo const & mi) const
{
- MathParInset::Metrics();
- width += 4;
- ascent += 2;
- descent += 2;
+ xcell(0).metrics(mi);
+ width_ = xcell(0).width() + 4;
+ ascent_ = xcell(0).ascent() + 2;
+ descent_ = xcell(0).descent() + 2;
}
-void MathMacroTemplate::draw(Painter & pain, int x, int y)
+void MathMacroTemplate::draw(Painter & pain, int x, int y) 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);
+ xcell(0).draw(pain, x + 2, y + 1);
+ pain.rectangle(x, y - ascent(), width(), height(), LColor::blue);
}
+
+void MathMacroTemplate::write(WriteStream & os) const
+{
+ os << "\n\\newcommand{\\" << name_.c_str() << '}';
+ if (numargs_ > 0)
+ os << '[' << numargs_ << ']';
+ os << '{' << cell(0) << "}\n";
+}