X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2FMacroTable.cpp;h=d279bdb84490c0c0efe4214905f117316babb610;hb=9296344b9a26191a2092d175a51e357ecc35145d;hp=4af30d4c5438c25e0d3e332b3223a49471dc6237;hpb=0f2069b8a5967aac1b4f841214294f1fe21d2cad;p=lyx.git diff --git a/src/mathed/MacroTable.cpp b/src/mathed/MacroTable.cpp index 4af30d4c54..d279bdb844 100644 --- a/src/mathed/MacroTable.cpp +++ b/src/mathed/MacroTable.cpp @@ -12,8 +12,9 @@ #include "InsetMathSqrt.h" #include "MacroTable.h" -#include "MathMacroTemplate.h" -#include "MathMacroArgument.h" +#include "InsetMathMacroTemplate.h" +#include "InsetMathMacroArgument.h" +#include "MathParser.h" #include "MathStream.h" #include "MathSupport.h" #include "InsetMathNest.h" @@ -41,22 +42,22 @@ namespace lyx { ///////////////////////////////////////////////////////////////////// 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) +MacroData::MacroData(Buffer * buf, InsetMathMacroTemplate const & macro) + : buffer_(buf), queried_(false), numargs_(0), sym_(0), optionals_(0), + lockCount_(0), redefinition_(false), type_(MacroTypeNewcommand) { queryData(macro); } @@ -67,11 +68,10 @@ bool MacroData::expand(vector const & args, MathData & to) const updateData(); // Hack. Any inset with a cell would do. - static InsetMathSqrt inset(0); - inset.setBuffer(const_cast(*buffer_)); + InsetMathSqrt inset(const_cast(buffer_)); docstring const & definition(display_.empty() ? definition_ : display_); - asArray(definition, inset.cell(0)); + asArray(definition, inset.cell(0), Parse::QUIET | Parse::MACRODEF); //lyxerr << "MathData::expand: args: " << args << endl; //LYXERR0("MathData::expand: ar: " << inset.cell(0)); for (DocIterator it = doc_iterator_begin(buffer_, &inset); it; it.forwardChar()) { @@ -81,7 +81,7 @@ bool MacroData::expand(vector const & args, MathData & to) const continue; //it.cell().erase(it.pos()); //it.cell().insert(it.pos(), it.nextInset()->asInsetMath() - size_t n = static_cast(it.nextInset())->number(); + size_t n = static_cast(it.nextInset())->number(); if (n <= args.size()) { it.cell().erase(it.pos()); it.cell().insert(it.pos(), args[n - 1]); @@ -110,6 +110,36 @@ vector const & MacroData::defaults() const } +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_; @@ -117,7 +147,7 @@ void MacroData::unlock() const } -void MacroData::queryData(MathMacroTemplate const & macro) const +void MacroData::queryData(InsetMathMacroTemplate const & macro) const { if (queried_) return; @@ -152,7 +182,7 @@ void MacroData::updateData() const } // query the data from the macro template - queryData(static_cast(*inset)); + queryData(static_cast(*inset)); } @@ -168,9 +198,10 @@ int MacroData::write(odocstream & os, bool overwriteRedefinition) const } // output template - MathMacroTemplate const & tmpl = - static_cast(*inset); - WriteStream wi(os, false, true, WriteStream::wsDefault); + InsetMathMacroTemplate const & tmpl = + static_cast(*inset); + otexrowstream ots(os); + WriteStream wi(ots, false, true, WriteStream::wsDefault); return tmpl.write(wi, overwriteRedefinition); } @@ -210,20 +241,21 @@ MacroTable::insert(docstring const & name, MacroData const & data) 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); + InsetMathMacroTemplate mac(buf); + mac.fromString(def); MacroData data(buf, mac); - data.requires() = requires; return insert(mac.name(), data); } -void MacroTable::getMacroNames(std::set & names) const +void MacroTable::getMacroNames(std::set & 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); }