2001-02-26 12:53:35 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2001-02-13 17:08:51 +00:00
|
|
|
#include "math_macrotemplate.h"
|
2001-11-08 12:06:56 +00:00
|
|
|
#include "math_mathmlstream.h"
|
2001-04-24 16:13:38 +00:00
|
|
|
#include "Painter.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "debug.h"
|
2001-02-14 15:00:50 +00:00
|
|
|
|
2001-02-13 17:08:51 +00:00
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
using std::endl;
|
|
|
|
|
|
|
|
|
2001-08-03 09:54:48 +00:00
|
|
|
MathMacroTemplate::MathMacroTemplate()
|
2001-08-08 17:26:30 +00:00
|
|
|
: MathNestInset(1), numargs_(0), name_()
|
2001-04-24 16:13:38 +00:00
|
|
|
{}
|
2001-02-13 17:08:51 +00:00
|
|
|
|
2001-04-25 15:43:57 +00:00
|
|
|
|
2001-08-03 09:54:48 +00:00
|
|
|
MathMacroTemplate::MathMacroTemplate(string const & nm, int numargs)
|
2001-08-08 17:26:30 +00:00
|
|
|
: MathNestInset(1), numargs_(numargs), name_(nm)
|
2001-10-02 10:50:10 +00:00
|
|
|
{
|
2001-12-11 11:33:43 +00:00
|
|
|
if (numargs_ > 9)
|
2001-10-02 10:50:10 +00:00
|
|
|
lyxerr << "MathMacroTemplate::MathMacroTemplate: wrong # of arguments: "
|
2002-02-16 15:59:55 +00:00
|
|
|
<< numargs_ << endl;
|
2001-10-02 10:50:10 +00:00
|
|
|
}
|
2001-02-26 12:53:35 +00:00
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
MathInset * MathMacroTemplate::clone() const
|
2001-02-26 12:53:35 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
//lyxerr << "cloning MacroTemplate!\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
return new MathMacroTemplate(*this);
|
2001-02-26 12:53:35 +00:00
|
|
|
}
|
2001-02-13 17:08:51 +00:00
|
|
|
|
2001-06-27 15:33:55 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
int MathMacroTemplate::numargs() const
|
|
|
|
{
|
|
|
|
return numargs_;
|
|
|
|
}
|
2001-02-13 17:08:51 +00:00
|
|
|
|
2001-06-27 15:33:55 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathMacroTemplate::numargs(int numargs)
|
2001-02-13 17:08:51 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
numargs_ = numargs;
|
|
|
|
}
|
2001-02-13 17:08:51 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-08-08 17:26:30 +00:00
|
|
|
string const & MathMacroTemplate::name() const
|
|
|
|
{
|
|
|
|
return name_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-22 15:37:49 +00:00
|
|
|
void MathMacroTemplate::metrics(MathMetricsInfo const & mi) const
|
2001-03-05 10:52:39 +00:00
|
|
|
{
|
2001-10-22 15:37:49 +00:00
|
|
|
xcell(0).metrics(mi);
|
2001-06-25 00:06:33 +00:00
|
|
|
width_ = xcell(0).width() + 4;
|
|
|
|
ascent_ = xcell(0).ascent() + 2;
|
|
|
|
descent_ = xcell(0).descent() + 2;
|
2001-03-05 10:52:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-06 17:20:26 +00:00
|
|
|
void MathMacroTemplate::draw(Painter & pain, int x, int y) const
|
2001-02-13 17:08:51 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
xcell(0).draw(pain, x + 2, y + 1);
|
|
|
|
pain.rectangle(x, y - ascent(), width(), height(), LColor::blue);
|
2001-02-13 17:08:51 +00:00
|
|
|
}
|
2001-11-08 12:06:56 +00:00
|
|
|
|
|
|
|
|
2001-11-09 08:35:57 +00:00
|
|
|
void MathMacroTemplate::write(WriteStream & os) const
|
2001-11-08 12:06:56 +00:00
|
|
|
{
|
|
|
|
os << "\n\\newcommand{\\" << name_.c_str() << '}';
|
|
|
|
if (numargs_ > 0)
|
2001-11-20 08:27:13 +00:00
|
|
|
os << '[' << numargs_ << ']';
|
2001-11-08 12:06:56 +00:00
|
|
|
os << '{' << cell(0) << "}\n";
|
|
|
|
}
|