2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
|
* \file InsetMathXYArrow.cpp
|
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 "MathStream.h"
|
|
|
|
|
#include "MathSupport.h"
|
2002-05-23 09:21:32 +00:00
|
|
|
|
#include "frontends/Painter.h"
|
2007-11-29 07:04:28 +00:00
|
|
|
|
#include "support/debug.h"
|
2002-02-08 08:03:38 +00:00
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
|
using namespace std;
|
2002-02-08 08:03:38 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathXYArrow::InsetMathXYArrow()
|
|
|
|
|
: InsetMathNest(2)
|
2002-02-08 08:03:38 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
|
Inset * InsetMathXYArrow::clone() const
|
2002-02-08 08:03:38 +00:00
|
|
|
|
{
|
2007-08-30 18:03:17 +00:00
|
|
|
|
return 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData 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;
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData const & t = cell(0);
|
|
|
|
|
for (MathData::const_iterator it = t.begin(); it != t.end(); ++it) {
|
2002-02-11 08:19:02 +00:00
|
|
|
|
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
|
2007-04-26 16:05:57 +00:00
|
|
|
|
static MathData dummy;
|
2002-07-10 15:51:28 +00:00
|
|
|
|
return dummy;
|
|
|
|
|
#endif
|
2002-02-11 08:19:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData 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
|
2007-04-26 16:05:57 +00:00
|
|
|
|
static MathData dummy;
|
2002-07-10 15:51:28 +00:00
|
|
|
|
return dummy;
|
|
|
|
|
#endif
|
2002-02-11 08:19:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-11-28 15:15:49 +00:00
|
|
|
|
bool 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: "));
|
2007-09-24 13:52:04 +00:00
|
|
|
|
width_ = w + max(dim0.width(), dim1.wid);
|
|
|
|
|
ascent_ = dim0.asc;
|
|
|
|
|
descent_ = dim0.des + dim1.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");
|
2007-09-24 13:52:04 +00:00
|
|
|
|
y += max(dim0.des, ldes) + 5;
|
2002-02-11 08:19:02 +00:00
|
|
|
|
|
2007-09-24 13:52:04 +00:00
|
|
|
|
y += max(dim1.asc, lasc) + 5;
|
2002-08-02 14:29:42 +00:00
|
|
|
|
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");
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData const & s = sourceCell();
|
|
|
|
|
MathData const & t = targetCell();
|
2007-10-25 12:41:02 +00:00
|
|
|
|
pi.pain.line(s.xm(), s.ym(), t.xm(), t.ym(), Color_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
|