2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file math_xyarrowinset.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
2002-02-08 08:03:38 +00:00
|
|
|
|
|
2003-08-19 13:00:56 +00:00
|
|
|
|
#include <config.h>
|
2002-02-08 08:03:38 +00:00
|
|
|
|
|
|
|
|
|
#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
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2003-06-16 11:49:38 +00:00
|
|
|
|
InsetBase * MathXYArrowInset::clone() const
|
2002-02-08 08:03:38 +00:00
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-02 14:29:42 +00:00
|
|
|
|
MathArray const & MathXYArrowInset::targetCell() const
|
2002-02-11 08:19:02 +00:00
|
|
|
|
{
|
2002-11-27 10:30:28 +00:00
|
|
|
|
#if 0
|
2002-02-11 08:19:02 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-08-02 11:30:30 +00:00
|
|
|
|
//lyxerr << "target: x: " << x << " y: " << y << endl;
|
2002-03-21 06:57:13 +00:00
|
|
|
|
MathInset::idx_type n = mi_.idx + p->ncols() * y + x;
|
|
|
|
|
if (n >= p->nargs()) {
|
2003-08-02 11:30:30 +00:00
|
|
|
|
lyxerr << "source: n: " << mi_.idx << "\n"
|
|
|
|
|
<< "target: n: " << n << " out of range" << endl;
|
2002-02-11 08:19:02 +00:00
|
|
|
|
n = 0;
|
|
|
|
|
}
|
2002-08-02 14:29:42 +00:00
|
|
|
|
return p->cell(n);
|
2002-07-10 15:51:28 +00:00
|
|
|
|
#else
|
2002-08-02 14:29:42 +00:00
|
|
|
|
static MathArray dummy;
|
2002-07-10 15:51:28 +00:00
|
|
|
|
return dummy;
|
|
|
|
|
#endif
|
2002-02-11 08:19:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-02 14:29:42 +00:00
|
|
|
|
MathArray const & MathXYArrowInset::sourceCell() const
|
2002-02-11 08:19:02 +00:00
|
|
|
|
{
|
2002-07-10 15:51:28 +00:00
|
|
|
|
#if 0
|
2002-08-02 14:29:42 +00:00
|
|
|
|
return targetMatrix()->cell(mi_.idx);
|
2002-07-10 15:51:28 +00:00
|
|
|
|
#else
|
2002-08-02 14:29:42 +00:00
|
|
|
|
static MathArray dummy;
|
2002-07-10 15:51:28 +00:00
|
|
|
|
return dummy;
|
|
|
|
|
#endif
|
2002-02-11 08:19:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-21 14:20:48 +00:00
|
|
|
|
void MathXYArrowInset::metrics(MetricsInfo & mi) const
|
2002-02-08 08:03:38 +00:00
|
|
|
|
{
|
|
|
|
|
MathNestInset::metrics(mi);
|
2002-05-30 07:09:54 +00:00
|
|
|
|
mi_ = mi;
|
2003-03-21 14:20:48 +00:00
|
|
|
|
FontSetChanger dummy(mi.base, "textrm");
|
2002-07-10 15:51:28 +00:00
|
|
|
|
#if 0
|
2002-03-19 16:55:58 +00:00
|
|
|
|
target_ = mi.inset ? mi.inset->asXYMatrixInset() : 0;
|
2002-02-11 08:19:02 +00:00
|
|
|
|
|
|
|
|
|
if (editing()) {
|
2002-05-30 07:09:54 +00:00
|
|
|
|
int w = mathed_string_width(mi.base.font, "target: ");
|
2002-08-02 14:29:42 +00:00
|
|
|
|
width_ = w + max(cell(0).width(), cell(1).width());
|
|
|
|
|
ascent_ = cell(0).ascent();
|
|
|
|
|
descent_ = cell(0).descent() + cell(1).height() + 10;
|
2002-02-11 08:19:02 +00:00
|
|
|
|
} 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
|
|
|
|
}
|
2002-07-10 15:51:28 +00:00
|
|
|
|
#endif
|
2002-02-11 08:19:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-21 14:20:48 +00:00
|
|
|
|
void MathXYArrowInset::draw(PainterInfo & pi, int x, int y) const
|
2002-02-11 08:19:02 +00:00
|
|
|
|
{
|
|
|
|
|
metrics(mi_);
|
2003-03-21 14:20:48 +00:00
|
|
|
|
FontSetChanger dummy(pi.base, "textrm");
|
2002-02-11 08:19:02 +00:00
|
|
|
|
|
|
|
|
|
if (editing()) {
|
|
|
|
|
|
2002-07-10 15:51:28 +00:00
|
|
|
|
#if 0
|
|
|
|
|
|
2002-02-11 08:19:02 +00:00
|
|
|
|
int lasc;
|
|
|
|
|
int ldes;
|
|
|
|
|
int lwid;
|
2002-05-30 07:09:54 +00:00
|
|
|
|
mathed_string_dim(pi.base.font, "target: ", lasc, ldes, lwid);
|
2002-02-11 08:19:02 +00:00
|
|
|
|
|
2002-08-02 14:29:42 +00:00
|
|
|
|
cell(0).draw(pi, x + lwid, y);
|
2002-05-30 07:09:54 +00:00
|
|
|
|
drawStr(pi, pi.base.font, x + 3, y, "target");
|
2002-08-02 14:29:42 +00:00
|
|
|
|
y += max(cell(0).descent(), ldes) + 5;
|
2002-02-11 08:19:02 +00:00
|
|
|
|
|
2002-08-02 14:29:42 +00:00
|
|
|
|
y += max(cell(1).ascent(), lasc) + 5;
|
|
|
|
|
cell(1).draw(pi, x + lwid, y);
|
2002-05-30 07:09:54 +00:00
|
|
|
|
drawStr(pi, pi.base.font, x + 3, y, "label");
|
2002-02-11 08:19:02 +00:00
|
|
|
|
|
2002-07-10 15:51:28 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2002-02-11 08:19:02 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
2002-07-10 15:51:28 +00:00
|
|
|
|
drawStr(pi, font_, x, y, "X");
|
2002-08-02 14:29:42 +00:00
|
|
|
|
MathArray const & s = sourceCell();
|
|
|
|
|
MathArray const & t = targetCell();
|
2002-05-30 07:09:54 +00:00
|
|
|
|
pi.pain.line(s.xm(), s.ym(), t.xm(), t.ym(), LColor::math);
|
2002-08-02 14:29:42 +00:00
|
|
|
|
cell(1).draw(pi, (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())
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << '[' << cell(0) << ']';
|
2002-02-11 08:19:02 +00:00
|
|
|
|
if (cell(1).size())
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << (up_ ? '^' : '_') << '{' << cell(1) << '}';
|
2002-02-11 08:19:02 +00:00
|
|
|
|
os << " ";
|
2002-02-08 08:03:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathXYArrowInset::normalize(NormalStream & os) const
|
|
|
|
|
{
|
|
|
|
|
os << "[xyarrow ";
|
|
|
|
|
MathNestInset::normalize(os);
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << ']';
|
2002-02-08 08:03:38 +00:00
|
|
|
|
}
|