2002-02-08 08:03:38 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "math_xyarrowinset.h"
|
2002-02-11 08:19:02 +00:00
|
|
|
#include "math_xymatrixinset.h"
|
2002-02-08 08:03:38 +00:00
|
|
|
#include "math_mathmlstream.h"
|
|
|
|
#include "math_streamstr.h"
|
2002-02-11 08:19:02 +00:00
|
|
|
#include "math_support.h"
|
2002-05-23 09:21:32 +00:00
|
|
|
#include "frontends/Painter.h"
|
2002-02-11 08:19:02 +00:00
|
|
|
#include "debug.h"
|
2002-02-08 08:03:38 +00:00
|
|
|
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
using std::max;
|
|
|
|
|
|
|
|
|
2002-02-08 08:03:38 +00:00
|
|
|
MathXYArrowInset::MathXYArrowInset()
|
2002-02-11 08:19:02 +00:00
|
|
|
: MathNestInset(2)
|
2002-02-08 08:03:38 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
MathInset * MathXYArrowInset::clone() const
|
|
|
|
{
|
|
|
|
return new MathXYArrowInset(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-11 08:19:02 +00:00
|
|
|
MathXYMatrixInset const * MathXYArrowInset::targetMatrix() const
|
|
|
|
{
|
2002-03-19 16:55:58 +00:00
|
|
|
return target_;
|
2002-02-11 08:19:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathXArray const & MathXYArrowInset::targetCell() const
|
|
|
|
{
|
|
|
|
MathXYMatrixInset const * p = targetMatrix();
|
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
|
|
|
MathArray const & t = cell(0);
|
|
|
|
for (MathArray::const_iterator it = t.begin(); it != t.end(); ++it) {
|
|
|
|
switch ((*it)->getChar()) {
|
|
|
|
case 'l': --x; break;
|
|
|
|
case 'r': ++x; break;
|
|
|
|
case 'u': --y; break;
|
|
|
|
case 'd': ++y; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//lyxerr << "target: x: " << x << " y: " << y << "\n";
|
2002-03-21 06:57:13 +00:00
|
|
|
MathInset::idx_type n = mi_.idx + p->ncols() * y + x;
|
|
|
|
if (n >= p->nargs()) {
|
2002-02-11 08:19:02 +00:00
|
|
|
lyxerr << "source: n: " << mi_.idx << "\n";
|
|
|
|
lyxerr << "target: n: " << n << " out of range\n";
|
|
|
|
n = 0;
|
|
|
|
}
|
|
|
|
return p->xcell(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathXArray const & MathXYArrowInset::sourceCell() const
|
|
|
|
{
|
|
|
|
return targetMatrix()->xcell(mi_.idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-08 08:03:38 +00:00
|
|
|
void MathXYArrowInset::metrics(MathMetricsInfo const & mi) const
|
|
|
|
{
|
|
|
|
MathNestInset::metrics(mi);
|
2002-03-19 16:55:58 +00:00
|
|
|
mi_ = mi;
|
|
|
|
whichFont(font_, LM_TC_TEXTRM, mi);
|
|
|
|
target_ = mi.inset ? mi.inset->asXYMatrixInset() : 0;
|
2002-02-11 08:19:02 +00:00
|
|
|
|
|
|
|
if (editing()) {
|
2002-03-19 16:55:58 +00:00
|
|
|
int w = mathed_string_width(font_, "target: ");
|
2002-02-16 15:59:55 +00:00
|
|
|
width_ = w + max(xcell(0).width(), xcell(1).width());
|
2002-02-11 08:19:02 +00:00
|
|
|
ascent_ = xcell(0).ascent();
|
|
|
|
descent_ = xcell(0).descent() + xcell(1).height() + 10;
|
|
|
|
} else {
|
|
|
|
width_ = 0;
|
|
|
|
ascent_ = 0;
|
|
|
|
descent_ = 0;
|
2002-03-19 16:55:58 +00:00
|
|
|
//mathed_string_dim(font_, "X", ascent_, descent_, width_);
|
2002-02-11 08:19:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathXYArrowInset::draw(Painter & pain, int x, int y) const
|
|
|
|
{
|
|
|
|
metrics(mi_);
|
|
|
|
|
|
|
|
if (editing()) {
|
|
|
|
|
|
|
|
int lasc;
|
|
|
|
int ldes;
|
|
|
|
int lwid;
|
2002-03-19 16:55:58 +00:00
|
|
|
mathed_string_dim(font_, "target: ", lasc, ldes, lwid);
|
2002-02-11 08:19:02 +00:00
|
|
|
|
|
|
|
xcell(0).draw(pain, x + lwid, y);
|
2002-03-19 16:55:58 +00:00
|
|
|
drawStr(pain, font_, x + 3, y, "target");
|
2002-02-16 15:59:55 +00:00
|
|
|
y += max(xcell(0).descent(), ldes) + 5;
|
2002-02-11 08:19:02 +00:00
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
y += max(xcell(1).ascent(), lasc) + 5;
|
2002-02-11 08:19:02 +00:00
|
|
|
xcell(1).draw(pain, x + lwid, y);
|
2002-03-19 16:55:58 +00:00
|
|
|
drawStr(pain, font_, x + 3, y, "label");
|
2002-02-11 08:19:02 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2002-03-19 16:55:58 +00:00
|
|
|
//drawStr(pain, font_, x, y, "X");
|
2002-02-11 08:19:02 +00:00
|
|
|
MathXArray const & s = sourceCell();
|
|
|
|
MathXArray const & t = targetCell();
|
|
|
|
pain.line(s.xm(), s.ym(), t.xm(), t.ym(), LColor::math);
|
|
|
|
xcell(1).draw(pain, (s.xm() + t.xm())/2, (s.ym() + t.ym())/2);
|
2002-03-21 17:42:56 +00:00
|
|
|
|
2002-02-11 08:19:02 +00:00
|
|
|
}
|
2002-02-08 08:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathXYArrowInset::write(WriteStream & os) const
|
|
|
|
{
|
2002-02-11 08:19:02 +00:00
|
|
|
os << "\\ar";
|
|
|
|
if (cell(0).size())
|
|
|
|
os << "[" << cell(0) << "]";
|
|
|
|
if (cell(1).size())
|
|
|
|
os << (up_ ? "^" : "_") << "{" << cell(1) << "}";
|
|
|
|
os << " ";
|
2002-02-08 08:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathXYArrowInset::normalize(NormalStream & os) const
|
|
|
|
{
|
|
|
|
os << "[xyarrow ";
|
|
|
|
MathNestInset::normalize(os);
|
|
|
|
os << "]";
|
|
|
|
}
|