]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathMacro.cpp
Set correctly the spacing between atoms in MathData
[lyx.git] / src / mathed / MathMacro.cpp
index 4529cf92807800219d23035e59122ae78ab3706e..c4401d2b69ee8bfbee87ae952fc4d5b96e1ce2ff 100644 (file)
@@ -68,6 +68,27 @@ public:
        ///
        InsetCode lyxCode() const { return ARGUMENT_PROXY_CODE; }
        ///
+       bool addToMathRow(MathRow & mrow, MetricsInfo const & mi) const
+       {
+               MathRow::Element e(MathRow::BEG_ARG);
+               e.macro = mathMacro_;
+               e.ar = &mathMacro_->cell(idx_);
+               mrow.push_back(e);
+
+               mathMacro_->macro()->unlock();
+               bool const has_contents = mathMacro_->cell(idx_).addToMathRow(mrow, mi);
+               mathMacro_->macro()->lock();
+
+               e.type = MathRow::END_ARG;
+               mrow.push_back(e);
+
+               if (has_contents)
+                       return true;
+               // if there was no contents, then we insert the empty macro inset
+               // instead.
+               return InsetMath::addToMathRow(mrow, mi);
+       }
+       ///
        void metrics(MetricsInfo & mi, Dimension & dim) const {
                mathMacro_->macro()->unlock();
                mathMacro_->cell(idx_).metrics(mi, dim);
@@ -266,6 +287,34 @@ MathMacro::~MathMacro()
 }
 
 
+bool MathMacro::addToMathRow(MathRow & mrow, MetricsInfo const & mi) const
+{
+       // set edit mode for which we will have calculated row.
+       // This is the same as what is done in metrics().
+       d->editing_[mi.base.bv] = editMode(mi.base.bv);
+
+       if (displayMode() == MathMacro::DISPLAY_NORMAL
+           && !d->editing_[mi.base.bv]) {
+               MathRow::Element e(MathRow::BEG_MACRO);
+               e.macro = this;
+               mrow.push_back(e);
+
+               d->macro_->lock();
+               bool const has_contents = d->expanded_.addToMathRow(mrow, mi);
+               d->macro_->unlock();
+
+               e.type = MathRow::END_MACRO;
+               mrow.push_back(e);
+
+               if (has_contents)
+                       return true;
+               // if there was no contents, then we insert the empty macro inset
+               // instead.
+       }
+       return InsetMath::addToMathRow(mrow, mi);
+}
+
+
 Inset * MathMacro::clone() const
 {
        MathMacro * copy = new MathMacro(*this);
@@ -344,7 +393,7 @@ bool MathMacro::editMode(BufferView const * bv) const {
 }
 
 
-MacroData const * MathMacro::macro()
+MacroData const * MathMacro::macro() const
 {
        return d->macro_;
 }
@@ -539,7 +588,8 @@ void MathMacro::updateRepresentation(Cursor * cur, MacroContext const & mc,
        }
        // get definition for list edit mode
        docstring const & display = d->macro_->display();
-       asArray(display.empty() ? d->macro_->definition() : display, d->definition_);
+       asArray(display.empty() ? d->macro_->definition() : display,
+               d->definition_, Parse::QUIET);
 }
 
 
@@ -614,8 +664,7 @@ void MathMacro::draw(PainterInfo & pi, int x, int y) const
                drawMarkers2(pi, expx, expy);
        } else {
                bool drawBox = lyxrc.macro_edit_style == LyXRC::MACRO_EDIT_INLINE_BOX;
-               bool upshape = d->macro_ && d->macro_->symbol()
-                               && d->macro_->symbol()->extra == "textmode";
+               bool upshape = currentMode() == TEXT_MODE;
                Changer dummy = pi.base.font.changeShape(upshape ? UP_SHAPE
                                                        : pi.base.font.shape());
 
@@ -752,6 +801,17 @@ size_t MathMacro::appetite() const
 }
 
 
+InsetMath::mode_type MathMacro::currentMode() const
+{
+       // User defined macros are always assumed to be mathmode macros.
+       // Only the global macros defined in lib/symbols may be textmode.
+
+       MacroData const * data = MacroTable::globalMacros().get(name());
+       bool textmode = data && data->symbol() && data->symbol()->extra == "textmode";
+       return textmode ? TEXT_MODE : MATH_MODE;
+}
+
+
 void MathMacro::validate(LaTeXFeatures & features) const
 {
        // Immediately after a document is loaded, in some cases the MacroData
@@ -929,10 +989,11 @@ bool MathMacro::folded() const
 
 void MathMacro::write(WriteStream & os) const
 {
-       bool const textmode_macro = d->macro_ && d->macro_->symbol()
-                               && d->macro_->symbol()->extra == "textmode";
-       bool const needs_mathmode = d->macro_ && (!d->macro_->symbol()
-                               || d->macro_->symbol()->extra != "textmode");
+       MacroData const * data = MacroTable::globalMacros().get(name());
+       bool textmode_macro = data && data->symbol()
+                                  && data->symbol()->extra == "textmode";
+       bool needs_mathmode = data && (!data->symbol()
+                                      || data->symbol()->extra != "textmode");
 
        MathEnsurer ensurer(os, needs_mathmode, true, textmode_macro);