nargs = tmplate->getNoArgs();
tcode = tmplate->getTCode();
args = new MacroArgumentBase[nargs];
- for (int i= 0; i<nargs; i++) {
+ for (int i = 0; i < nargs; ++i) {
// if (tmplate->getMacroPar(i)->Permit(LMPF_ALLOW_CR))
// args[i].row = new MathedRowSt(tmplate->getMacroPar(i)->GetColumns());
// else
SetName(tmplate->GetName());
}
-MathMacro::MathMacro(MathMacro* m):
+
+MathMacro::MathMacro(MathMacro * m):
MathParInset(LM_ST_TEXT, m->GetName(), LM_OT_MACRO)
{
tmplate = m->tmplate;
args = new MacroArgumentBase[nargs];
idx = 0;
SetName(tmplate->GetName());
- for (int i= 0; i<tmplate->nargs; i++) {
+ for (int i = 0; i < tmplate->nargs; ++i) {
m->setArgumentIdx(i);
MathedIter it(m->GetData());
args[i].row = m->args[i].row;
MathMacro::~MathMacro()
{
- for (idx= 0; idx<nargs; idx++) {
+ for (idx = 0; idx < nargs; ++idx) {
MathedIter it(args[idx].array);
it. Clear();
delete args[idx].row;
MathedInset * MathMacro::Clone()
{
-#if 0
- MathMacro *m = new MathMacro(this);
- return m;
-#endif
return new MathMacro(this);
}
void MathMacro::Metrics()
{
- if (nargs>0)
+ if (nargs > 0)
tmplate->update(this);
tmplate->Metrics();
width = tmplate->Width();
tmplate->SetStyle(size);
mathGC = latexGC;
tmplate->Draw(x, y);
- for (int i= 0; i<nargs; i++)
+ for (int i = 0; i < nargs; ++i)
tmplate->GetMacroXY(i, args[i].x, args[i].y);
}
}
-void MathMacro::GetXY(int& x, int& y) const
+void MathMacro::GetXY(int & x, int & y) const
{
x = args[idx].x; y = args[idx].y;
}
bool MathMacro::Permit(short f)
{
- return ((nargs>0) ? tmplate->getMacroPar(idx)->Permit(f): MathParInset::Permit(f));
+ return (nargs > 0) ?
+ tmplate->getMacroPar(idx)->Permit(f) : MathParInset::Permit(f);
}
+
void MathMacro::SetFocus(int x, int y)
{
tmplate->update(this);
}
-void MathMacro::Write(FILE *file)
+void MathMacro::Write(ostream & os)
{
string output;
MathMacro::Write(output);
- fprintf(file, "%s", output.c_str());
+ os << output;
}
// file += ']';
// }
- if (!(tmplate->flags & MMF_Env) && nargs>0)
+ if (!(tmplate->flags & MMF_Env) && nargs > 0)
file += '{';
- for (int i= 0; i<nargs; i++) {
+ for (int i = 0; i < nargs; ++i) {
array = args[i].array;
MathParInset::Write(file);
- if (i<nargs-1)
+ if (i < nargs - 1)
file += "}{";
}
if (tmplate->flags & MMF_Env) {
file += name;
file += '}';
} else {
- if (nargs>0)
+ if (nargs > 0)
file += '}';
else
file += ' ';
SetType(LM_OT_MACRO_ARG);
}
+
void MathMacroArgument::Draw(int x, int baseline)
{
if (expnd_mode) {
}
}
-void MathMacroArgument::Write(FILE *file)
+
+void MathMacroArgument::Write(ostream & os)
{
string output;
MathMacroArgument::Write(output);
- fprintf(file, "%s", output.c_str());
+ os << output;
}
-void MathMacroArgument::Write(string &file)
+
+void MathMacroArgument::Write(string & file)
{
if (expnd_mode) {
MathParInset::Write(file);
/* --------------------- MathMacroTemplate ---------------------------*/
-MathMacroTemplate::MathMacroTemplate(char const *nm, int na, int flg):
+MathMacroTemplate::MathMacroTemplate(char const * nm, int na, int flg):
MathParInset(LM_ST_TEXT, nm, LM_OT_MACRO),
flags(flg), nargs(na)
{
{
if (ed) {
flags |= MMF_Edit;
- for (int i= 0; i<nargs; i++) {
+ for (int i = 0; i < nargs; ++i) {
args[i].setExpand(false);
}
} else {
flags &= ~MMF_Edit;
- for (int i= 0; i<nargs; i++) {
+ for (int i = 0; i < nargs; ++i) {
args[i].setExpand(true);
}
}
int x2, y2;
bool expnd = (nargs>0) ? args[0].getExpand(): false;
if (flags & MMF_Edit) {
- for (int i= 0; i<nargs; i++) {
+ for (int i = 0; i < nargs; ++i) {
args[i].setExpand(false);
}
x2 = x; y2 = y;
} else {
- for (int i= 0; i<nargs; i++) {
+ for (int i = 0; i < nargs; ++i) {
args[i].setExpand(true);
}
x2 = xo; y2 = yo;
MathParInset::Draw(x, y);
xo = x2; yo = y2;
- for (int i= 0; i<nargs; i++) {
+ for (int i = 0; i < nargs; ++i) {
args[i].setExpand(expnd);
}
}
+
void MathMacroTemplate::Metrics()
{
bool expnd = (nargs>0) ? args[0].getExpand(): false;
}
}
-void MathMacroTemplate::update(MathMacro* macro)
+
+void MathMacroTemplate::update(MathMacro * macro)
{
int idx = (macro) ? macro->getArgumentIdx(): 0;
for (int i= 0; i<nargs; i++) {
}
-void MathMacroTemplate::WriteDef(FILE *file)
+void MathMacroTemplate::WriteDef(ostream & os)
{
- fprintf(file, "\n\\newcommand{\\%s}", name);
+ os << "\n\\newcommand{\\" << name << "}";
if (nargs > 0 )
- fprintf(file, "[%d]", nargs);
+ os << "[" << nargs << "]";
- fprintf(file, "{");
+ os << "{";
- for (int i= 0; i<nargs; i++) {
+ for (int i = 0; i < nargs; ++i) {
args[i].setExpand(false);
}
- Write(file);
- fprintf(file, "}\n");
+ Write(os);
+ os << "}\n";
}
+
void MathMacroTemplate::WriteDef(string &file)
{
file += "\n\\newcommand{\\";
file += '{';
- for (int i= 0; i<nargs; i++) {
+ for (int i = 0; i < nargs; ++i) {
args[i].setExpand(false);
}
Write(file);
file += "}\n";
}
-void MathMacroTemplate::setArgument(LyxArrayBase *a, int i)
+
+void MathMacroTemplate::setArgument(LyxArrayBase * a, int i)
{
args[i].SetData(a);
}
-void MathMacroTemplate::GetMacroXY(int i, int& x, int& y) const
+
+void MathMacroTemplate::GetMacroXY(int i, int & x, int & y) const
{
args[i].GetXY(x, y);
}
-MathParInset *MathMacroTemplate::getMacroPar(int i) const
+MathParInset * MathMacroTemplate::getMacroPar(int i) const
{
- return ((i>= 0 && i<nargs) ? (MathParInset*)&args[i]: 0);
+ return (i >= 0 && i < nargs) ? (MathParInset*)&args[i] : 0;
}
void MathMacroTemplate::SetMacroFocus(int &idx, int x, int y)
{
- for (int i= 0; i<nargs; i++) {
+ for (int i = 0; i < nargs; ++i) {
if (args[i].Inside(x, y)) {
idx = i;
break;
// The search is currently linear but will be binary or hash, later.
-MathMacroTemplate *MathMacroTable::getTemplate(char const* name) const
+MathMacroTemplate * MathMacroTable::getTemplate(char const * name) const
{
- for (int i= 0; i<num_macros; i++) {
+ for (int i = 0; i < num_macros; ++i) {
if (strcmp(name, macro_table[i]->GetName()) == 0)
return macro_table[i];
}
return 0;
}
-void MathMacroTable::addTemplate(MathMacroTemplate *m)
+void MathMacroTable::addTemplate(MathMacroTemplate * m)
{
- if (num_macros<max_macros)
+ if (num_macros < max_macros)
macro_table[num_macros++] = m;
else
lyxerr << "Error (MathMacroTable::addTemplate): "
void MathMacroTable::builtinMacros()
{
- MathMacroTemplate *m;
MathedIter iter;
- MathParInset* inset;// *arg;
- LyxArrayBase *array, *array2;
+ MathParInset * inset;// *arg;
+ LyxArrayBase * array2;
built = true;
lyxerr[Debug::MATHED] << "Building macros" << endl;
// This macro doesn't have arguments
- m = new MathMacroTemplate("notin"); // this leaks
+ MathMacroTemplate * m = new MathMacroTemplate("notin"); // this leaks
addTemplate(m);
- array = new LyxArrayBase; // this leaks
+ LyxArrayBase * array = new LyxArrayBase; // this leaks
iter.SetData(array);
iter.Insert(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not)); // this leaks
m->SetData(array);
MathMacroTable MathMacroTable::mathMTable(255);
-bool MathMacroTable::built = false;
-
+bool MathMacroTable::built = false;