2001-02-26 12:53:35 +00:00
|
|
|
|
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_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-02 10:03:27 +00:00
|
|
|
void MathMacroTemplate::metrics(MetricsInfo & mi, Dimension & dim) const
|
2001-03-05 10:52:39 +00:00
|
|
|
{
|
2002-08-02 14:29:42 +00:00
|
|
|
cell(0).metrics(mi);
|
|
|
|
cell(1).metrics(mi);
|
2003-05-27 13:55:03 +00:00
|
|
|
dim_.wid = cell(0).width() + cell(1).width() + 10;
|
|
|
|
dim_.asc = std::max(cell(0).ascent(), cell(1).ascent()) + 2;
|
|
|
|
dim_.des = std::max(cell(0).descent(), cell(1).descent()) + 2;
|
2003-06-02 10:03:27 +00:00
|
|
|
dim = dim_;
|
2001-03-05 10:52:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-21 14:20:48 +00:00
|
|
|
void MathMacroTemplate::draw(PainterInfo & pi, int x, int y) const
|
2001-02-13 17:08:51 +00:00
|
|
|
{
|
2002-08-02 14:29:42 +00:00
|
|
|
int const w0 = cell(0).width();
|
|
|
|
int const w1 = cell(1).width();
|
|
|
|
cell(0).draw(pi, x + 2, y + 1);
|
2003-05-28 13:22:36 +00:00
|
|
|
pi.pain.rectangle(x, y - dim_.ascent() + 1, w0 + 4, dim_.height(),
|
2003-04-14 16:00:42 +00:00
|
|
|
LColor::mathline);
|
2002-08-02 14:29:42 +00:00
|
|
|
cell(1).draw(pi, x + 8 + w0, y + 1);
|
2003-05-28 13:22:36 +00:00
|
|
|
pi.pain.rectangle(x + w0 + 6 , y - dim_.ascent() + 1, w1 + 4,
|
|
|
|
dim_.height(), LColor::mathline);
|
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
|
|
|
}
|