]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathMacro.cpp
Get rid of Inset::setPosCache
[lyx.git] / src / mathed / MathMacro.cpp
index a2a597f985dba2e90112ad41ee312a87ff41f5d6..6a5c904df7161855c8c9286df8e7e95142355870 100644 (file)
@@ -68,6 +68,14 @@ public:
        MathMacro const * owner() { return mathMacro_; }
        ///
        InsetCode lyxCode() const { return ARGUMENT_PROXY_CODE; }
+       /// The math data to use for display
+       MathData const & displayCell(BufferView const * bv) const
+       {
+               // handle default macro arguments
+               bool use_def_arg = !mathMacro_->editMetrics(bv)
+                       && mathMacro_->cell(idx_).empty();
+               return use_def_arg ? def_ : mathMacro_->cell(idx_);
+       }
        ///
        bool addToMathRow(MathRow & mrow, MetricsInfo & mi) const
        {
@@ -82,19 +90,14 @@ public:
                mrow.push_back(e_beg);
 
                mathMacro_->macro()->unlock();
-               bool has_contents;
-               // handle default macro arguments
-               if (!mathMacro_->editMetrics(mi.base.bv)
-                       && mathMacro_->cell(idx_).empty())
-                       has_contents = def_.addToMathRow(mrow, mi);
-               else
-                       has_contents = mathMacro_->cell(idx_).addToMathRow(mrow, mi);
+               bool has_contents = displayCell(mi.base.bv).addToMathRow(mrow, mi);
                mathMacro_->macro()->lock();
 
                // if there was no contents, and the contents is editable,
                // then we insert a box instead.
                if (!has_contents && mathMacro_->nesting() == 1) {
-                       MathRow::Element e(MathRow::BOX);
+                       // mathclass is ord because it should be spaced as a normal atom
+                       MathRow::Element e(MathRow::BOX, MC_ORD);
                        e.color = Color_mathline;
                        mrow.push_back(e);
                        has_contents = true;
@@ -113,6 +116,16 @@ public:
                // This should never be invoked, since ArgumentProxy insets are linearized
                LATTEST(false);
        }
+       ///
+       int kerning(BufferView const * bv) const
+       {
+               return displayCell(bv).kerning(bv);
+       }
+       ///
+       void draw(PainterInfo &, int, int) const {
+               // This should never be invoked, since ArgumentProxy insets are linearized
+               LATTEST(false);
+       }
        // write(), normalize(), infoize() and infoize2() are not needed since
        // MathMacro uses the definition and not the expanded cells.
        ///
@@ -127,22 +140,6 @@ public:
        void htmlize(HtmlStream & ms) const { ms << mathMacro_->cell(idx_); }
        ///
        void octave(OctaveStream & os) const { os << mathMacro_->cell(idx_); }
-       ///
-       void draw(PainterInfo &, int, int) const {
-               // This should never be invoked, since ArgumentProxy insets are linearized
-               LATTEST(false);
-       }
-       ///
-       size_t idx() const { return idx_; }
-       ///
-       int kerning(BufferView const * bv) const
-       {
-               if (mathMacro_->editMetrics(bv)
-                   || !mathMacro_->cell(idx_).empty())
-                       return mathMacro_->cell(idx_).kerning(bv);
-               else
-                       return def_.kerning(bv);
-       }
 
 private:
        ///
@@ -312,6 +309,7 @@ bool MathMacro::addToMathRow(MathRow & mrow, MetricsInfo & mi) const
        // if there was no contents and the array is editable, then we
        // insert a grey box instead.
        if (!has_contents && mi.base.macro_nesting == 1) {
+               // mathclass is unknown because it is irrelevant for spacing
                MathRow::Element e(MathRow::BOX);
                e.color = Color_mathmacroblend;
                mrow.push_back(e);
@@ -626,7 +624,6 @@ void MathMacro::draw(PainterInfo & pi, int x, int y) const
 {
        Dimension const dim = dimension(*pi.base.bv);
 
-       setPosCache(pi, x, y);
        int expx = x;
        int expy = y;