2001-02-13 17:08:51 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
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"
|
|
|
|
#include "math_macro.h"
|
|
|
|
#include "macro_support.h"
|
2001-02-14 15:00:50 +00:00
|
|
|
#include "support/LOstream.h"
|
2001-02-28 17:51:28 +00:00
|
|
|
#include "support/LAssert.h"
|
2001-02-14 15:00:50 +00:00
|
|
|
|
|
|
|
using std::ostream;
|
2001-02-13 17:08:51 +00:00
|
|
|
|
|
|
|
|
2001-03-01 14:07:43 +00:00
|
|
|
MathMacroTemplate::MathMacroTemplate(string const & nm, int na):
|
2001-02-13 17:08:51 +00:00
|
|
|
MathParInset(LM_ST_TEXT, nm, LM_OT_MACRO),
|
2001-03-01 14:07:43 +00:00
|
|
|
edit_(false),
|
|
|
|
nargs_(na)
|
2001-02-13 17:08:51 +00:00
|
|
|
{
|
2001-02-15 12:22:01 +00:00
|
|
|
if (nargs_ > 0) {
|
|
|
|
tcode_ = LM_TC_ACTIVE_INSET;
|
|
|
|
args_.resize(nargs_);
|
|
|
|
for (int i = 0; i < nargs_; ++i) {
|
2001-02-13 17:08:51 +00:00
|
|
|
args_[i].setNumber(i + 1);
|
|
|
|
}
|
|
|
|
} else {
|
2001-02-15 12:22:01 +00:00
|
|
|
tcode_ = LM_TC_INSET;
|
2001-02-13 17:08:51 +00:00
|
|
|
// Here is nargs != args_.size()
|
|
|
|
//args = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 12:53:35 +00:00
|
|
|
void MathMacroTemplate::setTCode(MathedTextCodes t)
|
|
|
|
{
|
|
|
|
tcode_ = t;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathedTextCodes MathMacroTemplate::getTCode() const
|
|
|
|
{
|
|
|
|
return tcode_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MathMacroTemplate::getNoArgs() const
|
|
|
|
{
|
|
|
|
return nargs_;
|
|
|
|
}
|
2001-02-13 17:08:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
void MathMacroTemplate::setEditMode(bool ed)
|
|
|
|
{
|
|
|
|
if (ed) {
|
2001-03-01 14:07:43 +00:00
|
|
|
edit_ = true;
|
2001-02-15 12:22:01 +00:00
|
|
|
for (int i = 0; i < nargs_; ++i) {
|
2001-02-13 17:08:51 +00:00
|
|
|
args_[i].setExpand(false);
|
|
|
|
}
|
2001-02-27 11:26:18 +00:00
|
|
|
} else {
|
2001-03-01 14:07:43 +00:00
|
|
|
edit_ = false;
|
2001-02-15 12:22:01 +00:00
|
|
|
for (int i = 0; i < nargs_; ++i) {
|
2001-02-13 17:08:51 +00:00
|
|
|
args_[i].setExpand(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathMacroTemplate::draw(Painter & pain, int x, int y)
|
|
|
|
{
|
2001-02-15 12:22:01 +00:00
|
|
|
int x2;
|
|
|
|
int y2;
|
2001-02-27 11:26:18 +00:00
|
|
|
bool expnd = (nargs_ > 0) ? args_[0].getExpand() : false;
|
2001-03-01 14:07:43 +00:00
|
|
|
if (edit_) {
|
2001-02-15 12:22:01 +00:00
|
|
|
for (int i = 0; i < nargs_; ++i) {
|
2001-02-13 17:08:51 +00:00
|
|
|
args_[i].setExpand(false);
|
|
|
|
}
|
2001-02-15 12:22:01 +00:00
|
|
|
x2 = x;
|
|
|
|
y2 = y;
|
2001-02-13 17:08:51 +00:00
|
|
|
} else {
|
2001-02-15 12:22:01 +00:00
|
|
|
for (int i = 0; i < nargs_; ++i) {
|
2001-02-13 17:08:51 +00:00
|
|
|
args_[i].setExpand(true);
|
|
|
|
}
|
2001-02-15 12:22:01 +00:00
|
|
|
x2 = xo();
|
|
|
|
y2 = yo();
|
2001-02-13 17:08:51 +00:00
|
|
|
}
|
|
|
|
MathParInset::draw(pain, x, y);
|
2001-02-15 12:22:01 +00:00
|
|
|
xo(x2);
|
|
|
|
yo(y2);
|
2001-02-13 17:08:51 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
for (int i = 0; i < nargs_; ++i) {
|
2001-02-13 17:08:51 +00:00
|
|
|
args_[i].setExpand(expnd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathMacroTemplate::Metrics()
|
|
|
|
{
|
2001-03-01 14:07:43 +00:00
|
|
|
bool const expnd = (nargs_ > 0) ? args_[0].getExpand() : false;
|
2001-02-13 17:08:51 +00:00
|
|
|
|
2001-03-01 14:07:43 +00:00
|
|
|
if (edit_) {
|
2001-02-15 12:22:01 +00:00
|
|
|
for (int i = 0; i < nargs_; ++i) {
|
2001-02-13 17:08:51 +00:00
|
|
|
args_[i].setExpand(false);
|
|
|
|
}
|
|
|
|
} else {
|
2001-02-15 12:22:01 +00:00
|
|
|
for (int i = 0; i < nargs_; ++i) {
|
2001-02-13 17:08:51 +00:00
|
|
|
args_[i].setExpand(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MathParInset::Metrics();
|
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
for (int i = 0; i < nargs_; ++i) {
|
2001-02-13 17:08:51 +00:00
|
|
|
args_[i].setExpand(expnd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathMacroTemplate::update(MathMacro * macro)
|
|
|
|
{
|
2001-02-28 17:51:28 +00:00
|
|
|
Assert(macro);
|
2001-03-01 14:07:43 +00:00
|
|
|
int const idx = macro->getArgumentIdx();
|
2001-02-15 12:22:01 +00:00
|
|
|
for (int i = 0; i < nargs_; ++i) {
|
2001-02-13 17:08:51 +00:00
|
|
|
macro->setArgumentIdx(i);
|
2001-02-16 09:25:43 +00:00
|
|
|
args_[i].setData(macro->GetData());
|
2001-02-13 17:08:51 +00:00
|
|
|
MathedRowSt * row = macro->getRowSt();
|
|
|
|
args_[i].setRowSt(row);
|
|
|
|
}
|
2001-02-28 17:51:28 +00:00
|
|
|
macro->setArgumentIdx(idx);
|
2001-02-13 17:08:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathMacroTemplate::WriteDef(ostream & os, bool fragile)
|
|
|
|
{
|
|
|
|
os << "\n\\newcommand{\\" << name << "}";
|
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
if (nargs_ > 0 )
|
|
|
|
os << "[" << nargs_ << "]";
|
2001-02-13 17:08:51 +00:00
|
|
|
|
|
|
|
os << "{";
|
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
for (int i = 0; i < nargs_; ++i) {
|
2001-02-13 17:08:51 +00:00
|
|
|
args_[i].setExpand(false);
|
|
|
|
}
|
2001-02-15 12:22:01 +00:00
|
|
|
Write(os, fragile);
|
2001-02-13 17:08:51 +00:00
|
|
|
os << "}\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathMacroTemplate::GetMacroXY(int i, int & x, int & y) const
|
|
|
|
{
|
|
|
|
args_[i].GetXY(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathParInset * MathMacroTemplate::getMacroPar(int i) const
|
|
|
|
{
|
2001-02-15 12:22:01 +00:00
|
|
|
if (i >= 0 && i < nargs_)
|
2001-02-13 17:08:51 +00:00
|
|
|
return const_cast<MathParInset *>
|
|
|
|
(static_cast<MathParInset const *>(&args_[i]));
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathMacroTemplate::SetMacroFocus(int &idx, int x, int y)
|
|
|
|
{
|
2001-02-15 12:22:01 +00:00
|
|
|
for (int i = 0; i < nargs_; ++i) {
|
2001-02-13 17:08:51 +00:00
|
|
|
if (args_[i].Inside(x, y)) {
|
|
|
|
idx = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|