]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MacroTable.cpp
Collapsable -> Collapsible (part 2)
[lyx.git] / src / mathed / MacroTable.cpp
index 31118ac6e086968bb258183df5874f5bde6bd2c0..d279bdb84490c0c0efe4214905f117316babb610 100644 (file)
@@ -12,8 +12,8 @@
 
 #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"
@@ -55,7 +55,7 @@ MacroData::MacroData(Buffer * buf, DocIterator const & pos)
 }
 
 
-MacroData::MacroData(Buffer * buf, MathMacroTemplate const & macro)
+MacroData::MacroData(Buffer * buf, InsetMathMacroTemplate const & macro)
        : buffer_(buf), queried_(false), numargs_(0), sym_(0), optionals_(0),
          lockCount_(0), redefinition_(false), type_(MacroTypeNewcommand)
 {
@@ -68,11 +68,10 @@ 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_));
 
        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()) {
@@ -82,7 +81,7 @@ bool MacroData::expand(vector<MathData> const & args, MathData & to) const
                        continue;
                //it.cell().erase(it.pos());
                //it.cell().insert(it.pos(), it.nextInset()->asInsetMath()
-               size_t n = static_cast<MathMacroArgument*>(it.nextInset())->number();
+               size_t n = static_cast<InsetMathMacroArgument*>(it.nextInset())->number();
                if (n <= args.size()) {
                        it.cell().erase(it.pos());
                        it.cell().insert(it.pos(), args[n - 1]);
@@ -114,11 +113,33 @@ vector<docstring> const & MacroData::defaults() const
 string const MacroData::requires() const
 {
        if (sym_)
-               return to_utf8(sym_->requires);
+               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_;
@@ -126,7 +147,7 @@ void MacroData::unlock() const
 }
 
 
-void MacroData::queryData(MathMacroTemplate const & macro) const
+void MacroData::queryData(InsetMathMacroTemplate const & macro) const
 {
        if (queried_)
                return;
@@ -161,7 +182,7 @@ void MacroData::updateData() const
        }
 
        // query the data from the macro template
-       queryData(static_cast<MathMacroTemplate const &>(*inset));
+       queryData(static_cast<InsetMathMacroTemplate const &>(*inset));
 }
 
 
@@ -177,9 +198,10 @@ int MacroData::write(odocstream & os, bool overwriteRedefinition) const
        }
 
        // output template
-       MathMacroTemplate const & tmpl =
-               static_cast<MathMacroTemplate const &>(*inset);
-       WriteStream wi(os, false, true, WriteStream::wsDefault);
+       InsetMathMacroTemplate const & tmpl =
+               static_cast<InsetMathMacroTemplate const &>(*inset);
+       otexrowstream ots(os);
+       WriteStream wi(ots, false, true, WriteStream::wsDefault);
        return tmpl.write(wi, overwriteRedefinition);
 }
 
@@ -222,16 +244,18 @@ MacroTable::iterator
 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);
        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);
 }