]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_macro.C
Fix to bug 2362: Deleting superscript also deletes subscript.
[lyx.git] / src / mathed / math_macro.C
index f1e1f495e79c65f3e572988eeaec8fa818a4f98d..a403edfc9c1ddf6569ed07dd8b4b9a95a5ff5c62 100644 (file)
@@ -21,6 +21,7 @@
 #include "debug.h"
 #include "BufferView.h"
 #include "LaTeXFeatures.h"
+#include "frontends/Painter.h"
 
 using std::string;
 using std::max;
@@ -33,7 +34,7 @@ MathMacro::MathMacro(string const & name, int numargs)
 {}
 
 
-auto_ptr<InsetBase> MathMacro::clone() const
+auto_ptr<InsetBase> MathMacro::doClone() const
 {
        return auto_ptr<InsetBase>(new MathMacro(*this));
 }
@@ -45,6 +46,15 @@ string MathMacro::name() const
 }
 
 
+void MathMacro::cursorPos(CursorSlice const & sl, bool boundary, int & x,
+               int & y) const
+{
+       // We may have 0 arguments, but MathNestInset requires at least one.
+       if (nargs() > 0)
+               MathNestInset::cursorPos(sl, boundary, x, y);
+}
+
+
 void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        if (!MacroTable::globalMacros().has(name())) {
@@ -79,7 +89,7 @@ void MathMacro::draw(PainterInfo & pi, int x, int y) const
                LyXFont font = pi.base.font;
                augmentFont(font, "lyxtex");
                int h = y - dim_.ascent() + 2 + tmpl_.ascent();
-               drawStr(pi, font, x + 3, h, name());
+               pi.pain.text(x + 3, h, name(), font);
                int const w = mathed_string_width(font, name());
                tmpl_.draw(pi, x + w + 12, h);
                h += tmpl_.descent();
@@ -91,7 +101,7 @@ void MathMacro::draw(PainterInfo & pi, int x, int y) const
                        c.draw(pi, x + ldim.wid, h);
                        char str[] = "#1:";
                        str[1] += static_cast<char>(i);
-                       drawStr(pi, font, x + 3, h, str);
+                       pi.pain.text(x + 3, h, str, font);
                        h += max(c.descent(), ldim.des) + 5;
                }
        } else {
@@ -101,6 +111,14 @@ void MathMacro::draw(PainterInfo & pi, int x, int y) const
 }
 
 
+void MathMacro::drawSelection(PainterInfo & pi, int x, int y) const
+{
+       // We may have 0 arguments, but MathNestInset requires at least one.
+       if (nargs() > 0)
+               MathNestInset::drawSelection(pi, x, y);
+}
+
+
 void MathMacro::validate(LaTeXFeatures & features) const
 {
        if (name() == "binom" || name() == "mathcircumflex")
@@ -108,6 +126,24 @@ void MathMacro::validate(LaTeXFeatures & features) const
 }
 
 
+InsetBase * MathMacro::editXY(LCursor & cur, int x, int y)
+{
+       // We may have 0 arguments, but MathNestInset requires at least one.
+       if (nargs() > 0) {
+               // Prevent crash due to cold coordcache
+               // FIXME: This is only a workaround, the call of
+               // MathNestInset::editXY is correct. The correct fix would
+               // ensure that the coordcache of the arguments is valid.
+               if (!editing(&cur.bv())) {
+                       edit(cur, true);
+                       return this;
+               }
+               return MathNestInset::editXY(cur, x, y);
+       }
+       return this;
+}
+
+
 void MathMacro::maple(MapleStream & os) const
 {
        updateExpansion();