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
|
|
|
|
*
|
|
|
|
* Copyright: (c) 1996, 1997 Alejandro Aguilar Sierra
|
|
|
|
*
|
|
|
|
* 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__
|
|
|
|
#pragma implementation "math_macro.h"
|
|
|
|
#pragma implementation "math_defs.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "LString.h"
|
|
|
|
#include "math_macro.h"
|
|
|
|
#include "math_iter.h"
|
|
|
|
#include "math_inset.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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
extern GC mathGC, mathFrameGC, latexGC;
|
|
|
|
extern int mathed_string_width(short type, int style, byte const* s, int ls);
|
|
|
|
extern int mathed_string_height(short, int, byte const*, int, int&, int&);
|
|
|
|
|
|
|
|
|
|
|
|
MathMacro::MathMacro(MathMacroTemplate* t):
|
|
|
|
MathParInset(LM_ST_TEXT, "", LM_OT_MACRO), tmplate(t)
|
|
|
|
{
|
|
|
|
nargs = tmplate->getNoArgs();
|
|
|
|
tcode = tmplate->getTCode();
|
|
|
|
args = new MacroArgumentBase[nargs];
|
1999-12-07 00:44:53 +00:00
|
|
|
for (int i = 0; i < nargs; ++i) {
|
1999-09-27 18:44:28 +00:00
|
|
|
// if (tmplate->getMacroPar(i)->Permit(LMPF_ALLOW_CR))
|
|
|
|
// args[i].row = new MathedRowSt(tmplate->getMacroPar(i)->GetColumns());
|
|
|
|
// else
|
|
|
|
args[i].row = 0;
|
|
|
|
/* int k = tmplate->getMacroPar(i)->GetColumns();
|
|
|
|
if (k>0) {
|
|
|
|
args[i].array = new LyxArrayBase;
|
2000-01-24 18:34:46 +00:00
|
|
|
for (int j= 0; j<k-1; ++j) args[i].array->Insert(j, LM_TC_TAB);
|
1999-09-27 18:44:28 +00:00
|
|
|
}*/
|
|
|
|
}
|
|
|
|
idx = 0;
|
|
|
|
SetName(tmplate->GetName());
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
tmplate = m->tmplate;
|
|
|
|
nargs = tmplate->getNoArgs();
|
|
|
|
tcode = tmplate->getTCode();
|
|
|
|
args = new MacroArgumentBase[nargs];
|
|
|
|
idx = 0;
|
|
|
|
SetName(tmplate->GetName());
|
1999-12-07 00:44:53 +00:00
|
|
|
for (int i = 0; i < tmplate->nargs; ++i) {
|
1999-09-27 18:44:28 +00:00
|
|
|
m->setArgumentIdx(i);
|
|
|
|
MathedIter it(m->GetData());
|
|
|
|
args[i].row = m->args[i].row;
|
|
|
|
args[i].array = it.Copy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MathMacro::~MathMacro()
|
|
|
|
{
|
1999-12-07 00:44:53 +00:00
|
|
|
for (idx = 0; idx < nargs; ++idx) {
|
1999-09-27 18:44:28 +00:00
|
|
|
MathedIter it(args[idx].array);
|
|
|
|
it. Clear();
|
|
|
|
delete args[idx].row;
|
|
|
|
}
|
|
|
|
delete[] args;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
tmplate->Metrics();
|
|
|
|
width = tmplate->Width();
|
|
|
|
ascent = tmplate->Ascent();
|
|
|
|
descent = tmplate->Descent();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathMacro::Draw(int x, int y)
|
|
|
|
{
|
|
|
|
xo = x; yo = y;
|
|
|
|
Metrics();
|
|
|
|
tmplate->update(this);
|
|
|
|
tmplate->SetStyle(size);
|
|
|
|
mathGC = latexGC;
|
|
|
|
tmplate->Draw(x, y);
|
1999-12-07 00:44:53 +00:00
|
|
|
for (int i = 0; i < nargs; ++i)
|
1999-09-27 18:44:28 +00:00
|
|
|
tmplate->GetMacroXY(i, args[i].x, args[i].y);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MathMacro::GetColumns()
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
|
|
|
x = args[idx].x; y = args[idx].y;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathMacro::Permit(short f)
|
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
void MathMacro::Write(ostream & os)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
string output;
|
1999-09-27 18:44:28 +00:00
|
|
|
MathMacro::Write(output);
|
1999-12-07 00:44:53 +00:00
|
|
|
os << output;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
void MathMacro::Write(string &file)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
if (tmplate->flags & MMF_Exp) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::MATHED] << "Expand " << tmplate->flags
|
|
|
|
<< ' ' << MMF_Exp << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
tmplate->update(this);
|
|
|
|
tmplate->Write(file);
|
|
|
|
} else {
|
|
|
|
if (tmplate->flags & MMF_Env) {
|
|
|
|
file += "\\begin{";
|
|
|
|
file += name;
|
|
|
|
file += "} ";
|
|
|
|
} else {
|
|
|
|
file += '\\';
|
|
|
|
file += name;
|
|
|
|
}
|
|
|
|
// if (options) {
|
|
|
|
// file += '[';
|
|
|
|
// file += options;
|
|
|
|
// file += ']';
|
|
|
|
// }
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
if (!(tmplate->flags & MMF_Env) && nargs > 0)
|
1999-09-27 18:44:28 +00:00
|
|
|
file += '{';
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
for (int i = 0; i < nargs; ++i) {
|
1999-09-27 18:44:28 +00:00
|
|
|
array = args[i].array;
|
|
|
|
MathParInset::Write(file);
|
1999-12-07 00:44:53 +00:00
|
|
|
if (i < nargs - 1)
|
1999-09-27 18:44:28 +00:00
|
|
|
file += "}{";
|
|
|
|
}
|
|
|
|
if (tmplate->flags & MMF_Env) {
|
|
|
|
file += "\\end{";
|
|
|
|
file += name;
|
|
|
|
file += '}';
|
|
|
|
} else {
|
1999-12-07 00:44:53 +00:00
|
|
|
if (nargs > 0)
|
1999-09-27 18:44:28 +00:00
|
|
|
file += '}';
|
|
|
|
else
|
|
|
|
file += ' ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*--------------- Macro argument -----------------------------------*/
|
|
|
|
|
|
|
|
MathMacroArgument::MathMacroArgument(int n)
|
|
|
|
{
|
|
|
|
number = n;
|
|
|
|
expnd_mode = false;
|
|
|
|
SetType(LM_OT_MACRO_ARG);
|
|
|
|
}
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
void MathMacroArgument::Draw(int x, int baseline)
|
|
|
|
{
|
|
|
|
if (expnd_mode) {
|
|
|
|
MathParInset::Draw(x, baseline);
|
|
|
|
} else {
|
|
|
|
unsigned char s[3];
|
1999-12-13 00:05:34 +00:00
|
|
|
sprintf(reinterpret_cast<char*>(s), "#%d", number);
|
1999-09-27 18:44:28 +00:00
|
|
|
drawStr(LM_TC_TEX, size, x, baseline, &s[0], 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathMacroArgument::Metrics()
|
|
|
|
{
|
|
|
|
if (expnd_mode) {
|
|
|
|
MathParInset::Metrics();
|
|
|
|
} else {
|
|
|
|
unsigned char s[3];
|
1999-12-13 00:05:34 +00:00
|
|
|
sprintf(reinterpret_cast<char*>(s), "#%d", number);
|
1999-09-27 18:44:28 +00:00
|
|
|
width = mathed_string_width(LM_TC_TEX, size, &s[0], 2);
|
|
|
|
mathed_string_height(LM_TC_TEX, size, &s[0], 2, ascent, descent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
|
|
|
void MathMacroArgument::Write(ostream & os)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
string output;
|
1999-09-27 18:44:28 +00:00
|
|
|
MathMacroArgument::Write(output);
|
1999-12-07 00:44:53 +00:00
|
|
|
os << output;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
|
|
|
void MathMacroArgument::Write(string & file)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
if (expnd_mode) {
|
|
|
|
MathParInset::Write(file);
|
|
|
|
} else {
|
|
|
|
file += '#';
|
1999-10-19 16:11:58 +00:00
|
|
|
file += tostr(number);
|
1999-09-27 18:44:28 +00:00
|
|
|
file += ' ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* --------------------- MathMacroTemplate ---------------------------*/
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
MathMacroTemplate::MathMacroTemplate(char 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)
|
|
|
|
{
|
2000-01-24 18:34:46 +00:00
|
|
|
if (nargs > 0) {
|
1999-09-27 18:44:28 +00:00
|
|
|
tcode = LM_TC_ACTIVE_INSET;
|
|
|
|
args = new MathMacroArgument[nargs];
|
2000-01-24 18:34:46 +00:00
|
|
|
for (int i = 0; i < nargs; ++i) {
|
|
|
|
args[i].setNumber(i + 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
tcode = LM_TC_INSET;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathMacroTemplate::~MathMacroTemplate()
|
|
|
|
{
|
|
|
|
// prevent to delete already deleted objects
|
2000-01-24 18:34:46 +00:00
|
|
|
for (int i = 0; i < nargs; ++i) {
|
1999-09-27 18:44:28 +00:00
|
|
|
args[i].SetData(0);
|
|
|
|
}
|
|
|
|
delete[] args;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathMacroTemplate::setEditMode(bool ed)
|
|
|
|
{
|
|
|
|
if (ed) {
|
|
|
|
flags |= MMF_Edit;
|
1999-12-07 00:44:53 +00:00
|
|
|
for (int i = 0; i < nargs; ++i) {
|
1999-09-27 18:44:28 +00:00
|
|
|
args[i].setExpand(false);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
flags &= ~MMF_Edit;
|
1999-12-07 00:44:53 +00:00
|
|
|
for (int i = 0; i < nargs; ++i) {
|
1999-09-27 18:44:28 +00:00
|
|
|
args[i].setExpand(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathMacroTemplate::Draw(int x, int y)
|
|
|
|
{
|
|
|
|
int x2, y2;
|
|
|
|
bool expnd = (nargs>0) ? args[0].getExpand(): false;
|
|
|
|
if (flags & MMF_Edit) {
|
1999-12-07 00:44:53 +00:00
|
|
|
for (int i = 0; i < nargs; ++i) {
|
1999-09-27 18:44:28 +00:00
|
|
|
args[i].setExpand(false);
|
|
|
|
}
|
|
|
|
x2 = x; y2 = y;
|
|
|
|
} else {
|
1999-12-07 00:44:53 +00:00
|
|
|
for (int i = 0; i < nargs; ++i) {
|
1999-09-27 18:44:28 +00:00
|
|
|
args[i].setExpand(true);
|
|
|
|
}
|
|
|
|
x2 = xo; y2 = yo;
|
|
|
|
}
|
|
|
|
MathParInset::Draw(x, y);
|
|
|
|
xo = x2; yo = y2;
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
for (int i = 0; i < nargs; ++i) {
|
1999-09-27 18:44:28 +00:00
|
|
|
args[i].setExpand(expnd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
void MathMacroTemplate::Metrics()
|
|
|
|
{
|
|
|
|
bool expnd = (nargs>0) ? args[0].getExpand(): false;
|
|
|
|
|
|
|
|
if (flags & MMF_Edit) {
|
2000-01-24 18:34:46 +00:00
|
|
|
for (int i = 0; i < nargs; ++i) {
|
1999-09-27 18:44:28 +00:00
|
|
|
args[i].setExpand(false);
|
|
|
|
}
|
|
|
|
} else {
|
2000-01-24 18:34:46 +00:00
|
|
|
for (int i = 0; i < nargs; ++i) {
|
1999-09-27 18:44:28 +00:00
|
|
|
args[i].setExpand(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MathParInset::Metrics();
|
|
|
|
|
2000-01-24 18:34:46 +00:00
|
|
|
for (int i = 0; i < nargs; ++i) {
|
1999-09-27 18:44:28 +00:00
|
|
|
args[i].setExpand(expnd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
|
|
|
void MathMacroTemplate::update(MathMacro * macro)
|
1999-09-27 18:44:28 +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);
|
|
|
|
args[i].SetData(macro->GetData());
|
|
|
|
MathedRowSt *row = macro->getRowSt();
|
|
|
|
args[i].setRowSt(row);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (macro)
|
|
|
|
macro->setArgumentIdx(idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
void MathMacroTemplate::WriteDef(ostream & os)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-12-07 00:44:53 +00:00
|
|
|
os << "\n\\newcommand{\\" << name << "}";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (nargs > 0 )
|
1999-12-07 00:44:53 +00:00
|
|
|
os << "[" << nargs << "]";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
os << "{";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
for (int i = 0; i < nargs; ++i) {
|
1999-09-27 18:44:28 +00:00
|
|
|
args[i].setExpand(false);
|
|
|
|
}
|
1999-12-07 00:44:53 +00:00
|
|
|
Write(os);
|
|
|
|
os << "}\n";
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
void MathMacroTemplate::WriteDef(string &file)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
file += "\n\\newcommand{\\";
|
|
|
|
file += name;
|
|
|
|
file += '}';
|
|
|
|
|
|
|
|
if (nargs > 0 ) {
|
|
|
|
file += '[';
|
1999-10-19 16:11:58 +00:00
|
|
|
file += tostr(nargs);
|
1999-09-27 18:44:28 +00:00
|
|
|
file += ']';
|
|
|
|
}
|
|
|
|
|
|
|
|
file += '{';
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
for (int i = 0; i < nargs; ++i) {
|
1999-09-27 18:44:28 +00:00
|
|
|
args[i].setExpand(false);
|
|
|
|
}
|
|
|
|
Write(file);
|
|
|
|
file += "}\n";
|
|
|
|
}
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
|
|
|
void MathMacroTemplate::setArgument(LyxArrayBase * a, int i)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
args[i].SetData(a);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
args[i].GetXY(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
MathParInset * MathMacroTemplate::getMacroPar(int i) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-12-13 00:05:34 +00:00
|
|
|
return (i >= 0 && i < nargs) ? static_cast<MathParInset*>(&args[i]) : 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathMacroTemplate::SetMacroFocus(int &idx, int x, int y)
|
|
|
|
{
|
1999-12-07 00:44:53 +00:00
|
|
|
for (int i = 0; i < nargs; ++i) {
|
1999-09-27 18:44:28 +00:00
|
|
|
if (args[i].Inside(x, y)) {
|
|
|
|
idx = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* -------------------------- MathMacroTable -----------------------*/
|
|
|
|
|
|
|
|
MathMacroTable::MathMacroTable(int n): max_macros(n)
|
|
|
|
{
|
|
|
|
macro_table = new MathMacroTemplateP[max_macros];
|
|
|
|
num_macros = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathMacroTable::~MathMacroTable()
|
|
|
|
{
|
|
|
|
delete[] macro_table;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// The search is currently linear but will be binary or hash, later.
|
1999-12-07 00:44:53 +00:00
|
|
|
MathMacroTemplate * MathMacroTable::getTemplate(char const * name) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-12-07 00:44:53 +00:00
|
|
|
for (int i = 0; i < num_macros; ++i) {
|
1999-11-15 11:06:41 +00:00
|
|
|
if (strcmp(name, macro_table[i]->GetName()) == 0)
|
1999-09-27 18:44:28 +00:00
|
|
|
return macro_table[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
void MathMacroTable::addTemplate(MathMacroTemplate * m)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-12-07 00:44:53 +00:00
|
|
|
if (num_macros < max_macros)
|
1999-09-27 18:44:28 +00:00
|
|
|
macro_table[num_macros++] = m;
|
|
|
|
else
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "Error (MathMacroTable::addTemplate): "
|
|
|
|
"Macro table exhausted!" << endl;
|
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;
|
|
|
|
LyxArrayBase * 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);
|
1999-12-07 00:44:53 +00:00
|
|
|
LyxArrayBase * array = new LyxArrayBase; // 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);
|
|
|
|
array = new LyxArrayBase; // this leaks
|
|
|
|
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);
|
|
|
|
array = new LyxArrayBase; // this leaks
|
|
|
|
iter.SetData(array);
|
|
|
|
iter.Insert(LM_bot, LM_TC_BOP);
|
|
|
|
m->SetData(array);
|
|
|
|
|
|
|
|
// binom has two arguments
|
|
|
|
m = new MathMacroTemplate("binom", 2);
|
|
|
|
addTemplate(m);
|
|
|
|
array = new LyxArrayBase;
|
|
|
|
m->SetData(array);
|
|
|
|
iter.SetData(array);
|
|
|
|
inset = new MathDelimInset('(', ')');
|
|
|
|
iter.Insert(inset, LM_TC_ACTIVE_INSET);
|
|
|
|
array = new LyxArrayBase;
|
|
|
|
iter.SetData(array);
|
|
|
|
MathFracInset *frac = new MathFracInset(LM_OT_ATOP);
|
|
|
|
iter.Insert(frac, LM_TC_ACTIVE_INSET);
|
|
|
|
inset->SetData(array);
|
|
|
|
array = new LyxArrayBase;
|
|
|
|
array2 = new LyxArrayBase;
|
|
|
|
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);
|
|
|
|
array = new LyxArrayBase; // this leaks
|
|
|
|
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);
|
|
|
|
array = new LyxArrayBase; // this leaks
|
|
|
|
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);
|
|
|
|
array = new LyxArrayBase; // this leaks
|
|
|
|
iter.SetData(array);
|
|
|
|
iter.Insert(arg, LM_TC_ACTIVE_INSET);
|
|
|
|
m->SetData(array);*/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathMacroTable MathMacroTable::mathMTable(255);
|
1999-12-07 00:44:53 +00:00
|
|
|
bool MathMacroTable::built = false;
|