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-06-27 15:33:55 +00:00
|
|
|
#include <functional>
|
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
#include "math_fracinset.h"
|
|
|
|
#include "LColor.h"
|
|
|
|
#include "Painter.h"
|
|
|
|
#include "mathed/support.h"
|
2001-02-14 15:00:50 +00:00
|
|
|
#include "support/LOstream.h"
|
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
MathFracInset::MathFracInset(MathInsetTypes ot)
|
2001-06-25 00:06:33 +00:00
|
|
|
: MathInset("frac", ot, 2)
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
if (objtype == LM_OT_STACKREL)
|
2001-02-13 13:28:32 +00:00
|
|
|
SetName("stackrel");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
MathInset * MathFracInset::clone() const
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
return new MathFracInset(*this);
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathFracInset::Metrics(MathStyles st)
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2001-07-06 12:09:32 +00:00
|
|
|
size_ = smallerStyleFrac(st);
|
|
|
|
xcell(0).Metrics(size_);
|
|
|
|
xcell(1).Metrics(size_);
|
2001-06-27 15:33:55 +00:00
|
|
|
width_ = std::max(xcell(0).width(), xcell(1).width()) + 4;
|
2001-06-25 00:06:33 +00:00
|
|
|
ascent_ = xcell(0).height() + 4 + 5;
|
|
|
|
descent_ = xcell(1).height() + 4 - 5;
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathFracInset::draw(Painter & pain, int x, int y)
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
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);
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathFracInset::Write(std::ostream & os, bool fragile) const
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
os << '\\' << name() << '{';
|
|
|
|
cell(0).Write(os, fragile);
|
|
|
|
os << "}{";
|
|
|
|
cell(1).Write(os, fragile);
|
|
|
|
os << '}';
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathFracInset::WriteNormal(std::ostream & os) const
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
os << '[' << name() << ' ';
|
|
|
|
cell(0).WriteNormal(os);
|
|
|
|
os << " ";
|
|
|
|
cell(1).WriteNormal(os);
|
|
|
|
os << "] ";
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
bool MathFracInset::idxRight(int &, int &) const
|
2001-02-28 17:21:16 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
return false;
|
2001-02-28 17:21:16 +00:00
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
bool MathFracInset::idxLeft(int &, int &) const
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
return false;
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
bool MathFracInset::idxUp(int & idx, int &) const
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
if (idx == 0)
|
|
|
|
return false;
|
|
|
|
idx = 0;
|
|
|
|
return true;
|
2001-04-27 12:35:55 +00:00
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
bool MathFracInset::idxDown(int & idx, int &) const
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
if (idx == 1)
|
|
|
|
return false;
|
|
|
|
idx = 1;
|
|
|
|
return true;
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
2001-04-25 15:43:57 +00:00
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
bool MathFracInset::idxFirstUp(int & idx, int & pos) const
|
|
|
|
{
|
|
|
|
idx = 0;
|
|
|
|
pos = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MathFracInset::idxFirstDown(int & idx, int & pos) const
|
|
|
|
{
|
|
|
|
idx = 1;
|
|
|
|
pos = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MathFracInset::idxLastUp(int & idx, int & pos) const
|
|
|
|
{
|
|
|
|
idx = 0;
|
|
|
|
pos = cell(idx).size();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MathFracInset::idxLastDown(int & idx, int & pos) const
|
|
|
|
{
|
|
|
|
idx = 1;
|
|
|
|
pos = cell(idx).size();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|