2001-02-13 13:28:32 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2001-02-26 12:53:35 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
#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)
|
2001-02-28 11:56:36 +00:00
|
|
|
: MathParInset(LM_ST_TEXT, "frac", ot),
|
|
|
|
idx_(0), den_(LM_ST_TEXT), dh_(0)
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
|
|
|
if (objtype == LM_OT_STACKREL) {
|
|
|
|
flag |= LMPF_SCRIPT;
|
|
|
|
SetName("stackrel");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathedInset * MathFracInset::Clone()
|
|
|
|
{
|
2001-02-20 10:49:48 +00:00
|
|
|
MathFracInset * p = new MathFracInset(*this);
|
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;
|
|
|
|
}
|
|
|
|
|
2001-04-25 15:43:57 +00:00
|
|
|
int MathFracInset::getArgumentIdx() const
|
|
|
|
{
|
|
|
|
return idx_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MathFracInset::getMaxArgumentIdx() const
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2001-02-13 13:28:32 +00:00
|
|
|
|
|
|
|
void MathFracInset::SetStyle(short st)
|
|
|
|
{
|
|
|
|
MathParInset::SetStyle(st);
|
2001-02-16 09:25:43 +00:00
|
|
|
dh_ = 0;
|
2001-02-28 11:56:36 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-20 16:00:22 +00:00
|
|
|
void MathFracInset::SetData(MathedArray const & n, MathedArray const & d)
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2001-02-28 11:56:36 +00:00
|
|
|
den_.setData(d);
|
2001-02-16 09:25:43 +00:00
|
|
|
MathParInset::setData(n);
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-20 16:00:22 +00:00
|
|
|
void MathFracInset::setData(MathedArray const & 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-28 11:56:36 +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-28 11:56:36 +00:00
|
|
|
den_.GetXY(x, y);
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-20 16:00:22 +00:00
|
|
|
MathedArray & MathFracInset::GetData()
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2001-02-16 09:25:43 +00:00
|
|
|
if (idx_ == 0)
|
2001-02-20 16:00:22 +00:00
|
|
|
return array;
|
2001-02-13 13:28:32 +00:00
|
|
|
else
|
2001-02-28 11:56:36 +00:00
|
|
|
return den_.GetData();
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-28 17:21:16 +00:00
|
|
|
MathedArray const & MathFracInset::GetData() const
|
|
|
|
{
|
|
|
|
if (idx_ == 0)
|
|
|
|
return array;
|
|
|
|
else
|
|
|
|
return den_.GetData();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
bool MathFracInset::Inside(int x, int y)
|
|
|
|
{
|
2001-02-26 12:53:35 +00:00
|
|
|
int const 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-25 15:43:57 +00:00
|
|
|
void MathFracInset::draw(Painter & pain, int x, int y)
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
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_);
|
2001-02-28 11:56:36 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-25 15:43:57 +00:00
|
|
|
void MathFracInset::Metrics()
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
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_;
|
2001-02-28 11:56:36 +00:00
|
|
|
den_.Metrics();
|
|
|
|
w1_ = den_.Width();
|
2001-02-16 09:25:43 +00:00
|
|
|
width = ((w0_ > w1_) ? w0_: w1_) + 12;
|
2001-02-13 13:28:32 +00:00
|
|
|
ascent = as;
|
2001-02-28 11:56:36 +00:00
|
|
|
descent = den_.Height()+ 2 - dh_;
|
2001-02-16 09:25:43 +00:00
|
|
|
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-28 11:56:36 +00:00
|
|
|
den_.Write(os, fragile);
|
2001-02-13 13:28:32 +00:00
|
|
|
os << '}';
|
|
|
|
}
|
2001-04-25 15:43:57 +00:00
|
|
|
|
|
|
|
void MathFracInset::WriteNormal(ostream & os)
|
|
|
|
{
|
|
|
|
os << '{' << name << ' ';
|
|
|
|
MathParInset::WriteNormal(os);
|
|
|
|
os << " ";
|
|
|
|
den_.WriteNormal(os);
|
|
|
|
os << "} ";
|
|
|
|
}
|