more mathed changes, read the changelog

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1649 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2001-03-01 14:07:43 +00:00
parent 21983193d6
commit aae45c2088
11 changed files with 159 additions and 183 deletions

View File

@ -1,5 +1,45 @@
2001-03-01 Lars Gullik Bjønnes <larsbj@trylle.birdstep.com> 2001-03-01 Lars Gullik Bjønnes <larsbj@trylle.birdstep.com>
* math_macrotemplate.h: make noncopyable, remove last arg to
constructor, remove flags_ add edit_
(flags): remove method
* math_macrotemplate.C (setArgument): delete method
(update): make idx const
(Metrics): use edit_, remove flags_
(draw): use edit_, remove flags_
(setEditMode): set edit_, remove flags_
(MathMacroTemplate): initialize edit_, remove flags_
* math_macro.h: remove x,y from MacroArgumentBase, make tmplate_ a
shared_ptr, let constructor take a shared_ptr
* math_macro.C (MathMacro): take shared_ptr as arg, remove double
initialization.
(draw): remove unneded update, remove removed update of x,y
(GetXY): call tmplates GetMacroXY directly
(SetFocus): call Metrics() instead of update()
(Write): remove support for math macro environments, simplifications.
* math_macrotable.h: make class noncopyable, change getMacro to
createMacro, change vector to map store a
shared_ptr<MathMacroTemplate> in it., remove unneeded typedef
* math_macrotable.C: add pragma
(createMacro): change name from getMacro, use shared_ptr
(getTemplate): Use map lookup to get macro, return shared_ptr
(addTemplate): assert that m containse a valid pointer, use map[]
insert.
(builtinMacros): by using shared_ptr fix the mem leak, remove
commented out unsupported macros
* math_cursor.C: changes because of the above
* math_parser.C: changes because of the abobe
* formulamacro.h: change tmacro_ to be a shared_ptr, remove
default arg on constructor.
* formulamacro.C: changes because of the above
* math_parinset.h: add pragma * math_parinset.h: add pragma
(SetAlign): move inline out of class def (SetAlign): move inline out of class def
(GetColumns): ditto (GetColumns): ditto

View File

