-#include <config.h>
+/**
+ * \file math_fracinset.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Alejandro Aguilar Sierra
+ * \author André Pönitz
+ *
+ * Full author contact details are available in file CREDITS.
+ */
-#ifdef __GNUG__
-#pragma implementation
-#endif
+#include <config.h>
#include "math_fracinset.h"
-#include "math_iter.h"
+#include "math_data.h"
+#include "math_mathmlstream.h"
+#include "textpainter.h"
#include "LColor.h"
-#include "Painter.h"
-#include "mathed/support.h"
-#include "support/LOstream.h"
+#include "frontends/Painter.h"
-using std::ostream;
+using std::string;
+using std::max;
+using std::auto_ptr;
-MathFracInset::MathFracInset(short ot)
- : MathParInset(LM_ST_TEXT, "frac", ot),
- idx_(0), den_(LM_ST_TEXT), dh_(0)
-{
- if (objtype == LM_OT_STACKREL) {
- flag |= LMPF_SCRIPT;
- SetName("stackrel");
- }
-}
+MathFracInset::MathFracInset(bool atop)
+ : atop_(atop)
+{}
-MathedInset * MathFracInset::Clone()
-{
- MathFracInset * p = new MathFracInset(*this);
- return p;
-}
-
-
-bool MathFracInset::setArgumentIdx(int i)
-{
- if (i == 0 || i == 1) {
- idx_ = i;
- return true;
- } else
- return false;
-}
-int MathFracInset::getArgumentIdx() const
+auto_ptr<InsetBase> MathFracInset::clone() const
{
- return idx_;
+ return auto_ptr<InsetBase>(new MathFracInset(*this));
}
-int MathFracInset::getMaxArgumentIdx() const
+MathFracInset * MathFracInset::asFracInset()
{
- return 1;
-}
-
-void MathFracInset::SetStyle(short st)
-{
- MathParInset::SetStyle(st);
- dh_ = 0;
- den_.SetStyle((size() == LM_ST_DISPLAY) ?
- static_cast<short>(LM_ST_TEXT)
- : size());
+ return atop_ ? 0 : this;
}
-void MathFracInset::SetData(MathedArray const & n, MathedArray const & d)
+MathFracInset const * MathFracInset::asFracInset() const
{
- den_.setData(d);
- MathParInset::setData(n);
+ return atop_ ? 0 : this;
}
-void MathFracInset::setData(MathedArray const & d)
+void MathFracInset::metrics(MetricsInfo & mi, Dimension & dim) const
{
- if (idx_ == 0)
- MathParInset::setData(d);
- else {
- den_.setData(d);
- }
+ FracChanger dummy(mi.base);
+ cell(0).metrics(mi);
+ cell(1).metrics(mi);
+ dim_.wid = max(cell(0).width(), cell(1).width()) + 2;
+ dim_.asc = cell(0).height() + 2 + 5;
+ dim_.des = cell(1).height() + 2 - 5;
+ dim = dim_;
}
-void MathFracInset::GetXY(int & x, int & y) const
-{
- if (idx_ == 0)
- MathParInset::GetXY(x, y);
- else
- den_.GetXY(x, y);
-}
-
-
-MathedArray & MathFracInset::GetData()
+void MathFracInset::draw(PainterInfo & pi, int x, int y) const
{
- if (idx_ == 0)
- return array;
- else
- return den_.GetData();
+ int m = x + dim_.wid / 2;
+ FracChanger dummy(pi.base);
+ cell(0).draw(pi, m - cell(0).width() / 2, y - cell(0).descent() - 2 - 5);
+ cell(1).draw(pi, m - cell(1).width() / 2, y + cell(1).ascent() + 2 - 5);
+ if (!atop_)
+ pi.pain.line(x + 1, y - 5, x + dim_.wid - 2, y - 5, LColor::math);
}
-MathedArray const & MathFracInset::GetData() const
+void MathFracInset::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
{
- if (idx_ == 0)
- return array;
- else
- return den_.GetData();
+ cell(0).metricsT(mi, dim);
+ cell(1).metricsT(mi, dim);
+ dim.wid = max(cell(0).width(), cell(1).width());
+ dim.asc = cell(0).height() + 1;
+ dim.des = cell(1).height();
+ //dim = dim_;
}
-bool MathFracInset::Inside(int x, int y)
+void MathFracInset::drawT(TextPainter & pain, int x, int y) const
{
- int const xx = xo() - (width - w0_) / 2;
-
- return x >= xx
- && x <= xx + width
- && y <= yo() + descent
- && y >= yo() - ascent;
+ int m = x + dim_.width() / 2;
+ cell(0).drawT(pain, m - cell(0).width() / 2, y - cell(0).descent() - 1);
+ cell(1).drawT(pain, m - cell(1).width() / 2, y + cell(1).ascent());
+ if (!atop_)
+ pain.horizontalLine(x, y, dim_.width());
}
-void MathFracInset::SetFocus(int /*x*/, int y)
-{
- // lyxerr << "y " << y << " " << yo << " " << den_->yo << " ";
- idx_ = (y > yo()) ? 1 : 0;
+void MathFracInset::write(WriteStream & os) const
+{
+ if (atop_)
+ os << '{' << cell(0) << "\\atop " << cell(1) << '}';
+ else // it's \\frac
+ MathNestInset::write(os);
}
-void MathFracInset::draw(Painter & pain, int x, int y)
-{
- int const idxp = idx_;
- int const sizex = size();
-
- idx_ = 0;
- if (size() == LM_ST_DISPLAY) incSize();
- MathParInset::draw(pain, x + (width - w0_) / 2, y - des0_);
- den_.draw(pain, x + (width - w1_) / 2, y + den_.Ascent() + 2 - dh_);
- size(sizex);
- if (objtype == LM_OT_FRAC)
- pain.line(x + 2, y - dh_,
- x + width - 4, y - dh_, LColor::mathline);
- idx_ = idxp;
+string MathFracInset::name() const
+{
+ return atop_ ? "atop" : "frac";
}
-void MathFracInset::Metrics()
+void MathFracInset::maple(MapleStream & os) const
{
- if (!dh_) {
- int a;
- int b;
- dh_ = mathed_char_height(LM_TC_CONST, size(), 'I', a, b) / 2;
- }
- int const idxp = idx_;
- int const sizex = size();
- idx_ = 0;
- if (size() == LM_ST_DISPLAY) incSize();
- MathParInset::Metrics();
- size(sizex);
- w0_ = width;
- int const as = Height() + 2 + dh_;
- des0_ = Descent() + 2 + dh_;
- den_.Metrics();
- w1_ = den_.Width();
- width = ((w0_ > w1_) ? w0_: w1_) + 12;
- ascent = as;
- descent = den_.Height()+ 2 - dh_;
- idx_ = idxp;
+ os << '(' << cell(0) << ")/(" << cell(1) << ')';
}
-MathParInset * MathFracInset::denom()
+
+void MathFracInset::mathematica(MathematicaStream & os) const
{
- return &den_;
+ os << '(' << cell(0) << ")/(" << cell(1) << ')';
}
-void MathFracInset::Write(ostream & os, bool fragile)
+void MathFracInset::octave(OctaveStream & os) const
{
- os << '\\' << name << '{';
- MathParInset::Write(os, fragile);
- os << "}{";
- den_.Write(os, fragile);
- os << '}';
+ os << '(' << cell(0) << ")/(" << cell(1) << ')';
}
-void MathFracInset::WriteNormal(ostream & os)
+void MathFracInset::mathmlize(MathMLStream & os) const
{
- os << '[' << name << ' ';
- MathParInset::WriteNormal(os);
- os << " ";
- den_.WriteNormal(os);
- os << "] ";
+ os << MTag("mfrac") << cell(0) << cell(1) << ETag("mfrac");
}