]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_rootinset.C
Fix to bug 2362: Deleting superscript also deletes subscript.
[lyx.git] / src / mathed / math_rootinset.C
index d7dbad49431ce5a1034326669a5eb5e081d4d362..8822ae1bf533b2622bd86c1557bb17f335bd2148 100644 (file)
@@ -1,23 +1,27 @@
-/*
- *  File:        math_root.C
- *  Purpose:     Implementation of the root object 
- *  Author:      Alejandro Aguilar Sierra <asierra@servidor.unam.mx> 
- *  Created:     January 1999
- *  Description: Root math object
+/**
+ * \file math_rootinset.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- *  Copyright: 1999 Alejandro Aguilar Sierra
+ * \author Alejandro Aguilar Sierra
+ * \author André Pönitz
  *
- *   You are free to use and modify this code under the terms of
- *   the GNU General Public Licence version 2 or later.
+ * Full author contact details are available in file CREDITS.
  */
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
+#include <config.h>
 
 #include "math_rootinset.h"
-#include "support/LOstream.h"
-#include "Painter.h"
+#include "math_data.h"
+#include "math_mathmlstream.h"
+#include "cursor.h"
+#include "LColor.h"
+
+#include "frontends/Painter.h"
+
+using std::max;
+using std::auto_ptr;
+
 
 
 MathRootInset::MathRootInset()
@@ -25,70 +29,81 @@ MathRootInset::MathRootInset()
 {}
 
 
-MathInset * MathRootInset::clone() const
+auto_ptr<InsetBase> MathRootInset::doClone() const
 {
-       return new MathRootInset(*this);
+       return auto_ptr<InsetBase>(new MathRootInset(*this));
 }
 
 
-void MathRootInset::metrics(MathMetricsInfo const & mi) const
+void MathRootInset::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        MathNestInset::metrics(mi);
-       ascent_  = std::max(xcell(0).ascent()  + 5, xcell(1).ascent())  + 2;
-       descent_ = std::max(xcell(1).descent() + 5, xcell(0).descent()) + 2;
-       width_   = xcell(0).width() + xcell(1).width() + 10;
+       dim.asc = max(cell(0).ascent()  + 5, cell(1).ascent())  + 2;
+       dim.des = max(cell(1).descent() + 5, cell(0).descent()) + 2;
+       dim.wid = cell(0).width() + cell(1).width() + 10;
+       metricsMarkers(dim);
+       dim_ = dim;
 }
 
 
-void MathRootInset::draw(Painter & pain, int x, int y) const
+void MathRootInset::draw(PainterInfo & pi, int x, int y) const
 {
-       int const w = xcell(0).width();
-       xcell(0).draw(pain, x, y - 5 - xcell(0).descent());       // the "exponent"
-       xcell(1).draw(pain, x + w + 8, y);   // the "base"
-       int const a = ascent();
-       int const d = descent();
+       int const w = cell(0).width();
+       // the "exponent"
+       cell(0).draw(pi, x, y - 5 - cell(0).descent());
+       // the "base"
+       cell(1).draw(pi, x + w + 8, y);
+       int const a = dim_.ascent();
+       int const d = dim_.descent();
        int xp[5];
        int yp[5];
-       xp[0] = x + width_;   yp[0] = y - a + 1;
-       xp[1] = x + w + 4;    yp[1] = y - a + 1;
-       xp[2] = x + w;        yp[2] = y + d;
-       xp[3] = x + w - 2;    yp[3] = y + (d - a)/2 + 2;
-       xp[4] = x;            yp[4] = y + (d - a)/2 + 2;
-       pain.lines(xp, yp, 5, LColor::mathline);
+       xp[0] = x + dim_.width();  yp[0] = y - a + 1;
+       xp[1] = x + w + 4;         yp[1] = y - a + 1;
+       xp[2] = x + w;             yp[2] = y + d;
+       xp[3] = x + w - 2;         yp[3] = y + (d - a)/2 + 2;
+       //xp[4] = x;                 yp[4] = y + (d - a)/2 + 2;
+       xp[4] = x + w - 5;         yp[4] = y + (d - a)/2 + 4;
+       pi.pain.lines(xp, yp, 5, LColor::math);
+       drawMarkers(pi, x, y);
 }
 
 
-void MathRootInset::write(MathWriteInfo & os) const
+void MathRootInset::write(WriteStream & os) const
 {
        os << "\\sqrt[" << cell(0) << "]{" << cell(1) << '}';
 }
 
 
-void MathRootInset::writeNormal(std::ostream & os) const
+void MathRootInset::normalize(NormalStream & os) const
 {
-       os << "[root ";
-       cell(1).writeNormal(os);  
-       os << " ";
-       cell(0).writeNormal(os);
-       os << "]";
+       os << "[root " << cell(0) << ' ' << cell(1) << ']';
 }
 
 
-bool MathRootInset::idxUp(int & idx, int & pos) const
+bool MathRootInset::idxUpDown(LCursor & cur, bool up) const
 {
-       if (idx == 0)
+       LCursor::idx_type const target = up ? 0 : 1;
+       if (cur.idx() == target)
                return false;
-       idx = 0;
-       pos = cell(0).size();
+       cur.idx() = target;
+       cur.pos() = up ? cur.lastpos() : 0;
        return true;
 }
 
 
-bool MathRootInset::idxDown(int & idx, int & pos) const
+void MathRootInset::maple(MapleStream & os) const
 {
-       if (idx == 1)
-               return false;
-       idx = 1;
-       pos = 0;
-       return true;
+       os << '(' << cell(1) << ")^(1/(" << cell(0) <<"))";
+}
+
+
+void MathRootInset::octave(OctaveStream & os) const
+{
+       os << "root(" << cell(1) << ',' << cell(0) << ')';
+}
+
+
+void MathRootInset::mathmlize(MathMLStream & os) const
+{
+       os << MTag("mroot") << cell(1) << cell(0) << ETag("mroot");
 }