return o << int(mmf);
}
-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&);
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
/* int k = tmplate->getMacroPar(i)->GetColumns();
if (k>0) {
args[i].array = new LyxArrayBase;
- for (int j= 0; j<k-1; j++) args[i].array->Insert(j, LM_TC_TAB);
+ for (int j= 0; j<k-1; ++j) args[i].array->Insert(j, LM_TC_TAB);
}*/
}
idx = 0;
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();
}
-void MathMacro::Draw(int x, int y)
+void MathMacro::draw(Painter & pain, int x, int y)
{
xo = x; yo = y;
Metrics();
tmplate->update(this);
tmplate->SetStyle(size);
- mathGC = latexGC;
- tmplate->Draw(x, y);
- for (int i= 0; i<nargs; i++)
+ tmplate->draw(pain, x, y);
+ 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)
{
+#ifdef USE_OSTREAM_ONLY
+ if (tmplate->flags & MMF_Exp) {
+ lyxerr[Debug::MATHED] << "Expand " << tmplate->flags
+ << ' ' << MMF_Exp << endl;
+ tmplate->update(this);
+ tmplate->Write(os);
+ } 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) {
+ array = args[i].array;
+ MathParInset::Write(os);
+ if (i < nargs - 1)
+ os << "}{";
+ }
+ if (tmplate->flags & MMF_Env) {
+ os << "\\end{"
+ << name
+ << '}';
+ } else {
+ if (nargs > 0)
+ os << '}';
+ else
+ os << ' ';
+ }
+ }
+#else
string output;
MathMacro::Write(output);
- fprintf(file, "%s", output.c_str());
+ os << output;
+#endif
}
+#ifndef USE_OSTREAM_ONLY
void MathMacro::Write(string &file)
{
if (tmplate->flags & MMF_Exp) {
// 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 += ' ';
}
}
}
-
+#endif
/*--------------- Macro argument -----------------------------------*/
SetType(LM_OT_MACRO_ARG);
}
-void MathMacroArgument::Draw(int x, int baseline)
+
+void MathMacroArgument::draw(Painter & pain, int x, int baseline)
{
if (expnd_mode) {
- MathParInset::Draw(x, baseline);
+ MathParInset::draw(pain, x, baseline);
} else {
unsigned char s[3];
- sprintf((char*)s, "#%d", number);
- drawStr(LM_TC_TEX, size, x, baseline, &s[0], 2);
+ sprintf(reinterpret_cast<char*>(s), "#%d", number);
+ drawStr(pain, LM_TC_TEX, size, x, baseline, &s[0], 2);
}
}
MathParInset::Metrics();
} else {
unsigned char s[3];
- sprintf((char*)s, "#%d", number);
+ sprintf(reinterpret_cast<char*>(s), "#%d", number);
width = mathed_string_width(LM_TC_TEX, size, &s[0], 2);
mathed_string_height(LM_TC_TEX, size, &s[0], 2, ascent, descent);
}
}
-void MathMacroArgument::Write(FILE *file)
+
+void MathMacroArgument::Write(ostream & os)
{
+#ifdef USE_OSTREAM_ONLY
+ if (expnd_mode) {
+ MathParInset::Write(os);
+ } else {
+ os << '#' << number << ' ';
+ }
+#else
string output;
MathMacroArgument::Write(output);
- fprintf(file, "%s", output.c_str());
+ os << output;
+#endif
}
-void MathMacroArgument::Write(string &file)
+
+#ifndef USE_OSTREAM_ONLY
+void MathMacroArgument::Write(string & file)
{
if (expnd_mode) {
MathParInset::Write(file);
file += ' ';
}
}
+#endif
/* --------------------- 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 (nargs>0) {
+ if (nargs > 0) {
tcode = LM_TC_ACTIVE_INSET;
args = new MathMacroArgument[nargs];
- for (int i= 0; i<nargs; i++) {
- args[i].setNumber(i+1);
+ for (int i = 0; i < nargs; ++i) {
+ args[i].setNumber(i + 1);
}
} else
tcode = LM_TC_INSET;
MathMacroTemplate::~MathMacroTemplate()
{
// prevent to delete already deleted objects
- for (int i= 0; i<nargs; i++) {
+ for (int i = 0; i < nargs; ++i) {
args[i].SetData(0);
}
delete[] args;
{
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);
}
}
}
-void MathMacroTemplate::Draw(int x, int y)
+void MathMacroTemplate::draw(Painter & pain, int x, int y)
{
int x2, y2;
- bool expnd = (nargs>0) ? args[0].getExpand(): false;
+ 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);
+ MathParInset::draw(pain, 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;
if (flags & MMF_Edit) {
- for (int i= 0; i<nargs; i++) {
+ for (int i = 0; i < nargs; ++i) {
args[i].setExpand(false);
}
} else {
- for (int i= 0; i<nargs; i++) {
+ for (int i = 0; i < nargs; ++i) {
args[i].setExpand(true);
}
}
MathParInset::Metrics();
- for (int i= 0; i<nargs; i++) {
+ for (int i = 0; i < nargs; ++i) {
args[i].setExpand(expnd);
}
}
-void MathMacroTemplate::update(MathMacro* macro)
+
+void MathMacroTemplate::update(MathMacro * macro)
{
int idx = (macro) ? macro->getArgumentIdx(): 0;
- for (int i= 0; i<nargs; i++) {
+ for (int i = 0; i < nargs; ++i) {
if (macro) {
macro->setArgumentIdx(i);
args[i].SetData(macro->GetData());
}
-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)
+
+#ifndef USE_OSTREAM_ONLY
+void MathMacroTemplate::WriteDef(string & file)
{
file += "\n\\newcommand{\\";
file += name;
file += '{';
- for (int i= 0; i<nargs; i++) {
+ for (int i = 0; i < nargs; ++i) {
args[i].setExpand(false);
}
Write(file);
file += "}\n";
}
+#endif
+
-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) ? static_cast<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;
/* -------------------------- MathMacroTable -----------------------*/
-MathMacroTable::MathMacroTable(int n): max_macros(n)
+MathMacroTable::MathMacroTable(int n) : max_macros(n)
{
macro_table = new MathMacroTemplateP[max_macros];
num_macros = 0;
// 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;