2001-02-13 13:28:32 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "math_fracinset.h"
|
|
|
|
#include "math_iter.h"
|
|
|
|
#include "LColor.h"
|
|
|
|
#include "Painter.h"
|
|
|
|
#include "mathed/support.h"
|
2001-02-14 15:00:50 +00:00
|
|
|
#include "support/LOstream.h"
|
|
|
|
|
|
|
|
using std::ostream;
|
2001-02-13 13:28:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
MathFracInset::MathFracInset(short ot)
|
|
|
|
: MathParInset(LM_ST_TEXT, "frac", ot)
|
|
|
|
{
|
|
|
|
|
2001-02-16 09:25:43 +00:00
|
|
|
den_ = new MathParInset(LM_ST_TEXT); // this leaks
|
|
|
|
dh_ = 0;
|
|
|
|
idx_ = 0;
|
2001-02-13 13:28:32 +00:00
|
|
|
if (objtype == LM_OT_STACKREL) {
|
|
|
|
flag |= LMPF_SCRIPT;
|
|
|
|
SetName("stackrel");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathFracInset::~MathFracInset()
|
|
|
|
{
|
2001-02-16 09:25:43 +00:00
|
|
|
delete den_;
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathedInset * MathFracInset::Clone()
|
|
|
|
{
|
|
|
|
MathFracInset * p = new MathFracInset(GetType());
|
|
|
|
MathedIter itn(array);
|
2001-02-16 09:25:43 +00:00
|
|
|
MathedIter itd(den_->GetData());
|
2001-02-13 13:28:32 +00:00
|
|
|
p->SetData(itn.Copy(), itd.Copy());
|
2001-02-16 09:25:43 +00:00
|
|
|
p->idx_ = idx_;
|
|
|
|
p->dh_ = dh_;
|
2001-02-13 13:28:32 +00:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathFracInset::setArgumentIdx(int i)
|
|
|
|
{
|
|
|
|
if (i == 0 || i == 1) {
|
2001-02-16 09:25:43 +00:00
|
|
|
idx_ = i;
|
2001-02-13 13:28:32 +00:00
|
|
|
return true;
|
|
|
|
} else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathFracInset::SetStyle(short st)
|
|
|
|
{
|
|
|
|
MathParInset::SetStyle(st);
|
2001-02-16 09:25:43 +00:00
|
|
|
dh_ = 0;
|
|
|
|
den_->SetStyle((size() == LM_ST_DISPLAY) ?
|
2001-02-13 13:28:32 +00:00
|
|
|
static_cast<short>(LM_ST_TEXT)
|
2001-02-15 12:22:01 +00:00
|
|
|
: size());
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathFracInset::SetData(MathedArray * n, MathedArray * d)
|
|
|
|
{
|
2001-02-16 09:25:43 +00:00
|
|
|
den_->setData(d);
|
|
|
|
MathParInset::setData(n);
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-16 09:25:43 +00:00
|
|
|
void MathFracInset::setData(MathedArray * d)
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2001-02-16 09:25:43 +00:00
|
|
|
if (idx_ == 0)
|
|
|
|
MathParInset::setData(d);
|
2001-02-13 13:28:32 +00:00
|
|
|
else {
|
2001-02-16 09:25:43 +00:00
|
|
|
den_->setData(d);
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathFracInset::GetXY(int & x, int & y) const
|
|
|
|
{
|
2001-02-16 09:25:43 +00:00
|
|
|
if (idx_ == 0)
|
2001-02-13 13:28:32 +00:00
|
|
|
MathParInset::GetXY(x, y);
|
|
|
|
else
|
2001-02-16 09:25:43 +00:00
|
|
|
den_->GetXY(x, y);
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathedArray * MathFracInset::GetData()
|
|
|
|
{
|
2001-02-16 09:25:43 +00:00
|
|
|
if (idx_ == 0)
|
2001-02-13 13:28:32 +00:00
|
|
|
return array;
|
|
|
|
else
|
2001-02-16 09:25:43 +00:00
|
|
|
return den_->GetData();
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathFracInset::Inside(int x, int y)
|
|
|
|
{
|
2001-02-16 09:25:43 +00:00
|
|
|
int xx = xo() - (width - w0_) / 2;
|
2001-02-13 13:28:32 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
return x >= xx
|
|
|
|
&& x <= xx + width
|
|
|
|
&& y <= yo() + descent
|
|
|
|
&& y >= yo() - ascent;
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathFracInset::SetFocus(int /*x*/, int y)
|
|
|
|
{
|
2001-02-16 09:25:43 +00:00
|
|
|
// lyxerr << "y " << y << " " << yo << " " << den_->yo << " ";
|
|
|
|
idx_ = (y > yo()) ? 1 : 0;
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
MathFracInset::draw(Painter & pain, int x, int y)
|
|
|
|
{
|
2001-02-16 09:25:43 +00:00
|
|
|
int const idxp = idx_;
|
|
|
|
int const sizex = size();
|
2001-02-13 13:28:32 +00:00
|
|
|
|
2001-02-16 09:25:43 +00:00
|
|
|
idx_ = 0;
|
2001-02-15 12:22:01 +00:00
|
|
|
if (size() == LM_ST_DISPLAY) incSize();
|
2001-02-16 09:25:43 +00:00
|
|
|
MathParInset::draw(pain, x + (width - w0_) / 2, y - des0_);
|
|
|
|
den_->draw(pain, x + (width - w1_) / 2, y + den_->Ascent() + 2 - dh_);
|
2001-02-15 12:22:01 +00:00
|
|
|
size(sizex);
|
2001-02-13 13:28:32 +00:00
|
|
|
if (objtype == LM_OT_FRAC)
|
2001-02-16 09:25:43 +00:00
|
|
|
pain.line(x + 2, y - dh_,
|
|
|
|
x + width - 4, y - dh_, LColor::mathline);
|
|
|
|
idx_ = idxp;
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
MathFracInset::Metrics()
|
|
|
|
{
|
2001-02-16 09:25:43 +00:00
|
|
|
if (!dh_) {
|
|
|
|
int a;
|
|
|
|
int b;
|
|
|
|
dh_ = mathed_char_height(LM_TC_CONST, size(), 'I', a, b) / 2;
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
2001-02-16 09:25:43 +00:00
|
|
|
int const idxp = idx_;
|
|
|
|
int const sizex = size();
|
|
|
|
idx_ = 0;
|
2001-02-15 12:22:01 +00:00
|
|
|
if (size() == LM_ST_DISPLAY) incSize();
|
2001-02-13 13:28:32 +00:00
|
|
|
MathParInset::Metrics();
|
2001-02-15 12:22:01 +00:00
|
|
|
size(sizex);
|
2001-02-16 09:25:43 +00:00
|
|
|
w0_ = width;
|
|
|
|
int const as = Height() + 2 + dh_;
|
|
|
|
des0_ = Descent() + 2 + dh_;
|
|
|
|
den_->Metrics();
|
|
|
|
w1_ = den_->Width();
|
|
|
|
width = ((w0_ > w1_) ? w0_: w1_) + 12;
|
2001-02-13 13:28:32 +00:00
|
|
|
ascent = as;
|
2001-02-16 09:25:43 +00:00
|
|
|
descent = den_->Height()+ 2 - dh_;
|
|
|
|
idx_ = idxp;
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathFracInset::Write(ostream & os, bool fragile)
|
|
|
|
{
|
|
|
|
os << '\\' << name << '{';
|
|
|
|
MathParInset::Write(os, fragile);
|
|
|
|
os << "}{";
|
2001-02-16 09:25:43 +00:00
|
|
|
den_->Write(os, fragile);
|
2001-02-13 13:28:32 +00:00
|
|
|
os << '}';
|
|
|
|
}
|