@ -42,7 +42,6 @@ using std::istream;
InsetFormulaMacro::InsetFormulaMacro() InsetFormulaMacro::InsetFormulaMacro()
: InsetFormula(true) : InsetFormula(true)
{ {
tmacro_ = 0;
opened_ = false; opened_ = false;
} }
@ -51,8 +50,8 @@ InsetFormulaMacro::InsetFormulaMacro(string nm, int na)
: InsetFormula(true), name_(nm) : InsetFormula(true), name_(nm)
{ {
tmacro_ = MathMacroTable::mathMTable.getTemplate(name_); tmacro_ = MathMacroTable::mathMTable.getTemplate(name_);
if (!tmacro_) { if (!tmacro_.get()) {
tmacro_ = new MathMacroTemplate(name_, na); tmacro_.reset(new MathMacroTemplate(name_, na));
MathMacroTable::mathMTable.addTemplate(tmacro_); MathMacroTable::mathMTable.addTemplate(tmacro_);
} }
opened_ = false; opened_ = false;
@ -61,13 +60,16 @@ InsetFormulaMacro::InsetFormulaMacro(string nm, int na)
InsetFormulaMacro::~InsetFormulaMacro() InsetFormulaMacro::~InsetFormulaMacro()
{ {
// We do not want the InsetFormula destructor to
// delete this. That is taken care of elsewhere (Lgb)
par = 0; par = 0;
} }
Inset * InsetFormulaMacro::Clone(Buffer const &) const Inset * InsetFormulaMacro::Clone(Buffer const &) const
{ {
return new InsetFormulaMacro(name_); // This should really use a proper copy constructor
return new InsetFormulaMacro(name_, 0);
} }
@ -105,7 +107,7 @@ void InsetFormulaMacro::Read(Buffer const *, LyXLex & lex)
MathedArray ar; MathedArray ar;
mathed_parse(ar, 0, reinterpret_cast<MathParInset **>(&tmacro_)); mathed_parse(ar, 0, reinterpret_cast<MathParInset **>(&tmacro_));
// since tmacro_ == 0 when mathed_parse is called we need to sett // Since tmacro_ == 0 when mathed_parse is called we need to set
// its contents explicitly afterwards (Lgb) // its contents explicitly afterwards (Lgb)
tmacro_->setData(ar); tmacro_->setData(ar);
@ -114,7 +116,7 @@ void InsetFormulaMacro::Read(Buffer const *, LyXLex & lex)
MathMacroTable::mathMTable.addTemplate(tmacro_); MathMacroTable::mathMTable.addTemplate(tmacro_);
name_ = tmacro_->GetName(); name_ = tmacro_->GetName();
par = tmacro_; par = tmacro_.get();
// reading of end_inset in the inset!!! // reading of end_inset in the inset!!!
while (lex.IsOK()) { while (lex.IsOK()) {

View File

@ -17,12 +17,14 @@
#ifndef INSET_FORMULA_MACRO_H #ifndef INSET_FORMULA_MACRO_H
#define INSET_FORMULA_MACRO_H #define INSET_FORMULA_MACRO_H
#include <boost/smart_ptr.hpp>
#include "formula.h"
#ifdef __GNUG__ #ifdef __GNUG__
#pragma interface #pragma interface
#endif #endif
#include "formula.h"
class MathMacroTemplate; class MathMacroTemplate;
@ -33,7 +35,7 @@ public:
InsetFormulaMacro(); InsetFormulaMacro();
/// ///
explicit explicit
InsetFormulaMacro(string name, int na = 0); InsetFormulaMacro(string name, int na);
/// ///
~InsetFormulaMacro(); ~InsetFormulaMacro();
/// ///
@ -74,7 +76,7 @@ private:
/// ///
string name_; string name_;
/// ///
MathMacroTemplate * tmacro_; boost::shared_ptr<MathMacroTemplate> tmacro_;
}; };

View File

@ -40,6 +40,7 @@
#include "math_decorationinset.h" #include "math_decorationinset.h"
#include "math_dotsinset.h" #include "math_dotsinset.h"
#include "math_accentinset.h" #include "math_accentinset.h"
#include "math_macrotemplate.h"
#include "mathed/support.h" #include "mathed/support.h"
static MathedArray selarray; static MathedArray selarray;
@ -751,7 +752,7 @@ void MathedCursor::Interpret(string const & s)
l = in_word_set(s); l = in_word_set(s);
if (!l) { if (!l) {
p = MathMacroTable::mathMTable.getMacro(s); p = MathMacroTable::mathMTable.createMacro(s);
if (!p) { if (!p) {
lyxerr[Debug::MATHED] << "Macro2 " << s << ' ' << tcode << endl; lyxerr[Debug::MATHED] << "Macro2 " << s << ' ' << tcode << endl;
if (s == "root") { if (s == "root") {
@ -815,7 +816,7 @@ void MathedCursor::Interpret(string const & s)
break; break;
case LM_TK_MACRO: case LM_TK_MACRO:
p = MathMacroTable::mathMTable.getMacro(s); p = MathMacroTable::mathMTable.createMacro(s);
tcode = static_cast<MathMacro*>(p)->getTCode(); tcode = static_cast<MathMacro*>(p)->getTCode();
lyxerr[Debug::MATHED] << "Macro " << s << ' ' << tcode << endl; lyxerr[Debug::MATHED] << "Macro " << s << ' ' << tcode << endl;
break; break;
@ -872,7 +873,7 @@ void MathedCursor::MacroModeClose()
latexkeys const * l = in_word_set(imacro->GetName()); latexkeys const * l = in_word_set(imacro->GetName());
if (!imacro->GetName().empty() if (!imacro->GetName().empty()
&& (!l || (l && IsMacro(l->token, l->id))) && && (!l || (l && IsMacro(l->token, l->id))) &&
!MathMacroTable::mathMTable.getMacro(imacro->GetName())) { !MathMacroTable::mathMTable.createMacro(imacro->GetName())) {
if (!l) { if (!l) {
//imacro->SetName(macrobf); //imacro->SetName(macrobf);
// This guarantees that the string will be removed by destructor // This guarantees that the string will be removed by destructor
@ -886,7 +887,7 @@ void MathedCursor::MacroModeClose()
static_cast<MathAccentInset*>(cursor->GetInset())->getAccentCode()); static_cast<MathAccentInset*>(cursor->GetInset())->getAccentCode());
} }
cursor->Delete(); cursor->Delete();
if (l || MathMacroTable::mathMTable.getMacro(imacro->GetName())) { if (l || MathMacroTable::mathMTable.createMacro(imacro->GetName())) {
Interpret(imacro->GetName()); Interpret(imacro->GetName());
} }
imacro->SetName(""); imacro->SetName("");

View File

@ -44,15 +44,13 @@ ostream & operator<<(ostream & o, MathedTextCodes mtc)
} }
MathMacro::MathMacro(MathMacroTemplate * t) MathMacro::MathMacro(boost::shared_ptr<MathMacroTemplate> const & t)
: MathParInset(LM_ST_TEXT, "", LM_OT_MACRO), tmplate_(t) : MathParInset(LM_ST_TEXT, "", LM_OT_MACRO),
tmplate_(t)
{ {
nargs_ = tmplate_->getNoArgs(); nargs_ = tmplate_->getNoArgs();
tcode_ = tmplate_->getTCode(); tcode_ = tmplate_->getTCode();
args_.resize(nargs_); args_.resize(nargs_);
for (int i = 0; i < nargs_; ++i) {
args_[i].row = 0;
}
idx_ = 0; idx_ = 0;
SetName(tmplate_->GetName()); SetName(tmplate_->GetName());
} }
@ -103,12 +101,8 @@ void MathMacro::draw(Painter & pain, int x, int y)
xo(x); xo(x);
yo(y); yo(y);
Metrics(); Metrics();
tmplate_->update(this);
tmplate_->SetStyle(size()); tmplate_->SetStyle(size());
tmplate_->draw(pain, x, y); tmplate_->draw(pain, x, y);
for (int i = 0; i < nargs_; ++i) {
tmplate_->GetMacroXY(i, args_[i].x, args_[i].y);
}
} }
@ -154,8 +148,13 @@ int MathMacro::GetColumns() const
void MathMacro::GetXY(int & x, int & y) const void MathMacro::GetXY(int & x, int & y) const
{ {
x = args_[idx_].x; #if 0
y = args_[idx_].y; x = args_[idx_].x_;
y = args_[idx_].y_;
#else
const_cast<MathMacro*>(this)->Metrics();
tmplate_->GetMacroXY(idx_, x, y);
#endif
} }
@ -169,7 +168,7 @@ bool MathMacro::Permit(short f) const
void MathMacro::SetFocus(int x, int y) void MathMacro::SetFocus(int x, int y)
{ {
tmplate_->update(this); Metrics();
tmplate_->SetMacroFocus(idx_, x, y); tmplate_->SetMacroFocus(idx_, x, y);
} }
@ -180,8 +179,6 @@ void MathMacro::setData(MathedArray const & a)
} }
MathedRowSt * MathMacro::getRowSt() const MathedRowSt * MathMacro::getRowSt() const
{ {
return args_[idx_].row; return args_[idx_].row;
@ -196,43 +193,18 @@ MathedTextCodes MathMacro::getTCode() const
void MathMacro::Write(ostream & os, bool fragile) void MathMacro::Write(ostream & os, bool fragile)
{ {
if (tmplate_->flags() & MMF_Exp) { os << '\\' << name;
lyxerr[Debug::MATHED] << "Expand " << tmplate_->flags()
<< ' ' << MMF_Exp << endl; if (nargs_ > 0) {
tmplate_->update(this); os << '{';
tmplate_->Write(os, fragile);
} 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) { for (int i = 0; i < nargs_; ++i) {
array = args_[i].array; array = args_[i].array;
MathParInset::Write(os, fragile); MathParInset::Write(os, fragile);
if (i < nargs_ - 1) if (i < nargs_ - 1)
os << "}{"; os << "}{";
}
if (tmplate_->flags() & MMF_Env) {
os << "\\end{"
<< name
<< '}';
} else {
if (nargs_ > 0)
os << '}';
else
os << ' ';
} }
} os << '}';
} else
os << ' ';
} }

View File

@ -22,6 +22,8 @@
#endif #endif
#include <vector> #include <vector>
#include <boost/smart_ptr.hpp>
#include "math_parinset.h" #include "math_parinset.h"
class MathMacroTemplate; class MathMacroTemplate;
@ -35,7 +37,7 @@ class MathMacro : public MathParInset {
public: public:
/// A macro can only be builded from an existing template /// A macro can only be builded from an existing template
explicit explicit
MathMacro(MathMacroTemplate *); MathMacro(boost::shared_ptr<MathMacroTemplate> const &);
/// or from another macro. /// or from another macro.
explicit explicit
MathMacro(MathMacro const &); MathMacro(MathMacro const &);
@ -73,20 +75,16 @@ public:
bool Permit(short) const; bool Permit(short) const;
private: private:
/// ///
MathMacroTemplate * tmplate_; boost::shared_ptr<MathMacroTemplate> tmplate_;
/// ///
struct MacroArgumentBase { struct MacroArgumentBase {
/// Position of the macro
int x;
///
int y;
/// ///
MathedRowSt * row; MathedRowSt * row;
/// ///
MathedArray array; MathedArray array;
/// ///
MacroArgumentBase() MacroArgumentBase()
: x(0), y(0), row(0) : row(0)
{} {}
}; };
std::vector<MacroArgumentBase> args_; std::vector<MacroArgumentBase> args_;

View File

@ -1,5 +1,9 @@
#include <config.h> #include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
#include "math_macrotable.h" #include "math_macrotable.h"
#include "math_macro.h" #include "math_macro.h"
#include "math_macrotemplate.h" #include "math_macrotemplate.h"
@ -10,6 +14,7 @@
#include "math_fracinset.h" #include "math_fracinset.h"
#include "math_parinset.h" #include "math_parinset.h"
#include "debug.h" #include "debug.h"
#include "support/LAssert.h"
using std::endl; using std::endl;
@ -18,68 +23,61 @@ MathMacroTable MathMacroTable::mathMTable;
bool MathMacroTable::built = false; bool MathMacroTable::built = false;
MathMacro * MathMacroTable::getMacro(string const & name) const MathMacro * MathMacroTable::createMacro(string const & name) const
{ {
MathMacroTemplate * mt = getTemplate(name); boost::shared_ptr<MathMacroTemplate> mt = getTemplate(name);
return (mt) ? new MathMacro(mt): 0; return (mt.get()) ? new MathMacro(mt) : 0;
} }
// The search is currently linear but will be binary or hash, later. boost::shared_ptr<MathMacroTemplate> const
MathMacroTemplate * MathMacroTable::getTemplate(string const & name) const MathMacroTable::getTemplate(string const & name) const
{ {
for (size_type i = 0; i < macro_table.size(); ++i) { table_type::const_iterator cit = macro_table.find(name);
if (name == macro_table[i]->GetName()) if (cit != macro_table.end()) return (*cit).second;
return macro_table[i]; return boost::shared_ptr<MathMacroTemplate>();
}
return 0;
}
void MathMacroTable::addTemplate(MathMacroTemplate * m)
{
macro_table.push_back(m);
} }
// All this stuff aparently leaks because it's created here and is not void
// deleted never, but it have to live all the LyX sesion. OK, would not MathMacroTable::addTemplate(boost::shared_ptr<MathMacroTemplate> const & m)
// so hard to do it in the MacroTable destructor, but this doesn't harm {
// seriously, so don't bother me with purify results here. ;-) Assert(m.get());
macro_table[m->GetName()] = m;
}
void MathMacroTable::builtinMacros() void MathMacroTable::builtinMacros()
{ {
MathParInset * inset;// *arg;
built = true; built = true;
lyxerr[Debug::MATHED] << "Building macros" << endl; lyxerr[Debug::MATHED] << "Building macros" << endl;
// This macro doesn't have arguments // This macro doesn't have arguments
MathMacroTemplate * m = new MathMacroTemplate("notin"); // this leaks
addTemplate(m);
{ {
boost::shared_ptr<MathMacroTemplate> m(new MathMacroTemplate("notin", 0));
addTemplate(m);
MathedArray array; MathedArray array;
MathedIter iter(&array); MathedIter iter(&array);
iter.insertInset(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not), iter.insertInset(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not),
LM_TC_INSET); // this leaks LM_TC_INSET);
m->setData(array); m->setData(array);
} }
// These two are only while we are still with LyX 2.x // These two are only while we are still with LyX 2.x
m = new MathMacroTemplate("emptyset"); // this leaks
addTemplate(m);
{ {
boost::shared_ptr<MathMacroTemplate> m(new MathMacroTemplate("emptyset", 0));
addTemplate(m);
MathedArray array; MathedArray array;
MathedIter iter(&array); MathedIter iter(&array);
iter.insertInset(new MathAccentInset('O', LM_TC_RM, LM_not), iter.insertInset(new MathAccentInset('O', LM_TC_RM, LM_not),
LM_TC_INSET); // this leaks LM_TC_INSET);
m->setData(array); m->setData(array);
} }
m = new MathMacroTemplate("perp"); // this leaks
addTemplate(m);
{ {
boost::shared_ptr<MathMacroTemplate> m(new MathMacroTemplate("perp", 0));
addTemplate(m);
MathedArray array; MathedArray array;
MathedIter iter(&array); MathedIter iter(&array);
iter.insert(LM_bot, LM_TC_BOP); iter.insert(LM_bot, LM_TC_BOP);
@ -87,13 +85,13 @@ void MathMacroTable::builtinMacros()
} }
// binom has two arguments // binom has two arguments
m = new MathMacroTemplate("binom", 2);
addTemplate(m);
{ {
boost::shared_ptr<MathMacroTemplate> m(new MathMacroTemplate("binom", 2));
addTemplate(m);
MathedArray array; MathedArray array;
m->setData(array); m->setData(array);
MathedIter iter(&array); MathedIter iter(&array);
inset = new MathDelimInset('(', ')'); MathParInset * inset = new MathDelimInset('(', ')');
iter.insertInset(inset, LM_TC_ACTIVE_INSET); iter.insertInset(inset, LM_TC_ACTIVE_INSET);
array = MathedArray(); array = MathedArray();
MathedIter iter2(&array); MathedIter iter2(&array);
@ -108,34 +106,4 @@ void MathMacroTable::builtinMacros()
iter4.insertInset(m->getMacroPar(1), LM_TC_INSET); iter4.insertInset(m->getMacroPar(1), LM_TC_INSET);
frac->SetData(array, array2); frac->SetData(array, array2);
} }
/*
// Cases has 1 argument
m = new MathMacroTemplate("cases", 1, MMF_Env); // this leaks
addTemplate(m);
array = new MathedArray; // this leaks
iter.SetData(array);
arg = new MathMatrixInset(2, 1); // this leaks
m->setArgument(arg);
arg->SetAlign('c', "ll");
iter.Insert(arg, LM_TC_ACTIVE_INSET);
inset = new MathDelimInset('{', '.'); // this leaks
inset->SetData(array);
array = new MathedArray; // 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);
arg = new MathMatrixInset(1, 1); // this leaks
m->setArgument(arg);
arg->SetType(LM_OT_MACRO);
array = new MathedArray; // this leaks
iter.SetData(array);
iter.Insert(arg, LM_TC_ACTIVE_INSET);
m->SetData(array);*/
} }

View File

@ -2,33 +2,39 @@
#ifndef MATHMACROTABLE #ifndef MATHMACROTABLE
#define MATHMACROTABLE #define MATHMACROTABLE
#include <vector> #include <map>
#include "LString.h" #include "LString.h"
#include <boost/utility.hpp>
#include <boost/smart_ptr.hpp>
#ifdef __GNUG__
#pragma interface
#endif
class MathMacroTemplate; class MathMacroTemplate;
class MathMacro; class MathMacro;
/// ///
class MathMacroTable { class MathMacroTable : noncopyable {
public: public:
/// ///
void addTemplate(MathMacroTemplate *); void addTemplate(boost::shared_ptr<MathMacroTemplate> const &);
/// ///
MathMacro * getMacro(string const &) const; MathMacro * createMacro(string const &) const;
/// ///
MathMacroTemplate * getTemplate(string const &) const; boost::shared_ptr<MathMacroTemplate> const
/// getTemplate(string const &) const;
void builtinMacros(); ///
/// void builtinMacros();
static MathMacroTable mathMTable; ///
/// static MathMacroTable mathMTable;
static bool built; ///
static bool built;
private: private:
/// ///
typedef std::vector<MathMacroTemplate *> table_type; typedef std::map<string, boost::shared_ptr<MathMacroTemplate> > table_type;
/// ///
typedef table_type::size_type size_type; table_type macro_table;
///
table_type macro_table;
}; };
#endif #endif

View File

@ -13,9 +13,10 @@
using std::ostream; using std::ostream;
MathMacroTemplate::MathMacroTemplate(string const & nm, int na, int flg): MathMacroTemplate::MathMacroTemplate(string const & nm, int na):
MathParInset(LM_ST_TEXT, nm, LM_OT_MACRO), MathParInset(LM_ST_TEXT, nm, LM_OT_MACRO),
flags_(flg), nargs_(na) edit_(false),
nargs_(na)
{ {
if (nargs_ > 0) { if (nargs_ > 0) {
tcode_ = LM_TC_ACTIVE_INSET; tcode_ = LM_TC_ACTIVE_INSET;
@ -52,12 +53,12 @@ int MathMacroTemplate::getNoArgs() const
void MathMacroTemplate::setEditMode(bool ed) void MathMacroTemplate::setEditMode(bool ed)
{ {
if (ed) { if (ed) {
flags_ |= MMF_Edit; edit_ = true;
for (int i = 0; i < nargs_; ++i) { for (int i = 0; i < nargs_; ++i) {
args_[i].setExpand(false); args_[i].setExpand(false);
} }
} else { } else {
flags_ &= ~MMF_Edit; edit_ = false;
for (int i = 0; i < nargs_; ++i) { for (int i = 0; i < nargs_; ++i) {
args_[i].setExpand(true); args_[i].setExpand(true);
} }
@ -70,7 +71,7 @@ void MathMacroTemplate::draw(Painter & pain, int x, int y)
int x2; int x2;
int y2; int y2;
bool expnd = (nargs_ > 0) ? args_[0].getExpand() : false; bool expnd = (nargs_ > 0) ? args_[0].getExpand() : false;
if (flags_ & MMF_Edit) { if (edit_) {
for (int i = 0; i < nargs_; ++i) { for (int i = 0; i < nargs_; ++i) {
args_[i].setExpand(false); args_[i].setExpand(false);
} }
@ -95,9 +96,9 @@ void MathMacroTemplate::draw(Painter & pain, int x, int y)
void MathMacroTemplate::Metrics() void MathMacroTemplate::Metrics()
{ {
bool expnd = (nargs_ > 0) ? args_[0].getExpand() : false; bool const expnd = (nargs_ > 0) ? args_[0].getExpand() : false;
if (flags_ & MMF_Edit) { if (edit_) {
for (int i = 0; i < nargs_; ++i) { for (int i = 0; i < nargs_; ++i) {
args_[i].setExpand(false); args_[i].setExpand(false);
} }
@ -117,7 +118,7 @@ void MathMacroTemplate::Metrics()
void MathMacroTemplate::update(MathMacro * macro) void MathMacroTemplate::update(MathMacro * macro)
{ {
Assert(macro); Assert(macro);
int idx = macro->getArgumentIdx(); int const idx = macro->getArgumentIdx();
for (int i = 0; i < nargs_; ++i) { for (int i = 0; i < nargs_; ++i) {
macro->setArgumentIdx(i); macro->setArgumentIdx(i);
args_[i].setData(macro->GetData()); args_[i].setData(macro->GetData());
@ -145,12 +146,6 @@ void MathMacroTemplate::WriteDef(ostream & os, bool fragile)
} }
void MathMacroTemplate::setArgument(MathedArray * 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); args_[i].GetXY(x, y);

View File

@ -4,6 +4,8 @@
#include <vector> #include <vector>
#include <boost/utility.hpp>
#include "math_parinset.h" #include "math_parinset.h"
#include "math_macroarg.h" #include "math_macroarg.h"
@ -16,11 +18,11 @@ class MathMacro;
/** This class contains the macro definition /** This class contains the macro definition
\author Alejandro Aguilar Sierra \author Alejandro Aguilar Sierra
*/ */
class MathMacroTemplate : public MathParInset { class MathMacroTemplate : public MathParInset, public noncopyable {
public: public:
/// A template constructor needs all the data /// A template constructor needs all the data
explicit explicit
MathMacroTemplate(string const &, int na = 0, int f = 0); MathMacroTemplate(string const &, int na);
/// ///
void draw(Painter &, int, int); void draw(Painter &, int, int);
/// ///
@ -28,11 +30,9 @@ public:
/// ///
void WriteDef(std::ostream &, bool fragile); void WriteDef(std::ostream &, bool fragile);
/// useful for special insets /// useful for special insets
void setTCode(MathedTextCodes t); void setTCode(MathedTextCodes t);
/// ///
MathedTextCodes getTCode() const; MathedTextCodes getTCode() const;
///
void setArgument(MathedArray *, int i= 0);
/// Number of arguments /// Number of arguments
int getNoArgs() const; int getNoArgs() const;
/// ///
@ -46,11 +46,9 @@ public:
/// Replace the appropriate arguments with a specific macro's data /// Replace the appropriate arguments with a specific macro's data
void update(MathMacro * m); void update(MathMacro * m);
///
short flags() const;
private: private:
/// /// Are we in edit mode or not?
short flags_; bool edit_;
/// ///
MathedTextCodes tcode_; MathedTextCodes tcode_;
/// ///
@ -58,10 +56,4 @@ private:
/// ///
int nargs_; int nargs_;
}; };
inline
short MathMacroTemplate::flags() const {
return flags_;
}
#endif #endif

View File

@ -783,7 +783,7 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
{ {
MathMacro * p = MathMacro * p =
MathMacroTable::mathMTable.getMacro(yylval.s); MathMacroTable::mathMTable.createMacro(yylval.s);
if (p) { if (p) {
if (accent) if (accent)
data.insertInset(doAccent(p), p->getTCode()); data.insertInset(doAccent(p), p->getTCode());
@ -881,7 +881,7 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
} else { } else {
// lyxerr << "MATHCRO[" << yytext << "]"; // lyxerr << "MATHCRO[" << yytext << "]";
MathMacro * p = MathMacro * p =
MathMacroTable::mathMTable.getMacro(yytext.data()); MathMacroTable::mathMTable.createMacro(yytext.data());
if (p) { if (p) {
data.insertInset(p, p->getTCode()); data.insertInset(p, p->getTCode());
p->setArgumentIdx(0); p->setArgumentIdx(0);
@ -898,7 +898,7 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
case LM_TK_MACRO: case LM_TK_MACRO:
{ {
MathedInset * p = MathedInset * p =
MathMacroTable::mathMTable.getMacro(yylval.l->name); MathMacroTable::mathMTable.createMacro(yylval.l->name);
if (p) { if (p) {
if (accent) { if (accent) {