2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
2006-09-17 09:14:18 +00:00
|
|
|
|
* \file InsetMathXYArrow.C
|
2003-08-19 13:00:56 +00:00
|
|
|
|
* 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
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "InsetMathXYArrow.h"
|
|
|
|
|
#include "MathMLStream.h"
|
|
|
|
|
#include "MathStream.h"
|
|
|
|
|
#include "MathSupport.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
|
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
using std::max;
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathXYArrow::InsetMathXYArrow()
|
|
|
|
|
: InsetMathNest(2)
|
2002-02-08 08:03:38 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
std::auto_ptr<InsetBase> InsetMathXYArrow::clone() const
|
2002-02-08 08:03:38 +00:00
|
|
|
|
{
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return std::auto_ptr<InsetBase>(new InsetMathXYArrow(*this));
|
2002-02-08 08:03:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathXYMatrix const * InsetMathXYArrow::targetMatrix() const
|
2002-02-11 08:19:02 +00:00
|
|
|
|
{
|
2002-03-19 16:55:58 +00:00
|
|
|
|
return target_;
|
2002-02-11 08:19:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
MathArray const & InsetMathXYArrow::targetCell() const
|
2002-02-11 08:19:02 +00:00
|
|
|
|
{
|
2002-11-27 10:30:28 +00:00
|
|
|
|
#if 0
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathXYMatrix const * p = targetMatrix();
|
2002-02-11 08:19:02 +00:00
|
|
|
|
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;
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMath::idx_type n = mi_.idx + p->ncols() * y + x;
|
2002-03-21 06:57:13 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
2004-10-05 10:11: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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
MathArray const & InsetMathXYArrow::sourceCell() const
|
2002-02-11 08:19:02 +00:00
|
|
|
|
{
|
2002-07-10 15:51:28 +00:00
|
|
|
|
#if 0
|
2004-10-05 10:11: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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathXYArrow::metrics(MetricsInfo & mi) const
|
2002-02-08 08:03:38 +00:00
|
|
|
|
{
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathNest::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()) {
|
2006-10-21 00:16:43 +00:00
|
|
|
|
int w = mathed_string_width(mi.base.font, from_ascii("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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathXYArrow::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);
|
2005-07-17 10:31:44 +00:00
|
|
|
|
pi.base.text(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);
|
2005-07-17 10:31:44 +00:00
|
|
|
|
pi.base.text(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 {
|
|
|
|
|
|
2005-07-17 10:31:44 +00:00
|
|
|
|
pi.pain.text(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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathXYArrow::write(WriteStream & os) const
|
2002-02-08 08:03:38 +00:00
|
|
|
|
{
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathXYArrow::normalize(NormalStream & os) const
|
2002-02-08 08:03:38 +00:00
|
|
|
|
{
|
|
|
|
|
os << "[xyarrow ";
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathNest::normalize(os);
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << ']';
|
2002-02-08 08:03:38 +00:00
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|