]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathMacro.cpp
Add \makeat switches to babel settings if necessary.
[lyx.git] / src / mathed / MathMacro.cpp
index 3eedbee531f17d9f6cf115c61fcc0ec8060bbc84..cd9b757a51742385a883a283ccd1d68913d59e8b 100644 (file)
@@ -30,7 +30,6 @@
 #include "LaTeXFeatures.h"
 #include "LyX.h"
 #include "LyXRC.h"
-#include "Undo.h"
 
 #include "frontends/Painter.h"
 
@@ -139,6 +138,15 @@ Inset * MathMacro::clone() const
 }
 
 
+void MathMacro::normalize(NormalStream & os) const
+{
+       os << "[macro " << name();
+       for (size_t i = 0; i < nargs(); ++i)
+               os << ' ' << cell(i);
+       os << ']';
+}
+
+
 docstring MathMacro::name() const
 {
        if (displayMode_ == DISPLAY_UNFOLDED)
@@ -165,9 +173,12 @@ bool MathMacro::editMode(BufferView const * bv) const {
                        // look if there is no other macro in edit mode above
                        ++i;
                        for (; i != cur.depth(); ++i) {
-                               MathMacro const * macro = dynamic_cast<MathMacro const *>(&cur[i].inset());
-                               if (macro && macro->displayMode() == DISPLAY_NORMAL)
-                                       return false;
+                               InsetMath * im = cur[i].asInsetMath();
+                               if (im) {
+                                       MathMacro const * macro = im->asMacro();
+                                       if (macro && macro->displayMode() == DISPLAY_NORMAL)
+                                               return false;
+                               }
                        }
 
                        // ok, none found, I am the highest one
@@ -250,7 +261,7 @@ void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const
                // otherwise do a manual metrics call
                CoordCache & coords = mi.base.bv->coordCache();
                for (idx_type i = 0; i < nargs(); ++i) {
-                       if (!coords.getArrays().has(&cell(i))) {
+                       if (!coords.getArrays().hasDim(&cell(i))) {
                                Dimension tdim;
                                cell(i).metrics(mi, tdim);
                        }
@@ -300,7 +311,8 @@ void MathMacro::updateMacro(MacroContext const & mc)
 }
 
 
-void MathMacro::updateRepresentation()
+void MathMacro::updateRepresentation(Cursor * cur, MacroContext const & mc,
+               UpdateType utype)
 {
        // known macro?
        if (macro_ == 0)
@@ -331,6 +343,8 @@ void MathMacro::updateRepresentation()
        }
        // expanding macro with the values
        macro_->expand(values, expanded_.cell(0));
+       if (utype == OutputUpdate && !expanded_.cell(0).empty())
+               expanded_.cell(0).updateMacros(cur, mc, utype);
        // get definition for list edit mode
        docstring const & display = macro_->display();
        asArray(display.empty() ? macro_->definition() : display, definition_);
@@ -444,7 +458,7 @@ void MathMacro::draw(PainterInfo & pi, int x, int y) const
 
        // edit mode changed?
        if (editing_[pi.base.bv] != editMode(pi.base.bv))
-               pi.base.bv->cursor().updateFlags(Update::SinglePar);
+               pi.base.bv->cursor().screenUpdateFlags(Update::SinglePar);
 }
 
 
@@ -533,7 +547,7 @@ void MathMacro::validate(LaTeXFeatures & features) const
 
 void MathMacro::edit(Cursor & cur, bool front, EntryDirection entry_from)
 {
-       cur.updateFlags(Update::SinglePar);
+       cur.screenUpdateFlags(Update::SinglePar);
        InsetMathNest::edit(cur, front, entry_from);
 }
 
@@ -542,7 +556,7 @@ Inset * MathMacro::editXY(Cursor & cur, int x, int y)
 {
        // We may have 0 arguments, but InsetMathNest requires at least one.
        if (nargs() > 0) {
-               cur.updateFlags(Update::SinglePar);
+               cur.screenUpdateFlags(Update::SinglePar);
                return InsetMathNest::editXY(cur, x, y);                
        } else
                return this;
@@ -614,14 +628,14 @@ void MathMacro::attachArguments(vector<MathData> const & args, size_t arity, int
 
 bool MathMacro::idxFirst(Cursor & cur) const 
 {
-       cur.updateFlags(Update::SinglePar);
+       cur.screenUpdateFlags(Update::SinglePar);
        return InsetMathNest::idxFirst(cur);
 }
 
 
 bool MathMacro::idxLast(Cursor & cur) const 
 {
-       cur.updateFlags(Update::SinglePar);
+       cur.screenUpdateFlags(Update::SinglePar);
        return InsetMathNest::idxLast(cur);
 }
 
@@ -641,11 +655,12 @@ bool MathMacro::notifyCursorLeaves(Cursor const & old, Cursor & cur)
                        inset_cursor.cell().erase(inset_cursor.pos());
                        inset_cursor.cell().insert(inset_cursor.pos(),
                                createInsetMath(unfolded_name, cur.buffer()));
-                       cur.updateFlags(cur.disp_.update() | Update::SinglePar);
+                       cur.resetAnchor();
+                       cur.screenUpdateFlags(cur.result().screenUpdate() | Update::SinglePar);
                        return true;
                }
        }
-       cur.updateFlags(Update::Force);
+       cur.screenUpdateFlags(Update::Force);
        return InsetMathNest::notifyCursorLeaves(old, cur);
 }
 
@@ -654,7 +669,7 @@ void MathMacro::fold(Cursor & cur)
 {
        if (!nextFoldMode_) {
                nextFoldMode_ = true;
-               cur.updateFlags(Update::SinglePar);
+               cur.screenUpdateFlags(Update::SinglePar);
        }
 }
 
@@ -663,7 +678,7 @@ void MathMacro::unfold(Cursor & cur)
 {
        if (nextFoldMode_) {
                nextFoldMode_ = false;
-               cur.updateFlags(Update::SinglePar);
+               cur.screenUpdateFlags(Update::SinglePar);
        }
 }
 
@@ -741,13 +756,23 @@ void MathMacro::maple(MapleStream & os) const
 
 void MathMacro::mathmlize(MathStream & os) const
 {
-       os << expanded_.cell(0);
+       MathData const & data = expanded_.cell(0);
+       if (data.empty()) {
+               // this means that we do not recognize the macro
+               throw MathExportException();
+       }
+       os << data;
 }
 
 
 void MathMacro::htmlize(HtmlStream & os) const
 {
-       os << expanded_.cell(0);
+       MathData const & data = expanded_.cell(0);
+       if (data.empty()) {
+               // this means that we do not recognize the macro
+               throw MathExportException();
+       }
+       os << data;
 }
 
 
@@ -845,13 +870,13 @@ bool MathMacro::insertCompletion(Cursor & cur, docstring const & s,
        docstring newName = name() + s;
        asArray(newName, cell(0));
        cur.bv().cursor().pos() = name().size();
-       cur.updateFlags(Update::SinglePar);
+       cur.screenUpdateFlags(Update::SinglePar);
        
        // finish macro
        if (finished) {
                cur.bv().cursor().pop();
                ++cur.bv().cursor().pos();
-               cur.updateFlags(Update::SinglePar);
+               cur.screenUpdateFlags(Update::SinglePar);
        }
        
        return true;