2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
|
* \file InsetMathRoot.cpp
|
2003-08-19 13:00:56 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*
|
2003-08-19 13:00:56 +00:00
|
|
|
|
* \author Alejandro Aguilar Sierra
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*
|
2003-08-19 13:00:56 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2003-08-19 13:00:56 +00:00
|
|
|
|
#include <config.h>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "InsetMathRoot.h"
|
2007-04-26 16:05:57 +00:00
|
|
|
|
#include "MathData.h"
|
2006-10-22 10:15:23 +00:00
|
|
|
|
#include "MathStream.h"
|
2007-04-26 14:56:30 +00:00
|
|
|
|
#include "Cursor.h"
|
2007-04-26 17:34:20 +00:00
|
|
|
|
#include "Color.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
#include "frontends/Painter.h"
|
2001-10-22 15:37:49 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathRoot::InsetMathRoot()
|
|
|
|
|
: InsetMathNest(2)
|
2001-02-28 11:56:36 +00:00
|
|
|
|
{}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
|
Inset * InsetMathRoot::clone() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2007-08-30 18:03:17 +00:00
|
|
|
|
return new InsetMathRoot(*this);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
|
void InsetMathRoot::metrics(MetricsInfo & mi, Dimension & dim) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2007-08-30 18:03:17 +00:00
|
|
|
|
using std::max;
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathNest::metrics(mi);
|
2004-01-30 11:41:12 +00:00
|
|
|
|
dim.asc = max(cell(0).ascent() + 5, cell(1).ascent()) + 2;
|
2007-03-12 23:42:35 +00:00
|
|
|
|
dim.des = max(cell(0).descent() - 5, cell(1).descent()) + 2;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
dim.wid = cell(0).width() + cell(1).width() + 10;
|
|
|
|
|
metricsMarkers(dim);
|
|
|
|
|
dim_ = dim;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathRoot::draw(PainterInfo & pi, int x, int y) const
|
2000-02-10 17:53:36 +00:00
|
|
|
|
{
|
2002-08-02 14:29:42 +00:00
|
|
|
|
int const w = cell(0).width();
|
2002-02-16 15:59:55 +00:00
|
|
|
|
// the "exponent"
|
2002-08-02 14:29:42 +00:00
|
|
|
|
cell(0).draw(pi, x, y - 5 - cell(0).descent());
|
2002-02-16 15:59:55 +00:00
|
|
|
|
// the "base"
|
2002-08-02 14:29:42 +00:00
|
|
|
|
cell(1).draw(pi, x + w + 8, y);
|
2003-05-28 13:22:36 +00:00
|
|
|
|
int const a = dim_.ascent();
|
|
|
|
|
int const d = dim_.descent();
|
2007-05-19 10:52:47 +00:00
|
|
|
|
int xp[4];
|
|
|
|
|
int yp[4];
|
|
|
|
|
pi.pain.line(x + dim_.width(), y - a + 1,
|
|
|
|
|
x + w + 4, y - a + 1, Color::math);
|
|
|
|
|
xp[0] = x + w + 4; yp[0] = y - a + 1;
|
|
|
|
|
xp[1] = x + w; yp[1] = y + d;
|
|
|
|
|
xp[2] = x + w - 2; yp[2] = y + (d - a)/2 + 2;
|
|
|
|
|
xp[3] = x + w - 5; yp[3] = y + (d - a)/2 + 4;
|
|
|
|
|
pi.pain.lines(xp, yp, 4, Color::math);
|
2002-07-30 13:56:02 +00:00
|
|
|
|
drawMarkers(pi, x, y);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathRoot::write(WriteStream & os) const
|
2000-03-07 01:14:37 +00:00
|
|
|
|
{
|
2001-10-19 11:25:48 +00:00
|
|
|
|
os << "\\sqrt[" << cell(0) << "]{" << cell(1) << '}';
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2001-04-25 15:43:57 +00:00
|
|
|
|
|
2001-04-27 12:35:55 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathRoot::normalize(NormalStream & os) const
|
2001-04-25 15:43:57 +00:00
|
|
|
|
{
|
2002-03-21 09:48:46 +00:00
|
|
|
|
os << "[root " << cell(0) << ' ' << cell(1) << ']';
|
2001-04-25 15:43:57 +00:00
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool InsetMathRoot::idxUpDown(Cursor & cur, bool up) const
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2007-04-26 14:56:30 +00:00
|
|
|
|
Cursor::idx_type const target = up ? 0 : 1;
|
2004-01-15 17:34:44 +00:00
|
|
|
|
if (cur.idx() == target)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
return false;
|
2004-01-15 17:34:44 +00:00
|
|
|
|
cur.idx() = target;
|
|
|
|
|
cur.pos() = up ? cur.lastpos() : 0;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2001-11-07 13:15:59 +00:00
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathRoot::maple(MapleStream & os) const
|
2002-10-28 17:15:19 +00:00
|
|
|
|
{
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << '(' << cell(1) << ")^(1/(" << cell(0) <<"))";
|
2002-10-28 17:15:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-01-07 03:28:53 +00:00
|
|
|
|
void InsetMathRoot::mathematica(MathematicaStream & os) const
|
|
|
|
|
{
|
|
|
|
|
os << '(' << cell(1) << ")^(1/(" << cell(0) <<"))";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathRoot::octave(OctaveStream & os) const
|
2001-11-07 13:15:59 +00:00
|
|
|
|
{
|
2007-01-07 03:28:53 +00:00
|
|
|
|
os << '(' << cell(1) << ")^(1/(" << cell(0) <<"))";
|
2001-11-07 17:30:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
void InsetMathRoot::mathmlize(MathStream & os) const
|
2001-11-07 17:30:26 +00:00
|
|
|
|
{
|
2001-11-09 08:35:57 +00:00
|
|
|
|
os << MTag("mroot") << cell(1) << cell(0) << ETag("mroot");
|
2001-11-07 13:15:59 +00:00
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|