1999-09-27 18:44:28 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/*
|
|
|
|
* File: math_macro.C
|
|
|
|
* Purpose: Implementation of macro class for mathed
|
|
|
|
* Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
|
|
|
|
* Created: November 1996
|
|
|
|
* Description: WYSIWYG math macros
|
|
|
|
*
|
|
|
|
* Dependencies: Mathed
|
|
|
|
*
|
2000-03-09 03:36:48 +00:00
|
|
|
* Copyright: 1996, 1997 Alejandro Aguilar Sierra
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
|
|
|
* Version: 0.2, Mathed & Lyx project.
|
|
|
|
*
|
|
|
|
* This code is under the GNU General Public Licence version 2 or later.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include FORMS_H_LOCATION
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
2001-02-13 13:28:32 +00:00
|
|
|
#pragma implementation
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "LString.h"
|
|
|
|
#include "math_macro.h"
|
2001-02-13 13:28:32 +00:00
|
|
|
#include "array.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "math_iter.h"
|
|
|
|
#include "math_inset.h"
|
2001-02-13 13:28:32 +00:00
|
|
|
#include "math_accentinset.h"
|
|
|
|
#include "math_deliminset.h"
|
|
|
|
#include "math_fracinset.h"
|
|
|
|
#include "math_rowst.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/lstrings.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
using std::ostream;
|
2000-03-28 02:18:55 +00:00
|
|
|
using std::endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-10-07 18:44:17 +00:00
|
|
|
ostream & operator<<(ostream & o, MathedTextCodes mtc)
|
|
|
|
{
|
|
|
|
return o << int(mtc);
|
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
enum MathedMacroFlag {
|
1999-11-15 11:06:41 +00:00
|
|
|
MMF_Env= 1,
|
|
|
|
MMF_Exp= 2,
|
|
|
|
MMF_Edit= 4
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
1999-10-07 18:44:17 +00:00
|
|
|
ostream & operator<<(ostream & o, MathedMacroFlag mmf)
|
|
|
|
{
|
|
|
|
return o << int(mmf);
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-02-08 15:09:15 +00:00
|
|
|
extern int mathed_string_width(short type, int style, string const & s);
|
|
|
|
extern int mathed_string_height(short, int, string const &, int &, int &);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
MathMacro::MathMacro(MathMacroTemplate* t):
|
|
|
|
MathParInset(LM_ST_TEXT, "", LM_OT_MACRO), tmplate(t)
|
|
|
|
{
|
2001-02-12 15:55:40 +00:00
|
|
|
nargs = tmplate->getNoArgs();
|
|
|
|
tcode = tmplate->getTCode();
|
|
|
|
args_.resize(nargs);
|
|
|
|
for (int i = 0; i < nargs; ++i) {
|
|
|
|
args_[i].row = 0;
|
|
|
|
}
|
|
|
|
idx = 0;
|
|
|
|
SetName(tmplate->GetName());
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
|
|
|
MathMacro::MathMacro(MathMacro * m):
|
1999-09-27 18:44:28 +00:00
|
|
|
MathParInset(LM_ST_TEXT, m->GetName(), LM_OT_MACRO)
|
|
|
|
{
|
2001-02-12 15:55:40 +00:00
|
|
|
tmplate = m->tmplate;
|
|
|
|
nargs = tmplate->getNoArgs();
|
|
|
|
tcode = tmplate->getTCode();
|
|
|
|
args_.resize(nargs);
|
|
|
|
idx = 0;
|
|
|
|
SetName(tmplate->GetName());
|
|
|
|
for (int i = 0; i < tmplate->nargs; ++i) {
|
|
|
|
m->setArgumentIdx(i);
|
|
|
|
MathedIter it(m->GetData());
|
|
|
|
args_[i].row = m->args_[i].row;
|
|
|
|
args_[i].array = it.Copy();
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MathMacro::~MathMacro()
|
|
|
|
{
|
2001-02-12 15:55:40 +00:00
|
|
|
for (idx = 0; idx < nargs; ++idx) {
|
|
|
|
MathedIter it(args_[idx].array);
|
|
|
|
it.Clear();
|
|
|
|
delete args_[idx].row;
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-25 13:15:52 +00:00
|
|
|
MathedInset * MathMacro::Clone()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-23 14:39:02 +00:00
|
|
|
return new MathMacro(this);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathMacro::Metrics()
|
|
|
|
{
|
1999-12-07 00:44:53 +00:00
|
|
|
if (nargs > 0)
|
1999-09-27 18:44:28 +00:00
|
|
|
tmplate->update(this);
|
2000-09-05 14:15:09 +00:00
|
|
|
tmplate->SetStyle(size);
|
1999-09-27 18:44:28 +00:00
|
|
|
tmplate->Metrics();
|
|
|
|
width = tmplate->Width();
|
|
|
|
ascent = tmplate->Ascent();
|
|
|
|
descent = tmplate->Descent();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
void MathMacro::draw(Painter & pain, int x, int y)
|
|
|
|
{
|
|
|
|
xo = x; yo = y;
|
|
|
|
Metrics();
|
|
|
|
tmplate->update(this);
|
|
|
|
tmplate->SetStyle(size);
|
|
|
|
tmplate->draw(pain, x, y);
|
2000-09-29 18:44:07 +00:00
|
|
|
for (int i = 0; i < nargs; ++i) {
|
2001-02-12 15:55:40 +00:00
|
|
|
tmplate->GetMacroXY(i, args_[i].x, args_[i].y);
|
2000-09-29 18:44:07 +00:00
|
|
|
}
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2000-09-29 18:44:07 +00:00
|
|
|
int MathMacro::GetColumns() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
return tmplate->getMacroPar(idx)->GetColumns();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
void MathMacro::GetXY(int & x, int & y) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-02-12 15:55:40 +00:00
|
|
|
x = args_[idx].x; y = args_[idx].y;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-12 15:55:40 +00:00
|
|
|
bool MathMacro::Permit(short f) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-12-07 00:44:53 +00:00
|
|
|
return (nargs > 0) ?
|
|
|
|
tmplate->getMacroPar(idx)->Permit(f) : MathParInset::Permit(f);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
void MathMacro::SetFocus(int x, int y)
|
|
|
|
{
|
|
|
|
tmplate->update(this);
|
|
|
|
tmplate->SetMacroFocus(idx, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-19 01:42:55 +00:00
|
|
|
void MathMacro::Write(ostream & os, bool fragile)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-03-07 01:14:37 +00:00
|
|
|
if (tmplate->flags & MMF_Exp) {
|
|
|
|
lyxerr[Debug::MATHED] << "Expand " << tmplate->flags
|
|
|
|
<< ' ' << MMF_Exp << endl;
|
|
|
|
tmplate->update(this);
|
2000-04-17 14:00:18 +00:00
|
|
|
tmplate->Write(os, fragile);
|
2000-03-07 01:14:37 +00:00
|
|
|
} else {
|
|
|
|
if (tmplate->flags & MMF_Env) {
|
|
|
|
os << "\\begin{"
|
|
|
|
<< name
|
|
|
|
<< "} ";
|
|
|
|
} else {
|
|
|
|
os << '\\' << name;
|
|
|
|
}
|
|
|
|
// if (options) {
|
|
|
|
// file += '[';
|
|
|
|
// file += options;
|
|
|
|
// file += ']';
|
|
|
|
// }
|
|
|
|
|
|
|
|
if (!(tmplate->flags & MMF_Env) && nargs > 0)
|
|
|
|
os << '{';
|
|
|
|
|
|
|
|
for (int i = 0; i < nargs; ++i) {
|
2001-02-12 15:55:40 +00:00
|
|
|
array = args_[i].array;
|
2000-04-17 14:00:18 +00:00
|
|
|
MathParInset::Write(os, fragile);
|
2000-03-07 01:14:37 +00:00
|
|
|
if (i < nargs - 1)
|
|
|
|
os << "}{";
|
|
|
|
}
|
|
|
|
if (tmplate->flags & MMF_Env) {
|
|
|
|
os << "\\end{"
|
|
|
|
<< name
|
|
|
|
<< '}';
|
|
|
|
} else {
|
|
|
|
if (nargs > 0)
|
|
|
|
os << '}';
|
|
|
|
else
|
|
|
|
os << ' ';
|
|
|
|
}
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*--------------- Macro argument -----------------------------------*/
|
|
|
|
|
|
|
|
MathMacroArgument::MathMacroArgument(int n)
|
|
|
|
{
|
|
|
|
number = n;
|
|
|
|
expnd_mode = false;
|
|
|
|
SetType(LM_OT_MACRO_ARG);
|
|
|
|
}
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
void MathMacroArgument::draw(Painter & pain, int x, int baseline)
|
|
|
|
{
|
2001-02-08 15:09:15 +00:00
|
|
|
if (expnd_mode) {
|
|
|
|
MathParInset::draw(pain, x, baseline);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
std::ostringstream ost;
|
|
|
|
ost << '#' << number;
|
2001-02-08 15:59:42 +00:00
|
|
|
drawStr(pain, LM_TC_TEX, size, x, baseline, ost.str().c_str());
|
2001-02-08 15:09:15 +00:00
|
|
|
}
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
void MathMacroArgument::Metrics()
|
|
|
|
{
|
2001-02-08 15:09:15 +00:00
|
|
|
if (expnd_mode) {
|
|
|
|
MathParInset::Metrics();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
std::ostringstream ost;
|
|
|
|
ost << '#' << number;
|
2001-02-08 15:59:42 +00:00
|
|
|
width = mathed_string_width(LM_TC_TEX, size, ost.str().c_str());
|
|
|
|
mathed_string_height(LM_TC_TEX, size, ost.str().c_str(),
|
|
|
|
ascent, descent);
|
2001-02-08 15:09:15 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
2000-04-19 01:42:55 +00:00
|
|
|
void MathMacroArgument::Write(ostream & os, bool fragile)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-03-07 01:14:37 +00:00
|
|
|
if (expnd_mode) {
|
2000-04-17 14:00:18 +00:00
|
|
|
MathParInset::Write(os, fragile);
|
2000-03-07 01:14:37 +00:00
|
|
|
} else {
|
|
|
|
os << '#' << number << ' ';
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
/* --------------------- MathMacroTemplate ---------------------------*/
|
|
|
|
|
2000-09-26 13:54:57 +00:00
|
|
|
MathMacroTemplate::MathMacroTemplate(string const & nm, int na, int flg):
|
1999-09-27 18:44:28 +00:00
|
|
|
MathParInset(LM_ST_TEXT, nm, LM_OT_MACRO),
|
|
|
|
flags(flg), nargs(na)
|
|
|
|
{
|
2001-02-12 15:55:40 +00:00
|
|
|
if (nargs > 0) {
|
|
|
|
tcode = LM_TC_ACTIVE_INSET;
|
|
|
|
args_.resize(nargs);
|
|
|
|
for (int i = 0; i < nargs; ++i) {
|
|
|
|
args_[i].setNumber(i + 1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
tcode = LM_TC_INSET;
|
|
|
|
// Here is nargs != args_.size()
|
|
|
|
//args = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathMacroTemplate::~MathMacroTemplate()
|
|
|
|
{
|
2001-02-12 15:55:40 +00:00
|
|
|
// prevent to delete already deleted objects
|
|
|
|
for (int i = 0; i < nargs; ++i) {
|
|
|
|
args_[i].SetData(0);
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathMacroTemplate::setEditMode(bool ed)
|
|
|
|
{
|
2001-02-12 15:55:40 +00:00
|
|
|
if (ed) {
|
|
|
|
flags |= MMF_Edit;
|
|
|
|
for (int i = 0; i < nargs; ++i) {
|
|
|
|
args_[i].setExpand(false);
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-02-12 15:55:40 +00:00
|
|
|
else {
|
|
|
|
flags &= ~MMF_Edit;
|
|
|
|
for (int i = 0; i < nargs; ++i) {
|
|
|
|
args_[i].setExpand(true);
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
void MathMacroTemplate::draw(Painter & pain, int x, int y)
|
|
|
|
{
|
2001-02-12 15:55:40 +00:00
|
|
|
int x2, y2;
|
|
|
|
bool expnd = (nargs > 0) ? args_[0].getExpand(): false;
|
|
|
|
if (flags & MMF_Edit) {
|
|
|
|
for (int i = 0; i < nargs; ++i) {
|
|
|
|
args_[i].setExpand(false);
|
|
|
|
}
|
|
|
|
x2 = x; y2 = y;
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < nargs; ++i) {
|
|
|
|
args_[i].setExpand(true);
|
|
|
|
}
|
|
|
|
x2 = xo; y2 = yo;
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
2001-02-12 15:55:40 +00:00
|
|
|
MathParInset::draw(pain, x, y);
|
|
|
|
xo = x2; yo = y2;
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
for (int i = 0; i < nargs; ++i) {
|
2001-02-12 15:55:40 +00:00
|
|
|
args_[i].setExpand(expnd);
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
void MathMacroTemplate::Metrics()
|
|
|
|
{
|
2001-02-12 15:55:40 +00:00
|
|
|
bool expnd = (nargs > 0) ? args_[0].getExpand(): false;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (flags & MMF_Edit) {
|
2000-01-24 18:34:46 +00:00
|
|
|
for (int i = 0; i < nargs; ++i) {
|
2001-02-12 15:55:40 +00:00
|
|
|
args_[i].setExpand(false);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
} else {
|
2000-01-24 18:34:46 +00:00
|
|
|
for (int i = 0; i < nargs; ++i) {
|
2001-02-12 15:55:40 +00:00
|
|
|
args_[i].setExpand(true);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
MathParInset::Metrics();
|
|
|
|
|
2000-01-24 18:34:46 +00:00
|
|
|
for (int i = 0; i < nargs; ++i) {
|
2001-02-12 15:55:40 +00:00
|
|
|
args_[i].setExpand(expnd);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
|
|
|
void MathMacroTemplate::update(MathMacro * macro)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-09-29 18:44:07 +00:00
|
|
|
int idx = (macro) ? macro->getArgumentIdx() : 0;
|
2000-01-24 18:34:46 +00:00
|
|
|
for (int i = 0; i < nargs; ++i) {
|
1999-09-27 18:44:28 +00:00
|
|
|
if (macro) {
|
|
|
|
macro->setArgumentIdx(i);
|
2001-02-12 15:55:40 +00:00
|
|
|
args_[i].SetData(macro->GetData());
|
2000-09-29 18:44:07 +00:00
|
|
|
MathedRowSt * row = macro->getRowSt();
|
2001-02-12 15:55:40 +00:00
|
|
|
args_[i].setRowSt(row);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (macro)
|
|
|
|
macro->setArgumentIdx(idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-19 01:42:55 +00:00
|
|
|
void MathMacroTemplate::WriteDef(ostream & os, bool fragile)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-12-07 00:44:53 +00:00
|
|
|
os << "\n\\newcommand{\\" << name << "}";
|
2001-02-12 15:55:40 +00:00
|
|
|
|
|
|
|
if (nargs > 0 )
|
|
|
|
os << "[" << nargs << "]";
|
|
|
|
|
|
|
|
os << "{";
|
|
|
|
|
|
|
|
for (int i = 0; i < nargs; ++i) {
|
|
|
|
args_[i].setExpand(false);
|
|
|
|
}
|
|
|
|
Write(os, fragile);
|
|
|
|
os << "}\n";
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
2001-02-12 08:55:14 +00:00
|
|
|
void MathMacroTemplate::setArgument(MathedArray * a, int i)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-02-12 15:55:40 +00:00
|
|
|
args_[i].SetData(a);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
|
|
|
void MathMacroTemplate::GetMacroXY(int i, int & x, int & y) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-02-12 15:55:40 +00:00
|
|
|
args_[i].GetXY(x, y);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
MathParInset * MathMacroTemplate::getMacroPar(int i) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-02-12 15:55:40 +00:00
|
|
|
if (i >= 0 && i < nargs)
|
|
|
|
return const_cast<MathParInset *>
|
|
|
|
(static_cast<MathParInset const *>(&args_[i]));
|
|
|
|
else
|
|
|
|
return 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathMacroTemplate::SetMacroFocus(int &idx, int x, int y)
|
|
|
|
{
|
2001-02-12 15:55:40 +00:00
|
|
|
for (int i = 0; i < nargs; ++i) {
|
|
|
|
if (args_[i].Inside(x, y)) {
|
|
|
|
idx = i;
|
|
|
|
break;
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* -------------------------- MathMacroTable -----------------------*/
|
|
|
|
|
|
|
|
// The search is currently linear but will be binary or hash, later.
|
2000-09-14 17:53:12 +00:00
|
|
|
MathMacroTemplate * MathMacroTable::getTemplate(string const & name) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-02-13 15:27:03 +00:00
|
|
|
for (size_type i = 0; i < macro_table.size(); ++i) {
|
|
|
|
if (name == macro_table[i]->GetName())
|
|
|
|
return macro_table[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
void MathMacroTable::addTemplate(MathMacroTemplate * m)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-02-13 15:27:03 +00:00
|
|
|
macro_table.push_back(m);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// All this stuff aparently leaks because it's created here and is not
|
|
|
|
// deleted never, but it have to live all the LyX sesion. OK, would not
|
|
|
|
// so hard to do it in the MacroTable destructor, but this doesn't harm
|
|
|
|
// seriously, so don't bother me with purify results here. ;-)
|
|
|
|
|
|
|
|
void MathMacroTable::builtinMacros()
|
|
|
|
{
|
|
|
|
MathedIter iter;
|
1999-12-07 00:44:53 +00:00
|
|
|
MathParInset * inset;// *arg;
|
2001-02-12 08:55:14 +00:00
|
|
|
MathedArray * array2;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
built = true;
|
|
|
|
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::MATHED] << "Building macros" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// This macro doesn't have arguments
|
1999-12-07 00:44:53 +00:00
|
|
|
MathMacroTemplate * m = new MathMacroTemplate("notin"); // this leaks
|
1999-09-27 18:44:28 +00:00
|
|
|
addTemplate(m);
|
2001-02-12 08:55:14 +00:00
|
|
|
MathedArray * array = new MathedArray; // this leaks
|
1999-09-27 18:44:28 +00:00
|
|
|
iter.SetData(array);
|
|
|
|
iter.Insert(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not)); // this leaks
|
|
|
|
m->SetData(array);
|
|
|
|
|
|
|
|
// These two are only while we are still with LyX 2.x
|
|
|
|
m = new MathMacroTemplate("emptyset"); // this leaks
|
|
|
|
addTemplate(m);
|
2001-02-12 08:55:14 +00:00
|
|
|
array = new MathedArray; // this leaks
|
1999-09-27 18:44:28 +00:00
|
|
|
iter.SetData(array);
|
|
|
|
iter.Insert(new MathAccentInset('O', LM_TC_RM, LM_not)); // this leaks
|
|
|
|
m->SetData(array);
|
|
|
|
|
|
|
|
m = new MathMacroTemplate("perp"); // this leaks
|
|
|
|
addTemplate(m);
|
2001-02-12 08:55:14 +00:00
|
|
|
array = new MathedArray; // this leaks
|
1999-09-27 18:44:28 +00:00
|
|
|
iter.SetData(array);
|
|
|
|
iter.Insert(LM_bot, LM_TC_BOP);
|
|
|
|
m->SetData(array);
|
|
|
|
|
|
|
|
// binom has two arguments
|
|
|
|
m = new MathMacroTemplate("binom", 2);
|
|
|
|
addTemplate(m);
|
2001-02-12 08:55:14 +00:00
|
|
|
array = new MathedArray;
|
1999-09-27 18:44:28 +00:00
|
|
|
m->SetData(array);
|
|
|
|
iter.SetData(array);
|
|
|
|
inset = new MathDelimInset('(', ')');
|
|
|
|
iter.Insert(inset, LM_TC_ACTIVE_INSET);
|
2001-02-12 08:55:14 +00:00
|
|
|
array = new MathedArray;
|
1999-09-27 18:44:28 +00:00
|
|
|
iter.SetData(array);
|
2001-02-13 13:28:32 +00:00
|
|
|
MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
|
1999-09-27 18:44:28 +00:00
|
|
|
iter.Insert(frac, LM_TC_ACTIVE_INSET);
|
|
|
|
inset->SetData(array);
|
2001-02-12 08:55:14 +00:00
|
|
|
array = new MathedArray;
|
|
|
|
array2 = new MathedArray;
|
1999-09-27 18:44:28 +00:00
|
|
|
iter.SetData(array);
|
|
|
|
iter.Insert(m->getMacroPar(0));
|
|
|
|
iter.SetData(array2);
|
|
|
|
iter.Insert(m->getMacroPar(1));
|
|
|
|
frac->SetData(array, array2);
|
|
|
|
|
|
|
|
/*
|
|
|
|
// Cases has 1 argument
|
|
|
|
m = new MathMacroTemplate("cases", 1, MMF_Env); // this leaks
|
|
|
|
addTemplate(m);
|
2001-02-12 08:55:14 +00:00
|
|
|
array = new MathedArray; // this leaks
|
1999-09-27 18:44:28 +00:00
|
|
|
iter.SetData(array);
|
1999-11-15 11:06:41 +00:00
|
|
|
arg = new MathMatrixInset(2, 1); // this leaks
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
m->setArgument(arg);
|
1999-11-15 11:06:41 +00:00
|
|
|
arg->SetAlign('c', "ll");
|
1999-09-27 18:44:28 +00:00
|
|
|
iter.Insert(arg, LM_TC_ACTIVE_INSET);
|
|
|
|
inset = new MathDelimInset('{', '.'); // this leaks
|
|
|
|
inset->SetData(array);
|
2001-02-12 08:55:14 +00:00
|
|
|
array = new MathedArray; // this leaks
|
1999-09-27 18:44:28 +00:00
|
|
|
iter.SetData(array);
|
|
|
|
iter.Insert(inset, LM_TC_ACTIVE_INSET);
|
|
|
|
m->SetData(array);
|
|
|
|
|
|
|
|
|
|
|
|
// the environment substack has 1 argument
|
|
|
|
m = new MathMacroTemplate("substack", 1, MMF_Env); // this leaks
|
|
|
|
addTemplate(m);
|
1999-11-15 11:06:41 +00:00
|
|
|
arg = new MathMatrixInset(1, 1); // this leaks
|
1999-09-27 18:44:28 +00:00
|
|
|
m->setArgument(arg);
|
|
|
|
arg->SetType(LM_OT_MACRO);
|
2001-02-12 08:55:14 +00:00
|
|
|
array = new MathedArray; // this leaks
|
1999-09-27 18:44:28 +00:00
|
|
|
iter.SetData(array);
|
|
|
|
iter.Insert(arg, LM_TC_ACTIVE_INSET);
|
|
|
|
m->SetData(array);*/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-13 15:27:03 +00:00
|
|
|
MathMacroTable MathMacroTable::mathMTable;
|
1999-12-07 00:44:53 +00:00
|
|
|
bool MathMacroTable::built = false;
|