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"
|
2002-07-12 14:24:47 +00:00
|
|
|
#include "math_parser.h"
|
2002-05-23 09:21:32 +00:00
|
|
|
#include "frontends/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
|
|
|
|
2001-08-03 09:54:48 +00:00
|
|
|
MathMacroTemplate::MathMacroTemplate()
|
2002-03-25 12:11:25 +00:00
|
|
|
: MathNestInset(2), 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
|
|
|
|
2002-07-12 14:24:47 +00:00
|
|
|
MathMacroTemplate::MathMacroTemplate(string const & nm, int numargs,
|
|
|
|
MathArray const & ar1, MathArray const & ar2)
|
2002-03-25 12:11:25 +00:00
|
|
|
: MathNestInset(2), 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-03-25 12:11:25 +00:00
|
|
|
<< numargs_ << std::endl;
|
2002-07-12 14:24:47 +00:00
|
|
|
cell(0) = ar1;
|
|
|
|
cell(1) = ar2;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MathMacroTemplate::MathMacroTemplate(std::istream & is)
|
|
|
|
: MathNestInset(2), numargs_(0), name_()
|
|
|
|
{
|
|
|
|
MathArray ar;
|
|
|
|
mathed_parse_cell(ar, is);
|
|
|
|
if (ar.size() != 1 || !ar[0]->asMacroTemplate()) {
|
|
|
|
lyxerr << "cannot read macro from '" << ar << "'\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
operator=( *(ar[0]->asMacroTemplate()) );
|
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
|
|
|
|
2002-08-01 15:53:46 +00:00
|
|
|
string MathMacroTemplate::name() const
|
2001-08-08 17:26:30 +00:00
|
|
|
{
|
|
|
|
return name_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-30 07:09:54 +00:00
|
|
|
void MathMacroTemplate::metrics(MathMetricsInfo & mi) const
|
2001-03-05 10:52:39 +00:00
|
|
|
{
|
2001-10-22 15:37:49 +00:00
|
|
|
xcell(0).metrics(mi);
|
2002-03-25 12:11:25 +00:00
|
|
|
xcell(1).metrics(mi);
|
2002-07-11 11:27:24 +00:00
|
|
|
dim_.w = xcell(0).width() + xcell(1).width() + 10;
|
|
|
|
dim_.a = std::max(xcell(0).ascent(), xcell(1).ascent()) + 2;
|
|
|
|
dim_.d = std::max(xcell(0).descent(), xcell(1).descent()) + 2;
|
2001-03-05 10:52:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-06-24 15:37:14 +00:00
|
|
|
void MathMacroTemplate::draw(MathPainterInfo & pi, int x, int y) const
|
2001-02-13 17:08:51 +00:00
|
|
|
{
|
2002-03-25 12:11:25 +00:00
|
|
|
int const w0 = xcell(0).width();
|
|
|
|
int const w1 = xcell(1).width();
|
2002-06-24 15:37:14 +00:00
|
|
|
xcell(0).draw(pi, x + 2, y + 1);
|
|
|
|
pi.pain.rectangle(x, y - ascent() + 1, w0 + 4, height(),
|
|
|
|
LColor::blue);
|
|
|
|
xcell(1).draw(pi, x + 8 + w0, y + 1);
|
|
|
|
pi.pain.rectangle(x + w0 + 6 , y - ascent() + 1, w1 + 4,
|
|
|
|
height(), LColor::blue);
|
2001-02-13 17:08:51 +00:00
|
|
|
}
|
2001-11-08 12:06:56 +00:00
|
|
|
|
|
|
|
|
2002-07-12 14:24:47 +00:00
|
|
|
|
2001-11-09 08:35:57 +00:00
|
|
|
void MathMacroTemplate::write(WriteStream & os) const
|
2001-11-08 12:06:56 +00:00
|
|
|
{
|
2002-03-25 12:11:25 +00:00
|
|
|
if (os.latex()) {
|
|
|
|
os << "\n\\newcommand{\\" << name_.c_str() << '}';
|
|
|
|
if (numargs_ > 0)
|
|
|
|
os << '[' << numargs_ << ']';
|
|
|
|
os << '{' << cell(0) << "}\n";
|
|
|
|
} else {
|
|
|
|
// writing .lyx
|
|
|
|
os << "\n\\newcommand{\\" << name_.c_str() << '}';
|
|
|
|
if (numargs_ > 0)
|
|
|
|
os << '[' << numargs_ << ']';
|
|
|
|
os << '{' << cell(0) << '}';
|
|
|
|
// write special .tex export only if necessary
|
|
|
|
if (!cell(1).empty())
|
|
|
|
os << "\n{" << cell(1) << '}';
|
|
|
|
}
|
2001-11-08 12:06:56 +00:00
|
|
|
}
|