#pragma implementation
#endif
+#include <functional>
+
#include "math_fracinset.h"
-#include "math_iter.h"
#include "LColor.h"
#include "Painter.h"
#include "mathed/support.h"
#include "support/LOstream.h"
-using std::ostream;
-
-MathFracInset::MathFracInset(short ot)
- : MathParInset(LM_ST_TEXT, "frac", ot),
- idx_(0), den_(LM_ST_TEXT), dh_(0)
+MathFracInset::MathFracInset(MathInsetTypes ot)
+ : MathInset("frac", ot, 2)
{
- if (objtype == LM_OT_STACKREL) {
- flag |= LMPF_SCRIPT;
+ if (objtype == LM_OT_STACKREL)
SetName("stackrel");
- }
}
-MathedInset * MathFracInset::Clone()
+MathInset * MathFracInset::clone() const
{
- MathFracInset * p = new MathFracInset(*this);
- return p;
+ return new MathFracInset(*this);
}
-bool MathFracInset::setArgumentIdx(int i)
+void MathFracInset::Metrics(MathStyles st)
{
- if (i == 0 || i == 1) {
- idx_ = i;
- return true;
- } else
- return false;
+ size_ = smallerStyleFrac(st);
+ xcell(0).Metrics(size_);
+ xcell(1).Metrics(size_);
+ width_ = std::max(xcell(0).width(), xcell(1).width()) + 4;
+ ascent_ = xcell(0).height() + 4 + 5;
+ descent_ = xcell(1).height() + 4 - 5;
}
-void MathFracInset::SetStyle(short st)
+void MathFracInset::draw(Painter & pain, int x, int y)
{
- MathParInset::SetStyle(st);
- dh_ = 0;
- den_.SetStyle((size() == LM_ST_DISPLAY) ?
- static_cast<short>(LM_ST_TEXT)
- : size());
+ xo(x);
+ yo(y);
+ int m = x + width() / 2;
+ xcell(0).draw(pain, m - xcell(0).width() / 2, y - xcell(0).descent() - 3 - 5);
+ xcell(1).draw(pain, m - xcell(1).width() / 2, y + xcell(1).ascent() + 3 - 5);
+
+ if (objtype == LM_OT_FRAC)
+ pain.line(x + 2, y - 5, x + width() - 4, y - 5, LColor::mathline);
}
-void MathFracInset::SetData(MathedArray const & n, MathedArray const & d)
+void MathFracInset::Write(std::ostream & os, bool fragile) const
{
- den_.setData(d);
- MathParInset::setData(n);
+ os << '\\' << name() << '{';
+ cell(0).Write(os, fragile);
+ os << "}{";
+ cell(1).Write(os, fragile);
+ os << '}';
}
-void MathFracInset::setData(MathedArray const & d)
+void MathFracInset::WriteNormal(std::ostream & os) const
{
- if (idx_ == 0)
- MathParInset::setData(d);
- else {
- den_.setData(d);
- }
+ os << '[' << name() << ' ';
+ cell(0).WriteNormal(os);
+ os << " ";
+ cell(1).WriteNormal(os);
+ os << "] ";
}
-void MathFracInset::GetXY(int & x, int & y) const
-{
- if (idx_ == 0)
- MathParInset::GetXY(x, y);
- else
- den_.GetXY(x, y);
+bool MathFracInset::idxRight(int &, int &) const
+{
+ return false;
}
-
-MathedArray & MathFracInset::GetData()
+bool MathFracInset::idxLeft(int &, int &) const
{
- if (idx_ == 0)
- return array;
- else
- return den_.GetData();
+ return false;
}
-MathedArray const & MathFracInset::GetData() const
+bool MathFracInset::idxUp(int & idx, int &) const
{
- if (idx_ == 0)
- return array;
- else
- return den_.GetData();
+ if (idx == 0)
+ return false;
+ idx = 0;
+ return true;
}
-
-bool MathFracInset::Inside(int x, int y)
+bool MathFracInset::idxDown(int & idx, int &) const
{
- int const xx = xo() - (width - w0_) / 2;
-
- return x >= xx
- && x <= xx + width
- && y <= yo() + descent
- && y >= yo() - ascent;
+ if (idx == 1)
+ return false;
+ idx = 1;
+ return true;
}
-
-void MathFracInset::SetFocus(int /*x*/, int y)
-{
- // lyxerr << "y " << y << " " << yo << " " << den_->yo << " ";
- idx_ = (y > yo()) ? 1 : 0;
+bool MathFracInset::idxFirstUp(int & idx, int & pos) const
+{
+ idx = 0;
+ pos = 0;
+ return true;
}
-
-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;
+bool MathFracInset::idxFirstDown(int & idx, int & pos) const
+{
+ idx = 1;
+ pos = 0;
+ return true;
}
-
-void
-MathFracInset::Metrics()
+bool MathFracInset::idxLastUp(int & idx, int & pos) 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;
+ idx = 0;
+ pos = cell(idx).size();
+ return true;
}
-
-void MathFracInset::Write(ostream & os, bool fragile)
+bool MathFracInset::idxLastDown(int & idx, int & pos) const
{
- os << '\\' << name << '{';
- MathParInset::Write(os, fragile);
- os << "}{";
- den_.Write(os, fragile);
- os << '}';
+ idx = 1;
+ pos = cell(idx).size();
+ return true;
}
+