#include "MacroTable.h"
#include "MathMacroTemplate.h"
#include "MathMacroArgument.h"
+#include "MathParser.h"
#include "MathStream.h"
#include "MathSupport.h"
#include "InsetMathNest.h"
/////////////////////////////////////////////////////////////////////
MacroData::MacroData(Buffer * buf)
- : buffer_(buf), queried_(true), numargs_(0), optionals_(0), lockCount_(0),
- redefinition_(false), type_(MacroTypeNewcommand)
+ : buffer_(buf), queried_(true), numargs_(0), sym_(0), optionals_(0),
+ lockCount_(0), redefinition_(false), type_(MacroTypeNewcommand)
{}
MacroData::MacroData(Buffer * buf, DocIterator const & pos)
- : buffer_(buf), pos_(pos), queried_(false), numargs_(0),
+ : buffer_(buf), pos_(pos), queried_(false), numargs_(0), sym_(0),
optionals_(0), lockCount_(0), redefinition_(false),
type_(MacroTypeNewcommand)
{
MacroData::MacroData(Buffer * buf, MathMacroTemplate const & macro)
- : buffer_(buf), queried_(false), numargs_(0), optionals_(0), lockCount_(0),
- redefinition_(false), type_(MacroTypeNewcommand)
+ : buffer_(buf), queried_(false), numargs_(0), sym_(0), optionals_(0),
+ lockCount_(0), redefinition_(false), type_(MacroTypeNewcommand)
{
queryData(macro);
}
-void MacroData::expand(vector<MathData> const & args, MathData & to) const
+bool MacroData::expand(vector<MathData> const & args, MathData & to) const
{
updateData();
// Hack. Any inset with a cell would do.
- static InsetMathSqrt inset(0);
- inset.setBuffer(const_cast<Buffer &>(*buffer_));
+ InsetMathSqrt inset(const_cast<Buffer *>(buffer_));
- // FIXME UNICODE
- asArray(display_.empty() ? definition_ : display_, inset.cell(0));
+ docstring const & definition(display_.empty() ? definition_ : display_);
+ asArray(definition, inset.cell(0));
//lyxerr << "MathData::expand: args: " << args << endl;
- //lyxerr << "MathData::expand: ar: " << inset.cell(0) << endl;
+ //LYXERR0("MathData::expand: ar: " << inset.cell(0));
for (DocIterator it = doc_iterator_begin(buffer_, &inset); it; it.forwardChar()) {
if (!it.nextInset())
continue;
it.cell().insert(it.pos(), args[n - 1]);
}
}
- //lyxerr << "MathData::expand: res: " << inset.cell(0) << endl;
+ //LYXERR0("MathData::expand: res: " << inset.cell(0));
to = inset.cell(0);
+ // If the result is equal to the definition then we either have a
+ // recursive loop, or the definition did not contain any macro in the
+ // first place.
+ return asString(to) != definition;
}
}
+string const MacroData::requires() const
+{
+ if (sym_)
+ return sym_->requires;
+ return string();
+}
+
+
+bool MacroData::hidden() const
+{
+ if (sym_)
+ return sym_->hidden;
+ return false;
+}
+
+
+docstring const MacroData::xmlname() const
+{
+ if (sym_)
+ return sym_->xmlname;
+ return docstring();
+}
+
+
+char const * MacroData::MathMLtype() const
+{
+ return sym_ ? sym_->MathMLtype() : 0;
+}
+
+
void MacroData::unlock() const
{
--lockCount_;
MacroTable::iterator
-MacroTable::insert(Buffer * buf, docstring const & def, string const & requires)
+MacroTable::insert(Buffer * buf, docstring const & def)
{
//lyxerr << "MacroTable::insert, def: " << to_utf8(def) << endl;
MathMacroTemplate mac(buf, def);
MacroData data(buf, mac);
- data.requires() = requires;
return insert(mac.name(), data);
}
-void MacroTable::getMacroNames(std::set<docstring> & names) const
+void MacroTable::getMacroNames(std::set<docstring> & names, bool gethidden) const
{
for (const_iterator it = begin(); it != end(); ++it)
- names.insert(it->first);
+ if (gethidden || !it->second.hidden())
+ names.insert(it->first);
}